107163879Schristos/* Interface between GCC C++ FE and GDB  -*- c -*-
207163879Schristos
3*1424dfb3Schristos   Copyright (C) 2014-2020 Free Software Foundation, Inc.
407163879Schristos
507163879Schristos   This file is part of GCC.
607163879Schristos
707163879Schristos   This program is free software; you can redistribute it and/or modify
807163879Schristos   it under the terms of the GNU General Public License as published by
907163879Schristos   the Free Software Foundation; either version 3 of the License, or
1007163879Schristos   (at your option) any later version.
1107163879Schristos
1207163879Schristos   This program is distributed in the hope that it will be useful,
1307163879Schristos   but WITHOUT ANY WARRANTY; without even the implied warranty of
1407163879Schristos   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1507163879Schristos   GNU General Public License for more details.
1607163879Schristos
1707163879Schristos   You should have received a copy of the GNU General Public License
1807163879Schristos   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1907163879Schristos
2007163879Schristos
2107163879Schristos
2207163879Schristos/* Push namespace NAME as the current binding level, to which
2307163879Schristos   newly-introduced decls will be bound.  An empty string identifies
2407163879Schristos   the global namespace, whereas NULL identifies an anonymous
2507163879Schristos   namespace.  A namespace named NAME is created in the current scope,
2607163879Schristos   if needed.
2707163879Schristos
2807163879Schristos   If the newly-created namespace is to be an inline namespace, see
2907163879Schristos   make_namespace_inline.  */
3007163879Schristos
3107163879SchristosGCC_METHOD1 (int /* bool */, push_namespace,
3207163879Schristos	     const char *)	      /* Argument NAME.  */
3307163879Schristos
3407163879Schristos/* Push TYPE as the current binding level, making its members visible
3507163879Schristos   for name lookup.  The current scope before the call must be the
3607163879Schristos   scope in which the class was declared.  This should be used if the
3707163879Schristos   definition of a class is already finished, but one wishes to define
3807163879Schristos   a nested class, or to enter the scope of one of its member
3907163879Schristos   functions.  */
4007163879Schristos
4107163879SchristosGCC_METHOD1 (int /* bool */, push_class,
4207163879Schristos	     gcc_type)		/* Argument TYPE.  */
4307163879Schristos
4407163879Schristos/* Push FUNCTION_DECL as the current (empty) binding level (see
4507163879Schristos   reactivate_decl).  The current enclosing scope before the call must
4607163879Schristos   be the scope in which the function was declared.  */
4707163879Schristos
4807163879SchristosGCC_METHOD1 (int /* bool */, push_function,
4907163879Schristos	     gcc_decl)	     /* Argument FUNCTION_DECL.  */
5007163879Schristos
5107163879Schristos/* Make DECL visible (again?) within SCOPE.  When SCOPE is NULL, it
5207163879Schristos   means the current scope; if it is not NULL, it must name a function
5307163879Schristos   that is currently active, even if not at the top of the binding
5407163879Schristos   chain.
5507163879Schristos
5607163879Schristos   This function can be used to make e.g. a global function or
5707163879Schristos   variable visible in a namespace or local scope (overriding another
5807163879Schristos   enclosing definition of the same name), but its most common
5907163879Schristos   expected use of this primitive, that gives it its name, is to make
6007163879Schristos   declarations visible again after reentering a function scope,
6107163879Schristos   because when a function is entered with push_function, that does
6207163879Schristos   NOT make any of the declarations nested in it visible for name
6307163879Schristos   lookup.
6407163879Schristos
6507163879Schristos   There is a reason/excuse for that: unlike namespaces and classes,
6607163879Schristos   G++ doesn't ever have to reenter function scopes, so its name
6707163879Schristos   resolution infrastructure is not prepared to do that.  But wait,
6807163879Schristos   there is also a good use for this apparent limitation: a function
6907163879Schristos   may contain multiple scopes (blocks), and the name may be bound to
7007163879Schristos   different symbols in each of these scopes.  With this interface, as
7107163879Schristos   we reenter a function scope, we may choose which symbols to make
7207163879Schristos   visible for the code snippet, or, if there could be template
7307163879Schristos   functions in local scopes, for unresolved names in nested template
7407163879Schristos   class default arguments, or in nested template function signatures.
7507163879Schristos
7607163879Schristos   As for making a local declaration visible for the code snippet,
7707163879Schristos   there are two possibilities: a) introduce it upfront, while
7807163879Schristos   entering the scope for the user expression (see the enter_scope
7907163879Schristos   callback, called by g++ when encountering the push_user_expression
8007163879Schristos   pragma), which might save some scope switching and reactivate_decl
8107163879Schristos   (though this can't be helped if some declarations have to be
8207163879Schristos   introduced and discarded, because of multiple definitions of the
8307163879Schristos   same name in different scopes within a function: they have to be
8407163879Schristos   defined in discriminator order); or b) introduce it when its name
8507163879Schristos   is looked up, entering the scope, introducing the declaration,
8607163879Schristos   leaving the scope, and then reactivating the declaration in its
8707163879Schristos   local scope.
8807163879Schristos
8907163879Schristos   Here's some more detail on how reactivate_decl works.  Say there's
9007163879Schristos   a function foo whose body looks like this:
9107163879Schristos
9207163879Schristos   {
9307163879Schristos     {
9407163879Schristos// point 1
9507163879Schristos       class c {} o __attribute__ ((__used__)); // c  , o
9607163879Schristos     }
9707163879Schristos     struct c {
9807163879Schristos       void f() {
9907163879Schristos// point 2
10007163879Schristos       }
10107163879Schristos     } o __attribute__ ((__used__));            // c_0, o_0
10207163879Schristos     {
10307163879Schristos       class c {} p __attribute__ ((__used__)); // c_1, p
10407163879Schristos// point 3
10507163879Schristos       o.f();
10607163879Schristos     }
10707163879Schristos   }
10807163879Schristos
10907163879Schristos   When we are about to define class c at point 1, we enter the
11007163879Schristos   function foo scope, and since no symbols are visible at point 1, we
11107163879Schristos   proceed to declare class c.  We may then define the class right
11207163879Schristos   away, or, if we leave the function scope, and we later wish to
11307163879Schristos   define it, or to define object o, we can reenter the scope and just
11407163879Schristos   use the previously-obtained gcc_decl to define the class, without
11507163879Schristos   having to reactivate the declaration.
11607163879Schristos
11707163879Schristos   Now, if we are to set up the binding context for point 2, we have
11807163879Schristos   to define c_0::f, and in order to do so, we have to declare and
11907163879Schristos   define c_0.  Before we can declare c_0, we MUST at least declare c.
12007163879Schristos
12107163879Schristos     As a general rule, before we can declare or define any local name
12207163879Schristos     with a discriminator, we have to at least declare any other
12307163879Schristos     occurrences of the same name in the same enclosing entity with
12407163879Schristos     lower or absent discriminator.
12507163879Schristos
12607163879Schristos   So, we declare c, then we leave the function scope and reenter it
12707163879Schristos   so as to declare c_0 (also with name "c", which is why we have to
12807163879Schristos   leave and reenter the function scope, otherwise we would get an
12907163879Schristos   error because of the duplicate definition; g++ will assign a
13007163879Schristos   discriminator because it still remembers there was an earlier
13107163879Schristos   declaration of c_0 within the function, it's just no longer in
13207163879Schristos   scope), then we can define c_0, including its member function f.
13307163879Schristos
13407163879Schristos   Likewise, if we wish to define o_0, we have to define o first.  If
13507163879Schristos   we wish to declare (and maybe then define) c_1, we have to at least
13607163879Schristos   declare (c and then) c_0 first.
13707163879Schristos
13807163879Schristos   Then, as we set up the binding context to compile a code snippet at
13907163879Schristos   point 3, we may choose to activate c_1, o_0 and p upfront,
14007163879Schristos   declaring and discarding c, c_0 and o, and then reentering the
14107163879Schristos   funciton scope to declare c_1, o_0 and p; or we can wait for oracle
14207163879Schristos   lookups of c, o or p.  If c is looked up, and the debugger resolves
14307163879Schristos   c in the scope to c_1, it is expected to enter the function scope
14407163879Schristos   from the top level, declare c, leave it, reenter it, declare c_0,
14507163879Schristos   leave it, reenter it, declare c_1, leave it, and then reactivate
14607163879Schristos   c_1 in the function scope.  If c_1 is needed as a complete type,
14707163879Schristos   the definition may be given right after the declaration, or the
14807163879Schristos   scope will have to be reentered in order to define the class.
14907163879Schristos
15007163879Schristos.  If the code snippet is at point 2, we don't need to (re)activate
15107163879Schristos   any declaration: nothing from any local scope is visible.  Just
15207163879Schristos   entering the scope of the class containing member function f
15307163879Schristos   reactivates the names of its members, including the class name
15407163879Schristos   itself.  */
15507163879Schristos
15607163879SchristosGCC_METHOD2 (int /* bool */, reactivate_decl,
15707163879Schristos	     gcc_decl,		/* Argument DECL.  */
15807163879Schristos	     gcc_decl)		/* Argument SCOPE.  */
15907163879Schristos
16007163879Schristos/* Pop the namespace last entered with push_namespace, or class last
16107163879Schristos   entered with push_class, or function last entered with
16207163879Schristos   push_function, restoring the binding level in effect before the
16307163879Schristos   matching push_* call.  */
16407163879Schristos
16507163879SchristosGCC_METHOD0 (int /* bool */, pop_binding_level)
16607163879Schristos
16707163879Schristos/* Return the NAMESPACE_DECL, TYPE_DECL or FUNCTION_DECL of the
16807163879Schristos   binding level that would be popped by pop_scope.  */
16907163879Schristos
17007163879SchristosGCC_METHOD0 (gcc_decl, get_current_binding_level_decl)
17107163879Schristos
17207163879Schristos/* Make the current binding level an inline namespace.  It must be a
17307163879Schristos   namespace to begin with.  It is safe to call this more than once
17407163879Schristos   for the same namespace, but after the first call, subsequent ones
17507163879Schristos   will not return a success status.  */
17607163879Schristos
17707163879SchristosGCC_METHOD0 (int /* bool */, make_namespace_inline)
17807163879Schristos
17907163879Schristos/* Add USED_NS to the namespaces used by the current binding level.
18007163879Schristos   Use get_current_binding_level_decl to obtain USED_NS's
18107163879Schristos   gcc_decl.  */
18207163879Schristos
18307163879SchristosGCC_METHOD1 (int /* bool */, add_using_namespace,
18407163879Schristos	     gcc_decl)			/* Argument USED_NS.  */
18507163879Schristos
18607163879Schristos/* Introduce a namespace alias declaration, as in:
18707163879Schristos
18807163879Schristos   namespace foo = [... ::] bar;
18907163879Schristos
19007163879Schristos   After this call, namespace TARGET will be visible as ALIAS within
19107163879Schristos   the current namespace.  Get the declaration for TARGET by calling
19207163879Schristos   get_current_binding_level_decl after pushing into it.  */
19307163879Schristos
19407163879SchristosGCC_METHOD2 (int /* bool */, add_namespace_alias,
19507163879Schristos	     const char *,		/* Argument ALIAS.  */
19607163879Schristos	     gcc_decl)			/* Argument TARGET.  */
19707163879Schristos
19807163879Schristos/* Introduce a using declaration, as in:
19907163879Schristos
20007163879Schristos   using foo::bar;
20107163879Schristos
20207163879Schristos   The TARGET decl names the qualifying scope (foo:: above) and the
20307163879Schristos   identifier (bar), but that does not mean that only TARGET will be
20407163879Schristos   brought into the current scope: all bindings of TARGET's identifier
20507163879Schristos   in the qualifying scope will be brought in.
20607163879Schristos
20707163879Schristos   FLAGS should specify GCC_CP_SYMBOL_USING.  If the current scope is
20807163879Schristos   a class scope, visibility flags must be supplied.
20907163879Schristos
21007163879Schristos   Even when TARGET is template dependent, we don't need to specify
21107163879Schristos   whether or not it is a typename: the supplied declaration (that
21207163879Schristos   could be a template-dependent type converted to declaration by
21307163879Schristos   get_type_decl) indicates so.  */
21407163879Schristos
21507163879SchristosGCC_METHOD2 (int /* bool */, add_using_decl,
21607163879Schristos	     enum gcc_cp_symbol_kind, /* Argument FLAGS.  */
21707163879Schristos	     gcc_decl)		      /* Argument TARGET.  */
21807163879Schristos
21907163879Schristos/* Create a new "decl" in GCC, and bind it in the current binding
22007163879Schristos   level.  A decl is a declaration, basically a kind of symbol.
22107163879Schristos
22207163879Schristos   NAME is the name of the new symbol.  SYM_KIND is the kind of
22307163879Schristos   symbol being requested.  SYM_TYPE is the new symbol's C++ type;
22407163879Schristos   except for labels, where this is not meaningful and should be
22507163879Schristos   zero.  If SUBSTITUTION_NAME is not NULL, then a reference to this
22607163879Schristos   decl in the source will later be substituted with a dereference
22707163879Schristos   of a variable of the given name.  Otherwise, for symbols having
22807163879Schristos   an address (e.g., functions), ADDRESS is the address.  FILENAME
22907163879Schristos   and LINE_NUMBER refer to the symbol's source location.  If this
23007163879Schristos   is not known, FILENAME can be NULL and LINE_NUMBER can be 0.
23107163879Schristos   This function returns the new decl.
23207163879Schristos
23307163879Schristos   Use this function to register typedefs, functions and variables to
23407163879Schristos   namespace and local binding levels, and typedefs, member functions
23507163879Schristos   (static or not), and static data members to class binding levels.
23607163879Schristos   Class members must have their access controls specified with
23707163879Schristos   GCC_CP_ACCESS_* flags in SYM_KIND.
23807163879Schristos
23907163879Schristos   Note that, since access controls are disabled, we have no means to
24007163879Schristos   express private, protected and public.
24107163879Schristos
24207163879Schristos   There are various flags that can be set in SYM_KIND to specify
24307163879Schristos   additional semantics.  Look for GCC_CP_FLAGs in the definition of
24407163879Schristos   enum gcc_cp_symbol_kind in gcc-cp-interface.h.
24507163879Schristos
24607163879Schristos   In order to define member functions, pass GCC_CP_SYMBOL_FUNCTION in
24707163879Schristos   SYM_KIND, and a function_type for static member functions or a
24807163879Schristos   method type for non-static member functions, including constructors
24907163879Schristos   and destructors.  Use build_function_type to create a function
25007163879Schristos   type; for a method type, start by creating a function type without
25107163879Schristos   any compiler-introduced artificial arguments (the implicit this
25207163879Schristos   pointer, and the __in_chrg added to constructors and destructors,
25307163879Schristos   and __vtt_parm added to the former), and then use build_method_type
25407163879Schristos   to create the method type out of the class type and the function
25507163879Schristos   type.
25607163879Schristos
25707163879Schristos   For operator functions, set GCC_CP_FLAG_SPECIAL_FUNCTION in
25807163879Schristos   SYM_KIND, in addition to any other applicable flags, and pass as
25907163879Schristos   NAME a string starting with the two-character mangling for operator
26007163879Schristos   name: "ps" for unary plus, "mL" for multiply and assign, *=; etc.
26107163879Schristos   Use "cv" for type converstion operators (the target type portion
26207163879Schristos   may be omitted, as it is taken from the return type in SYM_TYPE).
26307163879Schristos   For operator"", use "li" followed by the identifier (the mangled
26407163879Schristos   name mandates digits specifying the length of the identifier; if
26507163879Schristos   present, they determine the end of the identifier, otherwise, the
26607163879Schristos   identifier extents to the end of the string, so that "li3_Kme" and
26707163879Schristos   "li_Km" are equivalent).
26807163879Schristos
26907163879Schristos   Constructors and destructors need special care, because for each
27007163879Schristos   constructor and destructor there may be multiple clones defined
27107163879Schristos   internally by the compiler.  With build_decl, you can introduce the
27207163879Schristos   base declaration of a constructor or a destructor, setting
27307163879Schristos   GCC_CP_FLAG_SPECIAL_FUNCTION the flag and using names starting with
27407163879Schristos   capital "C" or "D", respectively, followed by a digit (see below),
27507163879Schristos   a blank, or NUL ('\0').  DO NOT supply an ADDRESS or a
27607163879Schristos   SUBSTITUTION_NAME to build_decl, it would be meaningless (and
27707163879Schristos   rejected) for the base declaration; use define_cdtor_clone to
27807163879Schristos   introduce the address of each clone.  For constructor templates,
27907163879Schristos   declare the template with build_decl, and then, for each
28007163879Schristos   specialization, introduce it with
28107163879Schristos   build_function_template_specialization, and then define the
28207163879Schristos   addresses of each of its clones with define_cdtor_clone.
28307163879Schristos
28407163879Schristos   NAMEs for GCC_CP_FLAG_SPECIAL_FUNCTION:
28507163879Schristos
28607163879Schristos     NAME    meaning
28707163879Schristos     C?      constructor base declaration (? may be 1, 2, 4, blank or NUL)
28807163879Schristos     D?      destructor base declaration (? may be 0, 1, 2, 4, blank or NUL)
28907163879Schristos     nw      operator new
29007163879Schristos     na      operator new[]
29107163879Schristos     dl      operator delete
29207163879Schristos     da      operator delete[]
29307163879Schristos     ps      operator + (unary)
29407163879Schristos     ng      operator - (unary)
29507163879Schristos     ad      operator & (unary)
29607163879Schristos     de      operator * (unary)
29707163879Schristos     co      operator ~
29807163879Schristos     pl      operator +
29907163879Schristos     mi      operator -
30007163879Schristos     ml      operator *
30107163879Schristos     dv      operator /
30207163879Schristos     rm      operator %
30307163879Schristos     an      operator &
30407163879Schristos     or      operator |
30507163879Schristos     eo      operator ^
30607163879Schristos     aS      operator =
30707163879Schristos     pL      operator +=
30807163879Schristos     mI      operator -=
30907163879Schristos     mL      operator *=
31007163879Schristos     dV      operator /=
31107163879Schristos     rM      operator %=
31207163879Schristos     aN      operator &=
31307163879Schristos     oR      operator |=
31407163879Schristos     eO      operator ^=
31507163879Schristos     ls      operator <<
31607163879Schristos     rs      operator >>
31707163879Schristos     lS      operator <<=
31807163879Schristos     rS      operator >>=
31907163879Schristos     eq      operator ==
32007163879Schristos     ne      operator !=
32107163879Schristos     lt      operator <
32207163879Schristos     gt      operator >
32307163879Schristos     le      operator <=
32407163879Schristos     ge      operator >=
32507163879Schristos     nt      operator !
32607163879Schristos     aa      operator &&
32707163879Schristos     oo      operator ||
32807163879Schristos     pp      operator ++
32907163879Schristos     mm      operator --
33007163879Schristos     cm      operator ,
33107163879Schristos     pm      operator ->*
33207163879Schristos     pt      operator ->
33307163879Schristos     cl      operator ()
33407163879Schristos     ix      operator []
33507163879Schristos     qu      operator ?
33607163879Schristos     cv      operator <T> (conversion operator)
33707163879Schristos     li<id>  operator "" <id>
33807163879Schristos
33907163879Schristos   FIXME: How about attributes?  */
34007163879Schristos
34107163879SchristosGCC_METHOD7 (gcc_decl, build_decl,
34207163879Schristos	     const char *,	      /* Argument NAME.  */
34307163879Schristos	     enum gcc_cp_symbol_kind, /* Argument SYM_KIND.  */
34407163879Schristos	     gcc_type,		      /* Argument SYM_TYPE.  */
34507163879Schristos	     const char *,	      /* Argument SUBSTITUTION_NAME.  */
34607163879Schristos	     gcc_address,	      /* Argument ADDRESS.  */
34707163879Schristos	     const char *,	      /* Argument FILENAME.  */
34807163879Schristos	     unsigned int)	      /* Argument LINE_NUMBER.  */
34907163879Schristos
35007163879Schristos/* Supply the ADDRESS of one of the multiple clones of constructor or
35107163879Schristos   destructor CDTOR.  The clone is specified by NAME, using the
35207163879Schristos   following name mangling conventions:
35307163879Schristos
35407163879Schristos     C1      in-charge constructor
35507163879Schristos     C2      not-in-charge constructor
35607163879Schristos     C4      unified constructor
35707163879Schristos     D0      deleting destructor
35807163879Schristos     D1      in-charge destructor
35907163879Schristos     D2      not-in-charge destructor
36007163879Schristos     D4      unified destructor
36107163879Schristos
36207163879Schristos   The following information is not necessary to use the API.
36307163879Schristos
36407163879Schristos   C1 initializes an instance of the class (rather than of derived
36507163879Schristos   classes), including virtual base classes, whereas C2 initializes a
36607163879Schristos   sub-object (of the given class type) of an instance of some derived
36707163879Schristos   class (or a full object that doesn't have any virtual base
36807163879Schristos   classes).
36907163879Schristos
37007163879Schristos   D0 and D1 destruct an instance of the class, including virtual base
37107163879Schristos   classes, but only the former calls operator delete to release the
37207163879Schristos   object's storage at the end; D2 destructs a sub-object (of the
37307163879Schristos   given class type) of an instance of a derived class (or a full
37407163879Schristos   object that doesn't have any virtual base classes).
37507163879Schristos
37607163879Schristos   The [CD]4 manglings (and symbol definitions) are non-standard, but
37707163879Schristos   GCC uses them in some cases: rather than assuming they are
37807163879Schristos   in-charge or not-in-charge, they test the implicit argument that
37907163879Schristos   the others ignore to tell how to behave.  These are used instead of
38007163879Schristos   cloning when we just can't use aliases.  */
38107163879Schristos
38207163879SchristosGCC_METHOD3 (gcc_decl, define_cdtor_clone,
38307163879Schristos	     const char *,	      /* Argument NAME.  */
38407163879Schristos	     gcc_decl,		      /* Argument CDTOR.  */
38507163879Schristos	     gcc_address)	      /* Argument ADDRESS.  */
38607163879Schristos
38707163879Schristos/* Return the type associated with the given declaration.  This is
38807163879Schristos   most useful to obtain the type associated with a forward-declared
38907163879Schristos   class, because it is the gcc_type, rather than the gcc_decl, that
39007163879Schristos   has to be used to build other types, but build_decl returns a
39107163879Schristos   gcc_decl rather than a gcc_type.  This call can in theory be used
39207163879Schristos   to obtain the type from any other declaration; it is supposed to
39307163879Schristos   return the same type that was supplied when the declaration was
39407163879Schristos   created.  */
39507163879Schristos
39607163879SchristosGCC_METHOD1 (gcc_type, get_decl_type,
39707163879Schristos	     gcc_decl)            /* Argument DECL.  */
39807163879Schristos
39907163879Schristos/* Return the declaration for a type.  */
40007163879Schristos
40107163879SchristosGCC_METHOD1 (gcc_decl, get_type_decl,
40207163879Schristos	     gcc_type)            /* Argument TYPE.  */
40307163879Schristos
40407163879Schristos/* Declare DECL as a friend of the current class scope, if TYPE is
40507163879Schristos   NULL, or of TYPE itself otherwise.  DECL may be a function or a
40607163879Schristos   class, be they template generics, template specializations or not
40707163879Schristos   templates.  TYPE must be a class type (not a template generic).
40807163879Schristos
40907163879Schristos   The add_friend call cannot introduce a declaration; even if the
41007163879Schristos   friend is first declared as a friend in the source code, the
41107163879Schristos   declaration belongs in the enclosing namespace, so it must be
41207163879Schristos   introduced in that namespace, and the resulting declaration can
41307163879Schristos   then be made a friend.
41407163879Schristos
41507163879Schristos   DECL cannot, however, be a member of a template class generic,
41607163879Schristos   because we have no means to introduce their declarations.  This
41707163879Schristos   interface has no notion of definitions for template generics.  As a
41807163879Schristos   consequence, users of this interface must introduce each friend
41907163879Schristos   template member specialization separately, i.e., instead of:
42007163879Schristos
42107163879Schristos     template <typename T> friend struct X<T>::M;
42207163879Schristos
42307163879Schristos   they must be declared as if they were:
42407163879Schristos
42507163879Schristos     friend struct X<onetype>::M;
42607163879Schristos     friend struct X<anothertype>::M;
42707163879Schristos     ... for each specialization of X.
42807163879Schristos
42907163879Schristos
43007163879Schristos   Specializations of a template can have each others' members as
43107163879Schristos   friends:
43207163879Schristos
43307163879Schristos     template <typename T> class foo {
43407163879Schristos       int f();
43507163879Schristos       template <typename U> friend int foo<U>::f();
43607163879Schristos     };
43707163879Schristos
43807163879Schristos   It wouldn't always be possible to define all specializations of a
43907163879Schristos   template class before introducing the friend declarations in their
44007163879Schristos   expanded, per-specialization form.
44107163879Schristos
44207163879Schristos   In order to simplify such friend declarations, and to enable
44307163879Schristos   incremental friend declarations as template specializations are
44407163879Schristos   introduced, add_friend can be called after the befriending class is
44507163879Schristos   fully defined, passing it a non-NULL TYPE argument naming the
44607163879Schristos   befriending class type.  */
44707163879Schristos
44807163879SchristosGCC_METHOD2 (int /* bool */, add_friend,
44907163879Schristos	     gcc_decl,		      /* Argument DECL.  */
45007163879Schristos	     gcc_type)		      /* Argument TYPE.  */
45107163879Schristos
45207163879Schristos/* Return the type of a pointer to a given base type.  */
45307163879Schristos
45407163879SchristosGCC_METHOD1 (gcc_type, build_pointer_type,
45507163879Schristos	     gcc_type)			/* Argument BASE_TYPE.  */
45607163879Schristos
45707163879Schristos/* Return the type of a reference to a given base type.  */
45807163879Schristos
45907163879SchristosGCC_METHOD2 (gcc_type, build_reference_type,
46007163879Schristos	     gcc_type,			/* Argument BASE_TYPE.  */
46107163879Schristos	     enum gcc_cp_ref_qualifiers)   /* Argument RQUALS.  */
46207163879Schristos
46307163879Schristos/* Create a new pointer-to-member type.  MEMBER_TYPE is the data
46407163879Schristos   member type, while CLASS_TYPE is the class type containing the data
46507163879Schristos   member.  For pointers to member functions, MEMBER_TYPE must be a
46607163879Schristos   method type, and CLASS_TYPE must be specified even though it might
46707163879Schristos   be possible to extract it from the method type.  */
46807163879Schristos
46907163879SchristosGCC_METHOD2 (gcc_type, build_pointer_to_member_type,
47007163879Schristos	     gcc_type,			   /* Argument CLASS_TYPE.  */
47107163879Schristos	     gcc_type) 			   /* Argument MEMBER_TYPE.  */
47207163879Schristos
47307163879Schristos/* Start a template parameter list scope and enters it, so that
47407163879Schristos   subsequent build_type_template_parameter and
47507163879Schristos   build_value_template_parameter calls create template parameters in
47607163879Schristos   the list.  The list is closed by a build_decl call with
47707163879Schristos   GCC_CP_SYMBOL_FUNCTION or GCC_CP_SYMBOL_CLASS, that, when the scope
47807163879Schristos   is a template parameter list, declares a template function or a
47907163879Schristos   template class with the then-closed parameter list.  The scope in
48007163879Schristos   which the new declaration is to be introduced by build_decl must be
48107163879Schristos   entered before calling start_template_decl, and build_decl returns
48207163879Schristos   to that scope, from the template parameter list scope, before
48307163879Schristos   introducing the declaration.  */
48407163879Schristos
48507163879SchristosGCC_METHOD0 (int /* bool */, start_template_decl)
48607163879Schristos
48707163879Schristos/* Build a typename template-parameter (e.g., the T in template
48807163879Schristos   <typename T = X>).  Either PACK_P should be nonzero, to indicate an
48907163879Schristos   argument pack (the last argument in a variadic template argument
49007163879Schristos   list, as in template <typename... T>), or DEFAULT_TYPE may be
49107163879Schristos   non-NULL to set the default type argument (e.g. X) for the template
49207163879Schristos   parameter.  FILENAME and LINE_NUMBER may specify the source
49307163879Schristos   location in which the template parameter was declared.  */
49407163879Schristos
49507163879SchristosGCC_METHOD5 (gcc_type, build_type_template_parameter,
49607163879Schristos	     const char *,			      /* Argument ID.  */
49707163879Schristos	     int /* bool */,			  /* Argument PACK_P.  */
49807163879Schristos	     gcc_type,			    /* Argument DEFAULT_TYPE.  */
49907163879Schristos	     const char *,			/* Argument FILENAME.  */
50007163879Schristos	     unsigned int)		     /* Argument LINE_NUMBER.  */
50107163879Schristos
50207163879Schristos/* Build a template template-parameter (e.g., the T in template
50307163879Schristos   <template <[...]> class T = X>).  DEFAULT_TEMPL may be non-NULL to
50407163879Schristos   set the default type-template argument (e.g. X) for the template
50507163879Schristos   template parameter.  FILENAME and LINE_NUMBER may specify the
50607163879Schristos   source location in which the template parameter was declared.  */
50707163879Schristos
50807163879SchristosGCC_METHOD5 (gcc_utempl, build_template_template_parameter,
50907163879Schristos	     const char *,			      /* Argument ID.  */
51007163879Schristos	     int /* bool */,			  /* Argument PACK_P.  */
51107163879Schristos	     gcc_utempl,		   /* Argument DEFAULT_TEMPL.  */
51207163879Schristos	     const char *,			/* Argument FILENAME.  */
51307163879Schristos	     unsigned int)		     /* Argument LINE_NUMBER.  */
51407163879Schristos
51507163879Schristos/* Build a value template-parameter (e.g., the V in template <typename
51607163879Schristos   T, T V> or in template <int V = X>).  DEFAULT_VALUE may be non-NULL
51707163879Schristos   to set the default value argument for the template parameter (e.g.,
51807163879Schristos   X).  FILENAME and LINE_NUMBER may specify the source location in
51907163879Schristos   which the template parameter was declared.  */
52007163879Schristos
52107163879SchristosGCC_METHOD5 (gcc_decl, build_value_template_parameter,
52207163879Schristos	     gcc_type,			  	    /* Argument TYPE.  */
52307163879Schristos	     const char *,			      /* Argument ID.  */
52407163879Schristos	     gcc_expr,			   /* Argument DEFAULT_VALUE.  */
52507163879Schristos	     const char *,			/* Argument FILENAME.  */
52607163879Schristos	     unsigned int)		     /* Argument LINE_NUMBER.  */
52707163879Schristos
52807163879Schristos/* Build a template-dependent typename (e.g., typename T::bar or
52907163879Schristos   typename T::template bart<X>).  ENCLOSING_TYPE should be the
53007163879Schristos   template-dependent nested name specifier (e.g., T), ID should be
53107163879Schristos   the name of the member of the ENCLOSING_TYPE (e.g., bar or bart),
53207163879Schristos   and TARGS should be non-NULL and specify the template arguments
53307163879Schristos   (e.g. <X>) iff ID is to name a class template.
53407163879Schristos
53507163879Schristos   In this and other calls, a template-dependent nested name specifier
53607163879Schristos   may be a template class parameter (build_type_template_parameter),
53707163879Schristos   a specialization (returned by build_dependent_type_template_id) of
53807163879Schristos   a template template parameter (returned by
53907163879Schristos   build_template_template_parameter) or a member type thereof
54007163879Schristos   (returned by build_dependent_typename itself).  */
54107163879Schristos
54207163879SchristosGCC_METHOD3 (gcc_type, build_dependent_typename,
54307163879Schristos	     gcc_type,			  /* Argument ENCLOSING_TYPE.  */
54407163879Schristos	     const char *,			      /* Argument ID.  */
54507163879Schristos	     const struct gcc_cp_template_args *)  /* Argument TARGS.  */
54607163879Schristos
54707163879Schristos/* Build a template-dependent class template (e.g., T::template bart).
54807163879Schristos   ENCLOSING_TYPE should be the template-dependent nested name
54907163879Schristos   specifier (e.g., T), ID should be the name of the class template
55007163879Schristos   member of the ENCLOSING_TYPE (e.g., bart).  */
55107163879Schristos
55207163879SchristosGCC_METHOD2 (gcc_utempl, build_dependent_class_template,
55307163879Schristos	     gcc_type,			  /* Argument ENCLOSING_TYPE.  */
55407163879Schristos	     const char *)			      /* Argument ID.  */
55507163879Schristos
55607163879Schristos/* Build a template-dependent type template-id (e.g., T<A>).
55707163879Schristos   TEMPLATE_DECL should be a template template parameter (e.g., the T
55807163879Schristos   in template <template <[...]> class T = X>), and TARGS should
55907163879Schristos   specify the template arguments (e.g. <A>).  */
56007163879Schristos
56107163879SchristosGCC_METHOD2 (gcc_type, build_dependent_type_template_id,
56207163879Schristos	     gcc_utempl,		   /* Argument TEMPLATE_DECL.  */
56307163879Schristos	     const struct gcc_cp_template_args *)  /* Argument TARGS.  */
56407163879Schristos
56507163879Schristos/* Build a template-dependent expression (e.g., S::val or S::template
56607163879Schristos   mtf<X>, or unqualified f or template tf<X>).
56707163879Schristos
56807163879Schristos   ENCLOSING_SCOPE should be a template-dependent nested name
56907163879Schristos   specifier (e.g., T), a resolved namespace or class decl, or NULL
57007163879Schristos   for unqualified names; ID should be the name of the member of the
57107163879Schristos   ENCLOSING_SCOPE (e.g., val or mtf) or unqualified overloaded
57207163879Schristos   function; and TARGS should list template arguments (e.g. <X>) when
57307163879Schristos   mtf or tf are to name a template function, or be NULL otherwise.
57407163879Schristos
57507163879Schristos   Unqualified names and namespace- or class-qualified names can only
57607163879Schristos   resolve to overloaded functions, to be used in contexts that
57707163879Schristos   involve overload resolution that cannot be resolved because of
57807163879Schristos   template-dependent argument or return types, such as call
57907163879Schristos   expressions with template-dependent arguments, conversion
58007163879Schristos   expressions to function types with template-dependent argument
58107163879Schristos   types or the like.  Other cases of unqualified or
58207163879Schristos   non-template-dependent-qualified names should NOT use this
58307163879Schristos   function, and use decl_expr to convert the appropriate function or
58407163879Schristos   object declaration to an expression.
58507163879Schristos
58607163879Schristos   If ID is the name of a special member function, FLAGS should be
58707163879Schristos   GCC_CP_SYMBOL_FUNCTION|GCC_CP_FLAG_SPECIAL_FUNCTION, and ID should
58807163879Schristos   be one of the encodings for special member functions documented in
58907163879Schristos   build_decl.  Otherwise, FLAGS should be GCC_CP_SYMBOL_MASK, which
59007163879Schristos   suggests the symbol kind is not known (though we know it is not a
59107163879Schristos   type).
59207163879Schristos
59307163879Schristos   If ID denotes a conversion operator, CONV_TYPE should name the
59407163879Schristos   target type of the conversion.  Otherwise, CONV_TYPE must be
59507163879Schristos   NULL.  */
59607163879Schristos
59707163879SchristosGCC_METHOD5 (gcc_expr, build_dependent_expr,
59807163879Schristos	     gcc_decl,			 /* Argument ENCLOSING_SCOPE.  */
59907163879Schristos	     enum gcc_cp_symbol_kind,		   /* Argument FLAGS.  */
60007163879Schristos	     const char *,			    /* Argument NAME.  */
60107163879Schristos	     gcc_type,			       /* Argument CONV_TYPE.  */
60207163879Schristos	     const struct gcc_cp_template_args *)  /* Argument TARGS.  */
60307163879Schristos
60407163879Schristos/* Build a gcc_expr for the value VALUE in type TYPE.  */
60507163879Schristos
60607163879SchristosGCC_METHOD2 (gcc_expr, build_literal_expr,
60707163879Schristos	     gcc_type,		  /* Argument TYPE.  */
60807163879Schristos	     unsigned long)	  /* Argument VALUE.  */
60907163879Schristos
61007163879Schristos/* Build a gcc_expr that denotes DECL, the declaration of a variable
61107163879Schristos   or function in namespace scope, or of a static member variable or
61207163879Schristos   function.  Use QUALIFIED_P to build the operand of unary & so as to
61307163879Schristos   compute a pointer-to-member, rather than a regular pointer.  */
61407163879Schristos
61507163879SchristosGCC_METHOD2 (gcc_expr, build_decl_expr,
61607163879Schristos	     gcc_decl,			/* Argument DECL.  */
61707163879Schristos	     int /* bool */)		/* Argument QUALIFIED_P.  */
61807163879Schristos
61907163879Schristos/* Build a gcc_expr that denotes the unary operation UNARY_OP applied
62007163879Schristos   to the gcc_expr OPERAND.  For non-expr operands, see
62107163879Schristos   unary_type_expr.  Besides the UNARY_OP encodings used for operator
62207163879Schristos   names, we support "pp_" for preincrement, and "mm_" for
62307163879Schristos   predecrement, "nx" for noexcept, "tw" for throw, "tr" for rethrow
62407163879Schristos   (pass NULL as the operand), "te" for typeid, "sz" for sizeof, "az"
62507163879Schristos   for alignof, "dl" for delete, "gsdl" for ::delete, "da" for
62607163879Schristos   delete[], "gsda" for ::delete[], "sp" for pack expansion, "sZ" for
62707163879Schristos   sizeof...(function argument pack).  */
62807163879Schristos
62907163879SchristosGCC_METHOD2 (gcc_expr, build_unary_expr,
63007163879Schristos	     const char *,	  /* Argument UNARY_OP.  */
63107163879Schristos	     gcc_expr)		  /* Argument OPERAND.  */
63207163879Schristos
63307163879Schristos/* Build a gcc_expr that denotes the binary operation BINARY_OP
63407163879Schristos   applied to gcc_exprs OPERAND1 and OPERAND2.  Besides the BINARY_OP
63507163879Schristos   encodings used for operator names, we support "ds" for the operator
63607163879Schristos   token ".*" and "dt" for the operator token ".".  When using
63707163879Schristos   operators that take a name as their second operand ("." and "->")
63807163879Schristos   use decl_expr to convert the gcc_decl of the member name to a
63907163879Schristos   gcc_expr, if the member name wasn't created with
64007163879Schristos   e.g. build_dependent_expr.  */
64107163879Schristos
64207163879SchristosGCC_METHOD3 (gcc_expr, build_binary_expr,
64307163879Schristos	     const char *,	  /* Argument BINARY_OP.  */
64407163879Schristos	     gcc_expr,		  /* Argument OPERAND1.  */
64507163879Schristos	     gcc_expr)		  /* Argument OPERAND2.  */
64607163879Schristos
64707163879Schristos/* Build a gcc_expr that denotes the ternary operation TERNARY_OP
64807163879Schristos   applied to gcc_exprs OPERAND1, OPERAND2 and OPERAND3.  The only
64907163879Schristos   supported TERNARY_OP is "qu", for the "?:" operator.  */
65007163879Schristos
65107163879SchristosGCC_METHOD4 (gcc_expr, build_ternary_expr,
65207163879Schristos	     const char *,	  /* Argument TERNARY_OP.  */
65307163879Schristos	     gcc_expr,		  /* Argument OPERAND1.  */
65407163879Schristos	     gcc_expr,		  /* Argument OPERAND2.  */
65507163879Schristos	     gcc_expr)		  /* Argument OPERAND3.  */
65607163879Schristos
65707163879Schristos/* Build a gcc_expr that denotes the unary operation UNARY_OP applied
65807163879Schristos   to the gcc_type OPERAND.  Supported unary operations taking types
65907163879Schristos   are "ti" for typeid, "st" for sizeof, "at" for alignof, and "sZ"
66007163879Schristos   for sizeof...(template argument pack).  */
66107163879Schristos
66207163879SchristosGCC_METHOD2 (gcc_expr, build_unary_type_expr,
66307163879Schristos	     const char *,	  /* Argument UNARY_OP.  */
66407163879Schristos	     gcc_type)		  /* Argument OPERAND.  */
66507163879Schristos
66607163879Schristos/* Build a gcc_expr that denotes the binary operation BINARY_OP
66707163879Schristos   applied to gcc_type OPERAND1 and gcc_expr OPERAND2.  Use this for
66807163879Schristos   all kinds of (single-argument) type casts ("dc", "sc", "cc", "rc"
66907163879Schristos   for dynamic, static, const and reinterpret casts, respectively;
67007163879Schristos   "cv" for functional or C-style casts).  */
67107163879Schristos
67207163879SchristosGCC_METHOD3 (gcc_expr, build_cast_expr,
67307163879Schristos	     const char *,	  /* Argument BINARY_OP.  */
67407163879Schristos	     gcc_type,		  /* Argument OPERAND1.  */
67507163879Schristos	     gcc_expr)		  /* Argument OPERAND2.  */
67607163879Schristos
67707163879Schristos/* Build a gcc_expr that denotes the conversion of an expression list
67807163879Schristos   VALUES to TYPE, with ("tl") or without ("cv") braces, or a braced
67907163879Schristos   initializer list of unspecified type (e.g., a component of another
68007163879Schristos   braced initializer list; pass "il" for CONV_OP, and NULL for
68107163879Schristos   TYPE).  */
68207163879Schristos
68307163879SchristosGCC_METHOD3 (gcc_expr, build_expression_list_expr,
68407163879Schristos	     const char *,			 /* Argument CONV_OP.  */
68507163879Schristos	     gcc_type,				    /* Argument TYPE.  */
68607163879Schristos	     const struct gcc_cp_function_args *) /* Argument VALUES.  */
68707163879Schristos
68807163879Schristos/* Build a gcc_expr that denotes a new ("nw") or new[] ("na")
68907163879Schristos   expression of TYPE, with or without a GLOBAL_NS qualifier (prefix
69007163879Schristos   the NEW_OP with "gs"), with or without PLACEMENT, with or without
69107163879Schristos   INITIALIZER.  If it's not a placement new, PLACEMENT must be NULL
69207163879Schristos   (rather than a zero-length placement arg list).  If there's no
69307163879Schristos   specified initializer, INITIALIZER must be NULL; a zero-length arg
69407163879Schristos   list stands for a default initializer.  */
69507163879Schristos
69607163879SchristosGCC_METHOD4 (gcc_expr, build_new_expr,
69707163879Schristos	     const char *,			       /* Argument NEW_OP.  */
69807163879Schristos	     const struct gcc_cp_function_args *,   /* Argument PLACEMENT.  */
69907163879Schristos	     gcc_type,					 /* Argument TYPE.  */
70007163879Schristos	     const struct gcc_cp_function_args *) /* Argument INITIALIZER.  */
70107163879Schristos
70207163879Schristos/* Return a call expression that calls CALLABLE with arguments ARGS.
70307163879Schristos   CALLABLE may be a function, a callable object, a pointer to
70407163879Schristos   function, an unresolved expression, an unresolved overload set, an
70507163879Schristos   object expression combined with a member function overload set or a
70607163879Schristos   pointer-to-member.  If QUALIFIED_P, CALLABLE will be interpreted as
70707163879Schristos   a qualified name, preventing virtual function dispatch.  */
70807163879Schristos
70907163879SchristosGCC_METHOD3 (gcc_expr, build_call_expr,
71007163879Schristos	     gcc_expr,			      /* Argument CALLABLE.  */
71107163879Schristos	     int /* bool */,		   /* Argument QUALIFIED_P.  */
71207163879Schristos	     const struct gcc_cp_function_args *) /* Argument ARGS.  */
71307163879Schristos
71407163879Schristos/* Return the type of the gcc_expr OPERAND.
71507163879Schristos   Use this for decltype.
71607163879Schristos   For decltype (auto), pass a NULL OPERAND.
71707163879Schristos
71807163879Schristos   Note: for template-dependent expressions, the result is NULL,
71907163879Schristos   because the type is only computed when template argument
72007163879Schristos   substitution is performed.  */
72107163879Schristos
72207163879SchristosGCC_METHOD1 (gcc_type, get_expr_type,
72307163879Schristos	     gcc_expr)		  /* Argument OPERAND.  */
72407163879Schristos
72507163879Schristos/* Introduce a specialization of a template function.
72607163879Schristos
72707163879Schristos   TEMPLATE_DECL is the template function, and TARGS are the arguments
72807163879Schristos   for the specialization.  ADDRESS is the address of the
72907163879Schristos   specialization.  FILENAME and LINE_NUMBER specify the source
73007163879Schristos   location associated with the template function specialization.  */
73107163879Schristos
73207163879SchristosGCC_METHOD5 (gcc_decl, build_function_template_specialization,
73307163879Schristos	     gcc_decl,			   /* Argument TEMPLATE_DECL.  */
73407163879Schristos	     const struct gcc_cp_template_args *,  /* Argument TARGS.  */
73507163879Schristos	     gcc_address,			 /* Argument ADDRESS.  */
73607163879Schristos	     const char *,	      /* Argument FILENAME.  */
73707163879Schristos	     unsigned int)	      /* Argument LINE_NUMBER.  */
73807163879Schristos
73907163879Schristos/* Specialize a template class as an incomplete type.  A definition
74007163879Schristos   can be supplied later, with start_class_type.
74107163879Schristos
74207163879Schristos   TEMPLATE_DECL is the template class, and TARGS are the arguments
74307163879Schristos   for the specialization.  FILENAME and LINE_NUMBER specify the
74407163879Schristos   source location associated with the template class
74507163879Schristos   specialization.  */
74607163879Schristos
74707163879SchristosGCC_METHOD4 (gcc_decl, build_class_template_specialization,
74807163879Schristos	     gcc_decl,			   /* Argument TEMPLATE_DECL.  */
74907163879Schristos	     const struct gcc_cp_template_args *,  /* Argument TARGS.  */
75007163879Schristos	     const char *,	      /* Argument FILENAME.  */
75107163879Schristos	     unsigned int)	      /* Argument LINE_NUMBER.  */
75207163879Schristos
75307163879Schristos/* Start defining a 'class', 'struct' or 'union' type, entering its
75407163879Schristos   own binding level.  Initially it has no fields.
75507163879Schristos
75607163879Schristos   TYPEDECL is the forward-declaration of the type, returned by
75707163879Schristos   build_decl.  BASE_CLASSES indicate the base classes of class NAME.
75807163879Schristos   FILENAME and LINE_NUMBER specify the source location associated
75907163879Schristos   with the class definition, should they be different from those of
76007163879Schristos   the forward declaration.  */
76107163879Schristos
76207163879SchristosGCC_METHOD4 (gcc_type, start_class_type,
76307163879Schristos	     gcc_decl,		      /* Argument TYPEDECL.  */
76407163879Schristos	     const struct gcc_vbase_array *,/* Argument BASE_CLASSES.  */
76507163879Schristos	     const char *,	      /* Argument FILENAME.  */
76607163879Schristos	     unsigned int)	      /* Argument LINE_NUMBER.  */
76707163879Schristos
76807163879Schristos/* Create a new closure class type, record it as the
76907163879Schristos   DISCRIMINATOR-numbered closure type in the current scope (or
77007163879Schristos   associated with EXTRA_SCOPE, if non-NULL), and enter the closure
77107163879Schristos   type's own binding level.  This primitive would sort of combine
77207163879Schristos   build_decl and start_class_type, if they could be used to introduce
77307163879Schristos   a closure type.  Initially it has no fields.
77407163879Schristos
77507163879Schristos   FILENAME and LINE_NUMBER specify the source location associated
77607163879Schristos   with the class.  EXTRA_SCOPE, if non-NULL, must be a PARM_DECL of
77707163879Schristos   the current function, or a FIELD_DECL of the current class.  If it
77807163879Schristos   is NULL, the current scope must be a function.  */
77907163879Schristos
78007163879SchristosGCC_METHOD5 (gcc_type, start_closure_class_type,
78107163879Schristos	     int,		      /* Argument DISCRIMINATOR.  */
78207163879Schristos	     gcc_decl,		      /* Argument EXTRA_SCOPE.  */
78307163879Schristos	     enum gcc_cp_symbol_kind, /* Argument FLAGS.  */
78407163879Schristos	     const char *,	      /* Argument FILENAME.  */
78507163879Schristos	     unsigned int)	      /* Argument LINE_NUMBER.  */
78607163879Schristos
78707163879Schristos/* Add a non-static data member to the most-recently-started
78807163879Schristos   unfinished struct or union type.  FIELD_NAME is the field's name.
78907163879Schristos   FIELD_TYPE is the type of the field.  BITSIZE and BITPOS indicate
79007163879Schristos   where in the struct the field occurs.  */
79107163879Schristos
79207163879SchristosGCC_METHOD5 (gcc_decl, build_field,
79307163879Schristos	     const char *,		   /* Argument FIELD_NAME.  */
79407163879Schristos	     gcc_type,			   /* Argument FIELD_TYPE.  */
79507163879Schristos	     enum gcc_cp_symbol_kind,	   /* Argument FIELD_FLAGS.  */
79607163879Schristos	     unsigned long,		   /* Argument BITSIZE.  */
79707163879Schristos	     unsigned long)		   /* Argument BITPOS.  */
79807163879Schristos
79907163879Schristos/* After all the fields have been added to a struct, class or union,
80007163879Schristos   the struct or union type must be "finished".  This does some final
80107163879Schristos   cleanups in GCC, and pops to the binding level that was in effect
80207163879Schristos   before the matching start_class_type or
80307163879Schristos   start_closure_class_type.  */
80407163879Schristos
80507163879SchristosGCC_METHOD1 (int /* bool */, finish_class_type,
80607163879Schristos	     unsigned long)		   /* Argument SIZE_IN_BYTES.  */
80707163879Schristos
80807163879Schristos/* Create a new 'enum' type, and record it in the current binding
80907163879Schristos   level.  The new type initially has no associated constants.
81007163879Schristos
81107163879Schristos   NAME is the enum name.  FILENAME and LINE_NUMBER specify its source
81207163879Schristos   location.  */
81307163879Schristos
81407163879SchristosGCC_METHOD5 (gcc_type, start_enum_type,
81507163879Schristos	     const char *,	      /* Argument NAME.  */
81607163879Schristos	     gcc_type,		      /* Argument UNDERLYING_INT_TYPE. */
81707163879Schristos	     enum gcc_cp_symbol_kind, /* Argument FLAGS.  */
81807163879Schristos	     const char *,	      /* Argument FILENAME.  */
81907163879Schristos	     unsigned int)	      /* Argument LINE_NUMBER.  */
82007163879Schristos
82107163879Schristos/* Add a new constant to an enum type.  NAME is the constant's name
82207163879Schristos   and VALUE is its value.  Returns a gcc_decl for the constant.  */
82307163879Schristos
82407163879SchristosGCC_METHOD3 (gcc_decl, build_enum_constant,
82507163879Schristos	     gcc_type,		       /* Argument ENUM_TYPE.  */
82607163879Schristos	     const char *,	       /* Argument NAME.  */
82707163879Schristos	     unsigned long)	       /* Argument VALUE.  */
82807163879Schristos
82907163879Schristos/* After all the constants have been added to an enum, the type must
83007163879Schristos   be "finished".  This does some final cleanups in GCC.  */
83107163879Schristos
83207163879SchristosGCC_METHOD1 (int /* bool */, finish_enum_type,
83307163879Schristos	     gcc_type)		       /* Argument ENUM_TYPE.  */
83407163879Schristos
83507163879Schristos/* Create a new function type.  RETURN_TYPE is the type returned by
83607163879Schristos   the function, and ARGUMENT_TYPES is a vector, of length NARGS, of
83707163879Schristos   the argument types.  IS_VARARGS is true if the function is
83807163879Schristos   varargs.  */
83907163879Schristos
84007163879SchristosGCC_METHOD3 (gcc_type, build_function_type,
84107163879Schristos	     gcc_type,			   /* Argument RETURN_TYPE.  */
84207163879Schristos	     const struct gcc_type_array *,/* Argument ARGUMENT_TYPES.  */
84307163879Schristos	     int /* bool */)		   /* Argument IS_VARARGS.  */
84407163879Schristos
84507163879Schristos/* Create a variant of a function type with an exception
84607163879Schristos   specification.  FUNCTION_TYPE is a function or method type.
84707163879Schristos   EXCEPT_TYPES is an array with the list of exception types.  Zero as
84807163879Schristos   the array length implies throw() AKA noexcept(true); NULL as the
84907163879Schristos   pointer to gcc_type_array implies noexcept(false), which is almost
85007163879Schristos   equivalent (but distinguishable by the compiler) to an unspecified
85107163879Schristos   exception list.  */
85207163879Schristos
85307163879SchristosGCC_METHOD2 (gcc_type, build_exception_spec_variant,
85407163879Schristos	     gcc_type,			   /* Argument FUNCTION_TYPE.  */
85507163879Schristos	     const struct gcc_type_array *)/* Argument EXCEPT_TYPES.  */
85607163879Schristos
85707163879Schristos/* Create a new non-static member function type.  FUNC_TYPE is the
85807163879Schristos   method prototype, without the implicit THIS pointer, added as a
85907163879Schristos   pointer to the QUALS-qualified CLASS_TYPE.  If CLASS_TYPE is NULL,
86007163879Schristos   this creates a cv-qualified (member) function type not associated
86107163879Schristos   with any specific class, as needed to support "typedef void f(int)
86207163879Schristos   const;", which can later be used to declare member functions and
86307163879Schristos   pointers to member functions.  */
86407163879Schristos
86507163879SchristosGCC_METHOD4 (gcc_type, build_method_type,
86607163879Schristos	     gcc_type,			   /* Argument CLASS_TYPE.  */
86707163879Schristos	     gcc_type, 			   /* Argument FUNC_TYPE.  */
86807163879Schristos	     enum gcc_cp_qualifiers,	   /* Argument QUALS.  */
86907163879Schristos	     enum gcc_cp_ref_qualifiers)   /* Argument RQUALS.  */
87007163879Schristos
87107163879Schristos/* Return a declaration for the (INDEX - 1)th argument of
87207163879Schristos   FUNCTION_DECL, i.e., for the first argument, use zero as the index.
87307163879Schristos   If FUNCTION_DECL is a non-static member function, use -1 to get the
87407163879Schristos   implicit THIS parameter.  */
87507163879Schristos
87607163879SchristosGCC_METHOD2 (gcc_decl, get_function_parameter_decl,
87707163879Schristos	     gcc_decl,			     /* Argument FUNCTION_DECL.  */
87807163879Schristos	     int)				     /* Argument INDEX.  */
87907163879Schristos
88007163879Schristos/* Return a lambda expr that constructs an instance of CLOSURE_TYPE.
88107163879Schristos   Only lambda exprs without any captures can be correctly created
88207163879Schristos   through these mechanisms; that's all we need to support lambdas
88307163879Schristos   expressions in default parameters, the only kind that may have to
88407163879Schristos   be introduced through this interface.  */
88507163879Schristos
88607163879SchristosGCC_METHOD1 (gcc_expr, build_lambda_expr,
88707163879Schristos	     gcc_type)			      /* Argument CLOSURE_TYPE.  */
88807163879Schristos
88907163879Schristos/* Return an integer type with the given properties.  If BUILTIN_NAME
89007163879Schristos   is non-NULL, it must name a builtin integral type with the given
89107163879Schristos   signedness and size, and that is the type that will be returned.  */
89207163879Schristos
89307163879SchristosGCC_METHOD3 (gcc_type, get_int_type,
89407163879Schristos	     int /* bool */,		   /* Argument IS_UNSIGNED.  */
89507163879Schristos	     unsigned long,                /* Argument SIZE_IN_BYTES.  */
89607163879Schristos	     const char *)		   /* Argument BUILTIN_NAME.  */
89707163879Schristos
89807163879Schristos/* Return the 'char' type, a distinct type from both 'signed char' and
89907163879Schristos   'unsigned char' returned by int_type.  */
90007163879Schristos
90107163879SchristosGCC_METHOD0 (gcc_type, get_char_type)
90207163879Schristos
90307163879Schristos/* Return a floating point type with the given properties.  If BUILTIN_NAME
90407163879Schristos   is non-NULL, it must name a builtin integral type with the given
90507163879Schristos   signedness and size, and that is the type that will be returned.  */
90607163879Schristos
90707163879SchristosGCC_METHOD2 (gcc_type, get_float_type,
90807163879Schristos	     unsigned long,                /* Argument SIZE_IN_BYTES.  */
90907163879Schristos	     const char *)		   /* Argument BUILTIN_NAME.  */
91007163879Schristos
91107163879Schristos/* Return the 'void' type.  */
91207163879Schristos
91307163879SchristosGCC_METHOD0 (gcc_type, get_void_type)
91407163879Schristos
91507163879Schristos/* Return the 'bool' type.  */
91607163879Schristos
91707163879SchristosGCC_METHOD0 (gcc_type, get_bool_type)
91807163879Schristos
91907163879Schristos/* Return the std::nullptr_t type.  */
92007163879Schristos
92107163879SchristosGCC_METHOD0 (gcc_type, get_nullptr_type)
92207163879Schristos
92307163879Schristos/* Return the nullptr constant.  */
92407163879Schristos
92507163879SchristosGCC_METHOD0 (gcc_expr, get_nullptr_constant)
92607163879Schristos
92707163879Schristos/* Create a new array type.  If NUM_ELEMENTS is -1, then the array
92807163879Schristos   is assumed to have an unknown length.  */
92907163879Schristos
93007163879SchristosGCC_METHOD2 (gcc_type, build_array_type,
93107163879Schristos	     gcc_type,			  /* Argument ELEMENT_TYPE.  */
93207163879Schristos	     int)			  /* Argument NUM_ELEMENTS.  */
93307163879Schristos
93407163879Schristos/* Create a new array type.  NUM_ELEMENTS is a template-dependent
93507163879Schristos   expression.  */
93607163879Schristos
93707163879SchristosGCC_METHOD2 (gcc_type, build_dependent_array_type,
93807163879Schristos	     gcc_type,			  /* Argument ELEMENT_TYPE.  */
93907163879Schristos	     gcc_expr)			  /* Argument NUM_ELEMENTS.  */
94007163879Schristos
94107163879Schristos/* Create a new variably-sized array type.  UPPER_BOUND_NAME is the
94207163879Schristos   name of a local variable that holds the upper bound of the array;
94307163879Schristos   it is one less than the array size.  */
94407163879Schristos
94507163879SchristosGCC_METHOD2 (gcc_type, build_vla_array_type,
94607163879Schristos	     gcc_type,			  /* Argument ELEMENT_TYPE.  */
94707163879Schristos	     const char *)		  /* Argument UPPER_BOUND_NAME.  */
94807163879Schristos
94907163879Schristos/* Return a qualified variant of a given base type.  QUALIFIERS says
95007163879Schristos   which qualifiers to use; it is composed of or'd together
95107163879Schristos   constants from 'enum gcc_cp_qualifiers'.  */
95207163879Schristos
95307163879SchristosGCC_METHOD2 (gcc_type, build_qualified_type,
95407163879Schristos	     gcc_type,			      /* Argument UNQUALIFIED_TYPE.  */
95507163879Schristos	     enum gcc_cp_qualifiers)	      /* Argument QUALIFIERS.  */
95607163879Schristos
95707163879Schristos/* Build a complex type given its element type.  */
95807163879Schristos
95907163879SchristosGCC_METHOD1 (gcc_type, build_complex_type,
96007163879Schristos	     gcc_type)			  /* Argument ELEMENT_TYPE.  */
96107163879Schristos
96207163879Schristos/* Build a vector type given its element type and number of
96307163879Schristos   elements.  */
96407163879Schristos
96507163879SchristosGCC_METHOD2 (gcc_type, build_vector_type,
96607163879Schristos	     gcc_type,			  /* Argument ELEMENT_TYPE.  */
96707163879Schristos	     int)			  /* Argument NUM_ELEMENTS.  */
96807163879Schristos
96907163879Schristos/* Build a constant.  NAME is the constant's name and VALUE is its
97007163879Schristos   value.  FILENAME and LINE_NUMBER refer to the type's source
97107163879Schristos   location.  If this is not known, FILENAME can be NULL and
97207163879Schristos   LINE_NUMBER can be 0.  */
97307163879Schristos
97407163879SchristosGCC_METHOD5 (int /* bool */, build_constant,
97507163879Schristos	     gcc_type,		  /* Argument TYPE.  */
97607163879Schristos	     const char *,	  /* Argument NAME.  */
97707163879Schristos	     unsigned long,	  /* Argument VALUE.  */
97807163879Schristos	     const char *,	  /* Argument FILENAME.  */
97907163879Schristos	     unsigned int)	  /* Argument LINE_NUMBER.  */
98007163879Schristos
98107163879Schristos/* Emit an error and return an error type object.  */
98207163879Schristos
98307163879SchristosGCC_METHOD1 (gcc_type, error,
98407163879Schristos	     const char *)		 /* Argument MESSAGE.  */
98507163879Schristos
98607163879Schristos/* Declare a static_assert with the given CONDITION and ERRORMSG at
98707163879Schristos   FILENAME:LINE_NUMBER.  */
98807163879Schristos
98907163879SchristosGCC_METHOD4 (int /* bool */, add_static_assert,
99007163879Schristos	     gcc_expr,     /* Argument CONDITION.  */
99107163879Schristos	     const char *, /* Argument ERRORMSG.  */
99207163879Schristos	     const char *, /* Argument FILENAME.  */
99307163879Schristos	     unsigned int) /* Argument LINE_NUMBER.  */
99407163879Schristos
99507163879Schristos#if 0
99607163879Schristos
99707163879Schristos/* FIXME: We don't want to expose the internal implementation detail
99807163879Schristos   that default parms are stored in function types, and it's not clear
99907163879Schristos   how this or other approaches would interact with the type sharing
100007163879Schristos   of e.g. ctor clones, so we're leaving this out, since default args
100107163879Schristos   are not even present in debug information anyway.  Besides, the set
100207163879Schristos   of default args for a function may grow within its scope, and vary
100307163879Schristos   independently in other scopes.  */
100407163879Schristos
100507163879Schristos/* Create a modified version of a function type that has default
100607163879Schristos   values for some of its arguments.  The returned type should ONLY be
100707163879Schristos   used to define functions or methods, never to declare parameters,
100807163879Schristos   variables, types or the like.
100907163879Schristos
101007163879Schristos   DEFAULTS must have at most as many N_ELEMENTS as there are
101107163879Schristos   arguments without default values in FUNCTION_TYPE.  Say, if
101207163879Schristos   FUNCTION_TYPE has an argument list such as (T1, T2, T3, T4 = V0)
101307163879Schristos   and DEFAULTS has 2 elements (V1, V2), the returned type will have
101407163879Schristos   the following argument list: (T1, T2 = V1, T3 = V2, T4 = V0).
101507163879Schristos
101607163879Schristos   Any NULL expressions in DEFAULTS will be marked as deferred, and
101707163879Schristos   they should be filled in with set_deferred_function_default_args.  */
101807163879Schristos
101907163879SchristosGCC_METHOD2 (gcc_type, add_function_default_args,
102007163879Schristos	     gcc_type,			     /* Argument FUNCTION_TYPE.  */
102107163879Schristos	     const struct gcc_cp_function_args *) /* Argument DEFAULTS.  */
102207163879Schristos
102307163879Schristos/* Fill in the first deferred default args in FUNCTION_DECL with the
102407163879Schristos   expressions given in DEFAULTS.  This can be used when the
102507163879Schristos   declaration of a parameter is needed to create a default
102607163879Schristos   expression, such as taking the size of an earlier parameter, or
102707163879Schristos   building a lambda expression in the parameter's context.  */
102807163879Schristos
102907163879SchristosGCC_METHOD2 (int /* bool */, set_deferred_function_default_args,
103007163879Schristos	     gcc_decl,			     /* Argument FUNCTION_DECL.  */
103107163879Schristos	     const struct gcc_cp_function_args *) /* Argument DEFAULTS.  */
103207163879Schristos
103307163879Schristos#endif
103407163879Schristos
103507163879Schristos
103607163879Schristos/* When you add entry points, add them at the end, so that the new API
103707163879Schristos   version remains compatible with the old version.
103807163879Schristos
103907163879Schristos   The following conventions have been observed as to naming entry points:
104007163879Schristos
104107163879Schristos   - build_* creates (and maybe records) something and returns it;
104207163879Schristos   - add_* creates and records something, but doesn't return it;
104307163879Schristos   - get_* obtains something without creating it;
104407163879Schristos   - start_* marks the beginning of a compound (type, list, ...);
104507163879Schristos   - finish_* completes the compound when needed.
104607163879Schristos
104707163879Schristos  Entry points that return an int (bool) and don't have a return value
104807163879Schristos  specification return nonzero (true) on success and zero (false) on
104907163879Schristos  failure.  This is in line with libcc1's conventions of returning a
105007163879Schristos  zero-initialized value in case of e.g. a transport error.  */
1051