[cfe-dev] How to get values from AttributeList

Aaron Ballman aaron at aaronballman.com
Fri Apr 17 08:23:24 PDT 2015


On Fri, Apr 17, 2015 at 11:05 AM, LUIS MIGUEL SANCHEZ GARCIA
<luismiguel.sanchez at uc3m.es> wrote:
> I would like to parser the values of a C++ attribute in clang, but I don't
> know how to get the information from the AttributeList class.
>
>
> For example, is it better to use?
>
>    IdentifierLoc *Value1 = A.getArgAsIdent(0);
>    IdentifierLoc *Value2 = A.getArgAsIdent(1);
>
>    or
>
>   Expr *Value1 = A.getArgAsExpr(0);
>   Expr *Value2 = A.getArgAsExpr(1);
>
> And later?

A good place to look is SemaDeclAttr.cpp; that's where parsed
attributes are converted into semantic attributes that attach to
declarations. (SemaStmtAttr.cpp is where you'd go for statement
attributes; type attributes are a bit more involved and live in
SemaType.cpp).

As for whether you would be using getArgAsIdent or getArgAsExpr, that
depends entirely on the declaration of your attribute in Attr.td
(specifically, what kind of arguments it takes). Attributes that take
an IdentifierArgument, EnumArgument, or VariadicEnumArgument all use
getArgAsIdent().

HTH!

~Aaron

>
> Thanks!
>
> Best 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
>




More information about the cfe-dev mailing list