-- --
-- S p e c --
-- --
--- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
--- ware Foundation; either version 2, or (at your option) any later ver- --
+-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
--- Public License distributed with GNAT; see file COPYING. If not, write --
--- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
--- MA 02111-1307, USA. --
+-- Public License distributed with GNAT; see file COPYING3. If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
package Exp_Ch9 is
- procedure Add_Discriminal_Declarations
- (Decls : List_Id;
- Typ : Entity_Id;
- Name : Name_Id;
- Loc : Source_Ptr);
- -- This routine is used to add discriminal declarations to task and
- -- protected operation bodies. The discriminants are available by normal
- -- selection from the concurrent object (whose name is passed as the third
- -- parameter). Discriminant references inside the body have already
- -- been replaced by references to the corresponding discriminals. The
- -- declarations constructed by this procedure hook the references up with
- -- the objects:
- --
- -- discriminal_name : discr_type renames name.discriminant_name;
- --
- -- Obviously we could have expanded the discriminant references in the
- -- first place to be the appropriate selection, but this turns out to
- -- be hard to do because it would introduce difference in handling of
- -- discriminant references depending on their location.
-
- procedure Add_Private_Declarations
- (Decls : List_Id;
- Typ : Entity_Id;
- Name : Name_Id;
- Loc : Source_Ptr);
- -- This routine is used to add private declarations to protected bodies.
- -- These are analogous to the discriminal declarations added to tasks
- -- and protected operations, and consist of a renaming of each private
- -- object to a selection from the concurrent object passed as an extra
- -- parameter to each such operation:
- -- private_name : private_type renames name.private_name;
- -- As with discriminals, private references inside the protected
- -- subprogram bodies have already been replaced by references to the
- -- corresponding privals.
+ type Subprogram_Protection_Mode is
+ (Dispatching_Mode,
+ Protected_Mode,
+ Unprotected_Mode);
+ -- This type is used to distinguish the different protection modes of a
+ -- protected subprogram.
procedure Build_Activation_Chain_Entity (N : Node_Id);
-- Given a declaration N of an object that is a task, or contains tasks
-- (other than allocators to tasks) this routine ensures that an activation
-- chain has been declared in the appropriate scope, building the required
-- declaration for the chain variable if not. The name of this variable
- -- is always _Chain and it is accessed by name. This procedure also adds
- -- an appropriate call to Activate_Tasks to activate the tasks for this
- -- activation chain. It does not however deal with the call needed in the
- -- case of allocators to Expunge_Unactivated_Tasks, this is separately
- -- handled in the Expand_Task_Allocator routine.
+ -- is always _Chain and it is accessed by name.
function Build_Call_With_Task (N : Node_Id; E : Entity_Id) return Node_Id;
-- N is a node representing the name of a task or an access to a task.
-- Task_Id of the associated task as the parameter. The caller is
-- responsible for analyzing and resolving the resulting tree.
+ function Build_Corresponding_Record
+ (N : Node_Id;
+ Ctyp : Node_Id;
+ Loc : Source_Ptr) return Node_Id;
+ -- Common to tasks and protected types. Copy discriminant specifications,
+ -- build record declaration. N is the type declaration, Ctyp is the
+ -- concurrent entity (task type or protected type).
+
+ function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id;
+ -- Create the statements which populate the entry names array of a task or
+ -- protected type. The statements are wrapped inside a block due to a local
+ -- declaration.
+
procedure Build_Master_Entity (E : Entity_Id);
-- Given an entity E for the declaration of an object containing tasks
-- or of a type declaration for an allocator whose designated type is a
-- declarative part.
function Build_Protected_Sub_Specification
- (N : Node_Id;
- Prottyp : Entity_Id;
- Unprotected : Boolean := False)
- return Node_Id;
- -- Build specification for protected subprogram. This is called when
+ (N : Node_Id;
+ Prot_Typ : Entity_Id;
+ Mode : Subprogram_Protection_Mode) return Node_Id;
+ -- Build the specification for protected subprogram. This is called when
-- expanding a protected type, and also when expanding the declaration for
- -- an Access_To_Protected_Subprogram type. In the latter case, Prottyp is
+ -- an Access_To_Protected_Subprogram type. In the latter case, Prot_Typ is
-- empty, and the first parameter of the signature of the protected op is
-- of type System.Address.
(Actions : List_Id;
N : Node_Id;
Init_Stmts : List_Id);
- -- Ada0Y (AI-287): Similar to previous routine, but used to expand alloca-
- -- ted aggregates with default initialized components. Init_Stmts contains
- -- the list of statements required to initialize the allocated aggregate.
- -- It replaces the call to Init (Args) done by Build_Task_Allocate_Block.
+ -- Ada 2005 (AI-287): Similar to previous routine, but used to expand
+ -- allocated aggregates with default initialized components. Init_Stmts
+ -- contains the list of statements required to initialize the allocated
+ -- aggregate. It replaces the call to Init (Args) done by
+ -- Build_Task_Allocate_Block.
function Concurrent_Ref (N : Node_Id) return Node_Id;
-- Given the name of a concurrent object (task or protected object), or
function Convert_Concurrent
(N : Node_Id;
- Typ : Entity_Id)
- return Node_Id;
- -- N is an expression of type Typ. If the type is not a concurrent
- -- type then it is returned unchanged. If it is a task or protected
- -- reference, Convert_Concurrent creates an unchecked conversion node
- -- from this expression to the corresponding concurrent record type
- -- value. We need this in any situation where the concurrent type is
- -- used, because the actual concurrent object is an object of the
- -- corresponding concurrent type, and manipulations on the concurrent
- -- object actually manipulate the corresponding object of the record
- -- type.
+ Typ : Entity_Id) return Node_Id;
+ -- N is an expression of type Typ. If the type is not a concurrent type
+ -- then it is returned unchanged. If it is a task or protected reference,
+ -- Convert_Concurrent creates an unchecked conversion node from this
+ -- expression to the corresponding concurrent record type value. We need
+ -- this in any situation where the concurrent type is used, because the
+ -- actual concurrent object is an object of the corresponding concurrent
+ -- type, and manipulations on the concurrent object actually manipulate the
+ -- corresponding object of the record type.
function Entry_Index_Expression
(Sloc : Source_Ptr;
procedure Establish_Task_Master (N : Node_Id);
-- Given a subprogram body, or a block statement, or a task body, this
- -- proccedure makes the necessary transformations required of a task
+ -- procedure makes the necessary transformations required of a task
-- master (add Enter_Master call at start, and establish a cleanup
-- routine to make sure Complete_Master is called on exit).
procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id);
- -- Build Equivalent_Type for an Access_to_protected_Subprogram.
+ -- Build Equivalent_Type for an Access_to_protected_Subprogram
procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id);
-- Expand declarations required for accept statement. See bodies of
-- Expand the entry barrier into a function. This is called directly
-- from Analyze_Entry_Body so that the discriminals and privals of the
-- barrier can be attached to the function declaration list, and a new
- -- set prepared for the entry body procedure, bedore the entry body
+ -- set prepared for the entry body procedure, before the entry body
-- statement sequence can be expanded. The resulting function is analyzed
-- now, within the context of the protected object, to resolve calls to
-- other protected functions.
- procedure Expand_Entry_Body_Declarations (N : Node_Id);
- -- Expand declarations required for the expansion of the
- -- statements of the body.
-
procedure Expand_N_Abort_Statement (N : Node_Id);
procedure Expand_N_Accept_Statement (N : Node_Id);
procedure Expand_N_Asynchronous_Select (N : Node_Id);
procedure Expand_N_Protected_Body (N : Node_Id);
procedure Expand_N_Protected_Type_Declaration (N : Node_Id);
- -- Expands protected type declarations. This results, among
- -- other things, in the declaration of a record type for the
- -- representation of protected objects and (if there are entries)
- -- in an entry service procedure. The Protection value used by
- -- the GNARL to control the object will always be the first
- -- field of the record, and the entry service procedure spec
- -- (if it exists) will always immediately follow the record
- -- declaration. This allows these two nodes to be found from
- -- the type using Corresponding_Record, without benefit of
- -- of further attributes.
+ -- Expands protected type declarations. This results, among other things,
+ -- in the declaration of a record type for the representation of protected
+ -- objects and (if there are entries) in an entry service procedure. The
+ -- Protection value used by the GNARL to control the object will always be
+ -- the first field of the record, and the entry service procedure spec (if
+ -- it exists) will always immediately follow the record declaration. This
+ -- allows these two nodes to be found from the type, without benefit of
+ -- further attributes, using Corresponding_Record.
procedure Expand_N_Requeue_Statement (N : Node_Id);
procedure Expand_N_Selective_Accept (N : Node_Id);
procedure Expand_Protected_Body_Declarations
(N : Node_Id;
Spec_Id : Entity_Id);
- -- Expand declarations required for a protected body. See bodies of
- -- both Expand_Protected_Body_Declarations and Expand_N_Protected_Body
- -- for full details of the nature and use of these declarations.
- -- The second argument is the entity for the corresponding
- -- protected type declaration.
+ -- Expand declarations required for a protected body. See bodies of both
+ -- Expand_Protected_Body_Declarations and Expand_N_Protected_Body for full
+ -- details of the nature and use of these declarations. The second argument
+ -- is the entity for the corresponding protected type declaration.
function External_Subprogram (E : Entity_Id) return Entity_Id;
-- return the external version of a protected operation, which locks
-- Given the declarations list for a protected body, find the
-- first protected operation body.
+ procedure Install_Private_Data_Declarations
+ (Loc : Source_Ptr;
+ Spec_Id : Entity_Id;
+ Conc_Typ : Entity_Id;
+ Body_Nod : Node_Id;
+ Decls : List_Id;
+ Barrier : Boolean := False;
+ Family : Boolean := False);
+ -- This routines generates several types, objects and object renamings used
+ -- in the handling of discriminants and private components of protected and
+ -- task types. It also generates the entry index for entry families. Formal
+ -- Spec_Id denotes an entry, entry family or a subprogram, Conc_Typ is the
+ -- concurrent type where Spec_Id resides, Body_Nod is the corresponding
+ -- body of Spec_Id, Decls are the declarations of the subprogram or entry.
+ -- Flag Barrier denotes whether the context is an entry barrier function.
+ -- Flag Family is used in conjunction with Barrier to denote a barrier for
+ -- an entry family.
+ --
+ -- The generated types, entities and renamings are:
+ --
+ -- * If flag Barrier is set or Spec_Id denotes a protected entry or an
+ -- entry family, generate:
+ --
+ -- type prot_typVP is access prot_typV;
+ -- _object : prot_typVP := prot_typV (_O);
+ --
+ -- where prot_typV is the corresponding record of a protected type and
+ -- _O is a formal parameter representing the concurrent object of either
+ -- the barrier function or the entry (family).
+ --
+ -- * If Conc_Typ is a protected type, create a renaming for the Protection
+ -- field _object:
+ --
+ -- conc_typR : protection_typ renames _object._object;
+ --
+ -- * If Conc_Typ has discriminants, create renamings of the form:
+ --
+ -- discr_nameD : discr_typ renames _object.discr_name;
+ -- or
+ -- discr_nameD : discr_typ renames _task.discr_name;
+ --
+ -- * If Conc_Typ denotes a protected type and has private components,
+ -- generate renamings of the form:
+ --
+ -- comp_name : comp_typ renames _object.comp_name;
+ --
+ -- * Finally, is flag Barrier and Family are set or Spec_Id denotes an
+ -- entry family, generate the entry index constant:
+ --
+ -- subtype Jnn is <Type of Index> range Low .. High;
+ -- J : constant Jnn :=
+ -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
+ --
+ -- All the above declarations are inserted in the order shown to the front
+ -- of Decls.
+
function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id;
-- Given the entity of the record type created for a task type, build
-- the call to Create_Task
function Make_Initialize_Protection
- (Protect_Rec : Entity_Id)
- return List_Id;
+ (Protect_Rec : Entity_Id) return List_Id;
-- Given the entity of the record type created for a protected type, build
-- a list of statements needed for proper initialization of the object.
function Next_Protected_Operation (N : Node_Id) return Node_Id;
- -- Given a protected operation node (a subprogram or entry body),
- -- find the following node in the declarations list.
+ -- Given a protected operation node (a subprogram or entry body), find the
+ -- following node in the declarations list.
procedure Set_Discriminals (Dec : Node_Id);
- -- Replace discriminals in a protected type for use by the
- -- next protected operation on the type. Each operation needs a
- -- new set of discirminals, since it needs a unique renaming of
- -- the discriminant fields in the record used to implement the
- -- protected type.
-
- procedure Set_Privals
- (Dec : Node_Id;
- Op : Node_Id;
- Loc : Source_Ptr);
- -- Associates a new set of privals (placeholders for later access to
- -- private components of protected objects) with the private object
- -- declarations of a protected object. These will be used to expand
- -- the references to private objects in the next protected
- -- subprogram or entry body to be expanded.
+ -- Replace discriminals in a protected type for use by the next protected
+ -- operation on the type. Each operation needs a new set of discriminals,
+ -- since it needs a unique renaming of the discriminant fields in the
+ -- record used to implement the protected type.
end Exp_Ch9;