[cfe-commits] r39867 - in /cfe/trunk: Basic/SourceManager.cpp Lex/MacroExpander.cpp include/clang/Basic/SourceManager.h

Chris Lattner sabre at nondot.org
Sat Jul 14 23:35:27 PDT 2007


Author: lattner
Date: Sun Jul 15 01:35:27 2007
New Revision: 39867

URL: http://llvm.org/viewvc/llvm-project?rev=39867&view=rev
Log:
Change SourceManager::getInstantiationLoc to take virtual locations, doing its
virtual->physical mapping explicitly.

Modified:
    cfe/trunk/Basic/SourceManager.cpp
    cfe/trunk/Lex/MacroExpander.cpp
    cfe/trunk/include/clang/Basic/SourceManager.h

Modified: cfe/trunk/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/SourceManager.cpp?rev=39867&r1=39866&r2=39867&view=diff

==============================================================================
--- cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/trunk/Basic/SourceManager.cpp Sun Jul 15 01:35:27 2007
@@ -166,11 +166,12 @@
 /// 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);

Modified: cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/MacroExpander.cpp?rev=39867&r1=39866&r2=39867&view=diff

==============================================================================
--- cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/trunk/Lex/MacroExpander.cpp Sun Jul 15 01:35:27 2007
@@ -499,8 +499,8 @@
     // 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

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=39867&r1=39866&r2=39867&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Sun Jul 15 01:35:27 2007
@@ -195,9 +195,8 @@
   }
   
   /// 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.





More information about the cfe-commits mailing list