1 /* Modula 2 language support routines for GDB, the GNU debugger.
2 Copyright 1992 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, Boston, MA 02111-1307, USA. */
23 #include "expression.h"
24 #include "parser-defs.h"
29 extern void _initialize_m2_language PARAMS ((void));
30 static struct type *m2_create_fundamental_type PARAMS ((struct objfile *, int));
31 static void m2_printstr PARAMS ((GDB_FILE *stream, char *string, unsigned int length, int width, int force_ellipses));
32 static void m2_printchar PARAMS ((int, GDB_FILE *));
33 static void m2_emit_char PARAMS ((int, GDB_FILE *, int));
35 /* Print the character C on STREAM as part of the contents of a literal
36 string whose delimiter is QUOTER. Note that that format for printing
37 characters and strings is language specific.
38 FIXME: This is a copy of the same function from c-exp.y. It should
39 be replaced with a true Modula version.
43 m2_emit_char (c, stream, quoter)
49 c &= 0xFF; /* Avoid sign bit follies */
51 if (PRINT_LITERAL_FORM (c))
53 if (c == '\\' || c == quoter)
55 fputs_filtered ("\\", stream);
57 fprintf_filtered (stream, "%c", c);
64 fputs_filtered ("\\n", stream);
67 fputs_filtered ("\\b", stream);
70 fputs_filtered ("\\t", stream);
73 fputs_filtered ("\\f", stream);
76 fputs_filtered ("\\r", stream);
79 fputs_filtered ("\\e", stream);
82 fputs_filtered ("\\a", stream);
85 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
91 /* FIXME: This is a copy of the same function from c-exp.y. It should
92 be replaced with a true Modula version. */
95 m2_printchar (c, stream)
99 fputs_filtered ("'", stream);
100 LA_EMIT_CHAR (c, stream, '\'');
101 fputs_filtered ("'", stream);
104 /* Print the character string STRING, printing at most LENGTH characters.
105 Printing stops early if the number hits print_max; repeat counts
106 are printed as appropriate. Print ellipses at the end if we
107 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
108 FIXME: This is a copy of the same function from c-exp.y. It should
109 be replaced with a true Modula version. */
112 m2_printstr (stream, string, length, width, force_ellipses)
119 register unsigned int i;
120 unsigned int things_printed = 0;
123 extern int inspect_it;
124 extern int repeat_count_threshold;
125 extern int print_max;
129 fputs_filtered ("\"\"", gdb_stdout);
133 for (i = 0; i < length && things_printed < print_max; ++i)
135 /* Position of the character we are examining
136 to see whether it is repeated. */
138 /* Number of repetitions we have detected so far. */
145 fputs_filtered (", ", stream);
151 while (rep1 < length && string[rep1] == string[i])
157 if (reps > repeat_count_threshold)
162 fputs_filtered ("\\\", ", stream);
164 fputs_filtered ("\", ", stream);
167 m2_printchar (string[i], stream);
168 fprintf_filtered (stream, " <repeats %u times>", reps);
170 things_printed += repeat_count_threshold;
178 fputs_filtered ("\\\"", stream);
180 fputs_filtered ("\"", stream);
183 LA_EMIT_CHAR (string[i], stream, '"');
188 /* Terminate the quotes if necessary. */
192 fputs_filtered ("\\\"", stream);
194 fputs_filtered ("\"", stream);
197 if (force_ellipses || i < length)
198 fputs_filtered ("...", stream);
201 /* FIXME: This is a copy of c_create_fundamental_type(), before
202 all the non-C types were stripped from it. Needs to be fixed
203 by an experienced Modula programmer. */
206 m2_create_fundamental_type (objfile, typeid)
207 struct objfile *objfile;
210 register struct type *type = NULL;
215 /* FIXME: For now, if we are asked to produce a type not in this
216 language, create the equivalent of a C integer type with the
217 name "<?type?>". When all the dust settles from the type
218 reconstruction work, this should probably become an error. */
219 type = init_type (TYPE_CODE_INT,
220 TARGET_INT_BIT / TARGET_CHAR_BIT,
221 0, "<?type?>", objfile);
222 warning ("internal error: no Modula fundamental type %d", typeid);
225 type = init_type (TYPE_CODE_VOID,
226 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
230 type = init_type (TYPE_CODE_BOOL,
231 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
232 TYPE_FLAG_UNSIGNED, "boolean", objfile);
235 type = init_type (TYPE_CODE_STRING,
236 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
237 0, "string", objfile);
240 type = init_type (TYPE_CODE_INT,
241 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
245 type = init_type (TYPE_CODE_INT,
246 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
247 0, "signed char", objfile);
249 case FT_UNSIGNED_CHAR:
250 type = init_type (TYPE_CODE_INT,
251 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
252 TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
255 type = init_type (TYPE_CODE_INT,
256 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
257 0, "short", objfile);
259 case FT_SIGNED_SHORT:
260 type = init_type (TYPE_CODE_INT,
261 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
262 0, "short", objfile); /* FIXME-fnf */
264 case FT_UNSIGNED_SHORT:
265 type = init_type (TYPE_CODE_INT,
266 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
267 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
270 type = init_type (TYPE_CODE_INT,
271 TARGET_INT_BIT / TARGET_CHAR_BIT,
274 case FT_SIGNED_INTEGER:
275 type = init_type (TYPE_CODE_INT,
276 TARGET_INT_BIT / TARGET_CHAR_BIT,
277 0, "int", objfile); /* FIXME -fnf */
279 case FT_UNSIGNED_INTEGER:
280 type = init_type (TYPE_CODE_INT,
281 TARGET_INT_BIT / TARGET_CHAR_BIT,
282 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
284 case FT_FIXED_DECIMAL:
285 type = init_type (TYPE_CODE_INT,
286 TARGET_INT_BIT / TARGET_CHAR_BIT,
287 0, "fixed decimal", objfile);
290 type = init_type (TYPE_CODE_INT,
291 TARGET_LONG_BIT / TARGET_CHAR_BIT,
295 type = init_type (TYPE_CODE_INT,
296 TARGET_LONG_BIT / TARGET_CHAR_BIT,
297 0, "long", objfile); /* FIXME -fnf */
299 case FT_UNSIGNED_LONG:
300 type = init_type (TYPE_CODE_INT,
301 TARGET_LONG_BIT / TARGET_CHAR_BIT,
302 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
305 type = init_type (TYPE_CODE_INT,
306 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
307 0, "long long", objfile);
309 case FT_SIGNED_LONG_LONG:
310 type = init_type (TYPE_CODE_INT,
311 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
312 0, "signed long long", objfile);
314 case FT_UNSIGNED_LONG_LONG:
315 type = init_type (TYPE_CODE_INT,
316 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
317 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
320 type = init_type (TYPE_CODE_FLT,
321 TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
322 0, "float", objfile);
324 case FT_DBL_PREC_FLOAT:
325 type = init_type (TYPE_CODE_FLT,
326 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
327 0, "double", objfile);
329 case FT_FLOAT_DECIMAL:
330 type = init_type (TYPE_CODE_FLT,
331 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
332 0, "floating decimal", objfile);
334 case FT_EXT_PREC_FLOAT:
335 type = init_type (TYPE_CODE_FLT,
336 TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
337 0, "long double", objfile);
340 type = init_type (TYPE_CODE_COMPLEX,
341 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
342 0, "complex", objfile);
343 TYPE_TARGET_TYPE (type)
344 = m2_create_fundamental_type (objfile, FT_FLOAT);
346 case FT_DBL_PREC_COMPLEX:
347 type = init_type (TYPE_CODE_COMPLEX,
348 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
349 0, "double complex", objfile);
350 TYPE_TARGET_TYPE (type)
351 = m2_create_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
353 case FT_EXT_PREC_COMPLEX:
354 type = init_type (TYPE_CODE_COMPLEX,
355 2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
356 0, "long double complex", objfile);
357 TYPE_TARGET_TYPE (type)
358 = m2_create_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
365 /* Table of operators and their precedences for printing expressions. */
367 static const struct op_print m2_op_print_tab[] = {
368 {"+", BINOP_ADD, PREC_ADD, 0},
369 {"+", UNOP_PLUS, PREC_PREFIX, 0},
370 {"-", BINOP_SUB, PREC_ADD, 0},
371 {"-", UNOP_NEG, PREC_PREFIX, 0},
372 {"*", BINOP_MUL, PREC_MUL, 0},
373 {"/", BINOP_DIV, PREC_MUL, 0},
374 {"DIV", BINOP_INTDIV, PREC_MUL, 0},
375 {"MOD", BINOP_REM, PREC_MUL, 0},
376 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
377 {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
378 {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
379 {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
380 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
381 {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
382 {"<=", BINOP_LEQ, PREC_ORDER, 0},
383 {">=", BINOP_GEQ, PREC_ORDER, 0},
384 {">", BINOP_GTR, PREC_ORDER, 0},
385 {"<", BINOP_LESS, PREC_ORDER, 0},
386 {"^", UNOP_IND, PREC_PREFIX, 0},
387 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
388 {"CAP", UNOP_CAP, PREC_BUILTIN_FUNCTION, 0},
389 {"CHR", UNOP_CHR, PREC_BUILTIN_FUNCTION, 0},
390 {"ORD", UNOP_ORD, PREC_BUILTIN_FUNCTION, 0},
391 {"FLOAT",UNOP_FLOAT, PREC_BUILTIN_FUNCTION, 0},
392 {"HIGH", UNOP_HIGH, PREC_BUILTIN_FUNCTION, 0},
393 {"MAX", UNOP_MAX, PREC_BUILTIN_FUNCTION, 0},
394 {"MIN", UNOP_MIN, PREC_BUILTIN_FUNCTION, 0},
395 {"ODD", UNOP_ODD, PREC_BUILTIN_FUNCTION, 0},
396 {"TRUNC", UNOP_TRUNC, PREC_BUILTIN_FUNCTION, 0},
400 /* The built-in types of Modula-2. */
402 struct type *builtin_type_m2_char;
403 struct type *builtin_type_m2_int;
404 struct type *builtin_type_m2_card;
405 struct type *builtin_type_m2_real;
406 struct type *builtin_type_m2_bool;
408 struct type ** CONST_PTR (m2_builtin_types[]) =
410 &builtin_type_m2_char,
411 &builtin_type_m2_int,
412 &builtin_type_m2_card,
413 &builtin_type_m2_real,
414 &builtin_type_m2_bool,
418 const struct language_defn m2_language_defn = {
424 m2_parse, /* parser */
425 m2_error, /* parser error function */
426 evaluate_subexp_standard,
427 m2_printchar, /* Print character constant */
428 m2_printstr, /* function to print string constant */
429 m2_emit_char, /* Function to print a single character */
430 m2_create_fundamental_type, /* Create fundamental type in this language */
431 m2_print_type, /* Print a type using appropriate syntax */
432 m2_val_print, /* Print a value using appropriate syntax */
433 c_value_print, /* Print a top-level value */
434 {"", "", "", ""}, /* Binary format info */
435 {"%loB", "", "o", "B"}, /* Octal format info */
436 {"%ld", "", "d", ""}, /* Decimal format info */
437 {"0%lXH", "0", "X", "H"}, /* Hex format info */
438 m2_op_print_tab, /* expression operators for printing */
439 0, /* arrays are first-class (not c-style) */
440 0, /* String lower bound */
441 &builtin_type_m2_char, /* Type of string elements */
445 /* Initialization for Modula-2 */
448 _initialize_m2_language ()
450 /* Modula-2 "pervasive" types. NOTE: these can be redefined!!! */
451 builtin_type_m2_int =
452 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
454 "INTEGER", (struct objfile *) NULL);
455 builtin_type_m2_card =
456 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
458 "CARDINAL", (struct objfile *) NULL);
459 builtin_type_m2_real =
460 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
462 "REAL", (struct objfile *) NULL);
463 builtin_type_m2_char =
464 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
466 "CHAR", (struct objfile *) NULL);
467 builtin_type_m2_bool =
468 init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
470 "BOOLEAN", (struct objfile *) NULL);
472 add_language (&m2_language_defn);