]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print in infix form a struct expression. |
1bac305b | 2 | |
213516ef | 3 | Copyright (C) 1986-2023 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
4de283e4 | 21 | #include "symtab.h" |
d55e5aa6 | 22 | #include "gdbtypes.h" |
4de283e4 TT |
23 | #include "expression.h" |
24 | #include "value.h" | |
c906108c SS |
25 | #include "language.h" |
26 | #include "parser-defs.h" | |
4de283e4 | 27 | #include "user-regs.h" /* For user_reg_map_regnum_to_name. */ |
82eeeb94 | 28 | #include "target.h" |
4de283e4 TT |
29 | #include "block.h" |
30 | #include "objfiles.h" | |
79a45b7d | 31 | #include "valprint.h" |
7f6aba03 | 32 | #include "cli/cli-style.h" |
de401988 TT |
33 | #include "c-lang.h" |
34 | #include "expop.h" | |
a88c4354 | 35 | #include "ada-exp.h" |
4de283e4 TT |
36 | |
37 | #include <ctype.h> | |
c906108c | 38 | |
5f9769d1 PH |
39 | /* Default name for the standard operator OPCODE (i.e., one defined in |
40 | the definition of enum exp_opcode). */ | |
41 | ||
a121b7c1 | 42 | const char * |
88b91969 | 43 | op_name (enum exp_opcode opcode) |
c906108c SS |
44 | { |
45 | switch (opcode) | |
46 | { | |
47 | default: | |
48 | { | |
49 | static char buf[30]; | |
50 | ||
08850b56 | 51 | xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode); |
c906108c SS |
52 | return buf; |
53 | } | |
56c12414 JK |
54 | #define OP(name) \ |
55 | case name: \ | |
56 | return #name ; | |
57 | #include "std-operator.def" | |
58 | #undef OP | |
c906108c SS |
59 | } |
60 | } | |
61 | ||
731d2cc1 TV |
62 | /* Meant to be used in debug sessions, so don't export it in a header file. */ |
63 | extern void ATTRIBUTE_USED debug_exp (struct expression *exp); | |
64 | ||
65 | /* Print EXP. */ | |
66 | ||
67 | void | |
68 | ATTRIBUTE_USED | |
69 | debug_exp (struct expression *exp) | |
70 | { | |
71 | exp->op->dump (gdb_stdlog, 0); | |
72 | gdb_flush (gdb_stdlog); | |
73 | } | |
74 | ||
de401988 TT |
75 | namespace expr |
76 | { | |
77 | ||
78 | void | |
79 | dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op) | |
80 | { | |
6cb06a8c | 81 | gdb_printf (stream, _("%*sOperation: %s\n"), depth, "", op_name (op)); |
de401988 TT |
82 | } |
83 | ||
84 | void | |
85 | dump_for_expression (struct ui_file *stream, int depth, const std::string &str) | |
86 | { | |
6cb06a8c | 87 | gdb_printf (stream, _("%*sString: %s\n"), depth, "", str.c_str ()); |
de401988 TT |
88 | } |
89 | ||
90 | void | |
91 | dump_for_expression (struct ui_file *stream, int depth, struct type *type) | |
92 | { | |
6cb06a8c | 93 | gdb_printf (stream, _("%*sType: "), depth, ""); |
de401988 | 94 | type_print (type, nullptr, stream, 0); |
6cb06a8c | 95 | gdb_printf (stream, "\n"); |
de401988 TT |
96 | } |
97 | ||
98 | void | |
99 | dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr) | |
100 | { | |
6cb06a8c TT |
101 | gdb_printf (stream, _("%*sConstant: %s\n"), depth, "", |
102 | core_addr_to_string (addr)); | |
de401988 TT |
103 | } |
104 | ||
105 | void | |
106 | dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar) | |
107 | { | |
6cb06a8c TT |
108 | gdb_printf (stream, _("%*sInternalvar: $%s\n"), depth, "", |
109 | internalvar_name (ivar)); | |
de401988 TT |
110 | } |
111 | ||
112 | void | |
113 | dump_for_expression (struct ui_file *stream, int depth, symbol *sym) | |
114 | { | |
6cb06a8c TT |
115 | gdb_printf (stream, _("%*sSymbol: %s\n"), depth, "", |
116 | sym->print_name ()); | |
de401988 TT |
117 | } |
118 | ||
119 | void | |
9c79936b TT |
120 | dump_for_expression (struct ui_file *stream, int depth, |
121 | bound_minimal_symbol msym) | |
de401988 | 122 | { |
6cb06a8c TT |
123 | gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "", |
124 | msym.minsym->print_name (), objfile_name (msym.objfile)); | |
de401988 TT |
125 | } |
126 | ||
127 | void | |
128 | dump_for_expression (struct ui_file *stream, int depth, const block *bl) | |
129 | { | |
6cb06a8c | 130 | gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl); |
de401988 TT |
131 | } |
132 | ||
9e5e03df TT |
133 | void |
134 | dump_for_expression (struct ui_file *stream, int depth, | |
135 | const block_symbol &sym) | |
136 | { | |
6cb06a8c | 137 | gdb_printf (stream, _("%*sBlock symbol:\n"), depth, ""); |
9e5e03df TT |
138 | dump_for_expression (stream, depth + 1, sym.symbol); |
139 | dump_for_expression (stream, depth + 1, sym.block); | |
140 | } | |
141 | ||
de401988 TT |
142 | void |
143 | dump_for_expression (struct ui_file *stream, int depth, | |
144 | type_instance_flags flags) | |
145 | { | |
6cb06a8c | 146 | gdb_printf (stream, _("%*sType flags: "), depth, ""); |
de401988 | 147 | if (flags & TYPE_INSTANCE_FLAG_CONST) |
0426ad51 | 148 | gdb_puts ("const ", stream); |
de401988 | 149 | if (flags & TYPE_INSTANCE_FLAG_VOLATILE) |
0426ad51 | 150 | gdb_puts ("volatile", stream); |
6cb06a8c | 151 | gdb_printf (stream, "\n"); |
de401988 TT |
152 | } |
153 | ||
154 | void | |
155 | dump_for_expression (struct ui_file *stream, int depth, | |
156 | enum c_string_type_values flags) | |
157 | { | |
6cb06a8c | 158 | gdb_printf (stream, _("%*sC string flags: "), depth, ""); |
de401988 TT |
159 | switch (flags & ~C_CHAR) |
160 | { | |
161 | case C_WIDE_STRING: | |
0426ad51 | 162 | gdb_puts (_("wide "), stream); |
de401988 TT |
163 | break; |
164 | case C_STRING_16: | |
0426ad51 | 165 | gdb_puts (_("u16 "), stream); |
de401988 TT |
166 | break; |
167 | case C_STRING_32: | |
0426ad51 | 168 | gdb_puts (_("u32 "), stream); |
de401988 TT |
169 | break; |
170 | default: | |
0426ad51 | 171 | gdb_puts (_("ordinary "), stream); |
de401988 TT |
172 | break; |
173 | } | |
174 | ||
175 | if ((flags & C_CHAR) != 0) | |
0426ad51 | 176 | gdb_puts (_("char"), stream); |
de401988 | 177 | else |
0426ad51 TT |
178 | gdb_puts (_("string"), stream); |
179 | gdb_puts ("\n", stream); | |
de401988 TT |
180 | } |
181 | ||
de401988 TT |
182 | void |
183 | dump_for_expression (struct ui_file *stream, int depth, | |
184 | enum range_flag flags) | |
185 | { | |
6cb06a8c | 186 | gdb_printf (stream, _("%*sRange:"), depth, ""); |
de401988 | 187 | if ((flags & RANGE_LOW_BOUND_DEFAULT) != 0) |
0426ad51 | 188 | gdb_puts (_("low-default "), stream); |
de401988 | 189 | if ((flags & RANGE_HIGH_BOUND_DEFAULT) != 0) |
0426ad51 | 190 | gdb_puts (_("high-default "), stream); |
de401988 | 191 | if ((flags & RANGE_HIGH_BOUND_EXCLUSIVE) != 0) |
0426ad51 | 192 | gdb_puts (_("high-exclusive "), stream); |
de401988 | 193 | if ((flags & RANGE_HAS_STRIDE) != 0) |
0426ad51 | 194 | gdb_puts (_("has-stride"), stream); |
6cb06a8c | 195 | gdb_printf (stream, "\n"); |
de401988 TT |
196 | } |
197 | ||
a88c4354 TT |
198 | void |
199 | dump_for_expression (struct ui_file *stream, int depth, | |
200 | const std::unique_ptr<ada_component> &comp) | |
201 | { | |
202 | comp->dump (stream, depth); | |
203 | } | |
204 | ||
cae26a0c TT |
205 | void |
206 | float_const_operation::dump (struct ui_file *stream, int depth) const | |
207 | { | |
6cb06a8c | 208 | gdb_printf (stream, _("%*sFloat: "), depth, ""); |
cae26a0c | 209 | print_floating (m_data.data (), m_type, stream); |
6cb06a8c | 210 | gdb_printf (stream, "\n"); |
cae26a0c TT |
211 | } |
212 | ||
de401988 | 213 | } /* namespace expr */ |