]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Fortran language support definitions for GDB, the GNU debugger. |
a2bd3dcd | 2 | |
3666a048 | 3 | Copyright (C) 1992-2021 Free Software Foundation, Inc. |
a2bd3dcd | 4 | |
c906108c SS |
5 | Contributed by Motorola. Adapted from the C definitions by Farooq Butt |
6 | ([email protected]). | |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 13 | (at your option) any later version. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b | 20 | You should have received a copy of the GNU General Public License |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 22 | |
1a5c2598 TT |
23 | #ifndef F_LANG_H |
24 | #define F_LANG_H | |
25 | ||
1a0ea399 AB |
26 | #include "valprint.h" |
27 | ||
79d43c61 | 28 | struct type_print_options; |
410a0ff2 | 29 | struct parser_state; |
79d43c61 | 30 | |
1a0ea399 AB |
31 | /* Class representing the Fortran language. */ |
32 | ||
33 | class f_language : public language_defn | |
34 | { | |
35 | public: | |
36 | f_language () | |
37 | : language_defn (language_fortran) | |
38 | { /* Nothing. */ } | |
39 | ||
40 | /* See language.h. */ | |
41 | ||
42 | const char *name () const override | |
43 | { return "fortran"; } | |
44 | ||
45 | /* See language.h. */ | |
46 | ||
47 | const char *natural_name () const override | |
48 | { return "Fortran"; } | |
49 | ||
50 | /* See language.h. */ | |
51 | ||
52 | const std::vector<const char *> &filename_extensions () const override | |
53 | { | |
54 | static const std::vector<const char *> extensions = { | |
55 | ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP", | |
56 | ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08" | |
57 | }; | |
58 | return extensions; | |
59 | } | |
60 | ||
61 | /* See language.h. */ | |
62 | void language_arch_info (struct gdbarch *gdbarch, | |
63 | struct language_arch_info *lai) const override; | |
64 | ||
65 | /* See language.h. */ | |
66 | unsigned int search_name_hash (const char *name) const override; | |
67 | ||
68 | /* See language.h. */ | |
69 | ||
70 | char *demangle_symbol (const char *mangled, int options) const override | |
71 | { | |
72 | /* We could support demangling here to provide module namespaces | |
73 | also for inferiors with only minimal symbol table (ELF symbols). | |
74 | Just the mangling standard is not standardized across compilers | |
75 | and there is no DW_AT_producer available for inferiors with only | |
76 | the ELF symbols to check the mangling kind. */ | |
77 | return nullptr; | |
78 | } | |
79 | ||
80 | /* See language.h. */ | |
81 | ||
82 | void print_type (struct type *type, const char *varstring, | |
83 | struct ui_file *stream, int show, int level, | |
84 | const struct type_print_options *flags) const override; | |
85 | ||
86 | /* See language.h. This just returns default set of word break | |
87 | characters but with the modules separator `::' removed. */ | |
88 | ||
89 | const char *word_break_characters (void) const override | |
90 | { | |
91 | static char *retval; | |
92 | ||
93 | if (!retval) | |
94 | { | |
95 | char *s; | |
96 | ||
97 | retval = xstrdup (language_defn::word_break_characters ()); | |
98 | s = strchr (retval, ':'); | |
99 | if (s) | |
100 | { | |
101 | char *last_char = &s[strlen (s) - 1]; | |
102 | ||
103 | *s = *last_char; | |
104 | *last_char = 0; | |
105 | } | |
106 | } | |
107 | return retval; | |
108 | } | |
109 | ||
110 | ||
111 | /* See language.h. */ | |
112 | ||
113 | void collect_symbol_completion_matches (completion_tracker &tracker, | |
114 | complete_symbol_mode mode, | |
115 | symbol_name_match_type name_match_type, | |
116 | const char *text, const char *word, | |
117 | enum type_code code) const override | |
118 | { | |
119 | /* Consider the modules separator :: as a valid symbol name character | |
120 | class. */ | |
121 | default_collect_symbol_completion_matches_break_on (tracker, mode, | |
122 | name_match_type, | |
123 | text, word, ":", | |
124 | code); | |
125 | } | |
126 | ||
127 | /* See language.h. */ | |
128 | ||
129 | void value_print_inner | |
130 | (struct value *val, struct ui_file *stream, int recurse, | |
131 | const struct value_print_options *options) const override; | |
132 | ||
133 | /* See language.h. */ | |
134 | ||
135 | struct block_symbol lookup_symbol_nonlocal | |
136 | (const char *name, const struct block *block, | |
137 | const domain_enum domain) const override; | |
138 | ||
139 | /* See language.h. */ | |
140 | ||
141 | int parser (struct parser_state *ps) const override; | |
142 | ||
143 | /* See language.h. */ | |
144 | ||
145 | void emitchar (int ch, struct type *chtype, | |
146 | struct ui_file *stream, int quoter) const override | |
147 | { | |
148 | const char *encoding = get_encoding (chtype); | |
149 | generic_emit_char (ch, chtype, stream, quoter, encoding); | |
150 | } | |
151 | ||
152 | /* See language.h. */ | |
153 | ||
154 | void printchar (int ch, struct type *chtype, | |
155 | struct ui_file *stream) const override | |
156 | { | |
157 | fputs_filtered ("'", stream); | |
76ca72bc | 158 | emitchar (ch, chtype, stream, '\''); |
1a0ea399 AB |
159 | fputs_filtered ("'", stream); |
160 | } | |
161 | ||
162 | /* See language.h. */ | |
163 | ||
164 | void printstr (struct ui_file *stream, struct type *elttype, | |
165 | const gdb_byte *string, unsigned int length, | |
166 | const char *encoding, int force_ellipses, | |
167 | const struct value_print_options *options) const override | |
168 | { | |
169 | const char *type_encoding = get_encoding (elttype); | |
170 | ||
171 | if (TYPE_LENGTH (elttype) == 4) | |
172 | fputs_filtered ("4_", stream); | |
c906108c | 173 | |
1a0ea399 AB |
174 | if (!encoding || !*encoding) |
175 | encoding = type_encoding; | |
1f20c35e | 176 | |
1a0ea399 AB |
177 | generic_printstr (stream, elttype, string, length, encoding, |
178 | force_ellipses, '\'', 0, options); | |
179 | } | |
1f20c35e | 180 | |
1a0ea399 | 181 | /* See language.h. */ |
c906108c | 182 | |
1a0ea399 AB |
183 | void print_typedef (struct type *type, struct symbol *new_symbol, |
184 | struct ui_file *stream) const override; | |
24051bbe | 185 | |
1a0ea399 AB |
186 | /* See language.h. */ |
187 | ||
188 | bool is_string_type_p (struct type *type) const override | |
189 | { | |
190 | type = check_typedef (type); | |
191 | return (type->code () == TYPE_CODE_STRING | |
192 | || (type->code () == TYPE_CODE_ARRAY | |
193 | && TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_CHAR)); | |
194 | } | |
195 | ||
196 | /* See language.h. */ | |
197 | ||
198 | const char *struct_too_deep_ellipsis () const override | |
199 | { return "(...)"; } | |
200 | ||
201 | /* See language.h. */ | |
202 | ||
203 | bool c_style_arrays_p () const override | |
204 | { return false; } | |
205 | ||
206 | /* See language.h. */ | |
207 | ||
208 | bool range_checking_on_by_default () const override | |
209 | { return true; } | |
210 | ||
211 | /* See language.h. */ | |
212 | ||
213 | enum case_sensitivity case_sensitivity () const override | |
214 | { return case_sensitive_off; } | |
215 | ||
216 | /* See language.h. */ | |
217 | ||
218 | enum array_ordering array_ordering () const override | |
219 | { return array_column_major; } | |
220 | ||
1a0ea399 AB |
221 | protected: |
222 | ||
223 | /* See language.h. */ | |
224 | ||
225 | symbol_name_matcher_ftype *get_symbol_name_matcher_inner | |
226 | (const lookup_name_info &lookup_name) const override; | |
227 | ||
228 | private: | |
1a0ea399 AB |
229 | /* Return the encoding that should be used for the character type |
230 | TYPE. */ | |
231 | ||
232 | static const char *get_encoding (struct type *type); | |
233 | ||
234 | /* Print any asterisks or open-parentheses needed before the variable | |
235 | name (to describe its type). | |
236 | ||
237 | On outermost call, pass 0 for PASSED_A_PTR. | |
238 | On outermost call, SHOW > 0 means should ignore | |
239 | any typename for TYPE and show its details. | |
240 | SHOW is always zero on recursive calls. */ | |
241 | ||
242 | void f_type_print_varspec_prefix (struct type *type, | |
243 | struct ui_file * stream, | |
244 | int show, int passed_a_ptr) const; | |
245 | ||
246 | /* Print any array sizes, function arguments or close parentheses needed | |
247 | after the variable name (to describe its type). Args work like | |
248 | c_type_print_varspec_prefix. | |
249 | ||
250 | PRINT_RANK_ONLY is true when TYPE is an array which should be printed | |
251 | without the upper and lower bounds being specified, this will occur | |
252 | when the array is not allocated or not associated and so there are no | |
253 | known upper or lower bounds. */ | |
254 | ||
255 | void f_type_print_varspec_suffix (struct type *type, | |
256 | struct ui_file *stream, | |
257 | int show, int passed_a_ptr, | |
258 | int demangled_args, | |
259 | int arrayprint_recurse_level, | |
260 | bool print_rank_only) const; | |
261 | ||
262 | /* Print the name of the type (or the ultimate pointer target, function | |
263 | value or array element), or the description of a structure or union. | |
264 | ||
265 | SHOW nonzero means don't print this type as just its name; | |
266 | show its real definition even if it has a name. | |
267 | SHOW zero means print just typename or struct tag if there is one | |
268 | SHOW negative means abbreviate structure elements. | |
269 | SHOW is decremented for printing of structure elements. | |
270 | ||
271 | LEVEL is the depth to indent by. We increase it for some recursive | |
272 | calls. */ | |
273 | ||
274 | void f_type_print_base (struct type *type, struct ui_file *stream, int show, | |
275 | int level) const; | |
276 | }; | |
24051bbe | 277 | |
c5aa993b | 278 | /* Language-specific data structures */ |
c906108c | 279 | |
4357ac6c | 280 | /* A common block. */ |
c906108c | 281 | |
4357ac6c TT |
282 | struct common_block |
283 | { | |
284 | /* The number of entries in the block. */ | |
285 | size_t n_entries; | |
c906108c | 286 | |
4357ac6c TT |
287 | /* The contents of the block, allocated using the struct hack. All |
288 | pointers in the array are non-NULL. */ | |
289 | struct symbol *contents[1]; | |
290 | }; | |
c906108c | 291 | |
2880242d | 292 | extern LONGEST f77_get_upperbound (struct type *); |
c906108c | 293 | |
2880242d | 294 | extern LONGEST f77_get_lowerbound (struct type *); |
c906108c | 295 | |
a14ed312 | 296 | extern int calc_f77_array_dims (struct type *); |
4cca3ac9 | 297 | |
4cca3ac9 UW |
298 | /* Fortran (F77) types */ |
299 | ||
300 | struct builtin_f_type | |
301 | { | |
302 | struct type *builtin_character; | |
303 | struct type *builtin_integer; | |
304 | struct type *builtin_integer_s2; | |
067630bd | 305 | struct type *builtin_integer_s8; |
4cca3ac9 UW |
306 | struct type *builtin_logical; |
307 | struct type *builtin_logical_s1; | |
308 | struct type *builtin_logical_s2; | |
ce4b0682 | 309 | struct type *builtin_logical_s8; |
4cca3ac9 UW |
310 | struct type *builtin_real; |
311 | struct type *builtin_real_s8; | |
312 | struct type *builtin_real_s16; | |
313 | struct type *builtin_complex_s8; | |
314 | struct type *builtin_complex_s16; | |
315 | struct type *builtin_complex_s32; | |
316 | struct type *builtin_void; | |
317 | }; | |
318 | ||
319 | /* Return the Fortran type table for the specified architecture. */ | |
320 | extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch); | |
321 | ||
aa3cfbda RB |
322 | /* Ensures that function argument TYPE is appropriate to inform the debugger |
323 | that ARG should be passed as a pointer. Returns the potentially updated | |
324 | argument type. | |
325 | ||
326 | If ARG is of type pointer then the type of ARG is returned, otherwise | |
327 | TYPE is returned untouched. | |
328 | ||
329 | This function exists to augment the types of Fortran function call | |
330 | parameters to be pointers to the reported value, when the corresponding ARG | |
331 | has also been wrapped in a pointer (by fortran_argument_convert). This | |
332 | informs the debugger that these arguments should be passed as a pointer | |
333 | rather than as the pointed to type. */ | |
334 | ||
335 | extern struct type *fortran_preserve_arg_pointer (struct value *arg, | |
336 | struct type *type); | |
337 | ||
a5c641b5 AB |
338 | /* Fortran arrays can have a negative stride. When this happens it is |
339 | often the case that the base address for an object is not the lowest | |
340 | address occupied by that object. For example, an array slice (10:1:-1) | |
341 | will be encoded with lower bound 1, upper bound 10, a stride of | |
342 | -ELEMENT_SIZE, and have a base address pointer that points at the | |
343 | element with the highest address in memory. | |
344 | ||
345 | This really doesn't play well with our current model of value contents, | |
346 | but could easily require a significant update in order to be supported | |
347 | "correctly". | |
348 | ||
349 | For now, we manually force the base address to be the lowest addressed | |
350 | element here. Yes, this will break some things, but it fixes other | |
351 | things. The hope is that it fixes more than it breaks. */ | |
352 | ||
353 | extern CORE_ADDR fortran_adjust_dynamic_array_base_address_hack | |
354 | (struct type *type, CORE_ADDR address); | |
355 | ||
1a5c2598 | 356 | #endif /* F_LANG_H */ |