]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
1 /* Output a VCG description on generated parser, for Bison,
2 Copyright 2001 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 #include "conflicts.h"
33 #include "print_graph.h"
39 /* Return an unambiguous printable representated, allocated in slot 0,
40 for NAME, suitable for C strings. */
42 quote (char const *name
)
44 return quotearg_n_style (0, escape_quoting_style
, name
);
47 /* This part will construct the label of nodes. */
49 print_core (int state
)
58 statep
= state_table
[state
];
64 obstack_sgrow (&graph_obstack
, "\t\tlabel:\t\"");
66 for (i
= 0; i
< k
; i
++)
69 obstack_sgrow (&graph_obstack
, "\\n");
71 sp1
= sp
= ritem
+ statep
->items
[i
];
78 obstack_fgrow1 (&graph_obstack
, "%d: ", rule
);
79 obstack_fgrow1 (&graph_obstack
, " %s -> ", quote (tags
[rlhs
[rule
]]));
81 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
82 obstack_fgrow1 (&graph_obstack
, "%s ", quote (tags
[*sp
]));
84 obstack_1grow (&graph_obstack
, '.');
87 obstack_fgrow1 (&graph_obstack
, " %s", quote (tags
[*sp
++]));
90 obstack_sgrow (&graph_obstack
, "\"\n");
94 print_actions (int state
, node_t
*node
)
104 static char buff
[10];
107 shiftp
= shift_table
[state
];
108 redp
= reduction_table
[state
];
109 errp
= err_table
[state
];
111 if (!shiftp
&& !redp
)
114 if (final_state
== state
)
115 fprintf (f
, " $default\taccept\n");
117 fprintf (f
, " NO ACTIONS\n");
126 for (i
= 0; i
< k
; i
++)
128 if (!shiftp
->shifts
[i
])
130 state1
= shiftp
->shifts
[i
];
131 symbol
= accessing_symbol
[state1
];
140 edge
.type
= back_edge
;
141 open_edge (&edge
, &graph_obstack
);
142 edge
.sourcename
= node
->title
;
143 sprintf (buff
, "%d", state1
);
144 edge
.targetname
= buff
;
145 edge
.color
= (symbol
== 0) ? blue
: red
;
146 /* FIXME: Be aware that quote uses static memory. The string
147 must be output immediately (which is the case here). */
148 edge
.label
= tags
[symbol
] ? quote (tags
[symbol
]) : NULL
;
149 output_edge (&edge
, &graph_obstack
);
150 close_edge (&graph_obstack
);
166 for (j
= 0; j
< nerrs
; j
++)
170 symbol
= errp
->errs
[j
];
174 if (consistent
[state
] && redp
)
176 rule
= redp
->rules
[0];
184 if (!shiftp
->shifts
[i
])
186 state1
= shiftp
->shifts
[i
];
187 symbol
= accessing_symbol
[state1
];
190 open_edge (&edge
, &graph_obstack
);
191 edge
.sourcename
= node
->title
;
192 sprintf (buff
, "%d", state1
);
193 edge
.targetname
= buff
;
195 edge
.label
= tags
[symbol
] ? quote (tags
[symbol
]) : NULL
;
196 output_edge (&edge
, &graph_obstack
);
197 close_edge (&graph_obstack
);
203 print_state (int state
)
205 static char name
[10];
209 open_node (&graph_obstack
);
211 sprintf (name
, "%d", state
);
213 output_node (&node
, &graph_obstack
);
215 print_core (state
); /* node label */
217 close_node (&graph_obstack
);
219 print_actions (state
, &node
); /* edges */
232 /* graph.smanhattan_edges = yes;
233 graph.manhattan_edges = yes; */
235 graph
.display_edge_labels
= yes
;
236 graph
.layoutalgorithm
= 0;
238 graph
.port_sharing
= no
;
239 graph
.finetuning
= yes
;
240 graph
.straight_phase
= yes
;
241 graph
.priority_phase
= yes
;
244 graph
.crossing_weight
= median
;
246 /* Output graph options. */
247 open_graph (&graph_obstack
);
248 output_graph (&graph
, &graph_obstack
);
250 for (i
= 0; i
< nstates
; i
++)
251 /* Output nodes & edges. */
255 close_graph (&graph
, &graph_obstack
);