diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-09-27 17:12:50 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-09-27 17:12:50 +0000 |
commit | 1b9c5374a3cd33b0e281f494f0e322aef035abca (patch) | |
tree | bc8706b14ff72cbf2f00636e60d534768fc6cafd | |
parent | d2af0dd5f7820db7cbf9a3734345ebc46e81d21a (diff) | |
download | clang-1b9c5374a3cd33b0e281f494f0e322aef035abca.tar.gz clang-1b9c5374a3cd33b0e281f494f0e322aef035abca.tar.bz2 clang-1b9c5374a3cd33b0e281f494f0e322aef035abca.tar.xz |
SourceManager: Open code isInMainFile.
- We really shouldn't compute line numbers for every file that is asked if it's
the main file, it destroys the lazy computation.
- Invalid locations are no longer accounted to the main file, no other
functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191535 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/SourceManager.h | 4 | ||||
-rw-r--r-- | lib/Basic/SourceManager.cpp | 30 |
2 files changed, 31 insertions, 3 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index c2bf2c5da0..6aab998bd8 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -1299,9 +1299,7 @@ public: /// whether it came from a file other than the main file. This is different /// from isWrittenInMainFile() because it takes line marker directives into /// account. - bool isInMainFile(SourceLocation Loc) const { - return getPresumedLoc(Loc).getIncludeLoc().isInvalid(); - } + bool isInMainFile(SourceLocation Loc) const; /// \brief Returns true if the spelling locations for both SourceLocations /// are part of the same file buffer. diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index fca0dba990..93e9a594e7 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -1553,6 +1553,36 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc, return PresumedLoc(Filename, LineNo, ColNo, IncludeLoc); } +/// \brief Returns whether the PresumedLoc for a given SourceLocation is +/// in the main file. +/// +/// This computes the "presumed" location for a SourceLocation, then checks +/// whether it came from a file other than the main file. This is different +/// from isWrittenInMainFile() because it takes line marker directives into +/// account. +bool SourceManager::isInMainFile(SourceLocation Loc) const { + if (Loc.isInvalid()) return false; + + // Presumed locations are always for expansion points. + std::pair<FileID, unsigned> LocInfo = getDecomposedExpansionLoc(Loc); + + bool Invalid = false; + const SLocEntry &Entry = getSLocEntry(LocInfo.first, &Invalid); + if (Invalid || !Entry.isFile()) + return false; + + const SrcMgr::FileInfo &FI = Entry.getFile(); + + // Check if there is a line directive for this location. + if (FI.hasLineDirectives()) + if (const LineEntry *Entry = + LineTable->FindNearestLineEntry(LocInfo.first, LocInfo.second)) + if (Entry->IncludeOffset) + return false; + + return FI.getIncludeLoc().isInvalid(); +} + /// \brief The size of the SLocEnty that \arg FID represents. unsigned SourceManager::getFileIDSize(FileID FID) const { bool Invalid = false; |