1 /* D language support routines for GDB, the GNU debugger.
3 Copyright (C) 2005-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
27 #include "parser-defs.h"
28 #include "gdb_obstack.h"
32 /* The name of the symbol to use to get the name of the main subprogram. */
33 static const char D_MAIN[] = "D main";
35 /* Function returning the special symbol name used by D for the main
36 procedure in the main program if it is found in minimal symbol list.
37 This function tries to find minimal symbols so that it finds them even
38 if the program was compiled without debugging information. */
43 struct minimal_symbol *msym;
45 msym = lookup_minimal_symbol (D_MAIN, NULL, NULL);
49 /* No known entry procedure found, the main program is probably not D. */
53 /* Extract identifiers from MANGLED_STR and append it to TEMPBUF.
54 Return 1 on success or 0 on failure. */
56 extract_identifiers (const char *mangled_str, struct obstack *tempbuf)
60 while (isdigit (*mangled_str))
64 i = strtol (mangled_str, &end_ptr, 10);
65 mangled_str = end_ptr;
66 if (i <= 0 || strlen (mangled_str) < i)
68 obstack_grow (tempbuf, mangled_str, i);
70 obstack_grow_str (tempbuf, ".");
72 if (*mangled_str == '\0' || i == 0)
74 obstack_blank (tempbuf, -1);
78 /* Extract and demangle type from MANGLED_STR and append it to TEMPBUF.
79 Return 1 on success or 0 on failure. */
81 extract_type_info (const char *mangled_str, struct obstack *tempbuf)
83 if (*mangled_str == '\0')
85 switch (*mangled_str++)
87 case 'A': /* dynamic array */
88 case 'G': /* static array */
89 case 'H': /* associative array */
90 if (!extract_type_info (mangled_str, tempbuf))
92 obstack_grow_str (tempbuf, "[]");
94 case 'P': /* pointer */
95 if (!extract_type_info (mangled_str, tempbuf))
97 obstack_grow_str (tempbuf, "*");
99 case 'R': /* reference */
100 if (!extract_type_info (mangled_str, tempbuf))
102 obstack_grow_str (tempbuf, "&");
104 case 'Z': /* return value */
105 return extract_type_info (mangled_str, tempbuf);
107 obstack_grow_str (tempbuf, "out ");
108 return extract_type_info (mangled_str, tempbuf);
109 case 'K': /* inout */
110 obstack_grow_str (tempbuf, "inout ");
111 return extract_type_info (mangled_str, tempbuf);
113 case 'T': /* typedef */
114 case 'D': /* delegate */
115 case 'C': /* class */
116 case 'S': /* struct */
117 return extract_identifiers (mangled_str, tempbuf);
120 case 'n': obstack_grow_str (tempbuf, "none"); return 1;
121 case 'v': obstack_grow_str (tempbuf, "void"); return 1;
122 case 'g': obstack_grow_str (tempbuf, "byte"); return 1;
123 case 'h': obstack_grow_str (tempbuf, "ubyte"); return 1;
124 case 's': obstack_grow_str (tempbuf, "short"); return 1;
125 case 't': obstack_grow_str (tempbuf, "ushort"); return 1;
126 case 'i': obstack_grow_str (tempbuf, "int"); return 1;
127 case 'k': obstack_grow_str (tempbuf, "uint"); return 1;
128 case 'l': obstack_grow_str (tempbuf, "long"); return 1;
129 case 'm': obstack_grow_str (tempbuf, "ulong"); return 1;
130 case 'f': obstack_grow_str (tempbuf, "float"); return 1;
131 case 'd': obstack_grow_str (tempbuf, "double"); return 1;
132 case 'e': obstack_grow_str (tempbuf, "real"); return 1;
134 /* imaginary and complex: */
135 case 'o': obstack_grow_str (tempbuf, "ifloat"); return 1;
136 case 'p': obstack_grow_str (tempbuf, "idouble"); return 1;
137 case 'j': obstack_grow_str (tempbuf, "ireal"); return 1;
138 case 'q': obstack_grow_str (tempbuf, "cfloat"); return 1;
139 case 'r': obstack_grow_str (tempbuf, "cdouble"); return 1;
140 case 'c': obstack_grow_str (tempbuf, "creal"); return 1;
143 case 'b': obstack_grow_str (tempbuf, "bit"); return 1;
144 case 'a': obstack_grow_str (tempbuf, "char"); return 1;
145 case 'u': obstack_grow_str (tempbuf, "wchar"); return 1;
146 case 'w': obstack_grow_str (tempbuf, "dchar"); return 1;
149 obstack_grow_str (tempbuf, "unknown");
154 /* Implements the la_demangle language_defn routine for language D. */
156 d_demangle (const char *symbol, int options)
158 struct obstack tempbuf;
160 unsigned char is_func = 0;
164 else if (strcmp (symbol, "_Dmain") == 0)
165 return xstrdup ("D main");
167 obstack_init (&tempbuf);
169 if (symbol[0] == '_' && symbol[1] == 'D')
174 else if (strncmp (symbol, "__Class_", 8) == 0)
176 else if (strncmp (symbol, "__init_", 7) == 0)
178 else if (strncmp (symbol, "__vtbl_", 7) == 0)
180 else if (strncmp (symbol, "__modctor_", 10) == 0)
182 else if (strncmp (symbol, "__moddtor_", 10) == 0)
184 else if (strncmp (symbol, "__ModuleInfo_", 13) == 0)
188 obstack_free (&tempbuf, NULL);
192 if (!extract_identifiers (symbol, &tempbuf))
194 obstack_free (&tempbuf, NULL);
198 obstack_grow_str (&tempbuf, "(");
199 if (is_func == 1 && *symbol == 'F')
202 while (*symbol != '\0' && *symbol != 'Z')
207 obstack_grow_str (&tempbuf, ", ");
208 if (!extract_type_info (symbol, &tempbuf))
210 obstack_free (&tempbuf, NULL);
215 obstack_grow_str0 (&tempbuf, ")");
217 /* Doesn't display the return type, but wouldn't be too hard to do. */
219 out_str = xstrdup (obstack_finish (&tempbuf));
220 obstack_free (&tempbuf, NULL);
224 /* Table mapping opcodes into strings for printing operators
225 and precedences of the operators. */
226 static const struct op_print d_op_print_tab[] =
228 {",", BINOP_COMMA, PREC_COMMA, 0},
229 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
230 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
231 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
232 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
233 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
234 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
235 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
236 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
237 {"<=", BINOP_LEQ, PREC_ORDER, 0},
238 {">=", BINOP_GEQ, PREC_ORDER, 0},
239 {">", BINOP_GTR, PREC_ORDER, 0},
240 {"<", BINOP_LESS, PREC_ORDER, 0},
241 {">>", BINOP_RSH, PREC_SHIFT, 0},
242 {"<<", BINOP_LSH, PREC_SHIFT, 0},
243 {"+", BINOP_ADD, PREC_ADD, 0},
244 {"-", BINOP_SUB, PREC_ADD, 0},
245 {"*", BINOP_MUL, PREC_MUL, 0},
246 {"/", BINOP_DIV, PREC_MUL, 0},
247 {"%", BINOP_REM, PREC_MUL, 0},
248 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
249 {"-", UNOP_NEG, PREC_PREFIX, 0},
250 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
251 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
252 {"*", UNOP_IND, PREC_PREFIX, 0},
253 {"&", UNOP_ADDR, PREC_PREFIX, 0},
254 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
255 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
256 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
260 static const struct language_defn d_language_defn =
273 c_printchar, /* Print a character constant. */
274 c_printstr, /* Function to print string constant. */
275 c_emit_char, /* Print a single char. */
276 c_print_type, /* Print a type using appropriate syntax. */
277 c_print_typedef, /* Print a typedef using appropriate
279 d_val_print, /* Print a value using appropriate syntax. */
280 c_value_print, /* Print a top-level value. */
281 default_read_var_value, /* la_read_var_value */
282 NULL, /* Language specific skip_trampoline. */
284 basic_lookup_symbol_nonlocal,
285 basic_lookup_transparent_type,
286 d_demangle, /* Language specific symbol demangler. */
287 NULL, /* Language specific
288 class_name_from_physname. */
289 d_op_print_tab, /* Expression operators for printing. */
290 1, /* C-style arrays. */
291 0, /* String lower bound. */
292 default_word_break_characters,
293 default_make_symbol_completion_list,
294 c_language_arch_info,
295 default_print_array_index,
296 default_pass_by_reference,
298 NULL, /* la_get_symbol_name_cmp */
299 iterate_over_symbols,
304 /* Provide a prototype to silence -Wmissing-prototypes. */
305 extern initialize_file_ftype _initialize_d_language;
308 _initialize_d_language (void)
310 add_language (&d_language_defn);