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