OSDN Git Service

* exp_dist.adb (Build_RPC_Receiver_Body): New subprogram. This
[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-2004, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
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_Res;  use Sem_Res;
40 with Sem_Util; use Sem_Util;
41 with Sinfo;    use Sinfo;
42 with Snames;   use Snames;
43 with Stand;    use Stand;
44 with Stringt;  use Stringt;
45 with Tbuild;   use Tbuild;
46
47 package body Sem_Dist is
48
49    -----------------------
50    -- Local Subprograms --
51    -----------------------
52
53    procedure RAS_E_Dereference (Pref : Node_Id);
54    --  Handles explicit dereference of Remote Access to Subprograms.
55
56    function Full_Qualified_Name (E : Entity_Id) return String_Id;
57    --  returns the full qualified name of the entity in lower case.
58
59    -------------------------
60    -- Add_Stub_Constructs --
61    -------------------------
62
63    procedure Add_Stub_Constructs (N : Node_Id) is
64       U    : constant Node_Id := Unit (N);
65       Spec : Entity_Id        := Empty;
66       Exp  : Node_Id          := U;         --  Unit that will be expanded
67
68    begin
69       pragma Assert (Distribution_Stub_Mode /= No_Stubs);
70
71       if Nkind (U) = N_Package_Declaration then
72          Spec := Defining_Entity (Specification (U));
73
74       elsif Nkind (U) = N_Package_Body then
75          Spec := Corresponding_Spec (U);
76
77       else pragma Assert (Nkind (U) = N_Package_Instantiation);
78          Exp  := Instance_Spec (U);
79          Spec := Defining_Entity (Specification (Exp));
80       end if;
81
82       pragma Assert (Is_Shared_Passive (Spec)
83         or else Is_Remote_Call_Interface (Spec));
84
85       if Distribution_Stub_Mode = Generate_Caller_Stub_Body then
86
87          if Is_Shared_Passive (Spec) then
88             null;
89          elsif Nkind (U) = N_Package_Body then
90             Error_Msg_N
91               ("Specification file expected from command line", U);
92          else
93             Expand_Calling_Stubs_Bodies (Exp);
94          end if;
95
96       else
97
98          if Is_Shared_Passive (Spec) then
99             Build_Passive_Partition_Stub (Exp);
100          else
101             Expand_Receiving_Stubs_Bodies (Exp);
102          end if;
103
104       end if;
105    end Add_Stub_Constructs;
106
107    ---------------------------------------
108    -- Build_RAS_Primitive_Specification --
109    ---------------------------------------
110
111    function Build_RAS_Primitive_Specification
112      (Subp_Spec          : Node_Id;
113       Remote_Object_Type : Node_Id) return Node_Id
114    is
115       Loc : constant Source_Ptr := Sloc (Subp_Spec);
116
117       Primitive_Spec : constant Node_Id :=
118                          Copy_Specification (Loc,
119                            Spec     => Subp_Spec,
120                            New_Name => Name_Call);
121
122       Subtype_Mark_For_Self : Node_Id;
123
124    begin
125       if No (Parameter_Specifications (Primitive_Spec)) then
126          Set_Parameter_Specifications (Primitive_Spec, New_List);
127       end if;
128
129       if Nkind (Remote_Object_Type) in N_Entity then
130          Subtype_Mark_For_Self :=
131            New_Occurrence_Of (Remote_Object_Type, Loc);
132       else
133          Subtype_Mark_For_Self := Remote_Object_Type;
134       end if;
135
136       Prepend_To (
137         Parameter_Specifications (Primitive_Spec),
138         Make_Parameter_Specification (Loc,
139           Defining_Identifier =>
140             Make_Defining_Identifier (Loc, Name_uS),
141           Parameter_Type      =>
142             Make_Access_Definition (Loc,
143               Subtype_Mark =>
144                 Subtype_Mark_For_Self)));
145
146       --  Trick later semantic analysis into considering this
147       --  operation as a primitive (dispatching) operation of
148       --  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
178       --  don't 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    -- Is_All_Remote_Call --
204    ------------------------
205
206    function Is_All_Remote_Call (N : Node_Id) return Boolean is
207       Par : Node_Id;
208
209    begin
210       if (Nkind (N) = N_Function_Call
211               or else Nkind (N) = N_Procedure_Call_Statement)
212         and then Nkind (Name (N)) in N_Has_Entity
213         and then Is_Remote_Call_Interface (Entity (Name (N)))
214         and then Has_All_Calls_Remote (Scope (Entity (Name (N))))
215         and then Comes_From_Source (N)
216       then
217          Par := Parent (Entity (Name (N)));
218
219          while Present (Par)
220            and then (Nkind (Par) /= N_Package_Specification
221                        or else Is_Wrapper_Package (Defining_Entity (Par)))
222          loop
223             Par := Parent (Par);
224          end loop;
225
226          if Present (Par) then
227             return
228               not Scope_Within_Or_Same (Current_Scope, Defining_Entity (Par));
229          else
230             return False;
231          end if;
232       else
233          return False;
234       end if;
235    end Is_All_Remote_Call;
236
237    ------------------------------------
238    -- Package_Specification_Of_Scope --
239    ------------------------------------
240
241    function Package_Specification_Of_Scope (E : Entity_Id) return Node_Id is
242       N : Node_Id := Parent (E);
243    begin
244       while Nkind (N) /= N_Package_Specification loop
245          N := Parent (N);
246       end loop;
247
248       return N;
249    end Package_Specification_Of_Scope;
250
251    --------------------------
252    -- Process_Partition_ID --
253    --------------------------
254
255    procedure Process_Partition_Id (N : Node_Id) is
256       Loc            : constant Source_Ptr := Sloc (N);
257       Ety            : Entity_Id;
258       Get_Pt_Id      : Node_Id;
259       Get_Pt_Id_Call : Node_Id;
260       Prefix_String  : String_Id;
261       Typ            : constant Entity_Id := Etype (N);
262
263    begin
264       Ety := Entity (Prefix (N));
265
266       --  In case prefix is not a library unit entity, get the entity
267       --  of library unit.
268
269       while (Present (Scope (Ety))
270         and then Scope (Ety) /= Standard_Standard)
271         and not Is_Child_Unit (Ety)
272       loop
273          Ety := Scope (Ety);
274       end loop;
275
276       --  Retrieve the proper function to call.
277
278       if Is_Remote_Call_Interface (Ety) then
279          Get_Pt_Id := New_Occurrence_Of
280            (RTE (RE_Get_Active_Partition_Id), Loc);
281
282       elsif Is_Shared_Passive (Ety) then
283          Get_Pt_Id := New_Occurrence_Of
284            (RTE (RE_Get_Passive_Partition_Id), Loc);
285
286       else
287          Get_Pt_Id := New_Occurrence_Of
288            (RTE (RE_Get_Local_Partition_Id), Loc);
289       end if;
290
291       --  Get and store the String_Id corresponding to the name of the
292       --  library unit whose Partition_Id is needed.
293
294       Get_Library_Unit_Name_String (Unit_Declaration_Node (Ety));
295       Prefix_String := String_From_Name_Buffer;
296
297       --  Build the function call which will replace the attribute
298
299       if Is_Remote_Call_Interface (Ety)
300         or else Is_Shared_Passive (Ety)
301       then
302          Get_Pt_Id_Call :=
303            Make_Function_Call (Loc,
304              Name => Get_Pt_Id,
305              Parameter_Associations =>
306                New_List (Make_String_Literal (Loc, Prefix_String)));
307
308       else
309          Get_Pt_Id_Call := Make_Function_Call (Loc, Get_Pt_Id);
310
311       end if;
312
313       --  Replace the attribute node by a conversion of the function call
314       --  to the target type.
315
316       Rewrite (N, Convert_To (Typ, Get_Pt_Id_Call));
317       Analyze_And_Resolve (N, Typ);
318    end Process_Partition_Id;
319
320    ----------------------------------
321    -- Process_Remote_AST_Attribute --
322    ----------------------------------
323
324    procedure Process_Remote_AST_Attribute
325      (N        : Node_Id;
326       New_Type : Entity_Id)
327    is
328       Loc                   : constant Source_Ptr := Sloc (N);
329       Remote_Subp           : Entity_Id;
330       Tick_Access_Conv_Call : Node_Id;
331       Remote_Subp_Decl      : Node_Id;
332       RS_Pkg_Specif         : Node_Id;
333       RS_Pkg_E              : Entity_Id;
334       RAS_Type              : Entity_Id := New_Type;
335       Async_E               : Entity_Id;
336       All_Calls_Remote_E    : Entity_Id;
337       Attribute_Subp        : Entity_Id;
338
339    begin
340       --  Check if we have to expand the access attribute
341
342       Remote_Subp := Entity (Prefix (N));
343
344       if not Expander_Active then
345          return;
346       end if;
347
348       if Ekind (RAS_Type) /= E_Record_Type then
349          RAS_Type := Equivalent_Type (RAS_Type);
350       end if;
351
352       Attribute_Subp := TSS (RAS_Type, TSS_RAS_Access);
353       pragma Assert (Present (Attribute_Subp));
354       Remote_Subp_Decl := Unit_Declaration_Node (Remote_Subp);
355
356       if Nkind (Remote_Subp_Decl) = N_Subprogram_Body then
357          Remote_Subp := Corresponding_Spec (Remote_Subp_Decl);
358          Remote_Subp_Decl := Unit_Declaration_Node (Remote_Subp);
359       end if;
360
361       RS_Pkg_Specif := Parent (Remote_Subp_Decl);
362       RS_Pkg_E := Defining_Entity (RS_Pkg_Specif);
363
364       Async_E :=
365         Boolean_Literals (Ekind (Remote_Subp) = E_Procedure
366                             and then Is_Asynchronous (Remote_Subp));
367
368       All_Calls_Remote_E :=
369         Boolean_Literals (Has_All_Calls_Remote (RS_Pkg_E));
370
371       Tick_Access_Conv_Call :=
372         Make_Function_Call (Loc,
373           Name => New_Occurrence_Of (Attribute_Subp, Loc),
374           Parameter_Associations =>
375             New_List (
376               Make_String_Literal (Loc, Full_Qualified_Name (RS_Pkg_E)),
377               Build_Subprogram_Id (Loc, Remote_Subp),
378               New_Occurrence_Of (Async_E, Loc),
379               New_Occurrence_Of (All_Calls_Remote_E, Loc)));
380
381       Rewrite (N, Tick_Access_Conv_Call);
382       Analyze_And_Resolve (N, RAS_Type);
383    end Process_Remote_AST_Attribute;
384
385    ------------------------------------
386    -- Process_Remote_AST_Declaration --
387    ------------------------------------
388
389    procedure Process_Remote_AST_Declaration (N : Node_Id) is
390       Loc            : constant Source_Ptr := Sloc (N);
391       User_Type      : constant Node_Id := Defining_Identifier (N);
392       Scop           : constant Entity_Id := Scope (User_Type);
393       Is_RCI         : constant Boolean :=
394         Is_Remote_Call_Interface (Scop);
395       Is_RT          : constant Boolean :=
396         Is_Remote_Types (Scop);
397       Type_Def       : constant Node_Id := Type_Definition (N);
398
399       Parameter      : Node_Id;
400       Is_Degenerate  : Boolean;
401       --  True iff this RAS has an access formal parameter (see
402       --  Exp_Dist.Add_RAS_Dereference_TSS for details).
403
404       Subpkg         : constant Entity_Id :=
405                          Make_Defining_Identifier
406                            (Loc, New_Internal_Name ('S'));
407       Subpkg_Decl    : Node_Id;
408       Vis_Decls      : constant List_Id := New_List;
409       Priv_Decls     : constant List_Id := New_List;
410
411       Obj_Type       : constant Entity_Id :=
412                          Make_Defining_Identifier
413                            (Loc, New_External_Name (
414                                    Chars (User_Type), 'R'));
415
416
417       Full_Obj_Type  : constant Entity_Id :=
418                          Make_Defining_Identifier
419                            (Loc, Chars (Obj_Type));
420
421       RACW_Type      : constant Entity_Id :=
422                          Make_Defining_Identifier
423                            (Loc, New_External_Name (
424                                    Chars (User_Type), 'P'));
425
426       Fat_Type       : constant Entity_Id :=
427                         Make_Defining_Identifier
428                           (Loc, Chars (User_Type));
429       Fat_Type_Decl  : Node_Id;
430
431    begin
432
433       --  The tagged private type, primitive operation and RACW
434       --  type associated with a RAS need to all be declared in
435       --  a subpackage of the one that contains the RAS declaration,
436       --  because the primitive of the object type, and the associated
437       --  primitive of the stub type, need to be dispatching operations
438       --  of these types, and the profile of the RAS might contain
439       --  tagged types declared in the same scope.
440
441       Append_To (Vis_Decls,
442         Make_Private_Type_Declaration (Loc,
443           Defining_Identifier => Obj_Type,
444           Abstract_Present => True,
445           Tagged_Present   => True,
446           Limited_Present  => True));
447
448       Append_To (Priv_Decls,
449         Make_Full_Type_Declaration (Loc,
450           Defining_Identifier =>
451             Full_Obj_Type,
452           Type_Definition     =>
453             Make_Record_Definition (Loc,
454               Abstract_Present => True,
455               Tagged_Present   => True,
456               Limited_Present  => True,
457               Null_Present     => True,
458               Component_List   => Empty)));
459
460       Is_Degenerate := False;
461       Parameter := First (Parameter_Specifications (Type_Def));
462       Parameters : while Present (Parameter) loop
463          if Nkind (Parameter_Type (Parameter)) = N_Access_Definition then
464             Error_Msg_N ("formal parameter& has anonymous access type?",
465               Defining_Identifier (Parameter));
466             Is_Degenerate := True;
467             exit Parameters;
468          end if;
469          Next (Parameter);
470       end loop Parameters;
471
472       if Is_Degenerate then
473          Error_Msg_NE (
474            "remote access-to-subprogram type& can only be null?",
475            Defining_Identifier (Parameter), User_Type);
476          --  The only legal value for a RAS with a formal parameter of an
477          --  anonymous access type is null, because it cannot be
478          --  subtype-Conformant with any legal remote subprogram declaration.
479          --  In this case, we cannot generate a corresponding primitive
480          --  operation.
481
482       else
483          Append_To (Vis_Decls,
484            Make_Abstract_Subprogram_Declaration (Loc,
485              Specification => Build_RAS_Primitive_Specification (
486                Subp_Spec          => Type_Def,
487                Remote_Object_Type => Obj_Type)));
488       end if;
489
490       Append_To (Vis_Decls,
491         Make_Full_Type_Declaration (Loc,
492           Defining_Identifier => RACW_Type,
493           Type_Definition     =>
494             Make_Access_To_Object_Definition (Loc,
495               All_Present => True,
496               Subtype_Indication =>
497                 Make_Attribute_Reference (Loc,
498                   Prefix =>
499                     New_Occurrence_Of (Obj_Type, Loc),
500                   Attribute_Name =>
501                     Name_Class))));
502       Set_Is_Remote_Call_Interface (RACW_Type, Is_RCI);
503       Set_Is_Remote_Types (RACW_Type, Is_RT);
504
505       Subpkg_Decl :=
506         Make_Package_Declaration (Loc,
507           Make_Package_Specification (Loc,
508             Defining_Unit_Name =>
509               Subpkg,
510             Visible_Declarations =>
511               Vis_Decls,
512             Private_Declarations =>
513               Priv_Decls,
514             End_Label =>
515               New_Occurrence_Of (Subpkg, Loc)));
516       Set_Is_Remote_Call_Interface (Subpkg, Is_RCI);
517       Set_Is_Remote_Types (Subpkg, Is_RT);
518       Insert_After_And_Analyze (N, Subpkg_Decl);
519
520       --  Many parts of the analyzer and expander expect
521       --  that the fat pointer type used to implement remote
522       --  access to subprogram types be a record.
523       --  Note: The structure of this type must be kept consistent
524       --  with the code generated by Remote_AST_Null_Value for the
525       --  corresponding 'null' expression.
526
527       Fat_Type_Decl := Make_Full_Type_Declaration (Loc,
528         Defining_Identifier => Fat_Type,
529         Type_Definition     =>
530           Make_Record_Definition (Loc,
531             Component_List =>
532               Make_Component_List (Loc,
533                 Component_Items => New_List (
534                   Make_Component_Declaration (Loc,
535                     Defining_Identifier =>
536                       Make_Defining_Identifier (Loc, Name_Ras),
537                     Component_Definition =>
538                       Make_Component_Definition (Loc,
539                         Aliased_Present     =>
540                           False,
541                         Subtype_Indication  =>
542                           New_Occurrence_Of (RACW_Type, Loc)))))));
543       Set_Equivalent_Type (User_Type, Fat_Type);
544       Set_Corresponding_Remote_Type (Fat_Type, User_Type);
545       Insert_After_And_Analyze (Subpkg_Decl, Fat_Type_Decl);
546
547       --  The reason we suppress the initialization procedure is that we know
548       --  that no initialization is required (even if Initialize_Scalars mode
549       --  is active), and there are order of elaboration problems if we do try
550       --  to generate an init proc for this created record type.
551
552       Set_Suppress_Init_Proc (Fat_Type);
553
554       if Expander_Active then
555          Add_RAST_Features (Parent (User_Type));
556       end if;
557    end Process_Remote_AST_Declaration;
558
559    -----------------------
560    -- RAS_E_Dereference --
561    -----------------------
562
563    procedure RAS_E_Dereference (Pref : Node_Id) is
564       Loc             : constant Source_Ptr := Sloc (Pref);
565       Call_Node       : Node_Id;
566       New_Type        : constant Entity_Id := Etype (Pref);
567       Explicit_Deref  : constant Node_Id   := Parent (Pref);
568       Deref_Subp_Call : constant Node_Id   := Parent (Explicit_Deref);
569       Deref_Proc      : Entity_Id;
570       Params          : List_Id;
571
572    begin
573       if Nkind (Deref_Subp_Call) = N_Procedure_Call_Statement then
574          Params := Parameter_Associations (Deref_Subp_Call);
575
576          if Present (Params) then
577             Prepend (Pref, Params);
578          else
579             Params := New_List (Pref);
580          end if;
581
582       elsif Nkind (Deref_Subp_Call) = N_Indexed_Component then
583
584          Params := Expressions (Deref_Subp_Call);
585
586          if Present (Params) then
587             Prepend (Pref, Params);
588          else
589             Params := New_List (Pref);
590          end if;
591
592       else
593          --  Context is not a call.
594
595          return;
596       end if;
597
598       if not Expander_Active then
599          return;
600       end if;
601
602       Deref_Proc := TSS (New_Type, TSS_RAS_Dereference);
603       pragma Assert (Present (Deref_Proc));
604
605       if Ekind (Deref_Proc) = E_Function then
606          Call_Node :=
607            Make_Function_Call (Loc,
608               Name => New_Occurrence_Of (Deref_Proc, Loc),
609               Parameter_Associations => Params);
610
611       else
612          Call_Node :=
613            Make_Procedure_Call_Statement (Loc,
614               Name => New_Occurrence_Of (Deref_Proc, Loc),
615               Parameter_Associations => Params);
616       end if;
617
618       Rewrite (Deref_Subp_Call, Call_Node);
619       Analyze (Deref_Subp_Call);
620    end RAS_E_Dereference;
621
622    ------------------------------
623    -- Remote_AST_E_Dereference --
624    ------------------------------
625
626    function Remote_AST_E_Dereference (P : Node_Id) return Boolean is
627       ET : constant Entity_Id  := Etype (P);
628
629    begin
630       --  Perform the changes only on original dereferences, and only if
631       --  we are generating code.
632
633       if Comes_From_Source (P)
634         and then Is_Record_Type (ET)
635         and then (Is_Remote_Call_Interface (ET)
636                    or else Is_Remote_Types (ET))
637         and then Present (Corresponding_Remote_Type (ET))
638         and then (Nkind (Parent (Parent (P))) = N_Procedure_Call_Statement
639                    or else Nkind (Parent (Parent (P))) = N_Indexed_Component)
640         and then Expander_Active
641       then
642          RAS_E_Dereference (P);
643          return True;
644       else
645          return False;
646       end if;
647    end Remote_AST_E_Dereference;
648
649    ------------------------------
650    -- Remote_AST_I_Dereference --
651    ------------------------------
652
653    function Remote_AST_I_Dereference (P : Node_Id) return Boolean is
654       ET     : constant Entity_Id  := Etype (P);
655       Deref  : Node_Id;
656
657    begin
658       if Comes_From_Source (P)
659         and then (Is_Remote_Call_Interface (ET)
660                    or else Is_Remote_Types (ET))
661         and then Present (Corresponding_Remote_Type (ET))
662         and then Ekind (Entity (P)) /= E_Function
663       then
664          Deref :=
665            Make_Explicit_Dereference (Sloc (P),
666              Prefix => Relocate_Node (P));
667          Rewrite (P, Deref);
668          Set_Etype (P, ET);
669          RAS_E_Dereference (Prefix (P));
670          return True;
671       end if;
672
673       return False;
674    end Remote_AST_I_Dereference;
675
676    ---------------------------
677    -- Remote_AST_Null_Value --
678    ---------------------------
679
680    function Remote_AST_Null_Value
681      (N   : Node_Id;
682       Typ : Entity_Id) return Boolean
683    is
684       Loc         : constant Source_Ptr := Sloc (N);
685       Target_Type : Entity_Id;
686
687    begin
688       if not Expander_Active then
689          return False;
690
691       elsif Ekind (Typ) = E_Access_Subprogram_Type
692         and then (Is_Remote_Call_Interface (Typ)
693                     or else Is_Remote_Types (Typ))
694         and then Comes_From_Source (N)
695         and then Expander_Active
696       then
697          --  Any null that comes from source and is of the RAS type must
698          --  be expanded, except if expansion is not active (nothing
699          --  gets expanded into the equivalent record type).
700
701          Target_Type := Equivalent_Type (Typ);
702
703       elsif Ekind (Typ) = E_Record_Type
704         and then Present (Corresponding_Remote_Type (Typ))
705       then
706          --  This is a record type representing a RAS type, this must be
707          --  expanded.
708
709          Target_Type := Typ;
710
711       else
712          --  We do not have to handle this case
713
714          return False;
715
716       end if;
717
718       Rewrite (N,
719         Make_Aggregate (Loc,
720           Component_Associations => New_List (
721             Make_Component_Association (Loc,
722               Choices => New_List (
723                 Make_Identifier (Loc, Name_Ras)),
724               Expression =>
725                 Make_Null (Loc)))));
726       Analyze_And_Resolve (N, Target_Type);
727       return True;
728    end Remote_AST_Null_Value;
729
730 end Sem_Dist;