Skip to content

Commit 23c3c4e

Browse files
committed
[clang][NFC] Convert Parser::ObjCTypeQual to scoped enum
1 parent 44d8aa8 commit 23c3c4e

File tree

3 files changed

+66
-33
lines changed

3 files changed

+66
-33
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "clang/Sema/SemaCodeCompletion.h"
2222
#include "clang/Sema/SemaObjC.h"
2323
#include "clang/Sema/SemaOpenMP.h"
24+
#include "llvm/ADT/STLForwardCompat.h"
2425
#include "llvm/ADT/SmallVector.h"
2526
#include "llvm/Frontend/OpenMP/OMPContext.h"
2627
#include "llvm/Support/SaveAndRestore.h"
@@ -86,6 +87,20 @@ enum class ParsedTemplateKind {
8687

8788
enum class CachedInitKind { DefaultArgument, DefaultInitializer };
8889

90+
// Definitions for Objective-c context sensitive keywords recognition.
91+
enum class ObjCTypeQual {
92+
in = 0,
93+
out,
94+
inout,
95+
oneway,
96+
bycopy,
97+
byref,
98+
nonnull,
99+
nullable,
100+
null_unspecified,
101+
NumQuals
102+
};
103+
89104
/// Parser - This implements a parser for the C family of languages. After
90105
/// parsing units of the grammar, productions are invoked to handle whatever has
91106
/// been read.
@@ -1818,13 +1833,8 @@ class Parser : public CodeCompletionHandler {
18181833
Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
18191834

18201835
IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1821-
// Definitions for Objective-c context sensitive keywords recognition.
1822-
enum ObjCTypeQual {
1823-
objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1824-
objc_nonnull, objc_nullable, objc_null_unspecified,
1825-
objc_NumQuals
1826-
};
1827-
IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1836+
1837+
IdentifierInfo *ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::NumQuals)];
18281838

18291839
bool isTokIdentifier_in() const;
18301840

clang/lib/Parse/ParseObjc.cpp

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "clang/Sema/Scope.h"
2424
#include "clang/Sema/SemaCodeCompletion.h"
2525
#include "clang/Sema/SemaObjC.h"
26+
#include "llvm/ADT/STLForwardCompat.h"
2627
#include "llvm/ADT/SmallVector.h"
2728
#include "llvm/ADT/StringExtras.h"
2829

@@ -1176,7 +1177,8 @@ bool Parser::isTokIdentifier_in() const {
11761177
// valid tokens following an 'in'; such as an identifier, unary operators,
11771178
// '[' etc.
11781179
return (getLangOpts().ObjC && Tok.is(tok::identifier) &&
1179-
Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
1180+
Tok.getIdentifierInfo() ==
1181+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::in)]);
11801182
}
11811183

11821184
/// ParseObjCTypeQualifierList - This routine parses the objective-c's type
@@ -1215,34 +1217,47 @@ void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
12151217
return;
12161218

