https://gcc.gnu.org/g:e7a8c5d1982006ee751711f618f49938d667ad0d
commit r16-6430-ge7a8c5d1982006ee751711f618f49938d667ad0d Author: Jose E. Marchesi <[email protected]> Date: Mon Dec 29 14:01:53 2025 +0100 a68: scope prelude packets This commit adapts the static scope checker to prelude packets. Signed-off-by: Jose E. Marchesi <[email protected]> gcc/algol68/ChangeLog * a68-parser-scope.cc (scope_module_text): New function. (scope_module_declaration): Likewise. (scope_particular_program): Likewise. (scope_prelude_packet): Likewise. (a68_scope_checker): Call scope_particular_program and scope_prelude_packet. gcc/testsuite/ChangeLog * algol68/compile/warning-scope-module-1.a68: New test. * algol68/compile/warning-scope-module-2.a68: Likewise. Diff: --- gcc/algol68/a68-parser-scope.cc | 63 ++++++++++++++++++---- .../algol68/compile/warning-scope-module-1.a68 | 11 ++++ .../algol68/compile/warning-scope-module-2.a68 | 13 +++++ 3 files changed, 77 insertions(+), 10 deletions(-) diff --git a/gcc/algol68/a68-parser-scope.cc b/gcc/algol68/a68-parser-scope.cc index e04704e25b62..8203423bdbcd 100644 --- a/gcc/algol68/a68-parser-scope.cc +++ b/gcc/algol68/a68-parser-scope.cc @@ -976,28 +976,71 @@ get_non_local_environs (NODE_T *p, int max) } } -/* The static scope checker. */ +/* Scope a module text. */ -void -a68_scope_checker (NODE_T *p) +static void +scope_module_text (NODE_T *p) { - if (SUB (p)) + for (; p != NO_NODE; FORWARD (p)) { - if (IS (SUB (p), PARTICULAR_PROGRAM)) - p = SUB (p); - else if (IS (SUB (p), PRELUDE_PACKET)) + if (IS (p, DEF_PART) || IS (p, POSTLUDE_PART)) { - /* XXX writeme. */ - return; + NODE_T *clause = NEXT (SUB (p)); + gcc_assert (IS (clause, ENQUIRY_CLAUSE) || IS (clause, SERIAL_CLAUSE)); + scope_serial_clause (clause, NO_VAR, true /* terminator */); } } +} + +/* Scope a module declaration. */ + +static void +scope_module_declaration (NODE_T *p) +{ + for (; p != NO_NODE; FORWARD (p)) + { + if (IS (p, MODULE_TEXT)) + scope_module_text (SUB (p)); + else + scope_module_declaration (SUB (p)); + } +} + +/* Scope a particular program. */ +static void +scope_particular_program (NODE_T *p) +{ + scope_enclosed_clause (SUB (SUB (p)), NO_VAR); +} + +/* Scope a prelude packet. */ + +static void +scope_prelude_packet (NODE_T *p) +{ + gcc_assert (IS (SUB (p), MODULE_DECLARATION)); + scope_module_declaration (SUB (p)); +} + +/* The static scope checker. */ + +void +a68_scope_checker (NODE_T *p) +{ /* Establish scopes of routine texts and format texts. */ get_youngest_environs (p); /* Find non-local environs. */ get_non_local_environs (p, PRIMAL_SCOPE); /* PROC and FORMAT identities can now be assigned a scope. */ bind_scope_to_tags (p); + /* Now check evertyhing else. */ - scope_enclosed_clause (SUB (p), NO_VAR); + gcc_assert (IS (p, PACKET)); + if (IS (SUB (p), PARTICULAR_PROGRAM)) + scope_particular_program (SUB (p)); + else if (IS (SUB (p), PRELUDE_PACKET)) + scope_prelude_packet (SUB (p)); + else + gcc_unreachable (); } diff --git a/gcc/testsuite/algol68/compile/warning-scope-module-1.a68 b/gcc/testsuite/algol68/compile/warning-scope-module-1.a68 new file mode 100644 index 000000000000..dcbef6686b7f --- /dev/null +++ b/gcc/testsuite/algol68/compile/warning-scope-module-1.a68 @@ -0,0 +1,11 @@ +{ dg-options "-Wscope" } + +{ Scope violation in module prelude. } + +module Module = +def proc increase = (ref int i) ref int: + (int j := i; + j); { dg-warning "scope violation" } + increase (loc int) +fed + diff --git a/gcc/testsuite/algol68/compile/warning-scope-module-2.a68 b/gcc/testsuite/algol68/compile/warning-scope-module-2.a68 new file mode 100644 index 000000000000..e7d43c1781fe --- /dev/null +++ b/gcc/testsuite/algol68/compile/warning-scope-module-2.a68 @@ -0,0 +1,13 @@ +{ dg-options "-Wscope" } + +{ Scope violation in module postlude. } + +module Module = +def + skip +postlude + proc increase = (ref int i) ref int: + (int j := i; + j); { dg-warning "scope violation" } + increase (loc int) +fed
