diff --git a/clang/Basic/SourceManager.cpp b/clang/Basic/SourceManager.cpp index 58617441d1ec..9b47ce22dd6e 100644 --- a/clang/Basic/SourceManager.cpp +++ b/clang/Basic/SourceManager.cpp @@ -120,6 +120,20 @@ unsigned SourceManager::createFileIDForMacroExp(SourceLocation SourcePos, return FileIDs.size(); } +/// 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 InstantLoc) { + unsigned CharFilePos = PhysLoc.getRawFilePos(); + unsigned CharFileID = PhysLoc.getFileID(); + + unsigned InstantiationFileID = + createFileIDForMacroExp(InstantLoc, CharFileID); + return SourceLocation(InstantiationFileID, CharFilePos); +} + + /// getCharacterData - Return a pointer to the start of the specified location /// in the appropriate SourceBuffer. This returns null if it cannot be diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 559724eacf86..be85824e1c08 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -184,6 +184,12 @@ public: return createFileID(createMemBufferInfoRec(Buffer), SourceLocation()); } + /// 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, + SourceLocation InstantiationLoc); + /// createFileIDForMacroExp - Return a new FileID for a macro expansion at /// SourcePos, where the macro token character came from PhysicalFileID. ///