Author: lebedevri Date: Tue Oct 30 05:37:16 2018 New Revision: 345594 URL: http://llvm.org/viewvc/llvm-project?rev=345594&view=rev Log: [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 Modified: cfe/trunk/include/clang/Basic/SourceManager.h cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp Modified: cfe/trunk/include/clang/Basic/SourceManager.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=345594&r1=345593&r2=345594&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/SourceManager.h (original) +++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Oct 30 05:37:16 2018 @@ -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)); Modified: cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp?rev=345594&r1=345593&r2=345594&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp (original) +++ cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp Tue Oct 30 05:37:16 2018 @@ -88,16 +88,6 @@ SourceLocation MacroPPCallbacks::getCorr 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(Sourc 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(Source 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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits