]> granicus.if.org Git - clang/commitdiff
Remove random windows line endings that snuck into the middle of this
authorChandler Carruth <chandlerc@gmail.com>
Sat, 19 Jan 2019 06:36:00 +0000 (06:36 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 19 Jan 2019 06:36:00 +0000 (06:36 +0000)
code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351633 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp

index 3bee026b0439fe21a8794f08f831101b7fc73770..674e112c7aa70615e4d067ff20e9672fce475e9f 100644 (file)
@@ -76,24 +76,24 @@ Preprocessor::AllocateVisibilityMacroDirective(SourceLocation Loc,
                                                bool isPublic) {
   return new (BP) VisibilityMacroDirective(Loc, isPublic);
 }
-\r
-/// Read and discard all tokens remaining on the current line until\r
-/// the tok::eod token is found.\r
-SourceRange Preprocessor::DiscardUntilEndOfDirective() {\r
-  Token Tmp;\r
-  SourceRange Res;\r
-\r
-  LexUnexpandedToken(Tmp);\r
-  Res.setBegin(Tmp.getLocation());\r
-  while (Tmp.isNot(tok::eod)) {\r
-    assert(Tmp.isNot(tok::eof) && "EOF seen while discarding directive tokens");\r
-    LexUnexpandedToken(Tmp);\r
-  }\r
-  Res.setEnd(Tmp.getLocation());\r
-  return Res;\r
-}\r
-\r
-/// Enumerates possible cases of #define/#undef a reserved identifier.\r
+
+/// Read and discard all tokens remaining on the current line until
+/// the tok::eod token is found.
+SourceRange Preprocessor::DiscardUntilEndOfDirective() {
+  Token Tmp;
+  SourceRange Res;
+
+  LexUnexpandedToken(Tmp);
+  Res.setBegin(Tmp.getLocation());
+  while (Tmp.isNot(tok::eod)) {
+    assert(Tmp.isNot(tok::eof) && "EOF seen while discarding directive tokens");
+    LexUnexpandedToken(Tmp);
+  }
+  Res.setEnd(Tmp.getLocation());
+  return Res;
+}
+
+/// Enumerates possible cases of #define/#undef a reserved identifier.
 enum MacroDiag {
   MD_NoWarn,        //> Not a reserved identifier
   MD_KeywordDef,    //> Macro hides keyword, enabled by default
@@ -541,25 +541,25 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
 
         // If this is in a skipping block or if we're already handled this #if
         // block, don't bother parsing the condition.
-        if (CondInfo.WasSkipping || CondInfo.FoundNonSkip) {\r
-          DiscardUntilEndOfDirective();\r
-        } else {\r
-          // Restore the value of LexingRawMode so that identifiers are\r
-          // looked up, etc, inside the #elif expression.\r
-          assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");\r
-          CurPPLexer->LexingRawMode = false;\r
-          IdentifierInfo *IfNDefMacro = nullptr;\r
-          DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);\r
-          const bool CondValue = DER.Conditional;\r
-          CurPPLexer->LexingRawMode = true;\r
-          if (Callbacks) {\r
-            Callbacks->Elif(\r
-                Tok.getLocation(), DER.ExprRange,\r
-                (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False),\r
-                CondInfo.IfLoc);\r
-          }\r
-          // If this condition is true, enter it!\r
-          if (CondValue) {\r
+        if (CondInfo.WasSkipping || CondInfo.FoundNonSkip) {
+          DiscardUntilEndOfDirective();
+        } else {
+          // Restore the value of LexingRawMode so that identifiers are
+          // looked up, etc, inside the #elif expression.
+          assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");
+          CurPPLexer->LexingRawMode = false;
+          IdentifierInfo *IfNDefMacro = nullptr;
+          DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);
+          const bool CondValue = DER.Conditional;
+          CurPPLexer->LexingRawMode = true;
+          if (Callbacks) {
+            Callbacks->Elif(
+                Tok.getLocation(), DER.ExprRange,
+                (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False),
+                CondInfo.IfLoc);
+          }
+          // If this condition is true, enter it!
+          if (CondValue) {
             CondInfo.FoundNonSkip = true;
             break;
           }
@@ -1119,30 +1119,30 @@ void Preprocessor::HandleLineDirective() {
   // If the StrTok is "eod", then it wasn't present.  Otherwise, it must be a
   // string followed by eod.
   if (StrTok.is(tok::eod))
-    ; // ok\r
-  else if (StrTok.isNot(tok::string_literal)) {\r
-    Diag(StrTok, diag::err_pp_line_invalid_filename);\r
-    DiscardUntilEndOfDirective();\r
-    return;\r
-  } else if (StrTok.hasUDSuffix()) {\r
-    Diag(StrTok, diag::err_invalid_string_udl);\r
-    DiscardUntilEndOfDirective();\r
-    return;\r
-  } else {\r
-    // Parse and validate the string, converting it into a unique ID.\r
-    StringLiteralParser Literal(StrTok, *this);\r
-    assert(Literal.isAscii() && "Didn't allow wide strings in");\r
-    if (Literal.hadError) {\r
-      DiscardUntilEndOfDirective();\r
-      return;\r
-    }\r
-    if (Literal.Pascal) {\r
-      Diag(StrTok, diag::err_pp_linemarker_invalid_filename);\r
-      DiscardUntilEndOfDirective();\r
-      return;\r
-    }\r
-    FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());\r
-\r
+    ; // ok
+  else if (StrTok.isNot(tok::string_literal)) {
+    Diag(StrTok, diag::err_pp_line_invalid_filename);
+    DiscardUntilEndOfDirective();
+    return;
+  } else if (StrTok.hasUDSuffix()) {
+    Diag(StrTok, diag::err_invalid_string_udl);
+    DiscardUntilEndOfDirective();
+    return;
+  } else {
+    // Parse and validate the string, converting it into a unique ID.
+    StringLiteralParser Literal(StrTok, *this);
+    assert(Literal.isAscii() && "Didn't allow wide strings in");
+    if (Literal.hadError) {
+      DiscardUntilEndOfDirective();
+      return;
+    }
+    if (Literal.Pascal) {
+      Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
+      DiscardUntilEndOfDirective();
+      return;
+    }
+    FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());
+
     // Verify that there is nothing after the string, other than EOD.  Because
     // of C99 6.10.4p5, macros that expand to empty tokens are ok.
     CheckEndOfDirective("line", true);
@@ -1269,30 +1269,30 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) {
   // string followed by eod.
   if (StrTok.is(tok::eod)) {
     // Treat this like "#line NN", which doesn't change file characteristics.
-    FileKind = SourceMgr.getFileCharacteristic(DigitTok.getLocation());\r
-  } else if (StrTok.isNot(tok::string_literal)) {\r
-    Diag(StrTok, diag::err_pp_linemarker_invalid_filename);\r
-    DiscardUntilEndOfDirective();\r
-    return;\r
-  } else if (StrTok.hasUDSuffix()) {\r
-    Diag(StrTok, diag::err_invalid_string_udl);\r
-    DiscardUntilEndOfDirective();\r
-    return;\r
-  } else {\r
-    // Parse and validate the string, converting it into a unique ID.\r
-    StringLiteralParser Literal(StrTok, *this);\r
-    assert(Literal.isAscii() && "Didn't allow wide strings in");\r
-    if (Literal.hadError) {\r
-      DiscardUntilEndOfDirective();\r
-      return;\r
-    }\r
-    if (Literal.Pascal) {\r
-      Diag(StrTok, diag::err_pp_linemarker_invalid_filename);\r
-      DiscardUntilEndOfDirective();\r
-      return;\r
-    }\r
-    FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());\r
-\r
+    FileKind = SourceMgr.getFileCharacteristic(DigitTok.getLocation());
+  } else if (StrTok.isNot(tok::string_literal)) {
+    Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
+    DiscardUntilEndOfDirective();
+    return;
+  } else if (StrTok.hasUDSuffix()) {
+    Diag(StrTok, diag::err_invalid_string_udl);
+    DiscardUntilEndOfDirective();
+    return;
+  } else {
+    // Parse and validate the string, converting it into a unique ID.
+    StringLiteralParser Literal(StrTok, *this);
+    assert(Literal.isAscii() && "Didn't allow wide strings in");
+    if (Literal.hadError) {
+      DiscardUntilEndOfDirective();
+      return;
+    }
+    if (Literal.Pascal) {
+      Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
+      DiscardUntilEndOfDirective();
+      return;
+    }
+    FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());
+
     // If a filename was present, read any flags that are present.
     if (ReadLineMarkerFlags(IsFileEntry, IsFileExit, FileKind, *this))
       return;
@@ -1356,14 +1356,14 @@ void Preprocessor::HandleIdentSCCSDirective(Token &Tok) {
       DiscardUntilEndOfDirective();
     return;
   }
-\r
-  if (StrTok.hasUDSuffix()) {\r
-    Diag(StrTok, diag::err_invalid_string_udl);\r
-    DiscardUntilEndOfDirective();\r
-    return;\r
-  }\r
-\r
-  // Verify that there is nothing after the string, other than EOD.\r
+
+  if (StrTok.hasUDSuffix()) {
+    Diag(StrTok, diag::err_invalid_string_udl);
+    DiscardUntilEndOfDirective();
+    return;
+  }
+
+  // Verify that there is nothing after the string, other than EOD.
   CheckEndOfDirective("ident");
 
   if (Callbacks) {
@@ -2805,29 +2805,29 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
                                      const Token &HashToken,
                                      bool ReadAnyTokensBeforeDirective) {
   ++NumIf;
-\r
-  // Parse and evaluate the conditional expression.\r
-  IdentifierInfo *IfNDefMacro = nullptr;\r
-  const DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);\r
-  const bool ConditionalTrue = DER.Conditional;\r
-\r
-  // If this condition is equivalent to #ifndef X, and if this is the first\r
-  // directive seen, handle it for the multiple-include optimization.\r
+
+  // Parse and evaluate the conditional expression.
+  IdentifierInfo *IfNDefMacro = nullptr;
+  const DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);
+  const bool ConditionalTrue = DER.Conditional;
+
+  // If this condition is equivalent to #ifndef X, and if this is the first
+  // directive seen, handle it for the multiple-include optimization.
   if (CurPPLexer->getConditionalStackDepth() == 0) {
     if (!ReadAnyTokensBeforeDirective && IfNDefMacro && ConditionalTrue)
       // FIXME: Pass in the location of the macro name, not the 'if' token.
       CurPPLexer->MIOpt.EnterTopLevelIfndef(IfNDefMacro, IfToken.getLocation());
     else
       CurPPLexer->MIOpt.EnterTopLevelConditional();
-  }\r
-\r
-  if (Callbacks)\r
-    Callbacks->If(\r
-        IfToken.getLocation(), DER.ExprRange,\r
-        (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));\r
-\r
-  // Should we include the stuff contained by this directive?\r
-  if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {\r
+  }
+
+  if (Callbacks)
+    Callbacks->If(
+        IfToken.getLocation(), DER.ExprRange,
+        (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
+
+  // Should we include the stuff contained by this directive?
+  if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
     // In 'single-file-parse mode' undefined identifiers trigger parsing of all
     // the directive blocks.
     CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
@@ -2914,13 +2914,13 @@ void Preprocessor::HandleElifDirective(Token &ElifToken,
                                        const Token &HashToken) {
   ++NumElse;
 
-  // #elif directive in a non-skipping conditional... start skipping.\r
-  // We don't care what the condition is, because we will always skip it (since\r
-  // the block immediately before it was included).\r
-  SourceRange ConditionRange = DiscardUntilEndOfDirective();\r
-\r
-  PPConditionalInfo CI;\r
-  if (CurPPLexer->popConditionalLevel(CI)) {\r
+  // #elif directive in a non-skipping conditional... start skipping.
+  // We don't care what the condition is, because we will always skip it (since
+  // the block immediately before it was included).
+  SourceRange ConditionRange = DiscardUntilEndOfDirective();
+
+  PPConditionalInfo CI;
+  if (CurPPLexer->popConditionalLevel(CI)) {
     Diag(ElifToken, diag::pp_err_elif_without_if);
     return;
   }
@@ -2930,13 +2930,13 @@ void Preprocessor::HandleElifDirective(Token &ElifToken,
     CurPPLexer->MIOpt.EnterTopLevelConditional();
 
   // If this is a #elif with a #else before it, report the error.
-  if (CI.FoundElse) Diag(ElifToken, diag::pp_err_elif_after_else);\r
-\r
-  if (Callbacks)\r
-    Callbacks->Elif(ElifToken.getLocation(), ConditionRange,\r
-                    PPCallbacks::CVK_NotEvaluated, CI.IfLoc);\r
-\r
-  if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) {\r
+  if (CI.FoundElse) Diag(ElifToken, diag::pp_err_elif_after_else);
+
+  if (Callbacks)
+    Callbacks->Elif(ElifToken.getLocation(), ConditionRange,
+                    PPCallbacks::CVK_NotEvaluated, CI.IfLoc);
+
+  if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) {
     // In 'single-file-parse mode' undefined identifiers trigger parsing of all
     // the directive blocks.
     CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,