[cfe-dev] Compare two DeclGroupRefs

Vassil Vassilev vasil.georgiev.vasilev at cern.ch
Mon Jul 16 01:01:22 PDT 2012


Hello devs,
   I need to compare two clang::DeclGroupRefs. Could somebody have a 
look into that patch and see whether I am doing it right?
Thanks a lot!
Vassil

Index: ../clang/include/clang/AST/DeclGroup.h
===================================================================
--- ../clang/include/clang/AST/DeclGroup.h    (revision 160041)
+++ ../clang/include/clang/AST/DeclGroup.h    (working copy)
@@ -128,6 +128,29 @@
      X.D = static_cast<Decl*>(Ptr);
      return X;
    }
+
+  /// operator== - Determine whether the specified DeclGroupRefs are 
identical.
+  ///
+  friend bool operator==(const DeclGroupRef LHS, const DeclGroupRef RHS) {
+    if (LHS.D == RHS.D) {
+      if (LHS.isSingleDecl() && RHS.isSingleDecl())
+        return true;
+
+      if (LHS.isDeclGroup() && RHS.isDeclGroup()){
+        const DeclGroup &LDG = LHS.getDeclGroup();
+        const DeclGroup &RDG = RHS.getDeclGroup();
+        if (LDG.size() != RDG.size())
+          return false;
+
+        for (size_t i = 0; i < LDG.size(); ++i)
+          if (LDG[i] != RDG[i])
+            return false;
+
+        return true;
+      }
+    }
+    return false;
+  }
  };

  } // end clang namespace




More information about the cfe-dev mailing list