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

List:       kdevelop-bugs
Subject:    [Bug 241793] Code completion fails on 'm_view' after
From:       Milian Wolff <mail () milianw ! de>
Date:       2010-10-03 17:35:36
Message-ID: 20101003173537.AD55571AF0 () immanuel ! kde ! org
[Download RAW message or body]

https://bugs.kde.org/show_bug.cgi?id=241793


Milian Wolff <mail@milianw.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED




--- Comment #3 from Milian Wolff <mail milianw de>  2010-10-03 19:35:20 ---
commit 47eb7eb2cc2539f2f16c8a524eae029b65ec23d7
Author: Milian Wolff <mail@milianw.de>
Date:   Sat Oct 2 10:48:54 2010 +0200

    fix: don't confuse the parser by comments after ambiguous declarations or
expressions

    BUG: 241793

diff --git a/languages/cpp/cppduchain/tests/test_duchain.cpp
b/languages/cpp/cppduchain/tests/test_duchain.cpp
index 0ccdce2..eda953e 100644
--- a/languages/cpp/cppduchain/tests/test_duchain.cpp
+++ b/languages/cpp/cppduchain/tests/test_duchain.cpp
@@ -5334,6 +5334,29 @@ void TestDUChain::testAutoTypes()
   }
 }

+void TestDUChain::testCommentAfterFunctionCall()
+{
+  // testcase for bug https://bugs.kde.org/show_bug.cgi?id=241793
+  
+  LockedTopDUContext top = parse("class View;\n"
+                                 "void setView(View* m_view) {\n"
+                                 "  setView(0);\n"
+                                 "  setView(m_view); //\n"
+                                 "}\n", DumpAll);
+  QVERIFY(top);
+  DUChainReadLocker lock;
+  QVERIFY(top->problems().isEmpty());
+
+  QCOMPARE(top->localDeclarations().size(), 2);
+  QCOMPARE(top->childContexts().size(), 2);
+
+  QCOMPARE(top->childContexts().first()->localDeclarations().size(), 1);
+  Declaration* m_view =
top->childContexts().first()->localDeclarations().first();
+
+  QVERIFY(top->childContexts().last()->localDeclarations().isEmpty());
+  QCOMPARE(m_view->uses().size(), 1);
+}
+
 KDevelop::TopDUContext* TestDUChain::parse(const QByteArray& unit, DumpAreas
dump, TopDUContext* update, bool keepAst)
 {
   if (dump)
diff --git a/languages/cpp/cppduchain/tests/test_duchain.h
b/languages/cpp/cppduchain/tests/test_duchain.h
index ac092e0..808d0ae 100644
--- a/languages/cpp/cppduchain/tests/test_duchain.h
+++ b/languages/cpp/cppduchain/tests/test_duchain.h
@@ -183,6 +183,7 @@ private slots:
   void testAutoTypeIntegral();
   void testAutoTypes();

+  void testCommentAfterFunctionCall();
 private:
   void assertNoMemberFunctionModifiers(KDevelop::ClassFunctionDeclaration*
memberFun);

diff --git a/languages/cpp/parser/parser.cpp b/languages/cpp/parser/parser.cpp
index 3c2eaed..94f23e6 100644
--- a/languages/cpp/parser/parser.cpp
+++ b/languages/cpp/parser/parser.cpp
@@ -2878,6 +2878,15 @@ bool Parser::parseStatement(StatementAST *&node)
   return parseExpressionOrDeclarationStatement(node);
 }

+//since advance includes comments, this checks for both, ; or ; //
+bool isValidExprOrDeclEnd(ParseSession* session) {
+  int prev = session->token_stream->kind(session->token_stream->cursor() - 1);
+  if (prev == Token_comment) {
+    prev = session->token_stream->kind(session->token_stream->cursor() - 2);
+  }
+  return prev == ';';
+}
+
 bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
 {
   // hold any errors while the expression/declaration ambiguity is resolved
@@ -2889,7 +2898,8 @@ bool
Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
   ///@todo solve -1 thing
   StatementAST *decl_ast = 0;
   bool maybe_amb = parseDeclarationStatement(decl_ast);
-  maybe_amb &= session->token_stream->kind(session->token_stream->cursor() -
1) == ';';
+  maybe_amb &= isValidExprOrDeclEnd(session);
+  maybe_amb &= isValidExprOrDeclEnd(session);

   // if parsing as a declaration succeeded, then any pending errors are
genuine.
   // Otherwise this is not a declaration so ignore the errors.
@@ -2903,7 +2913,7 @@ bool
Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
   rewind(start);
   StatementAST *expr_ast = 0;
   maybe_amb &= parseExpressionStatement(expr_ast);
-  maybe_amb &= session->token_stream->kind(session->token_stream->cursor() -
1) == ';';
+  maybe_amb &= isValidExprOrDeclEnd(session);

   // if parsing as an expression succeeded, then any pending errors are
genuine.
   // Otherwise this is not an expression so ignore the errors.
diff --git a/languages/cpp/parser/tests/test_parser.cpp
b/languages/cpp/parser/tests/test_parser.cpp
index 0c79d62..1e09838 100644
--- a/languages/cpp/parser/tests/test_parser.cpp
+++ b/languages/cpp/parser/tests/test_parser.cpp
@@ -571,6 +571,27 @@ private slots:
     QCOMPARE(propAst->final, isFinal);
   }

+  void testCommentAfterFunctionCall() {
+    //this is ambigous
+    pool memPool;
+    TranslationUnitAST* ast = parse("void setView() {\n"
+                                    "  setView(m_view); //\n"
+                                    "}\n", &memPool);
+
+    QVERIFY(ast != 0);
+
+    DumpTree dumper;
+    dumper.dump(ast, lastSession->token_stream);
+
+    QCOMPARE(ast->declarations->count(), 1);
+    QVERIFY(hasKind(ast, AST::Kind_FunctionDefinition));
+    FunctionDefinitionAST* funcAst =
static_cast<FunctionDefinitionAST*>(getAST(ast, AST::Kind_FunctionDefinition));
+    QVERIFY(hasKind(funcAst, AST::Kind_ExpressionOrDeclarationStatement));
+    ExpressionOrDeclarationStatementAST* ambAst =
static_cast<ExpressionOrDeclarationStatementAST*>(getAST(funcAst,
AST::Kind_ExpressionOrDeclarationStatement));
+    QVERIFY(hasKind(funcAst, AST::Kind_FunctionCall));
+    QVERIFY(hasKind(funcAst, AST::Kind_InitDeclarator));
+  }
+
 private:
   ParseSession* lastSession;

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

_______________________________________________
KDevelop-bugs mailing list
KDevelop-bugs@kdevelop.org
https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-bugs
[prev in list] [next in list] [prev in thread] [next in thread] 

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