Skip to content

Commit 2a3e308

Browse files
committed
a68: remove coalesce_public_symbols shortcut
As planned, this commit removes a crude hack (the coalescing of 'pub' symbols right after bottom-up parsing) that I introduced during the initial implementation of modules. The goal was to get working separated compilation as soon as possible. Now the rest of the parser, and also the lowerer pass, is made to know about these 'pub' symbols. Signed-off-by: Jose E. Marchesi <[email protected]> gcc/algol68/ChangeLog * a68-parser-bottom-up.cc (a68_bottom_up_error_check): Do not check for the absence of public-symbols. (a68_bottom_up_coalesce_pub): Removed function. * a68-parser.cc (a68_parser): Do not call a68_bottom_up_coalesce_pub * a68-parser-extract.cc (a68_extract_indicants): Adapt to the presence of public-symbols. * a68-parser-modes.cc (get_mode_from_proc_variables): Likewise. * a68-parser-taxes.cc (tax_variable_dec): Likewise. (tax_proc_variable_dec): Likewise. (tax_op_dec): Likewise (tax_prio_dec): Likewise. * a68-low-decls.cc (a68_lower_mode_declaration): Adapt to the presence of public-symbols. (a68_lower_variable_declaration): Likewise. (a68_lower_identity_declaration): Likewise. (a68_lower_procedure_declaration): Likewise. (a68_lower_procedure_variable_declaration): Likewise. (a68_lower_brief_operator_declaration): Likewise. (a68_lower_operator_declaration): Likewise. gcc/testsuite/ChangeLog * algol68/compile/module-2.a68: Expand test a little.
1 parent 4ac3370 commit 2a3e308

File tree

7 files changed

+105
-72
lines changed

7 files changed

+105
-72
lines changed

gcc/algol68/a68-low-decls.cc

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
equals symbol, declarer;
4949
mode symbol, defining indicant,
5050
equals symbol, void symbol;
51+
public symbol, mode symbol, defining indicant,
52+
equals symbol, declarer;
53+
public symbol, mode symbol, defining indicant,
54+
equals symbol, void symbol;
5155
mode declaration, comma symbol,
5256
defining indicant, equals symbol, declarer;
5357
mode declaration, comma symbol,
@@ -71,8 +75,16 @@ a68_lower_mode_declaration (NODE_T *p, LOW_CTX_T ctx)
7175
}
7276
else
7377
{
74-
gcc_assert (IS (SUB (p), MODE_SYMBOL));
75-
defining_indicant = NEXT (SUB (p));
78+
if (IS (SUB (p), PUBLIC_SYMBOL))
79+
{
80+
gcc_assert (IS (NEXT (SUB (p)), MODE_SYMBOL));
81+
defining_indicant = NEXT (NEXT (SUB (p)));
82+
}
83+
else
84+
{
85+
gcc_assert (IS (SUB (p), MODE_SYMBOL));
86+
defining_indicant = NEXT (SUB (p));
87+
}
7688
}
7789

7890
/* Create a TYPE_DECL declaration for the defined mode and chain it in the
@@ -100,6 +112,12 @@ a68_lower_mode_declaration (NODE_T *p, LOW_CTX_T ctx)
100112
qualifier, declarer, defining identifier;
101113
declarer, defining identifier, assign symbol, unit;
102114
declarer, defining identifier;
115+
public symbol, qualifier, declarer, defining identifier,
116+
assign symbol, unit;
117+
public symbol, qualifier, declarer, defining identiifer;
118+
qualifier, declarer, defining identifier;
119+
public symbol, declarer, defining identifier, assign symbol, unit;
120+
declarer, defining identifier;
103121
variable declaration, comma symbol,
104122
defining identifier, assign symbol, unit;
105123
variable declaration, comma symbol,
@@ -135,21 +153,29 @@ a68_lower_variable_declaration (NODE_T *p, LOW_CTX_T ctx)
135153
sub_expr = a68_lower_tree (SUB (p), new_ctx);
136154
defining_identifier = NEXT (NEXT (SUB (p)));
137155
}
138-
else if (IS (SUB (p), QUALIFIER))
139-
{
140-
/* The qualifier determines what kind of generator is used in the
141-
variable declaration. This is already annotated in the tax entry for
142-
the definining identifier. */
143-
declarer = NEXT (SUB (p));
144-
defining_identifier = NEXT (NEXT (SUB (p)));
145-
}
146-
else if (IS (SUB (p), DECLARER))
156+
else
147157
{
148-
declarer = SUB (p);
149-
defining_identifier = NEXT (SUB (p));
158+
NODE_T *q = SUB (p);
159+
160+
if (IS (q, PUBLIC_SYMBOL))
161+
FORWARD (q);
162+
163+
if (IS (q, QUALIFIER))
164+
{
165+
/* The qualifier determines what kind of generator is used in the
166+
variable declaration. This is already annotated in the tax entry
167+
for the definining identifier. */
168+
declarer = NEXT (q);
169+
defining_identifier = NEXT (NEXT (q));
170+
}
171+
else if (IS (q, DECLARER))
172+
{
173+
declarer = q;
174+
defining_identifier = NEXT (q);
175+
}
176+
else
177+
gcc_unreachable ();
150178
}
151-
else
152-
gcc_unreachable ();
153179

