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