]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
a68: scope prelude packets
authorJose E. Marchesi <jose.marchesi@oracle.com>
Mon, 29 Dec 2025 13:01:53 +0000 (14:01 +0100)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Mon, 29 Dec 2025 13:06:15 +0000 (14:06 +0100)
This commit adapts the static scope checker to prelude packets.

Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>
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.

gcc/algol68/a68-parser-scope.cc
gcc/testsuite/algol68/compile/warning-scope-module-1.a68 [new file with mode: 0644]
gcc/testsuite/algol68/compile/warning-scope-module-2.a68 [new file with mode: 0644]

index e04704e25b620379735ccebe53f687160aff8749..8203423bdbcdad241530859f6589fa04ccf11622 100644 (file)
@@ -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 (file)
index 0000000..dcbef66
--- /dev/null
@@ -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 (file)
index 0000000..e7d43c1
--- /dev/null
@@ -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