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

toString methods and generics.

This commit is contained in:
Sergey Prigogin 2008-02-25 00:00:32 +00:00
parent a2f9f9a4eb
commit bd4d1ba488
10 changed files with 558 additions and 552 deletions

View file

@ -25,6 +25,9 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier
private boolean isShort; private boolean isShort;
private boolean isLong; private boolean isLong;
/**
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier
*/
public int getType() { public int getType() {
return type; return type;
} }

View file

@ -29,9 +29,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
* @author jcamelon * @author jcamelon
*/ */
public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, IASTAmbiguityParent { public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, IASTAmbiguityParent {
private IASTName templateName; private IASTName templateName;
private IASTNode[] templateArguments = null;
private IBinding binding = null;
private int fResolutionDepth = 0;
public CPPASTTemplateId() { public CPPASTTemplateId() {
} }
@ -73,17 +74,12 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
return (IASTNode[]) ArrayUtil.trim(IASTNode.class, templateArguments); return (IASTNode[]) ArrayUtil.trim(IASTNode.class, templateArguments);
} }
private IASTNode [] templateArguments = null;
private IBinding binding = null;
private int fResolutionDepth= 0;
public IBinding resolveBinding() { public IBinding resolveBinding() {
if (binding == null) { if (binding == null) {
// protect for infinite recursion // protect for infinite recursion
if (++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) { if (++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) {
binding= new CPPASTName.RecursionResolvingBinding(this); binding= new CPPASTName.RecursionResolvingBinding(this);
} } else {
else {
binding = CPPTemplates.createBinding(this); binding = CPPTemplates.createBinding(this);
} }
} }
@ -95,10 +91,10 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
return null; return null;
} }
public char[] toCharArray() { public char[] toCharArray() {
return templateName.toCharArray(); return templateName.toCharArray();
} }
@Override @Override
public String toString() { public String toString() {
return templateName.toString(); return templateName.toString();
@ -113,7 +109,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
default: break; default: break;
} }
} }
if( templateName != null ) if( !templateName.accept( action ) ) return false; if (templateName != null && !templateName.accept(action)) return false;
IASTNode[] nodes = getTemplateArguments(); IASTNode[] nodes = getTemplateArguments();
for (int i = 0; i < nodes.length; i++) { for (int i = 0; i < nodes.length; i++) {
@ -167,8 +163,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
IASTNode parent = getParent(); IASTNode parent = getParent();
if (parent instanceof IASTNameOwner) { if (parent instanceof IASTNameOwner) {
int role = ((IASTNameOwner) parent).getRoleForName(this); int role = ((IASTNameOwner) parent).getRoleForName(this);
if( role == IASTNameOwner.r_definition ) return true; return role == IASTNameOwner.r_definition;
return false;
} }
return false; return false;
} }

View file

@ -79,7 +79,7 @@ public class CPPASTUsingDirective extends CPPASTNode implements
public IBinding[] findBindings(IASTName n, boolean isPrefix) { public IBinding[] findBindings(IASTName n, boolean isPrefix) {
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix); IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
List filtered = new ArrayList(); List<IBinding> filtered = new ArrayList<IBinding>();
for (int i = 0;i < bindings.length; i++) { for (int i = 0;i < bindings.length; i++) {
if (bindings[i] instanceof ICPPNamespace) { if (bindings[i] instanceof ICPPNamespace) {
@ -87,6 +87,6 @@ public class CPPASTUsingDirective extends CPPASTNode implements
} }
} }
return (IBinding[]) filtered.toArray(new IBinding[filtered.size()]); return filtered.toArray(new IBinding[filtered.size()]);
} }
} }

View file

