From abca2bba54197256f2830f757218cfbea2ed9cd1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 15 Jul 2007 06:35:27 +0000 Subject: [PATCH] Change SourceManager::getInstantiationLoc to take virtual locations, doing its virtual->physical mapping explicitly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39867 91177308-0d34-0410-b5e6-96231b3b80d8 --- Basic/SourceManager.cpp | 9 +++++---- Lex/MacroExpander.cpp | 4 ++-- include/clang/Basic/SourceManager.h | 5 ++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Basic/SourceManager.cpp b/Basic/SourceManager.cpp index 2a9a553fcc..a2520e3aff 100644 --- a/Basic/SourceManager.cpp +++ b/Basic/SourceManager.cpp @@ -166,11 +166,12 @@ unsigned SourceManager::createFileID(const InfoRec *File, /// getInstantiationLoc - Return a new SourceLocation that encodes the fact /// that a token from physloc PhysLoc should actually be referenced from /// InstantiationLoc. -SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc, +SourceLocation SourceManager::getInstantiationLoc(SourceLocation VirtLoc, SourceLocation InstantLoc) { - assert(getFIDInfo(PhysLoc.getFileID())->IDType != - SrcMgr::FileIDInfo::MacroExpansion && - "Location instantiated in a macro?"); + // The specified source location may be a mapped location, due to a macro + // instantiation or #line directive. Strip off this information to find out + // where the characters are actually located. + SourceLocation PhysLoc = getPhysicalLoc(VirtLoc); // Resolve InstantLoc down to a real logical location. InstantLoc = getLogicalLoc(InstantLoc); diff --git a/Lex/MacroExpander.cpp b/Lex/MacroExpander.cpp index 7a46b14297..c98949ec1d 100644 --- a/Lex/MacroExpander.cpp +++ b/Lex/MacroExpander.cpp @@ -499,8 +499,8 @@ void MacroExpander::Lex(LexerToken &Tok) { // The token could have come from a prior macro expansion. In that case, // ignore the macro expand part to get to the physloc. This happens for // stuff like: #define A(X) X A(A(X)) A(1) - SourceLocation PhysLoc = SrcMgr.getPhysicalLoc(Tok.getLocation()); - Tok.setLocation(SrcMgr.getInstantiationLoc(PhysLoc, InstantiateLoc)); + Tok.setLocation(SrcMgr.getInstantiationLoc(Tok.getLocation(), + InstantiateLoc)); } // If this is the first token, set the lexical properties of the token to diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index e7f0d30a1f..741ca16913 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -195,9 +195,8 @@ public: } /// getInstantiationLoc - Return a new SourceLocation that encodes the fact - /// that a token from physloc PhysLoc should actually be referenced from - /// InstantiationLoc. - SourceLocation getInstantiationLoc(SourceLocation PhysLoc, + /// that a token at Loc should actually be referenced from InstantiationLoc. + SourceLocation getInstantiationLoc(SourceLocation Loc, SourceLocation InstantiationLoc); /// getBuffer - Return the buffer for the specified FileID.