diff options
Diffstat (limited to 'core/org.eclipse.cdt.core')
24 files changed, 186 insertions, 216 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index a668dc29cab..cada1a83730 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; -import org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index 212d7d87724..ced69d9f59d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.index.IIndexType; /** @@ -115,10 +116,10 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements } @Override - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { ICPPSpecialization instance = getInstance(arguments); if (instance == null) { - instance = new CPPDeferredClassInstance(this, arguments); + instance = new CPPDeferredClassInstance(this, argMap, arguments); addSpecialization(arguments, instance); } return instance; @@ -127,7 +128,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements public void checkForDefinition() { FindDefinitionAction action = new FindDefinitionAction(); IASTNode node = CPPVisitor.getContainingBlockItem(declarations[0]).getParent(); - while(node instanceof ICPPASTTemplateDeclaration) + while (node instanceof ICPPASTTemplateDeclaration) node = node.getParent(); node.accept(action); definition = action.result; @@ -141,7 +142,8 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements } public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) { - partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.append(ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec); + partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.append( + ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec); } public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java index e53274136e3..de86471ed11 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java @@ -77,7 +77,7 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl //If the argument is a template parameter, we can't instantiate yet, defer for later if( CPPTemplates.typeContainsTemplateParameter( arg ) ){ - return deferredInstance( args ); + return deferredInstance( argMap, args ); } try { if( !CPPTemplates.deduceTemplateArgument( argMap, spec, arg ) ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index 782b22b5b9b..62ef1845645 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -110,7 +110,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization return CPPTemplates.instantiateTemplate(this, arguments, argumentMap); } - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java index 99ac715b7fe..aebbdfaf9d0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java @@ -24,20 +24,19 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance; 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.ICPPTemplateInstance; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ObjectMap; /** - * Represents a partially instantiated C++ class template, who's arguments contain at least one template - * type parameter. + * Represents a partially instantiated class template, where instance arguments contain at least one + * template type parameter. * * @author aniefer */ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassType, ICPPDeferredTemplateInstance, ICPPInternalDeferredClassInstance { - public CPPDeferredClassInstance(ICPPClassTemplate orig, IType[] arguments) { - super(null, orig, buildArgumentMap(orig, arguments), arguments); + public CPPDeferredClassInstance(ICPPClassTemplate orig, ObjectMap argMap, IType[] arguments) { + super(null, orig, argMap, arguments); } /* (non-Javadoc) @@ -177,34 +176,4 @@ public class CPPDeferredClassInstance extends CPPInstance private ICPPClassTemplate getClassTemplate() { return (ICPPClassTemplate) getSpecializedBinding(); } - - private static ObjectMap buildArgumentMap(ICPPClassTemplate template, IType[] arguments) { - ICPPTemplateParameter[] parameters = null; - try { - parameters = template.getTemplateParameters(); - } catch (DOMException e) { - } - - if (parameters == null || parameters.length == 0) { - return null; - } - - int numParams = parameters.length; - ObjectMap map = new ObjectMap(numParams); - int numArgs = arguments.length; - boolean trivial = true; - for (int i = 0; i < numParams && i < numArgs; i++) { - ICPPTemplateParameter param = parameters[i]; - IType arg = arguments[i]; - - if (!CPPTemplates.matchTemplateParameterAndArgument(param, arg, map)) { - return null; - } - map.put(param, arg); - if (!arg.equals(param)) { - trivial = false; - } - } - return trivial ? null : map; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java index bb2b5ac0b84..48fb9ba8288 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java @@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; /** * @author aniefer */ -public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBinding { +public class CPPField extends CPPVariable implements ICPPField { public static class CPPFieldProblem extends CPPVariable.CPPVariableProblem implements ICPPField { /** * @param id diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 0ebc9d4d865..49690bb9b2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -33,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** @@ -278,7 +279,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition#deferredInstance(org.eclipse.cdt.core.dom.ast.IType[]) */ @Override - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { ICPPSpecialization instance = getInstance( arguments ); if( instance == null ){ instance = new CPPDeferredFunctionInstance( this, arguments ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java index cdb3284171c..33bec3def1c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java @@ -13,7 +13,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.IBinding; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; @@ -24,8 +23,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; * @author aniefer * */ -public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization implements - ICPPFunctionTemplate, ICPPFunction, ICPPInternalTemplate { +public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization + implements ICPPFunctionTemplate, ICPPInternalTemplate { private ObjectMap instances = null; @@ -73,8 +72,7 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization return CPPTemplates.instantiateTemplate( this, arguments, argumentMap ); } - public ICPPSpecialization deferredInstance(IType[] arguments) { - // TODO Auto-generated method stub + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java index b5b04a70095..d0aa5f4aea3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java @@ -103,7 +103,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC } } - public abstract ICPPSpecialization deferredInstance(IType[] arguments); + public abstract ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments); public IBinding instantiate(ICPPASTTemplateId templateId) {//IASTNode[] arguments) { IASTNode[] args = templateId.getTemplateArguments(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java index bd29f4deca8..f754733c8f8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java @@ -41,7 +41,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements ICPPTemplateTemplateParameter, ICPPClassType, ICPPInternalTemplate, ICPPInternalUnknown { - private ICPPTemplateParameter [] templateParameters = null; + private ICPPTemplateParameter[] templateParameters = null; private ObjectMap instances = null; private ICPPScope unknownScope = null; @@ -50,16 +50,15 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement */ public CPPTemplateTemplateParameter(IASTName name) { super(name); - // TODO Auto-generated constructor stub } public ICPPScope getUnknownScope() { - if( unknownScope == null ) { + if (unknownScope == null) { IASTName n = null; IASTNode[] nodes = getDeclarations(); - if( nodes != null && nodes.length > 0 ) + if (nodes != null && nodes.length > 0) n = (IASTName) nodes[0]; - unknownScope = new CPPUnknownScope( this, n ); + unknownScope = new CPPUnknownScope(this, n); } return unknownScope; } @@ -68,25 +67,25 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter#getTemplateParameters() */ public ICPPTemplateParameter[] getTemplateParameters() { - if( templateParameters == null ){ + if (templateParameters == null) { ICPPASTTemplatedTypeTemplateParameter template = (ICPPASTTemplatedTypeTemplateParameter) getPrimaryDeclaration().getParent(); - ICPPASTTemplateParameter [] params = template.getTemplateParameters(); + ICPPASTTemplateParameter[] params = template.getTemplateParameters(); ICPPTemplateParameter p = null; - ICPPTemplateParameter [] result = null; + ICPPTemplateParameter[] result = null; for (int i = 0; i < params.length; i++) { - if( params[i] instanceof ICPPASTSimpleTypeTemplateParameter ){ + if (params[i] instanceof ICPPASTSimpleTypeTemplateParameter) { p = (ICPPTemplateParameter) ((ICPPASTSimpleTypeTemplateParameter)params[i]).getName().resolveBinding(); - } else if( params[i] instanceof ICPPASTParameterDeclaration ) { + } else if (params[i] instanceof ICPPASTParameterDeclaration) { p = (ICPPTemplateParameter) ((ICPPASTParameterDeclaration)params[i]).getDeclarator().getName().resolveBinding(); - } else if( params[i] instanceof ICPPASTTemplatedTypeTemplateParameter ){ + } else if (params[i] instanceof ICPPASTTemplatedTypeTemplateParameter) { p = (ICPPTemplateParameter) ((ICPPASTTemplatedTypeTemplateParameter)params[i]).getName().resolveBinding(); } - if( p != null ){ - result = (ICPPTemplateParameter[]) ArrayUtil.append( ICPPTemplateParameter.class, result, p ); + if (p != null) { + result = (ICPPTemplateParameter[]) ArrayUtil.append(ICPPTemplateParameter.class, result, p); } } - templateParameters = (ICPPTemplateParameter[]) ArrayUtil.trim( ICPPTemplateParameter.class, result ); + templateParameters = (ICPPTemplateParameter[]) ArrayUtil.trim(ICPPTemplateParameter.class, result); } return templateParameters; } @@ -96,18 +95,18 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @return */ public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) { - IASTName name = CPPTemplates.getTemplateParameterName( templateParameter ); + IASTName name = CPPTemplates.getTemplateParameterName(templateParameter); IBinding binding = name.getBinding(); - if( binding == null ){ + if (binding == null) { //create a new binding and set it for the corresponding parameter in all known decls - if( templateParameter instanceof ICPPASTSimpleTypeTemplateParameter ) - binding = new CPPTemplateTypeParameter( name ); - else if( templateParameter instanceof ICPPASTParameterDeclaration ) - binding = new CPPTemplateNonTypeParameter( name ); + if (templateParameter instanceof ICPPASTSimpleTypeTemplateParameter) + binding = new CPPTemplateTypeParameter(name); + else if (templateParameter instanceof ICPPASTParameterDeclaration) + binding = new CPPTemplateNonTypeParameter(name); else - binding = new CPPTemplateTemplateParameter( name ); - name.setBinding( binding ); + binding = new CPPTemplateTemplateParameter(name); + name.setBinding(binding); } return binding; } @@ -123,7 +122,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter#getDefault() */ public IType getDefault() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -131,7 +129,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases() */ public ICPPBase[] getBases() { - // TODO Auto-generated method stub return ICPPBase.EMPTY_BASE_ARRAY; } @@ -139,7 +136,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFields() */ public IField[] getFields() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -147,7 +143,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#findField(java.lang.String) */ public IField findField(String name) throws DOMException { - // TODO Auto-generated method stub return null; } @@ -155,7 +150,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields() */ public ICPPField[] getDeclaredFields() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -163,7 +157,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods() */ public ICPPMethod[] getMethods() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -171,7 +164,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods() */ public ICPPMethod[] getAllDeclaredMethods() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -179,7 +171,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods() */ public ICPPMethod[] getDeclaredMethods() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -194,7 +185,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends() */ public IBinding[] getFriends() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -202,7 +192,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey() */ public int getKey() throws DOMException { - // TODO Auto-generated method stub return 0; } @@ -210,7 +199,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope() */ public IScope getCompositeScope() throws DOMException { - // TODO Auto-generated method stub return null; } @@ -219,8 +207,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement */ @Override public void addDefinition(IASTNode node) { - // TODO Auto-generated method stub - } /* (non-Javadoc) @@ -228,18 +214,16 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement */ @Override public void addDeclaration(IASTNode node) { - // TODO Auto-generated method stub - } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) */ - public boolean isSameType( IType type ) { - if( type == this ) + public boolean isSameType(IType type) { + if (type == this) return true; - if( type instanceof ITypedef ) - return ((ITypedef)type).isSameType( this ); + if (type instanceof ITypedef) + return ((ITypedef)type).isSameType(this); return false; } @@ -248,54 +232,53 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement } public IBinding instantiate(IType[] arguments) { - return deferredInstance( arguments ); + return deferredInstance(null, arguments); } - public ICPPSpecialization deferredInstance(IType[] arguments) { - ICPPSpecialization instance = getInstance( arguments ); - if( instance == null ){ - instance = new CPPDeferredClassInstance( this, arguments ); - addSpecialization( arguments, instance ); + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { + ICPPSpecialization instance = getInstance(arguments); + if (instance == null) { + instance = new CPPDeferredClassInstance(this, argMap, arguments); + addSpecialization(arguments, instance); } return instance; } - public ICPPSpecialization getInstance( IType [] arguments ) { - if( instances == null ) + public ICPPSpecialization getInstance(IType[] arguments) { + if (instances == null) return null; int found = -1; - for( int i = 0; i < instances.size(); i++ ){ - IType [] args = (IType[]) instances.keyAt( i ); - if( args.length == arguments.length ){ + for (int i = 0; i < instances.size(); i++) { + IType[] args = (IType[]) instances.keyAt(i); + if (args.length == arguments.length) { int j = 0; - for(; j < args.length; j++) { - if( !( args[j].isSameType( arguments[j] ) ) ) + for (; j < args.length; j++) { + if (!(args[j].isSameType(arguments[j]))) break; } - if( j == args.length ){ + if (j == args.length) { found = i; break; } } } - if( found != -1 ){ + if (found != -1) { return (ICPPSpecialization) instances.getAt(found); } return null; } - public void addSpecialization( IType [] types, ICPPSpecialization spec ){ - if( instances == null ) - instances = new ObjectMap( 2 ); - instances.put( types, spec ); + public void addSpecialization(IType[] types, ICPPSpecialization spec) { + if (instances == null) + instances = new ObjectMap(2); + instances.put(types, spec); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#resolveUnknown(org.eclipse.cdt.core.parser.util.ObjectMap) */ - public IBinding resolveUnknown( ObjectMap argMap ) { - // TODO Auto-generated method stub + public IBinding resolveUnknown(ObjectMap argMap) { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java index b446be0e4d9..b7335ea52ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java @@ -1382,7 +1382,7 @@ public class CPPTemplates { } } - //14.5.4.1 If none of the specializations is more specialized than all the other matchnig + //14.5.4.1 If none of the specializations is more specialized than all the other matching //specializations, then the use of the class template is ambiguous and the program is ill-formed. if (!bestMatchIsBest) { //TODO problem @@ -1599,6 +1599,7 @@ public class CPPTemplates { ICPPTemplateParameter param = null; IType arg = null; IType[] actualArgs = new IType[numParams]; + boolean argsContainTemplateParameters = false; for (int i = 0; i < numParams; i++) { arg = null; @@ -1606,10 +1607,6 @@ public class CPPTemplates { if (i < numArgs) { arg = arguments[i]; - //If the argument is a template parameter, we can't instantiate yet, defer for later - if (typeContainsTemplateParameter(arg)) { - return ((ICPPInternalTemplateInstantiator) template).deferredInstance(arguments); - } } else { IType defaultType = null; try { @@ -1641,14 +1638,26 @@ public class CPPTemplates { } if (CPPTemplates.matchTemplateParameterAndArgument(param, arg, map)) { - map.put(param, arg); + if (!param.equals(arg)) { + map.put(param, arg); + } actualArgs[i] = arg; + if (typeContainsTemplateParameter(arg)) { + argsContainTemplateParameters = true; + } } else { //TODO problem return null; } } + if (map.isEmpty()) { + map = null; + } + if (argsContainTemplateParameters) { + return ((ICPPInternalTemplateInstantiator) template).deferredInstance(map, arguments); + } + ICPPSpecialization instance = ((ICPPInternalTemplateInstantiator) template).getInstance(actualArgs); if (instance != null) { return instance; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java index 048cf4eeb1a..2f447c5b64a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java @@ -63,10 +63,10 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPInte instances.put(arguments, specialization); } - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { ICPPSpecialization instance = getInstance(arguments); if (instance == null) { - instance = new CPPDeferredClassInstance(this, arguments); + instance = new CPPDeferredClassInstance(this, argMap, arguments); addSpecialization(arguments, instance); } return instance; @@ -93,7 +93,7 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPInte } public IBinding instantiate(IType[] arguments) { - return deferredInstance(arguments); + return deferredInstance(null, arguments); } public IType[] getArguments() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplateInstantiator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplateInstantiator.java index 6131cbf6a67..aa3c433f335 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplateInstantiator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplateInstantiator.java @@ -6,23 +6,24 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; +import org.eclipse.cdt.core.parser.util.ObjectMap; /** * @author Bryan Wilkinson - * */ public interface ICPPInternalTemplateInstantiator { - - public IBinding instantiate( IType [] arguments ); - - public ICPPSpecialization deferredInstance( IType [] arguments ); - - public ICPPSpecialization getInstance( IType [] arguments ); + + public IBinding instantiate(IType[] arguments); + + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments); + + public ICPPSpecialization getInstance(IType[] arguments); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java index a362464c689..3721c745e7f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.index.CIndex; @@ -63,8 +64,8 @@ ICPPClassTemplate, ICPPInternalTemplateInstantiator { return result; } - public ICPPSpecialization deferredInstance(IType[] arguments) { - return InternalTemplateInstantiatorUtil.deferredInstance(arguments, cf, rbinding); + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { + return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding); } public ICPPSpecialization getInstance(IType[] arguments) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java index 7fd91d119b6..9b4b90c4d10 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java @@ -18,6 +18,7 @@ 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.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; @@ -46,8 +47,8 @@ CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTempla return result; } - public ICPPSpecialization deferredInstance(IType[] arguments) { - return InternalTemplateInstantiatorUtil.deferredInstance(arguments, cf, rbinding); + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { + return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding); } public ICPPSpecialization getInstance(IType[] arguments) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java index bdf714929ba..bbf6e5959ab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java @@ -41,8 +41,8 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp } // TODO - what happens to the arguments? - public ICPPSpecialization deferredInstance(IType[] arguments) { - ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator)rbinding).deferredInstance(arguments); + public ICPPSpecialization deferredInstance(IType[] arguments, ObjectMap argMap) { + ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator) rbinding).deferredInstance(argMap, arguments); return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding)spec); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java index 072613379af..d3fcaaa1a36 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; @@ -35,8 +36,8 @@ public class CompositeCPPFunctionTemplate extends CompositeCPPFunction implement return result; } - public ICPPSpecialization deferredInstance(IType[] arguments) { - return InternalTemplateInstantiatorUtil.deferredInstance(arguments, cf, rbinding); + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { + return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding); } public ICPPSpecialization getInstance(IType[] arguments) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java index 33bd5c041f4..1bcf4fccd6a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; @@ -37,7 +38,7 @@ public class CompositeCPPFunctionTemplateSpecialization return result; } - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { fail(); return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java index c1de137928a..08c501d0f72 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.index.CIndex; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; @@ -23,10 +24,10 @@ import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; import org.eclipse.core.runtime.CoreException; public class InternalTemplateInstantiatorUtil { - public static ICPPSpecialization deferredInstance(IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) { - ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator)rbinding).deferredInstance(arguments); + public static ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) { + ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator)rbinding).deferredInstance(argMap, arguments); if (spec instanceof IIndexFragmentBinding) { - return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding)spec); + return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding) spec); } else { //can result in a non-index binding return spec; @@ -38,7 +39,7 @@ public class InternalTemplateInstantiatorUtil { try { IIndexFragmentBinding[] bindings= ((CIndex)((CPPCompositesFactory)cf).getContext()).findEquivalentBindings(cbinding); - for(int i=0; i<bindings.length && !(preferredInstance instanceof IIndexFragmentBinding); i++) { + for (int i = 0; i < bindings.length && !(preferredInstance instanceof IIndexFragmentBinding); i++) { ICPPInternalTemplateInstantiator instantiator= (ICPPInternalTemplateInstantiator) bindings[i]; preferredInstance= instantiator.getInstance(arguments); } @@ -46,7 +47,7 @@ public class InternalTemplateInstantiatorUtil { CCorePlugin.log(ce); } - if(preferredInstance instanceof IIndexFragmentBinding) { + if (preferredInstance instanceof IIndexFragmentBinding) { return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding)preferredInstance); } else { // can result in a non-index binding diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java index 479902681ae..d92399b3bb2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java @@ -38,6 +38,7 @@ import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance; @@ -54,11 +55,9 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson - * */ class PDOMCPPClassTemplate extends PDOMCPPClassType - implements ICPPClassTemplate, ICPPInternalTemplateInstantiator, - ICPPTemplateScope { + implements ICPPClassTemplate, ICPPInternalTemplateInstantiator, ICPPTemplateScope { private static final int PARAMETERS = PDOMCPPClassType.RECORD_SIZE + 0; private static final int INSTANCES = PDOMCPPClassType.RECORD_SIZE + 4; @@ -71,15 +70,14 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMCPPClassType.RECORD_SIZE + 16; - public PDOMCPPClassTemplate(PDOM pdom, PDOMNode parent, ICPPClassTemplate template) - throws CoreException { + public PDOMCPPClassTemplate(PDOM pdom, PDOMNode parent, ICPPClassTemplate template) throws CoreException { super(pdom, parent, (ICPPClassType) template); } public PDOMCPPClassTemplate(PDOM pdom, int bindingRecord) { super(pdom, bindingRecord); } - + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -130,16 +128,15 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException { try { - ArrayList<PDOMCPPClassTemplatePartialSpecialization> partials = new ArrayList<PDOMCPPClassTemplatePartialSpecialization>(); + ArrayList<PDOMCPPClassTemplatePartialSpecialization> partials = + new ArrayList<PDOMCPPClassTemplatePartialSpecialization>(); for (PDOMCPPClassTemplatePartialSpecialization partial = getFirstPartial(); partial != null; partial = partial.getNextPartial()) { partials.add(partial); } - return partials - .toArray(new ICPPClassTemplatePartialSpecialization[partials - .size()]); + return partials.toArray(new ICPPClassTemplatePartialSpecialization[partials.size()]); } catch (CoreException e) { CCorePlugin.log(e); return new ICPPClassTemplatePartialSpecialization[0]; @@ -154,7 +151,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException { try { if (getDBName().equals(name.toCharArray())) { - if (CPPClassScope.isConstructorReference(name)){ + if (CPPClassScope.isConstructorReference(name)) { return CPPSemantics.resolveAmbiguities(name, getConstructors()); } //9.2 ... The class-name is also inserted into the scope of the class itself @@ -172,7 +169,8 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType } }; - BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), filter, false, true); + BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), filter, + false, true); accept(visitor); return CPPSemantics.resolveAmbiguities(name, visitor.getBindings()); } catch (CoreException e) { @@ -182,7 +180,8 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType } @Override - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { + public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) + throws DOMException { IBinding[] result = null; try { if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0) @@ -202,7 +201,8 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType } }; - BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), filter, prefixLookup, !prefixLookup); + BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), filter, + prefixLookup, !prefixLookup); accept(visitor); result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings()); } catch (CoreException e) { @@ -213,7 +213,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType private class PDOMCPPTemplateScope implements ICPPTemplateScope, IIndexScope { public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings( this, name, false ); + return CPPSemantics.findBindings(this, name, false); } public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException { @@ -242,7 +242,8 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType throws DOMException { IBinding[] result = null; try { - BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup); + BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, + prefixLookup, !prefixLookup); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + PARAMETERS, getLinkageImpl()); list.accept(visitor); result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings()); @@ -309,10 +310,10 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType } } - public ICPPSpecialization deferredInstance(IType[] arguments) { - ICPPSpecialization instance = getInstance( arguments ); - if( instance == null ){ - instance = new CPPDeferredClassInstance( this, arguments ); + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { + ICPPSpecialization instance = getInstance(arguments); + if (instance == null) { + instance = new CPPDeferredClassInstance(this, argMap, arguments); } return instance; } @@ -368,10 +369,10 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType return e.getProblem(); } - if( template instanceof IProblemBinding ) + if (template instanceof IProblemBinding) return template; - if( template != null && template instanceof ICPPClassTemplatePartialSpecialization ){ - return ((PDOMCPPClassTemplate)template).instantiate( arguments ); + if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) { + return ((PDOMCPPClassTemplate)template).instantiate(arguments); } return CPPTemplates.instantiateTemplate(this, arguments, null); @@ -384,45 +385,46 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType } try { - if( type instanceof ICPPClassTemplate && !(type instanceof ProblemBinding)) { - boolean same= !(type instanceof ICPPClassTemplatePartialSpecialization); - ICPPClassType ctype= (ICPPClassType) type; - try { - if (same && ctype.getKey() == getKey()) { - char[][] qname= ctype.getQualifiedNameCharArray(); - same= hasQualifiedName(qname, qname.length-1); + if (type instanceof ICPPClassTemplate && !(type instanceof ProblemBinding)) { + boolean same= !(type instanceof ICPPClassTemplatePartialSpecialization); + ICPPClassType ctype= (ICPPClassType) type; + try { + if (same && ctype.getKey() == getKey()) { + char[][] qname= ctype.getQualifiedNameCharArray(); + same= hasQualifiedName(qname, qname.length - 1); + } + } catch (DOMException e) { + CCorePlugin.log(e); } - } catch (DOMException e) { - CCorePlugin.log(e); - } - if(!same) - return false; - - ICPPTemplateParameter[] params= getTemplateParameters(); - ICPPTemplateParameter[] oparams= ((ICPPClassTemplate)type).getTemplateParameters(); - - if(params==null && oparams==null) - return true; - - if(params==null || oparams==null) - return false; - - if(params.length != oparams.length) - return false; - - for(int i=0; same && i<params.length; i++) { - ICPPTemplateParameter p= params[i], op= oparams[i]; - if(p instanceof IType && op instanceof IType) { - same &= (((IType)p).isSameType((IType)op)); - } else { + if (!same) + return false; + + ICPPTemplateParameter[] params= getTemplateParameters(); + ICPPTemplateParameter[] oparams= ((ICPPClassTemplate) type).getTemplateParameters(); + + if (params == null && oparams == null) + return true; + + if (params == null || oparams == null) return false; + + if (params.length != oparams.length) + return false; + + for (int i = 0; same && i < params.length; i++) { + ICPPTemplateParameter p= params[i]; + ICPPTemplateParameter op= oparams[i]; + if (p instanceof IType && op instanceof IType) { + same &= (((IType)p).isSameType((IType)op)); + } else { + return false; + } } + + return same; } - - return same; - } - } catch(DOMException de) { - CCorePlugin.log(de); + } catch (DOMException e) { + CCorePlugin.log(e); return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java index 51f78bfc344..84f1c0a5168 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java @@ -25,7 +25,6 @@ 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.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.Util; @@ -41,7 +40,6 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson - * */ class PDOMCPPClassTemplatePartialSpecialization extends PDOMCPPClassTemplate implements ICPPClassTemplatePartialSpecialization, ICPPSpecialization, IPDOMOverloader { @@ -118,16 +116,16 @@ class PDOMCPPClassTemplatePartialSpecialization extends } private static class TemplateArgumentCollector implements IPDOMVisitor { - private List args = new ArrayList(); + private List<IType> args = new ArrayList<IType>(); public boolean visit(IPDOMNode node) throws CoreException { if (node instanceof IType) - args.add(node); + args.add((IType) node); return false; } public void leave(IPDOMNode node) throws CoreException { } public IType[] getTemplateArguments() { - return (IType[])args.toArray(new IType[args.size()]); + return args.toArray(new IType[args.size()]); } } @@ -182,7 +180,7 @@ class PDOMCPPClassTemplatePartialSpecialization extends //If the argument is a template parameter, we can't instantiate yet, defer for later if( CPPTemplates.typeContainsTemplateParameter( arg ) ){ - return deferredInstance( args ); + return deferredInstance( argMap, args ); } try { if( !CPPTemplates.deduceTemplateArgument( argMap, spec, arg ) ) @@ -199,11 +197,11 @@ class PDOMCPPClassTemplatePartialSpecialization extends return null; } - return (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args ); + return CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args ); } private static class NodeCollector implements IPDOMVisitor { - private List nodes = new ArrayList(); + private List<IPDOMNode> nodes = new ArrayList<IPDOMNode>(); public boolean visit(IPDOMNode node) throws CoreException { nodes.add(node); return false; @@ -211,7 +209,7 @@ class PDOMCPPClassTemplatePartialSpecialization extends public void leave(IPDOMNode node) throws CoreException { } public IPDOMNode[] getNodes() { - return (IPDOMNode[])nodes.toArray(new IPDOMNode[nodes.size()]); + return nodes.toArray(new IPDOMNode[nodes.size()]); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java index f8ebac41c23..4057ad7d1ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; @@ -74,10 +75,10 @@ class PDOMCPPClassTemplateSpecialization extends return template.getTemplateParameters(); } - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { ICPPSpecialization instance = getInstance( arguments ); if( instance == null ){ - instance = new CPPDeferredClassInstance( this, arguments ); + instance = new CPPDeferredClassInstance( this, argMap, arguments ); } return instance; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java index 90d200c7cfd..9db85d11167 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates; @@ -47,7 +48,6 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson - * */ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements ICPPFunctionTemplate, ICPPInternalTemplateInstantiator, @@ -114,7 +114,7 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements } } - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { ICPPSpecialization instance = getInstance(arguments); if( instance == null ){ instance = new CPPDeferredFunctionInstance( this, arguments ); @@ -224,7 +224,8 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements throws DOMException { IBinding[] result = null; try { - BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup); + BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, + prefixLookup, !prefixLookup); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + TEMPLATE_PARAMS, getLinkageImpl()); list.accept(visitor); result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java index 443cc2bc282..156052adab6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; @@ -69,7 +70,7 @@ class PDOMCPPFunctionTemplateSpecialization extends return template.getTemplateParameters(); } - public ICPPSpecialization deferredInstance(IType[] arguments) { + public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { ICPPSpecialization instance = getInstance(arguments); if( instance == null ){ instance = new CPPDeferredFunctionInstance( this, arguments ); |