1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

More cleanup of template resolution code. Do not use clone.

This commit is contained in:
Sergey Prigogin 2008-04-06 21:49:46 +00:00
parent e87ef6e31d
commit 1a2abe7d43
5 changed files with 69 additions and 17 deletions

View file

@ -31,7 +31,8 @@ import org.eclipse.core.runtime.PlatformObject;
/**
* @author aniefer
*/
public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnknown, Cloneable {
public abstract class CPPUnknownBinding extends PlatformObject
implements ICPPInternalUnknown, Cloneable {
private ICPPScope unknownScope;
protected ICPPInternalUnknown scopeBinding;
protected IASTName name;
@ -145,15 +146,16 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
if (s != null && ASTInternal.isFullyCached(s))
result = s.getBinding(name, true);
} else if (t instanceof ICPPInternalUnknown) {
CPPUnknownBinding res = clone();
res.scopeBinding = (ICPPInternalUnknown) t;
res.unknownScope = null;
result = res;
result = resolvePartially((ICPPInternalUnknown) t, argMap);
}
}
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownClassType#resolvePartially(org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown, org.eclipse.cdt.core.parser.util.ObjectMap)
*/
protected abstract IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap);
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;

View file

@ -22,6 +22,7 @@ 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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
* Represents a C++ class, declaration of which is not yet available.
@ -124,4 +125,15 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPInternalUn
public ICPPClassType[] getNestedClasses() {
return ICPPClassType.EMPTY_CLASS_ARRAY;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownClassType#resolvePartially(org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown, org.eclipse.cdt.core.parser.util.ObjectMap)
*/
@Override
public IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap) {
if (parentBinding == this.scopeBinding) {
return this;
}
return new CPPUnknownClass(parentBinding, name);
}
}

View file

@ -101,25 +101,28 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPInte
return arguments;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#resolveUnknown(org.eclipse.cdt.core.parser.util.ObjectMap)
*/
@Override
public IBinding resolveUnknown(ObjectMap argMap) throws DOMException {
IBinding result = super.resolveUnknown(argMap);
IType[] newArgs = new IType[arguments.length];
for (int i = 0; i < newArgs.length; i++) {
newArgs[i] = CPPTemplates.instantiateType(arguments[i], argMap);
}
if (result instanceof ICPPSpecialization) {
ICPPSpecialization specialization = (ICPPSpecialization) result;
result = CPPTemplates.instantiateTemplate((ICPPTemplateDefinition) specialization, newArgs, null);
} else {
ICPPInternalUnknown newScopeBinding = result instanceof CPPUnknownBinding ?
((CPPUnknownBinding) result).scopeBinding : scopeBinding;
result = new CPPUnknownClassInstance(newScopeBinding, name, newArgs);
if (result instanceof ICPPSpecialization && result instanceof ICPPTemplateDefinition) {
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap);
result = CPPTemplates.instantiateTemplate((ICPPTemplateDefinition) result, newArgs, null);
}
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownClassType#resolvePartially(org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown, org.eclipse.cdt.core.parser.util.ObjectMap)
*/
@Override
public IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap) {
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap);
return new CPPUnknownClassInstance(parentBinding, name, newArgs);
}
@Override
public String toString() {
return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -10,11 +10,22 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown;
/*
* @author Sergey Prigogin
*/
public interface ICPPInternalUnknownClassType extends ICPPClassType, ICPPInternalUnknown {
/**
* Resolves unknown type to another unknown type that is a step closer to the final
* name resolution.
* @param parentBinding a new parent binding, usually a result of partial resolution
* of the original parent binding.
* @param argMap template argument map.
* @return a partially resolved, but still unknown, binding.
*/
public IBinding resolvePartially(ICPPInternalUnknown parentBinding, ObjectMap argMap);
}

View file

@ -753,6 +753,30 @@ public class CPPTemplates {
return newType;
}
/**
* Instantiates types contained in an array.
* @param types an array of types
* @param argMap template argument map
* @return an array containing instantiated types.
*/
public static IType[] instantiateTypes(IType[] types, ObjectMap argMap) {
// Don't create a new array until it's really needed.
IType[] result = types;
for (int i = 0; i < types.length; i++) {
IType type = CPPTemplates.instantiateType(types[i], argMap);
if (type != types[i]) {
if (result == types) {
result = new IType[types.length];
if (i > 0) {
System.arraycopy(types, 0, result, 0, i);
}
}
result[i] = type;
}
}
return result;
}
public static ICPPASTTemplateDeclaration getTemplateDeclaration(IASTName name) {
if (name == null) return null;