| @@ -1,153 +1,155 @@ | | | @@ -1,153 +1,155 @@ |
1 | /* $NetBSD: print.c,v 1.8 2021/01/03 18:35:51 rillig Exp $ */ | | 1 | /* $NetBSD: print.c,v 1.9 2021/01/05 07:37:41 rillig Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2003 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2003 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #if HAVE_NBTOOL_CONFIG_H | | 32 | #if HAVE_NBTOOL_CONFIG_H |
33 | #include "nbtool_config.h" | | 33 | #include "nbtool_config.h" |
34 | #endif | | 34 | #endif |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | #ifndef lint | | 37 | #ifndef lint |
38 | __RCSID("$NetBSD: print.c,v 1.8 2021/01/03 18:35:51 rillig Exp $"); | | 38 | __RCSID("$NetBSD: print.c,v 1.9 2021/01/05 07:37:41 rillig Exp $"); |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include <stdio.h> | | 41 | #include <stdio.h> |
42 | | | 42 | |
43 | #include "lint1.h" | | 43 | #include "lint1.h" |
44 | | | 44 | |
45 | static const char *str_op_t[] = | | 45 | static const char *str_op_t[] = |
46 | { | | 46 | { |
47 | "*noop*", | | 47 | "*noop*", |
48 | "->", | | 48 | "->", |
49 | ".", | | 49 | ".", |
50 | "!", | | 50 | "!", |
51 | "~", | | 51 | "~", |
52 | "++", | | 52 | "++", |
53 | "--", | | 53 | "--", |
54 | "++<", | | 54 | "++<", |
55 | "--<", | | 55 | "--<", |
56 | "++>", | | 56 | "++>", |
57 | "-->", | | 57 | "-->", |
58 | "+", | | 58 | "+", |
59 | "-", | | 59 | "-", |
60 | "*", | | 60 | "*", |
61 | "&", | | 61 | "&", |
62 | "*", | | 62 | "*", |
63 | "/", | | 63 | "/", |
64 | "%", | | 64 | "%", |
65 | "+", | | 65 | "+", |
66 | "-", | | 66 | "-", |
67 | "<<", | | 67 | "<<", |
68 | ">>", | | 68 | ">>", |
69 | "<", | | 69 | "<", |
70 | "<=", | | 70 | "<=", |
71 | ">", | | 71 | ">", |
72 | ">=", | | 72 | ">=", |
73 | "==", | | 73 | "==", |
74 | "!=", | | 74 | "!=", |
75 | "&", | | 75 | "&", |
76 | "^", | | 76 | "^", |
77 | "|", | | 77 | "|", |
78 | "&&", | | 78 | "&&", |
79 | "||", | | 79 | "||", |
80 | "?", | | 80 | "?", |
81 | ":", | | 81 | ":", |
82 | "=", | | 82 | "=", |
83 | "*=", | | 83 | "*=", |
84 | "/=", | | 84 | "/=", |
85 | "%=", | | 85 | "%=", |
86 | "+=", | | 86 | "+=", |
87 | "-=", | | 87 | "-=", |
88 | "<<=", | | 88 | "<<=", |
89 | ">>=", | | 89 | ">>=", |
90 | "&=", | | 90 | "&=", |
91 | "^=", | | 91 | "^=", |
92 | "|=", | | 92 | "|=", |
93 | "*name*", | | 93 | "*name*", |
94 | "*constant*", | | 94 | "*constant*", |
95 | "*string*", | | 95 | "*string*", |
96 | "*field select*", | | 96 | "*field select*", |
97 | "*call*", | | 97 | "*call*", |
98 | ",", | | 98 | ",", |
99 | "*(cast)*", | | 99 | "*(cast)*", |
100 | "*icall*", | | 100 | "*icall*", |
101 | "*load*", | | 101 | "*load*", |
102 | "*push*", | | 102 | "*push*", |
103 | "return", | | 103 | "return", |
| | | 104 | "real", |
| | | 105 | "imag", |
104 | "*init*", | | 106 | "*init*", |
105 | "*case*", | | 107 | "*case*", |
106 | "*farg*", | | 108 | "*farg*", |
107 | }; | | 109 | }; |
108 | | | 110 | |
109 | char * | | 111 | char * |
110 | print_tnode(char *buf, size_t bufsiz, const tnode_t *tn) | | 112 | print_tnode(char *buf, size_t bufsiz, const tnode_t *tn) |
111 | { | | 113 | { |
112 | strg_t *st; | | 114 | strg_t *st; |
113 | val_t *v; | | 115 | val_t *v; |
114 | sym_t *s; | | 116 | sym_t *s; |
115 | switch (tn->tn_op) { | | 117 | switch (tn->tn_op) { |
116 | case NAME: | | 118 | case NAME: |
117 | s = tn->tn_sym; | | 119 | s = tn->tn_sym; |
118 | (void)snprintf(buf, bufsiz, "%s", s->s_name); | | 120 | (void)snprintf(buf, bufsiz, "%s", s->s_name); |
119 | break; | | 121 | break; |
120 | case CON: | | 122 | case CON: |
121 | v = tn->tn_val; | | 123 | v = tn->tn_val; |
122 | switch (v->v_tspec) { | | 124 | switch (v->v_tspec) { |
123 | case FLOAT: | | 125 | case FLOAT: |
124 | case DOUBLE: | | 126 | case DOUBLE: |
125 | case LDOUBLE: | | 127 | case LDOUBLE: |
126 | (void)snprintf(buf, bufsiz, "%Lg", v->v_ldbl); | | 128 | (void)snprintf(buf, bufsiz, "%Lg", v->v_ldbl); |
127 | break; | | 129 | break; |
128 | default: | | 130 | default: |
129 | (void)snprintf(buf, bufsiz, v->v_ansiu ? "%llu" : | | 131 | (void)snprintf(buf, bufsiz, v->v_ansiu ? "%llu" : |
130 | "%lld", (unsigned long long)v->v_quad); | | 132 | "%lld", (unsigned long long)v->v_quad); |
131 | break; | | 133 | break; |
132 | } | | 134 | } |
133 | break; | | 135 | break; |
134 | | | 136 | |
135 | case STRING: | | 137 | case STRING: |
136 | st = tn->tn_string; | | 138 | st = tn->tn_string; |
137 | switch (st->st_tspec) { | | 139 | switch (st->st_tspec) { |
138 | case CHAR: | | 140 | case CHAR: |
139 | case SCHAR: | | 141 | case SCHAR: |
140 | case UCHAR: | | 142 | case UCHAR: |
141 | (void)snprintf(buf, bufsiz, "\"%s\"", st->st_cp); | | 143 | (void)snprintf(buf, bufsiz, "\"%s\"", st->st_cp); |
142 | break; | | 144 | break; |
143 | default: | | 145 | default: |
144 | (void)snprintf(buf, bufsiz, "\"*wide string*\""); | | 146 | (void)snprintf(buf, bufsiz, "\"*wide string*\""); |
145 | break; | | 147 | break; |
146 | } | | 148 | } |
147 | break; | | 149 | break; |
148 | default: | | 150 | default: |
149 | (void)snprintf(buf, bufsiz, "%s", str_op_t[tn->tn_op]); | | 151 | (void)snprintf(buf, bufsiz, "%s", str_op_t[tn->tn_op]); |
150 | break; | | 152 | break; |
151 | } | | 153 | } |
152 | return buf; | | 154 | return buf; |
153 | } | | 155 | } |