[cfe-dev] How to get values from AttributeList
Aaron Ballman
aaron at aaronballman.com
Fri Apr 17 08:45:03 PDT 2015
On Fri, Apr 17, 2015 at 11:38 AM, LUIS MIGUEL SANCHEZ GARCIA
<luismiguel.sanchez at uc3m.es> wrote:
> Hi Aaron,
>
> I included two integers in attr.td file for this attribute declaration. I
> included the numbers by hand in the object creation
> (I wrote a handler in SemaDeclAttr.cpp file)
> and works, but I obtain error when I try to get the values form the
> attribute list.
>
> Do you have any hint?
Without seeing your code, it's hard to give a concrete answer, but I
suspect what you want is something like:
Expr *Arg = A.getArgAsExpr(0);
if (auto *L = dyn_cast<IntegerLiteral>(Arg)) {
llvm::APInt V = L->getValue();
// Do interesting things
}
~Aaron
>
> Thanks!
> Luis.
>
> El 17/04/2015 17:23, "Aaron Ballman" <aaron at aaronballman.com> escribió:
>>
>> 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