1169695Skan/* Internal demangler interface for g++ V3 ABI.
2169695Skan   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3169695Skan   Written by Ian Lance Taylor <ian@wasabisystems.com>.
4169695Skan
5169695Skan   This file is part of the libiberty library, which is part of GCC.
6169695Skan
7169695Skan   This file is free software; you can redistribute it and/or modify
8169695Skan   it under the terms of the GNU General Public License as published by
9169695Skan   the Free Software Foundation; either version 2 of the License, or
10169695Skan   (at your option) any later version.
11169695Skan
12169695Skan   In addition to the permissions in the GNU General Public License, the
13169695Skan   Free Software Foundation gives you unlimited permission to link the
14169695Skan   compiled version of this file into combinations with other programs,
15169695Skan   and to distribute those combinations without any restriction coming
16169695Skan   from the use of this file.  (The General Public License restrictions
17169695Skan   do apply in other respects; for example, they cover modification of
18169695Skan   the file, and distribution when not linked into a combined
19169695Skan   executable.)
20169695Skan
21169695Skan   This program is distributed in the hope that it will be useful,
22169695Skan   but WITHOUT ANY WARRANTY; without even the implied warranty of
23169695Skan   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24169695Skan   GNU General Public License for more details.
25169695Skan
26169695Skan   You should have received a copy of the GNU General Public License
27169695Skan   along with this program; if not, write to the Free Software
28169695Skan   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
29169695Skan*/
30169695Skan
31169695Skan/* This file provides some definitions shared by cp-demangle.c and
32169695Skan   cp-demint.c.  It should not be included by any other files.  */
33169695Skan
34169695Skan/* Information we keep for operators.  */
35169695Skan
36169695Skanstruct demangle_operator_info
37169695Skan{
38169695Skan  /* Mangled name.  */
39169695Skan  const char *code;
40169695Skan  /* Real name.  */
41169695Skan  const char *name;
42169695Skan  /* Length of real name.  */
43169695Skan  int len;
44169695Skan  /* Number of arguments.  */
45169695Skan  int args;
46169695Skan};
47169695Skan
48169695Skan/* How to print the value of a builtin type.  */
49169695Skan
50169695Skanenum d_builtin_type_print
51169695Skan{
52169695Skan  /* Print as (type)val.  */
53169695Skan  D_PRINT_DEFAULT,
54169695Skan  /* Print as integer.  */
55169695Skan  D_PRINT_INT,
56169695Skan  /* Print as unsigned integer, with trailing "u".  */
57169695Skan  D_PRINT_UNSIGNED,
58169695Skan  /* Print as long, with trailing "l".  */
59169695Skan  D_PRINT_LONG,
60169695Skan  /* Print as unsigned long, with trailing "ul".  */
61169695Skan  D_PRINT_UNSIGNED_LONG,
62169695Skan  /* Print as long long, with trailing "ll".  */
63169695Skan  D_PRINT_LONG_LONG,
64169695Skan  /* Print as unsigned long long, with trailing "ull".  */
65169695Skan  D_PRINT_UNSIGNED_LONG_LONG,
66169695Skan  /* Print as bool.  */
67169695Skan  D_PRINT_BOOL,
68169695Skan  /* Print as float--put value in square brackets.  */
69169695Skan  D_PRINT_FLOAT,
70169695Skan  /* Print in usual way, but here to detect void.  */
71169695Skan  D_PRINT_VOID
72169695Skan};
73169695Skan
74169695Skan/* Information we keep for a builtin type.  */
75169695Skan
76169695Skanstruct demangle_builtin_type_info
77169695Skan{
78169695Skan  /* Type name.  */
79169695Skan  const char *name;
80169695Skan  /* Length of type name.  */
81169695Skan  int len;
82169695Skan  /* Type name when using Java.  */
83169695Skan  const char *java_name;
84169695Skan  /* Length of java name.  */
85169695Skan  int java_len;
86169695Skan  /* How to print a value of this type.  */
87169695Skan  enum d_builtin_type_print print;
88169695Skan};
89169695Skan
90169695Skan/* The information structure we pass around.  */
91169695Skan
92169695Skanstruct d_info
93169695Skan{
94169695Skan  /* The string we are demangling.  */
95169695Skan  const char *s;
96169695Skan  /* The end of the string we are demangling.  */
97169695Skan  const char *send;
98169695Skan  /* The options passed to the demangler.  */
99169695Skan  int options;
100169695Skan  /* The next character in the string to consider.  */
101169695Skan  const char *n;
102169695Skan  /* The array of components.  */
103169695Skan  struct demangle_component *comps;
104169695Skan  /* The index of the next available component.  */
105169695Skan  int next_comp;
106169695Skan  /* The number of available component structures.  */
107169695Skan  int num_comps;
108169695Skan  /* The array of substitutions.  */
109169695Skan  struct demangle_component **subs;
110169695Skan  /* The index of the next substitution.  */
111169695Skan  int next_sub;
112169695Skan  /* The number of available entries in the subs array.  */
113169695Skan  int num_subs;
114169695Skan  /* The number of substitutions which we actually made from the subs
115169695Skan     array, plus the number of template parameter references we
116169695Skan     saw.  */
117169695Skan  int did_subs;
118169695Skan  /* The last name we saw, for constructors and destructors.  */
119169695Skan  struct demangle_component *last_name;
120169695Skan  /* A running total of the length of large expansions from the
121169695Skan     mangled name to the demangled name, such as standard
122169695Skan     substitutions and builtin types.  */
123169695Skan  int expansion;
124169695Skan};
125169695Skan
126259694Spfg/* To avoid running past the ending '\0', don't:
127259694Spfg   - call d_peek_next_char if d_peek_char returned '\0'
128259694Spfg   - call d_advance with an 'i' that is too large
129259694Spfg   - call d_check_char(di, '\0')
130259694Spfg   Everything else is safe.  */
131169695Skan#define d_peek_char(di) (*((di)->n))
132169695Skan#define d_peek_next_char(di) ((di)->n[1])
133169695Skan#define d_advance(di, i) ((di)->n += (i))
134259694Spfg#define d_check_char(di, c) (d_peek_char(di) == c ? ((di)->n++, 1) : 0)
135259694Spfg#define d_next_char(di) (d_peek_char(di) == '\0' ? '\0' : *((di)->n++))
136169695Skan#define d_str(di) ((di)->n)
137169695Skan
138169695Skan/* Functions and arrays in cp-demangle.c which are referenced by
139169695Skan   functions in cp-demint.c.  */
140169695Skan#ifdef IN_GLIBCPP_V3
141169695Skan#define CP_STATIC_IF_GLIBCPP_V3 static
142169695Skan#else
143169695Skan#define CP_STATIC_IF_GLIBCPP_V3 extern
144169695Skan#endif
145169695Skan
146169695SkanCP_STATIC_IF_GLIBCPP_V3
147169695Skanconst struct demangle_operator_info cplus_demangle_operators[];
148169695Skan
149169695Skan#define D_BUILTIN_TYPE_COUNT (26)
150169695Skan
151169695SkanCP_STATIC_IF_GLIBCPP_V3
152169695Skanconst struct demangle_builtin_type_info
153169695Skancplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
154169695Skan
155169695SkanCP_STATIC_IF_GLIBCPP_V3
156169695Skanstruct demangle_component *
157169695Skancplus_demangle_mangled_name (struct d_info *, int);
158169695Skan
159169695SkanCP_STATIC_IF_GLIBCPP_V3
160169695Skanstruct demangle_component *
161169695Skancplus_demangle_type (struct d_info *);
162169695Skan
163169695Skanextern void
164169695Skancplus_demangle_init_info (const char *, int, size_t, struct d_info *);
165169695Skan
166169695Skan/* cp-demangle.c needs to define this a little differently */
167169695Skan#undef CP_STATIC_IF_GLIBCPP_V3
168