Skip to content

Commit dd6bcdb

Browse files
[Attributes] Remove AttrSyntax and migrate uses to AttributeCommonInfo::Syntax (NFC)
This is setup for allowing hasAttribute to work for plugin-provided attributes Differential Revision: https://reviews.llvm.org/D126902
1 parent 5904836 commit dd6bcdb

File tree

6 files changed

+41
-45
lines changed

6 files changed

+41
-45
lines changed

Diff for: clang/include/clang/Basic/Attributes.h

+4-20
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,19 @@
99
#ifndef LLVM_CLANG_BASIC_ATTRIBUTES_H
1010
#define LLVM_CLANG_BASIC_ATTRIBUTES_H
1111

12+
#include "clang/Basic/AttributeCommonInfo.h"
1213
#include "clang/Basic/LangOptions.h"
1314
#include "clang/Basic/TargetInfo.h"
1415

1516
namespace clang {
1617

1718
class IdentifierInfo;
1819

19-
enum class AttrSyntax {
20-
/// Is the identifier known as a GNU-style attribute?
21-
GNU,
22-
/// Is the identifier known as a __declspec-style attribute?
23-
Declspec,
24-
/// Is the identifier known as a [] Microsoft-style attribute?
25-
Microsoft,
26-
// Is the identifier known as a C++-style attribute?
27-
CXX,
28-
// Is the identifier known as a C-style attribute?
29-
C,
30-
// Is the identifier known as a pragma attribute?
31-
Pragma,
32-
// Is the identifier known as a HLSL semantic?
33-
HLSLSemantic,
34-
};
35-
3620
/// Return the version number associated with the attribute if we
3721
/// recognize and implement the attribute specified by the given information.
38-
int hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope,
39-
const IdentifierInfo *Attr, const TargetInfo &Target,
40-
const LangOptions &LangOpts);
22+
int hasAttribute(AttributeCommonInfo::Syntax Syntax,
23+
const IdentifierInfo *Scope, const IdentifierInfo *Attr,
24+
const TargetInfo &Target, const LangOptions &LangOpts);
4125

4226
} // end namespace clang
4327

Diff for: clang/lib/Basic/Attributes.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include "llvm/ADT/StringSwitch.h"
66
using namespace clang;
77

8-
int clang::hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope,
9-
const IdentifierInfo *Attr, const TargetInfo &Target,
10-
const LangOptions &LangOpts) {
8+
int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax,
9+
const IdentifierInfo *Scope, const IdentifierInfo *Attr,
10+
const TargetInfo &Target, const LangOptions &LangOpts) {
1111
StringRef Name = Attr->getName();
1212
// Normalize the attribute name, __foo__ becomes foo.
1313
if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__"))

Diff for: clang/lib/Lex/PPMacroExpansion.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "clang/Basic/AttributeCommonInfo.h"
1415
#include "clang/Basic/Attributes.h"
1516
#include "clang/Basic/Builtins.h"
1617
#include "clang/Basic/FileManager.h"
@@ -1689,8 +1690,9 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
16891690
[this](Token &Tok, bool &HasLexedNextToken) -> int {
16901691
IdentifierInfo *II = ExpectFeatureIdentifierInfo(Tok, *this,
16911692
diag::err_feature_check_malformed);
1692-
return II ? hasAttribute(AttrSyntax::GNU, nullptr, II,
1693-
getTargetInfo(), getLangOpts()) : 0;
1693+
return II ? hasAttribute(AttributeCommonInfo::Syntax::AS_GNU, nullptr,
1694+
II, getTargetInfo(), getLangOpts())
1695+
: 0;
16941696
});
16951697
} else if (II == Ident__has_declspec) {
16961698
EvaluateFeatureLikeBuiltinMacro(OS, Tok, II, *this, true,
@@ -1700,8 +1702,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
17001702
if (II) {
17011703
const LangOptions &LangOpts = getLangOpts();
17021704
return LangOpts.DeclSpecKeyword &&
1703-
hasAttribute(AttrSyntax::Declspec, nullptr, II,
1704-
getTargetInfo(), LangOpts);
1705+
hasAttribute(AttributeCommonInfo::Syntax::AS_Declspec, nullptr,
1706+
II, getTargetInfo(), LangOpts);
17051707
}
17061708

17071709
return false;
@@ -1730,7 +1732,9 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
17301732
diag::err_feature_check_malformed);
17311733
}
17321734

