]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Refactor repeated code for querying Boolean-valued aspects
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 26 Jan 2024 11:14:48 +0000 (12:14 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 13 May 2024 08:03:31 +0000 (10:03 +0200)
Code cleanup following a fix for aspect Exclusive_Functions; semantics
is unaffected.

gcc/ada/

* exp_ch9.adb (Build_Protected_Subprogram_Body,
Build_Protected_Subprogram_Call_Cleanup): Reuse refactored
routine.
* sem_util.adb
(Has_Enabled_Aspect): Refactored repeated code.
(Is_Static_Function): Reuse refactored routine.
* sem_util.ads (Has_Enabled_Aspect):
New query routine refactored from repeated code.

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

index 1b231b8bf2c250e1e57b7ecab177e871189b5dfa..a89e3247647c8bb88cc39a1993b4af69f703c0db 100644 (file)
@@ -3835,13 +3835,7 @@ package body Exp_Ch9 is
                 Expression => New_Occurrence_Of (R, Loc));
          end if;
 
-         if Has_Aspect (Pid, Aspect_Exclusive_Functions)
-           and then
-             (No (Find_Value_Of_Aspect (Pid, Aspect_Exclusive_Functions))
-               or else
-                 Is_True (Static_Boolean (Find_Value_Of_Aspect
-                   (Pid, Aspect_Exclusive_Functions))))
-         then
+         if Has_Enabled_Aspect (Pid, Aspect_Exclusive_Functions) then
             Lock_Kind := RE_Lock;
          else
             Lock_Kind := RE_Lock_Read_Only;
@@ -4041,16 +4035,9 @@ package body Exp_Ch9 is
       if (Nkind (Op_Spec) = N_Procedure_Specification
             or else
           (Nkind (Op_Spec) = N_Function_Specification
-             and then Has_Aspect (Conc_Typ, Aspect_Exclusive_Functions)
              and then
-               (No
-                 (Find_Value_Of_Aspect (Conc_Typ,
-                    Aspect_Exclusive_Functions))
-                  or else
-                Is_True
-                  (Static_Boolean
-                     (Find_Value_Of_Aspect
-                        (Conc_Typ, Aspect_Exclusive_Functions))))))
+           Has_Enabled_Aspect
+             (Conc_Typ, Aspect_Exclusive_Functions)))
         and then Has_Entries (Conc_Typ)
       then
          case Corresponding_Runtime_Package (Conc_Typ) is
index b30cbcd57e93ce32318772b5f4783cd059c6f8ed..e9ab6650dac6c2c32411e08a295d8a329c389f93 100644 (file)
@@ -13484,6 +13484,28 @@ package body Sem_Util is
       return False;
    end Has_Effectively_Volatile_Component;
 
+   ------------------------
+   -- Has_Enabled_Aspect --
+   ------------------------
+
+   function Has_Enabled_Aspect
+     (Id : Entity_Id;
+      A  : Aspect_Id)
+      return Boolean
+   is
+      Asp : constant Node_Id := Find_Aspect (Id, A);
+   begin
+      if Present (Asp) then
+         if Present (Expression (Asp)) then
+            return Is_True (Static_Boolean (Expression (Asp)));
+         else
+            return True;
+         end if;
+      else
+         return False;
+      end if;
+   end Has_Enabled_Aspect;
+
    ----------------------------
    -- Has_Volatile_Component --
    ----------------------------
@@ -20356,11 +20378,7 @@ package body Sem_Util is
       --  for efficiency.
 
       return Ada_Version >= Ada_2022
-        and then Has_Aspect (Subp, Aspect_Static)
-        and then
-          (No (Find_Value_Of_Aspect (Subp, Aspect_Static))
-            or else Is_True (Static_Boolean
-                               (Find_Value_Of_Aspect (Subp, Aspect_Static))));
+        and then Has_Enabled_Aspect (Subp, Aspect_Static);
    end Is_Static_Function;
 
    -----------------------------
index a5eb1ecd7c16f975b9fa6be82e7a9f4aa314b6bd..527b1075c3fdbb0012c49db6a6a41d4a09b9566b 100644 (file)
@@ -1559,6 +1559,12 @@ package Sem_Util is
    --  Given arbitrary type Typ, determine whether it contains at least one
    --  effectively volatile component.
 
+   function Has_Enabled_Aspect (Id : Entity_Id; A : Aspect_Id) return Boolean
+     with Pre => A in Boolean_Aspects;
+   --  Returns True if a Boolean-valued aspect is enabled on entity Id; i.e. it
+   --  is present and either has no aspect definition or its aspect definition
+   --  statically evaluates to True.
+
    function Has_Volatile_Component (Typ : Entity_Id) return Boolean;
    --  Given arbitrary type Typ, determine whether it contains at least one
    --  volatile component.