Skip to content

Commit b09ee88

Browse files
committed
Generalize our two different kinds of declaration argument for
attributes to support any kind of declaration. In preparation for adding a third kind.
1 parent 1e5f149 commit b09ee88

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
174174
class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
175175
class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
176176
class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
177-
class FunctionArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
178-
opt,
179-
fake>;
180-
class NamedArgument<string name, bit opt = 0, bit fake = 0> : Argument<name,
181-
opt,
182-
fake>;
177+
class DeclArgument<DeclNode kind, string name, bit opt = 0, bit fake = 0>
178+
: Argument<name, opt, fake> {
179+
DeclNode Kind = kind;
180+
}
183181

184182
// An argument of a OMPDeclareVariantAttr that represents the `match`
185183
// clause of the declare variant by keeping the information (incl. nesting) in
@@ -956,7 +954,7 @@ def OSConsumesThis : InheritableAttr {
956954

957955
def Cleanup : InheritableAttr {
958956
let Spellings = [GCC<"cleanup">];
959-
let Args = [FunctionArgument<"FunctionDecl">];
957+
let Args = [DeclArgument<Function, "FunctionDecl">];
960958
let Subjects = SubjectList<[LocalVar]>;
961959
let Documentation = [Undocumented];
962960
}
@@ -2382,7 +2380,7 @@ def DiagnoseIf : InheritableAttr {
23822380
["error", "warning"],
23832381
["DT_Error", "DT_Warning"]>,
23842382
BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
2385-
NamedArgument<"Parent", 0, /*fake*/ 1>];
2383+
DeclArgument<Named, "Parent", 0, /*fake*/ 1>];
23862384
let InheritEvenIfAlreadyPresent = 1;
23872385
let LateParsed = 1;
23882386
let AdditionalMembers = [{

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ namespace {
339339
}
340340

341341
void writeDump(raw_ostream &OS) const override {
342-
if (type == "FunctionDecl *" || type == "NamedDecl *") {
342+
if (StringRef(type).endswith("Decl *")) {
343343
OS << " OS << \" \";\n";
344344
OS << " dumpBareDeclRef(SA->get" << getUpperName() << "());\n";
345345
} else if (type == "IdentifierInfo *") {
@@ -1290,10 +1290,9 @@ createArgument(const Record &Arg, StringRef Attr,
12901290
Ptr = std::make_unique<EnumArgument>(Arg, Attr);
12911291
else if (ArgName == "ExprArgument")
12921292
Ptr = std::make_unique<ExprArgument>(Arg, Attr);
1293-
else if (ArgName == "FunctionArgument")
1294-
Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "FunctionDecl *");
1295-
else if (ArgName == "NamedArgument")
1296-
Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "NamedDecl *");
1293+
else if (ArgName == "DeclArgument")
1294+
Ptr = std::make_unique<SimpleArgument>(
1295+
Arg, Attr, (Arg.getValueAsDef("Kind")->getName() + "Decl *").str());
12971296
else if (ArgName == "IdentifierArgument")
12981297
Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "IdentifierInfo *");
12991298
else if (ArgName == "DefaultBoolArgument")

0 commit comments

Comments
 (0)