From b09ee8882010ff2a7d55e30c46c19533d0ab562d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 14 Apr 2020 23:28:33 -0700 Subject: [PATCH] Generalize our two different kinds of declaration argument for attributes to support any kind of declaration. In preparation for adding a third kind. --- clang/include/clang/Basic/Attr.td | 14 ++++++-------- clang/utils/TableGen/ClangAttrEmitter.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index c586f9b..e22e906 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -174,12 +174,10 @@ class IdentifierArgument : Argument; class IntArgument : Argument; class StringArgument : Argument; class ExprArgument : Argument; -class FunctionArgument : Argument; -class NamedArgument : Argument; +class DeclArgument + : Argument { + DeclNode Kind = kind; +} // An argument of a OMPDeclareVariantAttr that represents the `match` // clause of the declare variant by keeping the information (incl. nesting) in @@ -956,7 +954,7 @@ def OSConsumesThis : InheritableAttr { def Cleanup : InheritableAttr { let Spellings = [GCC<"cleanup">]; - let Args = [FunctionArgument<"FunctionDecl">]; + let Args = [DeclArgument]; let Subjects = SubjectList<[LocalVar]>; let Documentation = [Undocumented]; } @@ -2382,7 +2380,7 @@ def DiagnoseIf : InheritableAttr { ["error", "warning"], ["DT_Error", "DT_Warning"]>, BoolArgument<"ArgDependent", 0, /*fake*/ 1>, - NamedArgument<"Parent", 0, /*fake*/ 1>]; + DeclArgument]; let InheritEvenIfAlreadyPresent = 1; let LateParsed = 1; let AdditionalMembers = [{ diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 486799e..ca3bebd5 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -339,7 +339,7 @@ namespace { } void writeDump(raw_ostream &OS) const override { - if (type == "FunctionDecl *" || type == "NamedDecl *") { + if (StringRef(type).endswith("Decl *")) { OS << " OS << \" \";\n"; OS << " dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; } else if (type == "IdentifierInfo *") { @@ -1290,10 +1290,9 @@ createArgument(const Record &Arg, StringRef Attr, Ptr = std::make_unique(Arg, Attr); else if (ArgName == "ExprArgument") Ptr = std::make_unique(Arg, Attr); - else if (ArgName == "FunctionArgument") - Ptr = std::make_unique(Arg, Attr, "FunctionDecl *"); - else if (ArgName == "NamedArgument") - Ptr = std::make_unique(Arg, Attr, "NamedDecl *"); + else if (ArgName == "DeclArgument") + Ptr = std::make_unique( + Arg, Attr, (Arg.getValueAsDef("Kind")->getName() + "Decl *").str()); else if (ArgName == "IdentifierArgument") Ptr = std::make_unique(Arg, Attr, "IdentifierInfo *"); else if (ArgName == "DefaultBoolArgument") -- 2.7.4