@ -75,7 +75,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @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() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -83,7 +82,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @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) throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -91,7 +89,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @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() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -99,7 +96,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @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() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -107,7 +103,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @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() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -115,7 +110,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @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() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -133,7 +127,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @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() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -159,7 +152,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
*/ */
@Override @Override
public Object clone() { public Object clone() {
// TODO Auto-generated method stub
return this; return this;
} }
@ -180,7 +172,8 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
if (!ct1.isSameType(ct2)) if (!ct1.isSameType(ct2))
return false; return false;
ObjectMap m1 = getArgumentMap(), m2 = ((ICPPTemplateInstance)type).getArgumentMap(); ObjectMap m1 = getArgumentMap();
ObjectMap m2 = ((ICPPTemplateInstance) type).getArgumentMap();
if (m1 == null || m2 == null || m1.size() != m2.size()) if (m1 == null || m2 == null || m1.size() != m2.size())
return false; return false;
for (int i = 0; i < m1.size(); i++) { for (int i = 0; i < m1.size(); i++) {
@ -210,6 +203,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof ICPPClassType ? isSameType((ICPPClassType)obj) : false; return obj instanceof ICPPClassType && isSameType((ICPPClassType) obj);
} }
} }

View file

@ -38,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; 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.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
@ -276,9 +275,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
i--; i--;
continue; continue;
} }
} else if( obj instanceof ICPPConstructor ) } else if (obj instanceof ICPPConstructor) {
bs = (IBinding[]) ArrayUtil.append(ICPPConstructor.class, bs, obj); bs = (IBinding[]) ArrayUtil.append(ICPPConstructor.class, bs, obj);
} }
}
return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, bs); return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, bs);
} else if (o instanceof IASTName) { } else if (o instanceof IASTName) {
if (shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName)o).getBinding() != null) { if (shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName)o).getBinding() != null) {
@ -404,7 +404,7 @@ class ImplicitsAnalysis {
IASTParameterDeclaration[] ps = dcltor.getParameters(); IASTParameterDeclaration[] ps = dcltor.getParameters();
if (ps.length >= 1) { if (ps.length >= 1) {
if (paramHasTypeReferenceToTheAssociatedClassType(ps[0], compSpec.getName().getRawSignature())) { if (paramHasTypeReferenceToTheAssociatedClassType(ps[0], compSpec.getName().getRawSignature())) {
// and all remaining arguments have initialisers // and all remaining arguments have initializers
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;
@ -446,8 +446,7 @@ class ImplicitsAnalysis {
if (!(dcltor instanceof ICPPASTFunctionDeclarator) || !(spec instanceof IASTSimpleDeclSpecifier) || if (!(dcltor instanceof ICPPASTFunctionDeclarator) || !(spec instanceof IASTSimpleDeclSpecifier) ||
((IASTSimpleDeclSpecifier)spec).getType() != IASTSimpleDeclSpecifier.t_unspecified) ((IASTSimpleDeclSpecifier)spec).getType() != IASTSimpleDeclSpecifier.t_unspecified) {
{
continue; continue;
} }

View file

@ -40,8 +40,8 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
* @param scope * @param scope
* @param argumentMap * @param argumentMap
*/ */
public CPPClassTemplateSpecialization(IBinding specialized, public CPPClassTemplateSpecialization(IBinding specialized, ICPPScope scope,
ICPPScope scope, ObjectMap argumentMap) { ObjectMap argumentMap) {
super(specialized, scope, argumentMap); super(specialized, scope, argumentMap);
} }
@ -100,8 +100,9 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
return e.getProblem(); return e.getProblem();
} }
if( template instanceof IProblemBinding ) if (template instanceof IProblemBinding) {
return template; return template;
}
if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) { if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) {
return ((ICPPInternalTemplateInstantiator) template).instantiate(arguments); return ((ICPPInternalTemplateInstantiator) template).instantiate(arguments);
} }
@ -110,11 +111,14 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
} }
public ICPPSpecialization deferredInstance(IType[] arguments) { public ICPPSpecialization deferredInstance(IType[] arguments) {
// TODO Auto-generated method stub
return null; return null;
} }
public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) { public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) {
//should not occur //should not occur
} }
public String toString() {
return getName();
}
} }

View file

