Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: tools/clang/blink_gc_plugin/JsonWriter.h

Issue 1385193002: Bisect clang Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 246985 Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/clang/blink_gc_plugin/Edge.cpp ('k') | tools/clang/blink_gc_plugin/NeedsTracing.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/blink_gc_plugin/JsonWriter.h
diff --git a/tools/clang/blink_gc_plugin/JsonWriter.h b/tools/clang/blink_gc_plugin/JsonWriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..3fe79103bbadbadc21770b707584ba1648462ed4
--- /dev/null
+++ b/tools/clang/blink_gc_plugin/JsonWriter.h
@@ -0,0 +1,70 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
+#define TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
+
+#include "llvm/Support/raw_ostream.h"
+
+// Helper to write information for the points-to graph.
+class JsonWriter {
+ public:
+ static JsonWriter* from(std::unique_ptr<llvm::raw_ostream> os) {
+ return os ? new JsonWriter(std::move(os)) : 0;
+ }
+ void OpenList() {
+ Separator();
+ *os_ << "[";
+ state_.push(false);
+ }
+ void OpenList(const std::string key) {
+ Write(key);
+ *os_ << ":";
+ OpenList();
+ }
+ void CloseList() {
+ *os_ << "]";
+ state_.pop();
+ }
+ void OpenObject() {
+ Separator();
+ *os_ << "{";
+ state_.push(false);
+ }
+ void CloseObject() {
+ *os_ << "}\n";
+ state_.pop();
+ }
+ void Write(const size_t val) {
+ Separator();
+ *os_ << val;
+ }
+ void Write(const std::string val) {
+ Separator();
+ *os_ << "\"" << val << "\"";
+ }
+ void Write(const std::string key, const size_t val) {
+ Separator();
+ *os_ << "\"" << key << "\":" << val;
+ }
+ void Write(const std::string key, const std::string val) {
+ Separator();
+ *os_ << "\"" << key << "\":\"" << val << "\"";
+ }
+ private:
+ JsonWriter(std::unique_ptr<llvm::raw_ostream> os) : os_(std::move(os)) {}
+ void Separator() {
+ if (state_.empty())
+ return;
+ if (state_.top()) {
+ *os_ << ",";
+ return;
+ }
+ state_.top() = true;
+ }
+ std::unique_ptr<llvm::raw_ostream> os_;
+ std::stack<bool> state_;
+};
+
+#endif // TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
« no previous file with comments | « tools/clang/blink_gc_plugin/Edge.cpp ('k') | tools/clang/blink_gc_plugin/NeedsTracing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698