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