<div dir="ltr">Thanks for your comments!<div><br></div><div>I changed the enumerators like this:</div><div><br></div><font face="monospace, monospace" color="#0000ff"> def OWNCustom : Attr {<br>   let Spellings = [CXX11<"own", "custom">];<br>   let Args = [VariadicEnumArgument<"Callable", "Consumed",<br>                                    ["aa", "bb", "cc"],<br>                                    ["AA", "BB", "CC"]>];<br>}</font><br><br>however, I still have problems:<div><br></div><div><div><font face="monospace, monospace" color="#0000ff">clang++ test01.cpp  -std=c++1y -Xclang -ast-dump -fsyntax-only</font></div><div><font face="monospace, monospace" color="#0000ff">test01.cpp:8:90: error: use of undeclared identifier 'aa'</font></div><div><font face="monospace, monospace" color="#0000ff">    [[own::custom(bb,aa)]]</font></div></div><div><br></div><div>If I include only one parameter <span style="color:rgb(0,0,255);font-family:monospace,monospace">[[own::custom(aa)]]</span>, It works.</div><div><br></div><div>Any idea about what is happening?</div><div><br></div><div>Regards,</div><div>Luis.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-22 0:13 GMT+02:00 Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Apr 21, 2015 at 9:54 AM, LUIS MIGUEL SANCHEZ GARCIA<br>
<<a href="mailto:luismiguel.sanchez@uc3m.es">luismiguel.sanchez@uc3m.es</a>> wrote:<br>
> Thanks Aaron,<br>
><br>
> It was the solution. In order to complete the information I include my<br>
> complete example, If anyone needs it.<br>
><br>
> In the original source code I included an attribute named (own::custom) that<br>
> receive one or more unsigned int.<br>
><br>
> [[own::custom(1,2,3,4)]]<br>
> statement;<br>
><br>
> In file tools/clang/lib/Sema/SemaStmtAttr.cpp, I included:<br>
><br>
> static Attr *handleOWNCustomAttr(Sema &S, Stmt *St, const AttributeList &A,<br>
>                                    SourceRange Range) {<br>
>   std::vector<unsigned int> Values;<br>
>   for (unsigned int i=0;i<A.getNumArgs ();++i){<br>
>          Expr *Arg1 = A.getArgAsExpr(i);<br>
>           if (auto *L = dyn_cast<IntegerLiteral>(Arg1)) {<br>
>                 llvm::APInt V = L->getValue();<br>
>                 unsigned int rint = std::atoi(V.toString(10,false).c_str());<br>
<br>
</span>There's no need to use a string to convert the APInt object, btw. ;-)<br>
<span class=""><br>
>                 Values.push_back(rint);<br>
>           }<br>
>   }<br>
>   return ::new (S.Context) OWNCustomAttr(A.getRange(), S.Context,<br>
> &Values[0], Values.size(),<br>
><br>
> A.getAttributeSpellingListIndex());<br>
> }<br>
><br>
> I hope that it could help anyone.<br>
><br>
> Now I have another question: I would like to get the same information with<br>
> variadic enums as parameters.<br>
><br>
> I included something like (in tools/clang/include/clang/Basic/Attr.td):<br>
><br>
> def OWNCustom : Attr {<br>
>   let Spellings = [CXX11<"own", "custom">];<br>
>   let Args = [VariadicEnumArgument<"Callable", "Consumed",<br>
>                                    ["AA", "BB", "CC"],<br>
>                                    ["AA", "BB", "CC"]>];<br>
<br>
</span>You don't want the values and the enumerators to be the same<br>
identifiers; that seems like a dangerous idea.<br>
<span class=""><br>
>   let Documentation = [Undocumented];<br>
> }<br>
><br>
> and in file tools/clang/lib/Sema/SemaStmtAttr.cpp I included:<br>
><br>
> static Attr *handleOWNCustomAttr(Sema &S, Stmt *St, const AttributeList &A,<br>
>                                    SourceRange Range) {<br>
><br>
>   std::vector<OWNCustom::Consumed> Values;<br>
>   for (unsigned int i=0;i<A.getNumArgs ();++i){<br>
>          IdentifierLoc *Arg1 = A.getArgAsIdent(i);<br>
>          OWNCustom::Consumed Out;<br>
>          if (OWNCustom::ConvertStrToConsumed (Arg1->Ident->getName(), Out)){<br>
>                 Values.push_back(Out);<br>
>           }<br>
>   }<br>
><br>
>   return ::new (S.Context) OWNCustomAttr(A.getRange(), S.Context,<br>
>                                            &Values[0], Values.size(),<br>
><br>
> A.getAttributeSpellingListIndex());<br>
> }<br>
><br>
> Evething works with only one attribute (e.g. [[own::custom(AA)]]), but fails<br>
> with two or more enums (e.g. [[own::custom(AA,BB)]]).<br>
><br>
> Any help?<br>
<br>
</span>Fails in what way?<br>
<br>
Also, that code has UB when no enumeration values are provided to your<br>
attribute (&Values[0] would be more safely written as Values.data()).<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> Thanks!<br>
><br>
><br>
> Regards,<br>
> Luis.<br>
><br>
><br>
> 2015-04-17 17:45 GMT+02:00 Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>>:<br>
>><br>
>> On Fri, Apr 17, 2015 at 11:38 AM, LUIS MIGUEL SANCHEZ GARCIA<br>
>> <<a href="mailto:luismiguel.sanchez@uc3m.es">luismiguel.sanchez@uc3m.es</a>> wrote:<br>
>> > Hi Aaron,<br>
>> ><br>
>> > I included two integers in <a href="http://attr.td" target="_blank">attr.td</a> file for this attribute declaration.<br>
>> > I<br>
>> > included the numbers by hand in the object creation<br>
>> > (I wrote a handler in SemaDeclAttr.cpp file)<br>
>> > and works, but I obtain error when I try to get the values form the<br>
>> > attribute list.<br>
>> ><br>
>> > Do you have any hint?<br>
>><br>
>> Without seeing your code, it's hard to give a concrete answer, but I<br>
>> suspect what you want is something like:<br>
>><br>
>> Expr *Arg = A.getArgAsExpr(0);<br>
>> if (auto *L = dyn_cast<IntegerLiteral>(Arg)) {<br>
>>   llvm::APInt V = L->getValue();<br>
>>   // Do interesting things<br>
>> }<br>
>><br>
>> ~Aaron<br>
>><br>
>> ><br>
>> > Thanks!<br>
>> > Luis.<br>
>> ><br>
>> > El 17/04/2015 17:23, "Aaron Ballman" <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> escribió:<br>
>> >><br>
>> >> On Fri, Apr 17, 2015 at 11:05 AM, LUIS MIGUEL SANCHEZ GARCIA<br>
>> >> <<a href="mailto:luismiguel.sanchez@uc3m.es">luismiguel.sanchez@uc3m.es</a>> wrote:<br>
>> >> > I would like to parser the values of a C++ attribute in clang, but I<br>
>> >> > don't<br>
>> >> > know how to get the information from the AttributeList class.<br>
>> >> ><br>
>> >> ><br>
>> >> > For example, is it better to use?<br>
>> >> ><br>
>> >> >    IdentifierLoc *Value1 = A.getArgAsIdent(0);<br>
>> >> >    IdentifierLoc *Value2 = A.getArgAsIdent(1);<br>
>> >> ><br>
>> >> >    or<br>
>> >> ><br>
>> >> >   Expr *Value1 = A.getArgAsExpr(0);<br>
>> >> >   Expr *Value2 = A.getArgAsExpr(1);<br>
>> >> ><br>
>> >> > And later?<br>
>> >><br>
>> >> A good place to look is SemaDeclAttr.cpp; that's where parsed<br>
>> >> attributes are converted into semantic attributes that attach to<br>
>> >> declarations. (SemaStmtAttr.cpp is where you'd go for statement<br>
>> >> attributes; type attributes are a bit more involved and live in<br>
>> >> SemaType.cpp).<br>
>> >><br>
>> >> As for whether you would be using getArgAsIdent or getArgAsExpr, that<br>
>> >> depends entirely on the declaration of your attribute in Attr.td<br>
>> >> (specifically, what kind of arguments it takes). Attributes that take<br>
>> >> an IdentifierArgument, EnumArgument, or VariadicEnumArgument all use<br>
>> >> getArgAsIdent().<br>
>> >><br>
>> >> HTH!<br>
>> >><br>
>> >> ~Aaron<br>
>> >><br>
>> >> ><br>
>> >> > Thanks!<br>
>> >> ><br>
>> >> > Best regards,<br>
>> >> > Luis.<br>
>> >> > --<br>
>> >> > --<br>
>> >> > --<br>
>> >> > --------------------------------------------------<br>
>> >> > Luis Miguel Sánchez García<br>
>> >> > Computer Architecture and Technology Area.<br>
>> >> > Office 2.2.B08<br>
>> >> > Computer Science Department. UNIVERSIDAD CARLOS III DE MADRID<br>
>> >> > Universidad Carlos III de Madrid<br>
>> >> > Avda. de la Universidad, 30<br>
>> >> > 28911 Leganés - Madrid - Spain<br>
>> >> > e-mail: <a href="mailto:lmsan@arcos.inf.uc3m.es">lmsan@arcos.inf.uc3m.es</a><br>
>> >> >         <a href="mailto:luismiguel.sanchez@uc3m.es">luismiguel.sanchez@uc3m.es</a><br>
>> >> ><br>
>> >> > Phone: (+34) 91 624 5951<br>
>> >> ><br>
>> >> > Linked-In: <a href="http://es.linkedin.com/in/lmsan" target="_blank">http://es.linkedin.com/in/lmsan</a><br>
>> >> > Twitter: <a href="http://twitter.com/lmsanchezgarcia" target="_blank">http://twitter.com/lmsanchezgarcia</a><br>
>> >> > --------------------------------------------------<br>
>> >> ><br>
>> >> > _______________________________________________<br>
>> >> > cfe-dev mailing list<br>
>> >> > <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> >> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
>> >> ><br>
><br>
><br>
><br>
><br>
> --<br>
> --<br>
> --<br>
> --------------------------------------------------<br>
> Luis Miguel Sánchez García<br>
> Computer Architecture and Technology Area.<br>
> Office 2.2.B08<br>
> Computer Science Department. UNIVERSIDAD CARLOS III DE MADRID<br>
> Universidad Carlos III de Madrid<br>
> Avda. de la Universidad, 30<br>
> 28911 Leganés - Madrid - Spain<br>
> e-mail: <a href="mailto:lmsan@arcos.inf.uc3m.es">lmsan@arcos.inf.uc3m.es</a><br>
>         <a href="mailto:luismiguel.sanchez@uc3m.es">luismiguel.sanchez@uc3m.es</a><br>
><br>
> Phone: (+34) 91 624 5951<br>
><br>
> Linked-In: <a href="http://es.linkedin.com/in/lmsan" target="_blank">http://es.linkedin.com/in/lmsan</a><br>
> Twitter: <a href="http://twitter.com/lmsanchezgarcia" target="_blank">http://twitter.com/lmsanchezgarcia</a><br>
> --------------------------------------------------<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;font-family:arial">-- </span><br style="font-size:small;font-family:arial"><span style="font-size:small;font-family:arial">-- </span><br style="font-size:small;font-family:arial"><span style="font-size:small;font-family:arial">--------------------------------------------------</span><br style="font-size:small;font-family:arial"><span style="font-size:small;font-family:arial">Luis Miguel Sánchez García</span><br style="font-size:small;font-family:arial"><span style="font-size:small;font-family:arial;border-collapse:collapse">Computer Architecture and Technology Area.</span><div style="font-size:small;font-family:arial">Office 2.2.B08<br><div>Computer Science Department. UNIVERSIDAD CARLOS III DE MADRID<br>Universidad Carlos III de Madrid<br>Avda. de la Universidad, 30<br>28911 Leganés - Madrid - Spain<br>e-mail: <a href="mailto:lmsan@arcos.inf.uc3m.es" style="color:rgb(17,85,204)" target="_blank">lmsan@arcos.inf.uc3m.es</a><br>        <a href="mailto:luismiguel.sanchez@uc3m.es" style="color:rgb(17,85,204)" target="_blank">luismiguel.sanchez@uc3m.es</a><br><br></div><div>Phone: (+34) 91 624 5951<br><div> <br>Linked-In: <a href="http://es.linkedin.com/in/lmsan" style="color:rgb(17,85,204)" target="_blank">http://es.linkedin.com/in/lmsan</a><br>Twitter: <a href="http://twitter.com/lmsanchezgarcia" style="color:rgb(17,85,204)" target="_blank">http://twitter.com/lmsanchezgarcia</a><br>--------------------------------------------------</div></div></div></div></div></div>
</div>