mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 299911. Implementations of ICPPEvaluation.instantiate methods.
This commit is contained in:
parent
1a90fef0a5
commit
01d99c5643
4 changed files with 87 additions and 32 deletions
|
@ -201,7 +201,7 @@ public class EvalBinding extends CPPEvaluation {
|
||||||
IType type = CPPTemplates.instantiateType(originalType, tpMap, packOffset, within, point);
|
IType type = CPPTemplates.instantiateType(originalType, tpMap, packOffset, within, point);
|
||||||
IValue originalValue = enumerator.getValue();
|
IValue originalValue = enumerator.getValue();
|
||||||
IValue value = CPPTemplates.instantiateValue(originalValue, tpMap, packOffset, within, maxdepth, point);
|
IValue value = CPPTemplates.instantiateValue(originalValue, tpMap, packOffset, within, maxdepth, point);
|
||||||
// TODO(sprigogin): Not sure is the following condition is correct.
|
// TODO(sprigogin): Not sure if following condition is correct.
|
||||||
if (type != originalType || value != originalValue)
|
if (type != originalType || value != originalValue)
|
||||||
return new EvalFixed(type, ValueCategory.PRVALUE, value);
|
return new EvalFixed(type, ValueCategory.PRVALUE, value);
|
||||||
} else if (fBinding instanceof ICPPTemplateNonTypeParameter) {
|
} else if (fBinding instanceof ICPPTemplateNonTypeParameter) {
|
||||||
|
@ -211,16 +211,12 @@ public class EvalBinding extends CPPEvaluation {
|
||||||
return new EvalFixed(null, ValueCategory.PRVALUE, value);
|
return new EvalFixed(null, ValueCategory.PRVALUE, value);
|
||||||
}
|
}
|
||||||
// TODO(sprigogin): Do we need something similar for pack expansion?
|
// TODO(sprigogin): Do we need something similar for pack expansion?
|
||||||
} else if (fBinding instanceof IVariable) {
|
|
||||||
// TODO(sprigogin): Not sure what to do in this case.
|
|
||||||
} else if (fBinding instanceof IFunction) {
|
|
||||||
// TODO(sprigogin): Not sure what to do in this case.
|
|
||||||
} else if (fBinding instanceof ICPPUnknownBinding) {
|
} else if (fBinding instanceof ICPPUnknownBinding) {
|
||||||
try {
|
try {
|
||||||
binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fBinding, tpMap,
|
binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fBinding, tpMap,
|
||||||
packOffset, within, point);
|
packOffset, within, point);
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore?
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (binding == fBinding)
|
if (binding == fBinding)
|
||||||
|
|
|
@ -7,13 +7,19 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||||
|
|
||||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||||
|
@ -130,7 +136,39 @@ public class EvalFunctionSet extends CPPEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
||||||
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
||||||
// TODO(sprigogin): Not sure how to instantiate what to instantiate a CPPFunctionSet.
|
ICPPTemplateArgument[] originalArguments = fFunctionSet.getTemplateArguments();
|
||||||
return this;
|
ICPPTemplateArgument[] arguments = originalArguments;
|
||||||
|
try {
|
||||||
|
arguments = CPPTemplates.instantiateArguments(originalArguments, tpMap, packOffset, within, point);
|
||||||
|
} catch (DOMException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
IBinding originalOwner = fFunctionSet.getOwner();
|
||||||
|
IBinding owner = originalOwner;
|
||||||
|
if (originalOwner instanceof ICPPUnknownBinding) {
|
||||||
|
try {
|
||||||
|
owner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) owner, tpMap,
|
||||||
|
packOffset, within, point);
|
||||||
|
} catch (DOMException e) {
|
||||||
|
CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore?
|
||||||
|
}
|
||||||
|
} else if (owner instanceof IType) {
|
||||||
|
IType type = CPPTemplates.instantiateType((IType) owner, tpMap, packOffset, within, point);
|
||||||
|
if (type instanceof IBinding)
|
||||||
|
owner = (IBinding) type;
|
||||||
|
}
|
||||||
|
ICPPFunction[] originalFunctions = fFunctionSet.getBindings();
|
||||||
|
ICPPFunction[] functions = originalFunctions;
|
||||||
|
if (owner instanceof ICPPClassSpecialization && owner != originalOwner) {
|
||||||
|
functions = new ICPPFunction[originalFunctions.length];
|
||||||
|
for (int i = 0; i < originalFunctions.length; i++) {
|
||||||
|
functions[i] = (ICPPFunction) CPPTemplates.createSpecialization((ICPPClassSpecialization) owner,
|
||||||
|
originalFunctions[i], point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Arrays.equals(arguments, originalArguments) && functions == originalFunctions)
|
||||||
|
return this;
|
||||||
|
return new EvalFunctionSet(new CPPFunctionSet(functions, arguments, null), fAddressOf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,15 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||||
|
|
||||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
|
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
|
||||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
@ -22,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||||
|
@ -252,6 +256,13 @@ public class EvalID extends CPPEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
||||||
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
||||||
|
ICPPTemplateArgument[] arguments = fTemplateArgs;
|
||||||
|
try {
|
||||||
|
arguments = CPPTemplates.instantiateArguments(fTemplateArgs, tpMap, packOffset, within, point);
|
||||||
|
} catch (DOMException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
|
||||||
ICPPEvaluation fieldOwner = fFieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point);
|
ICPPEvaluation fieldOwner = fFieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point);
|
||||||
IBinding nameOwner = fNameOwner;
|
IBinding nameOwner = fNameOwner;
|
||||||
if (fNameOwner instanceof ICPPTemplateParameter) {
|
if (fNameOwner instanceof ICPPTemplateParameter) {
|
||||||
|
@ -266,12 +277,34 @@ public class EvalID extends CPPEvaluation {
|
||||||
nameOwner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fNameOwner, tpMap,
|
nameOwner = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fNameOwner, tpMap,
|
||||||
packOffset, within, point);
|
packOffset, within, point);
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore?
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fieldOwner == fFieldOwner && nameOwner == fNameOwner)
|
if (Arrays.equals(arguments, fTemplateArgs) && fieldOwner == fFieldOwner && nameOwner == fNameOwner)
|
||||||
return this;
|
return this;
|
||||||
// TODO(sprigogin): Not sure how to construct the new evaluation.
|
|
||||||
return this;
|
if (nameOwner == null)
|
||||||
|
nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point);
|
||||||
|
|
||||||
|
if (nameOwner instanceof ICompositeType) {
|
||||||
|
ICompositeType ownerType = (ICompositeType) nameOwner;
|
||||||
|
// TODO(sprigogin): Is this the right way to do lookup, or should findBindings be used instead?
|
||||||
|
LookupData data = new LookupData(fName, fTemplateArgs, point);
|
||||||
|
try {
|
||||||
|
CPPSemantics.lookup(data, ownerType.getScope());
|
||||||
|
} catch (DOMException e) {
|
||||||
|
}
|
||||||
|
IBinding[] bindings = data.getFoundBindings();
|
||||||
|
IBinding binding = bindings.length == 1 ? bindings[0] : null;
|
||||||
|
if (binding instanceof IEnumerator) {
|
||||||
|
return new EvalBinding(binding, null);
|
||||||
|
} else if (binding instanceof ICPPMember) {
|
||||||
|
return new EvalMemberAccess(ownerType, ValueCategory.PRVALUE, binding, false);
|
||||||
|
} else if (binding instanceof CPPFunctionSet) {
|
||||||
|
return new EvalFunctionSet((CPPFunctionSet) binding, fAddressOf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,6 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
@ -316,24 +314,14 @@ public class EvalMemberAccess extends CPPEvaluation {
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
|
||||||
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
|
||||||
IType type = CPPTemplates.instantiateType(fOwnerType, tpMap, packOffset, within, point);
|
IType ownerType = CPPTemplates.instantiateType(fOwnerType, tpMap, packOffset, within, point);
|
||||||
IBinding member = fMember;
|
if (ownerType == fOwnerType)
|
||||||
if (fMember instanceof ICPPUnknownBinding) {
|
|
||||||
try {
|
|
||||||
member = CPPTemplates.resolveUnknown((ICPPUnknownBinding) fMember, tpMap,
|
|
||||||
packOffset, within, point);
|
|
||||||
} catch (DOMException e) {
|
|
||||||
CCorePlugin.log(e); // TODO(sprigogin): Is this exception safe to ignore?
|
|
||||||
}
|
|
||||||
} else if (fMember instanceof IEnumerator) {
|
|
||||||
// TODO(sprigogin): Not sure what to do in this case.
|
|
||||||
} else if (fMember instanceof IVariable) {
|
|
||||||
// TODO(sprigogin): Not sure what to do in this case.
|
|
||||||
} else if (fMember instanceof IFunction) {
|
|
||||||
// TODO(sprigogin): Not sure what to do in this case.
|
|
||||||
}
|
|
||||||
if (type == fOwnerType && member == fMember)
|
|
||||||
return this;
|
return this;
|
||||||
return new EvalMemberAccess(type, fOwnerValueCategory, member, fIsPointerDeref);
|
|
||||||
|
IBinding member = fMember;
|
||||||
|
if (ownerType instanceof ICPPClassSpecialization) {
|
||||||
|
member = CPPTemplates.createSpecialization((ICPPClassSpecialization) ownerType, fMember, point);
|
||||||
|
}
|
||||||
|
return new EvalMemberAccess(ownerType, fOwnerValueCategory, member, fIsPointerDeref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue