1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

169666: remove duplicate binding results from index queries, provide composite bindings

This commit is contained in:
Andrew Ferguson 2007-02-13 09:14:38 +00:00
parent 3ccc12e868
commit b130569488
79 changed files with 3303 additions and 548 deletions

View file

@ -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

View file

@ -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();

View file

@ -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());
}
}

View file

@ -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

View file

@ -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;
}
}
}

View file

@ -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

View file

@ -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; i<aEnumerators.length; i++){
actualEnumerators.add(aEnumerators[i].getName());
}
assertEquals(expectedEnumerators, actualEnumerators);
}
/**
*
* @param binding
* @param cqn
* @param qn may be null
*/
static protected void assertPTM(IType type, String cqn, String qn) {
try {
assertTrue(type instanceof ICPPPointerToMemberType);
ICPPPointerToMemberType ptmt = (ICPPPointerToMemberType) type;
ICPPClassType classType = ptmt.getMemberOfClass();
assertQNEquals(cqn, classType);
if(qn!=null) {
assert(ptmt.getType() instanceof ICPPBinding);
ICPPBinding tyBinding = (ICPPBinding) ptmt.getType();
assertQNEquals(qn, tyBinding);
}
} catch(DOMException de) {
fail(de.getMessage());
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation.
* Copyright (c) 2007 IBM Corporation.
* 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
@ -124,13 +124,13 @@ public class PDOMSearchTest extends PDOMTestBase {
/** result #1 * */
ICPPClassType class1 = (ICPPClassType) class1s[0];
assertEquals("Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class1)));
assertEquals("Class1", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(class1)));
IBinding[] methods = class1.getDeclaredMethods();
assertEquals(0, methods.length);
/** result #2 * */
ICPPClassType class2 = (ICPPClassType) class1s[1];
assertEquals("namespace1::Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class2)));
assertEquals("namespace1::Class1", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(class2)));
/* Members in this class */
@ -153,12 +153,12 @@ public class PDOMSearchTest extends PDOMTestBase {
/** result #3 * */
ICPPMethod method3 = (ICPPMethod) class1s[2];
assertEquals("namespace1::Class1::Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(method3)));
assertEquals("namespace1::Class1::Class1", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(method3)));
assertEquals(method3, methods[0]);
/** result #4 * */
ICPPClassType class4 = (ICPPClassType) class1s[3];
assertEquals("namespace1::namespace2::Class1", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(class4)));
assertEquals("namespace1::namespace2::Class1", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(class4)));
methods = class4.getDeclaredMethods();
assertEquals(0, methods.length);
@ -172,7 +172,7 @@ public class PDOMSearchTest extends PDOMTestBase {
/** result #1 * */
ICPPClassType cls1 = (ICPPClassType) class2s[0];
assertEquals("Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(cls1)));
assertEquals("Class2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(cls1)));
methods = cls1.getDeclaredMethods();
assertEquals(3, methods.length);
assertEquals("Class2", methods[0].getName());
@ -181,16 +181,16 @@ public class PDOMSearchTest extends PDOMTestBase {
/** result #2 * */
ICPPMethod meth2 = (ICPPMethod) class2s[1];
assertEquals("Class2::Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(meth2)));
assertEquals("Class2::Class2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(meth2)));
assertEquals(meth2, methods[0]);
/** result #3 * */
ICPPClassType cls3 = (ICPPClassType) class2s[2];
assertEquals("namespace1::Class1::Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(cls3)));
assertEquals("namespace1::Class1::Class2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(cls3)));
/** result #3 * */
ICPPClassType cls4 = (ICPPClassType) class2s[3];
assertEquals("namespace1::Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(cls4)));
assertEquals("namespace1::Class2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(cls4)));
/* Nested class references - namespace1::Class1::Class2 */
IName[] refs = pdom.findNames(cls3, IIndex.FIND_REFERENCES);
@ -212,12 +212,12 @@ public class PDOMSearchTest extends PDOMTestBase {
IBinding[] functions = pdom.findBindings(Pattern.compile("foo2"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, functions.length);
assertTrue(functions[0] instanceof ICPPFunction);
assertEquals("foo2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(functions[0])));
assertEquals("foo2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(functions[0])));
functions = pdom.findBindings(Pattern.compile("main"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, functions.length);
assertTrue(functions[0] instanceof ICPPFunction);
assertEquals("main", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(functions[0])));
assertEquals("main", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(functions[0])));
}
@ -226,7 +226,7 @@ public class PDOMSearchTest extends PDOMTestBase {
IBinding[] methods = pdom.findBindings(Pattern.compile("~Class2"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, methods.length);
assertTrue(methods[0] instanceof ICPPMethod);
assertEquals("Class2::~Class2", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(methods[0])));
assertEquals("Class2::~Class2", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(methods[0])));
}
@ -235,12 +235,12 @@ public class PDOMSearchTest extends PDOMTestBase {
IBinding[] fields = pdom.findBindings(Pattern.compile("class1x"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, fields.length);
assertTrue(fields[0] instanceof ICPPField);
assertEquals("namespace1::Class1::class1x", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(fields[0])));
assertEquals("namespace1::Class1::class1x", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(fields[0])));
fields = pdom.findBindings(Pattern.compile("class1y"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, fields.length);
assertTrue(fields[0] instanceof ICPPField);
assertEquals("namespace1::Class1::class1y", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(fields[0])));
assertEquals("namespace1::Class1::class1y", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(fields[0])));
}
@ -249,7 +249,7 @@ public class PDOMSearchTest extends PDOMTestBase {
IBinding[] variables = pdom.findBindings(Pattern.compile("var"), false, INDEX_FILTER, NULL_MONITOR);
assertEquals(1, variables.length);
assertTrue(variables[0] instanceof ICPPVariable);
assertEquals("var", getBindingQualifiedName(pdom.getLinkages()[0].adaptBinding(variables[0])));
assertEquals("var", getBindingQualifiedName(pdom.getLinkageImpls()[0].adaptBinding(variables[0])));
/* Variable references */
IName[] refs = pdom.findNames(variables[0], IIndex.FIND_REFERENCES);

View file

@ -39,8 +39,8 @@ public class PDOMTests extends TestSuite {
suite.addTest(MethodTests.suite());
suite.addTest(NamespaceTests.suite());
suite.addTest(IndexCBindingResolutionTest.suite());
suite.addTest(IndexCPPBindingResolutionTest.suite());
IndexCBindingResolutionTest.addTests(suite);
IndexCPPBindingResolutionTest.addTests(suite);
suite.addTest(IndexBindingResolutionBugs.suite());
suite.addTest(CFunctionTests.suite());

View file

@ -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.core.testplugin.util;
@ -20,10 +21,10 @@ import java.io.LineNumberReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -62,14 +63,13 @@ public class TestSourceReader {
* @throws IOException
*/
public static StringBuffer[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, final String testName, int sections) throws IOException {
IPath filePath= new Path(srcRoot + '/' + clazz.getName().replace('.', '/') + ".java");
String fqn = clazz.getName().replace('.', '/');
fqn = fqn.indexOf("$")==-1 ? fqn : fqn.substring(0,fqn.indexOf("$"));
IPath filePath= new Path(srcRoot + '/' + fqn + ".java");
InputStream in= FileLocator.openStream(bundle, filePath, false);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
final int OUT_COMMENT=0, IN_COMMENT=1;
int state = OUT_COMMENT;
LinkedList q;
List contents = new ArrayList();
StringBuffer content = new StringBuffer();
for(String line = br.readLine(); line!=null; line = br.readLine()) {
@ -90,6 +90,9 @@ public class TestSourceReader {
}
}
if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) {
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
}
throw new IOException("Test data not found for "+clazz+" "+testName);
}

View file

@ -13,7 +13,8 @@ bin.includes = plugin.xml,\
about.html,\
.,\
META-INF/,\
.options
.options,\
library.jar
src.includes = schema/,\
.options
javadoc.packages = org.eclipse.cdt.core.*,\
@ -32,4 +33,9 @@ source.. = src/,\
jre.compilation.profile=J2SE-1.4
javacSource=1.4
javacTarget=1.4
source.library.jar = model/,\
browser/,\
src/,\
utils/,\
parser/

View file

@ -251,15 +251,6 @@ public interface IIndex {
*/
public IIndexBinding[] findBindings(char[] name, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
/**
* Searches the given namespace for all bindings of a given name.
* In case a binding exists in multiple projects, no duplicate bindings are returned.
* @param nsbinding the namespace to be searched.
* @param name a simple (unqualified) name.
* @return an array of bindings
*/
public IBinding[] findInNamespace(IBinding nsbinding, char[] name);
/**
* Searches for all bindings with names that start with the given prefix.
* @param prefix the prefix with which all returned bindings must start
@ -267,7 +258,7 @@ public interface IIndex {
* @return an array of bindings with the prefix
* @throws CoreException
*/
public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException;
public IIndexBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException;
/**
* Searches for all names that resolve to the given binding. You can limit the result to references, declarations
@ -314,4 +305,15 @@ public interface IIndex {
* @throws CoreException
*/
public IIndexName[] findDefinitions(IBinding binding) throws CoreException;
/**
* Returns an IIndexBinding for this IIndex that is equivalent to the specified binding,
* or null if such a binding does not exist in this index. This is useful for adapting
* bindings obtained from IIndex objects that might have been created for a different scope
* or for IBinding objects obtained direct from the AST.
* @param binding
* @return an IIndexBinding for this IIndex that is equivalent to the specified binding
* @throws CoreException
*/
public IIndexBinding adaptBinding(IBinding binding);
}

View file

@ -8,9 +8,8 @@
* Contributors:
* Andrew Ferguson (Symbian) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.index.IIndexFileLocation;
/**
* Each IIndexFragment stores file location representations in an implementation specific manner.

View file

@ -18,6 +18,13 @@ public class Linkage implements ILinkage {
public static final ILinkage NO_LINKAGE = new Linkage(NO_LINKAGE_ID);
public static final ILinkage C_LINKAGE = new Linkage(C_LINKAGE_ID);
public static final ILinkage CPP_LINKAGE = new Linkage(CPP_LINKAGE_ID);
public static final ILinkage FORTRAN_LINKAGE = new Linkage(FORTRAN_LINKAGE_ID);
private static final ILinkage[] LINKAGES= {C_LINKAGE, CPP_LINKAGE, FORTRAN_LINKAGE};
public static final ILinkage[] getAllLinkages() {
return LINKAGES;
}
private String fID;
private Linkage(String id) {

View file

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
*******************************************************************************/
/*
* Created on Nov 29, 2004
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndex;
@ -109,9 +111,12 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode;
IASTName nsname = nsdef.getName();
IBinding nsbinding= nsname.resolveBinding();
if (nsbinding != null) {
IBinding[] bindings= index.findInNamespace(nsbinding, name.toCharArray());
binding= CPPSemantics.resolveAmbiguities(name, bindings);
if(nsbinding instanceof ICPPNamespace) {
ICPPNamespace nsbindingAdapted = (ICPPNamespace) index.adaptBinding(nsbinding);
if(nsbindingAdapted!=null) {
IBinding[] bindings = nsbindingAdapted.getNamespaceScope().find(name.toString());
binding= CPPSemantics.resolveAmbiguities(name, bindings);
}
}
}
}

View file

@ -9,6 +9,7 @@
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
*******************************************************************************/
/*
* Created on Dec 8, 2004
@ -130,6 +131,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException;
/**
@ -1029,7 +1031,7 @@ public class CPPSemantics {
mergeResults( data, b, true );
} else if (data.prefixLookup && data.astName != null) {
IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope);
if (parent == null && scope instanceof IIndexBinding) {
if (parent == null && scope instanceof IIndexScope) {
IBinding[] bindings = scope.find(data.astName.toString(), data.prefixLookup);
mergeResults(data, bindings, true);
} else if (scope instanceof ICPPNamespaceScope && !(scope instanceof ICPPBlockScope)) {
@ -1038,8 +1040,8 @@ public class CPPSemantics {
if (index != null) {
try {
IIndexBinding binding = index.findBinding(ns.getScopeName());
if (binding instanceof ICPPNamespaceScope) {
ICPPNamespaceScope indexNs = (ICPPNamespaceScope) binding;
if (binding instanceof ICPPNamespace) {
ICPPNamespaceScope indexNs = ((ICPPNamespace)binding).getNamespaceScope();
IBinding[] bindings = indexNs.find(data.astName.toString(), data.prefixLookup);
mergeResults(data, bindings, true);
}
@ -1138,7 +1140,7 @@ public class CPPSemantics {
private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
IScope parentScope= scope.getParent();
// the index cannot return the translation unit as parent scope
if (parentScope == null && scope instanceof IIndexBinding) {
if (parentScope == null && scope instanceof IIndexScope) {
parentScope= unit.getScope();
}
return parentScope;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
* Copyright (c) 2004, 2006, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/
/*
* Created on Nov 29, 2004
@ -145,6 +146,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
/**
* @author aniefer
@ -2051,7 +2053,7 @@ public class CPPVisitor {
private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
IScope parentScope= scope.getParent();
// the index cannot return the translation unit as parent scope
if (parentScope == null && scope instanceof IIndexBinding) {
if (parentScope == null && scope instanceof IIndexScope) {
parentScope= unit.getScope();
}
return parentScope;

View file

@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@ -22,6 +23,7 @@ import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -32,11 +34,22 @@ import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
import org.eclipse.cdt.internal.core.index.composite.c.CCompositesFactory;
import org.eclipse.cdt.internal.core.index.composite.cpp.CPPCompositesFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
public class CIndex implements IIndex {
/**
* If this constant is set, for logical index objects with only
* one fragment, composite binding wrappers will not be used.
*/
private static final boolean SPECIALCASE_SINGLES = true;
final private IIndexFragment[] fFragments;
final private int fPrimaryFragmentCount;
private int fReadLock;
@ -50,91 +63,18 @@ public class CIndex implements IIndex {
this(fragments, fragments.length);
}
public IIndexFragment[] getPrimaryFragments() {
IIndexFragment[] result= new IIndexFragment[fPrimaryFragmentCount];
System.arraycopy(fFragments, 0, result, 0, fPrimaryFragmentCount);
return result;
}
public IIndexBinding adaptBinding(IBinding binding) throws CoreException {
if (binding instanceof IIndexFragmentBinding) {
IIndexFragmentBinding fragBinding= (IIndexFragmentBinding) binding;
if (isFragment(fragBinding.getFragment())) {
return fragBinding;
}
}
for (int i = 0; i < fFragments.length; i++) {
IIndexProxyBinding result= fFragments[i].adaptBinding(binding);
if (result instanceof IIndexFragmentBinding) {
return (IIndexFragmentBinding) result;
}
}
return null;
}
public IIndexBinding findBinding(IName name) throws CoreException {
if (name instanceof IIndexFragmentName) {
return findBinding((IIndexFragmentName) name);
}
if (name instanceof IASTName) {
return findBinding((IASTName) name);
}
return null;
}
private IIndexBinding findBinding(IIndexFragmentName indexName) throws CoreException {
IIndexProxyBinding proxy= indexName.getBinding();
if (proxy instanceof IIndexFragmentBinding) {
IIndexFragmentBinding binding= (IIndexFragmentBinding) proxy;
if (isFragment(binding.getFragment())) {
return binding;
}
}
if (proxy != null) {
for (int i = 0; i < fFragments.length; i++) {
IIndexProxyBinding result= fFragments[i].adaptBinding(proxy);
if (result instanceof IIndexFragmentBinding) {
return (IIndexFragmentBinding) result;
}
}
}
return null;
}
private boolean isFragment(IIndexFragment frag) {
for (int i = 0; i < fFragments.length; i++) {
if (frag == fFragments[i]) {
return true;
}
}
return false;
}
private boolean isPrimaryFragment(IIndexFragment frag) {
for (int i = 0; i < fPrimaryFragmentCount; i++) {
if (frag == fFragments[i]) {
return true;
}
}
return false;
}
private IIndexBinding findBinding(IASTName astName) throws CoreException {
IIndexProxyBinding binding= null;
for (int i = 0; i < fFragments.length; i++) {
if (binding == null) {
binding= fFragments[i].findBinding(astName);
if (binding instanceof IIndexFragmentBinding) {
return (IIndexFragmentBinding) binding;
}
}
else {
IIndexProxyBinding alt= fFragments[i].adaptBinding(binding);
if (alt instanceof IIndexFragmentBinding) {
return (IIndexFragmentBinding) alt;
return adaptBinding(((IIndexFragmentName) name).getBinding());
} else if (name instanceof IASTName) {
if(SPECIALCASE_SINGLES && fFragments.length==1) {
return fFragments[0].findBinding((IASTName) name);
} else {
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentBinding binding= fFragments[i].findBinding((IASTName) name);
if(binding!=null) {
return getCompositesFactory(binding.getLinkage().getID()).getCompositeBinding(binding);
}
}
}
}
@ -146,33 +86,36 @@ public class CIndex implements IIndex {
}
public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
ArrayList result= new ArrayList();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length);
for (int i = 0; !monitor.isCanceled() && i < fFragments.length; i++) {
result.addAll(Arrays.asList(fFragments[i].findBindings(patterns, isFullyQualified, filter, new SubProgressMonitor(monitor, 1))));
if(SPECIALCASE_SINGLES && fFragments.length==1) {
return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor);
} else {
List result = new ArrayList();
ILinkage[] linkages = Linkage.getAllLinkages();
for(int j=0; j < linkages.length; j++) {
if(filter.acceptLinkage(linkages[j])) {
IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][];
for (int i = 0; i < fPrimaryFragmentCount; i++) {
try {
IBinding[] part = fFragments[i].findBindings(patterns, isFullyQualified, retargetFilter(linkages[j], filter), new SubProgressMonitor(monitor, 1));
fragmentBindings[i] = new IIndexFragmentBinding[part.length];
System.arraycopy(part, 0, fragmentBindings[i], 0, part.length);
} catch (CoreException e) {
CCorePlugin.log(e);
fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
}
ICompositesFactory factory = getCompositesFactory(linkages[j].getID());
result.add(factory.getCompositeBindings(fragmentBindings));
}
}
return flatten(result);
}
monitor.done();
return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]);
}
public IIndexBinding[] findBindings(char[] name, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
return findBindings(new char[][]{name}, filter, monitor);
}
public IIndexBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
ArrayList result= new ArrayList();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length);
for (int i = 0; !monitor.isCanceled() && i < fFragments.length; i++) {
result.addAll(Arrays.asList(fFragments[i].findBindings(names, filter, new SubProgressMonitor(monitor, 1))));
}
monitor.done();
return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]);
}
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
ArrayList result= new ArrayList();
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexProxyBinding adaptedBinding= fFragments[i].adaptBinding(binding);
IIndexFragmentBinding adaptedBinding= fFragments[i].adaptBinding(binding);
if (adaptedBinding != null) {
result.addAll(Arrays.asList(fFragments[i].findNames(adaptedBinding, flags)));
}
@ -193,11 +136,18 @@ public class CIndex implements IIndex {
}
public IIndexFile getFile(IIndexFileLocation location) throws CoreException {
IIndexFile result= null;
IIndexFile result= null, backup= null;
for (int i = 0; result==null && i < fPrimaryFragmentCount; i++) {
result= fFragments[i].getFile(location);
IIndexFragmentFile candidate= fFragments[i].getFile(location);
if(candidate!=null) {
if(candidate.hasNames()) {
result = candidate;
}
if(backup==null)
backup = candidate;
}
}
return result;
return result == null ? backup : result;
}
public IIndexFile resolveInclude(IIndexInclude include) throws CoreException {
@ -209,7 +159,7 @@ public class CIndex implements IIndex {
return result;
}
}
IIndexFileLocation location= include.getIncludesLocation();
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragment otherFrag = fFragments[i];
@ -226,7 +176,7 @@ public class CIndex implements IIndex {
public IIndexInclude[] findIncludedBy(IIndexFile file) throws CoreException {
return findIncludedBy(file, 0);
}
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException {
List result= new ArrayList();
findIncludedBy(Collections.singletonList(file), result, depth, new HashSet());
@ -258,12 +208,12 @@ public class CIndex implements IIndex {
}
findIncludedBy(nextLevel, out, depth, handled);
}
public IIndexInclude[] findIncludes(IIndexFile file) throws CoreException {
return findIncludes(file, 0);
}
public IIndexInclude[] findIncludes(IIndexFile file, int depth) throws CoreException {
List result= new ArrayList();
findIncludes(Collections.singletonList(file), result, depth, new HashSet());
@ -327,7 +277,7 @@ public class CIndex implements IIndex {
}
}
}
protected synchronized int getReadLockCount() {
return fReadLock;
}
@ -340,45 +290,166 @@ public class CIndex implements IIndex {
return result;
}
public IBinding[] findInNamespace(IBinding nsbinding, char[] name) {
ArrayList result= new ArrayList();
for (int i = 0; i < fFragments.length; i++) {
public IIndexBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
if(SPECIALCASE_SINGLES && fFragments.length==1) {
try {
IBinding[] part = fFragments[i].findInNamespace(nsbinding, name);
for (int j = 0; j < part.length; j++) {
IBinding binding = part[j];
if (binding instanceof IIndexBinding) {
result.add(binding);
}
}
if (!result.isEmpty()) {
return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]);
}
return fFragments[0].findBindings(names, filter, monitor);
} catch (CoreException e) {
CCorePlugin.log(e);
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
} else {
List result = new ArrayList();
ILinkage[] linkages = Linkage.getAllLinkages();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length * linkages.length);
for(int j=0; j < linkages.length; j++) {
if(filter.acceptLinkage(linkages[j])) {
IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][];
for (int i = 0; i < fPrimaryFragmentCount; i++) {
try {
IBinding[] part = fFragments[i].findBindings(names, retargetFilter(linkages[j], filter), new SubProgressMonitor(monitor, 1));
fragmentBindings[i] = new IIndexFragmentBinding[part.length];
System.arraycopy(part, 0, fragmentBindings[i], 0, part.length);
} catch (CoreException e) {
CCorePlugin.log(e);
fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
}
ICompositesFactory factory = getCompositesFactory(linkages[j].getID());
result.add(factory.getCompositeBindings(fragmentBindings));
}
}
monitor.done();
return flatten(result);
}
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
}
public IIndexBinding adaptBinding(IBinding binding) {
try {
if(SPECIALCASE_SINGLES && fFragments.length==1) {
return fFragments[0].adaptBinding(binding);
} else {
return getCompositesFactory(binding.getLinkage().getID()).getCompositeBinding(binding);
}
} catch(CoreException ce) {
CCorePlugin.log(ce);
return null;
}
}
public IIndexBinding[] findBindings(char[] name, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
return findBindings(new char[][]{name}, filter, monitor);
}
/*
* Non-API
*/
private IIndexBinding[] flatten(List bindingArrays) {
int size = 0;
for(int i=0; i<bindingArrays.size(); i++) {
size += ((IBinding[])bindingArrays.get(i)).length;
}
IIndexBinding[] result = new IIndexBinding[size];
int offset = 0;
for(int i=0; i<bindingArrays.size(); i++) {
IBinding[] src = (IBinding[]) bindingArrays.get(i);
System.arraycopy(src, 0, result, offset, src.length);
offset += src.length;
}
return result;
}
public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException {
ArrayList result= new ArrayList();
for (int i = 0; i < fFragments.length; i++) {
try {
IBinding[] part = fFragments[i].findBindingsForPrefix(prefix, filter);
for (int j = 0; j < part.length; j++) {
IBinding binding = part[j];
if (binding instanceof IIndexBinding) {
result.add(binding);
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
public IIndexFragment[] getPrimaryFragments() {
IIndexFragment[] result= new IIndexFragment[fPrimaryFragmentCount];
System.arraycopy(fFragments, 0, result, 0, fPrimaryFragmentCount);
return result;
}
private boolean isPrimaryFragment(IIndexFragment frag) {
for (int i = 0; i < fPrimaryFragmentCount; i++) {
if (frag == fFragments[i]) {
return true;
}
}
if (!result.isEmpty()) {
return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]);
return false;
}
public IIndexFragmentBinding[] findEquivalentBindings(IBinding binding) throws CoreException {
List result = new ArrayList();
for (int i = 0; i < fFragments.length; i++) {
IIndexFragmentBinding adapted = fFragments[i].adaptBinding(binding);
if (adapted instanceof IIndexFragmentBinding) {
result.add(adapted);
}
}
return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]);
}
ICompositesFactory cppCF, cCF, fCF;
private ICompositesFactory getCompositesFactory(String linkageID) {
if(linkageID.equals(ILinkage.CPP_LINKAGE_ID)) {
if(cppCF==null) {
cppCF = new CPPCompositesFactory(new CIndex(fFragments, fFragments.length));
}
return cppCF;
}
if(linkageID.equals(ILinkage.C_LINKAGE_ID)) {
if(cCF==null) {
cCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length));
}
return cCF;
}
if(linkageID.equals(ILinkage.FORTRAN_LINKAGE_ID)) {
if(fCF==null) {
fCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length));
}
// This is a placeholder - it will throw CompositingNotImplementedError
// if non-empty (non-c) results are returned by a fragment
return fCF;
}
throw new CompositingNotImplementedError();
}
private IndexFilter retargetFilter(final ILinkage linkage, final IndexFilter filter) {
return new IndexFilter() {
public boolean acceptBinding(IBinding binding) {
return filter.acceptBinding(binding);
}
public boolean acceptImplicitMethods() {
return filter.acceptImplicitMethods();
};
public boolean acceptLinkage(ILinkage other) {
return linkage.getID().equals(other.getID());
}
};
}
public IIndexBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException {
if(SPECIALCASE_SINGLES && fFragments.length==1) {
return fFragments[0].findBindingsForPrefix(prefix, filter);
} else {
List result = new ArrayList();
ILinkage[] linkages = Linkage.getAllLinkages();
for(int j=0; j < linkages.length; j++) {
if(filter.acceptLinkage(linkages[j])) {
IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][];
for (int i = 0; i < fPrimaryFragmentCount; i++) {
try {
IBinding[] part = fFragments[i].findBindingsForPrefix(prefix, retargetFilter(linkages[j], filter));
fragmentBindings[i] = new IIndexFragmentBinding[part.length];
System.arraycopy(part, 0, fragmentBindings[i], 0, part.length);
} catch (CoreException e) {
CCorePlugin.log(e);
fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
}
ICompositesFactory factory = getCompositesFactory(linkages[j].getID());
result.add(factory.getCompositeBindings(fragmentBindings));
}
}
return flatten(result);
}
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
}
}

View file

@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@ -93,15 +94,15 @@ final public class EmptyCIndex implements IIndex {
public IIndexBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
public IBinding[] findInNamespace(IBinding nsbinding, char[] name) {
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
}
public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) {
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
public IIndexBinding adaptBinding(IBinding binding) {
return null;
}
public IIndexBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) {
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
}
public IIndexBinding[] findBindings(char[][] names, IndexFilter filter,
IProgressMonitor monitor) {
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;

View file

@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@ -18,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@ -75,7 +77,7 @@ public interface IIndexFragment {
* @return the binding, or <code>null</code>
* @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 <code>null</code>, if no
@ -84,7 +86,7 @@ public interface IIndexFragment {
* @return the binding, or <code>null</code>
* @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 <code>null</code>, if no
@ -93,7 +95,7 @@ public interface IIndexFragment {
* @return the binding for the name, or <code>null</code>
* @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();
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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()]) );
}
}

View file

@ -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<result.length; i++)
result[i] = getCompositeBinding(bindings[i]);
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getComposites(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.internal.core.index.IIndexFragmentBinding[][])
*/
public final IIndexBinding[] getCompositeBindings(IIndexFragmentBinding[][] fragmentBindings) {
return getCompositeBindings(mergeBindingArrays(fragmentBindings));
}
/**
* Convenience method for taking a group of binding arrays, and returning a single array
* with the each binding appearing once
* @param fragmentBindings
* @return an array of unique bindings
*/
protected static IIndexFragmentBinding[] mergeBindingArrays(IIndexFragmentBinding[][] fragmentBindings) {
TreeSet ts = new TreeSet();
for(int i=0; i<fragmentBindings.length; i++)
for(int j=0; j<fragmentBindings[i].length; j++)
ts.add(fragmentBindings[i][j]);
return (IIndexFragmentBinding[]) ts.toArray(new IIndexFragmentBinding[ts.size()]);
}
/**
* Convenience method for finding a binding with a definition in the specified index
* context, which is equivalent to the specified binding
* @param index
* @param binding
* @return
*/
protected IIndexFragmentBinding findOneDefinition(IBinding binding) {
try{
CIndex cindex = (CIndex) index;
IIndexFragmentBinding[] ibs = cindex.findEquivalentBindings(binding);
IBinding def = ibs[0];
for(int i=0; i<ibs.length; i++) {
if(ibs[i].hasDefinition()) {
def = ibs[i];
}
}
return (IIndexFragmentBinding) def;
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
throw new CompositingNotImplementedError();
}
}

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* 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.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
public class CompositeArrayType extends CompositeType implements IArrayType, ITypeContainer {
public CompositeArrayType(IArrayType arrayType, ICompositesFactory cf) {
super((ITypeContainer) arrayType, cf);
}
public IASTExpression getArraySizeExpression() throws DOMException {
fail(); return null;
}
}

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* 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.ILinkage;
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.index.IIndexBinding;
import org.eclipse.core.runtime.CoreException;
/**
* Represents a binding which is split over several index fragments.
* <p>
* 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;
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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$
}
}

View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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<result.length; i++)
result[i] = (IEnumerator) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
return result;
}
public boolean isSameType(IType type) {
return ((IEnumeration)rbinding).isSameType(type);
}
public Object clone() {fail(); return null;}
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* 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.IBinding;
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.composite.ICompositesFactory;
class CompositeCEnumerator extends CompositeCBinding implements IIndexBinding, IEnumerator {
public CompositeCEnumerator(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public IType getType() throws DOMException {
return cf.getCompositeType(((IEnumerator)rbinding).getType());
}
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* 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.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCField extends CompositeCVariable implements IIndexBinding, IField {
public CompositeCField(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public ICompositeType getCompositeTypeOwner() throws DOMException {
IBinding preresult = ((IField)rbinding).getCompositeTypeOwner();
return (ICompositeType) cf.getCompositeBinding(preresult);
}
}

View file

@ -0,0 +1,90 @@
/*******************************************************************************
* 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
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;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCFunction extends CompositeCBinding implements IIndexBinding, IFunction {
public CompositeCFunction(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public IScope getFunctionScope() throws DOMException {fail(); return null;}
public IParameter[] getParameters() throws DOMException {
IParameter[] preResult = ((IFunction)rbinding).getParameters();
IParameter[] result = new IParameter[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = (IParameter) cf.getCompositeBinding((IIndexFragmentBinding) preResult[i]);
}
return result;
}
public IFunctionType getType() throws DOMException {
/* @see PDOMCFunction.getType() */
return new IFunctionType() {
public IType[] getParameterTypes() throws DOMException {
IType[] preresult = ((IFunctionType)rbinding).getParameterTypes();
IType[] result = new IType[preresult.length];
for(int i=0; i<preresult.length; i++) {
assert preresult!=null;
result[i] = cf.getCompositeType(preresult[i]);
}
return result;
}
public IType getReturnType() throws DOMException {
IType type = ((IFunctionType)rbinding).getReturnType();
return cf.getCompositeType(type);
}
public boolean isSameType(IType type) {
return ((IFunctionType)rbinding).isSameType(type);
}
public Object clone() {fail(); return null;}
};
}
public boolean isAuto() throws DOMException {
return ((IFunction)rbinding).isAuto();
}
public boolean isExtern() throws DOMException {
return ((IFunction)rbinding).isExtern();
}
public boolean isInline() throws DOMException {
return ((IFunction)rbinding).isInline();
}
public boolean isRegister() throws DOMException {
return ((IFunction)rbinding).isRegister();
}
public boolean isStatic() throws DOMException {
return ((IFunction)rbinding).isStatic();
}
public boolean takesVarArgs() throws DOMException {
return ((IFunction)rbinding).takesVarArgs();
}
}

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCParameter extends CompositeCBinding implements IIndexBinding, IParameter {
public CompositeCParameter(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public IType getType() throws DOMException {
IType rtype = ((IEnumerator)rbinding).getType();
return cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {
return ((IParameter)rbinding).isAuto();
}
public boolean isExtern() throws DOMException {
return ((IParameter)rbinding).isExtern();
}
public boolean isRegister() throws DOMException {
return ((IParameter)rbinding).isRegister();
}
public boolean isStatic() throws DOMException {
return ((IParameter)rbinding).isStatic();
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* 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.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField;
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;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCStructure extends CompositeCBinding implements IIndexBinding, ICompositeType, IIndexType {
public CompositeCStructure(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public IField findField(String name) throws DOMException {
IField preresult = ((ICompositeType)rbinding).findField(name);
return (IField) cf.getCompositeBinding((IIndexFragmentBinding) preresult);
}
public IScope getCompositeScope() throws DOMException {
return new CompositeCCompositeScope(cf, rbinding);
}
public IField[] getFields() throws DOMException {
IField[] result = ((ICompositeType)rbinding).getFields();
for(int i=0; i<result.length; i++)
result[i] = (IField) cf.getCompositeBinding((IIndexFragmentBinding)result[i]);
return result;
}
public int getKey() throws DOMException {
return ((ICompositeType)rbinding).getKey();
}
public boolean isSameType(IType type) {
return ((ICompositeType)rbinding).isSameType(type);
}
public Object clone() {fail(); return null;}
}

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCTypedef extends CompositeCBinding implements ITypedef, IIndexType, ITypeContainer {
public CompositeCTypedef(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public IType getType() throws DOMException {
IType type = ((ITypedef)rbinding).getType();
return cf.getCompositeType(type);
}
public boolean isSameType(IType type) {
return ((ITypedef)rbinding).isSameType(type);
}
public Object clone() {
fail(); return null;
}
public void setType(IType type) {
fail();
}
}

View file

@ -0,0 +1,47 @@
/*******************************************************************************
* 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCVariable extends CompositeCBinding implements IIndexBinding, IVariable {
public CompositeCVariable(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public IType getType() throws DOMException {
IType rtype = ((IVariable)rbinding).getType();
return cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {
return ((IVariable)rbinding).isAuto();
}
public boolean isExtern() throws DOMException {
return ((IVariable)rbinding).isExtern();
}
public boolean isRegister() throws DOMException {
return ((IVariable)rbinding).isRegister();
}
public boolean isStatic() throws DOMException {
return ((IVariable)rbinding).isStatic();
}
}

View file

@ -0,0 +1,175 @@
/*******************************************************************************
* 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.cpp;
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.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
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.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.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
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.cdt.internal.core.index.IIndexFragmentName;
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;
import org.eclipse.core.runtime.CoreException;
public class CPPCompositesFactory extends AbstractCompositeFactory implements ICompositesFactory {
public CPPCompositesFactory(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) throws DOMException {
IScope result;
if(rscope == null) {
return null;
} else if(rscope instanceof ICPPClassScope) {
ICPPClassScope classScope = (ICPPClassScope) rscope;
result = new CompositeCPPClassScope(this,
findOneDefinition(classScope.getClassType()));
} else if(rscope instanceof ICPPNamespaceScope) {
ICPPNamespaceScope nScope = (ICPPNamespaceScope) rscope;
try {
IBinding binding = ((IIndexFragmentName) nScope.getScopeName()).getBinding();
result = ((ICPPNamespace)binding).getNamespaceScope();
} catch(CoreException ce) {
CCorePlugin.log(ce);
throw new CompositingNotImplementedError(ce.getMessage());
}
} else {
throw new CompositingNotImplementedError();
}
return result;
}
/* (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 instanceof ICPPClassType) {
result = (ICPPClassType) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if(rtype instanceof ITypedef) {
result = new CompositeCPPTypedef(this, (ICPPBinding) rtype);
} else if (rtype instanceof IEnumeration) {
result = (IEnumeration) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if(rtype instanceof ICPPPointerToMemberType) {
result = new CompositeCPPPointerToMemberType(this, (ICPPPointerToMemberType)rtype);
} else if(rtype instanceof IPointerType) {
result = new CompositePointerType((IPointerType)rtype, this);
} else if(rtype instanceof ICPPReferenceType) {
result = new CompositeCPPReferenceType((ICPPReferenceType)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 == null) {
result = null;
} 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;
}
private ICPPNamespace[] getNamespaces(IBinding rbinding) throws CoreException {
CIndex cindex = (CIndex) index;
IIndexBinding[] ibs = cindex.findEquivalentBindings(rbinding);
ICPPNamespace[] namespaces = new ICPPNamespace[ibs.length];
for(int i=0; i<namespaces.length; i++)
namespaces[i] = (ICPPNamespace) ibs[i];
return namespaces;
}
/* (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 binding) {
IIndexBinding result;
try {
if(binding==null) {
result = null;
} else if(binding instanceof ICPPParameter) {
result = new CompositeCPPParameter(this, (ICPPParameter) binding);
} else if(binding instanceof ICPPField) {
result = new CompositeCPPField(this, (ICPPField) binding);
} else if(binding instanceof ICPPVariable) {
result = new CompositeCPPVariable(this, (ICPPVariable) binding);
} else if(binding instanceof ICPPClassType) {
ICPPClassType def = (ICPPClassType) findOneDefinition(binding);
result = def == null ? null : new CompositeCPPClassType(this, def);
} else if(binding instanceof ICPPConstructor) {
result = new CompositeCPPConstructor(this, (ICPPConstructor) binding);
} else if(binding instanceof ICPPMethod) {
result = new CompositeCPPMethod(this, (ICPPMethod) binding);
} else if(binding instanceof ICPPNamespaceAlias) {
result = new CompositeCPPNamespaceAlias(this, (ICPPNamespaceAlias) binding);
} else if(binding instanceof ICPPNamespace) {
ICPPNamespace[] ns = getNamespaces(binding);
result = ns.length == 0 ? null : new CompositeCPPNamespace(this, ns);
} else if(binding instanceof IEnumeration) {
IEnumeration def = (IEnumeration) findOneDefinition(binding);
result = def == null ? null : new CompositeCPPEnumeration(this, def);
} else if(binding instanceof ICPPFunction) {
result = new CompositeCPPFunction(this, (ICPPFunction) binding);
} else if(binding instanceof IEnumerator) {
result = new CompositeCPPEnumerator(this, (IEnumerator) binding);
} else if(binding instanceof ITypedef) {
result = new CompositeCPPTypedef(this, (ICPPBinding) binding);
} else {
throw new CompositingNotImplementedError("composite binding unavailable for "+binding+" "+binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
}
} catch(CoreException ce) {
CCorePlugin.log(ce);
throw new CompositingNotImplementedError(ce.getMessage());
}
return result;
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
* 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.cpp;
import java.util.Arrays;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.CompositeIndexBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
abstract class CompositeCPPBinding extends CompositeIndexBinding implements ICPPBinding {
public CompositeCPPBinding(ICompositesFactory cf, ICPPBinding rbinding) {
super(cf, (IIndexFragmentBinding) rbinding);
}
public boolean hasQualifiedName(char[][] qname) {
boolean result = true;
try {
char[][] myQN = getQualifiedNameCharArray();
result &= qname.length == myQN.length;
for(int i=0; result && i<qname.length; i++) {
char[] qnamePart = qname[i];
result &= Arrays.equals(qnamePart, myQN[i]);
}
} catch(DOMException de) {
CCorePlugin.log(de);
return false;
}
return result;
}
public String[] getQualifiedName() {
try {
return ((ICPPBinding)rbinding).getQualifiedName();
} catch(DOMException de) {
CCorePlugin.log(de);
return new String[0];
}
}
public char[][] getQualifiedNameCharArray() throws DOMException {
return ((ICPPBinding)rbinding).getQualifiedNameCharArray();
}
public boolean isGloballyQualified() throws DOMException {
return ((ICPPBinding)rbinding).isGloballyQualified();
}
}

View file

@ -0,0 +1,81 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.CCorePlugin;
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.IProblemBinding;
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.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding;
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 CompositeCPPClassScope extends CompositeScope implements ICPPClassScope {
public CompositeCPPClassScope(ICompositesFactory cf, IBinding rbinding) {
super(cf, rbinding);
}
public ICPPClassType getClassType() {
return (ICPPClassType) cf.getCompositeBinding(rbinding);
}
public ICPPMethod[] getImplicitMethods() {
try {
ICPPClassScope rscope = (ICPPClassScope) ((ICPPClassType)rbinding).getCompositeScope();
ICPPMethod[] result = rscope.getImplicitMethods();
for(int i=0; i<result.length; i++) {
result[i] = (ICPPMethod) cf.getCompositeBinding(result[i]);
}
return result;
} catch (DOMException de) {
CCorePlugin.log(de);
}
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IBinding binding = ((ICPPClassType)rbinding).getCompositeScope().getBinding(name, resolve);
if(binding instanceof IIndexFragmentBinding) {
return cf.getCompositeBinding((IIndexFragmentBinding) binding);
}
if(binding instanceof CPPCompositeBinding /* AST composite */) {
return new CPPCompositeBinding(
cf.getCompositeBindings(((CPPCompositeBinding)binding).getBindings())
);
}
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 = ((ICPPClassType)rbinding).getCompositeScope().find(name, prefixLookup);
return cf.getCompositeBindings(preresult);
}
public IBinding[] find(String name) throws DOMException {
IBinding[] preresult = ((ICPPClassType)rbinding).getCompositeScope().find(name);
return cf.getCompositeBindings(preresult);
}
public IIndexBinding getScopeBinding() {
return (IIndexBinding) getClassType();
}
}

View file

@ -0,0 +1,149 @@
/*******************************************************************************
* 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.cpp;
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.IField;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType, IIndexType {
public CompositeCPPClassType(ICompositesFactory cf, ICPPClassType rbinding) {
super(cf, rbinding);
}
public Object clone() {
fail(); return null;
}
public IField findField(String name) throws DOMException {
IField preResult = ((ICPPClassType)rbinding).findField(name);
return (IField) cf.getCompositeBinding(preResult);
}
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
ICPPMethod[] preResult = ((ICPPClassType)rbinding).getAllDeclaredMethods();
ICPPMethod[] result = new ICPPMethod[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = (ICPPMethod) cf.getCompositeBinding(preResult[i]);
}
return result;
}
public ICPPBase[] getBases() throws DOMException {
final ICPPBase[] preresult = ((ICPPClassType)rbinding).getBases();
ICPPBase[] result = new ICPPBase[preresult.length];
for(int i=0; i<preresult.length; i++) {
final int n = i;
result[i] = new ICPPBase() {
public IBinding getBaseClass() throws DOMException {
return cf.getCompositeBinding(preresult[n].getBaseClass());
}
public int getVisibility() throws DOMException {
return preresult[n].getVisibility();
}
public boolean isVirtual() throws DOMException {
return preresult[n].isVirtual();
}
public IName getBaseClassSpecifierName() {
return preresult[n].getBaseClassSpecifierName();
}
};
}
return result;
}
public ICPPConstructor[] getConstructors() throws DOMException {
ICPPConstructor[] preResult = ((ICPPClassType)rbinding).getConstructors();
ICPPConstructor[] result = new ICPPConstructor[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = (ICPPConstructor) cf.getCompositeBinding(preResult[i]);
}
return result;
}
public ICPPField[] getDeclaredFields() throws DOMException {
ICPPField[] preResult = ((ICPPClassType)rbinding).getDeclaredFields();
ICPPField[] result = new ICPPField[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = (ICPPField) cf.getCompositeBinding(preResult[i]);
}
return result;
}
public ICPPMethod[] getDeclaredMethods() throws DOMException {
ICPPMethod[] preResult = ((ICPPClassType)rbinding).getDeclaredMethods();
ICPPMethod[] result = new ICPPMethod[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = (ICPPMethod) cf.getCompositeBinding(preResult[i]);
}
return result;
}
public IField[] getFields() throws DOMException {
IField[] preResult = ((ICPPClassType)rbinding).getFields();
IField[] result = new IField[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = (IField) cf.getCompositeBinding(preResult[i]);
}
return result;
}
public IBinding[] getFriends() throws DOMException {
IBinding[] preResult = ((ICPPClassType)rbinding).getFriends();
IBinding[] result = new IBinding[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = cf.getCompositeBinding(preResult[i]);
}
return result;
}
public ICPPMethod[] getMethods() throws DOMException {
ICPPMethod[] result = ((ICPPClassType)rbinding).getMethods();
for(int i=0; i<result.length; i++) {
result[i] = (ICPPMethod) cf.getCompositeBinding(result[i]);
}
return result;
}
public ICPPClassType[] getNestedClasses() throws DOMException {
ICPPClassType[] preResult = ((ICPPClassType)rbinding).getNestedClasses();
ICPPClassType[] result = new ICPPClassType[preResult.length];
for(int i=0; i<preResult.length; i++) {
result[i] = (ICPPClassType) cf.getCompositeBinding(preResult[i]);
}
return result;
}
public IScope getCompositeScope() throws DOMException {
return new CompositeCPPClassScope(cf, rbinding);
}
public int getKey() throws DOMException {
return ((ICPPClassType)rbinding).getKey();
}
public boolean isSameType(IType type) {
return ((ICPPClassType)rbinding).isSameType(type);
}
}

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPConstructor extends CompositeCPPMethod implements ICPPConstructor {
public CompositeCPPConstructor(ICompositesFactory cf, ICPPFunction rbinding) {
super(cf, rbinding);
}
public boolean isExplicit() throws DOMException {
return ((ICPPConstructor)rbinding).isExplicit();
}
}

View file

@ -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.cpp;
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.dom.ast.cpp.ICPPBinding;
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 CompositeCPPEnumeration extends CompositeCPPBinding implements IEnumeration, IIndexType {
public CompositeCPPEnumeration(ICompositesFactory cf, IEnumeration rbinding) {
super(cf, (ICPPBinding) rbinding);
}
public IEnumerator[] getEnumerators() throws DOMException {
IEnumerator[] result = ((IEnumeration)rbinding).getEnumerators();
for(int i=0; i<result.length; i++)
result[i] = (IEnumerator) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
return result;
}
public boolean isSameType(IType type) {
return ((IEnumeration)rbinding).isSameType(type);
}
public Object clone() { fail(); return null; }
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPEnumerator extends CompositeCPPBinding implements IEnumerator {
public CompositeCPPEnumerator(ICompositesFactory cf, IEnumerator rbinding) {
super(cf, (ICPPBinding) rbinding);
}
public IType getType() throws DOMException {
IType type = ((IEnumerator)rbinding).getType();
return cf.getCompositeType(type);
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* 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.cpp;
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.IField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPField extends CompositeCPPVariable implements ICPPField {
public CompositeCPPField(ICompositesFactory cf, ICPPField rbinding) {
super(cf, rbinding);
}
public ICPPClassType getClassOwner() throws DOMException {
IIndexFragmentBinding rowner = (IIndexFragmentBinding) ((ICPPField)rbinding).getClassOwner();
return (ICPPClassType) cf.getCompositeBinding(rowner);
}
public int getVisibility() throws DOMException {
return ((ICPPField)rbinding).getVisibility();
}
public ICompositeType getCompositeTypeOwner() throws DOMException {
IBinding preresult = ((IField)rbinding).getCompositeTypeOwner();
return (ICompositeType) cf.getCompositeBinding(preresult);
}
}

View file

@ -0,0 +1,112 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
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 CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction, ICPPFunctionType, IIndexType {
public CompositeCPPFunction(ICompositesFactory cf, ICPPFunction rbinding) {
super(cf, rbinding);
}
public boolean isInline() throws DOMException {
return ((ICPPFunction)rbinding).isInline();
}
public boolean isMutable() throws DOMException {
return ((ICPPFunction)rbinding).isMutable();
}
public IScope getFunctionScope() throws DOMException {
fail(); return null;
}
public IParameter[] getParameters() throws DOMException {
IParameter[] result = ((ICPPFunction)rbinding).getParameters();
for(int i=0; i<result.length; i++) {
result[i] = (IParameter) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
}
return result;
}
public IFunctionType getType() throws DOMException {
return this;
}
public boolean isAuto() throws DOMException {
return ((ICPPFunction)rbinding).isAuto();
}
public boolean isExtern() throws DOMException {
return ((ICPPFunction)rbinding).isExtern();
}
public boolean isRegister() throws DOMException {
return ((ICPPFunction)rbinding).isRegister();
}
public boolean isStatic() throws DOMException {
return ((ICPPFunction)rbinding).isStatic();
}
public boolean takesVarArgs() throws DOMException {
return ((ICPPFunction)rbinding).takesVarArgs();
}
public boolean isConst() {
return ((ICPPFunctionType)rbinding).isConst();
}
public boolean isVolatile() {
return ((ICPPFunctionType)rbinding).isVolatile();
}
public IType[] getParameterTypes() throws DOMException {
IType[] result = ((ICPPFunctionType)rbinding).getParameterTypes();
for(int i=0; i<result.length; i++) {
result[i] = cf.getCompositeType(result[i]);
}
return result;
}
public IType getReturnType() throws DOMException {
return cf.getCompositeType(((ICPPFunctionType)rbinding).getReturnType());
}
public boolean isSameType(IType type) {
return ((ICPPFunctionType)rbinding).isSameType(type);
}
public Object clone() {
fail(); return null;
}
public String toString() {
StringBuffer result = new StringBuffer();
try {
result.append(getName()+" "+ASTTypeUtil.getParameterTypeString(getType())); //$NON-NLS-1$
} catch(DOMException de) {
result.append(de);
}
return result.toString();
}
}

View file

@ -0,0 +1,46 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPMethod extends CompositeCPPFunction implements ICPPMethod {
public CompositeCPPMethod(ICompositesFactory cf, ICPPFunction rbinding) {
super(cf, rbinding);
}
public boolean isDestructor() throws DOMException {
return ((ICPPMethod)rbinding).isDestructor();
}
public boolean isImplicit() {
return ((ICPPMethod)rbinding).isImplicit();
}
public boolean isVirtual() throws DOMException {
return ((ICPPMethod)rbinding).isVirtual();
}
public ICPPClassType getClassOwner() throws DOMException {
IIndexFragmentBinding rowner = (IIndexFragmentBinding) ((ICPPMethod)rbinding).getClassOwner();
return (ICPPClassType) cf.getCompositeBinding(rowner);
}
public int getVisibility() throws DOMException {
return ((ICPPMethod)rbinding).getVisibility();
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2006 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPNamespace extends CompositeCPPBinding implements ICPPNamespace {
ICPPNamespace[] namespaces;
public CompositeCPPNamespace(ICompositesFactory cf, ICPPNamespace[] namespaces) {
super(cf, namespaces[0]);
this.namespaces = namespaces;
}
public IBinding[] getMemberBindings() throws DOMException {
IIndexFragmentBinding[][] memberBindings = new IIndexFragmentBinding[namespaces.length][];
for(int i=0; i<namespaces.length; i++) {
IBinding[] bindings = namespaces[i].getMemberBindings();
memberBindings[i] = new IIndexFragmentBinding[bindings.length];
System.arraycopy(bindings, 0, memberBindings[i], 0, bindings.length);
}
return cf.getCompositeBindings(memberBindings);
}
public ICPPNamespaceScope getNamespaceScope() throws DOMException {
return new CompositeCPPNamespaceScope(cf, namespaces);
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPNamespaceAlias extends CompositeCPPBinding implements ICPPNamespaceAlias {
public CompositeCPPNamespaceAlias(ICompositesFactory cf, ICPPNamespaceAlias alias) {
super(cf, alias);
}
public IBinding[] getMemberBindings() throws DOMException {
fail(); return null;
}
public ICPPNamespaceScope getNamespaceScope() throws DOMException {
fail(); return null;
}
public IBinding getBinding() {
IIndexFragmentBinding ns = (IIndexFragmentBinding) ((ICPPNamespaceAlias)rbinding).getBinding();
return cf.getCompositeBinding(ns);
}
public int getDelegateType() {
fail(); return 0;
}
}

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
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.ICompositesFactory;
class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespaceScope {
ICPPNamespace[] namespaces;
public CompositeCPPNamespaceScope(ICompositesFactory cf, ICPPNamespace[] namespaces) {
super(cf, namespaces[0]);
this.namespaces = namespaces;
}
public void addUsingDirective(IASTNode directive) throws DOMException {
fail();
}
public IASTNode[] getUsingDirectives() throws DOMException {
return new IASTNode[0]; // same behaviour as PDOMCPPNamespace
}
public IBinding getBinding(IASTName name, boolean resolve)
throws DOMException {
IIndexFragmentBinding preresult = null;
for(int i=0; preresult==null && i<namespaces.length; i++) {
preresult = (IIndexFragmentBinding) namespaces[i].getNamespaceScope().getBinding(name, resolve);
}
return cf.getCompositeBinding(preresult);
}
final public IBinding[] find(String name) throws DOMException {
IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
for(int i=0; i<namespaces.length; i++) {
IBinding[] raw = namespaces[i].getNamespaceScope().find(name);
preresult[i] = new IIndexFragmentBinding[raw.length];
System.arraycopy(raw, 0, preresult[i], 0, raw.length);
}
return cf.getCompositeBindings(preresult);
}
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
for(int i=0; i<namespaces.length; i++) {
IBinding[] raw = namespaces[i].getNamespaceScope().find(name, prefixLookup);
preresult[i] = new IIndexFragmentBinding[raw.length];
System.arraycopy(raw, 0, preresult[i], 0, raw.length);
}
return cf.getCompositeBindings(preresult);
}
public IIndexBinding getScopeBinding() {
return cf.getCompositeBinding(rbinding);
}
}

View file

@ -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.cpp;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPParameter extends CompositeCPPVariable implements ICPPParameter {
public CompositeCPPParameter(ICompositesFactory cf, ICPPVariable rbinding) {
super(cf, rbinding);
}
public boolean hasDefaultValue() {
return ((ICPPParameter)rbinding).hasDefaultValue();
}
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPPointerToMemberType extends CompositePointerType implements IIndexType, ICPPPointerToMemberType {
CompositeCPPPointerToMemberType(ICompositesFactory cf, ICPPPointerToMemberType pointerToMemberType) throws DOMException {
super(pointerToMemberType, cf);
}
public ICPPClassType getMemberOfClass() {
IIndexFragmentBinding rbinding = (IIndexFragmentBinding) ((ICPPPointerToMemberType) type).getMemberOfClass();
return (ICPPClassType) cf.getCompositeBinding(rbinding);
}
}

View file

@ -0,0 +1,23 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.composite.CompositeType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPReferenceType extends CompositeType implements ICPPReferenceType {
public CompositeCPPReferenceType(ICPPReferenceType referenceType, ICompositesFactory cf) throws DOMException {
super((ITypeContainer) referenceType, cf);
}
}

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPTypedef extends CompositeCPPBinding implements ITypedef, IIndexType, ITypeContainer {
public CompositeCPPTypedef(ICompositesFactory cf, ICPPBinding delegate) {
super(cf, delegate);
}
public IType getType() throws DOMException {
IType type = ((ITypedef)rbinding).getType();
return cf.getCompositeType(type);
}
public boolean isSameType(IType type) {
return ((ITypedef)rbinding).isSameType(type);
}
public Object clone() {
fail(); return null;
}
public void setType(IType type) {
fail();
}
}

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* 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.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPVariable extends CompositeCPPBinding implements ICPPVariable {
public CompositeCPPVariable(ICompositesFactory cf, ICPPVariable delegate) {
super(cf, delegate);
}
public boolean isMutable() throws DOMException {
return ((ICPPVariable)rbinding).isMutable();
}
public IType getType() throws DOMException {
IType rtype = ((ICPPVariable)rbinding).getType();
return cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {
return ((ICPPVariable)rbinding).isAuto();
}
public boolean isExtern() throws DOMException {
return ((ICPPVariable)rbinding).isExtern();
}
public boolean isRegister() throws DOMException {
return ((ICPPVariable)rbinding).isRegister();
}
public boolean isStatic() throws DOMException {
return ((ICPPVariable)rbinding).isStatic();
}
}

View file

@ -9,6 +9,7 @@
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
@ -24,20 +25,18 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
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.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.LanguageManager;
@ -46,11 +45,9 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.index.IIndexProxyBinding;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
import org.eclipse.cdt.internal.core.pdom.dom.IIndexLocationConverter;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
@ -236,7 +233,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
public IIndexProxyBinding findBinding(IASTName name) throws CoreException {
public IIndexFragmentBinding findBinding(IASTName name) throws CoreException {
PDOMLinkage linkage= adaptLinkage(name.getLinkage());
if (linkage != null) {
return linkage.resolveBinding(name);
@ -419,7 +416,12 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
return db.getInt(LINKAGES);
}
public PDOMLinkage[] getLinkages() {
public IIndexLinkage[] getLinkages() {
Collection values = fLinkageIDCache.values();
return (IIndexLinkage[]) values.toArray(new IIndexLinkage[values.size()]);
}
public PDOMLinkage[] getLinkageImpls() {
Collection values = fLinkageIDCache.values();
return (PDOMLinkage[]) values.toArray(new PDOMLinkage[values.size()]);
}
@ -445,6 +447,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
private int lockCount;
private int waitingReaders;
private long lastWriteAccess= 0;
private long lastReadAccess= 0;
public void acquireReadLock() throws InterruptedException {
synchronized (mutex) {
@ -459,6 +462,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public void releaseReadLock() {
synchronized (mutex) {
assert lockCount > 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()]);
}
}

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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();
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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<preResult.length; i++) {
result[i] = preResult[i].toCharArray();
List result = new ArrayList();
try {
PDOMNode node = this;
while (node != null) {
if (node instanceof PDOMBinding) {
result.add(0, ((PDOMBinding)node).getName().toCharArray());
}
node = node.getParentNode();
}
return (char[][]) result.toArray(new char[result.size()][]);
} catch(CoreException ce) {
CCorePlugin.log(ce);
return null;
}
return result;
}
public boolean isGloballyQualified() throws DOMException {
throw new PDOMNotImplementedError();
}
}
}

View file

@ -35,11 +35,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
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.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
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;
@ -55,7 +57,7 @@ import org.eclipse.core.runtime.CoreException;
*
*/
class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
ICPPClassScope, IPDOMMemberOwner, IIndexType {
ICPPClassScope, IPDOMMemberOwner, IIndexType, IIndexScope {
private static final int FIRSTBASE = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 4; // byte
@ -491,4 +493,8 @@ ICPPClassScope, IPDOMMemberOwner, IIndexType {
base.delete();
}
}
public IIndexBinding getScopeBinding() {
return this;
}
}

View file

@ -238,39 +238,39 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction
}
try {
if (type instanceof ICPPFunctionType) {
ICPPFunctionType ft = (ICPPFunctionType) type;
IType rt1= getReturnType();
IType rt2= ft.getReturnType();
if (rt1 != rt2) {
if (rt1 == null || !rt1.isSameType(rt2)) {
return false;
}
}
if (type instanceof ICPPFunctionType) {
ICPPFunctionType ft = (ICPPFunctionType) type;
IType rt1= getReturnType();
IType rt2= ft.getReturnType();
if (rt1 != rt2) {
if (rt1 == null || !rt1.isSameType(rt2)) {
return false;
}
}
IType[] params1= getParameterTypes();
IType[] params2= ft.getParameterTypes();
if( params1.length == 1 && params2.length == 0 ){
if( !(params1[0] instanceof IBasicType) || ((IBasicType)params1[0]).getType() != IBasicType.t_void )
return false;
} else if( params2.length == 1 && params1.length == 0 ){
if( !(params2[0] instanceof IBasicType) || ((IBasicType)params2[0]).getType() != IBasicType.t_void )
return false;
} else if( params1.length != params2.length ){
return false;
} else {
for( int i = 0; i < params1.length; i++ ){
if (params1[i] == null || ! params1[i].isSameType( params2[i] ) )
return false;
}
}
if( isConst() != ft.isConst() || isVolatile() != ft.isVolatile() )
return false;
return true;
}
return false;
IType[] params1= getParameterTypes();
IType[] params2= ft.getParameterTypes();
if( params1.length == 1 && params2.length == 0 ){
if( !(params1[0] instanceof IBasicType) || ((IBasicType)params1[0]).getType() != IBasicType.t_void )
return false;
} else if( params2.length == 1 && params1.length == 0 ){
if( !(params2[0] instanceof IBasicType) || ((IBasicType)params2[0]).getType() != IBasicType.t_void )
return false;
} else if( params1.length != params2.length ){
return false;
} else {
for( int i = 0; i < params1.length; i++ ){
if (params1[i] == null || ! params1[i].isSameType( params2[i] ) )
return false;
}
}
if( isConst() != ft.isConst() || isVolatile() != ft.isVolatile() )
return false;
return true;
}
return false;
} catch (DOMException e) {
}
return false;
@ -285,7 +285,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction
if(types[0] instanceof IBasicType) {
if(((IBasicType)types[0]).getType()==IBasicType.t_void) {
types = new IType[0];
}
}
}
}
StringBuffer result = new StringBuffer();
@ -304,4 +304,33 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction
IType[] params = type.getParameterTypes();
return getSignatureMemento(params);
}
public int compareTo(Object other) {
int cmp = super.compareTo(other);
if(cmp==0) {
if(other instanceof PDOMCPPFunction) {
try {
PDOMCPPFunction otherFunction = (PDOMCPPFunction) other;
int mySM = getSignatureMemento();
int otherSM = otherFunction.getSignatureMemento();
return mySM == otherSM ? 0 : mySM < otherSM ? -1 : 1;
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
} else {
throw new PDOMNotImplementedError();
}
}
return cmp;
}
public String toString() {
StringBuffer result = new StringBuffer();
try {
result.append(getName()+" "+ASTTypeUtil.getParameterTypeString(getType())); //$NON-NLS-1$
} catch(DOMException de) {
result.append(de);
}
return result.toString();
}
}

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.index.IIndexScope;
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.IBTreeVisitor;
@ -39,7 +40,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer
*
*/
class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPNamespaceScope {
class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPNamespaceScope, IIndexScope {
private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0;
@ -157,4 +158,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
}
public void addUsingDirective(IASTNode directive) throws DOMException {fail();}
public IIndexBinding getScopeBinding() {
return this;
}
}

