| 1 | /* Chill language support routines for GDB, the GNU debugger. |
| 2 | Copyright 1992 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 "symtab.h" |
| 22 | #include "gdbtypes.h" |
| 23 | #include "expression.h" |
| 24 | #include "parser-defs.h" |
| 25 | #include "language.h" |
| 26 | #include "ch-lang.h" |
| 27 | |
| 28 | |
| 29 | /* For now, Chill uses a simple mangling algorithm whereby you simply |
| 30 | discard everything after the occurance of two successive CPLUS_MARKER |
| 31 | characters to derive the demangled form. */ |
| 32 | |
| 33 | char * |
| 34 | chill_demangle (mangled) |
| 35 | const char *mangled; |
| 36 | { |
| 37 | char *joiner; |
| 38 | char *demangled; |
| 39 | |
| 40 | joiner = strchr (mangled, CPLUS_MARKER); |
| 41 | if (joiner != NULL && *(joiner + 1) == CPLUS_MARKER) |
| 42 | { |
| 43 | demangled = savestring (mangled, joiner - mangled); |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | demangled = NULL; |
| 48 | } |
| 49 | return (demangled); |
| 50 | } |
| 51 | |
| 52 | static void |
| 53 | chill_printchar (c, stream) |
| 54 | register int c; |
| 55 | FILE *stream; |
| 56 | { |
| 57 | c &= 0xFF; /* Avoid sign bit follies */ |
| 58 | |
| 59 | if (PRINT_LITERAL_FORM (c)) |
| 60 | { |
| 61 | fprintf_filtered (stream, "'%c'", c); |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | fprintf_filtered (stream, "C'%.2x'", (unsigned int) c); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /* Print the character string STRING, printing at most LENGTH characters. |
| 70 | Printing stops early if the number hits print_max; repeat counts |
| 71 | are printed as appropriate. Print ellipses at the end if we |
| 72 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. |
| 73 | Note that gdb maintains the length of strings without counting the |
| 74 | terminating null byte, while chill strings are typically written with |
| 75 | an explicit null byte. So we always assume an implied null byte |
| 76 | until gdb is able to maintain non-null terminated strings as well |
| 77 | as null terminated strings (FIXME). |
| 78 | */ |
| 79 | |
| 80 | static void |
| 81 | chill_printstr (stream, string, length, force_ellipses) |
| 82 | FILE *stream; |
| 83 | char *string; |
| 84 | unsigned int length; |
| 85 | int force_ellipses; |
| 86 | { |
| 87 | register unsigned int i; |
| 88 | unsigned int things_printed = 0; |
| 89 | int in_literal_form = 0; |
| 90 | int in_control_form = 0; |
| 91 | int need_slashslash = 0; |
| 92 | unsigned int c; |
| 93 | extern int repeat_count_threshold; |
| 94 | extern int print_max; |
| 95 | |
| 96 | if (length == 0) |
| 97 | { |
| 98 | chill_printchar ('\0', stream); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | for (i = 0; i < length && things_printed < print_max; ++i) |
| 103 | { |
| 104 | /* Position of the character we are examining |
| 105 | to see whether it is repeated. */ |
| 106 | unsigned int rep1; |
| 107 | /* Number of repetitions we have detected so far. */ |
| 108 | unsigned int reps; |
| 109 | |
| 110 | QUIT; |
| 111 | |
| 112 | if (need_slashslash) |
| 113 | { |
| 114 | fputs_filtered ("//", stream); |
| 115 | need_slashslash = 0; |
| 116 | } |
| 117 | |
| 118 | rep1 = i + 1; |
| 119 | reps = 1; |
| 120 | while (rep1 < length && string[rep1] == string[i]) |
| 121 | { |
| 122 | ++rep1; |
| 123 | ++reps; |
| 124 | } |
| 125 | |
| 126 | c = string[i]; |
| 127 | if (reps > repeat_count_threshold) |
| 128 | { |
| 129 | if (in_control_form || in_literal_form) |
| 130 | { |
| 131 | fputs_filtered ("'//", stream); |
| 132 | in_control_form = in_literal_form = 0; |
| 133 | } |
| 134 | chill_printchar (c, stream); |
| 135 | fprintf_filtered (stream, "<repeats %u times>", reps); |
| 136 | i = rep1 - 1; |
| 137 | things_printed += repeat_count_threshold; |
| 138 | need_slashslash = 1; |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | if (PRINT_LITERAL_FORM (c)) |
| 143 | { |
| 144 | if (!in_literal_form) |
| 145 | { |
| 146 | if (in_control_form) |
| 147 | { |
| 148 | fputs_filtered ("'//", stream); |
| 149 | in_control_form = 0; |
| 150 | } |
| 151 | fputs_filtered ("'", stream); |
| 152 | in_literal_form = 1; |
| 153 | } |
| 154 | fprintf_filtered (stream, "%c", c); |
| 155 | } |
| 156 | else |
| 157 | { |
| 158 | if (!in_control_form) |
| 159 | { |
| 160 | if (in_literal_form) |
| 161 | { |
| 162 | fputs_filtered ("'//", stream); |
| 163 | in_literal_form = 0; |
| 164 | } |
| 165 | fputs_filtered ("c'", stream); |
| 166 | in_control_form = 1; |
| 167 | } |
| 168 | fprintf_filtered (stream, "%.2x", c); |
| 169 | } |
| 170 | ++things_printed; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /* Terminate the quotes if necessary. */ |
| 175 | if (in_literal_form || in_control_form) |
| 176 | { |
| 177 | fputs_filtered ("'", stream); |
| 178 | } |
| 179 | if (force_ellipses || (i < length)) |
| 180 | { |
| 181 | fputs_filtered ("...", stream); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | static struct type * |
| 186 | chill_create_fundamental_type (objfile, typeid) |
| 187 | struct objfile *objfile; |
| 188 | int typeid; |
| 189 | { |
| 190 | register struct type *type = NULL; |
| 191 | |
| 192 | switch (typeid) |
| 193 | { |
| 194 | default: |
| 195 | /* FIXME: For now, if we are asked to produce a type not in this |
| 196 | language, create the equivalent of a C integer type with the |
| 197 | name "<?type?>". When all the dust settles from the type |
| 198 | reconstruction work, this should probably become an error. */ |
| 199 | type = init_type (TYPE_CODE_INT, 2, 0, "<?type?>", objfile); |
| 200 | warning ("internal error: no chill fundamental type %d", typeid); |
| 201 | break; |
| 202 | case FT_VOID: |
| 203 | /* FIXME: Currently the GNU Chill compiler emits some DWARF entries for |
| 204 | typedefs, unrelated to anything directly in the code being compiled, |
| 205 | that have some FT_VOID types. Just fake it for now. */ |
| 206 | type = init_type (TYPE_CODE_VOID, 0, 0, "<?VOID?>", objfile); |
| 207 | break; |
| 208 | case FT_BOOLEAN: |
| 209 | type = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, "BOOL", objfile); |
| 210 | break; |
| 211 | case FT_CHAR: |
| 212 | type = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED, "CHAR", objfile); |
| 213 | break; |
| 214 | case FT_SIGNED_CHAR: |
| 215 | type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_SIGNED, "BYTE", objfile); |
| 216 | break; |
| 217 | case FT_UNSIGNED_CHAR: |
| 218 | type = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, "UBYTE", objfile); |
| 219 | break; |
| 220 | case FT_SHORT: /* Chill ints are 2 bytes */ |
| 221 | type = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_SIGNED, "INT", objfile); |
| 222 | break; |
| 223 | case FT_UNSIGNED_SHORT: /* Chill ints are 2 bytes */ |
| 224 | type = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, "UINT", objfile); |
| 225 | break; |
| 226 | case FT_INTEGER: /* FIXME? */ |
| 227 | case FT_SIGNED_INTEGER: /* FIXME? */ |
| 228 | case FT_LONG: /* Chill longs are 4 bytes */ |
| 229 | case FT_SIGNED_LONG: /* Chill longs are 4 bytes */ |
| 230 | type = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_SIGNED, "LONG", objfile); |
| 231 | break; |
| 232 | case FT_UNSIGNED_INTEGER: /* FIXME? */ |
| 233 | case FT_UNSIGNED_LONG: /* Chill longs are 4 bytes */ |
| 234 | type = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, "ULONG", objfile); |
| 235 | break; |
| 236 | case FT_FLOAT: |
| 237 | type = init_type (TYPE_CODE_FLT, 4, 0, "REAL", objfile); |
| 238 | break; |
| 239 | case FT_DBL_PREC_FLOAT: |
| 240 | type = init_type (TYPE_CODE_FLT, 8, 0, "LONG_REAL", objfile); |
| 241 | break; |
| 242 | } |
| 243 | return (type); |
| 244 | } |
| 245 | |
| 246 | \f |
| 247 | /* Table of operators and their precedences for printing expressions. */ |
| 248 | |
| 249 | static const struct op_print chill_op_print_tab[] = { |
| 250 | {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, |
| 251 | {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, |
| 252 | {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, |
| 253 | {"MOD", BINOP_MOD, PREC_MUL, 0}, |
| 254 | {"REM", BINOP_REM, PREC_MUL, 0}, |
| 255 | {":=", BINOP_ASSIGN, PREC_ASSIGN, 1}, |
| 256 | {"=", BINOP_EQUAL, PREC_EQUAL, 0}, |
| 257 | {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, |
| 258 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, |
| 259 | {">=", BINOP_GEQ, PREC_ORDER, 0}, |
| 260 | {">", BINOP_GTR, PREC_ORDER, 0}, |
| 261 | {"<", BINOP_LESS, PREC_ORDER, 0}, |
| 262 | {"+", BINOP_ADD, PREC_ADD, 0}, |
| 263 | {"-", BINOP_SUB, PREC_ADD, 0}, |
| 264 | {"*", BINOP_MUL, PREC_MUL, 0}, |
| 265 | {"/", BINOP_DIV, PREC_MUL, 0}, |
| 266 | {"//", BINOP_CONCAT, PREC_PREFIX, 0}, /* FIXME: precedence? */ |
| 267 | {"-", UNOP_NEG, PREC_PREFIX, 0}, |
| 268 | {NULL, 0, 0, 0} |
| 269 | }; |
| 270 | |
| 271 | \f |
| 272 | /* The built-in types of Chill. */ |
| 273 | |
| 274 | struct type *builtin_type_chill_bool; |
| 275 | struct type *builtin_type_chill_char; |
| 276 | struct type *builtin_type_chill_long; |
| 277 | struct type *builtin_type_chill_ulong; |
| 278 | struct type *builtin_type_chill_real; |
| 279 | |
| 280 | struct type ** const (chill_builtin_types[]) = |
| 281 | { |
| 282 | &builtin_type_chill_bool, |
| 283 | &builtin_type_chill_char, |
| 284 | &builtin_type_chill_long, |
| 285 | &builtin_type_chill_ulong, |
| 286 | &builtin_type_chill_real, |
| 287 | 0 |
| 288 | }; |
| 289 | |
| 290 | const struct language_defn chill_language_defn = { |
| 291 | "chill", |
| 292 | language_chill, |
| 293 | chill_builtin_types, |
| 294 | range_check_on, |
| 295 | type_check_on, |
| 296 | chill_parse, /* parser */ |
| 297 | chill_error, /* parser error function */ |
| 298 | chill_printchar, /* print a character constant */ |
| 299 | chill_printstr, /* function to print a string constant */ |
| 300 | chill_create_fundamental_type,/* Create fundamental type in this language */ |
| 301 | chill_print_type, /* Print a type using appropriate syntax */ |
| 302 | chill_val_print, /* Print a value using appropriate syntax */ |
| 303 | &BUILTIN_TYPE_LONGEST, /* longest signed integral type */ |
| 304 | &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */ |
| 305 | &builtin_type_chill_real, /* longest floating point type */ |
| 306 | {"", "B'", "", ""}, /* Binary format info */ |
| 307 | {"O'%o", "O'", "o", ""}, /* Octal format info */ |
| 308 | {"D'%d", "D'", "d", ""}, /* Decimal format info */ |
| 309 | {"H'%x", "H'", "x", ""}, /* Hex format info */ |
| 310 | chill_op_print_tab, /* expression operators for printing */ |
| 311 | LANG_MAGIC |
| 312 | }; |
| 313 | |
| 314 | /* Initialization for Chill */ |
| 315 | |
| 316 | void |
| 317 | _initialize_chill_language () |
| 318 | { |
| 319 | builtin_type_chill_bool = |
| 320 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 321 | TYPE_FLAG_UNSIGNED, |
| 322 | "BOOL", (struct objfile *) NULL); |
| 323 | builtin_type_chill_char = |
| 324 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 325 | TYPE_FLAG_UNSIGNED, |
| 326 | "CHAR", (struct objfile *) NULL); |
| 327 | builtin_type_chill_long = |
| 328 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 329 | 0, |
| 330 | "LONG", (struct objfile *) NULL); |
| 331 | builtin_type_chill_ulong = |
| 332 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 333 | TYPE_FLAG_UNSIGNED, |
| 334 | "ULONG", (struct objfile *) NULL); |
| 335 | builtin_type_chill_real = |
| 336 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 337 | 0, |
| 338 | "LONG_REAL", (struct objfile *) NULL); |
| 339 | |
| 340 | add_language (&chill_language_defn); |
| 341 | } |