cp-demangle.h 5.6 KB

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