* gcc.dg/pr26570.c: Clean up coverage files.
[official-gcc.git] / gcc / ada / exp_dist.adb
blob7e79bfb0448f228c1661ca1984b016f61eedc8e4
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-2006, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Lib; use Lib;
34 with Namet; use Namet;
35 with Nlists; use Nlists;
36 with Nmake; use Nmake;
37 with Opt; use Opt;
38 with Rtsfind; use Rtsfind;
39 with Sem; use Sem;
40 with Sem_Cat; use Sem_Cat;
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 with GNAT.HTable; use GNAT.HTable;
56 package body Exp_Dist is
58 -- The following model has been used to implement distributed objects:
59 -- given a designated type D and a RACW type R, then a record of the
60 -- form:
62 -- type Stub is tagged record
63 -- [...declaration similar to s-parint.ads RACW_Stub_Type...]
64 -- end record;
66 -- is built. This type has two properties:
68 -- 1) Since it has the same structure than RACW_Stub_Type, it can be
69 -- converted to and from this type to make it suitable for
70 -- System.Partition_Interface.Get_Unique_Remote_Pointer in order
71 -- to avoid memory leaks when the same remote object arrive on the
72 -- same partition through several paths;
74 -- 2) It also has the same dispatching table as the designated type D,
75 -- and thus can be used as an object designated by a value of type
76 -- R on any partition other than the one on which the object has
77 -- been created, since only dispatching calls will be performed and
78 -- the fields themselves will not be used. We call Derive_Subprograms
79 -- to fake half a derivation to ensure that the subprograms do have
80 -- the same dispatching table.
82 First_RCI_Subprogram_Id : constant := 2;
83 -- RCI subprograms are numbered starting at 2. The RCI receiver for
84 -- an RCI package can thus identify calls received through remote
85 -- access-to-subprogram dereferences by the fact that they have a
86 -- (primitive) subprogram id of 0, and 1 is used for the internal
87 -- RAS information lookup operation. (This is for the Garlic code
88 -- generation, where subprograms are identified by numbers; in the
89 -- PolyORB version, they are identified by name, with a numeric suffix
90 -- for homonyms.)
92 type Hash_Index is range 0 .. 50;
94 -----------------------
95 -- Local subprograms --
96 -----------------------
98 function Hash (F : Entity_Id) return Hash_Index;
99 -- DSA expansion associates stubs to distributed object types using
100 -- a hash table on entity ids.
102 function Hash (F : Name_Id) return Hash_Index;
103 -- The generation of subprogram identifiers requires an overload counter
104 -- to be associated with each remote subprogram names. These counters
105 -- are maintained in a hash table on name ids.
107 type Subprogram_Identifiers is record
108 Str_Identifier : String_Id;
109 Int_Identifier : Int;
110 end record;
112 package Subprogram_Identifier_Table is
113 new Simple_HTable (Header_Num => Hash_Index,
114 Element => Subprogram_Identifiers,
115 No_Element => (No_String, 0),
116 Key => Entity_Id,
117 Hash => Hash,
118 Equal => "=");
119 -- Mapping between a remote subprogram and the corresponding
120 -- subprogram identifiers.
122 package Overload_Counter_Table is
123 new Simple_HTable (Header_Num => Hash_Index,
124 Element => Int,
125 No_Element => 0,
126 Key => Name_Id,
127 Hash => Hash,
128 Equal => "=");
129 -- Mapping between a subprogram name and an integer that
130 -- counts the number of defining subprogram names with that
131 -- Name_Id encountered so far in a given context (an interface).
133 function Get_Subprogram_Ids (Def : Entity_Id) return Subprogram_Identifiers;
134 function Get_Subprogram_Id (Def : Entity_Id) return String_Id;
135 function Get_Subprogram_Id (Def : Entity_Id) return Int;
136 -- Given a subprogram defined in a RCI package, get its distribution
137 -- subprogram identifiers (the distribution identifiers are a unique
138 -- subprogram number, and the non-qualified subprogram name, in the
139 -- casing used for the subprogram declaration; if the name is overloaded,
140 -- a double underscore and a serial number are appended.
142 -- The integer identifier is used to perform remote calls with GARLIC;
143 -- the string identifier is used in the case of PolyORB.
145 -- Although the PolyORB DSA receiving stubs will make a caseless comparison
146 -- when receiving a call, the calling stubs will create requests with the
147 -- exact casing of the defining unit name of the called subprogram, so as
148 -- to allow calls to subprograms on distributed nodes that do distinguish
149 -- between casings.
151 -- NOTE: Another design would be to allow a representation clause on
152 -- subprogram specs: for Subp'Distribution_Identifier use "fooBar";
154 pragma Warnings (Off, Get_Subprogram_Id);
155 -- One homonym only is unreferenced (specific to the GARLIC version)
157 procedure Add_RAS_Dereference_TSS (N : Node_Id);
158 -- Add a subprogram body for RAS Dereference TSS
160 procedure Add_RAS_Proxy_And_Analyze
161 (Decls : List_Id;
162 Vis_Decl : Node_Id;
163 All_Calls_Remote_E : Entity_Id;
164 Proxy_Object_Addr : out Entity_Id);
165 -- Add the proxy type necessary to call the subprogram declared
166 -- by Vis_Decl through a remote access to subprogram type.
167 -- All_Calls_Remote_E must be Standard_True if a pragma All_Calls_Remote
168 -- applies, Standard_False otherwise. The new proxy type is appended
169 -- to Decls. Proxy_Object_Addr is a constant of type System.Address that
170 -- designates an instance of the proxy object.
172 function Build_Remote_Subprogram_Proxy_Type
173 (Loc : Source_Ptr;
174 ACR_Expression : Node_Id) return Node_Id;
175 -- Build and return a tagged record type definition for an RCI
176 -- subprogram proxy type.
177 -- ACR_Expression is use as the initialization value for
178 -- the All_Calls_Remote component.
180 function Build_Get_Unique_RP_Call
181 (Loc : Source_Ptr;
182 Pointer : Entity_Id;
183 Stub_Type : Entity_Id) return List_Id;
184 -- Build a call to Get_Unique_Remote_Pointer (Pointer), followed by a
185 -- tag fixup (Get_Unique_Remote_Pointer may have changed Pointer'Tag to
186 -- RACW_Stub_Type'Tag, while the desired tag is that of Stub_Type).
188 function Build_Subprogram_Calling_Stubs
189 (Vis_Decl : Node_Id;
190 Subp_Id : Node_Id;
191 Asynchronous : Boolean;
192 Dynamically_Asynchronous : Boolean := False;
193 Stub_Type : Entity_Id := Empty;
194 RACW_Type : Entity_Id := Empty;
195 Locator : Entity_Id := Empty;
196 New_Name : Name_Id := No_Name) return Node_Id;
197 -- Build the calling stub for a given subprogram with the subprogram ID
198 -- being Subp_Id. If Stub_Type is given, then the "addr" field of
199 -- parameters of this type will be marshalled instead of the object
200 -- itself. It will then be converted into Stub_Type before performing
201 -- the real call. If Dynamically_Asynchronous is True, then it will be
202 -- computed at run time whether the call is asynchronous or not.
203 -- Otherwise, the value of the formal Asynchronous will be used.
204 -- If Locator is not Empty, it will be used instead of RCI_Cache. If
205 -- New_Name is given, then it will be used instead of the original name.
207 function Build_RPC_Receiver_Specification
208 (RPC_Receiver : Entity_Id;
209 Request_Parameter : Entity_Id) return Node_Id;
210 -- Make a subprogram specification for an RPC receiver, with the given
211 -- defining unit name and formal parameter.
213 function Build_Ordered_Parameters_List (Spec : Node_Id) return List_Id;
214 -- Return an ordered parameter list: unconstrained parameters are put
215 -- at the beginning of the list and constrained ones are put after. If
216 -- there are no parameters, an empty list is returned. Special case:
217 -- the controlling formal of the equivalent RACW operation for a RAS
218 -- type is always left in first position.
220 procedure Add_Calling_Stubs_To_Declarations
221 (Pkg_Spec : Node_Id;
222 Decls : List_Id);
223 -- Add calling stubs to the declarative part
225 function Could_Be_Asynchronous (Spec : Node_Id) return Boolean;
226 -- Return True if nothing prevents the program whose specification is
227 -- given to be asynchronous (i.e. no out parameter).
229 function Pack_Entity_Into_Stream_Access
230 (Loc : Source_Ptr;
231 Stream : Node_Id;
232 Object : Entity_Id;
233 Etyp : Entity_Id := Empty) return Node_Id;
234 -- Pack Object (of type Etyp) into Stream. If Etyp is not given,
235 -- then Etype (Object) will be used if present. If the type is
236 -- constrained, then 'Write will be used to output the object,
237 -- If the type is unconstrained, 'Output will be used.
239 function Pack_Node_Into_Stream
240 (Loc : Source_Ptr;
241 Stream : Entity_Id;
242 Object : Node_Id;
243 Etyp : Entity_Id) return Node_Id;
244 -- Similar to above, with an arbitrary node instead of an entity
246 function Pack_Node_Into_Stream_Access
247 (Loc : Source_Ptr;
248 Stream : Node_Id;
249 Object : Node_Id;
250 Etyp : Entity_Id) return Node_Id;
251 -- Similar to above, with Stream instead of Stream'Access
253 function Make_Selected_Component
254 (Loc : Source_Ptr;
255 Prefix : Entity_Id;
256 Selector_Name : Name_Id) return Node_Id;
257 -- Return a selected_component whose prefix denotes the given entity,
258 -- and with the given Selector_Name.
260 function Scope_Of_Spec (Spec : Node_Id) return Entity_Id;
261 -- Return the scope represented by a given spec
263 procedure Set_Renaming_TSS
264 (Typ : Entity_Id;
265 Nam : Entity_Id;
266 TSS_Nam : TSS_Name_Type);
267 -- Create a renaming declaration of subprogram Nam,
268 -- and register it as a TSS for Typ with name TSS_Nam.
270 function Need_Extra_Constrained (Parameter : Node_Id) return Boolean;
271 -- Return True if the current parameter needs an extra formal to reflect
272 -- its constrained status.
274 function Is_RACW_Controlling_Formal
275 (Parameter : Node_Id;
276 Stub_Type : Entity_Id) return Boolean;
277 -- Return True if the current parameter is a controlling formal argument
278 -- of type Stub_Type or access to Stub_Type.
280 procedure Declare_Create_NVList
281 (Loc : Source_Ptr;
282 NVList : Entity_Id;
283 Decls : List_Id;
284 Stmts : List_Id);
285 -- Append the declaration of NVList to Decls, and its
286 -- initialization to Stmts.
288 function Add_Parameter_To_NVList
289 (Loc : Source_Ptr;
290 NVList : Entity_Id;
291 Parameter : Entity_Id;
292 Constrained : Boolean;
293 RACW_Ctrl : Boolean := False;
294 Any : Entity_Id) return Node_Id;
295 -- Return a call to Add_Item to add the Any corresponding
296 -- to the designated formal Parameter (with the indicated
297 -- Constrained status) to NVList. RACW_Ctrl must be set to
298 -- True for controlling formals of distributed object primitive
299 -- operations.
301 type Stub_Structure is record
302 Stub_Type : Entity_Id;
303 Stub_Type_Access : Entity_Id;
304 RPC_Receiver_Decl : Node_Id;
305 RACW_Type : Entity_Id;
306 end record;
307 -- This structure is necessary because of the two phases analysis of
308 -- a RACW declaration occurring in the same Remote_Types package as the
309 -- designated type. RACW_Type is any of the RACW types pointing on this
310 -- designated type, it is used here to save an anonymous type creation
311 -- for each primitive operation.
313 -- For a RACW that implements a RAS, no object RPC receiver is generated.
314 -- Instead, RPC_Receiver_Decl is the declaration after which the
315 -- RPC receiver would have been inserted.
317 Empty_Stub_Structure : constant Stub_Structure :=
318 (Empty, Empty, Empty, Empty);
320 package Stubs_Table is
321 new Simple_HTable (Header_Num => Hash_Index,
322 Element => Stub_Structure,
323 No_Element => Empty_Stub_Structure,
324 Key => Entity_Id,
325 Hash => Hash,
326 Equal => "=");
327 -- Mapping between a RACW designated type and its stub type
329 package Asynchronous_Flags_Table is
330 new Simple_HTable (Header_Num => Hash_Index,
331 Element => Entity_Id,
332 No_Element => Empty,
333 Key => Entity_Id,
334 Hash => Hash,
335 Equal => "=");
336 -- Mapping between a RACW type and a constant having the value True
337 -- if the RACW is asynchronous and False otherwise.
339 package RCI_Locator_Table is
340 new Simple_HTable (Header_Num => Hash_Index,
341 Element => Entity_Id,
342 No_Element => Empty,
343 Key => Entity_Id,
344 Hash => Hash,
345 Equal => "=");
346 -- Mapping between a RCI package on which All_Calls_Remote applies and
347 -- the generic instantiation of RCI_Locator for this package.
349 package RCI_Calling_Stubs_Table is
350 new Simple_HTable (Header_Num => Hash_Index,
351 Element => Entity_Id,
352 No_Element => Empty,
353 Key => Entity_Id,
354 Hash => Hash,
355 Equal => "=");
356 -- Mapping between a RCI subprogram and the corresponding calling stubs
358 procedure Add_Stub_Type
359 (Designated_Type : Entity_Id;
360 RACW_Type : Entity_Id;
361 Decls : List_Id;
362 Stub_Type : out Entity_Id;
363 Stub_Type_Access : out Entity_Id;
364 RPC_Receiver_Decl : out Node_Id;
365 Existing : out Boolean);
366 -- Add the declaration of the stub type, the access to stub type and the
367 -- object RPC receiver at the end of Decls. If these already exist,
368 -- then nothing is added in the tree but the right values are returned
369 -- anyhow and Existing is set to True.
371 procedure Add_RACW_Asynchronous_Flag
372 (Declarations : List_Id;
373 RACW_Type : Entity_Id);
374 -- Declare a boolean constant associated with RACW_Type whose value
375 -- indicates at run time whether a pragma Asynchronous applies to it.
377 procedure Assign_Subprogram_Identifier
378 (Def : Entity_Id;
379 Spn : Int;
380 Id : out String_Id);
381 -- Determine the distribution subprogram identifier to
382 -- be used for remote subprogram Def, return it in Id and
383 -- store it in a hash table for later retrieval by
384 -- Get_Subprogram_Id. Spn is the subprogram number.
386 function RCI_Package_Locator
387 (Loc : Source_Ptr;
388 Package_Spec : Node_Id) return Node_Id;
389 -- Instantiate the generic package RCI_Locator in order to locate the
390 -- RCI package whose spec is given as argument.
392 function Make_Tag_Check (Loc : Source_Ptr; N : Node_Id) return Node_Id;
393 -- Surround a node N by a tag check, as in:
394 -- begin
395 -- <N>;
396 -- exception
397 -- when E : Ada.Tags.Tag_Error =>
398 -- Raise_Exception (Program_Error'Identity,
399 -- Exception_Message (E));
400 -- end;
402 function Input_With_Tag_Check
403 (Loc : Source_Ptr;
404 Var_Type : Entity_Id;
405 Stream : Node_Id) return Node_Id;
406 -- Return a function with the following form:
407 -- function R return Var_Type is
408 -- begin
409 -- return Var_Type'Input (S);
410 -- exception
411 -- when E : Ada.Tags.Tag_Error =>
412 -- Raise_Exception (Program_Error'Identity,
413 -- Exception_Message (E));
414 -- end R;
416 --------------------------------------------
417 -- Hooks for PCS-specific code generation --
418 --------------------------------------------
420 -- Part of the code generation circuitry for distribution needs to be
421 -- tailored for each implementation of the PCS. For each routine that
422 -- needs to be specialized, a Specific_<routine> wrapper is created,
423 -- which calls the corresponding <routine> in package
424 -- <pcs_implementation>_Support.
426 procedure Specific_Add_RACW_Features
427 (RACW_Type : Entity_Id;
428 Desig : Entity_Id;
429 Stub_Type : Entity_Id;
430 Stub_Type_Access : Entity_Id;
431 RPC_Receiver_Decl : Node_Id;
432 Declarations : List_Id);
433 -- Add declaration for TSSs for a given RACW type. The declarations are
434 -- added just after the declaration of the RACW type itself, while the
435 -- bodies are inserted at the end of Decls. Runtime-specific ancillary
436 -- subprogram for Add_RACW_Features.
438 procedure Specific_Add_RAST_Features
439 (Vis_Decl : Node_Id;
440 RAS_Type : Entity_Id);
441 -- Add declaration for TSSs for a given RAS type. PCS-specific ancillary
442 -- subprogram for Add_RAST_Features.
444 -- An RPC_Target record is used during construction of calling stubs
445 -- to pass PCS-specific tree fragments corresponding to the information
446 -- necessary to locate the target of a remote subprogram call.
448 type RPC_Target (PCS_Kind : PCS_Names) is record
449 case PCS_Kind is
450 when Name_PolyORB_DSA =>
451 Object : Node_Id;
452 -- An expression whose value is a PolyORB reference to the target
453 -- object.
454 when others =>
455 Partition : Entity_Id;
456 -- A variable containing the Partition_ID of the target parition
458 RPC_Receiver : Node_Id;
459 -- An expression whose value is the address of the target RPC
460 -- receiver.
461 end case;
462 end record;
464 procedure Specific_Build_General_Calling_Stubs
465 (Decls : List_Id;
466 Statements : List_Id;
467 Target : RPC_Target;
468 Subprogram_Id : Node_Id;
469 Asynchronous : Node_Id := Empty;
470 Is_Known_Asynchronous : Boolean := False;
471 Is_Known_Non_Asynchronous : Boolean := False;
472 Is_Function : Boolean;
473 Spec : Node_Id;
474 Stub_Type : Entity_Id := Empty;
475 RACW_Type : Entity_Id := Empty;
476 Nod : Node_Id);
477 -- Build calling stubs for general purpose. The parameters are:
478 -- Decls : a place to put declarations
479 -- Statements : a place to put statements
480 -- Target : PCS-specific target information (see details
481 -- in RPC_Target declaration).
482 -- Subprogram_Id : a node containing the subprogram ID
483 -- Asynchronous : True if an APC must be made instead of an RPC.
484 -- The value needs not be supplied if one of the
485 -- Is_Known_... is True.
486 -- Is_Known_Async... : True if we know that this is asynchronous
487 -- Is_Known_Non_A... : True if we know that this is not asynchronous
488 -- Spec : a node with a Parameter_Specifications and
489 -- a Result_Definition if applicable
490 -- Stub_Type : in case of RACW stubs, parameters of type access
491 -- to Stub_Type will be marshalled using the
492 -- address of the object (the addr field) rather
493 -- than using the 'Write on the stub itself
494 -- Nod : used to provide sloc for generated code
496 function Specific_Build_Stub_Target
497 (Loc : Source_Ptr;
498 Decls : List_Id;
499 RCI_Locator : Entity_Id;
500 Controlling_Parameter : Entity_Id) return RPC_Target;
501 -- Build call target information nodes for use within calling stubs. In the
502 -- RCI case, RCI_Locator is the entity for the instance of RCI_Locator. If
503 -- for an RACW, Controlling_Parameter is the entity for the controlling
504 -- formal parameter used to determine the location of the target of the
505 -- call. Decls provides a location where variable declarations can be
506 -- appended to construct the necessary values.
508 procedure Specific_Build_Stub_Type
509 (RACW_Type : Entity_Id;
510 Stub_Type : Entity_Id;
511 Stub_Type_Decl : out Node_Id;
512 RPC_Receiver_Decl : out Node_Id);
513 -- Build a type declaration for the stub type associated with an RACW
514 -- type, and the necessary RPC receiver, if applicable. PCS-specific
515 -- ancillary subprogram for Add_Stub_Type. If no RPC receiver declaration
516 -- is generated, then RPC_Receiver_Decl is set to Empty.
518 procedure Specific_Build_RPC_Receiver_Body
519 (RPC_Receiver : Entity_Id;
520 Request : out Entity_Id;
521 Subp_Id : out Entity_Id;
522 Subp_Index : out Entity_Id;
523 Stmts : out List_Id;
524 Decl : out Node_Id);
525 -- Make a subprogram body for an RPC receiver, with the given
526 -- defining unit name. On return:
527 -- - Subp_Id is the subprogram identifier from the PCS.
528 -- - Subp_Index is the index in the list of subprograms
529 -- used for dispatching (a variable of type Subprogram_Id).
530 -- - Stmts is the place where the request dispatching
531 -- statements can occur,
532 -- - Decl is the subprogram body declaration.
534 function Specific_Build_Subprogram_Receiving_Stubs
535 (Vis_Decl : Node_Id;
536 Asynchronous : Boolean;
537 Dynamically_Asynchronous : Boolean := False;
538 Stub_Type : Entity_Id := Empty;
539 RACW_Type : Entity_Id := Empty;
540 Parent_Primitive : Entity_Id := Empty) return Node_Id;
541 -- Build the receiving stub for a given subprogram. The subprogram
542 -- declaration is also built by this procedure, and the value returned
543 -- is a N_Subprogram_Body. If a parameter of type access to Stub_Type is
544 -- found in the specification, then its address is read from the stream
545 -- instead of the object itself and converted into an access to
546 -- class-wide type before doing the real call using any of the RACW type
547 -- pointing on the designated type.
549 procedure Specific_Add_Obj_RPC_Receiver_Completion
550 (Loc : Source_Ptr;
551 Decls : List_Id;
552 RPC_Receiver : Entity_Id;
553 Stub_Elements : Stub_Structure);
554 -- Add the necessary code to Decls after the completion of generation
555 -- of the RACW RPC receiver described by Stub_Elements.
557 procedure Specific_Add_Receiving_Stubs_To_Declarations
558 (Pkg_Spec : Node_Id;
559 Decls : List_Id);
560 -- Add receiving stubs to the declarative part of an RCI unit
562 package GARLIC_Support is
564 -- Support for generating DSA code that uses the GARLIC PCS
566 -- The subprograms below provide the GARLIC versions of
567 -- the corresponding Specific_<subprogram> routine declared
568 -- above.
570 procedure Add_RACW_Features
571 (RACW_Type : Entity_Id;
572 Stub_Type : Entity_Id;
573 Stub_Type_Access : Entity_Id;
574 RPC_Receiver_Decl : Node_Id;
575 Declarations : List_Id);
577 procedure Add_RAST_Features
578 (Vis_Decl : Node_Id;
579 RAS_Type : Entity_Id);
581 procedure Build_General_Calling_Stubs
582 (Decls : List_Id;
583 Statements : List_Id;
584 Target_Partition : Entity_Id; -- From RPC_Target
585 Target_RPC_Receiver : Node_Id; -- From RPC_Target
586 Subprogram_Id : Node_Id;
587 Asynchronous : Node_Id := Empty;
588 Is_Known_Asynchronous : Boolean := False;
589 Is_Known_Non_Asynchronous : Boolean := False;
590 Is_Function : Boolean;
591 Spec : Node_Id;
592 Stub_Type : Entity_Id := Empty;
593 RACW_Type : Entity_Id := Empty;
594 Nod : Node_Id);
596 function Build_Stub_Target
597 (Loc : Source_Ptr;
598 Decls : List_Id;
599 RCI_Locator : Entity_Id;
600 Controlling_Parameter : Entity_Id) return RPC_Target;
602 procedure Build_Stub_Type
603 (RACW_Type : Entity_Id;
604 Stub_Type : Entity_Id;
605 Stub_Type_Decl : out Node_Id;
606 RPC_Receiver_Decl : out Node_Id);
608 function Build_Subprogram_Receiving_Stubs
609 (Vis_Decl : Node_Id;
610 Asynchronous : Boolean;
611 Dynamically_Asynchronous : Boolean := False;
612 Stub_Type : Entity_Id := Empty;
613 RACW_Type : Entity_Id := Empty;
614 Parent_Primitive : Entity_Id := Empty) return Node_Id;
616 procedure Add_Obj_RPC_Receiver_Completion
617 (Loc : Source_Ptr;
618 Decls : List_Id;
619 RPC_Receiver : Entity_Id;
620 Stub_Elements : Stub_Structure);
622 procedure Add_Receiving_Stubs_To_Declarations
623 (Pkg_Spec : Node_Id;
624 Decls : List_Id);
626 procedure Build_RPC_Receiver_Body
627 (RPC_Receiver : Entity_Id;
628 Request : out Entity_Id;
629 Subp_Id : out Entity_Id;
630 Subp_Index : out Entity_Id;
631 Stmts : out List_Id;
632 Decl : out Node_Id);
634 end GARLIC_Support;
636 package PolyORB_Support is
638 -- Support for generating DSA code that uses the PolyORB PCS
640 -- The subprograms below provide the PolyORB versions of
641 -- the corresponding Specific_<subprogram> routine declared
642 -- above.
644 procedure Add_RACW_Features
645 (RACW_Type : Entity_Id;
646 Desig : Entity_Id;
647 Stub_Type : Entity_Id;
648 Stub_Type_Access : Entity_Id;
649 RPC_Receiver_Decl : Node_Id;
650 Declarations : List_Id);
652 procedure Add_RAST_Features
653 (Vis_Decl : Node_Id;
654 RAS_Type : Entity_Id);
656 procedure Build_General_Calling_Stubs
657 (Decls : List_Id;
658 Statements : List_Id;
659 Target_Object : Node_Id; -- From RPC_Target
660 Subprogram_Id : Node_Id;
661 Asynchronous : Node_Id := Empty;
662 Is_Known_Asynchronous : Boolean := False;
663 Is_Known_Non_Asynchronous : Boolean := False;
664 Is_Function : Boolean;
665 Spec : Node_Id;
666 Stub_Type : Entity_Id := Empty;
667 RACW_Type : Entity_Id := Empty;
668 Nod : Node_Id);
670 function Build_Stub_Target
671 (Loc : Source_Ptr;
672 Decls : List_Id;
673 RCI_Locator : Entity_Id;
674 Controlling_Parameter : Entity_Id) return RPC_Target;
676 procedure Build_Stub_Type
677 (RACW_Type : Entity_Id;
678 Stub_Type : Entity_Id;
679 Stub_Type_Decl : out Node_Id;
680 RPC_Receiver_Decl : out Node_Id);
682 function Build_Subprogram_Receiving_Stubs
683 (Vis_Decl : Node_Id;
684 Asynchronous : Boolean;
685 Dynamically_Asynchronous : Boolean := False;
686 Stub_Type : Entity_Id := Empty;
687 RACW_Type : Entity_Id := Empty;
688 Parent_Primitive : Entity_Id := Empty) return Node_Id;
690 procedure Add_Obj_RPC_Receiver_Completion
691 (Loc : Source_Ptr;
692 Decls : List_Id;
693 RPC_Receiver : Entity_Id;
694 Stub_Elements : Stub_Structure);
696 procedure Add_Receiving_Stubs_To_Declarations
697 (Pkg_Spec : Node_Id;
698 Decls : List_Id);
700 procedure Build_RPC_Receiver_Body
701 (RPC_Receiver : Entity_Id;
702 Request : out Entity_Id;
703 Subp_Id : out Entity_Id;
704 Subp_Index : out Entity_Id;
705 Stmts : out List_Id;
706 Decl : out Node_Id);
708 procedure Reserve_NamingContext_Methods;
709 -- Mark the method names for interface NamingContext as already used in
710 -- the overload table, so no clashes occur with user code (with the
711 -- PolyORB PCS, RCIs Implement The NamingContext interface to allow
712 -- their methods to be accessed as objects, for the implementation of
713 -- remote access-to-subprogram types).
715 package Helpers is
717 -- Routines to build distribtion helper subprograms for user-defined
718 -- types. For implementation of the Distributed systems annex (DSA)
719 -- over the PolyORB generic middleware components, it is necessary to
720 -- generate several supporting subprograms for each application data
721 -- type used in inter-partition communication. These subprograms are:
722 -- * a Typecode function returning a high-level description of the
723 -- type's structure;
724 -- * two conversion functions allowing conversion of values of the
725 -- type from and to the generic data containers used by PolyORB.
726 -- These generic containers are called 'Any' type values after
727 -- the CORBA terminology, and hence the conversion subprograms
728 -- are named To_Any and From_Any.
730 function Build_From_Any_Call
731 (Typ : Entity_Id;
732 N : Node_Id;
733 Decls : List_Id) return Node_Id;
734 -- Build call to From_Any attribute function of type Typ with
735 -- expression N as actual parameter. Decls is the declarations list
736 -- for an appropriate enclosing scope of the point where the call
737 -- will be inserted; if the From_Any attribute for Typ needs to be
738 -- generated at this point, its declaration is appended to Decls.
740 procedure Build_From_Any_Function
741 (Loc : Source_Ptr;
742 Typ : Entity_Id;
743 Decl : out Node_Id;
744 Fnam : out Entity_Id);
745 -- Build From_Any attribute function for Typ. Loc is the reference
746 -- location for generated nodes, Typ is the type for which the
747 -- conversion function is generated. On return, Decl and Fnam contain
748 -- the declaration and entity for the newly-created function.
750 function Build_To_Any_Call
751 (N : Node_Id;
752 Decls : List_Id) return Node_Id;
753 -- Build call to To_Any attribute function with expression as actual
754 -- parameter. Decls is the declarations list for an appropriate
755 -- enclosing scope of the point where the call will be inserted; if
756 -- the To_Any attribute for Typ needs to be generated at this point,
757 -- its declaration is appended to Decls.
759 procedure Build_To_Any_Function
760 (Loc : Source_Ptr;
761 Typ : Entity_Id;
762 Decl : out Node_Id;
763 Fnam : out Entity_Id);
764 -- Build To_Any attribute function for Typ. Loc is the reference
765 -- location for generated nodes, Typ is the type for which the
766 -- conversion function is generated. On return, Decl and Fnam contain
767 -- the declaration and entity for the newly-created function.
769 function Build_TypeCode_Call
770 (Loc : Source_Ptr;
771 Typ : Entity_Id;
772 Decls : List_Id) return Node_Id;
773 -- Build call to TypeCode attribute function for Typ. Decls is the
774 -- declarations list for an appropriate enclosing scope of the point
775 -- where the call will be inserted; if the To_Any attribute for Typ
776 -- needs to be generated at this point, its declaration is appended
777 -- to Decls.
779 procedure Build_TypeCode_Function
780 (Loc : Source_Ptr;
781 Typ : Entity_Id;
782 Decl : out Node_Id;
783 Fnam : out Entity_Id);
784 -- Build TypeCode attribute function for Typ. Loc is the reference
785 -- location for generated nodes, Typ is the type for which the
786 -- conversion function is generated. On return, Decl and Fnam contain
787 -- the declaration and entity for the newly-created function.
789 procedure Build_Name_And_Repository_Id
790 (E : Entity_Id;
791 Name_Str : out String_Id;
792 Repo_Id_Str : out String_Id);
793 -- In the PolyORB distribution model, each distributed object type
794 -- and each distributed operation has a globally unique identifier,
795 -- its Repository Id. This subprogram builds and returns two strings
796 -- for entity E (a distributed object type or operation): one
797 -- containing the name of E, the second containing its repository id.
799 end Helpers;
801 end PolyORB_Support;
803 ------------------------------------
804 -- Local variables and structures --
805 ------------------------------------
807 RCI_Cache : Node_Id;
808 -- Needs comments ???
810 Output_From_Constrained : constant array (Boolean) of Name_Id :=
811 (False => Name_Output,
812 True => Name_Write);
813 -- The attribute to choose depending on the fact that the parameter
814 -- is constrained or not. There is no such thing as Input_From_Constrained
815 -- since this require separate mechanisms ('Input is a function while
816 -- 'Read is a procedure).
818 ---------------------------------------
819 -- Add_Calling_Stubs_To_Declarations --
820 ---------------------------------------
822 procedure Add_Calling_Stubs_To_Declarations
823 (Pkg_Spec : Node_Id;
824 Decls : List_Id)
826 Current_Subprogram_Number : Int := First_RCI_Subprogram_Id;
827 -- Subprogram id 0 is reserved for calls received from
828 -- remote access-to-subprogram dereferences.
830 Current_Declaration : Node_Id;
831 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
832 RCI_Instantiation : Node_Id;
833 Subp_Stubs : Node_Id;
834 Subp_Str : String_Id;
836 begin
837 -- The first thing added is an instantiation of the generic package
838 -- System.Partition_Interface.RCI_Locator with the name of this
839 -- remote package. This will act as an interface with the name server
840 -- to determine the Partition_ID and the RPC_Receiver for the
841 -- receiver of this package.
843 RCI_Instantiation := RCI_Package_Locator (Loc, Pkg_Spec);
844 RCI_Cache := Defining_Unit_Name (RCI_Instantiation);
846 Append_To (Decls, RCI_Instantiation);
847 Analyze (RCI_Instantiation);
849 -- For each subprogram declaration visible in the spec, we do
850 -- build a body. We also increment a counter to assign a different
851 -- Subprogram_Id to each subprograms. The receiving stubs processing
852 -- do use the same mechanism and will thus assign the same Id and
853 -- do the correct dispatching.
855 Overload_Counter_Table.Reset;
856 PolyORB_Support.Reserve_NamingContext_Methods;
858 Current_Declaration := First (Visible_Declarations (Pkg_Spec));
860 while Present (Current_Declaration) loop
861 if Nkind (Current_Declaration) = N_Subprogram_Declaration
862 and then Comes_From_Source (Current_Declaration)
863 then
864 Assign_Subprogram_Identifier (
865 Defining_Unit_Name (Specification (Current_Declaration)),
866 Current_Subprogram_Number,
867 Subp_Str);
869 Subp_Stubs :=
870 Build_Subprogram_Calling_Stubs (
871 Vis_Decl => Current_Declaration,
872 Subp_Id =>
873 Build_Subprogram_Id (Loc,
874 Defining_Unit_Name (Specification (Current_Declaration))),
875 Asynchronous =>
876 Nkind (Specification (Current_Declaration)) =
877 N_Procedure_Specification
878 and then
879 Is_Asynchronous (Defining_Unit_Name (Specification
880 (Current_Declaration))));
882 Append_To (Decls, Subp_Stubs);
883 Analyze (Subp_Stubs);
885 Current_Subprogram_Number := Current_Subprogram_Number + 1;
886 end if;
888 Next (Current_Declaration);
889 end loop;
890 end Add_Calling_Stubs_To_Declarations;
892 -----------------------------
893 -- Add_Parameter_To_NVList --
894 -----------------------------
896 function Add_Parameter_To_NVList
897 (Loc : Source_Ptr;
898 NVList : Entity_Id;
899 Parameter : Entity_Id;
900 Constrained : Boolean;
901 RACW_Ctrl : Boolean := False;
902 Any : Entity_Id) return Node_Id
904 Parameter_Name_String : String_Id;
905 Parameter_Mode : Node_Id;
907 function Parameter_Passing_Mode
908 (Loc : Source_Ptr;
909 Parameter : Entity_Id;
910 Constrained : Boolean) return Node_Id;
911 -- Return an expression that denotes the parameter passing
912 -- mode to be used for Parameter in distribution stubs,
913 -- where Constrained is Parameter's constrained status.
915 ----------------------------
916 -- Parameter_Passing_Mode --
917 ----------------------------
919 function Parameter_Passing_Mode
920 (Loc : Source_Ptr;
921 Parameter : Entity_Id;
922 Constrained : Boolean) return Node_Id
924 Lib_RE : RE_Id;
926 begin
927 if Out_Present (Parameter) then
928 if In_Present (Parameter)
929 or else not Constrained
930 then
931 -- Unconstrained formals must be translated
932 -- to 'in' or 'inout', not 'out', because
933 -- they need to be constrained by the actual.
935 Lib_RE := RE_Mode_Inout;
936 else
937 Lib_RE := RE_Mode_Out;
938 end if;
940 else
941 Lib_RE := RE_Mode_In;
942 end if;
944 return New_Occurrence_Of (RTE (Lib_RE), Loc);
945 end Parameter_Passing_Mode;
947 -- Start of processing for Add_Parameter_To_NVList
949 begin
950 if Nkind (Parameter) = N_Defining_Identifier then
951 Get_Name_String (Chars (Parameter));
952 else
953 Get_Name_String (Chars (Defining_Identifier
954 (Parameter)));
955 end if;
957 Parameter_Name_String := String_From_Name_Buffer;
959 if RACW_Ctrl then
960 Parameter_Mode := New_Occurrence_Of
961 (RTE (RE_Mode_In), Loc);
962 else
963 Parameter_Mode := Parameter_Passing_Mode (Loc,
964 Parameter, Constrained);
965 end if;
967 return
968 Make_Procedure_Call_Statement (Loc,
969 Name =>
970 New_Occurrence_Of
971 (RTE (RE_NVList_Add_Item), Loc),
972 Parameter_Associations => New_List (
973 New_Occurrence_Of (NVList, Loc),
974 Make_Function_Call (Loc,
975 Name =>
976 New_Occurrence_Of
977 (RTE (RE_To_PolyORB_String), Loc),
978 Parameter_Associations => New_List (
979 Make_String_Literal (Loc,
980 Strval => Parameter_Name_String))),
981 New_Occurrence_Of (Any, Loc),
982 Parameter_Mode));
983 end Add_Parameter_To_NVList;
985 --------------------------------
986 -- Add_RACW_Asynchronous_Flag --
987 --------------------------------
989 procedure Add_RACW_Asynchronous_Flag
990 (Declarations : List_Id;
991 RACW_Type : Entity_Id)
993 Loc : constant Source_Ptr := Sloc (RACW_Type);
995 Asynchronous_Flag : constant Entity_Id :=
996 Make_Defining_Identifier (Loc,
997 New_External_Name (Chars (RACW_Type), 'A'));
999 begin
1000 -- Declare the asynchronous flag. This flag will be changed to True
1001 -- whenever it is known that the RACW type is asynchronous.
1003 Append_To (Declarations,
1004 Make_Object_Declaration (Loc,
1005 Defining_Identifier => Asynchronous_Flag,
1006 Constant_Present => True,
1007 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
1008 Expression => New_Occurrence_Of (Standard_False, Loc)));
1010 Asynchronous_Flags_Table.Set (RACW_Type, Asynchronous_Flag);
1011 end Add_RACW_Asynchronous_Flag;
1013 -----------------------
1014 -- Add_RACW_Features --
1015 -----------------------
1017 procedure Add_RACW_Features (RACW_Type : Entity_Id) is
1018 Desig : constant Entity_Id := Etype (Designated_Type (RACW_Type));
1019 Same_Scope : constant Boolean := Scope (Desig) = Scope (RACW_Type);
1020 Decls : List_Id;
1022 Stub_Type : Entity_Id;
1023 Stub_Type_Access : Entity_Id;
1024 RPC_Receiver_Decl : Node_Id;
1026 Existing : Boolean;
1027 -- True when appropriate stubs have already been generated (this is the
1028 -- case when another RACW with the same designated type has already been
1029 -- encountered, in which case we reuse the previous stubs rather than
1030 -- generating new ones).
1032 begin
1033 if not Expander_Active then
1034 return;
1035 end if;
1037 -- Look for declarations
1039 -- Case of declaring a RACW in the same package than its designated
1040 -- type, so the list to use for late declarations must be the private
1041 -- part of the package. We do know that this private part exists since
1042 -- the designated type has to be a private one.
1044 if Same_Scope then
1046 Decls := Private_Declarations
1047 (Package_Specification_Of_Scope (Current_Scope));
1049 -- Comment here???
1051 else
1052 Decls := List_Containing (Declaration_Node (RACW_Type));
1054 if 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;
1059 end if;
1061 -- If we were unable to find the declarations, that means that the
1062 -- completion of the type was missing. We can safely return and let the
1063 -- error be caught by the semantic analysis.
1065 if No (Decls) then
1066 return;
1067 end if;
1069 Add_Stub_Type
1070 (Designated_Type => Desig,
1071 RACW_Type => RACW_Type,
1072 Decls => Decls,
1073 Stub_Type => Stub_Type,
1074 Stub_Type_Access => Stub_Type_Access,
1075 RPC_Receiver_Decl => RPC_Receiver_Decl,
1076 Existing => Existing);
1078 Add_RACW_Asynchronous_Flag
1079 (Declarations => Decls,
1080 RACW_Type => RACW_Type);
1082 Specific_Add_RACW_Features
1083 (RACW_Type => RACW_Type,
1084 Desig => Desig,
1085 Stub_Type => Stub_Type,
1086 Stub_Type_Access => Stub_Type_Access,
1087 RPC_Receiver_Decl => RPC_Receiver_Decl,
1088 Declarations => Decls);
1090 if not Same_Scope and then not Existing then
1092 -- The RACW has been declared in another scope than the designated
1093 -- type and has not been handled by another RACW in the same package
1094 -- as the first one, so add primitive for the stub type here.
1096 Validate_RACW_Primitives (RACW_Type);
1097 Add_RACW_Primitive_Declarations_And_Bodies
1098 (Designated_Type => Desig,
1099 Insertion_Node => RPC_Receiver_Decl,
1100 Decls => Decls);
1102 else
1103 -- Validate_RACW_Primitives will be called when the designated type
1104 -- is frozen, see Exp_Ch3.Freeze_Type.
1105 -- ??? Shouldn't we have a pragma Assert (not Is_Frozen (Desig))?
1107 Add_Access_Type_To_Process (E => Desig, A => RACW_Type);
1108 end if;
1109 end Add_RACW_Features;
1111 ------------------------------------------------
1112 -- Add_RACW_Primitive_Declarations_And_Bodies --
1113 ------------------------------------------------
1115 procedure Add_RACW_Primitive_Declarations_And_Bodies
1116 (Designated_Type : Entity_Id;
1117 Insertion_Node : Node_Id;
1118 Decls : List_Id)
1120 Loc : constant Source_Ptr := Sloc (Insertion_Node);
1121 -- Set Sloc of generated declaration copy of insertion node Sloc, so
1122 -- the declarations are recognized as belonging to the current package.
1124 Stub_Elements : constant Stub_Structure :=
1125 Stubs_Table.Get (Designated_Type);
1127 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
1129 Is_RAS : constant Boolean :=
1130 not Comes_From_Source (Stub_Elements.RACW_Type);
1132 Current_Insertion_Node : Node_Id := Insertion_Node;
1134 RPC_Receiver : Entity_Id;
1135 RPC_Receiver_Statements : List_Id;
1136 RPC_Receiver_Case_Alternatives : constant List_Id := New_List;
1137 RPC_Receiver_Elsif_Parts : List_Id;
1138 RPC_Receiver_Request : Entity_Id;
1139 RPC_Receiver_Subp_Id : Entity_Id;
1140 RPC_Receiver_Subp_Index : Entity_Id;
1142 Subp_Str : String_Id;
1144 Current_Primitive_Elmt : Elmt_Id;
1145 Current_Primitive : Entity_Id;
1146 Current_Primitive_Body : Node_Id;
1147 Current_Primitive_Spec : Node_Id;
1148 Current_Primitive_Decl : Node_Id;
1149 Current_Primitive_Number : Int := 0;
1151 Current_Primitive_Alias : Node_Id;
1153 Current_Receiver : Entity_Id;
1154 Current_Receiver_Body : Node_Id;
1156 RPC_Receiver_Decl : Node_Id;
1158 Possibly_Asynchronous : Boolean;
1160 begin
1161 if not Expander_Active then
1162 return;
1163 end if;
1165 if not Is_RAS then
1166 RPC_Receiver := Make_Defining_Identifier (Loc,
1167 New_Internal_Name ('P'));
1168 Specific_Build_RPC_Receiver_Body (
1169 RPC_Receiver => RPC_Receiver,
1170 Request => RPC_Receiver_Request,
1171 Subp_Id => RPC_Receiver_Subp_Id,
1172 Subp_Index => RPC_Receiver_Subp_Index,
1173 Stmts => RPC_Receiver_Statements,
1174 Decl => RPC_Receiver_Decl);
1176 if Get_PCS_Name = Name_PolyORB_DSA then
1178 -- For the case of PolyORB, we need to map a textual operation
1179 -- name into a primitive index. Currently we do so using a simple
1180 -- sequence of string comparisons.
1182 RPC_Receiver_Elsif_Parts := New_List;
1183 end if;
1184 end if;
1186 -- Build callers, receivers for every primitive operations and a RPC
1187 -- receiver for this type.
1189 if Present (Primitive_Operations (Designated_Type)) then
1190 Overload_Counter_Table.Reset;
1192 Current_Primitive_Elmt :=
1193 First_Elmt (Primitive_Operations (Designated_Type));
1194 while Current_Primitive_Elmt /= No_Elmt loop
1195 Current_Primitive := Node (Current_Primitive_Elmt);
1197 -- Copy the primitive of all the parents, except predefined ones
1198 -- that are not remotely dispatching.
1200 if Chars (Current_Primitive) /= Name_uSize
1201 and then Chars (Current_Primitive) /= Name_uAlignment
1202 and then not Is_TSS (Current_Primitive, TSS_Deep_Finalize)
1203 then
1204 -- The first thing to do is build an up-to-date copy of the
1205 -- spec with all the formals referencing Designated_Type
1206 -- transformed into formals referencing Stub_Type. Since this
1207 -- primitive may have been inherited, go back the alias chain
1208 -- until the real primitive has been found.
1210 Current_Primitive_Alias := Current_Primitive;
1211 while Present (Alias (Current_Primitive_Alias)) loop
1212 pragma Assert
1213 (Current_Primitive_Alias
1214 /= Alias (Current_Primitive_Alias));
1215 Current_Primitive_Alias := Alias (Current_Primitive_Alias);
1216 end loop;
1218 Current_Primitive_Spec :=
1219 Copy_Specification (Loc,
1220 Spec => Parent (Current_Primitive_Alias),
1221 Object_Type => Designated_Type,
1222 Stub_Type => Stub_Elements.Stub_Type);
1224 Current_Primitive_Decl :=
1225 Make_Subprogram_Declaration (Loc,
1226 Specification => Current_Primitive_Spec);
1228 Insert_After (Current_Insertion_Node, Current_Primitive_Decl);
1229 Analyze (Current_Primitive_Decl);
1230 Current_Insertion_Node := Current_Primitive_Decl;
1232 Possibly_Asynchronous :=
1233 Nkind (Current_Primitive_Spec) = N_Procedure_Specification
1234 and then Could_Be_Asynchronous (Current_Primitive_Spec);
1236 Assign_Subprogram_Identifier (
1237 Defining_Unit_Name (Current_Primitive_Spec),
1238 Current_Primitive_Number,
1239 Subp_Str);
1241 Current_Primitive_Body :=
1242 Build_Subprogram_Calling_Stubs
1243 (Vis_Decl => Current_Primitive_Decl,
1244 Subp_Id =>
1245 Build_Subprogram_Id (Loc,
1246 Defining_Unit_Name (Current_Primitive_Spec)),
1247 Asynchronous => Possibly_Asynchronous,
1248 Dynamically_Asynchronous => Possibly_Asynchronous,
1249 Stub_Type => Stub_Elements.Stub_Type,
1250 RACW_Type => Stub_Elements.RACW_Type);
1251 Append_To (Decls, Current_Primitive_Body);
1253 -- Analyzing the body here would cause the Stub type to be
1254 -- frozen, thus preventing subsequent primitive declarations.
1255 -- For this reason, it will be analyzed later in the regular
1256 -- flow.
1258 -- Build the receiver stubs
1260 if not Is_RAS then
1261 Current_Receiver_Body :=
1262 Specific_Build_Subprogram_Receiving_Stubs
1263 (Vis_Decl => Current_Primitive_Decl,
1264 Asynchronous => Possibly_Asynchronous,
1265 Dynamically_Asynchronous => Possibly_Asynchronous,
1266 Stub_Type => Stub_Elements.Stub_Type,
1267 RACW_Type => Stub_Elements.RACW_Type,
1268 Parent_Primitive => Current_Primitive);
1270 Current_Receiver := Defining_Unit_Name (
1271 Specification (Current_Receiver_Body));
1273 Append_To (Decls, Current_Receiver_Body);
1275 -- Add a case alternative to the receiver
1277 if Get_PCS_Name = Name_PolyORB_DSA then
1278 Append_To (RPC_Receiver_Elsif_Parts,
1279 Make_Elsif_Part (Loc,
1280 Condition =>
1281 Make_Function_Call (Loc,
1282 Name =>
1283 New_Occurrence_Of (
1284 RTE (RE_Caseless_String_Eq), Loc),
1285 Parameter_Associations => New_List (
1286 New_Occurrence_Of (RPC_Receiver_Subp_Id, Loc),
1287 Make_String_Literal (Loc, Subp_Str))),
1288 Then_Statements => New_List (
1289 Make_Assignment_Statement (Loc,
1290 Name => New_Occurrence_Of (
1291 RPC_Receiver_Subp_Index, Loc),
1292 Expression =>
1293 Make_Integer_Literal (Loc,
1294 Current_Primitive_Number)))));
1295 end if;
1297 Append_To (RPC_Receiver_Case_Alternatives,
1298 Make_Case_Statement_Alternative (Loc,
1299 Discrete_Choices => New_List (
1300 Make_Integer_Literal (Loc, Current_Primitive_Number)),
1302 Statements => New_List (
1303 Make_Procedure_Call_Statement (Loc,
1304 Name =>
1305 New_Occurrence_Of (Current_Receiver, Loc),
1306 Parameter_Associations => New_List (
1307 New_Occurrence_Of (RPC_Receiver_Request, Loc))))));
1308 end if;
1310 -- Increment the index of current primitive
1312 Current_Primitive_Number := Current_Primitive_Number + 1;
1313 end if;
1315 Next_Elmt (Current_Primitive_Elmt);
1316 end loop;
1317 end if;
1319 -- Build the case statement and the heart of the subprogram
1321 if not Is_RAS then
1322 if Get_PCS_Name = Name_PolyORB_DSA
1323 and then Present (First (RPC_Receiver_Elsif_Parts))
1324 then
1325 Append_To (RPC_Receiver_Statements,
1326 Make_Implicit_If_Statement (Designated_Type,
1327 Condition => New_Occurrence_Of (Standard_False, Loc),
1328 Then_Statements => New_List,
1329 Elsif_Parts => RPC_Receiver_Elsif_Parts));
1330 end if;
1332 Append_To (RPC_Receiver_Case_Alternatives,
1333 Make_Case_Statement_Alternative (Loc,
1334 Discrete_Choices => New_List (Make_Others_Choice (Loc)),
1335 Statements => New_List (Make_Null_Statement (Loc))));
1337 Append_To (RPC_Receiver_Statements,
1338 Make_Case_Statement (Loc,
1339 Expression =>
1340 New_Occurrence_Of (RPC_Receiver_Subp_Index, Loc),
1341 Alternatives => RPC_Receiver_Case_Alternatives));
1343 Append_To (Decls, RPC_Receiver_Decl);
1344 Specific_Add_Obj_RPC_Receiver_Completion (Loc,
1345 Decls, RPC_Receiver, Stub_Elements);
1346 end if;
1348 -- Do not analyze RPC receiver at this stage since it will otherwise
1349 -- reference subprograms that have not been analyzed yet. It will be
1350 -- analyzed in the regular flow.
1352 end Add_RACW_Primitive_Declarations_And_Bodies;
1354 -----------------------------
1355 -- Add_RAS_Dereference_TSS --
1356 -----------------------------
1358 procedure Add_RAS_Dereference_TSS (N : Node_Id) is
1359 Loc : constant Source_Ptr := Sloc (N);
1361 Type_Def : constant Node_Id := Type_Definition (N);
1363 RAS_Type : constant Entity_Id := Defining_Identifier (N);
1364 Fat_Type : constant Entity_Id := Equivalent_Type (RAS_Type);
1365 RACW_Type : constant Entity_Id := Underlying_RACW_Type (RAS_Type);
1366 Desig : constant Entity_Id := Etype (Designated_Type (RACW_Type));
1368 Stub_Elements : constant Stub_Structure := Stubs_Table.Get (Desig);
1369 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
1371 RACW_Primitive_Name : Node_Id;
1373 Proc : constant Entity_Id :=
1374 Make_Defining_Identifier (Loc,
1375 Chars => Make_TSS_Name (RAS_Type, TSS_RAS_Dereference));
1377 Proc_Spec : Node_Id;
1378 Param_Specs : List_Id;
1379 Param_Assoc : constant List_Id := New_List;
1380 Stmts : constant List_Id := New_List;
1382 RAS_Parameter : constant Entity_Id :=
1383 Make_Defining_Identifier (Loc,
1384 Chars => New_Internal_Name ('P'));
1386 Is_Function : constant Boolean :=
1387 Nkind (Type_Def) = N_Access_Function_Definition;
1389 Is_Degenerate : Boolean;
1390 -- Set to True if the subprogram_specification for this RAS has an
1391 -- anonymous access parameter (see Process_Remote_AST_Declaration).
1393 Spec : constant Node_Id := Type_Def;
1395 Current_Parameter : Node_Id;
1397 -- Start of processing for Add_RAS_Dereference_TSS
1399 begin
1400 -- The Dereference TSS for a remote access-to-subprogram type has the
1401 -- form:
1403 -- [function|procedure] ras_typeRD (RAS_Value, <RAS_Parameters>)
1404 -- [return <>]
1406 -- This is called whenever a value of a RAS type is dereferenced
1408 -- First construct a list of parameter specifications:
1410 -- The first formal is the RAS values
1412 Param_Specs := New_List (
1413 Make_Parameter_Specification (Loc,
1414 Defining_Identifier => RAS_Parameter,
1415 In_Present => True,
1416 Parameter_Type =>
1417 New_Occurrence_Of (Fat_Type, Loc)));
1419 -- The following formals are copied from the type declaration
1421 Is_Degenerate := False;
1422 Current_Parameter := First (Parameter_Specifications (Type_Def));
1423 Parameters : while Present (Current_Parameter) loop
1424 if Nkind (Parameter_Type (Current_Parameter)) =
1425 N_Access_Definition
1426 then
1427 Is_Degenerate := True;
1428 end if;
1430 Append_To (Param_Specs,
1431 Make_Parameter_Specification (Loc,
1432 Defining_Identifier =>
1433 Make_Defining_Identifier (Loc,
1434 Chars => Chars (Defining_Identifier (Current_Parameter))),
1435 In_Present => In_Present (Current_Parameter),
1436 Out_Present => Out_Present (Current_Parameter),
1437 Parameter_Type =>
1438 New_Copy_Tree (Parameter_Type (Current_Parameter)),
1439 Expression =>
1440 New_Copy_Tree (Expression (Current_Parameter))));
1442 Append_To (Param_Assoc,
1443 Make_Identifier (Loc,
1444 Chars => Chars (Defining_Identifier (Current_Parameter))));
1446 Next (Current_Parameter);
1447 end loop Parameters;
1449 if Is_Degenerate then
1450 Prepend_To (Param_Assoc, New_Occurrence_Of (RAS_Parameter, Loc));
1452 -- Generate a dummy body. This code will never actually be executed,
1453 -- because null is the only legal value for a degenerate RAS type.
1454 -- For legality's sake (in order to avoid generating a function
1455 -- that does not contain a return statement), we include a dummy
1456 -- recursive call on the TSS itself.
1458 Append_To (Stmts,
1459 Make_Raise_Program_Error (Loc, Reason => PE_Explicit_Raise));
1460 RACW_Primitive_Name := New_Occurrence_Of (Proc, Loc);
1462 else
1463 -- For a normal RAS type, we cast the RAS formal to the corresponding
1464 -- tagged type, and perform a dispatching call to its Call primitive
1465 -- operation.
1467 Prepend_To (Param_Assoc,
1468 Unchecked_Convert_To (RACW_Type,
1469 New_Occurrence_Of (RAS_Parameter, Loc)));
1471 RACW_Primitive_Name := Make_Selected_Component (Loc,
1472 Prefix => Scope (RACW_Type),
1473 Selector_Name => Name_Call);
1474 end if;
1476 if Is_Function then
1477 Append_To (Stmts,
1478 Make_Return_Statement (Loc,
1479 Expression =>
1480 Make_Function_Call (Loc,
1481 Name =>
1482 RACW_Primitive_Name,
1483 Parameter_Associations => Param_Assoc)));
1485 else
1486 Append_To (Stmts,
1487 Make_Procedure_Call_Statement (Loc,
1488 Name =>
1489 RACW_Primitive_Name,
1490 Parameter_Associations => Param_Assoc));
1491 end if;
1493 -- Build the complete subprogram
1495 if Is_Function then
1496 Proc_Spec :=
1497 Make_Function_Specification (Loc,
1498 Defining_Unit_Name => Proc,
1499 Parameter_Specifications => Param_Specs,
1500 Result_Definition =>
1501 New_Occurrence_Of (
1502 Entity (Result_Definition (Spec)), Loc));
1504 Set_Ekind (Proc, E_Function);
1505 Set_Etype (Proc,
1506 New_Occurrence_Of (Entity (Result_Definition (Spec)), Loc));
1508 else
1509 Proc_Spec :=
1510 Make_Procedure_Specification (Loc,
1511 Defining_Unit_Name => Proc,
1512 Parameter_Specifications => Param_Specs);
1514 Set_Ekind (Proc, E_Procedure);
1515 Set_Etype (Proc, Standard_Void_Type);
1516 end if;
1518 Discard_Node (
1519 Make_Subprogram_Body (Loc,
1520 Specification => Proc_Spec,
1521 Declarations => New_List,
1522 Handled_Statement_Sequence =>
1523 Make_Handled_Sequence_Of_Statements (Loc,
1524 Statements => Stmts)));
1526 Set_TSS (Fat_Type, Proc);
1527 end Add_RAS_Dereference_TSS;
1529 -------------------------------
1530 -- Add_RAS_Proxy_And_Analyze --
1531 -------------------------------
1533 procedure Add_RAS_Proxy_And_Analyze
1534 (Decls : List_Id;
1535 Vis_Decl : Node_Id;
1536 All_Calls_Remote_E : Entity_Id;
1537 Proxy_Object_Addr : out Entity_Id)
1539 Loc : constant Source_Ptr := Sloc (Vis_Decl);
1541 Subp_Name : constant Entity_Id :=
1542 Defining_Unit_Name (Specification (Vis_Decl));
1544 Pkg_Name : constant Entity_Id :=
1545 Make_Defining_Identifier (Loc,
1546 Chars =>
1547 New_External_Name (Chars (Subp_Name), 'P', -1));
1549 Proxy_Type : constant Entity_Id :=
1550 Make_Defining_Identifier (Loc,
1551 Chars =>
1552 New_External_Name (
1553 Related_Id => Chars (Subp_Name),
1554 Suffix => 'P'));
1556 Proxy_Type_Full_View : constant Entity_Id :=
1557 Make_Defining_Identifier (Loc,
1558 Chars (Proxy_Type));
1560 Subp_Decl_Spec : constant Node_Id :=
1561 Build_RAS_Primitive_Specification
1562 (Subp_Spec => Specification (Vis_Decl),
1563 Remote_Object_Type => Proxy_Type);
1565 Subp_Body_Spec : constant Node_Id :=
1566 Build_RAS_Primitive_Specification
1567 (Subp_Spec => Specification (Vis_Decl),
1568 Remote_Object_Type => Proxy_Type);
1570 Vis_Decls : constant List_Id := New_List;
1571 Pvt_Decls : constant List_Id := New_List;
1572 Actuals : constant List_Id := New_List;
1573 Formal : Node_Id;
1574 Perform_Call : Node_Id;
1576 begin
1577 -- type subpP is tagged limited private;
1579 Append_To (Vis_Decls,
1580 Make_Private_Type_Declaration (Loc,
1581 Defining_Identifier => Proxy_Type,
1582 Tagged_Present => True,
1583 Limited_Present => True));
1585 -- [subprogram] Call
1586 -- (Self : access subpP;
1587 -- ...other-formals...)
1588 -- [return T];
1590 Append_To (Vis_Decls,
1591 Make_Subprogram_Declaration (Loc,
1592 Specification => Subp_Decl_Spec));
1594 -- A : constant System.Address;
1596 Proxy_Object_Addr := Make_Defining_Identifier (Loc, Name_uA);
1598 Append_To (Vis_Decls,
1599 Make_Object_Declaration (Loc,
1600 Defining_Identifier =>
1601 Proxy_Object_Addr,
1602 Constant_Present =>
1603 True,
1604 Object_Definition =>
1605 New_Occurrence_Of (RTE (RE_Address), Loc)));
1607 -- private
1609 -- type subpP is tagged limited record
1610 -- All_Calls_Remote : Boolean := [All_Calls_Remote?];
1611 -- ...
1612 -- end record;
1614 Append_To (Pvt_Decls,
1615 Make_Full_Type_Declaration (Loc,
1616 Defining_Identifier =>
1617 Proxy_Type_Full_View,
1618 Type_Definition =>
1619 Build_Remote_Subprogram_Proxy_Type (Loc,
1620 New_Occurrence_Of (All_Calls_Remote_E, Loc))));
1622 -- Trick semantic analysis into swapping the public and
1623 -- full view when freezing the public view.
1625 Set_Comes_From_Source (Proxy_Type_Full_View, True);
1627 -- procedure Call
1628 -- (Self : access O;
1629 -- ...other-formals...) is
1630 -- begin
1631 -- P (...other-formals...);
1632 -- end Call;
1634 -- function Call
1635 -- (Self : access O;
1636 -- ...other-formals...)
1637 -- return T is
1638 -- begin
1639 -- return F (...other-formals...);
1640 -- end Call;
1642 if Nkind (Subp_Decl_Spec) = N_Procedure_Specification then
1643 Perform_Call :=
1644 Make_Procedure_Call_Statement (Loc,
1645 Name =>
1646 New_Occurrence_Of (Subp_Name, Loc),
1647 Parameter_Associations =>
1648 Actuals);
1649 else
1650 Perform_Call :=
1651 Make_Return_Statement (Loc,
1652 Expression =>
1653 Make_Function_Call (Loc,
1654 Name =>
1655 New_Occurrence_Of (Subp_Name, Loc),
1656 Parameter_Associations =>
1657 Actuals));
1658 end if;
1660 Formal := First (Parameter_Specifications (Subp_Decl_Spec));
1661 pragma Assert (Present (Formal));
1662 loop
1663 Next (Formal);
1664 exit when No (Formal);
1665 Append_To (Actuals,
1666 New_Occurrence_Of (Defining_Identifier (Formal), Loc));
1667 end loop;
1669 -- O : aliased subpP;
1671 Append_To (Pvt_Decls,
1672 Make_Object_Declaration (Loc,
1673 Defining_Identifier =>
1674 Make_Defining_Identifier (Loc,
1675 Name_uO),
1676 Aliased_Present =>
1677 True,
1678 Object_Definition =>
1679 New_Occurrence_Of (Proxy_Type, Loc)));
1681 -- A : constant System.Address := O'Address;
1683 Append_To (Pvt_Decls,
1684 Make_Object_Declaration (Loc,
1685 Defining_Identifier =>
1686 Make_Defining_Identifier (Loc,
1687 Chars (Proxy_Object_Addr)),
1688 Constant_Present =>
1689 True,
1690 Object_Definition =>
1691 New_Occurrence_Of (RTE (RE_Address), Loc),
1692 Expression =>
1693 Make_Attribute_Reference (Loc,
1694 Prefix => New_Occurrence_Of (
1695 Defining_Identifier (Last (Pvt_Decls)), Loc),
1696 Attribute_Name =>
1697 Name_Address)));
1699 Append_To (Decls,
1700 Make_Package_Declaration (Loc,
1701 Specification => Make_Package_Specification (Loc,
1702 Defining_Unit_Name => Pkg_Name,
1703 Visible_Declarations => Vis_Decls,
1704 Private_Declarations => Pvt_Decls,
1705 End_Label => Empty)));
1706 Analyze (Last (Decls));
1708 Append_To (Decls,
1709 Make_Package_Body (Loc,
1710 Defining_Unit_Name =>
1711 Make_Defining_Identifier (Loc,
1712 Chars (Pkg_Name)),
1713 Declarations => New_List (
1714 Make_Subprogram_Body (Loc,
1715 Specification =>
1716 Subp_Body_Spec,
1717 Declarations => New_List,
1718 Handled_Statement_Sequence =>
1719 Make_Handled_Sequence_Of_Statements (Loc,
1720 Statements => New_List (Perform_Call))))));
1721 Analyze (Last (Decls));
1722 end Add_RAS_Proxy_And_Analyze;
1724 -----------------------
1725 -- Add_RAST_Features --
1726 -----------------------
1728 procedure Add_RAST_Features (Vis_Decl : Node_Id) is
1729 RAS_Type : constant Entity_Id :=
1730 Equivalent_Type (Defining_Identifier (Vis_Decl));
1731 begin
1732 pragma Assert (No (TSS (RAS_Type, TSS_RAS_Access)));
1733 Add_RAS_Dereference_TSS (Vis_Decl);
1734 Specific_Add_RAST_Features (Vis_Decl, RAS_Type);
1735 end Add_RAST_Features;
1737 -------------------
1738 -- Add_Stub_Type --
1739 -------------------
1741 procedure Add_Stub_Type
1742 (Designated_Type : Entity_Id;
1743 RACW_Type : Entity_Id;
1744 Decls : List_Id;
1745 Stub_Type : out Entity_Id;
1746 Stub_Type_Access : out Entity_Id;
1747 RPC_Receiver_Decl : out Node_Id;
1748 Existing : out Boolean)
1750 Loc : constant Source_Ptr := Sloc (RACW_Type);
1752 Stub_Elements : constant Stub_Structure :=
1753 Stubs_Table.Get (Designated_Type);
1754 Stub_Type_Decl : Node_Id;
1755 Stub_Type_Access_Decl : Node_Id;
1757 begin
1758 if Stub_Elements /= Empty_Stub_Structure then
1759 Stub_Type := Stub_Elements.Stub_Type;
1760 Stub_Type_Access := Stub_Elements.Stub_Type_Access;
1761 RPC_Receiver_Decl := Stub_Elements.RPC_Receiver_Decl;
1762 Existing := True;
1763 return;
1764 end if;
1766 Existing := False;
1767 Stub_Type :=
1768 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
1769 Stub_Type_Access :=
1770 Make_Defining_Identifier (Loc,
1771 New_External_Name (
1772 Related_Id => Chars (Stub_Type),
1773 Suffix => 'A'));
1775 Specific_Build_Stub_Type (
1776 RACW_Type, Stub_Type,
1777 Stub_Type_Decl, RPC_Receiver_Decl);
1779 Stub_Type_Access_Decl :=
1780 Make_Full_Type_Declaration (Loc,
1781 Defining_Identifier => Stub_Type_Access,
1782 Type_Definition =>
1783 Make_Access_To_Object_Definition (Loc,
1784 All_Present => True,
1785 Subtype_Indication => New_Occurrence_Of (Stub_Type, Loc)));
1787 Append_To (Decls, Stub_Type_Decl);
1788 Analyze (Last (Decls));
1789 Append_To (Decls, Stub_Type_Access_Decl);
1790 Analyze (Last (Decls));
1792 -- This is in no way a type derivation, but we fake it to make
1793 -- sure that the dispatching table gets built with the corresponding
1794 -- primitive operations at the right place.
1796 Derive_Subprograms (Parent_Type => Designated_Type,
1797 Derived_Type => Stub_Type);
1799 if Present (RPC_Receiver_Decl) then
1800 Append_To (Decls, RPC_Receiver_Decl);
1801 else
1802 RPC_Receiver_Decl := Last (Decls);
1803 end if;
1805 Stubs_Table.Set (Designated_Type,
1806 (Stub_Type => Stub_Type,
1807 Stub_Type_Access => Stub_Type_Access,
1808 RPC_Receiver_Decl => RPC_Receiver_Decl,
1809 RACW_Type => RACW_Type));
1810 end Add_Stub_Type;
1812 ----------------------------------
1813 -- Assign_Subprogram_Identifier --
1814 ----------------------------------
1816 procedure Assign_Subprogram_Identifier
1817 (Def : Entity_Id;
1818 Spn : Int;
1819 Id : out String_Id)
1821 N : constant Name_Id := Chars (Def);
1823 Overload_Order : constant Int :=
1824 Overload_Counter_Table.Get (N) + 1;
1826 begin
1827 Overload_Counter_Table.Set (N, Overload_Order);
1829 Get_Name_String (N);
1831 -- Homonym handling: as in Exp_Dbug, but much simpler,
1832 -- because the only entities for which we have to generate
1833 -- names here need only to be disambiguated within their
1834 -- own scope.
1836 if Overload_Order > 1 then
1837 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "__";
1838 Name_Len := Name_Len + 2;
1839 Add_Nat_To_Name_Buffer (Overload_Order);
1840 end if;
1842 Id := String_From_Name_Buffer;
1843 Subprogram_Identifier_Table.Set (Def,
1844 Subprogram_Identifiers'(Str_Identifier => Id, Int_Identifier => Spn));
1845 end Assign_Subprogram_Identifier;
1847 ------------------------------
1848 -- Build_Get_Unique_RP_Call --
1849 ------------------------------
1851 function Build_Get_Unique_RP_Call
1852 (Loc : Source_Ptr;
1853 Pointer : Entity_Id;
1854 Stub_Type : Entity_Id) return List_Id
1856 begin
1857 return New_List (
1858 Make_Procedure_Call_Statement (Loc,
1859 Name =>
1860 New_Occurrence_Of (RTE (RE_Get_Unique_Remote_Pointer), Loc),
1861 Parameter_Associations => New_List (
1862 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
1863 New_Occurrence_Of (Pointer, Loc)))),
1865 Make_Assignment_Statement (Loc,
1866 Name =>
1867 Make_Selected_Component (Loc,
1868 Prefix =>
1869 New_Occurrence_Of (Pointer, Loc),
1870 Selector_Name =>
1871 New_Occurrence_Of (First_Tag_Component
1872 (Designated_Type (Etype (Pointer))), Loc)),
1873 Expression =>
1874 Make_Attribute_Reference (Loc,
1875 Prefix =>
1876 New_Occurrence_Of (Stub_Type, Loc),
1877 Attribute_Name =>
1878 Name_Tag)));
1880 -- Note: The assignment to Pointer._Tag is safe here because
1881 -- we carefully ensured that Stub_Type has exactly the same layout
1882 -- as System.Partition_Interface.RACW_Stub_Type.
1884 end Build_Get_Unique_RP_Call;
1886 -----------------------------------
1887 -- Build_Ordered_Parameters_List --
1888 -----------------------------------
1890 function Build_Ordered_Parameters_List (Spec : Node_Id) return List_Id is
1891 Constrained_List : List_Id;
1892 Unconstrained_List : List_Id;
1893 Current_Parameter : Node_Id;
1895 First_Parameter : Node_Id;
1896 For_RAS : Boolean := False;
1898 begin
1899 if No (Parameter_Specifications (Spec)) then
1900 return New_List;
1901 end if;
1903 Constrained_List := New_List;
1904 Unconstrained_List := New_List;
1905 First_Parameter := First (Parameter_Specifications (Spec));
1907 if Nkind (Parameter_Type (First_Parameter)) = N_Access_Definition
1908 and then Chars (Defining_Identifier (First_Parameter)) = Name_uS
1909 then
1910 For_RAS := True;
1911 end if;
1913 -- Loop through the parameters and add them to the right list
1915 Current_Parameter := First_Parameter;
1916 while Present (Current_Parameter) loop
1917 if (Nkind (Parameter_Type (Current_Parameter)) = N_Access_Definition
1918 or else
1919 Is_Constrained (Etype (Parameter_Type (Current_Parameter)))
1920 or else
1921 Is_Elementary_Type (Etype (Parameter_Type (Current_Parameter))))
1922 and then not (For_RAS and then Current_Parameter = First_Parameter)
1923 then
1924 Append_To (Constrained_List, New_Copy (Current_Parameter));
1925 else
1926 Append_To (Unconstrained_List, New_Copy (Current_Parameter));
1927 end if;
1929 Next (Current_Parameter);
1930 end loop;
1932 -- Unconstrained parameters are returned first
1934 Append_List_To (Unconstrained_List, Constrained_List);
1936 return Unconstrained_List;
1937 end Build_Ordered_Parameters_List;
1939 ----------------------------------
1940 -- Build_Passive_Partition_Stub --
1941 ----------------------------------
1943 procedure Build_Passive_Partition_Stub (U : Node_Id) is
1944 Pkg_Spec : Node_Id;
1945 Pkg_Name : String_Id;
1946 L : List_Id;
1947 Reg : Node_Id;
1948 Loc : constant Source_Ptr := Sloc (U);
1950 begin
1951 -- Verify that the implementation supports distribution, by accessing
1952 -- a type defined in the proper version of system.rpc
1954 declare
1955 Dist_OK : Entity_Id;
1956 pragma Warnings (Off, Dist_OK);
1957 begin
1958 Dist_OK := RTE (RE_Params_Stream_Type);
1959 end;
1961 -- Use body if present, spec otherwise
1963 if Nkind (U) = N_Package_Declaration then
1964 Pkg_Spec := Specification (U);
1965 L := Visible_Declarations (Pkg_Spec);
1966 else
1967 Pkg_Spec := Parent (Corresponding_Spec (U));
1968 L := Declarations (U);
1969 end if;
1971 Get_Library_Unit_Name_String (Pkg_Spec);
1972 Pkg_Name := String_From_Name_Buffer;
1973 Reg :=
1974 Make_Procedure_Call_Statement (Loc,
1975 Name =>
1976 New_Occurrence_Of (RTE (RE_Register_Passive_Package), Loc),
1977 Parameter_Associations => New_List (
1978 Make_String_Literal (Loc, Pkg_Name),
1979 Make_Attribute_Reference (Loc,
1980 Prefix =>
1981 New_Occurrence_Of (Defining_Entity (Pkg_Spec), Loc),
1982 Attribute_Name =>
1983 Name_Version)));
1984 Append_To (L, Reg);
1985 Analyze (Reg);
1986 end Build_Passive_Partition_Stub;
1988 --------------------------------------
1989 -- Build_RPC_Receiver_Specification --
1990 --------------------------------------
1992 function Build_RPC_Receiver_Specification
1993 (RPC_Receiver : Entity_Id;
1994 Request_Parameter : Entity_Id) return Node_Id
1996 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
1997 begin
1998 return
1999 Make_Procedure_Specification (Loc,
2000 Defining_Unit_Name => RPC_Receiver,
2001 Parameter_Specifications => New_List (
2002 Make_Parameter_Specification (Loc,
2003 Defining_Identifier => Request_Parameter,
2004 Parameter_Type =>
2005 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
2006 end Build_RPC_Receiver_Specification;
2008 ----------------------------------------
2009 -- Build_Remote_Subprogram_Proxy_Type --
2010 ----------------------------------------
2012 function Build_Remote_Subprogram_Proxy_Type
2013 (Loc : Source_Ptr;
2014 ACR_Expression : Node_Id) return Node_Id
2016 begin
2017 return
2018 Make_Record_Definition (Loc,
2019 Tagged_Present => True,
2020 Limited_Present => True,
2021 Component_List =>
2022 Make_Component_List (Loc,
2024 Component_Items => New_List (
2025 Make_Component_Declaration (Loc,
2026 Defining_Identifier =>
2027 Make_Defining_Identifier (Loc,
2028 Name_All_Calls_Remote),
2029 Component_Definition =>
2030 Make_Component_Definition (Loc,
2031 Subtype_Indication =>
2032 New_Occurrence_Of (Standard_Boolean, Loc)),
2033 Expression =>
2034 ACR_Expression),
2036 Make_Component_Declaration (Loc,
2037 Defining_Identifier =>
2038 Make_Defining_Identifier (Loc,
2039 Name_Receiver),
2040 Component_Definition =>
2041 Make_Component_Definition (Loc,
2042 Subtype_Indication =>
2043 New_Occurrence_Of (RTE (RE_Address), Loc)),
2044 Expression =>
2045 New_Occurrence_Of (RTE (RE_Null_Address), Loc)),
2047 Make_Component_Declaration (Loc,
2048 Defining_Identifier =>
2049 Make_Defining_Identifier (Loc,
2050 Name_Subp_Id),
2051 Component_Definition =>
2052 Make_Component_Definition (Loc,
2053 Subtype_Indication =>
2054 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc))))));
2055 end Build_Remote_Subprogram_Proxy_Type;
2057 ------------------------------------
2058 -- Build_Subprogram_Calling_Stubs --
2059 ------------------------------------
2061 function Build_Subprogram_Calling_Stubs
2062 (Vis_Decl : Node_Id;
2063 Subp_Id : Node_Id;
2064 Asynchronous : Boolean;
2065 Dynamically_Asynchronous : Boolean := False;
2066 Stub_Type : Entity_Id := Empty;
2067 RACW_Type : Entity_Id := Empty;
2068 Locator : Entity_Id := Empty;
2069 New_Name : Name_Id := No_Name) return Node_Id
2071 Loc : constant Source_Ptr := Sloc (Vis_Decl);
2073 Decls : constant List_Id := New_List;
2074 Statements : constant List_Id := New_List;
2076 Subp_Spec : Node_Id;
2077 -- The specification of the body
2079 Controlling_Parameter : Entity_Id := Empty;
2081 Asynchronous_Expr : Node_Id := Empty;
2083 RCI_Locator : Entity_Id;
2085 Spec_To_Use : Node_Id;
2087 procedure Insert_Partition_Check (Parameter : Node_Id);
2088 -- Check that the parameter has been elaborated on the same partition
2089 -- than the controlling parameter (E.4(19)).
2091 ----------------------------
2092 -- Insert_Partition_Check --
2093 ----------------------------
2095 procedure Insert_Partition_Check (Parameter : Node_Id) is
2096 Parameter_Entity : constant Entity_Id :=
2097 Defining_Identifier (Parameter);
2098 begin
2099 -- The expression that will be built is of the form:
2101 -- if not Same_Partition (Parameter, Controlling_Parameter) then
2102 -- raise Constraint_Error;
2103 -- end if;
2105 -- We do not check that Parameter is in Stub_Type since such a check
2106 -- has been inserted at the point of call already (a tag check since
2107 -- we have multiple controlling operands).
2109 Append_To (Decls,
2110 Make_Raise_Constraint_Error (Loc,
2111 Condition =>
2112 Make_Op_Not (Loc,
2113 Right_Opnd =>
2114 Make_Function_Call (Loc,
2115 Name =>
2116 New_Occurrence_Of (RTE (RE_Same_Partition), Loc),
2117 Parameter_Associations =>
2118 New_List (
2119 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
2120 New_Occurrence_Of (Parameter_Entity, Loc)),
2121 Unchecked_Convert_To (RTE (RE_RACW_Stub_Type_Access),
2122 New_Occurrence_Of (Controlling_Parameter, Loc))))),
2123 Reason => CE_Partition_Check_Failed));
2124 end Insert_Partition_Check;
2126 -- Start of processing for Build_Subprogram_Calling_Stubs
2128 begin
2129 Subp_Spec := Copy_Specification (Loc,
2130 Spec => Specification (Vis_Decl),
2131 New_Name => New_Name);
2133 if Locator = Empty then
2134 RCI_Locator := RCI_Cache;
2135 Spec_To_Use := Specification (Vis_Decl);
2136 else
2137 RCI_Locator := Locator;
2138 Spec_To_Use := Subp_Spec;
2139 end if;
2141 -- Find a controlling argument if we have a stub type. Also check
2142 -- if this subprogram can be made asynchronous.
2144 if Present (Stub_Type)
2145 and then Present (Parameter_Specifications (Spec_To_Use))
2146 then
2147 declare
2148 Current_Parameter : Node_Id :=
2149 First (Parameter_Specifications
2150 (Spec_To_Use));
2151 begin
2152 while Present (Current_Parameter) loop
2154 Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type)
2155 then
2156 if Controlling_Parameter = Empty then
2157 Controlling_Parameter :=
2158 Defining_Identifier (Current_Parameter);
2159 else
2160 Insert_Partition_Check (Current_Parameter);
2161 end if;
2162 end if;
2164 Next (Current_Parameter);
2165 end loop;
2166 end;
2167 end if;
2169 pragma Assert (No (Stub_Type) or else Present (Controlling_Parameter));
2171 if Dynamically_Asynchronous then
2172 Asynchronous_Expr := Make_Selected_Component (Loc,
2173 Prefix => Controlling_Parameter,
2174 Selector_Name => Name_Asynchronous);
2175 end if;
2177 Specific_Build_General_Calling_Stubs
2178 (Decls => Decls,
2179 Statements => Statements,
2180 Target => Specific_Build_Stub_Target (Loc,
2181 Decls, RCI_Locator, Controlling_Parameter),
2182 Subprogram_Id => Subp_Id,
2183 Asynchronous => Asynchronous_Expr,
2184 Is_Known_Asynchronous => Asynchronous
2185 and then not Dynamically_Asynchronous,
2186 Is_Known_Non_Asynchronous
2187 => not Asynchronous
2188 and then not Dynamically_Asynchronous,
2189 Is_Function => Nkind (Spec_To_Use) =
2190 N_Function_Specification,
2191 Spec => Spec_To_Use,
2192 Stub_Type => Stub_Type,
2193 RACW_Type => RACW_Type,
2194 Nod => Vis_Decl);
2196 RCI_Calling_Stubs_Table.Set
2197 (Defining_Unit_Name (Specification (Vis_Decl)),
2198 Defining_Unit_Name (Spec_To_Use));
2200 return
2201 Make_Subprogram_Body (Loc,
2202 Specification => Subp_Spec,
2203 Declarations => Decls,
2204 Handled_Statement_Sequence =>
2205 Make_Handled_Sequence_Of_Statements (Loc, Statements));
2206 end Build_Subprogram_Calling_Stubs;
2208 -------------------------
2209 -- Build_Subprogram_Id --
2210 -------------------------
2212 function Build_Subprogram_Id
2213 (Loc : Source_Ptr;
2214 E : Entity_Id) return Node_Id
2216 begin
2217 if Get_Subprogram_Ids (E).Str_Identifier = No_String then
2218 declare
2219 Current_Declaration : Node_Id;
2220 Current_Subp : Entity_Id;
2221 Current_Subp_Str : String_Id;
2222 Current_Subp_Number : Int := First_RCI_Subprogram_Id;
2224 begin
2225 -- Build_Subprogram_Id is called outside of the context of
2226 -- generating calling or receiving stubs. Hence we are processing
2227 -- an 'Access attribute_reference for an RCI subprogram, for the
2228 -- purpose of obtaining a RAS value.
2230 pragma Assert
2231 (Is_Remote_Call_Interface (Scope (E))
2232 and then
2233 (Nkind (Parent (E)) = N_Procedure_Specification
2234 or else
2235 Nkind (Parent (E)) = N_Function_Specification));
2237 Current_Declaration :=
2238 First (Visible_Declarations
2239 (Package_Specification_Of_Scope (Scope (E))));
2240 while Present (Current_Declaration) loop
2241 if Nkind (Current_Declaration) = N_Subprogram_Declaration
2242 and then Comes_From_Source (Current_Declaration)
2243 then
2244 Current_Subp := Defining_Unit_Name (Specification (
2245 Current_Declaration));
2247 Assign_Subprogram_Identifier
2248 (Current_Subp, Current_Subp_Number, Current_Subp_Str);
2250 Current_Subp_Number := Current_Subp_Number + 1;
2251 end if;
2253 Next (Current_Declaration);
2254 end loop;
2255 end;
2256 end if;
2258 case Get_PCS_Name is
2259 when Name_PolyORB_DSA =>
2260 return Make_String_Literal (Loc, Get_Subprogram_Id (E));
2261 when others =>
2262 return Make_Integer_Literal (Loc, Get_Subprogram_Id (E));
2263 end case;
2264 end Build_Subprogram_Id;
2266 ------------------------
2267 -- Copy_Specification --
2268 ------------------------
2270 function Copy_Specification
2271 (Loc : Source_Ptr;
2272 Spec : Node_Id;
2273 Object_Type : Entity_Id := Empty;
2274 Stub_Type : Entity_Id := Empty;
2275 New_Name : Name_Id := No_Name) return Node_Id
2277 Parameters : List_Id := No_List;
2279 Current_Parameter : Node_Id;
2280 Current_Identifier : Entity_Id;
2281 Current_Type : Node_Id;
2282 Current_Etype : Entity_Id;
2284 Name_For_New_Spec : Name_Id;
2286 New_Identifier : Entity_Id;
2288 -- Comments needed in body below ???
2290 begin
2291 if New_Name = No_Name then
2292 pragma Assert (Nkind (Spec) = N_Function_Specification
2293 or else Nkind (Spec) = N_Procedure_Specification);
2295 Name_For_New_Spec := Chars (Defining_Unit_Name (Spec));
2296 else
2297 Name_For_New_Spec := New_Name;
2298 end if;
2300 if Present (Parameter_Specifications (Spec)) then
2301 Parameters := New_List;
2302 Current_Parameter := First (Parameter_Specifications (Spec));
2303 while Present (Current_Parameter) loop
2304 Current_Identifier := Defining_Identifier (Current_Parameter);
2305 Current_Type := Parameter_Type (Current_Parameter);
2307 if Nkind (Current_Type) = N_Access_Definition then
2308 Current_Etype := Entity (Subtype_Mark (Current_Type));
2310 if Present (Object_Type) then
2311 pragma Assert (
2312 Root_Type (Current_Etype) = Root_Type (Object_Type));
2313 Current_Type :=
2314 Make_Access_Definition (Loc,
2315 Subtype_Mark => New_Occurrence_Of (Stub_Type, Loc),
2316 Null_Exclusion_Present =>
2317 Null_Exclusion_Present (Current_Type));
2319 else
2320 Current_Type :=
2321 Make_Access_Definition (Loc,
2322 Subtype_Mark =>
2323 New_Occurrence_Of (Current_Etype, Loc),
2324 Null_Exclusion_Present =>
2325 Null_Exclusion_Present (Current_Type));
2326 end if;
2328 else
2329 Current_Etype := Entity (Current_Type);
2331 if Present (Object_Type)
2332 and then Current_Etype = Object_Type
2333 then
2334 Current_Type := New_Occurrence_Of (Stub_Type, Loc);
2335 else
2336 Current_Type := New_Occurrence_Of (Current_Etype, Loc);
2337 end if;
2338 end if;
2340 New_Identifier := Make_Defining_Identifier (Loc,
2341 Chars (Current_Identifier));
2343 Append_To (Parameters,
2344 Make_Parameter_Specification (Loc,
2345 Defining_Identifier => New_Identifier,
2346 Parameter_Type => Current_Type,
2347 In_Present => In_Present (Current_Parameter),
2348 Out_Present => Out_Present (Current_Parameter),
2349 Expression =>
2350 New_Copy_Tree (Expression (Current_Parameter))));
2352 -- For a regular formal parameter (that needs to be marshalled
2353 -- in the context of remote calls), set the Etype now, because
2354 -- marshalling processing might need it.
2356 if Is_Entity_Name (Current_Type) then
2357 Set_Etype (New_Identifier, Entity (Current_Type));
2359 -- Current_Type is an access definition, special processing
2360 -- (not requiring etype) will occur for marshalling.
2362 else
2363 null;
2364 end if;
2366 Next (Current_Parameter);
2367 end loop;
2368 end if;
2370 case Nkind (Spec) is
2372 when N_Function_Specification | N_Access_Function_Definition =>
2373 return
2374 Make_Function_Specification (Loc,
2375 Defining_Unit_Name =>
2376 Make_Defining_Identifier (Loc,
2377 Chars => Name_For_New_Spec),
2378 Parameter_Specifications => Parameters,
2379 Result_Definition =>
2380 New_Occurrence_Of (Entity (Result_Definition (Spec)), Loc));
2382 when N_Procedure_Specification | N_Access_Procedure_Definition =>
2383 return
2384 Make_Procedure_Specification (Loc,
2385 Defining_Unit_Name =>
2386 Make_Defining_Identifier (Loc,
2387 Chars => Name_For_New_Spec),
2388 Parameter_Specifications => Parameters);
2390 when others =>
2391 raise Program_Error;
2392 end case;
2393 end Copy_Specification;
2395 -----------------------------
2396 -- Corresponding_Stub_Type --
2397 -----------------------------
2399 function Corresponding_Stub_Type (RACW_Type : Entity_Id) return Entity_Id is
2400 Desig : constant Entity_Id :=
2401 Etype (Designated_Type (RACW_Type));
2402 Stub_Elements : constant Stub_Structure := Stubs_Table.Get (Desig);
2403 begin
2404 return Stub_Elements.Stub_Type;
2405 end Corresponding_Stub_Type;
2407 ---------------------------
2408 -- Could_Be_Asynchronous --
2409 ---------------------------
2411 function Could_Be_Asynchronous (Spec : Node_Id) return Boolean is
2412 Current_Parameter : Node_Id;
2414 begin
2415 if Present (Parameter_Specifications (Spec)) then
2416 Current_Parameter := First (Parameter_Specifications (Spec));
2417 while Present (Current_Parameter) loop
2418 if Out_Present (Current_Parameter) then
2419 return False;
2420 end if;
2422 Next (Current_Parameter);
2423 end loop;
2424 end if;
2426 return True;
2427 end Could_Be_Asynchronous;
2429 ---------------------------
2430 -- Declare_Create_NVList --
2431 ---------------------------
2433 procedure Declare_Create_NVList
2434 (Loc : Source_Ptr;
2435 NVList : Entity_Id;
2436 Decls : List_Id;
2437 Stmts : List_Id)
2439 begin
2440 Append_To (Decls,
2441 Make_Object_Declaration (Loc,
2442 Defining_Identifier => NVList,
2443 Aliased_Present => False,
2444 Object_Definition =>
2445 New_Occurrence_Of (RTE (RE_NVList_Ref), Loc)));
2447 Append_To (Stmts,
2448 Make_Procedure_Call_Statement (Loc,
2449 Name =>
2450 New_Occurrence_Of (RTE (RE_NVList_Create), Loc),
2451 Parameter_Associations => New_List (
2452 New_Occurrence_Of (NVList, Loc))));
2453 end Declare_Create_NVList;
2455 ---------------------------------------------
2456 -- Expand_All_Calls_Remote_Subprogram_Call --
2457 ---------------------------------------------
2459 procedure Expand_All_Calls_Remote_Subprogram_Call (N : Node_Id) is
2460 Called_Subprogram : constant Entity_Id := Entity (Name (N));
2461 RCI_Package : constant Entity_Id := Scope (Called_Subprogram);
2462 Loc : constant Source_Ptr := Sloc (N);
2463 RCI_Locator : Node_Id;
2464 RCI_Cache : Entity_Id;
2465 Calling_Stubs : Node_Id;
2466 E_Calling_Stubs : Entity_Id;
2468 begin
2469 E_Calling_Stubs := RCI_Calling_Stubs_Table.Get (Called_Subprogram);
2471 if E_Calling_Stubs = Empty then
2472 RCI_Cache := RCI_Locator_Table.Get (RCI_Package);
2474 if RCI_Cache = Empty then
2475 RCI_Locator :=
2476 RCI_Package_Locator
2477 (Loc, Specification (Unit_Declaration_Node (RCI_Package)));
2478 Prepend_To (Current_Sem_Unit_Declarations, RCI_Locator);
2480 -- The RCI_Locator package is inserted at the top level in the
2481 -- current unit, and must appear in the proper scope, so that it
2482 -- is not prematurely removed by the GCC back-end.
2484 declare
2485 Scop : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
2487 begin
2488 if Ekind (Scop) = E_Package_Body then
2489 New_Scope (Spec_Entity (Scop));
2491 elsif Ekind (Scop) = E_Subprogram_Body then
2492 New_Scope
2493 (Corresponding_Spec (Unit_Declaration_Node (Scop)));
2495 else
2496 New_Scope (Scop);
2497 end if;
2499 Analyze (RCI_Locator);
2500 Pop_Scope;
2501 end;
2503 RCI_Cache := Defining_Unit_Name (RCI_Locator);
2505 else
2506 RCI_Locator := Parent (RCI_Cache);
2507 end if;
2509 Calling_Stubs := Build_Subprogram_Calling_Stubs
2510 (Vis_Decl => Parent (Parent (Called_Subprogram)),
2511 Subp_Id =>
2512 Build_Subprogram_Id (Loc, Called_Subprogram),
2513 Asynchronous => Nkind (N) = N_Procedure_Call_Statement
2514 and then
2515 Is_Asynchronous (Called_Subprogram),
2516 Locator => RCI_Cache,
2517 New_Name => New_Internal_Name ('S'));
2518 Insert_After (RCI_Locator, Calling_Stubs);
2519 Analyze (Calling_Stubs);
2520 E_Calling_Stubs := Defining_Unit_Name (Specification (Calling_Stubs));
2521 end if;
2523 Rewrite (Name (N), New_Occurrence_Of (E_Calling_Stubs, Loc));
2524 end Expand_All_Calls_Remote_Subprogram_Call;
2526 ---------------------------------
2527 -- Expand_Calling_Stubs_Bodies --
2528 ---------------------------------
2530 procedure Expand_Calling_Stubs_Bodies (Unit_Node : Node_Id) is
2531 Spec : constant Node_Id := Specification (Unit_Node);
2532 Decls : constant List_Id := Visible_Declarations (Spec);
2533 begin
2534 New_Scope (Scope_Of_Spec (Spec));
2535 Add_Calling_Stubs_To_Declarations
2536 (Specification (Unit_Node), Decls);
2537 Pop_Scope;
2538 end Expand_Calling_Stubs_Bodies;
2540 -----------------------------------
2541 -- Expand_Receiving_Stubs_Bodies --
2542 -----------------------------------
2544 procedure Expand_Receiving_Stubs_Bodies (Unit_Node : Node_Id) is
2545 Spec : Node_Id;
2546 Decls : List_Id;
2547 Temp : List_Id;
2549 begin
2550 if Nkind (Unit_Node) = N_Package_Declaration then
2551 Spec := Specification (Unit_Node);
2552 Decls := Private_Declarations (Spec);
2554 if No (Decls) then
2555 Decls := Visible_Declarations (Spec);
2556 end if;
2558 New_Scope (Scope_Of_Spec (Spec));
2559 Specific_Add_Receiving_Stubs_To_Declarations (Spec, Decls);
2561 else
2562 Spec :=
2563 Package_Specification_Of_Scope (Corresponding_Spec (Unit_Node));
2564 Decls := Declarations (Unit_Node);
2565 New_Scope (Scope_Of_Spec (Unit_Node));
2566 Temp := New_List;
2567 Specific_Add_Receiving_Stubs_To_Declarations (Spec, Temp);
2568 Insert_List_Before (First (Decls), Temp);
2569 end if;
2571 Pop_Scope;
2572 end Expand_Receiving_Stubs_Bodies;
2574 --------------------
2575 -- GARLIC_Support --
2576 --------------------
2578 package body GARLIC_Support is
2580 -- Local subprograms
2582 procedure Add_RACW_Read_Attribute
2583 (RACW_Type : Entity_Id;
2584 Stub_Type : Entity_Id;
2585 Stub_Type_Access : Entity_Id;
2586 Declarations : List_Id);
2587 -- Add Read attribute in Decls for the RACW type. The Read attribute
2588 -- is added right after the RACW_Type declaration while the body is
2589 -- inserted after Declarations.
2591 procedure Add_RACW_Write_Attribute
2592 (RACW_Type : Entity_Id;
2593 Stub_Type : Entity_Id;
2594 Stub_Type_Access : Entity_Id;
2595 RPC_Receiver : Node_Id;
2596 Declarations : List_Id);
2597 -- Same thing for the Write attribute
2599 function Stream_Parameter return Node_Id;
2600 function Result return Node_Id;
2601 function Object return Node_Id renames Result;
2602 -- Functions to create occurrences of the formal parameter names of
2603 -- the 'Read and 'Write attributes.
2605 Loc : Source_Ptr;
2606 -- Shared source location used by Add_{Read,Write}_Read_Attribute
2607 -- and their ancillary subroutines (set on entry by Add_RACW_Features).
2609 procedure Add_RAS_Access_TSS (N : Node_Id);
2610 -- Add a subprogram body for RAS Access TSS
2612 -------------------------------------
2613 -- Add_Obj_RPC_Receiver_Completion --
2614 -------------------------------------
2616 procedure Add_Obj_RPC_Receiver_Completion
2617 (Loc : Source_Ptr;
2618 Decls : List_Id;
2619 RPC_Receiver : Entity_Id;
2620 Stub_Elements : Stub_Structure) is
2621 begin
2622 -- The RPC receiver body should not be the completion of the
2623 -- declaration recorded in the stub structure, because then the
2624 -- occurrences of the formal parameters within the body should
2625 -- refer to the entities from the declaration, not from the
2626 -- completion, to which we do not have easy access. Instead, the
2627 -- RPC receiver body acts as its own declaration, and the RPC
2628 -- receiver declaration is completed by a renaming-as-body.
2630 Append_To (Decls,
2631 Make_Subprogram_Renaming_Declaration (Loc,
2632 Specification =>
2633 Copy_Specification (Loc,
2634 Specification (Stub_Elements.RPC_Receiver_Decl)),
2635 Name => New_Occurrence_Of (RPC_Receiver, Loc)));
2636 end Add_Obj_RPC_Receiver_Completion;
2638 -----------------------
2639 -- Add_RACW_Features --
2640 -----------------------
2642 procedure Add_RACW_Features
2643 (RACW_Type : Entity_Id;
2644 Stub_Type : Entity_Id;
2645 Stub_Type_Access : Entity_Id;
2646 RPC_Receiver_Decl : Node_Id;
2647 Declarations : List_Id)
2649 RPC_Receiver : Node_Id;
2650 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
2652 begin
2653 Loc := Sloc (RACW_Type);
2655 if Is_RAS then
2657 -- For a RAS, the RPC receiver is that of the RCI unit,
2658 -- not that of the corresponding distributed object type.
2659 -- We retrieve its address from the local proxy object.
2661 RPC_Receiver := Make_Selected_Component (Loc,
2662 Prefix =>
2663 Unchecked_Convert_To (RTE (RE_RAS_Proxy_Type_Access), Object),
2664 Selector_Name => Make_Identifier (Loc, Name_Receiver));
2666 else
2667 RPC_Receiver := Make_Attribute_Reference (Loc,
2668 Prefix => New_Occurrence_Of (
2669 Defining_Unit_Name (Specification (RPC_Receiver_Decl)), Loc),
2670 Attribute_Name => Name_Address);
2671 end if;
2673 Add_RACW_Write_Attribute (
2674 RACW_Type,
2675 Stub_Type,
2676 Stub_Type_Access,
2677 RPC_Receiver,
2678 Declarations);
2680 Add_RACW_Read_Attribute (
2681 RACW_Type,
2682 Stub_Type,
2683 Stub_Type_Access,
2684 Declarations);
2685 end Add_RACW_Features;
2687 -----------------------------
2688 -- Add_RACW_Read_Attribute --
2689 -----------------------------
2691 procedure Add_RACW_Read_Attribute
2692 (RACW_Type : Entity_Id;
2693 Stub_Type : Entity_Id;
2694 Stub_Type_Access : Entity_Id;
2695 Declarations : List_Id)
2697 Proc_Decl : Node_Id;
2698 Attr_Decl : Node_Id;
2700 Body_Node : Node_Id;
2702 Decls : List_Id;
2703 Statements : List_Id;
2704 Local_Statements : List_Id;
2705 Remote_Statements : List_Id;
2706 -- Various parts of the procedure
2708 Procedure_Name : constant Name_Id :=
2709 New_Internal_Name ('R');
2710 Source_Partition : constant Entity_Id :=
2711 Make_Defining_Identifier
2712 (Loc, New_Internal_Name ('P'));
2713 Source_Receiver : constant Entity_Id :=
2714 Make_Defining_Identifier
2715 (Loc, New_Internal_Name ('S'));
2716 Source_Address : constant Entity_Id :=
2717 Make_Defining_Identifier
2718 (Loc, New_Internal_Name ('P'));
2719 Local_Stub : constant Entity_Id :=
2720 Make_Defining_Identifier
2721 (Loc, New_Internal_Name ('L'));
2722 Stubbed_Result : constant Entity_Id :=
2723 Make_Defining_Identifier
2724 (Loc, New_Internal_Name ('S'));
2725 Asynchronous_Flag : constant Entity_Id :=
2726 Asynchronous_Flags_Table.Get (RACW_Type);
2727 pragma Assert (Present (Asynchronous_Flag));
2729 -- Start of processing for Add_RACW_Read_Attribute
2731 begin
2732 -- Generate object declarations
2734 Decls := New_List (
2735 Make_Object_Declaration (Loc,
2736 Defining_Identifier => Source_Partition,
2737 Object_Definition =>
2738 New_Occurrence_Of (RTE (RE_Partition_ID), Loc)),
2740 Make_Object_Declaration (Loc,
2741 Defining_Identifier => Source_Receiver,
2742 Object_Definition =>
2743 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
2745 Make_Object_Declaration (Loc,
2746 Defining_Identifier => Source_Address,
2747 Object_Definition =>
2748 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
2750 Make_Object_Declaration (Loc,
2751 Defining_Identifier => Local_Stub,
2752 Aliased_Present => True,
2753 Object_Definition => New_Occurrence_Of (Stub_Type, Loc)),
2755 Make_Object_Declaration (Loc,
2756 Defining_Identifier => Stubbed_Result,
2757 Object_Definition =>
2758 New_Occurrence_Of (Stub_Type_Access, Loc),
2759 Expression =>
2760 Make_Attribute_Reference (Loc,
2761 Prefix =>
2762 New_Occurrence_Of (Local_Stub, Loc),
2763 Attribute_Name =>
2764 Name_Unchecked_Access)));
2766 -- Read the source Partition_ID and RPC_Receiver from incoming stream
2768 Statements := New_List (
2769 Make_Attribute_Reference (Loc,
2770 Prefix =>
2771 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
2772 Attribute_Name => Name_Read,
2773 Expressions => New_List (
2774 Stream_Parameter,
2775 New_Occurrence_Of (Source_Partition, Loc))),
2777 Make_Attribute_Reference (Loc,
2778 Prefix =>
2779 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
2780 Attribute_Name =>
2781 Name_Read,
2782 Expressions => New_List (
2783 Stream_Parameter,
2784 New_Occurrence_Of (Source_Receiver, Loc))),
2786 Make_Attribute_Reference (Loc,
2787 Prefix =>
2788 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
2789 Attribute_Name =>
2790 Name_Read,
2791 Expressions => New_List (
2792 Stream_Parameter,
2793 New_Occurrence_Of (Source_Address, Loc))));
2795 -- Build_Get_Unique_RP_Call needs the type of Stubbed_Result
2797 Set_Etype (Stubbed_Result, Stub_Type_Access);
2799 -- If the Address is Null_Address, then return a null object
2801 Append_To (Statements,
2802 Make_Implicit_If_Statement (RACW_Type,
2803 Condition =>
2804 Make_Op_Eq (Loc,
2805 Left_Opnd => New_Occurrence_Of (Source_Address, Loc),
2806 Right_Opnd => Make_Integer_Literal (Loc, Uint_0)),
2807 Then_Statements => New_List (
2808 Make_Assignment_Statement (Loc,
2809 Name => Result,
2810 Expression => Make_Null (Loc)),
2811 Make_Return_Statement (Loc))));
2813 -- If the RACW denotes an object created on the current partition,
2814 -- Local_Statements will be executed. The real object will be used.
2816 Local_Statements := New_List (
2817 Make_Assignment_Statement (Loc,
2818 Name => Result,
2819 Expression =>
2820 Unchecked_Convert_To (RACW_Type,
2821 OK_Convert_To (RTE (RE_Address),
2822 New_Occurrence_Of (Source_Address, Loc)))));
2824 -- If the object is located on another partition, then a stub object
2825 -- will be created with all the information needed to rebuild the
2826 -- real object at the other end.
2828 Remote_Statements := New_List (
2830 Make_Assignment_Statement (Loc,
2831 Name => Make_Selected_Component (Loc,
2832 Prefix => Stubbed_Result,
2833 Selector_Name => Name_Origin),
2834 Expression =>
2835 New_Occurrence_Of (Source_Partition, Loc)),
2837 Make_Assignment_Statement (Loc,
2838 Name => Make_Selected_Component (Loc,
2839 Prefix => Stubbed_Result,
2840 Selector_Name => Name_Receiver),
2841 Expression =>
2842 New_Occurrence_Of (Source_Receiver, Loc)),
2844 Make_Assignment_Statement (Loc,
2845 Name => Make_Selected_Component (Loc,
2846 Prefix => Stubbed_Result,
2847 Selector_Name => Name_Addr),
2848 Expression =>
2849 New_Occurrence_Of (Source_Address, Loc)));
2851 Append_To (Remote_Statements,
2852 Make_Assignment_Statement (Loc,
2853 Name => Make_Selected_Component (Loc,
2854 Prefix => Stubbed_Result,
2855 Selector_Name => Name_Asynchronous),
2856 Expression =>
2857 New_Occurrence_Of (Asynchronous_Flag, Loc)));
2859 Append_List_To (Remote_Statements,
2860 Build_Get_Unique_RP_Call (Loc, Stubbed_Result, Stub_Type));
2861 -- ??? Issue with asynchronous calls here: the Asynchronous
2862 -- flag is set on the stub type if, and only if, the RACW type
2863 -- has a pragma Asynchronous. This is incorrect for RACWs that
2864 -- implement RAS types, because in that case the /designated
2865 -- subprogram/ (not the type) might be asynchronous, and
2866 -- that causes the stub to need to be asynchronous too.
2867 -- A solution is to transport a RAS as a struct containing
2868 -- a RACW and an asynchronous flag, and to properly alter
2869 -- the Asynchronous component in the stub type in the RAS's
2870 -- Input TSS.
2872 Append_To (Remote_Statements,
2873 Make_Assignment_Statement (Loc,
2874 Name => Result,
2875 Expression => Unchecked_Convert_To (RACW_Type,
2876 New_Occurrence_Of (Stubbed_Result, Loc))));
2878 -- Distinguish between the local and remote cases, and execute the
2879 -- appropriate piece of code.
2881 Append_To (Statements,
2882 Make_Implicit_If_Statement (RACW_Type,
2883 Condition =>
2884 Make_Op_Eq (Loc,
2885 Left_Opnd =>
2886 Make_Function_Call (Loc,
2887 Name => New_Occurrence_Of (
2888 RTE (RE_Get_Local_Partition_Id), Loc)),
2889 Right_Opnd => New_Occurrence_Of (Source_Partition, Loc)),
2890 Then_Statements => Local_Statements,
2891 Else_Statements => Remote_Statements));
2893 Build_Stream_Procedure
2894 (Loc, RACW_Type, Body_Node,
2895 Make_Defining_Identifier (Loc, Procedure_Name),
2896 Statements, Outp => True);
2897 Set_Declarations (Body_Node, Decls);
2899 Proc_Decl := Make_Subprogram_Declaration (Loc,
2900 Copy_Specification (Loc, Specification (Body_Node)));
2902 Attr_Decl :=
2903 Make_Attribute_Definition_Clause (Loc,
2904 Name => New_Occurrence_Of (RACW_Type, Loc),
2905 Chars => Name_Read,
2906 Expression =>
2907 New_Occurrence_Of (
2908 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
2910 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
2911 Insert_After (Proc_Decl, Attr_Decl);
2912 Append_To (Declarations, Body_Node);
2913 end Add_RACW_Read_Attribute;
2915 ------------------------------
2916 -- Add_RACW_Write_Attribute --
2917 ------------------------------
2919 procedure Add_RACW_Write_Attribute
2920 (RACW_Type : Entity_Id;
2921 Stub_Type : Entity_Id;
2922 Stub_Type_Access : Entity_Id;
2923 RPC_Receiver : Node_Id;
2924 Declarations : List_Id)
2926 Body_Node : Node_Id;
2927 Proc_Decl : Node_Id;
2928 Attr_Decl : Node_Id;
2930 Statements : List_Id;
2931 Local_Statements : List_Id;
2932 Remote_Statements : List_Id;
2933 Null_Statements : List_Id;
2935 Procedure_Name : constant Name_Id := New_Internal_Name ('R');
2937 begin
2938 -- Build the code fragment corresponding to the marshalling of a
2939 -- local object.
2941 Local_Statements := New_List (
2943 Pack_Entity_Into_Stream_Access (Loc,
2944 Stream => Stream_Parameter,
2945 Object => RTE (RE_Get_Local_Partition_Id)),
2947 Pack_Node_Into_Stream_Access (Loc,
2948 Stream => Stream_Parameter,
2949 Object => OK_Convert_To (RTE (RE_Unsigned_64), RPC_Receiver),
2950 Etyp => RTE (RE_Unsigned_64)),
2952 Pack_Node_Into_Stream_Access (Loc,
2953 Stream => Stream_Parameter,
2954 Object => OK_Convert_To (RTE (RE_Unsigned_64),
2955 Make_Attribute_Reference (Loc,
2956 Prefix =>
2957 Make_Explicit_Dereference (Loc,
2958 Prefix => Object),
2959 Attribute_Name => Name_Address)),
2960 Etyp => RTE (RE_Unsigned_64)));
2962 -- Build the code fragment corresponding to the marshalling of
2963 -- a remote object.
2965 Remote_Statements := New_List (
2967 Pack_Node_Into_Stream_Access (Loc,
2968 Stream => Stream_Parameter,
2969 Object =>
2970 Make_Selected_Component (Loc,
2971 Prefix => Unchecked_Convert_To (Stub_Type_Access,
2972 Object),
2973 Selector_Name =>
2974 Make_Identifier (Loc, Name_Origin)),
2975 Etyp => RTE (RE_Partition_ID)),
2977 Pack_Node_Into_Stream_Access (Loc,
2978 Stream => Stream_Parameter,
2979 Object =>
2980 Make_Selected_Component (Loc,
2981 Prefix => Unchecked_Convert_To (Stub_Type_Access,
2982 Object),
2983 Selector_Name =>
2984 Make_Identifier (Loc, Name_Receiver)),
2985 Etyp => RTE (RE_Unsigned_64)),
2987 Pack_Node_Into_Stream_Access (Loc,
2988 Stream => Stream_Parameter,
2989 Object =>
2990 Make_Selected_Component (Loc,
2991 Prefix => Unchecked_Convert_To (Stub_Type_Access,
2992 Object),
2993 Selector_Name =>
2994 Make_Identifier (Loc, Name_Addr)),
2995 Etyp => RTE (RE_Unsigned_64)));
2997 -- Build code fragment corresponding to marshalling of a null object
2999 Null_Statements := New_List (
3001 Pack_Entity_Into_Stream_Access (Loc,
3002 Stream => Stream_Parameter,
3003 Object => RTE (RE_Get_Local_Partition_Id)),
3005 Pack_Node_Into_Stream_Access (Loc,
3006 Stream => Stream_Parameter,
3007 Object => OK_Convert_To (RTE (RE_Unsigned_64), RPC_Receiver),
3008 Etyp => RTE (RE_Unsigned_64)),
3010 Pack_Node_Into_Stream_Access (Loc,
3011 Stream => Stream_Parameter,
3012 Object => Make_Integer_Literal (Loc, Uint_0),
3013 Etyp => RTE (RE_Unsigned_64)));
3015 Statements := New_List (
3016 Make_Implicit_If_Statement (RACW_Type,
3017 Condition =>
3018 Make_Op_Eq (Loc,
3019 Left_Opnd => Object,
3020 Right_Opnd => Make_Null (Loc)),
3021 Then_Statements => Null_Statements,
3022 Elsif_Parts => New_List (
3023 Make_Elsif_Part (Loc,
3024 Condition =>
3025 Make_Op_Eq (Loc,
3026 Left_Opnd =>
3027 Make_Attribute_Reference (Loc,
3028 Prefix => Object,
3029 Attribute_Name => Name_Tag),
3030 Right_Opnd =>
3031 Make_Attribute_Reference (Loc,
3032 Prefix => New_Occurrence_Of (Stub_Type, Loc),
3033 Attribute_Name => Name_Tag)),
3034 Then_Statements => Remote_Statements)),
3035 Else_Statements => Local_Statements));
3037 Build_Stream_Procedure
3038 (Loc, RACW_Type, Body_Node,
3039 Make_Defining_Identifier (Loc, Procedure_Name),
3040 Statements, Outp => False);
3042 Proc_Decl := Make_Subprogram_Declaration (Loc,
3043 Copy_Specification (Loc, Specification (Body_Node)));
3045 Attr_Decl :=
3046 Make_Attribute_Definition_Clause (Loc,
3047 Name => New_Occurrence_Of (RACW_Type, Loc),
3048 Chars => Name_Write,
3049 Expression =>
3050 New_Occurrence_Of (
3051 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
3053 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
3054 Insert_After (Proc_Decl, Attr_Decl);
3055 Append_To (Declarations, Body_Node);
3056 end Add_RACW_Write_Attribute;
3058 ------------------------
3059 -- Add_RAS_Access_TSS --
3060 ------------------------
3062 procedure Add_RAS_Access_TSS (N : Node_Id) is
3063 Loc : constant Source_Ptr := Sloc (N);
3065 Ras_Type : constant Entity_Id := Defining_Identifier (N);
3066 Fat_Type : constant Entity_Id := Equivalent_Type (Ras_Type);
3067 -- Ras_Type is the access to subprogram type while Fat_Type is the
3068 -- corresponding record type.
3070 RACW_Type : constant Entity_Id :=
3071 Underlying_RACW_Type (Ras_Type);
3072 Desig : constant Entity_Id :=
3073 Etype (Designated_Type (RACW_Type));
3075 Stub_Elements : constant Stub_Structure :=
3076 Stubs_Table.Get (Desig);
3077 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
3079 Proc : constant Entity_Id :=
3080 Make_Defining_Identifier (Loc,
3081 Chars => Make_TSS_Name (Ras_Type, TSS_RAS_Access));
3083 Proc_Spec : Node_Id;
3085 -- Formal parameters
3087 Package_Name : constant Entity_Id :=
3088 Make_Defining_Identifier (Loc,
3089 Chars => Name_P);
3090 -- Target package
3092 Subp_Id : constant Entity_Id :=
3093 Make_Defining_Identifier (Loc,
3094 Chars => Name_S);
3095 -- Target subprogram
3097 Asynch_P : constant Entity_Id :=
3098 Make_Defining_Identifier (Loc,
3099 Chars => Name_Asynchronous);
3100 -- Is the procedure to which the 'Access applies asynchronous?
3102 All_Calls_Remote : constant Entity_Id :=
3103 Make_Defining_Identifier (Loc,
3104 Chars => Name_All_Calls_Remote);
3105 -- True if an All_Calls_Remote pragma applies to the RCI unit
3106 -- that contains the subprogram.
3108 -- Common local variables
3110 Proc_Decls : List_Id;
3111 Proc_Statements : List_Id;
3113 Origin : constant Entity_Id :=
3114 Make_Defining_Identifier (Loc,
3115 Chars => New_Internal_Name ('P'));
3117 -- Additional local variables for the local case
3119 Proxy_Addr : constant Entity_Id :=
3120 Make_Defining_Identifier (Loc,
3121 Chars => New_Internal_Name ('P'));
3123 -- Additional local variables for the remote case
3125 Local_Stub : constant Entity_Id :=
3126 Make_Defining_Identifier (Loc,
3127 Chars => New_Internal_Name ('L'));
3129 Stub_Ptr : constant Entity_Id :=
3130 Make_Defining_Identifier (Loc,
3131 Chars => New_Internal_Name ('S'));
3133 function Set_Field
3134 (Field_Name : Name_Id;
3135 Value : Node_Id) return Node_Id;
3136 -- Construct an assignment that sets the named component in the
3137 -- returned record
3139 ---------------
3140 -- Set_Field --
3141 ---------------
3143 function Set_Field
3144 (Field_Name : Name_Id;
3145 Value : Node_Id) return Node_Id
3147 begin
3148 return
3149 Make_Assignment_Statement (Loc,
3150 Name =>
3151 Make_Selected_Component (Loc,
3152 Prefix => Stub_Ptr,
3153 Selector_Name => Field_Name),
3154 Expression => Value);
3155 end Set_Field;
3157 -- Start of processing for Add_RAS_Access_TSS
3159 begin
3160 Proc_Decls := New_List (
3162 -- Common declarations
3164 Make_Object_Declaration (Loc,
3165 Defining_Identifier => Origin,
3166 Constant_Present => True,
3167 Object_Definition =>
3168 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
3169 Expression =>
3170 Make_Function_Call (Loc,
3171 Name =>
3172 New_Occurrence_Of (RTE (RE_Get_Active_Partition_Id), Loc),
3173 Parameter_Associations => New_List (
3174 New_Occurrence_Of (Package_Name, Loc)))),
3176 -- Declaration use only in the local case: proxy address
3178 Make_Object_Declaration (Loc,
3179 Defining_Identifier => Proxy_Addr,
3180 Object_Definition =>
3181 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)),
3183 -- Declarations used only in the remote case: stub object and
3184 -- stub pointer.
3186 Make_Object_Declaration (Loc,
3187 Defining_Identifier => Local_Stub,
3188 Aliased_Present => True,
3189 Object_Definition =>
3190 New_Occurrence_Of (Stub_Elements.Stub_Type, Loc)),
3192 Make_Object_Declaration (Loc,
3193 Defining_Identifier =>
3194 Stub_Ptr,
3195 Object_Definition =>
3196 New_Occurrence_Of (Stub_Elements.Stub_Type_Access, Loc),
3197 Expression =>
3198 Make_Attribute_Reference (Loc,
3199 Prefix => New_Occurrence_Of (Local_Stub, Loc),
3200 Attribute_Name => Name_Unchecked_Access)));
3202 Set_Etype (Stub_Ptr, Stub_Elements.Stub_Type_Access);
3203 -- Build_Get_Unique_RP_Call needs this information
3205 -- Note: Here we assume that the Fat_Type is a record
3206 -- containing just a pointer to a proxy or stub object.
3208 Proc_Statements := New_List (
3210 -- Generate:
3212 -- Get_RAS_Info (Pkg, Subp, PA);
3213 -- if Origin = Local_Partition_Id
3214 -- and then not All_Calls_Remote
3215 -- then
3216 -- return Fat_Type!(PA);
3217 -- end if;
3219 Make_Procedure_Call_Statement (Loc,
3220 Name =>
3221 New_Occurrence_Of (RTE (RE_Get_RAS_Info), Loc),
3222 Parameter_Associations => New_List (
3223 New_Occurrence_Of (Package_Name, Loc),
3224 New_Occurrence_Of (Subp_Id, Loc),
3225 New_Occurrence_Of (Proxy_Addr, Loc))),
3227 Make_Implicit_If_Statement (N,
3228 Condition =>
3229 Make_And_Then (Loc,
3230 Left_Opnd =>
3231 Make_Op_Eq (Loc,
3232 Left_Opnd =>
3233 New_Occurrence_Of (Origin, Loc),
3234 Right_Opnd =>
3235 Make_Function_Call (Loc,
3236 New_Occurrence_Of (
3237 RTE (RE_Get_Local_Partition_Id), Loc))),
3238 Right_Opnd =>
3239 Make_Op_Not (Loc,
3240 New_Occurrence_Of (All_Calls_Remote, Loc))),
3241 Then_Statements => New_List (
3242 Make_Return_Statement (Loc,
3243 Unchecked_Convert_To (Fat_Type,
3244 OK_Convert_To (RTE (RE_Address),
3245 New_Occurrence_Of (Proxy_Addr, Loc)))))),
3247 Set_Field (Name_Origin,
3248 New_Occurrence_Of (Origin, Loc)),
3250 Set_Field (Name_Receiver,
3251 Make_Function_Call (Loc,
3252 Name =>
3253 New_Occurrence_Of (RTE (RE_Get_RCI_Package_Receiver), Loc),
3254 Parameter_Associations => New_List (
3255 New_Occurrence_Of (Package_Name, Loc)))),
3257 Set_Field (Name_Addr, New_Occurrence_Of (Proxy_Addr, Loc)),
3259 -- E.4.1(9) A remote call is asynchronous if it is a call to
3260 -- a procedure, or a call through a value of an access-to-procedure
3261 -- type, to which a pragma Asynchronous applies.
3263 -- Parameter Asynch_P is true when the procedure is asynchronous;
3264 -- Expression Asynch_T is true when the type is asynchronous.
3266 Set_Field (Name_Asynchronous,
3267 Make_Or_Else (Loc,
3268 New_Occurrence_Of (Asynch_P, Loc),
3269 New_Occurrence_Of (Boolean_Literals (
3270 Is_Asynchronous (Ras_Type)), Loc))));
3272 Append_List_To (Proc_Statements,
3273 Build_Get_Unique_RP_Call
3274 (Loc, Stub_Ptr, Stub_Elements.Stub_Type));
3276 -- Return the newly created value
3278 Append_To (Proc_Statements,
3279 Make_Return_Statement (Loc,
3280 Expression =>
3281 Unchecked_Convert_To (Fat_Type,
3282 New_Occurrence_Of (Stub_Ptr, Loc))));
3284 Proc_Spec :=
3285 Make_Function_Specification (Loc,
3286 Defining_Unit_Name => Proc,
3287 Parameter_Specifications => New_List (
3288 Make_Parameter_Specification (Loc,
3289 Defining_Identifier => Package_Name,
3290 Parameter_Type =>
3291 New_Occurrence_Of (Standard_String, Loc)),
3293 Make_Parameter_Specification (Loc,
3294 Defining_Identifier => Subp_Id,
3295 Parameter_Type =>
3296 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc)),
3298 Make_Parameter_Specification (Loc,
3299 Defining_Identifier => Asynch_P,
3300 Parameter_Type =>
3301 New_Occurrence_Of (Standard_Boolean, Loc)),
3303 Make_Parameter_Specification (Loc,
3304 Defining_Identifier => All_Calls_Remote,
3305 Parameter_Type =>
3306 New_Occurrence_Of (Standard_Boolean, Loc))),
3308 Result_Definition =>
3309 New_Occurrence_Of (Fat_Type, Loc));
3311 -- Set the kind and return type of the function to prevent
3312 -- ambiguities between Ras_Type and Fat_Type in subsequent analysis.
3314 Set_Ekind (Proc, E_Function);
3315 Set_Etype (Proc, Fat_Type);
3317 Discard_Node (
3318 Make_Subprogram_Body (Loc,
3319 Specification => Proc_Spec,
3320 Declarations => Proc_Decls,
3321 Handled_Statement_Sequence =>
3322 Make_Handled_Sequence_Of_Statements (Loc,
3323 Statements => Proc_Statements)));
3325 Set_TSS (Fat_Type, Proc);
3326 end Add_RAS_Access_TSS;
3328 -----------------------
3329 -- Add_RAST_Features --
3330 -----------------------
3332 procedure Add_RAST_Features
3333 (Vis_Decl : Node_Id;
3334 RAS_Type : Entity_Id)
3336 pragma Warnings (Off);
3337 pragma Unreferenced (RAS_Type);
3338 pragma Warnings (On);
3339 begin
3340 Add_RAS_Access_TSS (Vis_Decl);
3341 end Add_RAST_Features;
3343 -----------------------------------------
3344 -- Add_Receiving_Stubs_To_Declarations --
3345 -----------------------------------------
3347 procedure Add_Receiving_Stubs_To_Declarations
3348 (Pkg_Spec : Node_Id;
3349 Decls : List_Id)
3351 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
3353 Request_Parameter : Node_Id;
3355 Pkg_RPC_Receiver : constant Entity_Id :=
3356 Make_Defining_Identifier (Loc,
3357 New_Internal_Name ('H'));
3358 Pkg_RPC_Receiver_Statements : List_Id;
3359 Pkg_RPC_Receiver_Cases : constant List_Id := New_List;
3360 Pkg_RPC_Receiver_Body : Node_Id;
3361 -- A Pkg_RPC_Receiver is built to decode the request
3363 Lookup_RAS_Info : constant Entity_Id :=
3364 Make_Defining_Identifier (Loc,
3365 Chars => New_Internal_Name ('R'));
3366 -- A remote subprogram is created to allow peers to look up
3367 -- RAS information using subprogram ids.
3369 Subp_Id : Entity_Id;
3370 Subp_Index : Entity_Id;
3371 -- Subprogram_Id as read from the incoming stream
3373 Current_Declaration : Node_Id;
3374 Current_Subprogram_Number : Int := First_RCI_Subprogram_Id;
3375 Current_Stubs : Node_Id;
3377 Subp_Info_Array : constant Entity_Id :=
3378 Make_Defining_Identifier (Loc,
3379 Chars => New_Internal_Name ('I'));
3381 Subp_Info_List : constant List_Id := New_List;
3383 Register_Pkg_Actuals : constant List_Id := New_List;
3385 All_Calls_Remote_E : Entity_Id;
3386 Proxy_Object_Addr : Entity_Id;
3388 procedure Append_Stubs_To
3389 (RPC_Receiver_Cases : List_Id;
3390 Stubs : Node_Id;
3391 Subprogram_Number : Int);
3392 -- Add one case to the specified RPC receiver case list
3393 -- associating Subprogram_Number with the subprogram declared
3394 -- by Declaration, for which we have receiving stubs in Stubs.
3396 ---------------------
3397 -- Append_Stubs_To --
3398 ---------------------
3400 procedure Append_Stubs_To
3401 (RPC_Receiver_Cases : List_Id;
3402 Stubs : Node_Id;
3403 Subprogram_Number : Int)
3405 begin
3406 Append_To (RPC_Receiver_Cases,
3407 Make_Case_Statement_Alternative (Loc,
3408 Discrete_Choices =>
3409 New_List (Make_Integer_Literal (Loc, Subprogram_Number)),
3410 Statements =>
3411 New_List (
3412 Make_Procedure_Call_Statement (Loc,
3413 Name =>
3414 New_Occurrence_Of (
3415 Defining_Entity (Stubs), Loc),
3416 Parameter_Associations => New_List (
3417 New_Occurrence_Of (Request_Parameter, Loc))))));
3418 end Append_Stubs_To;
3420 -- Start of processing for Add_Receiving_Stubs_To_Declarations
3422 begin
3423 -- Building receiving stubs consist in several operations:
3425 -- - a package RPC receiver must be built. This subprogram
3426 -- will get a Subprogram_Id from the incoming stream
3427 -- and will dispatch the call to the right subprogram
3429 -- - a receiving stub for any subprogram visible in the package
3430 -- spec. This stub will read all the parameters from the stream,
3431 -- and put the result as well as the exception occurrence in the
3432 -- output stream
3434 -- - a dummy package with an empty spec and a body made of an
3435 -- elaboration part, whose job is to register the receiving
3436 -- part of this RCI package on the name server. This is done
3437 -- by calling System.Partition_Interface.Register_Receiving_Stub
3439 Build_RPC_Receiver_Body (
3440 RPC_Receiver => Pkg_RPC_Receiver,
3441 Request => Request_Parameter,
3442 Subp_Id => Subp_Id,
3443 Subp_Index => Subp_Index,
3444 Stmts => Pkg_RPC_Receiver_Statements,
3445 Decl => Pkg_RPC_Receiver_Body);
3446 pragma Assert (Subp_Id = Subp_Index);
3448 -- A null subp_id denotes a call through a RAS, in which case the
3449 -- next Uint_64 element in the stream is the address of the local
3450 -- proxy object, from which we can retrieve the actual subprogram id.
3452 Append_To (Pkg_RPC_Receiver_Statements,
3453 Make_Implicit_If_Statement (Pkg_Spec,
3454 Condition =>
3455 Make_Op_Eq (Loc,
3456 New_Occurrence_Of (Subp_Id, Loc),
3457 Make_Integer_Literal (Loc, 0)),
3458 Then_Statements => New_List (
3459 Make_Assignment_Statement (Loc,
3460 Name =>
3461 New_Occurrence_Of (Subp_Id, Loc),
3462 Expression =>
3463 Make_Selected_Component (Loc,
3464 Prefix =>
3465 Unchecked_Convert_To (RTE (RE_RAS_Proxy_Type_Access),
3466 OK_Convert_To (RTE (RE_Address),
3467 Make_Attribute_Reference (Loc,
3468 Prefix =>
3469 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
3470 Attribute_Name =>
3471 Name_Input,
3472 Expressions => New_List (
3473 Make_Selected_Component (Loc,
3474 Prefix => Request_Parameter,
3475 Selector_Name => Name_Params))))),
3476 Selector_Name =>
3477 Make_Identifier (Loc, Name_Subp_Id))))));
3479 -- Build a subprogram for RAS information lookups
3481 Current_Declaration :=
3482 Make_Subprogram_Declaration (Loc,
3483 Specification =>
3484 Make_Function_Specification (Loc,
3485 Defining_Unit_Name =>
3486 Lookup_RAS_Info,
3487 Parameter_Specifications => New_List (
3488 Make_Parameter_Specification (Loc,
3489 Defining_Identifier =>
3490 Make_Defining_Identifier (Loc, Name_Subp_Id),
3491 In_Present =>
3492 True,
3493 Parameter_Type =>
3494 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc))),
3495 Result_Definition =>
3496 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc)));
3497 Append_To (Decls, Current_Declaration);
3498 Analyze (Current_Declaration);
3500 Current_Stubs := Build_Subprogram_Receiving_Stubs
3501 (Vis_Decl => Current_Declaration,
3502 Asynchronous => False);
3503 Append_To (Decls, Current_Stubs);
3504 Analyze (Current_Stubs);
3506 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
3507 Stubs =>
3508 Current_Stubs,
3509 Subprogram_Number => 1);
3511 -- For each subprogram, the receiving stub will be built and a
3512 -- case statement will be made on the Subprogram_Id to dispatch
3513 -- to the right subprogram.
3515 All_Calls_Remote_E := Boolean_Literals (
3516 Has_All_Calls_Remote (Defining_Entity (Pkg_Spec)));
3518 Overload_Counter_Table.Reset;
3520 Current_Declaration := First (Visible_Declarations (Pkg_Spec));
3521 while Present (Current_Declaration) loop
3522 if Nkind (Current_Declaration) = N_Subprogram_Declaration
3523 and then Comes_From_Source (Current_Declaration)
3524 then
3525 declare
3526 Loc : constant Source_Ptr :=
3527 Sloc (Current_Declaration);
3528 -- While specifically processing Current_Declaration, use
3529 -- its Sloc as the location of all generated nodes.
3531 Subp_Def : constant Entity_Id :=
3532 Defining_Unit_Name
3533 (Specification (Current_Declaration));
3535 Subp_Val : String_Id;
3537 begin
3538 -- Build receiving stub
3540 Current_Stubs :=
3541 Build_Subprogram_Receiving_Stubs
3542 (Vis_Decl => Current_Declaration,
3543 Asynchronous =>
3544 Nkind (Specification (Current_Declaration)) =
3545 N_Procedure_Specification
3546 and then Is_Asynchronous (Subp_Def));
3548 Append_To (Decls, Current_Stubs);
3549 Analyze (Current_Stubs);
3551 -- Build RAS proxy
3553 Add_RAS_Proxy_And_Analyze (Decls,
3554 Vis_Decl =>
3555 Current_Declaration,
3556 All_Calls_Remote_E =>
3557 All_Calls_Remote_E,
3558 Proxy_Object_Addr =>
3559 Proxy_Object_Addr);
3561 -- Compute distribution identifier
3563 Assign_Subprogram_Identifier (
3564 Subp_Def,
3565 Current_Subprogram_Number,
3566 Subp_Val);
3568 pragma Assert (Current_Subprogram_Number =
3569 Get_Subprogram_Id (Subp_Def));
3571 -- Add subprogram descriptor (RCI_Subp_Info) to the
3572 -- subprograms table for this receiver. The aggregate
3573 -- below must be kept consistent with the declaration
3574 -- of type RCI_Subp_Info in System.Partition_Interface.
3576 Append_To (Subp_Info_List,
3577 Make_Component_Association (Loc,
3578 Choices => New_List (
3579 Make_Integer_Literal (Loc,
3580 Current_Subprogram_Number)),
3581 Expression =>
3582 Make_Aggregate (Loc,
3583 Component_Associations => New_List (
3584 Make_Component_Association (Loc,
3585 Choices => New_List (
3586 Make_Identifier (Loc, Name_Addr)),
3587 Expression =>
3588 New_Occurrence_Of (
3589 Proxy_Object_Addr, Loc))))));
3591 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
3592 Stubs =>
3593 Current_Stubs,
3594 Subprogram_Number =>
3595 Current_Subprogram_Number);
3596 end;
3598 Current_Subprogram_Number := Current_Subprogram_Number + 1;
3599 end if;
3601 Next (Current_Declaration);
3602 end loop;
3604 -- If we receive an invalid Subprogram_Id, it is best to do nothing
3605 -- rather than raising an exception since we do not want someone
3606 -- to crash a remote partition by sending invalid subprogram ids.
3607 -- This is consistent with the other parts of the case statement
3608 -- since even in presence of incorrect parameters in the stream,
3609 -- every exception will be caught and (if the subprogram is not an
3610 -- APC) put into the result stream and sent away.
3612 Append_To (Pkg_RPC_Receiver_Cases,
3613 Make_Case_Statement_Alternative (Loc,
3614 Discrete_Choices =>
3615 New_List (Make_Others_Choice (Loc)),
3616 Statements =>
3617 New_List (Make_Null_Statement (Loc))));
3619 Append_To (Pkg_RPC_Receiver_Statements,
3620 Make_Case_Statement (Loc,
3621 Expression =>
3622 New_Occurrence_Of (Subp_Id, Loc),
3623 Alternatives => Pkg_RPC_Receiver_Cases));
3625 Append_To (Decls,
3626 Make_Object_Declaration (Loc,
3627 Defining_Identifier => Subp_Info_Array,
3628 Constant_Present => True,
3629 Aliased_Present => True,
3630 Object_Definition =>
3631 Make_Subtype_Indication (Loc,
3632 Subtype_Mark =>
3633 New_Occurrence_Of (RTE (RE_RCI_Subp_Info_Array), Loc),
3634 Constraint =>
3635 Make_Index_Or_Discriminant_Constraint (Loc,
3636 New_List (
3637 Make_Range (Loc,
3638 Low_Bound => Make_Integer_Literal (Loc,
3639 First_RCI_Subprogram_Id),
3640 High_Bound =>
3641 Make_Integer_Literal (Loc,
3642 First_RCI_Subprogram_Id
3643 + List_Length (Subp_Info_List) - 1))))),
3644 Expression =>
3645 Make_Aggregate (Loc,
3646 Component_Associations => Subp_Info_List)));
3647 Analyze (Last (Decls));
3649 Append_To (Decls,
3650 Make_Subprogram_Body (Loc,
3651 Specification =>
3652 Copy_Specification (Loc, Parent (Lookup_RAS_Info)),
3653 Declarations =>
3654 No_List,
3655 Handled_Statement_Sequence =>
3656 Make_Handled_Sequence_Of_Statements (Loc,
3657 Statements => New_List (
3658 Make_Return_Statement (Loc,
3659 Expression => OK_Convert_To (RTE (RE_Unsigned_64),
3660 Make_Selected_Component (Loc,
3661 Prefix =>
3662 Make_Indexed_Component (Loc,
3663 Prefix =>
3664 New_Occurrence_Of (Subp_Info_Array, Loc),
3665 Expressions => New_List (
3666 Convert_To (Standard_Integer,
3667 Make_Identifier (Loc, Name_Subp_Id)))),
3668 Selector_Name =>
3669 Make_Identifier (Loc, Name_Addr))))))));
3670 Analyze (Last (Decls));
3672 Append_To (Decls, Pkg_RPC_Receiver_Body);
3673 Analyze (Last (Decls));
3675 Get_Library_Unit_Name_String (Pkg_Spec);
3676 Append_To (Register_Pkg_Actuals,
3677 -- Name
3678 Make_String_Literal (Loc,
3679 Strval => String_From_Name_Buffer));
3681 Append_To (Register_Pkg_Actuals,
3682 -- Receiver
3683 Make_Attribute_Reference (Loc,
3684 Prefix =>
3685 New_Occurrence_Of (Pkg_RPC_Receiver, Loc),
3686 Attribute_Name =>
3687 Name_Unrestricted_Access));
3689 Append_To (Register_Pkg_Actuals,
3690 -- Version
3691 Make_Attribute_Reference (Loc,
3692 Prefix =>
3693 New_Occurrence_Of (Defining_Entity (Pkg_Spec), Loc),
3694 Attribute_Name =>
3695 Name_Version));
3697 Append_To (Register_Pkg_Actuals,
3698 -- Subp_Info
3699 Make_Attribute_Reference (Loc,
3700 Prefix =>
3701 New_Occurrence_Of (Subp_Info_Array, Loc),
3702 Attribute_Name =>
3703 Name_Address));
3705 Append_To (Register_Pkg_Actuals,
3706 -- Subp_Info_Len
3707 Make_Attribute_Reference (Loc,
3708 Prefix =>
3709 New_Occurrence_Of (Subp_Info_Array, Loc),
3710 Attribute_Name =>
3711 Name_Length));
3713 Append_To (Decls,
3714 Make_Procedure_Call_Statement (Loc,
3715 Name =>
3716 New_Occurrence_Of (RTE (RE_Register_Receiving_Stub), Loc),
3717 Parameter_Associations => Register_Pkg_Actuals));
3718 Analyze (Last (Decls));
3719 end Add_Receiving_Stubs_To_Declarations;
3721 ---------------------------------
3722 -- Build_General_Calling_Stubs --
3723 ---------------------------------
3725 procedure Build_General_Calling_Stubs
3726 (Decls : List_Id;
3727 Statements : List_Id;
3728 Target_Partition : Entity_Id;
3729 Target_RPC_Receiver : Node_Id;
3730 Subprogram_Id : Node_Id;
3731 Asynchronous : Node_Id := Empty;
3732 Is_Known_Asynchronous : Boolean := False;
3733 Is_Known_Non_Asynchronous : Boolean := False;
3734 Is_Function : Boolean;
3735 Spec : Node_Id;
3736 Stub_Type : Entity_Id := Empty;
3737 RACW_Type : Entity_Id := Empty;
3738 Nod : Node_Id)
3740 Loc : constant Source_Ptr := Sloc (Nod);
3742 Stream_Parameter : Node_Id;
3743 -- Name of the stream used to transmit parameters to the
3744 -- remote package.
3746 Result_Parameter : Node_Id;
3747 -- Name of the result parameter (in non-APC cases) which get the
3748 -- result of the remote subprogram.
3750 Exception_Return_Parameter : Node_Id;
3751 -- Name of the parameter which will hold the exception sent by the
3752 -- remote subprogram.
3754 Current_Parameter : Node_Id;
3755 -- Current parameter being handled
3757 Ordered_Parameters_List : constant List_Id :=
3758 Build_Ordered_Parameters_List (Spec);
3760 Asynchronous_Statements : List_Id := No_List;
3761 Non_Asynchronous_Statements : List_Id := No_List;
3762 -- Statements specifics to the Asynchronous/Non-Asynchronous cases
3764 Extra_Formal_Statements : constant List_Id := New_List;
3765 -- List of statements for extra formal parameters. It will appear
3766 -- after the regular statements for writing out parameters.
3768 pragma Warnings (Off);
3769 pragma Unreferenced (RACW_Type);
3770 -- Used only for the PolyORB case
3771 pragma Warnings (On);
3773 begin
3774 -- The general form of a calling stub for a given subprogram is:
3776 -- procedure X (...) is P : constant Partition_ID :=
3777 -- RCI_Cache.Get_Active_Partition_ID; Stream, Result : aliased
3778 -- System.RPC.Params_Stream_Type (0); begin
3779 -- Put_Package_RPC_Receiver_In_Stream; (the package RPC receiver
3780 -- comes from RCI_Cache.Get_RCI_Package_Receiver)
3781 -- Put_Subprogram_Id_In_Stream; Put_Parameters_In_Stream; Do_RPC
3782 -- (Stream, Result); Read_Exception_Occurrence_From_Result;
3783 -- Raise_It;
3784 -- Read_Out_Parameters_And_Function_Return_From_Stream; end X;
3786 -- There are some variations: Do_APC is called for an asynchronous
3787 -- procedure and the part after the call is completely ommitted as
3788 -- well as the declaration of Result. For a function call, 'Input is
3789 -- always used to read the result even if it is constrained.
3791 Stream_Parameter :=
3792 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
3794 Append_To (Decls,
3795 Make_Object_Declaration (Loc,
3796 Defining_Identifier => Stream_Parameter,
3797 Aliased_Present => True,
3798 Object_Definition =>
3799 Make_Subtype_Indication (Loc,
3800 Subtype_Mark =>
3801 New_Occurrence_Of (RTE (RE_Params_Stream_Type), Loc),
3802 Constraint =>
3803 Make_Index_Or_Discriminant_Constraint (Loc,
3804 Constraints =>
3805 New_List (Make_Integer_Literal (Loc, 0))))));
3807 if not Is_Known_Asynchronous then
3808 Result_Parameter :=
3809 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
3811 Append_To (Decls,
3812 Make_Object_Declaration (Loc,
3813 Defining_Identifier => Result_Parameter,
3814 Aliased_Present => True,
3815 Object_Definition =>
3816 Make_Subtype_Indication (Loc,
3817 Subtype_Mark =>
3818 New_Occurrence_Of (RTE (RE_Params_Stream_Type), Loc),
3819 Constraint =>
3820 Make_Index_Or_Discriminant_Constraint (Loc,
3821 Constraints =>
3822 New_List (Make_Integer_Literal (Loc, 0))))));
3824 Exception_Return_Parameter :=
3825 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
3827 Append_To (Decls,
3828 Make_Object_Declaration (Loc,
3829 Defining_Identifier => Exception_Return_Parameter,
3830 Object_Definition =>
3831 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc)));
3833 else
3834 Result_Parameter := Empty;
3835 Exception_Return_Parameter := Empty;
3836 end if;
3838 -- Put first the RPC receiver corresponding to the remote package
3840 Append_To (Statements,
3841 Make_Attribute_Reference (Loc,
3842 Prefix =>
3843 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc),
3844 Attribute_Name => Name_Write,
3845 Expressions => New_List (
3846 Make_Attribute_Reference (Loc,
3847 Prefix =>
3848 New_Occurrence_Of (Stream_Parameter, Loc),
3849 Attribute_Name =>
3850 Name_Access),
3851 Target_RPC_Receiver)));
3853 -- Then put the Subprogram_Id of the subprogram we want to call in
3854 -- the stream.
3856 Append_To (Statements,
3857 Make_Attribute_Reference (Loc,
3858 Prefix =>
3859 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
3860 Attribute_Name =>
3861 Name_Write,
3862 Expressions => New_List (
3863 Make_Attribute_Reference (Loc,
3864 Prefix =>
3865 New_Occurrence_Of (Stream_Parameter, Loc),
3866 Attribute_Name => Name_Access),
3867 Subprogram_Id)));
3869 Current_Parameter := First (Ordered_Parameters_List);
3870 while Present (Current_Parameter) loop
3871 declare
3872 Typ : constant Node_Id :=
3873 Parameter_Type (Current_Parameter);
3874 Etyp : Entity_Id;
3875 Constrained : Boolean;
3876 Value : Node_Id;
3877 Extra_Parameter : Entity_Id;
3879 begin
3880 if Is_RACW_Controlling_Formal
3881 (Current_Parameter, Stub_Type)
3882 then
3883 -- In the case of a controlling formal argument, we marshall
3884 -- its addr field rather than the local stub.
3886 Append_To (Statements,
3887 Pack_Node_Into_Stream (Loc,
3888 Stream => Stream_Parameter,
3889 Object =>
3890 Make_Selected_Component (Loc,
3891 Prefix =>
3892 Defining_Identifier (Current_Parameter),
3893 Selector_Name => Name_Addr),
3894 Etyp => RTE (RE_Unsigned_64)));
3896 else
3897 Value := New_Occurrence_Of
3898 (Defining_Identifier (Current_Parameter), Loc);
3900 -- Access type parameters are transmitted as in out
3901 -- parameters. However, a dereference is needed so that
3902 -- we marshall the designated object.
3904 if Nkind (Typ) = N_Access_Definition then
3905 Value := Make_Explicit_Dereference (Loc, Value);
3906 Etyp := Etype (Subtype_Mark (Typ));
3907 else
3908 Etyp := Etype (Typ);
3909 end if;
3911 Constrained :=
3912 Is_Constrained (Etyp) or else Is_Elementary_Type (Etyp);
3914 -- Any parameter but unconstrained out parameters are
3915 -- transmitted to the peer.
3917 if In_Present (Current_Parameter)
3918 or else not Out_Present (Current_Parameter)
3919 or else not Constrained
3920 then
3921 Append_To (Statements,
3922 Make_Attribute_Reference (Loc,
3923 Prefix =>
3924 New_Occurrence_Of (Etyp, Loc),
3925 Attribute_Name =>
3926 Output_From_Constrained (Constrained),
3927 Expressions => New_List (
3928 Make_Attribute_Reference (Loc,
3929 Prefix =>
3930 New_Occurrence_Of (Stream_Parameter, Loc),
3931 Attribute_Name => Name_Access),
3932 Value)));
3933 end if;
3934 end if;
3936 -- If the current parameter has a dynamic constrained status,
3937 -- then this status is transmitted as well.
3938 -- This should be done for accessibility as well ???
3940 if Nkind (Typ) /= N_Access_Definition
3941 and then Need_Extra_Constrained (Current_Parameter)
3942 then
3943 -- In this block, we do not use the extra formal that has
3944 -- been created because it does not exist at the time of
3945 -- expansion when building calling stubs for remote access
3946 -- to subprogram types. We create an extra variable of this
3947 -- type and push it in the stream after the regular
3948 -- parameters.
3950 Extra_Parameter := Make_Defining_Identifier
3951 (Loc, New_Internal_Name ('P'));
3953 Append_To (Decls,
3954 Make_Object_Declaration (Loc,
3955 Defining_Identifier => Extra_Parameter,
3956 Constant_Present => True,
3957 Object_Definition =>
3958 New_Occurrence_Of (Standard_Boolean, Loc),
3959 Expression =>
3960 Make_Attribute_Reference (Loc,
3961 Prefix =>
3962 New_Occurrence_Of (
3963 Defining_Identifier (Current_Parameter), Loc),
3964 Attribute_Name => Name_Constrained)));
3966 Append_To (Extra_Formal_Statements,
3967 Make_Attribute_Reference (Loc,
3968 Prefix =>
3969 New_Occurrence_Of (Standard_Boolean, Loc),
3970 Attribute_Name =>
3971 Name_Write,
3972 Expressions => New_List (
3973 Make_Attribute_Reference (Loc,
3974 Prefix =>
3975 New_Occurrence_Of (Stream_Parameter, Loc),
3976 Attribute_Name =>
3977 Name_Access),
3978 New_Occurrence_Of (Extra_Parameter, Loc))));
3979 end if;
3981 Next (Current_Parameter);
3982 end;
3983 end loop;
3985 -- Append the formal statements list to the statements
3987 Append_List_To (Statements, Extra_Formal_Statements);
3989 if not Is_Known_Non_Asynchronous then
3991 -- Build the call to System.RPC.Do_APC
3993 Asynchronous_Statements := New_List (
3994 Make_Procedure_Call_Statement (Loc,
3995 Name =>
3996 New_Occurrence_Of (RTE (RE_Do_Apc), Loc),
3997 Parameter_Associations => New_List (
3998 New_Occurrence_Of (Target_Partition, Loc),
3999 Make_Attribute_Reference (Loc,
4000 Prefix =>
4001 New_Occurrence_Of (Stream_Parameter, Loc),
4002 Attribute_Name =>
4003 Name_Access))));
4004 else
4005 Asynchronous_Statements := No_List;
4006 end if;
4008 if not Is_Known_Asynchronous then
4010 -- Build the call to System.RPC.Do_RPC
4012 Non_Asynchronous_Statements := New_List (
4013 Make_Procedure_Call_Statement (Loc,
4014 Name =>
4015 New_Occurrence_Of (RTE (RE_Do_Rpc), Loc),
4016 Parameter_Associations => New_List (
4017 New_Occurrence_Of (Target_Partition, Loc),
4019 Make_Attribute_Reference (Loc,
4020 Prefix =>
4021 New_Occurrence_Of (Stream_Parameter, Loc),
4022 Attribute_Name =>
4023 Name_Access),
4025 Make_Attribute_Reference (Loc,
4026 Prefix =>
4027 New_Occurrence_Of (Result_Parameter, Loc),
4028 Attribute_Name =>
4029 Name_Access))));
4031 -- Read the exception occurrence from the result stream and
4032 -- reraise it. It does no harm if this is a Null_Occurrence since
4033 -- this does nothing.
4035 Append_To (Non_Asynchronous_Statements,
4036 Make_Attribute_Reference (Loc,
4037 Prefix =>
4038 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
4040 Attribute_Name =>
4041 Name_Read,
4043 Expressions => New_List (
4044 Make_Attribute_Reference (Loc,
4045 Prefix =>
4046 New_Occurrence_Of (Result_Parameter, Loc),
4047 Attribute_Name =>
4048 Name_Access),
4049 New_Occurrence_Of (Exception_Return_Parameter, Loc))));
4051 Append_To (Non_Asynchronous_Statements,
4052 Make_Procedure_Call_Statement (Loc,
4053 Name =>
4054 New_Occurrence_Of (RTE (RE_Reraise_Occurrence), Loc),
4055 Parameter_Associations => New_List (
4056 New_Occurrence_Of (Exception_Return_Parameter, Loc))));
4058 if Is_Function then
4060 -- If this is a function call, then read the value and return
4061 -- it. The return value is written/read using 'Output/'Input.
4063 Append_To (Non_Asynchronous_Statements,
4064 Make_Tag_Check (Loc,
4065 Make_Return_Statement (Loc,
4066 Expression =>
4067 Make_Attribute_Reference (Loc,
4068 Prefix =>
4069 New_Occurrence_Of (
4070 Etype (Result_Definition (Spec)), Loc),
4072 Attribute_Name => Name_Input,
4074 Expressions => New_List (
4075 Make_Attribute_Reference (Loc,
4076 Prefix =>
4077 New_Occurrence_Of (Result_Parameter, Loc),
4078 Attribute_Name => Name_Access))))));
4080 else
4081 -- Loop around parameters and assign out (or in out)
4082 -- parameters. In the case of RACW, controlling arguments
4083 -- cannot possibly have changed since they are remote, so we do
4084 -- not read them from the stream.
4086 Current_Parameter := First (Ordered_Parameters_List);
4087 while Present (Current_Parameter) loop
4088 declare
4089 Typ : constant Node_Id :=
4090 Parameter_Type (Current_Parameter);
4091 Etyp : Entity_Id;
4092 Value : Node_Id;
4094 begin
4095 Value :=
4096 New_Occurrence_Of
4097 (Defining_Identifier (Current_Parameter), Loc);
4099 if Nkind (Typ) = N_Access_Definition then
4100 Value := Make_Explicit_Dereference (Loc, Value);
4101 Etyp := Etype (Subtype_Mark (Typ));
4102 else
4103 Etyp := Etype (Typ);
4104 end if;
4106 if (Out_Present (Current_Parameter)
4107 or else Nkind (Typ) = N_Access_Definition)
4108 and then Etyp /= Stub_Type
4109 then
4110 Append_To (Non_Asynchronous_Statements,
4111 Make_Attribute_Reference (Loc,
4112 Prefix =>
4113 New_Occurrence_Of (Etyp, Loc),
4115 Attribute_Name => Name_Read,
4117 Expressions => New_List (
4118 Make_Attribute_Reference (Loc,
4119 Prefix =>
4120 New_Occurrence_Of (Result_Parameter, Loc),
4121 Attribute_Name =>
4122 Name_Access),
4123 Value)));
4124 end if;
4125 end;
4127 Next (Current_Parameter);
4128 end loop;
4129 end if;
4130 end if;
4132 if Is_Known_Asynchronous then
4133 Append_List_To (Statements, Asynchronous_Statements);
4135 elsif Is_Known_Non_Asynchronous then
4136 Append_List_To (Statements, Non_Asynchronous_Statements);
4138 else
4139 pragma Assert (Present (Asynchronous));
4140 Prepend_To (Asynchronous_Statements,
4141 Make_Attribute_Reference (Loc,
4142 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4143 Attribute_Name => Name_Write,
4144 Expressions => New_List (
4145 Make_Attribute_Reference (Loc,
4146 Prefix =>
4147 New_Occurrence_Of (Stream_Parameter, Loc),
4148 Attribute_Name => Name_Access),
4149 New_Occurrence_Of (Standard_True, Loc))));
4151 Prepend_To (Non_Asynchronous_Statements,
4152 Make_Attribute_Reference (Loc,
4153 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4154 Attribute_Name => Name_Write,
4155 Expressions => New_List (
4156 Make_Attribute_Reference (Loc,
4157 Prefix =>
4158 New_Occurrence_Of (Stream_Parameter, Loc),
4159 Attribute_Name => Name_Access),
4160 New_Occurrence_Of (Standard_False, Loc))));
4162 Append_To (Statements,
4163 Make_Implicit_If_Statement (Nod,
4164 Condition => Asynchronous,
4165 Then_Statements => Asynchronous_Statements,
4166 Else_Statements => Non_Asynchronous_Statements));
4167 end if;
4168 end Build_General_Calling_Stubs;
4170 -----------------------------
4171 -- Build_RPC_Receiver_Body --
4172 -----------------------------
4174 procedure Build_RPC_Receiver_Body
4175 (RPC_Receiver : Entity_Id;
4176 Request : out Entity_Id;
4177 Subp_Id : out Entity_Id;
4178 Subp_Index : out Entity_Id;
4179 Stmts : out List_Id;
4180 Decl : out Node_Id)
4182 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
4184 RPC_Receiver_Spec : Node_Id;
4185 RPC_Receiver_Decls : List_Id;
4187 begin
4188 Request := Make_Defining_Identifier (Loc, Name_R);
4190 RPC_Receiver_Spec :=
4191 Build_RPC_Receiver_Specification
4192 (RPC_Receiver => RPC_Receiver,
4193 Request_Parameter => Request);
4195 Subp_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
4196 Subp_Index := Subp_Id;
4198 -- Subp_Id may not be a constant, because in the case of the RPC
4199 -- receiver for an RCI package, when a call is received from a RAS
4200 -- dereference, it will be assigned during subsequent processing.
4202 RPC_Receiver_Decls := New_List (
4203 Make_Object_Declaration (Loc,
4204 Defining_Identifier => Subp_Id,
4205 Object_Definition =>
4206 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
4207 Expression =>
4208 Make_Attribute_Reference (Loc,
4209 Prefix =>
4210 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
4211 Attribute_Name => Name_Input,
4212 Expressions => New_List (
4213 Make_Selected_Component (Loc,
4214 Prefix => Request,
4215 Selector_Name => Name_Params)))));
4217 Stmts := New_List;
4219 Decl :=
4220 Make_Subprogram_Body (Loc,
4221 Specification => RPC_Receiver_Spec,
4222 Declarations => RPC_Receiver_Decls,
4223 Handled_Statement_Sequence =>
4224 Make_Handled_Sequence_Of_Statements (Loc,
4225 Statements => Stmts));
4226 end Build_RPC_Receiver_Body;
4228 -----------------------
4229 -- Build_Stub_Target --
4230 -----------------------
4232 function Build_Stub_Target
4233 (Loc : Source_Ptr;
4234 Decls : List_Id;
4235 RCI_Locator : Entity_Id;
4236 Controlling_Parameter : Entity_Id) return RPC_Target
4238 Target_Info : RPC_Target (PCS_Kind => Name_GARLIC_DSA);
4239 begin
4240 Target_Info.Partition :=
4241 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
4242 if Present (Controlling_Parameter) then
4243 Append_To (Decls,
4244 Make_Object_Declaration (Loc,
4245 Defining_Identifier => Target_Info.Partition,
4246 Constant_Present => True,
4247 Object_Definition =>
4248 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
4250 Expression =>
4251 Make_Selected_Component (Loc,
4252 Prefix => Controlling_Parameter,
4253 Selector_Name => Name_Origin)));
4255 Target_Info.RPC_Receiver :=
4256 Make_Selected_Component (Loc,
4257 Prefix => Controlling_Parameter,
4258 Selector_Name => Name_Receiver);
4260 else
4261 Append_To (Decls,
4262 Make_Object_Declaration (Loc,
4263 Defining_Identifier => Target_Info.Partition,
4264 Constant_Present => True,
4265 Object_Definition =>
4266 New_Occurrence_Of (RTE (RE_Partition_ID), Loc),
4268 Expression =>
4269 Make_Function_Call (Loc,
4270 Name => Make_Selected_Component (Loc,
4271 Prefix =>
4272 Make_Identifier (Loc, Chars (RCI_Locator)),
4273 Selector_Name =>
4274 Make_Identifier (Loc,
4275 Name_Get_Active_Partition_ID)))));
4277 Target_Info.RPC_Receiver :=
4278 Make_Selected_Component (Loc,
4279 Prefix =>
4280 Make_Identifier (Loc, Chars (RCI_Locator)),
4281 Selector_Name =>
4282 Make_Identifier (Loc, Name_Get_RCI_Package_Receiver));
4283 end if;
4284 return Target_Info;
4285 end Build_Stub_Target;
4287 ---------------------
4288 -- Build_Stub_Type --
4289 ---------------------
4291 procedure Build_Stub_Type
4292 (RACW_Type : Entity_Id;
4293 Stub_Type : Entity_Id;
4294 Stub_Type_Decl : out Node_Id;
4295 RPC_Receiver_Decl : out Node_Id)
4297 Loc : constant Source_Ptr := Sloc (Stub_Type);
4298 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
4300 begin
4301 Stub_Type_Decl :=
4302 Make_Full_Type_Declaration (Loc,
4303 Defining_Identifier => Stub_Type,
4304 Type_Definition =>
4305 Make_Record_Definition (Loc,
4306 Tagged_Present => True,
4307 Limited_Present => True,
4308 Component_List =>
4309 Make_Component_List (Loc,
4310 Component_Items => New_List (
4312 Make_Component_Declaration (Loc,
4313 Defining_Identifier =>
4314 Make_Defining_Identifier (Loc, Name_Origin),
4315 Component_Definition =>
4316 Make_Component_Definition (Loc,
4317 Aliased_Present => False,
4318 Subtype_Indication =>
4319 New_Occurrence_Of (
4320 RTE (RE_Partition_ID), Loc))),
4322 Make_Component_Declaration (Loc,
4323 Defining_Identifier =>
4324 Make_Defining_Identifier (Loc, Name_Receiver),
4325 Component_Definition =>
4326 Make_Component_Definition (Loc,
4327 Aliased_Present => False,
4328 Subtype_Indication =>
4329 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc))),
4331 Make_Component_Declaration (Loc,
4332 Defining_Identifier =>
4333 Make_Defining_Identifier (Loc, Name_Addr),
4334 Component_Definition =>
4335 Make_Component_Definition (Loc,
4336 Aliased_Present => False,
4337 Subtype_Indication =>
4338 New_Occurrence_Of (RTE (RE_Unsigned_64), Loc))),
4340 Make_Component_Declaration (Loc,
4341 Defining_Identifier =>
4342 Make_Defining_Identifier (Loc, Name_Asynchronous),
4343 Component_Definition =>
4344 Make_Component_Definition (Loc,
4345 Aliased_Present => False,
4346 Subtype_Indication =>
4347 New_Occurrence_Of (
4348 Standard_Boolean, Loc)))))));
4350 if Is_RAS then
4351 RPC_Receiver_Decl := Empty;
4352 else
4353 declare
4354 RPC_Receiver_Request : constant Entity_Id :=
4355 Make_Defining_Identifier (Loc, Name_R);
4356 begin
4357 RPC_Receiver_Decl :=
4358 Make_Subprogram_Declaration (Loc,
4359 Build_RPC_Receiver_Specification (
4360 RPC_Receiver => Make_Defining_Identifier (Loc,
4361 New_Internal_Name ('R')),
4362 Request_Parameter => RPC_Receiver_Request));
4363 end;
4364 end if;
4365 end Build_Stub_Type;
4367 --------------------------------------
4368 -- Build_Subprogram_Receiving_Stubs --
4369 --------------------------------------
4371 function Build_Subprogram_Receiving_Stubs
4372 (Vis_Decl : Node_Id;
4373 Asynchronous : Boolean;
4374 Dynamically_Asynchronous : Boolean := False;
4375 Stub_Type : Entity_Id := Empty;
4376 RACW_Type : Entity_Id := Empty;
4377 Parent_Primitive : Entity_Id := Empty) return Node_Id
4379 Loc : constant Source_Ptr := Sloc (Vis_Decl);
4381 Request_Parameter : Node_Id;
4382 -- ???
4384 Decls : constant List_Id := New_List;
4385 -- All the parameters will get declared before calling the real
4386 -- subprograms. Also the out parameters will be declared.
4388 Statements : constant List_Id := New_List;
4390 Extra_Formal_Statements : constant List_Id := New_List;
4391 -- Statements concerning extra formal parameters
4393 After_Statements : constant List_Id := New_List;
4394 -- Statements to be executed after the subprogram call
4396 Inner_Decls : List_Id := No_List;
4397 -- In case of a function, the inner declarations are needed since
4398 -- the result may be unconstrained.
4400 Excep_Handlers : List_Id := No_List;
4401 Excep_Choice : Entity_Id;
4402 Excep_Code : List_Id;
4404 Parameter_List : constant List_Id := New_List;
4405 -- List of parameters to be passed to the subprogram
4407 Current_Parameter : Node_Id;
4409 Ordered_Parameters_List : constant List_Id :=
4410 Build_Ordered_Parameters_List
4411 (Specification (Vis_Decl));
4413 Subp_Spec : Node_Id;
4414 -- Subprogram specification
4416 Called_Subprogram : Node_Id;
4417 -- The subprogram to call
4419 Null_Raise_Statement : Node_Id;
4421 Dynamic_Async : Entity_Id;
4423 begin
4424 if Present (RACW_Type) then
4425 Called_Subprogram :=
4426 New_Occurrence_Of (Parent_Primitive, Loc);
4427 else
4428 Called_Subprogram :=
4429 New_Occurrence_Of (
4430 Defining_Unit_Name (Specification (Vis_Decl)), Loc);
4431 end if;
4433 Request_Parameter :=
4434 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
4436 if Dynamically_Asynchronous then
4437 Dynamic_Async :=
4438 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
4439 else
4440 Dynamic_Async := Empty;
4441 end if;
4443 if not Asynchronous or Dynamically_Asynchronous then
4445 -- The first statement after the subprogram call is a statement to
4446 -- writes a Null_Occurrence into the result stream.
4448 Null_Raise_Statement :=
4449 Make_Attribute_Reference (Loc,
4450 Prefix =>
4451 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
4452 Attribute_Name => Name_Write,
4453 Expressions => New_List (
4454 Make_Selected_Component (Loc,
4455 Prefix => Request_Parameter,
4456 Selector_Name => Name_Result),
4457 New_Occurrence_Of (RTE (RE_Null_Occurrence), Loc)));
4459 if Dynamically_Asynchronous then
4460 Null_Raise_Statement :=
4461 Make_Implicit_If_Statement (Vis_Decl,
4462 Condition =>
4463 Make_Op_Not (Loc, New_Occurrence_Of (Dynamic_Async, Loc)),
4464 Then_Statements => New_List (Null_Raise_Statement));
4465 end if;
4467 Append_To (After_Statements, Null_Raise_Statement);
4468 end if;
4470 -- Loop through every parameter and get its value from the stream. If
4471 -- the parameter is unconstrained, then the parameter is read using
4472 -- 'Input at the point of declaration.
4474 Current_Parameter := First (Ordered_Parameters_List);
4475 while Present (Current_Parameter) loop
4476 declare
4477 Etyp : Entity_Id;
4478 Constrained : Boolean;
4480 Object : constant Entity_Id :=
4481 Make_Defining_Identifier (Loc,
4482 New_Internal_Name ('P'));
4484 Expr : Node_Id := Empty;
4486 Is_Controlling_Formal : constant Boolean :=
4487 Is_RACW_Controlling_Formal
4488 (Current_Parameter, Stub_Type);
4490 begin
4491 Set_Ekind (Object, E_Variable);
4493 if Is_Controlling_Formal then
4495 -- We have a controlling formal parameter. Read its address
4496 -- rather than a real object. The address is in Unsigned_64
4497 -- form.
4499 Etyp := RTE (RE_Unsigned_64);
4500 else
4501 Etyp := Etype (Parameter_Type (Current_Parameter));
4502 end if;
4504 Constrained :=
4505 Is_Constrained (Etyp) or else Is_Elementary_Type (Etyp);
4507 if In_Present (Current_Parameter)
4508 or else not Out_Present (Current_Parameter)
4509 or else not Constrained
4510 or else Is_Controlling_Formal
4511 then
4512 -- If an input parameter is constrained, then the read of
4513 -- the parameter is deferred until the beginning of the
4514 -- subprogram body. If it is unconstrained, then an
4515 -- expression is built for the object declaration and the
4516 -- variable is set using 'Input instead of 'Read. Note that
4517 -- this deferral does not change the order in which the
4518 -- actuals are read because Build_Ordered_Parameter_List
4519 -- puts them unconstrained first.
4521 if Constrained then
4522 Append_To (Statements,
4523 Make_Attribute_Reference (Loc,
4524 Prefix => New_Occurrence_Of (Etyp, Loc),
4525 Attribute_Name => Name_Read,
4526 Expressions => New_List (
4527 Make_Selected_Component (Loc,
4528 Prefix => Request_Parameter,
4529 Selector_Name => Name_Params),
4530 New_Occurrence_Of (Object, Loc))));
4532 else
4533 Expr := Input_With_Tag_Check (Loc,
4534 Var_Type => Etyp,
4535 Stream => Make_Selected_Component (Loc,
4536 Prefix => Request_Parameter,
4537 Selector_Name => Name_Params));
4538 Append_To (Decls, Expr);
4539 Expr := Make_Function_Call (Loc,
4540 New_Occurrence_Of (Defining_Unit_Name
4541 (Specification (Expr)), Loc));
4542 end if;
4543 end if;
4545 -- If we do not have to output the current parameter, then it
4546 -- can well be flagged as constant. This may allow further
4547 -- optimizations done by the back end.
4549 Append_To (Decls,
4550 Make_Object_Declaration (Loc,
4551 Defining_Identifier => Object,
4552 Constant_Present => not Constrained
4553 and then not Out_Present (Current_Parameter),
4554 Object_Definition =>
4555 New_Occurrence_Of (Etyp, Loc),
4556 Expression => Expr));
4558 -- An out parameter may be written back using a 'Write
4559 -- attribute instead of a 'Output because it has been
4560 -- constrained by the parameter given to the caller. Note that
4561 -- out controlling arguments in the case of a RACW are not put
4562 -- back in the stream because the pointer on them has not
4563 -- changed.
4565 if Out_Present (Current_Parameter)
4566 and then
4567 Etype (Parameter_Type (Current_Parameter)) /= Stub_Type
4568 then
4569 Append_To (After_Statements,
4570 Make_Attribute_Reference (Loc,
4571 Prefix => New_Occurrence_Of (Etyp, Loc),
4572 Attribute_Name => Name_Write,
4573 Expressions => New_List (
4574 Make_Selected_Component (Loc,
4575 Prefix => Request_Parameter,
4576 Selector_Name => Name_Result),
4577 New_Occurrence_Of (Object, Loc))));
4578 end if;
4580 -- For RACW controlling formals, the Etyp of Object is always
4581 -- an RACW, even if the parameter is not of an anonymous access
4582 -- type. In such case, we need to dereference it at call time.
4584 if Is_Controlling_Formal then
4585 if Nkind (Parameter_Type (Current_Parameter)) /=
4586 N_Access_Definition
4587 then
4588 Append_To (Parameter_List,
4589 Make_Parameter_Association (Loc,
4590 Selector_Name =>
4591 New_Occurrence_Of (
4592 Defining_Identifier (Current_Parameter), Loc),
4593 Explicit_Actual_Parameter =>
4594 Make_Explicit_Dereference (Loc,
4595 Unchecked_Convert_To (RACW_Type,
4596 OK_Convert_To (RTE (RE_Address),
4597 New_Occurrence_Of (Object, Loc))))));
4599 else
4600 Append_To (Parameter_List,
4601 Make_Parameter_Association (Loc,
4602 Selector_Name =>
4603 New_Occurrence_Of (
4604 Defining_Identifier (Current_Parameter), Loc),
4605 Explicit_Actual_Parameter =>
4606 Unchecked_Convert_To (RACW_Type,
4607 OK_Convert_To (RTE (RE_Address),
4608 New_Occurrence_Of (Object, Loc)))));
4609 end if;
4611 else
4612 Append_To (Parameter_List,
4613 Make_Parameter_Association (Loc,
4614 Selector_Name =>
4615 New_Occurrence_Of (
4616 Defining_Identifier (Current_Parameter), Loc),
4617 Explicit_Actual_Parameter =>
4618 New_Occurrence_Of (Object, Loc)));
4619 end if;
4621 -- If the current parameter needs an extra formal, then read it
4622 -- from the stream and set the corresponding semantic field in
4623 -- the variable. If the kind of the parameter identifier is
4624 -- E_Void, then this is a compiler generated parameter that
4625 -- doesn't need an extra constrained status.
4627 -- The case of Extra_Accessibility should also be handled ???
4629 if Nkind (Parameter_Type (Current_Parameter)) /=
4630 N_Access_Definition
4631 and then
4632 Ekind (Defining_Identifier (Current_Parameter)) /= E_Void
4633 and then
4634 Present (Extra_Constrained
4635 (Defining_Identifier (Current_Parameter)))
4636 then
4637 declare
4638 Extra_Parameter : constant Entity_Id :=
4639 Extra_Constrained
4640 (Defining_Identifier
4641 (Current_Parameter));
4643 Formal_Entity : constant Entity_Id :=
4644 Make_Defining_Identifier
4645 (Loc, Chars (Extra_Parameter));
4647 Formal_Type : constant Entity_Id :=
4648 Etype (Extra_Parameter);
4650 begin
4651 Append_To (Decls,
4652 Make_Object_Declaration (Loc,
4653 Defining_Identifier => Formal_Entity,
4654 Object_Definition =>
4655 New_Occurrence_Of (Formal_Type, Loc)));
4657 Append_To (Extra_Formal_Statements,
4658 Make_Attribute_Reference (Loc,
4659 Prefix => New_Occurrence_Of (
4660 Formal_Type, Loc),
4661 Attribute_Name => Name_Read,
4662 Expressions => New_List (
4663 Make_Selected_Component (Loc,
4664 Prefix => Request_Parameter,
4665 Selector_Name => Name_Params),
4666 New_Occurrence_Of (Formal_Entity, Loc))));
4667 Set_Extra_Constrained (Object, Formal_Entity);
4668 end;
4669 end if;
4670 end;
4672 Next (Current_Parameter);
4673 end loop;
4675 -- Append the formal statements list at the end of regular statements
4677 Append_List_To (Statements, Extra_Formal_Statements);
4679 if Nkind (Specification (Vis_Decl)) = N_Function_Specification then
4681 -- The remote subprogram is a function. We build an inner block to
4682 -- be able to hold a potentially unconstrained result in a
4683 -- variable.
4685 declare
4686 Etyp : constant Entity_Id :=
4687 Etype (Result_Definition (Specification (Vis_Decl)));
4688 Result : constant Node_Id :=
4689 Make_Defining_Identifier (Loc,
4690 New_Internal_Name ('R'));
4691 begin
4692 Inner_Decls := New_List (
4693 Make_Object_Declaration (Loc,
4694 Defining_Identifier => Result,
4695 Constant_Present => True,
4696 Object_Definition => New_Occurrence_Of (Etyp, Loc),
4697 Expression =>
4698 Make_Function_Call (Loc,
4699 Name => Called_Subprogram,
4700 Parameter_Associations => Parameter_List)));
4702 Append_To (After_Statements,
4703 Make_Attribute_Reference (Loc,
4704 Prefix => New_Occurrence_Of (Etyp, Loc),
4705 Attribute_Name => Name_Output,
4706 Expressions => New_List (
4707 Make_Selected_Component (Loc,
4708 Prefix => Request_Parameter,
4709 Selector_Name => Name_Result),
4710 New_Occurrence_Of (Result, Loc))));
4711 end;
4713 Append_To (Statements,
4714 Make_Block_Statement (Loc,
4715 Declarations => Inner_Decls,
4716 Handled_Statement_Sequence =>
4717 Make_Handled_Sequence_Of_Statements (Loc,
4718 Statements => After_Statements)));
4720 else
4721 -- The remote subprogram is a procedure. We do not need any inner
4722 -- block in this case.
4724 if Dynamically_Asynchronous then
4725 Append_To (Decls,
4726 Make_Object_Declaration (Loc,
4727 Defining_Identifier => Dynamic_Async,
4728 Object_Definition =>
4729 New_Occurrence_Of (Standard_Boolean, Loc)));
4731 Append_To (Statements,
4732 Make_Attribute_Reference (Loc,
4733 Prefix => New_Occurrence_Of (Standard_Boolean, Loc),
4734 Attribute_Name => Name_Read,
4735 Expressions => New_List (
4736 Make_Selected_Component (Loc,
4737 Prefix => Request_Parameter,
4738 Selector_Name => Name_Params),
4739 New_Occurrence_Of (Dynamic_Async, Loc))));
4740 end if;
4742 Append_To (Statements,
4743 Make_Procedure_Call_Statement (Loc,
4744 Name => Called_Subprogram,
4745 Parameter_Associations => Parameter_List));
4747 Append_List_To (Statements, After_Statements);
4748 end if;
4750 if Asynchronous and then not Dynamically_Asynchronous then
4752 -- For an asynchronous procedure, add a null exception handler
4754 Excep_Handlers := New_List (
4755 Make_Exception_Handler (Loc,
4756 Exception_Choices => New_List (Make_Others_Choice (Loc)),
4757 Statements => New_List (Make_Null_Statement (Loc))));
4759 else
4760 -- In the other cases, if an exception is raised, then the
4761 -- exception occurrence is copied into the output stream and
4762 -- no other output parameter is written.
4764 Excep_Choice :=
4765 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
4767 Excep_Code := New_List (
4768 Make_Attribute_Reference (Loc,
4769 Prefix =>
4770 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc),
4771 Attribute_Name => Name_Write,
4772 Expressions => New_List (
4773 Make_Selected_Component (Loc,
4774 Prefix => Request_Parameter,
4775 Selector_Name => Name_Result),
4776 New_Occurrence_Of (Excep_Choice, Loc))));
4778 if Dynamically_Asynchronous then
4779 Excep_Code := New_List (
4780 Make_Implicit_If_Statement (Vis_Decl,
4781 Condition => Make_Op_Not (Loc,
4782 New_Occurrence_Of (Dynamic_Async, Loc)),
4783 Then_Statements => Excep_Code));
4784 end if;
4786 Excep_Handlers := New_List (
4787 Make_Exception_Handler (Loc,
4788 Choice_Parameter => Excep_Choice,
4789 Exception_Choices => New_List (Make_Others_Choice (Loc)),
4790 Statements => Excep_Code));
4792 end if;
4794 Subp_Spec :=
4795 Make_Procedure_Specification (Loc,
4796 Defining_Unit_Name =>
4797 Make_Defining_Identifier (Loc, New_Internal_Name ('F')),
4799 Parameter_Specifications => New_List (
4800 Make_Parameter_Specification (Loc,
4801 Defining_Identifier => Request_Parameter,
4802 Parameter_Type =>
4803 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
4805 return
4806 Make_Subprogram_Body (Loc,
4807 Specification => Subp_Spec,
4808 Declarations => Decls,
4809 Handled_Statement_Sequence =>
4810 Make_Handled_Sequence_Of_Statements (Loc,
4811 Statements => Statements,
4812 Exception_Handlers => Excep_Handlers));
4813 end Build_Subprogram_Receiving_Stubs;
4815 ------------
4816 -- Result --
4817 ------------
4819 function Result return Node_Id is
4820 begin
4821 return Make_Identifier (Loc, Name_V);
4822 end Result;
4824 ----------------------
4825 -- Stream_Parameter --
4826 ----------------------
4828 function Stream_Parameter return Node_Id is
4829 begin
4830 return Make_Identifier (Loc, Name_S);
4831 end Stream_Parameter;
4833 end GARLIC_Support;
4835 -----------------------------
4836 -- Make_Selected_Component --
4837 -----------------------------
4839 function Make_Selected_Component
4840 (Loc : Source_Ptr;
4841 Prefix : Entity_Id;
4842 Selector_Name : Name_Id) return Node_Id
4844 begin
4845 return Make_Selected_Component (Loc,
4846 Prefix => New_Occurrence_Of (Prefix, Loc),
4847 Selector_Name => Make_Identifier (Loc, Selector_Name));
4848 end Make_Selected_Component;
4850 -----------------------
4851 -- Get_Subprogram_Id --
4852 -----------------------
4854 function Get_Subprogram_Id (Def : Entity_Id) return String_Id is
4855 Result : constant String_Id := Get_Subprogram_Ids (Def).Str_Identifier;
4856 begin
4857 pragma Assert (Result /= No_String);
4858 return Result;
4859 end Get_Subprogram_Id;
4861 -----------------------
4862 -- Get_Subprogram_Id --
4863 -----------------------
4865 function Get_Subprogram_Id (Def : Entity_Id) return Int is
4866 begin
4867 return Get_Subprogram_Ids (Def).Int_Identifier;
4868 end Get_Subprogram_Id;
4870 ------------------------
4871 -- Get_Subprogram_Ids --
4872 ------------------------
4874 function Get_Subprogram_Ids
4875 (Def : Entity_Id) return Subprogram_Identifiers
4877 begin
4878 return Subprogram_Identifier_Table.Get (Def);
4879 end Get_Subprogram_Ids;
4881 ----------
4882 -- Hash --
4883 ----------
4885 function Hash (F : Entity_Id) return Hash_Index is
4886 begin
4887 return Hash_Index (Natural (F) mod Positive (Hash_Index'Last + 1));
4888 end Hash;
4890 function Hash (F : Name_Id) return Hash_Index is
4891 begin
4892 return Hash_Index (Natural (F) mod Positive (Hash_Index'Last + 1));
4893 end Hash;
4895 --------------------------
4896 -- Input_With_Tag_Check --
4897 --------------------------
4899 function Input_With_Tag_Check
4900 (Loc : Source_Ptr;
4901 Var_Type : Entity_Id;
4902 Stream : Node_Id) return Node_Id
4904 begin
4905 return
4906 Make_Subprogram_Body (Loc,
4907 Specification => Make_Function_Specification (Loc,
4908 Defining_Unit_Name =>
4909 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4910 Result_Definition => New_Occurrence_Of (Var_Type, Loc)),
4911 Declarations => No_List,
4912 Handled_Statement_Sequence =>
4913 Make_Handled_Sequence_Of_Statements (Loc, New_List (
4914 Make_Tag_Check (Loc,
4915 Make_Return_Statement (Loc,
4916 Make_Attribute_Reference (Loc,
4917 Prefix => New_Occurrence_Of (Var_Type, Loc),
4918 Attribute_Name => Name_Input,
4919 Expressions =>
4920 New_List (Stream)))))));
4921 end Input_With_Tag_Check;
4923 --------------------------------
4924 -- Is_RACW_Controlling_Formal --
4925 --------------------------------
4927 function Is_RACW_Controlling_Formal
4928 (Parameter : Node_Id;
4929 Stub_Type : Entity_Id) return Boolean
4931 Typ : Entity_Id;
4933 begin
4934 -- If the kind of the parameter is E_Void, then it is not a
4935 -- controlling formal (this can happen in the context of RAS).
4937 if Ekind (Defining_Identifier (Parameter)) = E_Void then
4938 return False;
4939 end if;
4941 -- If the parameter is not a controlling formal, then it cannot
4942 -- be possibly a RACW_Controlling_Formal.
4944 if not Is_Controlling_Formal (Defining_Identifier (Parameter)) then
4945 return False;
4946 end if;
4948 Typ := Parameter_Type (Parameter);
4949 return (Nkind (Typ) = N_Access_Definition
4950 and then Etype (Subtype_Mark (Typ)) = Stub_Type)
4951 or else Etype (Typ) = Stub_Type;
4952 end Is_RACW_Controlling_Formal;
4954 --------------------
4955 -- Make_Tag_Check --
4956 --------------------
4958 function Make_Tag_Check (Loc : Source_Ptr; N : Node_Id) return Node_Id is
4959 Occ : constant Entity_Id :=
4960 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
4962 begin
4963 return Make_Block_Statement (Loc,
4964 Handled_Statement_Sequence =>
4965 Make_Handled_Sequence_Of_Statements (Loc,
4966 Statements => New_List (N),
4968 Exception_Handlers => New_List (
4969 Make_Exception_Handler (Loc,
4970 Choice_Parameter => Occ,
4972 Exception_Choices =>
4973 New_List (New_Occurrence_Of (RTE (RE_Tag_Error), Loc)),
4975 Statements =>
4976 New_List (Make_Procedure_Call_Statement (Loc,
4977 New_Occurrence_Of
4978 (RTE (RE_Raise_Program_Error_Unknown_Tag), Loc),
4979 New_List (New_Occurrence_Of (Occ, Loc))))))));
4980 end Make_Tag_Check;
4982 ----------------------------
4983 -- Need_Extra_Constrained --
4984 ----------------------------
4986 function Need_Extra_Constrained (Parameter : Node_Id) return Boolean is
4987 Etyp : constant Entity_Id := Etype (Parameter_Type (Parameter));
4988 begin
4989 return Out_Present (Parameter)
4990 and then Has_Discriminants (Etyp)
4991 and then not Is_Constrained (Etyp)
4992 and then not Is_Indefinite_Subtype (Etyp);
4993 end Need_Extra_Constrained;
4995 ------------------------------------
4996 -- Pack_Entity_Into_Stream_Access --
4997 ------------------------------------
4999 function Pack_Entity_Into_Stream_Access
5000 (Loc : Source_Ptr;
5001 Stream : Node_Id;
5002 Object : Entity_Id;
5003 Etyp : Entity_Id := Empty) return Node_Id
5005 Typ : Entity_Id;
5007 begin
5008 if Present (Etyp) then
5009 Typ := Etyp;
5010 else
5011 Typ := Etype (Object);
5012 end if;
5014 return
5015 Pack_Node_Into_Stream_Access (Loc,
5016 Stream => Stream,
5017 Object => New_Occurrence_Of (Object, Loc),
5018 Etyp => Typ);
5019 end Pack_Entity_Into_Stream_Access;
5021 ---------------------------
5022 -- Pack_Node_Into_Stream --
5023 ---------------------------
5025 function Pack_Node_Into_Stream
5026 (Loc : Source_Ptr;
5027 Stream : Entity_Id;
5028 Object : Node_Id;
5029 Etyp : Entity_Id) return Node_Id
5031 Write_Attribute : Name_Id := Name_Write;
5033 begin
5034 if not Is_Constrained (Etyp) then
5035 Write_Attribute := Name_Output;
5036 end if;
5038 return
5039 Make_Attribute_Reference (Loc,
5040 Prefix => New_Occurrence_Of (Etyp, Loc),
5041 Attribute_Name => Write_Attribute,
5042 Expressions => New_List (
5043 Make_Attribute_Reference (Loc,
5044 Prefix => New_Occurrence_Of (Stream, Loc),
5045 Attribute_Name => Name_Access),
5046 Object));
5047 end Pack_Node_Into_Stream;
5049 ----------------------------------
5050 -- Pack_Node_Into_Stream_Access --
5051 ----------------------------------
5053 function Pack_Node_Into_Stream_Access
5054 (Loc : Source_Ptr;
5055 Stream : Node_Id;
5056 Object : Node_Id;
5057 Etyp : Entity_Id) return Node_Id
5059 Write_Attribute : Name_Id := Name_Write;
5061 begin
5062 if not Is_Constrained (Etyp) then
5063 Write_Attribute := Name_Output;
5064 end if;
5066 return
5067 Make_Attribute_Reference (Loc,
5068 Prefix => New_Occurrence_Of (Etyp, Loc),
5069 Attribute_Name => Write_Attribute,
5070 Expressions => New_List (
5071 Stream,
5072 Object));
5073 end Pack_Node_Into_Stream_Access;
5075 ---------------------
5076 -- PolyORB_Support --
5077 ---------------------
5079 package body PolyORB_Support is
5081 -- Local subprograms
5083 procedure Add_RACW_Read_Attribute
5084 (RACW_Type : Entity_Id;
5085 Stub_Type : Entity_Id;
5086 Stub_Type_Access : Entity_Id;
5087 Declarations : List_Id);
5088 -- Add Read attribute in Decls for the RACW type. The Read attribute
5089 -- is added right after the RACW_Type declaration while the body is
5090 -- inserted after Declarations.
5092 procedure Add_RACW_Write_Attribute
5093 (RACW_Type : Entity_Id;
5094 Stub_Type : Entity_Id;
5095 Stub_Type_Access : Entity_Id;
5096 Declarations : List_Id);
5097 -- Same thing for the Write attribute
5099 procedure Add_RACW_From_Any
5100 (RACW_Type : Entity_Id;
5101 Stub_Type : Entity_Id;
5102 Stub_Type_Access : Entity_Id;
5103 Declarations : List_Id);
5104 -- Add the From_Any TSS for this RACW type
5106 procedure Add_RACW_To_Any
5107 (Designated_Type : Entity_Id;
5108 RACW_Type : Entity_Id;
5109 Stub_Type : Entity_Id;
5110 Stub_Type_Access : Entity_Id;
5111 Declarations : List_Id);
5112 -- Add the To_Any TSS for this RACW type
5114 procedure Add_RACW_TypeCode
5115 (Designated_Type : Entity_Id;
5116 RACW_Type : Entity_Id;
5117 Declarations : List_Id);
5118 -- Add the TypeCode TSS for this RACW type
5120 procedure Add_RAS_From_Any (RAS_Type : Entity_Id);
5121 -- Add the From_Any TSS for this RAS type
5123 procedure Add_RAS_To_Any (RAS_Type : Entity_Id);
5124 -- Add the To_Any TSS for this RAS type
5126 procedure Add_RAS_TypeCode (RAS_Type : Entity_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 Result_Definition => 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, TSS_From_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 Result_Definition => 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, TSS_To_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 begin
5809 Fnam :=
5810 Make_Defining_Identifier (Loc,
5811 Chars => New_Internal_Name ('T'));
5813 -- The spec for this subprogram has a dummy 'access RACW'
5814 -- argument, which serves only for overloading purposes.
5816 Func_Spec :=
5817 Make_Function_Specification (Loc,
5818 Defining_Unit_Name =>
5819 Fnam,
5820 Result_Definition => New_Occurrence_Of (RTE (RE_TypeCode), Loc));
5822 -- NOTE: The usage occurrences of RACW_Parameter must
5823 -- refer to the entity in the declaration spec, not those
5824 -- of the body spec.
5826 Func_Decl := Make_Subprogram_Declaration (Loc, Func_Spec);
5828 Func_Body :=
5829 Make_Subprogram_Body (Loc,
5830 Specification =>
5831 Copy_Specification (Loc, Func_Spec),
5832 Declarations => Empty_List,
5833 Handled_Statement_Sequence =>
5834 Make_Handled_Sequence_Of_Statements (Loc,
5835 Statements => New_List (
5836 Make_Return_Statement (Loc,
5837 Expression =>
5838 Make_Selected_Component (Loc,
5839 Prefix =>
5840 Defining_Identifier (
5841 Stub_Elements.RPC_Receiver_Decl),
5842 Selector_Name => Name_Obj_TypeCode)))));
5844 Insert_After (Declaration_Node (RACW_Type), Func_Decl);
5845 Append_To (Declarations, Func_Body);
5847 Set_Renaming_TSS (RACW_Type, Fnam, TSS_TypeCode);
5848 end Add_RACW_TypeCode;
5850 ------------------------------
5851 -- Add_RACW_Write_Attribute --
5852 ------------------------------
5854 procedure Add_RACW_Write_Attribute
5855 (RACW_Type : Entity_Id;
5856 Stub_Type : Entity_Id;
5857 Stub_Type_Access : Entity_Id;
5858 Declarations : List_Id)
5860 Loc : constant Source_Ptr := Sloc (RACW_Type);
5861 pragma Warnings (Off);
5862 pragma Unreferenced (
5863 Stub_Type,
5864 Stub_Type_Access);
5866 Is_RAS : constant Boolean := not Comes_From_Source (RACW_Type);
5867 pragma Unreferenced (Is_RAS);
5868 pragma Warnings (On);
5870 Body_Node : Node_Id;
5871 Proc_Decl : Node_Id;
5872 Attr_Decl : Node_Id;
5874 Statements : List_Id;
5875 Procedure_Name : constant Name_Id := New_Internal_Name ('R');
5877 function Stream_Parameter return Node_Id;
5878 function Object return Node_Id;
5879 -- Functions to create occurrences of the formal parameter names
5881 ------------
5882 -- Object --
5883 ------------
5885 function Object return Node_Id is
5886 Object_Ref : constant Node_Id :=
5887 Make_Identifier (Loc, Name_V);
5889 begin
5890 -- Etype must be set for Build_To_Any_Call
5892 Set_Etype (Object_Ref, RACW_Type);
5894 return Object_Ref;
5895 end Object;
5897 ----------------------
5898 -- Stream_Parameter --
5899 ----------------------
5901 function Stream_Parameter return Node_Id is
5902 begin
5903 return Make_Identifier (Loc, Name_S);
5904 end Stream_Parameter;
5906 -- Start of processing for Add_RACW_Write_Attribute
5908 begin
5909 Statements := New_List (
5910 Pack_Node_Into_Stream_Access (Loc,
5911 Stream => Stream_Parameter,
5912 Object =>
5913 Make_Function_Call (Loc,
5914 Name =>
5915 New_Occurrence_Of (RTE (RE_FA_ObjRef), Loc),
5916 Parameter_Associations => New_List (
5917 PolyORB_Support.Helpers.Build_To_Any_Call
5918 (Object, Declarations))),
5919 Etyp => RTE (RE_Object_Ref)));
5921 Build_Stream_Procedure
5922 (Loc, RACW_Type, Body_Node,
5923 Make_Defining_Identifier (Loc, Procedure_Name),
5924 Statements, Outp => False);
5926 Proc_Decl :=
5927 Make_Subprogram_Declaration (Loc,
5928 Copy_Specification (Loc, Specification (Body_Node)));
5930 Attr_Decl :=
5931 Make_Attribute_Definition_Clause (Loc,
5932 Name => New_Occurrence_Of (RACW_Type, Loc),
5933 Chars => Name_Write,
5934 Expression =>
5935 New_Occurrence_Of (
5936 Defining_Unit_Name (Specification (Proc_Decl)), Loc));
5938 Insert_After (Declaration_Node (RACW_Type), Proc_Decl);
5939 Insert_After (Proc_Decl, Attr_Decl);
5940 Append_To (Declarations, Body_Node);
5941 end Add_RACW_Write_Attribute;
5943 -----------------------
5944 -- Add_RAST_Features --
5945 -----------------------
5947 procedure Add_RAST_Features
5948 (Vis_Decl : Node_Id;
5949 RAS_Type : Entity_Id)
5951 begin
5952 Add_RAS_Access_TSS (Vis_Decl);
5954 Add_RAS_From_Any (RAS_Type);
5955 Add_RAS_TypeCode (RAS_Type);
5957 -- To_Any uses TypeCode, and therefore needs to be generated last
5959 Add_RAS_To_Any (RAS_Type);
5960 end Add_RAST_Features;
5962 ------------------------
5963 -- Add_RAS_Access_TSS --
5964 ------------------------
5966 procedure Add_RAS_Access_TSS (N : Node_Id) is
5967 Loc : constant Source_Ptr := Sloc (N);
5969 Ras_Type : constant Entity_Id := Defining_Identifier (N);
5970 Fat_Type : constant Entity_Id := Equivalent_Type (Ras_Type);
5971 -- Ras_Type is the access to subprogram type; Fat_Type is the
5972 -- corresponding record type.
5974 RACW_Type : constant Entity_Id :=
5975 Underlying_RACW_Type (Ras_Type);
5976 Desig : constant Entity_Id :=
5977 Etype (Designated_Type (RACW_Type));
5979 Stub_Elements : constant Stub_Structure :=
5980 Stubs_Table.Get (Desig);
5981 pragma Assert (Stub_Elements /= Empty_Stub_Structure);
5983 Proc : constant Entity_Id :=
5984 Make_Defining_Identifier (Loc,
5985 Chars => Make_TSS_Name (Ras_Type, TSS_RAS_Access));
5987 Proc_Spec : Node_Id;
5989 -- Formal parameters
5991 Package_Name : constant Entity_Id :=
5992 Make_Defining_Identifier (Loc,
5993 Chars => Name_P);
5995 -- Target package
5997 Subp_Id : constant Entity_Id :=
5998 Make_Defining_Identifier (Loc,
5999 Chars => Name_S);
6001 -- Target subprogram
6003 Asynch_P : constant Entity_Id :=
6004 Make_Defining_Identifier (Loc,
6005 Chars => Name_Asynchronous);
6006 -- Is the procedure to which the 'Access applies asynchronous?
6008 All_Calls_Remote : constant Entity_Id :=
6009 Make_Defining_Identifier (Loc,
6010 Chars => Name_All_Calls_Remote);
6011 -- True if an All_Calls_Remote pragma applies to the RCI unit
6012 -- that contains the subprogram.
6014 -- Common local variables
6016 Proc_Decls : List_Id;
6017 Proc_Statements : List_Id;
6019 Subp_Ref : constant Entity_Id :=
6020 Make_Defining_Identifier (Loc, Name_R);
6021 -- Reference that designates the target subprogram (returned
6022 -- by Get_RAS_Info).
6024 Is_Local : constant Entity_Id :=
6025 Make_Defining_Identifier (Loc, Name_L);
6026 Local_Addr : constant Entity_Id :=
6027 Make_Defining_Identifier (Loc, Name_A);
6028 -- For the call to Get_Local_Address
6030 -- Additional local variables for the remote case
6032 Local_Stub : constant Entity_Id :=
6033 Make_Defining_Identifier (Loc,
6034 Chars => New_Internal_Name ('L'));
6036 Stub_Ptr : constant Entity_Id :=
6037 Make_Defining_Identifier (Loc,
6038 Chars => New_Internal_Name ('S'));
6040 function Set_Field
6041 (Field_Name : Name_Id;
6042 Value : Node_Id) return Node_Id;
6043 -- Construct an assignment that sets the named component in the
6044 -- returned record
6046 ---------------
6047 -- Set_Field --
6048 ---------------
6050 function Set_Field
6051 (Field_Name : Name_Id;
6052 Value : Node_Id) return Node_Id
6054 begin
6055 return
6056 Make_Assignment_Statement (Loc,
6057 Name =>
6058 Make_Selected_Component (Loc,
6059 Prefix => Stub_Ptr,
6060 Selector_Name => Field_Name),
6061 Expression => Value);
6062 end Set_Field;
6064 -- Start of processing for Add_RAS_Access_TSS
6066 begin
6067 Proc_Decls := New_List (
6069 -- Common declarations
6071 Make_Object_Declaration (Loc,
6072 Defining_Identifier => Subp_Ref,
6073 Object_Definition =>
6074 New_Occurrence_Of (RTE (RE_Object_Ref), Loc)),
6076 Make_Object_Declaration (Loc,
6077 Defining_Identifier => Is_Local,
6078 Object_Definition =>
6079 New_Occurrence_Of (Standard_Boolean, Loc)),
6081 Make_Object_Declaration (Loc,
6082 Defining_Identifier => Local_Addr,
6083 Object_Definition =>
6084 New_Occurrence_Of (RTE (RE_Address), Loc)),
6086 Make_Object_Declaration (Loc,
6087 Defining_Identifier => Local_Stub,
6088 Aliased_Present => True,
6089 Object_Definition =>
6090 New_Occurrence_Of (Stub_Elements.Stub_Type, Loc)),
6092 Make_Object_Declaration (Loc,
6093 Defining_Identifier =>
6094 Stub_Ptr,
6095 Object_Definition =>
6096 New_Occurrence_Of (Stub_Elements.Stub_Type_Access, Loc),
6097 Expression =>
6098 Make_Attribute_Reference (Loc,
6099 Prefix => New_Occurrence_Of (Local_Stub, Loc),
6100 Attribute_Name => Name_Unchecked_Access)));
6102 Set_Etype (Stub_Ptr, Stub_Elements.Stub_Type_Access);
6103 -- Build_Get_Unique_RP_Call needs this information
6105 -- Get_RAS_Info (Pkg, Subp, R);
6106 -- Obtain a reference to the target subprogram
6108 Proc_Statements := New_List (
6109 Make_Procedure_Call_Statement (Loc,
6110 Name =>
6111 New_Occurrence_Of (RTE (RE_Get_RAS_Info), Loc),
6112 Parameter_Associations => New_List (
6113 New_Occurrence_Of (Package_Name, Loc),
6114 New_Occurrence_Of (Subp_Id, Loc),
6115 New_Occurrence_Of (Subp_Ref, Loc))),
6117 -- Get_Local_Address (R, L, A);
6118 -- Determine whether the subprogram is local (L), and if so
6119 -- obtain the local address of its proxy (A).
6121 Make_Procedure_Call_Statement (Loc,
6122 Name =>
6123 New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
6124 Parameter_Associations => New_List (
6125 New_Occurrence_Of (Subp_Ref, Loc),
6126 New_Occurrence_Of (Is_Local, Loc),
6127 New_Occurrence_Of (Local_Addr, Loc))));
6129 -- Note: Here we assume that the Fat_Type is a record containing just
6130 -- an access to a proxy or stub object.
6132 Append_To (Proc_Statements,
6134 -- if L then
6136 Make_Implicit_If_Statement (N,
6137 Condition =>
6138 New_Occurrence_Of (Is_Local, Loc),
6140 Then_Statements => New_List (
6142 -- if A.Target = null then
6144 Make_Implicit_If_Statement (N,
6145 Condition =>
6146 Make_Op_Eq (Loc,
6147 Make_Selected_Component (Loc,
6148 Prefix =>
6149 Unchecked_Convert_To (
6150 RTE (RE_RAS_Proxy_Type_Access),
6151 New_Occurrence_Of (Local_Addr, Loc)),
6152 Selector_Name =>
6153 Make_Identifier (Loc, Name_Target)),
6154 Make_Null (Loc)),
6156 Then_Statements => New_List (
6158 -- A.Target := Entity_Of (Ref);
6160 Make_Assignment_Statement (Loc,
6161 Name =>
6162 Make_Selected_Component (Loc,
6163 Prefix =>
6164 Unchecked_Convert_To (
6165 RTE (RE_RAS_Proxy_Type_Access),
6166 New_Occurrence_Of (Local_Addr, Loc)),
6167 Selector_Name =>
6168 Make_Identifier (Loc, Name_Target)),
6169 Expression =>
6170 Make_Function_Call (Loc,
6171 Name =>
6172 New_Occurrence_Of (RTE (RE_Entity_Of), Loc),
6173 Parameter_Associations => New_List (
6174 New_Occurrence_Of (Subp_Ref, Loc)))),
6176 -- Inc_Usage (A.Target);
6178 Make_Procedure_Call_Statement (Loc,
6179 Name =>
6180 New_Occurrence_Of (RTE (RE_Inc_Usage), Loc),
6181 Parameter_Associations => New_List (
6182 Make_Selected_Component (Loc,
6183 Prefix =>
6184 Unchecked_Convert_To (
6185 RTE (RE_RAS_Proxy_Type_Access),
6186 New_Occurrence_Of (Local_Addr, Loc)),
6187 Selector_Name => Make_Identifier (Loc,
6188 Name_Target)))))),
6190 -- end if;
6191 -- if not All_Calls_Remote then
6192 -- return Fat_Type!(A);
6193 -- end if;
6195 Make_Implicit_If_Statement (N,
6196 Condition =>
6197 Make_Op_Not (Loc,
6198 New_Occurrence_Of (All_Calls_Remote, Loc)),
6200 Then_Statements => New_List (
6201 Make_Return_Statement (Loc,
6202 Unchecked_Convert_To (Fat_Type,
6203 New_Occurrence_Of (Local_Addr, Loc))))))));
6205 Append_List_To (Proc_Statements, New_List (
6207 -- Stub.Target := Entity_Of (Ref);
6209 Set_Field (Name_Target,
6210 Make_Function_Call (Loc,
6211 Name =>
6212 New_Occurrence_Of (RTE (RE_Entity_Of), Loc),
6213 Parameter_Associations => New_List (
6214 New_Occurrence_Of (Subp_Ref, Loc)))),
6216 -- Inc_Usage (Stub.Target);
6218 Make_Procedure_Call_Statement (Loc,
6219 Name =>
6220 New_Occurrence_Of (RTE (RE_Inc_Usage), Loc),
6221 Parameter_Associations => New_List (
6222 Make_Selected_Component (Loc,
6223 Prefix => Stub_Ptr,
6224 Selector_Name => Name_Target))),
6226 -- E.4.1(9) A remote call is asynchronous if it is a call to
6227 -- a procedure, or a call through a value of an access-to-procedure
6228 -- type, to which a pragma Asynchronous applies.
6230 -- Parameter Asynch_P is true when the procedure is asynchronous;
6231 -- Expression Asynch_T is true when the type is asynchronous.
6233 Set_Field (Name_Asynchronous,
6234 Make_Or_Else (Loc,
6235 New_Occurrence_Of (Asynch_P, Loc),
6236 New_Occurrence_Of (Boolean_Literals (
6237 Is_Asynchronous (Ras_Type)), Loc)))));
6239 Append_List_To (Proc_Statements,
6240 Build_Get_Unique_RP_Call (Loc,
6241 Stub_Ptr, Stub_Elements.Stub_Type));
6243 Append_To (Proc_Statements,
6244 Make_Return_Statement (Loc,
6245 Expression =>
6246 Unchecked_Convert_To (Fat_Type,
6247 New_Occurrence_Of (Stub_Ptr, Loc))));
6249 Proc_Spec :=
6250 Make_Function_Specification (Loc,
6251 Defining_Unit_Name => Proc,
6252 Parameter_Specifications => New_List (
6253 Make_Parameter_Specification (Loc,
6254 Defining_Identifier => Package_Name,
6255 Parameter_Type =>
6256 New_Occurrence_Of (Standard_String, Loc)),
6258 Make_Parameter_Specification (Loc,
6259 Defining_Identifier => Subp_Id,
6260 Parameter_Type =>
6261 New_Occurrence_Of (Standard_String, Loc)),
6263 Make_Parameter_Specification (Loc,
6264 Defining_Identifier => Asynch_P,
6265 Parameter_Type =>
6266 New_Occurrence_Of (Standard_Boolean, Loc)),
6268 Make_Parameter_Specification (Loc,
6269 Defining_Identifier => All_Calls_Remote,
6270 Parameter_Type =>
6271 New_Occurrence_Of (Standard_Boolean, Loc))),
6273 Result_Definition =>
6274 New_Occurrence_Of (Fat_Type, Loc));
6276 -- Set the kind and return type of the function to prevent
6277 -- ambiguities between Ras_Type and Fat_Type in subsequent analysis.
6279 Set_Ekind (Proc, E_Function);
6280 Set_Etype (Proc, Fat_Type);
6282 Discard_Node (
6283 Make_Subprogram_Body (Loc,
6284 Specification => Proc_Spec,
6285 Declarations => Proc_Decls,
6286 Handled_Statement_Sequence =>
6287 Make_Handled_Sequence_Of_Statements (Loc,
6288 Statements => Proc_Statements)));
6290 Set_TSS (Fat_Type, Proc);
6291 end Add_RAS_Access_TSS;
6293 ----------------------
6294 -- Add_RAS_From_Any --
6295 ----------------------
6297 procedure Add_RAS_From_Any (RAS_Type : Entity_Id) is
6298 Loc : constant Source_Ptr := Sloc (RAS_Type);
6300 Fnam : constant Entity_Id := Make_Defining_Identifier (Loc,
6301 Make_TSS_Name (RAS_Type, TSS_From_Any));
6303 Func_Spec : Node_Id;
6305 Statements : List_Id;
6307 Any_Parameter : constant Entity_Id :=
6308 Make_Defining_Identifier (Loc, Name_A);
6310 begin
6311 Statements := New_List (
6312 Make_Return_Statement (Loc,
6313 Expression =>
6314 Make_Aggregate (Loc,
6315 Component_Associations => New_List (
6316 Make_Component_Association (Loc,
6317 Choices => New_List (
6318 Make_Identifier (Loc, Name_Ras)),
6319 Expression =>
6320 PolyORB_Support.Helpers.Build_From_Any_Call (
6321 Underlying_RACW_Type (RAS_Type),
6322 New_Occurrence_Of (Any_Parameter, Loc),
6323 No_List))))));
6325 Func_Spec :=
6326 Make_Function_Specification (Loc,
6327 Defining_Unit_Name =>
6328 Fnam,
6329 Parameter_Specifications => New_List (
6330 Make_Parameter_Specification (Loc,
6331 Defining_Identifier =>
6332 Any_Parameter,
6333 Parameter_Type =>
6334 New_Occurrence_Of (RTE (RE_Any), Loc))),
6335 Result_Definition => New_Occurrence_Of (RAS_Type, Loc));
6337 Discard_Node (
6338 Make_Subprogram_Body (Loc,
6339 Specification => Func_Spec,
6340 Declarations => No_List,
6341 Handled_Statement_Sequence =>
6342 Make_Handled_Sequence_Of_Statements (Loc,
6343 Statements => Statements)));
6344 Set_TSS (RAS_Type, Fnam);
6345 end Add_RAS_From_Any;
6347 --------------------
6348 -- Add_RAS_To_Any --
6349 --------------------
6351 procedure Add_RAS_To_Any (RAS_Type : Entity_Id) is
6352 Loc : constant Source_Ptr := Sloc (RAS_Type);
6354 Fnam : constant Entity_Id := Make_Defining_Identifier (Loc,
6355 Make_TSS_Name (RAS_Type, TSS_To_Any));
6357 Decls : List_Id;
6358 Statements : List_Id;
6360 Func_Spec : Node_Id;
6362 Any : constant Entity_Id :=
6363 Make_Defining_Identifier (Loc,
6364 Chars => New_Internal_Name ('A'));
6365 RAS_Parameter : constant Entity_Id :=
6366 Make_Defining_Identifier (Loc,
6367 Chars => New_Internal_Name ('R'));
6368 RACW_Parameter : constant Node_Id :=
6369 Make_Selected_Component (Loc,
6370 Prefix => RAS_Parameter,
6371 Selector_Name => Name_Ras);
6373 begin
6374 -- Object declarations
6376 Set_Etype (RACW_Parameter, Underlying_RACW_Type (RAS_Type));
6377 Decls := New_List (
6378 Make_Object_Declaration (Loc,
6379 Defining_Identifier =>
6380 Any,
6381 Object_Definition =>
6382 New_Occurrence_Of (RTE (RE_Any), Loc),
6383 Expression =>
6384 PolyORB_Support.Helpers.Build_To_Any_Call
6385 (RACW_Parameter, No_List)));
6387 Statements := New_List (
6388 Make_Procedure_Call_Statement (Loc,
6389 Name =>
6390 New_Occurrence_Of (RTE (RE_Set_TC), Loc),
6391 Parameter_Associations => New_List (
6392 New_Occurrence_Of (Any, Loc),
6393 PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
6394 RAS_Type, Decls))),
6395 Make_Return_Statement (Loc,
6396 Expression =>
6397 New_Occurrence_Of (Any, Loc)));
6399 Func_Spec :=
6400 Make_Function_Specification (Loc,
6401 Defining_Unit_Name =>
6402 Fnam,
6403 Parameter_Specifications => New_List (
6404 Make_Parameter_Specification (Loc,
6405 Defining_Identifier =>
6406 RAS_Parameter,
6407 Parameter_Type =>
6408 New_Occurrence_Of (RAS_Type, Loc))),
6409 Result_Definition => New_Occurrence_Of (RTE (RE_Any), Loc));
6411 Discard_Node (
6412 Make_Subprogram_Body (Loc,
6413 Specification => Func_Spec,
6414 Declarations => Decls,
6415 Handled_Statement_Sequence =>
6416 Make_Handled_Sequence_Of_Statements (Loc,
6417 Statements => Statements)));
6418 Set_TSS (RAS_Type, Fnam);
6419 end Add_RAS_To_Any;
6421 ----------------------
6422 -- Add_RAS_TypeCode --
6423 ----------------------
6425 procedure Add_RAS_TypeCode (RAS_Type : Entity_Id) is
6426 Loc : constant Source_Ptr := Sloc (RAS_Type);
6428 Fnam : constant Entity_Id := Make_Defining_Identifier (Loc,
6429 Make_TSS_Name (RAS_Type, TSS_TypeCode));
6431 Func_Spec : Node_Id;
6433 Decls : constant List_Id := New_List;
6434 Name_String, Repo_Id_String : String_Id;
6436 begin
6437 Func_Spec :=
6438 Make_Function_Specification (Loc,
6439 Defining_Unit_Name =>
6440 Fnam,
6441 Result_Definition => New_Occurrence_Of (RTE (RE_TypeCode), Loc));
6443 PolyORB_Support.Helpers.Build_Name_And_Repository_Id
6444 (RAS_Type, Name_Str => Name_String, Repo_Id_Str => Repo_Id_String);
6446 Discard_Node (
6447 Make_Subprogram_Body (Loc,
6448 Specification => Func_Spec,
6449 Declarations => Decls,
6450 Handled_Statement_Sequence =>
6451 Make_Handled_Sequence_Of_Statements (Loc,
6452 Statements => New_List (
6453 Make_Return_Statement (Loc,
6454 Expression =>
6455 Make_Function_Call (Loc,
6456 Name =>
6457 New_Occurrence_Of (RTE (RE_TC_Build), Loc),
6458 Parameter_Associations => New_List (
6459 New_Occurrence_Of (RTE (RE_TC_Object), Loc),
6460 Make_Aggregate (Loc,
6461 Expressions =>
6462 New_List (
6463 Make_Function_Call (Loc,
6464 Name => New_Occurrence_Of (
6465 RTE (RE_TA_String), Loc),
6466 Parameter_Associations => New_List (
6467 Make_String_Literal (Loc, Name_String))),
6468 Make_Function_Call (Loc,
6469 Name => New_Occurrence_Of (
6470 RTE (RE_TA_String), Loc),
6471 Parameter_Associations => New_List (
6472 Make_String_Literal (Loc,
6473 Repo_Id_String))))))))))));
6474 Set_TSS (RAS_Type, Fnam);
6475 end Add_RAS_TypeCode;
6477 -----------------------------------------
6478 -- Add_Receiving_Stubs_To_Declarations --
6479 -----------------------------------------
6481 procedure Add_Receiving_Stubs_To_Declarations
6482 (Pkg_Spec : Node_Id;
6483 Decls : List_Id)
6485 Loc : constant Source_Ptr := Sloc (Pkg_Spec);
6487 Pkg_RPC_Receiver : constant Entity_Id :=
6488 Make_Defining_Identifier (Loc,
6489 New_Internal_Name ('H'));
6490 Pkg_RPC_Receiver_Object : Node_Id;
6492 Pkg_RPC_Receiver_Body : Node_Id;
6493 Pkg_RPC_Receiver_Decls : List_Id;
6494 Pkg_RPC_Receiver_Statements : List_Id;
6495 Pkg_RPC_Receiver_Cases : constant List_Id := New_List;
6496 -- A Pkg_RPC_Receiver is built to decode the request
6498 Request : Node_Id;
6499 -- Request object received from neutral layer
6501 Subp_Id : Entity_Id;
6502 -- Subprogram identifier as received from the neutral
6503 -- distribution core.
6505 Subp_Index : Entity_Id;
6506 -- Internal index as determined by matching either the
6507 -- method name from the request structure, or the local
6508 -- subprogram address (in case of a RAS).
6510 Is_Local : constant Entity_Id :=
6511 Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
6512 Local_Address : constant Entity_Id :=
6513 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6514 -- Address of a local subprogram designated by a
6515 -- reference corresponding to a RAS.
6517 Dispatch_On_Address : constant List_Id := New_List;
6518 Dispatch_On_Name : constant List_Id := New_List;
6520 Current_Declaration : Node_Id;
6521 Current_Stubs : Node_Id;
6522 Current_Subprogram_Number : Int := First_RCI_Subprogram_Id;
6524 Subp_Info_Array : constant Entity_Id :=
6525 Make_Defining_Identifier (Loc,
6526 Chars => New_Internal_Name ('I'));
6528 Subp_Info_List : constant List_Id := New_List;
6530 Register_Pkg_Actuals : constant List_Id := New_List;
6532 All_Calls_Remote_E : Entity_Id;
6534 procedure Append_Stubs_To
6535 (RPC_Receiver_Cases : List_Id;
6536 Declaration : Node_Id;
6537 Stubs : Node_Id;
6538 Subp_Number : Int;
6539 Subp_Dist_Name : Entity_Id;
6540 Subp_Proxy_Addr : Entity_Id);
6541 -- Add one case to the specified RPC receiver case list associating
6542 -- Subprogram_Number with the subprogram declared by Declaration, for
6543 -- which we have receiving stubs in Stubs. Subp_Number is an internal
6544 -- subprogram index. Subp_Dist_Name is the string used to call the
6545 -- subprogram by name, and Subp_Dist_Addr is the address of the proxy
6546 -- object, used in the context of calls through remote
6547 -- access-to-subprogram types.
6549 ---------------------
6550 -- Append_Stubs_To --
6551 ---------------------
6553 procedure Append_Stubs_To
6554 (RPC_Receiver_Cases : List_Id;
6555 Declaration : Node_Id;
6556 Stubs : Node_Id;
6557 Subp_Number : Int;
6558 Subp_Dist_Name : Entity_Id;
6559 Subp_Proxy_Addr : Entity_Id)
6561 Case_Stmts : List_Id;
6562 begin
6563 Case_Stmts := New_List (
6564 Make_Procedure_Call_Statement (Loc,
6565 Name =>
6566 New_Occurrence_Of (
6567 Defining_Entity (Stubs), Loc),
6568 Parameter_Associations =>
6569 New_List (New_Occurrence_Of (Request, Loc))));
6570 if Nkind (Specification (Declaration))
6571 = N_Function_Specification
6572 or else not
6573 Is_Asynchronous (Defining_Entity (Specification (Declaration)))
6574 then
6575 Append_To (Case_Stmts, Make_Return_Statement (Loc));
6576 end if;
6578 Append_To (RPC_Receiver_Cases,
6579 Make_Case_Statement_Alternative (Loc,
6580 Discrete_Choices =>
6581 New_List (Make_Integer_Literal (Loc, Subp_Number)),
6582 Statements =>
6583 Case_Stmts));
6585 Append_To (Dispatch_On_Name,
6586 Make_Elsif_Part (Loc,
6587 Condition =>
6588 Make_Function_Call (Loc,
6589 Name =>
6590 New_Occurrence_Of (RTE (RE_Caseless_String_Eq), Loc),
6591 Parameter_Associations => New_List (
6592 New_Occurrence_Of (Subp_Id, Loc),
6593 New_Occurrence_Of (Subp_Dist_Name, Loc))),
6594 Then_Statements => New_List (
6595 Make_Assignment_Statement (Loc,
6596 New_Occurrence_Of (Subp_Index, Loc),
6597 Make_Integer_Literal (Loc,
6598 Subp_Number)))));
6600 Append_To (Dispatch_On_Address,
6601 Make_Elsif_Part (Loc,
6602 Condition =>
6603 Make_Op_Eq (Loc,
6604 Left_Opnd =>
6605 New_Occurrence_Of (Local_Address, Loc),
6606 Right_Opnd =>
6607 New_Occurrence_Of (Subp_Proxy_Addr, Loc)),
6608 Then_Statements => New_List (
6609 Make_Assignment_Statement (Loc,
6610 New_Occurrence_Of (Subp_Index, Loc),
6611 Make_Integer_Literal (Loc,
6612 Subp_Number)))));
6613 end Append_Stubs_To;
6615 -- Start of processing for Add_Receiving_Stubs_To_Declarations
6617 begin
6618 -- Building receiving stubs consist in several operations:
6620 -- - a package RPC receiver must be built. This subprogram
6621 -- will get a Subprogram_Id from the incoming stream
6622 -- and will dispatch the call to the right subprogram
6624 -- - a receiving stub for any subprogram visible in the package
6625 -- spec. This stub will read all the parameters from the stream,
6626 -- and put the result as well as the exception occurrence in the
6627 -- output stream
6629 -- - a dummy package with an empty spec and a body made of an
6630 -- elaboration part, whose job is to register the receiving
6631 -- part of this RCI package on the name server. This is done
6632 -- by calling System.Partition_Interface.Register_Receiving_Stub
6634 Build_RPC_Receiver_Body (
6635 RPC_Receiver => Pkg_RPC_Receiver,
6636 Request => Request,
6637 Subp_Id => Subp_Id,
6638 Subp_Index => Subp_Index,
6639 Stmts => Pkg_RPC_Receiver_Statements,
6640 Decl => Pkg_RPC_Receiver_Body);
6641 Pkg_RPC_Receiver_Decls := Declarations (Pkg_RPC_Receiver_Body);
6643 -- Extract local address information from the target reference:
6644 -- if non-null, that means that this is a reference that denotes
6645 -- one particular operation, and hence that the operation name
6646 -- must not be taken into account for dispatching.
6648 Append_To (Pkg_RPC_Receiver_Decls,
6649 Make_Object_Declaration (Loc,
6650 Defining_Identifier =>
6651 Is_Local,
6652 Object_Definition =>
6653 New_Occurrence_Of (Standard_Boolean, Loc)));
6654 Append_To (Pkg_RPC_Receiver_Decls,
6655 Make_Object_Declaration (Loc,
6656 Defining_Identifier =>
6657 Local_Address,
6658 Object_Definition =>
6659 New_Occurrence_Of (RTE (RE_Address), Loc)));
6660 Append_To (Pkg_RPC_Receiver_Statements,
6661 Make_Procedure_Call_Statement (Loc,
6662 Name =>
6663 New_Occurrence_Of (RTE (RE_Get_Local_Address), Loc),
6664 Parameter_Associations => New_List (
6665 Make_Selected_Component (Loc,
6666 Prefix => Request,
6667 Selector_Name => Name_Target),
6668 New_Occurrence_Of (Is_Local, Loc),
6669 New_Occurrence_Of (Local_Address, Loc))));
6671 -- Determine whether the reference that was used to make
6672 -- the call was the base RCI reference (in which case
6673 -- Local_Address is 0, and the method identifier from the
6674 -- request must be used to determine which subprogram is
6675 -- called) or a reference identifying one particular subprogram
6676 -- (in which case Local_Address is the address of that
6677 -- subprogram, and the method name from the request is
6678 -- ignored).
6679 -- In each case, cascaded elsifs are used to determine the
6680 -- proper subprogram index. Using hash tables might be
6681 -- more efficient.
6683 Append_To (Pkg_RPC_Receiver_Statements,
6684 Make_Implicit_If_Statement (Pkg_Spec,
6685 Condition =>
6686 Make_Op_Ne (Loc,
6687 Left_Opnd => New_Occurrence_Of (Local_Address, Loc),
6688 Right_Opnd => New_Occurrence_Of (RTE (RE_Null_Address), Loc)),
6689 Then_Statements => New_List (
6690 Make_Implicit_If_Statement (Pkg_Spec,
6691 Condition =>
6692 New_Occurrence_Of (Standard_False, Loc),
6693 Then_Statements => New_List (
6694 Make_Null_Statement (Loc)),
6695 Elsif_Parts =>
6696 Dispatch_On_Address)),
6697 Else_Statements => New_List (
6698 Make_Implicit_If_Statement (Pkg_Spec,
6699 Condition =>
6700 New_Occurrence_Of (Standard_False, Loc),
6701 Then_Statements => New_List (
6702 Make_Null_Statement (Loc)),
6703 Elsif_Parts =>
6704 Dispatch_On_Name))));
6706 -- For each subprogram, the receiving stub will be built and a
6707 -- case statement will be made on the Subprogram_Id to dispatch
6708 -- to the right subprogram.
6710 All_Calls_Remote_E := Boolean_Literals (
6711 Has_All_Calls_Remote (Defining_Entity (Pkg_Spec)));
6713 Overload_Counter_Table.Reset;
6714 Reserve_NamingContext_Methods;
6716 Current_Declaration := First (Visible_Declarations (Pkg_Spec));
6717 while Present (Current_Declaration) loop
6718 if Nkind (Current_Declaration) = N_Subprogram_Declaration
6719 and then Comes_From_Source (Current_Declaration)
6720 then
6721 declare
6722 Loc : constant Source_Ptr :=
6723 Sloc (Current_Declaration);
6724 -- While specifically processing Current_Declaration, use
6725 -- its Sloc as the location of all generated nodes.
6727 Subp_Def : constant Entity_Id :=
6728 Defining_Unit_Name
6729 (Specification (Current_Declaration));
6731 Subp_Val : String_Id;
6733 Subp_Dist_Name : constant Entity_Id :=
6734 Make_Defining_Identifier (Loc,
6735 New_External_Name (
6736 Related_Id => Chars (Subp_Def),
6737 Suffix => 'D',
6738 Suffix_Index => -1));
6740 Proxy_Object_Addr : Entity_Id;
6742 begin
6743 -- Build receiving stub
6745 Current_Stubs :=
6746 Build_Subprogram_Receiving_Stubs
6747 (Vis_Decl => Current_Declaration,
6748 Asynchronous =>
6749 Nkind (Specification (Current_Declaration)) =
6750 N_Procedure_Specification
6751 and then Is_Asynchronous (Subp_Def));
6753 Append_To (Decls, Current_Stubs);
6754 Analyze (Current_Stubs);
6756 -- Build RAS proxy
6758 Add_RAS_Proxy_And_Analyze (Decls,
6759 Vis_Decl =>
6760 Current_Declaration,
6761 All_Calls_Remote_E =>
6762 All_Calls_Remote_E,
6763 Proxy_Object_Addr =>
6764 Proxy_Object_Addr);
6766 -- Compute distribution identifier
6768 Assign_Subprogram_Identifier (
6769 Subp_Def,
6770 Current_Subprogram_Number,
6771 Subp_Val);
6773 pragma Assert (Current_Subprogram_Number =
6774 Get_Subprogram_Id (Subp_Def));
6776 Append_To (Decls,
6777 Make_Object_Declaration (Loc,
6778 Defining_Identifier => Subp_Dist_Name,
6779 Constant_Present => True,
6780 Object_Definition => New_Occurrence_Of (
6781 Standard_String, Loc),
6782 Expression =>
6783 Make_String_Literal (Loc, Subp_Val)));
6784 Analyze (Last (Decls));
6786 -- Add subprogram descriptor (RCI_Subp_Info) to the
6787 -- subprograms table for this receiver. The aggregate
6788 -- below must be kept consistent with the declaration
6789 -- of type RCI_Subp_Info in System.Partition_Interface.
6791 Append_To (Subp_Info_List,
6792 Make_Component_Association (Loc,
6793 Choices => New_List (
6794 Make_Integer_Literal (Loc,
6795 Current_Subprogram_Number)),
6796 Expression =>
6797 Make_Aggregate (Loc,
6798 Expressions => New_List (
6799 Make_Attribute_Reference (Loc,
6800 Prefix =>
6801 New_Occurrence_Of (
6802 Subp_Dist_Name, Loc),
6803 Attribute_Name => Name_Address),
6804 Make_Attribute_Reference (Loc,
6805 Prefix =>
6806 New_Occurrence_Of (
6807 Subp_Dist_Name, Loc),
6808 Attribute_Name => Name_Length),
6809 New_Occurrence_Of (Proxy_Object_Addr, Loc)))));
6811 Append_Stubs_To (Pkg_RPC_Receiver_Cases,
6812 Declaration => Current_Declaration,
6813 Stubs => Current_Stubs,
6814 Subp_Number => Current_Subprogram_Number,
6815 Subp_Dist_Name => Subp_Dist_Name,
6816 Subp_Proxy_Addr => Proxy_Object_Addr);
6817 end;
6819 Current_Subprogram_Number := Current_Subprogram_Number + 1;
6820 end if;
6822 Next (Current_Declaration);
6823 end loop;
6825 -- If we receive an invalid Subprogram_Id, it is best to do nothing
6826 -- rather than raising an exception since we do not want someone
6827 -- to crash a remote partition by sending invalid subprogram ids.
6828 -- This is consistent with the other parts of the case statement
6829 -- since even in presence of incorrect parameters in the stream,
6830 -- every exception will be caught and (if the subprogram is not an
6831 -- APC) put into the result stream and sent away.
6833 Append_To (Pkg_RPC_Receiver_Cases,
6834 Make_Case_Statement_Alternative (Loc,
6835 Discrete_Choices =>
6836 New_List (Make_Others_Choice (Loc)),
6837 Statements =>
6838 New_List (Make_Null_Statement (Loc))));
6840 Append_To (Pkg_RPC_Receiver_Statements,
6841 Make_Case_Statement (Loc,
6842 Expression =>
6843 New_Occurrence_Of (Subp_Index, Loc),
6844 Alternatives => Pkg_RPC_Receiver_Cases));
6846 Append_To (Decls,
6847 Make_Object_Declaration (Loc,
6848 Defining_Identifier => Subp_Info_Array,
6849 Constant_Present => True,
6850 Aliased_Present => True,
6851 Object_Definition =>
6852 Make_Subtype_Indication (Loc,
6853 Subtype_Mark =>
6854 New_Occurrence_Of (RTE (RE_RCI_Subp_Info_Array), Loc),
6855 Constraint =>
6856 Make_Index_Or_Discriminant_Constraint (Loc,
6857 New_List (
6858 Make_Range (Loc,
6859 Low_Bound => Make_Integer_Literal (Loc,
6860 First_RCI_Subprogram_Id),
6861 High_Bound =>
6862 Make_Integer_Literal (Loc,
6863 First_RCI_Subprogram_Id
6864 + List_Length (Subp_Info_List) - 1))))),
6865 Expression =>
6866 Make_Aggregate (Loc,
6867 Component_Associations => Subp_Info_List)));
6868 Analyze (Last (Decls));
6870 Append_To (Decls, Pkg_RPC_Receiver_Body);
6871 Analyze (Last (Decls));
6873 Pkg_RPC_Receiver_Object :=
6874 Make_Object_Declaration (Loc,
6875 Defining_Identifier =>
6876 Make_Defining_Identifier (Loc, New_Internal_Name ('R')),
6877 Aliased_Present => True,
6878 Object_Definition =>
6879 New_Occurrence_Of (RTE (RE_Servant), Loc));
6880 Append_To (Decls, Pkg_RPC_Receiver_Object);
6881 Analyze (Last (Decls));
6883 Get_Library_Unit_Name_String (Pkg_Spec);
6884 Append_To (Register_Pkg_Actuals,
6885 -- Name
6886 Make_String_Literal (Loc,
6887 Strval => String_From_Name_Buffer));
6889 Append_To (Register_Pkg_Actuals,
6890 -- Version
6891 Make_Attribute_Reference (Loc,
6892 Prefix =>
6893 New_Occurrence_Of
6894 (Defining_Entity (Pkg_Spec), Loc),
6895 Attribute_Name =>
6896 Name_Version));
6898 Append_To (Register_Pkg_Actuals,
6899 -- Handler
6900 Make_Attribute_Reference (Loc,
6901 Prefix =>
6902 New_Occurrence_Of (Pkg_RPC_Receiver, Loc),
6903 Attribute_Name => Name_Access));
6905 Append_To (Register_Pkg_Actuals,
6906 -- Receiver
6907 Make_Attribute_Reference (Loc,
6908 Prefix =>
6909 New_Occurrence_Of (
6910 Defining_Identifier (
6911 Pkg_RPC_Receiver_Object), Loc),
6912 Attribute_Name =>
6913 Name_Access));
6915 Append_To (Register_Pkg_Actuals,
6916 -- Subp_Info
6917 Make_Attribute_Reference (Loc,
6918 Prefix =>
6919 New_Occurrence_Of (Subp_Info_Array, Loc),
6920 Attribute_Name =>
6921 Name_Address));
6923 Append_To (Register_Pkg_Actuals,
6924 -- Subp_Info_Len
6925 Make_Attribute_Reference (Loc,
6926 Prefix =>
6927 New_Occurrence_Of (Subp_Info_Array, Loc),
6928 Attribute_Name =>
6929 Name_Length));
6931 Append_To (Register_Pkg_Actuals,
6932 -- Is_All_Calls_Remote
6933 New_Occurrence_Of (All_Calls_Remote_E, Loc));
6935 Append_To (Decls,
6936 Make_Procedure_Call_Statement (Loc,
6937 Name =>
6938 New_Occurrence_Of (RTE (RE_Register_Pkg_Receiving_Stub), Loc),
6939 Parameter_Associations => Register_Pkg_Actuals));
6940 Analyze (Last (Decls));
6942 end Add_Receiving_Stubs_To_Declarations;
6944 ---------------------------------
6945 -- Build_General_Calling_Stubs --
6946 ---------------------------------
6948 procedure Build_General_Calling_Stubs
6949 (Decls : List_Id;
6950 Statements : List_Id;
6951 Target_Object : Node_Id;
6952 Subprogram_Id : Node_Id;
6953 Asynchronous : Node_Id := Empty;
6954 Is_Known_Asynchronous : Boolean := False;
6955 Is_Known_Non_Asynchronous : Boolean := False;
6956 Is_Function : Boolean;
6957 Spec : Node_Id;
6958 Stub_Type : Entity_Id := Empty;
6959 RACW_Type : Entity_Id := Empty;
6960 Nod : Node_Id)
6962 Loc : constant Source_Ptr := Sloc (Nod);
6964 Arguments : Node_Id;
6965 -- Name of the named values list used to transmit parameters
6966 -- to the remote package
6968 Request : Node_Id;
6969 -- The request object constructed by these stubs
6971 Result : Node_Id;
6972 -- Name of the result named value (in non-APC cases) which get the
6973 -- result of the remote subprogram.
6975 Result_TC : Node_Id;
6976 -- Typecode expression for the result of the request (void
6977 -- typecode for procedures).
6979 Exception_Return_Parameter : Node_Id;
6980 -- Name of the parameter which will hold the exception sent by the
6981 -- remote subprogram.
6983 Current_Parameter : Node_Id;
6984 -- Current parameter being handled
6986 Ordered_Parameters_List : constant List_Id :=
6987 Build_Ordered_Parameters_List (Spec);
6989 Asynchronous_P : Node_Id;
6990 -- A Boolean expression indicating whether this call is asynchronous
6992 Asynchronous_Statements : List_Id := No_List;
6993 Non_Asynchronous_Statements : List_Id := No_List;
6994 -- Statements specifics to the Asynchronous/Non-Asynchronous cases
6996 Extra_Formal_Statements : constant List_Id := New_List;
6997 -- List of statements for extra formal parameters. It will appear
6998 -- after the regular statements for writing out parameters.
7000 After_Statements : constant List_Id := New_List;
7001 -- Statements to be executed after call returns (to assign
7002 -- in out or out parameter values).
7004 Etyp : Entity_Id;
7005 -- The type of the formal parameter being processed
7007 Is_Controlling_Formal : Boolean;
7008 Is_First_Controlling_Formal : Boolean;
7009 First_Controlling_Formal_Seen : Boolean := False;
7010 -- Controlling formal parameters of distributed object primitives
7011 -- require special handling, and the first such parameter needs even
7012 -- more special handling.
7014 begin
7015 -- ??? document general form of stub subprograms for the PolyORB case
7016 Request :=
7017 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
7019 Append_To (Decls,
7020 Make_Object_Declaration (Loc,
7021 Defining_Identifier => Request,
7022 Aliased_Present => False,
7023 Object_Definition =>
7024 New_Occurrence_Of (RTE (RE_Request_Access), Loc)));
7026 Result :=
7027 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
7029 if Is_Function then
7030 Result_TC := PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
7031 Etype (Result_Definition (Spec)), Decls);
7032 else
7033 Result_TC := New_Occurrence_Of (RTE (RE_TC_Void), Loc);
7034 end if;
7036 Append_To (Decls,
7037 Make_Object_Declaration (Loc,
7038 Defining_Identifier => Result,
7039 Aliased_Present => False,
7040 Object_Definition =>
7041 New_Occurrence_Of (RTE (RE_NamedValue), Loc),
7042 Expression =>
7043 Make_Aggregate (Loc,
7044 Component_Associations => New_List (
7045 Make_Component_Association (Loc,
7046 Choices => New_List (
7047 Make_Identifier (Loc, Name_Name)),
7048 Expression =>
7049 New_Occurrence_Of (RTE (RE_Result_Name), Loc)),
7050 Make_Component_Association (Loc,
7051 Choices => New_List (
7052 Make_Identifier (Loc, Name_Argument)),
7053 Expression =>
7054 Make_Function_Call (Loc,
7055 Name =>
7056 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7057 Parameter_Associations => New_List (
7058 Result_TC))),
7059 Make_Component_Association (Loc,
7060 Choices => New_List (
7061 Make_Identifier (Loc, Name_Arg_Modes)),
7062 Expression =>
7063 Make_Integer_Literal (Loc, 0))))));
7065 if not Is_Known_Asynchronous then
7066 Exception_Return_Parameter :=
7067 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
7069 Append_To (Decls,
7070 Make_Object_Declaration (Loc,
7071 Defining_Identifier => Exception_Return_Parameter,
7072 Object_Definition =>
7073 New_Occurrence_Of (RTE (RE_Exception_Occurrence), Loc)));
7075 else
7076 Exception_Return_Parameter := Empty;
7077 end if;
7079 -- Initialize and fill in arguments list
7081 Arguments :=
7082 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7083 Declare_Create_NVList (Loc, Arguments, Decls, Statements);
7085 Current_Parameter := First (Ordered_Parameters_List);
7086 while Present (Current_Parameter) loop
7088 if Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type) then
7089 Is_Controlling_Formal := True;
7090 Is_First_Controlling_Formal :=
7091 not First_Controlling_Formal_Seen;
7092 First_Controlling_Formal_Seen := True;
7093 else
7094 Is_Controlling_Formal := False;
7095 Is_First_Controlling_Formal := False;
7096 end if;
7098 if Is_Controlling_Formal then
7100 -- In the case of a controlling formal argument, we send its
7101 -- reference.
7103 Etyp := RACW_Type;
7105 else
7106 Etyp := Etype (Parameter_Type (Current_Parameter));
7107 end if;
7109 -- The first controlling formal parameter is treated specially: it
7110 -- is used to set the target object of the call.
7112 if not Is_First_Controlling_Formal then
7114 declare
7115 Constrained : constant Boolean :=
7116 Is_Constrained (Etyp)
7117 or else Is_Elementary_Type (Etyp);
7119 Any : constant Entity_Id :=
7120 Make_Defining_Identifier (Loc,
7121 New_Internal_Name ('A'));
7123 Actual_Parameter : Node_Id :=
7124 New_Occurrence_Of (
7125 Defining_Identifier (
7126 Current_Parameter), Loc);
7128 Expr : Node_Id;
7130 begin
7131 if Is_Controlling_Formal then
7133 -- For a controlling formal parameter (other than the
7134 -- first one), use the corresponding RACW. If the
7135 -- parameter is not an anonymous access parameter, that
7136 -- involves taking its 'Unrestricted_Access.
7138 if Nkind (Parameter_Type (Current_Parameter))
7139 = N_Access_Definition
7140 then
7141 Actual_Parameter := OK_Convert_To
7142 (Etyp, Actual_Parameter);
7143 else
7144 Actual_Parameter := OK_Convert_To (Etyp,
7145 Make_Attribute_Reference (Loc,
7146 Prefix =>
7147 Actual_Parameter,
7148 Attribute_Name =>
7149 Name_Unrestricted_Access));
7150 end if;
7152 end if;
7154 if In_Present (Current_Parameter)
7155 or else not Out_Present (Current_Parameter)
7156 or else not Constrained
7157 or else Is_Controlling_Formal
7158 then
7159 -- The parameter has an input value, is constrained at
7160 -- runtime by an input value, or is a controlling formal
7161 -- parameter (always passed as a reference) other than
7162 -- the first one.
7164 Expr := PolyORB_Support.Helpers.Build_To_Any_Call (
7165 Actual_Parameter, Decls);
7166 else
7167 Expr := Make_Function_Call (Loc,
7168 Name =>
7169 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7170 Parameter_Associations => New_List (
7171 PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
7172 Etyp, Decls)));
7173 end if;
7175 Append_To (Decls,
7176 Make_Object_Declaration (Loc,
7177 Defining_Identifier =>
7178 Any,
7179 Aliased_Present => False,
7180 Object_Definition =>
7181 New_Occurrence_Of (RTE (RE_Any), Loc),
7182 Expression =>
7183 Expr));
7185 Append_To (Statements,
7186 Add_Parameter_To_NVList (Loc,
7187 Parameter => Current_Parameter,
7188 NVList => Arguments,
7189 Constrained => Constrained,
7190 Any => Any));
7192 if Out_Present (Current_Parameter)
7193 and then not Is_Controlling_Formal
7194 then
7195 Append_To (After_Statements,
7196 Make_Assignment_Statement (Loc,
7197 Name =>
7198 New_Occurrence_Of (
7199 Defining_Identifier (Current_Parameter), Loc),
7200 Expression =>
7201 PolyORB_Support.Helpers.Build_From_Any_Call (
7202 Etype (Parameter_Type (Current_Parameter)),
7203 New_Occurrence_Of (Any, Loc),
7204 Decls)));
7206 end if;
7207 end;
7208 end if;
7210 -- If the current parameter has a dynamic constrained status, then
7211 -- this status is transmitted as well.
7212 -- This should be done for accessibility as well ???
7214 if Nkind (Parameter_Type (Current_Parameter))
7215 /= N_Access_Definition
7216 and then Need_Extra_Constrained (Current_Parameter)
7217 then
7218 -- In this block, we do not use the extra formal that has been
7219 -- created because it does not exist at the time of expansion
7220 -- when building calling stubs for remote access to subprogram
7221 -- types. We create an extra variable of this type and push it
7222 -- in the stream after the regular parameters.
7224 declare
7225 Extra_Any_Parameter : constant Entity_Id :=
7226 Make_Defining_Identifier
7227 (Loc, New_Internal_Name ('P'));
7229 begin
7230 Append_To (Decls,
7231 Make_Object_Declaration (Loc,
7232 Defining_Identifier =>
7233 Extra_Any_Parameter,
7234 Aliased_Present => False,
7235 Object_Definition =>
7236 New_Occurrence_Of (RTE (RE_Any), Loc),
7237 Expression =>
7238 PolyORB_Support.Helpers.Build_To_Any_Call (
7239 Make_Attribute_Reference (Loc,
7240 Prefix =>
7241 New_Occurrence_Of (
7242 Defining_Identifier (Current_Parameter), Loc),
7243 Attribute_Name => Name_Constrained),
7244 Decls)));
7245 Append_To (Extra_Formal_Statements,
7246 Add_Parameter_To_NVList (Loc,
7247 Parameter => Extra_Any_Parameter,
7248 NVList => Arguments,
7249 Constrained => True,
7250 Any => Extra_Any_Parameter));
7251 end;
7252 end if;
7254 Next (Current_Parameter);
7255 end loop;
7257 -- Append the formal statements list to the statements
7259 Append_List_To (Statements, Extra_Formal_Statements);
7261 Append_To (Statements,
7262 Make_Procedure_Call_Statement (Loc,
7263 Name =>
7264 New_Occurrence_Of (RTE (RE_Request_Create), Loc),
7265 Parameter_Associations => New_List (
7266 Target_Object,
7267 Subprogram_Id,
7268 New_Occurrence_Of (Arguments, Loc),
7269 New_Occurrence_Of (Result, Loc),
7270 New_Occurrence_Of (RTE (RE_Nil_Exc_List), Loc))));
7272 Append_To (Parameter_Associations (Last (Statements)),
7273 New_Occurrence_Of (Request, Loc));
7275 pragma Assert (
7276 not (Is_Known_Non_Asynchronous and Is_Known_Asynchronous));
7277 if Is_Known_Non_Asynchronous or Is_Known_Asynchronous then
7278 Asynchronous_P := New_Occurrence_Of (
7279 Boolean_Literals (Is_Known_Asynchronous), Loc);
7280 else
7281 pragma Assert (Present (Asynchronous));
7282 Asynchronous_P := New_Copy_Tree (Asynchronous);
7283 -- The expression node Asynchronous will be used to build an 'if'
7284 -- statement at the end of Build_General_Calling_Stubs: we need to
7285 -- make a copy here.
7286 end if;
7288 Append_To (Parameter_Associations (Last (Statements)),
7289 Make_Indexed_Component (Loc,
7290 Prefix =>
7291 New_Occurrence_Of (
7292 RTE (RE_Asynchronous_P_To_Sync_Scope), Loc),
7293 Expressions => New_List (Asynchronous_P)));
7295 Append_To (Statements,
7296 Make_Procedure_Call_Statement (Loc,
7297 Name =>
7298 New_Occurrence_Of (RTE (RE_Request_Invoke), Loc),
7299 Parameter_Associations => New_List (
7300 New_Occurrence_Of (Request, Loc))));
7302 Non_Asynchronous_Statements := New_List (Make_Null_Statement (Loc));
7303 Asynchronous_Statements := New_List (Make_Null_Statement (Loc));
7305 if not Is_Known_Asynchronous then
7307 -- Reraise an exception occurrence from the completed request.
7308 -- If the exception occurrence is empty, this is a no-op.
7310 Append_To (Non_Asynchronous_Statements,
7311 Make_Procedure_Call_Statement (Loc,
7312 Name =>
7313 New_Occurrence_Of (RTE (RE_Request_Raise_Occurrence), Loc),
7314 Parameter_Associations => New_List (
7315 New_Occurrence_Of (Request, Loc))));
7317 if Is_Function then
7319 -- If this is a function call, read the value and return it
7321 Append_To (Non_Asynchronous_Statements,
7322 Make_Tag_Check (Loc,
7323 Make_Return_Statement (Loc,
7324 PolyORB_Support.Helpers.Build_From_Any_Call (
7325 Etype (Result_Definition (Spec)),
7326 Make_Selected_Component (Loc,
7327 Prefix => Result,
7328 Selector_Name => Name_Argument),
7329 Decls))));
7330 end if;
7331 end if;
7333 Append_List_To (Non_Asynchronous_Statements,
7334 After_Statements);
7336 if Is_Known_Asynchronous then
7337 Append_List_To (Statements, Asynchronous_Statements);
7339 elsif Is_Known_Non_Asynchronous then
7340 Append_List_To (Statements, Non_Asynchronous_Statements);
7342 else
7343 pragma Assert (Present (Asynchronous));
7344 Append_To (Statements,
7345 Make_Implicit_If_Statement (Nod,
7346 Condition => Asynchronous,
7347 Then_Statements => Asynchronous_Statements,
7348 Else_Statements => Non_Asynchronous_Statements));
7349 end if;
7350 end Build_General_Calling_Stubs;
7352 -----------------------
7353 -- Build_Stub_Target --
7354 -----------------------
7356 function Build_Stub_Target
7357 (Loc : Source_Ptr;
7358 Decls : List_Id;
7359 RCI_Locator : Entity_Id;
7360 Controlling_Parameter : Entity_Id) return RPC_Target
7362 Target_Info : RPC_Target (PCS_Kind => Name_PolyORB_DSA);
7363 Target_Reference : constant Entity_Id :=
7364 Make_Defining_Identifier (Loc,
7365 New_Internal_Name ('T'));
7366 begin
7367 if Present (Controlling_Parameter) then
7368 Append_To (Decls,
7369 Make_Object_Declaration (Loc,
7370 Defining_Identifier => Target_Reference,
7371 Object_Definition =>
7372 New_Occurrence_Of (RTE (RE_Object_Ref), Loc),
7373 Expression =>
7374 Make_Function_Call (Loc,
7375 Name =>
7376 New_Occurrence_Of (RTE (RE_Make_Ref), Loc),
7377 Parameter_Associations => New_List (
7378 Make_Selected_Component (Loc,
7379 Prefix => Controlling_Parameter,
7380 Selector_Name => Name_Target)))));
7381 -- Controlling_Parameter has the same components as
7382 -- System.Partition_Interface.RACW_Stub_Type.
7384 Target_Info.Object := New_Occurrence_Of (Target_Reference, Loc);
7386 else
7387 Target_Info.Object :=
7388 Make_Selected_Component (Loc,
7389 Prefix =>
7390 Make_Identifier (Loc, Chars (RCI_Locator)),
7391 Selector_Name =>
7392 Make_Identifier (Loc, Name_Get_RCI_Package_Ref));
7393 end if;
7394 return Target_Info;
7395 end Build_Stub_Target;
7397 ---------------------
7398 -- Build_Stub_Type --
7399 ---------------------
7401 procedure Build_Stub_Type
7402 (RACW_Type : Entity_Id;
7403 Stub_Type : Entity_Id;
7404 Stub_Type_Decl : out Node_Id;
7405 RPC_Receiver_Decl : out Node_Id)
7407 Loc : constant Source_Ptr := Sloc (Stub_Type);
7408 pragma Warnings (Off);
7409 pragma Unreferenced (RACW_Type);
7410 pragma Warnings (On);
7412 begin
7413 Stub_Type_Decl :=
7414 Make_Full_Type_Declaration (Loc,
7415 Defining_Identifier => Stub_Type,
7416 Type_Definition =>
7417 Make_Record_Definition (Loc,
7418 Tagged_Present => True,
7419 Limited_Present => True,
7420 Component_List =>
7421 Make_Component_List (Loc,
7422 Component_Items => New_List (
7424 Make_Component_Declaration (Loc,
7425 Defining_Identifier =>
7426 Make_Defining_Identifier (Loc, Name_Target),
7427 Component_Definition =>
7428 Make_Component_Definition (Loc,
7429 Aliased_Present =>
7430 False,
7431 Subtype_Indication =>
7432 New_Occurrence_Of (RTE (RE_Entity_Ptr), Loc))),
7434 Make_Component_Declaration (Loc,
7435 Defining_Identifier =>
7436 Make_Defining_Identifier (Loc, Name_Asynchronous),
7437 Component_Definition =>
7438 Make_Component_Definition (Loc,
7439 Aliased_Present => False,
7440 Subtype_Indication =>
7441 New_Occurrence_Of (
7442 Standard_Boolean, Loc)))))));
7444 RPC_Receiver_Decl :=
7445 Make_Object_Declaration (Loc,
7446 Defining_Identifier => Make_Defining_Identifier (Loc,
7447 New_Internal_Name ('R')),
7448 Aliased_Present => True,
7449 Object_Definition =>
7450 New_Occurrence_Of (RTE (RE_Servant), Loc));
7451 end Build_Stub_Type;
7453 -----------------------------
7454 -- Build_RPC_Receiver_Body --
7455 -----------------------------
7457 procedure Build_RPC_Receiver_Body
7458 (RPC_Receiver : Entity_Id;
7459 Request : out Entity_Id;
7460 Subp_Id : out Entity_Id;
7461 Subp_Index : out Entity_Id;
7462 Stmts : out List_Id;
7463 Decl : out Node_Id)
7465 Loc : constant Source_Ptr := Sloc (RPC_Receiver);
7467 RPC_Receiver_Spec : Node_Id;
7468 RPC_Receiver_Decls : List_Id;
7470 begin
7471 Request := Make_Defining_Identifier (Loc, Name_R);
7473 RPC_Receiver_Spec :=
7474 Build_RPC_Receiver_Specification (
7475 RPC_Receiver => RPC_Receiver,
7476 Request_Parameter => Request);
7478 Subp_Id := Make_Defining_Identifier (Loc, Name_P);
7479 Subp_Index := Make_Defining_Identifier (Loc, Name_I);
7481 RPC_Receiver_Decls := New_List (
7482 Make_Object_Renaming_Declaration (Loc,
7483 Defining_Identifier => Subp_Id,
7484 Subtype_Mark => New_Occurrence_Of (Standard_String, Loc),
7485 Name =>
7486 Make_Explicit_Dereference (Loc,
7487 Prefix =>
7488 Make_Selected_Component (Loc,
7489 Prefix => Request,
7490 Selector_Name => Name_Operation))),
7492 Make_Object_Declaration (Loc,
7493 Defining_Identifier => Subp_Index,
7494 Object_Definition =>
7495 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
7496 Expression =>
7497 Make_Attribute_Reference (Loc,
7498 Prefix =>
7499 New_Occurrence_Of (RTE (RE_Subprogram_Id), Loc),
7500 Attribute_Name => Name_Last)));
7502 Stmts := New_List;
7504 Decl :=
7505 Make_Subprogram_Body (Loc,
7506 Specification => RPC_Receiver_Spec,
7507 Declarations => RPC_Receiver_Decls,
7508 Handled_Statement_Sequence =>
7509 Make_Handled_Sequence_Of_Statements (Loc,
7510 Statements => Stmts));
7511 end Build_RPC_Receiver_Body;
7513 --------------------------------------
7514 -- Build_Subprogram_Receiving_Stubs --
7515 --------------------------------------
7517 function Build_Subprogram_Receiving_Stubs
7518 (Vis_Decl : Node_Id;
7519 Asynchronous : Boolean;
7520 Dynamically_Asynchronous : Boolean := False;
7521 Stub_Type : Entity_Id := Empty;
7522 RACW_Type : Entity_Id := Empty;
7523 Parent_Primitive : Entity_Id := Empty) return Node_Id
7525 Loc : constant Source_Ptr := Sloc (Vis_Decl);
7527 Request_Parameter : Node_Id;
7528 -- ???
7530 Outer_Decls : constant List_Id := New_List;
7531 -- At the outermost level, an NVList and Any's are declared for all
7532 -- parameters. The Dynamic_Async flag also needs to be declared there
7533 -- to be visible from the exception handling code.
7535 Outer_Statements : constant List_Id := New_List;
7536 -- Statements that occur prior to the declaration of the actual
7537 -- parameter variables.
7539 Decls : constant List_Id := New_List;
7540 -- All the parameters will get declared before calling the real
7541 -- subprograms. Also the out parameters will be declared.
7542 -- At this level, parameters may be unconstrained.
7544 Statements : constant List_Id := New_List;
7546 Extra_Formal_Statements : constant List_Id := New_List;
7547 -- Statements concerning extra formal parameters
7549 After_Statements : constant List_Id := New_List;
7550 -- Statements to be executed after the subprogram call
7552 Inner_Decls : List_Id := No_List;
7553 -- In case of a function, the inner declarations are needed since
7554 -- the result may be unconstrained.
7556 Excep_Handlers : List_Id := No_List;
7558 Parameter_List : constant List_Id := New_List;
7559 -- List of parameters to be passed to the subprogram
7561 First_Controlling_Formal_Seen : Boolean := False;
7563 Current_Parameter : Node_Id;
7565 Ordered_Parameters_List : constant List_Id :=
7566 Build_Ordered_Parameters_List
7567 (Specification (Vis_Decl));
7569 Arguments : Node_Id;
7570 -- Name of the named values list used to retrieve parameters
7572 Subp_Spec : Node_Id;
7573 -- Subprogram specification
7575 Called_Subprogram : Node_Id;
7576 -- The subprogram to call
7578 begin
7579 if Present (RACW_Type) then
7580 Called_Subprogram :=
7581 New_Occurrence_Of (Parent_Primitive, Loc);
7582 else
7583 Called_Subprogram :=
7584 New_Occurrence_Of (
7585 Defining_Unit_Name (Specification (Vis_Decl)), Loc);
7586 end if;
7588 Request_Parameter :=
7589 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
7591 Arguments :=
7592 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7593 Declare_Create_NVList (Loc, Arguments, Outer_Decls, Outer_Statements);
7595 -- Loop through every parameter and get its value from the stream. If
7596 -- the parameter is unconstrained, then the parameter is read using
7597 -- 'Input at the point of declaration.
7599 Current_Parameter := First (Ordered_Parameters_List);
7600 while Present (Current_Parameter) loop
7601 declare
7602 Etyp : Entity_Id;
7603 Constrained : Boolean;
7604 Any : Entity_Id := Empty;
7605 Object : constant Entity_Id :=
7606 Make_Defining_Identifier (Loc,
7607 New_Internal_Name ('P'));
7608 Expr : Node_Id := Empty;
7610 Is_Controlling_Formal : constant Boolean
7611 := Is_RACW_Controlling_Formal (Current_Parameter, Stub_Type);
7613 Is_First_Controlling_Formal : Boolean := False;
7614 begin
7615 Set_Ekind (Object, E_Variable);
7617 if Is_Controlling_Formal then
7619 -- Controlling formals in distributed object primitive
7620 -- operations are handled specially:
7621 -- - the first controlling formal is used as the
7622 -- target of the call;
7623 -- - the remaining controlling formals are transmitted
7624 -- as RACWs.
7626 Etyp := RACW_Type;
7627 Is_First_Controlling_Formal :=
7628 not First_Controlling_Formal_Seen;
7629 First_Controlling_Formal_Seen := True;
7630 else
7631 Etyp := Etype (Parameter_Type (Current_Parameter));
7632 end if;
7634 Constrained :=
7635 Is_Constrained (Etyp)
7636 or else Is_Elementary_Type (Etyp);
7638 if not Is_First_Controlling_Formal then
7639 Any := Make_Defining_Identifier (Loc,
7640 New_Internal_Name ('A'));
7641 Append_To (Outer_Decls,
7642 Make_Object_Declaration (Loc,
7643 Defining_Identifier =>
7644 Any,
7645 Object_Definition =>
7646 New_Occurrence_Of (RTE (RE_Any), Loc),
7647 Expression =>
7648 Make_Function_Call (Loc,
7649 Name =>
7650 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
7651 Parameter_Associations => New_List (
7652 PolyORB_Support.Helpers.Build_TypeCode_Call (Loc,
7653 Etyp, Outer_Decls)))));
7655 Append_To (Outer_Statements,
7656 Add_Parameter_To_NVList (Loc,
7657 Parameter => Current_Parameter,
7658 NVList => Arguments,
7659 Constrained => Constrained,
7660 Any => Any));
7661 end if;
7663 if Is_First_Controlling_Formal then
7664 declare
7665 Addr : constant Entity_Id :=
7666 Make_Defining_Identifier (Loc,
7667 New_Internal_Name ('A'));
7668 Is_Local : constant Entity_Id :=
7669 Make_Defining_Identifier (Loc,
7670 New_Internal_Name ('L'));
7671 begin
7673 -- Special case: obtain the first controlling
7674 -- formal from the target of the remote call,
7675 -- instead of the argument list.
7677 Append_To (Outer_Decls,
7678 Make_Object_Declaration (Loc,
7679 Defining_Identifier =>
7680 Addr,
7681 Object_Definition =>
7682 New_Occurrence_Of (RTE (RE_Address), Loc)));
7683 Append_To (Outer_Decls,
7684 Make_Object_Declaration (Loc,
7685 Defining_Identifier =>
7686 Is_Local,
7687 Object_Definition =>
7688 New_Occurrence_Of (Standard_Boolean, Loc)));
7689 Append_To (Outer_Statements,
7690 Make_Procedure_Call_Statement (Loc,
7691 Name =>
7692 New_Occurrence_Of (
7693 RTE (RE_Get_Local_Address), Loc),
7694 Parameter_Associations => New_List (
7695 Make_Selected_Component (Loc,
7696 Prefix =>
7697 New_Occurrence_Of (
7698 Request_Parameter, Loc),
7699 Selector_Name =>
7700 Make_Identifier (Loc, Name_Target)),
7701 New_Occurrence_Of (Is_Local, Loc),
7702 New_Occurrence_Of (Addr, Loc))));
7704 Expr := Unchecked_Convert_To (RACW_Type,
7705 New_Occurrence_Of (Addr, Loc));
7706 end;
7708 elsif In_Present (Current_Parameter)
7709 or else not Out_Present (Current_Parameter)
7710 or else not Constrained
7711 then
7712 -- If an input parameter is constrained, then its reading is
7713 -- deferred until the beginning of the subprogram body. If
7714 -- it is unconstrained, then an expression is built for
7715 -- the object declaration and the variable is set using
7716 -- 'Input instead of 'Read.
7718 Expr := PolyORB_Support.Helpers.Build_From_Any_Call (
7719 Etyp, New_Occurrence_Of (Any, Loc), Decls);
7721 if Constrained then
7723 Append_To (Statements,
7724 Make_Assignment_Statement (Loc,
7725 Name =>
7726 New_Occurrence_Of (Object, Loc),
7727 Expression =>
7728 Expr));
7729 Expr := Empty;
7730 else
7731 null;
7732 -- Expr will be used to initialize (and constrain) the
7733 -- parameter when it is declared.
7734 end if;
7736 end if;
7738 -- If we do not have to output the current parameter, then
7739 -- it can well be flagged as constant. This may allow further
7740 -- optimizations done by the back end.
7742 Append_To (Decls,
7743 Make_Object_Declaration (Loc,
7744 Defining_Identifier => Object,
7745 Constant_Present => not Constrained
7746 and then not Out_Present (Current_Parameter),
7747 Object_Definition =>
7748 New_Occurrence_Of (Etyp, Loc),
7749 Expression => Expr));
7750 Set_Etype (Object, Etyp);
7752 -- An out parameter may be written back using a 'Write
7753 -- attribute instead of a 'Output because it has been
7754 -- constrained by the parameter given to the caller. Note that
7755 -- out controlling arguments in the case of a RACW are not put
7756 -- back in the stream because the pointer on them has not
7757 -- changed.
7759 if Out_Present (Current_Parameter)
7760 and then not Is_Controlling_Formal
7761 then
7762 Append_To (After_Statements,
7763 Make_Procedure_Call_Statement (Loc,
7764 Name =>
7765 New_Occurrence_Of (RTE (RE_Copy_Any_Value), Loc),
7766 Parameter_Associations => New_List (
7767 New_Occurrence_Of (Any, Loc),
7768 PolyORB_Support.Helpers.Build_To_Any_Call (
7769 New_Occurrence_Of (Object, Loc),
7770 Decls))));
7771 end if;
7773 -- For RACW controlling formals, the Etyp of Object is always
7774 -- an RACW, even if the parameter is not of an anonymous access
7775 -- type. In such case, we need to dereference it at call time.
7777 if Is_Controlling_Formal then
7778 if Nkind (Parameter_Type (Current_Parameter)) /=
7779 N_Access_Definition
7780 then
7781 Append_To (Parameter_List,
7782 Make_Parameter_Association (Loc,
7783 Selector_Name =>
7784 New_Occurrence_Of (
7785 Defining_Identifier (Current_Parameter), Loc),
7786 Explicit_Actual_Parameter =>
7787 Make_Explicit_Dereference (Loc,
7788 Unchecked_Convert_To (RACW_Type,
7789 OK_Convert_To (RTE (RE_Address),
7790 New_Occurrence_Of (Object, Loc))))));
7792 else
7793 Append_To (Parameter_List,
7794 Make_Parameter_Association (Loc,
7795 Selector_Name =>
7796 New_Occurrence_Of (
7797 Defining_Identifier (Current_Parameter), Loc),
7798 Explicit_Actual_Parameter =>
7799 Unchecked_Convert_To (RACW_Type,
7800 OK_Convert_To (RTE (RE_Address),
7801 New_Occurrence_Of (Object, Loc)))));
7802 end if;
7804 else
7805 Append_To (Parameter_List,
7806 Make_Parameter_Association (Loc,
7807 Selector_Name =>
7808 New_Occurrence_Of (
7809 Defining_Identifier (Current_Parameter), Loc),
7810 Explicit_Actual_Parameter =>
7811 New_Occurrence_Of (Object, Loc)));
7812 end if;
7814 -- If the current parameter needs an extra formal, then read it
7815 -- from the stream and set the corresponding semantic field in
7816 -- the variable. If the kind of the parameter identifier is
7817 -- E_Void, then this is a compiler generated parameter that
7818 -- doesn't need an extra constrained status.
7820 -- The case of Extra_Accessibility should also be handled ???
7822 if Nkind (Parameter_Type (Current_Parameter)) /=
7823 N_Access_Definition
7824 and then
7825 Ekind (Defining_Identifier (Current_Parameter)) /= E_Void
7826 and then
7827 Present (Extra_Constrained
7828 (Defining_Identifier (Current_Parameter)))
7829 then
7830 declare
7831 Extra_Parameter : constant Entity_Id :=
7832 Extra_Constrained
7833 (Defining_Identifier
7834 (Current_Parameter));
7835 Extra_Any : constant Entity_Id :=
7836 Make_Defining_Identifier
7837 (Loc, New_Internal_Name ('A'));
7838 Formal_Entity : constant Entity_Id :=
7839 Make_Defining_Identifier
7840 (Loc, Chars (Extra_Parameter));
7842 Formal_Type : constant Entity_Id :=
7843 Etype (Extra_Parameter);
7844 begin
7845 Append_To (Outer_Decls,
7846 Make_Object_Declaration (Loc,
7847 Defining_Identifier =>
7848 Extra_Any,
7849 Object_Definition =>
7850 New_Occurrence_Of (RTE (RE_Any), Loc)));
7852 Append_To (Outer_Statements,
7853 Add_Parameter_To_NVList (Loc,
7854 Parameter => Extra_Parameter,
7855 NVList => Arguments,
7856 Constrained => True,
7857 Any => Extra_Any));
7859 Append_To (Decls,
7860 Make_Object_Declaration (Loc,
7861 Defining_Identifier => Formal_Entity,
7862 Object_Definition =>
7863 New_Occurrence_Of (Formal_Type, Loc)));
7865 Append_To (Extra_Formal_Statements,
7866 Make_Assignment_Statement (Loc,
7867 Name =>
7868 New_Occurrence_Of (Extra_Parameter, Loc),
7869 Expression =>
7870 PolyORB_Support.Helpers.Build_From_Any_Call (
7871 Etype (Extra_Parameter),
7872 New_Occurrence_Of (Extra_Any, Loc),
7873 Decls)));
7874 Set_Extra_Constrained (Object, Formal_Entity);
7876 end;
7877 end if;
7878 end;
7880 Next (Current_Parameter);
7881 end loop;
7883 Append_To (Outer_Statements,
7884 Make_Procedure_Call_Statement (Loc,
7885 Name =>
7886 New_Occurrence_Of (RTE (RE_Request_Arguments), Loc),
7887 Parameter_Associations => New_List (
7888 New_Occurrence_Of (Request_Parameter, Loc),
7889 New_Occurrence_Of (Arguments, Loc))));
7891 Append_List_To (Statements, Extra_Formal_Statements);
7893 if Nkind (Specification (Vis_Decl)) = N_Function_Specification then
7895 -- The remote subprogram is a function. We build an inner block to
7896 -- be able to hold a potentially unconstrained result in a
7897 -- variable.
7899 declare
7900 Etyp : constant Entity_Id :=
7901 Etype (Result_Definition (Specification (Vis_Decl)));
7902 Result : constant Node_Id :=
7903 Make_Defining_Identifier (Loc,
7904 New_Internal_Name ('R'));
7905 begin
7906 Inner_Decls := New_List (
7907 Make_Object_Declaration (Loc,
7908 Defining_Identifier => Result,
7909 Constant_Present => True,
7910 Object_Definition => New_Occurrence_Of (Etyp, Loc),
7911 Expression =>
7912 Make_Function_Call (Loc,
7913 Name => Called_Subprogram,
7914 Parameter_Associations => Parameter_List)));
7916 Set_Etype (Result, Etyp);
7917 Append_To (After_Statements,
7918 Make_Procedure_Call_Statement (Loc,
7919 Name =>
7920 New_Occurrence_Of (RTE (RE_Set_Result), Loc),
7921 Parameter_Associations => New_List (
7922 New_Occurrence_Of (Request_Parameter, Loc),
7923 PolyORB_Support.Helpers.Build_To_Any_Call (
7924 New_Occurrence_Of (Result, Loc),
7925 Decls))));
7926 -- A DSA function does not have out or inout arguments
7927 end;
7929 Append_To (Statements,
7930 Make_Block_Statement (Loc,
7931 Declarations => Inner_Decls,
7932 Handled_Statement_Sequence =>
7933 Make_Handled_Sequence_Of_Statements (Loc,
7934 Statements => After_Statements)));
7936 else
7937 -- The remote subprogram is a procedure. We do not need any inner
7938 -- block in this case. No specific processing is required here for
7939 -- the dynamically asynchronous case: the indication of whether
7940 -- call is asynchronous or not is managed by the Sync_Scope
7941 -- attibute of the request, and is handled entirely in the
7942 -- protocol layer.
7944 Append_To (After_Statements,
7945 Make_Procedure_Call_Statement (Loc,
7946 Name =>
7947 New_Occurrence_Of (RTE (RE_Request_Set_Out), Loc),
7948 Parameter_Associations => New_List (
7949 New_Occurrence_Of (Request_Parameter, Loc))));
7951 Append_To (Statements,
7952 Make_Procedure_Call_Statement (Loc,
7953 Name => Called_Subprogram,
7954 Parameter_Associations => Parameter_List));
7956 Append_List_To (Statements, After_Statements);
7957 end if;
7959 Subp_Spec :=
7960 Make_Procedure_Specification (Loc,
7961 Defining_Unit_Name =>
7962 Make_Defining_Identifier (Loc, New_Internal_Name ('F')),
7964 Parameter_Specifications => New_List (
7965 Make_Parameter_Specification (Loc,
7966 Defining_Identifier => Request_Parameter,
7967 Parameter_Type =>
7968 New_Occurrence_Of (RTE (RE_Request_Access), Loc))));
7970 -- An exception raised during the execution of an incoming
7971 -- remote subprogram call and that needs to be sent back
7972 -- to the caller is propagated by the receiving stubs, and
7973 -- will be handled by the caller (the distribution runtime).
7975 if Asynchronous and then not Dynamically_Asynchronous then
7977 -- For an asynchronous procedure, add a null exception handler
7979 Excep_Handlers := New_List (
7980 Make_Exception_Handler (Loc,
7981 Exception_Choices => New_List (Make_Others_Choice (Loc)),
7982 Statements => New_List (Make_Null_Statement (Loc))));
7984 else
7986 -- In the other cases, if an exception is raised, then the
7987 -- exception occurrence is propagated.
7989 null;
7990 end if;
7992 Append_To (Outer_Statements,
7993 Make_Block_Statement (Loc,
7994 Declarations =>
7995 Decls,
7996 Handled_Statement_Sequence =>
7997 Make_Handled_Sequence_Of_Statements (Loc,
7998 Statements => Statements)));
8000 return
8001 Make_Subprogram_Body (Loc,
8002 Specification => Subp_Spec,
8003 Declarations => Outer_Decls,
8004 Handled_Statement_Sequence =>
8005 Make_Handled_Sequence_Of_Statements (Loc,
8006 Statements => Outer_Statements,
8007 Exception_Handlers => Excep_Handlers));
8008 end Build_Subprogram_Receiving_Stubs;
8009 -------------
8010 -- Helpers --
8011 -------------
8013 package body Helpers is
8015 -----------------------
8016 -- Local Subprograms --
8017 -----------------------
8019 function Find_Numeric_Representation
8020 (Typ : Entity_Id) return Entity_Id;
8021 -- Given a numeric type Typ, return the smallest integer or floarting
8022 -- point type from Standard, or the smallest unsigned (modular) type
8023 -- from System.Unsigned_Types, whose range encompasses that of Typ.
8025 function Make_Stream_Procedure_Function_Name
8026 (Loc : Source_Ptr;
8027 Typ : Entity_Id;
8028 Nam : Name_Id) return Entity_Id;
8029 -- Return the name to be assigned for stream subprogram Nam of Typ.
8030 -- (copied from exp_strm.adb, should be shared???)
8032 ------------------------------------------------------------
8033 -- Common subprograms for building various tree fragments --
8034 ------------------------------------------------------------
8036 function Build_Get_Aggregate_Element
8037 (Loc : Source_Ptr;
8038 Any : Entity_Id;
8039 TC : Node_Id;
8040 Idx : Node_Id) return Node_Id;
8041 -- Build a call to Get_Aggregate_Element on Any
8042 -- for typecode TC, returning the Idx'th element.
8044 generic
8045 Subprogram : Entity_Id;
8046 -- Reference location for constructed nodes
8048 Arry : Entity_Id;
8049 -- For 'Range and Etype
8051 Indices : List_Id;
8052 -- For the construction of the innermost element expression
8054 with procedure Add_Process_Element
8055 (Stmts : List_Id;
8056 Any : Entity_Id;
8057 Counter : Entity_Id;
8058 Datum : Node_Id);
8060 procedure Append_Array_Traversal
8061 (Stmts : List_Id;
8062 Any : Entity_Id;
8063 Counter : Entity_Id := Empty;
8064 Depth : Pos := 1);
8065 -- Build nested loop statements that iterate over the elements of an
8066 -- array Arry. The statement(s) built by Add_Process_Element are
8067 -- executed for each element; Indices is the list of indices to be
8068 -- used in the construction of the indexed component that denotes the
8069 -- current element. Subprogram is the entity for the subprogram for
8070 -- which this iterator is generated. The generated statements are
8071 -- appended to Stmts.
8073 generic
8074 Rec : Entity_Id;
8075 -- The record entity being dealt with
8077 with procedure Add_Process_Element
8078 (Stmts : List_Id;
8079 Container : Node_Or_Entity_Id;
8080 Counter : in out Int;
8081 Rec : Entity_Id;
8082 Field : Node_Id);
8083 -- Rec is the instance of the record type, or Empty.
8084 -- Field is either the N_Defining_Identifier for a component,
8085 -- or an N_Variant_Part.
8087 procedure Append_Record_Traversal
8088 (Stmts : List_Id;
8089 Clist : Node_Id;
8090 Container : Node_Or_Entity_Id;
8091 Counter : in out Int);
8092 -- Process component list Clist. Individual fields are passed
8093 -- to Field_Processing. Each variant part is also processed.
8094 -- Container is the outer Any (for From_Any/To_Any),
8095 -- the outer typecode (for TC) to which the operation applies.
8097 -----------------------------
8098 -- Append_Record_Traversal --
8099 -----------------------------
8101 procedure Append_Record_Traversal
8102 (Stmts : List_Id;
8103 Clist : Node_Id;
8104 Container : Node_Or_Entity_Id;
8105 Counter : in out Int)
8107 CI : constant List_Id := Component_Items (Clist);
8108 VP : constant Node_Id := Variant_Part (Clist);
8110 Item : Node_Id := First (CI);
8111 Def : Entity_Id;
8113 begin
8114 while Present (Item) loop
8115 Def := Defining_Identifier (Item);
8116 if not Is_Internal_Name (Chars (Def)) then
8117 Add_Process_Element
8118 (Stmts, Container, Counter, Rec, Def);
8119 end if;
8120 Next (Item);
8121 end loop;
8123 if Present (VP) then
8124 Add_Process_Element (Stmts, Container, Counter, Rec, VP);
8125 end if;
8126 end Append_Record_Traversal;
8128 -------------------------
8129 -- Build_From_Any_Call --
8130 -------------------------
8132 function Build_From_Any_Call
8133 (Typ : Entity_Id;
8134 N : Node_Id;
8135 Decls : List_Id) return Node_Id
8137 Loc : constant Source_Ptr := Sloc (N);
8139 U_Type : Entity_Id := Underlying_Type (Typ);
8141 Fnam : Entity_Id := Empty;
8142 Lib_RE : RE_Id := RE_Null;
8144 begin
8146 -- First simple case where the From_Any function is present
8147 -- in the type's TSS.
8149 Fnam := Find_Inherited_TSS (U_Type, TSS_From_Any);
8151 if Sloc (U_Type) <= Standard_Location then
8152 U_Type := Base_Type (U_Type);
8153 end if;
8155 -- Check first for Boolean and Character. These are enumeration
8156 -- types, but we treat them specially, since they may require
8157 -- special handling in the transfer protocol. However, this
8158 -- special handling only applies if they have standard
8159 -- representation, otherwise they are treated like any other
8160 -- enumeration type.
8162 if Present (Fnam) then
8163 null;
8165 elsif U_Type = Standard_Boolean then
8166 Lib_RE := RE_FA_B;
8168 elsif U_Type = Standard_Character then
8169 Lib_RE := RE_FA_C;
8171 elsif U_Type = Standard_Wide_Character then
8172 Lib_RE := RE_FA_WC;
8174 elsif U_Type = Standard_Wide_Wide_Character then
8175 Lib_RE := RE_FA_WWC;
8177 -- Floating point types
8179 elsif U_Type = Standard_Short_Float then
8180 Lib_RE := RE_FA_SF;
8182 elsif U_Type = Standard_Float then
8183 Lib_RE := RE_FA_F;
8185 elsif U_Type = Standard_Long_Float then
8186 Lib_RE := RE_FA_LF;
8188 elsif U_Type = Standard_Long_Long_Float then
8189 Lib_RE := RE_FA_LLF;
8191 -- Integer types
8193 elsif U_Type = Etype (Standard_Short_Short_Integer) then
8194 Lib_RE := RE_FA_SSI;
8196 elsif U_Type = Etype (Standard_Short_Integer) then
8197 Lib_RE := RE_FA_SI;
8199 elsif U_Type = Etype (Standard_Integer) then
8200 Lib_RE := RE_FA_I;
8202 elsif U_Type = Etype (Standard_Long_Integer) then
8203 Lib_RE := RE_FA_LI;
8205 elsif U_Type = Etype (Standard_Long_Long_Integer) then
8206 Lib_RE := RE_FA_LLI;
8208 -- Unsigned integer types
8210 elsif U_Type = RTE (RE_Short_Short_Unsigned) then
8211 Lib_RE := RE_FA_SSU;
8213 elsif U_Type = RTE (RE_Short_Unsigned) then
8214 Lib_RE := RE_FA_SU;
8216 elsif U_Type = RTE (RE_Unsigned) then
8217 Lib_RE := RE_FA_U;
8219 elsif U_Type = RTE (RE_Long_Unsigned) then
8220 Lib_RE := RE_FA_LU;
8222 elsif U_Type = RTE (RE_Long_Long_Unsigned) then
8223 Lib_RE := RE_FA_LLU;
8225 elsif U_Type = Standard_String then
8226 Lib_RE := RE_FA_String;
8228 -- Other (non-primitive) types
8230 else
8231 declare
8232 Decl : Entity_Id;
8233 begin
8234 Build_From_Any_Function (Loc, U_Type, Decl, Fnam);
8235 Append_To (Decls, Decl);
8236 end;
8237 end if;
8239 -- Call the function
8241 if Lib_RE /= RE_Null then
8242 pragma Assert (No (Fnam));
8243 Fnam := RTE (Lib_RE);
8244 end if;
8246 return
8247 Make_Function_Call (Loc,
8248 Name => New_Occurrence_Of (Fnam, Loc),
8249 Parameter_Associations => New_List (N));
8250 end Build_From_Any_Call;
8252 -----------------------------
8253 -- Build_From_Any_Function --
8254 -----------------------------
8256 procedure Build_From_Any_Function
8257 (Loc : Source_Ptr;
8258 Typ : Entity_Id;
8259 Decl : out Node_Id;
8260 Fnam : out Entity_Id)
8262 Spec : Node_Id;
8263 Decls : constant List_Id := New_List;
8264 Stms : constant List_Id := New_List;
8265 Any_Parameter : constant Entity_Id
8266 := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
8267 begin
8268 Fnam := Make_Stream_Procedure_Function_Name (Loc,
8269 Typ, Name_uFrom_Any);
8271 Spec :=
8272 Make_Function_Specification (Loc,
8273 Defining_Unit_Name => Fnam,
8274 Parameter_Specifications => New_List (
8275 Make_Parameter_Specification (Loc,
8276 Defining_Identifier =>
8277 Any_Parameter,
8278 Parameter_Type =>
8279 New_Occurrence_Of (RTE (RE_Any), Loc))),
8280 Result_Definition => New_Occurrence_Of (Typ, Loc));
8282 -- The following is taken care of by Exp_Dist.Add_RACW_From_Any
8284 pragma Assert
8285 (not (Is_Remote_Access_To_Class_Wide_Type (Typ)));
8287 if Is_Derived_Type (Typ)
8288 and then not Is_Tagged_Type (Typ)
8289 then
8290 Append_To (Stms,
8291 Make_Return_Statement (Loc,
8292 Expression =>
8293 OK_Convert_To (
8294 Typ,
8295 Build_From_Any_Call (
8296 Root_Type (Typ),
8297 New_Occurrence_Of (Any_Parameter, Loc),
8298 Decls))));
8300 elsif Is_Record_Type (Typ)
8301 and then not Is_Derived_Type (Typ)
8302 and then not Is_Tagged_Type (Typ)
8303 then
8304 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
8305 Append_To (Stms,
8306 Make_Return_Statement (Loc,
8307 Expression =>
8308 OK_Convert_To (
8309 Typ,
8310 Build_From_Any_Call (
8311 Etype (Typ),
8312 New_Occurrence_Of (Any_Parameter, Loc),
8313 Decls))));
8314 else
8315 declare
8316 Disc : Entity_Id := Empty;
8317 Discriminant_Associations : List_Id;
8318 Rdef : constant Node_Id :=
8319 Type_Definition (Declaration_Node (Typ));
8320 Component_Counter : Int := 0;
8322 -- The returned object
8324 Res : constant Entity_Id :=
8325 Make_Defining_Identifier (Loc,
8326 New_Internal_Name ('R'));
8328 Res_Definition : Node_Id := New_Occurrence_Of (Typ, Loc);
8330 procedure FA_Rec_Add_Process_Element
8331 (Stmts : List_Id;
8332 Any : Entity_Id;
8333 Counter : in out Int;
8334 Rec : Entity_Id;
8335 Field : Node_Id);
8337 procedure FA_Append_Record_Traversal is
8338 new Append_Record_Traversal
8339 (Rec => Res,
8340 Add_Process_Element => FA_Rec_Add_Process_Element);
8342 --------------------------------
8343 -- FA_Rec_Add_Process_Element --
8344 --------------------------------
8346 procedure FA_Rec_Add_Process_Element
8347 (Stmts : List_Id;
8348 Any : Entity_Id;
8349 Counter : in out Int;
8350 Rec : Entity_Id;
8351 Field : Node_Id)
8353 begin
8354 if Nkind (Field) = N_Defining_Identifier then
8356 -- A regular component
8358 Append_To (Stmts,
8359 Make_Assignment_Statement (Loc,
8360 Name => Make_Selected_Component (Loc,
8361 Prefix =>
8362 New_Occurrence_Of (Rec, Loc),
8363 Selector_Name =>
8364 New_Occurrence_Of (Field, Loc)),
8365 Expression =>
8366 Build_From_Any_Call (Etype (Field),
8367 Build_Get_Aggregate_Element (Loc,
8368 Any => Any,
8369 Tc => Build_TypeCode_Call (Loc,
8370 Etype (Field), Decls),
8371 Idx => Make_Integer_Literal (Loc,
8372 Counter)),
8373 Decls)));
8375 else
8376 -- A variant part
8378 declare
8379 Variant : Node_Id;
8380 Struct_Counter : Int := 0;
8382 Block_Decls : constant List_Id := New_List;
8383 Block_Stmts : constant List_Id := New_List;
8384 VP_Stmts : List_Id;
8386 Alt_List : constant List_Id := New_List;
8387 Choice_List : List_Id;
8389 Struct_Any : constant Entity_Id :=
8390 Make_Defining_Identifier (Loc,
8391 New_Internal_Name ('S'));
8393 begin
8394 Append_To (Decls,
8395 Make_Object_Declaration (Loc,
8396 Defining_Identifier =>
8397 Struct_Any,
8398 Constant_Present =>
8399 True,
8400 Object_Definition =>
8401 New_Occurrence_Of (RTE (RE_Any), Loc),
8402 Expression =>
8403 Make_Function_Call (Loc,
8404 Name => New_Occurrence_Of (
8405 RTE (RE_Extract_Union_Value), Loc),
8406 Parameter_Associations => New_List (
8407 Build_Get_Aggregate_Element (Loc,
8408 Any => Any,
8409 Tc => Make_Function_Call (Loc,
8410 Name => New_Occurrence_Of (
8411 RTE (RE_Any_Member_Type), Loc),
8412 Parameter_Associations =>
8413 New_List (
8414 New_Occurrence_Of (Any, Loc),
8415 Make_Integer_Literal (Loc,
8416 Counter))),
8417 Idx => Make_Integer_Literal (Loc,
8418 Counter))))));
8420 Append_To (Stmts,
8421 Make_Block_Statement (Loc,
8422 Declarations =>
8423 Block_Decls,
8424 Handled_Statement_Sequence =>
8425 Make_Handled_Sequence_Of_Statements (Loc,
8426 Statements => Block_Stmts)));
8428 Append_To (Block_Stmts,
8429 Make_Case_Statement (Loc,
8430 Expression =>
8431 Make_Selected_Component (Loc,
8432 Prefix => Rec,
8433 Selector_Name =>
8434 Chars (Name (Field))),
8435 Alternatives =>
8436 Alt_List));
8438 Variant := First_Non_Pragma (Variants (Field));
8440 while Present (Variant) loop
8441 Choice_List := New_Copy_List_Tree
8442 (Discrete_Choices (Variant));
8444 VP_Stmts := New_List;
8445 FA_Append_Record_Traversal (
8446 Stmts => VP_Stmts,
8447 Clist => Component_List (Variant),
8448 Container => Struct_Any,
8449 Counter => Struct_Counter);
8451 Append_To (Alt_List,
8452 Make_Case_Statement_Alternative (Loc,
8453 Discrete_Choices => Choice_List,
8454 Statements =>
8455 VP_Stmts));
8456 Next_Non_Pragma (Variant);
8457 end loop;
8458 end;
8459 end if;
8460 Counter := Counter + 1;
8461 end FA_Rec_Add_Process_Element;
8463 begin
8464 -- First all discriminants
8466 if Has_Discriminants (Typ) then
8467 Disc := First_Discriminant (Typ);
8468 Discriminant_Associations := New_List;
8470 while Present (Disc) loop
8471 declare
8472 Disc_Var_Name : constant Entity_Id :=
8473 Make_Defining_Identifier (Loc, Chars (Disc));
8474 Disc_Type : constant Entity_Id :=
8475 Etype (Disc);
8476 begin
8477 Append_To (Decls,
8478 Make_Object_Declaration (Loc,
8479 Defining_Identifier =>
8480 Disc_Var_Name,
8481 Constant_Present => True,
8482 Object_Definition =>
8483 New_Occurrence_Of (Disc_Type, Loc),
8484 Expression =>
8485 Build_From_Any_Call (Etype (Disc),
8486 Build_Get_Aggregate_Element (Loc,
8487 Any => Any_Parameter,
8488 Tc => Build_TypeCode_Call
8489 (Loc, Etype (Disc), Decls),
8490 Idx => Make_Integer_Literal
8491 (Loc, Component_Counter)),
8492 Decls)));
8493 Component_Counter := Component_Counter + 1;
8495 Append_To (Discriminant_Associations,
8496 Make_Discriminant_Association (Loc,
8497 Selector_Names => New_List (
8498 New_Occurrence_Of (Disc, Loc)),
8499 Expression =>
8500 New_Occurrence_Of (Disc_Var_Name, Loc)));
8501 end;
8502 Next_Discriminant (Disc);
8503 end loop;
8505 Res_Definition := Make_Subtype_Indication (Loc,
8506 Subtype_Mark => Res_Definition,
8507 Constraint =>
8508 Make_Index_Or_Discriminant_Constraint (Loc,
8509 Discriminant_Associations));
8510 end if;
8512 -- Now we have all the discriminants in variables, we can
8513 -- declared a constrained object. Note that we are not
8514 -- initializing (non-discriminant) components directly in
8515 -- the object declarations, because which fields to
8516 -- initialize depends (at run time) on the discriminant
8517 -- values.
8519 Append_To (Decls,
8520 Make_Object_Declaration (Loc,
8521 Defining_Identifier =>
8522 Res,
8523 Object_Definition =>
8524 Res_Definition));
8526 -- ... then all components
8528 FA_Append_Record_Traversal (Stms,
8529 Clist => Component_List (Rdef),
8530 Container => Any_Parameter,
8531 Counter => Component_Counter);
8533 Append_To (Stms,
8534 Make_Return_Statement (Loc,
8535 Expression => New_Occurrence_Of (Res, Loc)));
8536 end;
8537 end if;
8539 elsif Is_Array_Type (Typ) then
8540 declare
8541 Constrained : constant Boolean := Is_Constrained (Typ);
8543 procedure FA_Ary_Add_Process_Element
8544 (Stmts : List_Id;
8545 Any : Entity_Id;
8546 Counter : Entity_Id;
8547 Datum : Node_Id);
8548 -- Assign the current element (as identified by Counter) of
8549 -- Any to the variable denoted by name Datum, and advance
8550 -- Counter by 1. If Datum is not an Any, a call to From_Any
8551 -- for its type is inserted.
8553 --------------------------------
8554 -- FA_Ary_Add_Process_Element --
8555 --------------------------------
8557 procedure FA_Ary_Add_Process_Element
8558 (Stmts : List_Id;
8559 Any : Entity_Id;
8560 Counter : Entity_Id;
8561 Datum : Node_Id)
8563 Assignment : constant Node_Id :=
8564 Make_Assignment_Statement (Loc,
8565 Name => Datum,
8566 Expression => Empty);
8568 Element_Any : constant Node_Id :=
8569 Build_Get_Aggregate_Element (Loc,
8570 Any => Any,
8571 Tc => Build_TypeCode_Call (Loc,
8572 Etype (Datum), Decls),
8573 Idx => New_Occurrence_Of (Counter, Loc));
8575 begin
8576 -- Note: here we *prepend* statements to Stmts, so
8577 -- we must do it in reverse order.
8579 Prepend_To (Stmts,
8580 Make_Assignment_Statement (Loc,
8581 Name =>
8582 New_Occurrence_Of (Counter, Loc),
8583 Expression =>
8584 Make_Op_Add (Loc,
8585 Left_Opnd =>
8586 New_Occurrence_Of (Counter, Loc),
8587 Right_Opnd =>
8588 Make_Integer_Literal (Loc, 1))));
8590 if Nkind (Datum) /= N_Attribute_Reference then
8592 -- We ignore the value of the length of each
8593 -- dimension, since the target array has already
8594 -- been constrained anyway.
8596 if Etype (Datum) /= RTE (RE_Any) then
8597 Set_Expression (Assignment,
8598 Build_From_Any_Call (
8599 Component_Type (Typ),
8600 Element_Any,
8601 Decls));
8602 else
8603 Set_Expression (Assignment, Element_Any);
8604 end if;
8605 Prepend_To (Stmts, Assignment);
8606 end if;
8607 end FA_Ary_Add_Process_Element;
8609 Counter : constant Entity_Id :=
8610 Make_Defining_Identifier (Loc, Name_J);
8612 Initial_Counter_Value : Int := 0;
8614 Component_TC : constant Entity_Id :=
8615 Make_Defining_Identifier (Loc, Name_T);
8617 Res : constant Entity_Id :=
8618 Make_Defining_Identifier (Loc, Name_R);
8620 procedure Append_From_Any_Array_Iterator is
8621 new Append_Array_Traversal (
8622 Subprogram => Fnam,
8623 Arry => Res,
8624 Indices => New_List,
8625 Add_Process_Element => FA_Ary_Add_Process_Element);
8627 Res_Subtype_Indication : Node_Id :=
8628 New_Occurrence_Of (Typ, Loc);
8630 begin
8631 if not Constrained then
8632 declare
8633 Ndim : constant Int := Number_Dimensions (Typ);
8634 Lnam : Name_Id;
8635 Hnam : Name_Id;
8636 Indx : Node_Id := First_Index (Typ);
8637 Indt : Entity_Id;
8639 Ranges : constant List_Id := New_List;
8641 begin
8642 for J in 1 .. Ndim loop
8643 Lnam := New_External_Name ('L', J);
8644 Hnam := New_External_Name ('H', J);
8645 Indt := Etype (Indx);
8647 Append_To (Decls,
8648 Make_Object_Declaration (Loc,
8649 Defining_Identifier =>
8650 Make_Defining_Identifier (Loc, Lnam),
8651 Constant_Present =>
8652 True,
8653 Object_Definition =>
8654 New_Occurrence_Of (Indt, Loc),
8655 Expression =>
8656 Build_From_Any_Call (
8657 Indt,
8658 Build_Get_Aggregate_Element (Loc,
8659 Any => Any_Parameter,
8660 Tc => Build_TypeCode_Call (Loc,
8661 Indt, Decls),
8662 Idx => Make_Integer_Literal (Loc, J - 1)),
8663 Decls)));
8665 Append_To (Decls,
8666 Make_Object_Declaration (Loc,
8667 Defining_Identifier =>
8668 Make_Defining_Identifier (Loc, Hnam),
8669 Constant_Present =>
8670 True,
8671 Object_Definition =>
8672 New_Occurrence_Of (Indt, Loc),
8673 Expression => Make_Attribute_Reference (Loc,
8674 Prefix =>
8675 New_Occurrence_Of (Indt, Loc),
8676 Attribute_Name => Name_Val,
8677 Expressions => New_List (
8678 Make_Op_Subtract (Loc,
8679 Left_Opnd =>
8680 Make_Op_Add (Loc,
8681 Left_Opnd =>
8682 Make_Attribute_Reference (Loc,
8683 Prefix =>
8684 New_Occurrence_Of (Indt, Loc),
8685 Attribute_Name =>
8686 Name_Pos,
8687 Expressions => New_List (
8688 Make_Identifier (Loc, Lnam))),
8689 Right_Opnd =>
8690 Make_Function_Call (Loc,
8691 Name => New_Occurrence_Of (RTE (
8692 RE_Get_Nested_Sequence_Length),
8693 Loc),
8694 Parameter_Associations =>
8695 New_List (
8696 New_Occurrence_Of (
8697 Any_Parameter, Loc),
8698 Make_Integer_Literal (Loc,
8699 J)))),
8700 Right_Opnd =>
8701 Make_Integer_Literal (Loc, 1))))));
8703 Append_To (Ranges,
8704 Make_Range (Loc,
8705 Low_Bound => Make_Identifier (Loc, Lnam),
8706 High_Bound => Make_Identifier (Loc, Hnam)));
8708 Next_Index (Indx);
8709 end loop;
8711 -- Now we have all the necessary bound information:
8712 -- apply the set of range constraints to the
8713 -- (unconstrained) nominal subtype of Res.
8715 Initial_Counter_Value := Ndim;
8716 Res_Subtype_Indication := Make_Subtype_Indication (Loc,
8717 Subtype_Mark =>
8718 Res_Subtype_Indication,
8719 Constraint =>
8720 Make_Index_Or_Discriminant_Constraint (Loc,
8721 Constraints => Ranges));
8722 end;
8723 end if;
8725 Append_To (Decls,
8726 Make_Object_Declaration (Loc,
8727 Defining_Identifier => Res,
8728 Object_Definition => Res_Subtype_Indication));
8729 Set_Etype (Res, Typ);
8731 Append_To (Decls,
8732 Make_Object_Declaration (Loc,
8733 Defining_Identifier => Counter,
8734 Object_Definition =>
8735 New_Occurrence_Of (RTE (RE_Long_Unsigned), Loc),
8736 Expression =>
8737 Make_Integer_Literal (Loc, Initial_Counter_Value)));
8739 Append_To (Decls,
8740 Make_Object_Declaration (Loc,
8741 Defining_Identifier => Component_TC,
8742 Constant_Present => True,
8743 Object_Definition =>
8744 New_Occurrence_Of (RTE (RE_TypeCode), Loc),
8745 Expression =>
8746 Build_TypeCode_Call (Loc,
8747 Component_Type (Typ), Decls)));
8749 Append_From_Any_Array_Iterator (Stms,
8750 Any_Parameter, Counter);
8752 Append_To (Stms,
8753 Make_Return_Statement (Loc,
8754 Expression => New_Occurrence_Of (Res, Loc)));
8755 end;
8757 elsif Is_Integer_Type (Typ) or else Is_Unsigned_Type (Typ) then
8758 Append_To (Stms,
8759 Make_Return_Statement (Loc,
8760 Expression =>
8761 Unchecked_Convert_To (
8762 Typ,
8763 Build_From_Any_Call (
8764 Find_Numeric_Representation (Typ),
8765 New_Occurrence_Of (Any_Parameter, Loc),
8766 Decls))));
8768 else
8769 -- Default: type is represented as an opaque sequence of bytes
8771 declare
8772 Strm : constant Entity_Id :=
8773 Make_Defining_Identifier (Loc,
8774 Chars => New_Internal_Name ('S'));
8775 Res : constant Entity_Id :=
8776 Make_Defining_Identifier (Loc,
8777 Chars => New_Internal_Name ('R'));
8779 begin
8780 -- Strm : Buffer_Stream_Type;
8782 Append_To (Decls,
8783 Make_Object_Declaration (Loc,
8784 Defining_Identifier =>
8785 Strm,
8786 Aliased_Present =>
8787 True,
8788 Object_Definition =>
8789 New_Occurrence_Of (RTE (RE_Buffer_Stream_Type), Loc)));
8791 -- Allocate_Buffer (Strm);
8793 Append_To (Stms,
8794 Make_Procedure_Call_Statement (Loc,
8795 Name =>
8796 New_Occurrence_Of (RTE (RE_Allocate_Buffer), Loc),
8797 Parameter_Associations => New_List (
8798 New_Occurrence_Of (Strm, Loc))));
8800 -- Any_To_BS (Strm, A);
8802 Append_To (Stms,
8803 Make_Procedure_Call_Statement (Loc,
8804 Name =>
8805 New_Occurrence_Of (RTE (RE_Any_To_BS), Loc),
8806 Parameter_Associations => New_List (
8807 New_Occurrence_Of (Any_Parameter, Loc),
8808 New_Occurrence_Of (Strm, Loc))));
8810 -- declare
8811 -- Res : constant T := T'Input (Strm);
8812 -- begin
8813 -- Release_Buffer (Strm);
8814 -- return Res;
8815 -- end;
8817 Append_To (Stms, Make_Block_Statement (Loc,
8818 Declarations => New_List (
8819 Make_Object_Declaration (Loc,
8820 Defining_Identifier => Res,
8821 Constant_Present => True,
8822 Object_Definition =>
8823 New_Occurrence_Of (Typ, Loc),
8824 Expression =>
8825 Make_Attribute_Reference (Loc,
8826 Prefix => New_Occurrence_Of (Typ, Loc),
8827 Attribute_Name => Name_Input,
8828 Expressions => New_List (
8829 Make_Attribute_Reference (Loc,
8830 Prefix => New_Occurrence_Of (Strm, Loc),
8831 Attribute_Name => Name_Access))))),
8833 Handled_Statement_Sequence =>
8834 Make_Handled_Sequence_Of_Statements (Loc,
8835 Statements => New_List (
8836 Make_Procedure_Call_Statement (Loc,
8837 Name =>
8838 New_Occurrence_Of (RTE (RE_Release_Buffer), Loc),
8839 Parameter_Associations =>
8840 New_List (
8841 New_Occurrence_Of (Strm, Loc))),
8842 Make_Return_Statement (Loc,
8843 Expression => New_Occurrence_Of (Res, Loc))))));
8845 end;
8846 end if;
8848 Decl :=
8849 Make_Subprogram_Body (Loc,
8850 Specification => Spec,
8851 Declarations => Decls,
8852 Handled_Statement_Sequence =>
8853 Make_Handled_Sequence_Of_Statements (Loc,
8854 Statements => Stms));
8855 end Build_From_Any_Function;
8857 ---------------------------------
8858 -- Build_Get_Aggregate_Element --
8859 ---------------------------------
8861 function Build_Get_Aggregate_Element
8862 (Loc : Source_Ptr;
8863 Any : Entity_Id;
8864 TC : Node_Id;
8865 Idx : Node_Id) return Node_Id
8867 begin
8868 return Make_Function_Call (Loc,
8869 Name =>
8870 New_Occurrence_Of (
8871 RTE (RE_Get_Aggregate_Element), Loc),
8872 Parameter_Associations => New_List (
8873 New_Occurrence_Of (Any, Loc),
8875 Idx));
8876 end Build_Get_Aggregate_Element;
8878 -------------------------
8879 -- Build_Reposiroty_Id --
8880 -------------------------
8882 procedure Build_Name_And_Repository_Id
8883 (E : Entity_Id;
8884 Name_Str : out String_Id;
8885 Repo_Id_Str : out String_Id)
8887 begin
8888 Start_String;
8889 Store_String_Chars ("DSA:");
8890 Get_Library_Unit_Name_String (Scope (E));
8891 Store_String_Chars (
8892 Name_Buffer (Name_Buffer'First
8893 .. Name_Buffer'First + Name_Len - 1));
8894 Store_String_Char ('.');
8895 Get_Name_String (Chars (E));
8896 Store_String_Chars (
8897 Name_Buffer (Name_Buffer'First
8898 .. Name_Buffer'First + Name_Len - 1));
8899 Store_String_Chars (":1.0");
8900 Repo_Id_Str := End_String;
8901 Name_Str := String_From_Name_Buffer;
8902 end Build_Name_And_Repository_Id;
8904 -----------------------
8905 -- Build_To_Any_Call --
8906 -----------------------
8908 function Build_To_Any_Call
8909 (N : Node_Id;
8910 Decls : List_Id) return Node_Id
8912 Loc : constant Source_Ptr := Sloc (N);
8914 Typ : Entity_Id := Etype (N);
8915 U_Type : Entity_Id;
8917 Fnam : Entity_Id := Empty;
8918 Lib_RE : RE_Id := RE_Null;
8920 begin
8921 -- If N is a selected component, then maybe its Etype
8922 -- has not been set yet: try to use the Etype of the
8923 -- selector_name in that case.
8925 if No (Typ) and then Nkind (N) = N_Selected_Component then
8926 Typ := Etype (Selector_Name (N));
8927 end if;
8928 pragma Assert (Present (Typ));
8930 -- The full view, if Typ is private; the completion,
8931 -- if Typ is incomplete.
8933 U_Type := Underlying_Type (Typ);
8935 -- First simple case where the To_Any function is present
8936 -- in the type's TSS.
8938 Fnam := Find_Inherited_TSS (U_Type, TSS_To_Any);
8940 -- Check first for Boolean and Character. These are enumeration
8941 -- types, but we treat them specially, since they may require
8942 -- special handling in the transfer protocol. However, this
8943 -- special handling only applies if they have standard
8944 -- representation, otherwise they are treated like any other
8945 -- enumeration type.
8947 if Sloc (U_Type) <= Standard_Location then
8948 U_Type := Base_Type (U_Type);
8949 end if;
8951 if Present (Fnam) then
8952 null;
8954 elsif U_Type = Standard_Boolean then
8955 Lib_RE := RE_TA_B;
8957 elsif U_Type = Standard_Character then
8958 Lib_RE := RE_TA_C;
8960 elsif U_Type = Standard_Wide_Character then
8961 Lib_RE := RE_TA_WC;
8963 elsif U_Type = Standard_Wide_Wide_Character then
8964 Lib_RE := RE_TA_WWC;
8966 -- Floating point types
8968 elsif U_Type = Standard_Short_Float then
8969 Lib_RE := RE_TA_SF;
8971 elsif U_Type = Standard_Float then
8972 Lib_RE := RE_TA_F;
8974 elsif U_Type = Standard_Long_Float then
8975 Lib_RE := RE_TA_LF;
8977 elsif U_Type = Standard_Long_Long_Float then
8978 Lib_RE := RE_TA_LLF;
8980 -- Integer types
8982 elsif U_Type = Etype (Standard_Short_Short_Integer) then
8983 Lib_RE := RE_TA_SSI;
8985 elsif U_Type = Etype (Standard_Short_Integer) then
8986 Lib_RE := RE_TA_SI;
8988 elsif U_Type = Etype (Standard_Integer) then
8989 Lib_RE := RE_TA_I;
8991 elsif U_Type = Etype (Standard_Long_Integer) then
8992 Lib_RE := RE_TA_LI;
8994 elsif U_Type = Etype (Standard_Long_Long_Integer) then
8995 Lib_RE := RE_TA_LLI;
8997 -- Unsigned integer types
8999 elsif U_Type = RTE (RE_Short_Short_Unsigned) then
9000 Lib_RE := RE_TA_SSU;
9002 elsif U_Type = RTE (RE_Short_Unsigned) then
9003 Lib_RE := RE_TA_SU;
9005 elsif U_Type = RTE (RE_Unsigned) then
9006 Lib_RE := RE_TA_U;
9008 elsif U_Type = RTE (RE_Long_Unsigned) then
9009 Lib_RE := RE_TA_LU;
9011 elsif U_Type = RTE (RE_Long_Long_Unsigned) then
9012 Lib_RE := RE_TA_LLU;
9014 elsif U_Type = Standard_String then
9015 Lib_RE := RE_TA_String;
9017 elsif U_Type = Underlying_Type (RTE (RE_TypeCode)) then
9018 Lib_RE := RE_TA_TC;
9020 -- Other (non-primitive) types
9022 else
9023 declare
9024 Decl : Entity_Id;
9025 begin
9026 Build_To_Any_Function (Loc, U_Type, Decl, Fnam);
9027 Append_To (Decls, Decl);
9028 end;
9029 end if;
9031 -- Call the function
9033 if Lib_RE /= RE_Null then
9034 pragma Assert (No (Fnam));
9035 Fnam := RTE (Lib_RE);
9036 end if;
9038 return
9039 Make_Function_Call (Loc,
9040 Name => New_Occurrence_Of (Fnam, Loc),
9041 Parameter_Associations => New_List (N));
9042 end Build_To_Any_Call;
9044 ---------------------------
9045 -- Build_To_Any_Function --
9046 ---------------------------
9048 procedure Build_To_Any_Function
9049 (Loc : Source_Ptr;
9050 Typ : Entity_Id;
9051 Decl : out Node_Id;
9052 Fnam : out Entity_Id)
9054 Spec : Node_Id;
9055 Decls : constant List_Id := New_List;
9056 Stms : constant List_Id := New_List;
9058 Expr_Parameter : constant Entity_Id :=
9059 Make_Defining_Identifier (Loc, Name_E);
9061 Any : constant Entity_Id :=
9062 Make_Defining_Identifier (Loc, Name_A);
9064 Any_Decl : Node_Id;
9065 Result_TC : Node_Id := Build_TypeCode_Call (Loc, Typ, Decls);
9067 begin
9068 Fnam := Make_Stream_Procedure_Function_Name (Loc,
9069 Typ, Name_uTo_Any);
9071 Spec :=
9072 Make_Function_Specification (Loc,
9073 Defining_Unit_Name => Fnam,
9074 Parameter_Specifications => New_List (
9075 Make_Parameter_Specification (Loc,
9076 Defining_Identifier =>
9077 Expr_Parameter,
9078 Parameter_Type =>
9079 New_Occurrence_Of (Typ, Loc))),
9080 Result_Definition => New_Occurrence_Of (RTE (RE_Any), Loc));
9081 Set_Etype (Expr_Parameter, Typ);
9083 Any_Decl :=
9084 Make_Object_Declaration (Loc,
9085 Defining_Identifier =>
9086 Any,
9087 Object_Definition =>
9088 New_Occurrence_Of (RTE (RE_Any), Loc));
9090 if Is_Derived_Type (Typ) and then not Is_Tagged_Type (Typ) then
9091 declare
9092 Rt_Type : constant Entity_Id
9093 := Root_Type (Typ);
9094 Expr : constant Node_Id
9095 := OK_Convert_To (
9096 Rt_Type,
9097 New_Occurrence_Of (Expr_Parameter, Loc));
9098 begin
9099 Set_Expression (Any_Decl, Build_To_Any_Call (Expr, Decls));
9100 end;
9102 elsif Is_Record_Type (Typ) and then not Is_Tagged_Type (Typ) then
9103 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
9104 declare
9105 Rt_Type : constant Entity_Id
9106 := Etype (Typ);
9107 Expr : constant Node_Id
9108 := OK_Convert_To (
9109 Rt_Type,
9110 New_Occurrence_Of (Expr_Parameter, Loc));
9112 begin
9113 Set_Expression (Any_Decl,
9114 Build_To_Any_Call (Expr, Decls));
9115 end;
9117 else
9118 declare
9119 Disc : Entity_Id := Empty;
9120 Rdef : constant Node_Id :=
9121 Type_Definition (Declaration_Node (Typ));
9122 Counter : Int := 0;
9123 Elements : constant List_Id := New_List;
9125 procedure TA_Rec_Add_Process_Element
9126 (Stmts : List_Id;
9127 Container : Node_Or_Entity_Id;
9128 Counter : in out Int;
9129 Rec : Entity_Id;
9130 Field : Node_Id);
9132 procedure TA_Append_Record_Traversal is
9133 new Append_Record_Traversal
9134 (Rec => Expr_Parameter,
9135 Add_Process_Element => TA_Rec_Add_Process_Element);
9137 --------------------------------
9138 -- TA_Rec_Add_Process_Element --
9139 --------------------------------
9141 procedure TA_Rec_Add_Process_Element
9142 (Stmts : List_Id;
9143 Container : Node_Or_Entity_Id;
9144 Counter : in out Int;
9145 Rec : Entity_Id;
9146 Field : Node_Id)
9148 Field_Ref : Node_Id;
9150 begin
9151 if Nkind (Field) = N_Defining_Identifier then
9153 -- A regular component
9155 Field_Ref := Make_Selected_Component (Loc,
9156 Prefix => New_Occurrence_Of (Rec, Loc),
9157 Selector_Name => New_Occurrence_Of (Field, Loc));
9158 Set_Etype (Field_Ref, Etype (Field));
9160 Append_To (Stmts,
9161 Make_Procedure_Call_Statement (Loc,
9162 Name =>
9163 New_Occurrence_Of (
9164 RTE (RE_Add_Aggregate_Element), Loc),
9165 Parameter_Associations => New_List (
9166 New_Occurrence_Of (Any, Loc),
9167 Build_To_Any_Call (Field_Ref, Decls))));
9169 else
9170 -- A variant part
9172 declare
9173 Variant : Node_Id;
9174 Struct_Counter : Int := 0;
9176 Block_Decls : constant List_Id := New_List;
9177 Block_Stmts : constant List_Id := New_List;
9178 VP_Stmts : List_Id;
9180 Alt_List : constant List_Id := New_List;
9181 Choice_List : List_Id;
9183 Union_Any : constant Entity_Id :=
9184 Make_Defining_Identifier (Loc,
9185 New_Internal_Name ('U'));
9187 Struct_Any : constant Entity_Id :=
9188 Make_Defining_Identifier (Loc,
9189 New_Internal_Name ('S'));
9191 function Make_Discriminant_Reference
9192 return Node_Id;
9193 -- Build a selected component for the
9194 -- discriminant of this variant part.
9196 ---------------------------------
9197 -- Make_Discriminant_Reference --
9198 ---------------------------------
9200 function Make_Discriminant_Reference
9201 return Node_Id
9203 Nod : constant Node_Id :=
9204 Make_Selected_Component (Loc,
9205 Prefix => Rec,
9206 Selector_Name =>
9207 Chars (Name (Field)));
9208 begin
9209 Set_Etype (Nod, Name (Field));
9210 return Nod;
9211 end Make_Discriminant_Reference;
9213 begin
9214 Append_To (Stmts,
9215 Make_Block_Statement (Loc,
9216 Declarations =>
9217 Block_Decls,
9218 Handled_Statement_Sequence =>
9219 Make_Handled_Sequence_Of_Statements (Loc,
9220 Statements => Block_Stmts)));
9222 Append_To (Block_Decls,
9223 Make_Object_Declaration (Loc,
9224 Defining_Identifier => Union_Any,
9225 Object_Definition =>
9226 New_Occurrence_Of (RTE (RE_Any), Loc),
9227 Expression =>
9228 Make_Function_Call (Loc,
9229 Name => New_Occurrence_Of (
9230 RTE (RE_Create_Any), Loc),
9231 Parameter_Associations => New_List (
9232 Make_Function_Call (Loc,
9233 Name =>
9234 New_Occurrence_Of (
9235 RTE (RE_Any_Member_Type), Loc),
9236 Parameter_Associations => New_List (
9237 New_Occurrence_Of (Container, Loc),
9238 Make_Integer_Literal (Loc,
9239 Counter)))))));
9241 Append_To (Block_Decls,
9242 Make_Object_Declaration (Loc,
9243 Defining_Identifier => Struct_Any,
9244 Object_Definition =>
9245 New_Occurrence_Of (RTE (RE_Any), Loc),
9246 Expression =>
9247 Make_Function_Call (Loc,
9248 Name => New_Occurrence_Of (
9249 RTE (RE_Create_Any), Loc),
9250 Parameter_Associations => New_List (
9251 Make_Function_Call (Loc,
9252 Name =>
9253 New_Occurrence_Of (
9254 RTE (RE_Any_Member_Type), Loc),
9255 Parameter_Associations => New_List (
9256 New_Occurrence_Of (Union_Any, Loc),
9257 Make_Integer_Literal (Loc,
9258 Uint_0)))))));
9260 Append_To (Block_Stmts,
9261 Make_Case_Statement (Loc,
9262 Expression =>
9263 Make_Discriminant_Reference,
9264 Alternatives =>
9265 Alt_List));
9267 Variant := First_Non_Pragma (Variants (Field));
9268 while Present (Variant) loop
9269 Choice_List := New_Copy_List_Tree
9270 (Discrete_Choices (Variant));
9272 VP_Stmts := New_List;
9273 TA_Append_Record_Traversal (
9274 Stmts => VP_Stmts,
9275 Clist => Component_List (Variant),
9276 Container => Struct_Any,
9277 Counter => Struct_Counter);
9279 -- Append discriminant value and inner struct
9280 -- to union aggregate.
9282 Append_To (VP_Stmts,
9283 Make_Procedure_Call_Statement (Loc,
9284 Name =>
9285 New_Occurrence_Of (
9286 RTE (RE_Add_Aggregate_Element), Loc),
9287 Parameter_Associations => New_List (
9288 New_Occurrence_Of (Union_Any, Loc),
9289 Build_To_Any_Call (
9290 Make_Discriminant_Reference,
9291 Block_Decls))));
9293 Append_To (VP_Stmts,
9294 Make_Procedure_Call_Statement (Loc,
9295 Name =>
9296 New_Occurrence_Of (
9297 RTE (RE_Add_Aggregate_Element), Loc),
9298 Parameter_Associations => New_List (
9299 New_Occurrence_Of (Union_Any, Loc),
9300 New_Occurrence_Of (Struct_Any, Loc))));
9302 -- Append union to outer aggregate
9304 Append_To (VP_Stmts,
9305 Make_Procedure_Call_Statement (Loc,
9306 Name =>
9307 New_Occurrence_Of (
9308 RTE (RE_Add_Aggregate_Element), Loc),
9309 Parameter_Associations => New_List (
9310 New_Occurrence_Of (Container, Loc),
9311 Make_Function_Call (Loc,
9312 Name => New_Occurrence_Of (
9313 RTE (RE_Any_Aggregate_Build), Loc),
9314 Parameter_Associations => New_List (
9315 New_Occurrence_Of (
9316 Union_Any, Loc))))));
9318 Append_To (Alt_List,
9319 Make_Case_Statement_Alternative (Loc,
9320 Discrete_Choices => Choice_List,
9321 Statements =>
9322 VP_Stmts));
9323 Next_Non_Pragma (Variant);
9324 end loop;
9325 end;
9326 end if;
9327 end TA_Rec_Add_Process_Element;
9329 begin
9330 -- First all discriminants
9332 if Has_Discriminants (Typ) then
9333 Disc := First_Discriminant (Typ);
9335 while Present (Disc) loop
9336 Append_To (Elements,
9337 Make_Component_Association (Loc,
9338 Choices => New_List (
9339 Make_Integer_Literal (Loc, Counter)),
9340 Expression =>
9341 Build_To_Any_Call (
9342 Make_Selected_Component (Loc,
9343 Prefix => Expr_Parameter,
9344 Selector_Name => Chars (Disc)),
9345 Decls)));
9346 Counter := Counter + 1;
9347 Next_Discriminant (Disc);
9348 end loop;
9350 else
9351 -- Make elements an empty array
9353 declare
9354 Dummy_Any : constant Entity_Id :=
9355 Make_Defining_Identifier (Loc,
9356 Chars => New_Internal_Name ('A'));
9358 begin
9359 Append_To (Decls,
9360 Make_Object_Declaration (Loc,
9361 Defining_Identifier => Dummy_Any,
9362 Object_Definition =>
9363 New_Occurrence_Of (RTE (RE_Any), Loc)));
9365 Append_To (Elements,
9366 Make_Component_Association (Loc,
9367 Choices => New_List (
9368 Make_Range (Loc,
9369 Low_Bound =>
9370 Make_Integer_Literal (Loc, 1),
9371 High_Bound =>
9372 Make_Integer_Literal (Loc, 0))),
9373 Expression =>
9374 New_Occurrence_Of (Dummy_Any, Loc)));
9375 end;
9376 end if;
9378 Set_Expression (Any_Decl,
9379 Make_Function_Call (Loc,
9380 Name => New_Occurrence_Of (
9381 RTE (RE_Any_Aggregate_Build), Loc),
9382 Parameter_Associations => New_List (
9383 Result_TC,
9384 Make_Aggregate (Loc,
9385 Component_Associations => Elements))));
9386 Result_TC := Empty;
9388 -- ... then all components
9390 TA_Append_Record_Traversal (Stms,
9391 Clist => Component_List (Rdef),
9392 Container => Any,
9393 Counter => Counter);
9394 end;
9395 end if;
9397 elsif Is_Array_Type (Typ) then
9398 declare
9399 Constrained : constant Boolean := Is_Constrained (Typ);
9401 procedure TA_Ary_Add_Process_Element
9402 (Stmts : List_Id;
9403 Any : Entity_Id;
9404 Counter : Entity_Id;
9405 Datum : Node_Id);
9407 --------------------------------
9408 -- TA_Ary_Add_Process_Element --
9409 --------------------------------
9411 procedure TA_Ary_Add_Process_Element
9412 (Stmts : List_Id;
9413 Any : Entity_Id;
9414 Counter : Entity_Id;
9415 Datum : Node_Id)
9417 pragma Warnings (Off);
9418 pragma Unreferenced (Counter);
9419 pragma Warnings (On);
9421 Element_Any : Node_Id;
9423 begin
9424 if Etype (Datum) = RTE (RE_Any) then
9425 Element_Any := Datum;
9426 else
9427 Element_Any := Build_To_Any_Call (Datum, Decls);
9428 end if;
9430 Append_To (Stmts,
9431 Make_Procedure_Call_Statement (Loc,
9432 Name => New_Occurrence_Of (
9433 RTE (RE_Add_Aggregate_Element), Loc),
9434 Parameter_Associations => New_List (
9435 New_Occurrence_Of (Any, Loc),
9436 Element_Any)));
9437 end TA_Ary_Add_Process_Element;
9439 procedure Append_To_Any_Array_Iterator is
9440 new Append_Array_Traversal (
9441 Subprogram => Fnam,
9442 Arry => Expr_Parameter,
9443 Indices => New_List,
9444 Add_Process_Element => TA_Ary_Add_Process_Element);
9446 Index : Node_Id;
9448 begin
9449 Set_Expression (Any_Decl,
9450 Make_Function_Call (Loc,
9451 Name =>
9452 New_Occurrence_Of (RTE (RE_Create_Any), Loc),
9453 Parameter_Associations => New_List (Result_TC)));
9454 Result_TC := Empty;
9456 if not Constrained then
9457 Index := First_Index (Typ);
9458 for J in 1 .. Number_Dimensions (Typ) loop
9459 Append_To (Stms,
9460 Make_Procedure_Call_Statement (Loc,
9461 Name =>
9462 New_Occurrence_Of (
9463 RTE (RE_Add_Aggregate_Element), Loc),
9464 Parameter_Associations => New_List (
9465 New_Occurrence_Of (Any, Loc),
9466 Build_To_Any_Call (
9467 OK_Convert_To (Etype (Index),
9468 Make_Attribute_Reference (Loc,
9469 Prefix =>
9470 New_Occurrence_Of (Expr_Parameter, Loc),
9471 Attribute_Name => Name_First,
9472 Expressions => New_List (
9473 Make_Integer_Literal (Loc, J)))),
9474 Decls))));
9475 Next_Index (Index);
9476 end loop;
9477 end if;
9479 Append_To_Any_Array_Iterator (Stms, Any);
9480 end;
9482 elsif Is_Integer_Type (Typ) or else Is_Unsigned_Type (Typ) then
9483 Set_Expression (Any_Decl,
9484 Build_To_Any_Call (
9485 OK_Convert_To (
9486 Find_Numeric_Representation (Typ),
9487 New_Occurrence_Of (Expr_Parameter, Loc)),
9488 Decls));
9490 else
9491 -- Default: type is represented as an opaque sequence of bytes
9493 declare
9494 Strm : constant Entity_Id := Make_Defining_Identifier (Loc,
9495 New_Internal_Name ('S'));
9497 begin
9498 -- Strm : aliased Buffer_Stream_Type;
9500 Append_To (Decls,
9501 Make_Object_Declaration (Loc,
9502 Defining_Identifier =>
9503 Strm,
9504 Aliased_Present =>
9505 True,
9506 Object_Definition =>
9507 New_Occurrence_Of (RTE (RE_Buffer_Stream_Type), Loc)));
9509 -- Allocate_Buffer (Strm);
9511 Append_To (Stms,
9512 Make_Procedure_Call_Statement (Loc,
9513 Name =>
9514 New_Occurrence_Of (RTE (RE_Allocate_Buffer), Loc),
9515 Parameter_Associations => New_List (
9516 New_Occurrence_Of (Strm, Loc))));
9518 -- T'Output (Strm'Access, E);
9520 Append_To (Stms,
9521 Make_Attribute_Reference (Loc,
9522 Prefix => New_Occurrence_Of (Typ, Loc),
9523 Attribute_Name => Name_Output,
9524 Expressions => New_List (
9525 Make_Attribute_Reference (Loc,
9526 Prefix => New_Occurrence_Of (Strm, Loc),
9527 Attribute_Name => Name_Access),
9528 New_Occurrence_Of (Expr_Parameter, Loc))));
9530 -- BS_To_Any (Strm, A);
9532 Append_To (Stms,
9533 Make_Procedure_Call_Statement (Loc,
9534 Name =>
9535 New_Occurrence_Of (RTE (RE_BS_To_Any), Loc),
9536 Parameter_Associations => New_List (
9537 New_Occurrence_Of (Strm, Loc),
9538 New_Occurrence_Of (Any, Loc))));
9540 -- Release_Buffer (Strm);
9542 Append_To (Stms,
9543 Make_Procedure_Call_Statement (Loc,
9544 Name =>
9545 New_Occurrence_Of (RTE (RE_Release_Buffer), Loc),
9546 Parameter_Associations => New_List (
9547 New_Occurrence_Of (Strm, Loc))));
9548 end;
9549 end if;
9551 Append_To (Decls, Any_Decl);
9553 if Present (Result_TC) then
9554 Append_To (Stms,
9555 Make_Procedure_Call_Statement (Loc,
9556 Name => New_Occurrence_Of (RTE (RE_Set_TC), Loc),
9557 Parameter_Associations => New_List (
9558 New_Occurrence_Of (Any, Loc),
9559 Result_TC)));
9560 end if;
9562 Append_To (Stms,
9563 Make_Return_Statement (Loc,
9564 Expression => New_Occurrence_Of (Any, Loc)));
9566 Decl :=
9567 Make_Subprogram_Body (Loc,
9568 Specification => Spec,
9569 Declarations => Decls,
9570 Handled_Statement_Sequence =>
9571 Make_Handled_Sequence_Of_Statements (Loc,
9572 Statements => Stms));
9573 end Build_To_Any_Function;
9575 -------------------------
9576 -- Build_TypeCode_Call --
9577 -------------------------
9579 function Build_TypeCode_Call
9580 (Loc : Source_Ptr;
9581 Typ : Entity_Id;
9582 Decls : List_Id) return Node_Id
9584 U_Type : Entity_Id := Underlying_Type (Typ);
9585 -- The full view, if Typ is private; the completion,
9586 -- if Typ is incomplete.
9588 Fnam : Entity_Id := Empty;
9589 Lib_RE : RE_Id := RE_Null;
9591 Expr : Node_Id;
9593 begin
9594 -- Special case System.PolyORB.Interface.Any: its primitives have
9595 -- not been set yet, so can't call Find_Inherited_TSS.
9597 if Typ = RTE (RE_Any) then
9598 Fnam := RTE (RE_TC_Any);
9600 else
9601 -- First simple case where the TypeCode is present
9602 -- in the type's TSS.
9604 Fnam := Find_Inherited_TSS (U_Type, TSS_TypeCode);
9605 end if;
9607 if No (Fnam) then
9608 if Sloc (U_Type) <= Standard_Location then
9610 -- Do not try to build alias typecodes for subtypes from
9611 -- Standard.
9613 U_Type := Base_Type (U_Type);
9614 end if;
9616 if U_Type = Standard_Boolean then
9617 Lib_RE := RE_TC_B;
9619 elsif U_Type = Standard_Character then
9620 Lib_RE := RE_TC_C;
9622 elsif U_Type = Standard_Wide_Character then
9623 Lib_RE := RE_TC_WC;
9625 elsif U_Type = Standard_Wide_Wide_Character then
9626 Lib_RE := RE_TC_WWC;
9628 -- Floating point types
9630 elsif U_Type = Standard_Short_Float then
9631 Lib_RE := RE_TC_SF;
9633 elsif U_Type = Standard_Float then
9634 Lib_RE := RE_TC_F;
9636 elsif U_Type = Standard_Long_Float then
9637 Lib_RE := RE_TC_LF;
9639 elsif U_Type = Standard_Long_Long_Float then
9640 Lib_RE := RE_TC_LLF;
9642 -- Integer types (walk back to the base type)
9644 elsif U_Type = Etype (Standard_Short_Short_Integer) then
9645 Lib_RE := RE_TC_SSI;
9647 elsif U_Type = Etype (Standard_Short_Integer) then
9648 Lib_RE := RE_TC_SI;
9650 elsif U_Type = Etype (Standard_Integer) then
9651 Lib_RE := RE_TC_I;
9653 elsif U_Type = Etype (Standard_Long_Integer) then
9654 Lib_RE := RE_TC_LI;
9656 elsif U_Type = Etype (Standard_Long_Long_Integer) then
9657 Lib_RE := RE_TC_LLI;
9659 -- Unsigned integer types
9661 elsif U_Type = RTE (RE_Short_Short_Unsigned) then
9662 Lib_RE := RE_TC_SSU;
9664 elsif U_Type = RTE (RE_Short_Unsigned) then
9665 Lib_RE := RE_TC_SU;
9667 elsif U_Type = RTE (RE_Unsigned) then
9668 Lib_RE := RE_TC_U;
9670 elsif U_Type = RTE (RE_Long_Unsigned) then
9671 Lib_RE := RE_TC_LU;
9673 elsif U_Type = RTE (RE_Long_Long_Unsigned) then
9674 Lib_RE := RE_TC_LLU;
9676 elsif U_Type = Standard_String then
9677 Lib_RE := RE_TC_String;
9679 -- Other (non-primitive) types
9681 else
9682 declare
9683 Decl : Entity_Id;
9684 begin
9685 Build_TypeCode_Function (Loc, U_Type, Decl, Fnam);
9686 Append_To (Decls, Decl);
9687 end;
9688 end if;
9690 if Lib_RE /= RE_Null then
9691 Fnam := RTE (Lib_RE);
9692 end if;
9693 end if;
9695 -- Call the function
9697 Expr :=
9698 Make_Function_Call (Loc, Name => New_Occurrence_Of (Fnam, Loc));
9700 -- Allow Expr to be used as arg to Build_To_Any_Call immediately
9702 Set_Etype (Expr, RTE (RE_TypeCode));
9704 return Expr;
9705 end Build_TypeCode_Call;
9707 -----------------------------
9708 -- Build_TypeCode_Function --
9709 -----------------------------
9711 procedure Build_TypeCode_Function
9712 (Loc : Source_Ptr;
9713 Typ : Entity_Id;
9714 Decl : out Node_Id;
9715 Fnam : out Entity_Id)
9717 Spec : Node_Id;
9718 Decls : constant List_Id := New_List;
9719 Stms : constant List_Id := New_List;
9721 TCNam : constant Entity_Id :=
9722 Make_Stream_Procedure_Function_Name (Loc,
9723 Typ, Name_uTypeCode);
9725 Parameters : List_Id;
9727 procedure Add_String_Parameter
9728 (S : String_Id;
9729 Parameter_List : List_Id);
9730 -- Add a literal for S to Parameters
9732 procedure Add_TypeCode_Parameter
9733 (TC_Node : Node_Id;
9734 Parameter_List : List_Id);
9735 -- Add the typecode for Typ to Parameters
9737 procedure Add_Long_Parameter
9738 (Expr_Node : Node_Id;
9739 Parameter_List : List_Id);
9740 -- Add a signed long integer expression to Parameters
9742 procedure Initialize_Parameter_List
9743 (Name_String : String_Id;
9744 Repo_Id_String : String_Id;
9745 Parameter_List : out List_Id);
9746 -- Return a list that contains the first two parameters
9747 -- for a parameterized typecode: name and repository id.
9749 function Make_Constructed_TypeCode
9750 (Kind : Entity_Id;
9751 Parameters : List_Id) return Node_Id;
9752 -- Call TC_Build with the given kind and parameters
9754 procedure Return_Constructed_TypeCode (Kind : Entity_Id);
9755 -- Make a return statement that calls TC_Build with the given
9756 -- typecode kind, and the constructed parameters list.
9758 procedure Return_Alias_TypeCode (Base_TypeCode : Node_Id);
9759 -- Return a typecode that is a TC_Alias for the given typecode
9761 --------------------------
9762 -- Add_String_Parameter --
9763 --------------------------
9765 procedure Add_String_Parameter
9766 (S : String_Id;
9767 Parameter_List : List_Id)
9769 begin
9770 Append_To (Parameter_List,
9771 Make_Function_Call (Loc,
9772 Name =>
9773 New_Occurrence_Of (RTE (RE_TA_String), Loc),
9774 Parameter_Associations => New_List (
9775 Make_String_Literal (Loc, S))));
9776 end Add_String_Parameter;
9778 ----------------------------
9779 -- Add_TypeCode_Parameter --
9780 ----------------------------
9782 procedure Add_TypeCode_Parameter
9783 (TC_Node : Node_Id;
9784 Parameter_List : List_Id)
9786 begin
9787 Append_To (Parameter_List,
9788 Make_Function_Call (Loc,
9789 Name =>
9790 New_Occurrence_Of (RTE (RE_TA_TC), Loc),
9791 Parameter_Associations => New_List (
9792 TC_Node)));
9793 end Add_TypeCode_Parameter;
9795 ------------------------
9796 -- Add_Long_Parameter --
9797 ------------------------
9799 procedure Add_Long_Parameter
9800 (Expr_Node : Node_Id;
9801 Parameter_List : List_Id)
9803 begin
9804 Append_To (Parameter_List,
9805 Make_Function_Call (Loc,
9806 Name =>
9807 New_Occurrence_Of (RTE (RE_TA_LI), Loc),
9808 Parameter_Associations => New_List (Expr_Node)));
9809 end Add_Long_Parameter;
9811 -------------------------------
9812 -- Initialize_Parameter_List --
9813 -------------------------------
9815 procedure Initialize_Parameter_List
9816 (Name_String : String_Id;
9817 Repo_Id_String : String_Id;
9818 Parameter_List : out List_Id)
9820 begin
9821 Parameter_List := New_List;
9822 Add_String_Parameter (Name_String, Parameter_List);
9823 Add_String_Parameter (Repo_Id_String, Parameter_List);
9824 end Initialize_Parameter_List;
9826 ---------------------------
9827 -- Return_Alias_TypeCode --
9828 ---------------------------
9830 procedure Return_Alias_TypeCode
9831 (Base_TypeCode : Node_Id)
9833 begin
9834 Add_TypeCode_Parameter (Base_TypeCode, Parameters);
9835 Return_Constructed_TypeCode (RTE (RE_TC_Alias));
9836 end Return_Alias_TypeCode;
9838 -------------------------------
9839 -- Make_Constructed_TypeCode --
9840 -------------------------------
9842 function Make_Constructed_TypeCode
9843 (Kind : Entity_Id;
9844 Parameters : List_Id) return Node_Id
9846 Constructed_TC : constant Node_Id :=
9847 Make_Function_Call (Loc,
9848 Name =>
9849 New_Occurrence_Of (RTE (RE_TC_Build), Loc),
9850 Parameter_Associations => New_List (
9851 New_Occurrence_Of (Kind, Loc),
9852 Make_Aggregate (Loc,
9853 Expressions => Parameters)));
9854 begin
9855 Set_Etype (Constructed_TC, RTE (RE_TypeCode));
9856 return Constructed_TC;
9857 end Make_Constructed_TypeCode;
9859 ---------------------------------
9860 -- Return_Constructed_TypeCode --
9861 ---------------------------------
9863 procedure Return_Constructed_TypeCode (Kind : Entity_Id) is
9864 begin
9865 Append_To (Stms,
9866 Make_Return_Statement (Loc,
9867 Expression =>
9868 Make_Constructed_TypeCode (Kind, Parameters)));
9869 end Return_Constructed_TypeCode;
9871 ------------------
9872 -- Record types --
9873 ------------------
9875 procedure TC_Rec_Add_Process_Element
9876 (Params : List_Id;
9877 Any : Entity_Id;
9878 Counter : in out Int;
9879 Rec : Entity_Id;
9880 Field : Node_Id);
9882 procedure TC_Append_Record_Traversal is
9883 new Append_Record_Traversal (
9884 Rec => Empty,
9885 Add_Process_Element => TC_Rec_Add_Process_Element);
9887 --------------------------------
9888 -- TC_Rec_Add_Process_Element --
9889 --------------------------------
9891 procedure TC_Rec_Add_Process_Element
9892 (Params : List_Id;
9893 Any : Entity_Id;
9894 Counter : in out Int;
9895 Rec : Entity_Id;
9896 Field : Node_Id)
9898 pragma Warnings (Off);
9899 pragma Unreferenced (Any, Counter, Rec);
9900 pragma Warnings (On);
9902 begin
9903 if Nkind (Field) = N_Defining_Identifier then
9905 -- A regular component
9907 Add_TypeCode_Parameter (
9908 Build_TypeCode_Call (Loc, Etype (Field), Decls), Params);
9909 Get_Name_String (Chars (Field));
9910 Add_String_Parameter (String_From_Name_Buffer, Params);
9912 else
9914 -- A variant part
9916 declare
9917 Discriminant_Type : constant Entity_Id :=
9918 Etype (Name (Field));
9920 Is_Enum : constant Boolean :=
9921 Is_Enumeration_Type (Discriminant_Type);
9923 Union_TC_Params : List_Id;
9925 U_Name : constant Name_Id :=
9926 New_External_Name (Chars (Typ), 'U', -1);
9928 Name_Str : String_Id;
9929 Struct_TC_Params : List_Id;
9931 Variant : Node_Id;
9932 Choice : Node_Id;
9933 Default : constant Node_Id :=
9934 Make_Integer_Literal (Loc, -1);
9936 Dummy_Counter : Int := 0;
9938 procedure Add_Params_For_Variant_Components;
9939 -- Add a struct TypeCode and a corresponding member name
9940 -- to the union parameter list.
9942 -- Ordering of declarations is a complete mess in this
9943 -- area, it is supposed to be types/varibles, then
9944 -- subprogram specs, then subprogram bodies ???
9946 ---------------------------------------
9947 -- Add_Params_For_Variant_Components --
9948 ---------------------------------------
9950 procedure Add_Params_For_Variant_Components
9952 S_Name : constant Name_Id :=
9953 New_External_Name (U_Name, 'S', -1);
9955 begin
9956 Get_Name_String (S_Name);
9957 Name_Str := String_From_Name_Buffer;
9958 Initialize_Parameter_List
9959 (Name_Str, Name_Str, Struct_TC_Params);
9961 -- Build struct parameters
9963 TC_Append_Record_Traversal (Struct_TC_Params,
9964 Component_List (Variant),
9965 Empty,
9966 Dummy_Counter);
9968 Add_TypeCode_Parameter
9969 (Make_Constructed_TypeCode
9970 (RTE (RE_TC_Struct), Struct_TC_Params),
9971 Union_TC_Params);
9973 Add_String_Parameter (Name_Str, Union_TC_Params);
9974 end Add_Params_For_Variant_Components;
9976 begin
9977 Get_Name_String (U_Name);
9978 Name_Str := String_From_Name_Buffer;
9980 Initialize_Parameter_List
9981 (Name_Str, Name_Str, Union_TC_Params);
9983 Add_String_Parameter (Name_Str, Params);
9985 -- Add union in enclosing parameter list
9987 Add_TypeCode_Parameter
9988 (Make_Constructed_TypeCode
9989 (RTE (RE_TC_Union), Union_TC_Params),
9990 Parameters);
9992 -- Build union parameters
9994 Add_TypeCode_Parameter
9995 (Discriminant_Type, Union_TC_Params);
9996 Add_Long_Parameter (Default, Union_TC_Params);
9998 Variant := First_Non_Pragma (Variants (Field));
9999 while Present (Variant) loop
10000 Choice := First (Discrete_Choices (Variant));
10001 while Present (Choice) loop
10002 case Nkind (Choice) is
10003 when N_Range =>
10004 declare
10005 L : constant Uint :=
10006 Expr_Value (Low_Bound (Choice));
10007 H : constant Uint :=
10008 Expr_Value (High_Bound (Choice));
10009 J : Uint := L;
10010 -- 3.8.1(8) guarantees that the bounds of
10011 -- this range are static.
10013 Expr : Node_Id;
10015 begin
10016 while J <= H loop
10017 if Is_Enum then
10018 Expr := New_Occurrence_Of (
10019 Get_Enum_Lit_From_Pos (
10020 Discriminant_Type, J, Loc), Loc);
10021 else
10022 Expr :=
10023 Make_Integer_Literal (Loc, J);
10024 end if;
10025 Append_To (Union_TC_Params,
10026 Build_To_Any_Call (Expr, Decls));
10027 Add_Params_For_Variant_Components;
10028 J := J + Uint_1;
10029 end loop;
10030 end;
10032 when N_Others_Choice =>
10033 Add_Long_Parameter (
10034 Make_Integer_Literal (Loc, 0),
10035 Union_TC_Params);
10036 Add_Params_For_Variant_Components;
10038 when others =>
10039 Append_To (Union_TC_Params,
10040 Build_To_Any_Call (Choice, Decls));
10041 Add_Params_For_Variant_Components;
10043 end case;
10045 end loop;
10047 Next_Non_Pragma (Variant);
10048 end loop;
10050 end;
10051 end if;
10052 end TC_Rec_Add_Process_Element;
10054 Type_Name_Str : String_Id;
10055 Type_Repo_Id_Str : String_Id;
10057 begin
10058 pragma Assert (not Is_Itype (Typ));
10059 Fnam := TCNam;
10061 Spec :=
10062 Make_Function_Specification (Loc,
10063 Defining_Unit_Name => Fnam,
10064 Parameter_Specifications => Empty_List,
10065 Result_Definition =>
10066 New_Occurrence_Of (RTE (RE_TypeCode), Loc));
10068 Build_Name_And_Repository_Id (Typ,
10069 Name_Str => Type_Name_Str, Repo_Id_Str => Type_Repo_Id_Str);
10070 Initialize_Parameter_List
10071 (Type_Name_Str, Type_Repo_Id_Str, Parameters);
10073 if Is_Derived_Type (Typ)
10074 and then not Is_Tagged_Type (Typ)
10075 then
10076 declare
10077 Parent_Type : Entity_Id := Etype (Typ);
10078 begin
10080 if Is_Itype (Parent_Type) then
10082 -- Skip implicit base type
10084 Parent_Type := Etype (Parent_Type);
10085 end if;
10087 Return_Alias_TypeCode (
10088 Build_TypeCode_Call (Loc, Parent_Type, Decls));
10089 end;
10091 elsif Is_Integer_Type (Typ)
10092 or else Is_Unsigned_Type (Typ)
10093 then
10094 Return_Alias_TypeCode (
10095 Build_TypeCode_Call (Loc,
10096 Find_Numeric_Representation (Typ), Decls));
10098 elsif Is_Record_Type (Typ)
10099 and then not Is_Tagged_Type (Typ)
10100 then
10101 if Nkind (Declaration_Node (Typ)) = N_Subtype_Declaration then
10102 Return_Alias_TypeCode (
10103 Build_TypeCode_Call (Loc, Etype (Typ), Decls));
10104 else
10105 declare
10106 Disc : Entity_Id := Empty;
10107 Rdef : constant Node_Id :=
10108 Type_Definition (Declaration_Node (Typ));
10109 Dummy_Counter : Int := 0;
10110 begin
10111 -- First all discriminants
10113 if Has_Discriminants (Typ) then
10114 Disc := First_Discriminant (Typ);
10115 end if;
10116 while Present (Disc) loop
10117 Add_TypeCode_Parameter (
10118 Build_TypeCode_Call (Loc, Etype (Disc), Decls),
10119 Parameters);
10120 Get_Name_String (Chars (Disc));
10121 Add_String_Parameter (
10122 String_From_Name_Buffer,
10123 Parameters);
10124 Next_Discriminant (Disc);
10125 end loop;
10127 -- ... then all components
10129 TC_Append_Record_Traversal
10130 (Parameters, Component_List (Rdef),
10131 Empty, Dummy_Counter);
10132 Return_Constructed_TypeCode (RTE (RE_TC_Struct));
10133 end;
10134 end if;
10136 elsif Is_Array_Type (Typ) then
10137 declare
10138 Ndim : constant Pos := Number_Dimensions (Typ);
10139 Inner_TypeCode : Node_Id;
10140 Constrained : constant Boolean := Is_Constrained (Typ);
10141 Indx : Node_Id := First_Index (Typ);
10143 begin
10144 Inner_TypeCode := Build_TypeCode_Call (Loc,
10145 Component_Type (Typ),
10146 Decls);
10148 for J in 1 .. Ndim loop
10149 if Constrained then
10150 Inner_TypeCode := Make_Constructed_TypeCode
10151 (RTE (RE_TC_Array), New_List (
10152 Build_To_Any_Call (
10153 OK_Convert_To (RTE (RE_Long_Unsigned),
10154 Make_Attribute_Reference (Loc,
10155 Prefix =>
10156 New_Occurrence_Of (Typ, Loc),
10157 Attribute_Name =>
10158 Name_Length,
10159 Expressions => New_List (
10160 Make_Integer_Literal (Loc,
10161 Ndim - J + 1)))),
10162 Decls),
10163 Build_To_Any_Call (Inner_TypeCode, Decls)));
10165 else
10166 -- Unconstrained case: add low bound for each
10167 -- dimension.
10169 Add_TypeCode_Parameter
10170 (Build_TypeCode_Call (Loc, Etype (Indx), Decls),
10171 Parameters);
10172 Get_Name_String (New_External_Name ('L', J));
10173 Add_String_Parameter (
10174 String_From_Name_Buffer,
10175 Parameters);
10176 Next_Index (Indx);
10178 Inner_TypeCode := Make_Constructed_TypeCode
10179 (RTE (RE_TC_Sequence), New_List (
10180 Build_To_Any_Call (
10181 OK_Convert_To (RTE (RE_Long_Unsigned),
10182 Make_Integer_Literal (Loc, 0)),
10183 Decls),
10184 Build_To_Any_Call (Inner_TypeCode, Decls)));
10185 end if;
10186 end loop;
10188 if Constrained then
10189 Return_Alias_TypeCode (Inner_TypeCode);
10190 else
10191 Add_TypeCode_Parameter (Inner_TypeCode, Parameters);
10192 Start_String;
10193 Store_String_Char ('V');
10194 Add_String_Parameter (End_String, Parameters);
10195 Return_Constructed_TypeCode (RTE (RE_TC_Struct));
10196 end if;
10197 end;
10199 else
10200 -- Default: type is represented as an opaque sequence of bytes
10202 Return_Alias_TypeCode
10203 (New_Occurrence_Of (RTE (RE_TC_Opaque), Loc));
10204 end if;
10206 Decl :=
10207 Make_Subprogram_Body (Loc,
10208 Specification => Spec,
10209 Declarations => Decls,
10210 Handled_Statement_Sequence =>
10211 Make_Handled_Sequence_Of_Statements (Loc,
10212 Statements => Stms));
10213 end Build_TypeCode_Function;
10215 ---------------------------------
10216 -- Find_Numeric_Representation --
10217 ---------------------------------
10219 function Find_Numeric_Representation
10220 (Typ : Entity_Id) return Entity_Id
10222 FST : constant Entity_Id := First_Subtype (Typ);
10223 P_Size : constant Uint := Esize (FST);
10225 begin
10226 if Is_Unsigned_Type (Typ) then
10227 if P_Size <= Standard_Short_Short_Integer_Size then
10228 return RTE (RE_Short_Short_Unsigned);
10230 elsif P_Size <= Standard_Short_Integer_Size then
10231 return RTE (RE_Short_Unsigned);
10233 elsif P_Size <= Standard_Integer_Size then
10234 return RTE (RE_Unsigned);
10236 elsif P_Size <= Standard_Long_Integer_Size then
10237 return RTE (RE_Long_Unsigned);
10239 else
10240 return RTE (RE_Long_Long_Unsigned);
10241 end if;
10243 elsif Is_Integer_Type (Typ) then
10244 if P_Size <= Standard_Short_Short_Integer_Size then
10245 return Standard_Short_Short_Integer;
10247 elsif P_Size <= Standard_Short_Integer_Size then
10248 return Standard_Short_Integer;
10250 elsif P_Size <= Standard_Integer_Size then
10251 return Standard_Integer;
10253 elsif P_Size <= Standard_Long_Integer_Size then
10254 return Standard_Long_Integer;
10256 else
10257 return Standard_Long_Long_Integer;
10258 end if;
10260 elsif Is_Floating_Point_Type (Typ) then
10261 if P_Size <= Standard_Short_Float_Size then
10262 return Standard_Short_Float;
10264 elsif P_Size <= Standard_Float_Size then
10265 return Standard_Float;
10267 elsif P_Size <= Standard_Long_Float_Size then
10268 return Standard_Long_Float;
10270 else
10271 return Standard_Long_Long_Float;
10272 end if;
10274 else
10275 raise Program_Error;
10276 end if;
10278 -- TBD: fixed point types???
10279 -- TBverified numeric types with a biased representation???
10281 end Find_Numeric_Representation;
10283 ---------------------------
10284 -- Append_Array_Traversal --
10285 ---------------------------
10287 procedure Append_Array_Traversal
10288 (Stmts : List_Id;
10289 Any : Entity_Id;
10290 Counter : Entity_Id := Empty;
10291 Depth : Pos := 1)
10293 Loc : constant Source_Ptr := Sloc (Subprogram);
10294 Typ : constant Entity_Id := Etype (Arry);
10295 Constrained : constant Boolean := Is_Constrained (Typ);
10296 Ndim : constant Pos := Number_Dimensions (Typ);
10298 Inner_Any, Inner_Counter : Entity_Id;
10300 Loop_Stm : Node_Id;
10301 Inner_Stmts : constant List_Id := New_List;
10303 begin
10304 if Depth > Ndim then
10306 -- Processing for one element of an array
10308 declare
10309 Element_Expr : constant Node_Id :=
10310 Make_Indexed_Component (Loc,
10311 New_Occurrence_Of (Arry, Loc),
10312 Indices);
10314 begin
10315 Set_Etype (Element_Expr, Component_Type (Typ));
10316 Add_Process_Element (Stmts,
10317 Any => Any,
10318 Counter => Counter,
10319 Datum => Element_Expr);
10320 end;
10322 return;
10323 end if;
10325 Append_To (Indices,
10326 Make_Identifier (Loc, New_External_Name ('L', Depth)));
10328 if not Constrained or else Depth > 1 then
10329 Inner_Any := Make_Defining_Identifier (Loc,
10330 New_External_Name ('A', Depth));
10331 Set_Etype (Inner_Any, RTE (RE_Any));
10332 else
10333 Inner_Any := Empty;
10334 end if;
10336 if Present (Counter) then
10337 Inner_Counter := Make_Defining_Identifier (Loc,
10338 New_External_Name ('J', Depth));
10339 else
10340 Inner_Counter := Empty;
10341 end if;
10343 declare
10344 Loop_Any : Node_Id := Inner_Any;
10345 begin
10347 -- For the first dimension of a constrained array, we add
10348 -- elements directly in the corresponding Any; there is no
10349 -- intervening inner Any.
10351 if No (Loop_Any) then
10352 Loop_Any := Any;
10353 end if;
10355 Append_Array_Traversal (Inner_Stmts,
10356 Any => Loop_Any,
10357 Counter => Inner_Counter,
10358 Depth => Depth + 1);
10359 end;
10361 Loop_Stm :=
10362 Make_Implicit_Loop_Statement (Subprogram,
10363 Iteration_Scheme =>
10364 Make_Iteration_Scheme (Loc,
10365 Loop_Parameter_Specification =>
10366 Make_Loop_Parameter_Specification (Loc,
10367 Defining_Identifier =>
10368 Make_Defining_Identifier (Loc,
10369 Chars => New_External_Name ('L', Depth)),
10371 Discrete_Subtype_Definition =>
10372 Make_Attribute_Reference (Loc,
10373 Prefix => New_Occurrence_Of (Arry, Loc),
10374 Attribute_Name => Name_Range,
10376 Expressions => New_List (
10377 Make_Integer_Literal (Loc, Depth))))),
10378 Statements => Inner_Stmts);
10380 declare
10381 Decls : constant List_Id := New_List;
10382 Dimen_Stmts : constant List_Id := New_List;
10383 Length_Node : Node_Id;
10385 Inner_Any_TypeCode : constant Entity_Id :=
10386 Make_Defining_Identifier (Loc,
10387 New_External_Name ('T', Depth));
10389 Inner_Any_TypeCode_Expr : Node_Id;
10391 begin
10392 if Depth = 1 then
10393 if Constrained then
10394 Inner_Any_TypeCode_Expr :=
10395 Make_Function_Call (Loc,
10396 Name =>
10397 New_Occurrence_Of (RTE (RE_Get_TC), Loc),
10398 Parameter_Associations => New_List (
10399 New_Occurrence_Of (Any, Loc)));
10400 else
10401 Inner_Any_TypeCode_Expr :=
10402 Make_Function_Call (Loc,
10403 Name =>
10404 New_Occurrence_Of (RTE (RE_Any_Member_Type), Loc),
10405 Parameter_Associations => New_List (
10406 New_Occurrence_Of (Any, Loc),
10407 Make_Integer_Literal (Loc, Ndim)));
10408 end if;
10409 else
10410 Inner_Any_TypeCode_Expr :=
10411 Make_Function_Call (Loc,
10412 Name =>
10413 New_Occurrence_Of (RTE (RE_Content_Type), Loc),
10414 Parameter_Associations => New_List (
10415 Make_Identifier (Loc,
10416 New_External_Name ('T', Depth - 1))));
10417 end if;
10419 Append_To (Decls,
10420 Make_Object_Declaration (Loc,
10421 Defining_Identifier => Inner_Any_TypeCode,
10422 Constant_Present => True,
10423 Object_Definition => New_Occurrence_Of (
10424 RTE (RE_TypeCode), Loc),
10425 Expression => Inner_Any_TypeCode_Expr));
10427 if Present (Inner_Any) then
10428 Append_To (Decls,
10429 Make_Object_Declaration (Loc,
10430 Defining_Identifier => Inner_Any,
10431 Object_Definition =>
10432 New_Occurrence_Of (RTE (RE_Any), Loc),
10433 Expression =>
10434 Make_Function_Call (Loc,
10435 Name =>
10436 New_Occurrence_Of (
10437 RTE (RE_Create_Any), Loc),
10438 Parameter_Associations => New_List (
10439 New_Occurrence_Of (Inner_Any_TypeCode, Loc)))));
10440 end if;
10442 if Present (Inner_Counter) then
10443 Append_To (Decls,
10444 Make_Object_Declaration (Loc,
10445 Defining_Identifier => Inner_Counter,
10446 Object_Definition =>
10447 New_Occurrence_Of (RTE (RE_Long_Unsigned), Loc),
10448 Expression =>
10449 Make_Integer_Literal (Loc, 0)));
10450 end if;
10452 if not Constrained then
10453 Length_Node := Make_Attribute_Reference (Loc,
10454 Prefix => New_Occurrence_Of (Arry, Loc),
10455 Attribute_Name => Name_Length,
10456 Expressions =>
10457 New_List (Make_Integer_Literal (Loc, Depth)));
10458 Set_Etype (Length_Node, RTE (RE_Long_Unsigned));
10460 Add_Process_Element (Dimen_Stmts,
10461 Datum => Length_Node,
10462 Any => Inner_Any,
10463 Counter => Inner_Counter);
10464 end if;
10466 -- Loop_Stm does approrpriate processing for each element
10467 -- of Inner_Any.
10469 Append_To (Dimen_Stmts, Loop_Stm);
10471 -- Link outer and inner any
10473 if Present (Inner_Any) then
10474 Add_Process_Element (Dimen_Stmts,
10475 Any => Any,
10476 Counter => Counter,
10477 Datum => New_Occurrence_Of (Inner_Any, Loc));
10478 end if;
10480 Append_To (Stmts,
10481 Make_Block_Statement (Loc,
10482 Declarations =>
10483 Decls,
10484 Handled_Statement_Sequence =>
10485 Make_Handled_Sequence_Of_Statements (Loc,
10486 Statements => Dimen_Stmts)));
10487 end;
10488 end Append_Array_Traversal;
10490 -----------------------------------------
10491 -- Make_Stream_Procedure_Function_Name --
10492 -----------------------------------------
10494 function Make_Stream_Procedure_Function_Name
10495 (Loc : Source_Ptr;
10496 Typ : Entity_Id;
10497 Nam : Name_Id) return Entity_Id
10499 begin
10500 -- For tagged types, we use a canonical name so that it matches
10501 -- the primitive spec. For all other cases, we use a serialized
10502 -- name so that multiple generations of the same procedure do not
10503 -- clash.
10505 if Is_Tagged_Type (Typ) then
10506 return Make_Defining_Identifier (Loc, Nam);
10507 else
10508 return Make_Defining_Identifier (Loc,
10509 Chars =>
10510 New_External_Name (Nam, ' ', Increment_Serial_Number));
10511 end if;
10512 end Make_Stream_Procedure_Function_Name;
10513 end Helpers;
10515 -----------------------------------
10516 -- Reserve_NamingContext_Methods --
10517 -----------------------------------
10519 procedure Reserve_NamingContext_Methods is
10520 Str_Resolve : constant String := "resolve";
10521 begin
10522 Name_Buffer (1 .. Str_Resolve'Length) := Str_Resolve;
10523 Name_Len := Str_Resolve'Length;
10524 Overload_Counter_Table.Set (Name_Find, 1);
10525 end Reserve_NamingContext_Methods;
10527 end PolyORB_Support;
10529 -------------------------------
10530 -- RACW_Type_Is_Asynchronous --
10531 -------------------------------
10533 procedure RACW_Type_Is_Asynchronous (RACW_Type : Entity_Id) is
10534 Asynchronous_Flag : constant Entity_Id :=
10535 Asynchronous_Flags_Table.Get (RACW_Type);
10536 begin
10537 Replace (Expression (Parent (Asynchronous_Flag)),
10538 New_Occurrence_Of (Standard_True, Sloc (Asynchronous_Flag)));
10539 end RACW_Type_Is_Asynchronous;
10541 -------------------------
10542 -- RCI_Package_Locator --
10543 -------------------------
10545 function RCI_Package_Locator
10546 (Loc : Source_Ptr;
10547 Package_Spec : Node_Id) return Node_Id
10549 Inst : Node_Id;
10550 Pkg_Name : String_Id;
10552 begin
10553 Get_Library_Unit_Name_String (Package_Spec);
10554 Pkg_Name := String_From_Name_Buffer;
10555 Inst :=
10556 Make_Package_Instantiation (Loc,
10557 Defining_Unit_Name =>
10558 Make_Defining_Identifier (Loc, New_Internal_Name ('R')),
10559 Name =>
10560 New_Occurrence_Of (RTE (RE_RCI_Locator), Loc),
10561 Generic_Associations => New_List (
10562 Make_Generic_Association (Loc,
10563 Selector_Name =>
10564 Make_Identifier (Loc, Name_RCI_Name),
10565 Explicit_Generic_Actual_Parameter =>
10566 Make_String_Literal (Loc,
10567 Strval => Pkg_Name))));
10569 RCI_Locator_Table.Set (Defining_Unit_Name (Package_Spec),
10570 Defining_Unit_Name (Inst));
10571 return Inst;
10572 end RCI_Package_Locator;
10574 -----------------------------------------------
10575 -- Remote_Types_Tagged_Full_View_Encountered --
10576 -----------------------------------------------
10578 procedure Remote_Types_Tagged_Full_View_Encountered
10579 (Full_View : Entity_Id)
10581 Stub_Elements : constant Stub_Structure :=
10582 Stubs_Table.Get (Full_View);
10583 begin
10584 if Stub_Elements /= Empty_Stub_Structure then
10585 Add_RACW_Primitive_Declarations_And_Bodies
10586 (Full_View,
10587 Stub_Elements.RPC_Receiver_Decl,
10588 List_Containing (Declaration_Node (Full_View)));
10589 end if;
10590 end Remote_Types_Tagged_Full_View_Encountered;
10592 -------------------
10593 -- Scope_Of_Spec --
10594 -------------------
10596 function Scope_Of_Spec (Spec : Node_Id) return Entity_Id is
10597 Unit_Name : Node_Id;
10599 begin
10600 Unit_Name := Defining_Unit_Name (Spec);
10601 while Nkind (Unit_Name) /= N_Defining_Identifier loop
10602 Unit_Name := Defining_Identifier (Unit_Name);
10603 end loop;
10605 return Unit_Name;
10606 end Scope_Of_Spec;
10608 ----------------------
10609 -- Set_Renaming_TSS --
10610 ----------------------
10612 procedure Set_Renaming_TSS
10613 (Typ : Entity_Id;
10614 Nam : Entity_Id;
10615 TSS_Nam : TSS_Name_Type)
10617 Loc : constant Source_Ptr := Sloc (Nam);
10618 Spec : constant Node_Id := Parent (Nam);
10620 TSS_Node : constant Node_Id :=
10621 Make_Subprogram_Renaming_Declaration (Loc,
10622 Specification =>
10623 Copy_Specification (Loc,
10624 Spec => Spec,
10625 New_Name => Make_TSS_Name (Typ, TSS_Nam)),
10626 Name => New_Occurrence_Of (Nam, Loc));
10628 Snam : constant Entity_Id :=
10629 Defining_Unit_Name (Specification (TSS_Node));
10631 begin
10632 if Nkind (Spec) = N_Function_Specification then
10633 Set_Ekind (Snam, E_Function);
10634 Set_Etype (Snam, Entity (Result_Definition (Spec)));
10635 else
10636 Set_Ekind (Snam, E_Procedure);
10637 Set_Etype (Snam, Standard_Void_Type);
10638 end if;
10640 Set_TSS (Typ, Snam);
10641 end Set_Renaming_TSS;
10643 ----------------------------------------------
10644 -- Specific_Add_Obj_RPC_Receiver_Completion --
10645 ----------------------------------------------
10647 procedure Specific_Add_Obj_RPC_Receiver_Completion
10648 (Loc : Source_Ptr;
10649 Decls : List_Id;
10650 RPC_Receiver : Entity_Id;
10651 Stub_Elements : Stub_Structure) is
10652 begin
10653 case Get_PCS_Name is
10654 when Name_PolyORB_DSA =>
10655 PolyORB_Support.Add_Obj_RPC_Receiver_Completion (Loc,
10656 Decls, RPC_Receiver, Stub_Elements);
10657 when others =>
10658 GARLIC_Support.Add_Obj_RPC_Receiver_Completion (Loc,
10659 Decls, RPC_Receiver, Stub_Elements);
10660 end case;
10661 end Specific_Add_Obj_RPC_Receiver_Completion;
10663 --------------------------------
10664 -- Specific_Add_RACW_Features --
10665 --------------------------------
10667 procedure Specific_Add_RACW_Features
10668 (RACW_Type : Entity_Id;
10669 Desig : Entity_Id;
10670 Stub_Type : Entity_Id;
10671 Stub_Type_Access : Entity_Id;
10672 RPC_Receiver_Decl : Node_Id;
10673 Declarations : List_Id) is
10674 begin
10675 case Get_PCS_Name is
10676 when Name_PolyORB_DSA =>
10677 PolyORB_Support.Add_RACW_Features (
10678 RACW_Type,
10679 Desig,
10680 Stub_Type,
10681 Stub_Type_Access,
10682 RPC_Receiver_Decl,
10683 Declarations);
10685 when others =>
10686 GARLIC_Support.Add_RACW_Features (
10687 RACW_Type,
10688 Stub_Type,
10689 Stub_Type_Access,
10690 RPC_Receiver_Decl,
10691 Declarations);
10692 end case;
10693 end Specific_Add_RACW_Features;
10695 --------------------------------
10696 -- Specific_Add_RAST_Features --
10697 --------------------------------
10699 procedure Specific_Add_RAST_Features
10700 (Vis_Decl : Node_Id;
10701 RAS_Type : Entity_Id) is
10702 begin
10703 case Get_PCS_Name is
10704 when Name_PolyORB_DSA =>
10705 PolyORB_Support.Add_RAST_Features (Vis_Decl, RAS_Type);
10706 when others =>
10707 GARLIC_Support.Add_RAST_Features (Vis_Decl, RAS_Type);
10708 end case;
10709 end Specific_Add_RAST_Features;
10711 --------------------------------------------------
10712 -- Specific_Add_Receiving_Stubs_To_Declarations --
10713 --------------------------------------------------
10715 procedure Specific_Add_Receiving_Stubs_To_Declarations
10716 (Pkg_Spec : Node_Id;
10717 Decls : List_Id)
10719 begin
10720 case Get_PCS_Name is
10721 when Name_PolyORB_DSA =>
10722 PolyORB_Support.Add_Receiving_Stubs_To_Declarations (
10723 Pkg_Spec, Decls);
10724 when others =>
10725 GARLIC_Support.Add_Receiving_Stubs_To_Declarations (
10726 Pkg_Spec, Decls);
10727 end case;
10728 end Specific_Add_Receiving_Stubs_To_Declarations;
10730 ------------------------------------------
10731 -- Specific_Build_General_Calling_Stubs --
10732 ------------------------------------------
10734 procedure Specific_Build_General_Calling_Stubs
10735 (Decls : List_Id;
10736 Statements : List_Id;
10737 Target : RPC_Target;
10738 Subprogram_Id : Node_Id;
10739 Asynchronous : Node_Id := Empty;
10740 Is_Known_Asynchronous : Boolean := False;
10741 Is_Known_Non_Asynchronous : Boolean := False;
10742 Is_Function : Boolean;
10743 Spec : Node_Id;
10744 Stub_Type : Entity_Id := Empty;
10745 RACW_Type : Entity_Id := Empty;
10746 Nod : Node_Id)
10748 begin
10749 case Get_PCS_Name is
10750 when Name_PolyORB_DSA =>
10751 PolyORB_Support.Build_General_Calling_Stubs (
10752 Decls,
10753 Statements,
10754 Target.Object,
10755 Subprogram_Id,
10756 Asynchronous,
10757 Is_Known_Asynchronous,
10758 Is_Known_Non_Asynchronous,
10759 Is_Function,
10760 Spec,
10761 Stub_Type,
10762 RACW_Type,
10763 Nod);
10764 when others =>
10765 GARLIC_Support.Build_General_Calling_Stubs (
10766 Decls,
10767 Statements,
10768 Target.Partition,
10769 Target.RPC_Receiver,
10770 Subprogram_Id,
10771 Asynchronous,
10772 Is_Known_Asynchronous,
10773 Is_Known_Non_Asynchronous,
10774 Is_Function,
10775 Spec,
10776 Stub_Type,
10777 RACW_Type,
10778 Nod);
10779 end case;
10780 end Specific_Build_General_Calling_Stubs;
10782 --------------------------------------
10783 -- Specific_Build_RPC_Receiver_Body --
10784 --------------------------------------
10786 procedure Specific_Build_RPC_Receiver_Body
10787 (RPC_Receiver : Entity_Id;
10788 Request : out Entity_Id;
10789 Subp_Id : out Entity_Id;
10790 Subp_Index : out Entity_Id;
10791 Stmts : out List_Id;
10792 Decl : out Node_Id)
10794 begin
10795 case Get_PCS_Name is
10796 when Name_PolyORB_DSA =>
10797 PolyORB_Support.Build_RPC_Receiver_Body
10798 (RPC_Receiver,
10799 Request,
10800 Subp_Id,
10801 Subp_Index,
10802 Stmts,
10803 Decl);
10804 when others =>
10805 GARLIC_Support.Build_RPC_Receiver_Body
10806 (RPC_Receiver,
10807 Request,
10808 Subp_Id,
10809 Subp_Index,
10810 Stmts,
10811 Decl);
10812 end case;
10813 end Specific_Build_RPC_Receiver_Body;
10815 --------------------------------
10816 -- Specific_Build_Stub_Target --
10817 --------------------------------
10819 function Specific_Build_Stub_Target
10820 (Loc : Source_Ptr;
10821 Decls : List_Id;
10822 RCI_Locator : Entity_Id;
10823 Controlling_Parameter : Entity_Id) return RPC_Target
10825 begin
10826 case Get_PCS_Name is
10827 when Name_PolyORB_DSA =>
10828 return PolyORB_Support.Build_Stub_Target (Loc,
10829 Decls, RCI_Locator, Controlling_Parameter);
10830 when others =>
10831 return GARLIC_Support.Build_Stub_Target (Loc,
10832 Decls, RCI_Locator, Controlling_Parameter);
10833 end case;
10834 end Specific_Build_Stub_Target;
10836 ------------------------------
10837 -- Specific_Build_Stub_Type --
10838 ------------------------------
10840 procedure Specific_Build_Stub_Type
10841 (RACW_Type : Entity_Id;
10842 Stub_Type : Entity_Id;
10843 Stub_Type_Decl : out Node_Id;
10844 RPC_Receiver_Decl : out Node_Id)
10846 begin
10847 case Get_PCS_Name is
10848 when Name_PolyORB_DSA =>
10849 PolyORB_Support.Build_Stub_Type (
10850 RACW_Type, Stub_Type,
10851 Stub_Type_Decl, RPC_Receiver_Decl);
10852 when others =>
10853 GARLIC_Support.Build_Stub_Type (
10854 RACW_Type, Stub_Type,
10855 Stub_Type_Decl, RPC_Receiver_Decl);
10856 end case;
10857 end Specific_Build_Stub_Type;
10859 function Specific_Build_Subprogram_Receiving_Stubs
10860 (Vis_Decl : Node_Id;
10861 Asynchronous : Boolean;
10862 Dynamically_Asynchronous : Boolean := False;
10863 Stub_Type : Entity_Id := Empty;
10864 RACW_Type : Entity_Id := Empty;
10865 Parent_Primitive : Entity_Id := Empty) return Node_Id
10867 begin
10868 case Get_PCS_Name is
10869 when Name_PolyORB_DSA =>
10870 return PolyORB_Support.Build_Subprogram_Receiving_Stubs (
10871 Vis_Decl,
10872 Asynchronous,
10873 Dynamically_Asynchronous,
10874 Stub_Type,
10875 RACW_Type,
10876 Parent_Primitive);
10877 when others =>
10878 return GARLIC_Support.Build_Subprogram_Receiving_Stubs (
10879 Vis_Decl,
10880 Asynchronous,
10881 Dynamically_Asynchronous,
10882 Stub_Type,
10883 RACW_Type,
10884 Parent_Primitive);
10885 end case;
10886 end Specific_Build_Subprogram_Receiving_Stubs;
10888 --------------------------
10889 -- Underlying_RACW_Type --
10890 --------------------------
10892 function Underlying_RACW_Type (RAS_Typ : Entity_Id) return Entity_Id is
10893 Record_Type : Entity_Id;
10895 begin
10896 if Ekind (RAS_Typ) = E_Record_Type then
10897 Record_Type := RAS_Typ;
10898 else
10899 pragma Assert (Present (Equivalent_Type (RAS_Typ)));
10900 Record_Type := Equivalent_Type (RAS_Typ);
10901 end if;
10903 return
10904 Etype (Subtype_Indication (
10905 Component_Definition (
10906 First (Component_Items (Component_List (
10907 Type_Definition (Declaration_Node (Record_Type))))))));
10908 end Underlying_RACW_Type;
10910 end Exp_Dist;