aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/TokenLexer.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-08-23 21:02:32 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-08-23 21:02:32 +0000
commitc0069d850efe74bac36c526dfec86b7dad1ede2f (patch)
tree6fe574386766d02e864c040bbc9c728035cf9fb2 /lib/Lex/TokenLexer.cpp
parentf8c50652f7b224e66b0b6098d1fba07e036019b4 (diff)
TokenLexer::getExpansionLocForMacroDefLoc doesn't need to return an invalid SourceLocation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138377 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/TokenLexer.cpp')
-rw-r--r--lib/Lex/TokenLexer.cpp45
1 files changed, 16 insertions, 29 deletions
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index cda7975ef1..3dcba98bea 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -143,11 +143,8 @@ void TokenLexer::ExpandFunctionArguments() {
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 @@ void TokenLexer::Lex(Token &Tok) {
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 @@ bool TokenLexer::PasteTokens(Token &Tok) {
// 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 @@ SourceLocation
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 @@ void TokenLexer::updateLocForMacroArgTokens(SourceLocation ArgIdSpellLoc,
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);