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