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 (c
, stream
, quoter
)
49 struct ui_file
*stream
;
53 c
&= 0xFF; /* Avoid sign bit follies */
55 if (PRINT_LITERAL_FORM (c
))
57 if (c
== '\\' || c
== quoter
)
59 fputs_filtered ("\\", stream
);
61 fprintf_filtered (stream
, "%c", c
);
68 fputs_filtered ("\\n", stream
);
71 fputs_filtered ("\\b", stream
);
74 fputs_filtered ("\\t", stream
);
77 fputs_filtered ("\\f", stream
);
80 fputs_filtered ("\\r", stream
);
83 fputs_filtered ("\\e", stream
);
86 fputs_filtered ("\\a", stream
);
89 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
95 /* FIXME: This is a copy of the same function from c-exp.y. It should
96 be replaced with a true Modula version. */
99 m2_printchar (c
, stream
)
101 struct ui_file
*stream
;
103 fputs_filtered ("'", stream
);
104 LA_EMIT_CHAR (c
, stream
, '\'');
105 fputs_filtered ("'", stream
);
108 /* Print the character string STRING, printing at most LENGTH characters.
109 Printing stops early if the number hits print_max; repeat counts
110 are printed as appropriate. Print ellipses at the end if we
111 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
112 FIXME: This is a copy of the same function from c-exp.y. It should
113 be replaced with a true Modula version. */
116 m2_printstr (stream
, string
, length
, width
, force_ellipses
)
117 struct ui_file
*stream
;
123 register unsigned int i
;
124 unsigned int things_printed
= 0;
127 extern int inspect_it
;
131 fputs_filtered ("\"\"", gdb_stdout
);
135 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
137 /* Position of the character we are examining
138 to see whether it is repeated. */
140 /* Number of repetitions we have detected so far. */
147 fputs_filtered (", ", stream
);
153 while (rep1
< length
&& string
[rep1
] == string
[i
])
159 if (reps
> repeat_count_threshold
)
164 fputs_filtered ("\\\", ", stream
);
166 fputs_filtered ("\", ", stream
);
169 m2_printchar (string
[i
], stream
);
170 fprintf_filtered (stream
, " <repeats %u times>", reps
);
172 things_printed
+= repeat_count_threshold
;
180 fputs_filtered ("\\\"", stream
);
182 fputs_filtered ("\"", stream
);
185 LA_EMIT_CHAR (string
[i
], stream
, '"');
190 /* Terminate the quotes if necessary. */
194 fputs_filtered ("\\\"", stream
);
196 fputs_filtered ("\"", stream
);
199 if (force_ellipses
|| i
< length
)
200 fputs_filtered ("...", stream
);
203 /* FIXME: This is a copy of c_create_fundamental_type(), before
204 all the non-C types were stripped from it. Needs to be fixed
205 by an experienced Modula programmer. */
208 m2_create_fundamental_type (objfile
, typeid)
209 struct objfile
*objfile
;
212 register struct type
*type
= NULL
;
217 /* FIXME: For now, if we are asked to produce a type not in this
218 language, create the equivalent of a C integer type with the
219 name "<?type?>". When all the dust settles from the type
220 reconstruction work, this should probably become an error. */
221 type
= init_type (TYPE_CODE_INT
,
222 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
223 0, "<?type?>", objfile
);
224 warning ("internal error: no Modula fundamental type %d", typeid);
227 type
= init_type (TYPE_CODE_VOID
,
228 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
232 type
= init_type (TYPE_CODE_BOOL
,
233 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
234 TYPE_FLAG_UNSIGNED
, "boolean", objfile
);
237 type
= init_type (TYPE_CODE_STRING
,
238 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
239 0, "string", objfile
);
242 type
= init_type (TYPE_CODE_INT
,
243 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
247 type
= init_type (TYPE_CODE_INT
,
248 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
249 0, "signed char", objfile
);
251 case FT_UNSIGNED_CHAR
:
252 type
= init_type (TYPE_CODE_INT
,
253 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
254 TYPE_FLAG_UNSIGNED
, "unsigned char", objfile
);
257 type
= init_type (TYPE_CODE_INT
,
258 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
259 0, "short", objfile
);
261 case FT_SIGNED_SHORT
:
262 type
= init_type (TYPE_CODE_INT
,
263 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
264 0, "short", objfile
); /* FIXME-fnf */
266 case FT_UNSIGNED_SHORT
:
267 type
= init_type (TYPE_CODE_INT
,
268 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
269 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
272 type
= init_type (TYPE_CODE_INT
,
273 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
276 case FT_SIGNED_INTEGER
:
277 type
= init_type (TYPE_CODE_INT
,
278 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
279 0, "int", objfile
); /* FIXME -fnf */
281 case FT_UNSIGNED_INTEGER
:
282 type
= init_type (TYPE_CODE_INT
,
283 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
284 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
286 case FT_FIXED_DECIMAL
:
287 type
= init_type (TYPE_CODE_INT
,
288 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
289 0, "fixed decimal", objfile
);
292 type
= init_type (TYPE_CODE_INT
,
293 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
297 type
= init_type (TYPE_CODE_INT
,
298 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
299 0, "long", objfile
); /* FIXME -fnf */
301 case FT_UNSIGNED_LONG
:
302 type
= init_type (TYPE_CODE_INT
,
303 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
304 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
307 type
= init_type (TYPE_CODE_INT
,
308 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
309 0, "long long", objfile
);
311 case FT_SIGNED_LONG_LONG
:
312 type
= init_type (TYPE_CODE_INT
,
313 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
314 0, "signed long long", objfile
);
316 case FT_UNSIGNED_LONG_LONG
:
317 type
= init_type (TYPE_CODE_INT
,
318 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
319 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
322 type
= init_type (TYPE_CODE_FLT
,
323 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
324 0, "float", objfile
);
326 case FT_DBL_PREC_FLOAT
:
327 type
= init_type (TYPE_CODE_FLT
,
328 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
329 0, "double", objfile
);
331 case FT_FLOAT_DECIMAL
:
332 type
= init_type (TYPE_CODE_FLT
,
333 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
334 0, "floating decimal", objfile
);
336 case FT_EXT_PREC_FLOAT
:
337 type
= init_type (TYPE_CODE_FLT
,
338 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
339 0, "long double", objfile
);
342 type
= init_type (TYPE_CODE_COMPLEX
,
343 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
344 0, "complex", objfile
);
345 TYPE_TARGET_TYPE (type
)
346 = m2_create_fundamental_type (objfile
, FT_FLOAT
);
348 case FT_DBL_PREC_COMPLEX
:
349 type
= init_type (TYPE_CODE_COMPLEX
,
350 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
351 0, "double complex", objfile
);
352 TYPE_TARGET_TYPE (type
)
353 = m2_create_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
355 case FT_EXT_PREC_COMPLEX
:
356 type
= init_type (TYPE_CODE_COMPLEX
,
357 2 * TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
358 0, "long double complex", objfile
);
359 TYPE_TARGET_TYPE (type
)
360 = m2_create_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
367 /* Table of operators and their precedences for printing expressions. */
369 static const struct op_print m2_op_print_tab
[] =
371 {"+", BINOP_ADD
, PREC_ADD
, 0},
372 {"+", UNOP_PLUS
, PREC_PREFIX
, 0},
373 {"-", BINOP_SUB
, PREC_ADD
, 0},
374 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
375 {"*", BINOP_MUL
, PREC_MUL
, 0},
376 {"/", BINOP_DIV
, PREC_MUL
, 0},
377 {"DIV", BINOP_INTDIV
, PREC_MUL
, 0},
378 {"MOD", BINOP_REM
, PREC_MUL
, 0},
379 {":=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
380 {"OR", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
381 {"AND", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
382 {"NOT", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
383 {"=", BINOP_EQUAL
, PREC_EQUAL
, 0},
384 {"<>", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
385 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
386 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
387 {">", BINOP_GTR
, PREC_ORDER
, 0},
388 {"<", BINOP_LESS
, PREC_ORDER
, 0},
389 {"^", UNOP_IND
, PREC_PREFIX
, 0},
390 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
391 {"CAP", UNOP_CAP
, PREC_BUILTIN_FUNCTION
, 0},
392 {"CHR", UNOP_CHR
, PREC_BUILTIN_FUNCTION
, 0},
393 {"ORD", UNOP_ORD
, PREC_BUILTIN_FUNCTION
, 0},
394 {"FLOAT", UNOP_FLOAT
, PREC_BUILTIN_FUNCTION
, 0},
395 {"HIGH", UNOP_HIGH
, PREC_BUILTIN_FUNCTION
, 0},
396 {"MAX", UNOP_MAX
, PREC_BUILTIN_FUNCTION
, 0},
397 {"MIN", UNOP_MIN
, PREC_BUILTIN_FUNCTION
, 0},
398 {"ODD", UNOP_ODD
, PREC_BUILTIN_FUNCTION
, 0},
399 {"TRUNC", UNOP_TRUNC
, PREC_BUILTIN_FUNCTION
, 0},
403 /* The built-in types of Modula-2. */
405 struct type
*builtin_type_m2_char
;
406 struct type
*builtin_type_m2_int
;
407 struct type
*builtin_type_m2_card
;
408 struct type
*builtin_type_m2_real
;
409 struct type
*builtin_type_m2_bool
;
411 struct type
**CONST_PTR (m2_builtin_types
[]) =
413 &builtin_type_m2_char
,
414 &builtin_type_m2_int
,
415 &builtin_type_m2_card
,
416 &builtin_type_m2_real
,
417 &builtin_type_m2_bool
,
421 const struct language_defn m2_language_defn
=
428 m2_parse
, /* parser */
429 m2_error
, /* parser error function */
430 evaluate_subexp_standard
,
431 m2_printchar
, /* Print character constant */
432 m2_printstr
, /* function to print string constant */
433 m2_emit_char
, /* Function to print a single character */
434 m2_create_fundamental_type
, /* Create fundamental type in this language */
435 m2_print_type
, /* Print a type using appropriate syntax */
436 m2_val_print
, /* Print a value using appropriate syntax */
437 c_value_print
, /* Print a top-level value */
438 {"", "", "", ""}, /* Binary format info */
439 {"%loB", "", "o", "B"}, /* Octal format info */
440 {"%ld", "", "d", ""}, /* Decimal format info */
441 {"0%lXH", "0", "X", "H"}, /* Hex format info */
442 m2_op_print_tab
, /* expression operators for printing */
443 0, /* arrays are first-class (not c-style) */
444 0, /* String lower bound */
445 &builtin_type_m2_char
, /* Type of string elements */
449 /* Initialization for Modula-2 */
452 _initialize_m2_language ()
454 /* Modula-2 "pervasive" types. NOTE: these can be redefined!!! */
455 builtin_type_m2_int
=
456 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
458 "INTEGER", (struct objfile
*) NULL
);
459 builtin_type_m2_card
=
460 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
462 "CARDINAL", (struct objfile
*) NULL
);
463 builtin_type_m2_real
=
464 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
466 "REAL", (struct objfile
*) NULL
);
467 builtin_type_m2_char
=
468 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
470 "CHAR", (struct objfile
*) NULL
);
471 builtin_type_m2_bool
=
472 init_type (TYPE_CODE_BOOL
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
474 "BOOLEAN", (struct objfile
*) NULL
);
476 add_language (&m2_language_defn
);