1 /* Multiple source language support for GDB.
2 Copyright 1991, 1992 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"
45 extern void _initialize_language
PARAMS ((void));
48 show_language_command
PARAMS ((char *, int));
51 set_language_command
PARAMS ((char *, int));
54 show_type_command
PARAMS ((char *, int));
57 set_type_command
PARAMS ((char *, int));
60 show_range_command
PARAMS ((char *, int));
63 set_range_command
PARAMS ((char *, int));
66 set_range_str
PARAMS ((void));
69 set_type_str
PARAMS ((void));
72 set_lang_str
PARAMS ((void));
75 unk_lang_error
PARAMS ((char *));
78 unk_lang_parser
PARAMS ((void));
81 show_check
PARAMS ((char *, int));
84 set_check
PARAMS ((char *, int));
87 set_type_range
PARAMS ((void));
90 unk_lang_emit_char
PARAMS ((int c
, GDB_FILE
* stream
, int quoter
));
93 unk_lang_printchar
PARAMS ((int c
, GDB_FILE
* stream
));
96 unk_lang_printstr
PARAMS ((GDB_FILE
* stream
, char *string
, unsigned int length
, int width
, int force_ellipses
));
99 unk_lang_create_fundamental_type
PARAMS ((struct objfile
*, int));
102 unk_lang_print_type
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int));
105 unk_lang_val_print
PARAMS ((struct type
*, char *, int, CORE_ADDR
, GDB_FILE
*,
106 int, int, int, enum val_prettyprint
));
109 unk_lang_value_print
PARAMS ((value_ptr
, GDB_FILE
*, int, enum val_prettyprint
));
111 /* Forward declaration */
112 extern const struct language_defn unknown_language_defn
;
113 extern char *warning_pre_print
;
115 /* The current (default at startup) state of type and range checking.
116 (If the modes are set to "auto", though, these are changed based
117 on the default language at startup, and then again based on the
118 language of the first source file. */
120 enum range_mode range_mode
= range_mode_auto
;
121 enum range_check range_check
= range_check_off
;
122 enum type_mode type_mode
= type_mode_auto
;
123 enum type_check type_check
= type_check_off
;
125 /* The current language and language_mode (see language.h) */
127 const struct language_defn
*current_language
= &unknown_language_defn
;
128 enum language_mode language_mode
= language_mode_auto
;
130 /* The language that the user expects to be typing in (the language
131 of main(), or the last language we notified them about, or C). */
133 const struct language_defn
*expected_language
;
135 /* The list of supported languages. The list itself is malloc'd. */
137 static const struct language_defn
**languages
;
138 static unsigned languages_size
;
139 static unsigned languages_allocsize
;
140 #define DEFAULT_ALLOCSIZE 4
142 /* The "set language/type/range" commands all put stuff in these
143 buffers. This is to make them work as set/show commands. The
144 user's string is copied here, then the set_* commands look at
145 them and update them to something that looks nice when it is
148 static char *language
;
152 /* Warning issued when current_language and the language of the current
153 frame do not match. */
154 char lang_frame_mismatch_warn
[] =
155 "Warning: the current language does not match this frame.";
158 /* This page contains the functions corresponding to GDB commands
159 and their helpers. */
161 /* Show command. Display a warning if the language set
162 does not match the frame. */
164 show_language_command (ignore
, from_tty
)
168 enum language flang
; /* The language of the current frame */
170 flang
= get_frame_language ();
171 if (flang
!= language_unknown
&&
172 language_mode
== language_mode_manual
&&
173 current_language
->la_language
!= flang
)
174 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
177 /* Set command. Change the current working language. */
179 set_language_command (ignore
, from_tty
)
187 if (!language
|| !language
[0])
189 printf_unfiltered ("The currently understood settings are:\n\n");
190 printf_unfiltered ("local or auto Automatic setting based on source file\n");
192 for (i
= 0; i
< languages_size
; ++i
)
194 /* Already dealt with these above. */
195 if (languages
[i
]->la_language
== language_unknown
196 || languages
[i
]->la_language
== language_auto
)
199 /* FIXME for now assume that the human-readable name is just
200 a capitalization of the internal name. */
201 printf_unfiltered ("%-16s Use the %c%s language\n",
202 languages
[i
]->la_name
,
203 /* Capitalize first letter of language
205 toupper (languages
[i
]->la_name
[0]),
206 languages
[i
]->la_name
+ 1);
208 /* Restore the silly string. */
209 set_language (current_language
->la_language
);
213 /* Search the list of languages for a match. */
214 for (i
= 0; i
< languages_size
; i
++)
216 if (STREQ (languages
[i
]->la_name
, language
))
218 /* Found it! Go into manual mode, and use this language. */
219 if (languages
[i
]->la_language
== language_auto
)
221 /* Enter auto mode. Set to the current frame's language, if known. */
222 language_mode
= language_mode_auto
;
223 flang
= get_frame_language ();
224 if (flang
!= language_unknown
)
225 set_language (flang
);
226 expected_language
= current_language
;
231 /* Enter manual mode. Set the specified language. */
232 language_mode
= language_mode_manual
;
233 current_language
= languages
[i
];
236 expected_language
= current_language
;
242 /* Reset the language (esp. the global string "language") to the
244 err_lang
= savestring (language
, strlen (language
));
245 make_cleanup (free
, err_lang
); /* Free it after error */
246 set_language (current_language
->la_language
);
247 error ("Unknown language `%s'.", err_lang
);
250 /* Show command. Display a warning if the type setting does
251 not match the current language. */
253 show_type_command (ignore
, from_tty
)
257 if (type_check
!= current_language
->la_type_check
)
259 "Warning: the current type check setting does not match the language.\n");
262 /* Set command. Change the setting for type checking. */
264 set_type_command (ignore
, from_tty
)
268 if (STREQ (type
, "on"))
270 type_check
= type_check_on
;
271 type_mode
= type_mode_manual
;
273 else if (STREQ (type
, "warn"))
275 type_check
= type_check_warn
;
276 type_mode
= type_mode_manual
;
278 else if (STREQ (type
, "off"))
280 type_check
= type_check_off
;
281 type_mode
= type_mode_manual
;
283 else if (STREQ (type
, "auto"))
285 type_mode
= type_mode_auto
;
287 /* Avoid hitting the set_type_str call below. We
288 did it in set_type_range. */
293 warning ("Unrecognized type check setting: \"%s\"", type
);
296 show_type_command ((char *) NULL
, from_tty
);
299 /* Show command. Display a warning if the range setting does
300 not match the current language. */
302 show_range_command (ignore
, from_tty
)
307 if (range_check
!= current_language
->la_range_check
)
309 "Warning: the current range check setting does not match the language.\n");
312 /* Set command. Change the setting for range checking. */
314 set_range_command (ignore
, from_tty
)
318 if (STREQ (range
, "on"))
320 range_check
= range_check_on
;
321 range_mode
= range_mode_manual
;
323 else if (STREQ (range
, "warn"))
325 range_check
= range_check_warn
;
326 range_mode
= range_mode_manual
;
328 else if (STREQ (range
, "off"))
330 range_check
= range_check_off
;
331 range_mode
= range_mode_manual
;
333 else if (STREQ (range
, "auto"))
335 range_mode
= range_mode_auto
;
337 /* Avoid hitting the set_range_str call below. We
338 did it in set_type_range. */
343 warning ("Unrecognized range check setting: \"%s\"", range
);
346 show_range_command ((char *) 0, from_tty
);
349 /* Set the status of range and type checking based on
350 the current modes and the current language.
351 If SHOW is non-zero, then print out the current language,
352 type and range checking status. */
357 if (range_mode
== range_mode_auto
)
358 range_check
= current_language
->la_range_check
;
360 if (type_mode
== type_mode_auto
)
361 type_check
= current_language
->la_type_check
;
367 /* Set current language to (enum language) LANG. Returns previous language. */
374 enum language prev_language
;
376 prev_language
= current_language
->la_language
;
378 for (i
= 0; i
< languages_size
; i
++)
380 if (languages
[i
]->la_language
== lang
)
382 current_language
= languages
[i
];
389 return prev_language
;
392 /* This page contains functions that update the global vars
393 language, type and range. */
400 if (language_mode
== language_mode_auto
)
401 prefix
= "auto; currently ";
403 language
= concat (prefix
, current_language
->la_name
, NULL
);
409 char *tmp
= NULL
, *prefix
= "";
412 if (type_mode
== type_mode_auto
)
413 prefix
= "auto; currently ";
423 case type_check_warn
:
427 error ("Unrecognized type check setting.");
430 type
= concat (prefix
, tmp
, NULL
);
436 char *tmp
, *pref
= "";
438 if (range_mode
== range_mode_auto
)
439 pref
= "auto; currently ";
446 case range_check_off
:
449 case range_check_warn
:
453 error ("Unrecognized range check setting.");
457 range
= concat (pref
, tmp
, NULL
);
461 /* Print out the current language settings: language, range and
462 type checking. If QUIETLY, print only what has changed. */
465 language_info (quietly
)
468 if (quietly
&& expected_language
== current_language
)
471 expected_language
= current_language
;
472 printf_unfiltered ("Current language: %s\n", language
);
473 show_language_command ((char *) 0, 1);
477 printf_unfiltered ("Type checking: %s\n", type
);
478 show_type_command ((char *) 0, 1);
479 printf_unfiltered ("Range checking: %s\n", range
);
480 show_range_command ((char *) 0, 1);
484 /* Return the result of a binary operation. */
486 #if 0 /* Currently unused */
489 binop_result_type (v1
, v2
)
493 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
494 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
496 int l1
= TYPE_LENGTH (t1
);
497 int l2
= TYPE_LENGTH (t2
);
499 switch (current_language
->la_language
)
503 if (TYPE_CODE (t1
) == TYPE_CODE_FLT
)
504 return TYPE_CODE (t2
) == TYPE_CODE_FLT
&& l2
> l1
?
505 VALUE_TYPE (v2
) : VALUE_TYPE (v1
);
506 else if (TYPE_CODE (t2
) == TYPE_CODE_FLT
)
507 return TYPE_CODE (t1
) == TYPE_CODE_FLT
&& l1
> l2
?
508 VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
509 else if (TYPE_UNSIGNED (t1
) && l1
> l2
)
510 return VALUE_TYPE (v1
);
511 else if (TYPE_UNSIGNED (t2
) && l2
> l1
)
512 return VALUE_TYPE (v2
);
513 else /* Both are signed. Result is the longer type */
514 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
517 /* If we are doing type-checking, l1 should equal l2, so this is
519 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
522 error ("Missing Chill support in function binop_result_check."); /*FIXME */
525 return (struct type
*) 0; /* For lint */
531 /* This page contains functions that return format strings for
532 printf for printing out numbers in different formats */
534 /* Returns the appropriate printf format for hexadecimal
537 local_hex_format_custom (pre
)
540 static char form
[50];
542 strcpy (form
, local_hex_format_prefix ());
545 strcat (form
, local_hex_format_specifier ());
546 strcat (form
, local_hex_format_suffix ());
550 /* Converts a number to hexadecimal (without leading "0x") and stores it in a
551 static string. Returns a pointer to this string. */
554 longest_raw_hex_string (num
)
557 static char res_longest_raw_hex_string
[50];
558 long long ll
= num
; /* MERGEBUG ?? see below */
559 res_longest_raw_hex_string
[0] = 0;
560 /* MERGEBUG ?? As a quick fix I am replacing this with sprintf
561 strcat_address_numeric (num, 0, res_longest_raw_hex_string, 50);
564 sprintf (res_longest_raw_hex_string
, "%llx", ll
);
565 return res_longest_raw_hex_string
;
568 /* Converts a number to hexadecimal and stores it in a static
569 string. Returns a pointer to this string. */
571 local_hex_string (num
)
576 sprintf (res
, local_hex_format (), num
);
580 /* Converts a LONGEST number to hexadecimal and stores it in a static
581 string. Returns a pointer to this string. */
583 longest_local_hex_string (num
)
586 return longest_local_hex_string_custom (num
, "l");
589 /* Converts a number to custom hexadecimal and stores it in a static
590 string. Returns a pointer to this string. */
592 local_hex_string_custom (num
, pre
)
598 sprintf (res
, local_hex_format_custom (pre
), num
);
602 /* Converts a LONGEST number to custom hexadecimal and stores it in a static
603 string. Returns a pointer to this string. Note that the width parameter
604 should end with "l", e.g. "08l" as with calls to local_hex_string_custom */
607 longest_local_hex_string_custom (num
, width
)
611 #define RESULT_BUF_LEN 50
612 static char res2
[RESULT_BUF_LEN
];
613 char format
[RESULT_BUF_LEN
];
614 #if !defined (PRINTF_HAS_LONG_LONG)
618 char *pad_char
; /* string with one character */
621 char temp_nbr_buf
[RESULT_BUF_LEN
];
624 #ifndef CC_HAS_LONG_LONG
625 /* If there is no long long, then LONGEST should be just long and we
626 can use local_hex_string_custom
628 return local_hex_string_custom ((unsigned long) num
, width
);
631 #if defined (PRINTF_HAS_LONG_LONG)
632 /* Just use printf. */
633 strcpy (format
, local_hex_format_prefix ()); /* 0x */
634 strcat (format
, "%");
635 strcat (format
, width
); /* e.g. "08l" */
636 strcat (format
, "l"); /* need "ll" for long long */
637 strcat (format
, local_hex_format_specifier ()); /* "x" */
638 strcat (format
, local_hex_format_suffix ()); /* "" */
639 sprintf (res2
, format
, num
);
641 #else /* !defined (PRINTF_HAS_LONG_LONG) */
642 /* Use strcat_address_numeric to print the number into a string, then
643 build the result string from local_hex_format_prefix, padding and
644 the hex representation as indicated by "width". */
647 /* With use_local == 0, we don't get the leading "0x" prefix. */
648 /* MERGEBUG ?? As a quick fix I am replacing this call to
649 strcat_address_numeric with sprintf
650 strcat_address_numeric(num, 0, temp_nbr_buf, RESULT_BUF_LEN);
655 sprintf (temp_nbr_buf
, "%llx", ll
);
661 if (*parse_ptr
== '-')
666 if (*parse_ptr
== '0')
670 pad_char
= "0"; /* If padding is on the right, it is blank */
672 field_width
= atoi (parse_ptr
);
673 num_len
= strlen (temp_nbr_buf
);
674 num_pad_chars
= field_width
- strlen (temp_nbr_buf
); /* possibly negative */
676 if (strlen (local_hex_format_prefix ()) + num_len
+ num_pad_chars
677 < RESULT_BUF_LEN
) /* paranoia */
678 internal_error ("longest_local_hex_string_custom: insufficient space to store result");
680 strcpy (res2
, local_hex_format_prefix ());
683 while (num_pad_chars
> 0)
685 strcat (res2
, pad_char
);
689 strcat (res2
, temp_nbr_buf
);
692 while (num_pad_chars
> 0)
694 strcat (res2
, pad_char
);
701 } /* longest_local_hex_string_custom */
703 /* Returns the appropriate printf format for octal
706 local_octal_format_custom (pre
)
709 static char form
[50];
711 strcpy (form
, local_octal_format_prefix ());
714 strcat (form
, local_octal_format_specifier ());
715 strcat (form
, local_octal_format_suffix ());
719 /* Returns the appropriate printf format for decimal numbers. */
721 local_decimal_format_custom (pre
)
724 static char form
[50];
726 strcpy (form
, local_decimal_format_prefix ());
729 strcat (form
, local_decimal_format_specifier ());
730 strcat (form
, local_decimal_format_suffix ());
735 /* This page contains functions that are used in type/range checking.
736 They all return zero if the type/range check fails.
738 It is hoped that these will make extending GDB to parse different
739 languages a little easier. These are primarily used in eval.c when
740 evaluating expressions and making sure that their types are correct.
741 Instead of having a mess of conjucted/disjuncted expressions in an "if",
742 the ideas of type can be wrapped up in the following functions.
744 Note that some of them are not currently dependent upon which language
745 is currently being parsed. For example, floats are the same in
746 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
747 TYPE_CODE_FLT), while booleans are different. */
749 /* Returns non-zero if its argument is a simple type. This is the same for
750 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
751 and thus will never cause the failure of the test. */
756 CHECK_TYPEDEF (type
);
757 switch (TYPE_CODE (type
))
763 case TYPE_CODE_RANGE
:
772 /* Returns non-zero if its argument is of an ordered type.
773 An ordered type is one in which the elements can be tested for the
774 properties of "greater than", "less than", etc, or for which the
775 operations "increment" or "decrement" make sense. */
780 CHECK_TYPEDEF (type
);
781 switch (TYPE_CODE (type
))
787 case TYPE_CODE_RANGE
:
795 /* Returns non-zero if the two types are the same */
797 same_type (arg1
, arg2
)
798 struct type
*arg1
, *arg2
;
800 CHECK_TYPEDEF (type
);
801 if (structured_type (arg1
) ? !structured_type (arg2
) : structured_type (arg2
))
802 /* One is structured and one isn't */
804 else if (structured_type (arg1
) && structured_type (arg2
))
806 else if (numeric_type (arg1
) && numeric_type (arg2
))
807 return (TYPE_CODE (arg2
) == TYPE_CODE (arg1
)) &&
808 (TYPE_UNSIGNED (arg1
) == TYPE_UNSIGNED (arg2
))
814 /* Returns non-zero if the type is integral */
819 CHECK_TYPEDEF (type
);
820 switch (current_language
->la_language
)
824 return (TYPE_CODE (type
) != TYPE_CODE_INT
) &&
825 (TYPE_CODE (type
) != TYPE_CODE_ENUM
) ? 0 : 1;
827 return TYPE_CODE (type
) != TYPE_CODE_INT
? 0 : 1;
829 error ("Missing Chill support in function integral_type."); /*FIXME */
831 error ("Language not supported.");
835 /* Returns non-zero if the value is numeric */
840 CHECK_TYPEDEF (type
);
841 switch (TYPE_CODE (type
))
852 /* Returns non-zero if the value is a character type */
854 character_type (type
)
857 CHECK_TYPEDEF (type
);
858 switch (current_language
->la_language
)
862 return TYPE_CODE (type
) != TYPE_CODE_CHAR
? 0 : 1;
866 return (TYPE_CODE (type
) == TYPE_CODE_INT
) &&
867 TYPE_LENGTH (type
) == sizeof (char)
874 /* Returns non-zero if the value is a string type */
879 CHECK_TYPEDEF (type
);
880 switch (current_language
->la_language
)
884 return TYPE_CODE (type
) != TYPE_CODE_STRING
? 0 : 1;
888 /* C does not have distinct string type. */
895 /* Returns non-zero if the value is a boolean type */
900 CHECK_TYPEDEF (type
);
901 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
903 switch (current_language
->la_language
)
907 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
908 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
909 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
917 /* Returns non-zero if the value is a floating-point type */
922 CHECK_TYPEDEF (type
);
923 return TYPE_CODE (type
) == TYPE_CODE_FLT
;
926 /* Returns non-zero if the value is a pointer type */
931 return TYPE_CODE (type
) == TYPE_CODE_PTR
||
932 TYPE_CODE (type
) == TYPE_CODE_REF
;
935 /* Returns non-zero if the value is a structured type */
937 structured_type (type
)
940 CHECK_TYPEDEF (type
);
941 switch (current_language
->la_language
)
945 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
946 (TYPE_CODE (type
) == TYPE_CODE_UNION
) ||
947 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
949 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
950 (TYPE_CODE (type
) == TYPE_CODE_SET
) ||
951 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
953 error ("Missing Chill support in function structured_type."); /*FIXME */
965 switch (current_language
->la_language
)
968 return builtin_type_chill_bool
;
969 case language_fortran
:
970 sym
= lookup_symbol ("logical", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
973 type
= SYMBOL_TYPE (sym
);
974 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
977 return builtin_type_f_logical_s2
;
979 sym
= lookup_symbol ("bool", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
982 type
= SYMBOL_TYPE (sym
);
983 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
986 return builtin_type_bool
;
988 return builtin_type_int
;
992 /* This page contains functions that return info about
993 (struct value) values used in GDB. */
995 /* Returns non-zero if the value VAL represents a true value. */
1000 /* It is possible that we should have some sort of error if a non-boolean
1001 value is used in this context. Possibly dependent on some kind of
1002 "boolean-checking" option like range checking. But it should probably
1003 not depend on the language except insofar as is necessary to identify
1004 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
1005 should be an error, probably). */
1006 return !value_logical_not (val
);
1009 /* Returns non-zero if the operator OP is defined on
1010 the values ARG1 and ARG2. */
1012 #if 0 /* Currently unused */
1015 binop_type_check (arg1
, arg2
, op
)
1016 value_ptr arg1
, arg2
;
1019 struct type
*t1
, *t2
;
1021 /* If we're not checking types, always return success. */
1025 t1
= VALUE_TYPE (arg1
);
1027 t2
= VALUE_TYPE (arg2
);
1035 if ((numeric_type (t1
) && pointer_type (t2
)) ||
1036 (pointer_type (t1
) && numeric_type (t2
)))
1038 warning ("combining pointer and integer.\n");
1044 if (!numeric_type (t1
) || !numeric_type (t2
))
1045 type_op_error ("Arguments to %s must be numbers.", op
);
1046 else if (!same_type (t1
, t2
))
1047 type_op_error ("Arguments to %s must be of the same type.", op
);
1050 case BINOP_LOGICAL_AND
:
1051 case BINOP_LOGICAL_OR
:
1052 if (!boolean_type (t1
) || !boolean_type (t2
))
1053 type_op_error ("Arguments to %s must be of boolean type.", op
);
1057 if ((pointer_type (t1
) && !(pointer_type (t2
) || integral_type (t2
))) ||
1058 (pointer_type (t2
) && !(pointer_type (t1
) || integral_type (t1
))))
1059 type_op_error ("A pointer can only be compared to an integer or pointer.", op
);
1060 else if ((pointer_type (t1
) && integral_type (t2
)) ||
1061 (integral_type (t1
) && pointer_type (t2
)))
1063 warning ("combining integer and pointer.\n");
1066 else if (!simple_type (t1
) || !simple_type (t2
))
1067 type_op_error ("Arguments to %s must be of simple type.", op
);
1068 else if (!same_type (t1
, t2
))
1069 type_op_error ("Arguments to %s must be of the same type.", op
);
1074 if (!integral_type (t1
) || !integral_type (t2
))
1075 type_op_error ("Arguments to %s must be of integral type.", op
);
1082 if (!ordered_type (t1
) || !ordered_type (t2
))
1083 type_op_error ("Arguments to %s must be of ordered type.", op
);
1084 else if (!same_type (t1
, t2
))
1085 type_op_error ("Arguments to %s must be of the same type.", op
);
1089 if (pointer_type (t1
) && !integral_type (t2
))
1090 type_op_error ("A pointer can only be assigned an integer.", op
);
1091 else if (pointer_type (t1
) && integral_type (t2
))
1093 warning ("combining integer and pointer.");
1096 else if (!simple_type (t1
) || !simple_type (t2
))
1097 type_op_error ("Arguments to %s must be of simple type.", op
);
1098 else if (!same_type (t1
, t2
))
1099 type_op_error ("Arguments to %s must be of the same type.", op
);
1103 /* FIXME: Needs to handle bitstrings as well. */
1104 if (!(string_type (t1
) || character_type (t1
) || integral_type (t1
))
1105 || !(string_type (t2
) || character_type (t2
) || integral_type (t2
)))
1106 type_op_error ("Arguments to %s must be strings or characters.", op
);
1109 /* Unary checks -- arg2 is null */
1111 case UNOP_LOGICAL_NOT
:
1112 if (!boolean_type (t1
))
1113 type_op_error ("Argument to %s must be of boolean type.", op
);
1118 if (!numeric_type (t1
))
1119 type_op_error ("Argument to %s must be of numeric type.", op
);
1123 if (integral_type (t1
))
1125 warning ("combining pointer and integer.\n");
1128 else if (!pointer_type (t1
))
1129 type_op_error ("Argument to %s must be a pointer.", op
);
1132 case UNOP_PREINCREMENT
:
1133 case UNOP_POSTINCREMENT
:
1134 case UNOP_PREDECREMENT
:
1135 case UNOP_POSTDECREMENT
:
1136 if (!ordered_type (t1
))
1137 type_op_error ("Argument to %s must be of an ordered type.", op
);
1141 /* Ok. The following operators have different meanings in
1142 different languages. */
1143 switch (current_language
->la_language
)
1147 case language_cplus
:
1151 if (!numeric_type (t1
) || !numeric_type (t2
))
1152 type_op_error ("Arguments to %s must be numbers.", op
);
1163 if (!float_type (t1
) || !float_type (t2
))
1164 type_op_error ("Arguments to %s must be floating point numbers.", op
);
1167 if (!integral_type (t1
) || !integral_type (t2
))
1168 type_op_error ("Arguments to %s must be of integral type.", op
);
1174 case language_chill
:
1175 error ("Missing Chill support in function binop_type_check."); /*FIXME */
1185 /* This page contains functions for the printing out of
1186 error messages that occur during type- and range-
1189 /* Prints the format string FMT with the operator as a string
1190 corresponding to the opcode OP. If FATAL is non-zero, then
1191 this is an error and error () is called. Otherwise, it is
1192 a warning and printf() is called. */
1194 op_error (fmt
, op
, fatal
)
1200 error (fmt
, op_string (op
));
1203 warning (fmt
, op_string (op
));
1207 /* These are called when a language fails a type- or range-check.
1208 The first argument should be a printf()-style format string, and
1209 the rest of the arguments should be its arguments. If
1210 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1211 is called in the style of error (). Otherwise, the message is prefixed
1212 by the value of warning_pre_print and we do not return to the top level. */
1215 type_error (char *string
,...)
1218 va_start (args
, string
);
1220 if (type_check
== type_check_warn
)
1221 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1225 vfprintf_filtered (gdb_stderr
, string
, args
);
1226 fprintf_filtered (gdb_stderr
, "\n");
1228 if (type_check
== type_check_on
)
1229 return_to_top_level (RETURN_ERROR
);
1233 range_error (char *string
,...)
1236 va_start (args
, string
);
1238 if (range_check
== range_check_warn
)
1239 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1243 vfprintf_filtered (gdb_stderr
, string
, args
);
1244 fprintf_filtered (gdb_stderr
, "\n");
1246 if (range_check
== range_check_on
)
1247 return_to_top_level (RETURN_ERROR
);
1251 /* This page contains miscellaneous functions */
1253 /* Return the language enum for a given language string. */
1261 for (i
= 0; i
< languages_size
; i
++)
1262 if (STREQ (languages
[i
]->la_name
, str
))
1263 return languages
[i
]->la_language
;
1265 return language_unknown
;
1268 /* Return the language struct for a given language enum. */
1270 const struct language_defn
*
1276 for (i
= 0; i
< languages_size
; i
++)
1278 if (languages
[i
]->la_language
== lang
)
1280 return languages
[i
];
1286 /* Return the language as a string */
1293 for (i
= 0; i
< languages_size
; i
++)
1295 if (languages
[i
]->la_language
== lang
)
1297 return languages
[i
]->la_name
;
1304 set_check (ignore
, from_tty
)
1309 "\"set check\" must be followed by the name of a check subcommand.\n");
1310 help_list (setchecklist
, "set check ", -1, gdb_stdout
);
1314 show_check (ignore
, from_tty
)
1318 cmd_show_list (showchecklist
, from_tty
, "");
1321 /* Add a language to the set of known languages. */
1325 const struct language_defn
*lang
;
1327 if (lang
->la_magic
!= LANG_MAGIC
)
1329 fprintf_unfiltered (gdb_stderr
, "Magic number of %s language struct wrong\n",
1336 languages_allocsize
= DEFAULT_ALLOCSIZE
;
1337 languages
= (const struct language_defn
**) xmalloc
1338 (languages_allocsize
* sizeof (*languages
));
1340 if (languages_size
>= languages_allocsize
)
1342 languages_allocsize
*= 2;
1343 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
1344 languages_allocsize
* sizeof (*languages
));
1346 languages
[languages_size
++] = lang
;
1349 /* Define the language that is no language. */
1358 unk_lang_error (msg
)
1361 error ("Attempted to parse an expression with unknown language");
1365 unk_lang_emit_char (c
, stream
, quoter
)
1370 error ("internal error - unimplemented function unk_lang_emit_char called.");
1374 unk_lang_printchar (c
, stream
)
1378 error ("internal error - unimplemented function unk_lang_printchar called.");
1382 unk_lang_printstr (stream
, string
, length
, width
, force_ellipses
)
1385 unsigned int length
;
1389 error ("internal error - unimplemented function unk_lang_printstr called.");
1392 static struct type
*
1393 unk_lang_create_fundamental_type (objfile
, typeid)
1394 struct objfile
*objfile
;
1397 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1401 unk_lang_print_type (type
, varstring
, stream
, show
, level
)
1408 error ("internal error - unimplemented function unk_lang_print_type called.");
1412 unk_lang_val_print (type
, valaddr
, embedded_offset
, address
, stream
, format
, deref_ref
,
1416 int embedded_offset
;
1422 enum val_prettyprint pretty
;
1424 error ("internal error - unimplemented function unk_lang_val_print called.");
1428 unk_lang_value_print (val
, stream
, format
, pretty
)
1432 enum val_prettyprint pretty
;
1434 error ("internal error - unimplemented function unk_lang_value_print called.");
1437 static struct type
**CONST_PTR (unknown_builtin_types
[]) =
1441 static const struct op_print unk_op_print_tab
[] =
1443 {NULL
, OP_NULL
, PREC_NULL
, 0}
1446 const struct language_defn unknown_language_defn
=
1450 &unknown_builtin_types
[0],
1455 evaluate_subexp_standard
,
1456 unk_lang_printchar
, /* Print character constant */
1459 unk_lang_create_fundamental_type
,
1460 unk_lang_print_type
, /* Print a type using appropriate syntax */
1461 unk_lang_val_print
, /* Print a value using appropriate syntax */
1462 unk_lang_value_print
, /* Print a top-level value */
1463 {"", "", "", ""}, /* Binary format info */
1464 {"0%lo", "0", "o", ""}, /* Octal format info */
1465 {"%ld", "", "d", ""}, /* Decimal format info */
1466 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1467 unk_op_print_tab
, /* expression operators for printing */
1468 1, /* c-style arrays */
1469 0, /* String lower bound */
1470 &builtin_type_char
, /* Type of string elements */
1474 /* These two structs define fake entries for the "local" and "auto" options. */
1475 const struct language_defn auto_language_defn
=
1479 &unknown_builtin_types
[0],
1484 evaluate_subexp_standard
,
1485 unk_lang_printchar
, /* Print character constant */
1488 unk_lang_create_fundamental_type
,
1489 unk_lang_print_type
, /* Print a type using appropriate syntax */
1490 unk_lang_val_print
, /* Print a value using appropriate syntax */
1491 unk_lang_value_print
, /* Print a top-level value */
1492 {"", "", "", ""}, /* Binary format info */
1493 {"0%lo", "0", "o", ""}, /* Octal format info */
1494 {"%ld", "", "d", ""}, /* Decimal format info */
1495 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1496 unk_op_print_tab
, /* expression operators for printing */
1497 1, /* c-style arrays */
1498 0, /* String lower bound */
1499 &builtin_type_char
, /* Type of string elements */
1503 const struct language_defn local_language_defn
=
1507 &unknown_builtin_types
[0],
1512 evaluate_subexp_standard
,
1513 unk_lang_printchar
, /* Print character constant */
1516 unk_lang_create_fundamental_type
,
1517 unk_lang_print_type
, /* Print a type using appropriate syntax */
1518 unk_lang_val_print
, /* Print a value using appropriate syntax */
1519 unk_lang_value_print
, /* Print a top-level value */
1520 {"", "", "", ""}, /* Binary format info */
1521 {"0%lo", "0", "o", ""}, /* Octal format info */
1522 {"%ld", "", "d", ""}, /* Decimal format info */
1523 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1524 unk_op_print_tab
, /* expression operators for printing */
1525 1, /* c-style arrays */
1526 0, /* String lower bound */
1527 &builtin_type_char
, /* Type of string elements */
1531 /* Initialize the language routines */
1534 _initialize_language ()
1536 struct cmd_list_element
*set
, *show
;
1538 /* GDB commands for language specific stuff */
1540 set
= add_set_cmd ("language", class_support
, var_string_noescape
,
1542 "Set the current source language.",
1544 show
= add_show_from_set (set
, &showlist
);
1545 set
->function
.cfunc
= set_language_command
;
1546 show
->function
.cfunc
= show_language_command
;
1548 add_prefix_cmd ("check", no_class
, set_check
,
1549 "Set the status of the type/range checker",
1550 &setchecklist
, "set check ", 0, &setlist
);
1551 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1552 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1554 add_prefix_cmd ("check", no_class
, show_check
,
1555 "Show the status of the type/range checker",
1556 &showchecklist
, "show check ", 0, &showlist
);
1557 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1558 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1560 set
= add_set_cmd ("type", class_support
, var_string_noescape
,
1562 "Set type checking. (on/warn/off/auto)",
1564 show
= add_show_from_set (set
, &showchecklist
);
1565 set
->function
.cfunc
= set_type_command
;
1566 show
->function
.cfunc
= show_type_command
;
1568 set
= add_set_cmd ("range", class_support
, var_string_noescape
,
1570 "Set range checking. (on/warn/off/auto)",
1572 show
= add_show_from_set (set
, &showchecklist
);
1573 set
->function
.cfunc
= set_range_command
;
1574 show
->function
.cfunc
= show_range_command
;
1576 add_language (&unknown_language_defn
);
1577 add_language (&local_language_defn
);
1578 add_language (&auto_language_defn
);
1580 language
= savestring ("auto", strlen ("auto"));
1581 set_language_command (language
, 0);
1583 type
= savestring ("auto", strlen ("auto"));
1584 set_type_command (NULL
, 0);
1586 range
= savestring ("auto", strlen ("auto"));
1587 set_range_command (NULL
, 0);