1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

- strings for types that are template parameters

- a class template partial specialization is now also considered a specialization in general
- fix collecting of content assist results to allow overloaded functions
- implement the names for specializations
- update CollectDeclarations/references to handle template parameters
- use internal interace during CPPvisitor.getDeclarations to improve open declaration on template stuff
This commit is contained in:
Andrew Niefer 2005-05-13 15:52:29 +00:00
parent 15c8faed14
commit 220206d7e9
8 changed files with 88 additions and 106 deletions

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
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.gnu.cpp.IGPPBasicType;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType;
@ -204,9 +205,9 @@ public class ASTTypeUtil {
} else if (type instanceof ICPPReferenceType) {
result.append(Keywords.cpAMPER);
} else if (type instanceof ICPPTemplateTypeParameter) {
try {
result.append(getType(((ICPPTemplateTypeParameter)type).getDefault()));
} catch (DOMException e) {}
result.append(((ICPPTemplateTypeParameter)type).getName());
} else if (type instanceof ICPPTemplateTemplateParameter) {
result.append(((ICPPTemplateTemplateParameter)type).getName());
} else if (type instanceof IEnumeration) {
result.append(Keywords.ENUM);
result.append(SPACE);

View file

@ -136,7 +136,7 @@ public class CharTable extends HashTable {
return keyTable[ idx ];
}
protected int lookup(char[] buffer ){
public int lookup(char[] buffer ){
return lookup(buffer, 0, buffer.length);
}

View file

@ -15,7 +15,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -119,8 +118,7 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
*/
public int getKey() throws DOMException {
// TODO Auto-generated method stub
return 0;
return ((ICPPClassType)getSpecializedBinding()).getKey();
}
/* (non-Javadoc)
@ -133,30 +131,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
return instanceScope;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/
public String[] getQualifiedName() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/
public char[][] getQualifiedNameCharArray() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
public boolean isGloballyQualified() throws DOMException {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
@ -165,21 +139,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
return this;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
*/
public IASTNode[] getDeclarations() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
*/
public IASTNode getDefinition() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
*/
@ -187,12 +146,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
return new CPPClassType.CPPClassTypeDelegate( name, this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void addDefinition(IASTNode node) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/

View file

@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
* @author aniefer
*/
public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate implements
ICPPClassTemplatePartialSpecialization {
ICPPClassTemplatePartialSpecialization, ICPPSpecialization {
private IType [] arguments;
/**
@ -99,4 +99,8 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl
return instance;
}
public IBinding getSpecializedBinding() {
return getPrimaryClassTemplate();
}
}

View file

@ -83,7 +83,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
@ -776,23 +775,24 @@ public class CPPSemantics {
objs = ArrayUtil.trim( Object.class, (Object[]) source );
int size = map != null ? map.size() : objs.length;
int resultInitialSize = resultMap.size();
for( int i = 0; i < size; i ++ ) {
char [] key = ( map != null ) ? map.keyAt(i)
: ( objs[i] instanceof IBinding) ? ((IBinding)objs[i]).getNameCharArray()
: ((IASTName)objs[i]).toCharArray();
if( !resultMap.containsKey( key ) ){
int idx = resultMap.lookup( key );
if( idx == -1 ){
resultMap.put( key, (map != null ) ? map.get( key ) : objs[i] );
} else if( !scoped ) {
} else if( !scoped || idx >= resultInitialSize ) {
Object obj = resultMap.get( key );
Object so = ( map != null ) ? map.get(key) : objs[i];
if( obj instanceof Object [] ) {
if( so instanceof IBinding )
if( so instanceof IBinding || so instanceof IASTName )
obj = ArrayUtil.append( Object.class, (Object[]) obj, so );
else
obj = ArrayUtil.addAll( Object.class, (Object[])obj, (Object[]) so );
} else {
if( so instanceof IBinding )
if( so instanceof IBinding || so instanceof IASTName )
obj = new Object [] { obj, so };
else {
Object [] temp = new Object [ ((Object[])so).length + 1 ];
@ -800,6 +800,7 @@ public class CPPSemantics {
obj = ArrayUtil.addAll( Object.class, temp, (Object[]) so );
}
}
resultMap.put( key, obj );
}
}
@ -1675,8 +1676,8 @@ public class CPPSemantics {
(type instanceof ICPPDelegate && ((ICPPDelegate)type).getBinding() == temp) )
{
//ok, delegates are synonyms
} else if( type instanceof ICPPClassTemplate && temp instanceof ICPPClassTemplatePartialSpecialization &&
((ICPPClassTemplatePartialSpecialization)temp).getPrimaryClassTemplate() == type )
} else if( type instanceof ICPPClassTemplate && temp instanceof ICPPSpecialization &&
((ICPPSpecialization)temp).getSpecializedBinding() == type )
{
//ok, stay with the template, the specialization, if applicable, will come out during instantiation
} else if( type != temp ) {
@ -2834,25 +2835,22 @@ public class CPPSemantics {
obj = map.get( key );
if( obj instanceof IBinding )
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, obj );
else {
Object item = null;
if( obj instanceof Object[] ){
Object[] objs = (Object[]) obj;
if( objs.length > 1 && objs[1] != null )
continue;
item = objs[0];
} else {
item = obj;
}
if( item instanceof IBinding )
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, item );
else {
IBinding binding = ((IASTName) item).resolveBinding();
if( binding != null && !(binding instanceof IProblemBinding))
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, binding );
}
else if( obj instanceof IASTName ) {
IBinding binding = ((IASTName) obj).resolveBinding();
if( binding != null && !(binding instanceof IProblemBinding))
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, binding );
} else if( obj instanceof Object [] ) {
Object[] objs = (Object[]) obj;
for (int j = 0; j < objs.length && objs[j] != null; j++) {
Object item = objs[j];
if( item instanceof IBinding )
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, item );
else if( item instanceof IASTName ) {
IBinding binding = ((IASTName) item).resolveBinding();
if( binding != null && !(binding instanceof IProblemBinding))
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, binding );
}
}
}
}
}

View file

@ -95,27 +95,22 @@ public abstract class CPPSpecialization implements ICPPSpecialization, ICPPInter
}
public String getName() {
// TODO Auto-generated method stub
return null;
return specialized.getName();
}
public char[] getNameCharArray() {
// TODO Auto-generated method stub
return null;
return specialized.getNameCharArray();
}
public IScope getScope() {
return scope;
}
public String[] getQualifiedName() throws DOMException {
// TODO Auto-generated method stub
return null;
public String[] getQualifiedName() {
return CPPVisitor.getQualifiedName( this );
}
public char[][] getQualifiedNameCharArray() throws DOMException {
// TODO Auto-generated method stub
return null;
public char[][] getQualifiedNameCharArray() {
return CPPVisitor.getQualifiedNameCharArray( this );
}
public boolean isGloballyQualified() throws DOMException {
// TODO Auto-generated method stub
return false;
return ((ICPPInternalBinding)specialized).isGloballyQualified();
}
}

View file

@ -93,10 +93,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
@ -115,7 +117,9 @@ 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.ICPPPointerToMemberType;
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.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
@ -974,6 +978,7 @@ public class CPPVisitor {
private static final int KIND_TYPE = 3;
private static final int KIND_NAMESPACE = 4;
private static final int KIND_COMPOSITE = 5;
private static final int KIND_TEMPLATE_PARAMETER = 6;
public CollectDeclarationsAction( IBinding binding ){
@ -994,6 +999,8 @@ public class CPPVisitor {
}
else if( binding instanceof ICPPUsingDeclaration )
kind = KIND_COMPOSITE;
else if( binding instanceof ICPPTemplateParameter )
kind = KIND_TEMPLATE_PARAMETER;
else
kind = KIND_OBJ_FN;
}
@ -1006,6 +1013,18 @@ public class CPPVisitor {
prop = name.getParent().getPropertyInParent();
switch( kind ){
case KIND_TEMPLATE_PARAMETER:
if( prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME ||
prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME )
{
break;
} else if( prop == IASTDeclarator.DECLARATOR_NAME ){
IASTNode d = name.getParent().getParent();
if( d.getPropertyInParent() == IASTParameterDeclaration.DECLARATOR ){
break;
}
}
return PROCESS_CONTINUE;
case KIND_LABEL:
if( prop == IASTLabelStatement.NAME )
break;
@ -1149,7 +1168,8 @@ public class CPPVisitor {
}
else if( binding instanceof ICPPNamespace) {
kind = KIND_NAMESPACE;
} else if( binding instanceof ICPPUsingDeclaration )
} else if( binding instanceof ICPPUsingDeclaration ||
binding instanceof ICPPTemplateParameter )
kind = KIND_COMPOSITE;
else
kind = KIND_OBJ_FN;
@ -1200,7 +1220,8 @@ public class CPPVisitor {
prop == IASTFunctionCallExpression.FUNCTION_NAME ||
prop == ICPPASTUsingDeclaration.NAME ||
prop == IASTNamedTypeSpecifier.NAME ||
prop == ICPPASTConstructorChainInitializer.MEMBER_ID)
prop == ICPPASTConstructorChainInitializer.MEMBER_ID ||
prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT )
{
break;
}
@ -1736,7 +1757,27 @@ public class CPPVisitor {
public static IASTName[] getDeclarations( IASTTranslationUnit tu, IBinding binding ){
CollectDeclarationsAction action = new CollectDeclarationsAction( binding );
tu.accept( action );
return action.getDeclarations();
IASTName [] found = action.getDeclarations();
if( found.length == 0 && binding instanceof ICPPSpecialization && binding instanceof ICPPInternalBinding ){
IASTNode node = ((ICPPInternalBinding)binding).getDefinition();
if( node == null ){
IASTNode [] nds = ((ICPPInternalBinding)binding).getDeclarations();
if( nds != null && nds.length > 0 )
node = nds[0];
}
if( node != null ){
IASTName name = null;
if( node instanceof IASTDeclarator )
name = ((IASTDeclarator)node).getName();
else if( node instanceof IASTName )
name = (IASTName) node;
if( name != null )
found = new IASTName[] { name };
}
}
return found;
}
public static String [] getQualifiedName( IBinding binding ){

View file

@ -41,7 +41,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
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.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.parser.ParseError;
@ -49,7 +48,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@ -351,15 +349,7 @@ public class DOMSearchUtil {
IBinding binding = searchName.resolveBinding();
names = getNames(tu, binding, limitTo);
if (names == null || names.length == 0) { // try alternate strategies
// fix for 92632
if (binding instanceof ICPPTemplateInstance) {
if (((ICPPTemplateInstance)binding).getTemplateDefinition() != null) {
binding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
names = getNames(tu, binding, limitTo);
}
}
if (names == null || names.length == 0) { // try alternate strategies
// fix for 86829
try {
if (binding instanceof ICPPConstructor && binding.getScope() instanceof ICPPClassScope) {