154180
/* Communicate declarer upward. */
155181
if (ctx.declarer != NULL)
@@ -281,6 +307,8 @@ a68_lower_variable_declaration (NODE_T *p, LOW_CTX_T ctx)
281307
282308
identity declaration : declarer, defining identifier,
283309
equals symbol, unit;
310+
public symbol, declarer, defining identifier,
311+
equals symbol, unit;
284312
identity declaration, comma symbol,
285313
defining identifier, equals symbol, unit;
286314
@@ -310,6 +338,10 @@ a68_lower_identity_declaration (NODE_T *p, LOW_CTX_T ctx)
310338
sub_expr = a68_lower_tree (SUB (p), ctx);
311339
defining_identifier = NEXT (NEXT (SUB (p)));
312340
}
341+
else if (IS (SUB (p), PUBLIC_SYMBOL))
342+
{
343+
defining_identifier = NEXT (NEXT (SUB (p)));
344+
}
313345
else if (IS (SUB (p), DECLARER))
314346
{
315347
defining_identifier = NEXT (SUB (p));
@@ -443,6 +475,7 @@ a68_lower_declaration_list (NODE_T *p, LOW_CTX_T ctx)
443475
/* Lower a procedure declaration.
444476
445477
procedure declaration : proc symbol, defining identifier, assign symbol, routine text;
478+
public symbol, proc symbol, defining identifier, assign symbol, routine text;
446479
procedure declaration, comma symbol,
447480
defining identifier, equals symbol, routine text.
448481
@@ -458,6 +491,10 @@ a68_lower_procedure_declaration (NODE_T *p, LOW_CTX_T ctx)
458491
sub_func_decl = a68_lower_tree (SUB (p), ctx);
459492
defining_identifier = NEXT (NEXT (SUB (p)));
460493
}
494+
else if (IS (SUB (p), PUBLIC_SYMBOL))
495+
{
496+
defining_identifier = NEXT (NEXT (SUB (p)));
497+
}
461498
else if (IS (SUB (p), PROC_SYMBOL))
462499
{
463500
defining_identifier = NEXT (SUB (p));
@@ -493,6 +530,8 @@ a68_lower_procedure_declaration (NODE_T *p, LOW_CTX_T ctx)
493530
procedure variable declaration
494531
: proc symbol, defining identifier, assign symbol, routine text;
495532
qualifier, proc symbol, defining identifier, assign symbol, routine text;
533+
public symbol, proc symbol, defining identifier, assign symbol, routine text;
534+
public symbol, qualifier, proc symbol, defining identifier, assign symbol, routine text;
496535
procedure variable declaration, comma symbol, defining identiier, assign symbol, routine text.
497536
498537
This lowers into the declaration of a VAR_DECL which is a pointer to the
@@ -508,15 +547,24 @@ a68_lower_procedure_variable_declaration (NODE_T *p, LOW_CTX_T ctx)
508547
sub_decl = a68_lower_tree (SUB (p), ctx);
509548
defining_identifier = NEXT (NEXT (SUB (p)));
510549
}
511-
else if (IS (SUB (p), PROC_SYMBOL))
512-
defining_identifier = NEXT (SUB (p));
513-
else if (IS (SUB (p), QUALIFIER))
514-
/* The qualifier determines what kind of generator is used in the variable
515-
declaration. This is already annotated in the tax entry for the
516-
definining identifier. */
517-
defining_identifier = NEXT (NEXT (SUB (p)));
518550
else
519-
gcc_unreachable ();
551+
{
552+
NODE_T *q = SUB (p);
553+
554+
if (IS (q, PUBLIC_SYMBOL))
555+
FORWARD (q);
556+
557+
if (IS (q, PROC_SYMBOL))
558+
defining_identifier = NEXT (q);
559+
else if (IS (q, QUALIFIER))
560+
/* The qualifier determines what kind of generator is used in the
561+
variable declaration. This is already annotated in the tax entry
562+
for the definining identifier. */
563+
defining_identifier = NEXT (NEXT (q));
564+
else
565+
gcc_unreachable ();
566+
}
567+
520568
NODE_T *routine_text = NEXT (NEXT (defining_identifier));
521569

522570
/* The routine text lowers into a pointer to function. */
@@ -590,6 +638,7 @@ a68_lower_priority_declaration (NODE_T *p ATTRIBUTE_UNUSED,
590638
591639
brief operator declaration
592640
: op symbol, defining operator, equals symbol, routine text;
641+
public symbol, op symbol, defining operator, equals symbol, routine text;
593642
brief operator declaration, comma symbol, defining operator, equals symbol, routine text.
594643
595644
The declarations low in a series of FUNCTION_DECLs, one per declared
@@ -607,7 +656,15 @@ a68_lower_brief_operator_declaration (NODE_T *p, LOW_CTX_T ctx)
607656
defining_operator = NEXT (NEXT (SUB (p)));
608657
}
609658
else
610-
defining_operator = NEXT (SUB (p));
659+
{
660+
if (IS (SUB (p), PUBLIC_SYMBOL))
661+
{
662+
gcc_assert (IS (NEXT (SUB (p)), OP_SYMBOL));
663+
defining_operator = NEXT (NEXT (SUB (p)));
664+
}
665+
else
666+
defining_operator = NEXT (SUB (p));
667+
}
611668
NODE_T *routine_text = NEXT (NEXT (defining_operator));
612669

613670
/* Lower the routine text to get a function decl. */
@@ -634,6 +691,7 @@ a68_lower_brief_operator_declaration (NODE_T *p, LOW_CTX_T ctx)
634691
/* Lower an operator declaration.
635692
636693
operator declaration : operator plan, defining operator, equals symbol, unit;
694+
public symbol, operator plan, defining operator, equals symbol, unit;
637695
operator declaration, comma symbol, defining operator, equals symbol, unit.
638696
639697
Each operator declaration lowers into a declaration. */
@@ -650,7 +708,12 @@ a68_lower_operator_declaration (NODE_T *p, LOW_CTX_T ctx)
650708
defining_operator = NEXT (NEXT (SUB (p)));
651709
}
652710
else
653-
defining_operator = NEXT (SUB (p));
711+
{
712+
if (IS (SUB (p), PUBLIC_SYMBOL))
713+
defining_operator = NEXT (NEXT (SUB (p)));
714+
else
715+
defining_operator = NEXT (SUB (p));
716+
}
654717
NODE_T *unit = NEXT (NEXT (defining_operator));
655718

