Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/guisupport/conflicttrc.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-1999 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * conflicttrc.cpp - Conflict trace display | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include "port.h" | |
11 | |
12 #include "arrays.h" | |
13 #include "assert.h" | |
14 #include "cd.h" | |
15 #include "conflictdc.h" | |
16 #include "conflicttrc.h" | |
17 #include "data.h" | |
18 #include "dc.h" | |
19 #include "items.h" | |
20 #include "nckwtr.h" | |
21 #include "p.h" | |
22 #include "q1a.h" | |
23 #include "q1glbl.h" | |
24 #include "rule.h" | |
25 #include "stexpdc.h" | |
26 #include "stacks.h" | |
27 #include "tracedc.h" | |
28 #include "ut.h" | |
29 #include "wm1.h" | |
30 #include "ws.h" | |
31 | |
32 //#define INCLUDE_LOGGING | |
33 #include "log.h" | |
34 | |
35 | |
36 //int *reduction_stack; | |
37 //int reduction_stack_depth; | |
38 | |
39 dc_ref new_item_stack_kernel(dc_ref d, tsd *isl) { | |
40 dc_ref window; | |
41 | |
42 check_tsd(isl); | |
43 return dc_ref(new rule_stack_dc(isl, d->des->c_loc_doc.y, d->head_title)); | |
44 } | |
45 | |
46 //class rule_stack_dc | |
47 | |
48 static int rule_stack_tabs[] = {4, 12, 0}; | |
49 | |
50 rule_stack_dc::rule_stack_dc(tsd *stack, unsigned ln, const AgString foot) | |
51 : dc("Rule Stack", foot) | |
52 , parser_stack(stack) | |
53 { | |
54 int k; | |
55 int sx, sn, fn, fx; | |
56 | |
57 k = stack->nt; | |
58 while (k--) { | |
59 xtxf(parser_stack, k, &sx, &sn, &fn, &fx); | |
60 if (ln == (unsigned) sx) { | |
61 break; | |
62 } | |
63 } | |
64 assert(k >= 0); | |
65 //des->c_size = cursor_bar_size; | |
66 des->d_size.y = parser_stack->nt; | |
67 tab_stops = rule_stack_tabs; | |
68 columnHeadTitle = "Level\tState\tRules"; | |
69 //getWidth(); | |
70 //manual_resize = 0; | |
71 //resize_window(); | |
72 des->c_loc_doc.y = parser_stack->nt-1; | |
73 //bound_cursor_ver(des); | |
74 //k = parser_stack->nt - 1 - k; | |
75 des->c_loc_doc.y = k; | |
76 //bound_cursor_ver(des); | |
77 } | |
78 | |
79 void rule_stack_dc::getLine(unsigned tln) const { | |
80 int sx, psx=0, sn, psn=0, fn, fx; | |
81 unsigned ln; | |
82 | |
83 LOGSECTION("rule_stack_dc::getLine"); | |
84 LOGV(tln); | |
85 ln = parser_stack->nt - tln - 1; | |
86 LOGV(ln); | |
87 if (ln < parser_stack->nt-1) { | |
88 xtx(parser_stack, ln+1, &psx, &psn, &fn, &fx); | |
89 } | |
90 xtx(parser_stack, ln, &sx, &sn, &fn, &fx); | |
91 LOGV(sx); | |
92 if (tln && sn == psn && sx == psx) { | |
93 sss("\t\t"); | |
94 } | |
95 else { | |
96 ssprintf("%2d\tS%03d:\t",sx,sn); | |
97 } | |
98 append_item(fn, fx); | |
99 return; | |
100 } | |
101 | |
102 | |
103 rule_stack_dc::item::item(tsd* stack, unsigned ln) { | |
104 LOGSECTION("rule_stack_dc::item::item"); | |
105 int sn; | |
106 int csd; | |
107 | |
108 LOGV(ln) LCV(stack->nt); | |
109 ln = stack->nt - 1 - ln; | |
110 LOGV(ln); | |
111 xtx(stack, ln, &csd, &sn, &rule, &index); | |
112 LOGV(sn) LCV(rule) LCV(index); | |
113 } | |
114 | |
115 rule_stack_dc::item rule_stack_dc::getItem(unsigned ln) const { | |
116 return item(parser_stack, ln); | |
117 } | |
118 | |
119 unsigned rule_stack_dc::state(unsigned ln) { | |
120 int csd; | |
121 int sn, fn, fx; | |
122 | |
123 ln = parser_stack->nt - 1 - ln; | |
124 xtx(parser_stack, ln, &csd, &sn, &fn, &fx); | |
125 return sn; | |
126 } | |
127 | |
128 unsigned rule_stack_dc::token(unsigned ln) { | |
129 item x = getItem(ln); | |
130 if (map_form_number[x.rule].length() <= x.index) { | |
131 return 0; | |
132 } | |
133 //return lstptr(map_form_number[x.rule], tokens)[x.index]; | |
134 return Rule(x.rule).token(x.index); | |
135 } | |
136 | |
137 void rule_stack_dc::synchCursor(unsigned ln) const { | |
138 LOGSECTION("rule_stack_dc::synchCursor"); | |
139 LOGV(ln); | |
140 set_rule_line(getItem(ln).rule); | |
141 LOGS("set_rule_line returned"); | |
142 } | |
143 | |
144 dc_ref rule_stack_dc::expansion_chain(unsigned ln) { | |
145 int csd; | |
146 int sn, fn, fx; | |
147 | |
148 ln = parser_stack->nt - 1 - ln; | |
149 xtx(parser_stack, ln, &csd, &sn, &fn, &fx); | |
150 return expansion_chain_window(sn, fn, fx); | |
151 } | |
152 | |
153 int rule_stack_dc::expansion_chain_ok(unsigned ln) { | |
154 LOGSECTION("rule_stack_dc::expansion_chain_ok"); | |
155 int csd; | |
156 int sn, fn, fx; | |
157 | |
158 ln = parser_stack->nt - 1 - ln; | |
159 xtx(parser_stack, ln, &csd, &sn, &fn, &fx); | |
160 LOGV(fn) LCV(fx); | |
161 return fn != 0 && fx == 0; | |
162 } | |
163 | |
164 int rule_stack_dc::rule_context_ok(unsigned ln) { | |
165 int csd; | |
166 int sn, fn, fx; | |
167 | |
168 ln = parser_stack->nt - 1 - ln; | |
169 xtx(parser_stack, ln, &csd, &sn, &fn, &fx); | |
170 return fn != 0; | |
171 } | |
172 | |
173 dc_ref rule_stack_dc::expansion_rules(unsigned ln) { | |
174 item x = getItem(ln); | |
175 return expand_specific_item(this, x.rule, x.index); | |
176 } | |
177 | |
178 int rule_stack_dc::expansion_rules_ok(unsigned ln) { | |
179 item x = getItem(ln); | |
180 return build_item_list_ok(token(ln)); | |
181 } | |
182 | |
183 dc_ref rule_stack_dc::state_expansion(unsigned ln) { | |
184 return state_expansion_window(state(ln)); | |
185 } | |
186 | |
187 int rule_stack_dc::keywords_ok(unsigned ln) { | |
188 return keywords_window_ok(state(ln)); | |
189 } | |
190 | |
191 dc_ref rule_stack_dc::keywords(unsigned ln) { | |
192 return keywords_window(state(ln)); | |
193 } | |
194 | |
195 int rule_stack_dc::productions_ok(unsigned ln) { | |
196 return productions_window_ok(token(ln)); | |
197 } | |
198 | |
199 dc_ref rule_stack_dc::productions(unsigned ln) { | |
200 return productions_window(token(ln)); | |
201 } | |
202 | |
203 dc_ref rule_stack_dc::rule_context(unsigned ln) { | |
204 item x = getItem(ln); | |
205 return rule_context_window(x.rule); | |
206 } | |
207 | |
208 int rule_stack_dc::set_elements_ok(unsigned ln) { | |
209 return token_set_window_ok(token(ln)); | |
210 } | |
211 | |
212 dc_ref rule_stack_dc::set_elements(unsigned ln) { | |
213 return token_set_window(token(ln)); | |
214 } | |
215 | |
216 dc_ref rule_stack_dc::state_definition(unsigned ln) { | |
217 return conflict_state_window(state(ln)); | |
218 } | |
219 | |
220 int rule_stack_dc::usage_ok(unsigned ln) { | |
221 return token_usage_window_ok(token(ln)); | |
222 } | |
223 | |
224 dc_ref rule_stack_dc::usage(unsigned ln) { | |
225 return token_usage_window(token(ln)); | |
226 } | |
227 | |
228 dc_ref problem_states_window(int sn, int fn, int fx, int ct) { | |
229 int cfn; | |
230 unsigned *list; | |
231 dc_ref new_window; | |
232 tsd *table; | |
233 int i, ns; | |
234 | |
235 if (fx < map_form_number[fn].length()) { | |
236 return NULL; | |
237 } | |
238 AgString foot = AgString::format("S%03d:R%03d:T%03d", sn, fn, ct); | |
239 cfn = get_reduction_states(sn, fn, fx); | |
240 list = lstptr(map_completed_form[cfn], reduction_states); | |
241 ns = map_completed_form[cfn].n_reduction_states; | |
242 iws(); | |
243 for (i = 0; i < ns; i++) { | |
244 if (x2d(list[i], ct)) { | |
245 aws(list[i]); | |
246 } | |
247 } | |
248 table = build_states_table((unsigned *) list_base, tis()); | |
249 rws(); | |
250 new_window = new state_list_dc("Problem States", table, foot); | |
251 return new_window; | |
252 } | |
253 | |
254 dc_ref build_conflict_trace(int s, int t, int f) { | |
255 LOGSECTION("build_conflict_trace"); | |
256 tsd *stack; | |
257 dc_ref new_window; | |
258 analyze_conflict(s, t, f, 0); | |
259 stack = make_stored_trace(&new_conflict_stack[0], | |
260 new_conflict_stack_depth, conflict_token); | |
261 new_window = new trace_window_dc("Conflict Trace", stack, s, t, f); | |
262 delete_tsd(stack); | |
263 return new_window; | |
264 } | |
265 | |
266 | |
267 dc_ref build_red_trace(int s, int t, int f) { | |
268 dc_ref window; | |
269 tsd *stack; | |
270 stack = make_stored_trace(&new_reduction_stack[0], | |
271 new_reduction_stack_depth, 0); | |
272 window = dc_ref(new trace_window_dc("Reduction Trace", stack, s, t, f)); | |
273 delete_tsd(stack); | |
274 return window; | |
275 } | |
276 | |
277 dc_ref conflict_red_trace(int s, int t, int f) { | |
278 dc_ref new_window; | |
279 | |
280 analyze_conflict(s, t, f, 0); | |
281 new_window = build_red_trace(s, t, f); | |
282 return new_window; | |
283 } | |
284 | |
285 | |
286 dc_ref set_up_stack_window(AgString name) { | |
287 tsd *stack; | |
288 dc_ref window; | |
289 | |
290 stack = init_tsd(2); | |
291 at(stack, 0, 0); | |
292 | |
293 window = dc_ref(new trace_window_dc(name, stack)); | |
294 delete_tsd(stack); | |
295 return window; | |
296 } | |
297 | |
298 tsd *build_et(FILE *f) { | |
299 tsd *et = init_tsd(2); | |
300 int s1, s2, tn; | |
301 int ns; | |
302 | |
303 int flag = 0 != fscanf(f, "%d", &ns); | |
304 flag &= 0 != fscanf(f, "%d", &s1); | |
305 | |
306 while (flag && ns--) { | |
307 flag &= 0 != fscanf(f,"%d", &s2); | |
308 if (!flag) { | |
309 break; | |
310 } | |
311 | |
312 const unsigned *goto_list; | |
313 int n = find_gotos(s1, &goto_list); | |
314 int found = 0; | |
315 while (n) { | |
316 //unsigned t = *goto_list++; | |
317 goto_list++; | |
318 unsigned s = *goto_list++; | |
319 if (s == s2) { | |
320 found = 1; | |
321 break; | |
322 } | |
323 n--; | |
324 } | |
325 flag &= found; | |
326 if (!flag) { | |
327 break; | |
328 } | |
329 at(et, s1, map_state_number[s2].char_token); | |
330 s1 = s2; | |
331 } | |
332 flag &= 0 != fscanf(f, "%d", &tn); | |
333 if (!flag) { | |
334 delete_tsd(et); | |
335 return 0; | |
336 } | |
337 at(et, s1, tn); | |
338 return et; | |
339 } | |
340 | |
341 dc_ref build_et_window(void) { | |
342 LOGSECTION("build_et_window"); | |
343 LOGV(etr_file_name.pointer()); | |
344 LOGV((int) &etr_file_name); | |
345 | |
346 if (!etr_file_name.exists()) { | |
347 return NULL; | |
348 } | |
349 | |
350 FILE *f = fopen(etr_file_name.pointer(), "r"); | |
351 tsd *et = build_et(f); | |
352 fclose(f); | |
353 if (et == 0) { | |
354 return dc_ref(); | |
355 } | |
356 | |
357 dc_ref window; | |
358 window = dc_ref(new trace_window_dc("Error Trace", et)); | |
359 window->foot_title = etr_file_name; | |
360 delete_tsd(et); | |
361 | |
362 return window; | |
363 } | |
364 |