1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

172454: additionally distinguish bindings by type constant in btree indices

This commit is contained in:
Andrew Ferguson 2007-02-02 20:49:17 +00:00
parent 254fd3131e
commit 55dcea05dd
10 changed files with 104 additions and 43 deletions

View file

@ -399,7 +399,7 @@ public class IndexBugsTests extends BaseTestCase {
// typedef struct S20070201 { // typedef struct S20070201 {
// int a; // int a;
// } S20070201; // } S20070201;
public void _test172454_1() throws Exception { public void test172454_1() throws Exception {
waitForIndexer(); waitForIndexer();
String content= getContentsForTest(1)[0].toString(); String content= getContentsForTest(1)[0].toString();
@ -434,7 +434,7 @@ public class IndexBugsTests extends BaseTestCase {
// typedef struct S20070201 { // typedef struct S20070201 {
// int a; // int a;
// } S20070201; // } S20070201;
public void _test172454_2() throws Exception { public void test172454_2() throws Exception {
waitForIndexer(); waitForIndexer();
String content= getContentsForTest(1)[0].toString(); String content= getContentsForTest(1)[0].toString();
@ -447,7 +447,7 @@ public class IndexBugsTests extends BaseTestCase {
assertEquals(2, bindings.length); assertEquals(2, bindings.length);
IBinding struct, typedef; IBinding struct, typedef;
if (bindings[0] instanceof ICCompositeTypeScope) { if (bindings[0] instanceof ICPPClassType) {
struct= bindings[0]; struct= bindings[0];
typedef= bindings[1]; typedef= bindings[1];
} }
@ -456,9 +456,12 @@ public class IndexBugsTests extends BaseTestCase {
typedef= bindings[0]; typedef= bindings[0];
} }
assertTrue(struct instanceof ICompositeType); assertTrue(struct instanceof ICPPClassType);
assertTrue(((ICPPClassType)struct).getKey()==ICompositeType.k_struct);
assertTrue(typedef instanceof ITypedef); assertTrue(typedef instanceof ITypedef);
assertTrue(((ITypedef) typedef).getType() instanceof ICCompositeTypeScope); IType aliased = ((ITypedef) typedef).getType();
assertTrue(aliased instanceof ICPPClassType);
assertTrue(((ICPPClassType)aliased).getKey()==ICompositeType.k_struct);
assertTrue(((ITypedef) typedef).isSameType((ICompositeType) struct)); assertTrue(((ITypedef) typedef).isSameType((ICompositeType) struct));
} }
finally { finally {

View file

@ -16,6 +16,8 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
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.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -79,6 +81,20 @@ public class IndexCBindingResolutionTest extends IndexBindingResolutionTestBase
IBinding b21 = getBindingFromASTName("a); /*func5*/", 1); IBinding b21 = getBindingFromASTName("a); /*func5*/", 1);
} }
// typedef struct S {int a;} S;
// typedef enum E {A,B} E;
// struct A {
// S *s;
// E *e;
// };
public void testTypedef() {
IBinding b1 = getBindingFromASTName("S", 1);
assertTrue(b1 instanceof ICompositeType);
IBinding b2 = getBindingFromASTName("E", 1);
assertTrue(b2 instanceof IEnumeration);
}
public void _testEnumeratorInFileScope() {fail("todo");} public void _testEnumeratorInFileScope() {fail("todo");}
public void _testEnumeratorInStructScope() {fail("todo");} public void _testEnumeratorInStructScope() {fail("todo");}
public void _testEnumeratorInUnionScope() {fail("todo");} public void _testEnumeratorInUnionScope() {fail("todo");}

View file

@ -17,6 +17,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
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.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.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
@ -958,4 +959,19 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
assertEquals(4, index.findNames(binding2, IIndex.FIND_DECLARATIONS).length); assertEquals(4, index.findNames(binding2, IIndex.FIND_DECLARATIONS).length);
} }
// typedef struct S {int a;} S;
// typedef enum E {A,B} E;
// class A {
// public:
// S *s;
// E *e;
// };
public void testTypedef() {
IBinding b1 = getBindingFromASTName("S", 1);
assertTrue(b1 instanceof ICPPClassType);
IBinding b2 = getBindingFromASTName("E", 1);
assertTrue(b2 instanceof IEnumeration);
}
} }

View file

@ -34,7 +34,13 @@ public class FindBinding {
public int compare(int record1, int record2) throws CoreException { public int compare(int record1, int record2) throws CoreException {
IString nm1 = PDOMNamedNode.getDBName(pdom, record1); IString nm1 = PDOMNamedNode.getDBName(pdom, record1);
IString nm2 = PDOMNamedNode.getDBName(pdom, record2); IString nm2 = PDOMNamedNode.getDBName(pdom, record2);
return nm1.compare(nm2); int cmp = nm1.compare(nm2);
if(cmp == 0) {
int t1 = PDOMNamedNode.getNodeType(pdom, record1);
int t2 = PDOMNamedNode.getNodeType(pdom, record2);
return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0);
}
return cmp;
} }
} }
@ -46,7 +52,17 @@ public class FindBinding {
return nm1.compare(name); return nm1.compare(name);
} }
public boolean visit(int record) throws CoreException { public boolean visit(int record) throws CoreException {
result[0] = pdom.getBinding(record); PDOMNamedNode nnode = (PDOMNamedNode) PDOMLinkage.getLinkage(pdom, record).getNode(record);
if(nnode.hasName(name)) {
int constant = nnode.getNodeType();
for(int i=0; i<constants.length; i++) {
if(constant==constants[i]) {
result[0] = (PDOMBinding) nnode;
return false;
}
}
return true;
}
return false; return false;
} }
}); });

