[cfe-commits] r138377 - /cfe/trunk/lib/Lex/TokenLexer.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Aug 23 14:02:32 PDT 2011


Author: akirtzidis
Date: Tue Aug 23 16:02:32 2011
New Revision: 138377

URL: http://llvm.org/viewvc/llvm-project?rev=138377&view=rev
Log:
TokenLexer::getExpansionLocForMacroDefLoc doesn't need to return an invalid SourceLocation.

Modified:
    cfe/trunk/lib/Lex/TokenLexer.cpp

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=138377&r1=138376&r2=138377&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Tue Aug 23 16:02:32 2011
@@ -143,11 +143,8 @@
       int ArgNo = Macro->getArgumentNum(Tokens[i+1].getIdentifierInfo());
       assert(ArgNo != -1 && "Token following # is not an argument?");
 
-      SourceLocation hashInstLoc;
-      if(ExpandLocStart.isValid()) {
-        hashInstLoc = getExpansionLocForMacroDefLoc(CurTok.getLocation());
-        assert(hashInstLoc.isValid() && "Expected '#' to come from definition");
-      }
+      SourceLocation hashInstLoc =
+          getExpansionLocForMacroDefLoc(CurTok.getLocation());
 
       Token Res;
       if (CurTok.is(tok::hash))  // Stringify
@@ -410,8 +407,6 @@
                                       Tok.getLength());
     } else {
       instLoc = getExpansionLocForMacroDefLoc(Tok.getLocation());
-      assert(instLoc.isValid() &&
-             "Location for token not coming from definition was not set!");
     }
 
     Tok.setLocation(instLoc);
@@ -591,18 +586,12 @@
   // diagnostics for the expanded token should appear as if the token was
   // expanded from the (##) operator. Pull this information together into
   // a new SourceLocation that captures all of this.
-  if (ExpandLocStart.isValid()) {
-    SourceManager &SM = PP.getSourceManager();
-    SourceLocation pasteLocInst =
-        getExpansionLocForMacroDefLoc(PasteOpLoc);
-    assert(pasteLocInst.isValid() &&
-           "Expected '##' to come from definition");
-
-    Tok.setLocation(SM.createExpansionLoc(Tok.getLocation(),
-                                          pasteLocInst,
-                                          pasteLocInst,
-                                          Tok.getLength()));
-  }
+  SourceManager &SM = PP.getSourceManager();
+  SourceLocation pasteLocInst = getExpansionLocForMacroDefLoc(PasteOpLoc);
+  Tok.setLocation(SM.createExpansionLoc(Tok.getLocation(),
+                                        pasteLocInst,
+                                        pasteLocInst,
+                                        Tok.getLength()));
 
   // Now that we got the result token, it will be subject to expansion.  Since
   // token pasting re-lexes the result token in raw mode, identifier information
@@ -656,18 +645,18 @@
 TokenLexer::getExpansionLocForMacroDefLoc(SourceLocation loc) const {
   assert(ExpandLocStart.isValid() && MacroExpansionStart.isValid() &&
          "Not appropriate for token streams");
-  assert(loc.isValid());
+  assert(loc.isValid() && loc.isFileID());
   
   SourceManager &SM = PP.getSourceManager();
-  unsigned relativeOffset;
-  if (loc.isFileID() &&
-      SM.isInFileID(loc,
+  assert(SM.isInFileID(loc,
                     MacroDefStartInfo.first, MacroDefStartInfo.second,
-                    Macro->getDefinitionLength(SM), &relativeOffset)) {
-    return MacroExpansionStart.getFileLocWithOffset(relativeOffset);
-  }
+                    Macro->getDefinitionLength(SM)));
 
-  return SourceLocation();
+  unsigned relativeOffset;
+  SM.isInFileID(loc,
+                MacroDefStartInfo.first, MacroDefStartInfo.second,
+                Macro->getDefinitionLength(SM), &relativeOffset);
+  return MacroExpansionStart.getFileLocWithOffset(relativeOffset);
 }
 
 /// \brief Finds the tokens that are consecutive (from the same FileID)
@@ -727,8 +716,6 @@
 
   SourceLocation curInst =
       getExpansionLocForMacroDefLoc(ArgIdSpellLoc);
-  assert(curInst.isValid() &&
-         "Expected arg identifier to come from definition");
   
   while (begin_tokens < end_tokens)
     updateConsecutiveMacroArgTokens(SM, curInst, begin_tokens, end_tokens);





More information about the cfe-commits mailing list