1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
6 #define TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
8 #include "llvm/Support/raw_ostream.h"
10 // TODO(hans): Remove this #ifdef after Clang is rolled past r234897.
11 #ifdef LLVM_FORCE_HEAD_REVISION
12 #define JSON_WRITER_STREAM std::unique_ptr<llvm::raw_ostream>
14 #define JSON_WRITER_STREAM llvm::raw_fd_ostream*
17 // Helper to write information for the points-to graph.
20 static JsonWriter
* from(JSON_WRITER_STREAM os
) {
21 return os
? new JsonWriter(std::move(os
)) : 0;
23 #ifndef LLVM_FORCE_HEAD_REVISION
33 void OpenList(const std::string key
) {
51 void Write(const size_t val
) {
55 void Write(const std::string val
) {
57 *os_
<< "\"" << val
<< "\"";
59 void Write(const std::string key
, const size_t val
) {
61 *os_
<< "\"" << key
<< "\":" << val
;
63 void Write(const std::string key
, const std::string val
) {
65 *os_
<< "\"" << key
<< "\":\"" << val
<< "\"";
68 JsonWriter(JSON_WRITER_STREAM os
) : os_(std::move(os
)) {}
78 JSON_WRITER_STREAM os_
;
79 std::stack
<bool> state_
;
82 #endif // TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_