656719
tree op_decl = TAX_TREE_DECL (TAX (defining_operator));

gcc/algol68/a68-parser-bottom-up.cc

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,13 +2900,6 @@ a68_bottom_up_error_check (NODE_T *p)
29002900
a68_error (p, "incorrect number of pictures for A",
29012901
ATTRIBUTE (p));
29022902
}
2903-
else if (IS (p, PUBLIC_SYMBOL))
2904-
{
2905-
/* These should have been removed by a68_bottom_up_coalesce_pub and
2906-
by a68_extract_indicants. */
2907-
/* XXX get rid of this. */
2908-
gcc_unreachable ();
2909-
}
29102903
else if (a68_is_one_of (p, DEFINING_INDICANT, DEFINING_IDENTIFIER, DEFINING_OPERATOR, STOP))
29112904
{
29122905
if (PUBLICIZED (p) && !PUBLIC_RANGE (TABLE (p)))
@@ -3004,31 +2997,3 @@ a68_rearrange_goto_less_jumps (NODE_T *p)
30042997
a68_rearrange_goto_less_jumps (SUB (p));
30052998
}
30062999
}
3007-
3008-
/*
3009-
* Remove PUBLIC_SYMBOLs resulting from reductions from the tree. Note that
3010-
* the defining indicants, identifiers and operators have been already marked
3011-
* as publicized or not publicized by the extract routines.
3012-
*/
3013-
3014-
void
3015-
a68_bottom_up_coalesce_pub (NODE_T *p)
3016-
{
3017-
for (; p != NO_NODE; FORWARD (p))
3018-
{
3019-
if (a68_is_one_of (p,
3020-
MODE_DECLARATION, PROCEDURE_DECLARATION, PRIORITY_DECLARATION,
3021-
PROCEDURE_VARIABLE_DECLARATION, BRIEF_OPERATOR_DECLARATION,
3022-
OPERATOR_DECLARATION, IDENTITY_DECLARATION,
3023-
VARIABLE_DECLARATION, STOP))
3024-
{
3025-
if (SUB (p) != NO_NODE && IS (SUB (p), PUBLIC_SYMBOL))
3026-
{
3027-
NODE_T *public_symbol = SUB (p);
3028-
SUB (p) = NEXT (public_symbol);
3029-
PREVIOUS (NEXT (public_symbol)) = NO_NODE;
3030-
}
3031-
}
3032-
a68_bottom_up_coalesce_pub (SUB (p));
3033-
}
3034-
}

