[cfe-dev] Finding all references to template alias

Abir Basak abirbasak at gmail.com
Fri Mar 22 03:23:56 PDT 2013


On Thu, Mar 21, 2013 at 9:39 PM, Manuel Klimek <klimek at google.com> wrote:

> On Thu, Mar 21, 2013 at 12:27 PM, Abir Basak <abirbasak at gmail.com> wrote:
>
>>
>> I am new to clang AST. I am trying to write a program which rewrites all
>> locations in a TU where template alias are used.
>>
>> say, given
>>
>> 1. template<class T,class U = T>
>> 2. class class_1{};
>> 3. template<class U>
>> 4. using alias1 = class_1<U>;
>> 5. template<class T,class U>
>> 6. using alias2 = class_1<T,U>;
>> 7.
>> 8. template<class X,class Y = alias1<X> >
>> 9. void foo(...)
>> 10. {
>> 11.   alias2<int,X> x = ...;
>> 12. }
>>
>> I am interested to transform all references to template alias to
>> something like typename alias1<X>::type, typename alias2<int,X>::type x =
>> ... etc, and may be optionally remove the 'typename' part if the resulting
>> type is not dependent.
>> I am using C++ API with RAV, and presently can get all template alias
>> decl using
>> Visit/Traverse TypeAliasTemplateDecl, but has no idea how to get all
>> references to them, such as at line 8 & 11 , irrespective to their name.
>>
>
> I have not dealt with template aliases yet, but I'd expect it pretty much
> to work like for any other type declaration:
> In line (8) you have a TemplateTypeParmDecl whose getDefaultArgument will
> yield a type (not sure which one exactly, I expect something
> like TemplateSpecializationType), whose declaration will be the
> TypeAliasDecl.
> In line (11) you have a declaration with the given type.
>
> With RAV, you'll want to visit TypeLoc's and check that those type locs
> refer to your template alias decl.
>
> Cheers,
> /Manuel
>
>
>
>>
>> Any help will be appreciated.
>> Thank you.
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
> Thank you for the reply. It just worked with TypeLoc.
Now I have a separate problem.
How can I get function prototype portion of defaulted/deleted function?

Say given, a class x, I have a defaulted constructor

class x
{
    inline x(x const& bla) noexcept = default
};
I am interested to get source for the function just before = sign, so that
i can translate it to
   inline x(x const& bla) noexcept
  {
  }
preferably keeping indentation correct.

Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130322/3af7afc9/attachment.html>


More information about the cfe-dev mailing list