@@ -76,24 +76,24 @@ Preprocessor::AllocateVisibilityMacroDirective(SourceLocation Loc,
7676 bool isPublic) {
7777 return new (BP) VisibilityMacroDirective (Loc, isPublic);
7878}
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.
9797enum MacroDiag {
9898 MD_NoWarn, // > Not a reserved identifier
9999 MD_KeywordDef, // > Macro hides keyword, enabled by default
@@ -541,25 +541,25 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
541541
542542 // If this is in a skipping block or if we're already handled this #if
543543 // 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) {
563563 CondInfo.FoundNonSkip = true ;
564564 break ;
565565 }
@@ -1119,30 +1119,30 @@ void Preprocessor::HandleLineDirective() {
11191119 // If the StrTok is "eod", then it wasn't present. Otherwise, it must be a
11201120 // string followed by eod.
11211121 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+
11461146 // Verify that there is nothing after the string, other than EOD. Because
11471147 // of C99 6.10.4p5, macros that expand to empty tokens are ok.
11481148 CheckEndOfDirective (" line" , true );
@@ -1269,30 +1269,30 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) {
12691269 // string followed by eod.
12701270 if (StrTok.is (tok::eod)) {
12711271 // 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+
12961296 // If a filename was present, read any flags that are present.
12971297 if (ReadLineMarkerFlags (IsFileEntry, IsFileExit, FileKind, *this ))
12981298 return ;
@@ -1356,14 +1356,14 @@ void Preprocessor::HandleIdentSCCSDirective(Token &Tok) {
13561356 DiscardUntilEndOfDirective ();
13571357 return ;
13581358 }
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.
13671367 CheckEndOfDirective (" ident" );
13681368
13691369 if (Callbacks) {
@@ -2805,29 +2805,29 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
28052805 const Token &HashToken,
28062806 bool ReadAnyTokensBeforeDirective) {
28072807 ++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.
28162816 if (CurPPLexer->getConditionalStackDepth () == 0 ) {
28172817 if (!ReadAnyTokensBeforeDirective && IfNDefMacro && ConditionalTrue)
28182818 // FIXME: Pass in the location of the macro name, not the 'if' token.
28192819 CurPPLexer->MIOpt .EnterTopLevelIfndef (IfNDefMacro, IfToken.getLocation ());
28202820 else
28212821 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 ) {
28312831 // In 'single-file-parse mode' undefined identifiers trigger parsing of all
28322832 // the directive blocks.
28332833 CurPPLexer->pushConditionalLevel (IfToken.getLocation (), /* wasskip*/ false ,
@@ -2914,13 +2914,13 @@ void Preprocessor::HandleElifDirective(Token &ElifToken,
29142914 const Token &HashToken) {
29152915 ++NumElse;
29162916
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)) {
29242924 Diag (ElifToken, diag::pp_err_elif_without_if);
29252925 return ;
29262926 }
@@ -2930,13 +2930,13 @@ void Preprocessor::HandleElifDirective(Token &ElifToken,
29302930 CurPPLexer->MIOpt .EnterTopLevelConditional ();
29312931
29322932 // 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 ) {
29402940 // In 'single-file-parse mode' undefined identifiers trigger parsing of all
29412941 // the directive blocks.
29422942 CurPPLexer->pushConditionalLevel (ElifToken.getLocation (), /* wasskip*/ false ,
0 commit comments