Patchwork [Ada] Implement Input/Output/Read/Write aspects

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 18, 2010, 9:53 a.m.
Message ID <20101018095327.GA25778@adacore.com>
Download mbox | patch
Permalink /patch/68154/
State New
Headers show

Comments

Arnaud Charlet - Oct. 18, 2010, 9:53 a.m.
This patch implements four additional aspects, Input/Output/Read/Write.
These aspects take names, and must be fully delayed.

The following compiles quietly with -gnat12 -gnatc

with Ada.Streams;
use Ada.Streams;
package Streamaspect is
   type T is new Integer with
     Input => My_Input;

   function My_Input
     (Stream : not null access Root_Stream_Type'Class)
      return T;
end;

Note in this example that the Aspect appears before the declaration
of the referenced routine (this will usually be the case, which is
why this aspect must be delayed till the freeze point).

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-10-18  Robert Dewar  <dewar@adacore.com>

	* aspects.ads, aspects.adb: Add entries for aspects
	Read/Write/Input/Output.
	* sem_ch13.adb (Analyze_Aspect_Specifications): Add processing for
	handling aspects Read/Write/Input/Output.

Patch

Index: aspects.adb
===================================================================
--- aspects.adb	(revision 165610)
+++ aspects.adb	(working copy)
@@ -86,9 +86,11 @@  package body Aspects is
      (Name_Favor_Top_Level,              Aspect_Favor_Top_Level),
      (Name_Inline,                       Aspect_Inline),
      (Name_Inline_Always,                Aspect_Inline_Always),
+     (Name_Input,                        Aspect_Input),
      (Name_Invariant,                    Aspect_Invariant),
      (Name_Machine_Radix,                Aspect_Machine_Radix),
      (Name_Object_Size,                  Aspect_Object_Size),
+     (Name_Output,                       Aspect_Output),
      (Name_Pack,                         Aspect_Pack),
      (Name_Persistent_BSS,               Aspect_Persistent_BSS),
      (Name_Post,                         Aspect_Post),
@@ -96,6 +98,7 @@  package body Aspects is
      (Name_Predicate,                    Aspect_Predicate),
      (Name_Preelaborable_Initialization, Aspect_Preelaborable_Initialization),
      (Name_Pure_Function,                Aspect_Pure_Function),
+     (Name_Read,                         Aspect_Read),
      (Name_Shared,                       Aspect_Shared),
      (Name_Size,                         Aspect_Size),
      (Name_Storage_Pool,                 Aspect_Storage_Pool),
@@ -112,7 +115,8 @@  package body Aspects is
      (Name_Value_Size,                   Aspect_Value_Size),
      (Name_Volatile,                     Aspect_Volatile),
      (Name_Volatile_Components,          Aspect_Volatile_Components),
-     (Name_Warnings,                     Aspect_Warnings));
+     (Name_Warnings,                     Aspect_Warnings),
+     (Name_Write,                        Aspect_Write));
 
    -------------------------------------
    -- Hash Table for Aspect Id Values --
Index: aspects.ads
===================================================================
--- aspects.ads	(revision 165610)
+++ aspects.ads	(working copy)
@@ -56,10 +56,12 @@  package Aspects is
       Aspect_Favor_Top_Level,               -- GNAT
       Aspect_Inline,
       Aspect_Inline_Always,                 -- GNAT
+      Aspect_Input,
       Aspect_Invariant,
       Aspect_Machine_Radix,
       Aspect_No_Return,
       Aspect_Object_Size,                   -- GNAT
+      Aspect_Output,
       Aspect_Pack,
       Aspect_Persistent_BSS,                -- GNAT
       Aspect_Post,
@@ -67,6 +69,7 @@  package Aspects is
       Aspect_Predicate,                     -- GNAT???
       Aspect_Preelaborable_Initialization,
       Aspect_Pure_Function,                 -- GNAT
+      Aspect_Read,
       Aspect_Shared,                        -- GNAT (equivalent to Atomic)
       Aspect_Size,
       Aspect_Storage_Pool,
@@ -83,7 +86,8 @@  package Aspects is
       Aspect_Value_Size,                    -- GNAT
       Aspect_Volatile,
       Aspect_Volatile_Components,
-      Aspect_Warnings);                     -- GNAT
+      Aspect_Warnings,
+      Aspect_Write);                        -- GNAT
 
    --  The following array indicates aspects that accept 'Class
 
@@ -118,10 +122,12 @@  package Aspects is
                         Aspect_Favor_Top_Level              => Optional,
                         Aspect_Inline                       => Optional,
                         Aspect_Inline_Always                => Optional,
+                        Aspect_Input                        => Name,
                         Aspect_Invariant                    => Expression,
                         Aspect_Machine_Radix                => Expression,
                         Aspect_No_Return                    => Optional,
                         Aspect_Object_Size                  => Expression,
+                        Aspect_Output                       => Name,
                         Aspect_Persistent_BSS               => Optional,
                         Aspect_Pack                         => Optional,
                         Aspect_Post                         => Expression,
@@ -129,6 +135,7 @@  package Aspects is
                         Aspect_Predicate                    => Expression,
                         Aspect_Preelaborable_Initialization => Optional,
                         Aspect_Pure_Function                => Optional,
+                        Aspect_Read                         => Name,
                         Aspect_Shared                       => Optional,
                         Aspect_Size                         => Expression,
                         Aspect_Storage_Pool                 => Name,
@@ -145,7 +152,8 @@  package Aspects is
                         Aspect_Value_Size                   => Expression,
                         Aspect_Volatile                     => Optional,
                         Aspect_Volatile_Components          => Optional,
-                        Aspect_Warnings                     => Name);
+                        Aspect_Warnings                     => Name,
+                        Aspect_Write                        => Name);
 
    function Get_Aspect_Id (Name : Name_Id) return Aspect_Id;
    pragma Inline (Get_Aspect_Id);
Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb	(revision 165610)
+++ sem_ch13.adb	(working copy)
@@ -870,13 +870,34 @@  package body Sem_Ch13 is
                         New_Occurrence_Of (E, Eloc),
                         Relocate_Node (Expr)),
                       Pragma_Identifier            =>
-                      Make_Identifier (Sloc (Id), Chars (Id)));
+                        Make_Identifier (Sloc (Id), Chars (Id)));
 
                   --  We don't have to play the delay game here, since the only
                   --  values are check names which don't get analyzed anyway.
 
                   Delay_Required := False;
 
+               --  Aspects corresponding to stream routines
+
+               when Aspect_Input  |
+                    Aspect_Output |
+                    Aspect_Read   |
+                    Aspect_Write  =>
+
+                  --  Construct the attribute definition clause
+
+                  Aitem :=
+                    Make_Attribute_Definition_Clause (Loc,
+                      Name       => Ent,
+                      Chars      => Chars (Id),
+                      Expression => Relocate_Node (Expr));
+
+                  --  These are always delayed (typically the subprogram that
+                  --  is referenced cannot have been declared yet, since it has
+                  --  a reference to the type for which this aspect is defined.
+
+                  Delay_Required := True;
+
                --  Aspects corresponding to pragmas with two arguments, where
                --  the second argument is a local name referring to the entity,
                --  and the first argument is the aspect definition expression.