Skip to content

Commit f3d9820

Browse files
committed
a68: support for publicized modules
This commit adds support for modules publicizing the exports of other modules. For example: module GRAMP = access pub GRAMP_Symbol, pub GRAMP_Word, pub GRAMP_Alphabet def pub string libgramp_version = "1.0"; skip fed Signed-off-by: Jose E. Marchesi <[email protected]> gcc/algol68/ChangeLog * a68-parser-taxes.cc (tax_module_dec): Do not handle DEFINING_MODULE_INDICANT. * a68-exports.cc (a68_add_module_to_moif): Do not mangle module names in module extracts. (add_pub_revelations_to_moif): New function. (a68_do_exports): Simplify and call add_pub_revelations_to_moif. * a68-imports.cc (a68_decode_moifs): Add all decoded moifs to the global list TOP_MOIF. * a68-parser-extract.cc (extract_revelation): Recurse to import extracts from publicized modules. (a68_extract_indicants): Do not add symbol table entries for defining modules. * a68-types.h (struct TAG_T): Remove field EXPORTED. (EXPORTED): Remove macro. (TOP_MOIF): Define. * a68-parser.cc (a68_parser): Initialize global list of moifs. (a68_new_tag): Do not initialize EXPORTED. gcc/testsuite/ChangeLog * algol68/execute/modules/module22bar.a68: New test. * algol68/execute/modules/module22foo.a68: Likewise. * algol68/execute/modules/program-22.a68: Likewise. * algol68/compile/modules/program-11.a68: Adjust test to publicized modules. * algol68/compile/modules/program-error-multiple-delaration-module-1.a68: Likewise.
1 parent f129bfb commit f3d9820

File tree

11 files changed

+152
-111
lines changed

11 files changed

+152
-111
lines changed

gcc/algol68/a68-exports.cc

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ static void
131131
a68_add_module_to_moif (MOIF_T *moif, TAG_T *tag)
132132
{
133133
EXTRACT_T *e = ggc_alloc<EXTRACT_T> ();
134-
/* Module tags are not associated with declarations, so we have to do the
135-
mangling here. */
136-
tree id = a68_get_mangled_indicant (NSYMBOL (NODE (tag)), NAME (moif));
137-
const char *tag_symbol = IDENTIFIER_POINTER (id);
134+
const char *tag_symbol = NSYMBOL (NODE (tag));
138135

139136
EXTRACT_KIND (e) = GA68_EXTRACT_MODU;
140137
EXTRACT_SYMBOL (e) = ggc_strdup (tag_symbol);
@@ -525,6 +522,26 @@ a68_asm_output_moif (MOIF_T *moif)
525522
}
526523
}
527524

525+
/* Add module exports for publicized module revelations. */
526+
527+
static void
528+
add_pub_revelations_to_moif (MOIF_T *moif, NODE_T *p)
529+
{
530+
for (; p != NO_NODE; FORWARD (p))
531+
{
532+
if (IS (p, PUBLIC_SYMBOL))
533+
{
534+
gcc_assert (IS (NEXT (p), MODULE_INDICANT));
535+
TAG_T *tag = a68_new_tag ();
536+
NODE (tag) = NEXT (p);
537+
a68_add_module_to_moif (moif, tag);
538+
FORWARD (p);
539+
}
540+
else
541+
add_pub_revelations_to_moif (moif, SUB (p));
542+
}
543+
}
544+
528545
/* Emit export information for the module definition in the parse tree P. */
529546

