demangle.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /* Defs for interface to demanglers.
  2. Copyright (C) 1992-2015 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 (1 << 9)
  46. #define DMGL_LUCID (1 << 10)
  47. #define DMGL_ARM (1 << 11)
  48. #define DMGL_HP (1 << 12) /* For the HP aCC compiler;
  49. same as ARM except for
  50. template arguments, etc. */
  51. #define DMGL_EDG (1 << 13)
  52. #define DMGL_GNU_V3 (1 << 14)
  53. #define DMGL_GNAT (1 << 15)
  54. #define DMGL_DLANG (1 << 16)
  55. /* If none of these are set, use 'current_demangling_style' as the default. */
  56. #define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG)
  57. /* Enumeration of possible demangling styles.
  58. Lucid and ARM styles are still kept logically distinct, even though
  59. they now both behave identically. The resulting style is actual the
  60. union of both. I.E. either style recognizes both "__pt__" and "__rf__"
  61. for operator "->", even though the first is lucid style and the second
  62. is ARM style. (FIXME?) */
  63. extern enum demangling_styles
  64. {
  65. no_demangling = -1,
  66. unknown_demangling = 0,
  67. auto_demangling = DMGL_AUTO,
  68. gnu_demangling = DMGL_GNU,
  69. lucid_demangling = DMGL_LUCID,
  70. arm_demangling = DMGL_ARM,
  71. hp_demangling = DMGL_HP,
  72. edg_demangling = DMGL_EDG,
  73. gnu_v3_demangling = DMGL_GNU_V3,
  74. java_demangling = DMGL_JAVA,
  75. gnat_demangling = DMGL_GNAT,
  76. dlang_demangling = DMGL_DLANG
  77. } current_demangling_style;
  78. /* Define string names for the various demangling styles. */
  79. #define NO_DEMANGLING_STYLE_STRING "none"
  80. #define AUTO_DEMANGLING_STYLE_STRING "auto"
  81. #define GNU_DEMANGLING_STYLE_STRING "gnu"
  82. #define LUCID_DEMANGLING_STYLE_STRING "lucid"
  83. #define ARM_DEMANGLING_STYLE_STRING "arm"
  84. #define HP_DEMANGLING_STYLE_STRING "hp"
  85. #define EDG_DEMANGLING_STYLE_STRING "edg"
  86. #define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3"
  87. #define JAVA_DEMANGLING_STYLE_STRING "java"
  88. #define GNAT_DEMANGLING_STYLE_STRING "gnat"
  89. #define DLANG_DEMANGLING_STYLE_STRING "dlang"
  90. /* Some macros to test what demangling style is active. */
  91. #define CURRENT_DEMANGLING_STYLE current_demangling_style
  92. #define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
  93. #define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU)
  94. #define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID)
  95. #define ARM_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_ARM)
  96. #define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
  97. #define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
  98. #define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
  99. #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
  100. #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
  101. #define DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_DLANG)
  102. /* Provide information about the available demangle styles. This code is
  103. pulled from gdb into libiberty because it is useful to binutils also. */
  104. extern const struct demangler_engine
  105. {
  106. const char *const demangling_style_name;
  107. const enum demangling_styles demangling_style;
  108. const char *const demangling_style_doc;
  109. } libiberty_demanglers[];
  110. extern char *
  111. cplus_demangle (const char *mangled, int options);
  112. extern int
  113. cplus_demangle_opname (const char *opname, char *result, int options);
  114. extern const char *
  115. cplus_mangle_opname (const char *opname, int options);
  116. /* Note: This sets global state. FIXME if you care about multi-threading. */
  117. extern void
  118. set_cplus_marker_for_demangling (int ch);
  119. extern enum demangling_styles
  120. cplus_demangle_set_style (enum demangling_styles style);
  121. extern enum demangling_styles
  122. cplus_demangle_name_to_style (const char *name);
  123. /* Callback typedef for allocation-less demangler interfaces. */
  124. typedef void (*demangle_callbackref) (const char *, size_t, void *);
  125. /* V3 ABI demangling entry points, defined in cp-demangle.c. Callback
  126. variants return non-zero on success, zero on error. char* variants
  127. return a string allocated by malloc on success, NULL on error. */
  128. extern int
  129. cplus_demangle_v3_callback (const char *mangled, int options,
  130. demangle_callbackref callback, void *opaque);
  131. extern char*
  132. cplus_demangle_v3 (const char *mangled, int options);
  133. extern int
  134. java_demangle_v3_callback (const char *mangled,
  135. demangle_callbackref callback, void *opaque);
  136. extern char*
  137. java_demangle_v3 (const char *mangled);
  138. char *
  139. ada_demangle (const char *mangled, int options);
  140. extern char *
  141. dlang_demangle (const char *mangled, int options);
  142. enum gnu_v3_ctor_kinds {
  143. gnu_v3_complete_object_ctor = 1,
  144. gnu_v3_base_object_ctor,
  145. gnu_v3_complete_object_allocating_ctor,
  146. /* These are not part of the V3 ABI. Unified constructors are generated
  147. as a speed-for-space optimization when the -fdeclone-ctor-dtor option
  148. is used, and are always internal symbols. */
  149. gnu_v3_unified_ctor,
  150. gnu_v3_object_ctor_group
  151. };
  152. /* Return non-zero iff NAME is the mangled form of a constructor name
  153. in the G++ V3 ABI demangling style. Specifically, return an `enum
  154. gnu_v3_ctor_kinds' value indicating what kind of constructor
  155. it is. */
  156. extern enum gnu_v3_ctor_kinds
  157. is_gnu_v3_mangled_ctor (const char *name);
  158. enum gnu_v3_dtor_kinds {
  159. gnu_v3_deleting_dtor = 1,
  160. gnu_v3_complete_object_dtor,
  161. gnu_v3_base_object_dtor,
  162. /* These are not part of the V3 ABI. Unified destructors are generated
  163. as a speed-for-space optimization when the -fdeclone-ctor-dtor option
  164. is used, and are always internal symbols. */
  165. gnu_v3_unified_dtor,
  166. gnu_v3_object_dtor_group
  167. };
  168. /* Return non-zero iff NAME is the mangled form of a destructor name
  169. in the G++ V3 ABI demangling style. Specifically, return an `enum
  170. gnu_v3_dtor_kinds' value, indicating what kind of destructor
  171. it is. */
  172. extern enum gnu_v3_dtor_kinds
  173. is_gnu_v3_mangled_dtor (const char *name);
  174. /* The V3 demangler works in two passes. The first pass builds a tree
  175. representation of the mangled name, and the second pass turns the
  176. tree representation into a demangled string. Here we define an
  177. interface to permit a caller to build their own tree
  178. representation, which they can pass to the demangler to get a
  179. demangled string. This can be used to canonicalize user input into
  180. something which the demangler might output. It could also be used
  181. by other demanglers in the future. */
  182. /* These are the component types which may be found in the tree. Many
  183. component types have one or two subtrees, referred to as left and
  184. right (a component type with only one subtree puts it in the left
  185. subtree). */
  186. enum demangle_component_type
  187. {
  188. /* A name, with a length and a pointer to a string. */
  189. DEMANGLE_COMPONENT_NAME,
  190. /* A qualified name. The left subtree is a class or namespace or
  191. some such thing, and the right subtree is a name qualified by
  192. that class. */
  193. DEMANGLE_COMPONENT_QUAL_NAME,
  194. /* A local name. The left subtree describes a function, and the
  195. right subtree is a name which is local to that function. */
  196. DEMANGLE_COMPONENT_LOCAL_NAME,
  197. /* A typed name. The left subtree is a name, and the right subtree
  198. describes that name as a function. */
  199. DEMANGLE_COMPONENT_TYPED_NAME,
  200. /* A template. The left subtree is a template name, and the right
  201. subtree is a template argument list. */
  202. DEMANGLE_COMPONENT_TEMPLATE,
  203. /* A template parameter. This holds a number, which is the template
  204. parameter index. */
  205. DEMANGLE_COMPONENT_TEMPLATE_PARAM,
  206. /* A function parameter. This holds a number, which is the index. */
  207. DEMANGLE_COMPONENT_FUNCTION_PARAM,
  208. /* A constructor. This holds a name and the kind of
  209. constructor. */
  210. DEMANGLE_COMPONENT_CTOR,
  211. /* A destructor. This holds a name and the kind of destructor. */
  212. DEMANGLE_COMPONENT_DTOR,
  213. /* A vtable. This has one subtree, the type for which this is a
  214. vtable. */
  215. DEMANGLE_COMPONENT_VTABLE,
  216. /* A VTT structure. This has one subtree, the type for which this
  217. is a VTT. */
  218. DEMANGLE_COMPONENT_VTT,
  219. /* A construction vtable. The left subtree is the type for which
  220. this is a vtable, and the right subtree is the derived type for
  221. which this vtable is built. */
  222. DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
  223. /* A typeinfo structure. This has one subtree, the type for which
  224. this is the tpeinfo structure. */
  225. DEMANGLE_COMPONENT_TYPEINFO,
  226. /* A typeinfo name. This has one subtree, the type for which this
  227. is the typeinfo name. */
  228. DEMANGLE_COMPONENT_TYPEINFO_NAME,
  229. /* A typeinfo function. This has one subtree, the type for which
  230. this is the tpyeinfo function. */
  231. DEMANGLE_COMPONENT_TYPEINFO_FN,
  232. /* A thunk. This has one subtree, the name for which this is a
  233. thunk. */
  234. DEMANGLE_COMPONENT_THUNK,
  235. /* A virtual thunk. This has one subtree, the name for which this
  236. is a virtual thunk. */
  237. DEMANGLE_COMPONENT_VIRTUAL_THUNK,
  238. /* A covariant thunk. This has one subtree, the name for which this
  239. is a covariant thunk. */
  240. DEMANGLE_COMPONENT_COVARIANT_THUNK,
  241. /* A Java class. This has one subtree, the type. */
  242. DEMANGLE_COMPONENT_JAVA_CLASS,
  243. /* A guard variable. This has one subtree, the name for which this
  244. is a guard variable. */
  245. DEMANGLE_COMPONENT_GUARD,
  246. /* The init and wrapper functions for C++11 thread_local variables. */
  247. DEMANGLE_COMPONENT_TLS_INIT,
  248. DEMANGLE_COMPONENT_TLS_WRAPPER,
  249. /* A reference temporary. This has one subtree, the name for which
  250. this is a temporary. */
  251. DEMANGLE_COMPONENT_REFTEMP,
  252. /* A hidden alias. This has one subtree, the encoding for which it
  253. is providing alternative linkage. */
  254. DEMANGLE_COMPONENT_HIDDEN_ALIAS,
  255. /* A standard substitution. This holds the name of the
  256. substitution. */
  257. DEMANGLE_COMPONENT_SUB_STD,
  258. /* The restrict qualifier. The one subtree is the type which is
  259. being qualified. */
  260. DEMANGLE_COMPONENT_RESTRICT,
  261. /* The volatile qualifier. The one subtree is the type which is
  262. being qualified. */
  263. DEMANGLE_COMPONENT_VOLATILE,
  264. /* The const qualifier. The one subtree is the type which is being
  265. qualified. */
  266. DEMANGLE_COMPONENT_CONST,
  267. /* The restrict qualifier modifying a member function. The one
  268. subtree is the type which is being qualified. */
  269. DEMANGLE_COMPONENT_RESTRICT_THIS,
  270. /* The volatile qualifier modifying a member function. The one
  271. subtree is the type which is being qualified. */
  272. DEMANGLE_COMPONENT_VOLATILE_THIS,
  273. /* The const qualifier modifying a member function. The one subtree
  274. is the type which is being qualified. */
  275. DEMANGLE_COMPONENT_CONST_THIS,
  276. /* C++11 A reference modifying a member function. The one subtree is the
  277. type which is being referenced. */
  278. DEMANGLE_COMPONENT_REFERENCE_THIS,
  279. /* C++11: An rvalue reference modifying a member function. The one
  280. subtree is the type which is being referenced. */
  281. DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS,
  282. /* A vendor qualifier. The left subtree is the type which is being
  283. qualified, and the right subtree is the name of the
  284. qualifier. */
  285. DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
  286. /* A pointer. The one subtree is the type which is being pointed
  287. to. */
  288. DEMANGLE_COMPONENT_POINTER,
  289. /* A reference. The one subtree is the type which is being
  290. referenced. */
  291. DEMANGLE_COMPONENT_REFERENCE,
  292. /* C++0x: An rvalue reference. The one subtree is the type which is
  293. being referenced. */
  294. DEMANGLE_COMPONENT_RVALUE_REFERENCE,
  295. /* A complex type. The one subtree is the base type. */
  296. DEMANGLE_COMPONENT_COMPLEX,
  297. /* An imaginary type. The one subtree is the base type. */
  298. DEMANGLE_COMPONENT_IMAGINARY,
  299. /* A builtin type. This holds the builtin type information. */
  300. DEMANGLE_COMPONENT_BUILTIN_TYPE,
  301. /* A vendor's builtin type. This holds the name of the type. */
  302. DEMANGLE_COMPONENT_VENDOR_TYPE,
  303. /* A function type. The left subtree is the return type. The right
  304. subtree is a list of ARGLIST nodes. Either or both may be
  305. NULL. */
  306. DEMANGLE_COMPONENT_FUNCTION_TYPE,
  307. /* An array type. The left subtree is the dimension, which may be
  308. NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
  309. expression. The right subtree is the element type. */
  310. DEMANGLE_COMPONENT_ARRAY_TYPE,
  311. /* A pointer to member type. The left subtree is the class type,
  312. and the right subtree is the member type. CV-qualifiers appear
  313. on the latter. */
  314. DEMANGLE_COMPONENT_PTRMEM_TYPE,
  315. /* A fixed-point type. */
  316. DEMANGLE_COMPONENT_FIXED_TYPE,
  317. /* A vector type. The left subtree is the number of elements,
  318. the right subtree is the element type. */
  319. DEMANGLE_COMPONENT_VECTOR_TYPE,
  320. /* An argument list. The left subtree is the current argument, and
  321. the right subtree is either NULL or another ARGLIST node. */
  322. DEMANGLE_COMPONENT_ARGLIST,
  323. /* A template argument list. The left subtree is the current
  324. template argument, and the right subtree is either NULL or
  325. another TEMPLATE_ARGLIST node. */
  326. DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
  327. /* An initializer list. The left subtree is either an explicit type or
  328. NULL, and the right subtree is a DEMANGLE_COMPONENT_ARGLIST. */
  329. DEMANGLE_COMPONENT_INITIALIZER_LIST,
  330. /* An operator. This holds information about a standard
  331. operator. */
  332. DEMANGLE_COMPONENT_OPERATOR,
  333. /* An extended operator. This holds the number of arguments, and
  334. the name of the extended operator. */
  335. DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
  336. /* A typecast, represented as a unary operator. The one subtree is
  337. the type to which the argument should be cast. */
  338. DEMANGLE_COMPONENT_CAST,
  339. /* A nullary expression. The left subtree is the operator. */
  340. DEMANGLE_COMPONENT_NULLARY,
  341. /* A unary expression. The left subtree is the operator, and the
  342. right subtree is the single argument. */
  343. DEMANGLE_COMPONENT_UNARY,
  344. /* A binary expression. The left subtree is the operator, and the
  345. right subtree is a BINARY_ARGS. */
  346. DEMANGLE_COMPONENT_BINARY,
  347. /* Arguments to a binary expression. The left subtree is the first
  348. argument, and the right subtree is the second argument. */
  349. DEMANGLE_COMPONENT_BINARY_ARGS,
  350. /* A trinary expression. The left subtree is the operator, and the
  351. right subtree is a TRINARY_ARG1. */
  352. DEMANGLE_COMPONENT_TRINARY,
  353. /* Arguments to a trinary expression. The left subtree is the first
  354. argument, and the right subtree is a TRINARY_ARG2. */
  355. DEMANGLE_COMPONENT_TRINARY_ARG1,
  356. /* More arguments to a trinary expression. The left subtree is the
  357. second argument, and the right subtree is the third argument. */
  358. DEMANGLE_COMPONENT_TRINARY_ARG2,
  359. /* A literal. The left subtree is the type, and the right subtree
  360. is the value, represented as a DEMANGLE_COMPONENT_NAME. */
  361. DEMANGLE_COMPONENT_LITERAL,
  362. /* A negative literal. Like LITERAL, but the value is negated.
  363. This is a minor hack: the NAME used for LITERAL points directly
  364. to the mangled string, but since negative numbers are mangled
  365. using 'n' instead of '-', we want a way to indicate a negative
  366. number which involves neither modifying the mangled string nor
  367. allocating a new copy of the literal in memory. */
  368. DEMANGLE_COMPONENT_LITERAL_NEG,
  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 cloned function. */
  403. DEMANGLE_COMPONENT_CLONE
  404. };
  405. /* Types which are only used internally. */
  406. struct demangle_operator_info;
  407. struct demangle_builtin_type_info;
  408. /* A node in the tree representation is an instance of a struct
  409. demangle_component. Note that the field names of the struct are
  410. not well protected against macros defined by the file including
  411. this one. We can fix this if it ever becomes a problem. */
  412. struct demangle_component
  413. {
  414. /* The type of this component. */
  415. enum demangle_component_type type;
  416. union
  417. {
  418. /* For DEMANGLE_COMPONENT_NAME. */
  419. struct
  420. {
  421. /* A pointer to the name (which need not NULL terminated) and
  422. its length. */
  423. const char *s;
  424. int len;
  425. } s_name;
  426. /* For DEMANGLE_COMPONENT_OPERATOR. */
  427. struct
  428. {
  429. /* Operator. */
  430. const struct demangle_operator_info *op;
  431. } s_operator;
  432. /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
  433. struct
  434. {
  435. /* Number of arguments. */
  436. int args;
  437. /* Name. */
  438. struct demangle_component *name;
  439. } s_extended_operator;
  440. /* For DEMANGLE_COMPONENT_FIXED_TYPE. */
  441. struct
  442. {
  443. /* The length, indicated by a C integer type name. */
  444. struct demangle_component *length;
  445. /* _Accum or _Fract? */
  446. short accum;
  447. /* Saturating or not? */
  448. short sat;
  449. } s_fixed;
  450. /* For DEMANGLE_COMPONENT_CTOR. */
  451. struct
  452. {
  453. /* Kind of constructor. */
  454. enum gnu_v3_ctor_kinds kind;
  455. /* Name. */
  456. struct demangle_component *name;
  457. } s_ctor;
  458. /* For DEMANGLE_COMPONENT_DTOR. */
  459. struct
  460. {
  461. /* Kind of destructor. */
  462. enum gnu_v3_dtor_kinds kind;
  463. /* Name. */
  464. struct demangle_component *name;
  465. } s_dtor;
  466. /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */
  467. struct
  468. {
  469. /* Builtin type. */
  470. const struct demangle_builtin_type_info *type;
  471. } s_builtin;
  472. /* For DEMANGLE_COMPONENT_SUB_STD. */
  473. struct
  474. {
  475. /* Standard substitution string. */
  476. const char* string;
  477. /* Length of string. */
  478. int len;
  479. } s_string;
  480. /* For DEMANGLE_COMPONENT_*_PARAM. */
  481. struct
  482. {
  483. /* Parameter index. */
  484. long number;
  485. } s_number;
  486. /* For DEMANGLE_COMPONENT_CHARACTER. */
  487. struct
  488. {
  489. int character;
  490. } s_character;
  491. /* For other types. */
  492. struct
  493. {
  494. /* Left (or only) subtree. */
  495. struct demangle_component *left;
  496. /* Right subtree. */
  497. struct demangle_component *right;
  498. } s_binary;
  499. struct
  500. {
  501. /* subtree, same place as d_left. */
  502. struct demangle_component *sub;
  503. /* integer. */
  504. int num;
  505. } s_unary_num;
  506. } u;
  507. };
  508. /* People building mangled trees are expected to allocate instances of
  509. struct demangle_component themselves. They can then call one of
  510. the following functions to fill them in. */
  511. /* Fill in most component types with a left subtree and a right
  512. subtree. Returns non-zero on success, zero on failure, such as an
  513. unrecognized or inappropriate component type. */
  514. extern int
  515. cplus_demangle_fill_component (struct demangle_component *fill,
  516. enum demangle_component_type,
  517. struct demangle_component *left,
  518. struct demangle_component *right);
  519. /* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success,
  520. zero for bad arguments. */
  521. extern int
  522. cplus_demangle_fill_name (struct demangle_component *fill,
  523. const char *, int);
  524. /* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the
  525. builtin type (e.g., "int", etc.). Returns non-zero on success,
  526. zero if the type is not recognized. */
  527. extern int
  528. cplus_demangle_fill_builtin_type (struct demangle_component *fill,
  529. const char *type_name);
  530. /* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the
  531. operator and the number of arguments which it takes (the latter is
  532. used to disambiguate operators which can be both binary and unary,
  533. such as '-'). Returns non-zero on success, zero if the operator is
  534. not recognized. */
  535. extern int
  536. cplus_demangle_fill_operator (struct demangle_component *fill,
  537. const char *opname, int args);
  538. /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the
  539. number of arguments and the name. Returns non-zero on success,
  540. zero for bad arguments. */
  541. extern int
  542. cplus_demangle_fill_extended_operator (struct demangle_component *fill,
  543. int numargs,
  544. struct demangle_component *nm);
  545. /* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success,
  546. zero for bad arguments. */
  547. extern int
  548. cplus_demangle_fill_ctor (struct demangle_component *fill,
  549. enum gnu_v3_ctor_kinds kind,
  550. struct demangle_component *name);
  551. /* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success,
  552. zero for bad arguments. */
  553. extern int
  554. cplus_demangle_fill_dtor (struct demangle_component *fill,
  555. enum gnu_v3_dtor_kinds kind,
  556. struct demangle_component *name);
  557. /* This function translates a mangled name into a struct
  558. demangle_component tree. The first argument is the mangled name.
  559. The second argument is DMGL_* options. This returns a pointer to a
  560. tree on success, or NULL on failure. On success, the third
  561. argument is set to a block of memory allocated by malloc. This
  562. block should be passed to free when the tree is no longer
  563. needed. */
  564. extern struct demangle_component *
  565. cplus_demangle_v3_components (const char *mangled, int options, void **mem);
  566. /* This function takes a struct demangle_component tree and returns
  567. the corresponding demangled string. The first argument is DMGL_*
  568. options. The second is the tree to demangle. The third is a guess
  569. at the length of the demangled string, used to initially allocate
  570. the return buffer. The fourth is a pointer to a size_t. On
  571. success, this function returns a buffer allocated by malloc(), and
  572. sets the size_t pointed to by the fourth argument to the size of
  573. the allocated buffer (not the length of the returned string). On
  574. failure, this function returns NULL, and sets the size_t pointed to
  575. by the fourth argument to 0 for an invalid tree, or to 1 for a
  576. memory allocation error. */
  577. extern char *
  578. cplus_demangle_print (int options,
  579. const struct demangle_component *tree,
  580. int estimated_length,
  581. size_t *p_allocated_size);
  582. /* This function takes a struct demangle_component tree and passes back
  583. a demangled string in one or more calls to a callback function.
  584. The first argument is DMGL_* options. The second is the tree to
  585. demangle. The third is a pointer to a callback function; on each call
  586. this receives an element of the demangled string, its length, and an
  587. opaque value. The fourth is the opaque value passed to the callback.
  588. The callback is called once or more to return the full demangled
  589. string. The demangled element string is always nul-terminated, though
  590. its length is also provided for convenience. In contrast to
  591. cplus_demangle_print(), this function does not allocate heap memory
  592. to grow output strings (except perhaps where alloca() is implemented
  593. by malloc()), and so is normally safe for use where the heap has been
  594. corrupted. On success, this function returns 1; on failure, 0. */
  595. extern int
  596. cplus_demangle_print_callback (int options,
  597. const struct demangle_component *tree,
  598. demangle_callbackref callback, void *opaque);
  599. #ifdef __cplusplus
  600. }
  601. #endif /* __cplusplus */
  602. #endif /* DEMANGLE_H */