This is an archive of the discontinued LLVM Phabricator instance.

[clangd] New conventions for JSON-marshalling functions, centralize machinery
ClosedPublic

Authored by sammccall on Nov 29 2017, 3:49 AM.

Details

Summary
  • JSON<->Obj interface is now ADL functions, so they play nicely with enums
  • recursive vector/map parsing and ObjectMapper moved to JSONExpr and tested
  • renamed (un)parse to to/fromJSON, since text -> JSON is called parse
  • Protocol.cpp gets a bit shorter

Sorry for the giant patch, it's prety mechanical though

Diff Detail

Event Timeline

sammccall created this revision.Nov 29 2017, 3:49 AM
ilya-biryukov accepted this revision.Nov 30 2017, 5:53 AM

Thanks you very much for this patch, JSON parsing now looks better than ever!
LGTM. (Just a few minor NITs).

clangd/JSONExpr.h
71

The name deserialize may be a bit too general and prone to clashes with other code. Maybe choosing something a bit more specific like json_deserialize is a better option.
On the other hand, we do the SFINAE trick to check the types are correct in Expr constructor, so we should be fine either way.

512

Maybe also call Out.clear() to be consistent with deserialize(..., vector)?

547

Maybe make this field private?

This revision is now accepted and ready to land.Nov 30 2017, 5:53 AM
sammccall edited the summary of this revision. (Show Details)Nov 30 2017, 1:31 PM
sammccall marked 3 inline comments as done.
sammccall added inline comments.
clangd/JSONExpr.h
71

Yeah, these are a bit generic. Renamed to toJSON/fromJSON - not perfect names but they're short and I find it easier to remember which direction they convert in.

This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.