530547
void
@@ -534,65 +551,59 @@ a68_do_exports (NODE_T *p)
534551
{
535552
if (IS (p, DEFINING_MODULE_INDICANT))
536553
{
537-
// XXX only do this if the defining module is to be
538-
// exported. Accessed modules without PUB are not exported. */
539-
TAG_T *tag = a68_find_tag_global (TABLE (p), MODULE_SYMBOL, NSYMBOL (p));
540-
gcc_assert (tag != NO_TAG);
554+
tree module_id = a68_get_mangled_indicant (NSYMBOL (p));
555+
MOIF_T *moif = a68_moif_new (IDENTIFIER_POINTER (module_id));
556+
char *prelude = xasprintf ("%s__prelude", IDENTIFIER_POINTER (module_id));
557+
char *postlude = xasprintf ("%s__postlude", IDENTIFIER_POINTER (module_id));
558+
PRELUDE (moif) = ggc_strdup (prelude);
559+
POSTLUDE (moif) = ggc_strdup (postlude);
560+
free (prelude);
561+
free (postlude);
562+
563+
NODE_T *module_text = NEXT (NEXT (p));
564+
gcc_assert (IS (module_text, MODULE_TEXT));
565+
566+
/* Get modules exports from the revelation part. */
567+
if (IS (SUB (module_text), REVELATION_PART))
568+
{
569+
NODE_T *revelation_part = SUB (module_text);
570+
add_pub_revelations_to_moif (moif, SUB (revelation_part));
571+
}
541572

542-
if (EXPORTED (tag))
573+
NODE_T *def_part = (IS (SUB (module_text), REVELATION_PART)
574+
? NEXT_SUB (module_text)
575+
: SUB (module_text));
576+
gcc_assert (IS (def_part, DEF_PART));
577+
TABLE_T *table = TABLE (SUB (def_part));
578+
gcc_assert (PUBLIC_RANGE (table));
579+
580+
for (TAG_T *t = INDICANTS (table); t != NO_TAG; FORWARD (t))
543581
{
544-
tree module_id = a68_get_mangled_indicant (NSYMBOL (p));
545-
MOIF_T *moif = a68_moif_new (IDENTIFIER_POINTER (module_id));
546-
char *prelude = xasprintf ("%s__prelude", IDENTIFIER_POINTER (module_id));
547-
char *postlude = xasprintf ("%s__postlude", IDENTIFIER_POINTER (module_id));
548-
PRELUDE (moif) = ggc_strdup (prelude);
549-
POSTLUDE (moif) = ggc_strdup (postlude);
550-
free (prelude);
551-
free (postlude);
552-
553-
NODE_T *module_text = NEXT (NEXT (p));
554-
gcc_assert (IS (module_text, MODULE_TEXT));
555-
NODE_T *def_part = (IS (SUB (module_text), REVELATION_PART)
556-
? NEXT_SUB (module_text)
557-
: SUB (module_text));
558-
gcc_assert (IS (def_part, DEF_PART));
559-
TABLE_T *table = TABLE (SUB (def_part));
560-
gcc_assert (PUBLIC_RANGE (table));
561-
562-
for (TAG_T *t = MODULES (table); t != NO_TAG; FORWARD (t))
563-
{
564-
if (PUBLICIZED (t))
565-
a68_add_module_to_moif (moif, t);
566-
}
567-
568-
for (TAG_T *t = INDICANTS (table); t != NO_TAG; FORWARD (t))
569-
{
570-
if (PUBLICIZED (t))
571-
a68_add_indicant_to_moif (moif, t);
572-
}
573-
574-
for (TAG_T *t = IDENTIFIERS (table); t != NO_TAG; FORWARD (t))
575-
{
576-
if (PUBLICIZED (t))
577-
a68_add_identifier_to_moif (moif, t);
578-
}
579-
580-
for (TAG_T *t = PRIO (table); t != NO_TAG; FORWARD (t))
581-
{
582-
if (PUBLICIZED (t))
583-
a68_add_prio_to_moif (moif, t);
584-
}
585-
586-
for (TAG_T *t = OPERATORS (table); t != NO_TAG; FORWARD (t))
587-
{
588-
if (PUBLICIZED (t))
589-
a68_add_operator_to_moif (moif, t);
590-
}
591-
592-
a68_asm_output_moif (moif);
593-
if (flag_a68_dump_moif)
594-
a68_dump_moif (moif);
582+
if (PUBLICIZED (t))
583+
a68_add_indicant_to_moif (moif, t);
595584
}
585+
586+
for (TAG_T *t = IDENTIFIERS (table); t != NO_TAG; FORWARD (t))
587+
{
588+
if (PUBLICIZED (t))
589+
a68_add_identifier_to_moif (moif, t);
590+
}
591+
592+
for (TAG_T *t = PRIO (table); t != NO_TAG; FORWARD (t))
593+
{
594+
if (PUBLICIZED (t))
595+
a68_add_prio_to_moif (moif, t);
596+
}
597+
598+
for (TAG_T *t = OPERATORS (table); t != NO_TAG; FORWARD (t))
599+
{
600+
if (PUBLICIZED (t))
601+
a68_add_operator_to_moif (moif, t);
602+
}
603+
604+
a68_asm_output_moif (moif);
605+
if (flag_a68_dump_moif)
606+
a68_dump_moif (moif);
596607
}
597608
else
598609
a68_do_exports (SUB (p));

gcc/algol68/a68-imports.cc

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,11 +1286,11 @@ a68_decode_extracts (MOIF_T *moif, encoded_modes_map_t &encoded_modes,
12861286
return false;
12871287
}
12881288

1289-
/* Decode the given exports data into a linked list of moifs. If there is a
1290-
decoding error then put an explicative mssage in *ERRSTR and return
1291-
NULL. */
1289+
/* Decode the given exports data into moifs, add them to the TOP_MOIF list, and
1290+
return true. If there is a decoding error then put an explicative message
1291+
in *ERRSTR and return false. */
12921292

1293-
static MOIF_T *
1293+
static bool
12941294
a68_decode_moifs (const char *data, size_t size, const char **errstr)
12951295
{
12961296
MOIF_T *moif_list = NO_MOIF;
@@ -1349,12 +1349,25 @@ a68_decode_moifs (const char *data, size_t size, const char **errstr)
13491349
}
13501350
}
13511351

