import gdb-1999-07-07 post reformat
[deliverable/binutils-gdb.git] / gdb / language.h
CommitLineData
c906108c
SS
1/* Source-language-related definitions for GDB.
2 Copyright 1991, 1992 Free Software Foundation, Inc.
3 Contributed by the Department of Computer Science at the State University
4 of New York at Buffalo.
5
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22#if !defined (LANGUAGE_H)
23#define LANGUAGE_H 1
24
25#ifdef __STDC__ /* Forward decls for prototypes */
26struct value;
27struct objfile;
28struct expression;
29/* enum exp_opcode; ANSI's `wisdom' didn't include forward enum decls. */
30#endif
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
40#define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */
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
46extern 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
53extern 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
60extern 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
67extern enum type_check
68 {type_check_off, type_check_warn, type_check_on} type_check;
69\f
70/* Information for doing language dependent formatting of printed values. */
71
72struct 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
101/* Structure tying together assorted information about a language. */
102
103struct 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
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. */
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
136 /* Evaluate an expression. */
137 struct value * (*evaluate_exp) PARAMS ((struct type *, struct expression *,
138 int *, enum noside));
139
140 void (*la_printchar) PARAMS ((int ch, GDB_FILE *stream));
141
142 void (*la_printstr) PARAMS ((GDB_FILE *stream, char *string,
143 unsigned int length, int width,
144 int force_ellipses));
145
146 void (*la_emitchar) PARAMS ((int ch, GDB_FILE *stream, int quoter));
147
148 struct type *(*la_fund_type) PARAMS ((struct objfile *, int));
149
150 /* Print a type using syntax appropriate for this language. */
151
152 void (*la_print_type) PARAMS ((struct type *, char *, GDB_FILE *, int, int));
153
154 /* Print a value using syntax appropriate for this language. */
155
156 int (*la_val_print) PARAMS ((struct type *, char *, int, CORE_ADDR, GDB_FILE *,
157 int, int, int, enum val_prettyprint));
158
159 /* Print a top-level value using syntax appropriate for this language. */
160
161 int (*la_value_print) PARAMS ((struct value *, GDB_FILE *,
162 int, enum val_prettyprint));
163
164 /* Base 2 (binary) formats. */
165
166 struct language_format_info la_binary_format;
167
168 /* Base 8 (octal) formats. */
169
170 struct language_format_info la_octal_format;
171
172 /* Base 10 (decimal) formats */
173
174 struct language_format_info la_decimal_format;
175
176 /* Base 16 (hexadecimal) formats */
177
178 struct language_format_info la_hex_format;
179
180 /* Table for printing expressions */
181
182 const struct op_print *la_op_print_tab;
183
184 /* Zero if the language has first-class arrays. True if there are no
185 array values, and array objects decay to pointers, as in C. */
186
187 char c_style_arrays;
188
189 /* Index to use for extracting the first element of a string. */
190 char string_lower_bound;
191
192 /* Type of elements of strings. */
193 struct type **string_char_type;
194
195 /* Add fields above this point, so the magic number is always last. */
196 /* Magic number for compat checking */
197
198 long la_magic;
199
200};
201
202#define LANG_MAGIC 910823L
203
204/* Pointer to the language_defn for our current language. This pointer
205 always points to *some* valid struct; it can be used without checking
206 it for validity.
207
208 The current language affects expression parsing and evaluation
209 (FIXME: it might be cleaner to make the evaluation-related stuff
210 separate exp_opcodes for each different set of semantics. We
211 should at least think this through more clearly with respect to
212 what happens if the language is changed between parsing and
213 evaluation) and printing of things like types and arrays. It does
214 *not* affect symbol-reading-- each source file in a symbol-file has
215 its own language and we should keep track of that regardless of the
216 language when symbols are read. If we want some manual setting for
217 the language of symbol files (e.g. detecting when ".c" files are
218 C++), it should be a seprate setting from the current_language. */
219
220extern const struct language_defn *current_language;
221
222/* Pointer to the language_defn expected by the user, e.g. the language
223 of main(), or the language we last mentioned in a message, or C. */
224
225extern const struct language_defn *expected_language;
226
227/* language_mode ==
228 language_mode_auto: current_language automatically set upon selection
229 of scope (e.g. stack frame)
230 language_mode_manual: current_language set only by user. */
231
232extern enum language_mode
233 {language_mode_auto, language_mode_manual} language_mode;
234\f
235/* These macros define the behaviour of the expression
236 evaluator. */
237
238/* Should we strictly type check expressions? */
239#define STRICT_TYPE (type_check != type_check_off)
240
241/* Should we range check values against the domain of their type? */
242#define RANGE_CHECK (range_check != range_check_off)
243
244/* "cast" really means conversion */
245/* FIXME -- should be a setting in language_defn */
246#define CAST_IS_CONVERSION (current_language->la_language == language_c || \
247 current_language->la_language == language_cplus)
248
249extern void
250language_info PARAMS ((int));
251
252extern enum language
253set_language PARAMS ((enum language));
254
255\f
256/* This page contains functions that return things that are
257 specific to languages. Each of these functions is based on
258 the current setting of working_lang, which the user sets
259 with the "set language" command. */
260
261#define create_fundamental_type(objfile,typeid) \
262 (current_language->la_fund_type(objfile, typeid))
263
264#define LA_PRINT_TYPE(type,varstring,stream,show,level) \
265 (current_language->la_print_type(type,varstring,stream,show,level))
266
267#define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \
268 (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \
269 recurse,pretty))
270#define LA_VALUE_PRINT(val,stream,fmt,pretty) \
271 (current_language->la_value_print(val,stream,fmt,pretty))
272
273/* Return a format string for printf that will print a number in one of
274 the local (language-specific) formats. Result is static and is
275 overwritten by the next call. Takes printf options like "08" or "l"
276 (to produce e.g. %08x or %lx). */
277
278#define local_binary_format() \
279 (current_language->la_binary_format.la_format)
280#define local_binary_format_prefix() \
281 (current_language->la_binary_format.la_format_prefix)
282#define local_binary_format_specifier() \
283 (current_language->la_binary_format.la_format_specifier)
284#define local_binary_format_suffix() \
285 (current_language->la_binary_format.la_format_suffix)
286
287#define local_octal_format() \
288 (current_language->la_octal_format.la_format)
289#define local_octal_format_prefix() \
290 (current_language->la_octal_format.la_format_prefix)
291#define local_octal_format_specifier() \
292 (current_language->la_octal_format.la_format_specifier)
293#define local_octal_format_suffix() \
294 (current_language->la_octal_format.la_format_suffix)
295
296#define local_decimal_format() \
297 (current_language->la_decimal_format.la_format)
298#define local_decimal_format_prefix() \
299 (current_language->la_decimal_format.la_format_prefix)
300#define local_decimal_format_specifier() \
301 (current_language->la_decimal_format.la_format_specifier)
302#define local_decimal_format_suffix() \
303 (current_language->la_decimal_format.la_format_suffix)
304
305#define local_hex_format() \
306 (current_language->la_hex_format.la_format)
307#define local_hex_format_prefix() \
308 (current_language->la_hex_format.la_format_prefix)
309#define local_hex_format_specifier() \
310 (current_language->la_hex_format.la_format_specifier)
311#define local_hex_format_suffix() \
312 (current_language->la_hex_format.la_format_suffix)
313
314#define LA_PRINT_CHAR(ch, stream) \
315 (current_language->la_printchar(ch, stream))
316#define LA_PRINT_STRING(stream, string, length, width, force_ellipses) \
317 (current_language->la_printstr(stream, string, length, width, force_ellipses))
318#define LA_EMIT_CHAR(ch, stream, quoter) \
319 (current_language->la_emitchar(ch, stream, quoter))
320
321/* Test a character to decide whether it can be printed in literal form
322 or needs to be printed in another representation. For example,
323 in C the literal form of the character with octal value 141 is 'a'
324 and the "other representation" is '\141'. The "other representation"
325 is program language dependent. */
326
327#define PRINT_LITERAL_FORM(c) \
328 ((c) >= 0x20 \
329 && ((c) < 0x7F || (c) >= 0xA0) \
330 && (!sevenbit_strings || (c) < 0x80))
331
332/* Return a format string for printf that will print a number in one of
333 the local (language-specific) formats. Result is static and is
334 overwritten by the next call. Takes printf options like "08" or "l"
335 (to produce e.g. %08x or %lx). */
336
337extern char *
338local_decimal_format_custom PARAMS ((char *)); /* language.c */
339
340extern char *
341local_octal_format_custom PARAMS ((char *)); /* language.c */
342
343extern char *
344local_hex_format_custom PARAMS ((char *)); /* language.c */
345
346/* Return a string that contains a number formatted in one of the local
347 (language-specific) formats. Result is static and is overwritten by
348 the next call. Takes printf options like "08" or "l". */
349
350extern char *
351local_hex_string PARAMS ((unsigned long)); /* language.c */
352
353extern char *
354local_hex_string_custom PARAMS ((unsigned long, char *)); /* language.c */
355
356/* Type predicates */
357
358extern int
359simple_type PARAMS ((struct type *));
360
361extern int
362ordered_type PARAMS ((struct type *));
363
364extern int
365same_type PARAMS ((struct type *, struct type *));
366
367extern int
368integral_type PARAMS ((struct type *));
369
370extern int
371numeric_type PARAMS ((struct type *));
372
373extern int
374character_type PARAMS ((struct type *));
375
376extern int
377boolean_type PARAMS ((struct type *));
378
379extern int
380float_type PARAMS ((struct type *));
381
382extern int
383pointer_type PARAMS ((struct type *));
384
385extern int
386structured_type PARAMS ((struct type *));
387
388/* Checks Binary and Unary operations for semantic type correctness */
389/* FIXME: Does not appear to be used */
390#define unop_type_check(v,o) binop_type_check((v),NULL,(o))
391
392extern void
393binop_type_check PARAMS ((struct value *, struct value *, int));
394
395/* Error messages */
396
397extern void
398op_error PARAMS ((char *fmt, enum exp_opcode, int));
399
400#define type_op_error(f,o) \
401 op_error((f),(o),type_check==type_check_on ? 1 : 0)
402#define range_op_error(f,o) \
403 op_error((f),(o),range_check==range_check_on ? 1 : 0)
404
405extern void
406type_error PARAMS ((char *, ...))
407 ATTR_FORMAT(printf, 1, 2);
408
409void
410range_error PARAMS ((char *, ...))
411 ATTR_FORMAT(printf, 1, 2);
412
413/* Data: Does this value represent "truth" to the current language? */
414
415extern int
416value_true PARAMS ((struct value *));
417
418extern struct type * lang_bool_type PARAMS ((void));
419
420/* The type used for Boolean values in the current language. */
421#define LA_BOOL_TYPE lang_bool_type ()
422
423/* Misc: The string representing a particular enum language. */
424
7a292a7a 425extern enum language language_enum PARAMS ((char *str));
c906108c 426
7a292a7a
SS
427extern const struct language_defn *language_def PARAMS ((enum language));
428
429extern char *language_str PARAMS ((enum language));
c906108c
SS
430
431/* Add a language to the set known by GDB (at initialization time). */
432
433extern void
434add_language PARAMS ((const struct language_defn *));
435
436extern enum language
437get_frame_language PARAMS ((void)); /* In stack.c */
438
439#endif /* defined (LANGUAGE_H) */
This page took 0.04443 seconds and 4 git commands to generate.