gcc/algol68/a68-parser-extract.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ a68_elaborate_bold_tags (NODE_T *p)
168168
static NODE_T *
169169
skip_pack_declarer (NODE_T *p)
170170
{
171-
/* Skip () REF [] REF FLEX [] [] ... */
171+
/* Skip PUB () REF [] REF FLEX [] [] ... */
172172
while (p != NO_NODE
173173
&& (a68_is_one_of (p, SUB_SYMBOL, OPEN_SYMBOL, REF_SYMBOL,
174174
FLEX_SYMBOL, SHORT_SYMBOL, LONG_SYMBOL, STOP)))
@@ -354,10 +354,7 @@ a68_extract_indicants (NODE_T *p)
354354
{
355355
NODE_T *pub_node = q;
356356
extract_revelation (NEXT (pub_node), true /* is_public */);
357-
/* XXX get rid of this crap. */
358-
PREVIOUS (NEXT (pub_node)) = PREVIOUS (pub_node);
359-
if (PREVIOUS (pub_node) != NO_NODE)
360-
NEXT (PREVIOUS (pub_node)) = NEXT (pub_node);
357+
FORWARD (q);
361358
FORWARD (q);
362359
}
363360
}

gcc/algol68/a68-parser-modes.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ get_mode_from_proc_variables (NODE_T *p)
766766
get_mode_from_proc_variables (SUB (p));
767767
get_mode_from_proc_variables (NEXT (p));
768768
}
769-
else if (IS (p, QUALIFIER) || IS (p, PROC_SYMBOL) || IS (p, COMMA_SYMBOL))
769+
else if (IS (p, PUBLIC_SYMBOL) || IS (p, QUALIFIER) || IS (p, PROC_SYMBOL) || IS (p, COMMA_SYMBOL))
770770
{
771771
get_mode_from_proc_variables (NEXT (p));
772772
}

