gdb/ada: Update some predicate functions to return bool
[deliverable/binutils-gdb.git] / gdb / m2-lang.c
CommitLineData
c906108c 1/* Modula 2 language support routines for GDB, the GNU debugger.
ce27fb25 2
42a4f53d 3 Copyright (C) 1992-2019 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"
21#include "symtab.h"
22#include "gdbtypes.h"
23#include "expression.h"
24#include "parser-defs.h"
25#include "language.h"
a53b64ea 26#include "varobj.h"
c906108c
SS
27#include "m2-lang.h"
28#include "c-lang.h"
745b8ca0 29#include "valprint.h"
c906108c 30
6c7a06a3
TT
31static void m2_printchar (int, struct type *, struct ui_file *);
32static void m2_emit_char (int, struct type *, struct ui_file *, int);
c906108c
SS
33
34/* Print the character C on STREAM as part of the contents of a literal
35 string whose delimiter is QUOTER. Note that that format for printing
36 characters and strings is language specific.
37 FIXME: This is a copy of the same function from c-exp.y. It should
844781a1 38 be replaced with a true Modula version. */
c906108c
SS
39
40static void
6c7a06a3 41m2_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
c906108c
SS
42{
43
025bb325 44 c &= 0xFF; /* Avoid sign bit follies. */
c906108c
SS
45
46 if (PRINT_LITERAL_FORM (c))
47 {
48 if (c == '\\' || c == quoter)
49 {
50 fputs_filtered ("\\", stream);
51 }
52 fprintf_filtered (stream, "%c", c);
53 }
54 else
55 {
56 switch (c)
57 {
58 case '\n':
59 fputs_filtered ("\\n", stream);
60 break;
61 case '\b':
62 fputs_filtered ("\\b", stream);
63 break;
64 case '\t':
65 fputs_filtered ("\\t", stream);
66 break;
67 case '\f':
68 fputs_filtered ("\\f", stream);
69 break;
70 case '\r':
71 fputs_filtered ("\\r", stream);
72 break;
73 case '\033':
74 fputs_filtered ("\\e", stream);
75 break;
76 case '\007':
77 fputs_filtered ("\\a", stream);
78 break;
79 default:
80 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
81 break;
82 }
83 }
84}
85
86/* FIXME: This is a copy of the same function from c-exp.y. It should
844781a1 87 be replaced with a true Modula version. */
c906108c
SS
88
89static void
6c7a06a3 90m2_printchar (int c, struct type *type, struct ui_file *stream)
c906108c
SS
91{
92 fputs_filtered ("'", stream);
6c7a06a3 93 LA_EMIT_CHAR (c, type, stream, '\'');
c906108c
SS
94 fputs_filtered ("'", stream);
95}
96
97/* Print the character string STRING, printing at most LENGTH characters.
98 Printing stops early if the number hits print_max; repeat counts
99 are printed as appropriate. Print ellipses at the end if we
100 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
101 FIXME: This is a copy of the same function from c-exp.y. It should
844781a1 102 be replaced with a true Modula version. */
c906108c
SS
103
104static void
6c7a06a3 105m2_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
be759fcf 106 unsigned int length, const char *encoding, int force_ellipses,
79a45b7d 107 const struct value_print_options *options)
c906108c 108{
f86f5ca3 109 unsigned int i;
c906108c
SS
110 unsigned int things_printed = 0;
111 int in_quotes = 0;
112 int need_comma = 0;
c906108c
SS
113
114 if (length == 0)
115 {
116 fputs_filtered ("\"\"", gdb_stdout);
117 return;
118 }
119
79a45b7d 120 for (i = 0; i < length && things_printed < options->print_max; ++i)
c906108c
SS
121 {
122 /* Position of the character we are examining
c5aa993b 123 to see whether it is repeated. */
c906108c
SS
124 unsigned int rep1;
125 /* Number of repetitions we have detected so far. */
126 unsigned int reps;
127
128 QUIT;
129
130 if (need_comma)
131 {
132 fputs_filtered (", ", stream);
133 need_comma = 0;
134 }
135
136 rep1 = i + 1;
137 reps = 1;
138 while (rep1 < length && string[rep1] == string[i])
139 {
140 ++rep1;
141 ++reps;
142 }
143
79a45b7d 144 if (reps > options->repeat_count_threshold)
c906108c
SS
145 {
146 if (in_quotes)
147 {
e93a8774 148 fputs_filtered ("\", ", stream);
c906108c
SS
149 in_quotes = 0;
150 }
6c7a06a3 151 m2_printchar (string[i], type, stream);
c906108c
SS
152 fprintf_filtered (stream, " <repeats %u times>", reps);
153 i = rep1 - 1;
79a45b7d 154 things_printed += options->repeat_count_threshold;
c906108c
SS
155 need_comma = 1;
156 }
157 else
158 {
159 if (!in_quotes)
160 {
e93a8774 161 fputs_filtered ("\"", stream);
c906108c
SS
162 in_quotes = 1;
163 }
6c7a06a3 164 LA_EMIT_CHAR (string[i], type, stream, '"');
c906108c
SS
165 ++things_printed;
166 }
167 }
168
169 /* Terminate the quotes if necessary. */
170 if (in_quotes)
e93a8774 171 fputs_filtered ("\"", stream);
c906108c
SS
172
173 if (force_ellipses || i < length)
174 fputs_filtered ("...", stream);
175}
176
844781a1
GM
177static struct value *
178evaluate_subexp_modula2 (struct type *expect_type, struct expression *exp,
179 int *pos, enum noside noside)
180{
181 enum exp_opcode op = exp->elts[*pos].opcode;
182 struct value *arg1;
183 struct value *arg2;
184 struct type *type;
b8d56208 185
844781a1
GM
186 switch (op)
187 {
188 case UNOP_HIGH:
189 (*pos)++;
190 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
191
192 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
193 return arg1;
194 else
195 {
196 arg1 = coerce_ref (arg1);
197 type = check_typedef (value_type (arg1));
198
199 if (m2_is_unbounded_array (type))
200 {
201 struct value *temp = arg1;
b8d56208 202
844781a1
GM
203 type = TYPE_FIELD_TYPE (type, 1);
204 /* i18n: Do not translate the "_m2_high" part! */
205 arg1 = value_struct_elt (&temp, NULL, "_m2_high", NULL,
206 _("unbounded structure "
207 "missing _m2_high field"));
208
209 if (value_type (arg1) != type)
210 arg1 = value_cast (type, arg1);
211 }
212 }
213 return arg1;
214
215 case BINOP_SUBSCRIPT:
216 (*pos)++;
217 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
218 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
219 if (noside == EVAL_SKIP)
220 goto nosideret;
221 /* If the user attempts to subscript something that is not an
222 array or pointer type (like a plain int variable for example),
223 then report this as an error. */
224
225 arg1 = coerce_ref (arg1);
226 type = check_typedef (value_type (arg1));
227
228 if (m2_is_unbounded_array (type))
229 {
230 struct value *temp = arg1;
231 type = TYPE_FIELD_TYPE (type, 0);
b8d56208
MS
232 if (type == NULL || (TYPE_CODE (type) != TYPE_CODE_PTR))
233 {
025bb325
MS
234 warning (_("internal error: unbounded "
235 "array structure is unknown"));
b8d56208
MS
236 return evaluate_subexp_standard (expect_type, exp, pos, noside);
237 }
844781a1
GM
238 /* i18n: Do not translate the "_m2_contents" part! */
239 arg1 = value_struct_elt (&temp, NULL, "_m2_contents", NULL,
240 _("unbounded structure "
241 "missing _m2_contents field"));
242
243 if (value_type (arg1) != type)
244 arg1 = value_cast (type, arg1);
245
976aa66e 246 check_typedef (value_type (arg1));
2497b498 247 return value_ind (value_ptradd (arg1, value_as_long (arg2)));
844781a1
GM
248 }
249 else
250 if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
251 {
252 if (TYPE_NAME (type))
253 error (_("cannot subscript something of type `%s'"),
254 TYPE_NAME (type));
255 else
256 error (_("cannot subscript requested type"));
257 }
258
259 if (noside == EVAL_AVOID_SIDE_EFFECTS)
260 return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
261 else
2497b498 262 return value_subscript (arg1, value_as_long (arg2));
844781a1
GM
263
264 default:
265 return evaluate_subexp_standard (expect_type, exp, pos, noside);
266 }
267
268 nosideret:
22601c15 269 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
844781a1 270}
c906108c 271\f
c5aa993b 272
c906108c
SS
273/* Table of operators and their precedences for printing expressions. */
274
c5aa993b
JM
275static const struct op_print m2_op_print_tab[] =
276{
277 {"+", BINOP_ADD, PREC_ADD, 0},
278 {"+", UNOP_PLUS, PREC_PREFIX, 0},
279 {"-", BINOP_SUB, PREC_ADD, 0},
280 {"-", UNOP_NEG, PREC_PREFIX, 0},
281 {"*", BINOP_MUL, PREC_MUL, 0},
282 {"/", BINOP_DIV, PREC_MUL, 0},
283 {"DIV", BINOP_INTDIV, PREC_MUL, 0},
284 {"MOD", BINOP_REM, PREC_MUL, 0},
285 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
286 {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
287 {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
288 {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
289 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
290 {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
291 {"<=", BINOP_LEQ, PREC_ORDER, 0},
292 {">=", BINOP_GEQ, PREC_ORDER, 0},
293 {">", BINOP_GTR, PREC_ORDER, 0},
294 {"<", BINOP_LESS, PREC_ORDER, 0},
295 {"^", UNOP_IND, PREC_PREFIX, 0},
296 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
297 {"CAP", UNOP_CAP, PREC_BUILTIN_FUNCTION, 0},
298 {"CHR", UNOP_CHR, PREC_BUILTIN_FUNCTION, 0},
299 {"ORD", UNOP_ORD, PREC_BUILTIN_FUNCTION, 0},
300 {"FLOAT", UNOP_FLOAT, PREC_BUILTIN_FUNCTION, 0},
301 {"HIGH", UNOP_HIGH, PREC_BUILTIN_FUNCTION, 0},
302 {"MAX", UNOP_MAX, PREC_BUILTIN_FUNCTION, 0},
303 {"MIN", UNOP_MIN, PREC_BUILTIN_FUNCTION, 0},
304 {"ODD", UNOP_ODD, PREC_BUILTIN_FUNCTION, 0},
305 {"TRUNC", UNOP_TRUNC, PREC_BUILTIN_FUNCTION, 0},
f486487f 306 {NULL, OP_NULL, PREC_BUILTIN_FUNCTION, 0}
c906108c
SS
307};
308\f
309/* The built-in types of Modula-2. */
310
cad351d1
UW
311enum m2_primitive_types {
312 m2_primitive_type_char,
313 m2_primitive_type_int,
314 m2_primitive_type_card,
315 m2_primitive_type_real,
316 m2_primitive_type_bool,
317 nr_m2_primitive_types
c906108c
SS
318};
319
cad351d1
UW
320static void
321m2_language_arch_info (struct gdbarch *gdbarch,
322 struct language_arch_info *lai)
323{
5760b90a
UW
324 const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
325
326 lai->string_char_type = builtin->builtin_char;
cad351d1
UW
327 lai->primitive_type_vector
328 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
329 struct type *);
330
331 lai->primitive_type_vector [m2_primitive_type_char]
5760b90a 332 = builtin->builtin_char;
cad351d1 333 lai->primitive_type_vector [m2_primitive_type_int]
5760b90a 334 = builtin->builtin_int;
cad351d1 335 lai->primitive_type_vector [m2_primitive_type_card]
5760b90a 336 = builtin->builtin_card;
cad351d1 337 lai->primitive_type_vector [m2_primitive_type_real]
5760b90a 338 = builtin->builtin_real;
cad351d1 339 lai->primitive_type_vector [m2_primitive_type_bool]
5760b90a 340 = builtin->builtin_bool;
fbb06eb1
UW
341
342 lai->bool_type_symbol = "BOOLEAN";
343 lai->bool_type_default = builtin->builtin_bool;
cad351d1
UW
344}
345
844781a1
GM
346const struct exp_descriptor exp_descriptor_modula2 =
347{
348 print_subexp_standard,
349 operator_length_standard,
c0201579 350 operator_check_standard,
844781a1
GM
351 op_name_standard,
352 dump_subexp_body_standard,
353 evaluate_subexp_modula2
354};
355
47e77640 356extern const struct language_defn m2_language_defn =
c5aa993b 357{
c906108c 358 "modula-2",
6abde28f 359 "Modula-2",
c906108c 360 language_m2,
c906108c 361 range_check_on,
63872f9d 362 case_sensitive_on,
7ca2d3a3 363 array_row_major,
9a044a89 364 macro_expansion_no,
56618e20 365 NULL,
844781a1 366 &exp_descriptor_modula2,
c906108c 367 m2_parse, /* parser */
e85c3284 368 null_post_parser,
c906108c
SS
369 m2_printchar, /* Print character constant */
370 m2_printstr, /* function to print string constant */
371 m2_emit_char, /* Function to print a single character */
c906108c 372 m2_print_type, /* Print a type using appropriate syntax */
5c6ce71d 373 m2_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
374 m2_val_print, /* Print a value using appropriate syntax */
375 c_value_print, /* Print a top-level value */
a5ee536b 376 default_read_var_value, /* la_read_var_value */
f636b87d 377 NULL, /* Language specific skip_trampoline */
2b2d9e11 378 NULL, /* name_of_this */
59cc4834 379 false, /* la_store_sym_names_in_linkage_form_p */
5f9a71c3 380 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 381 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 382 NULL, /* Language specific symbol demangler */
8b302db8 383 NULL,
025bb325
MS
384 NULL, /* Language specific
385 class_name_from_physname */
c906108c
SS
386 m2_op_print_tab, /* expression operators for printing */
387 0, /* arrays are first-class (not c-style) */
388 0, /* String lower bound */
6084f43a 389 default_word_break_characters,
eb3ff9a5 390 default_collect_symbol_completion_matches,
cad351d1 391 m2_language_arch_info,
e79af960 392 default_print_array_index,
41f1b697 393 default_pass_by_reference,
ae6a3a4c 394 default_get_string,
43cc5389 395 c_watch_location_expression,
b5ec771e 396 NULL, /* la_get_symbol_name_matcher */
f8eba3c6 397 iterate_over_symbols,
5ffa0793 398 default_search_name_hash,
a53b64ea 399 &default_varobj_ops,
bb2ec1b3 400 NULL,
62253a61 401 NULL
c906108c
SS
402};
403
5760b90a
UW
404static void *
405build_m2_types (struct gdbarch *gdbarch)
c906108c 406{
5760b90a
UW
407 struct builtin_m2_type *builtin_m2_type
408 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_m2_type);
409
c906108c 410 /* Modula-2 "pervasive" types. NOTE: these can be redefined!!! */
e9bb382b
UW
411 builtin_m2_type->builtin_int
412 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "INTEGER");
413 builtin_m2_type->builtin_card
414 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "CARDINAL");
415 builtin_m2_type->builtin_real
49f190bc
UW
416 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), "REAL",
417 gdbarch_float_format (gdbarch));
e9bb382b
UW
418 builtin_m2_type->builtin_char
419 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "CHAR");
420 builtin_m2_type->builtin_bool
421 = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "BOOLEAN");
c906108c 422
5760b90a
UW
423 return builtin_m2_type;
424}
425
426static struct gdbarch_data *m2_type_data;
427
428const struct builtin_m2_type *
429builtin_m2_type (struct gdbarch *gdbarch)
430{
9a3c8263 431 return (const struct builtin_m2_type *) gdbarch_data (gdbarch, m2_type_data);
5760b90a
UW
432}
433
434
435/* Initialization for Modula-2 */
436
437void
438_initialize_m2_language (void)
439{
440 m2_type_data = gdbarch_data_register_post_init (build_m2_types);
c906108c 441}
This page took 1.611081 seconds and 4 git commands to generate.