12171219
const IdentifierInfo *II = Tok.getIdentifierInfo();
1218-
for (unsigned i = 0; i != objc_NumQuals; ++i) {
1219-
if (II != ObjCTypeQuals[i] ||
1220-
NextToken().is(tok::less) ||
1221-
NextToken().is(tok::coloncolon))
1220+
for (unsigned i = 0; i != llvm::to_underlying(ObjCTypeQual::NumQuals);
1221+
++i) {
1222+
ObjCTypeQual TQ = static_cast<ObjCTypeQual>(i);
1223+
if (II != ObjCTypeQuals[llvm::to_underlying(TQ)] ||
1224+
NextToken().is(tok::less) || NextToken().is(tok::coloncolon))
12221225
continue;
12231226

12241227
ObjCDeclSpec::ObjCDeclQualifier Qual;
12251228
NullabilityKind Nullability;
1226-
switch (i) {
1229+
switch (TQ) {
12271230
default: llvm_unreachable("Unknown decl qualifier");
1228-
case objc_in: Qual = ObjCDeclSpec::DQ_In; break;
1229-
case objc_out: Qual = ObjCDeclSpec::DQ_Out; break;
1230-
case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break;
1231-
case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break;
1232-
case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break;
1233-
case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break;
1234-
1235-
case objc_nonnull:
1231+
case ObjCTypeQual::in:
1232+
Qual = ObjCDeclSpec::DQ_In;
1233+
break;
1234+
case ObjCTypeQual::out:
1235+
Qual = ObjCDeclSpec::DQ_Out;
1236+
break;
1237+
case ObjCTypeQual::inout:
1238+
Qual = ObjCDeclSpec::DQ_Inout;
1239+
break;
1240+
case ObjCTypeQual::oneway:
1241+
Qual = ObjCDeclSpec::DQ_Oneway;
1242+
break;
1243+
case ObjCTypeQual::bycopy:
1244+
Qual = ObjCDeclSpec::DQ_Bycopy;
1245+
break;
1246+
case ObjCTypeQual::byref:
1247+
Qual = ObjCDeclSpec::DQ_Byref;
1248+
break;
1249+
1250+
case ObjCTypeQual::nonnull:
12361251
Qual = ObjCDeclSpec::DQ_CSNullability;
12371252
Nullability = NullabilityKind::NonNull;
12381253
break;
12391254

1240-
case objc_nullable:
1255+
case ObjCTypeQual::nullable:
12411256
Qual = ObjCDeclSpec::DQ_CSNullability;
12421257
Nullability = NullabilityKind::Nullable;
12431258
break;
12441259

1245-
case objc_null_unspecified:
1260+
case ObjCTypeQual::null_unspecified:
12461261
Qual = ObjCDeclSpec::DQ_CSNullability;
12471262
Nullability = NullabilityKind::Unspecified;
12481263
break;

clang/lib/Parse/Parser.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,24 @@ void Parser::Initialize() {
512512
// Initialization for Objective-C context sensitive keywords recognition.
513513
// Referenced in Parser::ParseObjCTypeQualifierList.
514514
if (getLangOpts().ObjC) {
515-
ObjCTypeQuals[objc_in] = &PP.getIdentifierTable().get("in");
516-
ObjCTypeQuals[objc_out] = &PP.getIdentifierTable().get("out");
517-
ObjCTypeQuals[objc_inout] = &PP.getIdentifierTable().get("inout");
518-
ObjCTypeQuals[objc_oneway] = &PP.getIdentifierTable().get("oneway");
519-
ObjCTypeQuals[objc_bycopy] = &PP.getIdentifierTable().get("bycopy");
520-
ObjCTypeQuals[objc_byref] = &PP.getIdentifierTable().get("byref");
521-
ObjCTypeQuals[objc_nonnull] = &PP.getIdentifierTable().get("nonnull");
522-
ObjCTypeQuals[objc_nullable] = &PP.getIdentifierTable().get("nullable");
523-
ObjCTypeQuals[objc_null_unspecified]
524-
= &PP.getIdentifierTable().get("null_unspecified");
515+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::in)] =
516+
&PP.getIdentifierTable().get("in");
517+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::out)] =
518+
&PP.getIdentifierTable().get("out");
519+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::inout)] =
520+
&PP.getIdentifierTable().get("inout");
521+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::oneway)] =
522+
&PP.getIdentifierTable().get("oneway");
523+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::bycopy)] =
524+
&PP.getIdentifierTable().get("bycopy");
525+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::byref)] =
526+
&PP.getIdentifierTable().get("byref");
527+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::nonnull)] =
528+
&PP.getIdentifierTable().get("nonnull");
529+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::nullable)] =
530+
&PP.getIdentifierTable().get("nullable");
531+
ObjCTypeQuals[llvm::to_underlying(ObjCTypeQual::null_unspecified)] =
532+
&PP.getIdentifierTable().get("null_unspecified");
525533
}
526534

527535
Ident_instancetype = nullptr;

0 commit comments

Comments
 (0)