1 /* Type stack for GDB parser.
3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "type-stack.h"
23 #include "parser-defs.h"
25 /* See type-stack.h. */
28 type_stack::insert (enum type_pieces tp
)
30 union type_stack_elt element
;
33 gdb_assert (tp
== tp_pointer
|| tp
== tp_reference
34 || tp
== tp_rvalue_reference
|| tp
== tp_const
35 || tp
== tp_volatile
|| tp
== tp_restrict
38 /* If there is anything on the stack (we know it will be a
39 tp_pointer), insert the qualifier above it. Otherwise, simply
40 push this on the top of the stack. */
41 if (!m_elements
.empty () && (tp
== tp_const
|| tp
== tp_volatile
42 || tp
== tp_restrict
))
48 insert_into (slot
, element
);
51 /* See type-stack.h. */
54 type_stack::insert (struct expr_builder
*pstate
, const char *string
)
56 union type_stack_elt element
;
59 /* If there is anything on the stack (we know it will be a
60 tp_pointer), insert the address space qualifier above it.
61 Otherwise, simply push this on the top of the stack. */
62 if (!m_elements
.empty ())
67 element
.piece
= tp_space_identifier
;
68 insert_into (slot
, element
);
70 = address_space_name_to_type_instance_flags (pstate
->gdbarch (),
72 insert_into (slot
, element
);
75 /* See type-stack.h. */
78 type_stack::follow_type_instance_flags ()
80 type_instance_flags flags
= 0;
88 flags
|= TYPE_INSTANCE_FLAG_CONST
;
91 flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
94 flags
|= TYPE_INSTANCE_FLAG_ATOMIC
;
97 flags
|= TYPE_INSTANCE_FLAG_RESTRICT
;
100 gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
104 /* See type-stack.h. */
107 type_stack::follow_types (struct type
*follow_type
)
111 int make_volatile
= 0;
112 type_instance_flags make_addr_space
= 0;
113 bool make_restrict
= false;
114 bool make_atomic
= false;
122 goto process_qualifiers
;
130 case tp_space_identifier
:
131 make_addr_space
= (enum type_instance_flag_value
) pop_int ();
137 make_restrict
= true;
140 follow_type
= lookup_pointer_type (follow_type
);
141 goto process_qualifiers
;
143 follow_type
= lookup_lvalue_reference_type (follow_type
);
144 goto process_qualifiers
;
145 case tp_rvalue_reference
:
146 follow_type
= lookup_rvalue_reference_type (follow_type
);
149 follow_type
= make_cv_type (make_const
,
150 TYPE_VOLATILE (follow_type
),
153 follow_type
= make_cv_type (TYPE_CONST (follow_type
),
157 follow_type
= make_type_with_address_space (follow_type
,
160 follow_type
= make_restrict_type (follow_type
);
162 follow_type
= make_atomic_type (follow_type
);
163 make_const
= make_volatile
= 0;
165 make_restrict
= make_atomic
= false;
168 array_size
= pop_int ();
169 /* FIXME-type-allocation: need a way to free this type when we are
172 lookup_array_range_type (follow_type
,
173 0, array_size
>= 0 ? array_size
- 1 : 0);
175 follow_type
->bounds ()->high
.set_undefined ();
178 /* FIXME-type-allocation: need a way to free this type when we are
180 follow_type
= lookup_function_type (follow_type
);
183 case tp_function_with_arguments
:
185 std::vector
<struct type
*> *args
= pop_typelist ();
188 = lookup_function_type_with_arguments (follow_type
,
196 struct type_stack
*stack
= pop_type_stack ();
197 follow_type
= stack
->follow_types (follow_type
);
201 gdb_assert_not_reached ("unrecognized tp_ value in follow_types");