This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add missing (but documented!) JSONExpr typed accessors
ClosedPublic

Authored by sammccall on Nov 23 2017, 12:35 PM.

Diff Detail

Event Timeline

sammccall created this revision.Nov 23 2017, 12:35 PM

While here, fix a duplicated test.

ioeric added inline comments.Nov 24 2017, 1:37 AM
clangd/JSONExpr.h
368

Why is this needed? v[x].null() seems to be more intuitive than v.null(x).

unittests/clangd/JSONExprTests.cpp
203

It's not very obvious that this accesses a KV and converts the value, by only reading this line. Would it make sense to make the APIs more explicit e.g. get_as_xxx(...)?

sammccall added inline comments.Nov 24 2017, 1:48 AM
clangd/JSONExpr.h
368

In the overwhelmingly common case when parsing, v is a pointer, because it resulted from a call to array().

So it's (*v)[x].null() vs v->null(x) - I think the latter is slightly more readable.

But more compelling to me is having consistency between object/array.

We *can* live without these if you like, though - most of the time we iterate over arrays rather than indexed access.

unittests/clangd/JSONExprTests.cpp
203

I think this is made worse because it's an artificial example.
I've sent D40406 which has "real life" code - what do you think about the getters there?

I think the best variant names would be asString() or getString().

I'm a bit reluctant to add a fixed prefix to these common accessors as they seem noisy. I also think we'd need to change all the names on Expr(), which seems like a shame.

So I'm not sure about changing this, but curious what you think of the Protocol conversion code.

sammccall updated this revision to Diff 124203.Nov 24 2017, 6:45 AM
sammccall marked 2 inline comments as done.

Renames to address review comments

Thanks for the review! I think you're right about new names.

clangd/JSONExpr.h
368

I've kept these for now, for readability and symmetry.

unittests/clangd/JSONExprTests.cpp
203

After offline discussion, renamed to Expr::asString() and obj::getString().
These aren't much longer and are more accessible to casual inspection.

ioeric accepted this revision.Nov 28 2017, 1:01 AM

Lgtm

Thanks for the rename!

This revision is now accepted and ready to land.Nov 28 2017, 1:01 AM
This revision was automatically updated to reflect the committed changes.