xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/compile/compile-cplus.h (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
17f2ac410Schristos /* Header file for GDB compile C++ language support.
2*6881a400Schristos    Copyright (C) 2016-2023 Free Software Foundation, Inc.
37f2ac410Schristos 
47f2ac410Schristos    This program is free software; you can redistribute it and/or modify
57f2ac410Schristos    it under the terms of the GNU General Public License as published by
67f2ac410Schristos    the Free Software Foundation; either version 3 of the License, or
77f2ac410Schristos    (at your option) any later version.
87f2ac410Schristos 
97f2ac410Schristos    This program is distributed in the hope that it will be useful,
107f2ac410Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
117f2ac410Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
127f2ac410Schristos    GNU General Public License for more details.
137f2ac410Schristos 
147f2ac410Schristos    You should have received a copy of the GNU General Public License
157f2ac410Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
167f2ac410Schristos 
177f2ac410Schristos #ifndef COMPILE_COMPILE_CPLUS_H
187f2ac410Schristos #define COMPILE_COMPILE_CPLUS_H
197f2ac410Schristos 
207d62b00eSchristos #include "gdbsupport/enum-flags.h"
217f2ac410Schristos #include "gcc-cp-plugin.h"
227d62b00eSchristos #include "symtab.h"
237f2ac410Schristos 
247f2ac410Schristos struct type;
257f2ac410Schristos struct block;
267f2ac410Schristos 
277f2ac410Schristos /* enum-flags wrapper  */
287f2ac410Schristos DEF_ENUM_FLAGS_TYPE (enum gcc_cp_qualifiers, gcc_cp_qualifiers_flags);
297f2ac410Schristos DEF_ENUM_FLAGS_TYPE (enum gcc_cp_ref_qualifiers, gcc_cp_ref_qualifiers_flags);
307f2ac410Schristos DEF_ENUM_FLAGS_TYPE (enum gcc_cp_symbol_kind, gcc_cp_symbol_kind_flags);
317f2ac410Schristos 
327f2ac410Schristos class compile_cplus_instance;
337f2ac410Schristos 
347f2ac410Schristos /* A single component of a type's scope.  Type names are broken into
357f2ac410Schristos    "components," a series of unqualified names comprising the type name,
367f2ac410Schristos    e.g., "namespace1", "namespace2", "myclass".  */
377f2ac410Schristos 
387f2ac410Schristos struct scope_component
397f2ac410Schristos {
407f2ac410Schristos   /* The unqualified name of this scope.  */
417f2ac410Schristos   std::string name;
427f2ac410Schristos 
437f2ac410Schristos   /* The block symbol for this type/scope.  */
447f2ac410Schristos   struct block_symbol bsymbol;
457f2ac410Schristos };
467f2ac410Schristos 
477f2ac410Schristos /* Comparison operators for scope_components.  */
487f2ac410Schristos 
497f2ac410Schristos bool operator== (const scope_component &lhs, const scope_component &rhs);
507f2ac410Schristos bool operator!= (const scope_component &lhs, const scope_component &rhs);
517f2ac410Schristos 
527f2ac410Schristos 
537f2ac410Schristos /* A single compiler scope used to define a type.
547f2ac410Schristos 
557f2ac410Schristos    A compile_scope is a list of scope_components, where all leading
567f2ac410Schristos    scope_components are namespaces, followed by a single non-namespace
577f2ac410Schristos    type component (the actual type we are converting).  */
587f2ac410Schristos 
597f2ac410Schristos class compile_scope : private std::vector<scope_component>
607f2ac410Schristos {
617f2ac410Schristos public:
627f2ac410Schristos 
637f2ac410Schristos   using std::vector<scope_component>::push_back;
647f2ac410Schristos   using std::vector<scope_component>::pop_back;
657f2ac410Schristos   using std::vector<scope_component>::back;
667f2ac410Schristos   using std::vector<scope_component>::empty;
677f2ac410Schristos   using std::vector<scope_component>::size;
687f2ac410Schristos   using std::vector<scope_component>::begin;
697f2ac410Schristos   using std::vector<scope_component>::end;
707f2ac410Schristos   using std::vector<scope_component>::operator[];
717f2ac410Schristos 
727f2ac410Schristos   compile_scope ()
737f2ac410Schristos     : m_nested_type (GCC_TYPE_NONE), m_pushed (false)
747f2ac410Schristos   {
757f2ac410Schristos   }
767f2ac410Schristos 
777f2ac410Schristos   /* Return the gcc_type of the type if it is a nested definition.
787f2ac410Schristos      Returns GCC_TYPE_NONE if this type was not nested.  */
797f2ac410Schristos   gcc_type nested_type ()
807f2ac410Schristos   {
817f2ac410Schristos     return m_nested_type;
827f2ac410Schristos   }
837f2ac410Schristos 
847f2ac410Schristos private:
857f2ac410Schristos 
867f2ac410Schristos   /* compile_cplus_instance is a friend class so that it can set the
877f2ac410Schristos      following private members when compile_scopes are created.  */
887f2ac410Schristos   friend compile_cplus_instance;
897f2ac410Schristos 
907f2ac410Schristos   /* If the type was actually a nested type, this will hold that nested
917f2ac410Schristos      type after the scope is pushed.  */
927f2ac410Schristos   gcc_type m_nested_type;
937f2ac410Schristos 
947f2ac410Schristos   /* If true, this scope was pushed to the compiler and all namespaces
957f2ac410Schristos      must be popped when leaving the scope.  */
967f2ac410Schristos   bool m_pushed;
977f2ac410Schristos };
987f2ac410Schristos 
997f2ac410Schristos /* Comparison operators for compile_scopes.  */
1007f2ac410Schristos 
1017f2ac410Schristos bool operator== (const compile_scope &lhs, const compile_scope &rhs);
1027f2ac410Schristos bool operator!= (const compile_scope &lhs, const compile_scope &rhs);
1037f2ac410Schristos 
1047f2ac410Schristos /* Convert TYPENAME into a vector of namespace and top-most/super
1057f2ac410Schristos    composite scopes.
1067f2ac410Schristos 
1077f2ac410Schristos    For example, for the input "Namespace::classB::classInner", the
1087f2ac410Schristos    resultant vector will contain the tokens "Namespace" and
1097f2ac410Schristos    "classB".  */
1107f2ac410Schristos 
1117f2ac410Schristos compile_scope type_name_to_scope (const char *type_name,
1127f2ac410Schristos 				  const struct block *block);
1137f2ac410Schristos 
1147f2ac410Schristos /* A callback suitable for use as the GCC C++ symbol oracle.  */
1157f2ac410Schristos 
1167f2ac410Schristos extern gcc_cp_oracle_function gcc_cplus_convert_symbol;
1177f2ac410Schristos 
1187f2ac410Schristos /* A callback suitable for use as the GCC C++ address oracle.  */
1197f2ac410Schristos 
1207f2ac410Schristos extern gcc_cp_symbol_address_function gcc_cplus_symbol_address;
1217f2ac410Schristos 
1227f2ac410Schristos /* A subclass of compile_instance that is specific to the C++ front
1237f2ac410Schristos    end.  */
1247f2ac410Schristos 
1257f2ac410Schristos class compile_cplus_instance : public compile_instance
1267f2ac410Schristos {
1277f2ac410Schristos public:
1287f2ac410Schristos 
1297f2ac410Schristos   explicit compile_cplus_instance (struct gcc_cp_context *gcc_cp)
1307f2ac410Schristos     : compile_instance (&gcc_cp->base, m_default_cflags),
1317f2ac410Schristos       m_plugin (gcc_cp)
1327f2ac410Schristos   {
1337f2ac410Schristos     m_plugin.set_callbacks (gcc_cplus_convert_symbol,
1347f2ac410Schristos 			    gcc_cplus_symbol_address,
1357f2ac410Schristos 			    gcc_cplus_enter_scope, gcc_cplus_leave_scope,
1367f2ac410Schristos 			    this);
1377f2ac410Schristos   }
1387f2ac410Schristos 
1397f2ac410Schristos   /* Convert a gdb type, TYPE, to a GCC type.
1407f2ac410Schristos 
1417f2ac410Schristos      If this type was defined in another type, NESTED_ACCESS should indicate
1427f2ac410Schristos      the accessibility of this type (or GCC_CP_ACCESS_NONE if not a nested
1437f2ac410Schristos      type).  GCC_CP_ACCESS_NONE is the default nested access.
1447f2ac410Schristos 
1457f2ac410Schristos      The new GCC type is returned.  */
1467f2ac410Schristos   gcc_type convert_type
1477f2ac410Schristos     (struct type *type,
1487f2ac410Schristos      enum gcc_cp_symbol_kind nested_access = GCC_CP_ACCESS_NONE);
1497f2ac410Schristos 
1507f2ac410Schristos   /* Return a handle for the GCC plug-in.  */
1517f2ac410Schristos   gcc_cp_plugin &plugin () { return m_plugin; }
1527f2ac410Schristos 
1537f2ac410Schristos   /* Factory method to create a new scope based on TYPE with name TYPE_NAME.
1547f2ac410Schristos      [TYPE_NAME could be TYPE_NAME or SYMBOL_NATURAL_NAME.]
1557f2ac410Schristos 
1567f2ac410Schristos      If TYPE is a nested or local definition, nested_type () will return
1577f2ac410Schristos      the gcc_type of the conversion.
1587f2ac410Schristos 
1597f2ac410Schristos      Otherwise, nested_type () is GCC_TYPE_NONE.  */
1607f2ac410Schristos   compile_scope new_scope (const char *type_name, struct type *type);
1617f2ac410Schristos 
1627f2ac410Schristos   /* Enter the given NEW_SCOPE.  */
1637f2ac410Schristos   void enter_scope (compile_scope &&scope);
1647f2ac410Schristos 
1657f2ac410Schristos   /* Leave the current scope.  */
1667f2ac410Schristos   void leave_scope ();
1677f2ac410Schristos 
1687f2ac410Schristos   /* Add the qualifiers given by QUALS to BASE.  */
1697f2ac410Schristos   gcc_type convert_qualified_base (gcc_type base,
1707f2ac410Schristos 				   gcc_cp_qualifiers_flags quals);
1717f2ac410Schristos 
1727f2ac410Schristos   /* Convert TARGET into a pointer type.  */
1737f2ac410Schristos   gcc_type convert_pointer_base (gcc_type target);
1747f2ac410Schristos 
1757f2ac410Schristos   /* Convert BASE into a reference type.  RQUALS describes the reference.  */
1767f2ac410Schristos   gcc_type convert_reference_base (gcc_type base,
1777f2ac410Schristos 				   enum gcc_cp_ref_qualifiers rquals);
1787f2ac410Schristos 
1797f2ac410Schristos   /* Return the declaration name of the symbol named NATURAL.
1807f2ac410Schristos      This returns a name with no function arguments or template parameters,
1817f2ac410Schristos      suitable for passing to the compiler plug-in.  */
1827f2ac410Schristos   static gdb::unique_xmalloc_ptr<char> decl_name (const char *natural);
1837f2ac410Schristos 
1847f2ac410Schristos private:
1857f2ac410Schristos 
1867f2ac410Schristos   /* Callbacks suitable for use as the GCC C++ enter/leave scope requests.  */
1877f2ac410Schristos   static gcc_cp_enter_leave_user_expr_scope_function gcc_cplus_enter_scope;
1887f2ac410Schristos   static gcc_cp_enter_leave_user_expr_scope_function gcc_cplus_leave_scope;
1897f2ac410Schristos 
1907f2ac410Schristos   /* Default compiler flags for C++.  */
1917f2ac410Schristos   static const char *m_default_cflags;
1927f2ac410Schristos 
1937f2ac410Schristos   /* The GCC plug-in.  */
1947f2ac410Schristos   gcc_cp_plugin m_plugin;
1957f2ac410Schristos 
1967f2ac410Schristos   /* A list of scopes we are processing.  */
1977f2ac410Schristos   std::vector<compile_scope> m_scopes;
1987f2ac410Schristos };
1997f2ac410Schristos 
2007f2ac410Schristos /* Get the access flag for the NUM'th method of TYPE's FNI'th
2017f2ac410Schristos    fieldlist.  */
2027f2ac410Schristos 
2037f2ac410Schristos enum gcc_cp_symbol_kind get_method_access_flag (const struct type *type,
2047f2ac410Schristos 						int fni, int num);
2057f2ac410Schristos 
2067f2ac410Schristos #endif /* COMPILE_COMPILE_CPLUS_H */
207