OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [ada/] [sem_cat.adb] - Blame information for rev 304

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 281 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT COMPILER COMPONENTS                         --
4
--                                                                          --
5
--                              S E M _ C A T                               --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--          Copyright (C) 1992-2009, 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 3,  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 COPYING3.  If not, go to --
19
-- http://www.gnu.org/licenses for a complete copy of the license.          --
20
--                                                                          --
21
-- GNAT was originally developed  by the GNAT team at  New York University. --
22
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23
--                                                                          --
24
------------------------------------------------------------------------------
25
 
26
with Atree;    use Atree;
27
with Debug;    use Debug;
28
with Einfo;    use Einfo;
29
with Elists;   use Elists;
30
with Errout;   use Errout;
31
with Exp_Disp; use Exp_Disp;
32
with Fname;    use Fname;
33
with Lib;      use Lib;
34
with Namet;    use Namet;
35
with Nlists;   use Nlists;
36
with Opt;      use Opt;
37
with Sem;      use Sem;
38
with Sem_Aux;  use Sem_Aux;
39
with Sem_Eval; use Sem_Eval;
40
with Sem_Util; use Sem_Util;
41
with Sinfo;    use Sinfo;
42
with Snames;   use Snames;
43
with Stand;    use Stand;
44
 
45
package body Sem_Cat is
46
 
47
   -----------------------
48
   -- Local Subprograms --
49
   -----------------------
50
 
51
   procedure Check_Categorization_Dependencies
52
     (Unit_Entity     : Entity_Id;
53
      Depended_Entity : Entity_Id;
54
      Info_Node       : Node_Id;
55
      Is_Subunit      : Boolean);
56
   --  This procedure checks that the categorization of a lib unit and that
57
   --  of the depended unit satisfy dependency restrictions.
58
   --  The depended_entity can be the entity in a with_clause item, in which
59
   --  case Info_Node denotes that item. The depended_entity can also be the
60
   --  parent unit of a child unit, in which case Info_Node is the declaration
61
   --  of the child unit.  The error message is posted on Info_Node, and is
62
   --  specialized if Is_Subunit is true.
63
 
64
   procedure Check_Non_Static_Default_Expr
65
     (Type_Def : Node_Id;
66
      Obj_Decl : Node_Id);
67
   --  Iterate through the component list of a record definition, check
68
   --  that no component is declared with a nonstatic default value.
69
   --  If a nonstatic default exists, report an error on Obj_Decl.
70
 
71
   --  Iterate through the component list of a record definition, check
72
   --  that no component is declared with a non-static default value.
73
 
74
   function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
75
   --  Return True if the entity or one of its subcomponents is of an access
76
   --  type that does not have user-defined Read and Write attributes visible
77
   --  at any place.
78
 
79
   function In_RCI_Declaration (N : Node_Id) return Boolean;
80
   --  Determines if a declaration is  within the visible part of a Remote
81
   --  Call Interface compilation unit, for semantic checking purposes only,
82
   --  (returns false within an instance and within the package body).
83
 
84
   function In_RT_Declaration return Boolean;
85
   --  Determines if current scope is within a Remote Types compilation unit,
86
   --  for semantic checking purposes.
87
 
88
   function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
89
   --  Returns true if the entity is a type whose full view is a non-remote
90
   --  access type, for the purpose of enforcing E.2.2(8) rules.
91
 
92
   function In_Shared_Passive_Unit return Boolean;
93
   --  Determines if current scope is within a Shared Passive compilation unit
94
 
95
   function Static_Discriminant_Expr (L : List_Id) return Boolean;
96
   --  Iterate through the list of discriminants to check if any of them
97
   --  contains non-static default expression, which is a violation in
98
   --  a preelaborated library unit.
99
 
100
   procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
101
   --  Check validity of declaration if RCI or RT unit. It should not contain
102
   --  the declaration of an access-to-object type unless it is a general
103
   --  access type that designates a class-wide limited private type. There are
104
   --  also constraints about the primitive subprograms of the class-wide type.
105
   --  RM E.2 (9, 13, 14)
106
 
107
   ---------------------------------------
108
   -- Check_Categorization_Dependencies --
109
   ---------------------------------------
110
 
111
   procedure Check_Categorization_Dependencies
112
     (Unit_Entity     : Entity_Id;
113
      Depended_Entity : Entity_Id;
114
      Info_Node       : Node_Id;
115
      Is_Subunit      : Boolean)
116
   is
117
      N   : constant Node_Id := Info_Node;
118
      Err : Boolean;
119
 
120
      --  Here we define an enumeration type to represent categorization types,
121
      --  ordered so that a unit with a given categorization can only WITH
122
      --  units with lower or equal categorization type.
123
 
124
      type Categorization is
125
        (Pure,
126
         Shared_Passive,
127
         Remote_Types,
128
         Remote_Call_Interface,
129
         Normal);
130
 
131
      function Get_Categorization (E : Entity_Id) return Categorization;
132
      --  Check categorization flags from entity, and return in the form
133
      --  of the lowest value of the Categorization type that applies to E.
134
 
135
      ------------------------
136
      -- Get_Categorization --
137
      ------------------------
138
 
139
      function Get_Categorization (E : Entity_Id) return Categorization is
140
      begin
141
         --  Get the lowest categorization that corresponds to E. Note that
142
         --  nothing prevents several (different) categorization pragmas
143
         --  to apply to the same library unit, in which case the unit has
144
         --  all associated categories, so we need to be careful here to
145
         --  check pragmas in proper Categorization order in order to
146
         --  return the lowest applicable value.
147
 
148
         --  Ignore Pure specification if set by pragma Pure_Function
149
 
150
         if Is_Pure (E)
151
           and then not
