| 1 | /* Print in infix form a struct expression. |
| 2 | |
| 3 | Copyright (C) 1986-2018 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 | #include "defs.h" |
| 21 | #include "symtab.h" |
| 22 | #include "gdbtypes.h" |
| 23 | #include "expression.h" |
| 24 | #include "value.h" |
| 25 | #include "language.h" |
| 26 | #include "parser-defs.h" |
| 27 | #include "user-regs.h" /* For user_reg_map_regnum_to_name. */ |
| 28 | #include "target.h" |
| 29 | #include "block.h" |
| 30 | #include "objfiles.h" |
| 31 | #include "valprint.h" |
| 32 | |
| 33 | #include <ctype.h> |
| 34 | |
| 35 | void |
| 36 | print_expression (struct expression *exp, struct ui_file *stream) |
| 37 | { |
| 38 | int pc = 0; |
| 39 | |
| 40 | print_subexp (exp, &pc, stream, PREC_NULL); |
| 41 | } |
| 42 | |
| 43 | /* Print the subexpression of EXP that starts in position POS, on STREAM. |
| 44 | PREC is the precedence of the surrounding operator; |
| 45 | if the precedence of the main operator of this subexpression is less, |
| 46 | parentheses are needed here. */ |
| 47 | |
| 48 | void |
| 49 | print_subexp (struct expression *exp, int *pos, |
| 50 | struct ui_file *stream, enum precedence prec) |
| 51 | { |
| 52 | exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec); |
| 53 | } |
| 54 | |
| 55 | /* Standard implementation of print_subexp for use in language_defn |
| 56 | vectors. */ |
| 57 | void |
| 58 | print_subexp_standard (struct expression *exp, int *pos, |
| 59 | struct ui_file *stream, enum precedence prec) |
| 60 | { |
| 61 | unsigned tem; |
| 62 | const struct op_print *op_print_tab; |
| 63 | int pc; |
| 64 | unsigned nargs; |
| 65 | const char *op_str; |
| 66 | int assign_modify = 0; |
| 67 | enum exp_opcode opcode; |
| 68 | enum precedence myprec = PREC_NULL; |
| 69 | /* Set to 1 for a right-associative operator. */ |
| 70 | int assoc = 0; |
| 71 | struct value *val; |
| 72 | char *tempstr = NULL; |
| 73 | |
| 74 | op_print_tab = exp->language_defn->la_op_print_tab; |
| 75 | pc = (*pos)++; |
| 76 | opcode = exp->elts[pc].opcode; |
| 77 | switch (opcode) |
| 78 | { |
| 79 | /* Common ops */ |
| 80 | |
| 81 | case OP_TYPE: |
| 82 | (*pos) += 2; |
| 83 | type_print (exp->elts[pc + 1].type, "", stream, 0); |
| 84 | return; |
| 85 | |
| 86 | case OP_SCOPE: |
| 87 | myprec = PREC_PREFIX; |
| 88 | assoc = 0; |
| 89 | fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream); |
| 90 | fputs_filtered ("::", stream); |
| 91 | nargs = longest_to_int (exp->elts[pc + 2].longconst); |
| 92 | (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1); |
| 93 | fputs_filtered (&exp->elts[pc + 3].string, stream); |
| 94 | return; |
| 95 | |
| 96 | case OP_LONG: |
| 97 | { |
| 98 | struct value_print_options opts; |
| 99 | |
| 100 | get_no_prettyformat_print_options (&opts); |
| 101 | (*pos) += 3; |
| 102 | value_print (value_from_longest (exp->elts[pc + 1].type, |
| 103 | exp->elts[pc + 2].longconst), |
| 104 | stream, &opts); |
| 105 | } |
| 106 | return; |
| 107 | |
| 108 | case OP_FLOAT: |
| 109 | { |
| 110 | struct value_print_options opts; |
| 111 | |
| 112 | get_no_prettyformat_print_options (&opts); |
| 113 | (*pos) += 3; |
| 114 | value_print (value_from_contents (exp->elts[pc + 1].type, |
| 115 | exp->elts[pc + 2].floatconst), |
| 116 | stream, &opts); |
| 117 | } |
| 118 | return; |
| 119 | |
| 120 | case OP_VAR_VALUE: |
| 121 | { |
| 122 | const struct block *b; |
| 123 | |
| 124 | (*pos) += 3; |
| 125 | b = exp->elts[pc + 1].block; |
| 126 | if (b != NULL |
| 127 | && BLOCK_FUNCTION (b) != NULL |
| 128 | && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL) |
| 129 | { |
| 130 | fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream); |
| 131 | fputs_filtered ("::", stream); |
| 132 | } |
| 133 | fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream); |
| 134 | } |
| 135 | return; |
| 136 | |
| 137 | case OP_VAR_MSYM_VALUE: |
| 138 | { |
| 139 | (*pos) += 3; |
| 140 | fputs_filtered (MSYMBOL_PRINT_NAME (exp->elts[pc + 2].msymbol), stream); |
| 141 | } |
| 142 | return; |
| 143 | |
| 144 | case OP_FUNC_STATIC_VAR: |
| 145 | { |
| 146 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
| 147 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
| 148 | fputs_filtered (&exp->elts[pc + 1].string, stream); |
| 149 | } |
| 150 | return; |
| 151 | |
| 152 | case OP_VAR_ENTRY_VALUE: |
| 153 | { |
| 154 | (*pos) += 2; |
| 155 | fprintf_filtered (stream, "%s@entry", |
| 156 | SYMBOL_PRINT_NAME (exp->elts[pc + 1].symbol)); |
| 157 | } |
| 158 | return; |
| 159 | |
| 160 | case OP_LAST: |
| 161 | (*pos) += 2; |
| 162 | fprintf_filtered (stream, "$%d", |
| 163 | longest_to_int (exp->elts[pc + 1].longconst)); |
| 164 | return; |
| 165 | |
| 166 | case OP_REGISTER: |
| 167 | { |
| 168 | const char *name = &exp->elts[pc + 2].string; |
| 169 | |
| 170 | (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1); |
| 171 | fprintf_filtered (stream, "$%s", name); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | case OP_BOOL: |
| 176 | (*pos) += 2; |
| 177 | fprintf_filtered (stream, "%s", |
| 178 | longest_to_int (exp->elts[pc + 1].longconst) |
| 179 | ? "TRUE" : "FALSE"); |
| 180 | return; |
| 181 | |
| 182 | case OP_INTERNALVAR: |
| 183 | (*pos) += 2; |
| 184 | fprintf_filtered (stream, "$%s", |
| 185 | internalvar_name (exp->elts[pc + 1].internalvar)); |
| 186 | return; |
| 187 | |
| 188 | case OP_FUNCALL: |
| 189 | case OP_F77_UNDETERMINED_ARGLIST: |
| 190 | (*pos) += 2; |
| 191 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
| 192 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 193 | fputs_filtered (" (", stream); |
| 194 | for (tem = 0; tem < nargs; tem++) |
| 195 | { |
| 196 | if (tem != 0) |
| 197 | fputs_filtered (", ", stream); |
| 198 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 199 | } |
| 200 | fputs_filtered (")", stream); |
| 201 | return; |
| 202 | |
| 203 | case OP_NAME: |
| 204 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
| 205 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); |
| 206 | fputs_filtered (&exp->elts[pc + 2].string, stream); |
| 207 | return; |
| 208 | |
| 209 | case OP_STRING: |
| 210 | { |
| 211 | struct value_print_options opts; |
| 212 | |
| 213 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
| 214 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); |
| 215 | /* LA_PRINT_STRING will print using the current repeat count threshold. |
| 216 | If necessary, we can temporarily set it to zero, or pass it as an |
| 217 | additional parameter to LA_PRINT_STRING. -fnf */ |
| 218 | get_user_print_options (&opts); |
| 219 | LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, |
| 220 | (gdb_byte *) &exp->elts[pc + 2].string, nargs, |
| 221 | NULL, 0, &opts); |
| 222 | } |
| 223 | return; |
| 224 | |
| 225 | case OP_OBJC_NSSTRING: /* Objective-C Foundation Class |
| 226 | NSString constant. */ |
| 227 | { |
| 228 | struct value_print_options opts; |
| 229 | |
| 230 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
| 231 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); |
| 232 | fputs_filtered ("@\"", stream); |
| 233 | get_user_print_options (&opts); |
| 234 | LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, |
| 235 | (gdb_byte *) &exp->elts[pc + 2].string, nargs, |
| 236 | NULL, 0, &opts); |
| 237 | fputs_filtered ("\"", stream); |
| 238 | } |
| 239 | return; |
| 240 | |
| 241 | case OP_OBJC_MSGCALL: |
| 242 | { /* Objective C message (method) call. */ |
| 243 | gdb::unique_xmalloc_ptr<char> selector; |
| 244 | |
| 245 | (*pos) += 3; |
| 246 | nargs = longest_to_int (exp->elts[pc + 2].longconst); |
| 247 | fprintf_unfiltered (stream, "["); |
| 248 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 249 | if (0 == target_read_string (exp->elts[pc + 1].longconst, |
| 250 | &selector, 1024, NULL)) |
| 251 | { |
| 252 | error (_("bad selector")); |
| 253 | return; |
| 254 | } |
| 255 | if (nargs) |
| 256 | { |
| 257 | char *s, *nextS; |
| 258 | |
| 259 | s = selector.get (); |
| 260 | for (tem = 0; tem < nargs; tem++) |
| 261 | { |
| 262 | nextS = strchr (s, ':'); |
| 263 | gdb_assert (nextS); /* Make sure we found ':'. */ |
| 264 | *nextS = '\0'; |
| 265 | fprintf_unfiltered (stream, " %s: ", s); |
| 266 | s = nextS + 1; |
| 267 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 268 | } |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | fprintf_unfiltered (stream, " %s", selector.get ()); |
| 273 | } |
| 274 | fprintf_unfiltered (stream, "]"); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | case OP_ARRAY: |
| 279 | (*pos) += 3; |
| 280 | nargs = longest_to_int (exp->elts[pc + 2].longconst); |
| 281 | nargs -= longest_to_int (exp->elts[pc + 1].longconst); |
| 282 | nargs++; |
| 283 | tem = 0; |
| 284 | if (exp->elts[pc + 4].opcode == OP_LONG |
| 285 | && exp->elts[pc + 5].type |
| 286 | == builtin_type (exp->gdbarch)->builtin_char |
| 287 | && exp->language_defn->la_language == language_c) |
| 288 | { |
| 289 | /* Attempt to print C character arrays using string syntax. |
| 290 | Walk through the args, picking up one character from each |
| 291 | of the OP_LONG expression elements. If any array element |
| 292 | does not match our expection of what we should find for |
| 293 | a simple string, revert back to array printing. Note that |
| 294 | the last expression element is an explicit null terminator |
| 295 | byte, which doesn't get printed. */ |
| 296 | tempstr = (char *) alloca (nargs); |
| 297 | pc += 4; |
| 298 | while (tem < nargs) |
| 299 | { |
| 300 | if (exp->elts[pc].opcode != OP_LONG |
| 301 | || exp->elts[pc + 1].type |
| 302 | != builtin_type (exp->gdbarch)->builtin_char) |
| 303 | { |
| 304 | /* Not a simple array of char, use regular array |
| 305 | printing. */ |
| 306 | tem = 0; |
| 307 | break; |
| 308 | } |
| 309 | else |
| 310 | { |
| 311 | tempstr[tem++] = |
| 312 | longest_to_int (exp->elts[pc + 2].longconst); |
| 313 | pc += 4; |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | if (tem > 0) |
| 318 | { |
| 319 | struct value_print_options opts; |
| 320 | |
| 321 | get_user_print_options (&opts); |
| 322 | LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, |
| 323 | (gdb_byte *) tempstr, nargs - 1, NULL, 0, &opts); |
| 324 | (*pos) = pc; |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | fputs_filtered (" {", stream); |
| 329 | for (tem = 0; tem < nargs; tem++) |
| 330 | { |
| 331 | if (tem != 0) |
| 332 | { |
| 333 | fputs_filtered (", ", stream); |
| 334 | } |
| 335 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 336 | } |
| 337 | fputs_filtered ("}", stream); |
| 338 | } |
| 339 | return; |
| 340 | |
| 341 | case TERNOP_COND: |
| 342 | if ((int) prec > (int) PREC_COMMA) |
| 343 | fputs_filtered ("(", stream); |
| 344 | /* Print the subexpressions, forcing parentheses |
| 345 | around any binary operations within them. |
| 346 | This is more parentheses than are strictly necessary, |
| 347 | but it looks clearer. */ |
| 348 | print_subexp (exp, pos, stream, PREC_HYPER); |
| 349 | fputs_filtered (" ? ", stream); |
| 350 | print_subexp (exp, pos, stream, PREC_HYPER); |
| 351 | fputs_filtered (" : ", stream); |
| 352 | print_subexp (exp, pos, stream, PREC_HYPER); |
| 353 | if ((int) prec > (int) PREC_COMMA) |
| 354 | fputs_filtered (")", stream); |
| 355 | return; |
| 356 | |
| 357 | case TERNOP_SLICE: |
| 358 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 359 | fputs_filtered ("(", stream); |
| 360 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 361 | fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream); |
| 362 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 363 | fputs_filtered (")", stream); |
| 364 | return; |
| 365 | |
| 366 | case STRUCTOP_STRUCT: |
| 367 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
| 368 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
| 369 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 370 | fputs_filtered (".", stream); |
| 371 | fputs_filtered (&exp->elts[pc + 2].string, stream); |
| 372 | return; |
| 373 | |
| 374 | /* Will not occur for Modula-2. */ |
| 375 | case STRUCTOP_PTR: |
| 376 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
| 377 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
| 378 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 379 | fputs_filtered ("->", stream); |
| 380 | fputs_filtered (&exp->elts[pc + 2].string, stream); |
| 381 | return; |
| 382 | |
| 383 | case STRUCTOP_MEMBER: |
| 384 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 385 | fputs_filtered (".*", stream); |
| 386 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 387 | return; |
| 388 | |
| 389 | case STRUCTOP_MPTR: |
| 390 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 391 | fputs_filtered ("->*", stream); |
| 392 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 393 | return; |
| 394 | |
| 395 | case BINOP_SUBSCRIPT: |
| 396 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 397 | fputs_filtered ("[", stream); |
| 398 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 399 | fputs_filtered ("]", stream); |
| 400 | return; |
| 401 | |
| 402 | case UNOP_POSTINCREMENT: |
| 403 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 404 | fputs_filtered ("++", stream); |
| 405 | return; |
| 406 | |
| 407 | case UNOP_POSTDECREMENT: |
| 408 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 409 | fputs_filtered ("--", stream); |
| 410 | return; |
| 411 | |
| 412 | case UNOP_CAST: |
| 413 | (*pos) += 2; |
| 414 | if ((int) prec > (int) PREC_PREFIX) |
| 415 | fputs_filtered ("(", stream); |
| 416 | fputs_filtered ("(", stream); |
| 417 | type_print (exp->elts[pc + 1].type, "", stream, 0); |
| 418 | fputs_filtered (") ", stream); |
| 419 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 420 | if ((int) prec > (int) PREC_PREFIX) |
| 421 | fputs_filtered (")", stream); |
| 422 | return; |
| 423 | |
| 424 | case UNOP_CAST_TYPE: |
| 425 | if ((int) prec > (int) PREC_PREFIX) |
| 426 | fputs_filtered ("(", stream); |
| 427 | fputs_filtered ("(", stream); |
| 428 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 429 | fputs_filtered (") ", stream); |
| 430 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 431 | if ((int) prec > (int) PREC_PREFIX) |
| 432 | fputs_filtered (")", stream); |
| 433 | return; |
| 434 | |
| 435 | case UNOP_DYNAMIC_CAST: |
| 436 | case UNOP_REINTERPRET_CAST: |
| 437 | fputs_filtered (opcode == UNOP_DYNAMIC_CAST ? "dynamic_cast" |
| 438 | : "reinterpret_cast", stream); |
| 439 | fputs_filtered ("<", stream); |
| 440 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 441 | fputs_filtered ("> (", stream); |
| 442 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 443 | fputs_filtered (")", stream); |
| 444 | return; |
| 445 | |
| 446 | case UNOP_MEMVAL: |
| 447 | (*pos) += 2; |
| 448 | if ((int) prec > (int) PREC_PREFIX) |
| 449 | fputs_filtered ("(", stream); |
| 450 | if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC |
| 451 | && exp->elts[pc + 3].opcode == OP_LONG) |
| 452 | { |
| 453 | struct value_print_options opts; |
| 454 | |
| 455 | /* We have a minimal symbol fn, probably. It's encoded |
| 456 | as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address). |
| 457 | Swallow the OP_LONG (including both its opcodes); ignore |
| 458 | its type; print the value in the type of the MEMVAL. */ |
| 459 | (*pos) += 4; |
| 460 | val = value_at_lazy (exp->elts[pc + 1].type, |
| 461 | (CORE_ADDR) exp->elts[pc + 5].longconst); |
| 462 | get_no_prettyformat_print_options (&opts); |
| 463 | value_print (val, stream, &opts); |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | fputs_filtered ("{", stream); |
| 468 | type_print (exp->elts[pc + 1].type, "", stream, 0); |
| 469 | fputs_filtered ("} ", stream); |
| 470 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 471 | } |
| 472 | if ((int) prec > (int) PREC_PREFIX) |
| 473 | fputs_filtered (")", stream); |
| 474 | return; |
| 475 | |
| 476 | case UNOP_MEMVAL_TYPE: |
| 477 | if ((int) prec > (int) PREC_PREFIX) |
| 478 | fputs_filtered ("(", stream); |
| 479 | fputs_filtered ("{", stream); |
| 480 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 481 | fputs_filtered ("} ", stream); |
| 482 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 483 | if ((int) prec > (int) PREC_PREFIX) |
| 484 | fputs_filtered (")", stream); |
| 485 | return; |
| 486 | |
| 487 | case BINOP_ASSIGN_MODIFY: |
| 488 | opcode = exp->elts[pc + 1].opcode; |
| 489 | (*pos) += 2; |
| 490 | myprec = PREC_ASSIGN; |
| 491 | assoc = 1; |
| 492 | assign_modify = 1; |
| 493 | op_str = "???"; |
| 494 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) |
| 495 | if (op_print_tab[tem].opcode == opcode) |
| 496 | { |
| 497 | op_str = op_print_tab[tem].string; |
| 498 | break; |
| 499 | } |
| 500 | if (op_print_tab[tem].opcode != opcode) |
| 501 | /* Not found; don't try to keep going because we don't know how |
| 502 | to interpret further elements. */ |
| 503 | error (_("Invalid expression")); |
| 504 | break; |
| 505 | |
| 506 | /* C++ ops */ |
| 507 | |
| 508 | case OP_THIS: |
| 509 | ++(*pos); |
| 510 | if (exp->language_defn->la_name_of_this) |
| 511 | fputs_filtered (exp->language_defn->la_name_of_this, stream); |
| 512 | else |
| 513 | fprintf_filtered (stream, _("<language %s has no 'this'>"), |
| 514 | exp->language_defn->la_name); |
| 515 | return; |
| 516 | |
| 517 | /* Modula-2 ops */ |
| 518 | |
| 519 | case MULTI_SUBSCRIPT: |
| 520 | (*pos) += 2; |
| 521 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
| 522 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 523 | fprintf_unfiltered (stream, " ["); |
| 524 | for (tem = 0; tem < nargs; tem++) |
| 525 | { |
| 526 | if (tem != 0) |
| 527 | fprintf_unfiltered (stream, ", "); |
| 528 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 529 | } |
| 530 | fprintf_unfiltered (stream, "]"); |
| 531 | return; |
| 532 | |
| 533 | case BINOP_VAL: |
| 534 | (*pos) += 2; |
| 535 | fprintf_unfiltered (stream, "VAL("); |
| 536 | type_print (exp->elts[pc + 1].type, "", stream, 0); |
| 537 | fprintf_unfiltered (stream, ","); |
| 538 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 539 | fprintf_unfiltered (stream, ")"); |
| 540 | return; |
| 541 | |
| 542 | case TYPE_INSTANCE: |
| 543 | { |
| 544 | type_instance_flags flags |
| 545 | = (type_instance_flag_value) longest_to_int (exp->elts[pc + 1].longconst); |
| 546 | LONGEST count = exp->elts[pc + 2].longconst; |
| 547 | |
| 548 | /* The FLAGS. */ |
| 549 | (*pos)++; |
| 550 | /* The COUNT. */ |
| 551 | (*pos)++; |
| 552 | fputs_unfiltered ("TypeInstance(", stream); |
| 553 | while (count-- > 0) |
| 554 | { |
| 555 | type_print (exp->elts[(*pos)++].type, "", stream, 0); |
| 556 | if (count > 0) |
| 557 | fputs_unfiltered (",", stream); |
| 558 | } |
| 559 | fputs_unfiltered (",", stream); |
| 560 | /* Ending COUNT and ending TYPE_INSTANCE. */ |
| 561 | (*pos) += 2; |
| 562 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 563 | |
| 564 | if (flags & TYPE_INSTANCE_FLAG_CONST) |
| 565 | fputs_unfiltered (",const", stream); |
| 566 | if (flags & TYPE_INSTANCE_FLAG_VOLATILE) |
| 567 | fputs_unfiltered (",volatile", stream); |
| 568 | |
| 569 | fputs_unfiltered (")", stream); |
| 570 | return; |
| 571 | } |
| 572 | |
| 573 | case OP_RANGE: |
| 574 | { |
| 575 | enum range_type range_type; |
| 576 | |
| 577 | range_type = (enum range_type) |
| 578 | longest_to_int (exp->elts[pc + 1].longconst); |
| 579 | *pos += 2; |
| 580 | |
| 581 | if (range_type == NONE_BOUND_DEFAULT_EXCLUSIVE |
| 582 | || range_type == LOW_BOUND_DEFAULT_EXCLUSIVE) |
| 583 | fputs_filtered ("EXCLUSIVE_", stream); |
| 584 | fputs_filtered ("RANGE(", stream); |
| 585 | if (range_type == HIGH_BOUND_DEFAULT |
| 586 | || range_type == NONE_BOUND_DEFAULT |
| 587 | || range_type == NONE_BOUND_DEFAULT_EXCLUSIVE) |
| 588 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 589 | fputs_filtered ("..", stream); |
| 590 | if (range_type == LOW_BOUND_DEFAULT |
| 591 | || range_type == NONE_BOUND_DEFAULT) |
| 592 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
| 593 | fputs_filtered (")", stream); |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | /* Default ops */ |
| 598 | |
| 599 | default: |
| 600 | op_str = "???"; |
| 601 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) |
| 602 | if (op_print_tab[tem].opcode == opcode) |
| 603 | { |
| 604 | op_str = op_print_tab[tem].string; |
| 605 | myprec = op_print_tab[tem].precedence; |
| 606 | assoc = op_print_tab[tem].right_assoc; |
| 607 | break; |
| 608 | } |
| 609 | if (op_print_tab[tem].opcode != opcode) |
| 610 | /* Not found; don't try to keep going because we don't know how |
| 611 | to interpret further elements. For example, this happens |
| 612 | if opcode is OP_TYPE. */ |
| 613 | error (_("Invalid expression")); |
| 614 | } |
| 615 | |
| 616 | /* Note that PREC_BUILTIN will always emit parentheses. */ |
| 617 | if ((int) myprec < (int) prec) |
| 618 | fputs_filtered ("(", stream); |
| 619 | if ((int) opcode > (int) BINOP_END) |
| 620 | { |
| 621 | if (assoc) |
| 622 | { |
| 623 | /* Unary postfix operator. */ |
| 624 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
| 625 | fputs_filtered (op_str, stream); |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | /* Unary prefix operator. */ |
| 630 | fputs_filtered (op_str, stream); |
| 631 | if (myprec == PREC_BUILTIN_FUNCTION) |
| 632 | fputs_filtered ("(", stream); |
| 633 | print_subexp (exp, pos, stream, PREC_PREFIX); |
| 634 | if (myprec == PREC_BUILTIN_FUNCTION) |
| 635 | fputs_filtered (")", stream); |
| 636 | } |
| 637 | } |
| 638 | else |
| 639 | { |
| 640 | /* Binary operator. */ |
| 641 | /* Print left operand. |
| 642 | If operator is right-associative, |
| 643 | increment precedence for this operand. */ |
| 644 | print_subexp (exp, pos, stream, |
| 645 | (enum precedence) ((int) myprec + assoc)); |
| 646 | /* Print the operator itself. */ |
| 647 | if (assign_modify) |
| 648 | fprintf_filtered (stream, " %s= ", op_str); |
| 649 | else if (op_str[0] == ',') |
| 650 | fprintf_filtered (stream, "%s ", op_str); |
| 651 | else |
| 652 | fprintf_filtered (stream, " %s ", op_str); |
| 653 | /* Print right operand. |
| 654 | If operator is left-associative, |
| 655 | increment precedence for this operand. */ |
| 656 | print_subexp (exp, pos, stream, |
| 657 | (enum precedence) ((int) myprec + !assoc)); |
| 658 | } |
| 659 | |
| 660 | if ((int) myprec < (int) prec) |
| 661 | fputs_filtered (")", stream); |
| 662 | } |
| 663 | |
| 664 | /* Return the operator corresponding to opcode OP as |
| 665 | a string. NULL indicates that the opcode was not found in the |
| 666 | current language table. */ |
| 667 | const char * |
| 668 | op_string (enum exp_opcode op) |
| 669 | { |
| 670 | int tem; |
| 671 | const struct op_print *op_print_tab; |
| 672 | |
| 673 | op_print_tab = current_language->la_op_print_tab; |
| 674 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) |
| 675 | if (op_print_tab[tem].opcode == op) |
| 676 | return op_print_tab[tem].string; |
| 677 | return NULL; |
| 678 | } |
| 679 | |
| 680 | /* Support for dumping the raw data from expressions in a human readable |
| 681 | form. */ |
| 682 | |
| 683 | static int dump_subexp_body (struct expression *exp, struct ui_file *, int); |
| 684 | |
| 685 | /* Name for OPCODE, when it appears in expression EXP. */ |
| 686 | |
| 687 | const char * |
| 688 | op_name (struct expression *exp, enum exp_opcode opcode) |
| 689 | { |
| 690 | return exp->language_defn->la_exp_desc->op_name (opcode); |
| 691 | } |
| 692 | |
| 693 | /* Default name for the standard operator OPCODE (i.e., one defined in |
| 694 | the definition of enum exp_opcode). */ |
| 695 | |
| 696 | const char * |
| 697 | op_name_standard (enum exp_opcode opcode) |
| 698 | { |
| 699 | switch (opcode) |
| 700 | { |
| 701 | default: |
| 702 | { |
| 703 | static char buf[30]; |
| 704 | |
| 705 | xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode); |
| 706 | return buf; |
| 707 | } |
| 708 | #define OP(name) \ |
| 709 | case name: \ |
| 710 | return #name ; |
| 711 | #include "std-operator.def" |
| 712 | #undef OP |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | /* Print a raw dump of expression EXP to STREAM. |
| 717 | NOTE, if non-NULL, is printed as extra explanatory text. */ |
| 718 | |
| 719 | void |
| 720 | dump_raw_expression (struct expression *exp, struct ui_file *stream, |
| 721 | const char *note) |
| 722 | { |
| 723 | int elt; |
| 724 | char *eltscan; |
| 725 | int eltsize; |
| 726 | |
| 727 | fprintf_filtered (stream, "Dump of expression @ "); |
| 728 | gdb_print_host_address (exp, stream); |
| 729 | if (note) |
| 730 | fprintf_filtered (stream, ", %s:", note); |
| 731 | fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n", |
| 732 | exp->language_defn->la_name, exp->nelts, |
| 733 | (long) sizeof (union exp_element)); |
| 734 | fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode", |
| 735 | "Hex Value", "String Value"); |
| 736 | for (elt = 0; elt < exp->nelts; elt++) |
| 737 | { |
| 738 | fprintf_filtered (stream, "\t%5d ", elt); |
| 739 | |
| 740 | const char *opcode_name = op_name (exp, exp->elts[elt].opcode); |
| 741 | fprintf_filtered (stream, "%20s ", opcode_name); |
| 742 | |
| 743 | print_longest (stream, 'd', 0, exp->elts[elt].longconst); |
| 744 | fprintf_filtered (stream, " "); |
| 745 | |
| 746 | for (eltscan = (char *) &exp->elts[elt], |
| 747 | eltsize = sizeof (union exp_element); |
| 748 | eltsize-- > 0; |
| 749 | eltscan++) |
| 750 | { |
| 751 | fprintf_filtered (stream, "%c", |
| 752 | isprint (*eltscan) ? (*eltscan & 0xFF) : '.'); |
| 753 | } |
| 754 | fprintf_filtered (stream, "\n"); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | /* Dump the subexpression of prefix expression EXP whose operator is at |
| 759 | position ELT onto STREAM. Returns the position of the next |
| 760 | subexpression in EXP. */ |
| 761 | |
| 762 | int |
| 763 | dump_subexp (struct expression *exp, struct ui_file *stream, int elt) |
| 764 | { |
| 765 | static int indent = 0; |
| 766 | int i; |
| 767 | |
| 768 | fprintf_filtered (stream, "\n"); |
| 769 | fprintf_filtered (stream, "\t%5d ", elt); |
| 770 | |
| 771 | for (i = 1; i <= indent; i++) |
| 772 | fprintf_filtered (stream, " "); |
| 773 | indent += 2; |
| 774 | |
| 775 | fprintf_filtered (stream, "%-20s ", op_name (exp, exp->elts[elt].opcode)); |
| 776 | |
| 777 | elt = dump_subexp_body (exp, stream, elt); |
| 778 | |
| 779 | indent -= 2; |
| 780 | |
| 781 | return elt; |
| 782 | } |
| 783 | |
| 784 | /* Dump the operands of prefix expression EXP whose opcode is at |
| 785 | position ELT onto STREAM. Returns the position of the next |
| 786 | subexpression in EXP. */ |
| 787 | |
| 788 | static int |
| 789 | dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt) |
| 790 | { |
| 791 | return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt); |
| 792 | } |
| 793 | |
| 794 | /* Default value for subexp_body in exp_descriptor vector. */ |
| 795 | |
| 796 | int |
| 797 | dump_subexp_body_standard (struct expression *exp, |
| 798 | struct ui_file *stream, int elt) |
| 799 | { |
| 800 | int opcode = exp->elts[elt++].opcode; |
| 801 | |
| 802 | switch (opcode) |
| 803 | { |
| 804 | case TERNOP_COND: |
| 805 | case TERNOP_SLICE: |
| 806 | elt = dump_subexp (exp, stream, elt); |
| 807 | /* FALL THROUGH */ |
| 808 | case BINOP_ADD: |
| 809 | case BINOP_SUB: |
| 810 | case BINOP_MUL: |
| 811 | case BINOP_DIV: |
| 812 | case BINOP_REM: |
| 813 | case BINOP_MOD: |
| 814 | case BINOP_LSH: |
| 815 | case BINOP_RSH: |
| 816 | case BINOP_LOGICAL_AND: |
| 817 | case BINOP_LOGICAL_OR: |
| 818 | case BINOP_BITWISE_AND: |
| 819 | case BINOP_BITWISE_IOR: |
| 820 | case BINOP_BITWISE_XOR: |
| 821 | case BINOP_EQUAL: |
| 822 | case BINOP_NOTEQUAL: |
| 823 | case BINOP_LESS: |
| 824 | case BINOP_GTR: |
| 825 | case BINOP_LEQ: |
| 826 | case BINOP_GEQ: |
| 827 | case BINOP_REPEAT: |
| 828 | case BINOP_ASSIGN: |
| 829 | case BINOP_COMMA: |
| 830 | case BINOP_SUBSCRIPT: |
| 831 | case BINOP_EXP: |
| 832 | case BINOP_MIN: |
| 833 | case BINOP_MAX: |
| 834 | case BINOP_INTDIV: |
| 835 | case BINOP_ASSIGN_MODIFY: |
| 836 | case BINOP_VAL: |
| 837 | case BINOP_CONCAT: |
| 838 | case BINOP_END: |
| 839 | case STRUCTOP_MEMBER: |
| 840 | case STRUCTOP_MPTR: |
| 841 | elt = dump_subexp (exp, stream, elt); |
| 842 | /* FALL THROUGH */ |
| 843 | case UNOP_NEG: |
| 844 | case UNOP_LOGICAL_NOT: |
| 845 | case UNOP_COMPLEMENT: |
| 846 | case UNOP_IND: |
| 847 | case UNOP_ADDR: |
| 848 | case UNOP_PREINCREMENT: |
| 849 | case UNOP_POSTINCREMENT: |
| 850 | case UNOP_PREDECREMENT: |
| 851 | case UNOP_POSTDECREMENT: |
| 852 | case UNOP_SIZEOF: |
| 853 | case UNOP_ALIGNOF: |
| 854 | case UNOP_PLUS: |
| 855 | case UNOP_CAP: |
| 856 | case UNOP_CHR: |
| 857 | case UNOP_ORD: |
| 858 | case UNOP_ABS: |
| 859 | case UNOP_FLOAT: |
| 860 | case UNOP_HIGH: |
| 861 | case UNOP_MAX: |
| 862 | case UNOP_MIN: |
| 863 | case UNOP_ODD: |
| 864 | case UNOP_TRUNC: |
| 865 | elt = dump_subexp (exp, stream, elt); |
| 866 | break; |
| 867 | case OP_LONG: |
| 868 | fprintf_filtered (stream, "Type @"); |
| 869 | gdb_print_host_address (exp->elts[elt].type, stream); |
| 870 | fprintf_filtered (stream, " ("); |
| 871 | type_print (exp->elts[elt].type, NULL, stream, 0); |
| 872 | fprintf_filtered (stream, "), value %ld (0x%lx)", |
| 873 | (long) exp->elts[elt + 1].longconst, |
| 874 | (long) exp->elts[elt + 1].longconst); |
| 875 | elt += 3; |
| 876 | break; |
| 877 | case OP_FLOAT: |
| 878 | fprintf_filtered (stream, "Type @"); |
| 879 | gdb_print_host_address (exp->elts[elt].type, stream); |
| 880 | fprintf_filtered (stream, " ("); |
| 881 | type_print (exp->elts[elt].type, NULL, stream, 0); |
| 882 | fprintf_filtered (stream, "), value "); |
| 883 | print_floating (exp->elts[elt + 1].floatconst, |
| 884 | exp->elts[elt].type, stream); |
| 885 | elt += 3; |
| 886 | break; |
| 887 | case OP_VAR_VALUE: |
| 888 | fprintf_filtered (stream, "Block @"); |
| 889 | gdb_print_host_address (exp->elts[elt].block, stream); |
| 890 | fprintf_filtered (stream, ", symbol @"); |
| 891 | gdb_print_host_address (exp->elts[elt + 1].symbol, stream); |
| 892 | fprintf_filtered (stream, " (%s)", |
| 893 | SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol)); |
| 894 | elt += 3; |
| 895 | break; |
| 896 | case OP_VAR_MSYM_VALUE: |
| 897 | fprintf_filtered (stream, "Objfile @"); |
| 898 | gdb_print_host_address (exp->elts[elt].objfile, stream); |
| 899 | fprintf_filtered (stream, ", msymbol @"); |
| 900 | gdb_print_host_address (exp->elts[elt + 1].msymbol, stream); |
| 901 | fprintf_filtered (stream, " (%s)", |
| 902 | MSYMBOL_PRINT_NAME (exp->elts[elt + 1].msymbol)); |
| 903 | elt += 3; |
| 904 | break; |
| 905 | case OP_VAR_ENTRY_VALUE: |
| 906 | fprintf_filtered (stream, "Entry value of symbol @"); |
| 907 | gdb_print_host_address (exp->elts[elt].symbol, stream); |
| 908 | fprintf_filtered (stream, " (%s)", |
| 909 | SYMBOL_PRINT_NAME (exp->elts[elt].symbol)); |
| 910 | elt += 2; |
| 911 | break; |
| 912 | case OP_LAST: |
| 913 | fprintf_filtered (stream, "History element %ld", |
| 914 | (long) exp->elts[elt].longconst); |
| 915 | elt += 2; |
| 916 | break; |
| 917 | case OP_REGISTER: |
| 918 | fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string); |
| 919 | elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1); |
| 920 | break; |
| 921 | case OP_INTERNALVAR: |
| 922 | fprintf_filtered (stream, "Internal var @"); |
| 923 | gdb_print_host_address (exp->elts[elt].internalvar, stream); |
| 924 | fprintf_filtered (stream, " (%s)", |
| 925 | internalvar_name (exp->elts[elt].internalvar)); |
| 926 | elt += 2; |
| 927 | break; |
| 928 | case OP_FUNCALL: |
| 929 | case OP_F77_UNDETERMINED_ARGLIST: |
| 930 | { |
| 931 | int i, nargs; |
| 932 | |
| 933 | nargs = longest_to_int (exp->elts[elt].longconst); |
| 934 | |
| 935 | fprintf_filtered (stream, "Number of args: %d", nargs); |
| 936 | elt += 2; |
| 937 | |
| 938 | for (i = 1; i <= nargs + 1; i++) |
| 939 | elt = dump_subexp (exp, stream, elt); |
| 940 | } |
| 941 | break; |
| 942 | case OP_ARRAY: |
| 943 | { |
| 944 | int lower, upper; |
| 945 | int i; |
| 946 | |
| 947 | lower = longest_to_int (exp->elts[elt].longconst); |
| 948 | upper = longest_to_int (exp->elts[elt + 1].longconst); |
| 949 | |
| 950 | fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper); |
| 951 | elt += 3; |
| 952 | |
| 953 | for (i = 1; i <= upper - lower + 1; i++) |
| 954 | elt = dump_subexp (exp, stream, elt); |
| 955 | } |
| 956 | break; |
| 957 | case UNOP_DYNAMIC_CAST: |
| 958 | case UNOP_REINTERPRET_CAST: |
| 959 | case UNOP_CAST_TYPE: |
| 960 | case UNOP_MEMVAL_TYPE: |
| 961 | fprintf_filtered (stream, " ("); |
| 962 | elt = dump_subexp (exp, stream, elt); |
| 963 | fprintf_filtered (stream, ")"); |
| 964 | elt = dump_subexp (exp, stream, elt); |
| 965 | break; |
| 966 | case UNOP_MEMVAL: |
| 967 | case UNOP_CAST: |
| 968 | fprintf_filtered (stream, "Type @"); |
| 969 | gdb_print_host_address (exp->elts[elt].type, stream); |
| 970 | fprintf_filtered (stream, " ("); |
| 971 | type_print (exp->elts[elt].type, NULL, stream, 0); |
| 972 | fprintf_filtered (stream, ")"); |
| 973 | elt = dump_subexp (exp, stream, elt + 2); |
| 974 | break; |
| 975 | case OP_TYPE: |
| 976 | fprintf_filtered (stream, "Type @"); |
| 977 | gdb_print_host_address (exp->elts[elt].type, stream); |
| 978 | fprintf_filtered (stream, " ("); |
| 979 | type_print (exp->elts[elt].type, NULL, stream, 0); |
| 980 | fprintf_filtered (stream, ")"); |
| 981 | elt += 2; |
| 982 | break; |
| 983 | case OP_TYPEOF: |
| 984 | case OP_DECLTYPE: |
| 985 | fprintf_filtered (stream, "Typeof ("); |
| 986 | elt = dump_subexp (exp, stream, elt); |
| 987 | fprintf_filtered (stream, ")"); |
| 988 | break; |
| 989 | case OP_TYPEID: |
| 990 | fprintf_filtered (stream, "typeid ("); |
| 991 | elt = dump_subexp (exp, stream, elt); |
| 992 | fprintf_filtered (stream, ")"); |
| 993 | break; |
| 994 | case STRUCTOP_STRUCT: |
| 995 | case STRUCTOP_PTR: |
| 996 | { |
| 997 | char *elem_name; |
| 998 | int len; |
| 999 | |
| 1000 | len = longest_to_int (exp->elts[elt].longconst); |
| 1001 | elem_name = &exp->elts[elt + 1].string; |
| 1002 | |
| 1003 | fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name); |
| 1004 | elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1)); |
| 1005 | } |
| 1006 | break; |
| 1007 | case OP_SCOPE: |
| 1008 | { |
| 1009 | char *elem_name; |
| 1010 | int len; |
| 1011 | |
| 1012 | fprintf_filtered (stream, "Type @"); |
| 1013 | gdb_print_host_address (exp->elts[elt].type, stream); |
| 1014 | fprintf_filtered (stream, " ("); |
| 1015 | type_print (exp->elts[elt].type, NULL, stream, 0); |
| 1016 | fprintf_filtered (stream, ") "); |
| 1017 | |
| 1018 | len = longest_to_int (exp->elts[elt + 1].longconst); |
| 1019 | elem_name = &exp->elts[elt + 2].string; |
| 1020 | |
| 1021 | fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name); |
| 1022 | elt += 4 + BYTES_TO_EXP_ELEM (len + 1); |
| 1023 | } |
| 1024 | break; |
| 1025 | |
| 1026 | case OP_FUNC_STATIC_VAR: |
| 1027 | { |
| 1028 | int len = longest_to_int (exp->elts[elt].longconst); |
| 1029 | const char *var_name = &exp->elts[elt + 1].string; |
| 1030 | fprintf_filtered (stream, "Field name: `%.*s'", len, var_name); |
| 1031 | elt += 3 + BYTES_TO_EXP_ELEM (len + 1); |
| 1032 | } |
| 1033 | break; |
| 1034 | |
| 1035 | case TYPE_INSTANCE: |
| 1036 | { |
| 1037 | type_instance_flags flags |
| 1038 | = (type_instance_flag_value) longest_to_int (exp->elts[elt++].longconst); |
| 1039 | LONGEST len = exp->elts[elt++].longconst; |
| 1040 | fprintf_filtered (stream, "%s TypeInstance: ", plongest (len)); |
| 1041 | while (len-- > 0) |
| 1042 | { |
| 1043 | fprintf_filtered (stream, "Type @"); |
| 1044 | gdb_print_host_address (exp->elts[elt].type, stream); |
| 1045 | fprintf_filtered (stream, " ("); |
| 1046 | type_print (exp->elts[elt].type, NULL, stream, 0); |
| 1047 | fprintf_filtered (stream, ")"); |
| 1048 | elt++; |
| 1049 | if (len > 0) |
| 1050 | fputs_filtered (", ", stream); |
| 1051 | } |
| 1052 | |
| 1053 | fprintf_filtered (stream, " Flags: %s (", hex_string (flags)); |
| 1054 | bool space = false; |
| 1055 | auto print_one = [&] (const char *mod) |
| 1056 | { |
| 1057 | if (space) |
| 1058 | fputs_filtered (" ", stream); |
| 1059 | space = true; |
| 1060 | fprintf_filtered (stream, "%s", mod); |
| 1061 | }; |
| 1062 | if (flags & TYPE_INSTANCE_FLAG_CONST) |
| 1063 | print_one ("const"); |
| 1064 | if (flags & TYPE_INSTANCE_FLAG_VOLATILE) |
| 1065 | print_one ("volatile"); |
| 1066 | fprintf_filtered (stream, ")"); |
| 1067 | |
| 1068 | /* Ending LEN and ending TYPE_INSTANCE. */ |
| 1069 | elt += 2; |
| 1070 | elt = dump_subexp (exp, stream, elt); |
| 1071 | } |
| 1072 | break; |
| 1073 | case OP_STRING: |
| 1074 | { |
| 1075 | LONGEST len = exp->elts[elt].longconst; |
| 1076 | LONGEST type = exp->elts[elt + 1].longconst; |
| 1077 | |
| 1078 | fprintf_filtered (stream, "Language-specific string type: %s", |
| 1079 | plongest (type)); |
| 1080 | |
| 1081 | /* Skip length. */ |
| 1082 | elt += 1; |
| 1083 | |
| 1084 | /* Skip string content. */ |
| 1085 | elt += BYTES_TO_EXP_ELEM (len); |
| 1086 | |
| 1087 | /* Skip length and ending OP_STRING. */ |
| 1088 | elt += 2; |
| 1089 | } |
| 1090 | break; |
| 1091 | case OP_RANGE: |
| 1092 | { |
| 1093 | enum range_type range_type; |
| 1094 | |
| 1095 | range_type = (enum range_type) |
| 1096 | longest_to_int (exp->elts[elt].longconst); |
| 1097 | elt += 2; |
| 1098 | |
| 1099 | switch (range_type) |
| 1100 | { |
| 1101 | case BOTH_BOUND_DEFAULT: |
| 1102 | fputs_filtered ("Range '..'", stream); |
| 1103 | break; |
| 1104 | case LOW_BOUND_DEFAULT: |
| 1105 | fputs_filtered ("Range '..EXP'", stream); |
| 1106 | break; |
| 1107 | case LOW_BOUND_DEFAULT_EXCLUSIVE: |
| 1108 | fputs_filtered ("ExclusiveRange '..EXP'", stream); |
| 1109 | break; |
| 1110 | case HIGH_BOUND_DEFAULT: |
| 1111 | fputs_filtered ("Range 'EXP..'", stream); |
| 1112 | break; |
| 1113 | case NONE_BOUND_DEFAULT: |
| 1114 | fputs_filtered ("Range 'EXP..EXP'", stream); |
| 1115 | break; |
| 1116 | case NONE_BOUND_DEFAULT_EXCLUSIVE: |
| 1117 | fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream); |
| 1118 | break; |
| 1119 | default: |
| 1120 | fputs_filtered ("Invalid Range!", stream); |
| 1121 | break; |
| 1122 | } |
| 1123 | |
| 1124 | if (range_type == HIGH_BOUND_DEFAULT |
| 1125 | || range_type == NONE_BOUND_DEFAULT) |
| 1126 | elt = dump_subexp (exp, stream, elt); |
| 1127 | if (range_type == LOW_BOUND_DEFAULT |
| 1128 | || range_type == NONE_BOUND_DEFAULT) |
| 1129 | elt = dump_subexp (exp, stream, elt); |
| 1130 | } |
| 1131 | break; |
| 1132 | |
| 1133 | default: |
| 1134 | case OP_NULL: |
| 1135 | case MULTI_SUBSCRIPT: |
| 1136 | case OP_COMPLEX: |
| 1137 | case OP_BOOL: |
| 1138 | case OP_M2_STRING: |
| 1139 | case OP_THIS: |
| 1140 | case OP_NAME: |
| 1141 | fprintf_filtered (stream, "Unknown format"); |
| 1142 | } |
| 1143 | |
| 1144 | return elt; |
| 1145 | } |
| 1146 | |
| 1147 | void |
| 1148 | dump_prefix_expression (struct expression *exp, struct ui_file *stream) |
| 1149 | { |
| 1150 | int elt; |
| 1151 | |
| 1152 | fprintf_filtered (stream, "Dump of expression @ "); |
| 1153 | gdb_print_host_address (exp, stream); |
| 1154 | fputs_filtered (", after conversion to prefix form:\nExpression: `", stream); |
| 1155 | print_expression (exp, stream); |
| 1156 | fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n", |
| 1157 | exp->language_defn->la_name, exp->nelts, |
| 1158 | (long) sizeof (union exp_element)); |
| 1159 | fputs_filtered ("\n", stream); |
| 1160 | |
| 1161 | for (elt = 0; elt < exp->nelts;) |
| 1162 | elt = dump_subexp (exp, stream, elt); |
| 1163 | fputs_filtered ("\n", stream); |
| 1164 | } |