<div dir="ltr">Hi Aaron,<div><br></div><div><span style="font-size:12.8000001907349px">[[own::custom("bb", "aa")]] doesn't work. However, If I add the values by hand, It works:</span><br></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><div><font face="monospace, monospace"> Values.push_back(OWNCustom::AA);</font></div><div><font face="monospace, monospace"> Values.push_back(OWNCustom::BB);</font></div><div><font face="monospace, monospace"> return ::new (S.Context) OWNCustomAttr(A.getRange(), S.Context, Values.data(), Values.size(),</font></div><div><font face="monospace, monospace"> A.getAttributeSpellingListIndex());</font></div></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 18:44 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 Wed, Apr 22, 2015 at 3:10 AM, LUIS MIGUEL SANCHEZ GARCIA<br>
<<a href="mailto:luismiguel.sanchez@uc3m.es">luismiguel.sanchez@uc3m.es</a>> wrote:<br>
> Thanks for your comments!<br>
><br>
> I changed the enumerators like this:<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>
><br>
> however, I still have problems:<br>
><br>
> clang++ test01.cpp -std=c++1y -Xclang -ast-dump -fsyntax-only<br>
> test01.cpp:8:90: error: use of undeclared identifier 'aa'<br>
> [[own::custom(bb,aa)]]<br>
><br>
> If I include only one parameter [[own::custom(aa)]], It works.<br>
><br>
> Any idea about what is happening?<br>
<br>
</span>It seems that variadic enumerations expect the second (and later)<br>
arguments to be quoted strings, not identifiers. If you look at<br>
ParseAttributeArgsCommon, only the first argument can be an<br>
identifier. I think that's a bug, but in the meantime, you can do:<br>
<br>
[[own::custom("bb", "aa")]] instead, and that should work.<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> Regards,<br>
> Luis.<br>
><br>
><br>
> 2015-04-22 0:13 GMT+02:00 Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>>:<br>
>><br>
>> 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)<br>
>> > 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<br>
>> > &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 =<br>
>> > std::atoi(V.toString(10,false).c_str());<br>
>><br>
>> There's no need to use a string to convert the APInt object, btw. ;-)<br>
>><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<br>
>> > 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>
>> You don't want the values and the enumerators to be the same<br>
>> identifiers; that seems like a dangerous idea.<br>
>><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<br>
>> > &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(),<br>
>> > 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<br>
>> > fails<br>
>> > with two or more enums (e.g. [[own::custom(AA,BB)]]).<br>
>> ><br>
>> > Any help?<br>
>><br>
>> 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>
>><br>
>> ~Aaron<br>
>><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<br>
>> >> > 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>><br>
>> >> > 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<br>
>> >> >> > 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,<br>
>> >> >> that<br>
>> >> >> depends entirely on the declaration of your attribute in Attr.td<br>
>> >> >> (specifically, what kind of arguments it takes). Attributes that<br>
>> >> >> 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>
><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>