1130561Sobrien/* Internal demangler interface for g++ V3 ABI.
2218822Sdim   Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
3130561Sobrien   Written by Ian Lance Taylor <ian@wasabisystems.com>.
4130561Sobrien
5130561Sobrien   This file is part of the libiberty library, which is part of GCC.
6130561Sobrien
7130561Sobrien   This file is free software; you can redistribute it and/or modify
8130561Sobrien   it under the terms of the GNU General Public License as published by
9130561Sobrien   the Free Software Foundation; either version 2 of the License, or
10130561Sobrien   (at your option) any later version.
11130561Sobrien
12130561Sobrien   In addition to the permissions in the GNU General Public License, the
13130561Sobrien   Free Software Foundation gives you unlimited permission to link the
14130561Sobrien   compiled version of this file into combinations with other programs,
15130561Sobrien   and to distribute those combinations without any restriction coming
16130561Sobrien   from the use of this file.  (The General Public License restrictions
17130561Sobrien   do apply in other respects; for example, they cover modification of
18130561Sobrien   the file, and distribution when not linked into a combined
19130561Sobrien   executable.)
20130561Sobrien
21130561Sobrien   This program is distributed in the hope that it will be useful,
22130561Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
23130561Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24130561Sobrien   GNU General Public License for more details.
25130561Sobrien
26130561Sobrien   You should have received a copy of the GNU General Public License
27130561Sobrien   along with this program; if not, write to the Free Software
28218822Sdim   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
29130561Sobrien*/
30130561Sobrien
31130561Sobrien/* This file provides some definitions shared by cp-demangle.c and
32130561Sobrien   cp-demint.c.  It should not be included by any other files.  */
33130561Sobrien
34130561Sobrien/* Information we keep for operators.  */
35130561Sobrien
36130561Sobrienstruct demangle_operator_info
37130561Sobrien{
38130561Sobrien  /* Mangled name.  */
39130561Sobrien  const char *code;
40130561Sobrien  /* Real name.  */
41130561Sobrien  const char *name;
42130561Sobrien  /* Length of real name.  */
43130561Sobrien  int len;
44130561Sobrien  /* Number of arguments.  */
45130561Sobrien  int args;
46130561Sobrien};
47130561Sobrien
48130561Sobrien/* How to print the value of a builtin type.  */
49130561Sobrien
50130561Sobrienenum d_builtin_type_print
51130561Sobrien{
52130561Sobrien  /* Print as (type)val.  */
53130561Sobrien  D_PRINT_DEFAULT,
54130561Sobrien  /* Print as integer.  */
55130561Sobrien  D_PRINT_INT,
56218822Sdim  /* Print as unsigned integer, with trailing "u".  */
57218822Sdim  D_PRINT_UNSIGNED,
58218822Sdim  /* Print as long, with trailing "l".  */
59130561Sobrien  D_PRINT_LONG,
60218822Sdim  /* Print as unsigned long, with trailing "ul".  */
61218822Sdim  D_PRINT_UNSIGNED_LONG,
62218822Sdim  /* Print as long long, with trailing "ll".  */
63218822Sdim  D_PRINT_LONG_LONG,
64218822Sdim  /* Print as unsigned long long, with trailing "ull".  */
65218822Sdim  D_PRINT_UNSIGNED_LONG_LONG,
66130561Sobrien  /* Print as bool.  */
67130561Sobrien  D_PRINT_BOOL,
68218822Sdim  /* Print as float--put value in square brackets.  */
69218822Sdim  D_PRINT_FLOAT,
70130561Sobrien  /* Print in usual way, but here to detect void.  */
71130561Sobrien  D_PRINT_VOID
72130561Sobrien};
73130561Sobrien
74130561Sobrien/* Information we keep for a builtin type.  */
75130561Sobrien
76130561Sobrienstruct demangle_builtin_type_info
77130561Sobrien{
78130561Sobrien  /* Type name.  */
79130561Sobrien  const char *name;
80130561Sobrien  /* Length of type name.  */
81130561Sobrien  int len;
82130561Sobrien  /* Type name when using Java.  */
83130561Sobrien  const char *java_name;
84130561Sobrien  /* Length of java name.  */
85130561Sobrien  int java_len;
86130561Sobrien  /* How to print a value of this type.  */
87130561Sobrien  enum d_builtin_type_print print;
88130561Sobrien};
89130561Sobrien
90130561Sobrien/* The information structure we pass around.  */
91130561Sobrien
92130561Sobrienstruct d_info
93130561Sobrien{
94130561Sobrien  /* The string we are demangling.  */
95130561Sobrien  const char *s;
96130561Sobrien  /* The end of the string we are demangling.  */
97130561Sobrien  const char *send;
98130561Sobrien  /* The options passed to the demangler.  */
99130561Sobrien  int options;
100130561Sobrien  /* The next character in the string to consider.  */
101130561Sobrien  const char *n;
102130561Sobrien  /* The array of components.  */
103130561Sobrien  struct demangle_component *comps;
104130561Sobrien  /* The index of the next available component.  */
105130561Sobrien  int next_comp;
106130561Sobrien  /* The number of available component structures.  */
107130561Sobrien  int num_comps;
108130561Sobrien  /* The array of substitutions.  */
109130561Sobrien  struct demangle_component **subs;
110130561Sobrien  /* The index of the next substitution.  */
111130561Sobrien  int next_sub;
112130561Sobrien  /* The number of available entries in the subs array.  */
113130561Sobrien  int num_subs;
114130561Sobrien  /* The number of substitutions which we actually made from the subs
115130561Sobrien     array, plus the number of template parameter references we
116130561Sobrien     saw.  */
117130561Sobrien  int did_subs;
118130561Sobrien  /* The last name we saw, for constructors and destructors.  */
119130561Sobrien  struct demangle_component *last_name;
120130561Sobrien  /* A running total of the length of large expansions from the
121130561Sobrien     mangled name to the demangled name, such as standard
122130561Sobrien     substitutions and builtin types.  */
123130561Sobrien  int expansion;
124130561Sobrien};
125130561Sobrien
126218822Sdim/* To avoid running past the ending '\0', don't:
127218822Sdim   - call d_peek_next_char if d_peek_char returned '\0'
128218822Sdim   - call d_advance with an 'i' that is too large
129218822Sdim   - call d_check_char(di, '\0')
130218822Sdim   Everything else is safe.  */
131130561Sobrien#define d_peek_char(di) (*((di)->n))
132130561Sobrien#define d_peek_next_char(di) ((di)->n[1])
133130561Sobrien#define d_advance(di, i) ((di)->n += (i))
134218822Sdim#define d_check_char(di, c) (d_peek_char(di) == c ? ((di)->n++, 1) : 0)
135218822Sdim#define d_next_char(di) (d_peek_char(di) == '\0' ? '\0' : *((di)->n++))
136130561Sobrien#define d_str(di) ((di)->n)
137130561Sobrien
138130561Sobrien/* Functions and arrays in cp-demangle.c which are referenced by
139130561Sobrien   functions in cp-demint.c.  */
140218822Sdim#ifdef IN_GLIBCPP_V3
141218822Sdim#define CP_STATIC_IF_GLIBCPP_V3 static
142218822Sdim#else
143218822Sdim#define CP_STATIC_IF_GLIBCPP_V3 extern
144218822Sdim#endif
145130561Sobrien
146218822Sdim#ifndef IN_GLIBCPP_V3
147130561Sobrienextern const struct demangle_operator_info cplus_demangle_operators[];
148218822Sdim#endif
149130561Sobrien
150130561Sobrien#define D_BUILTIN_TYPE_COUNT (26)
151130561Sobrien
152218822SdimCP_STATIC_IF_GLIBCPP_V3
153218822Sdimconst struct demangle_builtin_type_info
154130561Sobriencplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
155130561Sobrien
156218822SdimCP_STATIC_IF_GLIBCPP_V3
157218822Sdimstruct demangle_component *
158218822Sdimcplus_demangle_mangled_name (struct d_info *, int);
159130561Sobrien
160218822SdimCP_STATIC_IF_GLIBCPP_V3
161218822Sdimstruct demangle_component *
162218822Sdimcplus_demangle_type (struct d_info *);
163130561Sobrien
164130561Sobrienextern void
165218822Sdimcplus_demangle_init_info (const char *, int, size_t, struct d_info *);
166218822Sdim
167218822Sdim/* cp-demangle.c needs to define this a little differently */
168218822Sdim#undef CP_STATIC_IF_GLIBCPP_V3
169