<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 23, 2015 at 3:01 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-Jan-23, at 14:32, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Fri, Jan 23, 2015 at 1:24 PM, Adrian Prantl <<a href="mailto:aprantl@apple.com">aprantl@apple.com</a>> wrote:<br>
> Author: adrian<br>
> Date: Fri Jan 23 15:24:41 2015<br>
> New Revision: 226939<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=226939&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=226939&view=rev</a><br>
> Log:<br>
> Move the accessor functions from DIExpression::iterator into a wrapper<br>
> DIExpression::Operand, so we can write range-based for loops.<br>
><br>
> Thanks to David Blaikie for the idea.<br>
><br>
> Modified:<br>
> llvm/trunk/include/llvm/IR/DebugInfo.h<br>
> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp<br>
> llvm/trunk/lib/IR/DebugInfo.cpp<br>
><br>
> Modified: llvm/trunk/include/llvm/IR/DebugInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=226939&r1=226938&r2=226939&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=226939&r1=226938&r2=226939&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/IR/DebugInfo.h (original)<br>
> +++ llvm/trunk/include/llvm/IR/DebugInfo.h Fri Jan 23 15:24:41 2015<br>
> @@ -867,16 +867,17 @@ public:<br>
> /// \brief Return the size of this piece in bytes.<br>
> uint64_t getPieceSize() const;<br>
><br>
> + class Operand;<br>
> +<br>
> /// \brief An iterator for DIExpression elements.<br>
> class iterator : public std::iterator<std::forward_iterator_tag, StringRef,<br>
> unsigned, const uint64_t *, uint64_t> {<br>
><br>
> I'm guessing these types passed to std::iterator need to be updated now that the value is an Operand, not a uint64_t.<br>
><br>
<br>
</div></div>Also, this should be a input_iterator, shouldn't it?<br>
<span class=""><br>
> DIHeaderFieldIterator I;<br>
><br>
> Really vaguely curious - should the expression be encoded as a raw byte sequence, rather than bytes in strings in a DIHeader? (bytes in strings seems inefficient?)<br>
><br>
<br>
</span>I think this is fine as is as a stop-gap. When my work is finished<br>
(I'm stalling because I'm having trouble figuring out how to stage<br>
everything), DIExpression won't be backed by a string: it'll store an<br>
array of `uint64_t` directly.<br>
<span class=""><br>
> iterator(DIHeaderFieldIterator I) : I(I) {}<br>
> -<br>
> public:<br>
> iterator() {}<br>
> iterator(const DIExpression &Expr) : I(++Expr.header_begin()) {}<br>
> - uint64_t operator*() const { return I.getNumber<uint64_t>(); }<br>
> + Operand operator*() const { return Operand(I); }<br>
><br>
> I /think/ you might need to return by reference than by value here (& have an Operand value as a member of the iterator) - I think that the iterator requirements require a reference to be returned or some other feature that makes returning by value not viable - but I could totally be wrong here, my memory is very vague.<br>
<br>
</span>Ah, right. This is what I was thinking of above.<br>
<br>
If we switch to input_iterator, returning by value is fine.<br></blockquote><div><br>I seemed to recall it wasn't OK even for input iterators.<br><br>Looking at the spec, it seems input iterator still has to support -> and to do that you need storage (since -> returns a raw pointer to the data).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
(Anyone know what happened to the "new iterator concepts" [1] that<br>
fixed this nonsense of conflating traversal with value access?<br>
<br>
[1]: <a href="http://www.boost.org/doc/libs/1_57_0/libs/iterator/doc/new-iter-concepts.html" target="_blank">http://www.boost.org/doc/libs/1_57_0/libs/iterator/doc/new-iter-concepts.html</a><br>
)<br>
<br>
</blockquote></div><br></div></div>