diff --git a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF index 8513f21b665..1f11c3bd7f8 100644 --- a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF @@ -25,7 +25,8 @@ Require-Bundle: org.eclipse.core.resources, org.eclipse.core.runtime, org.eclipse.ui.ide, org.eclipse.ui, - org.eclipse.jface.text + org.eclipse.jface.text, + org.eclipse.core.filesystem Eclipse-LazyStart: true Bundle-Vendor: Eclipse.org Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java index 1bb67b43996..da5f0ed7fe2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software Systems and others. + * Copyright (c) 2007 Symbian 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 @@ -108,7 +108,7 @@ public class IndexCompositeTests extends BaseTestCase { // class A1 {}; // void foo(X::B2 c) {} // namespace X { class A2 {}; B2 b; C2 c; } - public void _testTripleLinear() throws Exception { + public void testTripleLinear() throws Exception { StringBuffer[] contents = getContentsForTest(3); List projects = new ArrayList(); @@ -215,7 +215,7 @@ public class IndexCompositeTests extends BaseTestCase { // void foo(X::B2 c) {} // namespace X { class A2 {}; } // B1 ab; - public void _testTripleUpwardV() throws Exception { + public void testTripleUpwardV() throws Exception { StringBuffer[] contents = getContentsForTest(3); List projects = new ArrayList(); @@ -304,7 +304,7 @@ public class IndexCompositeTests extends BaseTestCase { // class A1 {}; // void foo(A1 a, A1 b) {} // namespace X { class A2 {}; } - public void _testTripleDownwardV() throws Exception { + public void testTripleDownwardV() throws Exception { StringBuffer[] contents = getContentsForTest(3); List projects = new ArrayList(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java index e48afb3a530..c605eb0d13b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software Systems and others. + * Copyright (c) 2007 Symbian 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 @@ -17,12 +17,12 @@ import junit.framework.Test; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -74,8 +74,8 @@ public class FilesOnReindexTests extends PDOMTestBase { IBinding[] bs = index.findBindings(Pattern.compile("C"), true, new IndexFilter(), new NullProgressMonitor()); assertEquals(1, bs.length); - PDOMBinding binding = (PDOMBinding) bs[0]; - IIndexFile file2 = binding.getFirstDefinition().getFile(); + IIndexBinding binding = (IIndexBinding) bs[0]; + IIndexFile file2 = index.findDefinitions(binding)[0].getFile(); assertEquals(file.getLocationURI(), file2.getLocation().getURI()); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionBugs.java index c551dee718e..071917f9e36 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionBugs.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -7,15 +7,13 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; import junit.framework.TestSuite; -import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.core.runtime.Path; /** * For testing PDOM binding resolution @@ -26,11 +24,8 @@ public class IndexBindingResolutionBugs extends IndexBindingResolutionTestBase { return suite(IndexBindingResolutionBugs.class); } - protected void setUp() throws Exception { - cproject= CProjectHelper.createCCProject("ResolveBindingBugs", "bin", IPDOMManager.ID_NO_INDEXER); - header = new Path("header.h"); - references = new Path("references.cpp"); - super.setUp(); + public IndexBindingResolutionBugs() { + setStrategy(new SinglePDOMTestStrategy(true)); } // // header file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java index a5160441b6d..59507ee9400 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java @@ -30,15 +30,18 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.osgi.framework.Bundle; /** @@ -51,45 +54,27 @@ import org.osgi.framework.Bundle; * the PDOM purely from AST information (i.e. without a real binding from the DOM) */ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase { - - IIndex index; - ICProject cproject; - IPath header, references; - StringBuffer[] testData; - IASTTranslationUnit ast; - + private ITestStrategy strategy; + + public void setStrategy(ITestStrategy strategy) { + this.strategy = strategy; + } protected void setUp() throws Exception { - Bundle b = CTestPlugin.getDefault().getBundle(); - testData = TestSourceReader.getContentsForTest(b, "parser", getClass(), getName(), 2); - - IFile file = TestSourceReader.createFile(cproject.getProject(), header, testData[0].toString()); - CCoreInternals.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); - - IFile cppfile= TestSourceReader.createFile(cproject.getProject(), references, testData[1].toString()); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); - - index= CCorePlugin.getIndexManager().getIndex(cproject); - index.acquireReadLock(); - ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile); + strategy.setUp(); } protected void tearDown() throws Exception { - if (index != null) { - index.releaseReadLock(); - } - if (cproject != null) { - cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); - } - super.tearDown(); + strategy.tearDown(); } protected IBinding getBindingFromASTName(String section, int len) { // get the language from the language manager ILanguage language = null; + ICProject cproject = strategy.getCProject(); + IASTTranslationUnit ast = strategy.getAst(); try { - language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), cproject.getProject()); + language = LanguageManager.getInstance().getLanguageForFile(strategy.getAst().getFilePath(), cproject.getProject()); } catch (CoreException e) { fail("Unexpected exception while getting language for file."); } @@ -97,7 +82,8 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase { assertNotNull("No language for file " + ast.getFilePath().toString(), language); - IASTName[] names= language.getSelectedNames(ast, testData[1].indexOf(section), len); + IASTName[] names= language.getSelectedNames(ast, strategy.getTestData()[1].indexOf(section), len); + assertEquals("<>1 name found for \""+section+"\"", 1, names.length); IBinding binding = names[0].resolveBinding(); assertNotNull("No binding for "+names[0].getRawSignature(), binding); @@ -108,15 +94,17 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase { protected IBinding getProblemFromASTName(String section, int len) { // get the language from the language manager ILanguage language = null; + ICProject cproject = strategy.getCProject(); + IASTTranslationUnit ast = strategy.getAst(); try { language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), cproject.getProject()); } catch (CoreException e) { fail("Unexpected exception while getting language for file."); } - assertNotNull("No language for file " + ast.getFilePath().toString(), language); + assertNotNull("No language for file " + ast.getFilePath().toString(), language); - IASTName[] names= language.getSelectedNames(ast, testData[1].indexOf(section), len); + IASTName[] names= language.getSelectedNames(ast, strategy.getTestData()[1].indexOf(section), len); assertEquals("<>1 name found for \""+section+"\"", 1, names.length); IBinding binding = names[0].resolveBinding(); assertNotNull("No binding for "+names[0].getRawSignature(), binding); @@ -124,29 +112,33 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase { return names[0].resolveBinding(); } - protected void assertQNEquals(String expectedQn, IBinding b12) throws DOMException { - assertTrue(b12 instanceof ICPPBinding); - assertEquals(expectedQn, CPPVisitor.renderQualifiedName(((ICPPBinding)b12).getQualifiedName())); + protected static void assertQNEquals(String expectedQn, IBinding b12) { + try { + assertTrue(b12 instanceof ICPPBinding); + assertEquals(expectedQn, CPPVisitor.renderQualifiedName(((ICPPBinding)b12).getQualifiedName())); + } catch(DOMException de) { + fail(de.getMessage()); + } } - + protected IType getVariableType(IBinding binding) throws DOMException { assertTrue(binding instanceof IVariable); return ((IVariable)binding).getType(); } - + protected IType getPtrType(IBinding binding) throws DOMException { // assert binding is a variable IVariable v = (IVariable) binding; IPointerType ptr = (IPointerType) v.getType(); return ptr.getType(); } - + protected void assertParamType(int index, Class type, IType function) throws DOMException { // assert function is IFunctionType IFunctionType ft = (IFunctionType) function; assertTrue(type.isInstance((ft.getParameterTypes()[index]))); } - + protected void assertCompositeTypeParam(int index, int compositeTypeKey, IType function, String qn) throws DOMException { // assert function is IFunctionType IFunctionType ft = (IFunctionType) function; @@ -154,8 +146,151 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase { assertEquals(compositeTypeKey, ((ICPPClassType)ft.getParameterTypes()[index]).getKey()); assertEquals(qn, CPPVisitor.renderQualifiedName(((ICPPClassType)ft.getParameterTypes()[index]).getQualifiedName())); } - + protected String readTaggedComment(final String tag) throws IOException { - return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag); - } -} + return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag); + } + + protected IIndex getIndex() { + return strategy.getIndex(); + } + + interface ITestStrategy { + IIndex getIndex(); + void setUp() throws Exception; + void tearDown() throws Exception; + public IASTTranslationUnit getAst(); + public StringBuffer[] getTestData(); + public ICProject getCProject(); + } + + class SinglePDOMTestStrategy implements ITestStrategy { + private IIndex index; + private ICProject cproject; + private StringBuffer[] testData; + private IASTTranslationUnit ast; + private boolean cpp; + + public SinglePDOMTestStrategy(boolean cpp) { + this.cpp = cpp; + } + + public ICProject getCProject() { + return cproject; + } + + public StringBuffer[] getTestData() { + return testData; + } + + public IASTTranslationUnit getAst() { + return ast; + } + + public void setUp() throws Exception { + cproject = cpp ? CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) + : CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + Bundle b = CTestPlugin.getDefault().getBundle(); + testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); + + IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), testData[0].toString()); + CCoreInternals.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + + IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString()); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + + index= CCorePlugin.getIndexManager().getIndex(cproject); + + index.acquireReadLock(); + ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile); + } + + public void tearDown() throws Exception { + if(index != null) { + index.releaseReadLock(); + } + if (cproject != null) { + cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); + } + } + + public IIndex getIndex() { + return index; + } + } + + class ReferencedProject implements ITestStrategy { + private IIndex index; + private ICProject cproject, referenced; + private StringBuffer[] testData; + private IASTTranslationUnit ast; + private boolean cpp; + + public ReferencedProject(boolean cpp) { + this.cpp = cpp; + } + + public ICProject getCProject() { + return cproject; + } + + public void tearDown() throws Exception { + if(index != null) { + index.releaseReadLock(); + } + if (cproject != null) { + cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); + } + if (referenced != null) { + referenced.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); + } + } + + public void setUp() throws Exception { + cproject= cpp ? CProjectHelper.createCCProject("OnlineContent", "bin", IPDOMManager.ID_NO_INDEXER) + : CProjectHelper.createCProject("OnlineContent", "bin", IPDOMManager.ID_NO_INDEXER); + Bundle b= CTestPlugin.getDefault().getBundle(); + testData= TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); + referenced = createReferencedContent(); + + IFile references= TestSourceReader.createFile(cproject.getProject(), new Path("refs.c" + (cpp ? "pp" : "")), testData[1].toString()); + + IProject[] refs = new IProject[] {referenced.getProject()}; + IProjectDescription pd = cproject.getProject().getDescription(); + pd.setReferencedProjects(refs); + cproject.getProject().setDescription(pd, new NullProgressMonitor()); + + CCoreInternals.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + + index= CCorePlugin.getIndexManager().getIndex(cproject); + index.acquireReadLock(); + ast= TestSourceReader.createIndexBasedAST(index, cproject, references); + } + + protected ICProject createReferencedContent() throws CoreException { + ICProject referenced = cpp ? CProjectHelper.createCCProject("ReferencedContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) + : CProjectHelper.createCProject("ReferencedContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + String content = testData[0].toString(); + IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), content); + + CCoreInternals.getPDOMManager().setIndexerId(referenced, IPDOMManager.ID_FAST_INDEXER); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + + return referenced; + } + + public IASTTranslationUnit getAst() { + return ast; + } + + public IIndex getIndex() { + return index; + } + + public StringBuffer[] getTestData() { + return testData; + } + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCBindingResolutionTest.java index 320870d9305..8b8c358210c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCBindingResolutionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software Systems and others. + * Copyright (c) 2007 Symbian 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 @@ -14,12 +14,9 @@ import java.io.IOException; import junit.framework.TestSuite; -import org.eclipse.cdt.core.dom.IPDOMManager; 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.testplugin.CProjectHelper; -import org.eclipse.core.runtime.Path; /** * For testing PDOM binding C language resolution @@ -31,15 +28,20 @@ import org.eclipse.core.runtime.Path; */ public class IndexCBindingResolutionTest extends IndexBindingResolutionTestBase { - public static TestSuite suite() { - return suite(IndexCBindingResolutionTest.class); + public static class SingleProject extends IndexCBindingResolutionTest { + public SingleProject() {setStrategy(new SinglePDOMTestStrategy(false));} } - - protected void setUp() throws Exception { - cproject= CProjectHelper.createCProject("ResolveBindingTestsC", "bin", IPDOMManager.ID_NO_INDEXER); - header = new Path("header.h"); - references = new Path("references.c"); - super.setUp(); + public static class ProjectWithDepProj extends IndexCBindingResolutionTest { + public ProjectWithDepProj() {setStrategy(new ReferencedProject(false));} + } + + public static void addTests(TestSuite suite) { + suite.addTest(suite(SingleProject.class)); + suite.addTest(suite(ProjectWithDepProj.class)); + } + + public IndexCBindingResolutionTest() { + setStrategy(new SinglePDOMTestStrategy(false)); } // // header file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java index 98a6ac1c427..84a05c8f7af 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software Systems and others. + * Copyright (c) 2007 Symbian 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 @@ -11,20 +11,30 @@ package org.eclipse.cdt.internal.pdom.tests; import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import junit.framework.TestSuite; -import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.DOMException; 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.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IPointerType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; /** * For testing PDOM binding CPP language resolution @@ -34,76 +44,76 @@ import org.eclipse.core.runtime.Path; * additionally check that the binding obtained has characteristics as * expected (type,name,etc..) */ -public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase { +public abstract class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase { - public static TestSuite suite() { - return suite(IndexCPPBindingResolutionTest.class); + public static class SingleProject extends IndexCPPBindingResolutionTest { + public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));} + } + public static class ProjectWithDepProj extends IndexCPPBindingResolutionTest { + public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));} } - protected void setUp() throws Exception { - cproject= CProjectHelper.createCCProject("ResolveBindingTestsCPP", "bin", IPDOMManager.ID_NO_INDEXER); - header = new Path("header.h"); - references = new Path("references.cpp"); - super.setUp(); - } - - // // header file - // class C { - // public: - // int field; - // struct CS { long* l; C *method(CS **); }; - // CS cs; - // CS **cspp; - // long * CS::* ouch; - // long * CS::* autsch; - // C * CS::* method(CS **); - // }; - - // // referencing file - // #include "header.h" - // void references() { - // C *cp = new C(); - // long l = 5, *lp; - // lp = &l; - // cp->cs.*cp->ouch = lp = cp->cs.*cp->autsch; - // &(cp->cs)->*cp->autsch = lp = &(cp->cs)->*cp->ouch; - // cp->cs.*method(cp->cspp);/*1*/ &(cp->cs)->*method(cp->cspp);/*2*/ - // } - public void testPointerToMemberFields() throws IOException { - IBinding b0 = getBindingFromASTName("cs.*cp->o", 2); - IBinding b1 = getBindingFromASTName("ouch = lp", 4); - IBinding b2 = getBindingFromASTName("autsch;", 6); - IBinding b3 = getBindingFromASTName("cs)->*cp->a", 2); - IBinding b4 = getBindingFromASTName("autsch = lp", 6); - IBinding b5 = getBindingFromASTName("ouch;", 4); + public static void addTests(TestSuite suite) { + suite.addTest(suite(SingleProject.class)); + suite.addTest(suite(ProjectWithDepProj.class)); } // // header file + // class Base {public: int field; void foo() {}}; + // class C : public Base { + // public: + // struct CS { long* l; C *method(CS **); }; + // CS cs; + // CS **cspp; + // long * CS::* ouch; + // long * CS::* autsch; + // C* (CS::*method)(CS **); + // }; - // class C { - // public: - // int field; - // struct CS { long* l; C *method(CS **); }; - // CS cs; - // CS **cspp; - // long * CS::* ouch; - // long * CS::* autsch; - // C * CS::* method(CS **); - // }; // // referencing file - // #include "header.h" + // #include "referenced.h" // void references() { - // C *cp = new C(); - // long l = 5, *lp; - // lp = &l; - // cp->cs.*cp->ouch = lp = cp->cs.*cp->autsch; - // &(cp->cs)->*cp->autsch = lp = &(cp->cs)->*cp->ouch; - // cp->cs.*method(cp->cspp);/*1*/ &(cp->cs)->*method(cp->cspp);/*2*/ + // C *cp = new C(); /*b0, b1*/ + // long l = 5, *lp; + // lp = &l; + // cp->cs.*cp->ouch = lp = cp->cs.*cp->autsch; /*b2, b3, b4*/ + // &(cp->cs)->*cp->autsch = lp = &(cp->cs)->*cp->ouch; + // (cp->cs).method(cp->cspp);/*1*/ (&(cp->cs))->method(cp->cspp);/*2*/ + // ((cp->cs).*(cp->method))(cp->cspp);/*3*/ + // ((&(cp->cs))->*(cp->method))(cp->cspp);/*4*/ // } - public void _testPointerToMemberFields_2() throws IOException { - // also fails without using the index (the header is empty) - IBinding b6 = getBindingFromASTName("method(cp->cspp);/*1*/", 6); - IBinding b7 = getBindingFromASTName("method(cp->cspp);/*2*/", 6); + public void testPointerToMemberFields() throws IOException, DOMException { + IBinding b0 = getBindingFromASTName("C *cp", 1); + assertClassType((ICPPClassType)b0, "C", ICPPClassType.k_class, 1, 6, 5, 9, 0, 1, 0, 2, 1); + + IBinding b1 = getBindingFromASTName("cp = new C()", 2); + assertVariable(b1, "cp", IPointerType.class, null); + IPointerType b1type = (IPointerType) ((ICPPVariable)b1).getType(); + assertClassType(b1type.getType(), "C", ICPPClassType.k_class, 1, 6, 5, 9, 0, 1, 0, 2, 1); + + IBinding b2 = getBindingFromASTName("cs.*cp->o", 2); + ICPPField field0 = (ICPPField) b2; + assertTrue(field0.getType() instanceof ICPPClassType); + + IBinding b3 = getBindingFromASTName("ouch = lp", 4); + assertField(b3, "C::ouch", ICPPPointerToMemberType.class, null); + assertPTM(((ICPPField)b3).getType(), "C::CS", null); + + IBinding b4 = getBindingFromASTName("autsch;", 6); + assertField(b4, "C::autsch", ICPPPointerToMemberType.class, null); + assertPTM(((ICPPField)b4).getType(), "C::CS", null); + + IBinding b5 = getBindingFromASTName("cs)->*cp->a", 2); + assertField(b5, "C::cs", ICPPClassType.class, "C::CS"); + assertClassType(((ICPPField)b5).getType(), "C::CS", ICompositeType.k_struct, 0, 1, 1, 5, 1, 1, 0, 2, 0); + + IBinding b6 = getBindingFromASTName("autsch = lp", 6); + assertField(b4, "C::autsch", ICPPPointerToMemberType.class, null); + assertPTM(((ICPPField)b4).getType(), "C::CS", null); + + IBinding b7 = getBindingFromASTName("ouch;", 4); + assertField(b3, "C::ouch", ICPPPointerToMemberType.class, null); + assertPTM(((ICPPField)b3).getType(), "C::CS", null); } // // header file @@ -112,6 +122,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // namespace ns {} // typedef int Int; typedef int *IntPtr; // void func(int*); void func(int); + // // referencing file // #include "header.h" // void references() { @@ -124,19 +135,66 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // } // class C2 : public C {}; /*base*/ // struct S2 : public S {}; /*base*/ - public void testSimpleGlobalBindings() throws IOException { - IBinding b0 = getBindingFromASTName("C c; ", 1); - IBinding b1 = getBindingFromASTName("c; ", 1); - IBinding b2 = getBindingFromASTName("S s;", 1); - IBinding b3 = getBindingFromASTName("s;", 1); - IBinding b4 = getBindingFromASTName("U u;", 1); - IBinding b5 = getBindingFromASTName("u; ", 1); - IBinding b6 = getBindingFromASTName("E e; ", 1); - IBinding b7 = getBindingFromASTName("e; ", 1); - IBinding b8 = getBindingFromASTName("var1 = 1;", 4); - IBinding b9 = getBindingFromASTName("var2 = c;", 4); - IBinding b10 = getBindingFromASTName("var3 = &s;", 4); - IBinding b11 = getBindingFromASTName("func(e);", 4); + public void testSimpleGlobalBindings() throws IOException, DOMException { + { + IBinding b0 = getBindingFromASTName("C c; ", 1); + assertClassTypeBinding(b0, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0); + + IBinding b1 = getBindingFromASTName("c; ", 1); + assertVariable(b1, "c", ICPPClassType.class, "C"); + ICPPClassType b1type = (ICPPClassType)((ICPPVariable)b1).getType(); + assertClassTypeBinding(b1type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0); + assertTrue(b1type.getScope() == null); + assertTrue(b1type.getCompositeScope() instanceof ICPPClassScope); + assertClassTypeBinding(((ICPPClassScope)b1type.getCompositeScope()).getClassType(), "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0); + } + { + IBinding b2 = getBindingFromASTName("S s;", 1); + assertClassTypeBinding(b2, "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0); + + IBinding b3 = getBindingFromASTName("s;", 1); + assertVariable(b3, "s", ICPPClassType.class, "S"); + ICPPClassType b3type = (ICPPClassType)((ICPPVariable)b3).getType(); + assertClassTypeBinding(b3type, "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0); + } + { + IBinding b4 = getBindingFromASTName("U u;", 1); + assertClassTypeBinding(b4, "U", ICompositeType.k_union, 0, 0, 0, 4, 0, 0, 0, 2, 0); + + IBinding b5 = getBindingFromASTName("u; ", 1); + assertVariable(b5, "u", ICPPClassType.class, "U"); + ICPPClassType b5type = (ICPPClassType)((ICPPVariable)b5).getType(); + assertClassTypeBinding(b5type, "U", ICompositeType.k_union, 0, 0, 0, 4, 0, 0, 0, 2, 0); + } + { + IBinding b6 = getBindingFromASTName("E e; ", 1); + assertEnumeration(b6, "E", new String[] {"ER1","ER2","ER3"}); + + IBinding b7 = getBindingFromASTName("e; ", 1); + assertVariable(b7, "e", IEnumeration.class, "E"); + IEnumeration b5type = (IEnumeration)((ICPPVariable)b7).getType(); + assertEnumeration(b5type, "E", new String[] {"ER1","ER2","ER3"}); + assertTrue(b5type.getScope() == null); + } + { + IBinding b8 = getBindingFromASTName("var1 = 1;", 4); + assertVariable(b8, "var1", ICPPBasicType.class, null); + } + { + IBinding b9 = getBindingFromASTName("var2 = c;", 4); + assertVariable(b9, "var2", ICPPClassType.class, "C"); + ICPPClassType b9type = (ICPPClassType)((ICPPVariable)b9).getType(); + assertClassTypeBinding(b9type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0); + } + { + IBinding b10 = getBindingFromASTName("var3 = &s;", 4); + assertVariable(b10, "var3", IPointerType.class, null); + IPointerType b10type = (IPointerType) ((ICPPVariable)b10).getType(); + assertClassTypeBinding((ICPPClassType) b10type.getType(), "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0); + } + { + IBinding b11 = getBindingFromASTName("func(e);", 4); + } IBinding b12 = getBindingFromASTName("func(var1);", 4); IBinding b13 = getBindingFromASTName("func(c);", 4); IBinding b14 = getBindingFromASTName("Int a; ", 3); @@ -152,8 +210,8 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b24 = getBindingFromASTName("S2 : public", 2); IBinding b25 = getBindingFromASTName("S {}; /*base*/", 1); } - - + + //// header content //class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2}; //short topBasic; void *topPtr; TopC *topCPtr; TopU topFunc(){return *new TopU();} @@ -161,10 +219,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas //// referencing content //namespace n1 { // class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2}; - // short topBasic; void *topPtr; TopC *topCPtr; TopU topFunc(){return *new TopU();} + // short topBasic; void *topPtr;/*A*/ TopC *topCPtr;/*A*/ TopU topFunc(){return *new TopU();} // class C { // class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2}; - // short topBasic; void *topPtr; TopC *topCPtr; TopU topFunc(){return *new TopU();} + // short topBasic; void *topPtr;/*B*/ TopC *topCPtr;/*B*/ TopU topFunc(){return *new TopU();} // void references() { // ::TopC c; ::TopS s; ::TopU u; ::TopE e = ::TopER1; // ::topBasic++; ::topPtr = &::topBasic; ::topCPtr = &c; ::topFunc(); @@ -178,25 +236,32 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b3 = getBindingFromASTName("TopE e", 4); IBinding b4 = getBindingFromASTName("TopER1;", 6); IBinding b5 = getBindingFromASTName("topBasic++", 8); - IBinding b6 = getBindingFromASTName("topPtr", 6); - IBinding b7 = getBindingFromASTName("topBasic", 8); - IBinding b8 = getBindingFromASTName("topCPtr", 7); - IBinding b9 = getBindingFromASTName("topFunc", 7); + IBinding b6 = getBindingFromASTName("topPtr = &", 6); + IBinding b7 = getBindingFromASTName("topBasic; ::", 8); + IBinding b8 = getBindingFromASTName("topCPtr = &", 7); + IBinding b9 = getBindingFromASTName("topFunc();", 7); + + IBinding _b5 = getBindingFromASTName("topBasic; v", 8); + IBinding _b6 = getBindingFromASTName("topPtr;/*A*/", 6); + IBinding _b7 = getBindingFromASTName("topPtr;/*B*/", 6); + IBinding _b8 = getBindingFromASTName("topCPtr;/*A*/", 7); + IBinding _b9 = getBindingFromASTName("topCPtr;/*B*/", 7); + IBinding _b10 = getBindingFromASTName("topFunc(){", 7); } - + public void _testMultiVirtualBaseClassLookup() {fail("aftodo");} public void _testMultiNonVirtualBaseClassLookup() {fail("aftodo");} - + public void _testQualifiedNamesForNamespaceAliases() {fail("aftodo");} public void _testQualifiedNamesForNamespaces() {fail("aftodo");} - + // // header content // namespace n1 { namespace n2 { struct S {}; } } // class c1 { public: class c2 { public: struct S {}; }; }; // struct s1 { struct s2 { struct S {}; }; }; // union u1 { struct u2 { struct S {}; }; }; // namespace n3 { class c3 { public: struct s3 { union u3 { struct S {}; }; }; }; } - + // // reference content // void reference() { // ::n1::n2::S _s0; n1::n2::S _s1; @@ -211,11 +276,23 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // namespace n1 { namespace n2 { S _s12; }} public void testQualifiedNamesForStruct() throws DOMException { IBinding b0 = getBindingFromASTName("S _s0;", 1); + assertTrue(b0.getScope() instanceof ICPPNamespaceScope); + assertTrue(b0.getScope().getParent() instanceof ICPPNamespaceScope); + assertTrue(b0.getScope().getParent().getParent() == null); assertQNEquals("n1::n2::S", b0); + IBinding b1 = getBindingFromASTName("S _s1;", 1); + assertTrue(b1.getScope() instanceof ICPPNamespaceScope); + assertTrue(b1.getScope().getParent() instanceof ICPPNamespaceScope); + assertTrue(b1.getScope().getParent().getParent() == null); assertQNEquals("n1::n2::S", b1); + IBinding b2 = getBindingFromASTName("S _s2;", 1); + assertTrue(b2.getScope() instanceof ICPPClassScope); + assertTrue(b2.getScope().getParent() instanceof ICPPClassScope); + assertTrue(b2.getScope().getParent().getParent() == null); assertQNEquals("c1::c2::S", b2); + IBinding b3 = getBindingFromASTName("S _s3;", 1); assertQNEquals("c1::c2::S", b3); IBinding b4 = getBindingFromASTName("S _s4;", 1); @@ -230,21 +307,28 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas assertQNEquals("n3::c3::s3::u3::S", b8); IBinding b9 = getBindingFromASTName("S _s9;", 1); assertQNEquals("n3::c3::s3::u3::S", b9); + IBinding b10 = getBindingFromASTName("S _s10;", 1); + assertTrue(b10.getScope() instanceof ICPPClassScope); + assertTrue(b10.getScope().getParent() instanceof ICPPClassScope); + assertTrue(b10.getScope().getParent().getParent() instanceof ICPPClassScope); + assertTrue(b10.getScope().getParent().getParent().getParent() instanceof ICPPNamespaceScope); + assertTrue(b10.getScope().getParent().getParent().getParent().getParent() == null); assertQNEquals("n3::c3::s3::u3::S", b10); + IBinding b11 = getBindingFromASTName("S _s11;", 1); assertQNEquals("n1::n2::S", b11); IBinding b12 = getBindingFromASTName("S _s12;", 1); assertQNEquals("n1::n2::S", b12); } - + // // header content // namespace n1 { namespace n2 { union U {}; } } // class c1 { public: class c2 { public: union U {}; }; }; // struct s1 { struct s2 { union U {}; }; }; // union u1 { struct u2 { union U {}; }; }; // namespace n3 { class c3 { public: struct s3 { union u3 { union U {}; }; }; }; } - + // // reference content // void reference() { // ::n1::n2::U _u0; n1::n2::U _u1; @@ -285,7 +369,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b12 = getBindingFromASTName("U _u12;", 1); assertQNEquals("n1::n2::U", b12); } - + // // header content // namespace n1 { namespace n2 { class C {}; } } // class c1 { public: class c2 { public: class C {}; }; }; @@ -333,47 +417,47 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b12 = getBindingFromASTName("C _c12;", 1); assertQNEquals("n1::n2::C", b12); } - - // // header content - // namespace n1 { namespace n2 { typedef int Int; } } - // class c1 { public: class c2 { public: typedef int Int; }; }; - // struct s1 { struct s2 { typedef int Int; }; }; - // union u1 { struct u2 { typedef int Int; }; }; - // namespace n3 { class c3 { public: struct s3 { union u3 { typedef int Int; }; }; }; } - - // // reference content - // void reference() { - // ::n1::n2::Int i0; n1::n2::Int i1; - // ::c1::c2::Int i2; c1::c2::Int i3; - // ::s1::s2::Int i4; s1::s2::Int i5; - // ::u1::u2::Int i6; u1::u2::Int i7; - // ::n3::c3::s3::u3::Int i8; - // n3::c3::s3::u3::Int i9; - // } - // namespace n3 { c3::s3::u3::Int i10; } - // namespace n1 { n2::Int i11; } - // namespace n1 { namespace n2 { Int i12; }} + + // // header content + // namespace n1 { namespace n2 { typedef int Int; } } + // class c1 { public: class c2 { public: typedef int Int; }; }; + // struct s1 { struct s2 { typedef int Int; }; }; + // union u1 { struct u2 { typedef int Int; }; }; + // namespace n3 { class c3 { public: struct s3 { union u3 { typedef int Int; }; }; }; } + + // // reference content + // void reference() { + // ::n1::n2::Int i0; n1::n2::Int i1; + // ::c1::c2::Int i2; c1::c2::Int i3; + // ::s1::s2::Int i4; s1::s2::Int i5; + // ::u1::u2::Int i6; u1::u2::Int i7; + // ::n3::c3::s3::u3::Int i8; + // n3::c3::s3::u3::Int i9; + // } + // namespace n3 { c3::s3::u3::Int i10; } + // namespace n1 { n2::Int i11; } + // namespace n1 { namespace n2 { Int i12; }} public void testQualifiedNamesForTypedef() throws DOMException { IBinding b0 = getBindingFromASTName("Int i0;", 3); assertQNEquals("n1::n2::Int", b0); IBinding b1= getBindingFromASTName("Int i1;", 3); assertQNEquals("n1::n2::Int", b1); - + IBinding b2 = getBindingFromASTName("Int i2;", 3); assertQNEquals("c1::c2::Int", b2); IBinding b3 = getBindingFromASTName("Int i3;", 3); assertQNEquals("c1::c2::Int", b3); - + IBinding b4 = getBindingFromASTName("Int i4;", 3); assertQNEquals("s1::s2::Int", b4); IBinding b5 = getBindingFromASTName("Int i5;", 3); assertQNEquals("s1::s2::Int", b5); - + IBinding b6 = getBindingFromASTName("Int i6;", 3); assertQNEquals("u1::u2::Int", b6); IBinding b7 = getBindingFromASTName("Int i7;", 3); assertQNEquals("u1::u2::Int", b7); - + IBinding b8 = getBindingFromASTName("Int i8;", 3); assertQNEquals("n3::c3::s3::u3::Int", b8); IBinding b9 = getBindingFromASTName("Int i9;", 3); @@ -385,10 +469,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b12 = getBindingFromASTName("Int i12;", 3); assertQNEquals("n1::n2::Int", b12); } - + // // header content // enum E { ER1, ER2 }; - + // // referencing content // class C { // E e1; @@ -401,10 +485,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b1 = getBindingFromASTName("ER1; }", 3); IBinding b2 = getBindingFromASTName("ER2; }", 3); } - + // // header content // enum E { ER1, ER2 }; - + // // referencing content // struct S { // E e1; @@ -417,10 +501,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b1 = getBindingFromASTName("ER1; }", 3); IBinding b2 = getBindingFromASTName("ER2; }", 3); } - + // // header content // enum E { ER1, ER2 }; - + // // referencing content // union U { // E e1; @@ -433,10 +517,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b1 = getBindingFromASTName("ER1; }", 3); IBinding b2 = getBindingFromASTName("ER2; }", 3); } - + // // header content // enum E { ER1, ER2 }; - + // // referencing content // namespace n1 { // E e1; @@ -449,10 +533,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b1 = getBindingFromASTName("ER1; }", 3); IBinding b2 = getBindingFromASTName("ER2; }", 3); } - - // // teh header + + // // the header // void foo(int a=2, int b=3); - + // #include "header.h" // void ref() { foo(); } public void testFunctionDefaultArguments() { @@ -464,7 +548,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // namespace ns { // const TYPE* foo(int a); // }; - + // #include "header.h" // const TYPE* ns::foo(int a) { return 0; } public void testTypeQualifier() { @@ -488,10 +572,10 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b1 = getBindingFromASTName("foo(55L);", 3); IBinding b2 = getBindingFromASTName("foo(4);", 3); } - + // // header content // namespace x { namespace y { int i; } } - + // // the references // #include "header.h" // class C { public: @@ -519,8 +603,8 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b5 = getBindingFromASTName("j++", 1); assertTrue(ICPPVariable.class.isInstance(b5)); } - - + + ////header content //struct S {int i;}; //struct SS { S s, *sp; }; @@ -530,7 +614,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas //S s, *sp; //SS ss, *ssp; //S *a[3]; - + ////reference content //void references() { // a[0]->i/*0*/++; (*a[0]).i/*1*/++; // IASTArraySubscriptExpression @@ -569,15 +653,15 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b17 = getBindingFromASTName("i/*17*/", 1); IBinding b18 = getBindingFromASTName("i/*18*/", 1); } - - + + // // header file // class C {public: C* cp;}; // C foo(C c); // C* foo(C* c); // int foo(int i); // int foo(int i, C c); - + // // referencing content // #include "header.h" // void references() { @@ -604,45 +688,45 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b0 = getBindingFromASTName("foo/*a*/", 3); IBinding b0a = getBindingFromASTName("cp[1]", 2); // assertCompositeTypeParam(0, ICPPClassType.k_class, b0, "C"); - + IBinding b1 = getBindingFromASTName("foo/*b*/", 3); IBinding b1a = getBindingFromASTName("cp+1", 2); - + IBinding b2 = getBindingFromASTName("foo/*c*/", 3); IBinding b2a = getBindingFromASTName("cp);/*1*/", 2); - + IBinding b3 = getBindingFromASTName("foo/*d*/", 3); IBinding b3a = getBindingFromASTName("c : c", 1); IBinding b3b = getBindingFromASTName("c);/*2*/", 1); - + IBinding b4 = getBindingFromASTName("foo/*e*/", 3); IBinding b4a = getBindingFromASTName("c);/*3*/", 1); - - IBinding b5 = getBindingFromASTName("foo/*f*/", 3); - IBinding b5a = getBindingFromASTName("cp);/*4*/", 2); + + IBinding b5 = getBindingFromASTName("cp);/*4*/", 2); + IBinding b5a = getBindingFromASTName("foo/*f*/", 3); IBinding b5b = getBindingFromASTName("cp->cp);/*5*/", 2); IBinding b5c = getBindingFromASTName("cp);/*5*/", 2); - + IBinding b6 = getBindingFromASTName("foo/*g*/", 3); IBinding b6a = getBindingFromASTName("foo(c));/*6*/", 3); IBinding b6b = getBindingFromASTName("c));/*6*/", 1); IBinding b6c = getBindingFromASTName("foo(foo(1));/*7*/", 3); IBinding b6d = getBindingFromASTName("foo(1));/*7*/", 3); - + IBinding b7 = getBindingFromASTName("foo/*h*/", 3); IBinding b7a = getBindingFromASTName("c);/*8*/", 1); - + IBinding b8 = getBindingFromASTName("foo/*i*/", 3); - + IBinding b9 = getBindingFromASTName("foo/*j*/", 3); IBinding b9a = getBindingFromASTName("C));/*9*/", 1); - + IBinding b10 = getBindingFromASTName("foo/*k*/", 3); IBinding b10a = getBindingFromASTName("cp);/*10*/", 2); - + IBinding b11 = getBindingFromASTName("foo/*l*/", 3); IBinding b11a = getBindingFromASTName("cp);/*11*/", 2); - + IBinding b12 = getBindingFromASTName("foo/*m*/", 3); IBinding b12a = getBindingFromASTName("C());/*12*/", 1); // IBinding b13 = getBindingFromASTName(ast, "foo/*n*/", 3); @@ -673,7 +757,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // void f(U); void f(U::i3); void f(U::lp3); void f(U::S3); void f(U::U3); void f(U::E3); // void f(n::i4); void f(n::lp4); void f(n::S4); void f(n::U4); void f(n::E4); // void f(E); - + // // reference content // #include "header.h" // void references() { @@ -717,7 +801,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b23 = getBindingFromASTName("f;/*23*/", 1); IBinding b24 = getBindingFromASTName("f;/*24*/", 1); } - + public void _testAddressOfOverloadedMethod() throws DOMException { fail("aftodo"); } // // the header @@ -754,7 +838,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // void f_int_ptr_const(int *const); // void f_const_int_ptr_const(const int*const); // void f_int_const_ptr_const(int const*const); - + // #include "header.h" // void ref() { // int* int_ptr = 0; @@ -851,7 +935,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas } // // the header - + // void f(int*){} // b1 // void f(const int*){} // b2 // void f(int const*){} // b2, redef @@ -868,7 +952,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas } // // the header - + // void f(int&){} // b1 // void f(const int&){} // b2 // void f(int const&){} // b2, redef @@ -904,11 +988,11 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // f(int_ptr_const); // b1 // f(const_int_ptr_const); // b2 // f(int_const_ptr_const); // b2 - // } + // } public void testConstIntPtrParameterInDefinitionAST2() throws CoreException { IBinding binding1= getBindingFromASTName("f(int*){}", 1); IBinding binding2= getBindingFromASTName("f(const int*){}", 1); - + assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1)); assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1)); assertEquals(binding2, getBindingFromASTName("f(int_const_ptr)", 1)); @@ -943,11 +1027,11 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // f(int_ptr_const); // b1 // f(const_int_ptr_const); // b2 // f(int_const_ptr_const); // b2 - // } + // } public void testConstIntPtrParameterInDefinition() throws CoreException { IBinding binding1= getBindingFromASTName("f(int*){}", 1); IBinding binding2= getBindingFromASTName("f(const int*){}", 1); - + assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1)); assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1)); assertEquals(binding2, getBindingFromASTName("f(int_const_ptr)", 1)); @@ -955,8 +1039,8 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1)); assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1)); - assertEquals(2, index.findNames(binding1, IIndex.FIND_DECLARATIONS).length); - assertEquals(4, index.findNames(binding2, IIndex.FIND_DECLARATIONS).length); + assertEquals(2, getIndex().findNames(binding1, IIndex.FIND_DECLARATIONS).length); + assertEquals(4, getIndex().findNames(binding2, IIndex.FIND_DECLARATIONS).length); } // typedef struct S {int a;} S; @@ -974,4 +1058,136 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas assertTrue(b2 instanceof IEnumeration); } + + + + + + /* CPP assertion helpers */ + /* ##################################################################### */ + + static protected void assertVariable( + IBinding binding, + String qn, + Class expType, + String expTypeQN + ) { + try { + assertTrue(binding instanceof ICPPVariable); + ICPPVariable variable = (ICPPVariable) binding; + assertQNEquals(qn, variable); + assertTrue(expType.isInstance(variable.getType())); + if(expTypeQN!=null) { + assert(variable.getType() instanceof ICPPBinding); + ICPPBinding tyBinding = (ICPPBinding) variable.getType(); + assertQNEquals(expTypeQN, tyBinding); + } + } catch(DOMException de) { + fail(de.getMessage()); + } + } + + static protected void assertField( + IBinding binding, + String qn, + Class expType, + String expTypeQN + ) { + try { + assertTrue(binding instanceof ICPPField); + ICPPField field = (ICPPField) binding; + assertQNEquals(qn, field); + assertTrue(expType.isInstance(field.getType())); + if(expTypeQN!=null) { + assert(field.getType() instanceof ICPPBinding); + ICPPBinding tyBinding = (ICPPBinding) field.getType(); + assertQNEquals(expTypeQN, tyBinding); + } + } catch(DOMException de) { + fail(de.getMessage()); + } + } + + static protected void assertClassTypeBinding(IBinding binding, + String qn, + int key, + int bases, + int fields, + int declaredFields, + int methods, + int declaredMethods, + int allDeclaredMethods, + int friends, + int constructors, + int nestedClasses) { + assertTrue(binding instanceof ICPPClassType); + assertClassType(((ICPPClassType) binding), qn, key, bases, fields, declaredFields, methods, declaredMethods, allDeclaredMethods, friends, constructors, nestedClasses); + } + + static protected void assertClassType( + IType type, + String qn, + int key, + int bases, + int fields, + int declaredFields, + int methods, + int declaredMethods, + int allDeclaredMethods, + int friends, + int constructors, + int nestedClasses + ) { + try { + assertTrue(type instanceof ICPPClassType); + ICPPClassType classType = (ICPPClassType) type; + assertQNEquals(qn, classType); + assertEquals(key, classType.getKey()); + assertEquals(bases, classType.getBases().length); + assertEquals(fields, classType.getFields().length); + assertEquals(declaredFields, classType.getDeclaredFields().length); + assertEquals(methods, classType.getMethods().length); + assertEquals(declaredMethods, classType.getDeclaredMethods().length); + assertEquals(allDeclaredMethods, classType.getAllDeclaredMethods().length); + // assertEquals(friends, classType.getFriends().length); (PDOMNotImplementedError) + assertEquals(constructors, classType.getConstructors().length); + assertEquals(nestedClasses, classType.getNestedClasses().length); + } catch(DOMException de) { + fail(de.getMessage()); + } + } + + public void assertEnumeration(IBinding binding, String name, String[] enumerators) throws DOMException { + assertTrue(binding instanceof IEnumeration); + assertEquals(name, binding.getName()); + IEnumerator[] aEnumerators = ((IEnumeration)binding).getEnumerators(); + Set expectedEnumerators = new HashSet(); + expectedEnumerators.addAll(Arrays.asList(enumerators)); + Set actualEnumerators = new HashSet(); + for(int i=0; inull * @throws CoreException */ - IIndexProxyBinding adaptBinding(IBinding binding) throws CoreException; + IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException; /** * Looks for a proxy binding matching the given one. May return null, if no @@ -84,7 +86,7 @@ public interface IIndexFragment { * @return the binding, or null * @throws CoreException */ - IIndexProxyBinding adaptBinding(IIndexProxyBinding proxy) throws CoreException; + IIndexFragmentBinding adaptBinding(IIndexFragmentBinding proxy) throws CoreException; /** * Looks for a binding of the given name from the AST. May return null, if no @@ -93,7 +95,7 @@ public interface IIndexFragment { * @return the binding for the name, or null * @throws CoreException */ - IIndexProxyBinding findBinding(IASTName astName) throws CoreException; + IIndexFragmentBinding findBinding(IASTName astName) throws CoreException; /** * Searches for all bindings with qualified names that seen as an array of simple names match the given array @@ -127,7 +129,7 @@ public interface IIndexFragment { * @return an array of names * @throws CoreException */ - IIndexFragmentName[] findNames(IIndexProxyBinding binding, int flags) throws CoreException; + IIndexFragmentName[] findNames(IIndexFragmentBinding binding, int flags) throws CoreException; /** * Acquires a read lock. @@ -145,13 +147,14 @@ public interface IIndexFragment { */ long getLastWriteAccess(); - /** - * Returns all bindings with the given name in the given namespace - */ - IBinding[] findInNamespace(IBinding nsbinding, char[] name) throws CoreException; - /** * Returns all bindings with the given prefix, accepted by the given filter */ - IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException; + IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException; + + /** + * Returns the linkages that are contained in this fragment + * @return + */ + IIndexLinkage[] getLinkages(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java index b80265b9cb4..494eff58ccf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -7,12 +7,31 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.index; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.core.runtime.CoreException; -public interface IIndexFragmentBinding extends IIndexBinding, IIndexProxyBinding { +public interface IIndexFragmentBinding extends Comparable, IIndexBinding { IIndexFragmentBinding[] EMPTY_INDEX_BINDING_ARRAY= new IIndexFragmentBinding[0]; + + /** + * Returns the owner of the binding. + */ + IIndexFragment getFragment(); + + /** + * Returns the linkage the binding belongs to. + */ + ILinkage getLinkage() throws CoreException; + + /** + * Returns whether this binding has any definitions associated with it + * in its associated fragment. + */ + boolean hasDefinition() throws CoreException; } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentFile.java index 6ae0ce7d4bb..af81c7fafa3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.index; @@ -27,4 +28,12 @@ public interface IIndexFragmentFile extends IIndexFile { */ void setTimestamp(long timestamp) throws CoreException; + /** + * Returns whether any names are associated with this file object + * in this fragment - i.e. whether this file contains content in its + * associated fragment + * @return whether any names are associated with this file object + * in this fragment + */ + boolean hasNames() throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentName.java index 391d19f2c51..665351c253c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentName.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.index; @@ -26,5 +27,5 @@ public interface IIndexFragmentName extends IIndexName { /** * Returns the (proxy) binding the name resolves to. */ - IIndexProxyBinding getBinding() throws CoreException; + IIndexFragmentBinding getBinding() throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexProxyBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java similarity index 52% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexProxyBinding.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java index f22008f9380..3fcc88166db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexProxyBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java @@ -1,28 +1,27 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2007 Symbian 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ package org.eclipse.cdt.internal.core.index; -import org.eclipse.cdt.core.dom.ILinkage; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.index.IIndexBinding; -public interface IIndexProxyBinding { + +/** + * Interface for scopes returned via the index + * @since 4.0 + */ +public interface IIndexScope extends IScope { /** - * Returns the owner of the binding. + * Get the binding associated with scope + * @return */ - IIndexFragment getFragment(); - - /** - * Returns the linkage the binding belongs to. - */ - ILinkage getLinkage() throws CoreException; - + IIndexBinding getScopeBinding(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java index e2dda72eaf5..d0842f1cc49 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java @@ -90,6 +90,7 @@ public class IndexFactory { ICProject cproject = projects[i]; IProject project= cproject.getProject(); checkAddProject(project, map, projectsToSearch, markWith); + projectsToSearch.add(project); } if (addDependencies || addDependent) { @@ -156,11 +157,24 @@ public class IndexFactory { } } + selectedProjects= getProjects(new ICProject[] {project}, true, false, new HashMap(), new Integer(1)); + selectedProjects.remove(project); + ArrayList readOnly= new ArrayList(); + for (Iterator iter = selectedProjects.iterator(); iter.hasNext(); ) { + ICProject cproject = (ICProject) iter.next(); + IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(cproject); + if (pdom != null) { + readOnly.add(pdom); + } + } + + if (pdoms.isEmpty()) { throw new CoreException(CCorePlugin.createStatus( MessageFormat.format(Messages.IndexFactory_errorNoSuchPDOM0, new Object[]{project.getElementName()}))); } - return new WritableCIndex((IWritableIndexFragment[]) pdoms.toArray(new IWritableIndexFragment[pdoms.size()]), new IIndexFragment[0]); + return new WritableCIndex((IWritableIndexFragment[]) pdoms.toArray(new IWritableIndexFragment[pdoms.size()]), + (IIndexFragment[]) readOnly.toArray(new IIndexFragment[readOnly.size()]) ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java new file mode 100644 index 00000000000..1b1bd010ba4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite; + +import java.util.TreeSet; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.internal.core.index.CIndex; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.core.runtime.CoreException; + +/** + * Commonality between composite factories + */ +public abstract class AbstractCompositeFactory implements ICompositesFactory { + protected IIndex index; + + public AbstractCompositeFactory(IIndex index) { + this.index = index; + } + + /* + * (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.composite.ICompositesFactory#getCompositeBindings(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.internal.core.index.IIndexFragmentBinding[]) + */ + public final IIndexBinding[] getCompositeBindings(IBinding[] bindings) { + IIndexBinding[] result = new IIndexBinding[bindings.length]; + for(int i=0; i + * Like the component IIndexBinding objects that make up a CompositeIndexBinding, the + * it is only valid to call methods and obtain information while a read-lock is held on the + * associated IIndex + */ +public abstract class CompositeIndexBinding implements IIndexBinding { + /** + * The factory used for obtaining further composite bindings + */ + protected final ICompositesFactory cf; + /** + * The representative binding for this composite binding. Most cases are simple + * enough that this becomes a delegate, some need to use it as a search key over fragments, + * and some ignore it as a representative binding from each fragment is needed to meet interface + * contracts. + */ + protected final IBinding rbinding; + + public CompositeIndexBinding(ICompositesFactory cf, IBinding rbinding) { + if(rbinding == null || cf == null) + throw new IllegalArgumentException(); + this.cf = cf; + this.rbinding = rbinding; + } + + public ILinkage getLinkage() throws CoreException { + return rbinding.getLinkage(); + } + + public String getName() { + return rbinding.getName(); + } + + public char[] getNameCharArray() { + return rbinding.getNameCharArray(); + } + + public Object getAdapter(Class adapter) { + fail(); + return null; + } + + public String[] getQualifiedName() { + return new String[] {getName()}; + } + + public IScope getScope() throws DOMException { + return cf.getCompositeScope(rbinding.getScope()); + } + + public boolean hasDefinition() throws CoreException { + fail(); return false; + } + + protected final void fail() { + throw new CompositingNotImplementedError("Compositing feature not implemented"); //$NON-NLS-1$ + } + + public String toString() { + return rbinding.toString(); + } + + public boolean isFileLocal() throws CoreException { + return rbinding instanceof IIndexBinding ? ((IIndexBinding)rbinding).isFileLocal() : true; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositePointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositePointerType.java new file mode 100644 index 00000000000..51c2a931481 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositePointerType.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IPointerType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; + +public class CompositePointerType extends CompositeType implements IPointerType, ITypeContainer { + public CompositePointerType(IPointerType pointerType, ICompositesFactory cf) throws DOMException { + super((ITypeContainer) pointerType, cf); + } + + public boolean isConst() throws DOMException { + return ((IPointerType)type).isConst(); + } + + public boolean isVolatile() throws DOMException { + return ((IPointerType)type).isVolatile(); + } + + public boolean isSameType(IType other) { + return ((IPointerType)type).isSameType(other); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java new file mode 100644 index 00000000000..9a9a3d8cb77 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IQualifierType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; + +public class CompositeQualifierType extends CompositeType implements IQualifierType, ITypeContainer { + public CompositeQualifierType(IQualifierType qualifierType, ICompositesFactory cf) throws DOMException { + super((ITypeContainer) qualifierType, cf); + } + + public boolean isConst() throws DOMException { + return ((IQualifierType)type).isConst(); + } + + public boolean isVolatile() throws DOMException { + return ((IQualifierType)type).isVolatile(); + } + + public boolean isSameType(IType other) { + return ((IQualifierType)type).isSameType(other); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java new file mode 100644 index 00000000000..6ecc3b1fed8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite; + +import org.eclipse.cdt.core.dom.IName; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.internal.core.index.IIndexScope; + +public abstract class CompositeScope implements IIndexScope { + /** + * The factory used for obtaining further composite bindings + */ + protected final ICompositesFactory cf; + /** + * The representative binding for this composite binding. Most cases are simple + * enough that this becomes a delegate, some need to use it as a search key over fragments, + * and some ignore it as a representative binding from each fragment is needed to meet interface + * contracts. + */ + protected final IBinding rbinding; + + public CompositeScope(ICompositesFactory cf, IBinding rbinding) { + if(cf==null || rbinding==null) + throw new NullPointerException(); + this.cf = cf; + this.rbinding = rbinding; + } + + final public IScope getParent() throws DOMException { + IScope rscope = rbinding.getScope(); + if(rscope!=null) { + return cf.getCompositeScope(rscope); + } + return null; + } + + // Note: for c++ namespaces we are returning an arbitrary name + final public IName getScopeName() throws DOMException { + IScope scope = rbinding.getScope(); + if(scope==null) + return null; + return scope.getScopeName(); + } + + protected final void fail() { + throw new CompositingNotImplementedError(); + } + + + public IBinding getRawScopeBinding() { + return rbinding; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeType.java new file mode 100644 index 00000000000..99f8e1bbff8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeType.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.index.IIndexType; + +/** + * Represents an index-contexting carrying type + */ +public abstract class CompositeType implements IType, IIndexType, ITypeContainer { + protected final ITypeContainer type; + protected final ICompositesFactory cf; + + protected CompositeType(ITypeContainer rtype, ICompositesFactory cf) { + this.type = rtype; + this.cf = cf; + } + + public boolean isSameType(IType other) { + return type.isSameType(other); + } + + public Object clone() { + fail(); return null; + } + + public final void setType(IType type) { + fail(); + } + + public final IType getType() throws DOMException { + return cf.getCompositeType(type.getType()); + } + + protected void fail() { + throw new CompositingNotImplementedError("Compositing feature (for IType) not implemented"); //$NON-NLS-1$ + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositingNotImplementedError.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositingNotImplementedError.java new file mode 100644 index 00000000000..817d5c7f6a1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositingNotImplementedError.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite; + +public class CompositingNotImplementedError extends Error { + private static final long serialVersionUID = -7296443480526626589L; + + public CompositingNotImplementedError() { + super(); + printStackTrace(); + } + + public CompositingNotImplementedError(String msg) { + super(msg); + printStackTrace(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java new file mode 100644 index 00000000000..9b4efbc7bcb --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; + +public interface ICompositesFactory { + + public IScope getCompositeScope(IScope rscope) throws DOMException; + + /** + * Returns a composite (in the sense of potentially spanning multiple index fragments - i.e. not to be confused + * with ICompositeType) type for the specified type. + * @param index + * @param type + * @return + */ + public IType getCompositeType(IType rtype) throws DOMException; + + /** + * Returns a composite (index context carrying) binding for the specified binding. It does not + * matter which fragment the specified binding comes from + * @param index the context to construct the composite binding for + * @param binding a binding that will be used when searching for information to return from the composite + * binding methods + * @return a composite (index context carrying) binding for the specified binding + */ + public IIndexBinding getCompositeBinding(IBinding binding); + + /** + * A convenience method that operates as getCompositeBinding but over the contents of an array + * @param index the context to construct the composite binding for + * @param bindings an array of composite bindings to use when pair-wise constructing the result via getCompositeBinding + * @return an array of composite bindings pair-wise constructed via getCompositeBinding + */ + public IIndexBinding[] getCompositeBindings(IBinding[] bindings); + + /** + * Identifies common bindings, calls getCompositeBindings + * @param index + * @param bindings + * @return + */ + public IIndexBinding[] getCompositeBindings(IIndexFragmentBinding[][] bindings); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java new file mode 100644 index 00000000000..f932feb1332 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite.c; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IArrayType; +import org.eclipse.cdt.core.dom.ast.IBasicType; +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.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IPointerType; +import org.eclipse.cdt.core.dom.ast.IQualifierType; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.cdt.internal.core.index.composite.AbstractCompositeFactory; +import org.eclipse.cdt.internal.core.index.composite.CompositeArrayType; +import org.eclipse.cdt.internal.core.index.composite.CompositePointerType; +import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType; +import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; + +public class CCompositesFactory extends AbstractCompositeFactory implements ICompositesFactory { + + public CCompositesFactory(IIndex index) { + super(index); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeScope(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IScope) + */ + public IScope getCompositeScope(IScope rscope) { + if(rscope==null) + return null; + if(rscope instanceof ICCompositeTypeScope) { + try { + ICCompositeTypeScope cscope = (ICCompositeTypeScope) rscope; + IIndexFragmentBinding rbinding = (IIndexFragmentBinding) cscope.getCompositeType(); + return ((ICompositeType)getCompositeBinding(rbinding)).getCompositeScope(); + } catch(DOMException de) { + CCorePlugin.log(de); + } + } + throw new CompositingNotImplementedError(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeType(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IType) + */ + public IType getCompositeType(IType rtype) throws DOMException { + IType result; + + if(rtype==null) { + result = null; + } else if(rtype instanceof ICompositeType) { + result = (ICompositeType) getCompositeBinding((IIndexFragmentBinding) rtype); + } else if (rtype instanceof IEnumeration) { + result = (IEnumeration) getCompositeBinding((IIndexFragmentBinding) rtype); + } else if(rtype instanceof IPointerType) { + result = new CompositePointerType((IPointerType)rtype, this); + } else if(rtype instanceof IQualifierType) { + result = new CompositeQualifierType((IQualifierType) rtype, this); + } else if(rtype instanceof IArrayType) { + result = new CompositeArrayType((IArrayType) rtype, this); + } else if(rtype instanceof ITypedef) { + result = new CompositeCTypedef(this, (IIndexFragmentBinding) rtype); + } else if(rtype instanceof IBasicType) { + result = rtype; // no context required its a leaf with no way to traverse upward + } else { + throw new CompositingNotImplementedError(); + } + + return result; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeBinding(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IBinding) + */ + public IIndexBinding getCompositeBinding(IBinding rbinding) { + IIndexBinding result; + + if(rbinding==null) { + result = null; + } else if(rbinding instanceof IParameter) { + result = new CompositeCParameter(this, rbinding); + } else if(rbinding instanceof IField) { + result = new CompositeCField(this, rbinding); + } else if(rbinding instanceof IVariable) { + result = new CompositeCVariable(this, rbinding); + } else if(rbinding instanceof ICompositeType) { + result = new CompositeCStructure(this, findOneDefinition(rbinding)); + } else if(rbinding instanceof IEnumeration) { + result = new CompositeCEnumeration(this, findOneDefinition(rbinding)); + } else if(rbinding instanceof IFunction) { + result = new CompositeCFunction(this, rbinding); + } else if(rbinding instanceof IEnumerator) { + result = new CompositeCEnumerator(this, rbinding); + } else if(rbinding instanceof ITypedef) { + result = new CompositeCTypedef(this, rbinding); + } else { + throw new CompositingNotImplementedError("composite binding unavailable for "+rbinding+" "+rbinding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$ + } + + return result; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCBinding.java new file mode 100644 index 00000000000..f56e9d5bd4a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCBinding.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite.c; + +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.internal.core.index.composite.CompositeIndexBinding; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; + +abstract class CompositeCBinding extends CompositeIndexBinding { + public CompositeCBinding(ICompositesFactory cf, IBinding rbinding) { + super(cf, rbinding); + } +} 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 new file mode 100644 index 00000000000..722e962ff83 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCCompositeScope.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite.c; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTName; +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.ICCompositeTypeScope; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.cdt.internal.core.index.composite.CompositeScope; +import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; + +class CompositeCCompositeScope extends CompositeScope implements ICCompositeTypeScope { + + public CompositeCCompositeScope(ICompositesFactory cf, IBinding rbinding) { + super(cf, rbinding); + } + + public IBinding getBinding(char[] name) throws DOMException { + fail(); return null; + } + + public ICompositeType getCompositeType() { + return (ICompositeType) cf.getCompositeBinding(rbinding); + } + + public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { + IBinding binding = ((ICompositeType)rbinding).getCompositeScope().getBinding(name, resolve); + if(binding instanceof IIndexFragmentBinding) { + IIndexFragmentBinding preresult = (IIndexFragmentBinding) binding; + return cf.getCompositeBinding(preresult); + } + if(binding!=null && !(binding instanceof IProblemBinding)) { + throw new CompositingNotImplementedError(binding.getClass().toString()); + } + return binding; + } + + public IBinding[] find(String name, boolean prefixLookup) + throws DOMException { + IBinding[] preresult = ((ICompositeType)rbinding).getCompositeScope().find(name, prefixLookup); + return cf.getCompositeBindings(preresult); + } + + public IBinding[] find(String name) throws DOMException { + IBinding[] preresult = ((ICompositeType)rbinding).getCompositeScope().find(name); + return cf.getCompositeBindings(preresult); + } + + public IIndexBinding getScopeBinding() { + return (IIndexBinding) getCompositeType(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCEnumeration.java new file mode 100644 index 00000000000..679de113fe8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCEnumeration.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite.c; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; + +class CompositeCEnumeration extends CompositeCBinding implements IIndexBinding, IEnumeration, IIndexType { + public CompositeCEnumeration(ICompositesFactory cf, IIndexFragmentBinding rbinding) { + super(cf, rbinding); + } + + public IEnumerator[] getEnumerators() throws DOMException { + IEnumerator[] result = ((IEnumeration)rbinding).getEnumerators(); + for(int i=0; i 0: "No lock to release"; //$NON-NLS-1$ + lastReadAccess= System.currentTimeMillis(); if (lockCount > 0) --lockCount; mutex.notifyAll(); @@ -508,12 +512,16 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public long getLastWriteAccess() { return lastWriteAccess; } + + public long getLastReadAccess() { + return lastReadAccess; + } protected PDOMLinkage adaptLinkage(ILinkage linkage) throws CoreException { return (PDOMLinkage) fLinkageIDCache.get(linkage.getID()); } - public IIndexProxyBinding adaptBinding(IBinding binding) throws CoreException { + public IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException { if (binding instanceof PDOMBinding) { PDOMBinding pdomBinding= (PDOMBinding) binding; if (pdomBinding.getPDOM() == this) { @@ -528,7 +536,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return null; } - public IIndexProxyBinding adaptBinding(IIndexProxyBinding binding) throws CoreException { + public IIndexFragmentBinding adaptBinding(IIndexFragmentBinding binding) throws CoreException { if (binding instanceof IBinding) { return adaptBinding((IBinding) binding); } @@ -544,14 +552,14 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } public IIndexFragmentName[] findNames(IBinding binding, int options) throws CoreException { - IIndexProxyBinding proxyBinding= adaptBinding(binding); + IIndexFragmentBinding proxyBinding= adaptBinding(binding); if (proxyBinding != null) { return findNames(proxyBinding, options); } return IIndexFragmentName.EMPTY_NAME_ARRAY; } - public IIndexFragmentName[] findNames(IIndexProxyBinding binding, int options) throws CoreException { + public IIndexFragmentName[] findNames(IIndexFragmentBinding binding, int options) throws CoreException { PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding); if (pdomBinding != null) { @@ -601,20 +609,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return fPath; } - public IBinding[] findInNamespace(IBinding nsbinding, char[] name) throws CoreException { - IIndexProxyBinding ns= adaptBinding(nsbinding); - if (ns instanceof ICPPNamespace) { - try { - ICPPNamespaceScope scope = ((ICPPNamespace)ns).getNamespaceScope(); - return scope.find(new String(name)); - } catch(DOMException de) { - CCorePlugin.log(de); - } - } - return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; - } - - public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException { + public IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException { ArrayList result = new ArrayList(); for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) { PDOMLinkage linkage = (PDOMLinkage) iter.next(); @@ -625,6 +620,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } } } - return (IBinding[]) result.toArray(new IBinding[result.size()]); + return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java index 0b5088b4f7d..0f6424159bd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; @@ -19,9 +20,9 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IWritableIndexFragment; -import org.eclipse.cdt.internal.core.pdom.dom.IIndexLocationConverter; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index e9fbab19f85..8e4cbce684a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; +import org.eclipse.cdt.internal.core.pdom.db.IString; import org.eclipse.core.runtime.CoreException; /** @@ -217,7 +218,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen return null; } } - + final public String[] getQualifiedName() { List result = new ArrayList(); try { @@ -238,4 +239,44 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen final public boolean isFileLocal() throws CoreException { return getParentNode() instanceof PDOMFileLocalScope; } + + + public boolean hasDefinition() throws CoreException { + return getFirstDefinition()!=null; + } + + private static int comparePDOMBindingQNs(PDOMBinding b0, PDOMBinding b1) { + try { + int cmp = 0; + do { + IString s0 = b0.getDBName(), s1 = b1.getDBName(); + cmp = s0.compare(s1); + if(cmp==0) { + b0 = (PDOMBinding) b0.getParentBinding(); + b1 = (PDOMBinding) b1.getParentBinding(); + if(b0==null || b1==null) { + cmp = b0==b1 ? 0 : (b0==null ? -1 : 1); + } + } + } while(cmp==0 && b1!=null && b0!=null); + return cmp; + } catch(CoreException ce) { + CCorePlugin.log(ce); + return -1; + } + } + + public int compareTo(Object other) { + if(other instanceof PDOMBinding) { + PDOMBinding otherBinding = (PDOMBinding) other; + int cmp = comparePDOMBindingQNs(this, otherBinding); + if(cmp==0) { + int t1 = getNodeType(); + int t2 = otherBinding.getNodeType(); + return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0); + } + return cmp; + } + throw new PDOMNotImplementedError(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java index da99c5c550f..d8688f8b7c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexInclude; +import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.internal.core.index.IIndexFragment; @@ -262,14 +263,14 @@ public class PDOMFile implements IIndexFragmentFile { PDOMInclude lastInclude= null; for (int i = 0; i < includes.length; i++) { IASTPreprocessorIncludeStatement statement = includes[i]; - PDOMFile file= (PDOMFile) files[i]; - assert file.getIndexFragment() instanceof IWritableIndexFragment; + PDOMFile thisIncludes= (PDOMFile) files[i]; + assert thisIncludes.getIndexFragment() instanceof IWritableIndexFragment; PDOMInclude pdomInclude = new PDOMInclude(pdom, statement); pdomInclude.setIncludedBy(this); - pdomInclude.setIncludes(file); + pdomInclude.setIncludes(thisIncludes); - file.addIncludedBy(pdomInclude); + thisIncludes.addIncludedBy(pdomInclude); if (lastInclude == null) { setFirstInclude(pdomInclude); } @@ -378,4 +379,8 @@ public class PDOMFile implements IIndexFragmentFile { throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toExternalProblem")+raw)); //$NON-NLS-1$ return result; } + + public boolean hasNames() throws CoreException { + return getFirstName()!=null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index c00116c448d..cec4d702a7c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -35,6 +35,8 @@ import org.eclipse.cdt.core.index.IIndexLinkage; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.index.IIndexScope; +import org.eclipse.cdt.internal.core.index.composite.CompositeScope; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.Database; @@ -204,9 +206,13 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } return null; } - - if (scope instanceof IIndexBinding) { - return adaptBinding((IBinding) scope); + + if(scope instanceof IIndexScope) { + if(scope instanceof CompositeScope) { // we special case for performance + return adaptBinding(((CompositeScope)scope).getRawScopeBinding()); + } else { + return adaptBinding(((IIndexScope) scope).getScopeBinding()); + } } // the scope is from the ast diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java index a852aa19ae7..34122066987 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java @@ -20,8 +20,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.internal.core.index.IIndexFragment; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentName; -import org.eclipse.cdt.internal.core.index.IIndexProxyBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.core.runtime.CoreException; @@ -326,7 +326,7 @@ public class PDOMName implements IIndexFragmentName, IASTFileLocation { return pdom; } - public IIndexProxyBinding getBinding() throws CoreException { + public IIndexFragmentBinding getBinding() throws CoreException { return getPDOMBinding(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java index aebd345438e..b42e8137dcf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java @@ -14,6 +14,7 @@ import java.net.URI; import java.net.URISyntaxException; import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.internal.core.index.IndexFileLocation; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; 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 12ed4ae61de..e55468d5a08 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 @@ -28,8 +28,10 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; @@ -45,7 +47,7 @@ import org.eclipse.core.runtime.Status; * @author Doug Schaefer * */ -public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCompositeTypeScope, IPDOMMemberOwner, IIndexType { +public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCompositeTypeScope, IPDOMMemberOwner, IIndexType, IIndexScope { private static final int MEMBERLIST = PDOMBinding.RECORD_SIZE; private static final int KEY = MEMBERLIST + 4; // byte protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8; @@ -243,4 +245,8 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom } return null; } + + public IIndexBinding getScopeBinding() { + return this; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java index 56540671798..342c844cab9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java @@ -12,6 +12,9 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; @@ -49,17 +52,24 @@ abstract class PDOMCPPBinding extends PDOMBinding implements ICPPBinding { return false; } - // TODO: performance? final public char[][] getQualifiedNameCharArray() throws DOMException { - String[] preResult = getQualifiedName(); - char[][] result = new char[preResult.length][]; - for(int i=0; i