diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2013-08-22 00:27:10 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2013-08-22 00:27:10 +0000 |
commit | 24146975f1af8c1b4b14e8545f218129d0e7dfeb (patch) | |
tree | 137eedc1279aef2736ec15715fd96019e1350ee5 /include/clang/Basic/SourceManager.h | |
parent | 55a2b3dbffefceb82bc34b5c88699e9c0a0d0b8c (diff) |
Split isFromMainFile into two functions.
Basically, isInMainFile considers line markers, and isWrittenInMainFile
doesn't. Distinguishing between the two is useful when dealing with
files which are preprocessed files or rewritten with -frewrite-includes
(so we don't, for example, print useless warnings).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188968 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 9fc4885220..c2bf2c5da0 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -1292,14 +1292,30 @@ public: PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives = true) const; - /// \brief Returns true if both SourceLocations correspond to the same file. - bool isFromSameFile(SourceLocation Loc1, SourceLocation Loc2) const { + /// \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 isInMainFile(SourceLocation Loc) const { + return getPresumedLoc(Loc).getIncludeLoc().isInvalid(); + } + + /// \brief Returns true if the spelling locations for both SourceLocations + /// are part of the same file buffer. + /// + /// This check ignores line marker directives. + bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const { return getFileID(Loc1) == getFileID(Loc2); } - /// \brief Returns true if the file of provided SourceLocation is the main - /// file. - bool isFromMainFile(SourceLocation Loc) const { + /// \brief Returns true if the spelling location for the given location + /// is in the main file buffer. + /// + /// This check ignores line marker directives. + bool isWrittenInMainFile(SourceLocation Loc) const { return getFileID(Loc) == getMainFileID(); } |