[PATCH] D53837: [clang] Move two utility functions into SourceManager

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 15:05:12 PDT 2018


lebedev.ri created this revision.
lebedev.ri added reviewers: rsmith, aaron.ballman.
lebedev.ri added a project: clang.
Herald added subscribers: kbarton, nemanjai.

So we can keep that not-so-great logic in one place.


Repository:
  rC Clang

https://reviews.llvm.org/D53837

Files:
  include/clang/Basic/SourceManager.h
  lib/CodeGen/MacroPPCallbacks.cpp


Index: lib/CodeGen/MacroPPCallbacks.cpp
===================================================================
--- lib/CodeGen/MacroPPCallbacks.cpp
+++ lib/CodeGen/MacroPPCallbacks.cpp
@@ -88,16 +88,6 @@
   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 @@
     updateStatusToNextScope();
     return;
   case BuiltinScope:
-    if (isCommandLineFile(PP.getSourceManager(), Loc))
+    if (PP.getSourceManager().isWrittenInCommandLineFile(Loc))
       return;
     updateStatusToNextScope();
     LLVM_FALLTHROUGH;
@@ -147,7 +137,7 @@
   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;
Index: include/clang/Basic/SourceManager.h
===================================================================
--- include/clang/Basic/SourceManager.h
+++ include/clang/Basic/SourceManager.h
@@ -1428,6 +1428,18 @@
     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));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53837.171582.patch
Type: text/x-patch
Size: 2212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181029/eb899fab/attachment-0001.bin>


More information about the cfe-commits mailing list