[Ada] Refactor duplicated code for First and Last attributes
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 23 Nov 2020 13:38:45 +0000 (14:38 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 14 Dec 2020 15:51:55 +0000 (10:51 -0500)
gcc/ada/

* sem_attr.adb (Analyze_Attribute): Merge identical code for
First/Last, First_Bit/Last_Bit and First_Valid/Last_Valid
attributes.

gcc/ada/sem_attr.adb

index b243af6e1ffe9376b59009a0424cb9cdf79a1aa6..526224454f628fa2ee6aae727b56bbabbef3b3a5 100644 (file)
@@ -4066,7 +4066,9 @@ package body Sem_Attr is
       -- First --
       -----------
 
-      when Attribute_First =>
+      when Attribute_First
+         | Attribute_Last
+      =>
          Check_Array_Or_Scalar_Type;
          Bad_Attribute_For_Predicate;
 
@@ -4074,7 +4076,9 @@ package body Sem_Attr is
       -- First_Bit --
       ---------------
 
-      when Attribute_First_Bit =>
+      when Attribute_First_Bit
+         | Attribute_Last_Bit
+      =>
          Check_Component;
          Set_Etype (N, Universal_Integer);
 
@@ -4082,7 +4086,9 @@ package body Sem_Attr is
       -- First_Valid --
       -----------------
 
-      when Attribute_First_Valid =>
+      when Attribute_First_Valid
+         | Attribute_Last_Valid
+      =>
          Check_First_Last_Valid;
          Set_Etype (N, P_Type);
 
@@ -4295,25 +4301,19 @@ package body Sem_Attr is
       -- Last --
       ----------
 
-      when Attribute_Last =>
-         Check_Array_Or_Scalar_Type;
-         Bad_Attribute_For_Predicate;
+      --  Shares processing with First attribute
 
       --------------
       -- Last_Bit --
       --------------
 
-      when Attribute_Last_Bit =>
-         Check_Component;
-         Set_Etype (N, Universal_Integer);
+      --  Shares processing with First_Bit attribute
 
       ----------------
       -- Last_Valid --
       ----------------
 
-      when Attribute_Last_Valid =>
-         Check_First_Last_Valid;
-         Set_Etype (N, P_Type);
+      --  Shares processing with First_Valid attribute
 
       ------------------
       -- Leading_Part --