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

List:       kde-commits
Subject:    KDE/kdevelop/plugins/managers/cmake
From:       Aleix Pol Gonzalez <aleixpol () gmail ! com>
Date:       2008-12-01 1:49:05
Message-ID: 1228096145.376401.10238.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 891050 by apol:

Improved the if() implementation

 M  +1 -0      parser/cmakecondition.cpp  
 M  +55 -68    parser/cmakeprojectvisitor.cpp  
 M  +50 -8     tests/cmake_cmakeprojectvisitor_test.cpp  
 M  +2 -2      tests/cmakeduchaintest.cpp  


--- trunk/KDE/kdevelop/plugins/managers/cmake/parser/cmakecondition.cpp \
#891049:891050 @@ -284,6 +284,7 @@
     QStringList::const_iterator it = expression.constBegin(), \
itEnd=expression.constEnd();  bool ret = evaluateCondition(it, itEnd-1);
     uint i=0;
+    m_argUses.clear();
     for(; it!=itEnd; ++it, ++i)
     {
         if(m_varUses.contains(it))
--- trunk/KDE/kdevelop/plugins/managers/cmake/parser/cmakeprojectvisitor.cpp \
#891049:891050 @@ -1032,85 +1032,72 @@
         const CMakeFunctionDesc d = ifast->content().at( ifast->line() );
         kWarning() << "Parser couldn't parse condition of an IF in file:" << \
ifast->condition() << d.filePath << d.line;  }
-    CMakeCondition cond(this);
-    bool result=cond.condition(ifast->condition());
-    QList<int> ini=cond.variableArguments();
-    usesForArguments(ifast->condition(), ini, m_topctx, \
ifast->content()[ifast->line()]);  
-    kDebug(9042) << "Visiting If" << ifast->condition() << "?" << result;
-    if(result)
-    {
-//         kDebug(9042) << "if executed, @" << lines; //<< "now:" << \
                ifast->content()[lines+1].writeBack();
-        lines+=walk(ifast->content(), lines+1)-lines;
-    }
-    else
-    {
-        int inside=0;
-//         kDebug(9042) << "if() was false, looking for an else/elseif @" << lines;
-        CMakeFileContent::const_iterator it=ifast->content().constBegin()+lines;
-        CMakeFileContent::const_iterator itEnd=ifast->content().constEnd();
+    int inside=0;
+//     kDebug(9042) << "if() was false, looking for an else/elseif @" << lines;
+    CMakeFileContent::const_iterator it=ifast->content().constBegin()+lines;
+    CMakeFileContent::const_iterator itEnd=ifast->content().constEnd();
 
-        for(; it!=itEnd; ++it, lines++)
+    bool visited=false;
+    QList<int> ini;
+    for(; it!=itEnd; ++it, lines++)
+    {
+        QString funcName=it->name.toLower();
+//         kDebug(9032) << "looking @" << lines << it->writeBack() << ">>" << inside \
<< visited; +        if(funcName=="if")
         {
-            QString funcName=it->name.toLower();
-//             kDebug(9032) << "looking @" << lines << it->writeBack() << ">>" << \
                inside;
-            if(funcName=="if")
+            inside++;
+        }
+        else if(funcName=="endif")
+        {
+            inside--;
+            if(inside<=0 && !it->arguments.isEmpty()) {
+                Q_ASSERT(!ini.isEmpty());
+                usesForArguments(ifast->condition(), ini, m_topctx, *it);     
+                break;
+            }
+//                 kDebug(9042) << "found an endif at:" << lines << "but" << inside;
+        }
+        
+        if(inside==1)
+        {
+            bool result;
+            
+            if(funcName=="if" || funcName=="elseif")
             {
-                inside++;
+                CMakeCondition cond(this);
+                IfAst myIf;
+                if(!myIf.parseFunctionInfo(*it))
+                    kDebug(9042) << "uncorrect condition correct" << \
it->writeBack(); +                result=cond.condition(myIf.condition());
+                QList<int> args=cond.variableArguments();
+                if(funcName=="if")
+                    ini=args;
+                usesForArguments(myIf.condition(), args, m_topctx, *it);
             }
-            else if(funcName=="endif")
+            else if(funcName=="else")
             {
-                inside--;
-                if(inside<=0) {
-                    usesForArguments(ifast->condition(), cond.variableArguments(), \
                m_topctx, *it);
-                    
-                    break;
-                }
-//                 kDebug(9042) << "found an endif at:" << lines << "but" << inside;
+                result=true;
+                usesForArguments(ifast->condition(), ini, m_topctx, *it);
             }
-            else if(inside==1 && funcName.startsWith("else"))
+            
+            if(!visited && result)
             {
-                if(funcName.endsWith("if")) //it is an else if
-                {
-//                     kDebug(9042) << "found an elseif" << it->writeBack();
-                    IfAst myIf;
-                    if(!myIf.parseFunctionInfo(*it))
-                        kDebug(9042) << "elseif not correct";
-                    if(cond.condition(myIf.condition()))
-                    {
-//                         kDebug(9042) << "which was true, calculating";
-                        lines = walk(ifast->content(), lines+1);
-                        break;
-                    }
-//                     else kDebug(9042) << "which was false";
-                }
-                else //it is an else
-                {
-//                     kDebug(9042) << "Found an else finally";
-                    lines = walk(ifast->content(), lines+1);
-                    break;
-                }
+                kDebug(9042) << "About to visit " << funcName << "?" << result;
+                
+                int oldpos=lines;
+                lines = walk(ifast->content(), lines+1)-1;
+                
+                it+=lines-oldpos;
+                
+                visited=true;
+//                 kDebug(9042) << "Visited. now in" << it->name;
             }
         }
     }
-
-//     kDebug(9042) << "looking for the endif now @" << lines;
-    CMakeFileContent::const_iterator it=ifast->content().constBegin()+lines;
-    CMakeFileContent::const_iterator itEnd=ifast->content().constEnd();
-    for(int inside=1; inside>0 && it!=itEnd; ++it, lines++)
-    {
-        QString funcName=it->name.toLower();
-        if(funcName=="if")
-            inside++;
-        else if(funcName=="endif") {
-            inside--;
-            if(inside<=0)
-                usesForArguments(ifast->condition(), ini, m_topctx, \
                ifast->content()[lines]);
-        }
-        kDebug(9042) << "endif???" << it->writeBack() << inside << lines;
-    }
-//     kDebug(9042) << "endif==" << ifast->content()[lines-1].writeBack() << "<>" << \
                ifast->condition() << '=' << lines-ifast->line() << "@" << lines;
-    return lines-ifast->line();
+//     kDebug() << "finish" << "<>" << ifast->condition() << '|' << \
lines-ifast->line() << '>' << lines; +//     kDebug(9042) << "endif==" << \
ifast->content()[lines].writeBack(); +    return lines-ifast->line()+1;
 }
 
 int CMakeProjectVisitor::visit(const ExecProgramAst *exec)
