[PATCH 30/57][Arm][GAS] Add support for MVE instructions: vqmovnt, vqmovnb, vqmovunt...
[binutils-gdb.git] / gdb / type-stack.c
blob7c2a7046ca24c70c5aa7b2ee5012b39a318447e5
1 /* Type stack for GDB parser.
3 Copyright (C) 1986-2019 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 "defs.h"
21 #include "type-stack.h"
23 #include "gdbtypes.h"
24 #include "parser-defs.h"
26 /* See type-stack.h. */
28 void
29 type_stack::insert (enum type_pieces tp)
31 union type_stack_elt element;
32 int slot;
34 gdb_assert (tp == tp_pointer || tp == tp_reference
35 || tp == tp_rvalue_reference || tp == tp_const
36 || tp == tp_volatile);
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 slot = 1;
43 else
44 slot = 0;
46 element.piece = tp;
47 insert_into (slot, element);
50 /* See type-stack.h. */
52 void
53 type_stack::insert (struct expr_builder *pstate, const char *string)
55 union type_stack_elt element;
56 int slot;
58 /* If there is anything on the stack (we know it will be a
59 tp_pointer), insert the address space qualifier above it.
60 Otherwise, simply push this on the top of the stack. */
61 if (!m_elements.empty ())
62 slot = 1;
63 else
64 slot = 0;
66 element.piece = tp_space_identifier;
67 insert_into (slot, element);
68 element.int_val = address_space_name_to_int (pstate->gdbarch (),
69 string);
70 insert_into (slot, element);
73 /* See type-stack.h. */
75 type_instance_flags
76 type_stack::follow_type_instance_flags ()
78 type_instance_flags flags = 0;
80 for (;;)
81 switch (pop ())
83 case tp_end:
84 return flags;
85 case tp_const:
86 flags |= TYPE_INSTANCE_FLAG_CONST;
87 break;
88 case tp_volatile:
89 flags |= TYPE_INSTANCE_FLAG_VOLATILE;
90 break;
91 default:
92 gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
96 /* See type-stack.h. */
98 struct type *
99 type_stack::follow_types (struct type *follow_type)
101 int done = 0;
102 int make_const = 0;
103 int make_volatile = 0;
104 int make_addr_space = 0;
105 int array_size;
107 while (!done)
108 switch (pop ())
110 case tp_end:
111 done = 1;
112 if (make_const)
113 follow_type = make_cv_type (make_const,
114 TYPE_VOLATILE (follow_type),
115 follow_type, 0);
116 if (make_volatile)
117 follow_type = make_cv_type (TYPE_CONST (follow_type),
118 make_volatile,
119 follow_type, 0);
120 if (make_addr_space)
121 follow_type = make_type_with_address_space (follow_type,
122 make_addr_space);
123 make_const = make_volatile = 0;
124 make_addr_space = 0;
125 break;
126 case tp_const:
127 make_const = 1;
128 break;
129 case tp_volatile:
130 make_volatile = 1;
131 break;
132 case tp_space_identifier:
133 make_addr_space = pop_int ();
134 break;
135 case tp_pointer:
136 follow_type = lookup_pointer_type (follow_type);
137 if (make_const)
138 follow_type = make_cv_type (make_const,
139 TYPE_VOLATILE (follow_type),
140 follow_type, 0);
141 if (make_volatile)
142 follow_type = make_cv_type (TYPE_CONST (follow_type),
143 make_volatile,
144 follow_type, 0);
145 if (make_addr_space)
146 follow_type = make_type_with_address_space (follow_type,
147 make_addr_space);
148 make_const = make_volatile = 0;
149 make_addr_space = 0;
150 break;
151 case tp_reference:
152 follow_type = lookup_lvalue_reference_type (follow_type);
153 goto process_reference;
154 case tp_rvalue_reference:
155 follow_type = lookup_rvalue_reference_type (follow_type);
156 process_reference:
157 if (make_const)
158 follow_type = make_cv_type (make_const,
159 TYPE_VOLATILE (follow_type),
160 follow_type, 0);
161 if (make_volatile)
162 follow_type = make_cv_type (TYPE_CONST (follow_type),
163 make_volatile,
164 follow_type, 0);
165 if (make_addr_space)
166 follow_type = make_type_with_address_space (follow_type,
167 make_addr_space);
168 make_const = make_volatile = 0;
169 make_addr_space = 0;
170 break;
171 case tp_array:
172 array_size = pop_int ();
173 /* FIXME-type-allocation: need a way to free this type when we are
174 done with it. */
175 follow_type =
176 lookup_array_range_type (follow_type,
177 0, array_size >= 0 ? array_size - 1 : 0);
178 if (array_size < 0)
179 TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (follow_type))
180 = PROP_UNDEFINED;
181 break;
182 case tp_function:
183 /* FIXME-type-allocation: need a way to free this type when we are
184 done with it. */
185 follow_type = lookup_function_type (follow_type);
186 break;
188 case tp_function_with_arguments:
190 std::vector<struct type *> *args = pop_typelist ();
192 follow_type
193 = lookup_function_type_with_arguments (follow_type,
194 args->size (),
195 args->data ());
197 break;
199 case tp_type_stack:
201 struct type_stack *stack = pop_type_stack ();
202 follow_type = stack->follow_types (follow_type);
204 break;
205 default:
206 gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
208 return follow_type;