public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-410] ada: Refactor repeated code for querying Boolean-valued aspects
@ 2024-05-13 8:36 Marc Poulhi?s
0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2024-05-13 8:36 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7f1289651145ed5590c883e9a531e3bcc11b1130
commit r15-410-g7f1289651145ed5590c883e9a531e3bcc11b1130
Author: Piotr Trojanek <trojanek@adacore.com>
Date: Fri Jan 26 12:14:48 2024 +0100
ada: Refactor repeated code for querying Boolean-valued aspects
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.
Diff:
---
gcc/ada/exp_ch9.adb | 19 +++----------------
gcc/ada/sem_util.adb | 28 +++++++++++++++++++++++-----
gcc/ada/sem_util.ads | 6 ++++++
3 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index 1b231b8bf2c2..a89e3247647c 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -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
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index b30cbcd57e93..e9ab6650dac6 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -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;
-----------------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index a5eb1ecd7c16..527b1075c3fd 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-13 8:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13 8:36 [gcc r15-410] ada: Refactor repeated code for querying Boolean-valued aspects Marc Poulhi?s
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).