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