| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- E X P _ C H 9 -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with Accessibility; use Accessibility; |
| 27 |
with Atree; use Atree; |
| 28 |
with Aspects; use Aspects; |
| 29 |
with Checks; use Checks; |
| 30 |
with Contracts; use Contracts; |
| 31 |
with Einfo; use Einfo; |
| 32 |
with Einfo.Entities; use Einfo.Entities; |
| 33 |
with Einfo.Utils; use Einfo.Utils; |
| 34 |
with Elists; use Elists; |
| 35 |
with Errout; use Errout; |
| 36 |
with Exp_Ch3; use Exp_Ch3; |
| 37 |
with Exp_Ch6; use Exp_Ch6; |
| 38 |
with Exp_Ch11; use Exp_Ch11; |
| 39 |
with Exp_Dbug; use Exp_Dbug; |
| 40 |
with Exp_Sel; use Exp_Sel; |
| 41 |
with Exp_Smem; use Exp_Smem; |
| 42 |
with Exp_Util; use Exp_Util; |
| 43 |
with Freeze; use Freeze; |
| 44 |
with Hostparm; |
| 45 |
with Itypes; use Itypes; |
| 46 |
with Namet; use Namet; |
| 47 |
with Nlists; use Nlists; |
| 48 |
with Nmake; use Nmake; |
| 49 |
with Opt; use Opt; |
| 50 |
with Restrict; use Restrict; |
| 51 |
with Rident; use Rident; |
| 52 |
with Rtsfind; use Rtsfind; |
| 53 |
with Sem; use Sem; |
| 54 |
with Sem_Aux; use Sem_Aux; |
| 55 |
with Sem_Ch5; use Sem_Ch5; |
| 56 |
with Sem_Ch6; use Sem_Ch6; |
| 57 |
with Sem_Ch8; use Sem_Ch8; |
| 58 |
with Sem_Ch9; use Sem_Ch9; |
| 59 |
with Sem_Ch11; use Sem_Ch11; |
| 60 |
with Sem_Ch13; use Sem_Ch13; |
| 61 |
with Sem_Elab; use Sem_Elab; |
| 62 |
with Sem_Eval; use Sem_Eval; |
| 63 |
with Sem_Res; use Sem_Res; |
| 64 |
with Sem_Util; use Sem_Util; |
| 65 |
with Sinfo; use Sinfo; |
| 66 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 67 |
with Sinfo.Utils; use Sinfo.Utils; |
| 68 |
with Snames; use Snames; |
| 69 |
with Stand; use Stand; |
| 70 |
with Targparm; use Targparm; |
| 71 |
with Tbuild; use Tbuild; |
| 72 |
with Uintp; use Uintp; |
| 73 |
with Validsw; use Validsw; |
| 74 |
|
| 75 |
package body Exp_Ch9 is |
| 76 |
|
| 77 |
-- The following constant establishes the upper bound for the index of |
| 78 |
-- an entry family. It is used to limit the allocated size of protected |
| 79 |
-- types with defaulted discriminant of an integer type, when the bound |
| 80 |
-- of some entry family depends on a discriminant. The limitation to entry |
| 81 |
-- families of 128K should be reasonable in all cases, and is a documented |
| 82 |
-- implementation restriction. |
| 83 |
|
| 84 |
Entry_Family_Bound : constant Pos := 2**16; |
| 85 |
|
| 86 |
----------------------- |
| 87 |
-- Local Subprograms -- |
| 88 |
----------------------- |
| 89 |
|
| 90 |
function Actual_Index_Expression |
| 91 |
(Sloc : Source_Ptr; |
| 92 |
Ent : Entity_Id; |
| 93 |
Index : Node_Id; |
| 94 |
Tsk : Entity_Id) return Node_Id; |
| 95 |
-- Compute the index position for an entry call. Tsk is the target task. If |
| 96 |
-- the bounds of some entry family depend on discriminants, the expression |
| 97 |
-- computed by this function uses the discriminants of the target task. |
| 98 |
|
| 99 |
procedure Add_Object_Pointer |
| 100 |
(Loc : Source_Ptr; |
| 101 |
Conc_Typ : Entity_Id; |
| 102 |
Decls : List_Id); |
| 103 |
-- Prepend an object pointer declaration to the declaration list Decls. |
| 104 |
-- This object pointer is initialized to a type conversion of the System. |
| 105 |
-- Address pointer passed to entry barrier functions and entry body |
| 106 |
-- procedures. |
| 107 |
|
| 108 |
procedure Add_Formal_Renamings |
| 109 |
(Spec : Node_Id; |
| 110 |
Decls : List_Id; |
| 111 |
Ent : Entity_Id; |
| 112 |
Loc : Source_Ptr); |
| 113 |
-- Create renaming declarations for the formals, inside the procedure that |
| 114 |
-- implements an entry body. The renamings make the original names of the |
| 115 |
-- formals accessible to gdb, and serve no other purpose. |
| 116 |
-- Spec is the specification of the procedure being built. |
| 117 |
-- Decls is the list of declarations to be enhanced. |
| 118 |
-- Ent is the entity for the original entry body. |
| 119 |
|
| 120 |
function Build_Accept_Body (Astat : Node_Id) return Node_Id; |
| 121 |
-- Transform accept statement into a block with added exception handler. |
| 122 |
-- Used both for simple accept statements and for accept alternatives in |
| 123 |
-- select statements. Astat is the accept statement. |
| 124 |
|
| 125 |
function Build_Barrier_Function |
| 126 |
(N : Node_Id; |
| 127 |
Ent : Entity_Id; |
| 128 |
Pid : Entity_Id) return Node_Id; |
| 129 |
-- Build the function body returning the value of the barrier expression |
| 130 |
-- for the specified entry body. |
| 131 |
|
| 132 |
function Build_Barrier_Function_Specification |
| 133 |
(Loc : Source_Ptr; |
| 134 |
Def_Id : Entity_Id) return Node_Id; |
| 135 |
-- Build a specification for a function implementing the protected entry |
| 136 |
-- barrier of the specified entry body. |
| 137 |
|
| 138 |
function Build_Corresponding_Record |
| 139 |
(N : Node_Id; |
| 140 |
Ctyp : Entity_Id; |
| 141 |
Loc : Source_Ptr) return Node_Id; |
| 142 |
-- Common to tasks and protected types. Copy discriminant specifications, |
| 143 |
-- build record declaration. N is the type declaration, Ctyp is the |
| 144 |
-- concurrent entity (task type or protected type). |
| 145 |
|
| 146 |
function Build_Dispatching_Tag_Check |
| 147 |
(K : Entity_Id; |
| 148 |
N : Node_Id) return Node_Id; |
| 149 |
-- Utility to create the tree to check whether the dispatching call in |
| 150 |
-- a timed entry call, a conditional entry call, or an asynchronous |
| 151 |
-- transfer of control is a call to a primitive of a non-synchronized type. |
| 152 |
-- K is the temporary that holds the tagged kind of the target object, and |
| 153 |
-- N is the enclosing construct. |
| 154 |
|
| 155 |
function Build_Entry_Count_Expression |
| 156 |
(Concurrent_Type : Entity_Id; |
| 157 |
Loc : Source_Ptr) return Node_Id; |
| 158 |
-- Compute number of entries for concurrent object. This is a count of |
| 159 |
-- simple entries, followed by an expression that computes the length |
| 160 |
-- of the range of each entry family. A single array with that size is |
| 161 |
-- allocated for each concurrent object of the type. |
| 162 |
|
| 163 |
function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id; |
| 164 |
-- Build the function that translates the entry index in the call |
| 165 |
-- (which depends on the size of entry families) into an index into the |
| 166 |
-- Entry_Bodies_Array, to determine the body and barrier function used |
| 167 |
-- in a protected entry call. A pointer to this function appears in every |
| 168 |
-- protected object. |
| 169 |
|
| 170 |
function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id; |
| 171 |
-- Build subprogram declaration for previous one |
| 172 |
|
| 173 |
function Build_Lock_Free_Protected_Subprogram_Body |
| 174 |
(N : Node_Id; |
| 175 |
Prot_Typ : Node_Id; |
| 176 |
Unprot_Spec : Node_Id) return Node_Id; |
| 177 |
-- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is |
| 178 |
-- the subprogram specification of the unprotected version of N. Transform |
| 179 |
-- N such that it invokes the unprotected version of the body. |
| 180 |
|
| 181 |
function Build_Lock_Free_Unprotected_Subprogram_Body |
| 182 |
(N : Node_Id; |
| 183 |
Prot_Typ : Node_Id) return Node_Id; |
| 184 |
-- N denotes a subprogram body of protected type Prot_Typ. Build a version |
| 185 |
-- of N where the original statements of N are synchronized through atomic |
| 186 |
-- actions such as compare and exchange. Prior to invoking this routine, it |
| 187 |
-- has been established that N can be implemented in a lock-free fashion. |
| 188 |
|
| 189 |
function Build_Parameter_Block |
| 190 |
(Loc : Source_Ptr; |
| 191 |
Actuals : List_Id; |
| 192 |
Formals : List_Id; |
| 193 |
Decls : List_Id) return Entity_Id; |
| 194 |
-- Generate an access type for each actual parameter in the list Actuals. |
| 195 |
-- Create an encapsulating record that contains all the actuals and return |
| 196 |
-- its type. Generate: |
| 197 |
-- type Ann1 is access all <actual1-type> |
| 198 |
-- ... |
| 199 |
-- type AnnN is access all <actualN-type> |
| 200 |
-- type Pnn is record |
| 201 |
-- <formal1> : Ann1; |
| 202 |
-- ... |
| 203 |
-- <formalN> : AnnN; |
| 204 |
-- end record; |
| 205 |
|
| 206 |
function Build_Protected_Entry |
| 207 |
(N : Node_Id; |
| 208 |
Ent : Entity_Id; |
| 209 |
Pid : Node_Id) return Node_Id; |
| 210 |
-- Build the procedure implementing the statement sequence of the specified |
| 211 |
-- entry body. |
| 212 |
|
| 213 |
function Build_Protected_Entry_Specification |
| 214 |
(Loc : Source_Ptr; |
| 215 |
Def_Id : Entity_Id; |
| 216 |
Ent_Id : Entity_Id) return Node_Id; |
| 217 |
-- Build a specification for the procedure implementing the statements of |
| 218 |
-- the specified entry body. Add attributes associating it with the entry |
| 219 |
-- defining identifier Ent_Id. |
| 220 |
|
| 221 |
function Build_Protected_Spec |
| 222 |
(N : Node_Id; |
| 223 |
Obj_Type : Entity_Id; |
| 224 |
Ident : Entity_Id; |
| 225 |
Unprotected : Boolean := False) return List_Id; |
| 226 |
-- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_ |
| 227 |
-- Subprogram_Type. Builds signature of protected subprogram, adding the |
| 228 |
-- formal that corresponds to the object itself. For an access to protected |
| 229 |
-- subprogram, there is no object type to specify, so the parameter has |
| 230 |
-- type Address and mode In. An indirect call through such a pointer will |
| 231 |
-- convert the address to a reference to the actual object. The object is |
| 232 |
-- a limited record and therefore a by_reference type. |
| 233 |
|
| 234 |
function Build_Protected_Subprogram_Body |
| 235 |
(N : Node_Id; |
| 236 |
Pid : Node_Id; |
| 237 |
N_Op_Spec : Node_Id) return Node_Id; |
| 238 |
-- This function is used to construct the protected version of a protected |
| 239 |
-- subprogram. Its statement sequence first defers abort, then locks the |
| 240 |
-- associated protected object, and then enters a block that contains a |
| 241 |
-- call to the unprotected version of the subprogram (for details, see |
| 242 |
-- Build_Unprotected_Subprogram_Body). This block statement requires a |
| 243 |
-- cleanup handler that unlocks the object in all cases. For details, |
| 244 |
-- see Exp_Ch7.Expand_Cleanup_Actions. |
| 245 |
|
| 246 |
function Build_Renamed_Formal_Declaration |
| 247 |
(New_F : Entity_Id; |
| 248 |
Formal : Entity_Id; |
| 249 |
Comp : Entity_Id; |
| 250 |
Renamed_Formal : Node_Id) return Node_Id; |
| 251 |
-- Create a renaming declaration for a formal, within a protected entry |
| 252 |
-- body or an accept body. The renamed object is a component of the |
| 253 |
-- parameter block that is a parameter in the entry call. |
| 254 |
-- |
| 255 |
-- In Ada 2012, if the formal is an incomplete tagged type, the renaming |
| 256 |
-- does not dereference the corresponding component to prevent an illegal |
| 257 |
-- use of the incomplete type (AI05-0151). |
| 258 |
|
| 259 |
function Build_Selected_Name |
| 260 |
(Prefix : Entity_Id; |
| 261 |
Selector : Entity_Id; |
| 262 |
Append_Char : Character := ' ') return Name_Id; |
| 263 |
-- Build a name in the form of Prefix__Selector, with an optional character |
| 264 |
-- appended. This is used for internal subprograms generated for operations |
| 265 |
-- of protected types, including barrier functions. For the subprograms |
| 266 |
-- generated for entry bodies and entry barriers, the generated name |
| 267 |
-- includes a sequence number that makes names unique in the presence of |
| 268 |
-- entry overloading. This is necessary because entry body procedures and |
| 269 |
-- barrier functions all have the same signature. |
| 270 |
|
| 271 |
procedure Build_Simple_Entry_Call |
| 272 |
(N : Node_Id; |
| 273 |
Concval : Node_Id; |
| 274 |
Ename : Node_Id; |
| 275 |
Index : Node_Id); |
| 276 |
-- Build the call corresponding to the task entry call. N is the task entry |
| 277 |
-- call, Concval is the concurrent object, Ename is the entry name and |
| 278 |
-- Index is the entry family index. |
| 279 |
-- Note that N might be expanded into an N_Block_Statement if it gets |
| 280 |
-- inlined. |
| 281 |
|
| 282 |
function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id; |
| 283 |
-- This routine constructs a specification for the procedure that we will |
| 284 |
-- build for the task body for task type T. The spec has the form: |
| 285 |
-- |
| 286 |
-- procedure tnameB (_Task : access tnameV); |
| 287 |
-- |
| 288 |
-- where name is the character name taken from the task type entity that |
| 289 |
-- is passed as the argument to the procedure, and tnameV is the task |
| 290 |
-- value type that is associated with the task type. |
| 291 |
|
| 292 |
function Build_Unprotected_Subprogram_Body |
| 293 |
(N : Node_Id; |
| 294 |
Pid : Node_Id) return Node_Id; |
| 295 |
-- This routine constructs the unprotected version of a protected |
| 296 |
-- subprogram body, which contains all of the code in the original, |
| 297 |
-- unexpanded body. This is the version of the protected subprogram that is |
| 298 |
-- called from all protected operations on the same object, including the |
| 299 |
-- protected version of the same subprogram. |
| 300 |
|
| 301 |
procedure Build_Wrapper_Bodies |
| 302 |
(Loc : Source_Ptr; |
| 303 |
Typ : Entity_Id; |
| 304 |
N : Node_Id); |
| 305 |
-- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding |
| 306 |
-- record of a concurrent type. N is the insertion node where all bodies |
| 307 |
-- will be placed. This routine builds the bodies of the subprograms which |
| 308 |
-- serve as an indirection mechanism to overriding primitives of concurrent |
| 309 |
-- types, entries and protected procedures. Any new body is analyzed. |
| 310 |
|
| 311 |
procedure Build_Wrapper_Specs |
| 312 |
(Loc : Source_Ptr; |
| 313 |
Typ : Entity_Id; |
| 314 |
N : in out Node_Id); |
| 315 |
-- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding |
| 316 |
-- record of a concurrent type. N is the insertion node where all specs |
| 317 |
-- will be placed. This routine builds the specs of the subprograms which |
| 318 |
-- serve as an indirection mechanism to overriding primitives of concurrent |
| 319 |
-- types, entries and protected procedures. Any new spec is analyzed. |
| 320 |
|
| 321 |
procedure Collect_Entry_Families |
| 322 |
(Loc : Source_Ptr; |
| 323 |
Cdecls : List_Id; |
| 324 |
Current_Node : in out Node_Id; |
| 325 |
Conctyp : Entity_Id); |
| 326 |
-- For each entry family in a concurrent type, create an anonymous array |
| 327 |
-- type of the right size, and add a component to the corresponding_record. |
| 328 |
|
| 329 |
function Concurrent_Object |
| 330 |
(Spec_Id : Entity_Id; |
| 331 |
Conc_Typ : Entity_Id) return Entity_Id; |
| 332 |
-- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return |
| 333 |
-- the entity associated with the concurrent object in the Protected_Body_ |
| 334 |
-- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity |
| 335 |
-- denotes formal parameter _O, _object or _task. |
| 336 |
|
| 337 |
function Copy_Result_Type (Res : Node_Id) return Node_Id; |
| 338 |
-- Copy the result type of a function specification, when building the |
| 339 |
-- internal operation corresponding to a protected function, or when |
| 340 |
-- expanding an access to protected function. If the result is an anonymous |
| 341 |
-- access to subprogram itself, we need to create a new signature with the |
| 342 |
-- same parameter names and the same resolved types, but with new entities |
| 343 |
-- for the formals. |
| 344 |
|
| 345 |
function Create_Secondary_Stack_For_Task (T : Node_Id) return Boolean; |
| 346 |
-- Return whether a secondary stack for the task T should be created by the |
| 347 |
-- expander. The secondary stack for a task will be created by the expander |
| 348 |
-- if the size of the stack has been specified by the Secondary_Stack_Size |
| 349 |
-- representation aspect and either the No_Implicit_Heap_Allocations or |
| 350 |
-- No_Implicit_Task_Allocations restrictions are in effect and the |
| 351 |
-- No_Secondary_Stack restriction is not. |
| 352 |
|
| 353 |
procedure Debug_Private_Data_Declarations (Decls : List_Id); |
| 354 |
-- Decls is a list which may contain the declarations created by Install_ |
| 355 |
-- Private_Data_Declarations. All generated entities are marked as needing |
| 356 |
-- debug info and debug nodes are manually generation where necessary. This |
| 357 |
-- step of the expansion must to be done after private data has been moved |
| 358 |
-- to its final resting scope to ensure proper visibility of debug objects. |
| 359 |
|
| 360 |
procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id); |
| 361 |
-- If control flow optimizations are suppressed, and Alt is an accept, |
| 362 |
-- delay, or entry call alternative with no trailing statements, insert |
| 363 |
-- a null trailing statement with the given Loc (which is the sloc of |
| 364 |
-- the accept, delay, or entry call statement). There might not be any |
| 365 |
-- generated code for the accept, delay, or entry call itself (the effect |
| 366 |
-- of these statements is part of the general processing done for the |
| 367 |
-- enclosing selective accept, timed entry call, or asynchronous select), |
| 368 |
-- and the null statement is there to carry the sloc of that statement to |
| 369 |
-- the back-end for trace-based coverage analysis purposes. |
| 370 |
|
| 371 |
procedure Extract_Dispatching_Call |
| 372 |
(N : Node_Id; |
| 373 |
Call_Ent : out Entity_Id; |
| 374 |
Object : out Entity_Id; |
| 375 |
Actuals : out List_Id; |
| 376 |
Formals : out List_Id); |
| 377 |
-- Given a dispatching call, extract the entity of the name of the call, |
| 378 |
-- its actual dispatching object, its actual parameters and the formal |
| 379 |
-- parameters of the overridden interface-level version. If the type of |
| 380 |
-- the dispatching object is an access type then an explicit dereference |
| 381 |
-- is returned in Object. |
| 382 |
|
| 383 |
procedure Extract_Entry |
| 384 |
(N : Node_Id; |
| 385 |
Concval : out Node_Id; |
| 386 |
Ename : out Node_Id; |
| 387 |
Index : out Node_Id); |
| 388 |
-- Given an entry call, returns the associated concurrent object, the entry |
| 389 |
-- name, and the entry family index. |
| 390 |
|
| 391 |
function Family_Offset |
| 392 |
(Loc : Source_Ptr; |
| 393 |
Hi : Node_Id; |
| 394 |
Lo : Node_Id; |
| 395 |
Ttyp : Entity_Id; |
| 396 |
Cap : Boolean) return Node_Id; |
| 397 |
-- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an |
| 398 |
-- accept statement, or the upper bound in the discrete subtype of an entry |
| 399 |
-- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent |
| 400 |
-- type of the entry. If Cap is true, the result is capped according to |
| 401 |
-- Entry_Family_Bound. |
| 402 |
|
| 403 |
function Family_Size |
| 404 |
(Loc : Source_Ptr; |
| 405 |
Hi : Node_Id; |
| 406 |
Lo : Node_Id; |
| 407 |
Ttyp : Entity_Id; |
| 408 |
Cap : Boolean) return Node_Id; |
| 409 |
-- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a |
| 410 |
-- family, and handle properly the superflat case. This is equivalent to |
| 411 |
-- the use of 'Length on the index type, but must use Family_Offset to |
| 412 |
-- handle properly the case of bounds that depend on discriminants. If |
| 413 |
-- Cap is true, the result is capped according to Entry_Family_Bound. |
| 414 |
|
| 415 |
procedure Find_Enclosing_Context |
| 416 |
(N : Node_Id; |
| 417 |
Context : out Node_Id; |
| 418 |
Context_Id : out Entity_Id; |
| 419 |
Context_Decls : out List_Id); |
| 420 |
-- Subsidiary routine to procedures Build_Activation_Chain_Entity and |
| 421 |
-- Build_Master_Entity. Given an arbitrary node in the tree, find the |
| 422 |
-- nearest enclosing body, block, package, or return statement and return |
| 423 |
-- its constituents. Context is the enclosing construct, Context_Id is |
| 424 |
-- the scope of Context_Id and Context_Decls is the declarative list of |
| 425 |
-- Context. |
| 426 |
|
| 427 |
function Index_Object (Spec_Id : Entity_Id) return Entity_Id; |
| 428 |
-- Given a subprogram identifier, return the entity which is associated |
| 429 |
-- with the protection entry index in the Protected_Body_Subprogram or |
| 430 |
-- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal |
| 431 |
-- parameter _E. |
| 432 |
|
| 433 |
function Is_Potentially_Large_Family |
| 434 |
(Base_Index : Entity_Id; |
| 435 |
Conctyp : Entity_Id; |
| 436 |
Lo : Node_Id; |
| 437 |
Hi : Node_Id) return Boolean; |
| 438 |
-- Determine whether an entry family is potentially large because one of |
| 439 |
-- its bounds denotes a discrminant. |
| 440 |
|
| 441 |
function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean; |
| 442 |
-- Determine whether Id is a function or a procedure and is marked as a |
| 443 |
-- private primitive. |
| 444 |
|
| 445 |
function Make_Unlock_Statement |
| 446 |
(Prot_Type : E_Protected_Type_Id; |
| 447 |
Op_Spec : N_Subprogram_Specification_Id; |
| 448 |
Loc : Source_Ptr) return N_Procedure_Call_Statement_Id; |
| 449 |
-- Build a statement that is suitable to unlock an object of type Prot_Type |
| 450 |
-- after having performed a protected operation on it. Prot_Type and |
| 451 |
-- Op_Spec are used to determine which unlocking subprogram to call, and |
| 452 |
-- whether to serve entries before unlocking. |
| 453 |
|
| 454 |
function Null_Statements (Stats : List_Id) return Boolean; |
| 455 |
-- Used to check DO-END sequence. Checks for equivalent of DO NULL; END. |
| 456 |
-- Allows labels, and pragma Warnings/Unreferenced in the sequence as well |
| 457 |
-- to still count as null. Returns True for a null sequence. The argument |
| 458 |
-- is the list of statements from the DO-END sequence. |
| 459 |
|
| 460 |
function Parameter_Block_Pack |
| 461 |
(Loc : Source_Ptr; |
| 462 |
Blk_Typ : Entity_Id; |
| 463 |
Actuals : List_Id; |
| 464 |
Formals : List_Id; |
| 465 |
Decls : List_Id; |
| 466 |
Stmts : List_Id) return Entity_Id; |
| 467 |
-- Set the components of the generated parameter block with the values |
| 468 |
-- of the actual parameters. Generate aliased temporaries to capture the |
| 469 |
-- values for types that are passed by copy. Otherwise generate a reference |
| 470 |
-- to the actual's value. Return the address of the aggregate block. |
| 471 |
-- Generate: |
| 472 |
-- Jnn1 : alias <formal-type1>; |
| 473 |
-- Jnn1 := <actual1>; |
| 474 |
-- ... |
| 475 |
-- P : Blk_Typ := ( |
| 476 |
-- Jnn1'unchecked_access; |
| 477 |
-- <actual2>'reference; |
| 478 |
-- ...); |
| 479 |
|
| 480 |
function Parameter_Block_Unpack |
| 481 |
(Loc : Source_Ptr; |
| 482 |
P : Entity_Id; |
| 483 |
Actuals : List_Id; |
| 484 |
Formals : List_Id) return List_Id; |
| 485 |
-- Retrieve the values of the components from the parameter block and |
| 486 |
-- assign then to the original actual parameters. Generate: |
| 487 |
-- <actual1> := P.<formal1>; |
| 488 |
-- ... |
| 489 |
-- <actualN> := P.<formalN>; |
| 490 |
|
| 491 |
procedure Reset_Scopes_To (Bod : Node_Id; E : Entity_Id); |
| 492 |
-- Reset the scope of declarations and blocks at the top level of Bod and |
| 493 |
-- of nested object declarations with scope pointing to the entry entity to |
| 494 |
-- be E. Bod is either a block or a subprogram body. Used after expanding |
| 495 |
-- various kinds of entry bodies into their corresponding constructs. This |
| 496 |
-- is needed during unnesting to determine whether a body generated for an |
| 497 |
-- entry or an accept alternative includes uplevel references. |
| 498 |
|
| 499 |
function Trivial_Accept_OK return Boolean; |
| 500 |
-- If there is no DO-END block for an accept, or if the DO-END block has |
| 501 |
-- only null statements, then it is possible to do the Rendezvous with much |
| 502 |
-- less overhead using the Accept_Trivial routine in the run-time library. |
| 503 |
-- However, this is not always a valid optimization. Whether it is valid or |
| 504 |
-- not depends on the Task_Dispatching_Policy. The issue is whether a full |
| 505 |
-- rescheduling action is required or not. In FIFO_Within_Priorities, such |
| 506 |
-- a rescheduling is required, so this optimization is not allowed. This |
| 507 |
-- function returns True if the optimization is permitted. |
| 508 |
|
| 509 |
function Wrap_Unprotected_Call |
| 510 |
(Call : Node_Id; |
| 511 |
Prot_Type : E_Protected_Type_Id; |
| 512 |
Op_Spec : N_Subprogram_Specification_Id; |
| 513 |
Loc : Source_Ptr) return N_Block_Statement_Id; |
| 514 |
-- Wrap Call into a block statement with a cleanup procedure set up to |
| 515 |
-- release the lock on a protected object of type Prot_Type. Call must be |
| 516 |
-- a statement that represents the inner and unprotected execution of the |
| 517 |
-- body of a protected operation. Op_Spec must be the spec of that |
| 518 |
-- protected operation. This is a subsidiary subprogram of |
| 519 |
-- Build_Protected_Subprogram_Body. |
| 520 |
|
| 521 |
----------------------------- |
| 522 |
-- Actual_Index_Expression -- |
| 523 |
----------------------------- |
| 524 |
|
| 525 |
function Actual_Index_Expression |
| 526 |
(Sloc : Source_Ptr; |
| 527 |
Ent : Entity_Id; |
| 528 |
Index : Node_Id; |
| 529 |
Tsk : Entity_Id) return Node_Id |
| 530 |
is |
| 531 |
Ttyp : constant Entity_Id := Etype (Tsk); |
| 532 |
Expr : Node_Id; |
| 533 |
Num : Node_Id; |
| 534 |
Lo : Node_Id; |
| 535 |
Hi : Node_Id; |
| 536 |
Prev : Entity_Id; |
| 537 |
S : Node_Id; |
| 538 |
|
| 539 |
function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id; |
| 540 |
-- Compute difference between bounds of entry family |
| 541 |
|
| 542 |
-------------------------- |
| 543 |
-- Actual_Family_Offset -- |
| 544 |
-------------------------- |
| 545 |
|
| 546 |
function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is |
| 547 |
|
| 548 |
function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id; |
| 549 |
-- Replace a reference to a discriminant with a selected component |
| 550 |
-- denoting the discriminant of the target task. |
| 551 |
|
| 552 |
----------------------------- |
| 553 |
-- Actual_Discriminant_Ref -- |
| 554 |
----------------------------- |
| 555 |
|
| 556 |
function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is |
| 557 |
Typ : constant Entity_Id := Etype (Bound); |
| 558 |
B : Node_Id; |
| 559 |
|
| 560 |
begin |
| 561 |
if not Is_Entity_Name (Bound) |
| 562 |
or else Ekind (Entity (Bound)) /= E_Discriminant |
| 563 |
then |
| 564 |
if Nkind (Bound) = N_Attribute_Reference then |
| 565 |
return Bound; |
| 566 |
else |
| 567 |
B := New_Copy_Tree (Bound); |
| 568 |
end if; |
| 569 |
|
| 570 |
else |
| 571 |
B := |
| 572 |
Make_Selected_Component (Sloc, |
| 573 |
Prefix => New_Copy_Tree (Tsk), |
| 574 |
Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc)); |
| 575 |
|
| 576 |
Analyze_And_Resolve (B, Typ); |
| 577 |
end if; |
| 578 |
|
| 579 |
return |
| 580 |
Make_Attribute_Reference (Sloc, |
| 581 |
Attribute_Name => Name_Pos, |
| 582 |
Prefix => New_Occurrence_Of (Etype (Bound), Sloc), |
| 583 |
Expressions => New_List (B)); |
| 584 |
end Actual_Discriminant_Ref; |
| 585 |
|
| 586 |
-- Start of processing for Actual_Family_Offset |
| 587 |
|
| 588 |
begin |
| 589 |
return |
| 590 |
Make_Op_Subtract (Sloc, |
| 591 |
Left_Opnd => Actual_Discriminant_Ref (Hi), |
| 592 |
Right_Opnd => Actual_Discriminant_Ref (Lo)); |
| 593 |
end Actual_Family_Offset; |
| 594 |
|
| 595 |
-- Start of processing for Actual_Index_Expression |
| 596 |
|
| 597 |
begin |
| 598 |
-- The queues of entries and entry families appear in textual order in |
| 599 |
-- the associated record. The entry index is computed as the sum of the |
| 600 |
-- number of queues for all entries that precede the designated one, to |
| 601 |
-- which is added the index expression, if this expression denotes a |
| 602 |
-- member of a family. |
| 603 |
|
| 604 |
-- The following is a place holder for the count of simple entries |
| 605 |
|
| 606 |
Num := Make_Integer_Literal (Sloc, 1); |
| 607 |
|
| 608 |
-- We construct an expression which is a series of addition operations. |
| 609 |
-- See comments in Entry_Index_Expression, which is identical in |
| 610 |
-- structure. |
| 611 |
|
| 612 |
if Present (Index) then |
| 613 |
S := Entry_Index_Type (Ent); |
| 614 |
|
| 615 |
-- First make sure the index is in range if requested. The index type |
| 616 |
-- has been directly set on the prefix, see Resolve_Entry. |
| 617 |
|
| 618 |
if Do_Range_Check (Index) then |
| 619 |
Generate_Range_Check |
| 620 |
(Index, Etype (Prefix (Parent (Index))), CE_Range_Check_Failed); |
| 621 |
end if; |
| 622 |
|
| 623 |
Expr := |
| 624 |
Make_Op_Add (Sloc, |
| 625 |
Left_Opnd => Num, |
| 626 |
Right_Opnd => |
| 627 |
Actual_Family_Offset ( |
| 628 |
Make_Attribute_Reference (Sloc, |
| 629 |
Attribute_Name => Name_Pos, |
| 630 |
Prefix => New_Occurrence_Of (Base_Type (S), Sloc), |
| 631 |
Expressions => New_List (Relocate_Node (Index))), |
| 632 |
Type_Low_Bound (S))); |
| 633 |
else |
| 634 |
Expr := Num; |
| 635 |
end if; |
| 636 |
|
| 637 |
-- Now add lengths of preceding entries and entry families |
| 638 |
|
| 639 |
Prev := First_Entity (Ttyp); |
| 640 |
while Chars (Prev) /= Chars (Ent) |
| 641 |
or else Ekind (Prev) /= Ekind (Ent) |
| 642 |
or else not Sem_Ch6.Type_Conformant (Ent, Prev) |
| 643 |
loop |
| 644 |
if Ekind (Prev) = E_Entry then |
| 645 |
Set_Intval (Num, Intval (Num) + 1); |
| 646 |
|
| 647 |
elsif Ekind (Prev) = E_Entry_Family then |
| 648 |
S := Entry_Index_Type (Prev); |
| 649 |
|
| 650 |
-- The need for the following full view retrieval stems from this |
| 651 |
-- complex case of nested generics and tasking: |
| 652 |
|
| 653 |
-- generic |
| 654 |
-- type Formal_Index is range <>; |
| 655 |
-- ... |
| 656 |
-- package Outer is |
| 657 |
-- type Index is private; |
| 658 |
-- generic |
| 659 |
-- ... |
| 660 |
-- package Inner is |
| 661 |
-- procedure P; |
| 662 |
-- end Inner; |
| 663 |
-- private |
| 664 |
-- type Index is new Formal_Index range 1 .. 10; |
| 665 |
-- end Outer; |
| 666 |
|
| 667 |
-- package body Outer is |
| 668 |
-- task type T is |
| 669 |
-- entry Fam (Index); -- (2) |
| 670 |
-- entry E; |
| 671 |
-- end T; |
| 672 |
-- package body Inner is -- (3) |
| 673 |
-- procedure P is |
| 674 |
-- begin |
| 675 |
-- T.E; -- (1) |
| 676 |
-- end P; |
| 677 |
-- end Inner; |
| 678 |
-- ... |
| 679 |
|
| 680 |
-- We are currently building the index expression for the entry |
| 681 |
-- call "T.E" (1). Part of the expansion must mention the range |
| 682 |
-- of the discrete type "Index" (2) of entry family "Fam". |
| 683 |
|
| 684 |
-- However only the private view of type "Index" is available to |
| 685 |
-- the inner generic (3) because there was no prior mention of |
| 686 |
-- the type inside "Inner". This visibility requirement is |
| 687 |
-- implicit and cannot be detected during the construction of |
| 688 |
-- the generic trees and needs special handling. |
| 689 |
|
| 690 |
if In_Instance_Body |
| 691 |
and then Is_Private_Type (S) |
| 692 |
and then Present (Full_View (S)) |
| 693 |
then |
| 694 |
S := Full_View (S); |
| 695 |
end if; |
| 696 |
|
| 697 |
Lo := Type_Low_Bound (S); |
| 698 |
Hi := Type_High_Bound (S); |
| 699 |
|
| 700 |
Expr := |
| 701 |
Make_Op_Add (Sloc, |
| 702 |
Left_Opnd => Expr, |
| 703 |
Right_Opnd => |
| 704 |
Make_Op_Add (Sloc, |
| 705 |
Left_Opnd => Actual_Family_Offset (Hi, Lo), |
| 706 |
Right_Opnd => Make_Integer_Literal (Sloc, 1))); |
| 707 |
|
| 708 |
-- Other components are anonymous types to be ignored |
| 709 |
|
| 710 |
else |
| 711 |
null; |
| 712 |
end if; |
| 713 |
|
| 714 |
Next_Entity (Prev); |
| 715 |
end loop; |
| 716 |
|
| 717 |
return Expr; |
| 718 |
end Actual_Index_Expression; |
| 719 |
|
| 720 |
-------------------------- |
| 721 |
-- Add_Formal_Renamings -- |
| 722 |
-------------------------- |
| 723 |
|
| 724 |
procedure Add_Formal_Renamings |
| 725 |
(Spec : Node_Id; |
| 726 |
Decls : List_Id; |
| 727 |
Ent : Entity_Id; |
| 728 |
Loc : Source_Ptr) |
| 729 |
is |
| 730 |
Ptr : constant Entity_Id := |
| 731 |
Defining_Identifier |
| 732 |
(Next (First (Parameter_Specifications (Spec)))); |
| 733 |
-- The name of the formal that holds the address of the parameter block |
| 734 |
-- for the call. |
| 735 |
|
| 736 |
Comp : Entity_Id; |
| 737 |
Decl : Node_Id; |
| 738 |
Formal : Entity_Id; |
| 739 |
New_F : Entity_Id; |
| 740 |
Renamed_Formal : Node_Id; |
| 741 |
|
| 742 |
begin |
| 743 |
Formal := First_Formal (Ent); |
| 744 |
while Present (Formal) loop |
| 745 |
Comp := Entry_Component (Formal); |
| 746 |
New_F := |
| 747 |
Make_Defining_Identifier (Sloc (Formal), |
| 748 |
Chars => Chars (Formal)); |
| 749 |
Set_Etype (New_F, Etype (Formal)); |
| 750 |
Set_Scope (New_F, Ent); |
| 751 |
|
| 752 |
-- Now we set debug info needed on New_F even though it does not come |
| 753 |
-- from source, so that the debugger will get the right information |
| 754 |
-- for these generated names. |
| 755 |
|
| 756 |
Set_Debug_Info_Needed (New_F); |
| 757 |
|
| 758 |
if Ekind (Formal) = E_In_Parameter then |
| 759 |
Mutate_Ekind (New_F, E_Constant); |
| 760 |
else |
| 761 |
Mutate_Ekind (New_F, E_Variable); |
| 762 |
Set_Extra_Constrained (New_F, Extra_Constrained (Formal)); |
| 763 |
end if; |
| 764 |
|
| 765 |
Set_Actual_Subtype (New_F, Actual_Subtype (Formal)); |
| 766 |
|
| 767 |
Renamed_Formal := |
| 768 |
Make_Selected_Component (Loc, |
| 769 |
Prefix => |
| 770 |
Make_Explicit_Dereference (Loc, |
| 771 |
Unchecked_Convert_To (Entry_Parameters_Type (Ent), |
| 772 |
Make_Identifier (Loc, Chars (Ptr)))), |
| 773 |
Selector_Name => New_Occurrence_Of (Comp, Loc)); |
| 774 |
|
| 775 |
Decl := |
| 776 |
Build_Renamed_Formal_Declaration |
| 777 |
(New_F, Formal, Comp, Renamed_Formal); |
| 778 |
|
| 779 |
Append (Decl, Decls); |
| 780 |
Set_Renamed_Object (Formal, New_F); |
| 781 |
Next_Formal (Formal); |
| 782 |
end loop; |
| 783 |
end Add_Formal_Renamings; |
| 784 |
|
| 785 |
------------------------ |
| 786 |
-- Add_Object_Pointer -- |
| 787 |
------------------------ |
| 788 |
|
| 789 |
procedure Add_Object_Pointer |
| 790 |
(Loc : Source_Ptr; |
| 791 |
Conc_Typ : Entity_Id; |
| 792 |
Decls : List_Id) |
| 793 |
is |
| 794 |
Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ); |
| 795 |
Decl : Node_Id; |
| 796 |
Obj_Ptr : Node_Id; |
| 797 |
|
| 798 |
begin |
| 799 |
-- Create the renaming declaration for the Protection object of a |
| 800 |
-- protected type. _Object is used by Complete_Entry_Body. |
| 801 |
-- ??? An attempt to make this a renaming was unsuccessful. |
| 802 |
|
| 803 |
-- Build the entity for the access type |
| 804 |
|
| 805 |
Obj_Ptr := |
| 806 |
Make_Defining_Identifier (Loc, |
| 807 |
New_External_Name (Chars (Rec_Typ), 'P')); |
| 808 |
|
| 809 |
-- Generate: |
| 810 |
-- _object : poVP := poVP!O; |
| 811 |
|
| 812 |
Decl := |
| 813 |
Make_Object_Declaration (Loc, |
| 814 |
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject), |
| 815 |
Object_Definition => New_Occurrence_Of (Obj_Ptr, Loc), |
| 816 |
Expression => |
| 817 |
Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO))); |
| 818 |
Set_Debug_Info_Needed (Defining_Identifier (Decl)); |
| 819 |
Prepend_To (Decls, Decl); |
| 820 |
|
| 821 |
-- Generate: |
| 822 |
-- type poVP is access poV; |
| 823 |
|
| 824 |
Decl := |
| 825 |
Make_Full_Type_Declaration (Loc, |
| 826 |
Defining_Identifier => |
| 827 |
Obj_Ptr, |
| 828 |
Type_Definition => |
| 829 |
Make_Access_To_Object_Definition (Loc, |
| 830 |
Subtype_Indication => |
| 831 |
New_Occurrence_Of (Rec_Typ, Loc))); |
| 832 |
Set_Debug_Info_Needed (Defining_Identifier (Decl)); |
| 833 |
Prepend_To (Decls, Decl); |
| 834 |
end Add_Object_Pointer; |
| 835 |
|
| 836 |
----------------------- |
| 837 |
-- Build_Accept_Body -- |
| 838 |
----------------------- |
| 839 |
|
| 840 |
function Build_Accept_Body (Astat : Node_Id) return Node_Id is |
| 841 |
Loc : constant Source_Ptr := Sloc (Astat); |
| 842 |
Stats : constant Node_Id := Handled_Statement_Sequence (Astat); |
| 843 |
New_S : Node_Id; |
| 844 |
Hand : Node_Id; |
| 845 |
Call : Node_Id; |
| 846 |
Ohandle : Node_Id; |
| 847 |
|
| 848 |
begin |
| 849 |
-- At the end of the statement sequence, Complete_Rendezvous is called. |
| 850 |
-- A label skipping the Complete_Rendezvous, and all other accept |
| 851 |
-- processing, has already been added for the expansion of requeue |
| 852 |
-- statements. The Sloc is copied from the last statement since it |
| 853 |
-- is really part of this last statement. |
| 854 |
|
| 855 |
Call := |
| 856 |
Build_Runtime_Call |
| 857 |
(Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous); |
| 858 |
Insert_Before (Last (Statements (Stats)), Call); |
| 859 |
Analyze (Call); |
| 860 |
|
| 861 |
-- Ada 2022 (AI12-0279) |
| 862 |
|
| 863 |
if Has_Yield_Aspect (Entity (Entry_Direct_Name (Astat))) |
| 864 |
and then RTE_Available (RE_Yield) |
| 865 |
then |
| 866 |
Insert_Action_After (Call, |
| 867 |
Make_Procedure_Call_Statement (Loc, |
| 868 |
New_Occurrence_Of (RTE (RE_Yield), Loc))); |
| 869 |
end if; |
| 870 |
|
| 871 |
-- If exception handlers are present, then append Complete_Rendezvous |
| 872 |
-- calls to the handlers, and construct the required outer block. As |
| 873 |
-- above, the Sloc is copied from the last statement in the sequence. |
| 874 |
|
| 875 |
if Present (Exception_Handlers (Stats)) then |
| 876 |
Hand := First (Exception_Handlers (Stats)); |
| 877 |
while Present (Hand) loop |
| 878 |
Call := |
| 879 |
Build_Runtime_Call |
| 880 |
(Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous); |
| 881 |
Append (Call, Statements (Hand)); |
| 882 |
Analyze (Call); |
| 883 |
|
| 884 |
-- Ada 2022 (AI12-0279) |
| 885 |
|
| 886 |
if Has_Yield_Aspect (Entity (Entry_Direct_Name (Astat))) |
| 887 |
and then RTE_Available (RE_Yield) |
| 888 |
then |
| 889 |
Insert_Action_After (Call, |
| 890 |
Make_Procedure_Call_Statement (Loc, |
| 891 |
New_Occurrence_Of (RTE (RE_Yield), Loc))); |
| 892 |
end if; |
| 893 |
|
| 894 |
Next (Hand); |
| 895 |
end loop; |
| 896 |
|
| 897 |
New_S := |
| 898 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 899 |
Statements => New_List ( |
| 900 |
Make_Block_Statement (Loc, |
| 901 |
Handled_Statement_Sequence => Stats))); |
| 902 |
|
| 903 |
else |
| 904 |
New_S := Stats; |
| 905 |
end if; |
| 906 |
|
| 907 |
-- At this stage we know that the new statement sequence does |
| 908 |
-- not have an exception handler part, so we supply one to call |
| 909 |
-- Exceptional_Complete_Rendezvous. This handler is |
| 910 |
|
| 911 |
-- when all others => |
| 912 |
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); |
| 913 |
|
| 914 |
-- We handle Abort_Signal to make sure that we properly catch the abort |
| 915 |
-- case and wake up the caller. |
| 916 |
|
| 917 |
Call := |
| 918 |
Make_Procedure_Call_Statement (Sloc (Stats), |
| 919 |
Name => New_Occurrence_Of ( |
| 920 |
RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)), |
| 921 |
Parameter_Associations => New_List ( |
| 922 |
Make_Function_Call (Sloc (Stats), |
| 923 |
Name => |
| 924 |
New_Occurrence_Of |
| 925 |
(RTE (RE_Get_GNAT_Exception), Sloc (Stats))))); |
| 926 |
|
| 927 |
Ohandle := Make_Others_Choice (Loc); |
| 928 |
Set_All_Others (Ohandle); |
| 929 |
|
| 930 |
Set_Exception_Handlers (New_S, |
| 931 |
New_List ( |
| 932 |
Make_Implicit_Exception_Handler (Loc, |
| 933 |
Exception_Choices => New_List (Ohandle), |
| 934 |
|
| 935 |
Statements => New_List (Call)))); |
| 936 |
|
| 937 |
-- Ada 2022 (AI12-0279) |
| 938 |
|
| 939 |
if Has_Yield_Aspect (Entity (Entry_Direct_Name (Astat))) |
| 940 |
and then RTE_Available (RE_Yield) |
| 941 |
then |
| 942 |
Insert_Action_After (Call, |
| 943 |
Make_Procedure_Call_Statement (Loc, |
| 944 |
New_Occurrence_Of (RTE (RE_Yield), Loc))); |
| 945 |
end if; |
| 946 |
|
| 947 |
Set_Parent (New_S, Astat); -- temp parent for Analyze call |
| 948 |
Analyze_Exception_Handlers (Exception_Handlers (New_S)); |
| 949 |
Expand_Exception_Handlers (New_S); |
| 950 |
|
| 951 |
-- Exceptional_Complete_Rendezvous must be called with abort still |
| 952 |
-- deferred, which is the case for a "when all others" handler. |
| 953 |
|
| 954 |
return New_S; |
| 955 |
end Build_Accept_Body; |
| 956 |
|
| 957 |
----------------------------------- |
| 958 |
-- Build_Activation_Chain_Entity -- |
| 959 |
----------------------------------- |
| 960 |
|
| 961 |
procedure Build_Activation_Chain_Entity (N : Node_Id) is |
| 962 |
function Has_Activation_Chain (Stmt : Node_Id) return Boolean; |
| 963 |
-- Determine whether an extended return statement has activation chain |
| 964 |
|
| 965 |
-------------------------- |
| 966 |
-- Has_Activation_Chain -- |
| 967 |
-------------------------- |
| 968 |
|
| 969 |
function Has_Activation_Chain (Stmt : Node_Id) return Boolean is |
| 970 |
Decl : Node_Id; |
| 971 |
|
| 972 |
begin |
| 973 |
Decl := First (Return_Object_Declarations (Stmt)); |
| 974 |
while Present (Decl) loop |
| 975 |
if Nkind (Decl) = N_Object_Declaration |
| 976 |
and then Chars (Defining_Identifier (Decl)) = Name_uChain |
| 977 |
then |
| 978 |
return True; |
| 979 |
end if; |
| 980 |
|
| 981 |
Next (Decl); |
| 982 |
end loop; |
| 983 |
|
| 984 |
return False; |
| 985 |
end Has_Activation_Chain; |
| 986 |
|
| 987 |
-- Local variables |
| 988 |
|
| 989 |
Context : Node_Id; |
| 990 |
Context_Id : Entity_Id; |
| 991 |
Decls : List_Id; |
| 992 |
|
| 993 |
-- Start of processing for Build_Activation_Chain_Entity |
| 994 |
|
| 995 |
begin |
| 996 |
-- No action needed if the run-time has no tasking support |
| 997 |
|
| 998 |
if Global_No_Tasking then |
| 999 |
return; |
| 1000 |
end if; |
| 1001 |
|
| 1002 |
-- Activation chain is never used for sequential elaboration policy, see |
| 1003 |
-- comment for Create_Restricted_Task_Sequential in s-tarest.ads). |
| 1004 |
|
| 1005 |
if Partition_Elaboration_Policy = 'S' then |
| 1006 |
return; |
| 1007 |
end if; |
| 1008 |
|
| 1009 |
Find_Enclosing_Context (N, Context, Context_Id, Decls); |
| 1010 |
|
| 1011 |
-- If activation chain entity has not been declared already, create one |
| 1012 |
|
| 1013 |
if Nkind (Context) = N_Extended_Return_Statement |
| 1014 |
or else No (Activation_Chain_Entity (Context)) |
| 1015 |
then |
| 1016 |
-- Since extended return statements do not store the entity of the |
| 1017 |
-- chain, examine the return object declarations to avoid creating |
| 1018 |
-- a duplicate. |
| 1019 |
|
| 1020 |
if Nkind (Context) = N_Extended_Return_Statement |
| 1021 |
and then Has_Activation_Chain (Context) |
| 1022 |
then |
| 1023 |
return; |
| 1024 |
end if; |
| 1025 |
|
| 1026 |
declare |
| 1027 |
Loc : constant Source_Ptr := Sloc (Context); |
| 1028 |
Chain : Entity_Id; |
| 1029 |
Decl : Node_Id; |
| 1030 |
|
| 1031 |
begin |
| 1032 |
Chain := Make_Defining_Identifier (Sloc (N), Name_uChain); |
| 1033 |
|
| 1034 |
-- Note: An extended return statement is not really a task |
| 1035 |
-- activator, but it does have an activation chain on which to |
| 1036 |
-- store the tasks temporarily. On successful return, the tasks |
| 1037 |
-- on this chain are moved to the chain passed in by the caller. |
| 1038 |
-- We do not build an Activation_Chain_Entity for an extended |
| 1039 |
-- return statement, because we do not want to build a call to |
| 1040 |
-- Activate_Tasks. Task activation is the responsibility of the |
| 1041 |
-- caller. |
| 1042 |
|
| 1043 |
if Nkind (Context) /= N_Extended_Return_Statement then |
| 1044 |
Set_Activation_Chain_Entity (Context, Chain); |
| 1045 |
end if; |
| 1046 |
|
| 1047 |
Decl := |
| 1048 |
Make_Object_Declaration (Loc, |
| 1049 |
Defining_Identifier => Chain, |
| 1050 |
Aliased_Present => True, |
| 1051 |
Object_Definition => |
| 1052 |
New_Occurrence_Of (RTE (RE_Activation_Chain), Loc)); |
| 1053 |
|
| 1054 |
Prepend_To (Decls, Decl); |
| 1055 |
|
| 1056 |
-- Ensure that _chain appears in the proper scope of the context |
| 1057 |
|
| 1058 |
if Context_Id /= Current_Scope then |
| 1059 |
Push_Scope (Context_Id); |
| 1060 |
Analyze (Decl); |
| 1061 |
Pop_Scope; |
| 1062 |
else |
| 1063 |
Analyze (Decl); |
| 1064 |
end if; |
| 1065 |
end; |
| 1066 |
end if; |
| 1067 |
end Build_Activation_Chain_Entity; |
| 1068 |
|
| 1069 |
---------------------------- |
| 1070 |
-- Build_Barrier_Function -- |
| 1071 |
---------------------------- |
| 1072 |
|
| 1073 |
function Build_Barrier_Function |
| 1074 |
(N : Node_Id; |
| 1075 |
Ent : Entity_Id; |
| 1076 |
Pid : Entity_Id) return Node_Id |
| 1077 |
is |
| 1078 |
Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N); |
| 1079 |
Cond : constant Node_Id := Condition (Ent_Formals); |
| 1080 |
Loc : constant Source_Ptr := Sloc (Cond); |
| 1081 |
Func_Id : constant Entity_Id := Barrier_Function (Ent); |
| 1082 |
Op_Decls : constant List_Id := New_List; |
| 1083 |
Stmt : Node_Id; |
| 1084 |
Func_Body : Node_Id; |
| 1085 |
|
| 1086 |
begin |
| 1087 |
-- Add a declaration for the Protection object, renaming declarations |
| 1088 |
-- for the discriminals and privals and finally a declaration for the |
| 1089 |
-- entry family index (if applicable). |
| 1090 |
|
| 1091 |
Install_Private_Data_Declarations (Sloc (N), |
| 1092 |
Spec_Id => Func_Id, |
| 1093 |
Conc_Typ => Pid, |
| 1094 |
Body_Nod => N, |
| 1095 |
Decls => Op_Decls, |
| 1096 |
Barrier => True, |
| 1097 |
Family => Ekind (Ent) = E_Entry_Family); |
| 1098 |
|
| 1099 |
-- If compiling with -fpreserve-control-flow, make sure we insert an |
| 1100 |
-- IF statement so that the back-end knows to generate a conditional |
| 1101 |
-- branch instruction, even if the condition is just the name of a |
| 1102 |
-- boolean object. Note that Expand_N_If_Statement knows to preserve |
| 1103 |
-- such redundant IF statements under -fpreserve-control-flow |
| 1104 |
-- (whether coming from this routine, or directly from source). |
| 1105 |
|
| 1106 |
if Opt.Suppress_Control_Flow_Optimizations then |
| 1107 |
Stmt := |
| 1108 |
Make_Implicit_If_Statement (Cond, |
| 1109 |
Condition => Cond, |
| 1110 |
Then_Statements => New_List ( |
| 1111 |
Make_Simple_Return_Statement (Loc, |
| 1112 |
New_Occurrence_Of (Standard_True, Loc))), |
| 1113 |
|
| 1114 |
Else_Statements => New_List ( |
| 1115 |
Make_Simple_Return_Statement (Loc, |
| 1116 |
New_Occurrence_Of (Standard_False, Loc)))); |
| 1117 |
|
| 1118 |
else |
| 1119 |
Stmt := Make_Simple_Return_Statement (Loc, Cond); |
| 1120 |
end if; |
| 1121 |
|
| 1122 |
-- Note: the condition in the barrier function needs to be properly |
| 1123 |
-- processed for the C/Fortran boolean possibility, but this happens |
| 1124 |
-- automatically since the return statement does this normalization. |
| 1125 |
|
| 1126 |
Func_Body := |
| 1127 |
Make_Subprogram_Body (Loc, |
| 1128 |
Specification => |
| 1129 |
Build_Barrier_Function_Specification (Loc, |
| 1130 |
Make_Defining_Identifier (Loc, Chars (Func_Id))), |
| 1131 |
Declarations => Op_Decls, |
| 1132 |
Handled_Statement_Sequence => |
| 1133 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 1134 |
Statements => New_List (Stmt))); |
| 1135 |
Set_Is_Entry_Barrier_Function (Func_Body); |
| 1136 |
|
| 1137 |
return Func_Body; |
| 1138 |
end Build_Barrier_Function; |
| 1139 |
|
| 1140 |
------------------------------------------ |
| 1141 |
-- Build_Barrier_Function_Specification -- |
| 1142 |
------------------------------------------ |
| 1143 |
|
| 1144 |
function Build_Barrier_Function_Specification |
| 1145 |
(Loc : Source_Ptr; |
| 1146 |
Def_Id : Entity_Id) return Node_Id |
| 1147 |
is |
| 1148 |
begin |
| 1149 |
Set_Debug_Info_Needed (Def_Id); |
| 1150 |
|
| 1151 |
return |
| 1152 |
Make_Function_Specification (Loc, |
| 1153 |
Defining_Unit_Name => Def_Id, |
| 1154 |
Parameter_Specifications => New_List ( |
| 1155 |
Make_Parameter_Specification (Loc, |
| 1156 |
Defining_Identifier => |
| 1157 |
Make_Defining_Identifier (Loc, Name_uO), |
| 1158 |
Parameter_Type => |
| 1159 |
New_Occurrence_Of (RTE (RE_Address), Loc)), |
| 1160 |
|
| 1161 |
Make_Parameter_Specification (Loc, |
| 1162 |
Defining_Identifier => |
| 1163 |
Make_Defining_Identifier (Loc, Name_uE), |
| 1164 |
Parameter_Type => |
| 1165 |
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))), |
| 1166 |
|
| 1167 |
Result_Definition => |
| 1168 |
New_Occurrence_Of (Standard_Boolean, Loc)); |
| 1169 |
end Build_Barrier_Function_Specification; |
| 1170 |
|
| 1171 |
-------------------------- |
| 1172 |
-- Build_Call_With_Task -- |
| 1173 |
-------------------------- |
| 1174 |
|
| 1175 |
function Build_Call_With_Task |
| 1176 |
(N : Node_Id; |
| 1177 |
E : Entity_Id) return Node_Id |
| 1178 |
is |
| 1179 |
Loc : constant Source_Ptr := Sloc (N); |
| 1180 |
begin |
| 1181 |
return |
| 1182 |
Make_Function_Call (Loc, |
| 1183 |
Name => New_Occurrence_Of (E, Loc), |
| 1184 |
Parameter_Associations => New_List (Concurrent_Ref (N))); |
| 1185 |
end Build_Call_With_Task; |
| 1186 |
|
| 1187 |
----------------------------- |
| 1188 |
-- Build_Class_Wide_Master -- |
| 1189 |
----------------------------- |
| 1190 |
|
| 1191 |
procedure Build_Class_Wide_Master (Typ : Entity_Id) is |
| 1192 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 1193 |
Master_Decl : Node_Id; |
| 1194 |
Master_Id : Entity_Id; |
| 1195 |
Master_Scope : Entity_Id; |
| 1196 |
Name_Id : Node_Id; |
| 1197 |
Related_Node : Node_Id; |
| 1198 |
Ren_Decl : Node_Id; |
| 1199 |
|
| 1200 |
begin |
| 1201 |
-- No action needed if the run-time has no tasking support |
| 1202 |
|
| 1203 |
if Global_No_Tasking then |
| 1204 |
return; |
| 1205 |
end if; |
| 1206 |
|
| 1207 |
-- Find the declaration that created the access type, which is either a |
| 1208 |
-- type declaration, or an object declaration with an access definition, |
| 1209 |
-- in which case the type is anonymous. |
| 1210 |
|
| 1211 |
if Is_Itype (Typ) then |
| 1212 |
Related_Node := Associated_Node_For_Itype (Typ); |
| 1213 |
else |
| 1214 |
Related_Node := Parent (Typ); |
| 1215 |
end if; |
| 1216 |
|
| 1217 |
Master_Scope := Find_Master_Scope (Typ); |
| 1218 |
|
| 1219 |
-- Nothing to do if the master scope already contains a _master entity. |
| 1220 |
-- The only exception to this is the following scenario: |
| 1221 |
|
| 1222 |
-- Source_Scope |
| 1223 |
-- Transient_Scope_1 |
| 1224 |
-- _master |
| 1225 |
|
| 1226 |
-- Transient_Scope_2 |
| 1227 |
-- use of master |
| 1228 |
|
| 1229 |
-- In this case the source scope is marked as having the master entity |
| 1230 |
-- even though the actual declaration appears inside an inner scope. If |
| 1231 |
-- the second transient scope requires a _master, it cannot use the one |
| 1232 |
-- already declared because the entity is not visible. |
| 1233 |
|
| 1234 |
Name_Id := Make_Identifier (Loc, Name_uMaster); |
| 1235 |
Master_Decl := Empty; |
| 1236 |
|
| 1237 |
if not Has_Master_Entity (Master_Scope) |
| 1238 |
or else No (Current_Entity_In_Scope (Name_Id)) |
| 1239 |
then |
| 1240 |
declare |
| 1241 |
Ins_Nod : Node_Id; |
| 1242 |
Par_Nod : Node_Id; |
| 1243 |
|
| 1244 |
begin |
| 1245 |
Master_Decl := Build_Master_Declaration (Loc); |
| 1246 |
|
| 1247 |
-- Ensure that the master declaration is placed before its use |
| 1248 |
|
| 1249 |
Ins_Nod := Find_Hook_Context (Related_Node); |
| 1250 |
while not Is_List_Member (Ins_Nod) loop |
| 1251 |
Ins_Nod := Parent (Ins_Nod); |
| 1252 |
end loop; |
| 1253 |
|
| 1254 |
Par_Nod := Parent (List_Containing (Ins_Nod)); |
| 1255 |
|
| 1256 |
-- For internal blocks created by Wrap_Loop_Statement, Wrap_ |
| 1257 |
-- Statements_In_Block, and Build_Abort_Undefer_Block, remember |
| 1258 |
-- that they have a task master entity declaration; required by |
| 1259 |
-- Build_Master_Entity to avoid creating another master entity, |
| 1260 |
-- and also ensures that subsequent calls to Find_Master_Scope |
| 1261 |
-- return this scope as the master scope of Typ. |
| 1262 |
|
| 1263 |
if Is_Internal_Block (Par_Nod) then |
| 1264 |
Set_Has_Master_Entity (Entity (Identifier (Par_Nod))); |
| 1265 |
|
| 1266 |
elsif Nkind (Par_Nod) = N_Handled_Sequence_Of_Statements |
| 1267 |
and then Is_Internal_Block (Parent (Par_Nod)) |
| 1268 |
then |
| 1269 |
Set_Has_Master_Entity (Entity (Identifier (Parent (Par_Nod)))); |
| 1270 |
|
| 1271 |
-- Otherwise remember that this scope has an associated task |
| 1272 |
-- master entity declaration. |
| 1273 |
|
| 1274 |
else |
| 1275 |
Set_Has_Master_Entity (Master_Scope); |
| 1276 |
end if; |
| 1277 |
|
| 1278 |
Insert_Before (First (List_Containing (Ins_Nod)), Master_Decl); |
| 1279 |
Analyze (Master_Decl); |
| 1280 |
|
| 1281 |
-- Mark the containing scope as a task master. Masters associated |
| 1282 |
-- with return statements are already marked at this stage (see |
| 1283 |
-- Analyze_Subprogram_Body). |
| 1284 |
|
| 1285 |
if Ekind (Current_Scope) /= E_Return_Statement then |
| 1286 |
declare |
| 1287 |
Par : Node_Id := Related_Node; |
| 1288 |
|
| 1289 |
begin |
| 1290 |
while Nkind (Par) /= N_Compilation_Unit loop |
| 1291 |
Par := Parent (Par); |
| 1292 |
|
| 1293 |
-- If we fall off the top, we are at the outer level, |
| 1294 |
-- and the environment task is our effective master, |
| 1295 |
-- so nothing to mark. |
| 1296 |
|
| 1297 |
if Nkind (Par) in |
| 1298 |
N_Block_Statement | N_Subprogram_Body | N_Task_Body |
| 1299 |
then |
| 1300 |
Set_Is_Task_Master (Par); |
| 1301 |
exit; |
| 1302 |
end if; |
| 1303 |
end loop; |
| 1304 |
end; |
| 1305 |
end if; |
| 1306 |
end; |
| 1307 |
end if; |
| 1308 |
|
| 1309 |
Master_Id := |
| 1310 |
Make_Defining_Identifier (Loc, New_External_Name (Chars (Typ), 'M')); |
| 1311 |
|
| 1312 |
-- Generate: |
| 1313 |
-- typeMnn renames _master; |
| 1314 |
|
| 1315 |
Ren_Decl := |
| 1316 |
Make_Object_Renaming_Declaration (Loc, |
| 1317 |
Defining_Identifier => Master_Id, |
| 1318 |
Subtype_Mark => New_Occurrence_Of (Standard_Integer, Loc), |
| 1319 |
Name => Name_Id); |
| 1320 |
|
| 1321 |
-- If the master is declared locally, add the renaming declaration |
| 1322 |
-- immediately after it, to prevent access-before-elaboration in the |
| 1323 |
-- back-end. |
| 1324 |
|
| 1325 |
if Present (Master_Decl) then |
| 1326 |
Insert_After (Master_Decl, Ren_Decl); |
| 1327 |
Analyze (Ren_Decl); |
| 1328 |
|
| 1329 |
else |
| 1330 |
Insert_Action (Related_Node, Ren_Decl); |
| 1331 |
end if; |
| 1332 |
|
| 1333 |
Set_Master_Id (Typ, Master_Id); |
| 1334 |
end Build_Class_Wide_Master; |
| 1335 |
|
| 1336 |
-------------------------------- |
| 1337 |
-- Build_Corresponding_Record -- |
| 1338 |
-------------------------------- |
| 1339 |
|
| 1340 |
function Build_Corresponding_Record |
| 1341 |
(N : Node_Id; |
| 1342 |
Ctyp : Entity_Id; |
| 1343 |
Loc : Source_Ptr) return Node_Id |
| 1344 |
is |
| 1345 |
Rec_Ent : constant Entity_Id := |
| 1346 |
Make_Defining_Identifier |
| 1347 |
(Loc, New_External_Name (Chars (Ctyp), 'V')); |
| 1348 |
Alist : List_Id; |
| 1349 |
Asp_Copy : Node_Id; |
| 1350 |
Aspect : Node_Id; |
| 1351 |
Disc : Entity_Id; |
| 1352 |
Dlist : List_Id; |
| 1353 |
New_Disc : Entity_Id; |
| 1354 |
Cdecls : List_Id; |
| 1355 |
|
| 1356 |
begin |
| 1357 |
Set_Corresponding_Record_Type (Ctyp, Rec_Ent); |
| 1358 |
Mutate_Ekind (Rec_Ent, E_Record_Type); |
| 1359 |
Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp)); |
| 1360 |
Set_Is_Concurrent_Record_Type (Rec_Ent, True); |
| 1361 |
Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp); |
| 1362 |
Set_Stored_Constraint (Rec_Ent, No_Elist); |
| 1363 |
Cdecls := New_List; |
| 1364 |
|
| 1365 |
-- Use discriminals to create list of discriminants for record, and |
| 1366 |
-- create new discriminals for use in default expressions, etc. It is |
| 1367 |
-- worth noting that a task discriminant gives rise to 5 entities; |
| 1368 |
|
| 1369 |
-- a) The original discriminant. |
| 1370 |
-- b) The discriminal for use in the task. |
| 1371 |
-- c) The discriminant of the corresponding record. |
| 1372 |
-- d) The discriminal for the init proc of the corresponding record. |
| 1373 |
-- e) The local variable that renames the discriminant in the procedure |
| 1374 |
-- for the task body. |
| 1375 |
|
| 1376 |
-- In fact the discriminals b) are used in the renaming declarations |
| 1377 |
-- for e). See details in einfo (Handling of Discriminants). |
| 1378 |
|
| 1379 |
if Present (Discriminant_Specifications (N)) then |
| 1380 |
Dlist := New_List; |
| 1381 |
Disc := First_Discriminant (Ctyp); |
| 1382 |
|
| 1383 |
while Present (Disc) loop |
| 1384 |
New_Disc := CR_Discriminant (Disc); |
| 1385 |
|
| 1386 |
Append_To (Dlist, |
| 1387 |
Make_Discriminant_Specification (Loc, |
| 1388 |
Defining_Identifier => New_Disc, |
| 1389 |
Discriminant_Type => |
| 1390 |
New_Occurrence_Of (Etype (Disc), Loc), |
| 1391 |
Expression => |
| 1392 |
New_Copy (Discriminant_Default_Value (Disc)))); |
| 1393 |
|
| 1394 |
Next_Discriminant (Disc); |
| 1395 |
end loop; |
| 1396 |
|
| 1397 |
else |
| 1398 |
Dlist := No_List; |
| 1399 |
end if; |
| 1400 |
|
| 1401 |
-- Propagate the aspect First_Controlling_Parameter to the corresponding |
| 1402 |
-- record to reuse the tagged types machinery. This is not needed if |
| 1403 |
-- the concurrent type does not implement interface types, as the |
| 1404 |
-- corresponding record will not be a tagged type in such case. |
| 1405 |
|
| 1406 |
Alist := No_List; |
| 1407 |
|
| 1408 |
if Present (Parent (Ctyp)) |
| 1409 |
and then Present (Interface_List (Parent (Ctyp))) |
| 1410 |
and then Present (Aspect_Specifications (N)) |
| 1411 |
then |
| 1412 |
Aspect := First (Aspect_Specifications (N)); |
| 1413 |
while Present (Aspect) loop |
| 1414 |
if Chars (Identifier (Aspect)) |
| 1415 |
= Name_First_Controlling_Parameter |
| 1416 |
then |
| 1417 |
Alist := New_List; |
| 1418 |
Asp_Copy := New_Copy_Tree (Aspect); |
| 1419 |
|
| 1420 |
-- Force its analysis in the corresponding record to add |
| 1421 |
-- the pragma. |
| 1422 |
|
| 1423 |
Set_Analyzed (Asp_Copy, False); |
| 1424 |
Append_To (Alist, Asp_Copy); |
| 1425 |
exit; |
| 1426 |
end if; |
| 1427 |
|
| 1428 |
Next (Aspect); |
| 1429 |
end loop; |
| 1430 |
end if; |
| 1431 |
|
| 1432 |
-- Now we can construct the record type declaration. Note that this |
| 1433 |
-- record is "limited tagged". It is "limited" to reflect the underlying |
| 1434 |
-- limitedness of the task or protected object that it represents, and |
| 1435 |
-- ensuring for example that it is properly passed by reference. It is |
| 1436 |
-- "tagged" to give support to dispatching calls through interfaces. We |
| 1437 |
-- propagate here the list of interfaces covered by the concurrent type |
| 1438 |
-- (Ada 2005: AI-345). |
| 1439 |
|
| 1440 |
return |
| 1441 |
Make_Full_Type_Declaration (Loc, |
| 1442 |
Defining_Identifier => Rec_Ent, |
| 1443 |
Aspect_Specifications => Alist, |
| 1444 |
Discriminant_Specifications => Dlist, |
| 1445 |
Type_Definition => |
| 1446 |
Make_Record_Definition (Loc, |
| 1447 |
Component_List => |
| 1448 |
Make_Component_List (Loc, Component_Items => Cdecls), |
| 1449 |
Tagged_Present => |
| 1450 |
Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp), |
| 1451 |
Interface_List => Interface_List (N), |
| 1452 |
Limited_Present => True)); |
| 1453 |
end Build_Corresponding_Record; |
| 1454 |
|
| 1455 |
--------------------------------- |
| 1456 |
-- Build_Dispatching_Tag_Check -- |
| 1457 |
--------------------------------- |
| 1458 |
|
| 1459 |
function Build_Dispatching_Tag_Check |
| 1460 |
(K : Entity_Id; |
| 1461 |
N : Node_Id) return Node_Id |
| 1462 |
is |
| 1463 |
Loc : constant Source_Ptr := Sloc (N); |
| 1464 |
|
| 1465 |
begin |
| 1466 |
return |
| 1467 |
Make_Op_Or (Loc, |
| 1468 |
Make_Op_Eq (Loc, |
| 1469 |
Left_Opnd => |
| 1470 |
New_Occurrence_Of (K, Loc), |
| 1471 |
Right_Opnd => |
| 1472 |
New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc)), |
| 1473 |
|
| 1474 |
Make_Op_Eq (Loc, |
| 1475 |
Left_Opnd => |
| 1476 |
New_Occurrence_Of (K, Loc), |
| 1477 |
Right_Opnd => |
| 1478 |
New_Occurrence_Of (RTE (RE_TK_Tagged), Loc))); |
| 1479 |
end Build_Dispatching_Tag_Check; |
| 1480 |
|
| 1481 |
---------------------------------- |
| 1482 |
-- Build_Entry_Count_Expression -- |
| 1483 |
---------------------------------- |
| 1484 |
|
| 1485 |
function Build_Entry_Count_Expression |
| 1486 |
(Concurrent_Type : Entity_Id; |
| 1487 |
Loc : Source_Ptr) return Node_Id |
| 1488 |
is |
| 1489 |
Eindx : Nat; |
| 1490 |
Ent : Entity_Id; |
| 1491 |
Ecount : Node_Id; |
| 1492 |
Lo : Node_Id; |
| 1493 |
Hi : Node_Id; |
| 1494 |
Typ : Entity_Id; |
| 1495 |
Large : Boolean; |
| 1496 |
|
| 1497 |
begin |
| 1498 |
-- Count number of non-family entries |
| 1499 |
|
| 1500 |
Eindx := 0; |
| 1501 |
Ent := First_Entity (Concurrent_Type); |
| 1502 |
while Present (Ent) loop |
| 1503 |
if Ekind (Ent) = E_Entry then |
| 1504 |
Eindx := Eindx + 1; |
| 1505 |
end if; |
| 1506 |
|
| 1507 |
Next_Entity (Ent); |
| 1508 |
end loop; |
| 1509 |
|
| 1510 |
Ecount := Make_Integer_Literal (Loc, Eindx); |
| 1511 |
|
| 1512 |
-- Loop through entry families building the addition nodes |
| 1513 |
|
| 1514 |
Ent := First_Entity (Concurrent_Type); |
| 1515 |
while Present (Ent) loop |
| 1516 |
if Ekind (Ent) = E_Entry_Family then |
| 1517 |
Typ := Entry_Index_Type (Ent); |
| 1518 |
Hi := Type_High_Bound (Typ); |
| 1519 |
Lo := Type_Low_Bound (Typ); |
| 1520 |
Large := Is_Potentially_Large_Family |
| 1521 |
(Base_Type (Typ), Concurrent_Type, Lo, Hi); |
| 1522 |
Ecount := |
| 1523 |
Make_Op_Add (Loc, |
| 1524 |
Left_Opnd => Ecount, |
| 1525 |
Right_Opnd => |
| 1526 |
Family_Size (Loc, Hi, Lo, Concurrent_Type, Large)); |
| 1527 |
end if; |
| 1528 |
|
| 1529 |
Next_Entity (Ent); |
| 1530 |
end loop; |
| 1531 |
|
| 1532 |
return Ecount; |
| 1533 |
end Build_Entry_Count_Expression; |
| 1534 |
|
| 1535 |
------------------------------ |
| 1536 |
-- Build_Master_Declaration -- |
| 1537 |
------------------------------ |
| 1538 |
|
| 1539 |
function Build_Master_Declaration (Loc : Source_Ptr) return Node_Id is |
| 1540 |
Master_Decl : Node_Id; |
| 1541 |
|
| 1542 |
begin |
| 1543 |
-- Generate a dummy master if tasks or tasking hierarchies are |
| 1544 |
-- prohibited. |
| 1545 |
|
| 1546 |
-- _Master : constant Integer := Library_Task_Level; |
| 1547 |
|
| 1548 |
if not Tasking_Allowed |
| 1549 |
or else Restrictions.Set (No_Task_Hierarchy) |
| 1550 |
or else not RTE_Available (RE_Current_Master) |
| 1551 |
then |
| 1552 |
Master_Decl := |
| 1553 |
Make_Object_Declaration (Loc, |
| 1554 |
Defining_Identifier => |
| 1555 |
Make_Defining_Identifier (Loc, Name_uMaster), |
| 1556 |
Constant_Present => True, |
| 1557 |
Object_Definition => |
| 1558 |
New_Occurrence_Of (Standard_Integer, Loc), |
| 1559 |
Expression => |
| 1560 |
Make_Integer_Literal (Loc, Library_Task_Level)); |
| 1561 |
|
| 1562 |
-- Generate: |
| 1563 |
-- _master : constant Integer := Current_Master.all; |
| 1564 |
|
| 1565 |
else |
| 1566 |
Master_Decl := |
| 1567 |
Make_Object_Declaration (Loc, |
| 1568 |
Defining_Identifier => |
| 1569 |
Make_Defining_Identifier (Loc, Name_uMaster), |
| 1570 |
Constant_Present => True, |
| 1571 |
Object_Definition => |
| 1572 |
New_Occurrence_Of (Standard_Integer, Loc), |
| 1573 |
Expression => |
| 1574 |
Make_Explicit_Dereference (Loc, |
| 1575 |
New_Occurrence_Of (RTE (RE_Current_Master), Loc))); |
| 1576 |
end if; |
| 1577 |
|
| 1578 |
return Master_Decl; |
| 1579 |
end Build_Master_Declaration; |
| 1580 |
|
| 1581 |
--------------------------- |
| 1582 |
-- Build_Parameter_Block -- |
| 1583 |
--------------------------- |
| 1584 |
|
| 1585 |
function Build_Parameter_Block |
| 1586 |
(Loc : Source_Ptr; |
| 1587 |
Actuals : List_Id; |
| 1588 |
Formals : List_Id; |
| 1589 |
Decls : List_Id) return Entity_Id |
| 1590 |
is |
| 1591 |
Actual : Entity_Id; |
| 1592 |
Comp_Nam : Node_Id; |
| 1593 |
Comps : List_Id; |
| 1594 |
Formal : Entity_Id; |
| 1595 |
Has_Comp : Boolean := False; |
| 1596 |
Rec_Nam : Node_Id; |
| 1597 |
|
| 1598 |
begin |
| 1599 |
Actual := First (Actuals); |
| 1600 |
Comps := New_List; |
| 1601 |
Formal := Defining_Identifier (First (Formals)); |
| 1602 |
|
| 1603 |
while Present (Actual) loop |
| 1604 |
if not Is_Controlling_Actual (Actual) then |
| 1605 |
|
| 1606 |
-- Generate: |
| 1607 |
-- type Ann is access all <actual-type> |
| 1608 |
|
| 1609 |
Comp_Nam := Make_Temporary (Loc, 'A'); |
| 1610 |
Set_Is_Param_Block_Component_Type (Comp_Nam); |
| 1611 |
|
| 1612 |
Append_To (Decls, |
| 1613 |
Make_Full_Type_Declaration (Loc, |
| 1614 |
Defining_Identifier => Comp_Nam, |
| 1615 |
Type_Definition => |
| 1616 |
Make_Access_To_Object_Definition (Loc, |
| 1617 |
All_Present => True, |
| 1618 |
Constant_Present => Ekind (Formal) = E_In_Parameter, |
| 1619 |
Subtype_Indication => |
| 1620 |
New_Occurrence_Of (Etype (Actual), Loc)))); |
| 1621 |
|
| 1622 |
-- Generate: |
| 1623 |
-- Param : Ann; |
| 1624 |
|
| 1625 |
Append_To (Comps, |
| 1626 |
Make_Component_Declaration (Loc, |
| 1627 |
Defining_Identifier => |
| 1628 |
Make_Defining_Identifier (Loc, Chars (Formal)), |
| 1629 |
Component_Definition => |
| 1630 |
Make_Component_Definition (Loc, |
| 1631 |
Subtype_Indication => |
| 1632 |
New_Occurrence_Of (Comp_Nam, Loc)))); |
| 1633 |
|
| 1634 |
Has_Comp := True; |
| 1635 |
end if; |
| 1636 |
|
| 1637 |
Next_Actual (Actual); |
| 1638 |
Next_Formal_With_Extras (Formal); |
| 1639 |
end loop; |
| 1640 |
|
| 1641 |
Rec_Nam := Make_Temporary (Loc, 'P'); |
| 1642 |
|
| 1643 |
if Has_Comp then |
| 1644 |
|
| 1645 |
-- Generate: |
| 1646 |
-- type Pnn is record |
| 1647 |
-- Param1 : Ann1; |
| 1648 |
-- ... |
| 1649 |
-- ParamN : AnnN; |
| 1650 |
|
| 1651 |
-- where Pnn is a parameter wrapping record, Param1 .. ParamN are |
| 1652 |
-- the original parameter names and Ann1 .. AnnN are the access to |
| 1653 |
-- actual types. |
| 1654 |
|
| 1655 |
Append_To (Decls, |
| 1656 |
Make_Full_Type_Declaration (Loc, |
| 1657 |
Defining_Identifier => |
| 1658 |
Rec_Nam, |
| 1659 |
Type_Definition => |
| 1660 |
Make_Record_Definition (Loc, |
| 1661 |
Component_List => |
| 1662 |
Make_Component_List (Loc, Comps)))); |
| 1663 |
else |
| 1664 |
-- Generate: |
| 1665 |
-- type Pnn is null record; |
| 1666 |
|
| 1667 |
Append_To (Decls, |
| 1668 |
Make_Full_Type_Declaration (Loc, |
| 1669 |
Defining_Identifier => |
| 1670 |
Rec_Nam, |
| 1671 |
Type_Definition => |
| 1672 |
Make_Record_Definition (Loc, |
| 1673 |
Null_Present => True, |
| 1674 |
Component_List => Empty))); |
| 1675 |
end if; |
| 1676 |
|
| 1677 |
return Rec_Nam; |
| 1678 |
end Build_Parameter_Block; |
| 1679 |
|
| 1680 |
-------------------------------------- |
| 1681 |
-- Build_Renamed_Formal_Declaration -- |
| 1682 |
-------------------------------------- |
| 1683 |
|
| 1684 |
function Build_Renamed_Formal_Declaration |
| 1685 |
(New_F : Entity_Id; |
| 1686 |
Formal : Entity_Id; |
| 1687 |
Comp : Entity_Id; |
| 1688 |
Renamed_Formal : Node_Id) return Node_Id |
| 1689 |
is |
| 1690 |
Loc : constant Source_Ptr := Sloc (New_F); |
| 1691 |
Decl : Node_Id; |
| 1692 |
|
| 1693 |
begin |
| 1694 |
-- If the formal is a tagged incomplete type, it is already passed |
| 1695 |
-- by reference, so it is sufficient to rename the pointer component |
| 1696 |
-- that corresponds to the actual. Otherwise we need to dereference |
| 1697 |
-- the pointer component to obtain the actual. |
| 1698 |
|
| 1699 |
if Is_Incomplete_Type (Etype (Formal)) |
| 1700 |
and then Is_Tagged_Type (Etype (Formal)) |
| 1701 |
then |
| 1702 |
Decl := |
| 1703 |
Make_Object_Renaming_Declaration (Loc, |
| 1704 |
Defining_Identifier => New_F, |
| 1705 |
Subtype_Mark => New_Occurrence_Of (Etype (Comp), Loc), |
| 1706 |
Name => Renamed_Formal); |
| 1707 |
|
| 1708 |
else |
| 1709 |
Decl := |
| 1710 |
Make_Object_Renaming_Declaration (Loc, |
| 1711 |
Defining_Identifier => New_F, |
| 1712 |
Subtype_Mark => New_Occurrence_Of (Etype (Formal), Loc), |
| 1713 |
Name => |
| 1714 |
Make_Explicit_Dereference (Loc, Renamed_Formal)); |
| 1715 |
end if; |
| 1716 |
|
| 1717 |
return Decl; |
| 1718 |
end Build_Renamed_Formal_Declaration; |
| 1719 |
|
| 1720 |
-------------------------- |
| 1721 |
-- Build_Wrapper_Bodies -- |
| 1722 |
-------------------------- |
| 1723 |
|
| 1724 |
procedure Build_Wrapper_Bodies |
| 1725 |
(Loc : Source_Ptr; |
| 1726 |
Typ : Entity_Id; |
| 1727 |
N : Node_Id) |
| 1728 |
is |
| 1729 |
Rec_Typ : Entity_Id; |
| 1730 |
|
| 1731 |
function Build_Wrapper_Body |
| 1732 |
(Loc : Source_Ptr; |
| 1733 |
Subp_Id : Entity_Id; |
| 1734 |
Obj_Typ : Entity_Id; |
| 1735 |
Formals : List_Id) return Node_Id; |
| 1736 |
-- Ada 2005 (AI-345): Build the body that wraps a primitive operation |
| 1737 |
-- associated with a protected or task type. Subp_Id is the subprogram |
| 1738 |
-- name which will be wrapped. Obj_Typ is the type of the new formal |
| 1739 |
-- parameter which handles dispatching and object notation. Formals are |
| 1740 |
-- the original formals of Subp_Id which will be explicitly replicated. |
| 1741 |
|
| 1742 |
------------------------ |
| 1743 |
-- Build_Wrapper_Body -- |
| 1744 |
------------------------ |
| 1745 |
|
| 1746 |
function Build_Wrapper_Body |
| 1747 |
(Loc : Source_Ptr; |
| 1748 |
Subp_Id : Entity_Id; |
| 1749 |
Obj_Typ : Entity_Id; |
| 1750 |
Formals : List_Id) return Node_Id |
| 1751 |
is |
| 1752 |
Body_Spec : Node_Id; |
| 1753 |
|
| 1754 |
begin |
| 1755 |
Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals); |
| 1756 |
|
| 1757 |
-- The subprogram is not overriding or is not a primitive declared |
| 1758 |
-- between two views. |
| 1759 |
|
| 1760 |
if No (Body_Spec) then |
| 1761 |
return Empty; |
| 1762 |
end if; |
| 1763 |
|
| 1764 |
declare |
| 1765 |
Actuals : List_Id := No_List; |
| 1766 |
Conv_Id : Node_Id; |
| 1767 |
First_Form : Node_Id; |
| 1768 |
Formal : Node_Id; |
| 1769 |
Nam : Node_Id; |
| 1770 |
|
| 1771 |
begin |
| 1772 |
-- Map formals to actuals. Use the list built for the wrapper |
| 1773 |
-- spec, skipping the object notation parameter. |
| 1774 |
|
| 1775 |
First_Form := First (Parameter_Specifications (Body_Spec)); |
| 1776 |
|
| 1777 |
Formal := First_Form; |
| 1778 |
Next (Formal); |
| 1779 |
|
| 1780 |
if Present (Formal) then |
| 1781 |
Actuals := New_List; |
| 1782 |
while Present (Formal) loop |
| 1783 |
Append_To (Actuals, |
| 1784 |
Make_Identifier (Loc, |
| 1785 |
Chars => Chars (Defining_Identifier (Formal)))); |
| 1786 |
Next (Formal); |
| 1787 |
end loop; |
| 1788 |
end if; |
| 1789 |
|
| 1790 |
-- Special processing for primitives declared between a private |
| 1791 |
-- type and its completion: the wrapper needs a properly typed |
| 1792 |
-- parameter if the wrapped operation has a controlling first |
| 1793 |
-- parameter. Note that this might not be the case for a function |
| 1794 |
-- with a controlling result. |
| 1795 |
|
| 1796 |
if Is_Private_Primitive_Subprogram (Subp_Id) then |
| 1797 |
if No (Actuals) then |
| 1798 |
Actuals := New_List; |
| 1799 |
end if; |
| 1800 |
|
| 1801 |
if Is_Controlling_Formal (First_Formal (Subp_Id)) then |
| 1802 |
Prepend_To (Actuals, |
| 1803 |
Unchecked_Convert_To |
| 1804 |
(Corresponding_Concurrent_Type (Obj_Typ), |
| 1805 |
Make_Identifier (Loc, Name_uO))); |
| 1806 |
|
| 1807 |
else |
| 1808 |
Prepend_To (Actuals, |
| 1809 |
Make_Identifier (Loc, |
| 1810 |
Chars => Chars (Defining_Identifier (First_Form)))); |
| 1811 |
end if; |
| 1812 |
|
| 1813 |
Nam := New_Occurrence_Of (Subp_Id, Loc); |
| 1814 |
else |
| 1815 |
-- An access-to-variable object parameter requires an explicit |
| 1816 |
-- dereference in the unchecked conversion. This case occurs |
| 1817 |
-- when a protected entry wrapper must override an interface |
| 1818 |
-- level procedure with interface access as first parameter. |
| 1819 |
|
| 1820 |
-- O.all.Subp_Id (Formal_1, ..., Formal_N) |
| 1821 |
|
| 1822 |
if Nkind (Parameter_Type (First_Form)) = |
| 1823 |
N_Access_Definition |
| 1824 |
then |
| 1825 |
Conv_Id := |
| 1826 |
Make_Explicit_Dereference (Loc, |
| 1827 |
Prefix => Make_Identifier (Loc, Name_uO)); |
| 1828 |
else |
| 1829 |
Conv_Id := Make_Identifier (Loc, Name_uO); |
| 1830 |
end if; |
| 1831 |
|
| 1832 |
Nam := |
| 1833 |
Make_Selected_Component (Loc, |
| 1834 |
Prefix => |
| 1835 |
Unchecked_Convert_To |
| 1836 |
(Corresponding_Concurrent_Type (Obj_Typ), Conv_Id), |
| 1837 |
Selector_Name => New_Occurrence_Of (Subp_Id, Loc)); |
| 1838 |
end if; |
| 1839 |
|
| 1840 |
-- Create the subprogram body. For a function, the call to the |
| 1841 |
-- actual subprogram has to be converted to the corresponding |
| 1842 |
-- record if it is a controlling result. |
| 1843 |
|
| 1844 |
if Ekind (Subp_Id) = E_Function then |
| 1845 |
declare |
| 1846 |
Res : Node_Id; |
| 1847 |
|
| 1848 |
begin |
| 1849 |
Res := |
| 1850 |
Make_Function_Call (Loc, |
| 1851 |
Name => Nam, |
| 1852 |
Parameter_Associations => Actuals); |
| 1853 |
|
| 1854 |
if Has_Controlling_Result (Subp_Id) then |
| 1855 |
Res := |
| 1856 |
Unchecked_Convert_To |
| 1857 |
(Corresponding_Record_Type (Etype (Subp_Id)), Res); |
| 1858 |
end if; |
| 1859 |
|
| 1860 |
return |
| 1861 |
Make_Subprogram_Body (Loc, |
| 1862 |
Specification => Body_Spec, |
| 1863 |
Declarations => Empty_List, |
| 1864 |
Handled_Statement_Sequence => |
| 1865 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 1866 |
Statements => New_List ( |
| 1867 |
Make_Simple_Return_Statement (Loc, Res)))); |
| 1868 |
end; |
| 1869 |
|
| 1870 |
else |
| 1871 |
return |
| 1872 |
Make_Subprogram_Body (Loc, |
| 1873 |
Specification => Body_Spec, |
| 1874 |
Declarations => Empty_List, |
| 1875 |
Handled_Statement_Sequence => |
| 1876 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 1877 |
Statements => New_List ( |
| 1878 |
Make_Procedure_Call_Statement (Loc, |
| 1879 |
Name => Nam, |
| 1880 |
Parameter_Associations => Actuals)))); |
| 1881 |
end if; |
| 1882 |
end; |
| 1883 |
end Build_Wrapper_Body; |
| 1884 |
|
| 1885 |
-- Start of processing for Build_Wrapper_Bodies |
| 1886 |
|
| 1887 |
begin |
| 1888 |
if Is_Concurrent_Type (Typ) then |
| 1889 |
Rec_Typ := Corresponding_Record_Type (Typ); |
| 1890 |
else |
| 1891 |
Rec_Typ := Typ; |
| 1892 |
end if; |
| 1893 |
|
| 1894 |
-- Generate wrapper bodies for a concurrent type which implements an |
| 1895 |
-- interface. |
| 1896 |
|
| 1897 |
if Present (Interfaces (Rec_Typ)) then |
| 1898 |
declare |
| 1899 |
Insert_Nod : Node_Id; |
| 1900 |
Prim : Entity_Id; |
| 1901 |
Prim_Elmt : Elmt_Id; |
| 1902 |
Prim_Decl : Node_Id; |
| 1903 |
Subp : Entity_Id; |
| 1904 |
Wrap_Body : Node_Id; |
| 1905 |
Wrap_Id : Entity_Id; |
| 1906 |
|
| 1907 |
begin |
| 1908 |
Insert_Nod := N; |
| 1909 |
|
| 1910 |
-- Examine all primitive operations of the corresponding record |
| 1911 |
-- type, looking for wrapper specs. Generate bodies in order to |
| 1912 |
-- complete them. |
| 1913 |
|
| 1914 |
Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ)); |
| 1915 |
while Present (Prim_Elmt) loop |
| 1916 |
Prim := Node (Prim_Elmt); |
| 1917 |
|
| 1918 |
if (Ekind (Prim) = E_Function |
| 1919 |
or else Ekind (Prim) = E_Procedure) |
| 1920 |
and then Is_Primitive_Wrapper (Prim) |
| 1921 |
then |
| 1922 |
Subp := Wrapped_Entity (Prim); |
| 1923 |
Prim_Decl := Parent (Parent (Prim)); |
| 1924 |
|
| 1925 |
Wrap_Body := |
| 1926 |
Build_Wrapper_Body (Loc, |
| 1927 |
Subp_Id => Subp, |
| 1928 |
Obj_Typ => Rec_Typ, |
| 1929 |
Formals => Parameter_Specifications (Parent (Subp))); |
| 1930 |
Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body)); |
| 1931 |
|
| 1932 |
Set_Corresponding_Spec (Wrap_Body, Prim); |
| 1933 |
Set_Corresponding_Body (Prim_Decl, Wrap_Id); |
| 1934 |
|
| 1935 |
Insert_After (Insert_Nod, Wrap_Body); |
| 1936 |
Insert_Nod := Wrap_Body; |
| 1937 |
|
| 1938 |
Analyze (Wrap_Body); |
| 1939 |
end if; |
| 1940 |
|
| 1941 |
Next_Elmt (Prim_Elmt); |
| 1942 |
end loop; |
| 1943 |
end; |
| 1944 |
end if; |
| 1945 |
end Build_Wrapper_Bodies; |
| 1946 |
|
| 1947 |
------------------------ |
| 1948 |
-- Build_Wrapper_Spec -- |
| 1949 |
------------------------ |
| 1950 |
|
| 1951 |
function Build_Wrapper_Spec |
| 1952 |
(Subp_Id : Entity_Id; |
| 1953 |
Obj_Typ : Entity_Id; |
| 1954 |
Formals : List_Id) return Node_Id |
| 1955 |
is |
| 1956 |
function Overriding_Possible |
| 1957 |
(Iface_Op : Entity_Id; |
| 1958 |
Wrapper : Entity_Id) return Boolean; |
| 1959 |
-- Determine whether a primitive operation can be overridden by Wrapper. |
| 1960 |
-- Iface_Op is the candidate primitive operation of an interface type, |
| 1961 |
-- Wrapper is the generated entry wrapper. |
| 1962 |
|
| 1963 |
function Replicate_Formals |
| 1964 |
(Loc : Source_Ptr; |
| 1965 |
Formals : List_Id) return List_Id; |
| 1966 |
-- An explicit parameter replication is required due to the Is_Entry_ |
| 1967 |
-- Formal flag being set for all the formals of an entry. The explicit |
| 1968 |
-- replication removes the flag that would otherwise cause a different |
| 1969 |
-- path of analysis. |
| 1970 |
|
| 1971 |
------------------------- |
| 1972 |
-- Overriding_Possible -- |
| 1973 |
------------------------- |
| 1974 |
|
| 1975 |
function Overriding_Possible |
| 1976 |
(Iface_Op : Entity_Id; |
| 1977 |
Wrapper : Entity_Id) return Boolean |
| 1978 |
is |
| 1979 |
Iface_Op_Spec : constant Node_Id := Parent (Iface_Op); |
| 1980 |
Wrapper_Spec : constant Node_Id := Parent (Wrapper); |
| 1981 |
|
| 1982 |
function Type_Conformant_Parameters |
| 1983 |
(Iface_Op_Params : List_Id; |
| 1984 |
Wrapper_Params : List_Id) return Boolean; |
| 1985 |
-- Determine whether the parameters of the generated entry wrapper |
| 1986 |
-- and those of a primitive operation are type conformant. During |
| 1987 |
-- this check, the first parameter of the primitive operation is |
| 1988 |
-- skipped if it is a controlling argument: protected functions |
| 1989 |
-- may have a controlling result. |
| 1990 |
|
| 1991 |
-------------------------------- |
| 1992 |
-- Type_Conformant_Parameters -- |
| 1993 |
-------------------------------- |
| 1994 |
|
| 1995 |
function Type_Conformant_Parameters |
| 1996 |
(Iface_Op_Params : List_Id; |
| 1997 |
Wrapper_Params : List_Id) return Boolean |
| 1998 |
is |
| 1999 |
Iface_Op_Param : Node_Id; |
| 2000 |
Iface_Op_Typ : Entity_Id; |
| 2001 |
Wrapper_Param : Node_Id; |
| 2002 |
Wrapper_Typ : Entity_Id; |
| 2003 |
|
| 2004 |
begin |
| 2005 |
-- Skip the first (controlling) parameter of primitive operation |
| 2006 |
|
| 2007 |
Iface_Op_Param := First (Iface_Op_Params); |
| 2008 |
|
| 2009 |
if Present (First_Formal (Iface_Op)) |
| 2010 |
and then Is_Controlling_Formal (First_Formal (Iface_Op)) |
| 2011 |
then |
| 2012 |
Next (Iface_Op_Param); |
| 2013 |
end if; |
| 2014 |
|
| 2015 |
Wrapper_Param := First (Wrapper_Params); |
| 2016 |
while Present (Iface_Op_Param) |
| 2017 |
and then Present (Wrapper_Param) |
| 2018 |
loop |
| 2019 |
Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param); |
| 2020 |
Wrapper_Typ := Find_Parameter_Type (Wrapper_Param); |
| 2021 |
|
| 2022 |
-- The two parameters must be mode conformant |
| 2023 |
|
| 2024 |
if not Conforming_Types |
| 2025 |
(Iface_Op_Typ, Wrapper_Typ, Mode_Conformant) |
| 2026 |
then |
| 2027 |
return False; |
| 2028 |
end if; |
| 2029 |
|
| 2030 |
Next (Iface_Op_Param); |
| 2031 |
Next (Wrapper_Param); |
| 2032 |
end loop; |
| 2033 |
|
| 2034 |
-- One of the lists is longer than the other |
| 2035 |
|
| 2036 |
if Present (Iface_Op_Param) or else Present (Wrapper_Param) then |
| 2037 |
return False; |
| 2038 |
end if; |
| 2039 |
|
| 2040 |
return True; |
| 2041 |
end Type_Conformant_Parameters; |
| 2042 |
|
| 2043 |
-- Start of processing for Overriding_Possible |
| 2044 |
|
| 2045 |
begin |
| 2046 |
if Chars (Iface_Op) /= Chars (Wrapper) then |
| 2047 |
return False; |
| 2048 |
end if; |
| 2049 |
|
| 2050 |
-- If an inherited subprogram is implemented by a protected procedure |
| 2051 |
-- or an entry, then the first parameter of the inherited subprogram |
| 2052 |
-- must be of mode OUT or IN OUT, or access-to-variable parameter. |
| 2053 |
|
| 2054 |
if Ekind (Iface_Op) = E_Procedure |
| 2055 |
and then Present (Parameter_Specifications (Iface_Op_Spec)) |
| 2056 |
then |
| 2057 |
declare |
| 2058 |
Obj_Param : constant Node_Id := |
| 2059 |
First (Parameter_Specifications (Iface_Op_Spec)); |
| 2060 |
begin |
| 2061 |
if not Out_Present (Obj_Param) |
| 2062 |
and then Nkind (Parameter_Type (Obj_Param)) /= |
| 2063 |
N_Access_Definition |
| 2064 |
then |
| 2065 |
return False; |
| 2066 |
end if; |
| 2067 |
end; |
| 2068 |
end if; |
| 2069 |
|
| 2070 |
return |
| 2071 |
Type_Conformant_Parameters |
| 2072 |
(Parameter_Specifications (Iface_Op_Spec), |
| 2073 |
Parameter_Specifications (Wrapper_Spec)); |
| 2074 |
end Overriding_Possible; |
| 2075 |
|
| 2076 |
----------------------- |
| 2077 |
-- Replicate_Formals -- |
| 2078 |
----------------------- |
| 2079 |
|
| 2080 |
function Replicate_Formals |
| 2081 |
(Loc : Source_Ptr; |
| 2082 |
Formals : List_Id) return List_Id |
| 2083 |
is |
| 2084 |
New_Formals : constant List_Id := New_List; |
| 2085 |
Formal : Node_Id; |
| 2086 |
Param_Type : Node_Id; |
| 2087 |
|
| 2088 |
begin |
| 2089 |
Formal := First (Formals); |
| 2090 |
|
| 2091 |
-- Skip the object parameter when dealing with primitives declared |
| 2092 |
-- between two views. |
| 2093 |
|
| 2094 |
if Is_Private_Primitive_Subprogram (Subp_Id) |
| 2095 |
and then not Has_Controlling_Result (Subp_Id) |
| 2096 |
then |
| 2097 |
Next (Formal); |
| 2098 |
end if; |
| 2099 |
|
| 2100 |
while Present (Formal) loop |
| 2101 |
|
| 2102 |
-- Create an explicit copy of the entry parameter |
| 2103 |
|
| 2104 |
-- When creating the wrapper subprogram for a primitive operation |
| 2105 |
-- of a protected interface we must construct an equivalent |
| 2106 |
-- signature to that of the overriding operation. For regular |
| 2107 |
-- parameters we can just use the type of the formal, but for |
| 2108 |
-- access to subprogram parameters we need to reanalyze the |
| 2109 |
-- parameter type to create local entities for the signature of |
| 2110 |
-- the subprogram type. Using the entities of the overriding |
| 2111 |
-- subprogram will result in out-of-scope errors in the back-end. |
| 2112 |
|
| 2113 |
if Nkind (Parameter_Type (Formal)) = N_Access_Definition then |
| 2114 |
Param_Type := Copy_Separate_Tree (Parameter_Type (Formal)); |
| 2115 |
else |
| 2116 |
Param_Type := |
| 2117 |
New_Occurrence_Of (Etype (Parameter_Type (Formal)), Loc); |
| 2118 |
end if; |
| 2119 |
|
| 2120 |
Append_To (New_Formals, |
| 2121 |
Make_Parameter_Specification (Loc, |
| 2122 |
Defining_Identifier => |
| 2123 |
Make_Defining_Identifier (Loc, |
| 2124 |
Chars => Chars (Defining_Identifier (Formal))), |
| 2125 |
In_Present => In_Present (Formal), |
| 2126 |
Out_Present => Out_Present (Formal), |
| 2127 |
Null_Exclusion_Present => Null_Exclusion_Present (Formal), |
| 2128 |
Parameter_Type => Param_Type)); |
| 2129 |
|
| 2130 |
Next (Formal); |
| 2131 |
end loop; |
| 2132 |
|
| 2133 |
return New_Formals; |
| 2134 |
end Replicate_Formals; |
| 2135 |
|
| 2136 |
-- Local variables |
| 2137 |
|
| 2138 |
Loc : constant Source_Ptr := Sloc (Subp_Id); |
| 2139 |
First_Param : Node_Id := Empty; |
| 2140 |
Iface : Entity_Id; |
| 2141 |
Iface_Elmt : Elmt_Id; |
| 2142 |
Iface_Op : Entity_Id; |
| 2143 |
Iface_Op_Elmt : Elmt_Id; |
| 2144 |
Overridden_Subp : Entity_Id; |
| 2145 |
|
| 2146 |
-- Start of processing for Build_Wrapper_Spec |
| 2147 |
|
| 2148 |
begin |
| 2149 |
-- No point in building wrappers for untagged concurrent types |
| 2150 |
|
| 2151 |
pragma Assert (Is_Tagged_Type (Obj_Typ)); |
| 2152 |
|
| 2153 |
-- Check if this subprogram has a profile that matches some interface |
| 2154 |
-- primitive. |
| 2155 |
|
| 2156 |
Check_Synchronized_Overriding (Subp_Id, Overridden_Subp); |
| 2157 |
|
| 2158 |
if Present (Overridden_Subp) then |
| 2159 |
First_Param := |
| 2160 |
First (Parameter_Specifications (Parent (Overridden_Subp))); |
| 2161 |
|
| 2162 |
-- An entry or a protected procedure can override a routine where the |
| 2163 |
-- controlling formal is either IN OUT, OUT or is of access-to-variable |
| 2164 |
-- type. Since the wrapper must have the exact same signature as that of |
| 2165 |
-- the overridden subprogram, we try to find the overriding candidate |
| 2166 |
-- and use its controlling formal. |
| 2167 |
|
| 2168 |
-- Check every implemented interface |
| 2169 |
|
| 2170 |
elsif Present (Interfaces (Obj_Typ)) then |
| 2171 |
Iface_Elmt := First_Elmt (Interfaces (Obj_Typ)); |
| 2172 |
Search : while Present (Iface_Elmt) loop |
| 2173 |
Iface := Node (Iface_Elmt); |
| 2174 |
|
| 2175 |
-- Check every interface primitive |
| 2176 |
|
| 2177 |
if Present (Primitive_Operations (Iface)) then |
| 2178 |
Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface)); |
| 2179 |
while Present (Iface_Op_Elmt) loop |
| 2180 |
Iface_Op := Node (Iface_Op_Elmt); |
| 2181 |
|
| 2182 |
-- Ignore predefined primitives |
| 2183 |
|
| 2184 |
if not Is_Predefined_Dispatching_Operation (Iface_Op) then |
| 2185 |
Iface_Op := Ultimate_Alias (Iface_Op); |
| 2186 |
|
| 2187 |
-- The current primitive operation can be overridden by |
| 2188 |
-- the generated entry wrapper. |
| 2189 |
|
| 2190 |
if Overriding_Possible (Iface_Op, Subp_Id) then |
| 2191 |
First_Param := |
| 2192 |
First (Parameter_Specifications (Parent (Iface_Op))); |
| 2193 |
|
| 2194 |
exit Search; |
| 2195 |
end if; |
| 2196 |
end if; |
| 2197 |
|
| 2198 |
Next_Elmt (Iface_Op_Elmt); |
| 2199 |
end loop; |
| 2200 |
end if; |
| 2201 |
|
| 2202 |
Next_Elmt (Iface_Elmt); |
| 2203 |
end loop Search; |
| 2204 |
end if; |
| 2205 |
|
| 2206 |
-- Do not generate the wrapper if no interface primitive is covered by |
| 2207 |
-- the subprogram and it is not a primitive declared between two views |
| 2208 |
-- (see Process_Full_View). |
| 2209 |
|
| 2210 |
if No (First_Param) |
| 2211 |
and then not Is_Private_Primitive_Subprogram (Subp_Id) |
| 2212 |
then |
| 2213 |
return Empty; |
| 2214 |
end if; |
| 2215 |
|
| 2216 |
declare |
| 2217 |
Wrapper_Id : constant Entity_Id := |
| 2218 |
Make_Defining_Identifier (Loc, Chars (Subp_Id)); |
| 2219 |
New_Formals : List_Id; |
| 2220 |
Obj_Param : Node_Id; |
| 2221 |
Obj_Param_Typ : Entity_Id; |
| 2222 |
|
| 2223 |
begin |
| 2224 |
-- Minimum decoration is needed to catch the entity in |
| 2225 |
-- Sem_Ch6.Override_Dispatching_Operation. |
| 2226 |
|
| 2227 |
if Ekind (Subp_Id) = E_Function then |
| 2228 |
Mutate_Ekind (Wrapper_Id, E_Function); |
| 2229 |
else |
| 2230 |
Mutate_Ekind (Wrapper_Id, E_Procedure); |
| 2231 |
end if; |
| 2232 |
|
| 2233 |
Set_Is_Primitive_Wrapper (Wrapper_Id); |
| 2234 |
Set_Wrapped_Entity (Wrapper_Id, Subp_Id); |
| 2235 |
Set_Is_Private_Primitive (Wrapper_Id, |
| 2236 |
Is_Private_Primitive_Subprogram (Subp_Id)); |
| 2237 |
|
| 2238 |
-- Process the formals |
| 2239 |
|
| 2240 |
New_Formals := Replicate_Formals (Loc, Formals); |
| 2241 |
|
| 2242 |
-- A function with a controlling result and no first controlling |
| 2243 |
-- formal needs no additional parameter. |
| 2244 |
|
| 2245 |
if Has_Controlling_Result (Subp_Id) |
| 2246 |
and then |
| 2247 |
(No (First_Formal (Subp_Id)) |
| 2248 |
or else not Is_Controlling_Formal (First_Formal (Subp_Id))) |
| 2249 |
then |
| 2250 |
null; |
| 2251 |
|
| 2252 |
-- Routine Subp_Id has been found to override an interface primitive. |
| 2253 |
-- If the interface operation has an access parameter, create a copy |
| 2254 |
-- of it, with the same null exclusion indicator if present. |
| 2255 |
|
| 2256 |
elsif Present (First_Param) then |
| 2257 |
if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then |
| 2258 |
Obj_Param_Typ := |
| 2259 |
Make_Access_Definition (Loc, |
| 2260 |
Subtype_Mark => |
| 2261 |
New_Occurrence_Of (Obj_Typ, Loc), |
| 2262 |
Null_Exclusion_Present => |
| 2263 |
Null_Exclusion_Present (Parameter_Type (First_Param)), |
| 2264 |
Constant_Present => |
| 2265 |
Constant_Present (Parameter_Type (First_Param))); |
| 2266 |
else |
| 2267 |
Obj_Param_Typ := New_Occurrence_Of (Obj_Typ, Loc); |
| 2268 |
end if; |
| 2269 |
|
| 2270 |
Obj_Param := |
| 2271 |
Make_Parameter_Specification (Loc, |
| 2272 |
Defining_Identifier => |
| 2273 |
Make_Defining_Identifier (Loc, |
| 2274 |
Chars => Name_uO), |
| 2275 |
In_Present => In_Present (First_Param), |
| 2276 |
Out_Present => Out_Present (First_Param), |
| 2277 |
Parameter_Type => Obj_Param_Typ); |
| 2278 |
|
| 2279 |
Prepend_To (New_Formals, Obj_Param); |
| 2280 |
|
| 2281 |
-- If we are dealing with a primitive declared between two views, |
| 2282 |
-- implemented by a synchronized operation, we need to create |
| 2283 |
-- a default parameter. The mode of the parameter must match that |
| 2284 |
-- of the primitive operation. |
| 2285 |
|
| 2286 |
else |
| 2287 |
pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id)); |
| 2288 |
|
| 2289 |
Obj_Param := |
| 2290 |
Make_Parameter_Specification (Loc, |
| 2291 |
Defining_Identifier => |
| 2292 |
Make_Defining_Identifier (Loc, Name_uO), |
| 2293 |
In_Present => |
| 2294 |
In_Present (Parent (First_Entity (Subp_Id))), |
| 2295 |
Out_Present => Ekind (Subp_Id) /= E_Function, |
| 2296 |
Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc)); |
| 2297 |
|
| 2298 |
Prepend_To (New_Formals, Obj_Param); |
| 2299 |
end if; |
| 2300 |
|
| 2301 |
-- Build the final spec. If it is a function with a controlling |
| 2302 |
-- result, it is a primitive operation of the corresponding |
| 2303 |
-- record type, so mark the spec accordingly. |
| 2304 |
|
| 2305 |
if Ekind (Subp_Id) = E_Function then |
| 2306 |
declare |
| 2307 |
Res_Def : Node_Id; |
| 2308 |
|
| 2309 |
begin |
| 2310 |
if Has_Controlling_Result (Subp_Id) then |
| 2311 |
Res_Def := |
| 2312 |
New_Occurrence_Of |
| 2313 |
(Corresponding_Record_Type (Etype (Subp_Id)), Loc); |
| 2314 |
else |
| 2315 |
Res_Def := New_Copy (Result_Definition (Parent (Subp_Id))); |
| 2316 |
end if; |
| 2317 |
|
| 2318 |
return |
| 2319 |
Make_Function_Specification (Loc, |
| 2320 |
Defining_Unit_Name => Wrapper_Id, |
| 2321 |
Parameter_Specifications => New_Formals, |
| 2322 |
Result_Definition => Res_Def); |
| 2323 |
end; |
| 2324 |
else |
| 2325 |
return |
| 2326 |
Make_Procedure_Specification (Loc, |
| 2327 |
Defining_Unit_Name => Wrapper_Id, |
| 2328 |
Parameter_Specifications => New_Formals); |
| 2329 |
end if; |
| 2330 |
end; |
| 2331 |
end Build_Wrapper_Spec; |
| 2332 |
|
| 2333 |
------------------------- |
| 2334 |
-- Build_Wrapper_Specs -- |
| 2335 |
------------------------- |
| 2336 |
|
| 2337 |
procedure Build_Wrapper_Specs |
| 2338 |
(Loc : Source_Ptr; |
| 2339 |
Typ : Entity_Id; |
| 2340 |
N : in out Node_Id) |
| 2341 |
is |
| 2342 |
Def : Node_Id; |
| 2343 |
Rec_Typ : Entity_Id; |
| 2344 |
procedure Scan_Declarations (L : List_Id); |
| 2345 |
-- Common processing for visible and private declarations |
| 2346 |
-- of a protected type. |
| 2347 |
|
| 2348 |
procedure Scan_Declarations (L : List_Id) is |
| 2349 |
Decl : Node_Id; |
| 2350 |
Wrap_Decl : Node_Id; |
| 2351 |
Wrap_Spec : Node_Id; |
| 2352 |
|
| 2353 |
begin |
| 2354 |
if No (L) then |
| 2355 |
return; |
| 2356 |
end if; |
| 2357 |
|
| 2358 |
Decl := First (L); |
| 2359 |
while Present (Decl) loop |
| 2360 |
Wrap_Spec := Empty; |
| 2361 |
|
| 2362 |
if Nkind (Decl) = N_Entry_Declaration |
| 2363 |
and then Ekind (Defining_Identifier (Decl)) = E_Entry |
| 2364 |
then |
| 2365 |
Wrap_Spec := |
| 2366 |
Build_Wrapper_Spec |
| 2367 |
(Subp_Id => Defining_Identifier (Decl), |
| 2368 |
Obj_Typ => Rec_Typ, |
| 2369 |
Formals => Parameter_Specifications (Decl)); |
| 2370 |
|
| 2371 |
elsif Nkind (Decl) = N_Subprogram_Declaration then |
| 2372 |
Wrap_Spec := |
| 2373 |
Build_Wrapper_Spec |
| 2374 |
(Subp_Id => Defining_Unit_Name (Specification (Decl)), |
| 2375 |
Obj_Typ => Rec_Typ, |
| 2376 |
Formals => |
| 2377 |
Parameter_Specifications (Specification (Decl))); |
| 2378 |
end if; |
| 2379 |
|
| 2380 |
if Present (Wrap_Spec) then |
| 2381 |
Wrap_Decl := |
| 2382 |
Make_Subprogram_Declaration (Loc, |
| 2383 |
Specification => Wrap_Spec); |
| 2384 |
|
| 2385 |
Insert_After (N, Wrap_Decl); |
| 2386 |
N := Wrap_Decl; |
| 2387 |
|
| 2388 |
Analyze (Wrap_Decl); |
| 2389 |
end if; |
| 2390 |
|
| 2391 |
Next (Decl); |
| 2392 |
end loop; |
| 2393 |
end Scan_Declarations; |
| 2394 |
|
| 2395 |
-- start of processing for Build_Wrapper_Specs |
| 2396 |
|
| 2397 |
begin |
| 2398 |
if Is_Protected_Type (Typ) then |
| 2399 |
Def := Protected_Definition (Parent (Typ)); |
| 2400 |
else pragma Assert (Is_Task_Type (Typ)); |
| 2401 |
Def := Task_Definition (Parent (Typ)); |
| 2402 |
end if; |
| 2403 |
|
| 2404 |
Rec_Typ := Corresponding_Record_Type (Typ); |
| 2405 |
|
| 2406 |
-- Generate wrapper specs for a concurrent type which implements an |
| 2407 |
-- interface. Operations in both the visible and private parts may |
| 2408 |
-- implement progenitor operations. |
| 2409 |
|
| 2410 |
if Present (Interfaces (Rec_Typ)) and then Present (Def) then |
| 2411 |
Scan_Declarations (Visible_Declarations (Def)); |
| 2412 |
Scan_Declarations (Private_Declarations (Def)); |
| 2413 |
end if; |
| 2414 |
end Build_Wrapper_Specs; |
| 2415 |
|
| 2416 |
--------------------------- |
| 2417 |
-- Build_Find_Body_Index -- |
| 2418 |
--------------------------- |
| 2419 |
|
| 2420 |
function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is |
| 2421 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 2422 |
Ent : Entity_Id; |
| 2423 |
E_Typ : Entity_Id; |
| 2424 |
Has_F : Boolean := False; |
| 2425 |
Index : Nat; |
| 2426 |
If_St : Node_Id := Empty; |
| 2427 |
Lo : Node_Id; |
| 2428 |
Hi : Node_Id; |
| 2429 |
Decls : List_Id := New_List; |
| 2430 |
Ret : Node_Id := Empty; |
| 2431 |
Spec : Node_Id; |
| 2432 |
Siz : Node_Id := Empty; |
| 2433 |
|
| 2434 |
procedure Add_If_Clause (Expr : Node_Id); |
| 2435 |
-- Add test for range of current entry |
| 2436 |
|
| 2437 |
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id; |
| 2438 |
-- If a bound of an entry is given by a discriminant, retrieve the |
| 2439 |
-- actual value of the discriminant from the enclosing object. |
| 2440 |
|
| 2441 |
------------------- |
| 2442 |
-- Add_If_Clause -- |
| 2443 |
------------------- |
| 2444 |
|
| 2445 |
procedure Add_If_Clause (Expr : Node_Id) is |
| 2446 |
Cond : Node_Id; |
| 2447 |
Stats : constant List_Id := |
| 2448 |
New_List ( |
| 2449 |
Make_Simple_Return_Statement (Loc, |
| 2450 |
Expression => Make_Integer_Literal (Loc, Index + 1))); |
| 2451 |
|
| 2452 |
begin |
| 2453 |
-- Index for current entry body |
| 2454 |
|
| 2455 |
Index := Index + 1; |
| 2456 |
|
| 2457 |
-- Compute total length of entry queues so far |
| 2458 |
|
| 2459 |
if No (Siz) then |
| 2460 |
Siz := Expr; |
| 2461 |
else |
| 2462 |
Siz := |
| 2463 |
Make_Op_Add (Loc, |
| 2464 |
Left_Opnd => Siz, |
| 2465 |
Right_Opnd => Expr); |
| 2466 |
end if; |
| 2467 |
|
| 2468 |
Cond := |
| 2469 |
Make_Op_Le (Loc, |
| 2470 |
Left_Opnd => Make_Identifier (Loc, Name_uE), |
| 2471 |
Right_Opnd => Siz); |
| 2472 |
|
| 2473 |
-- Map entry queue indexes in the range of the current family |
| 2474 |
-- into the current index, that designates the entry body. |
| 2475 |
|
| 2476 |
if No (If_St) then |
| 2477 |
If_St := |
| 2478 |
Make_Implicit_If_Statement (Typ, |
| 2479 |
Condition => Cond, |
| 2480 |
Then_Statements => Stats, |
| 2481 |
Elsif_Parts => New_List); |
| 2482 |
Ret := If_St; |
| 2483 |
|
| 2484 |
else |
| 2485 |
Append_To (Elsif_Parts (If_St), |
| 2486 |
Make_Elsif_Part (Loc, |
| 2487 |
Condition => Cond, |
| 2488 |
Then_Statements => Stats)); |
| 2489 |
end if; |
| 2490 |
end Add_If_Clause; |
| 2491 |
|
| 2492 |
------------------------------ |
| 2493 |
-- Convert_Discriminant_Ref -- |
| 2494 |
------------------------------ |
| 2495 |
|
| 2496 |
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is |
| 2497 |
B : Node_Id; |
| 2498 |
|
| 2499 |
begin |
| 2500 |
if Is_Entity_Name (Bound) |
| 2501 |
and then Ekind (Entity (Bound)) = E_Discriminant |
| 2502 |
then |
| 2503 |
B := |
| 2504 |
Make_Selected_Component (Loc, |
| 2505 |
Prefix => |
| 2506 |
Unchecked_Convert_To (Corresponding_Record_Type (Typ), |
| 2507 |
Make_Explicit_Dereference (Loc, |
| 2508 |
Make_Identifier (Loc, Name_uObject))), |
| 2509 |
Selector_Name => Make_Identifier (Loc, Chars (Bound))); |
| 2510 |
Set_Etype (B, Etype (Entity (Bound))); |
| 2511 |
else |
| 2512 |
B := New_Copy_Tree (Bound); |
| 2513 |
end if; |
| 2514 |
|
| 2515 |
return B; |
| 2516 |
end Convert_Discriminant_Ref; |
| 2517 |
|
| 2518 |
-- Start of processing for Build_Find_Body_Index |
| 2519 |
|
| 2520 |
begin |
| 2521 |
Spec := Build_Find_Body_Index_Spec (Typ); |
| 2522 |
|
| 2523 |
Ent := First_Entity (Typ); |
| 2524 |
while Present (Ent) loop |
| 2525 |
if Ekind (Ent) = E_Entry_Family then |
| 2526 |
Has_F := True; |
| 2527 |
exit; |
| 2528 |
end if; |
| 2529 |
|
| 2530 |
Next_Entity (Ent); |
| 2531 |
end loop; |
| 2532 |
|
| 2533 |
if not Has_F then |
| 2534 |
|
| 2535 |
-- If the protected type has no entry families, there is a one-one |
| 2536 |
-- correspondence between entry queue and entry body. |
| 2537 |
|
| 2538 |
Ret := |
| 2539 |
Make_Simple_Return_Statement (Loc, |
| 2540 |
Expression => Make_Identifier (Loc, Name_uE)); |
| 2541 |
|
| 2542 |
else |
| 2543 |
-- Suppose entries e1, e2, ... have size l1, l2, ... we generate |
| 2544 |
-- the following: |
| 2545 |
|
| 2546 |
-- if E <= l1 then return 1; |
| 2547 |
-- elsif E <= l1 + l2 then return 2; |
| 2548 |
-- ... |
| 2549 |
|
| 2550 |
Index := 0; |
| 2551 |
Siz := Empty; |
| 2552 |
Ent := First_Entity (Typ); |
| 2553 |
|
| 2554 |
Add_Object_Pointer (Loc, Typ, Decls); |
| 2555 |
|
| 2556 |
while Present (Ent) loop |
| 2557 |
if Ekind (Ent) = E_Entry then |
| 2558 |
Add_If_Clause (Make_Integer_Literal (Loc, 1)); |
| 2559 |
|
| 2560 |
elsif Ekind (Ent) = E_Entry_Family then |
| 2561 |
E_Typ := Entry_Index_Type (Ent); |
| 2562 |
Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ)); |
| 2563 |
Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ)); |
| 2564 |
Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False)); |
| 2565 |
end if; |
| 2566 |
|
| 2567 |
Next_Entity (Ent); |
| 2568 |
end loop; |
| 2569 |
|
| 2570 |
if Index = 1 then |
| 2571 |
Decls := New_List; |
| 2572 |
Ret := |
| 2573 |
Make_Simple_Return_Statement (Loc, |
| 2574 |
Expression => Make_Integer_Literal (Loc, 1)); |
| 2575 |
|
| 2576 |
else |
| 2577 |
-- Ranges are in increasing order, so last one doesn't need guard |
| 2578 |
|
| 2579 |
declare |
| 2580 |
Nod : constant Node_Id := Last (Elsif_Parts (Ret)); |
| 2581 |
begin |
| 2582 |
Remove (Nod); |
| 2583 |
Set_Else_Statements (Ret, Then_Statements (Nod)); |
| 2584 |
|
| 2585 |
-- If Elsif_Parts becomes empty then remove it entirely, as |
| 2586 |
-- otherwise we would violate the invariant of If_Statement |
| 2587 |
-- node described in Sinfo. |
| 2588 |
|
| 2589 |
if Is_Empty_List (Elsif_Parts (Ret)) then |
| 2590 |
pragma Assert (Elsif_Parts (Ret) /= No_List); |
| 2591 |
Set_Elsif_Parts (Ret, No_List); |
| 2592 |
end if; |
| 2593 |
end; |
| 2594 |
end if; |
| 2595 |
end if; |
| 2596 |
|
| 2597 |
return |
| 2598 |
Make_Subprogram_Body (Loc, |
| 2599 |
Specification => Spec, |
| 2600 |
Declarations => Decls, |
| 2601 |
Handled_Statement_Sequence => |
| 2602 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 2603 |
Statements => New_List (Ret))); |
| 2604 |
end Build_Find_Body_Index; |
| 2605 |
|
| 2606 |
-------------------------------- |
| 2607 |
-- Build_Find_Body_Index_Spec -- |
| 2608 |
-------------------------------- |
| 2609 |
|
| 2610 |
function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is |
| 2611 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 2612 |
Id : constant Entity_Id := |
| 2613 |
Make_Defining_Identifier (Loc, |
| 2614 |
Chars => New_External_Name (Chars (Typ), 'F')); |
| 2615 |
Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO); |
| 2616 |
Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE); |
| 2617 |
|
| 2618 |
begin |
| 2619 |
return |
| 2620 |
Make_Function_Specification (Loc, |
| 2621 |
Defining_Unit_Name => Id, |
| 2622 |
Parameter_Specifications => New_List ( |
| 2623 |
Make_Parameter_Specification (Loc, |
| 2624 |
Defining_Identifier => Parm1, |
| 2625 |
Parameter_Type => |
| 2626 |
New_Occurrence_Of (RTE (RE_Address), Loc)), |
| 2627 |
|
| 2628 |
Make_Parameter_Specification (Loc, |
| 2629 |
Defining_Identifier => Parm2, |
| 2630 |
Parameter_Type => |
| 2631 |
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))), |
| 2632 |
|
| 2633 |
Result_Definition => New_Occurrence_Of ( |
| 2634 |
RTE (RE_Protected_Entry_Index), Loc)); |
| 2635 |
end Build_Find_Body_Index_Spec; |
| 2636 |
|
| 2637 |
----------------------------------------------- |
| 2638 |
-- Build_Lock_Free_Protected_Subprogram_Body -- |
| 2639 |
----------------------------------------------- |
| 2640 |
|
| 2641 |
function Build_Lock_Free_Protected_Subprogram_Body |
| 2642 |
(N : Node_Id; |
| 2643 |
Prot_Typ : Node_Id; |
| 2644 |
Unprot_Spec : Node_Id) return Node_Id |
| 2645 |
is |
| 2646 |
Actuals : constant List_Id := New_List; |
| 2647 |
Loc : constant Source_Ptr := Sloc (N); |
| 2648 |
Spec : constant Node_Id := Specification (N); |
| 2649 |
Unprot_Id : constant Entity_Id := Defining_Unit_Name (Unprot_Spec); |
| 2650 |
Formal : Node_Id; |
| 2651 |
Prot_Spec : Node_Id; |
| 2652 |
Stmt : Node_Id; |
| 2653 |
|
| 2654 |
begin |
| 2655 |
-- Create the protected version of the body |
| 2656 |
|
| 2657 |
Prot_Spec := |
| 2658 |
Build_Protected_Sub_Specification (N, Prot_Typ, Protected_Mode); |
| 2659 |
|
| 2660 |
-- Build the actual parameters which appear in the call to the |
| 2661 |
-- unprotected version of the body. |
| 2662 |
|
| 2663 |
Formal := First (Parameter_Specifications (Prot_Spec)); |
| 2664 |
while Present (Formal) loop |
| 2665 |
Append_To (Actuals, |
| 2666 |
Make_Identifier (Loc, Chars (Defining_Identifier (Formal)))); |
| 2667 |
|
| 2668 |
Next (Formal); |
| 2669 |
end loop; |
| 2670 |
|
| 2671 |
-- Function case, generate: |
| 2672 |
-- return <Unprot_Func_Call>; |
| 2673 |
|
| 2674 |
if Nkind (Spec) = N_Function_Specification then |
| 2675 |
Stmt := |
| 2676 |
Make_Simple_Return_Statement (Loc, |
| 2677 |
Expression => |
| 2678 |
Make_Function_Call (Loc, |
| 2679 |
Name => |
| 2680 |
Make_Identifier (Loc, Chars (Unprot_Id)), |
| 2681 |
Parameter_Associations => Actuals)); |
| 2682 |
|
| 2683 |
-- Procedure case, call the unprotected version |
| 2684 |
|
| 2685 |
else |
| 2686 |
Stmt := |
| 2687 |
Make_Procedure_Call_Statement (Loc, |
| 2688 |
Name => |
| 2689 |
Make_Identifier (Loc, Chars (Unprot_Id)), |
| 2690 |
Parameter_Associations => Actuals); |
| 2691 |
end if; |
| 2692 |
|
| 2693 |
return |
| 2694 |
Make_Subprogram_Body (Loc, |
| 2695 |
Declarations => Empty_List, |
| 2696 |
Specification => Prot_Spec, |
| 2697 |
Handled_Statement_Sequence => |
| 2698 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 2699 |
Statements => New_List (Stmt))); |
| 2700 |
end Build_Lock_Free_Protected_Subprogram_Body; |
| 2701 |
|
| 2702 |
------------------------------------------------- |
| 2703 |
-- Build_Lock_Free_Unprotected_Subprogram_Body -- |
| 2704 |
------------------------------------------------- |
| 2705 |
|
| 2706 |
-- Procedures which meet the lock-free implementation requirements and |
| 2707 |
-- reference a unique scalar component Comp are expanded in the following |
| 2708 |
-- manner: |
| 2709 |
|
| 2710 |
-- procedure P (...) is |
| 2711 |
-- Expected_Comp : constant Comp_Type := |
| 2712 |
-- Comp_Type |
| 2713 |
-- (System.Atomic_Primitives.Lock_Free_Read_N |
| 2714 |
-- (_Object.Comp'Address)); |
| 2715 |
-- begin |
| 2716 |
-- loop |
| 2717 |
-- declare |
| 2718 |
-- <original declarations before the object renaming declaration |
| 2719 |
-- of Comp> |
| 2720 |
-- |
| 2721 |
-- Desired_Comp : Comp_Type := Expected_Comp; |
| 2722 |
-- Comp : Comp_Type renames Desired_Comp; |
| 2723 |
-- |
| 2724 |
-- <original declarations after the object renaming declaration |
| 2725 |
-- of Comp> |
| 2726 |
-- |
| 2727 |
-- begin |
| 2728 |
-- <original statements> |
| 2729 |
-- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N |
| 2730 |
-- (_Object.Comp'Address, |
| 2731 |
-- Interfaces.Unsigned_N (Expected_Comp), |
| 2732 |
-- Interfaces.Unsigned_N (Desired_Comp)); |
| 2733 |
-- end; |
| 2734 |
-- end loop; |
| 2735 |
-- end P; |
| 2736 |
|
| 2737 |
-- Each return and raise statement of P is transformed into an atomic |
| 2738 |
-- status check: |
| 2739 |
|
| 2740 |
-- if System.Atomic_Primitives.Lock_Free_Try_Write_N |
| 2741 |
-- (_Object.Comp'Address, |
| 2742 |
-- Interfaces.Unsigned_N (Expected_Comp), |
| 2743 |
-- Interfaces.Unsigned_N (Desired_Comp)); |
| 2744 |
-- then |
| 2745 |
-- <original statement> |
| 2746 |
-- else |
| 2747 |
-- goto L0; |
| 2748 |
-- end if; |
| 2749 |
|
| 2750 |
-- Functions which meet the lock-free implementation requirements and |
| 2751 |
-- reference a unique scalar component Comp are expanded in the following |
| 2752 |
-- manner: |
| 2753 |
|
| 2754 |
-- function F (...) return ... is |
| 2755 |
-- <original declarations before the object renaming declaration |
| 2756 |
-- of Comp> |
| 2757 |
-- |
| 2758 |
-- Expected_Comp : constant Comp_Type := |
| 2759 |
-- Comp_Type |
| 2760 |
-- (System.Atomic_Primitives.Lock_Free_Read_N |
| 2761 |
-- (_Object.Comp'Address)); |
| 2762 |
-- Comp : Comp_Type renames Expected_Comp; |
| 2763 |
-- |
| 2764 |
-- <original declarations after the object renaming declaration of |
| 2765 |
-- Comp> |
| 2766 |
-- |
| 2767 |
-- begin |
| 2768 |
-- <original statements> |
| 2769 |
-- end F; |
| 2770 |
|
| 2771 |
function Build_Lock_Free_Unprotected_Subprogram_Body |
| 2772 |
(N : Node_Id; |
| 2773 |
Prot_Typ : Node_Id) return Node_Id |
| 2774 |
is |
| 2775 |
function Referenced_Component (N : Node_Id) return Entity_Id; |
| 2776 |
-- Subprograms which meet the lock-free implementation criteria are |
| 2777 |
-- allowed to reference only one unique component. Return the prival |
| 2778 |
-- of the said component. |
| 2779 |
|
| 2780 |
-------------------------- |
| 2781 |
-- Referenced_Component -- |
| 2782 |
-------------------------- |
| 2783 |
|
| 2784 |
function Referenced_Component (N : Node_Id) return Entity_Id is |
| 2785 |
Comp : Entity_Id; |
| 2786 |
Decl : Node_Id; |
| 2787 |
Source_Comp : Entity_Id := Empty; |
| 2788 |
|
| 2789 |
begin |
| 2790 |
-- Find the unique source component which N references in its |
| 2791 |
-- statements. |
| 2792 |
|
| 2793 |
for Index in 1 .. Lock_Free_Subprogram_Table.Last loop |
| 2794 |
declare |
| 2795 |
Element : Lock_Free_Subprogram renames |
| 2796 |
Lock_Free_Subprogram_Table.Table (Index); |
| 2797 |
begin |
| 2798 |
if Element.Sub_Body = N then |
| 2799 |
Source_Comp := Element.Comp_Id; |
| 2800 |
exit; |
| 2801 |
end if; |
| 2802 |
end; |
| 2803 |
end loop; |
| 2804 |
|
| 2805 |
if No (Source_Comp) then |
| 2806 |
return Empty; |
| 2807 |
end if; |
| 2808 |
|
| 2809 |
-- Find the prival which corresponds to the source component within |
| 2810 |
-- the declarations of N. |
| 2811 |
|
| 2812 |
Decl := First (Declarations (N)); |
| 2813 |
while Present (Decl) loop |
| 2814 |
|
| 2815 |
-- Privals appear as object renamings |
| 2816 |
|
| 2817 |
if Nkind (Decl) = N_Object_Renaming_Declaration then |
| 2818 |
Comp := Defining_Identifier (Decl); |
| 2819 |
|
| 2820 |
if Present (Prival_Link (Comp)) |
| 2821 |
and then Prival_Link (Comp) = Source_Comp |
| 2822 |
then |
| 2823 |
return Comp; |
| 2824 |
end if; |
| 2825 |
end if; |
| 2826 |
|
| 2827 |
Next (Decl); |
| 2828 |
end loop; |
| 2829 |
|
| 2830 |
return Empty; |
| 2831 |
end Referenced_Component; |
| 2832 |
|
| 2833 |
-- Local variables |
| 2834 |
|
| 2835 |
Comp : constant Entity_Id := Referenced_Component (N); |
| 2836 |
Loc : constant Source_Ptr := Sloc (N); |
| 2837 |
Hand_Stmt_Seq : Node_Id := Handled_Statement_Sequence (N); |
| 2838 |
Decls : List_Id := Declarations (N); |
| 2839 |
|
| 2840 |
-- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body |
| 2841 |
|
| 2842 |
begin |
| 2843 |
-- Add renamings for the protection object, discriminals, privals, and |
| 2844 |
-- the entry index constant for use by debugger. |
| 2845 |
|
| 2846 |
Debug_Private_Data_Declarations (Decls); |
| 2847 |
|
| 2848 |
-- Perform the lock-free expansion when the subprogram references a |
| 2849 |
-- protected component. |
| 2850 |
|
| 2851 |
if Present (Comp) then |
| 2852 |
Protected_Component_Ref : declare |
| 2853 |
Comp_Decl : constant Node_Id := Parent (Comp); |
| 2854 |
Comp_Sel_Nam : constant Node_Id := Name (Comp_Decl); |
| 2855 |
Comp_Type : constant Entity_Id := Etype (Comp); |
| 2856 |
|
| 2857 |
Is_Procedure : constant Boolean := |
| 2858 |
Ekind (Corresponding_Spec (N)) = E_Procedure; |
| 2859 |
-- Indicates if N is a protected procedure body |
| 2860 |
|
| 2861 |
Block_Decls : List_Id := No_List; |
| 2862 |
Try_Write : Entity_Id; |
| 2863 |
Desired_Comp : Entity_Id; |
| 2864 |
Decl : Node_Id; |
| 2865 |
Label : Node_Id; |
| 2866 |
Label_Id : Entity_Id := Empty; |
| 2867 |
Read : Entity_Id; |
| 2868 |
Expected_Comp : Entity_Id; |
| 2869 |
Stmt : Node_Id; |
| 2870 |
Stmts : List_Id := |
| 2871 |
New_Copy_List_Tree (Statements (Hand_Stmt_Seq)); |
| 2872 |
Typ_Size : Int; |
| 2873 |
Unsigned : Entity_Id; |
| 2874 |
|
| 2875 |
function Process_Node (N : Node_Id) return Traverse_Result; |
| 2876 |
-- Transform a single node if it is a return statement, a raise |
| 2877 |
-- statement or a reference to Comp. |
| 2878 |
|
| 2879 |
procedure Process_Stmts (Stmts : List_Id); |
| 2880 |
-- Given a statement sequence Stmts, wrap any return or raise |
| 2881 |
-- statements in the following manner: |
| 2882 |
-- |
| 2883 |
-- if System.Atomic_Primitives.Lock_Free_Try_Write_N |
| 2884 |
-- (_Object.Comp'Address, |
| 2885 |
-- Interfaces.Unsigned_N (Expected_Comp), |
| 2886 |
-- Interfaces.Unsigned_N (Desired_Comp)) |
| 2887 |
-- then |
| 2888 |
-- <Stmt>; |
| 2889 |
-- else |
| 2890 |
-- goto L0; |
| 2891 |
-- end if; |
| 2892 |
|
| 2893 |
------------------ |
| 2894 |
-- Process_Node -- |
| 2895 |
------------------ |
| 2896 |
|
| 2897 |
function Process_Node (N : Node_Id) return Traverse_Result is |
| 2898 |
|
| 2899 |
procedure Wrap_Statement (Stmt : Node_Id); |
| 2900 |
-- Wrap an arbitrary statement inside an if statement where the |
| 2901 |
-- condition does an atomic check on the state of the object. |
| 2902 |
|
| 2903 |
-------------------- |
| 2904 |
-- Wrap_Statement -- |
| 2905 |
-------------------- |
| 2906 |
|
| 2907 |
procedure Wrap_Statement (Stmt : Node_Id) is |
| 2908 |
begin |
| 2909 |
-- The first time through, create the declaration of a label |
| 2910 |
-- which is used to skip the remainder of source statements |
| 2911 |
-- if the state of the object has changed. |
| 2912 |
|
| 2913 |
if No (Label_Id) then |
| 2914 |
Label_Id := |
| 2915 |
Make_Identifier (Loc, New_External_Name ('L', 0)); |
| 2916 |
Set_Entity (Label_Id, |
| 2917 |
Make_Defining_Identifier (Loc, Chars (Label_Id))); |
| 2918 |
end if; |
| 2919 |
|
| 2920 |
-- Generate: |
| 2921 |
-- if System.Atomic_Primitives.Lock_Free_Try_Write_N |
| 2922 |
-- (_Object.Comp'Address, |
| 2923 |
-- Interfaces.Unsigned_N (Expected_Comp), |
| 2924 |
-- Interfaces.Unsigned_N (Desired_Comp)) |
| 2925 |
-- then |
| 2926 |
-- <Stmt>; |
| 2927 |
-- else |
| 2928 |
-- goto L0; |
| 2929 |
-- end if; |
| 2930 |
|
| 2931 |
Rewrite (Stmt, |
| 2932 |
Make_Implicit_If_Statement (N, |
| 2933 |
Condition => |
| 2934 |
Make_Function_Call (Loc, |
| 2935 |
Name => |
| 2936 |
New_Occurrence_Of (Try_Write, Loc), |
| 2937 |
Parameter_Associations => New_List ( |
| 2938 |
Make_Attribute_Reference (Loc, |
| 2939 |
Prefix => Relocate_Node (Comp_Sel_Nam), |
| 2940 |
Attribute_Name => Name_Address), |
| 2941 |
|
| 2942 |
Unchecked_Convert_To (Unsigned, |
| 2943 |
New_Occurrence_Of (Expected_Comp, Loc)), |
| 2944 |
|
| 2945 |
Unchecked_Convert_To (Unsigned, |
| 2946 |
New_Occurrence_Of (Desired_Comp, Loc)))), |
| 2947 |
|
| 2948 |
Then_Statements => New_List (Relocate_Node (Stmt)), |
| 2949 |
|
| 2950 |
Else_Statements => New_List ( |
| 2951 |
Make_Goto_Statement (Loc, |
| 2952 |
Name => |
| 2953 |
New_Occurrence_Of (Entity (Label_Id), Loc))))); |
| 2954 |
end Wrap_Statement; |
| 2955 |
|
| 2956 |
-- Start of processing for Process_Node |
| 2957 |
|
| 2958 |
begin |
| 2959 |
-- Wrap each return and raise statement that appear inside a |
| 2960 |
-- procedure. Skip the last return statement which is added by |
| 2961 |
-- default since it is transformed into an exit statement. |
| 2962 |
|
| 2963 |
if Is_Procedure |
| 2964 |
and then ((Nkind (N) = N_Simple_Return_Statement |
| 2965 |
and then N /= Last (Stmts)) |
| 2966 |
or else Nkind (N) = N_Extended_Return_Statement |
| 2967 |
or else (Nkind (N) in |
| 2968 |
N_Raise_xxx_Error | N_Raise_Statement |
| 2969 |
and then Comes_From_Source (N))) |
| 2970 |
then |
| 2971 |
Wrap_Statement (N); |
| 2972 |
return Skip; |
| 2973 |
end if; |
| 2974 |
|
| 2975 |
-- Force reanalysis |
| 2976 |
|
| 2977 |
Set_Analyzed (N, False); |
| 2978 |
|
| 2979 |
return OK; |
| 2980 |
end Process_Node; |
| 2981 |
|
| 2982 |
procedure Process_Nodes is new Traverse_Proc (Process_Node); |
| 2983 |
|
| 2984 |
------------------- |
| 2985 |
-- Process_Stmts -- |
| 2986 |
------------------- |
| 2987 |
|
| 2988 |
procedure Process_Stmts (Stmts : List_Id) is |
| 2989 |
Stmt : Node_Id; |
| 2990 |
begin |
| 2991 |
Stmt := First (Stmts); |
| 2992 |
while Present (Stmt) loop |
| 2993 |
Process_Nodes (Stmt); |
| 2994 |
Next (Stmt); |
| 2995 |
end loop; |
| 2996 |
end Process_Stmts; |
| 2997 |
|
| 2998 |
-- Start of processing for Protected_Component_Ref |
| 2999 |
|
| 3000 |
begin |
| 3001 |
-- Get the type size |
| 3002 |
|
| 3003 |
if Known_Static_Esize (Comp_Type) then |
| 3004 |
Typ_Size := UI_To_Int (Esize (Comp_Type)); |
| 3005 |
|
| 3006 |
-- If the Esize (Object_Size) is unknown at compile time, look at |
| 3007 |
-- the RM_Size (Value_Size) since it may have been set by an |
| 3008 |
-- explicit representation clause. |
| 3009 |
|
| 3010 |
elsif Known_Static_RM_Size (Comp_Type) then |
| 3011 |
Typ_Size := UI_To_Int (RM_Size (Comp_Type)); |
| 3012 |
|
| 3013 |
-- Should not happen since this has already been checked in |
| 3014 |
-- Allows_Lock_Free_Implementation (see Sem_Ch9). |
| 3015 |
|
| 3016 |
else |
| 3017 |
raise Program_Error; |
| 3018 |
end if; |
| 3019 |
|
| 3020 |
-- Retrieve all relevant atomic routines and types |
| 3021 |
|
| 3022 |
case Typ_Size is |
| 3023 |
when 8 => |
| 3024 |
Try_Write := RTE (RE_Lock_Free_Try_Write_8); |
| 3025 |
Read := RTE (RE_Lock_Free_Read_8); |
| 3026 |
Unsigned := RTE (RE_Uint8); |
| 3027 |
|
| 3028 |
when 16 => |
| 3029 |
Try_Write := RTE (RE_Lock_Free_Try_Write_16); |
| 3030 |
Read := RTE (RE_Lock_Free_Read_16); |
| 3031 |
Unsigned := RTE (RE_Uint16); |
| 3032 |
|
| 3033 |
when 32 => |
| 3034 |
Try_Write := RTE (RE_Lock_Free_Try_Write_32); |
| 3035 |
Read := RTE (RE_Lock_Free_Read_32); |
| 3036 |
Unsigned := RTE (RE_Uint32); |
| 3037 |
|
| 3038 |
when 64 => |
| 3039 |
Try_Write := RTE (RE_Lock_Free_Try_Write_64); |
| 3040 |
Read := RTE (RE_Lock_Free_Read_64); |
| 3041 |
Unsigned := RTE (RE_Uint64); |
| 3042 |
|
| 3043 |
when others => |
| 3044 |
raise Program_Error; |
| 3045 |
end case; |
| 3046 |
|
| 3047 |
-- Generate: |
| 3048 |
-- Expected_Comp : constant Comp_Type := |
| 3049 |
-- Comp_Type |
| 3050 |
-- (System.Atomic_Primitives.Lock_Free_Read_N |
| 3051 |
-- (_Object.Comp'Address)); |
| 3052 |
|
| 3053 |
Expected_Comp := |
| 3054 |
Make_Defining_Identifier (Loc, |
| 3055 |
New_External_Name (Chars (Comp), Suffix => "_saved")); |
| 3056 |
|
| 3057 |
Decl := |
| 3058 |
Make_Object_Declaration (Loc, |
| 3059 |
Defining_Identifier => Expected_Comp, |
| 3060 |
Object_Definition => New_Occurrence_Of (Comp_Type, Loc), |
| 3061 |
Constant_Present => True, |
| 3062 |
Expression => |
| 3063 |
Unchecked_Convert_To (Comp_Type, |
| 3064 |
Make_Function_Call (Loc, |
| 3065 |
Name => New_Occurrence_Of (Read, Loc), |
| 3066 |
Parameter_Associations => New_List ( |
| 3067 |
Make_Attribute_Reference (Loc, |
| 3068 |
Prefix => Relocate_Node (Comp_Sel_Nam), |
| 3069 |
Attribute_Name => Name_Address))))); |
| 3070 |
|
| 3071 |
-- Protected procedures |
| 3072 |
|
| 3073 |
if Is_Procedure then |
| 3074 |
-- Move the original declarations inside the generated block |
| 3075 |
|
| 3076 |
Block_Decls := Decls; |
| 3077 |
|
| 3078 |
-- Reset the declarations list of the protected procedure to |
| 3079 |
-- contain only Decl. |
| 3080 |
|
| 3081 |
Decls := New_List (Decl); |
| 3082 |
|
| 3083 |
-- Generate: |
| 3084 |
-- Desired_Comp : Comp_Type := Expected_Comp; |
| 3085 |
|
| 3086 |
Desired_Comp := |
| 3087 |
Make_Defining_Identifier (Loc, |
| 3088 |
New_External_Name (Chars (Comp), Suffix => "_current")); |
| 3089 |
|
| 3090 |
-- Insert the declarations of Expected_Comp and Desired_Comp in |
| 3091 |
-- the block declarations right before the renaming of the |
| 3092 |
-- protected component. |
| 3093 |
|
| 3094 |
Insert_Before (Comp_Decl, |
| 3095 |
Make_Object_Declaration (Loc, |
| 3096 |
Defining_Identifier => Desired_Comp, |
| 3097 |
Object_Definition => New_Occurrence_Of (Comp_Type, Loc), |
| 3098 |
Expression => |
| 3099 |
New_Occurrence_Of (Expected_Comp, Loc))); |
| 3100 |
|
| 3101 |
-- Protected function |
| 3102 |
|
| 3103 |
else |
| 3104 |
Desired_Comp := Expected_Comp; |
| 3105 |
|
| 3106 |
-- Insert the declaration of Expected_Comp in the function |
| 3107 |
-- declarations right before the renaming of the protected |
| 3108 |
-- component. |
| 3109 |
|
| 3110 |
Insert_Before (Comp_Decl, Decl); |
| 3111 |
end if; |
| 3112 |
|
| 3113 |
-- Rewrite the protected component renaming declaration to be a |
| 3114 |
-- renaming of Desired_Comp. |
| 3115 |
|
| 3116 |
-- Generate: |
| 3117 |
-- Comp : Comp_Type renames Desired_Comp; |
| 3118 |
|
| 3119 |
Rewrite (Comp_Decl, |
| 3120 |
Make_Object_Renaming_Declaration (Loc, |
| 3121 |
Defining_Identifier => |
| 3122 |
Defining_Identifier (Comp_Decl), |
| 3123 |
Subtype_Mark => |
| 3124 |
New_Occurrence_Of (Comp_Type, Loc), |
| 3125 |
Name => |
| 3126 |
New_Occurrence_Of (Desired_Comp, Loc))); |
| 3127 |
|
| 3128 |
-- Wrap any return or raise statements in Stmts in same the manner |
| 3129 |
-- described in Process_Stmts. |
| 3130 |
|
| 3131 |
Process_Stmts (Stmts); |
| 3132 |
|
| 3133 |
-- Generate: |
| 3134 |
-- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N |
| 3135 |
-- (_Object.Comp'Address, |
| 3136 |
-- Interfaces.Unsigned_N (Expected_Comp), |
| 3137 |
-- Interfaces.Unsigned_N (Desired_Comp)) |
| 3138 |
|
| 3139 |
if Is_Procedure then |
| 3140 |
Stmt := |
| 3141 |
Make_Exit_Statement (Loc, |
| 3142 |
Condition => |
| 3143 |
Make_Function_Call (Loc, |
| 3144 |
Name => |
| 3145 |
New_Occurrence_Of (Try_Write, Loc), |
| 3146 |
Parameter_Associations => New_List ( |
| 3147 |
Make_Attribute_Reference (Loc, |
| 3148 |
Prefix => Relocate_Node (Comp_Sel_Nam), |
| 3149 |
Attribute_Name => Name_Address), |
| 3150 |
|
| 3151 |
Unchecked_Convert_To (Unsigned, |
| 3152 |
New_Occurrence_Of (Expected_Comp, Loc)), |
| 3153 |
|
| 3154 |
Unchecked_Convert_To (Unsigned, |
| 3155 |
New_Occurrence_Of (Desired_Comp, Loc))))); |
| 3156 |
|
| 3157 |
-- Small optimization: transform the default return statement |
| 3158 |
-- of a procedure into the atomic exit statement. |
| 3159 |
|
| 3160 |
if Nkind (Last (Stmts)) = N_Simple_Return_Statement then |
| 3161 |
Rewrite (Last (Stmts), Stmt); |
| 3162 |
else |
| 3163 |
Append_To (Stmts, Stmt); |
| 3164 |
end if; |
| 3165 |
end if; |
| 3166 |
|
| 3167 |
-- Create the declaration of the label used to skip the rest of |
| 3168 |
-- the source statements when the object state changes. |
| 3169 |
|
| 3170 |
if Present (Label_Id) then |
| 3171 |
Label := Make_Label (Loc, Label_Id); |
| 3172 |
Append_To (Decls, |
| 3173 |
Make_Implicit_Label_Declaration (Loc, |
| 3174 |
Defining_Identifier => Entity (Label_Id), |
| 3175 |
Label_Construct => Label)); |
| 3176 |
Append_To (Stmts, Label); |
| 3177 |
end if; |
| 3178 |
|
| 3179 |
-- Generate: |
| 3180 |
-- loop |
| 3181 |
-- declare |
| 3182 |
-- <Decls> |
| 3183 |
-- begin |
| 3184 |
-- <Stmts> |
| 3185 |
-- end; |
| 3186 |
-- end loop; |
| 3187 |
|
| 3188 |
if Is_Procedure then |
| 3189 |
Stmts := |
| 3190 |
New_List ( |
| 3191 |
Make_Loop_Statement (Loc, |
| 3192 |
Statements => New_List ( |
| 3193 |
Make_Block_Statement (Loc, |
| 3194 |
Declarations => Block_Decls, |
| 3195 |
Handled_Statement_Sequence => |
| 3196 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 3197 |
Statements => Stmts))), |
| 3198 |
End_Label => Empty)); |
| 3199 |
end if; |
| 3200 |
|
| 3201 |
Hand_Stmt_Seq := |
| 3202 |
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts); |
| 3203 |
end Protected_Component_Ref; |
| 3204 |
end if; |
| 3205 |
|
| 3206 |
-- Make an unprotected version of the subprogram for use within the same |
| 3207 |
-- object, with new name and extra parameter representing the object. |
| 3208 |
|
| 3209 |
return |
| 3210 |
Make_Subprogram_Body (Loc, |
| 3211 |
Specification => |
| 3212 |
Build_Protected_Sub_Specification (N, Prot_Typ, Unprotected_Mode), |
| 3213 |
Declarations => Decls, |
| 3214 |
Handled_Statement_Sequence => Hand_Stmt_Seq); |
| 3215 |
end Build_Lock_Free_Unprotected_Subprogram_Body; |
| 3216 |
|
| 3217 |
------------------------- |
| 3218 |
-- Build_Master_Entity -- |
| 3219 |
------------------------- |
| 3220 |
|
| 3221 |
procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is |
| 3222 |
Loc : constant Source_Ptr := Sloc (Obj_Or_Typ); |
| 3223 |
Context : Node_Id; |
| 3224 |
Context_Id : Entity_Id; |
| 3225 |
Decl : Node_Id; |
| 3226 |
Decls : List_Id; |
| 3227 |
Par : Node_Id; |
| 3228 |
|
| 3229 |
begin |
| 3230 |
-- No action needed if the run-time has no tasking support |
| 3231 |
|
| 3232 |
if Global_No_Tasking then |
| 3233 |
return; |
| 3234 |
end if; |
| 3235 |
|
| 3236 |
if Is_Itype (Obj_Or_Typ) then |
| 3237 |
Par := Associated_Node_For_Itype (Obj_Or_Typ); |
| 3238 |
else |
| 3239 |
Par := Parent (Obj_Or_Typ); |
| 3240 |
end if; |
| 3241 |
|
| 3242 |
-- When creating a master for a record component which is either a task |
| 3243 |
-- or access-to-task, the enclosing record is the master scope and the |
| 3244 |
-- proper insertion point is the component list. |
| 3245 |
|
| 3246 |
if Is_Record_Type (Current_Scope) then |
| 3247 |
Context := Par; |
| 3248 |
Context_Id := Current_Scope; |
| 3249 |
Decls := List_Containing (Context); |
| 3250 |
|
| 3251 |
-- Default case for object declarations and access types. Note that the |
| 3252 |
-- context is updated to the nearest enclosing body, block, package, or |
| 3253 |
-- return statement. |
| 3254 |
|
| 3255 |
else |
| 3256 |
Find_Enclosing_Context (Par, Context, Context_Id, Decls); |
| 3257 |
end if; |
| 3258 |
|
| 3259 |
-- When the enclosing context is a BIP function whose result type has |
| 3260 |
-- tasks, the function has an extra formal that is the master of the |
| 3261 |
-- tasks to be created by its returned object (that is, when its |
| 3262 |
-- enclosing context is a return statement). However, if the body of |
| 3263 |
-- the function creates tasks before its return statements, such tasks |
| 3264 |
-- need their own master. |
| 3265 |
|
| 3266 |
if Has_Master_Entity (Context_Id) |
| 3267 |
and then Ekind (Context_Id) = E_Function |
| 3268 |
and then Is_Build_In_Place_Function (Context_Id) |
| 3269 |
and then Needs_BIP_Task_Actuals (Context_Id) |
| 3270 |
then |
| 3271 |
-- No need to add it again if previously added |
| 3272 |
|
| 3273 |
declare |
| 3274 |
Master_Present : Boolean; |
| 3275 |
|
| 3276 |
begin |
| 3277 |
-- Handle transient scopes |
| 3278 |
|
| 3279 |
if Context_Id /= Current_Scope then |
| 3280 |
Push_Scope (Context_Id); |
| 3281 |
Master_Present := |
| 3282 |
Present (Current_Entity_In_Scope (Name_uMaster)); |
| 3283 |
Pop_Scope; |
| 3284 |
else |
| 3285 |
Master_Present := |
| 3286 |
Present (Current_Entity_In_Scope (Name_uMaster)); |
| 3287 |
end if; |
| 3288 |
|
| 3289 |
if Master_Present then |
| 3290 |
return; |
| 3291 |
end if; |
| 3292 |
end; |
| 3293 |
|
| 3294 |
-- Nothing to do if the context already has a master; internally built |
| 3295 |
-- finalizers don't need a master. |
| 3296 |
|
| 3297 |
elsif Has_Master_Entity (Context_Id) |
| 3298 |
or else Is_Finalizer (Context_Id) |
| 3299 |
then |
| 3300 |
return; |
| 3301 |
end if; |
| 3302 |
|
| 3303 |
Decl := Build_Master_Declaration (Loc); |
| 3304 |
|
| 3305 |
-- The master is inserted at the start of the declarative list of the |
| 3306 |
-- context. |
| 3307 |
|
| 3308 |
Prepend_To (Decls, Decl); |
| 3309 |
|
| 3310 |
-- In certain cases where transient scopes are involved, the immediate |
| 3311 |
-- scope is not always the proper master scope. Ensure that the master |
| 3312 |
-- declaration and entity appear in the same context. |
| 3313 |
|
| 3314 |
if Context_Id /= Current_Scope then |
| 3315 |
Push_Scope (Context_Id); |
| 3316 |
Analyze (Decl); |
| 3317 |
Pop_Scope; |
| 3318 |
else |
| 3319 |
Analyze (Decl); |
| 3320 |
end if; |
| 3321 |
|
| 3322 |
-- Mark the enclosing scope and its associated construct as being task |
| 3323 |
-- masters. |
| 3324 |
|
| 3325 |
Set_Has_Master_Entity (Context_Id); |
| 3326 |
|
| 3327 |
while Present (Context) |
| 3328 |
and then Nkind (Context) /= N_Compilation_Unit |
| 3329 |
loop |
| 3330 |
if Nkind (Context) in |
| 3331 |
N_Block_Statement | N_Subprogram_Body | N_Task_Body |
| 3332 |
then |
| 3333 |
Set_Is_Task_Master (Context); |
| 3334 |
exit; |
| 3335 |
|
| 3336 |
elsif Nkind (Parent (Context)) = N_Subunit then |
| 3337 |
Context := Corresponding_Stub (Parent (Context)); |
| 3338 |
end if; |
| 3339 |
|
| 3340 |
Context := Parent (Context); |
| 3341 |
end loop; |
| 3342 |
end Build_Master_Entity; |
| 3343 |
|
| 3344 |
--------------------------- |
| 3345 |
-- Build_Master_Renaming -- |
| 3346 |
--------------------------- |
| 3347 |
|
| 3348 |
procedure Build_Master_Renaming |
| 3349 |
(Ptr_Typ : Entity_Id; |
| 3350 |
Ins_Nod : Node_Id := Empty) |
| 3351 |
is |
| 3352 |
Loc : constant Source_Ptr := Sloc (Ptr_Typ); |
| 3353 |
Context : Node_Id; |
| 3354 |
Master_Decl : Node_Id; |
| 3355 |
Master_Id : Entity_Id; |
| 3356 |
|
| 3357 |
begin |
| 3358 |
-- No action needed if the run-time has no tasking support |
| 3359 |
|
| 3360 |
if Global_No_Tasking then |
| 3361 |
return; |
| 3362 |
end if; |
| 3363 |
|
| 3364 |
-- Determine the proper context to insert the master renaming |
| 3365 |
|
| 3366 |
if Present (Ins_Nod) then |
| 3367 |
Context := Ins_Nod; |
| 3368 |
|
| 3369 |
elsif Is_Itype (Ptr_Typ) then |
| 3370 |
Context := Associated_Node_For_Itype (Ptr_Typ); |
| 3371 |
|
| 3372 |
-- When the context references a discriminant or a component of a |
| 3373 |
-- private type and we are processing declarations in the private |
| 3374 |
-- part of the enclosing package, we must insert the master renaming |
| 3375 |
-- before the full declaration of the private type; otherwise the |
| 3376 |
-- master renaming would be inserted in the public part of the |
| 3377 |
-- package (and hence before the declaration of _master). |
| 3378 |
|
| 3379 |
if In_Private_Part (Current_Scope) then |
| 3380 |
declare |
| 3381 |
Ctx : Node_Id := Context; |
| 3382 |
|
| 3383 |
begin |
| 3384 |
if Nkind (Context) = N_Discriminant_Specification then |
| 3385 |
Ctx := Parent (Ctx); |
| 3386 |
else |
| 3387 |
while Nkind (Ctx) in |
| 3388 |
N_Component_Declaration | N_Component_List |
| 3389 |
loop |
| 3390 |
Ctx := Parent (Ctx); |
| 3391 |
end loop; |
| 3392 |
end if; |
| 3393 |
|
| 3394 |
if Nkind (Ctx) in N_Private_Type_Declaration |
| 3395 |
| N_Private_Extension_Declaration |
| 3396 |
then |
| 3397 |
Context := Parent (Full_View (Defining_Identifier (Ctx))); |
| 3398 |
end if; |
| 3399 |
end; |
| 3400 |
end if; |
| 3401 |
|
| 3402 |
else |
| 3403 |
Context := Parent (Ptr_Typ); |
| 3404 |
end if; |
| 3405 |
|
| 3406 |
-- Generate: |
| 3407 |
-- <Ptr_Typ>M : Master_Id renames _Master; |
| 3408 |
-- and add a numeric suffix to the name to ensure that it is |
| 3409 |
-- unique in case other access types in nested constructs |
| 3410 |
-- are homonyms of this one. |
| 3411 |
|
| 3412 |
Master_Id := |
| 3413 |
Make_Defining_Identifier (Loc, |
| 3414 |
New_External_Name (Chars (Ptr_Typ), 'M', -1)); |
| 3415 |
|
| 3416 |
Master_Decl := |
| 3417 |
Make_Object_Renaming_Declaration (Loc, |
| 3418 |
Defining_Identifier => Master_Id, |
| 3419 |
Subtype_Mark => |
| 3420 |
New_Occurrence_Of (Standard_Integer, Loc), |
| 3421 |
Name => Make_Identifier (Loc, Name_uMaster)); |
| 3422 |
|
| 3423 |
Insert_Action (Context, Master_Decl); |
| 3424 |
|
| 3425 |
-- The renamed master now services the access type |
| 3426 |
|
| 3427 |
Set_Master_Id (Ptr_Typ, Master_Id); |
| 3428 |
end Build_Master_Renaming; |
| 3429 |
|
| 3430 |
--------------------------- |
| 3431 |
-- Build_Protected_Entry -- |
| 3432 |
--------------------------- |
| 3433 |
|
| 3434 |
function Build_Protected_Entry |
| 3435 |
(N : Node_Id; |
| 3436 |
Ent : Entity_Id; |
| 3437 |
Pid : Node_Id) return Node_Id |
| 3438 |
is |
| 3439 |
Bod_Decls : constant List_Id := New_List; |
| 3440 |
Decls : constant List_Id := Declarations (N); |
| 3441 |
End_Lab : constant Node_Id := |
| 3442 |
End_Label (Handled_Statement_Sequence (N)); |
| 3443 |
End_Loc : constant Source_Ptr := |
| 3444 |
Sloc (Last (Statements (Handled_Statement_Sequence (N)))); |
| 3445 |
-- Used for the generated call to Complete_Entry_Body |
| 3446 |
|
| 3447 |
Loc : constant Source_Ptr := Sloc (N); |
| 3448 |
|
| 3449 |
Block_Id : Entity_Id; |
| 3450 |
Bod_Id : Entity_Id; |
| 3451 |
Bod_Spec : Node_Id; |
| 3452 |
Bod_Stmts : List_Id; |
| 3453 |
Complete : Node_Id; |
| 3454 |
Ohandle : Node_Id; |
| 3455 |
Proc_Body : Node_Id; |
| 3456 |
|
| 3457 |
EH_Loc : Source_Ptr; |
| 3458 |
-- Used for the exception handler, inserted at end of the body |
| 3459 |
|
| 3460 |
begin |
| 3461 |
-- Set the source location on the exception handler only when debugging |
| 3462 |
-- the expanded code (see Make_Implicit_Exception_Handler). |
| 3463 |
|
| 3464 |
if Debug_Generated_Code then |
| 3465 |
EH_Loc := End_Loc; |
| 3466 |
|
| 3467 |
-- Otherwise the inserted code should not be visible to the debugger |
| 3468 |
|
| 3469 |
else |
| 3470 |
EH_Loc := No_Location; |
| 3471 |
end if; |
| 3472 |
|
| 3473 |
Bod_Id := |
| 3474 |
Make_Defining_Identifier (Loc, |
| 3475 |
Chars => Chars (Protected_Body_Subprogram (Ent))); |
| 3476 |
Bod_Spec := Build_Protected_Entry_Specification (Loc, Bod_Id, Empty); |
| 3477 |
|
| 3478 |
-- Add the following declarations: |
| 3479 |
|
| 3480 |
-- type poVP is access poV; |
| 3481 |
-- _object : poVP := poVP (_O); |
| 3482 |
|
| 3483 |
-- where _O is the formal parameter associated with the concurrent |
| 3484 |
-- object. These declarations are needed for Complete_Entry_Body. |
| 3485 |
|
| 3486 |
Add_Object_Pointer (Loc, Pid, Bod_Decls); |
| 3487 |
|
| 3488 |
-- Add renamings for all formals, the Protection object, discriminals, |
| 3489 |
-- privals and the entry index constant for use by debugger. |
| 3490 |
|
| 3491 |
Add_Formal_Renamings (Bod_Spec, Bod_Decls, Ent, Loc); |
| 3492 |
Debug_Private_Data_Declarations (Decls); |
| 3493 |
|
| 3494 |
-- Put the declarations and the statements from the entry |
| 3495 |
|
| 3496 |
Bod_Stmts := |
| 3497 |
New_List ( |
| 3498 |
Make_Block_Statement (Loc, |
| 3499 |
Declarations => Decls, |
| 3500 |
Handled_Statement_Sequence => Handled_Statement_Sequence (N))); |
| 3501 |
|
| 3502 |
-- Analyze now and reset scopes for declarations so that Scope fields |
| 3503 |
-- currently denoting the entry will now denote the block scope, and |
| 3504 |
-- the block's scope will be set to the new procedure entity. |
| 3505 |
|
| 3506 |
Analyze_Statements (Bod_Stmts); |
| 3507 |
|
| 3508 |
Block_Id := Entity (Identifier (First (Bod_Stmts))); |
| 3509 |
|
| 3510 |
Set_Scope (Block_Id, Protected_Body_Subprogram (Ent)); |
| 3511 |
Set_Uses_Sec_Stack (Block_Id, Uses_Sec_Stack (Corresponding_Spec (N))); |
| 3512 |
|
| 3513 |
Reset_Scopes_To (First (Bod_Stmts), Block_Id); |
| 3514 |
Set_At_End_Proc (First (Bod_Stmts), At_End_Proc (N)); |
| 3515 |
|
| 3516 |
case Corresponding_Runtime_Package (Pid) is |
| 3517 |
when System_Tasking_Protected_Objects_Entries => |
| 3518 |
Append_To (Bod_Stmts, |
| 3519 |
Make_Procedure_Call_Statement (End_Loc, |
| 3520 |
Name => |
| 3521 |
New_Occurrence_Of (RTE (RE_Complete_Entry_Body), Loc), |
| 3522 |
Parameter_Associations => New_List ( |
| 3523 |
Make_Attribute_Reference (End_Loc, |
| 3524 |
Prefix => |
| 3525 |
Make_Selected_Component (End_Loc, |
| 3526 |
Prefix => |
| 3527 |
Make_Identifier (End_Loc, Name_uObject), |
| 3528 |
Selector_Name => |
| 3529 |
Make_Identifier (End_Loc, Name_uObject)), |
| 3530 |
Attribute_Name => Name_Unchecked_Access)))); |
| 3531 |
|
| 3532 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 3533 |
|
| 3534 |
-- Historically, a call to Complete_Single_Entry_Body was |
| 3535 |
-- inserted, but it was a null procedure. |
| 3536 |
|
| 3537 |
null; |
| 3538 |
|
| 3539 |
when others => |
| 3540 |
raise Program_Error; |
| 3541 |
end case; |
| 3542 |
|
| 3543 |
-- When exceptions cannot be propagated, we never need to call |
| 3544 |
-- Exception_Complete_Entry_Body. |
| 3545 |
|
| 3546 |
if No_Exception_Handlers_Set then |
| 3547 |
return |
| 3548 |
Make_Subprogram_Body (Loc, |
| 3549 |
Specification => Bod_Spec, |
| 3550 |
Declarations => Bod_Decls, |
| 3551 |
Handled_Statement_Sequence => |
| 3552 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 3553 |
Statements => Bod_Stmts, |
| 3554 |
End_Label => End_Lab)); |
| 3555 |
|
| 3556 |
else |
| 3557 |
Ohandle := Make_Others_Choice (Loc); |
| 3558 |
Set_All_Others (Ohandle); |
| 3559 |
|
| 3560 |
case Corresponding_Runtime_Package (Pid) is |
| 3561 |
when System_Tasking_Protected_Objects_Entries => |
| 3562 |
Complete := |
| 3563 |
New_Occurrence_Of |
| 3564 |
(RTE (RE_Exceptional_Complete_Entry_Body), Loc); |
| 3565 |
|
| 3566 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 3567 |
Complete := |
| 3568 |
New_Occurrence_Of |
| 3569 |
(RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc); |
| 3570 |
|
| 3571 |
when others => |
| 3572 |
raise Program_Error; |
| 3573 |
end case; |
| 3574 |
|
| 3575 |
-- Create body of entry procedure. The renaming declarations are |
| 3576 |
-- placed ahead of the block that contains the actual entry body. |
| 3577 |
|
| 3578 |
Proc_Body := |
| 3579 |
Make_Subprogram_Body (Loc, |
| 3580 |
Specification => Bod_Spec, |
| 3581 |
Declarations => Bod_Decls, |
| 3582 |
Handled_Statement_Sequence => |
| 3583 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 3584 |
Statements => Bod_Stmts, |
| 3585 |
End_Label => End_Lab, |
| 3586 |
Exception_Handlers => New_List ( |
| 3587 |
Make_Implicit_Exception_Handler (EH_Loc, |
| 3588 |
Exception_Choices => New_List (Ohandle), |
| 3589 |
|
| 3590 |
Statements => New_List ( |
| 3591 |
Make_Procedure_Call_Statement (EH_Loc, |
| 3592 |
Name => Complete, |
| 3593 |
Parameter_Associations => New_List ( |
| 3594 |
Make_Attribute_Reference (EH_Loc, |
| 3595 |
Prefix => |
| 3596 |
Make_Selected_Component (EH_Loc, |
| 3597 |
Prefix => |
| 3598 |
Make_Identifier (EH_Loc, Name_uObject), |
| 3599 |
Selector_Name => |
| 3600 |
Make_Identifier (EH_Loc, Name_uObject)), |
| 3601 |
Attribute_Name => Name_Unchecked_Access), |
| 3602 |
|
| 3603 |
Make_Function_Call (EH_Loc, |
| 3604 |
Name => |
| 3605 |
New_Occurrence_Of |
| 3606 |
(RTE (RE_Get_GNAT_Exception), Loc))))))))); |
| 3607 |
|
| 3608 |
-- Establish link between subprogram body and source entry body |
| 3609 |
|
| 3610 |
Set_Corresponding_Entry_Body (Proc_Body, N); |
| 3611 |
|
| 3612 |
Reset_Scopes_To (Proc_Body, Protected_Body_Subprogram (Ent)); |
| 3613 |
return Proc_Body; |
| 3614 |
end if; |
| 3615 |
end Build_Protected_Entry; |
| 3616 |
|
| 3617 |
----------------------------------------- |
| 3618 |
-- Build_Protected_Entry_Specification -- |
| 3619 |
----------------------------------------- |
| 3620 |
|
| 3621 |
function Build_Protected_Entry_Specification |
| 3622 |
(Loc : Source_Ptr; |
| 3623 |
Def_Id : Entity_Id; |
| 3624 |
Ent_Id : Entity_Id) return Node_Id |
| 3625 |
is |
| 3626 |
P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP); |
| 3627 |
|
| 3628 |
begin |
| 3629 |
Set_Debug_Info_Needed (Def_Id); |
| 3630 |
|
| 3631 |
if Present (Ent_Id) then |
| 3632 |
Append_Elmt (P, Accept_Address (Ent_Id)); |
| 3633 |
end if; |
| 3634 |
|
| 3635 |
return |
| 3636 |
Make_Procedure_Specification (Loc, |
| 3637 |
Defining_Unit_Name => Def_Id, |
| 3638 |
Parameter_Specifications => New_List ( |
| 3639 |
Make_Parameter_Specification (Loc, |
| 3640 |
Defining_Identifier => |
| 3641 |
Make_Defining_Identifier (Loc, Name_uO), |
| 3642 |
Parameter_Type => |
| 3643 |
New_Occurrence_Of (RTE (RE_Address), Loc)), |
| 3644 |
|
| 3645 |
Make_Parameter_Specification (Loc, |
| 3646 |
Defining_Identifier => P, |
| 3647 |
Parameter_Type => |
| 3648 |
New_Occurrence_Of (RTE (RE_Address), Loc)), |
| 3649 |
|
| 3650 |
Make_Parameter_Specification (Loc, |
| 3651 |
Defining_Identifier => |
| 3652 |
Make_Defining_Identifier (Loc, Name_uE), |
| 3653 |
Parameter_Type => |
| 3654 |
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc)))); |
| 3655 |
end Build_Protected_Entry_Specification; |
| 3656 |
|
| 3657 |
-------------------------- |
| 3658 |
-- Build_Protected_Spec -- |
| 3659 |
-------------------------- |
| 3660 |
|
| 3661 |
function Build_Protected_Spec |
| 3662 |
(N : Node_Id; |
| 3663 |
Obj_Type : Entity_Id; |
| 3664 |
Ident : Entity_Id; |
| 3665 |
Unprotected : Boolean := False) return List_Id |
| 3666 |
is |
| 3667 |
Loc : constant Source_Ptr := Sloc (N); |
| 3668 |
|
| 3669 |
Decl : Node_Id; |
| 3670 |
Formal : Entity_Id; |
| 3671 |
New_Formal : Entity_Id; |
| 3672 |
New_Plist : List_Id; |
| 3673 |
|
| 3674 |
begin |
| 3675 |
New_Plist := New_List; |
| 3676 |
|
| 3677 |
Formal := First_Formal (Ident); |
| 3678 |
while Present (Formal) loop |
| 3679 |
New_Formal := |
| 3680 |
Make_Defining_Identifier (Sloc (Formal), Chars (Formal)); |
| 3681 |
Set_Comes_From_Source (New_Formal, Comes_From_Source (Formal)); |
| 3682 |
|
| 3683 |
if Unprotected then |
| 3684 |
Mutate_Ekind (New_Formal, Ekind (Formal)); |
| 3685 |
Set_Protected_Formal (Formal, New_Formal); |
| 3686 |
end if; |
| 3687 |
|
| 3688 |
Append_To (New_Plist, |
| 3689 |
Make_Parameter_Specification (Loc, |
| 3690 |
Defining_Identifier => New_Formal, |
| 3691 |
Aliased_Present => Aliased_Present (Parent (Formal)), |
| 3692 |
In_Present => In_Present (Parent (Formal)), |
| 3693 |
Out_Present => Out_Present (Parent (Formal)), |
| 3694 |
Parameter_Type => New_Occurrence_Of (Etype (Formal), Loc))); |
| 3695 |
|
| 3696 |
Next_Formal (Formal); |
| 3697 |
end loop; |
| 3698 |
|
| 3699 |
-- If the subprogram is a procedure and the context is not an access |
| 3700 |
-- to protected subprogram, the parameter is in-out. Otherwise it is |
| 3701 |
-- an in parameter. |
| 3702 |
|
| 3703 |
Decl := |
| 3704 |
Make_Parameter_Specification (Loc, |
| 3705 |
Defining_Identifier => |
| 3706 |
Make_Defining_Identifier (Loc, Name_uObject), |
| 3707 |
In_Present => True, |
| 3708 |
Out_Present => |
| 3709 |
(Etype (Ident) = Standard_Void_Type |
| 3710 |
and then not Is_RTE (Obj_Type, RE_Address)), |
| 3711 |
Parameter_Type => |
| 3712 |
New_Occurrence_Of (Obj_Type, Loc)); |
| 3713 |
Set_Debug_Info_Needed (Defining_Identifier (Decl)); |
| 3714 |
Prepend_To (New_Plist, Decl); |
| 3715 |
|
| 3716 |
return New_Plist; |
| 3717 |
end Build_Protected_Spec; |
| 3718 |
|
| 3719 |
--------------------------------------- |
| 3720 |
-- Build_Protected_Sub_Specification -- |
| 3721 |
--------------------------------------- |
| 3722 |
|
| 3723 |
function Build_Protected_Sub_Specification |
| 3724 |
(N : Node_Id; |
| 3725 |
Prot_Typ : Entity_Id; |
| 3726 |
Mode : Subprogram_Protection_Mode) return Node_Id |
| 3727 |
is |
| 3728 |
Loc : constant Source_Ptr := Sloc (N); |
| 3729 |
Decl : Node_Id; |
| 3730 |
Def_Id : Entity_Id; |
| 3731 |
New_Id : Entity_Id; |
| 3732 |
New_Plist : List_Id; |
| 3733 |
New_Spec : Node_Id; |
| 3734 |
|
| 3735 |
Append_Chr : constant array (Subprogram_Protection_Mode) of Character := |
| 3736 |
(Dispatching_Mode => ' ', |
| 3737 |
Protected_Mode => 'P', |
| 3738 |
Unprotected_Mode => 'N'); |
| 3739 |
|
| 3740 |
begin |
| 3741 |
if Ekind (Defining_Unit_Name (Specification (N))) = E_Subprogram_Body |
| 3742 |
then |
| 3743 |
Decl := Unit_Declaration_Node (Corresponding_Spec (N)); |
| 3744 |
else |
| 3745 |
Decl := N; |
| 3746 |
end if; |
| 3747 |
|
| 3748 |
Def_Id := Defining_Unit_Name (Specification (Decl)); |
| 3749 |
|
| 3750 |
New_Plist := |
| 3751 |
Build_Protected_Spec |
| 3752 |
(Decl, Corresponding_Record_Type (Prot_Typ), Def_Id, |
| 3753 |
Mode = Unprotected_Mode); |
| 3754 |
New_Id := |
| 3755 |
Make_Defining_Identifier (Loc, |
| 3756 |
Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode))); |
| 3757 |
|
| 3758 |
-- Reference the original nondispatching subprogram since the analysis |
| 3759 |
-- of the object.operation notation may need its original name (see |
| 3760 |
-- Sem_Ch4.Names_Match). |
| 3761 |
|
| 3762 |
if Mode = Dispatching_Mode then |
| 3763 |
Mutate_Ekind (New_Id, Ekind (Def_Id)); |
| 3764 |
Set_Original_Protected_Subprogram (New_Id, Def_Id); |
| 3765 |
end if; |
| 3766 |
|
| 3767 |
-- Link the protected or unprotected version to the original subprogram |
| 3768 |
-- it emulates. |
| 3769 |
|
| 3770 |
Mutate_Ekind (New_Id, Ekind (Def_Id)); |
| 3771 |
Set_Protected_Subprogram (New_Id, Def_Id); |
| 3772 |
|
| 3773 |
-- The unprotected operation carries the user code, and debugging |
| 3774 |
-- information must be generated for it, even though this spec does |
| 3775 |
-- not come from source. It is also convenient to allow gdb to step |
| 3776 |
-- into the protected operation, even though it only contains lock/ |
| 3777 |
-- unlock calls. |
| 3778 |
|
| 3779 |
Set_Debug_Info_Needed (New_Id); |
| 3780 |
|
| 3781 |
-- If a pragma Eliminate applies to the source entity, the internal |
| 3782 |
-- subprograms will be eliminated as well. |
| 3783 |
|
| 3784 |
Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id)); |
| 3785 |
|
| 3786 |
-- It seems we should set Has_Nested_Subprogram here, but instead we |
| 3787 |
-- currently set it in Expand_N_Protected_Body, because the entity |
| 3788 |
-- created here isn't the one that Corresponding_Spec of the body |
| 3789 |
-- will later be set to, and that's the entity where it's needed. ??? |
| 3790 |
|
| 3791 |
Set_Has_Nested_Subprogram (New_Id, Has_Nested_Subprogram (Def_Id)); |
| 3792 |
|
| 3793 |
if Nkind (Specification (Decl)) = N_Procedure_Specification then |
| 3794 |
New_Spec := |
| 3795 |
Make_Procedure_Specification (Loc, |
| 3796 |
Defining_Unit_Name => New_Id, |
| 3797 |
Parameter_Specifications => New_Plist); |
| 3798 |
|
| 3799 |
-- Create a new specification for the anonymous subprogram type |
| 3800 |
|
| 3801 |
else |
| 3802 |
New_Spec := |
| 3803 |
Make_Function_Specification (Loc, |
| 3804 |
Defining_Unit_Name => New_Id, |
| 3805 |
Parameter_Specifications => New_Plist, |
| 3806 |
Result_Definition => |
| 3807 |
Copy_Result_Type (Result_Definition (Specification (Decl)))); |
| 3808 |
|
| 3809 |
Set_Return_Present (Defining_Unit_Name (New_Spec)); |
| 3810 |
end if; |
| 3811 |
|
| 3812 |
return New_Spec; |
| 3813 |
end Build_Protected_Sub_Specification; |
| 3814 |
|
| 3815 |
------------------------------------- |
| 3816 |
-- Build_Protected_Subprogram_Body -- |
| 3817 |
------------------------------------- |
| 3818 |
|
| 3819 |
function Build_Protected_Subprogram_Body |
| 3820 |
(N : Node_Id; |
| 3821 |
Pid : Node_Id; |
| 3822 |
N_Op_Spec : Node_Id) return Node_Id |
| 3823 |
is |
| 3824 |
Might_Raise : constant Boolean := Sem_Util.Might_Raise (N); |
| 3825 |
|
| 3826 |
Loc : constant Source_Ptr := Sloc (N); |
| 3827 |
Op_Spec : constant Node_Id := Specification (N); |
| 3828 |
P_Op_Spec : constant Node_Id := |
| 3829 |
Build_Protected_Sub_Specification (N, Pid, Protected_Mode); |
| 3830 |
|
| 3831 |
Lock_Kind : RE_Id; |
| 3832 |
Lock_Name : Node_Id; |
| 3833 |
Lock_Stmt : Node_Id; |
| 3834 |
Object_Parm : Node_Id; |
| 3835 |
Pformal : Node_Id; |
| 3836 |
R : Node_Id; |
| 3837 |
Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning |
| 3838 |
Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning |
| 3839 |
Stmts : List_Id; |
| 3840 |
Sub_Body : Node_Id; |
| 3841 |
Uactuals : List_Id; |
| 3842 |
Unprot_Call : Node_Id; |
| 3843 |
|
| 3844 |
begin |
| 3845 |
-- Build a list of the formal parameters of the protected version of |
| 3846 |
-- the subprogram to use as the actual parameters of the unprotected |
| 3847 |
-- version. |
| 3848 |
|
| 3849 |
Uactuals := New_List; |
| 3850 |
Pformal := First (Parameter_Specifications (P_Op_Spec)); |
| 3851 |
while Present (Pformal) loop |
| 3852 |
Append_To (Uactuals, |
| 3853 |
Make_Identifier (Loc, Chars (Defining_Identifier (Pformal)))); |
| 3854 |
Next (Pformal); |
| 3855 |
end loop; |
| 3856 |
|
| 3857 |
-- Make a call to the unprotected version of the subprogram built above |
| 3858 |
-- for use by the protected version built below. |
| 3859 |
|
| 3860 |
if Nkind (Op_Spec) = N_Function_Specification then |
| 3861 |
if Might_Raise then |
| 3862 |
Unprot_Call := |
| 3863 |
Make_Simple_Return_Statement (Loc, |
| 3864 |
Expression => |
| 3865 |
Make_Function_Call (Loc, |
| 3866 |
Name => |
| 3867 |
Make_Identifier (Loc, |
| 3868 |
Chars => Chars (Defining_Unit_Name (N_Op_Spec))), |
| 3869 |
Parameter_Associations => Uactuals)); |
| 3870 |
|
| 3871 |
else |
| 3872 |
R := Make_Temporary (Loc, 'R'); |
| 3873 |
|
| 3874 |
Unprot_Call := |
| 3875 |
Make_Object_Declaration (Loc, |
| 3876 |
Defining_Identifier => R, |
| 3877 |
Constant_Present => True, |
| 3878 |
Object_Definition => |
| 3879 |
New_Copy (Result_Definition (N_Op_Spec)), |
| 3880 |
Expression => |
| 3881 |
Make_Function_Call (Loc, |
| 3882 |
Name => |
| 3883 |
Make_Identifier (Loc, |
| 3884 |
Chars => Chars (Defining_Unit_Name (N_Op_Spec))), |
| 3885 |
Parameter_Associations => Uactuals)); |
| 3886 |
|
| 3887 |
Return_Stmt := |
| 3888 |
Make_Simple_Return_Statement (Loc, |
| 3889 |
Expression => New_Occurrence_Of (R, Loc)); |
| 3890 |
end if; |
| 3891 |
|
| 3892 |
if Has_Enabled_Aspect (Pid, Aspect_Exclusive_Functions) then |
| 3893 |
Lock_Kind := RE_Lock; |
| 3894 |
else |
| 3895 |
Lock_Kind := RE_Lock_Read_Only; |
| 3896 |
end if; |
| 3897 |
else |
| 3898 |
Unprot_Call := |
| 3899 |
Make_Procedure_Call_Statement (Loc, |
| 3900 |
Name => |
| 3901 |
Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))), |
| 3902 |
Parameter_Associations => Uactuals); |
| 3903 |
|
| 3904 |
Lock_Kind := RE_Lock; |
| 3905 |
end if; |
| 3906 |
|
| 3907 |
-- Make the protected subprogram body. This locks the protected |
| 3908 |
-- object and calls the unprotected version of the subprogram. |
| 3909 |
|
| 3910 |
case Corresponding_Runtime_Package (Pid) is |
| 3911 |
when System_Tasking_Protected_Objects_Entries => |
| 3912 |
Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entries), Loc); |
| 3913 |
|
| 3914 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 3915 |
Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entry), Loc); |
| 3916 |
|
| 3917 |
when System_Tasking_Protected_Objects => |
| 3918 |
Lock_Name := New_Occurrence_Of (RTE (Lock_Kind), Loc); |
| 3919 |
|
| 3920 |
when others => |
| 3921 |
raise Program_Error; |
| 3922 |
end case; |
| 3923 |
|
| 3924 |
Object_Parm := |
| 3925 |
Make_Attribute_Reference (Loc, |
| 3926 |
Prefix => |
| 3927 |
Make_Selected_Component (Loc, |
| 3928 |
Prefix => Make_Identifier (Loc, Name_uObject), |
| 3929 |
Selector_Name => Make_Identifier (Loc, Name_uObject)), |
| 3930 |
Attribute_Name => Name_Unchecked_Access); |
| 3931 |
|
| 3932 |
Lock_Stmt := |
| 3933 |
Make_Procedure_Call_Statement (Loc, |
| 3934 |
Name => Lock_Name, |
| 3935 |
Parameter_Associations => New_List (Object_Parm)); |
| 3936 |
|
| 3937 |
Stmts := (if Abort_Allowed then |
| 3938 |
New_List (Build_Runtime_Call (Loc, RE_Abort_Defer)) |
| 3939 |
else |
| 3940 |
New_List); |
| 3941 |
|
| 3942 |
if Might_Raise then |
| 3943 |
Unprot_Call := Wrap_Unprotected_Call |
| 3944 |
(Unprot_Call, Pid, Op_Spec, Loc); |
| 3945 |
|
| 3946 |
Unprot_Call := |
| 3947 |
Make_Block_Statement (Loc, |
| 3948 |
Handled_Statement_Sequence => |
| 3949 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 3950 |
Statements => New_List (Lock_Stmt, Unprot_Call))); |
| 3951 |
|
| 3952 |
Append (Unprot_Call, Stmts); |
| 3953 |
else |
| 3954 |
Append (Lock_Stmt, Stmts); |
| 3955 |
if Nkind (Op_Spec) = N_Function_Specification then |
| 3956 |
Pre_Stmts := Stmts; |
| 3957 |
Stmts := Empty_List; |
| 3958 |
else |
| 3959 |
Append (Unprot_Call, Stmts); |
| 3960 |
end if; |
| 3961 |
|
| 3962 |
Build_Protected_Subprogram_Call_Cleanup (Op_Spec, Pid, Loc, Stmts); |
| 3963 |
|
| 3964 |
if Nkind (Op_Spec) = N_Function_Specification then |
| 3965 |
Append_To (Stmts, Return_Stmt); |
| 3966 |
Append_To (Pre_Stmts, |
| 3967 |
Make_Block_Statement (Loc, |
| 3968 |
Declarations => New_List (Unprot_Call), |
| 3969 |
Handled_Statement_Sequence => |
| 3970 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 3971 |
Statements => Stmts))); |
| 3972 |
Stmts := Pre_Stmts; |
| 3973 |
end if; |
| 3974 |
end if; |
| 3975 |
|
| 3976 |
Sub_Body := |
| 3977 |
Make_Subprogram_Body (Loc, |
| 3978 |
Declarations => Empty_List, |
| 3979 |
Specification => P_Op_Spec, |
| 3980 |
Handled_Statement_Sequence => |
| 3981 |
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts)); |
| 3982 |
|
| 3983 |
-- Mark this subprogram as a protected subprogram body so that the |
| 3984 |
-- cleanup will be inserted. This is done only in the Might_Raise |
| 3985 |
-- case because otherwise the cleanup has already been inserted. |
| 3986 |
|
| 3987 |
if Might_Raise then |
| 3988 |
Set_Is_Protected_Subprogram_Body (Sub_Body); |
| 3989 |
end if; |
| 3990 |
|
| 3991 |
return Sub_Body; |
| 3992 |
end Build_Protected_Subprogram_Body; |
| 3993 |
|
| 3994 |
------------------------------------- |
| 3995 |
-- Build_Protected_Subprogram_Call -- |
| 3996 |
------------------------------------- |
| 3997 |
|
| 3998 |
procedure Build_Protected_Subprogram_Call |
| 3999 |
(N : Node_Id; |
| 4000 |
Name : Node_Id; |
| 4001 |
Rec : Node_Id; |
| 4002 |
External : Boolean := True) |
| 4003 |
is |
| 4004 |
Loc : constant Source_Ptr := Sloc (N); |
| 4005 |
Sub : constant Entity_Id := Entity (Name); |
| 4006 |
New_Sub : Node_Id; |
| 4007 |
Params : List_Id; |
| 4008 |
|
| 4009 |
begin |
| 4010 |
if External then |
| 4011 |
New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc); |
| 4012 |
else |
| 4013 |
New_Sub := |
| 4014 |
New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc); |
| 4015 |
end if; |
| 4016 |
|
| 4017 |
if Present (Parameter_Associations (N)) then |
| 4018 |
Params := New_Copy_List_Tree (Parameter_Associations (N)); |
| 4019 |
else |
| 4020 |
Params := New_List; |
| 4021 |
end if; |
| 4022 |
|
| 4023 |
-- If the type is an untagged derived type, convert to the root type, |
| 4024 |
-- which is the one on which the operations are defined. |
| 4025 |
|
| 4026 |
if Nkind (Rec) = N_Unchecked_Type_Conversion |
| 4027 |
and then not Is_Tagged_Type (Etype (Rec)) |
| 4028 |
and then Is_Derived_Type (Etype (Rec)) |
| 4029 |
then |
| 4030 |
Set_Etype (Rec, Root_Type (Etype (Rec))); |
| 4031 |
Set_Subtype_Mark (Rec, |
| 4032 |
New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N))); |
| 4033 |
end if; |
| 4034 |
|
| 4035 |
Prepend (Rec, Params); |
| 4036 |
|
| 4037 |
if Ekind (Sub) = E_Procedure then |
| 4038 |
Rewrite (N, |
| 4039 |
Make_Procedure_Call_Statement (Loc, |
| 4040 |
Name => New_Sub, |
| 4041 |
Parameter_Associations => Params)); |
| 4042 |
|
| 4043 |
else |
| 4044 |
pragma Assert (Ekind (Sub) = E_Function); |
| 4045 |
Rewrite (N, |
| 4046 |
Make_Function_Call (Loc, |
| 4047 |
Name => New_Sub, |
| 4048 |
Parameter_Associations => Params)); |
| 4049 |
|
| 4050 |
-- Preserve type of call for subsequent processing (required for |
| 4051 |
-- call to Wrap_Transient_Expression in the case of a shared passive |
| 4052 |
-- protected). |
| 4053 |
|
| 4054 |
Set_Etype (N, Etype (New_Sub)); |
| 4055 |
end if; |
| 4056 |
|
| 4057 |
if External |
| 4058 |
and then Nkind (Rec) = N_Unchecked_Type_Conversion |
| 4059 |
and then Is_Entity_Name (Expression (Rec)) |
| 4060 |
and then Is_Shared_Passive (Entity (Expression (Rec))) |
| 4061 |
then |
| 4062 |
Add_Shared_Var_Lock_Procs (N); |
| 4063 |
end if; |
| 4064 |
end Build_Protected_Subprogram_Call; |
| 4065 |
|
| 4066 |
--------------------------------------------- |
| 4067 |
-- Build_Protected_Subprogram_Call_Cleanup -- |
| 4068 |
--------------------------------------------- |
| 4069 |
|
| 4070 |
procedure Build_Protected_Subprogram_Call_Cleanup |
| 4071 |
(Op_Spec : Node_Id; |
| 4072 |
Conc_Typ : Node_Id; |
| 4073 |
Loc : Source_Ptr; |
| 4074 |
Stmts : List_Id) |
| 4075 |
is |
| 4076 |
Unlock_Stmt : constant N_Procedure_Call_Statement_Id := |
| 4077 |
Make_Unlock_Statement (Conc_Typ, Op_Spec, Loc); |
| 4078 |
begin |
| 4079 |
Append_To (Stmts, Unlock_Stmt); |
| 4080 |
|
| 4081 |
-- Generate: |
| 4082 |
-- Abort_Undefer; |
| 4083 |
|
| 4084 |
if Abort_Allowed then |
| 4085 |
Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer)); |
| 4086 |
end if; |
| 4087 |
end Build_Protected_Subprogram_Call_Cleanup; |
| 4088 |
|
| 4089 |
------------------------- |
| 4090 |
-- Build_Selected_Name -- |
| 4091 |
------------------------- |
| 4092 |
|
| 4093 |
function Build_Selected_Name |
| 4094 |
(Prefix : Entity_Id; |
| 4095 |
Selector : Entity_Id; |
| 4096 |
Append_Char : Character := ' ') return Name_Id |
| 4097 |
is |
| 4098 |
Select_Buffer : String (1 .. Hostparm.Max_Name_Length); |
| 4099 |
Select_Len : Natural; |
| 4100 |
|
| 4101 |
begin |
| 4102 |
Get_Name_String (Chars (Selector)); |
| 4103 |
Select_Len := Name_Len; |
| 4104 |
Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len); |
| 4105 |
Get_Name_String (Chars (Prefix)); |
| 4106 |
|
| 4107 |
-- If scope is anonymous type, discard suffix to recover name of |
| 4108 |
-- single protected object. Otherwise use protected type name. |
| 4109 |
|
| 4110 |
if Name_Buffer (Name_Len) = 'T' then |
| 4111 |
Name_Len := Name_Len - 1; |
| 4112 |
end if; |
| 4113 |
|
| 4114 |
Add_Str_To_Name_Buffer ("__"); |
| 4115 |
for J in 1 .. Select_Len loop |
| 4116 |
Add_Char_To_Name_Buffer (Select_Buffer (J)); |
| 4117 |
end loop; |
| 4118 |
|
| 4119 |
-- Now add the Append_Char if specified. The encoding to follow |
| 4120 |
-- depends on the type of entity. If Append_Char is either 'N' or 'P', |
| 4121 |
-- then the entity is associated to a protected type subprogram. |
| 4122 |
-- Otherwise, it is a protected type entry. For each case, the |
| 4123 |
-- encoding to follow for the suffix is documented in exp_dbug.ads. |
| 4124 |
|
| 4125 |
-- It would be better to encapsulate this as a routine in Exp_Dbug ??? |
| 4126 |
|
| 4127 |
if Append_Char /= ' ' then |
| 4128 |
if Append_Char in 'P' | 'N' then |
| 4129 |
Add_Char_To_Name_Buffer (Append_Char); |
| 4130 |
return Name_Find; |
| 4131 |
else |
| 4132 |
Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char)); |
| 4133 |
return New_External_Name (Name_Find, ' ', -1); |
| 4134 |
end if; |
| 4135 |
else |
| 4136 |
return Name_Find; |
| 4137 |
end if; |
| 4138 |
end Build_Selected_Name; |
| 4139 |
|
| 4140 |
----------------------------- |
| 4141 |
-- Build_Simple_Entry_Call -- |
| 4142 |
----------------------------- |
| 4143 |
|
| 4144 |
-- A task entry call is converted to a call to Call_Simple |
| 4145 |
|
| 4146 |
-- declare |
| 4147 |
-- P : parms := (parm, parm, parm); |
| 4148 |
-- begin |
| 4149 |
-- Call_Simple (acceptor-task, entry-index, P'Address); |
| 4150 |
-- parm := P.param; |
| 4151 |
-- parm := P.param; |
| 4152 |
-- ... |
| 4153 |
-- end; |
| 4154 |
|
| 4155 |
-- Here Pnn is an aggregate of the type constructed for the entry to hold |
| 4156 |
-- the parameters, and the constructed aggregate value contains either the |
| 4157 |
-- parameters or, in the case of non-elementary types, references to these |
| 4158 |
-- parameters. Then the address of this aggregate is passed to the runtime |
| 4159 |
-- routine, along with the task id value and the task entry index value. |
| 4160 |
-- Pnn is only required if parameters are present. |
| 4161 |
|
| 4162 |
-- The assignments after the call are present only in the case of in-out |
| 4163 |
-- or out parameters for elementary types, and are used to assign back the |
| 4164 |
-- resulting values of such parameters. |
| 4165 |
|
| 4166 |
-- Note: the reason that we insert a block here is that in the context |
| 4167 |
-- of selects, conditional entry calls etc. the entry call statement |
| 4168 |
-- appears on its own, not as an element of a list. |
| 4169 |
|
| 4170 |
-- A protected entry call is converted to a Protected_Entry_Call: |
| 4171 |
|
| 4172 |
-- declare |
| 4173 |
-- P : E1_Params := (param, param, param); |
| 4174 |
-- Pnn : Boolean; |
| 4175 |
-- Bnn : Communications_Block; |
| 4176 |
|
| 4177 |
-- declare |
| 4178 |
-- P : E1_Params := (param, param, param); |
| 4179 |
-- Bnn : Communications_Block; |
| 4180 |
|
| 4181 |
-- begin |
| 4182 |
-- Protected_Entry_Call ( |
| 4183 |
-- Object => po._object'Access, |
| 4184 |
-- E => <entry index>; |
| 4185 |
-- Uninterpreted_Data => P'Address; |
| 4186 |
-- Mode => Simple_Call; |
| 4187 |
-- Block => Bnn); |
| 4188 |
-- parm := P.param; |
| 4189 |
-- parm := P.param; |
| 4190 |
-- ... |
| 4191 |
-- end; |
| 4192 |
|
| 4193 |
procedure Build_Simple_Entry_Call |
| 4194 |
(N : Node_Id; |
| 4195 |
Concval : Node_Id; |
| 4196 |
Ename : Node_Id; |
| 4197 |
Index : Node_Id) |
| 4198 |
is |
| 4199 |
begin |
| 4200 |
Expand_Call (N); |
| 4201 |
|
| 4202 |
-- If call has been inlined, nothing left to do |
| 4203 |
|
| 4204 |
if Nkind (N) = N_Block_Statement then |
| 4205 |
return; |
| 4206 |
end if; |
| 4207 |
|
| 4208 |
-- Convert entry call to Call_Simple call |
| 4209 |
|
| 4210 |
declare |
| 4211 |
Loc : constant Source_Ptr := Sloc (N); |
| 4212 |
Parms : constant List_Id := Parameter_Associations (N); |
| 4213 |
Stats : constant List_Id := New_List; |
| 4214 |
Actual : Node_Id; |
| 4215 |
Call : Node_Id; |
| 4216 |
Comm_Name : Entity_Id; |
| 4217 |
Conctyp : Node_Id; |
| 4218 |
Decls : List_Id; |
| 4219 |
Ent : Entity_Id; |
| 4220 |
Ent_Acc : Entity_Id; |
| 4221 |
Formal : Node_Id; |
| 4222 |
Iface_Tag : Entity_Id; |
| 4223 |
Iface_Typ : Entity_Id; |
| 4224 |
N_Node : Node_Id; |
| 4225 |
N_Var : Node_Id; |
| 4226 |
P : Entity_Id; |
| 4227 |
Parm1 : Node_Id; |
| 4228 |
Parm2 : Node_Id; |
| 4229 |
Parm3 : Node_Id; |
| 4230 |
Pdecl : Node_Id; |
| 4231 |
Plist : List_Id; |
| 4232 |
X : Entity_Id; |
| 4233 |
Xdecl : Node_Id; |
| 4234 |
|
| 4235 |
begin |
| 4236 |
-- Simple entry and entry family cases merge here |
| 4237 |
|
| 4238 |
Ent := Entity (Ename); |
| 4239 |
Ent_Acc := Entry_Parameters_Type (Ent); |
| 4240 |
Conctyp := Etype (Concval); |
| 4241 |
|
| 4242 |
-- Special case for protected subprogram calls |
| 4243 |
|
| 4244 |
if Is_Protected_Type (Conctyp) |
| 4245 |
and then Is_Subprogram (Entity (Ename)) |
| 4246 |
then |
| 4247 |
if not Is_Eliminated (Entity (Ename)) then |
| 4248 |
Build_Protected_Subprogram_Call |
| 4249 |
(N, Ename, Convert_Concurrent (Concval, Conctyp)); |
| 4250 |
Analyze (N); |
| 4251 |
end if; |
| 4252 |
|
| 4253 |
return; |
| 4254 |
end if; |
| 4255 |
|
| 4256 |
-- First parameter is the Task_Id value from the task value or the |
| 4257 |
-- Object from the protected object value, obtained by selecting |
| 4258 |
-- the _Task_Id or _Object from the result of doing an unchecked |
| 4259 |
-- conversion to convert the value to the corresponding record type. |
| 4260 |
|
| 4261 |
if Nkind (Concval) = N_Function_Call |
| 4262 |
and then Is_Task_Type (Conctyp) |
| 4263 |
and then Ada_Version >= Ada_2005 |
| 4264 |
then |
| 4265 |
declare |
| 4266 |
ExpR : constant Node_Id := Relocate_Node (Concval); |
| 4267 |
Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR); |
| 4268 |
Decl : Node_Id; |
| 4269 |
|
| 4270 |
begin |
| 4271 |
Decl := |
| 4272 |
Make_Object_Declaration (Loc, |
| 4273 |
Defining_Identifier => Obj, |
| 4274 |
Object_Definition => New_Occurrence_Of (Conctyp, Loc), |
| 4275 |
Expression => ExpR); |
| 4276 |
Set_Etype (Obj, Conctyp); |
| 4277 |
Decls := New_List (Decl); |
| 4278 |
Rewrite (Concval, New_Occurrence_Of (Obj, Loc)); |
| 4279 |
end; |
| 4280 |
|
| 4281 |
else |
| 4282 |
Decls := New_List; |
| 4283 |
end if; |
| 4284 |
|
| 4285 |
Parm1 := Concurrent_Ref (Concval); |
| 4286 |
|
| 4287 |
-- Second parameter is the entry index, computed by the routine |
| 4288 |
-- provided for this purpose. The value of this expression is |
| 4289 |
-- assigned to an intermediate variable to assure that any entry |
| 4290 |
-- family index expressions are evaluated before the entry |
| 4291 |
-- parameters. |
| 4292 |
|
| 4293 |
if not Is_Protected_Type (Conctyp) |
| 4294 |
or else |
| 4295 |
Corresponding_Runtime_Package (Conctyp) = |
| 4296 |
System_Tasking_Protected_Objects_Entries |
| 4297 |
then |
| 4298 |
X := Make_Defining_Identifier (Loc, Name_uX); |
| 4299 |
|
| 4300 |
Xdecl := |
| 4301 |
Make_Object_Declaration (Loc, |
| 4302 |
Defining_Identifier => X, |
| 4303 |
Object_Definition => |
| 4304 |
New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc), |
| 4305 |
Expression => Actual_Index_Expression ( |
| 4306 |
Loc, Entity (Ename), Index, Concval)); |
| 4307 |
|
| 4308 |
Append_To (Decls, Xdecl); |
| 4309 |
Parm2 := New_Occurrence_Of (X, Loc); |
| 4310 |
|
| 4311 |
else |
| 4312 |
Xdecl := Empty; |
| 4313 |
Parm2 := Empty; |
| 4314 |
end if; |
| 4315 |
|
| 4316 |
-- The third parameter is the packaged parameters. If there are |
| 4317 |
-- none, then it is just the null address, since nothing is passed. |
| 4318 |
|
| 4319 |
if No (Parms) then |
| 4320 |
Parm3 := New_Occurrence_Of (RTE (RE_Null_Address), Loc); |
| 4321 |
P := Empty; |
| 4322 |
|
| 4323 |
-- Case of parameters present, where third argument is the address |
| 4324 |
-- of a packaged record containing the required parameter values. |
| 4325 |
|
| 4326 |
else |
| 4327 |
-- First build a list of parameter values, which are references to |
| 4328 |
-- objects of the parameter types. |
| 4329 |
|
| 4330 |
Plist := New_List; |
| 4331 |
|
| 4332 |
Actual := First_Actual (N); |
| 4333 |
Formal := First_Formal (Ent); |
| 4334 |
while Present (Actual) loop |
| 4335 |
|
| 4336 |
-- If it is a by-copy type, copy it to a new variable. The |
| 4337 |
-- packaged record has a field that points to this variable. |
| 4338 |
|
| 4339 |
if Is_By_Copy_Type (Etype (Actual)) then |
| 4340 |
N_Node := |
| 4341 |
Make_Object_Declaration (Loc, |
| 4342 |
Defining_Identifier => Make_Temporary (Loc, 'J'), |
| 4343 |
Aliased_Present => True, |
| 4344 |
Object_Definition => |
| 4345 |
New_Occurrence_Of (Etype (Formal), Loc)); |
| 4346 |
|
| 4347 |
-- Mark the object as not needing initialization since the |
| 4348 |
-- initialization is performed separately, avoiding errors |
| 4349 |
-- on cases such as formals of null-excluding access types. |
| 4350 |
|
| 4351 |
Set_No_Initialization (N_Node); |
| 4352 |
|
| 4353 |
-- We must make a separate assignment statement for the |
| 4354 |
-- case of limited types. We cannot assign it unless the |
| 4355 |
-- Assignment_OK flag is set first. An out formal of an |
| 4356 |
-- access type or whose type has a Default_Value must also |
| 4357 |
-- be initialized from the actual (see RM 6.4.1 (13-13.1)), |
| 4358 |
-- but no constraint, predicate, or null-exclusion check is |
| 4359 |
-- applied before the call. |
| 4360 |
|
| 4361 |
if Ekind (Formal) /= E_Out_Parameter |
| 4362 |
or else Is_Access_Type (Etype (Formal)) |
| 4363 |
or else |
| 4364 |
(Is_Scalar_Type (Etype (Formal)) |
| 4365 |
and then |
| 4366 |
Present (Default_Aspect_Value (Etype (Formal)))) |
| 4367 |
then |
| 4368 |
N_Var := |
| 4369 |
New_Occurrence_Of (Defining_Identifier (N_Node), Loc); |
| 4370 |
Set_Assignment_OK (N_Var); |
| 4371 |
Append_To (Stats, |
| 4372 |
Make_Assignment_Statement (Loc, |
| 4373 |
Name => N_Var, |
| 4374 |
Expression => Relocate_Node (Actual))); |
| 4375 |
|
| 4376 |
-- Mark the object as internal, so we don't later reset |
| 4377 |
-- No_Initialization flag in Default_Initialize_Object, |
| 4378 |
-- which would lead to needless default initialization. |
| 4379 |
-- We don't set this outside the if statement, because |
| 4380 |
-- out scalar parameters without Default_Value do require |
| 4381 |
-- default initialization if Initialize_Scalars applies. |
| 4382 |
|
| 4383 |
Set_Is_Internal (Defining_Identifier (N_Node)); |
| 4384 |
|
| 4385 |
-- If actual is an out parameter of a null-excluding |
| 4386 |
-- access type, there is access check on entry, so set |
| 4387 |
-- Suppress_Assignment_Checks on the generated statement |
| 4388 |
-- that assigns the actual to the parameter block. |
| 4389 |
|
| 4390 |
Set_Suppress_Assignment_Checks (Last (Stats)); |
| 4391 |
end if; |
| 4392 |
|
| 4393 |
Append (N_Node, Decls); |
| 4394 |
|
| 4395 |
Append_To (Plist, |
| 4396 |
Make_Attribute_Reference (Loc, |
| 4397 |
Attribute_Name => Name_Unchecked_Access, |
| 4398 |
Prefix => |
| 4399 |
New_Occurrence_Of |
| 4400 |
(Defining_Identifier (N_Node), Loc))); |
| 4401 |
|
| 4402 |
else |
| 4403 |
-- Interface class-wide formal |
| 4404 |
|
| 4405 |
if Ada_Version >= Ada_2005 |
| 4406 |
and then Ekind (Etype (Formal)) = E_Class_Wide_Type |
| 4407 |
and then Is_Interface (Etype (Formal)) |
| 4408 |
then |
| 4409 |
Iface_Typ := Etype (Etype (Formal)); |
| 4410 |
|
| 4411 |
-- Generate: |
| 4412 |
-- formal_iface_type! (actual.iface_tag)'reference |
| 4413 |
|
| 4414 |
Iface_Tag := |
| 4415 |
Find_Interface_Tag (Etype (Actual), Iface_Typ); |
| 4416 |
pragma Assert (Present (Iface_Tag)); |
| 4417 |
|
| 4418 |
Append_To (Plist, |
| 4419 |
Make_Reference (Loc, |
| 4420 |
Unchecked_Convert_To (Iface_Typ, |
| 4421 |
Make_Selected_Component (Loc, |
| 4422 |
Prefix => |
| 4423 |
Relocate_Node (Actual), |
| 4424 |
Selector_Name => |
| 4425 |
New_Occurrence_Of (Iface_Tag, Loc))))); |
| 4426 |
else |
| 4427 |
-- Generate: |
| 4428 |
-- actual'reference |
| 4429 |
|
| 4430 |
Append_To (Plist, |
| 4431 |
Make_Reference (Loc, Relocate_Node (Actual))); |
| 4432 |
end if; |
| 4433 |
end if; |
| 4434 |
|
| 4435 |
Next_Actual (Actual); |
| 4436 |
Next_Formal_With_Extras (Formal); |
| 4437 |
end loop; |
| 4438 |
|
| 4439 |
-- Now build the declaration of parameters initialized with the |
| 4440 |
-- aggregate containing this constructed parameter list. |
| 4441 |
|
| 4442 |
P := Make_Defining_Identifier (Loc, Name_uP); |
| 4443 |
|
| 4444 |
Pdecl := |
| 4445 |
Make_Object_Declaration (Loc, |
| 4446 |
Defining_Identifier => P, |
| 4447 |
Object_Definition => |
| 4448 |
New_Occurrence_Of (Designated_Type (Ent_Acc), Loc), |
| 4449 |
Expression => |
| 4450 |
Make_Aggregate (Loc, Expressions => Plist)); |
| 4451 |
|
| 4452 |
Parm3 := |
| 4453 |
Make_Attribute_Reference (Loc, |
| 4454 |
Prefix => New_Occurrence_Of (P, Loc), |
| 4455 |
Attribute_Name => Name_Address); |
| 4456 |
|
| 4457 |
Append (Pdecl, Decls); |
| 4458 |
end if; |
| 4459 |
|
| 4460 |
-- Now we can create the call, case of protected type |
| 4461 |
|
| 4462 |
if Is_Protected_Type (Conctyp) then |
| 4463 |
case Corresponding_Runtime_Package (Conctyp) is |
| 4464 |
when System_Tasking_Protected_Objects_Entries => |
| 4465 |
|
| 4466 |
-- Change the type of the index declaration |
| 4467 |
|
| 4468 |
Set_Object_Definition (Xdecl, |
| 4469 |
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc)); |
| 4470 |
|
| 4471 |
-- Some additional declarations for protected entry calls |
| 4472 |
|
| 4473 |
if No (Decls) then |
| 4474 |
Decls := New_List; |
| 4475 |
end if; |
| 4476 |
|
| 4477 |
-- Bnn : Communications_Block; |
| 4478 |
|
| 4479 |
Comm_Name := Make_Temporary (Loc, 'B'); |
| 4480 |
|
| 4481 |
Append_To (Decls, |
| 4482 |
Make_Object_Declaration (Loc, |
| 4483 |
Defining_Identifier => Comm_Name, |
| 4484 |
Object_Definition => |
| 4485 |
New_Occurrence_Of |
| 4486 |
(RTE (RE_Communication_Block), Loc))); |
| 4487 |
|
| 4488 |
-- Some additional statements for protected entry calls |
| 4489 |
|
| 4490 |
-- Protected_Entry_Call |
| 4491 |
-- (Object => po._object'Access, |
| 4492 |
-- E => <entry index>; |
| 4493 |
-- Uninterpreted_Data => P'Address; |
| 4494 |
-- Mode => Simple_Call; |
| 4495 |
-- Block => Bnn); |
| 4496 |
|
| 4497 |
Call := |
| 4498 |
Make_Procedure_Call_Statement (Loc, |
| 4499 |
Name => |
| 4500 |
New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc), |
| 4501 |
|
| 4502 |
Parameter_Associations => New_List ( |
| 4503 |
Make_Attribute_Reference (Loc, |
| 4504 |
Attribute_Name => Name_Unchecked_Access, |
| 4505 |
Prefix => Parm1), |
| 4506 |
Parm2, |
| 4507 |
Parm3, |
| 4508 |
New_Occurrence_Of (RTE (RE_Simple_Call), Loc), |
| 4509 |
New_Occurrence_Of (Comm_Name, Loc))); |
| 4510 |
|
| 4511 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 4512 |
|
| 4513 |
-- Protected_Single_Entry_Call |
| 4514 |
-- (Object => po._object'Access, |
| 4515 |
-- Uninterpreted_Data => P'Address); |
| 4516 |
|
| 4517 |
Call := |
| 4518 |
Make_Procedure_Call_Statement (Loc, |
| 4519 |
Name => |
| 4520 |
New_Occurrence_Of |
| 4521 |
(RTE (RE_Protected_Single_Entry_Call), Loc), |
| 4522 |
|
| 4523 |
Parameter_Associations => New_List ( |
| 4524 |
Make_Attribute_Reference (Loc, |
| 4525 |
Attribute_Name => Name_Unchecked_Access, |
| 4526 |
Prefix => Parm1), |
| 4527 |
Parm3)); |
| 4528 |
|
| 4529 |
when others => |
| 4530 |
raise Program_Error; |
| 4531 |
end case; |
| 4532 |
|
| 4533 |
-- Case of task type |
| 4534 |
|
| 4535 |
else |
| 4536 |
Call := |
| 4537 |
Make_Procedure_Call_Statement (Loc, |
| 4538 |
Name => |
| 4539 |
New_Occurrence_Of (RTE (RE_Call_Simple), Loc), |
| 4540 |
Parameter_Associations => New_List (Parm1, Parm2, Parm3)); |
| 4541 |
|
| 4542 |
end if; |
| 4543 |
|
| 4544 |
Append_To (Stats, Call); |
| 4545 |
|
| 4546 |
-- If there are out or in/out parameters by copy add assignment |
| 4547 |
-- statements for the result values. |
| 4548 |
|
| 4549 |
if Present (Parms) then |
| 4550 |
Actual := First_Actual (N); |
| 4551 |
Formal := First_Formal (Ent); |
| 4552 |
|
| 4553 |
Set_Assignment_OK (Actual); |
| 4554 |
while Present (Actual) loop |
| 4555 |
if Is_By_Copy_Type (Etype (Actual)) |
| 4556 |
and then Ekind (Formal) /= E_In_Parameter |
| 4557 |
then |
| 4558 |
N_Node := |
| 4559 |
Make_Assignment_Statement (Loc, |
| 4560 |
Name => New_Copy (Actual), |
| 4561 |
Expression => |
| 4562 |
Make_Explicit_Dereference (Loc, |
| 4563 |
Make_Selected_Component (Loc, |
| 4564 |
Prefix => New_Occurrence_Of (P, Loc), |
| 4565 |
Selector_Name => |
| 4566 |
Make_Identifier (Loc, Chars (Formal))))); |
| 4567 |
|
| 4568 |
-- In all cases (including limited private types) we want |
| 4569 |
-- the assignment to be valid. |
| 4570 |
|
| 4571 |
Set_Assignment_OK (Name (N_Node)); |
| 4572 |
|
| 4573 |
-- If the call is the triggering alternative in an |
| 4574 |
-- asynchronous select, or the entry_call alternative of a |
| 4575 |
-- conditional entry call, the assignments for in-out |
| 4576 |
-- parameters are incorporated into the statement list that |
| 4577 |
-- follows, so that there are executed only if the entry |
| 4578 |
-- call succeeds. |
| 4579 |
|
| 4580 |
if (Nkind (Parent (N)) = N_Triggering_Alternative |
| 4581 |
and then N = Triggering_Statement (Parent (N))) |
| 4582 |
or else |
| 4583 |
(Nkind (Parent (N)) = N_Entry_Call_Alternative |
| 4584 |
and then N = Entry_Call_Statement (Parent (N))) |
| 4585 |
then |
| 4586 |
if No (Statements (Parent (N))) then |
| 4587 |
Set_Statements (Parent (N), New_List); |
| 4588 |
end if; |
| 4589 |
|
| 4590 |
Prepend (N_Node, Statements (Parent (N))); |
| 4591 |
|
| 4592 |
else |
| 4593 |
Insert_After (Call, N_Node); |
| 4594 |
end if; |
| 4595 |
end if; |
| 4596 |
|
| 4597 |
Next_Actual (Actual); |
| 4598 |
Next_Formal_With_Extras (Formal); |
| 4599 |
end loop; |
| 4600 |
end if; |
| 4601 |
|
| 4602 |
-- Finally, create block and analyze it |
| 4603 |
|
| 4604 |
Rewrite (N, |
| 4605 |
Make_Block_Statement (Loc, |
| 4606 |
Declarations => Decls, |
| 4607 |
Handled_Statement_Sequence => |
| 4608 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 4609 |
Statements => Stats))); |
| 4610 |
|
| 4611 |
Analyze (N); |
| 4612 |
end; |
| 4613 |
end Build_Simple_Entry_Call; |
| 4614 |
|
| 4615 |
-------------------------------- |
| 4616 |
-- Build_Task_Activation_Call -- |
| 4617 |
-------------------------------- |
| 4618 |
|
| 4619 |
procedure Build_Task_Activation_Call (N : Node_Id) is |
| 4620 |
function Activation_Call_Loc return Source_Ptr; |
| 4621 |
-- Find a suitable source location for the activation call |
| 4622 |
|
| 4623 |
------------------------- |
| 4624 |
-- Activation_Call_Loc -- |
| 4625 |
------------------------- |
| 4626 |
|
| 4627 |
function Activation_Call_Loc return Source_Ptr is |
| 4628 |
begin |
| 4629 |
-- The activation call must carry the location of the "end" keyword |
| 4630 |
-- when the context is a package declaration. |
| 4631 |
|
| 4632 |
if Nkind (N) = N_Package_Declaration then |
| 4633 |
return End_Keyword_Location (N); |
| 4634 |
|
| 4635 |
-- Otherwise the activation call must carry the location of the |
| 4636 |
-- "begin" keyword. |
| 4637 |
|
| 4638 |
else |
| 4639 |
return Begin_Keyword_Location (N); |
| 4640 |
end if; |
| 4641 |
end Activation_Call_Loc; |
| 4642 |
|
| 4643 |
-- Local variables |
| 4644 |
|
| 4645 |
Chain : Entity_Id; |
| 4646 |
Call : Node_Id; |
| 4647 |
Loc : Source_Ptr; |
| 4648 |
Name : Node_Id; |
| 4649 |
Owner : Node_Id; |
| 4650 |
Stmt : Node_Id; |
| 4651 |
|
| 4652 |
-- Start of processing for Build_Task_Activation_Call |
| 4653 |
|
| 4654 |
begin |
| 4655 |
-- For sequential elaboration policy, all the tasks will be activated at |
| 4656 |
-- the end of the elaboration. |
| 4657 |
|
| 4658 |
if Partition_Elaboration_Policy = 'S' then |
| 4659 |
return; |
| 4660 |
|
| 4661 |
-- Do not create an activation call for a package spec if the package |
| 4662 |
-- has a completing body. The activation call will be inserted after |
| 4663 |
-- the "begin" of the body. |
| 4664 |
|
| 4665 |
elsif Nkind (N) = N_Package_Declaration |
| 4666 |
and then Present (Corresponding_Body (N)) |
| 4667 |
then |
| 4668 |
return; |
| 4669 |
end if; |
| 4670 |
|
| 4671 |
-- Obtain the activation chain entity. Block statements, entry bodies, |
| 4672 |
-- subprogram bodies, and task bodies keep the entity in their nodes. |
| 4673 |
-- Package bodies on the other hand store it in the declaration of the |
| 4674 |
-- corresponding package spec. |
| 4675 |
|
| 4676 |
Owner := N; |
| 4677 |
|
| 4678 |
if Nkind (Owner) = N_Package_Body then |
| 4679 |
Owner := Unit_Declaration_Node (Corresponding_Spec (Owner)); |
| 4680 |
end if; |
| 4681 |
|
| 4682 |
Chain := Activation_Chain_Entity (Owner); |
| 4683 |
|
| 4684 |
-- Nothing to do when there are no tasks to activate. This is indicated |
| 4685 |
-- by a missing activation chain entity; also skip generating it when |
| 4686 |
-- it is a ghost entity. |
| 4687 |
|
| 4688 |
if No (Chain) or else Is_Ignored_Ghost_Entity (Chain) then |
| 4689 |
return; |
| 4690 |
|
| 4691 |
-- The availability of the activation chain entity does not ensure |
| 4692 |
-- that we have tasks to activate because it may have been declared |
| 4693 |
-- by the frontend to pass a required extra formal to a build-in-place |
| 4694 |
-- subprogram call. If we are within the scope of a protected type and |
| 4695 |
-- pragma Detect_Blocking is active we can assume that no tasks will be |
| 4696 |
-- activated; if tasks are created in a protected object and this pragma |
| 4697 |
-- is active then the frontend emits a warning and Program_Error is |
| 4698 |
-- raised at runtime. |
| 4699 |
|
| 4700 |
elsif Detect_Blocking and then Within_Protected_Type (Current_Scope) then |
| 4701 |
return; |
| 4702 |
end if; |
| 4703 |
|
| 4704 |
-- The location of the activation call must be as close as possible to |
| 4705 |
-- the intended semantic location of the activation because the ABE |
| 4706 |
-- mechanism relies heavily on accurate locations. |
| 4707 |
|
| 4708 |
Loc := Activation_Call_Loc; |
| 4709 |
|
| 4710 |
if Restricted_Profile then |
| 4711 |
Name := New_Occurrence_Of (RTE (RE_Activate_Restricted_Tasks), Loc); |
| 4712 |
else |
| 4713 |
Name := New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc); |
| 4714 |
end if; |
| 4715 |
|
| 4716 |
Call := |
| 4717 |
Make_Procedure_Call_Statement (Loc, |
| 4718 |
Name => Name, |
| 4719 |
Parameter_Associations => |
| 4720 |
New_List (Make_Attribute_Reference (Loc, |
| 4721 |
Prefix => New_Occurrence_Of (Chain, Loc), |
| 4722 |
Attribute_Name => Name_Unchecked_Access))); |
| 4723 |
|
| 4724 |
if Nkind (N) = N_Package_Declaration then |
| 4725 |
if Present (Private_Declarations (Specification (N))) then |
| 4726 |
Append (Call, Private_Declarations (Specification (N))); |
| 4727 |
else |
| 4728 |
Append (Call, Visible_Declarations (Specification (N))); |
| 4729 |
end if; |
| 4730 |
|
| 4731 |
else |
| 4732 |
-- The call goes at the start of the statement sequence after the |
| 4733 |
-- start of exception range label if one is present. |
| 4734 |
|
| 4735 |
if Present (Handled_Statement_Sequence (N)) then |
| 4736 |
Stmt := First (Statements (Handled_Statement_Sequence (N))); |
| 4737 |
|
| 4738 |
-- A special case, skip exception range label if one is present |
| 4739 |
-- (from front end zcx processing). |
| 4740 |
|
| 4741 |
if Nkind (Stmt) = N_Label and then Exception_Junk (Stmt) then |
| 4742 |
Next (Stmt); |
| 4743 |
end if; |
| 4744 |
|
| 4745 |
-- Another special case, if the first statement is a block from |
| 4746 |
-- optimization of a local raise to a goto, then the call goes |
| 4747 |
-- inside this block. |
| 4748 |
|
| 4749 |
if Nkind (Stmt) = N_Block_Statement |
| 4750 |
and then Exception_Junk (Stmt) |
| 4751 |
then |
| 4752 |
Stmt := First (Statements (Handled_Statement_Sequence (Stmt))); |
| 4753 |
end if; |
| 4754 |
|
| 4755 |
-- Insertion point is after any exception label pushes, since we |
| 4756 |
-- want it covered by any local handlers. |
| 4757 |
|
| 4758 |
while Nkind (Stmt) in N_Push_xxx_Label loop |
| 4759 |
Next (Stmt); |
| 4760 |
end loop; |
| 4761 |
|
| 4762 |
-- Now we have the proper insertion point |
| 4763 |
|
| 4764 |
Insert_Before (Stmt, Call); |
| 4765 |
|
| 4766 |
else |
| 4767 |
Set_Handled_Statement_Sequence (N, |
| 4768 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 4769 |
Statements => New_List (Call))); |
| 4770 |
end if; |
| 4771 |
end if; |
| 4772 |
|
| 4773 |
Analyze (Call); |
| 4774 |
|
| 4775 |
if Legacy_Elaboration_Checks then |
| 4776 |
Check_Task_Activation (N); |
| 4777 |
end if; |
| 4778 |
end Build_Task_Activation_Call; |
| 4779 |
|
| 4780 |
------------------------------- |
| 4781 |
-- Build_Task_Allocate_Block -- |
| 4782 |
------------------------------- |
| 4783 |
|
| 4784 |
procedure Build_Task_Allocate_Block |
| 4785 |
(Actions : List_Id; |
| 4786 |
N : Node_Id; |
| 4787 |
Init_Stmts : List_Id) |
| 4788 |
is |
| 4789 |
Loc : constant Source_Ptr := Sloc (N); |
| 4790 |
Chain : constant Entity_Id := |
| 4791 |
Make_Defining_Identifier (Loc, Name_uChain); |
| 4792 |
Blkent : constant Entity_Id := Make_Temporary (Loc, 'A'); |
| 4793 |
Block : Node_Id; |
| 4794 |
|
| 4795 |
begin |
| 4796 |
Append_To (Init_Stmts, |
| 4797 |
Make_Procedure_Call_Statement (Loc, |
| 4798 |
Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc), |
| 4799 |
Parameter_Associations => New_List ( |
| 4800 |
Make_Attribute_Reference (Loc, |
| 4801 |
Prefix => New_Occurrence_Of (Chain, Loc), |
| 4802 |
Attribute_Name => Name_Unchecked_Access)))); |
| 4803 |
|
| 4804 |
Block := |
| 4805 |
Make_Block_Statement (Loc, |
| 4806 |
Identifier => New_Occurrence_Of (Blkent, Loc), |
| 4807 |
Declarations => New_List ( |
| 4808 |
|
| 4809 |
-- _Chain : aliased Activation_Chain; |
| 4810 |
|
| 4811 |
Make_Object_Declaration (Loc, |
| 4812 |
Defining_Identifier => Chain, |
| 4813 |
Aliased_Present => True, |
| 4814 |
Object_Definition => |
| 4815 |
New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))), |
| 4816 |
|
| 4817 |
Handled_Statement_Sequence => |
| 4818 |
Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts), |
| 4819 |
|
| 4820 |
Has_Created_Identifier => True, |
| 4821 |
Is_Task_Allocation_Block => True); |
| 4822 |
|
| 4823 |
Append_To (Actions, |
| 4824 |
Make_Implicit_Label_Declaration (Loc, |
| 4825 |
Defining_Identifier => Blkent, |
| 4826 |
Label_Construct => Block)); |
| 4827 |
|
| 4828 |
Append_To (Actions, Block); |
| 4829 |
|
| 4830 |
Set_Activation_Chain_Entity (Block, Chain); |
| 4831 |
end Build_Task_Allocate_Block; |
| 4832 |
|
| 4833 |
----------------------------------- |
| 4834 |
-- Build_Task_Proc_Specification -- |
| 4835 |
----------------------------------- |
| 4836 |
|
| 4837 |
function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is |
| 4838 |
Loc : constant Source_Ptr := Sloc (T); |
| 4839 |
Spec_Id : Entity_Id; |
| 4840 |
|
| 4841 |
begin |
| 4842 |
-- Case of explicit task type, suffix TB |
| 4843 |
|
| 4844 |
if Comes_From_Source (T) then |
| 4845 |
Spec_Id := |
| 4846 |
Make_Defining_Identifier (Loc, New_External_Name (Chars (T), "TB")); |
| 4847 |
|
| 4848 |
-- Case of anonymous task type, suffix B |
| 4849 |
|
| 4850 |
else |
| 4851 |
Spec_Id := |
| 4852 |
Make_Defining_Identifier (Loc, New_External_Name (Chars (T), 'B')); |
| 4853 |
end if; |
| 4854 |
|
| 4855 |
Set_Is_Internal (Spec_Id); |
| 4856 |
|
| 4857 |
-- Associate the procedure with the task, if this is the declaration |
| 4858 |
-- (and not the body) of the procedure. |
| 4859 |
|
| 4860 |
if No (Task_Body_Procedure (T)) then |
| 4861 |
Set_Task_Body_Procedure (T, Spec_Id); |
| 4862 |
end if; |
| 4863 |
|
| 4864 |
return |
| 4865 |
Make_Procedure_Specification (Loc, |
| 4866 |
Defining_Unit_Name => Spec_Id, |
| 4867 |
Parameter_Specifications => New_List ( |
| 4868 |
Make_Parameter_Specification (Loc, |
| 4869 |
Defining_Identifier => |
| 4870 |
Make_Defining_Identifier (Loc, Name_uTask), |
| 4871 |
Parameter_Type => |
| 4872 |
Make_Access_Definition (Loc, |
| 4873 |
Subtype_Mark => |
| 4874 |
New_Occurrence_Of (Corresponding_Record_Type (T), Loc))))); |
| 4875 |
end Build_Task_Proc_Specification; |
| 4876 |
|
| 4877 |
--------------------------------------- |
| 4878 |
-- Build_Unprotected_Subprogram_Body -- |
| 4879 |
--------------------------------------- |
| 4880 |
|
| 4881 |
function Build_Unprotected_Subprogram_Body |
| 4882 |
(N : Node_Id; |
| 4883 |
Pid : Node_Id) return Node_Id |
| 4884 |
is |
| 4885 |
Decls : constant List_Id := Declarations (N); |
| 4886 |
|
| 4887 |
begin |
| 4888 |
-- Add renamings for the Protection object, discriminals, privals, and |
| 4889 |
-- the entry index constant for use by debugger. |
| 4890 |
|
| 4891 |
Debug_Private_Data_Declarations (Decls); |
| 4892 |
|
| 4893 |
-- Make an unprotected version of the subprogram for use within the same |
| 4894 |
-- object, with a new name and an additional parameter representing the |
| 4895 |
-- object. |
| 4896 |
|
| 4897 |
return |
| 4898 |
Make_Subprogram_Body (Sloc (N), |
| 4899 |
Specification => |
| 4900 |
Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode), |
| 4901 |
Declarations => Decls, |
| 4902 |
Handled_Statement_Sequence => Handled_Statement_Sequence (N), |
| 4903 |
At_End_Proc => At_End_Proc (N)); |
| 4904 |
end Build_Unprotected_Subprogram_Body; |
| 4905 |
|
| 4906 |
---------------------------- |
| 4907 |
-- Collect_Entry_Families -- |
| 4908 |
---------------------------- |
| 4909 |
|
| 4910 |
procedure Collect_Entry_Families |
| 4911 |
(Loc : Source_Ptr; |
| 4912 |
Cdecls : List_Id; |
| 4913 |
Current_Node : in out Node_Id; |
| 4914 |
Conctyp : Entity_Id) |
| 4915 |
is |
| 4916 |
Efam : Entity_Id; |
| 4917 |
Efam_Decl : Node_Id; |
| 4918 |
Efam_Type : Entity_Id; |
| 4919 |
|
| 4920 |
begin |
| 4921 |
Efam := First_Entity (Conctyp); |
| 4922 |
while Present (Efam) loop |
| 4923 |
if Ekind (Efam) = E_Entry_Family then |
| 4924 |
Efam_Type := Make_Temporary (Loc, 'F'); |
| 4925 |
|
| 4926 |
declare |
| 4927 |
Eityp : constant Entity_Id := Entry_Index_Type (Efam); |
| 4928 |
Lo : constant Node_Id := Type_Low_Bound (Eityp); |
| 4929 |
Hi : constant Node_Id := Type_High_Bound (Eityp); |
| 4930 |
Bdecl : Node_Id; |
| 4931 |
Bityp : Entity_Id; |
| 4932 |
|
| 4933 |
begin |
| 4934 |
Bityp := Base_Type (Eityp); |
| 4935 |
|
| 4936 |
if Is_Potentially_Large_Family (Bityp, Conctyp, Lo, Hi) then |
| 4937 |
Bityp := Make_Temporary (Loc, 'B'); |
| 4938 |
|
| 4939 |
Bdecl := |
| 4940 |
Make_Subtype_Declaration (Loc, |
| 4941 |
Defining_Identifier => Bityp, |
| 4942 |
Subtype_Indication => |
| 4943 |
Make_Subtype_Indication (Loc, |
| 4944 |
Subtype_Mark => |
| 4945 |
New_Occurrence_Of (Standard_Integer, Loc), |
| 4946 |
Constraint => |
| 4947 |
Make_Range_Constraint (Loc, |
| 4948 |
Range_Expression => Make_Range (Loc, |
| 4949 |
Make_Integer_Literal |
| 4950 |
(Loc, -Entry_Family_Bound), |
| 4951 |
Make_Integer_Literal |
| 4952 |
(Loc, Entry_Family_Bound - 1))))); |
| 4953 |
|
| 4954 |
Insert_After (Current_Node, Bdecl); |
| 4955 |
Current_Node := Bdecl; |
| 4956 |
Analyze (Bdecl); |
| 4957 |
end if; |
| 4958 |
|
| 4959 |
Efam_Decl := |
| 4960 |
Make_Full_Type_Declaration (Loc, |
| 4961 |
Defining_Identifier => Efam_Type, |
| 4962 |
Type_Definition => |
| 4963 |
Make_Unconstrained_Array_Definition (Loc, |
| 4964 |
Subtype_Marks => |
| 4965 |
(New_List (New_Occurrence_Of (Bityp, Loc))), |
| 4966 |
|
| 4967 |
Component_Definition => |
| 4968 |
Make_Component_Definition (Loc, |
| 4969 |
Subtype_Indication => |
| 4970 |
New_Occurrence_Of (Standard_Character, Loc)))); |
| 4971 |
end; |
| 4972 |
|
| 4973 |
Insert_After (Current_Node, Efam_Decl); |
| 4974 |
Current_Node := Efam_Decl; |
| 4975 |
Analyze (Efam_Decl); |
| 4976 |
|
| 4977 |
Append_To (Cdecls, |
| 4978 |
Make_Component_Declaration (Loc, |
| 4979 |
Defining_Identifier => |
| 4980 |
Make_Defining_Identifier (Loc, Chars (Efam)), |
| 4981 |
|
| 4982 |
Component_Definition => |
| 4983 |
Make_Component_Definition (Loc, |
| 4984 |
Subtype_Indication => |
| 4985 |
Make_Subtype_Indication (Loc, |
| 4986 |
Subtype_Mark => |
| 4987 |
New_Occurrence_Of (Efam_Type, Loc), |
| 4988 |
|
| 4989 |
Constraint => |
| 4990 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 4991 |
Constraints => New_List ( |
| 4992 |
New_Occurrence_Of (Entry_Index_Type (Efam), |
| 4993 |
Loc))))))); |
| 4994 |
end if; |
| 4995 |
|
| 4996 |
Next_Entity (Efam); |
| 4997 |
end loop; |
| 4998 |
end Collect_Entry_Families; |
| 4999 |
|
| 5000 |
----------------------- |
| 5001 |
-- Concurrent_Object -- |
| 5002 |
----------------------- |
| 5003 |
|
| 5004 |
function Concurrent_Object |
| 5005 |
(Spec_Id : Entity_Id; |
| 5006 |
Conc_Typ : Entity_Id) return Entity_Id |
| 5007 |
is |
| 5008 |
begin |
| 5009 |
-- Parameter _O or _object |
| 5010 |
|
| 5011 |
if Is_Protected_Type (Conc_Typ) then |
| 5012 |
return First_Formal (Protected_Body_Subprogram (Spec_Id)); |
| 5013 |
|
| 5014 |
-- Parameter _task |
| 5015 |
|
| 5016 |
else |
| 5017 |
pragma Assert (Is_Task_Type (Conc_Typ)); |
| 5018 |
return First_Formal (Task_Body_Procedure (Conc_Typ)); |
| 5019 |
end if; |
| 5020 |
end Concurrent_Object; |
| 5021 |
|
| 5022 |
---------------------- |
| 5023 |
-- Copy_Result_Type -- |
| 5024 |
---------------------- |
| 5025 |
|
| 5026 |
function Copy_Result_Type (Res : Node_Id) return Node_Id is |
| 5027 |
New_Res : constant Node_Id := New_Copy_Tree (Res); |
| 5028 |
Par_Spec : Node_Id; |
| 5029 |
Formal : Entity_Id; |
| 5030 |
|
| 5031 |
begin |
| 5032 |
-- If the result type is an access_to_subprogram, we must create new |
| 5033 |
-- entities for its spec. |
| 5034 |
|
| 5035 |
if Nkind (New_Res) = N_Access_Definition |
| 5036 |
and then Present (Access_To_Subprogram_Definition (New_Res)) |
| 5037 |
then |
| 5038 |
-- Provide new entities for the formals |
| 5039 |
|
| 5040 |
Par_Spec := First (Parameter_Specifications |
| 5041 |
(Access_To_Subprogram_Definition (New_Res))); |
| 5042 |
while Present (Par_Spec) loop |
| 5043 |
Formal := Defining_Identifier (Par_Spec); |
| 5044 |
Set_Defining_Identifier (Par_Spec, |
| 5045 |
Make_Defining_Identifier (Sloc (Formal), Chars (Formal))); |
| 5046 |
Next (Par_Spec); |
| 5047 |
end loop; |
| 5048 |
end if; |
| 5049 |
|
| 5050 |
return New_Res; |
| 5051 |
end Copy_Result_Type; |
| 5052 |
|
| 5053 |
-------------------- |
| 5054 |
-- Concurrent_Ref -- |
| 5055 |
-------------------- |
| 5056 |
|
| 5057 |
-- The expression returned for a reference to a concurrent object has the |
| 5058 |
-- form: |
| 5059 |
|
| 5060 |
-- taskV!(name)._Task_Id |
| 5061 |
|
| 5062 |
-- for a task, and |
| 5063 |
|
| 5064 |
-- objectV!(name)._Object |
| 5065 |
|
| 5066 |
-- for a protected object. For the case of an access to a concurrent |
| 5067 |
-- object, there is an extra explicit dereference: |
| 5068 |
|
| 5069 |
-- taskV!(name.all)._Task_Id |
| 5070 |
-- objectV!(name.all)._Object |
| 5071 |
|
| 5072 |
-- here taskV and objectV are the types for the associated records, which |
| 5073 |
-- contain the required _Task_Id and _Object fields for tasks and protected |
| 5074 |
-- objects, respectively. |
| 5075 |
|
| 5076 |
-- For the case of a task type name, the expression is |
| 5077 |
|
| 5078 |
-- Self; |
| 5079 |
|
| 5080 |
-- i.e. a call to the Self function which returns precisely this Task_Id |
| 5081 |
|
| 5082 |
-- For the case of a protected type name, the expression is |
| 5083 |
|
| 5084 |
-- objectR |
| 5085 |
|
| 5086 |
-- which is a renaming of the _object field of the current object |
| 5087 |
-- record, passed into protected operations as a parameter. |
| 5088 |
|
| 5089 |
function Concurrent_Ref (N : Node_Id) return Node_Id is |
| 5090 |
Loc : constant Source_Ptr := Sloc (N); |
| 5091 |
Ntyp : constant Entity_Id := Etype (N); |
| 5092 |
Dtyp : Entity_Id; |
| 5093 |
Sel : Name_Id; |
| 5094 |
|
| 5095 |
function Is_Current_Task (T : Entity_Id) return Boolean; |
| 5096 |
-- Check whether the reference is to the immediately enclosing task |
| 5097 |
-- type, or to an outer one (rare but legal). |
| 5098 |
|
| 5099 |
--------------------- |
| 5100 |
-- Is_Current_Task -- |
| 5101 |
--------------------- |
| 5102 |
|
| 5103 |
function Is_Current_Task (T : Entity_Id) return Boolean is |
| 5104 |
Scop : Entity_Id; |
| 5105 |
|
| 5106 |
begin |
| 5107 |
Scop := Current_Scope; |
| 5108 |
while Present (Scop) and then Scop /= Standard_Standard loop |
| 5109 |
if Scop = T then |
| 5110 |
return True; |
| 5111 |
|
| 5112 |
elsif Is_Task_Type (Scop) then |
| 5113 |
return False; |
| 5114 |
|
| 5115 |
-- If this is a procedure nested within the task type, we must |
| 5116 |
-- assume that it can be called from an inner task, and therefore |
| 5117 |
-- cannot treat it as a local reference. |
| 5118 |
|
| 5119 |
elsif Is_Overloadable (Scop) and then In_Open_Scopes (T) then |
| 5120 |
return False; |
| 5121 |
|
| 5122 |
else |
| 5123 |
Scop := Scope (Scop); |
| 5124 |
end if; |
| 5125 |
end loop; |
| 5126 |
|
| 5127 |
-- We know that we are within the task body, so should have found it |
| 5128 |
-- in scope. |
| 5129 |
|
| 5130 |
raise Program_Error; |
| 5131 |
end Is_Current_Task; |
| 5132 |
|
| 5133 |
-- Start of processing for Concurrent_Ref |
| 5134 |
|
| 5135 |
begin |
| 5136 |
if Is_Access_Type (Ntyp) then |
| 5137 |
Dtyp := Designated_Type (Ntyp); |
| 5138 |
|
| 5139 |
if Is_Protected_Type (Dtyp) then |
| 5140 |
Sel := Name_uObject; |
| 5141 |
else |
| 5142 |
Sel := Name_uTask_Id; |
| 5143 |
end if; |
| 5144 |
|
| 5145 |
return |
| 5146 |
Make_Selected_Component (Loc, |
| 5147 |
Prefix => |
| 5148 |
Unchecked_Convert_To (Corresponding_Record_Type (Dtyp), |
| 5149 |
Make_Explicit_Dereference (Loc, N)), |
| 5150 |
Selector_Name => Make_Identifier (Loc, Sel)); |
| 5151 |
|
| 5152 |
elsif Is_Entity_Name (N) and then Is_Concurrent_Type (Entity (N)) then |
| 5153 |
if Is_Task_Type (Entity (N)) then |
| 5154 |
|
| 5155 |
if Is_Current_Task (Entity (N)) then |
| 5156 |
return |
| 5157 |
Make_Function_Call (Loc, |
| 5158 |
Name => New_Occurrence_Of (RTE (RE_Self), Loc)); |
| 5159 |
|
| 5160 |
else |
| 5161 |
declare |
| 5162 |
Decl : Node_Id; |
| 5163 |
T_Self : constant Entity_Id := Make_Temporary (Loc, 'T'); |
| 5164 |
T_Body : constant Node_Id := |
| 5165 |
Parent (Corresponding_Body (Parent (Entity (N)))); |
| 5166 |
|
| 5167 |
begin |
| 5168 |
Decl := |
| 5169 |
Make_Object_Declaration (Loc, |
| 5170 |
Defining_Identifier => T_Self, |
| 5171 |
Object_Definition => |
| 5172 |
New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc), |
| 5173 |
Expression => |
| 5174 |
Make_Function_Call (Loc, |
| 5175 |
Name => New_Occurrence_Of (RTE (RE_Self), Loc))); |
| 5176 |
Prepend (Decl, Declarations (T_Body)); |
| 5177 |
Analyze (Decl); |
| 5178 |
Set_Scope (T_Self, Entity (N)); |
| 5179 |
return New_Occurrence_Of (T_Self, Loc); |
| 5180 |
end; |
| 5181 |
end if; |
| 5182 |
|
| 5183 |
else |
| 5184 |
pragma Assert (Is_Protected_Type (Entity (N))); |
| 5185 |
|
| 5186 |
return |
| 5187 |
New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc); |
| 5188 |
end if; |
| 5189 |
|
| 5190 |
else |
| 5191 |
if Is_Protected_Type (Ntyp) then |
| 5192 |
Sel := Name_uObject; |
| 5193 |
elsif Is_Task_Type (Ntyp) then |
| 5194 |
Sel := Name_uTask_Id; |
| 5195 |
else |
| 5196 |
raise Program_Error; |
| 5197 |
end if; |
| 5198 |
|
| 5199 |
return |
| 5200 |
Make_Selected_Component (Loc, |
| 5201 |
Prefix => |
| 5202 |
Unchecked_Convert_To (Corresponding_Record_Type (Ntyp), |
| 5203 |
New_Copy_Tree (N)), |
| 5204 |
Selector_Name => Make_Identifier (Loc, Sel)); |
| 5205 |
end if; |
| 5206 |
end Concurrent_Ref; |
| 5207 |
|
| 5208 |
------------------------ |
| 5209 |
-- Convert_Concurrent -- |
| 5210 |
------------------------ |
| 5211 |
|
| 5212 |
function Convert_Concurrent |
| 5213 |
(N : Node_Id; |
| 5214 |
Typ : Entity_Id) return Node_Id |
| 5215 |
is |
| 5216 |
begin |
| 5217 |
if not Is_Concurrent_Type (Typ) then |
| 5218 |
return N; |
| 5219 |
else |
| 5220 |
return |
| 5221 |
Unchecked_Convert_To |
| 5222 |
(Corresponding_Record_Type (Typ), New_Copy_Tree (N)); |
| 5223 |
end if; |
| 5224 |
end Convert_Concurrent; |
| 5225 |
|
| 5226 |
------------------------------------- |
| 5227 |
-- Create_Secondary_Stack_For_Task -- |
| 5228 |
------------------------------------- |
| 5229 |
|
| 5230 |
function Create_Secondary_Stack_For_Task (T : Node_Id) return Boolean is |
| 5231 |
begin |
| 5232 |
return |
| 5233 |
(Restriction_Active (No_Implicit_Heap_Allocations) |
| 5234 |
or else Restriction_Active (No_Implicit_Task_Allocations)) |
| 5235 |
and then not Restriction_Active (No_Secondary_Stack) |
| 5236 |
and then Has_Rep_Pragma |
| 5237 |
(T, Name_Secondary_Stack_Size, Check_Parents => False); |
| 5238 |
end Create_Secondary_Stack_For_Task; |
| 5239 |
|
| 5240 |
------------------------------------- |
| 5241 |
-- Debug_Private_Data_Declarations -- |
| 5242 |
------------------------------------- |
| 5243 |
|
| 5244 |
procedure Debug_Private_Data_Declarations (Decls : List_Id) is |
| 5245 |
Debug_Nod : Node_Id; |
| 5246 |
Decl : Node_Id; |
| 5247 |
|
| 5248 |
begin |
| 5249 |
Decl := First (Decls); |
| 5250 |
while Present (Decl) and then not Comes_From_Source (Decl) loop |
| 5251 |
|
| 5252 |
-- Declaration for concurrent entity _object and its access type, |
| 5253 |
-- along with the entry index subtype: |
| 5254 |
-- type prot_typVP is access prot_typV; |
| 5255 |
-- _object : prot_typVP := prot_typV (_O); |
| 5256 |
-- subtype Jnn is <Type of Index> range Low .. High; |
| 5257 |
|
| 5258 |
if Nkind (Decl) in N_Full_Type_Declaration | N_Object_Declaration then |
| 5259 |
Set_Debug_Info_Needed (Defining_Identifier (Decl)); |
| 5260 |
|
| 5261 |
-- Declaration for the Protection object, discriminals, privals, and |
| 5262 |
-- entry index constant: |
| 5263 |
-- conc_typR : protection_typ renames _object._object; |
| 5264 |
-- discr_nameD : discr_typ renames _object.discr_name; |
| 5265 |
-- discr_nameD : discr_typ renames _task.discr_name; |
| 5266 |
-- prival_name : comp_typ renames _object.comp_name; |
| 5267 |
-- J : constant Jnn := |
| 5268 |
-- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First)); |
| 5269 |
|
| 5270 |
elsif Nkind (Decl) = N_Object_Renaming_Declaration then |
| 5271 |
Set_Debug_Info_Needed (Defining_Identifier (Decl)); |
| 5272 |
Debug_Nod := Debug_Renaming_Declaration (Decl); |
| 5273 |
|
| 5274 |
if Present (Debug_Nod) then |
| 5275 |
Insert_After (Decl, Debug_Nod); |
| 5276 |
end if; |
| 5277 |
end if; |
| 5278 |
|
| 5279 |
Next (Decl); |
| 5280 |
end loop; |
| 5281 |
end Debug_Private_Data_Declarations; |
| 5282 |
|
| 5283 |
------------------------------ |
| 5284 |
-- Ensure_Statement_Present -- |
| 5285 |
------------------------------ |
| 5286 |
|
| 5287 |
procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id) is |
| 5288 |
Stmt : Node_Id; |
| 5289 |
|
| 5290 |
begin |
| 5291 |
if Opt.Suppress_Control_Flow_Optimizations |
| 5292 |
and then Is_Empty_List (Statements (Alt)) |
| 5293 |
then |
| 5294 |
Stmt := Make_Null_Statement (Loc); |
| 5295 |
|
| 5296 |
-- Mark NULL statement as coming from source so that it is not |
| 5297 |
-- eliminated by GIGI. |
| 5298 |
|
| 5299 |
-- Another covert channel. If this is a requirement, it must be |
| 5300 |
-- documented in sinfo/einfo ??? |
| 5301 |
|
| 5302 |
Set_Comes_From_Source (Stmt, True); |
| 5303 |
|
| 5304 |
Set_Statements (Alt, New_List (Stmt)); |
| 5305 |
end if; |
| 5306 |
end Ensure_Statement_Present; |
| 5307 |
|
| 5308 |
---------------------------- |
| 5309 |
-- Entry_Index_Expression -- |
| 5310 |
---------------------------- |
| 5311 |
|
| 5312 |
function Entry_Index_Expression |
| 5313 |
(Sloc : Source_Ptr; |
| 5314 |
Ent : Entity_Id; |
| 5315 |
Index : Node_Id; |
| 5316 |
Ttyp : Entity_Id) return Node_Id |
| 5317 |
is |
| 5318 |
Expr : Node_Id; |
| 5319 |
Num : Node_Id; |
| 5320 |
Lo : Node_Id; |
| 5321 |
Hi : Node_Id; |
| 5322 |
Prev : Entity_Id; |
| 5323 |
S : Node_Id; |
| 5324 |
|
| 5325 |
begin |
| 5326 |
-- The queues of entries and entry families appear in textual order in |
| 5327 |
-- the associated record. The entry index is computed as the sum of the |
| 5328 |
-- number of queues for all entries that precede the designated one, to |
| 5329 |
-- which is added the index expression, if this expression denotes a |
| 5330 |
-- member of a family. |
| 5331 |
|
| 5332 |
-- The following is a place holder for the count of simple entries |
| 5333 |
|
| 5334 |
Num := Make_Integer_Literal (Sloc, 1); |
| 5335 |
|
| 5336 |
-- We construct an expression which is a series of addition operations. |
| 5337 |
-- The first operand is the number of single entries that precede this |
| 5338 |
-- one, the second operand is the index value relative to the start of |
| 5339 |
-- the referenced family, and the remaining operands are the lengths of |
| 5340 |
-- the entry families that precede this entry, i.e. the constructed |
| 5341 |
-- expression is: |
| 5342 |
|
| 5343 |
-- number_simple_entries + |
| 5344 |
-- (s'pos (index-value) - s'pos (family'first)) + 1 + |
| 5345 |
-- family'length + ... |
| 5346 |
|
| 5347 |
-- where index-value is the given index value, and s is the index |
| 5348 |
-- subtype (we have to use pos because the subtype might be an |
| 5349 |
-- enumeration type preventing direct subtraction). Note that the task |
| 5350 |
-- entry array is one-indexed. |
| 5351 |
|
| 5352 |
-- The upper bound of the entry family may be a discriminant, so we |
| 5353 |
-- retrieve the lower bound explicitly to compute offset, rather than |
| 5354 |
-- using the index subtype which may mention a discriminant. |
| 5355 |
|
| 5356 |
if Present (Index) then |
| 5357 |
S := Entry_Index_Type (Ent); |
| 5358 |
|
| 5359 |
-- First make sure the index is in range if requested. The index type |
| 5360 |
-- is the pristine Entry_Index_Type of the entry. |
| 5361 |
|
| 5362 |
if Do_Range_Check (Index) then |
| 5363 |
Generate_Range_Check (Index, S, CE_Range_Check_Failed); |
| 5364 |
end if; |
| 5365 |
|
| 5366 |
Expr := |
| 5367 |
Make_Op_Add (Sloc, |
| 5368 |
Left_Opnd => Num, |
| 5369 |
Right_Opnd => |
| 5370 |
Family_Offset |
| 5371 |
(Sloc, |
| 5372 |
Make_Attribute_Reference (Sloc, |
| 5373 |
Attribute_Name => Name_Pos, |
| 5374 |
Prefix => New_Occurrence_Of (Base_Type (S), Sloc), |
| 5375 |
Expressions => New_List (Relocate_Node (Index))), |
| 5376 |
Type_Low_Bound (S), |
| 5377 |
Ttyp, |
| 5378 |
False)); |
| 5379 |
else |
| 5380 |
Expr := Num; |
| 5381 |
end if; |
| 5382 |
|
| 5383 |
-- Now add lengths of preceding entries and entry families |
| 5384 |
|
| 5385 |
Prev := First_Entity (Ttyp); |
| 5386 |
while Chars (Prev) /= Chars (Ent) |
| 5387 |
or else Ekind (Prev) /= Ekind (Ent) |
| 5388 |
or else not Sem_Ch6.Type_Conformant (Ent, Prev) |
| 5389 |
loop |
| 5390 |
if Ekind (Prev) = E_Entry then |
| 5391 |
Set_Intval (Num, Intval (Num) + 1); |
| 5392 |
|
| 5393 |
elsif Ekind (Prev) = E_Entry_Family then |
| 5394 |
S := Entry_Index_Type (Prev); |
| 5395 |
Lo := Type_Low_Bound (S); |
| 5396 |
Hi := Type_High_Bound (S); |
| 5397 |
|
| 5398 |
Expr := |
| 5399 |
Make_Op_Add (Sloc, |
| 5400 |
Left_Opnd => Expr, |
| 5401 |
Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False)); |
| 5402 |
|
| 5403 |
-- Other components are anonymous types to be ignored |
| 5404 |
|
| 5405 |
else |
| 5406 |
null; |
| 5407 |
end if; |
| 5408 |
|
| 5409 |
Next_Entity (Prev); |
| 5410 |
end loop; |
| 5411 |
|
| 5412 |
return Expr; |
| 5413 |
end Entry_Index_Expression; |
| 5414 |
|
| 5415 |
--------------------------- |
| 5416 |
-- Establish_Task_Master -- |
| 5417 |
--------------------------- |
| 5418 |
|
| 5419 |
procedure Establish_Task_Master (N : Node_Id) is |
| 5420 |
Call : Node_Id; |
| 5421 |
|
| 5422 |
begin |
| 5423 |
if Restriction_Active (No_Task_Hierarchy) = False then |
| 5424 |
Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master); |
| 5425 |
|
| 5426 |
-- The block may have no declarations (and nevertheless be a task |
| 5427 |
-- master) if it contains a call that may return an object that |
| 5428 |
-- contains tasks. |
| 5429 |
|
| 5430 |
if No (Declarations (N)) then |
| 5431 |
Set_Declarations (N, New_List (Call)); |
| 5432 |
else |
| 5433 |
Prepend_To (Declarations (N), Call); |
| 5434 |
end if; |
| 5435 |
|
| 5436 |
Analyze (Call); |
| 5437 |
end if; |
| 5438 |
end Establish_Task_Master; |
| 5439 |
|
| 5440 |
-------------------------------- |
| 5441 |
-- Expand_Accept_Declarations -- |
| 5442 |
-------------------------------- |
| 5443 |
|
| 5444 |
-- Part of the expansion of an accept statement involves the creation of |
| 5445 |
-- a declaration that can be referenced from the statement sequence of |
| 5446 |
-- the accept: |
| 5447 |
|
| 5448 |
-- Ann : Address; |
| 5449 |
|
| 5450 |
-- This declaration is inserted immediately before the accept statement |
| 5451 |
-- and it is important that it be inserted before the statements of the |
| 5452 |
-- statement sequence are analyzed. Thus it would be too late to create |
| 5453 |
-- this declaration in the Expand_N_Accept_Statement routine, which is |
| 5454 |
-- why there is a separate procedure to be called directly from Sem_Ch9. |
| 5455 |
|
| 5456 |
-- Ann is used to hold the address of the record containing the parameters |
| 5457 |
-- (see Expand_N_Entry_Call for more details on how this record is built). |
| 5458 |
-- References to the parameters do an unchecked conversion of this address |
| 5459 |
-- to a pointer to the required record type, and then access the field that |
| 5460 |
-- holds the value of the required parameter. The entity for the address |
| 5461 |
-- variable is held as the top stack element (i.e. the last element) of the |
| 5462 |
-- Accept_Address stack in the corresponding entry entity, and this element |
| 5463 |
-- must be set in place before the statements are processed. |
| 5464 |
|
| 5465 |
-- The above description applies to the case of a stand alone accept |
| 5466 |
-- statement, i.e. one not appearing as part of a select alternative. |
| 5467 |
|
| 5468 |
-- For the case of an accept that appears as part of a select alternative |
| 5469 |
-- of a selective accept, we must still create the declaration right away, |
| 5470 |
-- since Ann is needed immediately, but there is an important difference: |
| 5471 |
|
| 5472 |
-- The declaration is inserted before the selective accept, not before |
| 5473 |
-- the accept statement (which is not part of a list anyway, and so would |
| 5474 |
-- not accommodate inserted declarations) |
| 5475 |
|
| 5476 |
-- We only need one address variable for the entire selective accept. So |
| 5477 |
-- the Ann declaration is created only for the first accept alternative, |
| 5478 |
-- and subsequent accept alternatives reference the same Ann variable. |
| 5479 |
|
| 5480 |
-- We can distinguish the two cases by seeing whether the accept statement |
| 5481 |
-- is part of a list. If not, then it must be in an accept alternative. |
| 5482 |
|
| 5483 |
-- To expand the requeue statement, a label is provided at the end of the |
| 5484 |
-- accept statement or alternative of which it is a part, so that the |
| 5485 |
-- statement can be skipped after the requeue is complete. This label is |
| 5486 |
-- created here rather than during the expansion of the accept statement, |
| 5487 |
-- because it will be needed by any requeue statements within the accept, |
| 5488 |
-- which are expanded before the accept. |
| 5489 |
|
| 5490 |
procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is |
| 5491 |
Loc : constant Source_Ptr := Sloc (N); |
| 5492 |
Stats : constant Node_Id := Handled_Statement_Sequence (N); |
| 5493 |
Ann : Entity_Id := Empty; |
| 5494 |
Adecl : Node_Id; |
| 5495 |
Lab : Node_Id; |
| 5496 |
Ldecl : Node_Id; |
| 5497 |
Ldecl2 : Node_Id; |
| 5498 |
|
| 5499 |
begin |
| 5500 |
if Expander_Active then |
| 5501 |
|
| 5502 |
-- If we have no handled statement sequence, we may need to build |
| 5503 |
-- a dummy sequence consisting of a null statement. This can be |
| 5504 |
-- skipped if the trivial accept optimization is permitted. |
| 5505 |
|
| 5506 |
if not Trivial_Accept_OK |
| 5507 |
and then (No (Stats) or else Null_Statements (Statements (Stats))) |
| 5508 |
then |
| 5509 |
Set_Handled_Statement_Sequence (N, |
| 5510 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 5511 |
Statements => New_List (Make_Null_Statement (Loc)))); |
| 5512 |
end if; |
| 5513 |
|
| 5514 |
-- Create and declare two labels to be placed at the end of the |
| 5515 |
-- accept statement. The first label is used to allow requeues to |
| 5516 |
-- skip the remainder of entry processing. The second label is used |
| 5517 |
-- to skip the remainder of entry processing if the rendezvous |
| 5518 |
-- completes in the middle of the accept body. |
| 5519 |
|
| 5520 |
if Present (Handled_Statement_Sequence (N)) then |
| 5521 |
declare |
| 5522 |
Ent : Entity_Id; |
| 5523 |
|
| 5524 |
begin |
| 5525 |
Ent := Make_Temporary (Loc, 'L'); |
| 5526 |
Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc)); |
| 5527 |
Ldecl := |
| 5528 |
Make_Implicit_Label_Declaration (Loc, |
| 5529 |
Defining_Identifier => Ent, |
| 5530 |
Label_Construct => Lab); |
| 5531 |
Append (Lab, Statements (Handled_Statement_Sequence (N))); |
| 5532 |
|
| 5533 |
Ent := Make_Temporary (Loc, 'L'); |
| 5534 |
Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc)); |
| 5535 |
Ldecl2 := |
| 5536 |
Make_Implicit_Label_Declaration (Loc, |
| 5537 |
Defining_Identifier => Ent, |
| 5538 |
Label_Construct => Lab); |
| 5539 |
Append (Lab, Statements (Handled_Statement_Sequence (N))); |
| 5540 |
end; |
| 5541 |
|
| 5542 |
else |
| 5543 |
Ldecl := Empty; |
| 5544 |
Ldecl2 := Empty; |
| 5545 |
end if; |
| 5546 |
|
| 5547 |
-- Case of stand alone accept statement |
| 5548 |
|
| 5549 |
if Is_List_Member (N) then |
| 5550 |
|
| 5551 |
if Present (Handled_Statement_Sequence (N)) then |
| 5552 |
Ann := Make_Temporary (Loc, 'A'); |
| 5553 |
|
| 5554 |
Adecl := |
| 5555 |
Make_Object_Declaration (Loc, |
| 5556 |
Defining_Identifier => Ann, |
| 5557 |
Object_Definition => |
| 5558 |
New_Occurrence_Of (RTE (RE_Address), Loc)); |
| 5559 |
|
| 5560 |
Insert_Before_And_Analyze (N, Adecl); |
| 5561 |
Insert_Before_And_Analyze (N, Ldecl); |
| 5562 |
Insert_Before_And_Analyze (N, Ldecl2); |
| 5563 |
end if; |
| 5564 |
|
| 5565 |
-- Case of accept statement which is in an accept alternative |
| 5566 |
|
| 5567 |
else |
| 5568 |
declare |
| 5569 |
Acc_Alt : constant Node_Id := Parent (N); |
| 5570 |
Sel_Acc : constant Node_Id := Parent (Acc_Alt); |
| 5571 |
Alt : Node_Id; |
| 5572 |
|
| 5573 |
begin |
| 5574 |
pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative); |
| 5575 |
pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept); |
| 5576 |
|
| 5577 |
-- ??? Consider a single label for select statements |
| 5578 |
|
| 5579 |
if Present (Handled_Statement_Sequence (N)) then |
| 5580 |
Prepend (Ldecl2, |
| 5581 |
Statements (Handled_Statement_Sequence (N))); |
| 5582 |
Analyze (Ldecl2); |
| 5583 |
|
| 5584 |
Prepend (Ldecl, |
| 5585 |
Statements (Handled_Statement_Sequence (N))); |
| 5586 |
Analyze (Ldecl); |
| 5587 |
end if; |
| 5588 |
|
| 5589 |
-- Find first accept alternative of the selective accept. A |
| 5590 |
-- valid selective accept must have at least one accept in it. |
| 5591 |
|
| 5592 |
Alt := First (Select_Alternatives (Sel_Acc)); |
| 5593 |
|
| 5594 |
while Nkind (Alt) /= N_Accept_Alternative loop |
| 5595 |
Next (Alt); |
| 5596 |
end loop; |
| 5597 |
|
| 5598 |
-- If this is the first accept statement, then we have to |
| 5599 |
-- create the Ann variable, as for the stand alone case, except |
| 5600 |
-- that it is inserted before the selective accept. Similarly, |
| 5601 |
-- a label for requeue expansion must be declared. |
| 5602 |
|
| 5603 |
if N = Accept_Statement (Alt) then |
| 5604 |
Ann := Make_Temporary (Loc, 'A'); |
| 5605 |
Adecl := |
| 5606 |
Make_Object_Declaration (Loc, |
| 5607 |
Defining_Identifier => Ann, |
| 5608 |
Object_Definition => |
| 5609 |
New_Occurrence_Of (RTE (RE_Address), Loc)); |
| 5610 |
|
| 5611 |
Insert_Before_And_Analyze (Sel_Acc, Adecl); |
| 5612 |
|
| 5613 |
-- If this is not the first accept statement, then find the Ann |
| 5614 |
-- variable allocated by the first accept and use it. |
| 5615 |
|
| 5616 |
else |
| 5617 |
Ann := |
| 5618 |
Node (Last_Elmt (Accept_Address |
| 5619 |
(Entity (Entry_Direct_Name (Accept_Statement (Alt)))))); |
| 5620 |
end if; |
| 5621 |
end; |
| 5622 |
end if; |
| 5623 |
|
| 5624 |
-- Merge here with Ann either created or referenced, and Adecl |
| 5625 |
-- pointing to the corresponding declaration. Remaining processing |
| 5626 |
-- is the same for the two cases. |
| 5627 |
|
| 5628 |
if Present (Ann) then |
| 5629 |
Append_Elmt (Ann, Accept_Address (Ent)); |
| 5630 |
Set_Debug_Info_Needed (Ann); |
| 5631 |
end if; |
| 5632 |
|
| 5633 |
-- Create renaming declarations for the entry formals. Each reference |
| 5634 |
-- to a formal becomes a dereference of a component of the parameter |
| 5635 |
-- block, whose address is held in Ann. These declarations are |
| 5636 |
-- eventually inserted into the accept block, and analyzed there so |
| 5637 |
-- that they have the proper scope for gdb and do not conflict with |
| 5638 |
-- other declarations. |
| 5639 |
|
| 5640 |
if Present (Parameter_Specifications (N)) |
| 5641 |
and then Present (Handled_Statement_Sequence (N)) |
| 5642 |
then |
| 5643 |
declare |
| 5644 |
Comp : Entity_Id; |
| 5645 |
Decl : Node_Id; |
| 5646 |
Formal : Entity_Id; |
| 5647 |
New_F : Entity_Id; |
| 5648 |
Renamed_Formal : Node_Id; |
| 5649 |
|
| 5650 |
begin |
| 5651 |
Push_Scope (Ent); |
| 5652 |
Formal := First_Formal (Ent); |
| 5653 |
|
| 5654 |
while Present (Formal) loop |
| 5655 |
Comp := Entry_Component (Formal); |
| 5656 |
New_F := Make_Defining_Identifier (Loc, Chars (Formal)); |
| 5657 |
|
| 5658 |
Set_Etype (New_F, Etype (Formal)); |
| 5659 |
Set_Scope (New_F, Ent); |
| 5660 |
|
| 5661 |
-- Now we set debug info needed on New_F even though it does |
| 5662 |
-- not come from source, so that the debugger will get the |
| 5663 |
-- right information for these generated names. |
| 5664 |
|
| 5665 |
Set_Debug_Info_Needed (New_F); |
| 5666 |
|
| 5667 |
if Ekind (Formal) = E_In_Parameter then |
| 5668 |
Mutate_Ekind (New_F, E_Constant); |
| 5669 |
else |
| 5670 |
Mutate_Ekind (New_F, E_Variable); |
| 5671 |
Set_Extra_Constrained (New_F, Extra_Constrained (Formal)); |
| 5672 |
end if; |
| 5673 |
|
| 5674 |
Set_Actual_Subtype (New_F, Actual_Subtype (Formal)); |
| 5675 |
|
| 5676 |
Renamed_Formal := |
| 5677 |
Make_Selected_Component (Loc, |
| 5678 |
Prefix => |
| 5679 |
Make_Explicit_Dereference (Loc, |
| 5680 |
Unchecked_Convert_To ( |
| 5681 |
Entry_Parameters_Type (Ent), |
| 5682 |
New_Occurrence_Of (Ann, Loc))), |
| 5683 |
Selector_Name => |
| 5684 |
New_Occurrence_Of (Comp, Loc)); |
| 5685 |
|
| 5686 |
Decl := |
| 5687 |
Build_Renamed_Formal_Declaration |
| 5688 |
(New_F, Formal, Comp, Renamed_Formal); |
| 5689 |
|
| 5690 |
if No (Declarations (N)) then |
| 5691 |
Set_Declarations (N, New_List); |
| 5692 |
end if; |
| 5693 |
|
| 5694 |
Append (Decl, Declarations (N)); |
| 5695 |
Set_Renamed_Object (Formal, New_F); |
| 5696 |
Next_Formal (Formal); |
| 5697 |
end loop; |
| 5698 |
|
| 5699 |
End_Scope; |
| 5700 |
end; |
| 5701 |
end if; |
| 5702 |
end if; |
| 5703 |
end Expand_Accept_Declarations; |
| 5704 |
|
| 5705 |
--------------------------------------------- |
| 5706 |
-- Expand_Access_Protected_Subprogram_Type -- |
| 5707 |
--------------------------------------------- |
| 5708 |
|
| 5709 |
procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is |
| 5710 |
Loc : constant Source_Ptr := Sloc (N); |
| 5711 |
T : constant Entity_Id := Defining_Identifier (N); |
| 5712 |
D_T : constant Entity_Id := Designated_Type (T); |
| 5713 |
D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D'); |
| 5714 |
E_T : constant Entity_Id := Make_Temporary (Loc, 'E'); |
| 5715 |
P_List : constant List_Id := |
| 5716 |
Build_Protected_Spec (N, RTE (RE_Address), D_T, False); |
| 5717 |
|
| 5718 |
Comps : List_Id; |
| 5719 |
Decl1 : Node_Id; |
| 5720 |
Decl2 : Node_Id; |
| 5721 |
Def1 : Node_Id; |
| 5722 |
|
| 5723 |
begin |
| 5724 |
-- Create access to subprogram with full signature |
| 5725 |
|
| 5726 |
if Etype (D_T) /= Standard_Void_Type then |
| 5727 |
Def1 := |
| 5728 |
Make_Access_Function_Definition (Loc, |
| 5729 |
Parameter_Specifications => P_List, |
| 5730 |
Result_Definition => |
| 5731 |
Copy_Result_Type (Result_Definition (Type_Definition (N)))); |
| 5732 |
|
| 5733 |
else |
| 5734 |
Def1 := |
| 5735 |
Make_Access_Procedure_Definition (Loc, |
| 5736 |
Parameter_Specifications => P_List); |
| 5737 |
end if; |
| 5738 |
|
| 5739 |
Decl1 := |
| 5740 |
Make_Full_Type_Declaration (Loc, |
| 5741 |
Defining_Identifier => D_T2, |
| 5742 |
Type_Definition => Def1); |
| 5743 |
|
| 5744 |
-- Declare the new types before the original one since the latter will |
| 5745 |
-- refer to them through the Equivalent_Type slot. |
| 5746 |
|
| 5747 |
Insert_Before_And_Analyze (N, Decl1); |
| 5748 |
|
| 5749 |
-- Associate the access to subprogram with its original access to |
| 5750 |
-- protected subprogram type. Needed by the backend to know that this |
| 5751 |
-- type corresponds with an access to protected subprogram type. |
| 5752 |
|
| 5753 |
Set_Original_Access_Type (D_T2, T); |
| 5754 |
|
| 5755 |
-- Create Equivalent_Type, a record with two components for an access to |
| 5756 |
-- object and an access to subprogram. |
| 5757 |
|
| 5758 |
Comps := New_List ( |
| 5759 |
Make_Component_Declaration (Loc, |
| 5760 |
Defining_Identifier => Make_Temporary (Loc, 'P'), |
| 5761 |
Component_Definition => |
| 5762 |
Make_Component_Definition (Loc, |
| 5763 |
Subtype_Indication => |
| 5764 |
New_Occurrence_Of (RTE (RE_Address), Loc))), |
| 5765 |
|
| 5766 |
Make_Component_Declaration (Loc, |
| 5767 |
Defining_Identifier => Make_Temporary (Loc, 'S'), |
| 5768 |
Component_Definition => |
| 5769 |
Make_Component_Definition (Loc, |
| 5770 |
Subtype_Indication => New_Occurrence_Of (D_T2, Loc)))); |
| 5771 |
|
| 5772 |
Decl2 := |
| 5773 |
Make_Full_Type_Declaration (Loc, |
| 5774 |
Defining_Identifier => E_T, |
| 5775 |
Type_Definition => |
| 5776 |
Make_Record_Definition (Loc, |
| 5777 |
Component_List => |
| 5778 |
Make_Component_List (Loc, Component_Items => Comps))); |
| 5779 |
|
| 5780 |
Insert_Before_And_Analyze (N, Decl2); |
| 5781 |
Set_Equivalent_Type (T, E_T); |
| 5782 |
end Expand_Access_Protected_Subprogram_Type; |
| 5783 |
|
| 5784 |
-------------------------- |
| 5785 |
-- Expand_Entry_Barrier -- |
| 5786 |
-------------------------- |
| 5787 |
|
| 5788 |
procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is |
| 5789 |
Cond : constant Node_Id := Condition (Entry_Body_Formal_Part (N)); |
| 5790 |
Prot : constant Entity_Id := Scope (Ent); |
| 5791 |
Spec_Decl : constant Node_Id := Parent (Prot); |
| 5792 |
|
| 5793 |
Func_Id : Entity_Id := Empty; |
| 5794 |
-- The entity of the barrier function |
| 5795 |
|
| 5796 |
function Is_Global_Entity (N : Node_Id) return Traverse_Result; |
| 5797 |
-- Check whether entity in Barrier is external to protected type. |
| 5798 |
-- If so, barrier may not be properly synchronized. |
| 5799 |
|
| 5800 |
function Is_Pure_Barrier (N : Node_Id) return Traverse_Result; |
| 5801 |
-- Check whether N meets the Pure_Barriers restriction. Return OK if |
| 5802 |
-- so. |
| 5803 |
|
| 5804 |
function Is_Simple_Barrier (N : Node_Id) return Boolean; |
| 5805 |
-- Check whether N meets the Simple_Barriers restriction. Return OK if |
| 5806 |
-- so. |
| 5807 |
|
| 5808 |
---------------------- |
| 5809 |
-- Is_Global_Entity -- |
| 5810 |
---------------------- |
| 5811 |
|
| 5812 |
function Is_Global_Entity (N : Node_Id) return Traverse_Result is |
| 5813 |
E : Entity_Id; |
| 5814 |
S : Entity_Id; |
| 5815 |
|
| 5816 |
begin |
| 5817 |
if Is_Entity_Name (N) and then Present (Entity (N)) then |
| 5818 |
E := Entity (N); |
| 5819 |
S := Scope (E); |
| 5820 |
|
| 5821 |
if Ekind (E) = E_Variable then |
| 5822 |
|
| 5823 |
-- If the variable is local to the barrier function generated |
| 5824 |
-- during expansion, it is ok. If expansion is not performed, |
| 5825 |
-- then Func is Empty so this test cannot succeed. |
| 5826 |
|
| 5827 |
if Scope_Within_Or_Same (S, Func_Id) then |
| 5828 |
null; |
| 5829 |
|
| 5830 |
-- A protected call from a barrier to another object is ok |
| 5831 |
|
| 5832 |
elsif Ekind (Etype (E)) = E_Protected_Type then |
| 5833 |
null; |
| 5834 |
|
| 5835 |
-- If the variable is within the package body we consider |
| 5836 |
-- this safe. This is a common (if dubious) idiom. |
| 5837 |
|
| 5838 |
elsif S = Scope (Prot) |
| 5839 |
and then Is_Package_Or_Generic_Package (S) |
| 5840 |
and then Nkind (Parent (E)) = N_Object_Declaration |
| 5841 |
and then Nkind (Parent (Parent (E))) = N_Package_Body |
| 5842 |
then |
| 5843 |
null; |
| 5844 |
|
| 5845 |
else |
| 5846 |
Error_Msg_N ("potentially unsynchronized barrier??", N); |
| 5847 |
Error_Msg_N ("\& should be private component of type??", N); |
| 5848 |
end if; |
| 5849 |
end if; |
| 5850 |
end if; |
| 5851 |
|
| 5852 |
return OK; |
| 5853 |
end Is_Global_Entity; |
| 5854 |
|
| 5855 |
procedure Check_Unprotected_Barrier is |
| 5856 |
new Traverse_Proc (Is_Global_Entity); |
| 5857 |
|
| 5858 |
----------------------- |
| 5859 |
-- Is_Simple_Barrier -- |
| 5860 |
----------------------- |
| 5861 |
|
| 5862 |
function Is_Simple_Barrier (N : Node_Id) return Boolean is |
| 5863 |
Renamed : Node_Id; |
| 5864 |
|
| 5865 |
begin |
| 5866 |
if Is_Static_Expression (N) then |
| 5867 |
return True; |
| 5868 |
elsif Ada_Version >= Ada_2022 |
| 5869 |
and then Nkind (N) in N_Selected_Component | N_Indexed_Component |
| 5870 |
and then Statically_Names_Object (N) |
| 5871 |
then |
| 5872 |
-- Restriction relaxed in Ada 2022 to allow statically named |
| 5873 |
-- subcomponents. |
| 5874 |
return Is_Simple_Barrier (Prefix (N)); |
| 5875 |
end if; |
| 5876 |
|
| 5877 |
-- Check if the name is a component of the protected object. If |
| 5878 |
-- the expander is active, the component has been transformed into a |
| 5879 |
-- renaming of _object.all.component. Original_Node is needed in case |
| 5880 |
-- validity checking is enabled, in which case the simple object |
| 5881 |
-- reference will have been rewritten. |
| 5882 |
|
| 5883 |
if Expander_Active then |
| 5884 |
|
| 5885 |
-- The expanded name may have been constant folded in which case |
| 5886 |
-- the original node is not necessarily an entity name (e.g. an |
| 5887 |
-- indexed component). |
| 5888 |
|
| 5889 |
if not Is_Entity_Name (Original_Node (N)) then |
| 5890 |
return False; |
| 5891 |
end if; |
| 5892 |
|
| 5893 |
Renamed := Renamed_Object (Entity (Original_Node (N))); |
| 5894 |
|
| 5895 |
return |
| 5896 |
Present (Renamed) |
| 5897 |
and then Nkind (Renamed) = N_Selected_Component |
| 5898 |
and then Chars (Prefix (Prefix (Renamed))) = Name_uObject; |
| 5899 |
elsif not Is_Entity_Name (N) then |
| 5900 |
return False; |
| 5901 |
else |
| 5902 |
return Is_Protected_Component (Entity (N)); |
| 5903 |
end if; |
| 5904 |
end Is_Simple_Barrier; |
| 5905 |
|
| 5906 |
--------------------- |
| 5907 |
-- Is_Pure_Barrier -- |
| 5908 |
--------------------- |
| 5909 |
|
| 5910 |
function Is_Pure_Barrier (N : Node_Id) return Traverse_Result is |
| 5911 |
begin |
| 5912 |
case Nkind (N) is |
| 5913 |
when N_Expanded_Name |
| 5914 |
| N_Identifier |
| 5915 |
=> |
| 5916 |
|
| 5917 |
-- Because of N_Expanded_Name case, return Skip instead of OK. |
| 5918 |
|
| 5919 |
if No (Entity (N)) then |
| 5920 |
return Abandon; |
| 5921 |
|
| 5922 |
elsif Is_Numeric_Type (Entity (N)) then |
| 5923 |
return Skip; |
| 5924 |
end if; |
| 5925 |
|
| 5926 |
case Ekind (Entity (N)) is |
| 5927 |
when E_Constant |
| 5928 |
| E_Discriminant |
| 5929 |
=> |
| 5930 |
return Skip; |
| 5931 |
|
| 5932 |
when E_Enumeration_Literal |
| 5933 |
| E_Named_Integer |
| 5934 |
| E_Named_Real |
| 5935 |
=> |
| 5936 |
if not Is_OK_Static_Expression (N) then |
| 5937 |
return Abandon; |
| 5938 |
end if; |
| 5939 |
return Skip; |
| 5940 |
|
| 5941 |
when E_Component => |
| 5942 |
return Skip; |
| 5943 |
|
| 5944 |
when E_Variable => |
| 5945 |
if Is_Simple_Barrier (N) then |
| 5946 |
return Skip; |
| 5947 |
end if; |
| 5948 |
|
| 5949 |
when E_Function => |
| 5950 |
|
| 5951 |
-- The count attribute has been transformed into run-time |
| 5952 |
-- calls. |
| 5953 |
|
| 5954 |
if Is_RTE (Entity (N), RE_Protected_Count) |
| 5955 |
or else Is_RTE (Entity (N), RE_Protected_Count_Entry) |
| 5956 |
then |
| 5957 |
return Skip; |
| 5958 |
end if; |
| 5959 |
|
| 5960 |
when others => |
| 5961 |
null; |
| 5962 |
end case; |
| 5963 |
|
| 5964 |
when N_Function_Call => |
| 5965 |
|
| 5966 |
-- Function call checks are carried out as part of the analysis |
| 5967 |
-- of the function call name. |
| 5968 |
|
| 5969 |
return OK; |
| 5970 |
|
| 5971 |
when N_Character_Literal |
| 5972 |
| N_Integer_Literal |
| 5973 |
| N_Real_Literal |
| 5974 |
=> |
| 5975 |
return OK; |
| 5976 |
|
| 5977 |
when N_Op_Boolean |
| 5978 |
| N_Op_Not |
| 5979 |
=> |
| 5980 |
if Ekind (Entity (N)) = E_Operator then |
| 5981 |
return OK; |
| 5982 |
end if; |
| 5983 |
|
| 5984 |
when N_Short_Circuit |
| 5985 |
| N_If_Expression |
| 5986 |
| N_Case_Expression |
| 5987 |
=> |
| 5988 |
return OK; |
| 5989 |
|
| 5990 |
when N_Indexed_Component | N_Selected_Component => |
| 5991 |
if Statically_Names_Object (N) then |
| 5992 |
return Is_Pure_Barrier (Prefix (N)); |
| 5993 |
else |
| 5994 |
return Abandon; |
| 5995 |
end if; |
| 5996 |
|
| 5997 |
when N_Case_Expression_Alternative => |
| 5998 |
-- do not traverse Discrete_Choices subtree |
| 5999 |
if Is_Pure_Barrier (Expression (N)) /= Abandon then |
| 6000 |
return Skip; |
| 6001 |
end if; |
| 6002 |
|
| 6003 |
when N_Expression_With_Actions => |
| 6004 |
-- this may occur in the case of a Count attribute reference |
| 6005 |
if Is_Rewrite_Substitution (N) |
| 6006 |
and then Is_Pure_Barrier (Original_Node (N)) /= Abandon |
| 6007 |
then |
| 6008 |
return Skip; |
| 6009 |
end if; |
| 6010 |
|
| 6011 |
when N_Membership_Test => |
| 6012 |
if Is_Pure_Barrier (Left_Opnd (N)) /= Abandon |
| 6013 |
and then All_Membership_Choices_Static (N) |
| 6014 |
then |
| 6015 |
return Skip; |
| 6016 |
end if; |
| 6017 |
|
| 6018 |
when N_Type_Conversion => |
| 6019 |
|
| 6020 |
-- Conversions to Universal_Integer do not raise constraint |
| 6021 |
-- errors. Likewise if the expression's type is statically |
| 6022 |
-- compatible with the target's type. |
| 6023 |
|
| 6024 |
if Etype (N) = Universal_Integer |
| 6025 |
or else Subtypes_Statically_Compatible |
| 6026 |
(Etype (Expression (N)), Etype (N)) |
| 6027 |
then |
| 6028 |
return OK; |
| 6029 |
end if; |
| 6030 |
|
| 6031 |
when N_Unchecked_Type_Conversion => |
| 6032 |
return OK; |
| 6033 |
|
| 6034 |
when others => |
| 6035 |
null; |
| 6036 |
end case; |
| 6037 |
|
| 6038 |
return Abandon; |
| 6039 |
end Is_Pure_Barrier; |
| 6040 |
|
| 6041 |
function Check_Pure_Barriers is new Traverse_Func (Is_Pure_Barrier); |
| 6042 |
|
| 6043 |
-- Local variables |
| 6044 |
|
| 6045 |
Entry_Body : Node_Id; |
| 6046 |
Func_Body : Node_Id := Empty; |
| 6047 |
|
| 6048 |
-- Start of processing for Expand_Entry_Barrier |
| 6049 |
|
| 6050 |
begin |
| 6051 |
if No_Run_Time_Mode then |
| 6052 |
Error_Msg_CRT ("entry barrier", N); |
| 6053 |
return; |
| 6054 |
end if; |
| 6055 |
|
| 6056 |
-- Prevent cascaded errors |
| 6057 |
|
| 6058 |
if Nkind (Cond) = N_Error then |
| 6059 |
return; |
| 6060 |
end if; |
| 6061 |
|
| 6062 |
-- The body of the entry barrier must be analyzed in the context of the |
| 6063 |
-- protected object, but its scope is external to it, just as any other |
| 6064 |
-- unprotected version of a protected operation. The specification has |
| 6065 |
-- been produced when the protected type declaration was elaborated. We |
| 6066 |
-- build the body, insert it in the enclosing scope, but analyze it in |
| 6067 |
-- the current context. A more uniform approach would be to treat the |
| 6068 |
-- barrier just as a protected function, and discard the protected |
| 6069 |
-- version of it because it is never called. |
| 6070 |
|
| 6071 |
if Expander_Active then |
| 6072 |
Func_Body := Build_Barrier_Function (N, Ent, Prot); |
| 6073 |
Func_Id := Barrier_Function (Ent); |
| 6074 |
Set_Corresponding_Spec (Func_Body, Func_Id); |
| 6075 |
|
| 6076 |
Entry_Body := Parent (Corresponding_Body (Spec_Decl)); |
| 6077 |
|
| 6078 |
if Nkind (Parent (Entry_Body)) = N_Subunit then |
| 6079 |
Entry_Body := Corresponding_Stub (Parent (Entry_Body)); |
| 6080 |
end if; |
| 6081 |
|
| 6082 |
Insert_Before_And_Analyze (Entry_Body, Func_Body); |
| 6083 |
|
| 6084 |
Set_Discriminals (Spec_Decl); |
| 6085 |
Set_Scope (Func_Id, Scope (Prot)); |
| 6086 |
|
| 6087 |
else |
| 6088 |
Analyze_And_Resolve (Cond, Any_Boolean); |
| 6089 |
end if; |
| 6090 |
|
| 6091 |
-- Check Simple_Barriers and Pure_Barriers restrictions. |
| 6092 |
-- Note that it is safe to be calling Check_Restriction from here, even |
| 6093 |
-- though this is part of the expander, since Expand_Entry_Barrier is |
| 6094 |
-- called from Sem_Ch9 even in -gnatc mode. |
| 6095 |
|
| 6096 |
if not Is_Simple_Barrier (Cond) then |
| 6097 |
-- flag restriction violation |
| 6098 |
Check_Restriction (Simple_Barriers, Cond); |
| 6099 |
end if; |
| 6100 |
|
| 6101 |
if Check_Pure_Barriers (Cond) = Abandon then |
| 6102 |
-- flag restriction violation |
| 6103 |
Check_Restriction (Pure_Barriers, Cond); |
| 6104 |
|
| 6105 |
-- Emit warning if barrier contains global entities and is thus |
| 6106 |
-- potentially unsynchronized (if Pure_Barriers restrictions |
| 6107 |
-- are met then no need to check for this). |
| 6108 |
Check_Unprotected_Barrier (Cond); |
| 6109 |
end if; |
| 6110 |
|
| 6111 |
-- Perform a small optimization of simple barrier functions. If the |
| 6112 |
-- scope of the condition's entity is not the barrier function, then |
| 6113 |
-- the condition does not depend on any of the generated renamings. |
| 6114 |
-- If this is the case, eliminate the renamings as they are useless. |
| 6115 |
-- This optimization is not performed when the condition was folded |
| 6116 |
-- and validity checks are in effect because the original condition |
| 6117 |
-- may have produced at least one check that depends on the generated |
| 6118 |
-- renamings. |
| 6119 |
|
| 6120 |
if Expander_Active |
| 6121 |
and then Is_Entity_Name (Cond) |
| 6122 |
and then Scope (Entity (Cond)) /= Func_Id |
| 6123 |
and then not Validity_Check_Operands |
| 6124 |
then |
| 6125 |
Set_Declarations (Func_Body, Empty_List); |
| 6126 |
end if; |
| 6127 |
end Expand_Entry_Barrier; |
| 6128 |
|
| 6129 |
------------------------------ |
| 6130 |
-- Expand_N_Abort_Statement -- |
| 6131 |
------------------------------ |
| 6132 |
|
| 6133 |
-- Expand abort T1, T2, .. Tn; into: |
| 6134 |
-- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...)) |
| 6135 |
|
| 6136 |
procedure Expand_N_Abort_Statement (N : Node_Id) is |
| 6137 |
Loc : constant Source_Ptr := Sloc (N); |
| 6138 |
Tlist : constant List_Id := Names (N); |
| 6139 |
Count : Nat; |
| 6140 |
Aggr : Node_Id; |
| 6141 |
Tasknm : Node_Id; |
| 6142 |
|
| 6143 |
begin |
| 6144 |
Aggr := Make_Aggregate (Loc, Component_Associations => New_List); |
| 6145 |
Count := 0; |
| 6146 |
|
| 6147 |
Tasknm := First (Tlist); |
| 6148 |
|
| 6149 |
while Present (Tasknm) loop |
| 6150 |
Count := Count + 1; |
| 6151 |
|
| 6152 |
-- A task interface class-wide type object is being aborted. Retrieve |
| 6153 |
-- its _task_id by calling a dispatching routine. |
| 6154 |
|
| 6155 |
if Ada_Version >= Ada_2005 |
| 6156 |
and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type |
| 6157 |
and then Is_Interface (Etype (Tasknm)) |
| 6158 |
and then Is_Task_Interface (Etype (Tasknm)) |
| 6159 |
then |
| 6160 |
Append_To (Component_Associations (Aggr), |
| 6161 |
Make_Component_Association (Loc, |
| 6162 |
Choices => New_List (Make_Integer_Literal (Loc, Count)), |
| 6163 |
Expression => |
| 6164 |
|
| 6165 |
-- Task_Id (Tasknm._disp_get_task_id) |
| 6166 |
|
| 6167 |
Unchecked_Convert_To |
| 6168 |
(RTE (RO_ST_Task_Id), |
| 6169 |
Make_Selected_Component (Loc, |
| 6170 |
Prefix => New_Copy_Tree (Tasknm), |
| 6171 |
Selector_Name => |
| 6172 |
Make_Identifier (Loc, Name_uDisp_Get_Task_Id))))); |
| 6173 |
|
| 6174 |
else |
| 6175 |
Append_To (Component_Associations (Aggr), |
| 6176 |
Make_Component_Association (Loc, |
| 6177 |
Choices => New_List (Make_Integer_Literal (Loc, Count)), |
| 6178 |
Expression => Concurrent_Ref (Tasknm))); |
| 6179 |
end if; |
| 6180 |
|
| 6181 |
Next (Tasknm); |
| 6182 |
end loop; |
| 6183 |
|
| 6184 |
Rewrite (N, |
| 6185 |
Make_Procedure_Call_Statement (Loc, |
| 6186 |
Name => New_Occurrence_Of (RTE (RE_Abort_Tasks), Loc), |
| 6187 |
Parameter_Associations => New_List ( |
| 6188 |
Make_Qualified_Expression (Loc, |
| 6189 |
Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_List), Loc), |
| 6190 |
Expression => Aggr)))); |
| 6191 |
|
| 6192 |
Analyze (N); |
| 6193 |
end Expand_N_Abort_Statement; |
| 6194 |
|
| 6195 |
------------------------------- |
| 6196 |
-- Expand_N_Accept_Statement -- |
| 6197 |
------------------------------- |
| 6198 |
|
| 6199 |
-- This procedure handles expansion of accept statements that stand alone, |
| 6200 |
-- i.e. they are not part of an accept alternative. The expansion of |
| 6201 |
-- accept statement in accept alternatives is handled by the routines |
| 6202 |
-- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The |
| 6203 |
-- following description applies only to stand alone accept statements. |
| 6204 |
|
| 6205 |
-- If there is no handled statement sequence, or only null statements, then |
| 6206 |
-- this is called a trivial accept, and the expansion is: |
| 6207 |
|
| 6208 |
-- Accept_Trivial (entry-index) |
| 6209 |
|
| 6210 |
-- If there is a handled statement sequence, then the expansion is: |
| 6211 |
|
| 6212 |
-- Ann : Address; |
| 6213 |
-- {Lnn : Label} |
| 6214 |
|
| 6215 |
-- begin |
| 6216 |
-- begin |
| 6217 |
-- Accept_Call (entry-index, Ann); |
| 6218 |
-- Renaming_Declarations for formals |
| 6219 |
-- <statement sequence from N_Accept_Statement node> |
| 6220 |
-- Complete_Rendezvous; |
| 6221 |
-- <<Lnn>> |
| 6222 |
-- |
| 6223 |
-- exception |
| 6224 |
-- when ... => |
| 6225 |
-- <exception handler from N_Accept_Statement node> |
| 6226 |
-- Complete_Rendezvous; |
| 6227 |
-- when ... => |
| 6228 |
-- <exception handler from N_Accept_Statement node> |
| 6229 |
-- Complete_Rendezvous; |
| 6230 |
-- ... |
| 6231 |
-- end; |
| 6232 |
|
| 6233 |
-- exception |
| 6234 |
-- when all others => |
| 6235 |
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); |
| 6236 |
-- end; |
| 6237 |
|
| 6238 |
-- The first three declarations were already inserted ahead of the accept |
| 6239 |
-- statement by the Expand_Accept_Declarations procedure, which was called |
| 6240 |
-- directly from the semantics during analysis of the accept statement, |
| 6241 |
-- before analyzing its contained statements. |
| 6242 |
|
| 6243 |
-- The declarations from the N_Accept_Statement, as noted in Sinfo, come |
| 6244 |
-- from possible expansion activity (the original source of course does |
| 6245 |
-- not have any declarations associated with the accept statement, since |
| 6246 |
-- an accept statement has no declarative part). In particular, if the |
| 6247 |
-- expander is active, the first such declaration is the declaration of |
| 6248 |
-- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement). |
| 6249 |
|
| 6250 |
-- The two blocks are merged into a single block if the inner block has |
| 6251 |
-- no exception handlers, but otherwise two blocks are required, since |
| 6252 |
-- exceptions might be raised in the exception handlers of the inner |
| 6253 |
-- block, and Exceptional_Complete_Rendezvous must be called. |
| 6254 |
|
| 6255 |
procedure Expand_N_Accept_Statement (N : Node_Id) is |
| 6256 |
Loc : constant Source_Ptr := Sloc (N); |
| 6257 |
Stats : constant Node_Id := Handled_Statement_Sequence (N); |
| 6258 |
Ename : constant Node_Id := Entry_Direct_Name (N); |
| 6259 |
Eindx : constant Node_Id := Entry_Index (N); |
| 6260 |
Eent : constant Entity_Id := Entity (Ename); |
| 6261 |
Acstack : constant Elist_Id := Accept_Address (Eent); |
| 6262 |
Ann : constant Entity_Id := Node (Last_Elmt (Acstack)); |
| 6263 |
Ttyp : constant Entity_Id := Etype (Scope (Eent)); |
| 6264 |
Blkent : Entity_Id; |
| 6265 |
Call : Node_Id; |
| 6266 |
Block : Node_Id; |
| 6267 |
|
| 6268 |
begin |
| 6269 |
-- If the accept statement is not part of a list, then its parent must |
| 6270 |
-- be an accept alternative, and, as described above, we do not do any |
| 6271 |
-- expansion for such accept statements at this level. |
| 6272 |
|
| 6273 |
if not Is_List_Member (N) then |
| 6274 |
pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative); |
| 6275 |
return; |
| 6276 |
|
| 6277 |
-- Trivial accept case (no statement sequence, or null statements). |
| 6278 |
-- If the accept statement has declarations, then just insert them |
| 6279 |
-- before the procedure call. |
| 6280 |
|
| 6281 |
elsif Trivial_Accept_OK |
| 6282 |
and then (No (Stats) or else Null_Statements (Statements (Stats))) |
| 6283 |
then |
| 6284 |
-- Remove declarations for renamings, because the parameter block |
| 6285 |
-- will not be assigned. |
| 6286 |
|
| 6287 |
declare |
| 6288 |
D : Node_Id; |
| 6289 |
Next_D : Node_Id; |
| 6290 |
|
| 6291 |
begin |
| 6292 |
D := First (Declarations (N)); |
| 6293 |
while Present (D) loop |
| 6294 |
Next_D := Next (D); |
| 6295 |
if Nkind (D) = N_Object_Renaming_Declaration then |
| 6296 |
Remove (D); |
| 6297 |
end if; |
| 6298 |
|
| 6299 |
D := Next_D; |
| 6300 |
end loop; |
| 6301 |
end; |
| 6302 |
|
| 6303 |
if Present (Declarations (N)) then |
| 6304 |
Insert_Actions (N, Declarations (N)); |
| 6305 |
end if; |
| 6306 |
|
| 6307 |
Rewrite (N, |
| 6308 |
Make_Procedure_Call_Statement (Loc, |
| 6309 |
Name => New_Occurrence_Of (RTE (RE_Accept_Trivial), Loc), |
| 6310 |
Parameter_Associations => New_List ( |
| 6311 |
Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp)))); |
| 6312 |
|
| 6313 |
Analyze (N); |
| 6314 |
|
| 6315 |
-- Ada 2022 (AI12-0279) |
| 6316 |
|
| 6317 |
if Has_Yield_Aspect (Eent) |
| 6318 |
and then RTE_Available (RE_Yield) |
| 6319 |
then |
| 6320 |
Insert_Action_After (N, |
| 6321 |
Make_Procedure_Call_Statement (Loc, |
| 6322 |
New_Occurrence_Of (RTE (RE_Yield), Loc))); |
| 6323 |
end if; |
| 6324 |
|
| 6325 |
-- Discard Entry_Address that was created for it, so it will not be |
| 6326 |
-- emitted if this accept statement is in the statement part of a |
| 6327 |
-- delay alternative. |
| 6328 |
|
| 6329 |
if Present (Stats) then |
| 6330 |
Remove_Last_Elmt (Acstack); |
| 6331 |
end if; |
| 6332 |
|
| 6333 |
-- Case of statement sequence present |
| 6334 |
|
| 6335 |
else |
| 6336 |
-- Construct the block, using the declarations from the accept |
| 6337 |
-- statement if any to initialize the declarations of the block. |
| 6338 |
|
| 6339 |
Blkent := Make_Temporary (Loc, 'A'); |
| 6340 |
Mutate_Ekind (Blkent, E_Block); |
| 6341 |
Set_Etype (Blkent, Standard_Void_Type); |
| 6342 |
Set_Scope (Blkent, Current_Scope); |
| 6343 |
|
| 6344 |
Block := |
| 6345 |
Make_Block_Statement (Loc, |
| 6346 |
Identifier => New_Occurrence_Of (Blkent, Loc), |
| 6347 |
Declarations => Declarations (N), |
| 6348 |
Handled_Statement_Sequence => Build_Accept_Body (N)); |
| 6349 |
|
| 6350 |
-- Reset the Scope of local entities associated with the accept |
| 6351 |
-- statement (that currently reference the entry scope) to the |
| 6352 |
-- block scope, to avoid having references to the locals treated |
| 6353 |
-- as up-level references. |
| 6354 |
|
| 6355 |
Reset_Scopes_To (Block, Blkent); |
| 6356 |
|
| 6357 |
-- For the analysis of the generated declarations, the parent node |
| 6358 |
-- must be properly set. |
| 6359 |
|
| 6360 |
Set_Parent (Block, Parent (N)); |
| 6361 |
Set_Parent (Blkent, Block); |
| 6362 |
|
| 6363 |
-- Prepend call to Accept_Call to main statement sequence If the |
| 6364 |
-- accept has exception handlers, the statement sequence is wrapped |
| 6365 |
-- in a block. Insert call and renaming declarations in the |
| 6366 |
-- declarations of the block, so they are elaborated before the |
| 6367 |
-- handlers. |
| 6368 |
|
| 6369 |
Call := |
| 6370 |
Make_Procedure_Call_Statement (Loc, |
| 6371 |
Name => New_Occurrence_Of (RTE (RE_Accept_Call), Loc), |
| 6372 |
Parameter_Associations => New_List ( |
| 6373 |
Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp), |
| 6374 |
New_Occurrence_Of (Ann, Loc))); |
| 6375 |
|
| 6376 |
if Parent (Stats) = N then |
| 6377 |
Prepend (Call, Statements (Stats)); |
| 6378 |
else |
| 6379 |
Set_Declarations (Parent (Stats), New_List (Call)); |
| 6380 |
end if; |
| 6381 |
|
| 6382 |
Analyze (Call); |
| 6383 |
|
| 6384 |
Push_Scope (Blkent); |
| 6385 |
|
| 6386 |
declare |
| 6387 |
D : Node_Id; |
| 6388 |
Next_D : Node_Id; |
| 6389 |
Typ : Entity_Id; |
| 6390 |
|
| 6391 |
begin |
| 6392 |
D := First (Declarations (N)); |
| 6393 |
while Present (D) loop |
| 6394 |
Next_D := Next (D); |
| 6395 |
|
| 6396 |
if Nkind (D) = N_Object_Renaming_Declaration then |
| 6397 |
|
| 6398 |
-- The renaming declarations for the formals were created |
| 6399 |
-- during analysis of the accept statement, and attached to |
| 6400 |
-- the list of declarations. Place them now in the context |
| 6401 |
-- of the accept block or subprogram. |
| 6402 |
|
| 6403 |
Remove (D); |
| 6404 |
Typ := Entity (Subtype_Mark (D)); |
| 6405 |
Insert_After (Call, D); |
| 6406 |
Analyze (D); |
| 6407 |
|
| 6408 |
-- If the formal is class_wide, it does not have an actual |
| 6409 |
-- subtype. The analysis of the renaming declaration creates |
| 6410 |
-- one, but we need to retain the class-wide nature of the |
| 6411 |
-- entity. |
| 6412 |
|
| 6413 |
if Is_Class_Wide_Type (Typ) then |
| 6414 |
Set_Etype (Defining_Identifier (D), Typ); |
| 6415 |
end if; |
| 6416 |
|
| 6417 |
end if; |
| 6418 |
|
| 6419 |
D := Next_D; |
| 6420 |
end loop; |
| 6421 |
end; |
| 6422 |
|
| 6423 |
End_Scope; |
| 6424 |
|
| 6425 |
-- Replace the accept statement by the new block |
| 6426 |
|
| 6427 |
Rewrite (N, Block); |
| 6428 |
Analyze (N); |
| 6429 |
|
| 6430 |
-- Last step is to unstack the Accept_Address value |
| 6431 |
|
| 6432 |
Remove_Last_Elmt (Acstack); |
| 6433 |
end if; |
| 6434 |
end Expand_N_Accept_Statement; |
| 6435 |
|
| 6436 |
---------------------------------- |
| 6437 |
-- Expand_N_Asynchronous_Select -- |
| 6438 |
---------------------------------- |
| 6439 |
|
| 6440 |
-- This procedure assumes that the trigger statement is an entry call or |
| 6441 |
-- a dispatching procedure call. A delay alternative should already have |
| 6442 |
-- been expanded into an entry call to the appropriate delay object Wait |
| 6443 |
-- entry. |
| 6444 |
|
| 6445 |
-- If the trigger is a task entry call, the select is implemented with |
| 6446 |
-- a Task_Entry_Call: |
| 6447 |
|
| 6448 |
-- declare |
| 6449 |
-- B : Boolean; |
| 6450 |
-- C : Boolean; |
| 6451 |
-- P : parms := (parm, parm, parm); |
| 6452 |
|
| 6453 |
-- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions |
| 6454 |
|
| 6455 |
-- procedure _clean is |
| 6456 |
-- begin |
| 6457 |
-- ... |
| 6458 |
-- Cancel_Task_Entry_Call (C); |
| 6459 |
-- ... |
| 6460 |
-- end _clean; |
| 6461 |
|
| 6462 |
-- begin |
| 6463 |
-- Abort_Defer; |
| 6464 |
-- Task_Entry_Call |
| 6465 |
-- (<acceptor-task>, -- Acceptor |
| 6466 |
-- <entry-index>, -- E |
| 6467 |
-- P'Address, -- Uninterpreted_Data |
| 6468 |
-- Asynchronous_Call, -- Mode |
| 6469 |
-- B); -- Rendezvous_Successful |
| 6470 |
|
| 6471 |
-- begin |
| 6472 |
-- begin |
| 6473 |
-- Abort_Undefer; |
| 6474 |
-- <abortable-part> |
| 6475 |
-- at end |
| 6476 |
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions |
| 6477 |
-- end; |
| 6478 |
-- exception |
| 6479 |
-- when Abort_Signal => null; |
| 6480 |
-- end; |
| 6481 |
|
| 6482 |
-- parm := P.param; |
| 6483 |
-- parm := P.param; |
| 6484 |
-- ... |
| 6485 |
-- if not C then |
| 6486 |
-- <triggered-statements> |
| 6487 |
-- end if; |
| 6488 |
-- end; |
| 6489 |
|
| 6490 |
-- Note that Build_Simple_Entry_Call is used to expand the entry of the |
| 6491 |
-- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure) |
| 6492 |
-- as follows: |
| 6493 |
|
| 6494 |
-- declare |
| 6495 |
-- P : parms := (parm, parm, parm); |
| 6496 |
-- begin |
| 6497 |
-- Call_Simple (acceptor-task, entry-index, P'Address); |
| 6498 |
-- parm := P.param; |
| 6499 |
-- parm := P.param; |
| 6500 |
-- ... |
| 6501 |
-- end; |
| 6502 |
|
| 6503 |
-- so the task at hand is to convert the latter expansion into the former |
| 6504 |
|
| 6505 |
-- If the trigger is a protected entry call, the select is implemented |
| 6506 |
-- with Protected_Entry_Call: |
| 6507 |
|
| 6508 |
-- declare |
| 6509 |
-- P : E1_Params := (param, param, param); |
| 6510 |
-- Bnn : Communications_Block; |
| 6511 |
|
| 6512 |
-- begin |
| 6513 |
-- declare |
| 6514 |
|
| 6515 |
-- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions |
| 6516 |
|
| 6517 |
-- procedure _clean is |
| 6518 |
-- begin |
| 6519 |
-- ... |
| 6520 |
-- if Enqueued (Bnn) then |
| 6521 |
-- Cancel_Protected_Entry_Call (Bnn); |
| 6522 |
-- end if; |
| 6523 |
-- ... |
| 6524 |
-- end _clean; |
| 6525 |
|
| 6526 |
-- begin |
| 6527 |
-- begin |
| 6528 |
-- Protected_Entry_Call |
| 6529 |
-- (po._object'Access, -- Object |
| 6530 |
-- <entry index>, -- E |
| 6531 |
-- P'Address, -- Uninterpreted_Data |
| 6532 |
-- Asynchronous_Call, -- Mode |
| 6533 |
-- Bnn); -- Block |
| 6534 |
|
| 6535 |
-- if Enqueued (Bnn) then |
| 6536 |
-- <abortable-part> |
| 6537 |
-- end if; |
| 6538 |
-- at end |
| 6539 |
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions |
| 6540 |
-- end; |
| 6541 |
-- exception |
| 6542 |
-- when Abort_Signal => null; |
| 6543 |
-- end; |
| 6544 |
|
| 6545 |
-- if not Cancelled (Bnn) then |
| 6546 |
-- <triggered-statements> |
| 6547 |
-- end if; |
| 6548 |
-- end; |
| 6549 |
|
| 6550 |
-- Build_Simple_Entry_Call is used to expand the all to a simple protected |
| 6551 |
-- entry call: |
| 6552 |
|
| 6553 |
-- declare |
| 6554 |
-- P : E1_Params := (param, param, param); |
| 6555 |
-- Bnn : Communications_Block; |
| 6556 |
|
| 6557 |
-- begin |
| 6558 |
-- Protected_Entry_Call |
| 6559 |
-- (po._object'Access, -- Object |
| 6560 |
-- <entry index>, -- E |
| 6561 |
-- P'Address, -- Uninterpreted_Data |
| 6562 |
-- Simple_Call, -- Mode |
| 6563 |
-- Bnn); -- Block |
| 6564 |
-- parm := P.param; |
| 6565 |
-- parm := P.param; |
| 6566 |
-- ... |
| 6567 |
-- end; |
| 6568 |
|
| 6569 |
-- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is |
| 6570 |
-- expanded into: |
| 6571 |
|
| 6572 |
-- declare |
| 6573 |
-- B : Boolean := False; |
| 6574 |
-- Bnn : Communication_Block; |
| 6575 |
-- C : Ada.Tags.Prim_Op_Kind; |
| 6576 |
-- D : System.Storage_Elements.Dummy_Communication_Block; |
| 6577 |
-- K : Ada.Tags.Tagged_Kind := |
| 6578 |
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); |
| 6579 |
-- P : Parameters := (Param1 .. ParamN); |
| 6580 |
-- S : Integer; |
| 6581 |
-- U : Boolean; |
| 6582 |
|
| 6583 |
-- begin |
| 6584 |
-- if K = Ada.Tags.TK_Limited_Tagged |
| 6585 |
-- or else K = Ada.Tags.TK_Tagged |
| 6586 |
-- then |
| 6587 |
-- <dispatching-call>; |
| 6588 |
-- <triggering-statements>; |
| 6589 |
|
| 6590 |
-- else |
| 6591 |
-- S := |
| 6592 |
-- Ada.Tags.Get_Offset_Index |
| 6593 |
-- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>)); |
| 6594 |
|
| 6595 |
-- _Disp_Get_Prim_Op_Kind (<object>, S, C); |
| 6596 |
|
| 6597 |
-- if C = POK_Protected_Entry then |
| 6598 |
-- declare |
| 6599 |
-- procedure _clean is |
| 6600 |
-- begin |
| 6601 |
-- if Enqueued (Bnn) then |
| 6602 |
-- Cancel_Protected_Entry_Call (Bnn); |
| 6603 |
-- end if; |
| 6604 |
-- end _clean; |
| 6605 |
|
| 6606 |
-- begin |
| 6607 |
-- begin |
| 6608 |
-- _Disp_Asynchronous_Select |
| 6609 |
-- (<object>, S, P'Address, D, B); |
| 6610 |
-- Bnn := Communication_Block (D); |
| 6611 |
|
| 6612 |
-- Param1 := P.Param1; |
| 6613 |
-- ... |
| 6614 |
-- ParamN := P.ParamN; |
| 6615 |
|
| 6616 |
-- if Enqueued (Bnn) then |
| 6617 |
-- <abortable-statements> |
| 6618 |
-- end if; |
| 6619 |
-- at end |
| 6620 |
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions |
| 6621 |
-- end; |
| 6622 |
-- exception |
| 6623 |
-- when Abort_Signal => null; |
| 6624 |
-- end; |
| 6625 |
|
| 6626 |
-- if not Cancelled (Bnn) then |
| 6627 |
-- <triggering-statements> |
| 6628 |
-- end if; |
| 6629 |
|
| 6630 |
-- elsif C = POK_Task_Entry then |
| 6631 |
-- declare |
| 6632 |
-- procedure _clean is |
| 6633 |
-- begin |
| 6634 |
-- Cancel_Task_Entry_Call (U); |
| 6635 |
-- end _clean; |
| 6636 |
|
| 6637 |
-- begin |
| 6638 |
-- Abort_Defer; |
| 6639 |
|
| 6640 |
-- _Disp_Asynchronous_Select |
| 6641 |
-- (<object>, S, P'Address, D, B); |
| 6642 |
-- Bnn := Communication_Bloc (D); |
| 6643 |
|
| 6644 |
-- Param1 := P.Param1; |
| 6645 |
-- ... |
| 6646 |
-- ParamN := P.ParamN; |
| 6647 |
|
| 6648 |
-- begin |
| 6649 |
-- begin |
| 6650 |
-- Abort_Undefer; |
| 6651 |
-- <abortable-statements> |
| 6652 |
-- at end |
| 6653 |
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions |
| 6654 |
-- end; |
| 6655 |
-- exception |
| 6656 |
-- when Abort_Signal => null; |
| 6657 |
-- end; |
| 6658 |
|
| 6659 |
-- if not U then |
| 6660 |
-- <triggering-statements> |
| 6661 |
-- end if; |
| 6662 |
-- end; |
| 6663 |
|
| 6664 |
-- else |
| 6665 |
-- <dispatching-call>; |
| 6666 |
-- <triggering-statements> |
| 6667 |
-- end if; |
| 6668 |
-- end if; |
| 6669 |
-- end; |
| 6670 |
|
| 6671 |
-- The job is to convert this to the asynchronous form |
| 6672 |
|
| 6673 |
-- If the trigger is a delay statement, it will have been expanded into |
| 6674 |
-- a call to one of the GNARL delay procedures. This routine will convert |
| 6675 |
-- this into a protected entry call on a delay object and then continue |
| 6676 |
-- processing as for a protected entry call trigger. This requires |
| 6677 |
-- declaring a Delay_Block object and adding a pointer to this object to |
| 6678 |
-- the parameter list of the delay procedure to form the parameter list of |
| 6679 |
-- the entry call. This object is used by the runtime to queue the delay |
| 6680 |
-- request. |
| 6681 |
|
| 6682 |
-- For a description of the use of P and the assignments after the call, |
| 6683 |
-- see Expand_N_Entry_Call_Statement. |
| 6684 |
|
| 6685 |
procedure Expand_N_Asynchronous_Select (N : Node_Id) is |
| 6686 |
Loc : constant Source_Ptr := Sloc (N); |
| 6687 |
Abrt : constant Node_Id := Abortable_Part (N); |
| 6688 |
Trig : constant Node_Id := Triggering_Alternative (N); |
| 6689 |
|
| 6690 |
Abortable_Block : Node_Id; |
| 6691 |
Actuals : List_Id; |
| 6692 |
Astats : List_Id; |
| 6693 |
Blk_Ent : constant Entity_Id := Make_Temporary (Loc, 'A'); |
| 6694 |
Blk_Typ : Entity_Id; |
| 6695 |
Call : Node_Id; |
| 6696 |
Call_Ent : Entity_Id; |
| 6697 |
Cancel_Param : Entity_Id; |
| 6698 |
Cleanup_Block : Node_Id; |
| 6699 |
Cleanup_Block_Ent : Entity_Id; |
| 6700 |
Cleanup_Stmts : List_Id; |
| 6701 |
Conc_Typ_Stmts : List_Id; |
| 6702 |
Concval : Node_Id; |
| 6703 |
Dblock_Ent : Entity_Id; |
| 6704 |
Decl : Node_Id; |
| 6705 |
Decls : List_Id; |
| 6706 |
Ecall : Node_Id; |
| 6707 |
Ename : Node_Id; |
| 6708 |
Enqueue_Call : Node_Id; |
| 6709 |
Formals : List_Id; |
| 6710 |
Index : Node_Id; |
| 6711 |
Lim_Typ_Stmts : List_Id; |
| 6712 |
N_Orig : Node_Id; |
| 6713 |
Obj : Entity_Id; |
| 6714 |
Param : Node_Id; |
| 6715 |
Params : List_Id; |
| 6716 |
Pdef : Entity_Id; |
| 6717 |
ProtE_Stmts : List_Id; |
| 6718 |
ProtP_Stmts : List_Id; |
| 6719 |
Stmt : Node_Id; |
| 6720 |
Stmts : List_Id; |
| 6721 |
TaskE_Stmts : List_Id; |
| 6722 |
Tstats : List_Id; |
| 6723 |
|
| 6724 |
B : Entity_Id; -- Call status flag |
| 6725 |
Bnn : Entity_Id; -- Communication block |
| 6726 |
C : Entity_Id; -- Call kind |
| 6727 |
K : Entity_Id; -- Tagged kind |
| 6728 |
P : Entity_Id; -- Parameter block |
| 6729 |
S : Entity_Id; -- Primitive operation slot |
| 6730 |
T : Entity_Id; -- Additional status flag |
| 6731 |
|
| 6732 |
procedure Rewrite_Abortable_Part; |
| 6733 |
-- If the trigger is a dispatching call, the expansion inserts multiple |
| 6734 |
-- copies of the abortable part. This is both inefficient, and may lead |
| 6735 |
-- to duplicate definitions that the back-end will reject, when the |
| 6736 |
-- abortable part includes loops. This procedure rewrites the abortable |
| 6737 |
-- part into a call to a generated procedure. |
| 6738 |
|
| 6739 |
---------------------------- |
| 6740 |
-- Rewrite_Abortable_Part -- |
| 6741 |
---------------------------- |
| 6742 |
|
| 6743 |
procedure Rewrite_Abortable_Part is |
| 6744 |
Proc : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA); |
| 6745 |
Decl : Node_Id; |
| 6746 |
|
| 6747 |
begin |
| 6748 |
Decl := |
| 6749 |
Make_Subprogram_Body (Loc, |
| 6750 |
Specification => |
| 6751 |
Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc), |
| 6752 |
Declarations => New_List, |
| 6753 |
Handled_Statement_Sequence => |
| 6754 |
Make_Handled_Sequence_Of_Statements (Loc, Astats)); |
| 6755 |
Insert_Before (N, Decl); |
| 6756 |
Analyze (Decl); |
| 6757 |
|
| 6758 |
-- Rewrite abortable part into a call to this procedure |
| 6759 |
|
| 6760 |
Astats := |
| 6761 |
New_List ( |
| 6762 |
Make_Procedure_Call_Statement (Loc, |
| 6763 |
Name => New_Occurrence_Of (Proc, Loc))); |
| 6764 |
end Rewrite_Abortable_Part; |
| 6765 |
|
| 6766 |
-- Start of processing for Expand_N_Asynchronous_Select |
| 6767 |
|
| 6768 |
begin |
| 6769 |
-- Asynchronous select is not supported on restricted runtimes. Don't |
| 6770 |
-- try to expand. |
| 6771 |
|
| 6772 |
if Restricted_Profile then |
| 6773 |
return; |
| 6774 |
end if; |
| 6775 |
|
| 6776 |
Process_Statements_For_Controlled_Objects (Trig); |
| 6777 |
Process_Statements_For_Controlled_Objects (Abrt); |
| 6778 |
|
| 6779 |
Ecall := Triggering_Statement (Trig); |
| 6780 |
|
| 6781 |
Ensure_Statement_Present (Sloc (Ecall), Trig); |
| 6782 |
|
| 6783 |
-- Retrieve Astats and Tstats now because the finalization machinery may |
| 6784 |
-- wrap them in blocks. |
| 6785 |
|
| 6786 |
Astats := Statements (Abrt); |
| 6787 |
Tstats := Statements (Trig); |
| 6788 |
|
| 6789 |
-- The arguments in the call may require dynamic allocation, and the |
| 6790 |
-- call statement may have been transformed into a block. The block |
| 6791 |
-- may contain additional declarations for internal entities, and the |
| 6792 |
-- original call is found by sequential search. |
| 6793 |
|
| 6794 |
if Nkind (Ecall) = N_Block_Statement then |
| 6795 |
Ecall := First (Statements (Handled_Statement_Sequence (Ecall))); |
| 6796 |
while Nkind (Ecall) not in |
| 6797 |
N_Procedure_Call_Statement | N_Entry_Call_Statement |
| 6798 |
loop |
| 6799 |
Next (Ecall); |
| 6800 |
end loop; |
| 6801 |
end if; |
| 6802 |
|
| 6803 |
-- This is either a dispatching call or a delay statement used as a |
| 6804 |
-- trigger which was expanded into a procedure call. |
| 6805 |
|
| 6806 |
if Nkind (Ecall) = N_Procedure_Call_Statement then |
| 6807 |
if Ada_Version >= Ada_2005 |
| 6808 |
and then |
| 6809 |
(No (Original_Node (Ecall)) |
| 6810 |
or else Nkind (Original_Node (Ecall)) not in N_Delay_Statement) |
| 6811 |
then |
| 6812 |
Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals); |
| 6813 |
|
| 6814 |
Rewrite_Abortable_Part; |
| 6815 |
Decls := New_List; |
| 6816 |
Stmts := New_List; |
| 6817 |
|
| 6818 |
-- Call status flag processing, generate: |
| 6819 |
-- B : Boolean := False; |
| 6820 |
|
| 6821 |
B := Build_B (Loc, Decls); |
| 6822 |
|
| 6823 |
-- Communication block processing, generate: |
| 6824 |
-- Bnn : Communication_Block; |
| 6825 |
|
| 6826 |
Bnn := Make_Temporary (Loc, 'B'); |
| 6827 |
Append_To (Decls, |
| 6828 |
Make_Object_Declaration (Loc, |
| 6829 |
Defining_Identifier => Bnn, |
| 6830 |
Object_Definition => |
| 6831 |
New_Occurrence_Of (RTE (RE_Communication_Block), Loc))); |
| 6832 |
|
| 6833 |
-- Call kind processing, generate: |
| 6834 |
-- C : Ada.Tags.Prim_Op_Kind; |
| 6835 |
|
| 6836 |
C := Build_C (Loc, Decls); |
| 6837 |
|
| 6838 |
-- Tagged kind processing, generate: |
| 6839 |
-- K : Ada.Tags.Tagged_Kind := |
| 6840 |
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); |
| 6841 |
|
| 6842 |
-- Dummy communication block, generate: |
| 6843 |
-- D : Dummy_Communication_Block; |
| 6844 |
|
| 6845 |
Append_To (Decls, |
| 6846 |
Make_Object_Declaration (Loc, |
| 6847 |
Defining_Identifier => |
| 6848 |
Make_Defining_Identifier (Loc, Name_uD), |
| 6849 |
Object_Definition => |
| 6850 |
New_Occurrence_Of |
| 6851 |
(RTE (RE_Dummy_Communication_Block), Loc))); |
| 6852 |
|
| 6853 |
K := Build_K (Loc, Decls, Obj); |
| 6854 |
|
| 6855 |
-- Parameter block processing |
| 6856 |
|
| 6857 |
Blk_Typ := Build_Parameter_Block |
| 6858 |
(Loc, Actuals, Formals, Decls); |
| 6859 |
P := Parameter_Block_Pack |
| 6860 |
(Loc, Blk_Typ, Actuals, Formals, Decls, Stmts); |
| 6861 |
|
| 6862 |
-- Dispatch table slot processing, generate: |
| 6863 |
-- S : Integer; |
| 6864 |
|
| 6865 |
S := Build_S (Loc, Decls); |
| 6866 |
|
| 6867 |
-- Additional status flag processing, generate: |
| 6868 |
-- Tnn : Boolean; |
| 6869 |
|
| 6870 |
T := Make_Temporary (Loc, 'T'); |
| 6871 |
Append_To (Decls, |
| 6872 |
Make_Object_Declaration (Loc, |
| 6873 |
Defining_Identifier => T, |
| 6874 |
Object_Definition => |
| 6875 |
New_Occurrence_Of (Standard_Boolean, Loc))); |
| 6876 |
|
| 6877 |
------------------------------ |
| 6878 |
-- Protected entry handling -- |
| 6879 |
------------------------------ |
| 6880 |
|
| 6881 |
-- Generate: |
| 6882 |
-- Param1 := P.Param1; |
| 6883 |
-- ... |
| 6884 |
-- ParamN := P.ParamN; |
| 6885 |
|
| 6886 |
Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals); |
| 6887 |
|
| 6888 |
-- Generate: |
| 6889 |
-- Bnn := Communication_Block (D); |
| 6890 |
|
| 6891 |
Prepend_To (Cleanup_Stmts, |
| 6892 |
Make_Assignment_Statement (Loc, |
| 6893 |
Name => New_Occurrence_Of (Bnn, Loc), |
| 6894 |
Expression => |
| 6895 |
Unchecked_Convert_To |
| 6896 |
(RTE (RE_Communication_Block), |
| 6897 |
Make_Identifier (Loc, Name_uD)))); |
| 6898 |
|
| 6899 |
-- Generate: |
| 6900 |
-- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B); |
| 6901 |
|
| 6902 |
Prepend_To (Cleanup_Stmts, |
| 6903 |
Make_Procedure_Call_Statement (Loc, |
| 6904 |
Name => |
| 6905 |
New_Occurrence_Of |
| 6906 |
(Find_Prim_Op |
| 6907 |
(Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select), |
| 6908 |
Loc), |
| 6909 |
Parameter_Associations => |
| 6910 |
New_List ( |
| 6911 |
New_Copy_Tree (Obj), -- <object> |
| 6912 |
New_Occurrence_Of (S, Loc), -- S |
| 6913 |
Make_Attribute_Reference (Loc, -- P'Address |
| 6914 |
Prefix => New_Occurrence_Of (P, Loc), |
| 6915 |
Attribute_Name => Name_Address), |
| 6916 |
Make_Identifier (Loc, Name_uD), -- D |
| 6917 |
New_Occurrence_Of (B, Loc)))); -- B |
| 6918 |
|
| 6919 |
-- Generate: |
| 6920 |
-- if Enqueued (Bnn) then |
| 6921 |
-- <abortable-statements> |
| 6922 |
-- end if; |
| 6923 |
|
| 6924 |
Append_To (Cleanup_Stmts, |
| 6925 |
Make_Implicit_If_Statement (N, |
| 6926 |
Condition => |
| 6927 |
Make_Function_Call (Loc, |
| 6928 |
Name => |
| 6929 |
New_Occurrence_Of (RTE (RE_Enqueued), Loc), |
| 6930 |
Parameter_Associations => |
| 6931 |
New_List (New_Occurrence_Of (Bnn, Loc))), |
| 6932 |
|
| 6933 |
Then_Statements => |
| 6934 |
New_Copy_List_Tree (Astats))); |
| 6935 |
|
| 6936 |
-- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions |
| 6937 |
-- will then generate a _clean for the communication block Bnn. |
| 6938 |
|
| 6939 |
-- Generate: |
| 6940 |
-- declare |
| 6941 |
-- procedure _clean is |
| 6942 |
-- begin |
| 6943 |
-- if Enqueued (Bnn) then |
| 6944 |
-- Cancel_Protected_Entry_Call (Bnn); |
| 6945 |
-- end if; |
| 6946 |
-- end _clean; |
| 6947 |
-- begin |
| 6948 |
-- Cleanup_Stmts |
| 6949 |
-- at end |
| 6950 |
-- _clean; |
| 6951 |
-- end; |
| 6952 |
|
| 6953 |
Cleanup_Block_Ent := Make_Temporary (Loc, 'C'); |
| 6954 |
Cleanup_Block := |
| 6955 |
Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn); |
| 6956 |
|
| 6957 |
-- Wrap the cleanup block in an exception handling block |
| 6958 |
|
| 6959 |
-- Generate: |
| 6960 |
-- begin |
| 6961 |
-- Cleanup_Block |
| 6962 |
-- exception |
| 6963 |
-- when Abort_Signal => null; |
| 6964 |
-- end; |
| 6965 |
|
| 6966 |
ProtE_Stmts := New_List ( |
| 6967 |
Build_Abort_Block (Loc, Cleanup_Block_Ent, Cleanup_Block)); |
| 6968 |
|
| 6969 |
-- Generate: |
| 6970 |
-- if not Cancelled (Bnn) then |
| 6971 |
-- <triggering-statements> |
| 6972 |
-- end if; |
| 6973 |
|
| 6974 |
Append_To (ProtE_Stmts, |
| 6975 |
Make_Implicit_If_Statement (N, |
| 6976 |
Condition => |
| 6977 |
Make_Op_Not (Loc, |
| 6978 |
Right_Opnd => |
| 6979 |
Make_Function_Call (Loc, |
| 6980 |
Name => |
| 6981 |
New_Occurrence_Of (RTE (RE_Cancelled), Loc), |
| 6982 |
Parameter_Associations => |
| 6983 |
New_List (New_Occurrence_Of (Bnn, Loc)))), |
| 6984 |
|
| 6985 |
Then_Statements => |
| 6986 |
New_Copy_List_Tree (Tstats))); |
| 6987 |
|
| 6988 |
------------------------- |
| 6989 |
-- Task entry handling -- |
| 6990 |
------------------------- |
| 6991 |
|
| 6992 |
-- Generate: |
| 6993 |
-- Param1 := P.Param1; |
| 6994 |
-- ... |
| 6995 |
-- ParamN := P.ParamN; |
| 6996 |
|
| 6997 |
TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals); |
| 6998 |
|
| 6999 |
-- Generate: |
| 7000 |
-- Bnn := Communication_Block (D); |
| 7001 |
|
| 7002 |
Append_To (TaskE_Stmts, |
| 7003 |
Make_Assignment_Statement (Loc, |
| 7004 |
Name => |
| 7005 |
New_Occurrence_Of (Bnn, Loc), |
| 7006 |
Expression => |
| 7007 |
Unchecked_Convert_To |
| 7008 |
(RTE (RE_Communication_Block), |
| 7009 |
Make_Identifier (Loc, Name_uD)))); |
| 7010 |
|
| 7011 |
-- Generate: |
| 7012 |
-- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B); |
| 7013 |
|
| 7014 |
Prepend_To (TaskE_Stmts, |
| 7015 |
Make_Procedure_Call_Statement (Loc, |
| 7016 |
Name => |
| 7017 |
New_Occurrence_Of ( |
| 7018 |
Find_Prim_Op (Etype (Etype (Obj)), |
| 7019 |
Name_uDisp_Asynchronous_Select), |
| 7020 |
Loc), |
| 7021 |
|
| 7022 |
Parameter_Associations => New_List ( |
| 7023 |
New_Copy_Tree (Obj), -- <object> |
| 7024 |
New_Occurrence_Of (S, Loc), -- S |
| 7025 |
Make_Attribute_Reference (Loc, -- P'Address |
| 7026 |
Prefix => New_Occurrence_Of (P, Loc), |
| 7027 |
Attribute_Name => Name_Address), |
| 7028 |
Make_Identifier (Loc, Name_uD), -- D |
| 7029 |
New_Occurrence_Of (B, Loc)))); -- B |
| 7030 |
|
| 7031 |
-- Generate: |
| 7032 |
-- Abort_Defer; |
| 7033 |
|
| 7034 |
Prepend_To (TaskE_Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer)); |
| 7035 |
|
| 7036 |
-- Generate: |
| 7037 |
-- Abort_Undefer; |
| 7038 |
-- <abortable-statements> |
| 7039 |
|
| 7040 |
Cleanup_Stmts := New_Copy_List_Tree (Astats); |
| 7041 |
|
| 7042 |
Prepend_To |
| 7043 |
(Cleanup_Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer)); |
| 7044 |
|
| 7045 |
-- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions |
| 7046 |
-- will generate a _clean for the additional status flag. |
| 7047 |
|
| 7048 |
-- Generate: |
| 7049 |
-- declare |
| 7050 |
-- procedure _clean is |
| 7051 |
-- begin |
| 7052 |
-- Cancel_Task_Entry_Call (U); |
| 7053 |
-- end _clean; |
| 7054 |
-- begin |
| 7055 |
-- Cleanup_Stmts |
| 7056 |
-- at end |
| 7057 |
-- _clean; |
| 7058 |
-- end; |
| 7059 |
|
| 7060 |
Cleanup_Block_Ent := Make_Temporary (Loc, 'C'); |
| 7061 |
Cleanup_Block := |
| 7062 |
Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T); |
| 7063 |
|
| 7064 |
-- Wrap the cleanup block in an exception handling block |
| 7065 |
|
| 7066 |
-- Generate: |
| 7067 |
-- begin |
| 7068 |
-- Cleanup_Block |
| 7069 |
-- exception |
| 7070 |
-- when Abort_Signal => null; |
| 7071 |
-- end; |
| 7072 |
|
| 7073 |
Append_To (TaskE_Stmts, |
| 7074 |
Build_Abort_Block (Loc, Cleanup_Block_Ent, Cleanup_Block)); |
| 7075 |
|
| 7076 |
-- Generate: |
| 7077 |
-- if not T then |
| 7078 |
-- <triggering-statements> |
| 7079 |
-- end if; |
| 7080 |
|
| 7081 |
Append_To (TaskE_Stmts, |
| 7082 |
Make_Implicit_If_Statement (N, |
| 7083 |
Condition => |
| 7084 |
Make_Op_Not (Loc, Right_Opnd => New_Occurrence_Of (T, Loc)), |
| 7085 |
|
| 7086 |
Then_Statements => |
| 7087 |
New_Copy_List_Tree (Tstats))); |
| 7088 |
|
| 7089 |
---------------------------------- |
| 7090 |
-- Protected procedure handling -- |
| 7091 |
---------------------------------- |
| 7092 |
|
| 7093 |
-- Generate: |
| 7094 |
-- <dispatching-call>; |
| 7095 |
-- <triggering-statements> |
| 7096 |
|
| 7097 |
ProtP_Stmts := New_Copy_List_Tree (Tstats); |
| 7098 |
Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall)); |
| 7099 |
|
| 7100 |
-- Generate: |
| 7101 |
-- S := Ada.Tags.Get_Offset_Index |
| 7102 |
-- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent)); |
| 7103 |
|
| 7104 |
Conc_Typ_Stmts := |
| 7105 |
New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent)); |
| 7106 |
|
| 7107 |
-- Generate: |
| 7108 |
-- _Disp_Get_Prim_Op_Kind (<object>, S, C); |
| 7109 |
|
| 7110 |
Append_To (Conc_Typ_Stmts, |
| 7111 |
Make_Procedure_Call_Statement (Loc, |
| 7112 |
Name => |
| 7113 |
New_Occurrence_Of |
| 7114 |
(Find_Prim_Op (Etype (Etype (Obj)), |
| 7115 |
Name_uDisp_Get_Prim_Op_Kind), |
| 7116 |
Loc), |
| 7117 |
Parameter_Associations => |
| 7118 |
New_List ( |
| 7119 |
New_Copy_Tree (Obj), |
| 7120 |
New_Occurrence_Of (S, Loc), |
| 7121 |
New_Occurrence_Of (C, Loc)))); |
| 7122 |
|
| 7123 |
-- Generate: |
| 7124 |
-- if C = POK_Procedure_Entry then |
| 7125 |
-- ProtE_Stmts |
| 7126 |
-- elsif C = POK_Task_Entry then |
| 7127 |
-- TaskE_Stmts |
| 7128 |
-- else |
| 7129 |
-- ProtP_Stmts |
| 7130 |
-- end if; |
| 7131 |
|
| 7132 |
Append_To (Conc_Typ_Stmts, |
| 7133 |
Make_Implicit_If_Statement (N, |
| 7134 |
Condition => |
| 7135 |
Make_Op_Eq (Loc, |
| 7136 |
Left_Opnd => |
| 7137 |
New_Occurrence_Of (C, Loc), |
| 7138 |
Right_Opnd => |
| 7139 |
New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)), |
| 7140 |
|
| 7141 |
Then_Statements => |
| 7142 |
ProtE_Stmts, |
| 7143 |
|
| 7144 |
Elsif_Parts => |
| 7145 |
New_List ( |
| 7146 |
Make_Elsif_Part (Loc, |
| 7147 |
Condition => |
| 7148 |
Make_Op_Eq (Loc, |
| 7149 |
Left_Opnd => |
| 7150 |
New_Occurrence_Of (C, Loc), |
| 7151 |
Right_Opnd => |
| 7152 |
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc)), |
| 7153 |
|
| 7154 |
Then_Statements => |
| 7155 |
TaskE_Stmts)), |
| 7156 |
|
| 7157 |
Else_Statements => |
| 7158 |
ProtP_Stmts)); |
| 7159 |
|
| 7160 |
-- Generate: |
| 7161 |
-- <dispatching-call>; |
| 7162 |
-- <triggering-statements> |
| 7163 |
|
| 7164 |
Lim_Typ_Stmts := New_Copy_List_Tree (Tstats); |
| 7165 |
Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall)); |
| 7166 |
|
| 7167 |
-- Generate: |
| 7168 |
-- if K = Ada.Tags.TK_Limited_Tagged |
| 7169 |
-- or else K = Ada.Tags.TK_Tagged |
| 7170 |
-- then |
| 7171 |
-- Lim_Typ_Stmts |
| 7172 |
-- else |
| 7173 |
-- Conc_Typ_Stmts |
| 7174 |
-- end if; |
| 7175 |
|
| 7176 |
Append_To (Stmts, |
| 7177 |
Make_Implicit_If_Statement (N, |
| 7178 |
Condition => Build_Dispatching_Tag_Check (K, N), |
| 7179 |
Then_Statements => Lim_Typ_Stmts, |
| 7180 |
Else_Statements => Conc_Typ_Stmts)); |
| 7181 |
|
| 7182 |
Rewrite (N, |
| 7183 |
Make_Block_Statement (Loc, |
| 7184 |
Declarations => |
| 7185 |
Decls, |
| 7186 |
Handled_Statement_Sequence => |
| 7187 |
Make_Handled_Sequence_Of_Statements (Loc, Stmts))); |
| 7188 |
|
| 7189 |
Analyze (N); |
| 7190 |
return; |
| 7191 |
|
| 7192 |
-- Delay triggering statement processing |
| 7193 |
|
| 7194 |
else |
| 7195 |
-- Add a Delay_Block object to the parameter list of the delay |
| 7196 |
-- procedure to form the parameter list of the Wait entry call. |
| 7197 |
|
| 7198 |
Dblock_Ent := Make_Temporary (Loc, 'D'); |
| 7199 |
|
| 7200 |
Pdef := Entity (Name (Ecall)); |
| 7201 |
|
| 7202 |
if Is_RTE (Pdef, RO_CA_Delay_For) then |
| 7203 |
Enqueue_Call := |
| 7204 |
New_Occurrence_Of (RTE (RE_Enqueue_Duration), Loc); |
| 7205 |
|
| 7206 |
elsif Is_RTE (Pdef, RO_CA_Delay_Until) then |
| 7207 |
Enqueue_Call := |
| 7208 |
New_Occurrence_Of (RTE (RE_Enqueue_Calendar), Loc); |
| 7209 |
|
| 7210 |
else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until)); |
| 7211 |
Enqueue_Call := New_Occurrence_Of (RTE (RE_Enqueue_RT), Loc); |
| 7212 |
end if; |
| 7213 |
|
| 7214 |
Append_To (Parameter_Associations (Ecall), |
| 7215 |
Make_Attribute_Reference (Loc, |
| 7216 |
Prefix => New_Occurrence_Of (Dblock_Ent, Loc), |
| 7217 |
Attribute_Name => Name_Unchecked_Access)); |
| 7218 |
|
| 7219 |
Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer)); |
| 7220 |
|
| 7221 |
Abortable_Block := |
| 7222 |
Make_Block_Statement (Loc, |
| 7223 |
Identifier => New_Occurrence_Of (Blk_Ent, Loc), |
| 7224 |
Handled_Statement_Sequence => |
| 7225 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 7226 |
Statements => Astats), |
| 7227 |
Has_Created_Identifier => True, |
| 7228 |
Is_Asynchronous_Call_Block => True); |
| 7229 |
|
| 7230 |
-- Wrap the abortable block in an exception handling block |
| 7231 |
|
| 7232 |
-- Generate: |
| 7233 |
-- begin |
| 7234 |
-- Abortable_Block |
| 7235 |
-- exception |
| 7236 |
-- when Abort_Signal => null; |
| 7237 |
-- end; |
| 7238 |
|
| 7239 |
Stmts := New_List ( |
| 7240 |
Build_Abort_Block (Loc, Blk_Ent, Abortable_Block)); |
| 7241 |
|
| 7242 |
-- Append call to if Enqueue (When, DB'Unchecked_Access) then |
| 7243 |
|
| 7244 |
Rewrite (Ecall, |
| 7245 |
Make_Implicit_If_Statement (N, |
| 7246 |
Condition => |
| 7247 |
Make_Function_Call (Loc, |
| 7248 |
Name => Enqueue_Call, |
| 7249 |
Parameter_Associations => Parameter_Associations (Ecall)), |
| 7250 |
Then_Statements => Stmts)); |
| 7251 |
|
| 7252 |
Stmts := New_List (Ecall); |
| 7253 |
|
| 7254 |
-- Construct statement sequence for new block |
| 7255 |
|
| 7256 |
Append_To (Stmts, |
| 7257 |
Make_Implicit_If_Statement (N, |
| 7258 |
Condition => |
| 7259 |
Make_Function_Call (Loc, |
| 7260 |
Name => New_Occurrence_Of ( |
| 7261 |
RTE (RE_Timed_Out), Loc), |
| 7262 |
Parameter_Associations => New_List ( |
| 7263 |
Make_Attribute_Reference (Loc, |
| 7264 |
Prefix => New_Occurrence_Of (Dblock_Ent, Loc), |
| 7265 |
Attribute_Name => Name_Unchecked_Access))), |
| 7266 |
Then_Statements => Tstats)); |
| 7267 |
|
| 7268 |
-- The result is the new block |
| 7269 |
|
| 7270 |
Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent); |
| 7271 |
|
| 7272 |
Rewrite (N, |
| 7273 |
Make_Block_Statement (Loc, |
| 7274 |
Declarations => New_List ( |
| 7275 |
Make_Object_Declaration (Loc, |
| 7276 |
Defining_Identifier => Dblock_Ent, |
| 7277 |
Aliased_Present => True, |
| 7278 |
Object_Definition => |
| 7279 |
New_Occurrence_Of (RTE (RE_Delay_Block), Loc))), |
| 7280 |
|
| 7281 |
Handled_Statement_Sequence => |
| 7282 |
Make_Handled_Sequence_Of_Statements (Loc, Stmts))); |
| 7283 |
|
| 7284 |
Analyze (N); |
| 7285 |
return; |
| 7286 |
end if; |
| 7287 |
|
| 7288 |
else |
| 7289 |
N_Orig := N; |
| 7290 |
end if; |
| 7291 |
|
| 7292 |
Extract_Entry (Ecall, Concval, Ename, Index); |
| 7293 |
Build_Simple_Entry_Call (Ecall, Concval, Ename, Index); |
| 7294 |
|
| 7295 |
Stmts := Statements (Handled_Statement_Sequence (Ecall)); |
| 7296 |
Decls := Declarations (Ecall); |
| 7297 |
|
| 7298 |
if Is_Protected_Type (Etype (Concval)) then |
| 7299 |
|
| 7300 |
-- Get the declarations of the block expanded from the entry call |
| 7301 |
|
| 7302 |
Decl := First (Decls); |
| 7303 |
while Present (Decl) |
| 7304 |
and then (Nkind (Decl) /= N_Object_Declaration |
| 7305 |
or else not Is_RTE (Etype (Object_Definition (Decl)), |
| 7306 |
RE_Communication_Block)) |
| 7307 |
loop |
| 7308 |
Next (Decl); |
| 7309 |
end loop; |
| 7310 |
|
| 7311 |
pragma Assert (Present (Decl)); |
| 7312 |
Cancel_Param := Defining_Identifier (Decl); |
| 7313 |
|
| 7314 |
-- Change the mode of the Protected_Entry_Call call |
| 7315 |
|
| 7316 |
-- Protected_Entry_Call ( |
| 7317 |
-- Object => po._object'Access, |
| 7318 |
-- E => <entry index>; |
| 7319 |
-- Uninterpreted_Data => P'Address; |
| 7320 |
-- Mode => Asynchronous_Call; |
| 7321 |
-- Block => Bnn); |
| 7322 |
|
| 7323 |
-- Skip assignments to temporaries created for in-out parameters |
| 7324 |
|
| 7325 |
-- This makes unwarranted assumptions about the shape of the expanded |
| 7326 |
-- tree for the call, and should be cleaned up ??? |
| 7327 |
|
| 7328 |
Stmt := First (Stmts); |
| 7329 |
while Nkind (Stmt) /= N_Procedure_Call_Statement loop |
| 7330 |
Next (Stmt); |
| 7331 |
end loop; |
| 7332 |
|
| 7333 |
Call := Stmt; |
| 7334 |
|
| 7335 |
Param := First (Parameter_Associations (Call)); |
| 7336 |
while Present (Param) |
| 7337 |
and then not Is_RTE (Etype (Param), RE_Call_Modes) |
| 7338 |
loop |
| 7339 |
Next (Param); |
| 7340 |
end loop; |
| 7341 |
|
| 7342 |
pragma Assert (Present (Param)); |
| 7343 |
Rewrite (Param, New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc)); |
| 7344 |
Analyze (Param); |
| 7345 |
|
| 7346 |
-- Append an if statement to execute the abortable part |
| 7347 |
|
| 7348 |
-- Generate: |
| 7349 |
-- if Enqueued (Bnn) then |
| 7350 |
|
| 7351 |
Append_To (Stmts, |
| 7352 |
Make_Implicit_If_Statement (N, |
| 7353 |
Condition => |
| 7354 |
Make_Function_Call (Loc, |
| 7355 |
Name => New_Occurrence_Of (RTE (RE_Enqueued), Loc), |
| 7356 |
Parameter_Associations => New_List ( |
| 7357 |
New_Occurrence_Of (Cancel_Param, Loc))), |
| 7358 |
Then_Statements => Astats)); |
| 7359 |
|
| 7360 |
Abortable_Block := |
| 7361 |
Make_Block_Statement (Loc, |
| 7362 |
Identifier => New_Occurrence_Of (Blk_Ent, Loc), |
| 7363 |
Handled_Statement_Sequence => |
| 7364 |
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts), |
| 7365 |
Has_Created_Identifier => True, |
| 7366 |
Is_Asynchronous_Call_Block => True); |
| 7367 |
|
| 7368 |
-- Wrap the abortable block in an exception handling block |
| 7369 |
|
| 7370 |
-- Generate: |
| 7371 |
-- begin |
| 7372 |
-- Abortable_Block |
| 7373 |
-- exception |
| 7374 |
-- when Abort_Signal => null; |
| 7375 |
-- end; |
| 7376 |
|
| 7377 |
Stmts := New_List ( |
| 7378 |
Build_Abort_Block (Loc, Blk_Ent, Abortable_Block), |
| 7379 |
|
| 7380 |
-- if not Cancelled (Bnn) then |
| 7381 |
-- triggered statements |
| 7382 |
-- end if; |
| 7383 |
|
| 7384 |
Make_Implicit_If_Statement (N, |
| 7385 |
Condition => Make_Op_Not (Loc, |
| 7386 |
Right_Opnd => |
| 7387 |
Make_Function_Call (Loc, |
| 7388 |
Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc), |
| 7389 |
Parameter_Associations => New_List ( |
| 7390 |
New_Occurrence_Of (Cancel_Param, Loc)))), |
| 7391 |
Then_Statements => Tstats)); |
| 7392 |
|
| 7393 |
-- Asynchronous task entry call |
| 7394 |
|
| 7395 |
else |
| 7396 |
if No (Decls) then |
| 7397 |
Decls := New_List; |
| 7398 |
end if; |
| 7399 |
|
| 7400 |
B := Make_Defining_Identifier (Loc, Name_uB); |
| 7401 |
|
| 7402 |
-- Insert declaration of B in declarations of existing block |
| 7403 |
|
| 7404 |
Prepend_To (Decls, |
| 7405 |
Make_Object_Declaration (Loc, |
| 7406 |
Defining_Identifier => B, |
| 7407 |
Object_Definition => |
| 7408 |
New_Occurrence_Of (Standard_Boolean, Loc))); |
| 7409 |
|
| 7410 |
Cancel_Param := Make_Defining_Identifier (Loc, Name_uC); |
| 7411 |
|
| 7412 |
-- Insert the declaration of C in the declarations of the existing |
| 7413 |
-- block. The variable is initialized to something (True or False, |
| 7414 |
-- does not matter) to prevent CodePeer from complaining about a |
| 7415 |
-- possible read of an uninitialized variable. |
| 7416 |
|
| 7417 |
Prepend_To (Decls, |
| 7418 |
Make_Object_Declaration (Loc, |
| 7419 |
Defining_Identifier => Cancel_Param, |
| 7420 |
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc), |
| 7421 |
Expression => New_Occurrence_Of (Standard_False, Loc), |
| 7422 |
Has_Init_Expression => True)); |
| 7423 |
|
| 7424 |
-- Remove and save the call to Call_Simple |
| 7425 |
|
| 7426 |
Stmt := First (Stmts); |
| 7427 |
|
| 7428 |
-- Skip assignments to temporaries created for in-out parameters. |
| 7429 |
-- This makes unwarranted assumptions about the shape of the expanded |
| 7430 |
-- tree for the call, and should be cleaned up ??? |
| 7431 |
|
| 7432 |
while Nkind (Stmt) /= N_Procedure_Call_Statement loop |
| 7433 |
Next (Stmt); |
| 7434 |
end loop; |
| 7435 |
|
| 7436 |
Call := Stmt; |
| 7437 |
|
| 7438 |
if Abort_Allowed then |
| 7439 |
Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer)); |
| 7440 |
end if; |
| 7441 |
|
| 7442 |
Abortable_Block := |
| 7443 |
Make_Block_Statement (Loc, |
| 7444 |
Identifier => New_Occurrence_Of (Blk_Ent, Loc), |
| 7445 |
Handled_Statement_Sequence => |
| 7446 |
Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats), |
| 7447 |
Has_Created_Identifier => True, |
| 7448 |
Is_Asynchronous_Call_Block => True); |
| 7449 |
|
| 7450 |
-- Wrap the abortable block in an exception handling block |
| 7451 |
|
| 7452 |
-- Generate: |
| 7453 |
-- begin |
| 7454 |
-- Abortable_Block |
| 7455 |
-- exception |
| 7456 |
-- when Abort_Signal => null; |
| 7457 |
-- end; |
| 7458 |
|
| 7459 |
Insert_After (Call, |
| 7460 |
Build_Abort_Block (Loc, Blk_Ent, Abortable_Block)); |
| 7461 |
|
| 7462 |
-- Create new call statement |
| 7463 |
|
| 7464 |
Params := Parameter_Associations (Call); |
| 7465 |
|
| 7466 |
Append_To (Params, |
| 7467 |
New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc)); |
| 7468 |
Append_To (Params, New_Occurrence_Of (B, Loc)); |
| 7469 |
|
| 7470 |
Rewrite (Call, |
| 7471 |
Make_Procedure_Call_Statement (Loc, |
| 7472 |
Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc), |
| 7473 |
Parameter_Associations => Params)); |
| 7474 |
|
| 7475 |
-- Construct statement sequence for new block |
| 7476 |
|
| 7477 |
Append_To (Stmts, |
| 7478 |
Make_Implicit_If_Statement (N, |
| 7479 |
Condition => |
| 7480 |
Make_Op_Not (Loc, New_Occurrence_Of (Cancel_Param, Loc)), |
| 7481 |
Then_Statements => Tstats)); |
| 7482 |
|
| 7483 |
-- Protected the call against abort |
| 7484 |
|
| 7485 |
Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer)); |
| 7486 |
end if; |
| 7487 |
|
| 7488 |
Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param); |
| 7489 |
|
| 7490 |
-- The result is the new block |
| 7491 |
|
| 7492 |
Rewrite (N_Orig, |
| 7493 |
Make_Block_Statement (Loc, |
| 7494 |
Declarations => Decls, |
| 7495 |
Handled_Statement_Sequence => |
| 7496 |
Make_Handled_Sequence_Of_Statements (Loc, Stmts))); |
| 7497 |
|
| 7498 |
Analyze (N_Orig); |
| 7499 |
end Expand_N_Asynchronous_Select; |
| 7500 |
|
| 7501 |
------------------------------------- |
| 7502 |
-- Expand_N_Conditional_Entry_Call -- |
| 7503 |
------------------------------------- |
| 7504 |
|
| 7505 |
-- The conditional task entry call is converted to a call to |
| 7506 |
-- Task_Entry_Call: |
| 7507 |
|
| 7508 |
-- declare |
| 7509 |
-- B : Boolean; |
| 7510 |
-- P : parms := (parm, parm, parm); |
| 7511 |
|
| 7512 |
-- begin |
| 7513 |
-- Task_Entry_Call |
| 7514 |
-- (<acceptor-task>, -- Acceptor |
| 7515 |
-- <entry-index>, -- E |
| 7516 |
-- P'Address, -- Uninterpreted_Data |
| 7517 |
-- Conditional_Call, -- Mode |
| 7518 |
-- B); -- Rendezvous_Successful |
| 7519 |
-- parm := P.param; |
| 7520 |
-- parm := P.param; |
| 7521 |
-- ... |
| 7522 |
-- if B then |
| 7523 |
-- normal-statements |
| 7524 |
-- else |
| 7525 |
-- else-statements |
| 7526 |
-- end if; |
| 7527 |
-- end; |
| 7528 |
|
| 7529 |
-- For a description of the use of P and the assignments after the call, |
| 7530 |
-- see Expand_N_Entry_Call_Statement. Note that the entry call of the |
| 7531 |
-- conditional entry call has already been expanded (by the Expand_N_Entry |
| 7532 |
-- _Call_Statement procedure) as follows: |
| 7533 |
|
| 7534 |
-- declare |
| 7535 |
-- P : parms := (parm, parm, parm); |
| 7536 |
-- begin |
| 7537 |
-- ... info for in-out parameters |
| 7538 |
-- Call_Simple (acceptor-task, entry-index, P'Address); |
| 7539 |
-- parm := P.param; |
| 7540 |
-- parm := P.param; |
| 7541 |
-- ... |
| 7542 |
-- end; |
| 7543 |
|
| 7544 |
-- so the task at hand is to convert the latter expansion into the former |
| 7545 |
|
| 7546 |
-- The conditional protected entry call is converted to a call to |
| 7547 |
-- Protected_Entry_Call: |
| 7548 |
|
| 7549 |
-- declare |
| 7550 |
-- P : parms := (parm, parm, parm); |
| 7551 |
-- Bnn : Communications_Block; |
| 7552 |
|
| 7553 |
-- begin |
| 7554 |
-- Protected_Entry_Call |
| 7555 |
-- (po._object'Access, -- Object |
| 7556 |
-- <entry index>, -- E |
| 7557 |
-- P'Address, -- Uninterpreted_Data |
| 7558 |
-- Conditional_Call, -- Mode |
| 7559 |
-- Bnn); -- Block |
| 7560 |
-- parm := P.param; |
| 7561 |
-- parm := P.param; |
| 7562 |
-- ... |
| 7563 |
-- if Cancelled (Bnn) then |
| 7564 |
-- else-statements |
| 7565 |
-- else |
| 7566 |
-- normal-statements |
| 7567 |
-- end if; |
| 7568 |
-- end; |
| 7569 |
|
| 7570 |
-- Ada 2005 (AI-345): A dispatching conditional entry call is converted |
| 7571 |
-- into: |
| 7572 |
|
| 7573 |
-- declare |
| 7574 |
-- B : Boolean := False; |
| 7575 |
-- C : Ada.Tags.Prim_Op_Kind; |
| 7576 |
-- K : Ada.Tags.Tagged_Kind := |
| 7577 |
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); |
| 7578 |
-- P : Parameters := (Param1 .. ParamN); |
| 7579 |
-- S : Integer; |
| 7580 |
|
| 7581 |
-- begin |
| 7582 |
-- if K = Ada.Tags.TK_Limited_Tagged |
| 7583 |
-- or else K = Ada.Tags.TK_Tagged |
| 7584 |
-- then |
| 7585 |
-- <dispatching-call>; |
| 7586 |
-- -- <triggering-statements> (code factorized after if-stmt) |
| 7587 |
|
| 7588 |
-- else |
| 7589 |
-- S := |
| 7590 |
-- Ada.Tags.Get_Offset_Index |
| 7591 |
-- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>)); |
| 7592 |
|
| 7593 |
-- _Disp_Conditional_Select (<object>, S, P'Address, C, B); |
| 7594 |
|
| 7595 |
-- if C = POK_Protected_Entry |
| 7596 |
-- or else C = POK_Task_Entry |
| 7597 |
-- then |
| 7598 |
-- Param1 := P.Param1; |
| 7599 |
-- ... |
| 7600 |
-- ParamN := P.ParamN; |
| 7601 |
-- end if; |
| 7602 |
|
| 7603 |
-- if B then |
| 7604 |
-- if C = POK_Procedure |
| 7605 |
-- or else C = POK_Protected_Procedure |
| 7606 |
-- or else C = POK_Task_Procedure |
| 7607 |
-- then |
| 7608 |
-- <dispatching-call>; |
| 7609 |
-- end if; |
| 7610 |
|
| 7611 |
-- -- <triggering-statements> (code factorized after if-stmt) |
| 7612 |
-- else |
| 7613 |
-- <else-statements> |
| 7614 |
-- goto L0; -- skip triggering statements |
| 7615 |
-- end if; |
| 7616 |
-- end if; |
| 7617 |
-- <triggering-statements> |
| 7618 |
-- L0: |
| 7619 |
-- end; |
| 7620 |
|
| 7621 |
procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is |
| 7622 |
Loc : constant Source_Ptr := Sloc (N); |
| 7623 |
Alt : constant Node_Id := Entry_Call_Alternative (N); |
| 7624 |
Blk : Node_Id := Entry_Call_Statement (Alt); |
| 7625 |
|
| 7626 |
Actuals : List_Id; |
| 7627 |
Blk_Typ : Entity_Id; |
| 7628 |
Call : Node_Id; |
| 7629 |
Call_Ent : Entity_Id; |
| 7630 |
Conc_Typ_Stmts : List_Id; |
| 7631 |
Decl : Node_Id; |
| 7632 |
Decls : List_Id; |
| 7633 |
Formals : List_Id; |
| 7634 |
Label : Node_Id; |
| 7635 |
Label_Id : Entity_Id := Empty; |
| 7636 |
Lim_Typ_Stmts : List_Id; |
| 7637 |
N_Stats : List_Id; |
| 7638 |
Obj : Entity_Id; |
| 7639 |
Param : Node_Id; |
| 7640 |
Params : List_Id; |
| 7641 |
Stmt : Node_Id; |
| 7642 |
Stmts : List_Id; |
| 7643 |
Transient_Blk : Node_Id; |
| 7644 |
Unpack : List_Id; |
| 7645 |
|
| 7646 |
B : Entity_Id; -- Call status flag |
| 7647 |
C : Entity_Id; -- Call kind |
| 7648 |
K : Entity_Id; -- Tagged kind |
| 7649 |
P : Entity_Id; -- Parameter block |
| 7650 |
S : Entity_Id; -- Primitive operation slot |
| 7651 |
|
| 7652 |
begin |
| 7653 |
Process_Statements_For_Controlled_Objects (N); |
| 7654 |
|
| 7655 |
if Ada_Version >= Ada_2005 |
| 7656 |
and then Nkind (Blk) = N_Procedure_Call_Statement |
| 7657 |
then |
| 7658 |
Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals); |
| 7659 |
|
| 7660 |
Decls := New_List; |
| 7661 |
Stmts := New_List; |
| 7662 |
|
| 7663 |
-- Call status flag processing, generate: |
| 7664 |
-- B : Boolean := False; |
| 7665 |
|
| 7666 |
B := Build_B (Loc, Decls); |
| 7667 |
|
| 7668 |
-- Call kind processing, generate: |
| 7669 |
-- C : Ada.Tags.Prim_Op_Kind; |
| 7670 |
|
| 7671 |
C := Build_C (Loc, Decls); |
| 7672 |
|
| 7673 |
-- Tagged kind processing, generate: |
| 7674 |
-- K : Ada.Tags.Tagged_Kind := |
| 7675 |
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); |
| 7676 |
|
| 7677 |
K := Build_K (Loc, Decls, Obj); |
| 7678 |
|
| 7679 |
-- Parameter block processing |
| 7680 |
|
| 7681 |
Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls); |
| 7682 |
P := Parameter_Block_Pack |
| 7683 |
(Loc, Blk_Typ, Actuals, Formals, Decls, Stmts); |
| 7684 |
|
| 7685 |
-- Dispatch table slot processing, generate: |
| 7686 |
-- S : Integer; |
| 7687 |
|
| 7688 |
S := Build_S (Loc, Decls); |
| 7689 |
|
| 7690 |
-- Generate: |
| 7691 |
-- S := Ada.Tags.Get_Offset_Index |
| 7692 |
-- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent)); |
| 7693 |
|
| 7694 |
Conc_Typ_Stmts := |
| 7695 |
New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent)); |
| 7696 |
|
| 7697 |
-- Generate: |
| 7698 |
-- _Disp_Conditional_Select (<object>, S, P'Address, C, B); |
| 7699 |
|
| 7700 |
Append_To (Conc_Typ_Stmts, |
| 7701 |
Make_Procedure_Call_Statement (Loc, |
| 7702 |
Name => |
| 7703 |
New_Occurrence_Of ( |
| 7704 |
Find_Prim_Op (Etype (Etype (Obj)), |
| 7705 |
Name_uDisp_Conditional_Select), |
| 7706 |
Loc), |
| 7707 |
Parameter_Associations => |
| 7708 |
New_List ( |
| 7709 |
New_Copy_Tree (Obj), -- <object> |
| 7710 |
New_Occurrence_Of (S, Loc), -- S |
| 7711 |
Make_Attribute_Reference (Loc, -- P'Address |
| 7712 |
Prefix => New_Occurrence_Of (P, Loc), |
| 7713 |
Attribute_Name => Name_Address), |
| 7714 |
New_Occurrence_Of (C, Loc), -- C |
| 7715 |
New_Occurrence_Of (B, Loc)))); -- B |
| 7716 |
|
| 7717 |
-- Generate: |
| 7718 |
-- if C = POK_Protected_Entry |
| 7719 |
-- or else C = POK_Task_Entry |
| 7720 |
-- then |
| 7721 |
-- Param1 := P.Param1; |
| 7722 |
-- ... |
| 7723 |
-- ParamN := P.ParamN; |
| 7724 |
-- end if; |
| 7725 |
|
| 7726 |
Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals); |
| 7727 |
|
| 7728 |
-- Generate the if statement only when the packed parameters need |
| 7729 |
-- explicit assignments to their corresponding actuals. |
| 7730 |
|
| 7731 |
if Present (Unpack) then |
| 7732 |
Append_To (Conc_Typ_Stmts, |
| 7733 |
Make_Implicit_If_Statement (N, |
| 7734 |
Condition => |
| 7735 |
Make_Or_Else (Loc, |
| 7736 |
Left_Opnd => |
| 7737 |
Make_Op_Eq (Loc, |
| 7738 |
Left_Opnd => |
| 7739 |
New_Occurrence_Of (C, Loc), |
| 7740 |
Right_Opnd => |
| 7741 |
New_Occurrence_Of (RTE ( |
| 7742 |
RE_POK_Protected_Entry), Loc)), |
| 7743 |
|
| 7744 |
Right_Opnd => |
| 7745 |
Make_Op_Eq (Loc, |
| 7746 |
Left_Opnd => |
| 7747 |
New_Occurrence_Of (C, Loc), |
| 7748 |
Right_Opnd => |
| 7749 |
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))), |
| 7750 |
|
| 7751 |
Then_Statements => Unpack)); |
| 7752 |
end if; |
| 7753 |
|
| 7754 |
-- Generate: |
| 7755 |
-- if B then |
| 7756 |
-- if C = POK_Procedure |
| 7757 |
-- or else C = POK_Protected_Procedure |
| 7758 |
-- or else C = POK_Task_Procedure |
| 7759 |
-- then |
| 7760 |
-- <dispatching-call> |
| 7761 |
-- end if; |
| 7762 |
-- -- <triggering-stataments> (code factorized after if-stmt) |
| 7763 |
-- else |
| 7764 |
-- <else-statements> |
| 7765 |
-- goto L0; -- skip triggering statements |
| 7766 |
-- end if; |
| 7767 |
|
| 7768 |
N_Stats := New_List; |
| 7769 |
|
| 7770 |
Prepend_To (N_Stats, |
| 7771 |
Make_Implicit_If_Statement (N, |
| 7772 |
Condition => |
| 7773 |
Make_Or_Else (Loc, |
| 7774 |
Left_Opnd => |
| 7775 |
Make_Op_Eq (Loc, |
| 7776 |
Left_Opnd => |
| 7777 |
New_Occurrence_Of (C, Loc), |
| 7778 |
Right_Opnd => |
| 7779 |
New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)), |
| 7780 |
|
| 7781 |
Right_Opnd => |
| 7782 |
Make_Or_Else (Loc, |
| 7783 |
Left_Opnd => |
| 7784 |
Make_Op_Eq (Loc, |
| 7785 |
Left_Opnd => |
| 7786 |
New_Occurrence_Of (C, Loc), |
| 7787 |
Right_Opnd => |
| 7788 |
New_Occurrence_Of (RTE ( |
| 7789 |
RE_POK_Protected_Procedure), Loc)), |
| 7790 |
|
| 7791 |
Right_Opnd => |
| 7792 |
Make_Op_Eq (Loc, |
| 7793 |
Left_Opnd => |
| 7794 |
New_Occurrence_Of (C, Loc), |
| 7795 |
Right_Opnd => |
| 7796 |
New_Occurrence_Of (RTE ( |
| 7797 |
RE_POK_Task_Procedure), Loc)))), |
| 7798 |
|
| 7799 |
Then_Statements => |
| 7800 |
New_List (Blk))); |
| 7801 |
|
| 7802 |
Label_Id := Make_Identifier (Loc, New_External_Name ('L', 0)); |
| 7803 |
Set_Entity (Label_Id, |
| 7804 |
Make_Defining_Identifier (Loc, Chars (Label_Id))); |
| 7805 |
|
| 7806 |
Append_To (Else_Statements (N), |
| 7807 |
Make_Goto_Statement (Loc, |
| 7808 |
Name => New_Occurrence_Of (Entity (Label_Id), Loc))); |
| 7809 |
|
| 7810 |
Append_To (Conc_Typ_Stmts, |
| 7811 |
Make_Implicit_If_Statement (N, |
| 7812 |
Condition => New_Occurrence_Of (B, Loc), |
| 7813 |
Then_Statements => N_Stats, |
| 7814 |
Else_Statements => Else_Statements (N))); |
| 7815 |
|
| 7816 |
-- Generate: |
| 7817 |
-- <dispatching-call>; |
| 7818 |
-- -- <triggering-statements> (code factorized after if-stmt) |
| 7819 |
|
| 7820 |
Lim_Typ_Stmts := New_List (New_Copy_Tree (Blk)); |
| 7821 |
|
| 7822 |
-- Generate: |
| 7823 |
-- if K = Ada.Tags.TK_Limited_Tagged |
| 7824 |
-- or else K = Ada.Tags.TK_Tagged |
| 7825 |
-- then |
| 7826 |
-- Lim_Typ_Stmts |
| 7827 |
-- else |
| 7828 |
-- Conc_Typ_Stmts |
| 7829 |
-- end if; |
| 7830 |
|
| 7831 |
Append_To (Stmts, |
| 7832 |
Make_Implicit_If_Statement (N, |
| 7833 |
Condition => Build_Dispatching_Tag_Check (K, N), |
| 7834 |
Then_Statements => Lim_Typ_Stmts, |
| 7835 |
Else_Statements => Conc_Typ_Stmts)); |
| 7836 |
|
| 7837 |
Label := Make_Label (Loc, Label_Id); |
| 7838 |
Append_To (Decls, |
| 7839 |
Make_Implicit_Label_Declaration (Loc, |
| 7840 |
Defining_Identifier => Entity (Label_Id), |
| 7841 |
Label_Construct => Label)); |
| 7842 |
|
| 7843 |
Append_List_To (Stmts, Statements (Alt)); -- triggering-statements |
| 7844 |
Append_To (Stmts, Label); |
| 7845 |
|
| 7846 |
Rewrite (N, |
| 7847 |
Make_Block_Statement (Loc, |
| 7848 |
Declarations => |
| 7849 |
Decls, |
| 7850 |
Handled_Statement_Sequence => |
| 7851 |
Make_Handled_Sequence_Of_Statements (Loc, Stmts))); |
| 7852 |
|
| 7853 |
-- As described above, the entry alternative is transformed into a |
| 7854 |
-- block that contains the gnulli call, and possibly assignment |
| 7855 |
-- statements for in-out parameters. The gnulli call may itself be |
| 7856 |
-- rewritten into a transient block if some unconstrained parameters |
| 7857 |
-- require it. We need to retrieve the call to complete its parameter |
| 7858 |
-- list. |
| 7859 |
|
| 7860 |
else |
| 7861 |
Transient_Blk := |
| 7862 |
First (Statements (Handled_Statement_Sequence (Blk))); |
| 7863 |
|
| 7864 |
if Present (Transient_Blk) |
| 7865 |
and then Nkind (Transient_Blk) = N_Block_Statement |
| 7866 |
then |
| 7867 |
Blk := Transient_Blk; |
| 7868 |
end if; |
| 7869 |
|
| 7870 |
Stmts := Statements (Handled_Statement_Sequence (Blk)); |
| 7871 |
Stmt := First (Stmts); |
| 7872 |
while Nkind (Stmt) /= N_Procedure_Call_Statement loop |
| 7873 |
Next (Stmt); |
| 7874 |
end loop; |
| 7875 |
|
| 7876 |
Call := Stmt; |
| 7877 |
Params := Parameter_Associations (Call); |
| 7878 |
|
| 7879 |
if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then |
| 7880 |
|
| 7881 |
-- Substitute Conditional_Entry_Call for Simple_Call parameter |
| 7882 |
|
| 7883 |
Param := First (Params); |
| 7884 |
while Present (Param) |
| 7885 |
and then not Is_RTE (Etype (Param), RE_Call_Modes) |
| 7886 |
loop |
| 7887 |
Next (Param); |
| 7888 |
end loop; |
| 7889 |
|
| 7890 |
pragma Assert (Present (Param)); |
| 7891 |
Rewrite (Param, |
| 7892 |
New_Occurrence_Of (RTE (RE_Conditional_Call), Loc)); |
| 7893 |
|
| 7894 |
Analyze (Param); |
| 7895 |
|
| 7896 |
-- Find the Communication_Block parameter for the call to the |
| 7897 |
-- Cancelled function. |
| 7898 |
|
| 7899 |
Decl := First (Declarations (Blk)); |
| 7900 |
while Present (Decl) |
| 7901 |
and then not Is_RTE (Etype (Object_Definition (Decl)), |
| 7902 |
RE_Communication_Block) |
| 7903 |
loop |
| 7904 |
Next (Decl); |
| 7905 |
end loop; |
| 7906 |
|
| 7907 |
-- Add an if statement to execute the else part if the call |
| 7908 |
-- does not succeed (as indicated by the Cancelled predicate). |
| 7909 |
|
| 7910 |
Append_To (Stmts, |
| 7911 |
Make_Implicit_If_Statement (N, |
| 7912 |
Condition => Make_Function_Call (Loc, |
| 7913 |
Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc), |
| 7914 |
Parameter_Associations => New_List ( |
| 7915 |
New_Occurrence_Of (Defining_Identifier (Decl), Loc))), |
| 7916 |
Then_Statements => Else_Statements (N), |
| 7917 |
Else_Statements => Statements (Alt))); |
| 7918 |
|
| 7919 |
else |
| 7920 |
B := Make_Defining_Identifier (Loc, Name_uB); |
| 7921 |
|
| 7922 |
-- Insert declaration of B in declarations of existing block |
| 7923 |
|
| 7924 |
if No (Declarations (Blk)) then |
| 7925 |
Set_Declarations (Blk, New_List); |
| 7926 |
end if; |
| 7927 |
|
| 7928 |
Prepend_To (Declarations (Blk), |
| 7929 |
Make_Object_Declaration (Loc, |
| 7930 |
Defining_Identifier => B, |
| 7931 |
Object_Definition => |
| 7932 |
New_Occurrence_Of (Standard_Boolean, Loc))); |
| 7933 |
|
| 7934 |
-- Create new call statement |
| 7935 |
|
| 7936 |
Append_To (Params, |
| 7937 |
New_Occurrence_Of (RTE (RE_Conditional_Call), Loc)); |
| 7938 |
Append_To (Params, New_Occurrence_Of (B, Loc)); |
| 7939 |
|
| 7940 |
Rewrite (Call, |
| 7941 |
Make_Procedure_Call_Statement (Loc, |
| 7942 |
Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc), |
| 7943 |
Parameter_Associations => Params)); |
| 7944 |
|
| 7945 |
-- Construct statement sequence for new block |
| 7946 |
|
| 7947 |
Append_To (Stmts, |
| 7948 |
Make_Implicit_If_Statement (N, |
| 7949 |
Condition => New_Occurrence_Of (B, Loc), |
| 7950 |
Then_Statements => Statements (Alt), |
| 7951 |
Else_Statements => Else_Statements (N))); |
| 7952 |
end if; |
| 7953 |
|
| 7954 |
-- The result is the new block |
| 7955 |
|
| 7956 |
Rewrite (N, |
| 7957 |
Make_Block_Statement (Loc, |
| 7958 |
Declarations => Declarations (Blk), |
| 7959 |
Handled_Statement_Sequence => |
| 7960 |
Make_Handled_Sequence_Of_Statements (Loc, Stmts))); |
| 7961 |
end if; |
| 7962 |
|
| 7963 |
Analyze (N); |
| 7964 |
|
| 7965 |
Reset_Scopes_To (N, Entity (Identifier (N))); |
| 7966 |
end Expand_N_Conditional_Entry_Call; |
| 7967 |
|
| 7968 |
--------------------------------------- |
| 7969 |
-- Expand_N_Delay_Relative_Statement -- |
| 7970 |
--------------------------------------- |
| 7971 |
|
| 7972 |
-- Delay statement is implemented as a procedure call to Delay_For |
| 7973 |
-- defined in Ada.Calendar.Delays in order to reduce the overhead of |
| 7974 |
-- simple delays imposed by the use of Protected Objects. |
| 7975 |
|
| 7976 |
procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is |
| 7977 |
Loc : constant Source_Ptr := Sloc (N); |
| 7978 |
Proc : Entity_Id; |
| 7979 |
|
| 7980 |
begin |
| 7981 |
-- Try to use Ada.Calendar.Delays.Delay_For if available. |
| 7982 |
|
| 7983 |
if RTE_Available (RO_CA_Delay_For) then |
| 7984 |
Proc := RTE (RO_CA_Delay_For); |
| 7985 |
|
| 7986 |
-- Otherwise, use System.Relative_Delays.Delay_For and emit an error |
| 7987 |
-- message if not available. This is the implementation used on |
| 7988 |
-- restricted platforms when Ada.Calendar is not available. |
| 7989 |
|
| 7990 |
else |
| 7991 |
Proc := RTE (RO_RD_Delay_For); |
| 7992 |
end if; |
| 7993 |
|
| 7994 |
Rewrite (N, |
| 7995 |
Make_Procedure_Call_Statement (Loc, |
| 7996 |
Name => New_Occurrence_Of (Proc, Loc), |
| 7997 |
Parameter_Associations => New_List (Expression (N)))); |
| 7998 |
Analyze (N); |
| 7999 |
end Expand_N_Delay_Relative_Statement; |
| 8000 |
|
| 8001 |
------------------------------------ |
| 8002 |
-- Expand_N_Delay_Until_Statement -- |
| 8003 |
------------------------------------ |
| 8004 |
|
| 8005 |
-- Delay Until statement is implemented as a procedure call to |
| 8006 |
-- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays. |
| 8007 |
|
| 8008 |
procedure Expand_N_Delay_Until_Statement (N : Node_Id) is |
| 8009 |
Loc : constant Source_Ptr := Sloc (N); |
| 8010 |
Typ : Entity_Id; |
| 8011 |
|
| 8012 |
begin |
| 8013 |
if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then |
| 8014 |
Typ := RTE (RO_CA_Delay_Until); |
| 8015 |
else |
| 8016 |
Typ := RTE (RO_RT_Delay_Until); |
| 8017 |
end if; |
| 8018 |
|
| 8019 |
Rewrite (N, |
| 8020 |
Make_Procedure_Call_Statement (Loc, |
| 8021 |
Name => New_Occurrence_Of (Typ, Loc), |
| 8022 |
Parameter_Associations => New_List (Expression (N)))); |
| 8023 |
|
| 8024 |
Analyze (N); |
| 8025 |
end Expand_N_Delay_Until_Statement; |
| 8026 |
|
| 8027 |
------------------------- |
| 8028 |
-- Expand_N_Entry_Body -- |
| 8029 |
------------------------- |
| 8030 |
|
| 8031 |
procedure Expand_N_Entry_Body (N : Node_Id) is |
| 8032 |
begin |
| 8033 |
-- Associate discriminals with the next protected operation body to be |
| 8034 |
-- expanded. |
| 8035 |
|
| 8036 |
if Present (Next_Protected_Operation (N)) then |
| 8037 |
Set_Discriminals (Parent (Current_Scope)); |
| 8038 |
end if; |
| 8039 |
end Expand_N_Entry_Body; |
| 8040 |
|
| 8041 |
----------------------------------- |
| 8042 |
-- Expand_N_Entry_Call_Statement -- |
| 8043 |
----------------------------------- |
| 8044 |
|
| 8045 |
-- An entry call is expanded into GNARLI calls to implement a simple entry |
| 8046 |
-- call (see Build_Simple_Entry_Call). |
| 8047 |
|
| 8048 |
procedure Expand_N_Entry_Call_Statement (N : Node_Id) is |
| 8049 |
Concval : Node_Id; |
| 8050 |
Ename : Node_Id; |
| 8051 |
Index : Node_Id; |
| 8052 |
|
| 8053 |
begin |
| 8054 |
if No_Run_Time_Mode then |
| 8055 |
Error_Msg_CRT ("entry call", N); |
| 8056 |
return; |
| 8057 |
end if; |
| 8058 |
|
| 8059 |
-- If this entry call is part of an asynchronous select, don't expand it |
| 8060 |
-- here; it will be expanded with the select statement. Don't expand |
| 8061 |
-- timed entry calls either, as they are translated into asynchronous |
| 8062 |
-- entry calls. |
| 8063 |
|
| 8064 |
-- ??? This whole approach is questionable; it may be better to go back |
| 8065 |
-- to allowing the expansion to take place and then attempting to fix it |
| 8066 |
-- up in Expand_N_Asynchronous_Select. The tricky part is figuring out |
| 8067 |
-- whether the expanded call is on a task or protected entry. |
| 8068 |
|
| 8069 |
if (Nkind (Parent (N)) /= N_Triggering_Alternative |
| 8070 |
or else N /= Triggering_Statement (Parent (N))) |
| 8071 |
and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative |
| 8072 |
or else N /= Entry_Call_Statement (Parent (N)) |
| 8073 |
or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call) |
| 8074 |
then |
| 8075 |
Extract_Entry (N, Concval, Ename, Index); |
| 8076 |
Build_Simple_Entry_Call (N, Concval, Ename, Index); |
| 8077 |
end if; |
| 8078 |
end Expand_N_Entry_Call_Statement; |
| 8079 |
|
| 8080 |
-------------------------------- |
| 8081 |
-- Expand_N_Entry_Declaration -- |
| 8082 |
-------------------------------- |
| 8083 |
|
| 8084 |
-- If there are parameters, then first, each of the formals is marked by |
| 8085 |
-- setting Is_Entry_Formal. Next a record type is built which is used to |
| 8086 |
-- hold the parameter values. The name of this record type is entryP where |
| 8087 |
-- entry is the name of the entry, with an additional corresponding access |
| 8088 |
-- type called entryPA. The record type has matching components for each |
| 8089 |
-- formal (the component names are the same as the formal names). For |
| 8090 |
-- elementary types, the component type matches the formal type. For |
| 8091 |
-- composite types, an access type is declared (with the name formalA) |
| 8092 |
-- which designates the formal type, and the type of the component is this |
| 8093 |
-- access type. Finally the Entry_Component of each formal is set to |
| 8094 |
-- reference the corresponding record component. |
| 8095 |
|
| 8096 |
procedure Expand_N_Entry_Declaration (N : Node_Id) is |
| 8097 |
Loc : constant Source_Ptr := Sloc (N); |
| 8098 |
Entry_Ent : constant Entity_Id := Defining_Identifier (N); |
| 8099 |
Components : List_Id; |
| 8100 |
Formal : Node_Id; |
| 8101 |
Ftype : Entity_Id; |
| 8102 |
Last_Decl : Node_Id; |
| 8103 |
Component : Entity_Id; |
| 8104 |
Ctype : Entity_Id; |
| 8105 |
Decl : Node_Id; |
| 8106 |
Rec_Ent : Entity_Id; |
| 8107 |
Acc_Ent : Entity_Id; |
| 8108 |
|
| 8109 |
begin |
| 8110 |
Formal := First_Formal (Entry_Ent); |
| 8111 |
Last_Decl := N; |
| 8112 |
|
| 8113 |
-- Most processing is done only if parameters are present |
| 8114 |
|
| 8115 |
if Present (Formal) then |
| 8116 |
Components := New_List; |
| 8117 |
|
| 8118 |
-- Loop through formals |
| 8119 |
|
| 8120 |
while Present (Formal) loop |
| 8121 |
Set_Is_Entry_Formal (Formal); |
| 8122 |
Component := |
| 8123 |
Make_Defining_Identifier (Sloc (Formal), Chars (Formal)); |
| 8124 |
Set_Entry_Component (Formal, Component); |
| 8125 |
Set_Entry_Formal (Component, Formal); |
| 8126 |
Ftype := Etype (Formal); |
| 8127 |
|
| 8128 |
-- Declare new access type and then append |
| 8129 |
|
| 8130 |
Ctype := Make_Temporary (Loc, 'A'); |
| 8131 |
Set_Is_Param_Block_Component_Type (Ctype); |
| 8132 |
|
| 8133 |
Decl := |
| 8134 |
Make_Full_Type_Declaration (Loc, |
| 8135 |
Defining_Identifier => Ctype, |
| 8136 |
Type_Definition => |
| 8137 |
Make_Access_To_Object_Definition (Loc, |
| 8138 |
All_Present => True, |
| 8139 |
Constant_Present => Ekind (Formal) = E_In_Parameter, |
| 8140 |
Subtype_Indication => New_Occurrence_Of (Ftype, Loc))); |
| 8141 |
|
| 8142 |
Insert_After (Last_Decl, Decl); |
| 8143 |
Last_Decl := Decl; |
| 8144 |
|
| 8145 |
Append_To (Components, |
| 8146 |
Make_Component_Declaration (Loc, |
| 8147 |
Defining_Identifier => Component, |
| 8148 |
Component_Definition => |
| 8149 |
Make_Component_Definition (Loc, |
| 8150 |
Subtype_Indication => New_Occurrence_Of (Ctype, Loc)))); |
| 8151 |
|
| 8152 |
Next_Formal_With_Extras (Formal); |
| 8153 |
end loop; |
| 8154 |
|
| 8155 |
-- Create the Entry_Parameter_Record declaration |
| 8156 |
|
| 8157 |
Rec_Ent := Make_Temporary (Loc, 'P'); |
| 8158 |
|
| 8159 |
Decl := |
| 8160 |
Make_Full_Type_Declaration (Loc, |
| 8161 |
Defining_Identifier => Rec_Ent, |
| 8162 |
Type_Definition => |
| 8163 |
Make_Record_Definition (Loc, |
| 8164 |
Component_List => |
| 8165 |
Make_Component_List (Loc, |
| 8166 |
Component_Items => Components))); |
| 8167 |
|
| 8168 |
Insert_After (Last_Decl, Decl); |
| 8169 |
Last_Decl := Decl; |
| 8170 |
|
| 8171 |
-- Construct and link in the corresponding access type |
| 8172 |
|
| 8173 |
Acc_Ent := Make_Temporary (Loc, 'A'); |
| 8174 |
|
| 8175 |
Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent); |
| 8176 |
|
| 8177 |
Decl := |
| 8178 |
Make_Full_Type_Declaration (Loc, |
| 8179 |
Defining_Identifier => Acc_Ent, |
| 8180 |
Type_Definition => |
| 8181 |
Make_Access_To_Object_Definition (Loc, |
| 8182 |
All_Present => True, |
| 8183 |
Subtype_Indication => New_Occurrence_Of (Rec_Ent, Loc))); |
| 8184 |
|
| 8185 |
Insert_After (Last_Decl, Decl); |
| 8186 |
end if; |
| 8187 |
end Expand_N_Entry_Declaration; |
| 8188 |
|
| 8189 |
----------------------------- |
| 8190 |
-- Expand_N_Protected_Body -- |
| 8191 |
----------------------------- |
| 8192 |
|
| 8193 |
-- Protected bodies are expanded to the completion of the subprograms |
| 8194 |
-- created for the corresponding protected type. These are a protected and |
| 8195 |
-- unprotected version of each protected subprogram in the object, a |
| 8196 |
-- function to calculate each entry barrier, and a procedure to execute the |
| 8197 |
-- sequence of statements of each protected entry body. For example, for |
| 8198 |
-- protected type ptype: |
| 8199 |
|
| 8200 |
-- function entB |
| 8201 |
-- (O : System.Address; |
| 8202 |
-- E : Protected_Entry_Index) |
| 8203 |
-- return Boolean |
| 8204 |
-- is |
| 8205 |
-- <discriminant renamings> |
| 8206 |
-- <private object renamings> |
| 8207 |
-- begin |
| 8208 |
-- return <barrier expression>; |
| 8209 |
-- end entB; |
| 8210 |
|
| 8211 |
-- procedure pprocN (_object : in out poV;...) is |
| 8212 |
-- <discriminant renamings> |
| 8213 |
-- <private object renamings> |
| 8214 |
-- begin |
| 8215 |
-- <sequence of statements> |
| 8216 |
-- end pprocN; |
| 8217 |
|
| 8218 |
-- procedure pprocP (_object : in out poV;...) is |
| 8219 |
-- procedure _clean is |
| 8220 |
-- Pn : Boolean; |
| 8221 |
-- begin |
| 8222 |
-- ptypeS (_object, Pn); |
| 8223 |
-- Unlock (_object._object'Access); |
| 8224 |
-- Abort_Undefer.all; |
| 8225 |
-- end _clean; |
| 8226 |
|
| 8227 |
-- begin |
| 8228 |
-- Abort_Defer.all; |
| 8229 |
-- Lock (_object._object'Access); |
| 8230 |
-- pprocN (_object;...); |
| 8231 |
-- at end |
| 8232 |
-- _clean; |
| 8233 |
-- end pproc; |
| 8234 |
|
| 8235 |
-- function pfuncN (_object : poV;...) return Return_Type is |
| 8236 |
-- <discriminant renamings> |
| 8237 |
-- <private object renamings> |
| 8238 |
-- begin |
| 8239 |
-- <sequence of statements> |
| 8240 |
-- end pfuncN; |
| 8241 |
|
| 8242 |
-- function pfuncP (_object : poV) return Return_Type is |
| 8243 |
-- procedure _clean is |
| 8244 |
-- begin |
| 8245 |
-- Unlock (_object._object'Access); |
| 8246 |
-- Abort_Undefer.all; |
| 8247 |
-- end _clean; |
| 8248 |
|
| 8249 |
-- begin |
| 8250 |
-- Abort_Defer.all; |
| 8251 |
-- Lock (_object._object'Access); |
| 8252 |
-- return pfuncN (_object); |
| 8253 |
|
| 8254 |
-- at end |
| 8255 |
-- _clean; |
| 8256 |
-- end pfunc; |
| 8257 |
|
| 8258 |
-- procedure entE |
| 8259 |
-- (O : System.Address; |
| 8260 |
-- P : System.Address; |
| 8261 |
-- E : Protected_Entry_Index) |
| 8262 |
-- is |
| 8263 |
-- <discriminant renamings> |
| 8264 |
-- <private object renamings> |
| 8265 |
-- type poVP is access poV; |
| 8266 |
-- _Object : ptVP := ptVP!(O); |
| 8267 |
|
| 8268 |
-- begin |
| 8269 |
-- begin |
| 8270 |
-- <statement sequence> |
| 8271 |
-- Complete_Entry_Body (_Object._Object); |
| 8272 |
-- exception |
| 8273 |
-- when all others => |
| 8274 |
-- Exceptional_Complete_Entry_Body ( |
| 8275 |
-- _Object._Object, Get_GNAT_Exception); |
| 8276 |
-- end; |
| 8277 |
-- end entE; |
| 8278 |
|
| 8279 |
-- The type poV is the record created for the protected type to hold |
| 8280 |
-- the state of the protected object. |
| 8281 |
|
| 8282 |
procedure Expand_N_Protected_Body (N : Node_Id) is |
| 8283 |
Loc : constant Source_Ptr := Sloc (N); |
| 8284 |
Pid : constant Entity_Id := Corresponding_Spec (N); |
| 8285 |
|
| 8286 |
Lock_Free_Active : constant Boolean := Uses_Lock_Free (Pid); |
| 8287 |
-- This flag indicates whether the lock free implementation is active |
| 8288 |
|
| 8289 |
Current_Node : Node_Id; |
| 8290 |
Disp_Op_Body : Node_Id; |
| 8291 |
New_Op_Body : Node_Id; |
| 8292 |
New_Op_Spec : Node_Id; |
| 8293 |
Op_Body : Node_Id; |
| 8294 |
Op_Decl : Node_Id; |
| 8295 |
Op_Id : Entity_Id; |
| 8296 |
Op_Spec : Entity_Id; |
| 8297 |
|
| 8298 |
function Build_Dispatching_Subprogram_Body |
| 8299 |
(N : Node_Id; |
| 8300 |
Pid : Node_Id; |
| 8301 |
Prot_Bod : Node_Id) return Node_Id; |
| 8302 |
-- Build a dispatching version of the protected subprogram body. The |
| 8303 |
-- newly generated subprogram contains a call to the original protected |
| 8304 |
-- body. The following code is generated: |
| 8305 |
-- |
| 8306 |
-- function <protected-function-name> (Param1 .. ParamN) return |
| 8307 |
-- <return-type> is |
| 8308 |
-- begin |
| 8309 |
-- return <protected-function-name>P (Param1 .. ParamN); |
| 8310 |
-- end <protected-function-name>; |
| 8311 |
-- |
| 8312 |
-- or |
| 8313 |
-- |
| 8314 |
-- procedure <protected-procedure-name> (Param1 .. ParamN) is |
| 8315 |
-- begin |
| 8316 |
-- <protected-procedure-name>P (Param1 .. ParamN); |
| 8317 |
-- end <protected-procedure-name> |
| 8318 |
|
| 8319 |
procedure Unanalyze_Use_Clauses (Op_Body : Node_Id); |
| 8320 |
-- Use and Use_Type clauses in the tree rooted at Op_Body |
| 8321 |
-- that have already been analyzed need to be marked as unanalyzed |
| 8322 |
-- because otherwise they will be ineffective in their new context. |
| 8323 |
|
| 8324 |
--------------------------------------- |
| 8325 |
-- Build_Dispatching_Subprogram_Body -- |
| 8326 |
--------------------------------------- |
| 8327 |
|
| 8328 |
function Build_Dispatching_Subprogram_Body |
| 8329 |
(N : Node_Id; |
| 8330 |
Pid : Node_Id; |
| 8331 |
Prot_Bod : Node_Id) return Node_Id |
| 8332 |
is |
| 8333 |
Loc : constant Source_Ptr := Sloc (N); |
| 8334 |
Actuals : List_Id; |
| 8335 |
Formal : Node_Id; |
| 8336 |
Spec : Node_Id; |
| 8337 |
Stmts : List_Id; |
| 8338 |
|
| 8339 |
begin |
| 8340 |
-- Generate a specification without a letter suffix in order to |
| 8341 |
-- override an interface function or procedure. |
| 8342 |
|
| 8343 |
Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode); |
| 8344 |
|
| 8345 |
-- The formal parameters become the actuals of the protected function |
| 8346 |
-- or procedure call. |
| 8347 |
|
| 8348 |
Actuals := New_List; |
| 8349 |
Formal := First (Parameter_Specifications (Spec)); |
| 8350 |
while Present (Formal) loop |
| 8351 |
Append_To (Actuals, |
| 8352 |
Make_Identifier (Loc, Chars (Defining_Identifier (Formal)))); |
| 8353 |
Next (Formal); |
| 8354 |
end loop; |
| 8355 |
|
| 8356 |
if Nkind (Spec) = N_Procedure_Specification then |
| 8357 |
Stmts := |
| 8358 |
New_List ( |
| 8359 |
Make_Procedure_Call_Statement (Loc, |
| 8360 |
Name => |
| 8361 |
New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc), |
| 8362 |
Parameter_Associations => Actuals)); |
| 8363 |
|
| 8364 |
else |
| 8365 |
pragma Assert (Nkind (Spec) = N_Function_Specification); |
| 8366 |
|
| 8367 |
Stmts := |
| 8368 |
New_List ( |
| 8369 |
Make_Simple_Return_Statement (Loc, |
| 8370 |
Expression => |
| 8371 |
Make_Function_Call (Loc, |
| 8372 |
Name => |
| 8373 |
New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc), |
| 8374 |
Parameter_Associations => Actuals))); |
| 8375 |
end if; |
| 8376 |
|
| 8377 |
return |
| 8378 |
Make_Subprogram_Body (Loc, |
| 8379 |
Declarations => Empty_List, |
| 8380 |
Specification => Spec, |
| 8381 |
Handled_Statement_Sequence => |
| 8382 |
Make_Handled_Sequence_Of_Statements (Loc, Stmts)); |
| 8383 |
end Build_Dispatching_Subprogram_Body; |
| 8384 |
|
| 8385 |
--------------------------- |
| 8386 |
-- Unanalyze_Use_Clauses -- |
| 8387 |
--------------------------- |
| 8388 |
|
| 8389 |
procedure Unanalyze_Use_Clauses (Op_Body : Node_Id) is |
| 8390 |
|
| 8391 |
function Process_One_Node (N : Node_Id) return Traverse_Result; |
| 8392 |
-- If N is a use or use type node then unanalyze it. |
| 8393 |
|
| 8394 |
procedure Process_Tree is new Traverse_Proc (Process_One_Node); |
| 8395 |
|
| 8396 |
function Process_One_Node (N : Node_Id) return Traverse_Result is |
| 8397 |
begin |
| 8398 |
if Nkind (N) in N_Use_Package_Clause | N_Use_Type_Clause then |
| 8399 |
Set_Analyzed (N, False); |
| 8400 |
end if; |
| 8401 |
return OK; -- return Skip if Is_Analyzed (N) ? |
| 8402 |
end Process_One_Node; |
| 8403 |
|
| 8404 |
-- Start of processing for Analyze_Use_Clauses |
| 8405 |
|
| 8406 |
begin |
| 8407 |
Process_Tree (Op_Body); |
| 8408 |
end Unanalyze_Use_Clauses; |
| 8409 |
|
| 8410 |
-- Start of processing for Expand_N_Protected_Body |
| 8411 |
|
| 8412 |
begin |
| 8413 |
if No_Run_Time_Mode then |
| 8414 |
Error_Msg_CRT ("protected body", N); |
| 8415 |
return; |
| 8416 |
end if; |
| 8417 |
|
| 8418 |
-- This is the proper body corresponding to a stub. The declarations |
| 8419 |
-- must be inserted at the point of the stub, which in turn is in the |
| 8420 |
-- declarative part of the parent unit. |
| 8421 |
|
| 8422 |
if Nkind (Parent (N)) = N_Subunit then |
| 8423 |
Current_Node := Corresponding_Stub (Parent (N)); |
| 8424 |
else |
| 8425 |
Current_Node := N; |
| 8426 |
end if; |
| 8427 |
|
| 8428 |
Op_Body := First (Declarations (N)); |
| 8429 |
|
| 8430 |
-- The protected body is replaced with the bodies of its protected |
| 8431 |
-- operations, and the declarations for internal objects that may |
| 8432 |
-- have been created for entry family bounds. |
| 8433 |
|
| 8434 |
Rewrite (N, Make_Null_Statement (Sloc (N))); |
| 8435 |
Analyze (N); |
| 8436 |
|
| 8437 |
while Present (Op_Body) loop |
| 8438 |
case Nkind (Op_Body) is |
| 8439 |
when N_Subprogram_Declaration => |
| 8440 |
null; |
| 8441 |
|
| 8442 |
when N_Subprogram_Body => |
| 8443 |
Op_Spec := Corresponding_Spec (Op_Body); |
| 8444 |
|
| 8445 |
-- Do not create bodies for eliminated operations |
| 8446 |
|
| 8447 |
if not Is_Eliminated (Defining_Entity (Op_Body)) |
| 8448 |
and then not Is_Eliminated (Op_Spec) |
| 8449 |
then |
| 8450 |
if Lock_Free_Active then |
| 8451 |
New_Op_Body := |
| 8452 |
Build_Lock_Free_Unprotected_Subprogram_Body |
| 8453 |
(Op_Body, Pid); |
| 8454 |
else |
| 8455 |
New_Op_Body := |
| 8456 |
Build_Unprotected_Subprogram_Body (Op_Body, Pid); |
| 8457 |
end if; |
| 8458 |
|
| 8459 |
-- Ugly. |
| 8460 |
-- We are going to perform name resolution in analysis of |
| 8461 |
-- this new body, but any already-analyzed use clauses |
| 8462 |
-- will be ineffective in this new context unless we take |
| 8463 |
-- action to "reactivate" them. So that's what we do here. |
| 8464 |
-- We arguably shouldn't be performing name resolution |
| 8465 |
-- here (just like we shouldn't perform name resolution in |
| 8466 |
-- an expanded instance body), but that's a larger issue. |
| 8467 |
|
| 8468 |
Unanalyze_Use_Clauses (New_Op_Body); |
| 8469 |
|
| 8470 |
Insert_After (Current_Node, New_Op_Body); |
| 8471 |
Current_Node := New_Op_Body; |
| 8472 |
Analyze (New_Op_Body); |
| 8473 |
|
| 8474 |
New_Op_Spec := Corresponding_Spec (New_Op_Body); |
| 8475 |
|
| 8476 |
-- When the original subprogram body has nested subprograms, |
| 8477 |
-- the new body also has them, so set the flag accordingly. |
| 8478 |
|
| 8479 |
Set_Has_Nested_Subprogram |
| 8480 |
(New_Op_Spec, Has_Nested_Subprogram (New_Op_Spec)); |
| 8481 |
|
| 8482 |
-- Similarly, when the original subprogram body uses the |
| 8483 |
-- secondary stack, the new body also does. This is needed |
| 8484 |
-- when the cleanup actions of the subprogram are delayed |
| 8485 |
-- because it contains a package instance with a body. |
| 8486 |
|
| 8487 |
Set_Uses_Sec_Stack (New_Op_Spec, Uses_Sec_Stack (Op_Spec)); |
| 8488 |
|
| 8489 |
-- Now reset the scopes of the top-level nested subprograms |
| 8490 |
-- and other declaration entities so that they now refer to |
| 8491 |
-- the new body's entity (it would preferable to do this |
| 8492 |
-- within Build_Protected_Sub_Specification, which is called |
| 8493 |
-- from Build_Unprotected_Subprogram_Body, but the needed |
| 8494 |
-- subprogram entity isn't available via Corresponding_Spec |
| 8495 |
-- until after the above Analyze call). |
| 8496 |
|
| 8497 |
Reset_Scopes_To (New_Op_Body, New_Op_Spec); |
| 8498 |
|
| 8499 |
-- Build the corresponding protected operation. This is |
| 8500 |
-- needed only if this is a public or private operation of |
| 8501 |
-- the type. |
| 8502 |
|
| 8503 |
Op_Decl := Unit_Declaration_Node (Op_Spec); |
| 8504 |
|
| 8505 |
if Nkind (Parent (Op_Decl)) = N_Protected_Definition then |
| 8506 |
if Lock_Free_Active then |
| 8507 |
New_Op_Body := |
| 8508 |
Build_Lock_Free_Protected_Subprogram_Body |
| 8509 |
(Op_Body, Pid, Specification (New_Op_Body)); |
| 8510 |
else |
| 8511 |
New_Op_Body := |
| 8512 |
Build_Protected_Subprogram_Body |
| 8513 |
(Op_Body, Pid, Specification (New_Op_Body)); |
| 8514 |
end if; |
| 8515 |
|
| 8516 |
Insert_After (Current_Node, New_Op_Body); |
| 8517 |
Current_Node := New_Op_Body; |
| 8518 |
Analyze (New_Op_Body); |
| 8519 |
|
| 8520 |
-- Generate an overriding primitive operation body for |
| 8521 |
-- this subprogram if the protected type implements |
| 8522 |
-- an interface. |
| 8523 |
|
| 8524 |
if Ada_Version >= Ada_2005 |
| 8525 |
and then |
| 8526 |
Present (Interfaces (Corresponding_Record_Type (Pid))) |
| 8527 |
then |
| 8528 |
Disp_Op_Body := |
| 8529 |
Build_Dispatching_Subprogram_Body ( |
| 8530 |
Op_Body, Pid, New_Op_Body); |
| 8531 |
|
| 8532 |
Insert_After (Current_Node, Disp_Op_Body); |
| 8533 |
Current_Node := Disp_Op_Body; |
| 8534 |
Analyze (Disp_Op_Body); |
| 8535 |
end if; |
| 8536 |
end if; |
| 8537 |
end if; |
| 8538 |
|
| 8539 |
when N_Entry_Body => |
| 8540 |
Op_Id := Defining_Identifier (Op_Body); |
| 8541 |
New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid); |
| 8542 |
|
| 8543 |
Insert_After (Current_Node, New_Op_Body); |
| 8544 |
Current_Node := New_Op_Body; |
| 8545 |
Analyze (New_Op_Body); |
| 8546 |
|
| 8547 |
when N_Implicit_Label_Declaration => |
| 8548 |
null; |
| 8549 |
|
| 8550 |
when N_Call_Marker |
| 8551 |
| N_Itype_Reference |
| 8552 |
=> |
| 8553 |
New_Op_Body := New_Copy (Op_Body); |
| 8554 |
Insert_After (Current_Node, New_Op_Body); |
| 8555 |
Current_Node := New_Op_Body; |
| 8556 |
|
| 8557 |
when N_Freeze_Entity => |
| 8558 |
New_Op_Body := New_Copy (Op_Body); |
| 8559 |
|
| 8560 |
if Present (Entity (Op_Body)) |
| 8561 |
and then Freeze_Node (Entity (Op_Body)) = Op_Body |
| 8562 |
then |
| 8563 |
Set_Freeze_Node (Entity (Op_Body), New_Op_Body); |
| 8564 |
end if; |
| 8565 |
|
| 8566 |
Insert_After (Current_Node, New_Op_Body); |
| 8567 |
Current_Node := New_Op_Body; |
| 8568 |
Analyze (New_Op_Body); |
| 8569 |
|
| 8570 |
when N_Pragma => |
| 8571 |
New_Op_Body := New_Copy (Op_Body); |
| 8572 |
Insert_After (Current_Node, New_Op_Body); |
| 8573 |
Current_Node := New_Op_Body; |
| 8574 |
Analyze (New_Op_Body); |
| 8575 |
|
| 8576 |
when N_Object_Declaration => |
| 8577 |
pragma Assert (not Comes_From_Source (Op_Body)); |
| 8578 |
New_Op_Body := New_Copy (Op_Body); |
| 8579 |
Insert_After (Current_Node, New_Op_Body); |
| 8580 |
Current_Node := New_Op_Body; |
| 8581 |
Analyze (New_Op_Body); |
| 8582 |
|
| 8583 |
when others => |
| 8584 |
raise Program_Error; |
| 8585 |
end case; |
| 8586 |
|
| 8587 |
Next (Op_Body); |
| 8588 |
end loop; |
| 8589 |
|
| 8590 |
-- Finally, create the body of the function that maps an entry index |
| 8591 |
-- into the corresponding body index, except when there is no entry, or |
| 8592 |
-- in a Ravenscar-like profile. |
| 8593 |
|
| 8594 |
if Corresponding_Runtime_Package (Pid) = |
| 8595 |
System_Tasking_Protected_Objects_Entries |
| 8596 |
then |
| 8597 |
New_Op_Body := Build_Find_Body_Index (Pid); |
| 8598 |
Insert_After (Current_Node, New_Op_Body); |
| 8599 |
Current_Node := New_Op_Body; |
| 8600 |
Analyze (New_Op_Body); |
| 8601 |
end if; |
| 8602 |
|
| 8603 |
-- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the |
| 8604 |
-- protected body. At this point all wrapper specs have been created, |
| 8605 |
-- frozen and included in the dispatch table for the protected type. |
| 8606 |
|
| 8607 |
if Ada_Version >= Ada_2005 then |
| 8608 |
Build_Wrapper_Bodies (Loc, Pid, Current_Node); |
| 8609 |
end if; |
| 8610 |
end Expand_N_Protected_Body; |
| 8611 |
|
| 8612 |
----------------------------------------- |
| 8613 |
-- Expand_N_Protected_Type_Declaration -- |
| 8614 |
----------------------------------------- |
| 8615 |
|
| 8616 |
-- First we create a corresponding record type declaration used to |
| 8617 |
-- represent values of this protected type. |
| 8618 |
-- The general form of this type declaration is |
| 8619 |
|
| 8620 |
-- type poV (discriminants) is record |
| 8621 |
-- _Object : aliased <kind>Protection |
| 8622 |
-- [(<entry count> [, <handler count>])]; |
| 8623 |
-- [entry_family : array (bounds) of Void;] |
| 8624 |
-- <private data fields> |
| 8625 |
-- end record; |
| 8626 |
|
| 8627 |
-- The discriminants are present only if the corresponding protected type |
| 8628 |
-- has discriminants, and they exactly mirror the protected type |
| 8629 |
-- discriminants. The private data fields similarly mirror the private |
| 8630 |
-- declarations of the protected type. |
| 8631 |
|
| 8632 |
-- The Object field is always present. It contains RTS specific data used |
| 8633 |
-- to control the protected object. It is declared as Aliased so that it |
| 8634 |
-- can be passed as a pointer to the RTS. This allows the protected record |
| 8635 |
-- to be referenced within RTS data structures. An appropriate Protection |
| 8636 |
-- type and discriminant are generated. |
| 8637 |
|
| 8638 |
-- The Service field is present for protected objects with entries. It |
| 8639 |
-- contains sufficient information to allow the entry service procedure for |
| 8640 |
-- this object to be called when the object is not known till runtime. |
| 8641 |
|
| 8642 |
-- One entry_family component is present for each entry family in the |
| 8643 |
-- task definition (see Expand_N_Task_Type_Declaration). |
| 8644 |
|
| 8645 |
-- When a protected object is declared, an instance of the protected type |
| 8646 |
-- value record is created. The elaboration of this declaration creates the |
| 8647 |
-- correct bounds for the entry families, and also evaluates the priority |
| 8648 |
-- expression if needed. The initialization routine for the protected type |
| 8649 |
-- itself then calls Initialize_Protection with appropriate parameters to |
| 8650 |
-- initialize the value of the Task_Id field. Install_Handlers may be also |
| 8651 |
-- called if a pragma Attach_Handler applies. |
| 8652 |
|
| 8653 |
-- Note: this record is passed to the subprograms created by the expansion |
| 8654 |
-- of protected subprograms and entries. It is an in parameter to protected |
| 8655 |
-- functions and an in out parameter to procedures and entry bodies. The |
| 8656 |
-- Entity_Id for this created record type is placed in the |
| 8657 |
-- Corresponding_Record_Type field of the associated protected type entity. |
| 8658 |
|
| 8659 |
-- Next we create a procedure specifications for protected subprograms and |
| 8660 |
-- entry bodies. For each protected subprograms two subprograms are |
| 8661 |
-- created, an unprotected and a protected version. The unprotected version |
| 8662 |
-- is called from within other operations of the same protected object. |
| 8663 |
|
| 8664 |
-- We also build the call to register the procedure if a pragma |
| 8665 |
-- Interrupt_Handler applies. |
| 8666 |
|
| 8667 |
-- A single subprogram is created to service all entry bodies; it has an |
| 8668 |
-- additional boolean out parameter indicating that the previous entry call |
| 8669 |
-- made by the current task was serviced immediately, i.e. not by proxy. |
| 8670 |
-- The O parameter contains a pointer to a record object of the type |
| 8671 |
-- described above. An untyped interface is used here to allow this |
| 8672 |
-- procedure to be called in places where the type of the object to be |
| 8673 |
-- serviced is not known. This must be done, for example, when a call that |
| 8674 |
-- may have been requeued is cancelled; the corresponding object must be |
| 8675 |
-- serviced, but which object that is not known till runtime. |
| 8676 |
|
| 8677 |
-- procedure ptypeS |
| 8678 |
-- (O : System.Address; P : out Boolean); |
| 8679 |
-- procedure pprocN (_object : in out poV); |
| 8680 |
-- procedure pproc (_object : in out poV); |
| 8681 |
-- function pfuncN (_object : poV); |
| 8682 |
-- function pfunc (_object : poV); |
| 8683 |
-- ... |
| 8684 |
|
| 8685 |
-- Note that this must come after the record type declaration, since |
| 8686 |
-- the specs refer to this type. |
| 8687 |
|
| 8688 |
procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is |
| 8689 |
Discr_Map : constant Elist_Id := New_Elmt_List; |
| 8690 |
Loc : constant Source_Ptr := Sloc (N); |
| 8691 |
Prot_Typ : constant Entity_Id := Defining_Identifier (N); |
| 8692 |
|
| 8693 |
Lock_Free_Active : constant Boolean := Uses_Lock_Free (Prot_Typ); |
| 8694 |
-- This flag indicates whether the lock free implementation is active |
| 8695 |
|
| 8696 |
Pdef : constant Node_Id := Protected_Definition (N); |
| 8697 |
-- This contains two lists; one for visible and one for private decls |
| 8698 |
|
| 8699 |
Current_Node : Node_Id := N; |
| 8700 |
E_Count : Int; |
| 8701 |
Entries_Aggr : Node_Id; |
| 8702 |
Rec_Decl : Node_Id; |
| 8703 |
Rec_Id : Entity_Id; |
| 8704 |
|
| 8705 |
procedure Check_Inlining (Subp : Entity_Id); |
| 8706 |
-- If the original operation has a pragma Inline, propagate the flag |
| 8707 |
-- to the internal body, for possible inlining later on. The source |
| 8708 |
-- operation is invisible to the back-end and is never actually called. |
| 8709 |
|
| 8710 |
procedure Expand_Entry_Declaration (Decl : Node_Id); |
| 8711 |
-- Create the entry barrier and the procedure body for entry declaration |
| 8712 |
-- Decl. All generated subprograms are added to Entry_Bodies_Array. |
| 8713 |
|
| 8714 |
function Static_Component_Size (Comp : Entity_Id) return Boolean; |
| 8715 |
-- When compiling under the Ravenscar profile, private components must |
| 8716 |
-- have a static size, or else a protected object will require heap |
| 8717 |
-- allocation, violating the corresponding restriction. It is preferable |
| 8718 |
-- to make this check here, because it provides a better error message |
| 8719 |
-- than the back-end, which refers to the object as a whole. |
| 8720 |
|
| 8721 |
procedure Register_Handler; |
| 8722 |
-- For a protected operation that is an interrupt handler, add the |
| 8723 |
-- freeze action that will register it as such. |
| 8724 |
|
| 8725 |
procedure Replace_Access_Definition (Comp : Node_Id); |
| 8726 |
-- If a private component of the type is an access to itself, this |
| 8727 |
-- is not a reference to the current instance, but an access type out |
| 8728 |
-- of which one might construct a list. If such a component exists, we |
| 8729 |
-- create an incomplete type for the equivalent record type, and |
| 8730 |
-- a named access type for it, that replaces the access definition |
| 8731 |
-- of the original component. This is similar to what is done for |
| 8732 |
-- records in Check_Anonymous_Access_Components, but simpler, because |
| 8733 |
-- the corresponding record type has no previous declaration. |
| 8734 |
-- This needs to be done only once, even if there are several such |
| 8735 |
-- access components. The following entity stores the constructed |
| 8736 |
-- access type. |
| 8737 |
|
| 8738 |
Acc_T : Entity_Id := Empty; |
| 8739 |
|
| 8740 |
-------------------- |
| 8741 |
-- Check_Inlining -- |
| 8742 |
-------------------- |
| 8743 |
|
| 8744 |
procedure Check_Inlining (Subp : Entity_Id) is |
| 8745 |
begin |
| 8746 |
if Is_Inlined (Subp) then |
| 8747 |
Set_Is_Inlined (Protected_Body_Subprogram (Subp)); |
| 8748 |
Set_Is_Inlined (Subp, False); |
| 8749 |
end if; |
| 8750 |
|
| 8751 |
if Has_Pragma_No_Inline (Subp) then |
| 8752 |
Set_Has_Pragma_No_Inline (Protected_Body_Subprogram (Subp)); |
| 8753 |
end if; |
| 8754 |
end Check_Inlining; |
| 8755 |
|
| 8756 |
--------------------------- |
| 8757 |
-- Static_Component_Size -- |
| 8758 |
--------------------------- |
| 8759 |
|
| 8760 |
function Static_Component_Size (Comp : Entity_Id) return Boolean is |
| 8761 |
Typ : constant Entity_Id := Etype (Comp); |
| 8762 |
C : Entity_Id; |
| 8763 |
|
| 8764 |
begin |
| 8765 |
if Is_Scalar_Type (Typ) then |
| 8766 |
return True; |
| 8767 |
|
| 8768 |
elsif Is_Array_Type (Typ) then |
| 8769 |
return Compile_Time_Known_Bounds (Typ); |
| 8770 |
|
| 8771 |
elsif Is_Record_Type (Typ) then |
| 8772 |
C := First_Component (Typ); |
| 8773 |
while Present (C) loop |
| 8774 |
if not Static_Component_Size (C) then |
| 8775 |
return False; |
| 8776 |
end if; |
| 8777 |
|
| 8778 |
Next_Component (C); |
| 8779 |
end loop; |
| 8780 |
|
| 8781 |
return True; |
| 8782 |
|
| 8783 |
-- Any other type will be checked by the back-end |
| 8784 |
|
| 8785 |
else |
| 8786 |
return True; |
| 8787 |
end if; |
| 8788 |
end Static_Component_Size; |
| 8789 |
|
| 8790 |
------------------------------ |
| 8791 |
-- Expand_Entry_Declaration -- |
| 8792 |
------------------------------ |
| 8793 |
|
| 8794 |
procedure Expand_Entry_Declaration (Decl : Node_Id) is |
| 8795 |
Ent_Id : constant Entity_Id := Defining_Entity (Decl); |
| 8796 |
Bar_Id : Entity_Id; |
| 8797 |
Bod_Id : Entity_Id; |
| 8798 |
Subp : Node_Id; |
| 8799 |
|
| 8800 |
begin |
| 8801 |
E_Count := E_Count + 1; |
| 8802 |
|
| 8803 |
-- Create the protected body subprogram |
| 8804 |
|
| 8805 |
Bod_Id := |
| 8806 |
Make_Defining_Identifier (Loc, |
| 8807 |
Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'E')); |
| 8808 |
Set_Protected_Body_Subprogram (Ent_Id, Bod_Id); |
| 8809 |
|
| 8810 |
Subp := |
| 8811 |
Make_Subprogram_Declaration (Loc, |
| 8812 |
Specification => |
| 8813 |
Build_Protected_Entry_Specification (Loc, Bod_Id, Ent_Id)); |
| 8814 |
|
| 8815 |
Insert_After (Current_Node, Subp); |
| 8816 |
Current_Node := Subp; |
| 8817 |
|
| 8818 |
Analyze (Subp); |
| 8819 |
|
| 8820 |
-- Build a wrapper procedure to handle contract cases, preconditions, |
| 8821 |
-- and postconditions. |
| 8822 |
|
| 8823 |
Build_Entry_Contract_Wrapper (Ent_Id, N); |
| 8824 |
|
| 8825 |
-- Create the barrier function |
| 8826 |
|
| 8827 |
Bar_Id := |
| 8828 |
Make_Defining_Identifier (Loc, |
| 8829 |
Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'B')); |
| 8830 |
Set_Barrier_Function (Ent_Id, Bar_Id); |
| 8831 |
|
| 8832 |
Subp := |
| 8833 |
Make_Subprogram_Declaration (Loc, |
| 8834 |
Specification => |
| 8835 |
Build_Barrier_Function_Specification (Loc, Bar_Id)); |
| 8836 |
Set_Is_Entry_Barrier_Function (Subp); |
| 8837 |
|
| 8838 |
Insert_After (Current_Node, Subp); |
| 8839 |
Current_Node := Subp; |
| 8840 |
|
| 8841 |
Analyze (Subp); |
| 8842 |
|
| 8843 |
Set_Protected_Body_Subprogram (Bar_Id, Bar_Id); |
| 8844 |
Set_Scope (Bar_Id, Scope (Ent_Id)); |
| 8845 |
|
| 8846 |
-- Collect pointers to the protected subprogram and the barrier |
| 8847 |
-- of the current entry, for insertion into Entry_Bodies_Array. |
| 8848 |
|
| 8849 |
Append_To (Expressions (Entries_Aggr), |
| 8850 |
Make_Aggregate (Loc, |
| 8851 |
Expressions => New_List ( |
| 8852 |
Make_Attribute_Reference (Loc, |
| 8853 |
Prefix => New_Occurrence_Of (Bar_Id, Loc), |
| 8854 |
Attribute_Name => Name_Unrestricted_Access), |
| 8855 |
Make_Attribute_Reference (Loc, |
| 8856 |
Prefix => New_Occurrence_Of (Bod_Id, Loc), |
| 8857 |
Attribute_Name => Name_Unrestricted_Access)))); |
| 8858 |
end Expand_Entry_Declaration; |
| 8859 |
|
| 8860 |
---------------------- |
| 8861 |
-- Register_Handler -- |
| 8862 |
---------------------- |
| 8863 |
|
| 8864 |
procedure Register_Handler is |
| 8865 |
|
| 8866 |
-- All semantic checks already done in Sem_Prag |
| 8867 |
|
| 8868 |
Prot_Proc : constant Entity_Id := |
| 8869 |
Defining_Unit_Name (Specification (Current_Node)); |
| 8870 |
|
| 8871 |
Proc_Address : constant Node_Id := |
| 8872 |
Make_Attribute_Reference (Loc, |
| 8873 |
Prefix => |
| 8874 |
New_Occurrence_Of (Prot_Proc, Loc), |
| 8875 |
Attribute_Name => Name_Address); |
| 8876 |
|
| 8877 |
RTS_Call : constant Entity_Id := |
| 8878 |
Make_Procedure_Call_Statement (Loc, |
| 8879 |
Name => |
| 8880 |
New_Occurrence_Of |
| 8881 |
(RTE (RE_Register_Interrupt_Handler), Loc), |
| 8882 |
Parameter_Associations => New_List (Proc_Address)); |
| 8883 |
begin |
| 8884 |
Append_Freeze_Action (Prot_Proc, RTS_Call); |
| 8885 |
end Register_Handler; |
| 8886 |
|
| 8887 |
------------------------------- |
| 8888 |
-- Replace_Access_Definition -- |
| 8889 |
------------------------------- |
| 8890 |
|
| 8891 |
procedure Replace_Access_Definition (Comp : Node_Id) is |
| 8892 |
Loc : constant Source_Ptr := Sloc (Comp); |
| 8893 |
Inc_T : Node_Id; |
| 8894 |
Inc_D : Node_Id; |
| 8895 |
Acc_Def : Node_Id; |
| 8896 |
Acc_D : Node_Id; |
| 8897 |
|
| 8898 |
begin |
| 8899 |
if No (Acc_T) then |
| 8900 |
Inc_T := Make_Defining_Identifier (Loc, Chars (Rec_Id)); |
| 8901 |
Inc_D := Make_Incomplete_Type_Declaration (Loc, Inc_T); |
| 8902 |
Acc_T := Make_Temporary (Loc, 'S'); |
| 8903 |
Acc_Def := |
| 8904 |
Make_Access_To_Object_Definition (Loc, |
| 8905 |
Subtype_Indication => New_Occurrence_Of (Inc_T, Loc)); |
| 8906 |
Acc_D := |
| 8907 |
Make_Full_Type_Declaration (Loc, |
| 8908 |
Defining_Identifier => Acc_T, |
| 8909 |
Type_Definition => Acc_Def); |
| 8910 |
|
| 8911 |
Insert_Before (Rec_Decl, Inc_D); |
| 8912 |
Analyze (Inc_D); |
| 8913 |
|
| 8914 |
Insert_Before (Rec_Decl, Acc_D); |
| 8915 |
Analyze (Acc_D); |
| 8916 |
end if; |
| 8917 |
|
| 8918 |
Set_Access_Definition (Comp, Empty); |
| 8919 |
Set_Subtype_Indication (Comp, New_Occurrence_Of (Acc_T, Loc)); |
| 8920 |
end Replace_Access_Definition; |
| 8921 |
|
| 8922 |
-- Local variables |
| 8923 |
|
| 8924 |
Body_Arr : Node_Id; |
| 8925 |
Body_Id : Entity_Id; |
| 8926 |
Cdecls : List_Id; |
| 8927 |
Comp : Node_Id; |
| 8928 |
Expr : Node_Id; |
| 8929 |
New_Priv : Node_Id; |
| 8930 |
Obj_Def : Node_Id; |
| 8931 |
Object_Comp : Node_Id; |
| 8932 |
Priv : Node_Id; |
| 8933 |
Sub : Node_Id; |
| 8934 |
|
| 8935 |
-- Start of processing for Expand_N_Protected_Type_Declaration |
| 8936 |
|
| 8937 |
begin |
| 8938 |
if Present (Corresponding_Record_Type (Prot_Typ)) then |
| 8939 |
return; |
| 8940 |
else |
| 8941 |
Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc); |
| 8942 |
Rec_Id := Defining_Identifier (Rec_Decl); |
| 8943 |
end if; |
| 8944 |
|
| 8945 |
Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl))); |
| 8946 |
|
| 8947 |
Qualify_Entity_Names (N); |
| 8948 |
|
| 8949 |
-- If the type has discriminants, their occurrences in the declaration |
| 8950 |
-- have been replaced by the corresponding discriminals. For components |
| 8951 |
-- that are constrained by discriminants, their homologues in the |
| 8952 |
-- corresponding record type must refer to the discriminants of that |
| 8953 |
-- record, so we must apply a new renaming to subtypes_indications: |
| 8954 |
|
| 8955 |
-- protected discriminant => discriminal => record discriminant |
| 8956 |
|
| 8957 |
-- This replacement is not applied to default expressions, for which |
| 8958 |
-- the discriminal is correct. |
| 8959 |
|
| 8960 |
if Has_Discriminants (Prot_Typ) then |
| 8961 |
declare |
| 8962 |
Disc : Entity_Id; |
| 8963 |
Decl : Node_Id; |
| 8964 |
|
| 8965 |
begin |
| 8966 |
Disc := First_Discriminant (Prot_Typ); |
| 8967 |
Decl := First (Discriminant_Specifications (Rec_Decl)); |
| 8968 |
while Present (Disc) loop |
| 8969 |
Append_Elmt (Discriminal (Disc), Discr_Map); |
| 8970 |
Append_Elmt (Defining_Identifier (Decl), Discr_Map); |
| 8971 |
Next_Discriminant (Disc); |
| 8972 |
Next (Decl); |
| 8973 |
end loop; |
| 8974 |
end; |
| 8975 |
end if; |
| 8976 |
|
| 8977 |
-- Fill in the component declarations |
| 8978 |
|
| 8979 |
-- Add components for entry families. For each entry family, create an |
| 8980 |
-- anonymous type declaration with the same size, and analyze the type. |
| 8981 |
|
| 8982 |
Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ); |
| 8983 |
|
| 8984 |
pragma Assert (Present (Pdef)); |
| 8985 |
|
| 8986 |
Insert_After (Current_Node, Rec_Decl); |
| 8987 |
Current_Node := Rec_Decl; |
| 8988 |
|
| 8989 |
-- Add private field components |
| 8990 |
|
| 8991 |
Priv := First (Private_Declarations (Pdef)); |
| 8992 |
while Present (Priv) loop |
| 8993 |
if Nkind (Priv) = N_Component_Declaration then |
| 8994 |
if not Static_Component_Size (Defining_Identifier (Priv)) then |
| 8995 |
|
| 8996 |
-- When compiling for a restricted profile, the private |
| 8997 |
-- components must have a static size. If not, this is an error |
| 8998 |
-- for a single protected declaration, and rates a warning on a |
| 8999 |
-- protected type declaration. |
| 9000 |
|
| 9001 |
if not Comes_From_Source (Prot_Typ) then |
| 9002 |
|
| 9003 |
-- It's ok to be checking this restriction at expansion |
| 9004 |
-- time, because this is only for the restricted profile, |
| 9005 |
-- which is not subject to strict RM conformance, so it |
| 9006 |
-- is OK to miss this check in -gnatc mode. |
| 9007 |
|
| 9008 |
Check_Restriction (No_Implicit_Heap_Allocations, Priv); |
| 9009 |
Check_Restriction |
| 9010 |
(No_Implicit_Protected_Object_Allocations, Priv); |
| 9011 |
|
| 9012 |
elsif Restriction_Active (No_Implicit_Heap_Allocations) then |
| 9013 |
if not Discriminated_Size (Defining_Identifier (Priv)) |
| 9014 |
then |
| 9015 |
-- Any object of the type will be non-static |
| 9016 |
|
| 9017 |
Error_Msg_N ("component has non-static size??", Priv); |
| 9018 |
Error_Msg_NE |
| 9019 |
("\creation of protected object of type& will " |
| 9020 |
& "violate restriction " |
| 9021 |
& "No_Implicit_Heap_Allocations??", Priv, Prot_Typ); |
| 9022 |
else |
| 9023 |
-- Object will be non-static if discriminants are |
| 9024 |
|
| 9025 |
Error_Msg_NE |
| 9026 |
("creation of protected object of type& with " |
| 9027 |
& "non-static discriminants will violate " |
| 9028 |
& "restriction No_Implicit_Heap_Allocations??", |
| 9029 |
Priv, Prot_Typ); |
| 9030 |
end if; |
| 9031 |
|
| 9032 |
-- Likewise for No_Implicit_Protected_Object_Allocations |
| 9033 |
|
| 9034 |
elsif Restriction_Active |
| 9035 |
(No_Implicit_Protected_Object_Allocations) |
| 9036 |
then |
| 9037 |
if not Discriminated_Size (Defining_Identifier (Priv)) then |
| 9038 |
-- Any object of the type will be non-static |
| 9039 |
|
| 9040 |
Error_Msg_N ("component has non-static size??", Priv); |
| 9041 |
Error_Msg_NE |
| 9042 |
("\creation of protected object of type& will violate " |
| 9043 |
& "restriction " |
| 9044 |
& "No_Implicit_Protected_Object_Allocations??", |
| 9045 |
Priv, Prot_Typ); |
| 9046 |
else |
| 9047 |
-- Object will be non-static if discriminants are |
| 9048 |
|
| 9049 |
Error_Msg_NE |
| 9050 |
("creation of protected object of type& with " |
| 9051 |
& "non-static discriminants will violate restriction " |
| 9052 |
& "No_Implicit_Protected_Object_Allocations??", |
| 9053 |
Priv, Prot_Typ); |
| 9054 |
end if; |
| 9055 |
end if; |
| 9056 |
end if; |
| 9057 |
|
| 9058 |
-- The component definition consists of a subtype indication, or |
| 9059 |
-- (in Ada 2005) an access definition. Make a copy of the proper |
| 9060 |
-- definition. |
| 9061 |
|
| 9062 |
declare |
| 9063 |
Old_Comp : constant Node_Id := Component_Definition (Priv); |
| 9064 |
Oent : constant Entity_Id := Defining_Identifier (Priv); |
| 9065 |
Nent : constant Entity_Id := |
| 9066 |
Make_Defining_Identifier (Sloc (Oent), |
| 9067 |
Chars => Chars (Oent)); |
| 9068 |
New_Comp : Node_Id; |
| 9069 |
|
| 9070 |
begin |
| 9071 |
if Present (Subtype_Indication (Old_Comp)) then |
| 9072 |
New_Comp := |
| 9073 |
Make_Component_Definition (Sloc (Oent), |
| 9074 |
Subtype_Indication => |
| 9075 |
New_Copy_Tree |
| 9076 |
(Subtype_Indication (Old_Comp), Discr_Map)); |
| 9077 |
else |
| 9078 |
New_Comp := |
| 9079 |
Make_Component_Definition (Sloc (Oent), |
| 9080 |
Access_Definition => |
| 9081 |
New_Copy_Tree |
| 9082 |
(Access_Definition (Old_Comp), Discr_Map)); |
| 9083 |
|
| 9084 |
-- A self-reference in the private part becomes a |
| 9085 |
-- self-reference to the corresponding record. |
| 9086 |
|
| 9087 |
if Entity (Subtype_Mark (Access_Definition (New_Comp))) |
| 9088 |
= Prot_Typ |
| 9089 |
then |
| 9090 |
Replace_Access_Definition (New_Comp); |
| 9091 |
end if; |
| 9092 |
end if; |
| 9093 |
|
| 9094 |
New_Priv := |
| 9095 |
Make_Component_Declaration (Loc, |
| 9096 |
Defining_Identifier => Nent, |
| 9097 |
Component_Definition => New_Comp, |
| 9098 |
Expression => Expression (Priv)); |
| 9099 |
|
| 9100 |
Set_Has_Per_Object_Constraint (Nent, |
| 9101 |
Has_Per_Object_Constraint (Oent)); |
| 9102 |
|
| 9103 |
Append_To (Cdecls, New_Priv); |
| 9104 |
end; |
| 9105 |
|
| 9106 |
elsif Nkind (Priv) = N_Subprogram_Declaration then |
| 9107 |
|
| 9108 |
-- Make the unprotected version of the subprogram available for |
| 9109 |
-- expansion of intra object calls. There is need for a protected |
| 9110 |
-- version only if the subprogram is an interrupt handler, |
| 9111 |
-- otherwise this operation can only be called from within the |
| 9112 |
-- body. |
| 9113 |
|
| 9114 |
Sub := |
| 9115 |
Make_Subprogram_Declaration (Loc, |
| 9116 |
Specification => |
| 9117 |
Build_Protected_Sub_Specification |
| 9118 |
(Priv, Prot_Typ, Unprotected_Mode)); |
| 9119 |
|
| 9120 |
Insert_After (Current_Node, Sub); |
| 9121 |
Analyze (Sub); |
| 9122 |
|
| 9123 |
Set_Protected_Body_Subprogram |
| 9124 |
(Defining_Unit_Name (Specification (Priv)), |
| 9125 |
Defining_Unit_Name (Specification (Sub))); |
| 9126 |
Check_Inlining (Defining_Unit_Name (Specification (Priv))); |
| 9127 |
Current_Node := Sub; |
| 9128 |
|
| 9129 |
Sub := |
| 9130 |
Make_Subprogram_Declaration (Loc, |
| 9131 |
Specification => |
| 9132 |
Build_Protected_Sub_Specification |
| 9133 |
(Priv, Prot_Typ, Protected_Mode)); |
| 9134 |
|
| 9135 |
Insert_After (Current_Node, Sub); |
| 9136 |
Analyze (Sub); |
| 9137 |
Current_Node := Sub; |
| 9138 |
|
| 9139 |
if Is_Interrupt_Handler |
| 9140 |
(Defining_Unit_Name (Specification (Priv))) |
| 9141 |
then |
| 9142 |
if not Restricted_Profile then |
| 9143 |
Register_Handler; |
| 9144 |
end if; |
| 9145 |
end if; |
| 9146 |
end if; |
| 9147 |
|
| 9148 |
Next (Priv); |
| 9149 |
end loop; |
| 9150 |
|
| 9151 |
-- Except for the lock-free implementation, append the _Object field |
| 9152 |
-- with the right type to the component list. We need to compute the |
| 9153 |
-- number of entries, and in some cases the number of Attach_Handler |
| 9154 |
-- pragmas. |
| 9155 |
|
| 9156 |
if not Lock_Free_Active then |
| 9157 |
declare |
| 9158 |
Entry_Count_Expr : constant Node_Id := |
| 9159 |
Build_Entry_Count_Expression |
| 9160 |
(Prot_Typ, Loc); |
| 9161 |
Num_Attach_Handler : Nat := 0; |
| 9162 |
Protection_Subtype : Node_Id; |
| 9163 |
Ritem : Node_Id; |
| 9164 |
|
| 9165 |
begin |
| 9166 |
if Has_Attach_Handler (Prot_Typ) then |
| 9167 |
Ritem := First_Rep_Item (Prot_Typ); |
| 9168 |
while Present (Ritem) loop |
| 9169 |
if Nkind (Ritem) = N_Pragma |
| 9170 |
and then Pragma_Name (Ritem) = Name_Attach_Handler |
| 9171 |
then |
| 9172 |
Num_Attach_Handler := Num_Attach_Handler + 1; |
| 9173 |
end if; |
| 9174 |
|
| 9175 |
Next_Rep_Item (Ritem); |
| 9176 |
end loop; |
| 9177 |
end if; |
| 9178 |
|
| 9179 |
-- Determine the proper protection type. There are two special |
| 9180 |
-- cases: 1) when the protected type has dynamic interrupt |
| 9181 |
-- handlers, and 2) when it has static handlers and we use a |
| 9182 |
-- restricted profile. |
| 9183 |
|
| 9184 |
if Has_Attach_Handler (Prot_Typ) |
| 9185 |
and then not Restricted_Profile |
| 9186 |
then |
| 9187 |
Protection_Subtype := |
| 9188 |
Make_Subtype_Indication (Loc, |
| 9189 |
Subtype_Mark => |
| 9190 |
New_Occurrence_Of |
| 9191 |
(RTE (RE_Static_Interrupt_Protection), Loc), |
| 9192 |
Constraint => |
| 9193 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 9194 |
Constraints => New_List ( |
| 9195 |
Entry_Count_Expr, |
| 9196 |
Make_Integer_Literal (Loc, Num_Attach_Handler)))); |
| 9197 |
|
| 9198 |
elsif Has_Interrupt_Handler (Prot_Typ) |
| 9199 |
and then not Restriction_Active (No_Dynamic_Attachment) |
| 9200 |
then |
| 9201 |
Protection_Subtype := |
| 9202 |
Make_Subtype_Indication (Loc, |
| 9203 |
Subtype_Mark => |
| 9204 |
New_Occurrence_Of |
| 9205 |
(RTE (RE_Dynamic_Interrupt_Protection), Loc), |
| 9206 |
Constraint => |
| 9207 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 9208 |
Constraints => New_List (Entry_Count_Expr))); |
| 9209 |
|
| 9210 |
else |
| 9211 |
case Corresponding_Runtime_Package (Prot_Typ) is |
| 9212 |
when System_Tasking_Protected_Objects_Entries => |
| 9213 |
Protection_Subtype := |
| 9214 |
Make_Subtype_Indication (Loc, |
| 9215 |
Subtype_Mark => |
| 9216 |
New_Occurrence_Of |
| 9217 |
(RTE (RE_Protection_Entries), Loc), |
| 9218 |
Constraint => |
| 9219 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 9220 |
Constraints => New_List (Entry_Count_Expr))); |
| 9221 |
|
| 9222 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 9223 |
Protection_Subtype := |
| 9224 |
New_Occurrence_Of (RTE (RE_Protection_Entry), Loc); |
| 9225 |
|
| 9226 |
when System_Tasking_Protected_Objects => |
| 9227 |
Protection_Subtype := |
| 9228 |
New_Occurrence_Of (RTE (RE_Protection), Loc); |
| 9229 |
|
| 9230 |
when others => |
| 9231 |
raise Program_Error; |
| 9232 |
end case; |
| 9233 |
end if; |
| 9234 |
|
| 9235 |
Object_Comp := |
| 9236 |
Make_Component_Declaration (Loc, |
| 9237 |
Defining_Identifier => |
| 9238 |
Make_Defining_Identifier (Loc, Name_uObject), |
| 9239 |
Component_Definition => |
| 9240 |
Make_Component_Definition (Loc, |
| 9241 |
Aliased_Present => True, |
| 9242 |
Subtype_Indication => Protection_Subtype)); |
| 9243 |
end; |
| 9244 |
|
| 9245 |
-- Put the _Object component after the private component so that it |
| 9246 |
-- be finalized early as required by 9.4(20). |
| 9247 |
|
| 9248 |
Append_To (Cdecls, Object_Comp); |
| 9249 |
end if; |
| 9250 |
|
| 9251 |
-- Analyze the record declaration immediately after construction, |
| 9252 |
-- because the initialization procedure is needed for single object |
| 9253 |
-- declarations before the next entity is analyzed (the freeze call |
| 9254 |
-- that generates this initialization procedure is found below). |
| 9255 |
|
| 9256 |
Analyze (Rec_Decl, Suppress => All_Checks); |
| 9257 |
|
| 9258 |
-- Analyze aspects of the corresponding record type. They may have been |
| 9259 |
-- propagated to it and its analysis is required to add the pragma (see |
| 9260 |
-- propagation of aspect First_Controlling_Parameter in the subprogram |
| 9261 |
-- Build_Corresponding_Record). |
| 9262 |
|
| 9263 |
if Has_Aspects (Rec_Decl) then |
| 9264 |
Analyze_Aspect_Specifications (Rec_Decl, Rec_Id); |
| 9265 |
|
| 9266 |
-- Handle aspects that may have been implicitly inherited and must be |
| 9267 |
-- explicitly propagated to the corresponding record type. This applies |
| 9268 |
-- specifically when the First_Controlling_Parameter aspect has been |
| 9269 |
-- implicitly inherited from an implemented interface. |
| 9270 |
|
| 9271 |
elsif Present (Interface_List (Parent (Prot_Typ))) |
| 9272 |
and then Has_First_Controlling_Parameter_Aspect (Prot_Typ) |
| 9273 |
then |
| 9274 |
Set_Has_First_Controlling_Parameter_Aspect (Rec_Id); |
| 9275 |
end if; |
| 9276 |
|
| 9277 |
-- Ada 2005 (AI-345): Construct the primitive entry wrappers before |
| 9278 |
-- the corresponding record is frozen. If any wrappers are generated, |
| 9279 |
-- Current_Node is updated accordingly. |
| 9280 |
|
| 9281 |
if Ada_Version >= Ada_2005 then |
| 9282 |
Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node); |
| 9283 |
end if; |
| 9284 |
|
| 9285 |
-- Collect pointers to entry bodies and their barriers, to be placed |
| 9286 |
-- in the Entry_Bodies_Array for the type. For each entry/family we |
| 9287 |
-- add an expression to the aggregate which is the initial value of |
| 9288 |
-- this array. The array is declared after all protected subprograms. |
| 9289 |
|
| 9290 |
if Has_Entries (Prot_Typ) then |
| 9291 |
Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List); |
| 9292 |
else |
| 9293 |
Entries_Aggr := Empty; |
| 9294 |
end if; |
| 9295 |
|
| 9296 |
-- Build two new procedure specifications for each protected subprogram; |
| 9297 |
-- one to call from outside the object and one to call from inside. |
| 9298 |
-- Build a barrier function and an entry body action procedure |
| 9299 |
-- specification for each protected entry. Initialize the entry body |
| 9300 |
-- array. If subprogram is flagged as eliminated, do not generate any |
| 9301 |
-- internal operations. |
| 9302 |
|
| 9303 |
E_Count := 0; |
| 9304 |
Comp := First (Visible_Declarations (Pdef)); |
| 9305 |
while Present (Comp) loop |
| 9306 |
if Nkind (Comp) = N_Subprogram_Declaration then |
| 9307 |
Sub := |
| 9308 |
Make_Subprogram_Declaration (Loc, |
| 9309 |
Specification => |
| 9310 |
Build_Protected_Sub_Specification |
| 9311 |
(Comp, Prot_Typ, Unprotected_Mode)); |
| 9312 |
|
| 9313 |
Insert_After (Current_Node, Sub); |
| 9314 |
Analyze (Sub); |
| 9315 |
|
| 9316 |
Set_Protected_Body_Subprogram |
| 9317 |
(Defining_Unit_Name (Specification (Comp)), |
| 9318 |
Defining_Unit_Name (Specification (Sub))); |
| 9319 |
Check_Inlining (Defining_Unit_Name (Specification (Comp))); |
| 9320 |
|
| 9321 |
-- Make the protected version of the subprogram available for |
| 9322 |
-- expansion of external calls. |
| 9323 |
|
| 9324 |
Current_Node := Sub; |
| 9325 |
|
| 9326 |
Sub := |
| 9327 |
Make_Subprogram_Declaration (Loc, |
| 9328 |
Specification => |
| 9329 |
Build_Protected_Sub_Specification |
| 9330 |
(Comp, Prot_Typ, Protected_Mode)); |
| 9331 |
|
| 9332 |
Insert_After (Current_Node, Sub); |
| 9333 |
Analyze (Sub); |
| 9334 |
|
| 9335 |
Current_Node := Sub; |
| 9336 |
|
| 9337 |
-- Generate an overriding primitive operation specification for |
| 9338 |
-- this subprogram if the protected type implements an interface |
| 9339 |
-- and Build_Wrapper_Spec did not generate its wrapper. |
| 9340 |
|
| 9341 |
if Ada_Version >= Ada_2005 |
| 9342 |
and then |
| 9343 |
Present (Interfaces (Corresponding_Record_Type (Prot_Typ))) |
| 9344 |
then |
| 9345 |
declare |
| 9346 |
Found : Boolean := False; |
| 9347 |
Prim_Elmt : Elmt_Id; |
| 9348 |
Prim_Op : Node_Id; |
| 9349 |
|
| 9350 |
begin |
| 9351 |
Prim_Elmt := |
| 9352 |
First_Elmt |
| 9353 |
(Primitive_Operations |
| 9354 |
(Corresponding_Record_Type (Prot_Typ))); |
| 9355 |
|
| 9356 |
while Present (Prim_Elmt) loop |
| 9357 |
Prim_Op := Node (Prim_Elmt); |
| 9358 |
|
| 9359 |
if Is_Primitive_Wrapper (Prim_Op) |
| 9360 |
and then Wrapped_Entity (Prim_Op) = |
| 9361 |
Defining_Entity (Specification (Comp)) |
| 9362 |
then |
| 9363 |
Found := True; |
| 9364 |
exit; |
| 9365 |
end if; |
| 9366 |
|
| 9367 |
Next_Elmt (Prim_Elmt); |
| 9368 |
end loop; |
| 9369 |
|
| 9370 |
if not Found then |
| 9371 |
Sub := |
| 9372 |
Make_Subprogram_Declaration (Loc, |
| 9373 |
Specification => |
| 9374 |
Build_Protected_Sub_Specification |
| 9375 |
(Comp, Prot_Typ, Dispatching_Mode)); |
| 9376 |
|
| 9377 |
Insert_After (Current_Node, Sub); |
| 9378 |
Analyze (Sub); |
| 9379 |
|
| 9380 |
Current_Node := Sub; |
| 9381 |
end if; |
| 9382 |
end; |
| 9383 |
end if; |
| 9384 |
|
| 9385 |
-- If a pragma Interrupt_Handler applies, build and add a call to |
| 9386 |
-- Register_Interrupt_Handler to the freezing actions of the |
| 9387 |
-- protected version (Current_Node) of the subprogram: |
| 9388 |
|
| 9389 |
-- system.interrupts.register_interrupt_handler |
| 9390 |
-- (prot_procP'address); |
| 9391 |
|
| 9392 |
if not Restricted_Profile |
| 9393 |
and then Is_Interrupt_Handler |
| 9394 |
(Defining_Unit_Name (Specification (Comp))) |
| 9395 |
then |
| 9396 |
Register_Handler; |
| 9397 |
end if; |
| 9398 |
|
| 9399 |
elsif Nkind (Comp) = N_Entry_Declaration then |
| 9400 |
Expand_Entry_Declaration (Comp); |
| 9401 |
end if; |
| 9402 |
|
| 9403 |
Next (Comp); |
| 9404 |
end loop; |
| 9405 |
|
| 9406 |
-- If there are some private entry declarations, expand it as if they |
| 9407 |
-- were visible entries. |
| 9408 |
|
| 9409 |
Comp := First (Private_Declarations (Pdef)); |
| 9410 |
while Present (Comp) loop |
| 9411 |
if Nkind (Comp) = N_Entry_Declaration then |
| 9412 |
Expand_Entry_Declaration (Comp); |
| 9413 |
end if; |
| 9414 |
|
| 9415 |
Next (Comp); |
| 9416 |
end loop; |
| 9417 |
|
| 9418 |
-- Create the declaration of an array object which contains the values |
| 9419 |
-- of any aspect/pragma Max_Queue_Length, Max_Entry_Queue_Length or |
| 9420 |
-- Max_EntryQueue_Depth for all entries of the protected |
| 9421 |
-- type. This object is later passed to the appropriate protected object |
| 9422 |
-- initialization routine. |
| 9423 |
|
| 9424 |
if Has_Entries (Prot_Typ) |
| 9425 |
and then Corresponding_Runtime_Package (Prot_Typ) = |
| 9426 |
System_Tasking_Protected_Objects_Entries |
| 9427 |
then |
| 9428 |
declare |
| 9429 |
Count : Int; |
| 9430 |
Item : Entity_Id; |
| 9431 |
Max_Vals : Node_Id; |
| 9432 |
Maxes : List_Id; |
| 9433 |
Maxes_Id : Entity_Id; |
| 9434 |
Need_Array : Boolean := False; |
| 9435 |
|
| 9436 |
begin |
| 9437 |
-- First check if there is any Max_[Entry_]Queue_Length pragma |
| 9438 |
|
| 9439 |
Item := First_Entity (Prot_Typ); |
| 9440 |
while Present (Item) loop |
| 9441 |
if Is_Entry (Item) and then Has_Max_Queue_Length (Item) then |
| 9442 |
Need_Array := True; |
| 9443 |
exit; |
| 9444 |
end if; |
| 9445 |
|
| 9446 |
Next_Entity (Item); |
| 9447 |
end loop; |
| 9448 |
|
| 9449 |
-- Gather the Max_Queue_Length values of all entries in a list. A |
| 9450 |
-- value of zero indicates that the entry has no limitation on its |
| 9451 |
-- queue length. |
| 9452 |
|
| 9453 |
if Need_Array then |
| 9454 |
Count := 0; |
| 9455 |
Item := First_Entity (Prot_Typ); |
| 9456 |
Maxes := New_List; |
| 9457 |
while Present (Item) loop |
| 9458 |
if Is_Entry (Item) then |
| 9459 |
Count := Count + 1; |
| 9460 |
Append_To (Maxes, |
| 9461 |
Make_Integer_Literal |
| 9462 |
(Loc, Get_Max_Queue_Length (Item))); |
| 9463 |
end if; |
| 9464 |
|
| 9465 |
Next_Entity (Item); |
| 9466 |
end loop; |
| 9467 |
|
| 9468 |
-- Create the declaration of the array object. Generate: |
| 9469 |
|
| 9470 |
-- Maxes_Id : aliased constant |
| 9471 |
-- Protected_Entry_Queue_Max_Array |
| 9472 |
-- (1 .. Count) := (..., ...); |
| 9473 |
|
| 9474 |
Maxes_Id := |
| 9475 |
Make_Defining_Identifier (Loc, |
| 9476 |
Chars => New_External_Name (Chars (Prot_Typ), 'B')); |
| 9477 |
|
| 9478 |
Max_Vals := |
| 9479 |
Make_Object_Declaration (Loc, |
| 9480 |
Defining_Identifier => Maxes_Id, |
| 9481 |
Aliased_Present => True, |
| 9482 |
Constant_Present => True, |
| 9483 |
Object_Definition => |
| 9484 |
Make_Subtype_Indication (Loc, |
| 9485 |
Subtype_Mark => |
| 9486 |
New_Occurrence_Of |
| 9487 |
(RTE (RE_Protected_Entry_Queue_Max_Array), Loc), |
| 9488 |
Constraint => |
| 9489 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 9490 |
Constraints => New_List ( |
| 9491 |
Make_Range (Loc, |
| 9492 |
Make_Integer_Literal (Loc, 1), |
| 9493 |
Make_Integer_Literal (Loc, Count))))), |
| 9494 |
Expression => Make_Aggregate (Loc, Maxes)); |
| 9495 |
|
| 9496 |
-- A pointer to this array will be placed in the corresponding |
| 9497 |
-- record by its initialization procedure so this needs to be |
| 9498 |
-- analyzed here. |
| 9499 |
|
| 9500 |
Insert_After (Current_Node, Max_Vals); |
| 9501 |
Current_Node := Max_Vals; |
| 9502 |
Analyze (Max_Vals); |
| 9503 |
|
| 9504 |
Set_Entry_Max_Queue_Lengths_Array (Prot_Typ, Maxes_Id); |
| 9505 |
end if; |
| 9506 |
end; |
| 9507 |
end if; |
| 9508 |
|
| 9509 |
-- Emit declaration for Entry_Bodies_Array, now that the addresses of |
| 9510 |
-- all protected subprograms have been collected. |
| 9511 |
|
| 9512 |
if Has_Entries (Prot_Typ) then |
| 9513 |
Body_Id := |
| 9514 |
Make_Defining_Identifier (Sloc (Prot_Typ), |
| 9515 |
Chars => New_External_Name (Chars (Prot_Typ), 'A')); |
| 9516 |
|
| 9517 |
case Corresponding_Runtime_Package (Prot_Typ) is |
| 9518 |
when System_Tasking_Protected_Objects_Entries => |
| 9519 |
Expr := Entries_Aggr; |
| 9520 |
Obj_Def := |
| 9521 |
Make_Subtype_Indication (Loc, |
| 9522 |
Subtype_Mark => |
| 9523 |
New_Occurrence_Of |
| 9524 |
(RTE (RE_Protected_Entry_Body_Array), Loc), |
| 9525 |
Constraint => |
| 9526 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 9527 |
Constraints => New_List ( |
| 9528 |
Make_Range (Loc, |
| 9529 |
Make_Integer_Literal (Loc, 1), |
| 9530 |
Make_Integer_Literal (Loc, E_Count))))); |
| 9531 |
|
| 9532 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 9533 |
Expr := Remove_Head (Expressions (Entries_Aggr)); |
| 9534 |
Obj_Def := New_Occurrence_Of (RTE (RE_Entry_Body), Loc); |
| 9535 |
|
| 9536 |
when others => |
| 9537 |
raise Program_Error; |
| 9538 |
end case; |
| 9539 |
|
| 9540 |
Body_Arr := |
| 9541 |
Make_Object_Declaration (Loc, |
| 9542 |
Defining_Identifier => Body_Id, |
| 9543 |
Aliased_Present => True, |
| 9544 |
Constant_Present => True, |
| 9545 |
Object_Definition => Obj_Def, |
| 9546 |
Expression => Expr); |
| 9547 |
|
| 9548 |
-- A pointer to this array will be placed in the corresponding record |
| 9549 |
-- by its initialization procedure so this needs to be analyzed here. |
| 9550 |
|
| 9551 |
Insert_After (Current_Node, Body_Arr); |
| 9552 |
Current_Node := Body_Arr; |
| 9553 |
Analyze (Body_Arr); |
| 9554 |
|
| 9555 |
Set_Entry_Bodies_Array (Prot_Typ, Body_Id); |
| 9556 |
|
| 9557 |
-- Finally, build the function that maps an entry index into the |
| 9558 |
-- corresponding body. A pointer to this function is placed in each |
| 9559 |
-- object of the type. Except for a ravenscar-like profile (no abort, |
| 9560 |
-- no entry queue, 1 entry) |
| 9561 |
|
| 9562 |
if Corresponding_Runtime_Package (Prot_Typ) = |
| 9563 |
System_Tasking_Protected_Objects_Entries |
| 9564 |
then |
| 9565 |
Sub := |
| 9566 |
Make_Subprogram_Declaration (Loc, |
| 9567 |
Specification => Build_Find_Body_Index_Spec (Prot_Typ)); |
| 9568 |
|
| 9569 |
Insert_After (Current_Node, Sub); |
| 9570 |
Analyze (Sub); |
| 9571 |
end if; |
| 9572 |
end if; |
| 9573 |
end Expand_N_Protected_Type_Declaration; |
| 9574 |
|
| 9575 |
-------------------------------- |
| 9576 |
-- Expand_N_Requeue_Statement -- |
| 9577 |
-------------------------------- |
| 9578 |
|
| 9579 |
-- A nondispatching requeue statement is expanded into one of four GNARLI |
| 9580 |
-- operations, depending on the source and destination (task or protected |
| 9581 |
-- object). A dispatching requeue statement is expanded into a call to the |
| 9582 |
-- predefined primitive _Disp_Requeue. In addition, code is generated to |
| 9583 |
-- jump around the remainder of processing for the original entry and, if |
| 9584 |
-- the destination is (different) protected object, to attempt to service |
| 9585 |
-- it. The following illustrates the various cases: |
| 9586 |
|
| 9587 |
-- procedure entE |
| 9588 |
-- (O : System.Address; |
| 9589 |
-- P : System.Address; |
| 9590 |
-- E : Protected_Entry_Index) |
| 9591 |
-- is |
| 9592 |
-- <discriminant renamings> |
| 9593 |
-- <private object renamings> |
| 9594 |
-- type poVP is access poV; |
| 9595 |
-- _object : ptVP := ptVP!(O); |
| 9596 |
|
| 9597 |
-- begin |
| 9598 |
-- begin |
| 9599 |
-- <start of statement sequence for entry> |
| 9600 |
|
| 9601 |
-- -- Requeue from one protected entry body to another protected |
| 9602 |
-- -- entry. |
| 9603 |
|
| 9604 |
-- Requeue_Protected_Entry ( |
| 9605 |
-- _object._object'Access, |
| 9606 |
-- new._object'Access, |
| 9607 |
-- E, |
| 9608 |
-- Abort_Present); |
| 9609 |
-- return; |
| 9610 |
|
| 9611 |
-- <some more of the statement sequence for entry> |
| 9612 |
|
| 9613 |
-- -- Requeue from an entry body to a task entry |
| 9614 |
|
| 9615 |
-- Requeue_Protected_To_Task_Entry ( |
| 9616 |
-- New._task_id, |
| 9617 |
-- E, |
| 9618 |
-- Abort_Present); |
| 9619 |
-- return; |
| 9620 |
|
| 9621 |
-- <rest of statement sequence for entry> |
| 9622 |
-- Complete_Entry_Body (_object._object); |
| 9623 |
|
| 9624 |
-- exception |
| 9625 |
-- when all others => |
| 9626 |
-- Exceptional_Complete_Entry_Body ( |
| 9627 |
-- _object._object, Get_GNAT_Exception); |
| 9628 |
-- end; |
| 9629 |
-- end entE; |
| 9630 |
|
| 9631 |
-- Requeue of a task entry call to a task entry |
| 9632 |
|
| 9633 |
-- Accept_Call (E, Ann); |
| 9634 |
-- <start of statement sequence for accept statement> |
| 9635 |
-- Requeue_Task_Entry (New._task_id, E, Abort_Present); |
| 9636 |
-- goto Lnn; |
| 9637 |
-- <rest of statement sequence for accept statement> |
| 9638 |
-- <<Lnn>> |
| 9639 |
-- Complete_Rendezvous; |
| 9640 |
|
| 9641 |
-- exception |
| 9642 |
-- when all others => |
| 9643 |
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); |
| 9644 |
|
| 9645 |
-- Requeue of a task entry call to a protected entry |
| 9646 |
|
| 9647 |
-- Accept_Call (E, Ann); |
| 9648 |
-- <start of statement sequence for accept statement> |
| 9649 |
-- Requeue_Task_To_Protected_Entry ( |
| 9650 |
-- new._object'Access, |
| 9651 |
-- E, |
| 9652 |
-- Abort_Present); |
| 9653 |
-- newS (new, Pnn); |
| 9654 |
-- goto Lnn; |
| 9655 |
-- <rest of statement sequence for accept statement> |
| 9656 |
-- <<Lnn>> |
| 9657 |
-- Complete_Rendezvous; |
| 9658 |
|
| 9659 |
-- exception |
| 9660 |
-- when all others => |
| 9661 |
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); |
| 9662 |
|
| 9663 |
-- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive |
| 9664 |
-- marked by pragma Implemented (XXX, By_Entry). |
| 9665 |
|
| 9666 |
-- The requeue is inside a protected entry: |
| 9667 |
|
| 9668 |
-- procedure entE |
| 9669 |
-- (O : System.Address; |
| 9670 |
-- P : System.Address; |
| 9671 |
-- E : Protected_Entry_Index) |
| 9672 |
-- is |
| 9673 |
-- <discriminant renamings> |
| 9674 |
-- <private object renamings> |
| 9675 |
-- type poVP is access poV; |
| 9676 |
-- _object : ptVP := ptVP!(O); |
| 9677 |
|
| 9678 |
-- begin |
| 9679 |
-- begin |
| 9680 |
-- <start of statement sequence for entry> |
| 9681 |
|
| 9682 |
-- _Disp_Requeue |
| 9683 |
-- (<interface class-wide object>, |
| 9684 |
-- True, |
| 9685 |
-- _object'Address, |
| 9686 |
-- Ada.Tags.Get_Offset_Index |
| 9687 |
-- (Tag (_object), |
| 9688 |
-- <interface dispatch table index of target entry>), |
| 9689 |
-- Abort_Present); |
| 9690 |
-- return; |
| 9691 |
|
| 9692 |
-- <rest of statement sequence for entry> |
| 9693 |
-- Complete_Entry_Body (_object._object); |
| 9694 |
|
| 9695 |
-- exception |
| 9696 |
-- when all others => |
| 9697 |
-- Exceptional_Complete_Entry_Body ( |
| 9698 |
-- _object._object, Get_GNAT_Exception); |
| 9699 |
-- end; |
| 9700 |
-- end entE; |
| 9701 |
|
| 9702 |
-- The requeue is inside a task entry: |
| 9703 |
|
| 9704 |
-- Accept_Call (E, Ann); |
| 9705 |
-- <start of statement sequence for accept statement> |
| 9706 |
-- _Disp_Requeue |
| 9707 |
-- (<interface class-wide object>, |
| 9708 |
-- False, |
| 9709 |
-- null, |
| 9710 |
-- Ada.Tags.Get_Offset_Index |
| 9711 |
-- (Tag (_object), |
| 9712 |
-- <interface dispatch table index of target entrt>), |
| 9713 |
-- Abort_Present); |
| 9714 |
-- newS (new, Pnn); |
| 9715 |
-- goto Lnn; |
| 9716 |
-- <rest of statement sequence for accept statement> |
| 9717 |
-- <<Lnn>> |
| 9718 |
-- Complete_Rendezvous; |
| 9719 |
|
| 9720 |
-- exception |
| 9721 |
-- when all others => |
| 9722 |
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); |
| 9723 |
|
| 9724 |
-- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive |
| 9725 |
-- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue |
| 9726 |
-- statement is replaced by a dispatching call with actual parameters taken |
| 9727 |
-- from the inner-most accept statement or entry body. |
| 9728 |
|
| 9729 |
-- Target.Primitive (Param1, ..., ParamN); |
| 9730 |
|
| 9731 |
-- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive |
| 9732 |
-- marked by pragma Implemented (XXX, By_Any | Optional) or not marked |
| 9733 |
-- at all. |
| 9734 |
|
| 9735 |
-- declare |
| 9736 |
-- S : constant Offset_Index := |
| 9737 |
-- Get_Offset_Index (Tag (Concval), DT_Position (Ename)); |
| 9738 |
-- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S); |
| 9739 |
|
| 9740 |
-- begin |
| 9741 |
-- if C = POK_Protected_Entry |
| 9742 |
-- or else C = POK_Task_Entry |
| 9743 |
-- then |
| 9744 |
-- <statements for dispatching requeue> |
| 9745 |
|
| 9746 |
-- elsif C = POK_Protected_Procedure then |
| 9747 |
-- <dispatching call equivalent> |
| 9748 |
|
| 9749 |
-- else |
| 9750 |
-- raise Program_Error; |
| 9751 |
-- end if; |
| 9752 |
-- end; |
| 9753 |
|
| 9754 |
procedure Expand_N_Requeue_Statement (N : Node_Id) is |
| 9755 |
Loc : constant Source_Ptr := Sloc (N); |
| 9756 |
Conc_Typ : Entity_Id; |
| 9757 |
Concval : Node_Id; |
| 9758 |
Ename : Node_Id; |
| 9759 |
Enc_Subp : Entity_Id; |
| 9760 |
Index : Node_Id; |
| 9761 |
Old_Typ : Entity_Id; |
| 9762 |
|
| 9763 |
function Build_Dispatching_Call_Equivalent return Node_Id; |
| 9764 |
-- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of |
| 9765 |
-- the form Concval.Ename. It is statically known that Ename is allowed |
| 9766 |
-- to be implemented by a protected procedure. Create a dispatching call |
| 9767 |
-- equivalent of Concval.Ename taking the actual parameters from the |
| 9768 |
-- inner-most accept statement or entry body. |
| 9769 |
|
| 9770 |
function Build_Dispatching_Requeue return Node_Id; |
| 9771 |
-- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of |
| 9772 |
-- the form Concval.Ename. It is statically known that Ename is allowed |
| 9773 |
-- to be implemented by a protected or a task entry. Create a call to |
| 9774 |
-- primitive _Disp_Requeue which handles the low-level actions. |
| 9775 |
|
| 9776 |
function Build_Dispatching_Requeue_To_Any return Node_Id; |
| 9777 |
-- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of |
| 9778 |
-- the form Concval.Ename. Ename is either marked by pragma Implemented |
| 9779 |
-- (XXX, By_Any | Optional) or not marked at all. Create a block which |
| 9780 |
-- determines at runtime whether Ename denotes an entry or a procedure |
| 9781 |
-- and perform the appropriate kind of dispatching select. |
| 9782 |
|
| 9783 |
function Build_Normal_Requeue return Node_Id; |
| 9784 |
-- N denotes a nondispatching requeue statement to either a task or a |
| 9785 |
-- protected entry. Build the appropriate runtime call to perform the |
| 9786 |
-- action. |
| 9787 |
|
| 9788 |
function Build_Skip_Statement (Search : Node_Id) return Node_Id; |
| 9789 |
-- For a protected entry, create a return statement to skip the rest of |
| 9790 |
-- the entry body. Otherwise, create a goto statement to skip the rest |
| 9791 |
-- of a task accept statement. The lookup for the enclosing entry body |
| 9792 |
-- or accept statement starts from Search. |
| 9793 |
|
| 9794 |
--------------------------------------- |
| 9795 |
-- Build_Dispatching_Call_Equivalent -- |
| 9796 |
--------------------------------------- |
| 9797 |
|
| 9798 |
function Build_Dispatching_Call_Equivalent return Node_Id is |
| 9799 |
Call_Ent : constant Entity_Id := Entity (Ename); |
| 9800 |
Obj : constant Node_Id := Original_Node (Concval); |
| 9801 |
Acc_Ent : Node_Id; |
| 9802 |
Actuals : List_Id; |
| 9803 |
Formal : Node_Id; |
| 9804 |
Formals : List_Id; |
| 9805 |
|
| 9806 |
begin |
| 9807 |
-- Climb the parent chain looking for the inner-most entry body or |
| 9808 |
-- accept statement. |
| 9809 |
|
| 9810 |
Acc_Ent := N; |
| 9811 |
while Present (Acc_Ent) |
| 9812 |
and then Nkind (Acc_Ent) not in N_Accept_Statement | N_Entry_Body |
| 9813 |
loop |
| 9814 |
Acc_Ent := Parent (Acc_Ent); |
| 9815 |
end loop; |
| 9816 |
|
| 9817 |
-- A requeue statement should be housed inside an entry body or an |
| 9818 |
-- accept statement at some level. If this is not the case, then the |
| 9819 |
-- tree is malformed. |
| 9820 |
|
| 9821 |
pragma Assert (Present (Acc_Ent)); |
| 9822 |
|
| 9823 |
-- Recover the list of formal parameters |
| 9824 |
|
| 9825 |
if Nkind (Acc_Ent) = N_Entry_Body then |
| 9826 |
Acc_Ent := Entry_Body_Formal_Part (Acc_Ent); |
| 9827 |
end if; |
| 9828 |
|
| 9829 |
Formals := Parameter_Specifications (Acc_Ent); |
| 9830 |
|
| 9831 |
-- Create the actual parameters for the dispatching call. These are |
| 9832 |
-- simply copies of the entry body or accept statement formals in the |
| 9833 |
-- same order as they appear. |
| 9834 |
|
| 9835 |
Actuals := No_List; |
| 9836 |
|
| 9837 |
if Present (Formals) then |
| 9838 |
Actuals := New_List; |
| 9839 |
Formal := First (Formals); |
| 9840 |
while Present (Formal) loop |
| 9841 |
Append_To (Actuals, |
| 9842 |
Make_Identifier (Loc, Chars (Defining_Identifier (Formal)))); |
| 9843 |
Next (Formal); |
| 9844 |
end loop; |
| 9845 |
end if; |
| 9846 |
|
| 9847 |
-- Generate: |
| 9848 |
-- Obj.Call_Ent (Actuals); |
| 9849 |
|
| 9850 |
return |
| 9851 |
Make_Procedure_Call_Statement (Loc, |
| 9852 |
Name => |
| 9853 |
Make_Selected_Component (Loc, |
| 9854 |
Prefix => Make_Identifier (Loc, Chars (Obj)), |
| 9855 |
Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))), |
| 9856 |
|
| 9857 |
Parameter_Associations => Actuals); |
| 9858 |
end Build_Dispatching_Call_Equivalent; |
| 9859 |
|
| 9860 |
------------------------------- |
| 9861 |
-- Build_Dispatching_Requeue -- |
| 9862 |
------------------------------- |
| 9863 |
|
| 9864 |
function Build_Dispatching_Requeue return Node_Id is |
| 9865 |
Params : constant List_Id := New_List; |
| 9866 |
|
| 9867 |
begin |
| 9868 |
-- Process the "with abort" parameter |
| 9869 |
|
| 9870 |
Prepend_To (Params, |
| 9871 |
New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc)); |
| 9872 |
|
| 9873 |
-- Process the entry wrapper's position in the primary dispatch |
| 9874 |
-- table parameter. Generate: |
| 9875 |
|
| 9876 |
-- Ada.Tags.Get_Entry_Index |
| 9877 |
-- (T => To_Tag_Ptr (Obj'Address).all, |
| 9878 |
-- Position => |
| 9879 |
-- Ada.Tags.Get_Offset_Index |
| 9880 |
-- (Ada.Tags.Tag (Concval), |
| 9881 |
-- <interface dispatch table position of Ename>)); |
| 9882 |
|
| 9883 |
-- Note that Obj'Address is recursively expanded into a call to |
| 9884 |
-- Base_Address (Obj). |
| 9885 |
|
| 9886 |
if Tagged_Type_Expansion then |
| 9887 |
Prepend_To (Params, |
| 9888 |
Make_Function_Call (Loc, |
| 9889 |
Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc), |
| 9890 |
Parameter_Associations => New_List ( |
| 9891 |
|
| 9892 |
Make_Explicit_Dereference (Loc, |
| 9893 |
Unchecked_Convert_To (RTE (RE_Tag_Ptr), |
| 9894 |
Make_Attribute_Reference (Loc, |
| 9895 |
Prefix => New_Copy_Tree (Concval), |
| 9896 |
Attribute_Name => Name_Address))), |
| 9897 |
|
| 9898 |
Make_Function_Call (Loc, |
| 9899 |
Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc), |
| 9900 |
Parameter_Associations => New_List ( |
| 9901 |
Unchecked_Convert_To (RTE (RE_Tag), Concval), |
| 9902 |
Make_Integer_Literal (Loc, |
| 9903 |
DT_Position (Entity (Ename)))))))); |
| 9904 |
|
| 9905 |
-- VM targets |
| 9906 |
|
| 9907 |
else |
| 9908 |
Prepend_To (Params, |
| 9909 |
Make_Function_Call (Loc, |
| 9910 |
Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc), |
| 9911 |
Parameter_Associations => New_List ( |
| 9912 |
|
| 9913 |
Make_Attribute_Reference (Loc, |
| 9914 |
Prefix => Concval, |
| 9915 |
Attribute_Name => Name_Tag), |
| 9916 |
|
| 9917 |
Make_Function_Call (Loc, |
| 9918 |
Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc), |
| 9919 |
|
| 9920 |
Parameter_Associations => New_List ( |
| 9921 |
|
| 9922 |
-- Obj_Tag |
| 9923 |
|
| 9924 |
Make_Attribute_Reference (Loc, |
| 9925 |
Prefix => Concval, |
| 9926 |
Attribute_Name => Name_Tag), |
| 9927 |
|
| 9928 |
-- Tag_Typ |
| 9929 |
|
| 9930 |
Make_Attribute_Reference (Loc, |
| 9931 |
Prefix => New_Occurrence_Of (Etype (Concval), Loc), |
| 9932 |
Attribute_Name => Name_Tag), |
| 9933 |
|
| 9934 |
-- Position |
| 9935 |
|
| 9936 |
Make_Integer_Literal (Loc, |
| 9937 |
DT_Position (Entity (Ename)))))))); |
| 9938 |
end if; |
| 9939 |
|
| 9940 |
-- Specific actuals for protected to XXX requeue |
| 9941 |
|
| 9942 |
if Is_Protected_Type (Old_Typ) then |
| 9943 |
Prepend_To (Params, |
| 9944 |
Make_Attribute_Reference (Loc, -- _object'Address |
| 9945 |
Prefix => |
| 9946 |
Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)), |
| 9947 |
Attribute_Name => Name_Address)); |
| 9948 |
|
| 9949 |
Prepend_To (Params, -- True |
| 9950 |
New_Occurrence_Of (Standard_True, Loc)); |
| 9951 |
|
| 9952 |
-- Specific actuals for task to XXX requeue |
| 9953 |
|
| 9954 |
else |
| 9955 |
pragma Assert (Is_Task_Type (Old_Typ)); |
| 9956 |
|
| 9957 |
Prepend_To (Params, -- null |
| 9958 |
New_Occurrence_Of (RTE (RE_Null_Address), Loc)); |
| 9959 |
|
| 9960 |
Prepend_To (Params, -- False |
| 9961 |
New_Occurrence_Of (Standard_False, Loc)); |
| 9962 |
end if; |
| 9963 |
|
| 9964 |
-- Add the object parameter |
| 9965 |
|
| 9966 |
Prepend_To (Params, New_Copy_Tree (Concval)); |
| 9967 |
|
| 9968 |
-- Generate: |
| 9969 |
-- _Disp_Requeue (<Params>); |
| 9970 |
|
| 9971 |
-- Find entity for Disp_Requeue operation, which belongs to |
| 9972 |
-- the type and may not be directly visible. |
| 9973 |
|
| 9974 |
declare |
| 9975 |
Elmt : Elmt_Id; |
| 9976 |
Op : Entity_Id := Empty; |
| 9977 |
|
| 9978 |
begin |
| 9979 |
Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ))); |
| 9980 |
while Present (Elmt) loop |
| 9981 |
Op := Node (Elmt); |
| 9982 |
exit when Chars (Op) = Name_uDisp_Requeue; |
| 9983 |
Next_Elmt (Elmt); |
| 9984 |
end loop; |
| 9985 |
|
| 9986 |
pragma Assert (Present (Op)); |
| 9987 |
|
| 9988 |
return |
| 9989 |
Make_Procedure_Call_Statement (Loc, |
| 9990 |
Name => New_Occurrence_Of (Op, Loc), |
| 9991 |
Parameter_Associations => Params); |
| 9992 |
end; |
| 9993 |
end Build_Dispatching_Requeue; |
| 9994 |
|
| 9995 |
-------------------------------------- |
| 9996 |
-- Build_Dispatching_Requeue_To_Any -- |
| 9997 |
-------------------------------------- |
| 9998 |
|
| 9999 |
function Build_Dispatching_Requeue_To_Any return Node_Id is |
| 10000 |
Call_Ent : constant Entity_Id := Entity (Ename); |
| 10001 |
Obj : constant Node_Id := Original_Node (Concval); |
| 10002 |
Skip : constant Node_Id := Build_Skip_Statement (N); |
| 10003 |
C : Entity_Id; |
| 10004 |
Decls : List_Id; |
| 10005 |
S : Entity_Id; |
| 10006 |
Stmts : List_Id; |
| 10007 |
|
| 10008 |
begin |
| 10009 |
Decls := New_List; |
| 10010 |
Stmts := New_List; |
| 10011 |
|
| 10012 |
-- Dispatch table slot processing, generate: |
| 10013 |
-- S : Integer; |
| 10014 |
|
| 10015 |
S := Build_S (Loc, Decls); |
| 10016 |
|
| 10017 |
-- Call kind processing, generate: |
| 10018 |
-- C : Ada.Tags.Prim_Op_Kind; |
| 10019 |
|
| 10020 |
C := Build_C (Loc, Decls); |
| 10021 |
|
| 10022 |
-- Generate: |
| 10023 |
-- S := Ada.Tags.Get_Offset_Index |
| 10024 |
-- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent)); |
| 10025 |
|
| 10026 |
Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent)); |
| 10027 |
|
| 10028 |
-- Generate: |
| 10029 |
-- _Disp_Get_Prim_Op_Kind (Obj, S, C); |
| 10030 |
|
| 10031 |
Append_To (Stmts, |
| 10032 |
Make_Procedure_Call_Statement (Loc, |
| 10033 |
Name => |
| 10034 |
New_Occurrence_Of ( |
| 10035 |
Find_Prim_Op (Etype (Etype (Obj)), |
| 10036 |
Name_uDisp_Get_Prim_Op_Kind), |
| 10037 |
Loc), |
| 10038 |
Parameter_Associations => New_List ( |
| 10039 |
New_Copy_Tree (Obj), |
| 10040 |
New_Occurrence_Of (S, Loc), |
| 10041 |
New_Occurrence_Of (C, Loc)))); |
| 10042 |
|
| 10043 |
Append_To (Stmts, |
| 10044 |
|
| 10045 |
-- if C = POK_Protected_Entry |
| 10046 |
-- or else C = POK_Task_Entry |
| 10047 |
-- then |
| 10048 |
|
| 10049 |
Make_Implicit_If_Statement (N, |
| 10050 |
Condition => |
| 10051 |
Make_Op_Or (Loc, |
| 10052 |
Left_Opnd => |
| 10053 |
Make_Op_Eq (Loc, |
| 10054 |
Left_Opnd => |
| 10055 |
New_Occurrence_Of (C, Loc), |
| 10056 |
Right_Opnd => |
| 10057 |
New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)), |
| 10058 |
|
| 10059 |
Right_Opnd => |
| 10060 |
Make_Op_Eq (Loc, |
| 10061 |
Left_Opnd => |
| 10062 |
New_Occurrence_Of (C, Loc), |
| 10063 |
Right_Opnd => |
| 10064 |
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))), |
| 10065 |
|
| 10066 |
-- Dispatching requeue equivalent |
| 10067 |
|
| 10068 |
Then_Statements => New_List ( |
| 10069 |
Build_Dispatching_Requeue, |
| 10070 |
Skip), |
| 10071 |
|
| 10072 |
-- elsif C = POK_Protected_Procedure then |
| 10073 |
|
| 10074 |
Elsif_Parts => New_List ( |
| 10075 |
Make_Elsif_Part (Loc, |
| 10076 |
Condition => |
| 10077 |
Make_Op_Eq (Loc, |
| 10078 |
Left_Opnd => |
| 10079 |
New_Occurrence_Of (C, Loc), |
| 10080 |
Right_Opnd => |
| 10081 |
New_Occurrence_Of ( |
| 10082 |
RTE (RE_POK_Protected_Procedure), Loc)), |
| 10083 |
|
| 10084 |
-- Dispatching call equivalent |
| 10085 |
|
| 10086 |
Then_Statements => New_List ( |
| 10087 |
Build_Dispatching_Call_Equivalent))), |
| 10088 |
|
| 10089 |
-- else |
| 10090 |
-- raise Program_Error; |
| 10091 |
-- end if; |
| 10092 |
|
| 10093 |
Else_Statements => New_List ( |
| 10094 |
Make_Raise_Program_Error (Loc, |
| 10095 |
Reason => PE_Explicit_Raise)))); |
| 10096 |
|
| 10097 |
-- Wrap everything into a block |
| 10098 |
|
| 10099 |
return |
| 10100 |
Make_Block_Statement (Loc, |
| 10101 |
Declarations => Decls, |
| 10102 |
Handled_Statement_Sequence => |
| 10103 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 10104 |
Statements => Stmts)); |
| 10105 |
end Build_Dispatching_Requeue_To_Any; |
| 10106 |
|
| 10107 |
-------------------------- |
| 10108 |
-- Build_Normal_Requeue -- |
| 10109 |
-------------------------- |
| 10110 |
|
| 10111 |
function Build_Normal_Requeue return Node_Id is |
| 10112 |
Params : constant List_Id := New_List; |
| 10113 |
Param : Node_Id; |
| 10114 |
RT_Call : Node_Id; |
| 10115 |
|
| 10116 |
begin |
| 10117 |
-- Process the "with abort" parameter |
| 10118 |
|
| 10119 |
Prepend_To (Params, |
| 10120 |
New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc)); |
| 10121 |
|
| 10122 |
-- Add the index expression to the parameters. It is common among all |
| 10123 |
-- four cases. |
| 10124 |
|
| 10125 |
Prepend_To (Params, |
| 10126 |
Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ)); |
| 10127 |
|
| 10128 |
if Is_Protected_Type (Old_Typ) then |
| 10129 |
declare |
| 10130 |
Self_Param : Node_Id; |
| 10131 |
|
| 10132 |
begin |
| 10133 |
Self_Param := |
| 10134 |
Make_Attribute_Reference (Loc, |
| 10135 |
Prefix => |
| 10136 |
Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)), |
| 10137 |
Attribute_Name => |
| 10138 |
Name_Unchecked_Access); |
| 10139 |
|
| 10140 |
-- Protected to protected requeue |
| 10141 |
|
| 10142 |
if Is_Protected_Type (Conc_Typ) then |
| 10143 |
RT_Call := |
| 10144 |
New_Occurrence_Of ( |
| 10145 |
RTE (RE_Requeue_Protected_Entry), Loc); |
| 10146 |
|
| 10147 |
Param := |
| 10148 |
Make_Attribute_Reference (Loc, |
| 10149 |
Prefix => |
| 10150 |
Concurrent_Ref (Concval), |
| 10151 |
Attribute_Name => |
| 10152 |
Name_Unchecked_Access); |
| 10153 |
|
| 10154 |
-- Protected to task requeue |
| 10155 |
|
| 10156 |
else pragma Assert (Is_Task_Type (Conc_Typ)); |
| 10157 |
RT_Call := |
| 10158 |
New_Occurrence_Of ( |
| 10159 |
RTE (RE_Requeue_Protected_To_Task_Entry), Loc); |
| 10160 |
|
| 10161 |
Param := Concurrent_Ref (Concval); |
| 10162 |
end if; |
| 10163 |
|
| 10164 |
Prepend_To (Params, Param); |
| 10165 |
Prepend_To (Params, Self_Param); |
| 10166 |
end; |
| 10167 |
|
| 10168 |
else pragma Assert (Is_Task_Type (Old_Typ)); |
| 10169 |
|
| 10170 |
-- Task to protected requeue |
| 10171 |
|
| 10172 |
if Is_Protected_Type (Conc_Typ) then |
| 10173 |
RT_Call := |
| 10174 |
New_Occurrence_Of ( |
| 10175 |
RTE (RE_Requeue_Task_To_Protected_Entry), Loc); |
| 10176 |
|
| 10177 |
Param := |
| 10178 |
Make_Attribute_Reference (Loc, |
| 10179 |
Prefix => |
| 10180 |
Concurrent_Ref (Concval), |
| 10181 |
Attribute_Name => |
| 10182 |
Name_Unchecked_Access); |
| 10183 |
|
| 10184 |
-- Task to task requeue |
| 10185 |
|
| 10186 |
else pragma Assert (Is_Task_Type (Conc_Typ)); |
| 10187 |
RT_Call := |
| 10188 |
New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc); |
| 10189 |
|
| 10190 |
Param := Concurrent_Ref (Concval); |
| 10191 |
end if; |
| 10192 |
|
| 10193 |
Prepend_To (Params, Param); |
| 10194 |
end if; |
| 10195 |
|
| 10196 |
return |
| 10197 |
Make_Procedure_Call_Statement (Loc, |
| 10198 |
Name => RT_Call, |
| 10199 |
Parameter_Associations => Params); |
| 10200 |
end Build_Normal_Requeue; |
| 10201 |
|
| 10202 |
-------------------------- |
| 10203 |
-- Build_Skip_Statement -- |
| 10204 |
-------------------------- |
| 10205 |
|
| 10206 |
function Build_Skip_Statement (Search : Node_Id) return Node_Id is |
| 10207 |
Skip_Stmt : Node_Id; |
| 10208 |
|
| 10209 |
begin |
| 10210 |
-- Build a return statement to skip the rest of the entire body |
| 10211 |
|
| 10212 |
if Is_Protected_Type (Old_Typ) then |
| 10213 |
Skip_Stmt := Make_Simple_Return_Statement (Loc); |
| 10214 |
|
| 10215 |
-- If the requeue is within a task, find the end label of the |
| 10216 |
-- enclosing accept statement and create a goto statement to it. |
| 10217 |
|
| 10218 |
else |
| 10219 |
declare |
| 10220 |
Acc : Node_Id; |
| 10221 |
Label : Node_Id; |
| 10222 |
|
| 10223 |
begin |
| 10224 |
-- Climb the parent chain looking for the enclosing accept |
| 10225 |
-- statement. |
| 10226 |
|
| 10227 |
Acc := Parent (Search); |
| 10228 |
while Present (Acc) |
| 10229 |
and then Nkind (Acc) /= N_Accept_Statement |
| 10230 |
loop |
| 10231 |
Acc := Parent (Acc); |
| 10232 |
end loop; |
| 10233 |
|
| 10234 |
-- The last statement is the second label used for completing |
| 10235 |
-- the rendezvous the usual way. The label we are looking for |
| 10236 |
-- is right before it. |
| 10237 |
|
| 10238 |
Label := |
| 10239 |
Prev (Last (Statements (Handled_Statement_Sequence (Acc)))); |
| 10240 |
|
| 10241 |
pragma Assert (Nkind (Label) = N_Label); |
| 10242 |
|
| 10243 |
-- Generate a goto statement to skip the rest of the accept |
| 10244 |
|
| 10245 |
Skip_Stmt := |
| 10246 |
Make_Goto_Statement (Loc, |
| 10247 |
Name => |
| 10248 |
New_Occurrence_Of (Entity (Identifier (Label)), Loc)); |
| 10249 |
end; |
| 10250 |
end if; |
| 10251 |
|
| 10252 |
Set_Analyzed (Skip_Stmt); |
| 10253 |
|
| 10254 |
return Skip_Stmt; |
| 10255 |
end Build_Skip_Statement; |
| 10256 |
|
| 10257 |
-- Start of processing for Expand_N_Requeue_Statement |
| 10258 |
|
| 10259 |
begin |
| 10260 |
-- Extract the components of the entry call |
| 10261 |
|
| 10262 |
Extract_Entry (N, Concval, Ename, Index); |
| 10263 |
Conc_Typ := Etype (Concval); |
| 10264 |
|
| 10265 |
-- Examine the scope stack in order to find nearest enclosing concurrent |
| 10266 |
-- type. This will constitute our invocation source. |
| 10267 |
|
| 10268 |
Old_Typ := Current_Scope; |
| 10269 |
while Present (Old_Typ) |
| 10270 |
and then not Is_Concurrent_Type (Old_Typ) |
| 10271 |
loop |
| 10272 |
Old_Typ := Scope (Old_Typ); |
| 10273 |
end loop; |
| 10274 |
|
| 10275 |
-- Obtain the innermost enclosing callable construct for use in |
| 10276 |
-- generating a dynamic accessibility check. |
| 10277 |
|
| 10278 |
Enc_Subp := Current_Scope; |
| 10279 |
|
| 10280 |
if Ekind (Enc_Subp) not in Entry_Kind | Subprogram_Kind then |
| 10281 |
Enc_Subp := Enclosing_Subprogram (Enc_Subp); |
| 10282 |
end if; |
| 10283 |
|
| 10284 |
-- Generate a dynamic accessibility check on the target object |
| 10285 |
|
| 10286 |
Insert_Before_And_Analyze (N, |
| 10287 |
Make_Raise_Program_Error (Loc, |
| 10288 |
Condition => |
| 10289 |
Make_Op_Gt (Loc, |
| 10290 |
Left_Opnd => Accessibility_Level (Name (N), Dynamic_Level), |
| 10291 |
Right_Opnd => Make_Integer_Literal (Loc, |
| 10292 |
Scope_Depth (Enc_Subp))), |
| 10293 |
Reason => PE_Accessibility_Check_Failed)); |
| 10294 |
|
| 10295 |
-- Ada 2012 (AI05-0030): We have a dispatching requeue of the form |
| 10296 |
-- Concval.Ename where the type of Concval is class-wide concurrent |
| 10297 |
-- interface. |
| 10298 |
|
| 10299 |
if Ada_Version >= Ada_2012 |
| 10300 |
and then Present (Concval) |
| 10301 |
and then Is_Class_Wide_Type (Conc_Typ) |
| 10302 |
and then Is_Concurrent_Interface (Conc_Typ) |
| 10303 |
then |
| 10304 |
declare |
| 10305 |
Has_Impl : Boolean := False; |
| 10306 |
Impl_Kind : Name_Id := No_Name; |
| 10307 |
|
| 10308 |
begin |
| 10309 |
-- Check whether the Ename is flagged by pragma Implemented |
| 10310 |
|
| 10311 |
if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then |
| 10312 |
Has_Impl := True; |
| 10313 |
Impl_Kind := Implementation_Kind (Entity (Ename)); |
| 10314 |
end if; |
| 10315 |
|
| 10316 |
-- The procedure_or_entry_NAME is guaranteed to be overridden by |
| 10317 |
-- an entry. Create a call to predefined primitive _Disp_Requeue. |
| 10318 |
|
| 10319 |
if Has_Impl and then Impl_Kind = Name_By_Entry then |
| 10320 |
Rewrite (N, Build_Dispatching_Requeue); |
| 10321 |
Analyze (N); |
| 10322 |
Insert_After (N, Build_Skip_Statement (N)); |
| 10323 |
|
| 10324 |
-- The procedure_or_entry_NAME is guaranteed to be overridden by |
| 10325 |
-- a protected procedure. In this case the requeue is transformed |
| 10326 |
-- into a dispatching call. |
| 10327 |
|
| 10328 |
elsif Has_Impl |
| 10329 |
and then Impl_Kind = Name_By_Protected_Procedure |
| 10330 |
then |
| 10331 |
Rewrite (N, Build_Dispatching_Call_Equivalent); |
| 10332 |
Analyze (N); |
| 10333 |
|
| 10334 |
-- The procedure_or_entry_NAME's implementation kind is either |
| 10335 |
-- By_Any, Optional, or pragma Implemented was not applied at all. |
| 10336 |
-- In this case a runtime test determines whether Ename denotes an |
| 10337 |
-- entry or a protected procedure and performs the appropriate |
| 10338 |
-- call. |
| 10339 |
|
| 10340 |
else |
| 10341 |
Rewrite (N, Build_Dispatching_Requeue_To_Any); |
| 10342 |
Analyze (N); |
| 10343 |
end if; |
| 10344 |
end; |
| 10345 |
|
| 10346 |
-- Processing for regular (nondispatching) requeues |
| 10347 |
|
| 10348 |
else |
| 10349 |
Rewrite (N, Build_Normal_Requeue); |
| 10350 |
Analyze (N); |
| 10351 |
Insert_After (N, Build_Skip_Statement (N)); |
| 10352 |
end if; |
| 10353 |
end Expand_N_Requeue_Statement; |
| 10354 |
|
| 10355 |
------------------------------- |
| 10356 |
-- Expand_N_Selective_Accept -- |
| 10357 |
------------------------------- |
| 10358 |
|
| 10359 |
procedure Expand_N_Selective_Accept (N : Node_Id) is |
| 10360 |
Loc : constant Source_Ptr := Sloc (N); |
| 10361 |
Alts : constant List_Id := Select_Alternatives (N); |
| 10362 |
|
| 10363 |
-- Note: in the below declarations a lot of new lists are allocated |
| 10364 |
-- unconditionally which may well not end up being used. That's not |
| 10365 |
-- a good idea since it wastes space gratuitously ??? |
| 10366 |
|
| 10367 |
Accept_Case : List_Id; |
| 10368 |
Accept_List : constant List_Id := New_List; |
| 10369 |
|
| 10370 |
Alt : Node_Id; |
| 10371 |
Alt_List : constant List_Id := New_List; |
| 10372 |
Alt_Stats : List_Id; |
| 10373 |
Ann : Entity_Id := Empty; |
| 10374 |
|
| 10375 |
Check_Guard : Boolean := True; |
| 10376 |
|
| 10377 |
Decls : constant List_Id := New_List; |
| 10378 |
Stats : constant List_Id := New_List; |
| 10379 |
Body_List : constant List_Id := New_List; |
| 10380 |
Trailing_List : constant List_Id := New_List; |
| 10381 |
|
| 10382 |
Choices : List_Id; |
| 10383 |
Else_Present : Boolean := False; |
| 10384 |
Terminate_Alt : Node_Id := Empty; |
| 10385 |
Select_Mode : Node_Id; |
| 10386 |
|
| 10387 |
Delay_Case : List_Id; |
| 10388 |
Delay_Count : Integer := 0; |
| 10389 |
Delay_Val : Entity_Id; |
| 10390 |
Delay_Index : Entity_Id; |
| 10391 |
Delay_Min : Entity_Id; |
| 10392 |
Delay_Num : Pos := 1; |
| 10393 |
Delay_Alt_List : List_Id := New_List; |
| 10394 |
Delay_List : constant List_Id := New_List; |
| 10395 |
D : Entity_Id; |
| 10396 |
M : Entity_Id; |
| 10397 |
|
| 10398 |
First_Delay : Boolean := True; |
| 10399 |
Guard_Open : Entity_Id; |
| 10400 |
|
| 10401 |
End_Lab : Node_Id; |
| 10402 |
Index : Pos := 1; |
| 10403 |
Lab : Node_Id; |
| 10404 |
Num_Alts : Nat; |
| 10405 |
Num_Accept : Nat := 0; |
| 10406 |
Proc : Node_Id; |
| 10407 |
Time_Type : Entity_Id := Empty; |
| 10408 |
Select_Call : Node_Id; |
| 10409 |
|
| 10410 |
Qnam : constant Entity_Id := |
| 10411 |
Make_Defining_Identifier (Loc, New_External_Name ('S', 0)); |
| 10412 |
|
| 10413 |
Xnam : constant Entity_Id := |
| 10414 |
Make_Defining_Identifier (Loc, New_External_Name ('J', 1)); |
| 10415 |
|
| 10416 |
----------------------- |
| 10417 |
-- Local subprograms -- |
| 10418 |
----------------------- |
| 10419 |
|
| 10420 |
function Accept_Or_Raise return List_Id; |
| 10421 |
-- For the rare case where delay alternatives all have guards, and |
| 10422 |
-- all of them are closed, it is still possible that there were open |
| 10423 |
-- accept alternatives with no callers. We must reexamine the |
| 10424 |
-- Accept_List, and execute a selective wait with no else if some |
| 10425 |
-- accept is open. If none, we raise program_error. |
| 10426 |
|
| 10427 |
procedure Add_Accept (Alt : Node_Id); |
| 10428 |
-- Process a single accept statement in a select alternative. Build |
| 10429 |
-- procedure for body of accept, and add entry to dispatch table with |
| 10430 |
-- expression for guard, in preparation for call to run time select. |
| 10431 |
|
| 10432 |
function Make_And_Declare_Label (Num : Int) return Node_Id; |
| 10433 |
-- Manufacture a label using Num as a serial number and declare it. |
| 10434 |
-- The declaration is appended to Decls. The label marks the trailing |
| 10435 |
-- statements of an accept or delay alternative. |
| 10436 |
|
| 10437 |
function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id; |
| 10438 |
-- Build call to Selective_Wait runtime routine |
| 10439 |
|
| 10440 |
procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int); |
| 10441 |
-- Add code to compare value of delay with previous values, and |
| 10442 |
-- generate case entry for trailing statements. |
| 10443 |
|
| 10444 |
procedure Process_Accept_Alternative |
| 10445 |
(Alt : Node_Id; |
| 10446 |
Index : Int; |
| 10447 |
Proc : Node_Id); |
| 10448 |
-- Add code to call corresponding procedure, and branch to |
| 10449 |
-- trailing statements, if any. |
| 10450 |
|
| 10451 |
--------------------- |
| 10452 |
-- Accept_Or_Raise -- |
| 10453 |
--------------------- |
| 10454 |
|
| 10455 |
function Accept_Or_Raise return List_Id is |
| 10456 |
Cond : Node_Id; |
| 10457 |
Stats : List_Id; |
| 10458 |
J : constant Entity_Id := Make_Temporary (Loc, 'J'); |
| 10459 |
|
| 10460 |
begin |
| 10461 |
-- We generate the following: |
| 10462 |
|
| 10463 |
-- for J in q'range loop |
| 10464 |
-- if q(J).S /=null_task_entry then |
| 10465 |
-- selective_wait (simple_mode,...); |
| 10466 |
-- done := True; |
| 10467 |
-- exit; |
| 10468 |
-- end if; |
| 10469 |
-- end loop; |
| 10470 |
-- |
| 10471 |
-- if no rendez_vous then |
| 10472 |
-- raise program_error; |
| 10473 |
-- end if; |
| 10474 |
|
| 10475 |
-- Note that the code needs to know that the selector name |
| 10476 |
-- in an Accept_Alternative is named S. |
| 10477 |
|
| 10478 |
Cond := Make_Op_Ne (Loc, |
| 10479 |
Left_Opnd => |
| 10480 |
Make_Selected_Component (Loc, |
| 10481 |
Prefix => |
| 10482 |
Make_Indexed_Component (Loc, |
| 10483 |
Prefix => New_Occurrence_Of (Qnam, Loc), |
| 10484 |
Expressions => New_List (New_Occurrence_Of (J, Loc))), |
| 10485 |
Selector_Name => Make_Identifier (Loc, Name_S)), |
| 10486 |
Right_Opnd => |
| 10487 |
New_Occurrence_Of (RTE (RE_Null_Task_Entry), Loc)); |
| 10488 |
|
| 10489 |
Stats := New_List ( |
| 10490 |
Make_Implicit_Loop_Statement (N, |
| 10491 |
Iteration_Scheme => |
| 10492 |
Make_Iteration_Scheme (Loc, |
| 10493 |
Loop_Parameter_Specification => |
| 10494 |
Make_Loop_Parameter_Specification (Loc, |
| 10495 |
Defining_Identifier => J, |
| 10496 |
Discrete_Subtype_Definition => |
| 10497 |
Make_Attribute_Reference (Loc, |
| 10498 |
Prefix => New_Occurrence_Of (Qnam, Loc), |
| 10499 |
Attribute_Name => Name_Range, |
| 10500 |
Expressions => New_List ( |
| 10501 |
Make_Integer_Literal (Loc, 1))))), |
| 10502 |
|
| 10503 |
Statements => New_List ( |
| 10504 |
Make_Implicit_If_Statement (N, |
| 10505 |
Condition => Cond, |
| 10506 |
Then_Statements => New_List ( |
| 10507 |
Make_Select_Call ( |
| 10508 |
New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)), |
| 10509 |
Make_Exit_Statement (Loc)))))); |
| 10510 |
|
| 10511 |
Append_To (Stats, |
| 10512 |
Make_Raise_Program_Error (Loc, |
| 10513 |
Condition => Make_Op_Eq (Loc, |
| 10514 |
Left_Opnd => New_Occurrence_Of (Xnam, Loc), |
| 10515 |
Right_Opnd => |
| 10516 |
New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)), |
| 10517 |
Reason => PE_All_Guards_Closed)); |
| 10518 |
|
| 10519 |
return Stats; |
| 10520 |
end Accept_Or_Raise; |
| 10521 |
|
| 10522 |
---------------- |
| 10523 |
-- Add_Accept -- |
| 10524 |
---------------- |
| 10525 |
|
| 10526 |
procedure Add_Accept (Alt : Node_Id) is |
| 10527 |
Acc_Stm : constant Node_Id := Accept_Statement (Alt); |
| 10528 |
Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm); |
| 10529 |
Eloc : constant Source_Ptr := Sloc (Ename); |
| 10530 |
Eent : constant Entity_Id := Entity (Ename); |
| 10531 |
Index : constant Node_Id := Entry_Index (Acc_Stm); |
| 10532 |
|
| 10533 |
Call : Node_Id; |
| 10534 |
Expr : Node_Id; |
| 10535 |
Null_Body : Node_Id; |
| 10536 |
PB_Ent : Entity_Id; |
| 10537 |
Proc_Body : Node_Id; |
| 10538 |
|
| 10539 |
-- Start of processing for Add_Accept |
| 10540 |
|
| 10541 |
begin |
| 10542 |
if No (Ann) then |
| 10543 |
Ann := Node (Last_Elmt (Accept_Address (Eent))); |
| 10544 |
end if; |
| 10545 |
|
| 10546 |
if Present (Condition (Alt)) then |
| 10547 |
Expr := |
| 10548 |
Make_If_Expression (Eloc, New_List ( |
| 10549 |
Condition (Alt), |
| 10550 |
Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)), |
| 10551 |
New_Occurrence_Of (RTE (RE_Null_Task_Entry), Eloc))); |
| 10552 |
else |
| 10553 |
Expr := Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)); |
| 10554 |
end if; |
| 10555 |
|
| 10556 |
if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then |
| 10557 |
Null_Body := New_Occurrence_Of (Standard_False, Eloc); |
| 10558 |
|
| 10559 |
-- Always add call to Abort_Undefer when generating code, since |
| 10560 |
-- this is what the runtime expects (abort deferred in |
| 10561 |
-- Selective_Wait). In CodePeer mode this only confuses the |
| 10562 |
-- analysis with unknown calls, so don't do it. |
| 10563 |
|
| 10564 |
if not CodePeer_Mode then |
| 10565 |
Call := Build_Runtime_Call (Loc, RE_Abort_Undefer); |
| 10566 |
Insert_Before |
| 10567 |
(First (Statements (Handled_Statement_Sequence |
| 10568 |
(Accept_Statement (Alt)))), |
| 10569 |
Call); |
| 10570 |
Analyze (Call); |
| 10571 |
end if; |
| 10572 |
|
| 10573 |
PB_Ent := |
| 10574 |
Make_Defining_Identifier (Eloc, |
| 10575 |
New_External_Name (Chars (Ename), 'A', Num_Accept)); |
| 10576 |
|
| 10577 |
-- Link the acceptor to the original receiving entry |
| 10578 |
|
| 10579 |
Mutate_Ekind (PB_Ent, E_Procedure); |
| 10580 |
Set_Receiving_Entry (PB_Ent, Eent); |
| 10581 |
|
| 10582 |
if Comes_From_Source (Alt) then |
| 10583 |
Set_Debug_Info_Needed (PB_Ent); |
| 10584 |
end if; |
| 10585 |
|
| 10586 |
Proc_Body := |
| 10587 |
Make_Subprogram_Body (Eloc, |
| 10588 |
Specification => |
| 10589 |
Make_Procedure_Specification (Eloc, |
| 10590 |
Defining_Unit_Name => PB_Ent), |
| 10591 |
Declarations => Declarations (Acc_Stm), |
| 10592 |
Handled_Statement_Sequence => |
| 10593 |
Build_Accept_Body (Accept_Statement (Alt))); |
| 10594 |
|
| 10595 |
Reset_Scopes_To (Proc_Body, PB_Ent); |
| 10596 |
|
| 10597 |
-- During the analysis of the body of the accept statement, any |
| 10598 |
-- zero cost exception handler records were collected in the |
| 10599 |
-- Accept_Handler_Records field of the N_Accept_Alternative node. |
| 10600 |
-- This is where we move them to where they belong, namely the |
| 10601 |
-- newly created procedure. |
| 10602 |
|
| 10603 |
Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt)); |
| 10604 |
Append (Proc_Body, Body_List); |
| 10605 |
|
| 10606 |
else |
| 10607 |
Null_Body := New_Occurrence_Of (Standard_True, Eloc); |
| 10608 |
|
| 10609 |
-- if accept statement has declarations, insert above, given that |
| 10610 |
-- we are not creating a body for the accept. |
| 10611 |
|
| 10612 |
if Present (Declarations (Acc_Stm)) then |
| 10613 |
Insert_Actions (N, Declarations (Acc_Stm)); |
| 10614 |
end if; |
| 10615 |
end if; |
| 10616 |
|
| 10617 |
Append_To (Accept_List, |
| 10618 |
Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr))); |
| 10619 |
|
| 10620 |
Num_Accept := Num_Accept + 1; |
| 10621 |
end Add_Accept; |
| 10622 |
|
| 10623 |
---------------------------- |
| 10624 |
-- Make_And_Declare_Label -- |
| 10625 |
---------------------------- |
| 10626 |
|
| 10627 |
function Make_And_Declare_Label (Num : Int) return Node_Id is |
| 10628 |
Lab_Id : Node_Id; |
| 10629 |
|
| 10630 |
begin |
| 10631 |
Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num)); |
| 10632 |
Lab := |
| 10633 |
Make_Label (Loc, Lab_Id); |
| 10634 |
|
| 10635 |
Append_To (Decls, |
| 10636 |
Make_Implicit_Label_Declaration (Loc, |
| 10637 |
Defining_Identifier => |
| 10638 |
Make_Defining_Identifier (Loc, Chars (Lab_Id)), |
| 10639 |
Label_Construct => Lab)); |
| 10640 |
|
| 10641 |
return Lab; |
| 10642 |
end Make_And_Declare_Label; |
| 10643 |
|
| 10644 |
---------------------- |
| 10645 |
-- Make_Select_Call -- |
| 10646 |
---------------------- |
| 10647 |
|
| 10648 |
function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is |
| 10649 |
Params : constant List_Id := New_List; |
| 10650 |
|
| 10651 |
begin |
| 10652 |
Append_To (Params, |
| 10653 |
Make_Attribute_Reference (Loc, |
| 10654 |
Prefix => New_Occurrence_Of (Qnam, Loc), |
| 10655 |
Attribute_Name => Name_Unchecked_Access)); |
| 10656 |
Append_To (Params, Select_Mode); |
| 10657 |
Append_To (Params, New_Occurrence_Of (Ann, Loc)); |
| 10658 |
Append_To (Params, New_Occurrence_Of (Xnam, Loc)); |
| 10659 |
|
| 10660 |
return |
| 10661 |
Make_Procedure_Call_Statement (Loc, |
| 10662 |
Name => New_Occurrence_Of (RTE (RE_Selective_Wait), Loc), |
| 10663 |
Parameter_Associations => Params); |
| 10664 |
end Make_Select_Call; |
| 10665 |
|
| 10666 |
-------------------------------- |
| 10667 |
-- Process_Accept_Alternative -- |
| 10668 |
-------------------------------- |
| 10669 |
|
| 10670 |
procedure Process_Accept_Alternative |
| 10671 |
(Alt : Node_Id; |
| 10672 |
Index : Int; |
| 10673 |
Proc : Node_Id) |
| 10674 |
is |
| 10675 |
Astmt : constant Node_Id := Accept_Statement (Alt); |
| 10676 |
Alt_Stats : List_Id; |
| 10677 |
|
| 10678 |
begin |
| 10679 |
Adjust_Condition (Condition (Alt)); |
| 10680 |
|
| 10681 |
-- Accept with body |
| 10682 |
|
| 10683 |
if Present (Handled_Statement_Sequence (Astmt)) then |
| 10684 |
Alt_Stats := |
| 10685 |
New_List ( |
| 10686 |
Make_Procedure_Call_Statement (Sloc (Proc), |
| 10687 |
Name => |
| 10688 |
New_Occurrence_Of |
| 10689 |
(Defining_Unit_Name (Specification (Proc)), |
| 10690 |
Sloc (Proc)))); |
| 10691 |
|
| 10692 |
-- Accept with no body (followed by trailing statements) |
| 10693 |
|
| 10694 |
else |
| 10695 |
declare |
| 10696 |
Entry_Id : constant Entity_Id := |
| 10697 |
Entity (Entry_Direct_Name (Accept_Statement (Alt))); |
| 10698 |
begin |
| 10699 |
-- Ada 2022 (AI12-0279) |
| 10700 |
|
| 10701 |
if Has_Yield_Aspect (Entry_Id) |
| 10702 |
and then RTE_Available (RE_Yield) |
| 10703 |
then |
| 10704 |
Alt_Stats := |
| 10705 |
New_List ( |
| 10706 |
Make_Procedure_Call_Statement (Sloc (Proc), |
| 10707 |
New_Occurrence_Of (RTE (RE_Yield), Sloc (Proc)))); |
| 10708 |
else |
| 10709 |
Alt_Stats := Empty_List; |
| 10710 |
end if; |
| 10711 |
end; |
| 10712 |
end if; |
| 10713 |
|
| 10714 |
Ensure_Statement_Present (Sloc (Astmt), Alt); |
| 10715 |
|
| 10716 |
-- After the call, if any, branch to trailing statements, if any. |
| 10717 |
-- We create a label for each, as well as the corresponding label |
| 10718 |
-- declaration. |
| 10719 |
|
| 10720 |
if not Is_Empty_List (Statements (Alt)) then |
| 10721 |
Lab := Make_And_Declare_Label (Index); |
| 10722 |
Append (Lab, Trailing_List); |
| 10723 |
Append_List (Statements (Alt), Trailing_List); |
| 10724 |
Append_To (Trailing_List, |
| 10725 |
Make_Goto_Statement (Loc, |
| 10726 |
Name => New_Copy (Identifier (End_Lab)))); |
| 10727 |
|
| 10728 |
else |
| 10729 |
Lab := End_Lab; |
| 10730 |
end if; |
| 10731 |
|
| 10732 |
Append_To (Alt_Stats, |
| 10733 |
Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab)))); |
| 10734 |
|
| 10735 |
Append_To (Alt_List, |
| 10736 |
Make_Case_Statement_Alternative (Loc, |
| 10737 |
Discrete_Choices => New_List (Make_Integer_Literal (Loc, Index)), |
| 10738 |
Statements => Alt_Stats)); |
| 10739 |
end Process_Accept_Alternative; |
| 10740 |
|
| 10741 |
------------------------------- |
| 10742 |
-- Process_Delay_Alternative -- |
| 10743 |
------------------------------- |
| 10744 |
|
| 10745 |
procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is |
| 10746 |
Dloc : constant Source_Ptr := Sloc (Delay_Statement (Alt)); |
| 10747 |
Cond : Node_Id; |
| 10748 |
Delay_Alt : List_Id; |
| 10749 |
|
| 10750 |
begin |
| 10751 |
-- Deal with C/Fortran boolean as delay condition |
| 10752 |
|
| 10753 |
Adjust_Condition (Condition (Alt)); |
| 10754 |
|
| 10755 |
-- Determine the smallest specified delay |
| 10756 |
|
| 10757 |
-- for each delay alternative generate: |
| 10758 |
|
| 10759 |
-- if guard-expression then |
| 10760 |
-- Delay_Val := delay-expression; |
| 10761 |
-- Guard_Open := True; |
| 10762 |
-- if Delay_Val < Delay_Min then |
| 10763 |
-- Delay_Min := Delay_Val; |
| 10764 |
-- Delay_Index := Index; |
| 10765 |
-- end if; |
| 10766 |
-- end if; |
| 10767 |
|
| 10768 |
-- The enclosing if-statement is omitted if there is no guard |
| 10769 |
|
| 10770 |
if Delay_Count = 1 or else First_Delay then |
| 10771 |
First_Delay := False; |
| 10772 |
|
| 10773 |
Delay_Alt := New_List ( |
| 10774 |
Make_Assignment_Statement (Loc, |
| 10775 |
Name => New_Occurrence_Of (Delay_Min, Loc), |
| 10776 |
Expression => Expression (Delay_Statement (Alt)))); |
| 10777 |
|
| 10778 |
if Delay_Count > 1 then |
| 10779 |
Append_To (Delay_Alt, |
| 10780 |
Make_Assignment_Statement (Loc, |
| 10781 |
Name => New_Occurrence_Of (Delay_Index, Loc), |
| 10782 |
Expression => Make_Integer_Literal (Loc, Index))); |
| 10783 |
end if; |
| 10784 |
|
| 10785 |
else |
| 10786 |
Delay_Alt := New_List ( |
| 10787 |
Make_Assignment_Statement (Loc, |
| 10788 |
Name => New_Occurrence_Of (Delay_Val, Loc), |
| 10789 |
Expression => Expression (Delay_Statement (Alt)))); |
| 10790 |
|
| 10791 |
if Time_Type = Standard_Duration then |
| 10792 |
Cond := |
| 10793 |
Make_Op_Lt (Loc, |
| 10794 |
Left_Opnd => New_Occurrence_Of (Delay_Val, Loc), |
| 10795 |
Right_Opnd => New_Occurrence_Of (Delay_Min, Loc)); |
| 10796 |
|
| 10797 |
else |
| 10798 |
-- The scope of the time type must define a comparison |
| 10799 |
-- operator. The scope itself may not be visible, so we |
| 10800 |
-- construct a node with entity information to insure that |
| 10801 |
-- semantic analysis can find the proper operator. |
| 10802 |
|
| 10803 |
Cond := |
| 10804 |
Make_Function_Call (Loc, |
| 10805 |
Name => Make_Selected_Component (Loc, |
| 10806 |
Prefix => |
| 10807 |
New_Occurrence_Of (Scope (Time_Type), Loc), |
| 10808 |
Selector_Name => |
| 10809 |
Make_Operator_Symbol (Loc, |
| 10810 |
Chars => Name_Op_Lt, |
| 10811 |
Strval => No_String)), |
| 10812 |
Parameter_Associations => |
| 10813 |
New_List ( |
| 10814 |
New_Occurrence_Of (Delay_Val, Loc), |
| 10815 |
New_Occurrence_Of (Delay_Min, Loc))); |
| 10816 |
|
| 10817 |
Set_Entity (Prefix (Name (Cond)), Scope (Time_Type)); |
| 10818 |
end if; |
| 10819 |
|
| 10820 |
Append_To (Delay_Alt, |
| 10821 |
Make_Implicit_If_Statement (N, |
| 10822 |
Condition => Cond, |
| 10823 |
Then_Statements => New_List ( |
| 10824 |
Make_Assignment_Statement (Loc, |
| 10825 |
Name => New_Occurrence_Of (Delay_Min, Loc), |
| 10826 |
Expression => New_Occurrence_Of (Delay_Val, Loc)), |
| 10827 |
|
| 10828 |
Make_Assignment_Statement (Loc, |
| 10829 |
Name => New_Occurrence_Of (Delay_Index, Loc), |
| 10830 |
Expression => Make_Integer_Literal (Loc, Index))))); |
| 10831 |
end if; |
| 10832 |
|
| 10833 |
if Check_Guard then |
| 10834 |
Append_To (Delay_Alt, |
| 10835 |
Make_Assignment_Statement (Loc, |
| 10836 |
Name => New_Occurrence_Of (Guard_Open, Loc), |
| 10837 |
Expression => New_Occurrence_Of (Standard_True, Loc))); |
| 10838 |
end if; |
| 10839 |
|
| 10840 |
if Present (Condition (Alt)) then |
| 10841 |
Delay_Alt := New_List ( |
| 10842 |
Make_Implicit_If_Statement (N, |
| 10843 |
Condition => Condition (Alt), |
| 10844 |
Then_Statements => Delay_Alt)); |
| 10845 |
end if; |
| 10846 |
|
| 10847 |
Append_List (Delay_Alt, Delay_List); |
| 10848 |
|
| 10849 |
Ensure_Statement_Present (Dloc, Alt); |
| 10850 |
|
| 10851 |
-- If the delay alternative has a statement part, add choice to the |
| 10852 |
-- case statements for delays. |
| 10853 |
|
| 10854 |
if not Is_Empty_List (Statements (Alt)) then |
| 10855 |
|
| 10856 |
if Delay_Count = 1 then |
| 10857 |
Append_List (Statements (Alt), Delay_Alt_List); |
| 10858 |
|
| 10859 |
else |
| 10860 |
Append_To (Delay_Alt_List, |
| 10861 |
Make_Case_Statement_Alternative (Loc, |
| 10862 |
Discrete_Choices => New_List ( |
| 10863 |
Make_Integer_Literal (Loc, Index)), |
| 10864 |
Statements => Statements (Alt))); |
| 10865 |
end if; |
| 10866 |
|
| 10867 |
elsif Delay_Count = 1 then |
| 10868 |
|
| 10869 |
-- If the single delay has no trailing statements, add a branch |
| 10870 |
-- to the exit label to the selective wait. |
| 10871 |
|
| 10872 |
Delay_Alt_List := New_List ( |
| 10873 |
Make_Goto_Statement (Loc, |
| 10874 |
Name => New_Copy (Identifier (End_Lab)))); |
| 10875 |
|
| 10876 |
end if; |
| 10877 |
end Process_Delay_Alternative; |
| 10878 |
|
| 10879 |
-- Start of processing for Expand_N_Selective_Accept |
| 10880 |
|
| 10881 |
begin |
| 10882 |
Process_Statements_For_Controlled_Objects (N); |
| 10883 |
|
| 10884 |
-- First insert some declarations before the select. The first is: |
| 10885 |
|
| 10886 |
-- Ann : Address |
| 10887 |
|
| 10888 |
-- This variable holds the parameters passed to the accept body. This |
| 10889 |
-- declaration has already been inserted by the time we get here by |
| 10890 |
-- a call to Expand_Accept_Declarations made from the semantics when |
| 10891 |
-- processing the first accept statement contained in the select. We |
| 10892 |
-- can find this entity as Accept_Address (E), where E is any of the |
| 10893 |
-- entries references by contained accept statements. |
| 10894 |
|
| 10895 |
-- The first step is to scan the list of Selective_Accept_Statements |
| 10896 |
-- to find this entity, and also count the number of accepts, and |
| 10897 |
-- determine if terminated, delay or else is present: |
| 10898 |
|
| 10899 |
Num_Alts := 0; |
| 10900 |
|
| 10901 |
Alt := First (Alts); |
| 10902 |
while Present (Alt) loop |
| 10903 |
Process_Statements_For_Controlled_Objects (Alt); |
| 10904 |
|
| 10905 |
if Nkind (Alt) = N_Accept_Alternative then |
| 10906 |
Add_Accept (Alt); |
| 10907 |
|
| 10908 |
elsif Nkind (Alt) = N_Delay_Alternative then |
| 10909 |
Delay_Count := Delay_Count + 1; |
| 10910 |
|
| 10911 |
-- If the delays are relative delays, the delay expressions have |
| 10912 |
-- type Standard_Duration. Otherwise they must have some time type |
| 10913 |
-- recognized by GNAT. |
| 10914 |
|
| 10915 |
if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then |
| 10916 |
Time_Type := Standard_Duration; |
| 10917 |
else |
| 10918 |
Time_Type := Etype (Expression (Delay_Statement (Alt))); |
| 10919 |
|
| 10920 |
if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) |
| 10921 |
or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time) |
| 10922 |
then |
| 10923 |
null; |
| 10924 |
else |
| 10925 |
-- Move this check to sem??? |
| 10926 |
Error_Msg_NE ( |
| 10927 |
"& is not a time type (RM 9.6(6))", |
| 10928 |
Expression (Delay_Statement (Alt)), Time_Type); |
| 10929 |
Time_Type := Standard_Duration; |
| 10930 |
Set_Etype (Expression (Delay_Statement (Alt)), Any_Type); |
| 10931 |
end if; |
| 10932 |
end if; |
| 10933 |
|
| 10934 |
if No (Condition (Alt)) then |
| 10935 |
|
| 10936 |
-- This guard will always be open |
| 10937 |
|
| 10938 |
Check_Guard := False; |
| 10939 |
end if; |
| 10940 |
|
| 10941 |
elsif Nkind (Alt) = N_Terminate_Alternative then |
| 10942 |
Adjust_Condition (Condition (Alt)); |
| 10943 |
Terminate_Alt := Alt; |
| 10944 |
end if; |
| 10945 |
|
| 10946 |
Num_Alts := Num_Alts + 1; |
| 10947 |
Next (Alt); |
| 10948 |
end loop; |
| 10949 |
|
| 10950 |
Else_Present := Present (Else_Statements (N)); |
| 10951 |
|
| 10952 |
-- At the same time (see procedure Add_Accept) we build the accept list: |
| 10953 |
|
| 10954 |
-- Qnn : Accept_List (1 .. num-select) := ( |
| 10955 |
-- (null-body, entry-index), |
| 10956 |
-- (null-body, entry-index), |
| 10957 |
-- .. |
| 10958 |
-- (null_body, entry-index)); |
| 10959 |
|
| 10960 |
-- In the above declaration, null-body is True if the corresponding |
| 10961 |
-- accept has no body, and false otherwise. The entry is either the |
| 10962 |
-- entry index expression if there is no guard, or if a guard is |
| 10963 |
-- present, then an if expression of the form: |
| 10964 |
|
| 10965 |
-- (if guard then entry-index else Null_Task_Entry) |
| 10966 |
|
| 10967 |
-- If a guard is statically known to be false, the entry can simply |
| 10968 |
-- be omitted from the accept list. |
| 10969 |
|
| 10970 |
Append_To (Decls, |
| 10971 |
Make_Object_Declaration (Loc, |
| 10972 |
Defining_Identifier => Qnam, |
| 10973 |
Object_Definition => New_Occurrence_Of (RTE (RE_Accept_List), Loc), |
| 10974 |
Aliased_Present => True, |
| 10975 |
Expression => |
| 10976 |
Make_Qualified_Expression (Loc, |
| 10977 |
Subtype_Mark => |
| 10978 |
New_Occurrence_Of (RTE (RE_Accept_List), Loc), |
| 10979 |
Expression => |
| 10980 |
Make_Aggregate (Loc, Expressions => Accept_List)))); |
| 10981 |
|
| 10982 |
-- Then we declare the variable that holds the index for the accept |
| 10983 |
-- that will be selected for service: |
| 10984 |
|
| 10985 |
-- Xnn : Select_Index; |
| 10986 |
|
| 10987 |
Append_To (Decls, |
| 10988 |
Make_Object_Declaration (Loc, |
| 10989 |
Defining_Identifier => Xnam, |
| 10990 |
Object_Definition => |
| 10991 |
New_Occurrence_Of (RTE (RE_Select_Index), Loc), |
| 10992 |
Expression => |
| 10993 |
New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc))); |
| 10994 |
|
| 10995 |
-- After this follow procedure declarations for each accept body |
| 10996 |
|
| 10997 |
-- procedure Pnn is |
| 10998 |
-- begin |
| 10999 |
-- ... |
| 11000 |
-- end; |
| 11001 |
|
| 11002 |
-- where the ... are statements from the corresponding procedure body. |
| 11003 |
-- No parameters are involved, since the parameters are passed via Ann |
| 11004 |
-- and the parameter references have already been expanded to be direct |
| 11005 |
-- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore, |
| 11006 |
-- any embedded tasking statements (which would normally be illegal in |
| 11007 |
-- procedures), have been converted to calls to the tasking runtime so |
| 11008 |
-- there is no problem in putting them into procedures. |
| 11009 |
|
| 11010 |
-- The original accept statement has been expanded into a block in |
| 11011 |
-- the same fashion as for simple accepts (see Build_Accept_Body). |
| 11012 |
|
| 11013 |
-- Note: we don't really need to build these procedures for the case |
| 11014 |
-- where no delay statement is present, but it is just as easy to |
| 11015 |
-- build them unconditionally, and not significantly inefficient, |
| 11016 |
-- since if they are short they will be inlined anyway. |
| 11017 |
|
| 11018 |
-- The procedure declarations have been assembled in Body_List |
| 11019 |
|
| 11020 |
-- If delays are present, we must compute the required delay. |
| 11021 |
-- We first generate the declarations: |
| 11022 |
|
| 11023 |
-- Delay_Index : Boolean := 0; |
| 11024 |
-- Delay_Min : Some_Time_Type.Time; |
| 11025 |
-- Delay_Val : Some_Time_Type.Time; |
| 11026 |
|
| 11027 |
-- Delay_Index will be set to the index of the minimum delay, i.e. the |
| 11028 |
-- active delay that is actually chosen as the basis for the possible |
| 11029 |
-- delay if an immediate rendez-vous is not possible. |
| 11030 |
|
| 11031 |
-- In the most common case there is a single delay statement, and this |
| 11032 |
-- is handled specially. |
| 11033 |
|
| 11034 |
if Delay_Count > 0 then |
| 11035 |
|
| 11036 |
-- Generate the required declarations |
| 11037 |
|
| 11038 |
Delay_Val := |
| 11039 |
Make_Defining_Identifier (Loc, New_External_Name ('D', 1)); |
| 11040 |
Delay_Index := |
| 11041 |
Make_Defining_Identifier (Loc, New_External_Name ('D', 2)); |
| 11042 |
Delay_Min := |
| 11043 |
Make_Defining_Identifier (Loc, New_External_Name ('D', 3)); |
| 11044 |
|
| 11045 |
pragma Assert (Present (Time_Type)); |
| 11046 |
|
| 11047 |
Append_To (Decls, |
| 11048 |
Make_Object_Declaration (Loc, |
| 11049 |
Defining_Identifier => Delay_Val, |
| 11050 |
Object_Definition => New_Occurrence_Of (Time_Type, Loc))); |
| 11051 |
|
| 11052 |
Append_To (Decls, |
| 11053 |
Make_Object_Declaration (Loc, |
| 11054 |
Defining_Identifier => Delay_Index, |
| 11055 |
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc), |
| 11056 |
Expression => Make_Integer_Literal (Loc, 0))); |
| 11057 |
|
| 11058 |
Append_To (Decls, |
| 11059 |
Make_Object_Declaration (Loc, |
| 11060 |
Defining_Identifier => Delay_Min, |
| 11061 |
Object_Definition => New_Occurrence_Of (Time_Type, Loc), |
| 11062 |
Expression => |
| 11063 |
Unchecked_Convert_To (Time_Type, |
| 11064 |
Make_Attribute_Reference (Loc, |
| 11065 |
Prefix => |
| 11066 |
New_Occurrence_Of (Underlying_Type (Time_Type), Loc), |
| 11067 |
Attribute_Name => Name_Last)))); |
| 11068 |
|
| 11069 |
-- Create Duration and Delay_Mode objects used for passing a delay |
| 11070 |
-- value to RTS |
| 11071 |
|
| 11072 |
D := Make_Temporary (Loc, 'D'); |
| 11073 |
M := Make_Temporary (Loc, 'M'); |
| 11074 |
|
| 11075 |
declare |
| 11076 |
Discr : Entity_Id; |
| 11077 |
|
| 11078 |
begin |
| 11079 |
-- Note that these values are defined in s-osprim.ads and must |
| 11080 |
-- be kept in sync: |
| 11081 |
-- |
| 11082 |
-- Relative : constant := 0; |
| 11083 |
-- Absolute_Calendar : constant := 1; |
| 11084 |
-- Absolute_RT : constant := 2; |
| 11085 |
|
| 11086 |
if Time_Type = Standard_Duration then |
| 11087 |
Discr := Make_Integer_Literal (Loc, 0); |
| 11088 |
|
| 11089 |
elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then |
| 11090 |
Discr := Make_Integer_Literal (Loc, 1); |
| 11091 |
|
| 11092 |
else |
| 11093 |
pragma Assert |
| 11094 |
(Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)); |
| 11095 |
Discr := Make_Integer_Literal (Loc, 2); |
| 11096 |
end if; |
| 11097 |
|
| 11098 |
Append_To (Decls, |
| 11099 |
Make_Object_Declaration (Loc, |
| 11100 |
Defining_Identifier => D, |
| 11101 |
Object_Definition => |
| 11102 |
New_Occurrence_Of (Standard_Duration, Loc))); |
| 11103 |
|
| 11104 |
Append_To (Decls, |
| 11105 |
Make_Object_Declaration (Loc, |
| 11106 |
Defining_Identifier => M, |
| 11107 |
Object_Definition => |
| 11108 |
New_Occurrence_Of (Standard_Integer, Loc), |
| 11109 |
Expression => Discr)); |
| 11110 |
end; |
| 11111 |
|
| 11112 |
if Check_Guard then |
| 11113 |
Guard_Open := |
| 11114 |
Make_Defining_Identifier (Loc, New_External_Name ('G', 1)); |
| 11115 |
|
| 11116 |
Append_To (Decls, |
| 11117 |
Make_Object_Declaration (Loc, |
| 11118 |
Defining_Identifier => Guard_Open, |
| 11119 |
Object_Definition => |
| 11120 |
New_Occurrence_Of (Standard_Boolean, Loc), |
| 11121 |
Expression => |
| 11122 |
New_Occurrence_Of (Standard_False, Loc))); |
| 11123 |
end if; |
| 11124 |
|
| 11125 |
-- Delay_Count is zero, don't need M and D set (suppress warning) |
| 11126 |
|
| 11127 |
else |
| 11128 |
M := Empty; |
| 11129 |
D := Empty; |
| 11130 |
end if; |
| 11131 |
|
| 11132 |
if Present (Terminate_Alt) then |
| 11133 |
|
| 11134 |
-- If the terminate alternative guard is False, use |
| 11135 |
-- Simple_Mode; otherwise use Terminate_Mode. |
| 11136 |
|
| 11137 |
if Present (Condition (Terminate_Alt)) then |
| 11138 |
Select_Mode := Make_If_Expression (Loc, |
| 11139 |
New_List (Condition (Terminate_Alt), |
| 11140 |
New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc), |
| 11141 |
New_Occurrence_Of (RTE (RE_Simple_Mode), Loc))); |
| 11142 |
else |
| 11143 |
Select_Mode := New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc); |
| 11144 |
end if; |
| 11145 |
|
| 11146 |
elsif Else_Present or Delay_Count > 0 then |
| 11147 |
Select_Mode := New_Occurrence_Of (RTE (RE_Else_Mode), Loc); |
| 11148 |
|
| 11149 |
else |
| 11150 |
Select_Mode := New_Occurrence_Of (RTE (RE_Simple_Mode), Loc); |
| 11151 |
end if; |
| 11152 |
|
| 11153 |
Select_Call := Make_Select_Call (Select_Mode); |
| 11154 |
Append (Select_Call, Stats); |
| 11155 |
|
| 11156 |
-- Now generate code to act on the result. There is an entry |
| 11157 |
-- in this case for each accept statement with a non-null body, |
| 11158 |
-- followed by a branch to the statements that follow the Accept. |
| 11159 |
-- In the absence of delay alternatives, we generate: |
| 11160 |
|
| 11161 |
-- case X is |
| 11162 |
-- when No_Rendezvous => -- omitted if simple mode |
| 11163 |
-- goto Lab0; |
| 11164 |
|
| 11165 |
-- when 1 => |
| 11166 |
-- P1n; |
| 11167 |
-- goto Lab1; |
| 11168 |
|
| 11169 |
-- when 2 => |
| 11170 |
-- P2n; |
| 11171 |
-- goto Lab2; |
| 11172 |
|
| 11173 |
-- when others => |
| 11174 |
-- goto Exit; |
| 11175 |
-- end case; |
| 11176 |
-- |
| 11177 |
-- Lab0: Else_Statements; |
| 11178 |
-- goto exit; |
| 11179 |
|
| 11180 |
-- Lab1: Trailing_Statements1; |
| 11181 |
-- goto Exit; |
| 11182 |
-- |
| 11183 |
-- Lab2: Trailing_Statements2; |
| 11184 |
-- goto Exit; |
| 11185 |
-- ... |
| 11186 |
-- Exit: |
| 11187 |
|
| 11188 |
-- Generate label for common exit |
| 11189 |
|
| 11190 |
End_Lab := Make_And_Declare_Label (Num_Alts + 1); |
| 11191 |
|
| 11192 |
-- First entry is the default case, when no rendezvous is possible |
| 11193 |
|
| 11194 |
Choices := New_List (New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)); |
| 11195 |
|
| 11196 |
if Else_Present then |
| 11197 |
|
| 11198 |
-- If no rendezvous is possible, the else part is executed |
| 11199 |
|
| 11200 |
Lab := Make_And_Declare_Label (0); |
| 11201 |
Alt_Stats := New_List ( |
| 11202 |
Make_Goto_Statement (Loc, |
| 11203 |
Name => New_Copy (Identifier (Lab)))); |
| 11204 |
|
| 11205 |
Append (Lab, Trailing_List); |
| 11206 |
Append_List (Else_Statements (N), Trailing_List); |
| 11207 |
Append_To (Trailing_List, |
| 11208 |
Make_Goto_Statement (Loc, |
| 11209 |
Name => New_Copy (Identifier (End_Lab)))); |
| 11210 |
else |
| 11211 |
Alt_Stats := New_List ( |
| 11212 |
Make_Goto_Statement (Loc, |
| 11213 |
Name => New_Copy (Identifier (End_Lab)))); |
| 11214 |
end if; |
| 11215 |
|
| 11216 |
Append_To (Alt_List, |
| 11217 |
Make_Case_Statement_Alternative (Loc, |
| 11218 |
Discrete_Choices => Choices, |
| 11219 |
Statements => Alt_Stats)); |
| 11220 |
|
| 11221 |
-- We make use of the fact that Accept_Index is an integer type, and |
| 11222 |
-- generate successive literals for entries for each accept. Only those |
| 11223 |
-- for which there is a body or trailing statements get a case entry. |
| 11224 |
|
| 11225 |
Alt := First (Select_Alternatives (N)); |
| 11226 |
Proc := First (Body_List); |
| 11227 |
while Present (Alt) loop |
| 11228 |
|
| 11229 |
if Nkind (Alt) = N_Accept_Alternative then |
| 11230 |
Process_Accept_Alternative (Alt, Index, Proc); |
| 11231 |
Index := Index + 1; |
| 11232 |
|
| 11233 |
if Present |
| 11234 |
(Handled_Statement_Sequence (Accept_Statement (Alt))) |
| 11235 |
then |
| 11236 |
Next (Proc); |
| 11237 |
end if; |
| 11238 |
|
| 11239 |
elsif Nkind (Alt) = N_Delay_Alternative then |
| 11240 |
Process_Delay_Alternative (Alt, Delay_Num); |
| 11241 |
Delay_Num := Delay_Num + 1; |
| 11242 |
end if; |
| 11243 |
|
| 11244 |
Next (Alt); |
| 11245 |
end loop; |
| 11246 |
|
| 11247 |
-- An others choice is always added to the main case, as well |
| 11248 |
-- as the delay case (to satisfy the compiler). |
| 11249 |
|
| 11250 |
Append_To (Alt_List, |
| 11251 |
Make_Case_Statement_Alternative (Loc, |
| 11252 |
Discrete_Choices => |
| 11253 |
New_List (Make_Others_Choice (Loc)), |
| 11254 |
Statements => |
| 11255 |
New_List (Make_Goto_Statement (Loc, |
| 11256 |
Name => New_Copy (Identifier (End_Lab)))))); |
| 11257 |
|
| 11258 |
Accept_Case := New_List ( |
| 11259 |
Make_Case_Statement (Loc, |
| 11260 |
Expression => New_Occurrence_Of (Xnam, Loc), |
| 11261 |
Alternatives => Alt_List)); |
| 11262 |
|
| 11263 |
Append_List (Trailing_List, Accept_Case); |
| 11264 |
Append_List (Body_List, Decls); |
| 11265 |
|
| 11266 |
-- Construct case statement for trailing statements of delay |
| 11267 |
-- alternatives, if there are several of them. |
| 11268 |
|
| 11269 |
if Delay_Count > 1 then |
| 11270 |
Append_To (Delay_Alt_List, |
| 11271 |
Make_Case_Statement_Alternative (Loc, |
| 11272 |
Discrete_Choices => |
| 11273 |
New_List (Make_Others_Choice (Loc)), |
| 11274 |
Statements => |
| 11275 |
New_List (Make_Null_Statement (Loc)))); |
| 11276 |
|
| 11277 |
Delay_Case := New_List ( |
| 11278 |
Make_Case_Statement (Loc, |
| 11279 |
Expression => New_Occurrence_Of (Delay_Index, Loc), |
| 11280 |
Alternatives => Delay_Alt_List)); |
| 11281 |
else |
| 11282 |
Delay_Case := Delay_Alt_List; |
| 11283 |
end if; |
| 11284 |
|
| 11285 |
-- If there are no delay alternatives, we append the case statement |
| 11286 |
-- to the statement list. |
| 11287 |
|
| 11288 |
if Delay_Count = 0 then |
| 11289 |
Append_List (Accept_Case, Stats); |
| 11290 |
|
| 11291 |
-- Delay alternatives present |
| 11292 |
|
| 11293 |
else |
| 11294 |
-- If delay alternatives are present we generate: |
| 11295 |
|
| 11296 |
-- find minimum delay. |
| 11297 |
-- DX := minimum delay; |
| 11298 |
-- M := <delay mode>; |
| 11299 |
-- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P, |
| 11300 |
-- DX, MX, X); |
| 11301 |
-- |
| 11302 |
-- if X = No_Rendezvous then |
| 11303 |
-- case statement for delay statements. |
| 11304 |
-- else |
| 11305 |
-- case statement for accept alternatives. |
| 11306 |
-- end if; |
| 11307 |
|
| 11308 |
declare |
| 11309 |
Cases : Node_Id; |
| 11310 |
Stmt : Node_Id; |
| 11311 |
Parms : List_Id; |
| 11312 |
Parm : Node_Id; |
| 11313 |
Conv : Node_Id; |
| 11314 |
|
| 11315 |
begin |
| 11316 |
-- The type of the delay expression is known to be legal |
| 11317 |
|
| 11318 |
if Time_Type = Standard_Duration then |
| 11319 |
Conv := New_Occurrence_Of (Delay_Min, Loc); |
| 11320 |
|
| 11321 |
elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then |
| 11322 |
Conv := Make_Function_Call (Loc, |
| 11323 |
New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc), |
| 11324 |
New_List (New_Occurrence_Of (Delay_Min, Loc))); |
| 11325 |
|
| 11326 |
else |
| 11327 |
pragma Assert |
| 11328 |
(Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)); |
| 11329 |
|
| 11330 |
Conv := Make_Function_Call (Loc, |
| 11331 |
New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc), |
| 11332 |
New_List (New_Occurrence_Of (Delay_Min, Loc))); |
| 11333 |
end if; |
| 11334 |
|
| 11335 |
Stmt := Make_Assignment_Statement (Loc, |
| 11336 |
Name => New_Occurrence_Of (D, Loc), |
| 11337 |
Expression => Conv); |
| 11338 |
|
| 11339 |
-- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode) |
| 11340 |
|
| 11341 |
Parms := Parameter_Associations (Select_Call); |
| 11342 |
|
| 11343 |
Parm := First (Parms); |
| 11344 |
while Present (Parm) and then Parm /= Select_Mode loop |
| 11345 |
Next (Parm); |
| 11346 |
end loop; |
| 11347 |
|
| 11348 |
pragma Assert (Present (Parm)); |
| 11349 |
Rewrite (Parm, New_Occurrence_Of (RTE (RE_Delay_Mode), Loc)); |
| 11350 |
Analyze (Parm); |
| 11351 |
|
| 11352 |
-- Prepare two new parameters of Duration and Delay_Mode type |
| 11353 |
-- which represent the value and the mode of the minimum delay. |
| 11354 |
|
| 11355 |
Next (Parm); |
| 11356 |
Insert_After (Parm, New_Occurrence_Of (M, Loc)); |
| 11357 |
Insert_After (Parm, New_Occurrence_Of (D, Loc)); |
| 11358 |
|
| 11359 |
-- Create a call to RTS |
| 11360 |
|
| 11361 |
Rewrite (Select_Call, |
| 11362 |
Make_Procedure_Call_Statement (Loc, |
| 11363 |
Name => New_Occurrence_Of (RTE (RE_Timed_Selective_Wait), Loc), |
| 11364 |
Parameter_Associations => Parms)); |
| 11365 |
|
| 11366 |
-- This new call should follow the calculation of the minimum |
| 11367 |
-- delay. |
| 11368 |
|
| 11369 |
Insert_List_Before (Select_Call, Delay_List); |
| 11370 |
|
| 11371 |
if Check_Guard then |
| 11372 |
Stmt := |
| 11373 |
Make_Implicit_If_Statement (N, |
| 11374 |
Condition => New_Occurrence_Of (Guard_Open, Loc), |
| 11375 |
Then_Statements => New_List ( |
| 11376 |
New_Copy_Tree (Stmt), |
| 11377 |
New_Copy_Tree (Select_Call)), |
| 11378 |
Else_Statements => Accept_Or_Raise); |
| 11379 |
Rewrite (Select_Call, Stmt); |
| 11380 |
else |
| 11381 |
Insert_Before (Select_Call, Stmt); |
| 11382 |
end if; |
| 11383 |
|
| 11384 |
Cases := |
| 11385 |
Make_Implicit_If_Statement (N, |
| 11386 |
Condition => Make_Op_Eq (Loc, |
| 11387 |
Left_Opnd => New_Occurrence_Of (Xnam, Loc), |
| 11388 |
Right_Opnd => |
| 11389 |
New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)), |
| 11390 |
|
| 11391 |
Then_Statements => Delay_Case, |
| 11392 |
Else_Statements => Accept_Case); |
| 11393 |
|
| 11394 |
Append (Cases, Stats); |
| 11395 |
end; |
| 11396 |
end if; |
| 11397 |
|
| 11398 |
Append (End_Lab, Stats); |
| 11399 |
|
| 11400 |
-- Replace accept statement with appropriate block |
| 11401 |
|
| 11402 |
Rewrite (N, |
| 11403 |
Make_Block_Statement (Loc, |
| 11404 |
Declarations => Decls, |
| 11405 |
Handled_Statement_Sequence => |
| 11406 |
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats))); |
| 11407 |
Analyze (N); |
| 11408 |
|
| 11409 |
-- Note: have to worry more about abort deferral in above code ??? |
| 11410 |
|
| 11411 |
-- Final step is to unstack the Accept_Address entries for all accept |
| 11412 |
-- statements appearing in accept alternatives in the select statement |
| 11413 |
|
| 11414 |
Alt := First (Alts); |
| 11415 |
while Present (Alt) loop |
| 11416 |
if Nkind (Alt) = N_Accept_Alternative then |
| 11417 |
Remove_Last_Elmt (Accept_Address |
| 11418 |
(Entity (Entry_Direct_Name (Accept_Statement (Alt))))); |
| 11419 |
end if; |
| 11420 |
|
| 11421 |
Next (Alt); |
| 11422 |
end loop; |
| 11423 |
end Expand_N_Selective_Accept; |
| 11424 |
|
| 11425 |
------------------------------------------- |
| 11426 |
-- Expand_N_Single_Protected_Declaration -- |
| 11427 |
------------------------------------------- |
| 11428 |
|
| 11429 |
-- A single protected declaration should never be present after semantic |
| 11430 |
-- analysis because it is transformed into a protected type declaration |
| 11431 |
-- and an accompanying anonymous object. This routine ensures that the |
| 11432 |
-- transformation takes place. |
| 11433 |
|
| 11434 |
procedure Expand_N_Single_Protected_Declaration (N : Node_Id) is |
| 11435 |
begin |
| 11436 |
raise Program_Error; |
| 11437 |
end Expand_N_Single_Protected_Declaration; |
| 11438 |
|
| 11439 |
-------------------------------------- |
| 11440 |
-- Expand_N_Single_Task_Declaration -- |
| 11441 |
-------------------------------------- |
| 11442 |
|
| 11443 |
-- A single task declaration should never be present after semantic |
| 11444 |
-- analysis because it is transformed into a task type declaration and |
| 11445 |
-- an accompanying anonymous object. This routine ensures that the |
| 11446 |
-- transformation takes place. |
| 11447 |
|
| 11448 |
procedure Expand_N_Single_Task_Declaration (N : Node_Id) is |
| 11449 |
begin |
| 11450 |
raise Program_Error; |
| 11451 |
end Expand_N_Single_Task_Declaration; |
| 11452 |
|
| 11453 |
------------------------ |
| 11454 |
-- Expand_N_Task_Body -- |
| 11455 |
------------------------ |
| 11456 |
|
| 11457 |
-- Given a task body |
| 11458 |
|
| 11459 |
-- task body tname is |
| 11460 |
-- <declarations> |
| 11461 |
-- begin |
| 11462 |
-- <statements> |
| 11463 |
-- end x; |
| 11464 |
|
| 11465 |
-- This expansion routine converts it into a procedure and sets the |
| 11466 |
-- elaboration flag for the procedure to true, to represent the fact |
| 11467 |
-- that the task body is now elaborated: |
| 11468 |
|
| 11469 |
-- procedure tnameB (_Task : access tnameV) is |
| 11470 |
-- discriminal : dtype renames _Task.discriminant; |
| 11471 |
|
| 11472 |
-- procedure _clean is |
| 11473 |
-- begin |
| 11474 |
-- Abort_Defer.all; |
| 11475 |
-- Complete_Task; |
| 11476 |
-- Abort_Undefer.all; |
| 11477 |
-- return; |
| 11478 |
-- end _clean; |
| 11479 |
|
| 11480 |
-- begin |
| 11481 |
-- Abort_Undefer.all; |
| 11482 |
-- <declarations> |
| 11483 |
-- System.Task_Stages.Complete_Activation; |
| 11484 |
-- <statements> |
| 11485 |
-- at end |
| 11486 |
-- _clean; |
| 11487 |
-- end tnameB; |
| 11488 |
|
| 11489 |
-- tnameE := True; |
| 11490 |
|
| 11491 |
-- In addition, if the task body is an activator, then a call to activate |
| 11492 |
-- tasks is added at the start of the statements, before the call to |
| 11493 |
-- Complete_Activation, and if in addition the task is a master then it |
| 11494 |
-- must be established as a master. These calls are inserted and analyzed |
| 11495 |
-- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is |
| 11496 |
-- expanded. |
| 11497 |
|
| 11498 |
-- There is one discriminal declaration line generated for each |
| 11499 |
-- discriminant that is present to provide an easy reference point for |
| 11500 |
-- discriminant references inside the body (see Exp_Ch2.Expand_Name). |
| 11501 |
|
| 11502 |
-- Note on relationship to GNARLI definition. In the GNARLI definition, |
| 11503 |
-- task body procedures have a profile (Arg : System.Address). That is |
| 11504 |
-- needed because GNARLI has to use the same access-to-subprogram type |
| 11505 |
-- for all task types. We depend here on knowing that in GNAT, passing |
| 11506 |
-- an address argument by value is identical to passing a record value |
| 11507 |
-- by access (in either case a single pointer is passed), so even though |
| 11508 |
-- this procedure has the wrong profile. In fact it's all OK, since the |
| 11509 |
-- callings sequence is identical. |
| 11510 |
|
| 11511 |
procedure Expand_N_Task_Body (N : Node_Id) is |
| 11512 |
Loc : constant Source_Ptr := Sloc (N); |
| 11513 |
Ttyp : constant Entity_Id := Corresponding_Spec (N); |
| 11514 |
Call : Node_Id; |
| 11515 |
New_N : Node_Id; |
| 11516 |
|
| 11517 |
Insert_Nod : Node_Id; |
| 11518 |
-- Used to determine the proper location of wrapper body insertions |
| 11519 |
|
| 11520 |
begin |
| 11521 |
-- if no task body procedure, means we had an error in configurable |
| 11522 |
-- run-time mode, and there is no point in proceeding further. |
| 11523 |
|
| 11524 |
if No (Task_Body_Procedure (Ttyp)) then |
| 11525 |
return; |
| 11526 |
end if; |
| 11527 |
|
| 11528 |
-- Add renaming declarations for discriminals and a declaration for the |
| 11529 |
-- entry family index (if applicable). |
| 11530 |
|
| 11531 |
Install_Private_Data_Declarations |
| 11532 |
(Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N)); |
| 11533 |
|
| 11534 |
-- Add a call to Abort_Undefer at the very beginning of the task |
| 11535 |
-- body since this body is called with abort still deferred. |
| 11536 |
|
| 11537 |
if Abort_Allowed then |
| 11538 |
Call := Build_Runtime_Call (Loc, RE_Abort_Undefer); |
| 11539 |
Prepend (Call, Declarations (N)); |
| 11540 |
Analyze (Call); |
| 11541 |
end if; |
| 11542 |
|
| 11543 |
-- Place call to Complete_Activation at the head of the statement list. |
| 11544 |
|
| 11545 |
if Restricted_Profile then |
| 11546 |
Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation); |
| 11547 |
else |
| 11548 |
Call := Build_Runtime_Call (Loc, RE_Complete_Activation); |
| 11549 |
end if; |
| 11550 |
|
| 11551 |
Insert_Before |
| 11552 |
(First (Statements (Handled_Statement_Sequence (N))), Call); |
| 11553 |
Analyze (Call); |
| 11554 |
|
| 11555 |
New_N := |
| 11556 |
Make_Subprogram_Body (Loc, |
| 11557 |
Specification => Build_Task_Proc_Specification (Ttyp), |
| 11558 |
Declarations => Declarations (N), |
| 11559 |
Handled_Statement_Sequence => Handled_Statement_Sequence (N)); |
| 11560 |
Set_Is_Task_Body_Procedure (New_N); |
| 11561 |
Set_At_End_Proc (New_N, At_End_Proc (N)); |
| 11562 |
|
| 11563 |
-- If the task contains generic instantiations, cleanup actions are |
| 11564 |
-- delayed until after instantiation. Transfer the activation chain to |
| 11565 |
-- the subprogram, to insure that the activation call is properly |
| 11566 |
-- generated. It the task body contains inner tasks, indicate that the |
| 11567 |
-- subprogram is a task master. |
| 11568 |
|
| 11569 |
if Delay_Cleanups (Ttyp) then |
| 11570 |
Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N)); |
| 11571 |
Set_Is_Task_Master (New_N, Is_Task_Master (N)); |
| 11572 |
end if; |
| 11573 |
|
| 11574 |
Rewrite (N, New_N); |
| 11575 |
Analyze (N); |
| 11576 |
|
| 11577 |
-- Set elaboration flag immediately after task body. If the body is a |
| 11578 |
-- subunit, the flag is set in the declarative part containing the stub. |
| 11579 |
|
| 11580 |
if Nkind (Parent (N)) /= N_Subunit then |
| 11581 |
Insert_After (N, |
| 11582 |
Make_Assignment_Statement (Loc, |
| 11583 |
Name => |
| 11584 |
Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')), |
| 11585 |
Expression => New_Occurrence_Of (Standard_True, Loc))); |
| 11586 |
end if; |
| 11587 |
|
| 11588 |
-- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after |
| 11589 |
-- the task body. At this point all wrapper specs have been created, |
| 11590 |
-- frozen and included in the dispatch table for the task type. |
| 11591 |
|
| 11592 |
if Ada_Version >= Ada_2005 then |
| 11593 |
if Nkind (Parent (N)) = N_Subunit then |
| 11594 |
Insert_Nod := Corresponding_Stub (Parent (N)); |
| 11595 |
else |
| 11596 |
Insert_Nod := N; |
| 11597 |
end if; |
| 11598 |
|
| 11599 |
Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod); |
| 11600 |
end if; |
| 11601 |
end Expand_N_Task_Body; |
| 11602 |
|
| 11603 |
------------------------------------ |
| 11604 |
-- Expand_N_Task_Type_Declaration -- |
| 11605 |
------------------------------------ |
| 11606 |
|
| 11607 |
-- We have several things to do. First we must create a Boolean flag used |
| 11608 |
-- to mark if the body is elaborated yet. This variable gets set to True |
| 11609 |
-- when the body of the task is elaborated (we can't rely on the normal |
| 11610 |
-- ABE mechanism for the task body, since we need to pass an access to |
| 11611 |
-- this elaboration boolean to the runtime routines). |
| 11612 |
|
| 11613 |
-- taskE : aliased Boolean := False; |
| 11614 |
|
| 11615 |
-- Next a variable is declared to hold the task stack size (either the |
| 11616 |
-- default : Unspecified_Size, or a value that is set by a pragma |
| 11617 |
-- Storage_Size). If the value of the pragma Storage_Size is static, then |
| 11618 |
-- the variable is initialized with this value: |
| 11619 |
|
| 11620 |
-- taskZ : Size_Type := Unspecified_Size; |
| 11621 |
-- or |
| 11622 |
-- taskZ : Size_Type := Size_Type (size_expression); |
| 11623 |
|
| 11624 |
-- Note: No variable is needed to hold the task relative deadline since |
| 11625 |
-- its value would never be static because the parameter is of a private |
| 11626 |
-- type (Ada.Real_Time.Time_Span). |
| 11627 |
|
| 11628 |
-- Next we create a corresponding record type declaration used to represent |
| 11629 |
-- values of this task. The general form of this type declaration is |
| 11630 |
|
| 11631 |
-- type taskV (discriminants) is record |
| 11632 |
-- _Task_Id : Task_Id; |
| 11633 |
-- entry_family : array (bounds) of Void; |
| 11634 |
-- _Priority : Integer := priority_expression; |
| 11635 |
-- _Size : Size_Type := size_expression; |
| 11636 |
-- _Secondary_Stack_Size : Size_Type := size_expression; |
| 11637 |
-- _Task_Info : Task_Info_Type := task_info_expression; |
| 11638 |
-- _CPU : Integer := cpu_range_expression; |
| 11639 |
-- _Relative_Deadline : Time_Span := time_span_expression; |
| 11640 |
-- _Domain : Dispatching_Domain := dd_expression; |
| 11641 |
-- end record; |
| 11642 |
|
| 11643 |
-- The discriminants are present only if the corresponding task type has |
| 11644 |
-- discriminants, and they exactly mirror the task type discriminants. |
| 11645 |
|
| 11646 |
-- The Id field is always present. It contains the Task_Id value, as set by |
| 11647 |
-- the call to Create_Task. Note that although the task is limited, the |
| 11648 |
-- task value record type is not limited, so there is no problem in passing |
| 11649 |
-- this field as an out parameter to Create_Task. |
| 11650 |
|
| 11651 |
-- One entry_family component is present for each entry family in the task |
| 11652 |
-- definition. The bounds correspond to the bounds of the entry family |
| 11653 |
-- (which may depend on discriminants). The element type is void, since we |
| 11654 |
-- only need the bounds information for determining the entry index. Note |
| 11655 |
-- that the use of an anonymous array would normally be illegal in this |
| 11656 |
-- context, but this is a parser check, and the semantics is quite prepared |
| 11657 |
-- to handle such a case. |
| 11658 |
|
| 11659 |
-- The _Size field is present only if a Storage_Size pragma appears in the |
| 11660 |
-- task definition. The expression captures the argument that was present |
| 11661 |
-- in the pragma, and is used to override the task stack size otherwise |
| 11662 |
-- associated with the task type. |
| 11663 |
|
| 11664 |
-- The _Secondary_Stack_Size field is present only the task entity has a |
| 11665 |
-- Secondary_Stack_Size rep item. It will be filled at the freeze point, |
| 11666 |
-- when the record init proc is built, to capture the expression of the |
| 11667 |
-- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot |
| 11668 |
-- be filled here since aspect evaluations are delayed till the freeze |
| 11669 |
-- point. |
| 11670 |
|
| 11671 |
-- The _Priority field is present only if the task entity has a Priority or |
| 11672 |
-- Interrupt_Priority rep item (pragma, aspect specification or attribute |
| 11673 |
-- definition clause). It will be filled at the freeze point, when the |
| 11674 |
-- record init proc is built, to capture the expression of the rep item |
| 11675 |
-- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled |
| 11676 |
-- here since aspect evaluations are delayed till the freeze point. |
| 11677 |
|
| 11678 |
-- The _Task_Info field is present only if a Task_Info pragma appears in |
| 11679 |
-- the task definition. The expression captures the argument that was |
| 11680 |
-- present in the pragma, and is used to provide the Task_Image parameter |
| 11681 |
-- to the call to Create_Task. |
| 11682 |
|
| 11683 |
-- The _CPU field is present only if the task entity has a CPU rep item |
| 11684 |
-- (pragma, aspect specification or attribute definition clause). It will |
| 11685 |
-- be filled at the freeze point, when the record init proc is built, to |
| 11686 |
-- capture the expression of the rep item (see Build_Record_Init_Proc in |
| 11687 |
-- Exp_Ch3). Note that it cannot be filled here since aspect evaluations |
| 11688 |
-- are delayed till the freeze point. |
| 11689 |
|
| 11690 |
-- The _Relative_Deadline field is present only if a Relative_Deadline |
| 11691 |
-- pragma appears in the task definition. The expression captures the |
| 11692 |
-- argument that was present in the pragma, and is used to provide the |
| 11693 |
-- Relative_Deadline parameter to the call to Create_Task. |
| 11694 |
|
| 11695 |
-- The _Domain field is present only if the task entity has a |
| 11696 |
-- Dispatching_Domain rep item (pragma, aspect specification or attribute |
| 11697 |
-- definition clause). It will be filled at the freeze point, when the |
| 11698 |
-- record init proc is built, to capture the expression of the rep item |
| 11699 |
-- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled |
| 11700 |
-- here since aspect evaluations are delayed till the freeze point. |
| 11701 |
|
| 11702 |
-- When a task is declared, an instance of the task value record is |
| 11703 |
-- created. The elaboration of this declaration creates the correct bounds |
| 11704 |
-- for the entry families, and also evaluates the size, priority, and |
| 11705 |
-- task_Info expressions if needed. The initialization routine for the task |
| 11706 |
-- type itself then calls Create_Task with appropriate parameters to |
| 11707 |
-- initialize the value of the Task_Id field. |
| 11708 |
|
| 11709 |
-- Note: the address of this record is passed as the "Discriminants" |
| 11710 |
-- parameter for Create_Task. Since Create_Task merely passes this onto the |
| 11711 |
-- body procedure, it does not matter that it does not quite match the |
| 11712 |
-- GNARLI model of what is being passed (the record contains more than just |
| 11713 |
-- the discriminants, but the discriminants can be found from the record |
| 11714 |
-- value). |
| 11715 |
|
| 11716 |
-- The Entity_Id for this created record type is placed in the |
| 11717 |
-- Corresponding_Record_Type field of the associated task type entity. |
| 11718 |
|
| 11719 |
-- Next we create a procedure specification for the task body procedure: |
| 11720 |
|
| 11721 |
-- procedure taskB (_Task : access taskV); |
| 11722 |
|
| 11723 |
-- Note that this must come after the record type declaration, since |
| 11724 |
-- the spec refers to this type. It turns out that the initialization |
| 11725 |
-- procedure for the value type references the task body spec, but that's |
| 11726 |
-- fine, since it won't be generated till the freeze point for the type, |
| 11727 |
-- which is certainly after the task body spec declaration. |
| 11728 |
|
| 11729 |
-- Finally, we set the task index value field of the entry attribute in |
| 11730 |
-- the case of a simple entry. |
| 11731 |
|
| 11732 |
procedure Expand_N_Task_Type_Declaration (N : Node_Id) is |
| 11733 |
Loc : constant Source_Ptr := Sloc (N); |
| 11734 |
TaskId : constant Entity_Id := Defining_Identifier (N); |
| 11735 |
Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N)); |
| 11736 |
Tasknm : constant Name_Id := Chars (Tasktyp); |
| 11737 |
Taskdef : constant Node_Id := Task_Definition (N); |
| 11738 |
|
| 11739 |
Body_Decl : Node_Id; |
| 11740 |
Cdecls : List_Id; |
| 11741 |
Decl_Stack : Node_Id; |
| 11742 |
Decl_SS : Node_Id; |
| 11743 |
Elab_Decl : Node_Id; |
| 11744 |
Ent_Stack : Entity_Id; |
| 11745 |
Proc_Spec : Node_Id; |
| 11746 |
Rec_Decl : Node_Id; |
| 11747 |
Rec_Ent : Entity_Id; |
| 11748 |
Size_Decl : Entity_Id; |
| 11749 |
Task_Size : Node_Id; |
| 11750 |
|
| 11751 |
function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id; |
| 11752 |
-- Searches the task definition T for the first occurrence of the pragma |
| 11753 |
-- Relative Deadline. The caller has ensured that the pragma is present |
| 11754 |
-- in the task definition. Note that this routine cannot be implemented |
| 11755 |
-- with the Rep Item chain mechanism since Relative_Deadline pragmas are |
| 11756 |
-- not chained because their expansion into a procedure call statement |
| 11757 |
-- would cause a break in the chain. |
| 11758 |
|
| 11759 |
---------------------------------- |
| 11760 |
-- Get_Relative_Deadline_Pragma -- |
| 11761 |
---------------------------------- |
| 11762 |
|
| 11763 |
function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id is |
| 11764 |
N : Node_Id; |
| 11765 |
|
| 11766 |
begin |
| 11767 |
N := First (Visible_Declarations (T)); |
| 11768 |
while Present (N) loop |
| 11769 |
if Nkind (N) = N_Pragma |
| 11770 |
and then Pragma_Name (N) = Name_Relative_Deadline |
| 11771 |
then |
| 11772 |
return N; |
| 11773 |
end if; |
| 11774 |
|
| 11775 |
Next (N); |
| 11776 |
end loop; |
| 11777 |
|
| 11778 |
N := First (Private_Declarations (T)); |
| 11779 |
while Present (N) loop |
| 11780 |
if Nkind (N) = N_Pragma |
| 11781 |
and then Pragma_Name (N) = Name_Relative_Deadline |
| 11782 |
then |
| 11783 |
return N; |
| 11784 |
end if; |
| 11785 |
|
| 11786 |
Next (N); |
| 11787 |
end loop; |
| 11788 |
|
| 11789 |
raise Program_Error; |
| 11790 |
end Get_Relative_Deadline_Pragma; |
| 11791 |
|
| 11792 |
-- Start of processing for Expand_N_Task_Type_Declaration |
| 11793 |
|
| 11794 |
begin |
| 11795 |
-- If already expanded, nothing to do |
| 11796 |
|
| 11797 |
if Present (Corresponding_Record_Type (Tasktyp)) then |
| 11798 |
return; |
| 11799 |
end if; |
| 11800 |
|
| 11801 |
-- Here we will do the expansion |
| 11802 |
|
| 11803 |
Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc); |
| 11804 |
|
| 11805 |
Rec_Ent := Defining_Identifier (Rec_Decl); |
| 11806 |
Cdecls := Component_Items (Component_List |
| 11807 |
(Type_Definition (Rec_Decl))); |
| 11808 |
|
| 11809 |
Qualify_Entity_Names (N); |
| 11810 |
|
| 11811 |
-- First create the elaboration variable |
| 11812 |
|
| 11813 |
Elab_Decl := |
| 11814 |
Make_Object_Declaration (Loc, |
| 11815 |
Defining_Identifier => |
| 11816 |
Make_Defining_Identifier (Sloc (Tasktyp), |
| 11817 |
Chars => New_External_Name (Tasknm, 'E')), |
| 11818 |
Aliased_Present => True, |
| 11819 |
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc), |
| 11820 |
Expression => New_Occurrence_Of (Standard_False, Loc)); |
| 11821 |
|
| 11822 |
Insert_After (N, Elab_Decl); |
| 11823 |
|
| 11824 |
-- Next create the declaration of the size variable (tasknmZ) |
| 11825 |
|
| 11826 |
Set_Storage_Size_Variable (Tasktyp, |
| 11827 |
Make_Defining_Identifier (Sloc (Tasktyp), |
| 11828 |
Chars => New_External_Name (Tasknm, 'Z'))); |
| 11829 |
|
| 11830 |
if Present (Taskdef) |
| 11831 |
and then Has_Storage_Size_Pragma (Taskdef) |
| 11832 |
and then |
| 11833 |
Is_OK_Static_Expression |
| 11834 |
(Expression |
| 11835 |
(First (Pragma_Argument_Associations |
| 11836 |
(Get_Rep_Pragma (TaskId, Name_Storage_Size))))) |
| 11837 |
then |
| 11838 |
Size_Decl := |
| 11839 |
Make_Object_Declaration (Loc, |
| 11840 |
Defining_Identifier => Storage_Size_Variable (Tasktyp), |
| 11841 |
Object_Definition => |
| 11842 |
New_Occurrence_Of (RTE (RE_Size_Type), Loc), |
| 11843 |
Expression => |
| 11844 |
Convert_To (RTE (RE_Size_Type), |
| 11845 |
Relocate_Node |
| 11846 |
(Expression (First (Pragma_Argument_Associations |
| 11847 |
(Get_Rep_Pragma |
| 11848 |
(TaskId, Name_Storage_Size))))))); |
| 11849 |
|
| 11850 |
else |
| 11851 |
Size_Decl := |
| 11852 |
Make_Object_Declaration (Loc, |
| 11853 |
Defining_Identifier => Storage_Size_Variable (Tasktyp), |
| 11854 |
Object_Definition => |
| 11855 |
New_Occurrence_Of (RTE (RE_Size_Type), Loc), |
| 11856 |
Expression => |
| 11857 |
New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc)); |
| 11858 |
end if; |
| 11859 |
|
| 11860 |
Insert_After (Elab_Decl, Size_Decl); |
| 11861 |
|
| 11862 |
-- Next build the rest of the corresponding record declaration. This is |
| 11863 |
-- done last, since the corresponding record initialization procedure |
| 11864 |
-- will reference the previously created entities. |
| 11865 |
|
| 11866 |
-- Fill in the component declarations -- first the _Task_Id field |
| 11867 |
|
| 11868 |
Append_To (Cdecls, |
| 11869 |
Make_Component_Declaration (Loc, |
| 11870 |
Defining_Identifier => |
| 11871 |
Make_Defining_Identifier (Loc, Name_uTask_Id), |
| 11872 |
Component_Definition => |
| 11873 |
Make_Component_Definition (Loc, |
| 11874 |
Subtype_Indication => New_Occurrence_Of (RTE (RO_ST_Task_Id), |
| 11875 |
Loc)))); |
| 11876 |
|
| 11877 |
-- Declare static ATCB (that is, created by the expander) if we are |
| 11878 |
-- using the Restricted run time. |
| 11879 |
|
| 11880 |
if Restricted_Profile then |
| 11881 |
Append_To (Cdecls, |
| 11882 |
Make_Component_Declaration (Loc, |
| 11883 |
Defining_Identifier => |
| 11884 |
Make_Defining_Identifier (Loc, Name_uATCB), |
| 11885 |
|
| 11886 |
Component_Definition => |
| 11887 |
Make_Component_Definition (Loc, |
| 11888 |
Aliased_Present => True, |
| 11889 |
Subtype_Indication => Make_Subtype_Indication (Loc, |
| 11890 |
Subtype_Mark => |
| 11891 |
New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc), |
| 11892 |
|
| 11893 |
Constraint => |
| 11894 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 11895 |
Constraints => |
| 11896 |
New_List (Make_Integer_Literal (Loc, 0))))))); |
| 11897 |
|
| 11898 |
end if; |
| 11899 |
|
| 11900 |
-- Declare static stack (that is, created by the expander) if we are |
| 11901 |
-- using the Restricted run time on a bare board configuration. |
| 11902 |
|
| 11903 |
if Restricted_Profile and then Preallocated_Stacks_On_Target then |
| 11904 |
|
| 11905 |
-- First we need to extract the appropriate stack size |
| 11906 |
|
| 11907 |
Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack); |
| 11908 |
|
| 11909 |
if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then |
| 11910 |
declare |
| 11911 |
Expr_N : constant Node_Id := |
| 11912 |
Expression (First ( |
| 11913 |
Pragma_Argument_Associations ( |
| 11914 |
Get_Rep_Pragma (TaskId, Name_Storage_Size)))); |
| 11915 |
Etyp : constant Entity_Id := Etype (Expr_N); |
| 11916 |
P : constant Node_Id := Parent (Expr_N); |
| 11917 |
|
| 11918 |
begin |
| 11919 |
-- The stack is defined inside the corresponding record. |
| 11920 |
-- Therefore if the size of the stack is set by means of |
| 11921 |
-- a discriminant, we must reference the discriminant of the |
| 11922 |
-- corresponding record type. |
| 11923 |
|
| 11924 |
if Nkind (Expr_N) in N_Has_Entity |
| 11925 |
and then Present (Discriminal_Link (Entity (Expr_N))) |
| 11926 |
then |
| 11927 |
Task_Size := |
| 11928 |
New_Occurrence_Of |
| 11929 |
(CR_Discriminant (Discriminal_Link (Entity (Expr_N))), |
| 11930 |
Loc); |
| 11931 |
Set_Parent (Task_Size, P); |
| 11932 |
Set_Etype (Task_Size, Etyp); |
| 11933 |
Set_Analyzed (Task_Size); |
| 11934 |
|
| 11935 |
else |
| 11936 |
Task_Size := New_Copy_Tree (Expr_N); |
| 11937 |
end if; |
| 11938 |
|
| 11939 |
-- On targets with a preallocated task stack the minimum stack |
| 11940 |
-- size is defined in System.Parameters. Since we do not have |
| 11941 |
-- access to the value of that definition here we replace the |
| 11942 |
-- static task size with the static expression |
| 11943 |
-- Size_Type'Max (Task_Size, Minimum_Stack_Size). |
| 11944 |
-- The compiler will evaluate this expression and replace the |
| 11945 |
-- task size with the Minimum_Stack_Size if needed. It is |
| 11946 |
-- important for this expression to be static to avoid |
| 11947 |
-- introducing implicit heap allocations that would break code |
| 11948 |
-- with the No_Implicit_Heap_Allocations restriction. |
| 11949 |
-- On some runtimes the allocation of the minimum stack size is |
| 11950 |
-- ensured by a call to Adjust_Storage_Size. We cannot use this |
| 11951 |
-- function here as it is not static and evaluated at runtime. |
| 11952 |
-- Note: This expression may not appear in the expanded code |
| 11953 |
-- as the compiler evaluates this expression before code |
| 11954 |
-- generation. |
| 11955 |
|
| 11956 |
Task_Size := |
| 11957 |
Convert_To |
| 11958 |
(RTE (RE_Storage_Offset), |
| 11959 |
Make_Attribute_Reference (Loc, |
| 11960 |
Attribute_Name => Name_Max, |
| 11961 |
Prefix => |
| 11962 |
New_Occurrence_Of |
| 11963 |
(RTE (RE_Size_Type), Loc), Expressions => New_List ( |
| 11964 |
Convert_To (RTE (RE_Size_Type), Task_Size), |
| 11965 |
New_Occurrence_Of (RTE (RE_Minimum_Stack_Size), |
| 11966 |
Loc)))); |
| 11967 |
end; |
| 11968 |
|
| 11969 |
else |
| 11970 |
Task_Size := |
| 11971 |
New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc); |
| 11972 |
end if; |
| 11973 |
|
| 11974 |
Decl_Stack := Make_Component_Declaration (Loc, |
| 11975 |
Defining_Identifier => Ent_Stack, |
| 11976 |
|
| 11977 |
Component_Definition => |
| 11978 |
Make_Component_Definition (Loc, |
| 11979 |
Aliased_Present => True, |
| 11980 |
Subtype_Indication => Make_Subtype_Indication (Loc, |
| 11981 |
Subtype_Mark => |
| 11982 |
New_Occurrence_Of (RTE (RE_Storage_Array), Loc), |
| 11983 |
|
| 11984 |
Constraint => |
| 11985 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 11986 |
Constraints => New_List (Make_Range (Loc, |
| 11987 |
Low_Bound => Make_Integer_Literal (Loc, 1), |
| 11988 |
High_Bound => Convert_To (RTE (RE_Storage_Offset), |
| 11989 |
Task_Size))))))); |
| 11990 |
|
| 11991 |
Append_To (Cdecls, Decl_Stack); |
| 11992 |
|
| 11993 |
-- The appropriate alignment for the stack is ensured by the run-time |
| 11994 |
-- code in charge of task creation. |
| 11995 |
|
| 11996 |
end if; |
| 11997 |
|
| 11998 |
-- Declare a static secondary stack if the conditions for a statically |
| 11999 |
-- generated stack are met. |
| 12000 |
|
| 12001 |
if Create_Secondary_Stack_For_Task (TaskId) then |
| 12002 |
declare |
| 12003 |
Size_Expr : constant Node_Id := |
| 12004 |
Expression (First ( |
| 12005 |
Pragma_Argument_Associations ( |
| 12006 |
Get_Rep_Pragma (TaskId, |
| 12007 |
Name_Secondary_Stack_Size)))); |
| 12008 |
|
| 12009 |
Stack_Size : Node_Id; |
| 12010 |
|
| 12011 |
begin |
| 12012 |
-- The secondary stack is defined inside the corresponding |
| 12013 |
-- record. Therefore if the size of the stack is set by means |
| 12014 |
-- of a discriminant, we must reference the discriminant of the |
| 12015 |
-- corresponding record type. |
| 12016 |
|
| 12017 |
if Nkind (Size_Expr) in N_Has_Entity |
| 12018 |
and then Present (Discriminal_Link (Entity (Size_Expr))) |
| 12019 |
then |
| 12020 |
Stack_Size := |
| 12021 |
New_Occurrence_Of |
| 12022 |
(CR_Discriminant (Discriminal_Link (Entity (Size_Expr))), |
| 12023 |
Loc); |
| 12024 |
Set_Parent (Stack_Size, Parent (Size_Expr)); |
| 12025 |
Set_Etype (Stack_Size, Etype (Size_Expr)); |
| 12026 |
Set_Analyzed (Stack_Size); |
| 12027 |
|
| 12028 |
else |
| 12029 |
Stack_Size := New_Copy_Tree (Size_Expr); |
| 12030 |
end if; |
| 12031 |
|
| 12032 |
-- Create the secondary stack for the task |
| 12033 |
|
| 12034 |
Decl_SS := |
| 12035 |
Make_Component_Declaration (Loc, |
| 12036 |
Defining_Identifier => |
| 12037 |
Make_Defining_Identifier (Loc, Name_uSecondary_Stack), |
| 12038 |
Component_Definition => |
| 12039 |
Make_Component_Definition (Loc, |
| 12040 |
Aliased_Present => True, |
| 12041 |
Subtype_Indication => |
| 12042 |
Make_Subtype_Indication (Loc, |
| 12043 |
Subtype_Mark => |
| 12044 |
New_Occurrence_Of (RTE (RE_SS_Stack), Loc), |
| 12045 |
Constraint => |
| 12046 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 12047 |
Constraints => New_List ( |
| 12048 |
Convert_To (RTE (RE_Size_Type), |
| 12049 |
Stack_Size)))))); |
| 12050 |
|
| 12051 |
Append_To (Cdecls, Decl_SS); |
| 12052 |
end; |
| 12053 |
end if; |
| 12054 |
|
| 12055 |
-- Add components for entry families |
| 12056 |
|
| 12057 |
Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp); |
| 12058 |
|
| 12059 |
-- Add the _Priority component if a Interrupt_Priority or Priority rep |
| 12060 |
-- item is present. |
| 12061 |
|
| 12062 |
if Has_Rep_Item (TaskId, Name_Priority, Check_Parents => False) then |
| 12063 |
Append_To (Cdecls, |
| 12064 |
Make_Component_Declaration (Loc, |
| 12065 |
Defining_Identifier => |
| 12066 |
Make_Defining_Identifier (Loc, Name_uPriority), |
| 12067 |
Component_Definition => |
| 12068 |
Make_Component_Definition (Loc, |
| 12069 |
Subtype_Indication => |
| 12070 |
New_Occurrence_Of (Standard_Integer, Loc)))); |
| 12071 |
end if; |
| 12072 |
|
| 12073 |
-- Add the _Size component if a Storage_Size pragma is present |
| 12074 |
|
| 12075 |
if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then |
| 12076 |
Append_To (Cdecls, |
| 12077 |
Make_Component_Declaration (Loc, |
| 12078 |
Defining_Identifier => |
| 12079 |
Make_Defining_Identifier (Loc, Name_uSize), |
| 12080 |
|
| 12081 |
Component_Definition => |
| 12082 |
Make_Component_Definition (Loc, |
| 12083 |
Subtype_Indication => |
| 12084 |
New_Occurrence_Of (RTE (RE_Size_Type), Loc)), |
| 12085 |
|
| 12086 |
Expression => |
| 12087 |
Convert_To (RTE (RE_Size_Type), |
| 12088 |
New_Copy_Tree ( |
| 12089 |
Expression (First ( |
| 12090 |
Pragma_Argument_Associations ( |
| 12091 |
Get_Rep_Pragma (TaskId, Name_Storage_Size)))))))); |
| 12092 |
end if; |
| 12093 |
|
| 12094 |
-- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size |
| 12095 |
-- pragma is present. |
| 12096 |
|
| 12097 |
if Has_Rep_Pragma |
| 12098 |
(TaskId, Name_Secondary_Stack_Size, Check_Parents => False) |
| 12099 |
then |
| 12100 |
Append_To (Cdecls, |
| 12101 |
Make_Component_Declaration (Loc, |
| 12102 |
Defining_Identifier => |
| 12103 |
Make_Defining_Identifier (Loc, Name_uSecondary_Stack_Size), |
| 12104 |
|
| 12105 |
Component_Definition => |
| 12106 |
Make_Component_Definition (Loc, |
| 12107 |
Subtype_Indication => |
| 12108 |
New_Occurrence_Of (RTE (RE_Size_Type), Loc)))); |
| 12109 |
end if; |
| 12110 |
|
| 12111 |
-- Add the _Task_Info component if a Task_Info pragma is present |
| 12112 |
|
| 12113 |
if Has_Rep_Pragma (TaskId, Name_Task_Info, Check_Parents => False) then |
| 12114 |
Append_To (Cdecls, |
| 12115 |
Make_Component_Declaration (Loc, |
| 12116 |
Defining_Identifier => |
| 12117 |
Make_Defining_Identifier (Loc, Name_uTask_Info), |
| 12118 |
|
| 12119 |
Component_Definition => |
| 12120 |
Make_Component_Definition (Loc, |
| 12121 |
Subtype_Indication => |
| 12122 |
New_Occurrence_Of (RTE (RE_Task_Info_Type), Loc)), |
| 12123 |
|
| 12124 |
Expression => New_Copy ( |
| 12125 |
Expression (First ( |
| 12126 |
Pragma_Argument_Associations ( |
| 12127 |
Get_Rep_Pragma |
| 12128 |
(TaskId, Name_Task_Info, Check_Parents => False))))))); |
| 12129 |
end if; |
| 12130 |
|
| 12131 |
-- Add the _CPU component if a CPU rep item is present |
| 12132 |
|
| 12133 |
if Has_Rep_Item (TaskId, Name_CPU, Check_Parents => False) then |
| 12134 |
Append_To (Cdecls, |
| 12135 |
Make_Component_Declaration (Loc, |
| 12136 |
Defining_Identifier => |
| 12137 |
Make_Defining_Identifier (Loc, Name_uCPU), |
| 12138 |
|
| 12139 |
Component_Definition => |
| 12140 |
Make_Component_Definition (Loc, |
| 12141 |
Subtype_Indication => |
| 12142 |
New_Occurrence_Of (RTE (RE_CPU_Range), Loc)))); |
| 12143 |
end if; |
| 12144 |
|
| 12145 |
-- Add the _Relative_Deadline component if a Relative_Deadline pragma is |
| 12146 |
-- present. If we are using a restricted run time this component will |
| 12147 |
-- not be added (deadlines are not allowed by the Ravenscar profile), |
| 12148 |
-- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF |
| 12149 |
-- profile). |
| 12150 |
|
| 12151 |
if (not Restricted_Profile or else Task_Dispatching_Policy = 'E') |
| 12152 |
and then Present (Taskdef) |
| 12153 |
and then Has_Relative_Deadline_Pragma (Taskdef) |
| 12154 |
then |
| 12155 |
Append_To (Cdecls, |
| 12156 |
Make_Component_Declaration (Loc, |
| 12157 |
Defining_Identifier => |
| 12158 |
Make_Defining_Identifier (Loc, Name_uRelative_Deadline), |
| 12159 |
|
| 12160 |
Component_Definition => |
| 12161 |
Make_Component_Definition (Loc, |
| 12162 |
Subtype_Indication => |
| 12163 |
New_Occurrence_Of (RTE (RE_Time_Span), Loc)), |
| 12164 |
|
| 12165 |
Expression => |
| 12166 |
Convert_To (RTE (RE_Time_Span), |
| 12167 |
New_Copy_Tree ( |
| 12168 |
Expression (First ( |
| 12169 |
Pragma_Argument_Associations ( |
| 12170 |
Get_Relative_Deadline_Pragma (Taskdef)))))))); |
| 12171 |
end if; |
| 12172 |
|
| 12173 |
-- Add the _Dispatching_Domain component if a Dispatching_Domain rep |
| 12174 |
-- item is present. If we are using a restricted run time this component |
| 12175 |
-- will not be added (dispatching domains are not allowed by the |
| 12176 |
-- Ravenscar profile). |
| 12177 |
|
| 12178 |
if not Restricted_Profile |
| 12179 |
and then |
| 12180 |
Has_Rep_Item |
| 12181 |
(TaskId, Name_Dispatching_Domain, Check_Parents => False) |
| 12182 |
then |
| 12183 |
Append_To (Cdecls, |
| 12184 |
Make_Component_Declaration (Loc, |
| 12185 |
Defining_Identifier => |
| 12186 |
Make_Defining_Identifier (Loc, Name_uDispatching_Domain), |
| 12187 |
|
| 12188 |
Component_Definition => |
| 12189 |
Make_Component_Definition (Loc, |
| 12190 |
Subtype_Indication => |
| 12191 |
New_Occurrence_Of |
| 12192 |
(RTE (RE_Dispatching_Domain_Access), Loc)))); |
| 12193 |
end if; |
| 12194 |
|
| 12195 |
Insert_After (Size_Decl, Rec_Decl); |
| 12196 |
|
| 12197 |
-- Analyze the record declaration immediately after construction, |
| 12198 |
-- because the initialization procedure is needed for single task |
| 12199 |
-- declarations before the next entity is analyzed. |
| 12200 |
|
| 12201 |
Analyze (Rec_Decl); |
| 12202 |
|
| 12203 |
-- Analyze aspects of the corresponding record type. They may have been |
| 12204 |
-- propagated to it and its analysis is required to add the pragma (see |
| 12205 |
-- propagation of aspect First_Controlling_Parameter in the subprogram |
| 12206 |
-- Build_Corresponding_Record). |
| 12207 |
|
| 12208 |
if Has_Aspects (Rec_Decl) then |
| 12209 |
Analyze_Aspect_Specifications (Rec_Decl, Rec_Ent); |
| 12210 |
|
| 12211 |
-- Handle aspects that may have been implicitly inherited and must be |
| 12212 |
-- explicitly propagated to the corresponding record type. This applies |
| 12213 |
-- specifically when the First_Controlling_Parameter aspect has been |
| 12214 |
-- implicitly inherited from an implemented interface. |
| 12215 |
|
| 12216 |
elsif Present (Interface_List (Parent (Tasktyp))) |
| 12217 |
and then Has_First_Controlling_Parameter_Aspect (Tasktyp) |
| 12218 |
then |
| 12219 |
Set_Has_First_Controlling_Parameter_Aspect (Rec_Ent); |
| 12220 |
end if; |
| 12221 |
|
| 12222 |
-- Create the declaration of the task body procedure |
| 12223 |
|
| 12224 |
Proc_Spec := Build_Task_Proc_Specification (Tasktyp); |
| 12225 |
Body_Decl := |
| 12226 |
Make_Subprogram_Declaration (Loc, |
| 12227 |
Specification => Proc_Spec); |
| 12228 |
Set_Is_Task_Body_Procedure (Body_Decl); |
| 12229 |
|
| 12230 |
Insert_After (Rec_Decl, Body_Decl); |
| 12231 |
|
| 12232 |
-- The subprogram does not comes from source, so we have to indicate the |
| 12233 |
-- need for debugging information explicitly. |
| 12234 |
|
| 12235 |
if Comes_From_Source (Original_Node (N)) then |
| 12236 |
Set_Debug_Info_Needed (Defining_Entity (Proc_Spec)); |
| 12237 |
end if; |
| 12238 |
|
| 12239 |
-- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before |
| 12240 |
-- the corresponding record has been frozen. |
| 12241 |
|
| 12242 |
if Ada_Version >= Ada_2005 then |
| 12243 |
Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl); |
| 12244 |
end if; |
| 12245 |
|
| 12246 |
-- Ada 2005 (AI-345): We must defer freezing to allow further |
| 12247 |
-- declaration of primitive subprograms covering task interfaces |
| 12248 |
|
| 12249 |
if Ada_Version <= Ada_95 then |
| 12250 |
|
| 12251 |
-- Now we can freeze the corresponding record. This needs manually |
| 12252 |
-- freezing, since it is really part of the task type, and the task |
| 12253 |
-- type is frozen at this stage. We of course need the initialization |
| 12254 |
-- procedure for this corresponding record type and we won't get it |
| 12255 |
-- in time if we don't freeze now. |
| 12256 |
|
| 12257 |
Insert_List_After (Body_Decl, List => Freeze_Entity (Rec_Ent, N)); |
| 12258 |
end if; |
| 12259 |
|
| 12260 |
-- Complete the expansion of access types to the current task type, if |
| 12261 |
-- any were declared. |
| 12262 |
|
| 12263 |
Expand_Previous_Access_Type (Tasktyp); |
| 12264 |
|
| 12265 |
-- Create wrappers for entries that have contract cases, preconditions |
| 12266 |
-- and postconditions. |
| 12267 |
|
| 12268 |
declare |
| 12269 |
Ent : Entity_Id; |
| 12270 |
|
| 12271 |
begin |
| 12272 |
Ent := First_Entity (Tasktyp); |
| 12273 |
while Present (Ent) loop |
| 12274 |
if Ekind (Ent) in E_Entry | E_Entry_Family then |
| 12275 |
Build_Entry_Contract_Wrapper (Ent, N); |
| 12276 |
end if; |
| 12277 |
|
| 12278 |
Next_Entity (Ent); |
| 12279 |
end loop; |
| 12280 |
end; |
| 12281 |
end Expand_N_Task_Type_Declaration; |
| 12282 |
|
| 12283 |
------------------------------- |
| 12284 |
-- Expand_N_Timed_Entry_Call -- |
| 12285 |
------------------------------- |
| 12286 |
|
| 12287 |
-- A timed entry call in normal case is not implemented using ATC mechanism |
| 12288 |
-- anymore for efficiency reason. |
| 12289 |
|
| 12290 |
-- select |
| 12291 |
-- T.E; |
| 12292 |
-- S1; |
| 12293 |
-- or |
| 12294 |
-- delay D; |
| 12295 |
-- S2; |
| 12296 |
-- end select; |
| 12297 |
|
| 12298 |
-- is expanded as follows: |
| 12299 |
|
| 12300 |
-- 1) When T.E is a task entry_call; |
| 12301 |
|
| 12302 |
-- declare |
| 12303 |
-- B : Boolean; |
| 12304 |
-- X : Task_Entry_Index := <entry index>; |
| 12305 |
-- DX : Duration := To_Duration (D); |
| 12306 |
-- M : Delay_Mode := <discriminant>; |
| 12307 |
-- P : parms := (parm, parm, parm); |
| 12308 |
|
| 12309 |
-- begin |
| 12310 |
-- Timed_Protected_Entry_Call |
| 12311 |
-- (<acceptor-task>, X, P'Address, DX, M, B); |
| 12312 |
-- if B then |
| 12313 |
-- S1; |
| 12314 |
-- else |
| 12315 |
-- S2; |
| 12316 |
-- end if; |
| 12317 |
-- end; |
| 12318 |
|
| 12319 |
-- 2) When T.E is a protected entry_call; |
| 12320 |
|
| 12321 |
-- declare |
| 12322 |
-- B : Boolean; |
| 12323 |
-- X : Protected_Entry_Index := <entry index>; |
| 12324 |
-- DX : Duration := To_Duration (D); |
| 12325 |
-- M : Delay_Mode := <discriminant>; |
| 12326 |
-- P : parms := (parm, parm, parm); |
| 12327 |
|
| 12328 |
-- begin |
| 12329 |
-- Timed_Protected_Entry_Call |
| 12330 |
-- (<object>'unchecked_access, X, P'Address, DX, M, B); |
| 12331 |
-- if B then |
| 12332 |
-- S1; |
| 12333 |
-- else |
| 12334 |
-- S2; |
| 12335 |
-- end if; |
| 12336 |
-- end; |
| 12337 |
|
| 12338 |
-- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there |
| 12339 |
-- is no delay and the triggering statements are executed. We first |
| 12340 |
-- determine the kind of the triggering call and then execute a |
| 12341 |
-- synchronized operation or a direct call. |
| 12342 |
|
| 12343 |
-- declare |
| 12344 |
-- B : Boolean := False; |
| 12345 |
-- C : Ada.Tags.Prim_Op_Kind; |
| 12346 |
-- DX : Duration := To_Duration (D) |
| 12347 |
-- K : Ada.Tags.Tagged_Kind := |
| 12348 |
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); |
| 12349 |
-- M : Integer :=...; |
| 12350 |
-- P : Parameters := (Param1 .. ParamN); |
| 12351 |
-- S : Integer; |
| 12352 |
|
| 12353 |
-- begin |
| 12354 |
-- if K = Ada.Tags.TK_Limited_Tagged |
| 12355 |
-- or else K = Ada.Tags.TK_Tagged |
| 12356 |
-- then |
| 12357 |
-- <dispatching-call>; |
| 12358 |
-- B := True; |
| 12359 |
|
| 12360 |
-- else |
| 12361 |
-- S := |
| 12362 |
-- Ada.Tags.Get_Offset_Index |
| 12363 |
-- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>)); |
| 12364 |
|
| 12365 |
-- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B); |
| 12366 |
|
| 12367 |
-- if C = POK_Protected_Entry |
| 12368 |
-- or else C = POK_Task_Entry |
| 12369 |
-- then |
| 12370 |
-- Param1 := P.Param1; |
| 12371 |
-- ... |
| 12372 |
-- ParamN := P.ParamN; |
| 12373 |
-- end if; |
| 12374 |
|
| 12375 |
-- if B then |
| 12376 |
-- if C = POK_Procedure |
| 12377 |
-- or else C = POK_Protected_Procedure |
| 12378 |
-- or else C = POK_Task_Procedure |
| 12379 |
-- then |
| 12380 |
-- <dispatching-call>; |
| 12381 |
-- end if; |
| 12382 |
-- end if; |
| 12383 |
-- end if; |
| 12384 |
|
| 12385 |
-- if B then |
| 12386 |
-- <triggering-statements> |
| 12387 |
-- else |
| 12388 |
-- <timed-statements> |
| 12389 |
-- end if; |
| 12390 |
-- end; |
| 12391 |
|
| 12392 |
-- The triggering statement and the sequence of timed statements have not |
| 12393 |
-- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain |
| 12394 |
-- global references if within an instantiation. |
| 12395 |
|
| 12396 |
procedure Expand_N_Timed_Entry_Call (N : Node_Id) is |
| 12397 |
Actuals : List_Id; |
| 12398 |
Blk_Typ : Entity_Id; |
| 12399 |
Call : Node_Id; |
| 12400 |
Call_Ent : Entity_Id; |
| 12401 |
Conc_Typ_Stmts : List_Id; |
| 12402 |
Concval : Node_Id := Empty; -- init to avoid warning |
| 12403 |
D_Alt : constant Node_Id := Delay_Alternative (N); |
| 12404 |
D_Conv : Node_Id; |
| 12405 |
D_Disc : Node_Id; |
| 12406 |
D_Stat : Node_Id := Delay_Statement (D_Alt); |
| 12407 |
D_Stats : List_Id; |
| 12408 |
D_Type : Entity_Id; |
| 12409 |
Decls : List_Id; |
| 12410 |
Dummy : Node_Id; |
| 12411 |
E_Alt : constant Node_Id := Entry_Call_Alternative (N); |
| 12412 |
E_Call : Node_Id := Entry_Call_Statement (E_Alt); |
| 12413 |
E_Stats : List_Id; |
| 12414 |
Ename : Node_Id; |
| 12415 |
Formals : List_Id; |
| 12416 |
Index : Node_Id; |
| 12417 |
Is_Disp_Select : Boolean; |
| 12418 |
Lim_Typ_Stmts : List_Id; |
| 12419 |
Loc : constant Source_Ptr := Sloc (D_Stat); |
| 12420 |
N_Stats : List_Id; |
| 12421 |
Obj : Entity_Id; |
| 12422 |
Param : Node_Id; |
| 12423 |
Params : List_Id; |
| 12424 |
Stmt : Node_Id; |
| 12425 |
Stmts : List_Id; |
| 12426 |
Unpack : List_Id; |
| 12427 |
|
| 12428 |
B : Entity_Id; -- Call status flag |
| 12429 |
C : Entity_Id; -- Call kind |
| 12430 |
D : Entity_Id; -- Delay |
| 12431 |
K : Entity_Id; -- Tagged kind |
| 12432 |
M : Entity_Id; -- Delay mode |
| 12433 |
P : Entity_Id; -- Parameter block |
| 12434 |
S : Entity_Id; -- Primitive operation slot |
| 12435 |
|
| 12436 |
-- Start of processing for Expand_N_Timed_Entry_Call |
| 12437 |
|
| 12438 |
begin |
| 12439 |
-- Under the Ravenscar profile, timed entry calls are excluded. An error |
| 12440 |
-- was already reported on spec, so do not attempt to expand the call. |
| 12441 |
|
| 12442 |
if Restriction_Active (No_Select_Statements) then |
| 12443 |
return; |
| 12444 |
end if; |
| 12445 |
|
| 12446 |
Process_Statements_For_Controlled_Objects (E_Alt); |
| 12447 |
Process_Statements_For_Controlled_Objects (D_Alt); |
| 12448 |
|
| 12449 |
Ensure_Statement_Present (Sloc (D_Stat), D_Alt); |
| 12450 |
|
| 12451 |
-- Retrieve E_Stats and D_Stats now because the finalization machinery |
| 12452 |
-- may wrap them in blocks. |
| 12453 |
|
| 12454 |
E_Stats := Statements (E_Alt); |
| 12455 |
D_Stats := Statements (D_Alt); |
| 12456 |
|
| 12457 |
-- The arguments in the call may require dynamic allocation, and the |
| 12458 |
-- call statement may have been transformed into a block. The block |
| 12459 |
-- may contain additional declarations for internal entities, and the |
| 12460 |
-- original call is found by sequential search. |
| 12461 |
|
| 12462 |
if Nkind (E_Call) = N_Block_Statement then |
| 12463 |
E_Call := First (Statements (Handled_Statement_Sequence (E_Call))); |
| 12464 |
while Nkind (E_Call) not in |
| 12465 |
N_Procedure_Call_Statement | N_Entry_Call_Statement |
| 12466 |
loop |
| 12467 |
Next (E_Call); |
| 12468 |
end loop; |
| 12469 |
end if; |
| 12470 |
|
| 12471 |
Is_Disp_Select := |
| 12472 |
Ada_Version >= Ada_2005 |
| 12473 |
and then Nkind (E_Call) = N_Procedure_Call_Statement; |
| 12474 |
|
| 12475 |
if Is_Disp_Select then |
| 12476 |
Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals); |
| 12477 |
Decls := New_List; |
| 12478 |
|
| 12479 |
Stmts := New_List; |
| 12480 |
|
| 12481 |
-- Generate: |
| 12482 |
-- B : Boolean := False; |
| 12483 |
|
| 12484 |
B := Build_B (Loc, Decls); |
| 12485 |
|
| 12486 |
-- Generate: |
| 12487 |
-- C : Ada.Tags.Prim_Op_Kind; |
| 12488 |
|
| 12489 |
C := Build_C (Loc, Decls); |
| 12490 |
|
| 12491 |
-- Because the analysis of all statements was disabled, manually |
| 12492 |
-- analyze the delay statement. |
| 12493 |
|
| 12494 |
Analyze (D_Stat); |
| 12495 |
D_Stat := Original_Node (D_Stat); |
| 12496 |
|
| 12497 |
else |
| 12498 |
-- Build an entry call using Simple_Entry_Call |
| 12499 |
|
| 12500 |
Extract_Entry (E_Call, Concval, Ename, Index); |
| 12501 |
Build_Simple_Entry_Call (E_Call, Concval, Ename, Index); |
| 12502 |
|
| 12503 |
Decls := Declarations (E_Call); |
| 12504 |
Stmts := Statements (Handled_Statement_Sequence (E_Call)); |
| 12505 |
|
| 12506 |
if No (Decls) then |
| 12507 |
Decls := New_List; |
| 12508 |
end if; |
| 12509 |
|
| 12510 |
-- Generate: |
| 12511 |
-- B : Boolean; |
| 12512 |
|
| 12513 |
B := Make_Defining_Identifier (Loc, Name_uB); |
| 12514 |
|
| 12515 |
Prepend_To (Decls, |
| 12516 |
Make_Object_Declaration (Loc, |
| 12517 |
Defining_Identifier => B, |
| 12518 |
Object_Definition => |
| 12519 |
New_Occurrence_Of (Standard_Boolean, Loc))); |
| 12520 |
end if; |
| 12521 |
|
| 12522 |
-- Duration and mode processing |
| 12523 |
|
| 12524 |
D_Type := Base_Type (Etype (Expression (D_Stat))); |
| 12525 |
|
| 12526 |
-- Use the type of the delay expression (Calendar or Real_Time) to |
| 12527 |
-- generate the appropriate conversion. |
| 12528 |
|
| 12529 |
if Nkind (D_Stat) = N_Delay_Relative_Statement then |
| 12530 |
D_Disc := Make_Integer_Literal (Loc, 0); |
| 12531 |
D_Conv := Relocate_Node (Expression (D_Stat)); |
| 12532 |
|
| 12533 |
elsif Is_RTE (D_Type, RO_CA_Time) then |
| 12534 |
D_Disc := Make_Integer_Literal (Loc, 1); |
| 12535 |
D_Conv := |
| 12536 |
Make_Function_Call (Loc, |
| 12537 |
Name => New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc), |
| 12538 |
Parameter_Associations => |
| 12539 |
New_List (New_Copy (Expression (D_Stat)))); |
| 12540 |
|
| 12541 |
else pragma Assert (Is_RTE (D_Type, RO_RT_Time)); |
| 12542 |
D_Disc := Make_Integer_Literal (Loc, 2); |
| 12543 |
D_Conv := |
| 12544 |
Make_Function_Call (Loc, |
| 12545 |
Name => New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc), |
| 12546 |
Parameter_Associations => |
| 12547 |
New_List (New_Copy (Expression (D_Stat)))); |
| 12548 |
end if; |
| 12549 |
|
| 12550 |
D := Make_Temporary (Loc, 'D'); |
| 12551 |
|
| 12552 |
-- Generate: |
| 12553 |
-- D : Duration; |
| 12554 |
|
| 12555 |
Append_To (Decls, |
| 12556 |
Make_Object_Declaration (Loc, |
| 12557 |
Defining_Identifier => D, |
| 12558 |
Object_Definition => New_Occurrence_Of (Standard_Duration, Loc))); |
| 12559 |
|
| 12560 |
M := Make_Temporary (Loc, 'M'); |
| 12561 |
|
| 12562 |
-- Generate: |
| 12563 |
-- M : Integer := (0 | 1 | 2); |
| 12564 |
|
| 12565 |
Append_To (Decls, |
| 12566 |
Make_Object_Declaration (Loc, |
| 12567 |
Defining_Identifier => M, |
| 12568 |
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc), |
| 12569 |
Expression => D_Disc)); |
| 12570 |
|
| 12571 |
-- Parameter block processing |
| 12572 |
|
| 12573 |
-- Manually create the parameter block for dispatching calls. In the |
| 12574 |
-- case of entries, the block has already been created during the call |
| 12575 |
-- to Build_Simple_Entry_Call. |
| 12576 |
|
| 12577 |
if Is_Disp_Select then |
| 12578 |
|
| 12579 |
-- Compute the delay at this stage because the evaluation of its |
| 12580 |
-- expression must not occur earlier (see ACVC C97302A). |
| 12581 |
|
| 12582 |
Append_To (Stmts, |
| 12583 |
Make_Assignment_Statement (Loc, |
| 12584 |
Name => New_Occurrence_Of (D, Loc), |
| 12585 |
Expression => D_Conv)); |
| 12586 |
|
| 12587 |
-- Tagged kind processing, generate: |
| 12588 |
-- K : Ada.Tags.Tagged_Kind := |
| 12589 |
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>)); |
| 12590 |
|
| 12591 |
K := Build_K (Loc, Decls, Obj); |
| 12592 |
|
| 12593 |
Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls); |
| 12594 |
P := |
| 12595 |
Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts); |
| 12596 |
|
| 12597 |
-- Dispatch table slot processing, generate: |
| 12598 |
-- S : Integer; |
| 12599 |
|
| 12600 |
S := Build_S (Loc, Decls); |
| 12601 |
|
| 12602 |
-- Generate: |
| 12603 |
-- S := Ada.Tags.Get_Offset_Index |
| 12604 |
-- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent)); |
| 12605 |
|
| 12606 |
Conc_Typ_Stmts := |
| 12607 |
New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent)); |
| 12608 |
|
| 12609 |
-- Generate: |
| 12610 |
-- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B); |
| 12611 |
|
| 12612 |
-- where Obj is the controlling formal parameter, S is the dispatch |
| 12613 |
-- table slot number of the dispatching operation, P is the wrapped |
| 12614 |
-- parameter block, D is the duration, M is the duration mode, C is |
| 12615 |
-- the call kind and B is the call status. |
| 12616 |
|
| 12617 |
Params := New_List; |
| 12618 |
|
| 12619 |
Append_To (Params, New_Copy_Tree (Obj)); |
| 12620 |
Append_To (Params, New_Occurrence_Of (S, Loc)); |
| 12621 |
Append_To (Params, |
| 12622 |
Make_Attribute_Reference (Loc, |
| 12623 |
Prefix => New_Occurrence_Of (P, Loc), |
| 12624 |
Attribute_Name => Name_Address)); |
| 12625 |
Append_To (Params, New_Occurrence_Of (D, Loc)); |
| 12626 |
Append_To (Params, New_Occurrence_Of (M, Loc)); |
| 12627 |
Append_To (Params, New_Occurrence_Of (C, Loc)); |
| 12628 |
Append_To (Params, New_Occurrence_Of (B, Loc)); |
| 12629 |
|
| 12630 |
Append_To (Conc_Typ_Stmts, |
| 12631 |
Make_Procedure_Call_Statement (Loc, |
| 12632 |
Name => |
| 12633 |
New_Occurrence_Of |
| 12634 |
(Find_Prim_Op |
| 12635 |
(Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc), |
| 12636 |
Parameter_Associations => Params)); |
| 12637 |
|
| 12638 |
-- Generate: |
| 12639 |
-- if C = POK_Protected_Entry |
| 12640 |
-- or else C = POK_Task_Entry |
| 12641 |
-- then |
| 12642 |
-- Param1 := P.Param1; |
| 12643 |
-- ... |
| 12644 |
-- ParamN := P.ParamN; |
| 12645 |
-- end if; |
| 12646 |
|
| 12647 |
Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals); |
| 12648 |
|
| 12649 |
-- Generate the if statement only when the packed parameters need |
| 12650 |
-- explicit assignments to their corresponding actuals. |
| 12651 |
|
| 12652 |
if Present (Unpack) then |
| 12653 |
Append_To (Conc_Typ_Stmts, |
| 12654 |
Make_Implicit_If_Statement (N, |
| 12655 |
|
| 12656 |
Condition => |
| 12657 |
Make_Or_Else (Loc, |
| 12658 |
Left_Opnd => |
| 12659 |
Make_Op_Eq (Loc, |
| 12660 |
Left_Opnd => New_Occurrence_Of (C, Loc), |
| 12661 |
Right_Opnd => |
| 12662 |
New_Occurrence_Of |
| 12663 |
(RTE (RE_POK_Protected_Entry), Loc)), |
| 12664 |
|
| 12665 |
Right_Opnd => |
| 12666 |
Make_Op_Eq (Loc, |
| 12667 |
Left_Opnd => New_Occurrence_Of (C, Loc), |
| 12668 |
Right_Opnd => |
| 12669 |
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))), |
| 12670 |
|
| 12671 |
Then_Statements => Unpack)); |
| 12672 |
end if; |
| 12673 |
|
| 12674 |
-- Generate: |
| 12675 |
|
| 12676 |
-- if B then |
| 12677 |
-- if C = POK_Procedure |
| 12678 |
-- or else C = POK_Protected_Procedure |
| 12679 |
-- or else C = POK_Task_Procedure |
| 12680 |
-- then |
| 12681 |
-- <dispatching-call> |
| 12682 |
-- end if; |
| 12683 |
-- end if; |
| 12684 |
|
| 12685 |
N_Stats := New_List ( |
| 12686 |
Make_Implicit_If_Statement (N, |
| 12687 |
Condition => |
| 12688 |
Make_Or_Else (Loc, |
| 12689 |
Left_Opnd => |
| 12690 |
Make_Op_Eq (Loc, |
| 12691 |
Left_Opnd => New_Occurrence_Of (C, Loc), |
| 12692 |
Right_Opnd => |
| 12693 |
New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)), |
| 12694 |
|
| 12695 |
Right_Opnd => |
| 12696 |
Make_Or_Else (Loc, |
| 12697 |
Left_Opnd => |
| 12698 |
Make_Op_Eq (Loc, |
| 12699 |
Left_Opnd => New_Occurrence_Of (C, Loc), |
| 12700 |
Right_Opnd => |
| 12701 |
New_Occurrence_Of (RTE ( |
| 12702 |
RE_POK_Protected_Procedure), Loc)), |
| 12703 |
Right_Opnd => |
| 12704 |
Make_Op_Eq (Loc, |
| 12705 |
Left_Opnd => New_Occurrence_Of (C, Loc), |
| 12706 |
Right_Opnd => |
| 12707 |
New_Occurrence_Of |
| 12708 |
(RTE (RE_POK_Task_Procedure), Loc)))), |
| 12709 |
|
| 12710 |
Then_Statements => New_List (E_Call))); |
| 12711 |
|
| 12712 |
Append_To (Conc_Typ_Stmts, |
| 12713 |
Make_Implicit_If_Statement (N, |
| 12714 |
Condition => New_Occurrence_Of (B, Loc), |
| 12715 |
Then_Statements => N_Stats)); |
| 12716 |
|
| 12717 |
-- Generate: |
| 12718 |
-- <dispatching-call>; |
| 12719 |
-- B := True; |
| 12720 |
|
| 12721 |
Lim_Typ_Stmts := |
| 12722 |
New_List (New_Copy_Tree (E_Call), |
| 12723 |
Make_Assignment_Statement (Loc, |
| 12724 |
Name => New_Occurrence_Of (B, Loc), |
| 12725 |
Expression => New_Occurrence_Of (Standard_True, Loc))); |
| 12726 |
|
| 12727 |
-- Generate: |
| 12728 |
-- if K = Ada.Tags.TK_Limited_Tagged |
| 12729 |
-- or else K = Ada.Tags.TK_Tagged |
| 12730 |
-- then |
| 12731 |
-- Lim_Typ_Stmts |
| 12732 |
-- else |
| 12733 |
-- Conc_Typ_Stmts |
| 12734 |
-- end if; |
| 12735 |
|
| 12736 |
Append_To (Stmts, |
| 12737 |
Make_Implicit_If_Statement (N, |
| 12738 |
Condition => Build_Dispatching_Tag_Check (K, N), |
| 12739 |
Then_Statements => Lim_Typ_Stmts, |
| 12740 |
Else_Statements => Conc_Typ_Stmts)); |
| 12741 |
|
| 12742 |
-- Generate: |
| 12743 |
|
| 12744 |
-- if B then |
| 12745 |
-- <triggering-statements> |
| 12746 |
-- else |
| 12747 |
-- <timed-statements> |
| 12748 |
-- end if; |
| 12749 |
|
| 12750 |
Append_To (Stmts, |
| 12751 |
Make_Implicit_If_Statement (N, |
| 12752 |
Condition => New_Occurrence_Of (B, Loc), |
| 12753 |
Then_Statements => E_Stats, |
| 12754 |
Else_Statements => D_Stats)); |
| 12755 |
|
| 12756 |
else |
| 12757 |
-- Simple case of a nondispatching trigger. Skip assignments to |
| 12758 |
-- temporaries created for in-out parameters. |
| 12759 |
|
| 12760 |
-- This makes unwarranted assumptions about the shape of the expanded |
| 12761 |
-- tree for the call, and should be cleaned up ??? |
| 12762 |
|
| 12763 |
Stmt := First (Stmts); |
| 12764 |
while Nkind (Stmt) /= N_Procedure_Call_Statement loop |
| 12765 |
Next (Stmt); |
| 12766 |
end loop; |
| 12767 |
|
| 12768 |
-- Compute the delay at this stage because the evaluation of |
| 12769 |
-- its expression must not occur earlier (see ACVC C97302A). |
| 12770 |
|
| 12771 |
Insert_Before (Stmt, |
| 12772 |
Make_Assignment_Statement (Loc, |
| 12773 |
Name => New_Occurrence_Of (D, Loc), |
| 12774 |
Expression => D_Conv)); |
| 12775 |
|
| 12776 |
Call := Stmt; |
| 12777 |
Params := Parameter_Associations (Call); |
| 12778 |
|
| 12779 |
-- For a protected type, we build a Timed_Protected_Entry_Call |
| 12780 |
|
| 12781 |
if Is_Protected_Type (Etype (Concval)) then |
| 12782 |
|
| 12783 |
-- Create a new call statement |
| 12784 |
|
| 12785 |
Param := First (Params); |
| 12786 |
while Present (Param) |
| 12787 |
and then not Is_RTE (Etype (Param), RE_Call_Modes) |
| 12788 |
loop |
| 12789 |
Next (Param); |
| 12790 |
end loop; |
| 12791 |
|
| 12792 |
Dummy := Remove_Next (Next (Param)); |
| 12793 |
|
| 12794 |
-- Remove garbage is following the Cancel_Param if present |
| 12795 |
|
| 12796 |
Dummy := Next (Param); |
| 12797 |
|
| 12798 |
-- Remove the mode of the Protected_Entry_Call call, then remove |
| 12799 |
-- the Communication_Block of the Protected_Entry_Call call, and |
| 12800 |
-- finally add Duration and a Delay_Mode parameter |
| 12801 |
|
| 12802 |
pragma Assert (Present (Param)); |
| 12803 |
Rewrite (Param, New_Occurrence_Of (D, Loc)); |
| 12804 |
|
| 12805 |
Rewrite (Dummy, New_Occurrence_Of (M, Loc)); |
| 12806 |
|
| 12807 |
-- Add a Boolean flag for successful entry call |
| 12808 |
|
| 12809 |
Append_To (Params, New_Occurrence_Of (B, Loc)); |
| 12810 |
|
| 12811 |
case Corresponding_Runtime_Package (Etype (Concval)) is |
| 12812 |
when System_Tasking_Protected_Objects_Entries => |
| 12813 |
Rewrite (Call, |
| 12814 |
Make_Procedure_Call_Statement (Loc, |
| 12815 |
Name => |
| 12816 |
New_Occurrence_Of |
| 12817 |
(RTE (RE_Timed_Protected_Entry_Call), Loc), |
| 12818 |
Parameter_Associations => Params)); |
| 12819 |
|
| 12820 |
when others => |
| 12821 |
raise Program_Error; |
| 12822 |
end case; |
| 12823 |
|
| 12824 |
-- For the task case, build a Timed_Task_Entry_Call |
| 12825 |
|
| 12826 |
else |
| 12827 |
-- Create a new call statement |
| 12828 |
|
| 12829 |
Append_To (Params, New_Occurrence_Of (D, Loc)); |
| 12830 |
Append_To (Params, New_Occurrence_Of (M, Loc)); |
| 12831 |
Append_To (Params, New_Occurrence_Of (B, Loc)); |
| 12832 |
|
| 12833 |
Rewrite (Call, |
| 12834 |
Make_Procedure_Call_Statement (Loc, |
| 12835 |
Name => |
| 12836 |
New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc), |
| 12837 |
Parameter_Associations => Params)); |
| 12838 |
end if; |
| 12839 |
|
| 12840 |
Append_To (Stmts, |
| 12841 |
Make_Implicit_If_Statement (N, |
| 12842 |
Condition => New_Occurrence_Of (B, Loc), |
| 12843 |
Then_Statements => E_Stats, |
| 12844 |
Else_Statements => D_Stats)); |
| 12845 |
end if; |
| 12846 |
|
| 12847 |
Rewrite (N, |
| 12848 |
Make_Block_Statement (Loc, |
| 12849 |
Declarations => Decls, |
| 12850 |
Handled_Statement_Sequence => |
| 12851 |
Make_Handled_Sequence_Of_Statements (Loc, Stmts))); |
| 12852 |
|
| 12853 |
Analyze (N); |
| 12854 |
|
| 12855 |
-- Some items in Decls used to be in the N_Block in E_Call that is |
| 12856 |
-- constructed in Expand_Entry_Call, and are now in the new Block |
| 12857 |
-- into which N has been rewritten. Adjust their scopes to reflect that. |
| 12858 |
|
| 12859 |
if Nkind (E_Call) = N_Block_Statement then |
| 12860 |
Obj := First_Entity (Entity (Identifier (E_Call))); |
| 12861 |
while Present (Obj) loop |
| 12862 |
Set_Scope (Obj, Entity (Identifier (N))); |
| 12863 |
Next_Entity (Obj); |
| 12864 |
end loop; |
| 12865 |
end if; |
| 12866 |
|
| 12867 |
Reset_Scopes_To (N, Entity (Identifier (N))); |
| 12868 |
end Expand_N_Timed_Entry_Call; |
| 12869 |
|
| 12870 |
---------------------------------------- |
| 12871 |
-- Expand_Protected_Body_Declarations -- |
| 12872 |
---------------------------------------- |
| 12873 |
|
| 12874 |
procedure Expand_Protected_Body_Declarations |
| 12875 |
(N : Node_Id; |
| 12876 |
Spec_Id : Entity_Id) |
| 12877 |
is |
| 12878 |
begin |
| 12879 |
if No_Run_Time_Mode then |
| 12880 |
Error_Msg_CRT ("protected body", N); |
| 12881 |
return; |
| 12882 |
|
| 12883 |
elsif Expander_Active then |
| 12884 |
|
| 12885 |
-- Associate discriminals with the first subprogram or entry body to |
| 12886 |
-- be expanded. |
| 12887 |
|
| 12888 |
if Present (First_Protected_Operation (Declarations (N))) then |
| 12889 |
Set_Discriminals (Parent (Spec_Id)); |
| 12890 |
end if; |
| 12891 |
end if; |
| 12892 |
end Expand_Protected_Body_Declarations; |
| 12893 |
|
| 12894 |
------------------------- |
| 12895 |
-- External_Subprogram -- |
| 12896 |
------------------------- |
| 12897 |
|
| 12898 |
function External_Subprogram (E : Entity_Id) return Entity_Id is |
| 12899 |
Subp : constant Entity_Id := Protected_Body_Subprogram (E); |
| 12900 |
|
| 12901 |
begin |
| 12902 |
-- The internal and external subprograms follow each other on the entity |
| 12903 |
-- chain. Note that previously private operations had no separate |
| 12904 |
-- external subprogram. We now create one in all cases, because a |
| 12905 |
-- private operation may actually appear in an external call, through |
| 12906 |
-- a 'Access reference used for a callback. |
| 12907 |
|
| 12908 |
-- If the operation is a function that returns an anonymous access type, |
| 12909 |
-- the corresponding itype appears before the operation, and must be |
| 12910 |
-- skipped. |
| 12911 |
|
| 12912 |
-- This mechanism is fragile, there should be a real link between the |
| 12913 |
-- two versions of the operation, but there is no place to put it ??? |
| 12914 |
|
| 12915 |
if Is_Access_Type (Next_Entity (Subp)) then |
| 12916 |
return Next_Entity (Next_Entity (Subp)); |
| 12917 |
else |
| 12918 |
return Next_Entity (Subp); |
| 12919 |
end if; |
| 12920 |
end External_Subprogram; |
| 12921 |
|
| 12922 |
------------------------------ |
| 12923 |
-- Extract_Dispatching_Call -- |
| 12924 |
------------------------------ |
| 12925 |
|
| 12926 |
procedure Extract_Dispatching_Call |
| 12927 |
(N : Node_Id; |
| 12928 |
Call_Ent : out Entity_Id; |
| 12929 |
Object : out Entity_Id; |
| 12930 |
Actuals : out List_Id; |
| 12931 |
Formals : out List_Id) |
| 12932 |
is |
| 12933 |
Call_Nam : Node_Id; |
| 12934 |
|
| 12935 |
begin |
| 12936 |
pragma Assert (Nkind (N) = N_Procedure_Call_Statement); |
| 12937 |
|
| 12938 |
if Present (Original_Node (N)) then |
| 12939 |
Call_Nam := Name (Original_Node (N)); |
| 12940 |
else |
| 12941 |
Call_Nam := Name (N); |
| 12942 |
end if; |
| 12943 |
|
| 12944 |
-- Retrieve the name of the dispatching procedure. It contains the |
| 12945 |
-- dispatch table slot number. |
| 12946 |
|
| 12947 |
loop |
| 12948 |
case Nkind (Call_Nam) is |
| 12949 |
when N_Identifier => |
| 12950 |
exit; |
| 12951 |
|
| 12952 |
when N_Selected_Component => |
| 12953 |
Call_Nam := Selector_Name (Call_Nam); |
| 12954 |
|
| 12955 |
when others => |
| 12956 |
raise Program_Error; |
| 12957 |
end case; |
| 12958 |
end loop; |
| 12959 |
|
| 12960 |
Actuals := Parameter_Associations (N); |
| 12961 |
Call_Ent := Entity (Call_Nam); |
| 12962 |
Formals := Parameter_Specifications (Parent (Call_Ent)); |
| 12963 |
Object := First (Actuals); |
| 12964 |
|
| 12965 |
if Present (Original_Node (Object)) then |
| 12966 |
Object := Original_Node (Object); |
| 12967 |
end if; |
| 12968 |
|
| 12969 |
-- If the type of the dispatching object is an access type then return |
| 12970 |
-- an explicit dereference of a copy of the object, and note that this |
| 12971 |
-- is the controlling actual of the call. |
| 12972 |
|
| 12973 |
if Is_Access_Type (Etype (Object)) then |
| 12974 |
Object := |
| 12975 |
Make_Explicit_Dereference (Sloc (N), New_Copy_Tree (Object)); |
| 12976 |
Analyze (Object); |
| 12977 |
Set_Is_Controlling_Actual (Object); |
| 12978 |
end if; |
| 12979 |
end Extract_Dispatching_Call; |
| 12980 |
|
| 12981 |
------------------- |
| 12982 |
-- Extract_Entry -- |
| 12983 |
------------------- |
| 12984 |
|
| 12985 |
procedure Extract_Entry |
| 12986 |
(N : Node_Id; |
| 12987 |
Concval : out Node_Id; |
| 12988 |
Ename : out Node_Id; |
| 12989 |
Index : out Node_Id) |
| 12990 |
is |
| 12991 |
Nam : constant Node_Id := Name (N); |
| 12992 |
|
| 12993 |
begin |
| 12994 |
-- For a simple entry, the name is a selected component, with the |
| 12995 |
-- prefix being the task value, and the selector being the entry. |
| 12996 |
|
| 12997 |
if Nkind (Nam) = N_Selected_Component then |
| 12998 |
Concval := Prefix (Nam); |
| 12999 |
Ename := Selector_Name (Nam); |
| 13000 |
Index := Empty; |
| 13001 |
|
| 13002 |
-- For a member of an entry family, the name is an indexed component |
| 13003 |
-- where the prefix is a selected component, whose prefix in turn is |
| 13004 |
-- the task value, and whose selector is the entry family. The single |
| 13005 |
-- expression in the expressions list of the indexed component is the |
| 13006 |
-- subscript for the family. |
| 13007 |
|
| 13008 |
else pragma Assert (Nkind (Nam) = N_Indexed_Component); |
| 13009 |
Concval := Prefix (Prefix (Nam)); |
| 13010 |
Ename := Selector_Name (Prefix (Nam)); |
| 13011 |
Index := First (Expressions (Nam)); |
| 13012 |
end if; |
| 13013 |
|
| 13014 |
-- Through indirection, the type may actually be a limited view of a |
| 13015 |
-- concurrent type. When compiling a call, the non-limited view of the |
| 13016 |
-- type is visible. |
| 13017 |
|
| 13018 |
if From_Limited_With (Etype (Concval)) then |
| 13019 |
Set_Etype (Concval, Non_Limited_View (Etype (Concval))); |
| 13020 |
end if; |
| 13021 |
end Extract_Entry; |
| 13022 |
|
| 13023 |
------------------- |
| 13024 |
-- Family_Offset -- |
| 13025 |
------------------- |
| 13026 |
|
| 13027 |
function Family_Offset |
| 13028 |
(Loc : Source_Ptr; |
| 13029 |
Hi : Node_Id; |
| 13030 |
Lo : Node_Id; |
| 13031 |
Ttyp : Entity_Id; |
| 13032 |
Cap : Boolean) return Node_Id |
| 13033 |
is |
| 13034 |
Ityp : Entity_Id; |
| 13035 |
Real_Hi : Node_Id; |
| 13036 |
Real_Lo : Node_Id; |
| 13037 |
|
| 13038 |
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id; |
| 13039 |
-- If one of the bounds is a reference to a discriminant, replace with |
| 13040 |
-- corresponding discriminal of type. Within the body of a task retrieve |
| 13041 |
-- the renamed discriminant by simple visibility, using its generated |
| 13042 |
-- name. Within a protected object, find the original discriminant and |
| 13043 |
-- replace it with the discriminal of the current protected operation. |
| 13044 |
|
| 13045 |
------------------------------ |
| 13046 |
-- Convert_Discriminant_Ref -- |
| 13047 |
------------------------------ |
| 13048 |
|
| 13049 |
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is |
| 13050 |
Loc : constant Source_Ptr := Sloc (Bound); |
| 13051 |
B : Node_Id; |
| 13052 |
D : Entity_Id; |
| 13053 |
|
| 13054 |
begin |
| 13055 |
if Is_Entity_Name (Bound) |
| 13056 |
and then Ekind (Entity (Bound)) = E_Discriminant |
| 13057 |
then |
| 13058 |
if Is_Task_Type (Ttyp) and then Has_Completion (Ttyp) then |
| 13059 |
B := Make_Identifier (Loc, Chars (Entity (Bound))); |
| 13060 |
Find_Direct_Name (B); |
| 13061 |
|
| 13062 |
elsif Is_Protected_Type (Ttyp) then |
| 13063 |
D := First_Discriminant (Ttyp); |
| 13064 |
while Chars (D) /= Chars (Entity (Bound)) loop |
| 13065 |
Next_Discriminant (D); |
| 13066 |
end loop; |
| 13067 |
|
| 13068 |
B := New_Occurrence_Of (Discriminal (D), Loc); |
| 13069 |
|
| 13070 |
else |
| 13071 |
B := New_Occurrence_Of (Discriminal (Entity (Bound)), Loc); |
| 13072 |
end if; |
| 13073 |
|
| 13074 |
elsif Nkind (Bound) = N_Attribute_Reference then |
| 13075 |
return Bound; |
| 13076 |
|
| 13077 |
else |
| 13078 |
B := New_Copy_Tree (Bound); |
| 13079 |
end if; |
| 13080 |
|
| 13081 |
return |
| 13082 |
Make_Attribute_Reference (Loc, |
| 13083 |
Attribute_Name => Name_Pos, |
| 13084 |
Prefix => New_Occurrence_Of (Etype (Bound), Loc), |
| 13085 |
Expressions => New_List (B)); |
| 13086 |
end Convert_Discriminant_Ref; |
| 13087 |
|
| 13088 |
-- Start of processing for Family_Offset |
| 13089 |
|
| 13090 |
begin |
| 13091 |
Real_Hi := Convert_Discriminant_Ref (Hi); |
| 13092 |
Real_Lo := Convert_Discriminant_Ref (Lo); |
| 13093 |
|
| 13094 |
if Cap then |
| 13095 |
if Is_Task_Type (Ttyp) then |
| 13096 |
Ityp := RTE (RE_Task_Entry_Index); |
| 13097 |
else |
| 13098 |
Ityp := RTE (RE_Protected_Entry_Index); |
| 13099 |
end if; |
| 13100 |
|
| 13101 |
Real_Hi := |
| 13102 |
Make_Attribute_Reference (Loc, |
| 13103 |
Prefix => New_Occurrence_Of (Ityp, Loc), |
| 13104 |
Attribute_Name => Name_Min, |
| 13105 |
Expressions => New_List ( |
| 13106 |
Real_Hi, |
| 13107 |
Make_Integer_Literal (Loc, Entry_Family_Bound - 1))); |
| 13108 |
|
| 13109 |
Real_Lo := |
| 13110 |
Make_Attribute_Reference (Loc, |
| 13111 |
Prefix => New_Occurrence_Of (Ityp, Loc), |
| 13112 |
Attribute_Name => Name_Max, |
| 13113 |
Expressions => New_List ( |
| 13114 |
Real_Lo, |
| 13115 |
Make_Integer_Literal (Loc, -Entry_Family_Bound))); |
| 13116 |
end if; |
| 13117 |
|
| 13118 |
return Make_Op_Subtract (Loc, Real_Hi, Real_Lo); |
| 13119 |
end Family_Offset; |
| 13120 |
|
| 13121 |
----------------- |
| 13122 |
-- Family_Size -- |
| 13123 |
----------------- |
| 13124 |
|
| 13125 |
function Family_Size |
| 13126 |
(Loc : Source_Ptr; |
| 13127 |
Hi : Node_Id; |
| 13128 |
Lo : Node_Id; |
| 13129 |
Ttyp : Entity_Id; |
| 13130 |
Cap : Boolean) return Node_Id |
| 13131 |
is |
| 13132 |
Ityp : Entity_Id; |
| 13133 |
|
| 13134 |
begin |
| 13135 |
if Is_Task_Type (Ttyp) then |
| 13136 |
Ityp := RTE (RE_Task_Entry_Index); |
| 13137 |
else |
| 13138 |
Ityp := RTE (RE_Protected_Entry_Index); |
| 13139 |
end if; |
| 13140 |
|
| 13141 |
return |
| 13142 |
Make_Attribute_Reference (Loc, |
| 13143 |
Prefix => New_Occurrence_Of (Ityp, Loc), |
| 13144 |
Attribute_Name => Name_Max, |
| 13145 |
Expressions => New_List ( |
| 13146 |
Make_Op_Add (Loc, |
| 13147 |
Left_Opnd => Family_Offset (Loc, Hi, Lo, Ttyp, Cap), |
| 13148 |
Right_Opnd => Make_Integer_Literal (Loc, 1)), |
| 13149 |
Make_Integer_Literal (Loc, 0))); |
| 13150 |
end Family_Size; |
| 13151 |
|
| 13152 |
---------------------------- |
| 13153 |
-- Find_Enclosing_Context -- |
| 13154 |
---------------------------- |
| 13155 |
|
| 13156 |
procedure Find_Enclosing_Context |
| 13157 |
(N : Node_Id; |
| 13158 |
Context : out Node_Id; |
| 13159 |
Context_Id : out Entity_Id; |
| 13160 |
Context_Decls : out List_Id) |
| 13161 |
is |
| 13162 |
begin |
| 13163 |
-- Traverse the parent chain looking for an enclosing body, block, |
| 13164 |
-- package or return statement. |
| 13165 |
|
| 13166 |
Context := Parent (N); |
| 13167 |
while Present (Context) loop |
| 13168 |
if Nkind (Context) in N_Entry_Body |
| 13169 |
| N_Extended_Return_Statement |
| 13170 |
| N_Package_Body |
| 13171 |
| N_Package_Declaration |
| 13172 |
| N_Subprogram_Body |
| 13173 |
| N_Task_Body |
| 13174 |
then |
| 13175 |
exit; |
| 13176 |
|
| 13177 |
-- Do not consider block created to protect a list of statements with |
| 13178 |
-- an Abort_Defer / Abort_Undefer_Direct pair. |
| 13179 |
|
| 13180 |
elsif Nkind (Context) = N_Block_Statement |
| 13181 |
and then not Is_Abort_Block (Context) |
| 13182 |
then |
| 13183 |
exit; |
| 13184 |
end if; |
| 13185 |
|
| 13186 |
Context := Parent (Context); |
| 13187 |
end loop; |
| 13188 |
|
| 13189 |
pragma Assert (Present (Context)); |
| 13190 |
|
| 13191 |
-- Extract the constituents of the context |
| 13192 |
|
| 13193 |
if Nkind (Context) = N_Extended_Return_Statement then |
| 13194 |
Context_Decls := Return_Object_Declarations (Context); |
| 13195 |
Context_Id := Return_Statement_Entity (Context); |
| 13196 |
|
| 13197 |
-- Package declarations and bodies use a common library-level activation |
| 13198 |
-- chain or task master, therefore return the package declaration as the |
| 13199 |
-- proper carrier for the appropriate flag. |
| 13200 |
|
| 13201 |
elsif Nkind (Context) = N_Package_Body then |
| 13202 |
Context_Decls := Declarations (Context); |
| 13203 |
Context_Id := Corresponding_Spec (Context); |
| 13204 |
Context := Parent (Context_Id); |
| 13205 |
|
| 13206 |
if Nkind (Context) = N_Defining_Program_Unit_Name then |
| 13207 |
Context := Parent (Parent (Context)); |
| 13208 |
else |
| 13209 |
Context := Parent (Context); |
| 13210 |
end if; |
| 13211 |
|
| 13212 |
elsif Nkind (Context) = N_Package_Declaration then |
| 13213 |
Context_Decls := Visible_Declarations (Specification (Context)); |
| 13214 |
Context_Id := Defining_Unit_Name (Specification (Context)); |
| 13215 |
|
| 13216 |
if Nkind (Context_Id) = N_Defining_Program_Unit_Name then |
| 13217 |
Context_Id := Defining_Identifier (Context_Id); |
| 13218 |
end if; |
| 13219 |
|
| 13220 |
else |
| 13221 |
if Nkind (Context) = N_Block_Statement then |
| 13222 |
Context_Id := Entity (Identifier (Context)); |
| 13223 |
|
| 13224 |
if No (Declarations (Context)) then |
| 13225 |
Set_Declarations (Context, New_List); |
| 13226 |
end if; |
| 13227 |
|
| 13228 |
elsif Nkind (Context) = N_Entry_Body then |
| 13229 |
Context_Id := Defining_Identifier (Context); |
| 13230 |
|
| 13231 |
elsif Nkind (Context) = N_Subprogram_Body then |
| 13232 |
if Present (Corresponding_Spec (Context)) then |
| 13233 |
Context_Id := Corresponding_Spec (Context); |
| 13234 |
else |
| 13235 |
Context_Id := Defining_Unit_Name (Specification (Context)); |
| 13236 |
|
| 13237 |
if Nkind (Context_Id) = N_Defining_Program_Unit_Name then |
| 13238 |
Context_Id := Defining_Identifier (Context_Id); |
| 13239 |
end if; |
| 13240 |
end if; |
| 13241 |
|
| 13242 |
elsif Nkind (Context) = N_Task_Body then |
| 13243 |
Context_Id := Corresponding_Spec (Context); |
| 13244 |
|
| 13245 |
else |
| 13246 |
raise Program_Error; |
| 13247 |
end if; |
| 13248 |
|
| 13249 |
Context_Decls := Declarations (Context); |
| 13250 |
end if; |
| 13251 |
|
| 13252 |
pragma Assert (Present (Context_Id)); |
| 13253 |
pragma Assert (Present (Context_Decls)); |
| 13254 |
end Find_Enclosing_Context; |
| 13255 |
|
| 13256 |
----------------------- |
| 13257 |
-- Find_Master_Scope -- |
| 13258 |
----------------------- |
| 13259 |
|
| 13260 |
function Find_Master_Scope (E : Entity_Id) return Entity_Id is |
| 13261 |
S : Entity_Id; |
| 13262 |
|
| 13263 |
begin |
| 13264 |
-- In Ada 2005, the master is the innermost enclosing scope that is not |
| 13265 |
-- transient. If the enclosing block is the rewriting of a call or the |
| 13266 |
-- scope is an extended return statement this is valid master. The |
| 13267 |
-- master in an extended return is only used within the return, and is |
| 13268 |
-- subsequently overwritten in Move_Activation_Chain, but it must exist |
| 13269 |
-- now before that overwriting occurs. |
| 13270 |
|
| 13271 |
S := Scope (E); |
| 13272 |
|
| 13273 |
if Ada_Version >= Ada_2005 then |
| 13274 |
while Is_Internal (S) loop |
| 13275 |
if Nkind (Parent (S)) = N_Block_Statement |
| 13276 |
and then Has_Master_Entity (S) |
| 13277 |
then |
| 13278 |
exit; |
| 13279 |
|
| 13280 |
elsif Ekind (S) = E_Return_Statement then |
| 13281 |
exit; |
| 13282 |
|
| 13283 |
else |
| 13284 |
S := Scope (S); |
| 13285 |
end if; |
| 13286 |
end loop; |
| 13287 |
end if; |
| 13288 |
|
| 13289 |
return S; |
| 13290 |
end Find_Master_Scope; |
| 13291 |
|
| 13292 |
------------------------------- |
| 13293 |
-- First_Protected_Operation -- |
| 13294 |
------------------------------- |
| 13295 |
|
| 13296 |
function First_Protected_Operation (D : List_Id) return Node_Id is |
| 13297 |
First_Op : Node_Id; |
| 13298 |
|
| 13299 |
begin |
| 13300 |
First_Op := First (D); |
| 13301 |
while Present (First_Op) |
| 13302 |
and then Nkind (First_Op) not in N_Subprogram_Body | N_Entry_Body |
| 13303 |
loop |
| 13304 |
Next (First_Op); |
| 13305 |
end loop; |
| 13306 |
|
| 13307 |
return First_Op; |
| 13308 |
end First_Protected_Operation; |
| 13309 |
|
| 13310 |
--------------------------------------- |
| 13311 |
-- Install_Private_Data_Declarations -- |
| 13312 |
--------------------------------------- |
| 13313 |
|
| 13314 |
procedure Install_Private_Data_Declarations |
| 13315 |
(Loc : Source_Ptr; |
| 13316 |
Spec_Id : Entity_Id; |
| 13317 |
Conc_Typ : Entity_Id; |
| 13318 |
Body_Nod : Node_Id; |
| 13319 |
Decls : List_Id; |
| 13320 |
Barrier : Boolean := False; |
| 13321 |
Family : Boolean := False) |
| 13322 |
is |
| 13323 |
Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ); |
| 13324 |
Decl : Node_Id; |
| 13325 |
Def : Node_Id; |
| 13326 |
Insert_Node : Node_Id := Empty; |
| 13327 |
Obj_Ent : Entity_Id; |
| 13328 |
|
| 13329 |
procedure Add (Decl : Node_Id); |
| 13330 |
-- Add a single declaration after Insert_Node. If this is the first |
| 13331 |
-- addition, Decl is added to the front of Decls and it becomes the |
| 13332 |
-- insertion node. |
| 13333 |
|
| 13334 |
function Replace_Bound (Bound : Node_Id) return Node_Id; |
| 13335 |
-- The bounds of an entry index may depend on discriminants, create a |
| 13336 |
-- reference to the corresponding prival. Otherwise return a duplicate |
| 13337 |
-- of the original bound. |
| 13338 |
|
| 13339 |
--------- |
| 13340 |
-- Add -- |
| 13341 |
--------- |
| 13342 |
|
| 13343 |
procedure Add (Decl : Node_Id) is |
| 13344 |
begin |
| 13345 |
if No (Insert_Node) then |
| 13346 |
Prepend_To (Decls, Decl); |
| 13347 |
else |
| 13348 |
Insert_After (Insert_Node, Decl); |
| 13349 |
end if; |
| 13350 |
|
| 13351 |
Insert_Node := Decl; |
| 13352 |
end Add; |
| 13353 |
|
| 13354 |
------------------- |
| 13355 |
-- Replace_Bound -- |
| 13356 |
------------------- |
| 13357 |
|
| 13358 |
function Replace_Bound (Bound : Node_Id) return Node_Id is |
| 13359 |
begin |
| 13360 |
if Nkind (Bound) = N_Identifier |
| 13361 |
and then Is_Discriminal (Entity (Bound)) |
| 13362 |
then |
| 13363 |
return Make_Identifier (Loc, Chars (Entity (Bound))); |
| 13364 |
else |
| 13365 |
return Duplicate_Subexpr (Bound); |
| 13366 |
end if; |
| 13367 |
end Replace_Bound; |
| 13368 |
|
| 13369 |
-- Start of processing for Install_Private_Data_Declarations |
| 13370 |
|
| 13371 |
begin |
| 13372 |
-- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote |
| 13373 |
-- formal parameter _O, _object or _task depending on the context. |
| 13374 |
|
| 13375 |
Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ); |
| 13376 |
|
| 13377 |
-- Special processing of _O for barrier functions, protected entries |
| 13378 |
-- and families. |
| 13379 |
|
| 13380 |
if Barrier |
| 13381 |
or else |
| 13382 |
(Is_Protected |
| 13383 |
and then |
| 13384 |
(Ekind (Spec_Id) = E_Entry |
| 13385 |
or else Ekind (Spec_Id) = E_Entry_Family)) |
| 13386 |
then |
| 13387 |
declare |
| 13388 |
Conc_Rec : constant Entity_Id := |
| 13389 |
Corresponding_Record_Type (Conc_Typ); |
| 13390 |
Typ_Id : constant Entity_Id := |
| 13391 |
Make_Defining_Identifier (Loc, |
| 13392 |
New_External_Name (Chars (Conc_Rec), 'P')); |
| 13393 |
begin |
| 13394 |
-- Generate: |
| 13395 |
-- type prot_typVP is access prot_typV; |
| 13396 |
|
| 13397 |
Decl := |
| 13398 |
Make_Full_Type_Declaration (Loc, |
| 13399 |
Defining_Identifier => Typ_Id, |
| 13400 |
Type_Definition => |
| 13401 |
Make_Access_To_Object_Definition (Loc, |
| 13402 |
Subtype_Indication => |
| 13403 |
New_Occurrence_Of (Conc_Rec, Loc))); |
| 13404 |
Add (Decl); |
| 13405 |
|
| 13406 |
-- Generate: |
| 13407 |
-- _object : prot_typVP := prot_typV (_O); |
| 13408 |
|
| 13409 |
Decl := |
| 13410 |
Make_Object_Declaration (Loc, |
| 13411 |
Defining_Identifier => |
| 13412 |
Make_Defining_Identifier (Loc, Name_uObject), |
| 13413 |
Object_Definition => New_Occurrence_Of (Typ_Id, Loc), |
| 13414 |
Expression => |
| 13415 |
Unchecked_Convert_To (Typ_Id, |
| 13416 |
New_Occurrence_Of (Obj_Ent, Loc))); |
| 13417 |
Add (Decl); |
| 13418 |
|
| 13419 |
-- Set the reference to the concurrent object |
| 13420 |
|
| 13421 |
Obj_Ent := Defining_Identifier (Decl); |
| 13422 |
end; |
| 13423 |
end if; |
| 13424 |
|
| 13425 |
-- Step 2: Create the Protection object and build its declaration for |
| 13426 |
-- any protected entry (family) of subprogram. Note for the lock-free |
| 13427 |
-- implementation, the Protection object is not needed anymore. |
| 13428 |
|
| 13429 |
if Is_Protected and then not Uses_Lock_Free (Conc_Typ) then |
| 13430 |
declare |
| 13431 |
Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R'); |
| 13432 |
Prot_Typ : RE_Id; |
| 13433 |
|
| 13434 |
begin |
| 13435 |
Set_Protection_Object (Spec_Id, Prot_Ent); |
| 13436 |
|
| 13437 |
-- Determine the proper protection type |
| 13438 |
|
| 13439 |
if Has_Attach_Handler (Conc_Typ) |
| 13440 |
and then not Restricted_Profile |
| 13441 |
then |
| 13442 |
Prot_Typ := RE_Static_Interrupt_Protection; |
| 13443 |
|
| 13444 |
elsif Has_Interrupt_Handler (Conc_Typ) |
| 13445 |
and then not Restriction_Active (No_Dynamic_Attachment) |
| 13446 |
then |
| 13447 |
Prot_Typ := RE_Dynamic_Interrupt_Protection; |
| 13448 |
|
| 13449 |
else |
| 13450 |
case Corresponding_Runtime_Package (Conc_Typ) is |
| 13451 |
when System_Tasking_Protected_Objects_Entries => |
| 13452 |
Prot_Typ := RE_Protection_Entries; |
| 13453 |
|
| 13454 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 13455 |
Prot_Typ := RE_Protection_Entry; |
| 13456 |
|
| 13457 |
when System_Tasking_Protected_Objects => |
| 13458 |
Prot_Typ := RE_Protection; |
| 13459 |
|
| 13460 |
when others => |
| 13461 |
raise Program_Error; |
| 13462 |
end case; |
| 13463 |
end if; |
| 13464 |
|
| 13465 |
-- Generate: |
| 13466 |
-- conc_typR : protection_typ renames _object._object; |
| 13467 |
|
| 13468 |
Decl := |
| 13469 |
Make_Object_Renaming_Declaration (Loc, |
| 13470 |
Defining_Identifier => Prot_Ent, |
| 13471 |
Subtype_Mark => |
| 13472 |
New_Occurrence_Of (RTE (Prot_Typ), Loc), |
| 13473 |
Name => |
| 13474 |
Make_Selected_Component (Loc, |
| 13475 |
Prefix => New_Occurrence_Of (Obj_Ent, Loc), |
| 13476 |
Selector_Name => Make_Identifier (Loc, Name_uObject))); |
| 13477 |
|
| 13478 |
Add (Decl); |
| 13479 |
end; |
| 13480 |
end if; |
| 13481 |
|
| 13482 |
-- Step 3: Add discriminant renamings (if any) |
| 13483 |
|
| 13484 |
if Has_Discriminants (Conc_Typ) then |
| 13485 |
declare |
| 13486 |
D : Entity_Id; |
| 13487 |
|
| 13488 |
begin |
| 13489 |
D := First_Discriminant (Conc_Typ); |
| 13490 |
while Present (D) loop |
| 13491 |
|
| 13492 |
-- Adjust the source location |
| 13493 |
|
| 13494 |
Set_Sloc (Discriminal (D), Loc); |
| 13495 |
|
| 13496 |
-- Generate: |
| 13497 |
-- discr_name : discr_typ renames _object.discr_name; |
| 13498 |
-- or |
| 13499 |
-- discr_name : discr_typ renames _task.discr_name; |
| 13500 |
|
| 13501 |
Decl := |
| 13502 |
Make_Object_Renaming_Declaration (Loc, |
| 13503 |
Defining_Identifier => Discriminal (D), |
| 13504 |
Subtype_Mark => New_Occurrence_Of (Etype (D), Loc), |
| 13505 |
Name => |
| 13506 |
Make_Selected_Component (Loc, |
| 13507 |
Prefix => New_Occurrence_Of (Obj_Ent, Loc), |
| 13508 |
Selector_Name => Make_Identifier (Loc, Chars (D)))); |
| 13509 |
|
| 13510 |
Add (Decl); |
| 13511 |
|
| 13512 |
-- Set debug info needed on this renaming declaration even |
| 13513 |
-- though it does not come from source, so that the debugger |
| 13514 |
-- will get the right information for these generated names. |
| 13515 |
|
| 13516 |
Set_Debug_Info_Needed (Discriminal (D)); |
| 13517 |
|
| 13518 |
Next_Discriminant (D); |
| 13519 |
end loop; |
| 13520 |
end; |
| 13521 |
end if; |
| 13522 |
|
| 13523 |
-- Step 4: Add private component renamings (if any) |
| 13524 |
|
| 13525 |
if Is_Protected then |
| 13526 |
Def := Protected_Definition (Parent (Conc_Typ)); |
| 13527 |
|
| 13528 |
if Present (Private_Declarations (Def)) then |
| 13529 |
declare |
| 13530 |
Comp : Node_Id; |
| 13531 |
Comp_Id : Entity_Id; |
| 13532 |
Decl_Id : Entity_Id; |
| 13533 |
Nam : Name_Id; |
| 13534 |
|
| 13535 |
begin |
| 13536 |
Comp := First (Private_Declarations (Def)); |
| 13537 |
while Present (Comp) loop |
| 13538 |
if Nkind (Comp) = N_Component_Declaration then |
| 13539 |
Comp_Id := Defining_Identifier (Comp); |
| 13540 |
Nam := Chars (Comp_Id); |
| 13541 |
Decl_Id := Make_Defining_Identifier (Sloc (Comp_Id), Nam); |
| 13542 |
|
| 13543 |
-- Minimal decoration |
| 13544 |
|
| 13545 |
if Ekind (Spec_Id) = E_Function then |
| 13546 |
Mutate_Ekind (Decl_Id, E_Constant); |
| 13547 |
else |
| 13548 |
Mutate_Ekind (Decl_Id, E_Variable); |
| 13549 |
end if; |
| 13550 |
|
| 13551 |
Set_Prival (Comp_Id, Decl_Id); |
| 13552 |
Set_Prival_Link (Decl_Id, Comp_Id); |
| 13553 |
Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id)); |
| 13554 |
Set_Is_Independent (Decl_Id, Is_Independent (Comp_Id)); |
| 13555 |
|
| 13556 |
-- Copy the Comes_From_Source flag of the component, as |
| 13557 |
-- the renaming may be the only entity directly seen by |
| 13558 |
-- the user in the context, but do not warn for it. |
| 13559 |
|
| 13560 |
Set_Comes_From_Source |
| 13561 |
(Decl_Id, Comes_From_Source (Comp_Id)); |
| 13562 |
Set_Warnings_Off (Decl_Id); |
| 13563 |
|
| 13564 |
-- Generate: |
| 13565 |
-- comp_name : comp_typ renames _object.comp_name; |
| 13566 |
|
| 13567 |
Decl := |
| 13568 |
Make_Object_Renaming_Declaration (Loc, |
| 13569 |
Defining_Identifier => Decl_Id, |
| 13570 |
Subtype_Mark => |
| 13571 |
New_Occurrence_Of (Etype (Comp_Id), Loc), |
| 13572 |
Name => |
| 13573 |
Make_Selected_Component (Loc, |
| 13574 |
Prefix => New_Occurrence_Of (Obj_Ent, Loc), |
| 13575 |
Selector_Name => Make_Identifier (Loc, Nam))); |
| 13576 |
|
| 13577 |
Add (Decl); |
| 13578 |
end if; |
| 13579 |
|
| 13580 |
Next (Comp); |
| 13581 |
end loop; |
| 13582 |
end; |
| 13583 |
end if; |
| 13584 |
end if; |
| 13585 |
|
| 13586 |
-- Step 5: Add the declaration of the entry index and the associated |
| 13587 |
-- type for barrier functions and entry families. |
| 13588 |
|
| 13589 |
if (Barrier and Family) or else Ekind (Spec_Id) = E_Entry_Family then |
| 13590 |
declare |
| 13591 |
E : constant Entity_Id := Index_Object (Spec_Id); |
| 13592 |
Index : constant Entity_Id := |
| 13593 |
Defining_Identifier |
| 13594 |
(Entry_Index_Specification |
| 13595 |
(Entry_Body_Formal_Part (Body_Nod))); |
| 13596 |
Index_Con : constant Entity_Id := |
| 13597 |
Make_Defining_Identifier (Loc, Chars (Index)); |
| 13598 |
High : Node_Id; |
| 13599 |
Index_Typ : Entity_Id; |
| 13600 |
Low : Node_Id; |
| 13601 |
|
| 13602 |
begin |
| 13603 |
-- Minimal decoration |
| 13604 |
|
| 13605 |
Mutate_Ekind (Index_Con, E_Constant); |
| 13606 |
Set_Entry_Index_Constant (Index, Index_Con); |
| 13607 |
Set_Discriminal_Link (Index_Con, Index); |
| 13608 |
|
| 13609 |
-- Retrieve the bounds of the entry family |
| 13610 |
|
| 13611 |
High := Type_High_Bound (Etype (Index)); |
| 13612 |
Low := Type_Low_Bound (Etype (Index)); |
| 13613 |
|
| 13614 |
-- In the simple case the entry family is given by a subtype mark |
| 13615 |
-- and the index constant has the same type. |
| 13616 |
|
| 13617 |
if Is_Entity_Name (Original_Node ( |
| 13618 |
Discrete_Subtype_Definition (Parent (Index)))) |
| 13619 |
then |
| 13620 |
Index_Typ := Etype (Index); |
| 13621 |
|
| 13622 |
-- Otherwise a new subtype declaration is required |
| 13623 |
|
| 13624 |
else |
| 13625 |
High := Replace_Bound (High); |
| 13626 |
Low := Replace_Bound (Low); |
| 13627 |
|
| 13628 |
Index_Typ := Make_Temporary (Loc, 'J'); |
| 13629 |
|
| 13630 |
-- Generate: |
| 13631 |
-- subtype Jnn is <Etype of Index> range Low .. High; |
| 13632 |
|
| 13633 |
Decl := |
| 13634 |
Make_Subtype_Declaration (Loc, |
| 13635 |
Defining_Identifier => Index_Typ, |
| 13636 |
Subtype_Indication => |
| 13637 |
Make_Subtype_Indication (Loc, |
| 13638 |
Subtype_Mark => |
| 13639 |
New_Occurrence_Of (Base_Type (Etype (Index)), Loc), |
| 13640 |
Constraint => |
| 13641 |
Make_Range_Constraint (Loc, |
| 13642 |
Range_Expression => |
| 13643 |
Make_Range (Loc, Low, High)))); |
| 13644 |
Add (Decl); |
| 13645 |
end if; |
| 13646 |
|
| 13647 |
Set_Etype (Index_Con, Index_Typ); |
| 13648 |
|
| 13649 |
-- Create the object which designates the index: |
| 13650 |
-- J : constant Jnn := |
| 13651 |
-- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First)); |
| 13652 |
-- |
| 13653 |
-- where Jnn is the subtype created above or the original type of |
| 13654 |
-- the index, _E is a formal of the protected body subprogram and |
| 13655 |
-- <index expr> is the index of the first family member. |
| 13656 |
|
| 13657 |
Decl := |
| 13658 |
Make_Object_Declaration (Loc, |
| 13659 |
Defining_Identifier => Index_Con, |
| 13660 |
Constant_Present => True, |
| 13661 |
Object_Definition => |
| 13662 |
New_Occurrence_Of (Index_Typ, Loc), |
| 13663 |
|
| 13664 |
Expression => |
| 13665 |
Make_Attribute_Reference (Loc, |
| 13666 |
Prefix => |
| 13667 |
New_Occurrence_Of (Index_Typ, Loc), |
| 13668 |
Attribute_Name => Name_Val, |
| 13669 |
|
| 13670 |
Expressions => New_List ( |
| 13671 |
|
| 13672 |
Make_Op_Add (Loc, |
| 13673 |
Left_Opnd => |
| 13674 |
Make_Op_Subtract (Loc, |
| 13675 |
Left_Opnd => New_Occurrence_Of (E, Loc), |
| 13676 |
Right_Opnd => |
| 13677 |
Entry_Index_Expression (Loc, |
| 13678 |
Defining_Identifier (Body_Nod), |
| 13679 |
Empty, Conc_Typ)), |
| 13680 |
|
| 13681 |
Right_Opnd => |
| 13682 |
Make_Attribute_Reference (Loc, |
| 13683 |
Prefix => |
| 13684 |
New_Occurrence_Of (Index_Typ, Loc), |
| 13685 |
Attribute_Name => Name_Pos, |
| 13686 |
Expressions => New_List ( |
| 13687 |
Make_Attribute_Reference (Loc, |
| 13688 |
Prefix => |
| 13689 |
New_Occurrence_Of (Index_Typ, Loc), |
| 13690 |
Attribute_Name => Name_First))))))); |
| 13691 |
Add (Decl); |
| 13692 |
end; |
| 13693 |
end if; |
| 13694 |
end Install_Private_Data_Declarations; |
| 13695 |
|
| 13696 |
--------------------------------- |
| 13697 |
-- Is_Potentially_Large_Family -- |
| 13698 |
--------------------------------- |
| 13699 |
|
| 13700 |
function Is_Potentially_Large_Family |
| 13701 |
(Base_Index : Entity_Id; |
| 13702 |
Conctyp : Entity_Id; |
| 13703 |
Lo : Node_Id; |
| 13704 |
Hi : Node_Id) return Boolean |
| 13705 |
is |
| 13706 |
begin |
| 13707 |
return Scope (Base_Index) = Standard_Standard |
| 13708 |
and then Base_Index = Base_Type (Standard_Integer) |
| 13709 |
and then Has_Defaulted_Discriminants (Conctyp) |
| 13710 |
and then |
| 13711 |
(Denotes_Discriminant (Lo, True) |
| 13712 |
or else |
| 13713 |
Denotes_Discriminant (Hi, True)); |
| 13714 |
end Is_Potentially_Large_Family; |
| 13715 |
|
| 13716 |
------------------------------------- |
| 13717 |
-- Is_Private_Primitive_Subprogram -- |
| 13718 |
------------------------------------- |
| 13719 |
|
| 13720 |
function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is |
| 13721 |
begin |
| 13722 |
return |
| 13723 |
(Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure) |
| 13724 |
and then Is_Private_Primitive (Id); |
| 13725 |
end Is_Private_Primitive_Subprogram; |
| 13726 |
|
| 13727 |
------------------ |
| 13728 |
-- Index_Object -- |
| 13729 |
------------------ |
| 13730 |
|
| 13731 |
function Index_Object (Spec_Id : Entity_Id) return Entity_Id is |
| 13732 |
Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id); |
| 13733 |
Formal : Entity_Id; |
| 13734 |
|
| 13735 |
begin |
| 13736 |
Formal := First_Formal (Bod_Subp); |
| 13737 |
while Present (Formal) loop |
| 13738 |
|
| 13739 |
-- Look for formal parameter _E |
| 13740 |
|
| 13741 |
if Chars (Formal) = Name_uE then |
| 13742 |
return Formal; |
| 13743 |
end if; |
| 13744 |
|
| 13745 |
Next_Formal (Formal); |
| 13746 |
end loop; |
| 13747 |
|
| 13748 |
-- A protected body subprogram should always have the parameter in |
| 13749 |
-- question. |
| 13750 |
|
| 13751 |
raise Program_Error; |
| 13752 |
end Index_Object; |
| 13753 |
|
| 13754 |
-------------------------------- |
| 13755 |
-- Make_Initialize_Protection -- |
| 13756 |
-------------------------------- |
| 13757 |
|
| 13758 |
function Make_Initialize_Protection |
| 13759 |
(Protect_Rec : Entity_Id) return List_Id |
| 13760 |
is |
| 13761 |
Loc : constant Source_Ptr := Sloc (Protect_Rec); |
| 13762 |
P_Arr : Entity_Id; |
| 13763 |
Pdec : Node_Id; |
| 13764 |
Ptyp : constant Node_Id := |
| 13765 |
Corresponding_Concurrent_Type (Protect_Rec); |
| 13766 |
Args : List_Id; |
| 13767 |
L : constant List_Id := New_List; |
| 13768 |
Has_Entry : constant Boolean := Has_Entries (Ptyp); |
| 13769 |
Prio_Type : Entity_Id; |
| 13770 |
Prio_Var : Entity_Id := Empty; |
| 13771 |
Restricted : constant Boolean := Restricted_Profile; |
| 13772 |
|
| 13773 |
begin |
| 13774 |
-- We may need two calls to properly initialize the object, one to |
| 13775 |
-- Initialize_Protection, and possibly one to Install_Handlers if we |
| 13776 |
-- have a pragma Attach_Handler. |
| 13777 |
|
| 13778 |
-- Get protected declaration. In the case of a task type declaration, |
| 13779 |
-- this is simply the parent of the protected type entity. In the single |
| 13780 |
-- protected object declaration, this parent will be the implicit type, |
| 13781 |
-- and we can find the corresponding single protected object declaration |
| 13782 |
-- by searching forward in the declaration list in the tree. |
| 13783 |
|
| 13784 |
-- Is the test for N_Single_Protected_Declaration needed here??? Nodes |
| 13785 |
-- of this type should have been removed during semantic analysis. |
| 13786 |
|
| 13787 |
Pdec := Parent (Ptyp); |
| 13788 |
while Nkind (Pdec) not in |
| 13789 |
N_Protected_Type_Declaration | N_Single_Protected_Declaration |
| 13790 |
loop |
| 13791 |
Next (Pdec); |
| 13792 |
end loop; |
| 13793 |
|
| 13794 |
-- Build the parameter list for the call. Note that _Init is the name |
| 13795 |
-- of the formal for the object to be initialized, which is the task |
| 13796 |
-- value record itself. |
| 13797 |
|
| 13798 |
Args := New_List; |
| 13799 |
|
| 13800 |
-- For lock-free implementation, skip initializations of the Protection |
| 13801 |
-- object. |
| 13802 |
|
| 13803 |
if not Uses_Lock_Free (Defining_Identifier (Pdec)) then |
| 13804 |
|
| 13805 |
-- Object parameter. This is a pointer to the object of type |
| 13806 |
-- Protection used by the GNARL to control the protected object. |
| 13807 |
|
| 13808 |
Append_To (Args, |
| 13809 |
Make_Attribute_Reference (Loc, |
| 13810 |
Prefix => |
| 13811 |
Make_Selected_Component (Loc, |
| 13812 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 13813 |
Selector_Name => Make_Identifier (Loc, Name_uObject)), |
| 13814 |
Attribute_Name => Name_Unchecked_Access)); |
| 13815 |
|
| 13816 |
-- Priority parameter. Set to Unspecified_Priority unless there is a |
| 13817 |
-- Priority rep item, in which case we take the value from the pragma |
| 13818 |
-- or attribute definition clause, or there is an Interrupt_Priority |
| 13819 |
-- rep item and no Priority rep item, and we set the ceiling to |
| 13820 |
-- Interrupt_Priority'Last, an implementation-defined value, see |
| 13821 |
-- (RM D.3(10)). |
| 13822 |
|
| 13823 |
if Has_Rep_Item (Ptyp, Name_Priority, Check_Parents => False) then |
| 13824 |
declare |
| 13825 |
Prio_Clause : constant Node_Id := |
| 13826 |
Get_Rep_Item |
| 13827 |
(Ptyp, Name_Priority, Check_Parents => False); |
| 13828 |
|
| 13829 |
Prio : Node_Id; |
| 13830 |
|
| 13831 |
begin |
| 13832 |
-- Pragma Priority |
| 13833 |
|
| 13834 |
if Nkind (Prio_Clause) = N_Pragma then |
| 13835 |
Prio := |
| 13836 |
Expression |
| 13837 |
(First (Pragma_Argument_Associations (Prio_Clause))); |
| 13838 |
|
| 13839 |
-- Get_Rep_Item returns either priority pragma |
| 13840 |
|
| 13841 |
if Pragma_Name (Prio_Clause) = Name_Priority then |
| 13842 |
Prio_Type := RTE (RE_Any_Priority); |
| 13843 |
else |
| 13844 |
Prio_Type := RTE (RE_Interrupt_Priority); |
| 13845 |
end if; |
| 13846 |
|
| 13847 |
-- Attribute definition clause Priority |
| 13848 |
|
| 13849 |
else |
| 13850 |
if Chars (Prio_Clause) = Name_Priority then |
| 13851 |
Prio_Type := RTE (RE_Any_Priority); |
| 13852 |
else |
| 13853 |
Prio_Type := RTE (RE_Interrupt_Priority); |
| 13854 |
end if; |
| 13855 |
|
| 13856 |
Prio := Expression (Prio_Clause); |
| 13857 |
end if; |
| 13858 |
|
| 13859 |
-- Always create a locale variable to capture the priority. |
| 13860 |
-- The priority is also passed to Install_Restriced_Handlers. |
| 13861 |
-- Note that it is really necessary to create this variable |
| 13862 |
-- explicitly. It might be thought that removing side effects |
| 13863 |
-- would the appropriate approach, but that could generate |
| 13864 |
-- declarations improperly placed in the enclosing scope. |
| 13865 |
|
| 13866 |
Prio_Var := Make_Temporary (Loc, 'R', Prio); |
| 13867 |
Append_To (L, |
| 13868 |
Make_Object_Declaration (Loc, |
| 13869 |
Defining_Identifier => Prio_Var, |
| 13870 |
Object_Definition => New_Occurrence_Of (Prio_Type, Loc), |
| 13871 |
Expression => Relocate_Node (Prio))); |
| 13872 |
|
| 13873 |
Append_To (Args, New_Occurrence_Of (Prio_Var, Loc)); |
| 13874 |
end; |
| 13875 |
|
| 13876 |
-- When no priority is specified but an xx_Handler pragma is, we |
| 13877 |
-- default to System.Interrupts.Default_Interrupt_Priority, see |
| 13878 |
-- D.3(10). |
| 13879 |
|
| 13880 |
elsif Has_Attach_Handler (Ptyp) |
| 13881 |
or else Has_Interrupt_Handler (Ptyp) |
| 13882 |
then |
| 13883 |
Append_To (Args, |
| 13884 |
New_Occurrence_Of (RTE (RE_Default_Interrupt_Priority), Loc)); |
| 13885 |
|
| 13886 |
-- Normal case, no priority or xx_Handler specified, default priority |
| 13887 |
|
| 13888 |
else |
| 13889 |
Append_To (Args, |
| 13890 |
New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc)); |
| 13891 |
end if; |
| 13892 |
|
| 13893 |
-- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes |
| 13894 |
|
| 13895 |
if Restricted_Profile and Task_Dispatching_Policy = 'E' then |
| 13896 |
Deadline_Floor : declare |
| 13897 |
Item : constant Node_Id := |
| 13898 |
Get_Rep_Item |
| 13899 |
(Ptyp, Name_Deadline_Floor, Check_Parents => False); |
| 13900 |
|
| 13901 |
Deadline : Node_Id; |
| 13902 |
|
| 13903 |
begin |
| 13904 |
if Present (Item) then |
| 13905 |
|
| 13906 |
-- Pragma Deadline_Floor |
| 13907 |
|
| 13908 |
if Nkind (Item) = N_Pragma then |
| 13909 |
Deadline := |
| 13910 |
Expression |
| 13911 |
(First (Pragma_Argument_Associations (Item))); |
| 13912 |
|
| 13913 |
-- Attribute definition clause Deadline_Floor |
| 13914 |
|
| 13915 |
else |
| 13916 |
pragma Assert |
| 13917 |
(Nkind (Item) = N_Attribute_Definition_Clause); |
| 13918 |
|
| 13919 |
Deadline := Expression (Item); |
| 13920 |
end if; |
| 13921 |
|
| 13922 |
Append_To (Args, Deadline); |
| 13923 |
|
| 13924 |
-- Unusual case: default deadline |
| 13925 |
|
| 13926 |
else |
| 13927 |
Append_To (Args, |
| 13928 |
New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc)); |
| 13929 |
end if; |
| 13930 |
end Deadline_Floor; |
| 13931 |
end if; |
| 13932 |
|
| 13933 |
-- Test for Compiler_Info parameter. This parameter allows entry body |
| 13934 |
-- procedures and barrier functions to be called from the runtime. It |
| 13935 |
-- is a pointer to the record generated by the compiler to represent |
| 13936 |
-- the protected object. |
| 13937 |
|
| 13938 |
-- A protected type without entries that covers an interface and |
| 13939 |
-- overrides the abstract routines with protected procedures is |
| 13940 |
-- considered equivalent to a protected type with entries in the |
| 13941 |
-- context of dispatching select statements. |
| 13942 |
|
| 13943 |
-- Protected types with interrupt handlers (when not using a |
| 13944 |
-- restricted profile) are also considered equivalent to protected |
| 13945 |
-- types with entries. |
| 13946 |
|
| 13947 |
-- The types which are used (Static_Interrupt_Protection and |
| 13948 |
-- Dynamic_Interrupt_Protection) are derived from Protection_Entries. |
| 13949 |
|
| 13950 |
declare |
| 13951 |
Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp); |
| 13952 |
|
| 13953 |
Called_Subp : RE_Id; |
| 13954 |
|
| 13955 |
begin |
| 13956 |
case Pkg_Id is |
| 13957 |
when System_Tasking_Protected_Objects_Entries => |
| 13958 |
Called_Subp := RE_Initialize_Protection_Entries; |
| 13959 |
|
| 13960 |
-- Argument Compiler_Info |
| 13961 |
|
| 13962 |
Append_To (Args, |
| 13963 |
Make_Attribute_Reference (Loc, |
| 13964 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 13965 |
Attribute_Name => Name_Address)); |
| 13966 |
|
| 13967 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 13968 |
Called_Subp := RE_Initialize_Protection_Entry; |
| 13969 |
|
| 13970 |
-- Argument Compiler_Info |
| 13971 |
|
| 13972 |
Append_To (Args, |
| 13973 |
Make_Attribute_Reference (Loc, |
| 13974 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 13975 |
Attribute_Name => Name_Address)); |
| 13976 |
|
| 13977 |
when System_Tasking_Protected_Objects => |
| 13978 |
Called_Subp := RE_Initialize_Protection; |
| 13979 |
|
| 13980 |
when others => |
| 13981 |
raise Program_Error; |
| 13982 |
end case; |
| 13983 |
|
| 13984 |
-- Entry_Queue_Maxes parameter. This is an access to an array of |
| 13985 |
-- naturals representing the entry queue maximums for each entry |
| 13986 |
-- in the protected type. Zero represents no max. The access is |
| 13987 |
-- null if there is no limit for all entries (usual case). |
| 13988 |
|
| 13989 |
if Has_Entry |
| 13990 |
and then Pkg_Id = System_Tasking_Protected_Objects_Entries |
| 13991 |
then |
| 13992 |
if Present (Entry_Max_Queue_Lengths_Array (Ptyp)) then |
| 13993 |
Append_To (Args, |
| 13994 |
Make_Attribute_Reference (Loc, |
| 13995 |
Prefix => |
| 13996 |
New_Occurrence_Of |
| 13997 |
(Entry_Max_Queue_Lengths_Array (Ptyp), Loc), |
| 13998 |
Attribute_Name => Name_Unrestricted_Access)); |
| 13999 |
else |
| 14000 |
Append_To (Args, Make_Null (Loc)); |
| 14001 |
end if; |
| 14002 |
|
| 14003 |
-- Edge cases exist where entry initialization functions are |
| 14004 |
-- called, but no entries exist, so null is appended. |
| 14005 |
|
| 14006 |
elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then |
| 14007 |
Append_To (Args, Make_Null (Loc)); |
| 14008 |
end if; |
| 14009 |
|
| 14010 |
-- Entry_Bodies parameter. This is a pointer to an array of |
| 14011 |
-- pointers to the entry body procedures and barrier functions of |
| 14012 |
-- the object. If the protected type has no entries this object |
| 14013 |
-- will not exist, in this case, pass a null (it can happen when |
| 14014 |
-- there are protected interrupt handlers or interfaces). |
| 14015 |
|
| 14016 |
if Has_Entry then |
| 14017 |
P_Arr := Entry_Bodies_Array (Ptyp); |
| 14018 |
|
| 14019 |
-- Argument Entry_Body (for single entry) or Entry_Bodies (for |
| 14020 |
-- multiple entries). |
| 14021 |
|
| 14022 |
Append_To (Args, |
| 14023 |
Make_Attribute_Reference (Loc, |
| 14024 |
Prefix => New_Occurrence_Of (P_Arr, Loc), |
| 14025 |
Attribute_Name => Name_Unrestricted_Access)); |
| 14026 |
|
| 14027 |
if Pkg_Id = System_Tasking_Protected_Objects_Entries then |
| 14028 |
|
| 14029 |
-- Find index mapping function (clumsy but ok for now) |
| 14030 |
|
| 14031 |
while Ekind (P_Arr) /= E_Function loop |
| 14032 |
Next_Entity (P_Arr); |
| 14033 |
end loop; |
| 14034 |
|
| 14035 |
Append_To (Args, |
| 14036 |
Make_Attribute_Reference (Loc, |
| 14037 |
Prefix => New_Occurrence_Of (P_Arr, Loc), |
| 14038 |
Attribute_Name => Name_Unrestricted_Access)); |
| 14039 |
end if; |
| 14040 |
|
| 14041 |
elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then |
| 14042 |
|
| 14043 |
-- This is the case where we have a protected object with |
| 14044 |
-- interfaces and no entries, and the single entry restriction |
| 14045 |
-- is in effect. We pass a null pointer for the entry |
| 14046 |
-- parameter because there is no actual entry. |
| 14047 |
|
| 14048 |
Append_To (Args, Make_Null (Loc)); |
| 14049 |
|
| 14050 |
elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then |
| 14051 |
|
| 14052 |
-- This is the case where we have a protected object with no |
| 14053 |
-- entries and: |
| 14054 |
-- - either interrupt handlers with non restricted profile, |
| 14055 |
-- - or interfaces |
| 14056 |
-- Note that the types which are used for interrupt handlers |
| 14057 |
-- (Static/Dynamic_Interrupt_Protection) are derived from |
| 14058 |
-- Protection_Entries. We pass two null pointers because there |
| 14059 |
-- is no actual entry, and the initialization procedure needs |
| 14060 |
-- both Entry_Bodies and Find_Body_Index. |
| 14061 |
|
| 14062 |
Append_To (Args, Make_Null (Loc)); |
| 14063 |
Append_To (Args, Make_Null (Loc)); |
| 14064 |
end if; |
| 14065 |
|
| 14066 |
Append_To (L, |
| 14067 |
Make_Procedure_Call_Statement (Loc, |
| 14068 |
Name => |
| 14069 |
New_Occurrence_Of (RTE (Called_Subp), Loc), |
| 14070 |
Parameter_Associations => Args)); |
| 14071 |
end; |
| 14072 |
end if; |
| 14073 |
|
| 14074 |
if Has_Attach_Handler (Ptyp) then |
| 14075 |
|
| 14076 |
-- We have a list of N Attach_Handler (ProcI, ExprI), and we have to |
| 14077 |
-- make the following call: |
| 14078 |
|
| 14079 |
-- Install_Handlers (_object, |
| 14080 |
-- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)); |
| 14081 |
|
| 14082 |
-- or, in the case of Ravenscar: |
| 14083 |
|
| 14084 |
-- Install_Restricted_Handlers |
| 14085 |
-- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access))); |
| 14086 |
|
| 14087 |
declare |
| 14088 |
Args : constant List_Id := New_List; |
| 14089 |
Table : constant List_Id := New_List; |
| 14090 |
Ritem : Node_Id := First_Rep_Item (Ptyp); |
| 14091 |
|
| 14092 |
begin |
| 14093 |
-- Build the Priority parameter (only for ravenscar) |
| 14094 |
|
| 14095 |
if Restricted then |
| 14096 |
|
| 14097 |
-- Priority comes from a pragma |
| 14098 |
|
| 14099 |
if Present (Prio_Var) then |
| 14100 |
Append_To (Args, New_Occurrence_Of (Prio_Var, Loc)); |
| 14101 |
|
| 14102 |
-- Priority is the default one |
| 14103 |
|
| 14104 |
else |
| 14105 |
Append_To (Args, |
| 14106 |
New_Occurrence_Of |
| 14107 |
(RTE (RE_Default_Interrupt_Priority), Loc)); |
| 14108 |
end if; |
| 14109 |
end if; |
| 14110 |
|
| 14111 |
-- Build the Attach_Handler table argument |
| 14112 |
|
| 14113 |
while Present (Ritem) loop |
| 14114 |
if Nkind (Ritem) = N_Pragma |
| 14115 |
and then Pragma_Name (Ritem) = Name_Attach_Handler |
| 14116 |
then |
| 14117 |
declare |
| 14118 |
Handler : constant Node_Id := |
| 14119 |
First (Pragma_Argument_Associations (Ritem)); |
| 14120 |
|
| 14121 |
Interrupt : constant Node_Id := Next (Handler); |
| 14122 |
Expr : constant Node_Id := Expression (Interrupt); |
| 14123 |
|
| 14124 |
begin |
| 14125 |
Append_To (Table, |
| 14126 |
Make_Aggregate (Loc, Expressions => New_List ( |
| 14127 |
Unchecked_Convert_To |
| 14128 |
(RTE (RE_System_Interrupt_Id), Expr), |
| 14129 |
Make_Attribute_Reference (Loc, |
| 14130 |
Prefix => |
| 14131 |
Make_Selected_Component (Loc, |
| 14132 |
Prefix => |
| 14133 |
Make_Identifier (Loc, Name_uInit), |
| 14134 |
Selector_Name => |
| 14135 |
Duplicate_Subexpr_No_Checks |
| 14136 |
(Expression (Handler))), |
| 14137 |
Attribute_Name => Name_Access)))); |
| 14138 |
end; |
| 14139 |
end if; |
| 14140 |
|
| 14141 |
Next_Rep_Item (Ritem); |
| 14142 |
end loop; |
| 14143 |
|
| 14144 |
-- Append the table argument we just built |
| 14145 |
|
| 14146 |
Append_To (Args, Make_Aggregate (Loc, Table)); |
| 14147 |
|
| 14148 |
-- Append the Install_Handlers (or Install_Restricted_Handlers) |
| 14149 |
-- call to the statements. |
| 14150 |
|
| 14151 |
if Restricted then |
| 14152 |
-- Call a simplified version of Install_Handlers to be used |
| 14153 |
-- when the Ravenscar restrictions are in effect |
| 14154 |
-- (Install_Restricted_Handlers). |
| 14155 |
|
| 14156 |
Append_To (L, |
| 14157 |
Make_Procedure_Call_Statement (Loc, |
| 14158 |
Name => |
| 14159 |
New_Occurrence_Of |
| 14160 |
(RTE (RE_Install_Restricted_Handlers), Loc), |
| 14161 |
Parameter_Associations => Args)); |
| 14162 |
|
| 14163 |
else |
| 14164 |
if not Uses_Lock_Free (Defining_Identifier (Pdec)) then |
| 14165 |
|
| 14166 |
-- First, prepends the _object argument |
| 14167 |
|
| 14168 |
Prepend_To (Args, |
| 14169 |
Make_Attribute_Reference (Loc, |
| 14170 |
Prefix => |
| 14171 |
Make_Selected_Component (Loc, |
| 14172 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14173 |
Selector_Name => |
| 14174 |
Make_Identifier (Loc, Name_uObject)), |
| 14175 |
Attribute_Name => Name_Unchecked_Access)); |
| 14176 |
end if; |
| 14177 |
|
| 14178 |
-- Then, insert call to Install_Handlers |
| 14179 |
|
| 14180 |
Append_To (L, |
| 14181 |
Make_Procedure_Call_Statement (Loc, |
| 14182 |
Name => |
| 14183 |
New_Occurrence_Of (RTE (RE_Install_Handlers), Loc), |
| 14184 |
Parameter_Associations => Args)); |
| 14185 |
end if; |
| 14186 |
end; |
| 14187 |
end if; |
| 14188 |
|
| 14189 |
return L; |
| 14190 |
end Make_Initialize_Protection; |
| 14191 |
|
| 14192 |
--------------------------- |
| 14193 |
-- Make_Task_Create_Call -- |
| 14194 |
--------------------------- |
| 14195 |
|
| 14196 |
function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is |
| 14197 |
Loc : constant Source_Ptr := Sloc (Task_Rec); |
| 14198 |
Args : List_Id; |
| 14199 |
Ecount : Node_Id; |
| 14200 |
Name : Node_Id; |
| 14201 |
Tdec : Node_Id; |
| 14202 |
Tdef : Node_Id; |
| 14203 |
Tnam : Name_Id; |
| 14204 |
Ttyp : Entity_Id; |
| 14205 |
|
| 14206 |
begin |
| 14207 |
Ttyp := Corresponding_Concurrent_Type (Task_Rec); |
| 14208 |
Tnam := Chars (Ttyp); |
| 14209 |
|
| 14210 |
-- Get task declaration. In the case of a task type declaration, this is |
| 14211 |
-- simply the parent of the task type entity. In the single task |
| 14212 |
-- declaration, this parent will be the implicit type, and we can find |
| 14213 |
-- the corresponding single task declaration by searching forward in the |
| 14214 |
-- declaration list in the tree. |
| 14215 |
|
| 14216 |
-- Is the test for N_Single_Task_Declaration needed here??? Nodes of |
| 14217 |
-- this type should have been removed during semantic analysis. |
| 14218 |
|
| 14219 |
Tdec := Parent (Ttyp); |
| 14220 |
while Nkind (Tdec) not in |
| 14221 |
N_Task_Type_Declaration | N_Single_Task_Declaration |
| 14222 |
loop |
| 14223 |
Next (Tdec); |
| 14224 |
end loop; |
| 14225 |
|
| 14226 |
-- Now we can find the task definition from this declaration |
| 14227 |
|
| 14228 |
Tdef := Task_Definition (Tdec); |
| 14229 |
|
| 14230 |
-- Build the parameter list for the call. Note that _Init is the name |
| 14231 |
-- of the formal for the object to be initialized, which is the task |
| 14232 |
-- value record itself. |
| 14233 |
|
| 14234 |
Args := New_List; |
| 14235 |
|
| 14236 |
-- Priority parameter. Set to Unspecified_Priority unless there is a |
| 14237 |
-- Priority rep item, in which case we take the value from the rep item. |
| 14238 |
-- Not used on Ravenscar_EDF profile. |
| 14239 |
|
| 14240 |
if not (Restricted_Profile and then Task_Dispatching_Policy = 'E') then |
| 14241 |
if Has_Rep_Item (Ttyp, Name_Priority, Check_Parents => False) then |
| 14242 |
Append_To (Args, |
| 14243 |
Make_Selected_Component (Loc, |
| 14244 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14245 |
Selector_Name => Make_Identifier (Loc, Name_uPriority))); |
| 14246 |
else |
| 14247 |
Append_To (Args, |
| 14248 |
New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc)); |
| 14249 |
end if; |
| 14250 |
end if; |
| 14251 |
|
| 14252 |
-- Optional Stack parameter |
| 14253 |
|
| 14254 |
if Restricted_Profile then |
| 14255 |
|
| 14256 |
-- If the stack has been preallocated by the expander then |
| 14257 |
-- pass its address. Otherwise, pass a null address. |
| 14258 |
|
| 14259 |
if Preallocated_Stacks_On_Target then |
| 14260 |
Append_To (Args, |
| 14261 |
Make_Attribute_Reference (Loc, |
| 14262 |
Prefix => |
| 14263 |
Make_Selected_Component (Loc, |
| 14264 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14265 |
Selector_Name => Make_Identifier (Loc, Name_uStack)), |
| 14266 |
Attribute_Name => Name_Address)); |
| 14267 |
|
| 14268 |
else |
| 14269 |
Append_To (Args, |
| 14270 |
New_Occurrence_Of (RTE (RE_Null_Address), Loc)); |
| 14271 |
end if; |
| 14272 |
end if; |
| 14273 |
|
| 14274 |
-- Size parameter. If no Storage_Size pragma is present, then |
| 14275 |
-- the size is taken from the taskZ variable for the type, which |
| 14276 |
-- is either Unspecified_Size, or has been reset by the use of |
| 14277 |
-- a Storage_Size attribute definition clause. If a pragma is |
| 14278 |
-- present, then the size is taken from the _Size field of the |
| 14279 |
-- task value record, which was set from the pragma value. |
| 14280 |
|
| 14281 |
if Present (Tdef) and then Has_Storage_Size_Pragma (Tdef) then |
| 14282 |
Append_To (Args, |
| 14283 |
Make_Selected_Component (Loc, |
| 14284 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14285 |
Selector_Name => Make_Identifier (Loc, Name_uSize))); |
| 14286 |
|
| 14287 |
else |
| 14288 |
Append_To (Args, |
| 14289 |
New_Occurrence_Of (Storage_Size_Variable (Ttyp), Loc)); |
| 14290 |
end if; |
| 14291 |
|
| 14292 |
-- Secondary_Stack parameter used for restricted profiles |
| 14293 |
|
| 14294 |
if Restricted_Profile then |
| 14295 |
|
| 14296 |
-- If the secondary stack has been allocated by the expander then |
| 14297 |
-- pass its access pointer. Otherwise, pass null. |
| 14298 |
|
| 14299 |
if Create_Secondary_Stack_For_Task (Ttyp) then |
| 14300 |
Append_To (Args, |
| 14301 |
Make_Attribute_Reference (Loc, |
| 14302 |
Prefix => |
| 14303 |
Make_Selected_Component (Loc, |
| 14304 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14305 |
Selector_Name => |
| 14306 |
Make_Identifier (Loc, Name_uSecondary_Stack)), |
| 14307 |
Attribute_Name => Name_Unrestricted_Access)); |
| 14308 |
|
| 14309 |
else |
| 14310 |
Append_To (Args, Make_Null (Loc)); |
| 14311 |
end if; |
| 14312 |
end if; |
| 14313 |
|
| 14314 |
-- Secondary_Stack_Size parameter. Set RE_Unspecified_Size unless there |
| 14315 |
-- is a Secondary_Stack_Size pragma, in which case take the value from |
| 14316 |
-- the pragma. If the restriction No_Secondary_Stack is active then a |
| 14317 |
-- size of 0 is passed regardless to prevent the allocation of the |
| 14318 |
-- unused stack. |
| 14319 |
|
| 14320 |
if Restriction_Active (No_Secondary_Stack) then |
| 14321 |
Append_To (Args, Make_Integer_Literal (Loc, 0)); |
| 14322 |
|
| 14323 |
elsif Has_Rep_Pragma |
| 14324 |
(Ttyp, Name_Secondary_Stack_Size, Check_Parents => False) |
| 14325 |
then |
| 14326 |
Append_To (Args, |
| 14327 |
Make_Selected_Component (Loc, |
| 14328 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14329 |
Selector_Name => |
| 14330 |
Make_Identifier (Loc, Name_uSecondary_Stack_Size))); |
| 14331 |
|
| 14332 |
else |
| 14333 |
Append_To (Args, |
| 14334 |
New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc)); |
| 14335 |
end if; |
| 14336 |
|
| 14337 |
-- Task_Info parameter. Set to Unspecified_Task_Info unless there is a |
| 14338 |
-- Task_Info pragma, in which case we take the value from the pragma. |
| 14339 |
|
| 14340 |
if Has_Rep_Pragma (Ttyp, Name_Task_Info, Check_Parents => False) then |
| 14341 |
Append_To (Args, |
| 14342 |
Make_Selected_Component (Loc, |
| 14343 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14344 |
Selector_Name => Make_Identifier (Loc, Name_uTask_Info))); |
| 14345 |
|
| 14346 |
else |
| 14347 |
Append_To (Args, |
| 14348 |
New_Occurrence_Of (RTE (RE_Unspecified_Task_Info), Loc)); |
| 14349 |
end if; |
| 14350 |
|
| 14351 |
-- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item, |
| 14352 |
-- in which case we take the value from the rep item. The parameter is |
| 14353 |
-- passed as an Integer because in the case of unspecified CPU the |
| 14354 |
-- value is not in the range of CPU_Range. |
| 14355 |
|
| 14356 |
if Has_Rep_Item (Ttyp, Name_CPU, Check_Parents => False) then |
| 14357 |
Append_To (Args, |
| 14358 |
Convert_To (Standard_Integer, |
| 14359 |
Make_Selected_Component (Loc, |
| 14360 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14361 |
Selector_Name => Make_Identifier (Loc, Name_uCPU)))); |
| 14362 |
else |
| 14363 |
Append_To (Args, |
| 14364 |
New_Occurrence_Of (RTE (RE_Unspecified_CPU), Loc)); |
| 14365 |
end if; |
| 14366 |
|
| 14367 |
if not Restricted_Profile or else Task_Dispatching_Policy = 'E' then |
| 14368 |
|
| 14369 |
-- Deadline parameter. If no Relative_Deadline pragma is present, |
| 14370 |
-- then the deadline is Time_Span_Zero. If a pragma is present, then |
| 14371 |
-- the deadline is taken from the _Relative_Deadline field of the |
| 14372 |
-- task value record, which was set from the pragma value. Note that |
| 14373 |
-- this parameter must not be generated for the restricted profiles |
| 14374 |
-- since Ravenscar does not allow deadlines. |
| 14375 |
|
| 14376 |
-- Case where pragma Relative_Deadline applies: use given value |
| 14377 |
|
| 14378 |
if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then |
| 14379 |
Append_To (Args, |
| 14380 |
Make_Selected_Component (Loc, |
| 14381 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14382 |
Selector_Name => |
| 14383 |
Make_Identifier (Loc, Name_uRelative_Deadline))); |
| 14384 |
|
| 14385 |
-- No pragma Relative_Deadline apply to the task |
| 14386 |
|
| 14387 |
else |
| 14388 |
Append_To (Args, |
| 14389 |
New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc)); |
| 14390 |
end if; |
| 14391 |
end if; |
| 14392 |
|
| 14393 |
if not Restricted_Profile then |
| 14394 |
|
| 14395 |
-- Dispatching_Domain parameter. If no Dispatching_Domain rep item is |
| 14396 |
-- present, then the dispatching domain is null. If a rep item is |
| 14397 |
-- present, then the dispatching domain is taken from the |
| 14398 |
-- _Dispatching_Domain field of the task value record, which was set |
| 14399 |
-- from the rep item value. |
| 14400 |
|
| 14401 |
-- Case where Dispatching_Domain rep item applies: use given value |
| 14402 |
|
| 14403 |
if Has_Rep_Item |
| 14404 |
(Ttyp, Name_Dispatching_Domain, Check_Parents => False) |
| 14405 |
then |
| 14406 |
Append_To (Args, |
| 14407 |
Make_Selected_Component (Loc, |
| 14408 |
Prefix => |
| 14409 |
Make_Identifier (Loc, Name_uInit), |
| 14410 |
Selector_Name => |
| 14411 |
Make_Identifier (Loc, Name_uDispatching_Domain))); |
| 14412 |
|
| 14413 |
-- No pragma or aspect Dispatching_Domain applies to the task |
| 14414 |
|
| 14415 |
else |
| 14416 |
Append_To (Args, Make_Null (Loc)); |
| 14417 |
end if; |
| 14418 |
|
| 14419 |
-- Number of entries. This is an expression of the form: |
| 14420 |
|
| 14421 |
-- n + _Init.a'Length + _Init.a'B'Length + ... |
| 14422 |
|
| 14423 |
-- where a,b... are the entry family names for the task definition |
| 14424 |
|
| 14425 |
Ecount := Build_Entry_Count_Expression (Ttyp, Loc); |
| 14426 |
Append_To (Args, Ecount); |
| 14427 |
|
| 14428 |
-- Master parameter. This is a reference to the _Master parameter of |
| 14429 |
-- the initialization procedure, except in the case of the pragma |
| 14430 |
-- Restrictions (No_Task_Hierarchy) where the value is fixed to |
| 14431 |
-- System.Tasking.Library_Task_Level. |
| 14432 |
|
| 14433 |
if Restriction_Active (No_Task_Hierarchy) = False then |
| 14434 |
Append_To (Args, Make_Identifier (Loc, Name_uMaster)); |
| 14435 |
else |
| 14436 |
Append_To (Args, Make_Integer_Literal (Loc, Library_Task_Level)); |
| 14437 |
end if; |
| 14438 |
end if; |
| 14439 |
|
| 14440 |
-- State parameter. This is a pointer to the task body procedure. The |
| 14441 |
-- required value is obtained by taking 'Unrestricted_Access of the task |
| 14442 |
-- body procedure and converting it (with an unchecked conversion) to |
| 14443 |
-- the type required by the task kernel. For further details, see the |
| 14444 |
-- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather |
| 14445 |
-- than 'Address in order to avoid creating trampolines. |
| 14446 |
|
| 14447 |
declare |
| 14448 |
Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp); |
| 14449 |
Subp_Ptr_Typ : constant Node_Id := |
| 14450 |
Create_Itype (E_Access_Subprogram_Type, Tdec); |
| 14451 |
Ref : constant Node_Id := Make_Itype_Reference (Loc); |
| 14452 |
|
| 14453 |
begin |
| 14454 |
Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc); |
| 14455 |
Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ); |
| 14456 |
|
| 14457 |
-- Be sure to freeze a reference to the access-to-subprogram type, |
| 14458 |
-- otherwise gigi will complain that it's in the wrong scope, because |
| 14459 |
-- it's actually inside the init procedure for the record type that |
| 14460 |
-- corresponds to the task type. |
| 14461 |
|
| 14462 |
Set_Itype (Ref, Subp_Ptr_Typ); |
| 14463 |
Append_Freeze_Action (Task_Rec, Ref); |
| 14464 |
|
| 14465 |
Append_To (Args, |
| 14466 |
Unchecked_Convert_To (RTE (RE_Task_Procedure_Access), |
| 14467 |
Make_Qualified_Expression (Loc, |
| 14468 |
Subtype_Mark => New_Occurrence_Of (Subp_Ptr_Typ, Loc), |
| 14469 |
Expression => |
| 14470 |
Make_Attribute_Reference (Loc, |
| 14471 |
Prefix => New_Occurrence_Of (Body_Proc, Loc), |
| 14472 |
Attribute_Name => Name_Unrestricted_Access)))); |
| 14473 |
end; |
| 14474 |
|
| 14475 |
-- Discriminants parameter. This is just the address of the task |
| 14476 |
-- value record itself (which contains the discriminant values |
| 14477 |
|
| 14478 |
Append_To (Args, |
| 14479 |
Make_Attribute_Reference (Loc, |
| 14480 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14481 |
Attribute_Name => Name_Address)); |
| 14482 |
|
| 14483 |
-- Elaborated parameter. This is an access to the elaboration Boolean |
| 14484 |
|
| 14485 |
Append_To (Args, |
| 14486 |
Make_Attribute_Reference (Loc, |
| 14487 |
Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')), |
| 14488 |
Attribute_Name => Name_Unchecked_Access)); |
| 14489 |
|
| 14490 |
-- Add Chain parameter (not done for sequential elaboration policy, see |
| 14491 |
-- comment for Create_Restricted_Task_Sequential in s-tarest.ads). |
| 14492 |
|
| 14493 |
if Partition_Elaboration_Policy /= 'S' then |
| 14494 |
Append_To (Args, Make_Identifier (Loc, Name_uChain)); |
| 14495 |
end if; |
| 14496 |
|
| 14497 |
-- Task name parameter. Take this from the _Task_Id parameter to the |
| 14498 |
-- init call unless there is a Task_Name pragma, in which case we take |
| 14499 |
-- the value from the pragma. |
| 14500 |
|
| 14501 |
if Has_Rep_Pragma (Ttyp, Name_Task_Name, Check_Parents => False) then |
| 14502 |
-- Copy expression in full, because it may be dynamic and have |
| 14503 |
-- side effects. |
| 14504 |
|
| 14505 |
Append_To (Args, |
| 14506 |
New_Copy_Tree |
| 14507 |
(Expression |
| 14508 |
(First |
| 14509 |
(Pragma_Argument_Associations |
| 14510 |
(Get_Rep_Pragma |
| 14511 |
(Ttyp, Name_Task_Name, Check_Parents => False)))))); |
| 14512 |
|
| 14513 |
else |
| 14514 |
Append_To (Args, Make_Identifier (Loc, Name_uTask_Name)); |
| 14515 |
end if; |
| 14516 |
|
| 14517 |
-- Created_Task parameter. This is the _Task_Id field of the task |
| 14518 |
-- record value |
| 14519 |
|
| 14520 |
Append_To (Args, |
| 14521 |
Make_Selected_Component (Loc, |
| 14522 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 14523 |
Selector_Name => Make_Identifier (Loc, Name_uTask_Id))); |
| 14524 |
|
| 14525 |
declare |
| 14526 |
Create_RE : RE_Id; |
| 14527 |
|
| 14528 |
begin |
| 14529 |
if Restricted_Profile then |
| 14530 |
if Partition_Elaboration_Policy = 'S' then |
| 14531 |
Create_RE := RE_Create_Restricted_Task_Sequential; |
| 14532 |
else |
| 14533 |
Create_RE := RE_Create_Restricted_Task; |
| 14534 |
end if; |
| 14535 |
else |
| 14536 |
Create_RE := RE_Create_Task; |
| 14537 |
end if; |
| 14538 |
|
| 14539 |
Name := New_Occurrence_Of (RTE (Create_RE), Loc); |
| 14540 |
end; |
| 14541 |
|
| 14542 |
return |
| 14543 |
Make_Procedure_Call_Statement (Loc, |
| 14544 |
Name => Name, |
| 14545 |
Parameter_Associations => Args); |
| 14546 |
end Make_Task_Create_Call; |
| 14547 |
|
| 14548 |
--------------------------- |
| 14549 |
-- Make_Unlock_Statement -- |
| 14550 |
--------------------------- |
| 14551 |
|
| 14552 |
function Make_Unlock_Statement |
| 14553 |
(Prot_Type : E_Protected_Type_Id; |
| 14554 |
Op_Spec : N_Subprogram_Specification_Id; |
| 14555 |
Loc : Source_Ptr) return N_Procedure_Call_Statement_Id |
| 14556 |
is |
| 14557 |
Nam : constant N_Identifier_Id := |
| 14558 |
-- If the associated protected object has entries, the expanded |
| 14559 |
-- exclusive protected operation has to service entry queues. |
| 14560 |
|
| 14561 |
(if (Nkind (Op_Spec) = N_Procedure_Specification |
| 14562 |
or else |
| 14563 |
(Nkind (Op_Spec) = N_Function_Specification |
| 14564 |
and then |
| 14565 |
Has_Enabled_Aspect |
| 14566 |
(Prot_Type, Aspect_Exclusive_Functions))) |
| 14567 |
and then Has_Entries (Prot_Type) |
| 14568 |
then |
| 14569 |
(case Corresponding_Runtime_Package (Prot_Type) is |
| 14570 |
when System_Tasking_Protected_Objects_Entries => |
| 14571 |
New_Occurrence_Of (RTE (RE_Service_Entries), Loc), |
| 14572 |
|
| 14573 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 14574 |
New_Occurrence_Of (RTE (RE_Service_Entry), Loc), |
| 14575 |
|
| 14576 |
when others => |
| 14577 |
raise Program_Error) |
| 14578 |
|
| 14579 |
-- Otherwise, unlocking the protected object is sufficient. |
| 14580 |
|
| 14581 |
else |
| 14582 |
(case Corresponding_Runtime_Package (Prot_Type) is |
| 14583 |
when System_Tasking_Protected_Objects_Entries => |
| 14584 |
New_Occurrence_Of (RTE (RE_Unlock_Entries), Loc), |
| 14585 |
|
| 14586 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 14587 |
New_Occurrence_Of (RTE (RE_Unlock_Entry), Loc), |
| 14588 |
|
| 14589 |
when System_Tasking_Protected_Objects => |
| 14590 |
New_Occurrence_Of (RTE (RE_Unlock), Loc), |
| 14591 |
|
| 14592 |
when others => |
| 14593 |
raise Program_Error)); |
| 14594 |
begin |
| 14595 |
return Make_Procedure_Call_Statement |
| 14596 |
(Loc, |
| 14597 |
Name => Nam, |
| 14598 |
Parameter_Associations => |
| 14599 |
New_List ( |
| 14600 |
Make_Attribute_Reference (Loc, |
| 14601 |
Prefix => |
| 14602 |
Make_Selected_Component (Loc, |
| 14603 |
Prefix => Make_Identifier (Loc, Name_uObject), |
| 14604 |
Selector_Name => Make_Identifier (Loc, Name_uObject)), |
| 14605 |
Attribute_Name => Name_Unchecked_Access))); |
| 14606 |
end Make_Unlock_Statement; |
| 14607 |
|
| 14608 |
------------------------------ |
| 14609 |
-- Next_Protected_Operation -- |
| 14610 |
------------------------------ |
| 14611 |
|
| 14612 |
function Next_Protected_Operation (N : Node_Id) return Node_Id is |
| 14613 |
Next_Op : Node_Id; |
| 14614 |
|
| 14615 |
begin |
| 14616 |
-- Check whether there is a subsequent body for a protected operation |
| 14617 |
-- in the current protected body. In Ada2012 that includes expression |
| 14618 |
-- functions that are completions. |
| 14619 |
|
| 14620 |
Next_Op := Next (N); |
| 14621 |
while Present (Next_Op) |
| 14622 |
and then Nkind (Next_Op) not in |
| 14623 |
N_Subprogram_Body | N_Entry_Body | N_Expression_Function |
| 14624 |
loop |
| 14625 |
Next (Next_Op); |
| 14626 |
end loop; |
| 14627 |
|
| 14628 |
return Next_Op; |
| 14629 |
end Next_Protected_Operation; |
| 14630 |
|
| 14631 |
--------------------- |
| 14632 |
-- Null_Statements -- |
| 14633 |
--------------------- |
| 14634 |
|
| 14635 |
function Null_Statements (Stats : List_Id) return Boolean is |
| 14636 |
Stmt : Node_Id; |
| 14637 |
|
| 14638 |
begin |
| 14639 |
Stmt := First (Stats); |
| 14640 |
while Nkind (Stmt) /= N_Empty |
| 14641 |
and then (Nkind (Stmt) in N_Null_Statement | N_Label |
| 14642 |
or else |
| 14643 |
(Nkind (Stmt) = N_Pragma |
| 14644 |
and then |
| 14645 |
Pragma_Name_Unmapped (Stmt) in Name_Unreferenced |
| 14646 |
| Name_Unmodified |
| 14647 |
| Name_Warnings)) |
| 14648 |
loop |
| 14649 |
Next (Stmt); |
| 14650 |
end loop; |
| 14651 |
|
| 14652 |
return Nkind (Stmt) = N_Empty; |
| 14653 |
end Null_Statements; |
| 14654 |
|
| 14655 |
-------------------------- |
| 14656 |
-- Parameter_Block_Pack -- |
| 14657 |
-------------------------- |
| 14658 |
|
| 14659 |
function Parameter_Block_Pack |
| 14660 |
(Loc : Source_Ptr; |
| 14661 |
Blk_Typ : Entity_Id; |
| 14662 |
Actuals : List_Id; |
| 14663 |
Formals : List_Id; |
| 14664 |
Decls : List_Id; |
| 14665 |
Stmts : List_Id) return Entity_Id |
| 14666 |
is |
| 14667 |
Actual : Entity_Id; |
| 14668 |
Expr : Node_Id := Empty; |
| 14669 |
Formal : Entity_Id; |
| 14670 |
Has_Param : Boolean := False; |
| 14671 |
P : Entity_Id; |
| 14672 |
Params : List_Id; |
| 14673 |
Temp_Asn : Node_Id; |
| 14674 |
Temp_Nam : Node_Id; |
| 14675 |
|
| 14676 |
begin |
| 14677 |
Actual := First (Actuals); |
| 14678 |
Formal := Defining_Identifier (First (Formals)); |
| 14679 |
Params := New_List; |
| 14680 |
while Present (Actual) loop |
| 14681 |
if Is_By_Copy_Type (Etype (Actual)) then |
| 14682 |
-- Generate: |
| 14683 |
-- Jnn : aliased <formal-type> |
| 14684 |
|
| 14685 |
Temp_Nam := Make_Temporary (Loc, 'J'); |
| 14686 |
|
| 14687 |
Append_To (Decls, |
| 14688 |
Make_Object_Declaration (Loc, |
| 14689 |
Aliased_Present => True, |
| 14690 |
Defining_Identifier => Temp_Nam, |
| 14691 |
Object_Definition => |
| 14692 |
New_Occurrence_Of (Etype (Formal), Loc))); |
| 14693 |
|
| 14694 |
-- The object is initialized with an explicit assignment |
| 14695 |
-- later. Indicate that it does not need an initialization |
| 14696 |
-- to prevent spurious warnings if the type excludes null. |
| 14697 |
|
| 14698 |
Set_No_Initialization (Last (Decls)); |
| 14699 |
|
| 14700 |
if Ekind (Formal) /= E_Out_Parameter then |
| 14701 |
|
| 14702 |
-- Generate: |
| 14703 |
-- Jnn := <actual> |
| 14704 |
|
| 14705 |
Temp_Asn := |
| 14706 |
New_Occurrence_Of (Temp_Nam, Loc); |
| 14707 |
|
| 14708 |
Set_Assignment_OK (Temp_Asn); |
| 14709 |
|
| 14710 |
Append_To (Stmts, |
| 14711 |
Make_Assignment_Statement (Loc, |
| 14712 |
Name => Temp_Asn, |
| 14713 |
Expression => New_Copy_Tree (Actual))); |
| 14714 |
end if; |
| 14715 |
|
| 14716 |
-- If the actual is not controlling, generate: |
| 14717 |
|
| 14718 |
-- Jnn'unchecked_access |
| 14719 |
|
| 14720 |
-- and add it to aggegate for access to formals. Note that the |
| 14721 |
-- actual may be by-copy but still be a controlling actual if it |
| 14722 |
-- is an access to class-wide interface. |
| 14723 |
|
| 14724 |
if not Is_Controlling_Actual (Actual) then |
| 14725 |
Append_To (Params, |
| 14726 |
Make_Attribute_Reference (Loc, |
| 14727 |
Attribute_Name => Name_Unchecked_Access, |
| 14728 |
Prefix => New_Occurrence_Of (Temp_Nam, Loc))); |
| 14729 |
|
| 14730 |
Has_Param := True; |
| 14731 |
end if; |
| 14732 |
|
| 14733 |
-- The controlling parameter is omitted |
| 14734 |
|
| 14735 |
else |
| 14736 |
if not Is_Controlling_Actual (Actual) then |
| 14737 |
Append_To (Params, |
| 14738 |
Make_Reference (Loc, New_Copy_Tree (Actual))); |
| 14739 |
|
| 14740 |
Has_Param := True; |
| 14741 |
end if; |
| 14742 |
end if; |
| 14743 |
|
| 14744 |
Next_Actual (Actual); |
| 14745 |
Next_Formal_With_Extras (Formal); |
| 14746 |
end loop; |
| 14747 |
|
| 14748 |
if Has_Param then |
| 14749 |
Expr := Make_Aggregate (Loc, Params); |
| 14750 |
end if; |
| 14751 |
|
| 14752 |
-- Generate: |
| 14753 |
-- P : Ann := ( |
| 14754 |
-- J1'unchecked_access; |
| 14755 |
-- <actual2>'reference; |
| 14756 |
-- ...); |
| 14757 |
|
| 14758 |
P := Make_Temporary (Loc, 'P'); |
| 14759 |
|
| 14760 |
Append_To (Decls, |
| 14761 |
Make_Object_Declaration (Loc, |
| 14762 |
Defining_Identifier => P, |
| 14763 |
Object_Definition => New_Occurrence_Of (Blk_Typ, Loc), |
| 14764 |
Expression => Expr)); |
| 14765 |
|
| 14766 |
return P; |
| 14767 |
end Parameter_Block_Pack; |
| 14768 |
|
| 14769 |
---------------------------- |
| 14770 |
-- Parameter_Block_Unpack -- |
| 14771 |
---------------------------- |
| 14772 |
|
| 14773 |
function Parameter_Block_Unpack |
| 14774 |
(Loc : Source_Ptr; |
| 14775 |
P : Entity_Id; |
| 14776 |
Actuals : List_Id; |
| 14777 |
Formals : List_Id) return List_Id |
| 14778 |
is |
| 14779 |
Actual : Entity_Id; |
| 14780 |
Asnmt : Node_Id; |
| 14781 |
Formal : Entity_Id; |
| 14782 |
Has_Asnmt : Boolean := False; |
| 14783 |
Result : constant List_Id := New_List; |
| 14784 |
|
| 14785 |
begin |
| 14786 |
Actual := First (Actuals); |
| 14787 |
Formal := Defining_Identifier (First (Formals)); |
| 14788 |
while Present (Actual) loop |
| 14789 |
if Is_By_Copy_Type (Etype (Actual)) |
| 14790 |
and then Ekind (Formal) /= E_In_Parameter |
| 14791 |
then |
| 14792 |
-- Generate: |
| 14793 |
-- <actual> := P.<formal>; |
| 14794 |
|
| 14795 |
Asnmt := |
| 14796 |
Make_Assignment_Statement (Loc, |
| 14797 |
Name => |
| 14798 |
New_Copy (Actual), |
| 14799 |
Expression => |
| 14800 |
Make_Explicit_Dereference (Loc, |
| 14801 |
Make_Selected_Component (Loc, |
| 14802 |
Prefix => |
| 14803 |
New_Occurrence_Of (P, Loc), |
| 14804 |
Selector_Name => |
| 14805 |
Make_Identifier (Loc, Chars (Formal))))); |
| 14806 |
|
| 14807 |
Set_Assignment_OK (Name (Asnmt)); |
| 14808 |
Append_To (Result, Asnmt); |
| 14809 |
|
| 14810 |
Has_Asnmt := True; |
| 14811 |
end if; |
| 14812 |
|
| 14813 |
Next_Actual (Actual); |
| 14814 |
Next_Formal_With_Extras (Formal); |
| 14815 |
end loop; |
| 14816 |
|
| 14817 |
if Has_Asnmt then |
| 14818 |
return Result; |
| 14819 |
else |
| 14820 |
return New_List (Make_Null_Statement (Loc)); |
| 14821 |
end if; |
| 14822 |
end Parameter_Block_Unpack; |
| 14823 |
|
| 14824 |
--------------------- |
| 14825 |
-- Reset_Scopes_To -- |
| 14826 |
--------------------- |
| 14827 |
|
| 14828 |
procedure Reset_Scopes_To (Bod : Node_Id; E : Entity_Id) is |
| 14829 |
function Reset_Scope (N : Node_Id) return Traverse_Result; |
| 14830 |
-- Temporaries may have been declared during expansion of the procedure |
| 14831 |
-- created for an entry body or an accept alternative. Indicate that |
| 14832 |
-- their scope is the new body, to ensure proper generation of uplevel |
| 14833 |
-- references where needed during unnesting. |
| 14834 |
|
| 14835 |
procedure Reset_Scopes is new Traverse_Proc (Reset_Scope); |
| 14836 |
|
| 14837 |
----------------- |
| 14838 |
-- Reset_Scope -- |
| 14839 |
----------------- |
| 14840 |
|
| 14841 |
function Reset_Scope (N : Node_Id) return Traverse_Result is |
| 14842 |
Decl : Node_Id; |
| 14843 |
|
| 14844 |
begin |
| 14845 |
-- If this is a block statement with an Identifier, it forms a scope, |
| 14846 |
-- so we want to reset its scope but not look inside. |
| 14847 |
|
| 14848 |
if N /= Bod |
| 14849 |
and then Nkind (N) = N_Block_Statement |
| 14850 |
and then Present (Identifier (N)) |
| 14851 |
then |
| 14852 |
Set_Scope (Entity (Identifier (N)), E); |
| 14853 |
return Skip; |
| 14854 |
|
| 14855 |
-- Reset scope for object declaration which scope is the task entry. |
| 14856 |
-- |
| 14857 |
-- Also look inside the declaration (in particular in the expression |
| 14858 |
-- if present) because we may have expanded to something like: |
| 14859 |
|
| 14860 |
-- O1 : Typ := do |
| 14861 |
-- TMP1 : OTyp := ...; |
| 14862 |
-- ... |
| 14863 |
-- in TMP1; |
| 14864 |
|
| 14865 |
-- And the scope for TMP1 is Scope (O1). We need to look inside the |
| 14866 |
-- declaration to also reset such scope. |
| 14867 |
|
| 14868 |
elsif Nkind (N) = N_Object_Declaration then |
| 14869 |
if Present (Scope (Defining_Entity (N))) |
| 14870 |
and then Ekind (Scope (Defining_Entity (N))) |
| 14871 |
in E_Entry | E_Entry_Family |
| 14872 |
then |
| 14873 |
Set_Scope (Defining_Entity (N), E); |
| 14874 |
end if; |
| 14875 |
|
| 14876 |
-- Ditto for a package declaration or a full type declaration, etc. |
| 14877 |
|
| 14878 |
elsif (Nkind (N) = N_Package_Declaration |
| 14879 |
and then N /= Specification (N)) |
| 14880 |
or else Nkind (N) in N_Declaration |
| 14881 |
or else Nkind (N) in N_Renaming_Declaration |
| 14882 |
or else Nkind (N) in N_Implicit_Label_Declaration |
| 14883 |
then |
| 14884 |
Set_Scope (Defining_Entity (N), E); |
| 14885 |
return Skip; |
| 14886 |
|
| 14887 |
elsif N = Bod then |
| 14888 |
|
| 14889 |
-- Scan declarations in new body. Declarations in the statement |
| 14890 |
-- part will be handled during later traversal. |
| 14891 |
|
| 14892 |
Decl := First (Declarations (N)); |
| 14893 |
while Present (Decl) loop |
| 14894 |
Reset_Scopes (Decl); |
| 14895 |
Next (Decl); |
| 14896 |
end loop; |
| 14897 |
|
| 14898 |
elsif Nkind (N) = N_Freeze_Entity then |
| 14899 |
|
| 14900 |
-- Scan the actions associated with a freeze node, which may |
| 14901 |
-- actually be declarations with entities that need to have |
| 14902 |
-- their scopes reset. |
| 14903 |
|
| 14904 |
Decl := First (Actions (N)); |
| 14905 |
while Present (Decl) loop |
| 14906 |
Reset_Scopes (Decl); |
| 14907 |
Next (Decl); |
| 14908 |
end loop; |
| 14909 |
|
| 14910 |
elsif N /= Bod and then Nkind (N) in N_Proper_Body then |
| 14911 |
|
| 14912 |
-- A subprogram without a separate declaration may be encountered, |
| 14913 |
-- and we need to reset the subprogram's entity's scope. |
| 14914 |
|
| 14915 |
if Nkind (N) = N_Subprogram_Body then |
| 14916 |
Set_Scope (Defining_Entity (Specification (N)), E); |
| 14917 |
end if; |
| 14918 |
|
| 14919 |
return Skip; |
| 14920 |
end if; |
| 14921 |
|
| 14922 |
return OK; |
| 14923 |
end Reset_Scope; |
| 14924 |
|
| 14925 |
-- Start of processing for Reset_Scopes_To |
| 14926 |
|
| 14927 |
begin |
| 14928 |
Reset_Scopes (Bod); |
| 14929 |
end Reset_Scopes_To; |
| 14930 |
|
| 14931 |
---------------------- |
| 14932 |
-- Set_Discriminals -- |
| 14933 |
---------------------- |
| 14934 |
|
| 14935 |
procedure Set_Discriminals (Dec : Node_Id) is |
| 14936 |
D : Entity_Id; |
| 14937 |
Pdef : Entity_Id; |
| 14938 |
D_Minal : Entity_Id; |
| 14939 |
|
| 14940 |
begin |
| 14941 |
pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration); |
| 14942 |
Pdef := Defining_Identifier (Dec); |
| 14943 |
|
| 14944 |
if Has_Discriminants (Pdef) then |
| 14945 |
D := First_Discriminant (Pdef); |
| 14946 |
while Present (D) loop |
| 14947 |
D_Minal := |
| 14948 |
Make_Defining_Identifier (Sloc (D), |
| 14949 |
Chars => New_External_Name (Chars (D), 'D')); |
| 14950 |
|
| 14951 |
Mutate_Ekind (D_Minal, E_Constant); |
| 14952 |
Set_Etype (D_Minal, Etype (D)); |
| 14953 |
Set_Scope (D_Minal, Pdef); |
| 14954 |
Set_Discriminal (D, D_Minal); |
| 14955 |
Set_Discriminal_Link (D_Minal, D); |
| 14956 |
|
| 14957 |
Next_Discriminant (D); |
| 14958 |
end loop; |
| 14959 |
end if; |
| 14960 |
end Set_Discriminals; |
| 14961 |
|
| 14962 |
----------------------- |
| 14963 |
-- Trivial_Accept_OK -- |
| 14964 |
----------------------- |
| 14965 |
|
| 14966 |
function Trivial_Accept_OK return Boolean is |
| 14967 |
begin |
| 14968 |
case Opt.Task_Dispatching_Policy is |
| 14969 |
|
| 14970 |
-- If we have the default task dispatching policy in effect, we can |
| 14971 |
-- definitely do the optimization (one way of looking at this is to |
| 14972 |
-- think of the formal definition of the default policy being allowed |
| 14973 |
-- to run any task it likes after a rendezvous, so even if notionally |
| 14974 |
-- a full rescheduling occurs, we can say that our dispatching policy |
| 14975 |
-- (i.e. the default dispatching policy) reorders the queue to be the |
| 14976 |
-- same as just before the call. |
| 14977 |
|
| 14978 |
when ' ' => |
| 14979 |
return True; |
| 14980 |
|
| 14981 |
-- FIFO_Within_Priorities certainly does not permit this |
| 14982 |
-- optimization since the Rendezvous is a scheduling action that may |
| 14983 |
-- require some other task to be run. |
| 14984 |
|
| 14985 |
when 'F' => |
| 14986 |
return False; |
| 14987 |
|
| 14988 |
-- For now, disallow the optimization for all other policies. This |
| 14989 |
-- may be over-conservative, but it is certainly not incorrect. |
| 14990 |
|
| 14991 |
when others => |
| 14992 |
return False; |
| 14993 |
end case; |
| 14994 |
end Trivial_Accept_OK; |
| 14995 |
|
| 14996 |
--------------------------- |
| 14997 |
-- Wrap_Unprotected_Call -- |
| 14998 |
--------------------------- |
| 14999 |
|
| 15000 |
function Wrap_Unprotected_Call |
| 15001 |
(Call : Node_Id; |
| 15002 |
Prot_Type : E_Protected_Type_Id; |
| 15003 |
Op_Spec : N_Subprogram_Specification_Id; |
| 15004 |
Loc : Source_Ptr) return N_Block_Statement_Id |
| 15005 |
is |
| 15006 |
Body_Id : constant N_Defining_Identifier_Id := |
| 15007 |
Make_Defining_Identifier (Loc, Name_Find ("_unlock")); |
| 15008 |
|
| 15009 |
Unlock_Body : constant N_Subprogram_Body_Id := |
| 15010 |
Make_Subprogram_Body |
| 15011 |
(Loc, |
| 15012 |
Specification => |
| 15013 |
Make_Procedure_Specification (Loc, Defining_Unit_Name => Body_Id), |
| 15014 |
Handled_Statement_Sequence => |
| 15015 |
Make_Handled_Sequence_Of_Statements |
| 15016 |
(Loc, Statements => New_List |
| 15017 |
(Make_Unlock_Statement (Prot_Type, Op_Spec, Loc)))); |
| 15018 |
|
| 15019 |
Decls : constant List_Id := New_List (Unlock_Body); |
| 15020 |
|
| 15021 |
HSS : constant N_Handled_Sequence_Of_Statements_Id := |
| 15022 |
Make_Handled_Sequence_Of_Statements |
| 15023 |
(Loc, Statements => New_List (Call), |
| 15024 |
At_End_Proc => New_Occurrence_Of (Body_Id, Loc)); |
| 15025 |
|
| 15026 |
Block_Statement : constant N_Block_Statement_Id := |
| 15027 |
Make_Block_Statement |
| 15028 |
(Loc, Declarations => Decls, |
| 15029 |
Handled_Statement_Sequence => |
| 15030 |
HSS); |
| 15031 |
|
| 15032 |
begin |
| 15033 |
if Debug_Generated_Code then |
| 15034 |
Set_Debug_Info_Needed (Body_Id); |
| 15035 |
end if; |
| 15036 |
|
| 15037 |
Set_Acts_As_Spec (Unlock_Body); |
| 15038 |
|
| 15039 |
return Block_Statement; |
| 15040 |
end Wrap_Unprotected_Call; |
| 15041 |
end Exp_Ch9; |