mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-14 20:46:12 +08:00

A later patch in this series will rewrite enum_flags fixing some API holes. That would cause build failures around code using type_instance_flags. Or rather, that should be using it, but wasn't. This patch fixes it by using type_instance_flags throughout instead of plain integers. Note that we can't make the seemingly obvious change to struct type::instance_flags: - unsigned instance_flags : 9; + ENUM_BITFIELD (type_instance_flag_value) instance_flags : 9; Because G++ complains then that 9 bits isn't sufficient for holding all values of type_instance_flag_value. So the patch adds an type::instance_flags() method, which takes care of casting appropriately, and adds a separate type::set_instance_flags method, following the pattern of the ongoing TYPE_XXX macro elimination. This converts uses of TYPE_INSTANCE_FLAGS to type::instance_flags() in the places where the code was already being touched, but there are still many references to the TYPE_INSTANCE_FLAGS macro left behind. Those could/should be fully replaced at some point. gdb/ChangeLog: * avr-tdep.c (avr_address_class_type_flags): Return type_instance_flags. (avr_address_class_type_flags_to_name): Take a type_instance_flags. (avr_address_class_name_to_type_flags): Return bool and take a type_instance_flags. * d-lang.c (build_d_types): Use type::set_instance_flags. * ft32-tdep.c (ft32_address_class_type_flags): Return type_instance_flags. (ft32_address_class_type_flags_to_name): Take a type_instance_flags. (ft32_address_class_name_to_type_flags): Return bool and take a type_instance_flags. (ft32_gdbarch_init): Use type::set_instance_flags. * eval.c (fake_method::fake_method): Use type::set_instance_flags. * gdbarch.h, gdbarch.c: Regenerate. * gdbarch.sh (address_class_type_flags): Use type_instance_flags. (address_class_name_to_type_flags): Use type_instance_flags and bool. * gdbtypes.c (address_space_name_to_int) (address_space_int_to_name, make_qualified_type): Use type_instance_flags. (make_qualified_type): Use type_instance_flags and type::set_instance_flags. (make_type_with_address_space, make_cv_type, make_vector_type) (check_typedef): Use type_instance_flags. (recursive_dump_type): Cast type_instance_flags to unsigned for printing. (copy_type_recursive): Use type::set_instance_flags. (gdbtypes_post_init): Use type::set_instance_flags. * gdbtypes.h (struct type) <instance_flags>: Rename to ... <m_instance_flags>: ... this. <instance_flags, set_instance_flags>: New methods. (TYPE_INSTANCE_FLAGS): Use the instance_flags method. (SET_TYPE_INSTANCE_FLAGS): New. (address_space_name_to_int, address_space_int_to_name) (make_type_with_address_space): Pass flags using type_instance_flags instead of int. * stabsread.c (cleanup_undefined_types_noname): Use type::set_instance_flags. * s390-tdep.c (s390_address_class_type_flags): Return type_instance_flags. (s390_address_class_type_flags_to_name): Take a type_instance_flags. (s390_address_class_name_to_type_flags): Return bool and take a type_instance_flags. * type-stack.c (type_stack::follow_types): Use type_instance_flags. * dwarf2/read.c (read_tag_pointer_type): Use type_instance_flags.
205 lines
5.2 KiB
C
205 lines
5.2 KiB
C
/* Type stack for GDB parser.
|
|
|
|
Copyright (C) 1986-2020 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "defs.h"
|
|
#include "type-stack.h"
|
|
|
|
#include "gdbtypes.h"
|
|
#include "parser-defs.h"
|
|
|
|
/* See type-stack.h. */
|
|
|
|
void
|
|
type_stack::insert (enum type_pieces tp)
|
|
{
|
|
union type_stack_elt element;
|
|
int slot;
|
|
|
|
gdb_assert (tp == tp_pointer || tp == tp_reference
|
|
|| tp == tp_rvalue_reference || tp == tp_const
|
|
|| tp == tp_volatile || tp == tp_restrict
|
|
|| tp == tp_atomic);
|
|
|
|
/* If there is anything on the stack (we know it will be a
|
|
tp_pointer), insert the qualifier above it. Otherwise, simply
|
|
push this on the top of the stack. */
|
|
if (!m_elements.empty () && (tp == tp_const || tp == tp_volatile
|
|
|| tp == tp_restrict))
|
|
slot = 1;
|
|
else
|
|
slot = 0;
|
|
|
|
element.piece = tp;
|
|
insert_into (slot, element);
|
|
}
|
|
|
|
/* See type-stack.h. */
|
|
|
|
void
|
|
type_stack::insert (struct expr_builder *pstate, const char *string)
|
|
{
|
|
union type_stack_elt element;
|
|
int slot;
|
|
|
|
/* If there is anything on the stack (we know it will be a
|
|
tp_pointer), insert the address space qualifier above it.
|
|
Otherwise, simply push this on the top of the stack. */
|
|
if (!m_elements.empty ())
|
|
slot = 1;
|
|
else
|
|
slot = 0;
|
|
|
|
element.piece = tp_space_identifier;
|
|
insert_into (slot, element);
|
|
element.int_val = address_space_name_to_int (pstate->gdbarch (),
|
|
string);
|
|
insert_into (slot, element);
|
|
}
|
|
|
|
/* See type-stack.h. */
|
|
|
|
type_instance_flags
|
|
type_stack::follow_type_instance_flags ()
|
|
{
|
|
type_instance_flags flags = 0;
|
|
|
|
for (;;)
|
|
switch (pop ())
|
|
{
|
|
case tp_end:
|
|
return flags;
|
|
case tp_const:
|
|
flags |= TYPE_INSTANCE_FLAG_CONST;
|
|
break;
|
|
case tp_volatile:
|
|
flags |= TYPE_INSTANCE_FLAG_VOLATILE;
|
|
break;
|
|
case tp_atomic:
|
|
flags |= TYPE_INSTANCE_FLAG_ATOMIC;
|
|
break;
|
|
case tp_restrict:
|
|
flags |= TYPE_INSTANCE_FLAG_RESTRICT;
|
|
break;
|
|
default:
|
|
gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
|
|
}
|
|
}
|
|
|
|
/* See type-stack.h. */
|
|
|
|
struct type *
|
|
type_stack::follow_types (struct type *follow_type)
|
|
{
|
|
int done = 0;
|
|
int make_const = 0;
|
|
int make_volatile = 0;
|
|
type_instance_flags make_addr_space = 0;
|
|
bool make_restrict = false;
|
|
bool make_atomic = false;
|
|
int array_size;
|
|
|
|
while (!done)
|
|
switch (pop ())
|
|
{
|
|
case tp_end:
|
|
done = 1;
|
|
goto process_qualifiers;
|
|
break;
|
|
case tp_const:
|
|
make_const = 1;
|
|
break;
|
|
case tp_volatile:
|
|
make_volatile = 1;
|
|
break;
|
|
case tp_space_identifier:
|
|
make_addr_space = (enum type_instance_flag_value) pop_int ();
|
|
break;
|
|
case tp_atomic:
|
|
make_atomic = true;
|
|
break;
|
|
case tp_restrict:
|
|
make_restrict = true;
|
|
break;
|
|
case tp_pointer:
|
|
follow_type = lookup_pointer_type (follow_type);
|
|
goto process_qualifiers;
|
|
case tp_reference:
|
|
follow_type = lookup_lvalue_reference_type (follow_type);
|
|
goto process_qualifiers;
|
|
case tp_rvalue_reference:
|
|
follow_type = lookup_rvalue_reference_type (follow_type);
|
|
process_qualifiers:
|
|
if (make_const)
|
|
follow_type = make_cv_type (make_const,
|
|
TYPE_VOLATILE (follow_type),
|
|
follow_type, 0);
|
|
if (make_volatile)
|
|
follow_type = make_cv_type (TYPE_CONST (follow_type),
|
|
make_volatile,
|
|
follow_type, 0);
|
|
if (make_addr_space)
|
|
follow_type = make_type_with_address_space (follow_type,
|
|
make_addr_space);
|
|
if (make_restrict)
|
|
follow_type = make_restrict_type (follow_type);
|
|
if (make_atomic)
|
|
follow_type = make_atomic_type (follow_type);
|
|
make_const = make_volatile = 0;
|
|
make_addr_space = 0;
|
|
make_restrict = make_atomic = false;
|
|
break;
|
|
case tp_array:
|
|
array_size = pop_int ();
|
|
/* FIXME-type-allocation: need a way to free this type when we are
|
|
done with it. */
|
|
follow_type =
|
|
lookup_array_range_type (follow_type,
|
|
0, array_size >= 0 ? array_size - 1 : 0);
|
|
if (array_size < 0)
|
|
follow_type->bounds ()->high.set_undefined ();
|
|
break;
|
|
case tp_function:
|
|
/* FIXME-type-allocation: need a way to free this type when we are
|
|
done with it. */
|
|
follow_type = lookup_function_type (follow_type);
|
|
break;
|
|
|
|
case tp_function_with_arguments:
|
|
{
|
|
std::vector<struct type *> *args = pop_typelist ();
|
|
|
|
follow_type
|
|
= lookup_function_type_with_arguments (follow_type,
|
|
args->size (),
|
|
args->data ());
|
|
}
|
|
break;
|
|
|
|
case tp_type_stack:
|
|
{
|
|
struct type_stack *stack = pop_type_stack ();
|
|
follow_type = stack->follow_types (follow_type);
|
|
}
|
|
break;
|
|
default:
|
|
gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
|
|
}
|
|
return follow_type;
|
|
}
|