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.
---
gcc/algol68/a68-parser-scope.cc | 63 ++++++++++++++++---
.../compile/warning-scope-module-1.a68 | 11 ++++
.../compile/warning-scope-module-2.a68 | 13 ++++
3 files changed, 77 insertions(+), 10 deletions(-)
create mode 100644 gcc/testsuite/algol68/compile/warning-scope-module-1.a68
create mode 100644 gcc/testsuite/algol68/compile/warning-scope-module-2.a68
diff --git a/gcc/algol68/a68-parser-scope.cc b/gcc/algol68/a68-parser-scope.cc
index e04704e25b6..8203423bdbc 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 00000000000..dcbef6686b7
--- /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 00000000000..e7d43c1781f
--- /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
--
2.30.2