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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #if !defined (LANGUAGE_H)
25 #ifdef __STDC__ /* Forward decls for prototypes */
29 /* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */
32 /* This used to be included to configure GDB for one or more specific
33 languages. Now it is shortcutted to configure for all of them. FIXME. */
34 /* #include "lang_def.h" */
40 #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */
43 range_mode_auto: range_check set automatically to default of language.
44 range_mode_manual: range_check set manually by user. */
46 extern enum range_mode {range_mode_auto, range_mode_manual} range_mode;
49 range_check_on: Ranges are checked in GDB expressions, producing errors.
50 range_check_warn: Ranges are checked, producing warnings.
51 range_check_off: Ranges are not checked in GDB expressions. */
53 extern enum range_check
54 {range_check_off, range_check_warn, range_check_on} range_check;
57 type_mode_auto: type_check set automatically to default of language
58 type_mode_manual: type_check set manually by user. */
60 extern enum type_mode {type_mode_auto, type_mode_manual} type_mode;
63 type_check_on: Types are checked in GDB expressions, producing errors.
64 type_check_warn: Types are checked, producing warnings.
65 type_check_off: Types are not checked in GDB expressions. */
67 extern enum type_check
68 {type_check_off, type_check_warn, type_check_on} type_check;
70 /* Information for doing language dependent formatting of printed values. */
72 struct language_format_info
74 /* The format that can be passed directly to standard C printf functions
75 to generate a completely formatted value in the format appropriate for
80 /* The prefix to be used when directly printing a value, or constructing
81 a standard C printf format. This generally is everything up to the
82 conversion specification (the part introduced by the '%' character
83 and terminated by the conversion specifier character). */
85 char *la_format_prefix;
87 /* The conversion specifier. This is generally everything after the
88 field width and precision, typically only a single character such
89 as 'o' for octal format or 'x' for hexadecimal format. */
91 char *la_format_specifier;
93 /* The suffix to be used when directly printing a value, or constructing
94 a standard C printf format. This generally is everything after the
95 conversion specification (the part introduced by the '%' character
96 and terminated by the conversion specifier character). */
98 char *la_format_suffix; /* Suffix for custom format string */
101 /* Structure tying together assorted information about a language. */
105 /* Name of the language */
109 /* its symtab language-enum (defs.h) */
111 enum language la_language;
113 /* Its builtin types. This is a vector ended by a NULL pointer. These
114 types can be specified by name in parsing types in expressions,
115 regardless of whether the program being debugged actually defines
118 struct type ** const *la_builtin_type_vector;
120 /* Default range checking */
122 enum range_check la_range_check;
124 /* Default type checking */
126 enum type_check la_type_check;
128 /* Parser function. */
130 int (*la_parser) PARAMS((void));
132 /* Parser error function */
134 void (*la_error) PARAMS ((char *));
136 /* Evaluate an expression. */
137 struct value * (*evaluate_exp) PARAMS ((struct type *, struct expression *,
138 int *, enum noside));
140 void (*la_printchar) PARAMS ((int ch, GDB_FILE *stream));
142 void (*la_printstr) PARAMS ((GDB_FILE *stream, char *string,
143 unsigned int length, int width,
144 int force_ellipses));
146 void (*la_emitchar) PARAMS ((int ch, GDB_FILE *stream, int quoter));
148 struct type *(*la_fund_type) PARAMS ((struct objfile *, int));
150 /* Print a type using syntax appropriate for this language. */
152 void (*la_print_type) PARAMS ((struct type *, char *, GDB_FILE *, int, int));
154 /* Print a value using syntax appropriate for this language. */
156 int (*la_val_print) PARAMS ((struct type *, char *, int, CORE_ADDR, GDB_FILE *,
157 int, int, int, enum val_prettyprint));
159 /* Print a top-level value using syntax appropriate for this language. */
161 int (*la_value_print) PARAMS ((struct value *, GDB_FILE *,
162 int, enum val_prettyprint));
164 /* Base 2 (binary) formats. */
166 struct language_format_info la_binary_format;
168 /* Base 8 (octal) formats. */
170 struct language_format_info la_octal_format;
172 /* Base 10 (decimal) formats */
174 struct language_format_info la_decimal_format;
176 /* Base 16 (hexadecimal) formats */
178 struct language_format_info la_hex_format;
180 /* Table for printing expressions */
182 const struct op_print *la_op_print_tab;
184 /* Zero if the language has first-class arrays. True if there are no
185 array values, and array objects decay to pointers, as in C. */
189 /* Index to use for extracting the first element of a string. */
190 char string_lower_bound;
192 /* Type of elements of strings. */
193 struct type **string_char_type;
195 /* Add fields above this point, so the magic number is always last. */
196 /* Magic number for compat checking */
202 #define LANG_MAGIC 910823L
204 /* Pointer to the language_defn for our current language. This pointer
205 always points to *some* valid struct; it can be used without checking
208 The current language affects expression parsing and evaluation
209 (FIXME: it might be cleaner to make the evaluation-related stuff
210 separate exp_opcodes for each different set of semantics. We
211 should at least think this through more clearly with respect to
212 what happens if the language is changed between parsing and
213 evaluation) and printing of things like types and arrays. It does
214 *not* affect symbol-reading-- each source file in a symbol-file has
215 its own language and we should keep track of that regardless of the
216 language when symbols are read. If we want some manual setting for
217 the language of symbol files (e.g. detecting when ".c" files are
218 C++), it should be a seprate setting from the current_language. */
220 extern const struct language_defn *current_language;
222 /* Pointer to the language_defn expected by the user, e.g. the language
223 of main(), or the language we last mentioned in a message, or C. */
225 extern const struct language_defn *expected_language;
228 language_mode_auto: current_language automatically set upon selection
229 of scope (e.g. stack frame)
230 language_mode_manual: current_language set only by user. */
232 extern enum language_mode
233 {language_mode_auto, language_mode_manual} language_mode;
235 /* These macros define the behaviour of the expression
238 /* Should we strictly type check expressions? */
239 #define STRICT_TYPE (type_check != type_check_off)
241 /* Should we range check values against the domain of their type? */
242 #define RANGE_CHECK (range_check != range_check_off)
244 /* "cast" really means conversion */
245 /* FIXME -- should be a setting in language_defn */
246 #define CAST_IS_CONVERSION (current_language->la_language == language_c || \
247 current_language->la_language == language_cplus)
250 language_info PARAMS ((int));
253 set_language PARAMS ((enum language));
256 /* This page contains functions that return things that are
257 specific to languages. Each of these functions is based on
258 the current setting of working_lang, which the user sets
259 with the "set language" command. */
261 #define create_fundamental_type(objfile,typeid) \
262 (current_language->la_fund_type(objfile, typeid))
264 #define LA_PRINT_TYPE(type,varstring,stream,show,level) \
265 (current_language->la_print_type(type,varstring,stream,show,level))
267 #define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \
268 (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \
270 #define LA_VALUE_PRINT(val,stream,fmt,pretty) \
271 (current_language->la_value_print(val,stream,fmt,pretty))
273 /* Return a format string for printf that will print a number in one of
274 the local (language-specific) formats. Result is static and is
275 overwritten by the next call. Takes printf options like "08" or "l"
276 (to produce e.g. %08x or %lx). */
278 #define local_binary_format() \
279 (current_language->la_binary_format.la_format)
280 #define local_binary_format_prefix() \
281 (current_language->la_binary_format.la_format_prefix)
282 #define local_binary_format_specifier() \
283 (current_language->la_binary_format.la_format_specifier)
284 #define local_binary_format_suffix() \
285 (current_language->la_binary_format.la_format_suffix)
287 #define local_octal_format() \
288 (current_language->la_octal_format.la_format)
289 #define local_octal_format_prefix() \
290 (current_language->la_octal_format.la_format_prefix)
291 #define local_octal_format_specifier() \
292 (current_language->la_octal_format.la_format_specifier)
293 #define local_octal_format_suffix() \
294 (current_language->la_octal_format.la_format_suffix)
296 #define local_decimal_format() \
297 (current_language->la_decimal_format.la_format)
298 #define local_decimal_format_prefix() \
299 (current_language->la_decimal_format.la_format_prefix)
300 #define local_decimal_format_specifier() \
301 (current_language->la_decimal_format.la_format_specifier)
302 #define local_decimal_format_suffix() \
303 (current_language->la_decimal_format.la_format_suffix)
305 #define local_hex_format() \
306 (current_language->la_hex_format.la_format)
307 #define local_hex_format_prefix() \
308 (current_language->la_hex_format.la_format_prefix)
309 #define local_hex_format_specifier() \
310 (current_language->la_hex_format.la_format_specifier)
311 #define local_hex_format_suffix() \
312 (current_language->la_hex_format.la_format_suffix)
314 #define LA_PRINT_CHAR(ch, stream) \
315 (current_language->la_printchar(ch, stream))
316 #define LA_PRINT_STRING(stream, string, length, width, force_ellipses) \
317 (current_language->la_printstr(stream, string, length, width, force_ellipses))
318 #define LA_EMIT_CHAR(ch, stream, quoter) \
319 (current_language->la_emitchar(ch, stream, quoter))
321 /* Test a character to decide whether it can be printed in literal form
322 or needs to be printed in another representation. For example,
323 in C the literal form of the character with octal value 141 is 'a'
324 and the "other representation" is '\141'. The "other representation"
325 is program language dependent. */
327 #define PRINT_LITERAL_FORM(c) \
329 && ((c) < 0x7F || (c) >= 0xA0) \
330 && (!sevenbit_strings || (c) < 0x80))
332 /* Return a format string for printf that will print a number in one of
333 the local (language-specific) formats. Result is static and is
334 overwritten by the next call. Takes printf options like "08" or "l"
335 (to produce e.g. %08x or %lx). */
338 local_decimal_format_custom PARAMS ((char *)); /* language.c */
341 local_octal_format_custom PARAMS ((char *)); /* language.c */
344 local_hex_format_custom PARAMS ((char *)); /* language.c */
346 /* Return a string that contains a number formatted in one of the local
347 (language-specific) formats. Result is static and is overwritten by
348 the next call. Takes printf options like "08" or "l". */
351 local_hex_string PARAMS ((unsigned long)); /* language.c */
354 local_hex_string_custom PARAMS ((unsigned long, char *)); /* language.c */
356 /* Type predicates */
359 simple_type PARAMS ((struct type *));
362 ordered_type PARAMS ((struct type *));
365 same_type PARAMS ((struct type *, struct type *));
368 integral_type PARAMS ((struct type *));
371 numeric_type PARAMS ((struct type *));
374 character_type PARAMS ((struct type *));
377 boolean_type PARAMS ((struct type *));
380 float_type PARAMS ((struct type *));
383 pointer_type PARAMS ((struct type *));
386 structured_type PARAMS ((struct type *));
388 /* Checks Binary and Unary operations for semantic type correctness */
389 /* FIXME: Does not appear to be used */
390 #define unop_type_check(v,o) binop_type_check((v),NULL,(o))
393 binop_type_check PARAMS ((struct value *, struct value *, int));
398 op_error PARAMS ((char *fmt, enum exp_opcode, int));
400 #define type_op_error(f,o) \
401 op_error((f),(o),type_check==type_check_on ? 1 : 0)
402 #define range_op_error(f,o) \
403 op_error((f),(o),range_check==range_check_on ? 1 : 0)
406 type_error PARAMS ((char *, ...))
407 ATTR_FORMAT(printf, 1, 2);
410 range_error PARAMS ((char *, ...))
411 ATTR_FORMAT(printf, 1, 2);
413 /* Data: Does this value represent "truth" to the current language? */
416 value_true PARAMS ((struct value *));
418 extern struct type * lang_bool_type PARAMS ((void));
420 /* The type used for Boolean values in the current language. */
421 #define LA_BOOL_TYPE lang_bool_type ()
423 /* Misc: The string representing a particular enum language. */
425 extern const struct language_defn *
426 language_def PARAMS ((enum language));
429 language_str PARAMS ((enum language));
431 /* Add a language to the set known by GDB (at initialization time). */
434 add_language PARAMS ((const struct language_defn *));
437 get_frame_language PARAMS ((void)); /* In stack.c */
439 #endif /* defined (LANGUAGE_H) */