<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 6, 2015 at 1:13 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
> On 2015-Apr-06, at 12:58, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Mon, Apr 6, 2015 at 12:48 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
> Author: dexonsmith<br>
> Date: Mon Apr  6 14:48:50 2015<br>
> New Revision: 234200<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=234200&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=234200&view=rev</a><br>
> Log:<br>
> DebugInfo: Add MDTypeRefArray, to replace DITypeArray<br>
><br>
> This array-like wrapper adapts `MDTuple` to have elements of `MDTypeRef`<br>
> (whereas `MDTypeArray` has elements of `MDType`).  This is necessary to<br>
> migrate code using `DITypeArray`.  The only use of this is<br>
> `MDSubroutineType`'s `getTypeArray()` accessor.<br>
><br>
> Modified:<br>
>     llvm/trunk/include/llvm/IR/DebugInfoMetadata.h<br>
><br>
> Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=234200&r1=234199&r2=234200&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=234200&r1=234199&r2=234200&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)<br>
> +++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Mon Apr  6 14:48:50 2015<br>
> @@ -89,6 +89,42 @@ typedef TypedDebugNodeRef<DebugNode> Deb<br>
>  typedef TypedDebugNodeRef<MDScope> MDScopeRef;<br>
>  typedef TypedDebugNodeRef<MDType> MDTypeRef;<br>
><br>
> +class MDTypeRefArray {<br>
> +  const MDTuple *N = nullptr;<br>
> +<br>
> +public:<br>
> +  MDTypeRefArray(const MDTuple *N) : N(N) {}<br>
> +  operator MDTuple *() const { return const_cast<MDTuple *>(N); }<br>
> +  MDTuple *operator->() const { return const_cast<MDTuple *>(N); }<br>
> +  MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }<br>
> +<br>
> +  unsigned size() const { return N->getNumOperands(); }<br>
> +  MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }<br>
> +<br>
> +  class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,<br>
> +                                 std::ptrdiff_t, void, MDTypeRef> {<br>
> +    MDNode::op_iterator I;<br>
> +<br>
> +  public:<br>
> +    explicit iterator(MDNode::op_iterator I) : I(I) {}<br>
> +    MDTypeRef operator*() const { return MDTypeRef(*I); }<br>
> +    iterator &operator++() {<br>
> +      ++I;<br>
> +      return *this;<br>
> +    }<br>
> +    iterator operator++(int) {<br>
> +      iterator Temp(*this);<br>
> +      ++I;<br>
> +      return Temp;<br>
> +    }<br>
> +    bool operator==(const iterator &X) const { return I == X.I; }<br>
> +    bool operator!=(const iterator &X) const { return I != X.I; }<br>
><br>
> FWIW, ideally op overloads that can be non-members should be (to allow the same conversions on the LHS and RHS) - these could be inline friend definitions (or one a friend, and one not - since it can be defined in terms of the other). Not a big deal & we violate this all over the place, and it's not immediately apparent that any conversions should be possible on either side - just good habits.<br>
<br>
</div></div>I'll keep that in mind.  Here there are no implicit conversions, so I'm<br>
tempted to leave it as is (since this is the most compact/clear way of<br>
writing the code).<br>
<br>
Unless you think this should *always* be the way we do it?</blockquote><div><br>That's my personal preference, yes - it just hasn't risen to the level of codifying it in the coding standards (like many C++ idioms, really).<br><br>& off-hand I can't find a great/canonical reference on this style/approach. No doubt I read it in a book somewhere... <br><br>Anyway, I'll leave it at "just a thought" rather than make any effort to mandate it, for now.<br><br>- Dave<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">  If so, you<br>
might propose an addition to the coding standards.  FWIW, I don't have<br>
a strong opinion one way or the other; happy to switch to "the one true<br>
way" if we decide there is one.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> +  };<br>
> +<br>
> +  iterator begin() const { return iterator(N->op_begin()); }<br>
> +  iterator end() const { return iterator(N->op_end()); }<br>
> +};<br>
> +<br>
>  /// \brief Tagged DWARF-like metadata node.<br>
>  ///<br>
>  /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,<br>
> @@ -826,7 +862,7 @@ public:<br>
><br>
>    TempMDSubroutineType clone() const { return cloneImpl(); }<br>
><br>
> -  MDTuple *getTypeArray() const { return getElements(); }<br>
> +  MDTypeRefArray getTypeArray() const { return getElements(); }<br>
>    Metadata *getRawTypeArray() const { return getRawElements(); }<br>
><br>
>    static bool classof(const Metadata *MD) {<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></blockquote></div><br></div></div>