[PATCH] D45753: Lift JSON library from clang-tools-extra/clangd to llvm/Support.

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 17 21:56:46 PDT 2018


sammccall created this revision.
sammccall added reviewers: bkramer, labath.
Herald added subscribers: llvm-commits, MaskRay, ioeric, ilya-biryukov, mgorny.

This consists of four main parts:

- an type json::Expr representing JSON values of dynamic kind, which can be composed, inspected, and modified
- a JSON parser from string -> json::Expr
- a JSON printer from json::Expr -> string, with optional pretty-printing
- a convention for mapping json::Expr <=> native types (fromJSON/toJSON) Mapping functions are provided for primitives (e.g. int, vector) and the ObjectMapper helper helps implement fromJSON for struct/object types.

Based on clangd's usage, a couple of places I'd appreciate review attention:

- fromJSON returns only bool. A richer error-signaling mechanism may be useful to provide useful messages, or let recursive fromJSONs (containers/structs) do careful error recovery.
- should json::obj be always explicitly written (like json::ary)
- there's no streaming parse API. I suspect there are some simple wins like a callback API where the document is a long array, and each element is small. But this can probably be bolted on easily when we see the need.


Repository:
  rL LLVM

https://reviews.llvm.org/D45753

Files:
  include/llvm/Support/JSON.h
  lib/Support/CMakeLists.txt
  lib/Support/JSON.cpp
  unittests/Support/CMakeLists.txt
  unittests/Support/JSONTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45753.142880.patch
Type: text/x-patch
Size: 42828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180418/eac51b92/attachment.bin>


More information about the llvm-commits mailing list