From a831e865bef42a8ab86078074eb9a08f5ab4439f Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 30 Oct 2008 11:07:20 +0000 Subject: [PATCH] Declaration - expression ambiguity with function call on lhs of binary expression, bug 252695. --- .../core/parser/tests/ast2/AST2CPPTests.java | 21 +++++++++++++++++++ .../internal/index/tests/IndexBugsTests.java | 10 +++++++-- .../parser/AbstractGNUSourceCodeParser.java | 9 ++++---- .../dom/parser/cpp/GNUCPPSourceParser.java | 1 + 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 9f1b8e148b7..15a91c6d251 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -6186,4 +6186,25 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(decl, func); } } + + // class MyClass{ + // public: + // int v; + // int& operator () (int i){ return v; } + // int& operator () (int i, int j){ return v; } + // }; + // + // int main(MyClass c, int i){ + // c(i,i)= 0; + // c(i) = 0; + // } + public void testFunctionCallOnLHS_252695() throws Exception { + final String code = getAboveComment(); + IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.CPP, true); + IASTFunctionDefinition fdef= getDeclaration(tu, 1); + IASTExpressionStatement exstmt= getStatement(fdef, 0); + assertInstance(exstmt.getExpression(), IASTBinaryExpression.class); + exstmt= getStatement(fdef, 1); + assertInstance(exstmt.getExpression(), IASTBinaryExpression.class); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index 1585f6269a8..6fc8f60d55b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -117,8 +117,14 @@ public class IndexBugsTests extends BaseTestCase { return TestSourceReader.createFile(container, new Path(fileName), contents); } - private void waitForIndexer() { - assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEX_WAIT_TIME, NPM)); + private void waitForIndexer() throws InterruptedException { + final IIndexManager indexManager = CCorePlugin.getIndexManager(); + long waitms= 1; + while (waitms < 2000 && indexManager.isIndexerSetupPostponed(fCProject)) { + Thread.sleep(waitms); + waitms*=2; + } + assertTrue(indexManager.joinIndexer(INDEX_WAIT_TIME, NPM)); } protected Pattern[] getPattern(String qname) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 97aaf5fcc7a..ce190e833cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -100,6 +100,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected boolean supportExtendedSizeofOperator; protected final IBuiltinBindingsProvider builtinBindingsProvider; + protected boolean functionCallCanBeLValue= false; + /** * Marks the beginning of the current declaration. It is important to clear the mark whenever we * enter a nested declaration, in order to avoid holding on to all the tokens. @@ -1648,9 +1650,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // At this point we know we have an ambiguity. // Attempt to resolve some ambiguities that are easy to detect. - // A * B = C; - // foo() = x; - // These can get parsed as expressions but the lvalue doesn't make sense + // A * B = C; // A*B cannot be a lvalue. + // foo() = x; // foo() cannot be a lvalue in c, in c++ it can. if (expressionStatement.getExpression() instanceof IASTBinaryExpression) { IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement.getExpression(); if (exp.getOperator() == IASTBinaryExpression.op_assign) { @@ -1659,7 +1660,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { && ((IASTBinaryExpression) lhs).getOperator() == IASTBinaryExpression.op_multiply) { return ds; } - if (lhs instanceof IASTFunctionCallExpression) { + if (lhs instanceof IASTFunctionCallExpression && !functionCallCanBeLValue) { return ds; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index d9e6e33dca5..999d5659e1e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -206,6 +206,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { supportParameterInfoBlock= config.supportParameterInfoBlock(); supportExtendedSizeofOperator= config.supportExtendedSizeofOperator(); supportFunctionStyleAsm= config.supportFunctionStyleAssembler(); + functionCallCanBeLValue= true; this.index= index; }