1733-
AttrSyntax Syntax = IsCXX ? AttrSyntax::CXX : AttrSyntax::C;
1735+
AttributeCommonInfo::Syntax Syntax =
1736+
IsCXX ? AttributeCommonInfo::Syntax::AS_CXX11
1737+
: AttributeCommonInfo::Syntax::AS_C2x;
17341738
return II ? hasAttribute(Syntax, ScopeII, II, getTargetInfo(),
17351739
getLangOpts())
17361740
: 0;

Diff for: clang/lib/Parse/ParseDecl.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "clang/Parse/Parser.h"
14-
#include "clang/Parse/RAIIObjectsForParser.h"
1513
#include "clang/AST/ASTContext.h"
1614
#include "clang/AST/DeclTemplate.h"
1715
#include "clang/AST/PrettyDeclStackTrace.h"
1816
#include "clang/Basic/AddressSpaces.h"
17+
#include "clang/Basic/AttributeCommonInfo.h"
1918
#include "clang/Basic/Attributes.h"
2019
#include "clang/Basic/CharInfo.h"
2120
#include "clang/Basic/TargetInfo.h"
2221
#include "clang/Parse/ParseDiagnostic.h"
22+
#include "clang/Parse/Parser.h"
23+
#include "clang/Parse/RAIIObjectsForParser.h"
2324
#include "clang/Sema/Lookup.h"
2425
#include "clang/Sema/ParsedTemplate.h"
2526
#include "clang/Sema/Scope.h"
@@ -596,7 +597,7 @@ bool Parser::ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
596597

