1 /* Source-language-related definitions for GDB.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by the Department of Computer Science at the State University
5 of New York at Buffalo.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 #if !defined (LANGUAGE_H)
27 /* Forward decls for prototypes */
31 /* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */
33 /* This used to be included to configure GDB for one or more specific
34 languages. Now it is left out to configure for all of them. FIXME. */
35 /* #include "lang_def.h" */
38 /* OBSOLETE #define _LANG_chill */
42 #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */
45 range_mode_auto: range_check set automatically to default of language.
46 range_mode_manual: range_check set manually by user. */
48 extern enum range_mode
50 range_mode_auto, range_mode_manual
55 range_check_on: Ranges are checked in GDB expressions, producing errors.
56 range_check_warn: Ranges are checked, producing warnings.
57 range_check_off: Ranges are not checked in GDB expressions. */
59 extern enum range_check
61 range_check_off, range_check_warn, range_check_on
66 type_mode_auto: type_check set automatically to default of language
67 type_mode_manual: type_check set manually by user. */
71 type_mode_auto, type_mode_manual
76 type_check_on: Types are checked in GDB expressions, producing errors.
77 type_check_warn: Types are checked, producing warnings.
78 type_check_off: Types are not checked in GDB expressions. */
80 extern enum type_check
82 type_check_off, type_check_warn, type_check_on
87 case_mode_auto: case_sensitivity set upon selection of scope
88 case_mode_manual: case_sensitivity set only by user. */
92 case_mode_auto, case_mode_manual
96 /* case_sensitivity ==
97 case_sensitive_on: Case sensitivity in name matching is used
98 case_sensitive_off: Case sensitivity in name matching is not used */
100 extern enum case_sensitivity
102 case_sensitive_on, case_sensitive_off
106 /* Information for doing language dependent formatting of printed values. */
108 struct language_format_info
110 /* The format that can be passed directly to standard C printf functions
111 to generate a completely formatted value in the format appropriate for
116 /* The prefix to be used when directly printing a value, or constructing
117 a standard C printf format. This generally is everything up to the
118 conversion specification (the part introduced by the '%' character
119 and terminated by the conversion specifier character). */
121 char *la_format_prefix;
123 /* The conversion specifier. This is generally everything after the
124 field width and precision, typically only a single character such
125 as 'o' for octal format or 'x' for hexadecimal format. */
127 char *la_format_specifier;
129 /* The suffix to be used when directly printing a value, or constructing
130 a standard C printf format. This generally is everything after the
131 conversion specification (the part introduced by the '%' character
132 and terminated by the conversion specifier character). */
134 char *la_format_suffix; /* Suffix for custom format string */
137 /* Structure tying together assorted information about a language. */
141 /* Name of the language */
145 /* its symtab language-enum (defs.h) */
147 enum language la_language;
149 /* Its builtin types. This is a vector ended by a NULL pointer. These
150 types can be specified by name in parsing types in expressions,
151 regardless of whether the program being debugged actually defines
154 struct type **const *la_builtin_type_vector;
156 /* Default range checking */
158 enum range_check la_range_check;
160 /* Default type checking */
162 enum type_check la_type_check;
164 /* Default case sensitivity */
165 enum case_sensitivity la_case_sensitivity;
167 /* Parser function. */
169 int (*la_parser) (void);
171 /* Parser error function */
173 void (*la_error) (char *);
175 /* Evaluate an expression. */
176 struct value *(*evaluate_exp) (struct type *, struct expression *,
179 void (*la_printchar) (int ch, struct ui_file * stream);
181 void (*la_printstr) (struct ui_file * stream, char *string,
182 unsigned int length, int width,
185 void (*la_emitchar) (int ch, struct ui_file * stream, int quoter);
187 struct type *(*la_fund_type) (struct objfile *, int);
189 /* Print a type using syntax appropriate for this language. */
191 void (*la_print_type) (struct type *, char *, struct ui_file *, int,
194 /* Print a value using syntax appropriate for this language. */
196 int (*la_val_print) (struct type *, char *, int, CORE_ADDR,
197 struct ui_file *, int, int, int,
198 enum val_prettyprint);
200 /* Print a top-level value using syntax appropriate for this language. */
202 int (*la_value_print) (struct value *, struct ui_file *,
203 int, enum val_prettyprint);
205 /* Base 2 (binary) formats. */
207 struct language_format_info la_binary_format;
209 /* Base 8 (octal) formats. */
211 struct language_format_info la_octal_format;
213 /* Base 10 (decimal) formats */
215 struct language_format_info la_decimal_format;
217 /* Base 16 (hexadecimal) formats */
219 struct language_format_info la_hex_format;
221 /* Table for printing expressions */
223 const struct op_print *la_op_print_tab;
225 /* Zero if the language has first-class arrays. True if there are no
226 array values, and array objects decay to pointers, as in C. */
230 /* Index to use for extracting the first element of a string. */
231 char string_lower_bound;
233 /* Type of elements of strings. */
234 struct type **string_char_type;
236 /* Add fields above this point, so the magic number is always last. */
237 /* Magic number for compat checking */
243 #define LANG_MAGIC 910823L
245 /* Pointer to the language_defn for our current language. This pointer
246 always points to *some* valid struct; it can be used without checking
249 The current language affects expression parsing and evaluation
250 (FIXME: it might be cleaner to make the evaluation-related stuff
251 separate exp_opcodes for each different set of semantics. We
252 should at least think this through more clearly with respect to
253 what happens if the language is changed between parsing and
254 evaluation) and printing of things like types and arrays. It does
255 *not* affect symbol-reading-- each source file in a symbol-file has
256 its own language and we should keep track of that regardless of the
257 language when symbols are read. If we want some manual setting for
258 the language of symbol files (e.g. detecting when ".c" files are
259 C++), it should be a separate setting from the current_language. */
261 extern const struct language_defn *current_language;
263 /* Pointer to the language_defn expected by the user, e.g. the language
264 of main(), or the language we last mentioned in a message, or C. */
266 extern const struct language_defn *expected_language;
269 language_mode_auto: current_language automatically set upon selection
270 of scope (e.g. stack frame)
271 language_mode_manual: current_language set only by user. */
273 extern enum language_mode
275 language_mode_auto, language_mode_manual
279 /* These macros define the behaviour of the expression
282 /* Should we strictly type check expressions? */
283 #define STRICT_TYPE (type_check != type_check_off)
285 /* Should we range check values against the domain of their type? */
286 #define RANGE_CHECK (range_check != range_check_off)
288 /* "cast" really means conversion */
289 /* FIXME -- should be a setting in language_defn */
290 #define CAST_IS_CONVERSION (current_language->la_language == language_c || \
291 current_language->la_language == language_cplus || \
292 current_language->la_language == language_objc)
294 extern void language_info (int);
296 extern enum language set_language (enum language);
299 /* This page contains functions that return things that are
300 specific to languages. Each of these functions is based on
301 the current setting of working_lang, which the user sets
302 with the "set language" command. */
304 #define create_fundamental_type(objfile,typeid) \
305 (current_language->la_fund_type(objfile, typeid))
307 #define LA_PRINT_TYPE(type,varstring,stream,show,level) \
308 (current_language->la_print_type(type,varstring,stream,show,level))
310 #define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \
311 (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \
313 #define LA_VALUE_PRINT(val,stream,fmt,pretty) \
314 (current_language->la_value_print(val,stream,fmt,pretty))
316 /* Return a format string for printf that will print a number in one of
317 the local (language-specific) formats. Result is static and is
318 overwritten by the next call. Takes printf options like "08" or "l"
319 (to produce e.g. %08x or %lx). */
321 #define local_binary_format() \
322 (current_language->la_binary_format.la_format)
323 #define local_binary_format_prefix() \
324 (current_language->la_binary_format.la_format_prefix)
325 #define local_binary_format_specifier() \
326 (current_language->la_binary_format.la_format_specifier)
327 #define local_binary_format_suffix() \
328 (current_language->la_binary_format.la_format_suffix)
330 #define local_octal_format() \
331 (current_language->la_octal_format.la_format)
332 #define local_octal_format_prefix() \
333 (current_language->la_octal_format.la_format_prefix)
334 #define local_octal_format_specifier() \
335 (current_language->la_octal_format.la_format_specifier)
336 #define local_octal_format_suffix() \
337 (current_language->la_octal_format.la_format_suffix)
339 #define local_decimal_format() \
340 (current_language->la_decimal_format.la_format)
341 #define local_decimal_format_prefix() \
342 (current_language->la_decimal_format.la_format_prefix)
343 #define local_decimal_format_specifier() \
344 (current_language->la_decimal_format.la_format_specifier)
345 #define local_decimal_format_suffix() \
346 (current_language->la_decimal_format.la_format_suffix)
348 #define local_hex_format() \
349 (current_language->la_hex_format.la_format)
350 #define local_hex_format_prefix() \
351 (current_language->la_hex_format.la_format_prefix)
352 #define local_hex_format_specifier() \
353 (current_language->la_hex_format.la_format_specifier)
354 #define local_hex_format_suffix() \
355 (current_language->la_hex_format.la_format_suffix)
357 #define LA_PRINT_CHAR(ch, stream) \
358 (current_language->la_printchar(ch, stream))
359 #define LA_PRINT_STRING(stream, string, length, width, force_ellipses) \
360 (current_language->la_printstr(stream, string, length, width, force_ellipses))
361 #define LA_EMIT_CHAR(ch, stream, quoter) \
362 (current_language->la_emitchar(ch, stream, quoter))
364 /* Test a character to decide whether it can be printed in literal form
365 or needs to be printed in another representation. For example,
366 in C the literal form of the character with octal value 141 is 'a'
367 and the "other representation" is '\141'. The "other representation"
368 is program language dependent. */
370 #define PRINT_LITERAL_FORM(c) \
372 && ((c) < 0x7F || (c) >= 0xA0) \
373 && (!sevenbit_strings || (c) < 0x80))
375 /* Return a format string for printf that will print a number in one of
376 the local (language-specific) formats. Result is static and is
377 overwritten by the next call. Takes printf options like "08" or "l"
378 (to produce e.g. %08x or %lx). */
380 extern char *local_decimal_format_custom (char *); /* language.c */
382 extern char *local_octal_format_custom (char *); /* language.c */
384 extern char *local_hex_format_custom (char *); /* language.c */
387 /* FIXME: cagney/2000-03-04: This function does not appear to be used.
388 It can be deleted once 5.0 has been released. */
389 /* Return a string that contains the hex digits of the number. No preceeding
392 extern char *longest_raw_hex_string (LONGEST);
395 /* Return a string that contains a number formatted in one of the local
396 (language-specific) formats. Result is static and is overwritten by
397 the next call. Takes printf options like "08l" or "l". */
399 extern char *local_hex_string (LONGEST); /* language.c */
401 extern char *local_hex_string_custom (LONGEST, char *); /* language.c */
403 /* Type predicates */
405 extern int simple_type (struct type *);
407 extern int ordered_type (struct type *);
409 extern int same_type (struct type *, struct type *);
411 extern int integral_type (struct type *);
413 extern int numeric_type (struct type *);
415 extern int character_type (struct type *);
417 extern int boolean_type (struct type *);
419 extern int float_type (struct type *);
421 extern int pointer_type (struct type *);
423 extern int structured_type (struct type *);
425 /* Checks Binary and Unary operations for semantic type correctness */
426 /* FIXME: Does not appear to be used */
427 #define unop_type_check(v,o) binop_type_check((v),NULL,(o))
429 extern void binop_type_check (struct value *, struct value *, int);
433 extern void op_error (char *fmt, enum exp_opcode, int);
435 #define type_op_error(f,o) \
436 op_error((f),(o),type_check==type_check_on ? 1 : 0)
437 #define range_op_error(f,o) \
438 op_error((f),(o),range_check==range_check_on ? 1 : 0)
440 extern void type_error (const char *, ...) ATTR_FORMAT (printf, 1, 2);
442 extern void range_error (const char *, ...) ATTR_FORMAT (printf, 1, 2);
444 /* Data: Does this value represent "truth" to the current language? */
446 extern int value_true (struct value *);
448 extern struct type *lang_bool_type (void);
450 /* The type used for Boolean values in the current language. */
451 #define LA_BOOL_TYPE lang_bool_type ()
453 /* Misc: The string representing a particular enum language. */
455 extern enum language language_enum (char *str);
457 extern const struct language_defn *language_def (enum language);
459 extern char *language_str (enum language);
461 /* Add a language to the set known by GDB (at initialization time). */
463 extern void add_language (const struct language_defn *);
465 extern enum language get_frame_language (void); /* In stack.c */
467 #endif /* defined (LANGUAGE_H) */