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, Boston, MA 02111-1307, USA. */
22 /* This file contains functions that return things that are specific
23 to languages. Each function should examine current_language if necessary,
24 and return the appropriate result. */
26 /* FIXME: Most of these would be better organized as macros which
27 return data out of a "language-specific" struct pointer that is set
28 whenever the working language changes. That would be a lot faster. */
31 #include "gdb_string.h"
32 #ifdef ANSI_PROTOTYPES
43 #include "expression.h"
46 #include "parser-defs.h"
49 show_language_command
PARAMS ((char *, int));
52 set_language_command
PARAMS ((char *, int));
55 show_type_command
PARAMS ((char *, int));
58 set_type_command
PARAMS ((char *, int));
61 show_range_command
PARAMS ((char *, int));
64 set_range_command
PARAMS ((char *, int));
67 set_range_str
PARAMS ((void));
70 set_type_str
PARAMS ((void));
73 set_lang_str
PARAMS ((void));
76 unk_lang_error
PARAMS ((char *));
79 unk_lang_parser
PARAMS ((void));
82 show_check
PARAMS ((char *, int));
85 set_check
PARAMS ((char *, int));
88 set_type_range
PARAMS ((void));
90 /* Forward declaration */
91 extern const struct language_defn unknown_language_defn
;
92 extern char *warning_pre_print
;
94 /* The current (default at startup) state of type and range checking.
95 (If the modes are set to "auto", though, these are changed based
96 on the default language at startup, and then again based on the
97 language of the first source file. */
99 enum range_mode range_mode
= range_mode_auto
;
100 enum range_check range_check
= range_check_off
;
101 enum type_mode type_mode
= type_mode_auto
;
102 enum type_check type_check
= type_check_off
;
104 /* The current language and language_mode (see language.h) */
106 const struct language_defn
*current_language
= &unknown_language_defn
;
107 enum language_mode language_mode
= language_mode_auto
;
109 /* The language that the user expects to be typing in (the language
110 of main(), or the last language we notified them about, or C). */
112 const struct language_defn
*expected_language
;
114 /* The list of supported languages. The list itself is malloc'd. */
116 static const struct language_defn
**languages
;
117 static unsigned languages_size
;
118 static unsigned languages_allocsize
;
119 #define DEFAULT_ALLOCSIZE 4
121 /* The "set language/type/range" commands all put stuff in these
122 buffers. This is to make them work as set/show commands. The
123 user's string is copied here, then the set_* commands look at
124 them and update them to something that looks nice when it is
127 static char *language
;
131 /* Warning issued when current_language and the language of the current
132 frame do not match. */
133 char lang_frame_mismatch_warn
[] =
134 "Warning: the current language does not match this frame.";
137 /* This page contains the functions corresponding to GDB commands
138 and their helpers. */
140 /* Show command. Display a warning if the language set
141 does not match the frame. */
143 show_language_command (ignore
, from_tty
)
147 enum language flang
; /* The language of the current frame */
149 flang
= get_frame_language();
150 if (flang
!= language_unknown
&&
151 language_mode
== language_mode_manual
&&
152 current_language
->la_language
!= flang
)
153 printf_filtered("%s\n",lang_frame_mismatch_warn
);
156 /* Set command. Change the current working language. */
158 set_language_command (ignore
, from_tty
)
166 /* FIXME -- do this from the list, with HELP. */
167 if (!language
|| !language
[0]) {
168 printf_unfiltered("The currently understood settings are:\n\n");
169 printf_unfiltered ("local or auto Automatic setting based on source file\n");
170 printf_unfiltered ("c Use the C language\n");
171 printf_unfiltered ("c++ Use the C++ language\n");
172 printf_unfiltered ("chill Use the Chill language\n");
173 printf_unfiltered ("fortran Use the Fortran language\n");
174 printf_unfiltered ("modula-2 Use the Modula-2 language\n");
175 /* Restore the silly string. */
176 set_language(current_language
->la_language
);
180 /* Search the list of languages for a match. */
181 for (i
= 0; i
< languages_size
; i
++) {
182 if (STREQ (languages
[i
]->la_name
, language
)) {
183 /* Found it! Go into manual mode, and use this language. */
184 if (languages
[i
]->la_language
== language_auto
) {
185 /* Enter auto mode. Set to the current frame's language, if known. */
186 language_mode
= language_mode_auto
;
187 flang
= get_frame_language();
188 if (flang
!=language_unknown
)
190 expected_language
= current_language
;
193 /* Enter manual mode. Set the specified language. */
194 language_mode
= language_mode_manual
;
195 current_language
= languages
[i
];
198 expected_language
= current_language
;
204 /* Reset the language (esp. the global string "language") to the
206 err_lang
=savestring(language
,strlen(language
));
207 make_cleanup (free
, err_lang
); /* Free it after error */
208 set_language(current_language
->la_language
);
209 error ("Unknown language `%s'.",err_lang
);
212 /* Show command. Display a warning if the type setting does
213 not match the current language. */
215 show_type_command(ignore
, from_tty
)
219 if (type_check
!= current_language
->la_type_check
)
221 "Warning: the current type check setting does not match the language.\n");
224 /* Set command. Change the setting for type checking. */
226 set_type_command(ignore
, from_tty
)
230 if (STREQ(type
,"on"))
232 type_check
= type_check_on
;
233 type_mode
= type_mode_manual
;
235 else if (STREQ(type
,"warn"))
237 type_check
= type_check_warn
;
238 type_mode
= type_mode_manual
;
240 else if (STREQ(type
,"off"))
242 type_check
= type_check_off
;
243 type_mode
= type_mode_manual
;
245 else if (STREQ(type
,"auto"))
247 type_mode
= type_mode_auto
;
249 /* Avoid hitting the set_type_str call below. We
250 did it in set_type_range. */
254 show_type_command((char *)NULL
, from_tty
);
257 /* Show command. Display a warning if the range setting does
258 not match the current language. */
260 show_range_command(ignore
, from_tty
)
265 if (range_check
!= current_language
->la_range_check
)
267 "Warning: the current range check setting does not match the language.\n");
270 /* Set command. Change the setting for range checking. */
272 set_range_command(ignore
, from_tty
)
276 if (STREQ(range
,"on"))
278 range_check
= range_check_on
;
279 range_mode
= range_mode_manual
;
281 else if (STREQ(range
,"warn"))
283 range_check
= range_check_warn
;
284 range_mode
= range_mode_manual
;
286 else if (STREQ(range
,"off"))
288 range_check
= range_check_off
;
289 range_mode
= range_mode_manual
;
291 else if (STREQ(range
,"auto"))
293 range_mode
= range_mode_auto
;
295 /* Avoid hitting the set_range_str call below. We
296 did it in set_type_range. */
300 show_range_command((char *)0, from_tty
);
303 /* Set the status of range and type checking based on
304 the current modes and the current language.
305 If SHOW is non-zero, then print out the current language,
306 type and range checking status. */
311 if (range_mode
== range_mode_auto
)
312 range_check
= current_language
->la_range_check
;
314 if (type_mode
== type_mode_auto
)
315 type_check
= current_language
->la_type_check
;
321 /* Set current language to (enum language) LANG. */
329 for (i
= 0; i
< languages_size
; i
++) {
330 if (languages
[i
]->la_language
== lang
) {
331 current_language
= languages
[i
];
339 /* This page contains functions that update the global vars
340 language, type and range. */
347 if (language_mode
== language_mode_auto
)
348 prefix
= "auto; currently ";
350 language
= concat(prefix
, current_language
->la_name
, NULL
);
356 char *tmp
, *prefix
= "";
359 if (type_mode
==type_mode_auto
)
360 prefix
= "auto; currently ";
370 case type_check_warn
:
374 error ("Unrecognized type check setting.");
377 type
= concat(prefix
,tmp
,NULL
);
383 char *tmp
, *pref
= "";
386 if (range_mode
==range_mode_auto
)
387 pref
= "auto; currently ";
394 case range_check_off
:
397 case range_check_warn
:
401 error ("Unrecognized range check setting.");
404 range
= concat(pref
,tmp
,NULL
);
408 /* Print out the current language settings: language, range and
409 type checking. If QUIETLY, print only what has changed. */
412 language_info (quietly
)
415 if (quietly
&& expected_language
== current_language
)
418 expected_language
= current_language
;
419 printf_unfiltered("Current language: %s\n",language
);
420 show_language_command((char *)0, 1);
424 printf_unfiltered("Type checking: %s\n",type
);
425 show_type_command((char *)0, 1);
426 printf_unfiltered("Range checking: %s\n",range
);
427 show_range_command((char *)0, 1);
431 /* Return the result of a binary operation. */
433 #if 0 /* Currently unused */
436 binop_result_type (v1
, v2
)
440 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
441 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
443 int l1
= TYPE_LENGTH (t1
);
444 int l2
= TYPE_LENGTH (t2
);
446 switch(current_language
->la_language
)
450 if (TYPE_CODE (t1
)==TYPE_CODE_FLT
)
451 return TYPE_CODE(t2
) == TYPE_CODE_FLT
&& l2
> l1
?
452 VALUE_TYPE(v2
) : VALUE_TYPE(v1
);
453 else if (TYPE_CODE(t2
)==TYPE_CODE_FLT
)
454 return TYPE_CODE(t1
)) == TYPE_CODE_FLT
&& l1
> l2
?
455 VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
456 else if (TYPE_UNSIGNED(t1
) && l1
> l2
)
457 return VALUE_TYPE(v1
);
458 else if (TYPE_UNSIGNED(t2
) && l2
> l1
)
459 return VALUE_TYPE(v2
);
460 else /* Both are signed. Result is the longer type */
461 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
464 /* If we are doing type-checking, l1 should equal l2, so this is
466 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
469 error ("Missing Chill support in function binop_result_check.");/*FIXME*/
472 return (struct type
*)0; /* For lint */
478 /* This page contains functions that return format strings for
479 printf for printing out numbers in different formats */
481 /* Returns the appropriate printf format for hexadecimal
484 local_hex_format_custom(pre
)
487 static char form
[50];
489 strcpy (form
, local_hex_format_prefix ());
492 strcat (form
, local_hex_format_specifier ());
493 strcat (form
, local_hex_format_suffix ());
497 /* Converts a number to hexadecimal and stores it in a static
498 string. Returns a pointer to this string. */
500 local_hex_string (num
)
505 sprintf (res
, local_hex_format(), num
);
509 /* Converts a number to custom hexadecimal and stores it in a static
510 string. Returns a pointer to this string. */
512 local_hex_string_custom(num
,pre
)
518 sprintf (res
, local_hex_format_custom(pre
), num
);
522 /* Returns the appropriate printf format for octal
525 local_octal_format_custom(pre
)
528 static char form
[50];
530 strcpy (form
, local_octal_format_prefix ());
533 strcat (form
, local_octal_format_specifier ());
534 strcat (form
, local_octal_format_suffix ());
538 /* Returns the appropriate printf format for decimal numbers. */
540 local_decimal_format_custom(pre
)
543 static char form
[50];
545 strcpy (form
, local_decimal_format_prefix ());
548 strcat (form
, local_decimal_format_specifier ());
549 strcat (form
, local_decimal_format_suffix ());
554 /* This page contains functions that are used in type/range checking.
555 They all return zero if the type/range check fails.
557 It is hoped that these will make extending GDB to parse different
558 languages a little easier. These are primarily used in eval.c when
559 evaluating expressions and making sure that their types are correct.
560 Instead of having a mess of conjucted/disjuncted expressions in an "if",
561 the ideas of type can be wrapped up in the following functions.
563 Note that some of them are not currently dependent upon which language
564 is currently being parsed. For example, floats are the same in
565 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
566 TYPE_CODE_FLT), while booleans are different. */
568 /* Returns non-zero if its argument is a simple type. This is the same for
569 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
570 and thus will never cause the failure of the test. */
575 CHECK_TYPEDEF (type
);
576 switch (TYPE_CODE (type
)) {
581 case TYPE_CODE_RANGE
:
590 /* Returns non-zero if its argument is of an ordered type.
591 An ordered type is one in which the elements can be tested for the
592 properties of "greater than", "less than", etc, or for which the
593 operations "increment" or "decrement" make sense. */
598 CHECK_TYPEDEF (type
);
599 switch (TYPE_CODE (type
)) {
604 case TYPE_CODE_RANGE
:
612 /* Returns non-zero if the two types are the same */
614 same_type (arg1
, arg2
)
615 struct type
*arg1
, *arg2
;
617 CHECK_TYPEDEF (type
);
618 if (structured_type(arg1
) ? !structured_type(arg2
) : structured_type(arg2
))
619 /* One is structured and one isn't */
621 else if (structured_type(arg1
) && structured_type(arg2
))
623 else if (numeric_type(arg1
) && numeric_type(arg2
))
624 return (TYPE_CODE(arg2
) == TYPE_CODE(arg1
)) &&
625 (TYPE_UNSIGNED(arg1
) == TYPE_UNSIGNED(arg2
))
631 /* Returns non-zero if the type is integral */
636 CHECK_TYPEDEF (type
);
637 switch(current_language
->la_language
)
641 return (TYPE_CODE(type
) != TYPE_CODE_INT
) &&
642 (TYPE_CODE(type
) != TYPE_CODE_ENUM
) ? 0 : 1;
644 return TYPE_CODE(type
) != TYPE_CODE_INT
? 0 : 1;
646 error ("Missing Chill support in function integral_type."); /*FIXME*/
648 error ("Language not supported.");
652 /* Returns non-zero if the value is numeric */
657 CHECK_TYPEDEF (type
);
658 switch (TYPE_CODE (type
)) {
668 /* Returns non-zero if the value is a character type */
670 character_type (type
)
673 CHECK_TYPEDEF (type
);
674 switch(current_language
->la_language
)
678 return TYPE_CODE(type
) != TYPE_CODE_CHAR
? 0 : 1;
682 return (TYPE_CODE(type
) == TYPE_CODE_INT
) &&
683 TYPE_LENGTH(type
) == sizeof(char)
690 /* Returns non-zero if the value is a string type */
695 CHECK_TYPEDEF (type
);
696 switch(current_language
->la_language
)
700 return TYPE_CODE(type
) != TYPE_CODE_STRING
? 0 : 1;
704 /* C does not have distinct string type. */
711 /* Returns non-zero if the value is a boolean type */
716 CHECK_TYPEDEF (type
);
717 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
719 switch(current_language
->la_language
)
723 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
724 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
725 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
733 /* Returns non-zero if the value is a floating-point type */
738 CHECK_TYPEDEF (type
);
739 return TYPE_CODE(type
) == TYPE_CODE_FLT
;
742 /* Returns non-zero if the value is a pointer type */
747 return TYPE_CODE(type
) == TYPE_CODE_PTR
||
748 TYPE_CODE(type
) == TYPE_CODE_REF
;
751 /* Returns non-zero if the value is a structured type */
753 structured_type(type
)
756 CHECK_TYPEDEF (type
);
757 switch(current_language
->la_language
)
761 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
762 (TYPE_CODE(type
) == TYPE_CODE_UNION
) ||
763 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
765 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
766 (TYPE_CODE(type
) == TYPE_CODE_SET
) ||
767 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
769 error ("Missing Chill support in function structured_type."); /*FIXME*/
776 /* This page contains functions that return info about
777 (struct value) values used in GDB. */
779 /* Returns non-zero if the value VAL represents a true value. */
784 /* It is possible that we should have some sort of error if a non-boolean
785 value is used in this context. Possibly dependent on some kind of
786 "boolean-checking" option like range checking. But it should probably
787 not depend on the language except insofar as is necessary to identify
788 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
789 should be an error, probably). */
790 return !value_logical_not (val
);
793 /* Returns non-zero if the operator OP is defined on
794 the values ARG1 and ARG2. */
796 #if 0 /* Currently unused */
799 binop_type_check(arg1
,arg2
,op
)
803 struct type
*t1
, *t2
;
805 /* If we're not checking types, always return success. */
819 if ((numeric_type(t1
) && pointer_type(t2
)) ||
820 (pointer_type(t1
) && numeric_type(t2
)))
822 warning ("combining pointer and integer.\n");
828 if (!numeric_type(t1
) || !numeric_type(t2
))
829 type_op_error ("Arguments to %s must be numbers.",op
);
830 else if (!same_type(t1
,t2
))
831 type_op_error ("Arguments to %s must be of the same type.",op
);
834 case BINOP_LOGICAL_AND
:
835 case BINOP_LOGICAL_OR
:
836 if (!boolean_type(t1
) || !boolean_type(t2
))
837 type_op_error ("Arguments to %s must be of boolean type.",op
);
841 if ((pointer_type(t1
) && !(pointer_type(t2
) || integral_type(t2
))) ||
842 (pointer_type(t2
) && !(pointer_type(t1
) || integral_type(t1
))))
843 type_op_error ("A pointer can only be compared to an integer or pointer.",op
);
844 else if ((pointer_type(t1
) && integral_type(t2
)) ||
845 (integral_type(t1
) && pointer_type(t2
)))
847 warning ("combining integer and pointer.\n");
850 else if (!simple_type(t1
) || !simple_type(t2
))
851 type_op_error ("Arguments to %s must be of simple type.",op
);
852 else if (!same_type(t1
,t2
))
853 type_op_error ("Arguments to %s must be of the same type.",op
);
858 if (!integral_type(t1
) || !integral_type(t2
))
859 type_op_error ("Arguments to %s must be of integral type.",op
);
866 if (!ordered_type(t1
) || !ordered_type(t2
))
867 type_op_error ("Arguments to %s must be of ordered type.",op
);
868 else if (!same_type(t1
,t2
))
869 type_op_error ("Arguments to %s must be of the same type.",op
);
873 if (pointer_type(t1
) && !integral_type(t2
))
874 type_op_error ("A pointer can only be assigned an integer.",op
);
875 else if (pointer_type(t1
) && integral_type(t2
))
877 warning ("combining integer and pointer.");
880 else if (!simple_type(t1
) || !simple_type(t2
))
881 type_op_error ("Arguments to %s must be of simple type.",op
);
882 else if (!same_type(t1
,t2
))
883 type_op_error ("Arguments to %s must be of the same type.",op
);
887 /* FIXME: Needs to handle bitstrings as well. */
888 if (!(string_type(t1
) || character_type(t1
) || integral_type(t1
))
889 || !(string_type(t2
) || character_type(t2
) || integral_type(t2
)))
890 type_op_error ("Arguments to %s must be strings or characters.", op
);
893 /* Unary checks -- arg2 is null */
895 case UNOP_LOGICAL_NOT
:
896 if (!boolean_type(t1
))
897 type_op_error ("Argument to %s must be of boolean type.",op
);
902 if (!numeric_type(t1
))
903 type_op_error ("Argument to %s must be of numeric type.",op
);
907 if (integral_type(t1
))
909 warning ("combining pointer and integer.\n");
912 else if (!pointer_type(t1
))
913 type_op_error ("Argument to %s must be a pointer.",op
);
916 case UNOP_PREINCREMENT
:
917 case UNOP_POSTINCREMENT
:
918 case UNOP_PREDECREMENT
:
919 case UNOP_POSTDECREMENT
:
920 if (!ordered_type(t1
))
921 type_op_error ("Argument to %s must be of an ordered type.",op
);
925 /* Ok. The following operators have different meanings in
926 different languages. */
927 switch(current_language
->la_language
)
935 if (!numeric_type(t1
) || !numeric_type(t2
))
936 type_op_error ("Arguments to %s must be numbers.",op
);
947 if (!float_type(t1
) || !float_type(t2
))
948 type_op_error ("Arguments to %s must be floating point numbers.",op
);
951 if (!integral_type(t1
) || !integral_type(t2
))
952 type_op_error ("Arguments to %s must be of integral type.",op
);
959 error ("Missing Chill support in function binop_type_check.");/*FIXME*/
969 /* This page contains functions for the printing out of
970 error messages that occur during type- and range-
973 /* Prints the format string FMT with the operator as a string
974 corresponding to the opcode OP. If FATAL is non-zero, then
975 this is an error and error () is called. Otherwise, it is
976 a warning and printf() is called. */
978 op_error (fmt
,op
,fatal
)
984 error (fmt
,op_string(op
));
987 warning (fmt
,op_string(op
));
991 /* These are called when a language fails a type- or range-check.
992 The first argument should be a printf()-style format string, and
993 the rest of the arguments should be its arguments. If
994 [type|range]_check is [type|range]_check_on, then return_to_top_level()
995 is called in the style of error (). Otherwise, the message is prefixed
996 by the value of warning_pre_print and we do not return to the top level. */
999 #ifdef ANSI_PROTOTYPES
1000 type_error (char *string
, ...)
1002 type_error (va_alist
)
1007 #ifdef ANSI_PROTOTYPES
1008 va_start (args
, string
);
1012 string
= va_arg (args
, char *);
1015 if (type_check
== type_check_warn
)
1016 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1020 vfprintf_filtered (gdb_stderr
, string
, args
);
1021 fprintf_filtered (gdb_stderr
, "\n");
1023 if (type_check
== type_check_on
)
1024 return_to_top_level (RETURN_ERROR
);
1028 #ifdef ANSI_PROTOTYPES
1029 range_error (char *string
, ...)
1031 range_error (va_alist
)
1036 #ifdef ANSI_PROTOTYPES
1037 va_start (args
, string
);
1041 string
= va_arg (args
, char *);
1044 if (range_check
== range_check_warn
)
1045 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1049 vfprintf_filtered (gdb_stderr
, string
, args
);
1050 fprintf_filtered (gdb_stderr
, "\n");
1052 if (range_check
== range_check_on
)
1053 return_to_top_level (RETURN_ERROR
);
1057 /* This page contains miscellaneous functions */
1059 /* Return the language struct for a given language enum. */
1061 const struct language_defn
*
1067 for (i
= 0; i
< languages_size
; i
++) {
1068 if (languages
[i
]->la_language
== lang
) {
1069 return languages
[i
];
1075 /* Return the language as a string */
1082 for (i
= 0; i
< languages_size
; i
++) {
1083 if (languages
[i
]->la_language
== lang
) {
1084 return languages
[i
]->la_name
;
1091 set_check (ignore
, from_tty
)
1096 "\"set check\" must be followed by the name of a check subcommand.\n");
1097 help_list(setchecklist
, "set check ", -1, gdb_stdout
);
1101 show_check (ignore
, from_tty
)
1105 cmd_show_list(showchecklist
, from_tty
, "");
1108 /* Add a language to the set of known languages. */
1112 const struct language_defn
*lang
;
1114 if (lang
->la_magic
!= LANG_MAGIC
)
1116 fprintf_unfiltered(gdb_stderr
, "Magic number of %s language struct wrong\n",
1123 languages_allocsize
= DEFAULT_ALLOCSIZE
;
1124 languages
= (const struct language_defn
**) xmalloc
1125 (languages_allocsize
* sizeof (*languages
));
1127 if (languages_size
>= languages_allocsize
)
1129 languages_allocsize
*= 2;
1130 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
1131 languages_allocsize
* sizeof (*languages
));
1133 languages
[languages_size
++] = lang
;
1136 /* Define the language that is no language. */
1145 unk_lang_error (msg
)
1148 error ("Attempted to parse an expression with unknown language");
1152 unk_lang_printchar (c
, stream
)
1156 error ("internal error - unimplemented function unk_lang_printchar called.");
1160 unk_lang_printstr (stream
, string
, length
, force_ellipses
)
1163 unsigned int length
;
1166 error ("internal error - unimplemented function unk_lang_printstr called.");
1169 static struct type
*
1170 unk_lang_create_fundamental_type (objfile
, typeid)
1171 struct objfile
*objfile
;
1174 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1178 unk_lang_print_type (type
, varstring
, stream
, show
, level
)
1185 error ("internal error - unimplemented function unk_lang_print_type called.");
1189 unk_lang_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
,
1198 enum val_prettyprint pretty
;
1200 error ("internal error - unimplemented function unk_lang_val_print called.");
1204 unk_lang_value_print (val
, stream
, format
, pretty
)
1208 enum val_prettyprint pretty
;
1210 error ("internal error - unimplemented function unk_lang_value_print called.");
1213 static struct type
** const (unknown_builtin_types
[]) = { 0 };
1214 static const struct op_print unk_op_print_tab
[] = {
1215 {NULL
, OP_NULL
, PREC_NULL
, 0}
1218 const struct language_defn unknown_language_defn
= {
1221 &unknown_builtin_types
[0],
1226 evaluate_subexp_standard
,
1227 unk_lang_printchar
, /* Print character constant */
1229 unk_lang_create_fundamental_type
,
1230 unk_lang_print_type
, /* Print a type using appropriate syntax */
1231 unk_lang_val_print
, /* Print a value using appropriate syntax */
1232 unk_lang_value_print
, /* Print a top-level value */
1233 {"", "", "", ""}, /* Binary format info */
1234 {"0%lo", "0", "o", ""}, /* Octal format info */
1235 {"%ld", "", "d", ""}, /* Decimal format info */
1236 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1237 unk_op_print_tab
, /* expression operators for printing */
1238 1, /* c-style arrays */
1239 0, /* String lower bound */
1240 &builtin_type_char
, /* Type of string elements */
1244 /* These two structs define fake entries for the "local" and "auto" options. */
1245 const struct language_defn auto_language_defn
= {
1248 &unknown_builtin_types
[0],
1253 evaluate_subexp_standard
,
1254 unk_lang_printchar
, /* Print character constant */
1256 unk_lang_create_fundamental_type
,
1257 unk_lang_print_type
, /* Print a type using appropriate syntax */
1258 unk_lang_val_print
, /* Print a value using appropriate syntax */
1259 unk_lang_value_print
, /* Print a top-level value */
1260 {"", "", "", ""}, /* Binary format info */
1261 {"0%lo", "0", "o", ""}, /* Octal format info */
1262 {"%ld", "", "d", ""}, /* Decimal format info */
1263 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1264 unk_op_print_tab
, /* expression operators for printing */
1265 1, /* c-style arrays */
1266 0, /* String lower bound */
1267 &builtin_type_char
, /* Type of string elements */
1271 const struct language_defn local_language_defn
= {
1274 &unknown_builtin_types
[0],
1279 evaluate_subexp_standard
,
1280 unk_lang_printchar
, /* Print character constant */
1282 unk_lang_create_fundamental_type
,
1283 unk_lang_print_type
, /* Print a type using appropriate syntax */
1284 unk_lang_val_print
, /* Print a value using appropriate syntax */
1285 unk_lang_value_print
, /* Print a top-level value */
1286 {"", "", "", ""}, /* Binary format info */
1287 {"0%lo", "0", "o", ""}, /* Octal format info */
1288 {"%ld", "", "d", ""}, /* Decimal format info */
1289 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1290 unk_op_print_tab
, /* expression operators for printing */
1291 1, /* c-style arrays */
1292 0, /* String lower bound */
1293 &builtin_type_char
, /* Type of string elements */
1297 /* Initialize the language routines */
1300 _initialize_language()
1302 struct cmd_list_element
*set
, *show
;
1304 /* GDB commands for language specific stuff */
1306 set
= add_set_cmd ("language", class_support
, var_string_noescape
,
1308 "Set the current source language.",
1310 show
= add_show_from_set (set
, &showlist
);
1311 set
->function
.cfunc
= set_language_command
;
1312 show
->function
.cfunc
= show_language_command
;
1314 add_prefix_cmd ("check", no_class
, set_check
,
1315 "Set the status of the type/range checker",
1316 &setchecklist
, "set check ", 0, &setlist
);
1317 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1318 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1320 add_prefix_cmd ("check", no_class
, show_check
,
1321 "Show the status of the type/range checker",
1322 &showchecklist
, "show check ", 0, &showlist
);
1323 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1324 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1326 set
= add_set_cmd ("type", class_support
, var_string_noescape
,
1328 "Set type checking. (on/warn/off/auto)",
1330 show
= add_show_from_set (set
, &showchecklist
);
1331 set
->function
.cfunc
= set_type_command
;
1332 show
->function
.cfunc
= show_type_command
;
1334 set
= add_set_cmd ("range", class_support
, var_string_noescape
,
1336 "Set range checking. (on/warn/off/auto)",
1338 show
= add_show_from_set (set
, &showchecklist
);
1339 set
->function
.cfunc
= set_range_command
;
1340 show
->function
.cfunc
= show_range_command
;
1342 add_language (&unknown_language_defn
);
1343 add_language (&local_language_defn
);
1344 add_language (&auto_language_defn
);
1346 language
= savestring ("auto",strlen("auto"));
1347 range
= savestring ("auto",strlen("auto"));
1348 type
= savestring ("auto",strlen("auto"));
1350 /* Have the above take effect */
1352 set_language_command (language
, 0);
1353 set_type_command (NULL
, 0);
1354 set_range_command (NULL
, 0);