1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Lazy initialization of LookupData.fTemplateArguments to avoid exceptions

in constructor.

Change-Id: I875233c7fe40ab4a56d9b76fb03c2e03441d29ae
This commit is contained in:
Sergey Prigogin 2015-08-21 18:36:26 -07:00
parent bea6a49e5b
commit 5d54cc3996
2 changed files with 30 additions and 25 deletions

View file

@ -463,7 +463,7 @@ public class CPPSemantics {
} else {
// Do not interpret template arguments to a template class as being
// explicit template arguments to its templated constructor.
data.fTemplateArguments = null;
data.setTemplateArguments(null);
binding= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, lookupPoint), true);
}
} catch (DOMException e) {
@ -1162,7 +1162,7 @@ public class CPPSemantics {
char[] tchars= new char[typeDtorChars.length - 1];
System.arraycopy(typeDtorChars, 1, tchars, 0, tchars.length);
LookupData ld2= new LookupData(tchars, data.fTemplateArguments, data.getLookupPoint());
LookupData ld2= new LookupData(tchars, data.getTemplateArguments(), data.getLookupPoint());
ld2.setIgnorePointOfDeclaration(data.isIgnorePointOfDeclaration());
ld2.contentAssist= data.contentAssist;
ld2.fNoNarrowing= data.fNoNarrowing;
@ -2469,7 +2469,7 @@ public class CPPSemantics {
// No arguments to resolve function
final IASTNode lookupPoint = data.getLookupPoint();
if (!data.hasFunctionArguments()) {
return createFunctionSet(fns, data.fTemplateArguments, lookupPoint, lookupName);
return createFunctionSet(fns, data.getTemplateArguments(), lookupPoint, lookupName);
}
// Reduce our set of candidate functions to only those who have the right number of parameters
@ -2477,7 +2477,7 @@ public class CPPSemantics {
ICPPFunction[] tmp= selectByArgumentCount(data, fns);
if (tmp.length == 0 || tmp[0] == null)
return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
tmp= CPPTemplates.instantiateForFunctionCall(tmp, data.fTemplateArguments,
tmp= CPPTemplates.instantiateForFunctionCall(tmp, data.getTemplateArguments(),
Arrays.asList(argTypes),
Arrays.asList(data.getFunctionArgumentValueCategories()),
data.argsContainImpliedObject, lookupPoint);

View file

@ -16,7 +16,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getSimplifiedType;
import org.eclipse.cdt.core.CCorePlugin;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
@ -73,15 +76,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Context data for IASTName lookup
*/
public class LookupData extends ScopeLookupData {
public ICPPTemplateArgument[] fTemplateArguments;
private static final ICPPTemplateArgument[] UNINITIALIZED_TEMPLATE_ARGUMENTS = {};
public Map<ICPPNamespaceScope, List<ICPPNamespaceScope>> usingDirectives= Collections.emptyMap();
/** Used to ensure we don't visit things more than once. */
@ -114,26 +113,16 @@ public class LookupData extends ScopeLookupData {
private ICPPEvaluation[] functionArgs;
private IType[] functionArgTypes;
private ValueCategory[] functionArgValueCategories;
private ICPPTemplateArgument[] fTemplateArguments = UNINITIALIZED_TEMPLATE_ARGUMENTS;
public ICPPClassType skippedScope;
public Object foundItems;
public ProblemBinding problem;
public LookupData(IASTName n) {
super(n, true, false);
if (n == null)
throw new IllegalArgumentException();
ICPPTemplateArgument[] args = null;
if (n instanceof ICPPASTTemplateId) {
try {
args= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) n);
} catch (DOMException e) {
CCorePlugin.log(e);
}
}
fTemplateArguments= args;
configureWith(n);
public LookupData(IASTName name) {
super(name, true, false);
fTemplateArguments = UNINITIALIZED_TEMPLATE_ARGUMENTS; // Lazy initialization to avoid DOMException.
configureWith(name);
}
public LookupData(char[] name, ICPPTemplateArgument[] templateArgs, IASTNode lookupPoint) {
@ -563,6 +552,22 @@ public class LookupData extends ScopeLookupData {
return functionArgValueCategories;
}
public ICPPTemplateArgument[] getTemplateArguments() throws DOMException {
if (fTemplateArguments == UNINITIALIZED_TEMPLATE_ARGUMENTS) {
IASTName name = getLookupName();
if (name instanceof ICPPASTTemplateId) {
fTemplateArguments = CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) name);
} else {
fTemplateArguments = null;
}
}
return fTemplateArguments;
}
void setTemplateArguments(ICPPTemplateArgument[] fTemplateArguments) {
this.fTemplateArguments = fTemplateArguments;
}
public int getFunctionArgumentCount() {
if (functionArgs != null)
return functionArgs.length;