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