[Ada] AI12-0228 Properties of qualified expressions used as names
authorArnaud Charlet <charlet@adacore.com>
Mon, 17 Feb 2020 17:41:37 +0000 (12:41 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 8 Jun 2020 07:51:10 +0000 (03:51 -0400)
2020-06-08  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

* sem_ch8.adb (Analyze_Object_Renaming): Update Get_Object_Name
to go through N_Qualified_Expression and N_Type_Conversion.  Fix
another case of wrong usage of E_Anonymous_Access_Type instead
of Anonymous_Access_Kind.
* sem_util.adb (Is_Dependent_Component_Of_Mutable_Object): Work
on the original node.
(Is_Aliased_View): Take into account N_Qualified_Expression.

gcc/ada/sem_ch8.adb
gcc/ada/sem_util.adb

index 709a839..4d9b5ba 100644 (file)
@@ -844,18 +844,23 @@ package body Sem_Ch8 is
       begin
          Obj_Nam := Nod;
          while Present (Obj_Nam) loop
-            if Nkind_In (Obj_Nam, N_Attribute_Reference,
-                                  N_Explicit_Dereference,
-                                  N_Indexed_Component,
-                                  N_Slice)
-            then
-               Obj_Nam := Prefix (Obj_Nam);
+            case Nkind (Obj_Nam) is
+               when N_Attribute_Reference
+                  | N_Explicit_Dereference
+                  | N_Indexed_Component
+                  | N_Slice
+               =>
+                  Obj_Nam := Prefix (Obj_Nam);
 
-            elsif Nkind (Obj_Nam) = N_Selected_Component then
-               Obj_Nam := Selector_Name (Obj_Nam);
-            else
-               exit;
-            end if;
+               when N_Selected_Component =>
+                  Obj_Nam := Selector_Name (Obj_Nam);
+
+               when N_Qualified_Expression | N_Type_Conversion =>
+                  Obj_Nam := Expression (Obj_Nam);
+
+               when others =>
+                  exit;
+            end case;
          end loop;
 
          return Obj_Nam;
@@ -1046,8 +1051,8 @@ package body Sem_Ch8 is
 
          if Nkind (Nam) = N_Type_Conversion
            and then not Comes_From_Source (Nam)
-           and then Ekind (Etype (Expression (Nam))) = E_Anonymous_Access_Type
-           and then Ekind (T) /= E_Anonymous_Access_Type
+           and then Ekind (Etype (Expression (Nam))) in Anonymous_Access_Kind
+           and then Ekind (T) not in Anonymous_Access_Kind
          then
             Wrong_Type (Expression (Nam), T); -- Should we give better error???
          end if;
index 4f7d2d0..f359fa2 100644 (file)
@@ -13736,6 +13736,13 @@ package body Sem_Util is
          return Is_Tagged_Type (Etype (Obj))
            and then Is_Aliased_View (Expression (Obj));
 
+      --  Ada 202x AI12-0228
+
+      elsif Nkind (Obj) = N_Qualified_Expression
+        and then Ada_Version >= Ada_2012
+      then
+         return Is_Aliased_View (Expression (Obj));
+
       elsif Nkind (Obj) = N_Explicit_Dereference then
          return Nkind (Original_Node (Obj)) /= N_Function_Call;
 
@@ -14582,6 +14589,8 @@ package body Sem_Util is
          Deref := Prefix (Deref);
       end loop;
 
+      Deref := Original_Node (Deref);
+
       --  If the prefix is a qualified expression of a variable, then function
       --  Is_Variable will return False for that because a qualified expression
       --  denotes a constant view, so we need to get the name being qualified
@@ -14599,9 +14608,11 @@ package body Sem_Util is
 
       if Is_Variable (Object)
         or else Is_Variable (Deref)
-        or else (Ada_Version >= Ada_2005
-                  and then (Nkind (Deref) = N_Explicit_Dereference
-                             or else Is_Access_Type (Etype (Deref))))
+        or else
+          (Ada_Version >= Ada_2005
+            and then (Nkind (Deref) = N_Explicit_Dereference
+                       or else (Present (Etype (Deref))
+                                 and then Is_Access_Type (Etype (Deref)))))
       then
          if Nkind (Object) = N_Selected_Component then