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

2018-10-30 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D53837#1279891, @rsmith wrote:

> Thanks, LG. I bet there's a bunch more places we could change to call these 
> two.


Thank you for the review.


Repository:
  rL LLVM

https://reviews.llvm.org/D53837



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-10-30 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345594: [clang] Move two utility functions into 
SourceManager (authored by lebedevri, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D53837?vs=171582&id=171681#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53837

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


Index: cfe/trunk/include/clang/Basic/SourceManager.h
===
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -1428,6 +1428,18 @@
 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));
Index: cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
===
--- cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
+++ cfe/trunk/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("");
-}
-
-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 @@
 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: cfe/trunk/include/clang/Basic/SourceManager.h
===
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -1428,6 +1428,18 @@
 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));
Index: cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
===
--- cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
+++ cfe/trunk/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("");
-}
-
-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 @@
 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;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm

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

2018-10-29 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Thanks, LG. I bet there's a bunch more places we could change to call these two.


Repository:
  rC Clang

https://reviews.llvm.org/D53837



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-10-29 Thread Roman Lebedev via Phabricator via cfe-commits
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("");
-}
-
-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 @@
 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  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));


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("");
-}
-
-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 @@
 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  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));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits