f-lang.h 11 KB

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