From a091e59733b34837caa8ba2ad21e2a01a42a88f2 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 21 Jan 2009 14:57:44 +0000 Subject: [PATCH] Removes the need to flush the cache of c-scopes, bug 259373. --- .../core/parser/tests/ast2/AST2KnRTests.java | 22 - .../cdt/core/parser/tests/ast2/AST2Tests.java | 293 ++++---- .../core/dom/ast/IASTFunctionDeclarator.java | 7 +- .../ast/IASTStandardFunctionDeclarator.java | 14 +- .../ASTAmbiguousBinaryVsCastExpression.java | 6 - ...AmbiguousCastVsFunctionCallExpression.java | 6 - .../core/dom/parser/ASTAmbiguousNode.java | 12 - .../internal/core/dom/parser/ASTInternal.java | 26 - .../core/dom/parser/DeclarationOptions.java | 4 +- .../IASTAmbiguousSimpleDeclaration.java | 21 + .../core/dom/parser/IASTInternalScope.java | 7 + .../core/dom/parser/ProblemBinding.java | 3 + .../core/dom/parser/c/CASTAmbiguity.java | 23 - .../dom/parser/c/CASTAmbiguityResolver.java | 37 +- .../dom/parser/c/CASTAmbiguousDeclarator.java | 14 +- .../dom/parser/c/CASTAmbiguousExpression.java | 10 +- .../c/CASTAmbiguousParameterDeclaration.java | 14 +- .../c/CASTAmbiguousSimpleDeclaration.java | 120 +++ .../dom/parser/c/CASTAmbiguousStatement.java | 17 +- .../parser/c/CASTCompositeTypeSpecifier.java | 20 +- .../parser/c/CASTDeclarationStatement.java | 21 +- .../dom/parser/c/CASTFunctionDeclarator.java | 34 +- .../dom/parser/c/CASTSimpleDeclaration.java | 32 +- .../dom/parser/c/CASTTranslationUnit.java | 20 +- .../dom/parser/c/CCompositeTypeScope.java | 52 +- .../internal/core/dom/parser/c/CScope.java | 489 +++++++----- .../core/dom/parser/c/CStructure.java | 174 +++-- .../internal/core/dom/parser/c/CVisitor.java | 705 +++++------------- .../core/dom/parser/c/GNUCSourceParser.java | 17 +- .../core/dom/parser/cpp/CPPASTAmbiguity.java | 22 - .../parser/cpp/CPPASTAmbiguousDeclarator.java | 3 +- .../parser/cpp/CPPASTAmbiguousExpression.java | 10 +- .../parser/cpp/CPPASTAmbiguousStatement.java | 3 +- .../cpp/CPPASTAmbiguousTemplateArgument.java | 10 +- .../core/dom/parser/cpp/CPPClassType.java | 11 +- .../dom/parser/cpp/ICPPASTInternalScope.java | 7 - .../core/pdom/dom/c/PDOMCStructure.java | 25 +- .../CompletionTest_SingleName_NoPrefix.java | 7 +- .../DOMCompletionProposalComputer.java | 17 +- .../dom/lrparser/c99/bindings/C99Scope.java | 17 +- 40 files changed, 1178 insertions(+), 1174 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index ee35ca7e0e0..6e93f10838a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -101,10 +101,6 @@ public class AST2KnRTests extends AST2BaseTest { assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - CVisitor.clearBindings(tu); - assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$ - assertNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - } public void testSimpleKRCTest2() throws Exception { @@ -136,10 +132,6 @@ public class AST2KnRTests extends AST2BaseTest { assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - CVisitor.clearBindings(tu); - assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$ - assertNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - } public void testSimpleKRCTest3() throws Exception { @@ -209,11 +201,6 @@ public class AST2KnRTests extends AST2BaseTest { assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$ - CVisitor.clearBindings(tu); - assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$ - assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$ - } public void testKRCWithTypes() throws Exception { @@ -268,10 +255,6 @@ public class AST2KnRTests extends AST2BaseTest { assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - CVisitor.clearBindings(tu); - assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$ - assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$ -// assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ } public void testKRCProblem1() throws Exception { @@ -519,11 +502,6 @@ public class AST2KnRTests extends AST2BaseTest { assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$ assertNotNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - CVisitor.clearBindings(tu); - assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$ - assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$ -// assertNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$ - } public void testKRC_monop_cards2() throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index c4f8509597b..860c15fb9a2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -926,89 +926,108 @@ public class AST2Tests extends AST2BaseTest { // b; // } public void testFunctionParameters() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + final String code = getAboveComment(); + IASTTranslationUnit tu = parse(code, ParserLanguage.C); assertTrue(tu.isFrozen()); - for (int i = 0; i < NUM_TESTS; i++) { - // void f( - IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu - .getDeclarations()[0]; - IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) f_decl - .getDeclarators()[0]; - IASTName f_name1 = dtor.getName(); - // int a); - IASTParameterDeclaration param1 = dtor.getParameters()[0]; - IASTDeclarator paramDtor = param1.getDeclarator(); - IASTName name_param1 = paramDtor.getName(); - - // void f( - IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu - .getDeclarations()[1]; - assertTrue(f_defn.getDeclarator() instanceof IASTStandardFunctionDeclarator); - dtor = (IASTStandardFunctionDeclarator) f_defn.getDeclarator(); - IASTName f_name2 = dtor.getName(); - // int b); - IASTParameterDeclaration param2 = dtor.getParameters()[0]; - paramDtor = param2.getDeclarator(); - IASTName name_param2 = paramDtor.getName(); - - // b; - IASTCompoundStatement compound = (IASTCompoundStatement) f_defn - .getBody(); - IASTExpressionStatement expStatement = (IASTExpressionStatement) compound - .getStatements()[0]; - IASTIdExpression idexp = (IASTIdExpression) expStatement - .getExpression(); - IASTName name_param3 = idexp.getName(); - - // bindings - IParameter param_1 = (IParameter) name_param3.resolveBinding(); - IParameter param_2 = (IParameter) name_param2.resolveBinding(); - IParameter param_3 = (IParameter) name_param1.resolveBinding(); - IFunction f_1 = (IFunction) f_name1.resolveBinding(); - IFunction f_2 = (IFunction) f_name2.resolveBinding(); - - assertNotNull(param_1); - assertNotNull(f_1); - assertSame(param_1, param_2); - assertSame(param_2, param_3); - assertSame(f_1, f_2); - - CVisitor.clearBindings(tu); - param_1 = (IParameter) name_param1.resolveBinding(); - param_2 = (IParameter) name_param3.resolveBinding(); - param_3 = (IParameter) name_param2.resolveBinding(); - f_1 = (IFunction) f_name2.resolveBinding(); - f_2 = (IFunction) f_name1.resolveBinding(); - assertNotNull(param_1); - assertNotNull(f_1); - assertSame(param_1, param_2); - assertSame(param_2, param_3); - assertSame(f_1, f_2); - - // test tu.getDeclarationsInAST(IBinding) - IASTName[] decls = tu.getDeclarationsInAST(f_name1.resolveBinding()); - assertEquals(decls.length, 2); - assertEquals(decls[0], f_name1); - assertEquals(decls[1], f_name2); - - decls = tu.getDeclarationsInAST(name_param1.resolveBinding()); - assertEquals(decls.length, 2); - assertEquals(decls[0], name_param1); - assertEquals(decls[1], name_param2); - - decls = tu.getDeclarationsInAST(f_name2.resolveBinding()); - assertEquals(decls.length, 2); - assertEquals(decls[0], f_name1); - assertEquals(decls[1], f_name2); - - decls = tu.getDeclarationsInAST(name_param2.resolveBinding()); - assertEquals(decls.length, 2); - assertEquals(decls[0], name_param1); - assertEquals(decls[1], name_param2); - - tu = validateCopy(tu); - } + // void f( + IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; + IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) f_decl.getDeclarators()[0]; + IASTName f_name1 = dtor.getName(); + // int a); + IASTParameterDeclaration param1 = dtor.getParameters()[0]; + IASTDeclarator paramDtor = param1.getDeclarator(); + IASTName name_param1 = paramDtor.getName(); + + // void f( + IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu.getDeclarations()[1]; + assertTrue(f_defn.getDeclarator() instanceof IASTStandardFunctionDeclarator); + dtor = (IASTStandardFunctionDeclarator) f_defn.getDeclarator(); + IASTName f_name2 = dtor.getName(); + // int b); + IASTParameterDeclaration param2 = dtor.getParameters()[0]; + paramDtor = param2.getDeclarator(); + IASTName name_param2 = paramDtor.getName(); + + // b; + IASTCompoundStatement compound = (IASTCompoundStatement) f_defn.getBody(); + IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements()[0]; + IASTIdExpression idexp = (IASTIdExpression) expStatement.getExpression(); + IASTName name_param3 = idexp.getName(); + + // bindings + IParameter param_1 = (IParameter) name_param3.resolveBinding(); + IParameter param_2 = (IParameter) name_param2.resolveBinding(); + IParameter param_3 = (IParameter) name_param1.resolveBinding(); + IFunction f_1 = (IFunction) f_name1.resolveBinding(); + IFunction f_2 = (IFunction) f_name2.resolveBinding(); + + assertNotNull(param_1); + assertNotNull(f_1); + assertSame(param_1, param_2); + assertSame(param_2, param_3); + assertSame(f_1, f_2); + + tu = parse(code, ParserLanguage.C); + assertTrue(tu.isFrozen()); + // void f( + f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; + dtor = (IASTStandardFunctionDeclarator) f_decl.getDeclarators()[0]; + f_name1 = dtor.getName(); + // int a); + param1 = dtor.getParameters()[0]; + paramDtor = param1.getDeclarator(); + name_param1 = paramDtor.getName(); + + // void f( + f_defn = (IASTFunctionDefinition) tu.getDeclarations()[1]; + dtor = (IASTStandardFunctionDeclarator) f_defn.getDeclarator(); + f_name2 = dtor.getName(); + // int b); + param2 = dtor.getParameters()[0]; + paramDtor = param2.getDeclarator(); + name_param2 = paramDtor.getName(); + + // b; + compound = (IASTCompoundStatement) f_defn.getBody(); + expStatement = (IASTExpressionStatement) compound.getStatements()[0]; + idexp = (IASTIdExpression) expStatement.getExpression(); + name_param3 = idexp.getName(); + + // bindings + param_1 = (IParameter) name_param1.resolveBinding(); + param_2 = (IParameter) name_param3.resolveBinding(); + param_3 = (IParameter) name_param2.resolveBinding(); + f_1 = (IFunction) f_name2.resolveBinding(); + f_2 = (IFunction) f_name1.resolveBinding(); + assertNotNull(param_1); + assertNotNull(f_1); + assertSame(param_1, param_2); + assertSame(param_2, param_3); + assertSame(f_1, f_2); + + // test tu.getDeclarationsInAST(IBinding) + IASTName[] decls = tu.getDeclarationsInAST(f_name1.resolveBinding()); + assertEquals(decls.length, 2); + assertEquals(decls[0], f_name1); + assertEquals(decls[1], f_name2); + + decls = tu.getDeclarationsInAST(name_param1.resolveBinding()); + assertEquals(decls.length, 2); + assertEquals(decls[0], name_param1); + assertEquals(decls[1], name_param2); + + decls = tu.getDeclarationsInAST(f_name2.resolveBinding()); + assertEquals(decls.length, 2); + assertEquals(decls[0], f_name1); + assertEquals(decls[1], f_name2); + + decls = tu.getDeclarationsInAST(name_param2.resolveBinding()); + assertEquals(decls.length, 2); + assertEquals(decls[0], name_param1); + assertEquals(decls[1], name_param2); + + tu = validateCopy(tu); } // void f(int a, int b) { } @@ -1219,52 +1238,42 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { - IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) tu - .getDeclarations()[0]; - IASTCompositeTypeSpecifier compType = (IASTCompositeTypeSpecifier) simpleDecl - .getDeclSpecifier(); - IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) compType - .getMembers()[0]; + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; + IASTCompositeTypeSpecifier compType = (IASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier(); + IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) compType.getMembers()[0]; IASTName name_x1 = decl_x.getDeclarators()[0].getName(); - IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu - .getDeclarations()[1]; + IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTCompoundStatement body = (IASTCompoundStatement) fdef.getBody(); - IASTExpressionStatement expStatement = (IASTExpressionStatement) body - .getStatements()[0]; - IASTFieldReference fieldRef = (IASTFieldReference) expStatement - .getExpression(); + IASTExpressionStatement expStatement = (IASTExpressionStatement) body.getStatements()[0]; + IASTFieldReference fieldRef = (IASTFieldReference) expStatement.getExpression(); IASTName name_x2 = fieldRef.getFieldName(); - + IField x1 = (IField) name_x1.resolveBinding(); IField x2 = (IField) name_x2.resolveBinding(); - + assertNotNull(x1); assertSame(x1, x2); - + // test tu.getDeclarationsInAST(IBinding) - IASTName[] decls = tu.getDeclarationsInAST(compType.getName() - .resolveBinding()); + IASTName[] decls = tu.getDeclarationsInAST(compType.getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], compType.getName()); - + decls = tu.getDeclarationsInAST(name_x1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x1); - - decls = tu.getDeclarationsInAST(fdef.getDeclarator().getName() - .resolveBinding()); + + decls = tu.getDeclarationsInAST(fdef.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fdef.getDeclarator().getName()); - - IASTCastExpression castExpression = (IASTCastExpression) ((IASTUnaryExpression) ((IASTFieldReference) expStatement - .getExpression()).getFieldOwner()).getOperand(); - IASTElaboratedTypeSpecifier elaboratedTypeSpecifier = ((IASTElaboratedTypeSpecifier) castExpression - .getTypeId().getDeclSpecifier()); - decls = tu.getDeclarationsInAST(elaboratedTypeSpecifier.getName() - .resolveBinding()); + + IASTCastExpression castExpression = (IASTCastExpression) ((IASTUnaryExpression) ((IASTFieldReference) expStatement.getExpression()).getFieldOwner()) + .getOperand(); + IASTElaboratedTypeSpecifier elaboratedTypeSpecifier = ((IASTElaboratedTypeSpecifier) castExpression.getTypeId().getDeclSpecifier()); + decls = tu.getDeclarationsInAST(elaboratedTypeSpecifier.getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], compType.getName()); - + decls = tu.getDeclarationsInAST(name_x2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x1); @@ -2954,22 +2963,23 @@ public class AST2Tests extends AST2BaseTest { // struct s { double i; } f(void); // struct s f(void) {} public void testBug84266() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + final String code = getAboveComment(); + IASTTranslationUnit tu = parse(code, ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - assertEquals(col.size(), 7); - + ICompositeType s_ref = (ICompositeType) col.getName(4).resolveBinding(); - ICompositeType s_decl = (ICompositeType) col.getName(0) - .resolveBinding(); - + ICompositeType s_decl = (ICompositeType) col.getName(0).resolveBinding(); assertSame(s_ref, s_decl); - CVisitor.clearBindings(tu); - + + tu = parse(code, ParserLanguage.C); + col = new CNameCollector(); + tu.accept(col); + assertEquals(col.size(), 7); + s_decl = (ICompositeType) col.getName(0).resolveBinding(); s_ref = (ICompositeType) col.getName(4).resolveBinding(); - assertSame(s_ref, s_decl); } @@ -3000,23 +3010,25 @@ public class AST2Tests extends AST2BaseTest { // struct s1 { struct s2 *s2p; /* ... */ }; // D1 // struct s2 { struct s1 *s1p; /* ... */ }; // D2 - public void testBug84186() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + public void testBug84186() throws Exception { + final String code = getAboveComment(); + IASTTranslationUnit tu = parse(code, ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - assertEquals(col.size(), 6); - + ICompositeType s_ref = (ICompositeType) col.getName(1).resolveBinding(); - ICompositeType s_decl = (ICompositeType) col.getName(3) - .resolveBinding(); - + ICompositeType s_decl = (ICompositeType) col.getName(3).resolveBinding(); assertSame(s_ref, s_decl); - CVisitor.clearBindings(tu); + + tu = parse(code, ParserLanguage.C); + col = new CNameCollector(); + tu.accept(col); + assertEquals(col.size(), 6); + s_decl = (ICompositeType) col.getName(3).resolveBinding(); s_ref = (ICompositeType) col.getName(1).resolveBinding(); - assertSame(s_ref, s_decl); } @@ -3161,10 +3173,11 @@ public class AST2Tests extends AST2BaseTest { IParameter p = (IParameter) col.getName(1).resolveBinding(); IVariable v1 = (IVariable) col.getName(2).resolveBinding(); - IScope scope = f.getFunctionScope(); + IASTFunctionDefinition fdef= getDeclaration(tu, 0); + IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope(); IBinding[] bs = scope.find("par"); //$NON-NLS-1$ - assertEquals(bs.length, 1); + assertEquals(1, bs.length); assertSame(bs[0], p); bs = scope.find("v1"); //$NON-NLS-1$ @@ -3191,7 +3204,8 @@ public class AST2Tests extends AST2BaseTest { IVariable S3 = (IVariable) col.getName(3).resolveBinding(); ILabel S4 = (ILabel) col.getName(4).resolveBinding(); - IScope scope = f.getFunctionScope(); + IASTFunctionDefinition fdef= getDeclaration(tu, 2); + IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope(); IBinding[] bs = scope.find("S"); //$NON-NLS-1$ @@ -5162,7 +5176,7 @@ public class AST2Tests extends AST2BaseTest { // int a,b; // { b; a; int a; } // } - public void _testLocalVariableResolution_Bug235831() throws Exception { + public void testLocalVariableResolution_Bug235831() throws Exception { final String comment= getAboveComment(); final boolean[] isCpps= {false, true}; for (boolean isCpp : isCpps) { @@ -5901,4 +5915,17 @@ public class AST2Tests extends AST2BaseTest { assertInstance(expr, IASTBinaryExpression.class); } } + + // typedef int TInt; + // struct X { + // const TInt; // declaration without name + // const a; // declares a; + // }; + public void testAmbiguousDeclaration_Bug259373() throws Exception { + final String code= getAboveComment(); + IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.C, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, false); + ITypedef td= bh.assertNonProblem("TInt; //", 4); + IField f= bh.assertNonProblem("a;", 1); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java index 4a14698d62b..30bb9b002e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java @@ -1,19 +1,20 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * Doug Schaefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; /** * This is a declarator for a function. * - * @author Doug Schaefer + * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTFunctionDeclarator extends IASTDeclarator { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java index 82b1fd5eb6c..2206991932e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStandardFunctionDeclarator.java @@ -1,19 +1,20 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * Doug Schaefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; /** * This is a declarator for a non K&R C function. * - * @author Doug Schaefer + * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTStandardFunctionDeclarator extends IASTFunctionDeclarator { @@ -26,6 +27,13 @@ public interface IASTStandardFunctionDeclarator extends IASTFunctionDeclarator { public final static ASTNodeProperty FUNCTION_PARAMETER = new ASTNodeProperty( "IASTStandardFunctionDeclarator.FUNCTION_PARAMETER - IASTParameterDeclaration for IASTStandardFunctionDeclarator"); //$NON-NLS-1$ + /** + * Get the scope for this declarator. Returns null, if this declarator does not + * declare a function-prototype or function-definition. + * @since 5.1 + */ + public IScope getFunctionScope(); + /** * Gets the parameter declarations for the function * diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java index 28631bb8055..f9542763276 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java @@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.core.runtime.Assert; @@ -56,11 +55,6 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod return CVisitor.getExpressionType(getExpressions()[0]); } - @Override - protected final IScope getAffectedScope() { - return null; - } - @Override public final IASTNode[] getNodes() { return getExpressions(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java index d63789de889..a52043da8c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java @@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.Assert; @@ -46,11 +45,6 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu fFunctionCallExpression= functionCall; } - @Override - protected final IScope getAffectedScope() { - return null; - } - @Override public final IASTNode[] getNodes() { return getExpressions(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java index 7e0fb66277b..0e9a68c853c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java @@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -56,11 +55,6 @@ public abstract class ASTAmbiguousNode extends ASTNode { * Return the alternative nodes for this ambiguity. */ public abstract IASTNode[] getNodes(); - - /** - * Returns the scope that may get polluted by alternatives of this ambiguity. - */ - protected abstract IScope getAffectedScope(); @Override public final boolean accept(ASTVisitor visitor) { @@ -76,7 +70,6 @@ public abstract class ASTAmbiguousNode extends ASTNode { public IASTNode resolveAmbiguity(ASTVisitor resolver) { beforeResolution(); - final IScope scope= getAffectedScope(); final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); IASTNode nodeToReplace= this; @@ -85,10 +78,6 @@ public abstract class ASTAmbiguousNode extends ASTNode { int minIssues = Integer.MAX_VALUE; for (IASTNode alternative : alternatives) { - // flush scope, even if this is the first alternative. The ambiguous node may have contributed an - // invalid binding to the scope during the resolution of other ambiguous nodes. - ASTInternal.flushCache(scope); - // setup the ast to use the alternative owner.replace(nodeToReplace, alternative); nodeToReplace= alternative; @@ -145,7 +134,6 @@ public abstract class ASTAmbiguousNode extends ASTNode { // switch back to the best alternative, if necessary. if (nodeToReplace != bestAlternative) { - ASTInternal.flushCache(scope); owner.replace(nodeToReplace, bestAlternative); } return bestAlternative; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java index d1a461a9010..7fe8c4ce1ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java @@ -17,7 +17,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.internal.core.dom.parser.c.CScope; import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; @@ -43,37 +42,12 @@ public class ASTInternal { return null; } - public static void flushCache(IScope scope) { - if (scope instanceof CScope) { - ((CScope) scope).flushCache(); - } - } - - public static boolean isFullyCached(IScope scope) throws DOMException { - if (scope instanceof CScope) { - return ((CScope) scope).isFullyCached(); - } - return true; - } - - public static void setFullyCached(IScope scope, boolean val) throws DOMException { - if (scope instanceof CScope) { - ((CScope) scope).setFullyCached(val); - } - } - public static void addBinding(IScope scope, IBinding binding) throws DOMException { if (scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).addBinding(binding); } } - public static void removeBinding(IScope scope, IBinding binding) throws DOMException { - if (scope instanceof CScope) { - ((CScope) scope).removeBinding(binding); - } - } - public static void addName(IScope scope, IASTName name) { if (scope instanceof IASTInternalScope) { try { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java index 2204345a5b6..d931db2fcc1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,7 +28,7 @@ public class DeclarationOptions { public static final DeclarationOptions GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_CONSTRUCTOR_INITIALIZER), FUNCTION_STYLE_ASM= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | NO_INITIALIZER), - C_MEMBER= new DeclarationOptions(ALLOW_BITFIELD), + C_MEMBER= new DeclarationOptions(ALLOW_BITFIELD | ALLOW_ABSTRACT), CPP_MEMBER= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD | ALLOW_CONSTRUCTOR_INITIALIZER), LOCAL= new DeclarationOptions(ALLOW_CONSTRUCTOR_INITIALIZER), PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT), diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java new file mode 100644 index 00000000000..14c61f38e4b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser; + +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; + +/** + * Needed to handle the ambiguity for simple declarations in plain C + * @since 5.1 + */ +public interface IASTAmbiguousSimpleDeclaration extends IASTSimpleDeclaration { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java index c58d4830df9..8b8ebb65894 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java @@ -41,4 +41,11 @@ public interface IASTInternalScope extends IScope { * @throws DOMException */ public void addName(IASTName name) throws DOMException; + + /** + * Can be called during ambiguity resolution to populate a scope without considering + * the ambiguous branches. The rest of the names has to be cached one by one after + * the ambiguities have been resolved. + */ + public void populateCache(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index af7955f1a55..76f7474b1ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -239,4 +239,7 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I this.arg= null; } } + + public void populateCache() { + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java deleted file mode 100644 index 3e04a1193c6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser.c; - -import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; - -public abstract class CASTAmbiguity extends ASTAmbiguousNode { - - @Override - protected IScope getAffectedScope() { - return CVisitor.getContainingScope(this); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java index e3ada63e2eb..c882343265d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java @@ -11,6 +11,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; /** @@ -25,7 +33,34 @@ public final class CASTAmbiguityResolver extends ASTVisitor { @Override public int visit(ASTAmbiguousNode astAmbiguousNode) { - astAmbiguousNode.resolveAmbiguity(this); + IASTNode node= astAmbiguousNode.resolveAmbiguity(this); + if (node instanceof IASTDeclarator || node instanceof IASTParameterDeclaration + || node instanceof IASTDeclaration) { + while(node != null) { + if (node instanceof IASTDeclaration || node instanceof IASTParameterDeclaration) { + repopulateScope(node); + break; + } + if (node instanceof IASTExpression) { + break; + } + node= node.getParent(); + } + } else if (node instanceof IASTDeclarationStatement) { + repopulateScope(((IASTDeclarationStatement) node).getDeclaration()); + } return PROCESS_SKIP; } + + private void repopulateScope(IASTNode node) { + IScope scope= CVisitor.getContainingScope(node); + if (scope instanceof CScope) { + CScope cscope = (CScope) scope; + if (scope instanceof ICCompositeTypeScope) { + cscope.markAsUncached(); + } else { + cscope.collectNames(node); + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java index 93df7c19a0e..63de5712bea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java @@ -15,8 +15,11 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator; +import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.core.runtime.Assert; /** @@ -25,7 +28,7 @@ import org.eclipse.core.runtime.Assert; * Example: void f(int (D)); // is D a type? * @since 5.0.1 */ -public class CASTAmbiguousDeclarator extends CASTAmbiguity implements IASTAmbiguousDeclarator { +public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmbiguousDeclarator { private IASTDeclarator[] dtors = new IASTDeclarator[2]; private int dtorPos=-1; @@ -38,6 +41,15 @@ public class CASTAmbiguousDeclarator extends CASTAmbiguity implements IASTAmbigu } } } + + @Override + protected void beforeResolution() { + // populate containing scope, so that it will not be affected by the alternative branches. + IScope scope= CVisitor.getContainingScope(this); + if (scope instanceof IASTInternalScope) { + ((IASTInternalScope) scope).populateCache(); + } + } public void addDeclarator(IASTDeclarator d) { assertNotFrozen(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java index d44fc40f560..08014b11568 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java @@ -13,12 +13,12 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; -public class CASTAmbiguousExpression extends CASTAmbiguity implements IASTAmbiguousExpression { +public class CASTAmbiguousExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression { private IASTExpression [] expressions = new IASTExpression[2]; private int expressionsPos=-1; @@ -29,12 +29,6 @@ public class CASTAmbiguousExpression extends CASTAmbiguity implements IASTAmbigu addExpression(e); } - @Override - protected IScope getAffectedScope() { - // an expression cannot pollute a parent scope - return null; - } - public void addExpression(IASTExpression e) { assertNotFrozen(); if (e != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java index 04abe4b0a9a..870e1097c4e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java @@ -14,8 +14,11 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousParameterDeclaration; +import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.core.runtime.Assert; /** @@ -24,7 +27,7 @@ import org.eclipse.core.runtime.Assert; * void function(const D*); // is D a type? * @since 5.0.1 */ -public class CASTAmbiguousParameterDeclaration extends CASTAmbiguity implements IASTAmbiguousParameterDeclaration { +public class CASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implements IASTAmbiguousParameterDeclaration { private IASTParameterDeclaration[] paramDecls = new IASTParameterDeclaration[2]; private int declPos=-1; @@ -44,6 +47,15 @@ public class CASTAmbiguousParameterDeclaration extends CASTAmbiguity implements } } + @Override + protected void beforeResolution() { + // populate containing scope, so that it will not be affected by the alternative branches. + IScope scope= CVisitor.getContainingScope(this); + if (scope instanceof IASTInternalScope) { + ((IASTInternalScope) scope).populateCache(); + } + } + public IASTParameterDeclaration[] getParameterDeclarations() { paramDecls = (IASTParameterDeclaration[]) ArrayUtil.removeNullsAfter(IASTParameterDeclaration.class, paramDecls, declPos ); return paramDecls; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java new file mode 100644 index 00000000000..27057b59b06 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousSimpleDeclaration; +import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; + +/** + * Handles ambiguities for parameter declarations. + *
+ * void function(const D*); // is D a type? + * @since 5.0.1 + */ +public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements IASTAmbiguousSimpleDeclaration { + + private IASTSimpleDeclaration fSimpleDecl; + private IASTDeclSpecifier fAltDeclSpec; + private IASTDeclarator fAltDtor; + + public CASTAmbiguousSimpleDeclaration(IASTSimpleDeclaration decl, IASTDeclSpecifier declSpec, IASTDeclarator dtor) { + fSimpleDecl= decl; + fAltDeclSpec= declSpec; + fAltDtor= dtor; + } + + @Override + protected void beforeResolution() { + // populate containing scope, so that it will not be affected by the alternative branches. + IScope scope= CVisitor.getContainingScope(this); + if (scope instanceof IASTInternalScope) { + ((IASTInternalScope) scope).populateCache(); + } + } + + @Override + public IASTNode[] getNodes() { + return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor}; + } + + public IASTSimpleDeclaration copy() { + throw new UnsupportedOperationException(); + } + + public void addDeclarator(IASTDeclarator declarator) { + fSimpleDecl.addDeclarator(declarator); + } + + public IASTDeclSpecifier getDeclSpecifier() { + return fSimpleDecl.getDeclSpecifier(); + } + + public IASTDeclarator[] getDeclarators() { + return fSimpleDecl.getDeclarators(); + } + + public void setDeclSpecifier(IASTDeclSpecifier declSpec) { + fSimpleDecl.setDeclSpecifier(declSpec); + } + + @Override + public final IASTNode resolveAmbiguity(ASTVisitor visitor) { + final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); + IASTNode nodeToReplace= this; + + // handle nested ambiguities first + owner.replace(nodeToReplace, fSimpleDecl); + IASTDeclSpecifier declSpec= fSimpleDecl.getDeclSpecifier(); + declSpec.accept(visitor); + + + // find nested names + final NameCollector nameCollector= new NameCollector(); + declSpec.accept(nameCollector); + final IASTName[] names= nameCollector.getNames(); + + // resolve names + boolean hasIssue= false; + for (IASTName name : names) { + try { + IBinding b = name.resolveBinding(); + if (b instanceof IProblemBinding) { + hasIssue= true; + break; + } + } catch (Exception t) { + hasIssue= true; + break; + } + } + if (hasIssue) { + // use the alternate version + final IASTAmbiguityParent parent = (IASTAmbiguityParent) fSimpleDecl; + parent.replace(declSpec, fAltDeclSpec); + parent.replace(fSimpleDecl.getDeclarators()[0], fAltDtor); + } + + // resolve further nested ambiguities + fSimpleDecl.accept(visitor); + return fSimpleDecl; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java index 29974bb4a17..a524f13f910 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java @@ -13,22 +13,31 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; +import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; -public class CASTAmbiguousStatement extends CASTAmbiguity implements IASTAmbiguousStatement { +public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbiguousStatement { private IASTStatement [] stmts = new IASTStatement[2]; private int stmtsPos=-1; - - public CASTAmbiguousStatement(IASTStatement... statements) { for(IASTStatement s : statements) addStatement(s); } - + @Override + protected void beforeResolution() { + // populate containing scope, so that it will not be affected by the alternative branches. + IScope scope= CVisitor.getContainingScope(this); + if (scope instanceof IASTInternalScope) { + ((IASTInternalScope) scope).populateCache(); + } + } + public void addStatement(IASTStatement s) { assertNotFrozen(); if (s != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java index 4c69b4b7efa..49c1e9ff343 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,15 +15,17 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Implementation for C composite specifiers. */ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements - ICASTCompositeTypeSpecifier { + ICASTCompositeTypeSpecifier, IASTAmbiguityParent { private int key; private IASTName name; @@ -134,5 +136,17 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements return r_unclear; } - + public void replace(IASTNode child, IASTNode other) { + if (declarations == null) return; + for(int i=0; i < declarations.length; ++i) { + if (declarations[i] == null) break; + if (declarations[i] == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + declarations[i] = (IASTDeclaration) other; + break; + } + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java index 3f4c5fefd50..ee1942a5596 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java @@ -1,25 +1,28 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Yuan Zhang / Beth Tibbitts (IBM Research) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** - * @author jcamelon + * A declaration statement. */ -public class CASTDeclarationStatement extends ASTNode implements IASTDeclarationStatement { +public class CASTDeclarationStatement extends ASTNode implements IASTDeclarationStatement, IASTAmbiguityParent { private IASTDeclaration declaration; @@ -71,4 +74,12 @@ public class CASTDeclarationStatement extends ASTNode implements IASTDeclaration } return true; } + + public void replace(IASTNode child, IASTNode other) { + if (child == declaration) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + declaration = (IASTDeclaration) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java index 130dc32e735..dabfdacfd5a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java @@ -1,31 +1,37 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * John Camelon (IBM Rational Software) - Initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.EScopeKind; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; /** - * @author jcamelon + * Models function declarators for plain c. */ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStandardFunctionDeclarator { private IASTParameterDeclaration [] parameters = null; private int parametersPos=-1; private boolean varArgs; + private IScope scope; public CASTFunctionDeclarator() { } @@ -94,4 +100,26 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda } super.replace(child, other); } + + public IScope getFunctionScope() { + if (scope != null) + return scope; + + // introduce a scope for function declarations and definitions, only. + IASTNode node= getParent(); + while(!(node instanceof IASTDeclaration)) { + if (node==null) + return null; + node= node.getParent(); + } + if (node instanceof IASTParameterDeclaration) + return null; + + if (node instanceof IASTFunctionDefinition) { + scope= ((IASTFunctionDefinition) node).getScope(); + } else if (ASTQueries.findTypeRelevantDeclarator(this) == this) { + scope = new CScope(this, EScopeKind.eLocal); + } + return scope; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java index 28ae1e24aae..5c33c6e04db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java @@ -1,28 +1,30 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Yuan Zhang / Beth Tibbitts (IBM Research) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Yuan Zhang / Beth Tibbitts (IBM Research) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** - * @author jcamelon + * Models a simple declaration. */ -public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclaration { +public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclaration, IASTAmbiguityParent { public CASTSimpleDeclaration() { @@ -101,4 +103,22 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat } return true; } + + public void replace(IASTNode child, IASTNode other) { + if (declSpecifier == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + declSpecifier= (IASTDeclSpecifier) other; + } else { + IASTDeclarator[] declarators = getDeclarators(); + for(int i = 0; i < declarators.length; i++) { + if(declarators[i] == child) { + declarators[i] = (IASTDeclarator)other; + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + break; + } + } + } + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 9aa4886f5bb..1f4629147bf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2008 IBM Corporation and others. + * Copyright (c) 2002, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,7 +16,9 @@ import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.EScopeKind; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -24,11 +26,12 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * C-specific implementation of a translation unit. */ -public class CASTTranslationUnit extends ASTTranslationUnit { +public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbiguityParent { private CScope compilationUnit = null; @@ -93,4 +96,17 @@ public class CASTTranslationUnit extends ASTTranslationUnit { protected ASTVisitor createAmbiguityNodeVisitor() { return new CASTAmbiguityResolver(); } + + public void replace(IASTNode child, IASTNode other) { + if (fDeclarations == null) return; + for(int i=0; i < fDeclarations.length; ++i) { + if (fDeclarations[i] == null) break; + if (fDeclarations[i] == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + fDeclarations[i] = (IASTDeclaration) other; + return; + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java index 9b21bdb38c4..2ff15f3372f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java @@ -1,32 +1,35 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Nov 25, 2004 - */ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; /** - * @author aniefer + * Implementation of scope for structs and unions. */ public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope { public CCompositeTypeScope( ICASTCompositeTypeSpecifier compTypeSpec ){ @@ -71,4 +74,39 @@ public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope return new CStructure.CStructureProblem( compSpec.getName(), IProblemBinding.SEMANTIC_BAD_SCOPE, compSpec.getName().toCharArray() ); } + + @Override + protected void doPopulateCache() { + ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) getPhysicalNode(); + ICASTCompositeTypeSpecifier[] specStack = null; + int stackIdx = -1; + IASTDeclaration[] members = compSpec.getMembers(); + while (members != null) { + int size = members.length; + for (int i = 0; i < size; i++) { + IASTNode node = members[i]; + if (node instanceof IASTSimpleDeclaration) { + IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators(); + for (int j = 0; j < declarators.length; j++) { + IASTDeclarator declarator = declarators[j]; + IASTName dtorName = ASTQueries.findInnermostDeclarator(declarator).getName(); + ASTInternal.addName(this, dtorName); + } + // anonymous structures and unions + if (declarators.length == 0 && ((IASTSimpleDeclaration) node).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) { + IASTCompositeTypeSpecifier declSpec = (IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier(); + IASTName n = declSpec.getName(); + if (n.toCharArray().length == 0) { + specStack = (ICASTCompositeTypeSpecifier[]) ArrayUtil.append(ICASTCompositeTypeSpecifier.class, specStack, declSpec); + } + } + } + } + if (specStack != null && ++stackIdx < specStack.length && specStack[stackIdx] != null) { + members = specStack[stackIdx].getMembers(); + } else { + members = null; + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java index 9848ca06e05..96e14d8f77d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) @@ -20,13 +20,22 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; @@ -35,22 +44,30 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; +import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICScope; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousParameterDeclaration; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; /** - * @author aniefer + * Base implementation for c-scopes */ public class CScope implements ICScope, IASTInternalScope { /** @@ -92,13 +109,12 @@ public class CScope implements ICScope, IASTInternalScope { }; private IASTNode physicalNode = null; - private boolean isFullyCached = false; + private boolean isCached = false; private CharArrayObjectMap[] mapsToNameOrBinding = { CharArrayObjectMap.EMPTY_MAP, CharArrayObjectMap.EMPTY_MAP }; - private ObjectMap reuseBindings= null; private final EScopeKind kind; - public CScope( IASTNode physical, EScopeKind eKind){ + public CScope(IASTNode physical, EScopeKind eKind) { physicalNode = physical; kind= eKind; } @@ -148,9 +164,9 @@ public class CScope implements ICScope, IASTInternalScope { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) */ - public IBinding[] find( String name ) throws DOMException { - return CVisitor.findBindings( this, name, false ); - } + public IBinding[] find(String name) throws DOMException { + return CVisitor.findBindings(this, name); + } public IBinding getBinding( int namespaceType, char [] name ){ Object o= mapsToNameOrBinding[namespaceType].get(name); @@ -160,26 +176,12 @@ public class CScope implements ICScope, IASTInternalScope { if (o instanceof IASTName) return ((IASTName) o).resolveBinding(); + if (o instanceof IASTName[]) { + return ((IASTName[]) o)[0].resolveBinding(); + } return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) - */ - public void removeBinding(IBinding binding) { - int type = ( binding instanceof ICompositeType || binding instanceof IEnumeration ) ? - NAMESPACE_TYPE_TAG : NAMESPACE_TYPE_OTHER; - - final CharArrayObjectMap bindingsMap = mapsToNameOrBinding[type]; - if( bindingsMap != CharArrayObjectMap.EMPTY_MAP ) { - Object o= bindingsMap.remove( binding.getNameCharArray(), 0, binding.getNameCharArray().length); - if (o != null && reuseBindings != null) { - reuseBindings.remove(o); - } - } - isFullyCached = false; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#getPhysicalNode() */ @@ -187,41 +189,36 @@ public class CScope implements ICScope, IASTInternalScope { return physicalNode; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICScope#addName(org.eclipse.cdt.core.dom.ast.IASTName) - */ - public void addName( IASTName name ) { - int type = getNamespaceType( name ); - CharArrayObjectMap map = mapsToNameOrBinding[type]; - if( map == CharArrayObjectMap.EMPTY_MAP ) - map= mapsToNameOrBinding[type] = new CharArrayObjectMap(1); - - final char [] n = name.toCharArray(); - final Object current= map.get( n ); - if (current instanceof IASTName) { - final CASTName currentName = (CASTName)current; - if (currentName.getOffset() <= ((CASTName) name).getOffset() ){ - return; - } - if (name.getBinding() == null) { - // bug 232300: we need to make sure that the binding is picked up even if the name is removed - // from the cache. Simply assigning it to the name is not enough, because a declaration or - // definition needs to be added to the binding. - IBinding reuseBinding= currentName.getBinding(); - if (reuseBinding == null && reuseBindings != null) { - reuseBinding= (IBinding) reuseBindings.get(currentName); - } - if (reuseBinding != null) { - if (reuseBindings == null) { - reuseBindings= new ObjectMap(1); - } - reuseBindings.put(name, reuseBinding); - reuseBindings.remove(currentName); - } + public void addName(IASTName name) { + final char[] nchars = name.toCharArray(); + if (nchars.length == 0) + return; + + int type = getNamespaceType(name); + CharArrayObjectMap map = mapsToNameOrBinding[type]; + if (map == CharArrayObjectMap.EMPTY_MAP) + map = mapsToNameOrBinding[type] = new CharArrayObjectMap(1); + + Object o= map.get(nchars); + if (o instanceof IASTName) { + if (o != name) { + map.put(nchars, new IASTName[] {(IASTName) o, name}); } - } - map.put(n, name); - } + } else if (o instanceof IASTName[]) { + final IASTName[] names = (IASTName[]) o; + for (IASTName n : names) { + if (n == null) + break; + if (n == name) + return; + } + final IASTName[] newNames= (IASTName[]) ArrayUtil.append(IASTName.class, names, name); + if (newNames != names) + map.put(nchars, newNames); + } else { + map.put(nchars, name); + } + } private int getNamespaceType( IASTName name ){ ASTNodeProperty prop = name.getPropertyInParent(); @@ -243,38 +240,35 @@ public class CScope implements ICScope, IASTInternalScope { return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY); } - public IBinding getBinding( IASTName name, boolean resolve, IIndexFileSet fileSet ) { - char [] c = name.toCharArray(); + public final IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) { + char[] c = name.toCharArray(); if( c.length == 0 ){ return null; } - final int type = getNamespaceType( name ); - Object o = mapsToNameOrBinding[type].get( name.toCharArray() ); + populateCache(); + final int type = getNamespaceType(name); + Object o = mapsToNameOrBinding[type].get(name.toCharArray()); - if( o instanceof IBinding ) - return (IBinding) o; + if (o instanceof IBinding) + return (IBinding) o; if (o instanceof IASTName) { - final IASTName n= (IASTName) o; - if (!isTypeDefinition(name) || CVisitor.declaredBefore(n, name)) { - IBinding b= n.getBinding(); - if (b != null) - return b; - - if (reuseBindings != null) { - b= (IBinding) reuseBindings.get(n); - if (b != null) - return b; - } - if (resolve && n != name) { - return n.resolveBinding(); - } - } + IBinding b= extractBinding((IASTName) o, resolve, name); + if (b != null) + return b; + } else if (o instanceof IASTName[]) { + for (IASTName n: ((IASTName[]) o)) { + if (n == null) + break; + IBinding b= extractBinding(n, resolve, name); + if (b != null) + return b; + } } IBinding result= null; - if(physicalNode instanceof IASTTranslationUnit) { + if (resolve && physicalNode instanceof IASTTranslationUnit) { final IASTTranslationUnit tu = (IASTTranslationUnit)physicalNode; IIndex index= tu.getIndex(); if(index!=null) { @@ -292,33 +286,47 @@ public class CScope implements ICScope, IASTInternalScope { return result; } - private boolean isTypeDefinition(IASTName name) { - if (name.getPropertyInParent()==IASTNamedTypeSpecifier.NAME) { - return true; + private IBinding extractBinding(final IASTName candidate, boolean resolve, IASTName forName) { + if (!resolve || acceptDeclaredAfter(forName) || CVisitor.declaredBefore(candidate, forName)) { + if (resolve && candidate != forName) { + return candidate.resolveBinding(); + } + return candidate.getBinding(); + } + return null; + } + + private boolean acceptDeclaredAfter(IASTName name) { + if (getKind() != EScopeKind.eGlobal) + return false; + final ASTNodeProperty propertyInParent = name.getPropertyInParent(); + if (propertyInParent==IASTNamedTypeSpecifier.NAME || + propertyInParent == IASTElaboratedTypeSpecifier.TYPE_NAME) { + return false; } IASTNode parent= name.getParent(); while (parent != null) { if (parent instanceof IASTUnaryExpression) { if (((IASTUnaryExpression) parent).getOperator() == IGNUASTUnaryExpression.op_typeof) - return true; + return false; } else if (parent instanceof IASTTypeIdExpression) { if (((IASTTypeIdExpression) parent).getOperator() == IASTTypeIdExpression.op_typeof) - return true; + return false; } parent= parent.getParent(); } - return false; + return true; } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean) */ - public IBinding[] getBindings( IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet ) { + public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) { char [] c = name.toCharArray(); - Object[] obj = null; - + + populateCache(); for (CharArrayObjectMap map : mapsToNameOrBinding) { if (prefixLookup) { Object[] keys = map.keyArray(); @@ -333,47 +341,49 @@ public class CScope implements ICScope, IASTInternalScope { } } - if(physicalNode instanceof IASTTranslationUnit) { - final IASTTranslationUnit tu = (IASTTranslationUnit)physicalNode; - IIndex index= tu.getIndex(); - if(index!=null) { - try { - IBinding[] bindings = prefixLookup ? - index.findBindingsForPrefix(name.toCharArray(), true, INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null) : - index.findBindings(name.toCharArray(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null); + if (physicalNode instanceof IASTTranslationUnit) { + final IASTTranslationUnit tu = (IASTTranslationUnit) physicalNode; + IIndex index = tu.getIndex(); + if (index != null) { + try { + IBinding[] bindings = prefixLookup ? index.findBindingsForPrefix(name.toCharArray(), true, INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null) + : index.findBindings(name.toCharArray(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null); if (fileSet != null) { - bindings= fileSet.filterFileLocalBindings(bindings); + bindings = fileSet.filterFileLocalBindings(bindings); } - + obj = ArrayUtil.addAll(Object.class, obj, bindings); - } catch(CoreException ce) { - CCorePlugin.log(ce); - } - } - } + } catch (CoreException ce) { + CCorePlugin.log(ce); + } + } + } obj = ArrayUtil.trim(Object.class, obj); IBinding[] result = null; - for (Object element : obj) { - if( element instanceof IBinding ) { - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, element); - } else if (element instanceof IASTName) { - final IASTName n= (IASTName) element; - IBinding b= n.getBinding(); - if (b == null) { - if (reuseBindings != null) { - b= (IBinding) reuseBindings.get(n); - } - if (resolve && b == null && n != name) { - b= n.resolveBinding(); - } - } - if (b != null) { - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, b); - } - - } - } + for (Object element : obj) { + if (element instanceof IBinding) { + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, element); + } else { + IASTName n= null; + if (element instanceof IASTName) { + n= (IASTName) element; + } else if (element instanceof IASTName[]) { + n = ((IASTName[]) element)[0]; + } + if (n != null) { + IBinding b = n.getBinding(); + if (b == null) { + if (resolve && n != name) { + b = n.resolveBinding(); + } + } + if (b != null) { + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, b); + } + } + } + } return (IBinding[]) ArrayUtil.trim(IBinding.class, result); } @@ -392,19 +402,164 @@ public class CScope implements ICScope, IASTInternalScope { return bindings[0]; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICScope#setFullyCached(boolean) - */ - public void setFullyCached( boolean b ){ - isFullyCached = b; + public void populateCache() { + if (isCached) + return; + + doPopulateCache(); + isCached= true; } + + protected void doPopulateCache() { + final IASTNode scopeNode = physicalNode; + IASTNode[] nodes = null; + if (scopeNode instanceof IASTCompoundStatement) { + IASTCompoundStatement compound = (IASTCompoundStatement) scopeNode; + if (scopeNode.getParent() instanceof IASTFunctionDefinition) { + IASTFunctionDeclarator dtor = ((IASTFunctionDefinition) scopeNode.getParent()).getDeclarator(); + if (dtor instanceof IASTStandardFunctionDeclarator) { + nodes = ((IASTStandardFunctionDeclarator) dtor).getParameters(); + } else if (dtor instanceof ICASTKnRFunctionDeclarator) { + nodes = ((ICASTKnRFunctionDeclarator) dtor).getParameterDeclarations(); + } + } + if (nodes == null || nodes.length == 0) { + nodes = compound.getStatements(); + } + } else if (scopeNode instanceof IASTTranslationUnit) { + IASTTranslationUnit translation = (IASTTranslationUnit) scopeNode; + nodes = translation.getDeclarations(); + } else if (scopeNode instanceof IASTStandardFunctionDeclarator) { + IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) scopeNode; + nodes = dtor.getParameters(); + } else if (scopeNode instanceof ICASTKnRFunctionDeclarator) { + ICASTKnRFunctionDeclarator dtor = (ICASTKnRFunctionDeclarator) scopeNode; + nodes = dtor.getParameterDeclarations(); + } else if (scopeNode instanceof IASTForStatement) { + final IASTForStatement forStmt = (IASTForStatement) scopeNode; + nodes= new IASTNode[] {forStmt.getInitializerStatement()}; + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICScope#isFullyCached() - */ - public boolean isFullyCached(){ - return isFullyCached; - } + if (nodes != null) { + int idx = -1; + IASTNode node = nodes.length > 0 ? nodes[++idx] : null; + while (node != null) { + collectNames(node); + if (idx > -1 && ++idx < nodes.length) { + node = nodes[idx]; + } else { + node = null; + if (nodes[0].getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER + || nodes[0].getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER) { + // function body, we were looking at parameters, now + // check the body itself + IASTCompoundStatement compound = null; + if (scopeNode instanceof IASTCompoundStatement) { + compound = (IASTCompoundStatement) scopeNode; + } else if (scopeNode instanceof IASTFunctionDeclarator) { + IASTNode n = scopeNode.getParent(); + while (n instanceof IASTDeclarator) + n = n.getParent(); + if (n instanceof IASTFunctionDefinition) { + compound = (IASTCompoundStatement) ((IASTFunctionDefinition) n).getBody(); + } + } + if (compound != null) { + nodes = compound.getStatements(); + if (nodes.length > 0) { + idx = 0; + node = nodes[0]; + } + } + } + } + } + } + } + + public void collectNames(IASTNode node) { + if (node instanceof IASTDeclaration) { + collectNames((IASTDeclaration) node); + } else if (node instanceof IASTParameterDeclaration) { + collectNames((IASTParameterDeclaration) node); + } else if (node instanceof IASTDeclarationStatement) { + collectNames(((IASTDeclarationStatement)node).getDeclaration()); + } + } + + private void collectNames(IASTParameterDeclaration paramDecl) { + if (paramDecl == null || paramDecl instanceof IASTAmbiguousParameterDeclaration) + return; + + collectNames(paramDecl.getDeclarator()); + collectNames(paramDecl.getDeclSpecifier()); + } + + private void collectNames(IASTDeclarator dtor) { + IASTDeclarator innermost= null; + while (dtor != null) { + if (dtor instanceof IASTAmbiguousDeclarator) { + innermost= null; + break; + } + innermost= dtor; + dtor= dtor.getNestedDeclarator(); + } + if (innermost != null) + ASTInternal.addName(this, innermost.getName()); + } + + private void collectNames(IASTDeclaration declaration) { + if (declaration instanceof IASTAmbiguousSimpleDeclaration) + return; + + if (declaration instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration; + IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); + for (IASTDeclarator dtor : declarators) { + collectNames(dtor); + } + collectNames(simpleDeclaration.getDeclSpecifier()); + } else if (declaration instanceof IASTFunctionDefinition) { + IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; + collectNames(functionDef.getDeclarator()); + collectNames(functionDef.getDeclSpecifier()); + } + } + + private void collectNames(IASTDeclSpecifier declSpec) { + IASTName tempName = null; + if (declSpec instanceof ICASTElaboratedTypeSpecifier) { + tempName = ((ICASTElaboratedTypeSpecifier)declSpec).getName(); + ASTInternal.addName(this, tempName); + } else if (declSpec instanceof ICASTCompositeTypeSpecifier) { + tempName = ((ICASTCompositeTypeSpecifier)declSpec).getName(); + ASTInternal.addName(this, tempName); + + //also have to check for any nested structs + IASTDeclaration[] nested = ((ICASTCompositeTypeSpecifier)declSpec).getMembers(); + for (IASTDeclaration element : nested) { + if (element instanceof IASTSimpleDeclaration) { + IASTDeclSpecifier d = ((IASTSimpleDeclaration)element).getDeclSpecifier(); + if (d instanceof ICASTCompositeTypeSpecifier || d instanceof IASTEnumerationSpecifier) { + collectNames(d); + } + } + } + } else if (declSpec instanceof ICASTEnumerationSpecifier) { + ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec; + tempName = enumeration.getName(); + ASTInternal.addName(this, tempName); + + //check enumerators + IASTEnumerator[] list = ((ICASTEnumerationSpecifier) declSpec).getEnumerators(); + for (IASTEnumerator enumerator : list) { + if (enumerator == null) break; + tempName = enumerator.getName(); + ASTInternal.addName(this, tempName); + } + } + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName() @@ -416,50 +571,24 @@ public class CScope implements ICScope, IASTInternalScope { return null; } - public void flushCache() { - CharArrayObjectMap map= mapsToNameOrBinding[0]; - CharArrayObjectMap builtins= null; - for (int i = 0; i < map.size(); i++) { - Object obj= map.getAt(i); - if (obj instanceof IASTName) { - ((IASTName) obj).setBinding(null); - } else if (obj instanceof IBinding) { - if (builtins == null) { - builtins= new CharArrayObjectMap(2); - } - builtins.put(((IBinding) obj).getNameCharArray(), obj); - } - } - mapsToNameOrBinding[0]= builtins == null ? CharArrayObjectMap.EMPTY_MAP : builtins; - - map= mapsToNameOrBinding[1]; - builtins= null; - for (int i = 0; i < map.size(); i++) { - Object obj= map.getAt(i); - if (obj instanceof IASTName) { - ((IASTName) obj).setBinding(null); - } else if (obj instanceof IBinding) { - if (builtins == null) { - builtins= new CharArrayObjectMap(2); - } - builtins.put(((IBinding) obj).getNameCharArray(), obj); - } - } - mapsToNameOrBinding[1]= builtins == null ? CharArrayObjectMap.EMPTY_MAP : builtins; - reuseBindings= null; - isFullyCached = false; - } - public void addBinding(IBinding binding) { int type = NAMESPACE_TYPE_OTHER; - if (binding instanceof ICompositeType || binding instanceof IEnumeration) { - type = NAMESPACE_TYPE_TAG; - } - - CharArrayObjectMap map = mapsToNameOrBinding[type]; - if( map == CharArrayObjectMap.EMPTY_MAP ) - map= mapsToNameOrBinding[type] = new CharArrayObjectMap(2); - + if (binding instanceof ICompositeType || binding instanceof IEnumeration) { + type = NAMESPACE_TYPE_TAG; + } + + CharArrayObjectMap map = mapsToNameOrBinding[type]; + if (map == CharArrayObjectMap.EMPTY_MAP) + map = mapsToNameOrBinding[type] = new CharArrayObjectMap(2); + map.put(binding.getNameCharArray(), binding); } + + /** + * In case there was an ambiguity the cache has to be populated for a second time. + * However, we do not clear any names in order not to loose bindings. + */ + public void markAsUncached() { + isCached= false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index 1979afff685..3c46eebcb13 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IField; @@ -31,10 +32,9 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; +import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.Linkage; -import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; @@ -67,6 +67,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte private IASTName [] declarations = null; private IASTName definition; + private boolean checked; + private ICompositeType typeInIndex; public CStructure( IASTName name ){ if( name.getPropertyInParent() == IASTCompositeTypeSpecifier.TYPE_NAME ) @@ -80,14 +82,28 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte public IASTNode getPhysicalNode(){ return ( definition != null ) ? (IASTNode)definition : (IASTNode)declarations[0]; } - private ICASTCompositeTypeSpecifier checkForDefinition( IASTElaboratedTypeSpecifier declSpec ){ - IASTDeclSpecifier spec = CVisitor.findDefinition( (ICASTElaboratedTypeSpecifier) declSpec ); - if( spec != null && spec instanceof ICASTCompositeTypeSpecifier ){ - ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) spec; - compTypeSpec.getName().setBinding( this ); - return compTypeSpec; + + private void checkForDefinition() { + if (!checked && definition == null) { + IASTNode declSpec = declarations[0].getParent(); + if (declSpec instanceof ICASTElaboratedTypeSpecifier) { + IASTDeclSpecifier spec = CVisitor.findDefinition((ICASTElaboratedTypeSpecifier) declSpec); + if (spec instanceof ICASTCompositeTypeSpecifier) { + ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) spec; + definition= compTypeSpec.getName(); + definition.setBinding(this); + } + } + + if (definition == null && typeInIndex == null) { + final IASTTranslationUnit translationUnit = declSpec.getTranslationUnit(); + IIndex index= translationUnit.getIndex(); + if (index != null) { + typeInIndex= (ICompositeType) index.adaptBinding(this); + } + } } - return null; + checked = true; } /* (non-Javadoc) @@ -122,103 +138,49 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields() */ public IField[] getFields() throws DOMException { - if( definition == null ){ - ICASTCompositeTypeSpecifier temp = checkForDefinition( (IASTElaboratedTypeSpecifier) declarations[0].getParent() ); - if( temp == null ) - return new IField [] { new CField.CFieldProblem( declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) }; - definition = temp.getName(); - } + checkForDefinition(); + if (definition == null) { + return new IField[] { + new CField.CFieldProblem(declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray()) + }; + } ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) definition.getParent(); IASTDeclaration[] members = compSpec.getMembers(); int size = members.length; IField[] fields = new IField[ size ]; - if( size > 0 ){ - ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope(); - if( ASTInternal.isFullyCached(scope) ) - scope = null; - for( int i = 0; i < size; i++ ){ + if (size > 0) { + for (int i = 0; i < size; i++) { IASTNode node = members[i]; - if( node instanceof IASTSimpleDeclaration ){ - IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators(); - for( int j = 0; j < declarators.length; j++ ){ + if (node instanceof IASTSimpleDeclaration) { + IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators(); + for (int j = 0; j < declarators.length; j++) { IASTDeclarator declarator = declarators[j]; IASTName name = declarator.getName(); IBinding binding = name.resolveBinding(); - if( scope != null ) - ASTInternal.addName(scope, name ); - if( binding != null ) - fields = (IField[]) ArrayUtil.append( IField.class, fields, binding ); + if (binding != null) + fields = (IField[]) ArrayUtil.append(IField.class, fields, binding); } } } - if( scope != null ) - ASTInternal.setFullyCached(scope, true); } return (IField[]) ArrayUtil.trim( IField.class, fields ); } public IField findField(String name) throws DOMException { - if (definition == null) { - ICASTCompositeTypeSpecifier temp = checkForDefinition((IASTElaboratedTypeSpecifier) declarations[0].getParent()); - if (temp == null) - return new CField.CFieldProblem(declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray()); - definition = temp.getName(); - } - - final char[] nchars= name.toCharArray(); - ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope(); - if (scope != null && ASTInternal.isFullyCached(scope)) { - IBinding binding = scope.getBinding(nchars); - if (binding instanceof IField) - return (IField) binding; - } else { - ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) definition.getParent(); - ICASTCompositeTypeSpecifier[] specStack = null; - int stackIdx = -1; - IASTDeclaration[] members = compSpec.getMembers(); - IField found = null; - while (members != null) { - int size = members.length; - for (int i = 0; i < size; i++) { - IASTNode node = members[i]; - if (node instanceof IASTSimpleDeclaration) { - IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators(); - for (int j = 0; j < declarators.length; j++) { - IASTDeclarator declarator = declarators[j]; - IASTName dtorName = CVisitor.findInnermostDeclarator(declarator).getName(); - if (scope != null) - ASTInternal.addName(scope, dtorName); - if (CharArrayUtils.equals(nchars, dtorName.toCharArray())) { - IBinding binding = dtorName.resolveBinding(); - if (binding instanceof IField) - found = (IField) binding; - } - } - // anonymous structures and unions - if (declarators.length == 0 && ((IASTSimpleDeclaration) node).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) { - IASTCompositeTypeSpecifier declSpec = (IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier(); - IASTName n = declSpec.getName(); - if (n.toCharArray().length == 0) { - specStack = (ICASTCompositeTypeSpecifier[]) ArrayUtil.append(ICASTCompositeTypeSpecifier.class, specStack, declSpec); - } - } - } - } - if (specStack != null && ++stackIdx < specStack.length && specStack[stackIdx] != null) { - members = specStack[stackIdx].getMembers(); - } else { - members = null; - } - } - if (scope != null) - ASTInternal.setFullyCached(scope, true); - if (found != null) - return found; + IScope scope = getCompositeScope(); + if (scope == null) { + return new CField.CFieldProblem(declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray()); } + final CASTName astName = new CASTName(name.toCharArray()); + astName.setPropertyInParent(CVisitor.STRING_LOOKUP_PROPERTY); + IBinding binding = scope.getBinding(astName, true); + if (binding instanceof IField) + return (IField) binding; + return null; } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey() */ @@ -231,7 +193,21 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope() */ public IScope getCompositeScope() { - return (definition != null ) ? ((IASTCompositeTypeSpecifier)definition.getParent()).getScope() : null; + checkForDefinition(); + if (definition != null) { + return ((IASTCompositeTypeSpecifier)definition.getParent()).getScope(); + } + // fwd-declarations must be backed up from the index + if (typeInIndex != null) { + try { + IScope scope = typeInIndex.getCompositeScope(); + if (scope instanceof ICCompositeTypeScope) + return scope; + } catch (DOMException e) { + // index bindings don't throw DOMExeptions. + } + } + return null; } @Override @@ -252,6 +228,28 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte definition = compositeTypeSpec.getName(); compositeTypeSpec.getName().setBinding( this ); } + + public void addDeclaration(IASTName decl) { + if (decl.getPropertyInParent() != IASTElaboratedTypeSpecifier.TYPE_NAME) + return; + + decl.setBinding(this); + if (declarations == null) { + declarations = new IASTName[] { decl }; + return; + } + for (int i = 0; i < declarations.length; i++) { + if (declarations[i] == null) { + declarations[i] = decl; + return; + } + } + IASTName tmp[] = new IASTName[declarations.length * 2]; + System.arraycopy(declarations, 0, tmp, 0, declarations.length); + tmp[declarations.length] = decl; + declarations = tmp; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 7392fbb7b4d..5c712a4f672 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -16,7 +16,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import java.util.ArrayList; import java.util.List; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; @@ -93,45 +92,22 @@ import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier; -import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; -import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; +import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.core.runtime.CoreException; /** * Collection of methods to find information in an AST. */ public class CVisitor extends ASTQueries { - public static class ClearBindingAction extends CASTVisitor { - { - shouldVisitNames = true; - } - @Override - public int visit(IASTName name) { - if (name.getBinding() != null) { - try { - IScope scope = name.resolveBinding().getScope(); - if (scope != null) - ASTInternal.removeBinding(scope, name.resolveBinding()); - } catch (DOMException e) { - } - name.setBinding(null); - } - - return PROCESS_CONTINUE; - } - } - public static class CollectProblemsAction extends CASTVisitor { { shouldVisitDeclarations = true; @@ -468,12 +444,6 @@ public class CVisitor extends ASTQueries { private static final String PTRDIFF_T = "ptrdiff_t"; //$NON-NLS-1$ public static final String EMPTY_STRING = ""; //$NON-NLS-1$ public static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$ - //lookup bits - private static final int COMPLETE = 0; - private static final int CURRENT_SCOPE = 1; - private static final int TAGS = 1 << 1; - private static final int INCLUDE_BLOCK_ITEM = 1 << 2; - private static final int PREFIX_LOOKUP = 1 << 3; //definition lookup start loc protected static final int AT_BEGINNING = 1; @@ -484,7 +454,7 @@ public class CVisitor extends ASTQueries { IASTNode parent = name.getParent(); if (parent instanceof CASTIdExpression) { - binding = resolveBinding(parent, COMPLETE | INCLUDE_BLOCK_ITEM); + binding = resolveBinding(parent); } else if (parent instanceof ICASTTypedefNameSpecifier) { binding = resolveBinding(parent); } else if (parent instanceof IASTFieldReference) { @@ -572,16 +542,23 @@ public class CVisitor extends ASTQueries { } private static IBinding createBinding(ICASTElaboratedTypeSpecifier elabTypeSpec) { IASTNode parent = elabTypeSpec.getParent(); + IASTName name = elabTypeSpec.getName(); if (parent instanceof IASTDeclaration) { - int bits = TAGS; + IBinding binding= null; if (parent instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)parent).getDeclarators().length == 0) { - bits |= CURRENT_SCOPE; + IScope scope= getContainingScope(elabTypeSpec); + try { + binding= scope.getBinding(name, false); + } catch (DOMException e) { + } + } else { + binding= resolveBinding(elabTypeSpec); } - IASTName name = elabTypeSpec.getName(); - IBinding binding = resolveBinding(elabTypeSpec, bits); if (binding != null) { if (binding instanceof CEnumeration) { ((CEnumeration)binding).addDeclaration(name); + } else if (binding instanceof CStructure) { + ((CStructure) binding).addDeclaration(name); } } else { if (elabTypeSpec.getKind() == IASTElaboratedTypeSpecifier.k_enum) { @@ -598,12 +575,7 @@ public class CVisitor extends ASTQueries { return binding; } else if (parent instanceof IASTTypeId || parent instanceof IASTParameterDeclaration) { - IASTNode blockItem = getContainingBlockItem(parent); - try { - return (IBinding) findBinding(blockItem, elabTypeSpec.getName(), COMPLETE | TAGS); - } catch (DOMException e) { - return null; - } + return resolveBinding(elabTypeSpec); } return null; } @@ -848,9 +820,12 @@ public class CVisitor extends ASTQueries { private static IBinding createBinding(IASTDeclarator declarator, IASTName name) { IBinding binding = null; if (declarator instanceof ICASTKnRFunctionDeclarator) { - IASTNode parent = declarator.getParent(); if (CharArrayUtils.equals(declarator.getName().toCharArray(), name.toCharArray())) { - binding = resolveBinding(parent, CURRENT_SCOPE); + IScope scope= CVisitor.getContainingScope(declarator); + try { + binding = scope.getBinding(name, false); + } catch (DOMException e) { + } if (binding != null && binding instanceof IIndexBinding == false) { if (binding instanceof ICInternalFunction) ((ICInternalFunction)binding).addDeclarator((ICASTKnRFunctionDeclarator) declarator); @@ -864,13 +839,6 @@ public class CVisitor extends ASTQueries { if (f instanceof CFunction) { binding = ((CFunction) f).resolveParameter(name); } - - if (declarator.getParent() instanceof IASTFunctionDefinition) { - IScope scope = ((IASTCompoundStatement)((IASTFunctionDefinition)declarator.getParent()).getBody()).getScope(); - if (scope != null && binding != null) { - ASTInternal.addName(scope, name); - } - } } } else { binding = createBinding(declarator); @@ -910,24 +878,17 @@ public class CVisitor extends ASTQueries { if (parent instanceof IASTParameterDeclaration || parent.getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER) { IASTDeclarator fdtor = (IASTDeclarator) parent.getParent(); - IASTDeclarator nested= fdtor.getNestedDeclarator(); - while (nested != null && nested.getPointerOperators().length == 0) { - fdtor= nested; - nested= nested.getNestedDeclarator(); + if (ASTQueries.findTypeRelevantDeclarator(fdtor) instanceof IASTFunctionDeclarator) { + IASTName n= ASTQueries.findInnermostDeclarator(fdtor).getName(); + IBinding temp = n.resolveBinding(); + if (temp != null && temp instanceof CFunction) { + binding = ((CFunction) temp).resolveParameter(name); + } else if (temp instanceof IFunction) { + //problems with the function, still create binding for the parameter + binding = new CParameter(name); + } + return binding; } - IBinding temp = fdtor.getName().resolveBinding(); - if (temp != null && temp instanceof CFunction) { - binding = ((CFunction) temp).resolveParameter(name); - } else if (temp instanceof IFunction) { - //problems with the function, still create binding for the parameter - binding = new CParameter(name); - } - try { - if (scope != null && ASTInternal.getPhysicalNodeOfScope(scope) instanceof IASTTranslationUnit) { - return binding; - } - } catch (DOMException e) { - } } else if (funcDeclarator != null) { if (binding != null && !(binding instanceof IIndexBinding)) { if (binding instanceof IFunction) { @@ -971,10 +932,6 @@ public class CVisitor extends ASTQueries { } } } - - if (scope != null && binding != null) { - ASTInternal.addName(scope, name); - } return binding; } @@ -998,37 +955,24 @@ public class CVisitor extends ASTQueries { } } catch (DOMException e2) { } - - binding = new CStructure(name); - - try { - scope= binding.getScope(); - ASTInternal.addName(scope, name); - } catch (DOMException e) { - } - - return binding; + return new CStructure(name); } protected static IBinding resolveBinding(IASTNode node) { - return resolveBinding(node, COMPLETE); - } - - protected static IBinding resolveBinding(IASTNode node, int bits) { if (node instanceof IASTFunctionDefinition) { IASTFunctionDefinition functionDef = (IASTFunctionDefinition) node; IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator(); IASTName name = findInnermostDeclarator(functionDeclartor).getName(); - IASTNode blockItem = getContainingBlockItem(node); + IScope scope = getContainingScope(node); try { - return (IBinding) findBinding(blockItem, name, bits); + return lookup(scope, name); } catch (DOMException e) { return null; } } else if (node instanceof IASTIdExpression) { - IASTNode blockItem = getContainingBlockItem(node); + IScope scope = getContainingScope(node); try { - IBinding binding = (IBinding) findBinding(blockItem, ((IASTIdExpression)node).getName(), bits); + IBinding binding = lookup(scope, ((IASTIdExpression)node).getName()); if (binding instanceof IType && !(binding instanceof IProblemBinding) ) { return new ProblemBinding(node, IProblemBinding.SEMANTIC_INVALID_TYPE, binding.getNameCharArray()); } @@ -1037,10 +981,10 @@ public class CVisitor extends ASTQueries { return null; } } else if (node instanceof ICASTTypedefNameSpecifier) { - IASTNode blockItem = getContainingBlockItem(node); + IScope scope = getContainingScope(node); try { IASTName name= ((ICASTTypedefNameSpecifier)node).getName(); - IBinding binding = (IBinding) findBinding(blockItem, name, bits); + IBinding binding = lookup(scope, name); if (binding == null) return new ProblemBinding(node, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray()); if (binding instanceof IType) @@ -1050,16 +994,16 @@ public class CVisitor extends ASTQueries { return null; } } else if (node instanceof ICASTElaboratedTypeSpecifier) { - IASTNode blockItem = getContainingBlockItem(node); + IScope scope = getContainingScope(node); try { - return (IBinding) findBinding(blockItem, ((ICASTElaboratedTypeSpecifier)node).getName(), bits); + return lookup(scope, ((ICASTElaboratedTypeSpecifier)node).getName()); } catch (DOMException e) { return null; } } else if (node instanceof ICASTCompositeTypeSpecifier) { - IASTNode blockItem = getContainingBlockItem(node); + IScope scope = getContainingScope(node); try { - return (IBinding) findBinding(blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits); + return lookup(scope, ((ICASTCompositeTypeSpecifier)node).getName()); } catch (DOMException e) { return null; } @@ -1158,20 +1102,44 @@ public class CVisitor extends ASTQueries { return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope(); } } - } else if (node instanceof IASTStatement) + } else if (node instanceof IASTStatement) { return getContainingScope((IASTStatement) node); - else if (node instanceof IASTParameterDeclaration) { + } else if (node instanceof IASTExpression) { IASTNode parent = node.getParent(); - if (parent instanceof IASTStandardFunctionDeclarator) { - parent = ((IASTDeclarator)parent).getParent(); - if (parent instanceof IASTFunctionDefinition) - return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope(); - return null; // parameter name in function declarations + if (parent instanceof IASTForStatement) { + return ((IASTForStatement)parent).getScope(); + } + } else if (node instanceof IASTParameterDeclaration) { + IASTNode parent = node.getParent(); + if (parent instanceof IASTStandardFunctionDeclarator) { + IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) parent; + if (ASTQueries.findTypeRelevantDeclarator(dtor) == dtor) { + parent= ASTQueries.findOutermostDeclarator(dtor); + ASTNodeProperty prop = parent.getPropertyInParent(); + if (prop == IASTSimpleDeclaration.DECLARATOR) + return dtor.getFunctionScope(); + else if (prop == IASTFunctionDefinition.DECLARATOR) + return ((IASTCompoundStatement) ((IASTFunctionDefinition) parent.getParent()).getBody()).getScope(); + } } - } - else if (node instanceof IASTEnumerator) { + } else if (node instanceof IASTEnumerator) { //put the enumerators in the same scope as the enumeration node = node.getParent(); + } else if (node instanceof IASTName) { + ASTNodeProperty prop = node.getPropertyInParent(); + if (prop == IASTLabelStatement.NAME) { + IScope scope= getContainingScope(node.getParent()); + //labels have function scope + while (scope != null && !(scope instanceof ICFunctionScope)) { + try { + scope = scope.getParent(); + } catch (DOMException e) { + scope = e.getProblem(); + break; + } + } + return scope; + } } node = node.getParent(); @@ -1186,22 +1154,18 @@ public class CVisitor extends ASTQueries { IASTCompoundStatement compound = (IASTCompoundStatement) parent; scope = compound.getScope(); } else if (parent instanceof IASTStatement) { - scope = getContainingScope((IASTStatement)parent); + if (parent instanceof IASTForStatement) { + scope= ((IASTForStatement) parent).getScope(); + } else { + scope = getContainingScope((IASTStatement)parent); + } } else if (parent instanceof IASTFunctionDefinition) { - IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator(); - IBinding function = ASTQueries.findInnermostDeclarator(fnDeclarator).getName().resolveBinding(); - try { - if (function instanceof IFunction) { - scope = ((IFunction)function).getFunctionScope(); - } else if (function instanceof ProblemBinding) { - return (IScope) function; - } - } catch (DOMException e) { - return e.getProblem(); - } + return ((IASTFunctionDefinition) parent).getScope(); + } else { + return getContainingScope(parent); } - if (statement instanceof IASTGotoStatement || statement instanceof IASTLabelStatement) { + if (statement instanceof IASTGotoStatement) { //labels have function scope while (scope != null && !(scope instanceof ICFunctionScope)) { try { @@ -1237,204 +1201,84 @@ public class CVisitor extends ASTQueries { } /** - * if (bits & PREFIX_LOOKUP) then returns IBinding[] - * otherwise returns IBinding + * Lookup for a name starting from the given scope. */ - protected static Object findBinding(IASTNode blockItem, IASTName name, int bits) throws DOMException{ + protected static IBinding lookup(IScope scope, IASTName name) throws DOMException{ + if (scope == null) + return null; + IIndexFileSet fileSet= IIndexFileSet.EMPTY; - if (blockItem != null) { - final IASTTranslationUnit tu= blockItem.getTranslationUnit(); - if (tu != null) { - final IIndexFileSet fs= (IIndexFileSet) tu.getAdapter(IIndexFileSet.class); - if (fs != null) { - fileSet= fs; - } + IASTTranslationUnit tu= name.getTranslationUnit(); + if (tu == null && scope instanceof IASTInternalScope) { + tu= ((IASTInternalScope) scope).getPhysicalNode().getTranslationUnit(); + } + if (tu != null) { + final IIndexFileSet fs= (IIndexFileSet) tu.getAdapter(IIndexFileSet.class); + if (fs != null) { + fileSet= fs; } } - boolean prefix = (bits & PREFIX_LOOKUP) != 0; - @SuppressWarnings("unchecked") - Object binding = prefix ? new ObjectSet(2) : null; - IIndexBinding foundIndexBinding= null; - CharArrayObjectMap prefixMap = prefix ? new CharArrayObjectMap(2) : null; - - while (blockItem != null) { - IASTNode parent = blockItem.getParent(); - IASTNode[] nodes = null; - IScope scope = null; - if (parent instanceof IASTCompoundStatement) { - IASTCompoundStatement compound = (IASTCompoundStatement) parent; - scope = compound.getScope(); - - if (parent.getParent() instanceof IASTFunctionDefinition) { - IASTFunctionDeclarator dtor = ((IASTFunctionDefinition)parent.getParent()).getDeclarator(); - if (dtor instanceof IASTStandardFunctionDeclarator) - nodes = ((IASTStandardFunctionDeclarator)dtor).getParameters(); - else if (dtor instanceof ICASTKnRFunctionDeclarator) - nodes = ((ICASTKnRFunctionDeclarator)dtor).getParameterDeclarations(); - } - if (nodes == null || nodes.length == 0) { - nodes = compound.getStatements(); - } - } else if (parent instanceof IASTTranslationUnit) { - IASTTranslationUnit translation = (IASTTranslationUnit) parent; - if (!prefix) { - nodes = translation.getDeclarations(); - scope = translation.getScope(); - } else { - // The index will be search later, still we need to look at the declarations found in - // the AST, bug 180883 - nodes = translation.getDeclarations(); - } - } else if (parent instanceof IASTStandardFunctionDeclarator) { - IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) parent; - nodes = dtor.getParameters(); - scope = getContainingScope(blockItem); - } else if (parent instanceof ICASTKnRFunctionDeclarator) { - ICASTKnRFunctionDeclarator dtor = (ICASTKnRFunctionDeclarator) parent; - nodes = dtor.getParameterDeclarations(); - scope = getContainingScope(blockItem); + while (scope != null) { + try { + if (!(scope instanceof ICCompositeTypeScope)) { + IBinding binding = scope.getBinding(name, true, fileSet); + if (binding != null) + return binding; + } + } catch (DOMException e) { } - - boolean typesOnly = (bits & TAGS) != 0; - boolean includeBlockItem = (bits & INCLUDE_BLOCK_ITEM) != 0; - if (prefix) - scope = null; - - if (scope != null && ASTInternal.isFullyCached(scope)) { - try { - binding = scope.getBinding(name, true, fileSet); - } catch (DOMException e) { - binding = null; - } - if (binding != null) - return binding; - } else { - if (!prefix && scope != null && scope.getParent() == null) { - binding= scope.getBinding(name, false, fileSet); - if (binding != null) { - if (binding instanceof IIndexBinding) { - foundIndexBinding= (IIndexBinding) binding; - } - else { - return binding; - } - } - } - - Object result = null; - boolean reachedBlockItem = false; - if (nodes != null) { - int idx = -1; - IASTNode node = nodes.length > 0 ? nodes[++idx] : null; - while (node != null) { - Object candidate = null; - try { - candidate = checkForBinding(scope, node, name, typesOnly, prefixMap); - } catch (DOMException e) { - continue; - } - - if (result == null && !reachedBlockItem && - (includeBlockItem || (node != blockItem))) - { - result = candidate; - } - if (node == blockItem) { - reachedBlockItem = true; - } - - if (idx > -1 && ++idx < nodes.length) { - node = nodes[idx]; - } else { - node = null; - if (nodes[0].getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER || - nodes[0].getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER) - { - //function body, we were looking at parameters, now check the body itself - IASTCompoundStatement compound = null; - if (parent instanceof IASTCompoundStatement) { - compound = (IASTCompoundStatement) parent; - } else if (parent instanceof IASTFunctionDeclarator) { - IASTNode n = parent.getParent(); - while (n instanceof IASTDeclarator) - n = n.getParent(); - if (n instanceof IASTFunctionDefinition) { - compound = (IASTCompoundStatement) ((IASTFunctionDefinition)n).getBody(); - } - } - if (compound != null) { - nodes = compound.getStatements(); - if (nodes.length > 0) { - idx = 0; - node = nodes[0]; - } - } - } - } - } - - } else { - try { - result = checkForBinding(scope, parent, name, typesOnly, prefixMap); - } catch (DOMException e) { - } - } - if (scope != null) { - try { - ASTInternal.setFullyCached(scope, true); - } catch (DOMException e) { - } - } - if (result != null) { - if (CVisitor.declaredBefore((IASTName)result, name)) { - return ((IASTName)result).resolveBinding(); - } - } - } - if ((bits & CURRENT_SCOPE) == 0) - blockItem = parent; - else - blockItem = null; - - if (blockItem instanceof IASTTranslationUnit) - break; + scope= scope.getParent(); } - if (foundIndexBinding != null) { - return foundIndexBinding; - } - if (prefixMap != null) { - IBinding[] result = null; - Object[] vals = prefixMap.valueArray(); - for (Object val : vals) { - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, ((IASTName) val).resolveBinding()); - } - - IASTTranslationUnit tu = (IASTTranslationUnit)blockItem; - IIndex index = tu.getIndex(); - if (index != null) { - try { - IndexFilter filter = IndexFilter.C_DECLARED_OR_IMPLICIT; - IBinding[] bindings= prefix - ? index.findBindingsForPrefix(name.toCharArray(), true, filter, null) - : index.findBindings(name.toCharArray(), filter, null); - bindings= fileSet.filterFileLocalBindings(bindings); - result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings); - } catch (CoreException e) { - CCorePlugin.log(e); - } - } - - return ArrayUtil.trim(IBinding.class, result); - } - if (blockItem != null) { - if (binding == null) - return externalBinding((IASTTranslationUnit) blockItem, name); - return binding; - } - return null; + + return externalBinding(tu, name); } + /** + * if (bits & PREFIX_LOOKUP) then returns IBinding[] + * otherwise returns IBinding + */ + protected static IBinding[] lookupPrefix(IScope scope, IASTName name) throws DOMException{ + if (scope == null) + return null; + + IIndexFileSet fileSet= IIndexFileSet.EMPTY; + IASTTranslationUnit tu= name.getTranslationUnit(); + if (tu == null && scope instanceof IASTInternalScope) { + tu= ((IASTInternalScope) scope).getPhysicalNode().getTranslationUnit(); + } + if (tu != null) { + final IIndexFileSet fs= (IIndexFileSet) tu.getAdapter(IIndexFileSet.class); + if (fs != null) { + fileSet= fs; + } + } + + CharArrayObjectMap prefixMap = new CharArrayObjectMap(2); + while (scope != null) { + try { + if (!(scope instanceof ICCompositeTypeScope)) { + IBinding[] bindings= scope.getBindings(name, true, true, fileSet); + for (IBinding b : bindings) { + final char[] n= b.getNameCharArray(); + if (!prefixMap.containsKey(n)) { + prefixMap.put(n, b); + } + } + } + } catch (DOMException e) { + } + scope= scope.getParent(); + } + + IBinding[] result = null; + Object[] vals = prefixMap.valueArray(); + for (Object val : vals) { + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, val); + } + return (IBinding[]) ArrayUtil.trim(IBinding.class, result); + } + private static IBinding externalBinding(IASTTranslationUnit tu, IASTName name) { IASTNode parent = name.getParent(); IBinding external = null; @@ -1442,7 +1286,7 @@ public class CVisitor extends ASTQueries { if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { //external function external = new CExternalFunction(tu, name); - ((CScope)tu.getScope()).addName(name); + ASTInternal.addName(tu.getScope(), name); } else { //external variable @@ -1454,182 +1298,6 @@ public class CVisitor extends ASTQueries { return external; } - private static IASTName checkForBinding(IScope scope, IASTDeclSpecifier declSpec, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap) throws DOMException{ - IASTName tempName = null; - IASTName resultName = null; - char[] n = name.toCharArray(); - if (declSpec instanceof ICASTElaboratedTypeSpecifier) { - tempName = ((ICASTElaboratedTypeSpecifier)declSpec).getName(); - - // Don't include the query name in the results - if (tempName == name) { - return null; - } - - if (scope != null) - ASTInternal.addName(scope, tempName); - if (typesOnly) { - if (prefixMap != null) - prefixMap = (CharArrayObjectMap) collectResult(tempName, n, prefixMap); - else if (collectResult(tempName, n, prefixMap) != null) - resultName = tempName; - } - } else if (declSpec instanceof ICASTCompositeTypeSpecifier) { - tempName = ((ICASTCompositeTypeSpecifier)declSpec).getName(); - if (scope != null) - ASTInternal.addName(scope, tempName); - - if (typesOnly) { - if (prefixMap != null) - prefixMap = (CharArrayObjectMap) collectResult(tempName, n, prefixMap); - else if (collectResult(tempName, n, prefixMap) != null) - resultName = tempName; - } - //also have to check for any nested structs - IASTDeclaration[] nested = ((ICASTCompositeTypeSpecifier)declSpec).getMembers(); - for (IASTDeclaration element : nested) { - if (element instanceof IASTSimpleDeclaration) { - IASTDeclSpecifier d = ((IASTSimpleDeclaration)element).getDeclSpecifier(); - if (d instanceof ICASTCompositeTypeSpecifier || d instanceof IASTEnumerationSpecifier) { - Object obj = checkForBinding(scope, d, name, typesOnly, prefixMap); - if (prefixMap == null && resultName == null) { - resultName = (IASTName) obj; - } - } - } - } - } else if (declSpec instanceof ICASTEnumerationSpecifier) { - ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec; - tempName = enumeration.getName(); - if (scope != null) - ASTInternal.addName(scope, tempName); - if (typesOnly) { - if (prefixMap != null) - prefixMap = (CharArrayObjectMap) collectResult(tempName, n, prefixMap); - else if (collectResult(tempName, n, prefixMap) != null) - resultName = tempName; - } - //check enumerators - IASTEnumerator[] list = ((ICASTEnumerationSpecifier) declSpec).getEnumerators(); - for (IASTEnumerator enumerator : list) { - if (enumerator == null) break; - tempName = enumerator.getName(); - if (scope != null) - ASTInternal.addName(scope, tempName); - if (!typesOnly) { - if (prefixMap != null) - prefixMap = (CharArrayObjectMap) collectResult(tempName, n, prefixMap); - else if (collectResult(tempName, n, prefixMap) != null) - resultName = tempName; - } - } - } - return resultName; - } - - private static Object collectResult(IASTName candidate, char[] name, CharArrayObjectMap prefixMap) { - char[] c = candidate.toCharArray(); - if (prefixMap == null && CharArrayUtils.equals(c, name)) { - return candidate; - } else if (prefixMap != null && CharArrayUtils.equals(c, 0, name.length, name, true) && !prefixMap.containsKey(c)) { - prefixMap.put(c, candidate); - } - return prefixMap; - } - - private static IASTName checkForBinding(IScope scope, IASTParameterDeclaration paramDecl, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap) throws DOMException{ - if (paramDecl == null) return null; - - IASTDeclarator dtor = paramDecl.getDeclarator(); - while (dtor.getNestedDeclarator() != null) { - dtor = dtor.getNestedDeclarator(); - } - IASTName tempName = dtor.getName(); - if (scope != null) - ASTInternal.addName(scope, tempName); - - if (!typesOnly) { - char[] c = tempName.toCharArray(); - char[] n = name.toCharArray(); - if (prefixMap == null && CharArrayUtils.equals(c, n)) - return tempName; - else if (prefixMap != null && CharArrayUtils.equals(c, 0, n.length, n, true) && !prefixMap.containsKey(c)) - prefixMap.put(c, tempName); - } else { - return checkForBinding(scope, paramDecl.getDeclSpecifier(), name, typesOnly, prefixMap); - } - return null; - } - - /** - * if not a prefix lookup, returns IASTName - * if doing prefix lookup, results are in prefixMap, returns null - */ - private static IASTName checkForBinding(IScope scope, IASTNode node, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap) throws DOMException{ - if (node instanceof IASTDeclaration) { - return checkForBinding(scope, (IASTDeclaration) node, name, typesOnly, prefixMap); - } else if (node instanceof IASTParameterDeclaration) { - return checkForBinding(scope, (IASTParameterDeclaration) node, name, typesOnly, prefixMap); - } else if (node instanceof IASTDeclarationStatement) { - return checkForBinding(scope, ((IASTDeclarationStatement)node).getDeclaration(), name, typesOnly, prefixMap); - } else if (node instanceof IASTForStatement) { - IASTForStatement forStatement = (IASTForStatement) node; - if (forStatement.getInitializerStatement() instanceof IASTDeclarationStatement) { - return checkForBinding(scope, ((IASTDeclarationStatement)forStatement.getInitializerStatement()).getDeclaration(), name, typesOnly, prefixMap); - } - } - return null; - } - - private static IASTName checkForBinding(IScope scope, IASTDeclaration declaration, IASTName name, boolean typesOnly, CharArrayObjectMap prefixMap) throws DOMException{ - char[] n = name.toCharArray(); - IASTName tempName = null; - IASTName resultName = null; - if (declaration instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration; - IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); - for (IASTDeclarator declarator : declarators) { - declarator= ASTQueries.findInnermostDeclarator(declarator); - tempName = declarator.getName(); - if (scope != null) - ASTInternal.addName(scope, tempName); - - if (!typesOnly) { - if (prefixMap != null) - prefixMap = (CharArrayObjectMap) collectResult(tempName, n, prefixMap); - else if (collectResult(tempName, n, prefixMap) != null) - resultName = tempName; - - } - } - tempName = checkForBinding(scope, simpleDeclaration.getDeclSpecifier(), name, typesOnly, prefixMap); - if (prefixMap == null && tempName != null) { - resultName = tempName; - } - } else if (!typesOnly && declaration instanceof IASTFunctionDefinition) { - IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; - - IASTDeclarator dtor = ASTQueries.findInnermostDeclarator(functionDef.getDeclarator()); - tempName = dtor.getName(); - if (scope != null) - ASTInternal.addName(scope, tempName); - - if (!typesOnly) { - if (prefixMap != null) - prefixMap = (CharArrayObjectMap) collectResult(tempName, n, prefixMap); - else if (collectResult(tempName, n, prefixMap) != null) - resultName = tempName; - } - - tempName = checkForBinding(scope, functionDef.getDeclSpecifier(), name, typesOnly, prefixMap); - if (prefixMap == null && tempName != null) { - resultName = tempName; - } - } - - return resultName; - } - protected static IASTDeclarator findDefinition(IASTDeclarator declarator, int beginAtLoc) { return (IASTDeclarator) findDefinition(declarator, declarator.getName().toCharArray(), beginAtLoc); } @@ -1702,10 +1370,6 @@ public class CVisitor extends ASTQueries { return null; } - public static void clearBindings(IASTTranslationUnit tu) { - tu.accept(new ClearBindingAction()); - } - /** * Create an IType for an IASTDeclarator. * @@ -1978,20 +1642,6 @@ public class CVisitor extends ASTQueries { return action.getReferences(); } - public static IBinding findTypeBinding(IASTNode startingPoint, IASTName name) throws DOMException { - if (startingPoint instanceof IASTTranslationUnit) { - IASTDeclaration[] declarations = ((IASTTranslationUnit)startingPoint).getDeclarations(); - if (declarations.length > 0) - return (IBinding) findBinding(declarations[declarations.length - 1], name, COMPLETE | INCLUDE_BLOCK_ITEM ); - } - if (startingPoint instanceof IASTCompoundStatement) { - IASTStatement[] statements = ((IASTCompoundStatement)startingPoint).getStatements(); - if (statements.length > 0) - return (IBinding) findBinding(statements[statements.length - 1], name, COMPLETE | INCLUDE_BLOCK_ITEM); - } - return null; - } - public static IBinding[] findBindingsForContentAssist(IASTName name, boolean isPrefix) { ASTNodeProperty prop = name.getPropertyInParent(); @@ -2000,36 +1650,25 @@ public class CVisitor extends ASTQueries { if (prop == IASTFieldReference.FIELD_NAME) { result = (IBinding[]) findBinding((IASTFieldReference) name.getParent(), isPrefix); } else { - int bits = isPrefix ? PREFIX_LOOKUP : COMPLETE; - if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { - bits |= TAGS; - } else if (prop == IASTIdExpression.ID_NAME) { - bits |= INCLUDE_BLOCK_ITEM; - } - - IASTNode blockItem = getContainingBlockItem(name); - try { - result = isPrefix ? (IBinding[]) findBinding(blockItem, name, bits) : - new IBinding[] { (IBinding) findBinding(blockItem, name, bits) }; - } catch (DOMException e) { + IScope scope= getContainingScope(name); + try { + if (isPrefix) { + result = lookupPrefix(scope, name); + } else { + result = new IBinding[] { lookup(scope, name) }; + } + } catch (DOMException e) { } } - return (IBinding[]) ArrayUtil.trim(IBinding.class, result); } - public static IBinding[] findBindings(IScope scope, String name, boolean prefixLookup) throws DOMException { - IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope); - if (node instanceof IASTFunctionDefinition) - node = ((IASTFunctionDefinition)node).getBody(); - + public static IBinding[] findBindings(IScope scope, String name) throws DOMException { CASTName astName = new CASTName(name.toCharArray()); - astName.setParent(node); //normal names astName.setPropertyInParent(STRING_LOOKUP_PROPERTY); - int flags = prefixLookup ? COMPLETE | PREFIX_LOOKUP : COMPLETE; - Object o1 = findBinding(astName, astName, flags); + Object o1 = lookup(scope, astName); IBinding[] b1 = null; if (o1 instanceof IBinding) { @@ -2040,8 +1679,7 @@ public class CVisitor extends ASTQueries { //structure names astName.setPropertyInParent(STRING_LOOKUP_TAGS_PROPERTY); - flags = prefixLookup ? COMPLETE | TAGS | PREFIX_LOOKUP : COMPLETE | TAGS; - Object o2 = findBinding(astName, astName, flags); + Object o2 = lookup(scope, astName); IBinding[] b2 = null; if (o2 instanceof IBinding) { @@ -2057,19 +1695,12 @@ public class CVisitor extends ASTQueries { if (scope instanceof ICFunctionScope) { ILabel[] labels = ((CFunctionScope)scope).getLabels(); for (ILabel label : labels) { - if (prefixLookup) { - if (CharArrayUtils.equals(label.getNameCharArray(), - 0, n.length, n, true)) { - b3.add(label); - } - } else { - if (CharArrayUtils.equals(label.getNameCharArray(), n)) { - b3.add(label); - break; - } - } + if (CharArrayUtils.equals(label.getNameCharArray(), n)) { + b3.add(label); + break; + } } - if (!prefixLookup) break; + break; } scope = scope.getParent(); } while (scope != null); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 1a7721627ae..f0d8dc8bbcd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -304,6 +304,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTDeclSpecifier declSpec= null; IASTDeclarator dtor= null; + IASTDeclSpecifier altDeclSpec= null; + IASTDeclarator altDeclarator= null; IToken markBeforDtor= null; try { declSpec = declSpecifierSeq(declOption); @@ -341,6 +343,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (e.altSpec != null) { declSpec= e.altSpec; dtor= e.altDeclarator; + altDeclSpec= e.declSpec; + altDeclarator= e.declarator; } else { declSpec = e.declSpec; dtor= e.declarator; @@ -411,6 +415,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { simpleDeclaration.addDeclarator(declarator); ((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset, endOffset-firstOffset); + if ( altDeclSpec != null && altDeclarator != null) { + simpleDeclaration= new CASTAmbiguousSimpleDeclaration(simpleDeclaration, altDeclSpec, altDeclarator); + } if (insertSemi) { IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, endOffset, 0); @@ -425,7 +432,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(firstOffset, LA(1).getEndOffset()); final IASTDeclarator outerDtor= declarators[0]; - final IASTDeclarator fdtor= CVisitor.findTypeRelevantDeclarator(outerDtor); + final IASTDeclarator fdtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); if (fdtor instanceof IASTFunctionDeclarator == false) throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); @@ -1147,7 +1154,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { case IToken.tLBRACE: if (option == DeclarationOptions.GLOBAL || option == DeclarationOptions.C_MEMBER || option == DeclarationOptions.FUNCTION_STYLE_ASM) { - if (CVisitor.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator) { + if (ASTQueries.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator) { return true; } } @@ -1392,9 +1399,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { // try abstract declarator if (!option.fAllowAbstract) { - // bit-fields may be abstract - if (!option.fAllowBitField || LT(1) != IToken.tCOLON) - throwBacktrack(LA(1)); + throwBacktrack(LA(1)); } return declarator(pointerOps, nodeFactory.newName(), null, startingOffset, endOffset, option); } @@ -1465,7 +1470,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } private boolean isAbstract(IASTName declaratorName, IASTDeclarator nestedDeclarator) { - nestedDeclarator= CVisitor.findInnermostDeclarator(nestedDeclarator); + nestedDeclarator= ASTQueries.findInnermostDeclarator(nestedDeclarator); if (nestedDeclarator != null) { declaratorName= nestedDeclarator.getName(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java deleted file mode 100644 index 8a67647fe01..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser.cpp; - -import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; - -public abstract class CPPASTAmbiguity extends ASTAmbiguousNode { - @Override - protected IScope getAffectedScope() { - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java index 633bd793f04..1b516bda6ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.Assert; @@ -26,7 +27,7 @@ import org.eclipse.core.runtime.Assert; *
* Example: void f(int (D)); // is D a type? */ -public class CPPASTAmbiguousDeclarator extends CPPASTAmbiguity implements IASTAmbiguousDeclarator { +public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmbiguousDeclarator { private IASTDeclarator[] dtors = new IASTDeclarator[2]; private int dtorPos=-1; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java index 5e4ea023b90..72bd23bca84 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java @@ -13,24 +13,18 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -public class CPPASTAmbiguousExpression extends CPPASTAmbiguity implements +public class CPPASTAmbiguousExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression { private IASTExpression [] exp = new IASTExpression[2]; private int expPos=-1; - @Override - public IScope getAffectedScope() { - // an expression does not introduce names to a parent scope. - return null; - } - public CPPASTAmbiguousExpression(IASTExpression... expressions) { for(IASTExpression e : expressions) addExpression(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java index 2c86296c595..c21dea58066 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java @@ -15,10 +15,11 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements +public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbiguousStatement { private IASTStatement [] stmts = new IASTStatement[2]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java index f13b697515b..02a212385eb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java @@ -18,15 +18,15 @@ import java.util.List; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAmbiguousTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.parser.ParserMessages; /** * Ambiguity node for deciding between type-id and id-expression in a template argument. */ -public class CPPASTAmbiguousTemplateArgument extends CPPASTAmbiguity implements ICPPASTAmbiguousTemplateArgument { +public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements ICPPASTAmbiguousTemplateArgument { private List fNodes; @@ -54,12 +54,6 @@ public class CPPASTAmbiguousTemplateArgument extends CPPASTAmbiguity implements throw new UnsupportedOperationException(); } - @Override - protected IScope getAffectedScope() { - // a template argument does not introduce names to a parent scope. - return null; - } - @Override public IASTNode[] getNodes() { return fNodes.toArray(new IASTNode[fNodes.size()]); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index f99cae09fc5..02ac927571c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -203,7 +203,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } public void checkForDefinition() { - if (!checked) { + if (!checked && definition == null) { FindDefinitionAction action = new FindDefinitionAction(); IASTNode node = CPPVisitor.getContainingBlockItem(getPhysicalNode()).getParent(); @@ -225,9 +225,8 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } } } - checked = true; } - return; + checked = true; } public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() { @@ -282,9 +281,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } public ICPPClassScope getCompositeScope() { - if (definition == null) { - checkForDefinition(); - } + checkForDefinition(); if (definition != null) { return getCompositeTypeSpecifier().getScope(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPASTInternalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPASTInternalScope.java index 0f7e5f385bf..bb8d357c4f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPASTInternalScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPASTInternalScope.java @@ -29,11 +29,4 @@ public interface ICPPASTInternalScope extends IASTInternalScope, ICPPScope { */ public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings, boolean checkPointOfDecl) throws DOMException; - - /** - * Can be called during ambiguity resolution to populate a scope without considering - * the ambiguous branches. The rest of the names has to be cached one by one after - * the ambiguities have been resolved. - */ - public void populateCache(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java index 5c43387ad0b..cc5423e6619 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 QNX Software Systems and others. + * Copyright (c) 2006, 2009 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,6 @@ * Markus Schorn (Wind River Systems) * Andrew Ferguson (Symbian) *******************************************************************************/ - package org.eclipse.cdt.internal.core.pdom.dom.c; import java.util.ArrayList; @@ -43,7 +42,6 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Status; @@ -113,7 +111,7 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom @Override public Object clone() { - throw new PDOMNotImplementedError(); + throw new UnsupportedOperationException(); } public int getKey() throws DOMException { @@ -226,8 +224,8 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom return result; } - public IScope getCompositeScope() throws DOMException { - throw new PDOMNotImplementedError(); + public IScope getCompositeScope() { + return this; } public boolean isSameType(IType type) { @@ -274,21 +272,28 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom } public IBinding getBinding(char[] name) throws DOMException { - fail(); return null; + return findField(new String(name)); } @Override public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException { - fail(); return null; + return getBinding(name.toCharArray()); } @Override public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { - fail(); return null; + return getBindings(name.toCharArray()); } public IBinding[] find(String name) throws DOMException { - fail(); return null; + return getBindings(name.toCharArray()); + } + + private IBinding[] getBindings(char[] name) throws DOMException { + IBinding b= getBinding(name); + if (b == null) + return IBinding.EMPTY_BINDING_ARRAY; + return new IBinding[]{b}; } public IIndexBinding getScopeBinding() { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_SingleName_NoPrefix.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_SingleName_NoPrefix.java index 187744188f7..a595089caac 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_SingleName_NoPrefix.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_SingleName_NoPrefix.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * IBM Rational Software - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.text.contentassist2; @@ -39,9 +39,6 @@ public class CompletionTest_SingleName_NoPrefix extends CompletionProposalsBase "xOtherClass", "AStruct", "XStruct", - "__FUNCTION__ : const char *", - "__PRETTY_FUNCTION__ : const char *", - "__func__ : const char *", "aNamespace", "xNamespace", "anEnumeration", diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index b283d536952..e7fb73c3056 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 QNX Software Systems and others. + * Copyright (c) 2007, 2009 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -66,6 +66,12 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.ICPartitions; +import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CBuiltinParameter; +import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter; +import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinVariable; +import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitFunction; +import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitTypedef; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef; @@ -263,7 +269,14 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer List proposals) { if ((binding instanceof CPPImplicitFunction - || binding instanceof CPPImplicitFunctionTemplate || binding instanceof CPPImplicitTypedef) + || binding instanceof CPPImplicitFunctionTemplate + || binding instanceof CPPImplicitTypedef + || binding instanceof CPPBuiltinVariable + || binding instanceof CPPBuiltinParameter + || binding instanceof CImplicitFunction + || binding instanceof CImplicitTypedef + || binding instanceof CBuiltinVariable + || binding instanceof CBuiltinParameter) && !(binding instanceof CPPImplicitMethod)) { return; } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java index ab00f6dcbed..af22d736608 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. + * Copyright (c) 2006, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -90,20 +90,7 @@ public class C99Scope implements IC99Scope, IASTInternalScope { throw new UnsupportedOperationException(); } - public void flushCache() { - - } - - public boolean isFullyCached() { - return true; - } - - public void removeBinding(IBinding binding) { - - } - - public void setFullyCached(boolean b) { - + public void populateCache() { } public IBinding getBinding(IASTName name, boolean resolve,