Merge branch 'vendor/DIFFUTILS'
[dragonfly.git] / contrib / binutils-2.27 / libiberty / cp-demangle.h
1 /* Internal demangler interface for g++ V3 ABI.
2    Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010
3    Free Software Foundation, Inc.
4    Written by Ian Lance Taylor <ian@wasabisystems.com>.
5
6    This file is part of the libiberty library, which is part of GCC.
7
8    This file is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    In addition to the permissions in the GNU General Public License, the
14    Free Software Foundation gives you unlimited permission to link the
15    compiled version of this file into combinations with other programs,
16    and to distribute those combinations without any restriction coming
17    from the use of this file.  (The General Public License restrictions
18    do apply in other respects; for example, they cover modification of
19    the file, and distribution when not linked into a combined
20    executable.)
21
22    This program is distributed in the hope that it will be useful,
23    but WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25    GNU General Public License for more details.
26
27    You should have received a copy of the GNU General Public License
28    along with this program; if not, write to the Free Software
29    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 
30 */
31
32 /* This file provides some definitions shared by cp-demangle.c and
33    cp-demint.c.  It should not be included by any other files.  */
34
35 /* Information we keep for operators.  */
36
37 struct demangle_operator_info
38 {
39   /* Mangled name.  */
40   const char *code;
41   /* Real name.  */
42   const char *name;
43   /* Length of real name.  */
44   int len;
45   /* Number of arguments.  */
46   int args;
47 };
48
49 /* How to print the value of a builtin type.  */
50
51 enum d_builtin_type_print
52 {
53   /* Print as (type)val.  */
54   D_PRINT_DEFAULT,
55   /* Print as integer.  */
56   D_PRINT_INT,
57   /* Print as unsigned integer, with trailing "u".  */
58   D_PRINT_UNSIGNED,
59   /* Print as long, with trailing "l".  */
60   D_PRINT_LONG,
61   /* Print as unsigned long, with trailing "ul".  */
62   D_PRINT_UNSIGNED_LONG,
63   /* Print as long long, with trailing "ll".  */
64   D_PRINT_LONG_LONG,
65   /* Print as unsigned long long, with trailing "ull".  */
66   D_PRINT_UNSIGNED_LONG_LONG,
67   /* Print as bool.  */
68   D_PRINT_BOOL,
69   /* Print as float--put value in square brackets.  */
70   D_PRINT_FLOAT,
71   /* Print in usual way, but here to detect void.  */
72   D_PRINT_VOID
73 };
74
75 /* Information we keep for a builtin type.  */
76
77 struct demangle_builtin_type_info
78 {
79   /* Type name.  */
80   const char *name;
81   /* Length of type name.  */
82   int len;
83   /* Type name when using Java.  */
84   const char *java_name;
85   /* Length of java name.  */
86   int java_len;
87   /* How to print a value of this type.  */
88   enum d_builtin_type_print print;
89 };
90
91 /* The information structure we pass around.  */
92
93 struct d_info
94 {
95   /* The string we are demangling.  */
96   const char *s;
97   /* The end of the string we are demangling.  */
98   const char *send;
99   /* The options passed to the demangler.  */
100   int options;
101   /* The next character in the string to consider.  */
102   const char *n;
103   /* The array of components.  */
104   struct demangle_component *comps;
105   /* The index of the next available component.  */
106   int next_comp;
107   /* The number of available component structures.  */
108   int num_comps;
109   /* The array of substitutions.  */
110   struct demangle_component **subs;
111   /* The index of the next substitution.  */
112   int next_sub;
113   /* The number of available entries in the subs array.  */
114   int num_subs;
115   /* The number of substitutions which we actually made from the subs
116      array, plus the number of template parameter references we
117      saw.  */
118   int did_subs;
119   /* The last name we saw, for constructors and destructors.  */
120   struct demangle_component *last_name;
121   /* A running total of the length of large expansions from the
122      mangled name to the demangled name, such as standard
123      substitutions and builtin types.  */
124   int expansion;
125   /* Non-zero if we are parsing an expression.  */
126   int is_expression;
127   /* Non-zero if we are parsing the type operand of a conversion
128      operator, but not when in an expression.  */
129   int is_conversion;
130 };
131
132 /* To avoid running past the ending '\0', don't:
133    - call d_peek_next_char if d_peek_char returned '\0'
134    - call d_advance with an 'i' that is too large
135    - call d_check_char(di, '\0')
136    Everything else is safe.  */
137 #define d_peek_char(di) (*((di)->n))
138 #ifndef CHECK_DEMANGLER
139 #  define d_peek_next_char(di) ((di)->n[1])
140 #  define d_advance(di, i) ((di)->n += (i))
141 #endif
142 #define d_check_char(di, c) (d_peek_char(di) == c ? ((di)->n++, 1) : 0)
143 #define d_next_char(di) (d_peek_char(di) == '\0' ? '\0' : *((di)->n++))
144 #define d_str(di) ((di)->n)
145
146 #ifdef CHECK_DEMANGLER
147 static inline char
148 d_peek_next_char (const struct d_info *di)
149 {
150   if (!di->n[0])
151     abort ();
152   return di->n[1];
153 }
154
155 static inline void
156 d_advance (struct d_info *di, int i)
157 {
158   if (i < 0)
159     abort ();
160   while (i--)
161     {
162       if (!di->n[0])
163         abort ();
164       di->n++;
165     }
166 }
167 #endif
168
169 /* Functions and arrays in cp-demangle.c which are referenced by
170    functions in cp-demint.c.  */
171 #ifdef IN_GLIBCPP_V3
172 #define CP_STATIC_IF_GLIBCPP_V3 static
173 #else
174 #define CP_STATIC_IF_GLIBCPP_V3 extern
175 #endif
176
177 #ifndef IN_GLIBCPP_V3
178 extern const struct demangle_operator_info cplus_demangle_operators[];
179 #endif
180
181 #define D_BUILTIN_TYPE_COUNT (33)
182
183 CP_STATIC_IF_GLIBCPP_V3
184 const struct demangle_builtin_type_info
185 cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
186
187 CP_STATIC_IF_GLIBCPP_V3
188 struct demangle_component *
189 cplus_demangle_mangled_name (struct d_info *, int);
190
191 CP_STATIC_IF_GLIBCPP_V3
192 struct demangle_component *
193 cplus_demangle_type (struct d_info *);
194
195 extern void
196 cplus_demangle_init_info (const char *, int, size_t, struct d_info *);
197
198 /* cp-demangle.c needs to define this a little differently */
199 #undef CP_STATIC_IF_GLIBCPP_V3