OSDN Git Service

2007-08-14 Geert Bosch <bosch@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_dist.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ D I S T                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2007, 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 ------------------------------------------------------------------------------
26
27 with Atree;    use Atree;
28 with Casing;   use Casing;
29 with Einfo;    use Einfo;
30 with Errout;   use Errout;
31 with Exp_Dist; use Exp_Dist;
32 with Exp_Tss;  use Exp_Tss;
33 with Nlists;   use Nlists;
34 with Nmake;    use Nmake;
35 with Namet;    use Namet;
36 with Opt;      use Opt;
37 with Rtsfind;  use Rtsfind;
38 with Sem;      use Sem;
39 with Sem_Eval; use Sem_Eval;
40 with Sem_Res;  use Sem_Res;
41 with Sem_Util; use Sem_Util;
42 with Sinfo;    use Sinfo;
43 with Stand;    use Stand;
44 with Stringt;  use Stringt;
45 with Tbuild;   use Tbuild;
46 with Uintp;    use Uintp;
47
48 package body Sem_Dist is
49
50    -----------------------
51    -- Local Subprograms --
52    -----------------------
53
54    procedure RAS_E_Dereference (Pref : Node_Id);
55    --  Handles explicit dereference of Remote Access to Subprograms
56
57    function Full_Qualified_Name (E : Entity_Id) return String_Id;
58    --  returns the full qualified name of the entity in lower case
59
60    -------------------------
61    -- Add_Stub_Constructs --
62    -------------------------
63
64    procedure Add_Stub_Constructs (N : Node_Id) is
65       U    : constant Node_Id := Unit (N);
66       Spec : Entity_Id        := Empty;
67       Exp  : Node_Id          := U;         --  Unit that will be expanded
68
69    begin
70       pragma Assert (Distribution_Stub_Mode /= No_Stubs);
71
72       if Nkind (U) = N_Package_Declaration then
73          Spec := Defining_Entity (Specification (U));
74
75       elsif Nkind (U) = N_Package_Body then
76          Spec := Corresponding_Spec (U);
77
78       else pragma Assert (Nkind (U) = N_Package_Instantiation);
79          Exp  := Instance_Spec (U);
80          Spec := Defining_Entity (Specification (Exp));
81       end if;
82
83       pragma Assert (Is_Shared_Passive (Spec)
84         or else Is_Remote_Call_Interface (Spec));
85
86       if Distribution_Stub_Mode = Generate_Caller_Stub_Body then
87
88          if Is_Shared_Passive (Spec) then
89             null;
90          elsif Nkind (U) = N_Package_Body then
91             Error_Msg_N
92               ("Specification file expected from command line", U);
93          else
94             Expand_Calling_Stubs_Bodies (Exp);
95          end if;
96
97       else
98
99          if Is_Shared_Passive (Spec) then
100             Build_Passive_Partition_Stub (Exp);
101          else
102             Expand_Receiving_Stubs_Bodies (Exp);
103          end if;
104
105       end if;
106    end Add_Stub_Constructs;
107
108    ---------------------------------------
109    -- Build_RAS_Primitive_Specification --
110    ---------------------------------------
111
112    function Build_RAS_Primitive_Specification
113      (Subp_Spec          : Node_Id;
114       Remote_Object_Type : Node_Id) return Node_Id
115    is
116       Loc : constant Source_Ptr := Sloc (Subp_Spec);
117
118       Primitive_Spec : constant Node_Id :=
119                          Copy_Specification (Loc,
120                            Spec     => Subp_Spec,
121                            New_Name => Name_uCall);
122
123       Subtype_Mark_For_Self : Node_Id;
124
125    begin
126       if No (Parameter_Specifications (Primitive_Spec)) then
127          Set_Parameter_Specifications (Primitive_Spec, New_List);
128       end if;
129
130       if Nkind (Remote_Object_Type) in N_Entity then
131          Subtype_Mark_For_Self :=
132            New_Occurrence_Of (Remote_Object_Type, Loc);
133       else
134          Subtype_Mark_For_Self := Remote_Object_Type;
135       end if;
136
137       Prepend_To (
138         Parameter_Specifications (Primitive_Spec),
139         Make_Parameter_Specification (Loc,
140           Defining_Identifier =>
141             Make_Defining_Identifier (Loc, Name_uS),
142           Parameter_Type      =>
143             Make_Access_Definition (Loc,
144               Subtype_Mark =>
145                 Subtype_Mark_For_Self)));
146
147       --  Trick later semantic analysis into considering this operation as a
148       --  primitive (dispatching) operation of tagged type Obj_Type.
149
150       Set_Comes_From_Source (
151         Defining_Unit_Name (Primitive_Spec), True);
152
153       return Primitive_Spec;
154    end Build_RAS_Primitive_Specification;
155
156    -------------------------
157    -- Full_Qualified_Name --
158    -------------------------
159
160    function Full_Qualified_Name (E : Entity_Id) return String_Id is
161       Ent         : Entity_Id := E;
162       Parent_Name : String_Id := No_String;
163
164    begin
165       --  Deals properly with child units
166
167       if Nkind (Ent) = N_Defining_Program_Unit_Name then
168          Ent := Defining_Identifier (Ent);
169       end if;
170
171       --  Compute recursively the qualification (only "Standard" has no scope)
172
173       if Present (Scope (Scope (Ent))) then
174          Parent_Name := Full_Qualified_Name (Scope (Ent));
175       end if;
176
177       --  Every entity should have a name except some expanded blocks. Do not
178       --  bother about those.
179
180       if Chars (Ent) = No_Name then
181          return Parent_Name;
182       end if;
183
184       --  Add a period between Name and qualification
185
186       if Parent_Name /= No_String then
187          Start_String (Parent_Name);
188          Store_String_Char (Get_Char_Code ('.'));
189
190       else
191          Start_String;
192       end if;
193
194       --  Generates the entity name in upper case
195
196       Get_Name_String (Chars (Ent));
197       Set_Casing (All_Lower_Case);
198       Store_String_Chars (Name_Buffer (1 .. Name_Len));
199       return End_String;
200    end Full_Qualified_Name;
201
202    ------------------
203    -- Get_PCS_Name --
204    ------------------
205
206    function Get_PCS_Name return PCS_Names is
207    begin
208       return
209         Chars (Entity (Expression (Parent (RTE (RE_DSA_Implementation)))));
210    end Get_PCS_Name;
211
212    ---------------------
213    -- Get_PCS_Version --
214    ---------------------
215
216    function Get_PCS_Version return Int is
217       PCS_Version_Entity : Entity_Id;
218       PCS_Version        : Int;
219
220    begin
221       if RTE_Available (RE_PCS_Version) then
222          PCS_Version_Entity := RTE (RE_PCS_Version);
223          pragma Assert (Ekind (PCS_Version_Entity) = E_Named_Integer);
224          PCS_Version :=
225            UI_To_Int (Expr_Value (Constant_Value (PCS_Version_Entity)));
226
227       else
228          --  Case of System.Partition_Interface.PCS_Version not found:
229          --  return a null version.
230
231          PCS_Version := 0;
232       end if;
233
234       return PCS_Version;
235    end Get_PCS_Version;
236
237    ------------------------
238    -- Is_All_Remote_Call --
239    ------------------------
240
241    function Is_All_Remote_Call (N : Node_Id) return Boolean is
242       Par : Node_Id;
243
244    begin
245       if (Nkind (N) = N_Function_Call
246               or else Nkind (N) = N_Procedure_Call_Statement)
247         and then Nkind (Name (N)) in N_Has_Entity
248         and then Is_Remote_Call_Interface (Entity (Name (N)))
249         and then Has_All_Calls_Remote (Scope (Entity (Name (N))))
250         and then Comes_From_Source (N)
251       then
252          Par := Parent (Entity (Name (N)));
253
254          while Present (Par)
255            and then (Nkind (Par) /= N_Package_Specification
256                        or else Is_Wrapper_Package (Defining_Entity (Par)))
257          loop
258             Par := Parent (Par);
259          end loop;
260
261          if Present (Par) then
262             return
263               not Scope_Within_Or_Same (Current_Scope, Defining_Entity (Par));
264          else
265             return False;
266          end if;
267       else
268          return False;
269       end if;
270    end Is_All_Remote_Call;
271
272    ------------------------------------
273    -- Package_Specification_Of_Scope --
274    ------------------------------------
275
276    function Package_Specification_Of_Scope (E : Entity_Id) return Node_Id is
277       N : Node_Id := Parent (E);
278    begin
279       while Nkind (N) /= N_Package_Specification loop
280          N := Parent (N);
281       end loop;
282
283       return N;
284    end Package_Specification_Of_Scope;
285
286    --------------------------
287    -- Process_Partition_ID --
288    --------------------------
289
290    procedure Process_Partition_Id (N : Node_Id) is
291       Loc            : constant Source_Ptr := Sloc (N);
292       Ety            : Entity_Id;
293       Get_Pt_Id      : Node_Id;
294       Get_Pt_Id_Call : Node_Id;
295       Prefix_String  : String_Id;
296       Typ            : constant Entity_Id := Etype (N);
297
298    begin
299       Ety := Entity (Prefix (N));
300
301       --  In case prefix is not a library unit entity, get the entity
302       --  of library unit.
303
304       while (Present (Scope (Ety))
305         and then Scope (Ety) /= Standard_Standard)
306         and not Is_Child_Unit (Ety)
307       loop
308          Ety := Scope (Ety);
309       end loop;
310
311       --  Retrieve the proper function to call
312
313       if Is_Remote_Call_Interface (Ety) then
314          Get_Pt_Id := New_Occurrence_Of
315            (RTE (RE_Get_Active_Partition_Id), Loc);
316
317       elsif Is_Shared_Passive (Ety) then
318          Get_Pt_Id := New_Occurrence_Of
319            (RTE (RE_Get_Passive_Partition_Id), Loc);
320
321       else
322          Get_Pt_Id := New_Occurrence_Of
323            (RTE (RE_Get_Local_Partition_Id), Loc);
324       end if;
325
326       --  Get and store the String_Id corresponding to the name of the
327       --  library unit whose Partition_Id is needed.
328
329       Get_Library_Unit_Name_String (Unit_Declaration_Node (Ety));
330       Prefix_String := String_From_Name_Buffer;
331
332       --  Build the function call which will replace the attribute
333
334       if Is_Remote_Call_Interface (Ety)
335         or else Is_Shared_Passive (Ety)
336       then
337          Get_Pt_Id_Call :=
338            Make_Function_Call (Loc,
339              Name => Get_Pt_Id,
340              Parameter_Associations =>
341                New_List (Make_String_Literal (Loc, Prefix_String)));
342
343       else
344          Get_Pt_Id_Call := Make_Function_Call (Loc, Get_Pt_Id);
345
346       end if;
347
348       --  Replace the attribute node by a conversion of the function call
349       --  to the target type.
350
351       Rewrite (N, Convert_To (Typ, Get_Pt_Id_Call));
352       Analyze_And_Resolve (N, Typ);
353    end Process_Partition_Id;
354
355    ----------------------------------
356    -- Process_Remote_AST_Attribute --
357    ----------------------------------
358
359    procedure Process_Remote_AST_Attribute
360      (N        : Node_Id;
361       New_Type : Entity_Id)
362    is
363       Loc                   : constant Source_Ptr := Sloc (N);
364       Remote_Subp           : Entity_Id;
365       Tick_Access_Conv_Call : Node_Id;
366       Remote_Subp_Decl      : Node_Id;
367       RS_Pkg_Specif         : Node_Id;
368       RS_Pkg_E              : Entity_Id;
369       RAS_Type              : Entity_Id := New_Type;
370       Async_E               : Entity_Id;
371       All_Calls_Remote_E    : Entity_Id;
372       Attribute_Subp        : Entity_Id;
373
374    begin
375       --  Check if we have to expand the access attribute
376
377       Remote_Subp := Entity (Prefix (N));
378
379       if not Expander_Active or else Get_PCS_Name = Name_No_DSA then
380          return;
381       end if;
382
383       if Ekind (RAS_Type) /= E_Record_Type then
384          RAS_Type := Equivalent_Type (RAS_Type);
385       end if;
386
387       Attribute_Subp := TSS (RAS_Type, TSS_RAS_Access);
388       pragma Assert (Present (Attribute_Subp));
389       Remote_Subp_Decl := Unit_Declaration_Node (Remote_Subp);
390
391       if Nkind (Remote_Subp_Decl) = N_Subprogram_Body then
392          Remote_Subp := Corresponding_Spec (Remote_Subp_Decl);
393          Remote_Subp_Decl := Unit_Declaration_Node (Remote_Subp);
394       end if;
395
396       RS_Pkg_Specif := Parent (Remote_Subp_Decl);
397       RS_Pkg_E := Defining_Entity (RS_Pkg_Specif);
398
399       Async_E :=
400         Boolean_Literals (Ekind (Remote_Subp) = E_Procedure
401                             and then Is_Asynchronous (Remote_Subp));
402
403       All_Calls_Remote_E :=
404         Boolean_Literals (Has_All_Calls_Remote (RS_Pkg_E));
405
406       Tick_Access_Conv_Call :=
407         Make_Function_Call (Loc,
408           Name => New_Occurrence_Of (Attribute_Subp, Loc),
409           Parameter_Associations =>
410             New_List (
411               Make_String_Literal (Loc, Full_Qualified_Name (RS_Pkg_E)),
412               Build_Subprogram_Id (Loc, Remote_Subp),
413               New_Occurrence_Of (Async_E, Loc),
414               New_Occurrence_Of (All_Calls_Remote_E, Loc)));
415
416       Rewrite (N, Tick_Access_Conv_Call);
417       Analyze_And_Resolve (N, RAS_Type);
418    end Process_Remote_AST_Attribute;
419
420    ------------------------------------
421    -- Process_Remote_AST_Declaration --
422    ------------------------------------
423
424    procedure Process_Remote_AST_Declaration (N : Node_Id) is
425       Loc       : constant Source_Ptr := Sloc (N);
426       User_Type : constant Node_Id    := Defining_Identifier (N);
427       Scop      : constant Entity_Id  := Scope (User_Type);
428       Is_RCI    : constant Boolean    := Is_Remote_Call_Interface (Scop);
429       Is_RT     : constant Boolean    := Is_Remote_Types (Scop);
430       Type_Def  : constant Node_Id    := Type_Definition (N);
431       Parameter : Node_Id;
432
433       Is_Degenerate : Boolean;
434       --  True iff this RAS has an access formal parameter (see
435       --  Exp_Dist.Add_RAS_Dereference_TSS for details).
436
437       Subpkg      : constant Entity_Id :=
438                       Make_Defining_Identifier (Loc,
439                         New_Internal_Name ('S'));
440       Subpkg_Decl : Node_Id;
441       Subpkg_Body : Node_Id;
442       Vis_Decls   : constant List_Id := New_List;
443       Priv_Decls  : constant List_Id := New_List;
444
445       Obj_Type : constant Entity_Id :=
446                     Make_Defining_Identifier (Loc,
447                       New_External_Name (Chars (User_Type), 'R'));
448
449       Full_Obj_Type : constant Entity_Id :=
450                         Make_Defining_Identifier (Loc,
451                           Chars (Obj_Type));
452
453       RACW_Type : constant Entity_Id :=
454                     Make_Defining_Identifier (Loc,
455                       New_External_Name (Chars (User_Type), 'P'));
456
457       Fat_Type : constant Entity_Id :=
458                    Make_Defining_Identifier (Loc,
459                      Chars (User_Type));
460
461       Fat_Type_Decl : Node_Id;
462
463    begin
464       Is_Degenerate := False;
465       Parameter := First (Parameter_Specifications (Type_Def));
466       while Present (Parameter) loop
467          if Nkind (Parameter_Type (Parameter)) = N_Access_Definition then
468             Error_Msg_N ("formal parameter& has anonymous access type?",
469               Defining_Identifier (Parameter));
470             Is_Degenerate := True;
471             exit;
472          end if;
473
474          Next (Parameter);
475       end loop;
476
477       if Is_Degenerate then
478          Error_Msg_NE
479            ("remote access-to-subprogram type& can only be null?",
480             Defining_Identifier (Parameter), User_Type);
481
482          --  The only legal value for a RAS with a formal parameter of an
483          --  anonymous access type is null, because it cannot be subtype-
484          --  conformant with any legal remote subprogram declaration. In this
485          --  case, we cannot generate a corresponding primitive operation.
486
487       end if;
488
489       if Get_PCS_Name = Name_No_DSA then
490          return;
491       end if;
492
493       --  The tagged private type, primitive operation and RACW type associated
494       --  with a RAS need to all be declared in a subpackage of the one that
495       --  contains the RAS declaration, because the primitive of the object
496       --  type, and the associated primitive of the stub type, need to be
497       --  dispatching operations of these types, and the profile of the RAS
498       --  might contain tagged types declared in the same scope.
499
500       Append_To (Vis_Decls,
501         Make_Private_Type_Declaration (Loc,
502           Defining_Identifier => Obj_Type,
503           Abstract_Present => True,
504           Tagged_Present   => True,
505           Limited_Present  => True));
506
507       Append_To (Priv_Decls,
508         Make_Full_Type_Declaration (Loc,
509           Defining_Identifier =>
510             Full_Obj_Type,
511           Type_Definition     =>
512             Make_Record_Definition (Loc,
513               Abstract_Present => True,
514               Tagged_Present   => True,
515               Limited_Present  => True,
516               Null_Present     => True,
517               Component_List   => Empty)));
518
519       --  Trick semantic analysis into swapping the public and full view when
520       --  freezing the public view.
521
522       Set_Comes_From_Source (Full_Obj_Type, True);
523
524       if not Is_Degenerate then
525          Append_To (Vis_Decls,
526            Make_Abstract_Subprogram_Declaration (Loc,
527              Specification => Build_RAS_Primitive_Specification (
528                Subp_Spec          => Type_Def,
529                Remote_Object_Type => Obj_Type)));
530       end if;
531
532       Append_To (Vis_Decls,
533         Make_Full_Type_Declaration (Loc,
534           Defining_Identifier => RACW_Type,
535           Type_Definition     =>
536             Make_Access_To_Object_Definition (Loc,
537               All_Present => True,
538               Subtype_Indication =>
539                 Make_Attribute_Reference (Loc,
540                   Prefix =>
541                     New_Occurrence_Of (Obj_Type, Loc),
542                   Attribute_Name =>
543                     Name_Class))));
544       Set_Is_Remote_Call_Interface (RACW_Type, Is_RCI);
545       Set_Is_Remote_Types (RACW_Type, Is_RT);
546
547       Subpkg_Decl :=
548         Make_Package_Declaration (Loc,
549           Make_Package_Specification (Loc,
550             Defining_Unit_Name =>
551               Subpkg,
552             Visible_Declarations =>
553               Vis_Decls,
554             Private_Declarations =>
555               Priv_Decls,
556             End_Label =>
557               New_Occurrence_Of (Subpkg, Loc)));
558       Set_Is_Remote_Call_Interface (Subpkg, Is_RCI);
559       Set_Is_Remote_Types (Subpkg, Is_RT);
560       Insert_After_And_Analyze (N, Subpkg_Decl);
561
562       --  Generate package body to receive RACW calling stubs
563       --  Note: Analyze_Declarations has an absolute requirement that
564       --  the declaration list be non-empty, so we provide a dummy null
565       --  statement here.
566
567       Subpkg_Body :=
568         Make_Package_Body (Loc,
569           Defining_Unit_Name =>
570             Make_Defining_Identifier (Loc, Chars (Subpkg)),
571           Declarations => New_List (
572             Make_Null_Statement (Loc)));
573       Insert_After_And_Analyze (Subpkg_Decl, Subpkg_Body);
574
575       --  Many parts of the analyzer and expander expect
576       --  that the fat pointer type used to implement remote
577       --  access to subprogram types be a record.
578       --  Note: The structure of this type must be kept consistent
579       --  with the code generated by Remote_AST_Null_Value for the
580       --  corresponding 'null' expression.
581
582       Fat_Type_Decl := Make_Full_Type_Declaration (Loc,
583         Defining_Identifier => Fat_Type,
584         Type_Definition     =>
585           Make_Record_Definition (Loc,
586             Component_List =>
587               Make_Component_List (Loc,
588                 Component_Items => New_List (
589                   Make_Component_Declaration (Loc,
590                     Defining_Identifier =>
591                       Make_Defining_Identifier (Loc, Name_Ras),
592                     Component_Definition =>
593                       Make_Component_Definition (Loc,
594                         Aliased_Present     =>
595                           False,
596                         Subtype_Indication  =>
597                           New_Occurrence_Of (RACW_Type, Loc)))))));
598       Set_Equivalent_Type (User_Type, Fat_Type);
599       Set_Corresponding_Remote_Type (Fat_Type, User_Type);
600       Insert_After_And_Analyze (Subpkg_Body, Fat_Type_Decl);
601
602       --  The reason we suppress the initialization procedure is that we know
603       --  that no initialization is required (even if Initialize_Scalars mode
604       --  is active), and there are order of elaboration problems if we do try
605       --  to generate an init proc for this created record type.
606
607       Set_Suppress_Init_Proc (Fat_Type);
608
609       if Expander_Active then
610          Add_RAST_Features (Parent (User_Type));
611       end if;
612    end Process_Remote_AST_Declaration;
613
614    -----------------------
615    -- RAS_E_Dereference --
616    -----------------------
617
618    procedure RAS_E_Dereference (Pref : Node_Id) is
619       Loc             : constant Source_Ptr := Sloc (Pref);
620       Call_Node       : Node_Id;
621       New_Type        : constant Entity_Id := Etype (Pref);
622       Explicit_Deref  : constant Node_Id   := Parent (Pref);
623       Deref_Subp_Call : constant Node_Id   := Parent (Explicit_Deref);
624       Deref_Proc      : Entity_Id;
625       Params          : List_Id;
626
627    begin
628       if Nkind (Deref_Subp_Call) = N_Procedure_Call_Statement then
629          Params := Parameter_Associations (Deref_Subp_Call);
630
631          if Present (Params) then
632             Prepend (Pref, Params);
633          else
634             Params := New_List (Pref);
635          end if;
636
637       elsif Nkind (Deref_Subp_Call) = N_Indexed_Component then
638
639          Params := Expressions (Deref_Subp_Call);
640
641          if Present (Params) then
642             Prepend (Pref, Params);
643          else
644             Params := New_List (Pref);
645          end if;
646
647       else
648          --  Context is not a call
649
650          return;
651       end if;
652
653       if not Expander_Active or else Get_PCS_Name = Name_No_DSA then
654          return;
655       end if;
656
657       Deref_Proc := TSS (New_Type, TSS_RAS_Dereference);
658       pragma Assert (Present (Deref_Proc));
659
660       if Ekind (Deref_Proc) = E_Function then
661          Call_Node :=
662            Make_Function_Call (Loc,
663               Name => New_Occurrence_Of (Deref_Proc, Loc),
664               Parameter_Associations => Params);
665
666       else
667          Call_Node :=
668            Make_Procedure_Call_Statement (Loc,
669               Name => New_Occurrence_Of (Deref_Proc, Loc),
670               Parameter_Associations => Params);
671       end if;
672
673       Rewrite (Deref_Subp_Call, Call_Node);
674       Analyze (Deref_Subp_Call);
675    end RAS_E_Dereference;
676
677    ------------------------------
678    -- Remote_AST_E_Dereference --
679    ------------------------------
680
681    function Remote_AST_E_Dereference (P : Node_Id) return Boolean is
682       ET : constant Entity_Id  := Etype (P);
683
684    begin
685       --  Perform the changes only on original dereferences, and only if
686       --  we are generating code.
687
688       if Comes_From_Source (P)
689         and then Is_Record_Type (ET)
690         and then (Is_Remote_Call_Interface (ET)
691                    or else Is_Remote_Types (ET))
692         and then Present (Corresponding_Remote_Type (ET))
693         and then (Nkind (Parent (Parent (P))) = N_Procedure_Call_Statement
694                    or else Nkind (Parent (Parent (P))) = N_Indexed_Component)
695         and then Expander_Active
696       then
697          RAS_E_Dereference (P);
698          return True;
699       else
700          return False;
701       end if;
702    end Remote_AST_E_Dereference;
703
704    ------------------------------
705    -- Remote_AST_I_Dereference --
706    ------------------------------
707
708    function Remote_AST_I_Dereference (P : Node_Id) return Boolean is
709       ET     : constant Entity_Id  := Etype (P);
710       Deref  : Node_Id;
711
712    begin
713       if Comes_From_Source (P)
714         and then (Is_Remote_Call_Interface (ET)
715                    or else Is_Remote_Types (ET))
716         and then Present (Corresponding_Remote_Type (ET))
717         and then Ekind (Entity (P)) /= E_Function
718       then
719          Deref :=
720            Make_Explicit_Dereference (Sloc (P),
721              Prefix => Relocate_Node (P));
722          Rewrite (P, Deref);
723          Set_Etype (P, ET);
724          RAS_E_Dereference (Prefix (P));
725          return True;
726       end if;
727
728       return False;
729    end Remote_AST_I_Dereference;
730
731    ---------------------------
732    -- Remote_AST_Null_Value --
733    ---------------------------
734
735    function Remote_AST_Null_Value
736      (N   : Node_Id;
737       Typ : Entity_Id) return Boolean
738    is
739       Loc         : constant Source_Ptr := Sloc (N);
740       Target_Type : Entity_Id;
741
742    begin
743       if not Expander_Active or else Get_PCS_Name = Name_No_DSA then
744          return False;
745
746       elsif Ekind (Typ) = E_Access_Subprogram_Type
747         and then (Is_Remote_Call_Interface (Typ)
748                     or else Is_Remote_Types (Typ))
749         and then Comes_From_Source (N)
750         and then Expander_Active
751       then
752          --  Any null that comes from source and is of the RAS type must
753          --  be expanded, except if expansion is not active (nothing
754          --  gets expanded into the equivalent record type).
755
756          Target_Type := Equivalent_Type (Typ);
757
758       elsif Ekind (Typ) = E_Record_Type
759         and then Present (Corresponding_Remote_Type (Typ))
760       then
761          --  This is a record type representing a RAS type, this must be
762          --  expanded.
763
764          Target_Type := Typ;
765
766       else
767          --  We do not have to handle this case
768
769          return False;
770
771       end if;
772
773       Rewrite (N,
774         Make_Aggregate (Loc,
775           Component_Associations => New_List (
776             Make_Component_Association (Loc,
777               Choices => New_List (
778                 Make_Identifier (Loc, Name_Ras)),
779               Expression =>
780                 Make_Null (Loc)))));
781       Analyze_And_Resolve (N, Target_Type);
782       return True;
783    end Remote_AST_Null_Value;
784
785 end Sem_Dist;