]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Source-language-related definitions for GDB. |
b6ba6518 KB |
2 | Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000 |
3 | Free Software Foundation, Inc. | |
c906108c SS |
4 | Contributed by the Department of Computer Science at the State University |
5 | of New York at Buffalo. | |
6 | ||
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
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. | |
c906108c | 13 | |
c5aa993b JM |
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. | |
c906108c | 18 | |
c5aa993b JM |
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. */ | |
c906108c SS |
23 | |
24 | #if !defined (LANGUAGE_H) | |
25 | #define LANGUAGE_H 1 | |
26 | ||
104c1213 | 27 | /* Forward decls for prototypes */ |
c906108c SS |
28 | struct value; |
29 | struct objfile; | |
30 | struct expression; | |
c5aa993b | 31 | /* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */ |
c906108c SS |
32 | |
33 | /* This used to be included to configure GDB for one or more specific | |
7e73cedf | 34 | languages. Now it is left out to configure for all of them. FIXME. */ |
c906108c SS |
35 | /* #include "lang_def.h" */ |
36 | #define _LANG_c | |
37 | #define _LANG_m2 | |
38 | #define _LANG_chill | |
750ba382 PM |
39 | #define _LANG_fortran |
40 | #define _LANG_pascal | |
c906108c | 41 | |
c5aa993b | 42 | #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ |
c906108c SS |
43 | |
44 | /* range_mode == | |
45 | range_mode_auto: range_check set automatically to default of language. | |
46 | range_mode_manual: range_check set manually by user. */ | |
47 | ||
c5aa993b JM |
48 | extern enum range_mode |
49 | { | |
50 | range_mode_auto, range_mode_manual | |
51 | } | |
52 | range_mode; | |
c906108c SS |
53 | |
54 | /* range_check == | |
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. */ | |
58 | ||
59 | extern enum range_check | |
c5aa993b JM |
60 | { |
61 | range_check_off, range_check_warn, range_check_on | |
62 | } | |
63 | range_check; | |
c906108c SS |
64 | |
65 | /* type_mode == | |
66 | type_mode_auto: type_check set automatically to default of language | |
67 | type_mode_manual: type_check set manually by user. */ | |
68 | ||
c5aa993b JM |
69 | extern enum type_mode |
70 | { | |
71 | type_mode_auto, type_mode_manual | |
72 | } | |
73 | type_mode; | |
c906108c SS |
74 | |
75 | /* type_check == | |
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. */ | |
79 | ||
80 | extern enum type_check | |
c5aa993b JM |
81 | { |
82 | type_check_off, type_check_warn, type_check_on | |
83 | } | |
84 | type_check; | |
63872f9d JG |
85 | |
86 | /* case_mode == | |
87 | case_mode_auto: case_sensitivity set upon selection of scope | |
88 | case_mode_manual: case_sensitivity set only by user. */ | |
89 | ||
90 | extern enum case_mode | |
91 | { | |
92 | case_mode_auto, case_mode_manual | |
93 | } | |
94 | case_mode; | |
95 | ||
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 */ | |
99 | ||
100 | extern enum case_sensitivity | |
101 | { | |
102 | case_sensitive_on, case_sensitive_off | |
103 | } | |
104 | case_sensitivity; | |
c906108c SS |
105 | \f |
106 | /* Information for doing language dependent formatting of printed values. */ | |
107 | ||
108 | struct language_format_info | |
c5aa993b JM |
109 | { |
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 | |
112 | the language. */ | |
c906108c | 113 | |
c5aa993b | 114 | char *la_format; |
c906108c | 115 | |
c5aa993b JM |
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). */ | |
c906108c | 120 | |
c5aa993b | 121 | char *la_format_prefix; |
c906108c | 122 | |
c5aa993b JM |
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. */ | |
c906108c | 126 | |
c5aa993b | 127 | char *la_format_specifier; |
c906108c | 128 | |
c5aa993b JM |
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). */ | |
c906108c | 133 | |
c5aa993b JM |
134 | char *la_format_suffix; /* Suffix for custom format string */ |
135 | }; | |
c906108c SS |
136 | |
137 | /* Structure tying together assorted information about a language. */ | |
138 | ||
139 | struct language_defn | |
c5aa993b JM |
140 | { |
141 | /* Name of the language */ | |
c906108c | 142 | |
c5aa993b | 143 | char *la_name; |
c906108c | 144 | |
c5aa993b | 145 | /* its symtab language-enum (defs.h) */ |
c906108c | 146 | |
c5aa993b | 147 | enum language la_language; |
c906108c | 148 | |
c5aa993b JM |
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 | |
152 | such a type. */ | |
c906108c | 153 | |
c5aa993b | 154 | struct type **const *la_builtin_type_vector; |
c906108c | 155 | |
c5aa993b | 156 | /* Default range checking */ |
c906108c | 157 | |
c5aa993b | 158 | enum range_check la_range_check; |
c906108c | 159 | |
c5aa993b | 160 | /* Default type checking */ |
c906108c | 161 | |
c5aa993b | 162 | enum type_check la_type_check; |
c906108c | 163 | |
63872f9d JG |
164 | /* Default case sensitivity */ |
165 | enum case_sensitivity la_case_sensitivity; | |
166 | ||
c5aa993b | 167 | /* Parser function. */ |
c906108c | 168 | |
507f3c78 | 169 | int (*la_parser) (void); |
c906108c | 170 | |
c5aa993b | 171 | /* Parser error function */ |
c906108c | 172 | |
507f3c78 | 173 | void (*la_error) (char *); |
c906108c | 174 | |
c5aa993b | 175 | /* Evaluate an expression. */ |
507f3c78 KB |
176 | struct value *(*evaluate_exp) (struct type *, struct expression *, |
177 | int *, enum noside); | |
c906108c | 178 | |
d9fcf2fb | 179 | void (*la_printchar) (int ch, struct ui_file * stream); |
c906108c | 180 | |
d9fcf2fb JM |
181 | void (*la_printstr) (struct ui_file * stream, char *string, |
182 | unsigned int length, int width, | |
183 | int force_ellipses); | |
c906108c | 184 | |
d9fcf2fb | 185 | void (*la_emitchar) (int ch, struct ui_file * stream, int quoter); |
c906108c | 186 | |
507f3c78 | 187 | struct type *(*la_fund_type) (struct objfile *, int); |
c906108c | 188 | |
c5aa993b | 189 | /* Print a type using syntax appropriate for this language. */ |
c906108c | 190 | |
d9fcf2fb JM |
191 | void (*la_print_type) (struct type *, char *, struct ui_file *, int, |
192 | int); | |
c906108c | 193 | |
c5aa993b | 194 | /* Print a value using syntax appropriate for this language. */ |
c906108c | 195 | |
d9fcf2fb JM |
196 | int (*la_val_print) (struct type *, char *, int, CORE_ADDR, |
197 | struct ui_file *, int, int, int, | |
198 | enum val_prettyprint); | |
c906108c | 199 | |
c5aa993b | 200 | /* Print a top-level value using syntax appropriate for this language. */ |
c906108c | 201 | |
d9fcf2fb JM |
202 | int (*la_value_print) (struct value *, struct ui_file *, |
203 | int, enum val_prettyprint); | |
c906108c | 204 | |
c5aa993b | 205 | /* Base 2 (binary) formats. */ |
c906108c | 206 | |
c5aa993b | 207 | struct language_format_info la_binary_format; |
c906108c | 208 | |
c5aa993b | 209 | /* Base 8 (octal) formats. */ |
c906108c | 210 | |
c5aa993b | 211 | struct language_format_info la_octal_format; |
c906108c | 212 | |
c5aa993b | 213 | /* Base 10 (decimal) formats */ |
c906108c | 214 | |
c5aa993b | 215 | struct language_format_info la_decimal_format; |
c906108c | 216 | |
c5aa993b | 217 | /* Base 16 (hexadecimal) formats */ |
c906108c | 218 | |
c5aa993b | 219 | struct language_format_info la_hex_format; |
c906108c | 220 | |
c5aa993b | 221 | /* Table for printing expressions */ |
c906108c | 222 | |
c5aa993b | 223 | const struct op_print *la_op_print_tab; |
c906108c | 224 | |
c5aa993b JM |
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. */ | |
c906108c | 227 | |
c5aa993b | 228 | char c_style_arrays; |
c906108c | 229 | |
c5aa993b JM |
230 | /* Index to use for extracting the first element of a string. */ |
231 | char string_lower_bound; | |
c906108c | 232 | |
c5aa993b JM |
233 | /* Type of elements of strings. */ |
234 | struct type **string_char_type; | |
c906108c | 235 | |
c5aa993b JM |
236 | /* Add fields above this point, so the magic number is always last. */ |
237 | /* Magic number for compat checking */ | |
238 | ||
239 | long la_magic; | |
240 | ||
241 | }; | |
c906108c SS |
242 | |
243 | #define LANG_MAGIC 910823L | |
244 | ||
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 | |
247 | it for validity. | |
248 | ||
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 | |
7e73cedf | 259 | C++), it should be a separate setting from the current_language. */ |
c906108c SS |
260 | |
261 | extern const struct language_defn *current_language; | |
262 | ||
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. */ | |
265 | ||
266 | extern const struct language_defn *expected_language; | |
267 | ||
268 | /* language_mode == | |
269 | language_mode_auto: current_language automatically set upon selection | |
c5aa993b | 270 | of scope (e.g. stack frame) |
c906108c SS |
271 | language_mode_manual: current_language set only by user. */ |
272 | ||
273 | extern enum language_mode | |
c5aa993b JM |
274 | { |
275 | language_mode_auto, language_mode_manual | |
276 | } | |
277 | language_mode; | |
c906108c SS |
278 | \f |
279 | /* These macros define the behaviour of the expression | |
280 | evaluator. */ | |
281 | ||
282 | /* Should we strictly type check expressions? */ | |
283 | #define STRICT_TYPE (type_check != type_check_off) | |
284 | ||
285 | /* Should we range check values against the domain of their type? */ | |
286 | #define RANGE_CHECK (range_check != range_check_off) | |
287 | ||
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 | ||
a14ed312 | 293 | extern void language_info (int); |
c906108c | 294 | |
a14ed312 | 295 | extern enum language set_language (enum language); |
c906108c | 296 | \f |
c5aa993b | 297 | |
c906108c SS |
298 | /* This page contains functions that return things that are |
299 | specific to languages. Each of these functions is based on | |
300 | the current setting of working_lang, which the user sets | |
301 | with the "set language" command. */ | |
302 | ||
303 | #define create_fundamental_type(objfile,typeid) \ | |
304 | (current_language->la_fund_type(objfile, typeid)) | |
305 | ||
306 | #define LA_PRINT_TYPE(type,varstring,stream,show,level) \ | |
307 | (current_language->la_print_type(type,varstring,stream,show,level)) | |
308 | ||
309 | #define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \ | |
310 | (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \ | |
311 | recurse,pretty)) | |
312 | #define LA_VALUE_PRINT(val,stream,fmt,pretty) \ | |
313 | (current_language->la_value_print(val,stream,fmt,pretty)) | |
314 | ||
315 | /* Return a format string for printf that will print a number in one of | |
316 | the local (language-specific) formats. Result is static and is | |
317 | overwritten by the next call. Takes printf options like "08" or "l" | |
318 | (to produce e.g. %08x or %lx). */ | |
319 | ||
320 | #define local_binary_format() \ | |
321 | (current_language->la_binary_format.la_format) | |
322 | #define local_binary_format_prefix() \ | |
323 | (current_language->la_binary_format.la_format_prefix) | |
324 | #define local_binary_format_specifier() \ | |
325 | (current_language->la_binary_format.la_format_specifier) | |
326 | #define local_binary_format_suffix() \ | |
327 | (current_language->la_binary_format.la_format_suffix) | |
328 | ||
329 | #define local_octal_format() \ | |
330 | (current_language->la_octal_format.la_format) | |
331 | #define local_octal_format_prefix() \ | |
332 | (current_language->la_octal_format.la_format_prefix) | |
333 | #define local_octal_format_specifier() \ | |
334 | (current_language->la_octal_format.la_format_specifier) | |
335 | #define local_octal_format_suffix() \ | |
336 | (current_language->la_octal_format.la_format_suffix) | |
337 | ||
338 | #define local_decimal_format() \ | |
339 | (current_language->la_decimal_format.la_format) | |
340 | #define local_decimal_format_prefix() \ | |
341 | (current_language->la_decimal_format.la_format_prefix) | |
342 | #define local_decimal_format_specifier() \ | |
343 | (current_language->la_decimal_format.la_format_specifier) | |
344 | #define local_decimal_format_suffix() \ | |
345 | (current_language->la_decimal_format.la_format_suffix) | |
346 | ||
347 | #define local_hex_format() \ | |
348 | (current_language->la_hex_format.la_format) | |
349 | #define local_hex_format_prefix() \ | |
350 | (current_language->la_hex_format.la_format_prefix) | |
351 | #define local_hex_format_specifier() \ | |
352 | (current_language->la_hex_format.la_format_specifier) | |
353 | #define local_hex_format_suffix() \ | |
354 | (current_language->la_hex_format.la_format_suffix) | |
355 | ||
356 | #define LA_PRINT_CHAR(ch, stream) \ | |
357 | (current_language->la_printchar(ch, stream)) | |
358 | #define LA_PRINT_STRING(stream, string, length, width, force_ellipses) \ | |
359 | (current_language->la_printstr(stream, string, length, width, force_ellipses)) | |
360 | #define LA_EMIT_CHAR(ch, stream, quoter) \ | |
361 | (current_language->la_emitchar(ch, stream, quoter)) | |
362 | ||
363 | /* Test a character to decide whether it can be printed in literal form | |
364 | or needs to be printed in another representation. For example, | |
365 | in C the literal form of the character with octal value 141 is 'a' | |
366 | and the "other representation" is '\141'. The "other representation" | |
367 | is program language dependent. */ | |
368 | ||
369 | #define PRINT_LITERAL_FORM(c) \ | |
370 | ((c) >= 0x20 \ | |
371 | && ((c) < 0x7F || (c) >= 0xA0) \ | |
372 | && (!sevenbit_strings || (c) < 0x80)) | |
373 | ||
374 | /* Return a format string for printf that will print a number in one of | |
375 | the local (language-specific) formats. Result is static and is | |
376 | overwritten by the next call. Takes printf options like "08" or "l" | |
377 | (to produce e.g. %08x or %lx). */ | |
378 | ||
a14ed312 | 379 | extern char *local_decimal_format_custom (char *); /* language.c */ |
c906108c | 380 | |
a14ed312 | 381 | extern char *local_octal_format_custom (char *); /* language.c */ |
c906108c | 382 | |
a14ed312 | 383 | extern char *local_hex_format_custom (char *); /* language.c */ |
c906108c | 384 | |
7acb79c8 AC |
385 | #if 0 |
386 | /* FIXME: cagney/2000-03-04: This function does not appear to be used. | |
387 | It can be deleted once 5.0 has been released. */ | |
c4093a6a JM |
388 | /* Return a string that contains the hex digits of the number. No preceeding |
389 | "0x" */ | |
390 | ||
a14ed312 | 391 | extern char *longest_raw_hex_string (LONGEST); |
7acb79c8 | 392 | #endif |
c4093a6a | 393 | |
c906108c SS |
394 | /* Return a string that contains a number formatted in one of the local |
395 | (language-specific) formats. Result is static and is overwritten by | |
c4093a6a | 396 | the next call. Takes printf options like "08l" or "l". */ |
c906108c | 397 | |
a14ed312 | 398 | extern char *local_hex_string (unsigned long); /* language.c */ |
c906108c | 399 | |
a14ed312 | 400 | extern char *longest_local_hex_string (LONGEST); /* language.c */ |
c4093a6a | 401 | |
a14ed312 | 402 | extern char *local_hex_string_custom (unsigned long, char *); /* language.c */ |
c906108c | 403 | |
a14ed312 | 404 | extern char *longest_local_hex_string_custom (LONGEST, char *); /* language.c */ |
c4093a6a | 405 | |
c906108c SS |
406 | /* Type predicates */ |
407 | ||
a14ed312 | 408 | extern int simple_type (struct type *); |
c906108c | 409 | |
a14ed312 | 410 | extern int ordered_type (struct type *); |
c906108c | 411 | |
a14ed312 | 412 | extern int same_type (struct type *, struct type *); |
c906108c | 413 | |
a14ed312 | 414 | extern int integral_type (struct type *); |
c906108c | 415 | |
a14ed312 | 416 | extern int numeric_type (struct type *); |
c906108c | 417 | |
a14ed312 | 418 | extern int character_type (struct type *); |
c906108c | 419 | |
a14ed312 | 420 | extern int boolean_type (struct type *); |
c906108c | 421 | |
a14ed312 | 422 | extern int float_type (struct type *); |
c906108c | 423 | |
a14ed312 | 424 | extern int pointer_type (struct type *); |
c906108c | 425 | |
a14ed312 | 426 | extern int structured_type (struct type *); |
c906108c SS |
427 | |
428 | /* Checks Binary and Unary operations for semantic type correctness */ | |
429 | /* FIXME: Does not appear to be used */ | |
430 | #define unop_type_check(v,o) binop_type_check((v),NULL,(o)) | |
431 | ||
a14ed312 | 432 | extern void binop_type_check (struct value *, struct value *, int); |
c906108c SS |
433 | |
434 | /* Error messages */ | |
435 | ||
a14ed312 | 436 | extern void op_error (char *fmt, enum exp_opcode, int); |
c906108c SS |
437 | |
438 | #define type_op_error(f,o) \ | |
439 | op_error((f),(o),type_check==type_check_on ? 1 : 0) | |
440 | #define range_op_error(f,o) \ | |
441 | op_error((f),(o),range_check==range_check_on ? 1 : 0) | |
442 | ||
ddfe3c15 | 443 | extern void type_error (const char *, ...) ATTR_FORMAT (printf, 1, 2); |
c906108c | 444 | |
ddfe3c15 | 445 | extern void range_error (const char *, ...) ATTR_FORMAT (printf, 1, 2); |
c906108c SS |
446 | |
447 | /* Data: Does this value represent "truth" to the current language? */ | |
448 | ||
a14ed312 | 449 | extern int value_true (struct value *); |
c906108c | 450 | |
a14ed312 | 451 | extern struct type *lang_bool_type (void); |
c906108c SS |
452 | |
453 | /* The type used for Boolean values in the current language. */ | |
454 | #define LA_BOOL_TYPE lang_bool_type () | |
455 | ||
456 | /* Misc: The string representing a particular enum language. */ | |
457 | ||
a14ed312 | 458 | extern enum language language_enum (char *str); |
c906108c | 459 | |
a14ed312 | 460 | extern const struct language_defn *language_def (enum language); |
7a292a7a | 461 | |
a14ed312 | 462 | extern char *language_str (enum language); |
c906108c SS |
463 | |
464 | /* Add a language to the set known by GDB (at initialization time). */ | |
465 | ||
a14ed312 | 466 | extern void add_language (const struct language_defn *); |
c906108c | 467 | |
a14ed312 | 468 | extern enum language get_frame_language (void); /* In stack.c */ |
c906108c | 469 | |
c5aa993b | 470 | #endif /* defined (LANGUAGE_H) */ |