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

Side by Side Diff: tools/clang/blink_gc_plugin/JsonWriter.h

Issue 207913002: Global cycle detection analysis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
6 #define TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
7
8 #include "llvm/Support/raw_ostream.h"
9
10 // Helper to write information for the points-to graph.
11 class JsonWriter {
12 public:
13 static JsonWriter* from(llvm::raw_fd_ostream* os) {
14 return os ? new JsonWriter(os) : 0;
15 }
16 ~JsonWriter() {
17 os_.close();
18 }
19 void OpenList() {
20 Separator();
21 os_ << "[";
22 state_.push(false);
23 }
24 void OpenList(const std::string key) {
25 Write(key);
26 os_ << ":";
27 OpenList();
28 }
29 void CloseList() {
30 os_ << "]";
31 state_.pop();
32 }
33 void OpenObject() {
34 Separator();
35 os_ << "{";
36 state_.push(false);
37 }
38 void CloseObject() {
39 os_ << "}\n";
40 state_.pop();
41 }
42 void Write(const size_t val) {
43 Separator();
44 os_ << val;
45 }
46 void Write(const std::string val) {
47 Separator();
48 os_ << "\"" << val << "\"";
49 }
50 void Write(const std::string key, const size_t val) {
51 Separator();
52 os_ << "\"" << key << "\":" << val;
53 }
54 void Write(const std::string key, const std::string val) {
55 Separator();
56 os_ << "\"" << key << "\":\"" << val << "\"";
57 }
58 private:
59 JsonWriter(llvm::raw_fd_ostream* os) : os_(*os) {}
60 void Separator() {
61 if (state_.empty())
62 return;
63 if (state_.top()) {
64 os_ << ",";
65 return;
66 }
67 state_.top() = true;
68 }
69 llvm::raw_fd_ostream& os_;
70 std::stack<bool> state_;
71 };
72
73 #endif // TOOLS_BLINK_GC_PLUGIN_JSON_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698