[cfe-commits] r38558 - in /cfe/cfe/trunk: Basic/SourceManager.cpp include/clang/Basic/SourceManager.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:22:37 PDT 2007
Author: sabre
Date: Wed Jul 11 11:22:37 2007
New Revision: 38558
URL: http://llvm.org/viewvc/llvm-project?rev=38558&view=rev
Log:
Update SourceManager::getLineNumber to return the correct line # for macro
instantiations.
Modified:
cfe/cfe/trunk/Basic/SourceManager.cpp
cfe/cfe/trunk/include/clang/Basic/SourceManager.h
Modified: cfe/cfe/trunk/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Basic/SourceManager.cpp?rev=38558&r1=38557&r2=38558&view=diff
==============================================================================
--- cfe/cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/cfe/trunk/Basic/SourceManager.cpp Wed Jul 11 11:22:37 2007
@@ -159,7 +159,16 @@
/// line offsets for the SourceBuffer, so this is not cheap: use only when
/// about to emit a diagnostic.
unsigned SourceManager::getLineNumber(SourceLocation IncludePos) {
- FileInfo *FileInfo = getFileInfo(IncludePos.getFileID());
+ unsigned FileID = IncludePos.getFileID();
+ // If this is a macro, we need to get the instantiation location.
+ const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(FileID);
+ if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
+ IncludePos = FIDInfo->IncludeLoc;
+ FileID = IncludePos.getFileID();
+ FIDInfo = getFIDInfo(FileID);
+ }
+
+ FileInfo *FileInfo = getFileInfo(FileID);
// If this is the first use of line information for this buffer, compute the
/// SourceLineCache for it on demand.
Modified: cfe/cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/SourceManager.h?rev=38558&r1=38557&r2=38558&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/SourceManager.h Wed Jul 11 11:22:37 2007
@@ -258,16 +258,22 @@
/// Return the InfoRec structure for the specified FileID. This is always the
/// physical reference for the ID.
- const SrcMgr::InfoRec *getInfoRec(unsigned FileID) const {
- const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(FileID);
-
+ const SrcMgr::InfoRec *getInfoRec(const SrcMgr::FileIDInfo *FIDInfo) const {
// For Macros, the physical loc is specified by the MacroTokenFileID.
if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion)
FIDInfo = &FileIDs[FIDInfo->u.MacroTokenFileID-1];
return FIDInfo->getNormalBufferInfo();
}
+ const SrcMgr::InfoRec *getInfoRec(unsigned FileID) const {
+ return getInfoRec(getFIDInfo(FileID));
+ }
+ SrcMgr::FileInfo *getFileInfo(const SrcMgr::FileIDInfo *FIDInfo) const {
+ if (const SrcMgr::InfoRec *IR = getInfoRec(FIDInfo))
+ return const_cast<SrcMgr::FileInfo *>(&IR->second);
+ return 0;
+ }
SrcMgr::FileInfo *getFileInfo(unsigned FileID) const {
if (const SrcMgr::InfoRec *IR = getInfoRec(FileID))
return const_cast<SrcMgr::FileInfo *>(&IR->second);
More information about the cfe-commits
mailing list