1 /* Source-language-related definitions 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #if !defined (LANGUAGE_H)
25 #ifdef __STDC__ /* Forward decls for prototypes */
28 /* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */
31 /* This used to be included to configure GDB for one or more specific
32 languages. Now it is shortcutted to configure for all of them. FIXME. */
33 /* #include "lang_def.h" */
39 range_mode_auto: range_check set automatically to default of language.
40 range_mode_manual: range_check set manually by user. */
42 extern enum range_mode {range_mode_auto, range_mode_manual} range_mode;
45 range_check_on: Ranges are checked in GDB expressions, producing errors.
46 range_check_warn: Ranges are checked, producing warnings.
47 range_check_off: Ranges are not checked in GDB expressions. */
49 extern enum range_check
50 {range_check_off, range_check_warn, range_check_on} range_check;
53 type_mode_auto: type_check set automatically to default of language
54 type_mode_manual: type_check set manually by user. */
56 extern enum type_mode {type_mode_auto, type_mode_manual} type_mode;
59 type_check_on: Types are checked in GDB expressions, producing errors.
60 type_check_warn: Types are checked, producing warnings.
61 type_check_off: Types are not checked in GDB expressions. */
63 extern enum type_check
64 {type_check_off, type_check_warn, type_check_on} type_check;
66 /* Information for doing language dependent formatting of printed values. */
68 struct language_format_info
70 /* The format that can be passed directly to standard C printf functions
71 to generate a completely formatted value in the format appropriate for
76 /* The prefix to be used when directly printing a value, or constructing
77 a standard C printf format. This generally is everything up to the
78 conversion specification (the part introduced by the '%' character
79 and terminated by the conversion specifier character). */
81 char *la_format_prefix;
83 /* The conversion specifier. This is generally everything after the
84 field width and precision, typically only a single character such
85 as 'o' for octal format or 'x' for hexadecimal format. */
87 char *la_format_specifier;
89 /* The suffix to be used when directly printing a value, or constructing
90 a standard C printf format. This generally is everything after the
91 conversion specification (the part introduced by the '%' character
92 and terminated by the conversion specifier character). */
94 char *la_format_suffix; /* Suffix for custom format string */
97 /* Structure tying together assorted information about a language. */
101 /* Name of the language */
105 /* its symtab language-enum (defs.h) */
107 enum language la_language;
109 /* Its builtin types. This is a vector ended by a NULL pointer. These
110 types can be specified by name in parsing types in expressions,
111 regardless of whether the program being debugged actually defines
114 struct type ** const *la_builtin_type_vector;
116 /* Default range checking */
118 enum range_check la_range_check;
120 /* Default type checking */
122 enum type_check la_type_check;
124 /* Parser function. */
126 int (*la_parser) PARAMS((void));
128 /* Parser error function */
130 void (*la_error) PARAMS ((char *));
132 void (*la_printchar) PARAMS ((int, GDB_FILE *));
134 void (*la_printstr) PARAMS ((GDB_FILE *, char *, unsigned int, int));
136 struct type *(*la_fund_type) PARAMS ((struct objfile *, int));
138 /* Print a type using syntax appropriate for this language. */
140 void (*la_print_type) PARAMS ((struct type *, char *, GDB_FILE *, int, int));
142 /* Print a value using syntax appropriate for this language. */
144 int (*la_val_print) PARAMS ((struct type *, char *, CORE_ADDR, GDB_FILE *,
145 int, int, int, enum val_prettyprint));
147 /* Longest floating point type */
149 struct type **la_longest_float;
151 /* Base 2 (binary) formats. */
153 struct language_format_info la_binary_format;
155 /* Base 8 (octal) formats. */
157 struct language_format_info la_octal_format;
159 /* Base 10 (decimal) formats */
161 struct language_format_info la_decimal_format;
163 /* Base 16 (hexadecimal) formats */
165 struct language_format_info la_hex_format;
168 /* Table for printing expressions */
170 const struct op_print *la_op_print_tab;
172 /* Add fields above this point, so the magic number is always last. */
173 /* Magic number for compat checking */
179 #define LANG_MAGIC 910823L
181 /* Pointer to the language_defn for our current language. This pointer
182 always points to *some* valid struct; it can be used without checking
185 The current language affects expression parsing and evaluation
186 (FIXME: it might be cleaner to make the evaluation-related stuff
187 separate exp_opcodes for each different set of semantics. We
188 should at least think this through more clearly with respect to
189 what happens if the language is changed between parsing and
190 evaluation) and printing of things like types and arrays. It does
191 *not* affect symbol-reading-- each source file in a symbol-file has
192 its own language and we should keep track of that regardless of the
193 language when symbols are read. If we want some manual setting for
194 the language of symbol files (e.g. detecting when ".c" files are
195 C++), it should be a seprate setting from the current_language. */
197 extern const struct language_defn *current_language;
199 /* Pointer to the language_defn expected by the user, e.g. the language
200 of main(), or the language we last mentioned in a message, or C. */
202 extern const struct language_defn *expected_language;
205 language_mode_auto: current_language automatically set upon selection
206 of scope (e.g. stack frame)
207 language_mode_manual: current_language set only by user. */
209 extern enum language_mode
210 {language_mode_auto, language_mode_manual} language_mode;
212 /* These macros define the behaviour of the expression
215 /* Should we strictly type check expressions? */
216 #define STRICT_TYPE (type_check != type_check_off)
218 /* Should we range check values against the domain of their type? */
219 #define RANGE_CHECK (range_check != range_check_off)
221 /* "cast" really means conversion */
222 /* FIXME -- should be a setting in language_defn */
223 #define CAST_IS_CONVERSION (current_language->la_language == language_c || \
224 current_language->la_language == language_cplus)
227 language_info PARAMS ((int));
230 set_language PARAMS ((enum language));
233 /* This page contains functions that return things that are
234 specific to languages. Each of these functions is based on
235 the current setting of working_lang, which the user sets
236 with the "set language" command. */
238 /* Returns some built-in types */
239 #define longest_float() (*current_language->la_longest_float)
241 #define create_fundamental_type(objfile,typeid) \
242 (current_language->la_fund_type(objfile, typeid))
244 #define LA_PRINT_TYPE(type,varstring,stream,show,level) \
245 (current_language->la_print_type(type,varstring,stream,show,level))
247 #define LA_VAL_PRINT(type,valaddr,addr,stream,fmt,deref,recurse,pretty) \
248 (current_language->la_val_print(type,valaddr,addr,stream,fmt,deref, \
251 /* Return a format string for printf that will print a number in one of
252 the local (language-specific) formats. Result is static and is
253 overwritten by the next call. Takes printf options like "08" or "l"
254 (to produce e.g. %08x or %lx). */
256 #define local_binary_format() \
257 (current_language->la_binary_format.la_format)
258 #define local_binary_format_prefix() \
259 (current_language->la_binary_format.la_format_prefix)
260 #define local_binary_format_specifier() \
261 (current_language->la_binary_format.la_format_specifier)
262 #define local_binary_format_suffix() \
263 (current_language->la_binary_format.la_format_suffix)
265 #define local_octal_format() \
266 (current_language->la_octal_format.la_format)
267 #define local_octal_format_prefix() \
268 (current_language->la_octal_format.la_format_prefix)
269 #define local_octal_format_specifier() \
270 (current_language->la_octal_format.la_format_specifier)
271 #define local_octal_format_suffix() \
272 (current_language->la_octal_format.la_format_suffix)
274 #define local_decimal_format() \
275 (current_language->la_decimal_format.la_format)
276 #define local_decimal_format_prefix() \
277 (current_language->la_decimal_format.la_format_prefix)
278 #define local_decimal_format_specifier() \
279 (current_language->la_decimal_format.la_format_specifier)
280 #define local_decimal_format_suffix() \
281 (current_language->la_decimal_format.la_format_suffix)
283 #define local_hex_format() \
284 (current_language->la_hex_format.la_format)
285 #define local_hex_format_prefix() \
286 (current_language->la_hex_format.la_format_prefix)
287 #define local_hex_format_specifier() \
288 (current_language->la_hex_format.la_format_specifier)
289 #define local_hex_format_suffix() \
290 (current_language->la_hex_format.la_format_suffix)
292 #define LA_PRINT_CHAR(ch, stream) \
293 (current_language->la_printchar(ch, stream))
294 #define LA_PRINT_STRING(stream, string, length, force_ellipses) \
295 (current_language->la_printstr(stream, string, length, force_ellipses))
297 /* Test a character to decide whether it can be printed in literal form
298 or needs to be printed in another representation. For example,
299 in C the literal form of the character with octal value 141 is 'a'
300 and the "other representation" is '\141'. The "other representation"
301 is program language dependent. */
303 #define PRINT_LITERAL_FORM(c) \
304 ((c)>=0x20 && ((c)<0x7F || (c)>=0xA0) && (!sevenbit_strings || (c)<0x80))
306 /* Return a format string for printf that will print a number in one of
307 the local (language-specific) formats. Result is static and is
308 overwritten by the next call. Takes printf options like "08" or "l"
309 (to produce e.g. %08x or %lx). */
312 local_decimal_format_custom PARAMS ((char *)); /* language.c */
315 local_octal_format_custom PARAMS ((char *)); /* language.c */
318 local_hex_format_custom PARAMS ((char *)); /* language.c */
320 /* Return a string that contains a number formatted in one of the local
321 (language-specific) formats. Result is static and is overwritten by
322 the next call. Takes printf options like "08" or "l". */
325 local_hex_string PARAMS ((unsigned long)); /* language.c */
328 local_hex_string_custom PARAMS ((unsigned long, char *)); /* language.c */
330 /* Type predicates */
333 simple_type PARAMS ((struct type *));
336 ordered_type PARAMS ((struct type *));
339 same_type PARAMS ((struct type *, struct type *));
342 integral_type PARAMS ((struct type *));
345 numeric_type PARAMS ((struct type *));
348 character_type PARAMS ((struct type *));
351 boolean_type PARAMS ((struct type *));
354 float_type PARAMS ((struct type *));
357 pointer_type PARAMS ((struct type *));
360 structured_type PARAMS ((struct type *));
362 /* Checks Binary and Unary operations for semantic type correctness */
363 /* FIXME: Does not appear to be used */
364 #define unop_type_check(v,o) binop_type_check((v),NULL,(o))
367 binop_type_check PARAMS ((struct value *, struct value *, int));
372 op_error PARAMS ((char *fmt, enum exp_opcode, int));
374 #define type_op_error(f,o) \
375 op_error((f),(o),type_check==type_check_on ? 1 : 0)
376 #define range_op_error(f,o) \
377 op_error((f),(o),range_check==range_check_on ? 1 : 0)
385 /* Data: Does this value represent "truth" to the current language? */
388 value_true PARAMS ((struct value *));
390 /* Misc: The string representing a particular enum language. */
392 extern const struct language_defn *
393 language_def PARAMS ((enum language));
396 language_str PARAMS ((enum language));
398 /* Add a language to the set known by GDB (at initialization time). */
401 add_language PARAMS ((const struct language_defn *));
404 get_frame_language PARAMS ((void)); /* In stack.c */
406 #endif /* defined (LANGUAGE_H) */