From e27ca67746b8eb82aa620cb4039bb16507745303 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 8 Jun 2015 12:44:29 -0700 Subject: [PATCH] Improved robustness of global scope handling. Change-Id: Id0222766e8c5e258f866f9a4c8b3307a06bdf4c7 --- .../core/parser/tests/ast2/AST2CPPTests.java | 76 ++++++----- .../cdt/core/parser/tests/ast2/AST2Tests.java | 13 +- .../cdt/internal/index/tests/Bug246129.java | 122 +++++++----------- .../cdt/internal/pdom/tests/ClassTests.java | 74 ++++++----- .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- .../org/eclipse/cdt/core/dom/ast/IScope.java | 78 ++++++----- .../core/dom/parser/ProblemBinding.java | 5 + .../internal/core/dom/parser/c/CScope.java | 5 + .../internal/core/dom/parser/c/CVisitor.java | 6 +- .../AbstractCPPClassSpecializationScope.java | 6 + .../core/dom/parser/cpp/CPPClassScope.java | 6 + .../core/dom/parser/cpp/CPPClosureType.java | 12 +- .../core/dom/parser/cpp/CPPScope.java | 5 + .../core/dom/parser/cpp/CPPScopeMapper.java | 6 + .../dom/parser/cpp/CPPUnknownTypeScope.java | 6 + .../parser/cpp/semantics/CPPSemantics.java | 32 +++-- .../dom/parser/cpp/semantics/CPPVisitor.java | 23 +--- .../dom/parser/cpp/semantics/LookupData.java | 6 + .../parser/cpp/semantics/SemanticUtil.java | 16 ++- .../composite/c/CompositeCCompositeScope.java | 7 + .../composite/cpp/CompositeCPPClassScope.java | 7 + .../CompositeCPPClassSpecializationScope.java | 7 + .../composite/cpp/CompositeCPPEnumScope.java | 19 ++- .../cpp/CompositeCPPNamespaceScope.java | 12 ++ .../core/pdom/dom/PDOMGlobalScope.java | 31 ++++- .../core/pdom/dom/c/PDOMCStructure.java | 6 + .../core/pdom/dom/cpp/PDOMCPPClassScope.java | 6 + .../cpp/PDOMCPPClassSpecializationScope.java | 8 ++ .../core/pdom/dom/cpp/PDOMCPPEnumScope.java | 6 + .../core/pdom/dom/cpp/PDOMCPPNamespace.java | 6 + core/org.eclipse.cdt.core/pom.xml | 2 +- .../ui/refactoring/rename/ASTManager.java | 12 +- .../rename/CRenameClassProcessor.java | 4 +- .../dom/lrparser/c99/bindings/C99Scope.java | 29 ++--- 34 files changed, 386 insertions(+), 275 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 3de57ae75c3..d12bf9a9d1c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -29,8 +29,6 @@ import java.io.StringReader; import java.util.Arrays; import java.util.HashSet; -import junit.framework.TestSuite; - import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.EScopeKind; @@ -153,6 +151,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil; import org.eclipse.cdt.internal.core.parser.ParserException; +import junit.framework.TestSuite; + public class AST2CPPTests extends AST2TestBase { public AST2CPPTests() { @@ -3408,16 +3408,16 @@ public class AST2CPPTests extends AST2TestBase { ICPPVariable v2 = (ICPPVariable) col.getName(3).resolveBinding(); String[] s = v1.getQualifiedName(); - assertEquals(s[0], "v1"); + assertEquals("v1", s[0]); assertFalse(v1.isGloballyQualified()); s = v2.getQualifiedName(); - assertEquals(s[0], "v2"); + assertEquals("v2", s[0]); assertFalse(v2.isGloballyQualified()); ICPPBlockScope scope = (ICPPBlockScope) v2.getScope(); - IBinding[] bs = scope.find("v1"); - assertEquals(bs.length, 1); + IBinding[] bs = scope.find("v1", tu); + assertEquals(1, bs.length); assertSame(bs[0], v1); } @@ -3437,17 +3437,17 @@ public class AST2CPPTests extends AST2TestBase { ICPPMethod f = (ICPPMethod) col.getName(7).resolveBinding(); IScope scope = f.getFunctionScope(); - IBinding[] bs = scope.find("a"); - assertEquals(bs.length, 1); + IBinding[] bs = scope.find("a", tu); + assertEquals(1, bs.length); assertSame(bs[0], a); - bs = scope.find("~B"); - assertEquals(bs.length, 1); + bs = scope.find("~B", tu); + assertEquals(1, bs.length); assertTrue(bs[0] instanceof ICPPMethod); assertTrue(bs[0].getName().equals("~B")); - bs = scope.find("A"); - assertEquals(bs.length, 1); + bs = scope.find("A", tu); + assertEquals(1, bs.length); assertSame(bs[0], A); } @@ -3470,16 +3470,16 @@ public class AST2CPPTests extends AST2TestBase { IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(5).getParent().getParent(); IScope scope = ((IASTCompoundStatement) def.getBody()).getScope(); - IBinding[] bs = scope.find("f"); + IBinding[] bs = scope.find("f", tu); assertEquals(3, bs.length); assertSame(bs[0], f3); assertSame(bs[1], f1); assertSame(bs[2], f2); String[] s = ((ICPPBinding) bs[1]).getQualifiedName(); - assertEquals(s.length, 2); - assertEquals(s[0], "A"); - assertEquals(s[1], "f"); + assertEquals(2, s.length); + assertEquals("A", s[0]); + assertEquals("f", s[1]); assertTrue(((ICPPBinding) bs[1]).isGloballyQualified()); } @@ -3508,7 +3508,7 @@ public class AST2CPPTests extends AST2TestBase { IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(8).getParent().getParent(); IScope scope = ((IASTCompoundStatement) def.getBody()).getScope(); - IBinding[] bs = scope.find("f"); + IBinding[] bs = scope.find("f", tu); assertEquals(3, bs.length); assertSame(bs[0], f); assertSame(bs[1], f1); @@ -3533,21 +3533,21 @@ public class AST2CPPTests extends AST2TestBase { IFunction f1 = (IFunction) col.getName(6).resolveBinding(); IScope classScope= f1.getScope(); assertTrue(classScope instanceof ICPPClassScope); - IBinding[] bindings = classScope.find("bf"); + IBinding[] bindings = classScope.find("bf", tu); ICPPMethod method= extractSingleMethod(bindings); - assertEquals(method.getQualifiedName()[0], "B"); + assertEquals("B", method.getQualifiedName()[0]); - bindings= classScope.find("f"); + bindings= classScope.find("f", tu); method= extractSingleMethod(bindings); - assertEquals(method.getQualifiedName()[0], "A"); + assertEquals("A", method.getQualifiedName()[0]); - bindings= classScope.find("B"); + bindings= classScope.find("B", tu); ICPPClassType classType= extractSingleClass(bindings); - assertEquals(classType.getQualifiedName()[0], "B"); + assertEquals("B", classType.getQualifiedName()[0]); - bindings= classScope.find("A"); + bindings= classScope.find("A", tu); classType= extractSingleClass(bindings); - assertEquals(classType.getQualifiedName()[0], "A"); + assertEquals("A", classType.getQualifiedName()[0]); } // class A { @@ -3571,39 +3571,39 @@ public class AST2CPPTests extends AST2TestBase { ICPPMethod fb = (ICPPMethod) col.getName(6).resolveBinding(); Object[] result = B.getDeclaredFields(); - assertEquals(result.length, 1); + assertEquals(1, result.length); assertSame(result[0], b); result = B.getFields(); - assertEquals(result.length, 2); + assertEquals(2, result.length); assertSame(result[0], b); assertSame(result[1], a); result = B.getDeclaredMethods(); - assertEquals(result.length, 1); + assertEquals(1, result.length); assertSame(result[0], fb); result = B.getAllDeclaredMethods(); - assertEquals(result.length, 2); + assertEquals(2, result.length); assertSame(result[0], fb); assertSame(result[1], fa); ICPPMethod[] B_implicit = ((ICPPClassScope) B.getCompositeScope()).getImplicitMethods(); - assertEquals(B_implicit.length, 4); + assertEquals(4, B_implicit.length); assertTrue(B_implicit[0].getName().equals("B")); assertTrue(B_implicit[1].getName().equals("B")); assertTrue(B_implicit[2].getName().equals("operator =")); assertTrue(B_implicit[3].getName().equals("~B")); ICPPMethod[] A_implicit = ((ICPPClassScope) A.getCompositeScope()).getImplicitMethods(); - assertEquals(A_implicit.length, 4); + assertEquals(4, A_implicit.length); assertTrue(A_implicit[0].getName().equals("A")); assertTrue(A_implicit[1].getName().equals("A")); assertTrue(A_implicit[2].getName().equals("operator =")); assertTrue(A_implicit[3].getName().equals("~A")); result = B.getMethods(); - assertEquals(result.length, 10); + assertEquals(10, result.length); assertSame(result[0], fb); assertSame(result[1], B_implicit[0]); assertSame(result[2], B_implicit[1]); @@ -3617,8 +3617,7 @@ public class AST2CPPTests extends AST2TestBase { } public void testBug87424() throws Exception { - IASTTranslationUnit tu = parse( - "int * __restrict x;", CPP, true); + IASTTranslationUnit tu = parse("int * __restrict x;", CPP, true); NameCollector col = new NameCollector(); tu.accept(col); @@ -3638,8 +3637,7 @@ public class AST2CPPTests extends AST2TestBase { } public void testBug87705() throws Exception { - IASTTranslationUnit tu = parse( - "class A { friend class B::C; };", CPP, true); + IASTTranslationUnit tu = parse("class A { friend class B::C; };", CPP, true); NameCollector col = new NameCollector(); tu.accept(col); @@ -3659,8 +3657,7 @@ public class AST2CPPTests extends AST2TestBase { } public void testBug88501_1() throws Exception { - IASTTranslationUnit tu = parse( - "void f(); void f(int); struct f;", CPP); + IASTTranslationUnit tu = parse("void f(); void f(int); struct f;", CPP); NameCollector col = new NameCollector(); tu.accept(col); @@ -3679,7 +3676,6 @@ public class AST2CPPTests extends AST2TestBase { // IProblemBinding p = (IProblemBinding) col.getName(1).resolveBinding(); // assertEquals(p.getID(), IProblemBinding.SEMANTIC_INVALID_REDEFINITION); // } - public void testBug8342_2() throws Exception { IASTTranslationUnit tu = parse("extern int a; extern char a;", CPP); NameCollector col = new NameCollector(); @@ -3770,7 +3766,7 @@ public class AST2CPPTests extends AST2TestBase { IFunction f2 = (IFunction) col.getName(3).resolveBinding(); IScope scope = tu.getScope(); - IBinding[] bs = scope.find("f"); + IBinding[] bs = scope.find("f", tu); assertEquals(bs.length, 2); assertSame(bs[0], f1); assertSame(bs[1], f2); 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 dc1c57f363b..fdd1a794c17 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 @@ -20,8 +20,6 @@ import static org.eclipse.cdt.core.parser.ParserLanguage.CPP; import java.io.IOException; -import junit.framework.TestSuite; - import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.EScopeKind; @@ -132,6 +130,8 @@ import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding; import org.eclipse.cdt.internal.core.model.ASTStringUtil; import org.eclipse.cdt.internal.core.parser.ParserException; +import junit.framework.TestSuite; + /** * Test cases on the AST. */ @@ -3080,8 +3080,7 @@ public class AST2Tests extends AST2TestBase { } public void testBug90253() throws Exception { - IASTTranslationUnit tu = parse( - "void f(int par) { int v1; };", C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("void f(int par) { int v1; };", C); //$NON-NLS-1$ NameCollector col = new NameCollector(); tu.accept(col); @@ -3092,11 +3091,11 @@ public class AST2Tests extends AST2TestBase { IASTFunctionDefinition fdef= getDeclaration(tu, 0); IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope(); - IBinding[] bs = scope.find("par"); //$NON-NLS-1$ + IBinding[] bs = scope.find("par", tu); //$NON-NLS-1$ assertEquals(1, bs.length); assertSame(bs[0], p); - bs = scope.find("v1"); //$NON-NLS-1$ + bs = scope.find("v1", tu); //$NON-NLS-1$ assertEquals(bs.length, 1); assertSame(bs[0], v1); } @@ -3123,7 +3122,7 @@ public class AST2Tests extends AST2TestBase { IASTFunctionDefinition fdef= getDeclaration(tu, 2); IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope(); - IBinding[] bs = scope.find("S"); //$NON-NLS-1$ + IBinding[] bs = scope.find("S", tu); //$NON-NLS-1$ assertNotNull(S2); assertEquals(bs.length, 3); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/Bug246129.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/Bug246129.java index d3d6044e7d2..e251865636c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/Bug246129.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/Bug246129.java @@ -6,15 +6,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ + * Markus Schorn - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; import java.io.File; import java.io.FileWriter; -import junit.framework.TestSuite; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -36,6 +34,8 @@ import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; +import junit.framework.TestSuite; + public class Bug246129 extends IndexTestBase { public static TestSuite suite() { @@ -45,29 +45,18 @@ public class Bug246129 extends IndexTestBase { } private ICProject fProject; - - private IFile fSource; - + private IFile fSource; private IFolder fWrapperIncludeFolder; - private IFolder fIncludeFolder; - private File fTmpDir; - private File fExternalWrapperIncludeFolder; - private File fExternalWrapperHeader; - private File fExternalIncludeFolder; - private File fExternalHeader; - private File fExternalExtFolder; - IIndex fIndex; - boolean fFalseFriendsAccepted; - + public Bug246129(String name) { super(name); } @@ -76,26 +65,22 @@ public class Bug246129 extends IndexTestBase { protected void setUp() throws Exception { super.setUp(); if (fProject == null) { - // Populate workspace fProject = createProject(true, "resources/indexTests/bug246129"); - + fSource = fProject.getProject().getFile("source.cpp"); - - fWrapperIncludeFolder = fProject.getProject().getFolder( - "wrapper_include"); - + + fWrapperIncludeFolder = fProject.getProject().getFolder("wrapper_include"); + fIncludeFolder = fProject.getProject().getFolder("include"); // Create header files external to the workspace. fTmpDir = CProjectHelper.freshDir(); - - fExternalWrapperIncludeFolder = new File(fTmpDir, - "wrapper_include"); + + fExternalWrapperIncludeFolder = new File(fTmpDir, "wrapper_include"); fExternalWrapperIncludeFolder.mkdir(); - - fExternalWrapperHeader = new File( - fExternalWrapperIncludeFolder, "external_type.h"); + + fExternalWrapperHeader = new File(fExternalWrapperIncludeFolder, "external_type.h"); fExternalWrapperHeader.createNewFile(); FileWriter writer = new FileWriter(fExternalWrapperHeader); writer.write("#ifndef EXTERNAL_WRAPPER_TYPE_H_\n"); @@ -105,15 +90,14 @@ public class Bug246129 extends IndexTestBase { writer.write("};\n"); writer.write("#endif\n"); writer.close(); - + fExternalIncludeFolder = new File(fTmpDir, "include"); fExternalIncludeFolder.mkdir(); - + fExternalExtFolder = new File(fExternalIncludeFolder, "ext"); fExternalExtFolder.mkdir(); - fExternalHeader = new File(fExternalIncludeFolder, - "external_type.h"); + fExternalHeader = new File(fExternalIncludeFolder, "external_type.h"); fExternalHeader.createNewFile(); writer = new FileWriter(fExternalHeader); writer.write("#ifndef EXTERNAL_TYPE_H_\n"); @@ -125,12 +109,10 @@ public class Bug246129 extends IndexTestBase { // The indexer needs non-empty build info in order to index // source files if index-all-files is turned off. - IPathEntry[] entries = new IPathEntry[] { CoreModel - .newIncludeEntry(fProject.getPath(), null, - fWrapperIncludeFolder.getLocation()), - CoreModel.newIncludeEntry(fProject.getPath(), null, - fIncludeFolder.getLocation()) }; - + IPathEntry[] entries = new IPathEntry[] { + CoreModel.newIncludeEntry(fProject.getPath(), null, fWrapperIncludeFolder.getLocation()), + CoreModel.newIncludeEntry(fProject.getPath(), null, fIncludeFolder.getLocation()) }; + fProject.setRawPathEntries(entries, npm()); // However, the scanner info provider used by the unit tests @@ -144,12 +126,10 @@ public class Bug246129 extends IndexTestBase { IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false"); - File falseFriendDirectory = new File(fWrapperIncludeFolder - .getLocation().toOSString() - + "/ext/.."); + File falseFriendDirectory = new File(fWrapperIncludeFolder.getLocation().toOSString() + "/ext/.."); fFalseFriendsAccepted = falseFriendDirectory.exists(); - + CCorePlugin.getIndexManager().reindex(fProject); waitForIndexer(fProject); fIndex = CCorePlugin.getIndexManager().getIndex(fProject); @@ -160,27 +140,23 @@ public class Bug246129 extends IndexTestBase { protected void tearDown() throws Exception { fExternalWrapperHeader.delete(); fExternalWrapperIncludeFolder.delete(); - + fExternalHeader.delete(); fExternalExtFolder.delete(); fExternalIncludeFolder.delete(); fTmpDir.delete(); - + super.tearDown(); } private void assertSymbolInIndex(String symbolName) throws Exception { - IIndexBinding[] bindings = fIndex.findBindings( - symbolName - .toCharArray(), false, IndexFilter.ALL, npm()); - assertTrue(bindings.length > 0); + IIndexBinding[] bindings = fIndex.findBindings(symbolName.toCharArray(), false, IndexFilter.ALL, npm()); + assertTrue(bindings.length != 0); } - + public void testIndex() throws Exception { - try { - fIndex.acquireReadLock(); IIndexFile[] indexFiles = fIndex.getAllFiles(); @@ -191,10 +167,9 @@ public class Bug246129 extends IndexTestBase { } else { assertEquals(5, indexFiles.length); } - + // The wrapper classes are found regardless whether false friends - // are - // accepted or not. + // are accepted or not. assertSymbolInIndex("Wrapper"); assertSymbolInIndex("ExternalWrapper"); @@ -204,18 +179,16 @@ public class Bug246129 extends IndexTestBase { assertSymbolInIndex("Type"); assertSymbolInIndex("ExternalType"); } - + // Check that all paths are normalized. for (IIndexFile indexFile : indexFiles) { - IIndexInclude[] includes = indexFile.getIncludes(); - + for (IIndexInclude i : includes) { IIndexFileLocation location = i.getIncludesLocation(); assertNotNull(location); - - assertFalse(location.getURI().toASCIIString() - .contains("..")); + + assertFalse(location.getURI().toASCIIString().contains("..")); String fullPath = location.getFullPath(); if (fullPath != null) { @@ -223,41 +196,38 @@ public class Bug246129 extends IndexTestBase { } } } - } finally { fIndex.releaseReadLock(); } } - - private void assertSymbolInAst(IScope scope, String symbolName) - throws Exception { - IBinding[] bindings = scope.find(symbolName); + + private void assertSymbolInAst(IScope scope, String symbolName, IASTTranslationUnit ast) throws Exception { + IBinding[] bindings = scope.find(symbolName, ast); assertTrue(bindings.length > 0); } - + public void testAst() throws Exception { - ITranslationUnit tu = CoreModel.getDefault().createTranslationUnitFrom( - fProject, fSource.getLocation()); + ITranslationUnit tu = + CoreModel.getDefault().createTranslationUnitFrom(fProject, fSource.getLocation()); IASTTranslationUnit ast = tu.getAST(); - + // The wrapper classes are found regardless whether false friends // are // accepted or not. IScope topLevel = ast.getScope(); - assertSymbolInAst(topLevel, "Wrapper"); - assertSymbolInAst(topLevel, "ExternalWrapper"); + assertSymbolInAst(topLevel, "Wrapper", ast); + assertSymbolInAst(topLevel, "ExternalWrapper", ast); // The Type class is only known on platforms with a File // implementation sorting out the false friends. if (!fFalseFriendsAccepted) { - assertSymbolInAst(topLevel, "Type"); - assertSymbolInAst(topLevel, "ExternalType"); + assertSymbolInAst(topLevel, "Type", ast); + assertSymbolInAst(topLevel, "ExternalType", ast); } // Check that all paths are normalized. - IASTPreprocessorIncludeStatement[] includes = ast - .getIncludeDirectives(); + IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); for (IASTPreprocessorIncludeStatement i : includes) { String includedPath = i.getPath(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java index 8be5291ac3f..7331c94d223 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java @@ -15,8 +15,6 @@ package org.eclipse.cdt.internal.pdom.tests; import java.util.regex.Pattern; -import junit.framework.Test; - import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -36,12 +34,12 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; +import junit.framework.Test; + /** * @author Doug Schaefer - * */ public class ClassTests extends PDOMTestBase { - protected PDOM pdom; public static Test suite() { @@ -61,11 +59,11 @@ public class ClassTests extends PDOMTestBase { protected void tearDown() throws Exception { pdom.releaseReadLock(); } - + public void test1() throws Exception { IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), true, IndexFilter.ALL, npm()); assertEquals(1, Bs.length); - ICPPClassType B = (ICPPClassType)Bs[0]; + ICPPClassType B = (ICPPClassType) Bs[0]; ICPPMethod[] Bmethods = B.getAllDeclaredMethods(); assertEquals(4, Bmethods.length); assertNotNull(findMethod(Bmethods, "B")); @@ -78,7 +76,7 @@ public class ClassTests extends PDOMTestBase { IASTFileLocation loc = Bf_refs[0].getFileLocation(); assertEquals(offset("class.cpp", "b.f()") + 2, loc.getNodeOffset()); } - + private ICPPMethod findMethod(ICPPMethod[] bmethods, String name) { for (ICPPMethod method : bmethods) { if (method.getName().equals(name)) { @@ -99,30 +97,30 @@ public class ClassTests extends PDOMTestBase { IField[] fields = NestedB.getFields(); assertEquals(1, fields.length); IField NestedB_x = fields[0]; - + IName[] refs = pdom.findNames(NestedB, IIndex.FIND_REFERENCES); assertEquals(1, refs.length); IASTFileLocation loc = refs[0].getFileLocation(); assertEquals(offset("nested.cpp", "::NestedB") + 2, loc.getNodeOffset()); - + refs = pdom.findNames(NestedB_x, IIndex.FIND_REFERENCES); assertEquals(1, refs.length); loc = refs[0].getFileLocation(); assertEquals(offset("nested.cpp", "x.x") + 2, loc.getNodeOffset()); } - + public void test147903() throws Exception { IBinding[] bindings = pdom.findBindings(Pattern.compile("pr147903"), false, IndexFilter.ALL, npm()); assertEquals(1, bindings.length); - ICPPNamespaceScope ns = ((ICPPNamespace)bindings[0]).getNamespaceScope(); - bindings = ns.find("testRef"); + ICPPNamespaceScope ns = ((ICPPNamespace) bindings[0]).getNamespaceScope(); + bindings = ns.find("testRef", null); assertEquals(1, bindings.length); IName[] refs = pdom.findNames(bindings[0], IIndex.FIND_REFERENCES); // for (int i = 0; i < refs.length; ++i) // System.out.println(refs[i].getFileLocation().getNodeOffset()); assertEquals(5, refs.length); } - + /* Test friend relationships between classes */ public void testFriend() throws Exception { IBinding[] bindings = pdom.findBindings(Pattern.compile("ClassA"), true, IndexFilter.ALL_DECLARED, npm()); @@ -140,40 +138,40 @@ public class ClassTests extends PDOMTestBase { IBinding[] friends = classA.getFriends(); assertEquals(1, friends.length); assertEquals(classC, friends[0]); //ClassC is a friend class of ClassA - + friends = classC.getFriends(); assertEquals(1, friends.length); assertEquals(funcB, friends[0]); //functionB is a friend of ClassC } - + public void noTest_testConstructor() throws Exception { // the source does not define Class1, so it is no surprise that the test is failing. - //TODO PDOM doesn't have information on constructor + // TODO PDOM doesn't have information on constructor IBinding[] bindings = pdom.findBindings(Pattern.compile("Class1"), false, IndexFilter.ALL, npm()); assertEquals(2, bindings.length); assertTrue(bindings[0] instanceof ICPPClassType); assertTrue(bindings[1] instanceof ICPPMethod); - + IName[] decls = pdom.findNames(bindings[1], IIndex.FIND_DECLARATIONS_DEFINITIONS); assertEquals(2, decls.length); IASTFileLocation loc = decls[0].getFileLocation(); - assertEquals(offset("constructor.cpp","Class1(int num);"), loc.getNodeOffset()); //character offset - + assertEquals(offset("constructor.cpp","Class1(int num);"), loc.getNodeOffset()); //character offset + loc = decls[1].getFileLocation(); assertEquals(offset("constructor.cpp","Class1::Class1") + 8, loc.getNodeOffset()); //character offset - + /* Member initialization */ bindings = pdom.findBindings(Pattern.compile("number"), false, IndexFilter.ALL, npm()); assertEquals(1, bindings.length); - + IName[] refs = pdom.findNames(bindings[0], IIndex.FIND_REFERENCES); assertEquals(1, refs.length); loc = refs[0].getFileLocation(); - assertEquals(offset("constructor.cpp","number(num)"), loc.getNodeOffset()); //character offset - + assertEquals(offset("constructor.cpp", "number(num)"), loc.getNodeOffset()); //character offset + assertEquals(bindings[0], ((PDOMName)refs[0]).getBinding()); } - + public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentA() throws Exception { IndexFilter JUST_CONSTRUCTORS= new IndexFilter() { @Override @@ -185,7 +183,7 @@ public class ClassTests extends PDOMTestBase { // expecting C(int) and C(const C &) assertEquals(2, bindings.length); } - + public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentB() throws Exception { IndexFilter JUST_CONSTRUCTORS= new IndexFilter() { @Override @@ -197,40 +195,40 @@ public class ClassTests extends PDOMTestBase { // expecting just D(D &) assertEquals(1, bindings.length); } - + public void testClassScope_bug185408() throws Exception { char[][] name= {"B".toCharArray(), "bf".toCharArray()}; IBinding[] bindings= pdom.findBindings(name, IndexFilter.ALL, npm()); assertEquals(1, bindings.length); IScope classScope= bindings[0].getScope(); - + assertTrue(classScope instanceof ICPPClassScope); - bindings= classScope.find("bf"); + bindings= classScope.find("bf", null); ICPPMethod method= extractSingleMethod(bindings); - assertEquals(method.getQualifiedName()[0], "B"); + assertEquals("B", method.getQualifiedName()[0]); - bindings= classScope.find("f"); + bindings= classScope.find("f", null); method= extractSingleMethod(bindings); - assertEquals(method.getQualifiedName()[0], "A"); + assertEquals("A", method.getQualifiedName()[0]); - bindings= classScope.find("B"); + bindings= classScope.find("B", null); ICPPClassType classType= extractSingleClass(bindings); - assertEquals(classType.getQualifiedName()[0], "B"); + assertEquals("B", classType.getQualifiedName()[0]); - bindings= classScope.find("A"); + bindings= classScope.find("A", null); classType= extractSingleClass(bindings); - assertEquals(classType.getQualifiedName()[0], "A"); + assertEquals("A", classType.getQualifiedName()[0]); } private ICPPMethod extractSingleMethod(IBinding[] bindings) { assertEquals(1, bindings.length); - assertTrue(bindings[0] instanceof ICPPMethod); + assertInstance(bindings[0], ICPPMethod.class); return (ICPPMethod) bindings[0]; } - + private ICPPClassType extractSingleClass(IBinding[] bindings) { assertEquals(1, bindings.length); - assertTrue(bindings[0] instanceof ICPPClassType); + assertInstance(bindings[0], ICPPClassType.class); return (ICPPClassType) bindings[0]; } diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 5ad9605c088..11216c0d519 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true -Bundle-Version: 5.10.0.qualifier +Bundle-Version: 5.11.0.qualifier Bundle-Activator: org.eclipse.cdt.core.CCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java index efe962f9faa..6694bf15536 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java @@ -9,6 +9,7 @@ * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -19,7 +20,7 @@ import org.eclipse.cdt.core.index.IIndexFileSet; /** * Scopes can be used to look-up names. With the exception of template-scopes the scopes * can be arranged in a hierarchy. - * + * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ @@ -31,46 +32,53 @@ public interface IScope { EScopeKind getKind(); /** - * Returns the IName for this scope, may be {@code null} + * Returns the IName for this scope, may be {@code null}. + * * @return The name of this scope. */ public IName getScopeName(); - + /** * Returns the first enclosing non-template scope, or {@code null} if this is the global scope. */ public IScope getParent() throws DOMException; /** - * This is the general lookup entry point. It returns the list of valid bindings for a given - * name. The lookup proceeds as an unqualified lookup. Constructors are not considered during - * this lookup and won't be returned. No attempt is made to resolve potential ambiguities or + * This is the general lookup entry point. It returns the list of valid bindings for a given name in this + * scope and its enclosing scopes. The name is treated as unqualified. Constructors are not considered + * during this lookup and won't be returned. No attempt is made to resolve potential ambiguities or * perform access checking. - * + * * @param name the name of the bindings - * @return An array of bindings. + * @param tu the translation unit determining the context for the lookup + * @return An array of bindings + * @since 5.11 */ - public IBinding[] find(String name); - + public IBinding[] find(String name, IASTTranslationUnit tu); + /** - * Returns the binding in this scope that the given name would resolve to. Could - * return null if there is no matching binding in this scope, if the binding has not - * yet been cached in this scope, or if resolve is {@code false} and the appropriate binding - * has not yet been resolved. - * + * @deprecated Use {{@link #find(String, IASTTranslationUnit)} + */ + @Deprecated + public IBinding[] find(String name); + + /** + * Returns the binding in this scope that the given name would resolve to. Could return {@code null} + * if there is no matching binding in this scope, if the binding has not yet been cached in this scope, + * or if resolve is {@code false} and the appropriate binding has not yet been resolved. + * * @param name the name of the binding * @param resolve whether or not to resolve the matching binding if it has not been so already * @return the binding in this scope that matches the name, or {@code null} */ public IBinding getBinding(IASTName name, boolean resolve); - + /** - * Returns the binding in this scope that the given name would resolve to. Could - * return null if there is no matching binding in this scope, if the binding has not - * yet been cached in this scope, or if resolve is {@code false} and the appropriate binding - * has not yet been resolved. Accepts file local bindings from the index for the files - * in the given set, only. - * + * Returns the binding in this scope that the given name would resolve to. Could return {@code null} + * if there is no matching binding in this scope, if the binding has not yet been cached in this scope, + * or if resolve is {@code false} and the appropriate binding has not yet been resolved. Accepts file + * local bindings from the index for the files in the given set, only. + * * @param name the name of the binding * @param resolve whether or not to resolve the matching binding if it has not been so already * @param acceptLocalBindings a set of files for which to accept local bindings @@ -88,9 +96,9 @@ public interface IScope { * @deprecated Use {@link #getBindings(ScopeLookupData)} instead */ @Deprecated - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings); + public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, + IIndexFileSet acceptLocalBindings); - /** * @since 5.5 * @noextend This class is not intended to be subclassed by clients. @@ -103,7 +111,7 @@ public interface IScope { private boolean fResolve= true; private boolean fPrefixLookup; private boolean fIgnorePointOfDeclaration; - + public ScopeLookupData(IASTName name, boolean resolve, boolean prefixLookup) { if (name == null) throw new IllegalArgumentException(); @@ -129,6 +137,17 @@ public interface IScope { } } + /** + * @since 5.11 + */ + public ScopeLookupData(char[] name, IASTTranslationUnit tu) { + fLookupPoint= null; + fLookupPointIsName= false; + fLookupKey= name; + fIgnorePointOfDeclaration= true; + fTu= tu; + } + public final void setPrefixLookup(boolean prefixLookup) { fPrefixLookup = prefixLookup; } @@ -183,11 +202,10 @@ public interface IScope { } /** - * Returns the bindings in this scope that the given name or prefix could resolve to. Could - * return null if there is no matching bindings in this scope, if the bindings have not - * yet been cached in this scope, or if resolve == false and the appropriate bindings - * have not yet been resolved. - * + * Returns the bindings in this scope that the given name or prefix could resolve to. Could return + * {@code null} if there is no matching bindings in this scope, if the bindings have not yet been cached + * in this scope, or if resolve is {@code false} and the appropriate bindings have not yet been resolved. + * * @return the bindings in this scope that match the name or prefix, or {@code null} * @since 5.5 */ 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 dd848250896..bdf087a23c8 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 @@ -174,6 +174,11 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I throw new DOMException(this); } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return IBinding.EMPTY_BINDING_ARRAY; + } + @Override public IBinding[] find(String name) { return IBinding.EMPTY_BINDING_ARRAY; 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 de23fe19352..d57bd3d431b 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 @@ -164,6 +164,11 @@ public class CScope implements ICScope, IASTInternalScope { } } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return find(name); + } + @Override public IBinding[] find(String name) { return CVisitor.findBindings(this, name); 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 33ee56d405d..55165f874a3 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 @@ -685,7 +685,7 @@ public class CVisitor extends ASTQueries { static IType getPtrDiffType(IASTBinaryExpression expr) { IScope scope = getContainingScope(expr); - IBinding[] bs = scope.find(PTRDIFF_T); + IBinding[] bs = scope.find(PTRDIFF_T, expr.getTranslationUnit()); for (IBinding b : bs) { if (b instanceof IType) { if (!(b instanceof ICInternalBinding) || @@ -701,7 +701,7 @@ public class CVisitor extends ASTQueries { static IType get_SIZE_T(IASTExpression expr) { IASTTranslationUnit tu= expr.getTranslationUnit(); if (tu != null) { - IBinding[] bs = tu.getScope().find(SIZE_T); + IBinding[] bs = tu.getScope().find(SIZE_T, expr.getTranslationUnit()); for (IBinding b : bs) { if (b instanceof IType) { if (!(b instanceof ICInternalBinding) || @@ -1650,7 +1650,7 @@ public class CVisitor extends ASTQueries { } // label names - List b3 = new ArrayList(); + List b3 = new ArrayList<>(); do { char[] n = name.toCharArray(); if (scope instanceof ICFunctionScope) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index 6015a27bde8..f780fc60c6c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -337,6 +338,11 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat return getOriginalClassType().getScope(); } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return find(name); + } + @Override public IBinding[] find(String name) { return CPPSemantics.findBindings(this, name, false); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index 432cfadf841..b966aef4d38 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; @@ -429,6 +430,11 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return find(name); + } + @Override public IBinding[] find(String name) { char[] n = name.toCharArray(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java index edd4261a84e..92cfafd2386 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; @@ -386,7 +387,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP } private IBinding[] getPrefixBindings(char[] name) { - List result= new ArrayList(); + List result= new ArrayList<>(); IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(name); for (ICPPMethod m : getMethods()) { if (!(m instanceof ICPPConstructor)) { @@ -398,6 +399,11 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP return result.toArray(new IBinding[result.size()]); } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return find(name); + } + @Override public IBinding[] find(String name) { return getBindings(name.toCharArray()); @@ -427,8 +433,8 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP @Override public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings) { - return getBindings(new ScopeLookupData(name, resolve, prefixLookup)); - } + return getBindings(new ScopeLookupData(name, resolve, prefixLookup)); + } @Override public IBinding[] getBindings(ScopeLookupData lookup) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index e60854cbd20..b47c7b25ff4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -336,6 +336,11 @@ abstract public class CPPScope implements ICPPASTInternalScope { } } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return find(name); + } + @Override public IBinding[] find(String name) { return CPPSemantics.findBindings(this, name, false); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java index e85e81c62d1..bfceb587dc0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java @@ -29,6 +29,7 @@ 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.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; @@ -97,6 +98,11 @@ public class CPPScopeMapper { } @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return fScope.find(name, tu); + } + + @Override @Deprecated public IBinding[] find(String name) { return fScope.find(name); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java index 155bb20913a..b4e8f00daa7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -78,6 +79,11 @@ public class CPPUnknownTypeScope implements ICPPInternalUnknownScope { return null; } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return IBinding.EMPTY_BINDING_ARRAY; + } + @Override public IBinding[] find(String name) { return IBinding.EMPTY_BINDING_ARRAY; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 116dd139e16..cfae877ad88 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -229,7 +229,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.TypeS import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost.Rank; -import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; @@ -734,7 +733,8 @@ public class CPPSemantics { if (parent != null) parent= parent.getParent(); // the loop if (parent instanceof ICPPASTRangeBasedForStatement) { - IBinding[] std= parent.getTranslationUnit().getScope().find(CPPVisitor.STD); + IASTTranslationUnit tu = parent.getTranslationUnit(); + IBinding[] std= tu.getScope().find(CPPVisitor.STD, tu); for (IBinding binding : std) { if (binding instanceof ICPPNamespace) { namespaces.add(((ICPPNamespace) binding).getNamespaceScope()); @@ -815,9 +815,7 @@ public class CPPSemantics { if (binding == null) return null; IScope scope = binding.getScope(); - if (tu != null) { - scope= tu.mapToASTScope(scope); - } + scope = SemanticUtil.mapToAST(scope, tu); while (scope != null && !(scope instanceof ICPPNamespaceScope)) { scope = getParentScope(scope, tu); } @@ -997,10 +995,7 @@ public class CPPSemantics { } } ICPPScope scope= useTemplScope ? nextTmplScope : nextScope; - CPPASTTranslationUnit tu = data.getTranslationUnit(); - if (tu != null) { - scope= (ICPPScope) tu.mapToASTScope((scope)); - } + scope = (ICPPScope) SemanticUtil.mapToAST(scope, data.getTranslationUnit()); if (!data.usingDirectivesOnly && !(data.ignoreMembers && scope instanceof ICPPClassScope)) { mergeResults(data, getBindingsFromScope(scope, data), true); @@ -1367,16 +1362,14 @@ public class CPPSemantics { return ((ICPPASTTemplateDeclaration) parent).getScope(); } - static ICPPScope getParentScope(IScope scope, ICPPASTTranslationUnit unit) throws DOMException { + static ICPPScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException { IScope parentScope= scope.getParent(); // The index cannot return the translation unit as parent scope. - if (unit instanceof CPPASTTranslationUnit) { - if (parentScope == null - && (scope instanceof IIndexScope || scope instanceof ICPPClassSpecializationScope)) { - parentScope = unit.getScope(); - } else { - parentScope = ((CPPASTTranslationUnit) unit).mapToASTScope(parentScope); - } + if (parentScope == null && scope instanceof ICPPClassSpecializationScope + && unit instanceof CPPASTTranslationUnit) { + parentScope = unit.getScope(); + } else { + parentScope = SemanticUtil.mapToAST(parentScope, unit); } return (ICPPScope) parentScope; } @@ -3586,6 +3579,11 @@ public class CPPSemantics { return type instanceof ICPPClassType || type instanceof IEnumeration || type instanceof ICPPUnknownType; } + public static IBinding[] findBindingsInScope(IScope scope, String name, IASTTranslationUnit tu) { + LookupData data = new LookupData(name.toCharArray(), null, tu); + return standardLookup(data, scope); + } + public static IBinding[] findBindings(IScope scope, String name, boolean qualified) { return findBindings(scope, name.toCharArray(), qualified, null); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 4f3c31e7d5e..999c4d484cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -220,7 +220,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; -import org.eclipse.cdt.internal.core.index.IIndexScope; /** * Collection of methods to extract information from a C++ translation unit. @@ -542,15 +541,15 @@ public class CPPVisitor extends ASTQueries { } if (mustBeSimple) { - // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains - // the declaration + // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype + // scope that contains the declaration. while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) { - scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit()); + scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit()); } } if (scope instanceof ICPPClassScope && isFriend && !qualified) { while (scope instanceof ICPPClassScope) { - scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit()); + scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit()); } } if (scope != null) { @@ -820,7 +819,7 @@ public class CPPVisitor extends ASTQueries { if (isFriendDecl) { try { while (scope.getKind() == EScopeKind.eClassType) { - scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit()); + scope = CPPSemantics.getParentScope(scope, name.getTranslationUnit()); } } catch (DOMException e1) { } @@ -2369,7 +2368,7 @@ public class CPPVisitor extends ASTQueries { if (node == null) return null; ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit(); - IBinding[] std= ast.getScope().find(STD); + IBinding[] std= ast.getScope().find(STD, ast); for (IBinding binding : std) { if (binding instanceof ICPPNamespace) { final ICPPNamespaceScope scope = ((ICPPNamespace) binding).getNamespaceScope(); @@ -2499,16 +2498,6 @@ public class CPPVisitor extends ASTQueries { return ns; } - private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException { - IScope parentScope= scope.getParent(); - // Replace the global scope from index with the global scope of the translation unit. - if ((parentScope == null || parentScope.getKind() == EScopeKind.eGlobal) && - scope instanceof IIndexScope && unit != null) { - parentScope= unit.getScope(); - } - return parentScope; - } - public static boolean isExternC(IASTNode node) { while (node != null) { node= node.getParent(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java index 694dab78592..ef38bc843c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java @@ -40,6 +40,7 @@ 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.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope.ScopeLookupData; @@ -135,6 +136,11 @@ public class LookupData extends ScopeLookupData { fTemplateArguments= templateArgs; } + public LookupData(char[] name, ICPPTemplateArgument[] templateArgs, IASTTranslationUnit tu) { + super(name, tu); + fTemplateArguments= templateArgs; + } + @Override public CPPASTTranslationUnit getTranslationUnit() { return (CPPASTTranslationUnit) super.getTranslationUnit(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index af32edb887f..55b7bdcfb1a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -27,7 +27,9 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier import java.util.HashSet; import java.util.Set; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializer; @@ -81,6 +83,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; +import org.eclipse.cdt.internal.core.index.IIndexScope; /** * Collection of static methods operating on C++ bindings. @@ -540,10 +543,15 @@ public class SemanticUtil { } public static IScope mapToAST(IScope scope, IASTNode point) { - if (point != null) { - IASTTranslationUnit ast = point.getTranslationUnit(); - if (ast instanceof ASTTranslationUnit) { - return ((ASTTranslationUnit) ast).mapToASTScope(scope); + if (scope instanceof IIndexScope) { + if (point != null) { + IASTTranslationUnit ast = point.getTranslationUnit(); + if (ast instanceof ASTTranslationUnit) { + return ((ASTTranslationUnit) ast).mapToASTScope(scope); + } + } else if (scope.getKind() == EScopeKind.eGlobal) { + CCorePlugin.log(new Exception( + "The point argument was not provided. Returning the global index scope.")); //$NON-NLS-1$ } } return scope; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCCompositeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCCompositeScope.java index d3adefda237..34d93718a9d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCCompositeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCCompositeScope.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.index.composite.c; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +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.c.ICCompositeTypeScope; @@ -55,6 +56,12 @@ class CompositeCCompositeScope extends CompositeScope implements ICCompositeType } @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + IBinding[] preresult = ((ICompositeType) rbinding).getCompositeScope().find(name, tu); + return processUncertainBindings(preresult); + } + + @Override @Deprecated public IBinding[] find(String name) { IBinding[] preresult = ((ICompositeType) rbinding).getCompositeScope().find(name); return processUncertainBindings(preresult); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java index 6da2ec831e2..f44014ac0c5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -77,6 +78,12 @@ class CompositeCPPClassScope extends CompositeScope implements ICPPClassScope { } @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + IBinding[] preresult = ((ICPPClassType) rbinding).getCompositeScope().find(name, tu); + return processUncertainBindings(preresult); + } + + @Override @Deprecated public IBinding[] find(String name) { IBinding[] preresult = ((ICPPClassType) rbinding).getCompositeScope().find(name); return processUncertainBindings(preresult); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index b00a7b572dd..5bf953fd5f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; @@ -81,6 +82,12 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme } @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + createDelegate(); + return fDelegate.find(name, tu); + } + + @Override @Deprecated public IBinding[] find(String name) { createDelegate(); return fDelegate.find(name); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumScope.java index 929dfdc0d80..9886727a9c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumScope.java @@ -6,12 +6,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; @@ -44,16 +45,22 @@ class CompositeCPPEnumScope extends CompositeScope implements ICPPEnumScope { @Override public IBinding[] getBindings(ScopeLookupData lookup) { - IBinding[] bindings = ((ICPPEnumeration)rbinding).asScope().getBindings(lookup); + IBinding[] bindings = ((ICPPEnumeration) rbinding).asScope().getBindings(lookup); return processUncertainBindings(bindings); } - + @Override - public IBinding[] find(String name) { - IBinding[] preresult = ((ICPPEnumeration)rbinding).asScope().find(name); + public IBinding[] find(String name, IASTTranslationUnit tu) { + IBinding[] preresult = ((ICPPEnumeration) rbinding).asScope().find(name, tu); return processUncertainBindings(preresult); } - + + @Override @Deprecated + public IBinding[] find(String name) { + IBinding[] preresult = ((ICPPEnumeration) rbinding).asScope().find(name); + return processUncertainBindings(preresult); + } + @Override public IIndexBinding getScopeBinding() { return cf.getCompositeBinding(rbinding); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java index 693a0ea5024..9b4a5e44ddd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; @@ -74,6 +75,17 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace } @Override + final public IBinding[] find(String name, IASTTranslationUnit tu) { + IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][]; + for (int i= 0; i < namespaces.length; i++) { + IBinding[] raw = namespaces[i].getNamespaceScope().find(name, tu); + preresult[i] = new IIndexFragmentBinding[raw.length]; + System.arraycopy(raw, 0, preresult[i], 0, raw.length); + } + return cf.getCompositeBindings(preresult); + } + + @Override @Deprecated final public IBinding[] find(String name) { IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][]; for (int i= 0; i < namespaces.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMGlobalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMGlobalScope.java index 0e881952ed4..218835e78dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMGlobalScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMGlobalScope.java @@ -10,8 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; @@ -27,35 +29,47 @@ public abstract class PDOMGlobalScope implements IIndexScope { return EScopeKind.eGlobal; } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + logInvalidCallError(); + return IBinding.EMPTY_BINDING_ARRAY; + } + @Override public IBinding[] find(String name) { - throw new UnsupportedOperationException(); + logInvalidCallError(); + return IBinding.EMPTY_BINDING_ARRAY; } @Override public IBinding getBinding(IASTName name, boolean resolve) { - throw new UnsupportedOperationException(); + logInvalidCallError(); + return null; } @Override public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) { - throw new UnsupportedOperationException(); + logInvalidCallError(); + return null; } @Override public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) { - throw new UnsupportedOperationException(); + logInvalidCallError(); + return IBinding.EMPTY_BINDING_ARRAY; } @Override public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings) { - throw new UnsupportedOperationException(); + logInvalidCallError(); + return IBinding.EMPTY_BINDING_ARRAY; } @Override public IBinding[] getBindings(ScopeLookupData lookup) { - throw new UnsupportedOperationException(); + logInvalidCallError(); + return IBinding.EMPTY_BINDING_ARRAY; } @Override @@ -77,4 +91,9 @@ public abstract class PDOMGlobalScope implements IIndexScope { public String toString() { return ""; //$NON-NLS-1$ } + + private void logInvalidCallError() { + CCorePlugin.log(new UnsupportedOperationException( + "Global index scope has to be mapped to the global scope of a particular translation unit.")); //$NON-NLS-1$ + } } 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 c8f5c396ed0..551a29ca77d 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 @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +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; @@ -292,6 +293,11 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom } @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return getBindings(name.toCharArray()); + } + + @Override @Deprecated public IBinding[] find(String name) { return getBindings(name.toCharArray()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java index a83c8065748..50b071b9bf3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java @@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +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.cpp.ICPPASTConversionName; @@ -258,6 +259,11 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope { } @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return CPPSemantics.findBindingsInScope(this, name, tu); + } + + @Override @Deprecated public IBinding[] find(String name) { return CPPSemantics.findBindings(this, name, false); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java index 58c503d1365..43bad7797ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java @@ -11,10 +11,13 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.internal.core.dom.parser.cpp.AbstractCPPClassSpecializationScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.index.IIndexScope; /** @@ -43,4 +46,9 @@ public class PDOMCPPClassSpecializationScope extends AbstractCPPClassSpecializat public IIndexName getScopeName() { return null; } + + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return CPPSemantics.findBindingsInScope(this, name, tu); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumScope.java index ce4159f068c..4ba004e02f8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumScope.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope; @@ -105,6 +106,11 @@ class PDOMCPPEnumScope implements ICPPEnumScope, IIndexScope { } @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return CPPSemantics.findBindingsInScope(this, name, tu); + } + + @Override @Deprecated public IBinding[] find(String name) { return CPPSemantics.findBindings(this, name, false); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java index 8038384b8da..9e785d9d7ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; @@ -166,6 +167,11 @@ class PDOMCPPNamespace extends PDOMCPPBinding return ICPPUsingDirective.EMPTY_ARRAY; } + @Override + public IBinding[] find(String name, IASTTranslationUnit tu) { + return find(name); + } + @Override public IBinding[] find(String name) { try { diff --git a/core/org.eclipse.cdt.core/pom.xml b/core/org.eclipse.cdt.core/pom.xml index 431156976bc..44f0ce3f1fd 100644 --- a/core/org.eclipse.cdt.core/pom.xml +++ b/core/org.eclipse.cdt.core/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 5.10.0-SNAPSHOT + 5.11.0-SNAPSHOT org.eclipse.cdt.core eclipse-plugin diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTManager.java index f89437355a4..01d4b4d4fbc 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTManager.java @@ -691,10 +691,10 @@ public class ASTManager implements IDisposable { } } - public static IBinding[] findInScope(final IScope scope, String name, boolean removeGlobalsWhenClassScope) - throws DOMException { + public static IBinding[] findInScope(final IScope scope, String name, IASTTranslationUnit tu, + boolean removeGlobalsWhenClassScope) throws DOMException { IBinding[] result= null; - result = scope.find(name); + result = scope.find(name, tu); if (result == null || result.length == 0) { return result; } @@ -706,7 +706,7 @@ public class ASTManager implements IDisposable { for (int i = 0; i < result.length; i++) { IBinding binding = result[i]; IScope bscope= binding.getScope(); - if (! (bscope instanceof ICPPClassScope || bscope instanceof ICCompositeTypeScope)) { + if (!(bscope instanceof ICPPClassScope || bscope instanceof ICCompositeTypeScope)) { result[i]= null; } else { count++; @@ -1197,7 +1197,7 @@ public class ASTManager implements IDisposable { if (scope != null) { IBinding[] conflicting= null; try { - conflicting= findInScope(scope, fRenameTo, true); + conflicting= findInScope(scope, fRenameTo, name.getTranslationUnit(), true); } catch (Exception e) { CUIPlugin.log(e); } @@ -1445,7 +1445,7 @@ public class ASTManager implements IDisposable { try { oldBindingsScope = oldBinding.getScope(); if (oldBindingsScope != null) { - newBindingsAboverOrEqual = ASTManager.findInScope(oldBindingsScope, fRenameTo, false); + newBindingsAboverOrEqual = ASTManager.findInScope(oldBindingsScope, fRenameTo, null, false); } } catch (DOMException e) { handleDOMException(tu, e, status); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameClassProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameClassProcessor.java index 54e67bc39bb..32794bc80fd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameClassProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameClassProcessor.java @@ -96,10 +96,10 @@ public class CRenameClassProcessor extends CRenameTypeProcessor { if (ctors != null) { ArrayUtil.addAll(bindings, ctors); } - + IScope scope= ctype.getCompositeScope(); if (scope != null) { - IBinding[] dtors= scope.find("~" + argument.getName()); //$NON-NLS-1$ + IBinding[] dtors= scope.find("~" + argument.getName(), argument.getTranslationUnit()); //$NON-NLS-1$ if (dtors != null) { ArrayUtil.addAll(bindings, dtors); } 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 6a39a24edaa..a000639db23 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 @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.index.IIndexFileSet; @@ -25,9 +26,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; */ @SuppressWarnings({"restriction","unused"}) public class C99Scope implements IC99Scope, IASTInternalScope { - - - private IScope parent; private IASTNode physicalNode; private IName scopeName; @@ -72,9 +70,13 @@ public class C99Scope implements IC99Scope, IASTInternalScope { this.scopeName = scopeName; } - @Override - public IBinding[] find( String name) { + public IBinding[] find(String name, IASTTranslationUnit tu) { + throw new UnsupportedOperationException(); + } + + @Override @Deprecated + public IBinding[] find(String name) { throw new UnsupportedOperationException(); } @@ -87,9 +89,6 @@ public class C99Scope implements IC99Scope, IASTInternalScope { public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) { throw new UnsupportedOperationException(); } - - - @Override public void addBinding(IBinding binding) { @@ -110,9 +109,7 @@ public class C99Scope implements IC99Scope, IASTInternalScope { } @Override - public IBinding getBinding(IASTName name, boolean resolve, - IIndexFileSet acceptLocalBindings) { - // TODO Auto-generated method stub + public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) { return null; } @@ -123,15 +120,11 @@ public class C99Scope implements IC99Scope, IASTInternalScope { @Deprecated public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings) { - return getBindings(new ScopeLookupData(name, resolve, prefixLookup)); - } + return getBindings(new ScopeLookupData(name, resolve, prefixLookup)); + } @Override public IBinding[] getBindings(ScopeLookupData lookup) { - // TODO Auto-generated method stub - return null; + return IBinding.EMPTY_BINDING_ARRAY; } - - - }