Skip to content

Commit ac5c996

Browse files
committed
[clang] Mark keywords that have their own parsing rules
This patch retroactively classifies all existing keyword attributes as “custom” keyword attributes, in the sense that the keywords have their own custom parsing rules. A follow-on patch will add an alternative type of keyword. No functional change intended. Differential Revision: https://reviews.llvm.org/D148699
1 parent 40c26ec commit ac5c996

File tree

1 file changed

+70
-57
lines changed

1 file changed

+70
-57
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 70 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,13 @@ class C2x<string namespace, string name, int version = 1>
311311
string Namespace = namespace;
312312
}
313313

314-
class Keyword<string name> : Spelling<name, "Keyword">;
314+
class Keyword<string name, bit hasOwnParseRules>
315+
: Spelling<name, "Keyword"> {
316+
bit HasOwnParseRules = hasOwnParseRules;
317+
}
318+
// A keyword that has its own individual parsing rules.
319+
class CustomKeyword<string name> : Keyword<name, 1> {}
320+
315321
class Pragma<string namespace, string name> : Spelling<name, "Pragma"> {
316322
string Namespace = namespace;
317323
}
@@ -709,13 +715,13 @@ def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr<TargetAnyArm> {
709715
}
710716

711717
def Aligned : InheritableAttr {
712-
let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
713-
Keyword<"_Alignas">];
718+
let Spellings = [GCC<"aligned">, Declspec<"align">, CustomKeyword<"alignas">,
719+
CustomKeyword<"_Alignas">];
714720
let Args = [AlignedArgument<"Alignment", 1>];
715721
let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
716-
Accessor<"isC11", [Keyword<"_Alignas">]>,
717-
Accessor<"isAlignas", [Keyword<"alignas">,
718-
Keyword<"_Alignas">]>,
722+
Accessor<"isC11", [CustomKeyword<"_Alignas">]>,
723+
Accessor<"isAlignas", [CustomKeyword<"alignas">,
724+
CustomKeyword<"_Alignas">]>,
719725
Accessor<"isDeclspec",[Declspec<"align">]>];
720726
let Documentation = [Undocumented];
721727
}
@@ -756,7 +762,7 @@ def AlignNatural : InheritableAttr {
756762

757763
def AlwaysInline : DeclOrStmtAttr {
758764
let Spellings = [GCC<"always_inline">, CXX11<"clang", "always_inline">,
759-
C2x<"clang", "always_inline">, Keyword<"__forceinline">];
765+
C2x<"clang", "always_inline">, CustomKeyword<"__forceinline">];
760766
let Accessors = [Accessor<"isClangAlwaysInline", [CXX11<"clang", "always_inline">,
761767
C2x<"clang", "always_inline">]>];
762768
let Subjects = SubjectList<[Function, Stmt], WarnDiag,
@@ -879,7 +885,7 @@ def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
879885
}
880886

