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 | e7800df48b533304caf17d4e523b2ba0618db40a (patch) | |
tree | c8cfaecb2a972502089bdae431ca0fd90776da4c /clang/lib/Basic/SourceManager.cpp | |
parent | 428d042828bb5e60dc2a37e70b81248b6057fccc (diff) | |
download | llvm-e7800df48b533304caf17d4e523b2ba0618db40a.zip llvm-e7800df48b533304caf17d4e523b2ba0618db40a.tar.gz llvm-e7800df48b533304caf17d4e523b2ba0618db40a.tar.bz2 |
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.
llvm-svn: 191535
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index fca0dba..93e9a59 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/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; |