[cfe-commits] Fwd: Compare two DeclGroupRefs

Sean Silva silvas at purdue.edu
Wed Jul 18 14:32:36 PDT 2012


Why not

std::equal(LHS.begin(), LHS.end(), RHS.begin(), RHS.end())

?

You may also want factor in if they are the same "kind" of DeclGroupRef
(i.e. isSingleDecl vs. isDeclGroup). Once you have that, then just compare
appropriately.

I'm not sure exactly how best to define the equality on DeclGroupRefs. One
possibility is "they represent the same sequence of Decl*'s", in which
case, the std::equal solution should be correct (maybe needing an isNull()
check).

--Sean Silva

On Wed, Jul 18, 2012 at 4:16 AM, Vassil Vassilev <
vasil.georgiev.vasilev at cern.ch> wrote:

>  ping...
>
>
>
> -------- Original Message --------  Subject: Compare two DeclGroupRefs  Date:
> Mon, 16 Jul 2012 10:01:22 +0200  From: Vassil Vassilev
> <vasil.georgiev.vasilev at cern.ch> <vasil.georgiev.vasilev at cern.ch>  To:
> cfe-dev at cs.uiuc.edu <cfe-dev at cs.uiuc.edu> <cfe-dev at cs.uiuc.edu>
>
> 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
>
>
>
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120718/712b8eca/attachment.html>


More information about the cfe-commits mailing list