<div dir="ltr">Thanks Aaron,<div><br></div><div>It was the solution. In order to complete the information<b> I include my complete example, If anyone needs it.</b> </div><div><br></div><div>In the original source code I included an attribute named (own::custom) that receive one or more <b>unsigned int</b>.</div><div><br></div><div><font face="monospace, monospace">[[own::custom(1,2,3,4)]]</font></div><div><font face="monospace, monospace">statement;</font></div><div><br></div><div>In file<font face="monospace, monospace"> tools/clang/lib/Sema/SemaStmtAttr.cpp</font>, I included:</div><div><br></div><div><div><font face="monospace, monospace">static Attr *handleOWNCustomAttr(Sema &S, Stmt *St, const AttributeList &A,</font></div><div><font face="monospace, monospace">                                   SourceRange Range) {</font></div><div><font face="monospace, monospace">  std::vector<unsigned int> Values;</font></div><div><font face="monospace, monospace">  for (unsigned int i=0;i<A.getNumArgs ();++i){</font></div><div><font face="monospace, monospace">         Expr *Arg1 = A.getArgAsExpr(i);</font></div><div><font face="monospace, monospace">          if (auto *L = dyn_cast<IntegerLiteral>(Arg1)) {</font></div><div><font face="monospace, monospace">                llvm::APInt V = L->getValue();</font></div><div><font face="monospace, monospace">                unsigned int rint = std::atoi(V.toString(10,false).c_str());</font></div><div><font face="monospace, monospace">                Values.push_back(rint);                 </font></div><div><font face="monospace, monospace">          }</font></div><div><font face="monospace, monospace">  }</font></div><div><font face="monospace, monospace">  return ::new (S.Context) OWNCustomAttr(A.getRange(), S.Context, &Values[0], Values.size(),</font></div><div><font face="monospace, monospace">                                           A.getAttributeSpellingListIndex());</font></div><div><font face="monospace, monospace">}</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">I hope that it could help anyone.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><b>Now I have another question</b>: I would like to get the same information with variadic enums as parameters.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">I included something like (in tools/clang/include/clang/Basic/Attr.td</font><span style="font-family:arial,helvetica,sans-serif">):</span></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><div><font face="monospace, monospace">def OWNCustom : Attr {</font></div><div><font face="monospace, monospace">  let Spellings = [CXX11<"own", "custom">];</font></div><div><font face="monospace, monospace">  let Args = [VariadicEnumArgument<"Callable", "Consumed",</font></div><div><font face="monospace, monospace">                                   ["AA", "BB", "CC"],</font></div><div><font face="monospace, monospace">                                   ["AA", "BB", "CC"]>];</font></div><div><font face="monospace, monospace">  let Documentation = [Undocumented];</font></div><div><font face="monospace, monospace">}</font></div></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">and in file tools/clang/lib/Sema/SemaStmtAttr.cpp I included:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><div><font face="monospace, monospace">static Attr *handleOWNCustomAttr(Sema &S, Stmt *St, const AttributeList &A, </font></div><div><font face="monospace, monospace">                                   SourceRange Range) {</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">  std::vector<OWNCustom::Consumed> Values;<br></font></div><div><font face="monospace, monospace">  for (unsigned int i=0;i<A.getNumArgs ();++i){</font></div><div><font face="monospace, monospace">         IdentifierLoc *Arg1 = A.getArgAsIdent(i);</font></div><div><font face="monospace, monospace">         OWNCustom::Consumed Out;</font><span style="font-family:monospace,monospace">         </span></div><div><font face="monospace, monospace">         if (OWNCustom::ConvertStrToConsumed (Arg1->Ident->getName(), Out)){</font></div><div><font face="monospace, monospace">                Values.push_back(Out);  </font></div><div><font face="monospace, monospace">          }   </font></div><div><font face="monospace, monospace">  }<br></font></div><div><font face="monospace, monospace">  </font></div><div><font face="monospace, monospace">  return ::new (S.Context) OWNCustomAttr(A.getRange(), S.Context, </font></div><div><font face="monospace, monospace">                                           &Values[0], Values.size(),<br></font></div><div><font face="monospace, monospace">                                           A.getAttributeSpellingListIndex());</font></div><div><font face="monospace, monospace">}</font></div></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Evething works with only one attribute (e.g. [[own::custom(AA)]]), but fails with two or more enums (e.g. [[own::custom(AA,BB)]]).</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Any help?</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Thanks!</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Regards,</font></div><div><font face="arial, helvetica, sans-serif">Luis.</font></div><div><font face="monospace, monospace"><br></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-17 17:45 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 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. 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>
</span>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>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><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>
</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>