[Ada] Simplify aspect processing with membership tests
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 14 Oct 2020 22:39:29 +0000 (00:39 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 25 Nov 2020 13:22:38 +0000 (08:22 -0500)
gcc/ada/

* sem_ch13.adb (Analyze_One_Aspect): Detect aspect identifiers
with membership tests.
(Check_Aspect_At_End_Of_Declarations): Likewise.
(Freeze_Entity_Checks): Likewise; a local constant is no longer
needed.
(Is_Operational_Item): Similar simplification for attribute
identifiers.
(Is_Type_Related_Rep_Item): Likewise.
(Resolve_Iterable_Operation): Detect names with a membership
test.
(Validate_Independence): Replace repeated Ekind with a
membership test.

gcc/ada/sem_ch13.adb

index 4659a48c387e391cb1f5660acd88b72e5aae7ce3..45e9d7517955e9289f872eb1190b7455eab74bf6 100644 (file)
@@ -1439,9 +1439,9 @@ package body Sem_Ch13 is
                      --  Aspect Full_Access_Only must be analyzed last so that
                      --  aspects Volatile and Atomic, if any, are analyzed.
 
-                     if A_Id /= Aspect_Export
-                       and then A_Id /= Aspect_Import
-                       and then A_Id /= Aspect_Full_Access_Only
+                     if A_Id not in Aspect_Export
+                                  | Aspect_Full_Access_Only
+                                  | Aspect_Import
                      then
                         Make_Pragma_From_Boolean_Aspect (ASN);
                      end if;
@@ -2800,9 +2800,7 @@ package body Sem_Ch13 is
 
             Ent := New_Occurrence_Of (E, Sloc (Id));
 
-            if A_Id = Aspect_Attach_Handler
-              or else A_Id = Aspect_Interrupt_Handler
-            then
+            if A_Id in Aspect_Attach_Handler | Aspect_Interrupt_Handler then
 
                --  Treat the specification as a reference to the protected
                --  operation, which might otherwise appear unreferenced and
@@ -2846,10 +2844,10 @@ package body Sem_Ch13 is
             --  Check some general restrictions on language defined aspects
 
             if not Implementation_Defined_Aspect (A_Id)
-              or else A_Id = Aspect_Async_Readers
-              or else A_Id = Aspect_Async_Writers
-              or else A_Id = Aspect_Effective_Reads
-              or else A_Id = Aspect_Effective_Writes
+              or else A_Id in Aspect_Async_Readers
+                            | Aspect_Async_Writers
+                            | Aspect_Effective_Reads
+                            | Aspect_Effective_Writes
             then
                Error_Msg_Name_1 := Nam;
 
@@ -2873,16 +2871,16 @@ package body Sem_Ch13 is
                        ("aspect % not allowed for formal type declaration",
                         Aspect);
 
-                  elsif A_Id /= Aspect_Atomic
-                     and then A_Id /= Aspect_Volatile
-                     and then A_Id /= Aspect_Independent
-                     and then A_Id /= Aspect_Atomic_Components
-                     and then A_Id /= Aspect_Independent_Components
-                     and then A_Id /= Aspect_Volatile_Components
-                     and then A_Id /= Aspect_Async_Readers
-                     and then A_Id /= Aspect_Async_Writers
-                     and then A_Id /= Aspect_Effective_Reads
-                     and then A_Id /= Aspect_Effective_Writes
+                  elsif A_Id not in Aspect_Atomic
+                                  | Aspect_Volatile
+                                  | Aspect_Independent
+                                  | Aspect_Atomic_Components
+                                  | Aspect_Independent_Components
+                                  | Aspect_Volatile_Components
+                                  | Aspect_Async_Readers
+                                  | Aspect_Async_Writers
+                                  | Aspect_Effective_Reads
+                                  | Aspect_Effective_Writes
                   then
                      Error_Msg_N
                        ("aspect % not allowed for formal type declaration",
@@ -2938,11 +2936,11 @@ package body Sem_Ch13 is
                   --  an attribute reference whose prefix is Standard, for
                   --  example Standard'Maximum_Alignment or Standard'Word_Size.
 
-                  elsif (A_Id = Aspect_Alignment
-                          or else A_Id = Aspect_Component_Size
-                          or else A_Id = Aspect_Object_Size
-                          or else A_Id = Aspect_Size
-                          or else A_Id = Aspect_Value_Size)
+                  elsif A_Id in Aspect_Alignment
+                              | Aspect_Component_Size
+                              | Aspect_Object_Size
+                              | Aspect_Size
+                              | Aspect_Value_Size
                     and then Present (Expr)
                     and then Nkind (Expr) = N_Attribute_Reference
                     and then Nkind (Prefix (Expr)) = N_Identifier
@@ -3011,9 +3009,8 @@ package body Sem_Ch13 is
                =>
                   --  Indexing aspects apply only to tagged type
 
-                  if (A_Id = Aspect_Constant_Indexing
-                        or else
-                      A_Id = Aspect_Variable_Indexing)
+                  if A_Id in Aspect_Constant_Indexing
+                           | Aspect_Variable_Indexing
                     and then not (Is_Type (E)
                                    and then Is_Tagged_Type (E))
                   then
@@ -3040,10 +3037,10 @@ package body Sem_Ch13 is
                   --  illegal specification of this aspect for a subtype now,
                   --  to prevent malformed rep_item chains.
 
-                  if A_Id = Aspect_Input  or else
-                     A_Id = Aspect_Output or else
-                     A_Id = Aspect_Read   or else
-                     A_Id = Aspect_Write
+                  if A_Id in Aspect_Input
+                           | Aspect_Output
+                           | Aspect_Read
+                           | Aspect_Write
                   then
                      if not Is_First_Subtype (E) then
                         Error_Msg_N
@@ -4262,7 +4259,7 @@ package body Sem_Ch13 is
                   Pname : Name_Id;
 
                begin
-                  if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
+                  if A_Id in Aspect_Pre | Aspect_Precondition then
                      Pname := Name_Precondition;
                   else
                      Pname := Name_Postcondition;
@@ -4509,7 +4506,7 @@ package body Sem_Ch13 is
 
                      goto Continue;
 
-                  elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then
+                  elsif A_Id in Aspect_Export | Aspect_Import then
                      Analyze_Aspect_Export_Import;
 
                   --  Disable_Controlled
@@ -4581,9 +4578,7 @@ package body Sem_Ch13 is
                      --  Exclude aspects Export and Import because their pragma
                      --  syntax does not map directly to a Boolean aspect.
 
-                     if A_Id /= Aspect_Export
-                       and then A_Id /= Aspect_Import
-                     then
+                     if A_Id not in Aspect_Export | Aspect_Import then
                         Aitem := Make_Aitem_Pragma
                           (Pragma_Argument_Associations => New_List (
                              Make_Pragma_Argument_Association (Sloc (Ent),
@@ -10578,22 +10573,22 @@ package body Sem_Ch13 is
       --  name, so we need to verify that one of these interpretations is
       --  the one available at at the freeze point.
 
-      elsif A_Id = Aspect_Input  or else
-            A_Id = Aspect_Output or else
-            A_Id = Aspect_Read   or else
-            A_Id = Aspect_Write  or else
-            A_Id = Aspect_Put_Image
+      elsif A_Id in Aspect_Input
+                  | Aspect_Output
+                  | Aspect_Read
+                  | Aspect_Write
+                  | Aspect_Put_Image
       then
          Analyze (End_Decl_Expr);
          Check_Overloaded_Name;
 
-      elsif A_Id = Aspect_Variable_Indexing or else
-            A_Id = Aspect_Constant_Indexing or else
-            A_Id = Aspect_Default_Iterator  or else
-            A_Id = Aspect_Iterator_Element  or else
-            A_Id = Aspect_Integer_Literal   or else
-            A_Id = Aspect_Real_Literal      or else
-            A_Id = Aspect_String_Literal
+      elsif A_Id in Aspect_Variable_Indexing
+                  | Aspect_Constant_Indexing
+                  | Aspect_Default_Iterator
+                  | Aspect_Iterator_Element
+                  | Aspect_Integer_Literal
+                  | Aspect_Real_Literal
+                  | Aspect_String_Literal
       then
          --  Make type unfrozen before analysis, to prevent spurious errors
          --  about late attributes.
@@ -10619,9 +10614,7 @@ package body Sem_Ch13 is
          --  also make its potential components accessible.
 
          if not Analyzed (Freeze_Expr) and then Inside_A_Generic then
-            if A_Id = Aspect_Dynamic_Predicate
-              or else A_Id = Aspect_Predicate
-            then
+            if A_Id in Aspect_Dynamic_Predicate | Aspect_Predicate then
                Push_Type (Ent);
                Preanalyze_Spec_Expression (Freeze_Expr, Standard_Boolean);
                Pop_Type (Ent);
@@ -10647,9 +10640,9 @@ package body Sem_Ch13 is
          --  visible for aspects that may reference them.
 
          if Present (Freeze_Expr) and then No (T) then
-            if A_Id = Aspect_Dynamic_Predicate
-              or else A_Id = Aspect_Predicate
-              or else A_Id = Aspect_Priority
+            if A_Id in Aspect_Dynamic_Predicate
+                     | Aspect_Predicate
+                     | Aspect_Priority
             then
                Push_Type (Ent);
                Check_Aspect_At_Freeze_Point (ASN);
@@ -10665,9 +10658,7 @@ package body Sem_Ch13 is
          --  partial view is visible. The expression must be scalar, so use
          --  the full view to resolve.
 
-         elsif (A_Id = Aspect_Default_Value
-                  or else
-                A_Id = Aspect_Default_Component_Value)
+         elsif A_Id in Aspect_Default_Component_Value | Aspect_Default_Value
             and then Is_Private_Type (T)
          then
             Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
@@ -10675,10 +10666,10 @@ package body Sem_Ch13 is
          --  The following aspect expressions may contain references to
          --  components and discriminants of the type.
 
-         elsif A_Id = Aspect_Dynamic_Predicate
-           or else A_Id = Aspect_Predicate
-           or else A_Id = Aspect_Priority
-           or else A_Id = Aspect_CPU
+         elsif A_Id in Aspect_CPU
+                     | Aspect_Dynamic_Predicate
+                     | Aspect_Predicate
+                     | Aspect_Priority
          then
             Push_Type (Ent);
             Preanalyze_Spec_Expression (End_Decl_Expr, T);
@@ -12700,7 +12691,6 @@ package body Sem_Ch13 is
         and then Scope (E) = Current_Scope
       then
          declare
-            A_Id  : Aspect_Id;
             Ritem : Node_Id;
 
          begin
@@ -12712,12 +12702,10 @@ package body Sem_Ch13 is
                  and then Entity (Ritem) = E
                  and then Is_Delayed_Aspect (Ritem)
                then
-                  A_Id := Get_Aspect_Id (Ritem);
-
-                  if A_Id = Aspect_Dynamic_Predicate
-                    or else A_Id = Aspect_Predicate
-                    or else A_Id = Aspect_Priority
-                    or else A_Id = Aspect_CPU
+                  if Get_Aspect_Id (Ritem) in Aspect_CPU
+                                            | Aspect_Dynamic_Predicate
+                                            | Aspect_Predicate
+                                            | Aspect_Priority
                   then
                     --  Retrieve the visibility to components and discriminants
                     --  in order to properly analyze the aspects.
@@ -13463,31 +13451,23 @@ package body Sem_Ch13 is
 
    function Is_Operational_Item (N : Node_Id) return Boolean is
    begin
-      if Nkind (N) /= N_Attribute_Definition_Clause then
-         return False;
-
-      else
-         declare
-            Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
-         begin
-
-            --  List of operational items is given in AARM 13.1(8.mm/1).
-            --  It is clearly incomplete, as it does not include iterator
-            --  aspects, among others.
-
-            return    Id = Attribute_Constant_Indexing
-              or else Id = Attribute_Default_Iterator
-              or else Id = Attribute_Implicit_Dereference
-              or else Id = Attribute_Input
-              or else Id = Attribute_Iterator_Element
-              or else Id = Attribute_Iterable
-              or else Id = Attribute_Output
-              or else Id = Attribute_Read
-              or else Id = Attribute_Variable_Indexing
-              or else Id = Attribute_Write
-              or else Id = Attribute_External_Tag;
-         end;
-      end if;
+      --  List of operational items is given in AARM 13.1(8.mm/1). It is
+      --  clearly incomplete, as it does not include iterator aspects, among
+      --  others.
+
+      return Nkind (N) = N_Attribute_Definition_Clause
+          and then
+        Get_Attribute_Id (Chars (N)) in Attribute_Constant_Indexing
+                                      | Attribute_External_Tag
+                                      | Attribute_Default_Iterator
+                                      | Attribute_Implicit_Dereference
+                                      | Attribute_Input
+                                      | Attribute_Iterable
+                                      | Attribute_Iterator_Element
+                                      | Attribute_Output
+                                      | Attribute_Read
+                                      | Attribute_Variable_Indexing
+                                      | Attribute_Write;
    end Is_Operational_Item;
 
    -------------------------
@@ -13695,17 +13675,13 @@ package body Sem_Ch13 is
    begin
       case Nkind (N) is
          when N_Attribute_Definition_Clause =>
-            declare
-               Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
-               --  See AARM 13.1(8.f-8.x) list items that end in "clause"
-               --  ???: include any GNAT-defined attributes here?
-            begin
-               return    Id = Attribute_Component_Size
-                 or else Id = Attribute_Bit_Order
-                 or else Id = Attribute_Storage_Pool
-                 or else Id = Attribute_Stream_Size
-                 or else Id = Attribute_Machine_Radix;
-            end;
+            --  See AARM 13.1(8.f-8.x) list items that end in "clause"
+            --  ???: include any GNAT-defined attributes here?
+            return Get_Attribute_Id (Chars (N)) in Attribute_Bit_Order
+                                                 | Attribute_Component_Size
+                                                 | Attribute_Machine_Radix
+                                                 | Attribute_Storage_Pool
+                                                 | Attribute_Stream_Size;
 
          when N_Pragma =>
             case Get_Pragma_Id (N) is
@@ -15135,7 +15111,7 @@ package body Sem_Ch13 is
          Ent := Entity (N);
          F1  := First_Formal (Ent);
 
-         if Nam = Name_First or else Nam = Name_Last then
+         if Nam in Name_First | Name_Last then
 
             --  First or Last (Container) => Cursor
 
@@ -16026,7 +16002,7 @@ package body Sem_Ch13 is
 
          --  Deal with component case
 
-         if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
+         if Ekind (E) in E_Component | E_Discriminant then
             if not OK_Component (E) then
                No_Independence;
                Reason_Bad_Component (E);