Thu Jul 15 17:03:50 2021 UTC ()
lint: replace call to ttos with type_name

Since tyname.c 1.20 from 2021-01-02, type_name is as simple to use as
ttos and more expressive.  It can also be called multiple times without
invalidating the returned strings.

Used only in debug mode.


(rillig)
diff -r1.45 -r1.46 src/usr.bin/xlint/lint1/emit1.c
diff -r1.117 -r1.118 src/usr.bin/xlint/lint1/externs1.h
diff -r1.314 -r1.315 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.45 -r1.46 src/usr.bin/xlint/lint1/emit1.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/emit1.c 2021/07/05 19:39:12 1.45
+++ src/usr.bin/xlint/lint1/emit1.c 2021/07/15 17:03:50 1.46
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: emit1.c,v 1.45 2021/07/05 19:39:12 rillig Exp $ */ 1/* $NetBSD: emit1.c,v 1.46 2021/07/15 17:03:50 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) && !defined(lint) 40#if defined(__RCSID) && !defined(lint)
41__RCSID("$NetBSD: emit1.c,v 1.45 2021/07/05 19:39:12 rillig Exp $"); 41__RCSID("$NetBSD: emit1.c,v 1.46 2021/07/15 17:03:50 rillig Exp $");
42#endif 42#endif
43 43
44#include "lint1.h" 44#include "lint1.h"
45 45
46static void outtt(sym_t *, sym_t *); 46static void outtt(sym_t *, sym_t *);
47static void outfstrg(strg_t *); 47static void outfstrg(strg_t *);
48 48
49/* 49/*
50 * Write type into the output buffer. 50 * Write type into the output buffer.
51 * The type is written as a sequence of substrings, each of which describes a 51 * The type is written as a sequence of substrings, each of which describes a
52 * node of type type_t 52 * node of type type_t
53 * a node is encoded as follows: 53 * a node is encoded as follows:
54 * _Bool B 54 * _Bool B
@@ -148,55 +148,26 @@ outtype(const type_t *tp) @@ -148,55 +148,26 @@ outtype(const type_t *tp)
148 if (tp->t_vararg) 148 if (tp->t_vararg)
149 na++; 149 na++;
150 outint(na); 150 outint(na);
151 for (arg = tp->t_args; arg != NULL; arg = arg->s_next) 151 for (arg = tp->t_args; arg != NULL; arg = arg->s_next)
152 outtype(arg->s_type); 152 outtype(arg->s_type);
153 if (tp->t_vararg) 153 if (tp->t_vararg)
154 outchar('E'); 154 outchar('E');
155 } 155 }
156 tp = tp->t_subt; 156 tp = tp->t_subt;
157 } 157 }
158} 158}
159 159
160/* 160/*
161 * type to string 
162 * used for debugging output 
163 * 
164 * it uses its own output buffer for conversion 
165 */ 
166const char * 
167ttos(const type_t *tp) 
168{ 
169 static ob_t tob; 
170 ob_t tmp; 
171 
172 if (tob.o_buf == NULL) { 
173 tob.o_len = 64; 
174 tob.o_buf = tob.o_next = xmalloc(tob.o_len); 
175 tob.o_end = tob.o_buf + tob.o_len; 
176 } 
177 
178 tmp = ob; 
179 ob = tob; 
180 ob.o_next = ob.o_buf; 
181 outtype(tp); 
182 outchar('\0'); 
183 tob = ob; 
184 ob = tmp; 
185 
186 return tob.o_buf; 
187} 
188 
189/* 
190 * write the name of a tag or typename 161 * write the name of a tag or typename
191 * 162 *
192 * if the tag is named, the name of the tag is written, 163 * if the tag is named, the name of the tag is written,
193 * otherwise, if a typename exists which refers to this tag, 164 * otherwise, if a typename exists which refers to this tag,
194 * this typename is written 165 * this typename is written
195 */ 166 */
196static void 167static void
197outtt(sym_t *tag, sym_t *tdef) 168outtt(sym_t *tag, sym_t *tdef)
198{ 169{
199 170
200 /* 0 is no longer used. */ 171 /* 0 is no longer used. */
201 172
202 if (tag->s_name != unnamed) { 173 if (tag->s_name != unnamed) {

cvs diff -r1.117 -r1.118 src/usr.bin/xlint/lint1/externs1.h (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/externs1.h 2021/07/14 17:07:24 1.117
+++ src/usr.bin/xlint/lint1/externs1.h 2021/07/15 17:03:50 1.118
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: externs1.h,v 1.117 2021/07/14 17:07:24 rillig Exp $ */ 1/* $NetBSD: externs1.h,v 1.118 2021/07/15 17:03:50 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -304,27 +304,26 @@ extern void begin_initialization(sym_t * @@ -304,27 +304,26 @@ extern void begin_initialization(sym_t *
304extern void end_initialization(void); 304extern void end_initialization(void);
305extern sym_t **current_initsym(void); 305extern sym_t **current_initsym(void);
306 306
307extern void init_rbrace(void); 307extern void init_rbrace(void);
308extern void init_lbrace(void); 308extern void init_lbrace(void);
309extern void init_expr(tnode_t *); 309extern void init_expr(tnode_t *);
310extern void add_designator_member(sbuf_t *); 310extern void add_designator_member(sbuf_t *);
311extern void add_designator_subscript(range_t); 311extern void add_designator_subscript(range_t);
312 312
313/* 313/*
314 * emit.c 314 * emit.c
315 */ 315 */
316extern void outtype(const type_t *); 316extern void outtype(const type_t *);
317extern const char *ttos(const type_t *); 
318extern void outsym(const sym_t *, scl_t, def_t); 317extern void outsym(const sym_t *, scl_t, def_t);
319extern void outfdef(const sym_t *, const pos_t *, bool, bool, 318extern void outfdef(const sym_t *, const pos_t *, bool, bool,
320 const sym_t *); 319 const sym_t *);
321extern void outcall(const tnode_t *, bool, bool); 320extern void outcall(const tnode_t *, bool, bool);
322extern void outusg(const sym_t *); 321extern void outusg(const sym_t *);
323 322
324/* 323/*
325 * lex.c 324 * lex.c
326 */ 325 */
327extern int lex_name(const char *, size_t); 326extern int lex_name(const char *, size_t);
328extern int lex_integer_constant(const char *, size_t, int); 327extern int lex_integer_constant(const char *, size_t, int);
329extern int lex_floating_constant(const char *, size_t); 328extern int lex_floating_constant(const char *, size_t);
330extern int lex_operator(int, op_t); 329extern int lex_operator(int, op_t);

cvs diff -r1.314 -r1.315 src/usr.bin/xlint/lint1/tree.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/tree.c 2021/07/14 17:07:24 1.314
+++ src/usr.bin/xlint/lint1/tree.c 2021/07/15 17:03:50 1.315
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.314 2021/07/14 17:07:24 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.315 2021/07/15 17:03:50 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) && !defined(lint) 39#if defined(__RCSID) && !defined(lint)
40__RCSID("$NetBSD: tree.c,v 1.314 2021/07/14 17:07:24 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.315 2021/07/15 17:03:50 rillig Exp $");
41#endif 41#endif
42 42
43#include <float.h> 43#include <float.h>
44#include <limits.h> 44#include <limits.h>
45#include <math.h> 45#include <math.h>
46#include <signal.h> 46#include <signal.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "lint1.h" 50#include "lint1.h"
51#include "cgram.h" 51#include "cgram.h"
52 52
53static tnode_t *expr_new_integer_constant(tspec_t, int64_t); 53static tnode_t *expr_new_integer_constant(tspec_t, int64_t);
@@ -3805,27 +3805,27 @@ display_expression(const tnode_t *tn, in @@ -3805,27 +3805,27 @@ display_expression(const tnode_t *tn, in
3805 char *s; 3805 char *s;
3806 size_t n; 3806 size_t n;
3807 n = MB_CUR_MAX * (tn->tn_string->st_len + 1); 3807 n = MB_CUR_MAX * (tn->tn_string->st_len + 1);
3808 s = xmalloc(n); 3808 s = xmalloc(n);
3809 (void)wcstombs(s, tn->tn_string->st_wcp, n); 3809 (void)wcstombs(s, tn->tn_string->st_wcp, n);
3810 (void)printf("L\"%s\"", s); 3810 (void)printf("L\"%s\"", s);
3811 free(s); 3811 free(s);
3812 } 3812 }
3813 (void)printf(" "); 3813 (void)printf(" ");
3814 } else if (tn->tn_op == FSEL) { 3814 } else if (tn->tn_op == FSEL) {
3815 (void)printf("o=%d, l=%d ", tn->tn_type->t_foffs, 3815 (void)printf("o=%d, l=%d ", tn->tn_type->t_foffs,
3816 tn->tn_type->t_flen); 3816 tn->tn_type->t_flen);
3817 } 3817 }
3818 (void)printf("%s\n", ttos(tn->tn_type)); 3818 (void)printf("%s\n", type_name(tn->tn_type));
3819 if (tn->tn_op == NAME || tn->tn_op == CON || tn->tn_op == STRING) 3819 if (tn->tn_op == NAME || tn->tn_op == CON || tn->tn_op == STRING)
3820 return; 3820 return;
3821 display_expression(tn->tn_left, offs + 2); 3821 display_expression(tn->tn_left, offs + 2);
3822 if (modtab[tn->tn_op].m_binary || 3822 if (modtab[tn->tn_op].m_binary ||
3823 (tn->tn_op == PUSH && tn->tn_right != NULL)) { 3823 (tn->tn_op == PUSH && tn->tn_right != NULL)) {
3824 display_expression(tn->tn_right, offs + 2); 3824 display_expression(tn->tn_right, offs + 2);
3825 } 3825 }
3826} 3826}
3827 3827
3828/* 3828/*
3829 * Called by expr() to recursively perform some tests. 3829 * Called by expr() to recursively perform some tests.
3830 */ 3830 */
3831/* ARGSUSED */ 3831/* ARGSUSED */