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