Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: in debug mode, print node tree for...



details:   https://anonhg.NetBSD.org/src/rev/9ba1e2e91a9f
branches:  trunk
changeset: 949190:9ba1e2e91a9f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jan 04 17:06:20 2021 +0000

description:
lint: in debug mode, print node tree for precedence

>From the code alone, it is too difficult to see how the various internal
operators are combined and what properties they have.  A simple tree
visualization helps to see all the details.

This is used to track down the typo in check_precedence_confusion, to
see whether it could have possibly had any influence at all.

diffstat:

 usr.bin/xlint/lint1/tree.c |  48 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 2 deletions(-)

diffs (76 lines):

diff -r 69f9f65c278d -r 9ba1e2e91a9f usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Jan 04 16:17:26 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Jan 04 17:06:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.123 2021/01/04 15:52:51 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.124 2021/01/04 17:06:20 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.123 2021/01/04 15:52:51 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.124 2021/01/04 17:06:20 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3972,6 +3972,48 @@
        return strg1;
 }
 
+#ifdef DEBUG
+static void
+dprint_node(const tnode_t *tn)
+{
+       static int indent = 0;
+
+       op_t op = tn->tn_op;
+
+       if (tn == NULL) {
+               printf("%*s" "null\n", indent, "");
+               return;
+       }
+
+       printf("%*s%s: %s%s%s",
+           indent, "",
+           op == CVT && !tn->tn_cast ? "convert" :
+           op == NAME ? "name" : getopname(op),
+           type_name(tn->tn_type), tn->tn_lvalue ? " lvalue" : "",
+           tn->tn_parenthesized ? " ()" : "");
+       indent += 2;
+       if (op == NAME)
+               printf(" %s\n", tn->tn_sym->s_name);
+       else if (op == CON)
+               printf(" value=?\n");
+       else if (op == STRING)
+               printf(" length=%zu\n", tn->tn_string->st_len);
+       else {
+               printf("\n");
+               dprint_node(tn->tn_left);
+               if (modtab[op].m_binary)
+                       dprint_node(tn->tn_right);
+       }
+       indent -= 2;
+}
+#else
+/*ARGSUSED*/
+static void
+dprint_node(const tnode_t *tn)
+{
+}
+#endif
+
 /*
  * Print a warning if the given node has operands which should be
  * parenthesized.
@@ -3999,6 +4041,8 @@
        lparn |= ln->tn_parenthesized;
        lop = ln->tn_op;
 
+       dprint_node(tn);
+
        if (mp->m_binary) {
                rparn = 0;
                /*



Home | Main Index | Thread Index | Old Index