mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 540549 - Have all template parameter bindings implement ICPPUnknownBinding
Change-Id: If09679f2d56c987175a8d85514da37840ac71205
This commit is contained in:
parent
1bb3bb5768
commit
86b8f21623
17 changed files with 83 additions and 37 deletions
|
@ -525,6 +525,9 @@ public class AST2TestBase extends SemanticTestBase {
|
|||
|
||||
final protected void assertNoProblemBindings(NameCollector col) {
|
||||
for (IASTName n : col.nameList) {
|
||||
if (n.getRawSignature().contains("waldo")) {
|
||||
n.resolveBinding();
|
||||
}
|
||||
assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ package org.eclipse.cdt.core.dom.ast.cpp;
|
|||
/**
|
||||
* Base interface for all template parameters (non-type, type and template).
|
||||
*
|
||||
* All template parameters should implement ICPPUnknownBinding as well
|
||||
* (but ICPPTemplateParameter cannot extend ICPPUnknownBinding because
|
||||
* ICPPUnknownBinding is not API).
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
|
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IValue;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
|
@ -171,4 +173,11 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
|
|||
public boolean isConstexpr() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPScope asScope() throws DOMException {
|
||||
// A non-type template parameter can never appear on the left hand side
|
||||
// of a scope resolution operator.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
|
@ -94,4 +95,11 @@ public class CPPTemplateNonTypeParameterSpecialization extends CPPTemplateParame
|
|||
public IASTExpression getDefault() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPScope asScope() throws DOMException {
|
||||
// A non-type template parameter can never appear on the left hand side
|
||||
// of a scope resolution operator.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
* Base implementation for template parameter bindings in the AST.
|
||||
*/
|
||||
public abstract class CPPTemplateParameter extends PlatformObject
|
||||
implements ICPPTemplateParameter, ICPPInternalBinding, ICPPTwoPhaseBinding {
|
||||
implements ICPPTemplateParameter, ICPPInternalBinding, ICPPTwoPhaseBinding, ICPPUnknownBinding {
|
||||
private IASTName[] declarations;
|
||||
private final int fParameterID;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
* CPPTemplateTypeParameterSpecialization, and CPPTemplateTemplateParameterSpecialization.
|
||||
*/
|
||||
public abstract class CPPTemplateParameterSpecialization extends PlatformObject
|
||||
implements ICPPTemplateParameter, ICPPSpecialization {
|
||||
implements ICPPTemplateParameter, ICPPSpecialization, ICPPUnknownBinding {
|
||||
private final ICPPSpecialization fOwner;
|
||||
private final ICPPScope fScope;
|
||||
private final ICPPTemplateParameter fSpecialized;
|
||||
|
|
|
@ -48,7 +48,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
|||
* A template template parameter.
|
||||
*/
|
||||
public class CPPTemplateTemplateParameter extends CPPTemplateParameter
|
||||
implements ICPPTemplateTemplateParameter, ICPPInternalTemplate, ICPPUnknownBinding, ICPPUnknownType {
|
||||
implements ICPPTemplateTemplateParameter, ICPPInternalTemplate, ICPPUnknownType {
|
||||
private ICPPTemplateParameter[] templateParameters;
|
||||
private ObjectMap instances;
|
||||
private ICPPScope unknownScope;
|
||||
|
|
|
@ -42,6 +42,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
|||
*/
|
||||
public class CPPTemplateTemplateParameterSpecialization extends CPPTemplateParameterSpecialization
|
||||
implements ICPPTemplateTemplateParameter {
|
||||
// The scope of the type named by the parameter specialization.
|
||||
// Not to be confused with CPPTemplateParameterSpecialization.fScope,
|
||||
// which is the enclosing scope in which the parameter specialization lives.
|
||||
private ICPPScope fScope;
|
||||
|
||||
public CPPTemplateTemplateParameterSpecialization(ICPPSpecialization owner, ICPPScope scope,
|
||||
ICPPTemplateTemplateParameter specialized, ICPPTemplateArgument defaultValue) {
|
||||
|
@ -175,4 +179,12 @@ public class CPPTemplateTemplateParameterSpecialization extends CPPTemplateParam
|
|||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPScope asScope() throws DOMException {
|
||||
if (fScope == null) {
|
||||
return new CPPUnknownTypeScope(this, new CPPASTName(getNameCharArray()));
|
||||
}
|
||||
return fScope;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|||
* The standard template parameter (template<typename T> or template<class T>).
|
||||
*/
|
||||
public class CPPTemplateTypeParameter extends CPPTemplateParameter
|
||||
implements ICPPTemplateTypeParameter, ICPPUnknownType, ICPPUnknownBinding {
|
||||
implements ICPPTemplateTypeParameter, ICPPUnknownType {
|
||||
private ICPPScope unknownScope;
|
||||
private final boolean fIsParameterPack;
|
||||
|
||||
|
|
|
@ -31,6 +31,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
|||
*/
|
||||
public class CPPTemplateTypeParameterSpecialization extends CPPTemplateParameterSpecialization
|
||||
implements ICPPTemplateTypeParameter {
|
||||
// The scope of the type named by the parameter specialization.
|
||||
// Not to be confused with CPPTemplateParameterSpecialization.fScope,
|
||||
// which is the enclosing scope in which the parameter specialization lives.
|
||||
private ICPPScope fScope;
|
||||
|
||||
public CPPTemplateTypeParameterSpecialization(ICPPSpecialization owner, ICPPScope scope,
|
||||
ICPPTemplateTypeParameter specialized, ICPPTemplateArgument defaultValue) {
|
||||
|
@ -69,4 +73,12 @@ public class CPPTemplateTypeParameterSpecialization extends CPPTemplateParameter
|
|||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPScope asScope() throws DOMException {
|
||||
if (fScope == null) {
|
||||
return new CPPUnknownTypeScope(this, new CPPASTName(getNameCharArray()));
|
||||
}
|
||||
return fScope;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1217,10 +1217,6 @@ public class CPPTemplates {
|
|||
return r;
|
||||
}
|
||||
|
||||
if (type instanceof ICPPTemplateParameter) {
|
||||
return determinePackSize((ICPPTemplateParameter) type, tpMap);
|
||||
}
|
||||
|
||||
if (type instanceof TypeOfDependentExpression) {
|
||||
return ((TypeOfDependentExpression) type).getEvaluation().determinePackSize(tpMap);
|
||||
}
|
||||
|
@ -1248,23 +1244,23 @@ public class CPPTemplates {
|
|||
return r;
|
||||
}
|
||||
|
||||
static int determinePackSize(ICPPTemplateParameter tpar, ICPPTemplateParameterMap tpMap) {
|
||||
if (tpar.isParameterPack()) {
|
||||
ICPPTemplateArgument[] args = tpMap.getPackExpansion(tpar);
|
||||
if (args != null) {
|
||||
return args.length;
|
||||
}
|
||||
return PACK_SIZE_DEFER;
|
||||
}
|
||||
return PACK_SIZE_NOT_FOUND;
|
||||
}
|
||||
|
||||
static int determinePackSize(ICPPUnknownBinding binding, ICPPTemplateParameterMap tpMap) {
|
||||
if (binding instanceof ICPPTemplateParameter) {
|
||||
ICPPTemplateParameter tpar = (ICPPTemplateParameter) binding;
|
||||
if (tpar.isParameterPack()) {
|
||||
ICPPTemplateArgument[] args = tpMap.getPackExpansion(tpar);
|
||||
if (args != null) {
|
||||
return args.length;
|
||||
}
|
||||
return PACK_SIZE_DEFER;
|
||||
}
|
||||
return PACK_SIZE_NOT_FOUND;
|
||||
}
|
||||
int r = PACK_SIZE_NOT_FOUND;
|
||||
if (binding instanceof ICPPDeferredClassInstance) {
|
||||
ICPPDeferredClassInstance dcl = (ICPPDeferredClassInstance) binding;
|
||||
if (dcl.getClassTemplate() instanceof ICPPTemplateTemplateParameter) {
|
||||
r = combinePackSize(r, determinePackSize((ICPPTemplateParameter) dcl.getClassTemplate(), tpMap));
|
||||
r = combinePackSize(r, determinePackSize((ICPPUnknownBinding) dcl.getClassTemplate(), tpMap));
|
||||
}
|
||||
ICPPTemplateArgument[] args = dcl.getTemplateArguments();
|
||||
for (ICPPTemplateArgument arg : args) {
|
||||
|
|
|
@ -481,9 +481,6 @@ public class EvalBinding extends CPPDependentEvaluation {
|
|||
if (binding instanceof IEnumerator) {
|
||||
return CPPTemplates.determinePackSize(((IEnumerator) binding).getValue(), tpMap);
|
||||
}
|
||||
if (binding instanceof ICPPTemplateNonTypeParameter) {
|
||||
return CPPTemplates.determinePackSize((ICPPTemplateNonTypeParameter) binding, tpMap);
|
||||
}
|
||||
if (binding instanceof ICPPUnknownBinding) {
|
||||
return CPPTemplates.determinePackSize((ICPPUnknownBinding) binding, tpMap);
|
||||
}
|
||||
|
@ -500,7 +497,7 @@ public class EvalBinding extends CPPDependentEvaluation {
|
|||
if (binding instanceof ICPPTemplateDefinition) {
|
||||
ICPPTemplateParameter[] parameters = ((ICPPTemplateDefinition) binding).getTemplateParameters();
|
||||
for (ICPPTemplateParameter param : parameters) {
|
||||
r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(param, tpMap));
|
||||
r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize((ICPPUnknownBinding) param, tpMap));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
|
@ -237,6 +236,9 @@ public class EvalID extends CPPDependentEvaluation {
|
|||
if (binding instanceof CPPFunctionSet) {
|
||||
return new EvalFunctionSet((CPPFunctionSet) binding, qualified, isAddressOf(expr), null, expr);
|
||||
}
|
||||
if (binding instanceof ICPPTemplateNonTypeParameter) { // has to come before ICPPUnknownBinding
|
||||
return new EvalBinding(binding, null, expr);
|
||||
}
|
||||
if (binding instanceof ICPPUnknownBinding) {
|
||||
// If the id-expression names a variable template, there is no need to defer name lookup.
|
||||
if (binding instanceof ICPPDeferredVariableInstance) {
|
||||
|
@ -305,8 +307,7 @@ public class EvalID extends CPPDependentEvaluation {
|
|||
}
|
||||
return new EvalBinding(binding, null, expr);
|
||||
}
|
||||
if (binding instanceof ICPPTemplateNonTypeParameter || binding instanceof IVariable
|
||||
|| binding instanceof IFunction) {
|
||||
if (binding instanceof IVariable || binding instanceof IFunction) {
|
||||
return new EvalBinding(binding, null, expr);
|
||||
}
|
||||
return EvalFixed.INCOMPLETE;
|
||||
|
@ -497,10 +498,7 @@ public class EvalID extends CPPDependentEvaluation {
|
|||
@Override
|
||||
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
|
||||
int r = fFieldOwner != null ? fFieldOwner.determinePackSize(tpMap) : CPPTemplates.PACK_SIZE_NOT_FOUND;
|
||||
if (fNameOwner instanceof ICPPTemplateParameter) {
|
||||
r = CPPTemplates.combinePackSize(r,
|
||||
CPPTemplates.determinePackSize((ICPPTemplateParameter) fNameOwner, tpMap));
|
||||
} else if (fNameOwner instanceof ICPPUnknownBinding) {
|
||||
if (fNameOwner instanceof ICPPUnknownBinding) { // handles template parameters as well
|
||||
r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize((ICPPUnknownBinding) fNameOwner, tpMap));
|
||||
}
|
||||
if (fTemplateArgs != null) {
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.IInternalPDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -22,7 +23,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Interface for template parameters stored in the index.
|
||||
*/
|
||||
public interface IPDOMCPPTemplateParameter extends IInternalPDOMNode, ICPPTemplateParameter {
|
||||
public interface IPDOMCPPTemplateParameter extends IInternalPDOMNode, ICPPTemplateParameter, ICPPUnknownBinding {
|
||||
IPDOMCPPTemplateParameter[] EMPTY_ARRAY = {};
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
|
@ -235,4 +236,11 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding
|
|||
public IASTExpression getDefault() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPScope asScope() throws DOMException {
|
||||
// A non-type template parameter can never appear on the left hand side
|
||||
// of a scope resolution operator.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||
|
@ -52,7 +51,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* Implementation of template template parameters for the index.
|
||||
*/
|
||||
public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding implements ICPPTemplateTemplateParameter,
|
||||
ICPPUnknownBinding, ICPPUnknownType, IIndexType, IPDOMCPPTemplateParameter, IPDOMCPPTemplateParameterOwner {
|
||||
ICPPUnknownType, IIndexType, IPDOMCPPTemplateParameter, IPDOMCPPTemplateParameterOwner {
|
||||
private static final int PACK_BIT = 1 << 31;
|
||||
|
||||
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE;
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||
|
@ -41,8 +40,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Binding for template type parameters in the index.
|
||||
*/
|
||||
class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMemberOwner, ICPPTemplateTypeParameter,
|
||||
ICPPUnknownBinding, ICPPUnknownType, IIndexType, IPDOMCPPTemplateParameter {
|
||||
class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding
|
||||
implements IPDOMMemberOwner, ICPPTemplateTypeParameter, ICPPUnknownType, IIndexType, IPDOMCPPTemplateParameter {
|
||||
private static final int PACK_BIT = 1 << 31;
|
||||
|
||||
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE;
|
||||
|
|
Loading…
Add table
Reference in a new issue