Commit 7b913f7f authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Changed Q_PROPERTY parsing and AST storage.

parent 21488e88
......@@ -144,6 +144,42 @@ unsigned AccessDeclarationAST::lastToken() const
return access_specifier_token + 1;
}
unsigned QtPropertyDeclarationNamingItemAST::firstToken() const
{
return item_name_token;
}
unsigned QtPropertyDeclarationNamingItemAST::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();
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;
......@@ -151,7 +187,18 @@ unsigned QtPropertyDeclarationAST::firstToken() const
unsigned QtPropertyDeclarationAST::lastToken() const
{
return rparen_token;
if (rparen_token)
return rparen_token + 1;
else if (property_declaration_items)
return property_declaration_items->lastToken();
else if (property_name)
return property_name->lastToken();
else if (type_id)
return type_id->lastToken();
else if (lparen_token)
return lparen_token + 1;
else
return property_specifier_token + 1;
}
unsigned QtEnumDeclarationAST::firstToken() const
......@@ -161,17 +208,31 @@ unsigned QtEnumDeclarationAST::firstToken() const
unsigned QtEnumDeclarationAST::lastToken() const
{
return rparen_token;
if (rparen_token)
return rparen_token + 1;
else if (enumerator_list)
return enumerator_list->lastToken();
else if (lparen_token)
return lparen_token + 1;
else
return enum_specifier_token + 1;
}
unsigned QtFlagsDeclarationAST::firstToken() const
{
return this->flags_specifier_token;
return flags_specifier_token + 1;
}
unsigned QtFlagsDeclarationAST::lastToken() const
{
return rparen_token;
if (rparen_token)
return rparen_token + 1;
else if (flag_enums_list)
return flag_enums_list->lastToken();
else if (lparen_token)
return lparen_token + 1;
else
return flags_specifier_token + 1;
}
unsigned QtDeclareFlagsDeclarationAST::firstToken() const
......@@ -181,7 +242,18 @@ unsigned QtDeclareFlagsDeclarationAST::firstToken() const
unsigned QtDeclareFlagsDeclarationAST::lastToken() const
{
return rparen_token;
if (rparen_token)
return rparen_token + 1;
else if (flags_name)
return flags_name->lastToken();
else if (comma_token)
return comma_token + 1;
else if (enum_name)
return enum_name->lastToken();
else if (lparen_token)
return lparen_token + 1;
else
return declareflags_specifier_token + 1;
}
unsigned ArrayAccessAST::firstToken() const
......
......@@ -262,6 +262,10 @@ 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; }
......@@ -552,43 +556,76 @@ protected:
virtual bool match0(AST *, ASTMatcher *);
};
class QtPropertyDeclarationItemAST: public AST
{
public:
unsigned item_name_token;
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;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT QtPropertyDeclarationAST: public DeclarationAST
{
/*
Q_PROPERTY(type name
READ getFunction
[WRITE setFunction]
[RESET resetFunction]
[NOTIFY notifySignal]
[DESIGNABLE bool]
[SCRIPTABLE bool]
[STORED bool]
[USER bool]
[CONSTANT]
[FINAL])*/
public:
unsigned property_specifier_token;
unsigned lparen_token;
ExpressionAST *type_id;
SimpleNameAST *property_name;
unsigned read_token;
SimpleNameAST *read_function;
unsigned write_token;
SimpleNameAST *write_function;
unsigned reset_token;
SimpleNameAST *reset_function;
unsigned notify_token;
SimpleNameAST *notify_function;
unsigned designable_token;
BoolLiteralAST *designable_value;
unsigned scriptable_token;
BoolLiteralAST *scriptable_value;
unsigned stored_token;
BoolLiteralAST *stored_value;
unsigned user_token;
BoolLiteralAST *user_value;
unsigned constant_token;
unsigned final_token;
QtPropertyDeclarationItemListAST *property_declaration_items;
unsigned rparen_token;
public:
......
......@@ -138,6 +138,28 @@ AccessDeclarationAST *AccessDeclarationAST::clone(MemoryPool *pool) const
return ast;
}
QtPropertyDeclarationNamingItemAST *QtPropertyDeclarationNamingItemAST::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;
return ast;
}
QtPropertyDeclarationAST *QtPropertyDeclarationAST::clone(MemoryPool *pool) const
{
QtPropertyDeclarationAST *ast = new (pool) QtPropertyDeclarationAST;
......@@ -147,32 +169,9 @@ QtPropertyDeclarationAST *QtPropertyDeclarationAST::clone(MemoryPool *pool) cons
ast->type_id = type_id->clone(pool);
if (property_name)
ast->property_name = property_name->clone(pool);
ast->read_token = read_token;
if (read_function)
ast->read_function = read_function->clone(pool);
ast->write_token = write_token;
if (write_function)
ast->write_function = write_function->clone(pool);
ast->reset_token = reset_token;
if (reset_function)
ast->reset_function = reset_function->clone(pool);
ast->notify_token = notify_token;
if (notify_function)
ast->notify_function = notify_function->clone(pool);
ast->designable_token = designable_token;
if (designable_value)
ast->designable_value = designable_value->clone(pool);
ast->scriptable_token = scriptable_token;
if (scriptable_value)
ast->scriptable_value = scriptable_value->clone(pool);
ast->stored_token = stored_token;
if (stored_value)
ast->stored_value = stored_value->clone(pool);
ast->user_token = user_token;
if (user_value)
ast->user_value = user_value->clone(pool);
ast->constant_token = constant_token;
ast->final_token = final_token;
for (QtPropertyDeclarationItemListAST *iter = property_declaration_items, **ast_iter = &ast->property_declaration_items;
iter; iter = iter->next, ast_iter = &(*ast_iter)->next)
*ast_iter = new (pool) QtPropertyDeclarationItemListAST((iter->value) ? iter->value->clone(pool) : 0);
ast->rparen_token = rparen_token;
return ast;
}
......
......@@ -105,6 +105,30 @@ bool AccessDeclarationAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool QtPropertyDeclarationNamingItemAST::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())
return matcher->match(this, _other);
return false;
}
bool QtPropertyDeclarationAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (QtPropertyDeclarationAST *_other = pattern->asQtPropertyDeclaration())
......
......@@ -206,85 +206,64 @@ bool ASTMatcher::match(AccessDeclarationAST *node, AccessDeclarationAST *pattern
return true;
}
bool ASTMatcher::match(QtPropertyDeclarationAST *node, QtPropertyDeclarationAST *pattern)
bool ASTMatcher::match(QtPropertyDeclarationNamingItemAST *node, QtPropertyDeclarationNamingItemAST *pattern)
{
(void) node;
(void) pattern;
pattern->property_specifier_token = node->property_specifier_token;
pattern->lparen_token = node->lparen_token;
if (! pattern->type_id)
pattern->type_id = node->type_id;
else if (! AST::match(node->type_id, pattern->type_id, this))
return false;
if (! pattern->property_name)
pattern->property_name = node->property_name;
else if (! AST::match(node->property_name, pattern->property_name, this))
if (! pattern->name_value)
pattern->name_value = node->name_value;
else if (! AST::match(node->name_value, pattern->name_value, this))
return false;
pattern->read_token = node->read_token;
if (! pattern->read_function)
pattern->read_function = node->read_function;
else if (! AST::match(node->read_function, pattern->read_function, this))
return false;
return true;
}
pattern->write_token = node->write_token;
bool ASTMatcher::match(QtPropertyDeclarationBoolItemAST *node, QtPropertyDeclarationBoolItemAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->write_function)
pattern->write_function = node->write_function;
else if (! AST::match(node->write_function, pattern->write_function, this))
if (! pattern->bool_value)
pattern->bool_value = node->bool_value;
else if (! AST::match(node->bool_value, pattern->bool_value, this))
return false;
pattern->reset_token = node->reset_token;
if (! pattern->reset_function)
pattern->reset_function = node->reset_function;
else if (! AST::match(node->reset_function, pattern->reset_function, this))
return false;
return true;
}
pattern->notify_token = node->notify_token;
bool ASTMatcher::match(QtPropertyDeclarationFlaggingItemAST *node, QtPropertyDeclarationFlaggingItemAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->notify_function)
pattern->notify_function = node->notify_function;
else if (! AST::match(node->notify_function, pattern->notify_function, this))
return false;
return true;
}
pattern->designable_token = node->designable_token;
bool ASTMatcher::match(QtPropertyDeclarationAST *node, QtPropertyDeclarationAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->designable_value)
pattern->designable_value = node->designable_value;
else if (! AST::match(node->designable_value, pattern->designable_value, this))
return false;
pattern->property_specifier_token = node->property_specifier_token;
pattern->scriptable_token = node->scriptable_token;
pattern->lparen_token = node->lparen_token;
if (! pattern->scriptable_value)
pattern->scriptable_value = node->scriptable_value;
else if (! AST::match(node->scriptable_value, pattern->scriptable_value, this))
if (! pattern->type_id)
pattern->type_id = node->type_id;
else if (! AST::match(node->type_id, pattern->type_id, this))
return false;
pattern->stored_token = node->stored_token;
if (! pattern->stored_value)
pattern->stored_value = node->stored_value;
else if (! AST::match(node->stored_value, pattern->stored_value, this))
if (! pattern->property_name)
pattern->property_name = node->property_name;
else if (! AST::match(node->property_name, pattern->property_name, this))
return false;
pattern->user_token = node->user_token;
if (! pattern->user_value)
pattern->user_value = node->user_value;
else if (! AST::match(node->user_value, pattern->user_value, this))
if (! pattern->property_declaration_items)
pattern->property_declaration_items = node->property_declaration_items;
else if (! AST::match(node->property_declaration_items, pattern->property_declaration_items, this))
return false;
pattern->constant_token = node->constant_token;
pattern->final_token = node->final_token;
pattern->rparen_token = node->rparen_token;
return true;
......
......@@ -142,6 +142,9 @@ 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(ObjCClassForwardDeclarationAST *node, ObjCClassForwardDeclarationAST *pattern);
virtual bool match(ObjCProtocolDeclarationAST *node, ObjCProtocolDeclarationAST *pattern);
virtual bool match(ObjCProtocolForwardDeclarationAST *node, ObjCProtocolForwardDeclarationAST *pattern);
......
......@@ -108,19 +108,35 @@ 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)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void QtPropertyDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(type_id, visitor);
accept(property_name, visitor);
accept(read_function, visitor);
accept(write_function, visitor);
accept(reset_function, visitor);
accept(notify_function, visitor);
accept(designable_value, visitor);
accept(scriptable_value, visitor);
accept(stored_value, visitor);
accept(user_value, visitor);
accept(property_declaration_items, visitor);
}
visitor->endVisit(this);
}
......
......@@ -205,6 +205,10 @@ public:
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; }
// ObjC++
virtual bool visit(ObjCClassDeclarationAST *) { return true; }
virtual bool visit(ObjCClassForwardDeclarationAST *) { return true; }
......@@ -336,6 +340,10 @@ public:
virtual void endVisit(QtMethodAST *) { }
virtual void endVisit(QtMemberDeclarationAST *) { }
virtual void endVisit(QtPropertyDeclarationBoolItemAST *) { }
virtual void endVisit(QtPropertyDeclarationFlaggingItemAST *) { }
virtual void endVisit(QtPropertyDeclarationNamingItemAST *) { }
// ObjC++
virtual void endVisit(ObjCClassDeclarationAST *) { }
virtual void endVisit(ObjCClassForwardDeclarationAST *) { }
......
......@@ -169,6 +169,10 @@ class QtFlagsDeclarationAST;
class QtMemberDeclarationAST;
class QtMethodAST;
class QtPropertyDeclarationAST;
class QtPropertyDeclarationBoolItemAST;
class QtPropertyDeclarationFlaggingItemAST;
class QtPropertyDeclarationItemAST;
class QtPropertyDeclarationNamingItemAST;
class QualifiedNameAST;
class ReferenceAST;
class ReturnStatementAST;
......@@ -213,8 +217,9 @@ typedef List<NestedNameSpecifierAST *> NestedNameSpecifierListAST;
typedef List<CatchClauseAST *> CatchClauseListAST;
typedef List<PtrOperatorAST *> PtrOperatorListAST;
typedef List<SpecifierAST *> SpecifierListAST;
typedef List<QtPropertyDeclarationItemAST *> QtPropertyDeclarationItemListAST;
typedef List<NameAST *> NameListAST;
typedef List<ObjCMessageArgumentAST *> ObjCMessageArgumentListAST;
typedef List<ObjCSelectorArgumentAST *> ObjCSelectorArgumentListAST;
typedef List<ObjCPropertyAttributeAST *> ObjCPropertyAttributeListAST;
......
......@@ -831,13 +831,16 @@ bool CheckDeclaration::visit(QtPropertyDeclarationAST *ast)
semantic()->check(ast->type_id, _scope);
if (ast->property_name)
semantic()->check(ast->property_name, _scope);
if (ast->read_function)
semantic()->check(ast->read_function, _scope);
if (ast->write_function)
semantic()->check(ast->write_function, _scope);
if (ast->reset_function)
semantic()->check(ast->reset_function, _scope);
if (ast->notify_function)
semantic()->check(ast->notify_function, _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;
}
......@@ -1794,74 +1794,59 @@ bool Parser::parseQtPropertyDeclaration(DeclarationAST *&node)
parseTypeId(ast->type_id);
ast->property_name = new (_pool) SimpleNameAST;
match(T_IDENTIFIER, &ast->property_name->identifier_token);
QtPropertyDeclarationItemListAST **iter = &ast->property_declaration_items;
while (true) {
if (LA() == T_RPAREN) {
ast->rparen_token = consumeToken();
node = ast;
break;
} else if (LA() == T_IDENTIFIER) {
QtPropertyDeclarationItemAST *item = 0;
switch (peekAtQtContextKeyword()) {
case Token_READ:
ast->read_token = consumeToken();
ast->read_function = new (_pool) SimpleNameAST;
match(T_IDENTIFIER, &ast->read_function->identifier_token);
break;