00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifdef HAVE_CONFIG_H
00041 #include "config.h"
00042 #endif
00043
00044 #ifdef HAVE_STDLIB_H
00045 #include <stdlib.h>
00046 #endif
00047 #ifdef HAVE_STRING_H
00048 #include <string.h>
00049 #endif
00050
00051 #include "ansidecl.h"
00052 #include "libiberty.h"
00053 #include "demangle.h"
00054 #include "cp-demangle.h"
00055
00056
00057
00058 int
00059 cplus_demangle_fill_component (p, type, left, right)
00060 struct demangle_component *p;
00061 enum demangle_component_type type;
00062 struct demangle_component *left;
00063 struct demangle_component *right;
00064 {
00065 if (p == NULL)
00066 return 0;
00067 switch (type)
00068 {
00069 case DEMANGLE_COMPONENT_QUAL_NAME:
00070 case DEMANGLE_COMPONENT_LOCAL_NAME:
00071 case DEMANGLE_COMPONENT_TYPED_NAME:
00072 case DEMANGLE_COMPONENT_TEMPLATE:
00073 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
00074 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
00075 case DEMANGLE_COMPONENT_FUNCTION_TYPE:
00076 case DEMANGLE_COMPONENT_ARRAY_TYPE:
00077 case DEMANGLE_COMPONENT_PTRMEM_TYPE:
00078 case DEMANGLE_COMPONENT_ARGLIST:
00079 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
00080 case DEMANGLE_COMPONENT_UNARY:
00081 case DEMANGLE_COMPONENT_BINARY:
00082 case DEMANGLE_COMPONENT_BINARY_ARGS:
00083 case DEMANGLE_COMPONENT_TRINARY:
00084 case DEMANGLE_COMPONENT_TRINARY_ARG1:
00085 case DEMANGLE_COMPONENT_TRINARY_ARG2:
00086 case DEMANGLE_COMPONENT_LITERAL:
00087 case DEMANGLE_COMPONENT_LITERAL_NEG:
00088 break;
00089
00090
00091 case DEMANGLE_COMPONENT_VTABLE:
00092 case DEMANGLE_COMPONENT_VTT:
00093 case DEMANGLE_COMPONENT_TYPEINFO:
00094 case DEMANGLE_COMPONENT_TYPEINFO_NAME:
00095 case DEMANGLE_COMPONENT_TYPEINFO_FN:
00096 case DEMANGLE_COMPONENT_THUNK:
00097 case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
00098 case DEMANGLE_COMPONENT_COVARIANT_THUNK:
00099 case DEMANGLE_COMPONENT_JAVA_CLASS:
00100 case DEMANGLE_COMPONENT_GUARD:
00101 case DEMANGLE_COMPONENT_REFTEMP:
00102 case DEMANGLE_COMPONENT_RESTRICT:
00103 case DEMANGLE_COMPONENT_VOLATILE:
00104 case DEMANGLE_COMPONENT_CONST:
00105 case DEMANGLE_COMPONENT_RESTRICT_THIS:
00106 case DEMANGLE_COMPONENT_VOLATILE_THIS:
00107 case DEMANGLE_COMPONENT_CONST_THIS:
00108 case DEMANGLE_COMPONENT_POINTER:
00109 case DEMANGLE_COMPONENT_REFERENCE:
00110 case DEMANGLE_COMPONENT_COMPLEX:
00111 case DEMANGLE_COMPONENT_IMAGINARY:
00112 case DEMANGLE_COMPONENT_VENDOR_TYPE:
00113 case DEMANGLE_COMPONENT_CAST:
00114 if (right != NULL)
00115 return 0;
00116 break;
00117
00118 default:
00119
00120 return 0;
00121 }
00122
00123 p->type = type;
00124 p->u.s_binary.left = left;
00125 p->u.s_binary.right = right;
00126
00127 return 1;
00128 }
00129
00130
00131
00132 int
00133 cplus_demangle_fill_builtin_type (p, typename)
00134 struct demangle_component *p;
00135 const char *typename;
00136 {
00137 int len;
00138 unsigned int i;
00139
00140 if (p == NULL || typename == NULL)
00141 return 0;
00142 len = strlen (typename);
00143 for (i = 0; i < D_BUILTIN_TYPE_COUNT; ++i)
00144 {
00145 if (len == cplus_demangle_builtin_types[i].len
00146 && strcmp (typename, cplus_demangle_builtin_types[i].name) == 0)
00147 {
00148 p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
00149 p->u.s_builtin.type = &cplus_demangle_builtin_types[i];
00150 return 1;
00151 }
00152 }
00153 return 0;
00154 }
00155
00156
00157
00158 int
00159 cplus_demangle_fill_operator (p, opname, args)
00160 struct demangle_component *p;
00161 const char *opname;
00162 int args;
00163 {
00164 int len;
00165 unsigned int i;
00166
00167 if (p == NULL || opname == NULL)
00168 return 0;
00169 len = strlen (opname);
00170 for (i = 0; cplus_demangle_operators[i].name != NULL; ++i)
00171 {
00172 if (len == cplus_demangle_operators[i].len
00173 && args == cplus_demangle_operators[i].args
00174 && strcmp (opname, cplus_demangle_operators[i].name) == 0)
00175 {
00176 p->type = DEMANGLE_COMPONENT_OPERATOR;
00177 p->u.s_operator.op = &cplus_demangle_operators[i];
00178 return 1;
00179 }
00180 }
00181 return 0;
00182 }
00183
00184
00185
00186 struct demangle_component *
00187 cplus_demangle_v3_components (mangled, options, mem)
00188 const char *mangled;
00189 int options;
00190 void **mem;
00191 {
00192 size_t len;
00193 int type;
00194 struct d_info di;
00195 struct demangle_component *dc;
00196
00197 len = strlen (mangled);
00198
00199 if (mangled[0] == '_' && mangled[1] == 'Z')
00200 type = 0;
00201 else
00202 {
00203 if ((options & DMGL_TYPES) == 0)
00204 return NULL;
00205 type = 1;
00206 }
00207
00208 cplus_demangle_init_info (mangled, options, len, &di);
00209
00210 di.comps = ((struct demangle_component *)
00211 malloc (di.num_comps * sizeof (struct demangle_component)));
00212 di.subs = ((struct demangle_component **)
00213 malloc (di.num_subs * sizeof (struct demangle_component *)));
00214 if (di.comps == NULL || di.subs == NULL)
00215 {
00216 if (di.comps != NULL)
00217 free (di.comps);
00218 if (di.subs != NULL)
00219 free (di.subs);
00220 return NULL;
00221 }
00222
00223 if (! type)
00224 dc = cplus_demangle_mangled_name (&di, 1);
00225 else
00226 dc = cplus_demangle_type (&di);
00227
00228
00229
00230 if ((options & DMGL_PARAMS) != 0 && d_peek_char (&di) != '\0')
00231 dc = NULL;
00232
00233 free (di.subs);
00234
00235 if (dc != NULL)
00236 *mem = di.comps;
00237 else
00238 free (di.comps);
00239
00240 return dc;
00241 }