Debian Codegraph @

gcc/ada/exp_dist.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P_ D I S T --
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 Atree; use Atree;
27 with Einfo; use Einfo;
28 with Einfo.Entities; use Einfo.Entities;
29 with Einfo.Utils; use Einfo.Utils;
30 with Elists; use Elists;
31 with Exp_Atag; use Exp_Atag;
32 with Exp_Strm; use Exp_Strm;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
35 with Lib; use Lib;
36 with Nlists; use Nlists;
37 with Nmake; use Nmake;
38 with Opt; use Opt;
39 with Rtsfind; use Rtsfind;
40 with Sem; use Sem;
41 with Sem_Aux; use Sem_Aux;
42 with Sem_Cat; use Sem_Cat;
43 with Sem_Ch3; use Sem_Ch3;
44 with Sem_Ch8; use Sem_Ch8;
45 with Sem_Ch12; use Sem_Ch12;
46 with Sem_Dist; use Sem_Dist;
47 with Sem_Eval; use Sem_Eval;
48 with Sem_Util; use Sem_Util;
49 with Sinfo; use Sinfo;
50 with Sinfo.Nodes; use Sinfo.Nodes;
51 with Sinfo.Utils; use Sinfo.Utils;
52 with Stand; use Stand;
53 with Stringt; use Stringt;
54 with Tbuild; use Tbuild;
55 with Ttypes; use Ttypes;
56 with Uintp; use Uintp;
57
58 with GNAT.HTable; use GNAT.HTable;
59
60 package body Exp_Dist is
61
62 -- The following model has been used to implement distributed objects:
63 -- given a designated type D and a RACW type R, then a record of the form:
64
65 -- type Stub is tagged record
66 -- [...declaration similar to s-parint.ads RACW_Stub_Type...]
67 -- end record;
68
69 -- is built. This type has two properties:
70
71 -- 1) Since it has the same structure as RACW_Stub_Type, it can
72 -- be converted to and from this type to make it suitable for
73 -- System.Partition_Interface.Get_Unique_Remote_Pointer in order
74 -- to avoid memory leaks when the same remote object arrives on the
75 -- same partition through several paths;
76
77 -- 2) It also has the same dispatching table as the designated type D,
78 -- and thus can be used as an object designated by a value of type
79 -- R on any partition other than the one on which the object has
80 -- been created, since only dispatching calls will be performed and
81 -- the fields themselves will not be used. We call Derive_Subprograms
82 -- to fake half a derivation to ensure that the subprograms do have
83 -- the same dispatching table.
84
85 First_RCI_Subprogram_Id : constant := 2;
86 -- RCI subprograms are numbered starting at 2. The RCI receiver for
87 -- an RCI package can thus identify calls received through remote
88 -- access-to-subprogram dereferences by the fact that they have a
89 -- (primitive) subprogram id of 0, and 1 is used for the internal RAS
90 -- information lookup operation. (This is for the Garlic code generation,
91 -- where subprograms are identified by numbers; in the PolyORB version,
92 -- they are identified by name, with a numeric suffix for homonyms.)
93
94 type Hash_Index is range 0 .. 50;
95
96 -----------------------
97 -- Local subprograms --
98 -----------------------
99
100 function Hash (F : Entity_Id) return Hash_Index;
101 -- DSA expansion associates stubs to distributed object types using a hash
102 -- table on entity ids.
103
104 function Hash (F : Name_Id) return Hash_Index;
105 -- The generation of subprogram identifiers requires an overload counter
106 -- to be associated with each remote subprogram name. These counters are
107 -- maintained in a hash table on name ids.
108
109 type Subprogram_Identifiers is record
110 Str_Identifier : String_Id;
111 Int_Identifier : Int;
112 end record;
113
114 package Subprogram_Identifier_Table is
115 new Simple_HTable (Header_Num => Hash_Index,
116 Element => Subprogram_Identifiers,
117 No_Element => (No_String, 0),
118 Key => Entity_Id,
119 Hash => Hash,
120 Equal => "=");
121 -- Mapping between a remote subprogram and the corresponding subprogram
122 -- identifiers.
123
124 package Overload_Counter_Table is
125 new Simple_HTable (Header_Num => Hash_Index,
126 Element => Int,
127 No_Element => 0,
128 Key => Name_Id,
129 Hash => Hash,
130 Equal => "=");
131 -- Mapping between a subprogram name and an integer that counts the number
132 -- of defining subprogram names with that Name_Id encountered so far in a
133 -- given context (an interface).
134
135 function Get_Subprogram_Ids (Def : Entity_Id) return Subprogram_Identifiers;
136 function Get_Subprogram_Id (Def : Entity_Id) return String_Id;
137 function Get_Subprogram_Id (Def : Entity_Id) return Int;
138 -- Given a subprogram defined in a RCI package, get its distribution
139 -- subprogram identifiers (the distribution identifiers are a unique
140 -- subprogram number, and the non-qualified subprogram name, in the
141 -- casing used for the subprogram declaration; if the name is overloaded,
142 -- a double underscore and a serial number are appended.
143 --
144 -- The integer identifier is used to perform remote calls with GARLIC;
145 -- the string identifier is used in the case of PolyORB.
146 --
147 -- Although the PolyORB DSA receiving stubs will make a caseless comparison
148 -- when receiving a call, the calling stubs will create requests with the
149 -- exact casing of the defining unit name of the called subprogram, so as
150 -- to allow calls to subprograms on distributed nodes that do distinguish
151 -- between casings.
152 --
153 -- NOTE: Another design would be to allow a representation clause on
154 -- subprogram specs: for Subp'Distribution_Identifier use "fooBar";
155
156 pragma Warnings (Off, Get_Subprogram_Id);
157 -- One homonym only is unreferenced (specific to the GARLIC version)
158
159 procedure Add_RAS_Dereference_TSS (N : Node_Id);
160 -- Add a subprogram body for RAS Dereference TSS
161
162 procedure Add_RAS_Proxy_And_Analyze
163 (Decls : List_Id;
164 Vis_Decl : Node_Id;
165 All_Calls_Remote_E : Entity_Id;
166 Proxy_Object_Addr : out Entity_Id);
167 -- Add the proxy type required, on the receiving (server) side, to handle
168 -- calls to the subprogram declared by Vis_Decl through a remote access
169 -- to subprogram type. All_Calls_Remote_E must be Standard_True if a pragma
170 -- All_Calls_Remote applies, Standard_False otherwise. The new proxy type
171 -- is appended to Decls. Proxy_Object_Addr is a constant of type
172 -- System.Address that designates an instance of the proxy object.
173
174 function Build_Remote_Subprogram_Proxy_Type
175 (Loc : Source_Ptr;
176 ACR_Expression : Node_Id) return Node_Id;
177 -- Build and return a tagged record type definition for an RCI subprogram
178 -- proxy type. ACR_Expression is used as the initialization value for the
179 -- All_Calls_Remote component.
180
181 function Build_Get_Unique_RP_Call
182 (Loc : Source_Ptr;
183 Pointer : Entity_Id;
184 Stub_Type : Entity_Id) return List_Id;
185 -- Build a call to Get_Unique_Remote_Pointer (Pointer), followed by a
186 -- tag fixup (Get_Unique_Remote_Pointer may have changed Pointer'Tag to
187 -- RACW_Stub_Type'Tag, while the desired tag is that of Stub_Type).
188
189 function Build_Stub_Tag
190 (Loc : Source_Ptr;
191 RACW_Type : Entity_Id) return Node_Id;
192 -- Return an expression denoting the tag of the stub type associated with
193 -- RACW_Type.
194
195 function Build_Subprogram_Calling_Stubs
196 (Vis_Decl : Node_Id;
197 Subp_Id : Node_Id;
198 Asynchronous : Boolean;
199 Dynamically_Asynchronous : Boolean := False;
200 Stub_Type : Entity_Id := Empty;
201 RACW_Type : Entity_Id := Empty;
202 Locator : Entity_Id := Empty;
203 New_Name : Name_Id := No_Name) return Node_Id;
204 -- Build the calling stub for a given subprogram with the subprogram ID
205 -- being Subp_Id. If Stub_Type is given, then the "addr" field of
206 -- parameters of this type will be marshalled instead of the object itself.
207 -- It will then be converted into Stub_Type before performing the real
208 -- call. If Dynamically_Asynchronous is True, then it will be computed at
209 -- run time whether the call is asynchronous or not. Otherwise, the value
210 -- of the formal Asynchronous will be used. If Locator is not Empty, it
211 -- will be used instead of RCI_Cache. If New_Name is given, then it will
212 -- be used instead of the original name.
213
214 function Build_RPC_Receiver_Specification
215 (RPC_Receiver : Entity_Id;
216 Request_Parameter : Entity_Id) return Node_Id;
217 -- Make a subprogram specification for an RPC receiver, with the given
218 -- defining unit name and formal parameter.
219
220 function Build_Ordered_Parameters_List (Spec : Node_Id) return List_Id;
221 -- Return an ordered parameter list: unconstrained parameters are put
222 -- at the beginning of the list and constrained ones are put after. If
223 -- there are no parameters, an empty list is returned. Special case:
224 -- the controlling formal of the equivalent RACW operation for a RAS
225 -- type is always left in first position.
226
227 function Transmit_As_Unconstrained (Typ : Entity_Id) return Boolean;
228 -- True when Typ is an unconstrained type, or a null-excluding access type.
229 -- In either case, this means stubs cannot contain a default-initialized
230 -- object declaration of such type.
231
232 procedure Add_Calling_Stubs_To_Declarations (Pkg_Spec : Node_Id);
233 -- Add calling stubs to the declarative part
234
235 function Could_Be_Asynchronous (Spec : Node_Id) return Boolean;
236 -- Return True if nothing prevents the program whose specification is
237 -- given to be asynchronous (i.e. no [IN] OUT parameters).
238
239 function Pack_Entity_Into_Stream_Access
240 (Loc : Source_Ptr;
241 Stream : Node_Id;
242 Object : Entity_Id;
243 Etyp : Entity_Id := Empty) return Node_Id;
244 -- Pack Object (of type Etyp) into Stream. If Etyp is not given,
245 -- then Etype (Object) will be used if present. If the type is
246 -- constrained, then 'Write will be used to output the object,
247 -- If the type is unconstrained, 'Output will be used.
248
249 function Pack_Node_Into_Stream
250 (Loc : Source_Ptr;
251 Stream : Entity_Id;
252 Object : Node_Id;
253 Etyp : Entity_Id) return Node_Id;
254 -- Similar to above, with an arbitrary node instead of an entity
255
256 function Pack_Node_Into_Stream_Access
257 (Loc : Source_Ptr;
258 Stream : Node_Id;
259 Object : Node_Id;
260 Etyp : Entity_Id) return Node_Id;
261 -- Similar to above, with Stream instead of Stream'Access
262
263 function Make_Selected_Component
264 (Loc : Source_Ptr;
265 Prefix : Entity_Id;
266 Selector_Name : Name_Id) return Node_Id;
267 -- Return a selected_component whose prefix denotes the given entity, and
268 -- with the given Selector_Name.
269
270 function Scope_Of_Spec (Spec : Node_Id) return Entity_Id;
271 -- Return the scope represented by a given spec
272
273 procedure Set_Renaming_TSS
274 (Typ : Entity_Id;
275 Nam : Entity_Id;
276 TSS_Nam : TSS_Name_Type);
277 -- Create a renaming declaration of subprogram Nam, and register it as a
278 -- TSS for Typ with name TSS_Nam.
279
280 function Need_Extra_Constrained (Parameter : Node_Id) return Boolean;
281 -- Return True if the current parameter needs an extra formal to reflect
282 -- its constrained status.
283
284 function Is_RACW_Controlling_Formal
285 (Parameter : Node_Id;
286 Stub_Type : Entity_Id) return Boolean;
287 -- Return True if the current parameter is a controlling formal argument
288 -- of type Stub_Type or access to Stub_Type.
289
290 procedure Declare_Create_NVList
291 (Loc : Source_Ptr;
292 NVList : Entity_Id;
293 Decls : List_Id;
294 Stmts : List_Id);
295 -- Append the declaration of NVList to Decls, and its
296 -- initialization to Stmts.
297
298 function Add_Parameter_To_NVList
299 (Loc : Source_Ptr;
300 NVList : Entity_Id;
301 Parameter : Entity_Id;
302 Constrained : Boolean;
303 Any : Entity_Id) return Node_Id;
304 -- Return a call to Add_Item to add the Any corresponding to the designated
305 -- formal Parameter (with the indicated Constrained status) to NVList.
306
307 --------------------
308 -- Stub_Structure --
309 --------------------
310
311 -- This record describes various tree fragments associated with the
312 -- generation of RACW calling stubs. One such record exists for every
313 -- distributed object type, i.e. each tagged type that is the designated
314 -- type of one or more RACW type.
315
316 type Stub_Structure is record
317 Stub_Type : Entity_Id;
318 -- Stub type: this type has the same primitive operations as the
319 -- designated types, but the provided bodies for these operations
320 -- a remote call to an actual target object potentially located on
321 -- another partition; each value of the stub type encapsulates a
322 -- reference to a remote object.
323
324 Stub_Type_Access : Entity_Id;
325 -- A local access type designating the stub type (this is not an RACW
326 -- type).
327
328 RPC_Receiver_Decl : Node_Id;
329 -- Declaration for the RPC receiver entity associated with the
330 -- designated type. As an exception, in the case of GARLIC, for an RACW
331 -- that implements a RAS, no object RPC receiver is generated. Instead,
332 -- RPC_Receiver_Decl is the declaration after which the RPC receiver
333 -- would have been inserted.
334
335 Body_Decls : List_Id;
336 -- List of subprogram bodies to be included in generated code: bodies
337 -- for the RACW's stream attributes, and for the primitive operations
338 -- of the stub type.
339
340 RACW_Type : Entity_Id;
341 -- One of the RACW types designating this distributed object type
342 -- (they are all interchangeable; we use any one of them in order to
343 -- avoid having to create various anonymous access types).
344
345 end record;
346
347 Empty_Stub_Structure : constant Stub_Structure :=
348 (Empty, Empty, Empty, No_List, Empty);
349
350 package Stubs_Table is
351 new Simple_HTable (Header_Num => Hash_Index,
352 Element => Stub_Structure,
353 No_Element => Empty_Stub_Structure,
354 Key => Entity_Id,
355 Hash => Hash,
356 Equal => "=");
357 -- Mapping between a RACW designated type and its stub type
358
359 package Asynchronous_Flags_Table is
360 new Simple_HTable (Header_Num => Hash_Index,
361 Element => Entity_Id,
362 No_Element => Empty,
363 Key => Entity_Id,
364 Hash => Hash,
365 Equal => "=");
366 -- Mapping between a RACW type and a constant having the value True
367 -- if the RACW is asynchronous and False otherwise.
368
369 package RCI_Locator_Table is
370 new Simple_HTable (Header_Num => Hash_Index,
371 Element => Entity_Id,
372 No_Element => Empty,
373 Key => Entity_Id,
374 Hash => Hash,
375 Equal => "=");
376 -- Mapping between a RCI package on which All_Calls_Remote applies and
377 -- the generic instantiation of RCI_Locator for this package.
378
379 package RCI_Calling_Stubs_Table is
380 new Simple_HTable (Header_Num => Hash_Index,
381 Element => Entity_Id,
382 No_Element => Empty,
383 Key => Entity_Id,
384 Hash => Hash,
385 Equal => "=");
386 -- Mapping between a RCI subprogram and the corresponding calling stubs
387
388 function Get_Stub_Elements (RACW_Type : Entity_Id) return Stub_Structure;
389 -- Return the stub information associated with the given RACW type
390
391 procedure Add_Stub_Type
392 (Designated_Type : Entity_Id;
393 RACW_Type : Entity_Id;
394 Decls : List_Id;
395 Stub_Type : out Entity_Id;
396 Stub_Type_Access : out Entity_Id;
397 RPC_Receiver_Decl : out Node_Id;
398 Body_Decls : out List_Id;
399 Existing : out Boolean);
400 -- Add the declaration of the stub type, the access to stub type and the
401 -- object RPC receiver at the end of Decls. If these already exist,
402 -- then nothing is added in the tree but the right values are returned
403 -- anyhow and Existing is set to True.
404
405 function Get_And_Reset_RACW_Bodies (RACW_Type : Entity_Id) return List_Id;
406 -- Retrieve the Body_Decls list associated to RACW_Type in the stub
407 -- structure table, reset it to No_List, and return the previous value.
408
409 procedure Add_RACW_Asynchronous_Flag
410 (Declarations : List_Id;
411 RACW_Type : Entity_Id);
412 -- Declare a boolean constant associated with RACW_Type whose value
413 -- indicates at run time whether a pragma Asynchronous applies to it.
414
415 procedure Assign_Subprogram_Identifier
416 (Def : Entity_Id;
417 Spn : Int;
418 Id : out String_Id);
419 -- Determine the distribution subprogram identifier to
420 -- be used for remote subprogram Def, return it in Id and
421 -- store it in a hash table for later retrieval by
422 -- Get_Subprogram_Id. Spn is the subprogram number.
423
424 function RCI_Package_Locator
425 (Loc : Source_Ptr;
426 Package_Spec : Node_Id) return Node_Id;
427 -- Instantiate the generic package RCI_Locator in order to locate the
428 -- RCI package whose spec is given as argument.
429
430 function Make_Tag_Check (Loc : Source_Ptr; N : Node_Id) return Node_Id;
431 -- Surround a node N by a tag check, as in:
432 -- begin
433 -- <N>;
434 -- exception
435 -- when E : Ada.Tags.Tag_Error =>
436 -- Raise_Exception (Program_Error'Identity,
437 -- Exception_Message (E));
438 -- end;
439
440 function Input_With_Tag_Check
441 (Loc : Source_Ptr;
442 Var_Type : Entity_Id;
443 Stream : Node_Id) return Node_Id;
444 -- Return a function with the following form:
445 -- function R return Var_Type is
446 -- begin
447 -- return Var_Type'Input (S);
448 -- exception
449 -- when E : Ada.Tags.Tag_Error =>
450 -- Raise_Exception (Program_Error'Identity,
451 -- Exception_Message (E));
452 -- end R;
453
454 procedure Build_Actual_Object_Declaration
455 (Object : Entity_Id;
456 Etyp : Entity_Id;
457 Variable : Boolean;
458 Expr : Node_Id;
459 Decls : List_Id);
460 -- Build the declaration of an object with the given defining identifier,
461 -- initialized with Expr if provided, to serve as actual parameter in a
462 -- server stub. If Variable is true, the declared object will be a variable
463 -- (case of an out or in out formal), else it will be a constant. Object's
464 -- Ekind is set accordingly. The declaration, as well as any other
465 -- declarations it requires, are appended to Decls.
466
467 --------------------------------------------
468 -- Hooks for PCS-specific code generation --
469 --------------------------------------------
470
471 -- Part of the code generation circuitry for distribution needs to be
472 -- tailored for each implementation of the PCS. For each routine that
473 -- needs to be specialized, a Specific_<routine> wrapper is created,
474 -- which calls the corresponding <routine> in package
475 -- <pcs_implementation>_Support.
476
477 procedure Specific_Add_RACW_Features
478 (RACW_Type : Entity_Id;
479 Desig : Entity_Id;
480 Stub_Type : Entity_Id;
481 Stub_Type_Access : Entity_Id;
482 RPC_Receiver_Decl : Node_Id;
483 Body_Decls : List_Id);
484 -- Add declaration for TSSs for a given RACW type. The declarations are
485 -- added just after the declaration of the RACW type itself. If the RACW
486 -- appears in the main unit, Body_Decls is a list of declarations to which
487 -- the bodies are appended. Else Body_Decls is No_List.
488 -- PCS-specific ancillary subprogram for Add_RACW_Features.
489
490 procedure Specific_Add_RAST_Features
491 (Vis_Decl : Node_Id;
492 RAS_Type : Entity_Id);
493 -- Add declaration for TSSs for a given RAS type. PCS-specific ancillary
494 -- subprogram for Add_RAST_Features.
495
496 -- An RPC_Target record is used during construction of calling stubs
497 -- to pass PCS-specific tree fragments corresponding to the information
498 -- necessary to locate the target of a remote subprogram call.
499
500 type RPC_Target (PCS_Kind : PCS_Names) is record
501 case PCS_Kind is
502 when Name_PolyORB_DSA =>
503 Object : Node_Id;
504 -- An expression whose value is a PolyORB reference to the target
505 -- object.
506
507 when others =>
508 Partition : Entity_Id;
509 -- A variable containing the Partition_ID of the target partition
510
511 RPC_Receiver : Node_Id;
512 -- An expression whose value is the address of the target RPC
513 -- receiver.
514 end case;
515 end record;
516
517 procedure Specific_Build_General_Calling_Stubs
518 (Decls : List_Id;
519 Statements : List_Id;
520 Target : RPC_Target;
521 Subprogram_Id : Node_Id;
522 Asynchronous : Node_Id := Empty;
523 Is_Known_Asynchronous : Boolean := False;
524 Is_Known_Non_Asynchronous : Boolean := False;
525 Is_Function : Boolean;
526 Spec : Node_Id;
527 Stub_Type : Entity_Id := Empty;
528 RACW_Type : Entity_Id := Empty;
529 Nod : Node_Id);
530 -- Build calling stubs for general purpose. The parameters are:
531 -- Decls : A place to put declarations
532 -- Statements : A place to put statements
533 -- Target : PCS-specific target information (see details in
534 -- RPC_Target declaration).
535 -- Subprogram_Id : A node containing the subprogram ID
536 -- Asynchronous : True if an APC must be made instead of an RPC.
537 -- The value needs not be supplied if one of the
538 -- Is_Known_... is True.
539 -- Is_Known_Async... : True if we know that this is asynchronous
540 -- Is_Known_Non_A... : True if we know that this is not asynchronous
541 -- Spec : Node with a Parameter_Specifications and a
542 -- Result_Definition if applicable
543 -- Stub_Type : For case of RACW stubs, parameters of type access
544 -- to Stub_Type will be marshalled using the address
545 -- address of the object (the addr field) rather
546 -- than using the 'Write on the stub itself
547 -- Nod : Used to provide sloc for generated code
548
549 function Specific_Build_Stub_Target
550 (Loc : Source_Ptr;
551 Decls : List_Id;
552 RCI_Locator : Entity_Id;
553 Controlling_Parameter : Entity_Id) return RPC_Target;
554 -- Build call target information nodes for use within calling stubs. In the
555 -- RCI case, RCI_Locator is the entity for the instance of RCI_Locator. If
556 -- for an RACW, Controlling_Parameter is the entity for the controlling
557 -- formal parameter used to determine the location of the target of the
558 -- call. Decls provides a location where variable declarations can be
559 -- appended to construct the necessary values.
560
561 function Specific_RPC_Receiver_Decl
562 (RACW_Type : Entity_Id) return Node_Id;
563 -- Build the RPC receiver, for RACW, if applicable, else return Empty
564
565 procedure Specific_Build_RPC_Receiver_Body
566 (RPC_Receiver : Entity_Id;
567 Request : out Entity_Id;
568 Subp_Id : out Entity_Id;
569 Subp_Index : out Entity_Id;
570 Stmts : out List_Id;
571 Decl : out Node_Id);
572 -- Make a subprogram body for an RPC receiver, with the given
573 -- defining unit name. On return:
574 -- - Subp_Id is the subprogram identifier from the PCS.
575 -- - Subp_Index is the index in the list of subprograms
576 -- used for dispatching (a variable of type Subprogram_Id).
577 -- - Stmts is the place where the request dispatching
578 -- statements can occur,
579 -- - Decl is the subprogram body declaration.
580
581 function Specific_Build_Subprogram_Receiving_Stubs
582 (Vis_Decl : Node_Id;
583 Asynchronous : Boolean;
584 Dynamically_Asynchronous : Boolean := False;
585 Stub_Type : Entity_Id := Empty;
586 RACW_Type : Entity_Id := Empty;
587 Parent_Primitive : Entity_Id := Empty) return Node_Id;
588 -- Build the receiving stub for a given subprogram. The subprogram
589 -- declaration is also built by this procedure, and the value returned
590 -- is a N_Subprogram_Body. If a parameter of type access to Stub_Type is
591 -- found in the specification, then its address is read from the stream
592 -- instead of the object itself and converted into an access to
593 -- class-wide type before doing the real call using any of the RACW type
594 -- pointing on the designated type.
595
596 procedure Specific_Add_Obj_RPC_Receiver_Completion
597 (Loc : Source_Ptr;
598 Decls : List_Id;
599 RPC_Receiver : Entity_Id;
600 Stub_Elements : Stub_Structure);
601 -- Add the necessary code to Decls after the completion of generation
602 -- of the RACW RPC receiver described by Stub_Elements.
603
604 procedure Specific_Add_Receiving_Stubs_To_Declarations
605 (Pkg_Spec : Node_Id;
606 Decls : List_Id;
607 Stmts : List_Id);
608 -- Add receiving stubs to the declarative part of an RCI unit
609
610 --------------------
611 -- GARLIC_Support --
612 --------------------
613
614 package GARLIC_Support is
615
616 -- Support for generating DSA code that uses the GARLIC PCS
617
618 -- The subprograms below provide the GARLIC versions of the
619 -- corresponding Specific_<subprogram> routine declared above.
620
621 procedure Add_RACW_Features
622 (RACW_Type : Entity_Id;
623 Stub_Type : Entity_Id;
624 Stub_Type_Access : Entity_Id;
625 RPC_Receiver_Decl : Node_Id;
626 Body_Decls : List_Id);
627
628 procedure Add_RAST_Features
629 (Vis_Decl : Node_Id;
630 RAS_Type : Entity_Id);
631
632 procedure Build_General_Calling_Stubs
633 (Decls : List_Id;
634 Statements : List_Id;
635 Target_Partition : Entity_Id; -- From RPC_Target
636 Target_RPC_Receiver : Node_Id; -- From RPC_Target
637 Subprogram_Id : Node_Id;
638 Asynchronous : Node_Id := Empty;
639 Is_Known_Asynchronous : Boolean := False;
640 Is_Known_Non_Asynchronous : Boolean := False;
641 Is_Function : Boolean;
642 Spec : Node_Id;
643 Stub_Type : Entity_Id := Empty;
644 RACW_Type : Entity_Id := Empty;
645 Nod : Node_Id);
646
647 function Build_Stub_Target
648 (Loc : Source_Ptr;
649 Decls : List_Id;
650 RCI_Locator : Entity_Id;
651 Controlling_Parameter : Entity_Id) return RPC_Target;
652
653 function RPC_Receiver_Decl (RACW_Type : Entity_Id) return Node_Id;
654
655 function Build_Subprogram_Receiving_Stubs
656 (Vis_Decl : Node_Id;
657 Asynchronous : Boolean;
658 Dynamically_Asynchronous : Boolean := False;
659 Stub_Type : Entity_Id := Empty;
660 RACW_Type : Entity_Id := Empty;
661 Parent_Primitive : Entity_Id := Empty) return Node_Id;
662
663 procedure Add_Obj_RPC_Receiver_Completion
664 (Loc : Source_Ptr;
665 Decls : List_Id;
666 RPC_Receiver : Entity_Id;
667 Stub_Elements : Stub_Structure);
668
669 procedure Add_Receiving_Stubs_To_Declarations
670 (Pkg_Spec : Node_Id;
671 Decls : List_Id;
672 Stmts : List_Id);
673
674 procedure Build_RPC_Receiver_Body
675 (RPC_Receiver : Entity_Id;
676 Request : out Entity_Id;
677 Subp_Id : out Entity_Id;
678 Subp_Index : out Entity_Id;
679 Stmts : out List_Id;
680 Decl : out Node_Id);
681
682 end GARLIC_Support;
683
684 ---------------------
685 -- PolyORB_Support --
686 ---------------------
687
688 package PolyORB_Support is
689
690 -- Support for generating DSA code that uses the PolyORB PCS
691
692 -- The subprograms below provide the PolyORB versions of the
693 -- corresponding Specific_<subprogram> routine declared above.
694
695 procedure Add_RACW_Features
696 (RACW_Type : Entity_Id;
697 Desig : Entity_Id;
698 Stub_Type : Entity_Id;
699 Stub_Type_Access : Entity_Id;
700 RPC_Receiver_Decl : Node_Id;
701 Body_Decls : List_Id);
702
703 procedure Add_RAST_Features
704 (Vis_Decl : Node_Id;
705 RAS_Type : Entity_Id);
706
707 procedure Build_General_Calling_Stubs
708 (Decls : List_Id;
709 Statements : List_Id;
710 Target_Object : Node_Id; -- From RPC_Target
711 Subprogram_Id : Node_Id;
712 Asynchronous : Node_Id := Empty;
713 Is_Known_Asynchronous : Boolean := False;
714 Is_Known_Non_Asynchronous : Boolean := False;
715 Is_Function : Boolean;
716 Spec : Node_Id;
717 Stub_Type : Entity_Id := Empty;
718 RACW_Type : Entity_Id := Empty;
719 Nod : Node_Id);
720
721 function Build_Stub_Target
722 (Loc : Source_Ptr;
723 Decls : List_Id;
724 RCI_Locator : Entity_Id;
725 Controlling_Parameter : Entity_Id) return RPC_Target;
726
727 function RPC_Receiver_Decl (RACW_Type : Entity_Id) return Node_Id;
728
729 function Build_Subprogram_Receiving_Stubs
730 (Vis_Decl : Node_Id;
731 Asynchronous : Boolean;
732 Dynamically_Asynchronous : Boolean := False;
733 Stub_Type : Entity_Id := Empty;
734 RACW_Type : Entity_Id := Empty;
735 Parent_Primitive : Entity_Id := Empty) return Node_Id;
736
737 procedure Add_Obj_RPC_Receiver_Completion
738 (Loc : Source_Ptr;
739 Decls : List_Id;
740 RPC_Receiver : Entity_Id;
741 Stub_Elements : Stub_Structure);
742
743 procedure Add_Receiving_Stubs_To_Declarations
744 (Pkg_Spec : Node_Id;
745 Decls : List_Id;
746 Stmts : List_Id);
747
748 procedure Build_RPC_Receiver_Body
749 (RPC_Receiver : Entity_Id;
750 Request : out Entity_Id;
751 Subp_Id : out Entity_Id;
752 Subp_Index : out Entity_Id;
753 Stmts : out List_Id;
754 Decl : out Node_Id);
755
756 procedure Reserve_NamingContext_Methods;
757 -- Mark the method names for interface NamingContext as already used in
758 -- the overload table, so no clashes occur with user code (with the
759 -- PolyORB PCS, RCIs Implement The NamingContext interface to allow
760 -- their methods to be accessed as objects, for the implementation of
761 -- remote access-to-subprogram types).
762
763 -------------
764 -- Helpers --
765 -------------
766
767 package Helpers is
768
769 -- Routines to build distribution helper subprograms for user-defined
770 -- types. For implementation of the Distributed systems annex (DSA)
771 -- over the PolyORB generic middleware components, it is necessary to
772 -- generate several supporting subprograms for each application data
773 -- type used in inter-partition communication. These subprograms are:
774
775 -- A Typecode function returning a high-level description of the
776 -- type's structure;
777
778 -- Two conversion functions allowing conversion of values of the
779 -- type from and to the generic data containers used by PolyORB.
780 -- These generic containers are called 'Any' type values after the
781 -- CORBA terminology, and hence the conversion subprograms are
782 -- named To_Any and From_Any.
783
784 function Build_From_Any_Call
785 (Typ : Entity_Id;
786 N : Node_Id;
787 Decls : List_Id) return Node_Id;
788 -- Build call to From_Any attribute function of type Typ with
789 -- expression N as actual parameter. Decls is the declarations list
790 -- for an appropriate enclosing scope of the point where the call
791 -- will be inserted; if the From_Any attribute for Typ needs to be
792 -- generated at this point, its declaration is appended to Decls.
793
794 procedure Build_From_Any_Function
795 (Loc : Source_Ptr;
796 Typ : Entity_Id;
797 Decl : out Node_Id;
798 Fnam : out Entity_Id);
799 -- Build From_Any attribute function for Typ. Loc is the reference
800 -- location for generated nodes, Typ is the type for which the
801 -- conversion function is generated. On return, Decl and Fnam contain
802 -- the declaration and entity for the newly-created function.
803
804 function Build_To_Any_Call
805 (Loc : Source_Ptr;
806 N : Node_Id;
807 Decls : List_Id;
808 Constrained : Boolean := False) return Node_Id;
809 -- Build call to To_Any attribute function with expression as actual
810 -- parameter. Loc is the reference location of generated nodes,
811 -- Decls is the declarations list for an appropriate enclosing scope
812 -- of the point where the call will be inserted; if the To_Any
813 -- attribute for the type of N needs to be generated at this point,
814 -- its declaration is appended to Decls. For the case of a limited
815 -- type, there is an additional parameter Constrained indicating
816 -- whether 'Write (when True) or 'Output (when False) is used.
817
818 procedure Build_To_Any_Function
819 (Loc : Source_Ptr;
820 Typ : Entity_Id;
821 Decl : out Node_Id;
822 Fnam : out Entity_Id);
823 -- Build To_Any attribute function for Typ. Loc is the reference
824 -- location for generated nodes, Typ is the type for which the
825 -- conversion function is generated. On return, Decl and Fnam contain
826 -- the declaration and entity for the newly-created function.
827
828 function Build_TypeCode_Call
829 (Loc : Source_Ptr;
830 Typ : Entity_Id;
831 Decls : List_Id) return Node_Id;
832 -- Build call to TypeCode attribute function for Typ. Decls is the
833 -- declarations list for an appropriate enclosing scope of the point
834 -- where the call will be inserted; if the To_Any attribute for Typ
835 -- needs to be generated at this point, its declaration is appended
836 -- to Decls.
837
838 procedure Build_TypeCode_Function
839 (Loc : Source_Ptr;
840 Typ : Entity_Id;
841 Decl : out Node_Id;
842 Fnam : out Entity_Id);
843 -- Build TypeCode attribute function for Typ. Loc is the reference
844 -- location for generated nodes, Typ is the type for which the
845 -- typecode function is generated. On return, Decl and Fnam contain
846 -- the declaration and entity for the newly-created function.
847
848 procedure Build_Name_And_Repository_Id
849 (E : Entity_Id;
850 Name_Str : out String_Id;
851 Repo_Id_Str : out String_Id);
852 -- In the PolyORB distribution model, each distributed object type
853 -- and each distributed operation has a globally unique identifier,
854 -- its Repository Id. This subprogram builds and returns two strings
855 -- for entity E (a distributed object type or operation): one
856 -- containing the name of E, the second containing its repository id.
857
858 procedure Assign_Opaque_From_Any
859 (Loc : Source_Ptr;
860 Stms : List_Id;
861 Typ : Entity_Id;
862 N : Node_Id;
863 Target : Entity_Id;
864 Constrained : Boolean := False);
865 -- For a Target object of type Typ, which has opaque representation
866 -- as a sequence of octets determined by stream attributes (which
867 -- includes all limited types), append code to Stmts performing the
868 -- equivalent of:
869 -- Target := Typ'From_Any (N)
870 --
871 -- or, if Target is Empty:
872 -- return Typ'From_Any (N)
873 --
874 -- Constrained determines whether 'Input (when False) or 'Read
875 -- (when True) is used.
876
877 end Helpers;
878
879 end PolyORB_Support;
880
881 -- The following PolyORB-specific subprograms are made visible to Exp_Attr:
882
883 function Build_From_Any_Call
884 (Typ : Entity_Id;
885 N : Node_Id;
886 Decls : List_Id) return Node_Id
887 renames PolyORB_Support.Helpers.Build_From_Any_Call;
888
889 function Build_To_Any_Call
890 (Loc : Source_Ptr;
891 N : Node_Id;
892 Decls : List_Id;
893 Constrained : Boolean := False) return Node_Id
894 renames PolyORB_Support.Helpers.Build_To_Any_Call;
895
896 function Build_TypeCode_Call
897 (Loc : Source_Ptr;
898 Typ : Entity_Id;
899 Decls : List_Id) return Node_Id
900 renames PolyORB_Support.Helpers.Build_TypeCode_Call;
901
902 ------------------------------------
903 -- Local variables and structures --
904 ------------------------------------
905
906 RCI_Cache : Node_Id := Empty;
907 -- Needs comments ???
908
909 Output_From_Constrained : constant array (Boolean) of Name_Id :=
910 (False => Name_Output,
911 True => Name_Write);
912 -- The attribute to choose depending on the fact that the parameter
913 -- is constrained or not. There is no such thing as Input_From_Constrained
914 -- since this require separate mechanisms ('Input is a function while
915 -- 'Read is a procedure).
916
917 generic
918 with procedure Process_Subprogram_Declaration (Decl : Node_Id);
919 -- Generate calling or receiving stub for this subprogram declaration
920
921 procedure Build_Package_Stubs (Pkg_Spec : Node_Id);
922 -- Recursively visit the given RCI Package_Specification, calling
923 -- Process_Subprogram_Declaration for each remote subprogram.
924
925 -------------------------
926 -- Build_Package_Stubs --
927 -------------------------
928
929 procedure Build_Package_Stubs (Pkg_Spec : Node_Id) is
930 Decls : constant List_Id := Visible_Declarations (Pkg_Spec);
931 Decl : Node_Id;
932
933 procedure Visit_Nested_Pkg (Nested_Pkg_Decl : Node_Id);
934 -- Recurse for the given nested package declaration
935
936 ----------------------
937 -- Visit_Nested_Pkg --
938 ----------------------
939
940 procedure Visit_Nested_Pkg (Nested_Pkg_Decl : Node_Id) is
941 Nested_Pkg_Spec : constant Node_Id := Specification (Nested_Pkg_Decl);
942 begin
943 Push_Scope (Scope_Of_Spec (Nested_Pkg_Spec));
944 Build_Package_Stubs (Nested_Pkg_Spec);
945 Pop_Scope;
946 end Visit_Nested_Pkg;
947
948 -- Start of processing for Build_Package_Stubs
949
950 begin
951 Decl := First (Decls);
952 while Present (Decl) loop
953 case Nkind (Decl) is
954 when N_Subprogram_Declaration =>
955
956 -- Note: we test Comes_From_Source on Spec, not Decl, because
957 -- in the case of a subprogram instance, only the specification
958 -- (not the declaration) is marked as coming from source.
959
960 if Comes_From_Source (Specification (Decl)) then
961 Process_Subprogram_Declaration (Decl);
962 end if;
963
964 when N_Package_Declaration =>
965
966 -- Case of a nested package or package instantiation coming
967 -- from source, including the wrapper package for an instance
968 -- of a generic subprogram.
969
970 declare
971 Pkg_Ent : constant Entity_Id :=
972 Defining_Unit_Name (Specification (Decl));
973 begin
974 if Comes_From_Source (Decl)
975 or else
976 (Is_Generic_Instance (Pkg_Ent)
977 and then Comes_From_Source
978 (Get_Unit_Instantiation_Node (Pkg_Ent)))
979 then
980 Visit_Nested_Pkg (Decl);
981 end if;
982 end;
983
984 when others =>
985 null;
986 end case;
987
988 Next (Decl);
989 end loop;
990 end Build_Package_Stubs;
991
992 ---------------------------------------
993 -- Add_Calling_Stubs_To_Declarations --
994 ---------------------------------------
995
996 procedure Add_Calling_Stubs_To_Declarations (Pkg_Spec : Node_Id) is
997 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
998
999 Current_Subprogram_Number : Int := First_RCI_Subprogram_Id;
1000 -- Subprogram id 0 is reserved for calls received from
1001 -- remote access-to-subprogram dereferences.
1002
1003 RCI_Instantiation : Node_Id;
1004
1005 procedure Visit_Subprogram (Decl : Node_Id);
1006 -- Generate calling stub for one remote subprogram
1007
1008 ----------------------
1009 -- Visit_Subprogram --
1010 ----------------------
1011
1012 procedure Visit_Subprogram (Decl : Node_Id) is
1013 Loc : constant Source_Ptr := Sloc (Decl);
1014 Spec : constant Node_Id := Specification (Decl);
1015 Subp_Stubs : Node_Id;
1016
1017 Subp_Str : String_Id;
1018 pragma Warnings (Off, Subp_Str);
1019
1020 begin
1021 -- Disable expansion of stubs if serious errors have been diagnosed,
1022 -- because otherwise some illegal remote subprogram declarations
1023 -- could cause cascaded errors in stubs.
1024
1025 if Serious_Errors_Detected /= 0 then
1026 return;
1027 end if;
1028
1029 Assign_Subprogram_Identifier
1030 (Defining_Unit_Name (Spec), Current_Subprogram_Number, Subp_Str);
1031
1032 Subp_Stubs :=
1033 Build_Subprogram_Calling_Stubs
1034 (Vis_Decl => Decl,
1035 Subp_Id =>
1036 Build_Subprogram_Id (Loc, Defining_Unit_Name (Spec)),
1037 Asynchronous =>
1038 Nkind (Spec) = N_Procedure_Specification
1039 and then Is_Asynchronous (Defining_Unit_Name (Spec)));
1040
1041 Append_To (List_Containing (Decl), Subp_Stubs);
1042 Analyze (Subp_Stubs);
1043
1044 Current_Subprogram_Number := Current_Subprogram_Number + 1;
1045 end Visit_Subprogram;
1046
1047 procedure Visit_Spec is new Build_Package_Stubs (Visit_Subprogram);
1048
1049 -- Start of processing for Add_Calling_Stubs_To_Declarations
1050
1051 begin
1052 Push_Scope (Scope_Of_Spec (Pkg_Spec));
1053
1054 -- The first thing added is an instantiation of the generic package
1055 -- System.Partition_Interface.RCI_Locator with the name of this remote
1056 -- package. This will act as an interface with the name server to
1057 -- determine the Partition_ID and the RPC_Receiver for the receiver
1058 -- of this package.
1059
1060 RCI_Instantiation := RCI_Package_Locator (Loc, Pkg_Spec);
1061 RCI_Cache := Defining_Unit_Name (RCI_Instantiation);
1062
1063 Append_To (Visible_Declarations (Pkg_Spec), RCI_Instantiation);
1064 Analyze (RCI_Instantiation);
1065
1066 -- For each subprogram declaration visible in the spec, we do build a
1067 -- body. We also increment a counter to assign a different Subprogram_Id
1068 -- to each subprogram. The receiving stubs processing uses the same
1069 -- mechanism and will thus assign the same Id and do the correct
1070 -- dispatching.
1071
1072 Overload_Counter_Table.Reset;
1073 PolyORB_Support.Reserve_NamingContext_Methods;
1074
1075 Visit_Spec (Pkg_Spec);
1076
1077 Pop_Scope;
1078 end Add_Calling_Stubs_To_Declarations;
1079
1080 -----------------------------
1081 -- Add_Parameter_To_NVList --
1082 -----------------------------
1083
1084 function Add_Parameter_To_NVList
1085 (Loc : Source_Ptr;
1086 NVList : Entity_Id;
1087 Parameter : Entity_Id;
1088 Constrained : Boolean;
1089 Any : Entity_Id) return Node_Id
1090 is
1091 Parameter_Name_String : String_Id;
1092 Parameter_Mode : Node_Id;
1093
1094 function Parameter_Passing_Mode
1095 (Loc : Source_Ptr;
1096 Parameter : Entity_Id;
1097 Constrained : Boolean) return Node_Id;
1098 -- Return an expression that denotes the parameter passing mode to be
1099 -- used for Parameter in distribution stubs, where Constrained is
1100 -- Parameter's constrained status.
1101
1102 ----------------------------
1103 -- Parameter_Passing_Mode --
1104 ----------------------------
1105
1106 function Parameter_Passing_Mode
1107 (Loc : Source_Ptr;
1108 Parameter : Entity_Id;
1109 Constrained : Boolean) return Node_Id
1110 is
1111 Lib_RE : RE_Id;
1112
1113 begin
1114 if Out_Present (Parameter) then
1115 if In_Present (Parameter)
1116 or else not Constrained
1117 then
1118 -- Unconstrained formals must be translated
1119 -- to 'in' or 'inout', not 'out', because
1120 -- they need to be constrained by the actual.
1121
1122 Lib_RE := RE_Mode_Inout;
1123 else
1124 Lib_RE := RE_Mode_Out;
1125 end if;
1126
1127 else
1128 Lib_RE := RE_Mode_In;
1129 end if;
1130
1131 return New_Occurrence_Of (RTE (Lib_RE), Loc);
1132 end Parameter_Passing_Mode;
1133
1134 -- Start of processing for Add_Parameter_To_NVList
1135
1136 begin
1137 if Nkind (Parameter) = N_Defining_Identifier then
1138 Get_Name_String (Chars (Parameter));
1139 else
1140 Get_Name_String (Chars (Defining_Identifier (Parameter)));
1141 end if;
1142
1143 Parameter_Name_String := String_From_Name_Buffer;
1144
1145 if Nkind (Parameter) = N_Defining_Identifier then
1146
1147 -- When the parameter passed to Add_Parameter_To_NVList is an
1148 -- Extra_Constrained parameter, Parameter is an N_Defining_
1149 -- Identifier, instead of a complete N_Parameter_Specification.
1150 -- Thus, we explicitly set 'in' mode in this case.
1151
1152 Parameter_Mode := New_Occurrence_Of (RTE (RE_Mode_In), Loc);
1153
1154 else
1155 Parameter_Mode :=
1156 Parameter_Passing_Mode (Loc, Parameter, Constrained);
1157 end if;
1158
1159 return
1160 Make_Procedure_Call_Statement (Loc,
1161 Name =>
1162 New_Occurrence_Of (RTE (RE_NVList_Add_Item), Loc),
1163 Parameter_Associations => New_List (
1164 New_Occurrence_Of (NVList, Loc),
1165 Make_Function_Call (Loc,
1166 Name =>
1167 New_Occurrence_Of (RTE (RE_To_PolyORB_String), Loc),
1168 Parameter_Associations => New_List (
1169 Make_String_Literal (Loc, Strval => Parameter_Name_String))),
1170 New_Occurrence_Of (Any, Loc),
1171 Parameter_Mode));
1172 end Add_Parameter_To_NVList;
1173
1174 --------------------------------
1175 -- Add_RACW_Asynchronous_Flag --
1176 --------------------------------
1177
1178 procedure Add_RACW_Asynchronous_Flag
1179 (Declarations : List_Id;
1180 RACW_Type : Entity_Id)
1181 is
1182 Loc : constant Source_Ptr := Sloc (RACW_Type);
1183
1184 Asynchronous_Flag : constant Entity_Id :=
1185 Make_Defining_Identifier (Loc,
1186 New_External_Name (Chars (RACW_Type), 'A'));
1187
1188 begin
1189 -- Declare the asynchronous flag. This flag will be changed to True
1190 -- whenever it is known that the RACW type is asynchronous.
1191
1192 Append_To (Declarations,
1193 Make_Object_Declaration (Loc,
1194 Defining_Identifier => Asynchronous_Flag,
1195 Constant_Present => True,
1196 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
1197 Expression => New_Occurrence_Of (Standard_False, Loc)));
1198
1199 Asynchronous_Flags_Table.Set (RACW_Type, Asynchronous_Flag);
1200 end Add_RACW_Asynchronous_Flag;
1201
1202 -----------------------
1203 -- Add_RACW_Features --
1204 -----------------------
1205
1206 procedure Add_RACW_Features (RACW_Type : Entity_Id) is
1207 Desig : constant Entity_Id := Etype (Designated_Type (RACW_Type));
1208 Same_Scope : constant Boolean := Scope (Desig) = Scope (RACW_Type);
1209
1210 Pkg_Spec : Node_Id;
1211 Decls : List_Id;
1212 Body_Decls : List_Id;
1213
1214 Stub_Type : Entity_Id;
1215 Stub_Type_Access : Entity_Id;
1216 RPC_Receiver_Decl : Node_Id;
1217
1218 Existing : Boolean;
1219 -- True when appropriate stubs have already been generated (this is the
1220 -- case when another RACW with the same designated type has already been
1221 -- encountered), in which case we reuse the previous stubs rather than
1222 -- generating new ones.
1223
1224 begin
1225 if not Expander_Active then
1226 return;
1227 end if;
1228
1229 -- Mark the current package declaration as containing an RACW, so that
1230 -- the bodies for the calling stubs and the RACW stream subprograms
1231 -- are attached to the tree when the corresponding body is encountered.
1232
1233 Set_Has_RACW (Current_Scope);
1234
1235 -- Look for place to declare the RACW stub type and RACW operations
1236
1237 Pkg_Spec := Empty;
1238
1239 if Same_Scope then
1240
1241 -- Case of declaring the RACW in the same package as its designated
1242 -- type: we know that the designated type is a private type, so we
1243 -- use the private declarations list.
1244
1245 Pkg_Spec := Package_Specification_Of_Scope (Current_Scope);
1246
1247 if Present (Private_Declarations (Pkg_Spec)) then
1248 Decls := Private_Declarations (Pkg_Spec);
1249 else
1250 Decls := Visible_Declarations (Pkg_Spec);
1251 end if;
1252
1253 else
1254 -- Case of declaring the RACW in another package than its designated
1255 -- type: use the private declarations list if present; otherwise
1256 -- use the visible declarations.
1257
1258 Decls := List_Containing (Declaration_Node (RACW_Type));
1259
1260 end if;
1261
1262 -- If we were unable to find the declarations, that means that the
1263 -- completion of the type was missing. We can safely return and let the
1264 -- error be caught by the semantic analysis.
1265
1266 if No (Decls) then
1267 return;
1268 end if;
1269
1270 Add_Stub_Type
1271 (Designated_Type => Desig,
1272 RACW_Type => RACW_Type,
1273 Decls => Decls,
1274 Stub_Type => Stub_Type,
1275 Stub_Type_Access => Stub_Type_Access,
1276 RPC_Receiver_Decl => RPC_Receiver_Decl,
1277 Body_Decls => Body_Decls,
1278 Existing => Existing);
1279
1280 -- If this RACW is not in the main unit, do not generate primitive or
1281 -- TSS bodies.
1282
1283 if not Entity_Is_In_Main_Unit (RACW_Type) then
1284 Body_Decls := No_List;
1285 end if;
1286
1287 Add_RACW_Asynchronous_Flag
1288 (Declarations => Decls,
1289 RACW_Type => RACW_Type);
1290
1291 Specific_Add_RACW_Features
1292 (RACW_Type => RACW_Type,
1293 Desig => Desig,
1294 Stub_Type => Stub_Type,
1295 Stub_Type_Access => Stub_Type_Access,
1296 RPC_Receiver_Decl => RPC_Receiver_Decl,
1297 Body_Decls => Body_Decls);
1298
1299 -- If we already have stubs for this designated type, nothing to do
1300
1301 if Existing then
1302 return;
1303 end if;
1304
1305 if Is_Frozen (Desig) then
1306 Validate_RACW_Primitives (RACW_Type);
1307 Add_RACW_Primitive_Declarations_And_Bodies
1308 (Designated_Type => Desig,
1309 Insertion_Node => RPC_Receiver_Decl,
1310 Body_Decls => Body_Decls);
1311
1312 else
1313 -- Validate_RACW_Primitives requires the list of all primitives of
1314 -- the designated type, so defer processing until Desig is frozen.
1315 -- See Exp_Ch3.Freeze_Type.
1316
1317 Add_Access_Type_To_Process (E => Desig, A => RACW_Type);
1318 end if;
1319 end Add_RACW_Features;
1320
1321 ------------------------------------------------
1322 -- Add_RACW_Primitive_Declarations_And_Bodies --
1323 ------------------------------------------------
1324
1325 procedure Add_RACW_Primitive_Declarations_And_Bodies
1326 (Designated_Type : Entity_Id;
1327 Insertion_Node : Node_Id;
1328 Body_Decls : List_Id)
1329 is
1330 Loc : constant Source_Ptr := Sloc (Insertion_Node);
1331 -- Set Sloc of generated declaration copy of insertion node Sloc, so
1332 -- the declarations are recognized as belonging to the current package.
1333
1334 Stub_Elements : constant Stub_Structure :=
1335 Stubs_Table.Get (Designated_Type);
1336
1337 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
1338
1339 Is_RAS : constant Boolean :=
1340 not Comes_From_Source (Stub_Elements.RACW_Type);
1341 -- Case of the RACW generated to implement a remote access-to-
1342 -- subprogram type.
1343
1344 Build_Bodies : constant Boolean :=
1345 In_Extended_Main_Code_Unit (Stub_Elements.Stub_Type);
1346 -- True when bodies must be prepared in Body_Decls. Bodies are generated
1347 -- only when the main unit is the unit that contains the stub type.
1348
1349 Current_Insertion_Node : Node_Id := Insertion_Node;
1350
1351 RPC_Receiver : Entity_Id;
1352 RPC_Receiver_Statements : List_Id;
1353 RPC_Receiver_Case_Alternatives : constant List_Id := New_List;
1354 RPC_Receiver_Elsif_Parts : List_Id := No_List;
1355 RPC_Receiver_Request : Entity_Id := Empty;
1356 RPC_Receiver_Subp_Id : Entity_Id := Empty;
1357 RPC_Receiver_Subp_Index : Entity_Id := Empty;
1358
1359 Subp_Str : String_Id;
1360
1361 Current_Primitive_Elmt : Elmt_Id;
1362 Current_Primitive : Entity_Id;
1363 Current_Primitive_Body : Node_Id;
1364 Current_Primitive_Spec : Node_Id;
1365 Current_Primitive_Decl : Node_Id;
1366 Current_Primitive_Number : Int := 0;
1367 Current_Primitive_Alias : Node_Id;
1368 Current_Receiver : Entity_Id;
1369 Current_Receiver_Body : Node_Id;
1370 RPC_Receiver_Decl : Node_Id;
1371 Possibly_Asynchronous : Boolean;
1372
1373 begin
1374 if not Expander_Active then
1375 return;
1376 end if;
1377
1378 if not Is_RAS then
1379 RPC_Receiver := Make_Temporary (Loc, 'P');
1380
1381 Specific_Build_RPC_Receiver_Body
1382 (RPC_Receiver => RPC_Receiver,
1383 Request => RPC_Receiver_Request,
1384 Subp_Id => RPC_Receiver_Subp_Id,
1385 Subp_Index => RPC_Receiver_Subp_Index,
1386 Stmts => RPC_Receiver_Statements,
1387 Decl => RPC_Receiver_Decl);
1388
1389 if Get_PCS_Name = Name_PolyORB_DSA then
1390
1391 -- For the case of PolyORB, we need to map a textual operation
1392 -- name into a primitive index. Currently we do so using a simple
1393 -- sequence of string comparisons.
1394
1395 RPC_Receiver_Elsif_Parts := New_List;
1396 end if;
1397 end if;
1398
1399 -- Build callers, receivers for every primitive operations and a RPC
1400 -- receiver for this type. Note that we use Direct_Primitive_Operations,
1401 -- not Primitive_Operations, because we really want just the primitives
1402 -- of the tagged type itself, and in the case of a tagged synchronized
1403 -- type we do not want to get the primitives of the corresponding
1404 -- record type).
1405
1406 if Present (Direct_Primitive_Operations (Designated_Type)) then
1407 Overload_Counter_Table.Reset;
1408
1409 Current_Primitive_Elmt :=
1410 First_Elmt (Direct_Primitive_Operations (Designated_Type));
1411 while Current_Primitive_Elmt /= No_Elmt loop
1412 Current_Primitive := Node (Current_Primitive_Elmt);
1413
1414 -- Copy the primitive of all the parents, except predefined ones
1415 -- that are not remotely dispatching. Also omit hidden primitives
1416 -- (occurs in the case of primitives of interface progenitors
1417 -- other than immediate ancestors of the Designated_Type).
1418
1419 if Chars (Current_Primitive) /= Name_uSize
1420 and then Chars (Current_Primitive) /= Name_uAlignment
1421 and then not
1422 (Is_TSS (Current_Primitive, TSS_Deep_Finalize) or else
1423 Is_TSS (Current_Primitive, TSS_Put_Image) or else
1424 Is_TSS (Current_Primitive, TSS_Stream_Input) or else
1425 Is_TSS (Current_Primitive, TSS_Stream_Output) or else
1426 Is_TSS (Current_Primitive, TSS_Stream_Read) or else
1427 Is_TSS (Current_Primitive, TSS_Stream_Write)
1428 or else
1429 Is_Predefined_Interface_Primitive (Current_Primitive))
1430 and then not Is_Hidden (Current_Primitive)
1431 then
1432 -- The first thing to do is build an up-to-date copy of the
1433 -- spec with all the formals referencing Controlling_Type
1434 -- transformed into formals referencing Stub_Type. Since this
1435 -- primitive may have been inherited, go back the alias chain
1436 -- until the real primitive has been found.
1437
1438 Current_Primitive_Alias := Ultimate_Alias (Current_Primitive);
1439
1440 -- Copy the spec from the original declaration for the purpose
1441 -- of declaring an overriding subprogram: we need to replace
1442 -- the type of each controlling formal with Stub_Type. The
1443 -- primitive may have been declared for Controlling_Type or
1444 -- inherited from some ancestor type for which we do not have
1445 -- an easily determined Entity_Id. We have no systematic way
1446 -- of knowing which type to substitute Stub_Type for. Instead,
1447 -- Copy_Specification relies on the flag Is_Controlling_Formal
1448 -- to determine which formals to change.
1449
1450 Current_Primitive_Spec :=
1451 Copy_Specification (Loc,
1452 Spec => Parent (Current_Primitive_Alias),
1453 Ctrl_Type => Stub_Elements.Stub_Type);
1454
1455 Current_Primitive_Decl :=
1456 Make_Subprogram_Declaration (Loc,
1457 Specification => Current_Primitive_Spec);
1458
1459 Insert_After_And_Analyze (Current_Insertion_Node,
1460 Current_Primitive_Decl);
1461 Current_Insertion_Node := Current_Primitive_Decl;
1462
1463 Possibly_Asynchronous :=
1464 Nkind (Current_Primitive_Spec) = N_Procedure_Specification
1465 and then Could_Be_Asynchronous (Current_Primitive_Spec);
1466
1467 Assign_Subprogram_Identifier (
1468 Defining_Unit_Name (Current_Primitive_Spec),
1469 Current_Primitive_Number,
1470 Subp_Str);
1471
1472 if Build_Bodies then
1473 Current_Primitive_Body :=
1474 Build_Subprogram_Calling_Stubs
1475 (Vis_Decl => Current_Primitive_Decl,
1476 Subp_Id =>
1477 Build_Subprogram_Id (Loc,
1478 Defining_Unit_Name (Current_Primitive_Spec)),
1479 Asynchronous => Possibly_Asynchronous,
1480 Dynamically_Asynchronous => Possibly_Asynchronous,
1481 Stub_Type => Stub_Elements.Stub_Type,
1482 RACW_Type => Stub_Elements.RACW_Type);
1483 Append_To (Body_Decls, Current_Primitive_Body);
1484
1485 -- Analyzing the body here would cause the Stub type to
1486 -- be frozen, thus preventing subsequent primitive
1487 -- declarations. For this reason, it will be analyzed
1488 -- later in the regular flow (and in the context of the
1489 -- appropriate unit body, see Append_RACW_Bodies).
1490
1491 end if;
1492
1493 -- Build the receiver stubs
1494
1495 if Build_Bodies and then not Is_RAS then
1496 Current_Receiver_Body :=
1497 Specific_Build_Subprogram_Receiving_Stubs
1498 (Vis_Decl => Current_Primitive_Decl,
1499 Asynchronous => Possibly_Asynchronous,
1500 Dynamically_Asynchronous => Possibly_Asynchronous,
1501 Stub_Type => Stub_Elements.Stub_Type,
1502 RACW_Type => Stub_Elements.RACW_Type,
1503 Parent_Primitive => Current_Primitive);
1504
1505 Current_Receiver :=
1506 Defining_Unit_Name (Specification (Current_Receiver_Body));
1507
1508 Append_To (Body_Decls, Current_Receiver_Body);
1509
1510 -- Add a case alternative to the receiver
1511
1512 if Get_PCS_Name = Name_PolyORB_DSA then
1513 Append_To (RPC_Receiver_Elsif_Parts,
1514 Make_Elsif_Part (Loc,
1515 Condition =>
1516 Make_Function_Call (Loc,
1517 Name =>
1518 New_Occurrence_Of (
1519 RTE (RE_Caseless_String_Eq), Loc),
1520 Parameter_Associations => New_List (
1521 New_Occurrence_Of (RPC_Receiver_Subp_Id, Loc),
1522 Make_String_Literal (Loc, Subp_Str))),
1523
1524 Then_Statements => New_List (
1525 Make_Assignment_Statement (Loc,
1526 Name => New_Occurrence_Of (
1527 RPC_Receiver_Subp_Index, Loc),
1528 Expression =>
1529 Make_Integer_Literal (Loc,
1530 Intval => Current_Primitive_Number)))));
1531 end if;
1532
1533 Append_To (RPC_Receiver_Case_Alternatives,
1534 Make_Case_Statement_Alternative (Loc,
1535 Discrete_Choices => New_List (
1536 Make_Integer_Literal (Loc, Current_Primitive_Number)),
1537
1538 Statements => New_List (
1539 Make_Procedure_Call_Statement (Loc,
1540 Name =>
1541 New_Occurrence_Of (Current_Receiver, Loc),
1542 Parameter_Associations => New_List (
1543 New_Occurrence_Of (RPC_Receiver_Request, Loc))))));
1544 end if;
1545
1546 -- Increment the index of current primitive
1547
1548 Current_Primitive_Number := Current_Primitive_Number + 1;
1549 end if;
1550
1551 Next_Elmt (Current_Primitive_Elmt);
1552 end loop;
1553 end if;
1554
1555 -- Build the case statement and the heart of the subprogram
1556
1557 if Build_Bodies and then not Is_RAS then
1558 if Get_PCS_Name = Name_PolyORB_DSA
1559 and then Present (First (RPC_Receiver_Elsif_Parts))
1560 then
1561 Append_To (RPC_Receiver_Statements,
1562 Make_Implicit_If_Statement (Designated_Type,
1563 Condition => New_Occurrence_Of (Standard_False, Loc),
1564 Then_Statements => New_List,
1565 Elsif_Parts => RPC_Receiver_Elsif_Parts));
1566 end if;
1567
1568 Append_To (RPC_Receiver_Case_Alternatives,
1569 Make_Case_Statement_Alternative (Loc,
1570 Discrete_Choices => New_List (Make_Others_Choice (Loc)),
1571 Statements => New_List (Make_Null_Statement (Loc))));
1572
1573 Append_To (RPC_Receiver_Statements,
1574 Make_Case_Statement (Loc,
1575 Expression =>
1576 New_Occurrence_Of (RPC_Receiver_Subp_Index, Loc),
1577 Alternatives => RPC_Receiver_Case_Alternatives));
1578
1579 Append_To (Body_Decls, RPC_Receiver_Decl);
1580 Specific_Add_Obj_RPC_Receiver_Completion (Loc,
1581 Body_Decls, RPC_Receiver, Stub_Elements);
1582
1583 -- Do not analyze RPC receiver body at this stage since it references
1584 -- subprograms that have not been analyzed yet. It will be analyzed in
1585 -- the regular flow (see Append_RACW_Bodies).
1586
1587 end if;
1588 end Add_RACW_Primitive_Declarations_And_Bodies;
1589
1590 -----------------------------
1591 -- Add_RAS_Dereference_TSS --
1592 -----------------------------
1593
1594 procedure Add_RAS_Dereference_TSS (N : Node_Id) is
1595 Loc : constant Source_Ptr := Sloc (N);
1596
1597 Type_Def : constant Node_Id := Type_Definition (N);
1598 RAS_Type : constant Entity_Id := Defining_Identifier (N);
1599 Fat_Type : constant Entity_Id := Equivalent_Type (RAS_Type);
1600 RACW_Type : constant Entity_Id := Underlying_RACW_Type (RAS_Type);
1601
1602 RACW_Primitive_Name : Node_Id;
1603
1604 Proc : constant Entity_Id :=
1605 Make_Defining_Identifier (Loc,
1606 Chars => Make_TSS_Name (RAS_Type, TSS_RAS_Dereference));
1607
1608 Proc_Spec : Node_Id;
1609 Param_Specs : List_Id;
1610 Param_Assoc : constant List_Id := New_List;
1611 Stmts : constant List_Id := New_List;
1612
1613 RAS_Parameter : constant Entity_Id := Make_Temporary (Loc, 'P');
1614
1615 Is_Function : constant Boolean :=
1616 Nkind (Type_Def) = N_Access_Function_Definition;
1617
1618 Is_Degenerate : Boolean;
1619 -- Set to True if the subprogram_specification for this RAS has an
1620 -- anonymous access parameter (see Process_Remote_AST_Declaration).
1621
1622 Spec : constant Node_Id := Type_Def;
1623
1624 Current_Parameter : Node_Id;
1625
1626 -- Start of processing for Add_RAS_Dereference_TSS
1627
1628 begin
1629 -- The Dereference TSS for a remote access-to-subprogram type has the
1630 -- form:
1631
1632 -- [function|procedure] ras_typeRD (RAS_Value, <RAS_Parameters>)
1633 -- [return <>]
1634
1635 -- This is called whenever a value of a RAS type is dereferenced
1636
1637 -- First construct a list of parameter specifications:
1638
1639 -- The first formal is the RAS values
1640
1641 Param_Specs := New_List (
1642 Make_Parameter_Specification (Loc,
1643 Defining_Identifier => RAS_Parameter,
1644 In_Present => True,
1645 Parameter_Type =>
1646 New_Occurrence_Of (Fat_Type, Loc)));
1647
1648 -- The following formals are copied from the type declaration
1649
1650 Is_Degenerate := False;
1651 Current_Parameter := First (Parameter_Specifications (Type_Def));
1652 Parameters : while Present (Current_Parameter) loop
1653 if Nkind (Parameter_Type (Current_Parameter)) =
1654 N_Access_Definition
1655 then
1656 Is_Degenerate := True;
1657 end if;
1658
1659 Append_To (Param_Specs,
1660 Make_Parameter_Specification (Loc,
1661 Defining_Identifier =>
1662 Make_Defining_Identifier (Loc,
1663 Chars => Chars (Defining_Identifier (Current_Parameter))),
1664 In_Present => In_Present (Current_Parameter),
1665 Out_Present => Out_Present (Current_Parameter),
1666 Parameter_Type =>
1667 New_Copy_Tree (Parameter_Type (Current_Parameter)),
1668 Expression =>
1669 New_Copy_Tree (Expression (Current_Parameter))));
1670
1671 Append_To (Param_Assoc,
1672 Make_Identifier (Loc,
1673 Chars => Chars (Defining_Identifier (Current_Parameter))));
1674
1675 Next (Current_Parameter);
1676 end loop Parameters;
1677
1678 if Is_Degenerate then
1679 Prepend_To (Param_Assoc, New_Occurrence_Of (RAS_Parameter, Loc));
1680
1681 -- Generate a dummy body. This code will never actually be executed,
1682 -- because null is the only legal value for a degenerate RAS type.
1683 -- For legality's sake (in order to avoid generating a function that
1684 -- does not contain a return statement), we include a dummy recursive
1685 -- call on the TSS itself.
1686
1687 Append_To (Stmts,
1688 Make_Raise_Program_Error (Loc, Reason => PE_Explicit_Raise));
1689 RACW_Primitive_Name := New_Occurrence_Of (Proc, Loc);
1690
1691 else
1692 -- For a normal RAS type, we cast the RAS formal to the corresponding
1693 -- tagged type, and perform a dispatching call to its Call primitive
1694 -- operation.
1695
1696 Prepend_To (Param_Assoc,
1697 Unchecked_Convert_To (RACW_Type,
1698 New_Occurrence_Of (RAS_Parameter, Loc)));
1699
1700 RACW_Primitive_Name :=
1701 Make_Selected_Component (Loc,
1702 Prefix => Scope (RACW_Type),
1703 Selector_Name => Name_uCall);
1704 end if;
1705
1706 if Is_Function then
1707 Append_To (Stmts,
1708 Make_Simple_Return_Statement (Loc,
1709 Expression =>
1710 Make_Function_Call (Loc,
1711 Name => RACW_Primitive_Name,
1712 Parameter_Associations => Param_Assoc)));
1713
1714 else
1715 Append_To (Stmts,
1716 Make_Procedure_Call_Statement (Loc,
1717 Name => RACW_Primitive_Name,
1718 Parameter_Associations => Param_Assoc));
1719 end if;
1720
1721 -- Build the complete subprogram
1722
1723 if Is_Function then
1724 Proc_Spec :=
1725 Make_Function_Specification (Loc,
1726 Defining_Unit_Name => Proc,
1727 Parameter_Specifications => Param_Specs,
1728 Result_Definition =>
1729 New_Occurrence_Of (
1730 Entity (Result_Definition (Spec)), Loc));
1731
1732 Mutate_Ekind (Proc, E_Function);
1733 Set_Etype (Proc,
1734 New_Occurrence_Of (Entity (Result_Definition (Spec)), Loc));
1735
1736 else
1737 Proc_Spec :=
1738 Make_Procedure_Specification (Loc,
1739 Defining_Unit_Name => Proc,
1740 Parameter_Specifications => Param_Specs);
1741
1742 Mutate_Ekind (Proc, E_Procedure);
1743 Set_Etype (Proc, Standard_Void_Type);
1744 end if;
1745
1746 Discard_Node (
1747 Make_Subprogram_Body (Loc,
1748 Specification => Proc_Spec,
1749 Declarations => New_List,
1750 Handled_Statement_Sequence =>
1751 Make_Handled_Sequence_Of_Statements (Loc,
1752 Statements => Stmts)));
1753
1754 Set_TSS (Fat_Type, Proc);
1755 end Add_RAS_Dereference_TSS;
1756
1757 -------------------------------
1758 -- Add_RAS_Proxy_And_Analyze --
1759 -------------------------------
1760
1761 procedure Add_RAS_Proxy_And_Analyze
1762 (Decls : List_Id;
1763 Vis_Decl : Node_Id;
1764 All_Calls_Remote_E : Entity_Id;
1765 Proxy_Object_Addr : out Entity_Id)
1766 is
1767 Loc : constant Source_Ptr := Sloc (Vis_Decl);
1768
1769 Subp_Name : constant Entity_Id :=
1770 Defining_Unit_Name (Specification (Vis_Decl));
1771
1772 Pkg_Name : constant Entity_Id :=
1773 Make_Defining_Identifier (Loc,
1774 Chars => New_External_Name (Chars (Subp_Name), 'P', -1));
1775
1776 Proxy_Type : constant Entity_Id :=
1777 Make_Defining_Identifier (Loc,
1778 Chars =>
1779 New_External_Name
1780 (Related_Id => Chars (Subp_Name),
1781 Suffix => 'P'));
1782
1783 Proxy_Type_Full_View : constant Entity_Id :=
1784 Make_Defining_Identifier (Loc,
1785 Chars (Proxy_Type));
1786
1787 Subp_Decl_Spec : constant Node_Id :=
1788 Build_RAS_Primitive_Specification
1789 (Subp_Spec => Specification (Vis_Decl),
1790 Remote_Object_Type => Proxy_Type);
1791
1792 Subp_Body_Spec : constant Node_Id :=
1793 Build_RAS_Primitive_Specification
1794 (Subp_Spec => Specification (Vis_Decl),
1795 Remote_Object_Type => Proxy_Type);
1796
1797 Vis_Decls : constant List_Id := New_List;
1798 Pvt_Decls : constant List_Id := New_List;
1799 Actuals : constant List_Id := New_List;
1800 Formal : Node_Id;
1801 Perform_Call : Node_Id;
1802
1803 begin
1804 -- type subpP is tagged limited private;
1805
1806 Append_To (Vis_Decls,
1807 Make_Private_Type_Declaration (Loc,
1808 Defining_Identifier => Proxy_Type,
1809 Tagged_Present => True,
1810 Limited_Present => True));
1811
1812 -- [subprogram] Call
1813 -- (Self : access subpP;
1814 -- ...other-formals...)
1815 -- [return T];
1816
1817 Append_To (Vis_Decls,
1818 Make_Subprogram_Declaration (Loc,
1819 Specification => Subp_Decl_Spec));
1820
1821 -- A : constant System.Address;
1822
1823 Proxy_Object_Addr := Make_Defining_Identifier (Loc, Name_uA);
1824
1825 Append_To (Vis_Decls,
1826 Make_Object_Declaration (Loc,
1827 Defining_Identifier => Proxy_Object_Addr,
1828 Constant_Present => True,
1829 Object_Definition => New_Occurrence_Of (RTE (RE_Address), Loc)));
1830
1831 -- private
1832
1833 -- type subpP is tagged limited record
1834 -- All_Calls_Remote : Boolean := [All_Calls_Remote?];
1835 -- ...
1836 -- end record;
1837
1838 Append_To (Pvt_Decls,
1839 Make_Full_Type_Declaration (Loc,
1840 Defining_Identifier => Proxy_Type_Full_View,
1841 Type_Definition =>
1842 Build_Remote_Subprogram_Proxy_Type (Loc,
1843 New_Occurrence_Of (All_Calls_Remote_E, Loc))));
1844
1845 -- Trick semantic analysis into swapping the public and full view when
1846 -- freezing the public view.
1847
1848 Set_Comes_From_Source (Proxy_Type_Full_View, True);
1849
1850 -- procedure Call
1851 -- (Self : access O;
1852 -- ...other-formals...) is
1853 -- begin
1854 -- P (...other-formals...);
1855 -- end Call;
1856
1857 -- function Call
1858 -- (Self : access O;
1859 -- ...other-formals...)
1860 -- return T is
1861 -- begin
1862 -- return F (...other-formals...);
1863 -- end Call;
1864
1865 if Nkind (Subp_Decl_Spec) = N_Procedure_Specification then
1866 Perform_Call :=
1867 Make_Procedure_Call_Statement (Loc,
1868 Name => New_Occurrence_Of (Subp_Name, Loc),
1869 Parameter_Associations => Actuals);
1870 else
1871 Perform_Call :=
1872 Make_Simple_Return_Statement (Loc,
1873 Expression =>
1874 Make_Function_Call (Loc,
1875 Name => New_Occurrence_Of (Subp_Name, Loc),
1876 Parameter_Associations => Actuals));
1877 end if;
1878
1879 Formal := First (Parameter_Specifications (Subp_Decl_Spec));
1880 pragma Assert (Present (Formal));
1881 loop
1882 Next (Formal);
1883 exit when No (Formal);
1884 Append_To (Actuals,
1885 New_Occurrence_Of (Defining_Identifier (Formal), Loc));
1886 end loop;
1887
1888 -- O : aliased subpP;
1889
1890 Append_To (Pvt_Decls,
1891 Make_Object_Declaration (Loc,
1892 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
1893 Aliased_Present => True,
1894 Object_Definition => New_Occurrence_Of (Proxy_Type, Loc)));
1895
1896 -- A : constant System.Address := O'Address;
1897
1898 Append_To (Pvt_Decls,
1899 Make_Object_Declaration (Loc,
1900 Defining_Identifier =>
1901 Make_Defining_Identifier (Loc, Chars (Proxy_Object_Addr)),
1902 Constant_Present => True,
1903 Object_Definition => New_Occurrence_Of (RTE (RE_Address), Loc),
1904 Expression =>
1905 Make_Attribute_Reference (Loc,
1906 Prefix => New_Occurrence_Of (
1907 Defining_Identifier (Last (Pvt_Decls)), Loc),
1908 Attribute_Name => Name_Address)));
1909
1910 Append_To (Decls,
1911 Make_Package_Declaration (Loc,
1912 Specification => Make_Package_Specification (Loc,
1913 Defining_Unit_Name => Pkg_Name,
1914 Visible_Declarations => Vis_Decls,
1915 Private_Declarations => Pvt_Decls,
1916 End_Label => Empty)));
1917 Analyze (Last (Decls));
1918
1919 Append_To (Decls,
1920 Make_Package_Body (Loc,
1921 Defining_Unit_Name =>
1922 Make_Defining_Identifier (Loc, Chars (Pkg_Name)),
1923 Declarations => New_List (
1924 Make_Subprogram_Body (Loc,
1925 Specification => Subp_Body_Spec,
1926 Declarations => New_List,
1927 Handled_Statement_Sequence =>
1928 Make_Handled_Sequence_Of_Statements (Loc,
1929 Statements => New_List (Perform_Call))))));
1930 Analyze (Last (Decls));
1931 end Add_RAS_Proxy_And_Analyze;
1932
1933 -----------------------
1934 -- Add_RAST_Features --
1935 -----------------------
1936
1937 procedure Add_RAST_Features (Vis_Decl : Node_Id) is
1938 RAS_Type : constant Entity_Id :=
1939 Equivalent_Type (Defining_Identifier (Vis_Decl));
1940 begin
1941 pragma Assert (No (TSS (RAS_Type, TSS_RAS_Access)));
1942 Add_RAS_Dereference_TSS (Vis_Decl);
1943 Specific_Add_RAST_Features (Vis_Decl, RAS_Type);
1944 end Add_RAST_Features;
1945
1946 -------------------
1947 -- Add_Stub_Type --
1948 -------------------
1949
1950 procedure Add_Stub_Type
1951 (Designated_Type : Entity_Id;
1952 RACW_Type : Entity_Id;
1953 Decls : List_Id;
1954 Stub_Type : out Entity_Id;
1955 Stub_Type_Access : out Entity_Id;
1956 RPC_Receiver_Decl : out Node_Id;
1957 Body_Decls : out List_Id;
1958 Existing : out Boolean)
1959 is
1960 Loc : constant Source_Ptr := Sloc (RACW_Type);
1961
1962 Stub_Elements : constant Stub_Structure :=
1963 Stubs_Table.Get (Designated_Type);
1964 Stub_Type_Decl : Node_Id;
1965 Stub_Type_Access_Decl : Node_Id;
1966
1967 begin
1968 if Stub_Elements /= Empty_Stub_Structure then
1969 Stub_Type := Stub_Elements.Stub_Type;
1970 Stub_Type_Access := Stub_Elements.Stub_Type_Access;
1971 RPC_Receiver_Decl := Stub_Elements.RPC_Receiver_Decl;
1972 Body_Decls := Stub_Elements.Body_Decls;
1973 Existing := True;
1974 return;
1975 end if;
1976
1977 Existing := False;
1978 Stub_Type := Make_Temporary (Loc, 'S');
1979 Mutate_Ekind (Stub_Type, E_Record_Type);
1980 Set_Is_RACW_Stub_Type (Stub_Type);
1981 Stub_Type_Access :=
1982 Make_Defining_Identifier (Loc,
1983 Chars => New_External_Name
1984 (Related_Id => Chars (Stub_Type), Suffix => 'A'));
1985
1986 RPC_Receiver_Decl := Specific_RPC_Receiver_Decl (RACW_Type);
1987
1988 -- Create new stub type, copying components from generic RACW_Stub_Type
1989
1990 Stub_Type_Decl :=
1991 Make_Full_Type_Declaration (Loc,
1992 Defining_Identifier => Stub_Type,
1993 Type_Definition =>
1994 Make_Record_Definition (Loc,
1995 Tagged_Present => True,
1996 Limited_Present => True,
1997 Component_List =>
1998 Make_Component_List (Loc,
1999 Component_Items =>
2000 Copy_Component_List (RTE (RE_RACW_Stub_Type), Loc))));
2001
2002 -- Does the stub type need to explicitly implement interfaces from the
2003 -- designated type???
2004
2005 -- In particular are there issues in the case where the designated type
2006 -- is a synchronized interface???
2007
2008 Stub_Type_Access_Decl :=
2009 Make_Full_Type_Declaration (Loc,
2010 Defining_Identifier => Stub_Type_Access,
2011 Type_Definition =>
2012 Make_Access_To_Object_Definition (Loc,
2013 All_Present => True,
2014 Subtype_Indication => New_Occurrence_Of (Stub_Type, Loc)));
2015
2016 Append_To (Decls, Stub_Type_Decl);
2017 Analyze (Last (Decls));
2018 Append_To (Decls, Stub_Type_Access_Decl);
2019 Analyze (Last (Decls));
2020
2021 -- We can't directly derive the stub type from the designated type,
2022 -- because we don't want any components or discriminants from the real
2023 -- type, so instead we manually fake a derivation to get an appropriate
2024 -- dispatch table.
2025
2026 Derive_Subprograms (Parent_Type => Designated_Type,
2027 Derived_Type => Stub_Type);
2028
2029 if Present (RPC_Receiver_Decl) then
2030 Append_To (Decls, RPC_Receiver_Decl);
2031
2032 else
2033 -- Case of RACW implementing a RAS with the GARLIC PCS: there is
2034 -- no RPC receiver in that case, this is just an indication of
2035 -- where to insert code in the tree (see comment in declaration of
2036 -- type Stub_Structure).
2037
2038 RPC_Receiver_Decl := Last (Decls);
2039 end if;
2040
2041 Body_Decls := New_List;
2042
2043 Stubs_Table.Set (Designated_Type,
2044 (Stub_Type => Stub_Type,
2045 Stub_Type_Access => Stub_Type_Access,
2046 RPC_Receiver_Decl => RPC_Receiver_Decl,
2047 Body_Decls => Body_Decls,
2048 RACW_Type => RACW_Type));
2049 end Add_Stub_Type;
2050
2051 ------------------------
2052 -- Append_RACW_Bodies --
2053 ------------------------
2054
2055 procedure Append_RACW_Bodies (Decls : List_Id; Spec_Id : Entity_Id) is
2056 E : Entity_Id;
2057
2058 begin
2059 E := First_Entity (Spec_Id);
2060 while Present (E) loop
2061 if Is_Remote_Access_To_Class_Wide_Type (E) then
2062 Append_List_To (Decls, Get_And_Reset_RACW_Bodies (E));
2063 end if;
2064
2065 Next_Entity (E);
2066 end loop;
2067 end Append_RACW_Bodies;
2068
2069 ----------------------------------
2070 -- Assign_Subprogram_Identifier --
2071 ----------------------------------
2072
2073 procedure Assign_Subprogram_Identifier
2074 (Def : Entity_Id;
2075 Spn : Int;
2076 Id : out String_Id)
2077 is
2078 N : constant Name_Id := Chars (Def);
2079
2080 Overload_Order : constant Int := Overload_Counter_Table.Get (N) + 1;
2081
2082 begin
2083 Overload_Counter_Table.Set (N, Overload_Order);
2084
2085 Get_Name_String (N);
2086
2087 -- Homonym handling: as in Exp_Dbug, but much simpler, because the only
2088 -- entities for which we have to generate names here need only to be
2089 -- disambiguated within their own scope.
2090
2091 if Overload_Order > 1 then
2092 Add_Str_To_Name_Buffer ("__");
2093 Add_Nat_To_Name_Buffer (Overload_Order);
2094 end if;
2095
2096 Id := String_From_Name_Buffer;
2097 Subprogram_Identifier_Table.Set
2098 (Def,
2099 Subprogram_Identifiers'(Str_Identifier => Id, Int_Identifier => Spn));
2100 end Assign_Subprogram_Identifier;
2101
2102 -------------------------------------
2103 -- Build_Actual_Object_Declaration --
2104 -------------------------------------
2105
2106 procedure Build_Actual_Object_Declaration
2107 (Object : Entity_Id;
2108 Etyp : Entity_Id;
2109 Variable : Boolean;
2110 Expr : Node_Id;
2111 Decls : List_Id)
2112 is
2113 Loc : constant Source_Ptr := Sloc (Object);
2114
2115 begin
2116 -- Declare a temporary object for the actual, possibly initialized with
2117 -- a 'Input/From_Any call.
2118
2119 -- Complication arises in the case of limited types, for which such a
2120 -- declaration is illegal in Ada 95. In that case, we first generate a
2121 -- renaming declaration of the 'Input call, and then if needed we
2122 -- generate an overlaid non-constant view.
2123
2124 if Ada_Version <= Ada_95
2125 and then Is_Limited_Type (Etyp)
2126 and then Present (Expr)
2127 then
2128
2129 -- Object : Etyp renames <func-call>
2130
2131 Append_To (Decls,
2132 Make_Object_Renaming_Declaration (Loc,
2133 Defining_Identifier => Object,
2134 Subtype_Mark => New_Occurrence_Of (Etyp, Loc),
2135 Name => Expr));
2136
2137 if Variable then
2138
2139 -- The name defined by the renaming declaration denotes a
2140 -- constant view; create a non-constant object at the same address
2141 -- to be used as the actual.
2142
2143 declare
2144 Constant_Object : constant Entity_Id :=
2145 Make_Temporary (Loc, 'P');
2146
2147 begin
2148 Set_Defining_Identifier
2149 (Last (Decls), Constant_Object);
2150
2151 -- We have an unconstrained Etyp: build the actual constrained
2152 -- subtype for the value we just read from the stream.
2153
2154 -- subtype S is <actual subtype of Constant_Object>;
2155
2156 Append_To (Decls,
2157 Build_Actual_Subtype (Etyp,
2158 New_Occurrence_Of (Constant_Object, Loc)));
2159
2160 -- Object : S;
2161
2162 Append_To (Decls,
2163 Make_Object_Declaration (Loc,
2164 Defining_Identifier => Object,
2165 Object_Definition =>
2166 New_Occurrence_Of
2167 (Defining_Identifier (Last (Decls)), Loc)));
2168 Mutate_Ekind (Object, E_Variable);
2169
2170 -- Suppress default initialization:
2171 -- pragma Import (Ada, Object);
2172
2173 Append_To (Decls,
2174 Make_Pragma (Loc,
2175 Chars => Name_Import,
2176 Pragma_Argument_Associations => New_List (
2177 Make_Pragma_Argument_Association (Loc,
2178 Chars => Name_Convention,
2179 Expression => Make_Identifier (Loc, Name_Ada)),
2180 Make_Pragma_Argument_Association (Loc,
2181 Chars => Name_Entity,
2182 Expression => New_Occurrence_Of (Object, Loc)))));
2183
2184 -- for Object'Address use Constant_Object'Address;
2185
2186 Append_To (Decls,
2187 Make_Attribute_Definition_Clause (Loc,
2188 Name => New_Occurrence_Of (Object, Loc),
2189 Chars => Name_Address,
2190 Expression =>
2191 Make_Attribute_Reference (Loc,
2192 Prefix => New_Occurrence_Of (Constant_Object, Loc),
2193 Attribute_Name => Name_Address)));
2194 end;
2195 end if;
2196
2197 else
2198 -- General case of a regular object declaration. Object is flagged
2199 -- constant unless it has mode out or in out, to allow the backend
2200 -- to optimize where possible.
2201
2202 -- Object : [constant] Etyp [:= <expr>];
2203
2204 Append_To (Decls,
2205 Make_Object_Declaration (Loc,
2206 Defining_Identifier => Object,
2207 Constant_Present => Present (Expr) and then not Variable,
2208 Object_Definition => New_Occurrence_Of (Etyp, Loc),
2209 Expression => Expr));
2210
2211 if Constant_Present (Last (Decls)) then
2212 Mutate_Ekind (Object, E_Constant);
2213 else
2214 Mutate_Ekind (Object, E_Variable);
2215 end if;
2216 end if;
2217 end Build_Actual_Object_Declaration;
2218
2219 ------------------------------
2220 -- Build_Get_Unique_RP_Call --
2221 ------------------------------
2222
2223 function Build_Get_Unique_RP_Call
2224 (Loc : Source_Ptr;
2225 Pointer : Entity_Id;
2226 Stub_Type : Entity_Id) return List_Id
2227 is
2228 begin
2229 return New_List (
2230 Make_Procedure_Call_Statement (Loc,
2231 Name =>
2232 New_Occurrence_Of (RTE (RE_Get_Unique_Remote_Pointer), Loc),
2233 Parameter_Associations => New_List (
2234 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
2235 New_Occurrence_Of (Pointer, Loc)))),
2236
2237 Make_Assignment_Statement (Loc,
2238 Name =>
2239 Make_Selected_Component (Loc,
2240 Prefix => New_Occurrence_Of (Pointer, Loc),
2241 Selector_Name =>
2242 New_Occurrence_Of (First_Tag_Component
2243 (Designated_Type (Etype (Pointer))), Loc)),
2244 Expression =>
2245 Make_Attribute_Reference (Loc,
2246 Prefix => New_Occurrence_Of (Stub_Type, Loc),
2247 Attribute_Name => Name_Tag)));
2248
2249 -- Note: The assignment to Pointer._Tag is safe here because
2250 -- we carefully ensured that Stub_Type has exactly the same layout
2251 -- as System.Partition_Interface.RACW_Stub_Type.
2252
2253 end Build_Get_Unique_RP_Call;
2254
2255 -----------------------------------
2256 -- Build_Ordered_Parameters_List --
2257 -----------------------------------
2258
2259 function Build_Ordered_Parameters_List (Spec : Node_Id) return List_Id is
2260 Constrained_List : List_Id;
2261 Unconstrained_List : List_Id;
2262 Current_Parameter : Node_Id;
2263 Ptyp : Node_Id;
2264
2265 First_Parameter : Node_Id;
2266 For_RAS : Boolean := False;
2267
2268 begin
2269 if No (Parameter_Specifications (Spec)) then
2270 return New_List;
2271 end if;
2272
2273 Constrained_List := New_List;
2274 Unconstrained_List := New_List;
2275 First_Parameter := First (Parameter_Specifications (Spec));
2276
2277 if Nkind (Parameter_Type (First_Parameter)) = N_Access_Definition
2278 and then Chars (Defining_Identifier (First_Parameter)) = Name_uS
2279 then
2280 For_RAS := True;
2281 end if;
2282
2283 -- Loop through the parameters and add them to the right list. Note that
2284 -- we treat a parameter of a null-excluding access type as unconstrained
2285 -- because we can't declare an object of such a type with default
2286 -- initialization.
2287
2288 Current_Parameter := First_Parameter;
2289 while Present (Current_Parameter) loop
2290 Ptyp := Parameter_Type (Current_Parameter);
2291
2292 if (Nkind (Ptyp) = N_Access_Definition
2293 or else not Transmit_As_Unconstrained (Etype (Ptyp)))
2294 and then not (For_RAS and then Current_Parameter = First_Parameter)
2295 then
2296 Append_To (Constrained_List, New_Copy (Current_Parameter));
2297 else
2298 Append_To (Unconstrained_List, New_Copy (Current_Parameter));
2299 end if;
2300
2301 Next (Current_Parameter);
2302 end loop;
2303
2304 -- Unconstrained parameters are returned first
2305
2306 Append_List_To (Unconstrained_List, Constrained_List);
2307
2308 return Unconstrained_List;
2309 end Build_Ordered_Parameters_List;
2310
2311 ----------------------------------
2312 -- Build_Passive_Partition_Stub --
2313 ----------------------------------
2314
2315 procedure Build_Passive_Partition_Stub (U : Node_Id) is
2316 Pkg_Spec : Node_Id;
2317 Pkg_Ent : Entity_Id;
2318 L : List_Id;
2319 Reg : Node_Id;
2320 Loc : constant Source_Ptr := Sloc (U);
2321
2322 begin
2323 -- Verify that the implementation supports distribution, by accessing
2324 -- a type defined in the proper version of system.rpc
2325
2326 declare
2327 Dist_OK : Entity_Id;
2328 pragma Warnings (Off, Dist_OK);
2329 begin
2330 Dist_OK := RTE (RE_Params_Stream_Type);
2331 end;
2332
2333 -- Use body if present, spec otherwise
2334
2335 if Nkind (U) = N_Package_Declaration then
2336 Pkg_Spec := Specification (U);
2337 L := Visible_Declarations (Pkg_Spec);
2338 else
2339 Pkg_Spec := Parent (Corresponding_Spec (U));
2340 L := Declarations (U);
2341 end if;
2342 Pkg_Ent := Defining_Entity (Pkg_Spec);
2343
2344 Reg :=
2345 Make_Procedure_Call_Statement (Loc,
2346 Name =>
2347 New_Occurrence_Of (RTE (RE_Register_Passive_Package), Loc),
2348 Parameter_Associations => New_List (
2349 Make_String_Literal (Loc,
2350 Fully_Qualified_Name_String (Pkg_Ent, Append_NUL => False)),
2351 Make_Attribute_Reference (Loc,
2352 Prefix => New_Occurrence_Of (Pkg_Ent, Loc),
2353 Attribute_Name => Name_Version)));
2354 Append_To (L, Reg);
2355 Analyze (Reg);
2356 end Build_Passive_Partition_Stub;
2357
2358 --------------------------------------
2359 -- Build_RPC_Receiver_Specification --
2360 --------------------------------------
2361
2362 function Build_RPC_Receiver_Specification
2363 (RPC_Receiver : Entity_Id;
2364 Request_Parameter : Entity_Id) return Node_Id
2365 is
2366 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
2367 begin
2368 return
2369 Make_Procedure_Specification (Loc,
2370 Defining_Unit_Name => RPC_Receiver,
2371 Parameter_Specifications => New_List (
2372 Make_Parameter_Specification (Loc,
2373 Defining_Identifier => Request_Parameter,
2374 Parameter_Type =>
2375 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
2376 end Build_RPC_Receiver_Specification;
2377
2378 ----------------------------------------
2379 -- Build_Remote_Subprogram_Proxy_Type --
2380 ----------------------------------------
2381
2382 function Build_Remote_Subprogram_Proxy_Type
2383 (Loc : Source_Ptr;
2384 ACR_Expression : Node_Id) return Node_Id
2385 is
2386 begin
2387 return
2388 Make_Record_Definition (Loc,
2389 Tagged_Present => True,
2390 Limited_Present => True,
2391 Component_List =>
2392 Make_Component_List (Loc,
2393 Component_Items => New_List (
2394 Make_Component_Declaration (Loc,
2395 Defining_Identifier =>
2396 Make_Defining_Identifier (Loc,
2397 Name_All_Calls_Remote),
2398 Component_Definition =>
2399 Make_Component_Definition (Loc,
2400 Subtype_Indication =>
2401 New_Occurrence_Of (Standard_Boolean, Loc)),
2402 Expression =>
2403 ACR_Expression),
2404
2405 Make_Component_Declaration (Loc,
2406 Defining_Identifier =>
2407 Make_Defining_Identifier (Loc,
2408 Name_Receiver),
2409 Component_Definition =>
2410 Make_Component_Definition (Loc,
2411 Subtype_Indication =>
2412 New_Occurrence_Of (RTE (RE_Address), Loc)),
2413 Expression =>
2414 New_Occurrence_Of (RTE (RE_Null_Address), Loc)),
2415
2416 Make_Component_Declaration (Loc,
2417 Defining_Identifier =>
2418 Make_Defining_Identifier (Loc,
2419 Name_Subp_Id),
2420 Component_Definition =>
2421 Make_Component_Definition (Loc,
2422 Subtype_Indication =>
2423 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc))))));
2424 end Build_Remote_Subprogram_Proxy_Type;
2425
2426 --------------------
2427 -- Build_Stub_Tag --
2428 --------------------
2429
2430 function Build_Stub_Tag
2431 (Loc : Source_Ptr;
2432 RACW_Type : Entity_Id) return Node_Id
2433 is
2434 Stub_Type : constant Entity_Id := Corresponding_Stub_Type (RACW_Type);
2435 begin
2436 return
2437 Make_Attribute_Reference (Loc,
2438 Prefix => New_Occurrence_Of (Stub_Type, Loc),
2439 Attribute_Name => Name_Tag);
2440 end Build_Stub_Tag;
2441
2442 ------------------------------------
2443 -- Build_Subprogram_Calling_Stubs --
2444 ------------------------------------
2445
2446 function Build_Subprogram_Calling_Stubs
2447 (Vis_Decl : Node_Id;
2448 Subp_Id : Node_Id;
2449 Asynchronous : Boolean;
2450 Dynamically_Asynchronous : Boolean := False;
2451 Stub_Type : Entity_Id := Empty;
2452 RACW_Type : Entity_Id := Empty;
2453 Locator : Entity_Id := Empty;
2454 New_Name : Name_Id := No_Name) return Node_Id
2455 is
2456 Loc : constant Source_Ptr := Sloc (Vis_Decl);
2457
2458 Decls : constant List_Id := New_List;
2459 Statements : constant List_Id := New_List;
2460
2461 Subp_Spec : Node_Id;
2462 -- The specification of the body
2463
2464 Controlling_Parameter : Entity_Id := Empty;
2465
2466 Asynchronous_Expr : Node_Id := Empty;
2467
2468 RCI_Locator : Entity_Id;
2469
2470 Spec_To_Use : Node_Id;
2471
2472 procedure Insert_Partition_Check (Parameter : Node_Id);
2473 -- Check that the parameter has been elaborated on the same partition
2474 -- than the controlling parameter (E.4(19)).
2475
2476 ----------------------------
2477 -- Insert_Partition_Check --
2478 ----------------------------
2479
2480 procedure Insert_Partition_Check (Parameter : Node_Id) is
2481 Parameter_Entity : constant Entity_Id :=
2482 Defining_Identifier (Parameter);
2483 begin
2484 -- The expression that will be built is of the form:
2485
2486 -- if not Same_Partition (Parameter, Controlling_Parameter) then
2487 -- raise Constraint_Error;
2488 -- end if;
2489
2490 -- We do not check that Parameter is in Stub_Type since such a check
2491 -- has been inserted at the point of call already (a tag check since
2492 -- we have multiple controlling operands).
2493
2494 Append_To (Decls,
2495 Make_Raise_Constraint_Error (Loc,
2496 Condition =>
2497 Make_Op_Not (Loc,
2498 Right_Opnd =>
2499 Make_Function_Call (Loc,
2500 Name =>
2501 New_Occurrence_Of (RTE (RE_Same_Partition), Loc),
2502 Parameter_Associations =>
2503 New_List (
2504 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
2505 New_Occurrence_Of (Parameter_Entity, Loc)),
2506 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
2507 New_Occurrence_Of (Controlling_Parameter, Loc))))),
2508 Reason => CE_Partition_Check_Failed));
2509 end Insert_Partition_Check;
2510
2511 -- Start of processing for Build_Subprogram_Calling_Stubs
2512
2513 begin
2514 Subp_Spec :=
2515 Copy_Specification (Loc,
2516 Spec => Specification (Vis_Decl),
2517 New_Name => New_Name);
2518
2519 if Locator = Empty then
2520 RCI_Locator := RCI_Cache;
2521 Spec_To_Use := Specification (Vis_Decl);
2522 else
2523 RCI_Locator := Locator;
2524 Spec_To_Use := Subp_Spec;
2525 end if;
2526
2527 -- Find a controlling argument if we have a stub type. Also check
2528 -- if this subprogram can be made asynchronous.
2529
2530 if Present (Stub_Type)
2531 and then Present (Parameter_Specifications (Spec_To_Use))
2532 then
2533 declare
2534 Current_Parameter : Node_Id :=
2535 First (Parameter_Specifications
2536 (Spec_To_Use));
2537 begin
2538 while Present (Current_Parameter) loop
2539 if
2540 Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type)
2541 then
2542 if Controlling_Parameter = Empty then
2543 Controlling_Parameter :=
2544 Defining_Identifier (Current_Parameter);
2545 else
2546 Insert_Partition_Check (Current_Parameter);
2547 end if;
2548 end if;
2549
2550 Next (Current_Parameter);
2551 end loop;
2552 end;
2553 end if;
2554
2555 pragma Assert (No (Stub_Type) or else Present (Controlling_Parameter));
2556
2557 if Dynamically_Asynchronous then
2558 Asynchronous_Expr := Make_Selected_Component (Loc,
2559 Prefix => Controlling_Parameter,
2560 Selector_Name => Name_Asynchronous);
2561 end if;
2562
2563 Specific_Build_General_Calling_Stubs
2564 (Decls => Decls,
2565 Statements => Statements,
2566 Target => Specific_Build_Stub_Target (Loc,
2567 Decls, RCI_Locator, Controlling_Parameter),
2568 Subprogram_Id => Subp_Id,
2569 Asynchronous => Asynchronous_Expr,
2570 Is_Known_Asynchronous => Asynchronous
2571 and then not Dynamically_Asynchronous,
2572 Is_Known_Non_Asynchronous
2573 => not Asynchronous
2574 and then not Dynamically_Asynchronous,
2575 Is_Function => Nkind (Spec_To_Use) =
2576 N_Function_Specification,
2577 Spec => Spec_To_Use,
2578 Stub_Type => Stub_Type,
2579 RACW_Type => RACW_Type,
2580 Nod => Vis_Decl);
2581
2582 RCI_Calling_Stubs_Table.Set
2583 (Defining_Unit_Name (Specification (Vis_Decl)),
2584 Defining_Unit_Name (Spec_To_Use));
2585
2586 return
2587 Make_Subprogram_Body (Loc,
2588 Specification => Subp_Spec,
2589 Declarations => Decls,
2590 Handled_Statement_Sequence =>
2591 Make_Handled_Sequence_Of_Statements (Loc, Statements));
2592 end Build_Subprogram_Calling_Stubs;
2593
2594 -------------------------
2595 -- Build_Subprogram_Id --
2596 -------------------------
2597
2598 function Build_Subprogram_Id
2599 (Loc : Source_Ptr;
2600 E : Entity_Id) return Node_Id
2601 is
2602 begin
2603 if Get_Subprogram_Ids (E).Str_Identifier = No_String then
2604 declare
2605 Current_Declaration : Node_Id;
2606 Current_Subp : Entity_Id;
2607 Current_Subp_Str : String_Id;
2608 Current_Subp_Number : Int := First_RCI_Subprogram_Id;
2609
2610 pragma Warnings (Off, Current_Subp_Str);
2611
2612 begin
2613 -- Build_Subprogram_Id is called outside of the context of
2614 -- generating calling or receiving stubs. Hence we are processing
2615 -- an 'Access attribute_reference for an RCI subprogram, for the
2616 -- purpose of obtaining a RAS value.
2617
2618 pragma Assert
2619 (Is_Remote_Call_Interface (Scope (E))
2620 and then
2621 (Nkind (Parent (E)) = N_Procedure_Specification
2622 or else
2623 Nkind (Parent (E)) = N_Function_Specification));
2624
2625 Current_Declaration :=
2626 First (Visible_Declarations
2627 (Package_Specification_Of_Scope (Scope (E))));
2628 while Present (Current_Declaration) loop
2629 if Nkind (Current_Declaration) = N_Subprogram_Declaration
2630 and then Comes_From_Source (Current_Declaration)
2631 then
2632 Current_Subp := Defining_Unit_Name (Specification (
2633 Current_Declaration));
2634
2635 Assign_Subprogram_Identifier
2636 (Current_Subp, Current_Subp_Number, Current_Subp_Str);
2637
2638 Current_Subp_Number := Current_Subp_Number + 1;
2639 end if;
2640
2641 Next (Current_Declaration);
2642 end loop;
2643 end;
2644 end if;
2645
2646 case Get_PCS_Name is
2647 when Name_PolyORB_DSA =>
2648 return Make_String_Literal (Loc, Get_Subprogram_Id (E));
2649
2650 when others =>
2651 return Make_Integer_Literal (Loc, Get_Subprogram_Id (E));
2652 end case;
2653 end Build_Subprogram_Id;
2654
2655 ------------------------
2656 -- Copy_Specification --
2657 ------------------------
2658
2659 function Copy_Specification
2660 (Loc : Source_Ptr;
2661 Spec : Node_Id;
2662 Ctrl_Type : Entity_Id := Empty;
2663 New_Name : Name_Id := No_Name) return Node_Id
2664 is
2665 Parameters : List_Id := No_List;
2666
2667 Current_Parameter : Node_Id;
2668 Current_Identifier : Entity_Id;
2669 Current_Type : Node_Id;
2670
2671 Name_For_New_Spec : Name_Id;
2672
2673 New_Identifier : Entity_Id;
2674
2675 -- Comments needed in body below ???
2676
2677 begin
2678 if New_Name = No_Name then
2679 pragma Assert (Nkind (Spec) = N_Function_Specification
2680 or else Nkind (Spec) = N_Procedure_Specification);
2681
2682 Name_For_New_Spec := Chars (Defining_Unit_Name (Spec));
2683 else
2684 Name_For_New_Spec := New_Name;
2685 end if;
2686
2687 if Present (Parameter_Specifications (Spec)) then
2688 Parameters := New_List;
2689 Current_Parameter := First (Parameter_Specifications (Spec));
2690 while Present (Current_Parameter) loop
2691 Current_Identifier := Defining_Identifier (Current_Parameter);
2692 Current_Type := Parameter_Type (Current_Parameter);
2693
2694 if Nkind (Current_Type) = N_Access_Definition then
2695 if Present (Ctrl_Type) then
2696 pragma Assert (Is_Controlling_Formal (Current_Identifier));
2697 Current_Type :=
2698 Make_Access_Definition (Loc,
2699 Subtype_Mark => New_Occurrence_Of (Ctrl_Type, Loc),
2700 Null_Exclusion_Present =>
2701 Null_Exclusion_Present (Current_Type));
2702
2703 else
2704 Current_Type :=
2705 Make_Access_Definition (Loc,
2706 Subtype_Mark =>
2707 New_Copy_Tree (Subtype_Mark (Current_Type)),
2708 Null_Exclusion_Present =>
2709 Null_Exclusion_Present (Current_Type));
2710 end if;
2711
2712 else
2713 if Present (Ctrl_Type)
2714 and then Is_Controlling_Formal (Current_Identifier)
2715 then
2716 Current_Type := New_Occurrence_Of (Ctrl_Type, Loc);
2717 else
2718 Current_Type := New_Copy_Tree (Current_Type);
2719 end if;
2720 end if;
2721
2722 New_Identifier := Make_Defining_Identifier (Loc,
2723 Chars (Current_Identifier));
2724
2725 Append_To (Parameters,
2726 Make_Parameter_Specification (Loc,
2727 Defining_Identifier => New_Identifier,
2728 Parameter_Type => Current_Type,
2729 In_Present => In_Present (Current_Parameter),
2730 Out_Present => Out_Present (Current_Parameter),
2731 Expression =>
2732 New_Copy_Tree (Expression (Current_Parameter))));
2733
2734 -- For a regular formal parameter (that needs to be marshalled
2735 -- in the context of remote calls), set the Etype now, because
2736 -- marshalling processing might need it.
2737
2738 if Is_Entity_Name (Current_Type) then
2739 Set_Etype (New_Identifier, Entity (Current_Type));
2740
2741 -- Current_Type is an access definition, special processing
2742 -- (not requiring etype) will occur for marshalling.
2743
2744 else
2745 null;
2746 end if;
2747
2748 Next (Current_Parameter);
2749 end loop;
2750 end if;
2751
2752 case Nkind (Spec) is
2753 when N_Access_Function_Definition
2754 | N_Function_Specification
2755 =>
2756 return
2757 Make_Function_Specification (Loc,
2758 Defining_Unit_Name =>
2759 Make_Defining_Identifier (Loc,
2760 Chars => Name_For_New_Spec),
2761 Parameter_Specifications => Parameters,
2762 Result_Definition =>
2763 New_Occurrence_Of (Entity (Result_Definition (Spec)), Loc));
2764
2765 when N_Access_Procedure_Definition
2766 | N_Procedure_Specification
2767 =>
2768 return
2769 Make_Procedure_Specification (Loc,
2770 Defining_Unit_Name =>
2771 Make_Defining_Identifier (Loc,
2772 Chars => Name_For_New_Spec),
2773 Parameter_Specifications => Parameters);
2774
2775 when others =>
2776 raise Program_Error;
2777 end case;
2778 end Copy_Specification;
2779
2780 -----------------------------
2781 -- Corresponding_Stub_Type --
2782 -----------------------------
2783
2784 function Corresponding_Stub_Type (RACW_Type : Entity_Id) return Entity_Id is
2785 Desig : constant Entity_Id :=
2786 Etype (Designated_Type (RACW_Type));
2787 Stub_Elements : constant Stub_Structure := Stubs_Table.Get (Desig);
2788 begin
2789 return Stub_Elements.Stub_Type;
2790 end Corresponding_Stub_Type;
2791
2792 ---------------------------
2793 -- Could_Be_Asynchronous --
2794 ---------------------------
2795
2796 function Could_Be_Asynchronous (Spec : Node_Id) return Boolean is
2797 Current_Parameter : Node_Id;
2798
2799 begin
2800 if Present (Parameter_Specifications (Spec)) then
2801 Current_Parameter := First (Parameter_Specifications (Spec));
2802 while Present (Current_Parameter) loop
2803 if Out_Present (Current_Parameter) then
2804 return False;
2805 end if;
2806
2807 Next (Current_Parameter);
2808 end loop;
2809 end if;
2810
2811 return True;
2812 end Could_Be_Asynchronous;
2813
2814 ---------------------------
2815 -- Declare_Create_NVList --
2816 ---------------------------
2817
2818 procedure Declare_Create_NVList
2819 (Loc : Source_Ptr;
2820 NVList : Entity_Id;
2821 Decls : List_Id;
2822 Stmts : List_Id)
2823 is
2824 begin
2825 Append_To (Decls,
2826 Make_Object_Declaration (Loc,
2827 Defining_Identifier => NVList,
2828 Object_Definition =>
2829 New_Occurrence_Of (RTE (RE_NVList_Ref), Loc)));
2830
2831 Append_To (Stmts,
2832 Make_Procedure_Call_Statement (Loc,
2833 Name => New_Occurrence_Of (RTE (RE_NVList_Create), Loc),
2834 Parameter_Associations => New_List (
2835 New_Occurrence_Of (NVList, Loc))));
2836 end Declare_Create_NVList;
2837
2838 ---------------------------------------------
2839 -- Expand_All_Calls_Remote_Subprogram_Call --
2840 ---------------------------------------------
2841
2842 procedure Expand_All_Calls_Remote_Subprogram_Call (N : Node_Id) is
2843 Loc : constant Source_Ptr := Sloc (N);
2844 Called_Subprogram : constant Entity_Id := Entity (Name (N));
2845 RCI_Package : constant Entity_Id := Scope (Called_Subprogram);
2846 RCI_Locator_Decl : Node_Id;
2847 RCI_Locator : Entity_Id;
2848 Calling_Stubs : Node_Id;
2849 E_Calling_Stubs : Entity_Id;
2850
2851 begin
2852 E_Calling_Stubs := RCI_Calling_Stubs_Table.Get (Called_Subprogram);
2853
2854 if E_Calling_Stubs = Empty then
2855 RCI_Locator := RCI_Locator_Table.Get (RCI_Package);
2856
2857 -- The RCI_Locator package and calling stub are inserted at the top
2858 -- level in the current unit, and must appear in the proper scope so
2859 -- that it is not prematurely removed by the GCC back end.
2860
2861 declare
2862 Scop : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
2863 begin
2864 if Ekind (Scop) = E_Package_Body then
2865 Push_Scope (Spec_Entity (Scop));
2866 elsif Ekind (Scop) = E_Subprogram_Body then
2867 Push_Scope
2868 (Corresponding_Spec (Unit_Declaration_Node (Scop)));
2869 else
2870 Push_Scope (Scop);
2871 end if;
2872 end;
2873
2874 if RCI_Locator = Empty then
2875 RCI_Locator_Decl :=
2876 RCI_Package_Locator (Loc, Package_Specification (RCI_Package));
2877 Prepend_To (Current_Sem_Unit_Declarations, RCI_Locator_Decl);
2878 Analyze (RCI_Locator_Decl);
2879 RCI_Locator := Defining_Unit_Name (RCI_Locator_Decl);
2880
2881 else
2882 RCI_Locator_Decl := Parent (RCI_Locator);
2883 end if;
2884
2885 Calling_Stubs := Build_Subprogram_Calling_Stubs
2886 (Vis_Decl => Parent (Parent (Called_Subprogram)),
2887 Subp_Id =>
2888 Build_Subprogram_Id (Loc, Called_Subprogram),
2889 Asynchronous => Nkind (N) = N_Procedure_Call_Statement
2890 and then
2891 Is_Asynchronous (Called_Subprogram),
2892 Locator => RCI_Locator,
2893 New_Name => New_Internal_Name ('S'));
2894 Insert_After (RCI_Locator_Decl, Calling_Stubs);
2895 Analyze (Calling_Stubs);
2896 Pop_Scope;
2897
2898 E_Calling_Stubs := Defining_Unit_Name (Specification (Calling_Stubs));
2899 end if;
2900
2901 Rewrite (Name (N), New_Occurrence_Of (E_Calling_Stubs, Loc));
2902 end Expand_All_Calls_Remote_Subprogram_Call;
2903
2904 ---------------------------------
2905 -- Expand_Calling_Stubs_Bodies --
2906 ---------------------------------
2907
2908 procedure Expand_Calling_Stubs_Bodies (Unit_Node : Node_Id) is
2909 Spec : constant Node_Id := Specification (Unit_Node);
2910 begin
2911 Add_Calling_Stubs_To_Declarations (Spec);
2912 end Expand_Calling_Stubs_Bodies;
2913
2914 -----------------------------------
2915 -- Expand_Receiving_Stubs_Bodies --
2916 -----------------------------------
2917
2918 procedure Expand_Receiving_Stubs_Bodies (Unit_Node : Node_Id) is
2919 Spec : Node_Id;
2920 Decls : List_Id;
2921 Stubs_Decls : List_Id;
2922 Stubs_Stmts : List_Id;
2923
2924 begin
2925 if Nkind (Unit_Node) = N_Package_Declaration then
2926 Spec := Specification (Unit_Node);
2927 Decls := Private_Declarations (Spec);
2928
2929 if No (Decls) then
2930 Decls := Visible_Declarations (Spec);
2931 end if;
2932
2933 Push_Scope (Scope_Of_Spec (Spec));
2934 Specific_Add_Receiving_Stubs_To_Declarations (Spec, Decls, Decls);
2935
2936 else
2937 Spec :=
2938 Package_Specification_Of_Scope (Corresponding_Spec (Unit_Node));
2939 Decls := Declarations (Unit_Node);
2940
2941 Push_Scope (Scope_Of_Spec (Unit_Node));
2942 Stubs_Decls := New_List;
2943 Stubs_Stmts := New_List;
2944 Specific_Add_Receiving_Stubs_To_Declarations
2945 (Spec, Stubs_Decls, Stubs_Stmts);
2946
2947 Insert_List_Before (First (Decls), Stubs_Decls);
2948
2949 declare
2950 HSS_Stmts : constant List_Id :=
2951 Statements (Handled_Statement_Sequence (Unit_Node));
2952
2953 First_HSS_Stmt : constant Node_Id := First (HSS_Stmts);
2954
2955 begin
2956 if No (First_HSS_Stmt) then
2957 Append_List_To (HSS_Stmts, Stubs_Stmts);
2958 else
2959 Insert_List_Before (First_HSS_Stmt, Stubs_Stmts);
2960 end if;
2961 end;
2962 end if;
2963
2964 Pop_Scope;
2965 end Expand_Receiving_Stubs_Bodies;
2966
2967 --------------------
2968 -- GARLIC_Support --
2969 --------------------
2970
2971 package body GARLIC_Support is
2972
2973 -- Local subprograms
2974
2975 procedure Add_RACW_Read_Attribute
2976 (RACW_Type : Entity_Id;
2977 Stub_Type : Entity_Id;
2978 Stub_Type_Access : Entity_Id;
2979 Body_Decls : List_Id);
2980 -- Add Read attribute for the RACW type. The declaration and attribute
2981 -- definition clauses are inserted right after the declaration of
2982 -- RACW_Type. If Body_Decls is not No_List, the subprogram body is
2983 -- appended to it (case where the RACW declaration is in the main unit).
2984
2985 procedure Add_RACW_Write_Attribute
2986 (RACW_Type : Entity_Id;
2987 Stub_Type : Entity_Id;
2988 Stub_Type_Access : Entity_Id;
2989 RPC_Receiver : Node_Id;
2990 Body_Decls : List_Id);
2991 -- Same as above for the Write attribute
2992
2993 function Stream_Parameter return Node_Id;
2994 function Result return Node_Id;
2995 function Object return Node_Id renames Result;
2996 -- Functions to create occurrences of the formal parameter names of the
2997 -- 'Read and 'Write attributes.
2998
2999 Loc : Source_Ptr;
3000 -- Shared source location used by Add_{Read,Write}_Read_Attribute and
3001 -- their ancillary subroutines (set on entry by Add_RACW_Features).
3002
3003 procedure Add_RAS_Access_TSS (N : Node_Id);
3004 -- Add a subprogram body for RAS Access TSS
3005
3006 -------------------------------------
3007 -- Add_Obj_RPC_Receiver_Completion --
3008 -------------------------------------
3009
3010 procedure Add_Obj_RPC_Receiver_Completion
3011 (Loc : Source_Ptr;
3012 Decls : List_Id;
3013 RPC_Receiver : Entity_Id;
3014 Stub_Elements : Stub_Structure)
3015 is
3016 begin
3017 -- The RPC receiver body should not be the completion of the
3018 -- declaration recorded in the stub structure, because then the
3019 -- occurrences of the formal parameters within the body should refer
3020 -- to the entities from the declaration, not from the completion, to
3021 -- which we do not have easy access. Instead, the RPC receiver body
3022 -- acts as its own declaration, and the RPC receiver declaration is
3023 -- completed by a renaming-as-body.
3024
3025 Append_To (Decls,
3026 Make_Subprogram_Renaming_Declaration (Loc,
3027 Specification =>
3028 Copy_Specification (Loc,
3029 Specification (Stub_Elements.RPC_Receiver_Decl)),
3030 Name => New_Occurrence_Of (RPC_Receiver, Loc)));
3031 end Add_Obj_RPC_Receiver_Completion;
3032
3033 -----------------------
3034 -- Add_RACW_Features --
3035 -----------------------
3036
3037 procedure Add_RACW_Features
3038 (RACW_Type : Entity_Id;
3039 Stub_Type : Entity_Id;
3040 Stub_Type_Access : Entity_Id;
3041 RPC_Receiver_Decl : Node_Id;
3042 Body_Decls : List_Id)
3043 is
3044 RPC_Receiver : Node_Id;
3045 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
3046
3047 begin
3048 Loc := Sloc (RACW_Type);
3049
3050 if Is_RAS then
3051
3052 -- For a RAS, the RPC receiver is that of the RCI unit, not that
3053 -- of the corresponding distributed object type. We retrieve its
3054 -- address from the local proxy object.
3055
3056 RPC_Receiver := Make_Selected_Component (Loc,
3057 Prefix =>
3058 Unchecked_Convert_To (RTE (RE_RAS_Proxy_Type_Access), Object),
3059 Selector_Name => Make_Identifier (Loc, Name_Receiver));
3060
3061 else
3062 RPC_Receiver := Make_Attribute_Reference (Loc,
3063 Prefix => New_Occurrence_Of (
3064 Defining_Unit_Name (Specification (RPC_Receiver_Decl)), Loc),
3065 Attribute_Name => Name_Address);
3066 end if;
3067
3068 Add_RACW_Write_Attribute
3069 (RACW_Type,
3070 Stub_Type,
3071 Stub_Type_Access,
3072 RPC_Receiver,
3073 Body_Decls);
3074
3075 Add_RACW_Read_Attribute
3076 (RACW_Type,
3077 Stub_Type,
3078 Stub_Type_Access,
3079 Body_Decls);
3080 end Add_RACW_Features;
3081
3082 -----------------------------
3083 -- Add_RACW_Read_Attribute --
3084 -----------------------------
3085
3086 procedure Add_RACW_Read_Attribute
3087 (RACW_Type : Entity_Id;
3088 Stub_Type : Entity_Id;
3089 Stub_Type_Access : Entity_Id;
3090 Body_Decls : List_Id)
3091 is
3092 Proc_Decl : Node_Id;
3093 Attr_Decl : Node_Id;
3094
3095 Body_Node : Node_Id;
3096
3097 Statements : constant List_Id := New_List;
3098 Decls : List_Id;
3099 Local_Statements : List_Id;
3100 Remote_Statements : List_Id;
3101 -- Various parts of the procedure
3102
3103 Pnam : constant Entity_Id := Make_Temporary (Loc, 'R');
3104 Asynchronous_Flag : constant Entity_Id :=
3105 Asynchronous_Flags_Table.Get (RACW_Type);
3106 pragma Assert (Present (Asynchronous_Flag));
3107
3108 -- Prepare local identifiers
3109
3110 Source_Partition : Entity_Id;
3111 Source_Receiver : Entity_Id;
3112 Source_Address : Entity_Id;
3113 Local_Stub : Entity_Id;
3114 Stubbed_Result : Entity_Id;
3115
3116 -- Start of processing for Add_RACW_Read_Attribute
3117
3118 begin
3119 Build_Stream_Procedure
3120 (RACW_Type, Body_Node, Pnam, Statements, Outp => True);
3121 Proc_Decl := Make_Subprogram_Declaration (Loc,
3122 Copy_Specification (Loc, Specification (Body_Node)));
3123
3124 Attr_Decl :=
3125 Make_Attribute_Definition_Clause (Loc,
3126 Name => New_Occurrence_Of (RACW_Type, Loc),
3127 Chars => Name_Read,
3128 Expression =>
3129 New_Occurrence_Of (
3130 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
3131
3132 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
3133 Insert_After (Proc_Decl, Attr_Decl);
3134
3135 if No (Body_Decls) then
3136
3137 -- Case of processing an RACW type from another unit than the
3138 -- main one: do not generate a body.
3139
3140 return;
3141 end if;
3142
3143 -- Prepare local identifiers
3144
3145 Source_Partition := Make_Temporary (Loc, 'P');
3146 Source_Receiver := Make_Temporary (Loc, 'S');
3147 Source_Address := Make_Temporary (Loc, 'P');
3148 Local_Stub := Make_Temporary (Loc, 'L');
3149 Stubbed_Result := Make_Temporary (Loc, 'S');
3150
3151 -- Generate object declarations
3152
3153 Decls := New_List (
3154 Make_Object_Declaration (Loc,
3155 Defining_Identifier => Source_Partition,
3156 Object_Definition =>
3157 New_Occurrence_Of (RTE (RE_Partition_ID), Loc)),
3158
3159 Make_Object_Declaration (Loc,
3160 Defining_Identifier => Source_Receiver,
3161 Object_Definition =>
3162 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
3163
3164 Make_Object_Declaration (Loc,
3165 Defining_Identifier => Source_Address,
3166 Object_Definition =>
3167 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
3168
3169 Make_Object_Declaration (Loc,
3170 Defining_Identifier => Local_Stub,
3171 Aliased_Present => True,
3172 Object_Definition => New_Occurrence_Of (Stub_Type, Loc)),
3173
3174 Make_Object_Declaration (Loc,
3175 Defining_Identifier => Stubbed_Result,
3176 Object_Definition =>
3177 New_Occurrence_Of (Stub_Type_Access, Loc),
3178 Expression =>
3179 Make_Attribute_Reference (Loc,
3180 Prefix =>
3181 New_Occurrence_Of (Local_Stub, Loc),
3182 Attribute_Name =>
3183 Name_Unchecked_Access)));
3184
3185 -- Read the source Partition_ID and RPC_Receiver from incoming stream
3186
3187 Append_List_To (Statements, New_List (
3188 Make_Attribute_Reference (Loc,
3189 Prefix =>
3190 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
3191 Attribute_Name => Name_Read,
3192 Expressions => New_List (
3193 Stream_Parameter,
3194 New_Occurrence_Of (Source_Partition, Loc))),
3195
3196 Make_Attribute_Reference (Loc,
3197 Prefix =>
3198 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
3199 Attribute_Name =>
3200 Name_Read,
3201 Expressions => New_List (
3202 Stream_Parameter,
3203 New_Occurrence_Of (Source_Receiver, Loc))),
3204
3205 Make_Attribute_Reference (Loc,
3206 Prefix =>
3207 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
3208 Attribute_Name =>
3209 Name_Read,
3210 Expressions => New_List (
3211 Stream_Parameter,
3212 New_Occurrence_Of (Source_Address, Loc)))));
3213
3214 -- Build_Get_Unique_RP_Call needs the type of Stubbed_Result
3215
3216 Set_Etype (Stubbed_Result, Stub_Type_Access);
3217
3218 -- If the Address is Null_Address, then return a null object, unless
3219 -- RACW_Type is null-excluding, in which case unconditionally raise
3220 -- CONSTRAINT_ERROR instead.
3221
3222 declare
3223 Zero_Statements : List_Id;
3224 -- Statements executed when a zero value is received
3225
3226 begin
3227 if Can_Never_Be_Null (RACW_Type) then
3228 Zero_Statements := New_List (
3229 Make_Raise_Constraint_Error (Loc,
3230 Reason => CE_Null_Not_Allowed));
3231 else
3232 Zero_Statements := New_List (
3233 Make_Assignment_Statement (Loc,
3234 Name => Result,
3235 Expression => Make_Null (Loc)),
3236 Make_Simple_Return_Statement (Loc));
3237 end if;
3238
3239 Append_To (Statements,
3240 Make_Implicit_If_Statement (RACW_Type,
3241 Condition =>
3242 Make_Op_Eq (Loc,
3243 Left_Opnd => New_Occurrence_Of (Source_Address, Loc),
3244 Right_Opnd => Make_Integer_Literal (Loc, Uint_0)),
3245 Then_Statements => Zero_Statements));
3246 end;
3247
3248 -- If the RACW denotes an object created on the current partition,
3249 -- Local_Statements will be executed. The real object will be used.
3250
3251 Local_Statements := New_List (
3252 Make_Assignment_Statement (Loc,
3253 Name => Result,
3254 Expression =>
3255 Unchecked_Convert_To (RACW_Type,
3256 OK_Convert_To (RTE (RE_Address),
3257 New_Occurrence_Of (Source_Address, Loc)))));
3258
3259 -- If the object is located on another partition, then a stub object
3260 -- will be created with all the information needed to rebuild the
3261 -- real object at the other end.
3262
3263 Remote_Statements := New_List (
3264
3265 Make_Assignment_Statement (Loc,
3266 Name => Make_Selected_Component (Loc,
3267 Prefix => Stubbed_Result,
3268 Selector_Name => Name_Origin),
3269 Expression =>
3270 New_Occurrence_Of (Source_Partition, Loc)),
3271
3272 Make_Assignment_Statement (Loc,
3273 Name => Make_Selected_Component (Loc,
3274 Prefix => Stubbed_Result,
3275 Selector_Name => Name_Receiver),
3276 Expression =>
3277 New_Occurrence_Of (Source_Receiver, Loc)),
3278
3279 Make_Assignment_Statement (Loc,
3280 Name => Make_Selected_Component (Loc,
3281 Prefix => Stubbed_Result,
3282 Selector_Name => Name_Addr),
3283 Expression =>
3284 New_Occurrence_Of (Source_Address, Loc)));
3285
3286 Append_To (Remote_Statements,
3287 Make_Assignment_Statement (Loc,
3288 Name => Make_Selected_Component (Loc,
3289 Prefix => Stubbed_Result,
3290 Selector_Name => Name_Asynchronous),
3291 Expression =>
3292 New_Occurrence_Of (Asynchronous_Flag, Loc)));
3293
3294 Append_List_To (Remote_Statements,
3295 Build_Get_Unique_RP_Call (Loc, Stubbed_Result, Stub_Type));
3296 -- ??? Issue with asynchronous calls here: the Asynchronous flag is
3297 -- set on the stub type if, and only if, the RACW type has a pragma
3298 -- Asynchronous. This is incorrect for RACWs that implement RAS
3299 -- types, because in that case the /designated subprogram/ (not the
3300 -- type) might be asynchronous, and that causes the stub to need to
3301 -- be asynchronous too. A solution is to transport a RAS as a struct
3302 -- containing a RACW and an asynchronous flag, and to properly alter
3303 -- the Asynchronous component in the stub type in the RAS's Input
3304 -- TSS.
3305
3306 Append_To (Remote_Statements,
3307 Make_Assignment_Statement (Loc,
3308 Name => Result,
3309 Expression => Unchecked_Convert_To (RACW_Type,
3310 New_Occurrence_Of (Stubbed_Result, Loc))));
3311
3312 -- Distinguish between the local and remote cases, and execute the
3313 -- appropriate piece of code.
3314
3315 Append_To (Statements,
3316 Make_Implicit_If_Statement (RACW_Type,
3317 Condition =>
3318 Make_Op_Eq (Loc,
3319 Left_Opnd =>
3320 Make_Function_Call (Loc,
3321 Name => New_Occurrence_Of (
3322 RTE (RE_Get_Local_Partition_Id), Loc)),
3323 Right_Opnd => New_Occurrence_Of (Source_Partition, Loc)),
3324 Then_Statements => Local_Statements,
3325 Else_Statements => Remote_Statements));
3326
3327 Set_Declarations (Body_Node, Decls);
3328 Append_To (Body_Decls, Body_Node);
3329 end Add_RACW_Read_Attribute;
3330
3331 ------------------------------
3332 -- Add_RACW_Write_Attribute --
3333 ------------------------------
3334
3335 procedure Add_RACW_Write_Attribute
3336 (RACW_Type : Entity_Id;
3337 Stub_Type : Entity_Id;
3338 Stub_Type_Access : Entity_Id;
3339 RPC_Receiver : Node_Id;
3340 Body_Decls : List_Id)
3341 is
3342 Body_Node : Node_Id;
3343 Proc_Decl : Node_Id;
3344 Attr_Decl : Node_Id;
3345
3346 Statements : constant List_Id := New_List;
3347 Local_Statements : List_Id;
3348 Remote_Statements : List_Id;
3349 Null_Statements : List_Id;
3350
3351 Pnam : constant Entity_Id := Make_Temporary (Loc, 'R');
3352
3353 begin
3354 Build_Stream_Procedure
3355 (RACW_Type, Body_Node, Pnam, Statements, Outp => False);
3356
3357 Proc_Decl := Make_Subprogram_Declaration (Loc,
3358 Copy_Specification (Loc, Specification (Body_Node)));
3359
3360 Attr_Decl :=
3361 Make_Attribute_Definition_Clause (Loc,
3362 Name => New_Occurrence_Of (RACW_Type, Loc),
3363 Chars => Name_Write,
3364 Expression =>
3365 New_Occurrence_Of (
3366 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
3367
3368 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
3369 Insert_After (Proc_Decl, Attr_Decl);
3370
3371 if No (Body_Decls) then
3372 return;
3373 end if;
3374
3375 -- Build the code fragment corresponding to the marshalling of a
3376 -- local object.
3377
3378 Local_Statements := New_List (
3379
3380 Pack_Entity_Into_Stream_Access (Loc,
3381 Stream => Stream_Parameter,
3382 Object => RTE (RE_Get_Local_Partition_Id)),
3383
3384 Pack_Node_Into_Stream_Access (Loc,
3385 Stream => Stream_Parameter,
3386 Object => OK_Convert_To (RTE (RE_Unsigned_64), RPC_Receiver),
3387 Etyp => RTE (RE_Unsigned_64)),
3388
3389 Pack_Node_Into_Stream_Access (Loc,
3390 Stream => Stream_Parameter,
3391 Object => OK_Convert_To (RTE (RE_Unsigned_64),
3392 Make_Attribute_Reference (Loc,
3393 Prefix =>
3394 Make_Explicit_Dereference (Loc,
3395 Prefix => Object),
3396 Attribute_Name => Name_Address)),
3397 Etyp => RTE (RE_Unsigned_64)));
3398
3399 -- Build the code fragment corresponding to the marshalling of
3400 -- a remote object.
3401
3402 Remote_Statements := New_List (
3403 Pack_Node_Into_Stream_Access (Loc,
3404 Stream => Stream_Parameter,
3405 Object =>
3406 Make_Selected_Component (Loc,
3407 Prefix =>
3408 Unchecked_Convert_To (Stub_Type_Access, Object),
3409 Selector_Name => Make_Identifier (Loc, Name_Origin)),
3410 Etyp => RTE (RE_Partition_ID)),
3411
3412 Pack_Node_Into_Stream_Access (Loc,
3413 Stream => Stream_Parameter,
3414 Object =>
3415 Make_Selected_Component (Loc,
3416 Prefix =>
3417 Unchecked_Convert_To (Stub_Type_Access, Object),
3418 Selector_Name => Make_Identifier (Loc, Name_Receiver)),
3419 Etyp => RTE (RE_Unsigned_64)),
3420
3421 Pack_Node_Into_Stream_Access (Loc,
3422 Stream => Stream_Parameter,
3423 Object =>
3424 Make_Selected_Component (Loc,
3425 Prefix =>
3426 Unchecked_Convert_To (Stub_Type_Access, Object),
3427 Selector_Name => Make_Identifier (Loc, Name_Addr)),
3428 Etyp => RTE (RE_Unsigned_64)));
3429
3430 -- Build code fragment corresponding to marshalling of a null object
3431
3432 Null_Statements := New_List (
3433
3434 Pack_Entity_Into_Stream_Access (Loc,
3435 Stream => Stream_Parameter,
3436 Object => RTE (RE_Get_Local_Partition_Id)),
3437
3438 Pack_Node_Into_Stream_Access (Loc,
3439 Stream => Stream_Parameter,
3440 Object => OK_Convert_To (RTE (RE_Unsigned_64), RPC_Receiver),
3441 Etyp => RTE (RE_Unsigned_64)),
3442
3443 Pack_Node_Into_Stream_Access (Loc,
3444 Stream => Stream_Parameter,
3445 Object => Make_Integer_Literal (Loc, Uint_0),
3446 Etyp => RTE (RE_Unsigned_64)));
3447
3448 Append_To (Statements,
3449 Make_Implicit_If_Statement (RACW_Type,
3450 Condition =>
3451 Make_Op_Eq (Loc,
3452 Left_Opnd => Object,
3453 Right_Opnd => Make_Null (Loc)),
3454
3455 Then_Statements => Null_Statements,
3456
3457 Elsif_Parts => New_List (
3458 Make_Elsif_Part (Loc,
3459 Condition =>
3460 Make_Op_Eq (Loc,
3461 Left_Opnd =>
3462 Make_Attribute_Reference (Loc,
3463 Prefix => Object,
3464 Attribute_Name => Name_Tag),
3465
3466 Right_Opnd =>
3467 Make_Attribute_Reference (Loc,
3468 Prefix => New_Occurrence_Of (Stub_Type, Loc),
3469 Attribute_Name => Name_Tag)),
3470 Then_Statements => Remote_Statements)),
3471 Else_Statements => Local_Statements));
3472
3473 Append_To (Body_Decls, Body_Node);
3474 end Add_RACW_Write_Attribute;
3475
3476 ------------------------
3477 -- Add_RAS_Access_TSS --
3478 ------------------------
3479
3480 procedure Add_RAS_Access_TSS (N : Node_Id) is
3481 Loc : constant Source_Ptr := Sloc (N);
3482
3483 Ras_Type : constant Entity_Id := Defining_Identifier (N);
3484 Fat_Type : constant Entity_Id := Equivalent_Type (Ras_Type);
3485 -- Ras_Type is the access to subprogram type while Fat_Type is the
3486 -- corresponding record type.
3487
3488 RACW_Type : constant Entity_Id :=
3489 Underlying_RACW_Type (Ras_Type);
3490 Desig : constant Entity_Id :=
3491 Etype (Designated_Type (RACW_Type));
3492
3493 Stub_Elements : constant Stub_Structure :=
3494 Stubs_Table.Get (Desig);
3495 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
3496
3497 Proc : constant Entity_Id :=
3498 Make_Defining_Identifier (Loc,
3499 Chars => Make_TSS_Name (Ras_Type, TSS_RAS_Access));
3500
3501 Proc_Spec : Node_Id;
3502
3503 -- Formal parameters
3504
3505 Package_Name : constant Entity_Id :=
3506 Make_Defining_Identifier (Loc,
3507 Chars => Name_P);
3508 -- Target package
3509
3510 Subp_Id : constant Entity_Id :=
3511 Make_Defining_Identifier (Loc,
3512 Chars => Name_S);
3513 -- Target subprogram
3514
3515 Asynch_P : constant Entity_Id :=
3516 Make_Defining_Identifier (Loc,
3517 Chars => Name_Asynchronous);
3518 -- Is the procedure to which the 'Access applies asynchronous?
3519
3520 All_Calls_Remote : constant Entity_Id :=
3521 Make_Defining_Identifier (Loc,
3522 Chars => Name_All_Calls_Remote);
3523 -- True if an All_Calls_Remote pragma applies to the RCI unit
3524 -- that contains the subprogram.
3525
3526 -- Common local variables
3527
3528 Proc_Decls : List_Id;
3529 Proc_Statements : List_Id;
3530
3531 Origin : constant Entity_Id := Make_Temporary (Loc, 'P');
3532
3533 -- Additional local variables for the local case
3534
3535 Proxy_Addr : constant Entity_Id := Make_Temporary (Loc, 'P');
3536
3537 -- Additional local variables for the remote case
3538
3539 Local_Stub : constant Entity_Id := Make_Temporary (Loc, 'L');
3540 Stub_Ptr : constant Entity_Id := Make_Temporary (Loc, 'S');
3541
3542 function Set_Field
3543 (Field_Name : Name_Id;
3544 Value : Node_Id) return Node_Id;
3545 -- Construct an assignment that sets the named component in the
3546 -- returned record
3547
3548 ---------------
3549 -- Set_Field --
3550 ---------------
3551
3552 function Set_Field
3553 (Field_Name : Name_Id;
3554 Value : Node_Id) return Node_Id
3555 is
3556 begin
3557 return
3558 Make_Assignment_Statement (Loc,
3559 Name =>
3560 Make_Selected_Component (Loc,
3561 Prefix => Stub_Ptr,
3562 Selector_Name => Field_Name),
3563 Expression => Value);
3564 end Set_Field;
3565
3566 -- Start of processing for Add_RAS_Access_TSS
3567
3568 begin
3569 Proc_Decls := New_List (
3570
3571 -- Common declarations
3572
3573 Make_Object_Declaration (Loc,
3574 Defining_Identifier => Origin,
3575 Constant_Present => True,
3576 Object_Definition =>
3577 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
3578 Expression =>
3579 Make_Function_Call (Loc,
3580 Name =>
3581 New_Occurrence_Of (RTE (RE_Get_Active_Partition_Id), Loc),
3582 Parameter_Associations => New_List (
3583 New_Occurrence_Of (Package_Name, Loc)))),
3584
3585 -- Declaration use only in the local case: proxy address
3586
3587 Make_Object_Declaration (Loc,
3588 Defining_Identifier => Proxy_Addr,
3589 Object_Definition =>
3590 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
3591
3592 -- Declarations used only in the remote case: stub object and
3593 -- stub pointer.
3594
3595 Make_Object_Declaration (Loc,
3596 Defining_Identifier => Local_Stub,
3597 Aliased_Present => True,
3598 Object_Definition =>
3599 New_Occurrence_Of (Stub_Elements.Stub_Type, Loc)),
3600
3601 Make_Object_Declaration (Loc,
3602 Defining_Identifier =>
3603 Stub_Ptr,
3604 Object_Definition =>
3605 New_Occurrence_Of (Stub_Elements.Stub_Type_Access, Loc),
3606 Expression =>
3607 Make_Attribute_Reference (Loc,
3608 Prefix => New_Occurrence_Of (Local_Stub, Loc),
3609 Attribute_Name => Name_Unchecked_Access)));
3610
3611 Set_Etype (Stub_Ptr, Stub_Elements.Stub_Type_Access);
3612
3613 -- Build_Get_Unique_RP_Call needs above information
3614
3615 -- Note: Here we assume that the Fat_Type is a record
3616 -- containing just a pointer to a proxy or stub object.
3617
3618 Proc_Statements := New_List (
3619
3620 -- Generate:
3621
3622 -- Get_RAS_Info (Pkg, Subp, PA);
3623 -- if Origin = Local_Partition_Id
3624 -- and then not All_Calls_Remote
3625 -- then
3626 -- return Fat_Type!(PA);
3627 -- end if;
3628
3629 Make_Procedure_Call_Statement (Loc,
3630 Name => New_Occurrence_Of (RTE (RE_Get_RAS_Info), Loc),
3631 Parameter_Associations => New_List (
3632 New_Occurrence_Of (Package_Name, Loc),
3633 New_Occurrence_Of (Subp_Id, Loc),
3634 New_Occurrence_Of (Proxy_Addr, Loc))),
3635
3636 Make_Implicit_If_Statement (N,
3637 Condition =>
3638 Make_And_Then (Loc,
3639 Left_Opnd =>
3640 Make_Op_Eq (Loc,
3641 Left_Opnd =>
3642 New_Occurrence_Of (Origin, Loc),
3643 Right_Opnd =>
3644 Make_Function_Call (Loc,
3645 New_Occurrence_Of (
3646 RTE (RE_Get_Local_Partition_Id), Loc))),
3647
3648 Right_Opnd =>
3649 Make_Op_Not (Loc,
3650 New_Occurrence_Of (All_Calls_Remote, Loc))),
3651
3652 Then_Statements => New_List (
3653 Make_Simple_Return_Statement (Loc,
3654 Unchecked_Convert_To (Fat_Type,
3655 OK_Convert_To (RTE (RE_Address),
3656 New_Occurrence_Of (Proxy_Addr, Loc)))))),
3657
3658 Set_Field (Name_Origin,
3659 New_Occurrence_Of (Origin, Loc)),
3660
3661 Set_Field (Name_Receiver,
3662 Make_Function_Call (Loc,
3663 Name =>
3664 New_Occurrence_Of (RTE (RE_Get_RCI_Package_Receiver), Loc),
3665 Parameter_Associations => New_List (
3666 New_Occurrence_Of (Package_Name, Loc)))),
3667
3668 Set_Field (Name_Addr, New_Occurrence_Of (Proxy_Addr, Loc)),
3669
3670 -- E.4.1(9) A remote call is asynchronous if it is a call to
3671 -- a procedure or a call through a value of an access-to-procedure
3672 -- type to which a pragma Asynchronous applies.
3673
3674 -- Asynch_P is true when the procedure is asynchronous;
3675 -- Asynch_T is true when the type is asynchronous.
3676
3677 Set_Field (Name_Asynchronous,
3678 Make_Or_Else (Loc,
3679 New_Occurrence_Of (Asynch_P, Loc),
3680 New_Occurrence_Of (Boolean_Literals (
3681 Is_Asynchronous (Ras_Type)), Loc))));
3682
3683 Append_List_To (Proc_Statements,
3684 Build_Get_Unique_RP_Call
3685 (Loc, Stub_Ptr, Stub_Elements.Stub_Type));
3686
3687 -- Return the newly created value
3688
3689 Append_To (Proc_Statements,
3690 Make_Simple_Return_Statement (Loc,
3691 Expression =>
3692 Unchecked_Convert_To (Fat_Type,
3693 New_Occurrence_Of (Stub_Ptr, Loc))));
3694
3695 Proc_Spec :=
3696 Make_Function_Specification (Loc,
3697 Defining_Unit_Name => Proc,
3698 Parameter_Specifications => New_List (
3699 Make_Parameter_Specification (Loc,
3700 Defining_Identifier => Package_Name,
3701 Parameter_Type =>
3702 New_Occurrence_Of (Standard_String, Loc)),
3703
3704 Make_Parameter_Specification (Loc,
3705 Defining_Identifier => Subp_Id,
3706 Parameter_Type =>
3707 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc)),
3708
3709 Make_Parameter_Specification (Loc,
3710 Defining_Identifier => Asynch_P,
3711 Parameter_Type =>
3712 New_Occurrence_Of (Standard_Boolean, Loc)),
3713
3714 Make_Parameter_Specification (Loc,
3715 Defining_Identifier => All_Calls_Remote,
3716 Parameter_Type =>
3717 New_Occurrence_Of (Standard_Boolean, Loc))),
3718
3719 Result_Definition =>
3720 New_Occurrence_Of (Fat_Type, Loc));
3721
3722 -- Set the kind and return type of the function to prevent
3723 -- ambiguities between Ras_Type and Fat_Type in subsequent analysis.
3724
3725 Mutate_Ekind (Proc, E_Function);
3726 Set_Etype (Proc, Fat_Type);
3727
3728 Discard_Node (
3729 Make_Subprogram_Body (Loc,
3730 Specification => Proc_Spec,
3731 Declarations => Proc_Decls,
3732 Handled_Statement_Sequence =>
3733 Make_Handled_Sequence_Of_Statements (Loc,
3734 Statements => Proc_Statements)));
3735
3736 Set_TSS (Fat_Type, Proc);
3737 end Add_RAS_Access_TSS;
3738
3739 -----------------------
3740 -- Add_RAST_Features --
3741 -----------------------
3742
3743 procedure Add_RAST_Features
3744 (Vis_Decl : Node_Id;
3745 RAS_Type : Entity_Id)
3746 is
3747 pragma Unreferenced (RAS_Type);
3748 begin
3749 Add_RAS_Access_TSS (Vis_Decl);
3750 end Add_RAST_Features;
3751
3752 -----------------------------------------
3753 -- Add_Receiving_Stubs_To_Declarations --
3754 -----------------------------------------
3755
3756 procedure Add_Receiving_Stubs_To_Declarations
3757 (Pkg_Spec : Node_Id;
3758 Decls : List_Id;
3759 Stmts : List_Id)
3760 is
3761 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
3762
3763 Request_Parameter : Node_Id;
3764
3765 Pkg_RPC_Receiver : constant Entity_Id :=
3766 Make_Temporary (Loc, 'H');
3767 Pkg_RPC_Receiver_Statements : List_Id;
3768 Pkg_RPC_Receiver_Cases : constant List_Id := New_List;
3769 Pkg_RPC_Receiver_Body : Node_Id;
3770 -- A Pkg_RPC_Receiver is built to decode the request
3771
3772 Lookup_RAS : Node_Id;
3773 Lookup_RAS_Info : constant Entity_Id := Make_Temporary (Loc, 'R');
3774 -- A remote subprogram is created to allow peers to look up RAS
3775 -- information using subprogram ids.
3776
3777 Subp_Id : Entity_Id;
3778 Subp_Index : Entity_Id;
3779 -- Subprogram_Id as read from the incoming stream
3780
3781 Current_Subp_Number : Int := First_RCI_Subprogram_Id;
3782 Current_Stubs : Node_Id;
3783
3784 Subp_Info_Array : constant Entity_Id := Make_Temporary (Loc, 'I');
3785 Subp_Info_List : constant List_Id := New_List;
3786
3787 Register_Pkg_Actuals : constant List_Id := New_List;
3788
3789 All_Calls_Remote_E : Entity_Id;
3790 Proxy_Object_Addr : Entity_Id;
3791
3792 procedure Append_Stubs_To
3793 (RPC_Receiver_Cases : List_Id;
3794 Stubs : Node_Id;
3795 Subprogram_Number : Int);
3796 -- Add one case to the specified RPC receiver case list
3797 -- associating Subprogram_Number with the subprogram declared
3798 -- by Declaration, for which we have receiving stubs in Stubs.
3799
3800 procedure Visit_Subprogram (Decl : Node_Id);
3801 -- Generate receiving stub for one remote subprogram
3802
3803 ---------------------
3804 -- Append_Stubs_To --
3805 ---------------------
3806
3807 procedure Append_Stubs_To
3808 (RPC_Receiver_Cases : List_Id;
3809 Stubs : Node_Id;
3810 Subprogram_Number : Int)
3811 is
3812 begin
3813 Append_To (RPC_Receiver_Cases,
3814 Make_Case_Statement_Alternative (Loc,
3815 Discrete_Choices =>
3816 New_List (Make_Integer_Literal (Loc, Subprogram_Number)),
3817 Statements =>
3818 New_List (
3819 Make_Procedure_Call_Statement (Loc,
3820 Name =>
3821 New_Occurrence_Of (Defining_Entity (Stubs), Loc),
3822 Parameter_Associations => New_List (
3823 New_Occurrence_Of (Request_Parameter, Loc))))));
3824 end Append_Stubs_To;
3825
3826 ----------------------
3827 -- Visit_Subprogram --
3828 ----------------------
3829
3830 procedure Visit_Subprogram (Decl : Node_Id) is
3831 Loc : constant Source_Ptr := Sloc (Decl);
3832 Spec : constant Node_Id := Specification (Decl);
3833 Subp_Def : constant Entity_Id := Defining_Unit_Name (Spec);
3834
3835 Subp_Val : String_Id;
3836 pragma Warnings (Off, Subp_Val);
3837
3838 begin
3839 -- Disable expansion of stubs if serious errors have been
3840 -- diagnosed, because otherwise some illegal remote subprogram
3841 -- declarations could cause cascaded errors in stubs.
3842
3843 if Serious_Errors_Detected /= 0 then
3844 return;
3845 end if;
3846
3847 -- Build receiving stub
3848
3849 Current_Stubs :=
3850 Build_Subprogram_Receiving_Stubs
3851 (Vis_Decl => Decl,
3852 Asynchronous =>
3853 Nkind (Spec) = N_Procedure_Specification
3854 and then Is_Asynchronous (Subp_Def));
3855
3856 Append_To (Decls, Current_Stubs);
3857 Analyze (Current_Stubs);
3858
3859 -- Build RAS proxy
3860
3861 Add_RAS_Proxy_And_Analyze (Decls,
3862 Vis_Decl => Decl,
3863 All_Calls_Remote_E => All_Calls_Remote_E,
3864 Proxy_Object_Addr => Proxy_Object_Addr);
3865
3866 -- Compute distribution identifier
3867
3868 Assign_Subprogram_Identifier
3869 (Subp_Def, Current_Subp_Number, Subp_Val);
3870
3871 pragma Assert (Current_Subp_Number = Get_Subprogram_Id (Subp_Def));
3872
3873 -- Add subprogram descriptor (RCI_Subp_Info) to the subprograms
3874 -- table for this receiver. This aggregate must be kept consistent
3875 -- with the declaration of RCI_Subp_Info in
3876 -- System.Partition_Interface.
3877
3878 Append_To (Subp_Info_List,
3879 Make_Component_Association (Loc,
3880 Choices => New_List (
3881 Make_Integer_Literal (Loc, Current_Subp_Number)),
3882
3883 Expression =>
3884 Make_Aggregate (Loc,
3885 Component_Associations => New_List (
3886
3887 -- Addr =>
3888
3889 Make_Component_Association (Loc,
3890 Choices =>
3891 New_List (Make_Identifier (Loc, Name_Addr)),
3892 Expression =>
3893 New_Occurrence_Of (Proxy_Object_Addr, Loc))))));
3894
3895 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
3896 Stubs => Current_Stubs,
3897 Subprogram_Number => Current_Subp_Number);
3898
3899 Current_Subp_Number := Current_Subp_Number + 1;
3900 end Visit_Subprogram;
3901
3902 procedure Visit_Spec is new Build_Package_Stubs (Visit_Subprogram);
3903
3904 -- Start of processing for Add_Receiving_Stubs_To_Declarations
3905
3906 begin
3907 -- Building receiving stubs consist in several operations:
3908
3909 -- - a package RPC receiver must be built. This subprogram
3910 -- will get a Subprogram_Id from the incoming stream
3911 -- and will dispatch the call to the right subprogram;
3912
3913 -- - a receiving stub for each subprogram visible in the package
3914 -- spec. This stub will read all the parameters from the stream,
3915 -- and put the result as well as the exception occurrence in the
3916 -- output stream;
3917
3918 -- - a dummy package with an empty spec and a body made of an
3919 -- elaboration part, whose job is to register the receiving
3920 -- part of this RCI package on the name server. This is done
3921 -- by calling System.Partition_Interface.Register_Receiving_Stub.
3922
3923 Build_RPC_Receiver_Body (
3924 RPC_Receiver => Pkg_RPC_Receiver,
3925 Request => Request_Parameter,
3926 Subp_Id => Subp_Id,
3927 Subp_Index => Subp_Index,
3928 Stmts => Pkg_RPC_Receiver_Statements,
3929 Decl => Pkg_RPC_Receiver_Body);
3930 pragma Assert (Subp_Id = Subp_Index);
3931
3932 -- A null subp_id denotes a call through a RAS, in which case the
3933 -- next Uint_64 element in the stream is the address of the local
3934 -- proxy object, from which we can retrieve the actual subprogram id.
3935
3936 Append_To (Pkg_RPC_Receiver_Statements,
3937 Make_Implicit_If_Statement (Pkg_Spec,
3938 Condition =>
3939 Make_Op_Eq (Loc,
3940 New_Occurrence_Of (Subp_Id, Loc),
3941 Make_Integer_Literal (Loc, 0)),
3942
3943 Then_Statements => New_List (
3944 Make_Assignment_Statement (Loc,
3945 Name =>
3946 New_Occurrence_Of (Subp_Id, Loc),
3947
3948 Expression =>
3949 Make_Selected_Component (Loc,
3950 Prefix =>
3951 Unchecked_Convert_To (RTE (RE_RAS_Proxy_Type_Access),
3952 OK_Convert_To (RTE (RE_Address),
3953 Make_Attribute_Reference (Loc,
3954 Prefix =>
3955 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
3956 Attribute_Name =>
3957 Name_Input,
3958 Expressions => New_List (
3959 Make_Selected_Component (Loc,
3960 Prefix => Request_Parameter,
3961 Selector_Name => Name_Params))))),
3962
3963 Selector_Name => Make_Identifier (Loc, Name_Subp_Id))))));
3964
3965 -- Build a subprogram for RAS information lookups
3966
3967 Lookup_RAS :=
3968 Make_Subprogram_Declaration (Loc,
3969 Specification =>
3970 Make_Function_Specification (Loc,
3971 Defining_Unit_Name =>
3972 Lookup_RAS_Info,
3973 Parameter_Specifications => New_List (
3974 Make_Parameter_Specification (Loc,
3975 Defining_Identifier =>
3976 Make_Defining_Identifier (Loc, Name_Subp_Id),
3977 In_Present =>
3978 True,
3979 Parameter_Type =>
3980 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc))),
3981 Result_Definition =>
3982 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)));
3983 Append_To (Decls, Lookup_RAS);
3984 Analyze (Lookup_RAS);
3985
3986 Current_Stubs := Build_Subprogram_Receiving_Stubs
3987 (Vis_Decl => Lookup_RAS,
3988 Asynchronous => False);
3989 Append_To (Decls, Current_Stubs);
3990 Analyze (Current_Stubs);
3991
3992 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
3993 Stubs => Current_Stubs,
3994 Subprogram_Number => 1);
3995
3996 -- For each subprogram, the receiving stub will be built and a
3997 -- case statement will be made on the Subprogram_Id to dispatch
3998 -- to the right subprogram.
3999
4000 All_Calls_Remote_E :=
4001 Boolean_Literals
4002 (Has_All_Calls_Remote (Defining_Entity (Pkg_Spec)));
4003
4004 Overload_Counter_Table.Reset;
4005
4006 Visit_Spec (Pkg_Spec);
4007
4008 -- If we receive an invalid Subprogram_Id, it is best to do nothing
4009 -- rather than raising an exception since we do not want someone
4010 -- to crash a remote partition by sending invalid subprogram ids.
4011 -- This is consistent with the other parts of the case statement
4012 -- since even in presence of incorrect parameters in the stream,
4013 -- every exception will be caught and (if the subprogram is not an
4014 -- APC) put into the result stream and sent away.
4015
4016 Append_To (Pkg_RPC_Receiver_Cases,
4017 Make_Case_Statement_Alternative (Loc,
4018 Discrete_Choices => New_List (Make_Others_Choice (Loc)),
4019 Statements => New_List (Make_Null_Statement (Loc))));
4020
4021 Append_To (Pkg_RPC_Receiver_Statements,
4022 Make_Case_Statement (Loc,
4023 Expression => New_Occurrence_Of (Subp_Id, Loc),
4024 Alternatives => Pkg_RPC_Receiver_Cases));
4025
4026 Append_To (Decls,
4027 Make_Object_Declaration (Loc,
4028 Defining_Identifier => Subp_Info_Array,
4029 Constant_Present => True,
4030 Aliased_Present => True,
4031 Object_Definition =>
4032 Make_Subtype_Indication (Loc,
4033 Subtype_Mark =>
4034 New_Occurrence_Of (RTE (RE_RCI_Subp_Info_Array), Loc),
4035 Constraint =>
4036 Make_Index_Or_Discriminant_Constraint (Loc,
4037 New_List (
4038 Make_Range (Loc,
4039 Low_Bound => Make_Integer_Literal (Loc,
4040 First_RCI_Subprogram_Id),
4041 High_Bound =>
4042 Make_Integer_Literal (Loc,
4043 Intval =>
4044 First_RCI_Subprogram_Id
4045 + List_Length (Subp_Info_List) - 1)))))));
4046
4047 -- For a degenerate RCI with no visible subprograms, Subp_Info_List
4048 -- has zero length, and the declaration is for an empty array, in
4049 -- which case no initialization aggregate must be generated.
4050
4051 if Present (First (Subp_Info_List)) then
4052 Set_Expression (Last (Decls),
4053 Make_Aggregate (Loc,
4054 Component_Associations => Subp_Info_List));
4055
4056 -- No initialization provided: remove CONSTANT so that the
4057 -- declaration is not an incomplete deferred constant.
4058
4059 else
4060 Set_Constant_Present (Last (Decls), False);
4061 end if;
4062
4063 Analyze (Last (Decls));
4064
4065 declare
4066 Subp_Info_Addr : Node_Id;
4067 -- Return statement for Lookup_RAS_Info: address of the subprogram
4068 -- information record for the requested subprogram id.
4069
4070 begin
4071 if Present (First (Subp_Info_List)) then
4072 Subp_Info_Addr :=
4073 Make_Selected_Component (Loc,
4074 Prefix =>
4075 Make_Indexed_Component (Loc,
4076 Prefix => New_Occurrence_Of (Subp_Info_Array, Loc),
4077 Expressions => New_List (
4078 Convert_To (Standard_Integer,
4079 Make_Identifier (Loc, Name_Subp_Id)))),
4080 Selector_Name => Make_Identifier (Loc, Name_Addr));
4081
4082 -- Case of no visible subprogram: just raise Constraint_Error, we
4083 -- know for sure we got junk from a remote partition.
4084
4085 else
4086 Subp_Info_Addr :=
4087 Make_Raise_Constraint_Error (Loc,
4088 Reason => CE_Range_Check_Failed);
4089 Set_Etype (Subp_Info_Addr, RTE (RE_Unsigned_64));
4090 end if;
4091
4092 Append_To (Decls,
4093 Make_Subprogram_Body (Loc,
4094 Specification =>
4095 Copy_Specification (Loc, Parent (Lookup_RAS_Info)),
4096 Declarations => No_List,
4097 Handled_Statement_Sequence =>
4098 Make_Handled_Sequence_Of_Statements (Loc,
4099 Statements => New_List (
4100 Make_Simple_Return_Statement (Loc,
4101 Expression =>
4102 OK_Convert_To
4103 (RTE (RE_Unsigned_64), Subp_Info_Addr))))));
4104 end;
4105
4106 Analyze (Last (Decls));
4107
4108 Append_To (Decls, Pkg_RPC_Receiver_Body);
4109 Analyze (Last (Decls));
4110
4111 -- Name
4112
4113 Append_To (Register_Pkg_Actuals,
4114 Make_String_Literal (Loc,
4115 Strval =>
4116 Fully_Qualified_Name_String
4117 (Defining_Entity (Pkg_Spec), Append_NUL => False)));
4118
4119 -- Receiver
4120
4121 Append_To (Register_Pkg_Actuals,
4122 Make_Attribute_Reference (Loc,
4123 Prefix => New_Occurrence_Of (Pkg_RPC_Receiver, Loc),
4124 Attribute_Name => Name_Unrestricted_Access));
4125
4126 -- Version
4127
4128 Append_To (Register_Pkg_Actuals,
4129 Make_Attribute_Reference (Loc,
4130 Prefix =>
4131 New_Occurrence_Of (Defining_Entity (Pkg_Spec), Loc),
4132 Attribute_Name => Name_Version));
4133
4134 -- Subp_Info
4135
4136 Append_To (Register_Pkg_Actuals,
4137 Make_Attribute_Reference (Loc,
4138 Prefix => New_Occurrence_Of (Subp_Info_Array, Loc),
4139 Attribute_Name => Name_Address));
4140
4141 -- Subp_Info_Len
4142
4143 Append_To (Register_Pkg_Actuals,
4144 Make_Attribute_Reference (Loc,
4145 Prefix => New_Occurrence_Of (Subp_Info_Array, Loc),
4146 Attribute_Name => Name_Length));
4147
4148 -- Generate the call
4149
4150 Append_To (Stmts,
4151 Make_Procedure_Call_Statement (Loc,
4152 Name =>
4153 New_Occurrence_Of (RTE (RE_Register_Receiving_Stub), Loc),
4154 Parameter_Associations => Register_Pkg_Actuals));
4155 Analyze (Last (Stmts));
4156 end Add_Receiving_Stubs_To_Declarations;
4157
4158 ---------------------------------
4159 -- Build_General_Calling_Stubs --
4160 ---------------------------------
4161
4162 procedure Build_General_Calling_Stubs
4163 (Decls : List_Id;
4164 Statements : List_Id;
4165 Target_Partition : Entity_Id;
4166 Target_RPC_Receiver : Node_Id;
4167 Subprogram_Id : Node_Id;
4168 Asynchronous : Node_Id := Empty;
4169 Is_Known_Asynchronous : Boolean := False;
4170 Is_Known_Non_Asynchronous : Boolean := False;
4171 Is_Function : Boolean;
4172 Spec : Node_Id;
4173 Stub_Type : Entity_Id := Empty;
4174 RACW_Type : Entity_Id := Empty;
4175 Nod : Node_Id)
4176 is
4177 Loc : constant Source_Ptr := Sloc (Nod);
4178
4179 Stream_Parameter : Node_Id;
4180 -- Name of the stream used to transmit parameters to the remote
4181 -- package.
4182
4183 Result_Parameter : Node_Id;
4184 -- Name of the result parameter (in non-APC cases) which get the
4185 -- result of the remote subprogram.
4186
4187 Exception_Return_Parameter : Node_Id;
4188 -- Name of the parameter which will hold the exception sent by the
4189 -- remote subprogram.
4190
4191 Current_Parameter : Node_Id;
4192 -- Current parameter being handled
4193
4194 Ordered_Parameters_List : constant List_Id :=
4195 Build_Ordered_Parameters_List (Spec);
4196
4197 Asynchronous_Statements : List_Id := No_List;
4198 Non_Asynchronous_Statements : List_Id := No_List;
4199 -- Statements specifics to the Asynchronous/Non-Asynchronous cases
4200
4201 Extra_Formal_Statements : constant List_Id := New_List;
4202 -- List of statements for extra formal parameters. It will appear
4203 -- after the regular statements for writing out parameters.
4204
4205 pragma Unreferenced (RACW_Type);
4206 -- Used only for the PolyORB case
4207
4208 begin
4209 -- The general form of a calling stub for a given subprogram is:
4210
4211 -- procedure X (...) is P : constant Partition_ID :=
4212 -- RCI_Cache.Get_Active_Partition_ID; Stream, Result : aliased
4213 -- System.RPC.Params_Stream_Type (0); begin
4214 -- Put_Package_RPC_Receiver_In_Stream; (the package RPC receiver
4215 -- comes from RCI_Cache.Get_RCI_Package_Receiver)
4216 -- Put_Subprogram_Id_In_Stream; Put_Parameters_In_Stream; Do_RPC
4217 -- (Stream, Result); Read_Exception_Occurrence_From_Result;
4218 -- Raise_It;
4219 -- Read_Out_Parameters_And_Function_Return_From_Stream; end X;
4220
4221 -- There are some variations: Do_APC is called for an asynchronous
4222 -- procedure and the part after the call is completely ommitted as
4223 -- well as the declaration of Result. For a function call, 'Input is
4224 -- always used to read the result even if it is constrained.
4225
4226 Stream_Parameter := Make_Temporary (Loc, 'S');
4227
4228 Append_To (Decls,
4229 Make_Object_Declaration (Loc,
4230 Defining_Identifier => Stream_Parameter,
4231 Aliased_Present => True,
4232 Object_Definition =>
4233 Make_Subtype_Indication (Loc,
4234 Subtype_Mark =>
4235 New_Occurrence_Of (RTE (RE_Params_Stream_Type), Loc),
4236 Constraint =>
4237 Make_Index_Or_Discriminant_Constraint (Loc,
4238 Constraints =>
4239 New_List (Make_Integer_Literal (Loc, 0))))));
4240
4241 if not Is_Known_Asynchronous then
4242 Result_Parameter := Make_Temporary (Loc, 'R');
4243
4244 Append_To (Decls,
4245 Make_Object_Declaration (Loc,
4246 Defining_Identifier => Result_Parameter,
4247 Aliased_Present => True,
4248 Object_Definition =>
4249 Make_Subtype_Indication (Loc,
4250 Subtype_Mark =>
4251 New_Occurrence_Of (RTE (RE_Params_Stream_Type), Loc),
4252 Constraint =>
4253 Make_Index_Or_Discriminant_Constraint (Loc,
4254 Constraints =>
4255 New_List (Make_Integer_Literal (Loc, 0))))));
4256
4257 Exception_Return_Parameter := Make_Temporary (Loc, 'E');
4258
4259 Append_To (Decls,
4260 Make_Object_Declaration (Loc,
4261 Defining_Identifier => Exception_Return_Parameter,
4262 Object_Definition =>
4263 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc)));
4264
4265 else
4266 Result_Parameter := Empty;
4267 Exception_Return_Parameter := Empty;
4268 end if;
4269
4270 -- Put first the RPC receiver corresponding to the remote package
4271
4272 Append_To (Statements,
4273 Make_Attribute_Reference (Loc,
4274 Prefix =>
4275 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
4276 Attribute_Name => Name_Write,
4277 Expressions => New_List (
4278 Make_Attribute_Reference (Loc,
4279 Prefix => New_Occurrence_Of (Stream_Parameter, Loc),
4280 Attribute_Name => Name_Access),
4281 Target_RPC_Receiver)));
4282
4283 -- Then put the Subprogram_Id of the subprogram we want to call in
4284 -- the stream.
4285
4286 Append_To (Statements,
4287 Make_Attribute_Reference (Loc,
4288 Prefix => New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
4289 Attribute_Name => Name_Write,
4290 Expressions => New_List (
4291 Make_Attribute_Reference (Loc,
4292 Prefix => New_Occurrence_Of (Stream_Parameter, Loc),
4293 Attribute_Name => Name_Access),
4294 Subprogram_Id)));
4295
4296 Current_Parameter := First (Ordered_Parameters_List);
4297 while Present (Current_Parameter) loop
4298 declare
4299 Typ : constant Node_Id :=
4300 Parameter_Type (Current_Parameter);
4301 Etyp : Entity_Id;
4302 Constrained : Boolean;
4303 Value : Node_Id;
4304 Extra_Parameter : Entity_Id;
4305
4306 begin
4307 if Is_RACW_Controlling_Formal
4308 (Current_Parameter, Stub_Type)
4309 then
4310 -- In the case of a controlling formal argument, we marshall
4311 -- its addr field rather than the local stub.
4312
4313 Append_To (Statements,
4314 Pack_Node_Into_Stream (Loc,
4315 Stream => Stream_Parameter,
4316 Object =>
4317 Make_Selected_Component (Loc,
4318 Prefix =>
4319 Defining_Identifier (Current_Parameter),
4320 Selector_Name => Name_Addr),
4321 Etyp => RTE (RE_Unsigned_64)));
4322
4323 else
4324 Value :=
4325 New_Occurrence_Of
4326 (Defining_Identifier (Current_Parameter), Loc);
4327
4328 -- Access type parameters are transmitted as in out
4329 -- parameters. However, a dereference is needed so that
4330 -- we marshall the designated object.
4331
4332 if Nkind (Typ) = N_Access_Definition then
4333 Value := Make_Explicit_Dereference (Loc, Value);
4334 Etyp := Etype (Subtype_Mark (Typ));
4335 else
4336 Etyp := Etype (Typ);
4337 end if;
4338
4339 Constrained := not Transmit_As_Unconstrained (Etyp);
4340
4341 -- Any parameter but unconstrained out parameters are
4342 -- transmitted to the peer.
4343
4344 if In_Present (Current_Parameter)
4345 or else not Out_Present (Current_Parameter)
4346 or else not Constrained
4347 then
4348 Append_To (Statements,
4349 Make_Attribute_Reference (Loc,
4350 Prefix => New_Occurrence_Of (Etyp, Loc),
4351 Attribute_Name =>
4352 Output_From_Constrained (Constrained),
4353 Expressions => New_List (
4354 Make_Attribute_Reference (Loc,
4355 Prefix =>
4356 New_Occurrence_Of (Stream_Parameter, Loc),
4357 Attribute_Name => Name_Access),
4358 Value)));
4359 end if;
4360 end if;
4361
4362 -- If the current parameter has a dynamic constrained status,
4363 -- then this status is transmitted as well.
4364 -- This should be done for accessibility as well ???
4365
4366 if Nkind (Typ) /= N_Access_Definition
4367 and then Need_Extra_Constrained (Current_Parameter)
4368 then
4369 -- In this block, we do not use the extra formal that has
4370 -- been created because it does not exist at the time of
4371 -- expansion when building calling stubs for remote access
4372 -- to subprogram types. We create an extra variable of this
4373 -- type and push it in the stream after the regular
4374 -- parameters.
4375
4376 Extra_Parameter := Make_Temporary (Loc, 'P');
4377
4378 Append_To (Decls,
4379 Make_Object_Declaration (Loc,
4380 Defining_Identifier => Extra_Parameter,
4381 Constant_Present => True,
4382 Object_Definition =>
4383 New_Occurrence_Of (Standard_Boolean, Loc),
4384 Expression =>
4385 Make_Attribute_Reference (Loc,
4386 Prefix =>
4387 New_Occurrence_Of (
4388 Defining_Identifier (Current_Parameter), Loc),
4389 Attribute_Name => Name_Constrained)));
4390
4391 Append_To (Extra_Formal_Statements,
4392 Make_Attribute_Reference (Loc,
4393 Prefix =>
4394 New_Occurrence_Of (Standard_Boolean, Loc),
4395 Attribute_Name => Name_Write,
4396 Expressions => New_List (
4397 Make_Attribute_Reference (Loc,
4398 Prefix =>
4399 New_Occurrence_Of
4400 (Stream_Parameter, Loc), Attribute_Name =>
4401 Name_Access),
4402 New_Occurrence_Of (Extra_Parameter, Loc))));
4403 end if;
4404
4405 Next (Current_Parameter);
4406 end;
4407 end loop;
4408
4409 -- Append the formal statements list to the statements
4410
4411 Append_List_To (Statements, Extra_Formal_Statements);
4412
4413 if not Is_Known_Non_Asynchronous then
4414
4415 -- Build the call to System.RPC.Do_APC
4416
4417 Asynchronous_Statements := New_List (
4418 Make_Procedure_Call_Statement (Loc,
4419 Name =>
4420 New_Occurrence_Of (RTE (RE_Do_Apc), Loc),
4421 Parameter_Associations => New_List (
4422 New_Occurrence_Of (Target_Partition, Loc),
4423 Make_Attribute_Reference (Loc,
4424 Prefix =>
4425 New_Occurrence_Of (Stream_Parameter, Loc),
4426 Attribute_Name => Name_Access))));
4427 else
4428 Asynchronous_Statements := No_List;
4429 end if;
4430
4431 if not Is_Known_Asynchronous then
4432
4433 -- Build the call to System.RPC.Do_RPC
4434
4435 Non_Asynchronous_Statements := New_List (
4436 Make_Procedure_Call_Statement (Loc,
4437 Name =>
4438 New_Occurrence_Of (RTE (RE_Do_Rpc), Loc),
4439 Parameter_Associations => New_List (
4440 New_Occurrence_Of (Target_Partition, Loc),
4441
4442 Make_Attribute_Reference (Loc,
4443 Prefix =>
4444 New_Occurrence_Of (Stream_Parameter, Loc),
4445 Attribute_Name => Name_Access),
4446
4447 Make_Attribute_Reference (Loc,
4448 Prefix =>
4449 New_Occurrence_Of (Result_Parameter, Loc),
4450 Attribute_Name => Name_Access))));
4451
4452 -- Read the exception occurrence from the result stream and
4453 -- reraise it. It does no harm if this is a Null_Occurrence since
4454 -- this does nothing.
4455
4456 Append_To (Non_Asynchronous_Statements,
4457 Make_Attribute_Reference (Loc,
4458 Prefix =>
4459 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
4460
4461 Attribute_Name => Name_Read,
4462
4463 Expressions => New_List (
4464 Make_Attribute_Reference (Loc,
4465 Prefix =>
4466 New_Occurrence_Of (Result_Parameter, Loc),
4467 Attribute_Name => Name_Access),
4468 New_Occurrence_Of (Exception_Return_Parameter, Loc))));
4469
4470 Append_To (Non_Asynchronous_Statements,
4471 Make_Procedure_Call_Statement (Loc,
4472 Name =>
4473 New_Occurrence_Of (RTE (RE_Reraise_Occurrence), Loc),
4474 Parameter_Associations => New_List (
4475 New_Occurrence_Of (Exception_Return_Parameter, Loc))));
4476
4477 if Is_Function then
4478
4479 -- If this is a function call, then read the value and return
4480 -- it. The return value is written/read using 'Output/'Input.
4481
4482 Append_To (Non_Asynchronous_Statements,
4483 Make_Tag_Check (Loc,
4484 Make_Simple_Return_Statement (Loc,
4485 Expression =>
4486 Make_Attribute_Reference (Loc,
4487 Prefix =>
4488 New_Occurrence_Of (
4489 Etype (Result_Definition (Spec)), Loc),
4490
4491 Attribute_Name => Name_Input,
4492
4493 Expressions => New_List (
4494 Make_Attribute_Reference (Loc,
4495 Prefix =>
4496 New_Occurrence_Of (Result_Parameter, Loc),
4497 Attribute_Name => Name_Access))))));
4498
4499 else
4500 -- Loop around parameters and assign out (or in out)
4501 -- parameters. In the case of RACW, controlling arguments
4502 -- cannot possibly have changed since they are remote, so
4503 -- we do not read them from the stream.
4504
4505 Current_Parameter := First (Ordered_Parameters_List);
4506 while Present (Current_Parameter) loop
4507 declare
4508 Typ : constant Node_Id :=
4509 Parameter_Type (Current_Parameter);
4510 Etyp : Entity_Id;
4511 Value : Node_Id;
4512
4513 begin
4514 Value :=
4515 New_Occurrence_Of
4516 (Defining_Identifier (Current_Parameter), Loc);
4517
4518 if Nkind (Typ) = N_Access_Definition then
4519 Value := Make_Explicit_Dereference (Loc, Value);
4520 Etyp := Etype (Subtype_Mark (Typ));
4521 else
4522 Etyp := Etype (Typ);
4523 end if;
4524
4525 if (Out_Present (Current_Parameter)
4526 or else Nkind (Typ) = N_Access_Definition)
4527 and then Etyp /= Stub_Type
4528 then
4529 Append_To (Non_Asynchronous_Statements,
4530 Make_Attribute_Reference (Loc,
4531 Prefix =>
4532 New_Occurrence_Of (Etyp, Loc),
4533
4534 Attribute_Name => Name_Read,
4535
4536 Expressions => New_List (
4537 Make_Attribute_Reference (Loc,
4538 Prefix =>
4539 New_Occurrence_Of (Result_Parameter, Loc),
4540 Attribute_Name => Name_Access),
4541 Value)));
4542 end if;
4543 end;
4544
4545 Next (Current_Parameter);
4546 end loop;
4547 end if;
4548 end if;
4549
4550 if Is_Known_Asynchronous then
4551 Append_List_To (Statements, Asynchronous_Statements);
4552
4553 elsif Is_Known_Non_Asynchronous then
4554 Append_List_To (Statements, Non_Asynchronous_Statements);
4555
4556 else
4557 pragma Assert (Present (Asynchronous));
4558 Prepend_To (Asynchronous_Statements,
4559 Make_Attribute_Reference (Loc,
4560 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4561 Attribute_Name => Name_Write,
4562 Expressions => New_List (
4563 Make_Attribute_Reference (Loc,
4564 Prefix =>
4565 New_Occurrence_Of (Stream_Parameter, Loc),
4566 Attribute_Name => Name_Access),
4567 New_Occurrence_Of (Standard_True, Loc))));
4568
4569 Prepend_To (Non_Asynchronous_Statements,
4570 Make_Attribute_Reference (Loc,
4571 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4572 Attribute_Name => Name_Write,
4573 Expressions => New_List (
4574 Make_Attribute_Reference (Loc,
4575 Prefix =>
4576 New_Occurrence_Of (Stream_Parameter, Loc),
4577 Attribute_Name => Name_Access),
4578 New_Occurrence_Of (Standard_False, Loc))));
4579
4580 Append_To (Statements,
4581 Make_Implicit_If_Statement (Nod,
4582 Condition => Asynchronous,
4583 Then_Statements => Asynchronous_Statements,
4584 Else_Statements => Non_Asynchronous_Statements));
4585 end if;
4586 end Build_General_Calling_Stubs;
4587
4588 -----------------------------
4589 -- Build_RPC_Receiver_Body --
4590 -----------------------------
4591
4592 procedure Build_RPC_Receiver_Body
4593 (RPC_Receiver : Entity_Id;
4594 Request : out Entity_Id;
4595 Subp_Id : out Entity_Id;
4596 Subp_Index : out Entity_Id;
4597 Stmts : out List_Id;
4598 Decl : out Node_Id)
4599 is
4600 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
4601
4602 RPC_Receiver_Spec : Node_Id;
4603 RPC_Receiver_Decls : List_Id;
4604
4605 begin
4606 Request := Make_Defining_Identifier (Loc, Name_R);
4607
4608 RPC_Receiver_Spec :=
4609 Build_RPC_Receiver_Specification
4610 (RPC_Receiver => RPC_Receiver,
4611 Request_Parameter => Request);
4612
4613 Subp_Id := Make_Temporary (Loc, 'P');
4614 Subp_Index := Subp_Id;
4615
4616 -- Subp_Id may not be a constant, because in the case of the RPC
4617 -- receiver for an RCI package, when a call is received from a RAS
4618 -- dereference, it will be assigned during subsequent processing.
4619
4620 RPC_Receiver_Decls := New_List (
4621 Make_Object_Declaration (Loc,
4622 Defining_Identifier => Subp_Id,
4623 Object_Definition =>
4624 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
4625 Expression =>
4626 Make_Attribute_Reference (Loc,
4627 Prefix =>
4628 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
4629 Attribute_Name => Name_Input,
4630 Expressions => New_List (
4631 Make_Selected_Component (Loc,
4632 Prefix => Request,
4633 Selector_Name => Name_Params)))));
4634
4635 Stmts := New_List;
4636
4637 Decl :=
4638 Make_Subprogram_Body (Loc,
4639 Specification => RPC_Receiver_Spec,
4640 Declarations => RPC_Receiver_Decls,
4641 Handled_Statement_Sequence =>
4642 Make_Handled_Sequence_Of_Statements (Loc,
4643 Statements => Stmts));
4644 end Build_RPC_Receiver_Body;
4645
4646 -----------------------
4647 -- Build_Stub_Target --
4648 -----------------------
4649
4650 function Build_Stub_Target
4651 (Loc : Source_Ptr;
4652 Decls : List_Id;
4653 RCI_Locator : Entity_Id;
4654 Controlling_Parameter : Entity_Id) return RPC_Target
4655 is
4656 Target_Info : RPC_Target (PCS_Kind => Name_GARLIC_DSA);
4657
4658 begin
4659 Target_Info.Partition := Make_Temporary (Loc, 'P');
4660
4661 if Present (Controlling_Parameter) then
4662 Append_To (Decls,
4663 Make_Object_Declaration (Loc,
4664 Defining_Identifier => Target_Info.Partition,
4665 Constant_Present => True,
4666 Object_Definition =>
4667 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
4668
4669 Expression =>
4670 Make_Selected_Component (Loc,
4671 Prefix => Controlling_Parameter,
4672 Selector_Name => Name_Origin)));
4673
4674 Target_Info.RPC_Receiver :=
4675 Make_Selected_Component (Loc,
4676 Prefix => Controlling_Parameter,
4677 Selector_Name => Name_Receiver);
4678
4679 else
4680 Append_To (Decls,
4681 Make_Object_Declaration (Loc,
4682 Defining_Identifier => Target_Info.Partition,
4683 Constant_Present => True,
4684 Object_Definition =>
4685 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
4686
4687 Expression =>
4688 Make_Function_Call (Loc,
4689 Name => Make_Selected_Component (Loc,
4690 Prefix =>
4691 Make_Identifier (Loc, Chars (RCI_Locator)),
4692 Selector_Name =>
4693 Make_Identifier (Loc,
4694 Name_Get_Active_Partition_ID)))));
4695
4696 Target_Info.RPC_Receiver :=
4697 Make_Selected_Component (Loc,
4698 Prefix =>
4699 Make_Identifier (Loc, Chars (RCI_Locator)),
4700 Selector_Name =>
4701 Make_Identifier (Loc, Name_Get_RCI_Package_Receiver));
4702 end if;
4703 return Target_Info;
4704 end Build_Stub_Target;
4705
4706 --------------------------------------
4707 -- Build_Subprogram_Receiving_Stubs --
4708 --------------------------------------
4709
4710 function Build_Subprogram_Receiving_Stubs
4711 (Vis_Decl : Node_Id;
4712 Asynchronous : Boolean;
4713 Dynamically_Asynchronous : Boolean := False;
4714 Stub_Type : Entity_Id := Empty;
4715 RACW_Type : Entity_Id := Empty;
4716 Parent_Primitive : Entity_Id := Empty) return Node_Id
4717 is
4718 Loc : constant Source_Ptr := Sloc (Vis_Decl);
4719
4720 Request_Parameter : constant Entity_Id := Make_Temporary (Loc, 'R');
4721 -- Formal parameter for receiving stubs: a descriptor for an incoming
4722 -- request.
4723
4724 Decls : constant List_Id := New_List;
4725 -- All the parameters will get declared before calling the real
4726 -- subprograms. Also the out parameters will be declared.
4727
4728 Statements : constant List_Id := New_List;
4729
4730 Extra_Formal_Statements : constant List_Id := New_List;
4731 -- Statements concerning extra formal parameters
4732
4733 After_Statements : constant List_Id := New_List;
4734 -- Statements to be executed after the subprogram call
4735
4736 Inner_Decls : List_Id := No_List;
4737 -- In case of a function, the inner declarations are needed since
4738 -- the result may be unconstrained.
4739
4740 Excep_Handlers : List_Id := No_List;
4741 Excep_Choice : Entity_Id;
4742 Excep_Code : List_Id;
4743
4744 Parameter_List : constant List_Id := New_List;
4745 -- List of parameters to be passed to the subprogram
4746
4747 Current_Parameter : Node_Id;
4748
4749 Ordered_Parameters_List : constant List_Id :=
4750 Build_Ordered_Parameters_List
4751 (Specification (Vis_Decl));
4752
4753 Subp_Spec : Node_Id;
4754 -- Subprogram specification
4755
4756 Called_Subprogram : Node_Id;
4757 -- The subprogram to call
4758
4759 Null_Raise_Statement : Node_Id;
4760
4761 Dynamic_Async : Entity_Id;
4762
4763 begin
4764 if Present (RACW_Type) then
4765 Called_Subprogram := New_Occurrence_Of (Parent_Primitive, Loc);
4766 else
4767 Called_Subprogram :=
4768 New_Occurrence_Of
4769 (Defining_Unit_Name (Specification (Vis_Decl)), Loc);
4770 end if;
4771
4772 if Dynamically_Asynchronous then
4773 Dynamic_Async := Make_Temporary (Loc, 'S');
4774 else
4775 Dynamic_Async := Empty;
4776 end if;
4777
4778 if not Asynchronous or Dynamically_Asynchronous then
4779
4780 -- The first statement after the subprogram call is a statement to
4781 -- write a Null_Occurrence into the result stream.
4782
4783 Null_Raise_Statement :=
4784 Make_Attribute_Reference (Loc,
4785 Prefix =>
4786 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
4787 Attribute_Name => Name_Write,
4788 Expressions => New_List (
4789 Make_Selected_Component (Loc,
4790 Prefix => Request_Parameter,
4791 Selector_Name => Name_Result),
4792 New_Occurrence_Of (RTE (RE_Null_Occurrence), Loc)));
4793
4794 if Dynamically_Asynchronous then
4795 Null_Raise_Statement :=
4796 Make_Implicit_If_Statement (Vis_Decl,
4797 Condition =>
4798 Make_Op_Not (Loc, New_Occurrence_Of (Dynamic_Async, Loc)),
4799 Then_Statements => New_List (Null_Raise_Statement));
4800 end if;
4801
4802 Append_To (After_Statements, Null_Raise_Statement);
4803 end if;
4804
4805 -- Loop through every parameter and get its value from the stream. If
4806 -- the parameter is unconstrained, then the parameter is read using
4807 -- 'Input at the point of declaration.
4808
4809 Current_Parameter := First (Ordered_Parameters_List);
4810 while Present (Current_Parameter) loop
4811 declare
4812 Etyp : Entity_Id;
4813 Constrained : Boolean;
4814
4815 Need_Extra_Constrained : Boolean;
4816 -- True when an Extra_Constrained actual is required
4817
4818 Object : constant Entity_Id := Make_Temporary (Loc, 'P');
4819
4820 Expr : Node_Id := Empty;
4821
4822 Is_Controlling_Formal : constant Boolean :=
4823 Is_RACW_Controlling_Formal
4824 (Current_Parameter, Stub_Type);
4825
4826 begin
4827 if Is_Controlling_Formal then
4828
4829 -- We have a controlling formal parameter. Read its address
4830 -- rather than a real object. The address is in Unsigned_64
4831 -- form.
4832
4833 Etyp := RTE (RE_Unsigned_64);
4834 else
4835 Etyp := Etype (Parameter_Type (Current_Parameter));
4836 end if;
4837
4838 Constrained := not Transmit_As_Unconstrained (Etyp);
4839
4840 if In_Present (Current_Parameter)
4841 or else not Out_Present (Current_Parameter)
4842 or else not Constrained
4843 or else Is_Controlling_Formal
4844 then
4845 -- If an input parameter is constrained, then the read of
4846 -- the parameter is deferred until the beginning of the
4847 -- subprogram body. If it is unconstrained, then an
4848 -- expression is built for the object declaration and the
4849 -- variable is set using 'Input instead of 'Read. Note that
4850 -- this deferral does not change the order in which the
4851 -- actuals are read because Build_Ordered_Parameter_List
4852 -- puts them unconstrained first.
4853
4854 if Constrained then
4855 Append_To (Statements,
4856 Make_Attribute_Reference (Loc,
4857 Prefix => New_Occurrence_Of (Etyp, Loc),
4858 Attribute_Name => Name_Read,
4859 Expressions => New_List (
4860 Make_Selected_Component (Loc,
4861 Prefix => Request_Parameter,
4862 Selector_Name => Name_Params),
4863 New_Occurrence_Of (Object, Loc))));
4864
4865 else
4866
4867 -- Build and append Input_With_Tag_Check function
4868
4869 Append_To (Decls,
4870 Input_With_Tag_Check (Loc,
4871 Var_Type => Etyp,
4872 Stream =>
4873 Make_Selected_Component (Loc,
4874 Prefix => Request_Parameter,
4875 Selector_Name => Name_Params)));
4876
4877 -- Prepare function call expression
4878
4879 Expr :=
4880 Make_Function_Call (Loc,
4881 Name =>
4882 New_Occurrence_Of
4883 (Defining_Unit_Name
4884 (Specification (Last (Decls))), Loc));
4885 end if;
4886 end if;
4887
4888 Need_Extra_Constrained :=
4889 Nkind (Parameter_Type (Current_Parameter)) /=
4890 N_Access_Definition
4891 and then
4892 Ekind (Defining_Identifier (Current_Parameter)) /= E_Void
4893 and then
4894 Present (Extra_Constrained
4895 (Defining_Identifier (Current_Parameter)));
4896
4897 -- We may not associate an extra constrained actual to a
4898 -- constant object, so if one is needed, declare the actual
4899 -- as a variable even if it won't be modified.
4900
4901 Build_Actual_Object_Declaration
4902 (Object => Object,
4903 Etyp => Etyp,
4904 Variable => Need_Extra_Constrained
4905 or else Out_Present (Current_Parameter),
4906 Expr => Expr,
4907 Decls => Decls);
4908
4909 -- An out parameter may be written back using a 'Write
4910 -- attribute instead of a 'Output because it has been
4911 -- constrained by the parameter given to the caller. Note that
4912 -- out controlling arguments in the case of a RACW are not put
4913 -- back in the stream because the pointer on them has not
4914 -- changed.
4915
4916 if Out_Present (Current_Parameter)
4917 and then
4918 Etype (Parameter_Type (Current_Parameter)) /= Stub_Type
4919 then
4920 Append_To (After_Statements,
4921 Make_Attribute_Reference (Loc,
4922 Prefix => New_Occurrence_Of (Etyp, Loc),
4923 Attribute_Name => Name_Write,
4924 Expressions => New_List (
4925 Make_Selected_Component (Loc,
4926 Prefix => Request_Parameter,
4927 Selector_Name => Name_Result),
4928 New_Occurrence_Of (Object, Loc))));
4929 end if;
4930
4931 -- For RACW controlling formals, the Etyp of Object is always
4932 -- an RACW, even if the parameter is not of an anonymous access
4933 -- type. In such case, we need to dereference it at call time.
4934
4935 if Is_Controlling_Formal then
4936 if Nkind (Parameter_Type (Current_Parameter)) /=
4937 N_Access_Definition
4938 then
4939 Append_To (Parameter_List,
4940 Make_Parameter_Association (Loc,
4941 Selector_Name =>
4942 New_Occurrence_Of (
4943 Defining_Identifier (Current_Parameter), Loc),
4944 Explicit_Actual_Parameter =>
4945 Make_Explicit_Dereference (Loc,
4946 Unchecked_Convert_To (RACW_Type,
4947 OK_Convert_To (RTE (RE_Address),
4948 New_Occurrence_Of (Object, Loc))))));
4949
4950 else
4951 Append_To (Parameter_List,
4952 Make_Parameter_Association (Loc,
4953 Selector_Name =>
4954 New_Occurrence_Of (
4955 Defining_Identifier (Current_Parameter), Loc),
4956 Explicit_Actual_Parameter =>
4957 Unchecked_Convert_To (RACW_Type,
4958 OK_Convert_To (RTE (RE_Address),
4959 New_Occurrence_Of (Object, Loc)))));
4960 end if;
4961
4962 else
4963 Append_To (Parameter_List,
4964 Make_Parameter_Association (Loc,
4965 Selector_Name =>
4966 New_Occurrence_Of (
4967 Defining_Identifier (Current_Parameter), Loc),
4968 Explicit_Actual_Parameter =>
4969 New_Occurrence_Of (Object, Loc)));
4970 end if;
4971
4972 -- If the current parameter needs an extra formal, then read it
4973 -- from the stream and set the corresponding semantic field in
4974 -- the variable. If the kind of the parameter identifier is
4975 -- E_Void, then this is a compiler generated parameter that
4976 -- doesn't need an extra constrained status.
4977
4978 -- The case of Extra_Accessibility should also be handled ???
4979
4980 if Need_Extra_Constrained then
4981 declare
4982 Extra_Parameter : constant Entity_Id :=
4983 Extra_Constrained
4984 (Defining_Identifier
4985 (Current_Parameter));
4986
4987 Formal_Entity : constant Entity_Id :=
4988 Make_Defining_Identifier
4989 (Loc, Chars (Extra_Parameter));
4990
4991 Formal_Type : constant Entity_Id :=
4992 Etype (Extra_Parameter);
4993
4994 begin
4995 Append_To (Decls,
4996 Make_Object_Declaration (Loc,
4997 Defining_Identifier => Formal_Entity,
4998 Object_Definition =>
4999 New_Occurrence_Of (Formal_Type, Loc)));
5000
5001 Append_To (Extra_Formal_Statements,
5002 Make_Attribute_Reference (Loc,
5003 Prefix => New_Occurrence_Of (
5004 Formal_Type, Loc),
5005 Attribute_Name => Name_Read,
5006 Expressions => New_List (
5007 Make_Selected_Component (Loc,
5008 Prefix => Request_Parameter,
5009 Selector_Name => Name_Params),
5010 New_Occurrence_Of (Formal_Entity, Loc))));
5011
5012 -- Note: the call to Set_Extra_Constrained below relies
5013 -- on the fact that Object's Ekind has been set by
5014 -- Build_Actual_Object_Declaration.
5015
5016 Set_Extra_Constrained (Object, Formal_Entity);
5017 end;
5018 end if;
5019 end;
5020
5021 Next (Current_Parameter);
5022 end loop;
5023
5024 -- Append the formal statements list at the end of regular statements
5025
5026 Append_List_To (Statements, Extra_Formal_Statements);
5027
5028 if Nkind (Specification (Vis_Decl)) = N_Function_Specification then
5029
5030 -- The remote subprogram is a function. We build an inner block to
5031 -- be able to hold a potentially unconstrained result in a
5032 -- variable.
5033
5034 declare
5035 Etyp : constant Entity_Id :=
5036 Etype (Result_Definition (Specification (Vis_Decl)));
5037 Result : constant Node_Id := Make_Temporary (Loc, 'R');
5038
5039 begin
5040 Inner_Decls := New_List (
5041 Make_Object_Declaration (Loc,
5042 Defining_Identifier => Result,
5043 Constant_Present => True,
5044 Object_Definition => New_Occurrence_Of (Etyp, Loc),
5045 Expression =>
5046 Make_Function_Call (Loc,
5047 Name => Called_Subprogram,
5048 Parameter_Associations => Parameter_List)));
5049
5050 if Is_Class_Wide_Type (Etyp) then
5051
5052 -- For a remote call to a function with a class-wide type,
5053 -- check that the returned value satisfies the requirements
5054 -- of E.4(18).
5055
5056 Append_To (Inner_Decls,
5057 Make_Transportable_Check (Loc,
5058 New_Occurrence_Of (Result, Loc)));
5059
5060 end if;
5061
5062 Append_To (After_Statements,
5063 Make_Attribute_Reference (Loc,
5064 Prefix => New_Occurrence_Of (Etyp, Loc),
5065 Attribute_Name => Name_Output,
5066 Expressions => New_List (
5067 Make_Selected_Component (Loc,
5068 Prefix => Request_Parameter,
5069 Selector_Name => Name_Result),
5070 New_Occurrence_Of (Result, Loc))));
5071 end;
5072
5073 Append_To (Statements,
5074 Make_Block_Statement (Loc,
5075 Declarations => Inner_Decls,
5076 Handled_Statement_Sequence =>
5077 Make_Handled_Sequence_Of_Statements (Loc,
5078 Statements => After_Statements)));
5079
5080 else
5081 -- The remote subprogram is a procedure. We do not need any inner
5082 -- block in this case.
5083
5084 if Dynamically_Asynchronous then
5085 Append_To (Decls,
5086 Make_Object_Declaration (Loc,
5087 Defining_Identifier => Dynamic_Async,
5088 Object_Definition =>
5089 New_Occurrence_Of (Standard_Boolean, Loc)));
5090
5091 Append_To (Statements,
5092 Make_Attribute_Reference (Loc,
5093 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
5094 Attribute_Name => Name_Read,
5095 Expressions => New_List (
5096 Make_Selected_Component (Loc,
5097 Prefix => Request_Parameter,
5098 Selector_Name => Name_Params),
5099 New_Occurrence_Of (Dynamic_Async, Loc))));
5100 end if;
5101
5102 Append_To (Statements,
5103 Make_Procedure_Call_Statement (Loc,
5104 Name => Called_Subprogram,
5105 Parameter_Associations => Parameter_List));
5106
5107 Append_List_To (Statements, After_Statements);
5108 end if;
5109
5110 if Asynchronous and then not Dynamically_Asynchronous then
5111
5112 -- For an asynchronous procedure, add a null exception handler
5113
5114 Excep_Handlers := New_List (
5115 Make_Implicit_Exception_Handler (Loc,
5116 Exception_Choices => New_List (Make_Others_Choice (Loc)),
5117 Statements => New_List (Make_Null_Statement (Loc))));
5118
5119 else
5120 -- In the other cases, if an exception is raised, then the
5121 -- exception occurrence is copied into the output stream and
5122 -- no other output parameter is written.
5123
5124 Excep_Choice := Make_Temporary (Loc, 'E');
5125
5126 Excep_Code := New_List (
5127 Make_Attribute_Reference (Loc,
5128 Prefix =>
5129 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
5130 Attribute_Name => Name_Write,
5131 Expressions => New_List (
5132 Make_Selected_Component (Loc,
5133 Prefix => Request_Parameter,
5134 Selector_Name => Name_Result),
5135 New_Occurrence_Of (Excep_Choice, Loc))));
5136
5137 if Dynamically_Asynchronous then
5138 Excep_Code := New_List (
5139 Make_Implicit_If_Statement (Vis_Decl,
5140 Condition => Make_Op_Not (Loc,
5141 New_Occurrence_Of (Dynamic_Async, Loc)),
5142 Then_Statements => Excep_Code));
5143 end if;
5144
5145 Excep_Handlers := New_List (
5146 Make_Implicit_Exception_Handler (Loc,
5147 Choice_Parameter => Excep_Choice,
5148 Exception_Choices => New_List (Make_Others_Choice (Loc)),
5149 Statements => Excep_Code));
5150
5151 end if;
5152
5153 Subp_Spec :=
5154 Make_Procedure_Specification (Loc,
5155 Defining_Unit_Name => Make_Temporary (Loc, 'F'),
5156
5157 Parameter_Specifications => New_List (
5158 Make_Parameter_Specification (Loc,
5159 Defining_Identifier => Request_Parameter,
5160 Parameter_Type =>
5161 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
5162
5163 return
5164 Make_Subprogram_Body (Loc,
5165 Specification => Subp_Spec,
5166 Declarations => Decls,
5167 Handled_Statement_Sequence =>
5168 Make_Handled_Sequence_Of_Statements (Loc,
5169 Statements => Statements,
5170 Exception_Handlers => Excep_Handlers));
5171 end Build_Subprogram_Receiving_Stubs;
5172
5173 ------------
5174 -- Result --
5175 ------------
5176
5177 function Result return Node_Id is
5178 begin
5179 return Make_Identifier (Loc, Name_V);
5180 end Result;
5181
5182 -----------------------
5183 -- RPC_Receiver_Decl --
5184 -----------------------
5185
5186 function RPC_Receiver_Decl (RACW_Type : Entity_Id) return Node_Id is
5187 Loc : constant Source_Ptr := Sloc (RACW_Type);
5188 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5189
5190 begin
5191 -- No RPC receiver for remote access-to-subprogram
5192
5193 if Is_RAS then
5194 return Empty;
5195 end if;
5196
5197 return
5198 Make_Subprogram_Declaration (Loc,
5199 Build_RPC_Receiver_Specification
5200 (RPC_Receiver => Make_Temporary (Loc, 'R'),
5201 Request_Parameter => Make_Defining_Identifier (Loc, Name_R)));
5202 end RPC_Receiver_Decl;
5203
5204 ----------------------
5205 -- Stream_Parameter --
5206 ----------------------
5207
5208 function Stream_Parameter return Node_Id is
5209 begin
5210 return Make_Identifier (Loc, Name_S);
5211 end Stream_Parameter;
5212
5213 end GARLIC_Support;
5214
5215 -------------------------------
5216 -- Get_And_Reset_RACW_Bodies --
5217 -------------------------------
5218
5219 function Get_And_Reset_RACW_Bodies (RACW_Type : Entity_Id) return List_Id is
5220 Desig : constant Entity_Id :=
5221 Etype (Designated_Type (RACW_Type));
5222
5223 Stub_Elements : Stub_Structure := Stubs_Table.Get (Desig);
5224
5225 Body_Decls : List_Id;
5226 -- Returned list of declarations
5227
5228 begin
5229 if Stub_Elements = Empty_Stub_Structure then
5230
5231 -- Stub elements may be missing as a consequence of a previously
5232 -- detected error.
5233
5234 return No_List;
5235 end if;
5236
5237 Body_Decls := Stub_Elements.Body_Decls;
5238 Stub_Elements.Body_Decls := No_List;
5239 Stubs_Table.Set (Desig, Stub_Elements);
5240 return Body_Decls;
5241 end Get_And_Reset_RACW_Bodies;
5242
5243 -----------------------
5244 -- Get_Stub_Elements --
5245 -----------------------
5246
5247 function Get_Stub_Elements (RACW_Type : Entity_Id) return Stub_Structure is
5248 Desig : constant Entity_Id :=
5249 Etype (Designated_Type (RACW_Type));
5250 Stub_Elements : constant Stub_Structure := Stubs_Table.Get (Desig);
5251 begin
5252 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
5253 return Stub_Elements;
5254 end Get_Stub_Elements;
5255
5256 -----------------------
5257 -- Get_Subprogram_Id --
5258 -----------------------
5259
5260 function Get_Subprogram_Id (Def : Entity_Id) return String_Id is
5261 Result : constant String_Id := Get_Subprogram_Ids (Def).Str_Identifier;
5262 begin
5263 pragma Assert (Result /= No_String);
5264 return Result;
5265 end Get_Subprogram_Id;
5266
5267 -----------------------
5268 -- Get_Subprogram_Id --
5269 -----------------------
5270
5271 function Get_Subprogram_Id (Def : Entity_Id) return Int is
5272 begin
5273 return Get_Subprogram_Ids (Def).Int_Identifier;
5274 end Get_Subprogram_Id;
5275
5276 ------------------------
5277 -- Get_Subprogram_Ids --
5278 ------------------------
5279
5280 function Get_Subprogram_Ids
5281 (Def : Entity_Id) return Subprogram_Identifiers
5282 is
5283 begin
5284 return Subprogram_Identifier_Table.Get (Def);
5285 end Get_Subprogram_Ids;
5286
5287 ----------
5288 -- Hash --
5289 ----------
5290
5291 function Hash (F : Entity_Id) return Hash_Index is
5292 begin
5293 return Hash_Index (Natural (F) mod Positive (Hash_Index'Last + 1));
5294 end Hash;
5295
5296 function Hash (F : Name_Id) return Hash_Index is
5297 begin
5298 return Hash_Index (Integer (F) mod Positive (Hash_Index'Last + 1));
5299 end Hash;
5300
5301 --------------------------
5302 -- Input_With_Tag_Check --
5303 --------------------------
5304
5305 function Input_With_Tag_Check
5306 (Loc : Source_Ptr;
5307 Var_Type : Entity_Id;
5308 Stream : Node_Id) return Node_Id
5309 is
5310 begin
5311 return
5312 Make_Subprogram_Body (Loc,
5313 Specification =>
5314 Make_Function_Specification (Loc,
5315 Defining_Unit_Name => Make_Temporary (Loc, 'S'),
5316 Result_Definition => New_Occurrence_Of (Var_Type, Loc)),
5317 Declarations => No_List,
5318 Handled_Statement_Sequence =>
5319 Make_Handled_Sequence_Of_Statements (Loc, New_List (
5320 Make_Tag_Check (Loc,
5321 Make_Simple_Return_Statement (Loc,
5322 Make_Attribute_Reference (Loc,
5323 Prefix => New_Occurrence_Of (Var_Type, Loc),
5324 Attribute_Name => Name_Input,
5325 Expressions =>
5326 New_List (Stream)))))));
5327 end Input_With_Tag_Check;
5328
5329 --------------------------------
5330 -- Is_RACW_Controlling_Formal --
5331 --------------------------------
5332
5333 function Is_RACW_Controlling_Formal
5334 (Parameter : Node_Id;
5335 Stub_Type : Entity_Id) return Boolean
5336 is
5337 Typ : Entity_Id;
5338
5339 begin
5340 -- If the kind of the parameter is E_Void, then it is not a controlling
5341 -- formal (this can happen in the context of RAS).
5342
5343 if Ekind (Defining_Identifier (Parameter)) = E_Void then
5344 return False;
5345 end if;
5346
5347 -- If the parameter is not a controlling formal, then it cannot be
5348 -- possibly a RACW_Controlling_Formal.
5349
5350 if not Is_Controlling_Formal (Defining_Identifier (Parameter)) then
5351 return False;
5352 end if;
5353
5354 Typ := Parameter_Type (Parameter);
5355 return (Nkind (Typ) = N_Access_Definition
5356 and then Etype (Subtype_Mark (Typ)) = Stub_Type)
5357 or else Etype (Typ) = Stub_Type;
5358 end Is_RACW_Controlling_Formal;
5359
5360 ------------------------------
5361 -- Make_Transportable_Check --
5362 ------------------------------
5363
5364 function Make_Transportable_Check
5365 (Loc : Source_Ptr;
5366 Expr : Node_Id) return Node_Id is
5367 begin
5368 return
5369 Make_Raise_Program_Error (Loc,
5370 Condition =>
5371 Make_Op_Not (Loc,
5372 Build_Get_Transportable (Loc,
5373 Make_Selected_Component (Loc,
5374 Prefix => Expr,
5375 Selector_Name => Make_Identifier (Loc, Name_uTag)))),
5376 Reason => PE_Non_Transportable_Actual);
5377 end Make_Transportable_Check;
5378
5379 -----------------------------
5380 -- Make_Selected_Component --
5381 -----------------------------
5382
5383 function Make_Selected_Component
5384 (Loc : Source_Ptr;
5385 Prefix : Entity_Id;
5386 Selector_Name : Name_Id) return Node_Id
5387 is
5388 begin
5389 return Make_Selected_Component (Loc,
5390 Prefix => New_Occurrence_Of (Prefix, Loc),
5391 Selector_Name => Make_Identifier (Loc, Selector_Name));
5392 end Make_Selected_Component;
5393
5394 --------------------
5395 -- Make_Tag_Check --
5396 --------------------
5397
5398 function Make_Tag_Check (Loc : Source_Ptr; N : Node_Id) return Node_Id is
5399 Occ : constant Entity_Id := Make_Temporary (Loc, 'E');
5400
5401 begin
5402 return Make_Block_Statement (Loc,
5403 Handled_Statement_Sequence =>
5404 Make_Handled_Sequence_Of_Statements (Loc,
5405 Statements => New_List (N),
5406
5407 Exception_Handlers => New_List (
5408 Make_Implicit_Exception_Handler (Loc,
5409 Choice_Parameter => Occ,
5410
5411 Exception_Choices =>
5412 New_List (New_Occurrence_Of (RTE (RE_Tag_Error), Loc)),
5413
5414 Statements =>
5415 New_List (Make_Procedure_Call_Statement (Loc,
5416 New_Occurrence_Of
5417 (RTE (RE_Raise_Program_Error_Unknown_Tag), Loc),
5418 New_List (New_Occurrence_Of (Occ, Loc))))))));
5419 end Make_Tag_Check;
5420
5421 ----------------------------
5422 -- Need_Extra_Constrained --
5423 ----------------------------
5424
5425 function Need_Extra_Constrained (Parameter : Node_Id) return Boolean is
5426 Etyp : constant Entity_Id := Etype (Parameter_Type (Parameter));
5427 begin
5428 return Out_Present (Parameter)
5429 and then Has_Discriminants (Etyp)
5430 and then not Is_Constrained (Etyp)
5431 and then Is_Definite_Subtype (Etyp);
5432 end Need_Extra_Constrained;
5433
5434 ------------------------------------
5435 -- Pack_Entity_Into_Stream_Access --
5436 ------------------------------------
5437
5438 function Pack_Entity_Into_Stream_Access
5439 (Loc : Source_Ptr;
5440 Stream : Node_Id;
5441 Object : Entity_Id;
5442 Etyp : Entity_Id := Empty) return Node_Id
5443 is
5444 Typ : Entity_Id;
5445
5446 begin
5447 if Present (Etyp) then
5448 Typ := Etyp;
5449 else
5450 Typ := Etype (Object);
5451 end if;
5452
5453 return
5454 Pack_Node_Into_Stream_Access (Loc,
5455 Stream => Stream,
5456 Object => New_Occurrence_Of (Object, Loc),
5457 Etyp => Typ);
5458 end Pack_Entity_Into_Stream_Access;
5459
5460 ---------------------------
5461 -- Pack_Node_Into_Stream --
5462 ---------------------------
5463
5464 function Pack_Node_Into_Stream
5465 (Loc : Source_Ptr;
5466 Stream : Entity_Id;
5467 Object : Node_Id;
5468 Etyp : Entity_Id) return Node_Id
5469 is
5470 Write_Attribute : Name_Id := Name_Write;
5471
5472 begin
5473 if not Is_Constrained (Etyp) then
5474 Write_Attribute := Name_Output;
5475 end if;
5476
5477 return
5478 Make_Attribute_Reference (Loc,
5479 Prefix => New_Occurrence_Of (Etyp, Loc),
5480 Attribute_Name => Write_Attribute,
5481 Expressions => New_List (
5482 Make_Attribute_Reference (Loc,
5483 Prefix => New_Occurrence_Of (Stream, Loc),
5484 Attribute_Name => Name_Access),
5485 Object));
5486 end Pack_Node_Into_Stream;
5487
5488 ----------------------------------
5489 -- Pack_Node_Into_Stream_Access --
5490 ----------------------------------
5491
5492 function Pack_Node_Into_Stream_Access
5493 (Loc : Source_Ptr;
5494 Stream : Node_Id;
5495 Object : Node_Id;
5496 Etyp : Entity_Id) return Node_Id
5497 is
5498 Write_Attribute : Name_Id := Name_Write;
5499
5500 begin
5501 if not Is_Constrained (Etyp) then
5502 Write_Attribute := Name_Output;
5503 end if;
5504
5505 return
5506 Make_Attribute_Reference (Loc,
5507 Prefix => New_Occurrence_Of (Etyp, Loc),
5508 Attribute_Name => Write_Attribute,
5509 Expressions => New_List (
5510 Stream,
5511 Object));
5512 end Pack_Node_Into_Stream_Access;
5513
5514 ---------------------
5515 -- PolyORB_Support --
5516 ---------------------
5517
5518 package body PolyORB_Support is
5519
5520 -- Local subprograms
5521
5522 procedure Add_RACW_Read_Attribute
5523 (RACW_Type : Entity_Id;
5524 Stub_Type : Entity_Id;
5525 Stub_Type_Access : Entity_Id;
5526 Body_Decls : List_Id);
5527 -- Add Read attribute for the RACW type. The declaration and attribute
5528 -- definition clauses are inserted right after the declaration of
5529 -- RACW_Type. If Body_Decls is not No_List, the subprogram body is
5530 -- appended to it (case where the RACW declaration is in the main unit).
5531
5532 procedure Add_RACW_Write_Attribute
5533 (RACW_Type : Entity_Id;
5534 Stub_Type : Entity_Id;
5535 Stub_Type_Access : Entity_Id;
5536 Body_Decls : List_Id);
5537 -- Same as above for the Write attribute
5538
5539 procedure Add_RACW_From_Any
5540 (RACW_Type : Entity_Id;
5541 Body_Decls : List_Id);
5542 -- Add the From_Any TSS for this RACW type
5543
5544 procedure Add_RACW_To_Any
5545 (RACW_Type : Entity_Id;
5546 Body_Decls : List_Id);
5547 -- Add the To_Any TSS for this RACW type
5548
5549 procedure Add_RACW_TypeCode
5550 (Designated_Type : Entity_Id;
5551 RACW_Type : Entity_Id;
5552 Body_Decls : List_Id);
5553 -- Add the TypeCode TSS for this RACW type
5554
5555 procedure Add_RAS_From_Any (RAS_Type : Entity_Id);
5556 -- Add the From_Any TSS for this RAS type
5557
5558 procedure Add_RAS_To_Any (RAS_Type : Entity_Id);
5559 -- Add the To_Any TSS for this RAS type
5560
5561 procedure Add_RAS_TypeCode (RAS_Type : Entity_Id);
5562 -- Add the TypeCode TSS for this RAS type
5563
5564 procedure Add_RAS_Access_TSS (N : Node_Id);
5565 -- Add a subprogram body for RAS Access TSS
5566
5567 -------------------------------------
5568 -- Add_Obj_RPC_Receiver_Completion --
5569 -------------------------------------
5570
5571 procedure Add_Obj_RPC_Receiver_Completion
5572 (Loc : Source_Ptr;
5573 Decls : List_Id;
5574 RPC_Receiver : Entity_Id;
5575 Stub_Elements : Stub_Structure)
5576 is
5577 Desig : constant Entity_Id :=
5578 Etype (Designated_Type (Stub_Elements.RACW_Type));
5579 begin
5580 Append_To (Decls,
5581 Make_Procedure_Call_Statement (Loc,
5582 Name =>
5583 New_Occurrence_Of (
5584 RTE (RE_Register_Obj_Receiving_Stub), Loc),
5585
5586 Parameter_Associations => New_List (
5587
5588 -- Name
5589
5590 Make_String_Literal (Loc,
5591 Fully_Qualified_Name_String (Desig, Append_NUL => False)),
5592
5593 -- Handler
5594
5595 Make_Attribute_Reference (Loc,
5596 Prefix =>
5597 New_Occurrence_Of (
5598 Defining_Unit_Name (Parent (RPC_Receiver)), Loc),
5599 Attribute_Name =>
5600 Name_Access),
5601
5602 -- Receiver
5603
5604 Make_Attribute_Reference (Loc,
5605 Prefix =>
5606 New_Occurrence_Of (
5607 Defining_Identifier (
5608 Stub_Elements.RPC_Receiver_Decl), Loc),
5609 Attribute_Name =>
5610 Name_Access))));
5611 end Add_Obj_RPC_Receiver_Completion;
5612
5613 -----------------------
5614 -- Add_RACW_Features --
5615 -----------------------
5616
5617 procedure Add_RACW_Features
5618 (RACW_Type : Entity_Id;
5619 Desig : Entity_Id;
5620 Stub_Type : Entity_Id;
5621 Stub_Type_Access : Entity_Id;
5622 RPC_Receiver_Decl : Node_Id;
5623 Body_Decls : List_Id)
5624 is
5625 pragma Unreferenced (RPC_Receiver_Decl);
5626
5627 begin
5628 Add_RACW_From_Any
5629 (RACW_Type => RACW_Type,
5630 Body_Decls => Body_Decls);
5631
5632 Add_RACW_To_Any
5633 (RACW_Type => RACW_Type,
5634 Body_Decls => Body_Decls);
5635
5636 Add_RACW_Write_Attribute
5637 (RACW_Type => RACW_Type,
5638 Stub_Type => Stub_Type,
5639 Stub_Type_Access => Stub_Type_Access,
5640 Body_Decls => Body_Decls);
5641
5642 Add_RACW_Read_Attribute
5643 (RACW_Type => RACW_Type,
5644 Stub_Type => Stub_Type,
5645 Stub_Type_Access => Stub_Type_Access,
5646 Body_Decls => Body_Decls);
5647
5648 Add_RACW_TypeCode
5649 (Designated_Type => Desig,
5650 RACW_Type => RACW_Type,
5651 Body_Decls => Body_Decls);
5652 end Add_RACW_Features;
5653
5654 -----------------------
5655 -- Add_RACW_From_Any --
5656 -----------------------
5657
5658 procedure Add_RACW_From_Any
5659 (RACW_Type : Entity_Id;
5660 Body_Decls : List_Id)
5661 is
5662 Loc : constant Source_Ptr := Sloc (RACW_Type);
5663 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5664 Fnam : constant Entity_Id :=
5665 Make_Defining_Identifier (Loc,
5666 Chars => New_External_Name (Chars (RACW_Type), 'F'));
5667
5668 Func_Spec : Node_Id;
5669 Func_Decl : Node_Id;
5670 Func_Body : Node_Id;
5671
5672 Statements : List_Id;
5673 -- Various parts of the subprogram
5674
5675 Any_Parameter : constant Entity_Id :=
5676 Make_Defining_Identifier (Loc, Name_A);
5677
5678 Asynchronous_Flag : constant Entity_Id :=
5679 Asynchronous_Flags_Table.Get (RACW_Type);
5680 -- The flag object declared in Add_RACW_Asynchronous_Flag
5681
5682 begin
5683 Func_Spec :=
5684 Make_Function_Specification (Loc,
5685 Defining_Unit_Name =>
5686 Fnam,
5687 Parameter_Specifications => New_List (
5688 Make_Parameter_Specification (Loc,
5689 Defining_Identifier =>
5690 Any_Parameter,
5691 Parameter_Type =>
5692 New_Occurrence_Of (RTE (RE_Any), Loc))),
5693 Result_Definition => New_Occurrence_Of (RACW_Type, Loc));
5694
5695 -- NOTE: The usage occurrences of RACW_Parameter must refer to the
5696 -- entity in the declaration spec, not those of the body spec.
5697
5698 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
5699 Insert_After (Declaration_Node (RACW_Type), Func_Decl);
5700 Set_Renaming_TSS (RACW_Type, Fnam, TSS_From_Any);
5701
5702 if No (Body_Decls) then
5703 return;
5704 end if;
5705
5706 -- ??? Issue with asynchronous calls here: the Asynchronous flag is
5707 -- set on the stub type if, and only if, the RACW type has a pragma
5708 -- Asynchronous. This is incorrect for RACWs that implement RAS
5709 -- types, because in that case the /designated subprogram/ (not the
5710 -- type) might be asynchronous, and that causes the stub to need to
5711 -- be asynchronous too. A solution is to transport a RAS as a struct
5712 -- containing a RACW and an asynchronous flag, and to properly alter
5713 -- the Asynchronous component in the stub type in the RAS's _From_Any
5714 -- TSS.
5715
5716 Statements := New_List (
5717 Make_Simple_Return_Statement (Loc,
5718 Expression => Unchecked_Convert_To (RACW_Type,
5719 Make_Function_Call (Loc,
5720 Name => New_Occurrence_Of (RTE (RE_Get_RACW), Loc),
5721 Parameter_Associations => New_List (
5722 Make_Function_Call (Loc,
5723 Name => New_Occurrence_Of (RTE (RE_FA_ObjRef), Loc),
5724 Parameter_Associations => New_List (
5725 New_Occurrence_Of (Any_Parameter, Loc))),
5726 Build_Stub_Tag (Loc, RACW_Type),
5727 New_Occurrence_Of (Boolean_Literals (Is_RAS), Loc),
5728 New_Occurrence_Of (Asynchronous_Flag, Loc))))));
5729
5730 Func_Body :=
5731 Make_Subprogram_Body (Loc,
5732 Specification => Copy_Specification (Loc, Func_Spec),
5733 Declarations => No_List,
5734 Handled_Statement_Sequence =>
5735 Make_Handled_Sequence_Of_Statements (Loc,
5736 Statements => Statements));
5737
5738 Append_To (Body_Decls, Func_Body);
5739 end Add_RACW_From_Any;
5740
5741 -----------------------------
5742 -- Add_RACW_Read_Attribute --
5743 -----------------------------
5744
5745 procedure Add_RACW_Read_Attribute
5746 (RACW_Type : Entity_Id;
5747 Stub_Type : Entity_Id;
5748 Stub_Type_Access : Entity_Id;
5749 Body_Decls : List_Id)
5750 is
5751 pragma Unreferenced (Stub_Type, Stub_Type_Access);
5752
5753 Loc : constant Source_Ptr := Sloc (RACW_Type);
5754
5755 Proc_Decl : Node_Id;
5756 Attr_Decl : Node_Id;
5757
5758 Body_Node : Node_Id;
5759
5760 Decls : constant List_Id := New_List;
5761 Statements : constant List_Id := New_List;
5762 Reference : constant Entity_Id :=
5763 Make_Defining_Identifier (Loc, Name_R);
5764 -- Various parts of the procedure
5765
5766 Pnam : constant Entity_Id := Make_Temporary (Loc, 'R');
5767
5768 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5769
5770 Asynchronous_Flag : constant Entity_Id :=
5771 Asynchronous_Flags_Table.Get (RACW_Type);
5772 pragma Assert (Present (Asynchronous_Flag));
5773
5774 function Stream_Parameter return Node_Id;
5775 function Result return Node_Id;
5776
5777 -- Functions to create occurrences of the formal parameter names
5778
5779 ------------
5780 -- Result --
5781 ------------
5782
5783 function Result return Node_Id is
5784 begin
5785 return Make_Identifier (Loc, Name_V);
5786 end Result;
5787
5788 ----------------------
5789 -- Stream_Parameter --
5790 ----------------------
5791
5792 function Stream_Parameter return Node_Id is
5793 begin
5794 return Make_Identifier (Loc, Name_S);
5795 end Stream_Parameter;
5796
5797 -- Start of processing for Add_RACW_Read_Attribute
5798
5799 begin
5800 Build_Stream_Procedure
5801 (RACW_Type, Body_Node, Pnam, Statements, Outp => True);
5802
5803 Proc_Decl := Make_Subprogram_Declaration (Loc,
5804 Copy_Specification (Loc, Specification (Body_Node)));
5805
5806 Attr_Decl :=
5807 Make_Attribute_Definition_Clause (Loc,
5808 Name => New_Occurrence_Of (RACW_Type, Loc),
5809 Chars => Name_Read,
5810 Expression =>
5811 New_Occurrence_Of (
5812 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
5813
5814 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
5815 Insert_After (Proc_Decl, Attr_Decl);
5816
5817 if No (Body_Decls) then
5818 return;
5819 end if;
5820
5821 Append_To (Decls,
5822 Make_Object_Declaration (Loc,
5823 Defining_Identifier =>
5824 Reference,
5825 Object_Definition =>
5826 New_Occurrence_Of (RTE (RE_Object_Ref), Loc)));
5827
5828 Append_List_To (Statements, New_List (
5829 Make_Attribute_Reference (Loc,
5830 Prefix =>
5831 New_Occurrence_Of (RTE (RE_Object_Ref), Loc),
5832 Attribute_Name => Name_Read,
5833 Expressions => New_List (
5834 Stream_Parameter,
5835 New_Occurrence_Of (Reference, Loc))),
5836
5837 Make_Assignment_Statement (Loc,
5838 Name =>
5839 Result,
5840 Expression =>
5841 Unchecked_Convert_To (RACW_Type,
5842 Make_Function_Call (Loc,
5843 Name =>
5844 New_Occurrence_Of (RTE (RE_Get_RACW), Loc),
5845 Parameter_Associations => New_List (
5846 New_Occurrence_Of (Reference, Loc),
5847 Build_Stub_Tag (Loc, RACW_Type),
5848 New_Occurrence_Of (Boolean_Literals (Is_RAS), Loc),
5849 New_Occurrence_Of (Asynchronous_Flag, Loc)))))));
5850
5851 Set_Declarations (Body_Node, Decls);
5852 Append_To (Body_Decls, Body_Node);
5853 end Add_RACW_Read_Attribute;
5854
5855 ---------------------
5856 -- Add_RACW_To_Any --
5857 ---------------------
5858
5859 procedure Add_RACW_To_Any
5860 (RACW_Type : Entity_Id;
5861 Body_Decls : List_Id)
5862 is
5863 Loc : constant Source_Ptr := Sloc (RACW_Type);
5864
5865 Fnam : constant Entity_Id :=
5866 Make_Defining_Identifier (Loc,
5867 Chars => New_External_Name (Chars (RACW_Type), 'T'));
5868
5869 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5870
5871 Stub_Elements : constant Stub_Structure :=
5872 Get_Stub_Elements (RACW_Type);
5873
5874 Func_Spec : Node_Id;
5875 Func_Decl : Node_Id;
5876 Func_Body : Node_Id;
5877
5878 Decls : List_Id;
5879 Statements : List_Id;
5880 -- Various parts of the subprogram
5881
5882 RACW_Parameter : constant Entity_Id :=
5883 Make_Defining_Identifier (Loc, Name_R);
5884
5885 Reference : constant Entity_Id := Make_Temporary (Loc, 'R');
5886 Any : constant Entity_Id := Make_Temporary (Loc, 'A');
5887
5888 begin
5889 Func_Spec :=
5890 Make_Function_Specification (Loc,
5891 Defining_Unit_Name =>
5892 Fnam,
5893 Parameter_Specifications => New_List (
5894 Make_Parameter_Specification (Loc,
5895 Defining_Identifier =>
5896 RACW_Parameter,
5897 Parameter_Type =>
5898 New_Occurrence_Of (RACW_Type, Loc))),
5899 Result_Definition => New_Occurrence_Of (RTE (RE_Any), Loc));
5900
5901 -- NOTE: The usage occurrences of RACW_Parameter must refer to the
5902 -- entity in the declaration spec, not in the body spec.
5903
5904 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
5905
5906 Insert_After (Declaration_Node (RACW_Type), Func_Decl);
5907 Set_Renaming_TSS (RACW_Type, Fnam, TSS_To_Any);
5908
5909 if No (Body_Decls) then
5910 return;
5911 end if;
5912
5913 -- Generate:
5914
5915 -- R : constant Object_Ref :=
5916 -- Get_Reference
5917 -- (Address!(RACW),
5918 -- "typ",
5919 -- Stub_Type'Tag,
5920 -- Is_RAS,
5921 -- RPC_Receiver'Access);
5922 -- A : Any;
5923
5924 Decls := New_List (
5925 Make_Object_Declaration (Loc,
5926 Defining_Identifier => Reference,
5927 Constant_Present => True,
5928 Object_Definition =>
5929 New_Occurrence_Of (RTE (RE_Object_Ref), Loc),
5930 Expression =>
5931 Make_Function_Call (Loc,
5932 Name => New_Occurrence_Of (RTE (RE_Get_Reference), Loc),
5933 Parameter_Associations => New_List (
5934 Unchecked_Convert_To (RTE (RE_Address),
5935 New_Occurrence_Of (RACW_Parameter, Loc)),
5936 Make_String_Literal (Loc,
5937 Strval => Fully_Qualified_Name_String
5938 (Etype (Designated_Type (RACW_Type)),
5939 Append_NUL => False)),
5940 Build_Stub_Tag (Loc, RACW_Type),
5941 New_Occurrence_Of (Boolean_Literals (Is_RAS), Loc),
5942 Make_Attribute_Reference (Loc,
5943 Prefix =>
5944 New_Occurrence_Of
5945 (Defining_Identifier
5946 (Stub_Elements.RPC_Receiver_Decl), Loc),
5947 Attribute_Name => Name_Access)))),
5948
5949 Make_Object_Declaration (Loc,
5950 Defining_Identifier => Any,
5951 Object_Definition => New_Occurrence_Of (RTE (RE_Any), Loc)));
5952
5953 -- Generate:
5954
5955 -- Any := TA_ObjRef (Reference);
5956 -- Set_TC (Any, RPC_Receiver.Obj_TypeCode);
5957 -- return Any;
5958
5959 Statements := New_List (
5960 Make_Assignment_Statement (Loc,
5961 Name => New_Occurrence_Of (Any, Loc),
5962 Expression =>
5963 Make_Function_Call (Loc,
5964 Name => New_Occurrence_Of (RTE (RE_TA_ObjRef), Loc),
5965 Parameter_Associations => New_List (
5966 New_Occurrence_Of (Reference, Loc)))),
5967
5968 Make_Procedure_Call_Statement (Loc,
5969 Name => New_Occurrence_Of (RTE (RE_Set_TC), Loc),
5970 Parameter_Associations => New_List (
5971 New_Occurrence_Of (Any, Loc),
5972 Make_Selected_Component (Loc,
5973 Prefix =>
5974 Defining_Identifier (
5975 Stub_Elements.RPC_Receiver_Decl),
5976 Selector_Name => Name_Obj_TypeCode))),
5977
5978 Make_Simple_Return_Statement (Loc,
5979 Expression => New_Occurrence_Of (Any, Loc)));
5980
5981 Func_Body :=
5982 Make_Subprogram_Body (Loc,
5983 Specification => Copy_Specification (Loc, Func_Spec),
5984 Declarations => Decls,
5985 Handled_Statement_Sequence =>
5986 Make_Handled_Sequence_Of_Statements (Loc,
5987 Statements => Statements));
5988 Append_To (Body_Decls, Func_Body);
5989 end Add_RACW_To_Any;
5990
5991 -----------------------
5992 -- Add_RACW_TypeCode --
5993 -----------------------
5994
5995 procedure Add_RACW_TypeCode
5996 (Designated_Type : Entity_Id;
5997 RACW_Type : Entity_Id;
5998 Body_Decls : List_Id)
5999 is
6000 Loc : constant Source_Ptr := Sloc (RACW_Type);
6001
6002 Fnam : constant Entity_Id :=
6003 Make_Defining_Identifier (Loc,
6004 Chars => New_External_Name (Chars (RACW_Type), 'Y'));
6005
6006 Stub_Elements : constant Stub_Structure :=
6007 Stubs_Table.Get (Designated_Type);
6008 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
6009
6010 Func_Spec : Node_Id;
6011 Func_Decl : Node_Id;
6012 Func_Body : Node_Id;
6013
6014 begin
6015 -- The spec for this subprogram has a dummy 'access RACW' argument,
6016 -- which serves only for overloading purposes.
6017
6018 Func_Spec :=
6019 Make_Function_Specification (Loc,
6020 Defining_Unit_Name => Fnam,
6021 Result_Definition => New_Occurrence_Of (RTE (RE_TypeCode), Loc));
6022
6023 -- NOTE: The usage occurrences of RACW_Parameter must refer to the
6024 -- entity in the declaration spec, not those of the body spec.
6025
6026 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
6027 Insert_After (Declaration_Node (RACW_Type), Func_Decl);
6028 Set_Renaming_TSS (RACW_Type, Fnam, TSS_TypeCode);
6029
6030 if No (Body_Decls) then
6031 return;
6032 end if;
6033
6034 Func_Body :=
6035 Make_Subprogram_Body (Loc,
6036 Specification => Copy_Specification (Loc, Func_Spec),
6037 Declarations => Empty_List,
6038 Handled_Statement_Sequence =>
6039 Make_Handled_Sequence_Of_Statements (Loc,
6040 Statements => New_List (
6041 Make_Simple_Return_Statement (Loc,
6042 Expression =>
6043 Make_Selected_Component (Loc,
6044 Prefix =>
6045 Defining_Identifier
6046 (Stub_Elements.RPC_Receiver_Decl),
6047 Selector_Name => Name_Obj_TypeCode)))));
6048
6049 Append_To (Body_Decls, Func_Body);
6050 end Add_RACW_TypeCode;
6051
6052 ------------------------------
6053 -- Add_RACW_Write_Attribute --
6054 ------------------------------
6055
6056 procedure Add_RACW_Write_Attribute
6057 (RACW_Type : Entity_Id;
6058 Stub_Type : Entity_Id;
6059 Stub_Type_Access : Entity_Id;
6060 Body_Decls : List_Id)
6061 is
6062 pragma Unreferenced (Stub_Type, Stub_Type_Access);
6063
6064 Loc : constant Source_Ptr := Sloc (RACW_Type);
6065
6066 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
6067
6068 Stub_Elements : constant Stub_Structure :=
6069 Get_Stub_Elements (RACW_Type);
6070
6071 Body_Node : Node_Id;
6072 Proc_Decl : Node_Id;
6073 Attr_Decl : Node_Id;
6074
6075 Statements : constant List_Id := New_List;
6076 Pnam : constant Entity_Id := Make_Temporary (Loc, 'R');
6077
6078 function Stream_Parameter return Node_Id;
6079 function Object return Node_Id;
6080 -- Functions to create occurrences of the formal parameter names
6081
6082 ------------
6083 -- Object --
6084 ------------
6085
6086 function Object return Node_Id is
6087 begin
6088 return Make_Identifier (Loc, Name_V);
6089 end Object;
6090
6091 ----------------------
6092 -- Stream_Parameter --
6093 ----------------------
6094
6095 function Stream_Parameter return Node_Id is
6096 begin
6097 return Make_Identifier (Loc, Name_S);
6098 end Stream_Parameter;
6099
6100 -- Start of processing for Add_RACW_Write_Attribute
6101
6102 begin
6103 Build_Stream_Procedure
6104 (RACW_Type, Body_Node, Pnam, Statements, Outp => False);
6105
6106 Proc_Decl :=
6107 Make_Subprogram_Declaration (Loc,
6108 Copy_Specification (Loc, Specification (Body_Node)));
6109
6110 Attr_Decl :=
6111 Make_Attribute_Definition_Clause (Loc,
6112 Name => New_Occurrence_Of (RACW_Type, Loc),
6113 Chars => Name_Write,
6114 Expression =>
6115 New_Occurrence_Of (
6116 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
6117
6118 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
6119 Insert_After (Proc_Decl, Attr_Decl);
6120
6121 if No (Body_Decls) then
6122 return;
6123 end if;
6124
6125 Append_To (Statements,
6126 Pack_Node_Into_Stream_Access (Loc,
6127 Stream => Stream_Parameter,
6128 Object =>
6129 Make_Function_Call (Loc,
6130 Name => New_Occurrence_Of (RTE (RE_Get_Reference), Loc),
6131 Parameter_Associations => New_List (
6132 Unchecked_Convert_To (RTE (RE_Address), Object),
6133 Make_String_Literal (Loc,
6134 Strval => Fully_Qualified_Name_String
6135 (Etype (Designated_Type (RACW_Type)),
6136 Append_NUL => False)),
6137 Build_Stub_Tag (Loc, RACW_Type),
6138 New_Occurrence_Of (Boolean_Literals (Is_RAS), Loc),
6139 Make_Attribute_Reference (Loc,
6140 Prefix =>
6141 New_Occurrence_Of
6142 (Defining_Identifier
6143 (Stub_Elements.RPC_Receiver_Decl), Loc),
6144 Attribute_Name => Name_Access))),
6145
6146 Etyp => RTE (RE_Object_Ref)));
6147
6148 Append_To (Body_Decls, Body_Node);
6149 end Add_RACW_Write_Attribute;
6150
6151 -----------------------
6152 -- Add_RAST_Features --
6153 -----------------------
6154
6155 procedure Add_RAST_Features
6156 (Vis_Decl : Node_Id;
6157 RAS_Type : Entity_Id)
6158 is
6159 begin
6160 Add_RAS_Access_TSS (Vis_Decl);
6161
6162 Add_RAS_From_Any (RAS_Type);
6163 Add_RAS_TypeCode (RAS_Type);
6164
6165 -- To_Any uses TypeCode, and therefore needs to be generated last
6166
6167 Add_RAS_To_Any (RAS_Type);
6168 end Add_RAST_Features;
6169
6170 ------------------------
6171 -- Add_RAS_Access_TSS --
6172 ------------------------
6173
6174 procedure Add_RAS_Access_TSS (N : Node_Id) is
6175 Loc : constant Source_Ptr := Sloc (N);
6176
6177 Ras_Type : constant Entity_Id := Defining_Identifier (N);
6178 Fat_Type : constant Entity_Id := Equivalent_Type (Ras_Type);
6179 -- Ras_Type is the access to subprogram type; Fat_Type is the
6180 -- corresponding record type.
6181
6182 RACW_Type : constant Entity_Id :=
6183 Underlying_RACW_Type (Ras_Type);
6184
6185 Stub_Elements : constant Stub_Structure :=
6186 Get_Stub_Elements (RACW_Type);
6187
6188 Proc : constant Entity_Id :=
6189 Make_Defining_Identifier (Loc,
6190 Chars => Make_TSS_Name (Ras_Type, TSS_RAS_Access));
6191
6192 Proc_Spec : Node_Id;
6193
6194 -- Formal parameters
6195
6196 Package_Name : constant Entity_Id :=
6197 Make_Defining_Identifier (Loc,
6198 Chars => Name_P);
6199
6200 -- Target package
6201
6202 Subp_Id : constant Entity_Id :=
6203 Make_Defining_Identifier (Loc,
6204 Chars => Name_S);
6205
6206 -- Target subprogram
6207
6208 Asynch_P : constant Entity_Id :=
6209 Make_Defining_Identifier (Loc,
6210 Chars => Name_Asynchronous);
6211 -- Is the procedure to which the 'Access applies asynchronous?
6212
6213 All_Calls_Remote : constant Entity_Id :=
6214 Make_Defining_Identifier (Loc,
6215 Chars => Name_All_Calls_Remote);
6216 -- True if an All_Calls_Remote pragma applies to the RCI unit
6217 -- that contains the subprogram.
6218
6219 -- Common local variables
6220
6221 Proc_Decls : List_Id;
6222 Proc_Statements : List_Id;
6223
6224 Subp_Ref : constant Entity_Id :=
6225 Make_Defining_Identifier (Loc, Name_R);
6226 -- Reference that designates the target subprogram (returned
6227 -- by Get_RAS_Info).
6228
6229 Is_Local : constant Entity_Id :=
6230 Make_Defining_Identifier (Loc, Name_L);
6231 Local_Addr : constant Entity_Id :=
6232 Make_Defining_Identifier (Loc, Name_A);
6233 -- For the call to Get_Local_Address
6234
6235 Local_Stub : constant Entity_Id := Make_Temporary (Loc, 'L');
6236 Stub_Ptr : constant Entity_Id := Make_Temporary (Loc, 'S');
6237 -- Additional local variables for the remote case
6238
6239 function Set_Field
6240 (Field_Name : Name_Id;
6241 Value : Node_Id) return Node_Id;
6242 -- Construct an assignment that sets the named component in the
6243 -- returned record
6244
6245 ---------------
6246 -- Set_Field --
6247 ---------------
6248
6249 function Set_Field
6250 (Field_Name : Name_Id;
6251 Value : Node_Id) return Node_Id
6252 is
6253 begin
6254 return
6255 Make_Assignment_Statement (Loc,
6256 Name =>
6257 Make_Selected_Component (Loc,
6258 Prefix => Stub_Ptr,
6259 Selector_Name => Field_Name),
6260 Expression => Value);
6261 end Set_Field;
6262
6263 -- Start of processing for Add_RAS_Access_TSS
6264
6265 begin
6266 Proc_Decls := New_List (
6267
6268 -- Common declarations
6269
6270 Make_Object_Declaration (Loc,
6271 Defining_Identifier => Subp_Ref,
6272 Object_Definition =>
6273 New_Occurrence_Of (RTE (RE_Object_Ref), Loc)),
6274
6275 Make_Object_Declaration (Loc,
6276 Defining_Identifier => Is_Local,
6277 Object_Definition =>
6278 New_Occurrence_Of (Standard_Boolean, Loc)),
6279
6280 Make_Object_Declaration (Loc,
6281 Defining_Identifier => Local_Addr,
6282 Object_Definition =>
6283 New_Occurrence_Of (RTE (RE_Address), Loc)),
6284
6285 Make_Object_Declaration (Loc,
6286 Defining_Identifier => Local_Stub,
6287 Aliased_Present => True,
6288 Object_Definition =>
6289 New_Occurrence_Of (Stub_Elements.Stub_Type, Loc)),
6290
6291 Make_Object_Declaration (Loc,
6292 Defining_Identifier => Stub_Ptr,
6293 Object_Definition =>
6294 New_Occurrence_Of (Stub_Elements.Stub_Type_Access, Loc),
6295 Expression =>
6296 Make_Attribute_Reference (Loc,
6297 Prefix => New_Occurrence_Of (Local_Stub, Loc),
6298 Attribute_Name => Name_Unchecked_Access)));
6299
6300 Set_Etype (Stub_Ptr, Stub_Elements.Stub_Type_Access);
6301 -- Build_Get_Unique_RP_Call needs this information
6302
6303 -- Get_RAS_Info (Pkg, Subp, R);
6304 -- Obtain a reference to the target subprogram
6305
6306 Proc_Statements := New_List (
6307 Make_Procedure_Call_Statement (Loc,
6308 Name => New_Occurrence_Of (RTE (RE_Get_RAS_Info), Loc),
6309 Parameter_Associations => New_List (
6310 New_Occurrence_Of (Package_Name, Loc),
6311 New_Occurrence_Of (Subp_Id, Loc),
6312 New_Occurrence_Of (Subp_Ref, Loc))),
6313
6314 -- Get_Local_Address (R, L, A);
6315 -- Determine whether the subprogram is local (L), and if so
6316 -- obtain the local address of its proxy (A).
6317
6318 Make_Procedure_Call_Statement (Loc,
6319 Name => New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
6320 Parameter_Associations => New_List (
6321 New_Occurrence_Of (Subp_Ref, Loc),
6322 New_Occurrence_Of (Is_Local, Loc),
6323 New_Occurrence_Of (Local_Addr, Loc))));
6324
6325 -- Note: Here we assume that the Fat_Type is a record containing just
6326 -- an access to a proxy or stub object.
6327
6328 Append_To (Proc_Statements,
6329
6330 -- if L then
6331
6332 Make_Implicit_If_Statement (N,
6333 Condition => New_Occurrence_Of (Is_Local, Loc),
6334
6335 Then_Statements => New_List (
6336
6337 -- if A.Target = null then
6338
6339 Make_Implicit_If_Statement (N,
6340 Condition =>
6341 Make_Op_Eq (Loc,
6342 Make_Selected_Component (Loc,
6343 Prefix =>
6344 Unchecked_Convert_To
6345 (RTE (RE_RAS_Proxy_Type_Access),
6346 New_Occurrence_Of (Local_Addr, Loc)),
6347 Selector_Name => Make_Identifier (Loc, Name_Target)),
6348 Make_Null (Loc)),
6349
6350 Then_Statements => New_List (
6351
6352 -- A.Target := Entity_Of (Ref);
6353
6354 Make_Assignment_Statement (Loc,
6355 Name =>
6356 Make_Selected_Component (Loc,
6357 Prefix =>
6358 Unchecked_Convert_To
6359 (RTE (RE_RAS_Proxy_Type_Access),
6360 New_Occurrence_Of (Local_Addr, Loc)),
6361 Selector_Name => Make_Identifier (Loc, Name_Target)),
6362 Expression =>
6363 Make_Function_Call (Loc,
6364 Name => New_Occurrence_Of (RTE (RE_Entity_Of), Loc),
6365 Parameter_Associations => New_List (
6366 New_Occurrence_Of (Subp_Ref, Loc)))),
6367
6368 -- Inc_Usage (A.Target);
6369 -- end if;
6370
6371 Make_Procedure_Call_Statement (Loc,
6372 Name => New_Occurrence_Of (RTE (RE_Inc_Usage), Loc),
6373 Parameter_Associations => New_List (
6374 Make_Selected_Component (Loc,
6375 Prefix =>
6376 Unchecked_Convert_To
6377 (RTE (RE_RAS_Proxy_Type_Access),
6378 New_Occurrence_Of (Local_Addr, Loc)),
6379 Selector_Name =>
6380 Make_Identifier (Loc, Name_Target)))))),
6381
6382 -- if not All_Calls_Remote then
6383 -- return Fat_Type!(A);
6384 -- end if;
6385
6386 Make_Implicit_If_Statement (N,
6387 Condition =>
6388 Make_Op_Not (Loc,
6389 Right_Opnd =>
6390 New_Occurrence_Of (All_Calls_Remote, Loc)),
6391
6392 Then_Statements => New_List (
6393 Make_Simple_Return_Statement (Loc,
6394 Expression =>
6395 Unchecked_Convert_To
6396 (Fat_Type, New_Occurrence_Of (Local_Addr, Loc))))))));
6397
6398 Append_List_To (Proc_Statements, New_List (
6399
6400 -- Stub.Target := Entity_Of (Ref);
6401
6402 Set_Field (Name_Target,
6403 Make_Function_Call (Loc,
6404 Name => New_Occurrence_Of (RTE (RE_Entity_Of), Loc),
6405 Parameter_Associations => New_List (
6406 New_Occurrence_Of (Subp_Ref, Loc)))),
6407
6408 -- Inc_Usage (Stub.Target);
6409
6410 Make_Procedure_Call_Statement (Loc,
6411 Name => New_Occurrence_Of (RTE (RE_Inc_Usage), Loc),
6412 Parameter_Associations => New_List (
6413 Make_Selected_Component (Loc,
6414 Prefix => Stub_Ptr,
6415 Selector_Name => Name_Target))),
6416
6417 -- E.4.1(9) A remote call is asynchronous if it is a call to
6418 -- a procedure, or a call through a value of an access-to-procedure
6419 -- type, to which a pragma Asynchronous applies.
6420
6421 -- Parameter Asynch_P is true when the procedure is asynchronous;
6422 -- Expression Asynch_T is true when the type is asynchronous.
6423
6424 Set_Field (Name_Asynchronous,
6425 Make_Or_Else (Loc,
6426 Left_Opnd => New_Occurrence_Of (Asynch_P, Loc),
6427 Right_Opnd =>
6428 New_Occurrence_Of
6429 (Boolean_Literals (Is_Asynchronous (Ras_Type)), Loc)))));
6430
6431 Append_List_To (Proc_Statements,
6432 Build_Get_Unique_RP_Call (Loc, Stub_Ptr, Stub_Elements.Stub_Type));
6433
6434 Append_To (Proc_Statements,
6435 Make_Simple_Return_Statement (Loc,
6436 Expression =>
6437 Unchecked_Convert_To (Fat_Type,
6438 New_Occurrence_Of (Stub_Ptr, Loc))));
6439
6440 Proc_Spec :=
6441 Make_Function_Specification (Loc,
6442 Defining_Unit_Name => Proc,
6443 Parameter_Specifications => New_List (
6444 Make_Parameter_Specification (Loc,
6445 Defining_Identifier => Package_Name,
6446 Parameter_Type =>
6447 New_Occurrence_Of (Standard_String, Loc)),
6448
6449 Make_Parameter_Specification (Loc,
6450 Defining_Identifier => Subp_Id,
6451 Parameter_Type =>
6452 New_Occurrence_Of (Standard_String, Loc)),
6453
6454 Make_Parameter_Specification (Loc,
6455 Defining_Identifier => Asynch_P,
6456 Parameter_Type =>
6457 New_Occurrence_Of (Standard_Boolean, Loc)),
6458
6459 Make_Parameter_Specification (Loc,
6460 Defining_Identifier => All_Calls_Remote,
6461 Parameter_Type =>
6462 New_Occurrence_Of (Standard_Boolean, Loc))),
6463
6464 Result_Definition =>
6465 New_Occurrence_Of (Fat_Type, Loc));
6466
6467 -- Set the kind and return type of the function to prevent
6468 -- ambiguities between Ras_Type and Fat_Type in subsequent analysis.
6469
6470 Mutate_Ekind (Proc, E_Function);
6471 Set_Etype (Proc, Fat_Type);
6472
6473 Discard_Node (
6474 Make_Subprogram_Body (Loc,
6475 Specification => Proc_Spec,
6476 Declarations => Proc_Decls,
6477 Handled_Statement_Sequence =>
6478 Make_Handled_Sequence_Of_Statements (Loc,
6479 Statements => Proc_Statements)));
6480
6481 Set_TSS (Fat_Type, Proc);
6482 end Add_RAS_Access_TSS;
6483
6484 ----------------------
6485 -- Add_RAS_From_Any --
6486 ----------------------
6487
6488 procedure Add_RAS_From_Any (RAS_Type : Entity_Id) is
6489 Loc : constant Source_Ptr := Sloc (RAS_Type);
6490
6491 Fnam : constant Entity_Id := Make_Defining_Identifier (Loc,
6492 Make_TSS_Name (RAS_Type, TSS_From_Any));
6493
6494 Func_Spec : Node_Id;
6495
6496 Statements : List_Id;
6497
6498 Any_Parameter : constant Entity_Id :=
6499 Make_Defining_Identifier (Loc, Name_A);
6500
6501 begin
6502 Statements := New_List (
6503 Make_Simple_Return_Statement (Loc,
6504 Expression =>
6505 Make_Aggregate (Loc,
6506 Component_Associations => New_List (
6507 Make_Component_Association (Loc,
6508 Choices => New_List (Make_Identifier (Loc, Name_Ras)),
6509 Expression =>
6510 PolyORB_Support.Helpers.Build_From_Any_Call
6511 (Underlying_RACW_Type (RAS_Type),
6512 New_Occurrence_Of (Any_Parameter, Loc),
6513 No_List))))));
6514
6515 Func_Spec :=
6516 Make_Function_Specification (Loc,
6517 Defining_Unit_Name => Fnam,
6518 Parameter_Specifications => New_List (
6519 Make_Parameter_Specification (Loc,
6520 Defining_Identifier => Any_Parameter,
6521 Parameter_Type => New_Occurrence_Of (RTE (RE_Any), Loc))),
6522 Result_Definition => New_Occurrence_Of (RAS_Type, Loc));
6523
6524 Discard_Node (
6525 Make_Subprogram_Body (Loc,
6526 Specification => Func_Spec,
6527 Declarations => No_List,
6528 Handled_Statement_Sequence =>
6529 Make_Handled_Sequence_Of_Statements (Loc,
6530 Statements => Statements)));
6531 Set_TSS (RAS_Type, Fnam);
6532 end Add_RAS_From_Any;
6533
6534 --------------------
6535 -- Add_RAS_To_Any --
6536 --------------------
6537
6538 procedure Add_RAS_To_Any (RAS_Type : Entity_Id) is
6539 Loc : constant Source_Ptr := Sloc (RAS_Type);
6540
6541 Fnam : constant Entity_Id := Make_Defining_Identifier (Loc,
6542 Make_TSS_Name (RAS_Type, TSS_To_Any));
6543
6544 Decls : List_Id;
6545 Statements : List_Id;
6546
6547 Func_Spec : Node_Id;
6548
6549 Any : constant Entity_Id := Make_Temporary (Loc, 'A');
6550 RAS_Parameter : constant Entity_Id := Make_Temporary (Loc, 'R');
6551 RACW_Parameter : constant Node_Id :=
6552 Make_Selected_Component (Loc,
6553 Prefix => RAS_Parameter,
6554 Selector_Name => Name_Ras);
6555
6556 begin
6557 -- Object declarations
6558
6559 Set_Etype (RACW_Parameter, Underlying_RACW_Type (RAS_Type));
6560 Decls := New_List (
6561 Make_Object_Declaration (Loc,
6562 Defining_Identifier => Any,
6563 Object_Definition => New_Occurrence_Of (RTE (RE_Any), Loc),
6564 Expression =>
6565 PolyORB_Support.Helpers.Build_To_Any_Call
6566 (Loc, RACW_Parameter, No_List)));
6567
6568 Statements := New_List (
6569 Make_Procedure_Call_Statement (Loc,
6570 Name => New_Occurrence_Of (RTE (RE_Set_TC), Loc),
6571 Parameter_Associations => New_List (
6572 New_Occurrence_Of (Any, Loc),
6573 PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
6574 RAS_Type, Decls))),
6575
6576 Make_Simple_Return_Statement (Loc,
6577 Expression => New_Occurrence_Of (Any, Loc)));
6578
6579 Func_Spec :=
6580 Make_Function_Specification (Loc,
6581 Defining_Unit_Name => Fnam,
6582 Parameter_Specifications => New_List (
6583 Make_Parameter_Specification (Loc,
6584 Defining_Identifier => RAS_Parameter,
6585 Parameter_Type => New_Occurrence_Of (RAS_Type, Loc))),
6586 Result_Definition => New_Occurrence_Of (RTE (RE_Any), Loc));
6587
6588 Discard_Node (
6589 Make_Subprogram_Body (Loc,
6590 Specification => Func_Spec,
6591 Declarations => Decls,
6592 Handled_Statement_Sequence =>
6593 Make_Handled_Sequence_Of_Statements (Loc,
6594 Statements => Statements)));
6595 Set_TSS (RAS_Type, Fnam);
6596 end Add_RAS_To_Any;
6597
6598 ----------------------
6599 -- Add_RAS_TypeCode --
6600 ----------------------
6601
6602 procedure Add_RAS_TypeCode (RAS_Type : Entity_Id) is
6603 Loc : constant Source_Ptr := Sloc (RAS_Type);
6604
6605 Fnam : constant Entity_Id := Make_Defining_Identifier (Loc,
6606 Make_TSS_Name (RAS_Type, TSS_TypeCode));
6607
6608 Func_Spec : Node_Id;
6609 Decls : constant List_Id := New_List;
6610 Name_String : String_Id;
6611 Repo_Id_String : String_Id;
6612
6613 begin
6614 Func_Spec :=
6615 Make_Function_Specification (Loc,
6616 Defining_Unit_Name => Fnam,
6617 Result_Definition => New_Occurrence_Of (RTE (RE_TypeCode), Loc));
6618
6619 PolyORB_Support.Helpers.Build_Name_And_Repository_Id
6620 (RAS_Type, Name_Str => Name_String, Repo_Id_Str => Repo_Id_String);
6621
6622 Discard_Node (
6623 Make_Subprogram_Body (Loc,
6624 Specification => Func_Spec,
6625 Declarations => Decls,
6626 Handled_Statement_Sequence =>
6627 Make_Handled_Sequence_Of_Statements (Loc,
6628 Statements => New_List (
6629 Make_Simple_Return_Statement (Loc,
6630 Expression =>
6631 Make_Function_Call (Loc,
6632 Name =>
6633 New_Occurrence_Of (RTE (RE_Build_Complex_TC), Loc),
6634 Parameter_Associations => New_List (
6635 New_Occurrence_Of (RTE (RE_Tk_Objref), Loc),
6636 Make_Aggregate (Loc,
6637 Expressions =>
6638 New_List (
6639 Make_Function_Call (Loc,
6640 Name =>
6641 New_Occurrence_Of
6642 (RTE (RE_TA_Std_String), Loc),
6643 Parameter_Associations => New_List (
6644 Make_String_Literal (Loc, Name_String))),
6645 Make_Function_Call (Loc,
6646 Name =>
6647 New_Occurrence_Of
6648 (RTE (RE_TA_Std_String), Loc),
6649 Parameter_Associations => New_List (
6650 Make_String_Literal (Loc,
6651 Strval => Repo_Id_String))))))))))));
6652 Set_TSS (RAS_Type, Fnam);
6653 end Add_RAS_TypeCode;
6654
6655 -----------------------------------------
6656 -- Add_Receiving_Stubs_To_Declarations --
6657 -----------------------------------------
6658
6659 procedure Add_Receiving_Stubs_To_Declarations
6660 (Pkg_Spec : Node_Id;
6661 Decls : List_Id;
6662 Stmts : List_Id)
6663 is
6664 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
6665
6666 Pkg_RPC_Receiver : constant Entity_Id :=
6667 Make_Temporary (Loc, 'H');
6668 Pkg_RPC_Receiver_Object : Node_Id;
6669 Pkg_RPC_Receiver_Body : Node_Id;
6670 Pkg_RPC_Receiver_Decls : List_Id;
6671 Pkg_RPC_Receiver_Statements : List_Id;
6672
6673 Pkg_RPC_Receiver_Cases : constant List_Id := New_List;
6674 -- A Pkg_RPC_Receiver is built to decode the request
6675
6676 Request : Node_Id;
6677 -- Request object received from neutral layer
6678
6679 Subp_Id : Entity_Id;
6680 -- Subprogram identifier as received from the neutral distribution
6681 -- core.
6682
6683 Subp_Index : Entity_Id;
6684 -- Internal index as determined by matching either the method name
6685 -- from the request structure, or the local subprogram address (in
6686 -- case of a RAS).
6687
6688 Is_Local : constant Entity_Id := Make_Temporary (Loc, 'L');
6689
6690 Local_Address : constant Entity_Id := Make_Temporary (Loc, 'A');
6691 -- Address of a local subprogram designated by a reference
6692 -- corresponding to a RAS.
6693
6694 Dispatch_On_Address : constant List_Id := New_List;
6695 Dispatch_On_Name : constant List_Id := New_List;
6696
6697 Current_Subp_Number : Int := First_RCI_Subprogram_Id;
6698
6699 Subp_Info_Array : constant Entity_Id := Make_Temporary (Loc, 'I');
6700 Subp_Info_List : constant List_Id := New_List;
6701
6702 Register_Pkg_Actuals : constant List_Id := New_List;
6703
6704 All_Calls_Remote_E : Entity_Id;
6705
6706 procedure Append_Stubs_To
6707 (RPC_Receiver_Cases : List_Id;
6708 Declaration : Node_Id;
6709 Stubs : Node_Id;
6710 Subp_Number : Int;
6711 Subp_Dist_Name : Entity_Id;
6712 Subp_Proxy_Addr : Entity_Id);
6713 -- Add one case to the specified RPC receiver case list associating
6714 -- Subprogram_Number with the subprogram declared by Declaration, for
6715 -- which we have receiving stubs in Stubs. Subp_Number is an internal
6716 -- subprogram index. Subp_Dist_Name is the string used to call the
6717 -- subprogram by name, and Subp_Dist_Addr is the address of the proxy
6718 -- object, used in the context of calls through remote
6719 -- access-to-subprogram types.
6720
6721 procedure Visit_Subprogram (Decl : Node_Id);
6722 -- Generate receiving stub for one remote subprogram
6723
6724 ---------------------
6725 -- Append_Stubs_To --
6726 ---------------------
6727
6728 procedure Append_Stubs_To
6729 (RPC_Receiver_Cases : List_Id;
6730 Declaration : Node_Id;
6731 Stubs : Node_Id;
6732 Subp_Number : Int;
6733 Subp_Dist_Name : Entity_Id;
6734 Subp_Proxy_Addr : Entity_Id)
6735 is
6736 Case_Stmts : List_Id;
6737 begin
6738 Case_Stmts := New_List (
6739 Make_Procedure_Call_Statement (Loc,
6740 Name =>
6741 New_Occurrence_Of (
6742 Defining_Entity (Stubs), Loc),
6743 Parameter_Associations =>
6744 New_List (New_Occurrence_Of (Request, Loc))));
6745
6746 if Nkind (Specification (Declaration)) = N_Function_Specification
6747 or else not
6748 Is_Asynchronous (Defining_Entity (Specification (Declaration)))
6749 then
6750 Append_To (Case_Stmts, Make_Simple_Return_Statement (Loc));
6751 end if;
6752
6753 Append_To (RPC_Receiver_Cases,
6754 Make_Case_Statement_Alternative (Loc,
6755 Discrete_Choices =>
6756 New_List (Make_Integer_Literal (Loc, Subp_Number)),
6757 Statements => Case_Stmts));
6758
6759 Append_To (Dispatch_On_Name,
6760 Make_Elsif_Part (Loc,
6761 Condition =>
6762 Make_Function_Call (Loc,
6763 Name =>
6764 New_Occurrence_Of (RTE (RE_Caseless_String_Eq), Loc),
6765 Parameter_Associations => New_List (
6766 New_Occurrence_Of (Subp_Id, Loc),
6767 New_Occurrence_Of (Subp_Dist_Name, Loc))),
6768
6769 Then_Statements => New_List (
6770 Make_Assignment_Statement (Loc,
6771 New_Occurrence_Of (Subp_Index, Loc),
6772 Make_Integer_Literal (Loc, Subp_Number)))));
6773
6774 Append_To (Dispatch_On_Address,
6775 Make_Elsif_Part (Loc,
6776 Condition =>
6777 Make_Op_Eq (Loc,
6778 Left_Opnd => New_Occurrence_Of (Local_Address, Loc),
6779 Right_Opnd => New_Occurrence_Of (Subp_Proxy_Addr, Loc)),
6780
6781 Then_Statements => New_List (
6782 Make_Assignment_Statement (Loc,
6783 New_Occurrence_Of (Subp_Index, Loc),
6784 Make_Integer_Literal (Loc, Subp_Number)))));
6785 end Append_Stubs_To;
6786
6787 ----------------------
6788 -- Visit_Subprogram --
6789 ----------------------
6790
6791 procedure Visit_Subprogram (Decl : Node_Id) is
6792 Loc : constant Source_Ptr := Sloc (Decl);
6793 Spec : constant Node_Id := Specification (Decl);
6794 Subp_Def : constant Entity_Id := Defining_Unit_Name (Spec);
6795
6796 Subp_Val : String_Id;
6797
6798 Subp_Dist_Name : constant Entity_Id :=
6799 Make_Defining_Identifier (Loc,
6800 Chars =>
6801 New_External_Name
6802 (Related_Id => Chars (Subp_Def),
6803 Suffix => 'D',
6804 Suffix_Index => -1));
6805
6806 Current_Stubs : Node_Id;
6807 Proxy_Obj_Addr : Entity_Id;
6808
6809 begin
6810 -- Disable expansion of stubs if serious errors have been
6811 -- diagnosed, because otherwise some illegal remote subprogram
6812 -- declarations could cause cascaded errors in stubs.
6813
6814 if Serious_Errors_Detected /= 0 then
6815 return;
6816 end if;
6817
6818 -- Build receiving stub
6819
6820 Current_Stubs :=
6821 Build_Subprogram_Receiving_Stubs
6822 (Vis_Decl => Decl,
6823 Asynchronous => Nkind (Spec) = N_Procedure_Specification
6824 and then Is_Asynchronous (Subp_Def));
6825
6826 Append_To (Decls, Current_Stubs);
6827 Analyze (Current_Stubs);
6828
6829 -- Build RAS proxy
6830
6831 Add_RAS_Proxy_And_Analyze (Decls,
6832 Vis_Decl => Decl,
6833 All_Calls_Remote_E => All_Calls_Remote_E,
6834 Proxy_Object_Addr => Proxy_Obj_Addr);
6835
6836 -- Compute distribution identifier
6837
6838 Assign_Subprogram_Identifier
6839 (Subp_Def, Current_Subp_Number, Subp_Val);
6840
6841 pragma Assert
6842 (Current_Subp_Number = Get_Subprogram_Id (Subp_Def));
6843
6844 Append_To (Decls,
6845 Make_Object_Declaration (Loc,
6846 Defining_Identifier => Subp_Dist_Name,
6847 Constant_Present => True,
6848 Object_Definition =>
6849 New_Occurrence_Of (Standard_String, Loc),
6850 Expression =>
6851 Make_String_Literal (Loc, Subp_Val)));
6852 Analyze (Last (Decls));
6853
6854 -- Add subprogram descriptor (RCI_Subp_Info) to the subprograms
6855 -- table for this receiver. The aggregate below must be kept
6856 -- consistent with the declaration of RCI_Subp_Info in
6857 -- System.Partition_Interface.
6858
6859 Append_To (Subp_Info_List,
6860 Make_Component_Association (Loc,
6861 Choices =>
6862 New_List (Make_Integer_Literal (Loc, Current_Subp_Number)),
6863
6864 Expression =>
6865 Make_Aggregate (Loc,
6866 Expressions => New_List (
6867
6868 -- Name =>
6869
6870 Make_Attribute_Reference (Loc,
6871 Prefix =>
6872 New_Occurrence_Of (Subp_Dist_Name, Loc),
6873 Attribute_Name => Name_Address),
6874
6875 -- Name_Length =>
6876
6877 Make_Attribute_Reference (Loc,
6878 Prefix =>
6879 New_Occurrence_Of (Subp_Dist_Name, Loc),
6880 Attribute_Name => Name_Length),
6881
6882 -- Addr =>
6883
6884 New_Occurrence_Of (Proxy_Obj_Addr, Loc)))));
6885
6886 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
6887 Declaration => Decl,
6888 Stubs => Current_Stubs,
6889 Subp_Number => Current_Subp_Number,
6890 Subp_Dist_Name => Subp_Dist_Name,
6891 Subp_Proxy_Addr => Proxy_Obj_Addr);
6892
6893 Current_Subp_Number := Current_Subp_Number + 1;
6894 end Visit_Subprogram;
6895
6896 procedure Visit_Spec is new Build_Package_Stubs (Visit_Subprogram);
6897
6898 -- Start of processing for Add_Receiving_Stubs_To_Declarations
6899
6900 begin
6901 -- Building receiving stubs consist in several operations:
6902
6903 -- - a package RPC receiver must be built. This subprogram will get
6904 -- a Subprogram_Id from the incoming stream and will dispatch the
6905 -- call to the right subprogram;
6906
6907 -- - a receiving stub for each subprogram visible in the package
6908 -- spec. This stub will read all the parameters from the stream,
6909 -- and put the result as well as the exception occurrence in the
6910 -- output stream;
6911
6912 Build_RPC_Receiver_Body (
6913 RPC_Receiver => Pkg_RPC_Receiver,
6914 Request => Request,
6915 Subp_Id => Subp_Id,
6916 Subp_Index => Subp_Index,
6917 Stmts => Pkg_RPC_Receiver_Statements,
6918 Decl => Pkg_RPC_Receiver_Body);
6919 Pkg_RPC_Receiver_Decls := Declarations (Pkg_RPC_Receiver_Body);
6920
6921 -- Extract local address information from the target reference:
6922 -- if non-null, that means that this is a reference that denotes
6923 -- one particular operation, and hence that the operation name
6924 -- must not be taken into account for dispatching.
6925
6926 Append_To (Pkg_RPC_Receiver_Decls,
6927 Make_Object_Declaration (Loc,
6928 Defining_Identifier => Is_Local,
6929 Object_Definition =>
6930 New_Occurrence_Of (Standard_Boolean, Loc)));
6931
6932 Append_To (Pkg_RPC_Receiver_Decls,
6933 Make_Object_Declaration (Loc,
6934 Defining_Identifier => Local_Address,
6935 Object_Definition =>
6936 New_Occurrence_Of (RTE (RE_Address), Loc)));
6937
6938 Append_To (Pkg_RPC_Receiver_Statements,
6939 Make_Procedure_Call_Statement (Loc,
6940 Name => New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
6941 Parameter_Associations => New_List (
6942 Make_Selected_Component (Loc,
6943 Prefix => Request,
6944 Selector_Name => Name_Target),
6945 New_Occurrence_Of (Is_Local, Loc),
6946 New_Occurrence_Of (Local_Address, Loc))));
6947
6948 -- For each subprogram, the receiving stub will be built and a case
6949 -- statement will be made on the Subprogram_Id to dispatch to the
6950 -- right subprogram.
6951
6952 All_Calls_Remote_E := Boolean_Literals (
6953 Has_All_Calls_Remote (Defining_Entity (Pkg_Spec)));
6954
6955 Overload_Counter_Table.Reset;
6956 Reserve_NamingContext_Methods;
6957
6958 Visit_Spec (Pkg_Spec);
6959
6960 Append_To (Decls,
6961 Make_Object_Declaration (Loc,
6962 Defining_Identifier => Subp_Info_Array,
6963 Constant_Present => True,
6964 Aliased_Present => True,
6965 Object_Definition =>
6966 Make_Subtype_Indication (Loc,
6967 Subtype_Mark =>
6968 New_Occurrence_Of (RTE (RE_RCI_Subp_Info_Array), Loc),
6969 Constraint =>
6970 Make_Index_Or_Discriminant_Constraint (Loc,
6971 New_List (
6972 Make_Range (Loc,
6973 Low_Bound =>
6974 Make_Integer_Literal (Loc,
6975 Intval => First_RCI_Subprogram_Id),
6976 High_Bound =>
6977 Make_Integer_Literal (Loc,
6978 Intval =>
6979 First_RCI_Subprogram_Id
6980 + List_Length (Subp_Info_List) - 1)))))));
6981
6982 if Present (First (Subp_Info_List)) then
6983 Set_Expression (Last (Decls),
6984 Make_Aggregate (Loc,
6985 Component_Associations => Subp_Info_List));
6986
6987 -- Generate the dispatch statement to determine the subprogram id
6988 -- of the called subprogram.
6989
6990 -- We first test whether the reference that was used to make the
6991 -- call was the base RCI reference (in which case Local_Address is
6992 -- zero, and the method identifier from the request must be used
6993 -- to determine which subprogram is called) or a reference
6994 -- identifying one particular subprogram (in which case
6995 -- Local_Address is the address of that subprogram, and the
6996 -- method name from the request is ignored). The latter occurs
6997 -- for the case of a call through a remote access-to-subprogram.
6998
6999 -- In each case, cascaded elsifs are used to determine the proper
7000 -- subprogram index. Using hash tables might be more efficient.
7001
7002 Append_To (Pkg_RPC_Receiver_Statements,
7003 Make_Implicit_If_Statement (Pkg_Spec,
7004 Condition =>
7005 Make_Op_Ne (Loc,
7006 Left_Opnd => New_Occurrence_Of (Local_Address, Loc),
7007 Right_Opnd => New_Occurrence_Of
7008 (RTE (RE_Null_Address), Loc)),
7009
7010 Then_Statements => New_List (
7011 Make_Implicit_If_Statement (Pkg_Spec,
7012 Condition => New_Occurrence_Of (Standard_False, Loc),
7013 Then_Statements => New_List (
7014 Make_Null_Statement (Loc)),
7015 Elsif_Parts => Dispatch_On_Address)),
7016
7017 Else_Statements => New_List (
7018 Make_Implicit_If_Statement (Pkg_Spec,
7019 Condition => New_Occurrence_Of (Standard_False, Loc),
7020 Then_Statements => New_List (Make_Null_Statement (Loc)),
7021 Elsif_Parts => Dispatch_On_Name))));
7022
7023 else
7024 -- For a degenerate RCI with no visible subprograms,
7025 -- Subp_Info_List has zero length, and the declaration is for an
7026 -- empty array, in which case no initialization aggregate must be
7027 -- generated. We do not generate a Dispatch_Statement either.
7028
7029 -- No initialization provided: remove CONSTANT so that the
7030 -- declaration is not an incomplete deferred constant.
7031
7032 Set_Constant_Present (Last (Decls), False);
7033 end if;
7034
7035 -- Analyze Subp_Info_Array declaration
7036
7037 Analyze (Last (Decls));
7038
7039 -- If we receive an invalid Subprogram_Id, it is best to do nothing
7040 -- rather than raising an exception since we do not want someone
7041 -- to crash a remote partition by sending invalid subprogram ids.
7042 -- This is consistent with the other parts of the case statement
7043 -- since even in presence of incorrect parameters in the stream,
7044 -- every exception will be caught and (if the subprogram is not an
7045 -- APC) put into the result stream and sent away.
7046
7047 Append_To (Pkg_RPC_Receiver_Cases,
7048 Make_Case_Statement_Alternative (Loc,
7049 Discrete_Choices => New_List (Make_Others_Choice (Loc)),
7050 Statements => New_List (Make_Null_Statement (Loc))));
7051
7052 Append_To (Pkg_RPC_Receiver_Statements,
7053 Make_Case_Statement (Loc,
7054 Expression => New_Occurrence_Of (Subp_Index, Loc),
7055 Alternatives => Pkg_RPC_Receiver_Cases));
7056
7057 -- Pkg_RPC_Receiver body is now complete: insert it into the tree and
7058 -- analyze it.
7059
7060 Append_To (Decls, Pkg_RPC_Receiver_Body);
7061 Analyze (Last (Decls));
7062
7063 Pkg_RPC_Receiver_Object :=
7064 Make_Object_Declaration (Loc,
7065 Defining_Identifier => Make_Temporary (Loc, 'R'),
7066 Aliased_Present => True,
7067 Object_Definition => New_Occurrence_Of (RTE (RE_Servant), Loc));
7068 Append_To (Decls, Pkg_RPC_Receiver_Object);
7069 Analyze (Last (Decls));
7070
7071 -- Name
7072
7073 Append_To (Register_Pkg_Actuals,
7074 Make_String_Literal (Loc,
7075 Strval =>
7076 Fully_Qualified_Name_String
7077 (Defining_Entity (Pkg_Spec), Append_NUL => False)));
7078
7079 -- Version
7080
7081 Append_To (Register_Pkg_Actuals,
7082 Make_Attribute_Reference (Loc,
7083 Prefix =>
7084 New_Occurrence_Of
7085 (Defining_Entity (Pkg_Spec), Loc),
7086 Attribute_Name => Name_Version));
7087
7088 -- Handler
7089
7090 Append_To (Register_Pkg_Actuals,
7091 Make_Attribute_Reference (Loc,
7092 Prefix =>
7093 New_Occurrence_Of (Pkg_RPC_Receiver, Loc),
7094 Attribute_Name => Name_Access));
7095
7096 -- Receiver
7097
7098 Append_To (Register_Pkg_Actuals,
7099 Make_Attribute_Reference (Loc,
7100 Prefix =>
7101 New_Occurrence_Of (
7102 Defining_Identifier (Pkg_RPC_Receiver_Object), Loc),
7103 Attribute_Name => Name_Access));
7104
7105 -- Subp_Info
7106
7107 Append_To (Register_Pkg_Actuals,
7108 Make_Attribute_Reference (Loc,
7109 Prefix => New_Occurrence_Of (Subp_Info_Array, Loc),
7110 Attribute_Name => Name_Address));
7111
7112 -- Subp_Info_Len
7113
7114 Append_To (Register_Pkg_Actuals,
7115 Make_Attribute_Reference (Loc,
7116 Prefix => New_Occurrence_Of (Subp_Info_Array, Loc),
7117 Attribute_Name => Name_Length));
7118
7119 -- Is_All_Calls_Remote
7120
7121 Append_To (Register_Pkg_Actuals,
7122 New_Occurrence_Of (All_Calls_Remote_E, Loc));
7123
7124 -- Finally call Register_Pkg_Receiving_Stub with the above parameters
7125
7126 Append_To (Stmts,
7127 Make_Procedure_Call_Statement (Loc,
7128 Name =>
7129 New_Occurrence_Of (RTE (RE_Register_Pkg_Receiving_Stub), Loc),
7130 Parameter_Associations => Register_Pkg_Actuals));
7131 Analyze (Last (Stmts));
7132 end Add_Receiving_Stubs_To_Declarations;
7133
7134 ---------------------------------
7135 -- Build_General_Calling_Stubs --
7136 ---------------------------------
7137
7138 procedure Build_General_Calling_Stubs
7139 (Decls : List_Id;
7140 Statements : List_Id;
7141 Target_Object : Node_Id;
7142 Subprogram_Id : Node_Id;
7143 Asynchronous : Node_Id := Empty;
7144 Is_Known_Asynchronous : Boolean := False;
7145 Is_Known_Non_Asynchronous : Boolean := False;
7146 Is_Function : Boolean;
7147 Spec : Node_Id;
7148 Stub_Type : Entity_Id := Empty;
7149 RACW_Type : Entity_Id := Empty;
7150 Nod : Node_Id)
7151 is
7152 Loc : constant Source_Ptr := Sloc (Nod);
7153
7154 Request : constant Entity_Id := Make_Temporary (Loc, 'R');
7155 -- The request object constructed by these stubs
7156 -- Could we use Name_R instead??? (see GLADE client stubs)
7157
7158 function Make_Request_RTE_Call
7159 (RE : RE_Id;
7160 Actuals : List_Id := New_List) return Node_Id;
7161 -- Generate a procedure call statement calling RE with the given
7162 -- actuals. Request'Access is appended to the list.
7163
7164 ---------------------------
7165 -- Make_Request_RTE_Call --
7166 ---------------------------
7167
7168 function Make_Request_RTE_Call
7169 (RE : RE_Id;
7170 Actuals : List_Id := New_List) return Node_Id
7171 is
7172 begin
7173 Append_To (Actuals,
7174 Make_Attribute_Reference (Loc,
7175 Prefix => New_Occurrence_Of (Request, Loc),
7176 Attribute_Name => Name_Access));
7177 return Make_Procedure_Call_Statement (Loc,
7178 Name =>
7179 New_Occurrence_Of (RTE (RE), Loc),
7180 Parameter_Associations => Actuals);
7181 end Make_Request_RTE_Call;
7182
7183 Arguments : Node_Id;
7184 -- Name of the named values list used to transmit parameters
7185 -- to the remote package
7186
7187 Result : Node_Id;
7188 -- Name of the result named value (in non-APC cases) which get the
7189 -- result of the remote subprogram.
7190
7191 Result_TC : Node_Id;
7192 -- Typecode expression for the result of the request (void
7193 -- typecode for procedures).
7194
7195 Exception_Return_Parameter : Node_Id;
7196 -- Name of the parameter which will hold the exception sent by the
7197 -- remote subprogram.
7198
7199 Current_Parameter : Node_Id;
7200 -- Current parameter being handled
7201
7202 Ordered_Parameters_List : constant List_Id :=
7203 Build_Ordered_Parameters_List (Spec);
7204
7205 Asynchronous_P : Node_Id;
7206 -- A Boolean expression indicating whether this call is asynchronous
7207
7208 Asynchronous_Statements : List_Id := No_List;
7209 Non_Asynchronous_Statements : List_Id := No_List;
7210 -- Statements specifics to the Asynchronous/Non-Asynchronous cases
7211
7212 Extra_Formal_Statements : constant List_Id := New_List;
7213 -- List of statements for extra formal parameters. It will appear
7214 -- after the regular statements for writing out parameters.
7215
7216 After_Statements : constant List_Id := New_List;
7217 -- Statements to be executed after call returns (to assign IN OUT or
7218 -- OUT parameter values).
7219
7220 Etyp : Entity_Id;
7221 -- The type of the formal parameter being processed
7222
7223 Is_Controlling_Formal : Boolean;
7224 Is_First_Controlling_Formal : Boolean;
7225 First_Controlling_Formal_Seen : Boolean := False;
7226 -- Controlling formal parameters of distributed object primitives
7227 -- require special handling, and the first such parameter needs even
7228 -- more special handling.
7229
7230 begin
7231 -- ??? document general form of stub subprograms for the PolyORB case
7232
7233 Append_To (Decls,
7234 Make_Object_Declaration (Loc,
7235 Defining_Identifier => Request,
7236 Aliased_Present => True,
7237 Object_Definition =>
7238 New_Occurrence_Of (RTE (RE_Request), Loc)));
7239
7240 Result := Make_Temporary (Loc, 'R');
7241
7242 if Is_Function then
7243 Result_TC :=
7244 PolyORB_Support.Helpers.Build_TypeCode_Call
7245 (Loc, Etype (Result_Definition (Spec)), Decls);
7246 else
7247 Result_TC := New_Occurrence_Of (RTE (RE_TC_Void), Loc);
7248 end if;
7249
7250 Append_To (Decls,
7251 Make_Object_Declaration (Loc,
7252 Defining_Identifier => Result,
7253 Object_Definition =>
7254 New_Occurrence_Of (RTE (RE_NamedValue), Loc),
7255 Expression =>
7256 Make_Aggregate (Loc,
7257 Component_Associations => New_List (
7258 Make_Component_Association (Loc,
7259 Choices => New_List (Make_Identifier (Loc, Name_Name)),
7260 Expression =>
7261 New_Occurrence_Of (RTE (RE_Result_Name), Loc)),
7262 Make_Component_Association (Loc,
7263 Choices => New_List (
7264 Make_Identifier (Loc, Name_Argument)),
7265 Expression =>
7266 Make_Function_Call (Loc,
7267 Name => New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7268 Parameter_Associations => New_List (Result_TC))),
7269 Make_Component_Association (Loc,
7270 Choices => New_List (
7271 Make_Identifier (Loc, Name_Arg_Modes)),
7272 Expression => Make_Integer_Literal (Loc, 0))))));
7273
7274 if not Is_Known_Asynchronous then
7275 Exception_Return_Parameter := Make_Temporary (Loc, 'E');
7276
7277 Append_To (Decls,
7278 Make_Object_Declaration (Loc,
7279 Defining_Identifier => Exception_Return_Parameter,
7280 Object_Definition =>
7281 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc)));
7282
7283 else
7284 Exception_Return_Parameter := Empty;
7285 end if;
7286
7287 -- Initialize and fill in arguments list
7288
7289 Arguments := Make_Temporary (Loc, 'A');
7290 Declare_Create_NVList (Loc, Arguments, Decls, Statements);
7291
7292 Current_Parameter := First (Ordered_Parameters_List);
7293 while Present (Current_Parameter) loop
7294 if Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type) then
7295 Is_Controlling_Formal := True;
7296 Is_First_Controlling_Formal :=
7297 not First_Controlling_Formal_Seen;
7298 First_Controlling_Formal_Seen := True;
7299
7300 else
7301 Is_Controlling_Formal := False;
7302 Is_First_Controlling_Formal := False;
7303 end if;
7304
7305 if Is_Controlling_Formal then
7306
7307 -- For a controlling formal argument, we send its reference
7308
7309 Etyp := RACW_Type;
7310
7311 else
7312 Etyp := Etype (Parameter_Type (Current_Parameter));
7313 end if;
7314
7315 -- The first controlling formal parameter is treated specially:
7316 -- it is used to set the target object of the call.
7317
7318 if not Is_First_Controlling_Formal then
7319 declare
7320 Constrained : constant Boolean :=
7321 Is_Constrained (Etyp)
7322 or else Is_Elementary_Type (Etyp);
7323
7324 Any : constant Entity_Id := Make_Temporary (Loc, 'A');
7325
7326 Actual_Parameter : Node_Id :=
7327 New_Occurrence_Of (
7328 Defining_Identifier (
7329 Current_Parameter), Loc);
7330
7331 Expr : Node_Id;
7332
7333 begin
7334 if Is_Controlling_Formal then
7335
7336 -- For a controlling formal parameter (other than the
7337 -- first one), use the corresponding RACW. If the
7338 -- parameter is not an anonymous access parameter, that
7339 -- involves taking its 'Unrestricted_Access.
7340
7341 if Nkind (Parameter_Type (Current_Parameter))
7342 = N_Access_Definition
7343 then
7344 Actual_Parameter := OK_Convert_To
7345 (Etyp, Actual_Parameter);
7346 else
7347 Actual_Parameter := OK_Convert_To (Etyp,
7348 Make_Attribute_Reference (Loc,
7349 Prefix => Actual_Parameter,
7350 Attribute_Name => Name_Unrestricted_Access));
7351 end if;
7352
7353 end if;
7354
7355 if In_Present (Current_Parameter)
7356 or else not Out_Present (Current_Parameter)
7357 or else not Constrained
7358 or else Is_Controlling_Formal
7359 then
7360 -- The parameter has an input value, is constrained at
7361 -- runtime by an input value, or is a controlling formal
7362 -- parameter (always passed as a reference) other than
7363 -- the first one.
7364
7365 Expr := PolyORB_Support.Helpers.Build_To_Any_Call
7366 (Loc, Actual_Parameter, Decls);
7367
7368 else
7369 Expr := Make_Function_Call (Loc,
7370 Name => New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7371 Parameter_Associations => New_List (
7372 PolyORB_Support.Helpers.Build_TypeCode_Call
7373 (Loc, Etyp, Decls)));
7374 end if;
7375
7376 Append_To (Decls,
7377 Make_Object_Declaration (Loc,
7378 Defining_Identifier => Any,
7379 Object_Definition =>
7380 New_Occurrence_Of (RTE (RE_Any), Loc),
7381 Expression => Expr));
7382
7383 Append_To (Statements,
7384 Add_Parameter_To_NVList (Loc,
7385 Parameter => Current_Parameter,
7386 NVList => Arguments,
7387 Constrained => Constrained,
7388 Any => Any));
7389
7390 if Out_Present (Current_Parameter)
7391 and then not Is_Controlling_Formal
7392 then
7393 if Is_Limited_Type (Etyp) then
7394 Helpers.Assign_Opaque_From_Any (Loc,
7395 Stms => After_Statements,
7396 Typ => Etyp,
7397 N => New_Occurrence_Of (Any, Loc),
7398 Target =>
7399 Defining_Identifier (Current_Parameter),
7400 Constrained => True);
7401
7402 else
7403 Append_To (After_Statements,
7404 Make_Assignment_Statement (Loc,
7405 Name =>
7406 New_Occurrence_Of (
7407 Defining_Identifier (Current_Parameter), Loc),
7408 Expression =>
7409 PolyORB_Support.Helpers.Build_From_Any_Call
7410 (Etyp,
7411 New_Occurrence_Of (Any, Loc),
7412 Decls)));
7413 end if;
7414 end if;
7415 end;
7416 end if;
7417
7418 -- If the current parameter has a dynamic constrained status, then
7419 -- this status is transmitted as well.
7420
7421 -- This should be done for accessibility as well ???
7422
7423 if Nkind (Parameter_Type (Current_Parameter)) /=
7424 N_Access_Definition
7425 and then Need_Extra_Constrained (Current_Parameter)
7426 then
7427 -- In this block, we do not use the extra formal that has been
7428 -- created because it does not exist at the time of expansion
7429 -- when building calling stubs for remote access to subprogram
7430 -- types. We create an extra variable of this type and push it
7431 -- in the stream after the regular parameters.
7432
7433 declare
7434 Extra_Any_Parameter : constant Entity_Id :=
7435 Make_Temporary (Loc, 'P');
7436
7437 Parameter_Exp : constant Node_Id :=
7438 Make_Attribute_Reference (Loc,
7439 Prefix => New_Occurrence_Of (
7440 Defining_Identifier (Current_Parameter), Loc),
7441 Attribute_Name => Name_Constrained);
7442
7443 begin
7444 Set_Etype (Parameter_Exp, Etype (Standard_Boolean));
7445
7446 Append_To (Decls,
7447 Make_Object_Declaration (Loc,
7448 Defining_Identifier => Extra_Any_Parameter,
7449 Object_Definition =>
7450 New_Occurrence_Of (RTE (RE_Any), Loc),
7451 Expression =>
7452 PolyORB_Support.Helpers.Build_To_Any_Call
7453 (Loc, Parameter_Exp, Decls)));
7454
7455 Append_To (Extra_Formal_Statements,
7456 Add_Parameter_To_NVList (Loc,
7457 Parameter => Extra_Any_Parameter,
7458 NVList => Arguments,
7459 Constrained => True,
7460 Any => Extra_Any_Parameter));
7461 end;
7462 end if;
7463
7464 Next (Current_Parameter);
7465 end loop;
7466
7467 -- Append the formal statements list to the statements
7468
7469 Append_List_To (Statements, Extra_Formal_Statements);
7470
7471 Append_To (Statements,
7472 Make_Procedure_Call_Statement (Loc,
7473 Name =>
7474 New_Occurrence_Of (RTE (RE_Request_Setup), Loc),
7475 Parameter_Associations => New_List (
7476 New_Occurrence_Of (Request, Loc),
7477 Target_Object,
7478 Subprogram_Id,
7479 New_Occurrence_Of (Arguments, Loc),
7480 New_Occurrence_Of (Result, Loc),
7481 New_Occurrence_Of (RTE (RE_Nil_Exc_List), Loc))));
7482
7483 pragma Assert
7484 (not (Is_Known_Non_Asynchronous and Is_Known_Asynchronous));
7485
7486 if Is_Known_Non_Asynchronous or Is_Known_Asynchronous then
7487 Asynchronous_P :=
7488 New_Occurrence_Of
7489 (Boolean_Literals (Is_Known_Asynchronous), Loc);
7490
7491 else
7492 pragma Assert (Present (Asynchronous));
7493 Asynchronous_P := New_Copy_Tree (Asynchronous);
7494
7495 -- The expression node Asynchronous will be used to build an 'if'
7496 -- statement at the end of Build_General_Calling_Stubs: we need to
7497 -- make a copy here.
7498 end if;
7499
7500 Append_To (Parameter_Associations (Last (Statements)),
7501 Make_Indexed_Component (Loc,
7502 Prefix =>
7503 New_Occurrence_Of (
7504 RTE (RE_Asynchronous_P_To_Sync_Scope), Loc),
7505 Expressions => New_List (Asynchronous_P)));
7506
7507 Append_To (Statements, Make_Request_RTE_Call (RE_Request_Invoke));
7508
7509 -- Asynchronous case
7510
7511 if not Is_Known_Non_Asynchronous then
7512 Asynchronous_Statements := New_List (Make_Null_Statement (Loc));
7513 end if;
7514
7515 -- Non-asynchronous case
7516
7517 if not Is_Known_Asynchronous then
7518 -- Reraise an exception occurrence from the completed request.
7519 -- If the exception occurrence is empty, this is a no-op.
7520
7521 Non_Asynchronous_Statements := New_List (
7522 Make_Procedure_Call_Statement (Loc,
7523 Name =>
7524 New_Occurrence_Of (RTE (RE_Request_Raise_Occurrence), Loc),
7525 Parameter_Associations => New_List (
7526 New_Occurrence_Of (Request, Loc))));
7527
7528 if Is_Function then
7529 -- If this is a function call, read the value and return it
7530
7531 Append_To (Non_Asynchronous_Statements,
7532 Make_Tag_Check (Loc,
7533 Make_Simple_Return_Statement (Loc,
7534 PolyORB_Support.Helpers.Build_From_Any_Call
7535 (Etype (Result_Definition (Spec)),
7536 Make_Selected_Component (Loc,
7537 Prefix => Result,
7538 Selector_Name => Name_Argument),
7539 Decls))));
7540
7541 else
7542
7543 -- Case of a procedure: deal with IN OUT and OUT formals
7544
7545 Append_List_To (Non_Asynchronous_Statements, After_Statements);
7546 end if;
7547 end if;
7548
7549 if Is_Known_Asynchronous then
7550 Append_List_To (Statements, Asynchronous_Statements);
7551
7552 elsif Is_Known_Non_Asynchronous then
7553 Append_List_To (Statements, Non_Asynchronous_Statements);
7554
7555 else
7556 pragma Assert (Present (Asynchronous));
7557 Append_To (Statements,
7558 Make_Implicit_If_Statement (Nod,
7559 Condition => Asynchronous,
7560 Then_Statements => Asynchronous_Statements,
7561 Else_Statements => Non_Asynchronous_Statements));
7562 end if;
7563 end Build_General_Calling_Stubs;
7564
7565 -----------------------
7566 -- Build_Stub_Target --
7567 -----------------------
7568
7569 function Build_Stub_Target
7570 (Loc : Source_Ptr;
7571 Decls : List_Id;
7572 RCI_Locator : Entity_Id;
7573 Controlling_Parameter : Entity_Id) return RPC_Target
7574 is
7575 Target_Info : RPC_Target (PCS_Kind => Name_PolyORB_DSA);
7576 Target_Reference : constant Entity_Id := Make_Temporary (Loc, 'T');
7577
7578 begin
7579 if Present (Controlling_Parameter) then
7580 Append_To (Decls,
7581 Make_Object_Declaration (Loc,
7582 Defining_Identifier => Target_Reference,
7583
7584 Object_Definition =>
7585 New_Occurrence_Of (RTE (RE_Object_Ref), Loc),
7586
7587 Expression =>
7588 Make_Function_Call (Loc,
7589 Name =>
7590 New_Occurrence_Of (RTE (RE_Make_Ref), Loc),
7591 Parameter_Associations => New_List (
7592 Make_Selected_Component (Loc,
7593 Prefix => Controlling_Parameter,
7594 Selector_Name => Name_Target)))));
7595
7596 -- Note: Controlling_Parameter has the same components as
7597 -- System.Partition_Interface.RACW_Stub_Type.
7598
7599 Target_Info.Object := New_Occurrence_Of (Target_Reference, Loc);
7600
7601 else
7602 Target_Info.Object :=
7603 Make_Selected_Component (Loc,
7604 Prefix =>
7605 Make_Identifier (Loc, Chars (RCI_Locator)),
7606 Selector_Name =>
7607 Make_Identifier (Loc, Name_Get_RCI_Package_Ref));
7608 end if;
7609
7610 return Target_Info;
7611 end Build_Stub_Target;
7612
7613 -----------------------------
7614 -- Build_RPC_Receiver_Body --
7615 -----------------------------
7616
7617 procedure Build_RPC_Receiver_Body
7618 (RPC_Receiver : Entity_Id;
7619 Request : out Entity_Id;
7620 Subp_Id : out Entity_Id;
7621 Subp_Index : out Entity_Id;
7622 Stmts : out List_Id;
7623 Decl : out Node_Id)
7624 is
7625 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
7626
7627 RPC_Receiver_Spec : Node_Id;
7628 RPC_Receiver_Decls : List_Id;
7629
7630 begin
7631 Request := Make_Defining_Identifier (Loc, Name_R);
7632
7633 RPC_Receiver_Spec :=
7634 Build_RPC_Receiver_Specification
7635 (RPC_Receiver => RPC_Receiver,
7636 Request_Parameter => Request);
7637
7638 Subp_Id := Make_Defining_Identifier (Loc, Name_P);
7639 Subp_Index := Make_Defining_Identifier (Loc, Name_I);
7640
7641 RPC_Receiver_Decls := New_List (
7642 Make_Object_Renaming_Declaration (Loc,
7643 Defining_Identifier => Subp_Id,
7644 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
7645 Name =>
7646 Make_Explicit_Dereference (Loc,
7647 Prefix =>
7648 Make_Selected_Component (Loc,
7649 Prefix => Request,
7650 Selector_Name => Name_Operation))),
7651
7652 Make_Object_Declaration (Loc,
7653 Defining_Identifier => Subp_Index,
7654 Object_Definition =>
7655 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
7656 Expression =>
7657 Make_Attribute_Reference (Loc,
7658 Prefix =>
7659 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
7660 Attribute_Name => Name_Last)));
7661
7662 Stmts := New_List;
7663
7664 Decl :=
7665 Make_Subprogram_Body (Loc,
7666 Specification => RPC_Receiver_Spec,
7667 Declarations => RPC_Receiver_Decls,
7668 Handled_Statement_Sequence =>
7669 Make_Handled_Sequence_Of_Statements (Loc,
7670 Statements => Stmts));
7671 end Build_RPC_Receiver_Body;
7672
7673 --------------------------------------
7674 -- Build_Subprogram_Receiving_Stubs --
7675 --------------------------------------
7676
7677 function Build_Subprogram_Receiving_Stubs
7678 (Vis_Decl : Node_Id;
7679 Asynchronous : Boolean;
7680 Dynamically_Asynchronous : Boolean := False;
7681 Stub_Type : Entity_Id := Empty;
7682 RACW_Type : Entity_Id := Empty;
7683 Parent_Primitive : Entity_Id := Empty) return Node_Id
7684 is
7685 Loc : constant Source_Ptr := Sloc (Vis_Decl);
7686
7687 Request_Parameter : constant Entity_Id := Make_Temporary (Loc, 'R');
7688 -- Formal parameter for receiving stubs: a descriptor for an incoming
7689 -- request.
7690
7691 Outer_Decls : constant List_Id := New_List;
7692 -- At the outermost level, an NVList and Any's are declared for all
7693 -- parameters. The Dynamic_Async flag also needs to be declared there
7694 -- to be visible from the exception handling code.
7695
7696 Outer_Statements : constant List_Id := New_List;
7697 -- Statements that occur prior to the declaration of the actual
7698 -- parameter variables.
7699
7700 Outer_Extra_Formal_Statements : constant List_Id := New_List;
7701 -- Statements concerning extra formal parameters, prior to the
7702 -- declaration of the actual parameter variables.
7703
7704 Decls : constant List_Id := New_List;
7705 -- All the parameters will get declared before calling the real
7706 -- subprograms. Also the out parameters will be declared. At this
7707 -- level, parameters may be unconstrained.
7708
7709 Statements : constant List_Id := New_List;
7710
7711 After_Statements : constant List_Id := New_List;
7712 -- Statements to be executed after the subprogram call
7713
7714 Inner_Decls : List_Id := No_List;
7715 -- In case of a function, the inner declarations are needed since
7716 -- the result may be unconstrained.
7717
7718 Excep_Handlers : List_Id := No_List;
7719
7720 Parameter_List : constant List_Id := New_List;
7721 -- List of parameters to be passed to the subprogram
7722
7723 First_Controlling_Formal_Seen : Boolean := False;
7724
7725 Current_Parameter : Node_Id;
7726
7727 Ordered_Parameters_List : constant List_Id :=
7728 Build_Ordered_Parameters_List
7729 (Specification (Vis_Decl));
7730
7731 Arguments : constant Entity_Id := Make_Temporary (Loc, 'A');
7732 -- Name of the named values list used to retrieve parameters
7733
7734 Subp_Spec : Node_Id;
7735 -- Subprogram specification
7736
7737 Called_Subprogram : Node_Id;
7738 -- The subprogram to call
7739
7740 begin
7741 if Present (RACW_Type) then
7742 Called_Subprogram :=
7743 New_Occurrence_Of (Parent_Primitive, Loc);
7744 else
7745 Called_Subprogram :=
7746 New_Occurrence_Of
7747 (Defining_Unit_Name (Specification (Vis_Decl)), Loc);
7748 end if;
7749
7750 Declare_Create_NVList (Loc, Arguments, Outer_Decls, Outer_Statements);
7751
7752 -- Loop through every parameter and get its value from the stream. If
7753 -- the parameter is unconstrained, then the parameter is read using
7754 -- 'Input at the point of declaration.
7755
7756 Current_Parameter := First (Ordered_Parameters_List);
7757 while Present (Current_Parameter) loop
7758 declare
7759 Etyp : Entity_Id;
7760 Constrained : Boolean;
7761 Any : Entity_Id := Empty;
7762 Object : constant Entity_Id := Make_Temporary (Loc, 'P');
7763 Expr : Node_Id := Empty;
7764
7765 Is_Controlling_Formal : constant Boolean :=
7766 Is_RACW_Controlling_Formal
7767 (Current_Parameter, Stub_Type);
7768
7769 Is_First_Controlling_Formal : Boolean := False;
7770
7771 Need_Extra_Constrained : Boolean;
7772 -- True when an extra constrained actual is required
7773
7774 begin
7775 if Is_Controlling_Formal then
7776
7777 -- Controlling formals in distributed object primitive
7778 -- operations are handled specially:
7779
7780 -- - the first controlling formal is used as the
7781 -- target of the call;
7782
7783 -- - the remaining controlling formals are transmitted
7784 -- as RACWs.
7785
7786 Etyp := RACW_Type;
7787 Is_First_Controlling_Formal :=
7788 not First_Controlling_Formal_Seen;
7789 First_Controlling_Formal_Seen := True;
7790
7791 else
7792 Etyp := Etype (Parameter_Type (Current_Parameter));
7793 end if;
7794
7795 Constrained :=
7796 Is_Constrained (Etyp) or else Is_Elementary_Type (Etyp);
7797
7798 if not Is_First_Controlling_Formal then
7799 Any := Make_Temporary (Loc, 'A');
7800
7801 Append_To (Outer_Decls,
7802 Make_Object_Declaration (Loc,
7803 Defining_Identifier => Any,
7804 Object_Definition =>
7805 New_Occurrence_Of (RTE (RE_Any), Loc),
7806 Expression =>
7807 Make_Function_Call (Loc,
7808 Name => New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7809 Parameter_Associations => New_List (
7810 PolyORB_Support.Helpers.Build_TypeCode_Call
7811 (Loc, Etyp, Outer_Decls)))));
7812
7813 Append_To (Outer_Statements,
7814 Add_Parameter_To_NVList (Loc,
7815 Parameter => Current_Parameter,
7816 NVList => Arguments,
7817 Constrained => Constrained,
7818 Any => Any));
7819 end if;
7820
7821 if Is_First_Controlling_Formal then
7822 declare
7823 Addr : constant Entity_Id := Make_Temporary (Loc, 'A');
7824
7825 Is_Local : constant Entity_Id :=
7826 Make_Temporary (Loc, 'L');
7827
7828 begin
7829 -- Special case: obtain the first controlling formal
7830 -- from the target of the remote call, instead of the
7831 -- argument list.
7832
7833 Append_To (Outer_Decls,
7834 Make_Object_Declaration (Loc,
7835 Defining_Identifier => Addr,
7836 Object_Definition =>
7837 New_Occurrence_Of (RTE (RE_Address), Loc)));
7838
7839 Append_To (Outer_Decls,
7840 Make_Object_Declaration (Loc,
7841 Defining_Identifier => Is_Local,
7842 Object_Definition =>
7843 New_Occurrence_Of (Standard_Boolean, Loc)));
7844
7845 Append_To (Outer_Statements,
7846 Make_Procedure_Call_Statement (Loc,
7847 Name =>
7848 New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
7849 Parameter_Associations => New_List (
7850 Make_Selected_Component (Loc,
7851 Prefix =>
7852 New_Occurrence_Of (
7853 Request_Parameter, Loc),
7854 Selector_Name =>
7855 Make_Identifier (Loc, Name_Target)),
7856 New_Occurrence_Of (Is_Local, Loc),
7857 New_Occurrence_Of (Addr, Loc))));
7858
7859 Expr := Unchecked_Convert_To (RACW_Type,
7860 New_Occurrence_Of (Addr, Loc));
7861 end;
7862
7863 elsif In_Present (Current_Parameter)
7864 or else not Out_Present (Current_Parameter)
7865 or else not Constrained
7866 then
7867 -- If an input parameter is constrained, then its reading is
7868 -- deferred until the beginning of the subprogram body. If
7869 -- it is unconstrained, then an expression is built for
7870 -- the object declaration and the variable is set using
7871 -- 'Input instead of 'Read.
7872
7873 if Constrained and then Is_Limited_Type (Etyp) then
7874 Helpers.Assign_Opaque_From_Any (Loc,
7875 Stms => Statements,
7876 Typ => Etyp,
7877 N => New_Occurrence_Of (Any, Loc),
7878 Target => Object);
7879
7880 else
7881 Expr := Helpers.Build_From_Any_Call
7882 (Etyp, New_Occurrence_Of (Any, Loc), Decls);
7883
7884 if Constrained then
7885 Append_To (Statements,
7886 Make_Assignment_Statement (Loc,
7887 Name => New_Occurrence_Of (Object, Loc),
7888 Expression => Expr));
7889 Expr := Empty;
7890
7891 else
7892 -- Expr will be used to initialize (and constrain) the
7893 -- parameter when it is declared.
7894 null;
7895 end if;
7896
7897 null;
7898 end if;
7899 end if;
7900
7901 Need_Extra_Constrained :=
7902 Nkind (Parameter_Type (Current_Parameter)) /=
7903 N_Access_Definition
7904 and then
7905 Ekind (Defining_Identifier (Current_Parameter)) /= E_Void
7906 and then
7907 Present (Extra_Constrained
7908 (Defining_Identifier (Current_Parameter)));
7909
7910 -- We may not associate an extra constrained actual to a
7911 -- constant object, so if one is needed, declare the actual
7912 -- as a variable even if it won't be modified.
7913
7914 Build_Actual_Object_Declaration
7915 (Object => Object,
7916 Etyp => Etyp,
7917 Variable => Need_Extra_Constrained
7918 or else Out_Present (Current_Parameter),
7919 Expr => Expr,
7920 Decls => Decls);
7921 Set_Etype (Object, Etyp);
7922
7923 -- An out parameter may be written back using a 'Write
7924 -- attribute instead of a 'Output because it has been
7925 -- constrained by the parameter given to the caller. Note that
7926 -- OUT controlling arguments in the case of a RACW are not put
7927 -- back in the stream because the pointer on them has not
7928 -- changed.
7929
7930 if Out_Present (Current_Parameter)
7931 and then not Is_Controlling_Formal
7932 then
7933 Append_To (After_Statements,
7934 Make_Procedure_Call_Statement (Loc,
7935 Name => New_Occurrence_Of (RTE (RE_Move_Any_Value), Loc),
7936 Parameter_Associations => New_List (
7937 New_Occurrence_Of (Any, Loc),
7938 PolyORB_Support.Helpers.Build_To_Any_Call
7939 (Loc,
7940 New_Occurrence_Of (Object, Loc),
7941 Decls,
7942 Constrained => True))));
7943 end if;
7944
7945 -- For RACW controlling formals, the Etyp of Object is always
7946 -- an RACW, even if the parameter is not of an anonymous access
7947 -- type. In such case, we need to dereference it at call time.
7948
7949 if Is_Controlling_Formal then
7950 if Nkind (Parameter_Type (Current_Parameter)) /=
7951 N_Access_Definition
7952 then
7953 Append_To (Parameter_List,
7954 Make_Parameter_Association (Loc,
7955 Selector_Name =>
7956 New_Occurrence_Of
7957 (Defining_Identifier (Current_Parameter), Loc),
7958 Explicit_Actual_Parameter =>
7959 Make_Explicit_Dereference (Loc,
7960 Prefix => New_Occurrence_Of (Object, Loc))));
7961
7962 else
7963 Append_To (Parameter_List,
7964 Make_Parameter_Association (Loc,
7965 Selector_Name =>
7966 New_Occurrence_Of
7967 (Defining_Identifier (Current_Parameter), Loc),
7968
7969 Explicit_Actual_Parameter =>
7970 New_Occurrence_Of (Object, Loc)));
7971 end if;
7972
7973 else
7974 Append_To (Parameter_List,
7975 Make_Parameter_Association (Loc,
7976 Selector_Name =>
7977 New_Occurrence_Of (
7978 Defining_Identifier (Current_Parameter), Loc),
7979 Explicit_Actual_Parameter =>
7980 New_Occurrence_Of (Object, Loc)));
7981 end if;
7982
7983 -- If the current parameter needs an extra formal, then read it
7984 -- from the stream and set the corresponding semantic field in
7985 -- the variable. If the kind of the parameter identifier is
7986 -- E_Void, then this is a compiler generated parameter that
7987 -- doesn't need an extra constrained status.
7988
7989 -- The case of Extra_Accessibility should also be handled ???
7990
7991 if Need_Extra_Constrained then
7992 declare
7993 Extra_Parameter : constant Entity_Id :=
7994 Extra_Constrained
7995 (Defining_Identifier
7996 (Current_Parameter));
7997
7998 Extra_Any : constant Entity_Id :=
7999 Make_Temporary (Loc, 'A');
8000
8001 Formal_Entity : constant Entity_Id :=
8002 Make_Defining_Identifier (Loc,
8003 Chars => Chars (Extra_Parameter));
8004
8005 Formal_Type : constant Entity_Id :=
8006 Etype (Extra_Parameter);
8007
8008 begin
8009 Append_To (Outer_Decls,
8010 Make_Object_Declaration (Loc,
8011 Defining_Identifier => Extra_Any,
8012 Object_Definition =>
8013 New_Occurrence_Of (RTE (RE_Any), Loc),
8014 Expression =>
8015 Make_Function_Call (Loc,
8016 Name =>
8017 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
8018 Parameter_Associations => New_List (
8019 PolyORB_Support.Helpers.Build_TypeCode_Call
8020 (Loc, Formal_Type, Outer_Decls)))));
8021
8022 Append_To (Outer_Extra_Formal_Statements,
8023 Add_Parameter_To_NVList (Loc,
8024 Parameter => Extra_Parameter,
8025 NVList => Arguments,
8026 Constrained => True,
8027 Any => Extra_Any));
8028
8029 Append_To (Decls,
8030 Make_Object_Declaration (Loc,
8031 Defining_Identifier => Formal_Entity,
8032 Object_Definition =>
8033 New_Occurrence_Of (Formal_Type, Loc)));
8034
8035 Append_To (Statements,
8036 Make_Assignment_Statement (Loc,
8037 Name => New_Occurrence_Of (Formal_Entity, Loc),
8038 Expression =>
8039 PolyORB_Support.Helpers.Build_From_Any_Call
8040 (Formal_Type,
8041 New_Occurrence_Of (Extra_Any, Loc),
8042 Decls)));
8043 Set_Extra_Constrained (Object, Formal_Entity);
8044 end;
8045 end if;
8046 end;
8047
8048 Next (Current_Parameter);
8049 end loop;
8050
8051 -- Extra Formals should go after all the other parameters
8052
8053 Append_List_To (Outer_Statements, Outer_Extra_Formal_Statements);
8054
8055 Append_To (Outer_Statements,
8056 Make_Procedure_Call_Statement (Loc,
8057 Name => New_Occurrence_Of (RTE (RE_Request_Arguments), Loc),
8058 Parameter_Associations => New_List (
8059 New_Occurrence_Of (Request_Parameter, Loc),
8060 New_Occurrence_Of (Arguments, Loc))));
8061
8062 if Nkind (Specification (Vis_Decl)) = N_Function_Specification then
8063
8064 -- The remote subprogram is a function: Build an inner block to be
8065 -- able to hold a potentially unconstrained result in a variable.
8066
8067 declare
8068 Etyp : constant Entity_Id :=
8069 Etype (Result_Definition (Specification (Vis_Decl)));
8070 Result : constant Node_Id := Make_Temporary (Loc, 'R');
8071
8072 begin
8073 Inner_Decls := New_List (
8074 Make_Object_Declaration (Loc,
8075 Defining_Identifier => Result,
8076 Constant_Present => True,
8077 Object_Definition => New_Occurrence_Of (Etyp, Loc),
8078 Expression =>
8079 Make_Function_Call (Loc,
8080 Name => Called_Subprogram,
8081 Parameter_Associations => Parameter_List)));
8082
8083 if Is_Class_Wide_Type (Etyp) then
8084
8085 -- For a remote call to a function with a class-wide type,
8086 -- check that the returned value satisfies the requirements
8087 -- of (RM E.4(18)).
8088
8089 Append_To (Inner_Decls,
8090 Make_Transportable_Check (Loc,
8091 New_Occurrence_Of (Result, Loc)));
8092
8093 end if;
8094
8095 Set_Etype (Result, Etyp);
8096 Append_To (After_Statements,
8097 Make_Procedure_Call_Statement (Loc,
8098 Name => New_Occurrence_Of (RTE (RE_Set_Result), Loc),
8099 Parameter_Associations => New_List (
8100 New_Occurrence_Of (Request_Parameter, Loc),
8101 PolyORB_Support.Helpers.Build_To_Any_Call
8102 (Loc, New_Occurrence_Of (Result, Loc), Decls))));
8103
8104 -- A DSA function does not have out or inout arguments
8105 end;
8106
8107 Append_To (Statements,
8108 Make_Block_Statement (Loc,
8109 Declarations => Inner_Decls,
8110 Handled_Statement_Sequence =>
8111 Make_Handled_Sequence_Of_Statements (Loc,
8112 Statements => After_Statements)));
8113
8114 else
8115 -- The remote subprogram is a procedure. We do not need any inner
8116 -- block in this case. No specific processing is required here for
8117 -- the dynamically asynchronous case: the indication of whether
8118 -- call is asynchronous or not is managed by the Sync_Scope
8119 -- attibute of the request, and is handled entirely in the
8120 -- protocol layer.
8121
8122 Append_To (After_Statements,
8123 Make_Procedure_Call_Statement (Loc,
8124 Name => New_Occurrence_Of (RTE (RE_Request_Set_Out), Loc),
8125 Parameter_Associations => New_List (
8126 New_Occurrence_Of (Request_Parameter, Loc))));
8127
8128 Append_To (Statements,
8129 Make_Procedure_Call_Statement (Loc,
8130 Name => Called_Subprogram,
8131 Parameter_Associations => Parameter_List));
8132
8133 Append_List_To (Statements, After_Statements);
8134 end if;
8135
8136 Subp_Spec :=
8137 Make_Procedure_Specification (Loc,
8138 Defining_Unit_Name => Make_Temporary (Loc, 'F'),
8139
8140 Parameter_Specifications => New_List (
8141 Make_Parameter_Specification (Loc,
8142 Defining_Identifier => Request_Parameter,
8143 Parameter_Type =>
8144 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
8145
8146 -- An exception raised during the execution of an incoming remote
8147 -- subprogram call and that needs to be sent back to the caller is
8148 -- propagated by the receiving stubs, and will be handled by the
8149 -- caller (the distribution runtime).
8150
8151 if Asynchronous and then not Dynamically_Asynchronous then
8152
8153 -- For an asynchronous procedure, add a null exception handler
8154
8155 Excep_Handlers := New_List (
8156 Make_Implicit_Exception_Handler (Loc,
8157 Exception_Choices => New_List (Make_Others_Choice (Loc)),
8158 Statements => New_List (Make_Null_Statement (Loc))));
8159
8160 else
8161 -- In the other cases, if an exception is raised, then the
8162 -- exception occurrence is propagated.
8163
8164 null;
8165 end if;
8166
8167 Append_To (Outer_Statements,
8168 Make_Block_Statement (Loc,
8169 Declarations => Decls,
8170 Handled_Statement_Sequence =>
8171 Make_Handled_Sequence_Of_Statements (Loc,
8172 Statements => Statements)));
8173
8174 return
8175 Make_Subprogram_Body (Loc,
8176 Specification => Subp_Spec,
8177 Declarations => Outer_Decls,
8178 Handled_Statement_Sequence =>
8179 Make_Handled_Sequence_Of_Statements (Loc,
8180 Statements => Outer_Statements,
8181 Exception_Handlers => Excep_Handlers));
8182 end Build_Subprogram_Receiving_Stubs;
8183
8184 -------------
8185 -- Helpers --
8186 -------------
8187
8188 package body Helpers is
8189
8190 -----------------------
8191 -- Local Subprograms --
8192 -----------------------
8193
8194 function Find_Numeric_Representation
8195 (Typ : Entity_Id) return Entity_Id;
8196 -- Given a numeric type Typ, return the smallest integer or modular
8197 -- type from Interfaces, or the smallest floating point type from
8198 -- Standard whose range encompasses that of Typ.
8199
8200 function Is_Generic_Actual_Subtype (Typ : Entity_Id) return Boolean;
8201 -- Return true if Typ is a subtype representing a generic formal type
8202 -- as a subtype of the actual type in an instance. This is needed to
8203 -- recognize these subtypes because the Is_Generic_Actual_Type flag
8204 -- can only be relied upon within the instance.
8205
8206 function Make_Helper_Function_Name
8207 (Loc : Source_Ptr;
8208 Typ : Entity_Id;
8209 Nam : Name_Id) return Entity_Id;
8210 -- Return the name to be assigned for helper subprogram Nam of Typ
8211
8212 ------------------------------------------------------------
8213 -- Common subprograms for building various tree fragments --
8214 ------------------------------------------------------------
8215
8216 function Build_Get_Aggregate_Element
8217 (Loc : Source_Ptr;
8218 Any : Entity_Id;
8219 TC : Node_Id;
8220 Idx : Node_Id) return Node_Id;
8221 -- Build a call to Get_Aggregate_Element on Any for typecode TC,
8222 -- returning the Idx'th element.
8223
8224 generic
8225 Subprogram : Entity_Id;
8226 -- Reference location for constructed nodes
8227
8228 Arry : Entity_Id;
8229 -- For 'Range and Etype
8230
8231 Indexes : List_Id;
8232 -- For the construction of the innermost element expression
8233
8234 with procedure Add_Process_Element
8235 (Stmts : List_Id;
8236 Any : Entity_Id;
8237 Counter : Entity_Id;
8238 Datum : Node_Id);
8239
8240 procedure Append_Array_Traversal
8241 (Stmts : List_Id;
8242 Any : Entity_Id;
8243 Counter : Entity_Id := Empty;
8244 Depth : Pos := 1);
8245 -- Build nested loop statements that iterate over the elements of an
8246 -- array Arry. The statement(s) built by Add_Process_Element are
8247 -- executed for each element; Indexes is the list of indexes to be
8248 -- used in the construction of the indexed component that denotes the
8249 -- current element. Subprogram is the entity for the subprogram for
8250 -- which this iterator is generated. The generated statements are
8251 -- appended to Stmts.
8252
8253 generic
8254 Rec : Entity_Id;
8255 -- The record entity being dealt with
8256
8257 with procedure Add_Process_Element
8258 (Stmts : List_Id;
8259 Container : Node_Or_Entity_Id;
8260 Counter : in out Nat;
8261 Rec : Entity_Id;
8262 Field : Node_Id);
8263 -- Rec is the instance of the record type, or Empty.
8264 -- Field is either the N_Defining_Identifier for a component,
8265 -- or an N_Variant_Part.
8266
8267 procedure Append_Record_Traversal
8268 (Stmts : List_Id;
8269 Clist : Node_Id;
8270 Container : Node_Or_Entity_Id;
8271 Counter : in out Nat);
8272 -- Process component list Clist. Individual fields are passed
8273 -- to Field_Processing. Each variant part is also processed.
8274 -- Container is the outer Any (for From_Any/To_Any),
8275 -- the outer typecode (for TC) to which the operation applies.
8276
8277 -----------------------------
8278 -- Append_Record_Traversal --
8279 -----------------------------
8280
8281 procedure Append_Record_Traversal
8282 (Stmts : List_Id;
8283 Clist : Node_Id;
8284 Container : Node_Or_Entity_Id;
8285 Counter : in out Nat)
8286 is
8287 CI : List_Id;
8288 VP : Node_Id;
8289 -- Clist's Component_Items and Variant_Part
8290
8291 Item : Node_Id;
8292 Def : Entity_Id;
8293
8294 begin
8295 if No (Clist) then
8296 return;
8297 end if;
8298
8299 CI := Component_Items (Clist);
8300 VP := Variant_Part (Clist);
8301
8302 Item := First_Non_Pragma (CI);
8303 while Present (Item) loop
8304 Def := Defining_Identifier (Item);
8305
8306 if not Is_Internal_Name (Chars (Def)) then
8307 Add_Process_Element
8308 (Stmts, Container, Counter, Rec, Def);
8309 end if;
8310
8311 Next_Non_Pragma (Item);
8312 end loop;
8313
8314 if Present (VP) then
8315 Add_Process_Element (Stmts, Container, Counter, Rec, VP);
8316 end if;
8317 end Append_Record_Traversal;
8318
8319 -----------------------------
8320 -- Assign_Opaque_From_Any --
8321 -----------------------------
8322
8323 procedure Assign_Opaque_From_Any
8324 (Loc : Source_Ptr;
8325 Stms : List_Id;
8326 Typ : Entity_Id;
8327 N : Node_Id;
8328 Target : Entity_Id;
8329 Constrained : Boolean := False)
8330 is
8331 Strm : constant Entity_Id := Make_Temporary (Loc, 'S');
8332 Expr : Node_Id;
8333
8334 Read_Call_List : List_Id;
8335 -- List on which to place the 'Read attribute reference
8336
8337 begin
8338 -- Strm : Buffer_Stream_Type;
8339
8340 Append_To (Stms,
8341 Make_Object_Declaration (Loc,
8342 Defining_Identifier => Strm,
8343 Aliased_Present => True,
8344 Object_Definition =>
8345 New_Occurrence_Of (RTE (RE_Buffer_Stream_Type), Loc)));
8346
8347 -- Any_To_BS (Strm, A);
8348
8349 Append_To (Stms,
8350 Make_Procedure_Call_Statement (Loc,
8351 Name => New_Occurrence_Of (RTE (RE_Any_To_BS), Loc),
8352 Parameter_Associations => New_List (
8353 N,
8354 New_Occurrence_Of (Strm, Loc))));
8355
8356 if Transmit_As_Unconstrained (Typ) and then not Constrained then
8357 Expr :=
8358 Make_Attribute_Reference (Loc,
8359 Prefix => New_Occurrence_Of (Typ, Loc),
8360 Attribute_Name => Name_Input,
8361 Expressions => New_List (
8362 Make_Attribute_Reference (Loc,
8363 Prefix => New_Occurrence_Of (Strm, Loc),
8364 Attribute_Name => Name_Access)));
8365
8366 -- Target := Typ'Input (Strm'Access)
8367
8368 if Present (Target) then
8369 Append_To (Stms,
8370 Make_Assignment_Statement (Loc,
8371 Name => New_Occurrence_Of (Target, Loc),
8372 Expression => Expr));
8373
8374 -- return Typ'Input (Strm'Access);
8375
8376 else
8377 Append_To (Stms,
8378 Make_Simple_Return_Statement (Loc,
8379 Expression => Expr));
8380 end if;
8381
8382 else
8383 if Present (Target) then
8384 Read_Call_List := Stms;
8385 Expr := New_Occurrence_Of (Target, Loc);
8386
8387 else
8388 declare
8389 Temp : constant Entity_Id := Make_Temporary (Loc, 'R');
8390
8391 begin
8392 Read_Call_List := New_List;
8393 Expr := New_Occurrence_Of (Temp, Loc);
8394
8395 Append_To (Stms, Make_Block_Statement (Loc,
8396 Declarations => New_List (
8397 Make_Object_Declaration (Loc,
8398 Defining_Identifier =>
8399 Temp,
8400 Object_Definition =>
8401 New_Occurrence_Of (Typ, Loc))),
8402
8403 Handled_Statement_Sequence =>
8404 Make_Handled_Sequence_Of_Statements (Loc,
8405 Statements => Read_Call_List)));
8406 end;
8407 end if;
8408
8409 -- Typ'Read (Strm'Access, [Target|Temp])
8410
8411 Append_To (Read_Call_List,
8412 Make_Attribute_Reference (Loc,
8413 Prefix => New_Occurrence_Of (Typ, Loc),
8414 Attribute_Name => Name_Read,
8415 Expressions => New_List (
8416 Make_Attribute_Reference (Loc,
8417 Prefix => New_Occurrence_Of (Strm, Loc),
8418 Attribute_Name => Name_Access),
8419 Expr)));
8420
8421 if No (Target) then
8422
8423 -- return Temp
8424
8425 Append_To (Read_Call_List,
8426 Make_Simple_Return_Statement (Loc,
8427 Expression => New_Copy (Expr)));
8428 end if;
8429 end if;
8430 end Assign_Opaque_From_Any;
8431
8432 -------------------------
8433 -- Build_From_Any_Call --
8434 -------------------------
8435
8436 function Build_From_Any_Call
8437 (Typ : Entity_Id;
8438 N : Node_Id;
8439 Decls : List_Id) return Node_Id
8440 is
8441 Loc : constant Source_Ptr := Sloc (N);
8442
8443 U_Type : Entity_Id := Underlying_Type (Typ);
8444
8445 Fnam : Entity_Id;
8446 Lib_RE : RE_Id := RE_Null;
8447 Result : Node_Id;
8448
8449 begin
8450 -- First simple case where the From_Any function is present
8451 -- in the type's TSS.
8452
8453 Fnam := Find_Inherited_TSS (U_Type, TSS_From_Any);
8454
8455 -- For the subtype representing a generic actual type, go to the
8456 -- actual type.
8457
8458 if Is_Generic_Actual_Subtype (U_Type) then
8459 U_Type := Underlying_Type (Base_Type (U_Type));
8460 end if;
8461
8462 -- For a standard subtype, go to the base type
8463
8464 if Sloc (U_Type) <= Standard_Location then
8465 U_Type := Base_Type (U_Type);
8466
8467 -- For a user subtype, go to first subtype
8468
8469 elsif Comes_From_Source (U_Type)
8470 and then Nkind (Declaration_Node (U_Type))
8471 = N_Subtype_Declaration
8472 then
8473 U_Type := First_Subtype (U_Type);
8474 end if;
8475
8476 -- Check first for Boolean and Character. These are enumeration
8477 -- types, but we treat them specially, since they may require
8478 -- special handling in the transfer protocol. However, this
8479 -- special handling only applies if they have standard
8480 -- representation, otherwise they are treated like any other
8481 -- enumeration type.
8482
8483 if Present (Fnam) then
8484 null;
8485
8486 elsif U_Type = Standard_Boolean then
8487 Lib_RE := RE_FA_B;
8488
8489 elsif U_Type = Standard_Character then
8490 Lib_RE := RE_FA_C;
8491
8492 elsif U_Type = Standard_Wide_Character then
8493 Lib_RE := RE_FA_WC;
8494
8495 elsif U_Type = Standard_Wide_Wide_Character then
8496 Lib_RE := RE_FA_WWC;
8497
8498 -- Floating point types
8499
8500 elsif U_Type = Standard_Short_Float then
8501 Lib_RE := RE_FA_SF;
8502
8503 elsif U_Type = Standard_Float then
8504 Lib_RE := RE_FA_F;
8505
8506 elsif U_Type = Standard_Long_Float then
8507 Lib_RE := RE_FA_LF;
8508
8509 elsif U_Type = Standard_Long_Long_Float then
8510 Lib_RE := RE_FA_LLF;
8511
8512 -- Integer types
8513
8514 elsif U_Type = RTE (RE_Integer_8) then
8515 Lib_RE := RE_FA_I8;
8516
8517 elsif U_Type = RTE (RE_Integer_16) then
8518 Lib_RE := RE_FA_I16;
8519
8520 elsif U_Type = RTE (RE_Integer_32) then
8521 Lib_RE := RE_FA_I32;
8522
8523 elsif U_Type = RTE (RE_Integer_64) then
8524 Lib_RE := RE_FA_I64;
8525
8526 -- Unsigned integer types
8527
8528 elsif U_Type = RTE (RE_Unsigned_8) then
8529 Lib_RE := RE_FA_U8;
8530
8531 elsif U_Type = RTE (RE_Unsigned_16) then
8532 Lib_RE := RE_FA_U16;
8533
8534 elsif U_Type = RTE (RE_Unsigned_32) then
8535 Lib_RE := RE_FA_U32;
8536
8537 elsif U_Type = RTE (RE_Unsigned_64) then
8538 Lib_RE := RE_FA_U64;
8539
8540 elsif Is_RTE (U_Type, RE_Unbounded_String) then
8541 Lib_RE := RE_FA_String;
8542
8543 -- Special DSA types
8544
8545 elsif Is_RTE (U_Type, RE_Any_Container_Ptr) then
8546 Lib_RE := RE_FA_A;
8547
8548 -- Other (non-primitive) types
8549
8550 else
8551 declare
8552 Decl : Entity_Id;
8553
8554 begin
8555 Build_From_Any_Function (Loc, U_Type, Decl, Fnam);
8556 Append_To (Decls, Decl);
8557 end;
8558 end if;
8559
8560 -- Call the function
8561
8562 if Lib_RE /= RE_Null then
8563 pragma Assert (No (Fnam));
8564 Fnam := RTE (Lib_RE);
8565 end if;
8566
8567 Result :=
8568 Make_Function_Call (Loc,
8569 Name => New_Occurrence_Of (Fnam, Loc),
8570 Parameter_Associations => New_List (N));
8571
8572 -- We must set the type of Result, so the unchecked conversion
8573 -- from the underlying type to the base type is properly done.
8574
8575 Set_Etype (Result, U_Type);
8576
8577 return Unchecked_Convert_To (Typ, Result);
8578 end Build_From_Any_Call;
8579
8580 -----------------------------
8581 -- Build_From_Any_Function --
8582 -----------------------------
8583
8584 procedure Build_From_Any_Function
8585 (Loc : Source_Ptr;
8586 Typ : Entity_Id;
8587 Decl : out Node_Id;
8588 Fnam : out Entity_Id)
8589 is
8590 Spec : Node_Id;
8591 Decls : constant List_Id := New_List;
8592 Stms : constant List_Id := New_List;
8593
8594 Any_Parameter : constant Entity_Id := Make_Temporary (Loc, 'A');
8595
8596 Use_Opaque_Representation : Boolean;
8597
8598 Real_Rep : Node_Id;
8599
8600 begin
8601 -- For a derived type, we can't go past the base type (to the
8602 -- parent type) here, because that would cause the attribute's
8603 -- formal parameter to have the wrong type; hence the Base_Type
8604 -- check here.
8605
8606 if Is_Itype (Typ) and then Typ /= Base_Type (Typ) then
8607 Build_From_Any_Function
8608 (Loc => Loc,
8609 Typ => Etype (Typ),
8610 Decl => Decl,
8611 Fnam => Fnam);
8612 return;
8613 end if;
8614
8615 Fnam := Make_Helper_Function_Name (Loc, Typ, Name_From_Any);
8616
8617 Spec :=
8618 Make_Function_Specification (Loc,
8619 Defining_Unit_Name => Fnam,
8620 Parameter_Specifications => New_List (
8621 Make_Parameter_Specification (Loc,
8622 Defining_Identifier => Any_Parameter,
8623 Parameter_Type => New_Occurrence_Of (RTE (RE_Any), Loc))),
8624 Result_Definition => New_Occurrence_Of (Typ, Loc));
8625
8626 -- The RACW case is taken care of by Exp_Dist.Add_RACW_From_Any
8627
8628 pragma Assert
8629 (not Is_Remote_Access_To_Class_Wide_Type (Typ));
8630
8631 Use_Opaque_Representation := False;
8632
8633 if Has_Stream_Attribute_Definition
8634 (Typ, TSS_Stream_Output, Real_Rep, At_Any_Place => True)
8635 or else
8636 Has_Stream_Attribute_Definition
8637 (Typ, TSS_Stream_Write, Real_Rep, At_Any_Place => True)
8638 then
8639 -- If user-defined stream attributes are specified for this
8640 -- type, use them and transmit data as an opaque sequence of
8641 -- stream elements.
8642
8643 Use_Opaque_Representation := True;
8644
8645 elsif Is_Derived_Type (Typ) and then not Is_Tagged_Type (Typ) then
8646 Append_To (Stms,
8647 Make_Simple_Return_Statement (Loc,
8648 Expression =>
8649 OK_Convert_To (Typ,
8650 Build_From_Any_Call
8651 (Root_Type (Typ),
8652 New_Occurrence_Of (Any_Parameter, Loc),
8653 Decls))));
8654
8655 elsif Is_Record_Type (Typ)
8656 and then not Is_Derived_Type (Typ)
8657 and then not Is_Tagged_Type (Typ)
8658 then
8659 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
8660 Append_To (Stms,
8661 Make_Simple_Return_Statement (Loc,
8662 Expression =>
8663 Build_From_Any_Call
8664 (Etype (Typ),
8665 New_Occurrence_Of (Any_Parameter, Loc),
8666 Decls)));
8667
8668 else
8669 declare
8670 Disc : Entity_Id := Empty;
8671 Discriminant_Associations : List_Id;
8672 Rdef : constant Node_Id :=
8673 Type_Definition
8674 (Declaration_Node (Typ));
8675 Component_Counter : Nat := 0;
8676
8677 -- The returned object
8678
8679 Res : constant Entity_Id := Make_Temporary (Loc, 'R');
8680
8681 Res_Definition : Node_Id := New_Occurrence_Of (Typ, Loc);
8682
8683 procedure FA_Rec_Add_Process_Element
8684 (Stmts : List_Id;
8685 Any : Entity_Id;
8686 Counter : in out Nat;
8687 Rec : Entity_Id;
8688 Field : Node_Id);
8689
8690 procedure FA_Append_Record_Traversal is
8691 new Append_Record_Traversal
8692 (Rec => Res,
8693 Add_Process_Element => FA_Rec_Add_Process_Element);
8694
8695 --------------------------------
8696 -- FA_Rec_Add_Process_Element --
8697 --------------------------------
8698
8699 procedure FA_Rec_Add_Process_Element
8700 (Stmts : List_Id;
8701 Any : Entity_Id;
8702 Counter : in out Nat;
8703 Rec : Entity_Id;
8704 Field : Node_Id)
8705 is
8706 Ctyp : Entity_Id;
8707 begin
8708 if Nkind (Field) = N_Defining_Identifier then
8709 -- A regular component
8710
8711 Ctyp := Etype (Field);
8712
8713 Append_To (Stmts,
8714 Make_Assignment_Statement (Loc,
8715 Name => Make_Selected_Component (Loc,
8716 Prefix =>
8717 New_Occurrence_Of (Rec, Loc),
8718 Selector_Name =>
8719 New_Occurrence_Of (Field, Loc)),
8720
8721 Expression =>
8722 Build_From_Any_Call (Ctyp,
8723 Build_Get_Aggregate_Element (Loc,
8724 Any => Any,
8725 TC =>
8726 Build_TypeCode_Call (Loc, Ctyp, Decls),
8727 Idx =>
8728 Make_Integer_Literal (Loc, Counter)),
8729 Decls)));
8730
8731 else
8732 -- A variant part
8733
8734 declare
8735 Variant : Node_Id;
8736 Struct_Counter : Nat := 0;
8737
8738 Block_Decls : constant List_Id := New_List;
8739 Block_Stmts : constant List_Id := New_List;
8740 VP_Stmts : List_Id;
8741
8742 Alt_List : constant List_Id := New_List;
8743 Choice_List : List_Id;
8744
8745 Struct_Any : constant Entity_Id :=
8746 Make_Temporary (Loc, 'S');
8747
8748 begin
8749 Append_To (Decls,
8750 Make_Object_Declaration (Loc,
8751 Defining_Identifier => Struct_Any,
8752 Constant_Present => True,
8753 Object_Definition =>
8754 New_Occurrence_Of (RTE (RE_Any), Loc),
8755 Expression =>
8756 Make_Function_Call (Loc,
8757 Name =>
8758 New_Occurrence_Of
8759 (RTE (RE_Extract_Union_Value), Loc),
8760
8761 Parameter_Associations => New_List (
8762 Build_Get_Aggregate_Element (Loc,
8763 Any => Any,
8764 TC =>
8765 Make_Function_Call (Loc,
8766 Name => New_Occurrence_Of (
8767 RTE (RE_Any_Member_Type), Loc),
8768 Parameter_Associations =>
8769 New_List (
8770 New_Occurrence_Of (Any, Loc),
8771 Make_Integer_Literal (Loc,
8772 Intval => Counter))),
8773 Idx =>
8774 Make_Integer_Literal (Loc,
8775 Intval => Counter))))));
8776
8777 Append_To (Stmts,
8778 Make_Block_Statement (Loc,
8779 Declarations => Block_Decls,
8780 Handled_Statement_Sequence =>
8781 Make_Handled_Sequence_Of_Statements (Loc,
8782 Statements => Block_Stmts)));
8783
8784 Append_To (Block_Stmts,
8785 Make_Case_Statement (Loc,
8786 Expression =>
8787 Make_Selected_Component (Loc,
8788 Prefix => Rec,
8789 Selector_Name => Chars (Name (Field))),
8790 Alternatives => Alt_List));
8791
8792 Variant := First_Non_Pragma (Variants (Field));
8793 while Present (Variant) loop
8794 Choice_List :=
8795 New_Copy_List_Tree
8796 (Discrete_Choices (Variant));
8797
8798 VP_Stmts := New_List;
8799
8800 -- Struct_Counter should be reset before
8801 -- handling a variant part. Indeed only one
8802 -- of the case statement alternatives will be
8803 -- executed at run time, so the counter must
8804 -- start at 0 for every case statement.
8805
8806 Struct_Counter := 0;
8807
8808 FA_Append_Record_Traversal (
8809 Stmts => VP_Stmts,
8810 Clist => Component_List (Variant),
8811 Container => Struct_Any,
8812 Counter => Struct_Counter);
8813
8814 Append_To (Alt_List,
8815 Make_Case_Statement_Alternative (Loc,
8816 Discrete_Choices => Choice_List,
8817 Statements => VP_Stmts));
8818 Next_Non_Pragma (Variant);
8819 end loop;
8820 end;
8821 end if;
8822
8823 Counter := Counter + 1;
8824 end FA_Rec_Add_Process_Element;
8825
8826 begin
8827 -- First all discriminants
8828
8829 if Has_Discriminants (Typ) then
8830 Discriminant_Associations := New_List;
8831
8832 Disc := First_Discriminant (Typ);
8833 while Present (Disc) loop
8834 declare
8835 Disc_Var_Name : constant Entity_Id :=
8836 Make_Defining_Identifier (Loc,
8837 Chars => Chars (Disc));
8838 Disc_Type : constant Entity_Id :=
8839 Etype (Disc);
8840
8841 begin
8842 Append_To (Decls,
8843 Make_Object_Declaration (Loc,
8844 Defining_Identifier => Disc_Var_Name,
8845 Constant_Present => True,
8846 Object_Definition =>
8847 New_Occurrence_Of (Disc_Type, Loc),
8848
8849 Expression =>
8850 Build_From_Any_Call (Disc_Type,
8851 Build_Get_Aggregate_Element (Loc,
8852 Any => Any_Parameter,
8853 TC => Build_TypeCode_Call
8854 (Loc, Disc_Type, Decls),
8855 Idx => Make_Integer_Literal (Loc,
8856 Intval => Component_Counter)),
8857 Decls)));
8858
8859 Component_Counter := Component_Counter + 1;
8860
8861 Append_To (Discriminant_Associations,
8862 Make_Discriminant_Association (Loc,
8863 Selector_Names => New_List (
8864 New_Occurrence_Of (Disc, Loc)),
8865 Expression =>
8866 New_Occurrence_Of (Disc_Var_Name, Loc)));
8867 end;
8868 Next_Discriminant (Disc);
8869 end loop;
8870
8871 Res_Definition :=
8872 Make_Subtype_Indication (Loc,
8873 Subtype_Mark => Res_Definition,
8874 Constraint =>
8875 Make_Index_Or_Discriminant_Constraint (Loc,
8876 Discriminant_Associations));
8877 end if;
8878
8879 -- Now we have all the discriminants in variables, we can
8880 -- declared a constrained object. Note that we are not
8881 -- initializing (non-discriminant) components directly in
8882 -- the object declarations, because which fields to
8883 -- initialize depends (at run time) on the discriminant
8884 -- values.
8885
8886 Append_To (Decls,
8887 Make_Object_Declaration (Loc,
8888 Defining_Identifier => Res,
8889 Object_Definition => Res_Definition));
8890
8891 -- ... then all components
8892
8893 FA_Append_Record_Traversal (Stms,
8894 Clist => Component_List (Rdef),
8895 Container => Any_Parameter,
8896 Counter => Component_Counter);
8897
8898 Append_To (Stms,
8899 Make_Simple_Return_Statement (Loc,
8900 Expression => New_Occurrence_Of (Res, Loc)));
8901 end;
8902 end if;
8903
8904 elsif Is_Array_Type (Typ) then
8905 declare
8906 Constrained : constant Boolean := Is_Constrained (Typ);
8907
8908 procedure FA_Ary_Add_Process_Element
8909 (Stmts : List_Id;
8910 Any : Entity_Id;
8911 Counter : Entity_Id;
8912 Datum : Node_Id);
8913 -- Assign the current element (as identified by Counter) of
8914 -- Any to the variable denoted by name Datum, and advance
8915 -- Counter by 1. If Datum is not an Any, a call to From_Any
8916 -- for its type is inserted.
8917
8918 --------------------------------
8919 -- FA_Ary_Add_Process_Element --
8920 --------------------------------
8921
8922 procedure FA_Ary_Add_Process_Element
8923 (Stmts : List_Id;
8924 Any : Entity_Id;
8925 Counter : Entity_Id;
8926 Datum : Node_Id)
8927 is
8928 Assignment : constant Node_Id :=
8929 Make_Assignment_Statement (Loc,
8930 Name => Datum,
8931 Expression => Empty);
8932
8933 Element_Any : Node_Id;
8934
8935 begin
8936 declare
8937 Element_TC : Node_Id;
8938
8939 begin
8940 if Etype (Datum) = RTE (RE_Any) then
8941
8942 -- When Datum is an Any the Etype field is not
8943 -- sufficient to determine the typecode of Datum
8944 -- (which can be a TC_SEQUENCE or TC_ARRAY
8945 -- depending on the value of Constrained).
8946
8947 -- Therefore we retrieve the typecode which has
8948 -- been constructed in Append_Array_Traversal with
8949 -- a call to Get_Any_Type.
8950
8951 Element_TC :=
8952 Make_Function_Call (Loc,
8953 Name => New_Occurrence_Of (
8954 RTE (RE_Get_Any_Type), Loc),
8955 Parameter_Associations => New_List (
8956 New_Occurrence_Of (Entity (Datum), Loc)));
8957 else
8958 -- For non Any Datum we simply construct a typecode
8959 -- matching the Etype of the Datum.
8960
8961 Element_TC := Build_TypeCode_Call
8962 (Loc, Etype (Datum), Decls);
8963 end if;
8964
8965 Element_Any :=
8966 Build_Get_Aggregate_Element (Loc,
8967 Any => Any,
8968 TC => Element_TC,
8969 Idx => New_Occurrence_Of (Counter, Loc));
8970 end;
8971
8972 -- Note: here we *prepend* statements to Stmts, so
8973 -- we must do it in reverse order.
8974
8975 Prepend_To (Stmts,
8976 Make_Assignment_Statement (Loc,
8977 Name =>
8978 New_Occurrence_Of (Counter, Loc),
8979 Expression =>
8980 Make_Op_Add (Loc,
8981 Left_Opnd => New_Occurrence_Of (Counter, Loc),
8982 Right_Opnd => Make_Integer_Literal (Loc, 1))));
8983
8984 if Nkind (Datum) /= N_Attribute_Reference then
8985
8986 -- We ignore the value of the length of each
8987 -- dimension, since the target array has already been
8988 -- constrained anyway.
8989
8990 if Etype (Datum) /= RTE (RE_Any) then
8991 Set_Expression (Assignment,
8992 Build_From_Any_Call
8993 (Component_Type (Typ), Element_Any, Decls));
8994 else
8995 Set_Expression (Assignment, Element_Any);
8996 end if;
8997
8998 Prepend_To (Stmts, Assignment);
8999 end if;
9000 end FA_Ary_Add_Process_Element;
9001
9002 ------------------------
9003 -- Local Declarations --
9004 ------------------------
9005
9006 Counter : constant Entity_Id :=
9007 Make_Defining_Identifier (Loc, Name_J);
9008
9009 Initial_Counter_Value : Int := 0;
9010
9011 Component_TC : constant Entity_Id :=
9012 Make_Defining_Identifier (Loc, Name_T);
9013
9014 Res : constant Entity_Id :=
9015 Make_Defining_Identifier (Loc, Name_R);
9016
9017 procedure Append_From_Any_Array_Iterator is
9018 new Append_Array_Traversal (
9019 Subprogram => Fnam,
9020 Arry => Res,
9021 Indexes => New_List,
9022 Add_Process_Element => FA_Ary_Add_Process_Element);
9023
9024 Res_Subtype_Indication : Node_Id :=
9025 New_Occurrence_Of (Typ, Loc);
9026
9027 begin
9028 if not Constrained then
9029 declare
9030 Ndim : constant Int := Number_Dimensions (Typ);
9031 Lnam : Name_Id;
9032 Hnam : Name_Id;
9033 Indx : Node_Id := First_Index (Typ);
9034 Indt : Entity_Id;
9035
9036 Ranges : constant List_Id := New_List;
9037
9038 begin
9039 for J in 1 .. Ndim loop
9040 Lnam := New_External_Name ('L', J);
9041 Hnam := New_External_Name ('H', J);
9042
9043 -- Note, for empty arrays bounds may be out of
9044 -- the range of Etype (Indx).
9045
9046 Indt := Base_Type (Etype (Indx));
9047
9048 Append_To (Decls,
9049 Make_Object_Declaration (Loc,
9050 Defining_Identifier =>
9051 Make_Defining_Identifier (Loc, Lnam),
9052 Constant_Present => True,
9053 Object_Definition =>
9054 New_Occurrence_Of (Indt, Loc),
9055 Expression =>
9056 Build_From_Any_Call
9057 (Indt,
9058 Build_Get_Aggregate_Element (Loc,
9059 Any => Any_Parameter,
9060 TC => Build_TypeCode_Call
9061 (Loc, Indt, Decls),
9062 Idx =>
9063 Make_Integer_Literal (Loc, J - 1)),
9064 Decls)));
9065
9066 Append_To (Decls,
9067 Make_Object_Declaration (Loc,
9068 Defining_Identifier =>
9069 Make_Defining_Identifier (Loc, Hnam),
9070
9071 Constant_Present => True,
9072
9073 Object_Definition =>
9074 New_Occurrence_Of (Indt, Loc),
9075
9076 Expression => Make_Attribute_Reference (Loc,
9077 Prefix =>
9078 New_Occurrence_Of (Indt, Loc),
9079
9080 Attribute_Name => Name_Val,
9081
9082 Expressions => New_List (
9083 Make_Op_Subtract (Loc,
9084 Left_Opnd =>
9085 Make_Op_Add (Loc,
9086 Left_Opnd =>
9087 OK_Convert_To
9088 (Standard_Long_Integer,
9089 Make_Identifier (Loc, Lnam)),
9090
9091 Right_Opnd =>
9092 OK_Convert_To
9093 (Standard_Long_Integer,
9094 Make_Function_Call (Loc,
9095 Name =>
9096 New_Occurrence_Of (RTE (
9097 RE_Get_Nested_Sequence_Length
9098 ), Loc),
9099 Parameter_Associations =>
9100 New_List (
9101 New_Occurrence_Of (
9102 Any_Parameter, Loc),
9103 Make_Integer_Literal (Loc,
9104 Intval => J))))),
9105
9106 Right_Opnd =>
9107 Make_Integer_Literal (Loc, 1))))));
9108
9109 Append_To (Ranges,
9110 Make_Range (Loc,
9111 Low_Bound => Make_Identifier (Loc, Lnam),
9112 High_Bound => Make_Identifier (Loc, Hnam)));
9113
9114 Next_Index (Indx);
9115 end loop;
9116
9117 -- Now we have all the necessary bound information:
9118 -- apply the set of range constraints to the
9119 -- (unconstrained) nominal subtype of Res.
9120
9121 Initial_Counter_Value := Ndim;
9122 Res_Subtype_Indication := Make_Subtype_Indication (Loc,
9123 Subtype_Mark => Res_Subtype_Indication,
9124 Constraint =>
9125 Make_Index_Or_Discriminant_Constraint (Loc,
9126 Constraints => Ranges));
9127 end;
9128 end if;
9129
9130 Append_To (Decls,
9131 Make_Object_Declaration (Loc,
9132 Defining_Identifier => Res,
9133 Object_Definition => Res_Subtype_Indication));
9134 Set_Etype (Res, Typ);
9135
9136 Append_To (Decls,
9137 Make_Object_Declaration (Loc,
9138 Defining_Identifier => Counter,
9139 Object_Definition =>
9140 New_Occurrence_Of (RTE (RE_Unsigned_32), Loc),
9141 Expression =>
9142 Make_Integer_Literal (Loc, Initial_Counter_Value)));
9143
9144 Append_To (Decls,
9145 Make_Object_Declaration (Loc,
9146 Defining_Identifier => Component_TC,
9147 Constant_Present => True,
9148 Object_Definition =>
9149 New_Occurrence_Of (RTE (RE_TypeCode), Loc),
9150 Expression =>
9151 Build_TypeCode_Call (Loc,
9152 Component_Type (Typ), Decls)));
9153
9154 Append_From_Any_Array_Iterator
9155 (Stms, Any_Parameter, Counter);
9156
9157 Append_To (Stms,
9158 Make_Simple_Return_Statement (Loc,
9159 Expression => New_Occurrence_Of (Res, Loc)));
9160 end;
9161
9162 elsif Is_Integer_Type (Typ) or else Is_Unsigned_Type (Typ) then
9163 Append_To (Stms,
9164 Make_Simple_Return_Statement (Loc,
9165 Expression =>
9166 Unchecked_Convert_To (Typ,
9167 Build_From_Any_Call
9168 (Find_Numeric_Representation (Typ),
9169 New_Occurrence_Of (Any_Parameter, Loc),
9170 Decls))));
9171
9172 else
9173 Use_Opaque_Representation := True;
9174 end if;
9175
9176 if Use_Opaque_Representation then
9177 Assign_Opaque_From_Any (Loc,
9178 Stms => Stms,
9179 Typ => Typ,
9180 N => New_Occurrence_Of (Any_Parameter, Loc),
9181 Target => Empty);
9182 end if;
9183
9184 Decl :=
9185 Make_Subprogram_Body (Loc,
9186 Specification => Spec,
9187 Declarations => Decls,
9188 Handled_Statement_Sequence =>
9189 Make_Handled_Sequence_Of_Statements (Loc,
9190 Statements => Stms));
9191 end Build_From_Any_Function;
9192
9193 ---------------------------------
9194 -- Build_Get_Aggregate_Element --
9195 ---------------------------------
9196
9197 function Build_Get_Aggregate_Element
9198 (Loc : Source_Ptr;
9199 Any : Entity_Id;
9200 TC : Node_Id;
9201 Idx : Node_Id) return Node_Id
9202 is
9203 begin
9204 return Make_Function_Call (Loc,
9205 Name =>
9206 New_Occurrence_Of (RTE (RE_Get_Aggregate_Element), Loc),
9207 Parameter_Associations => New_List (
9208 New_Occurrence_Of (Any, Loc),
9209 TC,
9210 Idx));
9211 end Build_Get_Aggregate_Element;
9212
9213 ----------------------------------
9214 -- Build_Name_And_Repository_Id --
9215 ----------------------------------
9216
9217 procedure Build_Name_And_Repository_Id
9218 (E : Entity_Id;
9219 Name_Str : out String_Id;
9220 Repo_Id_Str : out String_Id)
9221 is
9222 begin
9223 Name_Str := Fully_Qualified_Name_String (E, Append_NUL => False);
9224 Start_String;
9225 Store_String_Chars ("DSA:");
9226 Store_String_Chars (Name_Str);
9227 Store_String_Chars (":1.0");
9228 Repo_Id_Str := End_String;
9229 end Build_Name_And_Repository_Id;
9230
9231 -----------------------
9232 -- Build_To_Any_Call --
9233 -----------------------
9234
9235 function Build_To_Any_Call
9236 (Loc : Source_Ptr;
9237 N : Node_Id;
9238 Decls : List_Id;
9239 Constrained : Boolean := False) return Node_Id
9240 is
9241 Typ : Entity_Id := Etype (N);
9242 U_Type : Entity_Id;
9243 C_Type : Entity_Id;
9244 Fnam : Entity_Id;
9245 Lib_RE : RE_Id := RE_Null;
9246
9247 begin
9248 -- If N is a selected component, then maybe its Etype has not been
9249 -- set yet: try to use Etype of the selector_name in that case.
9250
9251 if No (Typ) and then Nkind (N) = N_Selected_Component then
9252 Typ := Etype (Selector_Name (N));
9253 end if;
9254
9255 pragma Assert (Present (Typ));
9256
9257 -- Get full view for private type, completion for incomplete type
9258
9259 U_Type := Underlying_Type (Typ);
9260
9261 -- First simple case where the To_Any function is present in the
9262 -- type's TSS.
9263
9264 Fnam := Find_Inherited_TSS (U_Type, TSS_To_Any);
9265
9266 -- For the subtype representing a generic actual type, go to the
9267 -- actual type.
9268
9269 if Is_Generic_Actual_Subtype (U_Type) then
9270 U_Type := Underlying_Type (Base_Type (U_Type));
9271 end if;
9272
9273 -- For a standard subtype, go to the base type
9274
9275 if Sloc (U_Type) <= Standard_Location then
9276 U_Type := Base_Type (U_Type);
9277
9278 -- For a user subtype, go to first subtype
9279
9280 elsif Comes_From_Source (U_Type)
9281 and then Nkind (Declaration_Node (U_Type))
9282 = N_Subtype_Declaration
9283 then
9284 U_Type := First_Subtype (U_Type);
9285 end if;
9286
9287 if Present (Fnam) then
9288 null;
9289
9290 -- Check first for Boolean and Character. These are enumeration
9291 -- types, but we treat them specially, since they may require
9292 -- special handling in the transfer protocol. However, this
9293 -- special handling only applies if they have standard
9294 -- representation, otherwise they are treated like any other
9295 -- enumeration type.
9296
9297 elsif U_Type = Standard_Boolean then
9298 Lib_RE := RE_TA_B;
9299
9300 elsif U_Type = Standard_Character then
9301 Lib_RE := RE_TA_C;
9302
9303 elsif U_Type = Standard_Wide_Character then
9304 Lib_RE := RE_TA_WC;
9305
9306 elsif U_Type = Standard_Wide_Wide_Character then
9307 Lib_RE := RE_TA_WWC;
9308
9309 -- Floating point types
9310
9311 elsif U_Type = Standard_Short_Float then
9312 Lib_RE := RE_TA_SF;
9313
9314 elsif U_Type = Standard_Float then
9315 Lib_RE := RE_TA_F;
9316
9317 elsif U_Type = Standard_Long_Float then
9318 Lib_RE := RE_TA_LF;
9319
9320 elsif U_Type = Standard_Long_Long_Float then
9321 Lib_RE := RE_TA_LLF;
9322
9323 -- Integer types
9324
9325 elsif U_Type = RTE (RE_Integer_8) then
9326 Lib_RE := RE_TA_I8;
9327
9328 elsif U_Type = RTE (RE_Integer_16) then
9329 Lib_RE := RE_TA_I16;
9330
9331 elsif U_Type = RTE (RE_Integer_32) then
9332 Lib_RE := RE_TA_I32;
9333
9334 elsif U_Type = RTE (RE_Integer_64) then
9335 Lib_RE := RE_TA_I64;
9336
9337 -- Unsigned integer types
9338
9339 elsif U_Type = RTE (RE_Unsigned_8) then
9340 Lib_RE := RE_TA_U8;
9341
9342 elsif U_Type = RTE (RE_Unsigned_16) then
9343 Lib_RE := RE_TA_U16;
9344
9345 elsif U_Type = RTE (RE_Unsigned_32) then
9346 Lib_RE := RE_TA_U32;
9347
9348 elsif U_Type = RTE (RE_Unsigned_64) then
9349 Lib_RE := RE_TA_U64;
9350
9351 elsif Is_RTE (U_Type, RE_Unbounded_String) then
9352 Lib_RE := RE_TA_String;
9353
9354 -- Special DSA types
9355
9356 elsif Is_RTE (U_Type, RE_Any_Container_Ptr) then
9357 Lib_RE := RE_TA_A;
9358 U_Type := Typ;
9359
9360 elsif U_Type = Underlying_Type (RTE (RE_TypeCode)) then
9361
9362 -- No corresponding FA_TC ???
9363
9364 Lib_RE := RE_TA_TC;
9365
9366 -- Other (non-primitive) types
9367
9368 else
9369 declare
9370 Decl : Entity_Id;
9371 begin
9372 Build_To_Any_Function (Loc, U_Type, Decl, Fnam);
9373 Append_To (Decls, Decl);
9374 end;
9375 end if;
9376
9377 -- Call the function
9378
9379 if Lib_RE /= RE_Null then
9380 pragma Assert (No (Fnam));
9381 Fnam := RTE (Lib_RE);
9382 end if;
9383
9384 -- If Fnam is already analyzed, find the proper expected type,
9385 -- else we have a newly constructed To_Any function and we know
9386 -- that the expected type of its parameter is U_Type.
9387
9388 if Ekind (Fnam) = E_Function
9389 and then Present (First_Formal (Fnam))
9390 then
9391 C_Type := Etype (First_Formal (Fnam));
9392 else
9393 C_Type := U_Type;
9394 end if;
9395
9396 declare
9397 Params : constant List_Id :=
9398 New_List (OK_Convert_To (C_Type, N));
9399 begin
9400 if Is_Limited_Type (C_Type) then
9401 Append_To (Params,
9402 New_Occurrence_Of (Boolean_Literals (Constrained), Loc));
9403 end if;
9404
9405 return
9406 Make_Function_Call (Loc,
9407 Name => New_Occurrence_Of (Fnam, Loc),
9408 Parameter_Associations => Params);
9409 end;
9410 end Build_To_Any_Call;
9411
9412 ---------------------------
9413 -- Build_To_Any_Function --
9414 ---------------------------
9415
9416 procedure Build_To_Any_Function
9417 (Loc : Source_Ptr;
9418 Typ : Entity_Id;
9419 Decl : out Node_Id;
9420 Fnam : out Entity_Id)
9421 is
9422 Spec : Node_Id;
9423 Params : List_Id;
9424 Decls : List_Id;
9425 Stms : List_Id;
9426
9427 Expr_Formal : Entity_Id;
9428 Cstr_Formal : Entity_Id := Empty; -- initialize to prevent warning
9429 Any : Entity_Id;
9430 Result_TC : Node_Id;
9431
9432 Any_Decl : Node_Id;
9433
9434 Use_Opaque_Representation : Boolean;
9435 -- When True, use stream attributes and represent type as an
9436 -- opaque sequence of bytes.
9437
9438 Real_Rep : Node_Id;
9439
9440 begin
9441 -- For a derived type, we can't go past the base type (to the
9442 -- parent type) here, because that would cause the attribute's
9443 -- formal parameter to have the wrong type; hence the Base_Type
9444 -- check here.
9445
9446 if Is_Itype (Typ) and then Typ /= Base_Type (Typ) then
9447 Build_To_Any_Function
9448 (Loc => Loc,
9449 Typ => Etype (Typ),
9450 Decl => Decl,
9451 Fnam => Fnam);
9452 return;
9453 end if;
9454
9455 Decls := New_List;
9456 Stms := New_List;
9457
9458 Any := Make_Defining_Identifier (Loc, Name_A);
9459 Result_TC := Build_TypeCode_Call (Loc, Typ, Decls);
9460
9461 Fnam := Make_Helper_Function_Name (Loc, Typ, Name_To_Any);
9462
9463 Expr_Formal := Make_Defining_Identifier (Loc, Name_E);
9464 Params := New_List (
9465 Make_Parameter_Specification (Loc,
9466 Defining_Identifier => Expr_Formal,
9467 Parameter_Type => New_Occurrence_Of (Typ, Loc)));
9468 Set_Etype (Expr_Formal, Typ);
9469
9470 if Is_Limited_Type (Typ) then
9471 Cstr_Formal := Make_Defining_Identifier (Loc, Name_C);
9472 Append_To (Params,
9473 Make_Parameter_Specification (Loc,
9474 Defining_Identifier => Cstr_Formal,
9475 Parameter_Type =>
9476 New_Occurrence_Of (Standard_Boolean, Loc)));
9477 end if;
9478
9479 Spec :=
9480 Make_Function_Specification (Loc,
9481 Defining_Unit_Name => Fnam,
9482 Parameter_Specifications => Params,
9483 Result_Definition =>
9484 New_Occurrence_Of (RTE (RE_Any), Loc));
9485
9486 Any_Decl :=
9487 Make_Object_Declaration (Loc,
9488 Defining_Identifier => Any,
9489 Object_Definition => New_Occurrence_Of (RTE (RE_Any), Loc));
9490
9491 Use_Opaque_Representation := False;
9492
9493 if Has_Stream_Attribute_Definition
9494 (Typ, TSS_Stream_Output, Real_Rep, At_Any_Place => True)
9495 or else
9496 Has_Stream_Attribute_Definition
9497 (Typ, TSS_Stream_Write, Real_Rep, At_Any_Place => True)
9498 then
9499 -- If user-defined stream attributes are specified for this
9500 -- type, use them and transmit data as an opaque sequence of
9501 -- stream elements.
9502
9503 Use_Opaque_Representation := True;
9504
9505 elsif Is_Derived_Type (Typ) and then not Is_Tagged_Type (Typ) then
9506
9507 -- Untagged derived type: convert to root type
9508
9509 declare
9510 Rt_Type : constant Entity_Id := Root_Type (Typ);
9511 Expr : constant Node_Id :=
9512 OK_Convert_To
9513 (Rt_Type,
9514 New_Occurrence_Of (Expr_Formal, Loc));
9515 begin
9516 Set_Expression (Any_Decl,
9517 Build_To_Any_Call (Loc, Expr, Decls));
9518 end;
9519
9520 elsif Is_Record_Type (Typ) and then not Is_Tagged_Type (Typ) then
9521
9522 -- Untagged record type
9523
9524 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
9525 declare
9526 Rt_Type : constant Entity_Id := Etype (Typ);
9527 Expr : constant Node_Id :=
9528 OK_Convert_To (Rt_Type,
9529 New_Occurrence_Of (Expr_Formal, Loc));
9530
9531 begin
9532 Set_Expression
9533 (Any_Decl, Build_To_Any_Call (Loc, Expr, Decls));
9534 end;
9535
9536 -- Comment needed here (and label on declare block ???)
9537
9538 else
9539 declare
9540 Disc : Entity_Id := Empty;
9541 Rdef : constant Node_Id :=
9542 Type_Definition (Declaration_Node (Typ));
9543 Counter : Nat := 0;
9544 Elements : constant List_Id := New_List;
9545
9546 procedure TA_Rec_Add_Process_Element
9547 (Stmts : List_Id;
9548 Container : Node_Or_Entity_Id;
9549 Counter : in out Nat;
9550 Rec : Entity_Id;
9551 Field : Node_Id);
9552 -- Processing routine for traversal below
9553
9554 procedure TA_Append_Record_Traversal is
9555 new Append_Record_Traversal
9556 (Rec => Expr_Formal,
9557 Add_Process_Element => TA_Rec_Add_Process_Element);
9558
9559 --------------------------------
9560 -- TA_Rec_Add_Process_Element --
9561 --------------------------------
9562
9563 procedure TA_Rec_Add_Process_Element
9564 (Stmts : List_Id;
9565 Container : Node_Or_Entity_Id;
9566 Counter : in out Nat;
9567 Rec : Entity_Id;
9568 Field : Node_Id)
9569 is
9570 Field_Ref : Node_Id;
9571
9572 begin
9573 if Nkind (Field) = N_Defining_Identifier then
9574
9575 -- A regular component
9576
9577 Field_Ref := Make_Selected_Component (Loc,
9578 Prefix => New_Occurrence_Of (Rec, Loc),
9579 Selector_Name => New_Occurrence_Of (Field, Loc));
9580 Set_Etype (Field_Ref, Etype (Field));
9581
9582 Append_To (Stmts,
9583 Make_Procedure_Call_Statement (Loc,
9584 Name =>
9585 New_Occurrence_Of (
9586 RTE (RE_Add_Aggregate_Element), Loc),
9587 Parameter_Associations => New_List (
9588 New_Occurrence_Of (Container, Loc),
9589 Build_To_Any_Call (Loc, Field_Ref, Decls))));
9590
9591 else
9592 -- A variant part
9593
9594 Variant_Part : declare
9595 Variant : Node_Id;
9596 Struct_Counter : Nat := 0;
9597
9598 Block_Decls : constant List_Id := New_List;
9599 Block_Stmts : constant List_Id := New_List;
9600 VP_Stmts : List_Id;
9601
9602 Alt_List : constant List_Id := New_List;
9603 Choice_List : List_Id;
9604
9605 Union_Any : constant Entity_Id :=
9606 Make_Temporary (Loc, 'V');
9607
9608 Struct_Any : constant Entity_Id :=
9609 Make_Temporary (Loc, 'S');
9610
9611 function Make_Discriminant_Reference
9612 return Node_Id;
9613 -- Build reference to the discriminant for this
9614 -- variant part.
9615
9616 ---------------------------------
9617 -- Make_Discriminant_Reference --
9618 ---------------------------------
9619
9620 function Make_Discriminant_Reference
9621 return Node_Id
9622 is
9623 Nod : constant Node_Id :=
9624 Make_Selected_Component (Loc,
9625 Prefix => Rec,
9626 Selector_Name =>
9627 Chars (Name (Field)));
9628 begin
9629 Set_Etype (Nod, Etype (Name (Field)));
9630 return Nod;
9631 end Make_Discriminant_Reference;
9632
9633 -- Start of processing for Variant_Part
9634
9635 begin
9636 Append_To (Stmts,
9637 Make_Block_Statement (Loc,
9638 Declarations =>
9639 Block_Decls,
9640 Handled_Statement_Sequence =>
9641 Make_Handled_Sequence_Of_Statements (Loc,
9642 Statements => Block_Stmts)));
9643
9644 -- Declare variant part aggregate (Union_Any).
9645 -- Knowing the position of this VP in the
9646 -- variant record, we can fetch the VP typecode
9647 -- from Container.
9648
9649 Append_To (Block_Decls,
9650 Make_Object_Declaration (Loc,
9651 Defining_Identifier => Union_Any,
9652 Object_Definition =>
9653 New_Occurrence_Of (RTE (RE_Any), Loc),
9654 Expression =>
9655 Make_Function_Call (Loc,
9656 Name => New_Occurrence_Of (
9657 RTE (RE_Create_Any), Loc),
9658 Parameter_Associations => New_List (
9659 Make_Function_Call (Loc,
9660 Name =>
9661 New_Occurrence_Of (
9662 RTE (RE_Any_Member_Type), Loc),
9663 Parameter_Associations => New_List (
9664 New_Occurrence_Of (Container, Loc),
9665 Make_Integer_Literal (Loc,
9666 Counter)))))));
9667
9668 -- Declare inner struct aggregate (which
9669 -- contains the components of this VP).
9670
9671 Append_To (Block_Decls,
9672 Make_Object_Declaration (Loc,
9673 Defining_Identifier => Struct_Any,
9674 Object_Definition =>
9675 New_Occurrence_Of (RTE (RE_Any), Loc),
9676 Expression =>
9677 Make_Function_Call (Loc,
9678 Name => New_Occurrence_Of (
9679 RTE (RE_Create_Any), Loc),
9680 Parameter_Associations => New_List (
9681 Make_Function_Call (Loc,
9682 Name =>
9683 New_Occurrence_Of (
9684 RTE (RE_Any_Member_Type), Loc),
9685 Parameter_Associations => New_List (
9686 New_Occurrence_Of (Union_Any, Loc),
9687 Make_Integer_Literal (Loc,
9688 Uint_1)))))));
9689
9690 -- Build case statement
9691
9692 Append_To (Block_Stmts,
9693 Make_Case_Statement (Loc,
9694 Expression => Make_Discriminant_Reference,
9695 Alternatives => Alt_List));
9696
9697 Variant := First_Non_Pragma (Variants (Field));
9698 while Present (Variant) loop
9699 Choice_List := New_Copy_List_Tree
9700 (Discrete_Choices (Variant));
9701
9702 VP_Stmts := New_List;
9703
9704 -- Append discriminant val to union aggregate
9705
9706 Append_To (VP_Stmts,
9707 Make_Procedure_Call_Statement (Loc,
9708 Name =>
9709 New_Occurrence_Of (
9710 RTE (RE_Add_Aggregate_Element), Loc),
9711 Parameter_Associations => New_List (
9712 New_Occurrence_Of (Union_Any, Loc),
9713 Build_To_Any_Call
9714 (Loc,
9715 Make_Discriminant_Reference,
9716 Block_Decls))));
9717
9718 -- Populate inner struct aggregate
9719
9720 -- Struct_Counter should be reset before
9721 -- handling a variant part. Indeed only one
9722 -- of the case statement alternatives will be
9723 -- executed at run time, so the counter must
9724 -- start at 0 for every case statement.
9725
9726 Struct_Counter := 0;
9727
9728 TA_Append_Record_Traversal
9729 (Stmts => VP_Stmts,
9730 Clist => Component_List (Variant),
9731 Container => Struct_Any,
9732 Counter => Struct_Counter);
9733
9734 -- Append inner struct to union aggregate
9735
9736 Append_To (VP_Stmts,
9737 Make_Procedure_Call_Statement (Loc,
9738 Name =>
9739 New_Occurrence_Of
9740 (RTE (RE_Add_Aggregate_Element), Loc),
9741 Parameter_Associations => New_List (
9742 New_Occurrence_Of (Union_Any, Loc),
9743 New_Occurrence_Of (Struct_Any, Loc))));
9744
9745 -- Append union to outer aggregate
9746
9747 Append_To (VP_Stmts,
9748 Make_Procedure_Call_Statement (Loc,
9749 Name =>
9750 New_Occurrence_Of
9751 (RTE (RE_Add_Aggregate_Element), Loc),
9752 Parameter_Associations => New_List (
9753 New_Occurrence_Of (Container, Loc),
9754 New_Occurrence_Of
9755 (Union_Any, Loc))));
9756
9757 Append_To (Alt_List,
9758 Make_Case_Statement_Alternative (Loc,
9759 Discrete_Choices => Choice_List,
9760 Statements => VP_Stmts));
9761
9762 Next_Non_Pragma (Variant);
9763 end loop;
9764 end Variant_Part;
9765 end if;
9766
9767 Counter := Counter + 1;
9768 end TA_Rec_Add_Process_Element;
9769
9770 begin
9771 -- Records are encoded in a TC_STRUCT aggregate:
9772
9773 -- -- Outer aggregate (TC_STRUCT)
9774 -- | [discriminant1]
9775 -- | [discriminant2]
9776 -- | ...
9777 -- |
9778 -- | [component1]
9779 -- | [component2]
9780 -- | ...
9781
9782 -- A component can be a common component or variant part
9783
9784 -- A variant part is encoded as a TC_UNION aggregate:
9785
9786 -- -- Variant Part Aggregate (TC_UNION)
9787 -- | [discriminant choice for this Variant Part]
9788 -- |
9789 -- | -- Inner struct (TC_STRUCT)
9790 -- | | [component1]
9791 -- | | [component2]
9792 -- | | ...
9793
9794 -- Let's start by building the outer aggregate. First we
9795 -- construct Elements array containing all discriminants.
9796
9797 if Has_Discriminants (Typ) then
9798 Disc := First_Discriminant (Typ);
9799 while Present (Disc) loop
9800 declare
9801 Discriminant : constant Entity_Id :=
9802 Make_Selected_Component (Loc,
9803 Prefix => Expr_Formal,
9804 Selector_Name => Chars (Disc));
9805 begin
9806 Set_Etype (Discriminant, Etype (Disc));
9807 Append_To (Elements,
9808 Make_Component_Association (Loc,
9809 Choices => New_List (
9810 Make_Integer_Literal (Loc, Counter)),
9811 Expression =>
9812 Build_To_Any_Call (Loc,
9813 Discriminant, Decls)));
9814 end;
9815
9816 Counter := Counter + 1;
9817 Next_Discriminant (Disc);
9818 end loop;
9819
9820 else
9821 -- If there are no discriminants, we declare an empty
9822 -- Elements array.
9823
9824 declare
9825 Dummy_Any : constant Entity_Id :=
9826 Make_Temporary (Loc, 'A');
9827
9828 begin
9829 Append_To (Decls,
9830 Make_Object_Declaration (Loc,
9831 Defining_Identifier => Dummy_Any,
9832 Object_Definition =>
9833 New_Occurrence_Of (RTE (RE_Any), Loc)));
9834
9835 Append_To (Elements,
9836 Make_Component_Association (Loc,
9837 Choices => New_List (
9838 Make_Range (Loc,
9839 Low_Bound =>
9840 Make_Integer_Literal (Loc, 1),
9841 High_Bound =>
9842 Make_Integer_Literal (Loc, 0))),
9843 Expression =>
9844 New_Occurrence_Of (Dummy_Any, Loc)));
9845 end;
9846 end if;
9847
9848 -- We build the result aggregate with discriminants
9849 -- as the first elements.
9850
9851 Set_Expression (Any_Decl,
9852 Make_Function_Call (Loc,
9853 Name => New_Occurrence_Of
9854 (RTE (RE_Any_Aggregate_Build), Loc),
9855 Parameter_Associations => New_List (
9856 Result_TC,
9857 Make_Aggregate (Loc,
9858 Component_Associations => Elements))));
9859 Result_TC := Empty;
9860
9861 -- Then we append all the components to the result
9862 -- aggregate.
9863
9864 TA_Append_Record_Traversal (Stms,
9865 Clist => Component_List (Rdef),
9866 Container => Any,
9867 Counter => Counter);
9868 end;
9869 end if;
9870
9871 elsif Is_Array_Type (Typ) then
9872
9873 -- Constrained and unconstrained array types
9874
9875 declare
9876 Constrained : constant Boolean :=
9877 not Transmit_As_Unconstrained (Typ);
9878
9879 procedure TA_Ary_Add_Process_Element
9880 (Stmts : List_Id;
9881 Any : Entity_Id;
9882 Counter : Entity_Id;
9883 Datum : Node_Id);
9884
9885 --------------------------------
9886 -- TA_Ary_Add_Process_Element --
9887 --------------------------------
9888
9889 procedure TA_Ary_Add_Process_Element
9890 (Stmts : List_Id;
9891 Any : Entity_Id;
9892 Counter : Entity_Id;
9893 Datum : Node_Id)
9894 is
9895 pragma Unreferenced (Counter);
9896
9897 Element_Any : Node_Id;
9898
9899 begin
9900 if Etype (Datum) = RTE (RE_Any) then
9901 Element_Any := Datum;
9902 else
9903 Element_Any := Build_To_Any_Call (Loc, Datum, Decls);
9904 end if;
9905
9906 Append_To (Stmts,
9907 Make_Procedure_Call_Statement (Loc,
9908 Name => New_Occurrence_Of (
9909 RTE (RE_Add_Aggregate_Element), Loc),
9910 Parameter_Associations => New_List (
9911 New_Occurrence_Of (Any, Loc),
9912 Element_Any)));
9913 end TA_Ary_Add_Process_Element;
9914
9915 procedure Append_To_Any_Array_Iterator is
9916 new Append_Array_Traversal (
9917 Subprogram => Fnam,
9918 Arry => Expr_Formal,
9919 Indexes => New_List,
9920 Add_Process_Element => TA_Ary_Add_Process_Element);
9921
9922 Index : Node_Id;
9923
9924 begin
9925 Set_Expression (Any_Decl,
9926 Make_Function_Call (Loc,
9927 Name =>
9928 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
9929 Parameter_Associations => New_List (Result_TC)));
9930 Result_TC := Empty;
9931
9932 if not Constrained then
9933 Index := First_Index (Typ);
9934 for J in 1 .. Number_Dimensions (Typ) loop
9935 Append_To (Stms,
9936 Make_Procedure_Call_Statement (Loc,
9937 Name =>
9938 New_Occurrence_Of
9939 (RTE (RE_Add_Aggregate_Element), Loc),
9940 Parameter_Associations => New_List (
9941 New_Occurrence_Of (Any, Loc),
9942 Build_To_Any_Call (Loc,
9943 OK_Convert_To (Etype (Index),
9944 Make_Attribute_Reference (Loc,
9945 Prefix =>
9946 New_Occurrence_Of (Expr_Formal, Loc),
9947 Attribute_Name => Name_First,
9948 Expressions => New_List (
9949 Make_Integer_Literal (Loc, J)))),
9950 Decls))));
9951 Next_Index (Index);
9952 end loop;
9953 end if;
9954
9955 Append_To_Any_Array_Iterator (Stms, Any);
9956 end;
9957
9958 elsif Is_Integer_Type (Typ) or else Is_Unsigned_Type (Typ) then
9959
9960 -- Integer types
9961
9962 Set_Expression (Any_Decl,
9963 Build_To_Any_Call (Loc,
9964 OK_Convert_To (
9965 Find_Numeric_Representation (Typ),
9966 New_Occurrence_Of (Expr_Formal, Loc)),
9967 Decls));
9968
9969 else
9970 -- Default case, including tagged types: opaque representation
9971
9972 Use_Opaque_Representation := True;
9973 end if;
9974
9975 if Use_Opaque_Representation then
9976 declare
9977 Strm : constant Entity_Id := Make_Temporary (Loc, 'S');
9978 -- Stream used to store data representation produced by
9979 -- stream attribute.
9980
9981 begin
9982 -- Generate:
9983 -- Strm : aliased Buffer_Stream_Type;
9984
9985 Append_To (Decls,
9986 Make_Object_Declaration (Loc,
9987 Defining_Identifier => Strm,
9988 Aliased_Present => True,
9989 Object_Definition =>
9990 New_Occurrence_Of (RTE (RE_Buffer_Stream_Type), Loc)));
9991
9992 -- Generate:
9993 -- T'Output (Strm'Access, E);
9994 -- or
9995 -- T'Write (Strm'Access, E);
9996 -- depending on whether to transmit as unconstrained.
9997
9998 -- For limited types, select at run time depending on
9999 -- Constrained parameter.
10000
10001 declare
10002 function Stream_Call (Attr : Name_Id) return Node_Id;
10003 -- Return a call to the named attribute
10004
10005 -----------------
10006 -- Stream_Call --
10007 -----------------
10008
10009 function Stream_Call (Attr : Name_Id) return Node_Id is
10010 begin
10011 return Make_Attribute_Reference (Loc,
10012 Prefix =>
10013 New_Occurrence_Of (Typ, Loc),
10014 Attribute_Name => Attr,
10015 Expressions => New_List (
10016 Make_Attribute_Reference (Loc,
10017 Prefix =>
10018 New_Occurrence_Of (Strm, Loc),
10019 Attribute_Name => Name_Access),
10020 New_Occurrence_Of (Expr_Formal, Loc)));
10021
10022 end Stream_Call;
10023
10024 begin
10025 if Is_Limited_Type (Typ) then
10026 Append_To (Stms,
10027 Make_Implicit_If_Statement (Typ,
10028 Condition =>
10029 New_Occurrence_Of (Cstr_Formal, Loc),
10030 Then_Statements => New_List (
10031 Stream_Call (Name_Write)),
10032 Else_Statements => New_List (
10033 Stream_Call (Name_Output))));
10034
10035 elsif Transmit_As_Unconstrained (Typ) then
10036 Append_To (Stms, Stream_Call (Name_Output));
10037
10038 else
10039 Append_To (Stms, Stream_Call (Name_Write));
10040 end if;
10041 end;
10042
10043 -- Generate:
10044 -- BS_To_Any (Strm, A);
10045
10046 Append_To (Stms,
10047 Make_Procedure_Call_Statement (Loc,
10048 Name =>
10049 New_Occurrence_Of (RTE (RE_BS_To_Any), Loc),
10050 Parameter_Associations => New_List (
10051 New_Occurrence_Of (Strm, Loc),
10052 New_Occurrence_Of (Any, Loc))));
10053
10054 -- Generate:
10055 -- Release_Buffer (Strm);
10056
10057 Append_To (Stms,
10058 Make_Procedure_Call_Statement (Loc,
10059 Name =>
10060 New_Occurrence_Of (RTE (RE_Release_Buffer), Loc),
10061 Parameter_Associations => New_List (
10062 New_Occurrence_Of (Strm, Loc))));
10063 end;
10064 end if;
10065
10066 Append_To (Decls, Any_Decl);
10067
10068 if Present (Result_TC) then
10069 Append_To (Stms,
10070 Make_Procedure_Call_Statement (Loc,
10071 Name =>
10072 New_Occurrence_Of (RTE (RE_Set_TC), Loc),
10073 Parameter_Associations => New_List (
10074 New_Occurrence_Of (Any, Loc),
10075 Result_TC)));
10076 end if;
10077
10078 Append_To (Stms,
10079 Make_Simple_Return_Statement (Loc,
10080 Expression => New_Occurrence_Of (Any, Loc)));
10081
10082 Decl :=
10083 Make_Subprogram_Body (Loc,
10084 Specification => Spec,
10085 Declarations => Decls,
10086 Handled_Statement_Sequence =>
10087 Make_Handled_Sequence_Of_Statements (Loc,
10088 Statements => Stms));
10089 end Build_To_Any_Function;
10090
10091 -------------------------
10092 -- Build_TypeCode_Call --
10093 -------------------------
10094
10095 function Build_TypeCode_Call
10096 (Loc : Source_Ptr;
10097 Typ : Entity_Id;
10098 Decls : List_Id) return Node_Id
10099 is
10100 U_Type : Entity_Id := Underlying_Type (Typ);
10101 -- The full view, if Typ is private; the completion,
10102 -- if Typ is incomplete.
10103
10104 Fnam : Entity_Id;
10105 Lib_RE : RE_Id := RE_Null;
10106 Expr : Node_Id;
10107
10108 begin
10109 -- Special case System.PolyORB.Interface.Any: its primitives have
10110 -- not been set yet, so can't call Find_Inherited_TSS.
10111
10112 if Typ = RTE (RE_Any) then
10113 Fnam := RTE (RE_TC_A);
10114
10115 else
10116 -- First simple case where the TypeCode is present
10117 -- in the type's TSS.
10118
10119 Fnam := Find_Inherited_TSS (U_Type, TSS_TypeCode);
10120 end if;
10121
10122 -- For the subtype representing a generic actual type, go to the
10123 -- actual type.
10124
10125 if Is_Generic_Actual_Subtype (U_Type) then
10126 U_Type := Underlying_Type (Base_Type (U_Type));
10127 end if;
10128
10129 -- For a standard subtype, go to the base type
10130
10131 if Sloc (U_Type) <= Standard_Location then
10132 U_Type := Base_Type (U_Type);
10133
10134 -- For a user subtype, go to first subtype
10135
10136 elsif Comes_From_Source (U_Type)
10137 and then Nkind (Declaration_Node (U_Type))
10138 = N_Subtype_Declaration
10139 then
10140 U_Type := First_Subtype (U_Type);
10141 end if;
10142
10143 if No (Fnam) then
10144 if U_Type = Standard_Boolean then
10145 Lib_RE := RE_TC_B;
10146
10147 elsif U_Type = Standard_Character then
10148 Lib_RE := RE_TC_C;
10149
10150 elsif U_Type = Standard_Wide_Character then
10151 Lib_RE := RE_TC_WC;
10152
10153 elsif U_Type = Standard_Wide_Wide_Character then
10154 Lib_RE := RE_TC_WWC;
10155
10156 -- Floating point types
10157
10158 elsif U_Type = Standard_Short_Float then
10159 Lib_RE := RE_TC_SF;
10160
10161 elsif U_Type = Standard_Float then
10162 Lib_RE := RE_TC_F;
10163
10164 elsif U_Type = Standard_Long_Float then
10165 Lib_RE := RE_TC_LF;
10166
10167 elsif U_Type = Standard_Long_Long_Float then
10168 Lib_RE := RE_TC_LLF;
10169
10170 -- Integer types (walk back to the base type)
10171
10172 elsif U_Type = RTE (RE_Integer_8) then
10173 Lib_RE := RE_TC_I8;
10174
10175 elsif U_Type = RTE (RE_Integer_16) then
10176 Lib_RE := RE_TC_I16;
10177
10178 elsif U_Type = RTE (RE_Integer_32) then
10179 Lib_RE := RE_TC_I32;
10180
10181 elsif U_Type = RTE (RE_Integer_64) then
10182 Lib_RE := RE_TC_I64;
10183
10184 -- Unsigned integer types
10185
10186 elsif U_Type = RTE (RE_Unsigned_8) then
10187 Lib_RE := RE_TC_U8;
10188
10189 elsif U_Type = RTE (RE_Unsigned_16) then
10190 Lib_RE := RE_TC_U16;
10191
10192 elsif U_Type = RTE (RE_Unsigned_32) then
10193 Lib_RE := RE_TC_U32;
10194
10195 elsif U_Type = RTE (RE_Unsigned_64) then
10196 Lib_RE := RE_TC_U64;
10197
10198 elsif Is_RTE (U_Type, RE_Unbounded_String) then
10199 Lib_RE := RE_TC_String;
10200
10201 -- Special DSA types
10202
10203 elsif Is_RTE (U_Type, RE_Any_Container_Ptr) then
10204 Lib_RE := RE_TC_A;
10205
10206 -- Other (non-primitive) types
10207
10208 else
10209 declare
10210 Decl : Entity_Id;
10211 begin
10212 Build_TypeCode_Function (Loc, U_Type, Decl, Fnam);
10213 Append_To (Decls, Decl);
10214 end;
10215 end if;
10216
10217 if Lib_RE /= RE_Null then
10218 Fnam := RTE (Lib_RE);
10219 end if;
10220 end if;
10221
10222 -- Call the function
10223
10224 Expr :=
10225 Make_Function_Call (Loc, Name => New_Occurrence_Of (Fnam, Loc));
10226
10227 -- Allow Expr to be used as arg to Build_To_Any_Call immediately
10228
10229 Set_Etype (Expr, RTE (RE_TypeCode));
10230
10231 return Expr;
10232 end Build_TypeCode_Call;
10233
10234 -----------------------------
10235 -- Build_TypeCode_Function --
10236 -----------------------------
10237
10238 procedure Build_TypeCode_Function
10239 (Loc : Source_Ptr;
10240 Typ : Entity_Id;
10241 Decl : out Node_Id;
10242 Fnam : out Entity_Id)
10243 is
10244 Spec : Node_Id;
10245 Decls : constant List_Id := New_List;
10246 Stms : constant List_Id := New_List;
10247
10248 TCNam : constant Entity_Id :=
10249 Make_Helper_Function_Name (Loc, Typ, Name_TypeCode);
10250
10251 Parameters : List_Id;
10252
10253 procedure Add_String_Parameter
10254 (S : String_Id;
10255 Parameter_List : List_Id);
10256 -- Add a literal for S to Parameters
10257
10258 procedure Add_TypeCode_Parameter
10259 (TC_Node : Node_Id;
10260 Parameter_List : List_Id);
10261 -- Add the typecode for Typ to Parameters
10262
10263 procedure Add_Long_Parameter
10264 (Expr_Node : Node_Id;
10265 Parameter_List : List_Id);
10266 -- Add a signed long integer expression to Parameters
10267
10268 procedure Initialize_Parameter_List
10269 (Name_String : String_Id;
10270 Repo_Id_String : String_Id;
10271 Parameter_List : out List_Id);
10272 -- Return a list that contains the first two parameters
10273 -- for a parameterized typecode: name and repository id.
10274
10275 function Make_Constructed_TypeCode
10276 (Kind : Entity_Id;
10277 Parameters : List_Id) return Node_Id;
10278 -- Call Build_Complex_TC with the given kind and parameters
10279
10280 procedure Return_Constructed_TypeCode (Kind : Entity_Id);
10281 -- Make a return statement that calls Build_Complex_TC with the
10282 -- given typecode kind, and the constructed parameters list.
10283
10284 procedure Return_Alias_TypeCode (Base_TypeCode : Node_Id);
10285 -- Return a typecode that is a TC_Alias for the given typecode
10286
10287 --------------------------
10288 -- Add_String_Parameter --
10289 --------------------------
10290
10291 procedure Add_String_Parameter
10292 (S : String_Id;
10293 Parameter_List : List_Id)
10294 is
10295 begin
10296 Append_To (Parameter_List,
10297 Make_Function_Call (Loc,
10298 Name => New_Occurrence_Of (RTE (RE_TA_Std_String), Loc),
10299 Parameter_Associations => New_List (
10300 Make_String_Literal (Loc, S))));
10301 end Add_String_Parameter;
10302
10303 ----------------------------
10304 -- Add_TypeCode_Parameter --
10305 ----------------------------
10306
10307 procedure Add_TypeCode_Parameter
10308 (TC_Node : Node_Id;
10309 Parameter_List : List_Id)
10310 is
10311 begin
10312 Append_To (Parameter_List,
10313 Make_Function_Call (Loc,
10314 Name => New_Occurrence_Of (RTE (RE_TA_TC), Loc),
10315 Parameter_Associations => New_List (TC_Node)));
10316 end Add_TypeCode_Parameter;
10317
10318 ------------------------
10319 -- Add_Long_Parameter --
10320 ------------------------
10321
10322 procedure Add_Long_Parameter
10323 (Expr_Node : Node_Id;
10324 Parameter_List : List_Id)
10325 is
10326 begin
10327 Append_To (Parameter_List,
10328 Make_Function_Call (Loc,
10329 Name =>
10330 New_Occurrence_Of (RTE (RE_TA_I32), Loc),
10331 Parameter_Associations => New_List (Expr_Node)));
10332 end Add_Long_Parameter;
10333
10334 -------------------------------
10335 -- Initialize_Parameter_List --
10336 -------------------------------
10337
10338 procedure Initialize_Parameter_List
10339 (Name_String : String_Id;
10340 Repo_Id_String : String_Id;
10341 Parameter_List : out List_Id)
10342 is
10343 begin
10344 Parameter_List := New_List;
10345 Add_String_Parameter (Name_String, Parameter_List);
10346 Add_String_Parameter (Repo_Id_String, Parameter_List);
10347 end Initialize_Parameter_List;
10348
10349 ---------------------------
10350 -- Return_Alias_TypeCode --
10351 ---------------------------
10352
10353 procedure Return_Alias_TypeCode (Base_TypeCode : Node_Id) is
10354 begin
10355 Add_TypeCode_Parameter (Base_TypeCode, Parameters);
10356 Return_Constructed_TypeCode (RTE (RE_Tk_Alias));
10357 end Return_Alias_TypeCode;
10358
10359 -------------------------------
10360 -- Make_Constructed_TypeCode --
10361 -------------------------------
10362
10363 function Make_Constructed_TypeCode
10364 (Kind : Entity_Id;
10365 Parameters : List_Id) return Node_Id
10366 is
10367 Constructed_TC : constant Node_Id :=
10368 Make_Function_Call (Loc,
10369 Name =>
10370 New_Occurrence_Of (RTE (RE_Build_Complex_TC), Loc),
10371 Parameter_Associations => New_List (
10372 New_Occurrence_Of (Kind, Loc),
10373 Make_Aggregate (Loc,
10374 Expressions => Parameters)));
10375 begin
10376 Set_Etype (Constructed_TC, RTE (RE_TypeCode));
10377 return Constructed_TC;
10378 end Make_Constructed_TypeCode;
10379
10380 ---------------------------------
10381 -- Return_Constructed_TypeCode --
10382 ---------------------------------
10383
10384 procedure Return_Constructed_TypeCode (Kind : Entity_Id) is
10385 begin
10386 Append_To (Stms,
10387 Make_Simple_Return_Statement (Loc,
10388 Expression =>
10389 Make_Constructed_TypeCode (Kind, Parameters)));
10390 end Return_Constructed_TypeCode;
10391
10392 ------------------
10393 -- Record types --
10394 ------------------
10395
10396 procedure TC_Rec_Add_Process_Element
10397 (Params : List_Id;
10398 Any : Entity_Id;
10399 Counter : in out Nat;
10400 Rec : Entity_Id;
10401 Field : Node_Id);
10402
10403 procedure TC_Append_Record_Traversal is
10404 new Append_Record_Traversal (
10405 Rec => Empty,
10406 Add_Process_Element => TC_Rec_Add_Process_Element);
10407
10408 --------------------------------
10409 -- TC_Rec_Add_Process_Element --
10410 --------------------------------
10411
10412 procedure TC_Rec_Add_Process_Element
10413 (Params : List_Id;
10414 Any : Entity_Id;
10415 Counter : in out Nat;
10416 Rec : Entity_Id;
10417 Field : Node_Id)
10418 is
10419 pragma Unreferenced (Any, Counter, Rec);
10420
10421 begin
10422 if Nkind (Field) = N_Defining_Identifier then
10423
10424 -- A regular component
10425
10426 Add_TypeCode_Parameter
10427 (Build_TypeCode_Call (Loc, Etype (Field), Decls), Params);
10428 Get_Name_String (Chars (Field));
10429 Add_String_Parameter (String_From_Name_Buffer, Params);
10430
10431 else
10432
10433 -- A variant part
10434
10435 Variant_Part : declare
10436 Disc_Type : constant Entity_Id := Etype (Name (Field));
10437
10438 Is_Enum : constant Boolean :=
10439 Is_Enumeration_Type (Disc_Type);
10440
10441 Union_TC_Params : List_Id;
10442
10443 U_Name : constant Name_Id :=
10444 New_External_Name (Chars (Typ), 'V', -1);
10445
10446 Name_Str : String_Id;
10447 Struct_TC_Params : List_Id;
10448
10449 Variant : Node_Id;
10450 Choice : Node_Id;
10451 Default : constant Node_Id :=
10452 Make_Integer_Literal (Loc, -1);
10453
10454 Dummy_Counter : Nat := 0;
10455
10456 Choice_Index : Int := 0;
10457 -- Index of current choice in TypeCode, used to identify
10458 -- it as the default choice if it is a "when others".
10459
10460 procedure Add_Params_For_Variant_Components;
10461 -- Add a struct TypeCode and a corresponding member name
10462 -- to the union parameter list.
10463
10464 -- Ordering of declarations is a complete mess in this
10465 -- area, it is supposed to be types/variables, then
10466 -- subprogram specs, then subprogram bodies ???
10467
10468 ---------------------------------------
10469 -- Add_Params_For_Variant_Components --
10470 ---------------------------------------
10471
10472 procedure Add_Params_For_Variant_Components is
10473 S_Name : constant Name_Id :=
10474 New_External_Name (U_Name, 'S', -1);
10475
10476 begin
10477 Get_Name_String (S_Name);
10478 Name_Str := String_From_Name_Buffer;
10479 Initialize_Parameter_List
10480 (Name_Str, Name_Str, Struct_TC_Params);
10481
10482 -- Build struct parameters
10483
10484 TC_Append_Record_Traversal (Struct_TC_Params,
10485 Component_List (Variant),
10486 Empty,
10487 Dummy_Counter);
10488
10489 Add_TypeCode_Parameter
10490 (Make_Constructed_TypeCode
10491 (RTE (RE_Tk_Struct), Struct_TC_Params),
10492 Union_TC_Params);
10493
10494 Add_String_Parameter (Name_Str, Union_TC_Params);
10495 end Add_Params_For_Variant_Components;
10496
10497 -- Start of processing for Variant_Part
10498
10499 begin
10500 Get_Name_String (U_Name);
10501 Name_Str := String_From_Name_Buffer;
10502
10503 Initialize_Parameter_List
10504 (Name_Str, Name_Str, Union_TC_Params);
10505
10506 -- Add union in enclosing parameter list
10507
10508 Add_TypeCode_Parameter
10509 (Make_Constructed_TypeCode
10510 (RTE (RE_Tk_Union), Union_TC_Params),
10511 Params);
10512
10513 Add_String_Parameter (Name_Str, Params);
10514
10515 -- Build union parameters
10516
10517 Add_TypeCode_Parameter
10518 (Build_TypeCode_Call (Loc, Disc_Type, Decls),
10519 Union_TC_Params);
10520
10521 Add_Long_Parameter (Default, Union_TC_Params);
10522
10523 Variant := First_Non_Pragma (Variants (Field));
10524 while Present (Variant) loop
10525 Choice := First (Discrete_Choices (Variant));
10526 while Present (Choice) loop
10527 case Nkind (Choice) is
10528 when N_Range =>
10529 declare
10530 L : constant Uint :=
10531 Expr_Value (Low_Bound (Choice));
10532 H : constant Uint :=
10533 Expr_Value (High_Bound (Choice));
10534 J : Uint := L;
10535 -- 3.8.1(8) guarantees that the bounds of
10536 -- this range are static.
10537
10538 Expr : Node_Id;
10539
10540 begin
10541 while J <= H loop
10542 if Is_Enum then
10543 Expr := Get_Enum_Lit_From_Pos
10544 (Disc_Type, J, Loc);
10545 else
10546 Expr :=
10547 Make_Integer_Literal (Loc, J);
10548 end if;
10549
10550 Set_Etype (Expr, Disc_Type);
10551 Append_To (Union_TC_Params,
10552 Build_To_Any_Call (Loc, Expr, Decls));
10553
10554 Add_Params_For_Variant_Components;
10555 J := J + Uint_1;
10556 end loop;
10557
10558 Choice_Index :=
10559 Choice_Index + UI_To_Int (H - L) + 1;
10560 end;
10561
10562 when N_Others_Choice =>
10563
10564 -- This variant has a default choice. We must
10565 -- therefore set the default parameter to the
10566 -- current choice index. This parameter is by
10567 -- construction the 4th in Union_TC_Params.
10568
10569 Replace
10570 (Pick (Union_TC_Params, 4),
10571 Make_Function_Call (Loc,
10572 Name =>
10573 New_Occurrence_Of
10574 (RTE (RE_TA_I32), Loc),
10575 Parameter_Associations =>
10576 New_List (
10577 Make_Integer_Literal (Loc,
10578 Intval => Choice_Index))));
10579
10580 -- Add a placeholder member label for the
10581 -- default case, which must have the
10582 -- discriminant type.
10583
10584 declare
10585 Exp : constant Node_Id :=
10586 Make_Attribute_Reference (Loc,
10587 Prefix => New_Occurrence_Of
10588 (Disc_Type, Loc),
10589 Attribute_Name => Name_First);
10590 begin
10591 Set_Etype (Exp, Disc_Type);
10592 Append_To (Union_TC_Params,
10593 Build_To_Any_Call (Loc, Exp, Decls));
10594 end;
10595
10596 Add_Params_For_Variant_Components;
10597 Choice_Index := Choice_Index + 1;
10598
10599 -- Case of an explicit choice
10600
10601 when others =>
10602 declare
10603 Exp : constant Node_Id :=
10604 New_Copy_Tree (Choice);
10605 begin
10606 Append_To (Union_TC_Params,
10607 Build_To_Any_Call (Loc, Exp, Decls));
10608 end;
10609
10610 Add_Params_For_Variant_Components;
10611 Choice_Index := Choice_Index + 1;
10612 end case;
10613
10614 Next (Choice);
10615 end loop;
10616
10617 Next_Non_Pragma (Variant);
10618 end loop;
10619 end Variant_Part;
10620 end if;
10621 end TC_Rec_Add_Process_Element;
10622
10623 Type_Name_Str : String_Id;
10624 Type_Repo_Id_Str : String_Id;
10625
10626 Real_Rep : Node_Id;
10627
10628 -- Start of processing for Build_TypeCode_Function
10629
10630 begin
10631 -- For a derived type, we can't go past the base type (to the
10632 -- parent type) here, because that would cause the attribute's
10633 -- formal parameter to have the wrong type; hence the Base_Type
10634 -- check here.
10635
10636 if Is_Itype (Typ) and then Typ /= Base_Type (Typ) then
10637 Build_TypeCode_Function
10638 (Loc => Loc,
10639 Typ => Etype (Typ),
10640 Decl => Decl,
10641 Fnam => Fnam);
10642 return;
10643 end if;
10644
10645 Fnam := TCNam;
10646
10647 Spec :=
10648 Make_Function_Specification (Loc,
10649 Defining_Unit_Name => Fnam,
10650 Parameter_Specifications => Empty_List,
10651 Result_Definition =>
10652 New_Occurrence_Of (RTE (RE_TypeCode), Loc));
10653
10654 Build_Name_And_Repository_Id (Typ,
10655 Name_Str => Type_Name_Str, Repo_Id_Str => Type_Repo_Id_Str);
10656
10657 Initialize_Parameter_List
10658 (Type_Name_Str, Type_Repo_Id_Str, Parameters);
10659
10660 if Has_Stream_Attribute_Definition
10661 (Typ, TSS_Stream_Output, Real_Rep, At_Any_Place => True)
10662 or else
10663 Has_Stream_Attribute_Definition
10664 (Typ, TSS_Stream_Write, Real_Rep, At_Any_Place => True)
10665 then
10666 -- If user-defined stream attributes are specified for this
10667 -- type, use them and transmit data as an opaque sequence of
10668 -- stream elements.
10669
10670 Return_Alias_TypeCode
10671 (New_Occurrence_Of (RTE (RE_TC_Opaque), Loc));
10672
10673 elsif Is_Derived_Type (Typ) and then not Is_Tagged_Type (Typ) then
10674 Return_Alias_TypeCode (
10675 Build_TypeCode_Call (Loc, Etype (Typ), Decls));
10676
10677 elsif Is_Integer_Type (Typ) or else Is_Unsigned_Type (Typ) then
10678 Return_Alias_TypeCode (
10679 Build_TypeCode_Call (Loc,
10680 Find_Numeric_Representation (Typ), Decls));
10681
10682 elsif Is_Record_Type (Typ) and then not Is_Tagged_Type (Typ) then
10683
10684 -- Record typecodes are encoded as follows:
10685 -- -- TC_STRUCT
10686 -- |
10687 -- | [Name]
10688 -- | [Repository Id]
10689 --
10690 -- Then for each discriminant:
10691 --
10692 -- | [Discriminant Type Code]
10693 -- | [Discriminant Name]
10694 -- | ...
10695 --
10696 -- Then for each component:
10697 --
10698 -- | [Component Type Code]
10699 -- | [Component Name]
10700 -- | ...
10701 --
10702 -- Variants components type codes are encoded as follows:
10703 -- -- TC_UNION
10704 -- |
10705 -- | [Name]
10706 -- | [Repository Id]
10707 -- | [Discriminant Type Code]
10708 -- | [Index of Default Variant Part or -1 for no default]
10709 --
10710 -- Then for each Variant Part :
10711 --
10712 -- | [VP Label]
10713 -- |
10714 -- | -- TC_STRUCT
10715 -- | | [Variant Part Name]
10716 -- | | [Variant Part Repository Id]
10717 -- | |
10718 -- | Then for each VP component:
10719 -- | | [VP component Typecode]
10720 -- | | [VP component Name]
10721 -- | | ...
10722 -- | --
10723 -- |
10724 -- | [VP Name]
10725
10726 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
10727 Return_Alias_TypeCode
10728 (Build_TypeCode_Call (Loc, Etype (Typ), Decls));
10729
10730 else
10731 declare
10732 Disc : Entity_Id := Empty;
10733 Rdef : constant Node_Id :=
10734 Type_Definition (Declaration_Node (Typ));
10735 Dummy_Counter : Int := 0;
10736
10737 begin
10738 -- Construct the discriminants typecodes
10739
10740 if Has_Discriminants (Typ) then
10741 Disc := First_Discriminant (Typ);
10742 end if;
10743
10744 while Present (Disc) loop
10745 Add_TypeCode_Parameter (
10746 Build_TypeCode_Call (Loc, Etype (Disc), Decls),
10747 Parameters);
10748 Get_Name_String (Chars (Disc));
10749 Add_String_Parameter (
10750 String_From_Name_Buffer,
10751 Parameters);
10752 Next_Discriminant (Disc);
10753 end loop;
10754
10755 -- then the components typecodes
10756
10757 TC_Append_Record_Traversal
10758 (Parameters, Component_List (Rdef),
10759 Empty, Dummy_Counter);
10760 Return_Constructed_TypeCode (RTE (RE_Tk_Struct));
10761 end;
10762 end if;
10763
10764 elsif Is_Array_Type (Typ) then
10765 declare
10766 Ndim : constant Pos := Number_Dimensions (Typ);
10767 Inner_TypeCode : Node_Id;
10768 Constrained : constant Boolean := Is_Constrained (Typ);
10769 Indx : Node_Id := First_Index (Typ);
10770
10771 begin
10772 Inner_TypeCode :=
10773 Build_TypeCode_Call (Loc, Component_Type (Typ), Decls);
10774
10775 for J in 1 .. Ndim loop
10776 if Constrained then
10777 Inner_TypeCode := Make_Constructed_TypeCode
10778 (RTE (RE_Tk_Array), New_List (
10779 Build_To_Any_Call (Loc,
10780 OK_Convert_To (RTE (RE_Unsigned_32),
10781 Make_Attribute_Reference (Loc,
10782 Prefix => New_Occurrence_Of (Typ, Loc),
10783 Attribute_Name => Name_Length,
10784 Expressions => New_List (
10785 Make_Integer_Literal (Loc,
10786 Intval => Ndim - J + 1)))),
10787 Decls),
10788 Build_To_Any_Call (Loc, Inner_TypeCode, Decls)));
10789
10790 else
10791 -- Unconstrained case: add low bound for each
10792 -- dimension.
10793
10794 Add_TypeCode_Parameter
10795 (Build_TypeCode_Call (Loc, Etype (Indx), Decls),
10796 Parameters);
10797 Get_Name_String (New_External_Name ('L', J));
10798 Add_String_Parameter (
10799 String_From_Name_Buffer,
10800 Parameters);
10801 Next_Index (Indx);
10802
10803 Inner_TypeCode := Make_Constructed_TypeCode
10804 (RTE (RE_Tk_Sequence), New_List (
10805 Build_To_Any_Call (Loc,
10806 OK_Convert_To (RTE (RE_Unsigned_32),
10807 Make_Integer_Literal (Loc, 0)),
10808 Decls),
10809 Build_To_Any_Call (Loc, Inner_TypeCode, Decls)));
10810 end if;
10811 end loop;
10812
10813 if Constrained then
10814 Return_Alias_TypeCode (Inner_TypeCode);
10815 else
10816 Add_TypeCode_Parameter (Inner_TypeCode, Parameters);
10817 Start_String;
10818 Store_String_Char ('V');
10819 Add_String_Parameter (End_String, Parameters);
10820 Return_Constructed_TypeCode (RTE (RE_Tk_Struct));
10821 end if;
10822 end;
10823
10824 else
10825 -- Default: type is represented as an opaque sequence of bytes
10826
10827 Return_Alias_TypeCode
10828 (New_Occurrence_Of (RTE (RE_TC_Opaque), Loc));
10829 end if;
10830
10831 Decl :=
10832 Make_Subprogram_Body (Loc,
10833 Specification => Spec,
10834 Declarations => Decls,
10835 Handled_Statement_Sequence =>
10836 Make_Handled_Sequence_Of_Statements (Loc,
10837 Statements => Stms));
10838 end Build_TypeCode_Function;
10839
10840 ---------------------------------
10841 -- Find_Numeric_Representation --
10842 ---------------------------------
10843
10844 function Find_Numeric_Representation
10845 (Typ : Entity_Id) return Entity_Id
10846 is
10847 FST : constant Entity_Id := First_Subtype (Typ);
10848 P_Size : constant Uint := Esize (FST);
10849
10850 begin
10851 -- Special case: for Stream_Element_Offset and Storage_Offset,
10852 -- always force transmission as a 64-bit value.
10853
10854 if Is_RTE (FST, RE_Stream_Element_Offset)
10855 or else
10856 Is_RTE (FST, RE_Storage_Offset)
10857 then
10858 return RTE (RE_Unsigned_64);
10859 end if;
10860
10861 if Is_Unsigned_Type (Typ) then
10862 if P_Size <= 8 then
10863 return RTE (RE_Unsigned_8);
10864
10865 elsif P_Size <= 16 then
10866 return RTE (RE_Unsigned_16);
10867
10868 elsif P_Size <= 32 then
10869 return RTE (RE_Unsigned_32);
10870
10871 else
10872 return RTE (RE_Unsigned_64);
10873 end if;
10874
10875 elsif Is_Integer_Type (Typ) then
10876 if P_Size <= 8 then
10877 return RTE (RE_Integer_8);
10878
10879 elsif P_Size <= Standard_Short_Integer_Size then
10880 return RTE (RE_Integer_16);
10881
10882 elsif P_Size <= Standard_Integer_Size then
10883 return RTE (RE_Integer_32);
10884
10885 else
10886 return RTE (RE_Integer_64);
10887 end if;
10888
10889 elsif Is_Floating_Point_Type (Typ) then
10890 if P_Size <= Standard_Short_Float_Size then
10891 return Standard_Short_Float;
10892
10893 elsif P_Size <= Standard_Float_Size then
10894 return Standard_Float;
10895
10896 elsif P_Size <= Standard_Long_Float_Size then
10897 return Standard_Long_Float;
10898
10899 else
10900 return Standard_Long_Long_Float;
10901 end if;
10902
10903 else
10904 raise Program_Error;
10905 end if;
10906
10907 -- What about fixed point types and numeric types with a biased
10908 -- representation???
10909
10910 end Find_Numeric_Representation;
10911
10912 ---------------------------------
10913 -- Is_Generic_Actual_Subtype --
10914 ---------------------------------
10915
10916 function Is_Generic_Actual_Subtype (Typ : Entity_Id) return Boolean is
10917 begin
10918 if Is_Itype (Typ)
10919 and then Present (Associated_Node_For_Itype (Typ))
10920 then
10921 declare
10922 N : constant Node_Id := Associated_Node_For_Itype (Typ);
10923 begin
10924 if Nkind (N) = N_Subtype_Declaration
10925 and then Nkind (Parent (N)) = N_Package_Specification
10926 and then Is_Generic_Instance (Scope_Of_Spec (Parent (N)))
10927 then
10928 return True;
10929 end if;
10930 end;
10931 end if;
10932
10933 return False;
10934 end Is_Generic_Actual_Subtype;
10935
10936 ---------------------------
10937 -- Append_Array_Traversal --
10938 ---------------------------
10939
10940 procedure Append_Array_Traversal
10941 (Stmts : List_Id;
10942 Any : Entity_Id;
10943 Counter : Entity_Id := Empty;
10944 Depth : Pos := 1)
10945 is
10946 Loc : constant Source_Ptr := Sloc (Subprogram);
10947 Typ : constant Entity_Id := Etype (Arry);
10948 Constrained : constant Boolean := Is_Constrained (Typ);
10949 Ndim : constant Pos := Number_Dimensions (Typ);
10950
10951 Inner_Any, Inner_Counter : Entity_Id;
10952
10953 Loop_Stm : Node_Id;
10954 Inner_Stmts : constant List_Id := New_List;
10955
10956 begin
10957 if Depth > Ndim then
10958
10959 -- Processing for one element of an array
10960
10961 declare
10962 Element_Expr : constant Node_Id :=
10963 Make_Indexed_Component (Loc,
10964 New_Occurrence_Of (Arry, Loc),
10965 Indexes);
10966 begin
10967 Set_Etype (Element_Expr, Component_Type (Typ));
10968 Add_Process_Element (Stmts,
10969 Any => Any,
10970 Counter => Counter,
10971 Datum => Element_Expr);
10972 end;
10973
10974 return;
10975 end if;
10976
10977 Append_To (Indexes,
10978 Make_Identifier (Loc, New_External_Name ('L', Depth)));
10979
10980 if not Constrained or else Depth > 1 then
10981 Inner_Any := Make_Defining_Identifier (Loc,
10982 New_External_Name ('A', Depth));
10983 Set_Etype (Inner_Any, RTE (RE_Any));
10984 else
10985 Inner_Any := Empty;
10986 end if;
10987
10988 if Present (Counter) then
10989 Inner_Counter := Make_Defining_Identifier (Loc,
10990 New_External_Name ('J', Depth));
10991 else
10992 Inner_Counter := Empty;
10993 end if;
10994
10995 declare
10996 Loop_Any : Node_Id := Inner_Any;
10997
10998 begin
10999 -- For the first dimension of a constrained array, we add
11000 -- elements directly in the corresponding Any; there is no
11001 -- intervening inner Any.
11002
11003 if No (Loop_Any) then
11004 Loop_Any := Any;
11005 end if;
11006
11007 Append_Array_Traversal (Inner_Stmts,
11008 Any => Loop_Any,
11009 Counter => Inner_Counter,
11010 Depth => Depth + 1);
11011 end;
11012
11013 Loop_Stm :=
11014 Make_Implicit_Loop_Statement (Subprogram,
11015 Iteration_Scheme =>
11016 Make_Iteration_Scheme (Loc,
11017 Loop_Parameter_Specification =>
11018 Make_Loop_Parameter_Specification (Loc,
11019 Defining_Identifier =>
11020 Make_Defining_Identifier (Loc,
11021 Chars => New_External_Name ('L', Depth)),
11022
11023 Discrete_Subtype_Definition =>
11024 Make_Attribute_Reference (Loc,
11025 Prefix => New_Occurrence_Of (Arry, Loc),
11026 Attribute_Name => Name_Range,
11027
11028 Expressions => New_List (
11029 Make_Integer_Literal (Loc, Depth))))),
11030 Statements => Inner_Stmts);
11031
11032 declare
11033 Decls : constant List_Id := New_List;
11034 Dimen_Stmts : constant List_Id := New_List;
11035 Length_Node : Node_Id;
11036
11037 Inner_Any_TypeCode : constant Entity_Id :=
11038 Make_Defining_Identifier (Loc,
11039 New_External_Name ('T', Depth));
11040
11041 Inner_Any_TypeCode_Expr : Node_Id;
11042
11043 begin
11044 if Depth = 1 then
11045 if Constrained then
11046 Inner_Any_TypeCode_Expr :=
11047 Make_Function_Call (Loc,
11048 Name => New_Occurrence_Of (RTE (RE_Get_TC), Loc),
11049 Parameter_Associations => New_List (
11050 New_Occurrence_Of (Any, Loc)));
11051
11052 else
11053 Inner_Any_TypeCode_Expr :=
11054 Make_Function_Call (Loc,
11055 Name =>
11056 New_Occurrence_Of (RTE (RE_Any_Member_Type), Loc),
11057 Parameter_Associations => New_List (
11058 New_Occurrence_Of (Any, Loc),
11059 Make_Integer_Literal (Loc, Ndim)));
11060 end if;
11061
11062 else
11063 Inner_Any_TypeCode_Expr :=
11064 Make_Function_Call (Loc,
11065 Name => New_Occurrence_Of (RTE (RE_Content_Type), Loc),
11066 Parameter_Associations => New_List (
11067 Make_Identifier (Loc,
11068 Chars => New_External_Name ('T', Depth - 1))));
11069 end if;
11070
11071 Append_To (Decls,
11072 Make_Object_Declaration (Loc,
11073 Defining_Identifier => Inner_Any_TypeCode,
11074 Constant_Present => True,
11075 Object_Definition => New_Occurrence_Of (
11076 RTE (RE_TypeCode), Loc),
11077 Expression => Inner_Any_TypeCode_Expr));
11078
11079 if Present (Inner_Any) then
11080 Append_To (Decls,
11081 Make_Object_Declaration (Loc,
11082 Defining_Identifier => Inner_Any,
11083 Object_Definition =>
11084 New_Occurrence_Of (RTE (RE_Any), Loc),
11085 Expression =>
11086 Make_Function_Call (Loc,
11087 Name =>
11088 New_Occurrence_Of (
11089 RTE (RE_Create_Any), Loc),
11090 Parameter_Associations => New_List (
11091 New_Occurrence_Of (Inner_Any_TypeCode, Loc)))));
11092 end if;
11093
11094 if Present (Inner_Counter) then
11095 Append_To (Decls,
11096 Make_Object_Declaration (Loc,
11097 Defining_Identifier => Inner_Counter,
11098 Object_Definition =>
11099 New_Occurrence_Of (RTE (RE_Unsigned_32), Loc),
11100 Expression =>
11101 Make_Integer_Literal (Loc, 0)));
11102 end if;
11103
11104 if not Constrained then
11105 Length_Node := Make_Attribute_Reference (Loc,
11106 Prefix => New_Occurrence_Of (Arry, Loc),
11107 Attribute_Name => Name_Length,
11108 Expressions =>
11109 New_List (Make_Integer_Literal (Loc, Depth)));
11110 Set_Etype (Length_Node, RTE (RE_Unsigned_32));
11111
11112 Add_Process_Element (Dimen_Stmts,
11113 Datum => Length_Node,
11114 Any => Inner_Any,
11115 Counter => Inner_Counter);
11116 end if;
11117
11118 -- Loop_Stm does appropriate processing for each element
11119 -- of Inner_Any.
11120
11121 Append_To (Dimen_Stmts, Loop_Stm);
11122
11123 -- Link outer and inner any
11124
11125 if Present (Inner_Any) then
11126 Add_Process_Element (Dimen_Stmts,
11127 Any => Any,
11128 Counter => Counter,
11129 Datum => New_Occurrence_Of (Inner_Any, Loc));
11130 end if;
11131
11132 Append_To (Stmts,
11133 Make_Block_Statement (Loc,
11134 Declarations =>
11135 Decls,
11136 Handled_Statement_Sequence =>
11137 Make_Handled_Sequence_Of_Statements (Loc,
11138 Statements => Dimen_Stmts)));
11139 end;
11140 end Append_Array_Traversal;
11141
11142 -------------------------------
11143 -- Make_Helper_Function_Name --
11144 -------------------------------
11145
11146 function Make_Helper_Function_Name
11147 (Loc : Source_Ptr;
11148 Typ : Entity_Id;
11149 Nam : Name_Id) return Entity_Id
11150 is
11151 begin
11152 declare
11153 Serial : Nat := 0;
11154 -- For tagged types that aren't frozen yet, generate the helper
11155 -- under its canonical name so that it matches the primitive
11156 -- spec. For all other cases, we use a serialized name so that
11157 -- multiple generations of the same procedure do not clash.
11158
11159 begin
11160 if Is_Tagged_Type (Typ) and then not Is_Frozen (Typ) then
11161 null;
11162 else
11163 Serial := Increment_Serial_Number;
11164 end if;
11165
11166 -- Use prefixed underscore to avoid potential clash with user
11167 -- identifier (we use attribute names for Nam).
11168
11169 return
11170 Make_Defining_Identifier (Loc,
11171 Chars =>
11172 New_External_Name
11173 (Related_Id => Nam,
11174 Suffix => ' ',
11175 Suffix_Index => Serial,
11176 Prefix => '_'));
11177 end;
11178 end Make_Helper_Function_Name;
11179 end Helpers;
11180
11181 -----------------------------------
11182 -- Reserve_NamingContext_Methods --
11183 -----------------------------------
11184
11185 procedure Reserve_NamingContext_Methods is
11186 begin
11187 Overload_Counter_Table.Set (Name_Find ("resolve"), 1);
11188 end Reserve_NamingContext_Methods;
11189
11190 -----------------------
11191 -- RPC_Receiver_Decl --
11192 -----------------------
11193
11194 function RPC_Receiver_Decl (RACW_Type : Entity_Id) return Node_Id is
11195 Loc : constant Source_Ptr := Sloc (RACW_Type);
11196 begin
11197 return
11198 Make_Object_Declaration (Loc,
11199 Defining_Identifier => Make_Temporary (Loc, 'R'),
11200 Aliased_Present => True,
11201 Object_Definition => New_Occurrence_Of (RTE (RE_Servant), Loc));
11202 end RPC_Receiver_Decl;
11203
11204 end PolyORB_Support;
11205
11206 -------------------------------
11207 -- RACW_Type_Is_Asynchronous --
11208 -------------------------------
11209
11210 procedure RACW_Type_Is_Asynchronous (RACW_Type : Entity_Id) is
11211 Asynchronous_Flag : constant Entity_Id :=
11212 Asynchronous_Flags_Table.Get (RACW_Type);
11213 begin
11214 Replace (Expression (Parent (Asynchronous_Flag)),
11215 New_Occurrence_Of (Standard_True, Sloc (Asynchronous_Flag)));
11216 end RACW_Type_Is_Asynchronous;
11217
11218 -------------------------
11219 -- RCI_Package_Locator --
11220 -------------------------
11221
11222 function RCI_Package_Locator
11223 (Loc : Source_Ptr;
11224 Package_Spec : Node_Id) return Node_Id
11225 is
11226 Inst : Node_Id;
11227 Pkg_Name : constant String_Id :=
11228 Fully_Qualified_Name_String
11229 (Defining_Entity (Package_Spec), Append_NUL => False);
11230
11231 begin
11232 Inst :=
11233 Make_Package_Instantiation (Loc,
11234 Defining_Unit_Name => Make_Temporary (Loc, 'R'),
11235
11236 Name =>
11237 New_Occurrence_Of (RTE (RE_RCI_Locator), Loc),
11238
11239 Generic_Associations => New_List (
11240 Make_Generic_Association (Loc,
11241 Selector_Name =>
11242 Make_Identifier (Loc, Name_RCI_Name),
11243 Explicit_Generic_Actual_Parameter =>
11244 Make_String_Literal (Loc,
11245 Strval => Pkg_Name)),
11246
11247 Make_Generic_Association (Loc,
11248 Selector_Name =>
11249 Make_Identifier (Loc, Name_Version),
11250 Explicit_Generic_Actual_Parameter =>
11251 Make_Attribute_Reference (Loc,
11252 Prefix =>
11253 New_Occurrence_Of (Defining_Entity (Package_Spec), Loc),
11254 Attribute_Name =>
11255 Name_Version))));
11256
11257 RCI_Locator_Table.Set
11258 (Defining_Unit_Name (Package_Spec),
11259 Defining_Unit_Name (Inst));
11260 return Inst;
11261 end RCI_Package_Locator;
11262
11263 -----------------------------------------------
11264 -- Remote_Types_Tagged_Full_View_Encountered --
11265 -----------------------------------------------
11266
11267 procedure Remote_Types_Tagged_Full_View_Encountered
11268 (Full_View : Entity_Id)
11269 is
11270 Stub_Elements : constant Stub_Structure :=
11271 Stubs_Table.Get (Full_View);
11272
11273 begin
11274 -- For an RACW encountered before the freeze point of its designated
11275 -- type, the stub type is generated at the point of the RACW declaration
11276 -- but the primitives are generated only once the designated type is
11277 -- frozen. That freeze can occur in another scope, for example when the
11278 -- RACW is declared in a nested package. In that case we need to
11279 -- reestablish the stub type's scope prior to generating its primitive
11280 -- operations.
11281
11282 if Stub_Elements /= Empty_Stub_Structure then
11283 declare
11284 Saved_Scope : constant Entity_Id := Current_Scope;
11285 Stubs_Scope : constant Entity_Id :=
11286 Scope (Stub_Elements.Stub_Type);
11287
11288 begin
11289 if Current_Scope /= Stubs_Scope then
11290 Push_Scope (Stubs_Scope);
11291 end if;
11292
11293 Add_RACW_Primitive_Declarations_And_Bodies
11294 (Full_View,
11295 Stub_Elements.RPC_Receiver_Decl,
11296 Stub_Elements.Body_Decls);
11297
11298 if Current_Scope /= Saved_Scope then
11299 Pop_Scope;
11300 end if;
11301 end;
11302 end if;
11303 end Remote_Types_Tagged_Full_View_Encountered;
11304
11305 -------------------
11306 -- Scope_Of_Spec --
11307 -------------------
11308
11309 function Scope_Of_Spec (Spec : Node_Id) return Entity_Id is
11310 Unit_Name : Node_Id;
11311
11312 begin
11313 Unit_Name := Defining_Unit_Name (Spec);
11314 while Nkind (Unit_Name) /= N_Defining_Identifier loop
11315 Unit_Name := Defining_Identifier (Unit_Name);
11316 end loop;
11317
11318 return Unit_Name;
11319 end Scope_Of_Spec;
11320
11321 ----------------------
11322 -- Set_Renaming_TSS --
11323 ----------------------
11324
11325 procedure Set_Renaming_TSS
11326 (Typ : Entity_Id;
11327 Nam : Entity_Id;
11328 TSS_Nam : TSS_Name_Type)
11329 is
11330 Loc : constant Source_Ptr := Sloc (Nam);
11331 Spec : constant Node_Id := Parent (Nam);
11332
11333 TSS_Node : constant Node_Id :=
11334 Make_Subprogram_Renaming_Declaration (Loc,
11335 Specification =>
11336 Copy_Specification (Loc,
11337 Spec => Spec,
11338 New_Name => Make_TSS_Name (Typ, TSS_Nam)),
11339 Name => New_Occurrence_Of (Nam, Loc));
11340
11341 Snam : constant Entity_Id :=
11342 Defining_Unit_Name (Specification (TSS_Node));
11343
11344 begin
11345 if Nkind (Spec) = N_Function_Specification then
11346 Mutate_Ekind (Snam, E_Function);
11347 Set_Etype (Snam, Entity (Result_Definition (Spec)));
11348 else
11349 Mutate_Ekind (Snam, E_Procedure);
11350 Set_Etype (Snam, Standard_Void_Type);
11351 end if;
11352
11353 Set_TSS (Typ, Snam);
11354 end Set_Renaming_TSS;
11355
11356 ----------------------------------------------
11357 -- Specific_Add_Obj_RPC_Receiver_Completion --
11358 ----------------------------------------------
11359
11360 procedure Specific_Add_Obj_RPC_Receiver_Completion
11361 (Loc : Source_Ptr;
11362 Decls : List_Id;
11363 RPC_Receiver : Entity_Id;
11364 Stub_Elements : Stub_Structure)
11365 is
11366 begin
11367 case Get_PCS_Name is
11368 when Name_PolyORB_DSA =>
11369 PolyORB_Support.Add_Obj_RPC_Receiver_Completion
11370 (Loc, Decls, RPC_Receiver, Stub_Elements);
11371
11372 when others =>
11373 GARLIC_Support.Add_Obj_RPC_Receiver_Completion
11374 (Loc, Decls, RPC_Receiver, Stub_Elements);
11375 end case;
11376 end Specific_Add_Obj_RPC_Receiver_Completion;
11377
11378 --------------------------------
11379 -- Specific_Add_RACW_Features --
11380 --------------------------------
11381
11382 procedure Specific_Add_RACW_Features
11383 (RACW_Type : Entity_Id;
11384 Desig : Entity_Id;
11385 Stub_Type : Entity_Id;
11386 Stub_Type_Access : Entity_Id;
11387 RPC_Receiver_Decl : Node_Id;
11388 Body_Decls : List_Id)
11389 is
11390 begin
11391 case Get_PCS_Name is
11392 when Name_PolyORB_DSA =>
11393 PolyORB_Support.Add_RACW_Features
11394 (RACW_Type,
11395 Desig,
11396 Stub_Type,
11397 Stub_Type_Access,
11398 RPC_Receiver_Decl,
11399 Body_Decls);
11400
11401 when others =>
11402 GARLIC_Support.Add_RACW_Features
11403 (RACW_Type,
11404 Stub_Type,
11405 Stub_Type_Access,
11406 RPC_Receiver_Decl,
11407 Body_Decls);
11408 end case;
11409 end Specific_Add_RACW_Features;
11410
11411 --------------------------------
11412 -- Specific_Add_RAST_Features --
11413 --------------------------------
11414
11415 procedure Specific_Add_RAST_Features
11416 (Vis_Decl : Node_Id;
11417 RAS_Type : Entity_Id)
11418 is
11419 begin
11420 case Get_PCS_Name is
11421 when Name_PolyORB_DSA =>
11422 PolyORB_Support.Add_RAST_Features (Vis_Decl, RAS_Type);
11423
11424 when others =>
11425 GARLIC_Support.Add_RAST_Features (Vis_Decl, RAS_Type);
11426 end case;
11427 end Specific_Add_RAST_Features;
11428
11429 --------------------------------------------------
11430 -- Specific_Add_Receiving_Stubs_To_Declarations --
11431 --------------------------------------------------
11432
11433 procedure Specific_Add_Receiving_Stubs_To_Declarations
11434 (Pkg_Spec : Node_Id;
11435 Decls : List_Id;
11436 Stmts : List_Id)
11437 is
11438 begin
11439 case Get_PCS_Name is
11440 when Name_PolyORB_DSA =>
11441 PolyORB_Support.Add_Receiving_Stubs_To_Declarations
11442 (Pkg_Spec, Decls, Stmts);
11443
11444 when others =>
11445 GARLIC_Support.Add_Receiving_Stubs_To_Declarations
11446 (Pkg_Spec, Decls, Stmts);
11447 end case;
11448 end Specific_Add_Receiving_Stubs_To_Declarations;
11449
11450 ------------------------------------------
11451 -- Specific_Build_General_Calling_Stubs --
11452 ------------------------------------------
11453
11454 procedure Specific_Build_General_Calling_Stubs
11455 (Decls : List_Id;
11456 Statements : List_Id;
11457 Target : RPC_Target;
11458 Subprogram_Id : Node_Id;
11459 Asynchronous : Node_Id := Empty;
11460 Is_Known_Asynchronous : Boolean := False;
11461 Is_Known_Non_Asynchronous : Boolean := False;
11462 Is_Function : Boolean;
11463 Spec : Node_Id;
11464 Stub_Type : Entity_Id := Empty;
11465 RACW_Type : Entity_Id := Empty;
11466 Nod : Node_Id)
11467 is
11468 begin
11469 case Get_PCS_Name is
11470 when Name_PolyORB_DSA =>
11471 PolyORB_Support.Build_General_Calling_Stubs
11472 (Decls,
11473 Statements,
11474 Target.Object,
11475 Subprogram_Id,
11476 Asynchronous,
11477 Is_Known_Asynchronous,
11478 Is_Known_Non_Asynchronous,
11479 Is_Function,
11480 Spec,
11481 Stub_Type,
11482 RACW_Type,
11483 Nod);
11484
11485 when others =>
11486 GARLIC_Support.Build_General_Calling_Stubs
11487 (Decls,
11488 Statements,
11489 Target.Partition,
11490 Target.RPC_Receiver,
11491 Subprogram_Id,
11492 Asynchronous,
11493 Is_Known_Asynchronous,
11494 Is_Known_Non_Asynchronous,
11495 Is_Function,
11496 Spec,
11497 Stub_Type,
11498 RACW_Type,
11499 Nod);
11500 end case;
11501 end Specific_Build_General_Calling_Stubs;
11502
11503 --------------------------------------
11504 -- Specific_Build_RPC_Receiver_Body --
11505 --------------------------------------
11506
11507 procedure Specific_Build_RPC_Receiver_Body
11508 (RPC_Receiver : Entity_Id;
11509 Request : out Entity_Id;
11510 Subp_Id : out Entity_Id;
11511 Subp_Index : out Entity_Id;
11512 Stmts : out List_Id;
11513 Decl : out Node_Id)
11514 is
11515 begin
11516 case Get_PCS_Name is
11517 when Name_PolyORB_DSA =>
11518 PolyORB_Support.Build_RPC_Receiver_Body
11519 (RPC_Receiver,
11520 Request,
11521 Subp_Id,
11522 Subp_Index,
11523 Stmts,
11524 Decl);
11525
11526 when others =>
11527 GARLIC_Support.Build_RPC_Receiver_Body
11528 (RPC_Receiver,
11529 Request,
11530 Subp_Id,
11531 Subp_Index,
11532 Stmts,
11533 Decl);
11534 end case;
11535 end Specific_Build_RPC_Receiver_Body;
11536
11537 --------------------------------
11538 -- Specific_Build_Stub_Target --
11539 --------------------------------
11540
11541 function Specific_Build_Stub_Target
11542 (Loc : Source_Ptr;
11543 Decls : List_Id;
11544 RCI_Locator : Entity_Id;
11545 Controlling_Parameter : Entity_Id) return RPC_Target
11546 is
11547 begin
11548 case Get_PCS_Name is
11549 when Name_PolyORB_DSA =>
11550 return
11551 PolyORB_Support.Build_Stub_Target
11552 (Loc, Decls, RCI_Locator, Controlling_Parameter);
11553
11554 when others =>
11555 return
11556 GARLIC_Support.Build_Stub_Target
11557 (Loc, Decls, RCI_Locator, Controlling_Parameter);
11558 end case;
11559 end Specific_Build_Stub_Target;
11560
11561 --------------------------------
11562 -- Specific_RPC_Receiver_Decl --
11563 --------------------------------
11564
11565 function Specific_RPC_Receiver_Decl
11566 (RACW_Type : Entity_Id) return Node_Id
11567 is
11568 begin
11569 case Get_PCS_Name is
11570 when Name_PolyORB_DSA =>
11571 return PolyORB_Support.RPC_Receiver_Decl (RACW_Type);
11572
11573 when others =>
11574 return GARLIC_Support.RPC_Receiver_Decl (RACW_Type);
11575 end case;
11576 end Specific_RPC_Receiver_Decl;
11577
11578 -----------------------------------------------
11579 -- Specific_Build_Subprogram_Receiving_Stubs --
11580 -----------------------------------------------
11581
11582 function Specific_Build_Subprogram_Receiving_Stubs
11583 (Vis_Decl : Node_Id;
11584 Asynchronous : Boolean;
11585 Dynamically_Asynchronous : Boolean := False;
11586 Stub_Type : Entity_Id := Empty;
11587 RACW_Type : Entity_Id := Empty;
11588 Parent_Primitive : Entity_Id := Empty) return Node_Id
11589 is
11590 begin
11591 case Get_PCS_Name is
11592 when Name_PolyORB_DSA =>
11593 return
11594 PolyORB_Support.Build_Subprogram_Receiving_Stubs
11595 (Vis_Decl,
11596 Asynchronous,
11597 Dynamically_Asynchronous,
11598 Stub_Type,
11599 RACW_Type,
11600 Parent_Primitive);
11601
11602 when others =>
11603 return
11604 GARLIC_Support.Build_Subprogram_Receiving_Stubs
11605 (Vis_Decl,
11606 Asynchronous,
11607 Dynamically_Asynchronous,
11608 Stub_Type,
11609 RACW_Type,
11610 Parent_Primitive);
11611 end case;
11612 end Specific_Build_Subprogram_Receiving_Stubs;
11613
11614 -------------------------------
11615 -- Transmit_As_Unconstrained --
11616 -------------------------------
11617
11618 function Transmit_As_Unconstrained (Typ : Entity_Id) return Boolean is
11619 begin
11620 return
11621 not (Is_Elementary_Type (Typ) or else Is_Constrained (Typ))
11622 or else (Is_Access_Type (Typ) and then Can_Never_Be_Null (Typ));
11623 end Transmit_As_Unconstrained;
11624
11625 --------------------------
11626 -- Underlying_RACW_Type --
11627 --------------------------
11628
11629 function Underlying_RACW_Type (RAS_Typ : Entity_Id) return Entity_Id is
11630 Record_Type : Entity_Id;
11631
11632 begin
11633 if Ekind (RAS_Typ) = E_Record_Type then
11634 Record_Type := RAS_Typ;
11635 else
11636 pragma Assert (Present (Equivalent_Type (RAS_Typ)));
11637 Record_Type := Equivalent_Type (RAS_Typ);
11638 end if;
11639
11640 return
11641 Etype (Subtype_Indication
11642 (Component_Definition
11643 (First (Component_Items
11644 (Component_List
11645 (Type_Definition
11646 (Declaration_Node (Record_Type))))))));
11647 end Underlying_RACW_Type;
11648
11649 end Exp_Dist;