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.
This commit is contained in:
rillig 2021-01-04 17:06:20 +00:00
parent 359dabd9dc
commit 8c672c9179

View File

@ -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 @@ cat_strings(strg_t *strg1, strg_t *strg2)
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 @@ check_precedence_confusion(tnode_t *tn)
lparn |= ln->tn_parenthesized;
lop = ln->tn_op;
dprint_node(tn);
if (mp->m_binary) {
rparn = 0;
/*