[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdevelop/buildtools/managers/qmake/parser
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2008-10-05 10:16:27
Message-ID: 1223201787.901086.23074.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 868034 by apaku:

Fix an error in the custom Ast, a OrAST doesn't have an identifier, so the
identifier member from StatementAST needed to be moved down into the leaf
classes.
The rest of the commit are adjustments to building custom Ast and the tests to
account for this change


 M  +3 -1      ast.h  
 M  +24 -1     buildastvisitor.cpp  
 M  +12 -7     qmakeast.cpp  
 M  +1 -6      tests/testhelpers.cpp  
 M  +36 -2     tests/testhelpers.h  


--- trunk/KDE/kdevelop/buildtools/managers/qmake/parser/ast.h #868033:868034
@@ -70,7 +70,6 @@
         public:
             StatementAST( AST* parent, AST::Type type );
             ~StatementAST();
-            ValueAST* identifier;
     };
 
 
@@ -98,6 +97,7 @@
             explicit AssignmentAST( AST* parent );
             ~AssignmentAST();
 
+            ValueAST* identifier;
             ValueAST* op;
             QList<ValueAST*> values;
     };
@@ -116,6 +116,7 @@
         public:
             explicit FunctionCallAST( AST* parent );
             ~FunctionCallAST();
+            ValueAST* identifier;
             QList<ValueAST*> args;
     };
 
@@ -125,6 +126,7 @@
         public:
             explicit SimpleScopeAST( AST* parent );
             ~SimpleScopeAST();
+            ValueAST* identifier;
     };
 
     class KDEVQMAKEPARSER_EXPORT OrAST : public ScopeAST
--- trunk/KDE/kdevelop/buildtools/managers/qmake/parser/buildastvisitor.cpp \
#868033:868034 @@ -31,6 +31,19 @@
 namespace QMake
 {
 
+void setIdentifierForStatement( StatementAST* stmt, ValueAST* val )
+{
+    if( OrAST* orop = dynamic_cast<OrAST*>( stmt ) ) {
+        setIdentifierForStatement( orop->scopes.at(0), val );
+    } else if( AssignmentAST* assign = dynamic_cast<AssignmentAST*>( stmt ) ) {
+        assign->identifier = val;
+    } else if( FunctionCallAST* funcall = dynamic_cast<FunctionCallAST*>( stmt ) ) {
+        funcall->identifier = val;
+    } else if( SimpleScopeAST* simple = dynamic_cast<SimpleScopeAST*>( stmt ) ) {
+        simple->identifier = val;
+    }
+}
+
 BuildASTVisitor::BuildASTVisitor(Parser* parser, ProjectAST* project)
     : m_parser(parser)
 {
@@ -93,16 +106,20 @@
     if( node->orOperator )
     {
         OrAST* orast = createAst<OrAST>( node, aststack.top() );
+        qDebug() << "created orast:" << orast;
         if( node->functionArguments )
         {
             FunctionCallAST* ast = createAst<FunctionCallAST>( node, orast );
             aststack.push( ast );
+            qDebug() << "creating function call as first or-op" << ast;
             visitNode( node->functionArguments );
+            qDebug() << "function call done";
             aststack.pop();
             orast->scopes.append( ast );
         }else
         {
             SimpleScopeAST* simple = createAst<SimpleScopeAST>( node, orast );
+            qDebug() << "creating simple scope as first or-op";
             orast->scopes.append( simple );
         }
         aststack.push(orast);
@@ -157,15 +174,21 @@
     if( !node->isNewline )
     {
         StatementAST* stmt = stackPop<StatementAST>();
+        qDebug() << "got statement ast, setting value" << stmt;
         ValueAST* val = createAst<ValueAST>(node, stmt);
+        qDebug() << "created value ast:" << val;
         val->value = getTokenString( node->id );
+        qDebug() << "set value" << val << val->value;
         setPositionForToken( node->id, val );
         if( node->isExclam )
         {
+                qDebug() << "found exclam";
             val->value = '!'+val->value;
         }
-        stmt->identifier = val;
+        setIdentifierForStatement( stmt, val );
+
         ScopeBodyAST* scope = stackTop<ScopeBodyAST>();
+        qDebug() << "scope:" << scope;
         scope->statements.append(stmt);
     }
 }
--- trunk/KDE/kdevelop/buildtools/managers/qmake/parser/qmakeast.cpp #868033:868034
@@ -39,22 +39,22 @@
 {}
 
 StatementAST::StatementAST( AST* parent, AST::Type type )
-        : AST( parent, type ), identifier(0)
+        : AST( parent, type )
 {}
 
 StatementAST::~StatementAST( )
 {
-    delete identifier;
-    identifier = 0;
 }
 
 
 AssignmentAST::AssignmentAST( AST* parent )
-        : StatementAST( parent, AST::Assignment )
+        : StatementAST( parent, AST::Assignment ), identifier(0)
 {}
 
 AssignmentAST::~AssignmentAST()
 {
+    delete identifier;
+    identifier = 0;
     qDeleteAll( values );
     values.clear();
     delete op;
@@ -72,12 +72,14 @@
 
 
 FunctionCallAST::FunctionCallAST( AST* parent )
-        : ScopeAST( parent, AST::FunctionCall )
+        : ScopeAST( parent, AST::FunctionCall ), identifier(0)
 {}
 
 
 FunctionCallAST::~FunctionCallAST()
 {
+    delete identifier;
+    identifier = 0;
     qDeleteAll( args );
     args.clear();
 }
@@ -111,11 +113,14 @@
 }
 
 SimpleScopeAST::SimpleScopeAST( AST* parent )
-        : ScopeAST( parent, AST::SimpleScope )
+        : ScopeAST( parent, AST::SimpleScope ), identifier(0)
 {}
 
 SimpleScopeAST::~SimpleScopeAST()
-{}
+{
+    delete identifier;
+    identifier = 0;
+}
 
 }
 
--- trunk/KDE/kdevelop/buildtools/managers/qmake/parser/tests/testhelpers.cpp \
#868033:868034 @@ -58,12 +58,7 @@
 
             }else if( orop && testorop )
             {
-                for(int i = 0; i < orop->scopes.count(); i++ )
-                {
-                    QVERIFY( i < testorop->scopes.count() );
-                    TESTFUNCNAME( orop->scopes.at(i),
-                                testorop->scopes.at(i)->identifier->value )
-                }
+                TESTOROPAST( orop, testorop )
             }
             QVERIFY( ( scope->body && testscope->body )
                         || ( !scope->body && !testscope->body ) );
--- trunk/KDE/kdevelop/buildtools/managers/qmake/parser/tests/testhelpers.h \
#868033:868034 @@ -74,7 +74,13 @@
 
 #define TESTFUNCNAME( scopeast, funcname ) \
     QVERIFY( scopeast ); \
-    QVERIFY( scopeast->identifier->value == funcname );
+    if( QMake::SimpleScopeAST* simpleast = dynamic_cast<QMake::SimpleScopeAST*>( \
scopeast ) ) \ +    { \
+        QVERIFY( simpleast->identifier->value == funcname );\
+    } else if( QMake::FunctionCallAST* funast = \
dynamic_cast<QMake::FunctionCallAST*>( scopeast ) ) \ +    { \
+        QVERIFY( funast->identifier->value == funcname );\
+    }
 
 #define TESTSCOPENAME( scopeast, scopename ) \
     QVERIFY( scopeast ); \
@@ -84,7 +90,13 @@
     for( int i = 0; i < funclist.size(); i++) \
     {\
         QVERIFY( i < scopeast->scopes.count() );\
-        QVERIFY( scopeast->scopes.at(i)->identifier->value == funclist.at(i) );\
+        if( QMake::SimpleScopeAST* simpleast = dynamic_cast<QMake::SimpleScopeAST*>( \
scopeast->scopes.at(i) ) ) \ +        { \
+            QVERIFY( simpleast->identifier->value == funclist.at(i) );\
+        } else if( QMake::FunctionCallAST* funast = \
dynamic_cast<QMake::FunctionCallAST*>( scopeast->scopes.at(i) ) ) \ +        { \
+            QVERIFY( funast->identifier->value == funclist.at(i) );\
+        } \
     }
 
 #define TESTSCOPEBODY( scope, teststmts, stmtcount ) \
@@ -92,7 +104,29 @@
     QVERIFY( scope->body->statements.count() == stmtcount ); \
     matchScopeBodies(scope->body->statements, teststmts);
 
+#define TESTSCOPEAST( scope, testscope ) \
+    QVERIFY( scope ); \
+    QVERIFY( testscope ); \
+    QMake::SimpleScopeAST* simple = dynamic_cast<QMake::SimpleScopeAST*>( scope ); \
+    QMake::SimpleScopeAST* testsimple = dynamic_cast<QMake::SimpleScopeAST*>( scope \
); \ +    QMake::FunctionCallAST* fun = dynamic_cast<QMake::FunctionCallAST*>( scope \
); \ +    QMake::FunctionCallAST* testfun = dynamic_cast<QMake::FunctionCallAST*>( \
scope ); \ +    QVERIFY( ( simple && testsimple ) || ( fun && testfun ) ); \
+    if( simple ) \
+    { \
+        QVERIFY( simple->identifier->value == testsimple->identifier->value ); \
+    } else \
+    { \
+        QVERIFY( fun->identifier->value == testfun->identifier->value ); \
+    }
 
+#define TESTOROPAST(orop,testorop) \
+    for(int i = 0; i < orop->scopes.count(); i++ ) \
+    { \
+        QVERIFY( i < testorop->scopes.count() ); \
+        TESTSCOPEAST( orop->scopes.at(i), testorop->scopes.at(i) ) \
+    }
+
 void matchScopeBodies( QList<QMake::StatementAST*>,
                              QList<QMake::StatementAST*> );
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic