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