1 /* Modula 2 language support definitions for GDB, the GNU debugger. 2 3 Copyright (C) 1992-2024 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 #ifndef M2_LANG_H 21 #define M2_LANG_H 22 23 struct type_print_options; 24 struct parser_state; 25 26 /* Defined in m2-typeprint.c */ 27 extern void m2_print_type (struct type *, const char *, struct ui_file *, int, 28 int, const struct type_print_options *); 29 30 extern int m2_is_long_set (struct type *type); 31 extern int m2_is_unbounded_array (struct type *type); 32 33 extern int get_long_set_bounds (struct type *type, LONGEST *low, 34 LONGEST *high); 35 36 /* Modula-2 types */ 37 38 struct builtin_m2_type 39 { 40 struct type *builtin_char = nullptr; 41 struct type *builtin_int = nullptr; 42 struct type *builtin_card = nullptr; 43 struct type *builtin_real = nullptr; 44 struct type *builtin_bool = nullptr; 45 }; 46 47 /* Return the Modula-2 type table for the specified architecture. */ 48 extern const struct builtin_m2_type *builtin_m2_type (struct gdbarch *gdbarch); 49 50 /* Class representing the M2 language. */ 51 52 class m2_language : public language_defn 53 { 54 public: 55 m2_language () 56 : language_defn (language_m2) 57 { /* Nothing. */ } 58 59 /* See language.h. */ 60 61 const char *name () const override 62 { return "modula-2"; } 63 64 /* See language.h. */ 65 66 const char *natural_name () const override 67 { return "Modula-2"; } 68 69 /* See language.h. */ 70 71 void language_arch_info (struct gdbarch *gdbarch, 72 struct language_arch_info *lai) const override; 73 74 /* See language.h. */ 75 76 void print_type (struct type *type, const char *varstring, 77 struct ui_file *stream, int show, int level, 78 const struct type_print_options *flags) const override 79 { 80 m2_print_type (type, varstring, stream, show, level, flags); 81 } 82 83 /* See language.h. */ 84 85 void value_print_inner (struct value *val, struct ui_file *stream, 86 int recurse, 87 const struct value_print_options *options) const override; 88 89 /* See language.h. */ 90 91 int parser (struct parser_state *ps) const override; 92 93 /* See language.h. */ 94 95 void emitchar (int ch, struct type *chtype, 96 struct ui_file *stream, int quoter) const override; 97 98 /* See language.h. */ 99 100 void printchar (int ch, struct type *chtype, 101 struct ui_file *stream) const override; 102 103 /* See language.h. */ 104 105 void printstr (struct ui_file *stream, struct type *elttype, 106 const gdb_byte *string, unsigned int length, 107 const char *encoding, int force_ellipses, 108 const struct value_print_options *options) const override; 109 110 /* See language.h. */ 111 112 void print_typedef (struct type *type, struct symbol *new_symbol, 113 struct ui_file *stream) const override; 114 115 /* See language.h. */ 116 117 bool is_string_type_p (struct type *type) const override 118 { 119 type = check_typedef (type); 120 if (type->code () == TYPE_CODE_ARRAY 121 && type->length () > 0 122 && type->target_type ()->length () > 0) 123 { 124 struct type *elttype = check_typedef (type->target_type ()); 125 126 if (elttype->length () == 1 127 && (elttype->code () == TYPE_CODE_INT 128 || elttype->code () == TYPE_CODE_CHAR)) 129 return true; 130 } 131 132 return false; 133 } 134 135 /* See language.h. */ 136 137 bool c_style_arrays_p () const override 138 { return false; } 139 140 /* See language.h. Despite not having C-style arrays, Modula-2 uses 0 141 for its string lower bounds. */ 142 143 char string_lower_bound () const override 144 { return 0; } 145 146 /* See language.h. */ 147 148 bool range_checking_on_by_default () const override 149 { return true; } 150 }; 151 152 #endif /* M2_LANG_H */ 153