/* Return the encoding that should be used for the character type
TYPE. */
-static const char *
-f_get_encoding (struct type *type)
+const char *
+f_language::get_encoding (struct type *type)
{
const char *encoding;
/* Table of operators and their precedences for printing expressions. */
-static const struct op_print f_op_print_tab[] =
+const struct op_print f_language::op_print_tab[] =
{
{"+", BINOP_ADD, PREC_ADD, 0},
{"+", UNOP_PLUS, PREC_PREFIX, 0},
{NULL, OP_NULL, PREC_REPEAT, 0}
};
\f
-enum f_primitive_types {
- f_primitive_type_character,
- f_primitive_type_logical,
- f_primitive_type_logical_s1,
- f_primitive_type_logical_s2,
- f_primitive_type_logical_s8,
- f_primitive_type_integer,
- f_primitive_type_integer_s2,
- f_primitive_type_real,
- f_primitive_type_real_s8,
- f_primitive_type_real_s16,
- f_primitive_type_complex_s8,
- f_primitive_type_complex_s16,
- f_primitive_type_void,
- nr_f_primitive_types
-};
/* Called from fortran_value_subarray to take a slice of an array or a
string. ARRAY is the array or string to be accessed. EXP, POS, and
type = value_type (arg1);
if (type->code () != value_type (arg2)->code ())
error (_("non-matching types for parameters to MODULO ()"));
- /* MODULO(A, P) = A - FLOOR (A / P) * P */
+ /* MODULO(A, P) = A - FLOOR (A / P) * P */
switch (type->code ())
{
case TYPE_CODE_INT:
type = value_type (arg1);
switch (type->code ())
- {
- case TYPE_CODE_STRUCT:
- case TYPE_CODE_UNION:
- case TYPE_CODE_MODULE:
- case TYPE_CODE_FUNC:
- error (_("argument to kind must be an intrinsic type"));
- }
+ {
+ case TYPE_CODE_STRUCT:
+ case TYPE_CODE_UNION:
+ case TYPE_CODE_MODULE:
+ case TYPE_CODE_FUNC:
+ error (_("argument to kind must be an intrinsic type"));
+ }
if (!TYPE_TARGET_TYPE (type))
- return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
+ return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
TYPE_LENGTH (type));
return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
case OP_F77_UNDETERMINED_ARGLIST:
/* Remember that in F77, functions, substring ops and array subscript
- operations cannot be disambiguated at parse time. We have made
- all array subscript operations, substring operations as well as
- function calls come here and we now have to discover what the heck
- this thing actually was. If it is a function, we process just as
- if we got an OP_FUNCALL. */
+ operations cannot be disambiguated at parse time. We have made
+ all array subscript operations, substring operations as well as
+ function calls come here and we now have to discover what the heck
+ this thing actually was. If it is a function, we process just as
+ if we got an OP_FUNCALL. */
int nargs = longest_to_int (exp->elts[pc + 1].longconst);
(*pos) += 2;
return;
case OP_F77_UNDETERMINED_ARGLIST:
+ (*pos)++;
print_subexp_funcall (exp, pos, stream);
return;
}
break;
case OP_F77_UNDETERMINED_ARGLIST:
- return dump_subexp_body_funcall (exp, stream, elt);
+ return dump_subexp_body_funcall (exp, stream, elt + 1);
}
elt += oplen;
}
/* Expression processing for Fortran. */
-static const struct exp_descriptor exp_descriptor_f =
+const struct exp_descriptor f_language::exp_descriptor_tab =
{
print_subexp_f,
operator_length_f,
evaluate_subexp_f
};
-/* Class representing the Fortran language. */
+/* See language.h. */
-class f_language : public language_defn
+void
+f_language::language_arch_info (struct gdbarch *gdbarch,
+ struct language_arch_info *lai) const
{
-public:
- f_language ()
- : language_defn (language_fortran)
- { /* Nothing. */ }
-
- /* See language.h. */
-
- const char *name () const override
- { return "fortran"; }
-
- /* See language.h. */
-
- const char *natural_name () const override
- { return "Fortran"; }
-
- /* See language.h. */
-
- const std::vector<const char *> &filename_extensions () const override
- {
- static const std::vector<const char *> extensions = {
- ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
- ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08"
- };
- return extensions;
- }
-
- /* See language.h. */
- void language_arch_info (struct gdbarch *gdbarch,
- struct language_arch_info *lai) const override
- {
- const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
-
- lai->string_char_type = builtin->builtin_character;
- lai->primitive_type_vector
- = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
- struct type *);
-
- lai->primitive_type_vector [f_primitive_type_character]
- = builtin->builtin_character;
- lai->primitive_type_vector [f_primitive_type_logical]
- = builtin->builtin_logical;
- lai->primitive_type_vector [f_primitive_type_logical_s1]
- = builtin->builtin_logical_s1;
- lai->primitive_type_vector [f_primitive_type_logical_s2]
- = builtin->builtin_logical_s2;
- lai->primitive_type_vector [f_primitive_type_logical_s8]
- = builtin->builtin_logical_s8;
- lai->primitive_type_vector [f_primitive_type_real]
- = builtin->builtin_real;
- lai->primitive_type_vector [f_primitive_type_real_s8]
- = builtin->builtin_real_s8;
- lai->primitive_type_vector [f_primitive_type_real_s16]
- = builtin->builtin_real_s16;
- lai->primitive_type_vector [f_primitive_type_complex_s8]
- = builtin->builtin_complex_s8;
- lai->primitive_type_vector [f_primitive_type_complex_s16]
- = builtin->builtin_complex_s16;
- lai->primitive_type_vector [f_primitive_type_void]
- = builtin->builtin_void;
-
- lai->bool_type_symbol = "logical";
- lai->bool_type_default = builtin->builtin_logical_s2;
- }
-
- /* See language.h. */
- unsigned int search_name_hash (const char *name) const override
- {
- return cp_search_name_hash (name);
- }
-
- /* See language.h. */
-
- char *demangle_symbol (const char *mangled, int options) const override
- {
- /* We could support demangling here to provide module namespaces
- also for inferiors with only minimal symbol table (ELF symbols).
- Just the mangling standard is not standardized across compilers
- and there is no DW_AT_producer available for inferiors with only
- the ELF symbols to check the mangling kind. */
- return nullptr;
- }
-
- /* See language.h. */
-
- void print_type (struct type *type, const char *varstring,
- struct ui_file *stream, int show, int level,
- const struct type_print_options *flags) const override
- {
- f_print_type (type, varstring, stream, show, level, flags);
- }
-
- /* See language.h. This just returns default set of word break
- characters but with the modules separator `::' removed. */
+ const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
- const char *word_break_characters (void) const override
+ /* Helper function to allow shorter lines below. */
+ auto add = [&] (struct type * t)
{
- static char *retval;
-
- if (!retval)
- {
- char *s;
-
- retval = xstrdup (language_defn::word_break_characters ());
- s = strchr (retval, ':');
- if (s)
- {
- char *last_char = &s[strlen (s) - 1];
-
- *s = *last_char;
- *last_char = 0;
- }
- }
- return retval;
- }
-
-
- /* See language.h. */
-
- void collect_symbol_completion_matches (completion_tracker &tracker,
- complete_symbol_mode mode,
- symbol_name_match_type name_match_type,
- const char *text, const char *word,
- enum type_code code) const override
- {
- /* Consider the modules separator :: as a valid symbol name character
- class. */
- default_collect_symbol_completion_matches_break_on (tracker, mode,
- name_match_type,
- text, word, ":",
- code);
- }
-
- /* See language.h. */
-
- void value_print_inner
- (struct value *val, struct ui_file *stream, int recurse,
- const struct value_print_options *options) const override
- {
- return f_value_print_inner (val, stream, recurse, options);
- }
-
- /* See language.h. */
-
- struct block_symbol lookup_symbol_nonlocal
- (const char *name, const struct block *block,
- const domain_enum domain) const override
- {
- return cp_lookup_symbol_nonlocal (this, name, block, domain);
- }
-
- /* See language.h. */
-
- int parser (struct parser_state *ps) const override
- {
- return f_parse (ps);
- }
-
- /* See language.h. */
-
- void emitchar (int ch, struct type *chtype,
- struct ui_file *stream, int quoter) const override
- {
- const char *encoding = f_get_encoding (chtype);
- generic_emit_char (ch, chtype, stream, quoter, encoding);
- }
-
- /* See language.h. */
-
- void printchar (int ch, struct type *chtype,
- struct ui_file *stream) const override
- {
- fputs_filtered ("'", stream);
- LA_EMIT_CHAR (ch, chtype, stream, '\'');
- fputs_filtered ("'", stream);
- }
-
- /* See language.h. */
-
- void printstr (struct ui_file *stream, struct type *elttype,
- const gdb_byte *string, unsigned int length,
- const char *encoding, int force_ellipses,
- const struct value_print_options *options) const override
- {
- const char *type_encoding = f_get_encoding (elttype);
-
- if (TYPE_LENGTH (elttype) == 4)
- fputs_filtered ("4_", stream);
-
- if (!encoding || !*encoding)
- encoding = type_encoding;
-
- generic_printstr (stream, elttype, string, length, encoding,
- force_ellipses, '\'', 0, options);
- }
-
- /* See language.h. */
-
- void print_typedef (struct type *type, struct symbol *new_symbol,
- struct ui_file *stream) const override
- {
- f_print_typedef (type, new_symbol, stream);
- }
-
- /* See language.h. */
-
- bool is_string_type_p (struct type *type) const override
- {
- type = check_typedef (type);
- return (type->code () == TYPE_CODE_STRING
- || (type->code () == TYPE_CODE_ARRAY
- && TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_CHAR));
- }
-
- /* See language.h. */
-
- const char *struct_too_deep_ellipsis () const override
- { return "(...)"; }
-
- /* See language.h. */
-
- bool c_style_arrays_p () const override
- { return false; }
-
- /* See language.h. */
-
- bool range_checking_on_by_default () const override
- { return true; }
-
- /* See language.h. */
-
- enum case_sensitivity case_sensitivity () const override
- { return case_sensitive_off; }
-
- /* See language.h. */
-
- enum array_ordering array_ordering () const override
- { return array_column_major; }
-
- /* See language.h. */
+ lai->add_primitive_type (t);
+ };
+
+ add (builtin->builtin_character);
+ add (builtin->builtin_logical);
+ add (builtin->builtin_logical_s1);
+ add (builtin->builtin_logical_s2);
+ add (builtin->builtin_logical_s8);
+ add (builtin->builtin_real);
+ add (builtin->builtin_real_s8);
+ add (builtin->builtin_real_s16);
+ add (builtin->builtin_complex_s8);
+ add (builtin->builtin_complex_s16);
+ add (builtin->builtin_void);
+
+ lai->set_string_char_type (builtin->builtin_character);
+ lai->set_bool_type (builtin->builtin_logical_s2, "logical");
+}
- const struct exp_descriptor *expression_ops () const override
- { return &exp_descriptor_f; }
+/* See language.h. */
- /* See language.h. */
+unsigned int
+f_language::search_name_hash (const char *name) const
+{
+ return cp_search_name_hash (name);
+}
- const struct op_print *opcode_print_table () const override
- { return f_op_print_tab; }
+/* See language.h. */
-protected:
+struct block_symbol
+f_language::lookup_symbol_nonlocal (const char *name,
+ const struct block *block,
+ const domain_enum domain) const
+{
+ return cp_lookup_symbol_nonlocal (this, name, block, domain);
+}
- /* See language.h. */
+/* See language.h. */
- symbol_name_matcher_ftype *get_symbol_name_matcher_inner
- (const lookup_name_info &lookup_name) const override
- {
- return cp_get_symbol_name_matcher (lookup_name);
- }
-};
+symbol_name_matcher_ftype *
+f_language::get_symbol_name_matcher_inner
+ (const lookup_name_info &lookup_name) const
+{
+ return cp_get_symbol_name_matcher (lookup_name);
+}
/* Single instance of the Fortran language class. */