mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Relax type comparisons a bit around defered class template instances, especially in derived to base conversions. fixes a couple hundred problems parsing iostream.
This commit is contained in:
parent
3784acdac1
commit
d1d753ba3a
3 changed files with 46 additions and 15 deletions
|
@ -1570,4 +1570,23 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f );
|
assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRelaxationForTemplateInheritance() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("template < class T > class A {}; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("template < class T > class B { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" void init( A<T> * ); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("template < class T > class C : public B<T> { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" C( A<T> * a ) { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" init( a ); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}; \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept( col );
|
||||||
|
|
||||||
|
ICPPMethod init = (ICPPMethod) col.getName(4).resolveBinding();
|
||||||
|
assertSame( init, col.getName(19).resolveBinding() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,14 +45,14 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
|
||||||
*/
|
*/
|
||||||
public ICPPBase[] getBases() {
|
public ICPPBase[] getBases() throws DOMException {
|
||||||
return ICPPBase.EMPTY_BASE_ARRAY;
|
return ((ICPPClassType) classTemplate).getBases();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
|
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
|
||||||
*/
|
*/
|
||||||
public IField[] getFields() throws DOMException {
|
public IField[] getFields() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String)
|
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IField findField(String name) throws DOMException {
|
public IField findField(String name) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields()
|
||||||
*/
|
*/
|
||||||
public ICPPField[] getDeclaredFields() throws DOMException {
|
public ICPPField[] getDeclaredFields() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
|
||||||
*/
|
*/
|
||||||
public ICPPMethod[] getMethods() throws DOMException {
|
public ICPPMethod[] getMethods() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods()
|
||||||
*/
|
*/
|
||||||
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
|
public ICPPMethod[] getAllDeclaredMethods() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods()
|
||||||
*/
|
*/
|
||||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
public ICPPMethod[] getDeclaredMethods() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -100,14 +100,14 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors()
|
||||||
*/
|
*/
|
||||||
public ICPPConstructor[] getConstructors() throws DOMException {
|
public ICPPConstructor[] getConstructors() {
|
||||||
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
|
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends()
|
||||||
*/
|
*/
|
||||||
public IBinding[] getFriends() throws DOMException {
|
public IBinding[] getFriends() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
|
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
|
||||||
*/
|
*/
|
||||||
public int getKey() throws DOMException {
|
public int getKey() throws DOMException {
|
||||||
// TODO Auto-generated method stub
|
return ((ICPPClassType)classTemplate).getKey();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -165,7 +164,17 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||||
*/
|
*/
|
||||||
public boolean isSameType(IType type) {
|
public boolean isSameType(IType type) {
|
||||||
// TODO Auto-generated method stub
|
if( type == this )
|
||||||
return type == this;
|
return true;
|
||||||
|
|
||||||
|
//allow some fuzziness here.
|
||||||
|
if( !(type instanceof CPPDeferredClassInstance ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ICPPClassTemplate typeClass = (ICPPClassTemplate) ((CPPDeferredClassInstance)type).getSpecializedBinding();
|
||||||
|
if( typeClass != classTemplate )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2844,7 +2844,10 @@ public class CPPSemantics {
|
||||||
parent = bases[i].getBaseClass();
|
parent = bases[i].getBaseClass();
|
||||||
boolean isVisible = ( wrapper.getVisibility() == ICPPBase.v_public);
|
boolean isVisible = ( wrapper.getVisibility() == ICPPBase.v_public);
|
||||||
|
|
||||||
if( parent == clsBase ){
|
if( parent.isSameType( clsBase ) ||
|
||||||
|
(clsBase instanceof ICPPSpecialization && //allow some flexibility with templates
|
||||||
|
((IType)((ICPPSpecialization)clsBase).getSpecializedBinding()).isSameType( parent ) ) )
|
||||||
|
{
|
||||||
if( needVisibility && !isVisible )
|
if( needVisibility && !isVisible )
|
||||||
return -1;
|
return -1;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue