From c79f25d5a6b9aa645c0068db07b389ce615948b1 Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Tue, 16 Feb 2010 16:54:39 +0100
Subject: [PATCH] Fixed Q_PROPERTY parsing to handle all possible cases.

---
 src/shared/cplusplus/AST.cpp              | 31 ++------------
 src/shared/cplusplus/AST.h                | 50 +----------------------
 src/shared/cplusplus/ASTClone.cpp         | 23 +++--------
 src/shared/cplusplus/ASTMatch0.cpp        | 20 +--------
 src/shared/cplusplus/ASTMatcher.cpp       | 29 +++----------
 src/shared/cplusplus/ASTMatcher.h         |  4 +-
 src/shared/cplusplus/ASTVisit.cpp         | 19 +--------
 src/shared/cplusplus/ASTVisitor.h         | 10 +----
 src/shared/cplusplus/ASTfwd.h             |  3 --
 src/shared/cplusplus/CheckDeclaration.cpp | 23 ++---------
 src/shared/cplusplus/CheckDeclaration.h   |  1 -
 src/shared/cplusplus/Parser.cpp           | 26 +++++-------
 12 files changed, 37 insertions(+), 202 deletions(-)

diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp
index 9a8312eabaa..c85e4a7b6f6 100644
--- a/src/shared/cplusplus/AST.cpp
+++ b/src/shared/cplusplus/AST.cpp
@@ -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;
diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h
index 4b0c149357f..2072af3e167 100644
--- a/src/shared/cplusplus/AST.h
+++ b/src/shared/cplusplus/AST.h
@@ -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);
diff --git a/src/shared/cplusplus/ASTClone.cpp b/src/shared/cplusplus/ASTClone.cpp
index 87ee91558b1..984b7d95265 100644
--- a/src/shared/cplusplus/ASTClone.cpp
+++ b/src/shared/cplusplus/ASTClone.cpp
@@ -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;
 }
 
diff --git a/src/shared/cplusplus/ASTMatch0.cpp b/src/shared/cplusplus/ASTMatch0.cpp
index a2fcf8e0b96..8ffc5e6cbd2 100644
--- a/src/shared/cplusplus/ASTMatch0.cpp
+++ b/src/shared/cplusplus/ASTMatch0.cpp
@@ -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;
diff --git a/src/shared/cplusplus/ASTMatcher.cpp b/src/shared/cplusplus/ASTMatcher.cpp
index c3e04a0d4e3..e891d606ce7 100644
--- a/src/shared/cplusplus/ASTMatcher.cpp
+++ b/src/shared/cplusplus/ASTMatcher.cpp
@@ -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;
diff --git a/src/shared/cplusplus/ASTMatcher.h b/src/shared/cplusplus/ASTMatcher.h
index c6466a4919f..d0b1e1cffff 100644
--- a/src/shared/cplusplus/ASTMatcher.h
+++ b/src/shared/cplusplus/ASTMatcher.h
@@ -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);
diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp
index 8b53d99f7f3..b7fccf6e48c 100644
--- a/src/shared/cplusplus/ASTVisit.cpp
+++ b/src/shared/cplusplus/ASTVisit.cpp
@@ -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);
 }
diff --git a/src/shared/cplusplus/ASTVisitor.h b/src/shared/cplusplus/ASTVisitor.h
index 72a3f4b736e..aedf1295947 100644
--- a/src/shared/cplusplus/ASTVisitor.h
+++ b/src/shared/cplusplus/ASTVisitor.h
@@ -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 *) { }
diff --git a/src/shared/cplusplus/ASTfwd.h b/src/shared/cplusplus/ASTfwd.h
index d2a1d317d81..9bce5ec76e0 100644
--- a/src/shared/cplusplus/ASTfwd.h
+++ b/src/shared/cplusplus/ASTfwd.h
@@ -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;
diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp
index a9ede700cad..2eb017b2a1c 100644
--- a/src/shared/cplusplus/CheckDeclaration.cpp
+++ b/src/shared/cplusplus/CheckDeclaration.cpp
@@ -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;
-}
diff --git a/src/shared/cplusplus/CheckDeclaration.h b/src/shared/cplusplus/CheckDeclaration.h
index 6d06d42b9b0..269957257bb 100644
--- a/src/shared/cplusplus/CheckDeclaration.h
+++ b/src/shared/cplusplus/CheckDeclaration.h
@@ -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);
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index fd2efcf978c..845fabcfe50 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -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;
-- 
GitLab