forked from OSchip/llvm-project
fa69b60806
Translating between JSON objects and C++ strutctures is common. From experience in clangd, fromJSON/ObjectMapper work well and save a lot of code, but aren't adopted elsewhere at least partly due to total lack of error reporting beyond "ok"/"bad". The recently-added error model should be rich enough for most applications. It requires tracking the path within the root object and reporting local errors at appropriate places. To do this, we exploit the fact that the call graph of recursive parse functions mirror the structure of the JSON itself. The current path is represented as a linked list of segments, each of which is on the stack as a parameter. Concretely, fromJSON now looks like: bool fromJSON(const Value&, T&, Path); Beyond the signature change, this is reasonably unobtrusive: building the path segments is mostly handled by ObjectMapper and the vector<T> fromJSON. However the root caller of fromJSON must now create a Root object to store the errors, which is a little clunky. I've added high-level parse<T>(StringRef) -> Expected<T>, but it's not general enough to be the primary interface I think (at least, not usable in clangd). All existing users (mostly just clangd) are updated in this patch, making this change backwards-compatible is a bit hairy. Differential Revision: https://reviews.llvm.org/D88103 |
||
---|---|---|
.. | ||
clang-apply-replacements | ||
clang-change-namespace | ||
clang-doc | ||
clang-include-fixer | ||
clang-move | ||
clang-query | ||
clang-reorder-fields | ||
clang-tidy | ||
clangd | ||
docs | ||
modularize | ||
pp-trace | ||
test | ||
tool-template | ||
unittests | ||
.gitignore | ||
CMakeLists.txt | ||
CODE_OWNERS.TXT | ||
LICENSE.TXT | ||
README.txt |
README.txt
//===----------------------------------------------------------------------===// // Clang Tools repository //===----------------------------------------------------------------------===// Welcome to the repository of extra Clang Tools. This repository holds tools that are developed as part of the LLVM compiler infrastructure project and the Clang frontend. These tools are kept in a separate "extra" repository to allow lighter weight checkouts of the core Clang codebase. This repository is only intended to be checked out inside of a full LLVM+Clang tree, and in the 'tools/extra' subdirectory of the Clang checkout. All discussion regarding Clang, Clang-based tools, and code in this repository should be held using the standard Clang mailing lists: http://lists.llvm.org/mailman/listinfo/cfe-dev Code review for this tree should take place on the standard Clang patch and commit lists: http://lists.llvm.org/mailman/listinfo/cfe-commits If you find a bug in these tools, please file it in the LLVM bug tracker: http://llvm.org/bugs/