mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 05:15:43 +02:00
separate template argument creation from CPPTemplates.createTypeArray
This commit is contained in:
parent
d917917c7c
commit
1aa5e93de5
6 changed files with 45 additions and 20 deletions
|
@ -44,8 +44,8 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl
|
||||||
*/
|
*/
|
||||||
public IType[] getArguments() {
|
public IType[] getArguments() {
|
||||||
if( arguments == null ){
|
if( arguments == null ){
|
||||||
ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName();
|
ICPPASTTemplateId id= (ICPPASTTemplateId) getTemplateName();
|
||||||
arguments = CPPTemplates.createTypeArray( id.getTemplateArguments() );
|
arguments = CPPTemplates.createTemplateArgumentArray(id);
|
||||||
}
|
}
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,9 +104,8 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
|
||||||
|
|
||||||
public abstract ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments);
|
public abstract ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments);
|
||||||
|
|
||||||
public IBinding instantiate(ICPPASTTemplateId templateId) {//IASTNode[] arguments) {
|
public IBinding instantiate(ICPPASTTemplateId id) {
|
||||||
IASTNode[] args = templateId.getTemplateArguments();
|
IType[] types = CPPTemplates.createTemplateArgumentArray(id);
|
||||||
IType[] types = CPPTemplates.createTypeArray(args);
|
|
||||||
return instantiate(types);
|
return instantiate(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,8 +106,7 @@ public class CPPUnknownScope implements ICPPScope, ICPPInternalUnknownScope {
|
||||||
IBinding b;
|
IBinding b;
|
||||||
IASTNode parent = name.getParent();
|
IASTNode parent = name.getParent();
|
||||||
if (parent instanceof ICPPASTTemplateId) {
|
if (parent instanceof ICPPASTTemplateId) {
|
||||||
IASTNode[] args = ((ICPPASTTemplateId) parent).getTemplateArguments();
|
IType[] arguments = CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) parent);
|
||||||
IType[] arguments = CPPTemplates.createTypeArray(args);
|
|
||||||
b = new CPPUnknownClassInstance(binding, name, arguments);
|
b = new CPPUnknownClassInstance(binding, name, arguments);
|
||||||
} else {
|
} else {
|
||||||
b = new CPPUnknownClass(binding, name);
|
b = new CPPUnknownClass(binding, name);
|
||||||
|
|
|
@ -280,7 +280,7 @@ public class CPPSemantics {
|
||||||
ICPPClassType cls = (ICPPClassType) binding;
|
ICPPClassType cls = (ICPPClassType) binding;
|
||||||
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) {
|
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) {
|
||||||
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
|
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
|
||||||
IType[] args = CPPTemplates.createTypeArray(id.getTemplateArguments());
|
IType[] args = CPPTemplates.createTemplateArgumentArray(id);
|
||||||
IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate(args);
|
IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate(args);
|
||||||
cls = inst instanceof ICPPClassType ? (ICPPClassType)inst : cls;
|
cls = inst instanceof ICPPClassType ? (ICPPClassType)inst : cls;
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ public class CPPSemantics {
|
||||||
IASTNode parent = name.getParent();
|
IASTNode parent = name.getParent();
|
||||||
|
|
||||||
if (name instanceof ICPPASTTemplateId) {
|
if (name instanceof ICPPASTTemplateId) {
|
||||||
data.templateArguments = ((ICPPASTTemplateId)name).getTemplateArguments();
|
data.templateId= ((ICPPASTTemplateId)name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent instanceof ICPPASTTemplateId)
|
if (parent instanceof ICPPASTTemplateId)
|
||||||
|
|
|
@ -309,8 +309,7 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template != null && template instanceof ICPPInternalTemplateInstantiator) {
|
if (template != null && template instanceof ICPPInternalTemplateInstantiator) {
|
||||||
IASTNode[] args = id.getTemplateArguments();
|
IType[] types= CPPTemplates.createTemplateArgumentArray(id);
|
||||||
IType[] types = CPPTemplates.createTypeArray(args);
|
|
||||||
template = ((ICPPInternalTemplateInstantiator) template).instantiate(types);
|
template = ((ICPPInternalTemplateInstantiator) template).instantiate(types);
|
||||||
return CPPSemantics.postResolution(template, id);
|
return CPPSemantics.postResolution(template, id);
|
||||||
}
|
}
|
||||||
|
@ -338,7 +337,7 @@ public class CPPTemplates {
|
||||||
return null; //TODO: problem?
|
return null; //TODO: problem?
|
||||||
|
|
||||||
ICPPClassTemplate classTemplate = (ICPPClassTemplate) template;
|
ICPPClassTemplate classTemplate = (ICPPClassTemplate) template;
|
||||||
IType[] args = createTypeArray(id.getTemplateArguments());
|
IType[] args= createTemplateArgumentArray(id);
|
||||||
if (classTemplate instanceof ICPPInternalTemplateInstantiator) {
|
if (classTemplate instanceof ICPPInternalTemplateInstantiator) {
|
||||||
IBinding binding = ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(args);
|
IBinding binding = ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(args);
|
||||||
return binding;
|
return binding;
|
||||||
|
@ -377,7 +376,7 @@ public class CPPTemplates {
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return e.getProblem();
|
return e.getProblem();
|
||||||
}
|
}
|
||||||
IType[] args = createTypeArray(id.getTemplateArguments());
|
IType[] args= createTemplateArgumentArray(id);
|
||||||
ObjectMap argMap = new ObjectMap(templateParams.length);
|
ObjectMap argMap = new ObjectMap(templateParams.length);
|
||||||
if (templateParams.length != args.length) {
|
if (templateParams.length != args.length) {
|
||||||
return null; //TODO problem
|
return null; //TODO problem
|
||||||
|
@ -464,7 +463,7 @@ public class CPPTemplates {
|
||||||
IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator) parent).getParameters();
|
IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator) parent).getParameters();
|
||||||
Object[] map_types;
|
Object[] map_types;
|
||||||
try {
|
try {
|
||||||
map_types = deduceTemplateFunctionArguments(function, ps, data.templateArguments);
|
map_types= deduceTemplateFunctionArguments(function, ps, data.templateId);
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return e.getProblem();
|
return e.getProblem();
|
||||||
}
|
}
|
||||||
|
@ -531,7 +530,7 @@ public class CPPTemplates {
|
||||||
IType[] templateArguments = null;
|
IType[] templateArguments = null;
|
||||||
|
|
||||||
if (name instanceof ICPPASTTemplateId) {
|
if (name instanceof ICPPASTTemplateId) {
|
||||||
templateArguments = createTypeArray(((ICPPASTTemplateId) name).getTemplateArguments());
|
templateArguments= createTemplateArgumentArray((ICPPASTTemplateId) name);
|
||||||
}
|
}
|
||||||
int numArgs = (templateArguments != null) ? templateArguments.length : 0;
|
int numArgs = (templateArguments != null) ? templateArguments.length : 0;
|
||||||
|
|
||||||
|
@ -599,10 +598,10 @@ public class CPPTemplates {
|
||||||
* @throws DOMException
|
* @throws DOMException
|
||||||
*/
|
*/
|
||||||
static protected Object[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate,
|
static protected Object[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate,
|
||||||
IASTParameterDeclaration[] ps, IASTNode[] specArgs) throws DOMException
|
IASTParameterDeclaration[] ps, ICPPASTTemplateId id) throws DOMException
|
||||||
{
|
{
|
||||||
ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters();
|
ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters();
|
||||||
IType[] arguments = createTypeArray(specArgs);
|
IType[] arguments= createTemplateArgumentArray(id);
|
||||||
IType[] result = new IType[templateParameters.length];
|
IType[] result = new IType[templateParameters.length];
|
||||||
|
|
||||||
ObjectMap map = null;
|
ObjectMap map = null;
|
||||||
|
@ -1108,6 +1107,30 @@ public class CPPTemplates {
|
||||||
return argA != null && argB != null && argA.isSameType(argB);
|
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) {
|
static public IType[] createTypeArray(Object[] params) {
|
||||||
if (params == null)
|
if (params == null)
|
||||||
return IType.EMPTY_TYPE_ARRAY;
|
return IType.EMPTY_TYPE_ARRAY;
|
||||||
|
@ -1391,7 +1414,9 @@ public class CPPTemplates {
|
||||||
ICPPTemplateInstance pInst = (ICPPTemplateInstance) p;
|
ICPPTemplateInstance pInst = (ICPPTemplateInstance) p;
|
||||||
ICPPTemplateInstance aInst = (ICPPTemplateInstance) a;
|
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();
|
ObjectMap aMap = aInst.getArgumentMap();
|
||||||
if (aMap != null && !(aInst.getTemplateDefinition() instanceof ICPPClassTemplatePartialSpecialization)) {
|
if (aMap != null && !(aInst.getTemplateDefinition() instanceof ICPPClassTemplatePartialSpecialization)) {
|
||||||
ICPPTemplateParameter[] aParams = aInst.getTemplateDefinition().getTemplateParameters();
|
ICPPTemplateParameter[] aParams = aInst.getTemplateDefinition().getTemplateParameters();
|
||||||
|
@ -1403,7 +1428,9 @@ public class CPPTemplates {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
if (aArgs.length != pArgs.length)
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < pArgs.length; i++) {
|
for (int i = 0; i < pArgs.length; i++) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ class LookupData {
|
||||||
public IBinding unknownBinding= null;
|
public IBinding unknownBinding= null;
|
||||||
public Object foundItems = null;
|
public Object foundItems = null;
|
||||||
public Object[] functionParameters;
|
public Object[] functionParameters;
|
||||||
public IASTNode[] templateArguments;
|
public ICPPASTTemplateId templateId;
|
||||||
public ProblemBinding problem;
|
public ProblemBinding problem;
|
||||||
|
|
||||||
public LookupData(IASTName n) {
|
public LookupData(IASTName n) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue