Mark ChangeLog
[official-gcc.git] / gcc / ada / exp_dist.adb
blob4c756b13317fcb2690aecd76484827cc9ae2d9fb
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-2005 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Exp_Strm; use Exp_Strm;
31 with Exp_Tss; use Exp_Tss;
32 with Exp_Util; use Exp_Util;
33 with GNAT.HTable; use GNAT.HTable;
34 with Lib; use Lib;
35 with Namet; use Namet;
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_Ch3; use Sem_Ch3;
42 with Sem_Ch8; use Sem_Ch8;
43 with Sem_Dist; use Sem_Dist;
44 with Sem_Eval; use Sem_Eval;
45 with Sem_Util; use Sem_Util;
46 with Sinfo; use Sinfo;
47 with Snames; use Snames;
48 with Stand; use Stand;
49 with Stringt; use Stringt;
50 with Tbuild; use Tbuild;
51 with Ttypes; use Ttypes;
52 with Uintp; use Uintp;
54 package body Exp_Dist is
56 -- The following model has been used to implement distributed objects:
57 -- given a designated type D and a RACW type R, then a record of the
58 -- form:
60 -- type Stub is tagged record
61 -- [...declaration similar to s-parint.ads RACW_Stub_Type...]
62 -- end record;
64 -- is built. This type has two properties:
66 -- 1) Since it has the same structure than RACW_Stub_Type, it can be
67 -- converted to and from this type to make it suitable for
68 -- System.Partition_Interface.Get_Unique_Remote_Pointer in order
69 -- to avoid memory leaks when the same remote object arrive on the
70 -- same partition through several paths;
72 -- 2) It also has the same dispatching table as the designated type D,
73 -- and thus can be used as an object designated by a value of type
74 -- R on any partition other than the one on which the object has
75 -- been created, since only dispatching calls will be performed and
76 -- the fields themselves will not be used. We call Derive_Subprograms
77 -- to fake half a derivation to ensure that the subprograms do have
78 -- the same dispatching table.
80 First_RCI_Subprogram_Id : constant := 2;
81 -- RCI subprograms are numbered starting at 2. The RCI receiver for
82 -- an RCI package can thus identify calls received through remote
83 -- access-to-subprogram dereferences by the fact that they have a
84 -- (primitive) subprogram id of 0, and 1 is used for the internal
85 -- RAS information lookup operation. (This is for the Garlic code
86 -- generation, where subprograms are identified by numbers; in the
87 -- PolyORB version, they are identified by name, with a numeric suffix
88 -- for homonyms.)
90 type Hash_Index is range 0 .. 50;
92 -----------------------
93 -- Local subprograms --
94 -----------------------
96 function Hash (F : Entity_Id) return Hash_Index;
97 -- DSA expansion associates stubs to distributed object types using
98 -- a hash table on entity ids.
100 function Hash (F : Name_Id) return Hash_Index;
101 -- The generation of subprogram identifiers requires an overload counter
102 -- to be associated with each remote subprogram names. These counters
103 -- are maintained in a hash table on name ids.
105 type Subprogram_Identifiers is record
106 Str_Identifier : String_Id;
107 Int_Identifier : Int;
108 end record;
110 package Subprogram_Identifier_Table is
111 new Simple_HTable (Header_Num => Hash_Index,
112 Element => Subprogram_Identifiers,
113 No_Element => (No_String, 0),
114 Key => Entity_Id,
115 Hash => Hash,
116 Equal => "=");
117 -- Mapping between a remote subprogram and the corresponding
118 -- subprogram identifiers.
120 package Overload_Counter_Table is
121 new Simple_HTable (Header_Num => Hash_Index,
122 Element => Int,
123 No_Element => 0,
124 Key => Name_Id,
125 Hash => Hash,
126 Equal => "=");
127 -- Mapping between a subprogram name and an integer that
128 -- counts the number of defining subprogram names with that
129 -- Name_Id encountered so far in a given context (an interface).
131 function Get_Subprogram_Ids (Def : Entity_Id) return Subprogram_Identifiers;
132 function Get_Subprogram_Id (Def : Entity_Id) return String_Id;
133 function Get_Subprogram_Id (Def : Entity_Id) return Int;
134 -- Given a subprogram defined in a RCI package, get its distribution
135 -- subprogram identifiers (the distribution identifiers are a unique
136 -- subprogram number, and the non-qualified subprogram name, in the
137 -- casing used for the subprogram declaration; if the name is overloaded,
138 -- a double underscore and a serial number are appended.
140 -- The integer identifier is used to perform remote calls with GARLIC;
141 -- the string identifier is used in the case of PolyORB.
143 -- Although the PolyORB DSA receiving stubs will make a caseless comparison
144 -- when receiving a call, the calling stubs will create requests with the
145 -- exact casing of the defining unit name of the called subprogram, so as
146 -- to allow calls to subprograms on distributed nodes that do distinguish
147 -- between casings.
149 -- NOTE: Another design would be to allow a representation clause on
150 -- subprogram specs: for Subp'Distribution_Identifier use "fooBar";
152 pragma Warnings (Off, Get_Subprogram_Id);
153 -- One homonym only is unreferenced (specific to the GARLIC version)
155 function Get_PCS_Name return PCS_Names;
156 -- Return the name of a literal of type
157 -- System.Partition_Interface.DSA_Implementation_Type
158 -- indicating what PCS is currently in use.
160 procedure Add_RAS_Dereference_TSS (N : Node_Id);
161 -- Add a subprogram body for RAS Dereference TSS
163 procedure Add_RAS_Proxy_And_Analyze
164 (Decls : List_Id;
165 Vis_Decl : Node_Id;
166 All_Calls_Remote_E : Entity_Id;
167 Proxy_Object_Addr : out Entity_Id);
168 -- Add the proxy type necessary to call the subprogram declared
169 -- by Vis_Decl through a remote access to subprogram type.
170 -- All_Calls_Remote_E must be Standard_True if a pragma All_Calls_Remote
171 -- applies, Standard_False otherwise. The new proxy type is appended
172 -- to Decls. Proxy_Object_Addr is a constant of type System.Address that
173 -- designates an instance of the proxy object.
175 function Build_Remote_Subprogram_Proxy_Type
176 (Loc : Source_Ptr;
177 ACR_Expression : Node_Id) return Node_Id;
178 -- Build and return a tagged record type definition for an RCI
179 -- subprogram proxy type.
180 -- ACR_Expression is use as the initialization value for
181 -- the All_Calls_Remote component.
183 function Build_Get_Unique_RP_Call
184 (Loc : Source_Ptr;
185 Pointer : Entity_Id;
186 Stub_Type : Entity_Id) return List_Id;
187 -- Build a call to Get_Unique_Remote_Pointer (Pointer), followed by a
188 -- tag fixup (Get_Unique_Remote_Pointer may have changed Pointer'Tag to
189 -- RACW_Stub_Type'Tag, while the desired tag is that of Stub_Type).
191 function Build_Subprogram_Calling_Stubs
192 (Vis_Decl : Node_Id;
193 Subp_Id : Node_Id;
194 Asynchronous : Boolean;
195 Dynamically_Asynchronous : Boolean := False;
196 Stub_Type : Entity_Id := Empty;
197 RACW_Type : Entity_Id := Empty;
198 Locator : Entity_Id := Empty;
199 New_Name : Name_Id := No_Name) return Node_Id;
200 -- Build the calling stub for a given subprogram with the subprogram ID
201 -- being Subp_Id. If Stub_Type is given, then the "addr" field of
202 -- parameters of this type will be marshalled instead of the object
203 -- itself. It will then be converted into Stub_Type before performing
204 -- the real call. If Dynamically_Asynchronous is True, then it will be
205 -- computed at run time whether the call is asynchronous or not.
206 -- Otherwise, the value of the formal Asynchronous will be used.
207 -- If Locator is not Empty, it will be used instead of RCI_Cache. If
208 -- New_Name is given, then it will be used instead of the original name.
210 function Build_RPC_Receiver_Specification
211 (RPC_Receiver : Entity_Id;
212 Request_Parameter : Entity_Id) return Node_Id;
213 -- Make a subprogram specification for an RPC receiver, with the given
214 -- defining unit name and formal parameter.
216 function Build_Ordered_Parameters_List (Spec : Node_Id) return List_Id;
217 -- Return an ordered parameter list: unconstrained parameters are put
218 -- at the beginning of the list and constrained ones are put after. If
219 -- there are no parameters, an empty list is returned. Special case:
220 -- the controlling formal of the equivalent RACW operation for a RAS
221 -- type is always left in first position.
223 procedure Add_Calling_Stubs_To_Declarations
224 (Pkg_Spec : Node_Id;
225 Decls : List_Id);
226 -- Add calling stubs to the declarative part
228 function Could_Be_Asynchronous (Spec : Node_Id) return Boolean;
229 -- Return True if nothing prevents the program whose specification is
230 -- given to be asynchronous (i.e. no out parameter).
232 function Pack_Entity_Into_Stream_Access
233 (Loc : Source_Ptr;
234 Stream : Node_Id;
235 Object : Entity_Id;
236 Etyp : Entity_Id := Empty) return Node_Id;
237 -- Pack Object (of type Etyp) into Stream. If Etyp is not given,
238 -- then Etype (Object) will be used if present. If the type is
239 -- constrained, then 'Write will be used to output the object,
240 -- If the type is unconstrained, 'Output will be used.
242 function Pack_Node_Into_Stream
243 (Loc : Source_Ptr;
244 Stream : Entity_Id;
245 Object : Node_Id;
246 Etyp : Entity_Id) return Node_Id;
247 -- Similar to above, with an arbitrary node instead of an entity
249 function Pack_Node_Into_Stream_Access
250 (Loc : Source_Ptr;
251 Stream : Node_Id;
252 Object : Node_Id;
253 Etyp : Entity_Id) return Node_Id;
254 -- Similar to above, with Stream instead of Stream'Access
256 function Make_Selected_Component
257 (Loc : Source_Ptr;
258 Prefix : Entity_Id;
259 Selector_Name : Name_Id) return Node_Id;
260 -- Return a selected_component whose prefix denotes the given entity,
261 -- and with the given Selector_Name.
263 function Scope_Of_Spec (Spec : Node_Id) return Entity_Id;
264 -- Return the scope represented by a given spec
266 procedure Set_Renaming_TSS
267 (Typ : Entity_Id;
268 Nam : Entity_Id;
269 TSS_Nam : Name_Id);
270 -- Create a renaming declaration of subprogram Nam,
271 -- and register it as a TSS for Typ with name TSS_Nam.
273 function Need_Extra_Constrained (Parameter : Node_Id) return Boolean;
274 -- Return True if the current parameter needs an extra formal to reflect
275 -- its constrained status.
277 function Is_RACW_Controlling_Formal
278 (Parameter : Node_Id; Stub_Type : Entity_Id) return Boolean;
279 -- Return True if the current parameter is a controlling formal argument
280 -- of type Stub_Type or access to Stub_Type.
282 procedure Declare_Create_NVList
283 (Loc : Source_Ptr;
284 NVList : Entity_Id;
285 Decls : List_Id;
286 Stmts : List_Id);
287 -- Append the declaration of NVList to Decls, and its
288 -- initialization to Stmts.
290 function Add_Parameter_To_NVList
291 (Loc : Source_Ptr;
292 NVList : Entity_Id;
293 Parameter : Entity_Id;
294 Constrained : Boolean;
295 RACW_Ctrl : Boolean := False;
296 Any : Entity_Id) return Node_Id;
297 -- Return a call to Add_Item to add the Any corresponding
298 -- to the designated formal Parameter (with the indicated
299 -- Constrained status) to NVList. RACW_Ctrl must be set to
300 -- True for controlling formals of distributed object primitive
301 -- operations.
303 type Stub_Structure is record
304 Stub_Type : Entity_Id;
305 Stub_Type_Access : Entity_Id;
306 RPC_Receiver_Decl : Node_Id;
307 RACW_Type : Entity_Id;
308 end record;
309 -- This structure is necessary because of the two phases analysis of
310 -- a RACW declaration occurring in the same Remote_Types package as the
311 -- designated type. RACW_Type is any of the RACW types pointing on this
312 -- designated type, it is used here to save an anonymous type creation
313 -- for each primitive operation.
315 -- For a RACW that implements a RAS, no object RPC receiver is generated.
316 -- Instead, RPC_Receiver_Decl is the declaration after which the
317 -- RPC receiver would have been inserted.
319 Empty_Stub_Structure : constant Stub_Structure :=
320 (Empty, Empty, Empty, Empty);
322 package Stubs_Table is
323 new Simple_HTable (Header_Num => Hash_Index,
324 Element => Stub_Structure,
325 No_Element => Empty_Stub_Structure,
326 Key => Entity_Id,
327 Hash => Hash,
328 Equal => "=");
329 -- Mapping between a RACW designated type and its stub type
331 package Asynchronous_Flags_Table is
332 new Simple_HTable (Header_Num => Hash_Index,
333 Element => Entity_Id,
334 No_Element => Empty,
335 Key => Entity_Id,
336 Hash => Hash,
337 Equal => "=");
338 -- Mapping between a RACW type and a constant having the value True
339 -- if the RACW is asynchronous and False otherwise.
341 package RCI_Locator_Table is
342 new Simple_HTable (Header_Num => Hash_Index,
343 Element => Entity_Id,
344 No_Element => Empty,
345 Key => Entity_Id,
346 Hash => Hash,
347 Equal => "=");
348 -- Mapping between a RCI package on which All_Calls_Remote applies and
349 -- the generic instantiation of RCI_Locator for this package.
351 package RCI_Calling_Stubs_Table is
352 new Simple_HTable (Header_Num => Hash_Index,
353 Element => Entity_Id,
354 No_Element => Empty,
355 Key => Entity_Id,
356 Hash => Hash,
357 Equal => "=");
358 -- Mapping between a RCI subprogram and the corresponding calling stubs
360 procedure Add_Stub_Type
361 (Designated_Type : Entity_Id;
362 RACW_Type : Entity_Id;
363 Decls : List_Id;
364 Stub_Type : out Entity_Id;
365 Stub_Type_Access : out Entity_Id;
366 RPC_Receiver_Decl : out Node_Id;
367 Existing : out Boolean);
368 -- Add the declaration of the stub type, the access to stub type and the
369 -- object RPC receiver at the end of Decls. If these already exist,
370 -- then nothing is added in the tree but the right values are returned
371 -- anyhow and Existing is set to True.
373 procedure Add_RACW_Asynchronous_Flag
374 (Declarations : List_Id;
375 RACW_Type : Entity_Id);
376 -- Declare a boolean constant associated with RACW_Type whose value
377 -- indicates at run time whether a pragma Asynchronous applies to it.
379 procedure Assign_Subprogram_Identifier
380 (Def : Entity_Id;
381 Spn : Int;
382 Id : out String_Id);
383 -- Determine the distribution subprogram identifier to
384 -- be used for remote subprogram Def, return it in Id and
385 -- store it in a hash table for later retrieval by
386 -- Get_Subprogram_Id. Spn is the subprogram number.
388 function RCI_Package_Locator
389 (Loc : Source_Ptr;
390 Package_Spec : Node_Id) return Node_Id;
391 -- Instantiate the generic package RCI_Locator in order to locate the
392 -- RCI package whose spec is given as argument.
394 function Make_Tag_Check (Loc : Source_Ptr; N : Node_Id) return Node_Id;
395 -- Surround a node N by a tag check, as in:
396 -- begin
397 -- <N>;
398 -- exception
399 -- when E : Ada.Tags.Tag_Error =>
400 -- Raise_Exception (Program_Error'Identity,
401 -- Exception_Message (E));
402 -- end;
404 function Input_With_Tag_Check
405 (Loc : Source_Ptr;
406 Var_Type : Entity_Id;
407 Stream : Node_Id) return Node_Id;
408 -- Return a function with the following form:
409 -- function R return Var_Type is
410 -- begin
411 -- return Var_Type'Input (S);
412 -- exception
413 -- when E : Ada.Tags.Tag_Error =>
414 -- Raise_Exception (Program_Error'Identity,
415 -- Exception_Message (E));
416 -- end R;
418 --------------------------------------------
419 -- Hooks for PCS-specific code generation --
420 --------------------------------------------
422 -- Part of the code generation circuitry for distribution needs to be
423 -- tailored for each implementation of the PCS. For each routine that
424 -- needs to be specialized, a Specific_<routine> wrapper is created,
425 -- which calls the corresponding <routine> in package
426 -- <pcs_implementation>_Support.
428 procedure Specific_Add_RACW_Features
429 (RACW_Type : Entity_Id;
430 Desig : Entity_Id;
431 Stub_Type : Entity_Id;
432 Stub_Type_Access : Entity_Id;
433 RPC_Receiver_Decl : Node_Id;
434 Declarations : List_Id);
435 -- Add declaration for TSSs for a given RACW type. The declarations are
436 -- added just after the declaration of the RACW type itself, while the
437 -- bodies are inserted at the end of Decls. Runtime-specific ancillary
438 -- subprogram for Add_RACW_Features.
440 procedure Specific_Add_RAST_Features
441 (Vis_Decl : Node_Id;
442 RAS_Type : Entity_Id;
443 Decls : List_Id);
444 -- Add declaration for TSSs for a given RAS type. The declarations are
445 -- added just after the declaration of the RAS type itself, while the
446 -- bodies are inserted at the end of Decls. PCS-specific ancillary
447 -- subprogram for Add_RAST_Features.
449 -- An RPC_Target record is used during construction of calling stubs
450 -- to pass PCS-specific tree fragments corresponding to the information
451 -- necessary to locate the target of a remote subprogram call.
453 type RPC_Target (PCS_Kind : PCS_Names) is record
454 case PCS_Kind is
455 when Name_PolyORB_DSA =>
456 Object : Node_Id;
457 -- An expression whose value is a PolyORB reference to the target
458 -- object.
459 when others =>
460 Partition : Entity_Id;
461 -- A variable containing the Partition_ID of the target parition
463 RPC_Receiver : Node_Id;
464 -- An expression whose value is the address of the target RPC
465 -- receiver.
466 end case;
467 end record;
469 procedure Specific_Build_General_Calling_Stubs
470 (Decls : List_Id;
471 Statements : List_Id;
472 Target : RPC_Target;
473 Subprogram_Id : Node_Id;
474 Asynchronous : Node_Id := Empty;
475 Is_Known_Asynchronous : Boolean := False;
476 Is_Known_Non_Asynchronous : Boolean := False;
477 Is_Function : Boolean;
478 Spec : Node_Id;
479 Stub_Type : Entity_Id := Empty;
480 RACW_Type : Entity_Id := Empty;
481 Nod : Node_Id);
482 -- Build calling stubs for general purpose. The parameters are:
483 -- Decls : a place to put declarations
484 -- Statements : a place to put statements
485 -- Target : PCS-specific target information (see details
486 -- in RPC_Target declaration).
487 -- Subprogram_Id : a node containing the subprogram ID
488 -- Asynchronous : True if an APC must be made instead of an RPC.
489 -- The value needs not be supplied if one of the
490 -- Is_Known_... is True.
491 -- Is_Known_Async... : True if we know that this is asynchronous
492 -- Is_Known_Non_A... : True if we know that this is not asynchronous
493 -- Spec : a node with a Parameter_Specifications and
494 -- a Subtype_Mark if applicable
495 -- Stub_Type : in case of RACW stubs, parameters of type access
496 -- to Stub_Type will be marshalled using the
497 -- address of the object (the addr field) rather
498 -- than using the 'Write on the stub itself
499 -- Nod : used to provide sloc for generated code
501 function Specific_Build_Stub_Target
502 (Loc : Source_Ptr;
503 Decls : List_Id;
504 RCI_Locator : Entity_Id;
505 Controlling_Parameter : Entity_Id) return RPC_Target;
506 -- Build call target information nodes for use within calling stubs. In the
507 -- RCI case, RCI_Locator is the entity for the instance of RCI_Locator. If
508 -- for an RACW, Controlling_Parameter is the entity for the controlling
509 -- formal parameter used to determine the location of the target of the
510 -- call. Decls provides a location where variable declarations can be
511 -- appended to construct the necessary values.
513 procedure Specific_Build_Stub_Type
514 (RACW_Type : Entity_Id;
515 Stub_Type : Entity_Id;
516 Stub_Type_Decl : out Node_Id;
517 RPC_Receiver_Decl : out Node_Id);
518 -- Build a type declaration for the stub type associated with an RACW
519 -- type, and the necessary RPC receiver, if applicable. PCS-specific
520 -- ancillary subprogram for Add_Stub_Type. If no RPC receiver declaration
521 -- is generated, then RPC_Receiver_Decl is set to Empty.
523 procedure Specific_Build_RPC_Receiver_Body
524 (RPC_Receiver : Entity_Id;
525 Request : out Entity_Id;
526 Subp_Id : out Entity_Id;
527 Subp_Index : out Entity_Id;
528 Stmts : out List_Id;
529 Decl : out Node_Id);
530 -- Make a subprogram body for an RPC receiver, with the given
531 -- defining unit name. On return:
532 -- - Subp_Id is the subprogram identifier from the PCS.
533 -- - Subp_Index is the index in the list of subprograms
534 -- used for dispatching (a variable of type Subprogram_Id).
535 -- - Stmts is the place where the request dispatching
536 -- statements can occur,
537 -- - Decl is the subprogram body declaration.
539 function Specific_Build_Subprogram_Receiving_Stubs
540 (Vis_Decl : Node_Id;
541 Asynchronous : Boolean;
542 Dynamically_Asynchronous : Boolean := False;
543 Stub_Type : Entity_Id := Empty;
544 RACW_Type : Entity_Id := Empty;
545 Parent_Primitive : Entity_Id := Empty) return Node_Id;
546 -- Build the receiving stub for a given subprogram. The subprogram
547 -- declaration is also built by this procedure, and the value returned
548 -- is a N_Subprogram_Body. If a parameter of type access to Stub_Type is
549 -- found in the specification, then its address is read from the stream
550 -- instead of the object itself and converted into an access to
551 -- class-wide type before doing the real call using any of the RACW type
552 -- pointing on the designated type.
554 procedure Specific_Add_Obj_RPC_Receiver_Completion
555 (Loc : Source_Ptr;
556 Decls : List_Id;
557 RPC_Receiver : Entity_Id;
558 Stub_Elements : Stub_Structure);
559 -- Add the necessary code to Decls after the completion of generation
560 -- of the RACW RPC receiver described by Stub_Elements.
562 procedure Specific_Add_Receiving_Stubs_To_Declarations
563 (Pkg_Spec : Node_Id;
564 Decls : List_Id);
565 -- Add receiving stubs to the declarative part of an RCI unit
567 package GARLIC_Support is
569 -- Support for generating DSA code that uses the GARLIC PCS
571 -- The subprograms below provide the GARLIC versions of
572 -- the corresponding Specific_<subprogram> routine declared
573 -- above.
575 procedure Add_RACW_Features
576 (RACW_Type : Entity_Id;
577 Stub_Type : Entity_Id;
578 Stub_Type_Access : Entity_Id;
579 RPC_Receiver_Decl : Node_Id;
580 Declarations : List_Id);
582 procedure Add_RAST_Features
583 (Vis_Decl : Node_Id;
584 RAS_Type : Entity_Id;
585 Decls : List_Id);
587 procedure Build_General_Calling_Stubs
588 (Decls : List_Id;
589 Statements : List_Id;
590 Target_Partition : Entity_Id; -- From RPC_Target
591 Target_RPC_Receiver : Node_Id; -- From RPC_Target
592 Subprogram_Id : Node_Id;
593 Asynchronous : Node_Id := Empty;
594 Is_Known_Asynchronous : Boolean := False;
595 Is_Known_Non_Asynchronous : Boolean := False;
596 Is_Function : Boolean;
597 Spec : Node_Id;
598 Stub_Type : Entity_Id := Empty;
599 RACW_Type : Entity_Id := Empty;
600 Nod : Node_Id);
602 function Build_Stub_Target
603 (Loc : Source_Ptr;
604 Decls : List_Id;
605 RCI_Locator : Entity_Id;
606 Controlling_Parameter : Entity_Id) return RPC_Target;
608 procedure Build_Stub_Type
609 (RACW_Type : Entity_Id;
610 Stub_Type : Entity_Id;
611 Stub_Type_Decl : out Node_Id;
612 RPC_Receiver_Decl : out Node_Id);
614 function Build_Subprogram_Receiving_Stubs
615 (Vis_Decl : Node_Id;
616 Asynchronous : Boolean;
617 Dynamically_Asynchronous : Boolean := False;
618 Stub_Type : Entity_Id := Empty;
619 RACW_Type : Entity_Id := Empty;
620 Parent_Primitive : Entity_Id := Empty) return Node_Id;
622 procedure Add_Obj_RPC_Receiver_Completion
623 (Loc : Source_Ptr;
624 Decls : List_Id;
625 RPC_Receiver : Entity_Id;
626 Stub_Elements : Stub_Structure);
628 procedure Add_Receiving_Stubs_To_Declarations
629 (Pkg_Spec : Node_Id;
630 Decls : List_Id);
632 procedure Build_RPC_Receiver_Body
633 (RPC_Receiver : Entity_Id;
634 Request : out Entity_Id;
635 Subp_Id : out Entity_Id;
636 Subp_Index : out Entity_Id;
637 Stmts : out List_Id;
638 Decl : out Node_Id);
640 end GARLIC_Support;
642 package PolyORB_Support is
644 -- Support for generating DSA code that uses the PolyORB PCS
646 -- The subprograms below provide the PolyORB versions of
647 -- the corresponding Specific_<subprogram> routine declared
648 -- above.
650 procedure Add_RACW_Features
651 (RACW_Type : Entity_Id;
652 Desig : Entity_Id;
653 Stub_Type : Entity_Id;
654 Stub_Type_Access : Entity_Id;
655 RPC_Receiver_Decl : Node_Id;
656 Declarations : List_Id);
658 procedure Add_RAST_Features
659 (Vis_Decl : Node_Id;
660 RAS_Type : Entity_Id;
661 Decls : List_Id);
663 procedure Build_General_Calling_Stubs
664 (Decls : List_Id;
665 Statements : List_Id;
666 Target_Object : Node_Id; -- From RPC_Target
667 Subprogram_Id : Node_Id;
668 Asynchronous : Node_Id := Empty;
669 Is_Known_Asynchronous : Boolean := False;
670 Is_Known_Non_Asynchronous : Boolean := False;
671 Is_Function : Boolean;
672 Spec : Node_Id;
673 Stub_Type : Entity_Id := Empty;
674 RACW_Type : Entity_Id := Empty;
675 Nod : Node_Id);
677 function Build_Stub_Target
678 (Loc : Source_Ptr;
679 Decls : List_Id;
680 RCI_Locator : Entity_Id;
681 Controlling_Parameter : Entity_Id) return RPC_Target;
683 procedure Build_Stub_Type
684 (RACW_Type : Entity_Id;
685 Stub_Type : Entity_Id;
686 Stub_Type_Decl : out Node_Id;
687 RPC_Receiver_Decl : out Node_Id);
689 function Build_Subprogram_Receiving_Stubs
690 (Vis_Decl : Node_Id;
691 Asynchronous : Boolean;
692 Dynamically_Asynchronous : Boolean := False;
693 Stub_Type : Entity_Id := Empty;
694 RACW_Type : Entity_Id := Empty;
695 Parent_Primitive : Entity_Id := Empty) return Node_Id;
697 procedure Add_Obj_RPC_Receiver_Completion
698 (Loc : Source_Ptr;
699 Decls : List_Id;
700 RPC_Receiver : Entity_Id;
701 Stub_Elements : Stub_Structure);
703 procedure Add_Receiving_Stubs_To_Declarations
704 (Pkg_Spec : Node_Id;
705 Decls : List_Id);
707 procedure Build_RPC_Receiver_Body
708 (RPC_Receiver : Entity_Id;
709 Request : out Entity_Id;
710 Subp_Id : out Entity_Id;
711 Subp_Index : out Entity_Id;
712 Stmts : out List_Id;
713 Decl : out Node_Id);
715 procedure Reserve_NamingContext_Methods;
716 -- Mark the method names for interface NamingContext as already used in
717 -- the overload table, so no clashes occur with user code (with the
718 -- PolyORB PCS, RCIs Implement The NamingContext interface to allow
719 -- their methods to be accessed as objects, for the implementation of
720 -- remote access-to-subprogram types).
722 package Helpers is
724 -- Routines to build distribtion helper subprograms for user-defined
725 -- types. For implementation of the Distributed systems annex (DSA)
726 -- over the PolyORB generic middleware components, it is necessary to
727 -- generate several supporting subprograms for each application data
728 -- type used in inter-partition communication. These subprograms are:
729 -- * a Typecode function returning a high-level description of the
730 -- type's structure;
731 -- * two conversion functions allowing conversion of values of the
732 -- type from and to the generic data containers used by PolyORB.
733 -- These generic containers are called 'Any' type values after
734 -- the CORBA terminology, and hence the conversion subprograms
735 -- are named To_Any and From_Any.
737 function Build_From_Any_Call
738 (Typ : Entity_Id;
739 N : Node_Id;
740 Decls : List_Id) return Node_Id;
741 -- Build call to From_Any attribute function of type Typ with
742 -- expression N as actual parameter. Decls is the declarations list
743 -- for an appropriate enclosing scope of the point where the call
744 -- will be inserted; if the From_Any attribute for Typ needs to be
745 -- generated at this point, its declaration is appended to Decls.
747 procedure Build_From_Any_Function
748 (Loc : Source_Ptr;
749 Typ : Entity_Id;
750 Decl : out Node_Id;
751 Fnam : out Entity_Id);
752 -- Build From_Any attribute function for Typ. Loc is the reference
753 -- location for generated nodes, Typ is the type for which the
754 -- conversion function is generated. On return, Decl and Fnam contain
755 -- the declaration and entity for the newly-created function.
757 function Build_To_Any_Call
758 (N : Node_Id;
759 Decls : List_Id) return Node_Id;
760 -- Build call to To_Any attribute function with expression as actual
761 -- parameter. Decls is the declarations list for an appropriate
762 -- enclosing scope of the point where the call will be inserted; if
763 -- the To_Any attribute for Typ needs to be generated at this point,
764 -- its declaration is appended to Decls.
766 procedure Build_To_Any_Function
767 (Loc : Source_Ptr;
768 Typ : Entity_Id;
769 Decl : out Node_Id;
770 Fnam : out Entity_Id);
771 -- Build To_Any attribute function for Typ. Loc is the reference
772 -- location for generated nodes, Typ is the type for which the
773 -- conversion function is generated. On return, Decl and Fnam contain
774 -- the declaration and entity for the newly-created function.
776 function Build_TypeCode_Call
777 (Loc : Source_Ptr;
778 Typ : Entity_Id;
779 Decls : List_Id) return Node_Id;
780 -- Build call to TypeCode attribute function for Typ. Decls is the
781 -- declarations list for an appropriate enclosing scope of the point
782 -- where the call will be inserted; if the To_Any attribute for Typ
783 -- needs to be generated at this point, its declaration is appended
784 -- to Decls.
786 procedure Build_TypeCode_Function
787 (Loc : Source_Ptr;
788 Typ : Entity_Id;
789 Decl : out Node_Id;
790 Fnam : out Entity_Id);
791 -- Build TypeCode attribute function for Typ. Loc is the reference
792 -- location for generated nodes, Typ is the type for which the
793 -- conversion function is generated. On return, Decl and Fnam contain
794 -- the declaration and entity for the newly-created function.
796 procedure Build_Name_And_Repository_Id
797 (E : Entity_Id;
798 Name_Str : out String_Id;
799 Repo_Id_Str : out String_Id);
800 -- In the PolyORB distribution model, each distributed object type
801 -- and each distributed operation has a globally unique identifier,
802 -- its Repository Id. This subprogram builds and returns two strings
803 -- for entity E (a distributed object type or operation): one
804 -- containing the name of E, the second containing its repository id.
806 end Helpers;
808 end PolyORB_Support;
810 ------------------------------------
811 -- Local variables and structures --
812 ------------------------------------
814 RCI_Cache : Node_Id;
815 -- Needs comments ???
817 Output_From_Constrained : constant array (Boolean) of Name_Id :=
818 (False => Name_Output,
819 True => Name_Write);
820 -- The attribute to choose depending on the fact that the parameter
821 -- is constrained or not. There is no such thing as Input_From_Constrained
822 -- since this require separate mechanisms ('Input is a function while
823 -- 'Read is a procedure).
825 ---------------------------------------
826 -- Add_Calling_Stubs_To_Declarations --
827 ---------------------------------------
829 procedure Add_Calling_Stubs_To_Declarations
830 (Pkg_Spec : Node_Id;
831 Decls : List_Id)
833 Current_Subprogram_Number : Int := First_RCI_Subprogram_Id;
834 -- Subprogram id 0 is reserved for calls received from
835 -- remote access-to-subprogram dereferences.
837 Current_Declaration : Node_Id;
838 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
839 RCI_Instantiation : Node_Id;
840 Subp_Stubs : Node_Id;
841 Subp_Str : String_Id;
843 begin
844 -- The first thing added is an instantiation of the generic package
845 -- System.Partition_Interface.RCI_Locator with the name of this
846 -- remote package. This will act as an interface with the name server
847 -- to determine the Partition_ID and the RPC_Receiver for the
848 -- receiver of this package.
850 RCI_Instantiation := RCI_Package_Locator (Loc, Pkg_Spec);
851 RCI_Cache := Defining_Unit_Name (RCI_Instantiation);
853 Append_To (Decls, RCI_Instantiation);
854 Analyze (RCI_Instantiation);
856 -- For each subprogram declaration visible in the spec, we do
857 -- build a body. We also increment a counter to assign a different
858 -- Subprogram_Id to each subprograms. The receiving stubs processing
859 -- do use the same mechanism and will thus assign the same Id and
860 -- do the correct dispatching.
862 Overload_Counter_Table.Reset;
863 PolyORB_Support.Reserve_NamingContext_Methods;
865 Current_Declaration := First (Visible_Declarations (Pkg_Spec));
867 while Present (Current_Declaration) loop
868 if Nkind (Current_Declaration) = N_Subprogram_Declaration
869 and then Comes_From_Source (Current_Declaration)
870 then
871 Assign_Subprogram_Identifier (
872 Defining_Unit_Name (Specification (Current_Declaration)),
873 Current_Subprogram_Number,
874 Subp_Str);
876 Subp_Stubs :=
877 Build_Subprogram_Calling_Stubs (
878 Vis_Decl => Current_Declaration,
879 Subp_Id =>
880 Build_Subprogram_Id (Loc,
881 Defining_Unit_Name (Specification (Current_Declaration))),
882 Asynchronous =>
883 Nkind (Specification (Current_Declaration)) =
884 N_Procedure_Specification
885 and then
886 Is_Asynchronous (Defining_Unit_Name (Specification
887 (Current_Declaration))));
889 Append_To (Decls, Subp_Stubs);
890 Analyze (Subp_Stubs);
892 Current_Subprogram_Number := Current_Subprogram_Number + 1;
893 end if;
895 Next (Current_Declaration);
896 end loop;
897 end Add_Calling_Stubs_To_Declarations;
899 -----------------------------
900 -- Add_Parameter_To_NVList --
901 -----------------------------
903 function Add_Parameter_To_NVList
904 (Loc : Source_Ptr;
905 NVList : Entity_Id;
906 Parameter : Entity_Id;
907 Constrained : Boolean;
908 RACW_Ctrl : Boolean := False;
909 Any : Entity_Id) return Node_Id
911 Parameter_Name_String : String_Id;
912 Parameter_Mode : Node_Id;
914 function Parameter_Passing_Mode
915 (Loc : Source_Ptr;
916 Parameter : Entity_Id;
917 Constrained : Boolean) return Node_Id;
918 -- Return an expression that denotes the parameter passing
919 -- mode to be used for Parameter in distribution stubs,
920 -- where Constrained is Parameter's constrained status.
922 ----------------------------
923 -- Parameter_Passing_Mode --
924 ----------------------------
926 function Parameter_Passing_Mode
927 (Loc : Source_Ptr;
928 Parameter : Entity_Id;
929 Constrained : Boolean) return Node_Id
931 Lib_RE : RE_Id;
933 begin
934 if Out_Present (Parameter) then
935 if In_Present (Parameter)
936 or else not Constrained
937 then
938 -- Unconstrained formals must be translated
939 -- to 'in' or 'inout', not 'out', because
940 -- they need to be constrained by the actual.
942 Lib_RE := RE_Mode_Inout;
943 else
944 Lib_RE := RE_Mode_Out;
945 end if;
947 else
948 Lib_RE := RE_Mode_In;
949 end if;
951 return New_Occurrence_Of (RTE (Lib_RE), Loc);
952 end Parameter_Passing_Mode;
954 -- Start of processing for Add_Parameter_To_NVList
956 begin
957 if Nkind (Parameter) = N_Defining_Identifier then
958 Get_Name_String (Chars (Parameter));
959 else
960 Get_Name_String (Chars (Defining_Identifier
961 (Parameter)));
962 end if;
964 Parameter_Name_String := String_From_Name_Buffer;
966 if RACW_Ctrl then
967 Parameter_Mode := New_Occurrence_Of
968 (RTE (RE_Mode_In), Loc);
969 else
970 Parameter_Mode := Parameter_Passing_Mode (Loc,
971 Parameter, Constrained);
972 end if;
974 return
975 Make_Procedure_Call_Statement (Loc,
976 Name =>
977 New_Occurrence_Of
978 (RTE (RE_NVList_Add_Item), Loc),
979 Parameter_Associations => New_List (
980 New_Occurrence_Of (NVList, Loc),
981 Make_Function_Call (Loc,
982 Name =>
983 New_Occurrence_Of
984 (RTE (RE_To_PolyORB_String), Loc),
985 Parameter_Associations => New_List (
986 Make_String_Literal (Loc,
987 Strval => Parameter_Name_String))),
988 New_Occurrence_Of (Any, Loc),
989 Parameter_Mode));
990 end Add_Parameter_To_NVList;
992 --------------------------------
993 -- Add_RACW_Asynchronous_Flag --
994 --------------------------------
996 procedure Add_RACW_Asynchronous_Flag
997 (Declarations : List_Id;
998 RACW_Type : Entity_Id)
1000 Loc : constant Source_Ptr := Sloc (RACW_Type);
1002 Asynchronous_Flag : constant Entity_Id :=
1003 Make_Defining_Identifier (Loc,
1004 New_External_Name (Chars (RACW_Type), 'A'));
1006 begin
1007 -- Declare the asynchronous flag. This flag will be changed to True
1008 -- whenever it is known that the RACW type is asynchronous.
1010 Append_To (Declarations,
1011 Make_Object_Declaration (Loc,
1012 Defining_Identifier => Asynchronous_Flag,
1013 Constant_Present => True,
1014 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
1015 Expression => New_Occurrence_Of (Standard_False, Loc)));
1017 Asynchronous_Flags_Table.Set (RACW_Type, Asynchronous_Flag);
1018 end Add_RACW_Asynchronous_Flag;
1020 -----------------------
1021 -- Add_RACW_Features --
1022 -----------------------
1024 procedure Add_RACW_Features (RACW_Type : Entity_Id)
1026 Desig : constant Entity_Id :=
1027 Etype (Designated_Type (RACW_Type));
1028 Decls : List_Id :=
1029 List_Containing (Declaration_Node (RACW_Type));
1031 Same_Scope : constant Boolean :=
1032 Scope (Desig) = Scope (RACW_Type);
1034 Stub_Type : Entity_Id;
1035 Stub_Type_Access : Entity_Id;
1036 RPC_Receiver_Decl : Node_Id;
1037 Existing : Boolean;
1039 begin
1040 if not Expander_Active then
1041 return;
1042 end if;
1044 if Same_Scope then
1046 -- We are declaring a RACW in the same package than its designated
1047 -- type, so the list to use for late declarations must be the
1048 -- private part of the package. We do know that this private part
1049 -- exists since the designated type has to be a private one.
1051 Decls := Private_Declarations
1052 (Package_Specification_Of_Scope (Current_Scope));
1054 elsif Nkind (Parent (Decls)) = N_Package_Specification
1055 and then Present (Private_Declarations (Parent (Decls)))
1056 then
1057 Decls := Private_Declarations (Parent (Decls));
1058 end if;
1060 -- If we were unable to find the declarations, that means that the
1061 -- completion of the type was missing. We can safely return and let
1062 -- the error be caught by the semantic analysis.
1064 if No (Decls) then
1065 return;
1066 end if;
1068 Add_Stub_Type
1069 (Designated_Type => Desig,
1070 RACW_Type => RACW_Type,
1071 Decls => Decls,
1072 Stub_Type => Stub_Type,
1073 Stub_Type_Access => Stub_Type_Access,
1074 RPC_Receiver_Decl => RPC_Receiver_Decl,
1075 Existing => Existing);
1077 Add_RACW_Asynchronous_Flag
1078 (Declarations => Decls,
1079 RACW_Type => RACW_Type);
1081 Specific_Add_RACW_Features
1082 (RACW_Type => RACW_Type,
1083 Desig => Desig,
1084 Stub_Type => Stub_Type,
1085 Stub_Type_Access => Stub_Type_Access,
1086 RPC_Receiver_Decl => RPC_Receiver_Decl,
1087 Declarations => Decls);
1089 if not Same_Scope and then not Existing then
1091 -- The RACW has been declared in another scope than the designated
1092 -- type and has not been handled by another RACW in the same package
1093 -- as the first one, so add primitive for the stub type here.
1095 Add_RACW_Primitive_Declarations_And_Bodies
1096 (Designated_Type => Desig,
1097 Insertion_Node => RPC_Receiver_Decl,
1098 Decls => Decls);
1100 else
1101 Add_Access_Type_To_Process (E => Desig, A => RACW_Type);
1102 end if;
1103 end Add_RACW_Features;
1105 ------------------------------------------------
1106 -- Add_RACW_Primitive_Declarations_And_Bodies --
1107 ------------------------------------------------
1109 procedure Add_RACW_Primitive_Declarations_And_Bodies
1110 (Designated_Type : Entity_Id;
1111 Insertion_Node : Node_Id;
1112 Decls : List_Id)
1114 -- Set Sloc of generated declaration copy of insertion node Sloc, so
1115 -- the declarations are recognized as belonging to the current package.
1117 Loc : constant Source_Ptr := Sloc (Insertion_Node);
1119 Stub_Elements : constant Stub_Structure :=
1120 Stubs_Table.Get (Designated_Type);
1122 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
1123 Is_RAS : constant Boolean :=
1124 not Comes_From_Source (Stub_Elements.RACW_Type);
1126 Current_Insertion_Node : Node_Id := Insertion_Node;
1128 RPC_Receiver : Entity_Id;
1129 RPC_Receiver_Statements : List_Id;
1130 RPC_Receiver_Case_Alternatives : constant List_Id := New_List;
1131 RPC_Receiver_Elsif_Parts : List_Id;
1132 RPC_Receiver_Request : Entity_Id;
1133 RPC_Receiver_Subp_Id : Entity_Id;
1134 RPC_Receiver_Subp_Index : Entity_Id;
1136 Subp_Str : String_Id;
1138 Current_Primitive_Elmt : Elmt_Id;
1139 Current_Primitive : Entity_Id;
1140 Current_Primitive_Body : Node_Id;
1141 Current_Primitive_Spec : Node_Id;
1142 Current_Primitive_Decl : Node_Id;
1143 Current_Primitive_Number : Int := 0;
1145 Current_Primitive_Alias : Node_Id;
1147 Current_Receiver : Entity_Id;
1148 Current_Receiver_Body : Node_Id;
1150 RPC_Receiver_Decl : Node_Id;
1152 Possibly_Asynchronous : Boolean;
1154 begin
1155 if not Expander_Active then
1156 return;
1157 end if;
1159 if not Is_RAS then
1160 RPC_Receiver := Make_Defining_Identifier (Loc,
1161 New_Internal_Name ('P'));
1162 Specific_Build_RPC_Receiver_Body (
1163 RPC_Receiver => RPC_Receiver,
1164 Request => RPC_Receiver_Request,
1165 Subp_Id => RPC_Receiver_Subp_Id,
1166 Subp_Index => RPC_Receiver_Subp_Index,
1167 Stmts => RPC_Receiver_Statements,
1168 Decl => RPC_Receiver_Decl);
1170 if Get_PCS_Name = Name_PolyORB_DSA then
1172 -- For the case of PolyORB, we need to map a textual operation
1173 -- name into a primitive index. Currently we do so using a
1174 -- simple sequence of string comparisons.
1176 RPC_Receiver_Elsif_Parts := New_List;
1177 Append_To (RPC_Receiver_Statements,
1178 Make_Implicit_If_Statement (Designated_Type,
1179 Condition => New_Occurrence_Of (Standard_False, Loc),
1180 Then_Statements => New_List,
1181 Elsif_Parts => RPC_Receiver_Elsif_Parts));
1182 end if;
1183 end if;
1185 -- Build callers, receivers for every primitive operations and a RPC
1186 -- receiver for this type.
1188 if Present (Primitive_Operations (Designated_Type)) then
1189 Overload_Counter_Table.Reset;
1191 Current_Primitive_Elmt :=
1192 First_Elmt (Primitive_Operations (Designated_Type));
1193 while Current_Primitive_Elmt /= No_Elmt loop
1194 Current_Primitive := Node (Current_Primitive_Elmt);
1196 -- Copy the primitive of all the parents, except predefined
1197 -- ones that are not remotely dispatching.
1199 if Chars (Current_Primitive) /= Name_uSize
1200 and then Chars (Current_Primitive) /= Name_uAlignment
1201 and then not Is_TSS (Current_Primitive, TSS_Deep_Finalize)
1202 then
1203 -- The first thing to do is build an up-to-date copy of
1204 -- the spec with all the formals referencing Designated_Type
1205 -- transformed into formals referencing Stub_Type. Since this
1206 -- primitive may have been inherited, go back the alias chain
1207 -- until the real primitive has been found.
1209 Current_Primitive_Alias := Current_Primitive;
1210 while Present (Alias (Current_Primitive_Alias)) loop
1211 pragma Assert
1212 (Current_Primitive_Alias
1213 /= Alias (Current_Primitive_Alias));
1214 Current_Primitive_Alias := Alias (Current_Primitive_Alias);
1215 end loop;
1217 Current_Primitive_Spec :=
1218 Copy_Specification (Loc,
1219 Spec => Parent (Current_Primitive_Alias),
1220 Object_Type => Designated_Type,
1221 Stub_Type => Stub_Elements.Stub_Type);
1223 Current_Primitive_Decl :=
1224 Make_Subprogram_Declaration (Loc,
1225 Specification => Current_Primitive_Spec);
1227 Insert_After (Current_Insertion_Node, Current_Primitive_Decl);
1228 Analyze (Current_Primitive_Decl);
1229 Current_Insertion_Node := Current_Primitive_Decl;
1231 Possibly_Asynchronous :=
1232 Nkind (Current_Primitive_Spec) = N_Procedure_Specification
1233 and then Could_Be_Asynchronous (Current_Primitive_Spec);
1235 Assign_Subprogram_Identifier (
1236 Defining_Unit_Name (Current_Primitive_Spec),
1237 Current_Primitive_Number,
1238 Subp_Str);
1240 Current_Primitive_Body :=
1241 Build_Subprogram_Calling_Stubs
1242 (Vis_Decl => Current_Primitive_Decl,
1243 Subp_Id =>
1244 Build_Subprogram_Id (Loc,
1245 Defining_Unit_Name (Current_Primitive_Spec)),
1246 Asynchronous => Possibly_Asynchronous,
1247 Dynamically_Asynchronous => Possibly_Asynchronous,
1248 Stub_Type => Stub_Elements.Stub_Type,
1249 RACW_Type => Stub_Elements.RACW_Type);
1250 Append_To (Decls, Current_Primitive_Body);
1252 -- Analyzing the body here would cause the Stub type to be
1253 -- frozen, thus preventing subsequent primitive declarations.
1254 -- For this reason, it will be analyzed later in the
1255 -- regular flow.
1257 -- Build the receiver stubs
1259 if not Is_RAS then
1260 Current_Receiver_Body :=
1261 Specific_Build_Subprogram_Receiving_Stubs
1262 (Vis_Decl => Current_Primitive_Decl,
1263 Asynchronous => Possibly_Asynchronous,
1264 Dynamically_Asynchronous => Possibly_Asynchronous,
1265 Stub_Type => Stub_Elements.Stub_Type,
1266 RACW_Type => Stub_Elements.RACW_Type,
1267 Parent_Primitive => Current_Primitive);
1269 Current_Receiver := Defining_Unit_Name (
1270 Specification (Current_Receiver_Body));
1272 Append_To (Decls, Current_Receiver_Body);
1274 -- Add a case alternative to the receiver
1276 if Get_PCS_Name = Name_PolyORB_DSA then
1277 Append_To (RPC_Receiver_Elsif_Parts,
1278 Make_Elsif_Part (Loc,
1279 Condition =>
1280 Make_Function_Call (Loc,
1281 Name =>
1282 New_Occurrence_Of (
1283 RTE (RE_Caseless_String_Eq), Loc),
1284 Parameter_Associations => New_List (
1285 New_Occurrence_Of (RPC_Receiver_Subp_Id, Loc),
1286 Make_String_Literal (Loc, Subp_Str))),
1287 Then_Statements => New_List (
1288 Make_Assignment_Statement (Loc,
1289 Name => New_Occurrence_Of (
1290 RPC_Receiver_Subp_Index, Loc),
1291 Expression =>
1292 Make_Integer_Literal (Loc,
1293 Current_Primitive_Number)))));
1294 end if;
1296 Append_To (RPC_Receiver_Case_Alternatives,
1297 Make_Case_Statement_Alternative (Loc,
1298 Discrete_Choices => New_List (
1299 Make_Integer_Literal (Loc, Current_Primitive_Number)),
1301 Statements => New_List (
1302 Make_Procedure_Call_Statement (Loc,
1303 Name =>
1304 New_Occurrence_Of (Current_Receiver, Loc),
1305 Parameter_Associations => New_List (
1306 New_Occurrence_Of (RPC_Receiver_Request, Loc))))));
1307 end if;
1309 -- Increment the index of current primitive
1311 Current_Primitive_Number := Current_Primitive_Number + 1;
1312 end if;
1314 Next_Elmt (Current_Primitive_Elmt);
1315 end loop;
1316 end if;
1318 -- Build the case statement and the heart of the subprogram
1320 if not Is_RAS then
1321 Append_To (RPC_Receiver_Case_Alternatives,
1322 Make_Case_Statement_Alternative (Loc,
1323 Discrete_Choices => New_List (Make_Others_Choice (Loc)),
1324 Statements => New_List (Make_Null_Statement (Loc))));
1326 Append_To (RPC_Receiver_Statements,
1327 Make_Case_Statement (Loc,
1328 Expression =>
1329 New_Occurrence_Of (RPC_Receiver_Subp_Index, Loc),
1330 Alternatives => RPC_Receiver_Case_Alternatives));
1332 Append_To (Decls, RPC_Receiver_Decl);
1333 Specific_Add_Obj_RPC_Receiver_Completion (Loc,
1334 Decls, RPC_Receiver, Stub_Elements);
1335 end if;
1337 -- Do not analyze RPC receiver at this stage since it will otherwise
1338 -- reference subprograms that have not been analyzed yet. It will
1339 -- be analyzed in the regular flow.
1341 end Add_RACW_Primitive_Declarations_And_Bodies;
1343 -----------------------------
1344 -- Add_RAS_Dereference_TSS --
1345 -----------------------------
1347 procedure Add_RAS_Dereference_TSS (N : Node_Id) is
1348 Loc : constant Source_Ptr := Sloc (N);
1350 Type_Def : constant Node_Id := Type_Definition (N);
1352 RAS_Type : constant Entity_Id := Defining_Identifier (N);
1353 Fat_Type : constant Entity_Id := Equivalent_Type (RAS_Type);
1354 RACW_Type : constant Entity_Id := Underlying_RACW_Type (RAS_Type);
1355 Desig : constant Entity_Id := Etype (Designated_Type (RACW_Type));
1357 Stub_Elements : constant Stub_Structure := Stubs_Table.Get (Desig);
1358 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
1360 RACW_Primitive_Name : Node_Id;
1362 Proc : constant Entity_Id :=
1363 Make_Defining_Identifier (Loc,
1364 Chars => Make_TSS_Name (RAS_Type, TSS_RAS_Dereference));
1366 Proc_Spec : Node_Id;
1367 Param_Specs : List_Id;
1368 Param_Assoc : constant List_Id := New_List;
1369 Stmts : constant List_Id := New_List;
1371 RAS_Parameter : constant Entity_Id :=
1372 Make_Defining_Identifier (Loc,
1373 Chars => New_Internal_Name ('P'));
1375 Is_Function : constant Boolean :=
1376 Nkind (Type_Def) = N_Access_Function_Definition;
1378 Is_Degenerate : Boolean;
1379 -- Set to True if the subprogram_specification for this RAS has
1380 -- an anonymous access parameter (see Process_Remote_AST_Declaration).
1382 Spec : constant Node_Id := Type_Def;
1384 Current_Parameter : Node_Id;
1386 -- Start of processing for Add_RAS_Dereference_TSS
1388 begin
1389 -- The Dereference TSS for a remote access-to-subprogram type
1390 -- has the form:
1392 -- [function|procedure] ras_typeRD (RAS_Value, <RAS_Parameters>)
1393 -- [return <>]
1395 -- This is called whenever a value of a RAS type is dereferenced
1397 -- First construct a list of parameter specifications:
1399 -- The first formal is the RAS values
1401 Param_Specs := New_List (
1402 Make_Parameter_Specification (Loc,
1403 Defining_Identifier => RAS_Parameter,
1404 In_Present => True,
1405 Parameter_Type =>
1406 New_Occurrence_Of (Fat_Type, Loc)));
1408 -- The following formals are copied from the type declaration
1410 Is_Degenerate := False;
1411 Current_Parameter := First (Parameter_Specifications (Type_Def));
1412 Parameters : while Present (Current_Parameter) loop
1413 if Nkind (Parameter_Type (Current_Parameter))
1414 = N_Access_Definition
1415 then
1416 Is_Degenerate := True;
1417 end if;
1418 Append_To (Param_Specs,
1419 Make_Parameter_Specification (Loc,
1420 Defining_Identifier =>
1421 Make_Defining_Identifier (Loc,
1422 Chars => Chars (Defining_Identifier (Current_Parameter))),
1423 In_Present => In_Present (Current_Parameter),
1424 Out_Present => Out_Present (Current_Parameter),
1425 Parameter_Type =>
1426 New_Copy_Tree (Parameter_Type (Current_Parameter)),
1427 Expression =>
1428 New_Copy_Tree (Expression (Current_Parameter))));
1430 Append_To (Param_Assoc,
1431 Make_Identifier (Loc,
1432 Chars => Chars (Defining_Identifier (Current_Parameter))));
1434 Next (Current_Parameter);
1435 end loop Parameters;
1437 if Is_Degenerate then
1438 Prepend_To (Param_Assoc, New_Occurrence_Of (RAS_Parameter, Loc));
1440 -- Generate a dummy body. This code will never actually be executed,
1441 -- because null is the only legal value for a degenerate RAS type.
1442 -- For legality's sake (in order to avoid generating a function
1443 -- that does not contain a return statement), we include a dummy
1444 -- recursive call on the TSS itself.
1446 Append_To (Stmts,
1447 Make_Raise_Program_Error (Loc, Reason => PE_Explicit_Raise));
1448 RACW_Primitive_Name := New_Occurrence_Of (Proc, Loc);
1450 else
1451 -- For a normal RAS type, we cast the RAS formal to the corresponding
1452 -- tagged type, and perform a dispatching call to its Call
1453 -- primitive operation.
1455 Prepend_To (Param_Assoc,
1456 Unchecked_Convert_To (RACW_Type,
1457 New_Occurrence_Of (RAS_Parameter, Loc)));
1459 RACW_Primitive_Name := Make_Selected_Component (Loc,
1460 Prefix => Scope (RACW_Type),
1461 Selector_Name => Name_Call);
1462 end if;
1464 if Is_Function then
1465 Append_To (Stmts,
1466 Make_Return_Statement (Loc,
1467 Expression =>
1468 Make_Function_Call (Loc,
1469 Name =>
1470 RACW_Primitive_Name,
1471 Parameter_Associations => Param_Assoc)));
1473 else
1474 Append_To (Stmts,
1475 Make_Procedure_Call_Statement (Loc,
1476 Name =>
1477 RACW_Primitive_Name,
1478 Parameter_Associations => Param_Assoc));
1479 end if;
1481 -- Build the complete subprogram
1483 if Is_Function then
1484 Proc_Spec :=
1485 Make_Function_Specification (Loc,
1486 Defining_Unit_Name => Proc,
1487 Parameter_Specifications => Param_Specs,
1488 Subtype_Mark =>
1489 New_Occurrence_Of (
1490 Entity (Subtype_Mark (Spec)), Loc));
1492 Set_Ekind (Proc, E_Function);
1493 Set_Etype (Proc,
1494 New_Occurrence_Of (Entity (Subtype_Mark (Spec)), Loc));
1496 else
1497 Proc_Spec :=
1498 Make_Procedure_Specification (Loc,
1499 Defining_Unit_Name => Proc,
1500 Parameter_Specifications => Param_Specs);
1502 Set_Ekind (Proc, E_Procedure);
1503 Set_Etype (Proc, Standard_Void_Type);
1504 end if;
1506 Discard_Node (
1507 Make_Subprogram_Body (Loc,
1508 Specification => Proc_Spec,
1509 Declarations => New_List,
1510 Handled_Statement_Sequence =>
1511 Make_Handled_Sequence_Of_Statements (Loc,
1512 Statements => Stmts)));
1514 Set_TSS (Fat_Type, Proc);
1515 end Add_RAS_Dereference_TSS;
1517 -------------------------------
1518 -- Add_RAS_Proxy_And_Analyze --
1519 -------------------------------
1521 procedure Add_RAS_Proxy_And_Analyze
1522 (Decls : List_Id;
1523 Vis_Decl : Node_Id;
1524 All_Calls_Remote_E : Entity_Id;
1525 Proxy_Object_Addr : out Entity_Id)
1527 Loc : constant Source_Ptr := Sloc (Vis_Decl);
1529 Subp_Name : constant Entity_Id :=
1530 Defining_Unit_Name (Specification (Vis_Decl));
1532 Pkg_Name : constant Entity_Id :=
1533 Make_Defining_Identifier (Loc,
1534 Chars =>
1535 New_External_Name (Chars (Subp_Name), 'P', -1));
1537 Proxy_Type : constant Entity_Id :=
1538 Make_Defining_Identifier (Loc,
1539 Chars =>
1540 New_External_Name (
1541 Related_Id => Chars (Subp_Name),
1542 Suffix => 'P'));
1544 Proxy_Type_Full_View : constant Entity_Id :=
1545 Make_Defining_Identifier (Loc,
1546 Chars (Proxy_Type));
1548 Subp_Decl_Spec : constant Node_Id :=
1549 Build_RAS_Primitive_Specification
1550 (Subp_Spec => Specification (Vis_Decl),
1551 Remote_Object_Type => Proxy_Type);
1553 Subp_Body_Spec : constant Node_Id :=
1554 Build_RAS_Primitive_Specification
1555 (Subp_Spec => Specification (Vis_Decl),
1556 Remote_Object_Type => Proxy_Type);
1558 Vis_Decls : constant List_Id := New_List;
1559 Pvt_Decls : constant List_Id := New_List;
1560 Actuals : constant List_Id := New_List;
1561 Formal : Node_Id;
1562 Perform_Call : Node_Id;
1564 begin
1565 -- type subpP is tagged limited private;
1567 Append_To (Vis_Decls,
1568 Make_Private_Type_Declaration (Loc,
1569 Defining_Identifier => Proxy_Type,
1570 Tagged_Present => True,
1571 Limited_Present => True));
1573 -- [subprogram] Call
1574 -- (Self : access subpP;
1575 -- ...other-formals...)
1576 -- [return T];
1578 Append_To (Vis_Decls,
1579 Make_Subprogram_Declaration (Loc,
1580 Specification => Subp_Decl_Spec));
1582 -- A : constant System.Address;
1584 Proxy_Object_Addr := Make_Defining_Identifier (Loc, Name_uA);
1586 Append_To (Vis_Decls,
1587 Make_Object_Declaration (Loc,
1588 Defining_Identifier =>
1589 Proxy_Object_Addr,
1590 Constant_Present =>
1591 True,
1592 Object_Definition =>
1593 New_Occurrence_Of (RTE (RE_Address), Loc)));
1595 -- private
1597 -- type subpP is tagged limited record
1598 -- All_Calls_Remote : Boolean := [All_Calls_Remote?];
1599 -- ...
1600 -- end record;
1602 Append_To (Pvt_Decls,
1603 Make_Full_Type_Declaration (Loc,
1604 Defining_Identifier =>
1605 Proxy_Type_Full_View,
1606 Type_Definition =>
1607 Build_Remote_Subprogram_Proxy_Type (Loc,
1608 New_Occurrence_Of (All_Calls_Remote_E, Loc))));
1610 -- Trick semantic analysis into swapping the public and
1611 -- full view when freezing the public view.
1613 Set_Comes_From_Source (Proxy_Type_Full_View, True);
1615 -- procedure Call
1616 -- (Self : access O;
1617 -- ...other-formals...) is
1618 -- begin
1619 -- P (...other-formals...);
1620 -- end Call;
1622 -- function Call
1623 -- (Self : access O;
1624 -- ...other-formals...)
1625 -- return T is
1626 -- begin
1627 -- return F (...other-formals...);
1628 -- end Call;
1630 if Nkind (Subp_Decl_Spec) = N_Procedure_Specification then
1631 Perform_Call :=
1632 Make_Procedure_Call_Statement (Loc,
1633 Name =>
1634 New_Occurrence_Of (Subp_Name, Loc),
1635 Parameter_Associations =>
1636 Actuals);
1637 else
1638 Perform_Call :=
1639 Make_Return_Statement (Loc,
1640 Expression =>
1641 Make_Function_Call (Loc,
1642 Name =>
1643 New_Occurrence_Of (Subp_Name, Loc),
1644 Parameter_Associations =>
1645 Actuals));
1646 end if;
1648 Formal := First (Parameter_Specifications (Subp_Decl_Spec));
1649 pragma Assert (Present (Formal));
1650 loop
1651 Next (Formal);
1652 exit when No (Formal);
1653 Append_To (Actuals,
1654 New_Occurrence_Of (Defining_Identifier (Formal), Loc));
1655 end loop;
1657 -- O : aliased subpP;
1659 Append_To (Pvt_Decls,
1660 Make_Object_Declaration (Loc,
1661 Defining_Identifier =>
1662 Make_Defining_Identifier (Loc,
1663 Name_uO),
1664 Aliased_Present =>
1665 True,
1666 Object_Definition =>
1667 New_Occurrence_Of (Proxy_Type, Loc)));
1669 -- A : constant System.Address := O'Address;
1671 Append_To (Pvt_Decls,
1672 Make_Object_Declaration (Loc,
1673 Defining_Identifier =>
1674 Make_Defining_Identifier (Loc,
1675 Chars (Proxy_Object_Addr)),
1676 Constant_Present =>
1677 True,
1678 Object_Definition =>
1679 New_Occurrence_Of (RTE (RE_Address), Loc),
1680 Expression =>
1681 Make_Attribute_Reference (Loc,
1682 Prefix => New_Occurrence_Of (
1683 Defining_Identifier (Last (Pvt_Decls)), Loc),
1684 Attribute_Name =>
1685 Name_Address)));
1687 Append_To (Decls,
1688 Make_Package_Declaration (Loc,
1689 Specification => Make_Package_Specification (Loc,
1690 Defining_Unit_Name => Pkg_Name,
1691 Visible_Declarations => Vis_Decls,
1692 Private_Declarations => Pvt_Decls,
1693 End_Label => Empty)));
1694 Analyze (Last (Decls));
1696 Append_To (Decls,
1697 Make_Package_Body (Loc,
1698 Defining_Unit_Name =>
1699 Make_Defining_Identifier (Loc,
1700 Chars (Pkg_Name)),
1701 Declarations => New_List (
1702 Make_Subprogram_Body (Loc,
1703 Specification =>
1704 Subp_Body_Spec,
1705 Declarations => New_List,
1706 Handled_Statement_Sequence =>
1707 Make_Handled_Sequence_Of_Statements (Loc,
1708 Statements => New_List (Perform_Call))))));
1709 Analyze (Last (Decls));
1710 end Add_RAS_Proxy_And_Analyze;
1712 -----------------------
1713 -- Add_RAST_Features --
1714 -----------------------
1716 procedure Add_RAST_Features (Vis_Decl : Node_Id) is
1717 RAS_Type : constant Entity_Id :=
1718 Equivalent_Type (Defining_Identifier (Vis_Decl));
1720 Spec : constant Node_Id :=
1721 Specification (Unit (Enclosing_Lib_Unit_Node (Vis_Decl)));
1722 Decls : List_Id := Private_Declarations (Spec);
1724 begin
1725 pragma Assert (No (TSS (RAS_Type, TSS_RAS_Access)));
1727 if No (Decls) then
1728 Decls := Visible_Declarations (Spec);
1729 end if;
1731 Add_RAS_Dereference_TSS (Vis_Decl);
1732 Specific_Add_RAST_Features (Vis_Decl, RAS_Type, Decls);
1733 end Add_RAST_Features;
1735 -------------------
1736 -- Add_Stub_Type --
1737 -------------------
1739 procedure Add_Stub_Type
1740 (Designated_Type : Entity_Id;
1741 RACW_Type : Entity_Id;
1742 Decls : List_Id;
1743 Stub_Type : out Entity_Id;
1744 Stub_Type_Access : out Entity_Id;
1745 RPC_Receiver_Decl : out Node_Id;
1746 Existing : out Boolean)
1748 Loc : constant Source_Ptr := Sloc (RACW_Type);
1750 Stub_Elements : constant Stub_Structure :=
1751 Stubs_Table.Get (Designated_Type);
1752 Stub_Type_Decl : Node_Id;
1753 Stub_Type_Access_Decl : Node_Id;
1755 begin
1756 if Stub_Elements /= Empty_Stub_Structure then
1757 Stub_Type := Stub_Elements.Stub_Type;
1758 Stub_Type_Access := Stub_Elements.Stub_Type_Access;
1759 RPC_Receiver_Decl := Stub_Elements.RPC_Receiver_Decl;
1760 Existing := True;
1761 return;
1762 end if;
1764 Existing := False;
1765 Stub_Type :=
1766 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
1767 Stub_Type_Access :=
1768 Make_Defining_Identifier (Loc,
1769 New_External_Name (
1770 Related_Id => Chars (Stub_Type),
1771 Suffix => 'A'));
1773 Specific_Build_Stub_Type (
1774 RACW_Type, Stub_Type,
1775 Stub_Type_Decl, RPC_Receiver_Decl);
1777 Stub_Type_Access_Decl :=
1778 Make_Full_Type_Declaration (Loc,
1779 Defining_Identifier => Stub_Type_Access,
1780 Type_Definition =>
1781 Make_Access_To_Object_Definition (Loc,
1782 All_Present => True,
1783 Subtype_Indication => New_Occurrence_Of (Stub_Type, Loc)));
1785 Append_To (Decls, Stub_Type_Decl);
1786 Analyze (Last (Decls));
1787 Append_To (Decls, Stub_Type_Access_Decl);
1788 Analyze (Last (Decls));
1790 -- This is in no way a type derivation, but we fake it to make
1791 -- sure that the dispatching table gets built with the corresponding
1792 -- primitive operations at the right place.
1794 Derive_Subprograms (Parent_Type => Designated_Type,
1795 Derived_Type => Stub_Type);
1797 if Present (RPC_Receiver_Decl) then
1798 Append_To (Decls, RPC_Receiver_Decl);
1799 else
1800 RPC_Receiver_Decl := Last (Decls);
1801 end if;
1803 Stubs_Table.Set (Designated_Type,
1804 (Stub_Type => Stub_Type,
1805 Stub_Type_Access => Stub_Type_Access,
1806 RPC_Receiver_Decl => RPC_Receiver_Decl,
1807 RACW_Type => RACW_Type));
1808 end Add_Stub_Type;
1810 ----------------------------------
1811 -- Assign_Subprogram_Identifier --
1812 ----------------------------------
1814 procedure Assign_Subprogram_Identifier
1815 (Def : Entity_Id;
1816 Spn : Int;
1817 Id : out String_Id)
1819 N : constant Name_Id := Chars (Def);
1821 Overload_Order : constant Int :=
1822 Overload_Counter_Table.Get (N) + 1;
1824 begin
1825 Overload_Counter_Table.Set (N, Overload_Order);
1827 Get_Name_String (N);
1829 -- Homonym handling: as in Exp_Dbug, but much simpler,
1830 -- because the only entities for which we have to generate
1831 -- names here need only to be disambiguated within their
1832 -- own scope.
1834 if Overload_Order > 1 then
1835 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "__";
1836 Name_Len := Name_Len + 2;
1837 Add_Nat_To_Name_Buffer (Overload_Order);
1838 end if;
1840 Id := String_From_Name_Buffer;
1841 Subprogram_Identifier_Table.Set (Def,
1842 Subprogram_Identifiers'(Str_Identifier => Id, Int_Identifier => Spn));
1843 end Assign_Subprogram_Identifier;
1845 ------------------------------
1846 -- Build_Get_Unique_RP_Call --
1847 ------------------------------
1849 function Build_Get_Unique_RP_Call
1850 (Loc : Source_Ptr;
1851 Pointer : Entity_Id;
1852 Stub_Type : Entity_Id) return List_Id
1854 begin
1855 return New_List (
1856 Make_Procedure_Call_Statement (Loc,
1857 Name =>
1858 New_Occurrence_Of (RTE (RE_Get_Unique_Remote_Pointer), Loc),
1859 Parameter_Associations => New_List (
1860 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
1861 New_Occurrence_Of (Pointer, Loc)))),
1863 Make_Assignment_Statement (Loc,
1864 Name =>
1865 Make_Selected_Component (Loc,
1866 Prefix =>
1867 New_Occurrence_Of (Pointer, Loc),
1868 Selector_Name =>
1869 New_Occurrence_Of (Tag_Component
1870 (Designated_Type (Etype (Pointer))), Loc)),
1871 Expression =>
1872 Make_Attribute_Reference (Loc,
1873 Prefix =>
1874 New_Occurrence_Of (Stub_Type, Loc),
1875 Attribute_Name =>
1876 Name_Tag)));
1878 -- Note: The assignment to Pointer._Tag is safe here because
1879 -- we carefully ensured that Stub_Type has exactly the same layout
1880 -- as System.Partition_Interface.RACW_Stub_Type.
1882 end Build_Get_Unique_RP_Call;
1884 -----------------------------------
1885 -- Build_Ordered_Parameters_List --
1886 -----------------------------------
1888 function Build_Ordered_Parameters_List (Spec : Node_Id) return List_Id is
1889 Constrained_List : List_Id;
1890 Unconstrained_List : List_Id;
1891 Current_Parameter : Node_Id;
1893 First_Parameter : Node_Id;
1894 For_RAS : Boolean := False;
1896 begin
1897 if not Present (Parameter_Specifications (Spec)) then
1898 return New_List;
1899 end if;
1901 Constrained_List := New_List;
1902 Unconstrained_List := New_List;
1903 First_Parameter := First (Parameter_Specifications (Spec));
1905 if Nkind (Parameter_Type (First_Parameter)) = N_Access_Definition
1906 and then Chars (Defining_Identifier (First_Parameter)) = Name_uS
1907 then
1908 For_RAS := True;
1909 end if;
1911 -- Loop through the parameters and add them to the right list
1913 Current_Parameter := First_Parameter;
1914 while Present (Current_Parameter) loop
1915 if (Nkind (Parameter_Type (Current_Parameter)) = N_Access_Definition
1916 or else
1917 Is_Constrained (Etype (Parameter_Type (Current_Parameter)))
1918 or else
1919 Is_Elementary_Type (Etype (Parameter_Type (Current_Parameter))))
1920 and then not (For_RAS and then Current_Parameter = First_Parameter)
1921 then
1922 Append_To (Constrained_List, New_Copy (Current_Parameter));
1923 else
1924 Append_To (Unconstrained_List, New_Copy (Current_Parameter));
1925 end if;
1927 Next (Current_Parameter);
1928 end loop;
1930 -- Unconstrained parameters are returned first
1932 Append_List_To (Unconstrained_List, Constrained_List);
1934 return Unconstrained_List;
1935 end Build_Ordered_Parameters_List;
1937 ----------------------------------
1938 -- Build_Passive_Partition_Stub --
1939 ----------------------------------
1941 procedure Build_Passive_Partition_Stub (U : Node_Id) is
1942 Pkg_Spec : Node_Id;
1943 Pkg_Name : String_Id;
1944 L : List_Id;
1945 Reg : Node_Id;
1946 Loc : constant Source_Ptr := Sloc (U);
1948 begin
1949 -- Verify that the implementation supports distribution, by accessing
1950 -- a type defined in the proper version of system.rpc
1952 declare
1953 Dist_OK : Entity_Id;
1954 pragma Warnings (Off, Dist_OK);
1955 begin
1956 Dist_OK := RTE (RE_Params_Stream_Type);
1957 end;
1959 -- Use body if present, spec otherwise
1961 if Nkind (U) = N_Package_Declaration then
1962 Pkg_Spec := Specification (U);
1963 L := Visible_Declarations (Pkg_Spec);
1964 else
1965 Pkg_Spec := Parent (Corresponding_Spec (U));
1966 L := Declarations (U);
1967 end if;
1969 Get_Library_Unit_Name_String (Pkg_Spec);
1970 Pkg_Name := String_From_Name_Buffer;
1971 Reg :=
1972 Make_Procedure_Call_Statement (Loc,
1973 Name =>
1974 New_Occurrence_Of (RTE (RE_Register_Passive_Package), Loc),
1975 Parameter_Associations => New_List (
1976 Make_String_Literal (Loc, Pkg_Name),
1977 Make_Attribute_Reference (Loc,
1978 Prefix =>
1979 New_Occurrence_Of (Defining_Entity (Pkg_Spec), Loc),
1980 Attribute_Name =>
1981 Name_Version)));
1982 Append_To (L, Reg);
1983 Analyze (Reg);
1984 end Build_Passive_Partition_Stub;
1986 --------------------------------------
1987 -- Build_RPC_Receiver_Specification --
1988 --------------------------------------
1990 function Build_RPC_Receiver_Specification
1991 (RPC_Receiver : Entity_Id;
1992 Request_Parameter : Entity_Id) return Node_Id
1994 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
1995 begin
1996 return
1997 Make_Procedure_Specification (Loc,
1998 Defining_Unit_Name => RPC_Receiver,
1999 Parameter_Specifications => New_List (
2000 Make_Parameter_Specification (Loc,
2001 Defining_Identifier => Request_Parameter,
2002 Parameter_Type =>
2003 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
2004 end Build_RPC_Receiver_Specification;
2006 ----------------------------------------
2007 -- Build_Remote_Subprogram_Proxy_Type --
2008 ----------------------------------------
2010 function Build_Remote_Subprogram_Proxy_Type
2011 (Loc : Source_Ptr;
2012 ACR_Expression : Node_Id) return Node_Id
2014 begin
2015 return
2016 Make_Record_Definition (Loc,
2017 Tagged_Present => True,
2018 Limited_Present => True,
2019 Component_List =>
2020 Make_Component_List (Loc,
2022 Component_Items => New_List (
2023 Make_Component_Declaration (Loc,
2024 Defining_Identifier =>
2025 Make_Defining_Identifier (Loc,
2026 Name_All_Calls_Remote),
2027 Component_Definition =>
2028 Make_Component_Definition (Loc,
2029 Subtype_Indication =>
2030 New_Occurrence_Of (Standard_Boolean, Loc)),
2031 Expression =>
2032 ACR_Expression),
2034 Make_Component_Declaration (Loc,
2035 Defining_Identifier =>
2036 Make_Defining_Identifier (Loc,
2037 Name_Receiver),
2038 Component_Definition =>
2039 Make_Component_Definition (Loc,
2040 Subtype_Indication =>
2041 New_Occurrence_Of (RTE (RE_Address), Loc)),
2042 Expression =>
2043 New_Occurrence_Of (RTE (RE_Null_Address), Loc)),
2045 Make_Component_Declaration (Loc,
2046 Defining_Identifier =>
2047 Make_Defining_Identifier (Loc,
2048 Name_Subp_Id),
2049 Component_Definition =>
2050 Make_Component_Definition (Loc,
2051 Subtype_Indication =>
2052 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc))))));
2053 end Build_Remote_Subprogram_Proxy_Type;
2055 ------------------------------------
2056 -- Build_Subprogram_Calling_Stubs --
2057 ------------------------------------
2059 function Build_Subprogram_Calling_Stubs
2060 (Vis_Decl : Node_Id;
2061 Subp_Id : Node_Id;
2062 Asynchronous : Boolean;
2063 Dynamically_Asynchronous : Boolean := False;
2064 Stub_Type : Entity_Id := Empty;
2065 RACW_Type : Entity_Id := Empty;
2066 Locator : Entity_Id := Empty;
2067 New_Name : Name_Id := No_Name) return Node_Id
2069 Loc : constant Source_Ptr := Sloc (Vis_Decl);
2071 Decls : constant List_Id := New_List;
2072 Statements : constant List_Id := New_List;
2074 Subp_Spec : Node_Id;
2075 -- The specification of the body
2077 Controlling_Parameter : Entity_Id := Empty;
2079 Asynchronous_Expr : Node_Id := Empty;
2081 RCI_Locator : Entity_Id;
2083 Spec_To_Use : Node_Id;
2085 procedure Insert_Partition_Check (Parameter : Node_Id);
2086 -- Check that the parameter has been elaborated on the same partition
2087 -- than the controlling parameter (E.4(19)).
2089 ----------------------------
2090 -- Insert_Partition_Check --
2091 ----------------------------
2093 procedure Insert_Partition_Check (Parameter : Node_Id) is
2094 Parameter_Entity : constant Entity_Id :=
2095 Defining_Identifier (Parameter);
2096 begin
2097 -- The expression that will be built is of the form:
2099 -- if not Same_Partition (Parameter, Controlling_Parameter) then
2100 -- raise Constraint_Error;
2101 -- end if;
2103 -- We do not check that Parameter is in Stub_Type since such a check
2104 -- has been inserted at the point of call already (a tag check since
2105 -- we have multiple controlling operands).
2107 Append_To (Decls,
2108 Make_Raise_Constraint_Error (Loc,
2109 Condition =>
2110 Make_Op_Not (Loc,
2111 Right_Opnd =>
2112 Make_Function_Call (Loc,
2113 Name =>
2114 New_Occurrence_Of (RTE (RE_Same_Partition), Loc),
2115 Parameter_Associations =>
2116 New_List (
2117 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
2118 New_Occurrence_Of (Parameter_Entity, Loc)),
2119 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
2120 New_Occurrence_Of (Controlling_Parameter, Loc))))),
2121 Reason => CE_Partition_Check_Failed));
2122 end Insert_Partition_Check;
2124 -- Start of processing for Build_Subprogram_Calling_Stubs
2126 begin
2127 Subp_Spec := Copy_Specification (Loc,
2128 Spec => Specification (Vis_Decl),
2129 New_Name => New_Name);
2131 if Locator = Empty then
2132 RCI_Locator := RCI_Cache;
2133 Spec_To_Use := Specification (Vis_Decl);
2134 else
2135 RCI_Locator := Locator;
2136 Spec_To_Use := Subp_Spec;
2137 end if;
2139 -- Find a controlling argument if we have a stub type. Also check
2140 -- if this subprogram can be made asynchronous.
2142 if Present (Stub_Type)
2143 and then Present (Parameter_Specifications (Spec_To_Use))
2144 then
2145 declare
2146 Current_Parameter : Node_Id :=
2147 First (Parameter_Specifications
2148 (Spec_To_Use));
2149 begin
2150 while Present (Current_Parameter) loop
2152 Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type)
2153 then
2154 if Controlling_Parameter = Empty then
2155 Controlling_Parameter :=
2156 Defining_Identifier (Current_Parameter);
2157 else
2158 Insert_Partition_Check (Current_Parameter);
2159 end if;
2160 end if;
2162 Next (Current_Parameter);
2163 end loop;
2164 end;
2165 end if;
2167 pragma Assert (No (Stub_Type) or else Present (Controlling_Parameter));
2169 if Dynamically_Asynchronous then
2170 Asynchronous_Expr := Make_Selected_Component (Loc,
2171 Prefix => Controlling_Parameter,
2172 Selector_Name => Name_Asynchronous);
2173 end if;
2175 Specific_Build_General_Calling_Stubs
2176 (Decls => Decls,
2177 Statements => Statements,
2178 Target => Specific_Build_Stub_Target (Loc,
2179 Decls, RCI_Locator, Controlling_Parameter),
2180 Subprogram_Id => Subp_Id,
2181 Asynchronous => Asynchronous_Expr,
2182 Is_Known_Asynchronous => Asynchronous
2183 and then not Dynamically_Asynchronous,
2184 Is_Known_Non_Asynchronous
2185 => not Asynchronous
2186 and then not Dynamically_Asynchronous,
2187 Is_Function => Nkind (Spec_To_Use) =
2188 N_Function_Specification,
2189 Spec => Spec_To_Use,
2190 Stub_Type => Stub_Type,
2191 RACW_Type => RACW_Type,
2192 Nod => Vis_Decl);
2194 RCI_Calling_Stubs_Table.Set
2195 (Defining_Unit_Name (Specification (Vis_Decl)),
2196 Defining_Unit_Name (Spec_To_Use));
2198 return
2199 Make_Subprogram_Body (Loc,
2200 Specification => Subp_Spec,
2201 Declarations => Decls,
2202 Handled_Statement_Sequence =>
2203 Make_Handled_Sequence_Of_Statements (Loc, Statements));
2204 end Build_Subprogram_Calling_Stubs;
2206 -------------------------
2207 -- Build_Subprogram_Id --
2208 -------------------------
2210 function Build_Subprogram_Id
2211 (Loc : Source_Ptr;
2212 E : Entity_Id) return Node_Id
2214 begin
2215 case Get_PCS_Name is
2216 when Name_PolyORB_DSA =>
2217 return Make_String_Literal (Loc, Get_Subprogram_Id (E));
2218 when others =>
2219 return Make_Integer_Literal (Loc, Get_Subprogram_Id (E));
2220 end case;
2221 end Build_Subprogram_Id;
2223 ------------------------
2224 -- Copy_Specification --
2225 ------------------------
2227 function Copy_Specification
2228 (Loc : Source_Ptr;
2229 Spec : Node_Id;
2230 Object_Type : Entity_Id := Empty;
2231 Stub_Type : Entity_Id := Empty;
2232 New_Name : Name_Id := No_Name) return Node_Id
2234 Parameters : List_Id := No_List;
2236 Current_Parameter : Node_Id;
2237 Current_Identifier : Entity_Id;
2238 Current_Type : Node_Id;
2239 Current_Etype : Entity_Id;
2241 Name_For_New_Spec : Name_Id;
2243 New_Identifier : Entity_Id;
2245 -- Comments needed in body below ???
2247 begin
2248 if New_Name = No_Name then
2249 pragma Assert (Nkind (Spec) = N_Function_Specification
2250 or else Nkind (Spec) = N_Procedure_Specification);
2252 Name_For_New_Spec := Chars (Defining_Unit_Name (Spec));
2253 else
2254 Name_For_New_Spec := New_Name;
2255 end if;
2257 if Present (Parameter_Specifications (Spec)) then
2258 Parameters := New_List;
2259 Current_Parameter := First (Parameter_Specifications (Spec));
2260 while Present (Current_Parameter) loop
2261 Current_Identifier := Defining_Identifier (Current_Parameter);
2262 Current_Type := Parameter_Type (Current_Parameter);
2264 if Nkind (Current_Type) = N_Access_Definition then
2265 Current_Etype := Entity (Subtype_Mark (Current_Type));
2267 if Present (Object_Type) then
2268 pragma Assert (
2269 Root_Type (Current_Etype) = Root_Type (Object_Type));
2270 Current_Type :=
2271 Make_Access_Definition (Loc,
2272 Subtype_Mark => New_Occurrence_Of (Stub_Type, Loc));
2273 else
2274 Current_Type :=
2275 Make_Access_Definition (Loc,
2276 Subtype_Mark =>
2277 New_Occurrence_Of (Current_Etype, Loc));
2278 end if;
2280 else
2281 Current_Etype := Entity (Current_Type);
2283 if Present (Object_Type)
2284 and then Current_Etype = Object_Type
2285 then
2286 Current_Type := New_Occurrence_Of (Stub_Type, Loc);
2287 else
2288 Current_Type := New_Occurrence_Of (Current_Etype, Loc);
2289 end if;
2290 end if;
2292 New_Identifier := Make_Defining_Identifier (Loc,
2293 Chars (Current_Identifier));
2295 Append_To (Parameters,
2296 Make_Parameter_Specification (Loc,
2297 Defining_Identifier => New_Identifier,
2298 Parameter_Type => Current_Type,
2299 In_Present => In_Present (Current_Parameter),
2300 Out_Present => Out_Present (Current_Parameter),
2301 Expression =>
2302 New_Copy_Tree (Expression (Current_Parameter))));
2304 -- For a regular formal parameter (that needs to be marshalled
2305 -- in the context of remote calls), set the Etype now, because
2306 -- marshalling processing might need it.
2308 if Is_Entity_Name (Current_Type) then
2309 Set_Etype (New_Identifier, Entity (Current_Type));
2311 -- Current_Type is an access definition, special processing
2312 -- (not requiring etype) will occur for marshalling.
2314 else
2315 null;
2316 end if;
2318 Next (Current_Parameter);
2319 end loop;
2320 end if;
2322 case Nkind (Spec) is
2324 when N_Function_Specification | N_Access_Function_Definition =>
2325 return
2326 Make_Function_Specification (Loc,
2327 Defining_Unit_Name =>
2328 Make_Defining_Identifier (Loc,
2329 Chars => Name_For_New_Spec),
2330 Parameter_Specifications => Parameters,
2331 Subtype_Mark =>
2332 New_Occurrence_Of (Entity (Subtype_Mark (Spec)), Loc));
2334 when N_Procedure_Specification | N_Access_Procedure_Definition =>
2335 return
2336 Make_Procedure_Specification (Loc,
2337 Defining_Unit_Name =>
2338 Make_Defining_Identifier (Loc,
2339 Chars => Name_For_New_Spec),
2340 Parameter_Specifications => Parameters);
2342 when others =>
2343 raise Program_Error;
2344 end case;
2345 end Copy_Specification;
2347 ---------------------------
2348 -- Could_Be_Asynchronous --
2349 ---------------------------
2351 function Could_Be_Asynchronous (Spec : Node_Id) return Boolean is
2352 Current_Parameter : Node_Id;
2354 begin
2355 if Present (Parameter_Specifications (Spec)) then
2356 Current_Parameter := First (Parameter_Specifications (Spec));
2357 while Present (Current_Parameter) loop
2358 if Out_Present (Current_Parameter) then
2359 return False;
2360 end if;
2362 Next (Current_Parameter);
2363 end loop;
2364 end if;
2366 return True;
2367 end Could_Be_Asynchronous;
2369 ---------------------------
2370 -- Declare_Create_NVList --
2371 ---------------------------
2373 procedure Declare_Create_NVList
2374 (Loc : Source_Ptr;
2375 NVList : Entity_Id;
2376 Decls : List_Id;
2377 Stmts : List_Id)
2379 begin
2380 Append_To (Decls,
2381 Make_Object_Declaration (Loc,
2382 Defining_Identifier => NVList,
2383 Aliased_Present => False,
2384 Object_Definition =>
2385 New_Occurrence_Of (RTE (RE_NVList_Ref), Loc)));
2387 Append_To (Stmts,
2388 Make_Procedure_Call_Statement (Loc,
2389 Name =>
2390 New_Occurrence_Of (RTE (RE_NVList_Create), Loc),
2391 Parameter_Associations => New_List (
2392 New_Occurrence_Of (NVList, Loc))));
2393 end Declare_Create_NVList;
2395 ---------------------------------------------
2396 -- Expand_All_Calls_Remote_Subprogram_Call --
2397 ---------------------------------------------
2399 procedure Expand_All_Calls_Remote_Subprogram_Call (N : Node_Id) is
2400 Called_Subprogram : constant Entity_Id := Entity (Name (N));
2401 RCI_Package : constant Entity_Id := Scope (Called_Subprogram);
2402 Loc : constant Source_Ptr := Sloc (N);
2403 RCI_Locator : Node_Id;
2404 RCI_Cache : Entity_Id;
2405 Calling_Stubs : Node_Id;
2406 E_Calling_Stubs : Entity_Id;
2408 begin
2409 E_Calling_Stubs := RCI_Calling_Stubs_Table.Get (Called_Subprogram);
2411 if E_Calling_Stubs = Empty then
2412 RCI_Cache := RCI_Locator_Table.Get (RCI_Package);
2414 if RCI_Cache = Empty then
2415 RCI_Locator :=
2416 RCI_Package_Locator
2417 (Loc, Specification (Unit_Declaration_Node (RCI_Package)));
2418 Prepend_To (Current_Sem_Unit_Declarations, RCI_Locator);
2420 -- The RCI_Locator package is inserted at the top level in the
2421 -- current unit, and must appear in the proper scope, so that it
2422 -- is not prematurely removed by the GCC back-end.
2424 declare
2425 Scop : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
2427 begin
2428 if Ekind (Scop) = E_Package_Body then
2429 New_Scope (Spec_Entity (Scop));
2431 elsif Ekind (Scop) = E_Subprogram_Body then
2432 New_Scope
2433 (Corresponding_Spec (Unit_Declaration_Node (Scop)));
2435 else
2436 New_Scope (Scop);
2437 end if;
2439 Analyze (RCI_Locator);
2440 Pop_Scope;
2441 end;
2443 RCI_Cache := Defining_Unit_Name (RCI_Locator);
2445 else
2446 RCI_Locator := Parent (RCI_Cache);
2447 end if;
2449 Calling_Stubs := Build_Subprogram_Calling_Stubs
2450 (Vis_Decl => Parent (Parent (Called_Subprogram)),
2451 Subp_Id =>
2452 Build_Subprogram_Id (Loc, Called_Subprogram),
2453 Asynchronous => Nkind (N) = N_Procedure_Call_Statement
2454 and then
2455 Is_Asynchronous (Called_Subprogram),
2456 Locator => RCI_Cache,
2457 New_Name => New_Internal_Name ('S'));
2458 Insert_After (RCI_Locator, Calling_Stubs);
2459 Analyze (Calling_Stubs);
2460 E_Calling_Stubs := Defining_Unit_Name (Specification (Calling_Stubs));
2461 end if;
2463 Rewrite (Name (N), New_Occurrence_Of (E_Calling_Stubs, Loc));
2464 end Expand_All_Calls_Remote_Subprogram_Call;
2466 ---------------------------------
2467 -- Expand_Calling_Stubs_Bodies --
2468 ---------------------------------
2470 procedure Expand_Calling_Stubs_Bodies (Unit_Node : Node_Id) is
2471 Spec : constant Node_Id := Specification (Unit_Node);
2472 Decls : constant List_Id := Visible_Declarations (Spec);
2473 begin
2474 New_Scope (Scope_Of_Spec (Spec));
2475 Add_Calling_Stubs_To_Declarations
2476 (Specification (Unit_Node), Decls);
2477 Pop_Scope;
2478 end Expand_Calling_Stubs_Bodies;
2480 -----------------------------------
2481 -- Expand_Receiving_Stubs_Bodies --
2482 -----------------------------------
2484 procedure Expand_Receiving_Stubs_Bodies (Unit_Node : Node_Id) is
2485 Spec : Node_Id;
2486 Decls : List_Id;
2487 Temp : List_Id;
2489 begin
2490 if Nkind (Unit_Node) = N_Package_Declaration then
2491 Spec := Specification (Unit_Node);
2492 Decls := Private_Declarations (Spec);
2494 if No (Decls) then
2495 Decls := Visible_Declarations (Spec);
2496 end if;
2498 New_Scope (Scope_Of_Spec (Spec));
2499 Specific_Add_Receiving_Stubs_To_Declarations (Spec, Decls);
2501 else
2502 Spec :=
2503 Package_Specification_Of_Scope (Corresponding_Spec (Unit_Node));
2504 Decls := Declarations (Unit_Node);
2505 New_Scope (Scope_Of_Spec (Unit_Node));
2506 Temp := New_List;
2507 Specific_Add_Receiving_Stubs_To_Declarations (Spec, Temp);
2508 Insert_List_Before (First (Decls), Temp);
2509 end if;
2511 Pop_Scope;
2512 end Expand_Receiving_Stubs_Bodies;
2514 --------------------
2515 -- GARLIC_Support --
2516 --------------------
2518 package body GARLIC_Support is
2520 -- Local subprograms
2522 procedure Add_RACW_Read_Attribute
2523 (RACW_Type : Entity_Id;
2524 Stub_Type : Entity_Id;
2525 Stub_Type_Access : Entity_Id;
2526 Declarations : List_Id);
2527 -- Add Read attribute in Decls for the RACW type. The Read attribute
2528 -- is added right after the RACW_Type declaration while the body is
2529 -- inserted after Declarations.
2531 procedure Add_RACW_Write_Attribute
2532 (RACW_Type : Entity_Id;
2533 Stub_Type : Entity_Id;
2534 Stub_Type_Access : Entity_Id;
2535 RPC_Receiver : Node_Id;
2536 Declarations : List_Id);
2537 -- Same thing for the Write attribute
2539 function Stream_Parameter return Node_Id;
2540 function Result return Node_Id;
2541 function Object return Node_Id renames Result;
2542 -- Functions to create occurrences of the formal parameter names of
2543 -- the 'Read and 'Write attributes.
2545 Loc : Source_Ptr;
2546 -- Shared source location used by Add_{Read,Write}_Read_Attribute
2547 -- and their ancillary subroutines (set on entry by Add_RACW_Features).
2549 procedure Add_RAS_Access_TSS (N : Node_Id);
2550 -- Add a subprogram body for RAS Access TSS
2552 -------------------------------------
2553 -- Add_Obj_RPC_Receiver_Completion --
2554 -------------------------------------
2556 procedure Add_Obj_RPC_Receiver_Completion
2557 (Loc : Source_Ptr;
2558 Decls : List_Id;
2559 RPC_Receiver : Entity_Id;
2560 Stub_Elements : Stub_Structure) is
2561 begin
2562 -- The RPC receiver body should not be the completion of the
2563 -- declaration recorded in the stub structure, because then the
2564 -- occurrences of the formal parameters within the body should
2565 -- refer to the entities from the declaration, not from the
2566 -- completion, to which we do not have easy access. Instead, the
2567 -- RPC receiver body acts as its own declaration, and the RPC
2568 -- receiver declaration is completed by a renaming-as-body.
2570 Append_To (Decls,
2571 Make_Subprogram_Renaming_Declaration (Loc,
2572 Specification =>
2573 Copy_Specification (Loc,
2574 Specification (Stub_Elements.RPC_Receiver_Decl)),
2575 Name => New_Occurrence_Of (RPC_Receiver, Loc)));
2576 end Add_Obj_RPC_Receiver_Completion;
2578 -----------------------
2579 -- Add_RACW_Features --
2580 -----------------------
2582 procedure Add_RACW_Features
2583 (RACW_Type : Entity_Id;
2584 Stub_Type : Entity_Id;
2585 Stub_Type_Access : Entity_Id;
2586 RPC_Receiver_Decl : Node_Id;
2587 Declarations : List_Id)
2589 RPC_Receiver : Node_Id;
2590 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
2592 begin
2593 Loc := Sloc (RACW_Type);
2595 if Is_RAS then
2597 -- For a RAS, the RPC receiver is that of the RCI unit,
2598 -- not that of the corresponding distributed object type.
2599 -- We retrieve its address from the local proxy object.
2601 RPC_Receiver := Make_Selected_Component (Loc,
2602 Prefix =>
2603 Unchecked_Convert_To (RTE (RE_RAS_Proxy_Type_Access), Object),
2604 Selector_Name => Make_Identifier (Loc, Name_Receiver));
2606 else
2607 RPC_Receiver := Make_Attribute_Reference (Loc,
2608 Prefix => New_Occurrence_Of (
2609 Defining_Unit_Name (Specification (RPC_Receiver_Decl)), Loc),
2610 Attribute_Name => Name_Address);
2611 end if;
2613 Add_RACW_Write_Attribute (
2614 RACW_Type,
2615 Stub_Type,
2616 Stub_Type_Access,
2617 RPC_Receiver,
2618 Declarations);
2620 Add_RACW_Read_Attribute (
2621 RACW_Type,
2622 Stub_Type,
2623 Stub_Type_Access,
2624 Declarations);
2625 end Add_RACW_Features;
2627 -----------------------------
2628 -- Add_RACW_Read_Attribute --
2629 -----------------------------
2631 procedure Add_RACW_Read_Attribute
2632 (RACW_Type : Entity_Id;
2633 Stub_Type : Entity_Id;
2634 Stub_Type_Access : Entity_Id;
2635 Declarations : List_Id)
2637 Proc_Decl : Node_Id;
2638 Attr_Decl : Node_Id;
2640 Body_Node : Node_Id;
2642 Decls : List_Id;
2643 Statements : List_Id;
2644 Local_Statements : List_Id;
2645 Remote_Statements : List_Id;
2646 -- Various parts of the procedure
2648 Procedure_Name : constant Name_Id :=
2649 New_Internal_Name ('R');
2650 Source_Partition : constant Entity_Id :=
2651 Make_Defining_Identifier
2652 (Loc, New_Internal_Name ('P'));
2653 Source_Receiver : constant Entity_Id :=
2654 Make_Defining_Identifier
2655 (Loc, New_Internal_Name ('S'));
2656 Source_Address : constant Entity_Id :=
2657 Make_Defining_Identifier
2658 (Loc, New_Internal_Name ('P'));
2659 Local_Stub : constant Entity_Id :=
2660 Make_Defining_Identifier
2661 (Loc, New_Internal_Name ('L'));
2662 Stubbed_Result : constant Entity_Id :=
2663 Make_Defining_Identifier
2664 (Loc, New_Internal_Name ('S'));
2665 Asynchronous_Flag : constant Entity_Id :=
2666 Asynchronous_Flags_Table.Get (RACW_Type);
2667 pragma Assert (Present (Asynchronous_Flag));
2669 -- Start of processing for Add_RACW_Read_Attribute
2671 begin
2672 -- Generate object declarations
2674 Decls := New_List (
2675 Make_Object_Declaration (Loc,
2676 Defining_Identifier => Source_Partition,
2677 Object_Definition =>
2678 New_Occurrence_Of (RTE (RE_Partition_ID), Loc)),
2680 Make_Object_Declaration (Loc,
2681 Defining_Identifier => Source_Receiver,
2682 Object_Definition =>
2683 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
2685 Make_Object_Declaration (Loc,
2686 Defining_Identifier => Source_Address,
2687 Object_Definition =>
2688 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
2690 Make_Object_Declaration (Loc,
2691 Defining_Identifier => Local_Stub,
2692 Aliased_Present => True,
2693 Object_Definition => New_Occurrence_Of (Stub_Type, Loc)),
2695 Make_Object_Declaration (Loc,
2696 Defining_Identifier => Stubbed_Result,
2697 Object_Definition =>
2698 New_Occurrence_Of (Stub_Type_Access, Loc),
2699 Expression =>
2700 Make_Attribute_Reference (Loc,
2701 Prefix =>
2702 New_Occurrence_Of (Local_Stub, Loc),
2703 Attribute_Name =>
2704 Name_Unchecked_Access)));
2706 -- Read the source Partition_ID and RPC_Receiver from incoming stream
2708 Statements := New_List (
2709 Make_Attribute_Reference (Loc,
2710 Prefix =>
2711 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
2712 Attribute_Name => Name_Read,
2713 Expressions => New_List (
2714 Stream_Parameter,
2715 New_Occurrence_Of (Source_Partition, Loc))),
2717 Make_Attribute_Reference (Loc,
2718 Prefix =>
2719 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
2720 Attribute_Name =>
2721 Name_Read,
2722 Expressions => New_List (
2723 Stream_Parameter,
2724 New_Occurrence_Of (Source_Receiver, Loc))),
2726 Make_Attribute_Reference (Loc,
2727 Prefix =>
2728 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
2729 Attribute_Name =>
2730 Name_Read,
2731 Expressions => New_List (
2732 Stream_Parameter,
2733 New_Occurrence_Of (Source_Address, Loc))));
2735 -- Build_Get_Unique_RP_Call needs the type of Stubbed_Result
2737 Set_Etype (Stubbed_Result, Stub_Type_Access);
2739 -- If the Address is Null_Address, then return a null object
2741 Append_To (Statements,
2742 Make_Implicit_If_Statement (RACW_Type,
2743 Condition =>
2744 Make_Op_Eq (Loc,
2745 Left_Opnd => New_Occurrence_Of (Source_Address, Loc),
2746 Right_Opnd => Make_Integer_Literal (Loc, Uint_0)),
2747 Then_Statements => New_List (
2748 Make_Assignment_Statement (Loc,
2749 Name => Result,
2750 Expression => Make_Null (Loc)),
2751 Make_Return_Statement (Loc))));
2753 -- If the RACW denotes an object created on the current partition,
2754 -- Local_Statements will be executed. The real object will be used.
2756 Local_Statements := New_List (
2757 Make_Assignment_Statement (Loc,
2758 Name => Result,
2759 Expression =>
2760 Unchecked_Convert_To (RACW_Type,
2761 OK_Convert_To (RTE (RE_Address),
2762 New_Occurrence_Of (Source_Address, Loc)))));
2764 -- If the object is located on another partition, then a stub object
2765 -- will be created with all the information needed to rebuild the
2766 -- real object at the other end.
2768 Remote_Statements := New_List (
2770 Make_Assignment_Statement (Loc,
2771 Name => Make_Selected_Component (Loc,
2772 Prefix => Stubbed_Result,
2773 Selector_Name => Name_Origin),
2774 Expression =>
2775 New_Occurrence_Of (Source_Partition, Loc)),
2777 Make_Assignment_Statement (Loc,
2778 Name => Make_Selected_Component (Loc,
2779 Prefix => Stubbed_Result,
2780 Selector_Name => Name_Receiver),
2781 Expression =>
2782 New_Occurrence_Of (Source_Receiver, Loc)),
2784 Make_Assignment_Statement (Loc,
2785 Name => Make_Selected_Component (Loc,
2786 Prefix => Stubbed_Result,
2787 Selector_Name => Name_Addr),
2788 Expression =>
2789 New_Occurrence_Of (Source_Address, Loc)));
2791 Append_To (Remote_Statements,
2792 Make_Assignment_Statement (Loc,
2793 Name => Make_Selected_Component (Loc,
2794 Prefix => Stubbed_Result,
2795 Selector_Name => Name_Asynchronous),
2796 Expression =>
2797 New_Occurrence_Of (Asynchronous_Flag, Loc)));
2799 Append_List_To (Remote_Statements,
2800 Build_Get_Unique_RP_Call (Loc, Stubbed_Result, Stub_Type));
2801 -- ??? Issue with asynchronous calls here: the Asynchronous
2802 -- flag is set on the stub type if, and only if, the RACW type
2803 -- has a pragma Asynchronous. This is incorrect for RACWs that
2804 -- implement RAS types, because in that case the /designated
2805 -- subprogram/ (not the type) might be asynchronous, and
2806 -- that causes the stub to need to be asynchronous too.
2807 -- A solution is to transport a RAS as a struct containing
2808 -- a RACW and an asynchronous flag, and to properly alter
2809 -- the Asynchronous component in the stub type in the RAS's
2810 -- Input TSS.
2812 Append_To (Remote_Statements,
2813 Make_Assignment_Statement (Loc,
2814 Name => Result,
2815 Expression => Unchecked_Convert_To (RACW_Type,
2816 New_Occurrence_Of (Stubbed_Result, Loc))));
2818 -- Distinguish between the local and remote cases, and execute the
2819 -- appropriate piece of code.
2821 Append_To (Statements,
2822 Make_Implicit_If_Statement (RACW_Type,
2823 Condition =>
2824 Make_Op_Eq (Loc,
2825 Left_Opnd =>
2826 Make_Function_Call (Loc,
2827 Name => New_Occurrence_Of (
2828 RTE (RE_Get_Local_Partition_Id), Loc)),
2829 Right_Opnd => New_Occurrence_Of (Source_Partition, Loc)),
2830 Then_Statements => Local_Statements,
2831 Else_Statements => Remote_Statements));
2833 Build_Stream_Procedure
2834 (Loc, RACW_Type, Body_Node,
2835 Make_Defining_Identifier (Loc, Procedure_Name),
2836 Statements, Outp => True);
2837 Set_Declarations (Body_Node, Decls);
2839 Proc_Decl := Make_Subprogram_Declaration (Loc,
2840 Copy_Specification (Loc, Specification (Body_Node)));
2842 Attr_Decl :=
2843 Make_Attribute_Definition_Clause (Loc,
2844 Name => New_Occurrence_Of (RACW_Type, Loc),
2845 Chars => Name_Read,
2846 Expression =>
2847 New_Occurrence_Of (
2848 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
2850 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
2851 Insert_After (Proc_Decl, Attr_Decl);
2852 Append_To (Declarations, Body_Node);
2853 end Add_RACW_Read_Attribute;
2855 ------------------------------
2856 -- Add_RACW_Write_Attribute --
2857 ------------------------------
2859 procedure Add_RACW_Write_Attribute
2860 (RACW_Type : Entity_Id;
2861 Stub_Type : Entity_Id;
2862 Stub_Type_Access : Entity_Id;
2863 RPC_Receiver : Node_Id;
2864 Declarations : List_Id)
2866 Body_Node : Node_Id;
2867 Proc_Decl : Node_Id;
2868 Attr_Decl : Node_Id;
2870 Statements : List_Id;
2871 Local_Statements : List_Id;
2872 Remote_Statements : List_Id;
2873 Null_Statements : List_Id;
2875 Procedure_Name : constant Name_Id := New_Internal_Name ('R');
2877 begin
2878 -- Build the code fragment corresponding to the marshalling of a
2879 -- local object.
2881 Local_Statements := New_List (
2883 Pack_Entity_Into_Stream_Access (Loc,
2884 Stream => Stream_Parameter,
2885 Object => RTE (RE_Get_Local_Partition_Id)),
2887 Pack_Node_Into_Stream_Access (Loc,
2888 Stream => Stream_Parameter,
2889 Object => OK_Convert_To (RTE (RE_Unsigned_64), RPC_Receiver),
2890 Etyp => RTE (RE_Unsigned_64)),
2892 Pack_Node_Into_Stream_Access (Loc,
2893 Stream => Stream_Parameter,
2894 Object => OK_Convert_To (RTE (RE_Unsigned_64),
2895 Make_Attribute_Reference (Loc,
2896 Prefix =>
2897 Make_Explicit_Dereference (Loc,
2898 Prefix => Object),
2899 Attribute_Name => Name_Address)),
2900 Etyp => RTE (RE_Unsigned_64)));
2902 -- Build the code fragment corresponding to the marshalling of
2903 -- a remote object.
2905 Remote_Statements := New_List (
2907 Pack_Node_Into_Stream_Access (Loc,
2908 Stream => Stream_Parameter,
2909 Object =>
2910 Make_Selected_Component (Loc,
2911 Prefix => Unchecked_Convert_To (Stub_Type_Access,
2912 Object),
2913 Selector_Name =>
2914 Make_Identifier (Loc, Name_Origin)),
2915 Etyp => RTE (RE_Partition_ID)),
2917 Pack_Node_Into_Stream_Access (Loc,
2918 Stream => Stream_Parameter,
2919 Object =>
2920 Make_Selected_Component (Loc,
2921 Prefix => Unchecked_Convert_To (Stub_Type_Access,
2922 Object),
2923 Selector_Name =>
2924 Make_Identifier (Loc, Name_Receiver)),
2925 Etyp => RTE (RE_Unsigned_64)),
2927 Pack_Node_Into_Stream_Access (Loc,
2928 Stream => Stream_Parameter,
2929 Object =>
2930 Make_Selected_Component (Loc,
2931 Prefix => Unchecked_Convert_To (Stub_Type_Access,
2932 Object),
2933 Selector_Name =>
2934 Make_Identifier (Loc, Name_Addr)),
2935 Etyp => RTE (RE_Unsigned_64)));
2937 -- Build code fragment corresponding to marshalling of a null object
2939 Null_Statements := New_List (
2941 Pack_Entity_Into_Stream_Access (Loc,
2942 Stream => Stream_Parameter,
2943 Object => RTE (RE_Get_Local_Partition_Id)),
2945 Pack_Node_Into_Stream_Access (Loc,
2946 Stream => Stream_Parameter,
2947 Object => OK_Convert_To (RTE (RE_Unsigned_64), RPC_Receiver),
2948 Etyp => RTE (RE_Unsigned_64)),
2950 Pack_Node_Into_Stream_Access (Loc,
2951 Stream => Stream_Parameter,
2952 Object => Make_Integer_Literal (Loc, Uint_0),
2953 Etyp => RTE (RE_Unsigned_64)));
2955 Statements := New_List (
2956 Make_Implicit_If_Statement (RACW_Type,
2957 Condition =>
2958 Make_Op_Eq (Loc,
2959 Left_Opnd => Object,
2960 Right_Opnd => Make_Null (Loc)),
2961 Then_Statements => Null_Statements,
2962 Elsif_Parts => New_List (
2963 Make_Elsif_Part (Loc,
2964 Condition =>
2965 Make_Op_Eq (Loc,
2966 Left_Opnd =>
2967 Make_Attribute_Reference (Loc,
2968 Prefix => Object,
2969 Attribute_Name => Name_Tag),
2970 Right_Opnd =>
2971 Make_Attribute_Reference (Loc,
2972 Prefix => New_Occurrence_Of (Stub_Type, Loc),
2973 Attribute_Name => Name_Tag)),
2974 Then_Statements => Remote_Statements)),
2975 Else_Statements => Local_Statements));
2977 Build_Stream_Procedure
2978 (Loc, RACW_Type, Body_Node,
2979 Make_Defining_Identifier (Loc, Procedure_Name),
2980 Statements, Outp => False);
2982 Proc_Decl := Make_Subprogram_Declaration (Loc,
2983 Copy_Specification (Loc, Specification (Body_Node)));
2985 Attr_Decl :=
2986 Make_Attribute_Definition_Clause (Loc,
2987 Name => New_Occurrence_Of (RACW_Type, Loc),
2988 Chars => Name_Write,
2989 Expression =>
2990 New_Occurrence_Of (
2991 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
2993 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
2994 Insert_After (Proc_Decl, Attr_Decl);
2995 Append_To (Declarations, Body_Node);
2996 end Add_RACW_Write_Attribute;
2998 ------------------------
2999 -- Add_RAS_Access_TSS --
3000 ------------------------
3002 procedure Add_RAS_Access_TSS (N : Node_Id) is
3003 Loc : constant Source_Ptr := Sloc (N);
3005 Ras_Type : constant Entity_Id := Defining_Identifier (N);
3006 Fat_Type : constant Entity_Id := Equivalent_Type (Ras_Type);
3007 -- Ras_Type is the access to subprogram type while Fat_Type is the
3008 -- corresponding record type.
3010 RACW_Type : constant Entity_Id :=
3011 Underlying_RACW_Type (Ras_Type);
3012 Desig : constant Entity_Id :=
3013 Etype (Designated_Type (RACW_Type));
3015 Stub_Elements : constant Stub_Structure :=
3016 Stubs_Table.Get (Desig);
3017 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
3019 Proc : constant Entity_Id :=
3020 Make_Defining_Identifier (Loc,
3021 Chars => Make_TSS_Name (Ras_Type, TSS_RAS_Access));
3023 Proc_Spec : Node_Id;
3025 -- Formal parameters
3027 Package_Name : constant Entity_Id :=
3028 Make_Defining_Identifier (Loc,
3029 Chars => Name_P);
3030 -- Target package
3032 Subp_Id : constant Entity_Id :=
3033 Make_Defining_Identifier (Loc,
3034 Chars => Name_S);
3035 -- Target subprogram
3037 Asynch_P : constant Entity_Id :=
3038 Make_Defining_Identifier (Loc,
3039 Chars => Name_Asynchronous);
3040 -- Is the procedure to which the 'Access applies asynchronous?
3042 All_Calls_Remote : constant Entity_Id :=
3043 Make_Defining_Identifier (Loc,
3044 Chars => Name_All_Calls_Remote);
3045 -- True if an All_Calls_Remote pragma applies to the RCI unit
3046 -- that contains the subprogram.
3048 -- Common local variables
3050 Proc_Decls : List_Id;
3051 Proc_Statements : List_Id;
3053 Origin : constant Entity_Id :=
3054 Make_Defining_Identifier (Loc,
3055 Chars => New_Internal_Name ('P'));
3057 -- Additional local variables for the local case
3059 Proxy_Addr : constant Entity_Id :=
3060 Make_Defining_Identifier (Loc,
3061 Chars => New_Internal_Name ('P'));
3063 -- Additional local variables for the remote case
3065 Local_Stub : constant Entity_Id :=
3066 Make_Defining_Identifier (Loc,
3067 Chars => New_Internal_Name ('L'));
3069 Stub_Ptr : constant Entity_Id :=
3070 Make_Defining_Identifier (Loc,
3071 Chars => New_Internal_Name ('S'));
3073 function Set_Field
3074 (Field_Name : Name_Id;
3075 Value : Node_Id) return Node_Id;
3076 -- Construct an assignment that sets the named component in the
3077 -- returned record
3079 ---------------
3080 -- Set_Field --
3081 ---------------
3083 function Set_Field
3084 (Field_Name : Name_Id;
3085 Value : Node_Id) return Node_Id
3087 begin
3088 return
3089 Make_Assignment_Statement (Loc,
3090 Name =>
3091 Make_Selected_Component (Loc,
3092 Prefix => Stub_Ptr,
3093 Selector_Name => Field_Name),
3094 Expression => Value);
3095 end Set_Field;
3097 -- Start of processing for Add_RAS_Access_TSS
3099 begin
3100 Proc_Decls := New_List (
3102 -- Common declarations
3104 Make_Object_Declaration (Loc,
3105 Defining_Identifier => Origin,
3106 Constant_Present => True,
3107 Object_Definition =>
3108 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
3109 Expression =>
3110 Make_Function_Call (Loc,
3111 Name =>
3112 New_Occurrence_Of (RTE (RE_Get_Active_Partition_Id), Loc),
3113 Parameter_Associations => New_List (
3114 New_Occurrence_Of (Package_Name, Loc)))),
3116 -- Declaration use only in the local case: proxy address
3118 Make_Object_Declaration (Loc,
3119 Defining_Identifier => Proxy_Addr,
3120 Object_Definition =>
3121 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
3123 -- Declarations used only in the remote case: stub object and
3124 -- stub pointer.
3126 Make_Object_Declaration (Loc,
3127 Defining_Identifier => Local_Stub,
3128 Aliased_Present => True,
3129 Object_Definition =>
3130 New_Occurrence_Of (Stub_Elements.Stub_Type, Loc)),
3132 Make_Object_Declaration (Loc,
3133 Defining_Identifier =>
3134 Stub_Ptr,
3135 Object_Definition =>
3136 New_Occurrence_Of (Stub_Elements.Stub_Type_Access, Loc),
3137 Expression =>
3138 Make_Attribute_Reference (Loc,
3139 Prefix => New_Occurrence_Of (Local_Stub, Loc),
3140 Attribute_Name => Name_Unchecked_Access)));
3142 Set_Etype (Stub_Ptr, Stub_Elements.Stub_Type_Access);
3143 -- Build_Get_Unique_RP_Call needs this information
3145 -- Note: Here we assume that the Fat_Type is a record
3146 -- containing just a pointer to a proxy or stub object.
3148 Proc_Statements := New_List (
3150 -- Generate:
3152 -- Get_RAS_Info (Pkg, Subp, PA);
3153 -- if Origin = Local_Partition_Id
3154 -- and then not All_Calls_Remote
3155 -- then
3156 -- return Fat_Type!(PA);
3157 -- end if;
3159 Make_Procedure_Call_Statement (Loc,
3160 Name =>
3161 New_Occurrence_Of (RTE (RE_Get_RAS_Info), Loc),
3162 Parameter_Associations => New_List (
3163 New_Occurrence_Of (Package_Name, Loc),
3164 New_Occurrence_Of (Subp_Id, Loc),
3165 New_Occurrence_Of (Proxy_Addr, Loc))),
3167 Make_Implicit_If_Statement (N,
3168 Condition =>
3169 Make_And_Then (Loc,
3170 Left_Opnd =>
3171 Make_Op_Eq (Loc,
3172 Left_Opnd =>
3173 New_Occurrence_Of (Origin, Loc),
3174 Right_Opnd =>
3175 Make_Function_Call (Loc,
3176 New_Occurrence_Of (
3177 RTE (RE_Get_Local_Partition_Id), Loc))),
3178 Right_Opnd =>
3179 Make_Op_Not (Loc,
3180 New_Occurrence_Of (All_Calls_Remote, Loc))),
3181 Then_Statements => New_List (
3182 Make_Return_Statement (Loc,
3183 Unchecked_Convert_To (Fat_Type,
3184 OK_Convert_To (RTE (RE_Address),
3185 New_Occurrence_Of (Proxy_Addr, Loc)))))),
3187 Set_Field (Name_Origin,
3188 New_Occurrence_Of (Origin, Loc)),
3190 Set_Field (Name_Receiver,
3191 Make_Function_Call (Loc,
3192 Name =>
3193 New_Occurrence_Of (RTE (RE_Get_RCI_Package_Receiver), Loc),
3194 Parameter_Associations => New_List (
3195 New_Occurrence_Of (Package_Name, Loc)))),
3197 Set_Field (Name_Addr, New_Occurrence_Of (Proxy_Addr, Loc)),
3199 -- E.4.1(9) A remote call is asynchronous if it is a call to
3200 -- a procedure, or a call through a value of an access-to-procedure
3201 -- type, to which a pragma Asynchronous applies.
3203 -- Parameter Asynch_P is true when the procedure is asynchronous;
3204 -- Expression Asynch_T is true when the type is asynchronous.
3206 Set_Field (Name_Asynchronous,
3207 Make_Or_Else (Loc,
3208 New_Occurrence_Of (Asynch_P, Loc),
3209 New_Occurrence_Of (Boolean_Literals (
3210 Is_Asynchronous (Ras_Type)), Loc))));
3212 Append_List_To (Proc_Statements,
3213 Build_Get_Unique_RP_Call
3214 (Loc, Stub_Ptr, Stub_Elements.Stub_Type));
3216 -- Return the newly created value
3218 Append_To (Proc_Statements,
3219 Make_Return_Statement (Loc,
3220 Expression =>
3221 Unchecked_Convert_To (Fat_Type,
3222 New_Occurrence_Of (Stub_Ptr, Loc))));
3224 Proc_Spec :=
3225 Make_Function_Specification (Loc,
3226 Defining_Unit_Name => Proc,
3227 Parameter_Specifications => New_List (
3228 Make_Parameter_Specification (Loc,
3229 Defining_Identifier => Package_Name,
3230 Parameter_Type =>
3231 New_Occurrence_Of (Standard_String, Loc)),
3233 Make_Parameter_Specification (Loc,
3234 Defining_Identifier => Subp_Id,
3235 Parameter_Type =>
3236 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc)),
3238 Make_Parameter_Specification (Loc,
3239 Defining_Identifier => Asynch_P,
3240 Parameter_Type =>
3241 New_Occurrence_Of (Standard_Boolean, Loc)),
3243 Make_Parameter_Specification (Loc,
3244 Defining_Identifier => All_Calls_Remote,
3245 Parameter_Type =>
3246 New_Occurrence_Of (Standard_Boolean, Loc))),
3248 Subtype_Mark =>
3249 New_Occurrence_Of (Fat_Type, Loc));
3251 -- Set the kind and return type of the function to prevent
3252 -- ambiguities between Ras_Type and Fat_Type in subsequent analysis.
3254 Set_Ekind (Proc, E_Function);
3255 Set_Etype (Proc, Fat_Type);
3257 Discard_Node (
3258 Make_Subprogram_Body (Loc,
3259 Specification => Proc_Spec,
3260 Declarations => Proc_Decls,
3261 Handled_Statement_Sequence =>
3262 Make_Handled_Sequence_Of_Statements (Loc,
3263 Statements => Proc_Statements)));
3265 Set_TSS (Fat_Type, Proc);
3266 end Add_RAS_Access_TSS;
3268 -----------------------
3269 -- Add_RAST_Features --
3270 -----------------------
3272 procedure Add_RAST_Features
3273 (Vis_Decl : Node_Id;
3274 RAS_Type : Entity_Id;
3275 Decls : List_Id)
3277 pragma Warnings (Off);
3278 pragma Unreferenced (RAS_Type, Decls);
3279 pragma Warnings (On);
3280 begin
3281 Add_RAS_Access_TSS (Vis_Decl);
3282 end Add_RAST_Features;
3284 -----------------------------------------
3285 -- Add_Receiving_Stubs_To_Declarations --
3286 -----------------------------------------
3288 procedure Add_Receiving_Stubs_To_Declarations
3289 (Pkg_Spec : Node_Id;
3290 Decls : List_Id)
3292 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
3294 Request_Parameter : Node_Id;
3296 Pkg_RPC_Receiver : constant Entity_Id :=
3297 Make_Defining_Identifier (Loc,
3298 New_Internal_Name ('H'));
3299 Pkg_RPC_Receiver_Statements : List_Id;
3300 Pkg_RPC_Receiver_Cases : constant List_Id := New_List;
3301 Pkg_RPC_Receiver_Body : Node_Id;
3302 -- A Pkg_RPC_Receiver is built to decode the request
3304 Lookup_RAS_Info : constant Entity_Id :=
3305 Make_Defining_Identifier (Loc,
3306 Chars => New_Internal_Name ('R'));
3307 -- A remote subprogram is created to allow peers to look up
3308 -- RAS information using subprogram ids.
3310 Subp_Id : Entity_Id;
3311 Subp_Index : Entity_Id;
3312 -- Subprogram_Id as read from the incoming stream
3314 Current_Declaration : Node_Id;
3315 Current_Subprogram_Number : Int := First_RCI_Subprogram_Id;
3316 Current_Stubs : Node_Id;
3318 Subp_Info_Array : constant Entity_Id :=
3319 Make_Defining_Identifier (Loc,
3320 Chars => New_Internal_Name ('I'));
3322 Subp_Info_List : constant List_Id := New_List;
3324 Register_Pkg_Actuals : constant List_Id := New_List;
3326 All_Calls_Remote_E : Entity_Id;
3327 Proxy_Object_Addr : Entity_Id;
3329 procedure Append_Stubs_To
3330 (RPC_Receiver_Cases : List_Id;
3331 Stubs : Node_Id;
3332 Subprogram_Number : Int);
3333 -- Add one case to the specified RPC receiver case list
3334 -- associating Subprogram_Number with the subprogram declared
3335 -- by Declaration, for which we have receiving stubs in Stubs.
3337 ---------------------
3338 -- Append_Stubs_To --
3339 ---------------------
3341 procedure Append_Stubs_To
3342 (RPC_Receiver_Cases : List_Id;
3343 Stubs : Node_Id;
3344 Subprogram_Number : Int)
3346 begin
3347 Append_To (RPC_Receiver_Cases,
3348 Make_Case_Statement_Alternative (Loc,
3349 Discrete_Choices =>
3350 New_List (Make_Integer_Literal (Loc, Subprogram_Number)),
3351 Statements =>
3352 New_List (
3353 Make_Procedure_Call_Statement (Loc,
3354 Name =>
3355 New_Occurrence_Of (
3356 Defining_Entity (Stubs), Loc),
3357 Parameter_Associations => New_List (
3358 New_Occurrence_Of (Request_Parameter, Loc))))));
3359 end Append_Stubs_To;
3361 -- Start of processing for Add_Receiving_Stubs_To_Declarations
3363 begin
3364 -- Building receiving stubs consist in several operations:
3366 -- - a package RPC receiver must be built. This subprogram
3367 -- will get a Subprogram_Id from the incoming stream
3368 -- and will dispatch the call to the right subprogram
3370 -- - a receiving stub for any subprogram visible in the package
3371 -- spec. This stub will read all the parameters from the stream,
3372 -- and put the result as well as the exception occurrence in the
3373 -- output stream
3375 -- - a dummy package with an empty spec and a body made of an
3376 -- elaboration part, whose job is to register the receiving
3377 -- part of this RCI package on the name server. This is done
3378 -- by calling System.Partition_Interface.Register_Receiving_Stub
3380 Build_RPC_Receiver_Body (
3381 RPC_Receiver => Pkg_RPC_Receiver,
3382 Request => Request_Parameter,
3383 Subp_Id => Subp_Id,
3384 Subp_Index => Subp_Index,
3385 Stmts => Pkg_RPC_Receiver_Statements,
3386 Decl => Pkg_RPC_Receiver_Body);
3387 pragma Assert (Subp_Id = Subp_Index);
3389 -- A null subp_id denotes a call through a RAS, in which case the
3390 -- next Uint_64 element in the stream is the address of the local
3391 -- proxy object, from which we can retrieve the actual subprogram id.
3393 Append_To (Pkg_RPC_Receiver_Statements,
3394 Make_Implicit_If_Statement (Pkg_Spec,
3395 Condition =>
3396 Make_Op_Eq (Loc,
3397 New_Occurrence_Of (Subp_Id, Loc),
3398 Make_Integer_Literal (Loc, 0)),
3399 Then_Statements => New_List (
3400 Make_Assignment_Statement (Loc,
3401 Name =>
3402 New_Occurrence_Of (Subp_Id, Loc),
3403 Expression =>
3404 Make_Selected_Component (Loc,
3405 Prefix =>
3406 Unchecked_Convert_To (RTE (RE_RAS_Proxy_Type_Access),
3407 OK_Convert_To (RTE (RE_Address),
3408 Make_Attribute_Reference (Loc,
3409 Prefix =>
3410 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
3411 Attribute_Name =>
3412 Name_Input,
3413 Expressions => New_List (
3414 Make_Selected_Component (Loc,
3415 Prefix => Request_Parameter,
3416 Selector_Name => Name_Params))))),
3417 Selector_Name =>
3418 Make_Identifier (Loc, Name_Subp_Id))))));
3420 -- Build a subprogram for RAS information lookups
3422 Current_Declaration :=
3423 Make_Subprogram_Declaration (Loc,
3424 Specification =>
3425 Make_Function_Specification (Loc,
3426 Defining_Unit_Name =>
3427 Lookup_RAS_Info,
3428 Parameter_Specifications => New_List (
3429 Make_Parameter_Specification (Loc,
3430 Defining_Identifier =>
3431 Make_Defining_Identifier (Loc, Name_Subp_Id),
3432 In_Present =>
3433 True,
3434 Parameter_Type =>
3435 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc))),
3436 Subtype_Mark =>
3437 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)));
3438 Append_To (Decls, Current_Declaration);
3439 Analyze (Current_Declaration);
3441 Current_Stubs := Build_Subprogram_Receiving_Stubs
3442 (Vis_Decl => Current_Declaration,
3443 Asynchronous => False);
3444 Append_To (Decls, Current_Stubs);
3445 Analyze (Current_Stubs);
3447 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
3448 Stubs =>
3449 Current_Stubs,
3450 Subprogram_Number => 1);
3452 -- For each subprogram, the receiving stub will be built and a
3453 -- case statement will be made on the Subprogram_Id to dispatch
3454 -- to the right subprogram.
3456 All_Calls_Remote_E := Boolean_Literals (
3457 Has_All_Calls_Remote (Defining_Entity (Pkg_Spec)));
3459 Overload_Counter_Table.Reset;
3461 Current_Declaration := First (Visible_Declarations (Pkg_Spec));
3462 while Present (Current_Declaration) loop
3463 if Nkind (Current_Declaration) = N_Subprogram_Declaration
3464 and then Comes_From_Source (Current_Declaration)
3465 then
3466 declare
3467 Loc : constant Source_Ptr :=
3468 Sloc (Current_Declaration);
3469 -- While specifically processing Current_Declaration, use
3470 -- its Sloc as the location of all generated nodes.
3472 Subp_Def : constant Entity_Id :=
3473 Defining_Unit_Name
3474 (Specification (Current_Declaration));
3476 Subp_Val : String_Id;
3478 begin
3479 pragma Assert (Current_Subprogram_Number =
3480 Get_Subprogram_Id (Subp_Def));
3482 -- Build receiving stub
3484 Current_Stubs :=
3485 Build_Subprogram_Receiving_Stubs
3486 (Vis_Decl => Current_Declaration,
3487 Asynchronous =>
3488 Nkind (Specification (Current_Declaration)) =
3489 N_Procedure_Specification
3490 and then Is_Asynchronous (Subp_Def));
3492 Append_To (Decls, Current_Stubs);
3493 Analyze (Current_Stubs);
3495 -- Build RAS proxy
3497 Add_RAS_Proxy_And_Analyze (Decls,
3498 Vis_Decl =>
3499 Current_Declaration,
3500 All_Calls_Remote_E =>
3501 All_Calls_Remote_E,
3502 Proxy_Object_Addr =>
3503 Proxy_Object_Addr);
3505 -- Compute distribution identifier
3507 Assign_Subprogram_Identifier (
3508 Subp_Def,
3509 Current_Subprogram_Number,
3510 Subp_Val);
3512 -- Add subprogram descriptor (RCI_Subp_Info) to the
3513 -- subprograms table for this receiver. The aggregate
3514 -- below must be kept consistent with the declaration
3515 -- of type RCI_Subp_Info in System.Partition_Interface.
3517 Append_To (Subp_Info_List,
3518 Make_Component_Association (Loc,
3519 Choices => New_List (
3520 Make_Integer_Literal (Loc,
3521 Current_Subprogram_Number)),
3522 Expression =>
3523 Make_Aggregate (Loc,
3524 Component_Associations => New_List (
3525 Make_Component_Association (Loc,
3526 Choices => New_List (
3527 Make_Identifier (Loc, Name_Addr)),
3528 Expression =>
3529 New_Occurrence_Of (
3530 Proxy_Object_Addr, Loc))))));
3532 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
3533 Stubs =>
3534 Current_Stubs,
3535 Subprogram_Number =>
3536 Current_Subprogram_Number);
3537 end;
3539 Current_Subprogram_Number := Current_Subprogram_Number + 1;
3540 end if;
3542 Next (Current_Declaration);
3543 end loop;
3545 -- If we receive an invalid Subprogram_Id, it is best to do nothing
3546 -- rather than raising an exception since we do not want someone
3547 -- to crash a remote partition by sending invalid subprogram ids.
3548 -- This is consistent with the other parts of the case statement
3549 -- since even in presence of incorrect parameters in the stream,
3550 -- every exception will be caught and (if the subprogram is not an
3551 -- APC) put into the result stream and sent away.
3553 Append_To (Pkg_RPC_Receiver_Cases,
3554 Make_Case_Statement_Alternative (Loc,
3555 Discrete_Choices =>
3556 New_List (Make_Others_Choice (Loc)),
3557 Statements =>
3558 New_List (Make_Null_Statement (Loc))));
3560 Append_To (Pkg_RPC_Receiver_Statements,
3561 Make_Case_Statement (Loc,
3562 Expression =>
3563 New_Occurrence_Of (Subp_Id, Loc),
3564 Alternatives => Pkg_RPC_Receiver_Cases));
3566 Append_To (Decls,
3567 Make_Object_Declaration (Loc,
3568 Defining_Identifier => Subp_Info_Array,
3569 Constant_Present => True,
3570 Aliased_Present => True,
3571 Object_Definition =>
3572 Make_Subtype_Indication (Loc,
3573 Subtype_Mark =>
3574 New_Occurrence_Of (RTE (RE_RCI_Subp_Info_Array), Loc),
3575 Constraint =>
3576 Make_Index_Or_Discriminant_Constraint (Loc,
3577 New_List (
3578 Make_Range (Loc,
3579 Low_Bound => Make_Integer_Literal (Loc,
3580 First_RCI_Subprogram_Id),
3581 High_Bound =>
3582 Make_Integer_Literal (Loc,
3583 First_RCI_Subprogram_Id
3584 + List_Length (Subp_Info_List) - 1))))),
3585 Expression =>
3586 Make_Aggregate (Loc,
3587 Component_Associations => Subp_Info_List)));
3588 Analyze (Last (Decls));
3590 Append_To (Decls,
3591 Make_Subprogram_Body (Loc,
3592 Specification =>
3593 Copy_Specification (Loc, Parent (Lookup_RAS_Info)),
3594 Declarations =>
3595 No_List,
3596 Handled_Statement_Sequence =>
3597 Make_Handled_Sequence_Of_Statements (Loc,
3598 Statements => New_List (
3599 Make_Return_Statement (Loc,
3600 Expression => OK_Convert_To (RTE (RE_Unsigned_64),
3601 Make_Selected_Component (Loc,
3602 Prefix =>
3603 Make_Indexed_Component (Loc,
3604 Prefix =>
3605 New_Occurrence_Of (Subp_Info_Array, Loc),
3606 Expressions => New_List (
3607 Convert_To (Standard_Integer,
3608 Make_Identifier (Loc, Name_Subp_Id)))),
3609 Selector_Name =>
3610 Make_Identifier (Loc, Name_Addr))))))));
3611 Analyze (Last (Decls));
3613 Append_To (Decls, Pkg_RPC_Receiver_Body);
3614 Analyze (Last (Decls));
3616 Get_Library_Unit_Name_String (Pkg_Spec);
3617 Append_To (Register_Pkg_Actuals,
3618 -- Name
3619 Make_String_Literal (Loc,
3620 Strval => String_From_Name_Buffer));
3622 Append_To (Register_Pkg_Actuals,
3623 -- Receiver
3624 Make_Attribute_Reference (Loc,
3625 Prefix =>
3626 New_Occurrence_Of (Pkg_RPC_Receiver, Loc),
3627 Attribute_Name =>
3628 Name_Unrestricted_Access));
3630 Append_To (Register_Pkg_Actuals,
3631 -- Version
3632 Make_Attribute_Reference (Loc,
3633 Prefix =>
3634 New_Occurrence_Of (Defining_Entity (Pkg_Spec), Loc),
3635 Attribute_Name =>
3636 Name_Version));
3638 Append_To (Register_Pkg_Actuals,
3639 -- Subp_Info
3640 Make_Attribute_Reference (Loc,
3641 Prefix =>
3642 New_Occurrence_Of (Subp_Info_Array, Loc),
3643 Attribute_Name =>
3644 Name_Address));
3646 Append_To (Register_Pkg_Actuals,
3647 -- Subp_Info_Len
3648 Make_Attribute_Reference (Loc,
3649 Prefix =>
3650 New_Occurrence_Of (Subp_Info_Array, Loc),
3651 Attribute_Name =>
3652 Name_Length));
3654 Append_To (Decls,
3655 Make_Procedure_Call_Statement (Loc,
3656 Name =>
3657 New_Occurrence_Of (RTE (RE_Register_Receiving_Stub), Loc),
3658 Parameter_Associations => Register_Pkg_Actuals));
3659 Analyze (Last (Decls));
3660 end Add_Receiving_Stubs_To_Declarations;
3662 ---------------------------------
3663 -- Build_General_Calling_Stubs --
3664 ---------------------------------
3666 procedure Build_General_Calling_Stubs
3667 (Decls : List_Id;
3668 Statements : List_Id;
3669 Target_Partition : Entity_Id;
3670 Target_RPC_Receiver : Node_Id;
3671 Subprogram_Id : Node_Id;
3672 Asynchronous : Node_Id := Empty;
3673 Is_Known_Asynchronous : Boolean := False;
3674 Is_Known_Non_Asynchronous : Boolean := False;
3675 Is_Function : Boolean;
3676 Spec : Node_Id;
3677 Stub_Type : Entity_Id := Empty;
3678 RACW_Type : Entity_Id := Empty;
3679 Nod : Node_Id)
3681 Loc : constant Source_Ptr := Sloc (Nod);
3683 Stream_Parameter : Node_Id;
3684 -- Name of the stream used to transmit parameters to the
3685 -- remote package.
3687 Result_Parameter : Node_Id;
3688 -- Name of the result parameter (in non-APC cases) which get the
3689 -- result of the remote subprogram.
3691 Exception_Return_Parameter : Node_Id;
3692 -- Name of the parameter which will hold the exception sent by the
3693 -- remote subprogram.
3695 Current_Parameter : Node_Id;
3696 -- Current parameter being handled
3698 Ordered_Parameters_List : constant List_Id :=
3699 Build_Ordered_Parameters_List (Spec);
3701 Asynchronous_Statements : List_Id := No_List;
3702 Non_Asynchronous_Statements : List_Id := No_List;
3703 -- Statements specifics to the Asynchronous/Non-Asynchronous cases
3705 Extra_Formal_Statements : constant List_Id := New_List;
3706 -- List of statements for extra formal parameters. It will appear
3707 -- after the regular statements for writing out parameters.
3709 pragma Warnings (Off);
3710 pragma Unreferenced (RACW_Type);
3711 -- Used only for the PolyORB case
3712 pragma Warnings (On);
3714 begin
3715 -- The general form of a calling stub for a given subprogram is:
3717 -- procedure X (...) is P : constant Partition_ID :=
3718 -- RCI_Cache.Get_Active_Partition_ID; Stream, Result : aliased
3719 -- System.RPC.Params_Stream_Type (0); begin
3720 -- Put_Package_RPC_Receiver_In_Stream; (the package RPC receiver
3721 -- comes from RCI_Cache.Get_RCI_Package_Receiver)
3722 -- Put_Subprogram_Id_In_Stream; Put_Parameters_In_Stream; Do_RPC
3723 -- (Stream, Result); Read_Exception_Occurrence_From_Result;
3724 -- Raise_It;
3725 -- Read_Out_Parameters_And_Function_Return_From_Stream; end X;
3727 -- There are some variations: Do_APC is called for an asynchronous
3728 -- procedure and the part after the call is completely ommitted as
3729 -- well as the declaration of Result. For a function call, 'Input is
3730 -- always used to read the result even if it is constrained.
3732 Stream_Parameter :=
3733 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
3735 Append_To (Decls,
3736 Make_Object_Declaration (Loc,
3737 Defining_Identifier => Stream_Parameter,
3738 Aliased_Present => True,
3739 Object_Definition =>
3740 Make_Subtype_Indication (Loc,
3741 Subtype_Mark =>
3742 New_Occurrence_Of (RTE (RE_Params_Stream_Type), Loc),
3743 Constraint =>
3744 Make_Index_Or_Discriminant_Constraint (Loc,
3745 Constraints =>
3746 New_List (Make_Integer_Literal (Loc, 0))))));
3748 if not Is_Known_Asynchronous then
3749 Result_Parameter :=
3750 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
3752 Append_To (Decls,
3753 Make_Object_Declaration (Loc,
3754 Defining_Identifier => Result_Parameter,
3755 Aliased_Present => True,
3756 Object_Definition =>
3757 Make_Subtype_Indication (Loc,
3758 Subtype_Mark =>
3759 New_Occurrence_Of (RTE (RE_Params_Stream_Type), Loc),
3760 Constraint =>
3761 Make_Index_Or_Discriminant_Constraint (Loc,
3762 Constraints =>
3763 New_List (Make_Integer_Literal (Loc, 0))))));
3765 Exception_Return_Parameter :=
3766 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
3768 Append_To (Decls,
3769 Make_Object_Declaration (Loc,
3770 Defining_Identifier => Exception_Return_Parameter,
3771 Object_Definition =>
3772 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc)));
3774 else
3775 Result_Parameter := Empty;
3776 Exception_Return_Parameter := Empty;
3777 end if;
3779 -- Put first the RPC receiver corresponding to the remote package
3781 Append_To (Statements,
3782 Make_Attribute_Reference (Loc,
3783 Prefix =>
3784 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
3785 Attribute_Name => Name_Write,
3786 Expressions => New_List (
3787 Make_Attribute_Reference (Loc,
3788 Prefix =>
3789 New_Occurrence_Of (Stream_Parameter, Loc),
3790 Attribute_Name =>
3791 Name_Access),
3792 Target_RPC_Receiver)));
3794 -- Then put the Subprogram_Id of the subprogram we want to call in
3795 -- the stream.
3797 Append_To (Statements,
3798 Make_Attribute_Reference (Loc,
3799 Prefix =>
3800 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
3801 Attribute_Name =>
3802 Name_Write,
3803 Expressions => New_List (
3804 Make_Attribute_Reference (Loc,
3805 Prefix =>
3806 New_Occurrence_Of (Stream_Parameter, Loc),
3807 Attribute_Name => Name_Access),
3808 Subprogram_Id)));
3810 Current_Parameter := First (Ordered_Parameters_List);
3811 while Present (Current_Parameter) loop
3812 declare
3813 Typ : constant Node_Id :=
3814 Parameter_Type (Current_Parameter);
3815 Etyp : Entity_Id;
3816 Constrained : Boolean;
3817 Value : Node_Id;
3818 Extra_Parameter : Entity_Id;
3820 begin
3821 if Is_RACW_Controlling_Formal
3822 (Current_Parameter, Stub_Type)
3823 then
3824 -- In the case of a controlling formal argument, we marshall
3825 -- its addr field rather than the local stub.
3827 Append_To (Statements,
3828 Pack_Node_Into_Stream (Loc,
3829 Stream => Stream_Parameter,
3830 Object =>
3831 Make_Selected_Component (Loc,
3832 Prefix =>
3833 Defining_Identifier (Current_Parameter),
3834 Selector_Name => Name_Addr),
3835 Etyp => RTE (RE_Unsigned_64)));
3837 else
3838 Value := New_Occurrence_Of
3839 (Defining_Identifier (Current_Parameter), Loc);
3841 -- Access type parameters are transmitted as in out
3842 -- parameters. However, a dereference is needed so that
3843 -- we marshall the designated object.
3845 if Nkind (Typ) = N_Access_Definition then
3846 Value := Make_Explicit_Dereference (Loc, Value);
3847 Etyp := Etype (Subtype_Mark (Typ));
3848 else
3849 Etyp := Etype (Typ);
3850 end if;
3852 Constrained :=
3853 Is_Constrained (Etyp) or else Is_Elementary_Type (Etyp);
3855 -- Any parameter but unconstrained out parameters are
3856 -- transmitted to the peer.
3858 if In_Present (Current_Parameter)
3859 or else not Out_Present (Current_Parameter)
3860 or else not Constrained
3861 then
3862 Append_To (Statements,
3863 Make_Attribute_Reference (Loc,
3864 Prefix =>
3865 New_Occurrence_Of (Etyp, Loc),
3866 Attribute_Name =>
3867 Output_From_Constrained (Constrained),
3868 Expressions => New_List (
3869 Make_Attribute_Reference (Loc,
3870 Prefix =>
3871 New_Occurrence_Of (Stream_Parameter, Loc),
3872 Attribute_Name => Name_Access),
3873 Value)));
3874 end if;
3875 end if;
3877 -- If the current parameter has a dynamic constrained status,
3878 -- then this status is transmitted as well.
3879 -- This should be done for accessibility as well ???
3881 if Nkind (Typ) /= N_Access_Definition
3882 and then Need_Extra_Constrained (Current_Parameter)
3883 then
3884 -- In this block, we do not use the extra formal that has
3885 -- been created because it does not exist at the time of
3886 -- expansion when building calling stubs for remote access
3887 -- to subprogram types. We create an extra variable of this
3888 -- type and push it in the stream after the regular
3889 -- parameters.
3891 Extra_Parameter := Make_Defining_Identifier
3892 (Loc, New_Internal_Name ('P'));
3894 Append_To (Decls,
3895 Make_Object_Declaration (Loc,
3896 Defining_Identifier => Extra_Parameter,
3897 Constant_Present => True,
3898 Object_Definition =>
3899 New_Occurrence_Of (Standard_Boolean, Loc),
3900 Expression =>
3901 Make_Attribute_Reference (Loc,
3902 Prefix =>
3903 New_Occurrence_Of (
3904 Defining_Identifier (Current_Parameter), Loc),
3905 Attribute_Name => Name_Constrained)));
3907 Append_To (Extra_Formal_Statements,
3908 Make_Attribute_Reference (Loc,
3909 Prefix =>
3910 New_Occurrence_Of (Standard_Boolean, Loc),
3911 Attribute_Name =>
3912 Name_Write,
3913 Expressions => New_List (
3914 Make_Attribute_Reference (Loc,
3915 Prefix =>
3916 New_Occurrence_Of (Stream_Parameter, Loc),
3917 Attribute_Name =>
3918 Name_Access),
3919 New_Occurrence_Of (Extra_Parameter, Loc))));
3920 end if;
3922 Next (Current_Parameter);
3923 end;
3924 end loop;
3926 -- Append the formal statements list to the statements
3928 Append_List_To (Statements, Extra_Formal_Statements);
3930 if not Is_Known_Non_Asynchronous then
3932 -- Build the call to System.RPC.Do_APC
3934 Asynchronous_Statements := New_List (
3935 Make_Procedure_Call_Statement (Loc,
3936 Name =>
3937 New_Occurrence_Of (RTE (RE_Do_Apc), Loc),
3938 Parameter_Associations => New_List (
3939 New_Occurrence_Of (Target_Partition, Loc),
3940 Make_Attribute_Reference (Loc,
3941 Prefix =>
3942 New_Occurrence_Of (Stream_Parameter, Loc),
3943 Attribute_Name =>
3944 Name_Access))));
3945 else
3946 Asynchronous_Statements := No_List;
3947 end if;
3949 if not Is_Known_Asynchronous then
3951 -- Build the call to System.RPC.Do_RPC
3953 Non_Asynchronous_Statements := New_List (
3954 Make_Procedure_Call_Statement (Loc,
3955 Name =>
3956 New_Occurrence_Of (RTE (RE_Do_Rpc), Loc),
3957 Parameter_Associations => New_List (
3958 New_Occurrence_Of (Target_Partition, Loc),
3960 Make_Attribute_Reference (Loc,
3961 Prefix =>
3962 New_Occurrence_Of (Stream_Parameter, Loc),
3963 Attribute_Name =>
3964 Name_Access),
3966 Make_Attribute_Reference (Loc,
3967 Prefix =>
3968 New_Occurrence_Of (Result_Parameter, Loc),
3969 Attribute_Name =>
3970 Name_Access))));
3972 -- Read the exception occurrence from the result stream and
3973 -- reraise it. It does no harm if this is a Null_Occurrence since
3974 -- this does nothing.
3976 Append_To (Non_Asynchronous_Statements,
3977 Make_Attribute_Reference (Loc,
3978 Prefix =>
3979 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
3981 Attribute_Name =>
3982 Name_Read,
3984 Expressions => New_List (
3985 Make_Attribute_Reference (Loc,
3986 Prefix =>
3987 New_Occurrence_Of (Result_Parameter, Loc),
3988 Attribute_Name =>
3989 Name_Access),
3990 New_Occurrence_Of (Exception_Return_Parameter, Loc))));
3992 Append_To (Non_Asynchronous_Statements,
3993 Make_Procedure_Call_Statement (Loc,
3994 Name =>
3995 New_Occurrence_Of (RTE (RE_Reraise_Occurrence), Loc),
3996 Parameter_Associations => New_List (
3997 New_Occurrence_Of (Exception_Return_Parameter, Loc))));
3999 if Is_Function then
4001 -- If this is a function call, then read the value and return
4002 -- it. The return value is written/read using 'Output/'Input.
4004 Append_To (Non_Asynchronous_Statements,
4005 Make_Tag_Check (Loc,
4006 Make_Return_Statement (Loc,
4007 Expression =>
4008 Make_Attribute_Reference (Loc,
4009 Prefix =>
4010 New_Occurrence_Of (
4011 Etype (Subtype_Mark (Spec)), Loc),
4013 Attribute_Name => Name_Input,
4015 Expressions => New_List (
4016 Make_Attribute_Reference (Loc,
4017 Prefix =>
4018 New_Occurrence_Of (Result_Parameter, Loc),
4019 Attribute_Name => Name_Access))))));
4021 else
4022 -- Loop around parameters and assign out (or in out)
4023 -- parameters. In the case of RACW, controlling arguments
4024 -- cannot possibly have changed since they are remote, so we do
4025 -- not read them from the stream.
4027 Current_Parameter := First (Ordered_Parameters_List);
4028 while Present (Current_Parameter) loop
4029 declare
4030 Typ : constant Node_Id :=
4031 Parameter_Type (Current_Parameter);
4032 Etyp : Entity_Id;
4033 Value : Node_Id;
4035 begin
4036 Value :=
4037 New_Occurrence_Of
4038 (Defining_Identifier (Current_Parameter), Loc);
4040 if Nkind (Typ) = N_Access_Definition then
4041 Value := Make_Explicit_Dereference (Loc, Value);
4042 Etyp := Etype (Subtype_Mark (Typ));
4043 else
4044 Etyp := Etype (Typ);
4045 end if;
4047 if (Out_Present (Current_Parameter)
4048 or else Nkind (Typ) = N_Access_Definition)
4049 and then Etyp /= Stub_Type
4050 then
4051 Append_To (Non_Asynchronous_Statements,
4052 Make_Attribute_Reference (Loc,
4053 Prefix =>
4054 New_Occurrence_Of (Etyp, Loc),
4056 Attribute_Name => Name_Read,
4058 Expressions => New_List (
4059 Make_Attribute_Reference (Loc,
4060 Prefix =>
4061 New_Occurrence_Of (Result_Parameter, Loc),
4062 Attribute_Name =>
4063 Name_Access),
4064 Value)));
4065 end if;
4066 end;
4068 Next (Current_Parameter);
4069 end loop;
4070 end if;
4071 end if;
4073 if Is_Known_Asynchronous then
4074 Append_List_To (Statements, Asynchronous_Statements);
4076 elsif Is_Known_Non_Asynchronous then
4077 Append_List_To (Statements, Non_Asynchronous_Statements);
4079 else
4080 pragma Assert (Present (Asynchronous));
4081 Prepend_To (Asynchronous_Statements,
4082 Make_Attribute_Reference (Loc,
4083 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4084 Attribute_Name => Name_Write,
4085 Expressions => New_List (
4086 Make_Attribute_Reference (Loc,
4087 Prefix =>
4088 New_Occurrence_Of (Stream_Parameter, Loc),
4089 Attribute_Name => Name_Access),
4090 New_Occurrence_Of (Standard_True, Loc))));
4092 Prepend_To (Non_Asynchronous_Statements,
4093 Make_Attribute_Reference (Loc,
4094 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4095 Attribute_Name => Name_Write,
4096 Expressions => New_List (
4097 Make_Attribute_Reference (Loc,
4098 Prefix =>
4099 New_Occurrence_Of (Stream_Parameter, Loc),
4100 Attribute_Name => Name_Access),
4101 New_Occurrence_Of (Standard_False, Loc))));
4103 Append_To (Statements,
4104 Make_Implicit_If_Statement (Nod,
4105 Condition => Asynchronous,
4106 Then_Statements => Asynchronous_Statements,
4107 Else_Statements => Non_Asynchronous_Statements));
4108 end if;
4109 end Build_General_Calling_Stubs;
4111 -----------------------------
4112 -- Build_RPC_Receiver_Body --
4113 -----------------------------
4115 procedure Build_RPC_Receiver_Body
4116 (RPC_Receiver : Entity_Id;
4117 Request : out Entity_Id;
4118 Subp_Id : out Entity_Id;
4119 Subp_Index : out Entity_Id;
4120 Stmts : out List_Id;
4121 Decl : out Node_Id)
4123 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
4125 RPC_Receiver_Spec : Node_Id;
4126 RPC_Receiver_Decls : List_Id;
4128 begin
4129 Request := Make_Defining_Identifier (Loc, Name_R);
4131 RPC_Receiver_Spec :=
4132 Build_RPC_Receiver_Specification
4133 (RPC_Receiver => RPC_Receiver,
4134 Request_Parameter => Request);
4136 Subp_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
4137 Subp_Index := Subp_Id;
4139 -- Subp_Id may not be a constant, because in the case of the RPC
4140 -- receiver for an RCI package, when a call is received from a RAS
4141 -- dereference, it will be assigned during subsequent processing.
4143 RPC_Receiver_Decls := New_List (
4144 Make_Object_Declaration (Loc,
4145 Defining_Identifier => Subp_Id,
4146 Object_Definition =>
4147 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
4148 Expression =>
4149 Make_Attribute_Reference (Loc,
4150 Prefix =>
4151 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
4152 Attribute_Name => Name_Input,
4153 Expressions => New_List (
4154 Make_Selected_Component (Loc,
4155 Prefix => Request,
4156 Selector_Name => Name_Params)))));
4158 Stmts := New_List;
4160 Decl :=
4161 Make_Subprogram_Body (Loc,
4162 Specification => RPC_Receiver_Spec,
4163 Declarations => RPC_Receiver_Decls,
4164 Handled_Statement_Sequence =>
4165 Make_Handled_Sequence_Of_Statements (Loc,
4166 Statements => Stmts));
4167 end Build_RPC_Receiver_Body;
4169 -----------------------
4170 -- Build_Stub_Target --
4171 -----------------------
4173 function Build_Stub_Target
4174 (Loc : Source_Ptr;
4175 Decls : List_Id;
4176 RCI_Locator : Entity_Id;
4177 Controlling_Parameter : Entity_Id) return RPC_Target
4179 Target_Info : RPC_Target (PCS_Kind => Name_GARLIC_DSA);
4180 begin
4181 Target_Info.Partition :=
4182 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
4183 if Present (Controlling_Parameter) then
4184 Append_To (Decls,
4185 Make_Object_Declaration (Loc,
4186 Defining_Identifier => Target_Info.Partition,
4187 Constant_Present => True,
4188 Object_Definition =>
4189 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
4191 Expression =>
4192 Make_Selected_Component (Loc,
4193 Prefix => Controlling_Parameter,
4194 Selector_Name => Name_Origin)));
4196 Target_Info.RPC_Receiver :=
4197 Make_Selected_Component (Loc,
4198 Prefix => Controlling_Parameter,
4199 Selector_Name => Name_Receiver);
4201 else
4202 Append_To (Decls,
4203 Make_Object_Declaration (Loc,
4204 Defining_Identifier => Target_Info.Partition,
4205 Constant_Present => True,
4206 Object_Definition =>
4207 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
4209 Expression =>
4210 Make_Function_Call (Loc,
4211 Name => Make_Selected_Component (Loc,
4212 Prefix =>
4213 Make_Identifier (Loc, Chars (RCI_Locator)),
4214 Selector_Name =>
4215 Make_Identifier (Loc,
4216 Name_Get_Active_Partition_ID)))));
4218 Target_Info.RPC_Receiver :=
4219 Make_Selected_Component (Loc,
4220 Prefix =>
4221 Make_Identifier (Loc, Chars (RCI_Locator)),
4222 Selector_Name =>
4223 Make_Identifier (Loc, Name_Get_RCI_Package_Receiver));
4224 end if;
4225 return Target_Info;
4226 end Build_Stub_Target;
4228 ---------------------
4229 -- Build_Stub_Type --
4230 ---------------------
4232 procedure Build_Stub_Type
4233 (RACW_Type : Entity_Id;
4234 Stub_Type : Entity_Id;
4235 Stub_Type_Decl : out Node_Id;
4236 RPC_Receiver_Decl : out Node_Id)
4238 Loc : constant Source_Ptr := Sloc (Stub_Type);
4239 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
4241 begin
4242 Stub_Type_Decl :=
4243 Make_Full_Type_Declaration (Loc,
4244 Defining_Identifier => Stub_Type,
4245 Type_Definition =>
4246 Make_Record_Definition (Loc,
4247 Tagged_Present => True,
4248 Limited_Present => True,
4249 Component_List =>
4250 Make_Component_List (Loc,
4251 Component_Items => New_List (
4253 Make_Component_Declaration (Loc,
4254 Defining_Identifier =>
4255 Make_Defining_Identifier (Loc, Name_Origin),
4256 Component_Definition =>
4257 Make_Component_Definition (Loc,
4258 Aliased_Present => False,
4259 Subtype_Indication =>
4260 New_Occurrence_Of (
4261 RTE (RE_Partition_ID), Loc))),
4263 Make_Component_Declaration (Loc,
4264 Defining_Identifier =>
4265 Make_Defining_Identifier (Loc, Name_Receiver),
4266 Component_Definition =>
4267 Make_Component_Definition (Loc,
4268 Aliased_Present => False,
4269 Subtype_Indication =>
4270 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc))),
4272 Make_Component_Declaration (Loc,
4273 Defining_Identifier =>
4274 Make_Defining_Identifier (Loc, Name_Addr),
4275 Component_Definition =>
4276 Make_Component_Definition (Loc,
4277 Aliased_Present => False,
4278 Subtype_Indication =>
4279 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc))),
4281 Make_Component_Declaration (Loc,
4282 Defining_Identifier =>
4283 Make_Defining_Identifier (Loc, Name_Asynchronous),
4284 Component_Definition =>
4285 Make_Component_Definition (Loc,
4286 Aliased_Present => False,
4287 Subtype_Indication =>
4288 New_Occurrence_Of (
4289 Standard_Boolean, Loc)))))));
4291 if Is_RAS then
4292 RPC_Receiver_Decl := Empty;
4293 else
4294 declare
4295 RPC_Receiver_Request : constant Entity_Id :=
4296 Make_Defining_Identifier (Loc, Name_R);
4297 begin
4298 RPC_Receiver_Decl :=
4299 Make_Subprogram_Declaration (Loc,
4300 Build_RPC_Receiver_Specification (
4301 RPC_Receiver => Make_Defining_Identifier (Loc,
4302 New_Internal_Name ('R')),
4303 Request_Parameter => RPC_Receiver_Request));
4304 end;
4305 end if;
4306 end Build_Stub_Type;
4308 --------------------------------------
4309 -- Build_Subprogram_Receiving_Stubs --
4310 --------------------------------------
4312 function Build_Subprogram_Receiving_Stubs
4313 (Vis_Decl : Node_Id;
4314 Asynchronous : Boolean;
4315 Dynamically_Asynchronous : Boolean := False;
4316 Stub_Type : Entity_Id := Empty;
4317 RACW_Type : Entity_Id := Empty;
4318 Parent_Primitive : Entity_Id := Empty) return Node_Id
4320 Loc : constant Source_Ptr := Sloc (Vis_Decl);
4322 Request_Parameter : Node_Id;
4323 -- ???
4325 Decls : constant List_Id := New_List;
4326 -- All the parameters will get declared before calling the real
4327 -- subprograms. Also the out parameters will be declared.
4329 Statements : constant List_Id := New_List;
4331 Extra_Formal_Statements : constant List_Id := New_List;
4332 -- Statements concerning extra formal parameters
4334 After_Statements : constant List_Id := New_List;
4335 -- Statements to be executed after the subprogram call
4337 Inner_Decls : List_Id := No_List;
4338 -- In case of a function, the inner declarations are needed since
4339 -- the result may be unconstrained.
4341 Excep_Handlers : List_Id := No_List;
4342 Excep_Choice : Entity_Id;
4343 Excep_Code : List_Id;
4345 Parameter_List : constant List_Id := New_List;
4346 -- List of parameters to be passed to the subprogram
4348 Current_Parameter : Node_Id;
4350 Ordered_Parameters_List : constant List_Id :=
4351 Build_Ordered_Parameters_List
4352 (Specification (Vis_Decl));
4354 Subp_Spec : Node_Id;
4355 -- Subprogram specification
4357 Called_Subprogram : Node_Id;
4358 -- The subprogram to call
4360 Null_Raise_Statement : Node_Id;
4362 Dynamic_Async : Entity_Id;
4364 begin
4365 if Present (RACW_Type) then
4366 Called_Subprogram :=
4367 New_Occurrence_Of (Parent_Primitive, Loc);
4368 else
4369 Called_Subprogram :=
4370 New_Occurrence_Of (
4371 Defining_Unit_Name (Specification (Vis_Decl)), Loc);
4372 end if;
4374 Request_Parameter :=
4375 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
4377 if Dynamically_Asynchronous then
4378 Dynamic_Async :=
4379 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
4380 else
4381 Dynamic_Async := Empty;
4382 end if;
4384 if not Asynchronous or Dynamically_Asynchronous then
4386 -- The first statement after the subprogram call is a statement to
4387 -- writes a Null_Occurrence into the result stream.
4389 Null_Raise_Statement :=
4390 Make_Attribute_Reference (Loc,
4391 Prefix =>
4392 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
4393 Attribute_Name => Name_Write,
4394 Expressions => New_List (
4395 Make_Selected_Component (Loc,
4396 Prefix => Request_Parameter,
4397 Selector_Name => Name_Result),
4398 New_Occurrence_Of (RTE (RE_Null_Occurrence), Loc)));
4400 if Dynamically_Asynchronous then
4401 Null_Raise_Statement :=
4402 Make_Implicit_If_Statement (Vis_Decl,
4403 Condition =>
4404 Make_Op_Not (Loc, New_Occurrence_Of (Dynamic_Async, Loc)),
4405 Then_Statements => New_List (Null_Raise_Statement));
4406 end if;
4408 Append_To (After_Statements, Null_Raise_Statement);
4409 end if;
4411 -- Loop through every parameter and get its value from the stream. If
4412 -- the parameter is unconstrained, then the parameter is read using
4413 -- 'Input at the point of declaration.
4415 Current_Parameter := First (Ordered_Parameters_List);
4416 while Present (Current_Parameter) loop
4417 declare
4418 Etyp : Entity_Id;
4419 Constrained : Boolean;
4421 Object : constant Entity_Id :=
4422 Make_Defining_Identifier (Loc,
4423 New_Internal_Name ('P'));
4425 Expr : Node_Id := Empty;
4427 Is_Controlling_Formal : constant Boolean :=
4428 Is_RACW_Controlling_Formal
4429 (Current_Parameter, Stub_Type);
4431 begin
4432 Set_Ekind (Object, E_Variable);
4434 if Is_Controlling_Formal then
4436 -- We have a controlling formal parameter. Read its address
4437 -- rather than a real object. The address is in Unsigned_64
4438 -- form.
4440 Etyp := RTE (RE_Unsigned_64);
4441 else
4442 Etyp := Etype (Parameter_Type (Current_Parameter));
4443 end if;
4445 Constrained :=
4446 Is_Constrained (Etyp) or else Is_Elementary_Type (Etyp);
4448 if In_Present (Current_Parameter)
4449 or else not Out_Present (Current_Parameter)
4450 or else not Constrained
4451 or else Is_Controlling_Formal
4452 then
4453 -- If an input parameter is contrained, then its reading is
4454 -- deferred until the beginning of the subprogram body. If
4455 -- it is unconstrained, then an expression is built for
4456 -- the object declaration and the variable is set using
4457 -- 'Input instead of 'Read.
4459 if Constrained and then not Is_Controlling_Formal then
4460 Append_To (Statements,
4461 Make_Attribute_Reference (Loc,
4462 Prefix => New_Occurrence_Of (Etyp, Loc),
4463 Attribute_Name => Name_Read,
4464 Expressions => New_List (
4465 Make_Selected_Component (Loc,
4466 Prefix => Request_Parameter,
4467 Selector_Name => Name_Params),
4468 New_Occurrence_Of (Object, Loc))));
4470 else
4471 Expr := Input_With_Tag_Check (Loc,
4472 Var_Type => Etyp,
4473 Stream => Make_Selected_Component (Loc,
4474 Prefix => Request_Parameter,
4475 Selector_Name => Name_Params));
4476 Append_To (Decls, Expr);
4477 Expr := Make_Function_Call (Loc,
4478 New_Occurrence_Of (Defining_Unit_Name
4479 (Specification (Expr)), Loc));
4480 end if;
4481 end if;
4483 -- If we do not have to output the current parameter, then it
4484 -- can well be flagged as constant. This may allow further
4485 -- optimizations done by the back end.
4487 Append_To (Decls,
4488 Make_Object_Declaration (Loc,
4489 Defining_Identifier => Object,
4490 Constant_Present => not Constrained
4491 and then not Out_Present (Current_Parameter),
4492 Object_Definition =>
4493 New_Occurrence_Of (Etyp, Loc),
4494 Expression => Expr));
4496 -- An out parameter may be written back using a 'Write
4497 -- attribute instead of a 'Output because it has been
4498 -- constrained by the parameter given to the caller. Note that
4499 -- out controlling arguments in the case of a RACW are not put
4500 -- back in the stream because the pointer on them has not
4501 -- changed.
4503 if Out_Present (Current_Parameter)
4504 and then
4505 Etype (Parameter_Type (Current_Parameter)) /= Stub_Type
4506 then
4507 Append_To (After_Statements,
4508 Make_Attribute_Reference (Loc,
4509 Prefix => New_Occurrence_Of (Etyp, Loc),
4510 Attribute_Name => Name_Write,
4511 Expressions => New_List (
4512 Make_Selected_Component (Loc,
4513 Prefix => Request_Parameter,
4514 Selector_Name => Name_Result),
4515 New_Occurrence_Of (Object, Loc))));
4516 end if;
4518 -- For RACW controlling formals, the Etyp of Object is always
4519 -- an RACW, even if the parameter is not of an anonymous access
4520 -- type. In such case, we need to dereference it at call time.
4522 if Is_Controlling_Formal then
4523 if Nkind (Parameter_Type (Current_Parameter)) /=
4524 N_Access_Definition
4525 then
4526 Append_To (Parameter_List,
4527 Make_Parameter_Association (Loc,
4528 Selector_Name =>
4529 New_Occurrence_Of (
4530 Defining_Identifier (Current_Parameter), Loc),
4531 Explicit_Actual_Parameter =>
4532 Make_Explicit_Dereference (Loc,
4533 Unchecked_Convert_To (RACW_Type,
4534 OK_Convert_To (RTE (RE_Address),
4535 New_Occurrence_Of (Object, Loc))))));
4537 else
4538 Append_To (Parameter_List,
4539 Make_Parameter_Association (Loc,
4540 Selector_Name =>
4541 New_Occurrence_Of (
4542 Defining_Identifier (Current_Parameter), Loc),
4543 Explicit_Actual_Parameter =>
4544 Unchecked_Convert_To (RACW_Type,
4545 OK_Convert_To (RTE (RE_Address),
4546 New_Occurrence_Of (Object, Loc)))));
4547 end if;
4549 else
4550 Append_To (Parameter_List,
4551 Make_Parameter_Association (Loc,
4552 Selector_Name =>
4553 New_Occurrence_Of (
4554 Defining_Identifier (Current_Parameter), Loc),
4555 Explicit_Actual_Parameter =>
4556 New_Occurrence_Of (Object, Loc)));
4557 end if;
4559 -- If the current parameter needs an extra formal, then read it
4560 -- from the stream and set the corresponding semantic field in
4561 -- the variable. If the kind of the parameter identifier is
4562 -- E_Void, then this is a compiler generated parameter that
4563 -- doesn't need an extra constrained status.
4565 -- The case of Extra_Accessibility should also be handled ???
4567 if Nkind (Parameter_Type (Current_Parameter)) /=
4568 N_Access_Definition
4569 and then
4570 Ekind (Defining_Identifier (Current_Parameter)) /= E_Void
4571 and then
4572 Present (Extra_Constrained
4573 (Defining_Identifier (Current_Parameter)))
4574 then
4575 declare
4576 Extra_Parameter : constant Entity_Id :=
4577 Extra_Constrained
4578 (Defining_Identifier
4579 (Current_Parameter));
4581 Formal_Entity : constant Entity_Id :=
4582 Make_Defining_Identifier
4583 (Loc, Chars (Extra_Parameter));
4585 Formal_Type : constant Entity_Id :=
4586 Etype (Extra_Parameter);
4588 begin
4589 Append_To (Decls,
4590 Make_Object_Declaration (Loc,
4591 Defining_Identifier => Formal_Entity,
4592 Object_Definition =>
4593 New_Occurrence_Of (Formal_Type, Loc)));
4595 Append_To (Extra_Formal_Statements,
4596 Make_Attribute_Reference (Loc,
4597 Prefix => New_Occurrence_Of (
4598 Formal_Type, Loc),
4599 Attribute_Name => Name_Read,
4600 Expressions => New_List (
4601 Make_Selected_Component (Loc,
4602 Prefix => Request_Parameter,
4603 Selector_Name => Name_Params),
4604 New_Occurrence_Of (Formal_Entity, Loc))));
4605 Set_Extra_Constrained (Object, Formal_Entity);
4606 end;
4607 end if;
4608 end;
4610 Next (Current_Parameter);
4611 end loop;
4613 -- Append the formal statements list at the end of regular statements
4615 Append_List_To (Statements, Extra_Formal_Statements);
4617 if Nkind (Specification (Vis_Decl)) = N_Function_Specification then
4619 -- The remote subprogram is a function. We build an inner block to
4620 -- be able to hold a potentially unconstrained result in a
4621 -- variable.
4623 declare
4624 Etyp : constant Entity_Id :=
4625 Etype (Subtype_Mark (Specification (Vis_Decl)));
4626 Result : constant Node_Id :=
4627 Make_Defining_Identifier (Loc,
4628 New_Internal_Name ('R'));
4629 begin
4630 Inner_Decls := New_List (
4631 Make_Object_Declaration (Loc,
4632 Defining_Identifier => Result,
4633 Constant_Present => True,
4634 Object_Definition => New_Occurrence_Of (Etyp, Loc),
4635 Expression =>
4636 Make_Function_Call (Loc,
4637 Name => Called_Subprogram,
4638 Parameter_Associations => Parameter_List)));
4640 Append_To (After_Statements,
4641 Make_Attribute_Reference (Loc,
4642 Prefix => New_Occurrence_Of (Etyp, Loc),
4643 Attribute_Name => Name_Output,
4644 Expressions => New_List (
4645 Make_Selected_Component (Loc,
4646 Prefix => Request_Parameter,
4647 Selector_Name => Name_Result),
4648 New_Occurrence_Of (Result, Loc))));
4649 end;
4651 Append_To (Statements,
4652 Make_Block_Statement (Loc,
4653 Declarations => Inner_Decls,
4654 Handled_Statement_Sequence =>
4655 Make_Handled_Sequence_Of_Statements (Loc,
4656 Statements => After_Statements)));
4658 else
4659 -- The remote subprogram is a procedure. We do not need any inner
4660 -- block in this case.
4662 if Dynamically_Asynchronous then
4663 Append_To (Decls,
4664 Make_Object_Declaration (Loc,
4665 Defining_Identifier => Dynamic_Async,
4666 Object_Definition =>
4667 New_Occurrence_Of (Standard_Boolean, Loc)));
4669 Append_To (Statements,
4670 Make_Attribute_Reference (Loc,
4671 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4672 Attribute_Name => Name_Read,
4673 Expressions => New_List (
4674 Make_Selected_Component (Loc,
4675 Prefix => Request_Parameter,
4676 Selector_Name => Name_Params),
4677 New_Occurrence_Of (Dynamic_Async, Loc))));
4678 end if;
4680 Append_To (Statements,
4681 Make_Procedure_Call_Statement (Loc,
4682 Name => Called_Subprogram,
4683 Parameter_Associations => Parameter_List));
4685 Append_List_To (Statements, After_Statements);
4686 end if;
4688 if Asynchronous and then not Dynamically_Asynchronous then
4690 -- For an asynchronous procedure, add a null exception handler
4692 Excep_Handlers := New_List (
4693 Make_Exception_Handler (Loc,
4694 Exception_Choices => New_List (Make_Others_Choice (Loc)),
4695 Statements => New_List (Make_Null_Statement (Loc))));
4697 else
4698 -- In the other cases, if an exception is raised, then the
4699 -- exception occurrence is copied into the output stream and
4700 -- no other output parameter is written.
4702 Excep_Choice :=
4703 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
4705 Excep_Code := New_List (
4706 Make_Attribute_Reference (Loc,
4707 Prefix =>
4708 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
4709 Attribute_Name => Name_Write,
4710 Expressions => New_List (
4711 Make_Selected_Component (Loc,
4712 Prefix => Request_Parameter,
4713 Selector_Name => Name_Result),
4714 New_Occurrence_Of (Excep_Choice, Loc))));
4716 if Dynamically_Asynchronous then
4717 Excep_Code := New_List (
4718 Make_Implicit_If_Statement (Vis_Decl,
4719 Condition => Make_Op_Not (Loc,
4720 New_Occurrence_Of (Dynamic_Async, Loc)),
4721 Then_Statements => Excep_Code));
4722 end if;
4724 Excep_Handlers := New_List (
4725 Make_Exception_Handler (Loc,
4726 Choice_Parameter => Excep_Choice,
4727 Exception_Choices => New_List (Make_Others_Choice (Loc)),
4728 Statements => Excep_Code));
4730 end if;
4732 Subp_Spec :=
4733 Make_Procedure_Specification (Loc,
4734 Defining_Unit_Name =>
4735 Make_Defining_Identifier (Loc, New_Internal_Name ('F')),
4737 Parameter_Specifications => New_List (
4738 Make_Parameter_Specification (Loc,
4739 Defining_Identifier => Request_Parameter,
4740 Parameter_Type =>
4741 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
4743 return
4744 Make_Subprogram_Body (Loc,
4745 Specification => Subp_Spec,
4746 Declarations => Decls,
4747 Handled_Statement_Sequence =>
4748 Make_Handled_Sequence_Of_Statements (Loc,
4749 Statements => Statements,
4750 Exception_Handlers => Excep_Handlers));
4751 end Build_Subprogram_Receiving_Stubs;
4753 ------------
4754 -- Result --
4755 ------------
4757 function Result return Node_Id is
4758 begin
4759 return Make_Identifier (Loc, Name_V);
4760 end Result;
4762 ----------------------
4763 -- Stream_Parameter --
4764 ----------------------
4766 function Stream_Parameter return Node_Id is
4767 begin
4768 return Make_Identifier (Loc, Name_S);
4769 end Stream_Parameter;
4771 end GARLIC_Support;
4773 -----------------------------
4774 -- Make_Selected_Component --
4775 -----------------------------
4777 function Make_Selected_Component
4778 (Loc : Source_Ptr;
4779 Prefix : Entity_Id;
4780 Selector_Name : Name_Id) return Node_Id
4782 begin
4783 return Make_Selected_Component (Loc,
4784 Prefix => New_Occurrence_Of (Prefix, Loc),
4785 Selector_Name => Make_Identifier (Loc, Selector_Name));
4786 end Make_Selected_Component;
4788 ------------------
4789 -- Get_PCS_Name --
4790 ------------------
4792 function Get_PCS_Name return PCS_Names is
4793 PCS_Name : constant PCS_Names :=
4794 Chars (Entity (Expression
4795 (Parent (RTE (RE_DSA_Implementation)))));
4796 begin
4797 return PCS_Name;
4798 end Get_PCS_Name;
4800 -----------------------
4801 -- Get_Subprogram_Id --
4802 -----------------------
4804 function Get_Subprogram_Id (Def : Entity_Id) return String_Id is
4805 begin
4806 return Get_Subprogram_Ids (Def).Str_Identifier;
4807 end Get_Subprogram_Id;
4809 -----------------------
4810 -- Get_Subprogram_Id --
4811 -----------------------
4813 function Get_Subprogram_Id (Def : Entity_Id) return Int is
4814 begin
4815 return Get_Subprogram_Ids (Def).Int_Identifier;
4816 end Get_Subprogram_Id;
4818 ------------------------
4819 -- Get_Subprogram_Ids --
4820 ------------------------
4822 function Get_Subprogram_Ids
4823 (Def : Entity_Id) return Subprogram_Identifiers
4825 Result : Subprogram_Identifiers :=
4826 Subprogram_Identifier_Table.Get (Def);
4828 Current_Declaration : Node_Id;
4829 Current_Subp : Entity_Id;
4830 Current_Subp_Str : String_Id;
4831 Current_Subp_Number : Int := First_RCI_Subprogram_Id;
4833 begin
4834 if Result.Str_Identifier = No_String then
4836 -- We are looking up this subprogram's identifier outside of the
4837 -- context of generating calling or receiving stubs. Hence we are
4838 -- processing an 'Access attribute_reference for an RCI subprogram,
4839 -- for the purpose of obtaining a RAS value.
4841 pragma Assert
4842 (Is_Remote_Call_Interface (Scope (Def))
4843 and then
4844 (Nkind (Parent (Def)) = N_Procedure_Specification
4845 or else
4846 Nkind (Parent (Def)) = N_Function_Specification));
4848 Current_Declaration :=
4849 First (Visible_Declarations
4850 (Package_Specification_Of_Scope (Scope (Def))));
4851 while Present (Current_Declaration) loop
4852 if Nkind (Current_Declaration) = N_Subprogram_Declaration
4853 and then Comes_From_Source (Current_Declaration)
4854 then
4855 Current_Subp := Defining_Unit_Name (Specification (
4856 Current_Declaration));
4857 Assign_Subprogram_Identifier
4858 (Current_Subp, Current_Subp_Number, Current_Subp_Str);
4860 if Current_Subp = Def then
4861 Result := (Current_Subp_Str, Current_Subp_Number);
4862 end if;
4864 Current_Subp_Number := Current_Subp_Number + 1;
4865 end if;
4867 Next (Current_Declaration);
4868 end loop;
4869 end if;
4871 pragma Assert (Result.Str_Identifier /= No_String);
4872 return Result;
4873 end Get_Subprogram_Ids;
4875 ----------
4876 -- Hash --
4877 ----------
4879 function Hash (F : Entity_Id) return Hash_Index is
4880 begin
4881 return Hash_Index (Natural (F) mod Positive (Hash_Index'Last + 1));
4882 end Hash;
4884 function Hash (F : Name_Id) return Hash_Index is
4885 begin
4886 return Hash_Index (Natural (F) mod Positive (Hash_Index'Last + 1));
4887 end Hash;
4889 --------------------------
4890 -- Input_With_Tag_Check --
4891 --------------------------
4893 function Input_With_Tag_Check
4894 (Loc : Source_Ptr;
4895 Var_Type : Entity_Id;
4896 Stream : Node_Id) return Node_Id
4898 begin
4899 return
4900 Make_Subprogram_Body (Loc,
4901 Specification => Make_Function_Specification (Loc,
4902 Defining_Unit_Name =>
4903 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4904 Subtype_Mark => New_Occurrence_Of (Var_Type, Loc)),
4905 Declarations => No_List,
4906 Handled_Statement_Sequence =>
4907 Make_Handled_Sequence_Of_Statements (Loc, New_List (
4908 Make_Tag_Check (Loc,
4909 Make_Return_Statement (Loc,
4910 Make_Attribute_Reference (Loc,
4911 Prefix => New_Occurrence_Of (Var_Type, Loc),
4912 Attribute_Name => Name_Input,
4913 Expressions =>
4914 New_List (Stream)))))));
4915 end Input_With_Tag_Check;
4917 --------------------------------
4918 -- Is_RACW_Controlling_Formal --
4919 --------------------------------
4921 function Is_RACW_Controlling_Formal
4922 (Parameter : Node_Id;
4923 Stub_Type : Entity_Id) return Boolean
4925 Typ : Entity_Id;
4927 begin
4928 -- If the kind of the parameter is E_Void, then it is not a
4929 -- controlling formal (this can happen in the context of RAS).
4931 if Ekind (Defining_Identifier (Parameter)) = E_Void then
4932 return False;
4933 end if;
4935 -- If the parameter is not a controlling formal, then it cannot
4936 -- be possibly a RACW_Controlling_Formal.
4938 if not Is_Controlling_Formal (Defining_Identifier (Parameter)) then
4939 return False;
4940 end if;
4942 Typ := Parameter_Type (Parameter);
4943 return (Nkind (Typ) = N_Access_Definition
4944 and then Etype (Subtype_Mark (Typ)) = Stub_Type)
4945 or else Etype (Typ) = Stub_Type;
4946 end Is_RACW_Controlling_Formal;
4948 --------------------
4949 -- Make_Tag_Check --
4950 --------------------
4952 function Make_Tag_Check (Loc : Source_Ptr; N : Node_Id) return Node_Id is
4953 Occ : constant Entity_Id :=
4954 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
4956 begin
4957 return Make_Block_Statement (Loc,
4958 Handled_Statement_Sequence =>
4959 Make_Handled_Sequence_Of_Statements (Loc,
4960 Statements => New_List (N),
4962 Exception_Handlers => New_List (
4963 Make_Exception_Handler (Loc,
4964 Choice_Parameter => Occ,
4966 Exception_Choices =>
4967 New_List (New_Occurrence_Of (RTE (RE_Tag_Error), Loc)),
4969 Statements =>
4970 New_List (Make_Procedure_Call_Statement (Loc,
4971 New_Occurrence_Of
4972 (RTE (RE_Raise_Program_Error_Unknown_Tag), Loc),
4973 New_List (New_Occurrence_Of (Occ, Loc))))))));
4974 end Make_Tag_Check;
4976 ----------------------------
4977 -- Need_Extra_Constrained --
4978 ----------------------------
4980 function Need_Extra_Constrained (Parameter : Node_Id) return Boolean is
4981 Etyp : constant Entity_Id := Etype (Parameter_Type (Parameter));
4982 begin
4983 return Out_Present (Parameter)
4984 and then Has_Discriminants (Etyp)
4985 and then not Is_Constrained (Etyp)
4986 and then not Is_Indefinite_Subtype (Etyp);
4987 end Need_Extra_Constrained;
4989 ------------------------------------
4990 -- Pack_Entity_Into_Stream_Access --
4991 ------------------------------------
4993 function Pack_Entity_Into_Stream_Access
4994 (Loc : Source_Ptr;
4995 Stream : Node_Id;
4996 Object : Entity_Id;
4997 Etyp : Entity_Id := Empty) return Node_Id
4999 Typ : Entity_Id;
5001 begin
5002 if Present (Etyp) then
5003 Typ := Etyp;
5004 else
5005 Typ := Etype (Object);
5006 end if;
5008 return
5009 Pack_Node_Into_Stream_Access (Loc,
5010 Stream => Stream,
5011 Object => New_Occurrence_Of (Object, Loc),
5012 Etyp => Typ);
5013 end Pack_Entity_Into_Stream_Access;
5015 ---------------------------
5016 -- Pack_Node_Into_Stream --
5017 ---------------------------
5019 function Pack_Node_Into_Stream
5020 (Loc : Source_Ptr;
5021 Stream : Entity_Id;
5022 Object : Node_Id;
5023 Etyp : Entity_Id) return Node_Id
5025 Write_Attribute : Name_Id := Name_Write;
5027 begin
5028 if not Is_Constrained (Etyp) then
5029 Write_Attribute := Name_Output;
5030 end if;
5032 return
5033 Make_Attribute_Reference (Loc,
5034 Prefix => New_Occurrence_Of (Etyp, Loc),
5035 Attribute_Name => Write_Attribute,
5036 Expressions => New_List (
5037 Make_Attribute_Reference (Loc,
5038 Prefix => New_Occurrence_Of (Stream, Loc),
5039 Attribute_Name => Name_Access),
5040 Object));
5041 end Pack_Node_Into_Stream;
5043 ----------------------------------
5044 -- Pack_Node_Into_Stream_Access --
5045 ----------------------------------
5047 function Pack_Node_Into_Stream_Access
5048 (Loc : Source_Ptr;
5049 Stream : Node_Id;
5050 Object : Node_Id;
5051 Etyp : Entity_Id) return Node_Id
5053 Write_Attribute : Name_Id := Name_Write;
5055 begin
5056 if not Is_Constrained (Etyp) then
5057 Write_Attribute := Name_Output;
5058 end if;
5060 return
5061 Make_Attribute_Reference (Loc,
5062 Prefix => New_Occurrence_Of (Etyp, Loc),
5063 Attribute_Name => Write_Attribute,
5064 Expressions => New_List (
5065 Stream,
5066 Object));
5067 end Pack_Node_Into_Stream_Access;
5069 ---------------------
5070 -- PolyORB_Support --
5071 ---------------------
5073 package body PolyORB_Support is
5075 -- Local subprograms
5077 procedure Add_RACW_Read_Attribute
5078 (RACW_Type : Entity_Id;
5079 Stub_Type : Entity_Id;
5080 Stub_Type_Access : Entity_Id;
5081 Declarations : List_Id);
5082 -- Add Read attribute in Decls for the RACW type. The Read attribute
5083 -- is added right after the RACW_Type declaration while the body is
5084 -- inserted after Declarations.
5086 procedure Add_RACW_Write_Attribute
5087 (RACW_Type : Entity_Id;
5088 Stub_Type : Entity_Id;
5089 Stub_Type_Access : Entity_Id;
5090 Declarations : List_Id);
5091 -- Same thing for the Write attribute
5093 procedure Add_RACW_From_Any
5094 (RACW_Type : Entity_Id;
5095 Stub_Type : Entity_Id;
5096 Stub_Type_Access : Entity_Id;
5097 Declarations : List_Id);
5098 -- Add the From_Any TSS for this RACW type
5100 procedure Add_RACW_To_Any
5101 (Designated_Type : Entity_Id;
5102 RACW_Type : Entity_Id;
5103 Stub_Type : Entity_Id;
5104 Stub_Type_Access : Entity_Id;
5105 Declarations : List_Id);
5106 -- Add the To_Any TSS for this RACW type
5108 procedure Add_RACW_TypeCode
5109 (Designated_Type : Entity_Id;
5110 RACW_Type : Entity_Id;
5111 Declarations : List_Id);
5112 -- Add the TypeCode TSS for this RACW type
5114 procedure Add_RAS_From_Any
5115 (RAS_Type : Entity_Id;
5116 Declarations : List_Id);
5117 -- Add the From_Any TSS for this RAS type
5119 procedure Add_RAS_To_Any
5120 (RAS_Type : Entity_Id;
5121 Declarations : List_Id);
5122 -- Add the To_Any TSS for this RAS type
5124 procedure Add_RAS_TypeCode
5125 (RAS_Type : Entity_Id;
5126 Declarations : List_Id);
5127 -- Add the TypeCode TSS for this RAS type
5129 procedure Add_RAS_Access_TSS (N : Node_Id);
5130 -- Add a subprogram body for RAS Access TSS
5132 -------------------------------------
5133 -- Add_Obj_RPC_Receiver_Completion --
5134 -------------------------------------
5136 procedure Add_Obj_RPC_Receiver_Completion
5137 (Loc : Source_Ptr;
5138 Decls : List_Id;
5139 RPC_Receiver : Entity_Id;
5140 Stub_Elements : Stub_Structure)
5142 Desig : constant Entity_Id :=
5143 Etype (Designated_Type (Stub_Elements.RACW_Type));
5144 begin
5145 Append_To (Decls,
5146 Make_Procedure_Call_Statement (Loc,
5147 Name =>
5148 New_Occurrence_Of (
5149 RTE (RE_Register_Obj_Receiving_Stub), Loc),
5151 Parameter_Associations => New_List (
5153 -- Name
5155 Make_String_Literal (Loc,
5156 Full_Qualified_Name (Desig)),
5158 -- Handler
5160 Make_Attribute_Reference (Loc,
5161 Prefix =>
5162 New_Occurrence_Of (
5163 Defining_Unit_Name (Parent (RPC_Receiver)), Loc),
5164 Attribute_Name =>
5165 Name_Access),
5167 -- Receiver
5169 Make_Attribute_Reference (Loc,
5170 Prefix =>
5171 New_Occurrence_Of (
5172 Defining_Identifier (
5173 Stub_Elements.RPC_Receiver_Decl), Loc),
5174 Attribute_Name =>
5175 Name_Access))));
5176 end Add_Obj_RPC_Receiver_Completion;
5178 -----------------------
5179 -- Add_RACW_Features --
5180 -----------------------
5182 procedure Add_RACW_Features
5183 (RACW_Type : Entity_Id;
5184 Desig : Entity_Id;
5185 Stub_Type : Entity_Id;
5186 Stub_Type_Access : Entity_Id;
5187 RPC_Receiver_Decl : Node_Id;
5188 Declarations : List_Id)
5190 pragma Warnings (Off);
5191 pragma Unreferenced (RPC_Receiver_Decl);
5192 pragma Warnings (On);
5194 begin
5195 Add_RACW_From_Any
5196 (RACW_Type => RACW_Type,
5197 Stub_Type => Stub_Type,
5198 Stub_Type_Access => Stub_Type_Access,
5199 Declarations => Declarations);
5201 Add_RACW_To_Any
5202 (Designated_Type => Desig,
5203 RACW_Type => RACW_Type,
5204 Stub_Type => Stub_Type,
5205 Stub_Type_Access => Stub_Type_Access,
5206 Declarations => Declarations);
5208 -- In the PolyORB case, the RACW 'Read and 'Write attributes
5209 -- are implemented in terms of the From_Any and To_Any TSSs,
5210 -- so these TSSs must be expanded before 'Read and 'Write.
5212 Add_RACW_Write_Attribute
5213 (RACW_Type => RACW_Type,
5214 Stub_Type => Stub_Type,
5215 Stub_Type_Access => Stub_Type_Access,
5216 Declarations => Declarations);
5218 Add_RACW_Read_Attribute
5219 (RACW_Type => RACW_Type,
5220 Stub_Type => Stub_Type,
5221 Stub_Type_Access => Stub_Type_Access,
5222 Declarations => Declarations);
5224 Add_RACW_TypeCode
5225 (Designated_Type => Desig,
5226 RACW_Type => RACW_Type,
5227 Declarations => Declarations);
5228 end Add_RACW_Features;
5230 -----------------------
5231 -- Add_RACW_From_Any --
5232 -----------------------
5234 procedure Add_RACW_From_Any
5235 (RACW_Type : Entity_Id;
5236 Stub_Type : Entity_Id;
5237 Stub_Type_Access : Entity_Id;
5238 Declarations : List_Id)
5240 Loc : constant Source_Ptr := Sloc (RACW_Type);
5241 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5243 Fnam : constant Entity_Id :=
5244 Make_Defining_Identifier (Loc, New_Internal_Name ('F'));
5246 Func_Spec : Node_Id;
5247 Func_Decl : Node_Id;
5248 Func_Body : Node_Id;
5250 Decls : List_Id;
5251 Statements : List_Id;
5252 Stub_Statements : List_Id;
5253 Local_Statements : List_Id;
5254 -- Various parts of the subprogram
5256 Any_Parameter : constant Entity_Id :=
5257 Make_Defining_Identifier (Loc, Name_A);
5258 Reference : constant Entity_Id :=
5259 Make_Defining_Identifier
5260 (Loc, New_Internal_Name ('R'));
5261 Is_Local : constant Entity_Id :=
5262 Make_Defining_Identifier
5263 (Loc, New_Internal_Name ('L'));
5264 Addr : constant Entity_Id :=
5265 Make_Defining_Identifier
5266 (Loc, New_Internal_Name ('A'));
5267 Local_Stub : constant Entity_Id :=
5268 Make_Defining_Identifier
5269 (Loc, New_Internal_Name ('L'));
5270 Stubbed_Result : constant Entity_Id :=
5271 Make_Defining_Identifier
5272 (Loc, New_Internal_Name ('S'));
5274 Stub_Condition : Node_Id;
5275 -- An expression that determines whether we create a stub for the
5276 -- newly-unpacked RACW. Normally we create a stub only for remote
5277 -- objects, but in the case of an RACW used to implement a RAS,
5278 -- we also create a stub for local subprograms if a pragma
5279 -- All_Calls_Remote applies.
5281 Asynchronous_Flag : constant Entity_Id :=
5282 Asynchronous_Flags_Table.Get (RACW_Type);
5283 -- The flag object declared in Add_RACW_Asynchronous_Flag
5285 begin
5286 -- Object declarations
5288 Decls := New_List (
5289 Make_Object_Declaration (Loc,
5290 Defining_Identifier =>
5291 Reference,
5292 Object_Definition =>
5293 New_Occurrence_Of (RTE (RE_Object_Ref), Loc),
5294 Expression =>
5295 Make_Function_Call (Loc,
5296 Name =>
5297 New_Occurrence_Of (RTE (RE_FA_ObjRef), Loc),
5298 Parameter_Associations => New_List (
5299 New_Occurrence_Of (Any_Parameter, Loc)))),
5301 Make_Object_Declaration (Loc,
5302 Defining_Identifier => Local_Stub,
5303 Aliased_Present => True,
5304 Object_Definition => New_Occurrence_Of (Stub_Type, Loc)),
5306 Make_Object_Declaration (Loc,
5307 Defining_Identifier => Stubbed_Result,
5308 Object_Definition =>
5309 New_Occurrence_Of (Stub_Type_Access, Loc),
5310 Expression =>
5311 Make_Attribute_Reference (Loc,
5312 Prefix =>
5313 New_Occurrence_Of (Local_Stub, Loc),
5314 Attribute_Name =>
5315 Name_Unchecked_Access)),
5317 Make_Object_Declaration (Loc,
5318 Defining_Identifier => Is_Local,
5319 Object_Definition =>
5320 New_Occurrence_Of (Standard_Boolean, Loc)),
5322 Make_Object_Declaration (Loc,
5323 Defining_Identifier => Addr,
5324 Object_Definition =>
5325 New_Occurrence_Of (RTE (RE_Address), Loc)));
5327 -- Build_Get_Unique_RP_Call needs the type of Stubbed_Result
5329 Set_Etype (Stubbed_Result, Stub_Type_Access);
5331 -- If the ref Is_Nil, return a null pointer
5333 Statements := New_List (
5334 Make_Implicit_If_Statement (RACW_Type,
5335 Condition =>
5336 Make_Function_Call (Loc,
5337 Name =>
5338 New_Occurrence_Of (RTE (RE_Is_Nil), Loc),
5339 Parameter_Associations => New_List (
5340 New_Occurrence_Of (Reference, Loc))),
5341 Then_Statements => New_List (
5342 Make_Return_Statement (Loc,
5343 Expression =>
5344 Make_Null (Loc)))));
5346 Append_To (Statements,
5347 Make_Procedure_Call_Statement (Loc,
5348 Name =>
5349 New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
5350 Parameter_Associations => New_List (
5351 New_Occurrence_Of (Reference, Loc),
5352 New_Occurrence_Of (Is_Local, Loc),
5353 New_Occurrence_Of (Addr, Loc))));
5355 -- If the object is located on another partition, then a stub object
5356 -- will be created with all the information needed to rebuild the
5357 -- real object at the other end. This stanza is always used in the
5358 -- case of RAS types, for which a stub is required even for local
5359 -- subprograms.
5361 Stub_Statements := New_List (
5362 Make_Assignment_Statement (Loc,
5363 Name => Make_Selected_Component (Loc,
5364 Prefix => Stubbed_Result,
5365 Selector_Name => Name_Target),
5366 Expression =>
5367 Make_Function_Call (Loc,
5368 Name =>
5369 New_Occurrence_Of (RTE (RE_Entity_Of), Loc),
5370 Parameter_Associations => New_List (
5371 New_Occurrence_Of (Reference, Loc)))),
5373 Make_Procedure_Call_Statement (Loc,
5374 Name =>
5375 New_Occurrence_Of (RTE (RE_Inc_Usage), Loc),
5376 Parameter_Associations => New_List (
5377 Make_Selected_Component (Loc,
5378 Prefix => Stubbed_Result,
5379 Selector_Name => Name_Target))),
5381 Make_Assignment_Statement (Loc,
5382 Name => Make_Selected_Component (Loc,
5383 Prefix => Stubbed_Result,
5384 Selector_Name => Name_Asynchronous),
5385 Expression =>
5386 New_Occurrence_Of (Asynchronous_Flag, Loc)));
5388 -- ??? Issue with asynchronous calls here: the Asynchronous
5389 -- flag is set on the stub type if, and only if, the RACW type
5390 -- has a pragma Asynchronous. This is incorrect for RACWs that
5391 -- implement RAS types, because in that case the /designated
5392 -- subprogram/ (not the type) might be asynchronous, and
5393 -- that causes the stub to need to be asynchronous too.
5394 -- A solution is to transport a RAS as a struct containing
5395 -- a RACW and an asynchronous flag, and to properly alter
5396 -- the Asynchronous component in the stub type in the RAS's
5397 -- _From_Any TSS.
5399 Append_List_To (Stub_Statements,
5400 Build_Get_Unique_RP_Call (Loc, Stubbed_Result, Stub_Type));
5402 -- Distinguish between the local and remote cases, and execute the
5403 -- appropriate piece of code.
5405 Stub_Condition := New_Occurrence_Of (Is_Local, Loc);
5407 if Is_RAS then
5408 Stub_Condition := Make_And_Then (Loc,
5409 Left_Opnd =>
5410 Stub_Condition,
5411 Right_Opnd =>
5412 Make_Selected_Component (Loc,
5413 Prefix =>
5414 Unchecked_Convert_To (
5415 RTE (RE_RAS_Proxy_Type_Access),
5416 New_Occurrence_Of (Addr, Loc)),
5417 Selector_Name =>
5418 Make_Identifier (Loc,
5419 Name_All_Calls_Remote)));
5420 end if;
5422 Local_Statements := New_List (
5423 Make_Return_Statement (Loc,
5424 Expression =>
5425 Unchecked_Convert_To (RACW_Type,
5426 New_Occurrence_Of (Addr, Loc))));
5428 Append_To (Statements,
5429 Make_Implicit_If_Statement (RACW_Type,
5430 Condition =>
5431 Stub_Condition,
5432 Then_Statements => Local_Statements,
5433 Else_Statements => Stub_Statements));
5435 Append_To (Statements,
5436 Make_Return_Statement (Loc,
5437 Expression => Unchecked_Convert_To (RACW_Type,
5438 New_Occurrence_Of (Stubbed_Result, Loc))));
5440 Func_Spec :=
5441 Make_Function_Specification (Loc,
5442 Defining_Unit_Name =>
5443 Fnam,
5444 Parameter_Specifications => New_List (
5445 Make_Parameter_Specification (Loc,
5446 Defining_Identifier =>
5447 Any_Parameter,
5448 Parameter_Type =>
5449 New_Occurrence_Of (RTE (RE_Any), Loc))),
5450 Subtype_Mark => New_Occurrence_Of (RACW_Type, Loc));
5452 -- NOTE: The usage occurrences of RACW_Parameter must
5453 -- refer to the entity in the declaration spec, not those
5454 -- of the body spec.
5456 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
5458 Func_Body :=
5459 Make_Subprogram_Body (Loc,
5460 Specification =>
5461 Copy_Specification (Loc, Func_Spec),
5462 Declarations => Decls,
5463 Handled_Statement_Sequence =>
5464 Make_Handled_Sequence_Of_Statements (Loc,
5465 Statements => Statements));
5467 Insert_After (Declaration_Node (RACW_Type), Func_Decl);
5468 Append_To (Declarations, Func_Body);
5470 Set_Renaming_TSS (RACW_Type, Fnam, Name_uFrom_Any);
5471 end Add_RACW_From_Any;
5473 -----------------------------
5474 -- Add_RACW_Read_Attribute --
5475 -----------------------------
5477 procedure Add_RACW_Read_Attribute
5478 (RACW_Type : Entity_Id;
5479 Stub_Type : Entity_Id;
5480 Stub_Type_Access : Entity_Id;
5481 Declarations : List_Id)
5483 pragma Warnings (Off);
5484 pragma Unreferenced (Stub_Type, Stub_Type_Access);
5485 pragma Warnings (On);
5486 Loc : constant Source_Ptr := Sloc (RACW_Type);
5488 Proc_Decl : Node_Id;
5489 Attr_Decl : Node_Id;
5491 Body_Node : Node_Id;
5493 Decls : List_Id;
5494 Statements : List_Id;
5495 -- Various parts of the procedure
5497 Procedure_Name : constant Name_Id :=
5498 New_Internal_Name ('R');
5499 Source_Ref : constant Entity_Id :=
5500 Make_Defining_Identifier
5501 (Loc, New_Internal_Name ('R'));
5502 Asynchronous_Flag : constant Entity_Id :=
5503 Asynchronous_Flags_Table.Get (RACW_Type);
5504 pragma Assert (Present (Asynchronous_Flag));
5506 function Stream_Parameter return Node_Id;
5507 function Result return Node_Id;
5508 -- Functions to create occurrences of the formal parameter names
5510 ------------
5511 -- Result --
5512 ------------
5514 function Result return Node_Id is
5515 begin
5516 return Make_Identifier (Loc, Name_V);
5517 end Result;
5519 ----------------------
5520 -- Stream_Parameter --
5521 ----------------------
5523 function Stream_Parameter return Node_Id is
5524 begin
5525 return Make_Identifier (Loc, Name_S);
5526 end Stream_Parameter;
5528 -- Start of processing for Add_RACW_Read_Attribute
5530 begin
5531 -- Generate object declarations
5533 Decls := New_List (
5534 Make_Object_Declaration (Loc,
5535 Defining_Identifier => Source_Ref,
5536 Object_Definition =>
5537 New_Occurrence_Of (RTE (RE_Object_Ref), Loc)));
5539 Statements := New_List (
5540 Make_Attribute_Reference (Loc,
5541 Prefix =>
5542 New_Occurrence_Of (RTE (RE_Object_Ref), Loc),
5543 Attribute_Name => Name_Read,
5544 Expressions => New_List (
5545 Stream_Parameter,
5546 New_Occurrence_Of (Source_Ref, Loc))),
5547 Make_Assignment_Statement (Loc,
5548 Name =>
5549 Result,
5550 Expression =>
5551 PolyORB_Support.Helpers.Build_From_Any_Call (
5552 RACW_Type,
5553 Make_Function_Call (Loc,
5554 Name =>
5555 New_Occurrence_Of (RTE (RE_TA_ObjRef), Loc),
5556 Parameter_Associations => New_List (
5557 New_Occurrence_Of (Source_Ref, Loc))),
5558 Decls)));
5560 Build_Stream_Procedure
5561 (Loc, RACW_Type, Body_Node,
5562 Make_Defining_Identifier (Loc, Procedure_Name),
5563 Statements, Outp => True);
5564 Set_Declarations (Body_Node, Decls);
5566 Proc_Decl := Make_Subprogram_Declaration (Loc,
5567 Copy_Specification (Loc, Specification (Body_Node)));
5569 Attr_Decl :=
5570 Make_Attribute_Definition_Clause (Loc,
5571 Name => New_Occurrence_Of (RACW_Type, Loc),
5572 Chars => Name_Read,
5573 Expression =>
5574 New_Occurrence_Of (
5575 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
5577 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
5578 Insert_After (Proc_Decl, Attr_Decl);
5579 Append_To (Declarations, Body_Node);
5580 end Add_RACW_Read_Attribute;
5582 ---------------------
5583 -- Add_RACW_To_Any --
5584 ---------------------
5586 procedure Add_RACW_To_Any
5587 (Designated_Type : Entity_Id;
5588 RACW_Type : Entity_Id;
5589 Stub_Type : Entity_Id;
5590 Stub_Type_Access : Entity_Id;
5591 Declarations : List_Id)
5593 Loc : constant Source_Ptr := Sloc (RACW_Type);
5595 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5597 Fnam : Entity_Id;
5599 Stub_Elements : constant Stub_Structure :=
5600 Stubs_Table.Get (Designated_Type);
5601 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
5603 Func_Spec : Node_Id;
5604 Func_Decl : Node_Id;
5605 Func_Body : Node_Id;
5607 Decls : List_Id;
5608 Statements : List_Id;
5609 Null_Statements : List_Id;
5610 Local_Statements : List_Id := No_List;
5611 Stub_Statements : List_Id;
5612 If_Node : Node_Id;
5613 -- Various parts of the subprogram
5615 RACW_Parameter : constant Entity_Id
5616 := Make_Defining_Identifier (Loc, Name_R);
5618 Reference : constant Entity_Id :=
5619 Make_Defining_Identifier
5620 (Loc, New_Internal_Name ('R'));
5621 Any : constant Entity_Id :=
5622 Make_Defining_Identifier
5623 (Loc, New_Internal_Name ('A'));
5625 begin
5626 -- Object declarations
5628 Decls := New_List (
5629 Make_Object_Declaration (Loc,
5630 Defining_Identifier =>
5631 Reference,
5632 Object_Definition =>
5633 New_Occurrence_Of (RTE (RE_Object_Ref), Loc)),
5634 Make_Object_Declaration (Loc,
5635 Defining_Identifier =>
5636 Any,
5637 Object_Definition =>
5638 New_Occurrence_Of (RTE (RE_Any), Loc)));
5640 -- If the object is null, nothing to do (Reference is already
5641 -- a Nil ref.)
5643 Null_Statements := New_List (Make_Null_Statement (Loc));
5645 if Is_RAS then
5647 -- If the object is a RAS designating a local subprogram,
5648 -- we already have a target reference.
5650 Local_Statements := New_List (
5651 Make_Procedure_Call_Statement (Loc,
5652 Name =>
5653 New_Occurrence_Of (RTE (RE_Set_Ref), Loc),
5654 Parameter_Associations => New_List (
5655 New_Occurrence_Of (Reference, Loc),
5656 Make_Selected_Component (Loc,
5657 Prefix =>
5658 Unchecked_Convert_To (RTE (RE_RAS_Proxy_Type_Access),
5659 New_Occurrence_Of (RACW_Parameter, Loc)),
5660 Selector_Name => Make_Identifier (Loc, Name_Target)))));
5662 else
5663 -- If the object is a local RACW object, use Get_Reference now
5664 -- to obtain a reference.
5666 Local_Statements := New_List (
5667 Make_Procedure_Call_Statement (Loc,
5668 Name =>
5669 New_Occurrence_Of (RTE (RE_Get_Reference), Loc),
5670 Parameter_Associations => New_List (
5671 Unchecked_Convert_To (
5672 RTE (RE_Address),
5673 New_Occurrence_Of (RACW_Parameter, Loc)),
5674 Make_String_Literal (Loc,
5675 Full_Qualified_Name (Designated_Type)),
5676 Make_Attribute_Reference (Loc,
5677 Prefix =>
5678 New_Occurrence_Of (
5679 Defining_Identifier (
5680 Stub_Elements.RPC_Receiver_Decl), Loc),
5681 Attribute_Name =>
5682 Name_Access),
5683 New_Occurrence_Of (Reference, Loc))));
5684 end if;
5686 -- If the object is located on another partition, use the target
5687 -- from the stub.
5689 Stub_Statements := New_List (
5690 Make_Procedure_Call_Statement (Loc,
5691 Name =>
5692 New_Occurrence_Of (RTE (RE_Set_Ref), Loc),
5693 Parameter_Associations => New_List (
5694 New_Occurrence_Of (Reference, Loc),
5695 Make_Selected_Component (Loc,
5696 Prefix => Unchecked_Convert_To (Stub_Type_Access,
5697 New_Occurrence_Of (RACW_Parameter, Loc)),
5698 Selector_Name =>
5699 Make_Identifier (Loc, Name_Target)))));
5701 -- Distinguish between the null, local and remote cases,
5702 -- and execute the appropriate piece of code.
5704 If_Node :=
5705 Make_Implicit_If_Statement (RACW_Type,
5706 Condition =>
5707 Make_Op_Eq (Loc,
5708 Left_Opnd => New_Occurrence_Of (RACW_Parameter, Loc),
5709 Right_Opnd => Make_Null (Loc)),
5710 Then_Statements => Null_Statements,
5711 Elsif_Parts => New_List (
5712 Make_Elsif_Part (Loc,
5713 Condition =>
5714 Make_Op_Ne (Loc,
5715 Left_Opnd =>
5716 Make_Attribute_Reference (Loc,
5717 Prefix =>
5718 New_Occurrence_Of (RACW_Parameter, Loc),
5719 Attribute_Name => Name_Tag),
5720 Right_Opnd =>
5721 Make_Attribute_Reference (Loc,
5722 Prefix => New_Occurrence_Of (Stub_Type, Loc),
5723 Attribute_Name => Name_Tag)),
5724 Then_Statements => Local_Statements)),
5725 Else_Statements => Stub_Statements);
5727 Statements := New_List (
5728 If_Node,
5729 Make_Assignment_Statement (Loc,
5730 Name =>
5731 New_Occurrence_Of (Any, Loc),
5732 Expression =>
5733 Make_Function_Call (Loc,
5734 Name => New_Occurrence_Of (RTE (RE_TA_ObjRef), Loc),
5735 Parameter_Associations => New_List (
5736 New_Occurrence_Of (Reference, Loc)))),
5737 Make_Procedure_Call_Statement (Loc,
5738 Name =>
5739 New_Occurrence_Of (RTE (RE_Set_TC), Loc),
5740 Parameter_Associations => New_List (
5741 New_Occurrence_Of (Any, Loc),
5742 Make_Selected_Component (Loc,
5743 Prefix =>
5744 Defining_Identifier (
5745 Stub_Elements.RPC_Receiver_Decl),
5746 Selector_Name => Name_Obj_TypeCode))),
5747 Make_Return_Statement (Loc,
5748 Expression =>
5749 New_Occurrence_Of (Any, Loc)));
5751 Fnam := Make_Defining_Identifier (
5752 Loc, New_Internal_Name ('T'));
5754 Func_Spec :=
5755 Make_Function_Specification (Loc,
5756 Defining_Unit_Name =>
5757 Fnam,
5758 Parameter_Specifications => New_List (
5759 Make_Parameter_Specification (Loc,
5760 Defining_Identifier =>
5761 RACW_Parameter,
5762 Parameter_Type =>
5763 New_Occurrence_Of (RACW_Type, Loc))),
5764 Subtype_Mark => New_Occurrence_Of (RTE (RE_Any), Loc));
5766 -- NOTE: The usage occurrences of RACW_Parameter must
5767 -- refer to the entity in the declaration spec, not in
5768 -- the body spec.
5770 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
5772 Func_Body :=
5773 Make_Subprogram_Body (Loc,
5774 Specification =>
5775 Copy_Specification (Loc, Func_Spec),
5776 Declarations => Decls,
5777 Handled_Statement_Sequence =>
5778 Make_Handled_Sequence_Of_Statements (Loc,
5779 Statements => Statements));
5781 Insert_After (Declaration_Node (RACW_Type), Func_Decl);
5782 Append_To (Declarations, Func_Body);
5784 Set_Renaming_TSS (RACW_Type, Fnam, Name_uTo_Any);
5785 end Add_RACW_To_Any;
5787 -----------------------
5788 -- Add_RACW_TypeCode --
5789 -----------------------
5791 procedure Add_RACW_TypeCode
5792 (Designated_Type : Entity_Id;
5793 RACW_Type : Entity_Id;
5794 Declarations : List_Id)
5796 Loc : constant Source_Ptr := Sloc (RACW_Type);
5798 Fnam : Entity_Id;
5800 Stub_Elements : constant Stub_Structure :=
5801 Stubs_Table.Get (Designated_Type);
5802 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
5804 Func_Spec : Node_Id;
5805 Func_Decl : Node_Id;
5806 Func_Body : Node_Id;
5808 RACW_Parameter : constant Entity_Id :=
5809 Make_Defining_Identifier (Loc, Name_R);
5811 begin
5812 Fnam :=
5813 Make_Defining_Identifier (Loc,
5814 Chars => New_Internal_Name ('T'));
5816 -- The spec for this subprogram has a dummy 'access RACW'
5817 -- argument, which serves only for overloading purposes.
5819 Func_Spec :=
5820 Make_Function_Specification (Loc,
5821 Defining_Unit_Name =>
5822 Fnam,
5823 Parameter_Specifications => New_List (
5824 Make_Parameter_Specification (Loc,
5825 Defining_Identifier =>
5826 RACW_Parameter,
5827 Parameter_Type =>
5828 Make_Access_Definition (Loc,
5829 Subtype_Mark =>
5830 New_Occurrence_Of (RACW_Type, Loc)))),
5831 Subtype_Mark => New_Occurrence_Of (RTE (RE_TypeCode), Loc));
5833 -- NOTE: The usage occurrences of RACW_Parameter must
5834 -- refer to the entity in the declaration spec, not those
5835 -- of the body spec.
5837 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
5839 Func_Body :=
5840 Make_Subprogram_Body (Loc,
5841 Specification =>
5842 Copy_Specification (Loc, Func_Spec),
5843 Declarations => Empty_List,
5844 Handled_Statement_Sequence =>
5845 Make_Handled_Sequence_Of_Statements (Loc,
5846 Statements => New_List (
5847 Make_Return_Statement (Loc,
5848 Expression =>
5849 Make_Selected_Component (Loc,
5850 Prefix =>
5851 Defining_Identifier (
5852 Stub_Elements.RPC_Receiver_Decl),
5853 Selector_Name => Name_Obj_TypeCode)))));
5855 Insert_After (Declaration_Node (RACW_Type), Func_Decl);
5856 Append_To (Declarations, Func_Body);
5858 Set_Renaming_TSS (RACW_Type, Fnam, Name_uTypeCode);
5859 end Add_RACW_TypeCode;
5861 ------------------------------
5862 -- Add_RACW_Write_Attribute --
5863 ------------------------------
5865 procedure Add_RACW_Write_Attribute
5866 (RACW_Type : Entity_Id;
5867 Stub_Type : Entity_Id;
5868 Stub_Type_Access : Entity_Id;
5869 Declarations : List_Id)
5871 Loc : constant Source_Ptr := Sloc (RACW_Type);
5872 pragma Warnings (Off);
5873 pragma Unreferenced (
5874 Stub_Type,
5875 Stub_Type_Access);
5877 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5878 pragma Unreferenced (Is_RAS);
5879 pragma Warnings (On);
5881 Body_Node : Node_Id;
5882 Proc_Decl : Node_Id;
5883 Attr_Decl : Node_Id;
5885 Statements : List_Id;
5886 Procedure_Name : constant Name_Id := New_Internal_Name ('R');
5888 function Stream_Parameter return Node_Id;
5889 function Object return Node_Id;
5890 -- Functions to create occurrences of the formal parameter names
5892 ------------
5893 -- Object --
5894 ------------
5896 function Object return Node_Id is
5897 Object_Ref : constant Node_Id :=
5898 Make_Identifier (Loc, Name_V);
5900 begin
5901 -- Etype must be set for Build_To_Any_Call
5903 Set_Etype (Object_Ref, RACW_Type);
5905 return Object_Ref;
5906 end Object;
5908 ----------------------
5909 -- Stream_Parameter --
5910 ----------------------
5912 function Stream_Parameter return Node_Id is
5913 begin
5914 return Make_Identifier (Loc, Name_S);
5915 end Stream_Parameter;
5917 -- Start of processing for Add_RACW_Write_Attribute
5919 begin
5920 Statements := New_List (
5921 Pack_Node_Into_Stream_Access (Loc,
5922 Stream => Stream_Parameter,
5923 Object =>
5924 Make_Function_Call (Loc,
5925 Name =>
5926 New_Occurrence_Of (RTE (RE_FA_ObjRef), Loc),
5927 Parameter_Associations => New_List (
5928 PolyORB_Support.Helpers.Build_To_Any_Call
5929 (Object, Declarations))),
5930 Etyp => RTE (RE_Object_Ref)));
5932 Build_Stream_Procedure
5933 (Loc, RACW_Type, Body_Node,
5934 Make_Defining_Identifier (Loc, Procedure_Name),
5935 Statements, Outp => False);
5937 Proc_Decl :=
5938 Make_Subprogram_Declaration (Loc,
5939 Copy_Specification (Loc, Specification (Body_Node)));
5941 Attr_Decl :=
5942 Make_Attribute_Definition_Clause (Loc,
5943 Name => New_Occurrence_Of (RACW_Type, Loc),
5944 Chars => Name_Write,
5945 Expression =>
5946 New_Occurrence_Of (
5947 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
5949 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
5950 Insert_After (Proc_Decl, Attr_Decl);
5951 Append_To (Declarations, Body_Node);
5952 end Add_RACW_Write_Attribute;
5954 -----------------------
5955 -- Add_RAST_Features --
5956 -----------------------
5958 procedure Add_RAST_Features
5959 (Vis_Decl : Node_Id;
5960 RAS_Type : Entity_Id;
5961 Decls : List_Id)
5963 begin
5964 Add_RAS_Access_TSS (Vis_Decl);
5966 Add_RAS_From_Any (RAS_Type, Decls);
5967 Add_RAS_TypeCode (RAS_Type, Decls);
5969 -- To_Any uses TypeCode, and therefore needs to be generated last
5971 Add_RAS_To_Any (RAS_Type, Decls);
5972 end Add_RAST_Features;
5974 ------------------------
5975 -- Add_RAS_Access_TSS --
5976 ------------------------
5978 procedure Add_RAS_Access_TSS (N : Node_Id) is
5979 Loc : constant Source_Ptr := Sloc (N);
5981 Ras_Type : constant Entity_Id := Defining_Identifier (N);
5982 Fat_Type : constant Entity_Id := Equivalent_Type (Ras_Type);
5983 -- Ras_Type is the access to subprogram type; Fat_Type is the
5984 -- corresponding record type.
5986 RACW_Type : constant Entity_Id :=
5987 Underlying_RACW_Type (Ras_Type);
5988 Desig : constant Entity_Id :=
5989 Etype (Designated_Type (RACW_Type));
5991 Stub_Elements : constant Stub_Structure :=
5992 Stubs_Table.Get (Desig);
5993 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
5995 Proc : constant Entity_Id :=
5996 Make_Defining_Identifier (Loc,
5997 Chars => Make_TSS_Name (Ras_Type, TSS_RAS_Access));
5999 Proc_Spec : Node_Id;
6001 -- Formal parameters
6003 Package_Name : constant Entity_Id :=
6004 Make_Defining_Identifier (Loc,
6005 Chars => Name_P);
6007 -- Target package
6009 Subp_Id : constant Entity_Id :=
6010 Make_Defining_Identifier (Loc,
6011 Chars => Name_S);
6013 -- Target subprogram
6015 Asynch_P : constant Entity_Id :=
6016 Make_Defining_Identifier (Loc,
6017 Chars => Name_Asynchronous);
6018 -- Is the procedure to which the 'Access applies asynchronous?
6020 All_Calls_Remote : constant Entity_Id :=
6021 Make_Defining_Identifier (Loc,
6022 Chars => Name_All_Calls_Remote);
6023 -- True if an All_Calls_Remote pragma applies to the RCI unit
6024 -- that contains the subprogram.
6026 -- Common local variables
6028 Proc_Decls : List_Id;
6029 Proc_Statements : List_Id;
6031 Subp_Ref : constant Entity_Id :=
6032 Make_Defining_Identifier (Loc, Name_R);
6033 -- Reference that designates the target subprogram (returned
6034 -- by Get_RAS_Info).
6036 Is_Local : constant Entity_Id :=
6037 Make_Defining_Identifier (Loc, Name_L);
6038 Local_Addr : constant Entity_Id :=
6039 Make_Defining_Identifier (Loc, Name_A);
6040 -- For the call to Get_Local_Address
6042 -- Additional local variables for the remote case
6044 Local_Stub : constant Entity_Id :=
6045 Make_Defining_Identifier (Loc,
6046 Chars => New_Internal_Name ('L'));
6048 Stub_Ptr : constant Entity_Id :=
6049 Make_Defining_Identifier (Loc,
6050 Chars => New_Internal_Name ('S'));
6052 function Set_Field
6053 (Field_Name : Name_Id;
6054 Value : Node_Id) return Node_Id;
6055 -- Construct an assignment that sets the named component in the
6056 -- returned record
6058 ---------------
6059 -- Set_Field --
6060 ---------------
6062 function Set_Field
6063 (Field_Name : Name_Id;
6064 Value : Node_Id) return Node_Id
6066 begin
6067 return
6068 Make_Assignment_Statement (Loc,
6069 Name =>
6070 Make_Selected_Component (Loc,
6071 Prefix => Stub_Ptr,
6072 Selector_Name => Field_Name),
6073 Expression => Value);
6074 end Set_Field;
6076 -- Start of processing for Add_RAS_Access_TSS
6078 begin
6079 Proc_Decls := New_List (
6081 -- Common declarations
6083 Make_Object_Declaration (Loc,
6084 Defining_Identifier => Subp_Ref,
6085 Object_Definition =>
6086 New_Occurrence_Of (RTE (RE_Object_Ref), Loc)),
6088 Make_Object_Declaration (Loc,
6089 Defining_Identifier => Is_Local,
6090 Object_Definition =>
6091 New_Occurrence_Of (Standard_Boolean, Loc)),
6093 Make_Object_Declaration (Loc,
6094 Defining_Identifier => Local_Addr,
6095 Object_Definition =>
6096 New_Occurrence_Of (RTE (RE_Address), Loc)),
6098 Make_Object_Declaration (Loc,
6099 Defining_Identifier => Local_Stub,
6100 Aliased_Present => True,
6101 Object_Definition =>
6102 New_Occurrence_Of (Stub_Elements.Stub_Type, Loc)),
6104 Make_Object_Declaration (Loc,
6105 Defining_Identifier =>
6106 Stub_Ptr,
6107 Object_Definition =>
6108 New_Occurrence_Of (Stub_Elements.Stub_Type_Access, Loc),
6109 Expression =>
6110 Make_Attribute_Reference (Loc,
6111 Prefix => New_Occurrence_Of (Local_Stub, Loc),
6112 Attribute_Name => Name_Unchecked_Access)));
6114 Set_Etype (Stub_Ptr, Stub_Elements.Stub_Type_Access);
6115 -- Build_Get_Unique_RP_Call needs this information
6117 -- Get_RAS_Info (Pkg, Subp, R);
6118 -- Obtain a reference to the target subprogram
6120 Proc_Statements := New_List (
6121 Make_Procedure_Call_Statement (Loc,
6122 Name =>
6123 New_Occurrence_Of (RTE (RE_Get_RAS_Info), Loc),
6124 Parameter_Associations => New_List (
6125 New_Occurrence_Of (Package_Name, Loc),
6126 New_Occurrence_Of (Subp_Id, Loc),
6127 New_Occurrence_Of (Subp_Ref, Loc))),
6129 -- Get_Local_Address (R, L, A);
6130 -- Determine whether the subprogram is local (L), and if so
6131 -- obtain the local address of its proxy (A).
6133 Make_Procedure_Call_Statement (Loc,
6134 Name =>
6135 New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
6136 Parameter_Associations => New_List (
6137 New_Occurrence_Of (Subp_Ref, Loc),
6138 New_Occurrence_Of (Is_Local, Loc),
6139 New_Occurrence_Of (Local_Addr, Loc))));
6141 -- Note: Here we assume that the Fat_Type is a record containing just
6142 -- an access to a proxy or stub object.
6144 Append_To (Proc_Statements,
6146 -- if L then
6148 Make_Implicit_If_Statement (N,
6149 Condition =>
6150 New_Occurrence_Of (Is_Local, Loc),
6152 Then_Statements => New_List (
6154 -- if A.Target = null then
6156 Make_Implicit_If_Statement (N,
6157 Condition =>
6158 Make_Op_Eq (Loc,
6159 Make_Selected_Component (Loc,
6160 Prefix =>
6161 Unchecked_Convert_To (
6162 RTE (RE_RAS_Proxy_Type_Access),
6163 New_Occurrence_Of (Local_Addr, Loc)),
6164 Selector_Name =>
6165 Make_Identifier (Loc, Name_Target)),
6166 Make_Null (Loc)),
6168 Then_Statements => New_List (
6170 -- A.Target := Entity_Of (Ref);
6172 Make_Assignment_Statement (Loc,
6173 Name =>
6174 Make_Selected_Component (Loc,
6175 Prefix =>
6176 Unchecked_Convert_To (
6177 RTE (RE_RAS_Proxy_Type_Access),
6178 New_Occurrence_Of (Local_Addr, Loc)),
6179 Selector_Name =>
6180 Make_Identifier (Loc, Name_Target)),
6181 Expression =>
6182 Make_Function_Call (Loc,
6183 Name =>
6184 New_Occurrence_Of (RTE (RE_Entity_Of), Loc),
6185 Parameter_Associations => New_List (
6186 New_Occurrence_Of (Subp_Ref, Loc)))),
6188 -- Inc_Usage (A.Target);
6190 Make_Procedure_Call_Statement (Loc,
6191 Name =>
6192 New_Occurrence_Of (RTE (RE_Inc_Usage), Loc),
6193 Parameter_Associations => New_List (
6194 Make_Selected_Component (Loc,
6195 Prefix =>
6196 Unchecked_Convert_To (
6197 RTE (RE_RAS_Proxy_Type_Access),
6198 New_Occurrence_Of (Local_Addr, Loc)),
6199 Selector_Name => Make_Identifier (Loc,
6200 Name_Target)))))),
6202 -- end if;
6203 -- if not All_Calls_Remote then
6204 -- return Fat_Type!(A);
6205 -- end if;
6207 Make_Implicit_If_Statement (N,
6208 Condition =>
6209 Make_Op_Not (Loc,
6210 New_Occurrence_Of (All_Calls_Remote, Loc)),
6212 Then_Statements => New_List (
6213 Make_Return_Statement (Loc,
6214 Unchecked_Convert_To (Fat_Type,
6215 New_Occurrence_Of (Local_Addr, Loc))))))));
6217 Append_List_To (Proc_Statements, New_List (
6219 -- Stub.Target := Entity_Of (Ref);
6221 Set_Field (Name_Target,
6222 Make_Function_Call (Loc,
6223 Name =>
6224 New_Occurrence_Of (RTE (RE_Entity_Of), Loc),
6225 Parameter_Associations => New_List (
6226 New_Occurrence_Of (Subp_Ref, Loc)))),
6228 -- Inc_Usage (Stub.Target);
6230 Make_Procedure_Call_Statement (Loc,
6231 Name =>
6232 New_Occurrence_Of (RTE (RE_Inc_Usage), Loc),
6233 Parameter_Associations => New_List (
6234 Make_Selected_Component (Loc,
6235 Prefix => Stub_Ptr,
6236 Selector_Name => Name_Target))),
6238 -- E.4.1(9) A remote call is asynchronous if it is a call to
6239 -- a procedure, or a call through a value of an access-to-procedure
6240 -- type, to which a pragma Asynchronous applies.
6242 -- Parameter Asynch_P is true when the procedure is asynchronous;
6243 -- Expression Asynch_T is true when the type is asynchronous.
6245 Set_Field (Name_Asynchronous,
6246 Make_Or_Else (Loc,
6247 New_Occurrence_Of (Asynch_P, Loc),
6248 New_Occurrence_Of (Boolean_Literals (
6249 Is_Asynchronous (Ras_Type)), Loc)))));
6251 Append_List_To (Proc_Statements,
6252 Build_Get_Unique_RP_Call (Loc,
6253 Stub_Ptr, Stub_Elements.Stub_Type));
6255 Append_To (Proc_Statements,
6256 Make_Return_Statement (Loc,
6257 Expression =>
6258 Unchecked_Convert_To (Fat_Type,
6259 New_Occurrence_Of (Stub_Ptr, Loc))));
6261 Proc_Spec :=
6262 Make_Function_Specification (Loc,
6263 Defining_Unit_Name => Proc,
6264 Parameter_Specifications => New_List (
6265 Make_Parameter_Specification (Loc,
6266 Defining_Identifier => Package_Name,
6267 Parameter_Type =>
6268 New_Occurrence_Of (Standard_String, Loc)),
6270 Make_Parameter_Specification (Loc,
6271 Defining_Identifier => Subp_Id,
6272 Parameter_Type =>
6273 New_Occurrence_Of (Standard_String, Loc)),
6275 Make_Parameter_Specification (Loc,
6276 Defining_Identifier => Asynch_P,
6277 Parameter_Type =>
6278 New_Occurrence_Of (Standard_Boolean, Loc)),
6280 Make_Parameter_Specification (Loc,
6281 Defining_Identifier => All_Calls_Remote,
6282 Parameter_Type =>
6283 New_Occurrence_Of (Standard_Boolean, Loc))),
6285 Subtype_Mark =>
6286 New_Occurrence_Of (Fat_Type, Loc));
6288 -- Set the kind and return type of the function to prevent
6289 -- ambiguities between Ras_Type and Fat_Type in subsequent analysis.
6291 Set_Ekind (Proc, E_Function);
6292 Set_Etype (Proc, Fat_Type);
6294 Discard_Node (
6295 Make_Subprogram_Body (Loc,
6296 Specification => Proc_Spec,
6297 Declarations => Proc_Decls,
6298 Handled_Statement_Sequence =>
6299 Make_Handled_Sequence_Of_Statements (Loc,
6300 Statements => Proc_Statements)));
6302 Set_TSS (Fat_Type, Proc);
6303 end Add_RAS_Access_TSS;
6305 ----------------------
6306 -- Add_RAS_From_Any --
6307 ----------------------
6309 procedure Add_RAS_From_Any
6310 (RAS_Type : Entity_Id;
6311 Declarations : List_Id)
6313 Loc : constant Source_Ptr := Sloc (RAS_Type);
6315 Fnam : constant Entity_Id :=
6316 Make_Defining_Identifier (Loc, New_Internal_Name ('F'));
6318 Func_Spec : Node_Id;
6319 Func_Decl : Node_Id;
6320 Func_Body : Node_Id;
6322 Statements : List_Id;
6324 Any_Parameter : constant Entity_Id :=
6325 Make_Defining_Identifier (Loc, Name_A);
6327 begin
6328 Statements := New_List (
6329 Make_Return_Statement (Loc,
6330 Expression =>
6331 Make_Aggregate (Loc,
6332 Component_Associations => New_List (
6333 Make_Component_Association (Loc,
6334 Choices => New_List (
6335 Make_Identifier (Loc, Name_Ras)),
6336 Expression =>
6337 PolyORB_Support.Helpers.Build_From_Any_Call (
6338 Underlying_RACW_Type (RAS_Type),
6339 New_Occurrence_Of (Any_Parameter, Loc),
6340 No_List))))));
6342 Func_Spec :=
6343 Make_Function_Specification (Loc,
6344 Defining_Unit_Name =>
6345 Fnam,
6346 Parameter_Specifications => New_List (
6347 Make_Parameter_Specification (Loc,
6348 Defining_Identifier =>
6349 Any_Parameter,
6350 Parameter_Type =>
6351 New_Occurrence_Of (RTE (RE_Any), Loc))),
6352 Subtype_Mark => New_Occurrence_Of (RAS_Type, Loc));
6354 -- NOTE: The usage occurrences of RACW_Parameter must
6355 -- refer to the entity in the declaration spec, not those
6356 -- of the body spec.
6358 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
6360 Func_Body :=
6361 Make_Subprogram_Body (Loc,
6362 Specification =>
6363 Copy_Specification (Loc, Func_Spec),
6364 Declarations => No_List,
6365 Handled_Statement_Sequence =>
6366 Make_Handled_Sequence_Of_Statements (Loc,
6367 Statements => Statements));
6369 Insert_After (Declaration_Node (RAS_Type), Func_Decl);
6370 Append_To (Declarations, Func_Body);
6372 Set_Renaming_TSS (RAS_Type, Fnam, Name_uFrom_Any);
6373 end Add_RAS_From_Any;
6375 --------------------
6376 -- Add_RAS_To_Any --
6377 --------------------
6379 procedure Add_RAS_To_Any
6380 (RAS_Type : Entity_Id;
6381 Declarations : List_Id)
6383 Loc : constant Source_Ptr := Sloc (RAS_Type);
6385 Fnam : Entity_Id;
6387 Decls : List_Id;
6388 Statements : List_Id;
6390 Func_Spec : Node_Id;
6391 Func_Decl : Node_Id;
6392 Func_Body : Node_Id;
6394 Any : constant Entity_Id :=
6395 Make_Defining_Identifier (Loc,
6396 Chars => New_Internal_Name ('A'));
6397 RAS_Parameter : constant Entity_Id :=
6398 Make_Defining_Identifier (Loc,
6399 Chars => New_Internal_Name ('R'));
6400 RACW_Parameter : constant Node_Id :=
6401 Make_Selected_Component (Loc,
6402 Prefix => RAS_Parameter,
6403 Selector_Name => Name_Ras);
6405 begin
6406 -- Object declarations
6408 Set_Etype (RACW_Parameter, Underlying_RACW_Type (RAS_Type));
6409 Decls := New_List (
6410 Make_Object_Declaration (Loc,
6411 Defining_Identifier =>
6412 Any,
6413 Object_Definition =>
6414 New_Occurrence_Of (RTE (RE_Any), Loc),
6415 Expression =>
6416 PolyORB_Support.Helpers.Build_To_Any_Call
6417 (RACW_Parameter, No_List)));
6419 Statements := New_List (
6420 Make_Procedure_Call_Statement (Loc,
6421 Name =>
6422 New_Occurrence_Of (RTE (RE_Set_TC), Loc),
6423 Parameter_Associations => New_List (
6424 New_Occurrence_Of (Any, Loc),
6425 PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
6426 RAS_Type, Decls))),
6427 Make_Return_Statement (Loc,
6428 Expression =>
6429 New_Occurrence_Of (Any, Loc)));
6431 Fnam := Make_Defining_Identifier (
6432 Loc, New_Internal_Name ('T'));
6434 Func_Spec :=
6435 Make_Function_Specification (Loc,
6436 Defining_Unit_Name =>
6437 Fnam,
6438 Parameter_Specifications => New_List (
6439 Make_Parameter_Specification (Loc,
6440 Defining_Identifier =>
6441 RAS_Parameter,
6442 Parameter_Type =>
6443 New_Occurrence_Of (RAS_Type, Loc))),
6444 Subtype_Mark => New_Occurrence_Of (RTE (RE_Any), Loc));
6446 -- NOTE: The usage occurrences of RAS_Parameter must
6447 -- refer to the entity in the declaration spec, not in
6448 -- the body spec.
6450 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
6452 Func_Body :=
6453 Make_Subprogram_Body (Loc,
6454 Specification =>
6455 Copy_Specification (Loc, Func_Spec),
6456 Declarations => Decls,
6457 Handled_Statement_Sequence =>
6458 Make_Handled_Sequence_Of_Statements (Loc,
6459 Statements => Statements));
6461 Insert_After (Declaration_Node (RAS_Type), Func_Decl);
6462 Append_To (Declarations, Func_Body);
6464 Set_Renaming_TSS (RAS_Type, Fnam, Name_uTo_Any);
6465 end Add_RAS_To_Any;
6467 ----------------------
6468 -- Add_RAS_TypeCode --
6469 ----------------------
6471 procedure Add_RAS_TypeCode
6472 (RAS_Type : Entity_Id;
6473 Declarations : List_Id)
6475 Loc : constant Source_Ptr := Sloc (RAS_Type);
6477 Fnam : Entity_Id;
6479 Func_Spec : Node_Id;
6480 Func_Decl : Node_Id;
6481 Func_Body : Node_Id;
6483 Decls : constant List_Id := New_List;
6484 Name_String, Repo_Id_String : String_Id;
6486 RAS_Parameter : constant Entity_Id :=
6487 Make_Defining_Identifier (Loc, Name_R);
6489 begin
6491 Fnam :=
6492 Make_Defining_Identifier (Loc,
6493 Chars => New_Internal_Name ('T'));
6495 -- The spec for this subprogram has a dummy 'access RAS'
6496 -- argument, which serves only for overloading purposes.
6498 Func_Spec :=
6499 Make_Function_Specification (Loc,
6500 Defining_Unit_Name =>
6501 Fnam,
6502 Parameter_Specifications => New_List (
6503 Make_Parameter_Specification (Loc,
6504 Defining_Identifier =>
6505 RAS_Parameter,
6506 Parameter_Type =>
6507 Make_Access_Definition (Loc,
6508 Subtype_Mark => New_Occurrence_Of (RAS_Type, Loc)))),
6509 Subtype_Mark => New_Occurrence_Of (RTE (RE_TypeCode), Loc));
6511 -- NOTE: The usage occurrences of RAS_Parameter must
6512 -- refer to the entity in the declaration spec, not those
6513 -- of the body spec.
6515 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
6517 PolyORB_Support.Helpers.Build_Name_And_Repository_Id
6518 (RAS_Type, Name_Str => Name_String, Repo_Id_Str => Repo_Id_String);
6520 Func_Body :=
6521 Make_Subprogram_Body (Loc,
6522 Specification =>
6523 Copy_Specification (Loc, Func_Spec),
6524 Declarations => Decls,
6525 Handled_Statement_Sequence =>
6526 Make_Handled_Sequence_Of_Statements (Loc,
6527 Statements => New_List (
6528 Make_Return_Statement (Loc,
6529 Expression =>
6530 Make_Function_Call (Loc,
6531 Name =>
6532 New_Occurrence_Of (RTE (RE_TC_Build), Loc),
6533 Parameter_Associations => New_List (
6534 New_Occurrence_Of (RTE (RE_TC_Object), Loc),
6535 Make_Aggregate (Loc,
6536 Expressions =>
6537 New_List (
6538 Make_Function_Call (Loc,
6539 Name => New_Occurrence_Of (
6540 RTE (RE_TA_String), Loc),
6541 Parameter_Associations => New_List (
6542 Make_String_Literal (Loc, Name_String))),
6543 Make_Function_Call (Loc,
6544 Name => New_Occurrence_Of (
6545 RTE (RE_TA_String), Loc),
6546 Parameter_Associations => New_List (
6547 Make_String_Literal (Loc,
6548 Repo_Id_String)))))))))));
6550 Insert_After (Declaration_Node (RAS_Type), Func_Decl);
6551 Append_To (Declarations, Func_Body);
6553 Set_Renaming_TSS (RAS_Type, Fnam, Name_uTypeCode);
6554 end Add_RAS_TypeCode;
6556 -----------------------------------------
6557 -- Add_Receiving_Stubs_To_Declarations --
6558 -----------------------------------------
6560 procedure Add_Receiving_Stubs_To_Declarations
6561 (Pkg_Spec : Node_Id;
6562 Decls : List_Id)
6564 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
6566 Pkg_RPC_Receiver : constant Entity_Id :=
6567 Make_Defining_Identifier (Loc,
6568 New_Internal_Name ('H'));
6569 Pkg_RPC_Receiver_Object : Node_Id;
6571 Pkg_RPC_Receiver_Body : Node_Id;
6572 Pkg_RPC_Receiver_Decls : List_Id;
6573 Pkg_RPC_Receiver_Statements : List_Id;
6574 Pkg_RPC_Receiver_Cases : constant List_Id := New_List;
6575 -- A Pkg_RPC_Receiver is built to decode the request
6577 Request : Node_Id;
6578 -- Request object received from neutral layer
6580 Subp_Id : Entity_Id;
6581 -- Subprogram identifier as received from the neutral
6582 -- distribution core.
6584 Subp_Index : Entity_Id;
6585 -- Internal index as determined by matching either the
6586 -- method name from the request structure, or the local
6587 -- subprogram address (in case of a RAS).
6589 Is_Local : constant Entity_Id :=
6590 Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
6591 Local_Address : constant Entity_Id :=
6592 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6593 -- Address of a local subprogram designated by a
6594 -- reference corresponding to a RAS.
6596 Dispatch_On_Address : constant List_Id := New_List;
6597 Dispatch_On_Name : constant List_Id := New_List;
6599 Current_Declaration : Node_Id;
6600 Current_Stubs : Node_Id;
6601 Current_Subprogram_Number : Int := First_RCI_Subprogram_Id;
6603 Subp_Info_Array : constant Entity_Id :=
6604 Make_Defining_Identifier (Loc,
6605 Chars => New_Internal_Name ('I'));
6607 Subp_Info_List : constant List_Id := New_List;
6609 Register_Pkg_Actuals : constant List_Id := New_List;
6611 All_Calls_Remote_E : Entity_Id;
6613 procedure Append_Stubs_To
6614 (RPC_Receiver_Cases : List_Id;
6615 Declaration : Node_Id;
6616 Stubs : Node_Id;
6617 Subp_Number : Int;
6618 Subp_Dist_Name : Entity_Id;
6619 Subp_Proxy_Addr : Entity_Id);
6620 -- Add one case to the specified RPC receiver case list associating
6621 -- Subprogram_Number with the subprogram declared by Declaration, for
6622 -- which we have receiving stubs in Stubs. Subp_Number is an internal
6623 -- subprogram index. Subp_Dist_Name is the string used to call the
6624 -- subprogram by name, and Subp_Dist_Addr is the address of the proxy
6625 -- object, used in the context of calls through remote
6626 -- access-to-subprogram types.
6628 ---------------------
6629 -- Append_Stubs_To --
6630 ---------------------
6632 procedure Append_Stubs_To
6633 (RPC_Receiver_Cases : List_Id;
6634 Declaration : Node_Id;
6635 Stubs : Node_Id;
6636 Subp_Number : Int;
6637 Subp_Dist_Name : Entity_Id;
6638 Subp_Proxy_Addr : Entity_Id)
6640 Case_Stmts : List_Id;
6641 begin
6642 Case_Stmts := New_List (
6643 Make_Procedure_Call_Statement (Loc,
6644 Name =>
6645 New_Occurrence_Of (
6646 Defining_Entity (Stubs), Loc),
6647 Parameter_Associations =>
6648 New_List (New_Occurrence_Of (Request, Loc))));
6649 if Nkind (Specification (Declaration))
6650 = N_Function_Specification
6651 or else not
6652 Is_Asynchronous (Defining_Entity (Specification (Declaration)))
6653 then
6654 Append_To (Case_Stmts, Make_Return_Statement (Loc));
6655 end if;
6657 Append_To (RPC_Receiver_Cases,
6658 Make_Case_Statement_Alternative (Loc,
6659 Discrete_Choices =>
6660 New_List (Make_Integer_Literal (Loc, Subp_Number)),
6661 Statements =>
6662 Case_Stmts));
6664 Append_To (Dispatch_On_Name,
6665 Make_Elsif_Part (Loc,
6666 Condition =>
6667 Make_Function_Call (Loc,
6668 Name =>
6669 New_Occurrence_Of (RTE (RE_Caseless_String_Eq), Loc),
6670 Parameter_Associations => New_List (
6671 New_Occurrence_Of (Subp_Id, Loc),
6672 New_Occurrence_Of (Subp_Dist_Name, Loc))),
6673 Then_Statements => New_List (
6674 Make_Assignment_Statement (Loc,
6675 New_Occurrence_Of (Subp_Index, Loc),
6676 Make_Integer_Literal (Loc,
6677 Subp_Number)))));
6679 Append_To (Dispatch_On_Address,
6680 Make_Elsif_Part (Loc,
6681 Condition =>
6682 Make_Op_Eq (Loc,
6683 Left_Opnd =>
6684 New_Occurrence_Of (Local_Address, Loc),
6685 Right_Opnd =>
6686 New_Occurrence_Of (Subp_Proxy_Addr, Loc)),
6687 Then_Statements => New_List (
6688 Make_Assignment_Statement (Loc,
6689 New_Occurrence_Of (Subp_Index, Loc),
6690 Make_Integer_Literal (Loc,
6691 Subp_Number)))));
6692 end Append_Stubs_To;
6694 -- Start of processing for Add_Receiving_Stubs_To_Declarations
6696 begin
6697 -- Building receiving stubs consist in several operations:
6699 -- - a package RPC receiver must be built. This subprogram
6700 -- will get a Subprogram_Id from the incoming stream
6701 -- and will dispatch the call to the right subprogram
6703 -- - a receiving stub for any subprogram visible in the package
6704 -- spec. This stub will read all the parameters from the stream,
6705 -- and put the result as well as the exception occurrence in the
6706 -- output stream
6708 -- - a dummy package with an empty spec and a body made of an
6709 -- elaboration part, whose job is to register the receiving
6710 -- part of this RCI package on the name server. This is done
6711 -- by calling System.Partition_Interface.Register_Receiving_Stub
6713 Build_RPC_Receiver_Body (
6714 RPC_Receiver => Pkg_RPC_Receiver,
6715 Request => Request,
6716 Subp_Id => Subp_Id,
6717 Subp_Index => Subp_Index,
6718 Stmts => Pkg_RPC_Receiver_Statements,
6719 Decl => Pkg_RPC_Receiver_Body);
6720 Pkg_RPC_Receiver_Decls := Declarations (Pkg_RPC_Receiver_Body);
6722 -- Extract local address information from the target reference:
6723 -- if non-null, that means that this is a reference that denotes
6724 -- one particular operation, and hence that the operation name
6725 -- must not be taken into account for dispatching.
6727 Append_To (Pkg_RPC_Receiver_Decls,
6728 Make_Object_Declaration (Loc,
6729 Defining_Identifier =>
6730 Is_Local,
6731 Object_Definition =>
6732 New_Occurrence_Of (Standard_Boolean, Loc)));
6733 Append_To (Pkg_RPC_Receiver_Decls,
6734 Make_Object_Declaration (Loc,
6735 Defining_Identifier =>
6736 Local_Address,
6737 Object_Definition =>
6738 New_Occurrence_Of (RTE (RE_Address), Loc)));
6739 Append_To (Pkg_RPC_Receiver_Statements,
6740 Make_Procedure_Call_Statement (Loc,
6741 Name =>
6742 New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
6743 Parameter_Associations => New_List (
6744 Make_Selected_Component (Loc,
6745 Prefix => Request,
6746 Selector_Name => Name_Target),
6747 New_Occurrence_Of (Is_Local, Loc),
6748 New_Occurrence_Of (Local_Address, Loc))));
6750 -- Determine whether the reference that was used to make
6751 -- the call was the base RCI reference (in which case
6752 -- Local_Address is 0, and the method identifier from the
6753 -- request must be used to determine which subprogram is
6754 -- called) or a reference identifying one particular subprogram
6755 -- (in which case Local_Address is the address of that
6756 -- subprogram, and the method name from the request is
6757 -- ignored).
6758 -- In each case, cascaded elsifs are used to determine the
6759 -- proper subprogram index. Using hash tables might be
6760 -- more efficient.
6762 Append_To (Pkg_RPC_Receiver_Statements,
6763 Make_Implicit_If_Statement (Pkg_Spec,
6764 Condition =>
6765 Make_Op_Ne (Loc,
6766 Left_Opnd => New_Occurrence_Of (Local_Address, Loc),
6767 Right_Opnd => New_Occurrence_Of (RTE (RE_Null_Address), Loc)),
6768 Then_Statements => New_List (
6769 Make_Implicit_If_Statement (Pkg_Spec,
6770 Condition =>
6771 New_Occurrence_Of (Standard_False, Loc),
6772 Then_Statements => New_List (
6773 Make_Null_Statement (Loc)),
6774 Elsif_Parts =>
6775 Dispatch_On_Address)),
6776 Else_Statements => New_List (
6777 Make_Implicit_If_Statement (Pkg_Spec,
6778 Condition =>
6779 New_Occurrence_Of (Standard_False, Loc),
6780 Then_Statements => New_List (
6781 Make_Null_Statement (Loc)),
6782 Elsif_Parts =>
6783 Dispatch_On_Name))));
6785 -- For each subprogram, the receiving stub will be built and a
6786 -- case statement will be made on the Subprogram_Id to dispatch
6787 -- to the right subprogram.
6789 All_Calls_Remote_E := Boolean_Literals (
6790 Has_All_Calls_Remote (Defining_Entity (Pkg_Spec)));
6792 Overload_Counter_Table.Reset;
6793 Reserve_NamingContext_Methods;
6795 Current_Declaration := First (Visible_Declarations (Pkg_Spec));
6796 while Present (Current_Declaration) loop
6797 if Nkind (Current_Declaration) = N_Subprogram_Declaration
6798 and then Comes_From_Source (Current_Declaration)
6799 then
6800 declare
6801 Loc : constant Source_Ptr :=
6802 Sloc (Current_Declaration);
6803 -- While specifically processing Current_Declaration, use
6804 -- its Sloc as the location of all generated nodes.
6806 Subp_Def : constant Entity_Id :=
6807 Defining_Unit_Name
6808 (Specification (Current_Declaration));
6810 Subp_Val : String_Id;
6812 Subp_Dist_Name : constant Entity_Id :=
6813 Make_Defining_Identifier (Loc,
6814 New_External_Name (
6815 Related_Id => Chars (Subp_Def),
6816 Suffix => 'D',
6817 Suffix_Index => -1));
6819 Proxy_Object_Addr : Entity_Id;
6821 begin
6822 pragma Assert (Current_Subprogram_Number =
6823 Get_Subprogram_Id (Subp_Def));
6825 -- Build receiving stub
6827 Current_Stubs :=
6828 Build_Subprogram_Receiving_Stubs
6829 (Vis_Decl => Current_Declaration,
6830 Asynchronous =>
6831 Nkind (Specification (Current_Declaration)) =
6832 N_Procedure_Specification
6833 and then Is_Asynchronous (Subp_Def));
6835 Append_To (Decls, Current_Stubs);
6836 Analyze (Current_Stubs);
6838 -- Build RAS proxy
6840 Add_RAS_Proxy_And_Analyze (Decls,
6841 Vis_Decl =>
6842 Current_Declaration,
6843 All_Calls_Remote_E =>
6844 All_Calls_Remote_E,
6845 Proxy_Object_Addr =>
6846 Proxy_Object_Addr);
6848 -- Compute distribution identifier
6850 Assign_Subprogram_Identifier (
6851 Subp_Def,
6852 Current_Subprogram_Number,
6853 Subp_Val);
6855 Append_To (Decls,
6856 Make_Object_Declaration (Loc,
6857 Defining_Identifier => Subp_Dist_Name,
6858 Constant_Present => True,
6859 Object_Definition => New_Occurrence_Of (
6860 Standard_String, Loc),
6861 Expression =>
6862 Make_String_Literal (Loc, Subp_Val)));
6863 Analyze (Last (Decls));
6865 -- Add subprogram descriptor (RCI_Subp_Info) to the
6866 -- subprograms table for this receiver. The aggregate
6867 -- below must be kept consistent with the declaration
6868 -- of type RCI_Subp_Info in System.Partition_Interface.
6870 Append_To (Subp_Info_List,
6871 Make_Component_Association (Loc,
6872 Choices => New_List (
6873 Make_Integer_Literal (Loc,
6874 Current_Subprogram_Number)),
6875 Expression =>
6876 Make_Aggregate (Loc,
6877 Expressions => New_List (
6878 Make_Attribute_Reference (Loc,
6879 Prefix =>
6880 New_Occurrence_Of (
6881 Subp_Dist_Name, Loc),
6882 Attribute_Name => Name_Address),
6883 Make_Attribute_Reference (Loc,
6884 Prefix =>
6885 New_Occurrence_Of (
6886 Subp_Dist_Name, Loc),
6887 Attribute_Name => Name_Length),
6888 New_Occurrence_Of (Proxy_Object_Addr, Loc)))));
6890 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
6891 Declaration => Current_Declaration,
6892 Stubs => Current_Stubs,
6893 Subp_Number => Current_Subprogram_Number,
6894 Subp_Dist_Name => Subp_Dist_Name,
6895 Subp_Proxy_Addr => Proxy_Object_Addr);
6896 end;
6898 Current_Subprogram_Number := Current_Subprogram_Number + 1;
6899 end if;
6901 Next (Current_Declaration);
6902 end loop;
6904 -- If we receive an invalid Subprogram_Id, it is best to do nothing
6905 -- rather than raising an exception since we do not want someone
6906 -- to crash a remote partition by sending invalid subprogram ids.
6907 -- This is consistent with the other parts of the case statement
6908 -- since even in presence of incorrect parameters in the stream,
6909 -- every exception will be caught and (if the subprogram is not an
6910 -- APC) put into the result stream and sent away.
6912 Append_To (Pkg_RPC_Receiver_Cases,
6913 Make_Case_Statement_Alternative (Loc,
6914 Discrete_Choices =>
6915 New_List (Make_Others_Choice (Loc)),
6916 Statements =>
6917 New_List (Make_Null_Statement (Loc))));
6919 Append_To (Pkg_RPC_Receiver_Statements,
6920 Make_Case_Statement (Loc,
6921 Expression =>
6922 New_Occurrence_Of (Subp_Index, Loc),
6923 Alternatives => Pkg_RPC_Receiver_Cases));
6925 Append_To (Decls,
6926 Make_Object_Declaration (Loc,
6927 Defining_Identifier => Subp_Info_Array,
6928 Constant_Present => True,
6929 Aliased_Present => True,
6930 Object_Definition =>
6931 Make_Subtype_Indication (Loc,
6932 Subtype_Mark =>
6933 New_Occurrence_Of (RTE (RE_RCI_Subp_Info_Array), Loc),
6934 Constraint =>
6935 Make_Index_Or_Discriminant_Constraint (Loc,
6936 New_List (
6937 Make_Range (Loc,
6938 Low_Bound => Make_Integer_Literal (Loc,
6939 First_RCI_Subprogram_Id),
6940 High_Bound =>
6941 Make_Integer_Literal (Loc,
6942 First_RCI_Subprogram_Id
6943 + List_Length (Subp_Info_List) - 1))))),
6944 Expression =>
6945 Make_Aggregate (Loc,
6946 Component_Associations => Subp_Info_List)));
6947 Analyze (Last (Decls));
6949 Append_To (Decls, Pkg_RPC_Receiver_Body);
6950 Analyze (Last (Decls));
6952 Pkg_RPC_Receiver_Object :=
6953 Make_Object_Declaration (Loc,
6954 Defining_Identifier =>
6955 Make_Defining_Identifier (Loc, New_Internal_Name ('R')),
6956 Aliased_Present => True,
6957 Object_Definition =>
6958 New_Occurrence_Of (RTE (RE_Servant), Loc));
6959 Append_To (Decls, Pkg_RPC_Receiver_Object);
6960 Analyze (Last (Decls));
6962 Get_Library_Unit_Name_String (Pkg_Spec);
6963 Append_To (Register_Pkg_Actuals,
6964 -- Name
6965 Make_String_Literal (Loc,
6966 Strval => String_From_Name_Buffer));
6968 Append_To (Register_Pkg_Actuals,
6969 -- Version
6970 Make_Attribute_Reference (Loc,
6971 Prefix =>
6972 New_Occurrence_Of
6973 (Defining_Entity (Pkg_Spec), Loc),
6974 Attribute_Name =>
6975 Name_Version));
6977 Append_To (Register_Pkg_Actuals,
6978 -- Handler
6979 Make_Attribute_Reference (Loc,
6980 Prefix =>
6981 New_Occurrence_Of (Pkg_RPC_Receiver, Loc),
6982 Attribute_Name => Name_Access));
6984 Append_To (Register_Pkg_Actuals,
6985 -- Receiver
6986 Make_Attribute_Reference (Loc,
6987 Prefix =>
6988 New_Occurrence_Of (
6989 Defining_Identifier (
6990 Pkg_RPC_Receiver_Object), Loc),
6991 Attribute_Name =>
6992 Name_Access));
6994 Append_To (Register_Pkg_Actuals,
6995 -- Subp_Info
6996 Make_Attribute_Reference (Loc,
6997 Prefix =>
6998 New_Occurrence_Of (Subp_Info_Array, Loc),
6999 Attribute_Name =>
7000 Name_Address));
7002 Append_To (Register_Pkg_Actuals,
7003 -- Subp_Info_Len
7004 Make_Attribute_Reference (Loc,
7005 Prefix =>
7006 New_Occurrence_Of (Subp_Info_Array, Loc),
7007 Attribute_Name =>
7008 Name_Length));
7010 Append_To (Register_Pkg_Actuals,
7011 -- Is_All_Calls_Remote
7012 New_Occurrence_Of (All_Calls_Remote_E, Loc));
7014 Append_To (Decls,
7015 Make_Procedure_Call_Statement (Loc,
7016 Name =>
7017 New_Occurrence_Of (RTE (RE_Register_Pkg_Receiving_Stub), Loc),
7018 Parameter_Associations => Register_Pkg_Actuals));
7019 Analyze (Last (Decls));
7021 end Add_Receiving_Stubs_To_Declarations;
7023 ---------------------------------
7024 -- Build_General_Calling_Stubs --
7025 ---------------------------------
7027 procedure Build_General_Calling_Stubs
7028 (Decls : List_Id;
7029 Statements : List_Id;
7030 Target_Object : Node_Id;
7031 Subprogram_Id : Node_Id;
7032 Asynchronous : Node_Id := Empty;
7033 Is_Known_Asynchronous : Boolean := False;
7034 Is_Known_Non_Asynchronous : Boolean := False;
7035 Is_Function : Boolean;
7036 Spec : Node_Id;
7037 Stub_Type : Entity_Id := Empty;
7038 RACW_Type : Entity_Id := Empty;
7039 Nod : Node_Id)
7041 Loc : constant Source_Ptr := Sloc (Nod);
7043 Arguments : Node_Id;
7044 -- Name of the named values list used to transmit parameters
7045 -- to the remote package
7047 Request : Node_Id;
7048 -- The request object constructed by these stubs
7050 Result : Node_Id;
7051 -- Name of the result named value (in non-APC cases) which get the
7052 -- result of the remote subprogram.
7054 Result_TC : Node_Id;
7055 -- Typecode expression for the result of the request (void
7056 -- typecode for procedures).
7058 Exception_Return_Parameter : Node_Id;
7059 -- Name of the parameter which will hold the exception sent by the
7060 -- remote subprogram.
7062 Current_Parameter : Node_Id;
7063 -- Current parameter being handled
7065 Ordered_Parameters_List : constant List_Id :=
7066 Build_Ordered_Parameters_List (Spec);
7068 Asynchronous_P : Node_Id;
7069 -- A Boolean expression indicating whether this call is asynchronous
7071 Asynchronous_Statements : List_Id := No_List;
7072 Non_Asynchronous_Statements : List_Id := No_List;
7073 -- Statements specifics to the Asynchronous/Non-Asynchronous cases
7075 Extra_Formal_Statements : constant List_Id := New_List;
7076 -- List of statements for extra formal parameters. It will appear
7077 -- after the regular statements for writing out parameters.
7079 After_Statements : constant List_Id := New_List;
7080 -- Statements to be executed after call returns (to assign
7081 -- in out or out parameter values).
7083 Etyp : Entity_Id;
7084 -- The type of the formal parameter being processed
7086 Is_Controlling_Formal : Boolean;
7087 Is_First_Controlling_Formal : Boolean;
7088 First_Controlling_Formal_Seen : Boolean := False;
7089 -- Controlling formal parameters of distributed object
7090 -- primitives require special handling, and the first
7091 -- such parameter needs even more.
7093 begin
7094 -- ??? document general form of stub subprograms for the PolyORB case
7095 Request :=
7096 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
7098 Append_To (Decls,
7099 Make_Object_Declaration (Loc,
7100 Defining_Identifier => Request,
7101 Aliased_Present => False,
7102 Object_Definition =>
7103 New_Occurrence_Of (RTE (RE_Request_Access), Loc)));
7105 Result :=
7106 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
7108 if Is_Function then
7109 Result_TC := PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
7110 Etype (Subtype_Mark (Spec)), Decls);
7111 else
7112 Result_TC := New_Occurrence_Of (RTE (RE_TC_Void), Loc);
7113 end if;
7115 Append_To (Decls,
7116 Make_Object_Declaration (Loc,
7117 Defining_Identifier => Result,
7118 Aliased_Present => False,
7119 Object_Definition =>
7120 New_Occurrence_Of (RTE (RE_NamedValue), Loc),
7121 Expression =>
7122 Make_Aggregate (Loc,
7123 Component_Associations => New_List (
7124 Make_Component_Association (Loc,
7125 Choices => New_List (
7126 Make_Identifier (Loc, Name_Name)),
7127 Expression =>
7128 New_Occurrence_Of (RTE (RE_Result_Name), Loc)),
7129 Make_Component_Association (Loc,
7130 Choices => New_List (
7131 Make_Identifier (Loc, Name_Argument)),
7132 Expression =>
7133 Make_Function_Call (Loc,
7134 Name =>
7135 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7136 Parameter_Associations => New_List (
7137 Result_TC))),
7138 Make_Component_Association (Loc,
7139 Choices => New_List (
7140 Make_Identifier (Loc, Name_Arg_Modes)),
7141 Expression =>
7142 Make_Integer_Literal (Loc, 0))))));
7144 if not Is_Known_Asynchronous then
7145 Exception_Return_Parameter :=
7146 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
7148 Append_To (Decls,
7149 Make_Object_Declaration (Loc,
7150 Defining_Identifier => Exception_Return_Parameter,
7151 Object_Definition =>
7152 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc)));
7154 else
7155 Exception_Return_Parameter := Empty;
7156 end if;
7158 -- Initialize and fill in arguments list
7160 Arguments :=
7161 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7162 Declare_Create_NVList (Loc, Arguments, Decls, Statements);
7164 Current_Parameter := First (Ordered_Parameters_List);
7165 while Present (Current_Parameter) loop
7167 if Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type) then
7168 Is_Controlling_Formal := True;
7169 Is_First_Controlling_Formal :=
7170 not First_Controlling_Formal_Seen;
7171 First_Controlling_Formal_Seen := True;
7172 else
7173 Is_Controlling_Formal := False;
7174 Is_First_Controlling_Formal := False;
7175 end if;
7177 if Is_Controlling_Formal then
7179 -- In the case of a controlling formal argument, we send
7180 -- its reference.
7182 Etyp := RACW_Type;
7184 else
7185 Etyp := Etype (Parameter_Type (Current_Parameter));
7186 end if;
7188 -- The first controlling formal parameter is treated
7189 -- specially: it is used to set the target object of
7190 -- the call.
7192 if not Is_First_Controlling_Formal then
7194 declare
7195 Constrained : constant Boolean :=
7196 Is_Constrained (Etyp)
7197 or else Is_Elementary_Type (Etyp);
7199 Any : constant Entity_Id :=
7200 Make_Defining_Identifier (Loc,
7201 New_Internal_Name ('A'));
7203 Actual_Parameter : Node_Id :=
7204 New_Occurrence_Of (
7205 Defining_Identifier (
7206 Current_Parameter), Loc);
7208 Expr : Node_Id;
7210 begin
7211 if Is_Controlling_Formal then
7213 -- For a controlling formal parameter (other
7214 -- than the first one), use the corresponding
7215 -- RACW. If the parameter is not an anonymous
7216 -- access parameter, that involves taking
7217 -- its 'Unrestricted_Access.
7219 if Nkind (Parameter_Type (Current_Parameter))
7220 = N_Access_Definition
7221 then
7222 Actual_Parameter := OK_Convert_To
7223 (Etyp, Actual_Parameter);
7224 else
7225 Actual_Parameter := OK_Convert_To (Etyp,
7226 Make_Attribute_Reference (Loc,
7227 Prefix =>
7228 Actual_Parameter,
7229 Attribute_Name =>
7230 Name_Unrestricted_Access));
7231 end if;
7233 end if;
7235 if In_Present (Current_Parameter)
7236 or else not Out_Present (Current_Parameter)
7237 or else not Constrained
7238 or else Is_Controlling_Formal
7239 then
7240 -- The parameter has an input value, is constrained
7241 -- at runtime by an input value, or is a controlling
7242 -- formal parameter (always passed as a reference)
7243 -- other than the first one.
7245 Expr := PolyORB_Support.Helpers.Build_To_Any_Call (
7246 Actual_Parameter, Decls);
7247 else
7248 Expr := Make_Function_Call (Loc,
7249 Name =>
7250 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7251 Parameter_Associations => New_List (
7252 PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
7253 Etyp, Decls)));
7254 end if;
7256 Append_To (Decls,
7257 Make_Object_Declaration (Loc,
7258 Defining_Identifier =>
7259 Any,
7260 Aliased_Present => False,
7261 Object_Definition =>
7262 New_Occurrence_Of (RTE (RE_Any), Loc),
7263 Expression =>
7264 Expr));
7266 Append_To (Statements,
7267 Add_Parameter_To_NVList (Loc,
7268 Parameter => Current_Parameter,
7269 NVList => Arguments,
7270 Constrained => Constrained,
7271 Any => Any));
7273 if Out_Present (Current_Parameter)
7274 and then not Is_Controlling_Formal
7275 then
7276 Append_To (After_Statements,
7277 Make_Assignment_Statement (Loc,
7278 Name =>
7279 New_Occurrence_Of (
7280 Defining_Identifier (Current_Parameter), Loc),
7281 Expression =>
7282 PolyORB_Support.Helpers.Build_From_Any_Call (
7283 Etype (Parameter_Type (Current_Parameter)),
7284 New_Occurrence_Of (Any, Loc),
7285 Decls)));
7287 end if;
7288 end;
7289 end if;
7291 -- If the current parameter has a dynamic constrained status,
7292 -- then this status is transmitted as well.
7293 -- This should be done for accessibility as well ???
7295 if Nkind (Parameter_Type (Current_Parameter))
7296 /= N_Access_Definition
7297 and then Need_Extra_Constrained (Current_Parameter)
7298 then
7299 -- In this block, we do not use the extra formal that has been
7300 -- created because it does not exist at the time of expansion
7301 -- when building calling stubs for remote access to subprogram
7302 -- types. We create an extra variable of this type and push it
7303 -- in the stream after the regular parameters.
7305 declare
7306 Extra_Any_Parameter : constant Entity_Id :=
7307 Make_Defining_Identifier
7308 (Loc, New_Internal_Name ('P'));
7310 begin
7311 Append_To (Decls,
7312 Make_Object_Declaration (Loc,
7313 Defining_Identifier =>
7314 Extra_Any_Parameter,
7315 Aliased_Present => False,
7316 Object_Definition =>
7317 New_Occurrence_Of (RTE (RE_Any), Loc),
7318 Expression =>
7319 PolyORB_Support.Helpers.Build_To_Any_Call (
7320 Make_Attribute_Reference (Loc,
7321 Prefix =>
7322 New_Occurrence_Of (
7323 Defining_Identifier (Current_Parameter), Loc),
7324 Attribute_Name => Name_Constrained),
7325 Decls)));
7326 Append_To (Extra_Formal_Statements,
7327 Add_Parameter_To_NVList (Loc,
7328 Parameter => Extra_Any_Parameter,
7329 NVList => Arguments,
7330 Constrained => True,
7331 Any => Extra_Any_Parameter));
7332 end;
7333 end if;
7335 Next (Current_Parameter);
7336 end loop;
7338 -- Append the formal statements list to the statements
7340 Append_List_To (Statements, Extra_Formal_Statements);
7342 Append_To (Statements,
7343 Make_Procedure_Call_Statement (Loc,
7344 Name =>
7345 New_Occurrence_Of (RTE (RE_Request_Create), Loc),
7346 Parameter_Associations => New_List (
7347 Target_Object,
7348 Subprogram_Id,
7349 New_Occurrence_Of (Arguments, Loc),
7350 New_Occurrence_Of (Result, Loc),
7351 New_Occurrence_Of (RTE (RE_Nil_Exc_List), Loc))));
7353 Append_To (Parameter_Associations (Last (Statements)),
7354 New_Occurrence_Of (Request, Loc));
7356 pragma Assert (
7357 not (Is_Known_Non_Asynchronous and Is_Known_Asynchronous));
7358 if Is_Known_Non_Asynchronous or Is_Known_Asynchronous then
7359 Asynchronous_P := New_Occurrence_Of (
7360 Boolean_Literals (Is_Known_Asynchronous), Loc);
7361 else
7362 pragma Assert (Present (Asynchronous));
7363 Asynchronous_P := New_Copy_Tree (Asynchronous);
7364 -- The expression node Asynchronous will be used to build
7365 -- an 'if' statement at the end of Build_General_Calling_Stubs:
7366 -- we need to make a copy here.
7367 end if;
7369 Append_To (Parameter_Associations (Last (Statements)),
7370 Make_Indexed_Component (Loc,
7371 Prefix =>
7372 New_Occurrence_Of (
7373 RTE (RE_Asynchronous_P_To_Sync_Scope), Loc),
7374 Expressions => New_List (Asynchronous_P)));
7376 Append_To (Statements,
7377 Make_Procedure_Call_Statement (Loc,
7378 Name =>
7379 New_Occurrence_Of (RTE (RE_Request_Invoke), Loc),
7380 Parameter_Associations => New_List (
7381 New_Occurrence_Of (Request, Loc))));
7383 Non_Asynchronous_Statements := New_List (Make_Null_Statement (Loc));
7384 Asynchronous_Statements := New_List (Make_Null_Statement (Loc));
7386 if not Is_Known_Asynchronous then
7388 -- Reraise an exception occurrence from the completed request.
7389 -- If the exception occurrence is empty, this is a no-op.
7391 Append_To (Non_Asynchronous_Statements,
7392 Make_Procedure_Call_Statement (Loc,
7393 Name =>
7394 New_Occurrence_Of (RTE (RE_Request_Raise_Occurrence), Loc),
7395 Parameter_Associations => New_List (
7396 New_Occurrence_Of (Request, Loc))));
7398 if Is_Function then
7400 -- If this is a function call, then read the value and
7401 -- return it.
7403 Append_To (Non_Asynchronous_Statements,
7404 Make_Tag_Check (Loc,
7405 Make_Return_Statement (Loc,
7406 PolyORB_Support.Helpers.Build_From_Any_Call (
7407 Etype (Subtype_Mark (Spec)),
7408 Make_Selected_Component (Loc,
7409 Prefix => Result,
7410 Selector_Name => Name_Argument),
7411 Decls))));
7412 end if;
7413 end if;
7415 Append_List_To (Non_Asynchronous_Statements,
7416 After_Statements);
7418 if Is_Known_Asynchronous then
7419 Append_List_To (Statements, Asynchronous_Statements);
7421 elsif Is_Known_Non_Asynchronous then
7422 Append_List_To (Statements, Non_Asynchronous_Statements);
7424 else
7425 pragma Assert (Present (Asynchronous));
7426 Append_To (Statements,
7427 Make_Implicit_If_Statement (Nod,
7428 Condition => Asynchronous,
7429 Then_Statements => Asynchronous_Statements,
7430 Else_Statements => Non_Asynchronous_Statements));
7431 end if;
7432 end Build_General_Calling_Stubs;
7434 -----------------------
7435 -- Build_Stub_Target --
7436 -----------------------
7438 function Build_Stub_Target
7439 (Loc : Source_Ptr;
7440 Decls : List_Id;
7441 RCI_Locator : Entity_Id;
7442 Controlling_Parameter : Entity_Id) return RPC_Target
7444 Target_Info : RPC_Target (PCS_Kind => Name_PolyORB_DSA);
7445 Target_Reference : constant Entity_Id :=
7446 Make_Defining_Identifier (Loc,
7447 New_Internal_Name ('T'));
7448 begin
7449 if Present (Controlling_Parameter) then
7450 Append_To (Decls,
7451 Make_Object_Declaration (Loc,
7452 Defining_Identifier => Target_Reference,
7453 Object_Definition =>
7454 New_Occurrence_Of (RTE (RE_Object_Ref), Loc),
7455 Expression =>
7456 Make_Function_Call (Loc,
7457 Name =>
7458 New_Occurrence_Of (RTE (RE_Make_Ref), Loc),
7459 Parameter_Associations => New_List (
7460 Make_Selected_Component (Loc,
7461 Prefix => Controlling_Parameter,
7462 Selector_Name => Name_Target)))));
7463 -- Controlling_Parameter has the same components
7464 -- as System.Partition_Interface.RACW_Stub_Type.
7466 Target_Info.Object := New_Occurrence_Of (Target_Reference, Loc);
7468 else
7469 Target_Info.Object :=
7470 Make_Selected_Component (Loc,
7471 Prefix =>
7472 Make_Identifier (Loc, Chars (RCI_Locator)),
7473 Selector_Name =>
7474 Make_Identifier (Loc, Name_Get_RCI_Package_Ref));
7475 end if;
7476 return Target_Info;
7477 end Build_Stub_Target;
7479 ---------------------
7480 -- Build_Stub_Type --
7481 ---------------------
7483 procedure Build_Stub_Type
7484 (RACW_Type : Entity_Id;
7485 Stub_Type : Entity_Id;
7486 Stub_Type_Decl : out Node_Id;
7487 RPC_Receiver_Decl : out Node_Id)
7489 Loc : constant Source_Ptr := Sloc (Stub_Type);
7490 pragma Warnings (Off);
7491 pragma Unreferenced (RACW_Type);
7492 pragma Warnings (On);
7494 begin
7495 Stub_Type_Decl :=
7496 Make_Full_Type_Declaration (Loc,
7497 Defining_Identifier => Stub_Type,
7498 Type_Definition =>
7499 Make_Record_Definition (Loc,
7500 Tagged_Present => True,
7501 Limited_Present => True,
7502 Component_List =>
7503 Make_Component_List (Loc,
7504 Component_Items => New_List (
7506 Make_Component_Declaration (Loc,
7507 Defining_Identifier =>
7508 Make_Defining_Identifier (Loc, Name_Target),
7509 Component_Definition =>
7510 Make_Component_Definition (Loc,
7511 Aliased_Present =>
7512 False,
7513 Subtype_Indication =>
7514 New_Occurrence_Of (RTE (RE_Entity_Ptr), Loc))),
7516 Make_Component_Declaration (Loc,
7517 Defining_Identifier =>
7518 Make_Defining_Identifier (Loc, Name_Asynchronous),
7519 Component_Definition =>
7520 Make_Component_Definition (Loc,
7521 Aliased_Present => False,
7522 Subtype_Indication =>
7523 New_Occurrence_Of (
7524 Standard_Boolean, Loc)))))));
7526 RPC_Receiver_Decl :=
7527 Make_Object_Declaration (Loc,
7528 Defining_Identifier => Make_Defining_Identifier (Loc,
7529 New_Internal_Name ('R')),
7530 Aliased_Present => True,
7531 Object_Definition =>
7532 New_Occurrence_Of (RTE (RE_Servant), Loc));
7533 end Build_Stub_Type;
7535 -----------------------------
7536 -- Build_RPC_Receiver_Body --
7537 -----------------------------
7539 procedure Build_RPC_Receiver_Body
7540 (RPC_Receiver : Entity_Id;
7541 Request : out Entity_Id;
7542 Subp_Id : out Entity_Id;
7543 Subp_Index : out Entity_Id;
7544 Stmts : out List_Id;
7545 Decl : out Node_Id)
7547 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
7549 RPC_Receiver_Spec : Node_Id;
7550 RPC_Receiver_Decls : List_Id;
7552 begin
7553 Request := Make_Defining_Identifier (Loc, Name_R);
7555 RPC_Receiver_Spec :=
7556 Build_RPC_Receiver_Specification (
7557 RPC_Receiver => RPC_Receiver,
7558 Request_Parameter => Request);
7560 Subp_Id := Make_Defining_Identifier (Loc, Name_P);
7561 Subp_Index := Make_Defining_Identifier (Loc, Name_I);
7563 RPC_Receiver_Decls := New_List (
7564 Make_Object_Renaming_Declaration (Loc,
7565 Defining_Identifier => Subp_Id,
7566 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
7567 Name =>
7568 Make_Explicit_Dereference (Loc,
7569 Prefix =>
7570 Make_Selected_Component (Loc,
7571 Prefix => Request,
7572 Selector_Name => Name_Operation))),
7574 Make_Object_Declaration (Loc,
7575 Defining_Identifier => Subp_Index,
7576 Object_Definition =>
7577 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
7578 Expression =>
7579 Make_Attribute_Reference (Loc,
7580 Prefix =>
7581 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
7582 Attribute_Name => Name_Last)));
7584 Stmts := New_List;
7586 Decl :=
7587 Make_Subprogram_Body (Loc,
7588 Specification => RPC_Receiver_Spec,
7589 Declarations => RPC_Receiver_Decls,
7590 Handled_Statement_Sequence =>
7591 Make_Handled_Sequence_Of_Statements (Loc,
7592 Statements => Stmts));
7593 end Build_RPC_Receiver_Body;
7595 --------------------------------------
7596 -- Build_Subprogram_Receiving_Stubs --
7597 --------------------------------------
7599 function Build_Subprogram_Receiving_Stubs
7600 (Vis_Decl : Node_Id;
7601 Asynchronous : Boolean;
7602 Dynamically_Asynchronous : Boolean := False;
7603 Stub_Type : Entity_Id := Empty;
7604 RACW_Type : Entity_Id := Empty;
7605 Parent_Primitive : Entity_Id := Empty) return Node_Id
7607 Loc : constant Source_Ptr := Sloc (Vis_Decl);
7609 Request_Parameter : Node_Id;
7610 -- ???
7612 Outer_Decls : constant List_Id := New_List;
7613 -- At the outermost level, an NVList and Any's are
7614 -- declared for all parameters. The Dynamic_Async
7615 -- flag also needs to be declared there to be visible
7616 -- from the exception handling code.
7618 Outer_Statements : constant List_Id := New_List;
7619 -- Statements that occur prior to the declaration of the actual
7620 -- parameter variables.
7622 Decls : constant List_Id := New_List;
7623 -- All the parameters will get declared before calling the real
7624 -- subprograms. Also the out parameters will be declared.
7625 -- At this level, parameters may be unconstrained.
7627 Statements : constant List_Id := New_List;
7629 Extra_Formal_Statements : constant List_Id := New_List;
7630 -- Statements concerning extra formal parameters
7632 After_Statements : constant List_Id := New_List;
7633 -- Statements to be executed after the subprogram call
7635 Inner_Decls : List_Id := No_List;
7636 -- In case of a function, the inner declarations are needed since
7637 -- the result may be unconstrained.
7639 Excep_Handlers : List_Id := No_List;
7641 Parameter_List : constant List_Id := New_List;
7642 -- List of parameters to be passed to the subprogram
7644 First_Controlling_Formal_Seen : Boolean := False;
7646 Current_Parameter : Node_Id;
7648 Ordered_Parameters_List : constant List_Id :=
7649 Build_Ordered_Parameters_List
7650 (Specification (Vis_Decl));
7652 Arguments : Node_Id;
7653 -- Name of the named values list used to retrieve parameters
7655 Subp_Spec : Node_Id;
7656 -- Subprogram specification
7658 Called_Subprogram : Node_Id;
7659 -- The subprogram to call
7661 begin
7662 if Present (RACW_Type) then
7663 Called_Subprogram :=
7664 New_Occurrence_Of (Parent_Primitive, Loc);
7665 else
7666 Called_Subprogram :=
7667 New_Occurrence_Of (
7668 Defining_Unit_Name (Specification (Vis_Decl)), Loc);
7669 end if;
7671 Request_Parameter :=
7672 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
7674 Arguments :=
7675 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7676 Declare_Create_NVList (Loc, Arguments, Outer_Decls, Outer_Statements);
7678 -- Loop through every parameter and get its value from the stream. If
7679 -- the parameter is unconstrained, then the parameter is read using
7680 -- 'Input at the point of declaration.
7682 Current_Parameter := First (Ordered_Parameters_List);
7683 while Present (Current_Parameter) loop
7684 declare
7685 Etyp : Entity_Id;
7686 Constrained : Boolean;
7687 Any : Entity_Id := Empty;
7688 Object : constant Entity_Id :=
7689 Make_Defining_Identifier (Loc,
7690 New_Internal_Name ('P'));
7691 Expr : Node_Id := Empty;
7693 Is_Controlling_Formal : constant Boolean
7694 := Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type);
7696 Is_First_Controlling_Formal : Boolean := False;
7697 begin
7698 Set_Ekind (Object, E_Variable);
7700 if Is_Controlling_Formal then
7702 -- Controlling formals in distributed object primitive
7703 -- operations are handled specially:
7704 -- - the first controlling formal is used as the
7705 -- target of the call;
7706 -- - the remaining controlling formals are transmitted
7707 -- as RACWs.
7709 Etyp := RACW_Type;
7710 Is_First_Controlling_Formal :=
7711 not First_Controlling_Formal_Seen;
7712 First_Controlling_Formal_Seen := True;
7713 else
7714 Etyp := Etype (Parameter_Type (Current_Parameter));
7715 end if;
7717 Constrained :=
7718 Is_Constrained (Etyp)
7719 or else Is_Elementary_Type (Etyp);
7721 if not Is_First_Controlling_Formal then
7722 Any := Make_Defining_Identifier (Loc,
7723 New_Internal_Name ('A'));
7724 Append_To (Outer_Decls,
7725 Make_Object_Declaration (Loc,
7726 Defining_Identifier =>
7727 Any,
7728 Object_Definition =>
7729 New_Occurrence_Of (RTE (RE_Any), Loc),
7730 Expression =>
7731 Make_Function_Call (Loc,
7732 Name =>
7733 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7734 Parameter_Associations => New_List (
7735 PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
7736 Etyp, Outer_Decls)))));
7738 Append_To (Outer_Statements,
7739 Add_Parameter_To_NVList (Loc,
7740 Parameter => Current_Parameter,
7741 NVList => Arguments,
7742 Constrained => Constrained,
7743 Any => Any));
7744 end if;
7746 if Is_First_Controlling_Formal then
7747 declare
7748 Addr : constant Entity_Id :=
7749 Make_Defining_Identifier (Loc,
7750 New_Internal_Name ('A'));
7751 Is_Local : constant Entity_Id :=
7752 Make_Defining_Identifier (Loc,
7753 New_Internal_Name ('L'));
7754 begin
7756 -- Special case: obtain the first controlling
7757 -- formal from the target of the remote call,
7758 -- instead of the argument list.
7760 Append_To (Outer_Decls,
7761 Make_Object_Declaration (Loc,
7762 Defining_Identifier =>
7763 Addr,
7764 Object_Definition =>
7765 New_Occurrence_Of (RTE (RE_Address), Loc)));
7766 Append_To (Outer_Decls,
7767 Make_Object_Declaration (Loc,
7768 Defining_Identifier =>
7769 Is_Local,
7770 Object_Definition =>
7771 New_Occurrence_Of (Standard_Boolean, Loc)));
7772 Append_To (Outer_Statements,
7773 Make_Procedure_Call_Statement (Loc,
7774 Name =>
7775 New_Occurrence_Of (
7776 RTE (RE_Get_Local_Address), Loc),
7777 Parameter_Associations => New_List (
7778 Make_Selected_Component (Loc,
7779 Prefix =>
7780 New_Occurrence_Of (
7781 Request_Parameter, Loc),
7782 Selector_Name =>
7783 Make_Identifier (Loc, Name_Target)),
7784 New_Occurrence_Of (Is_Local, Loc),
7785 New_Occurrence_Of (Addr, Loc))));
7787 Expr := Unchecked_Convert_To (RACW_Type,
7788 New_Occurrence_Of (Addr, Loc));
7789 end;
7791 elsif In_Present (Current_Parameter)
7792 or else not Out_Present (Current_Parameter)
7793 or else not Constrained
7794 then
7795 -- If an input parameter is contrained, then its reading is
7796 -- deferred until the beginning of the subprogram body. If
7797 -- it is unconstrained, then an expression is built for
7798 -- the object declaration and the variable is set using
7799 -- 'Input instead of 'Read.
7801 Expr := PolyORB_Support.Helpers.Build_From_Any_Call (
7802 Etyp, New_Occurrence_Of (Any, Loc), Decls);
7804 if Constrained then
7806 Append_To (Statements,
7807 Make_Assignment_Statement (Loc,
7808 Name =>
7809 New_Occurrence_Of (Object, Loc),
7810 Expression =>
7811 Expr));
7812 Expr := Empty;
7813 else
7814 null;
7815 -- Expr will be used to initialize (and constrain)
7816 -- the parameter when it is declared.
7817 end if;
7819 end if;
7821 -- If we do not have to output the current parameter, then
7822 -- it can well be flagged as constant. This may allow further
7823 -- optimizations done by the back end.
7825 Append_To (Decls,
7826 Make_Object_Declaration (Loc,
7827 Defining_Identifier => Object,
7828 Constant_Present => not Constrained
7829 and then not Out_Present (Current_Parameter),
7830 Object_Definition =>
7831 New_Occurrence_Of (Etyp, Loc),
7832 Expression => Expr));
7833 Set_Etype (Object, Etyp);
7835 -- An out parameter may be written back using a 'Write
7836 -- attribute instead of a 'Output because it has been
7837 -- constrained by the parameter given to the caller. Note that
7838 -- out controlling arguments in the case of a RACW are not put
7839 -- back in the stream because the pointer on them has not
7840 -- changed.
7842 if Out_Present (Current_Parameter)
7843 and then not Is_Controlling_Formal
7844 then
7845 Append_To (After_Statements,
7846 Make_Procedure_Call_Statement (Loc,
7847 Name =>
7848 New_Occurrence_Of (RTE (RE_Copy_Any_Value), Loc),
7849 Parameter_Associations => New_List (
7850 New_Occurrence_Of (Any, Loc),
7851 PolyORB_Support.Helpers.Build_To_Any_Call (
7852 New_Occurrence_Of (Object, Loc),
7853 Decls))));
7854 end if;
7856 -- For RACW controlling formals, the Etyp of Object is always
7857 -- an RACW, even if the parameter is not of an anonymous access
7858 -- type. In such case, we need to dereference it at call time.
7860 if Is_Controlling_Formal then
7861 if Nkind (Parameter_Type (Current_Parameter)) /=
7862 N_Access_Definition
7863 then
7864 Append_To (Parameter_List,
7865 Make_Parameter_Association (Loc,
7866 Selector_Name =>
7867 New_Occurrence_Of (
7868 Defining_Identifier (Current_Parameter), Loc),
7869 Explicit_Actual_Parameter =>
7870 Make_Explicit_Dereference (Loc,
7871 Unchecked_Convert_To (RACW_Type,
7872 OK_Convert_To (RTE (RE_Address),
7873 New_Occurrence_Of (Object, Loc))))));
7875 else
7876 Append_To (Parameter_List,
7877 Make_Parameter_Association (Loc,
7878 Selector_Name =>
7879 New_Occurrence_Of (
7880 Defining_Identifier (Current_Parameter), Loc),
7881 Explicit_Actual_Parameter =>
7882 Unchecked_Convert_To (RACW_Type,
7883 OK_Convert_To (RTE (RE_Address),
7884 New_Occurrence_Of (Object, Loc)))));
7885 end if;
7887 else
7888 Append_To (Parameter_List,
7889 Make_Parameter_Association (Loc,
7890 Selector_Name =>
7891 New_Occurrence_Of (
7892 Defining_Identifier (Current_Parameter), Loc),
7893 Explicit_Actual_Parameter =>
7894 New_Occurrence_Of (Object, Loc)));
7895 end if;
7897 -- If the current parameter needs an extra formal, then read it
7898 -- from the stream and set the corresponding semantic field in
7899 -- the variable. If the kind of the parameter identifier is
7900 -- E_Void, then this is a compiler generated parameter that
7901 -- doesn't need an extra constrained status.
7903 -- The case of Extra_Accessibility should also be handled ???
7905 if Nkind (Parameter_Type (Current_Parameter)) /=
7906 N_Access_Definition
7907 and then
7908 Ekind (Defining_Identifier (Current_Parameter)) /= E_Void
7909 and then
7910 Present (Extra_Constrained
7911 (Defining_Identifier (Current_Parameter)))
7912 then
7913 declare
7914 Extra_Parameter : constant Entity_Id :=
7915 Extra_Constrained
7916 (Defining_Identifier
7917 (Current_Parameter));
7918 Extra_Any : constant Entity_Id :=
7919 Make_Defining_Identifier
7920 (Loc, New_Internal_Name ('A'));
7921 Formal_Entity : constant Entity_Id :=
7922 Make_Defining_Identifier
7923 (Loc, Chars (Extra_Parameter));
7925 Formal_Type : constant Entity_Id :=
7926 Etype (Extra_Parameter);
7927 begin
7928 Append_To (Outer_Decls,
7929 Make_Object_Declaration (Loc,
7930 Defining_Identifier =>
7931 Extra_Any,
7932 Object_Definition =>
7933 New_Occurrence_Of (RTE (RE_Any), Loc)));
7935 Append_To (Outer_Statements,
7936 Add_Parameter_To_NVList (Loc,
7937 Parameter => Extra_Parameter,
7938 NVList => Arguments,
7939 Constrained => True,
7940 Any => Extra_Any));
7942 Append_To (Decls,
7943 Make_Object_Declaration (Loc,
7944 Defining_Identifier => Formal_Entity,
7945 Object_Definition =>
7946 New_Occurrence_Of (Formal_Type, Loc)));
7948 Append_To (Extra_Formal_Statements,
7949 Make_Assignment_Statement (Loc,
7950 Name =>
7951 New_Occurrence_Of (Extra_Parameter, Loc),
7952 Expression =>
7953 PolyORB_Support.Helpers.Build_From_Any_Call (
7954 Etype (Extra_Parameter),
7955 New_Occurrence_Of (Extra_Any, Loc),
7956 Decls)));
7957 Set_Extra_Constrained (Object, Formal_Entity);
7959 end;
7960 end if;
7961 end;
7963 Next (Current_Parameter);
7964 end loop;
7966 Append_To (Outer_Statements,
7967 Make_Procedure_Call_Statement (Loc,
7968 Name =>
7969 New_Occurrence_Of (RTE (RE_Request_Arguments), Loc),
7970 Parameter_Associations => New_List (
7971 New_Occurrence_Of (Request_Parameter, Loc),
7972 New_Occurrence_Of (Arguments, Loc))));
7974 Append_List_To (Statements, Extra_Formal_Statements);
7976 if Nkind (Specification (Vis_Decl)) = N_Function_Specification then
7978 -- The remote subprogram is a function. We build an inner block to
7979 -- be able to hold a potentially unconstrained result in a
7980 -- variable.
7982 declare
7983 Etyp : constant Entity_Id :=
7984 Etype (Subtype_Mark (Specification (Vis_Decl)));
7985 Result : constant Node_Id :=
7986 Make_Defining_Identifier (Loc,
7987 New_Internal_Name ('R'));
7988 begin
7989 Inner_Decls := New_List (
7990 Make_Object_Declaration (Loc,
7991 Defining_Identifier => Result,
7992 Constant_Present => True,
7993 Object_Definition => New_Occurrence_Of (Etyp, Loc),
7994 Expression =>
7995 Make_Function_Call (Loc,
7996 Name => Called_Subprogram,
7997 Parameter_Associations => Parameter_List)));
7999 Set_Etype (Result, Etyp);
8000 Append_To (After_Statements,
8001 Make_Procedure_Call_Statement (Loc,
8002 Name =>
8003 New_Occurrence_Of (RTE (RE_Set_Result), Loc),
8004 Parameter_Associations => New_List (
8005 New_Occurrence_Of (Request_Parameter, Loc),
8006 PolyORB_Support.Helpers.Build_To_Any_Call (
8007 New_Occurrence_Of (Result, Loc),
8008 Decls))));
8009 -- A DSA function does not have out or inout arguments
8010 end;
8012 Append_To (Statements,
8013 Make_Block_Statement (Loc,
8014 Declarations => Inner_Decls,
8015 Handled_Statement_Sequence =>
8016 Make_Handled_Sequence_Of_Statements (Loc,
8017 Statements => After_Statements)));
8019 else
8020 -- The remote subprogram is a procedure. We do not need any inner
8021 -- block in this case. No specific processing is required here for
8022 -- the dynamically asynchronous case: the indication of whether
8023 -- call is asynchronous or not is managed by the Sync_Scope
8024 -- attibute of the request, and is handled entirely in the
8025 -- protocol layer.
8027 Append_To (After_Statements,
8028 Make_Procedure_Call_Statement (Loc,
8029 Name =>
8030 New_Occurrence_Of (RTE (RE_Request_Set_Out), Loc),
8031 Parameter_Associations => New_List (
8032 New_Occurrence_Of (Request_Parameter, Loc))));
8034 Append_To (Statements,
8035 Make_Procedure_Call_Statement (Loc,
8036 Name => Called_Subprogram,
8037 Parameter_Associations => Parameter_List));
8039 Append_List_To (Statements, After_Statements);
8040 end if;
8042 Subp_Spec :=
8043 Make_Procedure_Specification (Loc,
8044 Defining_Unit_Name =>
8045 Make_Defining_Identifier (Loc, New_Internal_Name ('F')),
8047 Parameter_Specifications => New_List (
8048 Make_Parameter_Specification (Loc,
8049 Defining_Identifier => Request_Parameter,
8050 Parameter_Type =>
8051 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
8053 -- An exception raised during the execution of an incoming
8054 -- remote subprogram call and that needs to be sent back
8055 -- to the caller is propagated by the receiving stubs, and
8056 -- will be handled by the caller (the distribution runtime).
8058 if Asynchronous and then not Dynamically_Asynchronous then
8060 -- For an asynchronous procedure, add a null exception handler
8062 Excep_Handlers := New_List (
8063 Make_Exception_Handler (Loc,
8064 Exception_Choices => New_List (Make_Others_Choice (Loc)),
8065 Statements => New_List (Make_Null_Statement (Loc))));
8067 else
8069 -- In the other cases, if an exception is raised, then the
8070 -- exception occurrence is propagated.
8072 null;
8073 end if;
8075 Append_To (Outer_Statements,
8076 Make_Block_Statement (Loc,
8077 Declarations =>
8078 Decls,
8079 Handled_Statement_Sequence =>
8080 Make_Handled_Sequence_Of_Statements (Loc,
8081 Statements => Statements)));
8083 return
8084 Make_Subprogram_Body (Loc,
8085 Specification => Subp_Spec,
8086 Declarations => Outer_Decls,
8087 Handled_Statement_Sequence =>
8088 Make_Handled_Sequence_Of_Statements (Loc,
8089 Statements => Outer_Statements,
8090 Exception_Handlers => Excep_Handlers));
8091 end Build_Subprogram_Receiving_Stubs;
8092 -------------
8093 -- Helpers --
8094 -------------
8096 package body Helpers is
8098 -----------------------
8099 -- Local Subprograms --
8100 -----------------------
8102 function Find_Inherited_TSS
8103 (Typ : Entity_Id;
8104 Nam : Name_Id) return Entity_Id;
8105 -- A TSS reference for a representation aspect of a derived tagged
8106 -- type must take into account inheritance of that aspect from
8107 -- ancestor types. (copied from exp_attr.adb, should be shared???)
8109 function Find_Numeric_Representation
8110 (Typ : Entity_Id) return Entity_Id;
8111 -- Given a numeric type Typ, return the smallest integer or floarting
8112 -- point type from Standard, or the smallest unsigned (modular) type
8113 -- from System.Unsigned_Types, whose range encompasses that of Typ.
8115 function Make_Stream_Procedure_Function_Name
8116 (Loc : Source_Ptr;
8117 Typ : Entity_Id;
8118 Nam : Name_Id) return Entity_Id;
8119 -- Return the name to be assigned for stream subprogram Nam of Typ.
8120 -- (copied from exp_strm.adb, should be shared???)
8122 ------------------------------------------------------------
8123 -- Common subprograms for building various tree fragments --
8124 ------------------------------------------------------------
8126 function Build_Get_Aggregate_Element
8127 (Loc : Source_Ptr;
8128 Any : Entity_Id;
8129 TC : Node_Id;
8130 Idx : Node_Id) return Node_Id;
8131 -- Build a call to Get_Aggregate_Element on Any
8132 -- for typecode TC, returning the Idx'th element.
8134 generic
8135 Subprogram : Entity_Id;
8136 -- Reference location for constructed nodes
8138 Arry : Entity_Id;
8139 -- For 'Range and Etype
8141 Indices : List_Id;
8142 -- For the construction of the innermost element expression
8144 with procedure Add_Process_Element
8145 (Stmts : List_Id;
8146 Any : Entity_Id;
8147 Counter : Entity_Id;
8148 Datum : Node_Id);
8150 procedure Append_Array_Traversal
8151 (Stmts : List_Id;
8152 Any : Entity_Id;
8153 Counter : Entity_Id := Empty;
8154 Depth : Pos := 1);
8155 -- Build nested loop statements that iterate over the elements of an
8156 -- array Arry. The statement(s) built by Add_Process_Element are
8157 -- executed for each element; Indices is the list of indices to be
8158 -- used in the construction of the indexed component that denotes the
8159 -- current element. Subprogram is the entity for the subprogram for
8160 -- which this iterator is generated. The generated statements are
8161 -- appended to Stmts.
8163 generic
8164 Rec : Entity_Id;
8165 -- The record entity being dealt with
8167 with procedure Add_Process_Element
8168 (Stmts : List_Id;
8169 Container : Node_Or_Entity_Id;
8170 Counter : in out Int;
8171 Rec : Entity_Id;
8172 Field : Node_Id);
8173 -- Rec is the instance of the record type, or Empty.
8174 -- Field is either the N_Defining_Identifier for a component,
8175 -- or an N_Variant_Part.
8177 procedure Append_Record_Traversal
8178 (Stmts : List_Id;
8179 Clist : Node_Id;
8180 Container : Node_Or_Entity_Id;
8181 Counter : in out Int);
8182 -- Process component list Clist. Individual fields are passed
8183 -- to Field_Processing. Each variant part is also processed.
8184 -- Container is the outer Any (for From_Any/To_Any),
8185 -- the outer typecode (for TC) to which the operation applies.
8187 -----------------------------
8188 -- Append_Record_Traversal --
8189 -----------------------------
8191 procedure Append_Record_Traversal
8192 (Stmts : List_Id;
8193 Clist : Node_Id;
8194 Container : Node_Or_Entity_Id;
8195 Counter : in out Int)
8197 CI : constant List_Id := Component_Items (Clist);
8198 VP : constant Node_Id := Variant_Part (Clist);
8200 Item : Node_Id := First (CI);
8201 Def : Entity_Id;
8203 begin
8204 while Present (Item) loop
8205 Def := Defining_Identifier (Item);
8206 if not Is_Internal_Name (Chars (Def)) then
8207 Add_Process_Element
8208 (Stmts, Container, Counter, Rec, Def);
8209 end if;
8210 Next (Item);
8211 end loop;
8213 if Present (VP) then
8214 Add_Process_Element (Stmts, Container, Counter, Rec, VP);
8215 end if;
8216 end Append_Record_Traversal;
8218 -------------------------
8219 -- Build_From_Any_Call --
8220 -------------------------
8222 function Build_From_Any_Call
8223 (Typ : Entity_Id;
8224 N : Node_Id;
8225 Decls : List_Id) return Node_Id
8227 Loc : constant Source_Ptr := Sloc (N);
8229 U_Type : Entity_Id := Underlying_Type (Typ);
8231 Fnam : Entity_Id := Empty;
8232 Lib_RE : RE_Id := RE_Null;
8234 begin
8236 -- First simple case where the From_Any function is present
8237 -- in the type's TSS.
8239 Fnam := Find_Inherited_TSS (U_Type, Name_uFrom_Any);
8241 if Sloc (U_Type) <= Standard_Location then
8242 U_Type := Base_Type (U_Type);
8243 end if;
8245 -- Check first for Boolean and Character. These are enumeration
8246 -- types, but we treat them specially, since they may require
8247 -- special handling in the transfer protocol. However, this
8248 -- special handling only applies if they have standard
8249 -- representation, otherwise they are treated like any other
8250 -- enumeration type.
8252 if Present (Fnam) then
8253 null;
8255 elsif U_Type = Standard_Boolean then
8256 Lib_RE := RE_FA_B;
8258 elsif U_Type = Standard_Character then
8259 Lib_RE := RE_FA_C;
8261 elsif U_Type = Standard_Wide_Character then
8262 Lib_RE := RE_FA_WC;
8264 elsif U_Type = Standard_Wide_Wide_Character then
8265 Lib_RE := RE_FA_WWC;
8267 -- Floating point types
8269 elsif U_Type = Standard_Short_Float then
8270 Lib_RE := RE_FA_SF;
8272 elsif U_Type = Standard_Float then
8273 Lib_RE := RE_FA_F;
8275 elsif U_Type = Standard_Long_Float then
8276 Lib_RE := RE_FA_LF;
8278 elsif U_Type = Standard_Long_Long_Float then
8279 Lib_RE := RE_FA_LLF;
8281 -- Integer types
8283 elsif U_Type = Etype (Standard_Short_Short_Integer) then
8284 Lib_RE := RE_FA_SSI;
8286 elsif U_Type = Etype (Standard_Short_Integer) then
8287 Lib_RE := RE_FA_SI;
8289 elsif U_Type = Etype (Standard_Integer) then
8290 Lib_RE := RE_FA_I;
8292 elsif U_Type = Etype (Standard_Long_Integer) then
8293 Lib_RE := RE_FA_LI;
8295 elsif U_Type = Etype (Standard_Long_Long_Integer) then
8296 Lib_RE := RE_FA_LLI;
8298 -- Unsigned integer types
8300 elsif U_Type = RTE (RE_Short_Short_Unsigned) then
8301 Lib_RE := RE_FA_SSU;
8303 elsif U_Type = RTE (RE_Short_Unsigned) then
8304 Lib_RE := RE_FA_SU;
8306 elsif U_Type = RTE (RE_Unsigned) then
8307 Lib_RE := RE_FA_U;
8309 elsif U_Type = RTE (RE_Long_Unsigned) then
8310 Lib_RE := RE_FA_LU;
8312 elsif U_Type = RTE (RE_Long_Long_Unsigned) then
8313 Lib_RE := RE_FA_LLU;
8315 elsif U_Type = Standard_String then
8316 Lib_RE := RE_FA_String;
8318 -- Other (non-primitive) types
8320 else
8321 declare
8322 Decl : Entity_Id;
8323 begin
8324 Build_From_Any_Function (Loc, U_Type, Decl, Fnam);
8325 Append_To (Decls, Decl);
8326 end;
8327 end if;
8329 -- Call the function
8331 if Lib_RE /= RE_Null then
8332 pragma Assert (No (Fnam));
8333 Fnam := RTE (Lib_RE);
8334 end if;
8336 return
8337 Make_Function_Call (Loc,
8338 Name => New_Occurrence_Of (Fnam, Loc),
8339 Parameter_Associations => New_List (N));
8340 end Build_From_Any_Call;
8342 -----------------------------
8343 -- Build_From_Any_Function --
8344 -----------------------------
8346 procedure Build_From_Any_Function
8347 (Loc : Source_Ptr;
8348 Typ : Entity_Id;
8349 Decl : out Node_Id;
8350 Fnam : out Entity_Id)
8352 Spec : Node_Id;
8353 Decls : constant List_Id := New_List;
8354 Stms : constant List_Id := New_List;
8355 Any_Parameter : constant Entity_Id
8356 := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
8357 begin
8358 Fnam := Make_Stream_Procedure_Function_Name (Loc,
8359 Typ, Name_uFrom_Any);
8361 Spec :=
8362 Make_Function_Specification (Loc,
8363 Defining_Unit_Name => Fnam,
8364 Parameter_Specifications => New_List (
8365 Make_Parameter_Specification (Loc,
8366 Defining_Identifier =>
8367 Any_Parameter,
8368 Parameter_Type =>
8369 New_Occurrence_Of (RTE (RE_Any), Loc))),
8370 Subtype_Mark => New_Occurrence_Of (Typ, Loc));
8372 -- The following is taken care of by Exp_Dist.Add_RACW_From_Any
8374 pragma Assert
8375 (not (Is_Remote_Access_To_Class_Wide_Type (Typ)));
8378 if Is_Derived_Type (Typ)
8379 and then not Is_Tagged_Type (Typ)
8380 then
8381 Append_To (Stms,
8382 Make_Return_Statement (Loc,
8383 Expression =>
8384 OK_Convert_To (
8385 Typ,
8386 Build_From_Any_Call (
8387 Root_Type (Typ),
8388 New_Occurrence_Of (Any_Parameter, Loc),
8389 Decls))));
8391 elsif Is_Record_Type (Typ)
8392 and then not Is_Derived_Type (Typ)
8393 and then not Is_Tagged_Type (Typ)
8394 then
8395 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
8396 Append_To (Stms,
8397 Make_Return_Statement (Loc,
8398 Expression =>
8399 OK_Convert_To (
8400 Typ,
8401 Build_From_Any_Call (
8402 Etype (Typ),
8403 New_Occurrence_Of (Any_Parameter, Loc),
8404 Decls))));
8405 else
8406 declare
8407 Disc : Entity_Id := Empty;
8408 Discriminant_Associations : List_Id;
8409 Rdef : constant Node_Id :=
8410 Type_Definition (Declaration_Node (Typ));
8411 Component_Counter : Int := 0;
8413 -- The returned object
8415 Res : constant Entity_Id :=
8416 Make_Defining_Identifier (Loc,
8417 New_Internal_Name ('R'));
8419 Res_Definition : Node_Id := New_Occurrence_Of (Typ, Loc);
8421 procedure FA_Rec_Add_Process_Element
8422 (Stmts : List_Id;
8423 Any : Entity_Id;
8424 Counter : in out Int;
8425 Rec : Entity_Id;
8426 Field : Node_Id);
8428 procedure FA_Append_Record_Traversal is
8429 new Append_Record_Traversal
8430 (Rec => Res,
8431 Add_Process_Element => FA_Rec_Add_Process_Element);
8433 --------------------------------
8434 -- FA_Rec_Add_Process_Element --
8435 --------------------------------
8437 procedure FA_Rec_Add_Process_Element
8438 (Stmts : List_Id;
8439 Any : Entity_Id;
8440 Counter : in out Int;
8441 Rec : Entity_Id;
8442 Field : Node_Id)
8444 begin
8445 if Nkind (Field) = N_Defining_Identifier then
8447 -- A regular component
8449 Append_To (Stmts,
8450 Make_Assignment_Statement (Loc,
8451 Name => Make_Selected_Component (Loc,
8452 Prefix =>
8453 New_Occurrence_Of (Rec, Loc),
8454 Selector_Name =>
8455 New_Occurrence_Of (Field, Loc)),
8456 Expression =>
8457 Build_From_Any_Call (Etype (Field),
8458 Build_Get_Aggregate_Element (Loc,
8459 Any => Any,
8460 Tc => Build_TypeCode_Call (Loc,
8461 Etype (Field), Decls),
8462 Idx => Make_Integer_Literal (Loc,
8463 Counter)),
8464 Decls)));
8466 else
8467 -- A variant part
8469 declare
8470 Variant : Node_Id;
8471 Struct_Counter : Int := 0;
8473 Block_Decls : constant List_Id := New_List;
8474 Block_Stmts : constant List_Id := New_List;
8475 VP_Stmts : List_Id;
8477 Alt_List : constant List_Id := New_List;
8478 Choice_List : List_Id;
8480 Struct_Any : constant Entity_Id :=
8481 Make_Defining_Identifier (Loc,
8482 New_Internal_Name ('S'));
8484 begin
8485 Append_To (Decls,
8486 Make_Object_Declaration (Loc,
8487 Defining_Identifier =>
8488 Struct_Any,
8489 Constant_Present =>
8490 True,
8491 Object_Definition =>
8492 New_Occurrence_Of (RTE (RE_Any), Loc),
8493 Expression =>
8494 Make_Function_Call (Loc,
8495 Name => New_Occurrence_Of (
8496 RTE (RE_Extract_Union_Value), Loc),
8497 Parameter_Associations => New_List (
8498 Build_Get_Aggregate_Element (Loc,
8499 Any => Any,
8500 Tc => Make_Function_Call (Loc,
8501 Name => New_Occurrence_Of (
8502 RTE (RE_Any_Member_Type), Loc),
8503 Parameter_Associations =>
8504 New_List (
8505 New_Occurrence_Of (Any, Loc),
8506 Make_Integer_Literal (Loc,
8507 Counter))),
8508 Idx => Make_Integer_Literal (Loc,
8509 Counter))))));
8511 Append_To (Stmts,
8512 Make_Block_Statement (Loc,
8513 Declarations =>
8514 Block_Decls,
8515 Handled_Statement_Sequence =>
8516 Make_Handled_Sequence_Of_Statements (Loc,
8517 Statements => Block_Stmts)));
8519 Append_To (Block_Stmts,
8520 Make_Case_Statement (Loc,
8521 Expression =>
8522 Make_Selected_Component (Loc,
8523 Prefix => Rec,
8524 Selector_Name =>
8525 Chars (Name (Field))),
8526 Alternatives =>
8527 Alt_List));
8529 Variant := First_Non_Pragma (Variants (Field));
8531 while Present (Variant) loop
8532 Choice_List := New_Copy_List_Tree
8533 (Discrete_Choices (Variant));
8535 VP_Stmts := New_List;
8536 FA_Append_Record_Traversal (
8537 Stmts => VP_Stmts,
8538 Clist => Component_List (Variant),
8539 Container => Struct_Any,
8540 Counter => Struct_Counter);
8542 Append_To (Alt_List,
8543 Make_Case_Statement_Alternative (Loc,
8544 Discrete_Choices => Choice_List,
8545 Statements =>
8546 VP_Stmts));
8547 Next_Non_Pragma (Variant);
8548 end loop;
8549 end;
8550 end if;
8551 Counter := Counter + 1;
8552 end FA_Rec_Add_Process_Element;
8554 begin
8555 -- First all discriminants
8557 if Has_Discriminants (Typ) then
8558 Disc := First_Discriminant (Typ);
8559 Discriminant_Associations := New_List;
8561 while Present (Disc) loop
8562 declare
8563 Disc_Var_Name : constant Entity_Id :=
8564 Make_Defining_Identifier (Loc, Chars (Disc));
8565 Disc_Type : constant Entity_Id :=
8566 Etype (Disc);
8567 begin
8568 Append_To (Decls,
8569 Make_Object_Declaration (Loc,
8570 Defining_Identifier =>
8571 Disc_Var_Name,
8572 Constant_Present => True,
8573 Object_Definition =>
8574 New_Occurrence_Of (Disc_Type, Loc),
8575 Expression =>
8576 Build_From_Any_Call (Etype (Disc),
8577 Build_Get_Aggregate_Element (Loc,
8578 Any => Any_Parameter,
8579 Tc => Build_TypeCode_Call
8580 (Loc, Etype (Disc), Decls),
8581 Idx => Make_Integer_Literal
8582 (Loc, Component_Counter)),
8583 Decls)));
8584 Component_Counter := Component_Counter + 1;
8586 Append_To (Discriminant_Associations,
8587 Make_Discriminant_Association (Loc,
8588 Selector_Names => New_List (
8589 New_Occurrence_Of (Disc, Loc)),
8590 Expression =>
8591 New_Occurrence_Of (Disc_Var_Name, Loc)));
8592 end;
8593 Next_Discriminant (Disc);
8594 end loop;
8596 Res_Definition := Make_Subtype_Indication (Loc,
8597 Subtype_Mark => Res_Definition,
8598 Constraint =>
8599 Make_Index_Or_Discriminant_Constraint (Loc,
8600 Discriminant_Associations));
8601 end if;
8603 -- Now we have all the discriminants in variables, we can
8604 -- declared a constrained object. Note that we are not
8605 -- initializing (non-discriminant) components directly in
8606 -- the object declarations, because which fields to
8607 -- initialize depends (at run time) on the discriminant
8608 -- values.
8610 Append_To (Decls,
8611 Make_Object_Declaration (Loc,
8612 Defining_Identifier =>
8613 Res,
8614 Object_Definition =>
8615 Res_Definition));
8617 -- ... then all components
8619 FA_Append_Record_Traversal (Stms,
8620 Clist => Component_List (Rdef),
8621 Container => Any_Parameter,
8622 Counter => Component_Counter);
8624 Append_To (Stms,
8625 Make_Return_Statement (Loc,
8626 Expression => New_Occurrence_Of (Res, Loc)));
8627 end;
8628 end if;
8630 elsif Is_Array_Type (Typ) then
8631 declare
8632 Constrained : constant Boolean := Is_Constrained (Typ);
8634 procedure FA_Ary_Add_Process_Element
8635 (Stmts : List_Id;
8636 Any : Entity_Id;
8637 Counter : Entity_Id;
8638 Datum : Node_Id);
8639 -- Assign the current element (as identified by Counter) of
8640 -- Any to the variable denoted by name Datum, and advance
8641 -- Counter by 1. If Datum is not an Any, a call to From_Any
8642 -- for its type is inserted.
8644 --------------------------------
8645 -- FA_Ary_Add_Process_Element --
8646 --------------------------------
8648 procedure FA_Ary_Add_Process_Element
8649 (Stmts : List_Id;
8650 Any : Entity_Id;
8651 Counter : Entity_Id;
8652 Datum : Node_Id)
8654 Assignment : constant Node_Id :=
8655 Make_Assignment_Statement (Loc,
8656 Name => Datum,
8657 Expression => Empty);
8659 Element_Any : constant Node_Id :=
8660 Build_Get_Aggregate_Element (Loc,
8661 Any => Any,
8662 Tc => Build_TypeCode_Call (Loc,
8663 Etype (Datum), Decls),
8664 Idx => New_Occurrence_Of (Counter, Loc));
8666 begin
8667 -- Note: here we *prepend* statements to Stmts, so
8668 -- we must do it in reverse order.
8670 Prepend_To (Stmts,
8671 Make_Assignment_Statement (Loc,
8672 Name =>
8673 New_Occurrence_Of (Counter, Loc),
8674 Expression =>
8675 Make_Op_Add (Loc,
8676 Left_Opnd =>
8677 New_Occurrence_Of (Counter, Loc),
8678 Right_Opnd =>
8679 Make_Integer_Literal (Loc, 1))));
8681 if Nkind (Datum) /= N_Attribute_Reference then
8683 -- We ignore the value of the length of each
8684 -- dimension, since the target array has already
8685 -- been constrained anyway.
8687 if Etype (Datum) /= RTE (RE_Any) then
8688 Set_Expression (Assignment,
8689 Build_From_Any_Call (
8690 Component_Type (Typ),
8691 Element_Any,
8692 Decls));
8693 else
8694 Set_Expression (Assignment, Element_Any);
8695 end if;
8696 Prepend_To (Stmts, Assignment);
8697 end if;
8698 end FA_Ary_Add_Process_Element;
8700 Counter : constant Entity_Id :=
8701 Make_Defining_Identifier (Loc, Name_J);
8703 Initial_Counter_Value : Int := 0;
8705 Component_TC : constant Entity_Id :=
8706 Make_Defining_Identifier (Loc, Name_T);
8708 Res : constant Entity_Id :=
8709 Make_Defining_Identifier (Loc, Name_R);
8711 procedure Append_From_Any_Array_Iterator is
8712 new Append_Array_Traversal (
8713 Subprogram => Fnam,
8714 Arry => Res,
8715 Indices => New_List,
8716 Add_Process_Element => FA_Ary_Add_Process_Element);
8718 Res_Subtype_Indication : Node_Id :=
8719 New_Occurrence_Of (Typ, Loc);
8721 begin
8722 if not Constrained then
8723 declare
8724 Ndim : constant Int := Number_Dimensions (Typ);
8725 Lnam : Name_Id;
8726 Hnam : Name_Id;
8727 Indx : Node_Id := First_Index (Typ);
8728 Indt : Entity_Id;
8730 Ranges : constant List_Id := New_List;
8732 begin
8733 for J in 1 .. Ndim loop
8734 Lnam := New_External_Name ('L', J);
8735 Hnam := New_External_Name ('H', J);
8736 Indt := Etype (Indx);
8738 Append_To (Decls,
8739 Make_Object_Declaration (Loc,
8740 Defining_Identifier =>
8741 Make_Defining_Identifier (Loc, Lnam),
8742 Constant_Present =>
8743 True,
8744 Object_Definition =>
8745 New_Occurrence_Of (Indt, Loc),
8746 Expression =>
8747 Build_From_Any_Call (
8748 Indt,
8749 Build_Get_Aggregate_Element (Loc,
8750 Any => Any_Parameter,
8751 Tc => Build_TypeCode_Call (Loc,
8752 Indt, Decls),
8753 Idx => Make_Integer_Literal (Loc, J - 1)),
8754 Decls)));
8756 Append_To (Decls,
8757 Make_Object_Declaration (Loc,
8758 Defining_Identifier =>
8759 Make_Defining_Identifier (Loc, Hnam),
8760 Constant_Present =>
8761 True,
8762 Object_Definition =>
8763 New_Occurrence_Of (Indt, Loc),
8764 Expression => Make_Attribute_Reference (Loc,
8765 Prefix =>
8766 New_Occurrence_Of (Indt, Loc),
8767 Attribute_Name => Name_Val,
8768 Expressions => New_List (
8769 Make_Op_Subtract (Loc,
8770 Left_Opnd =>
8771 Make_Op_Add (Loc,
8772 Left_Opnd =>
8773 Make_Attribute_Reference (Loc,
8774 Prefix =>
8775 New_Occurrence_Of (Indt, Loc),
8776 Attribute_Name =>
8777 Name_Pos,
8778 Expressions => New_List (
8779 Make_Identifier (Loc, Lnam))),
8780 Right_Opnd =>
8781 Make_Function_Call (Loc,
8782 Name => New_Occurrence_Of (RTE (
8783 RE_Get_Nested_Sequence_Length),
8784 Loc),
8785 Parameter_Associations =>
8786 New_List (
8787 New_Occurrence_Of (
8788 Any_Parameter, Loc),
8789 Make_Integer_Literal (Loc,
8790 J)))),
8791 Right_Opnd =>
8792 Make_Integer_Literal (Loc, 1))))));
8794 Append_To (Ranges,
8795 Make_Range (Loc,
8796 Low_Bound => Make_Identifier (Loc, Lnam),
8797 High_Bound => Make_Identifier (Loc, Hnam)));
8799 Next_Index (Indx);
8800 end loop;
8802 -- Now we have all the necessary bound information:
8803 -- apply the set of range constraints to the
8804 -- (unconstrained) nominal subtype of Res.
8806 Initial_Counter_Value := Ndim;
8807 Res_Subtype_Indication := Make_Subtype_Indication (Loc,
8808 Subtype_Mark =>
8809 Res_Subtype_Indication,
8810 Constraint =>
8811 Make_Index_Or_Discriminant_Constraint (Loc,
8812 Constraints => Ranges));
8813 end;
8814 end if;
8816 Append_To (Decls,
8817 Make_Object_Declaration (Loc,
8818 Defining_Identifier => Res,
8819 Object_Definition => Res_Subtype_Indication));
8820 Set_Etype (Res, Typ);
8822 Append_To (Decls,
8823 Make_Object_Declaration (Loc,
8824 Defining_Identifier => Counter,
8825 Object_Definition =>
8826 New_Occurrence_Of (RTE (RE_Long_Unsigned), Loc),
8827 Expression =>
8828 Make_Integer_Literal (Loc, Initial_Counter_Value)));
8830 Append_To (Decls,
8831 Make_Object_Declaration (Loc,
8832 Defining_Identifier => Component_TC,
8833 Constant_Present => True,
8834 Object_Definition =>
8835 New_Occurrence_Of (RTE (RE_TypeCode), Loc),
8836 Expression =>
8837 Build_TypeCode_Call (Loc,
8838 Component_Type (Typ), Decls)));
8840 Append_From_Any_Array_Iterator (Stms,
8841 Any_Parameter, Counter);
8843 Append_To (Stms,
8844 Make_Return_Statement (Loc,
8845 Expression => New_Occurrence_Of (Res, Loc)));
8846 end;
8848 elsif Is_Integer_Type (Typ) or else Is_Unsigned_Type (Typ) then
8849 Append_To (Stms,
8850 Make_Return_Statement (Loc,
8851 Expression =>
8852 Unchecked_Convert_To (
8853 Typ,
8854 Build_From_Any_Call (
8855 Find_Numeric_Representation (Typ),
8856 New_Occurrence_Of (Any_Parameter, Loc),
8857 Decls))));
8859 else
8860 -- Default: type is represented as an opaque sequence of bytes
8862 declare
8863 Strm : constant Entity_Id :=
8864 Make_Defining_Identifier (Loc,
8865 Chars => New_Internal_Name ('S'));
8866 Res : constant Entity_Id :=
8867 Make_Defining_Identifier (Loc,
8868 Chars => New_Internal_Name ('R'));
8870 begin
8871 -- Strm : Buffer_Stream_Type;
8873 Append_To (Decls,
8874 Make_Object_Declaration (Loc,
8875 Defining_Identifier =>
8876 Strm,
8877 Aliased_Present =>
8878 True,
8879 Object_Definition =>
8880 New_Occurrence_Of (RTE (RE_Buffer_Stream_Type), Loc)));
8882 -- Any_To_BS (Strm, A);
8884 Append_To (Stms,
8885 Make_Procedure_Call_Statement (Loc,
8886 Name =>
8887 New_Occurrence_Of (RTE (RE_Any_To_BS), Loc),
8888 Parameter_Associations => New_List (
8889 New_Occurrence_Of (Any_Parameter, Loc),
8890 New_Occurrence_Of (Strm, Loc))));
8892 -- declare
8893 -- Res : constant T := T'Input (Strm);
8894 -- begin
8895 -- Release_Buffer (Strm);
8896 -- return Res;
8897 -- end;
8899 Append_To (Stms, Make_Block_Statement (Loc,
8900 Declarations => New_List (
8901 Make_Object_Declaration (Loc,
8902 Defining_Identifier => Res,
8903 Constant_Present => True,
8904 Object_Definition =>
8905 New_Occurrence_Of (Typ, Loc),
8906 Expression =>
8907 Make_Attribute_Reference (Loc,
8908 Prefix => New_Occurrence_Of (Typ, Loc),
8909 Attribute_Name => Name_Input,
8910 Expressions => New_List (
8911 Make_Attribute_Reference (Loc,
8912 Prefix => New_Occurrence_Of (Strm, Loc),
8913 Attribute_Name => Name_Access))))),
8915 Handled_Statement_Sequence =>
8916 Make_Handled_Sequence_Of_Statements (Loc,
8917 Statements => New_List (
8918 Make_Procedure_Call_Statement (Loc,
8919 Name =>
8920 New_Occurrence_Of (RTE (RE_Release_Buffer), Loc),
8921 Parameter_Associations =>
8922 New_List (
8923 New_Occurrence_Of (Strm, Loc))),
8924 Make_Return_Statement (Loc,
8925 Expression => New_Occurrence_Of (Res, Loc))))));
8927 end;
8928 end if;
8930 Decl :=
8931 Make_Subprogram_Body (Loc,
8932 Specification => Spec,
8933 Declarations => Decls,
8934 Handled_Statement_Sequence =>
8935 Make_Handled_Sequence_Of_Statements (Loc,
8936 Statements => Stms));
8937 end Build_From_Any_Function;
8939 ---------------------------------
8940 -- Build_Get_Aggregate_Element --
8941 ---------------------------------
8943 function Build_Get_Aggregate_Element
8944 (Loc : Source_Ptr;
8945 Any : Entity_Id;
8946 TC : Node_Id;
8947 Idx : Node_Id) return Node_Id
8949 begin
8950 return Make_Function_Call (Loc,
8951 Name =>
8952 New_Occurrence_Of (
8953 RTE (RE_Get_Aggregate_Element), Loc),
8954 Parameter_Associations => New_List (
8955 New_Occurrence_Of (Any, Loc),
8957 Idx));
8958 end Build_Get_Aggregate_Element;
8960 -------------------------
8961 -- Build_Reposiroty_Id --
8962 -------------------------
8964 procedure Build_Name_And_Repository_Id
8965 (E : Entity_Id;
8966 Name_Str : out String_Id;
8967 Repo_Id_Str : out String_Id)
8969 begin
8970 Start_String;
8971 Store_String_Chars ("DSA:");
8972 Get_Library_Unit_Name_String (Scope (E));
8973 Store_String_Chars (
8974 Name_Buffer (Name_Buffer'First
8975 .. Name_Buffer'First + Name_Len - 1));
8976 Store_String_Char ('.');
8977 Get_Name_String (Chars (E));
8978 Store_String_Chars (
8979 Name_Buffer (Name_Buffer'First
8980 .. Name_Buffer'First + Name_Len - 1));
8981 Store_String_Chars (":1.0");
8982 Repo_Id_Str := End_String;
8983 Name_Str := String_From_Name_Buffer;
8984 end Build_Name_And_Repository_Id;
8986 -----------------------
8987 -- Build_To_Any_Call --
8988 -----------------------
8990 function Build_To_Any_Call
8991 (N : Node_Id;
8992 Decls : List_Id) return Node_Id
8994 Loc : constant Source_Ptr := Sloc (N);
8996 Typ : Entity_Id := Etype (N);
8997 U_Type : Entity_Id;
8999 Fnam : Entity_Id := Empty;
9000 Lib_RE : RE_Id := RE_Null;
9002 begin
9003 -- If N is a selected component, then maybe its Etype
9004 -- has not been set yet: try to use the Etype of the
9005 -- selector_name in that case.
9007 if No (Typ) and then Nkind (N) = N_Selected_Component then
9008 Typ := Etype (Selector_Name (N));
9009 end if;
9010 pragma Assert (Present (Typ));
9012 -- The full view, if Typ is private; the completion,
9013 -- if Typ is incomplete.
9015 U_Type := Underlying_Type (Typ);
9017 -- First simple case where the To_Any function is present
9018 -- in the type's TSS.
9020 Fnam := Find_Inherited_TSS (U_Type, Name_uTo_Any);
9022 -- Check first for Boolean and Character. These are enumeration
9023 -- types, but we treat them specially, since they may require
9024 -- special handling in the transfer protocol. However, this
9025 -- special handling only applies if they have standard
9026 -- representation, otherwise they are treated like any other
9027 -- enumeration type.
9029 if Sloc (U_Type) <= Standard_Location then
9030 U_Type := Base_Type (U_Type);
9031 end if;
9033 if Present (Fnam) then
9034 null;
9036 elsif U_Type = Standard_Boolean then
9037 Lib_RE := RE_TA_B;
9039 elsif U_Type = Standard_Character then
9040 Lib_RE := RE_TA_C;
9042 elsif U_Type = Standard_Wide_Character then
9043 Lib_RE := RE_TA_WC;
9045 elsif U_Type = Standard_Wide_Wide_Character then
9046 Lib_RE := RE_TA_WWC;
9048 -- Floating point types
9050 elsif U_Type = Standard_Short_Float then
9051 Lib_RE := RE_TA_SF;
9053 elsif U_Type = Standard_Float then
9054 Lib_RE := RE_TA_F;
9056 elsif U_Type = Standard_Long_Float then
9057 Lib_RE := RE_TA_LF;
9059 elsif U_Type = Standard_Long_Long_Float then
9060 Lib_RE := RE_TA_LLF;
9062 -- Integer types
9064 elsif U_Type = Etype (Standard_Short_Short_Integer) then
9065 Lib_RE := RE_TA_SSI;
9067 elsif U_Type = Etype (Standard_Short_Integer) then
9068 Lib_RE := RE_TA_SI;
9070 elsif U_Type = Etype (Standard_Integer) then
9071 Lib_RE := RE_TA_I;
9073 elsif U_Type = Etype (Standard_Long_Integer) then
9074 Lib_RE := RE_TA_LI;
9076 elsif U_Type = Etype (Standard_Long_Long_Integer) then
9077 Lib_RE := RE_TA_LLI;
9079 -- Unsigned integer types
9081 elsif U_Type = RTE (RE_Short_Short_Unsigned) then
9082 Lib_RE := RE_TA_SSU;
9084 elsif U_Type = RTE (RE_Short_Unsigned) then
9085 Lib_RE := RE_TA_SU;
9087 elsif U_Type = RTE (RE_Unsigned) then
9088 Lib_RE := RE_TA_U;
9090 elsif U_Type = RTE (RE_Long_Unsigned) then
9091 Lib_RE := RE_TA_LU;
9093 elsif U_Type = RTE (RE_Long_Long_Unsigned) then
9094 Lib_RE := RE_TA_LLU;
9096 elsif U_Type = Standard_String then
9097 Lib_RE := RE_TA_String;
9099 elsif U_Type = Underlying_Type (RTE (RE_TypeCode)) then
9100 Lib_RE := RE_TA_TC;
9102 -- Other (non-primitive) types
9104 else
9105 declare
9106 Decl : Entity_Id;
9107 begin
9108 Build_To_Any_Function (Loc, U_Type, Decl, Fnam);
9109 Append_To (Decls, Decl);
9110 end;
9111 end if;
9113 -- Call the function
9115 if Lib_RE /= RE_Null then
9116 pragma Assert (No (Fnam));
9117 Fnam := RTE (Lib_RE);
9118 end if;
9120 return
9121 Make_Function_Call (Loc,
9122 Name => New_Occurrence_Of (Fnam, Loc),
9123 Parameter_Associations => New_List (N));
9124 end Build_To_Any_Call;
9126 ---------------------------
9127 -- Build_To_Any_Function --
9128 ---------------------------
9130 procedure Build_To_Any_Function
9131 (Loc : Source_Ptr;
9132 Typ : Entity_Id;
9133 Decl : out Node_Id;
9134 Fnam : out Entity_Id)
9136 Spec : Node_Id;
9137 Decls : constant List_Id := New_List;
9138 Stms : constant List_Id := New_List;
9140 Expr_Parameter : constant Entity_Id :=
9141 Make_Defining_Identifier (Loc, Name_E);
9143 Any : constant Entity_Id :=
9144 Make_Defining_Identifier (Loc, Name_A);
9146 Any_Decl : Node_Id;
9147 Result_TC : Node_Id := Build_TypeCode_Call (Loc, Typ, Decls);
9149 begin
9150 Fnam := Make_Stream_Procedure_Function_Name (Loc,
9151 Typ, Name_uTo_Any);
9153 Spec :=
9154 Make_Function_Specification (Loc,
9155 Defining_Unit_Name => Fnam,
9156 Parameter_Specifications => New_List (
9157 Make_Parameter_Specification (Loc,
9158 Defining_Identifier =>
9159 Expr_Parameter,
9160 Parameter_Type =>
9161 New_Occurrence_Of (Typ, Loc))),
9162 Subtype_Mark => New_Occurrence_Of (RTE (RE_Any), Loc));
9163 Set_Etype (Expr_Parameter, Typ);
9165 Any_Decl :=
9166 Make_Object_Declaration (Loc,
9167 Defining_Identifier =>
9168 Any,
9169 Object_Definition =>
9170 New_Occurrence_Of (RTE (RE_Any), Loc));
9172 if Is_Derived_Type (Typ) and then not Is_Tagged_Type (Typ) then
9173 declare
9174 Rt_Type : constant Entity_Id
9175 := Root_Type (Typ);
9176 Expr : constant Node_Id
9177 := OK_Convert_To (
9178 Rt_Type,
9179 New_Occurrence_Of (Expr_Parameter, Loc));
9180 begin
9181 Set_Expression (Any_Decl, Build_To_Any_Call (Expr, Decls));
9182 end;
9184 elsif Is_Record_Type (Typ) and then not Is_Tagged_Type (Typ) then
9185 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
9186 declare
9187 Rt_Type : constant Entity_Id
9188 := Etype (Typ);
9189 Expr : constant Node_Id
9190 := OK_Convert_To (
9191 Rt_Type,
9192 New_Occurrence_Of (Expr_Parameter, Loc));
9194 begin
9195 Set_Expression (Any_Decl,
9196 Build_To_Any_Call (Expr, Decls));
9197 end;
9199 else
9200 declare
9201 Disc : Entity_Id := Empty;
9202 Rdef : constant Node_Id :=
9203 Type_Definition (Declaration_Node (Typ));
9204 Counter : Int := 0;
9205 Elements : constant List_Id := New_List;
9207 procedure TA_Rec_Add_Process_Element
9208 (Stmts : List_Id;
9209 Container : Node_Or_Entity_Id;
9210 Counter : in out Int;
9211 Rec : Entity_Id;
9212 Field : Node_Id);
9214 procedure TA_Append_Record_Traversal is
9215 new Append_Record_Traversal
9216 (Rec => Expr_Parameter,
9217 Add_Process_Element => TA_Rec_Add_Process_Element);
9219 --------------------------------
9220 -- TA_Rec_Add_Process_Element --
9221 --------------------------------
9223 procedure TA_Rec_Add_Process_Element
9224 (Stmts : List_Id;
9225 Container : Node_Or_Entity_Id;
9226 Counter : in out Int;
9227 Rec : Entity_Id;
9228 Field : Node_Id)
9230 Field_Ref : Node_Id;
9232 begin
9233 if Nkind (Field) = N_Defining_Identifier then
9235 -- A regular component
9237 Field_Ref := Make_Selected_Component (Loc,
9238 Prefix => New_Occurrence_Of (Rec, Loc),
9239 Selector_Name => New_Occurrence_Of (Field, Loc));
9240 Set_Etype (Field_Ref, Etype (Field));
9242 Append_To (Stmts,
9243 Make_Procedure_Call_Statement (Loc,
9244 Name =>
9245 New_Occurrence_Of (
9246 RTE (RE_Add_Aggregate_Element), Loc),
9247 Parameter_Associations => New_List (
9248 New_Occurrence_Of (Any, Loc),
9249 Build_To_Any_Call (Field_Ref, Decls))));
9251 else
9252 -- A variant part
9254 declare
9255 Variant : Node_Id;
9256 Struct_Counter : Int := 0;
9258 Block_Decls : constant List_Id := New_List;
9259 Block_Stmts : constant List_Id := New_List;
9260 VP_Stmts : List_Id;
9262 Alt_List : constant List_Id := New_List;
9263 Choice_List : List_Id;
9265 Union_Any : constant Entity_Id :=
9266 Make_Defining_Identifier (Loc,
9267 New_Internal_Name ('U'));
9269 Struct_Any : constant Entity_Id :=
9270 Make_Defining_Identifier (Loc,
9271 New_Internal_Name ('S'));
9273 function Make_Discriminant_Reference
9274 return Node_Id;
9275 -- Build a selected component for the
9276 -- discriminant of this variant part.
9278 ---------------------------------
9279 -- Make_Discriminant_Reference --
9280 ---------------------------------
9282 function Make_Discriminant_Reference
9283 return Node_Id
9285 Nod : constant Node_Id :=
9286 Make_Selected_Component (Loc,
9287 Prefix => Rec,
9288 Selector_Name =>
9289 Chars (Name (Field)));
9290 begin
9291 Set_Etype (Nod, Name (Field));
9292 return Nod;
9293 end Make_Discriminant_Reference;
9295 begin
9296 Append_To (Stmts,
9297 Make_Block_Statement (Loc,
9298 Declarations =>
9299 Block_Decls,
9300 Handled_Statement_Sequence =>
9301 Make_Handled_Sequence_Of_Statements (Loc,
9302 Statements => Block_Stmts)));
9304 Append_To (Block_Decls,
9305 Make_Object_Declaration (Loc,
9306 Defining_Identifier => Union_Any,
9307 Object_Definition =>
9308 New_Occurrence_Of (RTE (RE_Any), Loc),
9309 Expression =>
9310 Make_Function_Call (Loc,
9311 Name => New_Occurrence_Of (
9312 RTE (RE_Create_Any), Loc),
9313 Parameter_Associations => New_List (
9314 Make_Function_Call (Loc,
9315 Name =>
9316 New_Occurrence_Of (
9317 RTE (RE_Any_Member_Type), Loc),
9318 Parameter_Associations => New_List (
9319 New_Occurrence_Of (Container, Loc),
9320 Make_Integer_Literal (Loc,
9321 Counter)))))));
9323 Append_To (Block_Decls,
9324 Make_Object_Declaration (Loc,
9325 Defining_Identifier => Struct_Any,
9326 Object_Definition =>
9327 New_Occurrence_Of (RTE (RE_Any), Loc),
9328 Expression =>
9329 Make_Function_Call (Loc,
9330 Name => New_Occurrence_Of (
9331 RTE (RE_Create_Any), Loc),
9332 Parameter_Associations => New_List (
9333 Make_Function_Call (Loc,
9334 Name =>
9335 New_Occurrence_Of (
9336 RTE (RE_Any_Member_Type), Loc),
9337 Parameter_Associations => New_List (
9338 New_Occurrence_Of (Union_Any, Loc),
9339 Make_Integer_Literal (Loc,
9340 Uint_0)))))));
9342 Append_To (Block_Stmts,
9343 Make_Case_Statement (Loc,
9344 Expression =>
9345 Make_Discriminant_Reference,
9346 Alternatives =>
9347 Alt_List));
9349 Variant := First_Non_Pragma (Variants (Field));
9350 while Present (Variant) loop
9351 Choice_List := New_Copy_List_Tree
9352 (Discrete_Choices (Variant));
9354 VP_Stmts := New_List;
9355 TA_Append_Record_Traversal (
9356 Stmts => VP_Stmts,
9357 Clist => Component_List (Variant),
9358 Container => Struct_Any,
9359 Counter => Struct_Counter);
9361 -- Append discriminant value and inner struct
9362 -- to union aggregate.
9364 Append_To (VP_Stmts,
9365 Make_Procedure_Call_Statement (Loc,
9366 Name =>
9367 New_Occurrence_Of (
9368 RTE (RE_Add_Aggregate_Element), Loc),
9369 Parameter_Associations => New_List (
9370 New_Occurrence_Of (Union_Any, Loc),
9371 Build_To_Any_Call (
9372 Make_Discriminant_Reference,
9373 Block_Decls))));
9375 Append_To (VP_Stmts,
9376 Make_Procedure_Call_Statement (Loc,
9377 Name =>
9378 New_Occurrence_Of (
9379 RTE (RE_Add_Aggregate_Element), Loc),
9380 Parameter_Associations => New_List (
9381 New_Occurrence_Of (Union_Any, Loc),
9382 New_Occurrence_Of (Struct_Any, Loc))));
9384 -- Append union to outer aggregate
9386 Append_To (VP_Stmts,
9387 Make_Procedure_Call_Statement (Loc,
9388 Name =>
9389 New_Occurrence_Of (
9390 RTE (RE_Add_Aggregate_Element), Loc),
9391 Parameter_Associations => New_List (
9392 New_Occurrence_Of (Container, Loc),
9393 Make_Function_Call (Loc,
9394 Name => New_Occurrence_Of (
9395 RTE (RE_Any_Aggregate_Build), Loc),
9396 Parameter_Associations => New_List (
9397 New_Occurrence_Of (
9398 Union_Any, Loc))))));
9400 Append_To (Alt_List,
9401 Make_Case_Statement_Alternative (Loc,
9402 Discrete_Choices => Choice_List,
9403 Statements =>
9404 VP_Stmts));
9405 Next_Non_Pragma (Variant);
9406 end loop;
9407 end;
9408 end if;
9409 end TA_Rec_Add_Process_Element;
9411 begin
9412 -- First all discriminants
9414 if Has_Discriminants (Typ) then
9415 Disc := First_Discriminant (Typ);
9417 while Present (Disc) loop
9418 Append_To (Elements,
9419 Make_Component_Association (Loc,
9420 Choices => New_List (
9421 Make_Integer_Literal (Loc, Counter)),
9422 Expression =>
9423 Build_To_Any_Call (
9424 Make_Selected_Component (Loc,
9425 Prefix => Expr_Parameter,
9426 Selector_Name => Chars (Disc)),
9427 Decls)));
9428 Counter := Counter + 1;
9429 Next_Discriminant (Disc);
9430 end loop;
9432 else
9433 -- Make elements an empty array
9435 declare
9436 Dummy_Any : constant Entity_Id :=
9437 Make_Defining_Identifier (Loc,
9438 Chars => New_Internal_Name ('A'));
9440 begin
9441 Append_To (Decls,
9442 Make_Object_Declaration (Loc,
9443 Defining_Identifier => Dummy_Any,
9444 Object_Definition =>
9445 New_Occurrence_Of (RTE (RE_Any), Loc)));
9447 Append_To (Elements,
9448 Make_Component_Association (Loc,
9449 Choices => New_List (
9450 Make_Range (Loc,
9451 Low_Bound =>
9452 Make_Integer_Literal (Loc, 1),
9453 High_Bound =>
9454 Make_Integer_Literal (Loc, 0))),
9455 Expression =>
9456 New_Occurrence_Of (Dummy_Any, Loc)));
9457 end;
9458 end if;
9460 Set_Expression (Any_Decl,
9461 Make_Function_Call (Loc,
9462 Name => New_Occurrence_Of (
9463 RTE (RE_Any_Aggregate_Build), Loc),
9464 Parameter_Associations => New_List (
9465 Result_TC,
9466 Make_Aggregate (Loc,
9467 Component_Associations => Elements))));
9468 Result_TC := Empty;
9470 -- ... then all components
9472 TA_Append_Record_Traversal (Stms,
9473 Clist => Component_List (Rdef),
9474 Container => Any,
9475 Counter => Counter);
9476 end;
9477 end if;
9479 elsif Is_Array_Type (Typ) then
9480 declare
9481 Constrained : constant Boolean := Is_Constrained (Typ);
9483 procedure TA_Ary_Add_Process_Element
9484 (Stmts : List_Id;
9485 Any : Entity_Id;
9486 Counter : Entity_Id;
9487 Datum : Node_Id);
9489 --------------------------------
9490 -- TA_Ary_Add_Process_Element --
9491 --------------------------------
9493 procedure TA_Ary_Add_Process_Element
9494 (Stmts : List_Id;
9495 Any : Entity_Id;
9496 Counter : Entity_Id;
9497 Datum : Node_Id)
9499 pragma Warnings (Off);
9500 pragma Unreferenced (Counter);
9501 pragma Warnings (On);
9503 Element_Any : Node_Id;
9505 begin
9506 if Etype (Datum) = RTE (RE_Any) then
9507 Element_Any := Datum;
9508 else
9509 Element_Any := Build_To_Any_Call (Datum, Decls);
9510 end if;
9512 Append_To (Stmts,
9513 Make_Procedure_Call_Statement (Loc,
9514 Name => New_Occurrence_Of (
9515 RTE (RE_Add_Aggregate_Element), Loc),
9516 Parameter_Associations => New_List (
9517 New_Occurrence_Of (Any, Loc),
9518 Element_Any)));
9519 end TA_Ary_Add_Process_Element;
9521 procedure Append_To_Any_Array_Iterator is
9522 new Append_Array_Traversal (
9523 Subprogram => Fnam,
9524 Arry => Expr_Parameter,
9525 Indices => New_List,
9526 Add_Process_Element => TA_Ary_Add_Process_Element);
9528 Index : Node_Id;
9530 begin
9531 Set_Expression (Any_Decl,
9532 Make_Function_Call (Loc,
9533 Name =>
9534 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
9535 Parameter_Associations => New_List (Result_TC)));
9536 Result_TC := Empty;
9538 if not Constrained then
9539 Index := First_Index (Typ);
9540 for J in 1 .. Number_Dimensions (Typ) loop
9541 Append_To (Stms,
9542 Make_Procedure_Call_Statement (Loc,
9543 Name =>
9544 New_Occurrence_Of (
9545 RTE (RE_Add_Aggregate_Element), Loc),
9546 Parameter_Associations => New_List (
9547 New_Occurrence_Of (Any, Loc),
9548 Build_To_Any_Call (
9549 OK_Convert_To (Etype (Index),
9550 Make_Attribute_Reference (Loc,
9551 Prefix =>
9552 New_Occurrence_Of (Expr_Parameter, Loc),
9553 Attribute_Name => Name_First,
9554 Expressions => New_List (
9555 Make_Integer_Literal (Loc, J)))),
9556 Decls))));
9557 Next_Index (Index);
9558 end loop;
9559 end if;
9561 Append_To_Any_Array_Iterator (Stms, Any);
9562 end;
9564 elsif Is_Integer_Type (Typ) or else Is_Unsigned_Type (Typ) then
9565 Set_Expression (Any_Decl,
9566 Build_To_Any_Call (
9567 OK_Convert_To (
9568 Find_Numeric_Representation (Typ),
9569 New_Occurrence_Of (Expr_Parameter, Loc)),
9570 Decls));
9572 else
9573 -- Default: type is represented as an opaque sequence of bytes
9575 declare
9576 Strm : constant Entity_Id := Make_Defining_Identifier (Loc,
9577 New_Internal_Name ('S'));
9579 begin
9580 -- Strm : aliased Buffer_Stream_Type;
9582 Append_To (Decls,
9583 Make_Object_Declaration (Loc,
9584 Defining_Identifier =>
9585 Strm,
9586 Aliased_Present =>
9587 True,
9588 Object_Definition =>
9589 New_Occurrence_Of (RTE (RE_Buffer_Stream_Type), Loc)));
9591 -- Allocate_Buffer (Strm);
9593 Append_To (Stms,
9594 Make_Procedure_Call_Statement (Loc,
9595 Name =>
9596 New_Occurrence_Of (RTE (RE_Allocate_Buffer), Loc),
9597 Parameter_Associations => New_List (
9598 New_Occurrence_Of (Strm, Loc))));
9600 -- T'Output (Strm'Access, E);
9602 Append_To (Stms,
9603 Make_Attribute_Reference (Loc,
9604 Prefix => New_Occurrence_Of (Typ, Loc),
9605 Attribute_Name => Name_Output,
9606 Expressions => New_List (
9607 Make_Attribute_Reference (Loc,
9608 Prefix => New_Occurrence_Of (Strm, Loc),
9609 Attribute_Name => Name_Access),
9610 New_Occurrence_Of (Expr_Parameter, Loc))));
9612 -- BS_To_Any (Strm, A);
9614 Append_To (Stms,
9615 Make_Procedure_Call_Statement (Loc,
9616 Name =>
9617 New_Occurrence_Of (RTE (RE_BS_To_Any), Loc),
9618 Parameter_Associations => New_List (
9619 New_Occurrence_Of (Strm, Loc),
9620 New_Occurrence_Of (Any, Loc))));
9622 -- Release_Buffer (Strm);
9624 Append_To (Stms,
9625 Make_Procedure_Call_Statement (Loc,
9626 Name =>
9627 New_Occurrence_Of (RTE (RE_Release_Buffer), Loc),
9628 Parameter_Associations => New_List (
9629 New_Occurrence_Of (Strm, Loc))));
9630 end;
9631 end if;
9633 Append_To (Decls, Any_Decl);
9635 if Present (Result_TC) then
9636 Append_To (Stms,
9637 Make_Procedure_Call_Statement (Loc,
9638 Name => New_Occurrence_Of (RTE (RE_Set_TC), Loc),
9639 Parameter_Associations => New_List (
9640 New_Occurrence_Of (Any, Loc),
9641 Result_TC)));
9642 end if;
9644 Append_To (Stms,
9645 Make_Return_Statement (Loc,
9646 Expression => New_Occurrence_Of (Any, Loc)));
9648 Decl :=
9649 Make_Subprogram_Body (Loc,
9650 Specification => Spec,
9651 Declarations => Decls,
9652 Handled_Statement_Sequence =>
9653 Make_Handled_Sequence_Of_Statements (Loc,
9654 Statements => Stms));
9655 end Build_To_Any_Function;
9657 -------------------------
9658 -- Build_TypeCode_Call --
9659 -------------------------
9661 function Build_TypeCode_Call
9662 (Loc : Source_Ptr;
9663 Typ : Entity_Id;
9664 Decls : List_Id) return Node_Id
9666 U_Type : Entity_Id := Underlying_Type (Typ);
9667 -- The full view, if Typ is private; the completion,
9668 -- if Typ is incomplete.
9670 Fnam : Entity_Id := Empty;
9671 Tnam : Entity_Id := Empty;
9672 Pnam : Entity_Id := Empty;
9673 Args : List_Id := Empty_List;
9674 Lib_RE : RE_Id := RE_Null;
9676 Expr : Node_Id;
9678 begin
9679 -- Special case System.PolyORB.Interface.Any: its primitives have
9680 -- not been set yet, so can't call Find_Inherited_TSS.
9682 if Typ = RTE (RE_Any) then
9683 Fnam := RTE (RE_TC_Any);
9685 else
9686 -- First simple case where the TypeCode is present
9687 -- in the type's TSS.
9689 Fnam := Find_Inherited_TSS (U_Type, Name_uTypeCode);
9691 if Present (Fnam) then
9693 -- When a TypeCode TSS exists, it has a single parameter
9694 -- that is an anonymous access to the corresponding type.
9695 -- This parameter is not used in any way; its purpose is
9696 -- solely to provide overloading of the TSS.
9698 Tnam :=
9699 Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
9700 Pnam :=
9701 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
9703 Append_To (Decls,
9704 Make_Full_Type_Declaration (Loc,
9705 Defining_Identifier => Tnam,
9706 Type_Definition =>
9707 Make_Access_To_Object_Definition (Loc,
9708 Subtype_Indication =>
9709 New_Occurrence_Of (U_Type, Loc))));
9710 Append_To (Decls,
9711 Make_Object_Declaration (Loc,
9712 Defining_Identifier => Pnam,
9713 Constant_Present => True,
9714 Object_Definition => New_Occurrence_Of (Tnam, Loc),
9716 -- Use a variable here to force proper freezing of Tnam
9718 Expression => Make_Null (Loc)));
9720 -- Normally, calling _TypeCode with a null access parameter
9721 -- should raise Constraint_Error, but this check is
9722 -- suppressed for expanded code, and we do not care anyway
9723 -- because we do not actually ever use this value.
9725 Args := New_List (New_Occurrence_Of (Pnam, Loc));
9726 end if;
9727 end if;
9729 if No (Fnam) then
9730 if Sloc (U_Type) <= Standard_Location then
9732 -- Do not try to build alias typecodes for subtypes from
9733 -- Standard.
9735 U_Type := Base_Type (U_Type);
9736 end if;
9738 if Is_Itype (U_Type) then
9739 return Build_TypeCode_Call
9740 (Loc, Associated_Node_For_Itype (U_Type), Decls);
9741 end if;
9743 if U_Type = Standard_Boolean then
9744 Lib_RE := RE_TC_B;
9746 elsif U_Type = Standard_Character then
9747 Lib_RE := RE_TC_C;
9749 elsif U_Type = Standard_Wide_Character then
9750 Lib_RE := RE_TC_WC;
9752 elsif U_Type = Standard_Wide_Wide_Character then
9753 Lib_RE := RE_TC_WWC;
9755 -- Floating point types
9757 elsif U_Type = Standard_Short_Float then
9758 Lib_RE := RE_TC_SF;
9760 elsif U_Type = Standard_Float then
9761 Lib_RE := RE_TC_F;
9763 elsif U_Type = Standard_Long_Float then
9764 Lib_RE := RE_TC_LF;
9766 elsif U_Type = Standard_Long_Long_Float then
9767 Lib_RE := RE_TC_LLF;
9769 -- Integer types (walk back to the base type)
9771 elsif U_Type = Etype (Standard_Short_Short_Integer) then
9772 Lib_RE := RE_TC_SSI;
9774 elsif U_Type = Etype (Standard_Short_Integer) then
9775 Lib_RE := RE_TC_SI;
9777 elsif U_Type = Etype (Standard_Integer) then
9778 Lib_RE := RE_TC_I;
9780 elsif U_Type = Etype (Standard_Long_Integer) then
9781 Lib_RE := RE_TC_LI;
9783 elsif U_Type = Etype (Standard_Long_Long_Integer) then
9784 Lib_RE := RE_TC_LLI;
9786 -- Unsigned integer types
9788 elsif U_Type = RTE (RE_Short_Short_Unsigned) then
9789 Lib_RE := RE_TC_SSU;
9791 elsif U_Type = RTE (RE_Short_Unsigned) then
9792 Lib_RE := RE_TC_SU;
9794 elsif U_Type = RTE (RE_Unsigned) then
9795 Lib_RE := RE_TC_U;
9797 elsif U_Type = RTE (RE_Long_Unsigned) then
9798 Lib_RE := RE_TC_LU;
9800 elsif U_Type = RTE (RE_Long_Long_Unsigned) then
9801 Lib_RE := RE_TC_LLU;
9803 elsif U_Type = Standard_String then
9804 Lib_RE := RE_TC_String;
9806 -- Other (non-primitive) types
9808 else
9809 declare
9810 Decl : Entity_Id;
9811 begin
9812 Build_TypeCode_Function (Loc, U_Type, Decl, Fnam);
9813 Append_To (Decls, Decl);
9814 end;
9815 end if;
9817 if Lib_RE /= RE_Null then
9818 Fnam := RTE (Lib_RE);
9819 end if;
9820 end if;
9822 -- Call the function
9824 Expr :=
9825 Make_Function_Call (Loc,
9826 Name => New_Occurrence_Of (Fnam, Loc),
9827 Parameter_Associations => Args);
9829 -- Allow Expr to be used as arg to Build_To_Any_Call immediately
9831 Set_Etype (Expr, RTE (RE_TypeCode));
9833 return Expr;
9834 end Build_TypeCode_Call;
9836 -----------------------------
9837 -- Build_TypeCode_Function --
9838 -----------------------------
9840 procedure Build_TypeCode_Function
9841 (Loc : Source_Ptr;
9842 Typ : Entity_Id;
9843 Decl : out Node_Id;
9844 Fnam : out Entity_Id)
9846 Spec : Node_Id;
9847 Decls : constant List_Id := New_List;
9848 Stms : constant List_Id := New_List;
9850 TCNam : constant Entity_Id :=
9851 Make_Stream_Procedure_Function_Name (Loc,
9852 Typ, Name_uTypeCode);
9854 Parameters : List_Id;
9856 procedure Add_String_Parameter
9857 (S : String_Id;
9858 Parameter_List : List_Id);
9859 -- Add a literal for S to Parameters
9861 procedure Add_TypeCode_Parameter
9862 (TC_Node : Node_Id;
9863 Parameter_List : List_Id);
9864 -- Add the typecode for Typ to Parameters
9866 procedure Add_Long_Parameter
9867 (Expr_Node : Node_Id;
9868 Parameter_List : List_Id);
9869 -- Add a signed long integer expression to Parameters
9871 procedure Initialize_Parameter_List
9872 (Name_String : String_Id;
9873 Repo_Id_String : String_Id;
9874 Parameter_List : out List_Id);
9875 -- Return a list that contains the first two parameters
9876 -- for a parameterized typecode: name and repository id.
9878 function Make_Constructed_TypeCode
9879 (Kind : Entity_Id;
9880 Parameters : List_Id) return Node_Id;
9881 -- Call TC_Build with the given kind and parameters
9883 procedure Return_Constructed_TypeCode (Kind : Entity_Id);
9884 -- Make a return statement that calls TC_Build with the given
9885 -- typecode kind, and the constructed parameters list.
9887 procedure Return_Alias_TypeCode (Base_TypeCode : Node_Id);
9888 -- Return a typecode that is a TC_Alias for the given typecode
9890 --------------------------
9891 -- Add_String_Parameter --
9892 --------------------------
9894 procedure Add_String_Parameter
9895 (S : String_Id;
9896 Parameter_List : List_Id)
9898 begin
9899 Append_To (Parameter_List,
9900 Make_Function_Call (Loc,
9901 Name =>
9902 New_Occurrence_Of (RTE (RE_TA_String), Loc),
9903 Parameter_Associations => New_List (
9904 Make_String_Literal (Loc, S))));
9905 end Add_String_Parameter;
9907 ----------------------------
9908 -- Add_TypeCode_Parameter --
9909 ----------------------------
9911 procedure Add_TypeCode_Parameter
9912 (TC_Node : Node_Id;
9913 Parameter_List : List_Id)
9915 begin
9916 Append_To (Parameter_List,
9917 Make_Function_Call (Loc,
9918 Name =>
9919 New_Occurrence_Of (RTE (RE_TA_TC), Loc),
9920 Parameter_Associations => New_List (
9921 TC_Node)));
9922 end Add_TypeCode_Parameter;
9924 ------------------------
9925 -- Add_Long_Parameter --
9926 ------------------------
9928 procedure Add_Long_Parameter
9929 (Expr_Node : Node_Id;
9930 Parameter_List : List_Id)
9932 begin
9933 Append_To (Parameter_List,
9934 Make_Function_Call (Loc,
9935 Name =>
9936 New_Occurrence_Of (RTE (RE_TA_LI), Loc),
9937 Parameter_Associations => New_List (Expr_Node)));
9938 end Add_Long_Parameter;
9940 -------------------------------
9941 -- Initialize_Parameter_List --
9942 -------------------------------
9944 procedure Initialize_Parameter_List
9945 (Name_String : String_Id;
9946 Repo_Id_String : String_Id;
9947 Parameter_List : out List_Id)
9949 begin
9950 Parameter_List := New_List;
9951 Add_String_Parameter (Name_String, Parameter_List);
9952 Add_String_Parameter (Repo_Id_String, Parameter_List);
9953 end Initialize_Parameter_List;
9955 ---------------------------
9956 -- Return_Alias_TypeCode --
9957 ---------------------------
9959 procedure Return_Alias_TypeCode
9960 (Base_TypeCode : Node_Id)
9962 begin
9963 Add_TypeCode_Parameter (Base_TypeCode, Parameters);
9964 Return_Constructed_TypeCode (RTE (RE_TC_Alias));
9965 end Return_Alias_TypeCode;
9967 -------------------------------
9968 -- Make_Constructed_TypeCode --
9969 -------------------------------
9971 function Make_Constructed_TypeCode
9972 (Kind : Entity_Id;
9973 Parameters : List_Id) return Node_Id
9975 Constructed_TC : constant Node_Id :=
9976 Make_Function_Call (Loc,
9977 Name =>
9978 New_Occurrence_Of (RTE (RE_TC_Build), Loc),
9979 Parameter_Associations => New_List (
9980 New_Occurrence_Of (Kind, Loc),
9981 Make_Aggregate (Loc,
9982 Expressions => Parameters)));
9983 begin
9984 Set_Etype (Constructed_TC, RTE (RE_TypeCode));
9985 return Constructed_TC;
9986 end Make_Constructed_TypeCode;
9988 ---------------------------------
9989 -- Return_Constructed_TypeCode --
9990 ---------------------------------
9992 procedure Return_Constructed_TypeCode (Kind : Entity_Id) is
9993 begin
9994 Append_To (Stms,
9995 Make_Return_Statement (Loc,
9996 Expression =>
9997 Make_Constructed_TypeCode (Kind, Parameters)));
9998 end Return_Constructed_TypeCode;
10000 ------------------
10001 -- Record types --
10002 ------------------
10004 procedure TC_Rec_Add_Process_Element
10005 (Params : List_Id;
10006 Any : Entity_Id;
10007 Counter : in out Int;
10008 Rec : Entity_Id;
10009 Field : Node_Id);
10011 procedure TC_Append_Record_Traversal is
10012 new Append_Record_Traversal (
10013 Rec => Empty,
10014 Add_Process_Element => TC_Rec_Add_Process_Element);
10016 --------------------------------
10017 -- TC_Rec_Add_Process_Element --
10018 --------------------------------
10020 procedure TC_Rec_Add_Process_Element
10021 (Params : List_Id;
10022 Any : Entity_Id;
10023 Counter : in out Int;
10024 Rec : Entity_Id;
10025 Field : Node_Id)
10027 pragma Warnings (Off);
10028 pragma Unreferenced (Any, Counter, Rec);
10029 pragma Warnings (On);
10031 begin
10032 if Nkind (Field) = N_Defining_Identifier then
10034 -- A regular component
10036 Add_TypeCode_Parameter (
10037 Build_TypeCode_Call (Loc, Etype (Field), Decls), Params);
10038 Get_Name_String (Chars (Field));
10039 Add_String_Parameter (String_From_Name_Buffer, Params);
10041 else
10043 -- A variant part
10045 declare
10046 Discriminant_Type : constant Entity_Id :=
10047 Etype (Name (Field));
10049 Is_Enum : constant Boolean :=
10050 Is_Enumeration_Type (Discriminant_Type);
10052 Union_TC_Params : List_Id;
10054 U_Name : constant Name_Id :=
10055 New_External_Name (Chars (Typ), 'U', -1);
10057 Name_Str : String_Id;
10058 Struct_TC_Params : List_Id;
10060 Variant : Node_Id;
10061 Choice : Node_Id;
10062 Default : constant Node_Id :=
10063 Make_Integer_Literal (Loc, -1);
10065 Dummy_Counter : Int := 0;
10067 procedure Add_Params_For_Variant_Components;
10068 -- Add a struct TypeCode and a corresponding member name
10069 -- to the union parameter list.
10071 -- Ordering of declarations is a complete mess in this
10072 -- area, it is supposed to be types/varibles, then
10073 -- subprogram specs, then subprogram bodies ???
10075 ---------------------------------------
10076 -- Add_Params_For_Variant_Components --
10077 ---------------------------------------
10079 procedure Add_Params_For_Variant_Components
10081 S_Name : constant Name_Id :=
10082 New_External_Name (U_Name, 'S', -1);
10084 begin
10085 Get_Name_String (S_Name);
10086 Name_Str := String_From_Name_Buffer;
10087 Initialize_Parameter_List
10088 (Name_Str, Name_Str, Struct_TC_Params);
10090 -- Build struct parameters
10092 TC_Append_Record_Traversal (Struct_TC_Params,
10093 Component_List (Variant),
10094 Empty,
10095 Dummy_Counter);
10097 Add_TypeCode_Parameter
10098 (Make_Constructed_TypeCode
10099 (RTE (RE_TC_Struct), Struct_TC_Params),
10100 Union_TC_Params);
10102 Add_String_Parameter (Name_Str, Union_TC_Params);
10103 end Add_Params_For_Variant_Components;
10105 begin
10106 Get_Name_String (U_Name);
10107 Name_Str := String_From_Name_Buffer;
10109 Initialize_Parameter_List
10110 (Name_Str, Name_Str, Union_TC_Params);
10112 Add_String_Parameter (Name_Str, Params);
10114 -- Add union in enclosing parameter list
10116 Add_TypeCode_Parameter
10117 (Make_Constructed_TypeCode
10118 (RTE (RE_TC_Union), Union_TC_Params),
10119 Parameters);
10121 -- Build union parameters
10123 Add_TypeCode_Parameter
10124 (Discriminant_Type, Union_TC_Params);
10125 Add_Long_Parameter (Default, Union_TC_Params);
10127 Variant := First_Non_Pragma (Variants (Field));
10128 while Present (Variant) loop
10129 Choice := First (Discrete_Choices (Variant));
10130 while Present (Choice) loop
10131 case Nkind (Choice) is
10132 when N_Range =>
10133 declare
10134 L : constant Uint :=
10135 Expr_Value (Low_Bound (Choice));
10136 H : constant Uint :=
10137 Expr_Value (High_Bound (Choice));
10138 J : Uint := L;
10139 -- 3.8.1(8) guarantees that the bounds of
10140 -- this range are static.
10142 Expr : Node_Id;
10144 begin
10145 while J <= H loop
10146 if Is_Enum then
10147 Expr := New_Occurrence_Of (
10148 Get_Enum_Lit_From_Pos (
10149 Discriminant_Type, J, Loc), Loc);
10150 else
10151 Expr :=
10152 Make_Integer_Literal (Loc, J);
10153 end if;
10154 Append_To (Union_TC_Params,
10155 Build_To_Any_Call (Expr, Decls));
10156 Add_Params_For_Variant_Components;
10157 J := J + Uint_1;
10158 end loop;
10159 end;
10161 when N_Others_Choice =>
10162 Add_Long_Parameter (
10163 Make_Integer_Literal (Loc, 0),
10164 Union_TC_Params);
10165 Add_Params_For_Variant_Components;
10167 when others =>
10168 Append_To (Union_TC_Params,
10169 Build_To_Any_Call (Choice, Decls));
10170 Add_Params_For_Variant_Components;
10172 end case;
10174 end loop;
10176 Next_Non_Pragma (Variant);
10177 end loop;
10179 end;
10180 end if;
10181 end TC_Rec_Add_Process_Element;
10183 Type_Name_Str : String_Id;
10184 Type_Repo_Id_Str : String_Id;
10186 begin
10187 pragma Assert (not Is_Itype (Typ));
10188 Fnam := TCNam;
10190 Spec :=
10191 Make_Function_Specification (Loc,
10192 Defining_Unit_Name => Fnam,
10193 Parameter_Specifications => Empty_List,
10194 Subtype_Mark => New_Occurrence_Of (RTE (RE_TypeCode), Loc));
10196 Build_Name_And_Repository_Id (Typ,
10197 Name_Str => Type_Name_Str, Repo_Id_Str => Type_Repo_Id_Str);
10198 Initialize_Parameter_List
10199 (Type_Name_Str, Type_Repo_Id_Str, Parameters);
10201 if Is_Derived_Type (Typ)
10202 and then not Is_Tagged_Type (Typ)
10203 then
10204 declare
10205 D_Node : constant Node_Id := Declaration_Node (Typ);
10206 Parent_Type : Entity_Id := Etype (Typ);
10207 begin
10209 if Is_Enumeration_Type (Typ)
10210 and then Nkind (D_Node) = N_Subtype_Declaration
10211 and then Nkind (Original_Node (D_Node))
10212 /= N_Subtype_Declaration
10213 then
10215 -- Parent_Type is the implicit intermediate base type
10216 -- created by Build_Derived_Enumeration_Type.
10218 Parent_Type := Etype (Parent_Type);
10219 end if;
10221 Return_Alias_TypeCode (
10222 Build_TypeCode_Call (Loc, Parent_Type, Decls));
10223 end;
10225 elsif Is_Integer_Type (Typ)
10226 or else Is_Unsigned_Type (Typ)
10227 then
10228 Return_Alias_TypeCode (
10229 Build_TypeCode_Call (Loc,
10230 Find_Numeric_Representation (Typ), Decls));
10232 elsif Is_Record_Type (Typ)
10233 and then not Is_Tagged_Type (Typ)
10234 then
10235 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
10236 Return_Alias_TypeCode (
10237 Build_TypeCode_Call (Loc, Etype (Typ), Decls));
10238 else
10239 declare
10240 Disc : Entity_Id := Empty;
10241 Rdef : constant Node_Id :=
10242 Type_Definition (Declaration_Node (Typ));
10243 Dummy_Counter : Int := 0;
10244 begin
10245 -- First all discriminants
10247 if Has_Discriminants (Typ) then
10248 Disc := First_Discriminant (Typ);
10249 end if;
10250 while Present (Disc) loop
10251 Add_TypeCode_Parameter (
10252 Build_TypeCode_Call (Loc, Etype (Disc), Decls),
10253 Parameters);
10254 Get_Name_String (Chars (Disc));
10255 Add_String_Parameter (
10256 String_From_Name_Buffer,
10257 Parameters);
10258 Next_Discriminant (Disc);
10259 end loop;
10261 -- ... then all components
10263 TC_Append_Record_Traversal
10264 (Parameters, Component_List (Rdef),
10265 Empty, Dummy_Counter);
10266 Return_Constructed_TypeCode (RTE (RE_TC_Struct));
10267 end;
10268 end if;
10270 elsif Is_Array_Type (Typ) then
10271 declare
10272 Ndim : constant Pos := Number_Dimensions (Typ);
10273 Inner_TypeCode : Node_Id;
10274 Constrained : constant Boolean := Is_Constrained (Typ);
10275 Indx : Node_Id := First_Index (Typ);
10277 begin
10278 Inner_TypeCode := Build_TypeCode_Call (Loc,
10279 Component_Type (Typ),
10280 Decls);
10282 for J in 1 .. Ndim loop
10283 if Constrained then
10284 Inner_TypeCode := Make_Constructed_TypeCode
10285 (RTE (RE_TC_Array), New_List (
10286 Build_To_Any_Call (
10287 OK_Convert_To (RTE (RE_Long_Unsigned),
10288 Make_Attribute_Reference (Loc,
10289 Prefix =>
10290 New_Occurrence_Of (Typ, Loc),
10291 Attribute_Name =>
10292 Name_Length,
10293 Expressions => New_List (
10294 Make_Integer_Literal (Loc,
10295 Ndim - J + 1)))),
10296 Decls),
10297 Build_To_Any_Call (Inner_TypeCode, Decls)));
10299 else
10300 -- Unconstrained case: add low bound for each
10301 -- dimension.
10303 Add_TypeCode_Parameter
10304 (Build_TypeCode_Call (Loc, Etype (Indx), Decls),
10305 Parameters);
10306 Get_Name_String (New_External_Name ('L', J));
10307 Add_String_Parameter (
10308 String_From_Name_Buffer,
10309 Parameters);
10310 Next_Index (Indx);
10312 Inner_TypeCode := Make_Constructed_TypeCode
10313 (RTE (RE_TC_Sequence), New_List (
10314 Build_To_Any_Call (
10315 OK_Convert_To (RTE (RE_Long_Unsigned),
10316 Make_Integer_Literal (Loc, 0)),
10317 Decls),
10318 Build_To_Any_Call (Inner_TypeCode, Decls)));
10319 end if;
10320 end loop;
10322 if Constrained then
10323 Return_Alias_TypeCode (Inner_TypeCode);
10324 else
10325 Add_TypeCode_Parameter (Inner_TypeCode, Parameters);
10326 Start_String;
10327 Store_String_Char ('V');
10328 Add_String_Parameter (End_String, Parameters);
10329 Return_Constructed_TypeCode (RTE (RE_TC_Struct));
10330 end if;
10331 end;
10333 else
10334 -- Default: type is represented as an opaque sequence of bytes
10336 Return_Alias_TypeCode
10337 (New_Occurrence_Of (RTE (RE_TC_Opaque), Loc));
10338 end if;
10340 Decl :=
10341 Make_Subprogram_Body (Loc,
10342 Specification => Spec,
10343 Declarations => Decls,
10344 Handled_Statement_Sequence =>
10345 Make_Handled_Sequence_Of_Statements (Loc,
10346 Statements => Stms));
10347 end Build_TypeCode_Function;
10349 ------------------------
10350 -- Find_Inherited_TSS --
10351 ------------------------
10353 function Find_Inherited_TSS
10354 (Typ : Entity_Id;
10355 Nam : Name_Id) return Entity_Id
10357 P_Type : Entity_Id := Typ;
10358 Proc : Entity_Id;
10360 begin
10361 Proc := TSS (Base_Type (Typ), Nam);
10363 -- Check first if there is a TSS given for the type itself
10365 if Present (Proc) then
10366 return Proc;
10367 end if;
10369 -- If Typ is a derived type, it may inherit attributes from some
10370 -- ancestor which is not the ultimate underlying one. If Typ is a
10371 -- derived tagged type, The corresponding primitive operation has
10372 -- been created explicitly.
10374 if Is_Derived_Type (P_Type) then
10375 if Is_Tagged_Type (P_Type) then
10376 return Find_Prim_Op (P_Type, Nam);
10377 else
10378 while Is_Derived_Type (P_Type) loop
10379 Proc := TSS (Base_Type (Etype (Typ)), Nam);
10381 if Present (Proc) then
10382 return Proc;
10383 else
10384 P_Type := Base_Type (Etype (P_Type));
10385 end if;
10386 end loop;
10387 end if;
10388 end if;
10390 -- If nothing else, use the TSS of the root type
10392 return TSS (Base_Type (Underlying_Type (Typ)), Nam);
10393 end Find_Inherited_TSS;
10395 ---------------------------------
10396 -- Find_Numeric_Representation --
10397 ---------------------------------
10399 function Find_Numeric_Representation (Typ : Entity_Id)
10400 return Entity_Id
10402 FST : constant Entity_Id := First_Subtype (Typ);
10403 P_Size : constant Uint := Esize (FST);
10405 begin
10406 if Is_Unsigned_Type (Typ) then
10407 if P_Size <= Standard_Short_Short_Integer_Size then
10408 return RTE (RE_Short_Short_Unsigned);
10410 elsif P_Size <= Standard_Short_Integer_Size then
10411 return RTE (RE_Short_Unsigned);
10413 elsif P_Size <= Standard_Integer_Size then
10414 return RTE (RE_Unsigned);
10416 elsif P_Size <= Standard_Long_Integer_Size then
10417 return RTE (RE_Long_Unsigned);
10419 else
10420 return RTE (RE_Long_Long_Unsigned);
10421 end if;
10423 elsif Is_Integer_Type (Typ) then
10424 if P_Size <= Standard_Short_Short_Integer_Size then
10425 return Standard_Short_Short_Integer;
10427 elsif P_Size <= Standard_Short_Integer_Size then
10428 return Standard_Short_Integer;
10430 elsif P_Size <= Standard_Integer_Size then
10431 return Standard_Integer;
10433 elsif P_Size <= Standard_Long_Integer_Size then
10434 return Standard_Long_Integer;
10436 else
10437 return Standard_Long_Long_Integer;
10438 end if;
10440 elsif Is_Floating_Point_Type (Typ) then
10441 if P_Size <= Standard_Short_Float_Size then
10442 return Standard_Short_Float;
10444 elsif P_Size <= Standard_Float_Size then
10445 return Standard_Float;
10447 elsif P_Size <= Standard_Long_Float_Size then
10448 return Standard_Long_Float;
10450 else
10451 return Standard_Long_Long_Float;
10452 end if;
10454 else
10455 raise Program_Error;
10456 end if;
10458 -- TBD: fixed point types???
10459 -- TBverified numeric types with a biased representation???
10461 end Find_Numeric_Representation;
10463 ---------------------------
10464 -- Append_Array_Traversal --
10465 ---------------------------
10467 procedure Append_Array_Traversal
10468 (Stmts : List_Id;
10469 Any : Entity_Id;
10470 Counter : Entity_Id := Empty;
10471 Depth : Pos := 1)
10473 Loc : constant Source_Ptr := Sloc (Subprogram);
10474 Typ : constant Entity_Id := Etype (Arry);
10475 Constrained : constant Boolean := Is_Constrained (Typ);
10476 Ndim : constant Pos := Number_Dimensions (Typ);
10478 Inner_Any, Inner_Counter : Entity_Id;
10480 Loop_Stm : Node_Id;
10481 Inner_Stmts : constant List_Id := New_List;
10483 begin
10484 if Depth > Ndim then
10486 -- Processing for one element of an array
10488 declare
10489 Element_Expr : constant Node_Id :=
10490 Make_Indexed_Component (Loc,
10491 New_Occurrence_Of (Arry, Loc),
10492 Indices);
10494 begin
10495 Set_Etype (Element_Expr, Component_Type (Typ));
10496 Add_Process_Element (Stmts,
10497 Any => Any,
10498 Counter => Counter,
10499 Datum => Element_Expr);
10500 end;
10502 return;
10503 end if;
10505 Append_To (Indices,
10506 Make_Identifier (Loc, New_External_Name ('L', Depth)));
10508 if Constrained then
10509 Inner_Any := Any;
10510 Inner_Counter := Counter;
10511 else
10512 Inner_Any := Make_Defining_Identifier (Loc,
10513 New_External_Name ('A', Depth));
10514 Set_Etype (Inner_Any, RTE (RE_Any));
10516 if Present (Counter) then
10517 Inner_Counter := Make_Defining_Identifier (Loc,
10518 New_External_Name ('J', Depth));
10519 else
10520 Inner_Counter := Empty;
10521 end if;
10522 end if;
10524 Append_Array_Traversal (Inner_Stmts,
10525 Any => Inner_Any,
10526 Counter => Inner_Counter,
10527 Depth => Depth + 1);
10529 Loop_Stm :=
10530 Make_Implicit_Loop_Statement (Subprogram,
10531 Iteration_Scheme =>
10532 Make_Iteration_Scheme (Loc,
10533 Loop_Parameter_Specification =>
10534 Make_Loop_Parameter_Specification (Loc,
10535 Defining_Identifier =>
10536 Make_Defining_Identifier (Loc,
10537 Chars => New_External_Name ('L', Depth)),
10539 Discrete_Subtype_Definition =>
10540 Make_Attribute_Reference (Loc,
10541 Prefix => New_Occurrence_Of (Arry, Loc),
10542 Attribute_Name => Name_Range,
10544 Expressions => New_List (
10545 Make_Integer_Literal (Loc, Depth))))),
10546 Statements => Inner_Stmts);
10548 if Constrained then
10549 Append_To (Stmts, Loop_Stm);
10550 return;
10551 end if;
10553 declare
10554 Decls : constant List_Id := New_List;
10555 Dimen_Stmts : constant List_Id := New_List;
10556 Length_Node : Node_Id;
10558 Inner_Any_TypeCode : constant Entity_Id :=
10559 Make_Defining_Identifier (Loc,
10560 New_External_Name ('T', Depth));
10562 Inner_Any_TypeCode_Expr : Node_Id;
10564 begin
10565 if Depth = 1 then
10566 Inner_Any_TypeCode_Expr :=
10567 Make_Function_Call (Loc,
10568 Name =>
10569 New_Occurrence_Of (RTE (RE_Any_Member_Type), Loc),
10570 Parameter_Associations => New_List (
10571 New_Occurrence_Of (Any, Loc),
10572 Make_Integer_Literal (Loc, Ndim)));
10573 else
10574 Inner_Any_TypeCode_Expr :=
10575 Make_Function_Call (Loc,
10576 Name =>
10577 New_Occurrence_Of (RTE (RE_Content_Type), Loc),
10578 Parameter_Associations => New_List (
10579 Make_Identifier (Loc,
10580 New_External_Name ('T', Depth - 1))));
10581 end if;
10583 Append_To (Decls,
10584 Make_Object_Declaration (Loc,
10585 Defining_Identifier => Inner_Any_TypeCode,
10586 Constant_Present => True,
10587 Object_Definition => New_Occurrence_Of (
10588 RTE (RE_TypeCode), Loc),
10589 Expression => Inner_Any_TypeCode_Expr));
10590 Append_To (Decls,
10591 Make_Object_Declaration (Loc,
10592 Defining_Identifier => Inner_Any,
10593 Object_Definition =>
10594 New_Occurrence_Of (RTE (RE_Any), Loc),
10595 Expression =>
10596 Make_Function_Call (Loc,
10597 Name =>
10598 New_Occurrence_Of (
10599 RTE (RE_Create_Any), Loc),
10600 Parameter_Associations => New_List (
10601 New_Occurrence_Of (Inner_Any_TypeCode, Loc)))));
10603 if Present (Inner_Counter) then
10604 Append_To (Decls,
10605 Make_Object_Declaration (Loc,
10606 Defining_Identifier => Inner_Counter,
10607 Object_Definition =>
10608 New_Occurrence_Of (RTE (RE_Long_Unsigned), Loc),
10609 Expression =>
10610 Make_Integer_Literal (Loc, 0)));
10611 end if;
10613 Length_Node := Make_Attribute_Reference (Loc,
10614 Prefix => New_Occurrence_Of (Arry, Loc),
10615 Attribute_Name => Name_Length,
10616 Expressions =>
10617 New_List (Make_Integer_Literal (Loc, Depth)));
10618 Set_Etype (Length_Node, RTE (RE_Long_Unsigned));
10620 Add_Process_Element (Dimen_Stmts,
10621 Datum => Length_Node,
10622 Any => Inner_Any,
10623 Counter => Inner_Counter);
10625 -- Loop_Stm does approrpriate processing for each element
10626 -- of Inner_Any.
10628 Append_To (Dimen_Stmts, Loop_Stm);
10630 -- Link outer and inner any
10632 Add_Process_Element (Dimen_Stmts,
10633 Any => Any,
10634 Counter => Counter,
10635 Datum => New_Occurrence_Of (Inner_Any, Loc));
10638 Append_To (Stmts,
10639 Make_Block_Statement (Loc,
10640 Declarations =>
10641 Decls,
10642 Handled_Statement_Sequence =>
10643 Make_Handled_Sequence_Of_Statements (Loc,
10644 Statements => Dimen_Stmts)));
10645 end;
10646 end Append_Array_Traversal;
10648 -----------------------------------------
10649 -- Make_Stream_Procedure_Function_Name --
10650 -----------------------------------------
10652 function Make_Stream_Procedure_Function_Name
10653 (Loc : Source_Ptr;
10654 Typ : Entity_Id;
10655 Nam : Name_Id) return Entity_Id
10657 begin
10658 -- For tagged types, we use a canonical name so that it matches
10659 -- the primitive spec. For all other cases, we use a serialized
10660 -- name so that multiple generations of the same procedure do not
10661 -- clash.
10663 if Is_Tagged_Type (Typ) then
10664 return Make_Defining_Identifier (Loc, Nam);
10665 else
10666 return Make_Defining_Identifier (Loc,
10667 Chars =>
10668 New_External_Name (Nam, ' ', Increment_Serial_Number));
10669 end if;
10670 end Make_Stream_Procedure_Function_Name;
10671 end Helpers;
10673 -----------------------------------
10674 -- Reserve_NamingContext_Methods --
10675 -----------------------------------
10677 procedure Reserve_NamingContext_Methods is
10678 Str_Resolve : constant String := "resolve";
10679 begin
10680 Name_Buffer (1 .. Str_Resolve'Length) := Str_Resolve;
10681 Name_Len := Str_Resolve'Length;
10682 Overload_Counter_Table.Set (Name_Find, 1);
10683 end Reserve_NamingContext_Methods;
10685 end PolyORB_Support;
10687 -------------------------------
10688 -- RACW_Type_Is_Asynchronous --
10689 -------------------------------
10691 procedure RACW_Type_Is_Asynchronous (RACW_Type : Entity_Id) is
10692 Asynchronous_Flag : constant Entity_Id :=
10693 Asynchronous_Flags_Table.Get (RACW_Type);
10694 begin
10695 Replace (Expression (Parent (Asynchronous_Flag)),
10696 New_Occurrence_Of (Standard_True, Sloc (Asynchronous_Flag)));
10697 end RACW_Type_Is_Asynchronous;
10699 -------------------------
10700 -- RCI_Package_Locator --
10701 -------------------------
10703 function RCI_Package_Locator
10704 (Loc : Source_Ptr;
10705 Package_Spec : Node_Id) return Node_Id
10707 Inst : Node_Id;
10708 Pkg_Name : String_Id;
10710 begin
10711 Get_Library_Unit_Name_String (Package_Spec);
10712 Pkg_Name := String_From_Name_Buffer;
10713 Inst :=
10714 Make_Package_Instantiation (Loc,
10715 Defining_Unit_Name =>
10716 Make_Defining_Identifier (Loc, New_Internal_Name ('R')),
10717 Name =>
10718 New_Occurrence_Of (RTE (RE_RCI_Locator), Loc),
10719 Generic_Associations => New_List (
10720 Make_Generic_Association (Loc,
10721 Selector_Name =>
10722 Make_Identifier (Loc, Name_RCI_Name),
10723 Explicit_Generic_Actual_Parameter =>
10724 Make_String_Literal (Loc,
10725 Strval => Pkg_Name))));
10727 RCI_Locator_Table.Set (Defining_Unit_Name (Package_Spec),
10728 Defining_Unit_Name (Inst));
10729 return Inst;
10730 end RCI_Package_Locator;
10732 -----------------------------------------------
10733 -- Remote_Types_Tagged_Full_View_Encountered --
10734 -----------------------------------------------
10736 procedure Remote_Types_Tagged_Full_View_Encountered
10737 (Full_View : Entity_Id)
10739 Stub_Elements : constant Stub_Structure :=
10740 Stubs_Table.Get (Full_View);
10741 begin
10742 if Stub_Elements /= Empty_Stub_Structure then
10743 Add_RACW_Primitive_Declarations_And_Bodies
10744 (Full_View,
10745 Stub_Elements.RPC_Receiver_Decl,
10746 List_Containing (Declaration_Node (Full_View)));
10747 end if;
10748 end Remote_Types_Tagged_Full_View_Encountered;
10750 -------------------
10751 -- Scope_Of_Spec --
10752 -------------------
10754 function Scope_Of_Spec (Spec : Node_Id) return Entity_Id is
10755 Unit_Name : Node_Id := Defining_Unit_Name (Spec);
10757 begin
10758 while Nkind (Unit_Name) /= N_Defining_Identifier loop
10759 Unit_Name := Defining_Identifier (Unit_Name);
10760 end loop;
10762 return Unit_Name;
10763 end Scope_Of_Spec;
10765 ----------------------
10766 -- Set_Renaming_TSS --
10767 ----------------------
10769 procedure Set_Renaming_TSS
10770 (Typ : Entity_Id;
10771 Nam : Entity_Id;
10772 TSS_Nam : Name_Id)
10774 Loc : constant Source_Ptr := Sloc (Nam);
10775 Spec : constant Node_Id := Parent (Nam);
10777 TSS_Node : constant Node_Id :=
10778 Make_Subprogram_Renaming_Declaration (Loc,
10779 Specification =>
10780 Copy_Specification (Loc,
10781 Spec => Spec,
10782 New_Name => TSS_Nam),
10783 Name => New_Occurrence_Of (Nam, Loc));
10785 Snam : constant Entity_Id :=
10786 Defining_Unit_Name (Specification (TSS_Node));
10788 begin
10789 if Nkind (Spec) = N_Function_Specification then
10790 Set_Ekind (Snam, E_Function);
10791 Set_Etype (Snam, Entity (Subtype_Mark (Spec)));
10792 else
10793 Set_Ekind (Snam, E_Procedure);
10794 Set_Etype (Snam, Standard_Void_Type);
10795 end if;
10797 Set_TSS (Typ, Snam);
10798 end Set_Renaming_TSS;
10800 ----------------------------------------------
10801 -- Specific_Add_Obj_RPC_Receiver_Completion --
10802 ----------------------------------------------
10804 procedure Specific_Add_Obj_RPC_Receiver_Completion
10805 (Loc : Source_Ptr;
10806 Decls : List_Id;
10807 RPC_Receiver : Entity_Id;
10808 Stub_Elements : Stub_Structure) is
10809 begin
10810 case Get_PCS_Name is
10811 when Name_PolyORB_DSA =>
10812 PolyORB_Support.Add_Obj_RPC_Receiver_Completion (Loc,
10813 Decls, RPC_Receiver, Stub_Elements);
10814 when others =>
10815 GARLIC_Support.Add_Obj_RPC_Receiver_Completion (Loc,
10816 Decls, RPC_Receiver, Stub_Elements);
10817 end case;
10818 end Specific_Add_Obj_RPC_Receiver_Completion;
10820 --------------------------------
10821 -- Specific_Add_RACW_Features --
10822 --------------------------------
10824 procedure Specific_Add_RACW_Features
10825 (RACW_Type : Entity_Id;
10826 Desig : Entity_Id;
10827 Stub_Type : Entity_Id;
10828 Stub_Type_Access : Entity_Id;
10829 RPC_Receiver_Decl : Node_Id;
10830 Declarations : List_Id) is
10831 begin
10832 case Get_PCS_Name is
10833 when Name_PolyORB_DSA =>
10834 PolyORB_Support.Add_RACW_Features (
10835 RACW_Type,
10836 Desig,
10837 Stub_Type,
10838 Stub_Type_Access,
10839 RPC_Receiver_Decl,
10840 Declarations);
10842 when others =>
10843 GARLIC_Support.Add_RACW_Features (
10844 RACW_Type,
10845 Stub_Type,
10846 Stub_Type_Access,
10847 RPC_Receiver_Decl,
10848 Declarations);
10849 end case;
10850 end Specific_Add_RACW_Features;
10852 --------------------------------
10853 -- Specific_Add_RAST_Features --
10854 --------------------------------
10856 procedure Specific_Add_RAST_Features
10857 (Vis_Decl : Node_Id;
10858 RAS_Type : Entity_Id;
10859 Decls : List_Id)
10861 begin
10862 case Get_PCS_Name is
10863 when Name_PolyORB_DSA =>
10864 PolyORB_Support.Add_RAST_Features (
10865 Vis_Decl, RAS_Type, Decls);
10866 when others =>
10867 GARLIC_Support.Add_RAST_Features (
10868 Vis_Decl, RAS_Type, Decls);
10869 end case;
10870 end Specific_Add_RAST_Features;
10872 --------------------------------------------------
10873 -- Specific_Add_Receiving_Stubs_To_Declarations --
10874 --------------------------------------------------
10876 procedure Specific_Add_Receiving_Stubs_To_Declarations
10877 (Pkg_Spec : Node_Id;
10878 Decls : List_Id)
10880 begin
10881 case Get_PCS_Name is
10882 when Name_PolyORB_DSA =>
10883 PolyORB_Support.Add_Receiving_Stubs_To_Declarations (
10884 Pkg_Spec, Decls);
10885 when others =>
10886 GARLIC_Support.Add_Receiving_Stubs_To_Declarations (
10887 Pkg_Spec, Decls);
10888 end case;
10889 end Specific_Add_Receiving_Stubs_To_Declarations;
10891 ------------------------------------------
10892 -- Specific_Build_General_Calling_Stubs --
10893 ------------------------------------------
10895 procedure Specific_Build_General_Calling_Stubs
10896 (Decls : List_Id;
10897 Statements : List_Id;
10898 Target : RPC_Target;
10899 Subprogram_Id : Node_Id;
10900 Asynchronous : Node_Id := Empty;
10901 Is_Known_Asynchronous : Boolean := False;
10902 Is_Known_Non_Asynchronous : Boolean := False;
10903 Is_Function : Boolean;
10904 Spec : Node_Id;
10905 Stub_Type : Entity_Id := Empty;
10906 RACW_Type : Entity_Id := Empty;
10907 Nod : Node_Id)
10909 begin
10910 case Get_PCS_Name is
10911 when Name_PolyORB_DSA =>
10912 PolyORB_Support.Build_General_Calling_Stubs (
10913 Decls,
10914 Statements,
10915 Target.Object,
10916 Subprogram_Id,
10917 Asynchronous,
10918 Is_Known_Asynchronous,
10919 Is_Known_Non_Asynchronous,
10920 Is_Function,
10921 Spec,
10922 Stub_Type,
10923 RACW_Type,
10924 Nod);
10925 when others =>
10926 GARLIC_Support.Build_General_Calling_Stubs (
10927 Decls,
10928 Statements,
10929 Target.Partition,
10930 Target.RPC_Receiver,
10931 Subprogram_Id,
10932 Asynchronous,
10933 Is_Known_Asynchronous,
10934 Is_Known_Non_Asynchronous,
10935 Is_Function,
10936 Spec,
10937 Stub_Type,
10938 RACW_Type,
10939 Nod);
10940 end case;
10941 end Specific_Build_General_Calling_Stubs;
10943 --------------------------------------
10944 -- Specific_Build_RPC_Receiver_Body --
10945 --------------------------------------
10947 procedure Specific_Build_RPC_Receiver_Body
10948 (RPC_Receiver : Entity_Id;
10949 Request : out Entity_Id;
10950 Subp_Id : out Entity_Id;
10951 Subp_Index : out Entity_Id;
10952 Stmts : out List_Id;
10953 Decl : out Node_Id)
10955 begin
10956 case Get_PCS_Name is
10957 when Name_PolyORB_DSA =>
10958 PolyORB_Support.Build_RPC_Receiver_Body
10959 (RPC_Receiver,
10960 Request,
10961 Subp_Id,
10962 Subp_Index,
10963 Stmts,
10964 Decl);
10965 when others =>
10966 GARLIC_Support.Build_RPC_Receiver_Body
10967 (RPC_Receiver,
10968 Request,
10969 Subp_Id,
10970 Subp_Index,
10971 Stmts,
10972 Decl);
10973 end case;
10974 end Specific_Build_RPC_Receiver_Body;
10976 --------------------------------
10977 -- Specific_Build_Stub_Target --
10978 --------------------------------
10980 function Specific_Build_Stub_Target
10981 (Loc : Source_Ptr;
10982 Decls : List_Id;
10983 RCI_Locator : Entity_Id;
10984 Controlling_Parameter : Entity_Id) return RPC_Target is
10985 begin
10986 case Get_PCS_Name is
10987 when Name_PolyORB_DSA =>
10988 return PolyORB_Support.Build_Stub_Target (Loc,
10989 Decls, RCI_Locator, Controlling_Parameter);
10990 when others =>
10991 return GARLIC_Support.Build_Stub_Target (Loc,
10992 Decls, RCI_Locator, Controlling_Parameter);
10993 end case;
10994 end Specific_Build_Stub_Target;
10996 ------------------------------
10997 -- Specific_Build_Stub_Type --
10998 ------------------------------
11000 procedure Specific_Build_Stub_Type
11001 (RACW_Type : Entity_Id;
11002 Stub_Type : Entity_Id;
11003 Stub_Type_Decl : out Node_Id;
11004 RPC_Receiver_Decl : out Node_Id)
11006 begin
11007 case Get_PCS_Name is
11008 when Name_PolyORB_DSA =>
11009 PolyORB_Support.Build_Stub_Type (
11010 RACW_Type, Stub_Type,
11011 Stub_Type_Decl, RPC_Receiver_Decl);
11012 when others =>
11013 GARLIC_Support.Build_Stub_Type (
11014 RACW_Type, Stub_Type,
11015 Stub_Type_Decl, RPC_Receiver_Decl);
11016 end case;
11017 end Specific_Build_Stub_Type;
11019 function Specific_Build_Subprogram_Receiving_Stubs
11020 (Vis_Decl : Node_Id;
11021 Asynchronous : Boolean;
11022 Dynamically_Asynchronous : Boolean := False;
11023 Stub_Type : Entity_Id := Empty;
11024 RACW_Type : Entity_Id := Empty;
11025 Parent_Primitive : Entity_Id := Empty) return Node_Id is
11026 begin
11027 case Get_PCS_Name is
11028 when Name_PolyORB_DSA =>
11029 return PolyORB_Support.Build_Subprogram_Receiving_Stubs (
11030 Vis_Decl,
11031 Asynchronous,
11032 Dynamically_Asynchronous,
11033 Stub_Type,
11034 RACW_Type,
11035 Parent_Primitive);
11036 when others =>
11037 return GARLIC_Support.Build_Subprogram_Receiving_Stubs (
11038 Vis_Decl,
11039 Asynchronous,
11040 Dynamically_Asynchronous,
11041 Stub_Type,
11042 RACW_Type,
11043 Parent_Primitive);
11044 end case;
11045 end Specific_Build_Subprogram_Receiving_Stubs;
11047 --------------------------
11048 -- Underlying_RACW_Type --
11049 --------------------------
11051 function Underlying_RACW_Type (RAS_Typ : Entity_Id) return Entity_Id is
11052 Record_Type : Entity_Id;
11054 begin
11055 if Ekind (RAS_Typ) = E_Record_Type then
11056 Record_Type := RAS_Typ;
11057 else
11058 pragma Assert (Present (Equivalent_Type (RAS_Typ)));
11059 Record_Type := Equivalent_Type (RAS_Typ);
11060 end if;
11062 return
11063 Etype (Subtype_Indication (
11064 Component_Definition (
11065 First (Component_Items (Component_List (
11066 Type_Definition (Declaration_Node (Record_Type))))))));
11067 end Underlying_RACW_Type;
11069 end Exp_Dist;