9c5eeadf07ab06a6140c681812e54567ace24dea
[deliverable/binutils-gdb.git] / gdb / d-lang.c
1 /* D language support routines for GDB, the GNU debugger.
2
3 Copyright (C) 2005-2014 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "language.h"
23 #include "varobj.h"
24 #include "d-lang.h"
25 #include "c-lang.h"
26 #include "parser-defs.h"
27 #include "gdb_obstack.h"
28
29 #include "safe-ctype.h"
30
31 static const char *parse_function_args (struct obstack *, const char *);
32 static const char *parse_type (struct obstack *, const char *);
33
34 /* The name of the symbol to use to get the name of the main subprogram. */
35 static const char D_MAIN[] = "D main";
36
37 /* Function returning the special symbol name used by D for the main
38 procedure in the main program if it is found in minimal symbol list.
39 This function tries to find minimal symbols so that it finds them even
40 if the program was compiled without debugging information. */
41
42 const char *
43 d_main_name (void)
44 {
45 struct minimal_symbol *msym;
46
47 msym = lookup_minimal_symbol (D_MAIN, NULL, NULL);
48 if (msym != NULL)
49 return D_MAIN;
50
51 /* No known entry procedure found, the main program is probably not D. */
52 return NULL;
53 }
54
55 /* Demangle the calling convention from MANGLE and append it to TEMPBUF.
56 Return the remaining string on success or NULL on failure. */
57
58 static const char *
59 parse_call_convention (struct obstack *tempbuf, const char *mangle)
60 {
61 if ((mangle == NULL) || (*mangle == '\0'))
62 return mangle;
63
64 switch (*mangle)
65 {
66 case 'F': /* (D) */
67 mangle++;
68 break;
69 case 'U': /* (C) */
70 mangle++;
71 obstack_grow_str (tempbuf, "extern(C) ");
72 break;
73 case 'W': /* (Windows) */
74 mangle++;
75 obstack_grow_str (tempbuf, "extern(Windows) ");
76 break;
77 case 'V': /* (Pascal) */
78 mangle++;
79 obstack_grow_str (tempbuf, "extern(Pascal) ");
80 break;
81 case 'R': /* (C++) */
82 mangle++;
83 obstack_grow_str (tempbuf, "extern(C++) ");
84 break;
85 default:
86 return NULL;
87 }
88
89 return mangle;
90 }
91
92 /* Demangle the D function attributes from MANGLE and append it to TEMPBUF.
93 Return the remaining string on success or NULL on failure. */
94
95 static const char *
96 parse_attributes (struct obstack *tempbuf, const char *mangle)
97 {
98 if ((mangle == NULL) || (*mangle == '\0'))
99 return mangle;
100
101 while (*mangle == 'N')
102 {
103 mangle++;
104 switch (*mangle)
105 {
106 case 'a': /* pure */
107 mangle++;
108 obstack_grow_str (tempbuf, "pure ");
109 continue;
110 case 'b': /* nothrow */
111 mangle++;
112 obstack_grow_str (tempbuf, "nothrow ");
113 continue;
114 case 'c': /* ref */
115 mangle++;
116 obstack_grow_str (tempbuf, "ref ");
117 continue;
118 case 'd': /* @property */
119 mangle++;
120 obstack_grow_str (tempbuf, "@property ");
121 continue;
122 case 'e': /* @trusted */
123 mangle++;
124 obstack_grow_str (tempbuf, "@trusted ");
125 continue;
126 case 'f': /* @safe */
127 mangle++;
128 obstack_grow_str (tempbuf, "@safe ");
129 continue;
130 case 'g':
131 case 'h':
132 /* inout parameter is represented as 'Ng'.
133 vector parameter is represented as 'Nh'.
134 If we see this, then we know we're really in the
135 parameter list. Rewind and break. */
136 mangle--;
137 }
138 break;
139 }
140 return mangle;
141 }
142
143 /* Demangle the function type from MANGLE and append it to TEMPBUF.
144 Return the remaining string on success or NULL on failure. */
145
146 static const char *
147 parse_function_type (struct obstack *tempbuf, const char *mangle)
148 {
149 struct obstack obattr, obargs, obtype;
150 char *attr, *args, *type;
151 size_t szattr, szargs, sztype;
152
153 if ((mangle == NULL) || (*mangle == '\0'))
154 return mangle;
155
156 /* The order of the mangled string is:
157 TypeFunction ::
158 CallConvention FuncAttrs Arguments ArgClose Type
159
160 The demangled string is re-ordered as:
161 CallConvention Type Arguments FuncAttrs
162 */
163 obstack_init (&obattr);
164 obstack_init (&obargs);
165 obstack_init (&obtype);
166
167 /* Function call convention. */
168 mangle = parse_call_convention (tempbuf, mangle);
169
170 /* Function attributes. */
171 mangle = parse_attributes (&obattr, mangle);
172 szattr = obstack_object_size (&obattr);
173 attr = obstack_finish (&obattr);
174
175 /* Function arguments. */
176 mangle = parse_function_args (&obargs, mangle);
177 szargs = obstack_object_size (&obargs);
178 args = obstack_finish (&obargs);
179
180 /* Function return type. */
181 mangle = parse_type (&obtype, mangle);
182 sztype = obstack_object_size (&obtype);
183 type = obstack_finish (&obtype);
184
185 /* Append to buffer in order. */
186 obstack_grow (tempbuf, type, sztype);
187 obstack_grow_str (tempbuf, "(");
188 obstack_grow (tempbuf, args, szargs);
189 obstack_grow_str (tempbuf, ") ");
190 obstack_grow (tempbuf, attr, szattr);
191
192 obstack_free (&obattr, NULL);
193 obstack_free (&obargs, NULL);
194 obstack_free (&obtype, NULL);
195 return mangle;
196 }
197
198 /* Demangle the argument list from MANGLE and append it to TEMPBUF.
199 Return the remaining string on success or NULL on failure. */
200
201 static const char *
202 parse_function_args (struct obstack *tempbuf, const char *mangle)
203 {
204 size_t n = 0;
205
206 while ((mangle != NULL) && (*mangle != '\0'))
207 {
208 switch (*mangle)
209 {
210 case 'X': /* (variadic T t...) style. */
211 mangle++;
212 obstack_grow_str (tempbuf, "...");
213 return mangle;
214 case 'Y': /* (variadic T t, ...) style. */
215 mangle++;
216 obstack_grow_str (tempbuf, ", ...");
217 return mangle;
218 case 'Z': /* Normal function. */
219 mangle++;
220 return mangle;
221 }
222
223 if (n++)
224 obstack_grow_str (tempbuf, ", ");
225
226 if (*mangle == 'M') /* scope(T) */
227 {
228 mangle++;
229 obstack_grow_str (tempbuf, "scope ");
230 }
231
232 switch (*mangle)
233 {
234 case 'J': /* out(T) */
235 mangle++;
236 obstack_grow_str (tempbuf, "out ");
237 break;
238 case 'K': /* ref(T) */
239 mangle++;
240 obstack_grow_str (tempbuf, "ref ");
241 break;
242 case 'L': /* lazy(T) */
243 mangle++;
244 obstack_grow_str (tempbuf, "lazy ");
245 break;
246 }
247 mangle = parse_type (tempbuf, mangle);
248 }
249 return mangle;
250 }
251
252 /* Demangle the type from MANGLE and append it to TEMPBUF.
253 Return the remaining string on success or NULL on failure. */
254
255 static const char *
256 parse_type (struct obstack *tempbuf, const char *mangle)
257 {
258 if ((mangle == NULL) || (*mangle == '\0'))
259 return mangle;
260
261 switch (*mangle)
262 {
263 case 'O': /* shared(T) */
264 mangle++;
265 obstack_grow_str (tempbuf, "shared(");
266 mangle = parse_type (tempbuf, mangle);
267 obstack_grow_str (tempbuf, ")");
268 return mangle;
269 case 'x': /* const(T) */
270 mangle++;
271 obstack_grow_str (tempbuf, "const(");
272 mangle = parse_type (tempbuf, mangle);
273 obstack_grow_str (tempbuf, ")");
274 return mangle;
275 case 'y': /* immutable(T) */
276 mangle++;
277 obstack_grow_str (tempbuf, "immutable(");
278 mangle = parse_type (tempbuf, mangle);
279 obstack_grow_str (tempbuf, ")");
280 return mangle;
281 case 'N':
282 mangle++;
283 if (*mangle == 'g') /* wild(T) */
284 {
285 mangle++;
286 obstack_grow_str (tempbuf, "inout(");
287 mangle = parse_type (tempbuf, mangle);
288 obstack_grow_str (tempbuf, ")");
289 return mangle;
290 }
291 else if (*mangle == 'h') /* vector(T) */
292 {
293 mangle++;
294 /* The basetype for vectors are always static arrays. */
295 if (*mangle != 'G')
296 return NULL;
297 obstack_grow_str (tempbuf, "__vector(");
298 mangle = parse_type (tempbuf, mangle);
299 obstack_grow_str (tempbuf, ")");
300 return mangle;
301 }
302 else
303 return NULL;
304 case 'A': /* dynamic array (T[]) */
305 mangle++;
306 mangle = parse_type (tempbuf, mangle);
307 obstack_grow_str (tempbuf, "[]");
308 return mangle;
309 case 'G': /* static array (T[N]) */
310 {
311 const char *numptr;
312 size_t num = 0;
313 mangle++;
314
315 numptr = mangle;
316 while (ISDIGIT (*mangle))
317 {
318 num++;
319 mangle++;
320 }
321 mangle = parse_type (tempbuf, mangle);
322 obstack_grow_str (tempbuf, "[");
323 obstack_grow (tempbuf, numptr, num);
324 obstack_grow_str (tempbuf, "]");
325 return mangle;
326 }
327 case 'H': /* associative array (T[T]) */
328 {
329 struct obstack obtype;
330 char *type;
331 size_t sztype;
332 mangle++;
333
334 obstack_init (&obtype);
335 mangle = parse_type (&obtype, mangle);
336 sztype = obstack_object_size (&obtype);
337 type = obstack_finish (&obtype);
338
339 mangle = parse_type (tempbuf, mangle);
340 obstack_grow_str (tempbuf, "[");
341 obstack_grow (tempbuf, type, sztype);
342 obstack_grow_str (tempbuf, "]");
343
344 obstack_free (&obtype, NULL);
345 return mangle;
346 }
347 case 'P': /* pointer (T*) */
348 mangle++;
349 mangle = parse_type (tempbuf, mangle);
350 obstack_grow_str (tempbuf, "*");
351 return mangle;
352 case 'I': /* ident T */
353 case 'C': /* class T */
354 case 'S': /* struct T */
355 case 'E': /* enum T */
356 case 'T': /* typedef T */
357 mangle++;
358 return d_parse_symbol (tempbuf, mangle);
359 case 'D': /* delegate T */
360 mangle++;
361 mangle = parse_function_type (tempbuf, mangle);
362 obstack_grow_str (tempbuf, "delegate");
363 return mangle;
364 case 'B': /* tuple T */
365 /* TODO: Handle this. */
366 return NULL;
367
368 /* Function types */
369 case 'F': case 'U': case 'W':
370 case 'V': case 'R':
371 mangle = parse_function_type (tempbuf, mangle);
372 obstack_grow_str (tempbuf, "function");
373 return mangle;
374
375 /* Basic types */
376 case 'n':
377 mangle++;
378 obstack_grow_str (tempbuf, "none");
379 return mangle;
380 case 'v':
381 mangle++;
382 obstack_grow_str (tempbuf, "void");
383 return mangle;
384 case 'g':
385 mangle++;
386 obstack_grow_str (tempbuf, "byte");
387 return mangle;
388 case 'h':
389 mangle++;
390 obstack_grow_str (tempbuf, "ubyte");
391 return mangle;
392 case 's':
393 mangle++;
394 obstack_grow_str (tempbuf, "short");
395 return mangle;
396 case 't':
397 mangle++;
398 obstack_grow_str (tempbuf, "ushort");
399 return mangle;
400 case 'i':
401 mangle++;
402 obstack_grow_str (tempbuf, "int");
403 return mangle;
404 case 'k':
405 mangle++;
406 obstack_grow_str (tempbuf, "uint");
407 return mangle;
408 case 'l':
409 mangle++;
410 obstack_grow_str (tempbuf, "long");
411 return mangle;
412 case 'm':
413 mangle++;
414 obstack_grow_str (tempbuf, "ulong");
415 return mangle;
416 case 'f':
417 mangle++;
418 obstack_grow_str (tempbuf, "float");
419 return mangle;
420 case 'd':
421 mangle++;
422 obstack_grow_str (tempbuf, "double");
423 return mangle;
424 case 'e':
425 mangle++;
426 obstack_grow_str (tempbuf, "real");
427 return mangle;
428
429 /* Imaginary and Complex types */
430 case 'o':
431 mangle++;
432 obstack_grow_str (tempbuf, "ifloat");
433 return mangle;
434 case 'p':
435 mangle++;
436 obstack_grow_str (tempbuf, "idouble");
437 return mangle;
438 case 'j':
439 mangle++;
440 obstack_grow_str (tempbuf, "ireal");
441 return mangle;
442 case 'q':
443 mangle++;
444 obstack_grow_str (tempbuf, "cfloat");
445 return mangle;
446 case 'r':
447 mangle++;
448 obstack_grow_str (tempbuf, "cdouble");
449 return mangle;
450 case 'c':
451 mangle++;
452 obstack_grow_str (tempbuf, "creal");
453 return mangle;
454
455 /* Other types */
456 case 'b':
457 mangle++;
458 obstack_grow_str (tempbuf, "bool");
459 return mangle;
460 case 'a':
461 mangle++;
462 obstack_grow_str (tempbuf, "char");
463 return mangle;
464 case 'u':
465 mangle++;
466 obstack_grow_str (tempbuf, "wchar");
467 return mangle;
468 case 'w':
469 mangle++;
470 obstack_grow_str (tempbuf, "dchar");
471 return mangle;
472
473 default: /* unhandled */
474 return NULL;
475 }
476 }
477
478 /* Extract the identifier from MANGLE and append it to TEMPBUF.
479 Return the remaining string on success or NULL on failure. */
480
481 static const char *
482 parse_identifier (struct obstack *tempbuf, const char *mangle)
483 {
484 if ((mangle == NULL) || (*mangle == '\0'))
485 return mangle;
486
487 if (ISDIGIT (*mangle))
488 {
489 char *endptr;
490 long i = strtol (mangle, &endptr, 10);
491
492 if (i <= 0 || strlen (endptr) < i)
493 return NULL;
494
495 mangle = endptr;
496
497 /* No support for demangling templates. */
498 if (i >= 5 && strncmp (mangle, "__T", 3) == 0)
499 return NULL;
500
501 if (strncmp (mangle, "__ctor", i) == 0)
502 {
503 /* Constructor symbol for a class/struct. */
504 obstack_grow_str (tempbuf, "this");
505 mangle += i;
506 return mangle;
507 }
508 else if (strncmp (mangle, "__dtor", i) == 0)
509 {
510 /* Destructor symbol for a class/struct. */
511 obstack_grow_str (tempbuf, "~this");
512 mangle += i;
513 return mangle;
514 }
515 else if (strncmp (mangle, "__postblit", i) == 0)
516 {
517 /* Postblit symbol for a struct. */
518 obstack_grow_str (tempbuf, "this(this)");
519 mangle += i;
520 return mangle;
521 }
522 else if (strncmp (mangle, "__initZ", i+1) == 0)
523 {
524 /* The static initialiser for a given symbol. */
525 obstack_grow_str (tempbuf, "init$");
526 mangle += i + 1;
527 return mangle;
528 }
529 else if (strncmp (mangle, "__ClassZ", i+1) == 0)
530 {
531 /* The classinfo symbol for a given class. */
532 obstack_grow_str (tempbuf, "classinfo$");
533 mangle += i + 1;
534 return mangle;
535 }
536 else if (strncmp (mangle, "__vtblZ", i+1) == 0)
537 {
538 /* The vtable symbol for a given class. */
539 obstack_grow_str (tempbuf, "vtbl$");
540 mangle += i + 1;
541 return mangle;
542 }
543 else if (strncmp (mangle, "__InterfaceZ", i+1) == 0)
544 {
545 /* The interface symbol for a given class. */
546 obstack_grow_str (tempbuf, "interface$");
547 mangle += i + 1;
548 return mangle;
549 }
550 else if (strncmp (mangle, "__ModuleInfoZ", i+1) == 0)
551 {
552 /* The ModuleInfo symbol for a given module. */
553 obstack_grow_str (tempbuf, "moduleinfo$");
554 mangle += i + 1;
555 return mangle;
556 }
557 obstack_grow (tempbuf, mangle, i);
558 mangle += i;
559 }
560 else
561 return NULL;
562
563 return mangle;
564 }
565
566 /* Test whether the current position of MANGLE is pointing to the
567 beginning of a mangled function parameter list, which starts with
568 the calling convention. Returns 1 on success or 0 on failure. */
569
570 static int
571 call_convention_p (const char *mangle)
572 {
573 size_t i;
574
575 if ((mangle == NULL) || (*mangle == '\0'))
576 return 0;
577
578 switch (*mangle)
579 {
580 case 'F': case 'U': case 'V':
581 case 'W': case 'R':
582 return 1;
583
584 case 'M': /* Prefix for functions needing 'this'. */
585 i = 1;
586 if (mangle[i] == 'x')
587 i++;
588
589 switch (mangle[i])
590 {
591 case 'F': case 'U': case 'V':
592 case 'W': case 'R':
593 return 1;
594 }
595
596 default:
597 return 0;
598 }
599 }
600
601 /* Extract and demangle the symbol in MANGLE and append it to TEMPBUF.
602 Return the remaining signature on success or NULL on failure. */
603
604 const char *
605 d_parse_symbol (struct obstack *tempbuf, const char *mangle)
606 {
607 size_t n = 0;
608 do
609 {
610 if (n++)
611 obstack_grow_str (tempbuf, ".");
612
613 mangle = parse_identifier (tempbuf, mangle);
614
615 if (call_convention_p (mangle))
616 {
617 char *saved;
618
619 /* Skip over 'this' parameter. */
620 if (*mangle == 'M')
621 mangle += (mangle[1] == 'x') ? 2 : 1;
622
623 /* Skip over calling convention and attributes in qualified name. */
624 saved = obstack_next_free (tempbuf);
625 mangle = parse_call_convention (tempbuf, mangle);
626 mangle = parse_attributes (tempbuf, mangle);
627 obstack_next_free (tempbuf) = saved;
628
629 obstack_grow_str (tempbuf, "(");
630 mangle = parse_function_args (tempbuf, mangle);
631 obstack_grow_str (tempbuf, ")");
632
633 /* Demangle the function return type as a kind of sanity test. */
634 if ((mangle != NULL) && !ISDIGIT (*mangle))
635 {
636 saved = obstack_next_free (tempbuf);
637 mangle = parse_type (tempbuf, mangle);
638 obstack_next_free (tempbuf) = saved;
639 }
640 }
641 }
642 while ((mangle != NULL) && ISDIGIT (*mangle));
643
644 return mangle;
645 }
646
647 /* Implements the la_demangle language_defn routine for language D. */
648
649 char *
650 d_demangle (const char *symbol, int options)
651 {
652 struct obstack tempbuf;
653 char *result;
654
655 if ((symbol == NULL) || (*symbol == '\0'))
656 return NULL;
657 else if (strcmp (symbol, "_Dmain") == 0)
658 return xstrdup ("D main");
659
660 obstack_init (&tempbuf);
661
662 if (strncmp (symbol, "_D", 2) == 0)
663 symbol += 2;
664 else
665 {
666 obstack_free (&tempbuf, NULL);
667 return NULL;
668 }
669
670 if (d_parse_symbol (&tempbuf, symbol) != NULL)
671 {
672 obstack_grow_str0 (&tempbuf, "");
673 result = xstrdup (obstack_finish (&tempbuf));
674 obstack_free (&tempbuf, NULL);
675 }
676 else
677 {
678 obstack_free (&tempbuf, NULL);
679 return NULL;
680 }
681
682 return result;
683 }
684
685 /* Table mapping opcodes into strings for printing operators
686 and precedences of the operators. */
687 static const struct op_print d_op_print_tab[] =
688 {
689 {",", BINOP_COMMA, PREC_COMMA, 0},
690 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
691 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
692 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
693 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
694 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
695 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
696 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
697 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
698 {"<=", BINOP_LEQ, PREC_ORDER, 0},
699 {">=", BINOP_GEQ, PREC_ORDER, 0},
700 {">", BINOP_GTR, PREC_ORDER, 0},
701 {"<", BINOP_LESS, PREC_ORDER, 0},
702 {">>", BINOP_RSH, PREC_SHIFT, 0},
703 {"<<", BINOP_LSH, PREC_SHIFT, 0},
704 {"+", BINOP_ADD, PREC_ADD, 0},
705 {"-", BINOP_SUB, PREC_ADD, 0},
706 {"*", BINOP_MUL, PREC_MUL, 0},
707 {"/", BINOP_DIV, PREC_MUL, 0},
708 {"%", BINOP_REM, PREC_MUL, 0},
709 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
710 {"-", UNOP_NEG, PREC_PREFIX, 0},
711 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
712 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
713 {"*", UNOP_IND, PREC_PREFIX, 0},
714 {"&", UNOP_ADDR, PREC_PREFIX, 0},
715 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
716 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
717 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
718 {NULL, 0, 0, 0}
719 };
720
721 /* Mapping of all D basic data types into the language vector. */
722
723 enum d_primitive_types {
724 d_primitive_type_void,
725 d_primitive_type_bool,
726 d_primitive_type_byte,
727 d_primitive_type_ubyte,
728 d_primitive_type_short,
729 d_primitive_type_ushort,
730 d_primitive_type_int,
731 d_primitive_type_uint,
732 d_primitive_type_long,
733 d_primitive_type_ulong,
734 d_primitive_type_cent, /* Signed 128 bit integer. */
735 d_primitive_type_ucent, /* Unsigned 128 bit integer. */
736 d_primitive_type_float,
737 d_primitive_type_double,
738 d_primitive_type_real,
739 d_primitive_type_ifloat, /* Imaginary float types. */
740 d_primitive_type_idouble,
741 d_primitive_type_ireal,
742 d_primitive_type_cfloat, /* Complex number of two float values. */
743 d_primitive_type_cdouble,
744 d_primitive_type_creal,
745 d_primitive_type_char, /* Unsigned character types. */
746 d_primitive_type_wchar,
747 d_primitive_type_dchar,
748 nr_d_primitive_types
749 };
750
751 /* Implements the la_language_arch_info language_defn routine
752 for language D. */
753
754 static void
755 d_language_arch_info (struct gdbarch *gdbarch,
756 struct language_arch_info *lai)
757 {
758 const struct builtin_d_type *builtin = builtin_d_type (gdbarch);
759
760 lai->string_char_type = builtin->builtin_char;
761 lai->primitive_type_vector
762 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_d_primitive_types + 1,
763 struct type *);
764
765 lai->primitive_type_vector [d_primitive_type_void]
766 = builtin->builtin_void;
767 lai->primitive_type_vector [d_primitive_type_bool]
768 = builtin->builtin_bool;
769 lai->primitive_type_vector [d_primitive_type_byte]
770 = builtin->builtin_byte;
771 lai->primitive_type_vector [d_primitive_type_ubyte]
772 = builtin->builtin_ubyte;
773 lai->primitive_type_vector [d_primitive_type_short]
774 = builtin->builtin_short;
775 lai->primitive_type_vector [d_primitive_type_ushort]
776 = builtin->builtin_ushort;
777 lai->primitive_type_vector [d_primitive_type_int]
778 = builtin->builtin_int;
779 lai->primitive_type_vector [d_primitive_type_uint]
780 = builtin->builtin_uint;
781 lai->primitive_type_vector [d_primitive_type_long]
782 = builtin->builtin_long;
783 lai->primitive_type_vector [d_primitive_type_ulong]
784 = builtin->builtin_ulong;
785 lai->primitive_type_vector [d_primitive_type_cent]
786 = builtin->builtin_cent;
787 lai->primitive_type_vector [d_primitive_type_ucent]
788 = builtin->builtin_ucent;
789 lai->primitive_type_vector [d_primitive_type_float]
790 = builtin->builtin_float;
791 lai->primitive_type_vector [d_primitive_type_double]
792 = builtin->builtin_double;
793 lai->primitive_type_vector [d_primitive_type_real]
794 = builtin->builtin_real;
795 lai->primitive_type_vector [d_primitive_type_ifloat]
796 = builtin->builtin_ifloat;
797 lai->primitive_type_vector [d_primitive_type_idouble]
798 = builtin->builtin_idouble;
799 lai->primitive_type_vector [d_primitive_type_ireal]
800 = builtin->builtin_ireal;
801 lai->primitive_type_vector [d_primitive_type_cfloat]
802 = builtin->builtin_cfloat;
803 lai->primitive_type_vector [d_primitive_type_cdouble]
804 = builtin->builtin_cdouble;
805 lai->primitive_type_vector [d_primitive_type_creal]
806 = builtin->builtin_creal;
807 lai->primitive_type_vector [d_primitive_type_char]
808 = builtin->builtin_char;
809 lai->primitive_type_vector [d_primitive_type_wchar]
810 = builtin->builtin_wchar;
811 lai->primitive_type_vector [d_primitive_type_dchar]
812 = builtin->builtin_dchar;
813
814 lai->bool_type_symbol = "bool";
815 lai->bool_type_default = builtin->builtin_bool;
816 }
817
818 static const struct language_defn d_language_defn =
819 {
820 "d",
821 "D",
822 language_d,
823 range_check_off,
824 case_sensitive_on,
825 array_row_major,
826 macro_expansion_no,
827 &exp_descriptor_c,
828 c_parse,
829 c_error,
830 null_post_parser,
831 c_printchar, /* Print a character constant. */
832 c_printstr, /* Function to print string constant. */
833 c_emit_char, /* Print a single char. */
834 c_print_type, /* Print a type using appropriate syntax. */
835 c_print_typedef, /* Print a typedef using appropriate
836 syntax. */
837 d_val_print, /* Print a value using appropriate syntax. */
838 c_value_print, /* Print a top-level value. */
839 default_read_var_value, /* la_read_var_value */
840 NULL, /* Language specific skip_trampoline. */
841 "this",
842 basic_lookup_symbol_nonlocal,
843 basic_lookup_transparent_type,
844 d_demangle, /* Language specific symbol demangler. */
845 NULL, /* Language specific
846 class_name_from_physname. */
847 d_op_print_tab, /* Expression operators for printing. */
848 1, /* C-style arrays. */
849 0, /* String lower bound. */
850 default_word_break_characters,
851 default_make_symbol_completion_list,
852 d_language_arch_info,
853 default_print_array_index,
854 default_pass_by_reference,
855 c_get_string,
856 NULL, /* la_get_symbol_name_cmp */
857 iterate_over_symbols,
858 &default_varobj_ops,
859 LANG_MAGIC
860 };
861
862 /* Build all D language types for the specified architecture. */
863
864 static void *
865 build_d_types (struct gdbarch *gdbarch)
866 {
867 struct builtin_d_type *builtin_d_type
868 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_d_type);
869
870 /* Basic types. */
871 builtin_d_type->builtin_void
872 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
873 builtin_d_type->builtin_bool
874 = arch_boolean_type (gdbarch, 8, 1, "bool");
875 builtin_d_type->builtin_byte
876 = arch_integer_type (gdbarch, 8, 0, "byte");
877 builtin_d_type->builtin_ubyte
878 = arch_integer_type (gdbarch, 8, 1, "ubyte");
879 builtin_d_type->builtin_short
880 = arch_integer_type (gdbarch, 16, 0, "short");
881 builtin_d_type->builtin_ushort
882 = arch_integer_type (gdbarch, 16, 1, "ushort");
883 builtin_d_type->builtin_int
884 = arch_integer_type (gdbarch, 32, 0, "int");
885 builtin_d_type->builtin_uint
886 = arch_integer_type (gdbarch, 32, 1, "uint");
887 builtin_d_type->builtin_long
888 = arch_integer_type (gdbarch, 64, 0, "long");
889 builtin_d_type->builtin_ulong
890 = arch_integer_type (gdbarch, 64, 1, "ulong");
891 builtin_d_type->builtin_cent
892 = arch_integer_type (gdbarch, 128, 0, "cent");
893 builtin_d_type->builtin_ucent
894 = arch_integer_type (gdbarch, 128, 1, "ucent");
895 builtin_d_type->builtin_float
896 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
897 "float", NULL);
898 builtin_d_type->builtin_double
899 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
900 "double", NULL);
901 builtin_d_type->builtin_real
902 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
903 "real", NULL);
904
905 TYPE_INSTANCE_FLAGS (builtin_d_type->builtin_byte)
906 |= TYPE_INSTANCE_FLAG_NOTTEXT;
907 TYPE_INSTANCE_FLAGS (builtin_d_type->builtin_ubyte)
908 |= TYPE_INSTANCE_FLAG_NOTTEXT;
909
910 /* Imaginary and complex types. */
911 builtin_d_type->builtin_ifloat
912 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
913 "ifloat", NULL);
914 builtin_d_type->builtin_idouble
915 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
916 "idouble", NULL);
917 builtin_d_type->builtin_ireal
918 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
919 "ireal", NULL);
920 builtin_d_type->builtin_cfloat
921 = arch_complex_type (gdbarch, "cfloat",
922 builtin_d_type->builtin_float);
923 builtin_d_type->builtin_cdouble
924 = arch_complex_type (gdbarch, "cdouble",
925 builtin_d_type->builtin_double);
926 builtin_d_type->builtin_creal
927 = arch_complex_type (gdbarch, "creal",
928 builtin_d_type->builtin_real);
929
930 /* Character types. */
931 builtin_d_type->builtin_char
932 = arch_character_type (gdbarch, 8, 1, "char");
933 builtin_d_type->builtin_wchar
934 = arch_character_type (gdbarch, 16, 1, "wchar");
935 builtin_d_type->builtin_dchar
936 = arch_character_type (gdbarch, 32, 1, "dchar");
937
938 return builtin_d_type;
939 }
940
941 static struct gdbarch_data *d_type_data;
942
943 /* Return the D type table for the specified architecture. */
944
945 const struct builtin_d_type *
946 builtin_d_type (struct gdbarch *gdbarch)
947 {
948 return gdbarch_data (gdbarch, d_type_data);
949 }
950
951 /* Provide a prototype to silence -Wmissing-prototypes. */
952 extern initialize_file_ftype _initialize_d_language;
953
954 void
955 _initialize_d_language (void)
956 {
957 d_type_data = gdbarch_data_register_post_init (build_d_types);
958
959 add_language (&d_language_defn);
960 }
This page took 0.050281 seconds and 3 git commands to generate.