[json] Provide a means to delegate writing a value to another API
authorDaniel Sanders <daniel_l_sanders@apple.com>
Tue, 6 Oct 2020 11:50:41 +0000 (13:50 +0200)
committerSam McCall <sam.mccall@gmail.com>
Wed, 7 Oct 2020 16:31:45 +0000 (18:31 +0200)
commit91a98ec11e2e001d01c47286bc1721046beeae62
tree8ac8d42ae8be56337c9a41e816a76cda82450acf
parentb953a01b2cd04263c878292c609686647be396ad
[json] Provide a means to delegate writing a value to another API

(Based on D87170 by dsanders)

I recently had need to call out to an external API to emit a JSON object as part
of one an LLVM tool was emitting. However, our JSON support didn't provide a way
to delegate part of the JSON output to that API.

Add rawValueBegin() and rawValueEnd() to maintain and check the internal state
while something else is writing to the stream. It's the users responsibility to
ensure that the resulting JSON output is still valid.

Differential Revision: https://reviews.llvm.org/D88902
llvm/include/llvm/Support/JSON.h
llvm/lib/Support/JSON.cpp
llvm/unittests/Support/JSONTest.cpp