* [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class
@ 2021-03-24 14:01 Simon Marchi
2021-03-24 14:01 ` [PATCH 2/4] gdb: remove TYPE_DECLARED_CLASS Simon Marchi
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Simon Marchi @ 2021-03-24 14:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Add the `is_declared_class` and `set_is_declared_class` methods on
`struct type`, in order to remove the `TYPE_DECLARED_CLASS` macro. In
this patch, the macro is changed to use the getter, so all the call
sites of the macro that are used as a setter are changed to use the
setter method directly. The next patch will remove the macro
completely.
gdb/ChangeLog:
* gdbtypes.h (struct type) <is_declared_class,
set_is_declared_class>: New methods.
(TYPE_DECLARED_CLASS): Use type::is_declared_class, change all
write call sites to use type::set_is_declared_class.
Change-Id: Idf08d32e137c885a0aba0a18f556a899c1cbfd68
---
gdb/dwarf2/read.c | 4 ++--
gdb/gdbtypes.h | 21 +++++++++++++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2bfb13d6d0e..43669df3cc8 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16145,7 +16145,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
}
if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
- TYPE_DECLARED_CLASS (type) = 1;
+ type->set_is_declared_class (true);
/* Store the calling convention in the type if it's available in
the die. Otherwise the calling convention remains set to
@@ -16759,7 +16759,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
set_type_align (type, TYPE_RAW_ALIGN (underlying_type));
}
- TYPE_DECLARED_CLASS (type) = dwarf2_flag_true_p (die, DW_AT_enum_class, cu);
+ type->set_is_declared_class (dwarf2_flag_true_p (die, DW_AT_enum_class, cu));
set_die_type (die, type, cu);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 45014a2b3e8..7444e7ad239 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -226,7 +226,7 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
enum types, this is true when "enum class" or "enum struct" was
used to declare the type.. */
-#define TYPE_DECLARED_CLASS(t) (TYPE_MAIN_TYPE (t)->flag_declared_class)
+#define TYPE_DECLARED_CLASS(t) ((t)->declared_class ())
/* * True if this type is a "flag" enum. A flag enum is one where all
the values are pairwise disjoint when "and"ed together. This
@@ -815,7 +815,7 @@ struct main_type
/* * True if this type was declared with "class" rather than
"struct". */
- unsigned int flag_declared_class : 1;
+ unsigned int m_flag_declared_class : 1;
/* * True if this is an enum type with disjoint values. This
affects how the enum is printed. */
@@ -1187,6 +1187,23 @@ struct type
this->main_type->m_flag_endianity_not_default = endianity_is_not_default;
}
+
+ /* True if this type was declared using the "class" keyword. This is
+ only valid for C++ structure and enum types. If false, a structure
+ was declared as a "struct"; if true it was declared "class". For
+ enum types, this is true when "enum class" or "enum struct" was
+ used to declare the type. */
+
+ bool is_declared_class () const
+ {
+ return this->main_type->m_flag_declared_class;
+ }
+
+ void set_is_declared_class (bool is_declared_class) const
+ {
+ this->main_type->m_flag_declared_class = is_declared_class;
+ }
+
/* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference
to this type's fixed_point_info. */
--
2.30.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] gdb: remove TYPE_DECLARED_CLASS
2021-03-24 14:01 [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Simon Marchi
@ 2021-03-24 14:01 ` Simon Marchi
2021-03-24 14:01 ` [PATCH 3/4] gdb: add type::is_flag_enum / type::set_is_flag_enum Simon Marchi
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-03-24 14:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
gdb/ChangeLog:
* gdbtypes.h (TYPE_DECLARED_CLASS): Remove, replace all uses
with type::is_declared_class.
Change-Id: Ifecb2342417ecd7bf570c3205344b09d706daab2
---
gdb/c-exp.y | 2 +-
gdb/c-typeprint.c | 8 ++++----
gdb/compile/compile-cplus-types.c | 6 +++---
gdb/d-exp.y | 2 +-
gdb/dwarf2/read.c | 2 +-
gdb/gdbtypes.c | 6 +++---
gdb/gdbtypes.h | 8 --------
gdb/valops.c | 2 +-
8 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index c0e4b494f3d..d6a2322dbf6 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1879,7 +1879,7 @@ type_aggregate_p (struct type *type)
|| type->code () == TYPE_CODE_UNION
|| type->code () == TYPE_CODE_NAMESPACE
|| (type->code () == TYPE_CODE_ENUM
- && TYPE_DECLARED_CLASS (type)));
+ && type->is_declared_class ()));
}
/* Validate a parameter typelist. */
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index b861aafbdc9..f81f1c2c113 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -965,7 +965,7 @@ output_access_specifier (struct ui_file *stream,
static bool
need_access_label_p (struct type *type)
{
- if (TYPE_DECLARED_CLASS (type))
+ if (type->is_declared_class ())
{
QUIT;
for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
@@ -1061,7 +1061,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
c_type_print_modifier (type, stream, 0, 1, language);
if (type->code () == TYPE_CODE_UNION)
fprintf_filtered (stream, "union ");
- else if (TYPE_DECLARED_CLASS (type))
+ else if (type->is_declared_class ())
fprintf_filtered (stream, "class ");
else
fprintf_filtered (stream, "struct ");
@@ -1499,7 +1499,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
fprintf_filtered (stream, "union ");
else if (type->code () == TYPE_CODE_STRUCT)
{
- if (TYPE_DECLARED_CLASS (type))
+ if (type->is_declared_class ())
fprintf_filtered (stream, "class ");
else
fprintf_filtered (stream, "struct ");
@@ -1552,7 +1552,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
case TYPE_CODE_ENUM:
c_type_print_modifier (type, stream, 0, 1, language);
fprintf_filtered (stream, "enum ");
- if (TYPE_DECLARED_CLASS (type))
+ if (type->is_declared_class ())
fprintf_filtered (stream, "class ");
/* Print the tag name if it exists.
The aCC compiler emits a spurious
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index d666ac3a83e..71ad6791e1d 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -91,7 +91,7 @@ get_method_access_flag (const struct type *type, int fni, int num)
gdb_assert (type->code () == TYPE_CODE_STRUCT);
/* If this type was not declared a class, everything is public. */
- if (!TYPE_DECLARED_CLASS (type))
+ if (!type->is_declared_class ())
return GCC_CP_ACCESS_PUBLIC;
/* Otherwise, read accessibility from the fn_field. */
@@ -828,11 +828,11 @@ compile_cplus_convert_struct_or_union (compile_cplus_instance *instance,
gcc_decl resuld;
if (type->code () == TYPE_CODE_STRUCT)
{
- const char *what = TYPE_DECLARED_CLASS (type) ? "struct" : "class";
+ const char *what = type->is_declared_class () ? "class" : "struct";
resuld = instance->plugin ().build_decl
(what, name.get (), (GCC_CP_SYMBOL_CLASS | nested_access
- | (TYPE_DECLARED_CLASS (type)
+ | (type->is_declared_class ()
? GCC_CP_FLAG_CLASS_NOFLAG
: GCC_CP_FLAG_CLASS_IS_STRUCT)),
0, nullptr, 0, filename, line);
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 90c342e0e21..20884baebba 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -640,7 +640,7 @@ type_aggregate_p (struct type *type)
|| type->code () == TYPE_CODE_UNION
|| type->code () == TYPE_CODE_MODULE
|| (type->code () == TYPE_CODE_ENUM
- && TYPE_DECLARED_CLASS (type)));
+ && type->is_declared_class ()));
}
/* Take care of parsing a number (anything that starts with a digit).
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 43669df3cc8..774fe14914e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -23305,7 +23305,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
return determine_prefix (parent, cu);
case DW_TAG_enumeration_type:
parent_type = read_type_die (parent, cu);
- if (TYPE_DECLARED_CLASS (parent_type))
+ if (parent_type->is_declared_class ())
{
if (parent_type->name () != NULL)
return parent_type->name ();
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1b2d4836959..5a20e7e16ca 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4507,7 +4507,7 @@ rank_one_type_parm_int (struct type *parm, struct type *arg, struct value *value
case TYPE_CODE_CHAR:
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
- if (TYPE_DECLARED_CLASS (arg))
+ if (arg->is_declared_class ())
return INCOMPATIBLE_TYPE_BADNESS;
return INTEGER_PROMOTION_BADNESS;
case TYPE_CODE_FLT:
@@ -4531,7 +4531,7 @@ rank_one_type_parm_enum (struct type *parm, struct type *arg, struct value *valu
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
case TYPE_CODE_ENUM:
- if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg))
+ if (parm->is_declared_class () || arg->is_declared_class ())
return INCOMPATIBLE_TYPE_BADNESS;
return INTEGER_CONVERSION_BADNESS;
case TYPE_CODE_FLT:
@@ -4551,7 +4551,7 @@ rank_one_type_parm_char (struct type *parm, struct type *arg, struct value *valu
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
case TYPE_CODE_ENUM:
- if (TYPE_DECLARED_CLASS (arg))
+ if (arg->is_declared_class ())
return INCOMPATIBLE_TYPE_BADNESS;
return INTEGER_CONVERSION_BADNESS;
case TYPE_CODE_FLT:
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 7444e7ad239..9677d068ee1 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -220,14 +220,6 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
#define TYPE_NOTTEXT(t) (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
-/* * True if this type was declared using the "class" keyword. This is
- only valid for C++ structure and enum types. If false, a structure
- was declared as a "struct"; if true it was declared "class". For
- enum types, this is true when "enum class" or "enum struct" was
- used to declare the type.. */
-
-#define TYPE_DECLARED_CLASS(t) ((t)->declared_class ())
-
/* * True if this type is a "flag" enum. A flag enum is one where all
the values are pairwise disjoint when "and"ed together. This
affects how enum values are printed. */
diff --git a/gdb/valops.c b/gdb/valops.c
index fec821ad932..d22c8c0a2e6 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3312,7 +3312,7 @@ enum_constant_from_type (struct type *type, const char *name)
int name_len = strlen (name);
gdb_assert (type->code () == TYPE_CODE_ENUM
- && TYPE_DECLARED_CLASS (type));
+ && type->is_declared_class ());
for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); ++i)
{
--
2.30.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] gdb: add type::is_flag_enum / type::set_is_flag_enum
2021-03-24 14:01 [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Simon Marchi
2021-03-24 14:01 ` [PATCH 2/4] gdb: remove TYPE_DECLARED_CLASS Simon Marchi
@ 2021-03-24 14:01 ` Simon Marchi
2021-03-24 14:01 ` [PATCH 4/4] gdb: remove TYPE_FLAG_ENUM Simon Marchi
2021-04-01 18:04 ` [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Tom Tromey
3 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-03-24 14:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Add the `is_flag_enum` and `set_is_flag_enum` methods on `struct type`,
in order to remove the `TYPE_FLAG_ENUM` macro. In this patch, the macro
is changed to use the getter, so all the call sites of the macro that
are used as a setter are changed to use the setter method directly. The
next patch will remove the macro completely.
gdb/ChangeLog:
* gdbtypes.h (struct type) <is_flag_enum,
set_is_flag_enum>: New methods.
(TYPE_FLAG_ENUM): Use type::is_flag_enum, change all
write call sites to use type::set_is_flag_enum.
Change-Id: I9c56c91626c8d784947ba94fcb97818526b81d1c
---
gdb/dwarf2/read.c | 2 +-
gdb/gdbtypes.h | 22 ++++++++++++++++------
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 774fe14914e..be364bfed83 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16675,7 +16675,7 @@ update_enumeration_type_from_children (struct die_info *die,
type->set_is_unsigned (true);
if (flag_enum)
- TYPE_FLAG_ENUM (type) = 1;
+ type->set_is_flag_enum (true);
}
/* Given a DW_AT_enumeration_type die, set its type. We do not
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 9677d068ee1..52c17532692 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -220,11 +220,7 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
#define TYPE_NOTTEXT(t) (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
-/* * True if this type is a "flag" enum. A flag enum is one where all
- the values are pairwise disjoint when "and"ed together. This
- affects how enum values are printed. */
-
-#define TYPE_FLAG_ENUM(t) (TYPE_MAIN_TYPE (t)->flag_flag_enum)
+#define TYPE_FLAG_ENUM(t) ((t)->is_flag_enum ())
/* * Constant type. If this is set, the corresponding type has a
const modifier. */
@@ -812,7 +808,7 @@ struct main_type
/* * True if this is an enum type with disjoint values. This
affects how the enum is printed. */
- unsigned int flag_flag_enum : 1;
+ unsigned int m_flag_flag_enum : 1;
/* * A discriminant telling us which field of the type_specific
union is being used for this type, if any. */
@@ -1196,6 +1192,20 @@ struct type
this->main_type->m_flag_declared_class = is_declared_class;
}
+ /* True if this type is a "flag" enum. A flag enum is one where all
+ the values are pairwise disjoint when "and"ed together. This
+ affects how enum values are printed. */
+
+ bool is_flag_enum () const
+ {
+ return this->main_type->m_flag_flag_enum;
+ }
+
+ void set_is_flag_enum (bool is_flag_enum)
+ {
+ this->main_type->m_flag_flag_enum = is_flag_enum;
+ }
+
/* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference
to this type's fixed_point_info. */
--
2.30.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] gdb: remove TYPE_FLAG_ENUM
2021-03-24 14:01 [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Simon Marchi
2021-03-24 14:01 ` [PATCH 2/4] gdb: remove TYPE_DECLARED_CLASS Simon Marchi
2021-03-24 14:01 ` [PATCH 3/4] gdb: add type::is_flag_enum / type::set_is_flag_enum Simon Marchi
@ 2021-03-24 14:01 ` Simon Marchi
2021-04-01 18:04 ` [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Tom Tromey
3 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-03-24 14:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
gdb/ChangeLog:
* gdbtypes.h (TYPE_FLAG_ENUM): Remove, replace all uses
with type::is_flag_enum.
Change-Id: I74e23893066eecd6df641045b859a6d6ebb13dd0
---
gdb/gdbtypes.h | 2 --
gdb/valprint.c | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 52c17532692..bb4d26eef1a 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -220,8 +220,6 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
#define TYPE_NOTTEXT(t) (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
-#define TYPE_FLAG_ENUM(t) ((t)->is_flag_enum ())
-
/* * Constant type. If this is set, the corresponding type has a
const modifier. */
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 340a329f9d0..102fcad59ca 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -603,7 +603,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
fputs_styled (TYPE_FIELD_NAME (type, i), variable_name_style.style (),
stream);
}
- else if (TYPE_FLAG_ENUM (type))
+ else if (type->is_flag_enum ())
{
int first = 1;
--
2.30.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class
2021-03-24 14:01 [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Simon Marchi
` (2 preceding siblings ...)
2021-03-24 14:01 ` [PATCH 4/4] gdb: remove TYPE_FLAG_ENUM Simon Marchi
@ 2021-04-01 18:04 ` Tom Tromey
2021-04-02 1:14 ` Simon Marchi
3 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2021-04-01 18:04 UTC (permalink / raw)
To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
Simon> Add the `is_declared_class` and `set_is_declared_class` methods on
Simon> `struct type`, in order to remove the `TYPE_DECLARED_CLASS` macro. In
Simon> this patch, the macro is changed to use the getter, so all the call
Simon> sites of the macro that are used as a setter are changed to use the
Simon> setter method directly. The next patch will remove the macro
Simon> completely.
Simon> gdb/ChangeLog:
Simon> * gdbtypes.h (struct type) <is_declared_class,
set_is_declared_class> : New methods.
Simon> (TYPE_DECLARED_CLASS): Use type::is_declared_class, change all
Simon> write call sites to use type::set_is_declared_class.
I skimmed through this series and all four of these look reasonable to me.
Thank you.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class
2021-04-01 18:04 ` [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Tom Tromey
@ 2021-04-02 1:14 ` Simon Marchi
0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-04-02 1:14 UTC (permalink / raw)
To: Tom Tromey, Simon Marchi via Gdb-patches
On 2021-04-01 2:04 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Simon> Add the `is_declared_class` and `set_is_declared_class` methods on
> Simon> `struct type`, in order to remove the `TYPE_DECLARED_CLASS` macro. In
> Simon> this patch, the macro is changed to use the getter, so all the call
> Simon> sites of the macro that are used as a setter are changed to use the
> Simon> setter method directly. The next patch will remove the macro
> Simon> completely.
>
> Simon> gdb/ChangeLog:
>
> Simon> * gdbtypes.h (struct type) <is_declared_class,
> set_is_declared_class> : New methods.
> Simon> (TYPE_DECLARED_CLASS): Use type::is_declared_class, change all
> Simon> write call sites to use type::set_is_declared_class.
>
> I skimmed through this series and all four of these look reasonable to me.
> Thank you.
>
> Tom
>
Thanks, pushed.
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-04-02 1:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 14:01 [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Simon Marchi
2021-03-24 14:01 ` [PATCH 2/4] gdb: remove TYPE_DECLARED_CLASS Simon Marchi
2021-03-24 14:01 ` [PATCH 3/4] gdb: add type::is_flag_enum / type::set_is_flag_enum Simon Marchi
2021-03-24 14:01 ` [PATCH 4/4] gdb: remove TYPE_FLAG_ENUM Simon Marchi
2021-04-01 18:04 ` [PATCH 1/4] gdb: add type::is_declared_class / type::set_is_declared_class Tom Tromey
2021-04-02 1:14 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).