597598
// If the attribute isn't known, we will not attempt to parse any
598599
// arguments.
599-
if (!hasAttribute(AttrSyntax::Declspec, nullptr, AttrName,
600+
if (!hasAttribute(AttributeCommonInfo::Syntax::AS_Declspec, nullptr, AttrName,
600601
getTargetInfo(), getLangOpts())) {
601602
// Eat the left paren, then skip to the ending right paren.
602603
ConsumeParen();

Diff for: clang/lib/Parse/ParseDeclCXX.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "clang/Parse/Parser.h"
1413
#include "clang/AST/ASTContext.h"
1514
#include "clang/AST/DeclTemplate.h"
1615
#include "clang/AST/PrettyDeclStackTrace.h"
16+
#include "clang/Basic/AttributeCommonInfo.h"
1717
#include "clang/Basic/Attributes.h"
1818
#include "clang/Basic/CharInfo.h"
1919
#include "clang/Basic/OperatorKinds.h"
2020
#include "clang/Basic/TargetInfo.h"
2121
#include "clang/Parse/ParseDiagnostic.h"
22+
#include "clang/Parse/Parser.h"
2223
#include "clang/Parse/RAIIObjectsForParser.h"
2324
#include "clang/Sema/DeclSpec.h"
2425
#include "clang/Sema/ParsedTemplate.h"
@@ -4308,16 +4309,17 @@ bool Parser::ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
43084309

43094310
// Try parsing microsoft attributes
43104311
if (getLangOpts().MicrosoftExt || getLangOpts().HLSL) {
4311-
if (hasAttribute(AttrSyntax::Microsoft, ScopeName, AttrName,
4312-
getTargetInfo(), getLangOpts()))
4312+
if (hasAttribute(AttributeCommonInfo::Syntax::AS_Microsoft, ScopeName,
4313+
AttrName, getTargetInfo(), getLangOpts()))
43134314
Syntax = ParsedAttr::AS_Microsoft;
43144315
}
43154316

43164317
// If the attribute isn't known, we will not attempt to parse any
43174318
// arguments.
43184319
if (Syntax != ParsedAttr::AS_Microsoft &&
4319-
!hasAttribute(LO.CPlusPlus ? AttrSyntax::CXX : AttrSyntax::C, ScopeName,
4320-
AttrName, getTargetInfo(), getLangOpts())) {
4320+
!hasAttribute(LO.CPlusPlus ? AttributeCommonInfo::Syntax::AS_CXX11
4321+
: AttributeCommonInfo::Syntax::AS_C2x,
4322+
ScopeName, AttrName, getTargetInfo(), getLangOpts())) {
43214323
if (getLangOpts().MicrosoftExt || getLangOpts().HLSL) {}
43224324
// Eat the left paren, then skip to the ending right paren.
43234325
ConsumeParen();

Diff for: clang/utils/TableGen/ClangAttrEmitter.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -3331,24 +3331,24 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
33313331

33323332
OS << "const llvm::Triple &T = Target.getTriple();\n";
33333333
OS << "switch (Syntax) {\n";
3334-
OS << "case AttrSyntax::GNU:\n";
3334+
OS << "case AttributeCommonInfo::Syntax::AS_GNU:\n";
33353335
OS << " return llvm::StringSwitch<int>(Name)\n";
33363336
GenerateHasAttrSpellingStringSwitch(GNU, OS, "GNU");
3337-
OS << "case AttrSyntax::Declspec:\n";
3337+
OS << "case AttributeCommonInfo::Syntax::AS_Declspec:\n";
33383338
OS << " return llvm::StringSwitch<int>(Name)\n";
33393339
GenerateHasAttrSpellingStringSwitch(Declspec, OS, "Declspec");
3340-
OS << "case AttrSyntax::Microsoft:\n";
3340+
OS << "case AttributeCommonInfo::Syntax::AS_Microsoft:\n";
33413341
OS << " return llvm::StringSwitch<int>(Name)\n";
33423342
GenerateHasAttrSpellingStringSwitch(Microsoft, OS, "Microsoft");
3343-
OS << "case AttrSyntax::Pragma:\n";
3343+
OS << "case AttributeCommonInfo::Syntax::AS_Pragma:\n";
33443344
OS << " return llvm::StringSwitch<int>(Name)\n";
33453345
GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
3346-
OS << "case AttrSyntax::HLSLSemantic:\n";
3346+
OS << "case AttributeCommonInfo::Syntax::AS_HLSLSemantic:\n";
33473347
OS << " return llvm::StringSwitch<int>(Name)\n";
33483348
GenerateHasAttrSpellingStringSwitch(HLSLSemantic, OS, "HLSLSemantic");
3349-
auto fn = [&OS](const char *Spelling, const char *Variety,
3349+
auto fn = [&OS](const char *Spelling,
33503350
const std::map<std::string, std::vector<Record *>> &List) {
3351-
OS << "case AttrSyntax::" << Variety << ": {\n";
3351+
OS << "case AttributeCommonInfo::Syntax::AS_" << Spelling << ": {\n";
33523352
// C++11-style attributes are further split out based on the Scope.
33533353
for (auto I = List.cbegin(), E = List.cend(); I != E; ++I) {
33543354
if (I != List.cbegin())
@@ -3363,8 +3363,13 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
33633363
}
33643364
OS << "\n} break;\n";
33653365
};
3366-
fn("CXX11", "CXX", CXX);
3367-
fn("C2x", "C", C2x);
3366+
fn("CXX11", CXX);
3367+
fn("C2x", C2x);
3368+
OS << "case AttributeCommonInfo::Syntax::AS_Keyword:\n";
3369+
OS << "case AttributeCommonInfo::Syntax::AS_ContextSensitiveKeyword:\n";
3370+
OS << " llvm_unreachable(\"hasAttribute not supported for keyword\");\n";
3371+
OS << " return 0;\n";
3372+
33683373
OS << "}\n";
33693374
}
33703375

0 commit comments

Comments
 (0)