[PATCH] D87335: [json] Create some llvm::Expected-based accessors

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 02:41:54 PDT 2020


sammccall added a comment.

A rough design sketch:

When parsing an object at the top level, we create an error context object. This can store e.g. the name of the schema for the top-level, as well as details of the created error. This is fixed-size with no allocations unless an actual error occurs.

While parsing a subobject, the JSON path is stored as a reverse linked list of stack objects, again with no other allocations until an error happens. (Actual string data is either constant or in the JSON object itself, I think)
When a parse-object-function wants to parse a subobject field "foo", it passes `Path.derive("foo")` to the corresponding parse function.

When an error is reported, the parsing function walks up the chain of path elements to find the root error context:

- storing path elements in the root (which has a vector<Elt> so) to preserve them once destroyed
- storing error semantics in the root as well (could include enum like "wrong type", custom error messages, pointer to relevant JSON data, etc)

Then the error context provides an API to check success, assemble a llvm::Error or Expected etc.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87335/new/

https://reviews.llvm.org/D87335



More information about the llvm-commits mailing list