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