* c-exp.y, m2-exp.y: Migrate code that has nothing to do with
[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 register int nbytes;
168
169 switch (typeid)
170 {
171 default:
172 /* FIXME: For now, if we are asked to produce a type not in this
173 language, create the equivalent of a C integer type with the
174 name "<?type?>". When all the dust settles from the type
175 reconstruction work, this should probably become an error. */
176 type = init_type (TYPE_CODE_INT,
177 TARGET_INT_BIT / TARGET_CHAR_BIT,
178 0, "<?type?>", objfile);
179 warning ("internal error: no chill fundamental type %d", typeid);
180 break;
181 case FT_BOOLEAN:
182 type = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, "BOOL", objfile);
183 break;
184 case FT_CHAR:
185 type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, "CHAR", objfile);
186 break;
187 case FT_SIGNED_CHAR:
188 type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_SIGNED, "BYTE", objfile);
189 break;
190 case FT_UNSIGNED_CHAR:
191 type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, "UBYTE", objfile);
192 break;
193 case FT_SHORT: /* Chill ints are 2 bytes */
194 type = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_SIGNED, "INT", objfile);
195 break;
196 case FT_UNSIGNED_SHORT: /* Chill ints are 2 bytes */
197 type = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, "UINT", objfile);
198 break;
199 case FT_INTEGER: /* Chill longs are 4 bytes */
200 type = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_SIGNED, "LONG", objfile);
201 break;
202 case FT_UNSIGNED_INTEGER: /* Chill longs are 4 bytes */
203 type = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, "ULONG", objfile);
204 break;
205 case FT_FLOAT:
206 type = init_type (TYPE_CODE_FLT, 4, 0, "REAL", objfile);
207 break;
208 case FT_DBL_PREC_FLOAT:
209 type = init_type (TYPE_CODE_FLT, 8, 0, "LONG_REAL", objfile);
210 break;
211 }
212 return (type);
213 }
214
215 \f
216 /* Table of operators and their precedences for printing expressions. */
217
218 const static struct op_print chill_op_print_tab[] = {
219 {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
220 {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
221 {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
222 {"MOD", BINOP_REM, PREC_MUL, 0},
223 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
224 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
225 {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
226 {"<=", BINOP_LEQ, PREC_ORDER, 0},
227 {">=", BINOP_GEQ, PREC_ORDER, 0},
228 {">", BINOP_GTR, PREC_ORDER, 0},
229 {"<", BINOP_LESS, PREC_ORDER, 0},
230 {"+", BINOP_ADD, PREC_ADD, 0},
231 {"-", BINOP_SUB, PREC_ADD, 0},
232 {"*", BINOP_MUL, PREC_MUL, 0},
233 {"/", BINOP_DIV, PREC_MUL, 0},
234 {"-", UNOP_NEG, PREC_PREFIX, 0},
235 {NULL, 0, 0, 0}
236 };
237
238 \f
239 /* The built-in types of Chill. */
240
241 struct type *builtin_type_chill_bool;
242 struct type *builtin_type_chill_char;
243 struct type *builtin_type_chill_long;
244 struct type *builtin_type_chill_ulong;
245 struct type *builtin_type_chill_real;
246
247 struct type ** const (chill_builtin_types[]) =
248 {
249 &builtin_type_chill_bool,
250 &builtin_type_chill_char,
251 &builtin_type_chill_long,
252 &builtin_type_chill_ulong,
253 &builtin_type_chill_real,
254 0
255 };
256
257 const struct language_defn chill_language_defn = {
258 "chill",
259 language_chill,
260 chill_builtin_types,
261 range_check_on,
262 type_check_on,
263 chill_parse, /* parser */
264 chill_error, /* parser error function */
265 chill_printchar, /* print a character constant */
266 chill_printstr, /* function to print a string constant */
267 chill_create_fundamental_type,/* Create fundamental type in this language */
268 &BUILTIN_TYPE_LONGEST, /* longest signed integral type */
269 &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */
270 &builtin_type_chill_real, /* longest floating point type */
271 {"", "B'", "", ""}, /* Binary format info */
272 {"O'%o", "O'", "o", ""}, /* Octal format info */
273 {"D'%d", "D'", "d", ""}, /* Decimal format info */
274 {"H'%x", "H'", "x", ""}, /* Hex format info */
275 chill_op_print_tab, /* expression operators for printing */
276 LANG_MAGIC
277 };
278
279 /* Initialization for Chill */
280
281 void
282 _initialize_chill_exp ()
283 {
284 builtin_type_chill_bool =
285 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
286 TYPE_FLAG_UNSIGNED,
287 "BOOL", (struct objfile *) NULL);
288 builtin_type_chill_char =
289 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
290 TYPE_FLAG_UNSIGNED,
291 "CHAR", (struct objfile *) NULL);
292 builtin_type_chill_long =
293 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
294 0,
295 "LONG", (struct objfile *) NULL);
296 builtin_type_chill_ulong =
297 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
298 TYPE_FLAG_UNSIGNED,
299 "ULONG", (struct objfile *) NULL);
300 builtin_type_chill_real =
301 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
302 0,
303 "LONG_REAL", (struct objfile *) NULL);
304
305 add_language (&chill_language_defn);
306 }
This page took 0.040404 seconds and 5 git commands to generate.