881887
def AsmLabel : InheritableAttr {
882-
let Spellings = [Keyword<"asm">, Keyword<"__asm__">];
888+
let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm__">];
883889
let Args = [
884890
// Label specifies the mangled name for the decl.
885891
StringArgument<"Label">,
@@ -997,7 +1003,7 @@ def CarriesDependency : InheritableParamAttr {
9971003
}
9981004

9991005
def CDecl : DeclOrTypeAttr {
1000-
let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
1006+
let Spellings = [GCC<"cdecl">, CustomKeyword<"__cdecl">, CustomKeyword<"_cdecl">];
10011007
// let Subjects = [Function, ObjCMethod];
10021008
let Documentation = [Undocumented];
10031009
}
@@ -1122,10 +1128,10 @@ def Const : InheritableAttr {
11221128
def ConstInit : InheritableAttr {
11231129
// This attribute does not have a C [[]] spelling because it requires the
11241130
// CPlusPlus language option.
1125-
let Spellings = [Keyword<"constinit">,
1131+
let Spellings = [CustomKeyword<"constinit">,
11261132
Clang<"require_constant_initialization", 0>];
11271133
let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
1128-
let Accessors = [Accessor<"isConstinit", [Keyword<"constinit">]>];
1134+
let Accessors = [Accessor<"isConstinit", [CustomKeyword<"constinit">]>];
11291135
let Documentation = [ConstInitDocs];
11301136
let LangOpts = [CPlusPlus];
11311137
let SimpleHandler = 1;
@@ -1276,7 +1282,7 @@ def SYCLSpecialClass: InheritableAttr {
12761282
}
12771283

12781284
def C11NoReturn : InheritableAttr {
1279-
let Spellings = [Keyword<"_Noreturn">];
1285+
let Spellings = [CustomKeyword<"_Noreturn">];
12801286
let Subjects = SubjectList<[Function], ErrorDiag>;
12811287
let SemaHandler = 0;
12821288
let Documentation = [C11NoReturnDocs];
@@ -1292,7 +1298,7 @@ def CXX11NoReturn : InheritableAttr {
12921298
// Similar to CUDA, OpenCL attributes do not receive a [[]] spelling because
12931299
// the specification does not expose them with one currently.
12941300
def OpenCLKernel : InheritableAttr {
1295-
let Spellings = [Keyword<"__kernel">, Keyword<"kernel">];
1301+
let Spellings = [CustomKeyword<"__kernel">, CustomKeyword<"kernel">];
12961302
let Subjects = SubjectList<[Function], ErrorDiag>;
12971303
let Documentation = [Undocumented];
12981304
let SimpleHandler = 1;
@@ -1316,26 +1322,28 @@ def OpenCLIntelReqdSubGroupSize: InheritableAttr {
13161322
// This attribute is both a type attribute, and a declaration attribute (for
13171323
// parameter variables).
13181324
def OpenCLAccess : Attr {
1319-
let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
1320-
Keyword<"__write_only">, Keyword<"write_only">,
1321-
Keyword<"__read_write">, Keyword<"read_write">];
1325+
let Spellings = [CustomKeyword<"__read_only">, CustomKeyword<"read_only">,
1326+
CustomKeyword<"__write_only">, CustomKeyword<"write_only">,
1327+
CustomKeyword<"__read_write">, CustomKeyword<"read_write">];
13221328
let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag>;
1323-
let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
1324-
Keyword<"read_only">]>,
1325-
Accessor<"isReadWrite", [Keyword<"__read_write">,
1326-
Keyword<"read_write">]>,
1327-
Accessor<"isWriteOnly", [Keyword<"__write_only">,
1328-
Keyword<"write_only">]>];
1329+
let Accessors = [Accessor<"isReadOnly", [CustomKeyword<"__read_only">,
1330+
CustomKeyword<"read_only">]>,
1331+
Accessor<"isReadWrite", [CustomKeyword<"__read_write">,
1332+
CustomKeyword<"read_write">]>,
1333+
Accessor<"isWriteOnly", [CustomKeyword<"__write_only">,
1334+
CustomKeyword<"write_only">]>];
13291335
let Documentation = [OpenCLAccessDocs];
13301336
}
13311337

13321338
def OpenCLPrivateAddressSpace : TypeAttr {
1333-
let Spellings = [Keyword<"__private">, Keyword<"private">, Clang<"opencl_private">];
1339+
let Spellings = [CustomKeyword<"__private">, CustomKeyword<"private">,
1340+
Clang<"opencl_private">];
13341341
let Documentation = [OpenCLAddressSpacePrivateDocs];
13351342
}
13361343

13371344
def OpenCLGlobalAddressSpace : TypeAttr {
1338-
let Spellings = [Keyword<"__global">, Keyword<"global">, Clang<"opencl_global">];
1345+
let Spellings = [CustomKeyword<"__global">, CustomKeyword<"global">,
1346+
Clang<"opencl_global">];
13391347
let Documentation = [OpenCLAddressSpaceGlobalDocs];
13401348
}
13411349

@@ -1350,17 +1358,20 @@ def OpenCLGlobalHostAddressSpace : TypeAttr {
13501358
}
13511359

13521360
def OpenCLLocalAddressSpace : TypeAttr {
1353-
let Spellings = [Keyword<"__local">, Keyword<"local">, Clang<"opencl_local">];
1361+
let Spellings = [CustomKeyword<"__local">, CustomKeyword<"local">,
1362+
Clang<"opencl_local">];
13541363
let Documentation = [OpenCLAddressSpaceLocalDocs];
13551364
}
13561365

13571366
def OpenCLConstantAddressSpace : TypeAttr {
1358-
let Spellings = [Keyword<"__constant">, Keyword<"constant">, Clang<"opencl_constant">];
1367+
let Spellings = [CustomKeyword<"__constant">, CustomKeyword<"constant">,
1368+
Clang<"opencl_constant">];
13591369
let Documentation = [OpenCLAddressSpaceConstantDocs];
13601370
}
13611371

13621372
def OpenCLGenericAddressSpace : TypeAttr {
1363-
let Spellings = [Keyword<"__generic">, Keyword<"generic">, Clang<"opencl_generic">];
1373+
let Spellings = [CustomKeyword<"__generic">, CustomKeyword<"generic">,
1374+
Clang<"opencl_generic">];
13641375
let Documentation = [OpenCLAddressSpaceGenericDocs];
13651376
}
13661377

@@ -1476,20 +1487,20 @@ def MustTail : StmtAttr {
14761487
}
14771488

14781489
def FastCall : DeclOrTypeAttr {
1479-
let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
1480-
Keyword<"_fastcall">];
1490+
let Spellings = [GCC<"fastcall">, CustomKeyword<"__fastcall">,
1491+
CustomKeyword<"_fastcall">];
14811492
// let Subjects = [Function, ObjCMethod];
14821493
let Documentation = [FastCallDocs];
14831494
}
14841495

14851496
def RegCall : DeclOrTypeAttr {
1486-
let Spellings = [GCC<"regcall">, Keyword<"__regcall">];
1497+
let Spellings = [GCC<"regcall">, CustomKeyword<"__regcall">];
14871498
let Documentation = [RegCallDocs];
14881499
}
14891500

14901501
def Final : InheritableAttr {
1491-
let Spellings = [Keyword<"final">, Keyword<"sealed">];
1492-
let Accessors = [Accessor<"isSpelledAsSealed", [Keyword<"sealed">]>];
1502+
let Spellings = [CustomKeyword<"final">, CustomKeyword<"sealed">];
1503+
let Accessors = [Accessor<"isSpelledAsSealed", [CustomKeyword<"sealed">]>];
14931504
let SemaHandler = 0;
14941505
// Omitted from docs, since this is language syntax, not an attribute, as far
14951506
// as users are concerned.
@@ -1835,7 +1846,7 @@ def Convergent : InheritableAttr {
18351846
}
18361847

18371848
def NoInline : DeclOrStmtAttr {
1838-
let Spellings = [Keyword<"__noinline__">, GCC<"noinline">,
1849+
let Spellings = [CustomKeyword<"__noinline__">, GCC<"noinline">,
18391850
CXX11<"clang", "noinline">, C2x<"clang", "noinline">,
18401851
Declspec<"noinline">];
18411852
let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
@@ -2031,35 +2042,35 @@ def PassObjectSize : InheritableParamAttr {
20312042

20322043
// Nullability type attributes.
20332044
def TypeNonNull : TypeAttr {
2034-
let Spellings = [Keyword<"_Nonnull">];
2045+
let Spellings = [CustomKeyword<"_Nonnull">];
20352046
let Documentation = [TypeNonNullDocs];
20362047
}
20372048

20382049
def TypeNullable : TypeAttr {
2039-
let Spellings = [Keyword<"_Nullable">];
2050+
let Spellings = [CustomKeyword<"_Nullable">];
20402051
let Documentation = [TypeNullableDocs];
20412052
}
20422053

20432054
def TypeNullableResult : TypeAttr {
2044-
let Spellings = [Keyword<"_Nullable_result">];
2055+
let Spellings = [CustomKeyword<"_Nullable_result">];
20452056
let Documentation = [TypeNullableResultDocs];
20462057
}
20472058

20482059
def TypeNullUnspecified : TypeAttr {
2049-
let Spellings = [Keyword<"_Null_unspecified">];
2060+
let Spellings = [CustomKeyword<"_Null_unspecified">];
20502061
let Documentation = [TypeNullUnspecifiedDocs];
20512062
}
20522063

20532064
// This is a marker used to indicate that an __unsafe_unretained qualifier was
20542065
// ignored because ARC is not enabled. The usual representation for this
20552066
// qualifier is as an ObjCOwnership attribute with Kind == "none".
20562067
def ObjCInertUnsafeUnretained : TypeAttr {
2057-
let Spellings = [Keyword<"__unsafe_unretained">];
2068+
let Spellings = [CustomKeyword<"__unsafe_unretained">];
20582069
let Documentation = [InternalOnly];
20592070
}
20602071

20612072
def ObjCKindOf : TypeAttr {
2062-
let Spellings = [Keyword<"__kindof">];
2073+
let Spellings = [CustomKeyword<"__kindof">];
20632074
let Documentation = [Undocumented];
20642075
}
20652076

@@ -2358,7 +2369,7 @@ def Overloadable : Attr {
23582369
}
23592370

23602371
def Override : InheritableAttr {
2361-
let Spellings = [Keyword<"override">];
2372+
let Spellings = [CustomKeyword<"override">];
23622373
let SemaHandler = 0;
23632374
// Omitted from docs, since this is language syntax, not an attribute, as far
23642375
// as users are concerned.
@@ -2603,7 +2614,8 @@ def Sentinel : InheritableAttr {
26032614
}
26042615

26052616
def StdCall : DeclOrTypeAttr {
2606-
let Spellings = [GCC<"stdcall">, Keyword<"__stdcall">, Keyword<"_stdcall">];
2617+
let Spellings = [GCC<"stdcall">, CustomKeyword<"__stdcall">,
2618+
CustomKeyword<"_stdcall">];
26072619
// let Subjects = [Function, ObjCMethod];
26082620
let Documentation = [StdCallDocs];
26092621
}
@@ -2672,15 +2684,15 @@ def SysVABI : DeclOrTypeAttr {
26722684
}
26732685

26742686
def ThisCall : DeclOrTypeAttr {
2675-
let Spellings = [GCC<"thiscall">, Keyword<"__thiscall">,
2676-
Keyword<"_thiscall">];
2687+
let Spellings = [GCC<"thiscall">, CustomKeyword<"__thiscall">,
2688+
CustomKeyword<"_thiscall">];
26772689
// let Subjects = [Function, ObjCMethod];
26782690
let Documentation = [ThisCallDocs];
26792691
}
26802692

26812693
def VectorCall : DeclOrTypeAttr {
2682-
let Spellings = [Clang<"vectorcall">, Keyword<"__vectorcall">,
2683-
Keyword<"_vectorcall">];
2694+
let Spellings = [Clang<"vectorcall">, CustomKeyword<"__vectorcall">,
2695+
CustomKeyword<"_vectorcall">];
26842696
// let Subjects = [Function, ObjCMethod];
26852697
let Documentation = [VectorCallDocs];
26862698
}
@@ -2699,7 +2711,8 @@ def ZeroCallUsedRegs : InheritableAttr {
26992711
}
27002712

27012713
def Pascal : DeclOrTypeAttr {
2702-
let Spellings = [Clang<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
2714+
let Spellings = [Clang<"pascal">, CustomKeyword<"__pascal">,
2715+
CustomKeyword<"_pascal">];
27032716
// let Subjects = [Function, ObjCMethod];
27042717
let Documentation = [Undocumented];
27052718
}
@@ -3596,37 +3609,37 @@ def Thread : Attr {
35963609
}
35973610

35983611
def Win64 : IgnoredAttr {
3599-
let Spellings = [Keyword<"__w64">];
3612+
let Spellings = [CustomKeyword<"__w64">];
36003613
let LangOpts = [MicrosoftExt];
36013614
}
36023615

36033616
def Ptr32 : TypeAttr {
3604-
let Spellings = [Keyword<"__ptr32">];
3617+
let Spellings = [CustomKeyword<"__ptr32">];
36053618
let Documentation = [Ptr32Docs];
36063619
}
36073620

36083621
def Ptr64 : TypeAttr {
3609-
let Spellings = [Keyword<"__ptr64">];
3622+
let Spellings = [CustomKeyword<"__ptr64">];
36103623
let Documentation = [Ptr64Docs];
36113624
}
36123625

36133626
def SPtr : TypeAttr {
3614-
let Spellings = [Keyword<"__sptr">];
3627+
let Spellings = [CustomKeyword<"__sptr">];
36153628
let Documentation = [SPtrDocs];
36163629
}
36173630

36183631
def UPtr : TypeAttr {
3619-
let Spellings = [Keyword<"__uptr">];
3632+
let Spellings = [CustomKeyword<"__uptr">];
36203633
let Documentation = [UPtrDocs];
36213634
}
36223635

36233636
def MSInheritance : InheritableAttr {
36243637
let LangOpts = [MicrosoftExt];
36253638
let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
3626-
let Spellings = [Keyword<"__single_inheritance">,
3627-
Keyword<"__multiple_inheritance">,
3628-
Keyword<"__virtual_inheritance">,
3629-
Keyword<"__unspecified_inheritance">];
3639+
let Spellings = [CustomKeyword<"__single_inheritance">,
3640+
CustomKeyword<"__multiple_inheritance">,
3641+
CustomKeyword<"__virtual_inheritance">,
3642+
CustomKeyword<"__unspecified_inheritance">];
36303643
let AdditionalMembers = [{
36313644
MSInheritanceModel getInheritanceModel() const {
36323645
// The spelling enum should agree with MSInheritanceModel.
@@ -4126,7 +4139,7 @@ def HLSLResource : InheritableAttr {
41264139
}
41274140

41284141
def HLSLGroupSharedAddressSpace : TypeAttr {
4129-
let Spellings = [Keyword<"groupshared">];
4142+
let Spellings = [CustomKeyword<"groupshared">];
41304143
let Subjects = SubjectList<[Var]>;
41314144
let Documentation = [HLSLGroupSharedAddressSpaceDocs];
41324145
}
@@ -4158,7 +4171,7 @@ def FunctionReturnThunks : InheritableAttr,
41584171
}
41594172

41604173
def WebAssemblyFuncref : TypeAttr, TargetSpecificAttr<TargetWebAssembly> {
4161-
let Spellings = [Keyword<"__funcref">];
4174+
let Spellings = [CustomKeyword<"__funcref">];
41624175
let Documentation = [WebAssemblyExportNameDocs];
41634176
let Subjects = SubjectList<[FunctionPointer], ErrorDiag>;
41644177
}

0 commit comments

Comments
 (0)