cp-demangle.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* Internal demangler interface for g++ V3 ABI.
  2. Copyright (C) 2003-2017 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor <ian@wasabisystems.com>.
  4. This file is part of the libiberty library, which is part of GCC.
  5. This file is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. In addition to the permissions in the GNU General Public License, the
  10. Free Software Foundation gives you unlimited permission to link the
  11. compiled version of this file into combinations with other programs,
  12. and to distribute those combinations without any restriction coming
  13. from the use of this file. (The General Public License restrictions
  14. do apply in other respects; for example, they cover modification of
  15. the file, and distribution when not linked into a combined
  16. executable.)
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25. /* This file provides some definitions shared by cp-demangle.c and
  26. cp-demint.c. It should not be included by any other files. */
  27. /* Information we keep for operators. */
  28. struct demangle_operator_info
  29. {
  30. /* Mangled name. */
  31. const char *code;
  32. /* Real name. */
  33. const char *name;
  34. /* Length of real name. */
  35. int len;
  36. /* Number of arguments. */
  37. int args;
  38. };
  39. /* How to print the value of a builtin type. */
  40. enum d_builtin_type_print
  41. {
  42. /* Print as (type)val. */
  43. D_PRINT_DEFAULT,
  44. /* Print as integer. */
  45. D_PRINT_INT,
  46. /* Print as unsigned integer, with trailing "u". */
  47. D_PRINT_UNSIGNED,
  48. /* Print as long, with trailing "l". */
  49. D_PRINT_LONG,
  50. /* Print as unsigned long, with trailing "ul". */
  51. D_PRINT_UNSIGNED_LONG,
  52. /* Print as long long, with trailing "ll". */
  53. D_PRINT_LONG_LONG,
  54. /* Print as unsigned long long, with trailing "ull". */
  55. D_PRINT_UNSIGNED_LONG_LONG,
  56. /* Print as bool. */
  57. D_PRINT_BOOL,
  58. /* Print as float--put value in square brackets. */
  59. D_PRINT_FLOAT,
  60. /* Print in usual way, but here to detect void. */
  61. D_PRINT_VOID
  62. };
  63. /* Information we keep for a builtin type. */
  64. struct demangle_builtin_type_info
  65. {
  66. /* Type name. */
  67. const char *name;
  68. /* Length of type name. */
  69. int len;
  70. /* Type name when using Java. */
  71. const char *java_name;
  72. /* Length of java name. */
  73. int java_len;
  74. /* How to print a value of this type. */
  75. enum d_builtin_type_print print;
  76. };
  77. /* The information structure we pass around. */
  78. struct d_info
  79. {
  80. /* The string we are demangling. */
  81. const char *s;
  82. /* The end of the string we are demangling. */
  83. const char *send;
  84. /* The options passed to the demangler. */
  85. int options;
  86. /* The next character in the string to consider. */
  87. const char *n;
  88. /* The array of components. */
  89. struct demangle_component *comps;
  90. /* The index of the next available component. */
  91. int next_comp;
  92. /* The number of available component structures. */
  93. int num_comps;
  94. /* The array of substitutions. */
  95. struct demangle_component **subs;
  96. /* The index of the next substitution. */
  97. int next_sub;
  98. /* The number of available entries in the subs array. */
  99. int num_subs;
  100. /* The last name we saw, for constructors and destructors. */
  101. struct demangle_component *last_name;
  102. /* A running total of the length of large expansions from the
  103. mangled name to the demangled name, such as standard
  104. substitutions and builtin types. */
  105. int expansion;
  106. /* Non-zero if we are parsing an expression. */
  107. int is_expression;
  108. /* Non-zero if we are parsing the type operand of a conversion
  109. operator, but not when in an expression. */
  110. int is_conversion;
  111. };
  112. /* To avoid running past the ending '\0', don't:
  113. - call d_peek_next_char if d_peek_char returned '\0'
  114. - call d_advance with an 'i' that is too large
  115. - call d_check_char(di, '\0')
  116. Everything else is safe. */
  117. #define d_peek_char(di) (*((di)->n))
  118. #ifndef CHECK_DEMANGLER
  119. # define d_peek_next_char(di) ((di)->n[1])
  120. # define d_advance(di, i) ((di)->n += (i))
  121. #endif
  122. #define d_check_char(di, c) (d_peek_char(di) == c ? ((di)->n++, 1) : 0)
  123. #define d_next_char(di) (d_peek_char(di) == '\0' ? '\0' : *((di)->n++))
  124. #define d_str(di) ((di)->n)
  125. #ifdef CHECK_DEMANGLER
  126. static inline char
  127. d_peek_next_char (const struct d_info *di)
  128. {
  129. if (!di->n[0])
  130. abort ();
  131. return di->n[1];
  132. }
  133. static inline void
  134. d_advance (struct d_info *di, int i)
  135. {
  136. if (i < 0)
  137. abort ();
  138. while (i--)
  139. {
  140. if (!di->n[0])
  141. abort ();
  142. di->n++;
  143. }
  144. }
  145. #endif
  146. /* Functions and arrays in cp-demangle.c which are referenced by
  147. functions in cp-demint.c. */
  148. #ifdef IN_GLIBCPP_V3
  149. #define CP_STATIC_IF_GLIBCPP_V3 static
  150. #else
  151. #define CP_STATIC_IF_GLIBCPP_V3 extern
  152. #endif
  153. #ifndef IN_GLIBCPP_V3
  154. extern const struct demangle_operator_info cplus_demangle_operators[];
  155. #endif
  156. #define D_BUILTIN_TYPE_COUNT (33)
  157. CP_STATIC_IF_GLIBCPP_V3
  158. const struct demangle_builtin_type_info
  159. cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
  160. CP_STATIC_IF_GLIBCPP_V3
  161. struct demangle_component *
  162. cplus_demangle_mangled_name (struct d_info *, int);
  163. CP_STATIC_IF_GLIBCPP_V3
  164. struct demangle_component *
  165. cplus_demangle_type (struct d_info *);
  166. extern void
  167. cplus_demangle_init_info (const char *, int, size_t, struct d_info *);
  168. /* cp-demangle.c needs to define this a little differently */
  169. #undef CP_STATIC_IF_GLIBCPP_V3