@@ -76,24 +76,24 @@ Preprocessor::AllocateVisibilityMacroDirective(SourceLocation Loc,
76
76
bool isPublic) {
77
77
return new (BP) VisibilityMacroDirective (Loc, isPublic);
78
78
}
79
-
80
- // / Read and discard all tokens remaining on the current line until
81
- // / the tok::eod token is found.
82
- SourceRange Preprocessor::DiscardUntilEndOfDirective () {
83
- Token Tmp;
84
- SourceRange Res;
85
-
86
- LexUnexpandedToken (Tmp);
87
- Res.setBegin (Tmp.getLocation ());
88
- while (Tmp.isNot (tok::eod)) {
89
- assert (Tmp.isNot (tok::eof) && " EOF seen while discarding directive tokens" );
90
- LexUnexpandedToken (Tmp);
91
- }
92
- Res.setEnd (Tmp.getLocation ());
93
- return Res;
94
- }
95
-
96
- // / Enumerates possible cases of #define/#undef a reserved identifier.
79
+
80
+ // / Read and discard all tokens remaining on the current line until
81
+ // / the tok::eod token is found.
82
+ SourceRange Preprocessor::DiscardUntilEndOfDirective () {
83
+ Token Tmp;
84
+ SourceRange Res;
85
+
86
+ LexUnexpandedToken (Tmp);
87
+ Res.setBegin (Tmp.getLocation ());
88
+ while (Tmp.isNot (tok::eod)) {
89
+ assert (Tmp.isNot (tok::eof) && " EOF seen while discarding directive tokens" );
90
+ LexUnexpandedToken (Tmp);
91
+ }
92
+ Res.setEnd (Tmp.getLocation ());
93
+ return Res;
94
+ }
95
+
96
+ // / Enumerates possible cases of #define/#undef a reserved identifier.
97
97
enum MacroDiag {
98
98
MD_NoWarn, // > Not a reserved identifier
99
99
MD_KeywordDef, // > Macro hides keyword, enabled by default
@@ -541,25 +541,25 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
541
541
542
542
// If this is in a skipping block or if we're already handled this #if
543
543
// block, don't bother parsing the condition.
544
- if (CondInfo.WasSkipping || CondInfo.FoundNonSkip ) {
545
- DiscardUntilEndOfDirective ();
546
- } else {
547
- // Restore the value of LexingRawMode so that identifiers are
548
- // looked up, etc, inside the #elif expression.
549
- assert (CurPPLexer->LexingRawMode && " We have to be skipping here!" );
550
- CurPPLexer->LexingRawMode = false ;
551
- IdentifierInfo *IfNDefMacro = nullptr ;
552
- DirectiveEvalResult DER = EvaluateDirectiveExpression (IfNDefMacro);
553
- const bool CondValue = DER.Conditional ;
554
- CurPPLexer->LexingRawMode = true ;
555
- if (Callbacks) {
556
- Callbacks->Elif (
557
- Tok.getLocation (), DER.ExprRange ,
558
- (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False),
559
- CondInfo.IfLoc );
560
- }
561
- // If this condition is true, enter it!
562
- if (CondValue) {
544
+ if (CondInfo.WasSkipping || CondInfo.FoundNonSkip ) {
545
+ DiscardUntilEndOfDirective ();
546
+ } else {
547
+ // Restore the value of LexingRawMode so that identifiers are
548
+ // looked up, etc, inside the #elif expression.
549
+ assert (CurPPLexer->LexingRawMode && " We have to be skipping here!" );
550
+ CurPPLexer->LexingRawMode = false ;
551
+ IdentifierInfo *IfNDefMacro = nullptr ;
552
+ DirectiveEvalResult DER = EvaluateDirectiveExpression (IfNDefMacro);
553
+ const bool CondValue = DER.Conditional ;
554
+ CurPPLexer->LexingRawMode = true ;
555
+ if (Callbacks) {
556
+ Callbacks->Elif (
557
+ Tok.getLocation (), DER.ExprRange ,
558
+ (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False),
559
+ CondInfo.IfLoc );
560
+ }
561
+ // If this condition is true, enter it!
562
+ if (CondValue) {
563
563
CondInfo.FoundNonSkip = true ;
564
564
break ;
565
565
}
@@ -1119,30 +1119,30 @@ void Preprocessor::HandleLineDirective() {
1119
1119
// If the StrTok is "eod", then it wasn't present. Otherwise, it must be a
1120
1120
// string followed by eod.
1121
1121
if (StrTok.is (tok::eod))
1122
- ; // ok
1123
- else if (StrTok.isNot (tok::string_literal)) {
1124
- Diag (StrTok, diag::err_pp_line_invalid_filename);
1125
- DiscardUntilEndOfDirective ();
1126
- return ;
1127
- } else if (StrTok.hasUDSuffix ()) {
1128
- Diag (StrTok, diag::err_invalid_string_udl);
1129
- DiscardUntilEndOfDirective ();
1130
- return ;
1131
- } else {
1132
- // Parse and validate the string, converting it into a unique ID.
1133
- StringLiteralParser Literal (StrTok, *this );
1134
- assert (Literal.isAscii () && " Didn't allow wide strings in" );
1135
- if (Literal.hadError ) {
1136
- DiscardUntilEndOfDirective ();
1137
- return ;
1138
- }
1139
- if (Literal.Pascal ) {
1140
- Diag (StrTok, diag::err_pp_linemarker_invalid_filename);
1141
- DiscardUntilEndOfDirective ();
1142
- return ;
1143
- }
1144
- FilenameID = SourceMgr.getLineTableFilenameID (Literal.GetString ());
1145
-
1122
+ ; // ok
1123
+ else if (StrTok.isNot (tok::string_literal)) {
1124
+ Diag (StrTok, diag::err_pp_line_invalid_filename);
1125
+ DiscardUntilEndOfDirective ();
1126
+ return ;
1127
+ } else if (StrTok.hasUDSuffix ()) {
1128
+ Diag (StrTok, diag::err_invalid_string_udl);
1129
+ DiscardUntilEndOfDirective ();
1130
+ return ;
1131
+ } else {
1132
+ // Parse and validate the string, converting it into a unique ID.
1133
+ StringLiteralParser Literal (StrTok, *this );
1134
+ assert (Literal.isAscii () && " Didn't allow wide strings in" );
1135
+ if (Literal.hadError ) {
1136
+ DiscardUntilEndOfDirective ();
1137
+ return ;
1138
+ }
1139
+ if (Literal.Pascal ) {
1140
+ Diag (StrTok, diag::err_pp_linemarker_invalid_filename);
1141
+ DiscardUntilEndOfDirective ();
1142
+ return ;
1143
+ }
1144
+ FilenameID = SourceMgr.getLineTableFilenameID (Literal.GetString ());
1145
+
1146
1146
// Verify that there is nothing after the string, other than EOD. Because
1147
1147
// of C99 6.10.4p5, macros that expand to empty tokens are ok.
1148
1148
CheckEndOfDirective (" line" , true );
@@ -1269,30 +1269,30 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) {
1269
1269
// string followed by eod.
1270
1270
if (StrTok.is (tok::eod)) {
1271
1271
// Treat this like "#line NN", which doesn't change file characteristics.
1272
- FileKind = SourceMgr.getFileCharacteristic (DigitTok.getLocation ());
1273
- } else if (StrTok.isNot (tok::string_literal)) {
1274
- Diag (StrTok, diag::err_pp_linemarker_invalid_filename);
1275
- DiscardUntilEndOfDirective ();
1276
- return ;
1277
- } else if (StrTok.hasUDSuffix ()) {
1278
- Diag (StrTok, diag::err_invalid_string_udl);
1279
- DiscardUntilEndOfDirective ();
1280
- return ;
1281
- } else {
1282
- // Parse and validate the string, converting it into a unique ID.
1283
- StringLiteralParser Literal (StrTok, *this );
1284
- assert (Literal.isAscii () && " Didn't allow wide strings in" );
1285
- if (Literal.hadError ) {
1286
- DiscardUntilEndOfDirective ();
1287
- return ;
1288
- }
1289
- if (Literal.Pascal ) {
1290
- Diag (StrTok, diag::err_pp_linemarker_invalid_filename);
1291
- DiscardUntilEndOfDirective ();
1292
- return ;
1293
- }
1294
- FilenameID = SourceMgr.getLineTableFilenameID (Literal.GetString ());
1295
-
1272
+ FileKind = SourceMgr.getFileCharacteristic (DigitTok.getLocation ());
1273
+ } else if (StrTok.isNot (tok::string_literal)) {
1274
+ Diag (StrTok, diag::err_pp_linemarker_invalid_filename);
1275
+ DiscardUntilEndOfDirective ();
1276
+ return ;
1277
+ } else if (StrTok.hasUDSuffix ()) {
1278
+ Diag (StrTok, diag::err_invalid_string_udl);
1279
+ DiscardUntilEndOfDirective ();
1280
+ return ;
1281
+ } else {
1282
+ // Parse and validate the string, converting it into a unique ID.
1283
+ StringLiteralParser Literal (StrTok, *this );
1284
+ assert (Literal.isAscii () && " Didn't allow wide strings in" );
1285
+ if (Literal.hadError ) {
1286
+ DiscardUntilEndOfDirective ();
1287
+ return ;
1288
+ }
1289
+ if (Literal.Pascal ) {
1290
+ Diag (StrTok, diag::err_pp_linemarker_invalid_filename);
1291
+ DiscardUntilEndOfDirective ();
1292
+ return ;
1293
+ }
1294
+ FilenameID = SourceMgr.getLineTableFilenameID (Literal.GetString ());
1295
+
1296
1296
// If a filename was present, read any flags that are present.
1297
1297
if (ReadLineMarkerFlags (IsFileEntry, IsFileExit, FileKind, *this ))
1298
1298
return ;
@@ -1356,14 +1356,14 @@ void Preprocessor::HandleIdentSCCSDirective(Token &Tok) {
1356
1356
DiscardUntilEndOfDirective ();
1357
1357
return ;
1358
1358
}
1359
-
1360
- if (StrTok.hasUDSuffix ()) {
1361
- Diag (StrTok, diag::err_invalid_string_udl);
1362
- DiscardUntilEndOfDirective ();
1363
- return ;
1364
- }
1365
-
1366
- // Verify that there is nothing after the string, other than EOD.
1359
+
1360
+ if (StrTok.hasUDSuffix ()) {
1361
+ Diag (StrTok, diag::err_invalid_string_udl);
1362
+ DiscardUntilEndOfDirective ();
1363
+ return ;
1364
+ }
1365
+
1366
+ // Verify that there is nothing after the string, other than EOD.
1367
1367
CheckEndOfDirective (" ident" );
1368
1368
1369
1369
if (Callbacks) {
@@ -2805,29 +2805,29 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
2805
2805
const Token &HashToken,
2806
2806
bool ReadAnyTokensBeforeDirective) {
2807
2807
++NumIf;
2808
-
2809
- // Parse and evaluate the conditional expression.
2810
- IdentifierInfo *IfNDefMacro = nullptr ;
2811
- const DirectiveEvalResult DER = EvaluateDirectiveExpression (IfNDefMacro);
2812
- const bool ConditionalTrue = DER.Conditional ;
2813
-
2814
- // If this condition is equivalent to #ifndef X, and if this is the first
2815
- // directive seen, handle it for the multiple-include optimization.
2808
+
2809
+ // Parse and evaluate the conditional expression.
2810
+ IdentifierInfo *IfNDefMacro = nullptr ;
2811
+ const DirectiveEvalResult DER = EvaluateDirectiveExpression (IfNDefMacro);
2812
+ const bool ConditionalTrue = DER.Conditional ;
2813
+
2814
+ // If this condition is equivalent to #ifndef X, and if this is the first
2815
+ // directive seen, handle it for the multiple-include optimization.
2816
2816
if (CurPPLexer->getConditionalStackDepth () == 0 ) {
2817
2817
if (!ReadAnyTokensBeforeDirective && IfNDefMacro && ConditionalTrue)
2818
2818
// FIXME: Pass in the location of the macro name, not the 'if' token.
2819
2819
CurPPLexer->MIOpt .EnterTopLevelIfndef (IfNDefMacro, IfToken.getLocation ());
2820
2820
else
2821
2821
CurPPLexer->MIOpt .EnterTopLevelConditional ();
2822
- }
2823
-
2824
- if (Callbacks)
2825
- Callbacks->If (
2826
- IfToken.getLocation (), DER.ExprRange ,
2827
- (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
2828
-
2829
- // Should we include the stuff contained by this directive?
2830
- if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds ) {
2822
+ }
2823
+
2824
+ if (Callbacks)
2825
+ Callbacks->If (
2826
+ IfToken.getLocation (), DER.ExprRange ,
2827
+ (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
2828
+
2829
+ // Should we include the stuff contained by this directive?
2830
+ if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds ) {
2831
2831
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
2832
2832
// the directive blocks.
2833
2833
CurPPLexer->pushConditionalLevel (IfToken.getLocation (), /* wasskip*/ false ,
@@ -2914,13 +2914,13 @@ void Preprocessor::HandleElifDirective(Token &ElifToken,
2914
2914
const Token &HashToken) {
2915
2915
++NumElse;
2916
2916
2917
- // #elif directive in a non-skipping conditional... start skipping.
2918
- // We don't care what the condition is, because we will always skip it (since
2919
- // the block immediately before it was included).
2920
- SourceRange ConditionRange = DiscardUntilEndOfDirective ();
2921
-
2922
- PPConditionalInfo CI;
2923
- if (CurPPLexer->popConditionalLevel (CI)) {
2917
+ // #elif directive in a non-skipping conditional... start skipping.
2918
+ // We don't care what the condition is, because we will always skip it (since
2919
+ // the block immediately before it was included).
2920
+ SourceRange ConditionRange = DiscardUntilEndOfDirective ();
2921
+
2922
+ PPConditionalInfo CI;
2923
+ if (CurPPLexer->popConditionalLevel (CI)) {
2924
2924
Diag (ElifToken, diag::pp_err_elif_without_if);
2925
2925
return ;
2926
2926
}
@@ -2930,13 +2930,13 @@ void Preprocessor::HandleElifDirective(Token &ElifToken,
2930
2930
CurPPLexer->MIOpt .EnterTopLevelConditional ();
2931
2931
2932
2932
// If this is a #elif with a #else before it, report the error.
2933
- if (CI.FoundElse ) Diag (ElifToken, diag::pp_err_elif_after_else);
2934
-
2935
- if (Callbacks)
2936
- Callbacks->Elif (ElifToken.getLocation (), ConditionRange,
2937
- PPCallbacks::CVK_NotEvaluated, CI.IfLoc );
2938
-
2939
- if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip ) {
2933
+ if (CI.FoundElse ) Diag (ElifToken, diag::pp_err_elif_after_else);
2934
+
2935
+ if (Callbacks)
2936
+ Callbacks->Elif (ElifToken.getLocation (), ConditionRange,
2937
+ PPCallbacks::CVK_NotEvaluated, CI.IfLoc );
2938
+
2939
+ if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip ) {
2940
2940
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
2941
2941
// the directive blocks.
2942
2942
CurPPLexer->pushConditionalLevel (ElifToken.getLocation (), /* wasskip*/ false ,
0 commit comments