--- trunk/KDE/kdevelop/plugins/managers/cmake/tests/cmake_cmakeprojectvisitor_test.cpp \
#891049:891050 @@ -103,11 +103,6 @@
     results << StringPair("eee", "cmd");
     results << StringPair("fff", "cmd");
     results << StringPair("ggg", "cmd");
-    results << StringPair("FOOBAR", "ORT Basket Is Strange ABORT");
-    results << StringPair("RES", "Ok");
-    results << StringPair("BARFOO", "ORT Is Basket Strange? ABORT");
-    results << StringPair("BARFOO_MATCH", "Basket Is");
-    results << StringPair("BARFOO_MATCHALL", "Basket Is;Basket Is;Basket Is;Basket \
Is");  QTest::newRow("cache") <<
             "project(simpletest)\n"
             "cmake_minimum_required(VERSION 2.6)\n"
@@ -115,9 +110,19 @@
             "set(bbb script CACHE STRING HELLO)\n"
             "set(ccc script CACHE STRING HELLO FORCE)\n"
             "set(ddd script)\n"
+            "#message(STATUS \"ooooo- ${aaa} ${bbb} ${ccc} ${ddd}\")\n"
             "find_path(eee stdio.h /usr/include)\n"
             "find_library(fff stdio.h /usr/include)\n"
