]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Source-language-related definitions for GDB. |
d9fcf2fb | 2 | Copyright 1991, 1992, 2000 Free Software Foundation, Inc. |
c906108c SS |
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 | ||
104c1213 | 26 | /* Forward decls for prototypes */ |
c906108c SS |
27 | struct value; |
28 | struct objfile; | |
29 | struct expression; | |
c5aa993b | 30 | /* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */ |
c906108c SS |
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 | ||
c5aa993b | 40 | #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ |
c906108c SS |
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 | ||
c5aa993b JM |
46 | extern enum range_mode |
47 | { | |
48 | range_mode_auto, range_mode_manual | |
49 | } | |
50 | range_mode; | |
c906108c SS |
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 | |
c5aa993b JM |
58 | { |
59 | range_check_off, range_check_warn, range_check_on | |
60 | } | |
61 | range_check; | |
c906108c SS |
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 | ||
c5aa993b JM |
67 | extern enum type_mode |
68 | { | |
69 | type_mode_auto, type_mode_manual | |
70 | } | |
71 | type_mode; | |
c906108c SS |
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 | |
c5aa993b JM |
79 | { |
80 | type_check_off, type_check_warn, type_check_on | |
81 | } | |
82 | type_check; | |
c906108c SS |
83 | \f |
84 | /* Information for doing language dependent formatting of printed values. */ | |
85 | ||
86 | struct language_format_info | |
c5aa993b JM |
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. */ | |
c906108c | 91 | |
c5aa993b | 92 | char *la_format; |
c906108c | 93 | |
c5aa993b JM |
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). */ | |
c906108c | 98 | |
c5aa993b | 99 | char *la_format_prefix; |
c906108c | 100 | |
c5aa993b JM |
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. */ | |
c906108c | 104 | |
c5aa993b | 105 | char *la_format_specifier; |
c906108c | 106 | |
c5aa993b JM |
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). */ | |
c906108c | 111 | |
c5aa993b JM |
112 | char *la_format_suffix; /* Suffix for custom format string */ |
113 | }; | |
c906108c SS |
114 | |
115 | /* Structure tying together assorted information about a language. */ | |
116 | ||
117 | struct language_defn | |
c5aa993b JM |
118 | { |
119 | /* Name of the language */ | |
c906108c | 120 | |
c5aa993b | 121 | char *la_name; |
c906108c | 122 | |
c5aa993b | 123 | /* its symtab language-enum (defs.h) */ |
c906108c | 124 | |
c5aa993b | 125 | enum language la_language; |
c906108c | 126 | |
c5aa993b JM |
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. */ | |
c906108c | 131 | |
c5aa993b | 132 | struct type **const *la_builtin_type_vector; |
c906108c | 133 | |
c5aa993b | 134 | /* Default range checking */ |
c906108c | 135 | |
c5aa993b | 136 | enum range_check la_range_check; |
c906108c | 137 | |
c5aa993b | 138 | /* Default type checking */ |
c906108c | 139 | |
c5aa993b | 140 | enum type_check la_type_check; |
c906108c | 141 | |
c5aa993b | 142 | /* Parser function. */ |
c906108c | 143 | |
507f3c78 | 144 | int (*la_parser) (void); |
c906108c | 145 | |
c5aa993b | 146 | /* Parser error function */ |
c906108c | 147 | |
507f3c78 | 148 | void (*la_error) (char *); |
c906108c | 149 | |
c5aa993b | 150 | /* Evaluate an expression. */ |
507f3c78 KB |
151 | struct value *(*evaluate_exp) (struct type *, struct expression *, |
152 | int *, enum noside); | |
c906108c | 153 | |
d9fcf2fb | 154 | void (*la_printchar) (int ch, struct ui_file * stream); |
c906108c | 155 | |
d9fcf2fb JM |
156 | void (*la_printstr) (struct ui_file * stream, char *string, |
157 | unsigned int length, int width, | |
158 | int force_ellipses); | |
c906108c | 159 | |
d9fcf2fb | 160 | void (*la_emitchar) (int ch, struct ui_file * stream, int quoter); |
c906108c | 161 | |
507f3c78 | 162 | struct type *(*la_fund_type) (struct objfile *, int); |
c906108c | 163 | |
c5aa993b | 164 | /* Print a type using syntax appropriate for this language. */ |
c906108c | 165 | |
d9fcf2fb JM |
166 | void (*la_print_type) (struct type *, char *, struct ui_file *, int, |
167 | int); | |
c906108c | 168 | |
c5aa993b | 169 | /* Print a value using syntax appropriate for this language. */ |
c906108c | 170 | |
d9fcf2fb JM |
171 | int (*la_val_print) (struct type *, char *, int, CORE_ADDR, |
172 | struct ui_file *, int, int, int, | |
173 | enum val_prettyprint); | |
c906108c | 174 | |
c5aa993b | 175 | /* Print a top-level value using syntax appropriate for this language. */ |
c906108c | 176 | |
d9fcf2fb JM |
177 | int (*la_value_print) (struct value *, struct ui_file *, |
178 | int, enum val_prettyprint); | |
c906108c | 179 | |
c5aa993b | 180 | /* Base 2 (binary) formats. */ |
c906108c | 181 | |
c5aa993b | 182 | struct language_format_info la_binary_format; |
c906108c | 183 | |
c5aa993b | 184 | /* Base 8 (octal) formats. */ |
c906108c | 185 | |
c5aa993b | 186 | struct language_format_info la_octal_format; |
c906108c | 187 | |
c5aa993b | 188 | /* Base 10 (decimal) formats */ |
c906108c | 189 | |
c5aa993b | 190 | struct language_format_info la_decimal_format; |
c906108c | 191 | |
c5aa993b | 192 | /* Base 16 (hexadecimal) formats */ |
c906108c | 193 | |
c5aa993b | 194 | struct language_format_info la_hex_format; |
c906108c | 195 | |
c5aa993b | 196 | /* Table for printing expressions */ |
c906108c | 197 | |
c5aa993b | 198 | const struct op_print *la_op_print_tab; |
c906108c | 199 | |
c5aa993b JM |
200 | /* Zero if the language has first-class arrays. True if there are no |
201 | array values, and array objects decay to pointers, as in C. */ | |
c906108c | 202 | |
c5aa993b | 203 | char c_style_arrays; |
c906108c | 204 | |
c5aa993b JM |
205 | /* Index to use for extracting the first element of a string. */ |
206 | char string_lower_bound; | |
c906108c | 207 | |
c5aa993b JM |
208 | /* Type of elements of strings. */ |
209 | struct type **string_char_type; | |
c906108c | 210 | |
c5aa993b JM |
211 | /* Add fields above this point, so the magic number is always last. */ |
212 | /* Magic number for compat checking */ | |
213 | ||
214 | long la_magic; | |
215 | ||
216 | }; | |
c906108c SS |
217 | |
218 | #define LANG_MAGIC 910823L | |
219 | ||
220 | /* Pointer to the language_defn for our current language. This pointer | |
221 | always points to *some* valid struct; it can be used without checking | |
222 | it for validity. | |
223 | ||
224 | The current language affects expression parsing and evaluation | |
225 | (FIXME: it might be cleaner to make the evaluation-related stuff | |
226 | separate exp_opcodes for each different set of semantics. We | |
227 | should at least think this through more clearly with respect to | |
228 | what happens if the language is changed between parsing and | |
229 | evaluation) and printing of things like types and arrays. It does | |
230 | *not* affect symbol-reading-- each source file in a symbol-file has | |
231 | its own language and we should keep track of that regardless of the | |
232 | language when symbols are read. If we want some manual setting for | |
233 | the language of symbol files (e.g. detecting when ".c" files are | |
234 | C++), it should be a seprate setting from the current_language. */ | |
235 | ||
236 | extern const struct language_defn *current_language; | |
237 | ||
238 | /* Pointer to the language_defn expected by the user, e.g. the language | |
239 | of main(), or the language we last mentioned in a message, or C. */ | |
240 | ||
241 | extern const struct language_defn *expected_language; | |
242 | ||
243 | /* language_mode == | |
244 | language_mode_auto: current_language automatically set upon selection | |
c5aa993b | 245 | of scope (e.g. stack frame) |
c906108c SS |
246 | language_mode_manual: current_language set only by user. */ |
247 | ||
248 | extern enum language_mode | |
c5aa993b JM |
249 | { |
250 | language_mode_auto, language_mode_manual | |
251 | } | |
252 | language_mode; | |
c906108c SS |
253 | \f |
254 | /* These macros define the behaviour of the expression | |
255 | evaluator. */ | |
256 | ||
257 | /* Should we strictly type check expressions? */ | |
258 | #define STRICT_TYPE (type_check != type_check_off) | |
259 | ||
260 | /* Should we range check values against the domain of their type? */ | |
261 | #define RANGE_CHECK (range_check != range_check_off) | |
262 | ||
263 | /* "cast" really means conversion */ | |
264 | /* FIXME -- should be a setting in language_defn */ | |
265 | #define CAST_IS_CONVERSION (current_language->la_language == language_c || \ | |
266 | current_language->la_language == language_cplus) | |
267 | ||
a14ed312 | 268 | extern void language_info (int); |
c906108c | 269 | |
a14ed312 | 270 | extern enum language set_language (enum language); |
c906108c | 271 | \f |
c5aa993b | 272 | |
c906108c SS |
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 | ||
a14ed312 | 354 | extern char *local_decimal_format_custom (char *); /* language.c */ |
c906108c | 355 | |
a14ed312 | 356 | extern char *local_octal_format_custom (char *); /* language.c */ |
c906108c | 357 | |
a14ed312 | 358 | extern char *local_hex_format_custom (char *); /* language.c */ |
c906108c | 359 | |
7acb79c8 AC |
360 | #if 0 |
361 | /* FIXME: cagney/2000-03-04: This function does not appear to be used. | |
362 | It can be deleted once 5.0 has been released. */ | |
c4093a6a JM |
363 | /* Return a string that contains the hex digits of the number. No preceeding |
364 | "0x" */ | |
365 | ||
a14ed312 | 366 | extern char *longest_raw_hex_string (LONGEST); |
7acb79c8 | 367 | #endif |
c4093a6a | 368 | |
c906108c SS |
369 | /* Return a string that contains a number formatted in one of the local |
370 | (language-specific) formats. Result is static and is overwritten by | |
c4093a6a | 371 | the next call. Takes printf options like "08l" or "l". */ |
c906108c | 372 | |
a14ed312 | 373 | extern char *local_hex_string (unsigned long); /* language.c */ |
c906108c | 374 | |
a14ed312 | 375 | extern char *longest_local_hex_string (LONGEST); /* language.c */ |
c4093a6a | 376 | |
a14ed312 | 377 | extern char *local_hex_string_custom (unsigned long, char *); /* language.c */ |
c906108c | 378 | |
a14ed312 | 379 | extern char *longest_local_hex_string_custom (LONGEST, char *); /* language.c */ |
c4093a6a | 380 | |
c906108c SS |
381 | /* Type predicates */ |
382 | ||
a14ed312 | 383 | extern int simple_type (struct type *); |
c906108c | 384 | |
a14ed312 | 385 | extern int ordered_type (struct type *); |
c906108c | 386 | |
a14ed312 | 387 | extern int same_type (struct type *, struct type *); |
c906108c | 388 | |
a14ed312 | 389 | extern int integral_type (struct type *); |
c906108c | 390 | |
a14ed312 | 391 | extern int numeric_type (struct type *); |
c906108c | 392 | |
a14ed312 | 393 | extern int character_type (struct type *); |
c906108c | 394 | |
a14ed312 | 395 | extern int boolean_type (struct type *); |
c906108c | 396 | |
a14ed312 | 397 | extern int float_type (struct type *); |
c906108c | 398 | |
a14ed312 | 399 | extern int pointer_type (struct type *); |
c906108c | 400 | |
a14ed312 | 401 | extern int structured_type (struct type *); |
c906108c SS |
402 | |
403 | /* Checks Binary and Unary operations for semantic type correctness */ | |
404 | /* FIXME: Does not appear to be used */ | |
405 | #define unop_type_check(v,o) binop_type_check((v),NULL,(o)) | |
406 | ||
a14ed312 | 407 | extern void binop_type_check (struct value *, struct value *, int); |
c906108c SS |
408 | |
409 | /* Error messages */ | |
410 | ||
a14ed312 | 411 | extern void op_error (char *fmt, enum exp_opcode, int); |
c906108c SS |
412 | |
413 | #define type_op_error(f,o) \ | |
414 | op_error((f),(o),type_check==type_check_on ? 1 : 0) | |
415 | #define range_op_error(f,o) \ | |
416 | op_error((f),(o),range_check==range_check_on ? 1 : 0) | |
417 | ||
a14ed312 | 418 | extern void type_error (char *, ...) ATTR_FORMAT (printf, 1, 2); |
c906108c | 419 | |
a14ed312 KB |
420 | void |
421 | range_error (char *, ...) | |
422 | ATTR_FORMAT (printf, 1, 2); | |
c906108c SS |
423 | |
424 | /* Data: Does this value represent "truth" to the current language? */ | |
425 | ||
a14ed312 | 426 | extern int value_true (struct value *); |
c906108c | 427 | |
a14ed312 | 428 | extern struct type *lang_bool_type (void); |
c906108c SS |
429 | |
430 | /* The type used for Boolean values in the current language. */ | |
431 | #define LA_BOOL_TYPE lang_bool_type () | |
432 | ||
433 | /* Misc: The string representing a particular enum language. */ | |
434 | ||
a14ed312 | 435 | extern enum language language_enum (char *str); |
c906108c | 436 | |
a14ed312 | 437 | extern const struct language_defn *language_def (enum language); |
7a292a7a | 438 | |
a14ed312 | 439 | extern char *language_str (enum language); |
c906108c SS |
440 | |
441 | /* Add a language to the set known by GDB (at initialization time). */ | |
442 | ||
a14ed312 | 443 | extern void add_language (const struct language_defn *); |
c906108c | 444 | |
a14ed312 | 445 | extern enum language get_frame_language (void); /* In stack.c */ |
c906108c | 446 | |
c5aa993b | 447 | #endif /* defined (LANGUAGE_H) */ |