@ -570,7 +570,8 @@ public class CPPTemplates {
* @return * @return
* @throws DOMException * @throws DOMException
*/ */
static protected Object[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate, IASTParameterDeclaration[] ps, IASTNode[] specArgs) throws DOMException static protected Object[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate,
IASTParameterDeclaration[] ps, IASTNode[] specArgs) throws DOMException
{ {
ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters(); ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters();
IType[] arguments = createTypeArray(specArgs); IType[] arguments = createTypeArray(specArgs);
@ -681,7 +682,8 @@ public class CPPTemplates {
} }
} catch (DOMException e) { } catch (DOMException e) {
} }
newType = new CPPFunctionType(ret, params, ((ICPPFunctionType)type).isConst(), ((ICPPFunctionType)type).isVolatile()); newType = new CPPFunctionType(ret, params, ((ICPPFunctionType)type).isConst(),
((ICPPFunctionType)type).isVolatile());
} else if (type instanceof ITypedef) { } else if (type instanceof ITypedef) {
// Typedef requires special treatment (bug 213861). // Typedef requires special treatment (bug 213861).
try { try {
@ -984,7 +986,8 @@ public class CPPTemplates {
return result; return result;
} }
static protected IFunction[] selectTemplateFunctions(ObjectSet templates, Object[] functionArguments, IASTName name) {//IASTNode[] templateArguments) { static protected IFunction[] selectTemplateFunctions(ObjectSet templates,
Object[] functionArguments, IASTName name) {//IASTNode[] templateArguments) {
if (templates == null || templates.size() == 0) if (templates == null || templates.size() == 0)
return null; return null;
@ -1576,11 +1579,8 @@ public class CPPTemplates {
return (t instanceof ICPPTemplateParameter); return (t instanceof ICPPTemplateParameter);
} }
public static IBinding instantiateTemplate(ICPPTemplateDefinition template, IType[] arguments, ObjectMap specializedArgs) { public static IBinding instantiateTemplate(ICPPTemplateDefinition template, IType[] arguments,
if (template == null) { ObjectMap specializedArgs) {
template = null;
}
ICPPTemplateParameter[] parameters = null; ICPPTemplateParameter[] parameters = null;
try { try {
parameters = template.getTemplateParameters(); parameters = template.getTemplateParameters();

View file

@ -43,7 +43,7 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
this.scopeBinding = scopeBinding; this.scopeBinding = scopeBinding;
} }
/* (non-Javadoc)``` /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#getUnknownScope() * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#getUnknownScope()
*/ */
public ICPPScope getUnknownScope() { public ICPPScope getUnknownScope() {
@ -152,4 +152,11 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
public ILinkage getLinkage() { public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE; return Linkage.CPP_LINKAGE;
} }
/* (non-Javadoc)
* For debug purposes only
*/
public String toString() {
return getName();
}
} }

View file

@ -27,6 +27,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
/** /**
* Represents a C++ class for which we don't yet have a complete declaration.
*
* @author aniefer * @author aniefer
*/ */
public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType { public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType {
@ -133,5 +135,4 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType
public ICPPClassType[] getNestedClasses() { public ICPPClassType[] getNestedClasses() {
return ICPPClassType.EMPTY_CLASS_ARRAY; return ICPPClassType.EMPTY_CLASS_ARRAY;
} }
} }

View file

@ -77,14 +77,12 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
* @see org.eclipse.cdt.core.dom.ast.IScope#addName(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.core.dom.ast.IScope#addName(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
public void addName(IASTName name) { public void addName(IASTName name) {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public void removeBinding( IBinding binding1 ) { public void removeBinding(IBinding binding) {
} }
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException { public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
@ -110,11 +108,11 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
IBinding b = new CPPUnknownClass(this, binding, name); IBinding b = new CPPUnknownClass(this, binding, name);
name.setBinding(b); name.setBinding(b);
map.put(c, b); map.put(c, b);
return b; return b;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) { public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
IIndexFileSet fileSet) {
if (map == null) if (map == null)
map = new CharArrayObjectMap(2); map = new CharArrayObjectMap(2);
@ -156,8 +154,14 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
public void flushCache() { public void flushCache() {
} }
public void addBinding(IBinding aBinding) { public void addBinding(IBinding binding) {
// do nothing, this is part of template magic and not a normal scope // do nothing, this is part of template magic and not a normal scope
} }
/* (non-Javadoc)
* For debug purposes only
*/
public String toString() {
return scopeName.toString();
}
} }