Index: clang/include/clang/Basic/Attributes.h =================================================================== --- clang/include/clang/Basic/Attributes.h +++ clang/include/clang/Basic/Attributes.h @@ -9,6 +9,7 @@ #ifndef LLVM_CLANG_BASIC_ATTRIBUTES_H #define LLVM_CLANG_BASIC_ATTRIBUTES_H +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/TargetInfo.h" @@ -16,28 +17,11 @@ class IdentifierInfo; -enum class AttrSyntax { - /// Is the identifier known as a GNU-style attribute? - GNU, - /// Is the identifier known as a __declspec-style attribute? - Declspec, - /// Is the identifier known as a [] Microsoft-style attribute? - Microsoft, - // Is the identifier known as a C++-style attribute? - CXX, - // Is the identifier known as a C-style attribute? - C, - // Is the identifier known as a pragma attribute? - Pragma, - // Is the identifier known as a HLSL semantic? - HLSLSemantic, -}; - /// Return the version number associated with the attribute if we /// recognize and implement the attribute specified by the given information. -int hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, - const IdentifierInfo *Attr, const TargetInfo &Target, - const LangOptions &LangOpts); +int hasAttribute(AttributeCommonInfo::Syntax Syntax, + const IdentifierInfo *Scope, const IdentifierInfo *Attr, + const TargetInfo &Target, const LangOptions &LangOpts); } // end namespace clang Index: clang/lib/Basic/Attributes.cpp =================================================================== --- clang/lib/Basic/Attributes.cpp +++ clang/lib/Basic/Attributes.cpp @@ -5,9 +5,9 @@ #include "llvm/ADT/StringSwitch.h" using namespace clang; -int clang::hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, - const IdentifierInfo *Attr, const TargetInfo &Target, - const LangOptions &LangOpts) { +int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax, + const IdentifierInfo *Scope, const IdentifierInfo *Attr, + const TargetInfo &Target, const LangOptions &LangOpts) { StringRef Name = Attr->getName(); // Normalize the attribute name, __foo__ becomes foo. if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__")) Index: clang/lib/Lex/PPMacroExpansion.cpp =================================================================== --- clang/lib/Lex/PPMacroExpansion.cpp +++ clang/lib/Lex/PPMacroExpansion.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/Attributes.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/FileManager.h" @@ -1689,8 +1690,9 @@ [this](Token &Tok, bool &HasLexedNextToken) -> int { IdentifierInfo *II = ExpectFeatureIdentifierInfo(Tok, *this, diag::err_feature_check_malformed); - return II ? hasAttribute(AttrSyntax::GNU, nullptr, II, - getTargetInfo(), getLangOpts()) : 0; + return II ? hasAttribute(AttributeCommonInfo::Syntax::AS_GNU, nullptr, + II, getTargetInfo(), getLangOpts()) + : 0; }); } else if (II == Ident__has_declspec) { EvaluateFeatureLikeBuiltinMacro(OS, Tok, II, *this, true, @@ -1700,8 +1702,8 @@ if (II) { const LangOptions &LangOpts = getLangOpts(); return LangOpts.DeclSpecKeyword && - hasAttribute(AttrSyntax::Declspec, nullptr, II, - getTargetInfo(), LangOpts); + hasAttribute(AttributeCommonInfo::Syntax::AS_Declspec, nullptr, + II, getTargetInfo(), LangOpts); } return false; @@ -1730,7 +1732,9 @@ diag::err_feature_check_malformed); } - AttrSyntax Syntax = IsCXX ? AttrSyntax::CXX : AttrSyntax::C; + AttributeCommonInfo::Syntax Syntax = + IsCXX ? AttributeCommonInfo::Syntax::AS_CXX11 + : AttributeCommonInfo::Syntax::AS_C2x; return II ? hasAttribute(Syntax, ScopeII, II, getTargetInfo(), getLangOpts()) : 0; Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -10,16 +10,17 @@ // //===----------------------------------------------------------------------===// -#include "clang/Parse/Parser.h" -#include "clang/Parse/RAIIObjectsForParser.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/PrettyDeclStackTrace.h" #include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/Attributes.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/TargetInfo.h" #include "clang/Parse/ParseDiagnostic.h" +#include "clang/Parse/Parser.h" +#include "clang/Parse/RAIIObjectsForParser.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" @@ -596,7 +597,7 @@ // If the attribute isn't known, we will not attempt to parse any // arguments. - if (!hasAttribute(AttrSyntax::Declspec, nullptr, AttrName, + if (!hasAttribute(AttributeCommonInfo::Syntax::AS_Declspec, nullptr, AttrName, getTargetInfo(), getLangOpts())) { // Eat the left paren, then skip to the ending right paren. ConsumeParen(); Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ clang/lib/Parse/ParseDeclCXX.cpp @@ -10,15 +10,16 @@ // //===----------------------------------------------------------------------===// -#include "clang/Parse/Parser.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/PrettyDeclStackTrace.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/Attributes.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/TargetInfo.h" #include "clang/Parse/ParseDiagnostic.h" +#include "clang/Parse/Parser.h" #include "clang/Parse/RAIIObjectsForParser.h" #include "clang/Sema/DeclSpec.h" #include "clang/Sema/ParsedTemplate.h" @@ -4308,16 +4309,17 @@ // Try parsing microsoft attributes if (getLangOpts().MicrosoftExt || getLangOpts().HLSL) { - if (hasAttribute(AttrSyntax::Microsoft, ScopeName, AttrName, - getTargetInfo(), getLangOpts())) + if (hasAttribute(AttributeCommonInfo::Syntax::AS_Microsoft, ScopeName, + AttrName, getTargetInfo(), getLangOpts())) Syntax = ParsedAttr::AS_Microsoft; } // If the attribute isn't known, we will not attempt to parse any // arguments. if (Syntax != ParsedAttr::AS_Microsoft && - !hasAttribute(LO.CPlusPlus ? AttrSyntax::CXX : AttrSyntax::C, ScopeName, - AttrName, getTargetInfo(), getLangOpts())) { + !hasAttribute(LO.CPlusPlus ? AttributeCommonInfo::Syntax::AS_CXX11 + : AttributeCommonInfo::Syntax::AS_C2x, + ScopeName, AttrName, getTargetInfo(), getLangOpts())) { if (getLangOpts().MicrosoftExt || getLangOpts().HLSL) {} // Eat the left paren, then skip to the ending right paren. ConsumeParen(); Index: clang/utils/TableGen/ClangAttrEmitter.cpp =================================================================== --- clang/utils/TableGen/ClangAttrEmitter.cpp +++ clang/utils/TableGen/ClangAttrEmitter.cpp @@ -3331,24 +3331,24 @@ OS << "const llvm::Triple &T = Target.getTriple();\n"; OS << "switch (Syntax) {\n"; - OS << "case AttrSyntax::GNU:\n"; + OS << "case AttributeCommonInfo::Syntax::AS_GNU:\n"; OS << " return llvm::StringSwitch(Name)\n"; GenerateHasAttrSpellingStringSwitch(GNU, OS, "GNU"); - OS << "case AttrSyntax::Declspec:\n"; + OS << "case AttributeCommonInfo::Syntax::AS_Declspec:\n"; OS << " return llvm::StringSwitch(Name)\n"; GenerateHasAttrSpellingStringSwitch(Declspec, OS, "Declspec"); - OS << "case AttrSyntax::Microsoft:\n"; + OS << "case AttributeCommonInfo::Syntax::AS_Microsoft:\n"; OS << " return llvm::StringSwitch(Name)\n"; GenerateHasAttrSpellingStringSwitch(Microsoft, OS, "Microsoft"); - OS << "case AttrSyntax::Pragma:\n"; + OS << "case AttributeCommonInfo::Syntax::AS_Pragma:\n"; OS << " return llvm::StringSwitch(Name)\n"; GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma"); - OS << "case AttrSyntax::HLSLSemantic:\n"; + OS << "case AttributeCommonInfo::Syntax::AS_HLSLSemantic:\n"; OS << " return llvm::StringSwitch(Name)\n"; GenerateHasAttrSpellingStringSwitch(HLSLSemantic, OS, "HLSLSemantic"); - auto fn = [&OS](const char *Spelling, const char *Variety, + auto fn = [&OS](const char *Spelling, const std::map> &List) { - OS << "case AttrSyntax::" << Variety << ": {\n"; + OS << "case AttributeCommonInfo::Syntax::AS_" << Spelling << ": {\n"; // C++11-style attributes are further split out based on the Scope. for (auto I = List.cbegin(), E = List.cend(); I != E; ++I) { if (I != List.cbegin()) @@ -3363,8 +3363,12 @@ } OS << "\n} break;\n"; }; - fn("CXX11", "CXX", CXX); - fn("C2x", "C", C2x); + fn("CXX11", CXX); + fn("C2x", C2x); + OS << "case AttributeCommonInfo::Syntax::AS_Keyword:\n"; + OS << "case AttributeCommonInfo::Syntax::AS_ContextSensitiveKeyword:\n"; + OS << " return 0;\n"; + OS << "}\n"; }