1 /* Fortran language support definitions for GDB, the GNU debugger.
3 Copyright (C) 1992-2021 Free Software Foundation, Inc.
5 Contributed by Motorola. Adapted from the C definitions by Farooq Butt
6 (fmbutt@engage.sps.mot.com).
8 This file is part of GDB.
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
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 struct type_print_options
;
31 /* Class representing the Fortran language. */
33 class f_language
: public language_defn
37 : language_defn (language_fortran
)
42 const char *name () const override
47 const char *natural_name () const override
52 const std::vector
<const char *> &filename_extensions () const override
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"
62 void language_arch_info (struct gdbarch
*gdbarch
,
63 struct language_arch_info
*lai
) const override
;
66 unsigned int search_name_hash (const char *name
) const override
;
70 gdb::unique_xmalloc_ptr
<char> demangle_symbol (const char *mangled
,
71 int options
) const override
73 /* We could support demangling here to provide module namespaces
74 also for inferiors with only minimal symbol table (ELF symbols).
75 Just the mangling standard is not standardized across compilers
76 and there is no DW_AT_producer available for inferiors with only
77 the ELF symbols to check the mangling kind. */
83 void print_type (struct type
*type
, const char *varstring
,
84 struct ui_file
*stream
, int show
, int level
,
85 const struct type_print_options
*flags
) const override
;
87 /* See language.h. This just returns default set of word break
88 characters but with the modules separator `::' removed. */
90 const char *word_break_characters (void) const override
98 retval
= xstrdup (language_defn::word_break_characters ());
99 s
= strchr (retval
, ':');
102 char *last_char
= &s
[strlen (s
) - 1];
112 /* See language.h. */
114 void collect_symbol_completion_matches (completion_tracker
&tracker
,
115 complete_symbol_mode mode
,
116 symbol_name_match_type name_match_type
,
117 const char *text
, const char *word
,
118 enum type_code code
) const override
120 /* Consider the modules separator :: as a valid symbol name character
122 default_collect_symbol_completion_matches_break_on (tracker
, mode
,
128 /* See language.h. */
130 void value_print_inner
131 (struct value
*val
, struct ui_file
*stream
, int recurse
,
132 const struct value_print_options
*options
) const override
;
134 /* See language.h. */
136 struct block_symbol lookup_symbol_nonlocal
137 (const char *name
, const struct block
*block
,
138 const domain_enum domain
) const override
;
140 /* See language.h. */
142 int parser (struct parser_state
*ps
) const override
;
144 /* See language.h. */
146 void emitchar (int ch
, struct type
*chtype
,
147 struct ui_file
*stream
, int quoter
) const override
149 const char *encoding
= get_encoding (chtype
);
150 generic_emit_char (ch
, chtype
, stream
, quoter
, encoding
);
153 /* See language.h. */
155 void printchar (int ch
, struct type
*chtype
,
156 struct ui_file
*stream
) const override
158 fputs_filtered ("'", stream
);
159 emitchar (ch
, chtype
, stream
, '\'');
160 fputs_filtered ("'", stream
);
163 /* See language.h. */
165 void printstr (struct ui_file
*stream
, struct type
*elttype
,
166 const gdb_byte
*string
, unsigned int length
,
167 const char *encoding
, int force_ellipses
,
168 const struct value_print_options
*options
) const override
170 const char *type_encoding
= get_encoding (elttype
);
172 if (TYPE_LENGTH (elttype
) == 4)
173 fputs_filtered ("4_", stream
);
175 if (!encoding
|| !*encoding
)
176 encoding
= type_encoding
;
178 generic_printstr (stream
, elttype
, string
, length
, encoding
,
179 force_ellipses
, '\'', 0, options
);
182 /* See language.h. */
184 void print_typedef (struct type
*type
, struct symbol
*new_symbol
,
185 struct ui_file
*stream
) const override
;
187 /* See language.h. */
189 bool is_string_type_p (struct type
*type
) const override
191 type
= check_typedef (type
);
192 return (type
->code () == TYPE_CODE_STRING
193 || (type
->code () == TYPE_CODE_ARRAY
194 && TYPE_TARGET_TYPE (type
)->code () == TYPE_CODE_CHAR
));
197 /* See language.h. */
199 const char *struct_too_deep_ellipsis () const override
202 /* See language.h. */
204 bool c_style_arrays_p () const override
207 /* See language.h. */
209 bool range_checking_on_by_default () const override
212 /* See language.h. */
214 enum case_sensitivity
case_sensitivity () const override
215 { return case_sensitive_off
; }
217 /* See language.h. */
219 enum array_ordering
array_ordering () const override
220 { return array_column_major
; }
224 /* See language.h. */
226 symbol_name_matcher_ftype
*get_symbol_name_matcher_inner
227 (const lookup_name_info
&lookup_name
) const override
;
230 /* Return the encoding that should be used for the character type
233 static const char *get_encoding (struct type
*type
);
235 /* Print any asterisks or open-parentheses needed before the variable
236 name (to describe its type).
238 On outermost call, pass 0 for PASSED_A_PTR.
239 On outermost call, SHOW > 0 means should ignore
240 any typename for TYPE and show its details.
241 SHOW is always zero on recursive calls. */
243 void f_type_print_varspec_prefix (struct type
*type
,
244 struct ui_file
* stream
,
245 int show
, int passed_a_ptr
) const;
247 /* Print any array sizes, function arguments or close parentheses needed
248 after the variable name (to describe its type). Args work like
249 c_type_print_varspec_prefix.
251 PRINT_RANK_ONLY is true when TYPE is an array which should be printed
252 without the upper and lower bounds being specified, this will occur
253 when the array is not allocated or not associated and so there are no
254 known upper or lower bounds. */
256 void f_type_print_varspec_suffix (struct type
*type
,
257 struct ui_file
*stream
,
258 int show
, int passed_a_ptr
,
260 int arrayprint_recurse_level
,
261 bool print_rank_only
) const;
263 /* Print the name of the type (or the ultimate pointer target, function
264 value or array element), or the description of a structure or union.
266 SHOW nonzero means don't print this type as just its name;
267 show its real definition even if it has a name.
268 SHOW zero means print just typename or struct tag if there is one
269 SHOW negative means abbreviate structure elements.
270 SHOW is decremented for printing of structure elements.
272 LEVEL is the depth to indent by. We increase it for some recursive
275 void f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
279 /* Language-specific data structures */
281 /* A common block. */
285 /* The number of entries in the block. */
288 /* The contents of the block, allocated using the struct hack. All
289 pointers in the array are non-NULL. */
290 struct symbol
*contents
[1];
293 extern LONGEST
f77_get_upperbound (struct type
*);
295 extern LONGEST
f77_get_lowerbound (struct type
*);
297 extern int calc_f77_array_dims (struct type
*);
299 /* Fortran (F77) types */
301 struct builtin_f_type
303 struct type
*builtin_character
;
304 struct type
*builtin_integer
;
305 struct type
*builtin_integer_s2
;
306 struct type
*builtin_integer_s8
;
307 struct type
*builtin_logical
;
308 struct type
*builtin_logical_s1
;
309 struct type
*builtin_logical_s2
;
310 struct type
*builtin_logical_s8
;
311 struct type
*builtin_real
;
312 struct type
*builtin_real_s8
;
313 struct type
*builtin_real_s16
;
314 struct type
*builtin_complex_s8
;
315 struct type
*builtin_complex_s16
;
316 struct type
*builtin_complex_s32
;
317 struct type
*builtin_void
;
320 /* Return the Fortran type table for the specified architecture. */
321 extern const struct builtin_f_type
*builtin_f_type (struct gdbarch
*gdbarch
);
323 /* Ensures that function argument TYPE is appropriate to inform the debugger
324 that ARG should be passed as a pointer. Returns the potentially updated
327 If ARG is of type pointer then the type of ARG is returned, otherwise
328 TYPE is returned untouched.
330 This function exists to augment the types of Fortran function call
331 parameters to be pointers to the reported value, when the corresponding ARG
332 has also been wrapped in a pointer (by fortran_argument_convert). This
333 informs the debugger that these arguments should be passed as a pointer
334 rather than as the pointed to type. */
336 extern struct type
*fortran_preserve_arg_pointer (struct value
*arg
,
339 /* Fortran arrays can have a negative stride. When this happens it is
340 often the case that the base address for an object is not the lowest
341 address occupied by that object. For example, an array slice (10:1:-1)
342 will be encoded with lower bound 1, upper bound 10, a stride of
343 -ELEMENT_SIZE, and have a base address pointer that points at the
344 element with the highest address in memory.
346 This really doesn't play well with our current model of value contents,
347 but could easily require a significant update in order to be supported
350 For now, we manually force the base address to be the lowest addressed
351 element here. Yes, this will break some things, but it fixes other
352 things. The hope is that it fixes more than it breaks. */
354 extern CORE_ADDR fortran_adjust_dynamic_array_base_address_hack
355 (struct type
*type
, CORE_ADDR address
);
357 #endif /* F_LANG_H */