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

LUIS MIGUEL SANCHEZ GARCIA luismiguel.sanchez at uc3m.es
Tue Apr 14 07:53:21 PDT 2015


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
--------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150414/220a9198/attachment.html>


More information about the cfe-dev mailing list