cp-demangle.h revision 130562
1285612Sdelphij/* Internal demangler interface for g++ V3 ABI.
254359Sroberto   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3285612Sdelphij   Written by Ian Lance Taylor <ian@wasabisystems.com>.
4285612Sdelphij
582498Sroberto   This file is part of the libiberty library, which is part of GCC.
682498Sroberto
782498Sroberto   This file is free software; you can redistribute it and/or modify
854359Sroberto   it under the terms of the GNU General Public License as published by
982498Sroberto   the Free Software Foundation; either version 2 of the License, or
1082498Sroberto   (at your option) any later version.
1182498Sroberto
1282498Sroberto   In addition to the permissions in the GNU General Public License, the
1354359Sroberto   Free Software Foundation gives you unlimited permission to link the
14285612Sdelphij   compiled version of this file into combinations with other programs,
15200576Sroberto   and to distribute those combinations without any restriction coming
16200576Sroberto   from the use of this file.  (The General Public License restrictions
17285612Sdelphij   do apply in other respects; for example, they cover modification of
18285612Sdelphij   the file, and distribution when not linked into a combined
19200576Sroberto   executable.)
20200576Sroberto
21285612Sdelphij   This program is distributed in the hope that it will be useful,
22200576Sroberto   but WITHOUT ANY WARRANTY; without even the implied warranty of
23285612Sdelphij   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24285612Sdelphij   GNU General Public License for more details.
25182007Sroberto
26285612Sdelphij   You should have received a copy of the GNU General Public License
27285612Sdelphij   along with this program; if not, write to the Free Software
28285612Sdelphij   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29285612Sdelphij*/
30182007Sroberto
31285612Sdelphij/* This file provides some definitions shared by cp-demangle.c and
32285612Sdelphij   cp-demint.c.  It should not be included by any other files.  */
33285612Sdelphij
34285612Sdelphij/* Information we keep for operators.  */
35285612Sdelphij
36182007Srobertostruct demangle_operator_info
37285612Sdelphij{
38285612Sdelphij  /* Mangled name.  */
39285612Sdelphij  const char *code;
40285612Sdelphij  /* Real name.  */
41285612Sdelphij  const char *name;
42285612Sdelphij  /* Length of real name.  */
43285612Sdelphij  int len;
44285612Sdelphij  /* Number of arguments.  */
45285612Sdelphij  int args;
46285612Sdelphij};
47285612Sdelphij
48285612Sdelphij/* How to print the value of a builtin type.  */
49285612Sdelphij
50182007Srobertoenum d_builtin_type_print
51285612Sdelphij{
52182007Sroberto  /* Print as (type)val.  */
53285612Sdelphij  D_PRINT_DEFAULT,
54285612Sdelphij  /* Print as integer.  */
55285612Sdelphij  D_PRINT_INT,
56285612Sdelphij  /* Print as long, with trailing `l'.  */
57285612Sdelphij  D_PRINT_LONG,
58285612Sdelphij  /* Print as bool.  */
59285612Sdelphij  D_PRINT_BOOL,
60285612Sdelphij  /* Print in usual way, but here to detect void.  */
61285612Sdelphij  D_PRINT_VOID
6254359Sroberto};
63285612Sdelphij
6482498Sroberto/* Information we keep for a builtin type.  */
65285612Sdelphij
66285612Sdelphijstruct demangle_builtin_type_info
67285612Sdelphij{
68285612Sdelphij  /* Type name.  */
69285612Sdelphij  const char *name;
70285612Sdelphij  /* Length of type name.  */
71285612Sdelphij  int len;
72285612Sdelphij  /* Type name when using Java.  */
73285612Sdelphij  const char *java_name;
74285612Sdelphij  /* Length of java name.  */
75182007Sroberto  int java_len;
7682498Sroberto  /* How to print a value of this type.  */
77285612Sdelphij  enum d_builtin_type_print print;
78285612Sdelphij};
79285612Sdelphij
80285612Sdelphij/* The information structure we pass around.  */
81285612Sdelphij
82285612Sdelphijstruct d_info
83285612Sdelphij{
84182007Sroberto  /* The string we are demangling.  */
85182007Sroberto  const char *s;
86182007Sroberto  /* The end of the string we are demangling.  */
87285612Sdelphij  const char *send;
88285612Sdelphij  /* The options passed to the demangler.  */
89285612Sdelphij  int options;
90285612Sdelphij  /* The next character in the string to consider.  */
91182007Sroberto  const char *n;
92285612Sdelphij  /* The array of components.  */
93285612Sdelphij  struct demangle_component *comps;
94285612Sdelphij  /* The index of the next available component.  */
95182007Sroberto  int next_comp;
96285612Sdelphij  /* The number of available component structures.  */
97285612Sdelphij  int num_comps;
98285612Sdelphij  /* The array of substitutions.  */
99182007Sroberto  struct demangle_component **subs;
100285612Sdelphij  /* The index of the next substitution.  */
101285612Sdelphij  int next_sub;
102285612Sdelphij  /* The number of available entries in the subs array.  */
103182007Sroberto  int num_subs;
104285612Sdelphij  /* The number of substitutions which we actually made from the subs
105285612Sdelphij     array, plus the number of template parameter references we
106285612Sdelphij     saw.  */
107285612Sdelphij  int did_subs;
108132451Sroberto  /* The last name we saw, for constructors and destructors.  */
109285612Sdelphij  struct demangle_component *last_name;
110285612Sdelphij  /* A running total of the length of large expansions from the
111285612Sdelphij     mangled name to the demangled name, such as standard
112285612Sdelphij     substitutions and builtin types.  */
113285612Sdelphij  int expansion;
114285612Sdelphij};
115285612Sdelphij
116285612Sdelphij#define d_peek_char(di) (*((di)->n))
117285612Sdelphij#define d_peek_next_char(di) ((di)->n[1])
118285612Sdelphij#define d_advance(di, i) ((di)->n += (i))
119285612Sdelphij#define d_next_char(di) (*((di)->n++))
120285612Sdelphij#define d_str(di) ((di)->n)
121285612Sdelphij
122285612Sdelphij/* Functions and arrays in cp-demangle.c which are referenced by
123285612Sdelphij   functions in cp-demint.c.  */
12454359Sroberto
125285612Sdelphijextern const struct demangle_operator_info cplus_demangle_operators[];
126182007Sroberto
127285612Sdelphij#define D_BUILTIN_TYPE_COUNT (26)
128285612Sdelphij
129285612Sdelphijextern const struct demangle_builtin_type_info
130182007Srobertocplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
131285612Sdelphij
132285612Sdelphijextern struct demangle_component *
133285612Sdelphijcplus_demangle_mangled_name PARAMS ((struct d_info *, int));
134285612Sdelphij
135285612Sdelphijextern struct demangle_component *
136285612Sdelphijcplus_demangle_type PARAMS ((struct d_info *));
137285612Sdelphij
138182007Srobertoextern void
139285612Sdelphijcplus_demangle_init_info PARAMS ((const char *, int, size_t, struct d_info *));
14056746Sroberto