* Makefile.in (VERSION): Bump to 4.7.4.
[deliverable/binutils-gdb.git] / gdb / ch-lang.c
1 /* Chill language support routines for GDB, the GNU debugger.
2 Copyright 1992 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "expression.h"
24 #include "parser-defs.h"
25 #include "language.h"
26 #include "ch-lang.h"
27
28 static void
29 chill_printchar (c, stream)
30 register int c;
31 FILE *stream;
32 {
33 c &= 0xFF; /* Avoid sign bit follies */
34
35 if (PRINT_LITERAL_FORM (c))
36 {
37 fprintf_filtered (stream, "'%c'", c);
38 }
39 else
40 {
41 fprintf_filtered (stream, "C'%.2x'", (unsigned int) c);
42 }
43 }
44
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).
54 */
55
56 static void
57 chill_printstr (stream, string, length, force_ellipses)
58 FILE *stream;
59 char *string;
60 unsigned int length;
61 int force_ellipses;
62 {
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;
68 unsigned int c;
69 extern int repeat_count_threshold;
70 extern int print_max;
71
72 if (length == 0)
73 {
74 chill_printchar ('\0', stream);
75 return;
76 }
77
78 for (i = 0; i < length && things_printed < print_max; ++i)
79 {
80 /* Position of the character we are examining
81 to see whether it is repeated. */
82 unsigned int rep1;
83 /* Number of repetitions we have detected so far. */
84 unsigned int reps;
85
86 QUIT;
87
88 if (need_slashslash)
89 {
90 fputs_filtered ("//", stream);
91 need_slashslash = 0;
92 }
93
94 rep1 = i + 1;
95 reps = 1;
96 while (rep1 < length && string[rep1] == string[i])
97 {
98 ++rep1;
99 ++reps;
100 }
101
102 c = string[i];
103 if (reps > repeat_count_threshold)
104 {
105 if (in_control_form || in_literal_form)
106 {
107 fputs_filtered ("'//", stream);
108 in_control_form = in_literal_form = 0;
109 }
110 chill_printchar (c, stream);
111 fprintf_filtered (stream, "<repeats %u times>", reps);
112 i = rep1 - 1;
113 things_printed += repeat_count_threshold;
114 need_slashslash = 1;
115 }
116 else
117 {
118 if (PRINT_LITERAL_FORM (c))
119 {
120 if (!in_literal_form)
121 {
122 if (in_control_form)
123 {
124 fputs_filtered ("'//", stream);
125 in_control_form = 0;
126 }
127 fputs_filtered ("'", stream);
128 in_literal_form = 1;
129 }
130 fprintf_filtered (stream, "%c", c);
131 }
132 else
133 {
134 if (!in_control_form)
135 {
136 if (in_literal_form)
137 {
138 fputs_filtered ("'//", stream);
139 in_literal_form = 0;
140 }
141 fputs_filtered ("c'", stream);
142 in_control_form = 1;
143 }
144 fprintf_filtered (stream, "%.2x", c);
145 }
146 ++things_printed;
147 }
148 }
149
150 /* Terminate the quotes if necessary. */
151 if (in_literal_form || in_control_form)
152 {
153 fputs_filtered ("'", stream);
154 }
155 if (force_ellipses || (i < length))
156 {
157 fputs_filtered ("...", stream);
158 }
159 }
160
161 static struct type *
162 chill_create_fundamental_type (objfile, typeid)
163 struct objfile *objfile;
164 int typeid;
165 {
166 register struct type *type = NULL;
167
168 switch (typeid)
169 {
170 default:
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);
177 break;
178 case FT_VOID:
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);
183 break;
184 case FT_BOOLEAN:
185 type = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, "BOOL", objfile);
186 break;
187 case FT_CHAR:
188 type = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED, "CHAR", objfile);
189 break;
190 case FT_SIGNED_CHAR:
191 type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_SIGNED, "BYTE", objfile);
192 break;
193 case FT_UNSIGNED_CHAR:
194 type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, "UBYTE", objfile);
195 break;
196 case FT_SHORT: /* Chill ints are 2 bytes */
197 type = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_SIGNED, "INT", objfile);
198 break;
199 case FT_UNSIGNED_SHORT: /* Chill ints are 2 bytes */
200 type = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, "UINT", objfile);
201 break;
202 case FT_INTEGER: /* Chill longs are 4 bytes */
203 type = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_SIGNED, "LONG", objfile);
204 break;
205 case FT_UNSIGNED_INTEGER: /* Chill longs are 4 bytes */
206 type = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, "ULONG", objfile);
207 break;
208 case FT_FLOAT:
209 type = init_type (TYPE_CODE_FLT, 4, 0, "REAL", objfile);
210 break;
211 case FT_DBL_PREC_FLOAT:
212 type = init_type (TYPE_CODE_FLT, 8, 0, "LONG_REAL", objfile);
213 break;
214 }
215 return (type);
216 }
217
218 \f
219 /* Table of operators and their precedences for printing expressions. */
220
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},
238 {NULL, 0, 0, 0}
239 };
240
241 \f
242 /* The built-in types of Chill. */
243
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;
249
250 struct type ** const (chill_builtin_types[]) =
251 {
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,
257 0
258 };
259
260 const struct language_defn chill_language_defn = {
261 "chill",
262 language_chill,
263 chill_builtin_types,
264 range_check_on,
265 type_check_on,
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 */
281 LANG_MAGIC
282 };
283
284 /* Initialization for Chill */
285
286 void
287 _initialize_chill_language ()
288 {
289 builtin_type_chill_bool =
290 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
291 TYPE_FLAG_UNSIGNED,
292 "BOOL", (struct objfile *) NULL);
293 builtin_type_chill_char =
294 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
295 TYPE_FLAG_UNSIGNED,
296 "CHAR", (struct objfile *) NULL);
297 builtin_type_chill_long =
298 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
299 0,
300 "LONG", (struct objfile *) NULL);
301 builtin_type_chill_ulong =
302 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
303 TYPE_FLAG_UNSIGNED,
304 "ULONG", (struct objfile *) NULL);
305 builtin_type_chill_real =
306 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
307 0,
308 "LONG_REAL", (struct objfile *) NULL);
309
310 add_language (&chill_language_defn);
311 }
This page took 0.047316 seconds and 5 git commands to generate.