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