]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/language.h
import gdb-1999-07-07 post reformat
[thirdparty/binutils-gdb.git] / gdb / language.h
CommitLineData
c906108c
SS
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.
5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b
JM
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. */
c906108c
SS
22
23#if !defined (LANGUAGE_H)
24#define LANGUAGE_H 1
25
c5aa993b 26#ifdef __STDC__ /* Forward decls for prototypes */
c906108c
SS
27struct value;
28struct objfile;
29struct expression;
c5aa993b 30/* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */
c906108c
SS
31#endif
32
33/* This used to be included to configure GDB for one or more specific
34 languages. Now it is shortcutted to configure for all of them. FIXME. */
35/* #include "lang_def.h" */
36#define _LANG_c
37#define _LANG_m2
38#define _LANG_chill
39#define _LANG_fortran
40
c5aa993b 41#define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */
c906108c
SS
42
43/* range_mode ==
44 range_mode_auto: range_check set automatically to default of language.
45 range_mode_manual: range_check set manually by user. */
46
c5aa993b
JM
47extern enum range_mode
48 {
49 range_mode_auto, range_mode_manual
50 }
51range_mode;
c906108c
SS
52
53/* range_check ==
54 range_check_on: Ranges are checked in GDB expressions, producing errors.
55 range_check_warn: Ranges are checked, producing warnings.
56 range_check_off: Ranges are not checked in GDB expressions. */
57
58extern enum range_check
c5aa993b
JM
59 {
60 range_check_off, range_check_warn, range_check_on
61 }
62range_check;
c906108c
SS
63
64/* type_mode ==
65 type_mode_auto: type_check set automatically to default of language
66 type_mode_manual: type_check set manually by user. */
67
c5aa993b
JM
68extern enum type_mode
69 {
70 type_mode_auto, type_mode_manual
71 }
72type_mode;
c906108c
SS
73
74/* type_check ==
75 type_check_on: Types are checked in GDB expressions, producing errors.
76 type_check_warn: Types are checked, producing warnings.
77 type_check_off: Types are not checked in GDB expressions. */
78
79extern enum type_check
c5aa993b
JM
80 {
81 type_check_off, type_check_warn, type_check_on
82 }
83type_check;
c906108c
SS
84\f
85/* Information for doing language dependent formatting of printed values. */
86
87struct language_format_info
c5aa993b
JM
88 {
89 /* The format that can be passed directly to standard C printf functions
90 to generate a completely formatted value in the format appropriate for
91 the language. */
c906108c 92
c5aa993b 93 char *la_format;
c906108c 94
c5aa993b
JM
95 /* The prefix to be used when directly printing a value, or constructing
96 a standard C printf format. This generally is everything up to the
97 conversion specification (the part introduced by the '%' character
98 and terminated by the conversion specifier character). */
c906108c 99
c5aa993b 100 char *la_format_prefix;
c906108c 101
c5aa993b
JM
102 /* The conversion specifier. This is generally everything after the
103 field width and precision, typically only a single character such
104 as 'o' for octal format or 'x' for hexadecimal format. */
c906108c 105
c5aa993b 106 char *la_format_specifier;
c906108c 107
c5aa993b
JM
108 /* The suffix to be used when directly printing a value, or constructing
109 a standard C printf format. This generally is everything after the
110 conversion specification (the part introduced by the '%' character
111 and terminated by the conversion specifier character). */
c906108c 112
c5aa993b
JM
113 char *la_format_suffix; /* Suffix for custom format string */
114 };
c906108c
SS
115
116/* Structure tying together assorted information about a language. */
117
118struct language_defn
c5aa993b
JM
119 {
120 /* Name of the language */
c906108c 121
c5aa993b 122 char *la_name;
c906108c 123
c5aa993b 124 /* its symtab language-enum (defs.h) */
c906108c 125
c5aa993b 126 enum language la_language;
c906108c 127
c5aa993b
JM
128 /* Its builtin types. This is a vector ended by a NULL pointer. These
129 types can be specified by name in parsing types in expressions,
130 regardless of whether the program being debugged actually defines
131 such a type. */
c906108c 132
c5aa993b 133 struct type **const *la_builtin_type_vector;
c906108c 134
c5aa993b 135 /* Default range checking */
c906108c 136
c5aa993b 137 enum range_check la_range_check;
c906108c 138
c5aa993b 139 /* Default type checking */
c906108c 140
c5aa993b 141 enum type_check la_type_check;
c906108c 142
c5aa993b 143 /* Parser function. */
c906108c 144
c5aa993b 145 int (*la_parser) PARAMS ((void));
c906108c 146
c5aa993b 147 /* Parser error function */
c906108c 148
c5aa993b 149 void (*la_error) PARAMS ((char *));
c906108c 150
c5aa993b
JM
151 /* Evaluate an expression. */
152 struct value *(*evaluate_exp) PARAMS ((struct type *, struct expression *,
153 int *, enum noside));
c906108c 154
c5aa993b 155 void (*la_printchar) PARAMS ((int ch, GDB_FILE * stream));
c906108c 156
c5aa993b
JM
157 void (*la_printstr) PARAMS ((GDB_FILE * stream, char *string,
158 unsigned int length, int width,
159 int force_ellipses));
c906108c 160
c5aa993b 161 void (*la_emitchar) PARAMS ((int ch, GDB_FILE * stream, int quoter));
c906108c 162
c5aa993b 163 struct type *(*la_fund_type) PARAMS ((struct objfile *, int));
c906108c 164
c5aa993b 165 /* Print a type using syntax appropriate for this language. */
c906108c 166
c5aa993b 167 void (*la_print_type) PARAMS ((struct type *, char *, GDB_FILE *, int, int));
c906108c 168
c5aa993b 169 /* Print a value using syntax appropriate for this language. */
c906108c 170
c5aa993b
JM
171 int (*la_val_print) PARAMS ((struct type *, char *, int, CORE_ADDR, GDB_FILE *,
172 int, int, int, enum val_prettyprint));
c906108c 173
c5aa993b 174 /* Print a top-level value using syntax appropriate for this language. */
c906108c 175
c5aa993b
JM
176 int (*la_value_print) PARAMS ((struct value *, GDB_FILE *,
177 int, enum val_prettyprint));
c906108c 178
c5aa993b 179 /* Base 2 (binary) formats. */
c906108c 180
c5aa993b 181 struct language_format_info la_binary_format;
c906108c 182
c5aa993b 183 /* Base 8 (octal) formats. */
c906108c 184
c5aa993b 185 struct language_format_info la_octal_format;
c906108c 186
c5aa993b 187 /* Base 10 (decimal) formats */
c906108c 188
c5aa993b 189 struct language_format_info la_decimal_format;
c906108c 190
c5aa993b 191 /* Base 16 (hexadecimal) formats */
c906108c 192
c5aa993b 193 struct language_format_info la_hex_format;
c906108c 194
c5aa993b 195 /* Table for printing expressions */
c906108c 196
c5aa993b 197 const struct op_print *la_op_print_tab;
c906108c 198
c5aa993b
JM
199 /* Zero if the language has first-class arrays. True if there are no
200 array values, and array objects decay to pointers, as in C. */
c906108c 201
c5aa993b 202 char c_style_arrays;
c906108c 203
c5aa993b
JM
204 /* Index to use for extracting the first element of a string. */
205 char string_lower_bound;
c906108c 206
c5aa993b
JM
207 /* Type of elements of strings. */
208 struct type **string_char_type;
c906108c 209
c5aa993b
JM
210 /* Add fields above this point, so the magic number is always last. */
211 /* Magic number for compat checking */
212
213 long la_magic;
214
215 };
c906108c
SS
216
217#define LANG_MAGIC 910823L
218
219/* Pointer to the language_defn for our current language. This pointer
220 always points to *some* valid struct; it can be used without checking
221 it for validity.
222
223 The current language affects expression parsing and evaluation
224 (FIXME: it might be cleaner to make the evaluation-related stuff
225 separate exp_opcodes for each different set of semantics. We
226 should at least think this through more clearly with respect to
227 what happens if the language is changed between parsing and
228 evaluation) and printing of things like types and arrays. It does
229 *not* affect symbol-reading-- each source file in a symbol-file has
230 its own language and we should keep track of that regardless of the
231 language when symbols are read. If we want some manual setting for
232 the language of symbol files (e.g. detecting when ".c" files are
233 C++), it should be a seprate setting from the current_language. */
234
235extern const struct language_defn *current_language;
236
237/* Pointer to the language_defn expected by the user, e.g. the language
238 of main(), or the language we last mentioned in a message, or C. */
239
240extern const struct language_defn *expected_language;
241
242/* language_mode ==
243 language_mode_auto: current_language automatically set upon selection
c5aa993b 244 of scope (e.g. stack frame)
c906108c
SS
245 language_mode_manual: current_language set only by user. */
246
247extern enum language_mode
c5aa993b
JM
248 {
249 language_mode_auto, language_mode_manual
250 }
251language_mode;
c906108c
SS
252\f
253/* These macros define the behaviour of the expression
254 evaluator. */
255
256/* Should we strictly type check expressions? */
257#define STRICT_TYPE (type_check != type_check_off)
258
259/* Should we range check values against the domain of their type? */
260#define RANGE_CHECK (range_check != range_check_off)
261
262/* "cast" really means conversion */
263/* FIXME -- should be a setting in language_defn */
264#define CAST_IS_CONVERSION (current_language->la_language == language_c || \
265 current_language->la_language == language_cplus)
266
267extern void
268language_info PARAMS ((int));
269
270extern enum language
271set_language PARAMS ((enum language));
c906108c 272\f
c5aa993b 273
c906108c
SS
274/* This page contains functions that return things that are
275 specific to languages. Each of these functions is based on
276 the current setting of working_lang, which the user sets
277 with the "set language" command. */
278
279#define create_fundamental_type(objfile,typeid) \
280 (current_language->la_fund_type(objfile, typeid))
281
282#define LA_PRINT_TYPE(type,varstring,stream,show,level) \
283 (current_language->la_print_type(type,varstring,stream,show,level))
284
285#define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \
286 (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \
287 recurse,pretty))
288#define LA_VALUE_PRINT(val,stream,fmt,pretty) \
289 (current_language->la_value_print(val,stream,fmt,pretty))
290
291/* Return a format string for printf that will print a number in one of
292 the local (language-specific) formats. Result is static and is
293 overwritten by the next call. Takes printf options like "08" or "l"
294 (to produce e.g. %08x or %lx). */
295
296#define local_binary_format() \
297 (current_language->la_binary_format.la_format)
298#define local_binary_format_prefix() \
299 (current_language->la_binary_format.la_format_prefix)
300#define local_binary_format_specifier() \
301 (current_language->la_binary_format.la_format_specifier)
302#define local_binary_format_suffix() \
303 (current_language->la_binary_format.la_format_suffix)
304
305#define local_octal_format() \
306 (current_language->la_octal_format.la_format)
307#define local_octal_format_prefix() \
308 (current_language->la_octal_format.la_format_prefix)
309#define local_octal_format_specifier() \
310 (current_language->la_octal_format.la_format_specifier)
311#define local_octal_format_suffix() \
312 (current_language->la_octal_format.la_format_suffix)
313
314#define local_decimal_format() \
315 (current_language->la_decimal_format.la_format)
316#define local_decimal_format_prefix() \
317 (current_language->la_decimal_format.la_format_prefix)
318#define local_decimal_format_specifier() \
319 (current_language->la_decimal_format.la_format_specifier)
320#define local_decimal_format_suffix() \
321 (current_language->la_decimal_format.la_format_suffix)
322
323#define local_hex_format() \
324 (current_language->la_hex_format.la_format)
325#define local_hex_format_prefix() \
326 (current_language->la_hex_format.la_format_prefix)
327#define local_hex_format_specifier() \
328 (current_language->la_hex_format.la_format_specifier)
329#define local_hex_format_suffix() \
330 (current_language->la_hex_format.la_format_suffix)
331
332#define LA_PRINT_CHAR(ch, stream) \
333 (current_language->la_printchar(ch, stream))
334#define LA_PRINT_STRING(stream, string, length, width, force_ellipses) \
335 (current_language->la_printstr(stream, string, length, width, force_ellipses))
336#define LA_EMIT_CHAR(ch, stream, quoter) \
337 (current_language->la_emitchar(ch, stream, quoter))
338
339/* Test a character to decide whether it can be printed in literal form
340 or needs to be printed in another representation. For example,
341 in C the literal form of the character with octal value 141 is 'a'
342 and the "other representation" is '\141'. The "other representation"
343 is program language dependent. */
344
345#define PRINT_LITERAL_FORM(c) \
346 ((c) >= 0x20 \
347 && ((c) < 0x7F || (c) >= 0xA0) \
348 && (!sevenbit_strings || (c) < 0x80))
349
350/* Return a format string for printf that will print a number in one of
351 the local (language-specific) formats. Result is static and is
352 overwritten by the next call. Takes printf options like "08" or "l"
353 (to produce e.g. %08x or %lx). */
354
355extern char *
c5aa993b 356 local_decimal_format_custom PARAMS ((char *)); /* language.c */
c906108c
SS
357
358extern char *
c5aa993b 359 local_octal_format_custom PARAMS ((char *)); /* language.c */
c906108c
SS
360
361extern char *
c5aa993b 362 local_hex_format_custom PARAMS ((char *)); /* language.c */
c906108c
SS
363
364/* Return a string that contains a number formatted in one of the local
365 (language-specific) formats. Result is static and is overwritten by
366 the next call. Takes printf options like "08" or "l". */
367
368extern char *
c5aa993b 369 local_hex_string PARAMS ((unsigned long)); /* language.c */
c906108c
SS
370
371extern char *
c5aa993b 372 local_hex_string_custom PARAMS ((unsigned long, char *)); /* language.c */
c906108c
SS
373
374/* Type predicates */
375
376extern int
377simple_type PARAMS ((struct type *));
378
379extern int
380ordered_type PARAMS ((struct type *));
381
382extern int
383same_type PARAMS ((struct type *, struct type *));
384
385extern int
386integral_type PARAMS ((struct type *));
387
388extern int
389numeric_type PARAMS ((struct type *));
390
391extern int
392character_type PARAMS ((struct type *));
393
394extern int
395boolean_type PARAMS ((struct type *));
396
397extern int
398float_type PARAMS ((struct type *));
399
400extern int
401pointer_type PARAMS ((struct type *));
402
403extern int
404structured_type PARAMS ((struct type *));
405
406/* Checks Binary and Unary operations for semantic type correctness */
407/* FIXME: Does not appear to be used */
408#define unop_type_check(v,o) binop_type_check((v),NULL,(o))
409
410extern void
411binop_type_check PARAMS ((struct value *, struct value *, int));
412
413/* Error messages */
414
415extern void
416op_error PARAMS ((char *fmt, enum exp_opcode, int));
417
418#define type_op_error(f,o) \
419 op_error((f),(o),type_check==type_check_on ? 1 : 0)
420#define range_op_error(f,o) \
421 op_error((f),(o),range_check==range_check_on ? 1 : 0)
422
423extern void
c5aa993b
JM
424 type_error
425PARAMS ((char *,...))
426ATTR_FORMAT (printf, 1, 2);
c906108c 427
c5aa993b
JM
428 void
429 range_error PARAMS ((char *,...))
430 ATTR_FORMAT (printf, 1, 2);
c906108c
SS
431
432/* Data: Does this value represent "truth" to the current language? */
433
c5aa993b
JM
434 extern int
435 value_true PARAMS ((struct value *));
c906108c 436
c5aa993b 437 extern struct type *lang_bool_type PARAMS ((void));
c906108c
SS
438
439/* The type used for Boolean values in the current language. */
440#define LA_BOOL_TYPE lang_bool_type ()
441
442/* Misc: The string representing a particular enum language. */
443
c5aa993b 444 extern enum language language_enum PARAMS ((char *str));
c906108c 445
c5aa993b 446 extern const struct language_defn *language_def PARAMS ((enum language));
7a292a7a 447
c5aa993b 448 extern char *language_str PARAMS ((enum language));
c906108c
SS
449
450/* Add a language to the set known by GDB (at initialization time). */
451
c5aa993b
JM
452 extern void
453 add_language PARAMS ((const struct language_defn *));
c906108c 454
c5aa993b
JM
455 extern enum language
456 get_frame_language PARAMS ((void)); /* In stack.c */
c906108c 457
c5aa993b 458#endif /* defined (LANGUAGE_H) */