1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Introduces an API to access the PDOM, bug 149565.

This commit is contained in:
Markus Schorn 2006-10-12 13:23:56 +00:00
parent 1b927015bb
commit f5a4ba1d76
159 changed files with 3946 additions and 1393 deletions

View file

@ -15,6 +15,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -56,21 +60,29 @@ public class PDOMDependencyCalculator implements IManagedDependencyCalculator {
if (resource != null) { if (resource != null) {
ICProject project = CoreModel.getDefault().create(resource.getProject()); ICProject project = CoreModel.getDefault().create(resource.getProject());
try { try {
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project); IIndex index= CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES);
PDOMFile file = pdom.getFile(resource.getLocation()); index.acquireReadLock();
if (file != null) { try {
PDOMFile[] includes = file.getAllIncludes(); IIndexFile file = index.getFile(resource.getLocation());
if (file != null) {
IIndexInclude[] includes = index.findIncludes(file, IIndex.DEPTH_INFINITE);
List/*<IPath>*/ list = new ArrayList/*<IPath>*/(); List/*<IPath>*/ list = new ArrayList/*<IPath>*/();
for (int i = 0; i < includes.length; ++i) for (int i = 0; i < includes.length; ++i)
list.add(new Path(includes[i].getFileName().getString())); list.add(new Path(includes[i].getIncludesLocation()));
dependencies = (IPath[])list.toArray(new IPath[list.size()]); dependencies = (IPath[])list.toArray(new IPath[list.size()]);
} else } else
dependencies = new IPath[0]; dependencies = new IPath[0];
}
finally {
index.releaseReadLock();
}
} catch (CoreException e) { } catch (CoreException e) {
// Activator.getDefault().getLog().log(e.getStatus()); // Activator.getDefault().getLog().log(e.getStatus());
dependencies = new IPath[0]; dependencies = new IPath[0];
} catch (InterruptedException e) {
dependencies = new IPath[0];
} }
} else } else
dependencies = new IPath[0]; dependencies = new IPath[0];

View file

