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 chill_printchar (c
, stream
)
33 c
&= 0xFF; /* Avoid sign bit follies */
35 if (PRINT_LITERAL_FORM (c
))
37 fprintf_filtered (stream
, "'%c'", c
);
41 fprintf_filtered (stream
, "C'%.2x'", (unsigned int) c
);
45 /* Print the character string STRING, printing at most LENGTH characters.
46 Printing stops early if the number hits print_max; repeat counts
47 are printed as appropriate. Print ellipses at the end if we
48 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
49 Note that gdb maintains the length of strings without counting the
50 terminating null byte, while chill strings are typically written with
51 an explicit null byte. So we always assume an implied null byte
52 until gdb is able to maintain non-null terminated strings as well
53 as null terminated strings (FIXME).
57 chill_printstr (stream
, string
, length
, force_ellipses
)
63 register unsigned int i
;
64 unsigned int things_printed
= 0;
65 int in_literal_form
= 0;
66 int in_control_form
= 0;
67 int need_slashslash
= 0;
69 extern int repeat_count_threshold
;
74 chill_printchar ('\0', stream
);
78 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
80 /* Position of the character we are examining
81 to see whether it is repeated. */
83 /* Number of repetitions we have detected so far. */
90 fputs_filtered ("//", stream
);
96 while (rep1
< length
&& string
[rep1
] == string
[i
])
103 if (reps
> repeat_count_threshold
)
105 if (in_control_form
|| in_literal_form
)
107 fputs_filtered ("'//", stream
);
108 in_control_form
= in_literal_form
= 0;
110 chill_printchar (c
, stream
);
111 fprintf_filtered (stream
, "<repeats %u times>", reps
);
113 things_printed
+= repeat_count_threshold
;
118 if (PRINT_LITERAL_FORM (c
))
120 if (!in_literal_form
)
124 fputs_filtered ("'//", stream
);
127 fputs_filtered ("'", stream
);
130 fprintf_filtered (stream
, "%c", c
);
134 if (!in_control_form
)
138 fputs_filtered ("'//", stream
);
141 fputs_filtered ("c'", stream
);
144 fprintf_filtered (stream
, "%.2x", c
);
150 /* Terminate the quotes if necessary. */
151 if (in_literal_form
|| in_control_form
)
153 fputs_filtered ("'", stream
);
155 if (force_ellipses
|| (i
< length
))
157 fputs_filtered ("...", stream
);
162 chill_create_fundamental_type (objfile
, typeid)
163 struct objfile
*objfile
;
166 register struct type
*type
= NULL
;
171 /* FIXME: For now, if we are asked to produce a type not in this
172 language, create the equivalent of a C integer type with the
173 name "<?type?>". When all the dust settles from the type
174 reconstruction work, this should probably become an error. */
175 type
= init_type (TYPE_CODE_INT
, 2, 0, "<?type?>", objfile
);
176 warning ("internal error: no chill fundamental type %d", typeid);
179 /* FIXME: Currently the GNU Chill compiler emits some DWARF entries for
180 typedefs, unrelated to anything directly in the code being compiled,
181 that have some FT_VOID types. Just fake it for now. */
182 type
= init_type (TYPE_CODE_VOID
, 0, 0, "<?VOID?>", objfile
);
185 type
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
, "BOOL", objfile
);
188 type
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
, "CHAR", objfile
);
191 type
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_SIGNED
, "BYTE", objfile
);
193 case FT_UNSIGNED_CHAR
:
194 type
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, "UBYTE", objfile
);
196 case FT_SHORT
: /* Chill ints are 2 bytes */
197 type
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_SIGNED
, "INT", objfile
);
199 case FT_UNSIGNED_SHORT
: /* Chill ints are 2 bytes */
200 type
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, "UINT", objfile
);
202 case FT_INTEGER
: /* Chill longs are 4 bytes */
203 type
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_SIGNED
, "LONG", objfile
);
205 case FT_UNSIGNED_INTEGER
: /* Chill longs are 4 bytes */
206 type
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
, "ULONG", objfile
);
209 type
= init_type (TYPE_CODE_FLT
, 4, 0, "REAL", objfile
);
211 case FT_DBL_PREC_FLOAT
:
212 type
= init_type (TYPE_CODE_FLT
, 8, 0, "LONG_REAL", objfile
);
219 /* Table of operators and their precedences for printing expressions. */
221 static const struct op_print chill_op_print_tab
[] = {
222 {"AND", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
223 {"OR", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
224 {"NOT", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
225 {"MOD", BINOP_REM
, PREC_MUL
, 0},
226 {":=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
227 {"=", BINOP_EQUAL
, PREC_EQUAL
, 0},
228 {"/=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
229 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
230 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
231 {">", BINOP_GTR
, PREC_ORDER
, 0},
232 {"<", BINOP_LESS
, PREC_ORDER
, 0},
233 {"+", BINOP_ADD
, PREC_ADD
, 0},
234 {"-", BINOP_SUB
, PREC_ADD
, 0},
235 {"*", BINOP_MUL
, PREC_MUL
, 0},
236 {"/", BINOP_DIV
, PREC_MUL
, 0},
237 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
242 /* The built-in types of Chill. */
244 struct type
*builtin_type_chill_bool
;
245 struct type
*builtin_type_chill_char
;
246 struct type
*builtin_type_chill_long
;
247 struct type
*builtin_type_chill_ulong
;
248 struct type
*builtin_type_chill_real
;
250 struct type
** const (chill_builtin_types
[]) =
252 &builtin_type_chill_bool
,
253 &builtin_type_chill_char
,
254 &builtin_type_chill_long
,
255 &builtin_type_chill_ulong
,
256 &builtin_type_chill_real
,
260 const struct language_defn chill_language_defn
= {
266 chill_parse
, /* parser */
267 chill_error
, /* parser error function */
268 chill_printchar
, /* print a character constant */
269 chill_printstr
, /* function to print a string constant */
270 chill_create_fundamental_type
,/* Create fundamental type in this language */
271 chill_print_type
, /* Print a type using appropriate syntax */
272 chill_val_print
, /* Print a value using appropriate syntax */
273 &BUILTIN_TYPE_LONGEST
, /* longest signed integral type */
274 &BUILTIN_TYPE_UNSIGNED_LONGEST
,/* longest unsigned integral type */
275 &builtin_type_chill_real
, /* longest floating point type */
276 {"", "B'", "", ""}, /* Binary format info */
277 {"O'%o", "O'", "o", ""}, /* Octal format info */
278 {"D'%d", "D'", "d", ""}, /* Decimal format info */
279 {"H'%x", "H'", "x", ""}, /* Hex format info */
280 chill_op_print_tab
, /* expression operators for printing */
284 /* Initialization for Chill */
287 _initialize_chill_language ()
289 builtin_type_chill_bool
=
290 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
292 "BOOL", (struct objfile
*) NULL
);
293 builtin_type_chill_char
=
294 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
296 "CHAR", (struct objfile
*) NULL
);
297 builtin_type_chill_long
=
298 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
300 "LONG", (struct objfile
*) NULL
);
301 builtin_type_chill_ulong
=
302 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
304 "ULONG", (struct objfile
*) NULL
);
305 builtin_type_chill_real
=
306 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
308 "LONG_REAL", (struct objfile
*) NULL
);
310 add_language (&chill_language_defn
);