[cfe-commits] r38579 - in /cfe/cfe/trunk: Basic/SourceManager.cpp Driver/clang.cpp include/clang/Basic/SourceManager.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:22:53 PDT 2007
Author: sabre
Date: Wed Jul 11 11:22:53 2007
New Revision: 38579
URL: http://llvm.org/viewvc/llvm-project?rev=38579&view=rev
Log:
Fix Preprocessor/macro_expandloc2.c
Modified:
cfe/cfe/trunk/Basic/SourceManager.cpp
cfe/cfe/trunk/Driver/clang.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=38579&r1=38578&r2=38579&view=diff
==============================================================================
--- cfe/cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/cfe/trunk/Basic/SourceManager.cpp Wed Jul 11 11:22:53 2007
@@ -260,6 +260,23 @@
return Pos-SourceLineCache;
}
+/// getSourceFilePos - This method returns the *logical* offset from the start
+/// of the file that the specified SourceLocation represents. This returns
+/// the location of the *logical* character data, not the physical file
+/// position. In the case of macros, for example, this returns where the
+/// macro was instantiated, not where the characters for the macro can be
+/// found.
+unsigned SourceManager::getSourceFilePos(SourceLocation Loc) const {
+
+ // If this is a macro, we need to get the instantiation location.
+ const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(Loc.getFileID());
+ if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion)
+ return getFilePos(FIDInfo->IncludeLoc);
+
+ return getFilePos(Loc);
+}
+
+
/// PrintStats - Print statistics to stderr.
///
void SourceManager::PrintStats() const {
Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=38579&r1=38578&r2=38579&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:22:53 2007
@@ -136,7 +136,6 @@
if (Pos.isValid()) {
LineNo = SourceMgr.getLineNumber(Pos);
- FilePos = SourceMgr.getFilePos(Pos);
FileID = Pos.getFileID();
// First, if this diagnostic is not in the main file, print out the
@@ -149,6 +148,7 @@
// Compute the column number. Rewind from the current position to the start
// of the line.
ColNo = SourceMgr.getColumnNumber(Pos);
+ FilePos = SourceMgr.getSourceFilePos(Pos);
LineStart = FilePos-ColNo+1; // Column # is 1-based
// Compute the line end. Scan forward from the error position to the end of
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=38579&r1=38578&r2=38579&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/SourceManager.h Wed Jul 11 11:22:53 2007
@@ -143,6 +143,15 @@
/// SourceManager - This file handles loading and caching of source files into
/// memory. This object owns the SourceBuffer objects for all of the loaded
/// files and assigns unique FileID's for each unique #include chain.
+///
+/// The SourceManager can be queried for information about SourceLocation
+/// objects, turning them into either physical or logical locations. Physical
+/// locations represent where the bytes corresponding to a token came from and
+/// logical locations represent where the location is in the user's view. In
+/// the case of a macro expansion, for example, the physical location indicates
+/// where the expanded token came from and the logical location specifies where
+/// it was expanded. Logical locations are also influenced by #line directives,
+/// etc.
class SourceManager {
/// FileInfos - Memoized information about all of the files tracked by this
/// SourceManager.
@@ -194,8 +203,8 @@
/// getFilePos - This (efficient) method returns the offset from the start of
/// the file that the specified SourceLocation represents. This returns the
/// location of the physical character data, not the logical file position.
- unsigned getFilePos(SourceLocation IncludePos) const {
- const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(IncludePos.getFileID());
+ unsigned getFilePos(SourceLocation Loc) const {
+ const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(Loc.getFileID());
// For Macros, the physical loc is specified by the MacroTokenFileID.
if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion)
@@ -204,8 +213,7 @@
// If this file has been split up into chunks, factor in the chunk number
// that the FileID references.
unsigned ChunkNo = FIDInfo->getNormalBufferChunkNo();
- return IncludePos.getRawFilePos() +
- (ChunkNo << SourceLocation::FilePosBits);
+ return Loc.getRawFilePos() + (ChunkNo << SourceLocation::FilePosBits);
}
/// getCharacterData - Return a pointer to the start of the specified location
@@ -224,6 +232,14 @@
/// about to emit a diagnostic.
unsigned getLineNumber(SourceLocation Loc);
+ /// getSourceFilePos - This method returns the *logical* offset from the start
+ /// of the file that the specified SourceLocation represents. This returns
+ /// the location of the *logical* character data, not the physical file
+ /// position. In the case of macros, for example, this returns where the
+ /// macro was instantiated, not where the characters for the macro can be
+ /// found.
+ unsigned getSourceFilePos(SourceLocation Loc) const;
+
/// getSourceName - This method returns the name of the file or buffer that
/// the SourceLocation specifies. This can be modified with #line directives,
/// etc.
More information about the cfe-commits
mailing list