Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to instantiate a CPPVariable?

Thanks, Nate. I think I’ll try that since I’m currently working on the 
instantiation of function templates for constexpr evaluation.

Regards,
Toni

Am 09.12.2015 um 20:13 schrieb Nathan Ridge <zeratul976@xxxxxxxxxxx>:

CDT doesn't currently instantiate the bodies of function templates
(only their declarations), so it doesn't yet have support built out
for some operations that are only needed in the context of 
instantiating the body of a function template, such as instantiating
a local variable.

To support this properly, we would want to add a 
CPPVariableSpecialization class similar to CPPFieldSpecialization,
and create one from an ICPPVariable in a way similar to how CPPTemplates.createSpecialization() creates a 
CPPFieldSpecialization from an ICPPField.

If you're interested in contributing this support, I would be happy
to review it. It would lay some of the groundwork for eventually
instantiating bodies of functions, which is something I'd like CDT
to be able to do at some point.

Regards,
Nate



From: toni.suter@xxxxxx
To: cdt-dev@xxxxxxxxxxx
Date: Wed, 9 Dec 2015 15:13:25 +0000
Subject: [cdt-dev] How to instantiate a CPPVariable?

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

_______________________________________________ cdt-dev mailing list cdt-dev@xxxxxxxxxxx To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top