Signed-off-by: Jose E. Marchesi <[email protected]>
gcc/ChangeLog
* algol68/a68-parser-debug.cc: New file.
---
gcc/algol68/a68-parser-debug.cc | 90 +++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 gcc/algol68/a68-parser-debug.cc
diff --git a/gcc/algol68/a68-parser-debug.cc b/gcc/algol68/a68-parser-debug.cc
new file mode 100644
index 00000000000..fb862407d2d
--- /dev/null
+++ b/gcc/algol68/a68-parser-debug.cc
@@ -0,0 +1,90 @@
+/* Debug facilities for the Algol 68 parser.
+ Copyright (C) 2025 Jose E. Marchesi.
+
+ GCC is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#define INCLUDE_MEMORY
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "diagnostic.h"
+
+#include "a68.h"
+
+/* Write a printable representation of the parse tree with top node P to the
+ standard output. */
+
+static void
+a68_dump_parse_tree_1 (NODE_T *p, int level)
+{
+ for (; p != NO_NODE; FORWARD (p))
+ {
+ int i;
+ location_t loc = a68_get_node_location (p);
+
+ for (i = 0; i < level; ++i)
+ printf (" ");
+ printf ("NODE %d::%s",
+ NUMBER (p),
+ a68_attribute_name (ATTRIBUTE (p)));
+
+ if (ATTRIBUTE (p) == IDENTIFIER
+ || ATTRIBUTE (p) == DEFINING_IDENTIFIER
+ || ATTRIBUTE (p) == DEFINING_OPERATOR
+ || ATTRIBUTE (p) == BOLD_TAG)
+ printf (" %s", NSYMBOL (p));
+
+ if (MOID (p) != NO_MOID)
+ {
+ MOID_T *moid = MOID (p);
+ char b[BUFFER_SIZE];
+ b[0] = '\0';
+
+ if (IS (moid, SERIES_MODE))
+ {
+ if (PACK (moid) != NO_PACK && NEXT (PACK (moid)) == NO_PACK)
+ a68_bufcat (b, a68_moid_to_string (MOID (PACK (moid)),
MOID_ERROR_WIDTH, p),
+ BUFFER_SIZE);
+ else
+ a68_bufcat (b, a68_moid_to_string (moid, MOID_ERROR_WIDTH, p),
BUFFER_SIZE);
+ }
+ else
+ a68_bufcat (b, a68_moid_to_string (moid, MOID_ERROR_WIDTH, p),
BUFFER_SIZE);
+
+ printf (" (%s)", b);
+ }
+ printf (" %s:%d:%d",
+ LOCATION_FILE (loc), LOCATION_LINE (loc), LOCATION_COLUMN (loc));
+ printf ("\n");
+ a68_dump_parse_tree_1 (SUB (p), level + 1);
+ }
+}
+
+void
+a68_dump_parse_tree (NODE_T *p)
+{
+ a68_dump_parse_tree_1 (p, 0);
+}
+
+void
+a68_dump_modes (MOID_T *moid)
+{
+ for (; moid != NO_MOID; FORWARD (moid))
+ {
+ printf ("%p %s\n", (void *) moid,
+ a68_moid_to_string (moid, MOID_ERROR_WIDTH, NODE (moid),
+ true /* indicant_value */));
+ }
+}
--
2.30.2