]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
d3b9b8ce5875b79ab15678c443738ccf7ec45dc0
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 /* This part will construct the label of nodes. */
41 print_core (int state
)
50 statep
= state_table
[state
];
56 obstack_sgrow (&graph_obstack
, "\t\tlabel:\t\"");
58 for (i
= 0; i
< k
; i
++)
61 obstack_sgrow (&graph_obstack
, "\\n");
63 sp1
= sp
= ritem
+ statep
->items
[i
];
70 obstack_fgrow1 (&graph_obstack
, _("%d: "), rule
);
71 obstack_fgrow1 (&graph_obstack
, " %s -> ", quote (tags
[rlhs
[rule
]]));
73 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
74 obstack_fgrow1 (&graph_obstack
, "%s ", quote (tags
[*sp
]));
76 obstack_1grow (&graph_obstack
, '.');
79 obstack_fgrow1 (&graph_obstack
, " %s", quote (tags
[*sp
++]));
82 obstack_sgrow (&graph_obstack
, "\"\n");
86 print_actions (int state
, node_t
*node
)
99 shiftp
= shift_table
[state
];
100 redp
= reduction_table
[state
];
101 errp
= err_table
[state
];
103 if (!shiftp
&& !redp
)
106 if (final_state
== state
)
107 fprintf (f
, " $default\taccept\n");
109 fprintf (f
, " NO ACTIONS\n");
118 for (i
= 0; i
< k
; i
++)
120 if (!shiftp
->shifts
[i
])
122 state1
= shiftp
->shifts
[i
];
123 symbol
= accessing_symbol
[state1
];
132 edge
.type
= back_edge
;
133 open_edge (&edge
, &graph_obstack
);
134 edge
.sourcename
= node
->title
;
135 sprintf (buff
, "%d", state1
);
136 edge
.targetname
= buff
;
137 edge
.color
= (symbol
== 0) ? blue
: red
;
138 /* FIXME: Be aware that quote uses static memory. The string
139 must be output immediately (which is the case here). */
140 edge
.label
= tags
[symbol
] ? quote (tags
[symbol
]) : NULL
;
141 output_edge (&edge
, &graph_obstack
);
142 close_edge (&graph_obstack
);
158 for (j
= 0; j
< nerrs
; j
++)
162 symbol
= errp
->errs
[j
];
166 if (consistent
[state
] && redp
)
168 rule
= redp
->rules
[0];
176 if (!shiftp
->shifts
[i
])
178 state1
= shiftp
->shifts
[i
];
179 symbol
= accessing_symbol
[state1
];
182 open_edge (&edge
, &graph_obstack
);
183 edge
.sourcename
= node
->title
;
184 sprintf (buff
, "%d", state1
);
185 edge
.targetname
= buff
;
187 edge
.label
= tags
[symbol
] ? quote (tags
[symbol
]) : NULL
;
188 output_edge (&edge
, &graph_obstack
);
189 close_edge (&graph_obstack
);
195 print_state (int state
)
197 static char name
[10];
201 open_node (&graph_obstack
);
203 sprintf (name
, "%d", state
);
205 output_node (&node
, &graph_obstack
);
207 print_core (state
); /* node label */
209 close_node (&graph_obstack
);
211 print_actions (state
, &node
); /* edges */
224 /* graph.smanhattan_edges = yes;
225 graph.manhattan_edges = yes; */
227 graph
.display_edge_labels
= yes
;
228 graph
.layoutalgorithm
= 0;
230 graph
.port_sharing
= no
;
231 graph
.finetuning
= yes
;
232 graph
.straight_phase
= yes
;
233 graph
.priority_phase
= yes
;
236 graph
.crossing_weight
= median
;
238 /* Output graph options. */
239 open_graph (&graph_obstack
);
240 output_graph (&graph
, &graph_obstack
);
242 for (i
= 0; i
< nstates
; i
++)
243 /* Output nodes & edges. */
247 close_graph (&graph
, &graph_obstack
);