demangle.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /* Defs for interface to demanglers.
  2. Copyright (C) 1992-2022 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License
  5. as published by the Free Software Foundation; either version 2, or
  6. (at your option) any later version.
  7. In addition to the permissions in the GNU Library General Public
  8. License, the Free Software Foundation gives you unlimited
  9. permission to link the compiled version of this file into
  10. combinations with other programs, and to distribute those
  11. combinations without any restriction coming from the use of this
  12. file. (The Library Public License restrictions do apply in other
  13. respects; for example, they cover modification of the file, and
  14. distribution when not linked into a combined executable.)
  15. This program is distributed in the hope that it will be useful, but
  16. WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Library General Public License for more details.
  19. You should have received a copy of the GNU Library General Public
  20. License along with this program; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  22. 02110-1301, USA. */
  23. #if !defined (DEMANGLE_H)
  24. #define DEMANGLE_H
  25. #include "libiberty.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif /* __cplusplus */
  29. /* Options passed to cplus_demangle (in 2nd parameter). */
  30. #define DMGL_NO_OPTS 0 /* For readability... */
  31. #define DMGL_PARAMS (1 << 0) /* Include function args */
  32. #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
  33. #define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */
  34. #define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
  35. #define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
  36. #define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when
  37. present) after function signature.
  38. It applies only to the toplevel
  39. function type. */
  40. #define DMGL_RET_DROP (1 << 6) /* Suppress printing function return
  41. types, even if present. It applies
  42. only to the toplevel function type.
  43. */
  44. #define DMGL_AUTO (1 << 8)
  45. #define DMGL_GNU_V3 (1 << 14)
  46. #define DMGL_GNAT (1 << 15)
  47. #define DMGL_DLANG (1 << 16)
  48. #define DMGL_RUST (1 << 17) /* Rust wraps GNU_V3 style mangling. */
  49. /* If none of these are set, use 'current_demangling_style' as the default. */
  50. #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG|DMGL_RUST)
  51. /* Disable a limit on the depth of recursion in mangled strings.
  52. Note if this limit is disabled then stack exhaustion is possible when
  53. demangling pathologically complicated strings. Bug reports about stack
  54. exhaustion when the option is enabled will be rejected. */
  55. #define DMGL_NO_RECURSE_LIMIT (1 << 18)
  56. /* If DMGL_NO_RECURSE_LIMIT is not enabled, then this is the value used as
  57. the maximum depth of recursion allowed. It should be enough for any
  58. real-world mangled name. */
  59. #define DEMANGLE_RECURSION_LIMIT 2048
  60. /* Enumeration of possible demangling styles.
  61. Lucid and ARM styles are still kept logically distinct, even though
  62. they now both behave identically. The resulting style is actual the
  63. union of both. I.E. either style recognizes both "__pt__" and "__rf__"
  64. for operator "->", even though the first is lucid style and the second
  65. is ARM style. (FIXME?) */
  66. extern enum demangling_styles
  67. {
  68. no_demangling = -1,
  69. unknown_demangling = 0,
  70. auto_demangling = DMGL_AUTO,
  71. gnu_v3_demangling = DMGL_GNU_V3,
  72. java_demangling = DMGL_JAVA,
  73. gnat_demangling = DMGL_GNAT,
  74. dlang_demangling = DMGL_DLANG,
  75. rust_demangling = DMGL_RUST
  76. } current_demangling_style;
  77. /* Define string names for the various demangling styles. */
  78. #define NO_DEMANGLING_STYLE_STRING "none"
  79. #define AUTO_DEMANGLING_STYLE_STRING "auto"
  80. #define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3"
  81. #define JAVA_DEMANGLING_STYLE_STRING "java"
  82. #define GNAT_DEMANGLING_STYLE_STRING "gnat"
  83. #define DLANG_DEMANGLING_STYLE_STRING "dlang"
  84. #define RUST_DEMANGLING_STYLE_STRING "rust"
  85. /* Some macros to test what demangling style is active. */
  86. #define CURRENT_DEMANGLING_STYLE current_demangling_style
  87. #define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
  88. #define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
  89. #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
  90. #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
  91. #define DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_DLANG)
  92. #define RUST_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_RUST)
  93. /* Provide information about the available demangle styles. This code is
  94. pulled from gdb into libiberty because it is useful to binutils also. */
  95. extern const struct demangler_engine
  96. {
  97. const char *const demangling_style_name;
  98. const enum demangling_styles demangling_style;
  99. const char *const demangling_style_doc;
  100. } libiberty_demanglers[];
  101. extern char *
  102. cplus_demangle (const char *mangled, int options);
  103. /* Note: This sets global state. FIXME if you care about multi-threading. */
  104. extern enum demangling_styles
  105. cplus_demangle_set_style (enum demangling_styles style);
  106. extern enum demangling_styles
  107. cplus_demangle_name_to_style (const char *name);
  108. /* Callback typedef for allocation-less demangler interfaces. */
  109. typedef void (*demangle_callbackref) (const char *, size_t, void *);
  110. /* V3 ABI demangling entry points, defined in cp-demangle.c. Callback
  111. variants return non-zero on success, zero on error. char* variants
  112. return a string allocated by malloc on success, NULL on error. */
  113. extern int
  114. cplus_demangle_v3_callback (const char *mangled, int options,
  115. demangle_callbackref callback, void *opaque);
  116. extern char*
  117. cplus_demangle_v3 (const char *mangled, int options);
  118. extern int
  119. java_demangle_v3_callback (const char *mangled,
  120. demangle_callbackref callback, void *opaque);
  121. extern char*
  122. java_demangle_v3 (const char *mangled);
  123. char *
  124. ada_demangle (const char *mangled, int options);
  125. extern char *
  126. dlang_demangle (const char *mangled, int options);
  127. extern int
  128. rust_demangle_callback (const char *mangled, int options,
  129. demangle_callbackref callback, void *opaque);
  130. extern char *
  131. rust_demangle (const char *mangled, int options);
  132. enum gnu_v3_ctor_kinds {
  133. gnu_v3_complete_object_ctor = 1,
  134. gnu_v3_base_object_ctor,
  135. gnu_v3_complete_object_allocating_ctor,
  136. /* These are not part of the V3 ABI. Unified constructors are generated
  137. as a speed-for-space optimization when the -fdeclone-ctor-dtor option
  138. is used, and are always internal symbols. */
  139. gnu_v3_unified_ctor,
  140. gnu_v3_object_ctor_group
  141. };
  142. /* Return non-zero iff NAME is the mangled form of a constructor name
  143. in the G++ V3 ABI demangling style. Specifically, return an `enum
  144. gnu_v3_ctor_kinds' value indicating what kind of constructor
  145. it is. */
  146. extern enum gnu_v3_ctor_kinds
  147. is_gnu_v3_mangled_ctor (const char *name);
  148. enum gnu_v3_dtor_kinds {
  149. gnu_v3_deleting_dtor = 1,
  150. gnu_v3_complete_object_dtor,
  151. gnu_v3_base_object_dtor,
  152. /* These are not part of the V3 ABI. Unified destructors are generated
  153. as a speed-for-space optimization when the -fdeclone-ctor-dtor option
  154. is used, and are always internal symbols. */
  155. gnu_v3_unified_dtor,
  156. gnu_v3_object_dtor_group
  157. };
  158. /* Return non-zero iff NAME is the mangled form of a destructor name
  159. in the G++ V3 ABI demangling style. Specifically, return an `enum
  160. gnu_v3_dtor_kinds' value, indicating what kind of destructor
  161. it is. */
  162. extern enum gnu_v3_dtor_kinds
  163. is_gnu_v3_mangled_dtor (const char *name);
  164. /* The V3 demangler works in two passes. The first pass builds a tree
  165. representation of the mangled name, and the second pass turns the
  166. tree representation into a demangled string. Here we define an
  167. interface to permit a caller to build their own tree
  168. representation, which they can pass to the demangler to get a
  169. demangled string. This can be used to canonicalize user input into
  170. something which the demangler might output. It could also be used
  171. by other demanglers in the future. */
  172. /* These are the component types which may be found in the tree. Many
  173. component types have one or two subtrees, referred to as left and
  174. right (a component type with only one subtree puts it in the left
  175. subtree). */
  176. enum demangle_component_type
  177. {
  178. /* A name, with a length and a pointer to a string. */
  179. DEMANGLE_COMPONENT_NAME,
  180. /* A qualified name. The left subtree is a class or namespace or
  181. some such thing, and the right subtree is a name qualified by
  182. that class. */
  183. DEMANGLE_COMPONENT_QUAL_NAME,
  184. /* A local name. The left subtree describes a function, and the
  185. right subtree is a name which is local to that function. */
  186. DEMANGLE_COMPONENT_LOCAL_NAME,
  187. /* A typed name. The left subtree is a name, and the right subtree
  188. describes that name as a function. */
  189. DEMANGLE_COMPONENT_TYPED_NAME,
  190. /* A template. The left subtree is a template name, and the right
  191. subtree is a template argument list. */
  192. DEMANGLE_COMPONENT_TEMPLATE,
  193. /* A template parameter. This holds a number, which is the template
  194. parameter index. */
  195. DEMANGLE_COMPONENT_TEMPLATE_PARAM,
  196. /* A function parameter. This holds a number, which is the index. */
  197. DEMANGLE_COMPONENT_FUNCTION_PARAM,
  198. /* A constructor. This holds a name and the kind of
  199. constructor. */
  200. DEMANGLE_COMPONENT_CTOR,
  201. /* A destructor. This holds a name and the kind of destructor. */
  202. DEMANGLE_COMPONENT_DTOR,
  203. /* A vtable. This has one subtree, the type for which this is a
  204. vtable. */
  205. DEMANGLE_COMPONENT_VTABLE,
  206. /* A VTT structure. This has one subtree, the type for which this
  207. is a VTT. */
  208. DEMANGLE_COMPONENT_VTT,
  209. /* A construction vtable. The left subtree is the type for which
  210. this is a vtable, and the right subtree is the derived type for
  211. which this vtable is built. */
  212. DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
  213. /* A typeinfo structure. This has one subtree, the type for which
  214. this is the tpeinfo structure. */
  215. DEMANGLE_COMPONENT_TYPEINFO,
  216. /* A typeinfo name. This has one subtree, the type for which this
  217. is the typeinfo name. */
  218. DEMANGLE_COMPONENT_TYPEINFO_NAME,
  219. /* A typeinfo function. This has one subtree, the type for which
  220. this is the tpyeinfo function. */
  221. DEMANGLE_COMPONENT_TYPEINFO_FN,
  222. /* A thunk. This has one subtree, the name for which this is a
  223. thunk. */
  224. DEMANGLE_COMPONENT_THUNK,
  225. /* A virtual thunk. This has one subtree, the name for which this
  226. is a virtual thunk. */
  227. DEMANGLE_COMPONENT_VIRTUAL_THUNK,
  228. /* A covariant thunk. This has one subtree, the name for which this
  229. is a covariant thunk. */
  230. DEMANGLE_COMPONENT_COVARIANT_THUNK,
  231. /* A Java class. This has one subtree, the type. */
  232. DEMANGLE_COMPONENT_JAVA_CLASS,
  233. /* A guard variable. This has one subtree, the name for which this
  234. is a guard variable. */
  235. DEMANGLE_COMPONENT_GUARD,
  236. /* The init and wrapper functions for C++11 thread_local variables. */
  237. DEMANGLE_COMPONENT_TLS_INIT,
  238. DEMANGLE_COMPONENT_TLS_WRAPPER,
  239. /* A reference temporary. This has one subtree, the name for which
  240. this is a temporary. */
  241. DEMANGLE_COMPONENT_REFTEMP,
  242. /* A hidden alias. This has one subtree, the encoding for which it
  243. is providing alternative linkage. */
  244. DEMANGLE_COMPONENT_HIDDEN_ALIAS,
  245. /* A standard substitution. This holds the name of the
  246. substitution. */
  247. DEMANGLE_COMPONENT_SUB_STD,
  248. /* The restrict qualifier. The one subtree is the type which is
  249. being qualified. */
  250. DEMANGLE_COMPONENT_RESTRICT,
  251. /* The volatile qualifier. The one subtree is the type which is
  252. being qualified. */
  253. DEMANGLE_COMPONENT_VOLATILE,
  254. /* The const qualifier. The one subtree is the type which is being
  255. qualified. */
  256. DEMANGLE_COMPONENT_CONST,
  257. /* The restrict qualifier modifying a member function. The one
  258. subtree is the type which is being qualified. */
  259. DEMANGLE_COMPONENT_RESTRICT_THIS,
  260. /* The volatile qualifier modifying a member function. The one
  261. subtree is the type which is being qualified. */
  262. DEMANGLE_COMPONENT_VOLATILE_THIS,
  263. /* The const qualifier modifying a member function. The one subtree
  264. is the type which is being qualified. */
  265. DEMANGLE_COMPONENT_CONST_THIS,
  266. /* C++11 A reference modifying a member function. The one subtree is the
  267. type which is being referenced. */
  268. DEMANGLE_COMPONENT_REFERENCE_THIS,
  269. /* C++11: An rvalue reference modifying a member function. The one
  270. subtree is the type which is being referenced. */
  271. DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS,
  272. /* A vendor qualifier. The left subtree is the type which is being
  273. qualified, and the right subtree is the name of the
  274. qualifier. */
  275. DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
  276. /* A pointer. The one subtree is the type which is being pointed
  277. to. */
  278. DEMANGLE_COMPONENT_POINTER,
  279. /* A reference. The one subtree is the type which is being
  280. referenced. */
  281. DEMANGLE_COMPONENT_REFERENCE,
  282. /* C++0x: An rvalue reference. The one subtree is the type which is
  283. being referenced. */
  284. DEMANGLE_COMPONENT_RVALUE_REFERENCE,
  285. /* A complex type. The one subtree is the base type. */
  286. DEMANGLE_COMPONENT_COMPLEX,
  287. /* An imaginary type. The one subtree is the base type. */
  288. DEMANGLE_COMPONENT_IMAGINARY,
  289. /* A builtin type. This holds the builtin type information. */
  290. DEMANGLE_COMPONENT_BUILTIN_TYPE,
  291. /* A vendor's builtin type. This holds the name of the type. */
  292. DEMANGLE_COMPONENT_VENDOR_TYPE,
  293. /* A function type. The left subtree is the return type. The right
  294. subtree is a list of ARGLIST nodes. Either or both may be
  295. NULL. */
  296. DEMANGLE_COMPONENT_FUNCTION_TYPE,
  297. /* An array type. The left subtree is the dimension, which may be
  298. NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
  299. expression. The right subtree is the element type. */
  300. DEMANGLE_COMPONENT_ARRAY_TYPE,
  301. /* A pointer to member type. The left subtree is the class type,
  302. and the right subtree is the member type. CV-qualifiers appear
  303. on the latter. */
  304. DEMANGLE_COMPONENT_PTRMEM_TYPE,
  305. /* A fixed-point type. */
  306. DEMANGLE_COMPONENT_FIXED_TYPE,
  307. /* A vector type. The left subtree is the number of elements,
  308. the right subtree is the element type. */
  309. DEMANGLE_COMPONENT_VECTOR_TYPE,
  310. /* An argument list. The left subtree is the current argument, and
  311. the right subtree is either NULL or another ARGLIST node. */
  312. DEMANGLE_COMPONENT_ARGLIST,
  313. /* A template argument list. The left subtree is the current
  314. template argument, and the right subtree is either NULL or
  315. another TEMPLATE_ARGLIST node. */
  316. DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
  317. /* A template parameter object (C++20). The left subtree is the
  318. corresponding template argument. */
  319. DEMANGLE_COMPONENT_TPARM_OBJ,
  320. /* An initializer list. The left subtree is either an explicit type or
  321. NULL, and the right subtree is a DEMANGLE_COMPONENT_ARGLIST. */
  322. DEMANGLE_COMPONENT_INITIALIZER_LIST,
  323. /* An operator. This holds information about a standard
  324. operator. */
  325. DEMANGLE_COMPONENT_OPERATOR,
  326. /* An extended operator. This holds the number of arguments, and
  327. the name of the extended operator. */
  328. DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
  329. /* A typecast, represented as a unary operator. The one subtree is
  330. the type to which the argument should be cast. */
  331. DEMANGLE_COMPONENT_CAST,
  332. /* A conversion operator, represented as a unary operator. The one
  333. subtree is the type to which the argument should be converted
  334. to. */
  335. DEMANGLE_COMPONENT_CONVERSION,
  336. /* A nullary expression. The left subtree is the operator. */
  337. DEMANGLE_COMPONENT_NULLARY,
  338. /* A unary expression. The left subtree is the operator, and the
  339. right subtree is the single argument. */
  340. DEMANGLE_COMPONENT_UNARY,
  341. /* A binary expression. The left subtree is the operator, and the
  342. right subtree is a BINARY_ARGS. */
  343. DEMANGLE_COMPONENT_BINARY,
  344. /* Arguments to a binary expression. The left subtree is the first
  345. argument, and the right subtree is the second argument. */
  346. DEMANGLE_COMPONENT_BINARY_ARGS,
  347. /* A trinary expression. The left subtree is the operator, and the
  348. right subtree is a TRINARY_ARG1. */
  349. DEMANGLE_COMPONENT_TRINARY,
  350. /* Arguments to a trinary expression. The left subtree is the first
  351. argument, and the right subtree is a TRINARY_ARG2. */
  352. DEMANGLE_COMPONENT_TRINARY_ARG1,
  353. /* More arguments to a trinary expression. The left subtree is the
  354. second argument, and the right subtree is the third argument. */
  355. DEMANGLE_COMPONENT_TRINARY_ARG2,
  356. /* A literal. The left subtree is the type, and the right subtree
  357. is the value, represented as a DEMANGLE_COMPONENT_NAME. */
  358. DEMANGLE_COMPONENT_LITERAL,
  359. /* A negative literal. Like LITERAL, but the value is negated.
  360. This is a minor hack: the NAME used for LITERAL points directly
  361. to the mangled string, but since negative numbers are mangled
  362. using 'n' instead of '-', we want a way to indicate a negative
  363. number which involves neither modifying the mangled string nor
  364. allocating a new copy of the literal in memory. */
  365. DEMANGLE_COMPONENT_LITERAL_NEG,
  366. /* A vendor's builtin expression. The left subtree holds the
  367. expression's name, and the right subtree is a argument list. */
  368. DEMANGLE_COMPONENT_VENDOR_EXPR,
  369. /* A libgcj compiled resource. The left subtree is the name of the
  370. resource. */
  371. DEMANGLE_COMPONENT_JAVA_RESOURCE,
  372. /* A name formed by the concatenation of two parts. The left
  373. subtree is the first part and the right subtree the second. */
  374. DEMANGLE_COMPONENT_COMPOUND_NAME,
  375. /* A name formed by a single character. */
  376. DEMANGLE_COMPONENT_CHARACTER,
  377. /* A number. */
  378. DEMANGLE_COMPONENT_NUMBER,
  379. /* A decltype type. */
  380. DEMANGLE_COMPONENT_DECLTYPE,
  381. /* Global constructors keyed to name. */
  382. DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS,
  383. /* Global destructors keyed to name. */
  384. DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
  385. /* A lambda closure type. */
  386. DEMANGLE_COMPONENT_LAMBDA,
  387. /* A default argument scope. */
  388. DEMANGLE_COMPONENT_DEFAULT_ARG,
  389. /* An unnamed type. */
  390. DEMANGLE_COMPONENT_UNNAMED_TYPE,
  391. /* A transactional clone. This has one subtree, the encoding for
  392. which it is providing alternative linkage. */
  393. DEMANGLE_COMPONENT_TRANSACTION_CLONE,
  394. /* A non-transactional clone entry point. In the i386/x86_64 abi,
  395. the unmangled symbol of a tm_callable becomes a thunk and the
  396. non-transactional function version is mangled thus. */
  397. DEMANGLE_COMPONENT_NONTRANSACTION_CLONE,
  398. /* A pack expansion. */
  399. DEMANGLE_COMPONENT_PACK_EXPANSION,
  400. /* A name with an ABI tag. */
  401. DEMANGLE_COMPONENT_TAGGED_NAME,
  402. /* A transaction-safe function type. */
  403. DEMANGLE_COMPONENT_TRANSACTION_SAFE,
  404. /* A cloned function. */
  405. DEMANGLE_COMPONENT_CLONE,
  406. DEMANGLE_COMPONENT_NOEXCEPT,
  407. DEMANGLE_COMPONENT_THROW_SPEC
  408. };
  409. /* Types which are only used internally. */
  410. struct demangle_operator_info;
  411. struct demangle_builtin_type_info;
  412. /* A node in the tree representation is an instance of a struct
  413. demangle_component. Note that the field names of the struct are
  414. not well protected against macros defined by the file including
  415. this one. We can fix this if it ever becomes a problem. */
  416. struct demangle_component
  417. {
  418. /* The type of this component. */
  419. enum demangle_component_type type;
  420. /* Guard against recursive component printing.
  421. Initialize to zero. Private to d_print_comp.
  422. All other fields are final after initialization. */
  423. int d_printing;
  424. int d_counting;
  425. union
  426. {
  427. /* For DEMANGLE_COMPONENT_NAME. */
  428. struct
  429. {
  430. /* A pointer to the name (which need not NULL terminated) and
  431. its length. */
  432. const char *s;
  433. int len;
  434. } s_name;
  435. /* For DEMANGLE_COMPONENT_OPERATOR. */
  436. struct
  437. {
  438. /* Operator. */
  439. const struct demangle_operator_info *op;
  440. } s_operator;
  441. /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
  442. struct
  443. {
  444. /* Number of arguments. */
  445. int args;
  446. /* Name. */
  447. struct demangle_component *name;
  448. } s_extended_operator;
  449. /* For DEMANGLE_COMPONENT_FIXED_TYPE. */
  450. struct
  451. {
  452. /* The length, indicated by a C integer type name. */
  453. struct demangle_component *length;
  454. /* _Accum or _Fract? */
  455. short accum;
  456. /* Saturating or not? */
  457. short sat;
  458. } s_fixed;
  459. /* For DEMANGLE_COMPONENT_CTOR. */
  460. struct
  461. {
  462. /* Kind of constructor. */
  463. enum gnu_v3_ctor_kinds kind;
  464. /* Name. */
  465. struct demangle_component *name;
  466. } s_ctor;
  467. /* For DEMANGLE_COMPONENT_DTOR. */
  468. struct
  469. {
  470. /* Kind of destructor. */
  471. enum gnu_v3_dtor_kinds kind;
  472. /* Name. */
  473. struct demangle_component *name;
  474. } s_dtor;
  475. /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */
  476. struct
  477. {
  478. /* Builtin type. */
  479. const struct demangle_builtin_type_info *type;
  480. } s_builtin;
  481. /* For DEMANGLE_COMPONENT_SUB_STD. */
  482. struct
  483. {
  484. /* Standard substitution string. */
  485. const char* string;
  486. /* Length of string. */
  487. int len;
  488. } s_string;
  489. /* For DEMANGLE_COMPONENT_*_PARAM. */
  490. struct
  491. {
  492. /* Parameter index. */
  493. long number;
  494. } s_number;
  495. /* For DEMANGLE_COMPONENT_CHARACTER. */
  496. struct
  497. {
  498. int character;
  499. } s_character;
  500. /* For other types. */
  501. struct
  502. {
  503. /* Left (or only) subtree. */
  504. struct demangle_component *left;
  505. /* Right subtree. */
  506. struct demangle_component *right;
  507. } s_binary;
  508. struct
  509. {
  510. /* subtree, same place as d_left. */
  511. struct demangle_component *sub;
  512. /* integer. */
  513. int num;
  514. } s_unary_num;
  515. } u;
  516. };
  517. /* People building mangled trees are expected to allocate instances of
  518. struct demangle_component themselves. They can then call one of
  519. the following functions to fill them in. */
  520. /* Fill in most component types with a left subtree and a right
  521. subtree. Returns non-zero on success, zero on failure, such as an
  522. unrecognized or inappropriate component type. */
  523. extern int
  524. cplus_demangle_fill_component (struct demangle_component *fill,
  525. enum demangle_component_type,
  526. struct demangle_component *left,
  527. struct demangle_component *right);
  528. /* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success,
  529. zero for bad arguments. */
  530. extern int
  531. cplus_demangle_fill_name (struct demangle_component *fill,
  532. const char *, int);
  533. /* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
  534. builtin type (e.g., "int", etc.). Returns non-zero on success,
  535. zero if the type is not recognized. */
  536. extern int
  537. cplus_demangle_fill_builtin_type (struct demangle_component *fill,
  538. const char *type_name);
  539. /* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
  540. operator and the number of arguments which it takes (the latter is
  541. used to disambiguate operators which can be both binary and unary,
  542. such as '-'). Returns non-zero on success, zero if the operator is
  543. not recognized. */
  544. extern int
  545. cplus_demangle_fill_operator (struct demangle_component *fill,
  546. const char *opname, int args);
  547. /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
  548. number of arguments and the name. Returns non-zero on success,
  549. zero for bad arguments. */
  550. extern int
  551. cplus_demangle_fill_extended_operator (struct demangle_component *fill,
  552. int numargs,
  553. struct demangle_component *nm);
  554. /* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success,
  555. zero for bad arguments. */
  556. extern int
  557. cplus_demangle_fill_ctor (struct demangle_component *fill,
  558. enum gnu_v3_ctor_kinds kind,
  559. struct demangle_component *name);
  560. /* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success,
  561. zero for bad arguments. */
  562. extern int
  563. cplus_demangle_fill_dtor (struct demangle_component *fill,
  564. enum gnu_v3_dtor_kinds kind,
  565. struct demangle_component *name);
  566. /* This function translates a mangled name into a struct
  567. demangle_component tree. The first argument is the mangled name.
  568. The second argument is DMGL_* options. This returns a pointer to a
  569. tree on success, or NULL on failure. On success, the third
  570. argument is set to a block of memory allocated by malloc. This
  571. block should be passed to free when the tree is no longer
  572. needed. */
  573. extern struct demangle_component *
  574. cplus_demangle_v3_components (const char *mangled, int options, void **mem);
  575. /* This function takes a struct demangle_component tree and returns
  576. the corresponding demangled string. The first argument is DMGL_*
  577. options. The second is the tree to demangle. The third is a guess
  578. at the length of the demangled string, used to initially allocate
  579. the return buffer. The fourth is a pointer to a size_t. On
  580. success, this function returns a buffer allocated by malloc(), and
  581. sets the size_t pointed to by the fourth argument to the size of
  582. the allocated buffer (not the length of the returned string). On
  583. failure, this function returns NULL, and sets the size_t pointed to
  584. by the fourth argument to 0 for an invalid tree, or to 1 for a
  585. memory allocation error. */
  586. extern char *
  587. cplus_demangle_print (int options,
  588. struct demangle_component *tree,
  589. int estimated_length,
  590. size_t *p_allocated_size);
  591. /* This function takes a struct demangle_component tree and passes back
  592. a demangled string in one or more calls to a callback function.
  593. The first argument is DMGL_* options. The second is the tree to
  594. demangle. The third is a pointer to a callback function; on each call
  595. this receives an element of the demangled string, its length, and an
  596. opaque value. The fourth is the opaque value passed to the callback.
  597. The callback is called once or more to return the full demangled
  598. string. The demangled element string is always nul-terminated, though
  599. its length is also provided for convenience. In contrast to
  600. cplus_demangle_print(), this function does not allocate heap memory
  601. to grow output strings (except perhaps where alloca() is implemented
  602. by malloc()), and so is normally safe for use where the heap has been
  603. corrupted. On success, this function returns 1; on failure, 0. */
  604. extern int
  605. cplus_demangle_print_callback (int options,
  606. struct demangle_component *tree,
  607. demangle_callbackref callback, void *opaque);
  608. #ifdef __cplusplus
  609. }
  610. #endif /* __cplusplus */
  611. #endif /* DEMANGLE_H */