[cfe-commits] r38560 - 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:39 PDT 2007
Author: sabre
Date: Wed Jul 11 11:22:38 2007
New Revision: 38560
URL: http://llvm.org/viewvc/llvm-project?rev=38560&view=rev
Log:
Implement a new SourceManager::getSourceName method
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=38560&r1=38559&r2=38560&view=diff
==============================================================================
--- cfe/cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/cfe/trunk/Basic/SourceManager.cpp Wed Jul 11 11:22:38 2007
@@ -133,18 +133,18 @@
/// getColumnNumber - Return the column # for the specified include position.
/// this is significantly cheaper to compute than the line number. This returns
/// zero if the column number isn't known.
-unsigned SourceManager::getColumnNumber(SourceLocation IncludePos) const {
- unsigned FileID = IncludePos.getFileID();
+unsigned SourceManager::getColumnNumber(SourceLocation Loc) const {
+ unsigned FileID = Loc.getFileID();
if (FileID == 0) return 0;
// 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();
+ Loc = FIDInfo->IncludeLoc;
+ FileID = Loc.getFileID();
}
- unsigned FilePos = getFilePos(IncludePos);
+ unsigned FilePos = getFilePos(Loc);
const SourceBuffer *Buffer = getBuffer(FileID);
const char *Buf = Buffer->getBufferStart();
@@ -154,17 +154,35 @@
return FilePos-LineStart+1;
}
+/// getSourceName - This method returns the name of the file or buffer that
+/// the SourceLocation specifies. This can be modified with #line directives,
+/// etc.
+std::string SourceManager::getSourceName(SourceLocation Loc) {
+ unsigned FileID = Loc.getFileID();
+ if (FileID == 0) return "";
+
+ // If this is a macro, we need to get the instantiation location.
+ const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(FileID);
+ if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
+ Loc = FIDInfo->IncludeLoc;
+ FIDInfo = getFIDInfo(Loc.getFileID());
+ }
+
+ return getFileInfo(FIDInfo)->Buffer->getBufferIdentifier();
+}
+
+
/// getLineNumber - Given a SourceLocation, return the physical line number
/// for the position indicated. This requires building and caching a table of
/// line offsets for the SourceBuffer, so this is not cheap: use only when
/// about to emit a diagnostic.
-unsigned SourceManager::getLineNumber(SourceLocation IncludePos) {
- unsigned FileID = IncludePos.getFileID();
+unsigned SourceManager::getLineNumber(SourceLocation Loc) {
+ unsigned FileID = Loc.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();
+ Loc = FIDInfo->IncludeLoc;
+ FileID = Loc.getFileID();
FIDInfo = getFIDInfo(FileID);
}
@@ -226,7 +244,7 @@
// type approaches to make good (tight?) initial guesses based on the
// assumption that all lines are the same average size.
unsigned *Pos = std::lower_bound(SourceLineCache, SourceLineCache+NumLines,
- getFilePos(IncludePos)+1);
+ getFilePos(Loc)+1);
return Pos-SourceLineCache;
}
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=38560&r1=38559&r2=38560&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/SourceManager.h Wed Jul 11 11:22:38 2007
@@ -226,6 +226,11 @@
/// line offsets for the SourceBuffer, so this is not cheap: use only when
/// about to emit a diagnostic.
unsigned getLineNumber(SourceLocation Loc);
+
+ /// getSourceName - This method returns the name of the file or buffer that
+ /// the SourceLocation specifies. This can be modified with #line directives,
+ /// etc.
+ std::string getSourceName(SourceLocation Loc);
/// getFileEntryForFileID - Return the FileEntry record for the specified
/// FileID if one exists.
@@ -262,7 +267,6 @@
// 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 {
More information about the cfe-commits
mailing list