| 1 | /* Support for printing Chill types for GDB, the GNU debugger. |
| 2 | Copyright 1986, 1988, 1989, 1991, 2000 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 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 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "obstack.h" |
| 23 | #include "bfd.h" /* Binary File Description */ |
| 24 | #include "symtab.h" |
| 25 | #include "gdbtypes.h" |
| 26 | #include "expression.h" |
| 27 | #include "value.h" |
| 28 | #include "gdbcore.h" |
| 29 | #include "target.h" |
| 30 | #include "command.h" |
| 31 | #include "gdbcmd.h" |
| 32 | #include "language.h" |
| 33 | #include "demangle.h" |
| 34 | #include "ch-lang.h" |
| 35 | #include "typeprint.h" |
| 36 | |
| 37 | #include "gdb_string.h" |
| 38 | #include <errno.h> |
| 39 | |
| 40 | static void chill_type_print_base (struct type *, struct ui_file *, int, int); |
| 41 | |
| 42 | void |
| 43 | chill_print_type (struct type *type, char *varstring, struct ui_file *stream, |
| 44 | int show, int level) |
| 45 | { |
| 46 | if (varstring != NULL && *varstring != '\0') |
| 47 | { |
| 48 | fputs_filtered (varstring, stream); |
| 49 | fputs_filtered (" ", stream); |
| 50 | } |
| 51 | chill_type_print_base (type, stream, show, level); |
| 52 | } |
| 53 | |
| 54 | /* Print the name of the type (or the ultimate pointer target, |
| 55 | function value or array element). |
| 56 | |
| 57 | SHOW nonzero means don't print this type as just its name; |
| 58 | show its real definition even if it has a name. |
| 59 | SHOW zero means print just typename or tag if there is one |
| 60 | SHOW negative means abbreviate structure elements. |
| 61 | SHOW is decremented for printing of structure elements. |
| 62 | |
| 63 | LEVEL is the depth to indent by. |
| 64 | We increase it for some recursive calls. */ |
| 65 | |
| 66 | static void |
| 67 | chill_type_print_base (struct type *type, struct ui_file *stream, int show, |
| 68 | int level) |
| 69 | { |
| 70 | register int len; |
| 71 | register int i; |
| 72 | struct type *index_type; |
| 73 | struct type *range_type; |
| 74 | LONGEST low_bound; |
| 75 | LONGEST high_bound; |
| 76 | |
| 77 | QUIT; |
| 78 | |
| 79 | wrap_here (" "); |
| 80 | if (type == NULL) |
| 81 | { |
| 82 | fputs_filtered ("<type unknown>", stream); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | /* When SHOW is zero or less, and there is a valid type name, then always |
| 87 | just print the type name directly from the type. */ |
| 88 | |
| 89 | if ((show <= 0) && (TYPE_NAME (type) != NULL)) |
| 90 | { |
| 91 | fputs_filtered (TYPE_NAME (type), stream); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF) |
| 96 | CHECK_TYPEDEF (type); |
| 97 | |
| 98 | switch (TYPE_CODE (type)) |
| 99 | { |
| 100 | case TYPE_CODE_TYPEDEF: |
| 101 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); |
| 102 | break; |
| 103 | case TYPE_CODE_PTR: |
| 104 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID) |
| 105 | { |
| 106 | fprintf_filtered (stream, |
| 107 | TYPE_NAME (type) ? TYPE_NAME (type) : "PTR"); |
| 108 | break; |
| 109 | } |
| 110 | fprintf_filtered (stream, "REF "); |
| 111 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); |
| 112 | break; |
| 113 | |
| 114 | case TYPE_CODE_BOOL: |
| 115 | /* FIXME: we should probably just print the TYPE_NAME, in case |
| 116 | anyone ever fixes the compiler to give us the real names |
| 117 | in the presence of the chill equivalent of typedef (assuming |
| 118 | there is one). */ |
| 119 | fprintf_filtered (stream, |
| 120 | TYPE_NAME (type) ? TYPE_NAME (type) : "BOOL"); |
| 121 | break; |
| 122 | |
| 123 | case TYPE_CODE_ARRAY: |
| 124 | fputs_filtered ("ARRAY (", stream); |
| 125 | range_type = TYPE_FIELD_TYPE (type, 0); |
| 126 | if (TYPE_CODE (range_type) != TYPE_CODE_RANGE) |
| 127 | chill_print_type (range_type, "", stream, 0, level); |
| 128 | else |
| 129 | { |
| 130 | index_type = TYPE_TARGET_TYPE (range_type); |
| 131 | low_bound = TYPE_FIELD_BITPOS (range_type, 0); |
| 132 | high_bound = TYPE_FIELD_BITPOS (range_type, 1); |
| 133 | print_type_scalar (index_type, low_bound, stream); |
| 134 | fputs_filtered (":", stream); |
| 135 | print_type_scalar (index_type, high_bound, stream); |
| 136 | } |
| 137 | fputs_filtered (") ", stream); |
| 138 | chill_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, level); |
| 139 | break; |
| 140 | |
| 141 | case TYPE_CODE_BITSTRING: |
| 142 | fprintf_filtered (stream, "BOOLS (%d)", |
| 143 | TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE (type, 0), 1) + 1); |
| 144 | break; |
| 145 | |
| 146 | case TYPE_CODE_SET: |
| 147 | fputs_filtered ("POWERSET ", stream); |
| 148 | chill_print_type (TYPE_INDEX_TYPE (type), "", stream, |
| 149 | show - 1, level); |
| 150 | break; |
| 151 | |
| 152 | case TYPE_CODE_STRING: |
| 153 | range_type = TYPE_FIELD_TYPE (type, 0); |
| 154 | index_type = TYPE_TARGET_TYPE (range_type); |
| 155 | high_bound = TYPE_FIELD_BITPOS (range_type, 1); |
| 156 | fputs_filtered ("CHARS (", stream); |
| 157 | print_type_scalar (index_type, high_bound + 1, stream); |
| 158 | fputs_filtered (")", stream); |
| 159 | break; |
| 160 | |
| 161 | case TYPE_CODE_MEMBER: |
| 162 | fprintf_filtered (stream, "MEMBER "); |
| 163 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); |
| 164 | break; |
| 165 | case TYPE_CODE_REF: |
| 166 | fprintf_filtered (stream, "/*LOC*/ "); |
| 167 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); |
| 168 | break; |
| 169 | case TYPE_CODE_FUNC: |
| 170 | fprintf_filtered (stream, "PROC ("); |
| 171 | len = TYPE_NFIELDS (type); |
| 172 | for (i = 0; i < len; i++) |
| 173 | { |
| 174 | struct type *param_type = TYPE_FIELD_TYPE (type, i); |
| 175 | if (i > 0) |
| 176 | { |
| 177 | fputs_filtered (", ", stream); |
| 178 | wrap_here (" "); |
| 179 | } |
| 180 | if (TYPE_CODE (param_type) == TYPE_CODE_REF) |
| 181 | { |
| 182 | chill_type_print_base (TYPE_TARGET_TYPE (param_type), |
| 183 | stream, 0, level); |
| 184 | fputs_filtered (" LOC", stream); |
| 185 | } |
| 186 | else |
| 187 | chill_type_print_base (param_type, stream, show, level); |
| 188 | } |
| 189 | fprintf_filtered (stream, ")"); |
| 190 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID) |
| 191 | { |
| 192 | fputs_filtered (" RETURNS (", stream); |
| 193 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); |
| 194 | fputs_filtered (")", stream); |
| 195 | } |
| 196 | break; |
| 197 | |
| 198 | case TYPE_CODE_STRUCT: |
| 199 | if (chill_varying_type (type)) |
| 200 | { |
| 201 | chill_type_print_base (TYPE_FIELD_TYPE (type, 1), |
| 202 | stream, 0, level); |
| 203 | fputs_filtered (" VARYING", stream); |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | fprintf_filtered (stream, "STRUCT "); |
| 208 | |
| 209 | fprintf_filtered (stream, "(\n"); |
| 210 | if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0)) |
| 211 | { |
| 212 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) |
| 213 | { |
| 214 | fprintfi_filtered (level + 4, stream, "<incomplete type>\n"); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | fprintfi_filtered (level + 4, stream, "<no data fields>\n"); |
| 219 | } |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | len = TYPE_NFIELDS (type); |
| 224 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) |
| 225 | { |
| 226 | struct type *field_type = TYPE_FIELD_TYPE (type, i); |
| 227 | QUIT; |
| 228 | print_spaces_filtered (level + 4, stream); |
| 229 | if (TYPE_CODE (field_type) == TYPE_CODE_UNION) |
| 230 | { |
| 231 | int j; /* variant number */ |
| 232 | fputs_filtered ("CASE OF\n", stream); |
| 233 | for (j = 0; j < TYPE_NFIELDS (field_type); j++) |
| 234 | { |
| 235 | int k; /* variant field index */ |
| 236 | struct type *variant_type |
| 237 | = TYPE_FIELD_TYPE (field_type, j); |
| 238 | int var_len = TYPE_NFIELDS (variant_type); |
| 239 | print_spaces_filtered (level + 4, stream); |
| 240 | if (strcmp (TYPE_FIELD_NAME (field_type, j), |
| 241 | "else") == 0) |
| 242 | fputs_filtered ("ELSE\n", stream); |
| 243 | else |
| 244 | fputs_filtered (":\n", stream); |
| 245 | if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT) |
| 246 | error ("variant record confusion"); |
| 247 | for (k = 0; k < var_len; k++) |
| 248 | { |
| 249 | print_spaces_filtered (level + 8, stream); |
| 250 | chill_print_type (TYPE_FIELD_TYPE (variant_type, k), |
| 251 | TYPE_FIELD_NAME (variant_type, k), |
| 252 | stream, show - 1, level + 8); |
| 253 | if (k < (var_len - 1)) |
| 254 | fputs_filtered (",", stream); |
| 255 | fputs_filtered ("\n", stream); |
| 256 | } |
| 257 | } |
| 258 | print_spaces_filtered (level + 4, stream); |
| 259 | fputs_filtered ("ESAC", stream); |
| 260 | } |
| 261 | else |
| 262 | chill_print_type (field_type, |
| 263 | TYPE_FIELD_NAME (type, i), |
| 264 | stream, show - 1, level + 4); |
| 265 | if (i < (len - 1)) |
| 266 | { |
| 267 | fputs_filtered (",", stream); |
| 268 | } |
| 269 | fputs_filtered ("\n", stream); |
| 270 | } |
| 271 | } |
| 272 | fprintfi_filtered (level, stream, ")"); |
| 273 | } |
| 274 | break; |
| 275 | |
| 276 | case TYPE_CODE_RANGE: |
| 277 | { |
| 278 | struct type *target = TYPE_TARGET_TYPE (type); |
| 279 | if (target && TYPE_NAME (target)) |
| 280 | fputs_filtered (TYPE_NAME (target), stream); |
| 281 | else |
| 282 | fputs_filtered ("RANGE", stream); |
| 283 | if (target == NULL) |
| 284 | target = builtin_type_long; |
| 285 | fputs_filtered (" (", stream); |
| 286 | print_type_scalar (target, TYPE_LOW_BOUND (type), stream); |
| 287 | fputs_filtered (":", stream); |
| 288 | print_type_scalar (target, TYPE_HIGH_BOUND (type), stream); |
| 289 | fputs_filtered (")", stream); |
| 290 | } |
| 291 | break; |
| 292 | |
| 293 | case TYPE_CODE_ENUM: |
| 294 | { |
| 295 | register int lastval = 0; |
| 296 | fprintf_filtered (stream, "SET ("); |
| 297 | len = TYPE_NFIELDS (type); |
| 298 | for (i = 0; i < len; i++) |
| 299 | { |
| 300 | QUIT; |
| 301 | if (i) |
| 302 | fprintf_filtered (stream, ", "); |
| 303 | wrap_here (" "); |
| 304 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); |
| 305 | if (lastval != TYPE_FIELD_BITPOS (type, i)) |
| 306 | { |
| 307 | fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i)); |
| 308 | lastval = TYPE_FIELD_BITPOS (type, i); |
| 309 | } |
| 310 | lastval++; |
| 311 | } |
| 312 | fprintf_filtered (stream, ")"); |
| 313 | } |
| 314 | break; |
| 315 | |
| 316 | case TYPE_CODE_VOID: |
| 317 | case TYPE_CODE_UNDEF: |
| 318 | case TYPE_CODE_ERROR: |
| 319 | case TYPE_CODE_UNION: |
| 320 | case TYPE_CODE_METHOD: |
| 321 | error ("missing language support in chill_type_print_base"); |
| 322 | break; |
| 323 | |
| 324 | default: |
| 325 | |
| 326 | /* Handle types not explicitly handled by the other cases, |
| 327 | such as fundamental types. For these, just print whatever |
| 328 | the type name is, as recorded in the type itself. If there |
| 329 | is no type name, then complain. */ |
| 330 | |
| 331 | if (TYPE_NAME (type) != NULL) |
| 332 | { |
| 333 | fputs_filtered (TYPE_NAME (type), stream); |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | error ("Unrecognized type code (%d) in symbol table.", |
| 338 | TYPE_CODE (type)); |
| 339 | } |
| 340 | break; |
| 341 | } |
| 342 | } |