[cfe-dev] How to get the AST of an expression serving as a template argument?
slycelote via cfe-dev
cfe-dev at lists.llvm.org
Sat Apr 9 14:10:27 PDT 2016
Thanks! I found that you can get it from TemplateSpecializationDecl,
code is below.
if (TypeSourceInfo* tsi = specDecl->getTypeAsWritten()) {
if (auto typeLoc =
tsi->getTypeLoc().getAs<TemplateSpecializationTypeLoc>()) {
for (unsigned i = 0; i < typeLoc.getNumArgs(); ++i) {
TemplateArgumentLocInfo locInfo = typeLoc.getArgLocInfo(i);
Expr* expr = locInfo.getAsExpr();
//expr->dump();
}
}
}
On 07/04/16 23:34, Nikola Smiljanic wrote:
> Sorry I can't give you the exact code but you want to get the primary
> template this was instantiated from (I think getTemplatedDecl returns it)
> and look at its argument.
>
> On Thu, Apr 7, 2016 at 1:58 PM, slycelote via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>> For example, in the program below RecursiveASTVisitor sees the template
>> argument as the integer 6. How to get the actual expression "n+n"?
>>
>> template<int m>
>> struct S {
>> };
>>
>> const int n = 3;
>>
>> template<>
>> struct S<n+n> {
>> };
>>
>> int main() {
>> S<6> s;
>> }
>>
>>
>> --
>> Sly.
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
--
Sly.
More information about the cfe-dev
mailing list