-
Notifications
You must be signed in to change notification settings - Fork 0
/
anal.c
1481 lines (1366 loc) · 61.8 KB
/
anal.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
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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
FILE NAME: anal.c
Copyright (C) 1997-2016 Vladimir Makarov.
Written by Vladimir Makarov <[email protected]>
This file is part of the tool SPRUT.
This is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
TITLE: Semantic analyzer of SPRUT (internal representation description
translator)
DESCRIPTION: This file tests semantically all description parts built by
the SPRUT parser and after that makes equivalent one level
description (i.e. with one description part).
SPECIAL CONSIDERATION:
The analyzer is to be called only after SPRUT parser.
Defining macro `NDEBUG' (e.g. by option `-D' in C compiler
command line) during the file compilation disables to fix
some internal errors of the analyzer.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#else /* In this case we are oriented to ANSI C */
#endif /* #ifdef HAVE_CONFIG_H */
#include <string.h>
#include "position.h"
#include "errors.h"
#include "ird.h"
#include "common.h"
#include "tab.h"
#include "anal.h"
#include <assert.h>
/* This page contains functions for traversing internal representation. */
/* This recursive function traverses description part hierarchy in
depth first order. */
static void
traverse_description_part_hierarchy
(IR_node_t top_description_part,
void (*applied_function) (IR_node_t description_part))
{
IR_node_t current_part;
if (top_description_part == NULL)
return;
for (current_part = IR_first_basic_description_part (top_description_part);
current_part != NULL;
current_part = IR_next_basic_description_part (current_part))
traverse_description_part_hierarchy (current_part, applied_function);
(*applied_function) (top_description_part);
}
/* This function traverses all node type declarations (even if it is
node type continuation, i.e. without super type) in given
description part in the same order as in source file. Remember
that all declarations of a node type are represented by nodes
`node_type'. */
static void
traverse_description_part_node_types
(IR_node_t description_part, void (*applied_function) (IR_node_t node_type))
{
IR_node_t node_type;
if (IR_last_type (description_part) == NULL)
return;
for (node_type = IR_next_type (IR_last_type (description_part));;
node_type = IR_next_type (node_type))
{
if (IR_NODE_MODE (node_type) == IR_NM_node_type)
(*applied_function) (node_type);
else
assert (IR_NODE_MODE (node_type) == IR_NM_predefined_type);
if (node_type == IR_last_type (description_part))
break;
}
}
/* This function traverses all fields which were declared in given
description part and node type of which is in table of node type.
Field is processed only once. This function must be called only
after inclusion all node types into table of types and fields into
table of node fields. After that all fields of a node type are
collected in a node type declaration which is included into the
table of type (remember that there may be a few declarations of a
node type and that all declarations of a node type are represented
by internal representation nodes `node_type'). No more one
activations of this function can exist simultaneously. */
static void
traverse_included_description_part_fields
(IR_node_t description_part, void (*applied_function) (IR_node_t field))
{
IR_node_t current_field;
IR_node_t current_type;
IR_node_t original_field;
IR_node_t original_type;
if (IR_last_type (description_part) == NULL)
return;
/* This cycle is needed to guarantee the single pass of node type which
is in the table. */
for (current_type = IR_next_type (IR_last_type (description_part));;
current_type = IR_next_type (current_type))
{
original_type = find_type (IR_type_identifier (current_type));
assert (original_type != NULL);
if (IR_NODE_MODE (original_type) == IR_NM_node_type)
IR_set_traverse_flag (original_type, FALSE);
if (current_type == IR_last_type (description_part))
break;
}
for (current_type = IR_next_type (IR_last_type (description_part));;
current_type = IR_next_type (current_type))
{
original_type = find_type (IR_type_identifier (current_type));
if (IR_NODE_MODE (original_type) == IR_NM_node_type
&& !IR_traverse_flag (original_type)
&& IR_last_field (original_type) != NULL)
{
for (current_field = IR_next_field (IR_last_field (original_type));;
current_field = IR_next_field (current_field))
{
if (IR_NODE_MODE (current_field) == IR_NM_field)
{
original_field
= find_node_field (IR_field_identifier (current_field),
original_type);
if (strcmp (IR_position (original_field).file_name,
IR_position (description_part).file_name) == 0)
(*applied_function) (original_field);
}
if (current_field == IR_last_field (original_type))
break;
}
IR_set_traverse_flag (original_type, TRUE);
}
if (current_type == IR_last_type (description_part))
break;
}
}
/* This page contains semantic functions. The most of the functions are
called from traverse functions. */
/* This function inserts identifiers of double node type declarations
of given description part into the table of double node type
declaration identifiers. In the case of repeated double node type
declaration the function generates warning. */
static void
process_double_declaration_list (IR_node_t description_part)
{
IR_node_t current_double_declaration;
IR_node_t included_double_declaration_identifier;
if (IR_last_double_declaration (description_part) == NULL)
return;
for (current_double_declaration
= IR_next_double_declaration (IR_last_double_declaration
(description_part));;
current_double_declaration
= IR_next_double_declaration (current_double_declaration))
{
included_double_declaration_identifier
= insert_double_declaration_identifier
(IR_double_declaration_identifier (current_double_declaration));
if (included_double_declaration_identifier
!= IR_double_declaration_identifier (current_double_declaration))
{
assert
(strcmp
(IR_identifier_itself (IR_double_declaration_identifier
(current_double_declaration)),
IR_identifier_itself (included_double_declaration_identifier))
== 0);
if (v_flag)
{
warning
(IR_position (current_double_declaration),
"warning -- repeated declaration `%s' as double node type",
IR_identifier_itself
(included_double_declaration_identifier));
append_message
(IR_position (included_double_declaration_identifier),
"here the first declaration of double node type");
}
}
if (current_double_declaration
== IR_last_double_declaration (description_part))
break;
}
}
/* This function processes all predefined type and node type
declarations of given description part. The processing consists of
insertion of types into the table of types,
generation of warning for repeated predefined type
declaration,
fixing error for predefined type declaration which is early
declared as node type,
fixing error for node type declaration which is early
declared as predefined type,
fixing error for repeated node type declaration with
basic super types,
fixing error for abstract node type declaration without
basic super types,
setting up fields `first_declaration_level' and
`node_type_number' for node type declarations which
are inserted in the table,
setting up field `declaration_level' for all fields of
all processed node type declaration.
moving super types from given node type declaration
to corresponding node type declaration which is in
the table of types.
Remember that there may be a few declarations of a node type and
that all declarations of a node type are represented by internal
representation nodes `node_type'. */
static void
process_type_list (IR_node_t description_part)
{
IR_node_t current_field;
IR_node_t current_type;
IR_node_t original_type;
IR_node_t first_additional_super_type_list_element;
IR_node_t last_additional_super_type_list_element;
if (IR_last_type (description_part) == NULL)
return;
for (current_type = IR_next_type (IR_last_type (description_part));;
current_type = IR_next_type (current_type))
{
if (IR_NODE_MODE (current_type) == IR_NM_predefined_type)
{
original_type = insert_type (current_type);
if (original_type != current_type)
{
if (IR_NODE_MODE (original_type) != IR_NM_predefined_type)
{
error
(FALSE, IR_position (current_type),
"identifier `%s' is declared early as node type",
IR_identifier_itself (IR_type_identifier (current_type)));
append_message (IR_position (original_type),
"here declaration of the node type");
}
else if (v_flag)
{
warning
(IR_position (current_type),
"warning -- repeated declaration of predefined type `%s'",
IR_identifier_itself (IR_type_identifier (current_type)));
append_message (IR_position (original_type),
"here first declaration of predefined type");
}
}
}
else
{
assert (IR_NODE_MODE (current_type) == IR_NM_node_type);
/* Set up field level */
if (IR_last_field (current_type) != NULL)
for (current_field = IR_next_field (IR_last_field (current_type));;
current_field = IR_next_field (current_field))
{
if (IR_NODE_MODE (current_field) == IR_NM_field)
IR_set_declaration_level
(current_field,
IR_description_part_level (description_part));
if (current_field == IR_last_field (current_type))
break;
}
original_type = insert_type (current_type);
if (original_type != current_type)
{
if (IR_NODE_MODE (original_type) == IR_NM_predefined_type)
{
error
(FALSE, IR_position (current_type),
"identifier `%s' is declared early as predefined type",
IR_identifier_itself (IR_type_identifier (current_type)));
append_message (IR_position (original_type),
"here declaration of predefined type");
}
else
{
/* Types are node types. */
if (IR_abstract_flag (current_type)
&& (IR_first_super_type_list_element (current_type)
== NULL
|| !IR_basic_super_types_flag (current_type)))
error (FALSE, IR_position (current_type),
"`%%abstract' can't be without basic super types");
if (IR_first_super_type_list_element (current_type) != NULL)
{
if (IR_first_super_type_list_element (original_type)
!= NULL
&& IR_basic_super_types_flag (current_type)
&& IR_basic_super_types_flag (original_type))
{
error
(FALSE, IR_position (current_type),
"`%s' is declared early with basic super types",
IR_identifier_itself (IR_type_identifier
(current_type)));
append_message
(IR_position (IR_type_identifier (original_type)),
"here declaration with basic super types");
}
else
{
if (IR_first_super_type_list_element (original_type)
== NULL)
{
/* Move the list. */
IR_set_first_super_type_list_element
(original_type,
IR_first_super_type_list_element
(current_type));
IR_set_last_super_type_list_element
(original_type,
IR_last_super_type_list_element
(current_type));
IR_set_basic_super_types_flag
(original_type,
IR_basic_super_types_flag (current_type));
}
else
{
/* Merge two lists. */
if (IR_basic_super_types_flag (current_type))
{
first_additional_super_type_list_element
= IR_first_super_type_list_element
(original_type);
last_additional_super_type_list_element
= IR_last_super_type_list_element
(original_type);
IR_set_first_super_type_list_element
(original_type,
IR_first_super_type_list_element
(current_type));
IR_set_last_super_type_list_element
(original_type,
IR_last_super_type_list_element
(current_type));
}
else
{
first_additional_super_type_list_element
= IR_first_super_type_list_element
(current_type);
last_additional_super_type_list_element
= IR_last_super_type_list_element
(current_type);
}
IR_set_next_super_type_list_element
(IR_last_super_type_list_element
(original_type),
first_additional_super_type_list_element);
IR_set_last_super_type_list_element
(original_type,
last_additional_super_type_list_element);
IR_set_basic_super_types_flag
(original_type,
IR_basic_super_types_flag (current_type)
|| IR_basic_super_types_flag (original_type));
}
/* Delete from source list. */
IR_set_first_super_type_list_element (current_type,
NULL);
IR_set_last_super_type_list_element (current_type,
NULL);
}
}
}
}
else
{
IR_set_first_declaration_level
(current_type, IR_description_part_level (description_part));
IR_set_node_type_number (current_type, number_of_node_types);
number_of_node_types++;
}
}
if (current_type == IR_last_type (description_part))
break;
}
}
/* This function sets up field `double_node_flag' of given node type
to TRUE iff there is corresponding double node type declaration in
given description. Given node type must represents node type
declaration in given description part. */
static void
make_precise_double_node_flag (IR_node_t description_part, IR_node_t node_type)
{
IR_node_t included_identifier;
included_identifier = find_double_declaration_identifier (IR_type_identifier
(node_type));
if (included_identifier != NULL
&& strcmp (IR_position (included_identifier).file_name,
(IR_position (description_part).file_name)) == 0)
IR_set_double_node_flag (node_type, TRUE);
}
/* This function calls `make_precise_double_node_flag' for all node
type declaration in given description part and for node type
`%root'. Field `double_node_flag' of all node type declarations is
set up to FALSE before call of the function. Remember that there
may be a few declarations of a node type and that all declarations
of a node type are represented by internal representation nodes
`node_type'. */
static void
set_basic_double_node_flags (IR_node_t description_part)
{
IR_node_t current_type;
if (IR_last_type (description_part) == NULL)
return;
for (current_type = IR_next_type (IR_last_type (description_part));;
current_type = IR_next_type (current_type))
{
if (IR_NODE_MODE (current_type) == IR_NM_node_type)
make_precise_double_node_flag (description_part, current_type);
else
assert (IR_NODE_MODE (current_type) == IR_NM_predefined_type);
if (current_type == IR_last_type (description_part))
break;
}
/* For %root */
make_precise_double_node_flag (description_part, root_node_type);
}
/* The following recursive function marks given node type and all its
super types by value `flag'. */
static void
mark_node_type_and_its_super_types (IR_node_t node_type, int flag)
{
IR_node_t current_super_type_list_element;
assert (node_type != NULL);
IR_set_mark_flag (node_type, flag);
for (current_super_type_list_element
= IR_first_super_type_list_element (node_type);
current_super_type_list_element != NULL;
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element))
if (IR_immediate_super_type (current_super_type_list_element) != NULL)
mark_node_type_and_its_super_types
(IR_immediate_super_type (current_super_type_list_element), flag);
}
/* The following recursive function returns true if given node type
has a marked super type (except for root node type) or given node
type is marked itself. */
static int
it_has_a_non_root_marked_super_type (IR_node_t node_type)
{
IR_node_t current_super_type_list_element;
assert (node_type != NULL);
if (node_type != root_node_type)
{
if (IR_mark_flag (node_type))
return TRUE;
for (current_super_type_list_element
= IR_first_super_type_list_element (node_type);
current_super_type_list_element != NULL;
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element))
if (IR_immediate_super_type (current_super_type_list_element) != NULL
&&
it_has_a_non_root_marked_super_type
(IR_immediate_super_type (current_super_type_list_element)))
return TRUE;
}
return FALSE;
}
/* The following function returns TRUE if given node types have a
common super type (except for root node type). */
static int
there_is_common_super_type (IR_node_t node_type_1, IR_node_t node_type_2)
{
int result;
assert (node_type_1 != NULL && node_type_2 != NULL);
mark_node_type_and_its_super_types (node_type_1, TRUE);
result = it_has_a_non_root_marked_super_type (node_type_2);
mark_node_type_and_its_super_types (node_type_1, FALSE);
return result;
}
/* This function processes given node type declaration which is in the
table of types. The processing consists of
fixing error for given node type declaration
have undefined super types identifiers,
fixing error for using undeclared identifiers as super types,
fixing error for using predefined type identifier as
super type,
fixing error for using intersected super types,
setting up fields `immediate_super_type' for given
node type declaration.
This function is called from function
`traverse_description_part_node_types'. The node type is processed
only once by the function. Remember that there may be a few
declarations of a node type and that all declarations of a node
type are represented by internal representation nodes
`node_type'. */
static void
set_and_test_super_types (IR_node_t node_type)
{
IR_node_t original_type;
IR_node_t super_type;
IR_node_t current_super_type_list_element;
IR_node_t next_super_type_list_element;
IR_node_t previous_super_type_list_element;
IR_node_t check_super_type_list_element;
int change_previous_flag;
original_type = find_type (IR_type_identifier (node_type));
assert (original_type != NULL);
/* The original node may be processed many times this is necessary
because additional super types can be in new files. */
if (/* The following test is needed because of possible previous errors. */
IR_NODE_MODE (original_type) != IR_NM_node_type)
return;
if (original_type == node_type
&& (IR_first_super_type_list_element (original_type) == NULL
|| !IR_basic_super_types_flag (original_type))
&& original_type != root_node_type)
error
(FALSE, IR_position (original_type),
"basic super types aren't defined anywhere for node type `%s'",
IR_identifier_itself (IR_type_identifier (original_type)));
for (current_super_type_list_element
= IR_first_super_type_list_element (original_type),
previous_super_type_list_element = NULL;
current_super_type_list_element != NULL;
current_super_type_list_element = next_super_type_list_element)
{
next_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element);
if (!IR_setting_and_testing_super_type_was_made
(current_super_type_list_element))
{
IR_set_setting_and_testing_super_type_was_made
(current_super_type_list_element, TRUE);
super_type = find_type (IR_immediate_super_type_identifier
(current_super_type_list_element));
if (super_type == NULL)
error
(FALSE, IR_position (IR_immediate_super_type_identifier
(current_super_type_list_element)),
"undefined identifier `%s' is used as super type",
IR_identifier_itself (IR_immediate_super_type_identifier
(current_super_type_list_element)));
else if (IR_NODE_MODE (super_type) == IR_NM_predefined_type)
{
error
(FALSE, IR_position (IR_immediate_super_type_identifier
(current_super_type_list_element)),
"predefined type `%s' is used as super type",
IR_identifier_itself (IR_immediate_super_type_identifier
(current_super_type_list_element)));
append_message (IR_position (super_type),
"here declaration of predefined type");
super_type = NULL;
}
else
assert (IR_NODE_MODE (super_type) == IR_NM_node_type);
IR_set_immediate_super_type (current_super_type_list_element,
super_type);
/* Check common super types. */
change_previous_flag = TRUE;
for (check_super_type_list_element
= IR_first_super_type_list_element (original_type);
check_super_type_list_element
!= current_super_type_list_element;
check_super_type_list_element
= IR_next_super_type_list_element
(check_super_type_list_element))
if (super_type != NULL
&& (IR_immediate_super_type (check_super_type_list_element)
!= NULL))
{
if (super_type
== IR_immediate_super_type (check_super_type_list_element))
{
warning
(IR_position (IR_immediate_super_type_identifier
(current_super_type_list_element)),
"repeated occurrence `%s' as super type of `%s' is ignored",
IR_identifier_itself
(IR_immediate_super_type_identifier
(current_super_type_list_element)),
IR_identifier_itself (IR_type_identifier
(original_type)));
/* Delete repeated occurrence. */
if (previous_super_type_list_element == NULL)
IR_set_first_super_type_list_element
(original_type, next_super_type_list_element);
else
IR_set_next_super_type_list_element
(previous_super_type_list_element,
next_super_type_list_element);
if (next_super_type_list_element == NULL)
IR_set_last_super_type_list_element
(original_type, previous_super_type_list_element);
change_previous_flag = FALSE;
break;
}
else if (there_is_common_super_type
(IR_immediate_super_type
(check_super_type_list_element), super_type))
error
(FALSE, IR_position (IR_immediate_super_type_identifier
(current_super_type_list_element)),
"node type `%s' has intersected super types `%s' and `%s'",
IR_identifier_itself (IR_type_identifier (original_type)),
IR_identifier_itself (IR_immediate_super_type_identifier
(current_super_type_list_element)),
IR_identifier_itself (IR_immediate_super_type_identifier
(check_super_type_list_element)));
}
if (change_previous_flag)
previous_super_type_list_element = current_super_type_list_element;
}
}
}
/* The following recursive function returns TRUE if given node type
has a super type equal to the original node type. The function is
invoked such way it is known that given node type is a super type
of the original node type. */
static int
there_is_super_type_cycle (IR_node_t node_type, IR_node_t original_node_type)
{
IR_node_t current_super_type_list_element;
IR_node_t immediate_super_type;
if (node_type == original_node_type)
return TRUE;
for (current_super_type_list_element
= IR_first_super_type_list_element (node_type);
current_super_type_list_element != NULL;
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element))
{
immediate_super_type
= IR_immediate_super_type (current_super_type_list_element);
if (immediate_super_type != NULL
&& there_is_super_type_cycle (immediate_super_type,
original_node_type))
return TRUE;
}
return FALSE;
}
/* This function processes given node type declaration which is in the
table of types. The processing consists of only fixing error for
cycle in super types of given node type. This function is called
from function `traverse_description_part_node_types'. The node
type is processed only once by the function. Remember that there
may be a few declarations of a node type and that all declarations
of a node type are represented by internal representation nodes
`node_type'. */
static void
test_super_type_cycle (IR_node_t node_type)
{
IR_node_t original_type;
IR_node_t current_super_type_list_element;
IR_node_t immediate_super_type;
original_type = find_type (IR_type_identifier (node_type));
assert (original_type != NULL);
/* The original node may be processed many times this is necessary
because additional super types can be in new files. */
if (/* The following test is needed because of possible previous errors. */
IR_NODE_MODE (original_type) == IR_NM_node_type)
{
for (current_super_type_list_element
= IR_first_super_type_list_element (node_type);
current_super_type_list_element != NULL;
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element))
if (!IR_testing_super_type_cycle_was_made
(current_super_type_list_element))
{
IR_set_testing_super_type_cycle_was_made
(current_super_type_list_element, TRUE);
immediate_super_type
= IR_immediate_super_type (current_super_type_list_element);
if (immediate_super_type != NULL
&& there_is_super_type_cycle (immediate_super_type,
original_type))
error (FALSE, IR_position (IR_type_identifier
(immediate_super_type)),
"cycle in super type `%s' of node type `%s'",
IR_identifier_itself (IR_type_identifier
(immediate_super_type)),
IR_identifier_itself (IR_type_identifier
(original_type)));
}
}
}
/* The following recursive function sets up field
`secondary_super_type_flag' for given node type and for all its
super types below given original node type. */
static void
auxiliary_function_set_secondary_super_type_flags
(IR_node_t node_type, IR_node_t original_node_type)
{
IR_node_t current_super_type_list_element;
if (node_type == NULL || node_type == original_node_type)
return;
IR_set_secondary_super_type_flag (node_type, TRUE);
for (current_super_type_list_element
= IR_first_super_type_list_element (node_type);
current_super_type_list_element != NULL;
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element))
auxiliary_function_set_secondary_super_type_flags
(IR_immediate_super_type (current_super_type_list_element),
original_node_type);
}
/* The following function sets up fields `secondary_super_type_flag'
for all super types of given node type with the aid of function
`auxiliary_function_set_secondary_super_type_flags'. */
static void
set_secondary_super_type_flags (IR_node_t node_type)
{
IR_node_t current_super_type_list_element;
IR_node_t original_type;
original_type = find_type (IR_type_identifier (node_type));
assert (original_type != NULL);
/* The following test is needed because of possible previous errors. */
if (IR_NODE_MODE (original_type) != IR_NM_node_type)
return;
/* The original node may be processed many times this is necessary
because additional super types can be in new files. */
current_super_type_list_element
= IR_first_super_type_list_element (original_type);
if (current_super_type_list_element != NULL)
for (;;)
{
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element);
if (current_super_type_list_element == NULL)
break;
auxiliary_function_set_secondary_super_type_flags
(IR_immediate_super_type (current_super_type_list_element),
original_type);
}
}
/* The following recursive function sets up field `double_node_flag'
for all super types of given node if the field of given original
node type is already set up. */
static void
auxiliary_function_set_double_node_flags_for_subtypes
(IR_node_t node_type, IR_node_t original_node_type)
{
IR_node_t current_super_type_list_element;
IR_node_t immediate_super_type;
if (IR_double_node_flag (node_type))
IR_set_double_node_flag (original_node_type, TRUE);
else
for (current_super_type_list_element
= IR_first_super_type_list_element (node_type);
current_super_type_list_element != NULL;
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element))
{
immediate_super_type
= IR_immediate_super_type (current_super_type_list_element);
if (immediate_super_type != NULL
&& immediate_super_type != original_node_type)
auxiliary_function_set_double_node_flags_for_subtypes
(immediate_super_type, original_node_type);
}
}
/* This function processes node type declaration which is in the table
of types and corresponds to given node type declaration. The
processing consists of setting up field `double_node_flag' to TRUE
iff any its super type has field `double_node_flag' equals to
TRUE. This function is called from function
`traverse_description_part_node_types'. As a consequence the node
types may be processed a few time (if there a few node type
declarations in given description part). Remember that there may
be a few declarations of a node type and that all declarations of a
node type are represented by internal representation nodes
`node_type'. */
static void
set_double_node_flags_for_subtypes (IR_node_t node_type)
{
IR_node_t original_type;
original_type = find_type (IR_type_identifier (node_type));
assert (original_type != NULL);
/* The following test is needed because of previous errors. */
if (IR_NODE_MODE (original_type) == IR_NM_node_type)
auxiliary_function_set_double_node_flags_for_subtypes (original_type,
original_type);
}
/* This function processes all fields of given node type declaration.
The processing consists of
fixing error for using undefined identifier as field type,
setting up field `field_type',
setting up field `node_type' to node type declaration which
is in the table of types and corresponds to given
node type declaration,
insertion of field into the table of node fields.
fixing error for repeated declaration of field in
given node type,
moving field from given node type declaration
to corresponding node type declaration which is in
the table of types.
Remember that there may be a few declarations of a node type and
that all declarations of a node type are represented by internal
representation nodes `node_type'. This function is called from
function `traverse_description_part_node_types'. All fields are
processed only once by this function. */
static void
insert_field_and_set_field_type (IR_node_t node_type)
{
IR_node_t current_field;
IR_node_t original_type;
IR_node_t field_type;
IR_node_t original_field;
IR_node_t previous_field;
IR_node_t next_field;
int move_flag;
original_type = find_type (IR_type_identifier (node_type));
/* The following test is needed because of previous errors. */
if (IR_NODE_MODE (original_type) == IR_NM_node_type
&& IR_last_field (node_type) != NULL)
for (previous_field = IR_last_field (node_type),
current_field = IR_next_field (previous_field);;
current_field = next_field)
{
move_flag = FALSE;
next_field = IR_next_field (current_field);
if (IR_NODE_MODE (current_field) == IR_NM_field)
{
/* Set up field type. */
field_type = find_type (IR_field_type_identifier (current_field));
if (field_type == NULL)
error
(FALSE, IR_position (IR_field_type_identifier (current_field)),
"undefined identifier `%s' is used as field type",
IR_identifier_itself (IR_field_type_identifier
(current_field)));
else
assert (IR_NODE_MODE (field_type) == IR_NM_predefined_type
|| IR_NODE_MODE (field_type) == IR_NM_node_type);
IR_set_field_type (current_field, field_type);
/* Test with fields in the same node type. */
IR_set_node_type (current_field, original_type);
original_field = insert_node_field (current_field);
if (original_field != current_field)
{
error
(FALSE, IR_position (current_field),
"field `%s' is declared early in node type `%s'",
IR_identifier_itself (IR_field_identifier (current_field)),
IR_identifier_itself (IR_type_identifier (original_type)));
append_message (IR_position (original_field),
"here first declaration of the field");
}
else if (original_type != node_type)
move_flag = TRUE;
}
else
{
assert (IR_NODE_MODE (current_field) == IR_NM_action
|| IR_NODE_MODE (current_field) == IR_NM_constraint);
if (original_type != node_type)
move_flag = TRUE;
}
if (move_flag)
{
/* Delete from source list */
IR_set_next_field (previous_field, next_field);
/* Add field to original node type. */
if (IR_last_field (original_type) != NULL)
{
IR_set_next_field (current_field,
IR_next_field (IR_last_field
(original_type)));
IR_set_next_field (IR_last_field (original_type),
current_field);
}
else
IR_set_next_field (current_field, current_field);
IR_set_last_field (original_type, current_field);
if (current_field == IR_last_field (node_type))
{
if (current_field == next_field)
IR_set_last_field (node_type, NULL);
break;
}
}
else
{
previous_field = current_field;
if (current_field == IR_last_field (node_type))
break;
}
}
}
/* The following recursive function checks repeated declaration of
given field in super types of given node type. */
static void
test_field_presence_in_super_type_hierarchy (IR_node_t field,
IR_node_t node_type,
IR_node_t original_node_type)
{
IR_node_t super_type;
IR_node_t field_declaration_in_super_type;
IR_node_t current_super_type_list_element;
for (current_super_type_list_element
= IR_first_super_type_list_element (node_type);
current_super_type_list_element != NULL;
current_super_type_list_element
= IR_next_super_type_list_element (current_super_type_list_element))
{
super_type = IR_immediate_super_type (current_super_type_list_element);
if (super_type != NULL && super_type != original_node_type)
{
field_declaration_in_super_type
= find_node_field (IR_field_identifier (field), super_type);
if (field_declaration_in_super_type != NULL)
{
error (FALSE, IR_position (field),
"field `%s' is declared early in super type `%s'",
IR_identifier_itself (IR_field_identifier (field)),
IR_identifier_itself (IR_type_identifier (super_type)));
append_message (IR_position (field_declaration_in_super_type),
"here first declaration of the field");
}
test_field_presence_in_super_type_hierarchy (field, super_type,
original_node_type);
}
}
}
/* This recursive function processes given field. The processing
consists of only fixing error for declaration of the same field in