[cfe-dev] Using clang-query for matching C++11 attributes

Manuel Klimek klimek at google.com
Tue Apr 14 18:22:50 PDT 2015


You'll probably need to implement a matcher for that, I don't think there
exists one yet.

On Tue, Apr 14, 2015 at 7:59 AM LUIS MIGUEL SANCHEZ GARCIA <
luismiguel.sanchez at uc3m.es> wrote:

> Hi all,
>
> I'm trying to extract the compound or single statement contained into an
> C++11 attribute using "clang-query".
>
>
> For example:
>
> - file.cpp contains:
>
> int main()
> {
>     int a = 5;
>     int b = 6;
>
> *    [[own::decl]] //included in my clang version*
> *    for (int i=0;i<100;i++){*
> * auto c = a + b;*
> *    }*
>     auto j1 = 2*a ;
>
>     return 0;
> }
>
> - using clang-query -extra-arg="-std=c++1y" file.cpp --
> clang-query>set output dump
> clang-query>match */* something */*
>
> and obtain as result something like:
>
> Match #1:
>
> Binding for "root":
> AttributedStmt 0x30cd8f0 </tmp/test01.cpp:8:5, line:11:5>
> |-OWNdeclAttr 0x30cd8e0 <line:8:7, col:12>
> `-ForStmt 0x30cd8a8 <line:9:5, line:11:5>
>   |-DeclStmt 0x30cd580 <line:9:10, col:17>
>   .......
>
>
> I would like to use something similar to the example of hasAttr() (which
> it does not work) found in
> http://clang.llvm.org/docs/LibASTMatchersReference.htmlMatcher<Decl>hasAttrattr::Kind
> AttrKind
>
> Matches declaration that has a given attribute.
>> Given
>>   __attribute__((device)) void f() { ... }
>> decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of
>> f.
>
>
> Thanks!
> Regards,
> Luis.
>
>
> --
> --
> --
> --------------------------------------------------
> Luis Miguel Sánchez García
> Computer Architecture and Technology Area.
> Office 2.2.B08
> Computer Science Department. UNIVERSIDAD CARLOS III DE MADRID
> Universidad Carlos III de Madrid
> Avda. de la Universidad, 30
> 28911 Leganés - Madrid - Spain
> e-mail: lmsan at arcos.inf.uc3m.es
>         luismiguel.sanchez at uc3m.es
>
> Phone: (+34) 91 624 5951
>
> Linked-In: http://es.linkedin.com/in/lmsan
> Twitter: http://twitter.com/lmsanchezgarcia
> --------------------------------------------------
>  _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150415/43d0dfe4/attachment.html>


More information about the cfe-dev mailing list