]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Rewrite Validated_View in recursive style
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 6 Apr 2021 11:10:40 +0000 (13:10 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 29 Jun 2021 14:23:46 +0000 (14:23 +0000)
gcc/ada/

* sem_util.ads (Validated_View): Fix style in comment.
* sem_util.adb (Validated_View): Rewrite in recursive style.

gcc/ada/sem_util.adb
gcc/ada/sem_util.ads

index 479bb146b61a6f10ff4c9ee137d9b6eac217582f..169825ec03065cbb768b15e9559c993bfca0876c 100644 (file)
@@ -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;
 
    -----------------------
index a1ed43cba43d5acac1012eb896a106ea8f9237c3..f9db80ea496c45b7ce2473b50732087212e18664 100644 (file)
@@ -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.