GDB (xrefs)
Loading...
Searching...
No Matches
type-stack.c
Go to the documentation of this file.
1/* Type stack for GDB parser.
2
3 Copyright (C) 1986-2023 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
28void
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
54void
55type_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
72 string);
73 insert_into (slot, element);
74}
75
76/* See type-stack.h. */
77
78type_instance_flags
80{
81 type_instance_flags flags = 0;
82
83 for (;;)
84 switch (pop ())
85 {
86 case tp_end:
87 return flags;
88 case tp_const:
90 break;
91 case tp_volatile:
93 break;
94 case tp_atomic:
96 break;
97 case tp_restrict:
99 break;
100 default:
101 gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
102 }
103}
104
105/* See type-stack.h. */
106
107struct type *
108type_stack::follow_types (struct type *follow_type)
109{
110 int done = 0;
111 int make_const = 0;
112 int make_volatile = 0;
113 type_instance_flags make_addr_space = 0;
114 bool make_restrict = false;
115 bool make_atomic = false;
116 int array_size;
117
118 while (!done)
119 switch (pop ())
120 {
121 case tp_end:
122 done = 1;
123 goto process_qualifiers;
124 break;
125 case tp_const:
126 make_const = 1;
127 break;
128 case tp_volatile:
129 make_volatile = 1;
130 break;
132 make_addr_space = (enum type_instance_flag_value) pop_int ();
133 break;
134 case tp_atomic:
135 make_atomic = true;
136 break;
137 case tp_restrict:
138 make_restrict = true;
139 break;
140 case tp_pointer:
141 follow_type = lookup_pointer_type (follow_type);
142 goto process_qualifiers;
143 case tp_reference:
144 follow_type = lookup_lvalue_reference_type (follow_type);
145 goto process_qualifiers;
147 follow_type = lookup_rvalue_reference_type (follow_type);
148 process_qualifiers:
149 if (make_const)
150 follow_type = make_cv_type (make_const,
151 TYPE_VOLATILE (follow_type),
152 follow_type, 0);
153 if (make_volatile)
154 follow_type = make_cv_type (TYPE_CONST (follow_type),
155 make_volatile,
156 follow_type, 0);
157 if (make_addr_space)
158 follow_type = make_type_with_address_space (follow_type,
159 make_addr_space);
160 if (make_restrict)
161 follow_type = make_restrict_type (follow_type);
162 if (make_atomic)
163 follow_type = make_atomic_type (follow_type);
164 make_const = make_volatile = 0;
165 make_addr_space = 0;
166 make_restrict = make_atomic = false;
167 break;
168 case tp_array:
169 array_size = pop_int ();
170 /* FIXME-type-allocation: need a way to free this type when we are
171 done with it. */
172 follow_type =
173 lookup_array_range_type (follow_type,
174 0, array_size >= 0 ? array_size - 1 : 0);
175 if (array_size < 0)
176 follow_type->bounds ()->high.set_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
185 {
186 std::vector<struct type *> *args = pop_typelist ();
187
188 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}
static struct parser_state * pstate
Definition ada-exp.c:101
struct type * make_restrict_type(struct type *type)
Definition gdbtypes.c:785
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:430
struct type * lookup_lvalue_reference_type(struct type *type)
Definition gdbtypes.c:518
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
Definition gdbtypes.c:1397
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
Definition gdbtypes.c:740
struct type * lookup_function_type(struct type *type)
Definition gdbtypes.c:567
struct type * lookup_function_type_with_arguments(struct type *type, int nparams, struct type **param_types)
Definition gdbtypes.c:577
struct type * make_type_with_address_space(struct type *type, type_instance_flags space_flag)
Definition gdbtypes.c:715
struct type * lookup_rvalue_reference_type(struct type *type)
Definition gdbtypes.c:526
struct type * make_atomic_type(struct type *type)
Definition gdbtypes.c:809
type_instance_flags address_space_name_to_type_instance_flags(struct gdbarch *gdbarch, const char *space_identifier)
Definition gdbtypes.c:614
type_instance_flag_value
Definition gdbtypes.h:95
@ TYPE_INSTANCE_FLAG_CONST
Definition gdbtypes.h:96
@ TYPE_INSTANCE_FLAG_VOLATILE
Definition gdbtypes.h:97
@ TYPE_INSTANCE_FLAG_ATOMIC
Definition gdbtypes.h:104
@ TYPE_INSTANCE_FLAG_RESTRICT
Definition gdbtypes.h:103
#define TYPE_CONST(t)
Definition gdbtypes.h:117
#define TYPE_VOLATILE(t)
Definition gdbtypes.h:122
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
void set_undefined()
Definition gdbtypes.h:325
struct gdbarch * gdbarch()
Definition parser-defs.h:59
struct dynamic_prop high
Definition gdbtypes.h:721
struct type_stack * pop_type_stack()
Definition type-stack.h:150
type_instance_flags follow_type_instance_flags()
Definition type-stack.c:79
std::vector< union type_stack_elt > m_elements
Definition type-stack.h:203
void insert_into(int slot, union type_stack_elt element)
Definition type-stack.h:195
struct type * follow_types(struct type *follow_type)
Definition type-stack.c:108
std::vector< struct type * > * pop_typelist()
Definition type-stack.h:140
enum type_pieces pop()
Definition type-stack.h:119
void insert(enum type_pieces tp)
Definition type-stack.c:29
int pop_int()
Definition type-stack.h:128
range_bounds * bounds() const
Definition gdbtypes.h:1065
type_pieces
Definition type-stack.h:32
@ tp_function
Definition type-stack.h:38
@ tp_const
Definition type-stack.h:40
@ tp_space_identifier
Definition type-stack.h:42
@ tp_rvalue_reference
Definition type-stack.h:36
@ tp_volatile
Definition type-stack.h:41
@ tp_array
Definition type-stack.h:37
@ tp_pointer
Definition type-stack.h:34
@ tp_function_with_arguments
Definition type-stack.h:39
@ tp_reference
Definition type-stack.h:35
@ tp_type_stack
Definition type-stack.h:45
@ tp_atomic
Definition type-stack.h:43
@ tp_end
Definition type-stack.h:33
@ tp_restrict
Definition type-stack.h:44
enum type_pieces piece
Definition type-stack.h:52