expprint.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* Print in infix form a struct expression.
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "symtab.h"
  16. #include "gdbtypes.h"
  17. #include "expression.h"
  18. #include "value.h"
  19. #include "language.h"
  20. #include "parser-defs.h"
  21. #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
  22. #include "target.h"
  23. #include "block.h"
  24. #include "objfiles.h"
  25. #include "valprint.h"
  26. #include "cli/cli-style.h"
  27. #include "c-lang.h"
  28. #include "expop.h"
  29. #include "ada-exp.h"
  30. #include <ctype.h>
  31. /* Default name for the standard operator OPCODE (i.e., one defined in
  32. the definition of enum exp_opcode). */
  33. const char *
  34. op_name (enum exp_opcode opcode)
  35. {
  36. switch (opcode)
  37. {
  38. default:
  39. {
  40. static char buf[30];
  41. xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode);
  42. return buf;
  43. }
  44. #define OP(name) \
  45. case name: \
  46. return #name ;
  47. #include "std-operator.def"
  48. #undef OP
  49. }
  50. }
  51. void
  52. dump_prefix_expression (struct expression *exp, struct ui_file *stream)
  53. {
  54. exp->op->dump (stream, 0);
  55. }
  56. namespace expr
  57. {
  58. void
  59. dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op)
  60. {
  61. gdb_printf (stream, _("%*sOperation: %s\n"), depth, "", op_name (op));
  62. }
  63. void
  64. dump_for_expression (struct ui_file *stream, int depth, const std::string &str)
  65. {
  66. gdb_printf (stream, _("%*sString: %s\n"), depth, "", str.c_str ());
  67. }
  68. void
  69. dump_for_expression (struct ui_file *stream, int depth, struct type *type)
  70. {
  71. gdb_printf (stream, _("%*sType: "), depth, "");
  72. type_print (type, nullptr, stream, 0);
  73. gdb_printf (stream, "\n");
  74. }
  75. void
  76. dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
  77. {
  78. gdb_printf (stream, _("%*sConstant: %s\n"), depth, "",
  79. core_addr_to_string (addr));
  80. }
  81. void
  82. dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
  83. {
  84. gdb_printf (stream, _("%*sInternalvar: $%s\n"), depth, "",
  85. internalvar_name (ivar));
  86. }
  87. void
  88. dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
  89. {
  90. gdb_printf (stream, _("%*sSymbol: %s\n"), depth, "",
  91. sym->print_name ());
  92. }
  93. void
  94. dump_for_expression (struct ui_file *stream, int depth,
  95. bound_minimal_symbol msym)
  96. {
  97. gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
  98. msym.minsym->print_name (), objfile_name (msym.objfile));
  99. }
  100. void
  101. dump_for_expression (struct ui_file *stream, int depth, const block *bl)
  102. {
  103. gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
  104. }
  105. void
  106. dump_for_expression (struct ui_file *stream, int depth,
  107. const block_symbol &sym)
  108. {
  109. gdb_printf (stream, _("%*sBlock symbol:\n"), depth, "");
  110. dump_for_expression (stream, depth + 1, sym.symbol);
  111. dump_for_expression (stream, depth + 1, sym.block);
  112. }
  113. void
  114. dump_for_expression (struct ui_file *stream, int depth,
  115. type_instance_flags flags)
  116. {
  117. gdb_printf (stream, _("%*sType flags: "), depth, "");
  118. if (flags & TYPE_INSTANCE_FLAG_CONST)
  119. gdb_puts ("const ", stream);
  120. if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
  121. gdb_puts ("volatile", stream);
  122. gdb_printf (stream, "\n");
  123. }
  124. void
  125. dump_for_expression (struct ui_file *stream, int depth,
  126. enum c_string_type_values flags)
  127. {
  128. gdb_printf (stream, _("%*sC string flags: "), depth, "");
  129. switch (flags & ~C_CHAR)
  130. {
  131. case C_WIDE_STRING:
  132. gdb_puts (_("wide "), stream);
  133. break;
  134. case C_STRING_16:
  135. gdb_puts (_("u16 "), stream);
  136. break;
  137. case C_STRING_32:
  138. gdb_puts (_("u32 "), stream);
  139. break;
  140. default:
  141. gdb_puts (_("ordinary "), stream);
  142. break;
  143. }
  144. if ((flags & C_CHAR) != 0)
  145. gdb_puts (_("char"), stream);
  146. else
  147. gdb_puts (_("string"), stream);
  148. gdb_puts ("\n", stream);
  149. }
  150. void
  151. dump_for_expression (struct ui_file *stream, int depth,
  152. enum range_flag flags)
  153. {
  154. gdb_printf (stream, _("%*sRange:"), depth, "");
  155. if ((flags & RANGE_LOW_BOUND_DEFAULT) != 0)
  156. gdb_puts (_("low-default "), stream);
  157. if ((flags & RANGE_HIGH_BOUND_DEFAULT) != 0)
  158. gdb_puts (_("high-default "), stream);
  159. if ((flags & RANGE_HIGH_BOUND_EXCLUSIVE) != 0)
  160. gdb_puts (_("high-exclusive "), stream);
  161. if ((flags & RANGE_HAS_STRIDE) != 0)
  162. gdb_puts (_("has-stride"), stream);
  163. gdb_printf (stream, "\n");
  164. }
  165. void
  166. dump_for_expression (struct ui_file *stream, int depth,
  167. const std::unique_ptr<ada_component> &comp)
  168. {
  169. comp->dump (stream, depth);
  170. }
  171. void
  172. float_const_operation::dump (struct ui_file *stream, int depth) const
  173. {
  174. gdb_printf (stream, _("%*sFloat: "), depth, "");
  175. print_floating (m_data.data (), m_type, stream);
  176. gdb_printf (stream, "\n");
  177. }
  178. } /* namespace expr */