1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-02 22:55:26 +02:00

separate template argument creation from CPPTemplates.createTypeArray

This commit is contained in:
Andrew Ferguson 2008-05-27 13:58:13 +00:00
parent d917917c7c
commit 1aa5e93de5
6 changed files with 45 additions and 20 deletions

View file

@ -44,8 +44,8 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl
*/
public IType[] getArguments() {
if( arguments == null ){
ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName();
arguments = CPPTemplates.createTypeArray( id.getTemplateArguments() );
ICPPASTTemplateId id= (ICPPASTTemplateId) getTemplateName();
arguments = CPPTemplates.createTemplateArgumentArray(id);
}
return arguments;
}

View file

@ -104,9 +104,8 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
public abstract ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments);
public IBinding instantiate(ICPPASTTemplateId templateId) {//IASTNode[] arguments) {
IASTNode[] args = templateId.getTemplateArguments();
IType[] types = CPPTemplates.createTypeArray(args);
public IBinding instantiate(ICPPASTTemplateId id) {
IType[] types = CPPTemplates.createTemplateArgumentArray(id);
return instantiate(types);
}

View file

@ -106,8 +106,7 @@ public class CPPUnknownScope implements ICPPScope, ICPPInternalUnknownScope {
IBinding b;
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTTemplateId) {
IASTNode[] args = ((ICPPASTTemplateId) parent).getTemplateArguments();
IType[] arguments = CPPTemplates.createTypeArray(args);
IType[] arguments = CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) parent);
b = new CPPUnknownClassInstance(binding, name, arguments);
} else {
b = new CPPUnknownClass(binding, name);

View file

@ -280,7 +280,7 @@ public class CPPSemantics {
ICPPClassType cls = (ICPPClassType) binding;
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) {
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
IType[] args = CPPTemplates.createTypeArray(id.getTemplateArguments());
IType[] args = CPPTemplates.createTemplateArgumentArray(id);
IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate(args);
cls = inst instanceof ICPPClassType ? (ICPPClassType)inst : cls;
}
@ -379,7 +379,7 @@ public class CPPSemantics {
IASTNode parent = name.getParent();
if (name instanceof ICPPASTTemplateId) {
data.templateArguments = ((ICPPASTTemplateId)name).getTemplateArguments();
data.templateId= ((ICPPASTTemplateId)name);
}
if (parent instanceof ICPPASTTemplateId)

View file

@ -309,8 +309,7 @@ public class CPPTemplates {
}
if (template != null && template instanceof ICPPInternalTemplateInstantiator) {
IASTNode[] args = id.getTemplateArguments();
IType[] types = CPPTemplates.createTypeArray(args);
IType[] types= CPPTemplates.createTemplateArgumentArray(id);
template = ((ICPPInternalTemplateInstantiator) template).instantiate(types);
return CPPSemantics.postResolution(template, id);
}
@ -338,7 +337,7 @@ public class CPPTemplates {
return null; //TODO: problem?
ICPPClassTemplate classTemplate = (ICPPClassTemplate) template;
IType[] args = createTypeArray(id.getTemplateArguments());
IType[] args= createTemplateArgumentArray(id);
if (classTemplate instanceof ICPPInternalTemplateInstantiator) {
IBinding binding = ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(args);
return binding;
@ -377,7 +376,7 @@ public class CPPTemplates {
} catch (DOMException e) {
return e.getProblem();
}
IType[] args = createTypeArray(id.getTemplateArguments());
IType[] args= createTemplateArgumentArray(id);
ObjectMap argMap = new ObjectMap(templateParams.length);
if (templateParams.length != args.length) {
return null; //TODO problem
@ -464,7 +463,7 @@ public class CPPTemplates {
IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator) parent).getParameters();
Object[] map_types;
try {
map_types = deduceTemplateFunctionArguments(function, ps, data.templateArguments);
map_types= deduceTemplateFunctionArguments(function, ps, data.templateId);
} catch (DOMException e) {
return e.getProblem();
}
@ -531,7 +530,7 @@ public class CPPTemplates {
IType[] templateArguments = null;
if (name instanceof ICPPASTTemplateId) {
templateArguments = createTypeArray(((ICPPASTTemplateId) name).getTemplateArguments());
templateArguments= createTemplateArgumentArray((ICPPASTTemplateId) name);
}
int numArgs = (templateArguments != null) ? templateArguments.length : 0;
@ -599,10 +598,10 @@ public class CPPTemplates {
* @throws DOMException
*/
static protected Object[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate,
IASTParameterDeclaration[] ps, IASTNode[] specArgs) throws DOMException
IASTParameterDeclaration[] ps, ICPPASTTemplateId id) throws DOMException
{
ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters();
IType[] arguments = createTypeArray(specArgs);
IType[] arguments= createTemplateArgumentArray(id);
IType[] result = new IType[templateParameters.length];
ObjectMap map = null;
@ -1108,6 +1107,30 @@ public class CPPTemplates {
return argA != null && argB != null && argA.isSameType(argB);
}
/**
* @param id the template id containing the template arguments
* @return an array of template arguments, currently modeled as IType objects. The
* empty IType array is returned if id is <code>null</code>
*/
static public IType[] createTemplateArgumentArray(ICPPASTTemplateId id) {
IType[] result= IType.EMPTY_TYPE_ARRAY;
if(id != null) {
IASTNode[] params= id.getTemplateArguments();
result = new IType[params.length];
for (int i = 0; i < params.length; i++) {
IType type= CPPVisitor.createType(params[i]);
// prevent null pointer exception when the type cannot be determined
// happens when templates with still ambiguous template-ids are accessed during
// resolution of other ambiguities.
result[i]= type == null ? new CPPBasicType(-1, 0) : type;
}
}
return result;
}
/*
* aftodo - need to review this
*/
static public IType[] createTypeArray(Object[] params) {
if (params == null)
return IType.EMPTY_TYPE_ARRAY;
@ -1391,7 +1414,9 @@ public class CPPTemplates {
ICPPTemplateInstance pInst = (ICPPTemplateInstance) p;
ICPPTemplateInstance aInst = (ICPPTemplateInstance) a;
IType[] pArgs = createTypeArray(pInst.getArguments());
IType[] pArgs = pInst.getArguments();
pArgs= pArgs == null ? IType.EMPTY_TYPE_ARRAY : pArgs; // aftodo - unnecessary?
ObjectMap aMap = aInst.getArgumentMap();
if (aMap != null && !(aInst.getTemplateDefinition() instanceof ICPPClassTemplatePartialSpecialization)) {
ICPPTemplateParameter[] aParams = aInst.getTemplateDefinition().getTemplateParameters();
@ -1403,7 +1428,9 @@ public class CPPTemplates {
return false;
}
} else {
IType[] aArgs = createTypeArray(aInst.getArguments());
IType[] aArgs = aInst.getArguments();
aArgs= aArgs == null ? IType.EMPTY_TYPE_ARRAY : aArgs; // aftodo - unnecessary?
if (aArgs.length != pArgs.length)
return false;
for (int i = 0; i < pArgs.length; i++) {

View file

@ -99,7 +99,7 @@ class LookupData {
public IBinding unknownBinding= null;
public Object foundItems = null;
public Object[] functionParameters;
public IASTNode[] templateArguments;
public ICPPASTTemplateId templateId;
public ProblemBinding problem;
public LookupData(IASTName n) {