mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
172454: additionally distinguish bindings by type constant in btree indices
This commit is contained in:
parent
254fd3131e
commit
55dcea05dd
10 changed files with 104 additions and 43 deletions
|
@ -399,7 +399,7 @@ public class IndexBugsTests extends BaseTestCase {
|
|||
// typedef struct S20070201 {
|
||||
// int a;
|
||||
// } S20070201;
|
||||
public void _test172454_1() throws Exception {
|
||||
public void test172454_1() throws Exception {
|
||||
waitForIndexer();
|
||||
String content= getContentsForTest(1)[0].toString();
|
||||
|
||||
|
@ -434,7 +434,7 @@ public class IndexBugsTests extends BaseTestCase {
|
|||
// typedef struct S20070201 {
|
||||
// int a;
|
||||
// } S20070201;
|
||||
public void _test172454_2() throws Exception {
|
||||
public void test172454_2() throws Exception {
|
||||
waitForIndexer();
|
||||
String content= getContentsForTest(1)[0].toString();
|
||||
|
||||
|
@ -447,7 +447,7 @@ public class IndexBugsTests extends BaseTestCase {
|
|||
assertEquals(2, bindings.length);
|
||||
|
||||
IBinding struct, typedef;
|
||||
if (bindings[0] instanceof ICCompositeTypeScope) {
|
||||
if (bindings[0] instanceof ICPPClassType) {
|
||||
struct= bindings[0];
|
||||
typedef= bindings[1];
|
||||
}
|
||||
|
@ -456,9 +456,12 @@ public class IndexBugsTests extends BaseTestCase {
|
|||
typedef= bindings[0];
|
||||
}
|
||||
|
||||
assertTrue(struct instanceof ICompositeType);
|
||||
assertTrue(struct instanceof ICPPClassType);
|
||||
assertTrue(((ICPPClassType)struct).getKey()==ICompositeType.k_struct);
|
||||
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));
|
||||
}
|
||||
finally {
|
||||
|
|
|
@ -16,6 +16,8 @@ import junit.framework.TestSuite;
|
|||
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -79,6 +81,20 @@ public class IndexCBindingResolutionTest extends IndexBindingResolutionTestBase
|
|||
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 _testEnumeratorInStructScope() {fail("todo");}
|
||||
public void _testEnumeratorInUnionScope() {fail("todo");}
|
||||
|
|
|
@ -17,6 +17,7 @@ import junit.framework.TestSuite;
|
|||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
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.ICPPVariable;
|
||||
|
@ -958,4 +959,19 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,13 @@ public class FindBinding {
|
|||
public int compare(int record1, int record2) throws CoreException {
|
||||
IString nm1 = PDOMNamedNode.getDBName(pdom, record1);
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -90,16 +90,16 @@ class PDOMCEnumeration extends PDOMBinding implements IEnumeration, IIndexType {
|
|||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
if (type instanceof PDOMNode) {
|
||||
PDOMNode node= (PDOMNode) type;
|
||||
if (node.getPDOM() == getPDOM()) {
|
||||
return node.getRecord() == getRecord();
|
||||
}
|
||||
}
|
||||
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
if (type instanceof IEnumeration) {
|
||||
IEnumeration etype= (IEnumeration) type;
|
||||
|
|
|
@ -80,23 +80,7 @@ class PDOMCLinkage extends PDOMLinkage {
|
|||
return new GCCLanguage();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public PDOMBinding addBinding(IBinding binding) throws CoreException {
|
||||
PDOMBinding pdomBinding = adaptBinding(binding);
|
||||
try {
|
||||
if (pdomBinding == null) {
|
||||
|
@ -144,6 +128,26 @@ class PDOMCLinkage extends PDOMLinkage {
|
|||
}
|
||||
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) {
|
||||
if (binding instanceof IField)
|
||||
|
@ -238,9 +242,8 @@ class PDOMCLinkage extends PDOMLinkage {
|
|||
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
|
||||
if (type instanceof ICBasicType) {
|
||||
return new PDOMCBasicType(pdom, parent, (ICBasicType)type);
|
||||
} else if (type instanceof ICompositeType) {
|
||||
ICompositeType ctype = (ICompositeType) type;
|
||||
return FindBinding.findBinding(getIndex(), getPDOM(), ctype.getNameCharArray(), new int[] {getBindingType(ctype)});
|
||||
} else if (type instanceof IBinding) {
|
||||
return addBinding((IBinding)type);
|
||||
}
|
||||
return super.addType(parent, type);
|
||||
}
|
||||
|
|
|
@ -156,16 +156,16 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
|
|||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
if (type instanceof PDOMNode) {
|
||||
PDOMNode node= (PDOMNode) type;
|
||||
if (node.getPDOM() == getPDOM()) {
|
||||
return node.getRecord() == getRecord();
|
||||
}
|
||||
}
|
||||
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
if (type instanceof ICompositeType) {
|
||||
ICompositeType etype= (ICompositeType) type;
|
||||
|
|
|
@ -109,16 +109,16 @@ ICPPClassScope, IPDOMMemberOwner, IIndexType {
|
|||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
if (type instanceof PDOMNode) {
|
||||
PDOMNode node= (PDOMNode) type;
|
||||
if (node.getPDOM() == getPDOM()) {
|
||||
return node.getRecord() == getRecord();
|
||||
}
|
||||
}
|
||||
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
if (type instanceof ICPPClassType && !(type instanceof ProblemBinding)) {
|
||||
ICPPClassType ctype= (ICPPClassType) type;
|
||||
|
|
|
@ -91,16 +91,16 @@ class PDOMCPPEnumeration extends PDOMCPPBinding implements IEnumeration, IIndexT
|
|||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
if (type instanceof PDOMNode) {
|
||||
PDOMNode node= (PDOMNode) type;
|
||||
if (node.getPDOM() == getPDOM()) {
|
||||
return node.getRecord() == getRecord();
|
||||
}
|
||||
}
|
||||
|
||||
if (type instanceof ITypedef) {
|
||||
return type.isSameType(this);
|
||||
}
|
||||
|
||||
try {
|
||||
if (type instanceof IEnumeration) {
|
||||
|
|
|
@ -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.IASTNode;
|
||||
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.ICPPASTQualifiedName;
|
||||
|
||||
|
@ -117,6 +118,12 @@ abstract public class IndexerASTVisitor extends ASTVisitor {
|
|||
visit(name, fDefinitionName);
|
||||
push(name, declspec);
|
||||
}
|
||||
if (declspec instanceof ICASTCompositeTypeSpecifier) {
|
||||
ICASTCompositeTypeSpecifier cts= (ICASTCompositeTypeSpecifier) declspec;
|
||||
IASTName name = cts.getName();
|
||||
visit(name, fDefinitionName);
|
||||
push(name, declspec);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue