]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/c-lang.c
* configure.ac: Switch license to GPLv3.
[thirdparty/binutils-gdb.git] / gdb / c-lang.c
CommitLineData
c906108c 1/* C language support routines for GDB, the GNU debugger.
ce27fb25 2
6aba47ca
DJ
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003,
4 2004, 2005, 2007 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b
JM
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
197e01b6
EZ
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
c906108c
SS
22
23#include "defs.h"
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "parser-defs.h"
28#include "language.h"
29#include "c-lang.h"
745b8ca0 30#include "valprint.h"
84f0252a
JB
31#include "macroscope.h"
32#include "gdb_assert.h"
234b45d4 33#include "charset.h"
a15ef5f5 34#include "gdb_string.h"
9a3d7dfd 35#include "demangle.h"
b18be20d 36#include "cp-abi.h"
1fcb5155 37#include "cp-support.h"
c906108c 38
a14ed312 39extern void _initialize_c_language (void);
d9fcf2fb 40static void c_emit_char (int c, struct ui_file * stream, int quoter);
c906108c
SS
41
42/* Print the character C on STREAM as part of the contents of a literal
43 string whose delimiter is QUOTER. Note that that format for printing
44 characters and strings is language specific. */
45
46static void
f86f5ca3 47c_emit_char (int c, struct ui_file *stream, int quoter)
c906108c 48{
234b45d4
KB
49 const char *escape;
50 int host_char;
51
c906108c
SS
52 c &= 0xFF; /* Avoid sign bit follies */
53
234b45d4
KB
54 escape = c_target_char_has_backslash_escape (c);
55 if (escape)
c906108c 56 {
234b45d4
KB
57 if (quoter == '"' && strcmp (escape, "0") == 0)
58 /* Print nulls embedded in double quoted strings as \000 to
59 prevent ambiguity. */
60 fprintf_filtered (stream, "\\000");
61 else
62 fprintf_filtered (stream, "\\%s", escape);
c906108c 63 }
234b45d4
KB
64 else if (target_char_to_host (c, &host_char)
65 && host_char_print_literally (host_char))
c906108c 66 {
234b45d4
KB
67 if (host_char == '\\' || host_char == quoter)
68 fputs_filtered ("\\", stream);
69 fprintf_filtered (stream, "%c", host_char);
c906108c 70 }
234b45d4
KB
71 else
72 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
c906108c
SS
73}
74
75void
fba45db2 76c_printchar (int c, struct ui_file *stream)
c906108c
SS
77{
78 fputc_filtered ('\'', stream);
79 LA_EMIT_CHAR (c, stream, '\'');
80 fputc_filtered ('\'', stream);
81}
82
83/* Print the character string STRING, printing at most LENGTH characters.
84 LENGTH is -1 if the string is nul terminated. Each character is WIDTH bytes
85 long. Printing stops early if the number hits print_max; repeat counts are
86 printed as appropriate. Print ellipses at the end if we had to stop before
87 printing LENGTH characters, or if FORCE_ELLIPSES. */
88
89void
fc1a4b47 90c_printstr (struct ui_file *stream, const gdb_byte *string,
ce27fb25 91 unsigned int length, int width, int force_ellipses)
c906108c 92{
f86f5ca3 93 unsigned int i;
c906108c
SS
94 unsigned int things_printed = 0;
95 int in_quotes = 0;
96 int need_comma = 0;
c906108c
SS
97
98 /* If the string was not truncated due to `set print elements', and
99 the last byte of it is a null, we don't print that, in traditional C
100 style. */
101 if (!force_ellipses
102 && length > 0
78a51202
JB
103 && (extract_unsigned_integer (string + (length - 1) * width, width)
104 == '\0'))
c906108c
SS
105 length--;
106
107 if (length == 0)
108 {
109 fputs_filtered ("\"\"", stream);
110 return;
111 }
112
113 for (i = 0; i < length && things_printed < print_max; ++i)
114 {
115 /* Position of the character we are examining
c5aa993b 116 to see whether it is repeated. */
c906108c
SS
117 unsigned int rep1;
118 /* Number of repetitions we have detected so far. */
119 unsigned int reps;
120 unsigned long current_char;
121
122 QUIT;
123
124 if (need_comma)
125 {
126 fputs_filtered (", ", stream);
127 need_comma = 0;
128 }
129
130 current_char = extract_unsigned_integer (string + i * width, width);
131
132 rep1 = i + 1;
133 reps = 1;
134 while (rep1 < length
135 && extract_unsigned_integer (string + rep1 * width, width)
c5aa993b 136 == current_char)
c906108c
SS
137 {
138 ++rep1;
139 ++reps;
140 }
141
142 if (reps > repeat_count_threshold)
143 {
144 if (in_quotes)
145 {
146 if (inspect_it)
147 fputs_filtered ("\\\", ", stream);
148 else
149 fputs_filtered ("\", ", stream);
150 in_quotes = 0;
151 }
152 LA_PRINT_CHAR (current_char, stream);
3d263c1d 153 fprintf_filtered (stream, _(" <repeats %u times>"), reps);
c906108c
SS
154 i = rep1 - 1;
155 things_printed += repeat_count_threshold;
156 need_comma = 1;
157 }
158 else
159 {
160 if (!in_quotes)
161 {
162 if (inspect_it)
163 fputs_filtered ("\\\"", stream);
164 else
165 fputs_filtered ("\"", stream);
166 in_quotes = 1;
167 }
168 LA_EMIT_CHAR (current_char, stream, '"');
169 ++things_printed;
170 }
171 }
172
173 /* Terminate the quotes if necessary. */
174 if (in_quotes)
175 {
176 if (inspect_it)
177 fputs_filtered ("\\\"", stream);
178 else
179 fputs_filtered ("\"", stream);
180 }
181
182 if (force_ellipses || i < length)
183 fputs_filtered ("...", stream);
184}
185
186/* Create a fundamental C type using default reasonable for the current
187 target machine.
188
189 Some object/debugging file formats (DWARF version 1, COFF, etc) do not
190 define fundamental types such as "int" or "double". Others (stabs or
191 DWARF version 2, etc) do define fundamental types. For the formats which
192 don't provide fundamental types, gdb can create such types using this
193 function.
194
195 FIXME: Some compilers distinguish explicitly signed integral types
196 (signed short, signed int, signed long) from "regular" integral types
197 (short, int, long) in the debugging information. There is some dis-
198 agreement as to how useful this feature is. In particular, gcc does
199 not support this. Also, only some debugging formats allow the
200 distinction to be passed on to a debugger. For now, we always just
201 use "short", "int", or "long" as the type name, for both the implicit
202 and explicitly signed types. This also makes life easier for the
203 gdb test suite since we don't have to account for the differences
204 in output depending upon what the compiler and debugging format
205 support. We will probably have to re-examine the issue when gdb
8470e927 206 starts taking its fundamental type information directly from the
c906108c
SS
207 debugging information supplied by the compiler. fnf@cygnus.com */
208
209struct type *
fba45db2 210c_create_fundamental_type (struct objfile *objfile, int typeid)
c906108c 211{
f86f5ca3 212 struct type *type = NULL;
c906108c
SS
213
214 switch (typeid)
215 {
c5aa993b
JM
216 default:
217 /* FIXME: For now, if we are asked to produce a type not in this
218 language, create the equivalent of a C integer type with the
219 name "<?type?>". When all the dust settles from the type
220 reconstruction work, this should probably become an error. */
221 type = init_type (TYPE_CODE_INT,
9a76efb6 222 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b 223 0, "<?type?>", objfile);
3d263c1d 224 warning (_("internal error: no C/C++ fundamental type %d"), typeid);
c5aa993b
JM
225 break;
226 case FT_VOID:
227 type = init_type (TYPE_CODE_VOID,
228 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
229 0, "void", objfile);
230 break;
231 case FT_BOOLEAN:
232 type = init_type (TYPE_CODE_BOOL,
233 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
234 0, "bool", objfile);
c5aa993b
JM
235 break;
236 case FT_CHAR:
237 type = init_type (TYPE_CODE_INT,
238 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
6edc140f 239 TYPE_FLAG_NOSIGN, "char", objfile);
c5aa993b
JM
240 break;
241 case FT_SIGNED_CHAR:
242 type = init_type (TYPE_CODE_INT,
243 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
244 0, "signed char", objfile);
245 break;
246 case FT_UNSIGNED_CHAR:
247 type = init_type (TYPE_CODE_INT,
248 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
249 TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
250 break;
251 case FT_SHORT:
252 type = init_type (TYPE_CODE_INT,
9a76efb6 253 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
254 0, "short", objfile);
255 break;
256 case FT_SIGNED_SHORT:
257 type = init_type (TYPE_CODE_INT,
9a76efb6 258 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
259 0, "short", objfile); /* FIXME-fnf */
260 break;
261 case FT_UNSIGNED_SHORT:
262 type = init_type (TYPE_CODE_INT,
9a76efb6 263 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
264 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
265 break;
266 case FT_INTEGER:
267 type = init_type (TYPE_CODE_INT,
9a76efb6 268 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
269 0, "int", objfile);
270 break;
271 case FT_SIGNED_INTEGER:
272 type = init_type (TYPE_CODE_INT,
9a76efb6 273 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
274 0, "int", objfile); /* FIXME -fnf */
275 break;
276 case FT_UNSIGNED_INTEGER:
277 type = init_type (TYPE_CODE_INT,
9a76efb6 278 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
279 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
280 break;
281 case FT_LONG:
282 type = init_type (TYPE_CODE_INT,
9a76efb6 283 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
284 0, "long", objfile);
285 break;
286 case FT_SIGNED_LONG:
287 type = init_type (TYPE_CODE_INT,
9a76efb6 288 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
289 0, "long", objfile); /* FIXME -fnf */
290 break;
291 case FT_UNSIGNED_LONG:
292 type = init_type (TYPE_CODE_INT,
9a76efb6 293 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
294 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
295 break;
296 case FT_LONG_LONG:
297 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
298 gdbarch_long_long_bit (current_gdbarch)
299 / TARGET_CHAR_BIT,
c5aa993b
JM
300 0, "long long", objfile);
301 break;
302 case FT_SIGNED_LONG_LONG:
303 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
304 gdbarch_long_long_bit (current_gdbarch)
305 / TARGET_CHAR_BIT,
c5aa993b
JM
306 0, "signed long long", objfile);
307 break;
308 case FT_UNSIGNED_LONG_LONG:
309 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
310 gdbarch_long_long_bit (current_gdbarch)
311 / TARGET_CHAR_BIT,
c5aa993b
JM
312 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
313 break;
314 case FT_FLOAT:
315 type = init_type (TYPE_CODE_FLT,
ea06eb3d 316 gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
317 0, "float", objfile);
318 break;
319 case FT_DBL_PREC_FLOAT:
320 type = init_type (TYPE_CODE_FLT,
ea06eb3d 321 gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
c5aa993b
JM
322 0, "double", objfile);
323 break;
324 case FT_EXT_PREC_FLOAT:
325 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
326 gdbarch_long_double_bit (current_gdbarch)
327 / TARGET_CHAR_BIT,
c5aa993b
JM
328 0, "long double", objfile);
329 break;
f65ca430
DJ
330 case FT_COMPLEX:
331 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
332 2 * gdbarch_float_bit (current_gdbarch)
333 / TARGET_CHAR_BIT,
f65ca430
DJ
334 0, "complex float", objfile);
335 TYPE_TARGET_TYPE (type)
ea06eb3d
UW
336 = init_type (TYPE_CODE_FLT,
337 gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
f65ca430
DJ
338 0, "float", objfile);
339 break;
340 case FT_DBL_PREC_COMPLEX:
341 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
342 2 * gdbarch_double_bit (current_gdbarch)
343 / TARGET_CHAR_BIT,
f65ca430
DJ
344 0, "complex double", objfile);
345 TYPE_TARGET_TYPE (type)
ea06eb3d
UW
346 = init_type (TYPE_CODE_FLT,
347 gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
f65ca430
DJ
348 0, "double", objfile);
349 break;
350 case FT_EXT_PREC_COMPLEX:
351 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
352 2 * gdbarch_long_double_bit (current_gdbarch)
353 / TARGET_CHAR_BIT,
f65ca430
DJ
354 0, "complex long double", objfile);
355 TYPE_TARGET_TYPE (type)
ea06eb3d
UW
356 = init_type (TYPE_CODE_FLT,
357 gdbarch_long_double_bit (current_gdbarch)
358 / TARGET_CHAR_BIT,
f65ca430
DJ
359 0, "long double", objfile);
360 break;
c5aa993b
JM
361 case FT_TEMPLATE_ARG:
362 type = init_type (TYPE_CODE_TEMPLATE_ARG,
363 0,
364 0, "<template arg>", objfile);
c5aa993b
JM
365 break;
366 }
c906108c
SS
367 return (type);
368}
c906108c 369\f
84f0252a 370/* Preprocessing and parsing C and C++ expressions. */
c5aa993b 371
84f0252a
JB
372
373/* When we find that lexptr (the global var defined in parse.c) is
374 pointing at a macro invocation, we expand the invocation, and call
375 scan_macro_expansion to save the old lexptr here and point lexptr
376 into the expanded text. When we reach the end of that, we call
377 end_macro_expansion to pop back to the value we saved here. The
378 macro expansion code promises to return only fully-expanded text,
379 so we don't need to "push" more than one level.
380
381 This is disgusting, of course. It would be cleaner to do all macro
382 expansion beforehand, and then hand that to lexptr. But we don't
383 really know where the expression ends. Remember, in a command like
384
385 (gdb) break *ADDRESS if CONDITION
386
387 we evaluate ADDRESS in the scope of the current frame, but we
388 evaluate CONDITION in the scope of the breakpoint's location. So
389 it's simply wrong to try to macro-expand the whole thing at once. */
390static char *macro_original_text;
391static char *macro_expanded_text;
392
393
394void
395scan_macro_expansion (char *expansion)
396{
397 /* We'd better not be trying to push the stack twice. */
398 gdb_assert (! macro_original_text);
399 gdb_assert (! macro_expanded_text);
400
401 /* Save the old lexptr value, so we can return to it when we're done
402 parsing the expanded text. */
403 macro_original_text = lexptr;
404 lexptr = expansion;
405
406 /* Save the expanded text, so we can free it when we're finished. */
407 macro_expanded_text = expansion;
408}
409
410
411int
5ae5f592 412scanning_macro_expansion (void)
84f0252a
JB
413{
414 return macro_original_text != 0;
415}
416
417
418void
5ae5f592 419finished_macro_expansion (void)
84f0252a
JB
420{
421 /* There'd better be something to pop back to, and we better have
422 saved a pointer to the start of the expanded text. */
423 gdb_assert (macro_original_text);
424 gdb_assert (macro_expanded_text);
425
426 /* Pop back to the original text. */
427 lexptr = macro_original_text;
428 macro_original_text = 0;
429
430 /* Free the expanded text. */
431 xfree (macro_expanded_text);
432 macro_expanded_text = 0;
433}
434
435
436static void
437scan_macro_cleanup (void *dummy)
438{
439 if (macro_original_text)
440 finished_macro_expansion ();
441}
442
443
444/* We set these global variables before calling c_parse, to tell it
445 how it to find macro definitions for the expression at hand. */
446macro_lookup_ftype *expression_macro_lookup_func;
447void *expression_macro_lookup_baton;
448
449
450static struct macro_definition *
451null_macro_lookup (const char *name, void *baton)
452{
453 return 0;
454}
455
456
457static int
5ae5f592 458c_preprocess_and_parse (void)
84f0252a
JB
459{
460 /* Set up a lookup function for the macro expander. */
461 struct macro_scope *scope = 0;
462 struct cleanup *back_to = make_cleanup (free_current_contents, &scope);
463
464 if (expression_context_block)
465 scope = sal_macro_scope (find_pc_line (expression_context_pc, 0));
466 else
467 scope = default_macro_scope ();
468
469 if (scope)
470 {
471 expression_macro_lookup_func = standard_macro_lookup;
472 expression_macro_lookup_baton = (void *) scope;
473 }
474 else
475 {
476 expression_macro_lookup_func = null_macro_lookup;
477 expression_macro_lookup_baton = 0;
478 }
479
480 gdb_assert (! macro_original_text);
481 make_cleanup (scan_macro_cleanup, 0);
482
483 {
484 int result = c_parse ();
485 do_cleanups (back_to);
486 return result;
487 }
488}
489
490
491\f
c906108c
SS
492/* Table mapping opcodes into strings for printing operators
493 and precedences of the operators. */
494
495const struct op_print c_op_print_tab[] =
c5aa993b
JM
496{
497 {",", BINOP_COMMA, PREC_COMMA, 0},
498 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
499 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
500 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
501 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
502 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
503 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
504 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
505 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
506 {"<=", BINOP_LEQ, PREC_ORDER, 0},
507 {">=", BINOP_GEQ, PREC_ORDER, 0},
508 {">", BINOP_GTR, PREC_ORDER, 0},
509 {"<", BINOP_LESS, PREC_ORDER, 0},
510 {">>", BINOP_RSH, PREC_SHIFT, 0},
511 {"<<", BINOP_LSH, PREC_SHIFT, 0},
512 {"+", BINOP_ADD, PREC_ADD, 0},
513 {"-", BINOP_SUB, PREC_ADD, 0},
514 {"*", BINOP_MUL, PREC_MUL, 0},
515 {"/", BINOP_DIV, PREC_MUL, 0},
516 {"%", BINOP_REM, PREC_MUL, 0},
517 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
518 {"-", UNOP_NEG, PREC_PREFIX, 0},
519 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
520 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
521 {"*", UNOP_IND, PREC_PREFIX, 0},
522 {"&", UNOP_ADDR, PREC_PREFIX, 0},
523 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
524 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
525 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
c5aa993b 526 {NULL, 0, 0, 0}
c906108c
SS
527};
528\f
685419e2
AC
529enum c_primitive_types {
530 c_primitive_type_int,
531 c_primitive_type_long,
532 c_primitive_type_short,
533 c_primitive_type_char,
534 c_primitive_type_float,
535 c_primitive_type_double,
536 c_primitive_type_void,
537 c_primitive_type_long_long,
538 c_primitive_type_signed_char,
539 c_primitive_type_unsigned_char,
540 c_primitive_type_unsigned_short,
541 c_primitive_type_unsigned_int,
542 c_primitive_type_unsigned_long,
543 c_primitive_type_unsigned_long_long,
544 c_primitive_type_long_double,
545 c_primitive_type_complex,
546 c_primitive_type_double_complex,
547 nr_c_primitive_types
548};
549
e9667a65 550void
685419e2
AC
551c_language_arch_info (struct gdbarch *gdbarch,
552 struct language_arch_info *lai)
553{
554 const struct builtin_type *builtin = builtin_type (gdbarch);
e9667a65 555 lai->string_char_type = builtin->builtin_char;
685419e2
AC
556 lai->primitive_type_vector
557 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
558 struct type *);
559 lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
560 lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
561 lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
562 lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
563 lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
564 lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
565 lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
566 lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
567 lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
568 lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
569 lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
570 lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
571 lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
572 lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
573 lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
574 lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
575 lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
cad351d1 576}
685419e2 577
c5aa993b
JM
578const struct language_defn c_language_defn =
579{
c906108c
SS
580 "c", /* Language name */
581 language_c,
685419e2 582 NULL,
c906108c
SS
583 range_check_off,
584 type_check_off,
63872f9d 585 case_sensitive_on,
7ca2d3a3 586 array_row_major,
5f9769d1 587 &exp_descriptor_standard,
84f0252a 588 c_preprocess_and_parse,
c906108c 589 c_error,
e85c3284 590 null_post_parser,
c906108c
SS
591 c_printchar, /* Print a character constant */
592 c_printstr, /* Function to print string constant */
593 c_emit_char, /* Print a single char */
594 c_create_fundamental_type, /* Create fundamental type in this language */
595 c_print_type, /* Print a type using appropriate syntax */
596 c_val_print, /* Print a value using appropriate syntax */
597 c_value_print, /* Print a top-level value */
f636b87d 598 NULL, /* Language specific skip_trampoline */
5f9a71c3
DC
599 NULL, /* value_of_this */
600 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 601 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 602 NULL, /* Language specific symbol demangler */
31c27f77 603 NULL, /* Language specific class_name_from_physname */
c906108c
SS
604 c_op_print_tab, /* expression operators for printing */
605 1, /* c-style arrays */
606 0, /* String lower bound */
685419e2 607 NULL,
6084f43a 608 default_word_break_characters,
685419e2 609 c_language_arch_info,
e79af960 610 default_print_array_index,
c906108c
SS
611 LANG_MAGIC
612};
613
cad351d1
UW
614enum cplus_primitive_types {
615 cplus_primitive_type_int,
616 cplus_primitive_type_long,
617 cplus_primitive_type_short,
618 cplus_primitive_type_char,
619 cplus_primitive_type_float,
620 cplus_primitive_type_double,
621 cplus_primitive_type_void,
622 cplus_primitive_type_long_long,
623 cplus_primitive_type_signed_char,
624 cplus_primitive_type_unsigned_char,
625 cplus_primitive_type_unsigned_short,
626 cplus_primitive_type_unsigned_int,
627 cplus_primitive_type_unsigned_long,
628 cplus_primitive_type_unsigned_long_long,
629 cplus_primitive_type_long_double,
630 cplus_primitive_type_complex,
631 cplus_primitive_type_double_complex,
632 cplus_primitive_type_bool,
633 nr_cplus_primitive_types
c906108c
SS
634};
635
cad351d1
UW
636static void
637cplus_language_arch_info (struct gdbarch *gdbarch,
638 struct language_arch_info *lai)
639{
640 const struct builtin_type *builtin = builtin_type (gdbarch);
641 lai->string_char_type = builtin->builtin_char;
642 lai->primitive_type_vector
643 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
644 struct type *);
645 lai->primitive_type_vector [cplus_primitive_type_int]
646 = builtin->builtin_int;
647 lai->primitive_type_vector [cplus_primitive_type_long]
648 = builtin->builtin_long;
649 lai->primitive_type_vector [cplus_primitive_type_short]
650 = builtin->builtin_short;
651 lai->primitive_type_vector [cplus_primitive_type_char]
652 = builtin->builtin_char;
653 lai->primitive_type_vector [cplus_primitive_type_float]
654 = builtin->builtin_float;
655 lai->primitive_type_vector [cplus_primitive_type_double]
656 = builtin->builtin_double;
657 lai->primitive_type_vector [cplus_primitive_type_void]
658 = builtin->builtin_void;
659 lai->primitive_type_vector [cplus_primitive_type_long_long]
660 = builtin->builtin_long_long;
661 lai->primitive_type_vector [cplus_primitive_type_signed_char]
662 = builtin->builtin_signed_char;
663 lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
664 = builtin->builtin_unsigned_char;
665 lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
666 = builtin->builtin_unsigned_short;
667 lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
668 = builtin->builtin_unsigned_int;
669 lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
670 = builtin->builtin_unsigned_long;
671 lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
672 = builtin->builtin_unsigned_long_long;
673 lai->primitive_type_vector [cplus_primitive_type_long_double]
674 = builtin->builtin_long_double;
675 lai->primitive_type_vector [cplus_primitive_type_complex]
676 = builtin->builtin_complex;
677 lai->primitive_type_vector [cplus_primitive_type_double_complex]
678 = builtin->builtin_double_complex;
679 lai->primitive_type_vector [cplus_primitive_type_bool]
680 = builtin->builtin_bool;
681}
682
c5aa993b
JM
683const struct language_defn cplus_language_defn =
684{
685 "c++", /* Language name */
c906108c 686 language_cplus,
cad351d1 687 NULL,
c906108c
SS
688 range_check_off,
689 type_check_off,
63872f9d 690 case_sensitive_on,
7ca2d3a3 691 array_row_major,
5f9769d1 692 &exp_descriptor_standard,
84f0252a 693 c_preprocess_and_parse,
c906108c 694 c_error,
e85c3284 695 null_post_parser,
c906108c
SS
696 c_printchar, /* Print a character constant */
697 c_printstr, /* Function to print string constant */
698 c_emit_char, /* Print a single char */
699 c_create_fundamental_type, /* Create fundamental type in this language */
700 c_print_type, /* Print a type using appropriate syntax */
701 c_val_print, /* Print a value using appropriate syntax */
702 c_value_print, /* Print a top-level value */
b18be20d 703 cplus_skip_trampoline, /* Language specific skip_trampoline */
5f9a71c3 704 value_of_this, /* value_of_this */
1fcb5155 705 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 706 cp_lookup_transparent_type, /* lookup_transparent_type */
9a3d7dfd 707 cplus_demangle, /* Language specific symbol demangler */
31c27f77 708 cp_class_name_from_physname, /* Language specific class_name_from_physname */
c906108c
SS
709 c_op_print_tab, /* expression operators for printing */
710 1, /* c-style arrays */
711 0, /* String lower bound */
cad351d1 712 NULL,
6084f43a 713 default_word_break_characters,
cad351d1 714 cplus_language_arch_info,
e79af960 715 default_print_array_index,
c906108c
SS
716 LANG_MAGIC
717};
718
c5aa993b
JM
719const struct language_defn asm_language_defn =
720{
c906108c
SS
721 "asm", /* Language name */
722 language_asm,
e9667a65 723 NULL,
c906108c
SS
724 range_check_off,
725 type_check_off,
63872f9d 726 case_sensitive_on,
7ca2d3a3 727 array_row_major,
5f9769d1 728 &exp_descriptor_standard,
84f0252a 729 c_preprocess_and_parse,
c906108c 730 c_error,
e85c3284 731 null_post_parser,
c906108c
SS
732 c_printchar, /* Print a character constant */
733 c_printstr, /* Function to print string constant */
734 c_emit_char, /* Print a single char */
735 c_create_fundamental_type, /* Create fundamental type in this language */
736 c_print_type, /* Print a type using appropriate syntax */
737 c_val_print, /* Print a value using appropriate syntax */
738 c_value_print, /* Print a top-level value */
f636b87d 739 NULL, /* Language specific skip_trampoline */
5f9a71c3
DC
740 NULL, /* value_of_this */
741 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 742 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 743 NULL, /* Language specific symbol demangler */
31c27f77 744 NULL, /* Language specific class_name_from_physname */
c906108c
SS
745 c_op_print_tab, /* expression operators for printing */
746 1, /* c-style arrays */
747 0, /* String lower bound */
e9667a65 748 NULL,
6084f43a 749 default_word_break_characters,
e9667a65 750 c_language_arch_info, /* FIXME: la_language_arch_info. */
e79af960 751 default_print_array_index,
c906108c
SS
752 LANG_MAGIC
753};
754
20a0e81d
JB
755/* The following language_defn does not represent a real language.
756 It just provides a minimal support a-la-C that should allow users
757 to do some simple operations when debugging applications that use
758 a language currently not supported by GDB. */
759
760const struct language_defn minimal_language_defn =
761{
762 "minimal", /* Language name */
763 language_minimal,
e9667a65 764 NULL,
20a0e81d
JB
765 range_check_off,
766 type_check_off,
767 case_sensitive_on,
7ca2d3a3 768 array_row_major,
5f9769d1 769 &exp_descriptor_standard,
20a0e81d
JB
770 c_preprocess_and_parse,
771 c_error,
e85c3284 772 null_post_parser,
20a0e81d
JB
773 c_printchar, /* Print a character constant */
774 c_printstr, /* Function to print string constant */
775 c_emit_char, /* Print a single char */
776 c_create_fundamental_type, /* Create fundamental type in this language */
777 c_print_type, /* Print a type using appropriate syntax */
778 c_val_print, /* Print a value using appropriate syntax */
779 c_value_print, /* Print a top-level value */
780 NULL, /* Language specific skip_trampoline */
5f9a71c3
DC
781 NULL, /* value_of_this */
782 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 783 basic_lookup_transparent_type,/* lookup_transparent_type */
20a0e81d 784 NULL, /* Language specific symbol demangler */
31c27f77 785 NULL, /* Language specific class_name_from_physname */
20a0e81d
JB
786 c_op_print_tab, /* expression operators for printing */
787 1, /* c-style arrays */
788 0, /* String lower bound */
e9667a65 789 NULL,
6084f43a 790 default_word_break_characters,
e9667a65 791 c_language_arch_info,
e79af960 792 default_print_array_index,
20a0e81d
JB
793 LANG_MAGIC
794};
795
c906108c 796void
fba45db2 797_initialize_c_language (void)
c906108c
SS
798{
799 add_language (&c_language_defn);
800 add_language (&cplus_language_defn);
801 add_language (&asm_language_defn);
20a0e81d 802 add_language (&minimal_language_defn);
c906108c 803}