View file

@ -18,9 +18,10 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IParameter;
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.cpp.ICPPParameter;
import org.eclipse.cdt.internal.core.Util;
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.dom.PDOMNamedNode;
@ -33,7 +34,7 @@ import org.eclipse.core.runtime.CoreException;
*
* @author Doug Schaefer
*/
class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IIndexFragmentBinding {
/**
* Offset of pointer to the next parameter (relative to the
@ -114,7 +115,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
return rec != 0 ? new PDOMCPPParameter(pdom, rec) : null;
}
public String[] getQualifiedName() throws DOMException {
public String[] getQualifiedName() {
throw new PDOMNotImplementedError();
}
@ -193,4 +194,21 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
}
return defValue;
}
public IIndexFragment getFragment() {
return pdom;
}
public boolean hasDefinition() throws CoreException {
// parameter bindings do not span index fragments
return true;
}
public int compareTo(Object arg0) {
throw new PDOMNotImplementedError();
}
public boolean isFileLocal() throws CoreException {
return true;
}
}

View file

@ -58,12 +58,16 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
if (typeNode != null)
db.putInt(record + TYPE_OFFSET, typeNode.getRecord());
db.putByte(record + ANNOTATIONS, PDOMCPPAnnotation.encodeAnnotation(variable));
db.putByte(record + ANNOTATIONS, encodeFlags(variable));
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
protected byte encodeFlags(ICPPVariable variable) throws DOMException {
return PDOMCPPAnnotation.encodeAnnotation(variable);
}
public PDOMCPPVariable(PDOM pdom, int record) {
super(pdom, record);
}

View file

@ -14,6 +14,9 @@ package org.eclipse.cdt.ui.tests.typehierarchy;
import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
@ -47,6 +50,10 @@ public class TypeHierarchyAcrossProjectsTest extends TypeHierarchyBaseTest {
super.setUp();
fCProject2= CProjectHelper.createCCProject("__thTest_2__", "bin", IPDOMManager.ID_FAST_INDEXER);
IProjectDescription desc= fCProject2.getProject().getDescription();
desc.setReferencedProjects(new IProject[]{fCProject.getProject()});
fCProject2.getProject().setDescription(desc, new NullProgressMonitor());
CCoreInternals.getPDOMManager().reindex(fCProject2);
fIndex= CCorePlugin.getIndexManager().getIndex(new ICProject[] {fCProject, fCProject2});
TestScannerProvider.sIncludes= new String[]{fCProject.getProject().getLocation().toOSString(), fCProject2.getProject().getLocation().toOSString()};
@ -82,7 +89,7 @@ public class TypeHierarchyAcrossProjectsTest extends TypeHierarchyBaseTest {
// int field4;
// int method4();
// };
public void _testSimpleInheritanceAcross() throws Exception {
public void testSimpleInheritanceAcross() throws Exception {
StringBuffer[] content= getContentsForTest(2);
String header= content[0].toString();
String source = content[1].toString();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 QNX Software Systems and others.
* Copyright (c) 2005, 2006, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX - Initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
@ -190,7 +191,7 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
return new Object[0];
}
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
PDOMLinkage[] linkages= pdom.getLinkages();
PDOMLinkage[] linkages= pdom.getLinkageImpls();
if (linkages.length == 1) {
// Skip linkages in hierarchy if there is only one
return getChildren(linkages[0]);
@ -224,7 +225,7 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
return false;
}
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
PDOMLinkage[] linkages = pdom.getLinkages();
PDOMLinkage[] linkages = pdom.getLinkageImpls();
if (linkages.length == 0)
return false;
else if (linkages.length == 1)