152
             (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
153
         then
154
            return Pure;
155
 
156
         elsif Is_Shared_Passive (E) then
157
            return Shared_Passive;
158
 
159
         elsif Is_Remote_Types (E) then
160
            return Remote_Types;
161
 
162
         elsif Is_Remote_Call_Interface (E) then
163
            return Remote_Call_Interface;
164
 
165
         else
166
            return Normal;
167
         end if;
168
      end Get_Categorization;
169
 
170
      Unit_Category : Categorization;
171
      With_Category : Categorization;
172
 
173
   --  Start of processing for Check_Categorization_Dependencies
174
 
175
   begin
176
      --  Intrinsic subprograms are preelaborated, so do not impose any
177
      --  categorization dependencies.
178
 
179
      if Is_Intrinsic_Subprogram (Depended_Entity) then
180
         return;
181
      end if;
182
 
183
      --  First check 10.2.1 (11/1) rules on preelaborate packages
184
 
185
      if Is_Preelaborated (Unit_Entity)
186
        and then not Is_Preelaborated (Depended_Entity)
187
        and then not Is_Pure (Depended_Entity)
188
      then
189
         Err := True;
190
      else
191
         Err := False;
192
      end if;
193
 
194
      --  Check categorization rules of RM E.2(5)
195
 
196
      Unit_Category := Get_Categorization (Unit_Entity);
197
      With_Category := Get_Categorization (Depended_Entity);
198
 
199
      if With_Category > Unit_Category then
200
 
201
         --  Special case: Remote_Types and Remote_Call_Interface are allowed
202
         --  to WITH anything in the package body, per (RM E.2(5)).
203
 
204
         if (Unit_Category = Remote_Types
205
               or else Unit_Category = Remote_Call_Interface)
206
           and then In_Package_Body (Unit_Entity)
207
         then
208
            null;
209
         else
210
            Err := True;
211
         end if;
212
      end if;
213
 
214
      --  Here if we have an error
215
 
216
      if Err then
217
 
218
         --  These messages are warnings in GNAT mode, to allow it to be
219
         --  judiciously turned off. Otherwise it is a real error.
220
 
221
         Error_Msg_Warn := GNAT_Mode;
222
 
223
         --  Don't give error if main unit is not an internal unit, and the
224
         --  unit generating the message is an internal unit. This is the
225
         --  situation in which such messages would be ignored in any case,
226
         --  so it is convenient not to generate them (since it causes
227
         --  annoying interference with debugging).
228
 
229
         if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
230
           and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
231
         then
232
            return;
233
 
234
         --  Subunit case
235
 
236
         elsif Is_Subunit then
237
            Error_Msg_NE
238
              ("<subunit cannot depend on& " &
239
               "(parent has wrong categorization)", N, Depended_Entity);
240
 
241
         --  Normal unit, not subunit
242
 
243
         else
244
            Error_Msg_NE
245
              ("<cannot depend on& " &
246
               "(wrong categorization)", N, Depended_Entity);
247
         end if;
248
 
249
         --  Add further explanation for Pure/Preelaborate common cases
250
 
251
         if Unit_Category = Pure then
252
            Error_Msg_NE
253
              ("\<pure unit cannot depend on non-pure unit",
254
               N, Depended_Entity);
255
 
256
         elsif Is_Preelaborated (Unit_Entity)
257
           and then not Is_Preelaborated (Depended_Entity)
258
           and then not Is_Pure (Depended_Entity)
259
         then
260
            Error_Msg_NE
261
              ("\<preelaborated unit cannot depend on "
262
               & "non-preelaborated unit",
263
               N, Depended_Entity);
264
         end if;
265
      end if;
266
   end Check_Categorization_Dependencies;
267
 
268
   -----------------------------------
269
   -- Check_Non_Static_Default_Expr --
270
   -----------------------------------
271
 
272
   procedure Check_Non_Static_Default_Expr
273
     (Type_Def : Node_Id;
274
      Obj_Decl : Node_Id)
275
   is
276
      Recdef         : Node_Id;
277
      Component_Decl : Node_Id;
278
 
279
   begin
280
      if Nkind (Type_Def) = N_Derived_Type_Definition then
281
         Recdef := Record_Extension_Part (Type_Def);
282
 
283
         if No (Recdef) then
284
            return;
285
         end if;
286
 
287
      else
288
         Recdef := Type_Def;
289
      end if;
290
 
291
      --  Check that component declarations do not involve:
292
 
293
      --    a. a non-static default expression, where the object is
294
      --       declared to be default initialized.
295
 
296
      --    b. a dynamic Itype (discriminants and constraints)
297
 
298
      if Null_Present (Recdef) then
299
         return;
300
      else
301
         Component_Decl := First (Component_Items (Component_List (Recdef)));
302
      end if;
303
 
304
      while Present (Component_Decl)
305
        and then Nkind (Component_Decl) = N_Component_Declaration
306
      loop
307
         if Present (Expression (Component_Decl))
308
           and then Nkind (Expression (Component_Decl)) /= N_Null
309
           and then not Is_Static_Expression (Expression (Component_Decl))
310
         then
311
            Error_Msg_Sloc := Sloc (Component_Decl);
312
            Error_Msg_F
313
              ("object in preelaborated unit has non-static default#",
314
               Obj_Decl);
315
 
316
         --  Fix this later ???
317
 
318
         --  elsif Has_Dynamic_Itype (Component_Decl) then
319
         --     Error_Msg_N
320
         --       ("dynamic type discriminant," &
321
         --        " constraint in preelaborated unit",
322
         --        Component_Decl);
323
         end if;
324
 
325
         Next (Component_Decl);
326
      end loop;
327
   end Check_Non_Static_Default_Expr;
328
 
329
   -------------------------------------
330
   -- Has_Stream_Attribute_Definition --
331
   -------------------------------------
332
 
333
   function Has_Stream_Attribute_Definition
334
     (Typ          : Entity_Id;
335
      Nam          : TSS_Name_Type;
336
      At_Any_Place : Boolean := False) return Boolean
337
   is
338
      Rep_Item  : Node_Id;
339
      Full_Type : Entity_Id := Typ;
340
 
341
   begin
342
      --  In the case of a type derived from a private view, any specified
343
      --  stream attributes will be attached to the derived type's underlying
344
      --  type rather the derived type entity itself (which is itself private).
345
 
346
      if Is_Private_Type (Typ)
347
        and then Is_Derived_Type (Typ)
348
        and then Present (Full_View (Typ))
349
      then
350
         Full_Type := Underlying_Type (Typ);
351
      end if;
352
 
353
      --  We start from the declaration node and then loop until the end of
354
      --  the list until we find the requested attribute definition clause.
355
      --  In Ada 2005 mode, clauses are ignored if they are not currently
356
      --  visible (this is tested using the corresponding Entity, which is
357
      --  inserted by the expander at the point where the clause occurs),
358
      --  unless At_Any_Place is true.
359
 
360
      Rep_Item := First_Rep_Item (Full_Type);
361
      while Present (Rep_Item) loop
362
         if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
363
            case Chars (Rep_Item) is
364
               when Name_Read =>
365
                  exit when Nam = TSS_Stream_Read;
366
 
367
               when Name_Write =>
368
                  exit when Nam = TSS_Stream_Write;
369
 
370
               when Name_Input =>
371
                  exit when Nam = TSS_Stream_Input;
372
 
373
               when Name_Output =>
374
                  exit when Nam = TSS_Stream_Output;
375
 
376
               when others =>
377
                  null;
378
 
379
            end case;
380
         end if;
381
 
382
         Next_Rep_Item (Rep_Item);
383
      end loop;
384
 
385
      --  If At_Any_Place is true, return True if the attribute is available
386
      --  at any place; if it is false, return True only if the attribute is
387
      --  currently visible.
388
 
389
      return Present (Rep_Item)
390
        and then (Ada_Version < Ada_05
391
                   or else At_Any_Place
392
                   or else not Is_Hidden (Entity (Rep_Item)));
393
   end Has_Stream_Attribute_Definition;
394
 
395
   ---------------------------
396
   -- In_Preelaborated_Unit --
397
   ---------------------------
398
 
399
   function In_Preelaborated_Unit return Boolean is
400
      Unit_Entity : constant Entity_Id := Current_Scope;
401
      Unit_Kind   : constant Node_Kind :=
402
                      Nkind (Unit (Cunit (Current_Sem_Unit)));
403
 
404
   begin
405
      --  There are no constraints on body of remote_call_interface or
406
      --  remote_types packages.
407
 
408
      return (Unit_Entity /= Standard_Standard)
409
        and then (Is_Preelaborated (Unit_Entity)
410
                    or else Is_Pure (Unit_Entity)
411
                    or else Is_Shared_Passive (Unit_Entity)
412
                    or else
413
                      ((Is_Remote_Types (Unit_Entity)
414
                               or else Is_Remote_Call_Interface (Unit_Entity))
415
                         and then Ekind (Unit_Entity) = E_Package
416
                         and then Unit_Kind /= N_Package_Body
417
                         and then not In_Package_Body (Unit_Entity)
418
                         and then not In_Instance));
419
   end In_Preelaborated_Unit;
420
 
421
   ------------------
422
   -- In_Pure_Unit --
423
   ------------------
424
 
425
   function In_Pure_Unit return Boolean is
426
   begin
427
      return Is_Pure (Current_Scope);
428
   end In_Pure_Unit;
429
 
430
   ------------------------
431
   -- In_RCI_Declaration --
432
   ------------------------
433
 
434
   function In_RCI_Declaration (N : Node_Id) return Boolean is
435
      Unit_Entity : constant Entity_Id := Current_Scope;
436
      Unit_Kind   : constant Node_Kind :=
437
                      Nkind (Unit (Cunit (Current_Sem_Unit)));
438
 
439
   begin
440
      --  There are no restrictions on the private part or body
441
      --  of an RCI unit.
442
 
443
      return Is_Remote_Call_Interface (Unit_Entity)
444
        and then Is_Package_Or_Generic_Package (Unit_Entity)
445
        and then Unit_Kind /= N_Package_Body
446
        and then List_Containing (N) =
447
                  Visible_Declarations
448
                    (Specification (Unit_Declaration_Node (Unit_Entity)))
449
        and then not In_Package_Body (Unit_Entity)
450
        and then not In_Instance;
451
 
452
      --  What about the case of a nested package in the visible part???
453
      --  This case is missed by the List_Containing check above???
454
   end In_RCI_Declaration;
455
 
456
   -----------------------
457
   -- In_RT_Declaration --
458
   -----------------------
459
 
460
   function In_RT_Declaration return Boolean is
461
      Unit_Entity : constant Entity_Id := Current_Scope;
462
      Unit_Kind   : constant Node_Kind :=
463
                      Nkind (Unit (Cunit (Current_Sem_Unit)));
464
 
465
   begin
466
      --  There are no restrictions on the body of a Remote Types unit
467
 
468
      return Is_Remote_Types (Unit_Entity)
469
        and then Is_Package_Or_Generic_Package (Unit_Entity)
470
        and then Unit_Kind /= N_Package_Body
471
        and then not In_Package_Body (Unit_Entity)
472
        and then not In_Instance;
473
   end In_RT_Declaration;
474
 
475
   ----------------------------
476
   -- In_Shared_Passive_Unit --
477
   ----------------------------
478
 
479
   function In_Shared_Passive_Unit return Boolean is
480
      Unit_Entity : constant Entity_Id := Current_Scope;
481
 
482
   begin
483
      return Is_Shared_Passive (Unit_Entity);
484
   end In_Shared_Passive_Unit;
485
 
486
   ---------------------------------------
487
   -- In_Subprogram_Task_Protected_Unit --
488
   ---------------------------------------
489
 
490
   function In_Subprogram_Task_Protected_Unit return Boolean is
491
      E : Entity_Id;
492
 
493
   begin
494
      --  The following is to verify that a declaration is inside
495
      --  subprogram, generic subprogram, task unit, protected unit.
496
      --  Used to validate if a lib. unit is Pure. RM 10.2.1(16).
497
 
498
      --  Use scope chain to check successively outer scopes
499
 
500
      E := Current_Scope;
501
      loop
502
         if Is_Subprogram (E)
503
              or else
504
            Is_Generic_Subprogram (E)
505
              or else
506
            Is_Concurrent_Type (E)
507
         then
508
            return True;
509
 
510
         elsif E = Standard_Standard then
511
            return False;
512
         end if;
513
 
514
         E := Scope (E);
515
      end loop;
516
   end In_Subprogram_Task_Protected_Unit;
517
 
518
   -------------------------------
519
   -- Is_Non_Remote_Access_Type --
520
   -------------------------------
521
 
522
   function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
523
      U_E : constant Entity_Id := Underlying_Type (E);
524
   begin
525
      if No (U_E) then
526
 
527
         --  This case arises for the case of a generic formal type, in which
528
         --  case E.2.2(8) rules will be enforced at instantiation time.
529
 
530
         return False;
531
      end if;
532
 
533
      return Is_Access_Type (U_E)
534
        and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
535
        and then not Is_Remote_Access_To_Subprogram_Type (U_E);
536
   end Is_Non_Remote_Access_Type;
537
 
538
   ----------------------------------
539
   -- Missing_Read_Write_Attribute --
540
   ----------------------------------
541
 
542
   function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
543
      Component      : Entity_Id;
544
      Component_Type : Entity_Id;
545
      U_E            : constant Entity_Id := Underlying_Type (E);
546
 
547
      function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
548
      --  Return True if entity has attribute definition clauses for Read and
549
      --  Write attributes that are visible at some place.
550
 
551
      -------------------------------
552
      -- Has_Read_Write_Attributes --
553
      -------------------------------
554
 
555
      function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
556
      begin
557
         return True
558
           and then Has_Stream_Attribute_Definition (E,
559
                      TSS_Stream_Read,  At_Any_Place => True)
560
           and then Has_Stream_Attribute_Definition (E,
561
                      TSS_Stream_Write, At_Any_Place => True);
562
      end Has_Read_Write_Attributes;
563
 
564
   --  Start of processing for Missing_Read_Write_Attributes
565
 
566
   begin
567
      if No (U_E) then
568
         return False;
569
 
570
      elsif Has_Read_Write_Attributes (E)
571
        or else Has_Read_Write_Attributes (U_E)
572
      then
573
         return False;
574
 
575
      elsif Is_Non_Remote_Access_Type (U_E) then
576
         return True;
577
      end if;
578
 
579
      if Is_Record_Type (U_E) then
580
         Component := First_Entity (U_E);
581
         while Present (Component) loop
582
            if not Is_Tag (Component) then
583
               Component_Type := Etype (Component);
584
 
585
               if Missing_Read_Write_Attributes (Component_Type) then
586
                  return True;
587
               end if;
588
            end if;
589
 
590
            Next_Entity (Component);
591
         end loop;
592
      end if;
593
 
594
      return False;
595
   end Missing_Read_Write_Attributes;
596
 
597
   -------------------------------------
598
   -- Set_Categorization_From_Pragmas --
599
   -------------------------------------
600
 
601
   procedure Set_Categorization_From_Pragmas (N : Node_Id) is
602
      P   : constant Node_Id := Parent (N);
603
      S   : constant Entity_Id := Current_Scope;
604
 
605
      procedure Set_Parents (Visibility : Boolean);
606
         --  If this is a child instance, the parents are not immediately
607
         --  visible during analysis. Make them momentarily visible so that
608
         --  the argument of the pragma can be resolved properly, and reset
609
         --  afterwards.
610
 
611
      -----------------
612
      -- Set_Parents --
613
      -----------------
614
 
615
      procedure Set_Parents (Visibility : Boolean) is
616
         Par : Entity_Id;
617
      begin
618
         Par := Scope (S);
619
         while Present (Par) and then Par /= Standard_Standard loop
620
            Set_Is_Immediately_Visible (Par, Visibility);
621
            Par := Scope (Par);
622
         end loop;
623
      end Set_Parents;
624
 
625
   --  Start of processing for Set_Categorization_From_Pragmas
626
 
627
   begin
628
      --  Deal with categorization pragmas in Pragmas of Compilation_Unit.
629
      --  The purpose is to set categorization flags before analyzing the
630
      --  unit itself, so as to diagnose violations of categorization as
631
      --  we process each declaration, even though the pragma appears after
632
      --  the unit.
633
 
634
      if Nkind (P) /= N_Compilation_Unit then
635
         return;
636
      end if;
637
 
638
      declare
639
         PN : Node_Id;
640
 
641
      begin
642
         if Is_Child_Unit (S)
643
           and then Is_Generic_Instance (S)
644
         then
645
            Set_Parents (True);
646
         end if;
647
 
648
         PN := First (Pragmas_After (Aux_Decls_Node (P)));
649
         while Present (PN) loop
650
 
651
            --  Skip implicit types that may have been introduced by
652
            --  previous analysis.
653
 
654
            if Nkind (PN) = N_Pragma then
655
               case Get_Pragma_Id (PN) is
656
                  when Pragma_All_Calls_Remote   |
657
                    Pragma_Preelaborate          |
658
                    Pragma_Pure                  |
659
                    Pragma_Remote_Call_Interface |
660
                    Pragma_Remote_Types          |
661
                    Pragma_Shared_Passive        => Analyze (PN);
662
                  when others                    => null;
663
               end case;
664
            end if;
665
 
666
            Next (PN);
667
         end loop;
668
 
669
         if Is_Child_Unit (S)
670
           and then Is_Generic_Instance (S)
671
         then
672
            Set_Parents (False);
673
         end if;
674
      end;
675
   end Set_Categorization_From_Pragmas;
676
 
677
   -----------------------------------
678
   -- Set_Categorization_From_Scope --
679
   -----------------------------------
680
 
681
   procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
682
      Declaration   : Node_Id := Empty;
683
      Specification : Node_Id := Empty;
684
 
685
   begin
686
      Set_Is_Pure (E,
687
        Is_Pure (Scop) and then Is_Library_Level_Entity (E));
688
 
689
      if not Is_Remote_Call_Interface (E) then
690
         if Ekind (E) in Subprogram_Kind then
691
            Declaration := Unit_Declaration_Node (E);
692
 
693
            if Nkind (Declaration) = N_Subprogram_Body
694
                 or else
695
               Nkind (Declaration) = N_Subprogram_Renaming_Declaration
696
            then
697
               Specification := Corresponding_Spec (Declaration);
698
            end if;
699
         end if;
700
 
701
         --  A subprogram body or renaming-as-body is a remote call
702
         --  interface if it serves as the completion of a subprogram
703
         --  declaration that is a remote call interface.
704
 
705
         if Nkind (Specification) in N_Entity then
706
            Set_Is_Remote_Call_Interface
707
              (E, Is_Remote_Call_Interface (Specification));
708
 
709
         --  A subprogram declaration is a remote call interface when it is
710
         --  declared within the visible part of, or declared by, a library
711
         --  unit declaration that is a remote call interface.
712
 
713
         else
714
            Set_Is_Remote_Call_Interface
715
              (E, Is_Remote_Call_Interface (Scop)
716
                    and then not (In_Private_Part (Scop)
717
                                    or else In_Package_Body (Scop)));
718
         end if;
719
      end if;
720
 
721
      Set_Is_Remote_Types
722
        (E, Is_Remote_Types (Scop)
723
              and then not (In_Private_Part (Scop)
724
                              or else In_Package_Body (Scop)));
725
   end Set_Categorization_From_Scope;
726
 
727
   ------------------------------
728
   -- Static_Discriminant_Expr --
729
   ------------------------------
730
 
731
   --  We need to accommodate a Why_Not_Static call somehow here ???
732
 
733
   function Static_Discriminant_Expr (L : List_Id) return Boolean is
734
      Discriminant_Spec : Node_Id;
735
 
736
   begin
737
      Discriminant_Spec := First (L);
738
      while Present (Discriminant_Spec) loop
739
         if Present (Expression (Discriminant_Spec))
740
           and then not Is_Static_Expression (Expression (Discriminant_Spec))
741
         then
742
            return False;
743
         end if;
744
 
745
         Next (Discriminant_Spec);
746
      end loop;
747
 
748
      return True;
749
   end Static_Discriminant_Expr;
750
 
751
   --------------------------------------
752
   -- Validate_Access_Type_Declaration --
753
   --------------------------------------
754
 
755
   procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
756
      Def : constant Node_Id := Type_Definition (N);
757
 
758
   begin
759
      case Nkind (Def) is
760
 
761
         --  Access to subprogram case
762
 
763
         when N_Access_To_Subprogram_Definition =>
764
 
765
            --  A pure library_item must not contain the declaration of a
766
            --  named access type, except within a subprogram, generic
767
            --  subprogram, task unit, or protected unit (RM 10.2.1(16)).
768
 
769
            --  This test is skipped in Ada 2005 (see AI-366)
770
 
771
            if Ada_Version < Ada_05
772
              and then Comes_From_Source (T)
773
              and then In_Pure_Unit
774
              and then not In_Subprogram_Task_Protected_Unit
775
            then
776
               Error_Msg_N ("named access type not allowed in pure unit", T);
777
            end if;
778
 
779
         --  Access to object case
780
 
781
         when N_Access_To_Object_Definition =>
782
            if Comes_From_Source (T)
783
              and then In_Pure_Unit
784
              and then not In_Subprogram_Task_Protected_Unit
785
            then
786
               --  We can't give the message yet, since the type is not frozen
787
               --  and in Ada 2005 mode, access types are allowed in pure units
788
               --  if the type has no storage pool (see AI-366). So we set a
789
               --  flag which will be checked at freeze time.
790
 
791
               Set_Is_Pure_Unit_Access_Type (T);
792
            end if;
793
 
794
            --  Check for RCI or RT unit type declaration: declaration of an
795
            --  access-to-object type is illegal unless it is a general access
796
            --  type that designates a class-wide limited private type.
797
            --  Note that constraints on the primitive subprograms of the
798
            --  designated tagged type are not enforced here but in
799
            --  Validate_RACW_Primitives, which is done separately because the
800
            --  designated type might not be frozen (and therefore its
801
            --  primitive operations might not be completely known) at the
802
            --  point of the RACW declaration.
803
 
804
            Validate_Remote_Access_Object_Type_Declaration (T);
805
 
806
            --  Check for shared passive unit type declaration. It should
807
            --  not contain the declaration of access to class wide type,
808
            --  access to task type and access to protected type with entry.
809
 
810
            Validate_SP_Access_Object_Type_Decl (T);
811
 
812
         when others =>
813
            null;
814
      end case;
815
 
816
      --  Set categorization flag from package on entity as well, to allow
817
      --  easy checks later on for required validations of RCI or RT units.
818
      --  This is only done for entities that are in the original source.
819
 
820
      if Comes_From_Source (T)
821
        and then not (In_Package_Body (Scope (T))
822
                        or else In_Private_Part (Scope (T)))
823
      then
824
         Set_Is_Remote_Call_Interface
825
           (T, Is_Remote_Call_Interface (Scope (T)));
826
         Set_Is_Remote_Types
827
           (T, Is_Remote_Types (Scope (T)));
828
      end if;
829
   end Validate_Access_Type_Declaration;
830
 
831
   ----------------------------
832
   -- Validate_Ancestor_Part --
833
   ----------------------------
834
 
835
   procedure Validate_Ancestor_Part (N : Node_Id) is
836
      A : constant Node_Id   := Ancestor_Part (N);
837
      T : constant Entity_Id := Entity (A);
838
 
839
   begin
840
      if In_Preelaborated_Unit
841
        and then not In_Subprogram_Or_Concurrent_Unit
842
        and then (not Inside_A_Generic
843
                   or else Present (Enclosing_Generic_Body (N)))
844
      then
845
         --  If the type is private, it must have the Ada 2005 pragma
846
         --  Has_Preelaborable_Initialization.
847
         --  The check is omitted within predefined units. This is probably
848
         --  obsolete code to fix the Ada95 weakness in this area ???
849
 
850
         if Is_Private_Type (T)
851
           and then not Has_Pragma_Preelab_Init (T)
852
           and then not Is_Internal_File_Name
853
                          (Unit_File_Name (Get_Source_Unit (N)))
854
         then
855
            Error_Msg_N
856
              ("private ancestor type not allowed in preelaborated unit", A);
857
 
858
         elsif Is_Record_Type (T) then
859
            if Nkind (Parent (T)) = N_Full_Type_Declaration then
860
               Check_Non_Static_Default_Expr
861
                 (Type_Definition (Parent (T)), A);
862
            end if;
863
         end if;
864
      end if;
865
   end Validate_Ancestor_Part;
866
 
867
   ----------------------------------------
868
   -- Validate_Categorization_Dependency --
869
   ----------------------------------------
870
 
871
   procedure Validate_Categorization_Dependency
872
     (N : Node_Id;
873
      E : Entity_Id)
874
   is
875
      K          : constant Node_Kind := Nkind (N);
876
      P          : Node_Id            := Parent (N);
877
      U          : Entity_Id := E;
878
      Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
879
 
880
   begin
881
      --  Only validate library units and subunits. For subunits, checks
882
      --  concerning withed units apply to the parent compilation unit.
883
 
884
      if Is_Subunit then
885
         P := Parent (P);
886
         U := Scope (E);
887
 
888
         while Present (U)
889
           and then not Is_Compilation_Unit (U)
890
           and then not Is_Child_Unit (U)
891
         loop
892
            U := Scope (U);
893
         end loop;
894
      end if;
895
 
896
      if Nkind (P) /= N_Compilation_Unit then
897
         return;
898
      end if;
899
 
900
      --  Body of RCI unit does not need validation
901
 
902
      if Is_Remote_Call_Interface (E)
903
        and then (Nkind (N) = N_Package_Body
904
                   or else Nkind (N) = N_Subprogram_Body)
905
      then
906
         return;
907
      end if;
908
 
909
      --  Ada 2005 (AI-50217): Process explicit non-limited with_clauses
910
 
911
      declare
912
         Item             : Node_Id;
913
         Entity_Of_Withed : Entity_Id;
914
 
915
      begin
916
         Item := First (Context_Items (P));
917
         while Present (Item) loop
918
            if Nkind (Item) = N_With_Clause
919
              and then not (Implicit_With (Item)
920
                              or else Limited_Present (Item))
921
            then
922
               Entity_Of_Withed := Entity (Name (Item));
923
               Check_Categorization_Dependencies
924
                 (U, Entity_Of_Withed, Item, Is_Subunit);
925
            end if;
926
 
927
            Next (Item);
928
         end loop;
929
      end;
930
 
931
      --  Child depends on parent; therefore parent should also be categorized
932
      --  and satisfy the dependency hierarchy.
933
 
934
      --  Check if N is a child spec
935
 
936
      if (K in N_Generic_Declaration              or else
937
          K in N_Generic_Instantiation            or else
938
          K in N_Generic_Renaming_Declaration     or else
939
          K =  N_Package_Declaration              or else
940
          K =  N_Package_Renaming_Declaration     or else
941
          K =  N_Subprogram_Declaration           or else
942
          K =  N_Subprogram_Renaming_Declaration)
943
        and then Present (Parent_Spec (N))
944
      then
945
         Check_Categorization_Dependencies (E, Scope (E), N, False);
946
 
947
         --  Verify that public child of an RCI library unit must also be an
948
         --  RCI library unit (RM E.2.3(15)).
949
 
950
         if Is_Remote_Call_Interface (Scope (E))
951
           and then not Private_Present (P)
952
           and then not Is_Remote_Call_Interface (E)
953
         then
954
            Error_Msg_N ("public child of rci unit must also be rci unit", N);
955
         end if;
956
      end if;
957
   end Validate_Categorization_Dependency;
958
 
959
   --------------------------------
960
   -- Validate_Controlled_Object --
961
   --------------------------------
962
 
963
   procedure Validate_Controlled_Object (E : Entity_Id) is
964
   begin
965
      --  Don't need this check in Ada 2005 mode, where this is all taken
966
      --  care of by the mechanism for Preelaborable Initialization.
967
 
968
      if Ada_Version >= Ada_05 then
969
         return;
970
      end if;
971
 
972
      --  For now, never apply this check for internal GNAT units, since we
973
      --  have a number of cases in the library where we are stuck with objects
974
      --  of this type, and the RM requires Preelaborate.
975
 
976
      --  For similar reasons, we only do this check for source entities, since
977
      --  we generate entities of this type in some situations.
978
 
979
      --  Note that the 10.2.1(9) restrictions are not relevant to us anyway.
980
      --  We have to enforce them for RM compatibility, but we have no trouble
981
      --  accepting these objects and doing the right thing. Note that there is
982
      --  no requirement that Preelaborate not actually generate any code!
983
 
984
      if In_Preelaborated_Unit
985
        and then not Debug_Flag_PP
986
        and then Comes_From_Source (E)
987
        and then not
988
          Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
989
        and then (not Inside_A_Generic
990
                   or else Present (Enclosing_Generic_Body (E)))
991
        and then not Is_Protected_Type (Etype (E))
992
      then
993
         Error_Msg_N
994
           ("library level controlled object not allowed in " &
995
            "preelaborated unit", E);
996
      end if;
997
   end Validate_Controlled_Object;
998
 
999
   --------------------------------------
1000
   -- Validate_Null_Statement_Sequence --
1001
   --------------------------------------
1002
 
1003
   procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1004
      Item : Node_Id;
1005
 
1006
   begin
1007
      if In_Preelaborated_Unit then
1008
         Item := First (Statements (Handled_Statement_Sequence (N)));
1009
         while Present (Item) loop
1010
            if Nkind (Item) /= N_Label
1011
              and then Nkind (Item) /= N_Null_Statement
1012
            then
1013
               --  In GNAT mode, this is a warning, allowing the run-time
1014
               --  to judiciously bypass this error condition.
1015
 
1016
               Error_Msg_Warn := GNAT_Mode;
1017
               Error_Msg_N
1018
                 ("<statements not allowed in preelaborated unit", Item);
1019
 
1020
               exit;
1021
            end if;
1022
 
1023
            Next (Item);
1024
         end loop;
1025
      end if;
1026
   end Validate_Null_Statement_Sequence;
1027
 
1028
   ---------------------------------
1029
   -- Validate_Object_Declaration --
1030
   ---------------------------------
1031
 
1032
   procedure Validate_Object_Declaration (N : Node_Id) is
1033
      Id  : constant Entity_Id  := Defining_Identifier (N);
1034
      E   : constant Node_Id    := Expression (N);
1035
      Odf : constant Node_Id    := Object_Definition (N);
1036
      T   : constant Entity_Id  := Etype (Id);
1037
 
1038
   begin
1039
      --  Verify that any access to subprogram object does not have in its
1040
      --  subprogram profile access type parameters or limited parameters
1041
      --  without Read and Write attributes (E.2.3(13)).
1042
 
1043
      Validate_RCI_Subprogram_Declaration (N);
1044
 
1045
      --  Check that if we are in preelaborated elaboration code, then we
1046
      --  do not have an instance of a default initialized private, task or
1047
      --  protected object declaration which would violate (RM 10.2.1(9)).
1048
      --  Note that constants are never default initialized (and the test
1049
      --  below also filters out deferred constants). A variable is default
1050
      --  initialized if it does *not* have an initialization expression.
1051
 
1052
      --  Filter out cases that are not declaration of a variable from source
1053
 
1054
      if Nkind (N) /= N_Object_Declaration
1055
        or else Constant_Present (N)
1056
        or else not Comes_From_Source (Id)
1057
      then
1058
         return;
1059
      end if;
1060
 
1061
      --  Exclude generic specs from the checks (this will get rechecked
1062
      --  on instantiations).
1063
 
1064
      if Inside_A_Generic
1065
        and then No (Enclosing_Generic_Body (Id))
1066
      then
1067
         return;
1068
      end if;
1069
 
1070
      --  Required checks for declaration that is in a preelaborated
1071
      --  package and is not within some subprogram.
1072
 
1073
      if In_Preelaborated_Unit
1074
        and then not In_Subprogram_Or_Concurrent_Unit
1075
      then
1076
         --  Check for default initialized variable case. Note that in
1077
         --  accordance with (RM B.1(24)) imported objects are not
1078
         --  subject to default initialization.
1079
         --  If the initialization does not come from source and is an
1080
         --  aggregate, it is a static initialization that replaces an
1081
         --  implicit call, and must be treated as such.
1082
 
1083
         if Present (E)
1084
           and then
1085
            (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1086
         then
1087
            null;
1088
 
1089
         elsif Is_Imported (Id) then
1090
            null;
1091
 
1092
         else
1093
            declare
1094
               Ent : Entity_Id := T;
1095
 
1096
            begin
1097
               --  An array whose component type is a record with nonstatic
1098
               --  default expressions is a violation, so we get the array's
1099
               --  component type.
1100
 
1101
               if Is_Array_Type (Ent) then
1102
                  declare
1103
                     Comp_Type : Entity_Id;
1104
 
1105
                  begin
1106
                     Comp_Type := Component_Type (Ent);
1107
                     while Is_Array_Type (Comp_Type) loop
1108
                        Comp_Type := Component_Type (Comp_Type);
1109
                     end loop;
1110
 
1111
                     Ent := Comp_Type;
1112
                  end;
1113
               end if;
1114
 
1115
               --  Object decl. that is of record type and has no default expr.
1116
               --  should check if there is any non-static default expression
1117
               --  in component decl. of the record type decl.
1118
 
1119
               if Is_Record_Type (Ent) then
1120
                  if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1121
                     Check_Non_Static_Default_Expr
1122
                       (Type_Definition (Parent (Ent)), N);
1123
 
1124
                  elsif Nkind (Odf) = N_Subtype_Indication
1125
                    and then not Is_Array_Type (T)
1126
                    and then not Is_Private_Type (T)
1127
                  then
1128
                     Check_Non_Static_Default_Expr (Type_Definition
1129
                       (Parent (Entity (Subtype_Mark (Odf)))), N);
1130
                  end if;
1131
               end if;
1132
 
1133
               --  Check for invalid use of private object. Note that Ada 2005
1134
               --  AI-161 modifies the rules for Ada 2005, including the use of
1135
               --  the new pragma Preelaborable_Initialization.
1136
 
1137
               if Is_Private_Type (Ent)
1138
                 or else Depends_On_Private (Ent)
1139
               then
1140
                  --  Case where type has preelaborable initialization which
1141
                  --  means that a pragma Preelaborable_Initialization was
1142
                  --  given for the private type.
1143
 
1144
                  if Has_Preelaborable_Initialization (Ent) then
1145
 
1146
                     --  But for the predefined units, we will ignore this
1147
                     --  status unless we are in Ada 2005 mode since we want
1148
                     --  Ada 95 compatible behavior, in which the entities
1149
                     --  marked with this pragma in the predefined library are
1150
                     --  not treated specially.
1151
 
1152
                     if Ada_Version < Ada_05 then
1153
                        Error_Msg_N
1154
                          ("private object not allowed in preelaborated unit",
1155
                           N);
1156
                        Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1157
                     end if;
1158
 
1159
                  --  Type does not have preelaborable initialization
1160
 
1161
                  else
1162
                     --  We allow this when compiling in GNAT mode to make life
1163
                     --  easier for some cases where it would otherwise be hard
1164
                     --  to be exactly valid Ada.
1165
 
1166
                     if not GNAT_Mode then
1167
                        Error_Msg_N
1168
                          ("private object not allowed in preelaborated unit",
1169
                           N);
1170
 
1171
                        --  Add a message if it would help to provide a pragma
1172
                        --  Preelaborable_Initialization on the type of the
1173
                        --  object (which would make it legal in Ada 2005).
1174
 
1175
                        --  If the type has no full view (generic type, or
1176
                        --  previous error), the warning does not apply.
1177
 
1178
                        if Is_Private_Type (Ent)
1179
                          and then Present (Full_View (Ent))
1180
                          and then
1181
                            Has_Preelaborable_Initialization (Full_View (Ent))
1182
                        then
1183
                           Error_Msg_Sloc := Sloc (Ent);
1184
 
1185
                           if Ada_Version >= Ada_05 then
1186
                              Error_Msg_NE
1187
                                ("\would be legal if pragma Preelaborable_" &
1188
                                 "Initialization given for & #", N, Ent);
1189
                           else
1190
                              Error_Msg_NE
1191
                                ("\would be legal in Ada 2005 if pragma " &
1192
                                 "Preelaborable_Initialization given for & #",
1193
                                 N, Ent);
1194
                           end if;
1195
                        end if;
1196
                     end if;
1197
                  end if;
1198
 
1199
               --  Access to Task or Protected type
1200
 
1201
               elsif Is_Entity_Name (Odf)
1202
                 and then Present (Etype (Odf))
1203
                 and then Is_Access_Type (Etype (Odf))
1204
               then
1205
                  Ent := Designated_Type (Etype (Odf));
1206
 
1207
               elsif Is_Entity_Name (Odf) then
1208
                  Ent := Entity (Odf);
1209
 
1210
               elsif Nkind (Odf) = N_Subtype_Indication then
1211
                  Ent := Etype (Subtype_Mark (Odf));
1212
 
1213
               elsif
1214
                  Nkind (Odf) = N_Constrained_Array_Definition
1215
               then
1216
                  Ent := Component_Type (T);
1217
 
1218
               --  else
1219
               --     return;
1220
               end if;
1221
 
1222
               if Is_Task_Type (Ent)
1223
                 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1224
               then
1225
                  Error_Msg_N
1226
                    ("concurrent object not allowed in preelaborated unit",
1227
                     N);
1228
                  return;
1229
               end if;
1230
            end;
1231
         end if;
1232
 
1233
         --  Non-static discriminant not allowed in preelaborated unit
1234
         --  Controlled object of a type with a user-defined Initialize
1235
         --  is forbidden as well.
1236
 
1237
         if Is_Record_Type (Etype (Id)) then
1238
            declare
1239
               ET  : constant Entity_Id := Etype (Id);
1240
               EE  : constant Entity_Id := Etype (Etype (Id));
1241
               PEE : Node_Id;
1242
 
1243
            begin
1244
               if Has_Discriminants (ET)
1245
                 and then Present (EE)
1246
               then
1247
                  PEE := Parent (EE);
1248
 
1249
                  if Nkind (PEE) = N_Full_Type_Declaration
1250
                    and then not Static_Discriminant_Expr
1251
                                  (Discriminant_Specifications (PEE))
1252
                  then
1253
                     Error_Msg_N
1254
                       ("non-static discriminant in preelaborated unit",
1255
                        PEE);
1256
                  end if;
1257
               end if;
1258
 
1259
               if Has_Overriding_Initialize (ET) then
1260
                  Error_Msg_NE
1261
                    ("controlled type& does not have"
1262
                      & " preelaborable initialization", N, ET);
1263
               end if;
1264
            end;
1265
 
1266
         end if;
1267
      end if;
1268
 
1269
      --  A pure library_item must not contain the declaration of any variable
1270
      --  except within a subprogram, generic subprogram, task unit, or
1271
      --  protected unit (RM 10.2.1(16)).
1272
 
1273
      if In_Pure_Unit
1274
        and then not In_Subprogram_Task_Protected_Unit
1275
      then
1276
         Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1277
 
1278
      --  The visible part of an RCI library unit must not contain the
1279
      --  declaration of a variable (RM E.1.3(9))
1280
 
1281
      elsif In_RCI_Declaration (N) then
1282
         Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1283
 
1284
      --  The visible part of a Shared Passive library unit must not contain
1285
      --  the declaration of a variable (RM E.2.2(7))
1286
 
1287
      elsif In_RT_Declaration then
1288
         Error_Msg_N
1289
           ("variable declaration not allowed in remote types unit", N);
1290
      end if;
1291
 
1292
   end Validate_Object_Declaration;
1293
 
1294
   ------------------------------
1295
   -- Validate_RACW_Primitives --
1296
   ------------------------------
1297
 
1298
   procedure Validate_RACW_Primitives (T : Entity_Id) is
1299
      Desig_Type             : Entity_Id;
1300
      Primitive_Subprograms  : Elist_Id;
1301
      Subprogram_Elmt        : Elmt_Id;
1302
      Subprogram             : Entity_Id;
1303
      Param_Spec             : Node_Id;
1304
      Param                  : Entity_Id;
1305
      Param_Type             : Entity_Id;
1306
      Rtyp                   : Node_Id;
1307
 
1308
      procedure Illegal_RACW (Msg : String; N : Node_Id);
1309
      --  Diagnose that T is illegal because of the given reason, associated
1310
      --  with the location of node N.
1311
 
1312
      Illegal_RACW_Message_Issued : Boolean := False;
1313
      --  Set True once Illegal_RACW has been called
1314
 
1315
      ------------------
1316
      -- Illegal_RACW --
1317
      ------------------
1318
 
1319
      procedure Illegal_RACW (Msg : String; N : Node_Id) is
1320
      begin
1321
         if not Illegal_RACW_Message_Issued then
1322
            Error_Msg_N
1323
              ("illegal remote access to class-wide type&", T);
1324
            Illegal_RACW_Message_Issued := True;
1325
         end if;
1326
 
1327
         Error_Msg_Sloc := Sloc (N);
1328
         Error_Msg_N ("\\" & Msg & " in primitive#", T);
1329
      end Illegal_RACW;
1330
 
1331
   --  Start of processing for Validate_RACW_Primitives
1332
 
1333
   begin
1334
      Desig_Type := Etype (Designated_Type (T));
1335
 
1336
      Primitive_Subprograms := Primitive_Operations (Desig_Type);
1337
 
1338
      Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1339
      while Subprogram_Elmt /= No_Elmt loop
1340
         Subprogram := Node (Subprogram_Elmt);
1341
 
1342
         if Is_Predefined_Dispatching_Operation (Subprogram)
1343
           or else Is_Hidden (Subprogram)
1344
         then
1345
            goto Next_Subprogram;
1346
         end if;
1347
 
1348
         --  Check return type
1349
 
1350
         if Ekind (Subprogram) = E_Function then
1351
            Rtyp := Etype (Subprogram);
1352
 
1353
            if Has_Controlling_Result (Subprogram) then
1354
               null;
1355
 
1356
            elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1357
               Illegal_RACW ("anonymous access result", Rtyp);
1358
 
1359
            elsif Is_Limited_Type (Rtyp) then
1360
               if No (TSS (Rtyp, TSS_Stream_Read))
1361
                    or else
1362
                  No (TSS (Rtyp, TSS_Stream_Write))
1363
               then
1364
                  Illegal_RACW
1365
                    ("limited return type must have Read and Write attributes",
1366
                     Parent (Subprogram));
1367
                  Explain_Limited_Type (Rtyp, Parent (Subprogram));
1368
 
1369
               --  Check that the return type supports external streaming.
1370
               --  Note that the language of the standard (E.2.2(14)) does not
1371
               --  explicitly mention that case, but it really does not make
1372
               --  sense to return a value containing a local access type.
1373
 
1374
               elsif Missing_Read_Write_Attributes (Rtyp)
1375
                       and then not Error_Posted (Rtyp)
1376
               then
1377
                  Illegal_RACW ("return type containing non-remote access "
1378
                    & "must have Read and Write attributes",
1379
                    Parent (Subprogram));
1380
               end if;
1381
 
1382
            end if;
1383
         end if;
1384
 
1385
         Param := First_Formal (Subprogram);
1386
         while Present (Param) loop
1387
 
1388
            --  Now find out if this parameter is a controlling parameter
1389
 
1390
            Param_Spec := Parent (Param);
1391
            Param_Type := Etype (Param);
1392
 
1393
            if Is_Controlling_Formal (Param) then
1394
 
1395
               --  It is a controlling parameter, so specific checks below
1396
               --  do not apply.
1397
 
1398
               null;
1399
 
1400
            elsif Ekind (Param_Type) = E_Anonymous_Access_Type
1401
              or else Ekind (Param_Type) = E_Anonymous_Access_Subprogram_Type
1402
            then
1403
               --  From RM E.2.2(14), no anonymous access parameter other than
1404
               --  controlling ones may be used (because an anonymous access
1405
               --  type never supports external streaming).
1406
 
1407
               Illegal_RACW ("non-controlling access parameter", Param_Spec);
1408
 
1409
            elsif Is_Limited_Type (Param_Type) then
1410
 
1411
               --  Not a controlling parameter, so type must have Read and
1412
               --  Write attributes.
1413
 
1414
               if No (TSS (Param_Type, TSS_Stream_Read))
1415
                    or else
1416
                  No (TSS (Param_Type, TSS_Stream_Write))
1417
               then
1418
                  Illegal_RACW
1419
                    ("limited formal must have Read and Write attributes",
1420
                     Param_Spec);
1421
                  Explain_Limited_Type (Param_Type, Param_Spec);
1422
               end if;
1423
 
1424
            elsif Missing_Read_Write_Attributes (Param_Type)
1425
               and then not Error_Posted (Param_Type)
1426
            then
1427
               Illegal_RACW ("parameter containing non-remote access "
1428
                 & "must have Read and Write attributes", Param_Spec);
1429
            end if;
1430
 
1431
            --  Check next parameter in this subprogram
1432
 
1433
            Next_Formal (Param);
1434
         end loop;
1435
 
1436
         <<Next_Subprogram>>
1437
            Next_Elmt (Subprogram_Elmt);
1438
      end loop;
1439
   end Validate_RACW_Primitives;
1440
 
1441
   -------------------------------
1442
   -- Validate_RCI_Declarations --
1443
   -------------------------------
1444
 
1445
   procedure Validate_RCI_Declarations (P : Entity_Id) is
1446
      E : Entity_Id;
1447
 
1448
   begin
1449
      E := First_Entity (P);
1450
      while Present (E) loop
1451
         if Comes_From_Source (E) then
1452
            if Is_Limited_Type (E) then
1453
               Error_Msg_N
1454
                 ("limited type not allowed in rci unit", Parent (E));
1455
               Explain_Limited_Type (E, Parent (E));
1456
 
1457
            elsif Ekind (E) = E_Generic_Function
1458
              or else Ekind (E) = E_Generic_Package
1459
              or else Ekind (E) = E_Generic_Procedure
1460
            then
1461
               Error_Msg_N ("generic declaration not allowed in rci unit",
1462
                 Parent (E));
1463
 
1464
            elsif (Ekind (E) = E_Function
1465
                    or else Ekind (E) = E_Procedure)
1466
              and then Has_Pragma_Inline (E)
1467
            then
1468
               Error_Msg_N
1469
                 ("inlined subprogram not allowed in rci unit", Parent (E));
1470
 
1471
            --  Inner packages that are renamings need not be checked. Generic
1472
            --  RCI packages are subject to the checks, but entities that come
1473
            --  from formal packages are not part of the visible declarations
1474
            --  of the package and are not checked.
1475
 
1476
            elsif Ekind (E) = E_Package then
1477
               if Present (Renamed_Entity (E)) then
1478
                  null;
1479
 
1480
               elsif Ekind (P) /= E_Generic_Package
1481
                 or else List_Containing (Unit_Declaration_Node (E)) /=
1482
                           Generic_Formal_Declarations
1483
                             (Unit_Declaration_Node (P))
1484
               then
1485
                  Validate_RCI_Declarations (E);
1486
               end if;
1487
            end if;
1488
         end if;
1489
 
1490
         Next_Entity (E);
1491
      end loop;
1492
   end Validate_RCI_Declarations;
1493
 
1494
   -----------------------------------------
1495
   -- Validate_RCI_Subprogram_Declaration --
1496
   -----------------------------------------
1497
 
1498
   procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1499
      K               : constant Node_Kind := Nkind (N);
1500
      Profile         : List_Id;
1501
      Id              : Node_Id;
1502
      Param_Spec      : Node_Id;
1503
      Param_Type      : Entity_Id;
1504
      Base_Param_Type : Entity_Id;
1505
      Base_Under_Type : Entity_Id;
1506
      Type_Decl       : Node_Id;
1507
      Error_Node      : Node_Id := N;
1508
 
1509
   begin
1510
      --  This procedure enforces rules on subprogram and access to subprogram
1511
      --  declarations in RCI units. These rules do not apply to expander
1512
      --  generated routines, which are not remote subprograms. It is called:
1513
 
1514
      --    1. from Analyze_Subprogram_Declaration.
1515
      --    2. from Validate_Object_Declaration (access to subprogram).
1516
 
1517
      if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then
1518
         return;
1519
      end if;
1520
 
1521
      if K = N_Subprogram_Declaration then
1522
         Profile := Parameter_Specifications (Specification (N));
1523
 
1524
      else pragma Assert (K = N_Object_Declaration);
1525
 
1526
         --  The above assertion is dubious, the visible declarations of an
1527
         --  RCI unit never contain an object declaration, this should be an
1528
         --  ACCESS-to-object declaration???
1529
 
1530
         Id := Defining_Identifier (N);
1531
 
1532
         if Nkind (Id) = N_Defining_Identifier
1533
           and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1534
           and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1535
         then
1536
            Profile :=
1537
              Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1538
         else
1539
            return;
1540
         end if;
1541
      end if;
1542
 
1543
      --  Iterate through the parameter specification list, checking that
1544
      --  no access parameter and no limited type parameter in the list.
1545
      --  RM E.2.3(14).
1546
 
1547
      if Present (Profile) then
1548
         Param_Spec := First (Profile);
1549
         while Present (Param_Spec) loop
1550
            Param_Type := Etype (Defining_Identifier (Param_Spec));
1551
            Type_Decl  := Parent (Param_Type);
1552
 
1553
            if Ekind (Param_Type) = E_Anonymous_Access_Type then
1554
 
1555
               if K = N_Subprogram_Declaration then
1556
                  Error_Node := Param_Spec;
1557
               end if;
1558
 
1559
               --  Report error only if declaration is in source program
1560
 
1561
               if Comes_From_Source
1562
                 (Defining_Entity (Specification (N)))
1563
               then
1564
                  Error_Msg_N
1565
                    ("subprogram in 'R'C'I unit cannot have access parameter",
1566
                      Error_Node);
1567
               end if;
1568
 
1569
            --  For a limited private type parameter, we check only the private
1570
            --  declaration and ignore full type declaration, unless this is
1571
            --  the only declaration for the type, e.g., as a limited record.
1572
 
1573
            elsif Is_Limited_Type (Param_Type)
1574
              and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1575
                         or else
1576
                        (Nkind (Type_Decl) = N_Full_Type_Declaration
1577
                          and then not (Has_Private_Declaration (Param_Type))
1578
                          and then Comes_From_Source (N)))
1579
            then
1580
               --  A limited parameter is legal only if user-specified Read and
1581
               --  Write attributes exist for it. Second part of RM E.2.3 (14).
1582
 
1583
               if No (Full_View (Param_Type))
1584
                 and then Ekind (Param_Type) /= E_Record_Type
1585
               then
1586
                  --  Type does not have completion yet, so if declared in
1587
                  --  the current RCI scope it is illegal, and will be flagged
1588
                  --  subsequently.
1589
 
1590
                  return;
1591
               end if;
1592
 
1593
               --  In Ada 95 the rules permit using a limited type that has
1594
               --  user-specified Read and Write attributes that are specified
1595
               --  in the private part of the package, whereas Ada 2005
1596
               --  (AI-240) revises this to require the attributes to be
1597
               --  "available" (implying that the attribute clauses must be
1598
               --  visible to the RCI client). The Ada 95 rules violate the
1599
               --  contract model for privacy, but we support both semantics
1600
               --  for now for compatibility (note that ACATS test BXE2009
1601
               --  checks a case that conforms to the Ada 95 rules but is
1602
               --  illegal in Ada 2005). In the Ada 2005 case we check for the
1603
               --  possibilities of visible TSS stream subprograms or explicit
1604
               --  stream attribute definitions because the TSS subprograms
1605
               --  can be hidden in the private part while the attribute
1606
               --  definitions are still be available from the visible part.
1607
 
1608
               Base_Param_Type := Base_Type (Param_Type);
1609
               Base_Under_Type := Base_Type (Underlying_Type
1610
                                              (Base_Param_Type));
1611
 
1612
               if (Ada_Version < Ada_05
1613
                     and then
1614
                       (No (TSS (Base_Param_Type, TSS_Stream_Read))
1615
                          or else
1616
                        No (TSS (Base_Param_Type, TSS_Stream_Write)))
1617
                     and then
1618
                       (No (TSS (Base_Under_Type, TSS_Stream_Read))
1619
                          or else
1620
                        No (TSS (Base_Under_Type, TSS_Stream_Write))))
1621
                 or else
1622
                   (Ada_Version >= Ada_05
1623
                      and then
1624
                        (No (TSS (Base_Param_Type, TSS_Stream_Read))
1625
                           or else
1626
                         No (TSS (Base_Param_Type, TSS_Stream_Write))
1627
                           or else
1628
                         Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1629
                           or else
1630
                         Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write)))
1631
                      and then
1632
                        (not Has_Stream_Attribute_Definition
1633
                               (Base_Param_Type, TSS_Stream_Read)
1634
                           or else
1635
                         not Has_Stream_Attribute_Definition
1636
                               (Base_Param_Type, TSS_Stream_Write)))
1637
               then
1638
                  if K = N_Subprogram_Declaration then
1639
                     Error_Node := Param_Spec;
1640
                  end if;
1641
 
1642
                  if Ada_Version >= Ada_05 then
1643
                     Error_Msg_N
1644
                       ("limited parameter in 'R'C'I unit "
1645
                          & "must have visible read/write attributes ",
1646
                        Error_Node);
1647
                  else
1648
                     Error_Msg_N
1649
                       ("limited parameter in 'R'C'I unit "
1650
                          & "must have read/write attributes ",
1651
                        Error_Node);
1652
                  end if;
1653
                  Explain_Limited_Type (Param_Type, Error_Node);
1654
               end if;
1655
 
1656
            --  In Ada 95, any non-remote access type (or any type with a
1657
            --  component of a non-remote access type) that is visible in an
1658
            --  RCI unit comes from a Remote_Types or Remote_Call_Interface
1659
            --  unit, and thus is already guaranteed to support external
1660
            --  streaming. However in Ada 2005 we have to account for the case
1661
            --  of named access types from declared pure units as well, which
1662
            --  may or may not support external streaming, and so we need to
1663
            --  perform a specific check for E.2.3(14/2) here.
1664
 
1665
            --  Note that if the declaration of the type itself is illegal, we
1666
            --  do not perform this check since it might be a cascaded error.
1667
 
1668
            else
1669
               if K = N_Subprogram_Declaration then
1670
                  Error_Node := Param_Spec;
1671
               end if;
1672
 
1673
               if Missing_Read_Write_Attributes (Param_Type)
1674
                    and then not Error_Posted (Param_Type)
1675
               then
1676
                  Error_Msg_N
1677
                    ("parameter containing non-remote access in 'R'C'I "
1678
                     & "subprogram must have visible "
1679
                     & "Read and Write attributes", Error_Node);
1680
               end if;
1681
            end if;
1682
            Next (Param_Spec);
1683
         end loop;
1684
 
1685
         --  No check on return type???
1686
      end if;
1687
   end Validate_RCI_Subprogram_Declaration;
1688
 
1689
   ----------------------------------------------------
1690
   -- Validate_Remote_Access_Object_Type_Declaration --
1691
   ----------------------------------------------------
1692
 
1693
   procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1694
 
1695
      function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean;
1696
      --  True if tagged type E is a valid candidate as the root type of the
1697
      --  designated type for a RACW, i.e. a tagged limited private type, or a
1698
      --  limited interface type, or a private extension of such a type.
1699
 
1700
      ---------------------------------
1701
      -- Is_Valid_Remote_Object_Type --
1702
      ---------------------------------
1703
 
1704
      function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is
1705
         P : constant Node_Id := Parent (E);
1706
 
1707
      begin
1708
         pragma Assert (Is_Tagged_Type (E));
1709
 
1710
         --  Simple case: a limited private type
1711
 
1712
         if Nkind (P) = N_Private_Type_Declaration
1713
           and then Is_Limited_Record (E)
1714
         then
1715
            return True;
1716
 
1717
         --  A limited interface is not currently a legal ancestor for the
1718
         --  designated type of an RACW type, because a type that implements
1719
         --  such an interface need not be limited. However, the ARG seems to
1720
         --  incline towards allowing an access to classwide limited interface
1721
         --  type as a remote access type, as resolved in AI05-060. But note
1722
         --  that the expansion circuitry for RACWs that designate classwide
1723
         --  interfaces is not complete yet.
1724
 
1725
         elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then
1726
            return True;
1727
 
1728
         --  A generic tagged limited type is a valid candidate. Limitedness
1729
         --  will be checked again on the actual at instantiation point.
1730
 
1731
         elsif Nkind (P) = N_Formal_Type_Declaration
1732
           and then Ekind (E) = E_Record_Type_With_Private
1733
           and then Is_Generic_Type (E)
1734
           and then Is_Limited_Record (E)
1735
         then
1736
            return True;
1737
 
1738
         --  A private extension declaration is a valid candidate if its parent
1739
         --  type is.
1740
 
1741
         elsif Nkind (P) = N_Private_Extension_Declaration then
1742
            return Is_Valid_Remote_Object_Type (Etype (E));
1743
 
1744
         else
1745
            return False;
1746
         end if;
1747
      end Is_Valid_Remote_Object_Type;
1748
 
1749
      --  Local variables
1750
 
1751
      Direct_Designated_Type : Entity_Id;
1752
      Desig_Type             : Entity_Id;
1753
 
1754
   --  Start of processing for Validate_Remote_Access_Object_Type_Declaration
1755
 
1756
   begin
1757
      --  We are called from Analyze_Type_Declaration, and the Nkind of the
1758
      --  given node is N_Access_To_Object_Definition.
1759
 
1760
      if not Comes_From_Source (T)
1761
        or else (not In_RCI_Declaration (Parent (T))
1762
                   and then not In_RT_Declaration)
1763
      then
1764
         return;
1765
      end if;
1766
 
1767
      --  An access definition in the private part of a Remote Types package
1768
      --  may be legal if it has user-defined Read and Write attributes. This
1769
      --  will be checked at the end of the package spec processing.
1770
 
1771
      if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1772
         return;
1773
      end if;
1774
 
1775
      --  Check RCI or RT unit type declaration. It may not contain the
1776
      --  declaration of an access-to-object type unless it is a general access
1777
      --  type that designates a class-wide limited private type or subtype.
1778
      --  There are also constraints on the primitive subprograms of the
1779
      --  class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1780
 
1781
      if Ekind (T) /= E_General_Access_Type
1782
        or else not Is_Class_Wide_Type (Designated_Type (T))
1783
      then
1784
         if In_RCI_Declaration (Parent (T)) then
1785
            Error_Msg_N
1786
              ("error in access type in Remote_Call_Interface unit", T);
1787
         else
1788
            Error_Msg_N
1789
              ("error in access type in Remote_Types unit", T);
1790
         end if;
1791
 
1792
         Error_Msg_N ("\must be general access to class-wide type", T);
1793
         return;
1794
      end if;
1795
 
1796
      Direct_Designated_Type := Designated_Type (T);
1797
      Desig_Type := Etype (Direct_Designated_Type);
1798
 
1799
      --  Why is the check below not in
1800
      --  Validate_Remote_Access_To_Class_Wide_Type???
1801
 
1802
      if not Is_Valid_Remote_Object_Type (Desig_Type) then
1803
         Error_Msg_N
1804
           ("error in designated type of remote access to class-wide type", T);
1805
         Error_Msg_N
1806
           ("\must be tagged limited private or private extension", T);
1807
         return;
1808
      end if;
1809
   end Validate_Remote_Access_Object_Type_Declaration;
1810
 
1811
   -----------------------------------------------
1812
   -- Validate_Remote_Access_To_Class_Wide_Type --
1813
   -----------------------------------------------
1814
 
1815
   procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1816
      K  : constant Node_Kind := Nkind (N);
1817
      PK : constant Node_Kind := Nkind (Parent (N));
1818
      E  : Entity_Id;
1819
 
1820
   begin
1821
      --  This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1822
      --  of class-wide limited private types.
1823
 
1824
      --    Storage_Pool and Storage_Size are not defined for such types
1825
      --
1826
      --    The expected type of allocator must not be such a type.
1827
 
1828
      --    The actual parameter of generic instantiation must not be such a
1829
      --    type if the formal parameter is of an access type.
1830
 
1831
      --  On entry, there are five cases
1832
 
1833
      --    1. called from sem_attr Analyze_Attribute where attribute name is
1834
      --       either Storage_Pool or Storage_Size.
1835
 
1836
      --    2. called from exp_ch4 Expand_N_Allocator
1837
 
1838
      --    3. called from sem_ch12 Analyze_Associations
1839
 
1840
      --    4. called from sem_ch4 Analyze_Explicit_Dereference
1841
 
1842
      --    5. called from sem_res Resolve_Actuals
1843
 
1844
      if K = N_Attribute_Reference then
1845
         E := Etype (Prefix (N));
1846
 
1847
         if Is_Remote_Access_To_Class_Wide_Type (E) then
1848
            Error_Msg_N ("incorrect attribute of remote operand", N);
1849
            return;
1850
         end if;
1851
 
1852
      elsif K = N_Allocator then
1853
         E := Etype (N);
1854
 
1855
         if Is_Remote_Access_To_Class_Wide_Type (E) then
1856
            Error_Msg_N ("incorrect expected remote type of allocator", N);
1857
            return;
1858
         end if;
1859
 
1860
      elsif K in N_Has_Entity then
1861
         E := Entity (N);
1862
 
1863
         if Is_Remote_Access_To_Class_Wide_Type (E) then
1864
            Error_Msg_N ("incorrect remote type generic actual", N);
1865
            return;
1866
         end if;
1867
 
1868
      --  This subprogram also enforces the checks in E.2.2(13). A value of
1869
      --  such type must not be dereferenced unless as controlling operand of
1870
      --  a dispatching call. Explicit dereferences not coming from source are
1871
      --  exempted from this checking because the expander produces them in
1872
      --  some cases (such as for tag checks on dispatching calls with multiple
1873
      --  controlling operands). However we do check in the case of an implicit
1874
      --  dereference that is expanded to an explicit dereference (hence the
1875
      --  test of whether Original_Node (N) comes from source).
1876
 
1877
      elsif K = N_Explicit_Dereference
1878
        and then Comes_From_Source (Original_Node (N))
1879
      then
1880
         E := Etype (Prefix (N));
1881
 
1882
         --  If the class-wide type is not a remote one, the restrictions
1883
         --  do not apply.
1884
 
1885
         if not Is_Remote_Access_To_Class_Wide_Type (E) then
1886
            return;
1887
         end if;
1888
 
1889
         --  If we have a true dereference that comes from source and that
1890
         --  is a controlling argument for a dispatching call, accept it.
1891
 
1892
         if Is_Actual_Parameter (N)
1893
           and then Is_Controlling_Actual (N)
1894
         then
1895
            return;
1896
         end if;
1897
 
1898
         --  If we are just within a procedure or function call and the
1899
         --  dereference has not been analyzed, return because this procedure
1900
         --  will be called again from sem_res Resolve_Actuals. The same can
1901
         --  apply in the case of dereference that is the prefix of a selected
1902
         --  component, which can be a call given in prefixed form.
1903
 
1904
         if (Is_Actual_Parameter (N)
1905
              or else PK = N_Selected_Component)
1906
           and then not Analyzed (N)
1907
         then
1908
            return;
1909
         end if;
1910
 
1911
         --  We must allow expanded code to generate a reference to the tag of
1912
         --  the designated object (may be either the actual tag, or the stub
1913
         --  tag in the case of a remote object).
1914
 
1915
         if PK = N_Selected_Component
1916
           and then Is_Tag (Entity (Selector_Name (Parent (N))))
1917
         then
1918
            return;
1919
         end if;
1920
 
1921
         Error_Msg_N
1922
           ("invalid dereference of a remote access-to-class-wide value", N);
1923
      end if;
1924
   end Validate_Remote_Access_To_Class_Wide_Type;
1925
 
1926
   ------------------------------------------
1927
   -- Validate_Remote_Type_Type_Conversion --
1928
   ------------------------------------------
1929
 
1930
   procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1931
      S : constant Entity_Id := Etype (N);
1932
      E : constant Entity_Id := Etype (Expression (N));
1933
 
1934
   begin
1935
      --  This test is required in the case where a conversion appears inside a
1936
      --  normal package, it does not necessarily have to be inside an RCI,
1937
      --  Remote_Types unit (RM E.2.2(9,12)).
1938
 
1939
      if Is_Remote_Access_To_Subprogram_Type (E)
1940
        and then not Is_Remote_Access_To_Subprogram_Type (S)
1941
      then
1942
         Error_Msg_N
1943
           ("incorrect conversion of remote operand to local type", N);
1944
         return;
1945
 
1946
      elsif not Is_Remote_Access_To_Subprogram_Type (E)
1947
        and then Is_Remote_Access_To_Subprogram_Type (S)
1948
      then
1949
         Error_Msg_N
1950
           ("incorrect conversion of local operand to remote type", N);
1951
         return;
1952
 
1953
      elsif Is_Remote_Access_To_Class_Wide_Type (E)
1954
        and then not Is_Remote_Access_To_Class_Wide_Type (S)
1955
      then
1956
         Error_Msg_N
1957
           ("incorrect conversion of remote operand to local type", N);
1958
         return;
1959
      end if;
1960
 
1961
      --  If a local access type is converted into a RACW type, then the
1962
      --  current unit has a pointer that may now be exported to another
1963
      --  partition.
1964
 
1965
      if Is_Remote_Access_To_Class_Wide_Type (S)
1966
        and then not Is_Remote_Access_To_Class_Wide_Type (E)
1967
      then
1968
         Set_Has_RACW (Current_Sem_Unit);
1969
      end if;
1970
   end Validate_Remote_Type_Type_Conversion;
1971
 
1972
   -------------------------------
1973
   -- Validate_RT_RAT_Component --
1974
   -------------------------------
1975
 
1976
   procedure Validate_RT_RAT_Component (N : Node_Id) is
1977
      Spec           : constant Node_Id   := Specification (N);
1978
      Name_U         : constant Entity_Id := Defining_Entity (Spec);
1979
      Typ            : Entity_Id;
1980
      U_Typ          : Entity_Id;
1981
      First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1982
 
1983
   begin
1984
      if not Is_Remote_Types (Name_U) then
1985
         return;
1986
      end if;
1987
 
1988
      Typ := First_Entity (Name_U);
1989
      while Present (Typ) and then Typ /= First_Priv_Ent loop
1990
         U_Typ := Underlying_Type (Typ);
1991
 
1992
         if No (U_Typ) then
1993
            U_Typ := Typ;
1994
         end if;
1995
 
1996
         if Comes_From_Source (Typ) and then Is_Type (Typ) then
1997
            if Missing_Read_Write_Attributes (Typ) then
1998
               if Is_Non_Remote_Access_Type (Typ) then
1999
                  Error_Msg_N ("error in non-remote access type", U_Typ);
2000
               else
2001
                  Error_Msg_N
2002
                    ("error in record type containing a component of a " &
2003
                     "non-remote access type", U_Typ);
2004
               end if;
2005
 
2006
               if Ada_Version >= Ada_05 then
2007
                  Error_Msg_N
2008
                    ("\must have visible Read and Write attribute " &
2009
                     "definition clauses (RM E.2.2(8))", U_Typ);
2010
               else
2011
                  Error_Msg_N
2012
                    ("\must have Read and Write attribute " &
2013
                     "definition clauses (RM E.2.2(8))", U_Typ);
2014
               end if;
2015
            end if;
2016
         end if;
2017
 
2018
         Next_Entity (Typ);
2019
      end loop;
2020
   end Validate_RT_RAT_Component;
2021
 
2022
   -----------------------------------------
2023
   -- Validate_SP_Access_Object_Type_Decl --
2024
   -----------------------------------------
2025
 
2026
   procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2027
      Direct_Designated_Type : Entity_Id;
2028
 
2029
      function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2030
      --  Return true if the protected type designated by T has
2031
      --  entry declarations.
2032
 
2033
      ----------------------------
2034
      -- Has_Entry_Declarations --
2035
      ----------------------------
2036
 
2037
      function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2038
         Ety : Entity_Id;
2039
 
2040
      begin
2041
         if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2042
            Ety := First_Entity (E);
2043
            while Present (Ety) loop
2044
               if Ekind (Ety) = E_Entry then
2045
                  return True;
2046
               end if;
2047
 
2048
               Next_Entity (Ety);
2049
            end loop;
2050
         end if;
2051
 
2052
         return False;
2053
      end Has_Entry_Declarations;
2054
 
2055
   --  Start of processing for Validate_SP_Access_Object_Type_Decl
2056
 
2057
   begin
2058
      --  We are called from Sem_Ch3.Analyze_Type_Declaration, and the
2059
      --  Nkind of the given entity is N_Access_To_Object_Definition.
2060
 
2061
      if not Comes_From_Source (T)
2062
        or else not In_Shared_Passive_Unit
2063
        or else In_Subprogram_Task_Protected_Unit
2064
      then
2065
         return;
2066
      end if;
2067
 
2068
      --  Check Shared Passive unit. It should not contain the declaration
2069
      --  of an access-to-object type whose designated type is a class-wide
2070
      --  type, task type or protected type with entry (RM E.2.1(7)).
2071
 
2072
      Direct_Designated_Type := Designated_Type (T);
2073
 
2074
      if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2075
         Error_Msg_N
2076
           ("invalid access-to-class-wide type in shared passive unit", T);
2077
         return;
2078
 
2079
      elsif Ekind (Direct_Designated_Type) in Task_Kind then
2080
         Error_Msg_N
2081
           ("invalid access-to-task type in shared passive unit", T);
2082
         return;
2083
 
2084
      elsif Ekind (Direct_Designated_Type) in Protected_Kind
2085
        and then Has_Entry_Declarations (Direct_Designated_Type)
2086
      then
2087
         Error_Msg_N
2088
           ("invalid access-to-protected type in shared passive unit", T);
2089
         return;
2090
      end if;
2091
   end Validate_SP_Access_Object_Type_Decl;
2092
 
2093
   ---------------------------------
2094
   -- Validate_Static_Object_Name --
2095
   ---------------------------------
2096
 
2097
   procedure Validate_Static_Object_Name (N : Node_Id) is
2098
      E : Entity_Id;
2099
 
2100
      function Is_Primary (N : Node_Id) return Boolean;
2101
      --  Determine whether node is syntactically a primary in an expression
2102
      --  This function should probably be somewhere else ???
2103
      --  Also it does not do what it says, e.g if N is a binary operator
2104
      --  whose parent is a binary operator, Is_Primary returns True ???
2105
 
2106
      ----------------
2107
      -- Is_Primary --
2108
      ----------------
2109
 
2110
      function Is_Primary (N : Node_Id) return Boolean is
2111
         K : constant Node_Kind := Nkind (Parent (N));
2112
 
2113
      begin
2114
         case K is
2115
            when N_Op | N_Membership_Test =>
2116
               return True;
2117
 
2118
            when N_Aggregate
2119
               | N_Component_Association
2120
               | N_Index_Or_Discriminant_Constraint =>
2121
               return True;
2122
 
2123
            when N_Attribute_Reference =>
2124
               return Attribute_Name (Parent (N)) /= Name_Address
2125
                 and then Attribute_Name (Parent (N)) /= Name_Access
2126
                 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2127
                 and then
2128
                   Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2129
 
2130
            when N_Indexed_Component =>
2131
               return (N /= Prefix (Parent (N))
2132
                 or else Is_Primary (Parent (N)));
2133
 
2134
            when N_Qualified_Expression | N_Type_Conversion =>
2135
               return Is_Primary (Parent (N));
2136
 
2137
            when N_Assignment_Statement | N_Object_Declaration =>
2138
               return (N = Expression (Parent (N)));
2139
 
2140
            when N_Selected_Component =>
2141
               return Is_Primary (Parent (N));
2142
 
2143
            when others =>
2144
               return False;
2145
         end case;
2146
      end Is_Primary;
2147
 
2148
   --  Start of processing for Validate_Static_Object_Name
2149
 
2150
   begin
2151
      if not In_Preelaborated_Unit
2152
        or else not Comes_From_Source (N)
2153
        or else In_Subprogram_Or_Concurrent_Unit
2154
        or else Ekind (Current_Scope) = E_Block
2155
      then
2156
         return;
2157
 
2158
      --  Filter out cases where primary is default in a component declaration,
2159
      --  discriminant specification, or actual in a record type initialization
2160
      --  call.
2161
 
2162
      --  Initialization call of internal types
2163
 
2164
      elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2165
 
2166
         if Present (Parent (Parent (N)))
2167
           and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2168
         then
2169
            return;
2170
         end if;
2171
 
2172
         if Nkind (Name (Parent (N))) = N_Identifier
2173
           and then not Comes_From_Source (Entity (Name (Parent (N))))
2174
         then
2175
            return;
2176
         end if;
2177
      end if;
2178
 
2179
      --  Error if the name is a primary in an expression. The parent must not
2180
      --  be an operator, or a selected component or an indexed component that
2181
      --  is itself a primary. Entities that are actuals do not need to be
2182
      --  checked, because the call itself will be diagnosed.
2183
 
2184
      if Is_Primary (N)
2185
        and then (not Inside_A_Generic
2186
                   or else Present (Enclosing_Generic_Body (N)))
2187
      then
2188
         if Ekind (Entity (N)) = E_Variable
2189
           or else Ekind (Entity (N)) in Formal_Object_Kind
2190
         then
2191
            Flag_Non_Static_Expr
2192
              ("non-static object name in preelaborated unit", N);
2193
 
2194
         --  Give an error for a reference to a nonstatic constant, unless the
2195
         --  constant is in another GNAT library unit that is preelaborable.
2196
 
2197
         elsif Ekind (Entity (N)) = E_Constant
2198
           and then not Is_Static_Expression (N)
2199
         then
2200
            E := Entity (N);
2201
 
2202
            if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2203
              and then
2204
                Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2205
              and then (Is_Preelaborated (Scope (E))
2206
                          or else Is_Pure (Scope (E))
2207
                          or else (Present (Renamed_Object (E))
2208
                                     and then
2209
                                       Is_Entity_Name (Renamed_Object (E))
2210
                                     and then
2211
                                       (Is_Preelaborated
2212
                                         (Scope (Renamed_Object (E)))
2213
                                            or else
2214
                                              Is_Pure (Scope
2215
                                                (Renamed_Object (E))))))
2216
            then
2217
               null;
2218
 
2219
            --  This is the error case
2220
 
2221
            else
2222
               --  In GNAT mode, this is just a warning, to allow it to be
2223
               --  judiciously turned off. Otherwise it is a real error.
2224
 
2225
               if GNAT_Mode then
2226
                  Error_Msg_N
2227
                    ("?non-static constant in preelaborated unit", N);
2228
               else
2229
                  Flag_Non_Static_Expr
2230
                    ("non-static constant in preelaborated unit", N);
2231
               end if;
2232
            end if;
2233
         end if;
2234
      end if;
2235
   end Validate_Static_Object_Name;
2236
 
2237
end Sem_Cat;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.