/** * demangle.hをgcc-4.1.0から移植 * 使うときは-L-libertyを付ければおk * License: GPL v2 */ /* Defs for interface to demanglers. Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ module gcc.demangle; extern(C): version=USE_NO_HEADER; version(USE_NO_HEADER){ }else{ private import gcc.libiberty; } /* Options passed to cplus_demangle (in 2nd parameter). */ enum{ DMGL_NO_OPTS= 0, /* For readability... */ DMGL_PARAMS= (1 << 0), /* Include function args */ DMGL_ANSI= (1 << 1), /* Include const, volatile, etc */ DMGL_JAVA= (1 << 2), /* Demangle as Java rather than C++. */ DMGL_VERBOSE= (1 << 3), /* Include implementation details. */ DMGL_TYPES= (1 << 4), /* Also try to demangle type encodings. */ DMGL_AUTO= (1 << 8), DMGL_GNU= (1 << 9), DMGL_LUCID= (1 << 10), DMGL_ARM= (1 << 11), DMGL_HP= (1 << 12), /* For the HP aCC compiler; same as ARM except for template arguments, etc. */ DMGL_EDG= (1 << 13), DMGL_GNU_V3= (1 << 14), DMGL_GNAT= (1 << 15), } /* If none of these are set, use 'current_demangling_style' as the default. */ const DMGL_STYLE_MASK=(DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT); /* Enumeration of possible demangling styles. Lucid and ARM styles are still kept logically distinct, even though they now both behave identically. The resulting style is actual the union of both. I.E. either style recognizes both "__pt__" and "__rf__" for operator "->", even though the first is lucid style and the second is ARM style. (FIXME?) */ extern enum demangling_styles { no_demangling = -1, unknown_demangling = 0, auto_demangling = DMGL_AUTO, gnu_demangling = DMGL_GNU, lucid_demangling = DMGL_LUCID, arm_demangling = DMGL_ARM, hp_demangling = DMGL_HP, edg_demangling = DMGL_EDG, gnu_v3_demangling = DMGL_GNU_V3, java_demangling = DMGL_JAVA, gnat_demangling = DMGL_GNAT } alias demangling_styles current_demangling_style; /* Define string names for the various demangling styles. */ char[] NO_DEMANGLING_STYLE_STRING= "none"; char[] AUTO_DEMANGLING_STYLE_STRING= "auto"; char[] GNU_DEMANGLING_STYLE_STRING= "gnu"; char[] LUCID_DEMANGLING_STYLE_STRING= "lucid"; char[] ARM_DEMANGLING_STYLE_STRING= "arm"; char[] HP_DEMANGLING_STYLE_STRING= "hp"; char[] EDG_DEMANGLING_STYLE_STRING= "edg"; char[] GNU_V3_DEMANGLING_STYLE_STRING= "gnu-v3"; char[] JAVA_DEMANGLING_STYLE_STRING= "java"; char[] GNAT_DEMANGLING_STYLE_STRING= "gnat"; /* Some macros to test what demangling style is active. */ alias current_demangling_style CURRENT_DEMANGLING_STYLE; /** static assert(0,"何してるか良く分からね"); enum{ AUTO_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO), GNU_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU), LUCID_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID), ARM_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_ARM), HP_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_HP), EDG_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG), GNU_V3_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3), JAVA_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA), GNAT_DEMANGLING=((cast(int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT), } */ /* Provide information about the available demangle styles. This code is pulled from gdb into libiberty because it is useful to binutils also. */ extern const struct demangler_engine { const char* demangling_style_name; const demangling_styles demangling_style; const char* demangling_style_doc; } alias demangler_engine libiberty_demanglers[]; extern char* cplus_demangle(char* mangled, int options); extern int cplus_demangle_opname(char *opname, char *result, int options); extern char* cplus_mangle_opname(char *opname, int options); /* Note: This sets global state. FIXME if you care about multi-threading. */ extern void set_cplus_marker_for_demangling(int ch); extern demangling_styles cplus_demangle_set_style(demangling_styles style); extern demangling_styles cplus_demangle_name_to_style(char *name); /* V3 ABI demangling entry points, defined in cp-demangle.c. */ extern char* cplus_demangle_v3(char* mangled, int options); extern char* java_demangle_v3 (char* mangled); enum gnu_v3_ctor_kinds{ gnu_v3_complete_object_ctor = 1, gnu_v3_base_object_ctor, gnu_v3_complete_object_allocating_ctor }; /* Return non-zero iff NAME is the mangled form of a constructor name in the G++ V3 ABI demangling style. Specifically, return an `enum gnu_v3_ctor_kinds' value indicating what kind of constructor it is. */ extern gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (char *name); enum gnu_v3_dtor_kinds{ gnu_v3_deleting_dtor = 1, gnu_v3_complete_object_dtor, gnu_v3_base_object_dtor } /* Return non-zero iff NAME is the mangled form of a destructor name in the G++ V3 ABI demangling style. Specifically, return an `enum gnu_v3_dtor_kinds' value, indicating what kind of destructor it is. */ extern gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (char *name); /* The V3 demangler works in two passes. The first pass builds a tree representation of the mangled name, and the second pass turns the tree representation into a demangled string. Here we define an interface to permit a caller to build their own tree representation, which they can pass to the demangler to get a demangled string. This can be used to canonicalize user input into something which the demangler might output. It could also be used by other demanglers in the future. */ /* These are the component types which may be found in the tree. Many component types have one or two subtrees, referred to as left and right (a component type with only one subtree puts it in the left subtree). */ enum demangle_component_type { /* A name, with a length and a pointer to a string. */ DEMANGLE_COMPONENT_NAME, /* A qualified name. The left subtree is a class or namespace or some such thing, and the right subtree is a name qualified by that class. */ DEMANGLE_COMPONENT_QUAL_NAME, /* A local name. The left subtree describes a function, and the right subtree is a name which is local to that function. */ DEMANGLE_COMPONENT_LOCAL_NAME, /* A typed name. The left subtree is a name, and the right subtree describes that name as a function. */ DEMANGLE_COMPONENT_TYPED_NAME, /* A template. The left subtree is a template name, and the right subtree is a template argument list. */ DEMANGLE_COMPONENT_TEMPLATE, /* A template parameter. This holds a number, which is the template parameter index. */ DEMANGLE_COMPONENT_TEMPLATE_PARAM, /* A constructor. This holds a name and the kind of constructor. */ DEMANGLE_COMPONENT_CTOR, /* A destructor. This holds a name and the kind of destructor. */ DEMANGLE_COMPONENT_DTOR, /* A vtable. This has one subtree, the type for which this is a vtable. */ DEMANGLE_COMPONENT_VTABLE, /* A VTT structure. This has one subtree, the type for which this is a VTT. */ DEMANGLE_COMPONENT_VTT, /* A construction vtable. The left subtree is the type for which this is a vtable, and the right subtree is the derived type for which this vtable is built. */ DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE, /* A typeinfo structure. This has one subtree, the type for which this is the tpeinfo structure. */ DEMANGLE_COMPONENT_TYPEINFO, /* A typeinfo name. This has one subtree, the type for which this is the typeinfo name. */ DEMANGLE_COMPONENT_TYPEINFO_NAME, /* A typeinfo function. This has one subtree, the type for which this is the tpyeinfo function. */ DEMANGLE_COMPONENT_TYPEINFO_FN, /* A thunk. This has one subtree, the name for which this is a thunk. */ DEMANGLE_COMPONENT_THUNK, /* A virtual thunk. This has one subtree, the name for which this is a virtual thunk. */ DEMANGLE_COMPONENT_VIRTUAL_THUNK, /* A covariant thunk. This has one subtree, the name for which this is a covariant thunk. */ DEMANGLE_COMPONENT_COVARIANT_THUNK, /* A Java class. This has one subtree, the type. */ DEMANGLE_COMPONENT_JAVA_CLASS, /* A guard variable. This has one subtree, the name for which this is a guard variable. */ DEMANGLE_COMPONENT_GUARD, /* A reference temporary. This has one subtree, the name for which this is a temporary. */ DEMANGLE_COMPONENT_REFTEMP, /* A hidden alias. This has one subtree, the encoding for which it is providing alternative linkage. */ DEMANGLE_COMPONENT_HIDDEN_ALIAS, /* A standard substitution. This holds the name of the substitution. */ DEMANGLE_COMPONENT_SUB_STD, /* The restrict qualifier. The one subtree is the type which is being qualified. */ DEMANGLE_COMPONENT_RESTRICT, /* The volatile qualifier. The one subtree is the type which is being qualified. */ DEMANGLE_COMPONENT_VOLATILE, /* The const qualifier. The one subtree is the type which is being qualified. */ DEMANGLE_COMPONENT_CONST, /* The restrict qualifier modifying a member function. The one subtree is the type which is being qualified. */ DEMANGLE_COMPONENT_RESTRICT_THIS, /* The volatile qualifier modifying a member function. The one subtree is the type which is being qualified. */ DEMANGLE_COMPONENT_VOLATILE_THIS, /* The const qualifier modifying a member function. The one subtree is the type which is being qualified. */ DEMANGLE_COMPONENT_CONST_THIS, /* A vendor qualifier. The left subtree is the type which is being qualified, and the right subtree is the name of the qualifier. */ DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL, /* A pointer. The one subtree is the type which is being pointed to. */ DEMANGLE_COMPONENT_POINTER, /* A reference. The one subtree is the type which is being referenced. */ DEMANGLE_COMPONENT_REFERENCE, /* A complex type. The one subtree is the base type. */ DEMANGLE_COMPONENT_COMPLEX, /* An imaginary type. The one subtree is the base type. */ DEMANGLE_COMPONENT_IMAGINARY, /* A builtin type. This holds the builtin type information. */ DEMANGLE_COMPONENT_BUILTIN_TYPE, /* A vendor's builtin type. This holds the name of the type. */ DEMANGLE_COMPONENT_VENDOR_TYPE, /* A function type. The left subtree is the return type. The right subtree is a list of ARGLIST nodes. Either or both may be NULL. */ DEMANGLE_COMPONENT_FUNCTION_TYPE, /* An array type. The left subtree is the dimension, which may be NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an expression. The right subtree is the element type. */ DEMANGLE_COMPONENT_ARRAY_TYPE, /* A pointer to member type. The left subtree is the class type, and the right subtree is the member type. CV-qualifiers appear on the latter. */ DEMANGLE_COMPONENT_PTRMEM_TYPE, /* An argument list. The left subtree is the current argument, and the right subtree is either NULL or another ARGLIST node. */ DEMANGLE_COMPONENT_ARGLIST, /* A template argument list. The left subtree is the current template argument, and the right subtree is either NULL or another TEMPLATE_ARGLIST node. */ DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, /* An operator. This holds information about a standard operator. */ DEMANGLE_COMPONENT_OPERATOR, /* An extended operator. This holds the number of arguments, and the name of the extended operator. */ DEMANGLE_COMPONENT_EXTENDED_OPERATOR, /* A typecast, represented as a unary operator. The one subtree is the type to which the argument should be cast. */ DEMANGLE_COMPONENT_CAST, /* A unary expression. The left subtree is the operator, and the right subtree is the single argument. */ DEMANGLE_COMPONENT_UNARY, /* A binary expression. The left subtree is the operator, and the right subtree is a BINARY_ARGS. */ DEMANGLE_COMPONENT_BINARY, /* Arguments to a binary expression. The left subtree is the first argument, and the right subtree is the second argument. */ DEMANGLE_COMPONENT_BINARY_ARGS, /* A trinary expression. The left subtree is the operator, and the right subtree is a TRINARY_ARG1. */ DEMANGLE_COMPONENT_TRINARY, /* Arguments to a trinary expression. The left subtree is the first argument, and the right subtree is a TRINARY_ARG2. */ DEMANGLE_COMPONENT_TRINARY_ARG1, /* More arguments to a trinary expression. The left subtree is the second argument, and the right subtree is the third argument. */ DEMANGLE_COMPONENT_TRINARY_ARG2, /* A literal. The left subtree is the type, and the right subtree is the value, represented as a DEMANGLE_COMPONENT_NAME. */ DEMANGLE_COMPONENT_LITERAL, /* A negative literal. Like LITERAL, but the value is negated. This is a minor hack: the NAME used for LITERAL points directly to the mangled string, but since negative numbers are mangled using 'n' instead of '-', we want a way to indicate a negative number which involves neither modifying the mangled string nor allocating a new copy of the literal in memory. */ DEMANGLE_COMPONENT_LITERAL_NEG }; /* Types which are only used internally. */ struct demangle_operator_info; struct demangle_builtin_type_info; /* A node in the tree representation is an instance of a struct demangle_component. Note that the field names of the struct are not well protected against macros defined by the file including this one. We can fix this if it ever becomes a problem. */ struct demangle_component { /* The type of this component. */ demangle_component_type type; union u { /* For DEMANGLE_COMPONENT_NAME. */ struct s_name { /* A pointer to the name (which need not NULL terminated) and its length. */ const char* s; int len; } /* For DEMANGLE_COMPONENT_OPERATOR. */ struct s_operator { /* Operator. */ const demangle_operator_info *op; } /* For DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */ struct s_extended_operator { /* Number of arguments. */ int args; /* Name. */ demangle_component *name; } /* For DEMANGLE_COMPONENT_CTOR. */ struct s_ctor { /* Kind of constructor. */ gnu_v3_ctor_kinds kind; /* Name. */ demangle_component *name; } /* For DEMANGLE_COMPONENT_DTOR. */ struct s_dtor { /* Kind of destructor. */ gnu_v3_dtor_kinds kind; /* Name. */ demangle_component *name; } /* For DEMANGLE_COMPONENT_BUILTIN_TYPE. */ struct s_builtin { /* Builtin type. */ const demangle_builtin_type_info* type; } /* For DEMANGLE_COMPONENT_SUB_STD. */ struct s_string { /* Standard substitution string. */ const char* string; /* Length of string. */ int len; } /* For DEMANGLE_COMPONENT_TEMPLATE_PARAM. */ struct s_number { /* Template parameter index. */ int number; } /* For other types. */ struct s_binary { /* Left (or only) subtree. */ demangle_component *left; /* Right subtree. */ demangle_component *right; } } }; /* People building mangled trees are expected to allocate instances of struct demangle_component themselves. They can then call one of the following functions to fill them in. */ /* Fill in most component types with a left subtree and a right subtree. Returns non-zero on success, zero on failure, such as an unrecognized or inappropriate component type. */ extern int cplus_demangle_fill_component (demangle_component* fill, demangle_component_type, demangle_component *left, demangle_component *right); /* Fill in a DEMANGLE_COMPONENT_NAME. Returns non-zero on success, zero for bad arguments. */ extern int cplus_demangle_fill_name (demangle_component* fill, char*, int); /* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE, using the name of the builtin type (e.g., "int", etc.). Returns non-zero on success, zero if the type is not recognized. */ extern int cplus_demangle_fill_builtin_type (demangle_component* fill, char* type_name); /* Fill in a DEMANGLE_COMPONENT_OPERATOR, using the name of the operator and the number of arguments which it takes (the latter is used to disambiguate operators which can be both binary and unary, such as '-'). Returns non-zero on success, zero if the operator is not recognized. */ extern int cplus_demangle_fill_operator (demangle_component* fill, char* opname, int args); /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR, providing the number of arguments and the name. Returns non-zero on success, zero for bad arguments. */ extern int cplus_demangle_fill_extended_operator (demangle_component* fill, int numargs, demangle_component* nm); /* Fill in a DEMANGLE_COMPONENT_CTOR. Returns non-zero on success, zero for bad arguments. */ extern int cplus_demangle_fill_ctor(demangle_component* fill, gnu_v3_ctor_kinds kind, demangle_component* name); /* Fill in a DEMANGLE_COMPONENT_DTOR. Returns non-zero on success, zero for bad arguments. */ extern int cplus_demangle_fill_dtor (demangle_component *fill, gnu_v3_dtor_kinds kind, demangle_component *name); /* This function translates a mangled name into a struct demangle_component tree. The first argument is the mangled name. The second argument is DMGL_* options. This returns a pointer to a tree on success, or NULL on failure. On success, the third argument is set to a block of memory allocated by malloc. This block should be passed to free when the tree is no longer needed. */ extern demangle_component* cplus_demangle_v3_components(char* mangled, int options, void** mem); /* This function takes a struct demangle_component tree and returns the corresponding demangled string. The first argument is DMGL_* options. The second is the tree to demangle. The third is a guess at the length of the demangled string, used to initially allocate the return buffer. The fourth is a pointer to a size_t. On success, this function returns a buffer allocated by malloc(), and sets the size_t pointed to by the fourth argument to the size of the allocated buffer (not the length of the returned string). On failure, this function returns NULL, and sets the size_t pointed to by the fourth argument to 0 for an invalid tree, or to 1 for a memory allocation error. */ extern char* cplus_demangle_print (int options, demangle_component* tree, int estimated_length, size_t* p_allocated_size);