gcc/algol68/a68-parser-taxes.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,10 @@ tax_identity_dec (NODE_T *p, MOID_T **m)
890890
tax_identity_dec (SUB (p), m);
891891
tax_identity_dec (NEXT (p), m);
892892
}
893+
else if (IS (p, PUBLIC_SYMBOL))
894+
{
895+
tax_identity_dec (NEXT (p), m);
896+
}
893897
else if (IS (p, DECLARER))
894898
{
895899
tax_tags (SUB (p));
@@ -939,6 +943,10 @@ tax_variable_dec (NODE_T *p, int *q, MOID_T **m, bool e)
939943
tax_variable_dec (SUB (p), q, m, e);
940944
tax_variable_dec (NEXT (p), q, m, e);
941945
}
946+
else if (IS (p, PUBLIC_SYMBOL))
947+
{
948+
tax_variable_dec (NEXT (p), q, m, e);
949+
}
942950
else if (IS (p, DECLARER))
943951
{
944952
tax_tags (SUB (p));
@@ -1009,7 +1017,7 @@ tax_proc_variable_dec (NODE_T *p, int *q, bool e)
10091017
*q = ATTRIBUTE (SUB (p));
10101018
tax_proc_variable_dec (NEXT (p), q, true);
10111019
}
1012-
else if (a68_is_one_of (p, PROC_SYMBOL, COMMA_SYMBOL, STOP))
1020+
else if (a68_is_one_of (p, PUBLIC_SYMBOL, PROC_SYMBOL, COMMA_SYMBOL, STOP))
10131021
{
10141022
tax_proc_variable_dec (NEXT (p), q, e);
10151023
}
@@ -1059,7 +1067,7 @@ tax_proc_dec (NODE_T *p)
10591067
tax_proc_dec (SUB (p));
10601068
tax_proc_dec (NEXT (p));
10611069
}
1062-
else if (a68_is_one_of (p, PROC_SYMBOL, COMMA_SYMBOL, STOP))
1070+
else if (a68_is_one_of (p, PUBLIC_SYMBOL, PROC_SYMBOL, COMMA_SYMBOL, STOP))
10631071
{
10641072
tax_proc_dec (NEXT (p));
10651073
}
@@ -1136,7 +1144,7 @@ tax_op_dec (NODE_T *p, MOID_T **m)
11361144
{
11371145
tax_op_dec (NEXT (p), m);
11381146
}
1139-
else if (IS (p, COMMA_SYMBOL))
1147+
else if (a68_is_one_of (p, PUBLIC_SYMBOL, COMMA_SYMBOL, STOP))
11401148
{
11411149
tax_op_dec (NEXT (p), m);
11421150
}
@@ -1211,7 +1219,7 @@ tax_brief_op_dec (NODE_T *p)
12111219
tax_brief_op_dec (SUB (p));
12121220
tax_brief_op_dec (NEXT (p));
12131221
}
1214-
else if (a68_is_one_of (p, OP_SYMBOL, COMMA_SYMBOL, STOP))
1222+
else if (a68_is_one_of (p, PUBLIC_SYMBOL, OP_SYMBOL, COMMA_SYMBOL, STOP))
12151223
{
12161224
tax_brief_op_dec (NEXT (p));
12171225
}
@@ -1247,7 +1255,7 @@ static void tax_prio_dec (NODE_T *p)
12471255
tax_prio_dec (SUB (p));
12481256
tax_prio_dec (NEXT (p));
12491257
}
1250-
else if (a68_is_one_of (p, PRIO_SYMBOL, COMMA_SYMBOL, STOP))
1258+
else if (a68_is_one_of (p, PUBLIC_SYMBOL, PRIO_SYMBOL, COMMA_SYMBOL, STOP))
12511259
{
12521260
tax_prio_dec (NEXT (p));
12531261
}

gcc/algol68/a68-parser.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ a68_parser (const char *filename)
522522
// printf ("AFTER PRELIMINARY SYMBOL TABLE SETUP\n");
523523
// a68_dump_parse_tree (TOP_NODE (&A68_JOB), true);
524524
a68_bottom_up_parser (TOP_NODE (&A68_JOB));
525-
a68_bottom_up_coalesce_pub (TOP_NODE (&A68_JOB));
526525
renum = 0;
527526
renumber_nodes (TOP_NODE (&A68_JOB), &renum);
528527
}

gcc/testsuite/algol68/compile/module-2.a68

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module Foo = def pub int idpublic = 10;
44
real varprivate := 3.14;
55
pub proc lala = (int a, b) int: a + b;
66
pub proc lele := (int a, b) int: a - b;
7+
pub proc(int,int)int lili := (int a, b) int: a * b;
78
skip
89
fed

0 commit comments

Comments
 (0)