@ -98,7 +98,7 @@ public class CModelElementsTests extends TestCase {
//ITranslationUnit included = (ITranslationUnit)CoreModel.getDefault().create(includedFile); //ITranslationUnit included = (ITranslationUnit)CoreModel.getDefault().create(includedFile);
// parse the translation unit to get the elements tree // parse the translation unit to get the elements tree
tu.parse(); // tu.parse();
// tu ---> include // tu ---> include
checkInclude(tu); checkInclude(tu);

View file

@ -57,7 +57,7 @@ public class IIncludeTests extends IntegratedCModelTest {
return suite; return suite;
} }
public void testGetIncludeName() public void testGetIncludeName() throws CModelException
{ {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
IInclude[] theIncludes = null; IInclude[] theIncludes = null;
@ -100,7 +100,7 @@ public class IIncludeTests extends IntegratedCModelTest {
} }
public void testIsStandard() public void testIsStandard() throws CModelException
{ {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
IInclude[] theIncludes = null; IInclude[] theIncludes = null;

View file

@ -318,7 +318,7 @@ public class IStructureTests extends IntegratedCModelTest {
} }
// IInheritance // IInheritance
public void testGetBaseTypes() { public void testGetBaseTypes() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
ICElement myElementDerived = null; ICElement myElementDerived = null;
String[] myBaseTypes = null; String[] myBaseTypes = null;
@ -345,7 +345,7 @@ public class IStructureTests extends IntegratedCModelTest {
} }
// IInheritance // IInheritance
public void testGetAccessControl() { public void testGetAccessControl() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
ICElement myElementDerived = null; ICElement myElementDerived = null;
String[] myBaseTypes = null; String[] myBaseTypes = null;
@ -390,7 +390,7 @@ public class IStructureTests extends IntegratedCModelTest {
// Language Specification Tests // Language Specification Tests
// //
public void testAnonymousStructObject() { public void testAnonymousStructObject() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
ICElement myElement = null; ICElement myElement = null;
try { try {

View file

@ -20,6 +20,7 @@ import java.io.FileNotFoundException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
@ -87,7 +88,7 @@ public abstract class IntegratedCModelTest extends TestCase {
CProjectHelper.delete(fCProject); CProjectHelper.delete(fCProject);
} }
protected ITranslationUnit getTU() { protected ITranslationUnit getTU() throws CModelException {
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(sourceFile); ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(sourceFile);
if(isStructuralParse()) { if(isStructuralParse()) {
CCorePlugin.getDefault().setStructuralParseMode(true); CCorePlugin.getDefault().setStructuralParseMode(true);
@ -96,7 +97,8 @@ public abstract class IntegratedCModelTest extends TestCase {
} }
// parse the translation unit to get the elements tree // parse the translation unit to get the elements tree
// Force the parsing now to do this in the right ParseMode. // Force the parsing now to do this in the right ParseMode.
tu.parse(); tu.close();
tu.open(new NullProgressMonitor());
CCorePlugin.getDefault().setStructuralParseMode(false); CCorePlugin.getDefault().setStructuralParseMode(false);
return tu; return tu;
} }

View file

@ -96,13 +96,10 @@ public class StructuralCModelElementsTests extends TestCase {
public void testCModelElements() throws CModelException{ public void testCModelElements() throws CModelException{
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(headerFile); ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(headerFile);
//ITranslationUnit included = (ITranslationUnit)CoreModel.getDefault().create(includedFile);
// turn on the structural parse mode // turn on the structural parse mode
tu.close();
CCorePlugin.getDefault().setStructuralParseMode(true); CCorePlugin.getDefault().setStructuralParseMode(true);
// parse the translation unit to get the elements tree
tu.parse();
// tu ---> include // tu ---> include
checkInclude(tu); checkInclude(tu);

View file

@ -54,21 +54,21 @@ public class StructuralStructureTests extends IStructureTests {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.tests.IStructureTests#testAnonymousStructObject() * @see org.eclipse.cdt.core.model.tests.IStructureTests#testAnonymousStructObject()
*/ */
public void testAnonymousStructObject() { public void testAnonymousStructObject() throws CModelException {
setStructuralParse(true); setStructuralParse(true);
super.testAnonymousStructObject(); super.testAnonymousStructObject();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.tests.IStructureTests#testGetAccessControl() * @see org.eclipse.cdt.core.model.tests.IStructureTests#testGetAccessControl()
*/ */
public void testGetAccessControl() { public void testGetAccessControl() throws CModelException {
setStructuralParse(true); setStructuralParse(true);
super.testGetAccessControl(); super.testGetAccessControl();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.tests.IStructureTests#testGetBaseTypes() * @see org.eclipse.cdt.core.model.tests.IStructureTests#testGetBaseTypes()
*/ */
public void testGetBaseTypes() { public void testGetBaseTypes() throws CModelException {
setStructuralParse(true); setStructuralParse(true);
super.testGetBaseTypes(); super.testGetBaseTypes();
} }

View file

@ -27,9 +27,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -162,7 +162,7 @@ public class DOMSearchUtil {
} }
IBinding binding = searchName.resolveBinding(); IBinding binding = searchName.resolveBinding();
if (binding instanceof PDOMBinding) { if (binding instanceof IIndexBinding) {
Assert.fail("Not implemented"); Assert.fail("Not implemented");
// try { // try {
// ArrayList pdomNames = new ArrayList(); // ArrayList pdomNames = new ArrayList();

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
@ -39,7 +40,7 @@ public class DOMSelectionParseBaseTest extends DOMFileBasePluginTest {
protected IASTNode parse(IFile file, int offset1, int offset2, boolean expectedToPass) throws Exception { protected IASTNode parse(IFile file, int offset1, int offset2, boolean expectedToPass) throws Exception {
ITranslationUnit tu = (ITranslationUnit)CCorePlugin.getDefault().getCoreModel().create(file); ITranslationUnit tu = (ITranslationUnit)CCorePlugin.getDefault().getCoreModel().create(file);
IASTTranslationUnit ast = tu.getLanguage().getASTTranslationUnit(tu, 0); IASTTranslationUnit ast = tu.getAST();
IASTName[] names = tu.getLanguage().getSelectedNames(ast, offset1, offset2 - offset1); IASTName[] names = tu.getLanguage().getSelectedNames(ast, offset1, offset2 - offset1);
if (!expectedToPass) return null; if (!expectedToPass) return null;

View file

@ -22,6 +22,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
@ -47,21 +49,21 @@ public class ClassTests extends PDOMTestBase {
} }
public void test1() throws Exception { public void test1() throws Exception {
IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), new NullProgressMonitor()); IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, Bs.length); assertEquals(1, Bs.length);
ICPPClassType B = (ICPPClassType)Bs[0]; ICPPClassType B = (ICPPClassType)Bs[0];
ICPPMethod[] Bmethods = B.getAllDeclaredMethods(); ICPPMethod[] Bmethods = B.getAllDeclaredMethods();
assertEquals(1, Bmethods.length); assertEquals(1, Bmethods.length);
ICPPMethod Bf = Bmethods[0]; ICPPMethod Bf = Bmethods[0];
assertEquals("f", Bf.getName()); assertEquals("f", Bf.getName());
IName [] Bf_refs = pdom.getReferences(Bf); IName [] Bf_refs = pdom.findNames(Bf, IIndex.FIND_REFERENCES);
assertEquals(1, Bf_refs.length); assertEquals(1, Bf_refs.length);
IASTFileLocation loc = Bf_refs[0].getFileLocation(); IASTFileLocation loc = Bf_refs[0].getFileLocation();
assertEquals(offset("class.cpp", "b.f()") + 2, loc.getNodeOffset()); assertEquals(offset("class.cpp", "b.f()") + 2, loc.getNodeOffset());
} }
public void testNested() throws Exception { public void testNested() throws Exception {
IBinding[] bindings = pdom.findBindings(Pattern.compile("NestedA"), new NullProgressMonitor()); IBinding[] bindings = pdom.findBindings(Pattern.compile("NestedA"), false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
ICPPClassType NestedA = (ICPPClassType)bindings[0]; ICPPClassType NestedA = (ICPPClassType)bindings[0];
ICPPClassType[] nested = NestedA.getNestedClasses(); ICPPClassType[] nested = NestedA.getNestedClasses();
@ -72,24 +74,24 @@ public class ClassTests extends PDOMTestBase {
assertEquals(1, fields.length); assertEquals(1, fields.length);
IField NestedB_x = fields[0]; IField NestedB_x = fields[0];
IName[] refs = pdom.getReferences(NestedB); IName[] refs = pdom.findNames(NestedB, IIndex.FIND_REFERENCES);
assertEquals(1, refs.length); assertEquals(1, refs.length);
IASTFileLocation loc = refs[0].getFileLocation(); IASTFileLocation loc = refs[0].getFileLocation();
assertEquals(offset("nested.cpp", "::NestedB") + 2, loc.getNodeOffset()); assertEquals(offset("nested.cpp", "::NestedB") + 2, loc.getNodeOffset());
refs = pdom.getReferences(NestedB_x); refs = pdom.findNames(NestedB_x, IIndex.FIND_REFERENCES);
assertEquals(1, refs.length); assertEquals(1, refs.length);
loc = refs[0].getFileLocation(); loc = refs[0].getFileLocation();
assertEquals(offset("nested.cpp", "x.x") + 2, loc.getNodeOffset()); assertEquals(offset("nested.cpp", "x.x") + 2, loc.getNodeOffset());
} }
public void failedTest147903() throws Exception { public void failedTest147903() throws Exception {
IBinding[] bindings = pdom.findBindings(Pattern.compile("pr147903"), new NullProgressMonitor()); IBinding[] bindings = pdom.findBindings(Pattern.compile("pr147903"), false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
ICPPNamespaceScope ns = ((ICPPNamespace)bindings[0]).getNamespaceScope(); ICPPNamespaceScope ns = ((ICPPNamespace)bindings[0]).getNamespaceScope();
bindings = ns.find("testRef"); bindings = ns.find("testRef");
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
IName[] refs = pdom.getReferences(bindings[0]); IName[] refs = pdom.findNames(bindings[0], IIndex.FIND_REFERENCES);
for (int i = 0; i < refs.length; ++i) for (int i = 0; i < refs.length; ++i)
System.out.println(refs[i].getFileLocation().getNodeOffset()); System.out.println(refs[i].getFileLocation().getNodeOffset());
assertEquals(5, refs.length); assertEquals(5, refs.length);

View file

@ -19,6 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
@ -46,7 +48,7 @@ public class EnumerationTests extends PDOMTestBase {
public void testC() throws Exception { public void testC() throws Exception {
// Check bindings // Check bindings
Pattern pattern = Pattern.compile("TestCEnum"); Pattern pattern = Pattern.compile("TestCEnum");
IBinding[] bindings = pdom.findBindings(pattern, new NullProgressMonitor()); IBinding[] bindings = pdom.findBindings(pattern, false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
IEnumeration enumeration = (IEnumeration)bindings[0]; IEnumeration enumeration = (IEnumeration)bindings[0];
assertEquals("TestCEnum", enumeration.getName()); assertEquals("TestCEnum", enumeration.getName());
@ -57,19 +59,19 @@ public class EnumerationTests extends PDOMTestBase {
assertEquals("cc", enumerators[2].getName()); assertEquals("cc", enumerators[2].getName());
// Declaration of TestEnum // Declaration of TestEnum
IName[] enumDecls = pdom.getDeclarations(enumeration); IName[] enumDecls = pdom.findNames(enumeration, IIndex.FIND_DECLARATIONS_DEFINITIONS);
assertEquals(1, enumDecls.length); assertEquals(1, enumDecls.length);
IASTFileLocation loc = enumDecls[0].getFileLocation(); IASTFileLocation loc = enumDecls[0].getFileLocation();
assertEquals(5, loc.getNodeOffset()); assertEquals(5, loc.getNodeOffset());
// Reference to TestEnum // Reference to TestEnum
IName[] enumRefs = pdom.getReferences(enumeration); IName[] enumRefs = pdom.findNames(enumeration, IIndex.FIND_REFERENCES);
assertEquals(1, enumRefs.length); assertEquals(1, enumRefs.length);
loc = enumRefs[0].getFileLocation(); loc = enumRefs[0].getFileLocation();
assertEquals(offset("enumTest.c", "TestCEnum test"), loc.getNodeOffset()); assertEquals(offset("enumTest.c", "TestCEnum test"), loc.getNodeOffset());
// Reference to a // Reference to a
IName[] aRefs = pdom.getReferences(enumerators[0]); IName[] aRefs = pdom.findNames(enumerators[0], IIndex.FIND_REFERENCES);
assertEquals(1, aRefs.length); assertEquals(1, aRefs.length);
loc = aRefs[0].getFileLocation(); loc = aRefs[0].getFileLocation();
assertEquals(offset("enumTest.c", "ca;"), loc.getNodeOffset()); assertEquals(offset("enumTest.c", "ca;"), loc.getNodeOffset());
@ -78,7 +80,7 @@ public class EnumerationTests extends PDOMTestBase {
public void testCPP() throws Exception { public void testCPP() throws Exception {
// Check bindings // Check bindings
Pattern pattern = Pattern.compile("TestCPPEnum"); Pattern pattern = Pattern.compile("TestCPPEnum");
IBinding[] bindings = pdom.findBindings(pattern, new NullProgressMonitor()); IBinding[] bindings = pdom.findBindings(pattern, false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
IEnumeration enumeration = (IEnumeration)bindings[0]; IEnumeration enumeration = (IEnumeration)bindings[0];
assertEquals("TestCPPEnum", enumeration.getName()); assertEquals("TestCPPEnum", enumeration.getName());
@ -89,19 +91,19 @@ public class EnumerationTests extends PDOMTestBase {
assertEquals("cppc", enumerators[2].getName()); assertEquals("cppc", enumerators[2].getName());
// Declaration of TestEnum // Declaration of TestEnum
IName[] enumDecls = pdom.getDeclarations(enumeration); IName[] enumDecls = pdom.findNames(enumeration, IIndex.FIND_DECLARATIONS_DEFINITIONS);
assertEquals(1, enumDecls.length); assertEquals(1, enumDecls.length);
IASTFileLocation loc = enumDecls[0].getFileLocation(); IASTFileLocation loc = enumDecls[0].getFileLocation();
assertEquals(5, loc.getNodeOffset()); assertEquals(5, loc.getNodeOffset());
// Reference to TestEnum // Reference to TestEnum
IName[] enumRefs = pdom.getReferences(enumeration); IName[] enumRefs = pdom.findNames(enumeration, IIndex.FIND_REFERENCES);
assertEquals(1, enumRefs.length); assertEquals(1, enumRefs.length);
loc = enumRefs[0].getFileLocation(); loc = enumRefs[0].getFileLocation();
assertEquals(offset("enumTest.cpp", "TestCPPEnum test"), loc.getNodeOffset()); assertEquals(offset("enumTest.cpp", "TestCPPEnum test"), loc.getNodeOffset());
// Reference to a // Reference to a
IName[] aRefs = pdom.getReferences(enumerators[0]); IName[] aRefs = pdom.findNames(enumerators[0], IIndex.FIND_REFERENCES);
assertEquals(1, aRefs.length); assertEquals(1, aRefs.length);
loc = aRefs[0].getFileLocation(); loc = aRefs[0].getFileLocation();
assertEquals(offset("enumTest.cpp", "cppa;"), loc.getNodeOffset()); assertEquals(offset("enumTest.cpp", "cppa;"), loc.getNodeOffset());

View file

@ -11,9 +11,10 @@
package org.eclipse.cdt.internal.pdom.tests; package org.eclipse.cdt.internal.pdom.tests;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
/** /**
@ -23,12 +24,12 @@ import org.eclipse.core.runtime.IPath;
public class IncludesTests extends PDOMTestBase { public class IncludesTests extends PDOMTestBase {
protected ICProject project; protected ICProject project;
protected PDOM pdom; protected IIndex pdom;
protected void setUp() throws Exception { protected void setUp() throws Exception {
if (pdom == null) { if (pdom == null) {
project = createProject("includesTests"); project = createProject("includesTests");
pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project); pdom = CCorePlugin.getIndexManager().getIndex(project);
} }
pdom.acquireReadLock(); pdom.acquireReadLock();
} }
@ -39,9 +40,9 @@ public class IncludesTests extends PDOMTestBase {
public void test1() throws Exception { public void test1() throws Exception {
IPath loc = project.getProject().getLocation().append("I2.h"); IPath loc = project.getProject().getLocation().append("I2.h");
PDOMFile file = pdom.getFile(loc.toOSString()); IIndexFile file = pdom.getFile(loc);
assertNotNull(file); assertNotNull(file);
PDOMFile[] allIncludedBy = file.getAllIncludedBy(); IIndexInclude[] allIncludedBy = pdom.findIncludedBy(file, -1);
assertEquals(9, allIncludedBy.length); // i.e. all of them assertEquals(9, allIncludedBy.length); // i.e. all of them
} }

View file

@ -22,6 +22,8 @@ import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
@ -48,7 +50,7 @@ public class TypesTests extends PDOMTestBase {
public void testC() throws Exception { public void testC() throws Exception {
// Get the binding for A::f // Get the binding for A::f
IBinding [] CAs = pdom.findBindings(Pattern.compile("CA"), new NullProgressMonitor()); IBinding [] CAs = pdom.findBindings(Pattern.compile("CA"), false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, CAs.length); assertEquals(1, CAs.length);
ICompositeType CA = (ICompositeType)CAs[0]; ICompositeType CA = (ICompositeType)CAs[0];
IField [] CAfields = CA.getFields(); IField [] CAfields = CA.getFields();
@ -57,7 +59,7 @@ public class TypesTests extends PDOMTestBase {
assertEquals("x", x.getName()); assertEquals("x", x.getName());
// Make sure that there is a reference in g(); // Make sure that there is a reference in g();
IName[] xRefs = pdom.getReferences(x); IName[] xRefs = pdom.findNames(x, IIndex.FIND_REFERENCES);
assertEquals(1, xRefs.length); assertEquals(1, xRefs.length);
IASTFileLocation loc = xRefs[0].getFileLocation(); IASTFileLocation loc = xRefs[0].getFileLocation();
assertEquals(offset("typedef.c", "x->x") + 3, loc.getNodeOffset()); assertEquals(offset("typedef.c", "x->x") + 3, loc.getNodeOffset());
@ -65,7 +67,7 @@ public class TypesTests extends PDOMTestBase {
public void testCPP() throws Exception { public void testCPP() throws Exception {
// Get the binding for A::f // Get the binding for A::f
IBinding [] As = pdom.findBindings(Pattern.compile("A"), new NullProgressMonitor()); IBinding [] As = pdom.findBindings(Pattern.compile("A"), false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, As.length); assertEquals(1, As.length);
ICPPClassType A = (ICPPClassType)As[0]; ICPPClassType A = (ICPPClassType)As[0];
ICPPMethod[] Amethods = A.getMethods(); ICPPMethod[] Amethods = A.getMethods();
@ -74,17 +76,17 @@ public class TypesTests extends PDOMTestBase {
assertEquals("f", f.getName()); assertEquals("f", f.getName());
// Make sure that there is a reference in g(); // Make sure that there is a reference in g();
IName[] fRefs = pdom.getReferences(f); IName[] fRefs = pdom.findNames(f, IIndex.FIND_REFERENCES);
assertEquals(1, fRefs.length); assertEquals(1, fRefs.length);
IASTFileLocation loc = fRefs[0].getFileLocation(); IASTFileLocation loc = fRefs[0].getFileLocation();
assertEquals(offset("typedef.cpp", "x->f") + 3, loc.getNodeOffset()); assertEquals(offset("typedef.cpp", "x->f") + 3, loc.getNodeOffset());
} }
public void test145351() throws Exception { public void test145351() throws Exception {
IBinding [] bindings = pdom.findBindings(Pattern.compile("spinlock_t"), new NullProgressMonitor()); IBinding [] bindings = pdom.findBindings(Pattern.compile("spinlock_t"), false, new IndexFilter(), new NullProgressMonitor());
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
ITypedef spinlock_t = (ITypedef)bindings[0]; ITypedef spinlock_t = (ITypedef)bindings[0];
IName [] refs = pdom.getReferences(spinlock_t); IName [] refs = pdom.findNames(spinlock_t, IIndex.FIND_REFERENCES);
assertEquals(1, refs.length); assertEquals(1, refs.length);
IASTFileLocation loc = refs[0].getFileLocation(); IASTFileLocation loc = refs[0].getFileLocation();
assertEquals(offset("bug145351.c", "spinlock_t global_bh_lock"), loc.getNodeOffset()); assertEquals(offset("bug145351.c", "spinlock_t global_bh_lock"), loc.getNodeOffset());

View file

@ -1,3 +1,5 @@
#Mon Oct 09 11:18:42 BST 2006 #Tue Oct 10 16:32:29 CEST 2006
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//parser/org/eclipse/cdt/internal/core/index/messages.properties=8859_1
encoding//parser/org/eclipse/cdt/internal/core/pdom/db/messages.properties=8859_1 encoding//parser/org/eclipse/cdt/internal/core/pdom/db/messages.properties=8859_1
encoding//parser/org/eclipse/cdt/internal/core/pdom/messages.properties=8859_1

View file

@ -1,4 +1,4 @@
#Mon Jul 03 19:51:10 CEST 2006 #Thu Oct 05 16:52:57 CEST 2006
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4

View file

@ -0,0 +1,3 @@
#Thu Oct 05 16:52:57 CEST 2006
eclipse.preferences.version=1
internal.default.compliance=user

View file

@ -14,17 +14,17 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.IEnumeration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; 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.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -120,12 +120,12 @@ public class AllTypesCache {
return; return;
case ICElement.C_STRUCT: case ICElement.C_STRUCT:
if (node instanceof ICPPClassType if (node instanceof ICPPClassType
&& ((ICPPClassType)node).getKey() == ICPPClassType.k_struct) && ((ICPPClassType)node).getKey() == ICompositeType.k_struct)
types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project)); types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project));
return; return;
case ICElement.C_UNION: case ICElement.C_UNION:
if (node instanceof ICPPClassType if (node instanceof ICPPClassType
&& ((ICPPClassType)node).getKey() == ICPPClassType.k_union) && ((ICPPClassType)node).getKey() == ICompositeType.k_union)
types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project)); types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project));
return; return;
case ICElement.C_ENUMERATION: case ICElement.C_ENUMERATION:
@ -152,10 +152,15 @@ public class AllTypesCache {
CPPTypesCollector cppCollector = new CPPTypesCollector(kinds, types, project); CPPTypesCollector cppCollector = new CPPTypesCollector(kinds, types, project);
PDOM pdom = (PDOM)pdomManager.getPDOM(project); PDOM pdom = (PDOM)pdomManager.getPDOM(project);
PDOMLinkage cLinkage = pdom.getLinkage(GCCLanguage.getDefault()); PDOMLinkage linkage= pdom.getLinkage(ILinkage.C_LINKAGE_ID);
cLinkage.accept(cCollector); if (linkage != null) {
PDOMLinkage cppLinkage = pdom.getLinkage(GPPLanguage.getDefault()); linkage.accept(cCollector);
cppLinkage.accept(cppCollector); }
linkage= pdom.getLinkage(ILinkage.CPP_LINKAGE_ID);
if (linkage != null) {
linkage.accept(cppCollector);
}
} }
return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]); return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]);

View file

@ -15,13 +15,14 @@ package org.eclipse.cdt.core.browser;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMResolver;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -120,9 +121,8 @@ public class PDOMTypeInfo implements ITypeInfo {
public ITypeReference getResolvedReference() { public ITypeReference getResolvedReference() {
try { try {
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(project); PDOM pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
IPDOMResolver resolver = (IPDOMResolver) pdom.getAdapter(IPDOMResolver.class); IName[] names= pdom.findNames(binding, IIndex.FIND_DEFINITIONS);
IName[] names= resolver.getDefinitions(binding);
return names != null && names.length > 0 ? new PDOMTypeReference(names[0], project) : null; return names != null && names.length > 0 ? new PDOMTypeReference(names[0], project) : null;
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.model;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject;
/**
* Models the differences between various languages.
* @since 4.0
*/
public abstract class AbstractLanguage extends PlatformObject implements ILanguage {
final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException {
throw new UnsupportedOperationException();
}
final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, ICodeReaderFactory codeReaderFactory,
int style) throws CoreException {
throw new UnsupportedOperationException();
}
}

View file

@ -326,14 +326,8 @@ public class CoreModel {
*/ */
public static String getRegistedContentTypeId(IProject project, String name) { public static String getRegistedContentTypeId(IProject project, String name) {
IContentType contentType = CCorePlugin.getContentType(project, name); IContentType contentType = CCorePlugin.getContentType(project, name);
if (contentType != null) { if (contentType != null && LanguageManager.getInstance().getLanguage(contentType) != null) {
String id = contentType.getId(); return contentType.getId();
String[] ids = getRegistedContentTypeIds();
for (int i = 0; i < ids.length; i++) {
if (ids[i].equals(id)) {
return id;
}
}
} }
return null; return null;
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.model; package org.eclipse.cdt.core.model;
@ -15,12 +16,16 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
/** /**
* Models differences between languages. The interace is not supposed to be implemented directly.
* Rather than that clients may subclass {@link AbstractLanguage}.
* @author Doug Schaefer * @author Doug Schaefer
*
*/ */
public interface ILanguage extends IAdaptable { public interface ILanguage extends IAdaptable {
@ -28,31 +33,27 @@ public interface ILanguage extends IAdaptable {
public static final String KEY = "language"; //$NON-NLS-1$ public static final String KEY = "language"; //$NON-NLS-1$
/** /**
* Style for getTranslationUnit. Use the index for resolving bindings that aren't * @deprecated has no effect.
* found in the AST.
*/ */
public static final int AST_USE_INDEX = 1; public static final int AST_USE_INDEX = 1;
/** /**
* Style for getTranslationUnit. Don't parse header files. It's a good idea to * @deprecated use {@link ITranslationUnit#AST_SKIP_ALL_HEADERS}
* turn on AST_USE_INDEX when you do this.
*/ */
public static final int AST_SKIP_ALL_HEADERS = 2; public static final int AST_SKIP_ALL_HEADERS = ITranslationUnit.AST_SKIP_ALL_HEADERS;
/** /**
* Style for getTranslationUnit. Used by the indexer to skip over headers it * @deprecated use {@link ITranslationUnit#AST_SKIP_INDEXED_HEADERS}
* already has indexed.
*/ */
public static final int AST_SKIP_INDEXED_HEADERS = 4; public static final int AST_SKIP_INDEXED_HEADERS = ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
/** /**
* Style for getTranslationUnit. Don't parse the file if there is no build * @deprecated use {@link ITranslationUnit#AST_SKIP_IF_NO_BUILD_INFO}
* information for it.
*/ */
public static final int AST_SKIP_IF_NO_BUILD_INFO = 8; public static final int AST_SKIP_IF_NO_BUILD_INFO = ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO;
/** /**
* Return the language id for this language in the given PDOM. * Return the language id for this language.
* This is to differentiate languages from eachother. * This is to differentiate languages from eachother.
* *
* @return language id * @return language id
@ -60,23 +61,14 @@ public interface ILanguage extends IAdaptable {
public String getId(); public String getId();
/** /**
* Create the AST for the given file with the given style. * @deprecated use {@link ITranslationUnit#getAST()}.
*
* @param file
* @param style
* @return
*/ */
public IASTTranslationUnit getASTTranslationUnit( public IASTTranslationUnit getASTTranslationUnit(
ITranslationUnit file, ITranslationUnit file,
int style) throws CoreException; int style) throws CoreException;
/** /**
* Create the AST for the given file with the given style with a given * @deprecated use {@link ITranslationUnit#getAST(...)}.
* code reader factory.
*
* @param file
* @param style
* @return
*/ */
public IASTTranslationUnit getASTTranslationUnit( public IASTTranslationUnit getASTTranslationUnit(
ITranslationUnit file, ITranslationUnit file,
@ -114,4 +106,7 @@ public interface ILanguage extends IAdaptable {
* to parse using the default CDT model builder * to parse using the default CDT model builder
*/ */
public IContributedModelBuilder createModelBuilder(ITranslationUnit tu); public IContributedModelBuilder createModelBuilder(ITranslationUnit tu);
// mstodo javadoc
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index) throws CoreException;
} }

View file

@ -7,13 +7,19 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.model; package org.eclipse.cdt.core.model;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
/** /**
* Represents an entire C translation unit (<code>.c</code> source file). * Represents an entire C translation unit (<code>.c</code> source file).
@ -25,6 +31,23 @@ import org.eclipse.core.runtime.IProgressMonitor;
* the case. * the case.
*/ */
public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISourceReference, ISourceManipulation { public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISourceReference, ISourceManipulation {
/**
* Style for {@link #getAST(IIndex, int)}. Don't parse header files.
*/
public static final int AST_SKIP_ALL_HEADERS = 2;
/**
* Style for {@link #getAST(IIndex, int)}. Skips over headers that are found in the index.
*/
public static final int AST_SKIP_INDEXED_HEADERS = 4;
/**
* Style for {@link #getAST(IIndex, int)}. Don't parse the file if there is no build
* information for it.
*/
public static final int AST_SKIP_IF_NO_BUILD_INFO = 8;
/** /**
* Creates and returns an include declaration in this translation unit * Creates and returns an include declaration in this translation unit
* with the given name. * with the given name.
@ -386,4 +409,51 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* *
*/ */
public void setIsStructureKnown(boolean wasSuccessful); public void setIsStructureKnown(boolean wasSuccessful);
/**
* Returns the absolute path of the location of the translation unit. May be <code>null</code>, in
* case the location does not exist.
* @return an absolute path to the location, or <code>null</code>
* @since 4.0
*/
public IPath getLocation();
/**
* Returns the code reader that can be used to parse the translation unit. If the translation unit is a
* working copy the reader will read from the buffer.
* @return a code reader for parsing the translation unit
* @since 4.0
*/
public CodeReader getCodeReader();
/**
* Returns the scanner info associated with this translation unit. May return <code>null</code> if no
* configuration is available.
* @param force if <code>true</code> a default info is returned, even if nothing is configured for this
* translation unit
* @return a scanner info for parsing the translation unit or <code>null</code> if none is configured
* @since 4.0
*/
public IScannerInfo getScannerInfo(boolean force);
/**
* Creates the full AST for this translation unit. May return <code>null</code> if the language of this
* translation unit does not support ASTs.
* @return the AST for the translation unit or <code>null</code>
* @throws CoreException
* @since 4.0
*/
public IASTTranslationUnit getAST() throws CoreException;
/**
* Creates an AST based on the requested style. May return <code>null</code> if the language of this
* translation unit does not support ASTs.
* @param index index to back up the parsing of the AST, may be <code>null</code>
* @param style <code>0</code> or a combination of {@link #AST_SKIP_ALL_HEADERS},
* {@link #AST_SKIP_IF_NO_BUILD_INFO} and {@link #AST_SKIP_INDEXED_HEADERS}
* @return the AST requested or <code>null</code>
* @throws CoreException
* @since 4.0
*/
public IASTTranslationUnit getAST(IIndex index, int style) throws CoreException;
} }

View file

@ -19,12 +19,16 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.content.IContentTypeManager;
@ -33,9 +37,18 @@ import org.eclipse.core.runtime.content.IContentTypeManager;
* *
*/ */
public class LanguageManager { public class LanguageManager {
private static final String NAMESPACE_SEPARATOR = "."; //$NON-NLS-1$
private static final String LANGUAGE_EXTENSION_POINT_ID = "org.eclipse.cdt.core.language"; //$NON-NLS-1$
private static final String ELEMENT_LANGUAGE = "language"; //$NON-NLS-1$
private static final String ELEMENT_CONTENT_TYPE = "contentType"; //$NON-NLS-1$
private static final String ELEMENT_PDOM_LINKAGE_FACTORY = "pdomLinkageFactory"; //$NON-NLS-1$
private static final String ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$
private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
private static LanguageManager instance; private static LanguageManager instance;
private Map cache = new HashMap(); private Map fLanguageCache = new HashMap();
private Map fPDOMLinkageFactoryCache= new HashMap();
private Map fContentTypeToLanguageCache= new HashMap();
public static LanguageManager getInstance() { public static LanguageManager getInstance() {
if (instance == null) if (instance == null)
@ -43,42 +56,30 @@ public class LanguageManager {
return instance; return instance;
} }
public ILanguage getLanguage(String id) throws CoreException { public ILanguage getLanguage(String id) {
ILanguage language = (ILanguage)cache.get(id); ILanguage language = (ILanguage)fLanguageCache.get(id);
if (language != null) if (language != null)
return language; return language;
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY); IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
IExtension[] extensions = point.getExtensions(); for (int j = 0; j < configs.length; ++j) {
for (int i = 0; i < extensions.length; ++i) { final IConfigurationElement languageElem = configs[j];
IExtension extension = extensions[i]; if (ELEMENT_LANGUAGE.equals(languageElem.getName())) {
IConfigurationElement[] languages = extension.getConfigurationElements(); String langId = getLanguageID(languageElem);
for (int j = 0; j < languages.length; ++j) {
IConfigurationElement languageElem = languages[j];
String langId = extension.getNamespaceIdentifier() + "." + languageElem.getAttribute("id"); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
if (langId.equals(id)) { if (langId.equals(id)) {
language = (ILanguage)languageElem.createExecutableExtension("class"); //$NON-NLS-1$ final ILanguage[] result= new ILanguage[]{null};
cache.put(id, language); SafeRunner.run(new ISafeRunnable(){
return language; public void handleException(Throwable exception) {
} CCorePlugin.log(exception);
} }
}
return null; public void run() throws Exception {
} result[0]= (ILanguage)languageElem.createExecutableExtension(ATTRIBUTE_CLASS);
}
public ILanguage getLanguage(IContentType contentType) throws CoreException { });
String contentTypeId= contentType.getId(); if (result[0] != null) {
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY); fLanguageCache.put(id, result[0]);
IExtension[] extensions = point.getExtensions(); return result[0];
for (int i = 0; i < extensions.length; ++i) {
IConfigurationElement[] languages = extensions[i].getConfigurationElements();
for (int j = 0; j < languages.length; ++j) {
IConfigurationElement language = languages[j];
IConfigurationElement[] assocContentTypes = language.getChildren("contentType"); //$NON-NLS-1$
for (int k = 0; k < assocContentTypes.length; ++k) {
if (contentTypeId.equals(assocContentTypes[k].getAttribute("id"))) { //$NON-NLS-1$
return (ILanguage)language.createExecutableExtension("class"); //$NON-NLS-1$
} }
} }
} }
@ -86,6 +87,39 @@ public class LanguageManager {
return null; return null;
} }
private String getLanguageID(final IConfigurationElement languageElem) {
return languageElem.getNamespaceIdentifier() + NAMESPACE_SEPARATOR + languageElem.getAttribute(ATTRIBUTE_ID);
}
public ILanguage getLanguage(IContentType contentType) {
String contentTypeID= contentType.getId();
return getLanguageForContentTypeID(contentTypeID);
}
private ILanguage getLanguageForContentTypeID(String contentTypeID) {
ILanguage language = (ILanguage)fContentTypeToLanguageCache.get(contentTypeID);
if (language != null || fContentTypeToLanguageCache.containsKey(contentTypeID))
return language;
IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
for (int j = 0; j < configs.length; ++j) {
final IConfigurationElement languageElem = configs[j];
if (ELEMENT_LANGUAGE.equals(languageElem.getName())) {
IConfigurationElement[] assocContentTypes = languageElem.getChildren(ELEMENT_CONTENT_TYPE);
for (int k = 0; k < assocContentTypes.length; ++k) {
if (contentTypeID.equals(assocContentTypes[k].getAttribute(ATTRIBUTE_ID))) {
String id= getLanguageID(languageElem);
ILanguage lang= getLanguage(id);
fContentTypeToLanguageCache.put(contentTypeID, lang);
return lang;
}
}
}
}
fContentTypeToLanguageCache.put(contentTypeID, null);
return null;
}
/** /**
* @deprecated use getRegisteredContentTypes() instead. * @deprecated use getRegisteredContentTypes() instead.
*/ */
@ -98,15 +132,13 @@ public class LanguageManager {
allTypes.add(CCorePlugin.CONTENT_TYPE_CXXSOURCE); allTypes.add(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
IContentTypeManager manager = Platform.getContentTypeManager(); IContentTypeManager manager = Platform.getContentTypeManager();
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY); IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
IExtension[] extensions = point.getExtensions(); for (int j = 0; j < configs.length; ++j) {
for (int i = 0; i < extensions.length; ++i) { final IConfigurationElement languageElem = configs[j];
IConfigurationElement[] languages = extensions[i].getConfigurationElements(); if (ELEMENT_LANGUAGE.equals(languageElem.getName())) {
for (int j = 0; j < languages.length; ++j) { IConfigurationElement[] contentTypes = languageElem.getChildren(ELEMENT_CONTENT_TYPE);
IConfigurationElement language = languages[j];
IConfigurationElement[] contentTypes = language.getChildren("contentType"); //$NON-NLS-1$
for (int k = 0; k < contentTypes.length; ++k) { for (int k = 0; k < contentTypes.length; ++k) {
IContentType langContType = manager.getContentType(contentTypes[k].getAttribute("id")); //$NON-NLS-1$ IContentType langContType = manager.getContentType(contentTypes[k].getAttribute(ATTRIBUTE_ID));
allTypes.add(langContType.getId()); allTypes.add(langContType.getId());
} }
} }
@ -133,15 +165,15 @@ public class LanguageManager {
allTypes.add(CCorePlugin.CONTENT_TYPE_CXXSOURCE); allTypes.add(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
IContentTypeManager manager = Platform.getContentTypeManager(); IContentTypeManager manager = Platform.getContentTypeManager();
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY); IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, LANGUAGE_EXTENSION_POINT_ID);
IExtension[] extensions = point.getExtensions(); IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; ++i) { for (int i = 0; i < extensions.length; ++i) {
IConfigurationElement[] languages = extensions[i].getConfigurationElements(); IConfigurationElement[] languages = extensions[i].getConfigurationElements();
for (int j = 0; j < languages.length; ++j) { for (int j = 0; j < languages.length; ++j) {
IConfigurationElement language = languages[j]; IConfigurationElement language = languages[j];
IConfigurationElement[] contentTypes = language.getChildren("contentType"); //$NON-NLS-1$ IConfigurationElement[] contentTypes = language.getChildren(ELEMENT_CONTENT_TYPE);
for (int k = 0; k < contentTypes.length; ++k) { for (int k = 0; k < contentTypes.length; ++k) {
IContentType langContType = manager.getContentType(contentTypes[k].getAttribute("id")); //$NON-NLS-1$ IContentType langContType = manager.getContentType(contentTypes[k].getAttribute(ATTRIBUTE_ID));
allTypes.add(langContType.getId()); allTypes.add(langContType.getId());
} }
} }
@ -151,7 +183,7 @@ public class LanguageManager {
} }
public boolean isContributedContentType(String contentTypeId) { public boolean isContributedContentType(String contentTypeId) {
return collectContentTypeIds().contains(contentTypeId); return contentTypeId != null && getLanguageForContentTypeID(contentTypeId) != null;
} }
public IContributedModelBuilder getContributedModelBuilderFor(TranslationUnit tu) { public IContributedModelBuilder getContributedModelBuilderFor(TranslationUnit tu) {
@ -162,4 +194,38 @@ public class LanguageManager {
return null; return null;
} }
} }
/**
* Returns a factory for the given linkage ID. The IDs are defined in {@link ILinkage}.
* @param linkageID an ID for a linkage.
* @return a factory or <code>null</code>.
* @since 4.0
*/
public IPDOMLinkageFactory getPDOMLinkageFactory(String linkageID) {
final IPDOMLinkageFactory[] result= new IPDOMLinkageFactory[] {null};
result[0]= (IPDOMLinkageFactory) fPDOMLinkageFactoryCache.get(linkageID);
if (result[0] == null) {
// read configuration
IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
for (int i = 0; result[0] == null && i < configs.length; i++) {
final IConfigurationElement element = configs[i];
if (ELEMENT_PDOM_LINKAGE_FACTORY.equals(element.getName())) {
if (linkageID.equals(element.getAttribute(ATTRIBUTE_ID))) {
SafeRunner.run(new ISafeRunnable(){
public void handleException(Throwable exception) {
CCorePlugin.log(exception);
}
public void run() throws Exception {
result[0]= (IPDOMLinkageFactory) element.createExecutableExtension(ATTRIBUTE_CLASS);
}}
);
}
}
}
fPDOMLinkageFactoryCache.put(linkageID, result[0]);
}
return result[0];
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2005 QNX Software Systems and others. * Copyright (c) 2002, 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
@ -24,6 +25,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -89,13 +91,7 @@ public class ContentTypeProcessor extends CModelOperation {
if (id == null || id.length() == 0) { if (id == null || id.length() == 0) {
return false; return false;
} }
String[] ids = CoreModel.getRegistedContentTypeIds(); return LanguageManager.getInstance().isContributedContentType(id);
for (int i = 0; i < ids.length; i++) {
if (ids[i].equals(id)) {
return true;
}
}
return false;
} }
protected void processContentType(ICElement celement, IContentType contentType, IScopeContext context) { protected void processContentType(ICElement celement, IContentType contentType, IScopeContext context) {

View file

@ -17,9 +17,13 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IContributedModelBuilder; import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.IInclude; import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
@ -32,7 +36,15 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IUsing; import org.eclipse.cdt.core.model.IUsing;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -56,7 +68,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
*/ */
protected IProblemRequestor problemRequestor; protected IProblemRequestor problemRequestor;
SourceManipulationInfo sourceManipulationInfo = null; SourceManipulationInfo sourceManipulationInfo = null;
public TranslationUnit(ICElement parent, IFile file, String idType) { public TranslationUnit(ICElement parent, IFile file, String idType) {
@ -74,7 +85,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
setContentTypeID(idType); setContentTypeID(idType);
} }
public ITranslationUnit getTranslationUnit () { public ITranslationUnit getTranslationUnit() {
return this; return this;
} }
@ -120,7 +131,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
public ICElement getElementAtOffset(int pos) throws CModelException { public ICElement getElementAtOffset(int pos) throws CModelException {
ICElement e= getSourceElementAtOffset(pos); ICElement e = getSourceElementAtOffset(pos);
if (e == this) { if (e == this) {
return null; return null;
} }
@ -128,14 +139,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
public ICElement[] getElementsAtOffset(int pos) throws CModelException { public ICElement[] getElementsAtOffset(int pos) throws CModelException {
ICElement[] e= getSourceElementsAtOffset(pos); ICElement[] e = getSourceElementsAtOffset(pos);
if (e.length == 1 && e[0] == this) { if (e.length == 1 && e[0] == this) {
return CElement.NO_ELEMENTS; return CElement.NO_ELEMENTS;
} }
return e; return e;
} }
public ICElement getElement(String name ) { public ICElement getElement(String name) {
if (name == null || name.length() == 0) { if (name == null || name.length() == 0) {
return null; return null;
} }
@ -155,7 +166,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
for (int j = 0; j < names.length; ++j) { for (int j = 0; j < names.length; ++j) {
if (current instanceof IParent) { if (current instanceof IParent) {
try { try {
ICElement[] celements = ((IParent)current).getChildren(); ICElement[] celements = ((IParent) current).getChildren();
current = null; current = null;
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {
if (names[j].equals(celements[i].getElementName())) { if (names[j].equals(celements[i].getElementName())) {
@ -179,7 +190,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {
if (celements[i].getElementType() == ICElement.C_INCLUDE) { if (celements[i].getElementType() == ICElement.C_INCLUDE) {
if (name.equals(celements[i].getElementName())) { if (name.equals(celements[i].getElementName())) {
return (IInclude)celements[i]; return (IInclude) celements[i];
} }
} }
} }
@ -196,7 +207,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
aList.add(celements[i]); aList.add(celements[i]);
} }
} }
return (IInclude[])aList.toArray(new IInclude[0]); return (IInclude[]) aList.toArray(new IInclude[0]);
} }
public IUsing getUsing(String name) { public IUsing getUsing(String name) {
@ -205,7 +216,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {
if (celements[i].getElementType() == ICElement.C_USING) { if (celements[i].getElementType() == ICElement.C_USING) {
if (name.equals(celements[i].getElementName())) { if (name.equals(celements[i].getElementName())) {
return (IUsing)celements[i]; return (IUsing) celements[i];
} }
} }
} }
@ -222,7 +233,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
aList.add(celements[i]); aList.add(celements[i]);
} }
} }
return (IUsing[])aList.toArray(new IUsing[0]); return (IUsing[]) aList.toArray(new IUsing[0]);
} }
public INamespace getNamespace(String name) { public INamespace getNamespace(String name) {
@ -231,7 +242,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
ICElement current = this; ICElement current = this;
for (int j = 0; j < names.length; ++j) { for (int j = 0; j < names.length; ++j) {
if (current instanceof IParent) { if (current instanceof IParent) {
ICElement[] celements = ((IParent)current).getChildren(); ICElement[] celements = ((IParent) current).getChildren();
current = null; current = null;
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {
if (celements[i].getElementType() == ICElement.C_NAMESPACE) { if (celements[i].getElementType() == ICElement.C_NAMESPACE) {
@ -246,7 +257,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
} }
if (current instanceof INamespace) { if (current instanceof INamespace) {
return (INamespace)current; return (INamespace) current;
} }
} catch (CModelException e) { } catch (CModelException e) {
} }
@ -261,7 +272,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
aList.add(celements[i]); aList.add(celements[i]);
} }
} }
return (INamespace[])aList.toArray(new INamespace[0]); return (INamespace[]) aList.toArray(new INamespace[0]);
} }
public void setLocation(IPath loc) { public void setLocation(IPath loc) {
@ -283,7 +294,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public IFile getFile() { public IFile getFile() {
IResource res = getResource(); IResource res = getResource();
if (res instanceof IFile) { if (res instanceof IFile) {
return (IFile)res; return (IFile) res;
} }
return null; return null;
} }
@ -315,7 +326,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
* @see org.eclipse.cdt.core.model.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.core.model.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
*/ */
public void rename(String name, boolean force, IProgressMonitor monitor) public void rename(String name, boolean force, IProgressMonitor monitor)
throws CModelException { throws CModelException {
getSourceManipulationInfo().rename(name, force, monitor); getSourceManipulationInfo().rename(name, force, monitor);
} }
@ -334,7 +345,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
protected TranslationUnitInfo getTranslationUnitInfo() throws CModelException { protected TranslationUnitInfo getTranslationUnitInfo() throws CModelException {
return (TranslationUnitInfo)getElementInfo(); return (TranslationUnitInfo) getElementInfo();
} }
protected SourceManipulationInfo getSourceManipulationInfo() { protected SourceManipulationInfo getSourceManipulationInfo() {
@ -344,7 +355,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
return sourceManipulationInfo; return sourceManipulationInfo;
} }
protected CElementInfo createElementInfo () { protected CElementInfo createElementInfo() {
return new TranslationUnitInfo(this); return new TranslationUnitInfo(this);
} }
@ -358,7 +369,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
*/ */
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof ITranslationUnit)) return false; if (!(o instanceof ITranslationUnit)) return false;
return super.equals(o) && !((ITranslationUnit)o).isWorkingCopy(); return super.equals(o) && !((ITranslationUnit) o).isWorkingCopy();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -376,7 +387,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory); Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null) return null; if (perFactoryWorkingCopies == null) return null;
return (WorkingCopy)perFactoryWorkingCopies.get(this); return (WorkingCopy) perFactoryWorkingCopies.get(this);
} }
/** /**
@ -384,15 +395,15 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
* @param newElements * @param newElements
* @param element * @param element
*/ */
private void getNewElements(Map mapping, CElement element){ private void getNewElements(Map mapping, CElement element) {
Object info = null; Object info = null;
try { try {
info = element.getElementInfo(); info = element.getElementInfo();
} catch (CModelException e) { } catch (CModelException e) {
} }
if(info != null){ if (info != null) {
if(element instanceof IParent){ if (element instanceof IParent) {
ICElement[] children = ((CElementInfo)info).getChildren(); ICElement[] children = ((CElementInfo) info).getChildren();
int size = children.length; int size = children.length;
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
CElement child = (CElement) children[i]; CElement child = (CElement) children[i];
@ -417,13 +428,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
// generate structure // generate structure
this.parse(newElements); this.parse(newElements);
/////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////
if (isWorkingCopy()) { if (isWorkingCopy()) {
ITranslationUnit original = ((IWorkingCopy)this).getOriginalElement(); ITranslationUnit original = ((IWorkingCopy)this).getOriginalElement();
// might be IResource.NULL_STAMP if original does not exist // might be IResource.NULL_STAMP if original does not exist
IResource r = original.getResource(); IResource r = original.getResource();
if (r != null && r instanceof IFile) { if (r != null && r instanceof IFile) {
unitInfo.fTimestamp = ((IFile) r).getModificationStamp(); unitInfo.fTimestamp = ((IFile) r).getModificationStamp();
} }
} }
@ -455,7 +466,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
* @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory, org.eclipse.cdt.core.model.IProblemRequestor) * @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory, org.eclipse.cdt.core.model.IProblemRequestor)
*/ */
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory, IProblemRequestor requestor) public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory, IProblemRequestor requestor)
throws CModelException { throws CModelException {
// if factory is null, default factory must be used // if factory is null, default factory must be used
if (factory == null) factory = BufferManager.getDefaultBufferManager(); if (factory == null) factory = BufferManager.getDefaultBufferManager();
@ -468,7 +479,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
Map sharedWorkingCopies = manager.sharedWorkingCopies; Map sharedWorkingCopies = manager.sharedWorkingCopies;
Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory); Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null){ if (perFactoryWorkingCopies == null) {
perFactoryWorkingCopies = new HashMap(); perFactoryWorkingCopies = new HashMap();
sharedWorkingCopies.put(factory, perFactoryWorkingCopies); sharedWorkingCopies.put(factory, perFactoryWorkingCopies);
} }
@ -479,13 +490,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, requestor); CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, requestor);
op.runOperation(monitor); op.runOperation(monitor);
return (IWorkingCopy)op.getResultElements()[0]; return (IWorkingCopy) op.getResultElements()[0];
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy() * @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy()
*/ */
public IWorkingCopy getWorkingCopy()throws CModelException{ public IWorkingCopy getWorkingCopy() throws CModelException {
return this.getWorkingCopy(null, null); return this.getWorkingCopy(null, null);
} }
@ -512,9 +523,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
protected void openParent(Object childInfo, Map newElements, IProgressMonitor pm) throws CModelException { protected void openParent(Object childInfo, Map newElements, IProgressMonitor pm) throws CModelException {
try { try {
super.openParent(childInfo, newElements, pm); super.openParent(childInfo, newElements, pm);
} catch(CModelException e){ } catch (CModelException e) {
// allow parent to not exist for working copies defined outside // allow parent to not exist for working copies defined outside
if (!isWorkingCopy()){ if (!isWorkingCopy()) {
throw e; throw e;
} }
} }
@ -546,14 +557,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
*/ */
protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException {
// create buffer - translation units only use default buffer factory // create buffer - translation units only use default buffer factory
BufferManager bufManager = getBufferManager(); BufferManager bufManager = getBufferManager();
IBuffer buffer = getBufferFactory().createBuffer(this); IBuffer buffer = getBufferFactory().createBuffer(this);
if (buffer == null) if (buffer == null)
return null; return null;
// set the buffer source // set the buffer source
if (buffer.getCharacters() == null){ if (buffer.getCharacters() == null) {
IResource file = this.getResource(); IResource file = this.getResource();
if (file != null && file.getType() == IResource.FILE) { if (file != null && file.getType() == IResource.FILE) {
buffer.setContents(Util.getResourceContentsAsCharArray((IFile)file)); buffer.setContents(Util.getResourceContentsAsCharArray((IFile)file));
@ -682,15 +693,15 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public ILanguage getLanguage() throws CoreException { public ILanguage getLanguage() throws CoreException {
if (language == null) { if (language == null) {
language= computeLanguage(contentTypeId); language = computeLanguage(contentTypeId);
// Special magic for C/C++ header files // Special magic for C/C++ header files
if (language == null && isHeaderUnit()) { if (language == null && isHeaderUnit()) {
if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(contentTypeId)) { if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(contentTypeId)) {
language= computeLanguage(CCorePlugin.CONTENT_TYPE_CSOURCE); language = computeLanguage(CCorePlugin.CONTENT_TYPE_CSOURCE);
} }
else if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(contentTypeId)) { else if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(contentTypeId)) {
language= computeLanguage(CCorePlugin.CONTENT_TYPE_CXXSOURCE); language = computeLanguage(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
} }
} }
} }
@ -744,4 +755,69 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} catch (CModelException e) { } catch (CModelException e) {
} }
} }
public IASTTranslationUnit getAST() throws CoreException {
return getAST(null, 0);
}
public IASTTranslationUnit getAST(IIndex index, int style) throws CoreException {
ICodeReaderFactory codeReaderFactory;
if (index != null && (style & (ITranslationUnit.AST_SKIP_INDEXED_HEADERS | ITranslationUnit.AST_SKIP_ALL_HEADERS)) != 0) {
codeReaderFactory= new IndexBasedCodeReaderFactory(index);
}
else {
codeReaderFactory = SavedCodeReaderFactory.getInstance();
}
IScannerInfo scanInfo = getScannerInfo( (style & ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO) == 0);
if (scanInfo == null) {
return null;
}
CodeReader reader;
reader = getCodeReader();
ILanguage language= getLanguage();
if (language != null) {
return language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index);
}
return null;
}
public CodeReader getCodeReader() {
CodeReader reader;
IPath location= getLocation();
if (isWorkingCopy() || location == null) {
if (location == null) {
reader= new CodeReader(getContents());
}
else {
reader= new CodeReader(location.toOSString(), getContents());
}
}
else {
reader= ParserUtil.createReader(location.toOSString(), null);
}
return reader;
}
public IScannerInfo getScannerInfo(boolean force) {
IResource resource = getResource();
ICProject project = getCProject();
IProject rproject = project.getProject();
IScannerInfoProvider provider = CCorePlugin.getDefault()
.getScannerInfoProvider(rproject);
if (provider != null) {
IResource infoResource = resource != null ? resource : rproject;
IScannerInfo scanInfo = provider
.getScannerInformation(infoResource);
if (scanInfo != null)
return scanInfo;
}
if (force) {
return new ScannerInfo();
}
return null;
}
} }

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom;
/**
* Represents a linkage in the AST or the index.
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will
* work or that it will remain the same. Please do not use this API without
* consulting with the CDT team.
* </p>
* @since 4.0
*/
public interface ILinkage {
final static String NO_LINKAGE_ID= "none"; //$NON-NLS-1$
final static String C_LINKAGE_ID= "C"; //$NON-NLS-1$
final static String CPP_LINKAGE_ID= "C++"; //$NON-NLS-1$
final static String FORTRAN_LINKAGE_ID= "Fortran"; //$NON-NLS-1$
String getID();
}

View file

@ -13,16 +13,19 @@ package org.eclipse.cdt.core.dom;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
/** /**
* Common interface for names in the index and the AST * Common interface for names in the index and the AST.
* <p> This interface is not intended to be implemented by clients. </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will
* work or that it will remain the same. Please do not use this API without
* consulting with the CDT team.
* </p>
* @since 4.0 * @since 4.0
*/ */
public interface IName { public interface IName {
public static final IName[] EMPTY_NAME_ARRAY = new IName[0];
/** /**
* Return a char array representation of the name. * Return a char array representation of the name.
* *
@ -30,13 +33,6 @@ public interface IName {
*/ */
public char[] toCharArray(); public char[] toCharArray();
/**
* Resolve the semantic object this name is referring to.
*
* @return <code>IBinding</code> binding
*/
public IBinding resolveBinding();
/** /**
* Is this name being used in the AST as the introduction of a declaration? * Is this name being used in the AST as the introduction of a declaration?
* @return boolean * @return boolean

View file

@ -11,13 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom; package org.eclipse.cdt.core.dom;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
/** /**
* This is the reader interface to the PDOM. It is used by general * This is the reader interface to the PDOM. It is used by general
@ -25,74 +19,4 @@ import org.eclipse.core.runtime.IProgressMonitor;
* *
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IPDOM extends IAdaptable { public interface IPDOM extends IAdaptable {}
/**
* Find all the bindings whose names that match the pattern.
*
* @param pattern
* @return
* @throws CoreException
*/
public IBinding[] findBindings(Pattern pattern, IProgressMonitor monitor) throws CoreException;
/**
* Find all bindings whose qualified names match the array of patterns.
*
* @param pattern
* @return
* @throws CoreException
*/
public IBinding[] findBindings(Pattern[] pattern, IProgressMonitor monitor) throws CoreException;
/**
* Recursively visit the nodes in this PDOM using the given visitor.
*
* @param visitor
* @throws CoreException
*/
public void accept(IPDOMVisitor visitor) throws CoreException;
/**
* Clear all the contents of this PDOM.
*
* @throws CoreException
*/
public void clear() throws CoreException;
/**
* Looks to see if anything has been stored in this PDOM.
*
* @return is the PDOM empty
* @throws CoreException
*/
public boolean isEmpty() throws CoreException;
public ICodeReaderFactory getCodeReaderFactory();
public ICodeReaderFactory getCodeReaderFactory(IWorkingCopy root);
/**
* When accessing a PDOM and working with its objects it's neccessary to hold
* a read-lock on the PDOM. Make sure to release it: <pre>
* pdom.acquireReadLock();
* try {
* // do what you have to do.
* }
* finally {
* pdom.releaseReadLock();
* } </pre>
* @throws InterruptedException
* @since 4.0
*/
public void acquireReadLock() throws InterruptedException;
public void releaseReadLock();
/**
* You must not hold any other lock on any PDOM when acquiring a write lock.
* Failing to do so may lead to dead-locks.
*/
public void acquireWriteLock() throws InterruptedException;
public void releaseWriteLock();
}

View file

@ -1,35 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
/**
* This is the interface used by the DOM to help with resolving
* bindings amongst other things.
*
* @author Doug Schaefer
*/
public interface IPDOMResolver extends IAdaptable {
public IBinding resolveBinding(IASTName name);
public IName[] getDeclarations(IBinding binding) throws CoreException;
public IName[] getDefinitions(IBinding binding) throws CoreException;
public IName[] getReferences(IBinding binding) throws CoreException;
}

View file

@ -11,6 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
/** /**
@ -42,6 +43,13 @@ public interface IASTName extends IASTNode, IName {
*/ */
public void setBinding( IBinding binding ); public void setBinding( IBinding binding );
/**
* Resolve the semantic object this name is referring to.
*
* @return <code>IBinding</code> binding
*/
public IBinding resolveBinding();
/** /**
* Return a list of bindings in the scope of the name that have the name as * Return a list of bindings in the scope of the name that have the name as
* a prefix. * a prefix.
@ -49,4 +57,9 @@ public interface IASTName extends IASTNode, IName {
* @return <code>IBinding []</code> bindings that start with this name * @return <code>IBinding []</code> bindings that start with this name
*/ */
public IBinding[] resolvePrefix(); public IBinding[] resolvePrefix();
/**
* Determines the current linkage in which the name has to be resolved.
*/
public ILinkage getLinkage();
} }

View file

@ -12,7 +12,7 @@
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -219,14 +219,14 @@ public interface IASTTranslationUnit extends IASTNode {
* *
* @return the Index for this translation unit * @return the Index for this translation unit
*/ */
public IPDOM getIndex(); public IIndex getIndex();
/** /**
* Set the Index to be used for this translation unit. * Set the Index to be used for this translation unit.
* *
* @param index * @param index
*/ */
public void setIndex(IPDOM index); public void setIndex(IIndex index);
/** /**
* Returns the language for this translation unit. * Returns the language for this translation unit.

View file

@ -7,12 +7,16 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
/** /**
* Represents the semantics of a name found in the AST or the index.
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IBinding extends IAdaptable { public interface IBinding extends IAdaptable {
@ -38,4 +42,9 @@ public interface IBinding extends IAdaptable {
*/ */
public IScope getScope() throws DOMException; public IScope getScope() throws DOMException;
/**
* Every binding has a linkage.
*/
public ILinkage getLinkage() throws CoreException;
} }

View file

@ -46,15 +46,10 @@ public interface IScope {
*/ */
public IBinding[] find(String name) throws DOMException; public IBinding[] find(String name) throws DOMException;
/**
* Return the physical IASTNode that this scope was created for
* @return
*/
public IASTNode getPhysicalNode() throws DOMException;
/** /**
* The IScope serves as a mechanism for caching IASTNames and bindings to * The IScope serves as a mechanism for caching IASTNames and bindings to
* speed up resolution. * speed up resolution.
* mstodo more work: remove the ast-specific methods.
*/ */
/** /**
@ -97,24 +92,4 @@ public interface IScope {
* @throws DOMException * @throws DOMException
*/ */
public void addBinding(IBinding binding) throws DOMException; public void addBinding(IBinding binding) throws DOMException;
/**
* Set whether or not all the names in this scope have been cached
*
* @param b
*/
public void setFullyCached(boolean b) throws DOMException;
/**
* whether or not this scope's cache contains all the names
*
* @return
*/
public boolean isFullyCached() throws DOMException;
/**
* clear the name cache in this scope
* @throws DOMException
*/
public void flushCache() throws DOMException;
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.gnu.c; package org.eclipse.cdt.core.dom.ast.gnu.c;
@ -22,9 +23,10 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IContributedModelBuilder; import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.CodeReader;
@ -36,28 +38,23 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration;
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.PDOMCodeReaderFactory;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory; import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
public class GCCLanguage extends PlatformObject implements ILanguage { public class GCCLanguage extends AbstractLanguage {
protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration(); protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
// Must match the id in the extension // Must match the id in the extension
@ -80,53 +77,9 @@ public class GCCLanguage extends PlatformObject implements ILanguage {
return super.getAdapter(adapter); return super.getAdapter(adapter);
} }
public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException { public IASTTranslationUnit getASTTranslationUnit(CodeReader reader,
ICodeReaderFactory fileCreator; IScannerInfo scanInfo, ICodeReaderFactory codeReaderFactory, IIndex index) throws CoreException {
if ((style & (ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_SKIP_ALL_HEADERS)) != 0) { IScannerExtensionConfiguration scannerExtensionConfiguration= C_GNU_SCANNER_EXTENSION;
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(file.getCProject()).getAdapter(PDOM.class);
fileCreator = new PDOMCodeReaderFactory(pdom);
} else
fileCreator = SavedCodeReaderFactory.getInstance();
return getASTTranslationUnit(file, fileCreator, style);
}
public IASTTranslationUnit getASTTranslationUnit(
ITranslationUnit file,
ICodeReaderFactory codeReaderFactory,
int style) throws CoreException {
IResource resource = file.getResource();
ICProject project = file.getCProject();
IProject rproject = project.getProject();
IScannerInfo scanInfo = null;
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(rproject);
if (provider != null){
IResource infoResource = resource != null ? resource : rproject;
IScannerInfo buildScanInfo = provider.getScannerInformation(infoResource);
if (buildScanInfo != null)
scanInfo = buildScanInfo;
else if ((style & ILanguage.AST_SKIP_IF_NO_BUILD_INFO) != 0)
return null;
else
scanInfo = new ScannerInfo();
}
CodeReader reader;
IFile rfile = (IFile)file.getResource();
String path = rfile != null ? rfile.getLocation().toOSString() : file.getPath().toOSString();
if (file instanceof IWorkingCopy) {
// get the working copy contents
reader = new CodeReader(path, file.getContents());
} else {
reader = codeReaderFactory.createCodeReaderForTranslationUnit(path);
if (reader == null)
return null;
}
IScannerExtensionConfiguration scannerExtensionConfiguration
= C_GNU_SCANNER_EXTENSION;
IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
ParserLanguage.C, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, codeReaderFactory); ParserLanguage.C, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, codeReaderFactory);
//assume GCC //assume GCC
@ -135,8 +88,8 @@ public class GCCLanguage extends PlatformObject implements ILanguage {
// Parse // Parse
IASTTranslationUnit ast = parser.parse(); IASTTranslationUnit ast = parser.parse();
if ((style & AST_USE_INDEX) != 0) // mstodo isn't that too late to set the index?
ast.setIndex(CCorePlugin.getPDOMManager().getPDOM(file.getCProject())); ast.setIndex(index);
return ast; return ast;
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.gnu.cpp; package org.eclipse.cdt.core.dom.ast.gnu.cpp;
@ -22,9 +23,10 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IContributedModelBuilder; import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.CodeReader;
@ -36,28 +38,23 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration;
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.PDOMCodeReaderFactory;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory; import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
*/ */
public class GPPLanguage extends PlatformObject implements ILanguage { public class GPPLanguage extends AbstractLanguage {
protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration(); protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration();
public static final String ID = CCorePlugin.PLUGIN_ID + ".g++"; //$NON-NLS-1$ public static final String ID = CCorePlugin.PLUGIN_ID + ".g++"; //$NON-NLS-1$
@ -79,53 +76,10 @@ public class GPPLanguage extends PlatformObject implements ILanguage {
return super.getAdapter(adapter); return super.getAdapter(adapter);
} }
public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException {
ICodeReaderFactory fileCreator;
if ((style & (ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_SKIP_ALL_HEADERS)) != 0) {
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(file.getCProject()).getAdapter(PDOM.class);
fileCreator = new PDOMCodeReaderFactory(pdom);
} else
fileCreator = SavedCodeReaderFactory.getInstance();
return getASTTranslationUnit(file, fileCreator, style);
}
public IASTTranslationUnit getASTTranslationUnit(
ITranslationUnit file,
ICodeReaderFactory codeReaderFactory,
int style) throws CoreException {
IResource resource = file.getResource();
ICProject project = file.getCProject();
IProject rproject = project.getProject();
IScannerInfo scanInfo = null;
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(rproject);
if (provider != null){
IResource infoResource = resource != null ? resource : rproject;
IScannerInfo buildScanInfo = provider.getScannerInformation(infoResource);
if (buildScanInfo != null)
scanInfo = buildScanInfo;
else if ((style & ILanguage.AST_SKIP_IF_NO_BUILD_INFO) != 0)
return null;
else
scanInfo = new ScannerInfo();
}
CodeReader reader;
IFile rfile = (IFile)file.getResource();
String path = rfile != null ? rfile.getLocation().toOSString() : file.getPath().toOSString();
if (file instanceof IWorkingCopy) {
// get the working copy contents
reader = new CodeReader(path, file.getContents());
} else {
reader = codeReaderFactory.createCodeReaderForTranslationUnit(path);
if (reader == null)
return null;
}
IScannerExtensionConfiguration scannerExtensionConfiguration
= CPP_GNU_SCANNER_EXTENSION;
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory codeReaderFactory, IIndex index) throws CoreException {
IScannerExtensionConfiguration scannerExtensionConfiguration= CPP_GNU_SCANNER_EXTENSION;
IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
ParserLanguage.CPP, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, codeReaderFactory); ParserLanguage.CPP, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, codeReaderFactory);
//assume GCC //assume GCC
@ -133,9 +87,9 @@ public class GPPLanguage extends PlatformObject implements ILanguage {
new GPPParserExtensionConfiguration() ); new GPPParserExtensionConfiguration() );
// Parse // Parse
IASTTranslationUnit ast = parser.parse(); IASTTranslationUnit ast= parser.parse();
if ((style & AST_USE_INDEX) != 0) // mstodo isn't that too late to set the index?
ast.setIndex(CCorePlugin.getPDOMManager().getPDOM(file.getCProject())); ast.setIndex(index);
return ast; return ast;
} }

View file

@ -0,0 +1,278 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* Interface for accessing the index for one or more projects.
*
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndex {
/**
* Constant to specify infinite depth.
* @see #findIncludedBy(IIndexFile, int)
* @see #findIncludes(IIndexFile, int)
*/
final int DEPTH_INFINITE = -1;
/**
* Constant to find direct includes, only.
* @see #findIncludedBy(IIndexFile, int)
* @see #findIncludes(IIndexFile, int)
*/
final int DEPTH_ZERO = 0;
/**
* Constant to search for declarations. This does not include definitions.
*/
final int FIND_DECLARATIONS = 0x1;
/**
* Constant to search for definitions. This does not include declarations.
*/
final int FIND_DEFINITIONS = 0x2;
/**
* Constant to search for all declarations including definitons.
*/
final int FIND_REFERENCES = 0x4;
/**
* Constant to search for references. This does not include declarations or definitions.
*/
final int FIND_DECLARATIONS_DEFINITIONS = FIND_DECLARATIONS | FIND_DEFINITIONS;
/**
* Constant to search for all occurrences of a binding. This includes declarations, definitons and references.
*/
final int FIND_ALL_OCCURENCES = FIND_DECLARATIONS | FIND_DEFINITIONS | FIND_REFERENCES;
/**
* Before making calls to an index you have to obtain a lock. The objects
* returned by an index become invalid as soon as the indexer writes to the
* index. You may obtain nested read locks. Make sure you release the lock.
* @see #getLastWriteAccess()
* <pre>
* index.acquireReadLock();
* try {
* ....
* }
* finally {
* index.releaseReadLock();
* }
* </pre>
*/
public void acquireReadLock() throws InterruptedException;
/**
* Any lock obtained by {@link #acquireReadLock()} must be released.
*/
public void releaseReadLock();
/**
* Returns a timestamp of when the index was last written to. This can
* be used to figure out whether information read from the index is
* still reliable or not.
*
* <pre>
* long timestamp;
* IBinding binding= null;
* index.acquireReadLock();
* try {
* timestamp= index.getLastWriteAccess();
* binding= index.findBinding(...);
* }
* finally {
* index.releaseReadLock();
* }
* ...
* index.acqureReadLock();
* try {
* if (index.getLastWriteAccess() != timestamp) {
* // don't use binding, it's not valid anymore
* binding= index.findBinding(...);
* }
* String name= binding.getName();
* ...
* }
* finally {
* index.releaseReadLock();
* }
*/
public long getLastWriteAccess();
/**
* Looks for a file with the given location. May return <code>null</code>.
* @param location absolute path of the file location
* @return the file in the index or <code>null</code>
* @throws CoreException
*/
public IIndexFile getFile(IPath location) throws CoreException;
/**
* Looks for include relations originated by the given file.
* This is the same as <pre> findIncludes(file, DEPTH_ZERO); </pre>
* @param file the file containing the include directives
* @return an array of include relations
* @throws CoreException
*/
public IIndexInclude[] findIncludes(IIndexFile file) throws CoreException;
/**
* Looks for include relations pointing to the given file.
* This is the same as <pre> findIncludedBy(file, DEPTH_ZERO); </pre>
* @param file the file included by the directives to be found
* @return an array of include relations
* @throws CoreException
*/
public IIndexInclude[] findIncludedBy(IIndexFile file) throws CoreException;
/**
* Looks recursively for include relations originated by the given file.
* @param file the file containing the include directives
* @param depth depth to which includes are followed, should be one of
* {@link #DEPTH_ZERO} or {@link #DEPTH_INFINITE}
* @return an array of include relations
* @throws CoreException
*/
public IIndexInclude[] findIncludes(IIndexFile file, int depth) throws CoreException;
/**
* Looks recursively for include relations pointing to the given file.
* @param file the file the include directives point to
* @param depth depth to which includes are followed, should be one of
* {@link #DEPTH_ZERO} or {@link #DEPTH_INFINITE}
* @return an array of include relations
* @throws CoreException
*/
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException;
/**
* Resolves the file that is included by the given include directive. May return <code>null</code>
* in case the file cannot be found. This is usually more efficient than using:
* <pre>
* getFile(include.getIncludesLocation())
* </pre>
* @param include
* @return the file included or <code>null</code>.
* @throws CoreException
* @since 4.0
*/
public IIndexFile resolveInclude(IIndexInclude include) throws CoreException;
/**
* Looks for a binding for the given ICElement. May return <code>null</code>.
* @param element an element a binding is searched for
* @return a binding for the element or <code>null</code>
* @throws CoreException
*/
public IIndexBinding findBinding(ICElement element) throws CoreException;
/**
* Searches for the binding of a name. The name may be originated by
* an AST or by a search in an index. May return <code>null</code>.
* @param name a name to find the binding for
* @return the binding or <code>null</code>
* @throws CoreException
*/
public IIndexBinding findBinding(IName name) throws CoreException;
/**
* Searches for all bindings with simple names that match the given pattern. In case a binding exists
* in multiple projects, no duplicate bindings are returned.
* This is fully equivalent to
* <pre>
* findBindings(new Pattern[]{pattern}, isFullyQualified, filter, monitor);
* </pre>
* @param pattern the pattern the name of the binding has to match.
* @param isFullyQualified if <code>true</code>, binding must be in global scope
* @param filter a filter that allows for skipping parts of the index
* @param monitor a monitor to report progress
* @return an array of bindings matching the pattern
* @throws CoreException
*/
public IIndexBinding[] findBindings(Pattern pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
/**
* Searches for all bindings with qualified names that seen as an array of simple names match the given array
* of patterns. In case a binding exists in multiple projects, no duplicate bindings are returned.
* You can search with an array of patterns that specifies a partial qualification only.
* @param patterns an array of patterns the names of the qualified name of the bindings have to match.
* @param isFullyQualified if <code>true</code>, the array of pattern specifies the fully qualified name
* @param filter a filter that allows for skipping parts of the index
* @param monitor a monitor to report progress
* @return an array of bindings matching the pattern
* @throws CoreException
*/
public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
/**
* Searches for all names that resolve to the given binding. You can limit the result to references, declarations
* or definitions, or a combination of those.
* @param binding a binding for which names are searched for
* @param flags a combination of {@link #FIND_DECLARATIONS}, {@link #FIND_DEFINITIONS} and {@link #FIND_REFERENCES}
* @return an array of names
* @throws CoreException
*/
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException;
/**
* Searches for all references that resolve to the given binding.
* This is fully equivalent to
* <pre>
* findNames(binding, IIndex.FIND_REFERENCES);
* </pre>
* @param binding a binding for which references are searched for
* @return an array of names
* @throws CoreException
*/
public IIndexName[] findReferences(IBinding binding) throws CoreException;
/**
* Searches for all declarations and definitions that resolve to the given binding.
* This is fully equivalent to
* <pre>
* findNames(binding, IIndex.FIND_DECLARATIONS_DEFINITIONS);
* </pre>
* @param binding a binding for which declarations are searched for
* @return an array of names
* @throws CoreException
*/
public IIndexName[] findDeclarations(IBinding binding) throws CoreException;
/**
* Searches for all definitions that resolve to the given binding.
* This is fully equivalent to
* <pre>
* findNames(binding, IIndex.FIND_DEFINITIONS);
* </pre>
* @param binding a binding for which declarations are searched for
* @return an array of names
* @throws CoreException
*/
public IIndexName[] findDefinitions(IBinding binding) throws CoreException;
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.core.runtime.CoreException;
/**
* Represents the semantics of a name in the index.
*
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndexBinding extends IBinding {
/**
* Returns the enclosing binding. May return <code>null</code>. To give an example, for a member function
* the parent binding would be the class defining the member.
* @throws CoreException
*/
IIndexBinding getParentBinding() throws CoreException;
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.core.runtime.CoreException;
/**
* Represents a file that has been indexed.
*
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndexFile {
/**
* Returns the absolute path of the location of the file.
* @return the absolute path of the location of the file
* @throws CoreException
*/
String getLocation() throws CoreException;
/**
* Returns all includes found in this file.
* @return an array of all includes found in this file
* @throws CoreException
*/
IIndexInclude[] getIncludes() throws CoreException;
/**
* Returns all macros defined in this file.
* @return an array of macros found in this file
* @throws CoreException
*/
IIndexMacro[] getMacros() throws CoreException;
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.core.runtime.CoreException;
/**
* Interface for an include directive stored in the index.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndexInclude {
IIndexInclude[] EMPTY_INCLUDES_ARRAY = new IIndexInclude[0];
/**
* Returns the file that contains this directive.
* @return the file performing the include
* @throws CoreException
*/
IIndexFile getIncludedBy() throws CoreException;
/**
* Returns the absolute path of the location of the file that contains this directive.
* @return the absolute path of the location of the file performing the include
* @throws CoreException
*/
String getIncludedByLocation() throws CoreException;
/**
* Returns the absolute path of the location of the file that is included by this directive.
* @return the absolute path of the location of the file that is included by this directive
* @throws CoreException
*/
String getIncludesLocation() throws CoreException;
}

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ILinkage;
/**
* Represents the linkage of a name in the index.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndexLinkage extends ILinkage {
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.parser.IMacro;
/**
* Represents a macro stored in the index.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndexMacro extends IMacro {
}

View file

@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.core.runtime.CoreException;
/**
* Starting point for working with the index. The manager can be obtained via
* {@link CCorePlugin#getIndexManager()}.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0
*/
public interface IIndexManager {
public final static int ADD_DEPENDENCIES = 0x1;
public final static int ADD_DEPENDENT = 0x2;
/**
* Returns the index for the given project.
* @param project the project to get the index for
* @return an index for the project
* @throws CoreException
*/
IIndex getIndex(ICProject project) throws CoreException;
/**
* Returns the index for the given projects.
* @param projects the projects to get the index for
* @return an index for the projects
* @throws CoreException
*/
IIndex getIndex(ICProject[] projects) throws CoreException;
/**
* Returns the index for the given project. You can specify to add dependencies or dependent projects.
* @param project the project to get the index for
* @param options <code>0</code> or a combination of {@link #ADD_DEPENDENCIES} and {@link #ADD_DEPENDENT}.
* @return an index for the project
* @throws CoreException
*/
IIndex getIndex(ICProject project, int options) throws CoreException;
/**
* Returns the index for the given projects. You can specify to add dependencies or dependent projects.
* @param projects the projects to get the index for
* @param options <code>0</code> or a combination of {@link #ADD_DEPENDENCIES} and {@link #ADD_DEPENDENT}.
* @return an index for the projects
* @throws CoreException
*/
IIndex getIndex(ICProject[] projects, int options) throws CoreException;
}

View file

@ -17,27 +17,31 @@ import org.eclipse.cdt.core.dom.IName;
/** /**
* Interface for all the names in the index. These constitute either a * Interface for all the names in the index. These constitute either a
* declaration or a reference. * declaration or a reference.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
* </p>
*
* @since 4.0 * @since 4.0
*/ */
public interface IIndexName extends IName { public interface IIndexName extends IName {
public static final IIndexName[] EMPTY_NAME_ARRAY = new IIndexName[0];
/** /**
* Returns the location of the file the name resides in. * Returns the location of the file the name resides in.
* @since 4.0
*/ */
public String getFileName(); public String getFileName();
/** /**
* Returns the character offset of the location of the name. * Returns the character offset of the location of the name.
* @since 4.0
*/ */
public int getNodeOffset(); public int getNodeOffset();
/** /**
* Returns the length of the name. * Returns the length of the name.
* @since 4.0
*/ */
public int getNodeLength(); public int getNodeLength();
} }

View file

@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ILinkage;
/**
* Can be subclassed and used for queries in the index.
* @since 4.0
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will
* work or that it will remain the same. Please do not use this API without
* consulting with the CDT team.
* </p>
*/
public class IndexFilter {
/**
* Returns whether or not to include objects of the given linkage in the query.
* @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor)
* @param linkage a linkage to be tested
* @return whether to include objects of the given linkage in the query.
*/
public boolean acceptLinkage(ILinkage linkage) {
return true;
}
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom;
import org.eclipse.cdt.core.dom.ILinkage;
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);
private String fID;
private Linkage(String id) {
fID= id;
}
public String getID() {
return fID;
}
}

View file

@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
/**
* Access to methods on scopes and bindings internal to the parser.
* @since 4.0
*/
public class ASTInternal {
public static IASTNode[] getDeclarationsOfBinding(IBinding binding) {
if( binding instanceof ICPPInternalBinding ) {
return ((ICPPInternalBinding)binding).getDeclarations();
}
assert false;
return IASTNode.EMPTY_NODE_ARRAY;
}
public static IASTNode getPhysicalNodeOfScope(IScope scope) throws DOMException {
if (scope instanceof IASTInternalScope) {
return ((IASTInternalScope) scope).getPhysicalNode();
}
assert false;
return null;
}
public static void flushCache(IScope scope) throws DOMException {
if (scope instanceof IASTInternalScope) {
((IASTInternalScope) scope).flushCache();
}
}
public static boolean isFullyCached(IScope scope) throws DOMException {
if (scope instanceof IASTInternalScope) {
return ((IASTInternalScope) scope).isFullyCached();
}
return true;
}
public static void setFullyCached(IScope scope, boolean val) throws DOMException {
if (scope instanceof IASTInternalScope) {
((IASTInternalScope) scope).setFullyCached(val);
}
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,9 +7,11 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTBuiltinSymbolProvider; import org.eclipse.cdt.core.dom.ast.IASTBuiltinSymbolProvider;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
@ -22,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType; import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType;
import org.eclipse.cdt.internal.core.dom.parser.c.CFunctionType; import org.eclipse.cdt.internal.core.dom.parser.c.CFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitFunction; import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitFunction;
@ -2352,6 +2355,9 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider {
return null; return null;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }
static public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter { static public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter {
@ -2436,5 +2442,8 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider {
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }
} }

View file

@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode;
/**
* Interface for methods on scopes that are internal to the AST.
* @since 4.0
*/
public interface IASTInternalScope {
/**
* Return the physical IASTNode that this scope was created for
* @return
*/
public IASTNode getPhysicalNode() throws DOMException;
/**
* Set whether or not all the names in this scope have been cached
*
* @param b
*/
public void setFullyCached(boolean b) throws DOMException;
/**
* whether or not this scope's cache contains all the names
*
* @return
*/
public boolean isFullyCached() throws DOMException;
/**
* clear the name cache in this scope
* @throws DOMException
*/
public void flushCache() throws DOMException;
}

View file

@ -17,6 +17,7 @@ package org.eclipse.cdt.internal.core.dom.parser;
import java.text.MessageFormat; import java.text.MessageFormat;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.parser.ParserMessages; import org.eclipse.cdt.internal.core.parser.ParserMessages;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -33,7 +35,7 @@ import org.eclipse.core.runtime.PlatformObject;
/** /**
* @author aniefer * @author aniefer
*/ */
public class ProblemBinding extends PlatformObject implements IProblemBinding, IType, IScope { public class ProblemBinding extends PlatformObject implements IProblemBinding, IType, IScope, IASTInternalScope {
protected final int id; protected final int id;
protected final char [] arg; protected final char [] arg;
protected IASTNode node; protected IASTNode node;
@ -208,4 +210,8 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
public void addBinding(IBinding binding) throws DOMException { public void addBinding(IBinding binding) throws DOMException {
throw new DOMException( this ); throw new DOMException( this );
} }
public ILinkage getLinkage() {
return Linkage.NO_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -21,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
@ -75,7 +77,7 @@ public abstract class CASTAmbiguity extends CASTNode {
if( scope != null ) if( scope != null )
{ {
try { try {
scope.flushCache(); ASTInternal.flushCache(scope);
} catch (DOMException e) { } catch (DOMException e) {
} }
} }

View file

@ -7,14 +7,17 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.dom.Linkage;
/** /**
* @author jcamelon * @author jcamelon
@ -141,4 +144,7 @@ public class CASTName extends CASTNode implements IASTName {
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -13,8 +13,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMResolver;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
@ -42,6 +40,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
@ -51,7 +50,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation; import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException; import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -68,7 +66,7 @@ public class CASTTranslationUnit extends CASTNode implements
private ILocationResolver resolver; private ILocationResolver resolver;
private IPDOM pdom; private IIndex index;
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
@ -125,11 +123,9 @@ public class CASTTranslationUnit extends CASTNode implements
*/ */
public IName[] getDeclarations(IBinding binding) { public IName[] getDeclarations(IBinding binding) {
IName[] names= getDeclarationsInAST(binding); IName[] names= getDeclarationsInAST(binding);
if (names.length == 0 && pdom != null) { if (names.length == 0 && index != null) {
try { try {
binding = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(binding); names = index.findDeclarations(binding);
if (binding != null)
names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDeclarations(binding);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return names; return names;
@ -156,11 +152,9 @@ public class CASTTranslationUnit extends CASTNode implements
*/ */
public IName[] getDefinitions(IBinding binding) { public IName[] getDefinitions(IBinding binding) {
IName[] names= getDefinitionsInAST(binding); IName[] names= getDefinitionsInAST(binding);
if (names.length == 0 && pdom != null) { if (names.length == 0 && index != null) {
try { try {
binding = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(binding); names= index.findDefinitions(binding);
if (binding != null)
names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDefinitions(binding);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return names; return names;
@ -566,12 +560,12 @@ public class CASTTranslationUnit extends CASTNode implements
return new GCCLanguage(); return new GCCLanguage();
} }
public IPDOM getIndex() { public IIndex getIndex() {
return pdom; return index;
} }
public void setIndex(IPDOM pdom) { public void setIndex(IIndex index) {
this.pdom = pdom; this.index = index;
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,6 +15,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
@ -28,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -156,4 +159,8 @@ public class CEnumeration extends PlatformObject implements IEnumeration {
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,6 +15,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -23,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -76,4 +79,7 @@ public class CEnumerator extends PlatformObject implements IEnumerator {
return enumeration; return enumeration;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,12 +15,15 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -91,4 +95,8 @@ public class CExternalVariable extends PlatformObject implements ICExternalBindi
public boolean isRegister() { public boolean isRegister() {
return false; return false;
} }
public ILinkage getLinkage() throws CoreException {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,9 +7,11 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -31,7 +33,9 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -431,4 +435,8 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
else else
bits &= ~FULLY_RESOLVED; bits &= ~FULLY_RESOLVED;
} }
public ILinkage getLinkage() throws CoreException {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,9 +7,11 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
@ -20,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -114,4 +117,8 @@ public class CKnRParameter extends PlatformObject implements IParameter {
return ((IASTSimpleDeclaration)declaration).getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_register; return ((IASTSimpleDeclaration)declaration).getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_register;
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,12 +15,14 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -71,4 +74,7 @@ public class CLabel extends PlatformObject implements ILabel {
return CVisitor.getContainingScope( labelStatement.getParent() ); return CVisitor.getContainingScope( labelStatement.getParent() );
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,10 +7,12 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
@ -26,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -184,4 +187,8 @@ public class CParameter extends PlatformObject implements IParameter {
} }
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -35,11 +35,12 @@ import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CScope implements ICScope { public class CScope implements ICScope, IASTInternalScope {
/** /**
* ISO C:99 6.2.3 there are seperate namespaces for various categories of * ISO C:99 6.2.3 there are seperate namespaces for various categories of
* identifiers: - label names ( labels have ICFunctionScope ) - tags of * identifiers: - label names ( labels have ICFunctionScope ) - tags of

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,10 +7,12 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
@ -31,6 +33,8 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -107,7 +111,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
IField[] fields = new IField[ size ]; IField[] fields = new IField[ size ];
if( size > 0 ){ if( size > 0 ){
ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope(); ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope();
if( scope.isFullyCached() ) if( ASTInternal.isFullyCached(scope) )
scope = null; scope = null;
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
IASTNode node = members[i]; IASTNode node = members[i];
@ -125,7 +129,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
} }
} }
if( scope != null ) if( scope != null )
scope.setFullyCached( true ); ASTInternal.setFullyCached(scope, true);
} }
return (IField[]) ArrayUtil.trim( IField.class, fields ); return (IField[]) ArrayUtil.trim( IField.class, fields );
} }
@ -142,7 +146,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
} }
ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope(); ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope();
if( scope != null && scope.isFullyCached() ){ if( scope != null && ASTInternal.isFullyCached(scope) ){
IBinding binding = scope.getBinding( name.toCharArray() ); IBinding binding = scope.getBinding( name.toCharArray() );
if( binding instanceof IField ) if( binding instanceof IField )
return (IField) binding; return (IField) binding;
@ -186,7 +190,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
} }
} }
if( scope != null ) if( scope != null )
scope.setFullyCached( true ); ASTInternal.setFullyCached(scope, true);
if( found != null ) if( found != null )
return found; return found;
} }
@ -237,4 +241,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
return type.isSameType( this ); return type.isSameType( this );
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,10 +7,12 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -18,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -98,4 +101,8 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer
return temp.isSameType( t ); return temp.isSameType( t );
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,10 +7,12 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -22,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -131,4 +134,8 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalBi
public boolean isRegister() { public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register ); return hasStorageClass( IASTDeclSpecifier.sc_register );
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
} }

View file

@ -7,12 +7,12 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMResolver;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
@ -89,10 +89,12 @@ import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -851,7 +853,7 @@ public class CVisitor {
binding = new CParameter( name ); binding = new CParameter( name );
} }
try { try {
if( scope != null && scope.getPhysicalNode() instanceof IASTTranslationUnit ){ if( scope != null && ASTInternal.getPhysicalNodeOfScope(scope) instanceof IASTTranslationUnit ){
return binding; return binding;
} }
} catch (DOMException e) { } catch (DOMException e) {
@ -1205,7 +1207,7 @@ public class CVisitor {
if( prefix ) if( prefix )
scope = null; scope = null;
if( scope != null && scope.isFullyCached() ){ if( scope != null && ASTInternal.isFullyCached(scope) ){
try { try {
binding = scope.getBinding( name, true ); binding = scope.getBinding( name, true );
} catch ( DOMException e ) { } catch ( DOMException e ) {
@ -1278,7 +1280,7 @@ public class CVisitor {
} }
if( scope != null ) { if( scope != null ) {
try { try {
scope.setFullyCached( true ); ASTInternal.setFullyCached(scope, true);
} catch ( DOMException e ) { } catch ( DOMException e ) {
} }
} }
@ -1305,9 +1307,13 @@ public class CVisitor {
if( blockItem != null) { if( blockItem != null) {
// We're at the end of our rope, check the PDOM if we can // We're at the end of our rope, check the PDOM if we can
IASTTranslationUnit tu = (IASTTranslationUnit)blockItem; IASTTranslationUnit tu = (IASTTranslationUnit)blockItem;
IPDOM pdom = tu.getIndex(); IIndex index = tu.getIndex();
if (pdom != null) { if (index != null) {
binding = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).resolveBinding(name); try {
binding = index.findBinding(name);
} catch (CoreException e) {
CCorePlugin.log(e);
}
} }
if (binding == null) if (binding == null)
@ -1915,7 +1921,7 @@ public class CVisitor {
} }
public static IBinding[] findBindings( IScope scope, String name ) throws DOMException{ public static IBinding[] findBindings( IScope scope, String name ) throws DOMException{
IASTNode node = scope.getPhysicalNode(); IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope);
if( node instanceof IASTFunctionDefinition ) if( node instanceof IASTFunctionDefinition )
node = ((IASTFunctionDefinition)node).getBody(); node = ((IASTFunctionDefinition)node).getBody();

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
public abstract class CPPASTAmbiguity extends CPPASTNode { public abstract class CPPASTAmbiguity extends CPPASTNode {
@ -76,7 +77,7 @@ public abstract class CPPASTAmbiguity extends CPPASTNode {
if( scope != null ) if( scope != null )
{ {
try { try {
scope.flushCache(); ASTInternal.flushCache(scope);
} catch (DOMException de) {} } catch (DOMException de) {}
} }
} }

View file

@ -10,11 +10,13 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.dom.Linkage;
/** /**
* @author jcamelon * @author jcamelon
@ -151,5 +153,4 @@ public class CPPASTName extends CPPASTNode implements IASTName {
} }
return false; return false;
} }
} }

View file

@ -10,6 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/** /**
@ -17,6 +19,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
*/ */
public abstract class CPPASTNode extends ASTNode { public abstract class CPPASTNode extends ASTNode {
// A little empty isn't it... public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
@ -20,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
/** /**
* @author jcamelon * @author jcamelon
@ -276,6 +278,4 @@ public class CPPASTQualifiedName extends CPPASTNode implements
} }
return false; return false;
} }
} }

View file

@ -13,8 +13,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMResolver;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
@ -56,6 +54,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; 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.ICPPScope;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
@ -67,7 +66,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException; import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -83,7 +81,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
private ILocationResolver resolver; private ILocationResolver resolver;
private IPDOM pdom; private IIndex index;
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
@ -189,11 +187,9 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
public IName[] getDeclarations(IBinding b) { public IName[] getDeclarations(IBinding b) {
IName[] names = getDeclarationsInAST(b); IName[] names = getDeclarationsInAST(b);
if (names.length == 0 && pdom != null) { if (names.length == 0 && index != null) {
try { try {
b = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(b); names = index.findDeclarations(b);
if (binding != null)
names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDeclarations(b);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return names; return names;
@ -220,11 +216,9 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
public IName[] getDefinitions(IBinding binding) { public IName[] getDefinitions(IBinding binding) {
IName[] names = getDefinitionsInAST(binding); IName[] names = getDefinitionsInAST(binding);
if (names.length == 0 && pdom != null) { if (names.length == 0 && index != null) {
try { try {
binding = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(binding); names = index.findDefinitions(binding);
if (binding != null)
names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDefinitions(binding);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return names; return names;
@ -609,12 +603,12 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
return new GPPLanguage(); return new GPPLanguage();
} }
public IPDOM getIndex() { public IIndex getIndex() {
return pdom; return index;
} }
public void setIndex(IPDOM pdom) { public void setIndex(IIndex pdom) {
this.pdom = pdom; this.index = pdom;
} }
} }

View file

@ -13,6 +13,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -30,6 +31,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.CoreException;
/** /**
* @author aniefer * @author aniefer
@ -197,5 +200,4 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
public ICPPClassType[] getNestedClasses() throws DOMException { public ICPPClassType[] getNestedClasses() throws DOMException {
return ICPPClassType.EMPTY_CLASS_ARRAY; return ICPPClassType.EMPTY_CLASS_ARRAY;
} }
} }

View file

@ -33,11 +33,13 @@ import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPClassInstanceScope implements ICPPClassScope { public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope {
private static final char[] CONSTRUCTOR_KEY = "!!!CTOR!!!".toCharArray(); //$NON-NLS-1$ private static final char[] CONSTRUCTOR_KEY = "!!!CTOR!!!".toCharArray(); //$NON-NLS-1$
private CharArrayObjectMap bindings; private CharArrayObjectMap bindings;
@ -251,14 +253,17 @@ public class CPPClassInstanceScope implements ICPPClassScope {
public IASTNode getPhysicalNode() throws DOMException { public IASTNode getPhysicalNode() throws DOMException {
ICPPClassType cls = getOriginalClass(); ICPPClassType cls = getOriginalClass();
ICPPClassScope scope = (ICPPClassScope)cls.getCompositeScope(); ICPPClassScope scope = (ICPPClassScope)cls.getCompositeScope();
if( scope != null )
return scope.getPhysicalNode();
if( cls instanceof ICPPInternalBinding ){ IASTNode node= ASTInternal.getPhysicalNodeOfScope(scope);
IASTNode [] nds = ((ICPPInternalBinding)cls).getDeclarations(); if (node != null) {
if( nds != null && nds.length > 0 ) return node;
return nds[0];
} }
IASTNode[] nds= ASTInternal.getDeclarationsOfBinding(cls);
if( nds != null && nds.length > 0 )
return nds[0];
return null; return null;
} }

View file

@ -181,5 +181,4 @@ public class CPPClassSpecialization extends CPPSpecialization implements
public ICPPClassType[] getNestedClasses() throws DOMException { public ICPPClassType[] getNestedClasses() throws DOMException {
return ICPPClassType.EMPTY_CLASS_ARRAY; return ICPPClassType.EMPTY_CLASS_ARRAY;
} }
} }

View file

@ -50,6 +50,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType.CPPClassTypeProblem; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType.CPPClassTypeProblem;
/** /**
@ -389,7 +390,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
} }
ICPPClassScope scope = (ICPPClassScope) getCompositeScope(); ICPPClassScope scope = (ICPPClassScope) getCompositeScope();
if( scope.isFullyCached() ) if( ASTInternal.isFullyCached(scope))
return ((CPPClassScope)scope).getConstructors( true ); return ((CPPClassScope)scope).getConstructors( true );
IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers(); IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers();

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Nov 29, 2004 * Created on Nov 29, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
@ -47,12 +49,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -373,7 +376,7 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI
{ {
while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){ while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){
try { try {
scope = (ICPPScope) scope.getParent(); scope = scope.getParent();
} catch (DOMException e1) { } catch (DOMException e1) {
} }
} }
@ -678,7 +681,7 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI
} }
ICPPClassScope scope = (ICPPClassScope) getCompositeScope(); ICPPClassScope scope = (ICPPClassScope) getCompositeScope();
if( scope.isFullyCached() ) if( ASTInternal.isFullyCached(scope) )
return ((CPPClassScope)scope).getConstructors( true ); return ((CPPClassScope)scope).getConstructors( true );
IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers(); IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers();
@ -821,4 +824,8 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI
} }
return (ICPPClassType[]) ArrayUtil.trim( ICPPClassType.class, result ); return (ICPPClassType[]) ArrayUtil.trim( ICPPClassType.class, result );
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -13,11 +13,14 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -66,4 +69,8 @@ public class CPPCompositeBinding extends PlatformObject implements IBinding {
return bindings; return bindings;
} }
public ILinkage getLinkage() throws CoreException {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -14,6 +14,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -21,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -155,4 +157,7 @@ public class CPPDelegate extends PlatformObject implements ICPPDelegate, ICPPInt
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -14,6 +14,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -188,4 +190,8 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP
return ((ITypedef)type).isSameType( this ); return ((ITypedef)type).isSameType( this );
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -14,6 +14,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -152,4 +154,7 @@ public class CPPEnumerator extends PlatformObject implements IEnumerator, ICPPIn
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Nov 29, 2004 * Created on Nov 29, 2004
@ -28,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/** /**
* @author aniefer * @author aniefer
@ -87,7 +89,7 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
char [] myName = getNameCharArray(); char [] myName = getNameCharArray();
ICPPClassScope scope = (ICPPClassScope) getScope(); ICPPClassScope scope = (ICPPClassScope) getScope();
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) scope.getPhysicalNode(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
IASTDeclaration [] members = compSpec.getMembers(); IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){ for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof IASTSimpleDeclaration ){ if( members[i] instanceof IASTSimpleDeclaration ){

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 1, 2004 * Created on Dec 1, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -36,6 +38,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -172,7 +176,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
//implicit binding //implicit binding
IScope scope = getScope(); IScope scope = getScope();
try { try {
IASTNode node = scope.getPhysicalNode(); IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope);
tu = node.getTranslationUnit(); tu = node.getTranslationUnit();
} catch ( DOMException e ) { } catch ( DOMException e ) {
} }
@ -592,4 +596,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} }
return false; return false;
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -32,6 +33,7 @@ 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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/** /**
* @author aniefer * @author aniefer
@ -84,7 +86,7 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
IFunctionType ftype = getType(); IFunctionType ftype = getType();
IType [] params = ftype.getParameterTypes(); IType [] params = ftype.getParameterTypes();
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) getScope().getPhysicalNode(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(getScope());
IASTDeclaration [] members = compSpec.getMembers(); IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){ for( int i = 0; i < members.length; i++ ){
IASTDeclarator dtor = null; IASTDeclarator dtor = null;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,12 +15,14 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -143,5 +146,8 @@ public class CPPLabel extends PlatformObject implements ILabel, ICPPInternalBind
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 1, 2004 * Created on Dec 1, 2004
@ -33,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/** /**
* @author aniefer * @author aniefer
@ -118,7 +120,7 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
char [] myName = getNameCharArray(); char [] myName = getNameCharArray();
ICPPClassScope scope = (ICPPClassScope) getScope(); ICPPClassScope scope = (ICPPClassScope) getScope();
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) scope.getPhysicalNode(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
IASTDeclaration [] members = compSpec.getMembers(); IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){ for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof IASTSimpleDeclaration ){ if( members[i] instanceof IASTSimpleDeclaration ){

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Mar 31, 2005 * Created on Mar 31, 2005
@ -30,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/** /**
* @author aniefer * @author aniefer
@ -64,7 +66,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
if( scope instanceof ICPPTemplateScope ) if( scope instanceof ICPPTemplateScope )
scope = scope.getParent(); scope = scope.getParent();
ICPPClassScope clsScope = (ICPPClassScope) scope; ICPPClassScope clsScope = (ICPPClassScope) scope;
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) clsScope.getPhysicalNode(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(clsScope);
IASTDeclaration [] members = compSpec.getMembers(); IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){ for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof ICPPASTTemplateDeclaration ){ if( members[i] instanceof ICPPASTTemplateDeclaration ){

View file

@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 1, 2004 * Created on Dec 1, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -37,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -240,7 +243,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/ */
public String getName() { public String getName() {
return tu != null ? null : namespaceDefinitions[0].toString(); //$NON-NLS-1$ return tu != null ? null : namespaceDefinitions[0].toString();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -363,4 +366,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
return IBinding.EMPTY_BINDING_ARRAY; return IBinding.EMPTY_BINDING_ARRAY;
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,6 +15,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -24,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; 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.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -151,4 +154,8 @@ public class CPPNamespaceAlias extends PlatformObject implements ICPPNamespaceAl
public IBinding[] getMemberBindings() throws DOMException { public IBinding[] getMemberBindings() throws DOMException {
return namespace.getMemberBindings(); return namespace.getMemberBindings();
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 10, 2004 * Created on Dec 10, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -28,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -280,4 +283,8 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
} }
return null; return null;
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -7,13 +7,14 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Nov 29, 2004 * Created on Nov 29, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -23,16 +24,18 @@ 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.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.runtime.CoreException;
/** /**
* @author aniefer * @author aniefer
*/ */
abstract public class CPPScope implements ICPPScope{ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
public static class CPPScopeProblem extends ProblemBinding implements ICPPScope { public static class CPPScopeProblem extends ProblemBinding implements ICPPScope {
public CPPScopeProblem( IASTNode node, int id, char[] arg ) { public CPPScopeProblem( IASTNode node, int id, char[] arg ) {
super( node, id, arg ); super( node, id, arg );
@ -125,13 +128,18 @@ abstract public class CPPScope implements ICPPScope{
} }
return (IBinding) obj; return (IBinding) obj;
} else { } else {
IPDOM pdom = name.getTranslationUnit().getIndex(); IIndex index = name.getTranslationUnit().getIndex();
if (pdom != null) { if (index != null) {
// Try looking this up in the PDOM // Try looking this up in the PDOM
if (physicalNode instanceof ICPPASTNamespaceDefinition) { if (physicalNode instanceof ICPPASTNamespaceDefinition) {
ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode; ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode;
IASTName nsname = nsdef.getName(); IASTName nsname = nsdef.getName();
IBinding nsbinding = ((PDOM)pdom).resolveBinding(nsname); IBinding nsbinding= null;
try {
nsbinding = index.findBinding(nsname);
} catch (CoreException e) {
CCorePlugin.log(e);
}
if (nsbinding instanceof ICPPScope) if (nsbinding instanceof ICPPScope)
return ((ICPPScope)nsbinding).getBinding(name, forceResolve); return ((ICPPScope)nsbinding).getBinding(name, forceResolve);
} }

View file

@ -7,14 +7,14 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 8, 2004 * Created on Dec 8, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMResolver;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
@ -117,16 +117,19 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil.ArrayWrapper; import org.eclipse.cdt.core.parser.util.ArrayUtil.ArrayWrapper;
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.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.runtime.CoreException;
/** /**
* @author aniefer * @author aniefer
@ -136,7 +139,7 @@ public class CPPSemantics {
protected static final ASTNodeProperty STRING_LOOKUP_PROPERTY = new ASTNodeProperty("CPPSemantics.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$ protected static final ASTNodeProperty STRING_LOOKUP_PROPERTY = new ASTNodeProperty("CPPSemantics.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$
public static final char[] EMPTY_NAME_ARRAY = new char[0]; public static final char[] EMPTY_NAME_ARRAY = new char[0];
public static final String EMPTY_NAME = ""; //$NON-NLS-1$ public static final String EMPTY_NAME = ""; //$NON-NLS-1$
public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '}; //$NON-NLS-1$ public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '};
public static final IType VOID_TYPE = new CPPBasicType( IBasicType.t_void, 0 ); public static final IType VOID_TYPE = new CPPBasicType( IBasicType.t_void, 0 );
static protected class LookupData static protected class LookupData
@ -749,9 +752,13 @@ public class CPPSemantics {
} }
if( binding == null || binding instanceof IProblemBinding ){ if( binding == null || binding instanceof IProblemBinding ){
// Let's try the pdom // Let's try the pdom
IPDOM pdom = name.getTranslationUnit().getIndex(); IIndex index = name.getTranslationUnit().getIndex();
if (pdom != null) { if (index != null) {
binding = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).resolveBinding(name); try {
binding = index.findBinding(name);
} catch (CoreException e) {
CCorePlugin.log(e);
}
} }
// If we're still null... // If we're still null...
@ -1015,7 +1022,7 @@ public class CPPSemantics {
ArrayWrapper directives = null; ArrayWrapper directives = null;
if( !data.usingDirectivesOnly ){ if( !data.usingDirectivesOnly ){
if( scope.isFullyCached() && !data.prefixLookup && data.astName != null ){ if( ASTInternal.isFullyCached(scope) && !data.prefixLookup && data.astName != null ){
IBinding binding = data.prefixLookup ? null : scope.getBinding( data.astName, true ); IBinding binding = data.prefixLookup ? null : scope.getBinding( data.astName, true );
if( binding != null && if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) || ( CPPSemantics.declaredBefore( binding, data.astName ) ||
@ -1156,7 +1163,7 @@ public class CPPSemantics {
//is circular inheritance //is circular inheritance
if( ! data.inheritanceChain.containsKey( parent ) ){ if( ! data.inheritanceChain.containsKey( parent ) ){
//is this name define in this scope? //is this name define in this scope?
if( data.astName != null && !data.prefixLookup && parent.isFullyCached() ) if( data.astName != null && !data.prefixLookup && ASTInternal.isFullyCached(parent) )
inherited = parent.getBinding( data.astName, true ); inherited = parent.getBinding( data.astName, true );
else else
inherited = lookupInScope( data, parent, null ); inherited = lookupInScope( data, parent, null );
@ -1363,7 +1370,7 @@ public class CPPSemantics {
static protected IASTName[] lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem ) throws DOMException { static protected IASTName[] lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem ) throws DOMException {
Object possible = null; Object possible = null;
IASTNode [] nodes = null; IASTNode [] nodes = null;
IASTNode parent = scope.getPhysicalNode(); IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope);
IASTName [] namespaceDefs = null; IASTName [] namespaceDefs = null;
int namespaceIdx = -1; int namespaceIdx = -1;
@ -1521,7 +1528,7 @@ public class CPPSemantics {
} }
scope.setFullyCached( true ); ASTInternal.setFullyCached(scope, true);
return found; return found;
} }
@ -1546,7 +1553,7 @@ public class CPPSemantics {
ArrayWrapper usings = new ArrayWrapper(); ArrayWrapper usings = new ArrayWrapper();
boolean found = false; boolean found = false;
if( temp.isFullyCached() && !data.prefixLookup ){ if( ASTInternal.isFullyCached(temp) && !data.prefixLookup ){
IBinding binding = temp.getBinding( data.astName, true ); IBinding binding = temp.getBinding( data.astName, true );
if( binding != null && if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) || ( CPPSemantics.declaredBefore( binding, data.astName ) ||
@ -2155,7 +2162,7 @@ public class CPPSemantics {
if( scope instanceof ICPPClassScope ){ if( scope instanceof ICPPClassScope ){
cls = ((ICPPClassScope)scope).getClassType(); cls = ((ICPPClassScope)scope).getClassType();
} else { } else {
cls = new CPPClassType.CPPClassTypeProblem( scope.getPhysicalNode(), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray() ); cls = new CPPClassType.CPPClassTypeProblem(ASTInternal.getPhysicalNodeOfScope(scope), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray() );
} }
if( cls instanceof ICPPClassTemplate ){ if( cls instanceof ICPPClassTemplate ){
IBinding within = CPPTemplates.instantiateWithinClassTemplate( (ICPPClassTemplate) cls ); IBinding within = CPPTemplates.instantiateWithinClassTemplate( (ICPPClassTemplate) cls );
@ -3211,7 +3218,7 @@ public class CPPSemantics {
public static IBinding[] findBindings( IScope scope, char []name, boolean qualified ) throws DOMException{ public static IBinding[] findBindings( IScope scope, char []name, boolean qualified ) throws DOMException{
CPPASTName astName = new CPPASTName(); CPPASTName astName = new CPPASTName();
astName.setName( name ); astName.setName( name );
astName.setParent( scope.getPhysicalNode() ); astName.setParent( ASTInternal.getPhysicalNodeOfScope(scope));
astName.setPropertyInParent( STRING_LOOKUP_PROPERTY ); astName.setPropertyInParent( STRING_LOOKUP_PROPERTY );
LookupData data = new LookupData( astName ); LookupData data = new LookupData( astName );

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* / * /
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,6 +15,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -22,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -114,5 +117,7 @@ public abstract class CPPSpecialization extends PlatformObject implements ICPPSp
public boolean isGloballyQualified() throws DOMException { public boolean isGloballyQualified() throws DOMException {
return ((ICPPInternalBinding)specialized).isGloballyQualified(); return ((ICPPInternalBinding)specialized).isGloballyQualified();
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Mar 14, 2005 * Created on Mar 14, 2005
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
@ -41,6 +43,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -387,4 +390,8 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
public IASTNode getDefinition() { public IASTNode getDefinition() {
return definition; return definition;
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Mar 11, 2005 * Created on Mar 11, 2005
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -20,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -153,4 +156,8 @@ public class CPPTemplateParameter extends PlatformObject implements ICPPTemplate
} }
} }
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Dec 11, 2004 * Created on Dec 11, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -23,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; 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.ITypeContainer;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -215,4 +218,8 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
} }
} }
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,6 +15,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -24,6 +26,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -146,7 +150,7 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
if( t instanceof ICPPClassType ){ if( t instanceof ICPPClassType ){
IScope s = ((ICPPClassType)t).getCompositeScope(); IScope s = ((ICPPClassType)t).getCompositeScope();
if( s != null && s.isFullyCached() ) if( s != null && ASTInternal.isFullyCached(s) )
result = s.getBinding( name, true ); result = s.getBinding( name, true );
// CPPSemantics.LookupData data = CPPSemantics.createLookupData( name, false ); // CPPSemantics.LookupData data = CPPSemantics.createLookupData( name, false );
// CPPSemantics.lookup( data, s ); // CPPSemantics.lookup( data, s );
@ -156,4 +160,8 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
} }
return result; return result;
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -23,11 +23,12 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPUnknownScope implements ICPPScope { public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
private IBinding binding = null; private IBinding binding = null;
private IASTName scopeName = null; private IASTName scopeName = null;
private CharArrayObjectMap map = null; private CharArrayObjectMap map = null;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
@ -14,6 +15,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -25,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -152,4 +155,7 @@ public class CPPUsingDeclaration extends PlatformObject implements ICPPUsingDecl
public void removeDeclaration( IASTNode node ) { public void removeDeclaration( IASTNode node ) {
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,12 +7,14 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Nov 29, 2004 * Created on Nov 29, 2004
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -28,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -368,4 +371,8 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
public boolean isRegister() { public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register ); return hasStorageClass( IASTDeclSpecifier.sc_register );
} }
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
} }

View file

@ -141,6 +141,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; 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.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -618,7 +619,7 @@ public class CPPVisitor {
ICPPASTCompositeTypeSpecifier clsTypeSpec; ICPPASTCompositeTypeSpecifier clsTypeSpec;
try { try {
IASTNode node = ((ICPPClassScope)containingScope).getPhysicalNode(); IASTNode node = ASTInternal.getPhysicalNodeOfScope(containingScope);
if (node instanceof ICPPASTCompositeTypeSpecifier) if (node instanceof ICPPASTCompositeTypeSpecifier)
clsTypeSpec = (ICPPASTCompositeTypeSpecifier)node; clsTypeSpec = (ICPPASTCompositeTypeSpecifier)node;
else else
@ -1639,7 +1640,7 @@ public class CPPVisitor {
IASTNode node = null; IASTNode node = null;
while( scope != null ){ while( scope != null ){
if( scope instanceof ICPPBlockScope ){ if( scope instanceof ICPPBlockScope ){
node = ((ICPPBlockScope)scope).getPhysicalNode(); node = ASTInternal.getPhysicalNodeOfScope(scope);
if( node.getParent() instanceof IASTFunctionDefinition ) if( node.getParent() instanceof IASTFunctionDefinition )
break; break;
} }

View file

@ -0,0 +1,311 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IName;
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.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
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.core.model.ICElement;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
public class CIndex implements IIndex {
final private IIndexFragment[] fFragments;
final private int fPrimaryFragmentCount;
private int fReadLock;
public CIndex(IIndexFragment[] fragments, int primaryFragmentCount) {
fFragments= fragments;
fPrimaryFragmentCount= primaryFragmentCount;
}
public CIndex(IIndexFragment[] fragments) {
this(fragments, fragments.length);
}
public IIndexBinding findBinding(ICElement element) throws CoreException {
// mstodo ICElement to IBinding
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 null;
}
public IIndexBinding[] findBindings(Pattern pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
return findBindings(new Pattern[]{pattern}, isFullyQualified, filter, monitor);
}
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))));
}
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);
if (adaptedBinding != null) {
result.addAll(Arrays.asList(fFragments[i].findNames(adaptedBinding, flags)));
}
}
return (IIndexName[]) result.toArray(new IIndexName[result.size()]);
}
public IIndexName[] findDeclarations(IBinding binding) throws CoreException {
return findNames(binding, FIND_DECLARATIONS_DEFINITIONS);
}
public IIndexName[] findDefinitions(IBinding binding) throws CoreException {
return findNames(binding, FIND_DEFINITIONS);
}
public IIndexName[] findReferences(IBinding binding) throws CoreException {
return findNames(binding, FIND_REFERENCES);
}
public IIndexFile getFile(IPath location) throws CoreException {
IIndexFile result= null;
for (int i = 0; result==null && i < fPrimaryFragmentCount; i++) {
result= fFragments[i].getFile(location);
}
return result;
}
public IIndexFile resolveInclude(IIndexInclude include) throws CoreException {
IIndexFragmentInclude fragmentInclude = (IIndexFragmentInclude) include;
IIndexFragment frag= fragmentInclude.getFragment();
if (isPrimaryFragment(frag)) {
IIndexFile result= fragmentInclude.getIncludes();
if (result != null) {
return result;
}
}
Path location= new Path(include.getIncludesLocation());
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragment otherFrag = fFragments[i];
if (otherFrag != frag) {
IIndexFile result= otherFrag.getFile(location);
if (result != null) {
return result;
}
}
}
return null;
}
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());
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
}
public void findIncludedBy(List in, List out, int depth, HashSet handled) throws CoreException {
List nextLevel= depth != 0 ? new LinkedList() : null;
for (Iterator it= in.iterator(); it.hasNext(); ) {
IIndexFragmentFile file = (IIndexFragmentFile) it.next();
for (int j= 0; j < fPrimaryFragmentCount; j++) {
IIndexInclude[] includedBy= fFragments[j].findIncludedBy(file);
for (int k= 0; k < includedBy.length; k++) {
IIndexInclude include = includedBy[k];
if (handled.add(include.getIncludedByLocation())) {
out.add(include);
if (depth != 0) {
nextLevel.add(include.getIncludedBy());
}
}
}
}
}
if (depth == 0 || nextLevel.isEmpty()) {
return;
}
if (depth > 0) {
depth--;
}
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());
result= result.subList(1, result.size());
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
}
public void findIncludes(List in, List out, int depth, HashSet handled) throws CoreException {
List nextLevel= depth != 0 ? new LinkedList() : null;
for (Iterator it= in.iterator(); it.hasNext(); ) {
IIndexFragmentFile file = (IIndexFragmentFile) it.next();
IIndexFragment frag= file.getIndexFragment();
if (isPrimaryFragment(frag)) {
IIndexInclude[] includes= file.getIncludes();
for (int k= 0; k < includes.length; k++) {
IIndexInclude include = includes[k];
if (handled.add(include.getIncludesLocation())) {
out.add(include);
if (depth != 0) {
IIndexFile includedByFile= resolveInclude(include);
if (includedByFile != null) {
nextLevel.add(includedByFile);
}
}
}
}
}
}
if (depth == 0 || nextLevel.isEmpty()) {
return;
}
if (depth > 0) {
depth--;
}
findIncludes(nextLevel, out, depth, handled);
}
public synchronized void acquireReadLock() throws InterruptedException {
if (++fReadLock == 1) {
int i= 0;
try {
for (i = 0; i < fFragments.length; i++) {
fFragments[i].acquireReadLock();
}
}
finally {
if (i < fFragments.length) {
// rollback
fReadLock--;
while (--i >= 0) {
fFragments[i].releaseReadLock();
}
}
}
}
}
public synchronized void releaseReadLock() {
if (--fReadLock == 0) {
for (int i=0; i < fFragments.length; i++) {
fFragments[i].releaseReadLock();
}
}
}
protected synchronized int getReadLockCount() {
return fReadLock;
}
public long getLastWriteAccess() {
long result= 0;
for (int i=0; i < fFragments.length; i++) {
result= Math.max(result, fFragments[i].getLastWriteAccess());
}
return result;
}
}

View file

@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IName;
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.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
final public class EmptyCIndex implements IIndex {
public static IIndex INSTANCE= new EmptyCIndex();
private EmptyCIndex() {
}
public IIndexBinding findBinding(ICElement element) {
return null;
}
public IIndexName[] findDeclarations(IBinding binding) {
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
public IIndexName[] findDefinitions(IBinding binding) {
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
public IIndexName[] findReferences(IBinding binding) {
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
public IIndexName[] findNames(IBinding binding, int flags) {
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
public IIndexFile getFile(IPath location) {
return null;
}
public IIndexFile resolveInclude(IIndexInclude include) {
return null;
}
public IIndexInclude[] findIncludedBy(IIndexFile file) {
return IIndexInclude.EMPTY_INCLUDES_ARRAY;
}
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) {
return IIndexInclude.EMPTY_INCLUDES_ARRAY;
}
public IIndexInclude[] findIncludes(IIndexFile file) {
return IIndexInclude.EMPTY_INCLUDES_ARRAY;
}
public IIndexInclude[] findIncludes(IIndexFile file, int depth) {
return IIndexInclude.EMPTY_INCLUDES_ARRAY;
}
public void acquireReadLock() {
}
public void releaseReadLock() {
}
public long getLastWriteAccess() {
return 0;
}
public IIndexBinding findBinding(IName name) {
return null;
}
public IIndexBinding[] findBindings(Pattern pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) {
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
public IIndexBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
}

Some files were not shown because too many files have changed in this diff Show more