gdb/
[platform/upstream/binutils.git] / gdb / cp-support.h
1 /* Helper routines for C++ support in GDB.
2    Copyright (C) 2002-2005, 2007-2012 Free Software Foundation, Inc.
3
4    Contributed by MontaVista Software.
5    Namespace support contributed by David Carlton.
6
7    This file is part of GDB.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
22 #ifndef CP_SUPPORT_H
23 #define CP_SUPPORT_H
24
25 /* We need this for 'domain_enum', alas...  */
26
27 #include "symtab.h"
28 #include "vec.h"
29 #include "gdb_vecs.h"
30 #include "gdb_obstack.h"
31
32 /* Opaque declarations.  */
33
34 struct symbol;
35 struct block;
36 struct objfile;
37 struct type;
38 struct demangle_component;
39
40 /* A string representing the name of the anonymous namespace used in GDB.  */
41
42 #define CP_ANONYMOUS_NAMESPACE_STR "(anonymous namespace)"
43
44 /* The length of the string representing the anonymous namespace.  */
45
46 #define CP_ANONYMOUS_NAMESPACE_LEN 21
47
48 /* The result of parsing a name.  */
49
50 struct demangle_parse_info
51 {
52   /* The memory used during the parse.  */
53   struct demangle_info *info;
54
55   /* The result of the parse.  */
56   struct demangle_component *tree;
57
58   /* Any temporary memory used during typedef replacement.  */
59   struct obstack obstack;
60 };
61
62 /* This struct is designed to store data from using directives.  It
63    says that names from namespace IMPORT_SRC should be visible within
64    namespace IMPORT_DEST.  These form a linked list; NEXT is the next
65    element of the list.  If the imported namespace or declaration has
66    been aliased within the IMPORT_DEST namespace, ALIAS is set to a
67    string representing the alias.  Otherwise, ALIAS is NULL.
68    DECLARATION is the name of the imported declaration, if this import
69    statement represents one.  Otherwise DECLARATION is NULL and this
70    import statement represents a namespace.
71
72    C++:      using namespace A;
73    Fortran:  use A
74    import_src = "A"
75    import_dest = local scope of the import statement even such as ""
76    alias = NULL
77    declaration = NULL
78    excludes = NULL
79
80    C++:      using A::x;
81    Fortran:  use A, only: x
82    import_src = "A"
83    import_dest = local scope of the import statement even such as ""
84    alias = NULL
85    declaration = "x"
86    excludes = NULL
87    The declaration will get imported as import_dest::x.
88
89    C++ has no way to import all names except those listed ones.
90    Fortran:  use A, localname => x
91    import_src = "A"
92    import_dest = local scope of the import statement even such as ""
93    alias = "localname"
94    declaration = "x"
95    excludes = NULL
96    +
97    import_src = "A"
98    import_dest = local scope of the import statement even such as ""
99    alias = NULL
100    declaration = NULL
101    excludes = ["x"]
102    All the entries of A get imported except of "x".  "x" gets imported as
103    "localname".  "x" is not defined as a local name by this statement.
104
105    C++:      namespace LOCALNS = A;
106    Fortran has no way to address non-local namespace/module.
107    import_src = "A"
108    import_dest = local scope of the import statement even such as ""
109    alias = "LOCALNS"
110    declaration = NULL
111    excludes = NULL
112    The namespace will get imported as the import_dest::LOCALNS
113    namespace.
114
115    C++ cannot express it, it would be something like: using localname
116    = A::x;
117    Fortran:  use A, only localname => x
118    import_src = "A"
119    import_dest = local scope of the import statement even such as ""
120    alias = "localname"
121    declaration = "x"
122    excludes = NULL
123    The declaration will get imported as localname or
124    `import_dest`localname.  */
125
126 struct using_direct
127 {
128   char *import_src;
129   char *import_dest;
130
131   char *alias;
132   char *declaration;
133
134   struct using_direct *next;
135
136   /* Used during import search to temporarily mark this node as
137      searched.  */
138   int searched;
139
140   /* USING_DIRECT has variable allocation size according to the number of
141      EXCLUDES entries, the last entry is NULL.  */
142   const char *excludes[1];
143 };
144
145
146 /* Functions from cp-support.c.  */
147
148 extern char *cp_canonicalize_string (const char *string);
149
150 extern char *cp_canonicalize_string_no_typedefs (const char *string);
151
152 extern char *cp_class_name_from_physname (const char *physname);
153
154 extern char *method_name_from_physname (const char *physname);
155
156 extern unsigned int cp_find_first_component (const char *name);
157
158 extern unsigned int cp_entire_prefix_len (const char *name);
159
160 extern char *cp_func_name (const char *full_name);
161
162 extern char *cp_remove_params (const char *demangled_name);
163
164 extern struct symbol **make_symbol_overload_list (const char *,
165                                                   const char *);
166
167 extern struct symbol **make_symbol_overload_list_adl (struct type **arg_types,
168                                                       int nargs,
169                                                       const char *func_name);
170
171 extern struct type *cp_lookup_rtti_type (const char *name,
172                                          struct block *block);
173
174 /* Functions/variables from cp-namespace.c.  */
175
176 extern int cp_is_anonymous (const char *namespace);
177
178 extern void cp_add_using_directive (const char *dest,
179                                     const char *src,
180                                     const char *alias,
181                                     const char *declaration,
182                                     VEC (const_char_ptr) *excludes,
183                                     struct obstack *obstack);
184
185 extern void cp_set_block_scope (const struct symbol *symbol,
186                                 struct block *block,
187                                 struct obstack *obstack,
188                                 const char *processing_current_prefix,
189                                 int processing_has_namespace_info);
190
191 extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol,
192                                               struct objfile *objfile);
193
194 extern struct symbol *cp_lookup_symbol_nonlocal (const char *name,
195                                                  const struct block *block,
196                                                  const domain_enum domain);
197
198 extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
199                                                   const char *name,
200                                                   const struct block *block,
201                                                   const domain_enum domain);
202
203 extern struct symbol *cp_lookup_symbol_imports (const char *scope,
204                                                 const char *name,
205                                                 const struct block *block,
206                                                 const domain_enum domain,
207                                                 const int declaration_only,
208                                                 const int search_parents);
209
210 extern struct symbol *cp_lookup_symbol_imports_or_template
211      (const char *scope,
212       const char *name,
213       const struct block *block,
214       const domain_enum domain);
215
216 extern struct symbol *cp_lookup_nested_symbol (struct type *parent_type,
217                                                const char *nested_name,
218                                                const struct block *block);
219
220 struct type *cp_lookup_transparent_type (const char *name);
221
222 /* Functions from cp-name-parser.y.  */
223
224 extern struct demangle_parse_info *cp_demangled_name_to_comp
225      (const char *demangled_name, const char **errmsg);
226
227 extern char *cp_comp_to_string (struct demangle_component *result,
228                                 int estimated_len);
229
230 extern void cp_demangled_name_parse_free (struct demangle_parse_info *);
231 extern struct cleanup *make_cleanup_cp_demangled_name_parse_free
232      (struct demangle_parse_info *);
233 extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *,
234                                            struct demangle_component *,
235                                            struct demangle_parse_info *);
236
237 extern struct demangle_parse_info *cp_new_demangle_parse_info (void);
238
239 /* The list of "maint cplus" commands.  */
240
241 extern struct cmd_list_element *maint_cplus_cmd_list;
242
243 #endif /* CP_SUPPORT_H */