Ninja
Main Page
Namespaces
Classes
Files
File List
File Members
graphviz.cc
Go to the documentation of this file.
1
// Copyright 2011 Google Inc. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "
graphviz.h
"
16
17
#include <stdio.h>
18
19
#include "
graph.h
"
20
21
void
GraphViz::AddTarget
(
Node
* node) {
22
if
(
visited_nodes_
.find(node) !=
visited_nodes_
.end())
23
return
;
24
25
printf(
"\"%p\" [label=\"%s\"]\n"
, node, node->
path
().c_str());
26
visited_nodes_
.insert(node);
27
28
Edge
* edge = node->
in_edge
();
29
30
if
(!edge) {
31
// Leaf node.
32
// Draw as a rect?
33
return
;
34
}
35
36
if
(
visited_edges_
.find(edge) !=
visited_edges_
.end())
37
return
;
38
visited_edges_
.insert(edge);
39
40
if
(edge->
inputs_
.size() == 1 && edge->
outputs_
.size() == 1) {
41
// Can draw simply.
42
// Note extra space before label text -- this is cosmetic and feels
43
// like a graphviz bug.
44
printf(
"\"%p\" -> \"%p\" [label=\" %s\"]\n"
,
45
edge->
inputs_
[0], edge->
outputs_
[0], edge->
rule_
->
name
().c_str());
46
}
else
{
47
printf(
"\"%p\" [label=\"%s\", shape=ellipse]\n"
,
48
edge, edge->
rule_
->
name
().c_str());
49
for
(vector<Node*>::iterator out = edge->
outputs_
.begin();
50
out != edge->
outputs_
.end(); ++out) {
51
printf(
"\"%p\" -> \"%p\"\n"
, edge, *out);
52
}
53
for
(vector<Node*>::iterator in = edge->
inputs_
.begin();
54
in != edge->
inputs_
.end(); ++in) {
55
const
char
* order_only =
""
;
56
if
(edge->
is_order_only
(in - edge->
inputs_
.begin()))
57
order_only =
" style=dotted"
;
58
printf(
"\"%p\" -> \"%p\" [arrowhead=none%s]\n"
, (*in), edge, order_only);
59
}
60
}
61
62
for
(vector<Node*>::iterator in = edge->
inputs_
.begin();
63
in != edge->
inputs_
.end(); ++in) {
64
AddTarget
(*in);
65
}
66
}
67
68
void
GraphViz::Start
() {
69
printf(
"digraph ninja {\n"
);
70
printf(
"rankdir=\"LR\"\n"
);
71
printf(
"node [fontsize=10, shape=box, height=0.25]\n"
);
72
printf(
"edge [fontsize=10]\n"
);
73
}
74
75
void
GraphViz::Finish
() {
76
printf(
"}\n"
);
77
}
Generated on Thu Jul 18 2013 20:51:41 for Ninja by
1.8.4