This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add parsing and value inspection to JSONExpr.
ClosedPublic

Authored by sammccall on Nov 17 2017, 9:37 AM.

Details

Summary

This will replace the places where we're using YAMLParser to parse JSON now:

  • the new marshalling code (T::parse()) should handle fewer cases and require fewer explicit casts
  • we'll early-reject invalid JSON that YAMLParser accepts
  • we'll be able to fix protocol-parsing bugs caused by the fact that YAML can only parse forward

I plan to do the conversion as soon as this lands, but I don't want it in one
patch as the protocol.cpp changes are conflict-prone.

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Nov 17 2017, 9:37 AM
ioeric edited edge metadata.Nov 20 2017, 3:40 AM

Code looks good. Just some nits.

clangd/JSONExpr.h
62 ↗(On Diff #123363)

It's not obvious what O.array("options") does. Does it convert O.at("options") to an array?

78 ↗(On Diff #123363)

I wonder if we could merge Kind and ExprType.

sammccall updated this revision to Diff 123794.Nov 21 2017, 7:33 AM

Address comment.

clangd/JSONExpr.h
62 ↗(On Diff #123363)

Yes. Added a bit more context here.

78 ↗(On Diff #123363)

As discussed offline, the conceptual difference is public API vs internal implementation. If there was no difference in practice, YAGNI, but we have String->{T_String, T_StringRef}.

So either we need two enums or some hidden internal state which helps us distinguish. The latter seems more error prone to me (e.g. no help from -Wswitch).

So I prefer the current way overall, though it's not a really big deal.

This revision is now accepted and ready to land.Nov 21 2017, 7:36 AM
This revision was automatically updated to reflect the committed changes.