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