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