Hi everyone,
I’m trying to instantiate a CPPVariable or better yet an IVariable in general. Let’s say,
I have a declaration T val{}; in a function template where
T is a template parameter.
Later I use val in some way, e.g. val++; Here, val’s binding is a CPPVariable with a type
that is a CPPTemplateTypeParameter. What I want is to instantiate the CPPVariable or in other
words create a new CPPVariable where the type is replaced with the template argument
that is provided for the template parameter T. How should I do that? Right now my solution
looks like this, but I wondered whether there is a better way of doing it:
IType newType = CPPTemplates.instantiateType(variable.getType(),
tpMap,
packOffset, within,
point);
CPPVariable newVariable;
if(newType != variable.getType()) {
newVariable =
new CPPVariable((IASTName)variable.getDefinition(),
newType);
if(variable.getDeclarations() !=
null) {
for(IASTNode
declaration : variable.getDeclarations()) {
newVariable.addDeclaration(declaration);
}
}
}
I also tried to use CPPTemplates.instantiateBinding(), but this function does nothing if the binding is
a CPPVariable.
Thank you and best regards,
Toni
|