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 // Helper to write information for the points-to graph.
13 static JsonWriter
* from(std::unique_ptr
<llvm::raw_ostream
> os
) {
14 return os
? new JsonWriter(std::move(os
)) : 0;
21 void OpenList(const std::string key
) {
39 void Write(const size_t val
) {
43 void Write(const std::string val
) {
45 *os_
<< "\"" << val
<< "\"";
47 void Write(const std::string key
, const size_t val
) {
49 *os_
<< "\"" << key
<< "\":" << val
;
51 void Write(const std::string key
, const std::string val
) {
53 *os_
<< "\"" << key
<< "\":\"" << val
<< "\"";
56 JsonWriter(std::unique_ptr
<llvm::raw_ostream
> os
) : os_(std::move(os
)) {}
66 std::unique_ptr
<llvm::raw_ostream
> os_
;
67 std::stack
<bool> state_
;
70 #endif // TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_