Commit | Line | Data |
---|---|---|
c8023e66 | 1 | /* Multiple source language support for GDB. |
7ed0f002 | 2 | Copyright 1991, 1992 Free Software Foundation, Inc. |
c8023e66 JG |
3 | Contributed by the Department of Computer Science at the State University |
4 | of New York at Buffalo. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
21 | ||
22 | /* This file contains functions that return things that are specific | |
23 | to languages. Each function should examine current_language if necessary, | |
24 | and return the appropriate result. */ | |
25 | ||
26 | /* FIXME: Most of these would be better organized as macros which | |
27 | return data out of a "language-specific" struct pointer that is set | |
28 | whenever the working language changes. That would be a lot faster. */ | |
29 | ||
d747e0af | 30 | #include "defs.h" |
c8023e66 JG |
31 | #include <string.h> |
32 | #include <varargs.h> | |
33 | ||
c8023e66 | 34 | #include "symtab.h" |
1ab3bf1b | 35 | #include "gdbtypes.h" |
c8023e66 JG |
36 | #include "value.h" |
37 | #include "gdbcmd.h" | |
38 | #include "frame.h" | |
c8023e66 | 39 | #include "expression.h" |
7ed0f002 | 40 | #include "language.h" |
c8023e66 JG |
41 | #include "target.h" |
42 | #include "parser-defs.h" | |
43 | ||
7ed0f002 JG |
44 | static void |
45 | show_language_command PARAMS ((char *, int)); | |
46 | ||
47 | static void | |
48 | set_language_command PARAMS ((char *, int)); | |
49 | ||
50 | static void | |
51 | show_type_command PARAMS ((char *, int)); | |
c4668207 | 52 | |
7ed0f002 JG |
53 | static void |
54 | set_type_command PARAMS ((char *, int)); | |
55 | ||
56 | static void | |
57 | show_range_command PARAMS ((char *, int)); | |
58 | ||
59 | static void | |
60 | set_range_command PARAMS ((char *, int)); | |
61 | ||
62 | static void | |
63 | set_range_str PARAMS ((void)); | |
64 | ||
65 | static void | |
66 | set_type_str PARAMS ((void)); | |
67 | ||
68 | static void | |
69 | set_lang_str PARAMS ((void)); | |
70 | ||
71 | static void | |
72 | unk_lang_error PARAMS ((char *)); | |
73 | ||
74 | static int | |
75 | unk_lang_parser PARAMS ((void)); | |
76 | ||
77 | static void | |
78 | show_check PARAMS ((char *, int)); | |
79 | ||
80 | static void | |
81 | set_check PARAMS ((char *, int)); | |
82 | ||
83 | static void | |
84 | set_type_range PARAMS ((void)); | |
c8023e66 JG |
85 | |
86 | /* Forward declaration */ | |
0c6efbcc | 87 | extern const struct language_defn unknown_language_defn; |
318bf84f | 88 | extern char *warning_pre_print; |
7ed0f002 | 89 | |
c8023e66 JG |
90 | /* The current (default at startup) state of type and range checking. |
91 | (If the modes are set to "auto", though, these are changed based | |
92 | on the default language at startup, and then again based on the | |
93 | language of the first source file. */ | |
94 | ||
95 | enum range_mode range_mode = range_mode_auto; | |
96 | enum range_check range_check = range_check_off; | |
97 | enum type_mode type_mode = type_mode_auto; | |
98 | enum type_check type_check = type_check_off; | |
99 | ||
100 | /* The current language and language_mode (see language.h) */ | |
101 | ||
0c6efbcc | 102 | const struct language_defn *current_language = &unknown_language_defn; |
c8023e66 JG |
103 | enum language_mode language_mode = language_mode_auto; |
104 | ||
b5af69c3 JG |
105 | /* The language that the user expects to be typing in (the language |
106 | of main(), or the last language we notified them about, or C). */ | |
107 | ||
108 | const struct language_defn *expected_language; | |
109 | ||
c8023e66 JG |
110 | /* The list of supported languages. The list itself is malloc'd. */ |
111 | ||
7ed0f002 | 112 | static const struct language_defn **languages; |
c8023e66 JG |
113 | static unsigned languages_size; |
114 | static unsigned languages_allocsize; | |
e58de8a2 | 115 | #define DEFAULT_ALLOCSIZE 4 |
c8023e66 JG |
116 | |
117 | /* The "set language/type/range" commands all put stuff in these | |
118 | buffers. This is to make them work as set/show commands. The | |
119 | user's string is copied here, then the set_* commands look at | |
120 | them and update them to something that looks nice when it is | |
121 | printed out. */ | |
122 | ||
123 | static char *language; | |
124 | static char *type; | |
125 | static char *range; | |
126 | ||
127 | /* Warning issued when current_language and the language of the current | |
128 | frame do not match. */ | |
129 | char lang_frame_mismatch_warn[] = | |
130 | "Warning: the current language does not match this frame."; | |
131 | ||
c8023e66 JG |
132 | \f |
133 | /* This page contains the functions corresponding to GDB commands | |
134 | and their helpers. */ | |
135 | ||
136 | /* Show command. Display a warning if the language set | |
137 | does not match the frame. */ | |
7ed0f002 | 138 | static void |
d8ce1326 JG |
139 | show_language_command (ignore, from_tty) |
140 | char *ignore; | |
c8023e66 JG |
141 | int from_tty; |
142 | { | |
143 | enum language flang; /* The language of the current frame */ | |
144 | ||
145 | flang = get_frame_language(); | |
146 | if (flang != language_unknown && | |
147 | language_mode == language_mode_manual && | |
148 | current_language->la_language != flang) | |
149 | printf_filtered("%s\n",lang_frame_mismatch_warn); | |
150 | } | |
151 | ||
152 | /* Set command. Change the current working language. */ | |
7ed0f002 | 153 | static void |
d8ce1326 JG |
154 | set_language_command (ignore, from_tty) |
155 | char *ignore; | |
c8023e66 JG |
156 | int from_tty; |
157 | { | |
158 | int i; | |
159 | enum language flang; | |
5f3d478e | 160 | char *err_lang; |
c8023e66 JG |
161 | |
162 | /* FIXME -- do this from the list, with HELP. */ | |
163 | if (!language || !language[0]) { | |
199b2450 TL |
164 | printf_unfiltered("The currently understood settings are:\n\n"); |
165 | printf_unfiltered ("local or auto Automatic setting based on source file\n"); | |
166 | printf_unfiltered ("c Use the C language\n"); | |
167 | printf_unfiltered ("c++ Use the C++ language\n"); | |
168 | printf_unfiltered ("chill Use the Chill language\n"); | |
169 | printf_unfiltered ("modula-2 Use the Modula-2 language\n"); | |
0b798409 JG |
170 | /* Restore the silly string. */ |
171 | set_language(current_language->la_language); | |
c8023e66 JG |
172 | return; |
173 | } | |
174 | ||
175 | /* Search the list of languages for a match. */ | |
176 | for (i = 0; i < languages_size; i++) { | |
2e4964ad | 177 | if (STREQ (languages[i]->la_name, language)) { |
c8023e66 JG |
178 | /* Found it! Go into manual mode, and use this language. */ |
179 | if (languages[i]->la_language == language_auto) { | |
180 | /* Enter auto mode. Set to the current frame's language, if known. */ | |
181 | language_mode = language_mode_auto; | |
182 | flang = get_frame_language(); | |
183 | if (flang!=language_unknown) | |
184 | set_language(flang); | |
b5af69c3 | 185 | expected_language = current_language; |
c8023e66 JG |
186 | return; |
187 | } else { | |
188 | /* Enter manual mode. Set the specified language. */ | |
189 | language_mode = language_mode_manual; | |
190 | current_language = languages[i]; | |
191 | set_type_range (); | |
192 | set_lang_str(); | |
b5af69c3 | 193 | expected_language = current_language; |
c8023e66 JG |
194 | return; |
195 | } | |
196 | } | |
197 | } | |
198 | ||
5f3d478e JG |
199 | /* Reset the language (esp. the global string "language") to the |
200 | correct values. */ | |
201 | err_lang=savestring(language,strlen(language)); | |
202 | make_cleanup (free, err_lang); /* Free it after error */ | |
203 | set_language(current_language->la_language); | |
204 | error ("Unknown language `%s'.",err_lang); | |
c8023e66 JG |
205 | } |
206 | ||
207 | /* Show command. Display a warning if the type setting does | |
208 | not match the current language. */ | |
7ed0f002 | 209 | static void |
d8ce1326 JG |
210 | show_type_command(ignore, from_tty) |
211 | char *ignore; | |
c8023e66 JG |
212 | int from_tty; |
213 | { | |
214 | if (type_check != current_language->la_type_check) | |
199b2450 | 215 | printf_unfiltered( |
c8023e66 JG |
216 | "Warning: the current type check setting does not match the language.\n"); |
217 | } | |
218 | ||
219 | /* Set command. Change the setting for type checking. */ | |
7ed0f002 | 220 | static void |
d8ce1326 JG |
221 | set_type_command(ignore, from_tty) |
222 | char *ignore; | |
c8023e66 JG |
223 | int from_tty; |
224 | { | |
2e4964ad | 225 | if (STREQ(type,"on")) |
c8023e66 JG |
226 | { |
227 | type_check = type_check_on; | |
228 | type_mode = type_mode_manual; | |
229 | } | |
2e4964ad | 230 | else if (STREQ(type,"warn")) |
c8023e66 JG |
231 | { |
232 | type_check = type_check_warn; | |
233 | type_mode = type_mode_manual; | |
234 | } | |
2e4964ad | 235 | else if (STREQ(type,"off")) |
c8023e66 JG |
236 | { |
237 | type_check = type_check_off; | |
238 | type_mode = type_mode_manual; | |
239 | } | |
2e4964ad | 240 | else if (STREQ(type,"auto")) |
c8023e66 JG |
241 | { |
242 | type_mode = type_mode_auto; | |
243 | set_type_range(); | |
244 | /* Avoid hitting the set_type_str call below. We | |
245 | did it in set_type_range. */ | |
246 | return; | |
247 | } | |
248 | set_type_str(); | |
d8ce1326 | 249 | show_type_command((char *)NULL, from_tty); |
c8023e66 JG |
250 | } |
251 | ||
252 | /* Show command. Display a warning if the range setting does | |
253 | not match the current language. */ | |
7ed0f002 | 254 | static void |
d8ce1326 JG |
255 | show_range_command(ignore, from_tty) |
256 | char *ignore; | |
c8023e66 JG |
257 | int from_tty; |
258 | { | |
259 | ||
260 | if (range_check != current_language->la_range_check) | |
199b2450 | 261 | printf_unfiltered( |
c8023e66 JG |
262 | "Warning: the current range check setting does not match the language.\n"); |
263 | } | |
264 | ||
265 | /* Set command. Change the setting for range checking. */ | |
7ed0f002 | 266 | static void |
d8ce1326 JG |
267 | set_range_command(ignore, from_tty) |
268 | char *ignore; | |
c8023e66 JG |
269 | int from_tty; |
270 | { | |
2e4964ad | 271 | if (STREQ(range,"on")) |
c8023e66 JG |
272 | { |
273 | range_check = range_check_on; | |
274 | range_mode = range_mode_manual; | |
275 | } | |
2e4964ad | 276 | else if (STREQ(range,"warn")) |
c8023e66 JG |
277 | { |
278 | range_check = range_check_warn; | |
279 | range_mode = range_mode_manual; | |
280 | } | |
2e4964ad | 281 | else if (STREQ(range,"off")) |
c8023e66 JG |
282 | { |
283 | range_check = range_check_off; | |
284 | range_mode = range_mode_manual; | |
285 | } | |
2e4964ad | 286 | else if (STREQ(range,"auto")) |
c8023e66 JG |
287 | { |
288 | range_mode = range_mode_auto; | |
289 | set_type_range(); | |
290 | /* Avoid hitting the set_range_str call below. We | |
291 | did it in set_type_range. */ | |
292 | return; | |
293 | } | |
294 | set_range_str(); | |
d8ce1326 | 295 | show_range_command((char *)0, from_tty); |
c8023e66 JG |
296 | } |
297 | ||
298 | /* Set the status of range and type checking based on | |
299 | the current modes and the current language. | |
300 | If SHOW is non-zero, then print out the current language, | |
301 | type and range checking status. */ | |
302 | static void | |
303 | set_type_range() | |
304 | { | |
c8023e66 JG |
305 | |
306 | if (range_mode == range_mode_auto) | |
307 | range_check = current_language->la_range_check; | |
308 | ||
309 | if (type_mode == type_mode_auto) | |
310 | type_check = current_language->la_type_check; | |
311 | ||
312 | set_type_str(); | |
313 | set_range_str(); | |
314 | } | |
315 | ||
316 | /* Set current language to (enum language) LANG. */ | |
317 | ||
318 | void | |
319 | set_language(lang) | |
320 | enum language lang; | |
321 | { | |
322 | int i; | |
323 | ||
324 | for (i = 0; i < languages_size; i++) { | |
325 | if (languages[i]->la_language == lang) { | |
326 | current_language = languages[i]; | |
327 | set_type_range (); | |
328 | set_lang_str(); | |
545af6ce | 329 | break; |
c8023e66 JG |
330 | } |
331 | } | |
332 | } | |
333 | \f | |
334 | /* This page contains functions that update the global vars | |
335 | language, type and range. */ | |
7ed0f002 | 336 | static void |
c8023e66 JG |
337 | set_lang_str() |
338 | { | |
d8ce1326 | 339 | char *prefix = ""; |
c8023e66 JG |
340 | |
341 | free (language); | |
342 | if (language_mode == language_mode_auto) | |
343 | prefix = "auto; currently "; | |
344 | ||
58ae87f6 | 345 | language = concat(prefix, current_language->la_name, NULL); |
c8023e66 JG |
346 | } |
347 | ||
7ed0f002 | 348 | static void |
c8023e66 JG |
349 | set_type_str() |
350 | { | |
351 | char *tmp, *prefix = ""; | |
352 | ||
353 | free (type); | |
354 | if (type_mode==type_mode_auto) | |
355 | prefix = "auto; currently "; | |
356 | ||
357 | switch(type_check) | |
358 | { | |
359 | case type_check_on: | |
360 | tmp = "on"; | |
361 | break; | |
362 | case type_check_off: | |
363 | tmp = "off"; | |
364 | break; | |
365 | case type_check_warn: | |
366 | tmp = "warn"; | |
367 | break; | |
368 | default: | |
369 | error ("Unrecognized type check setting."); | |
370 | } | |
371 | ||
58ae87f6 | 372 | type = concat(prefix,tmp,NULL); |
c8023e66 JG |
373 | } |
374 | ||
7ed0f002 | 375 | static void |
c8023e66 JG |
376 | set_range_str() |
377 | { | |
378 | char *tmp, *pref = ""; | |
379 | ||
380 | free (range); | |
381 | if (range_mode==range_mode_auto) | |
382 | pref = "auto; currently "; | |
383 | ||
384 | switch(range_check) | |
385 | { | |
386 | case range_check_on: | |
387 | tmp = "on"; | |
388 | break; | |
389 | case range_check_off: | |
390 | tmp = "off"; | |
391 | break; | |
392 | case range_check_warn: | |
393 | tmp = "warn"; | |
394 | break; | |
395 | default: | |
396 | error ("Unrecognized range check setting."); | |
397 | } | |
398 | ||
58ae87f6 | 399 | range = concat(pref,tmp,NULL); |
c8023e66 JG |
400 | } |
401 | ||
402 | ||
403 | /* Print out the current language settings: language, range and | |
7ed0f002 | 404 | type checking. If QUIETLY, print only what has changed. */ |
b5af69c3 | 405 | |
c8023e66 | 406 | void |
7ed0f002 JG |
407 | language_info (quietly) |
408 | int quietly; | |
c8023e66 | 409 | { |
b5af69c3 JG |
410 | if (quietly && expected_language == current_language) |
411 | return; | |
412 | ||
413 | expected_language = current_language; | |
199b2450 | 414 | printf_unfiltered("Current language: %s\n",language); |
b5af69c3 JG |
415 | show_language_command((char *)0, 1); |
416 | ||
417 | if (!quietly) | |
418 | { | |
199b2450 | 419 | printf_unfiltered("Type checking: %s\n",type); |
b5af69c3 | 420 | show_type_command((char *)0, 1); |
199b2450 | 421 | printf_unfiltered("Range checking: %s\n",range); |
b5af69c3 JG |
422 | show_range_command((char *)0, 1); |
423 | } | |
c8023e66 JG |
424 | } |
425 | \f | |
426 | /* Return the result of a binary operation. */ | |
7ed0f002 JG |
427 | |
428 | #if 0 /* Currently unused */ | |
429 | ||
c8023e66 | 430 | struct type * |
82a2edfb JK |
431 | binop_result_type (v1, v2) |
432 | value_ptr v1, v2; | |
c8023e66 JG |
433 | { |
434 | int l1,l2,size,uns; | |
435 | ||
d8ce1326 JG |
436 | l1 = TYPE_LENGTH(VALUE_TYPE(v1)); |
437 | l2 = TYPE_LENGTH(VALUE_TYPE(v2)); | |
c8023e66 JG |
438 | |
439 | switch(current_language->la_language) | |
440 | { | |
441 | case language_c: | |
545af6ce | 442 | case language_cplus: |
c8023e66 JG |
443 | if (TYPE_CODE(VALUE_TYPE(v1))==TYPE_CODE_FLT) |
444 | return TYPE_CODE(VALUE_TYPE(v2)) == TYPE_CODE_FLT && l2 > l1 ? | |
445 | VALUE_TYPE(v2) : VALUE_TYPE(v1); | |
446 | else if (TYPE_CODE(VALUE_TYPE(v2))==TYPE_CODE_FLT) | |
447 | return TYPE_CODE(VALUE_TYPE(v1)) == TYPE_CODE_FLT && l1 > l2 ? | |
448 | VALUE_TYPE(v1) : VALUE_TYPE(v2); | |
449 | else if (TYPE_UNSIGNED(VALUE_TYPE(v1)) && l1 > l2) | |
450 | return VALUE_TYPE(v1); | |
451 | else if (TYPE_UNSIGNED(VALUE_TYPE(v2)) && l2 > l1) | |
452 | return VALUE_TYPE(v2); | |
453 | else /* Both are signed. Result is the longer type */ | |
454 | return l1 > l2 ? VALUE_TYPE(v1) : VALUE_TYPE(v2); | |
455 | break; | |
456 | case language_m2: | |
457 | /* If we are doing type-checking, l1 should equal l2, so this is | |
458 | not needed. */ | |
459 | return l1 > l2 ? VALUE_TYPE(v1) : VALUE_TYPE(v2); | |
460 | break; | |
5aefc1ca | 461 | case language_chill: |
e58de8a2 | 462 | error ("Missing Chill support in function binop_result_check.");/*FIXME*/ |
c8023e66 | 463 | } |
d8ce1326 JG |
464 | abort(); |
465 | return (struct type *)0; /* For lint */ | |
c8023e66 | 466 | } |
7ed0f002 JG |
467 | |
468 | #endif /* 0 */ | |
469 | ||
c8023e66 JG |
470 | \f |
471 | /* This page contains functions that return format strings for | |
472 | printf for printing out numbers in different formats */ | |
473 | ||
474 | /* Returns the appropriate printf format for hexadecimal | |
475 | numbers. */ | |
476 | char * | |
477 | local_hex_format_custom(pre) | |
478 | char *pre; | |
479 | { | |
480 | static char form[50]; | |
481 | ||
2e66cf7d FF |
482 | strcpy (form, local_hex_format_prefix ()); |
483 | strcat (form, "%"); | |
c8023e66 | 484 | strcat (form, pre); |
2e66cf7d FF |
485 | strcat (form, local_hex_format_specifier ()); |
486 | strcat (form, local_hex_format_suffix ()); | |
c8023e66 JG |
487 | return form; |
488 | } | |
489 | ||
490 | /* Converts a number to hexadecimal and stores it in a static | |
491 | string. Returns a pointer to this string. */ | |
492 | char * | |
493 | local_hex_string (num) | |
5573d7d4 | 494 | unsigned long num; |
c8023e66 JG |
495 | { |
496 | static char res[50]; | |
497 | ||
2e66cf7d | 498 | sprintf (res, local_hex_format(), num); |
c8023e66 JG |
499 | return res; |
500 | } | |
501 | ||
502 | /* Converts a number to custom hexadecimal and stores it in a static | |
503 | string. Returns a pointer to this string. */ | |
504 | char * | |
505 | local_hex_string_custom(num,pre) | |
5573d7d4 | 506 | unsigned long num; |
c8023e66 JG |
507 | char *pre; |
508 | { | |
509 | static char res[50]; | |
510 | ||
511 | sprintf (res, local_hex_format_custom(pre), num); | |
512 | return res; | |
513 | } | |
514 | ||
515 | /* Returns the appropriate printf format for octal | |
516 | numbers. */ | |
517 | char * | |
518 | local_octal_format_custom(pre) | |
519 | char *pre; | |
520 | { | |
521 | static char form[50]; | |
522 | ||
2e66cf7d FF |
523 | strcpy (form, local_octal_format_prefix ()); |
524 | strcat (form, "%"); | |
c8023e66 | 525 | strcat (form, pre); |
2e66cf7d FF |
526 | strcat (form, local_octal_format_specifier ()); |
527 | strcat (form, local_octal_format_suffix ()); | |
c8023e66 JG |
528 | return form; |
529 | } | |
58a66e24 FF |
530 | |
531 | /* Returns the appropriate printf format for decimal numbers. */ | |
532 | char * | |
533 | local_decimal_format_custom(pre) | |
534 | char *pre; | |
535 | { | |
536 | static char form[50]; | |
537 | ||
538 | strcpy (form, local_decimal_format_prefix ()); | |
539 | strcat (form, "%"); | |
540 | strcat (form, pre); | |
541 | strcat (form, local_decimal_format_specifier ()); | |
542 | strcat (form, local_decimal_format_suffix ()); | |
543 | return form; | |
544 | } | |
c8023e66 JG |
545 | \f |
546 | /* This page contains functions that are used in type/range checking. | |
547 | They all return zero if the type/range check fails. | |
548 | ||
549 | It is hoped that these will make extending GDB to parse different | |
550 | languages a little easier. These are primarily used in eval.c when | |
551 | evaluating expressions and making sure that their types are correct. | |
552 | Instead of having a mess of conjucted/disjuncted expressions in an "if", | |
553 | the ideas of type can be wrapped up in the following functions. | |
554 | ||
555 | Note that some of them are not currently dependent upon which language | |
556 | is currently being parsed. For example, floats are the same in | |
557 | C and Modula-2 (ie. the only floating point type has TYPE_CODE of | |
558 | TYPE_CODE_FLT), while booleans are different. */ | |
559 | ||
560 | /* Returns non-zero if its argument is a simple type. This is the same for | |
561 | both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur, | |
562 | and thus will never cause the failure of the test. */ | |
563 | int | |
564 | simple_type(type) | |
565 | struct type *type; | |
566 | { | |
567 | switch (TYPE_CODE (type)) { | |
568 | case TYPE_CODE_INT: | |
569 | case TYPE_CODE_CHAR: | |
570 | case TYPE_CODE_ENUM: | |
571 | case TYPE_CODE_FLT: | |
572 | case TYPE_CODE_RANGE: | |
573 | case TYPE_CODE_BOOL: | |
574 | return 1; | |
575 | ||
576 | default: | |
577 | return 0; | |
578 | } | |
579 | } | |
580 | ||
2e66cf7d FF |
581 | /* Returns non-zero if its argument is of an ordered type. |
582 | An ordered type is one in which the elements can be tested for the | |
583 | properties of "greater than", "less than", etc, or for which the | |
584 | operations "increment" or "decrement" make sense. */ | |
c8023e66 JG |
585 | int |
586 | ordered_type (type) | |
587 | struct type *type; | |
588 | { | |
589 | switch (TYPE_CODE (type)) { | |
590 | case TYPE_CODE_INT: | |
591 | case TYPE_CODE_CHAR: | |
592 | case TYPE_CODE_ENUM: | |
593 | case TYPE_CODE_FLT: | |
594 | case TYPE_CODE_RANGE: | |
595 | return 1; | |
596 | ||
597 | default: | |
598 | return 0; | |
599 | } | |
600 | } | |
601 | ||
602 | /* Returns non-zero if the two types are the same */ | |
603 | int | |
604 | same_type (arg1, arg2) | |
605 | struct type *arg1, *arg2; | |
606 | { | |
607 | if (structured_type(arg1) ? !structured_type(arg2) : structured_type(arg2)) | |
608 | /* One is structured and one isn't */ | |
609 | return 0; | |
610 | else if (structured_type(arg1) && structured_type(arg2)) | |
611 | return arg1 == arg2; | |
612 | else if (numeric_type(arg1) && numeric_type(arg2)) | |
613 | return (TYPE_CODE(arg2) == TYPE_CODE(arg1)) && | |
614 | (TYPE_UNSIGNED(arg1) == TYPE_UNSIGNED(arg2)) | |
615 | ? 1 : 0; | |
616 | else | |
617 | return arg1==arg2; | |
618 | } | |
619 | ||
620 | /* Returns non-zero if the type is integral */ | |
621 | int | |
622 | integral_type (type) | |
623 | struct type *type; | |
624 | { | |
625 | switch(current_language->la_language) | |
626 | { | |
627 | case language_c: | |
545af6ce | 628 | case language_cplus: |
c8023e66 JG |
629 | return (TYPE_CODE(type) != TYPE_CODE_INT) && |
630 | (TYPE_CODE(type) != TYPE_CODE_ENUM) ? 0 : 1; | |
631 | case language_m2: | |
632 | return TYPE_CODE(type) != TYPE_CODE_INT ? 0 : 1; | |
e58de8a2 FF |
633 | case language_chill: |
634 | error ("Missing Chill support in function integral_type."); /*FIXME*/ | |
c8023e66 JG |
635 | default: |
636 | error ("Language not supported."); | |
637 | } | |
638 | } | |
639 | ||
640 | /* Returns non-zero if the value is numeric */ | |
641 | int | |
642 | numeric_type (type) | |
643 | struct type *type; | |
644 | { | |
645 | switch (TYPE_CODE (type)) { | |
646 | case TYPE_CODE_INT: | |
647 | case TYPE_CODE_FLT: | |
648 | return 1; | |
649 | ||
650 | default: | |
651 | return 0; | |
652 | } | |
653 | } | |
654 | ||
655 | /* Returns non-zero if the value is a character type */ | |
656 | int | |
657 | character_type (type) | |
658 | struct type *type; | |
659 | { | |
660 | switch(current_language->la_language) | |
661 | { | |
2e66cf7d | 662 | case language_chill: |
c8023e66 JG |
663 | case language_m2: |
664 | return TYPE_CODE(type) != TYPE_CODE_CHAR ? 0 : 1; | |
665 | ||
666 | case language_c: | |
545af6ce | 667 | case language_cplus: |
c8023e66 JG |
668 | return (TYPE_CODE(type) == TYPE_CODE_INT) && |
669 | TYPE_LENGTH(type) == sizeof(char) | |
670 | ? 1 : 0; | |
51b57ded FF |
671 | default: |
672 | return (0); | |
c8023e66 JG |
673 | } |
674 | } | |
675 | ||
fcbadaee FF |
676 | /* Returns non-zero if the value is a string type */ |
677 | int | |
678 | string_type (type) | |
679 | struct type *type; | |
680 | { | |
681 | switch(current_language->la_language) | |
682 | { | |
fcbadaee | 683 | case language_chill: |
fcbadaee FF |
684 | case language_m2: |
685 | return TYPE_CODE(type) != TYPE_CODE_STRING ? 0 : 1; | |
686 | ||
687 | case language_c: | |
688 | case language_cplus: | |
689 | /* C does not have distinct string type. */ | |
690 | return (0); | |
691 | default: | |
692 | return (0); | |
693 | } | |
694 | } | |
695 | ||
c8023e66 JG |
696 | /* Returns non-zero if the value is a boolean type */ |
697 | int | |
698 | boolean_type (type) | |
699 | struct type *type; | |
700 | { | |
61932a8e JK |
701 | if (TYPE_CODE (type) == TYPE_CODE_BOOL) |
702 | return 1; | |
703 | switch(current_language->la_language) | |
704 | { | |
705 | case language_c: | |
706 | case language_cplus: | |
707 | /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL | |
708 | for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */ | |
709 | if (TYPE_CODE (type) == TYPE_CODE_INT) | |
710 | return 1; | |
51b57ded | 711 | default: |
61932a8e | 712 | break; |
c8023e66 | 713 | } |
61932a8e | 714 | return 0; |
c8023e66 JG |
715 | } |
716 | ||
717 | /* Returns non-zero if the value is a floating-point type */ | |
718 | int | |
719 | float_type (type) | |
720 | struct type *type; | |
721 | { | |
722 | return TYPE_CODE(type) == TYPE_CODE_FLT; | |
723 | } | |
724 | ||
725 | /* Returns non-zero if the value is a pointer type */ | |
726 | int | |
727 | pointer_type(type) | |
728 | struct type *type; | |
729 | { | |
730 | return TYPE_CODE(type) == TYPE_CODE_PTR || | |
731 | TYPE_CODE(type) == TYPE_CODE_REF; | |
732 | } | |
733 | ||
734 | /* Returns non-zero if the value is a structured type */ | |
735 | int | |
736 | structured_type(type) | |
737 | struct type *type; | |
738 | { | |
739 | switch(current_language->la_language) | |
740 | { | |
741 | case language_c: | |
545af6ce | 742 | case language_cplus: |
c8023e66 JG |
743 | return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || |
744 | (TYPE_CODE(type) == TYPE_CODE_UNION) || | |
745 | (TYPE_CODE(type) == TYPE_CODE_ARRAY); | |
746 | case language_m2: | |
747 | return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || | |
748 | (TYPE_CODE(type) == TYPE_CODE_SET) || | |
749 | (TYPE_CODE(type) == TYPE_CODE_ARRAY); | |
e58de8a2 FF |
750 | case language_chill: |
751 | error ("Missing Chill support in function structured_type."); /*FIXME*/ | |
51b57ded FF |
752 | default: |
753 | return (0); | |
c8023e66 JG |
754 | } |
755 | } | |
756 | \f | |
757 | /* This page contains functions that return info about | |
758 | (struct value) values used in GDB. */ | |
759 | ||
760 | /* Returns non-zero if the value VAL represents a true value. */ | |
761 | int | |
61932a8e | 762 | value_true (val) |
82a2edfb | 763 | value_ptr val; |
c8023e66 | 764 | { |
61932a8e JK |
765 | /* It is possible that we should have some sort of error if a non-boolean |
766 | value is used in this context. Possibly dependent on some kind of | |
767 | "boolean-checking" option like range checking. But it should probably | |
768 | not depend on the language except insofar as is necessary to identify | |
769 | a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean | |
770 | should be an error, probably). */ | |
771 | return !value_logical_not (val); | |
c8023e66 JG |
772 | } |
773 | \f | |
774 | /* Returns non-zero if the operator OP is defined on | |
775 | the values ARG1 and ARG2. */ | |
7ed0f002 JG |
776 | |
777 | #if 0 /* Currently unused */ | |
778 | ||
c8023e66 JG |
779 | void |
780 | binop_type_check(arg1,arg2,op) | |
82a2edfb | 781 | value_ptr arg1,arg2; |
c8023e66 JG |
782 | int op; |
783 | { | |
784 | struct type *t1, *t2; | |
785 | ||
786 | /* If we're not checking types, always return success. */ | |
787 | if (!STRICT_TYPE) | |
788 | return; | |
789 | ||
790 | t1=VALUE_TYPE(arg1); | |
82a2edfb | 791 | if (arg2 != NULL) |
c8023e66 JG |
792 | t2=VALUE_TYPE(arg2); |
793 | else | |
794 | t2=NULL; | |
795 | ||
796 | switch(op) | |
797 | { | |
798 | case BINOP_ADD: | |
799 | case BINOP_SUB: | |
800 | if ((numeric_type(t1) && pointer_type(t2)) || | |
801 | (pointer_type(t1) && numeric_type(t2))) | |
802 | { | |
318bf84f | 803 | warning ("combining pointer and integer.\n"); |
c8023e66 JG |
804 | break; |
805 | } | |
806 | case BINOP_MUL: | |
807 | case BINOP_LSH: | |
808 | case BINOP_RSH: | |
809 | if (!numeric_type(t1) || !numeric_type(t2)) | |
810 | type_op_error ("Arguments to %s must be numbers.",op); | |
811 | else if (!same_type(t1,t2)) | |
812 | type_op_error ("Arguments to %s must be of the same type.",op); | |
813 | break; | |
814 | ||
e58de8a2 FF |
815 | case BINOP_LOGICAL_AND: |
816 | case BINOP_LOGICAL_OR: | |
c8023e66 JG |
817 | if (!boolean_type(t1) || !boolean_type(t2)) |
818 | type_op_error ("Arguments to %s must be of boolean type.",op); | |
819 | break; | |
820 | ||
821 | case BINOP_EQUAL: | |
822 | if ((pointer_type(t1) && !(pointer_type(t2) || integral_type(t2))) || | |
823 | (pointer_type(t2) && !(pointer_type(t1) || integral_type(t1)))) | |
824 | type_op_error ("A pointer can only be compared to an integer or pointer.",op); | |
825 | else if ((pointer_type(t1) && integral_type(t2)) || | |
826 | (integral_type(t1) && pointer_type(t2))) | |
827 | { | |
318bf84f | 828 | warning ("combining integer and pointer.\n"); |
c8023e66 JG |
829 | break; |
830 | } | |
831 | else if (!simple_type(t1) || !simple_type(t2)) | |
832 | type_op_error ("Arguments to %s must be of simple type.",op); | |
833 | else if (!same_type(t1,t2)) | |
834 | type_op_error ("Arguments to %s must be of the same type.",op); | |
835 | break; | |
836 | ||
837 | case BINOP_REM: | |
76a0ffb4 | 838 | case BINOP_MOD: |
c8023e66 JG |
839 | if (!integral_type(t1) || !integral_type(t2)) |
840 | type_op_error ("Arguments to %s must be of integral type.",op); | |
841 | break; | |
842 | ||
843 | case BINOP_LESS: | |
844 | case BINOP_GTR: | |
845 | case BINOP_LEQ: | |
846 | case BINOP_GEQ: | |
847 | if (!ordered_type(t1) || !ordered_type(t2)) | |
848 | type_op_error ("Arguments to %s must be of ordered type.",op); | |
849 | else if (!same_type(t1,t2)) | |
850 | type_op_error ("Arguments to %s must be of the same type.",op); | |
851 | break; | |
852 | ||
853 | case BINOP_ASSIGN: | |
854 | if (pointer_type(t1) && !integral_type(t2)) | |
855 | type_op_error ("A pointer can only be assigned an integer.",op); | |
856 | else if (pointer_type(t1) && integral_type(t2)) | |
857 | { | |
318bf84f | 858 | warning ("combining integer and pointer."); |
c8023e66 JG |
859 | break; |
860 | } | |
861 | else if (!simple_type(t1) || !simple_type(t2)) | |
862 | type_op_error ("Arguments to %s must be of simple type.",op); | |
863 | else if (!same_type(t1,t2)) | |
864 | type_op_error ("Arguments to %s must be of the same type.",op); | |
865 | break; | |
866 | ||
fcbadaee | 867 | case BINOP_CONCAT: |
2fcc38b8 FF |
868 | /* FIXME: Needs to handle bitstrings as well. */ |
869 | if (!(string_type(t1) || character_type(t1) || integral_type(t1)) | |
870 | || !(string_type(t2) || character_type(t2) || integral_type(t2))) | |
fcbadaee FF |
871 | type_op_error ("Arguments to %s must be strings or characters.", op); |
872 | break; | |
873 | ||
c8023e66 JG |
874 | /* Unary checks -- arg2 is null */ |
875 | ||
e58de8a2 | 876 | case UNOP_LOGICAL_NOT: |
c8023e66 JG |
877 | if (!boolean_type(t1)) |
878 | type_op_error ("Argument to %s must be of boolean type.",op); | |
879 | break; | |
880 | ||
881 | case UNOP_PLUS: | |
882 | case UNOP_NEG: | |
883 | if (!numeric_type(t1)) | |
884 | type_op_error ("Argument to %s must be of numeric type.",op); | |
885 | break; | |
886 | ||
887 | case UNOP_IND: | |
888 | if (integral_type(t1)) | |
889 | { | |
318bf84f | 890 | warning ("combining pointer and integer.\n"); |
c8023e66 JG |
891 | break; |
892 | } | |
893 | else if (!pointer_type(t1)) | |
894 | type_op_error ("Argument to %s must be a pointer.",op); | |
895 | break; | |
896 | ||
897 | case UNOP_PREINCREMENT: | |
898 | case UNOP_POSTINCREMENT: | |
899 | case UNOP_PREDECREMENT: | |
900 | case UNOP_POSTDECREMENT: | |
901 | if (!ordered_type(t1)) | |
902 | type_op_error ("Argument to %s must be of an ordered type.",op); | |
903 | break; | |
904 | ||
905 | default: | |
906 | /* Ok. The following operators have different meanings in | |
907 | different languages. */ | |
908 | switch(current_language->la_language) | |
909 | { | |
910 | #ifdef _LANG_c | |
911 | case language_c: | |
545af6ce | 912 | case language_cplus: |
c8023e66 JG |
913 | switch(op) |
914 | { | |
915 | case BINOP_DIV: | |
916 | if (!numeric_type(t1) || !numeric_type(t2)) | |
917 | type_op_error ("Arguments to %s must be numbers.",op); | |
918 | break; | |
919 | } | |
920 | break; | |
921 | #endif | |
922 | ||
923 | #ifdef _LANG_m2 | |
924 | case language_m2: | |
925 | switch(op) | |
926 | { | |
927 | case BINOP_DIV: | |
928 | if (!float_type(t1) || !float_type(t2)) | |
929 | type_op_error ("Arguments to %s must be floating point numbers.",op); | |
930 | break; | |
931 | case BINOP_INTDIV: | |
932 | if (!integral_type(t1) || !integral_type(t2)) | |
933 | type_op_error ("Arguments to %s must be of integral type.",op); | |
934 | break; | |
935 | } | |
936 | #endif | |
e58de8a2 FF |
937 | |
938 | #ifdef _LANG_chill | |
939 | case language_chill: | |
940 | error ("Missing Chill support in function binop_type_check.");/*FIXME*/ | |
941 | #endif | |
942 | ||
c8023e66 JG |
943 | } |
944 | } | |
945 | } | |
7ed0f002 JG |
946 | |
947 | #endif /* 0 */ | |
948 | ||
c8023e66 JG |
949 | \f |
950 | /* This page contains functions for the printing out of | |
951 | error messages that occur during type- and range- | |
952 | checking. */ | |
953 | ||
954 | /* Prints the format string FMT with the operator as a string | |
955 | corresponding to the opcode OP. If FATAL is non-zero, then | |
956 | this is an error and error () is called. Otherwise, it is | |
957 | a warning and printf() is called. */ | |
958 | void | |
959 | op_error (fmt,op,fatal) | |
960 | char *fmt; | |
961 | enum exp_opcode op; | |
962 | int fatal; | |
963 | { | |
964 | if (fatal) | |
965 | error (fmt,op_string(op)); | |
966 | else | |
967 | { | |
318bf84f | 968 | warning (fmt,op_string(op)); |
c8023e66 JG |
969 | } |
970 | } | |
971 | ||
972 | /* These are called when a language fails a type- or range-check. | |
973 | The first argument should be a printf()-style format string, and | |
974 | the rest of the arguments should be its arguments. If | |
975 | [type|range]_check is [type|range]_check_on, then return_to_top_level() | |
976 | is called in the style of error (). Otherwise, the message is prefixed | |
318bf84f | 977 | by the value of warning_pre_print and we do not return to the top level. */ |
7ed0f002 | 978 | |
c8023e66 JG |
979 | void |
980 | type_error (va_alist) | |
7ed0f002 | 981 | va_dcl |
c8023e66 JG |
982 | { |
983 | va_list args; | |
984 | char *string; | |
985 | ||
a0cf4681 | 986 | if (type_check == type_check_warn) |
e16b9023 | 987 | fprintf_filtered (gdb_stderr, warning_pre_print); |
c8023e66 | 988 | else |
a0cf4681 | 989 | error_begin (); |
c8023e66 JG |
990 | |
991 | va_start (args); | |
992 | string = va_arg (args, char *); | |
e16b9023 JK |
993 | vfprintf_filtered (gdb_stderr, string, args); |
994 | fprintf_filtered (gdb_stderr, "\n"); | |
c8023e66 | 995 | va_end (args); |
a0cf4681 JK |
996 | if (type_check == type_check_on) |
997 | return_to_top_level (RETURN_ERROR); | |
c8023e66 JG |
998 | } |
999 | ||
1000 | void | |
1001 | range_error (va_alist) | |
7ed0f002 | 1002 | va_dcl |
c8023e66 JG |
1003 | { |
1004 | va_list args; | |
1005 | char *string; | |
1006 | ||
a0cf4681 | 1007 | if (range_check == range_check_warn) |
e16b9023 | 1008 | fprintf_filtered (gdb_stderr, warning_pre_print); |
c8023e66 | 1009 | else |
a0cf4681 | 1010 | error_begin (); |
c8023e66 JG |
1011 | |
1012 | va_start (args); | |
1013 | string = va_arg (args, char *); | |
e16b9023 JK |
1014 | vfprintf_filtered (gdb_stderr, string, args); |
1015 | fprintf_filtered (gdb_stderr, "\n"); | |
c8023e66 | 1016 | va_end (args); |
a0cf4681 JK |
1017 | if (range_check == range_check_on) |
1018 | return_to_top_level (RETURN_ERROR); | |
c8023e66 JG |
1019 | } |
1020 | ||
1021 | \f | |
1022 | /* This page contains miscellaneous functions */ | |
1023 | ||
bf229b4e FF |
1024 | /* Return the language struct for a given language enum. */ |
1025 | ||
1026 | const struct language_defn * | |
1027 | language_def(lang) | |
1028 | enum language lang; | |
1029 | { | |
1030 | int i; | |
1031 | ||
1032 | for (i = 0; i < languages_size; i++) { | |
1033 | if (languages[i]->la_language == lang) { | |
1034 | return languages[i]; | |
1035 | } | |
1036 | } | |
1037 | return NULL; | |
1038 | } | |
1039 | ||
c8023e66 JG |
1040 | /* Return the language as a string */ |
1041 | char * | |
1042 | language_str(lang) | |
1043 | enum language lang; | |
1044 | { | |
1045 | int i; | |
1046 | ||
1047 | for (i = 0; i < languages_size; i++) { | |
1048 | if (languages[i]->la_language == lang) { | |
1049 | return languages[i]->la_name; | |
1050 | } | |
1051 | } | |
1052 | return "Unknown"; | |
1053 | } | |
1054 | ||
c8023e66 | 1055 | static void |
d8ce1326 JG |
1056 | set_check (ignore, from_tty) |
1057 | char *ignore; | |
c8023e66 JG |
1058 | int from_tty; |
1059 | { | |
199b2450 | 1060 | printf_unfiltered( |
c8023e66 | 1061 | "\"set check\" must be followed by the name of a check subcommand.\n"); |
199b2450 | 1062 | help_list(setchecklist, "set check ", -1, gdb_stdout); |
c8023e66 JG |
1063 | } |
1064 | ||
1065 | static void | |
be772100 JG |
1066 | show_check (ignore, from_tty) |
1067 | char *ignore; | |
c8023e66 JG |
1068 | int from_tty; |
1069 | { | |
1070 | cmd_show_list(showchecklist, from_tty, ""); | |
1071 | } | |
1072 | \f | |
1073 | /* Add a language to the set of known languages. */ | |
1074 | ||
1075 | void | |
1076 | add_language (lang) | |
7ed0f002 | 1077 | const struct language_defn *lang; |
c8023e66 JG |
1078 | { |
1079 | if (lang->la_magic != LANG_MAGIC) | |
1080 | { | |
199b2450 | 1081 | fprintf_unfiltered(gdb_stderr, "Magic number of %s language struct wrong\n", |
c8023e66 JG |
1082 | lang->la_name); |
1083 | abort(); | |
1084 | } | |
1085 | ||
1086 | if (!languages) | |
1087 | { | |
1088 | languages_allocsize = DEFAULT_ALLOCSIZE; | |
7ed0f002 | 1089 | languages = (const struct language_defn **) xmalloc |
c8023e66 JG |
1090 | (languages_allocsize * sizeof (*languages)); |
1091 | } | |
1092 | if (languages_size >= languages_allocsize) | |
1093 | { | |
1094 | languages_allocsize *= 2; | |
7ed0f002 | 1095 | languages = (const struct language_defn **) xrealloc ((char *) languages, |
c8023e66 JG |
1096 | languages_allocsize * sizeof (*languages)); |
1097 | } | |
1098 | languages[languages_size++] = lang; | |
c8023e66 JG |
1099 | } |
1100 | ||
1101 | /* Define the language that is no language. */ | |
1102 | ||
7ed0f002 | 1103 | static int |
c8023e66 JG |
1104 | unk_lang_parser () |
1105 | { | |
1106 | return 1; | |
1107 | } | |
1108 | ||
7ed0f002 JG |
1109 | static void |
1110 | unk_lang_error (msg) | |
1111 | char *msg; | |
c8023e66 JG |
1112 | { |
1113 | error ("Attempted to parse an expression with unknown language"); | |
1114 | } | |
1115 | ||
5d074aa9 FF |
1116 | static void |
1117 | unk_lang_printchar (c, stream) | |
1118 | register int c; | |
199b2450 | 1119 | GDB_FILE *stream; |
5d074aa9 FF |
1120 | { |
1121 | error ("internal error - unimplemented function unk_lang_printchar called."); | |
1122 | } | |
1123 | ||
1124 | static void | |
1125 | unk_lang_printstr (stream, string, length, force_ellipses) | |
199b2450 | 1126 | GDB_FILE *stream; |
5d074aa9 FF |
1127 | char *string; |
1128 | unsigned int length; | |
1129 | int force_ellipses; | |
1130 | { | |
1131 | error ("internal error - unimplemented function unk_lang_printstr called."); | |
1132 | } | |
1133 | ||
bf229b4e FF |
1134 | static struct type * |
1135 | unk_lang_create_fundamental_type (objfile, typeid) | |
1136 | struct objfile *objfile; | |
1137 | int typeid; | |
1138 | { | |
1139 | error ("internal error - unimplemented function unk_lang_create_fundamental_type called."); | |
1140 | } | |
1141 | ||
a8a69e63 FF |
1142 | void |
1143 | unk_lang_print_type (type, varstring, stream, show, level) | |
1144 | struct type *type; | |
1145 | char *varstring; | |
199b2450 | 1146 | GDB_FILE *stream; |
a8a69e63 FF |
1147 | int show; |
1148 | int level; | |
1149 | { | |
1150 | error ("internal error - unimplemented function unk_lang_print_type called."); | |
1151 | } | |
1152 | ||
1153 | int | |
1154 | unk_lang_val_print (type, valaddr, address, stream, format, deref_ref, | |
1155 | recurse, pretty) | |
1156 | struct type *type; | |
1157 | char *valaddr; | |
1158 | CORE_ADDR address; | |
199b2450 | 1159 | GDB_FILE *stream; |
a8a69e63 FF |
1160 | int format; |
1161 | int deref_ref; | |
1162 | int recurse; | |
1163 | enum val_prettyprint pretty; | |
1164 | { | |
1165 | error ("internal error - unimplemented function unk_lang_val_print called."); | |
1166 | } | |
1167 | ||
e10cfcaa PB |
1168 | int |
1169 | unk_lang_value_print (val, stream, format, pretty) | |
1170 | value_ptr val; | |
1171 | GDB_FILE *stream; | |
1172 | int format; | |
1173 | enum val_prettyprint pretty; | |
1174 | { | |
1175 | error ("internal error - unimplemented function unk_lang_value_print called."); | |
1176 | } | |
1177 | ||
c8023e66 | 1178 | static struct type ** const (unknown_builtin_types[]) = { 0 }; |
a8a69e63 | 1179 | static const struct op_print unk_op_print_tab[] = { |
8631194d | 1180 | {NULL, OP_NULL, PREC_NULL, 0} |
a8a69e63 | 1181 | }; |
c8023e66 JG |
1182 | |
1183 | const struct language_defn unknown_language_defn = { | |
1184 | "unknown", | |
1185 | language_unknown, | |
1186 | &unknown_builtin_types[0], | |
1187 | range_check_off, | |
1188 | type_check_off, | |
1189 | unk_lang_parser, | |
1190 | unk_lang_error, | |
5d074aa9 FF |
1191 | unk_lang_printchar, /* Print character constant */ |
1192 | unk_lang_printstr, | |
bf229b4e | 1193 | unk_lang_create_fundamental_type, |
a8a69e63 FF |
1194 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
1195 | unk_lang_val_print, /* Print a value using appropriate syntax */ | |
e10cfcaa | 1196 | unk_lang_value_print, /* Print a top-level value */ |
2e66cf7d | 1197 | {"", "", "", ""}, /* Binary format info */ |
5573d7d4 JK |
1198 | {"0%lo", "0", "o", ""}, /* Octal format info */ |
1199 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
1200 | {"0x%lx", "0x", "x", ""}, /* Hex format info */ | |
c8023e66 JG |
1201 | unk_op_print_tab, /* expression operators for printing */ |
1202 | LANG_MAGIC | |
1203 | }; | |
1204 | ||
1205 | /* These two structs define fake entries for the "local" and "auto" options. */ | |
1206 | const struct language_defn auto_language_defn = { | |
1207 | "auto", | |
1208 | language_auto, | |
1209 | &unknown_builtin_types[0], | |
1210 | range_check_off, | |
1211 | type_check_off, | |
1212 | unk_lang_parser, | |
1213 | unk_lang_error, | |
5d074aa9 FF |
1214 | unk_lang_printchar, /* Print character constant */ |
1215 | unk_lang_printstr, | |
bf229b4e | 1216 | unk_lang_create_fundamental_type, |
a8a69e63 FF |
1217 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
1218 | unk_lang_val_print, /* Print a value using appropriate syntax */ | |
e10cfcaa | 1219 | unk_lang_value_print, /* Print a top-level value */ |
2e66cf7d | 1220 | {"", "", "", ""}, /* Binary format info */ |
5573d7d4 JK |
1221 | {"0%lo", "0", "o", ""}, /* Octal format info */ |
1222 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
1223 | {"0x%lx", "0x", "x", ""}, /* Hex format info */ | |
c8023e66 JG |
1224 | unk_op_print_tab, /* expression operators for printing */ |
1225 | LANG_MAGIC | |
1226 | }; | |
1227 | ||
1228 | const struct language_defn local_language_defn = { | |
1229 | "local", | |
1230 | language_auto, | |
1231 | &unknown_builtin_types[0], | |
1232 | range_check_off, | |
1233 | type_check_off, | |
1234 | unk_lang_parser, | |
1235 | unk_lang_error, | |
5d074aa9 FF |
1236 | unk_lang_printchar, /* Print character constant */ |
1237 | unk_lang_printstr, | |
bf229b4e | 1238 | unk_lang_create_fundamental_type, |
a8a69e63 FF |
1239 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
1240 | unk_lang_val_print, /* Print a value using appropriate syntax */ | |
e10cfcaa | 1241 | unk_lang_value_print, /* Print a top-level value */ |
2e66cf7d | 1242 | {"", "", "", ""}, /* Binary format info */ |
5573d7d4 JK |
1243 | {"0%lo", "0", "o", ""}, /* Octal format info */ |
1244 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
1245 | {"0x%lx", "0x", "x", ""}, /* Hex format info */ | |
c8023e66 JG |
1246 | unk_op_print_tab, /* expression operators for printing */ |
1247 | LANG_MAGIC | |
1248 | }; | |
1249 | \f | |
1250 | /* Initialize the language routines */ | |
1251 | ||
1252 | void | |
1253 | _initialize_language() | |
1254 | { | |
1255 | struct cmd_list_element *set, *show; | |
1256 | ||
1257 | /* GDB commands for language specific stuff */ | |
1258 | ||
1259 | set = add_set_cmd ("language", class_support, var_string_noescape, | |
1260 | (char *)&language, | |
0b798409 | 1261 | "Set the current source language.", |
c8023e66 JG |
1262 | &setlist); |
1263 | show = add_show_from_set (set, &showlist); | |
1ab3bf1b JG |
1264 | set->function.cfunc = set_language_command; |
1265 | show->function.cfunc = show_language_command; | |
c8023e66 JG |
1266 | |
1267 | add_prefix_cmd ("check", no_class, set_check, | |
1268 | "Set the status of the type/range checker", | |
1269 | &setchecklist, "set check ", 0, &setlist); | |
1270 | add_alias_cmd ("c", "check", no_class, 1, &setlist); | |
1271 | add_alias_cmd ("ch", "check", no_class, 1, &setlist); | |
1272 | ||
1273 | add_prefix_cmd ("check", no_class, show_check, | |
1274 | "Show the status of the type/range checker", | |
7cb83757 | 1275 | &showchecklist, "show check ", 0, &showlist); |
c8023e66 JG |
1276 | add_alias_cmd ("c", "check", no_class, 1, &showlist); |
1277 | add_alias_cmd ("ch", "check", no_class, 1, &showlist); | |
1278 | ||
1279 | set = add_set_cmd ("type", class_support, var_string_noescape, | |
1280 | (char *)&type, | |
7cb83757 | 1281 | "Set type checking. (on/warn/off/auto)", |
c8023e66 JG |
1282 | &setchecklist); |
1283 | show = add_show_from_set (set, &showchecklist); | |
1ab3bf1b JG |
1284 | set->function.cfunc = set_type_command; |
1285 | show->function.cfunc = show_type_command; | |
c8023e66 JG |
1286 | |
1287 | set = add_set_cmd ("range", class_support, var_string_noescape, | |
1288 | (char *)&range, | |
7cb83757 | 1289 | "Set range checking. (on/warn/off/auto)", |
c8023e66 JG |
1290 | &setchecklist); |
1291 | show = add_show_from_set (set, &showchecklist); | |
1ab3bf1b JG |
1292 | set->function.cfunc = set_range_command; |
1293 | show->function.cfunc = show_range_command; | |
c8023e66 JG |
1294 | |
1295 | add_language (&unknown_language_defn); | |
1296 | add_language (&local_language_defn); | |
1297 | add_language (&auto_language_defn); | |
1298 | ||
1299 | language = savestring ("auto",strlen("auto")); | |
1300 | range = savestring ("auto",strlen("auto")); | |
1301 | type = savestring ("auto",strlen("auto")); | |
1302 | ||
1303 | /* Have the above take effect */ | |
1304 | ||
5f3d478e | 1305 | set_language_command (language, 0); |
c8023e66 JG |
1306 | set_type_command (NULL, 0); |
1307 | set_range_command (NULL, 0); | |
1308 | } |