Skip to content

Commit 21444e3

Browse files
committed
[clang][NFC] Convert Sema::PragmaMsStackAction to scoped enum
1 parent 6f6af49 commit 21444e3

File tree

4 files changed

+101
-91
lines changed

4 files changed

+101
-91
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ enum class PragmaClangSectionKind {
475475

476476
enum class PragmaClangSectionAction { Set = 0, Clear = 1 };
477477

478+
enum PragmaMsStackAction {
479+
Reset = 0x0, // #pragma ()
480+
Set = 0x1, // #pragma (value)
481+
Push = 0x2, // #pragma (push[, id])
482+
Pop = 0x4, // #pragma (pop[, id])
483+
Show = 0x8, // #pragma (show) -- only for "pack"!
484+
PushSet = Push | Set, // #pragma (push[, id], value)
485+
PopSet = Pop | Set, // #pragma (pop[, id], value)
486+
};
487+
478488
/// Sema - This implements semantic analysis and AST building for C.
479489
/// \nosubgrouping
480490
class Sema final : public SemaBase {
@@ -1436,16 +1446,6 @@ class Sema final : public SemaBase {
14361446
PragmaClangSection PragmaClangRelroSection;
14371447
PragmaClangSection PragmaClangTextSection;
14381448

1439-
enum PragmaMsStackAction {
1440-
PSK_Reset = 0x0, // #pragma ()
1441-
PSK_Set = 0x1, // #pragma (value)
1442-
PSK_Push = 0x2, // #pragma (push[, id])
1443-
PSK_Pop = 0x4, // #pragma (pop[, id])
1444-
PSK_Show = 0x8, // #pragma (show) -- only for "pack"!
1445-
PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value)
1446-
PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value)
1447-
};
1448-
14491449
struct PragmaPackInfo {
14501450
PragmaMsStackAction Action;
14511451
StringRef SlotLabel;
@@ -1569,15 +1569,15 @@ class Sema final : public SemaBase {
15691569

15701570
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action,
15711571
llvm::StringRef StackSlotLabel, ValueType Value) {
1572-
if (Action == PSK_Reset) {
1572+
if (Action == PragmaMsStackAction::Reset) {
15731573
CurrentValue = DefaultValue;
15741574
CurrentPragmaLocation = PragmaLocation;
15751575
return;
15761576
}
1577-
if (Action & PSK_Push)
1577+
if (Action & PragmaMsStackAction::Push)
15781578
Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
15791579
PragmaLocation);
1580-
else if (Action & PSK_Pop) {
1580+
else if (Action & PragmaMsStackAction::Pop) {
15811581
if (!StackSlotLabel.empty()) {
15821582
// If we've got a label, try to find it and jump there.
15831583
auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
@@ -1596,7 +1596,7 @@ class Sema final : public SemaBase {
15961596
Stack.pop_back();
15971597
}
15981598
}
1599-
if (Action & PSK_Set) {
1599+
if (Action & PragmaMsStackAction::Set) {
16001600
CurrentValue = Value;
16011601
CurrentPragmaLocation = PragmaLocation;
16021602
}
@@ -1617,7 +1617,8 @@ class Sema final : public SemaBase {
16171617
//
16181618
// Push / pop a named sentinel slot.
16191619
void SentinelAction(PragmaMsStackAction Action, StringRef Label) {
1620-
assert((Action == PSK_Push || Action == PSK_Pop) &&
1620+
assert((Action == PragmaMsStackAction::Push ||
1621+
Action == PragmaMsStackAction::Pop) &&
16211622
"Can only push / pop #pragma stack sentinels!");
16221623
Act(CurrentPragmaLocation, Action, Label, CurrentValue);
16231624
}
@@ -1629,7 +1630,7 @@ class Sema final : public SemaBase {
16291630
bool hasValue() const { return CurrentValue != DefaultValue; }
16301631

16311632
SmallVector<Slot, 2> Stack;
1632-
ValueType DefaultValue; // Value used for PSK_Reset action.
1633+
ValueType DefaultValue; // Value used for PragmaMsStackAction::Reset action.
16331634
ValueType CurrentValue;
16341635
SourceLocation CurrentPragmaLocation;
16351636
};

clang/lib/Parse/ParsePragma.cpp

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ void Parser::HandlePragmaFloatControl() {
869869
// and the FloatControl is the lower 16 bits. Use shift and bit-and
870870
// to decode the parts.
871871
uintptr_t Value = reinterpret_cast<uintptr_t>(Tok.getAnnotationValue());
872-
Sema::PragmaMsStackAction Action =
873-
static_cast<Sema::PragmaMsStackAction>((Value >> 16) & 0xFFFF);
872+
PragmaMsStackAction Action =
873+
static_cast<PragmaMsStackAction>((Value >> 16) & 0xFFFF);
874874
PragmaFloatControlKind Kind = PragmaFloatControlKind(Value & 0xFFFF);
875875
SourceLocation PragmaLoc = ConsumeAnnotationToken();
876876
Actions.ActOnPragmaFloatControl(PragmaLoc, Action, Kind);
@@ -1019,8 +1019,8 @@ void Parser::HandlePragmaMSPointersToMembers() {
10191019
void Parser::HandlePragmaMSVtorDisp() {
10201020
assert(Tok.is(tok::annot_pragma_ms_vtordisp));
10211021
uintptr_t Value = reinterpret_cast<uintptr_t>(Tok.getAnnotationValue());
1022-
Sema::PragmaMsStackAction Action =
1023-
static_cast<Sema::PragmaMsStackAction>((Value >> 16) & 0xFFFF);
1022+
PragmaMsStackAction Action =
1023+
static_cast<PragmaMsStackAction>((Value >> 16) & 0xFFFF);
10241024
MSVtorDispMode Mode = MSVtorDispMode(Value & 0xFFFF);
10251025
SourceLocation PragmaLoc = ConsumeAnnotationToken();
10261026
Actions.ActOnPragmaMSVtorDisp(Action, PragmaLoc, Mode);
@@ -1151,21 +1151,21 @@ bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
11511151
return false;
11521152
}
11531153
PP.Lex(Tok); // (
1154-
Sema::PragmaMsStackAction Action = Sema::PSK_Reset;
1154+
PragmaMsStackAction Action = PragmaMsStackAction::Reset;
11551155
StringRef SlotLabel;
11561156
if (Tok.isAnyIdentifier()) {
11571157
StringRef PushPop = Tok.getIdentifierInfo()->getName();
11581158
if (PushPop == "push")
1159-
Action = Sema::PSK_Push;
1159+
Action = PragmaMsStackAction::Push;
11601160
else if (PushPop == "pop")
1161-
Action = Sema::PSK_Pop;
1161+
Action = PragmaMsStackAction::Pop;
11621162
else {
11631163
PP.Diag(PragmaLocation,
11641164
diag::warn_pragma_expected_section_push_pop_or_name)
11651165
<< PragmaName;
11661166
return false;
11671167
}
1168-
if (Action != Sema::PSK_Reset) {
1168+
if (Action != PragmaMsStackAction::Reset) {
11691169
PP.Lex(Tok); // push | pop
11701170
if (Tok.is(tok::comma)) {
11711171
PP.Lex(Tok); // ,
@@ -1191,10 +1191,12 @@ bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
11911191
StringLiteral *SegmentName = nullptr;
11921192
if (Tok.isNot(tok::r_paren)) {
11931193
if (Tok.isNot(tok::string_literal)) {
1194-
unsigned DiagID = Action != Sema::PSK_Reset ? !SlotLabel.empty() ?
1195-
diag::warn_pragma_expected_section_name :
1196-
diag::warn_pragma_expected_section_label_or_name :
1197-
diag::warn_pragma_expected_section_push_pop_or_name;
1194+
unsigned DiagID =
1195+
Action != PragmaMsStackAction::Reset
1196+
? !SlotLabel.empty()
1197+
? diag::warn_pragma_expected_section_name
1198+
: diag::warn_pragma_expected_section_label_or_name
1199+
: diag::warn_pragma_expected_section_push_pop_or_name;
11981200
PP.Diag(PragmaLocation, DiagID) << PragmaName;
11991201
return false;
12001202
}
@@ -1209,7 +1211,7 @@ bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
12091211
}
12101212
// Setting section "" has no effect
12111213
if (SegmentName->getLength())
1212-
Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set);
1214+
Action = (PragmaMsStackAction)(Action | PragmaMsStackAction::Set);
12131215
}
12141216
if (Tok.isNot(tok::r_paren)) {
12151217
PP.Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
@@ -1298,23 +1300,23 @@ bool Parser::HandlePragmaMSStrictGuardStackCheck(
12981300
PragmaName))
12991301
return false;
13001302

1301-
Sema::PragmaMsStackAction Action = Sema::PSK_Set;
1303+
PragmaMsStackAction Action = PragmaMsStackAction::Set;
13021304
if (Tok.is(tok::identifier)) {
13031305
StringRef PushPop = Tok.getIdentifierInfo()->getName();
13041306
if (PushPop == "push") {
13051307
PP.Lex(Tok);
1306-
Action = Sema::PSK_Push;
1308+
Action = PragmaMsStackAction::Push;
13071309
if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
13081310
PragmaName))
13091311
return false;
13101312
} else if (PushPop == "pop") {
13111313
PP.Lex(Tok);
1312-
Action = Sema::PSK_Pop;
1314+
Action = PragmaMsStackAction::Pop;
13131315
}
13141316
}
13151317

13161318
bool Value = false;
1317-
if (Action & Sema::PSK_Push || Action & Sema::PSK_Set) {
1319+
if (Action & PragmaMsStackAction::Push || Action & PragmaMsStackAction::Set) {
13181320
const IdentifierInfo *II = Tok.getIdentifierInfo();
13191321
if (II && II->isStr("off")) {
13201322
PP.Lex(Tok);
@@ -2138,7 +2140,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21382140
return;
21392141
}
21402142

2141-
Sema::PragmaMsStackAction Action = Sema::PSK_Reset;
2143+
PragmaMsStackAction Action = PragmaMsStackAction::Reset;
21422144
StringRef SlotLabel;
21432145
Token Alignment;
21442146
Alignment.startToken();
@@ -2152,12 +2154,12 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21522154
// the push/pop stack.
21532155
// In Apple gcc/XL, #pragma pack(4) is equivalent to #pragma pack(push, 4)
21542156
Action = (PP.getLangOpts().ApplePragmaPack || PP.getLangOpts().XLPragmaPack)
2155-
? Sema::PSK_Push_Set
2156-
: Sema::PSK_Set;
2157+
? PragmaMsStackAction::PushSet
2158+
: PragmaMsStackAction::Set;
21572159
} else if (Tok.is(tok::identifier)) {
21582160
// Map pragma pack options to pack (integer).
21592161
auto MapPack = [&](const char *Literal) {
2160-
Action = Sema::PSK_Push_Set;
2162+
Action = PragmaMsStackAction::PushSet;
21612163
Alignment = Tok;
21622164
Alignment.setKind(tok::numeric_constant);
21632165
Alignment.setLiteralData(Literal);
@@ -2166,7 +2168,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21662168

21672169
const IdentifierInfo *II = Tok.getIdentifierInfo();
21682170
if (II->isStr("show")) {
2169-
Action = Sema::PSK_Show;
2171+
Action = PragmaMsStackAction::Show;
21702172
PP.Lex(Tok);
21712173
} else if (II->isStr("packed") && PP.getLangOpts().ZOSExt) {
21722174
// #pragma pack(packed) is the same as #pragma pack(1)
@@ -2182,13 +2184,13 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21822184
PP.Lex(Tok);
21832185
} else if (II->isStr("reset") && PP.getLangOpts().ZOSExt) {
21842186
// #pragma pack(reset) is the same as #pragma pack(pop) on XL
2185-
Action = Sema::PSK_Pop;
2187+
Action = PragmaMsStackAction::Pop;
21862188
PP.Lex(Tok);
21872189
} else {
21882190
if (II->isStr("push")) {
2189-
Action = Sema::PSK_Push;
2191+
Action = PragmaMsStackAction::Push;
21902192
} else if (II->isStr("pop")) {
2191-
Action = Sema::PSK_Pop;
2193+
Action = PragmaMsStackAction::Pop;
21922194
} else {
21932195
PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_action) << "pack";
21942196
return;
@@ -2199,7 +2201,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21992201
PP.Lex(Tok);
22002202

22012203
if (Tok.is(tok::numeric_constant)) {
2202-
Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set);
2204+
Action = (PragmaMsStackAction)(Action | PragmaMsStackAction::Set);
22032205
Alignment = Tok;
22042206

22052207
PP.Lex(Tok);
@@ -2215,7 +2217,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
22152217
return;
22162218
}
22172219

2218-
Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set);
2220+
Action = (PragmaMsStackAction)(Action | PragmaMsStackAction::Set);
22192221
Alignment = Tok;
22202222

22212223
PP.Lex(Tok);
@@ -2232,7 +2234,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
22322234
// the push/pop stack.
22332235
// In Apple gcc and IBM XL, #pragma pack() is equivalent to #pragma
22342236
// pack(pop).
2235-
Action = Sema::PSK_Pop;
2237+
Action = PragmaMsStackAction::Pop;
22362238
}
22372239

22382240
if (Tok.isNot(tok::r_paren)) {
@@ -2895,7 +2897,7 @@ void PragmaMSVtorDisp::HandlePragma(Preprocessor &PP,
28952897
}
28962898
PP.Lex(Tok);
28972899

2898-
Sema::PragmaMsStackAction Action = Sema::PSK_Set;
2900+
PragmaMsStackAction Action = PragmaMsStackAction::Set;
28992901
const IdentifierInfo *II = Tok.getIdentifierInfo();
29002902
if (II) {
29012903
if (II->isStr("push")) {
@@ -2906,24 +2908,24 @@ void PragmaMSVtorDisp::HandlePragma(Preprocessor &PP,
29062908
return;
29072909
}
29082910
PP.Lex(Tok);
2909-
Action = Sema::PSK_Push_Set;
2911+
Action = PragmaMsStackAction::PushSet;
29102912
// not push, could be on/off
29112913
} else if (II->isStr("pop")) {
29122914
// #pragma vtordisp(pop)
29132915
PP.Lex(Tok);
2914-
Action = Sema::PSK_Pop;
2916+
Action = PragmaMsStackAction::Pop;
29152917
}
29162918
// not push or pop, could be on/off
29172919
} else {
29182920
if (Tok.is(tok::r_paren)) {
29192921
// #pragma vtordisp()
2920-
Action = Sema::PSK_Reset;
2922+
Action = PragmaMsStackAction::Reset;
29212923
}
29222924
}
29232925

29242926

29252927
uint64_t Value = 0;
2926-
if (Action & Sema::PSK_Push || Action & Sema::PSK_Set) {
2928+
if (Action & PragmaMsStackAction::Push || Action & PragmaMsStackAction::Set) {
29272929
const IdentifierInfo *II = Tok.getIdentifierInfo();
29282930
if (II && II->isStr("off")) {
29292931
PP.Lex(Tok);
@@ -3014,7 +3016,7 @@ void PragmaMSPragma::HandlePragma(Preprocessor &PP,
30143016
void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30153017
PragmaIntroducer Introducer,
30163018
Token &Tok) {
3017-
Sema::PragmaMsStackAction Action = Sema::PSK_Set;
3019+
PragmaMsStackAction Action = PragmaMsStackAction::Set;
30183020
SourceLocation FloatControlLoc = Tok.getLocation();
30193021
Token PragmaName = Tok;
30203022
if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
@@ -3054,7 +3056,8 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30543056
return;
30553057
}
30563058
PP.Lex(Tok); // Eat the r_paren
3057-
Action = (Kind == PFC_Pop) ? Sema::PSK_Pop : Sema::PSK_Push;
3059+
Action = (Kind == PFC_Pop) ? PragmaMsStackAction::Pop
3060+
: PragmaMsStackAction::Push;
30583061
} else {
30593062
if (Tok.is(tok::r_paren))
30603063
// Selecting Precise or Except
@@ -3078,7 +3081,7 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30783081
if (Kind == PFC_Except)
30793082
Kind = PFC_NoExcept;
30803083
} else if (PushOnOff == "push") {
3081-
Action = Sema::PSK_Push_Set;
3084+
Action = PragmaMsStackAction::PushSet;
30823085
} else {
30833086
PP.Diag(Tok.getLocation(), diag::err_pragma_float_control_malformed);
30843087
return;
@@ -3092,7 +3095,7 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
30923095
}
30933096
StringRef ExpectedPush = Tok.getIdentifierInfo()->getName();
30943097
if (ExpectedPush == "push") {
3095-
Action = Sema::PSK_Push_Set;
3098+
Action = PragmaMsStackAction::PushSet;
30963099
} else {
30973100
PP.Diag(Tok.getLocation(), diag::err_pragma_float_control_malformed);
30983101
return;

0 commit comments

Comments
 (0)