diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-15 20:52:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-15 20:52:18 +0000 |
commit | e7fb48466afcbf2c4ccdfa658824282fdc3c512c (patch) | |
tree | 4c2ea5e76f59eb02d41ce34a981cf1c19227ec87 /lib/Lex/Lexer.cpp | |
parent | 3ada6ffd92e02b02f1cdb3c2044aab24dbe0b755 (diff) |
track "just a little more" location information for macro instantiations.
Now instead of just tracking the expansion history, also track the full
range of the macro that got replaced. For object-like macros, this doesn't
change anything. For _Pragma and function-like macros, this means we track
the locations of the ')'.
This is required for PR3579 because apparently GCC uses the line of the ')'
of a function-like macro as the location to expand __LINE__ to.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64601 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 72715c9eed..5f32522020 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -151,7 +151,8 @@ Lexer::Lexer(FileID FID, const SourceManager &SM, const LangOptions &features) /// out of the critical path of the lexer! /// Lexer *Lexer::Create_PragmaLexer(SourceLocation SpellingLoc, - SourceLocation InstantiationLoc, + SourceLocation InstantiationLocStart, + SourceLocation InstantiationLocEnd, unsigned TokLen, Preprocessor &PP) { SourceManager &SM = PP.getSourceManager(); @@ -170,7 +171,8 @@ Lexer *Lexer::Create_PragmaLexer(SourceLocation SpellingLoc, // Set the SourceLocation with the remapping information. This ensures that // GetMappedTokenLoc will remap the tokens as they are lexed. L->FileLoc = SM.createInstantiationLoc(SM.getLocForStartOfFile(SpellingFID), - InstantiationLoc, TokLen); + InstantiationLocStart, + InstantiationLocEnd, TokLen); // Ensure that the lexer thinks it is inside a directive, so that end \n will // return an EOM token. @@ -315,16 +317,24 @@ static SourceLocation GetMappedTokenLoc(Preprocessor &PP, static SourceLocation GetMappedTokenLoc(Preprocessor &PP, SourceLocation FileLoc, unsigned CharNo, unsigned TokLen) { + assert(FileLoc.isMacroID() && "Must be an instantiation"); + // Otherwise, we're lexing "mapped tokens". This is used for things like // _Pragma handling. Combine the instantiation location of FileLoc with the // spelling location. - SourceManager &SourceMgr = PP.getSourceManager(); + SourceManager &SM = PP.getSourceManager(); // Create a new SLoc which is expanded from Instantiation(FileLoc) but whose // characters come from spelling(FileLoc)+Offset. - SourceLocation SpellingLoc = SourceMgr.getSpellingLoc(FileLoc); + SourceLocation SpellingLoc = SM.getSpellingLoc(FileLoc); SpellingLoc = SpellingLoc.getFileLocWithOffset(CharNo); - return SourceMgr.createInstantiationLoc(SpellingLoc, FileLoc, TokLen); + + // Figure out the expansion loc range, which is the range covered by the + // original _Pragma(...) sequence. + std::pair<SourceLocation,SourceLocation> II = + SM.getImmediateInstantiationRange(FileLoc); + + return SM.createInstantiationLoc(SpellingLoc, II.first, II.second, TokLen); } /// getSourceLocation - Return a source location identifier for the specified |