-            "find_program(ggg gcc /usr/gcc)\n"
+            "find_program(ggg gcc /usr/gcc)\n" << cacheValues << results;
+            
+    cacheValues.clear();
+    results.clear();
+    results << StringPair("FOOBAR", "ORT Basket Is Strange ABORT");
+    results << StringPair("RES", "Ok");
+    results << StringPair("BARFOO", "ORT Is Basket Strange? ABORT");
+    results << StringPair("BARFOO_MATCH", "Basket Is");
+    results << StringPair("BARFOO_MATCHALL", "Basket Is;Basket Is;Basket Is;Basket \
Is"); +    QTest::newRow("string") << 
             "set(FOOBAR \"ORT Basket Is Strange ABORT\")\n"
             "if( FOOBAR MATCHES \"^ORT Bas\")\n"
             "  set(RES Ok)\n"
@@ -127,13 +132,15 @@
             "string( REGEX REPLACE \"Basket ([a-zA-Z]*) ([a-zA-Z]*)\" \"\\\\1 Basket \
                \\\\2?\" BARFOO ${FOOBAR})\n"
             "string( REGEX MATCH \"Basket Is\" BARFOO_MATCH ${FOOBAR} ${RES} \
                ${FOOBAR})\n"
             "string( REGEX MATCHALL \"Basket Is\" BARFOO_MATCHALL ${FOOBAR} \
                \"${FOOBAR}${RES}${FOOBAR}\" ${FOOBAR})\n"
-            "#message(STATUS \"ooooo- ${aaa} ${bbb} ${ccc} ${ddd}\")\n" << \
cacheValues << results; +            << cacheValues << results;
             
     
     cacheValues.clear();
     results.clear();
     results << StringPair("kkk", "abcdef");
-    QTest::newRow("abc") << "set(a abc)\nset(b def)\nSET(kkk \"${a}${b}\")\n" << \
cacheValues << results; +    QTest::newRow("abc") << "set(a abc)\n"
+                            "set(b def)\n"
+                            "SET(kkk \"${a}${b}\")\n" << cacheValues << results;
     
     cacheValues.clear();
     results.clear();
@@ -229,6 +236,39 @@
                                "set(res 1)\n"
                             "endif(( ONE AND ZERO ) OR ( ZERO OR ONE ))\n"
                              << cacheValues << results;
+                             
+                             cacheValues.clear();
+    results.clear();
+    results << StringPair("res", "1");
+    results << StringPair("end", "1");
+    QTest::newRow("full conditional") <<
+                            "set(ONE TRUE)\n"
+                            "set(ZERO FALSE)\n"
+                            "if(ONE)\n"
+                               "set(res 1)\n"
+                               "set(res 1)\n"
+                            "else(ONE)\n"
+                               "set(res 0)\n"
+                               "set(res 0)\n"
+                            "endif(ONE)\n"
+                            "set(end 1)\n"
+                             << cacheValues << results;
+                             
+    results.clear();
+    results << StringPair("res", "1");
+    results << StringPair("end", "1");
+    QTest::newRow("full conditional.false") <<
+                            "set(ONE TRUE)\n"
+                            "set(ZERO FALSE)\n"
+                            "if(ZERO)\n"
+                               "set(res 0)\n"
+                               "set(res 0)\n"
+                            "else(ZERO)\n"
+                               "set(res 1)\n"
+                               "set(res 1)\n"
+                            "endif(ZERO)\n"
+                            "set(end 1)\n"
+                             << cacheValues << results;
 }
 
 void CMakeProjectVisitorTest::testRun()
@@ -264,6 +304,8 @@
         CMakeFunctionArgument arg;
         arg.value=vp.first;
         
+        qDebug() << "iiiii" << vm.value(vp.first).join(QString(";")) << vp.second;
+        
         QCOMPARE(vm.value(vp.first).join(QString(";")), vp.second);
     }
 }
--- trunk/KDE/kdevelop/plugins/managers/cmake/tests/cmakeduchaintest.cpp \
#891049:891050 @@ -144,14 +144,14 @@
             "include(included)\n"
             
             "macro(bla kk)\n"
-            " message(STATUS ${kk})\n"
+                "message(STATUS ${kk})\n"
             "endmacro(bla)\n"
             
             "set(usinginc aa${avalue})\n"
             "bla(kk)\n"
             
             "if(var)\n"
-            " message(STATUS \"life rocks\")\n"
+                "message(STATUS \"life rocks\")\n"
             "endif(var)\n"
             "message(STATUS \"------- done\")\n"
             );


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

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