1 /* Chill 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "expression.h"
24 #include "parser-defs.h"
29 /* For now, Chill uses a simple mangling algorithm whereby you simply
30 discard everything after the occurance of two successive CPLUS_MARKER
31 characters to derive the demangled form. */
34 chill_demangle (mangled)
40 joiner = strchr (mangled, CPLUS_MARKER);
41 if (joiner != NULL && *(joiner + 1) == CPLUS_MARKER)
43 demangled = savestring (mangled, joiner - mangled);
53 chill_printchar (c, stream)
57 c &= 0xFF; /* Avoid sign bit follies */
59 if (PRINT_LITERAL_FORM (c))
61 fprintf_filtered (stream, "'%c'", c);
65 fprintf_filtered (stream, "C'%.2x'", (unsigned int) c);
69 /* Print the character string STRING, printing at most LENGTH characters.
70 Printing stops early if the number hits print_max; repeat counts
71 are printed as appropriate. Print ellipses at the end if we
72 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
73 Note that gdb maintains the length of strings without counting the
74 terminating null byte, while chill strings are typically written with
75 an explicit null byte. So we always assume an implied null byte
76 until gdb is able to maintain non-null terminated strings as well
77 as null terminated strings (FIXME).
81 chill_printstr (stream, string, length, force_ellipses)
87 register unsigned int i;
88 unsigned int things_printed = 0;
89 int in_literal_form = 0;
90 int in_control_form = 0;
91 int need_slashslash = 0;
93 extern int repeat_count_threshold;
98 fputs_filtered ("\"\"", stream);
102 for (i = 0; i < length && things_printed < print_max; ++i)
104 /* Position of the character we are examining
105 to see whether it is repeated. */
107 /* Number of repetitions we have detected so far. */
114 fputs_filtered ("//", stream);
120 while (rep1 < length && string[rep1] == string[i])
127 if (reps > repeat_count_threshold)
129 if (in_control_form || in_literal_form)
131 fputs_filtered ("\"//", stream);
132 in_control_form = in_literal_form = 0;
134 chill_printchar (c, stream);
135 fprintf_filtered (stream, "<repeats %u times>", reps);
137 things_printed += repeat_count_threshold;
142 if (PRINT_LITERAL_FORM (c))
144 if (!in_literal_form)
148 fputs_filtered ("\"//", stream);
151 fputs_filtered ("\"", stream);
154 fprintf_filtered (stream, "%c", c);
158 if (!in_control_form)
162 fputs_filtered ("\"//", stream);
165 fputs_filtered ("c\"", stream);
168 fprintf_filtered (stream, "%.2x", c);
174 /* Terminate the quotes if necessary. */
175 if (in_literal_form || in_control_form)
177 fputs_filtered ("\"", stream);
179 if (force_ellipses || (i < length))
181 fputs_filtered ("...", stream);
185 /* Return 1 if TYPE is a varying string or array. */
188 chill_is_varying_struct (type)
191 if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
193 if (TYPE_NFIELDS (type) != 2)
195 if (strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
201 chill_create_fundamental_type (objfile, typeid)
202 struct objfile *objfile;
205 register struct type *type = NULL;
210 /* FIXME: For now, if we are asked to produce a type not in this
211 language, create the equivalent of a C integer type with the
212 name "<?type?>". When all the dust settles from the type
213 reconstruction work, this should probably become an error. */
214 type = init_type (TYPE_CODE_INT, 2, 0, "<?type?>", objfile);
215 warning ("internal error: no chill fundamental type %d", typeid);
218 /* FIXME: Currently the GNU Chill compiler emits some DWARF entries for
219 typedefs, unrelated to anything directly in the code being compiled,
220 that have some FT_VOID types. Just fake it for now. */
221 type = init_type (TYPE_CODE_VOID, 0, 0, "<?VOID?>", objfile);
224 type = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, "BOOL", objfile);
227 type = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED, "CHAR", objfile);
230 type = init_type (TYPE_CODE_INT, 1, 0, "BYTE", objfile);
232 case FT_UNSIGNED_CHAR:
233 type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, "UBYTE", objfile);
235 case FT_SHORT: /* Chill ints are 2 bytes */
236 type = init_type (TYPE_CODE_INT, 2, 0, "INT", objfile);
238 case FT_UNSIGNED_SHORT: /* Chill ints are 2 bytes */
239 type = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, "UINT", objfile);
241 case FT_INTEGER: /* FIXME? */
242 case FT_SIGNED_INTEGER: /* FIXME? */
243 case FT_LONG: /* Chill longs are 4 bytes */
244 case FT_SIGNED_LONG: /* Chill longs are 4 bytes */
245 type = init_type (TYPE_CODE_INT, 4, 0, "LONG", objfile);
247 case FT_UNSIGNED_INTEGER: /* FIXME? */
248 case FT_UNSIGNED_LONG: /* Chill longs are 4 bytes */
249 type = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, "ULONG", objfile);
252 type = init_type (TYPE_CODE_FLT, 4, 0, "REAL", objfile);
254 case FT_DBL_PREC_FLOAT:
255 type = init_type (TYPE_CODE_FLT, 8, 0, "LONG_REAL", objfile);
262 /* Table of operators and their precedences for printing expressions. */
264 static const struct op_print chill_op_print_tab[] = {
265 {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
266 {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
267 {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
268 {"MOD", BINOP_MOD, PREC_MUL, 0},
269 {"REM", BINOP_REM, PREC_MUL, 0},
270 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
271 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
272 {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
273 {"<=", BINOP_LEQ, PREC_ORDER, 0},
274 {">=", BINOP_GEQ, PREC_ORDER, 0},
275 {">", BINOP_GTR, PREC_ORDER, 0},
276 {"<", BINOP_LESS, PREC_ORDER, 0},
277 {"+", BINOP_ADD, PREC_ADD, 0},
278 {"-", BINOP_SUB, PREC_ADD, 0},
279 {"*", BINOP_MUL, PREC_MUL, 0},
280 {"/", BINOP_DIV, PREC_MUL, 0},
281 {"//", BINOP_CONCAT, PREC_PREFIX, 0}, /* FIXME: precedence? */
282 {"-", UNOP_NEG, PREC_PREFIX, 0},
287 /* The built-in types of Chill. */
289 struct type *builtin_type_chill_bool;
290 struct type *builtin_type_chill_char;
291 struct type *builtin_type_chill_long;
292 struct type *builtin_type_chill_ulong;
293 struct type *builtin_type_chill_real;
295 struct type ** const (chill_builtin_types[]) =
297 &builtin_type_chill_bool,
298 &builtin_type_chill_char,
299 &builtin_type_chill_long,
300 &builtin_type_chill_ulong,
301 &builtin_type_chill_real,
305 const struct language_defn chill_language_defn = {
311 chill_parse, /* parser */
312 chill_error, /* parser error function */
313 chill_printchar, /* print a character constant */
314 chill_printstr, /* function to print a string constant */
315 chill_create_fundamental_type,/* Create fundamental type in this language */
316 chill_print_type, /* Print a type using appropriate syntax */
317 chill_val_print, /* Print a value using appropriate syntax */
318 &builtin_type_chill_real, /* longest floating point type */
319 {"", "B'", "", ""}, /* Binary format info */
320 {"O'%lo", "O'", "o", ""}, /* Octal format info */
321 {"D'%ld", "D'", "d", ""}, /* Decimal format info */
322 {"H'%lx", "H'", "x", ""}, /* Hex format info */
323 chill_op_print_tab, /* expression operators for printing */
327 /* Initialization for Chill */
330 _initialize_chill_language ()
332 builtin_type_chill_bool =
333 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
335 "BOOL", (struct objfile *) NULL);
336 builtin_type_chill_char =
337 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
339 "CHAR", (struct objfile *) NULL);
340 builtin_type_chill_long =
341 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
343 "LONG", (struct objfile *) NULL);
344 builtin_type_chill_ulong =
345 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
347 "ULONG", (struct objfile *) NULL);
348 builtin_type_chill_real =
349 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
351 "LONG_REAL", (struct objfile *) NULL);
353 add_language (&chill_language_defn);