[lldb-dev] Converting global option tables to use ArrayRef

Zachary Turner via lldb-dev lldb-dev at lists.llvm.org
Wed Sep 21 23:48:05 PDT 2016


I have a patch I'd like to submit tomorrow which converts all of the global
command option tables from C-style arrays to llvm ArrayRefs.

Actually they are still declared internally in each translation unit as
C-style arrays, but the Option classes are updated so that they return
ArrayRefs instead of raw pointers.  Previously there were two strategies:

1) Sometimes we'd return a const Option* and have a method on the class
called GetNumDefinitions() so you could treat the pointer as an array.

2) Other times we'd return a const Option* and expect the caller to iterate
until it reached a sentinel entry.

With the new approach, the two methods are merged and now the
GetDefinitions() method only returns an ArrayRef<OptionDefinition>.

Since this carries with it its length, neither the GetNumDefinitions()
method nor the sentinel entry are needed any more.

Most of the old code compiled without modification, because ArrayRef can be
treated with a similar syntax as arrays, except you'll get a nice assert if
you index out of bounds.

An added bonus is that you can now iterate over them with ranged-based for
syntax.

I can put it up for review if anyone would like, but as it is extremely
mechanical there's not really much to see.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20160922/9e135fc2/attachment.html>


More information about the lldb-dev mailing list