summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-10-30 12:37:16 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-10-30 12:37:16 +0000
commitdbebe6ee9c0b6e15541bf03b3bf08dd1fd107a88 (patch)
tree3e0f8c5a9f8b6dd43535df32b782ddb325f08c50
parent29bc80e5f70b8a72ea47803d45e78e5117baa27b (diff)
[clang] Move two utility functions into SourceManager
Summary: So we can keep that not-so-great logic in one place. Reviewers: rsmith, aaron.ballman Reviewed By: rsmith Subscribers: nemanjai, kbarton, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D53837 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345594 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/SourceManager.h12
-rw-r--r--lib/CodeGen/MacroPPCallbacks.cpp14
2 files changed, 14 insertions, 12 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index c5a53960b3..914225a5c2 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -1428,6 +1428,18 @@ public:
return getFileID(Loc) == getMainFileID();
}
+ /// Returns whether \p Loc is located in a <built-in> file.
+ bool isWrittenInBuiltinFile(SourceLocation Loc) const {
+ StringRef Filename(getPresumedLoc(Loc).getFilename());
+ return Filename.equals("<built-in>");
+ }
+
+ /// Returns whether \p Loc is located in a <command line> file.
+ bool isWrittenInCommandLineFile(SourceLocation Loc) const {
+ StringRef Filename(getPresumedLoc(Loc).getFilename());
+ return Filename.equals("<command line>");
+ }
+
/// Returns if a SourceLocation is in a system header.
bool isInSystemHeader(SourceLocation Loc) const {
return isSystem(getFileCharacteristic(Loc));
diff --git a/lib/CodeGen/MacroPPCallbacks.cpp b/lib/CodeGen/MacroPPCallbacks.cpp
index 48dea7d54b..05acc9bb27 100644
--- a/lib/CodeGen/MacroPPCallbacks.cpp
+++ b/lib/CodeGen/MacroPPCallbacks.cpp
@@ -88,16 +88,6 @@ SourceLocation MacroPPCallbacks::getCorrectLocation(SourceLocation Loc) {
return SourceLocation();
}
-static bool isBuiltinFile(SourceManager &SM, SourceLocation Loc) {
- StringRef Filename(SM.getPresumedLoc(Loc).getFilename());
- return Filename.equals("<built-in>");
-}
-
-static bool isCommandLineFile(SourceManager &SM, SourceLocation Loc) {
- StringRef Filename(SM.getPresumedLoc(Loc).getFilename());
- return Filename.equals("<command line>");
-}
-
void MacroPPCallbacks::updateStatusToNextScope() {
switch (Status) {
case NoScope:
@@ -127,7 +117,7 @@ void MacroPPCallbacks::FileEntered(SourceLocation Loc) {
updateStatusToNextScope();
return;
case BuiltinScope:
- if (isCommandLineFile(PP.getSourceManager(), Loc))
+ if (PP.getSourceManager().isWrittenInCommandLineFile(Loc))
return;
updateStatusToNextScope();
LLVM_FALLTHROUGH;
@@ -147,7 +137,7 @@ void MacroPPCallbacks::FileExited(SourceLocation Loc) {
default:
llvm_unreachable("Do not expect to exit a file from current scope");
case BuiltinScope:
- if (!isBuiltinFile(PP.getSourceManager(), Loc))
+ if (!PP.getSourceManager().isWrittenInBuiltinFile(Loc))
// Skip next scope and change status to MainFileScope.
Status = MainFileScope;
return;