-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug_Walker.c
670 lines (532 loc) · 21.7 KB
/
Debug_Walker.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
/*
* Debug_Node_Walker.c
*
* Created on: Dec 25, 2017
* Author: Josip
*/
#include "System.h"
#include "Lexer.h"
#include "AST.h"
#include "Debug_Walker.h"
#define MAX_DBG_TREE_DEPTH 30
struct s_debug_walker_statistics
{
uint8_t Level;
struct s_vertical_line
{
uint8_t Levels[MAX_DBG_TREE_DEPTH];
uint8_t Idx;
} VerLine;
struct s_cur_node_info
{
e_ast_node_type Type;
void* Ptr;
} Current_Node;
} Debug_Walker_Statistics;
void Debug_Walker_Printout()
{
static uint8_t LastLevel = 0;
uint8_t Idx;
uint8_t Idx_2;
System_Print("\t"); /* Remove \t to remove margin */
/* Check if a new line is needed */
if(Debug_Walker_Statistics.Level < LastLevel)
{
for(Idx = 0; Idx < Debug_Walker_Statistics.Level-1; Idx++)
{
/* Check if a vertical line shall be drawn */
for(Idx_2 = 0; Idx_2 < Debug_Walker_Statistics.VerLine.Idx; Idx_2++)
{
if(Debug_Walker_Statistics.VerLine.Levels[Idx_2] == Idx)
{
/* Vertical line shall be drawn */
System_Print("| ");
break;
}
}
if(Idx_2 == Debug_Walker_Statistics.VerLine.Idx)
{
System_Print(" ");
}
}
System_Print("|\n\t"); /* Remove \t to remove margin */
}
LastLevel = Debug_Walker_Statistics.Level;
/* Draw current level */
if(Debug_Walker_Statistics.Current_Node.Type != PROGRAM)
{
for(Idx = 0; Idx < Debug_Walker_Statistics.Level-1; Idx++)
{
/* Check if a vertical line shall be drawn */
for(Idx_2 = 0; Idx_2 < Debug_Walker_Statistics.VerLine.Idx; Idx_2++)
{
if(Debug_Walker_Statistics.VerLine.Levels[Idx_2] == Idx)
{
/* Vertical line shall be drawn */
System_Print("| ");
break;
}
}
if(Idx_2 == Debug_Walker_Statistics.VerLine.Idx)
{
System_Print(" ");
}
}
System_Print("|____");
}
switch(Debug_Walker_Statistics.Current_Node.Type)
{
case PROGRAM:
System_Print("PROGRAM\n");
break;
case VAR_DECL:
System_Print("VAR_DECL\n");
break;
case TYPE:
System_Print("TYPE -> %s\n", ((s_ast_type*)Debug_Walker_Statistics.Current_Node.Ptr)->token.value.string);
break;
case VAR:
System_Print("VAR -> %s\n", ((s_ast_variable*)Debug_Walker_Statistics.Current_Node.Ptr)->token.value.string);
break;
case COMPOUND_MAIN:
System_Print("COMPOUND_MAIN\n");
break;
case COMPOUND:
System_Print("COMPOUND -> %s\n", ((s_ast_compound*)Debug_Walker_Statistics.Current_Node.Ptr)->name.value.string);
break;
case COMPOUND_CALL:
System_Print("COMPOUND_CALL -> %s\n", ((s_ast_compoundStatementCall*)Debug_Walker_Statistics.Current_Node.Ptr)->cmpStatementName.value.string);
break;
case ARGUMENT:
System_Print("ARGUMENT\n");
break;
case COMPOUND_RETURN:
System_Print("COMPOUND_RETURN\n");
break;
case RETURN_STATEMENT:
System_Print("RETURN\n");
break;
case FOR_STATEMENT:
System_Print("FOR_STATEMENT\n");
break;
case BREAK_STATEMENT:
System_Print("BREAK_STATEMENT\n");
break;
case IF_STATEMENT:
System_Print("IF_STATEMENT\n");
break;
case IF_CONDITION:
System_Print("IF_CONDITION\n");
break;
case ELSE_CONDITION:
System_Print("ELSE_CONDITION\n");
break;
case PARAMETER:
System_Print("PARAMETER\n");
break;
case ASSIGNMENT:
System_Print("ASSIGNMENT\n");
break;
case BINARY_OP:
System_Print("BINARY_OP -> %s\n", ((s_ast_binary*)Debug_Walker_Statistics.Current_Node.Ptr)->token.value.string);
break;
case UNARY_OP:
System_Print("UNARY_OP -> %s\n", ((s_ast_unary*)Debug_Walker_Statistics.Current_Node.Ptr)->token.value.string);
break;
case NUM:
System_Print("NUM -> %d\n", ((s_ast_num*)Debug_Walker_Statistics.Current_Node.Ptr)->token.value.integer_const);
break;
case NO_OP:
/* Not Implemented Yet */
break;
case TEST_WAIT_TIMEOUT:
System_Print("TEST_WAIT_TIMEOUT\n");
break;
case WHILE_STATEMENT:
System_Print("WHILE_STATEMENT\n");
break;
}
}
void Debug_Walker_Visit( void* NodePtr )
{
void* TempNodePtr;
/* Increment Level */
Debug_Walker_Statistics.Level++;
/* Update Statistics */
Debug_Walker_Statistics.Current_Node.Type = ((s_ast_node_info*)NodePtr)->type;
Debug_Walker_Statistics.Current_Node.Ptr = NodePtr;
/* Determine Node Type */
switch( ((s_ast_node_info*)NodePtr)->type )
{
case PROGRAM:
/* Debug Printout */
Debug_Walker_Printout( PROGRAM );
/* Add Vertical Line */
if(((s_ast_program*)NodePtr)->global_var_decl_link.var_declaration != NULL ||
((s_ast_program*)NodePtr)->compound_link.compound_statement != NULL )
{
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
}
/* Global Variable Declaration Visit */
TempNodePtr = (void*)&((s_ast_program*)NodePtr)->global_var_decl_link;
while( TempNodePtr != NULL && ((struct global_var_decl_link*)TempNodePtr)->var_declaration != NULL )
{
Debug_Walker_Visit( ((struct global_var_decl_link*)TempNodePtr)->var_declaration );
TempNodePtr = (void*)((struct global_var_decl_link*)TempNodePtr)->next_var_decl_link;
}
/* Compound Statement Visit */
TempNodePtr = (void*)&((s_ast_program*)NodePtr)->compound_link;
while( TempNodePtr != NULL && ((struct compound_link*)TempNodePtr)->compound_statement != NULL )
{
Debug_Walker_Visit( ((struct compound_link*)TempNodePtr)->compound_statement );
TempNodePtr = (void*)((struct compound_link*)TempNodePtr)->next_compound_link;
}
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
/* Visit Compound Main */
Debug_Walker_Visit( ((s_ast_program*)NodePtr)->compound_main );
break;
case VAR_DECL:
/* Debug Printout */
Debug_Walker_Printout( VAR_DECL );
/* Type Node Visit */
Debug_Walker_Visit( ((s_ast_var_declaration*)NodePtr)->type );
/* Variable Node Visits */
TempNodePtr = (void*)&((s_ast_var_declaration*)NodePtr)->var_link;
while( TempNodePtr != NULL && ((struct var_link*)TempNodePtr)->variable != NULL )
{
Debug_Walker_Visit( ((struct var_link*)TempNodePtr)->variable );
TempNodePtr = (void*)((struct var_link*)TempNodePtr)->next_var_link;
}
break;
case COMPOUND_MAIN:
/* Debug Printout */
Debug_Walker_Printout( COMPOUND_MAIN );
/* Add Vertical Line */
if(((s_ast_compound_main*)NodePtr)->main_var_decl_link.var_declaration != NULL ||
((s_ast_compound_main*)NodePtr)->statement_link.statement != NULL )
{
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
}
/* Main Variable Declaration Visit */
TempNodePtr = (void*)&((s_ast_compound_main*)NodePtr)->main_var_decl_link;
while( TempNodePtr != NULL && ((struct main_var_decl_link*)TempNodePtr)->var_declaration != NULL )
{
Debug_Walker_Visit( ((struct main_var_decl_link*)TempNodePtr)->var_declaration );
TempNodePtr = (void*)((struct main_var_decl_link*)TempNodePtr)->next_var_decl_link;
}
/* Statement Node Visit */
TempNodePtr = (void*)&((s_ast_compound_main*)NodePtr)->statement_link;
while( TempNodePtr != NULL && ((struct s_ast_statement_link*)TempNodePtr)->statement != NULL )
{
/* Check if this is the last statement */
if(((struct s_ast_statement_link*)TempNodePtr)->next_statement_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
Debug_Walker_Visit( ((struct s_ast_statement_link*)TempNodePtr)->statement );
TempNodePtr = (void*)((struct s_ast_statement_link*)TempNodePtr)->next_statement_link;
}
break;
case COMPOUND:
/* Debug Printout */
Debug_Walker_Printout( COMPOUND );
/* Add Vertical Line */
if(((s_ast_compound*)NodePtr)->parameter_link.parameter != NULL ||
((s_ast_compound*)NodePtr)->cmp_var_decl_link.var_declaration != NULL ||
((s_ast_compound*)NodePtr)->statement_link.statement != NULL)
{
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
}
/* Compound Return Type Visit */
if( ((s_ast_compound*)NodePtr)->return_type != NULL )
{
Debug_Walker_Visit( ((s_ast_compound*)NodePtr)->return_type );
}
/* Parameter Visit */
TempNodePtr = (void*)&((s_ast_compound*)NodePtr)->parameter_link;
while( TempNodePtr != NULL && ((struct parameter_link*)TempNodePtr)->parameter != NULL )
{
Debug_Walker_Visit( ((struct parameter_link*)TempNodePtr)->parameter );
TempNodePtr = (void*)((struct parameter_link*)TempNodePtr)->next_parameter_link;
}
/* Compound Variable Declaration Visit */
TempNodePtr = (void*)&((s_ast_compound*)NodePtr)->cmp_var_decl_link;
while( TempNodePtr != NULL && ((struct cmp_var_decl_link*)TempNodePtr)->var_declaration != NULL )
{
Debug_Walker_Visit( ((struct cmp_var_decl_link*)TempNodePtr)->var_declaration );
TempNodePtr = (void*)((struct cmp_var_decl_link*)TempNodePtr)->next_var_decl_link;
}
/* Statement Node Visit */
TempNodePtr = (void*)&((s_ast_compound*)NodePtr)->statement_link;
while( TempNodePtr != NULL && ((struct s_ast_statement_link*)TempNodePtr)->statement != NULL )
{
/* Check if this is the last statement */
if(((struct s_ast_statement_link*)TempNodePtr)->next_statement_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
Debug_Walker_Visit( ((struct s_ast_statement_link*)TempNodePtr)->statement );
TempNodePtr = (void*)((struct s_ast_statement_link*)TempNodePtr)->next_statement_link;
}
break;
case COMPOUND_CALL:
/* Debug Printout */
Debug_Walker_Printout( COMPOUND_CALL );
/* Add Vertical Line */
if(((s_ast_compoundStatementCall*)NodePtr)->argument_link.argument != NULL)
{
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
}
/* Compound Call Argument Visit */
TempNodePtr = (void*)&((s_ast_compoundStatementCall*)NodePtr)->argument_link;
while( TempNodePtr != NULL && ((struct argument_link*)TempNodePtr)->argument != NULL )
{
/* Check if this is the last argument */
if(((struct argument_link*)TempNodePtr)->next_argument_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
Debug_Walker_Visit( ((struct argument_link*)TempNodePtr)->argument );
TempNodePtr = (void*)((struct argument_link*)TempNodePtr)->next_argument_link;
}
break;
case ARGUMENT:
/* Debug Printout */
Debug_Walker_Printout( ARGUMENT );
/* Visit Argument Nodes */
Debug_Walker_Visit( ((s_ast_compoundCallArg*)NodePtr)->argument );
break;
case COMPOUND_RETURN:
/* Debug Printout */
Debug_Walker_Printout( COMPOUND_RETURN );
/* Type Visit */
Debug_Walker_Visit( ((s_ast_compound_return*)NodePtr)->type );
break;
case RETURN_STATEMENT:
/* Debug Printout */
Debug_Walker_Printout( RETURN );
/* Visit Return Value */
if( ((s_ast_compoundReturnStatement*)NodePtr)->value != NULL )
{
Debug_Walker_Visit( ((s_ast_compoundReturnStatement*)NodePtr)->value );
}
break;
case FOR_STATEMENT:
/* Debug Printout */
Debug_Walker_Printout( FOR_STATEMENT );
/* Add Vertical Line */
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
/* Visit Init Statement */
if( ((s_ast_forStatement*)NodePtr)->initStatement != NULL )
{
Debug_Walker_Visit( ((s_ast_forStatement*)NodePtr)->initStatement );
}
/* Visit Post Statement */
if( ((s_ast_forStatement*)NodePtr)->postStatement != NULL )
{
Debug_Walker_Visit( ((s_ast_forStatement*)NodePtr)->postStatement );
}
/* Visit Condition Statement */
if( ((s_ast_forStatement*)NodePtr)->condition != NULL )
{
Debug_Walker_Visit( ((s_ast_forStatement*)NodePtr)->condition );
}
/* Visit Statements */
TempNodePtr = (void*)&((s_ast_forStatement*)NodePtr)->statement_link;
while( TempNodePtr != NULL && ((struct s_ast_statement_link*)TempNodePtr)->statement != NULL )
{
/* Check if this is the last argument */
if(((struct s_ast_statement_link*)TempNodePtr)->next_statement_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
Debug_Walker_Visit( ((struct s_ast_statement_link*)TempNodePtr)->statement );
TempNodePtr = (void*)((struct s_ast_statement_link*)TempNodePtr)->next_statement_link;
}
break;
case BREAK_STATEMENT:
/* Debug Printout */
Debug_Walker_Printout( BREAK_STATEMENT );
break;
case IF_STATEMENT:
/* Debug Printout */
Debug_Walker_Printout( IF_STATEMENT );
/* Add Vertical Line */
if(((s_ast_ifStatement*)NodePtr)->if_condition_link.ifCondition != NULL)
{
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
}
/* Visit If Conditions */
TempNodePtr = (void*)&((s_ast_ifStatement*)NodePtr)->if_condition_link;
while( TempNodePtr != NULL && ((struct if_condition_link*)TempNodePtr)->ifCondition != NULL )
{
if(((s_ast_ifStatement*)NodePtr)->elseCondition == NULL)
{
/* Check if this is the last argument */
if(((struct if_condition_link*)TempNodePtr)->next_ifCondition_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
}
Debug_Walker_Visit( ((struct if_condition_link*)TempNodePtr)->ifCondition );
TempNodePtr = (void*)((struct if_condition_link*)TempNodePtr)->next_ifCondition_link;
}
/* Visit Else Condition */
if(((s_ast_ifStatement*)NodePtr)->elseCondition != NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
Debug_Walker_Visit( ((s_ast_ifStatement*)NodePtr)->elseCondition );
}
break;
case IF_CONDITION:
/* Debug Printout */
Debug_Walker_Printout( IF_CONDITION );
/* Add Vertical Line */
if(((s_ast_ifCondition*)NodePtr)->statement_link.statement != NULL)
{
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
}
/* Visit Condition */
Debug_Walker_Visit( ((s_ast_ifCondition*)NodePtr)->condition );
/* Visit Statements */
TempNodePtr = (void*)&((s_ast_ifCondition*)NodePtr)->statement_link;
while( TempNodePtr != NULL && ((struct s_ast_statement_link*)TempNodePtr)->statement != NULL )
{
/* Check if this is the last argument */
if(((struct s_ast_statement_link*)TempNodePtr)->next_statement_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
Debug_Walker_Visit( ((struct s_ast_statement_link*)TempNodePtr)->statement );
TempNodePtr = (void*)((struct s_ast_statement_link*)TempNodePtr)->next_statement_link;
}
break;
case ELSE_CONDITION:
/* Debug Printout */
Debug_Walker_Printout( ELSE_CONDITION );
/* Add Vertical Line */
if(((s_ast_elseCodnition*)NodePtr)->statement_link.statement != NULL)
{
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
}
/* Visit Statements */
TempNodePtr = (void*)&((s_ast_elseCodnition*)NodePtr)->statement_link;
while( TempNodePtr != NULL && ((struct s_ast_statement_link*)TempNodePtr)->statement != NULL )
{
/* Check if this is the last argument */
if(((struct s_ast_statement_link*)TempNodePtr)->next_statement_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
Debug_Walker_Visit( ((struct s_ast_statement_link*)TempNodePtr)->statement );
TempNodePtr = (void*)((struct s_ast_statement_link*)TempNodePtr)->next_statement_link;
}
break;
case PARAMETER:
/* Debug Printout */
Debug_Walker_Printout( PARAMETER );
/* Type Visit */
Debug_Walker_Visit( ((s_ast_parameter*)NodePtr)->type );
/* Variable Visit */
Debug_Walker_Visit( ((s_ast_parameter*)NodePtr)->variable );
break;
case ASSIGNMENT:
/* Debug Printout */
Debug_Walker_Printout( ASSIGNMENT );
/* Variable (Left Operand) Visit */
Debug_Walker_Visit( ((s_ast_assignment*)NodePtr)->variable );
/* Expression Visit */
Debug_Walker_Visit( ((s_ast_assignment*)NodePtr)->expression );
break;
case BINARY_OP:
/* Debug Printout */
Debug_Walker_Printout( BINARY_OP );
/* Add Vertical Line */
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
/* Visit Left Operand */
Debug_Walker_Visit( ((s_ast_binary*)NodePtr)->leftOperand );
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
/* Visit Right Operand */
Debug_Walker_Visit( ((s_ast_binary*)NodePtr)->rightOperand );
break;
case UNARY_OP:
/* Debug Printout */
Debug_Walker_Printout( UNARY_OP );
/* Visit Operand */
Debug_Walker_Visit( ((s_ast_unary*)NodePtr)->operand );
break;
case NUM:
/* Debug Printout */
Debug_Walker_Printout( UNARY_OP );
break;
case TYPE:
/* Debug Printout */
Debug_Walker_Printout( TYPE );
break;
case VAR:
/* Debug Printout */
Debug_Walker_Printout( VAR );
break;
case TEST_WAIT_TIMEOUT:
/* Debug Printout */
Debug_Walker_Printout( TEST_WAIT_TIMEOUT );
/* Visit Value */
Debug_Walker_Visit( ((s_ast_testWaitForTimeout*)NodePtr)->value );
break;
case WHILE_STATEMENT:
/* Debug Printout */
Debug_Walker_Printout( TEST_WAIT_TIMEOUT );
/* Add Vertical Line */
Debug_Walker_Statistics.VerLine.Levels[Debug_Walker_Statistics.VerLine.Idx] = Debug_Walker_Statistics.Level;
Debug_Walker_Statistics.VerLine.Idx++;
/* Visit Value */
Debug_Walker_Visit( ((s_ast_whileStatement*)NodePtr)->condition );
/* Visit Statements */
TempNodePtr = (void*)&((s_ast_whileStatement*)NodePtr)->statement_link;
while( TempNodePtr != NULL && ((struct s_ast_statement_link*)TempNodePtr)->statement != NULL )
{
/* Check if this is the last argument */
if(((struct s_ast_statement_link*)TempNodePtr)->next_statement_link == NULL)
{
/* Remove Vertical Line */
Debug_Walker_Statistics.VerLine.Idx--;
}
Debug_Walker_Visit( ((struct s_ast_statement_link*)TempNodePtr)->statement );
TempNodePtr = (void*)((struct s_ast_statement_link*)TempNodePtr)->next_statement_link;
}
break;
default:
printf("Node Type Unknown: %d\n", ((s_ast_node_info*)NodePtr)->type);
exit(1);
break;
}
/* Decrement Level */
Debug_Walker_Statistics.Level--;
}
void Debug_Walker_Walkthrought( s_ast_program* ProgramNode )
{
/* Init Statistics */
Debug_Walker_Statistics.Level = 255; /* Will overflow to 0 on first visit */
Debug_Walker_Statistics.Current_Node.Type = PROGRAM;
System_Print("Abstract Syntax Tree:\n \n");
Debug_Walker_Visit( ProgramNode );
}