[PATCH] Add contains() and overlaps() predicates to tooling::Range.

Guillaume Papin guillaume.papin at epitech.eu
Fri Jul 19 02:59:35 PDT 2013


Hi klimek,

As suggested in your last mail (Re: [PATCH] Make tooling::Range more
convenient.) I added the predicates to the tooling::Range class.

http://llvm-reviews.chandlerc.com/D1184

Files:
  include/clang/Tooling/Refactoring.h

Index: include/clang/Tooling/Refactoring.h
===================================================================
--- include/clang/Tooling/Refactoring.h
+++ include/clang/Tooling/Refactoring.h
@@ -38,8 +38,27 @@
   Range() : Offset(0), Length(0) {}
   Range(unsigned Offset, unsigned Length) : Offset(Offset), Length(Length) {}
 
+  /// \brief Accessors.
+  /// @{
   unsigned getOffset() const { return Offset; }
   unsigned getLength() const { return Length; }
+  /// @}
+
+  /// \name Range Predicates
+  /// @{
+  /// \brief Whether this range overlaps with \p RHS or not.
+  bool overlaps(Range RHS) const {
+    if ((Offset + Length) <= RHS.Offset || Offset >= (RHS.Offset + RHS.Length))
+      return false;
+    return true;
+  }
+
+  /// \brief Whether this range contains \p RHS or not.
+  bool contains(Range RHS) const {
+    return RHS.Offset >= Offset &&
+           (RHS.Offset + RHS.Length) <= (Offset + Length);
+  }
+  /// @}
 
 private:
   unsigned Offset;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1184.1.patch
Type: text/x-patch
Size: 974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130719/3591527a/attachment.bin>


More information about the cfe-commits mailing list