diff options
author | Ronan Desplanques <desplanques@adacore.com> | 2024-09-02 15:38:21 +0200 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-10-08 10:37:11 +0200 |
commit | 7e09f16ef980883598268b2044b9b370ec3a9611 (patch) | |
tree | 236cd26c5cc9b0f85994488a873a1fe59f2b9240 /gcc/ada/doc/gnat_rm | |
parent | 23017cea9c8438865e557782c6c46eb996cf2132 (diff) | |
download | gcc-7e09f16ef980883598268b2044b9b370ec3a9611.zip gcc-7e09f16ef980883598268b2044b9b370ec3a9611.tar.gz gcc-7e09f16ef980883598268b2044b9b370ec3a9611.tar.bz2 |
ada: Add External_Initialization extension
This patch introduces a GNAT extension that adds a new aspect,
External_Initialization. A section is added to the reference
manual with a description of what the aspect does.
The implementation reuses existing mechanisms, in particular
Sinput.L.Load_Source_File and Sem_Res.Set_String_Literal_Subtype.
A new node kind is added, and nodes of that type are present in what
is passed to the back ends. That makes it necessary to update the back
ends to handle the new node type. The C interface is extended to make
that possible.
gcc/ada/ChangeLog:
* aspects.ads: Add entities for External_Initialization.
* checks.adb (Selected_Length_Checks): Add support for
N_External_Initializer nodes.
* doc/gnat_rm/gnat_language_extensions.rst: Add section for the added
extension.
* exp_util.adb (Insert_Actions): Add support for N_External_Initializer
nodes.
* fe.h (C_Source_Buffer): New function.
* gen_il-fields.ads: Add new field.
* gen_il-gen-gen_nodes.adb: Add N_External_Initializer node kind.
* gen_il-gen.adb: Add new field type.
* gen_il-types.ads: Add new node kind and new field type.
* pprint.adb (Expr_Name): Handle new node kind.
* sem.adb (Analyze): Add support for N_External_Initializer nodes.
* sem_ch13.adb (Analyze_Aspect_Specifications, Check_Aspect_At_Freeze_Point):
Add support for External_Initialization aspect.
* sem_ch3.adb (Apply_External_Initialization): New subprogram.
(Analyze_Object_Declaration): Add support for External_Initialization aspect.
* sem_res.adb (Resolve_External_Initializer): New procedure.
(Resolve): Add support for N_External_Initializer nodes.
(Set_String_Literal_Subtype): Extend to handle N_External_Initializer nodes.
* sinfo-utils.adb (Is_In_Union_Id): Adapt to new field addition.
* sinfo.ads: Add documentation for new node kind and new field.
* sinput.adb, sinput.ads (C_Source_Buffer): Add new C interface function.
* snames.ads-tmpl: Add new aspect identifier.
* sprint.adb (Sprint_Node_Actual): Add nop handling of N_External_Initializer
nodes.
* types.ads: Modify type to allow for new C interface.
* gcc-interface/trans.cc (gnat_to_gnu): Handle new GNAT node type.
* gcc-interface/Make-lang.in: Update list of stage1 run-time library units.
* gnat-style.texi: Regenerate.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
Diffstat (limited to 'gcc/ada/doc/gnat_rm')
-rw-r--r-- | gcc/ada/doc/gnat_rm/gnat_language_extensions.rst | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst index e7cd73f..b29f23c 100644 --- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst +++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst @@ -740,3 +740,28 @@ the following standard-Ada instantiation: Link to the original RFC: https://github.com/AdaCore/ada-spark-rfcs/blob/topic/generic_instantiations/considered/rfc-inference-of-dependent-types.md + +External_Initialization Aspect +------------------------------ + +The ``External_Initialization`` aspect provides a feature similar to Rust's ``include_bytes!`` +and to C23's ``#embed``. It has the effect of initializing an object with the contents of +a file specified by a file path. + +Only string objects and objects of type ``Ada.Streams.Stream_Element_Array`` can be subject +to the ``External_Initialization`` aspect. + +Example: + +.. code-block:: ada + + with Ada.Streams; + + package P is + S : constant String with External_Initialization => "foo.txt"; + + X : constant Ada.Streams.Stream_Element_Array with External_Initialization => "bar.bin"; + end P; + +Link to the original RFC: +https://github.com/AdaCore/ada-spark-rfcs/blob/master/considered/rfc-embed-binary-resources.rst |