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