This repository has been archived by the owner on Oct 18, 2020. It is now read-only.
/
gwpp.c
724 lines (674 loc) · 19 KB
/
gwpp.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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "defs.h"
#include "map.h"
#include "absyn.h"
#include "hash.h"
#include "scanner.h"
#define TABLEN 2
extern m_str op2str(Operator);
typedef struct {
const m_str name;
FILE* file;
m_uint line, pos;
m_uint indent;
m_bool skip;
m_bool nonl;
m_bool comment;
} Linter;
ANN static void lint_type_decl(Linter* linter, Type_Decl* type);
ANN static void lint_exp(Linter* linter, Exp exp);
ANN static void lint_stmt(Linter* linter, Stmt stmt);
ANN static void lint_stmt_if(Linter* linter, Stmt_If stmt);
ANN static void lint_stmt_list(Linter* linter, Stmt_List list);
ANN static void lint_class_def(Linter* linter, Class_Def class_def);
ANN static void lint_print(Linter* linter, const char* fmt, ...) {
va_list arg;
va_start(arg, fmt);
vfprintf(linter->file, fmt, arg);
va_end(arg);
}
ANN static void lint_nl(Linter* linter) {
const m_uint pos = linter->pos;
fprintf(linter->file, "\n");
linter->pos = ftell(linter->file);
if((m_int)linter->pos - (m_int)pos > 80)
fprintf(stderr, "'\033[31;1m%s\033[0m' long line %" INT_F "%" INT_F " %" INT_F "\n",
linter->name, linter->line, linter->pos, pos);
linter->line++;
}
ANN static void lint_indent(Linter* linter) {
if(linter->skip) {
lint_print(linter, " ");
linter->skip--;
return;
}
for(m_uint i = 0; i < linter->indent; i++)
for(m_uint j = 0; j < TABLEN; j++)
lint_print(linter, " ");
}
ANN static void lint_id_list(Linter* linter, ID_List list) {
const m_bool next = list->next ? 1 : 0;
if(next)
lint_print(linter, "<");
do {
lint_print(linter, s_name(list->xid));
if(list->next)
lint_print(linter, ".");
} while((list = list->next));
if(next)
lint_print(linter, ">");
}
ANN static void lint_array(Linter* linter, Array_Sub array) {
Exp exp = array->exp;
for(m_uint i = 0; i < array->depth; i++) {
Exp tmp = exp ? exp->next : NULL;
if(exp)
exp->next = NULL;
lint_print(linter, "[");
if(exp)
lint_exp(linter, exp);
lint_print(linter, "]");
if(exp) {
exp->next = tmp;
exp = tmp;
}
}
}
ANN static void lint_array_lit(Linter* linter, Array_Sub array) {
Exp exp = array->exp;
for(m_uint i = 0; i < array->depth; i++) {
Exp tmp = exp ? exp->next : NULL;
lint_print(linter, "[");
if(exp) {
if(exp->exp_type == ae_exp_primary &&
exp->d.exp_primary.primary_type == ae_primary_array)
lint_print(linter, " ");
lint_exp(linter, exp);
if(exp->exp_type == ae_exp_primary &&
exp->d.exp_primary.primary_type == ae_primary_array)
lint_print(linter, " ");
}
lint_print(linter, "]");
if(exp) {
exp->next = tmp;
}
}
}
ANN static void lint_type_list(Linter* linter, Type_List list) {
lint_print(linter, "“");
do {
lint_type_decl(linter, list->td);
if(list->next)
lint_print(linter, ", ");
} while((list = list->next));
lint_print(linter, "”");
}
ANN static void lint_type_decl(Linter* linter, Type_Decl* type) {
if(GET_FLAG(type, private))
lint_print(linter, "private ");
if(GET_FLAG(type, static))
lint_print(linter, "static ");
if(type->xid->ref) {
lint_print(linter, "typeof ");
lint_id_list(linter, type->xid->ref ? type->xid->ref : type->xid);
} else {
if(type->types)
lint_type_list(linter, type->types);
lint_id_list(linter, type->xid);
}
if(GET_FLAG(type, ref))
lint_print(linter, "@");
if(type->array)
lint_array(linter, type->array);
}
static void lint_stmt_indent(Linter* linter, Stmt stmt) {
if(stmt->stmt_type == ae_stmt_if) {
lint_print(linter, " ");
lint_stmt_if(linter, &stmt->d.stmt_if);
return;
} else if(stmt->stmt_type != ae_stmt_code) {
lint_nl(linter);
linter->indent++;
} else if(!linter->skip)
lint_print(linter, " ");
lint_stmt(linter, stmt);
if(stmt->stmt_type != ae_stmt_code)
linter->indent--;
}
ANN static void lint_exp_decl(Linter* linter, Exp_Decl* decl) {
Var_Decl_List list = decl->list;
lint_type_decl(linter, decl->td);
lint_print(linter, " ");
do {
lint_print(linter, s_name(list->self->xid));
if(list->self->array)
lint_array(linter, list->self->array);
if(list->next)
lint_print(linter, ", ");
} while((list = list->next));
}
ANN static void lint_exp_unary(Linter* linter, Exp_Unary* unary) {
lint_print(linter, "%s", op2str(unary->op));
switch(unary->op) {
case op_inc:
case op_dec:
lint_exp(linter, unary->exp);
break;
case op_new:
lint_print(linter, " ");
lint_type_decl(linter, unary->td);
break;
case op_spork:
lint_print(linter, " ~");
if(unary->code)
lint_stmt(linter, unary->code);
else
lint_exp(linter, unary->exp);
default: break;
}
}
ANN static void lint_exp_binary(Linter* linter, Exp_Binary* binary) {
lint_exp(linter, binary->lhs);
lint_print(linter, " %s ", op2str(binary->op));
lint_exp(linter, binary->rhs);
}
ANN static void lint_exp_primary(Linter* linter, Exp_Primary* exp) {
switch(exp->primary_type) {
case ae_primary_id:
lint_print(linter, "%s", s_name(exp->d.var));
break;
case ae_primary_num:
lint_print(linter, "%li", exp->d.num);
break;
case ae_primary_float:
lint_print(linter, "%.g", exp->d.fnum);
if(!(exp->d.fnum - floor(exp->d.fnum)))
lint_print(linter, ".0");
break;
case ae_primary_str:
lint_print(linter, "\"%s\"", exp->d.str);
break;
case ae_primary_array:
lint_array_lit(linter, exp->d.array);
break;
case ae_primary_hack:
lint_print(linter, "<<<");
lint_exp(linter, exp->d.exp);
lint_print(linter, ">>>");
break;
case ae_primary_complex:
lint_print(linter, "#(");
lint_exp(linter, exp->d.vec.exp);
lint_print(linter, ")");
break;
case ae_primary_polar:
lint_print(linter, "%(");
lint_exp(linter, exp->d.vec.exp);
lint_print(linter, ")");
break;
case ae_primary_vec:
lint_print(linter, "@(");
lint_exp(linter, exp->d.vec.exp);
lint_print(linter, ")");
break;
case ae_primary_char:
lint_print(linter, "'%s'", exp->d.chr);
break;
case ae_primary_nil:
lint_print(linter, "()");
break;
default:
break;
}
}
ANN static void lint_exp_array(Linter* linter, Exp_Array* array) {
lint_exp(linter, array->base);
lint_exp(linter, array->array->exp);
}
ANN static void lint_exp_cast(Linter* linter, Exp_Cast* cast) {
lint_exp(linter, cast->exp);
lint_print(linter, "$ ");
lint_type_decl(linter, cast->td);
}
ANN static void lint_exp_post(Linter* linter, Exp_Postfix* post) {
lint_exp(linter, post->exp);
lint_print(linter, "%s", op2str(post->op));
}
ANN static void lint_exp_dur(Linter* linter, Exp_Dur* dur) {
lint_exp(linter, dur->base);
lint_print(linter, "::");
lint_exp(linter, dur->unit);
}
ANN static void lint_exp_call(Linter* linter, Exp_Call* exp_call) {
if(exp_call->tmpl)
lint_type_list(linter, exp_call->tmpl->types);
lint_exp(linter, exp_call->func);
lint_print(linter, "(");
if(exp_call->args)
lint_exp(linter, exp_call->args);
lint_print(linter, ")");
}
ANN static void lint_exp_dot(Linter* linter, Exp_Dot* member) {
lint_exp(linter, member->base);
lint_print(linter, ".%s", s_name(member->xid));
}
ANN static void lint_exp_if(Linter* linter, Exp_If* exp_if) {
lint_exp(linter, exp_if->cond);
lint_print(linter, " ? ");
lint_exp(linter, exp_if->if_exp);
lint_print(linter, " : ");
lint_exp(linter, exp_if->else_exp);
}
ANN static void lint_exp(Linter* linter, Exp exp) {
while(exp) {
switch(exp->exp_type) {
case ae_exp_primary:
lint_exp_primary(linter, &exp->d.exp_primary);
break;
case ae_exp_decl:
lint_exp_decl(linter, &exp->d.exp_decl);
break;
case ae_exp_unary:
lint_exp_unary(linter, &exp->d.exp_unary);
break;
case ae_exp_binary:
lint_exp_binary(linter, &exp->d.exp_binary);
break;
case ae_exp_post:
lint_exp_post(linter, &exp->d.exp_post);
break;
case ae_exp_cast:
lint_exp_cast(linter, &exp->d.exp_cast);
break;
case ae_exp_call:
lint_exp_call(linter, &exp->d.exp_call);
break;
case ae_exp_array:
lint_exp_array(linter, &exp->d.exp_array);
break;
case ae_exp_dot:
lint_exp_dot(linter, &exp->d.exp_dot);
break;
case ae_exp_dur:
lint_exp_dur(linter, &exp->d.exp_dur);
break;
case ae_exp_if:
lint_exp_if(linter, &exp->d.exp_if);
break;
default:
break;
}
exp = exp->next;
if(exp)
lint_print(linter, ", ");
};
}
ANN static void lint_stmt_code(Linter* linter, Stmt_Code stmt) {
if(!stmt->stmt_list) {
lint_print(linter, "{}");
return;
}
lint_print(linter, "{");
lint_nl(linter);
linter->indent++;
if(stmt->stmt_list)
lint_stmt_list(linter, stmt->stmt_list);
linter->indent--;
lint_indent(linter);
lint_print(linter, "}");
lint_nl(linter);
}
ANN static void lint_stmt_return(Linter* linter, Stmt_Exp stmt) {
lint_print(linter, "return");
if(stmt->val) {
lint_print(linter, " ");
lint_exp(linter, stmt->val);
}
lint_print(linter, ";");
lint_nl(linter);
}
ANN static void lint_stmt_flow(Linter* linter, struct Stmt_Flow_* stmt, const m_str str) {
if(!stmt->is_do) {
lint_print(linter, "%s(", str);
lint_exp(linter, stmt->cond);
lint_print(linter, ")");
linter->skip++;
lint_stmt_indent(linter, stmt->body);
lint_nl(linter);
} else {
lint_print(linter, "do");
lint_stmt_indent(linter, stmt->body);
lint_print(linter, " %s(", str);
lint_exp(linter, stmt->cond);
lint_print(linter, ")");
lint_nl(linter);
}
}
ANN static void lint_stmt_for(Linter* linter, Stmt_For stmt) {
lint_print(linter, "for(");
linter->nonl++;
lint_stmt(linter, stmt->c1);
lint_print(linter, " ");
lint_stmt(linter, stmt->c2);
lint_print(linter, " ");
if(stmt->c3)
lint_exp(linter, stmt->c3);
lint_print(linter, ")");
linter->nonl--;
lint_stmt_indent(linter, stmt->body);
}
ANN static void lint_stmt_auto(Linter* linter, Stmt_Auto stmt) {
lint_print(linter, "for(");
lint_print(linter, "auto ");
lint_print(linter, s_name(stmt->sym));
lint_print(linter, " : ");
lint_exp(linter, stmt->exp);
lint_print(linter, ")");
lint_stmt_indent(linter, stmt->body);
}
ANN static void lint_stmt_loop(Linter* linter, Stmt_Loop stmt) {
lint_print(linter, "repeat(");
lint_exp(linter, stmt->cond);
lint_print(linter, ")");
lint_stmt(linter, stmt->body);
}
ANN static void lint_stmt_switch(Linter* linter, Stmt_Switch stmt) {
lint_print(linter, "switch(");
lint_exp(linter, stmt->val);
lint_print(linter, ")");
}
ANN static void lint_stmt_case(Linter* linter, Stmt_Exp stmt) {
lint_print(linter, "case ");
lint_exp(linter, stmt->val);
lint_print(linter, ":");
lint_nl(linter);
}
ANN static void lint_stmt_if(Linter* linter, Stmt_If stmt) {
lint_print(linter, "if(");
lint_exp(linter, stmt->cond);
lint_print(linter, ")");
if(stmt->if_body->stmt_type == ae_stmt_code)
linter->skip++;
lint_stmt_indent(linter, stmt->if_body);
if(stmt->else_body) {
if(stmt->if_body->stmt_type != ae_stmt_code)
lint_indent(linter);
else
lint_print(linter, " ");
lint_print(linter, "else");
if(stmt->else_body->stmt_type == ae_stmt_code)
linter->skip++;
lint_stmt_indent(linter, stmt->else_body);
if(stmt->else_body->stmt_type == ae_stmt_code)
lint_nl(linter);
}
}
ANN void lint_stmt_enum(Linter* linter, Stmt_Enum stmt) {
ID_List list = stmt->list;
lint_print(linter, "enum {");
lint_nl(linter);
linter->indent++;
do {
lint_indent(linter);
lint_print(linter, "%s", s_name(list->xid));
if(list->next)
lint_print(linter, ",");
lint_nl(linter);
} while((list = list->next));
linter->indent--;
lint_indent(linter);
lint_print(linter, "}");
if(stmt->xid)
lint_print(linter, " %s", s_name(stmt->xid));
lint_print(linter, ";");
lint_nl(linter);
}
ANN void lint_stmt_fptr(Linter* linter, Stmt_Fptr ptr) {
Arg_List list = ptr->args;
lint_print(linter, "typedef ");
lint_type_decl(linter, ptr->td);
lint_print(linter, " ");
lint_print(linter, s_name(ptr->xid));
lint_print(linter, "(");
while(list) {
lint_type_decl(linter, list->td);
lint_print(linter, " %s", s_name(list->var_decl->xid));
list = list->next;
if(list || GET_FLAG(ptr->td, variadic))
lint_print(linter, ", ");
}
if(GET_FLAG(ptr->td, variadic))
lint_print(linter, "...");
lint_print(linter, ")");
lint_nl(linter);
}
ANN void lint_stmt_type(Linter* linter, Stmt_Type ptr) {
lint_print(linter, "typedef ");
lint_type_decl(linter, ptr->td);
lint_print(linter, " ");
lint_print(linter, s_name(ptr->xid));
lint_print(linter, ";");
lint_nl(linter);
}
ANN void lint_stmt_union(Linter* linter, Stmt_Union stmt) {
Decl_List l = stmt->l;
if(GET_FLAG(stmt, private))
lint_print(linter, "private ");
if(GET_FLAG(stmt, static))
lint_print(linter, "static ");
lint_print(linter, "union ");
if(stmt->type_xid)
lint_print(linter, "%s ", s_name(stmt->type_xid));
lint_print(linter, "{");
lint_nl(linter);
linter->indent++;
do {
lint_indent(linter);
lint_exp(linter, l->self);
lint_print(linter, ";");
lint_nl(linter);
} while((l = l->next));
linter->indent--;
lint_print(linter, "}");
if(stmt->xid)
lint_print(linter, " %s", s_name(stmt->xid));
lint_print(linter, ";");
lint_nl(linter);
}
ANN void lint_stmt_goto(Linter* linter, Stmt_Jump stmt) {
if(stmt->is_label)
lint_print(linter, "%s:", s_name(stmt->name));
else
lint_print(linter, "goto %s;", s_name(stmt->name));
lint_nl(linter);
}
ANN void lint_stmt_continue(Linter* linter, Stmt stmt __attribute__((unused))) {
lint_print(linter, "continue;");
lint_nl(linter);
}
ANN void lint_stmt_break(Linter* linter, Stmt stmt __attribute__((unused))) {
lint_print(linter, "break;");
lint_nl(linter);
}
ANN void lint_stmt_pp(Linter* linter, Stmt_PP stmt) {
if(stmt->type == ae_pp_comment)
lint_print(linter, "// ");
else if(stmt->type == ae_pp_include)
lint_print(linter, "#include ");
else if(stmt->type == ae_pp_define)
lint_print(linter, "#define ");
else if(stmt->type == ae_pp_undef)
lint_print(linter, "#undef ");
else if(stmt->type == ae_pp_ifdef)
lint_print(linter, "#ifdef ");
else if(stmt->type == ae_pp_ifndef)
lint_print(linter, "#ifndef ");
else if(stmt->type == ae_pp_else)
lint_print(linter, "#else ");
else if(stmt->type == ae_pp_endif)
lint_print(linter, "#endif ");
if(stmt->data)
lint_print(linter, stmt->data);
lint_nl(linter);
}
ANN static void lint_stmt(Linter* linter, Stmt stmt) {
if(stmt->stmt_type == ae_stmt_exp && !stmt->d.stmt_exp.val)
return;
lint_indent(linter);
switch(stmt->stmt_type) {
case ae_stmt_exp:
lint_exp(linter, stmt->d.stmt_exp.val);
lint_print(linter, ";");
if(!linter->nonl)
lint_nl(linter);
break;
case ae_stmt_code:
lint_stmt_code(linter, &stmt->d.stmt_code);
break;
case ae_stmt_return:
lint_stmt_return(linter, &stmt->d.stmt_exp);
break;
case ae_stmt_if:
lint_stmt_if(linter, &stmt->d.stmt_if);
break;
case ae_stmt_while:
lint_stmt_flow(linter, &stmt->d.stmt_flow, "while");
break;
case ae_stmt_for:
lint_stmt_for(linter, &stmt->d.stmt_for);
break;
case ae_stmt_auto:
lint_stmt_auto(linter, &stmt->d.stmt_auto);
break;
case ae_stmt_until:
lint_stmt_flow(linter, &stmt->d.stmt_flow, "until");
break;
case ae_stmt_loop:
lint_stmt_loop(linter, &stmt->d.stmt_loop);
break;
case ae_stmt_switch:
lint_stmt_switch(linter, &stmt->d.stmt_switch);
break;
case ae_stmt_case:
lint_stmt_case(linter, &stmt->d.stmt_exp);
break;
case ae_stmt_enum:
lint_stmt_enum(linter, &stmt->d.stmt_enum);
break;
case ae_stmt_continue:
lint_stmt_continue(linter, stmt);
break;
case ae_stmt_break:
lint_stmt_break(linter, stmt);
break;
case ae_stmt_jump:
lint_stmt_goto(linter, &stmt->d.stmt_jump);
break;
case ae_stmt_fptr:
lint_stmt_fptr(linter, &stmt->d.stmt_fptr);
break;
case ae_stmt_type:
lint_stmt_type(linter, &stmt->d.stmt_type);
break;
case ae_stmt_union:
lint_stmt_union(linter, &stmt->d.stmt_union);
break;
case ae_stmt_pp:
lint_stmt_pp(linter, &stmt->d.stmt_pp);
break;
}
}
ANN static void lint_stmt_list(Linter* linter, Stmt_List list) {
do lint_stmt(linter, list->stmt);
while((list = list->next));
}
ANN static void lint_func_def(Linter* linter, Func_Def f) {
Arg_List list = f->arg_list;
lint_indent(linter);
lint_print(linter, "%s", GET_FLAG(f, variadic) ?
"variadic " : "function ");
if(GET_FLAG(f, static))
lint_print(linter, "static ");
lint_type_decl(linter, f->td);
lint_print(linter, " ");
lint_print(linter, s_name(f->name));
lint_print(linter, "(");
while(list) {
lint_type_decl(linter, list->td);
lint_print(linter, " %s", s_name(list->var_decl->xid));
list = list->next;
if(list)
lint_print(linter, ", ");
}
lint_print(linter, ")");
linter->skip++;
lint_stmt_indent(linter, f->d.code);
lint_nl(linter);
f->flag &= ~ae_flag_template;
}
ANN static void lint_section(Linter* linter, Section* section) {
ae_section_t t = section->section_type;
if(t == ae_section_stmt)
lint_stmt_list(linter, section->d.stmt_list);
else if(t == ae_section_func)
lint_func_def(linter, section->d.func_def);
else if(t == ae_section_class)
lint_class_def(linter, section->d.class_def);
}
ANN static void lint_class_def(Linter* linter, Class_Def class_def) {
Class_Body body = class_def->body;
lint_indent(linter);
if(class_def->tmpl) {
lint_print(linter, "template");
lint_id_list(linter, class_def->tmpl->list.list);
}
lint_print(linter, "class %s", s_name(class_def->name->xid));
if(class_def->ext) {
lint_print(linter, " extends ");
lint_type_decl(linter, class_def->ext);
lint_nl(linter);
}
lint_print(linter, " {");
lint_nl(linter);
linter->indent++;
while(body) {
lint_section(linter, body->section);
body = body->next;
}
linter->indent--;
lint_nl(linter);
lint_nl(linter);
}
ANN void lint_ast(Linter* linter, Ast ast) {
do lint_section(linter, ast->section);
while((ast = ast->next));
}
int main(int argc, char** argv) {
argc--; argv++;
Scanner* scan = new_scanner(127); // magic number
while(argc--) {
Linter linter = { *argv, NULL, 1, 0, 0, 0, 0, 0 };
if(!strcmp(*argv, "-l")) {
scan->lint = 1;
++argv;
continue;
}
Ast ast;
FILE* f = fopen(*argv, "r");
if(!f)
continue;
if(!(ast = parse(scan, *argv++, f)))
goto close;
linter.file = stdout;
lint_ast(&linter, ast);
free_ast(ast);
close:
fclose(f);
}
free_scanner(scan);
free_symbols();
return 0;
}