From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED 03/35] ada: Fix ordering of code for pragma Preelaborable_Initialization
Date: Thu, 16 May 2024 11:25:32 +0200 [thread overview]
Message-ID: <20240516092606.41242-3-poulhies@adacore.com> (raw)
In-Reply-To: <20240516092606.41242-1-poulhies@adacore.com>
From: Piotr Trojanek <trojanek@adacore.com>
Code cleanup.
gcc/ada/
* sem_prag.adb (Analyze_Pragma): Move case alternative to match
to alphabetic order.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_prag.adb | 160 +++++++++++++++++++++----------------------
1 file changed, 80 insertions(+), 80 deletions(-)
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 105cc73eba3..2fc46ab0cd2 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -21889,86 +21889,6 @@ package body Sem_Prag is
Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
end if;
- ----------------------------------
- -- Preelaborable_Initialization --
- ----------------------------------
-
- -- pragma Preelaborable_Initialization (DIRECT_NAME);
-
- when Pragma_Preelaborable_Initialization => Preelab_Init : declare
- Ent : Entity_Id;
-
- begin
- Ada_2005_Pragma;
- Check_Arg_Count (1);
- Check_No_Identifiers;
- Check_Arg_Is_Identifier (Arg1);
- Check_Arg_Is_Local_Name (Arg1);
- Check_First_Subtype (Arg1);
- Ent := Entity (Get_Pragma_Arg (Arg1));
-
- -- A pragma that applies to a Ghost entity becomes Ghost for the
- -- purposes of legality checks and removal of ignored Ghost code.
-
- Mark_Ghost_Pragma (N, Ent);
-
- -- The pragma may come from an aspect on a private declaration,
- -- even if the freeze point at which this is analyzed in the
- -- private part after the full view.
-
- if Has_Private_Declaration (Ent)
- and then From_Aspect_Specification (N)
- then
- null;
-
- -- Check appropriate type argument
-
- elsif Is_Private_Type (Ent)
- or else Is_Protected_Type (Ent)
- or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
-
- -- AI05-0028: The pragma applies to all composite types. Note
- -- that we apply this binding interpretation to earlier versions
- -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
- -- choice since there are other compilers that do the same.
-
- or else Is_Composite_Type (Ent)
- then
- null;
-
- else
- Error_Pragma_Arg
- ("pragma % can only be applied to private, formal derived, "
- & "protected, or composite type", Arg1);
- end if;
-
- -- Give an error if the pragma is applied to a protected type that
- -- does not qualify (due to having entries, or due to components
- -- that do not qualify).
-
- if Is_Protected_Type (Ent)
- and then not Has_Preelaborable_Initialization (Ent)
- then
- Error_Msg_N
- ("protected type & does not have preelaborable "
- & "initialization", Ent);
-
- -- Otherwise mark the type as definitely having preelaborable
- -- initialization.
-
- else
- Set_Known_To_Have_Preelab_Init (Ent);
- end if;
-
- if Has_Pragma_Preelab_Init (Ent)
- and then Warn_On_Redundant_Constructs
- then
- Error_Pragma ("?r?duplicate pragma%!");
- else
- Set_Has_Pragma_Preelab_Init (Ent);
- end if;
- end Preelab_Init;
-
--------------------
-- Persistent_BSS --
--------------------
@@ -22057,6 +21977,86 @@ package body Sem_Prag is
end if;
end Persistent_BSS;
+ ----------------------------------
+ -- Preelaborable_Initialization --
+ ----------------------------------
+
+ -- pragma Preelaborable_Initialization (DIRECT_NAME);
+
+ when Pragma_Preelaborable_Initialization => Preelab_Init : declare
+ Ent : Entity_Id;
+
+ begin
+ Ada_2005_Pragma;
+ Check_Arg_Count (1);
+ Check_No_Identifiers;
+ Check_Arg_Is_Identifier (Arg1);
+ Check_Arg_Is_Local_Name (Arg1);
+ Check_First_Subtype (Arg1);
+ Ent := Entity (Get_Pragma_Arg (Arg1));
+
+ -- A pragma that applies to a Ghost entity becomes Ghost for the
+ -- purposes of legality checks and removal of ignored Ghost code.
+
+ Mark_Ghost_Pragma (N, Ent);
+
+ -- The pragma may come from an aspect on a private declaration,
+ -- even if the freeze point at which this is analyzed in the
+ -- private part after the full view.
+
+ if Has_Private_Declaration (Ent)
+ and then From_Aspect_Specification (N)
+ then
+ null;
+
+ -- Check appropriate type argument
+
+ elsif Is_Private_Type (Ent)
+ or else Is_Protected_Type (Ent)
+ or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
+
+ -- AI05-0028: The pragma applies to all composite types. Note
+ -- that we apply this binding interpretation to earlier versions
+ -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
+ -- choice since there are other compilers that do the same.
+
+ or else Is_Composite_Type (Ent)
+ then
+ null;
+
+ else
+ Error_Pragma_Arg
+ ("pragma % can only be applied to private, formal derived, "
+ & "protected, or composite type", Arg1);
+ end if;
+
+ -- Give an error if the pragma is applied to a protected type that
+ -- does not qualify (due to having entries, or due to components
+ -- that do not qualify).
+
+ if Is_Protected_Type (Ent)
+ and then not Has_Preelaborable_Initialization (Ent)
+ then
+ Error_Msg_N
+ ("protected type & does not have preelaborable "
+ & "initialization", Ent);
+
+ -- Otherwise mark the type as definitely having preelaborable
+ -- initialization.
+
+ else
+ Set_Known_To_Have_Preelab_Init (Ent);
+ end if;
+
+ if Has_Pragma_Preelab_Init (Ent)
+ and then Warn_On_Redundant_Constructs
+ then
+ Error_Pragma ("?r?duplicate pragma%!");
+ else
+ Set_Has_Pragma_Preelab_Init (Ent);
+ end if;
+ end Preelab_Init;
+
--------------------
-- Rename_Pragma --
--------------------
--
2.43.2
next prev parent reply other threads:[~2024-05-16 9:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-16 9:25 [COMMITTED 01/35] ada: Fix docs and comments about pragmas for Boolean-valued aspects Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 02/35] ada: Fix casing in error messages Marc Poulhiès
2024-05-16 9:25 ` Marc Poulhiès [this message]
2024-05-16 9:25 ` [COMMITTED 04/35] ada: Fix alphabetic ordering of aspect identifiers Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 05/35] ada: Cleanup reporting locations for Ada 2022 and GNAT extension aspects Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 06/35] ada: Reuse existing expression when rewriting aspects to pragmas Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 07/35] ada: Remove Aspect_Specifications field from N_Procedure_Specification Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 08/35] ada: Fix bug in maintaining dimension info Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 09/35] ada: Formal_Derived_Type'Size is not static Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 10/35] ada: Implement per-finalization-collection spinlocks Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 11/35] ada: Follow up fixes for Put_Image/streaming regressions Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 12/35] ada: Fix crash with -gnatdJ and -gnatw_q Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 13/35] ada: Fix casing of CUDA in error messages Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 14/35] ada: Fix bogus error on function returning noncontrolling result in private part Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 15/35] ada: Fix resolving tagged operations in array aggregates Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 16/35] ada: Fix latent alignment issue for dynamically-allocated controlled objects Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 17/35] ada: Fix typo in CUDA error message Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 18/35] ada: Fixup one more pattern of broken scope information Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 19/35] ada: Minor performance improvement for dynamically-allocated controlled objects Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 20/35] ada: Fix comments about Get_Ranged_Checks Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 21/35] ada: Fix detection of if_expressions that are known on entry Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 22/35] ada: No need to follow New_Occurrence_Of with Set_Etype Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 23/35] ada: Improve recovery from illegal occurrence of 'Old in if_expression Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 24/35] ada: Propagate Program_Error from failed finalization of collection Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 25/35] ada: Fix reason code for length check Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 26/35] ada: Ignore ghost nodes in call graph information for dispatching calls Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 27/35] ada: Avoid checking parameters of protected procedures Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 28/35] ada: Fix standalone Windows builds of adaint.c Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 29/35] ada: Fix missing length checks with case expressions Marc Poulhiès
2024-05-16 9:25 ` [COMMITTED 30/35] ada: Fix reference to RM clause in comment Marc Poulhiès
2024-05-16 9:26 ` [COMMITTED 31/35] ada: Implement new experimental attribute 'Super Marc Poulhiès
2024-05-16 9:26 ` [COMMITTED 32/35] ada: Exception on Indefinite_Vector aggregate with loop_parameter_specification Marc Poulhiès
2024-05-16 9:26 ` [COMMITTED 33/35] ada: Redundant validity checks Marc Poulhiès
2024-05-16 9:26 ` [COMMITTED 34/35] ada: Reset scope of top level object declaration during unnesting Marc Poulhiès
2024-05-16 9:26 ` [COMMITTED 35/35] ada: Remove obsolete reference in comment Marc Poulhiès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240516092606.41242-3-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=trojanek@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).