Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / d-lang.c
CommitLineData
6aecb9c2
JB
1/* D language support routines for GDB, the GNU debugger.
2
3666a048 3 Copyright (C) 2005-2021 Free Software Foundation, Inc.
6aecb9c2
JB
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"
d55e5aa6 21#include "symtab.h"
4de283e4 22#include "language.h"
d55e5aa6 23#include "varobj.h"
4de283e4
TT
24#include "d-lang.h"
25#include "c-lang.h"
26#include "demangle.h"
27#include "cp-support.h"
0d12e84c 28#include "gdbarch.h"
af30c400 29#include "parser-defs.h"
6aecb9c2 30
63778547
IB
31/* The name of the symbol to use to get the name of the main subprogram. */
32static const char D_MAIN[] = "D main";
33
34/* Function returning the special symbol name used by D for the main
35 procedure in the main program if it is found in minimal symbol list.
36 This function tries to find minimal symbols so that it finds them even
37 if the program was compiled without debugging information. */
38
39const char *
40d_main_name (void)
41{
3b7344d5 42 struct bound_minimal_symbol msym;
63778547
IB
43
44 msym = lookup_minimal_symbol (D_MAIN, NULL, NULL);
3b7344d5 45 if (msym.minsym != NULL)
63778547
IB
46 return D_MAIN;
47
48 /* No known entry procedure found, the main program is probably not D. */
49 return NULL;
50}
51
6aecb9c2 52/* Implements the la_demangle language_defn routine for language D. */
ec9f644a 53
6aecb9c2
JB
54char *
55d_demangle (const char *symbol, int options)
56{
35a49624 57 return gdb_demangle (symbol, options | DMGL_DLANG);
6aecb9c2
JB
58}
59
0874fd07
AB
60/* Class representing the D language. */
61
62class d_language : public language_defn
63{
64public:
65 d_language ()
0e25e767 66 : language_defn (language_d)
0874fd07 67 { /* Nothing. */ }
1fb314aa 68
6f7664a9
AB
69 /* See language.h. */
70
71 const char *name () const override
72 { return "d"; }
73
74 /* See language.h. */
75
76 const char *natural_name () const override
77 { return "D"; }
78
e171d6f1
AB
79 /* See language.h. */
80
81 const std::vector<const char *> &filename_extensions () const override
82 {
83 static const std::vector<const char *> extensions = { ".d" };
84 return extensions;
85 }
86
1fb314aa
AB
87 /* See language.h. */
88 void language_arch_info (struct gdbarch *gdbarch,
89 struct language_arch_info *lai) const override
90 {
91 const struct builtin_d_type *builtin = builtin_d_type (gdbarch);
92
7bea47f0
AB
93 /* Helper function to allow shorter lines below. */
94 auto add = [&] (struct type * t)
95 {
96 lai->add_primitive_type (t);
97 };
98
99 add (builtin->builtin_void);
100 add (builtin->builtin_bool);
101 add (builtin->builtin_byte);
102 add (builtin->builtin_ubyte);
103 add (builtin->builtin_short);
104 add (builtin->builtin_ushort);
105 add (builtin->builtin_int);
106 add (builtin->builtin_uint);
107 add (builtin->builtin_long);
108 add (builtin->builtin_ulong);
109 add (builtin->builtin_cent);
110 add (builtin->builtin_ucent);
111 add (builtin->builtin_float);
112 add (builtin->builtin_double);
113 add (builtin->builtin_real);
114 add (builtin->builtin_ifloat);
115 add (builtin->builtin_idouble);
116 add (builtin->builtin_ireal);
117 add (builtin->builtin_cfloat);
118 add (builtin->builtin_cdouble);
119 add (builtin->builtin_creal);
120 add (builtin->builtin_char);
121 add (builtin->builtin_wchar);
122 add (builtin->builtin_dchar);
123
124 lai->set_string_char_type (builtin->builtin_char);
125 lai->set_bool_type (builtin->builtin_bool, "bool");
1fb314aa 126 }
6f827019
AB
127
128 /* See language.h. */
129 bool sniff_from_mangled_name (const char *mangled,
130 char **demangled) const override
131 {
132 *demangled = d_demangle (mangled, 0);
133 return *demangled != NULL;
134 }
fbfb0a46
AB
135
136 /* See language.h. */
137
5399db93 138 char *demangle_symbol (const char *mangled, int options) const override
0a50df5d
AB
139 {
140 return d_demangle (mangled, options);
141 }
142
143 /* See language.h. */
144
fbfb0a46
AB
145 void print_type (struct type *type, const char *varstring,
146 struct ui_file *stream, int show, int level,
147 const struct type_print_options *flags) const override
148 {
149 c_print_type (type, varstring, stream, show, level, flags);
150 }
ebe2334e
AB
151
152 /* See language.h. */
153
154 void value_print_inner
155 (struct value *val, struct ui_file *stream, int recurse,
156 const struct value_print_options *options) const override
157 {
158 return d_value_print_inner (val, stream, recurse, options);
159 }
a78a19b1
AB
160
161 /* See language.h. */
162
163 struct block_symbol lookup_symbol_nonlocal
164 (const char *name, const struct block *block,
165 const domain_enum domain) const override
166 {
167 return d_lookup_symbol_nonlocal (this, name, block, domain);
168 }
87afa652
AB
169
170 /* See language.h. */
171
172 int parser (struct parser_state *ps) const override
173 {
174 return d_parse (ps);
175 }
5bae7c4e
AB
176
177 /* See language.h. */
178
179 const char *name_of_this () const override
180 { return "this"; }
0874fd07
AB
181};
182
183/* Single instance of the D language class. */
184
185static d_language d_language_defn;
186
94b1b47e
IB
187/* Build all D language types for the specified architecture. */
188
189static void *
190build_d_types (struct gdbarch *gdbarch)
191{
192 struct builtin_d_type *builtin_d_type
193 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_d_type);
194
195 /* Basic types. */
196 builtin_d_type->builtin_void
77b7c781 197 = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
94b1b47e
IB
198 builtin_d_type->builtin_bool
199 = arch_boolean_type (gdbarch, 8, 1, "bool");
200 builtin_d_type->builtin_byte
201 = arch_integer_type (gdbarch, 8, 0, "byte");
202 builtin_d_type->builtin_ubyte
203 = arch_integer_type (gdbarch, 8, 1, "ubyte");
204 builtin_d_type->builtin_short
205 = arch_integer_type (gdbarch, 16, 0, "short");
206 builtin_d_type->builtin_ushort
207 = arch_integer_type (gdbarch, 16, 1, "ushort");
208 builtin_d_type->builtin_int
209 = arch_integer_type (gdbarch, 32, 0, "int");
210 builtin_d_type->builtin_uint
211 = arch_integer_type (gdbarch, 32, 1, "uint");
212 builtin_d_type->builtin_long
213 = arch_integer_type (gdbarch, 64, 0, "long");
214 builtin_d_type->builtin_ulong
215 = arch_integer_type (gdbarch, 64, 1, "ulong");
216 builtin_d_type->builtin_cent
217 = arch_integer_type (gdbarch, 128, 0, "cent");
218 builtin_d_type->builtin_ucent
219 = arch_integer_type (gdbarch, 128, 1, "ucent");
220 builtin_d_type->builtin_float
221 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
49f190bc 222 "float", gdbarch_float_format (gdbarch));
94b1b47e
IB
223 builtin_d_type->builtin_double
224 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
49f190bc 225 "double", gdbarch_double_format (gdbarch));
94b1b47e
IB
226 builtin_d_type->builtin_real
227 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
49f190bc 228 "real", gdbarch_long_double_format (gdbarch));
94b1b47e 229
314ad88d
PA
230 builtin_d_type->builtin_byte->set_instance_flags
231 (builtin_d_type->builtin_byte->instance_flags ()
232 | TYPE_INSTANCE_FLAG_NOTTEXT);
233
234 builtin_d_type->builtin_ubyte->set_instance_flags
235 (builtin_d_type->builtin_ubyte->instance_flags ()
236 | TYPE_INSTANCE_FLAG_NOTTEXT);
94b1b47e
IB
237
238 /* Imaginary and complex types. */
239 builtin_d_type->builtin_ifloat
240 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
49f190bc 241 "ifloat", gdbarch_float_format (gdbarch));
94b1b47e
IB
242 builtin_d_type->builtin_idouble
243 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
49f190bc 244 "idouble", gdbarch_double_format (gdbarch));
94b1b47e
IB
245 builtin_d_type->builtin_ireal
246 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
49f190bc 247 "ireal", gdbarch_long_double_format (gdbarch));
94b1b47e 248 builtin_d_type->builtin_cfloat
5b930b45 249 = init_complex_type ("cfloat", builtin_d_type->builtin_float);
94b1b47e 250 builtin_d_type->builtin_cdouble
5b930b45 251 = init_complex_type ("cdouble", builtin_d_type->builtin_double);
94b1b47e 252 builtin_d_type->builtin_creal
5b930b45 253 = init_complex_type ("creal", builtin_d_type->builtin_real);
94b1b47e
IB
254
255 /* Character types. */
256 builtin_d_type->builtin_char
257 = arch_character_type (gdbarch, 8, 1, "char");
258 builtin_d_type->builtin_wchar
259 = arch_character_type (gdbarch, 16, 1, "wchar");
260 builtin_d_type->builtin_dchar
261 = arch_character_type (gdbarch, 32, 1, "dchar");
262
263 return builtin_d_type;
264}
265
266static struct gdbarch_data *d_type_data;
267
268/* Return the D type table for the specified architecture. */
269
270const struct builtin_d_type *
271builtin_d_type (struct gdbarch *gdbarch)
272{
9a3c8263 273 return (const struct builtin_d_type *) gdbarch_data (gdbarch, d_type_data);
94b1b47e
IB
274}
275
6c265988 276void _initialize_d_language ();
6aecb9c2 277void
6c265988 278_initialize_d_language ()
6aecb9c2 279{
94b1b47e 280 d_type_data = gdbarch_data_register_post_init (build_d_types);
6aecb9c2 281}
This page took 0.812205 seconds and 4 git commands to generate.