Back to index

cell-binutils  2.17cvs20070401
cp-demangle.h
Go to the documentation of this file.
00001 /* Internal demangler interface for g++ V3 ABI.
00002    Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
00003    Written by Ian Lance Taylor <ian@wasabisystems.com>.
00004 
00005    This file is part of the libiberty library, which is part of GCC.
00006 
00007    This file is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    In addition to the permissions in the GNU General Public License, the
00013    Free Software Foundation gives you unlimited permission to link the
00014    compiled version of this file into combinations with other programs,
00015    and to distribute those combinations without any restriction coming
00016    from the use of this file.  (The General Public License restrictions
00017    do apply in other respects; for example, they cover modification of
00018    the file, and distribution when not linked into a combined
00019    executable.)
00020 
00021    This program is distributed in the hope that it will be useful,
00022    but WITHOUT ANY WARRANTY; without even the implied warranty of
00023    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024    GNU General Public License for more details.
00025 
00026    You should have received a copy of the GNU General Public License
00027    along with this program; if not, write to the Free Software
00028    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 
00029 */
00030 
00031 /* This file provides some definitions shared by cp-demangle.c and
00032    cp-demint.c.  It should not be included by any other files.  */
00033 
00034 /* Information we keep for operators.  */
00035 
00036 struct demangle_operator_info
00037 {
00038   /* Mangled name.  */
00039   const char *code;
00040   /* Real name.  */
00041   const char *name;
00042   /* Length of real name.  */
00043   int len;
00044   /* Number of arguments.  */
00045   int args;
00046 };
00047 
00048 /* How to print the value of a builtin type.  */
00049 
00050 enum d_builtin_type_print
00051 {
00052   /* Print as (type)val.  */
00053   D_PRINT_DEFAULT,
00054   /* Print as integer.  */
00055   D_PRINT_INT,
00056   /* Print as unsigned integer, with trailing "u".  */
00057   D_PRINT_UNSIGNED,
00058   /* Print as long, with trailing "l".  */
00059   D_PRINT_LONG,
00060   /* Print as unsigned long, with trailing "ul".  */
00061   D_PRINT_UNSIGNED_LONG,
00062   /* Print as long long, with trailing "ll".  */
00063   D_PRINT_LONG_LONG,
00064   /* Print as unsigned long long, with trailing "ull".  */
00065   D_PRINT_UNSIGNED_LONG_LONG,
00066   /* Print as bool.  */
00067   D_PRINT_BOOL,
00068   /* Print as float--put value in square brackets.  */
00069   D_PRINT_FLOAT,
00070   /* Print in usual way, but here to detect void.  */
00071   D_PRINT_VOID
00072 };
00073 
00074 /* Information we keep for a builtin type.  */
00075 
00076 struct demangle_builtin_type_info
00077 {
00078   /* Type name.  */
00079   const char *name;
00080   /* Length of type name.  */
00081   int len;
00082   /* Type name when using Java.  */
00083   const char *java_name;
00084   /* Length of java name.  */
00085   int java_len;
00086   /* How to print a value of this type.  */
00087   enum d_builtin_type_print print;
00088 };
00089 
00090 /* The information structure we pass around.  */
00091 
00092 struct d_info
00093 {
00094   /* The string we are demangling.  */
00095   const char *s;
00096   /* The end of the string we are demangling.  */
00097   const char *send;
00098   /* The options passed to the demangler.  */
00099   int options;
00100   /* The next character in the string to consider.  */
00101   const char *n;
00102   /* The array of components.  */
00103   struct demangle_component *comps;
00104   /* The index of the next available component.  */
00105   int next_comp;
00106   /* The number of available component structures.  */
00107   int num_comps;
00108   /* The array of substitutions.  */
00109   struct demangle_component **subs;
00110   /* The index of the next substitution.  */
00111   int next_sub;
00112   /* The number of available entries in the subs array.  */
00113   int num_subs;
00114   /* The number of substitutions which we actually made from the subs
00115      array, plus the number of template parameter references we
00116      saw.  */
00117   int did_subs;
00118   /* The last name we saw, for constructors and destructors.  */
00119   struct demangle_component *last_name;
00120   /* A running total of the length of large expansions from the
00121      mangled name to the demangled name, such as standard
00122      substitutions and builtin types.  */
00123   int expansion;
00124 };
00125 
00126 /* To avoid running past the ending '\0', don't:
00127    - call d_peek_next_char if d_peek_char returned '\0'
00128    - call d_advance with an 'i' that is too large
00129    - call d_check_char(di, '\0')
00130    Everything else is safe.  */
00131 #define d_peek_char(di) (*((di)->n))
00132 #define d_peek_next_char(di) ((di)->n[1])
00133 #define d_advance(di, i) ((di)->n += (i))
00134 #define d_check_char(di, c) (d_peek_char(di) == c ? ((di)->n++, 1) : 0)
00135 #define d_next_char(di) (d_peek_char(di) == '\0' ? '\0' : *((di)->n++))
00136 #define d_str(di) ((di)->n)
00137 
00138 /* Functions and arrays in cp-demangle.c which are referenced by
00139    functions in cp-demint.c.  */
00140 #ifdef IN_GLIBCPP_V3
00141 #define CP_STATIC_IF_GLIBCPP_V3 static
00142 #else
00143 #define CP_STATIC_IF_GLIBCPP_V3 extern
00144 #endif
00145 
00146 #ifndef IN_GLIBCPP_V3
00147 extern const struct demangle_operator_info cplus_demangle_operators[];
00148 #endif
00149 
00150 #define D_BUILTIN_TYPE_COUNT (26)
00151 
00152 CP_STATIC_IF_GLIBCPP_V3
00153 const struct demangle_builtin_type_info
00154 cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
00155 
00156 CP_STATIC_IF_GLIBCPP_V3
00157 struct demangle_component *
00158 cplus_demangle_mangled_name (struct d_info *, int);
00159 
00160 CP_STATIC_IF_GLIBCPP_V3
00161 struct demangle_component *
00162 cplus_demangle_type (struct d_info *);
00163 
00164 extern void
00165 cplus_demangle_init_info (const char *, int, size_t, struct d_info *);
00166 
00167 /* cp-demangle.c needs to define this a little differently */
00168 #undef CP_STATIC_IF_GLIBCPP_V3