mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
add unit tests related to 201174 and improve debug information, apply a fix to CPPFunctionSpecialization for answering isStatic for when the binding being specialized is an index binding
This commit is contained in:
parent
ac3d4db76b
commit
2a94956ebe
6 changed files with 146 additions and 11 deletions
|
@ -275,6 +275,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
||||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
|
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
|
||||||
|
|
||||||
if(DEBUG) {
|
if(DEBUG) {
|
||||||
|
System.out.println("Project PDOM: "+getName());
|
||||||
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
|
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
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.index.IIndex;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,6 +60,72 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
setStrategy(new ReferencedProject(true));
|
setStrategy(new ReferencedProject(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// class X {
|
||||||
|
// public: static void foo() {}
|
||||||
|
// };
|
||||||
|
|
||||||
|
// class A{};
|
||||||
|
// void bar() {
|
||||||
|
// X<A>::foo();
|
||||||
|
// }
|
||||||
|
public void testUnindexedMethodInstance() {
|
||||||
|
IBinding b0= getBindingFromASTName("foo()", 3);
|
||||||
|
assertInstance(b0, ICPPMethod.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// class X {};
|
||||||
|
|
||||||
|
// class A{};
|
||||||
|
// void bar() {
|
||||||
|
// X<A> xa= new X<A>();
|
||||||
|
// }
|
||||||
|
public void testUnindexedConstructorInstance() {
|
||||||
|
IBinding b0= getBindingFromASTName("X<A>()", 4);
|
||||||
|
assertInstance(b0, ICPPConstructor.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// class Str1 {
|
||||||
|
// public:
|
||||||
|
// Str1(const char* s) {
|
||||||
|
// s_ = s;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// const char* s_;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template<typename T>
|
||||||
|
// class StrT {
|
||||||
|
// public:
|
||||||
|
// StrT(const T* s) {
|
||||||
|
// s_ = s;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// const T* s_;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// typedef StrT<char> Str2;
|
||||||
|
//
|
||||||
|
// class C1 {
|
||||||
|
// public:
|
||||||
|
// void m1(const Str1& s) {}
|
||||||
|
// void m2(const Str2& s) {}
|
||||||
|
// void m3();
|
||||||
|
// };
|
||||||
|
|
||||||
|
// void C1::m3() {
|
||||||
|
// m1("aaa"); // OK
|
||||||
|
// m2("aaa"); // problem
|
||||||
|
// }
|
||||||
|
public void _testUnindexedConstructorInstanceImplicitReference() throws Exception {
|
||||||
|
IBinding b0= getBindingFromASTName("m1(\"aaa\")", 2);
|
||||||
|
IBinding b1= getBindingFromASTName("m2(\"aaa\")", 2);
|
||||||
|
|
||||||
|
assertEquals(1, getIndex().findNames(b0, IIndex.FIND_REFERENCES).length);
|
||||||
|
assertEquals(1, getIndex().findNames(b1, IIndex.FIND_REFERENCES).length);
|
||||||
|
}
|
||||||
|
|
||||||
// // Bryan W.'s example from bugzilla#167098
|
// // Bryan W.'s example from bugzilla#167098
|
||||||
// template<class K>
|
// template<class K>
|
||||||
// class D { //CPPClassTemplate
|
// class D { //CPPClassTemplate
|
||||||
|
@ -81,15 +148,32 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
// // foo<int,int> -> CPPMethodInstance
|
// // foo<int,int> -> CPPMethodInstance
|
||||||
// }
|
// }
|
||||||
public void testCPPConstructorTemplateSpecialization() throws Exception {
|
public void testCPPConstructorTemplateSpecialization() throws Exception {
|
||||||
IBinding b0= getBindingFromASTName("D<int>(", 1);
|
IBinding b0= getBindingFromASTName("D<int> *var", 1);
|
||||||
IBinding b1= getBindingFromASTName("D<int>(", 6);
|
IBinding b1= getBindingFromASTName("D<int> *var", 6);
|
||||||
|
|
||||||
assertInstance(b0, ICPPClassTemplate.class); // *D*<int>(5, 6)
|
assertInstance(b0, ICPPClassTemplate.class);
|
||||||
assertInstance(b0, ICPPClassType.class); // *D*<int>(5, 6)
|
assertInstance(b0, ICPPClassType.class);
|
||||||
assertInstance(b1, ICPPTemplateInstance.class); // *D<int>*(5, 6)
|
assertInstance(b1, ICPPTemplateInstance.class);
|
||||||
assertInstance(b1, ICPPConstructor.class); // *D<int>*(5, 6)
|
assertInstance(b1, ICPPClassType.class);
|
||||||
|
|
||||||
IBinding tidSpc= ((ICPPTemplateInstance)b1).getSpecializedBinding();
|
// ICPPClassType _ct= (ICPPClassType) b1;
|
||||||
|
// ICPPConstructor[] _ctcs= _ct.getConstructors();
|
||||||
|
// assertEquals(3, _ctcs.length); // two implicit plus the constructor template
|
||||||
|
|
||||||
|
IBinding b2= getBindingFromASTName("D<int>(", 1);
|
||||||
|
IBinding b3= getBindingFromASTName("D<int>(", 6);
|
||||||
|
|
||||||
|
assertInstance(b2, ICPPClassTemplate.class); // *D*<int>(5, 6)
|
||||||
|
assertInstance(b2, ICPPClassType.class); // *D*<int>(5, 6)
|
||||||
|
assertInstance(b3, ICPPTemplateInstance.class); // *D<int>*(5, 6)
|
||||||
|
assertInstance(b3, ICPPConstructor.class); // *D<int>*(5, 6)
|
||||||
|
|
||||||
|
//
|
||||||
|
// ICPPClassType ct= (ICPPClassType) b2;
|
||||||
|
// ICPPConstructor[] ctcs= ct.getConstructors();
|
||||||
|
// assertEquals(3, ctcs.length); // two implicit plus the constructor template
|
||||||
|
|
||||||
|
IBinding tidSpc= ((ICPPTemplateInstance)b3).getSpecializedBinding();
|
||||||
assertInstance(tidSpc, ICPPConstructor.class);
|
assertInstance(tidSpc, ICPPConstructor.class);
|
||||||
assertInstance(tidSpc, ICPPSpecialization.class);
|
assertInstance(tidSpc, ICPPSpecialization.class);
|
||||||
assertInstance(tidSpc, ICPPFunctionTemplate.class);
|
assertInstance(tidSpc, ICPPFunctionTemplate.class);
|
||||||
|
|
|
@ -382,8 +382,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps analyzis of the class declaration for user declared members relevent
|
* Helps analysis of the class declaration for user declared members relevant
|
||||||
* to deciding which implicit bindings to declare.
|
* to deciding which implicit bindings to declare.
|
||||||
|
*
|
||||||
|
* @see chapter 12 of the ISO specification
|
||||||
*/
|
*/
|
||||||
class ImplicitsAnalysis {
|
class ImplicitsAnalysis {
|
||||||
private boolean hasUserDeclaredConstructor;
|
private boolean hasUserDeclaredConstructor;
|
||||||
|
@ -404,7 +406,7 @@ class ImplicitsAnalysis {
|
||||||
IASTParameterDeclaration [] ps = dcltor.getParameters();
|
IASTParameterDeclaration [] ps = dcltor.getParameters();
|
||||||
if( ps.length >= 1 ){
|
if( ps.length >= 1 ){
|
||||||
if(paramHasTypeReferenceToTheAssociatedClassType(ps[0])) {
|
if(paramHasTypeReferenceToTheAssociatedClassType(ps[0])) {
|
||||||
// and all remaining arguments have initializers
|
// and all remaining arguments have initialisers
|
||||||
for(int j=1; j<ps.length; j++) {
|
for(int j=1; j<ps.length; j++) {
|
||||||
if( ps[j].getDeclarator().getInitializer() == null ) {
|
if( ps[j].getDeclarator().getInitializer() == null ) {
|
||||||
continue outer;
|
continue outer;
|
||||||
|
|
|
@ -30,6 +30,7 @@ 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.dom.ast.cpp.ICPPParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction.CPPFunctionDelegate;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction.CPPFunctionDelegate;
|
||||||
|
|
||||||
|
@ -101,6 +102,11 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
|
||||||
IBinding f = getSpecializedBinding();
|
IBinding f = getSpecializedBinding();
|
||||||
if( f instanceof ICPPInternalFunction)
|
if( f instanceof ICPPInternalFunction)
|
||||||
return ((ICPPInternalFunction)f).isStatic( resolveAll );
|
return ((ICPPInternalFunction)f).isStatic( resolveAll );
|
||||||
|
if( f instanceof IIndexBinding && f instanceof ICPPFunction ) {
|
||||||
|
try {
|
||||||
|
return ((ICPPFunction) f).isStatic();
|
||||||
|
} catch(DOMException de) { /* cannot occur as we query the index */}
|
||||||
|
}
|
||||||
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static );
|
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -196,9 +198,45 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
||||||
|
|
||||||
abstract protected int getRecordSize(); // superclass's implementation is no longer valid
|
abstract protected int getRecordSize(); // superclass's implementation is no longer valid
|
||||||
|
|
||||||
|
/* For debug purposes only
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
try {
|
||||||
|
return getName() + " " + getConstantNameForValue(getLinkageImpl(), getNodeType()); //$NON-NLS-1$
|
||||||
|
} catch(CoreException ce) {
|
||||||
return getName() + " " + getNodeType(); //$NON-NLS-1$
|
return getName() + " " + getNodeType(); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For debug purposes only.
|
||||||
|
* @param linkage
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected static String getConstantNameForValue(PDOMLinkage linkage, int value) {
|
||||||
|
Class c= linkage.getClass();
|
||||||
|
Field[] fields= c.getFields();
|
||||||
|
for(int i=0; i<fields.length; i++) {
|
||||||
|
try {
|
||||||
|
fields[i].setAccessible(true);
|
||||||
|
if((fields[i].getModifiers() & Modifier.STATIC) != 0) {
|
||||||
|
if(int.class.equals(fields[i].getType())) {
|
||||||
|
int fvalue= fields[i].getInt(null);
|
||||||
|
if(fvalue == value)
|
||||||
|
return fields[i].getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(IllegalAccessException iae) {
|
||||||
|
continue;
|
||||||
|
} catch(IllegalArgumentException iae) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Integer.toString(value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to shorten subclass file length
|
* Convenience method to shorten subclass file length
|
||||||
|
|
|
@ -249,7 +249,11 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
result.append(getName()+" "+ASTTypeUtil.getParameterTypeString(getType())); //$NON-NLS-1$
|
result.append(getName()+" "+ASTTypeUtil.getParameterTypeString(getType())); //$NON-NLS-1$
|
||||||
|
try {
|
||||||
|
result.append(" "+getConstantNameForValue(getLinkageImpl(), getNodeType())); //$NON-NLS-1$
|
||||||
|
} catch(CoreException ce) {
|
||||||
result.append(" "+getNodeType()); //$NON-NLS-1$
|
result.append(" "+getNodeType()); //$NON-NLS-1$
|
||||||
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue