1 /* Modula 2 language support routines for GDB, the GNU debugger.
2 Copyright 1992, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
24 #include "expression.h"
25 #include "parser-defs.h"
31 extern void _initialize_m2_language (void);
32 static struct type *m2_create_fundamental_type (struct objfile *, int);
33 static void m2_printstr (struct ui_file * stream, char *string,
34 unsigned int length, int width,
36 static void m2_printchar (int, struct ui_file *);
37 static void m2_emit_char (int, struct ui_file *, int);
39 /* Print the character C on STREAM as part of the contents of a literal
40 string whose delimiter is QUOTER. Note that that format for printing
41 characters and strings is language specific.
42 FIXME: This is a copy of the same function from c-exp.y. It should
43 be replaced with a true Modula version.
47 m2_emit_char (register int c, struct ui_file *stream, int quoter)
50 c &= 0xFF; /* Avoid sign bit follies */
52 if (PRINT_LITERAL_FORM (c))
54 if (c == '\\' || c == quoter)
56 fputs_filtered ("\\", stream);
58 fprintf_filtered (stream, "%c", c);
65 fputs_filtered ("\\n", stream);
68 fputs_filtered ("\\b", stream);
71 fputs_filtered ("\\t", stream);
74 fputs_filtered ("\\f", stream);
77 fputs_filtered ("\\r", stream);
80 fputs_filtered ("\\e", stream);
83 fputs_filtered ("\\a", stream);
86 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
92 /* FIXME: This is a copy of the same function from c-exp.y. It should
93 be replaced with a true Modula version. */
96 m2_printchar (int c, struct ui_file *stream)
98 fputs_filtered ("'", stream);
99 LA_EMIT_CHAR (c, stream, '\'');
100 fputs_filtered ("'", stream);
103 /* Print the character string STRING, printing at most LENGTH characters.
104 Printing stops early if the number hits print_max; repeat counts
105 are printed as appropriate. Print ellipses at the end if we
106 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
107 FIXME: This is a copy of the same function from c-exp.y. It should
108 be replaced with a true Modula version. */
111 m2_printstr (struct ui_file *stream, char *string, unsigned int length,
112 int width, int force_ellipses)
114 register unsigned int i;
115 unsigned int things_printed = 0;
118 extern int inspect_it;
122 fputs_filtered ("\"\"", gdb_stdout);
126 for (i = 0; i < length && things_printed < print_max; ++i)
128 /* Position of the character we are examining
129 to see whether it is repeated. */
131 /* Number of repetitions we have detected so far. */
138 fputs_filtered (", ", stream);
144 while (rep1 < length && string[rep1] == string[i])
150 if (reps > repeat_count_threshold)
155 fputs_filtered ("\\\", ", stream);
157 fputs_filtered ("\", ", stream);
160 m2_printchar (string[i], stream);
161 fprintf_filtered (stream, " <repeats %u times>", reps);
163 things_printed += repeat_count_threshold;
171 fputs_filtered ("\\\"", stream);
173 fputs_filtered ("\"", stream);
176 LA_EMIT_CHAR (string[i], stream, '"');
181 /* Terminate the quotes if necessary. */
185 fputs_filtered ("\\\"", stream);
187 fputs_filtered ("\"", stream);
190 if (force_ellipses || i < length)
191 fputs_filtered ("...", stream);
194 /* FIXME: This is a copy of c_create_fundamental_type(), before
195 all the non-C types were stripped from it. Needs to be fixed
196 by an experienced Modula programmer. */
199 m2_create_fundamental_type (struct objfile *objfile, int typeid)
201 register struct type *type = NULL;
206 /* FIXME: For now, if we are asked to produce a type not in this
207 language, create the equivalent of a C integer type with the
208 name "<?type?>". When all the dust settles from the type
209 reconstruction work, this should probably become an error. */
210 type = init_type (TYPE_CODE_INT,
211 TARGET_INT_BIT / TARGET_CHAR_BIT,
212 0, "<?type?>", objfile);
213 warning ("internal error: no Modula fundamental type %d", typeid);
216 type = init_type (TYPE_CODE_VOID,
217 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
221 type = init_type (TYPE_CODE_BOOL,
222 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
223 TYPE_FLAG_UNSIGNED, "boolean", objfile);
226 type = init_type (TYPE_CODE_STRING,
227 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
228 0, "string", objfile);
231 type = init_type (TYPE_CODE_INT,
232 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
236 type = init_type (TYPE_CODE_INT,
237 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
238 0, "signed char", objfile);
240 case FT_UNSIGNED_CHAR:
241 type = init_type (TYPE_CODE_INT,
242 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
243 TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
246 type = init_type (TYPE_CODE_INT,
247 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
248 0, "short", objfile);
250 case FT_SIGNED_SHORT:
251 type = init_type (TYPE_CODE_INT,
252 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
253 0, "short", objfile); /* FIXME-fnf */
255 case FT_UNSIGNED_SHORT:
256 type = init_type (TYPE_CODE_INT,
257 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
258 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
261 type = init_type (TYPE_CODE_INT,
262 TARGET_INT_BIT / TARGET_CHAR_BIT,
265 case FT_SIGNED_INTEGER:
266 type = init_type (TYPE_CODE_INT,
267 TARGET_INT_BIT / TARGET_CHAR_BIT,
268 0, "int", objfile); /* FIXME -fnf */
270 case FT_UNSIGNED_INTEGER:
271 type = init_type (TYPE_CODE_INT,
272 TARGET_INT_BIT / TARGET_CHAR_BIT,
273 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
275 case FT_FIXED_DECIMAL:
276 type = init_type (TYPE_CODE_INT,
277 TARGET_INT_BIT / TARGET_CHAR_BIT,
278 0, "fixed decimal", objfile);
281 type = init_type (TYPE_CODE_INT,
282 TARGET_LONG_BIT / TARGET_CHAR_BIT,
286 type = init_type (TYPE_CODE_INT,
287 TARGET_LONG_BIT / TARGET_CHAR_BIT,
288 0, "long", objfile); /* FIXME -fnf */
290 case FT_UNSIGNED_LONG:
291 type = init_type (TYPE_CODE_INT,
292 TARGET_LONG_BIT / TARGET_CHAR_BIT,
293 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
296 type = init_type (TYPE_CODE_INT,
297 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
298 0, "long long", objfile);
300 case FT_SIGNED_LONG_LONG:
301 type = init_type (TYPE_CODE_INT,
302 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
303 0, "signed long long", objfile);
305 case FT_UNSIGNED_LONG_LONG:
306 type = init_type (TYPE_CODE_INT,
307 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
308 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
311 type = init_type (TYPE_CODE_FLT,
312 TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
313 0, "float", objfile);
315 case FT_DBL_PREC_FLOAT:
316 type = init_type (TYPE_CODE_FLT,
317 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
318 0, "double", objfile);
320 case FT_FLOAT_DECIMAL:
321 type = init_type (TYPE_CODE_FLT,
322 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
323 0, "floating decimal", objfile);
325 case FT_EXT_PREC_FLOAT:
326 type = init_type (TYPE_CODE_FLT,
327 TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
328 0, "long double", objfile);
331 type = init_type (TYPE_CODE_COMPLEX,
332 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
333 0, "complex", objfile);
334 TYPE_TARGET_TYPE (type)
335 = m2_create_fundamental_type (objfile, FT_FLOAT);
337 case FT_DBL_PREC_COMPLEX:
338 type = init_type (TYPE_CODE_COMPLEX,
339 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
340 0, "double complex", objfile);
341 TYPE_TARGET_TYPE (type)
342 = m2_create_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
344 case FT_EXT_PREC_COMPLEX:
345 type = init_type (TYPE_CODE_COMPLEX,
346 2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
347 0, "long double complex", objfile);
348 TYPE_TARGET_TYPE (type)
349 = m2_create_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
356 /* Table of operators and their precedences for printing expressions. */
358 static const struct op_print m2_op_print_tab[] =
360 {"+", BINOP_ADD, PREC_ADD, 0},
361 {"+", UNOP_PLUS, PREC_PREFIX, 0},
362 {"-", BINOP_SUB, PREC_ADD, 0},
363 {"-", UNOP_NEG, PREC_PREFIX, 0},
364 {"*", BINOP_MUL, PREC_MUL, 0},
365 {"/", BINOP_DIV, PREC_MUL, 0},
366 {"DIV", BINOP_INTDIV, PREC_MUL, 0},
367 {"MOD", BINOP_REM, PREC_MUL, 0},
368 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
369 {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
370 {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
371 {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
372 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
373 {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
374 {"<=", BINOP_LEQ, PREC_ORDER, 0},
375 {">=", BINOP_GEQ, PREC_ORDER, 0},
376 {">", BINOP_GTR, PREC_ORDER, 0},
377 {"<", BINOP_LESS, PREC_ORDER, 0},
378 {"^", UNOP_IND, PREC_PREFIX, 0},
379 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
380 {"CAP", UNOP_CAP, PREC_BUILTIN_FUNCTION, 0},
381 {"CHR", UNOP_CHR, PREC_BUILTIN_FUNCTION, 0},
382 {"ORD", UNOP_ORD, PREC_BUILTIN_FUNCTION, 0},
383 {"FLOAT", UNOP_FLOAT, PREC_BUILTIN_FUNCTION, 0},
384 {"HIGH", UNOP_HIGH, PREC_BUILTIN_FUNCTION, 0},
385 {"MAX", UNOP_MAX, PREC_BUILTIN_FUNCTION, 0},
386 {"MIN", UNOP_MIN, PREC_BUILTIN_FUNCTION, 0},
387 {"ODD", UNOP_ODD, PREC_BUILTIN_FUNCTION, 0},
388 {"TRUNC", UNOP_TRUNC, PREC_BUILTIN_FUNCTION, 0},
392 /* The built-in types of Modula-2. */
394 struct type *builtin_type_m2_char;
395 struct type *builtin_type_m2_int;
396 struct type *builtin_type_m2_card;
397 struct type *builtin_type_m2_real;
398 struct type *builtin_type_m2_bool;
400 struct type **CONST_PTR (m2_builtin_types[]) =
402 &builtin_type_m2_char,
403 &builtin_type_m2_int,
404 &builtin_type_m2_card,
405 &builtin_type_m2_real,
406 &builtin_type_m2_bool,
410 const struct language_defn m2_language_defn =
418 m2_parse, /* parser */
419 m2_error, /* parser error function */
420 evaluate_subexp_standard,
421 m2_printchar, /* Print character constant */
422 m2_printstr, /* function to print string constant */
423 m2_emit_char, /* Function to print a single character */
424 m2_create_fundamental_type, /* Create fundamental type in this language */
425 m2_print_type, /* Print a type using appropriate syntax */
426 m2_val_print, /* Print a value using appropriate syntax */
427 c_value_print, /* Print a top-level value */
428 {"", "", "", ""}, /* Binary format info */
429 {"%loB", "", "o", "B"}, /* Octal format info */
430 {"%ld", "", "d", ""}, /* Decimal format info */
431 {"0%lXH", "0", "X", "H"}, /* Hex format info */
432 m2_op_print_tab, /* expression operators for printing */
433 0, /* arrays are first-class (not c-style) */
434 0, /* String lower bound */
435 &builtin_type_m2_char, /* Type of string elements */
439 /* Initialization for Modula-2 */
442 _initialize_m2_language (void)
444 /* Modula-2 "pervasive" types. NOTE: these can be redefined!!! */
445 builtin_type_m2_int =
446 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
448 "INTEGER", (struct objfile *) NULL);
449 builtin_type_m2_card =
450 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
452 "CARDINAL", (struct objfile *) NULL);
453 builtin_type_m2_real =
454 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
456 "REAL", (struct objfile *) NULL);
457 builtin_type_m2_char =
458 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
460 "CHAR", (struct objfile *) NULL);
461 builtin_type_m2_bool =
462 init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
464 "BOOLEAN", (struct objfile *) NULL);
466 add_language (&m2_language_defn);