gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / type-stack.c
1 /* Type stack for GDB parser.
2
3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "type-stack.h"
22
23 #include "gdbtypes.h"
24 #include "parser-defs.h"
25
26 /* See type-stack.h. */
27
28 void
29 type_stack::insert (enum type_pieces tp)
30 {
31 union type_stack_elt element;
32 int slot;
33
34 gdb_assert (tp == tp_pointer || tp == tp_reference
35 || tp == tp_rvalue_reference || tp == tp_const
36 || tp == tp_volatile || tp == tp_restrict
37 || tp == tp_atomic);
38
39 /* If there is anything on the stack (we know it will be a
40 tp_pointer), insert the qualifier above it. Otherwise, simply
41 push this on the top of the stack. */
42 if (!m_elements.empty () && (tp == tp_const || tp == tp_volatile
43 || tp == tp_restrict))
44 slot = 1;
45 else
46 slot = 0;
47
48 element.piece = tp;
49 insert_into (slot, element);
50 }
51
52 /* See type-stack.h. */
53
54 void
55 type_stack::insert (struct expr_builder *pstate, const char *string)
56 {
57 union type_stack_elt element;
58 int slot;
59
60 /* If there is anything on the stack (we know it will be a
61 tp_pointer), insert the address space qualifier above it.
62 Otherwise, simply push this on the top of the stack. */
63 if (!m_elements.empty ())
64 slot = 1;
65 else
66 slot = 0;
67
68 element.piece = tp_space_identifier;
69 insert_into (slot, element);
70 element.int_val = address_space_name_to_int (pstate->gdbarch (),
71 string);
72 insert_into (slot, element);
73 }
74
75 /* See type-stack.h. */
76
77 type_instance_flags
78 type_stack::follow_type_instance_flags ()
79 {
80 type_instance_flags flags = 0;
81
82 for (;;)
83 switch (pop ())
84 {
85 case tp_end:
86 return flags;
87 case tp_const:
88 flags |= TYPE_INSTANCE_FLAG_CONST;
89 break;
90 case tp_volatile:
91 flags |= TYPE_INSTANCE_FLAG_VOLATILE;
92 break;
93 case tp_atomic:
94 flags |= TYPE_INSTANCE_FLAG_ATOMIC;
95 break;
96 case tp_restrict:
97 flags |= TYPE_INSTANCE_FLAG_RESTRICT;
98 break;
99 default:
100 gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
101 }
102 }
103
104 /* See type-stack.h. */
105
106 struct type *
107 type_stack::follow_types (struct type *follow_type)
108 {
109 int done = 0;
110 int make_const = 0;
111 int make_volatile = 0;
112 int make_addr_space = 0;
113 bool make_restrict = false;
114 bool make_atomic = false;
115 int array_size;
116
117 while (!done)
118 switch (pop ())
119 {
120 case tp_end:
121 done = 1;
122 goto process_qualifiers;
123 break;
124 case tp_const:
125 make_const = 1;
126 break;
127 case tp_volatile:
128 make_volatile = 1;
129 break;
130 case tp_space_identifier:
131 make_addr_space = pop_int ();
132 break;
133 case tp_atomic:
134 make_atomic = true;
135 break;
136 case tp_restrict:
137 make_restrict = true;
138 break;
139 case tp_pointer:
140 follow_type = lookup_pointer_type (follow_type);
141 goto process_qualifiers;
142 case tp_reference:
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);
147 process_qualifiers:
148 if (make_const)
149 follow_type = make_cv_type (make_const,
150 TYPE_VOLATILE (follow_type),
151 follow_type, 0);
152 if (make_volatile)
153 follow_type = make_cv_type (TYPE_CONST (follow_type),
154 make_volatile,
155 follow_type, 0);
156 if (make_addr_space)
157 follow_type = make_type_with_address_space (follow_type,
158 make_addr_space);
159 if (make_restrict)
160 follow_type = make_restrict_type (follow_type);
161 if (make_atomic)
162 follow_type = make_atomic_type (follow_type);
163 make_const = make_volatile = 0;
164 make_addr_space = 0;
165 make_restrict = make_atomic = false;
166 break;
167 case tp_array:
168 array_size = pop_int ();
169 /* FIXME-type-allocation: need a way to free this type when we are
170 done with it. */
171 follow_type =
172 lookup_array_range_type (follow_type,
173 0, array_size >= 0 ? array_size - 1 : 0);
174 if (array_size < 0)
175 TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (follow_type))
176 = PROP_UNDEFINED;
177 break;
178 case tp_function:
179 /* FIXME-type-allocation: need a way to free this type when we are
180 done with it. */
181 follow_type = lookup_function_type (follow_type);
182 break;
183
184 case tp_function_with_arguments:
185 {
186 std::vector<struct type *> *args = pop_typelist ();
187
188 follow_type
189 = lookup_function_type_with_arguments (follow_type,
190 args->size (),
191 args->data ());
192 }
193 break;
194
195 case tp_type_stack:
196 {
197 struct type_stack *stack = pop_type_stack ();
198 follow_type = stack->follow_types (follow_type);
199 }
200 break;
201 default:
202 gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
203 }
204 return follow_type;
205 }
This page took 0.033543 seconds and 4 git commands to generate.