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