From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Rewrite Validated_View in recursive style
Date: Wed, 30 Jun 2021 05:30:45 -0400 [thread overview]
Message-ID: <20210630093045.GA341@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 393 bytes --]
Iteration with an artificial Continue flag in routine Validated_View was
confusing. Also, most of the routines that traverse type hierarchies are
written in recursive style.
Cleanup only; semantics is unaffected.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_util.ads (Validated_View): Fix style in comment.
* sem_util.adb (Validated_View): Rewrite in recursive style.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2713 bytes --]
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -29471,42 +29471,36 @@ package body Sem_Util is
--------------------
function Validated_View (Typ : Entity_Id) return Entity_Id is
- Continue : Boolean;
- Val_Typ : Entity_Id;
-
begin
- Continue := True;
- Val_Typ := Base_Type (Typ);
-
-- Obtain the full view of the input type by stripping away concurrency,
-- derivations, and privacy.
- while Continue loop
- Continue := False;
-
- if Is_Concurrent_Type (Val_Typ) then
- if Present (Corresponding_Record_Type (Val_Typ)) then
- Continue := True;
- Val_Typ := Corresponding_Record_Type (Val_Typ);
+ if Is_Base_Type (Typ) then
+ if Is_Concurrent_Type (Typ) then
+ if Present (Corresponding_Record_Type (Typ)) then
+ return Corresponding_Record_Type (Typ);
+ else
+ return Typ;
end if;
- elsif Is_Derived_Type (Val_Typ) then
- Continue := True;
- Val_Typ := Etype (Val_Typ);
+ elsif Is_Derived_Type (Typ) then
+ return Validated_View (Etype (Typ));
- elsif Is_Private_Type (Val_Typ) then
- if Present (Underlying_Full_View (Val_Typ)) then
- Continue := True;
- Val_Typ := Underlying_Full_View (Val_Typ);
+ elsif Is_Private_Type (Typ) then
+ if Present (Underlying_Full_View (Typ)) then
+ return Validated_View (Underlying_Full_View (Typ));
- elsif Present (Full_View (Val_Typ)) then
- Continue := True;
- Val_Typ := Full_View (Val_Typ);
+ elsif Present (Full_View (Typ)) then
+ return Validated_View (Full_View (Typ));
+ else
+ return Typ;
end if;
end if;
- end loop;
- return Val_Typ;
+ return Typ;
+ else
+ return Validated_View (Base_Type (Typ));
+ end if;
end Validated_View;
-----------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -3290,7 +3290,7 @@ package Sem_Util is
function Validated_View (Typ : Entity_Id) return Entity_Id;
-- Obtain the "validated view" of arbitrary type Typ which is suitable for
- -- verification by attributes 'Valid_Scalars. This view is the type itself
+ -- verification by attribute 'Valid_Scalars. This view is the type itself
-- or its full view while stripping away concurrency, derivations, and
-- privacy.
reply other threads:[~2021-06-30 9:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210630093045.GA341@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).