15796c8dcSSimon Schubert /* Helper routines for C++ support in GDB. 2*ef5ccd6cSJohn Marino Copyright (C) 2002-2013 Free Software Foundation, Inc. 35796c8dcSSimon Schubert 45796c8dcSSimon Schubert Contributed by MontaVista Software. 55796c8dcSSimon Schubert Namespace support contributed by David Carlton. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This file is part of GDB. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert (at your option) any later version. 135796c8dcSSimon Schubert 145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert GNU General Public License for more details. 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert #ifndef CP_SUPPORT_H 235796c8dcSSimon Schubert #define CP_SUPPORT_H 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert /* We need this for 'domain_enum', alas... */ 265796c8dcSSimon Schubert 275796c8dcSSimon Schubert #include "symtab.h" 28a45ae5f8SJohn Marino #include "vec.h" 29*ef5ccd6cSJohn Marino #include "gdb_vecs.h" 30a45ae5f8SJohn Marino #include "gdb_obstack.h" 315796c8dcSSimon Schubert 325796c8dcSSimon Schubert /* Opaque declarations. */ 335796c8dcSSimon Schubert 345796c8dcSSimon Schubert struct symbol; 355796c8dcSSimon Schubert struct block; 365796c8dcSSimon Schubert struct objfile; 375796c8dcSSimon Schubert struct type; 385796c8dcSSimon Schubert struct demangle_component; 395796c8dcSSimon Schubert 40c50c785cSJohn Marino /* A string representing the name of the anonymous namespace used in GDB. */ 41c50c785cSJohn Marino 42c50c785cSJohn Marino #define CP_ANONYMOUS_NAMESPACE_STR "(anonymous namespace)" 43c50c785cSJohn Marino 44c50c785cSJohn Marino /* The length of the string representing the anonymous namespace. */ 45c50c785cSJohn Marino 46c50c785cSJohn Marino #define CP_ANONYMOUS_NAMESPACE_LEN 21 47c50c785cSJohn Marino 48a45ae5f8SJohn Marino /* The result of parsing a name. */ 49a45ae5f8SJohn Marino 50a45ae5f8SJohn Marino struct demangle_parse_info 51a45ae5f8SJohn Marino { 52a45ae5f8SJohn Marino /* The memory used during the parse. */ 53a45ae5f8SJohn Marino struct demangle_info *info; 54a45ae5f8SJohn Marino 55a45ae5f8SJohn Marino /* The result of the parse. */ 56a45ae5f8SJohn Marino struct demangle_component *tree; 57a45ae5f8SJohn Marino 58a45ae5f8SJohn Marino /* Any temporary memory used during typedef replacement. */ 59a45ae5f8SJohn Marino struct obstack obstack; 60a45ae5f8SJohn Marino }; 61a45ae5f8SJohn Marino 625796c8dcSSimon Schubert /* This struct is designed to store data from using directives. It 63c50c785cSJohn Marino says that names from namespace IMPORT_SRC should be visible within 64c50c785cSJohn Marino namespace IMPORT_DEST. These form a linked list; NEXT is the next 65c50c785cSJohn Marino element of the list. If the imported namespace or declaration has 66c50c785cSJohn Marino been aliased within the IMPORT_DEST namespace, ALIAS is set to a 67c50c785cSJohn Marino string representing the alias. Otherwise, ALIAS is NULL. 68c50c785cSJohn Marino DECLARATION is the name of the imported declaration, if this import 69c50c785cSJohn Marino statement represents one. Otherwise DECLARATION is NULL and this 70c50c785cSJohn Marino import statement represents a namespace. 71cf7f2e2dSJohn Marino 72cf7f2e2dSJohn Marino C++: using namespace A; 73cf7f2e2dSJohn Marino Fortran: use A 74cf7f2e2dSJohn Marino import_src = "A" 75cf7f2e2dSJohn Marino import_dest = local scope of the import statement even such as "" 76cf7f2e2dSJohn Marino alias = NULL 77cf7f2e2dSJohn Marino declaration = NULL 78a45ae5f8SJohn Marino excludes = NULL 79cf7f2e2dSJohn Marino 80cf7f2e2dSJohn Marino C++: using A::x; 81cf7f2e2dSJohn Marino Fortran: use A, only: x 82cf7f2e2dSJohn Marino import_src = "A" 83cf7f2e2dSJohn Marino import_dest = local scope of the import statement even such as "" 84cf7f2e2dSJohn Marino alias = NULL 85cf7f2e2dSJohn Marino declaration = "x" 86a45ae5f8SJohn Marino excludes = NULL 87cf7f2e2dSJohn Marino The declaration will get imported as import_dest::x. 88cf7f2e2dSJohn Marino 89a45ae5f8SJohn Marino C++ has no way to import all names except those listed ones. 90a45ae5f8SJohn Marino Fortran: use A, localname => x 91a45ae5f8SJohn Marino import_src = "A" 92a45ae5f8SJohn Marino import_dest = local scope of the import statement even such as "" 93a45ae5f8SJohn Marino alias = "localname" 94a45ae5f8SJohn Marino declaration = "x" 95a45ae5f8SJohn Marino excludes = NULL 96a45ae5f8SJohn Marino + 97a45ae5f8SJohn Marino import_src = "A" 98a45ae5f8SJohn Marino import_dest = local scope of the import statement even such as "" 99a45ae5f8SJohn Marino alias = NULL 100a45ae5f8SJohn Marino declaration = NULL 101a45ae5f8SJohn Marino excludes = ["x"] 102a45ae5f8SJohn Marino All the entries of A get imported except of "x". "x" gets imported as 103a45ae5f8SJohn Marino "localname". "x" is not defined as a local name by this statement. 104a45ae5f8SJohn Marino 105cf7f2e2dSJohn Marino C++: namespace LOCALNS = A; 106cf7f2e2dSJohn Marino Fortran has no way to address non-local namespace/module. 107cf7f2e2dSJohn Marino import_src = "A" 108cf7f2e2dSJohn Marino import_dest = local scope of the import statement even such as "" 109cf7f2e2dSJohn Marino alias = "LOCALNS" 110cf7f2e2dSJohn Marino declaration = NULL 111a45ae5f8SJohn Marino excludes = NULL 112c50c785cSJohn Marino The namespace will get imported as the import_dest::LOCALNS 113c50c785cSJohn Marino namespace. 114cf7f2e2dSJohn Marino 115c50c785cSJohn Marino C++ cannot express it, it would be something like: using localname 116c50c785cSJohn Marino = A::x; 117cf7f2e2dSJohn Marino Fortran: use A, only localname => x 118cf7f2e2dSJohn Marino import_src = "A" 119cf7f2e2dSJohn Marino import_dest = local scope of the import statement even such as "" 120cf7f2e2dSJohn Marino alias = "localname" 121cf7f2e2dSJohn Marino declaration = "x" 122a45ae5f8SJohn Marino excludes = NULL 123c50c785cSJohn Marino The declaration will get imported as localname or 124c50c785cSJohn Marino `import_dest`localname. */ 1255796c8dcSSimon Schubert 1265796c8dcSSimon Schubert struct using_direct 1275796c8dcSSimon Schubert { 128*ef5ccd6cSJohn Marino const char *import_src; 129*ef5ccd6cSJohn Marino const char *import_dest; 130cf7f2e2dSJohn Marino 131*ef5ccd6cSJohn Marino const char *alias; 132*ef5ccd6cSJohn Marino const char *declaration; 133cf7f2e2dSJohn Marino 1345796c8dcSSimon Schubert struct using_direct *next; 135cf7f2e2dSJohn Marino 136c50c785cSJohn Marino /* Used during import search to temporarily mark this node as 137c50c785cSJohn Marino searched. */ 138cf7f2e2dSJohn Marino int searched; 139a45ae5f8SJohn Marino 140a45ae5f8SJohn Marino /* USING_DIRECT has variable allocation size according to the number of 141a45ae5f8SJohn Marino EXCLUDES entries, the last entry is NULL. */ 142a45ae5f8SJohn Marino const char *excludes[1]; 1435796c8dcSSimon Schubert }; 1445796c8dcSSimon Schubert 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert /* Functions from cp-support.c. */ 1475796c8dcSSimon Schubert 1485796c8dcSSimon Schubert extern char *cp_canonicalize_string (const char *string); 1495796c8dcSSimon Schubert 150a45ae5f8SJohn Marino extern char *cp_canonicalize_string_no_typedefs (const char *string); 151a45ae5f8SJohn Marino 152*ef5ccd6cSJohn Marino typedef const char *(canonicalization_ftype) (struct type *, void *); 153*ef5ccd6cSJohn Marino 154*ef5ccd6cSJohn Marino extern char *cp_canonicalize_string_full (const char *string, 155*ef5ccd6cSJohn Marino canonicalization_ftype *finder, 156*ef5ccd6cSJohn Marino void *data); 157*ef5ccd6cSJohn Marino 1585796c8dcSSimon Schubert extern char *cp_class_name_from_physname (const char *physname); 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert extern char *method_name_from_physname (const char *physname); 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert extern unsigned int cp_find_first_component (const char *name); 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert extern unsigned int cp_entire_prefix_len (const char *name); 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert extern char *cp_func_name (const char *full_name); 1675796c8dcSSimon Schubert 1685796c8dcSSimon Schubert extern char *cp_remove_params (const char *demangled_name); 1695796c8dcSSimon Schubert 1705796c8dcSSimon Schubert extern struct symbol **make_symbol_overload_list (const char *, 1715796c8dcSSimon Schubert const char *); 1725796c8dcSSimon Schubert 173cf7f2e2dSJohn Marino extern struct symbol **make_symbol_overload_list_adl (struct type **arg_types, 174cf7f2e2dSJohn Marino int nargs, 175cf7f2e2dSJohn Marino const char *func_name); 176cf7f2e2dSJohn Marino 1775796c8dcSSimon Schubert extern struct type *cp_lookup_rtti_type (const char *name, 1785796c8dcSSimon Schubert struct block *block); 1795796c8dcSSimon Schubert 1805796c8dcSSimon Schubert /* Functions/variables from cp-namespace.c. */ 1815796c8dcSSimon Schubert 1825796c8dcSSimon Schubert extern int cp_is_anonymous (const char *namespace); 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert extern void cp_add_using_directive (const char *dest, 1855796c8dcSSimon Schubert const char *src, 186cf7f2e2dSJohn Marino const char *alias, 187cf7f2e2dSJohn Marino const char *declaration, 188a45ae5f8SJohn Marino VEC (const_char_ptr) *excludes, 189*ef5ccd6cSJohn Marino int copy_names, 190cf7f2e2dSJohn Marino struct obstack *obstack); 1915796c8dcSSimon Schubert 192a45ae5f8SJohn Marino extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol, 193a45ae5f8SJohn Marino struct objfile *objfile); 1945796c8dcSSimon Schubert 1955796c8dcSSimon Schubert extern struct symbol *cp_lookup_symbol_nonlocal (const char *name, 1965796c8dcSSimon Schubert const struct block *block, 1975796c8dcSSimon Schubert const domain_enum domain); 1985796c8dcSSimon Schubert 1995796c8dcSSimon Schubert extern struct symbol *cp_lookup_symbol_namespace (const char *namespace, 2005796c8dcSSimon Schubert const char *name, 2015796c8dcSSimon Schubert const struct block *block, 2025796c8dcSSimon Schubert const domain_enum domain); 2035796c8dcSSimon Schubert 204cf7f2e2dSJohn Marino extern struct symbol *cp_lookup_symbol_imports (const char *scope, 205cf7f2e2dSJohn Marino const char *name, 206cf7f2e2dSJohn Marino const struct block *block, 207cf7f2e2dSJohn Marino const domain_enum domain, 208cf7f2e2dSJohn Marino const int declaration_only, 209cf7f2e2dSJohn Marino const int search_parents); 210cf7f2e2dSJohn Marino 211c50c785cSJohn Marino extern struct symbol *cp_lookup_symbol_imports_or_template 212c50c785cSJohn Marino (const char *scope, 213c50c785cSJohn Marino const char *name, 214c50c785cSJohn Marino const struct block *block, 215c50c785cSJohn Marino const domain_enum domain); 216c50c785cSJohn Marino 217*ef5ccd6cSJohn Marino extern struct symbol *cp_lookup_nested_symbol (struct type *parent_type, 2185796c8dcSSimon Schubert const char *nested_name, 2195796c8dcSSimon Schubert const struct block *block); 2205796c8dcSSimon Schubert 2215796c8dcSSimon Schubert struct type *cp_lookup_transparent_type (const char *name); 2225796c8dcSSimon Schubert 2235796c8dcSSimon Schubert /* Functions from cp-name-parser.y. */ 2245796c8dcSSimon Schubert 225a45ae5f8SJohn Marino extern struct demangle_parse_info *cp_demangled_name_to_comp 2265796c8dcSSimon Schubert (const char *demangled_name, const char **errmsg); 2275796c8dcSSimon Schubert 2285796c8dcSSimon Schubert extern char *cp_comp_to_string (struct demangle_component *result, 2295796c8dcSSimon Schubert int estimated_len); 2305796c8dcSSimon Schubert 231a45ae5f8SJohn Marino extern void cp_demangled_name_parse_free (struct demangle_parse_info *); 232a45ae5f8SJohn Marino extern struct cleanup *make_cleanup_cp_demangled_name_parse_free 233a45ae5f8SJohn Marino (struct demangle_parse_info *); 234a45ae5f8SJohn Marino extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *, 235a45ae5f8SJohn Marino struct demangle_component *, 236a45ae5f8SJohn Marino struct demangle_parse_info *); 237a45ae5f8SJohn Marino 238a45ae5f8SJohn Marino extern struct demangle_parse_info *cp_new_demangle_parse_info (void); 239a45ae5f8SJohn Marino 2405796c8dcSSimon Schubert /* The list of "maint cplus" commands. */ 2415796c8dcSSimon Schubert 2425796c8dcSSimon Schubert extern struct cmd_list_element *maint_cplus_cmd_list; 2435796c8dcSSimon Schubert 2445796c8dcSSimon Schubert #endif /* CP_SUPPORT_H */ 245