From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id EFFAB386F81D for ; Sun, 15 Nov 2020 08:49:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EFFAB386F81D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=brobecke@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D07E756061; Sun, 15 Nov 2020 03:49:53 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id joeN7qmgTs1d; Sun, 15 Nov 2020 03:49:53 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id C0C2956053; Sun, 15 Nov 2020 03:49:53 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id BDA53111; Sun, 15 Nov 2020 03:49:53 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Simon Marchi , Joel Brobecker Subject: [RFA 4/6] Make fixed_point_type_base_type a method of struct type Date: Sun, 15 Nov 2020 03:49:42 -0500 Message-Id: <1605430184-81335-5-git-send-email-brobecker@adacore.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1605430184-81335-1-git-send-email-brobecker@adacore.com> References: <1604817017-25807-1-git-send-email-brobecker@adacore.com> <1605430184-81335-1-git-send-email-brobecker@adacore.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Nov 2020 08:49:55 -0000 As suggested by Simon, to logically connect this function to the object it inspects. Note that, logically, this method should be "const". Unfortunately, the implementation iterates on struct type objects starting with "this", and thus trying to declare the method "const" triggers a compilation error. gdb/ChangeLog: * gdbtypes.h (struct type) New method, replacing the fixed_point_type_base_type function. All callers updated throughout this project. (fixed_point_type_base_type): Remove declaration. * gdbtypes.c (type::fixed_point_type_base_type): Replaces fixed_point_type_base_type. Adjust implementation accordingly. --- gdb/ada-valprint.c | 2 +- gdb/gdbtypes.c | 6 ++++-- gdb/gdbtypes.h | 17 +++++++++-------- gdb/valprint.c | 2 +- gdb/value.c | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 482069a..6ddb584 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -1028,7 +1028,7 @@ ada_value_print_1 (struct value *val, struct ui_file *stream, int recurse, } if (is_fixed_point_type (type)) - type = fixed_point_type_base_type (type); + type = type->fixed_point_type_base_type (); switch (type->code ()) { diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 255d9e3..eb176c9 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -5861,8 +5861,10 @@ is_fixed_point_type (struct type *type) /* See gdbtypes.h. */ struct type * -fixed_point_type_base_type (struct type *type) +type::fixed_point_type_base_type () { + struct type *type = this; + while (check_typedef (type)->code () == TYPE_CODE_RANGE) type = TYPE_TARGET_TYPE (check_typedef (type)); type = check_typedef (type); @@ -5876,7 +5878,7 @@ fixed_point_type_base_type (struct type *type) const gdb_mpq & fixed_point_scaling_factor (struct type *type) { - type = fixed_point_type_base_type (type); + type = type->fixed_point_type_base_type (); return type->fixed_point_info ().scaling_factor; } diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index b05d000..19f95f4 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1215,6 +1215,15 @@ struct type this->main_type->type_specific.fixed_point_info = info; } + /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its base type. + + In other words, this returns the type after having peeled all + intermediate type layers (such as TYPE_CODE_RANGE, for instance). + The TYPE_CODE of the type returned is guaranteed to be + a TYPE_CODE_FIXED_POINT. */ + + struct type *fixed_point_type_base_type (); + /* * Return the dynamic property of the requested KIND from this type's list of dynamic properties. */ dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const; @@ -2580,14 +2589,6 @@ extern int type_not_associated (const struct type *type); a range type whose base type is a TYPE_CODE_FIXED_POINT. */ extern bool is_fixed_point_type (struct type *type); -/* Assuming that TYPE is a fixed point type, return its base type. - - In other words, this returns the type after having peeled all - intermediate type layers (such as TYPE_CODE_RANGE, for instance). - The TYPE_CODE of the type returned is guaranteed to be - a TYPE_CODE_FIXED_POINT. */ -extern struct type *fixed_point_type_base_type (struct type *type); - /* Given TYPE, which is a fixed point type, return its scaling factor. */ extern const gdb_mpq &fixed_point_scaling_factor (struct type *type); diff --git a/gdb/valprint.c b/gdb/valprint.c index 21a4bf4..66f8de9 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -872,7 +872,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse, type = check_typedef (type); if (is_fixed_point_type (type)) - type = fixed_point_type_base_type (type); + type = type->fixed_point_type_base_type (); switch (type->code ()) { diff --git a/gdb/value.c b/gdb/value.c index 7444e79..f3f5169 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -2759,7 +2759,7 @@ LONGEST unpack_long (struct type *type, const gdb_byte *valaddr) { if (is_fixed_point_type (type)) - type = fixed_point_type_base_type (type); + type = type->fixed_point_type_base_type (); enum bfd_endian byte_order = type_byte_order (type); enum type_code code = type->code (); -- 2.1.4