1352-
/* Got some juicy exports for youuuuuu... */
1353-
return moif_list;
1352+
/* Add the moifs in moif_list to the global list of moifs. */
1353+
/* XXX error and fail on duplicates? */
1354+
{
1355+
MOIF_T *end = TOP_MOIF (&A68_JOB);
1356+
if (end == NO_MOIF)
1357+
TOP_MOIF (&A68_JOB) = moif_list;
1358+
else
1359+
{
1360+
while (NEXT (end) != NO_MOIF)
1361+
FORWARD (end);
1362+
NEXT (end) = moif_list;
1363+
}
1364+
}
1365+
1366+
return true;
13541367
decode_error:
13551368
if (*errstr == NULL)
13561369
*errstr = "premature end of data";
1357-
return NULL;
1370+
return false;
13581371
}
13591372

13601373
/* Get a moif with the exports for module named MODULE. If no exports can be
@@ -1395,11 +1408,16 @@ a68_open_packet (const char *module)
13951408

13961409
/* Got some data. Decode it into a list of moif. */
13971410
const char *errstr = NULL;
1398-
MOIF_T *moif = a68_decode_moifs (exports_data, exports_data_size, &errstr);
1411+
if (!a68_decode_moifs (exports_data, exports_data_size, &errstr))
1412+
{
1413+
a68_error (NO_NODE, "%s", errstr);
1414+
return NULL;
1415+
}
13991416

1400-
/* The moif we are looking for must be in the list. Note these are garbage
1401-
collected. */
1417+
/* The androids we are looking for are likely to be now in the global
1418+
list. */
1419+
MOIF_T *moif = TOP_MOIF (&A68_JOB);
14021420
while (moif != NO_MOIF && strcmp (NAME (moif), module) != 0)
1403-
moif = NEXT (moif);
1421+
FORWARD (moif);
14041422
return moif;
14051423
}

gcc/algol68/a68-parser-extract.cc

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,30 @@ skip_pack_declarer (NODE_T *p)
185185
return p;
186186
}
187187

188-
/* Extract a revelation. */
188+
/* Extract the revelation associated with the module MODULE. The node Q is
189+
used for symbol table and diagnostic purposes. Publicized modules are
190+
recursively extracted as well. This call may result in one or more
191+
errors. */
189192

