From dbebe6ee9c0b6e15541bf03b3bf08dd1fd107a88 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 30 Oct 2018 12:37:16 +0000 Subject: [PATCH] [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 --- include/clang/Basic/SourceManager.h | 12 ++++++++++++ lib/CodeGen/MacroPPCallbacks.cpp | 14 ++------------ 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 file. + bool isWrittenInBuiltinFile(SourceLocation Loc) const { + StringRef Filename(getPresumedLoc(Loc).getFilename()); + return Filename.equals(""); + } + + /// Returns whether \p Loc is located in a file. + bool isWrittenInCommandLineFile(SourceLocation Loc) const { + StringRef Filename(getPresumedLoc(Loc).getFilename()); + return Filename.equals(""); + } + /// 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(""); -} - -static bool isCommandLineFile(SourceManager &SM, SourceLocation Loc) { - StringRef Filename(SM.getPresumedLoc(Loc).getFilename()); - return Filename.equals(""); -} - 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; -- 2.40.0