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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
|
#include "compiledefines.h"
#include "types.t"
#include "system.h"
#include "syntaxtr.t"
#include "comsupport.h"
#include "settings.h"
#include "sizes.h"
#include "checker.h"
#include "checksupport.h"
#include "dbprint.h"
#include "codegen_types.h"
#define for_l(v,l,n) for(v=(l);v!=NULL;v=v->n)
#define PrintAnnotation(annot)
#undef PRINT_alt_lifted_node_ids
#undef PRINT_NODE_ID_REF_COUNTS
#define PRINT_ALL_NODE_ID_ADDRESSES
#undef PRINT_NODE_LINE_NUMBERS
#define PRINT_NODE_ID_REF_COUNT
static void PrintUnaryState (StateKind kind, ObjectKind obj, File file)
{
switch (kind)
{ case OnB: FPutS ("OnB ", file); break;
case OnA: FPutS ("OnA ", file); break;
case StrictOnA: FPutS ("StrictOnA ", file); break;
case SemiStrict: FPutS ("SemiStrict ", file); break;
case StrictRedirection: FPutS ("StrictRedirection ", file); break;
case Parallel: FPutS ("Parallel ", file); break;
case Undefined: FPutS ("Undefined ", file); break;
case UnderEval: FPutS ("UnderEval ", file); break;
}
switch (obj)
{ case UnknownObj: FPutS ("??? ", file); break;
case IntObj: FPutS ("Int ", file); break;
case BoolObj: FPutS ("Bool ", file); break;
case CharObj: FPutS ("Char ", file); break;
case StringObj: FPutS ("String ", file); break;
case RealObj: FPutS ("Real ", file); break;
case FileObj: FPutS ("File ", file); break;
case TupleObj: FPutS ("Tuple ", file); break;
case ListObj: FPutS ("List ", file); break;
case ProcIdObj: FPutS ("ProcId ", file); break;
case RecordObj: FPutS ("Record ", file); break;
}
}
void PrintState (StateS state, File file)
{
switch (state.state_type){
case TupleState:
{
int i,arity;
arity=state.state_arity;
FPrintF (file,"t%d",arity);
for (i=0; i<arity; ++i){
FPrintF (file," ");
PrintState (state.state_tuple_arguments[i],file);
}
break;
}
case RecordState:
FPutC ('r',file);
break;
case ArrayState:
FPutC ('a',file);
break;
case SimpleState:
PrintUnaryState (state.state_kind,state.state_object, file);
break;
}
}
void DPrintNodeId (NodeId nid, File file)
{
if (nid){
if (nid->nid_ident){
FPrintF (file, "%s",nid->nid_ident->ident_name);
#ifdef PRINT_ALL_NODE_ID_ADDRESSES
FPrintF (file, "@i_%lx", (long) nid);
#endif
} else
FPrintF (file, "i_%lx", (long) nid);
#ifdef PRINT_NODE_ID_REF_COUNT
FPrintF (file, "<%d>", nid->nid_refcount);
#endif
} else
FPrintF (file," 00000000");
}
void DPrintNodeIdS (char *s,NodeId node_id,File file)
{
FPrintF (file,"%s",s);
DPrintNodeId (node_id,file);
FPrintF (file,"\n");
}
static void DPrintTypeVar (TypeVar tv, Node follow, File file)
{
if (tv){
if (tv->tv_ident)
FPrintF (file, "%s",tv->tv_ident->ident_name);
else
FPrintF (file, "i_%lx", (long) tv);
FPrintF (file, "<%d>", tv->tv_refcount);
if (follow)
FPutS (" = ", file);
}
}
static void PrintArgument (Args arg,Bool brackets,int n_leading_spaces,File file)
{
/*
PrintState (arg->arg_state, file);
if ((arg->arg_state.state_mark & STATE_UNIQUE_MASK)!=0)
FPrintF (file,"*");
*/
if (arg->arg_node->node_kind==NodeIdNode)
DPrintNodeId (arg->arg_node->node_node_id,file);
else
PrintRuleNode (arg->arg_node,brackets,n_leading_spaces,file);
}
static void print_spaces (int n_leading_spaces,File file)
{
int n;
for (n=0; n<n_leading_spaces; ++n)
FPutC (' ',file);
}
static void PrintArguments (Args args, char separator, Bool brackets,int n_leading_spaces,File file)
{
if (args!=NULL){
PrintArgument (args,brackets,n_leading_spaces,file);
for (args = args -> arg_next; args; args = args -> arg_next){
FPutC (separator, file);
if (separator=='\n')
print_spaces (n_leading_spaces,file);
PrintArgument (args, brackets,n_leading_spaces,file);
}
}
}
void PrintRuleNode (Node node,Bool brackets,int n_leading_spaces,File file)
{
/*
if (IsOnACycle (node -> node_number))
FPutS ("<C>", file);
PrintState (node -> node_state,file);
*/
switch (node -> node_kind){
case NormalNode:
{
Symbol node_symb = node->node_symbol;
if (node_symb -> symb_kind == tuple_symb){
FPutC ('(', file);
PrintArguments (node -> node_arguments, ',', False,n_leading_spaces,file);
FPutC (')', file);
}
else if (node_symb -> symb_kind == list_type)
{ FPutC ('[', file);
PrintArguments (node -> node_arguments, ',', False,n_leading_spaces,file);
FPutC (']', file);
}
else if (node_symb -> symb_kind == nil_symb)
FPutS ("[]", file);
else if (node_symb -> symb_kind == cons_symb)
{ FPutC ('[', file);
PrintArgument (node -> node_arguments, brackets,n_leading_spaces,file);
FPutC (':', file);
PrintArgument (node -> node_arguments -> arg_next, brackets,n_leading_spaces,file);
FPutC (']', file);
} else if (node_symb -> symb_kind==select_symb){
FPutS ("_sel",file);
FPutC ('0'+node->node_arity,file);
FPutC (' ',file);
PrintArgument (node -> node_arguments,True,n_leading_spaces,file);
} else {
if (brackets && node -> node_arguments)
FPutC ('(', file);
PrintSymbol (node_symb, file);
#ifdef PRINT_NODE_LINE_NUMBERS
FPrintF (file,"#%d",node->node_line);
#endif
if (node_symb->symb_kind==definition && node_symb->symb_def->sdef_kind==IMPRULE &&
(node_symb->symb_def->sdef_rule->rule_mark & RULE_INTERNAL_FUNCTION_MASK))
{
FPrintF (file,"_%d",node_symb->symb_def->sdef_number);
}
if (node -> node_arguments)
{ FPutC (' ', file);
PrintArguments (node -> node_arguments,' ', True,n_leading_spaces,file);
if (brackets)
FPutC (')', file);
}
}
break;
}
case SelectorNode:
PrintArgument (node -> node_arguments, True,n_leading_spaces,file);
if (node->node_arity>1){
FPutC ('!',file);
FPutC ('0'+node->node_arity,file);
} else
FPutC ('.',file);
PrintSymbol (node->node_symbol, file);
break;
case IfNode:
{
Args elsepart, thenpart, condpart;
condpart = node -> node_arguments;
thenpart = condpart -> arg_next;
elsepart = thenpart -> arg_next;
if (brackets)
FPutC ('(', file);
FPutS ("IF ", file);
PrintArgument (condpart, True,n_leading_spaces,file);
FPutC ('\n',file);
print_spaces (n_leading_spaces+4,file);
#if 0
# ifdef PRINT_NODE_ID_REF_COUNTS
FPutS ("[ ", file);
{
NodeIdRefCountListP node_id_ref_count_elem;
for_l (node_id_ref_count_elem,node->node_then_node_id_ref_counts,nrcl_next){
DPrintNodeId (node_id_ref_count_elem->nrcl_node_id,file);
fprintf (file," %d ",node_id_ref_count_elem->nrcl_ref_count);
}
}
FPutS ("]\n", file);
print_spaces (n_leading_spaces+4,file);
# else
if (node->node_then_strict_node_ids!=NULL){
StrictNodeIdP strict_node_id;
FPutS ("let! ", file);
for_l (strict_node_id,node->node_then_strict_node_ids,snid_next){
DPrintNodeId (strict_node_id->snid_node_id,file);
FPutS ("; ",file);
}
FPutC ('\n',file);
print_spaces (n_leading_spaces+4,file);
}
# endif
#endif
PrintArgument (thenpart, True,n_leading_spaces+4,file);
if (node->node_then_node_defs!=NULL){
FPutC ('\n',file);
print_spaces (n_leading_spaces+4,file);
FPutS ("{\n",file);
PrintNodeDefs (node->node_then_node_defs,n_leading_spaces+8,file);
print_spaces (n_leading_spaces+4,file);
FPutC ('}', file);
}
FPutC ('\n',file);
print_spaces (n_leading_spaces+4,file);
#if 0
# ifdef PRINT_NODE_ID_REF_COUNTS
FPutS ("[ ", file);
{
NodeIdRefCountListP node_id_ref_count_elem;
for_l (node_id_ref_count_elem,node->node_else_node_id_ref_counts,nrcl_next){
DPrintNodeId (node_id_ref_count_elem->nrcl_node_id,file);
fprintf (file," %d ",node_id_ref_count_elem->nrcl_ref_count);
}
}
FPutS ("]\n",file);
print_spaces (n_leading_spaces+4,file);
# else
if (node->node_else_strict_node_ids!=NULL){
StrictNodeIdP strict_node_id;
FPutS ("let! ", file);
for (strict_node_id=node->node_else_strict_node_ids; strict_node_id!=NULL; strict_node_id=strict_node_id->snid_next){
DPrintNodeId (strict_node_id->snid_node_id,file);
FPutS ("; ",file);
}
FPutC ('\n',file);
print_spaces (n_leading_spaces+4,file);
}
# endif
#endif
PrintArgument (elsepart, True,n_leading_spaces+4,file);
if (node->node_else_node_defs!=NULL){
FPutC ('\n', file);
print_spaces (n_leading_spaces+4,file);
FPutS ("{\n",file);
PrintNodeDefs (node->node_else_node_defs,n_leading_spaces+8,file);
print_spaces (n_leading_spaces+4,file);
FPutS ("}\n", file);
print_spaces (n_leading_spaces,file);
}
if (brackets)
FPutC (')', file);
break;
}
case NodeIdNode:
{
NodeId node_id;
node_id=node->node_node_id;
if (node_id->nid_ident){
FPrintF (file, " %s<%d>",node_id->nid_ident->ident_name,node_id->nid_refcount);
#ifdef PRINT_ALL_NODE_ID_ADDRESSES
FPrintF (file, " i_%lx",(long) node_id);
#endif
} else
FPrintF (file, " i_%lx<%d>",(long) node_id,node_id->nid_refcount);
break;
}
case UpdateNode:
{ Args field = node -> node_arguments;
FPutC ('{', file);
PrintArgument (field, False,n_leading_spaces,file);
FPutS (" & ", file);
field = field -> arg_next;
PrintArgument (field, False,n_leading_spaces,file);
for (field = field -> arg_next; field; field = field -> arg_next)
{ FPutC (',', file);
PrintArgument (field, False,n_leading_spaces,file);
}
FPutC ('}', file);
break;
}
case MatchNode:
{
FPutS ("Match ",file);
PrintSymbol (node->node_symbol,file);
FPutC (' ',file);
PrintArgument (node->node_arguments,False,n_leading_spaces,file);
break;
}
case SwitchNode:
FPutS ("Switch ",file);
DPrintNodeId (node->node_node_id,file);
FPutC ('\n',file);
print_spaces (n_leading_spaces,file);
PrintArguments (node->node_arguments,'\n',True,n_leading_spaces,file);
break;
case CaseNode:
FPutS ("Case: ",file);
PrintSymbol (node->node_symbol, file);
FPutS (" [ ",file);
{
NodeIdRefCountListP node_id_ref_count_elem;
for_l (node_id_ref_count_elem,node->node_node_id_ref_counts,nrcl_next){
DPrintNodeId (node_id_ref_count_elem->nrcl_node_id,file);
fprintf (file," %d ",node_id_ref_count_elem->nrcl_ref_count);
}
}
FPutS ("]\n",file);
print_spaces (n_leading_spaces+4,file);
#if 0
# ifndef PRINT_NODE_ID_REF_COUNTS
if (node->node_strict_node_ids!=NULL){
StrictNodeIdP strict_node_id;
FPutS ("let! ", file);
for_l (strict_node_id,node->node_strict_node_ids,snid_next){
if (strict_node_id->snid_mark & STRICT_NODE_ID_IDENT_MASK){
FPrintF (file, " %s",strict_node_id->snid_ident->ident_name);
} else {
DPrintNodeId (strict_node_id->snid_node_id,file);
FPutS ("; ",file);
}
}
FPutC ('\n',file);
print_spaces (n_leading_spaces+4,file);
}
# endif
#endif
PrintArgument (node->node_arguments,False,n_leading_spaces+4,file);
if (node->node_node_defs!=NULL){
FPutC ('\n', file);
print_spaces (n_leading_spaces,file);
FPutS ("{\n",file);
PrintNodeDefs (node->node_node_defs,n_leading_spaces+4,file);
print_spaces (n_leading_spaces,file);
FPutS ("}\n", file);
print_spaces (n_leading_spaces,file);
}
break;
case DefaultNode:
FPutS ("Default: [ ",file);
{
NodeIdRefCountListP node_id_ref_count_elem;
for_l (node_id_ref_count_elem,node->node_node_id_ref_counts,nrcl_next){
DPrintNodeId (node_id_ref_count_elem->nrcl_node_id,file);
fprintf (file," %d ",node_id_ref_count_elem->nrcl_ref_count);
}
}
FPutS ("]\n",file);
print_spaces (n_leading_spaces+4,file);
#if 0
# ifndef PRINT_NODE_ID_REF_COUNTS
if (node->node_strict_node_ids!=NULL){
StrictNodeIdP strict_node_id;
FPutS ("let! ", file);
for_l (strict_node_id,node->node_strict_node_ids,snid_next){
if (strict_node_id->snid_mark & STRICT_NODE_ID_IDENT_MASK){
FPrintF (file, " %s",strict_node_id->snid_ident->ident_name);
} else {
DPrintNodeId (strict_node_id->snid_node_id,file);
FPutS ("; ",file);
}
}
FPutC ('\n',file);
print_spaces (n_leading_spaces+4,file);
}
# endif
#endif
PrintArgument (node->node_arguments,False,n_leading_spaces+4,file);
if (node->node_node_defs!=NULL){
FPutC ('\n', file);
print_spaces (n_leading_spaces,file);
FPutS ("{\n",file);
PrintNodeDefs (node->node_node_defs,n_leading_spaces+4,file);
print_spaces (n_leading_spaces,file);
FPutS ("}\n", file);
print_spaces (n_leading_spaces,file);
}
break;
case PushNode:
{
NodeIdListElementP node_id_list;
FPutS ("Push ",file);
DPrintNodeId (node->node_arguments->arg_node->node_node_id,file);
FPutS ("[",file);
for_l (node_id_list,node->node_node_ids,nidl_next){
DPrintNodeId (node_id_list->nidl_node_id,file);
if (node_id_list->nidl_next!=NULL)
FPutC (' ',file);
}
FPutS ("]",file);
FPutC ('\n',file);
print_spaces (n_leading_spaces,file);
PrintArgument (node->node_arguments->arg_next,True,n_leading_spaces,file);
break;
}
case GuardNode:
FPutS ("Guard ",file);
PrintArgument (node->node_arguments,True,n_leading_spaces,file);
FPutC ('\n',file);
print_spaces (n_leading_spaces,file);
PrintArgument (node->node_arguments->arg_next,True,n_leading_spaces,file);
if (node->node_node_defs!=NULL){
FPutC ('\n', file);
print_spaces (n_leading_spaces,file);
FPutS ("with {\n",file);
PrintNodeDefs (node->node_node_defs,n_leading_spaces+4,file);
print_spaces (n_leading_spaces,file);
FPutS ("}\n", file);
print_spaces (n_leading_spaces,file);
}
break;
case TupleSelectorsNode:
FPutS ("TupleSelectors (",file);
PrintArguments (node->node_arguments,',',True,n_leading_spaces,file);
FPutS (") = ",file);
PrintRuleNode (node->node_node,True,n_leading_spaces,file);
break;
case FillUniqueNode:
FPutS ("FillUniqueNode ",file);
DPrintNodeId (node->node_node->node_arguments->arg_node->node_node_id,file);
FPutC (' ',file);
PrintArguments (node->node_arguments,' ',True,n_leading_spaces,file);
break;
default:
FPutC ('?',file);
FPrintF (file,"%d",(int)node->node_kind);
}
}
void PrintNodeDef (NodeDefP def_p,int n_leading_spaces,File file)
{
int n;
/* FPrintF (file, "%d: ", (int) def_p->def_number); */
for (n=n_leading_spaces; n>0; --n)
FPutC (' ',file);
DPrintNodeId (def_p -> def_id, file);
if (def_p -> def_node){
FPutS (" = ", file);
PrintRuleNode (def_p->def_node, False,n_leading_spaces,file);
}
FPutS ("\n",file);
}
void PrintNodeDefs (NodeDefs defs,int n_leading_spaces,File file)
{
for ( ; defs!=NULL; defs=defs->def_next)
PrintNodeDef (defs,n_leading_spaces,file);
}
STRUCT (lifted_node_id,LiftedNodeId){
NodeId lnid_lifted_node_id;
NodeId lnid_lhs_node_id;
struct lifted_node_id * lnid_next;
};
void PrintRuleAlt (RuleAlts rulealt,int n_leading_spaces,File file)
{
PrintRuleNode (rulealt->alt_lhs_root, False,n_leading_spaces,file);
#ifdef PRINT_alt_lifted_node_ids
if (rulealt->alt_lifted_node_ids){
LiftedNodeId lifted_node_id_p;
FPutS (" <<",file);
for_l (lifted_node_id_p,rulealt->alt_lifted_node_ids,lnid_next){
FPutC (' ',file);
DPrintNodeId (lifted_node_id_p->lnid_lhs_node_id,file);
FPutC (':',file);
DPrintNodeId (lifted_node_id_p->lnid_lifted_node_id,file);
}
FPutS (" >>",file);
}
#endif
if (rulealt->alt_lhs_defs){
FPutS ("\n", file);
PrintNodeDefs (rulealt -> alt_lhs_defs,4,file);
FPutS (" = ", file);
} else
FPutS ("\n = ", file);
if (rulealt -> alt_kind==Contractum){
#if 1
# ifndef PRINT_NODE_ID_REF_COUNTS
if (rulealt->alt_strict_node_ids!=NULL){
StrictNodeIdP strict_node_id;
FPutS ("let! ", file);
for_l (strict_node_id,rulealt->alt_strict_node_ids,snid_next){
if (strict_node_id->snid_mark & STRICT_NODE_ID_IDENT_MASK){
FPrintF (file, " %s",strict_node_id->snid_ident->ident_name);
} else {
DPrintNodeId (strict_node_id->snid_node_id,file);
FPutS ("; ",file);
}
}
FPutC ('\n',file);
print_spaces (n_leading_spaces,file);
}
# endif
#endif
PrintRuleNode (rulealt->alt_rhs_root, False,n_leading_spaces,file);
FPutS ("\n", file);
PrintNodeDefs (rulealt->alt_rhs_defs,4,file);
} else {
/*
FPutS (rulealt->alt_rhs_root->node_node_id->nid_ident->ident_name,file);
*/
}
}
static void PrintRuleAlts (RuleAlts rulealt,int n_leading_spaces,File file)
{
for (; rulealt; rulealt = rulealt -> alt_next)
PrintRuleAlt (rulealt,n_leading_spaces,file);
}
static void PrintTypeArguments (TypeArgs args, char separator, File file)
{
if (args){
PrintTypeNode (args->type_arg_node, file);
for (args = args->type_arg_next; args; args = args->type_arg_next){
FPutC (separator, file);
PrintTypeNode (args->type_arg_node, file);
}
}
}
static char *PrintUniVars = "uvwxyz";
#define NrOfPrintUniVars 6
void PrintTypeNode (TypeNode node, File file)
{
if (node->type_node_annotation || node->type_node_annotation == StrictOnA)
FPutC ('!', file);
if (node->type_node_attribute == UniqueAttr)
FPutC ('*', file);
else if (node->type_node_attribute > UniqueAttr)
{ unsigned node_attr = node->type_node_attribute - UniqueAttr;
if (node_attr < NrOfPrintUniVars)
{ FPutC (PrintUniVars[node_attr], file);
FPutC (':', file);
}
else
FPrintF (file, "%u:", node_attr);
}
if (node->type_node_is_var)
FPutS (node->type_node_tv->tv_ident->ident_name, file);
else if (node->type_node_symbol->symb_kind == tuple_type)
{ FPutC ('(', file);
PrintTypeArguments (node->type_node_arguments, ',', file);
FPutC (')', file);
}
else if (node->type_node_symbol->symb_kind == list_type)
{ FPutC ('[', file);
PrintTypeArguments (node->type_node_arguments,',', file);
FPutC (']', file);
}
else if (node->type_node_symbol->symb_kind >= array_type &&
node->type_node_symbol->symb_kind <= unboxed_array_type)
{ char *delim_chars = ":|#";
char array_delim = delim_chars [node->type_node_symbol->symb_kind - array_type];
FPutC ('{', file);
FPutC (array_delim, file);
PrintTypeArguments (node->type_node_arguments,',', file);
FPutC (array_delim, file);
FPutC ('}', file);
}
else if (node->type_node_symbol->symb_kind == apply_symb)
{ FPutC ('(', file);
PrintTypeArguments (node -> type_node_arguments, ' ', file);
FPutC (')', file);
} else
{ if (node->type_node_arguments)
FPutC ('(', file);
PrintSymbol (node->type_node_symbol, file);
if (node->type_node_arguments){
FPutC (' ', file);
PrintTypeArguments (node->type_node_arguments,' ', file);
FPutC (')', file);
}
}
}
static void PrintAttribute (AttributeKind attr, File file)
{
if (attr == NotUniqueAttr)
return;
else if (attr == UniqueAttr)
FPutC ('*', file);
else
FPrintF (file, "%d", attr - UniqueAttr, file);
}
static void PrintTypeAttrEquations (UniVarEquations equs, File file)
{
for (; equs; equs = equs -> uve_next)
{ AttributeKindList next;
PrintAttribute (equs -> uve_demanded, file);
FPutC (':', file);
for (next = equs -> uve_offered; next; next = next -> akl_next)
{ FPutC (' ', file);
PrintAttribute (next -> akl_elem, file);
}
}
}
static void PrintTypeContext (TypeContext type_context, File file)
{
SymbolList symbols;
for (symbols = type_context -> tyco_symbols; symbols; symbols = symbols -> sl_next)
{
#ifndef CLEAN2
PrintSymbol (symbols -> sl_symbol -> sdef_class -> cd_symbol, file);
#endif
FPutC (' ', file);
DPrintTypeVar (type_context -> tyco_variable, NULL, file);
}
}
static void PrintTypeContexts (TypeContext type_contexts, File file)
{
PrintTypeContext (type_contexts, file);
for (type_contexts = type_contexts -> tyco_next; type_contexts; type_contexts = type_contexts -> tyco_next)
{ FPutS (" & ", file);
PrintTypeContext (type_contexts, file);
}
}
void PrintTypeAlt (TypeAlts type_alts, File file, Bool with_equats)
{
TypeNode lhs_root = type_alts -> type_alt_lhs;
PrintSymbol (lhs_root -> type_node_symbol, file);
FPutS (" :: ", file);
PrintTypeArguments (lhs_root -> type_node_arguments, ' ', file);
FPutS (" -> ", file);
PrintTypeNode (type_alts -> type_alt_rhs, file);
if (type_alts -> type_alt_type_context)
{ FPutS (" | ", file);
PrintTypeContexts (type_alts -> type_alt_type_context, file);
}
FPutC ('\n', file);
if (with_equats)
{ PrintTypeAttrEquations (type_alts -> type_alt_attr_equations, file);
FPutC ('\n', file);
}
}
void PrintImpRule (ImpRules rule,int n_leading_spaces,File file)
{
/*
if (rule -> rule_type)
PrintTypeAlt (rule -> rule_type, file);
*/
PrintRuleAlts (rule->rule_alts,n_leading_spaces,file);
}
void PrintRules (ImpRules rules,File file)
{
ImpRuleS *rule;
for_l (rule,rules,rule_next){
PrintImpRule (rule,4,file);
if (rule->rule_next!=NULL)
FPutC ('\n',file);
}
}
|