190193
static void
191-
extract_revelation (NODE_T *q, bool is_public ATTRIBUTE_UNUSED)
194+
extract_revelation (NODE_T *q, const char *module, TAG_T *tag)
192195
{
193-
/* Store in the symbol table. */
194-
TAG_T *tag = a68_add_tag (TABLE (q), MODULE_SYMBOL, q, NO_MOID, STOP);
195-
gcc_assert (tag != NO_TAG);
196-
EXPORTED (tag) = false; // XXX depends on PUB!
197196
/* Import the MOIF and install it in the tag. */
198-
MOIF_T *moif = a68_open_packet (NSYMBOL (q));
197+
MOIF_T *moif = a68_open_packet (module);
199198
if (moif == NULL)
200199
{
201-
a68_error (q, "cannot find module Z", NSYMBOL (q));
200+
a68_error (q, "cannot find module Z", module);
202201
return;
203202
}
204-
MOIF (tag) = moif; // XXX add to existing list of moifs.
203+
204+
if (tag != NO_TAG)
205+
MOIF (tag) = moif;
206+
207+
/* First thing to do is to extract the revelations of publicized modules in
208+
this moif. This leads to recursive calls of this function. */
209+
210+
for (EXTRACT_T *e : MODULES (moif))
211+
extract_revelation (q, EXTRACT_SYMBOL (e), NO_TAG);
205212

206213
/* Store all the modes from the MOIF in the moid list.
207214
@@ -345,18 +352,26 @@ a68_extract_indicants (NODE_T *p)
345352
FORWARD (q);
346353
if (q != NO_NODE)
347354
{
355+
NODE_T *bold_tag = NO_NODE;
356+
348357
if (IS (q, BOLD_TAG))
349358
{
350-
extract_revelation (q, false /* is_public */);
359+
bold_tag = q;
351360
FORWARD (q);
352361
}
353362
else if (a68_whether (q, PUBLIC_SYMBOL, BOLD_TAG, STOP))
354363
{
355-
NODE_T *pub_node = q;
356-
extract_revelation (NEXT (pub_node), true /* is_public */);
364+
bold_tag = NEXT (q);
357365
FORWARD (q);
358366
FORWARD (q);
359367
}
368+
369+
if (bold_tag != NO_NODE)
370+
{
371+
TAG_T *tag = a68_add_tag (TABLE (bold_tag), MODULE_SYMBOL, bold_tag, NO_MOID, STOP);
372+
gcc_assert (tag != NO_TAG);
373+
extract_revelation (bold_tag, NSYMBOL (bold_tag), tag);
374+
}
360375
}
361376
}
362377
while (q != NO_NODE && IS (q, COMMA_SYMBOL));
@@ -370,14 +385,7 @@ a68_extract_indicants (NODE_T *p)
370385
detect_redefined_keyword (q, MODULE_DECLARATION);
371386
if (a68_whether (q, BOLD_TAG, EQUALS_SYMBOL, STOP))
372387
{
373-
/* Store in the symbol table.
374-
XXX also add to global list of modules?
375-
Position of definition (q) connects to this lexical
376-
level! */
377388
ATTRIBUTE (q) = DEFINING_MODULE_INDICANT;
378-
TAG_T *tag = a68_add_tag (TABLE (p), MODULE_SYMBOL, q, NO_MOID, STOP);
379-
gcc_assert (tag != NO_TAG);
380-
EXPORTED (tag) = true;
381389
FORWARD (q);
382390
ATTRIBUTE (q) = EQUALS_SYMBOL; /* XXX why not ALT_EQUALS_SYMBOL */
383391
if (NEXT (q) != NO_NODE && IS (NEXT (q), ACCESS_SYMBOL))

gcc/algol68/a68-parser-taxes.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,18 +1188,6 @@ tax_module_dec (NODE_T *p)
11881188
{
11891189
tax_module_dec (NEXT (p));
11901190
}
1191-
else if (IS (p, DEFINING_MODULE_INDICANT))
1192-
{
1193-
TAG_T *entry = MODULES (TABLE (p));
1194-
while (entry != NO_TAG && NODE (entry) != p)
1195-
FORWARD (entry);
1196-
MOID (p) = NO_MOID;
1197-
TAX (p) = entry;
1198-
HEAP (entry) = LOC_SYMBOL;
1199-
MOID (entry) = NO_MOID;
1200-
PUBLICIZED (entry) = PUBLICIZED (p);
1201-
tax_module_dec (NEXT (p));
1202-
}
12031191
else
12041192
{
12051193
tax_tags (p);

gcc/algol68/a68-parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ a68_parser (const char *filename)
446446
A68_PARSER (error_tag) = (TAG_T *) a68_new_tag ();
447447
TOP_NODE (&A68_JOB) = NO_NODE;
448448
TOP_MOID (&A68_JOB) = NO_MOID;
449+
TOP_MOIF (&A68_JOB) = NO_MOIF;
449450
TOP_LINE (&A68_JOB) = NO_LINE;
450451
STANDENV_MOID (&A68_JOB) = NO_MOID;
451452
a68_set_up_tables ();
@@ -784,7 +785,6 @@ a68_new_tag (void)
784785
VARIABLE (z) = false;
785786
IS_RECURSIVE (z) = false;
786787
PUBLICIZED (z) = true; /* XXX */
787-
EXPORTED (z) = false;
788788
ASCRIBED_ROUTINE_TEXT (z) = false;
789789
LOWERER (z) = NO_LOWERER;
790790
TAX_TREE_DECL (z) = NULL_TREE;

gcc/algol68/a68-types.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,6 @@ struct GTY(()) TABLE_T
585585
PUBLICIZED is set for tags that are marked as public and therefore shall be
586586
exported as part of a module interface.
587587
588-
EXPORTED is set for DEFINING_MODULEs whose module interface is to be
589-
exported.
590-
591588
ASCRIBED_ROUTINE_TEXT is set when the defining identifier is ascribed a
592589
routine-text in an identity declaration.
593590
@@ -621,7 +618,7 @@ struct GTY((chain_next ("%h.next"))) TAG_T
621618
NODE_T *node, *unit;
622619
const char *value;
623620
bool scope_assigned, use, in_proc, loc_assigned, portable, variable;
624-
bool ascribed_routine_text, is_recursive, publicized, exported;
621+
bool ascribed_routine_text, is_recursive, publicized;
625622
int priority, heap, scope, youngest_environ, number;
626623
STATUS_MASK_T status;
627624
tree tree_decl;
@@ -645,6 +642,7 @@ struct GTY(()) MODULE_T
645642
int error_count, warning_count, source_scan;
646643
LINE_T *top_line;
647644
MOID_T *top_moid, *standenv_moid;
645+
MOIF_T *top_moif;
648646
NODE_T *top_node;
649647
OPTIONS_T options;
650648
FILE * GTY ((skip)) file_source_fd;
@@ -930,7 +928,6 @@ struct GTY(()) A68_T
930928
#define EQUIVALENT(p) ((p)->equivalent_mode)
931929
#define EQUIVALENT_MODE(p) ((p)->equivalent_mode)
932930
#define ERROR_COUNT(p) ((p)->error_count)
933-
#define EXPORTED(p) ((p)->exported)
934931
#define EXTERN_SYMBOL(p) ((p)->extern_symbol)
935932
#define EXTRACT_IN_PROC(p) ((p)->in_proc)
936933
#define EXTRACT_KIND(p) ((p)->kind)
@@ -1097,6 +1094,7 @@ struct GTY(()) A68_T
10971094
#define TEXT(p) ((p)->text)
10981095
#define TOP_LINE(p) ((p)->top_line)
10991096
#define TOP_MOID(p) ((p)->top_moid)
1097+
#define TOP_MOIF(p) ((p)->top_moif)
11001098
#define TOP_NODE(p) ((p)->top_node)
11011099
#define TRANSIENT(p) ((p)->transient)
11021100
#define TREE_LISTING_SAFE(p) ((p)->tree_listing_safe)

gcc/testsuite/algol68/compile/modules/program-11.a68

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
inside controlled clauses in access clauses with
55
several revelations. }
66

7-
access Module10,
8-
Module11,
7+
access Module11,
98
Module12
109
begin assert (foo = 10);
1110
assert (bar = "foo") { dg-error "" }

0 commit comments

Comments
 (0)