I’m adding a custom attribute followed by this http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute, here’s my def:
def MEItem : InheritableParamAttr {
let Spellings = [CXX11<“me”, “type”>, C2x<“me”, “type”>];
let Args = [StringArgument<“Type”, 1>, StringArgument<“Getter”, 1>, StringArgument<“Setter”, 1>];
let Subjects = SubjectList<[Field]>;
let Documentation = [Undocumented];
}
I just copied what ExternalSourceSymbol does, so the handling code is like this:
static void handleMEItemAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!checkAttributeAtLeastNumArgs(S, AL, 1))
return;
assert(checkAttributeAtMostNumArgs(S, AL, 3) &&
“Invalid number of arguments in an item attribute”);
StringRef Type;
if (const auto *SE = dyn_cast_or_null(AL.getArgAsExpr(0)))
Type = SE->getString();
StringRef Getter;
if (const auto *SE = dyn_cast_or_null(AL.getArgAsExpr(1)))
Getter = SE->getString();
StringRef Setter;
if (const auto *SE = dyn_cast_or_null(AL.getArgAsExpr(2)))
Setter = SE->getString();
D->addAttr(::new (S.Context) MEItemAttr(S.Context, AL, Type, Getter, Setter));
}
but if I use this attribute in my code, for example [[me::type(“int”)]], the code crashed at AL.getArgAsExpr(1):
clang::ArgsUnion clang::ParsedAttr::getArg(unsigned int) const: Assertion `Arg < NumArgs && “Arg access out of range!”’ failed.
then I tried this: [[me::type(Type=“int”, Getter=“xxx”, Setter=“xxx”)]]
error: use of undeclared identifier ‘Type’ [[me::type(Type=“int”, Getter=“xxx”, Setter=“xxx”)]]
So what did I miss?