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