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