1 /* Multiple source language support for GDB.
2 Copyright 1991, 1992, 2000 Free Software Foundation, Inc.
3 Contributed by the Department of Computer Science at the State University
4 of New York at Buffalo.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This file contains functions that return things that are specific
24 to languages. Each function should examine current_language if necessary,
25 and return the appropriate result. */
27 /* FIXME: Most of these would be better organized as macros which
28 return data out of a "language-specific" struct pointer that is set
29 whenever the working language changes. That would be a lot faster. */
33 #include "gdb_string.h"
40 #include "expression.h"
43 #include "parser-defs.h"
46 extern void _initialize_language (void);
48 static void show_language_command (char *, int);
50 static void set_language_command (char *, int);
52 static void show_type_command (char *, int);
54 static void set_type_command (char *, int);
56 static void show_range_command (char *, int);
58 static void set_range_command (char *, int);
60 static void set_range_str (void);
62 static void set_type_str (void);
64 static void set_lang_str (void);
66 static void unk_lang_error (char *);
68 static int unk_lang_parser (void);
70 static void show_check (char *, int);
72 static void set_check (char *, int);
74 static void set_type_range (void);
76 static void unk_lang_emit_char (int c
, struct ui_file
*stream
, int quoter
);
78 static void unk_lang_printchar (int c
, struct ui_file
*stream
);
80 static void unk_lang_printstr (struct ui_file
* stream
, char *string
,
81 unsigned int length
, int width
,
84 static struct type
*unk_lang_create_fundamental_type (struct objfile
*, int);
86 static void unk_lang_print_type (struct type
*, char *, struct ui_file
*,
89 static int unk_lang_val_print (struct type
*, char *, int, CORE_ADDR
,
90 struct ui_file
*, int, int, int,
91 enum val_prettyprint
);
93 static int unk_lang_value_print (value_ptr
, struct ui_file
*, int, enum val_prettyprint
);
95 /* Forward declaration */
96 extern const struct language_defn unknown_language_defn
;
97 extern char *warning_pre_print
;
99 /* The current (default at startup) state of type and range checking.
100 (If the modes are set to "auto", though, these are changed based
101 on the default language at startup, and then again based on the
102 language of the first source file. */
104 enum range_mode range_mode
= range_mode_auto
;
105 enum range_check range_check
= range_check_off
;
106 enum type_mode type_mode
= type_mode_auto
;
107 enum type_check type_check
= type_check_off
;
109 /* The current language and language_mode (see language.h) */
111 const struct language_defn
*current_language
= &unknown_language_defn
;
112 enum language_mode language_mode
= language_mode_auto
;
114 /* The language that the user expects to be typing in (the language
115 of main(), or the last language we notified them about, or C). */
117 const struct language_defn
*expected_language
;
119 /* The list of supported languages. The list itself is malloc'd. */
121 static const struct language_defn
**languages
;
122 static unsigned languages_size
;
123 static unsigned languages_allocsize
;
124 #define DEFAULT_ALLOCSIZE 4
126 /* The "set language/type/range" commands all put stuff in these
127 buffers. This is to make them work as set/show commands. The
128 user's string is copied here, then the set_* commands look at
129 them and update them to something that looks nice when it is
132 static char *language
;
136 /* Warning issued when current_language and the language of the current
137 frame do not match. */
138 char lang_frame_mismatch_warn
[] =
139 "Warning: the current language does not match this frame.";
142 /* This page contains the functions corresponding to GDB commands
143 and their helpers. */
145 /* Show command. Display a warning if the language set
146 does not match the frame. */
148 show_language_command (ignore
, from_tty
)
152 enum language flang
; /* The language of the current frame */
154 flang
= get_frame_language ();
155 if (flang
!= language_unknown
&&
156 language_mode
== language_mode_manual
&&
157 current_language
->la_language
!= flang
)
158 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
161 /* Set command. Change the current working language. */
163 set_language_command (ignore
, from_tty
)
171 if (!language
|| !language
[0])
173 printf_unfiltered ("The currently understood settings are:\n\n");
174 printf_unfiltered ("local or auto Automatic setting based on source file\n");
176 for (i
= 0; i
< languages_size
; ++i
)
178 /* Already dealt with these above. */
179 if (languages
[i
]->la_language
== language_unknown
180 || languages
[i
]->la_language
== language_auto
)
183 /* FIXME for now assume that the human-readable name is just
184 a capitalization of the internal name. */
185 printf_unfiltered ("%-16s Use the %c%s language\n",
186 languages
[i
]->la_name
,
187 /* Capitalize first letter of language
189 toupper (languages
[i
]->la_name
[0]),
190 languages
[i
]->la_name
+ 1);
192 /* Restore the silly string. */
193 set_language (current_language
->la_language
);
197 /* Search the list of languages for a match. */
198 for (i
= 0; i
< languages_size
; i
++)
200 if (STREQ (languages
[i
]->la_name
, language
))
202 /* Found it! Go into manual mode, and use this language. */
203 if (languages
[i
]->la_language
== language_auto
)
205 /* Enter auto mode. Set to the current frame's language, if known. */
206 language_mode
= language_mode_auto
;
207 flang
= get_frame_language ();
208 if (flang
!= language_unknown
)
209 set_language (flang
);
210 expected_language
= current_language
;
215 /* Enter manual mode. Set the specified language. */
216 language_mode
= language_mode_manual
;
217 current_language
= languages
[i
];
220 expected_language
= current_language
;
226 /* Reset the language (esp. the global string "language") to the
228 err_lang
= savestring (language
, strlen (language
));
229 make_cleanup (free
, err_lang
); /* Free it after error */
230 set_language (current_language
->la_language
);
231 error ("Unknown language `%s'.", err_lang
);
234 /* Show command. Display a warning if the type setting does
235 not match the current language. */
237 show_type_command (ignore
, from_tty
)
241 if (type_check
!= current_language
->la_type_check
)
243 "Warning: the current type check setting does not match the language.\n");
246 /* Set command. Change the setting for type checking. */
248 set_type_command (ignore
, from_tty
)
252 if (STREQ (type
, "on"))
254 type_check
= type_check_on
;
255 type_mode
= type_mode_manual
;
257 else if (STREQ (type
, "warn"))
259 type_check
= type_check_warn
;
260 type_mode
= type_mode_manual
;
262 else if (STREQ (type
, "off"))
264 type_check
= type_check_off
;
265 type_mode
= type_mode_manual
;
267 else if (STREQ (type
, "auto"))
269 type_mode
= type_mode_auto
;
271 /* Avoid hitting the set_type_str call below. We
272 did it in set_type_range. */
277 warning ("Unrecognized type check setting: \"%s\"", type
);
280 show_type_command ((char *) NULL
, from_tty
);
283 /* Show command. Display a warning if the range setting does
284 not match the current language. */
286 show_range_command (ignore
, from_tty
)
291 if (range_check
!= current_language
->la_range_check
)
293 "Warning: the current range check setting does not match the language.\n");
296 /* Set command. Change the setting for range checking. */
298 set_range_command (ignore
, from_tty
)
302 if (STREQ (range
, "on"))
304 range_check
= range_check_on
;
305 range_mode
= range_mode_manual
;
307 else if (STREQ (range
, "warn"))
309 range_check
= range_check_warn
;
310 range_mode
= range_mode_manual
;
312 else if (STREQ (range
, "off"))
314 range_check
= range_check_off
;
315 range_mode
= range_mode_manual
;
317 else if (STREQ (range
, "auto"))
319 range_mode
= range_mode_auto
;
321 /* Avoid hitting the set_range_str call below. We
322 did it in set_type_range. */
327 warning ("Unrecognized range check setting: \"%s\"", range
);
330 show_range_command ((char *) 0, from_tty
);
333 /* Set the status of range and type checking based on
334 the current modes and the current language.
335 If SHOW is non-zero, then print out the current language,
336 type and range checking status. */
341 if (range_mode
== range_mode_auto
)
342 range_check
= current_language
->la_range_check
;
344 if (type_mode
== type_mode_auto
)
345 type_check
= current_language
->la_type_check
;
351 /* Set current language to (enum language) LANG. Returns previous language. */
358 enum language prev_language
;
360 prev_language
= current_language
->la_language
;
362 for (i
= 0; i
< languages_size
; i
++)
364 if (languages
[i
]->la_language
== lang
)
366 current_language
= languages
[i
];
373 return prev_language
;
376 /* This page contains functions that update the global vars
377 language, type and range. */
385 if (language_mode
== language_mode_auto
)
386 prefix
= "auto; currently ";
388 language
= concat (prefix
, current_language
->la_name
, NULL
);
394 char *tmp
= NULL
, *prefix
= "";
398 if (type_mode
== type_mode_auto
)
399 prefix
= "auto; currently ";
409 case type_check_warn
:
413 error ("Unrecognized type check setting.");
416 type
= concat (prefix
, tmp
, NULL
);
422 char *tmp
, *pref
= "";
424 if (range_mode
== range_mode_auto
)
425 pref
= "auto; currently ";
432 case range_check_off
:
435 case range_check_warn
:
439 error ("Unrecognized range check setting.");
444 range
= concat (pref
, tmp
, NULL
);
448 /* Print out the current language settings: language, range and
449 type checking. If QUIETLY, print only what has changed. */
452 language_info (quietly
)
455 if (quietly
&& expected_language
== current_language
)
458 expected_language
= current_language
;
459 printf_unfiltered ("Current language: %s\n", language
);
460 show_language_command ((char *) 0, 1);
464 printf_unfiltered ("Type checking: %s\n", type
);
465 show_type_command ((char *) 0, 1);
466 printf_unfiltered ("Range checking: %s\n", range
);
467 show_range_command ((char *) 0, 1);
471 /* Return the result of a binary operation. */
473 #if 0 /* Currently unused */
476 binop_result_type (v1
, v2
)
480 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
481 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
483 int l1
= TYPE_LENGTH (t1
);
484 int l2
= TYPE_LENGTH (t2
);
486 switch (current_language
->la_language
)
490 if (TYPE_CODE (t1
) == TYPE_CODE_FLT
)
491 return TYPE_CODE (t2
) == TYPE_CODE_FLT
&& l2
> l1
?
492 VALUE_TYPE (v2
) : VALUE_TYPE (v1
);
493 else if (TYPE_CODE (t2
) == TYPE_CODE_FLT
)
494 return TYPE_CODE (t1
) == TYPE_CODE_FLT
&& l1
> l2
?
495 VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
496 else if (TYPE_UNSIGNED (t1
) && l1
> l2
)
497 return VALUE_TYPE (v1
);
498 else if (TYPE_UNSIGNED (t2
) && l2
> l1
)
499 return VALUE_TYPE (v2
);
500 else /* Both are signed. Result is the longer type */
501 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
504 /* If we are doing type-checking, l1 should equal l2, so this is
506 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
509 error ("Missing Chill support in function binop_result_check."); /*FIXME */
512 return (struct type
*) 0; /* For lint */
518 /* This page contains functions that return format strings for
519 printf for printing out numbers in different formats */
521 /* Returns the appropriate printf format for hexadecimal
524 local_hex_format_custom (pre
)
527 static char form
[50];
529 strcpy (form
, local_hex_format_prefix ());
532 strcat (form
, local_hex_format_specifier ());
533 strcat (form
, local_hex_format_suffix ());
538 /* FIXME: cagney/2000-03-04: This function does not appear to be used.
539 It can be deleted once 5.0 has been released. */
540 /* FIXME: cagney/2000-03-04: This code assumes that the compiler
541 supports ``long long''. */
542 /* Converts a number to hexadecimal (without leading "0x") and stores it in a
543 static string. Returns a pointer to this string. */
546 longest_raw_hex_string (num
)
549 static char res_longest_raw_hex_string
[50];
550 long long ll
= num
; /* MERGEBUG ?? see below */
551 res_longest_raw_hex_string
[0] = 0;
552 /* MERGEBUG ?? As a quick fix I am replacing this with sprintf
553 strcat_address_numeric (num, 0, res_longest_raw_hex_string, 50);
556 sprintf (res_longest_raw_hex_string
, "%llx", ll
);
557 return res_longest_raw_hex_string
;
561 /* Converts a number to hexadecimal and stores it in a static
562 string. Returns a pointer to this string. */
564 local_hex_string (num
)
569 sprintf (res
, local_hex_format (), num
);
573 /* Converts a LONGEST number to hexadecimal and stores it in a static
574 string. Returns a pointer to this string. */
576 longest_local_hex_string (num
)
579 return longest_local_hex_string_custom (num
, "l");
582 /* Converts a number to custom hexadecimal and stores it in a static
583 string. Returns a pointer to this string. */
585 local_hex_string_custom (num
, pre
)
591 sprintf (res
, local_hex_format_custom (pre
), num
);
595 /* Converts a LONGEST number to custom hexadecimal and stores it in a static
596 string. Returns a pointer to this string. Note that the width parameter
597 should end with "l", e.g. "08l" as with calls to local_hex_string_custom */
600 longest_local_hex_string_custom (num
, width
)
604 #define RESULT_BUF_LEN 50
605 static char res2
[RESULT_BUF_LEN
];
606 char format
[RESULT_BUF_LEN
];
607 #if !defined (PRINTF_HAS_LONG_LONG)
611 char *pad_char
; /* string with one character */
614 char temp_nbr_buf
[RESULT_BUF_LEN
];
617 #ifndef CC_HAS_LONG_LONG
618 /* If there is no long long, then LONGEST should be just long and we
619 can use local_hex_string_custom
621 return local_hex_string_custom ((unsigned long) num
, width
);
622 #elif defined (PRINTF_HAS_LONG_LONG)
623 /* Just use printf. */
624 strcpy (format
, local_hex_format_prefix ()); /* 0x */
625 strcat (format
, "%");
626 strcat (format
, width
); /* e.g. "08l" */
627 strcat (format
, "l"); /* need "ll" for long long */
628 strcat (format
, local_hex_format_specifier ()); /* "x" */
629 strcat (format
, local_hex_format_suffix ()); /* "" */
630 sprintf (res2
, format
, num
);
632 #else /* !defined (PRINTF_HAS_LONG_LONG) */
633 /* Use strcat_address_numeric to print the number into a string, then
634 build the result string from local_hex_format_prefix, padding and
635 the hex representation as indicated by "width". */
638 /* With use_local == 0, we don't get the leading "0x" prefix. */
639 /* MERGEBUG ?? As a quick fix I am replacing this call to
640 strcat_address_numeric with sprintf
641 strcat_address_numeric(num, 0, temp_nbr_buf, RESULT_BUF_LEN);
646 sprintf (temp_nbr_buf
, "%llx", ll
);
652 if (*parse_ptr
== '-')
657 if (*parse_ptr
== '0')
661 pad_char
= "0"; /* If padding is on the right, it is blank */
663 field_width
= atoi (parse_ptr
);
664 num_len
= strlen (temp_nbr_buf
);
665 num_pad_chars
= field_width
- strlen (temp_nbr_buf
); /* possibly negative */
667 if (strlen (local_hex_format_prefix ()) + num_len
+ num_pad_chars
668 < RESULT_BUF_LEN
) /* paranoia */
669 internal_error ("longest_local_hex_string_custom: insufficient space to store result");
671 strcpy (res2
, local_hex_format_prefix ());
674 while (num_pad_chars
> 0)
676 strcat (res2
, pad_char
);
680 strcat (res2
, temp_nbr_buf
);
683 while (num_pad_chars
> 0)
685 strcat (res2
, pad_char
);
692 } /* longest_local_hex_string_custom */
694 /* Returns the appropriate printf format for octal
697 local_octal_format_custom (pre
)
700 static char form
[50];
702 strcpy (form
, local_octal_format_prefix ());
705 strcat (form
, local_octal_format_specifier ());
706 strcat (form
, local_octal_format_suffix ());
710 /* Returns the appropriate printf format for decimal numbers. */
712 local_decimal_format_custom (pre
)
715 static char form
[50];
717 strcpy (form
, local_decimal_format_prefix ());
720 strcat (form
, local_decimal_format_specifier ());
721 strcat (form
, local_decimal_format_suffix ());
726 /* This page contains functions that are used in type/range checking.
727 They all return zero if the type/range check fails.
729 It is hoped that these will make extending GDB to parse different
730 languages a little easier. These are primarily used in eval.c when
731 evaluating expressions and making sure that their types are correct.
732 Instead of having a mess of conjucted/disjuncted expressions in an "if",
733 the ideas of type can be wrapped up in the following functions.
735 Note that some of them are not currently dependent upon which language
736 is currently being parsed. For example, floats are the same in
737 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
738 TYPE_CODE_FLT), while booleans are different. */
740 /* Returns non-zero if its argument is a simple type. This is the same for
741 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
742 and thus will never cause the failure of the test. */
747 CHECK_TYPEDEF (type
);
748 switch (TYPE_CODE (type
))
754 case TYPE_CODE_RANGE
:
763 /* Returns non-zero if its argument is of an ordered type.
764 An ordered type is one in which the elements can be tested for the
765 properties of "greater than", "less than", etc, or for which the
766 operations "increment" or "decrement" make sense. */
771 CHECK_TYPEDEF (type
);
772 switch (TYPE_CODE (type
))
778 case TYPE_CODE_RANGE
:
786 /* Returns non-zero if the two types are the same */
788 same_type (arg1
, arg2
)
789 struct type
*arg1
, *arg2
;
791 CHECK_TYPEDEF (type
);
792 if (structured_type (arg1
) ? !structured_type (arg2
) : structured_type (arg2
))
793 /* One is structured and one isn't */
795 else if (structured_type (arg1
) && structured_type (arg2
))
797 else if (numeric_type (arg1
) && numeric_type (arg2
))
798 return (TYPE_CODE (arg2
) == TYPE_CODE (arg1
)) &&
799 (TYPE_UNSIGNED (arg1
) == TYPE_UNSIGNED (arg2
))
805 /* Returns non-zero if the type is integral */
810 CHECK_TYPEDEF (type
);
811 switch (current_language
->la_language
)
815 return (TYPE_CODE (type
) != TYPE_CODE_INT
) &&
816 (TYPE_CODE (type
) != TYPE_CODE_ENUM
) ? 0 : 1;
818 case language_pascal
:
819 return TYPE_CODE (type
) != TYPE_CODE_INT
? 0 : 1;
821 error ("Missing Chill support in function integral_type."); /*FIXME */
823 error ("Language not supported.");
827 /* Returns non-zero if the value is numeric */
832 CHECK_TYPEDEF (type
);
833 switch (TYPE_CODE (type
))
844 /* Returns non-zero if the value is a character type */
846 character_type (type
)
849 CHECK_TYPEDEF (type
);
850 switch (current_language
->la_language
)
854 case language_pascal
:
855 return TYPE_CODE (type
) != TYPE_CODE_CHAR
? 0 : 1;
859 return (TYPE_CODE (type
) == TYPE_CODE_INT
) &&
860 TYPE_LENGTH (type
) == sizeof (char)
867 /* Returns non-zero if the value is a string type */
872 CHECK_TYPEDEF (type
);
873 switch (current_language
->la_language
)
877 case language_pascal
:
878 return TYPE_CODE (type
) != TYPE_CODE_STRING
? 0 : 1;
882 /* C does not have distinct string type. */
889 /* Returns non-zero if the value is a boolean type */
894 CHECK_TYPEDEF (type
);
895 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
897 switch (current_language
->la_language
)
901 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
902 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
903 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
911 /* Returns non-zero if the value is a floating-point type */
916 CHECK_TYPEDEF (type
);
917 return TYPE_CODE (type
) == TYPE_CODE_FLT
;
920 /* Returns non-zero if the value is a pointer type */
925 return TYPE_CODE (type
) == TYPE_CODE_PTR
||
926 TYPE_CODE (type
) == TYPE_CODE_REF
;
929 /* Returns non-zero if the value is a structured type */
931 structured_type (type
)
934 CHECK_TYPEDEF (type
);
935 switch (current_language
->la_language
)
939 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
940 (TYPE_CODE (type
) == TYPE_CODE_UNION
) ||
941 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
942 case language_pascal
:
943 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
944 (TYPE_CODE(type
) == TYPE_CODE_UNION
) ||
945 (TYPE_CODE(type
) == TYPE_CODE_SET
) ||
946 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
948 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
949 (TYPE_CODE (type
) == TYPE_CODE_SET
) ||
950 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
952 error ("Missing Chill support in function structured_type."); /*FIXME */
964 switch (current_language
->la_language
)
967 return builtin_type_chill_bool
;
968 case language_fortran
:
969 sym
= lookup_symbol ("logical", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
972 type
= SYMBOL_TYPE (sym
);
973 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
976 return builtin_type_f_logical_s2
;
978 case language_pascal
:
979 if (current_language
->la_language
==language_cplus
)
980 {sym
= lookup_symbol ("bool", NULL
, VAR_NAMESPACE
, NULL
, NULL
);}
982 {sym
= lookup_symbol ("boolean", NULL
, VAR_NAMESPACE
, NULL
, NULL
);}
985 type
= SYMBOL_TYPE (sym
);
986 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
989 return builtin_type_bool
;
991 sym
= lookup_symbol ("boolean", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
994 type
= SYMBOL_TYPE (sym
);
995 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
998 return java_boolean_type
;
1000 return builtin_type_int
;
1004 /* This page contains functions that return info about
1005 (struct value) values used in GDB. */
1007 /* Returns non-zero if the value VAL represents a true value. */
1012 /* It is possible that we should have some sort of error if a non-boolean
1013 value is used in this context. Possibly dependent on some kind of
1014 "boolean-checking" option like range checking. But it should probably
1015 not depend on the language except insofar as is necessary to identify
1016 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
1017 should be an error, probably). */
1018 return !value_logical_not (val
);
1021 /* Returns non-zero if the operator OP is defined on
1022 the values ARG1 and ARG2. */
1024 #if 0 /* Currently unused */
1027 binop_type_check (arg1
, arg2
, op
)
1028 value_ptr arg1
, arg2
;
1031 struct type
*t1
, *t2
;
1033 /* If we're not checking types, always return success. */
1037 t1
= VALUE_TYPE (arg1
);
1039 t2
= VALUE_TYPE (arg2
);
1047 if ((numeric_type (t1
) && pointer_type (t2
)) ||
1048 (pointer_type (t1
) && numeric_type (t2
)))
1050 warning ("combining pointer and integer.\n");
1056 if (!numeric_type (t1
) || !numeric_type (t2
))
1057 type_op_error ("Arguments to %s must be numbers.", op
);
1058 else if (!same_type (t1
, t2
))
1059 type_op_error ("Arguments to %s must be of the same type.", op
);
1062 case BINOP_LOGICAL_AND
:
1063 case BINOP_LOGICAL_OR
:
1064 if (!boolean_type (t1
) || !boolean_type (t2
))
1065 type_op_error ("Arguments to %s must be of boolean type.", op
);
1069 if ((pointer_type (t1
) && !(pointer_type (t2
) || integral_type (t2
))) ||
1070 (pointer_type (t2
) && !(pointer_type (t1
) || integral_type (t1
))))
1071 type_op_error ("A pointer can only be compared to an integer or pointer.", op
);
1072 else if ((pointer_type (t1
) && integral_type (t2
)) ||
1073 (integral_type (t1
) && pointer_type (t2
)))
1075 warning ("combining integer and pointer.\n");
1078 else if (!simple_type (t1
) || !simple_type (t2
))
1079 type_op_error ("Arguments to %s must be of simple type.", op
);
1080 else if (!same_type (t1
, t2
))
1081 type_op_error ("Arguments to %s must be of the same type.", op
);
1086 if (!integral_type (t1
) || !integral_type (t2
))
1087 type_op_error ("Arguments to %s must be of integral type.", op
);
1094 if (!ordered_type (t1
) || !ordered_type (t2
))
1095 type_op_error ("Arguments to %s must be of ordered type.", op
);
1096 else if (!same_type (t1
, t2
))
1097 type_op_error ("Arguments to %s must be of the same type.", op
);
1101 if (pointer_type (t1
) && !integral_type (t2
))
1102 type_op_error ("A pointer can only be assigned an integer.", op
);
1103 else if (pointer_type (t1
) && integral_type (t2
))
1105 warning ("combining integer and pointer.");
1108 else if (!simple_type (t1
) || !simple_type (t2
))
1109 type_op_error ("Arguments to %s must be of simple type.", op
);
1110 else if (!same_type (t1
, t2
))
1111 type_op_error ("Arguments to %s must be of the same type.", op
);
1115 /* FIXME: Needs to handle bitstrings as well. */
1116 if (!(string_type (t1
) || character_type (t1
) || integral_type (t1
))
1117 || !(string_type (t2
) || character_type (t2
) || integral_type (t2
)))
1118 type_op_error ("Arguments to %s must be strings or characters.", op
);
1121 /* Unary checks -- arg2 is null */
1123 case UNOP_LOGICAL_NOT
:
1124 if (!boolean_type (t1
))
1125 type_op_error ("Argument to %s must be of boolean type.", op
);
1130 if (!numeric_type (t1
))
1131 type_op_error ("Argument to %s must be of numeric type.", op
);
1135 if (integral_type (t1
))
1137 warning ("combining pointer and integer.\n");
1140 else if (!pointer_type (t1
))
1141 type_op_error ("Argument to %s must be a pointer.", op
);
1144 case UNOP_PREINCREMENT
:
1145 case UNOP_POSTINCREMENT
:
1146 case UNOP_PREDECREMENT
:
1147 case UNOP_POSTDECREMENT
:
1148 if (!ordered_type (t1
))
1149 type_op_error ("Argument to %s must be of an ordered type.", op
);
1153 /* Ok. The following operators have different meanings in
1154 different languages. */
1155 switch (current_language
->la_language
)
1159 case language_cplus
:
1163 if (!numeric_type (t1
) || !numeric_type (t2
))
1164 type_op_error ("Arguments to %s must be numbers.", op
);
1175 if (!float_type (t1
) || !float_type (t2
))
1176 type_op_error ("Arguments to %s must be floating point numbers.", op
);
1179 if (!integral_type (t1
) || !integral_type (t2
))
1180 type_op_error ("Arguments to %s must be of integral type.", op
);
1186 case language_pascal
:
1190 if (!float_type(t1
) && !float_type(t2
))
1191 type_op_error ("Arguments to %s must be floating point numbers.",op
);
1194 if (!integral_type(t1
) || !integral_type(t2
))
1195 type_op_error ("Arguments to %s must be of integral type.",op
);
1201 case language_chill
:
1202 error ("Missing Chill support in function binop_type_check."); /*FIXME */
1212 /* This page contains functions for the printing out of
1213 error messages that occur during type- and range-
1216 /* Prints the format string FMT with the operator as a string
1217 corresponding to the opcode OP. If FATAL is non-zero, then
1218 this is an error and error () is called. Otherwise, it is
1219 a warning and printf() is called. */
1221 op_error (fmt
, op
, fatal
)
1227 error (fmt
, op_string (op
));
1230 warning (fmt
, op_string (op
));
1234 /* These are called when a language fails a type- or range-check.
1235 The first argument should be a printf()-style format string, and
1236 the rest of the arguments should be its arguments. If
1237 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1238 is called in the style of error (). Otherwise, the message is prefixed
1239 by the value of warning_pre_print and we do not return to the top level. */
1242 type_error (char *string
,...)
1245 va_start (args
, string
);
1247 if (type_check
== type_check_warn
)
1248 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1252 vfprintf_filtered (gdb_stderr
, string
, args
);
1253 fprintf_filtered (gdb_stderr
, "\n");
1255 if (type_check
== type_check_on
)
1256 return_to_top_level (RETURN_ERROR
);
1260 range_error (char *string
,...)
1263 va_start (args
, string
);
1265 if (range_check
== range_check_warn
)
1266 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1270 vfprintf_filtered (gdb_stderr
, string
, args
);
1271 fprintf_filtered (gdb_stderr
, "\n");
1273 if (range_check
== range_check_on
)
1274 return_to_top_level (RETURN_ERROR
);
1278 /* This page contains miscellaneous functions */
1280 /* Return the language enum for a given language string. */
1288 for (i
= 0; i
< languages_size
; i
++)
1289 if (STREQ (languages
[i
]->la_name
, str
))
1290 return languages
[i
]->la_language
;
1292 return language_unknown
;
1295 /* Return the language struct for a given language enum. */
1297 const struct language_defn
*
1303 for (i
= 0; i
< languages_size
; i
++)
1305 if (languages
[i
]->la_language
== lang
)
1307 return languages
[i
];
1313 /* Return the language as a string */
1320 for (i
= 0; i
< languages_size
; i
++)
1322 if (languages
[i
]->la_language
== lang
)
1324 return languages
[i
]->la_name
;
1331 set_check (ignore
, from_tty
)
1336 "\"set check\" must be followed by the name of a check subcommand.\n");
1337 help_list (setchecklist
, "set check ", -1, gdb_stdout
);
1341 show_check (ignore
, from_tty
)
1345 cmd_show_list (showchecklist
, from_tty
, "");
1348 /* Add a language to the set of known languages. */
1352 const struct language_defn
*lang
;
1354 if (lang
->la_magic
!= LANG_MAGIC
)
1356 fprintf_unfiltered (gdb_stderr
, "Magic number of %s language struct wrong\n",
1363 languages_allocsize
= DEFAULT_ALLOCSIZE
;
1364 languages
= (const struct language_defn
**) xmalloc
1365 (languages_allocsize
* sizeof (*languages
));
1367 if (languages_size
>= languages_allocsize
)
1369 languages_allocsize
*= 2;
1370 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
1371 languages_allocsize
* sizeof (*languages
));
1373 languages
[languages_size
++] = lang
;
1376 /* Define the language that is no language. */
1385 unk_lang_error (msg
)
1388 error ("Attempted to parse an expression with unknown language");
1392 unk_lang_emit_char (c
, stream
, quoter
)
1394 struct ui_file
*stream
;
1397 error ("internal error - unimplemented function unk_lang_emit_char called.");
1401 unk_lang_printchar (c
, stream
)
1403 struct ui_file
*stream
;
1405 error ("internal error - unimplemented function unk_lang_printchar called.");
1409 unk_lang_printstr (stream
, string
, length
, width
, force_ellipses
)
1410 struct ui_file
*stream
;
1412 unsigned int length
;
1416 error ("internal error - unimplemented function unk_lang_printstr called.");
1419 static struct type
*
1420 unk_lang_create_fundamental_type (objfile
, typeid)
1421 struct objfile
*objfile
;
1424 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1428 unk_lang_print_type (type
, varstring
, stream
, show
, level
)
1431 struct ui_file
*stream
;
1435 error ("internal error - unimplemented function unk_lang_print_type called.");
1439 unk_lang_val_print (type
, valaddr
, embedded_offset
, address
, stream
, format
, deref_ref
,
1443 int embedded_offset
;
1445 struct ui_file
*stream
;
1449 enum val_prettyprint pretty
;
1451 error ("internal error - unimplemented function unk_lang_val_print called.");
1455 unk_lang_value_print (val
, stream
, format
, pretty
)
1457 struct ui_file
*stream
;
1459 enum val_prettyprint pretty
;
1461 error ("internal error - unimplemented function unk_lang_value_print called.");
1464 static struct type
**CONST_PTR (unknown_builtin_types
[]) =
1468 static const struct op_print unk_op_print_tab
[] =
1470 {NULL
, OP_NULL
, PREC_NULL
, 0}
1473 const struct language_defn unknown_language_defn
=
1477 &unknown_builtin_types
[0],
1482 evaluate_subexp_standard
,
1483 unk_lang_printchar
, /* Print character constant */
1486 unk_lang_create_fundamental_type
,
1487 unk_lang_print_type
, /* Print a type using appropriate syntax */
1488 unk_lang_val_print
, /* Print a value using appropriate syntax */
1489 unk_lang_value_print
, /* Print a top-level value */
1490 {"", "", "", ""}, /* Binary format info */
1491 {"0%lo", "0", "o", ""}, /* Octal format info */
1492 {"%ld", "", "d", ""}, /* Decimal format info */
1493 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1494 unk_op_print_tab
, /* expression operators for printing */
1495 1, /* c-style arrays */
1496 0, /* String lower bound */
1497 &builtin_type_char
, /* Type of string elements */
1501 /* These two structs define fake entries for the "local" and "auto" options. */
1502 const struct language_defn auto_language_defn
=
1506 &unknown_builtin_types
[0],
1511 evaluate_subexp_standard
,
1512 unk_lang_printchar
, /* Print character constant */
1515 unk_lang_create_fundamental_type
,
1516 unk_lang_print_type
, /* Print a type using appropriate syntax */
1517 unk_lang_val_print
, /* Print a value using appropriate syntax */
1518 unk_lang_value_print
, /* Print a top-level value */
1519 {"", "", "", ""}, /* Binary format info */
1520 {"0%lo", "0", "o", ""}, /* Octal format info */
1521 {"%ld", "", "d", ""}, /* Decimal format info */
1522 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1523 unk_op_print_tab
, /* expression operators for printing */
1524 1, /* c-style arrays */
1525 0, /* String lower bound */
1526 &builtin_type_char
, /* Type of string elements */
1530 const struct language_defn local_language_defn
=
1534 &unknown_builtin_types
[0],
1539 evaluate_subexp_standard
,
1540 unk_lang_printchar
, /* Print character constant */
1543 unk_lang_create_fundamental_type
,
1544 unk_lang_print_type
, /* Print a type using appropriate syntax */
1545 unk_lang_val_print
, /* Print a value using appropriate syntax */
1546 unk_lang_value_print
, /* Print a top-level value */
1547 {"", "", "", ""}, /* Binary format info */
1548 {"0%lo", "0", "o", ""}, /* Octal format info */
1549 {"%ld", "", "d", ""}, /* Decimal format info */
1550 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1551 unk_op_print_tab
, /* expression operators for printing */
1552 1, /* c-style arrays */
1553 0, /* String lower bound */
1554 &builtin_type_char
, /* Type of string elements */
1558 /* Initialize the language routines */
1561 _initialize_language ()
1563 struct cmd_list_element
*set
, *show
;
1565 /* GDB commands for language specific stuff */
1567 set
= add_set_cmd ("language", class_support
, var_string_noescape
,
1569 "Set the current source language.",
1571 show
= add_show_from_set (set
, &showlist
);
1572 set
->function
.cfunc
= set_language_command
;
1573 show
->function
.cfunc
= show_language_command
;
1575 add_prefix_cmd ("check", no_class
, set_check
,
1576 "Set the status of the type/range checker",
1577 &setchecklist
, "set check ", 0, &setlist
);
1578 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1579 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1581 add_prefix_cmd ("check", no_class
, show_check
,
1582 "Show the status of the type/range checker",
1583 &showchecklist
, "show check ", 0, &showlist
);
1584 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1585 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1587 set
= add_set_cmd ("type", class_support
, var_string_noescape
,
1589 "Set type checking. (on/warn/off/auto)",
1591 show
= add_show_from_set (set
, &showchecklist
);
1592 set
->function
.cfunc
= set_type_command
;
1593 show
->function
.cfunc
= show_type_command
;
1595 set
= add_set_cmd ("range", class_support
, var_string_noescape
,
1597 "Set range checking. (on/warn/off/auto)",
1599 show
= add_show_from_set (set
, &showchecklist
);
1600 set
->function
.cfunc
= set_range_command
;
1601 show
->function
.cfunc
= show_range_command
;
1603 add_language (&unknown_language_defn
);
1604 add_language (&local_language_defn
);
1605 add_language (&auto_language_defn
);
1607 language
= savestring ("auto", strlen ("auto"));
1608 set_language_command (language
, 0);
1610 type
= savestring ("auto", strlen ("auto"));
1611 set_type_command (NULL
, 0);
1613 range
= savestring ("auto", strlen ("auto"));
1614 set_range_command (NULL
, 0);