Fix TARGET_CHAR_BIT/HOST_CHAR_BIT confusion in gmp-utils.c
[binutils-gdb.git] / gdb / f-lang.h
blob351f2191c16092e2e9397ead5347674b03dbeadd
1 /* Fortran language support definitions for GDB, the GNU debugger.
3 Copyright (C) 1992-2020 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/>. */
23 #ifndef F_LANG_H
24 #define F_LANG_H
26 #include "valprint.h"
28 struct type_print_options;
29 struct parser_state;
31 /* Class representing the Fortran language. */
33 class f_language : public language_defn
35 public:
36 f_language ()
37 : language_defn (language_fortran)
38 { /* Nothing. */ }
40 /* See language.h. */
42 const char *name () const override
43 { return "fortran"; }
45 /* See language.h. */
47 const char *natural_name () const override
48 { return "Fortran"; }
50 /* See language.h. */
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"
58 return extensions;
61 /* See language.h. */
62 void language_arch_info (struct gdbarch *gdbarch,
63 struct language_arch_info *lai) const override;
65 /* See language.h. */
66 unsigned int search_name_hash (const char *name) const override;
68 /* See language.h. */
70 char *demangle_symbol (const char *mangled, int options) const override
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;
80 /* See language.h. */
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;
86 /* See language.h. This just returns default set of word break
87 characters but with the modules separator `::' removed. */
89 const char *word_break_characters (void) const override
91 static char *retval;
93 if (!retval)
95 char *s;
97 retval = xstrdup (language_defn::word_break_characters ());
98 s = strchr (retval, ':');
99 if (s)
101 char *last_char = &s[strlen (s) - 1];
103 *s = *last_char;
104 *last_char = 0;
107 return retval;
111 /* See language.h. */
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
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);
127 /* See language.h. */
129 void value_print_inner
130 (struct value *val, struct ui_file *stream, int recurse,
131 const struct value_print_options *options) const override;
133 /* See language.h. */
135 struct block_symbol lookup_symbol_nonlocal
136 (const char *name, const struct block *block,
137 const domain_enum domain) const override;
139 /* See language.h. */
141 int parser (struct parser_state *ps) const override;
143 /* See language.h. */
145 void emitchar (int ch, struct type *chtype,
146 struct ui_file *stream, int quoter) const override
148 const char *encoding = get_encoding (chtype);
149 generic_emit_char (ch, chtype, stream, quoter, encoding);
152 /* See language.h. */
154 void printchar (int ch, struct type *chtype,
155 struct ui_file *stream) const override
157 fputs_filtered ("'", stream);
158 LA_EMIT_CHAR (ch, chtype, stream, '\'');
159 fputs_filtered ("'", stream);
162 /* See language.h. */
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
169 const char *type_encoding = get_encoding (elttype);
171 if (TYPE_LENGTH (elttype) == 4)
172 fputs_filtered ("4_", stream);
174 if (!encoding || !*encoding)
175 encoding = type_encoding;
177 generic_printstr (stream, elttype, string, length, encoding,
178 force_ellipses, '\'', 0, options);
181 /* See language.h. */
183 void print_typedef (struct type *type, struct symbol *new_symbol,
184 struct ui_file *stream) const override;
186 /* See language.h. */
188 bool is_string_type_p (struct type *type) const override
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));
196 /* See language.h. */
198 const char *struct_too_deep_ellipsis () const override
199 { return "(...)"; }
201 /* See language.h. */
203 bool c_style_arrays_p () const override
204 { return false; }
206 /* See language.h. */
208 bool range_checking_on_by_default () const override
209 { return true; }
211 /* See language.h. */
213 enum case_sensitivity case_sensitivity () const override
214 { return case_sensitive_off; }
216 /* See language.h. */
218 enum array_ordering array_ordering () const override
219 { return array_column_major; }
221 /* See language.h. */
223 const struct exp_descriptor *expression_ops () const override
224 { return &exp_descriptor_tab; }
226 /* See language.h. */
228 const struct op_print *opcode_print_table () const override
229 { return op_print_tab; }
231 protected:
233 /* See language.h. */
235 symbol_name_matcher_ftype *get_symbol_name_matcher_inner
236 (const lookup_name_info &lookup_name) const override;
238 private:
239 /* Table of expression handling functions for use by EXPRESSION_OPS
240 member function. */
242 static const struct exp_descriptor exp_descriptor_tab;
244 /* Table of opcode data for use by OPCODE_PRINT_TABLE member function. */
246 static const struct op_print op_print_tab[];
248 /* Return the encoding that should be used for the character type
249 TYPE. */
251 static const char *get_encoding (struct type *type);
253 /* Print any asterisks or open-parentheses needed before the variable
254 name (to describe its type).
256 On outermost call, pass 0 for PASSED_A_PTR.
257 On outermost call, SHOW > 0 means should ignore
258 any typename for TYPE and show its details.
259 SHOW is always zero on recursive calls. */
261 void f_type_print_varspec_prefix (struct type *type,
262 struct ui_file * stream,
263 int show, int passed_a_ptr) const;
265 /* Print any array sizes, function arguments or close parentheses needed
266 after the variable name (to describe its type). Args work like
267 c_type_print_varspec_prefix.
269 PRINT_RANK_ONLY is true when TYPE is an array which should be printed
270 without the upper and lower bounds being specified, this will occur
271 when the array is not allocated or not associated and so there are no
272 known upper or lower bounds. */
274 void f_type_print_varspec_suffix (struct type *type,
275 struct ui_file *stream,
276 int show, int passed_a_ptr,
277 int demangled_args,
278 int arrayprint_recurse_level,
279 bool print_rank_only) const;
281 /* Print the name of the type (or the ultimate pointer target, function
282 value or array element), or the description of a structure or union.
284 SHOW nonzero means don't print this type as just its name;
285 show its real definition even if it has a name.
286 SHOW zero means print just typename or struct tag if there is one
287 SHOW negative means abbreviate structure elements.
288 SHOW is decremented for printing of structure elements.
290 LEVEL is the depth to indent by. We increase it for some recursive
291 calls. */
293 void f_type_print_base (struct type *type, struct ui_file *stream, int show,
294 int level) const;
297 /* Language-specific data structures */
299 /* A common block. */
301 struct common_block
303 /* The number of entries in the block. */
304 size_t n_entries;
306 /* The contents of the block, allocated using the struct hack. All
307 pointers in the array are non-NULL. */
308 struct symbol *contents[1];
311 extern LONGEST f77_get_upperbound (struct type *);
313 extern LONGEST f77_get_lowerbound (struct type *);
315 extern int calc_f77_array_dims (struct type *);
317 /* Fortran (F77) types */
319 struct builtin_f_type
321 struct type *builtin_character;
322 struct type *builtin_integer;
323 struct type *builtin_integer_s2;
324 struct type *builtin_integer_s8;
325 struct type *builtin_logical;
326 struct type *builtin_logical_s1;
327 struct type *builtin_logical_s2;
328 struct type *builtin_logical_s8;
329 struct type *builtin_real;
330 struct type *builtin_real_s8;
331 struct type *builtin_real_s16;
332 struct type *builtin_complex_s8;
333 struct type *builtin_complex_s16;
334 struct type *builtin_complex_s32;
335 struct type *builtin_void;
338 /* Return the Fortran type table for the specified architecture. */
339 extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch);
341 /* Ensures that function argument TYPE is appropriate to inform the debugger
342 that ARG should be passed as a pointer. Returns the potentially updated
343 argument type.
345 If ARG is of type pointer then the type of ARG is returned, otherwise
346 TYPE is returned untouched.
348 This function exists to augment the types of Fortran function call
349 parameters to be pointers to the reported value, when the corresponding ARG
350 has also been wrapped in a pointer (by fortran_argument_convert). This
351 informs the debugger that these arguments should be passed as a pointer
352 rather than as the pointed to type. */
354 extern struct type *fortran_preserve_arg_pointer (struct value *arg,
355 struct type *type);
357 /* Fortran arrays can have a negative stride. When this happens it is
358 often the case that the base address for an object is not the lowest
359 address occupied by that object. For example, an array slice (10:1:-1)
360 will be encoded with lower bound 1, upper bound 10, a stride of
361 -ELEMENT_SIZE, and have a base address pointer that points at the
362 element with the highest address in memory.
364 This really doesn't play well with our current model of value contents,
365 but could easily require a significant update in order to be supported
366 "correctly".
368 For now, we manually force the base address to be the lowest addressed
369 element here. Yes, this will break some things, but it fixes other
370 things. The hope is that it fixes more than it breaks. */
372 extern CORE_ADDR fortran_adjust_dynamic_array_base_address_hack
373 (struct type *type, CORE_ADDR address);
375 #endif /* F_LANG_H */