View file

@ -90,16 +90,16 @@ class PDOMCEnumeration extends PDOMBinding implements IEnumeration, IIndexType {
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof PDOMNode) { if (type instanceof PDOMNode) {
PDOMNode node= (PDOMNode) type; PDOMNode node= (PDOMNode) type;
if (node.getPDOM() == getPDOM()) { if (node.getPDOM() == getPDOM()) {
return node.getRecord() == getRecord(); return node.getRecord() == getRecord();
} }
} }
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof IEnumeration) { if (type instanceof IEnumeration) {
IEnumeration etype= (IEnumeration) type; IEnumeration etype= (IEnumeration) type;

View file

@ -80,23 +80,7 @@ class PDOMCLinkage extends PDOMLinkage {
return new GCCLanguage(); return new GCCLanguage();
} }
public PDOMBinding addBinding(IASTName name) throws CoreException { public PDOMBinding addBinding(IBinding binding) throws CoreException {
if (name == null)
return null;
char[] namechars = name.toCharArray();
if (namechars == null || name.toCharArray().length == 0)
return null;
IBinding binding = name.resolveBinding();
if (binding == null || binding instanceof IProblemBinding)
// can't tell what it is
return null;
if (binding instanceof IParameter)
// skip parameters
return null;
PDOMBinding pdomBinding = adaptBinding(binding); PDOMBinding pdomBinding = adaptBinding(binding);
try { try {
if (pdomBinding == null) { if (pdomBinding == null) {
@ -144,6 +128,26 @@ class PDOMCLinkage extends PDOMLinkage {
} }
return pdomBinding; return pdomBinding;
} }
public PDOMBinding addBinding(IASTName name) throws CoreException {
if (name == null)
return null;
char[] namechars = name.toCharArray();
if (namechars == null || name.toCharArray().length == 0)
return null;
IBinding binding = name.resolveBinding();
if (binding == null || binding instanceof IProblemBinding)
// can't tell what it is
return null;
if (binding instanceof IParameter)
// skip parameters
return null;
return addBinding(binding);
}
public int getBindingType(IBinding binding) { public int getBindingType(IBinding binding) {
if (binding instanceof IField) if (binding instanceof IField)
@ -238,9 +242,8 @@ class PDOMCLinkage extends PDOMLinkage {
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
if (type instanceof ICBasicType) { if (type instanceof ICBasicType) {
return new PDOMCBasicType(pdom, parent, (ICBasicType)type); return new PDOMCBasicType(pdom, parent, (ICBasicType)type);
} else if (type instanceof ICompositeType) { } else if (type instanceof IBinding) {
ICompositeType ctype = (ICompositeType) type; return addBinding((IBinding)type);
return FindBinding.findBinding(getIndex(), getPDOM(), ctype.getNameCharArray(), new int[] {getBindingType(ctype)});
} }
return super.addType(parent, type); return super.addType(parent, type);
} }

View file

@ -156,16 +156,16 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof PDOMNode) { if (type instanceof PDOMNode) {
PDOMNode node= (PDOMNode) type; PDOMNode node= (PDOMNode) type;
if (node.getPDOM() == getPDOM()) { if (node.getPDOM() == getPDOM()) {
return node.getRecord() == getRecord(); return node.getRecord() == getRecord();
} }
} }
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof ICompositeType) { if (type instanceof ICompositeType) {
ICompositeType etype= (ICompositeType) type; ICompositeType etype= (ICompositeType) type;

View file

@ -109,16 +109,16 @@ ICPPClassScope, IPDOMMemberOwner, IIndexType {
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof PDOMNode) { if (type instanceof PDOMNode) {
PDOMNode node= (PDOMNode) type; PDOMNode node= (PDOMNode) type;
if (node.getPDOM() == getPDOM()) { if (node.getPDOM() == getPDOM()) {
return node.getRecord() == getRecord(); return node.getRecord() == getRecord();
} }
} }
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof ICPPClassType && !(type instanceof ProblemBinding)) { if (type instanceof ICPPClassType && !(type instanceof ProblemBinding)) {
ICPPClassType ctype= (ICPPClassType) type; ICPPClassType ctype= (ICPPClassType) type;

View file

@ -91,16 +91,16 @@ class PDOMCPPEnumeration extends PDOMCPPBinding implements IEnumeration, IIndexT
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof PDOMNode) { if (type instanceof PDOMNode) {
PDOMNode node= (PDOMNode) type; PDOMNode node= (PDOMNode) type;
if (node.getPDOM() == getPDOM()) { if (node.getPDOM() == getPDOM()) {
return node.getRecord() == getRecord(); return node.getRecord() == getRecord();
} }
} }
if (type instanceof ITypedef) {
return type.isSameType(this);
}
try { try {
if (type instanceof IEnumeration) { if (type instanceof IEnumeration) {

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
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.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
@ -117,6 +118,12 @@ abstract public class IndexerASTVisitor extends ASTVisitor {
visit(name, fDefinitionName); visit(name, fDefinitionName);
push(name, declspec); push(name, declspec);
} }
if (declspec instanceof ICASTCompositeTypeSpecifier) {
ICASTCompositeTypeSpecifier cts= (ICASTCompositeTypeSpecifier) declspec;
IASTName name = cts.getName();
visit(name, fDefinitionName);
push(name, declspec);
}
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }