OSDN Git Service

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