Commit c79f25d5 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed Q_PROPERTY parsing to handle all possible cases.

parent 8c2928e1
......@@ -144,42 +144,19 @@ unsigned AccessDeclarationAST::lastToken() const
return access_specifier_token + 1;
}
unsigned QtPropertyDeclarationNamingItemAST::firstToken() const
unsigned QtPropertyDeclarationItemAST::firstToken() const
{
return item_name_token;
}
unsigned QtPropertyDeclarationNamingItemAST::lastToken() const
unsigned QtPropertyDeclarationItemAST::lastToken() const
{
if (name_value)
return name_value->lastToken();
else
return item_name_token + 1;
}
unsigned QtPropertyDeclarationBoolItemAST::firstToken() const
{
return item_name_token;
}
unsigned QtPropertyDeclarationBoolItemAST::lastToken() const
{
if (bool_value)
return bool_value->lastToken();
if (expression)
return expression->lastToken();
else
return item_name_token + 1;
}
unsigned QtPropertyDeclarationFlaggingItemAST::firstToken() const
{
return item_name_token;
}
unsigned QtPropertyDeclarationFlaggingItemAST::lastToken() const
{
return item_name_token + 1;
}
unsigned QtPropertyDeclarationAST::firstToken() const
{
return property_specifier_token;
......
......@@ -261,10 +261,7 @@ public:
virtual QtMemberDeclarationAST *asQtMemberDeclaration() { return 0; }
virtual QtMethodAST *asQtMethod() { return 0; }
virtual QtPropertyDeclarationAST *asQtPropertyDeclaration() { return 0; }
virtual QtPropertyDeclarationBoolItemAST *asQtPropertyDeclarationBoolItem() { return 0; }
virtual QtPropertyDeclarationFlaggingItemAST *asQtPropertyDeclarationFlaggingItem() { return 0; }
virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return 0; }
virtual QtPropertyDeclarationNamingItemAST *asQtPropertyDeclarationNamingItem() { return 0; }
virtual QualifiedNameAST *asQualifiedName() { return 0; }
virtual ReferenceAST *asReference() { return 0; }
virtual ReturnStatementAST *asReturnStatement() { return 0; }
......@@ -559,58 +556,15 @@ class QtPropertyDeclarationItemAST: public AST
{
public:
unsigned item_name_token;
ExpressionAST *expression;
public:
virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return this; }
virtual QtPropertyDeclarationItemAST *clone(MemoryPool *pool) const = 0;
};
class QtPropertyDeclarationNamingItemAST: public QtPropertyDeclarationItemAST
{
public:
SimpleNameAST *name_value;
public:
virtual QtPropertyDeclarationNamingItemAST *asQtPropertyDeclarationNamingItem() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual QtPropertyDeclarationNamingItemAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class QtPropertyDeclarationBoolItemAST: public QtPropertyDeclarationItemAST
{
public:
BoolLiteralAST *bool_value;
public:
virtual QtPropertyDeclarationBoolItemAST *asQtPropertyDeclarationBoolItem() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual QtPropertyDeclarationBoolItemAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class QtPropertyDeclarationFlaggingItemAST: public QtPropertyDeclarationItemAST
{
public:
virtual QtPropertyDeclarationFlaggingItemAST *asQtPropertyDeclarationFlaggingItem() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual QtPropertyDeclarationFlaggingItemAST *clone(MemoryPool *pool) const;
virtual QtPropertyDeclarationItemAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
......
......@@ -138,25 +138,12 @@ AccessDeclarationAST *AccessDeclarationAST::clone(MemoryPool *pool) const
return ast;
}
QtPropertyDeclarationNamingItemAST *QtPropertyDeclarationNamingItemAST::clone(MemoryPool *pool) const
QtPropertyDeclarationItemAST *QtPropertyDeclarationItemAST::clone(MemoryPool *pool) const
{
QtPropertyDeclarationNamingItemAST *ast = new (pool) QtPropertyDeclarationNamingItemAST;
if (name_value)
ast->name_value = name_value->clone(pool);
return ast;
}
QtPropertyDeclarationBoolItemAST *QtPropertyDeclarationBoolItemAST::clone(MemoryPool *pool) const
{
QtPropertyDeclarationBoolItemAST *ast = new (pool) QtPropertyDeclarationBoolItemAST;
if (bool_value)
ast->bool_value = bool_value->clone(pool);
return ast;
}
QtPropertyDeclarationFlaggingItemAST *QtPropertyDeclarationFlaggingItemAST::clone(MemoryPool *pool) const
{
QtPropertyDeclarationFlaggingItemAST *ast = new (pool) QtPropertyDeclarationFlaggingItemAST;
QtPropertyDeclarationItemAST *ast = new (pool) QtPropertyDeclarationItemAST;
ast->item_name_token = item_name_token;
if (expression)
ast->expression = expression->clone(pool);
return ast;
}
......
......@@ -105,25 +105,9 @@ bool AccessDeclarationAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool QtPropertyDeclarationNamingItemAST::match0(AST *pattern, ASTMatcher *matcher)
bool QtPropertyDeclarationItemAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (QtPropertyDeclarationNamingItemAST *_other = pattern->asQtPropertyDeclarationNamingItem())
return matcher->match(this, _other);
return false;
}
bool QtPropertyDeclarationBoolItemAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (QtPropertyDeclarationBoolItemAST *_other = pattern->asQtPropertyDeclarationBoolItem())
return matcher->match(this, _other);
return false;
}
bool QtPropertyDeclarationFlaggingItemAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (QtPropertyDeclarationFlaggingItemAST *_other = pattern->asQtPropertyDeclarationFlaggingItem())
if (QtPropertyDeclarationItemAST *_other = pattern->asQtPropertyDeclarationItem())
return matcher->match(this, _other);
return false;
......
......@@ -206,40 +206,21 @@ bool ASTMatcher::match(AccessDeclarationAST *node, AccessDeclarationAST *pattern
return true;
}
bool ASTMatcher::match(QtPropertyDeclarationNamingItemAST *node, QtPropertyDeclarationNamingItemAST *pattern)
bool ASTMatcher::match(QtPropertyDeclarationItemAST *node, QtPropertyDeclarationItemAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->name_value)
pattern->name_value = node->name_value;
else if (! AST::match(node->name_value, pattern->name_value, this))
return false;
pattern->item_name_token = node->item_name_token;
return true;
}
bool ASTMatcher::match(QtPropertyDeclarationBoolItemAST *node, QtPropertyDeclarationBoolItemAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->bool_value)
pattern->bool_value = node->bool_value;
else if (! AST::match(node->bool_value, pattern->bool_value, this))
if (! pattern->expression)
pattern->expression = node->expression;
else if (! AST::match(node->expression, pattern->expression, this))
return false;
return true;
}
bool ASTMatcher::match(QtPropertyDeclarationFlaggingItemAST *node, QtPropertyDeclarationFlaggingItemAST *pattern)
{
(void) node;
(void) pattern;
return true;
}
bool ASTMatcher::match(QtPropertyDeclarationAST *node, QtPropertyDeclarationAST *pattern)
{
(void) node;
......
......@@ -141,9 +141,7 @@ public:
virtual bool match(QtMethodAST *node, QtMethodAST *pattern);
virtual bool match(QtMemberDeclarationAST *node, QtMemberDeclarationAST *pattern);
virtual bool match(ObjCClassDeclarationAST *node, ObjCClassDeclarationAST *pattern);
virtual bool match(QtPropertyDeclarationBoolItemAST *node, QtPropertyDeclarationBoolItemAST *pattern);
virtual bool match(QtPropertyDeclarationFlaggingItemAST *node, QtPropertyDeclarationFlaggingItemAST *pattern);
virtual bool match(QtPropertyDeclarationNamingItemAST *node, QtPropertyDeclarationNamingItemAST *pattern);
virtual bool match(QtPropertyDeclarationItemAST *node, QtPropertyDeclarationItemAST *pattern);
virtual bool match(ObjCClassForwardDeclarationAST *node, ObjCClassForwardDeclarationAST *pattern);
virtual bool match(ObjCProtocolDeclarationAST *node, ObjCProtocolDeclarationAST *pattern);
virtual bool match(ObjCProtocolForwardDeclarationAST *node, ObjCProtocolForwardDeclarationAST *pattern);
......
......@@ -108,25 +108,10 @@ void AccessDeclarationAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void QtPropertyDeclarationNamingItemAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(name_value, visitor);
}
visitor->endVisit(this);
}
void QtPropertyDeclarationBoolItemAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(bool_value, visitor);
}
visitor->endVisit(this);
}
void QtPropertyDeclarationFlaggingItemAST::accept0(ASTVisitor *visitor)
void QtPropertyDeclarationItemAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
}
visitor->endVisit(this);
}
......
......@@ -203,10 +203,7 @@ public:
virtual bool visit(WhileStatementAST *) { return true; }
virtual bool visit(QtMethodAST *) { return true; }
virtual bool visit(QtMemberDeclarationAST *) { return true; }
virtual bool visit(QtPropertyDeclarationBoolItemAST *) { return true; }
virtual bool visit(QtPropertyDeclarationFlaggingItemAST *) { return true; }
virtual bool visit(QtPropertyDeclarationNamingItemAST *) { return true; }
virtual bool visit(QtPropertyDeclarationItemAST *) { return true; }
// ObjC++
virtual bool visit(ObjCClassDeclarationAST *) { return true; }
......@@ -337,10 +334,7 @@ public:
virtual void endVisit(WhileStatementAST *) { }
virtual void endVisit(QtMethodAST *) { }
virtual void endVisit(QtMemberDeclarationAST *) { }
virtual void endVisit(QtPropertyDeclarationBoolItemAST *) { }
virtual void endVisit(QtPropertyDeclarationFlaggingItemAST *) { }
virtual void endVisit(QtPropertyDeclarationNamingItemAST *) { }
virtual void endVisit(QtPropertyDeclarationItemAST *) { }
// ObjC++
virtual void endVisit(ObjCClassDeclarationAST *) { }
......
......@@ -168,10 +168,7 @@ class QtFlagsDeclarationAST;
class QtMemberDeclarationAST;
class QtMethodAST;
class QtPropertyDeclarationAST;
class QtPropertyDeclarationBoolItemAST;
class QtPropertyDeclarationFlaggingItemAST;
class QtPropertyDeclarationItemAST;
class QtPropertyDeclarationNamingItemAST;
class QualifiedNameAST;
class ReferenceAST;
class ReturnStatementAST;
......
......@@ -56,9 +56,12 @@
#include "Symbols.h"
#include "Control.h"
#include "Literals.h"
#include "QtContextKeywords.h"
#include <string>
#include <cassert>
#include <QDebug>
using namespace CPlusPlus;
CheckDeclaration::CheckDeclaration(Semantic *semantic)
......@@ -815,23 +818,3 @@ bool CheckDeclaration::visit(QtFlagsDeclarationAST *ast)
semantic()->check(iter->value, _scope);
return false;
}
bool CheckDeclaration::visit(QtPropertyDeclarationAST *ast)
{
if (ast->type_id)
semantic()->check(ast->type_id, _scope);
if (ast->property_name)
semantic()->check(ast->property_name, _scope);
for (QtPropertyDeclarationItemListAST *iter = ast->property_declaration_items;
iter; iter = iter->next) {
if (! iter->value)
continue;
if (QtPropertyDeclarationNamingItemAST *namedItem = iter->value->asQtPropertyDeclarationNamingItem())
if (namedItem->name_value)
semantic()->check(namedItem->name_value, _scope);
}
return false;
}
......@@ -77,7 +77,6 @@ protected:
virtual bool visit(SimpleDeclarationAST *ast);
virtual bool visit(EmptyDeclarationAST *ast);
virtual bool visit(AccessDeclarationAST *ast);
virtual bool visit(QtPropertyDeclarationAST *ast);
virtual bool visit(QtEnumDeclarationAST *ast);
virtual bool visit(QtFlagsDeclarationAST *ast);
virtual bool visit(AsmDefinitionAST *ast);
......
......@@ -1806,34 +1806,30 @@ bool Parser::parseQtPropertyDeclaration(DeclarationAST *&node)
case Token_READ:
case Token_WRITE:
case Token_RESET:
case Token_NOTIFY: {
QtPropertyDeclarationNamingItemAST *nItem = new (_pool) QtPropertyDeclarationNamingItemAST;
nItem->item_name_token = consumeToken();
nItem->name_value = new (_pool) SimpleNameAST;
match(T_IDENTIFIER, &nItem->name_value->identifier_token);
item = nItem;
break;
}
case Token_NOTIFY:
case Token_DESIGNABLE:
case Token_SCRIPTABLE:
case Token_STORED:
case Token_USER: {
QtPropertyDeclarationBoolItemAST *bItem = new (_pool) QtPropertyDeclarationBoolItemAST;
bItem->item_name_token = consumeToken();
unsigned item_name_token = consumeToken();
ExpressionAST *expr = 0;
if (parseBoolLiteral(expr)) {
bItem->bool_value = expr->asBoolLiteral();
if (parsePostfixExpression(expr)) {
QtPropertyDeclarationItemAST *bItem =
new (_pool) QtPropertyDeclarationItemAST;
bItem->item_name_token = item_name_token;
bItem->expression = expr;
item = bItem;
} else {
_translationUnit->error(cursor(), "expected `true' or `false' before `%s'", tok().spell());
_translationUnit->error(cursor(),
"expected expression before `%s'",
tok().spell());
}
break;
}
case Token_CONSTANT:
case Token_FINAL: {
QtPropertyDeclarationFlaggingItemAST *fItem = new (_pool) QtPropertyDeclarationFlaggingItemAST;
QtPropertyDeclarationItemAST *fItem = new (_pool) QtPropertyDeclarationItemAST;
fItem->item_name_token = consumeToken();
item = fItem;
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment