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