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