comparison gcc/ada/sem_util.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
4 -- -- 4 -- --
5 -- S E M _ U T I L -- 5 -- S E M _ U T I L --
6 -- -- 6 -- --
7 -- B o d y -- 7 -- B o d y --
8 -- -- 8 -- --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- 9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
10 -- -- 10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under -- 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- -- 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- -- 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- -- 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
32 with Debug; use Debug; 32 with Debug; use Debug;
33 with Elists; use Elists; 33 with Elists; use Elists;
34 with Errout; use Errout; 34 with Errout; use Errout;
35 with Erroutc; use Erroutc; 35 with Erroutc; use Erroutc;
36 with Exp_Ch11; use Exp_Ch11; 36 with Exp_Ch11; use Exp_Ch11;
37 with Exp_Disp; use Exp_Disp;
38 with Exp_Util; use Exp_Util; 37 with Exp_Util; use Exp_Util;
39 with Fname; use Fname; 38 with Fname; use Fname;
40 with Freeze; use Freeze; 39 with Freeze; use Freeze;
41 with Lib; use Lib; 40 with Lib; use Lib;
42 with Lib.Xref; use Lib.Xref; 41 with Lib.Xref; use Lib.Xref;
71 70
72 with GNAT.HTable; use GNAT.HTable; 71 with GNAT.HTable; use GNAT.HTable;
73 72
74 package body Sem_Util is 73 package body Sem_Util is
75 74
75 ---------------------------
76 -- Local Data Structures --
77 ---------------------------
78
79 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
80 -- A collection to hold the entities of the variables declared in package
81 -- System.Scalar_Values which describe the invalid values of scalar types.
82
83 Invalid_Binder_Values_Set : Boolean := False;
84 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
85
86 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
87 -- A collection to hold the invalid values of float types as specified by
88 -- pragma Initialize_Scalars.
89
90 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
91 -- A collection to hold the invalid values of integer types as specified
92 -- by pragma Initialize_Scalars.
93
76 ----------------------- 94 -----------------------
77 -- Local Subprograms -- 95 -- Local Subprograms --
78 ----------------------- 96 -----------------------
79 97
80 function Build_Component_Subtype 98 function Build_Component_Subtype
82 Loc : Source_Ptr; 100 Loc : Source_Ptr;
83 T : Entity_Id) return Node_Id; 101 T : Entity_Id) return Node_Id;
84 -- This function builds the subtype for Build_Actual_Subtype_Of_Component 102 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
85 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints, 103 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
86 -- Loc is the source location, T is the original subtype. 104 -- Loc is the source location, T is the original subtype.
105
106 procedure Examine_Array_Bounds
107 (Typ : Entity_Id;
108 All_Static : out Boolean;
109 Has_Empty : out Boolean);
110 -- Inspect the index constraints of array type Typ. Flag All_Static is set
111 -- when all ranges are static. Flag Has_Empty is set only when All_Static
112 -- is set and indicates that at least one range is empty.
87 113
88 function Has_Enabled_Property 114 function Has_Enabled_Property
89 (Item_Id : Entity_Id; 115 (Item_Id : Entity_Id;
90 Property : Name_Id) return Boolean; 116 Property : Name_Id) return Boolean;
91 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled. 117 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
139 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is 165 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
140 -- eliminated. 166 -- eliminated.
141 167
142 function Subprogram_Name (N : Node_Id) return String; 168 function Subprogram_Name (N : Node_Id) return String;
143 -- Return the fully qualified name of the enclosing subprogram for the 169 -- Return the fully qualified name of the enclosing subprogram for the
144 -- given node N. 170 -- given node N, with file:line:col information appended, e.g.
171 -- "subp:file:line:col", corresponding to the source location of the
172 -- body of the subprogram.
145 173
146 ------------------------------ 174 ------------------------------
147 -- Abstract_Interface_List -- 175 -- Abstract_Interface_List --
148 ------------------------------ 176 ------------------------------
149 177
154 if Is_Concurrent_Type (Typ) then 182 if Is_Concurrent_Type (Typ) then
155 183
156 -- If we are dealing with a synchronized subtype, go to the base 184 -- If we are dealing with a synchronized subtype, go to the base
157 -- type, whose declaration has the interface list. 185 -- type, whose declaration has the interface list.
158 186
159 -- Shouldn't this be Declaration_Node??? 187 Nod := Declaration_Node (Base_Type (Typ));
160 188
161 Nod := Parent (Base_Type (Typ)); 189 if Nkind_In (Nod, N_Full_Type_Declaration,
162 190 N_Private_Type_Declaration)
163 if Nkind (Nod) = N_Full_Type_Declaration then 191 then
164 return Empty_List; 192 return Empty_List;
165 end if; 193 end if;
166 194
167 elsif Ekind (Typ) = E_Record_Type_With_Private then 195 elsif Ekind (Typ) = E_Record_Type_With_Private then
168 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then 196 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
592 ----------- 620 -----------
593 -- Inner -- 621 -- Inner --
594 ----------- 622 -----------
595 623
596 procedure Inner (E : Entity_Id) is 624 procedure Inner (E : Entity_Id) is
625 Scop : Node_Id;
626
597 begin 627 begin
598 -- If entity has an internal name, skip by it, and print its scope. 628 -- If entity has an internal name, skip by it, and print its scope.
599 -- Note that we strip a final R from the name before the test; this 629 -- Note that we strip a final R from the name before the test; this
600 -- is needed for some cases of instantiations. 630 -- is needed for some cases of instantiations.
601 631
613 Inner (Scope (E)); 643 Inner (Scope (E));
614 return; 644 return;
615 end if; 645 end if;
616 end; 646 end;
617 647
648 Scop := Scope (E);
649
618 -- Just print entity name if its scope is at the outer level 650 -- Just print entity name if its scope is at the outer level
619 651
620 if Scope (E) = Standard_Standard then 652 if Scop = Standard_Standard then
621 null; 653 null;
622 654
623 -- If scope comes from source, write scope and entity 655 -- If scope comes from source, write scope and entity
624 656
625 elsif Comes_From_Source (Scope (E)) then 657 elsif Comes_From_Source (Scop) then
626 Append_Entity_Name (Temp, Scope (E)); 658 Append_Entity_Name (Temp, Scop);
627 Append (Temp, '.'); 659 Append (Temp, '.');
628 660
629 -- If in wrapper package skip past it 661 -- If in wrapper package skip past it
630 662
631 elsif Is_Wrapper_Package (Scope (E)) then 663 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
632 Append_Entity_Name (Temp, Scope (Scope (E))); 664 Append_Entity_Name (Temp, Scope (Scop));
633 Append (Temp, '.'); 665 Append (Temp, '.');
634 666
635 -- Otherwise nothing to output (happens in unnamed block statements) 667 -- Otherwise nothing to output (happens in unnamed block statements)
636 668
637 else 669 else
693 and then Has_Private_Declaration (Typ) 725 and then Has_Private_Declaration (Typ)
694 and then Is_Tagged_Type (Typ) 726 and then Is_Tagged_Type (Typ)
695 and then Scop = Current_Scope 727 and then Scop = Current_Scope
696 then 728 then
697 -- The inherited operation is available at the earliest place after 729 -- The inherited operation is available at the earliest place after
698 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only 730 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
699 -- relevant for type extensions. If the parent operation appears 731 -- relevant for type extensions. If the parent operation appears
700 -- after the type extension, the operation is not visible. 732 -- after the type extension, the operation is not visible.
701 733
702 Decl := First 734 Decl := First
703 (Visible_Declarations 735 (Visible_Declarations
706 if Nkind (Decl) = N_Private_Extension_Declaration 738 if Nkind (Decl) = N_Private_Extension_Declaration
707 and then Defining_Entity (Decl) = Typ 739 and then Defining_Entity (Decl) = Typ
708 then 740 then
709 if Sloc (Decl) > Sloc (Par) then 741 if Sloc (Decl) > Sloc (Par) then
710 Next_E := Next_Entity (Par); 742 Next_E := Next_Entity (Par);
711 Set_Next_Entity (Par, S); 743 Link_Entities (Par, S);
712 Set_Next_Entity (S, Next_E); 744 Link_Entities (S, Next_E);
713 return; 745 return;
714 746
715 else 747 else
716 exit; 748 exit;
717 end if; 749 end if;
1331 1363
1332 -- The new operation is internal and overriding indicators do not apply 1364 -- The new operation is internal and overriding indicators do not apply
1333 -- (the original primitive may have carried one). 1365 -- (the original primitive may have carried one).
1334 1366
1335 Set_Must_Override (Specification (Clone_Body), False); 1367 Set_Must_Override (Specification (Clone_Body), False);
1336 Insert_Before (Bod, Clone_Body); 1368
1369 -- If the subprogram body is the proper body of a stub, insert the
1370 -- subprogram after the stub, i.e. the same declarative region as
1371 -- the original sugprogram.
1372
1373 if Nkind (Parent (Bod)) = N_Subunit then
1374 Insert_After (Corresponding_Stub (Parent (Bod)), Clone_Body);
1375
1376 else
1377 Insert_Before (Bod, Clone_Body);
1378 end if;
1379
1337 Analyze (Clone_Body); 1380 Analyze (Clone_Body);
1338 end Build_Class_Wide_Clone_Body; 1381 end Build_Class_Wide_Clone_Body;
1339 1382
1340 --------------------------------- 1383 ---------------------------------
1341 -- Build_Class_Wide_Clone_Call -- 1384 -- Build_Class_Wide_Clone_Call --
3183 Scop : Entity_Id; 3226 Scop : Entity_Id;
3184 3227
3185 begin 3228 begin
3186 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable)); 3229 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3187 3230
3231 -- Nothing to do for internally-generated abstract states and variables
3232 -- because they do not represent the hidden state of the source unit.
3233
3234 if not Comes_From_Source (Id) then
3235 return;
3236 end if;
3237
3188 -- Find the proper context where the object or state appears 3238 -- Find the proper context where the object or state appears
3189 3239
3190 Scop := Scope (Id); 3240 Scop := Scope (Id);
3191 while Present (Scop) loop 3241 while Present (Scop) loop
3192 Context := Scop; 3242 Context := Scop;
3273 ----------------------------- 3323 -----------------------------
3274 -- Check_Part_Of_Reference -- 3324 -- Check_Part_Of_Reference --
3275 ----------------------------- 3325 -----------------------------
3276 3326
3277 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is 3327 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3328 function Is_Enclosing_Package_Body
3329 (Body_Decl : Node_Id;
3330 Obj_Id : Entity_Id) return Boolean;
3331 pragma Inline (Is_Enclosing_Package_Body);
3332 -- Determine whether package body Body_Decl or its corresponding spec
3333 -- immediately encloses the declaration of object Obj_Id.
3334
3335 function Is_Internal_Declaration_Or_Body
3336 (Decl : Node_Id) return Boolean;
3337 pragma Inline (Is_Internal_Declaration_Or_Body);
3338 -- Determine whether declaration or body denoted by Decl is internal
3339
3340 function Is_Single_Declaration_Or_Body
3341 (Decl : Node_Id;
3342 Conc_Typ : Entity_Id) return Boolean;
3343 pragma Inline (Is_Single_Declaration_Or_Body);
3344 -- Determine whether protected/task declaration or body denoted by Decl
3345 -- belongs to single concurrent type Conc_Typ.
3346
3347 function Is_Single_Task_Pragma
3348 (Prag : Node_Id;
3349 Task_Typ : Entity_Id) return Boolean;
3350 pragma Inline (Is_Single_Task_Pragma);
3351 -- Determine whether pragma Prag belongs to single task type Task_Typ
3352
3353 -------------------------------
3354 -- Is_Enclosing_Package_Body --
3355 -------------------------------
3356
3357 function Is_Enclosing_Package_Body
3358 (Body_Decl : Node_Id;
3359 Obj_Id : Entity_Id) return Boolean
3360 is
3361 Obj_Context : Node_Id;
3362
3363 begin
3364 -- Find the context of the object declaration
3365
3366 Obj_Context := Parent (Declaration_Node (Obj_Id));
3367
3368 if Nkind (Obj_Context) = N_Package_Specification then
3369 Obj_Context := Parent (Obj_Context);
3370 end if;
3371
3372 -- The object appears immediately within the package body
3373
3374 if Obj_Context = Body_Decl then
3375 return True;
3376
3377 -- The object appears immediately within the corresponding spec
3378
3379 elsif Nkind (Obj_Context) = N_Package_Declaration
3380 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3381 Obj_Context
3382 then
3383 return True;
3384 end if;
3385
3386 return False;
3387 end Is_Enclosing_Package_Body;
3388
3389 -------------------------------------
3390 -- Is_Internal_Declaration_Or_Body --
3391 -------------------------------------
3392
3393 function Is_Internal_Declaration_Or_Body
3394 (Decl : Node_Id) return Boolean
3395 is
3396 begin
3397 if Comes_From_Source (Decl) then
3398 return False;
3399
3400 -- A body generated for an expression function which has not been
3401 -- inserted into the tree yet (In_Spec_Expression is True) is not
3402 -- considered internal.
3403
3404 elsif Nkind (Decl) = N_Subprogram_Body
3405 and then Was_Expression_Function (Decl)
3406 and then not In_Spec_Expression
3407 then
3408 return False;
3409 end if;
3410
3411 return True;
3412 end Is_Internal_Declaration_Or_Body;
3413
3414 -----------------------------------
3415 -- Is_Single_Declaration_Or_Body --
3416 -----------------------------------
3417
3418 function Is_Single_Declaration_Or_Body
3419 (Decl : Node_Id;
3420 Conc_Typ : Entity_Id) return Boolean
3421 is
3422 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3423
3424 begin
3425 return
3426 Present (Anonymous_Object (Spec_Id))
3427 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3428 end Is_Single_Declaration_Or_Body;
3429
3430 ---------------------------
3431 -- Is_Single_Task_Pragma --
3432 ---------------------------
3433
3434 function Is_Single_Task_Pragma
3435 (Prag : Node_Id;
3436 Task_Typ : Entity_Id) return Boolean
3437 is
3438 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3439
3440 begin
3441 -- To qualify, the pragma must be associated with single task type
3442 -- Task_Typ.
3443
3444 return
3445 Is_Single_Task_Object (Task_Typ)
3446 and then Nkind (Decl) = N_Object_Declaration
3447 and then Defining_Entity (Decl) = Task_Typ;
3448 end Is_Single_Task_Pragma;
3449
3450 -- Local variables
3451
3278 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id); 3452 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3279 Decl : Node_Id;
3280 OK_Use : Boolean := False;
3281 Par : Node_Id; 3453 Par : Node_Id;
3282 Prag_Nam : Name_Id; 3454 Prag_Nam : Name_Id;
3283 Spec_Id : Entity_Id; 3455 Prev : Node_Id;
3284 3456
3285 begin 3457 -- Start of processing for Check_Part_Of_Reference
3458
3459 begin
3460 -- Nothing to do when the variable was recorded, but did not become a
3461 -- constituent of a single concurrent type.
3462
3463 if No (Conc_Obj) then
3464 return;
3465 end if;
3466
3286 -- Traverse the parent chain looking for a suitable context for the 3467 -- Traverse the parent chain looking for a suitable context for the
3287 -- reference to the concurrent constituent. 3468 -- reference to the concurrent constituent.
3288 3469
3289 Par := Parent (Ref); 3470 Prev := Ref;
3471 Par := Parent (Prev);
3290 while Present (Par) loop 3472 while Present (Par) loop
3291 if Nkind (Par) = N_Pragma then 3473 if Nkind (Par) = N_Pragma then
3292 Prag_Nam := Pragma_Name (Par); 3474 Prag_Nam := Pragma_Name (Par);
3293 3475
3294 -- A concurrent constituent is allowed to appear in pragmas 3476 -- A concurrent constituent is allowed to appear in pragmas
3295 -- Initial_Condition and Initializes as this is part of the 3477 -- Initial_Condition and Initializes as this is part of the
3296 -- elaboration checks for the constituent (SPARK RM 9.3). 3478 -- elaboration checks for the constituent (SPARK RM 9(3)).
3297 3479
3298 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then 3480 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3299 OK_Use := True; 3481 return;
3300 exit;
3301 3482
3302 -- When the reference appears within pragma Depends or Global, 3483 -- When the reference appears within pragma Depends or Global,
3303 -- check whether the pragma applies to a single task type. Note 3484 -- check whether the pragma applies to a single task type. Note
3304 -- that the pragma is not encapsulated by the type definition, 3485 -- that the pragma may not encapsulated by the type definition,
3305 -- but this is still a valid context. 3486 -- but this is still a valid context.
3306 3487
3307 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then 3488 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3308 Decl := Find_Related_Declaration_Or_Body (Par); 3489 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3309 3490 then
3310 if Nkind (Decl) = N_Object_Declaration 3491 return;
3311 and then Defining_Entity (Decl) = Conc_Obj
3312 then
3313 OK_Use := True;
3314 exit;
3315 end if;
3316 end if; 3492 end if;
3317 3493
3318 -- The reference appears somewhere in the definition of the single 3494 -- The reference appears somewhere in the definition of a single
3319 -- protected/task type (SPARK RM 9.3). 3495 -- concurrent type (SPARK RM 9(3)).
3320 3496
3321 elsif Nkind_In (Par, N_Single_Protected_Declaration, 3497 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3322 N_Single_Task_Declaration) 3498 N_Single_Task_Declaration)
3323 and then Defining_Entity (Par) = Conc_Obj 3499 and then Defining_Entity (Par) = Conc_Obj
3324 then 3500 then
3325 OK_Use := True; 3501 return;
3326 exit; 3502
3327 3503 -- The reference appears within the declaration or body of a single
3328 -- The reference appears within the expanded declaration or the body 3504 -- concurrent type (SPARK RM 9(3)).
3329 -- of the single protected/task type (SPARK RM 9.3).
3330 3505
3331 elsif Nkind_In (Par, N_Protected_Body, 3506 elsif Nkind_In (Par, N_Protected_Body,
3332 N_Protected_Type_Declaration, 3507 N_Protected_Type_Declaration,
3333 N_Task_Body, 3508 N_Task_Body,
3334 N_Task_Type_Declaration) 3509 N_Task_Type_Declaration)
3510 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3335 then 3511 then
3336 Spec_Id := Unique_Defining_Entity (Par); 3512 return;
3337 3513
3338 if Present (Anonymous_Object (Spec_Id)) 3514 -- The reference appears within the statement list of the object's
3339 and then Anonymous_Object (Spec_Id) = Conc_Obj 3515 -- immediately enclosing package (SPARK RM 9(3)).
3340 then 3516
3341 OK_Use := True; 3517 elsif Nkind (Par) = N_Package_Body
3342 exit; 3518 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3343 end if; 3519 and then Is_Enclosing_Package_Body (Par, Var_Id)
3520 then
3521 return;
3344 3522
3345 -- The reference has been relocated within an internally generated 3523 -- The reference has been relocated within an internally generated
3346 -- package or subprogram. Assume that the reference is legal as the 3524 -- package or subprogram. Assume that the reference is legal as the
3347 -- real check was already performed in the original context of the 3525 -- real check was already performed in the original context of the
3348 -- reference. 3526 -- reference.
3349 3527
3350 elsif Nkind_In (Par, N_Package_Body, 3528 elsif Nkind_In (Par, N_Package_Body,
3351 N_Package_Declaration, 3529 N_Package_Declaration,
3352 N_Subprogram_Body, 3530 N_Subprogram_Body,
3353 N_Subprogram_Declaration) 3531 N_Subprogram_Declaration)
3354 and then not Comes_From_Source (Par) 3532 and then Is_Internal_Declaration_Or_Body (Par)
3355 then 3533 then
3356 -- Continue to examine the context if the reference appears in a 3534 return;
3357 -- subprogram body which was previously an expression function,
3358 -- unless this is during preanalysis (when In_Spec_Expression is
3359 -- True), as the body may not yet be inserted in the tree.
3360
3361 if Nkind (Par) = N_Subprogram_Body
3362 and then Was_Expression_Function (Par)
3363 and then not In_Spec_Expression
3364 then
3365 null;
3366
3367 -- Otherwise the reference is legal
3368
3369 else
3370 OK_Use := True;
3371 exit;
3372 end if;
3373 3535
3374 -- The reference has been relocated to an inlined body for GNATprove. 3536 -- The reference has been relocated to an inlined body for GNATprove.
3375 -- Assume that the reference is legal as the real check was already 3537 -- Assume that the reference is legal as the real check was already
3376 -- performed in the original context of the reference. 3538 -- performed in the original context of the reference.
3377 3539
3378 elsif GNATprove_Mode 3540 elsif GNATprove_Mode
3379 and then Nkind (Par) = N_Subprogram_Body 3541 and then Nkind (Par) = N_Subprogram_Body
3380 and then Chars (Defining_Entity (Par)) = Name_uParent 3542 and then Chars (Defining_Entity (Par)) = Name_uParent
3381 then 3543 then
3382 OK_Use := True; 3544 return;
3383 exit; 3545 end if;
3384 end if; 3546
3385 3547 Prev := Par;
3386 Par := Parent (Par); 3548 Par := Parent (Prev);
3387 end loop; 3549 end loop;
3388 3550
3389 -- The reference is illegal as it appears outside the definition or 3551 -- At this point it is known that the reference does not appear within a
3390 -- body of the single protected/task type. 3552 -- legal context.
3391 3553
3392 if not OK_Use then 3554 Error_Msg_NE
3555 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3556 Error_Msg_Name_1 := Chars (Var_Id);
3557
3558 if Is_Single_Protected_Object (Conc_Obj) then
3393 Error_Msg_NE 3559 Error_Msg_NE
3394 ("reference to variable & cannot appear in this context", 3560 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3395 Ref, Var_Id); 3561
3396 Error_Msg_Name_1 := Chars (Var_Id); 3562 else
3397 3563 Error_Msg_NE
3398 if Is_Single_Protected_Object (Conc_Obj) then 3564 ("\% is constituent of single task type &", Ref, Conc_Obj);
3399 Error_Msg_NE
3400 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3401
3402 else
3403 Error_Msg_NE
3404 ("\% is constituent of single task type &", Ref, Conc_Obj);
3405 end if;
3406 end if; 3565 end if;
3407 end Check_Part_Of_Reference; 3566 end Check_Part_Of_Reference;
3408 3567
3409 ------------------------------------------ 3568 ------------------------------------------
3410 -- Check_Potentially_Blocking_Operation -- 3569 -- Check_Potentially_Blocking_Operation --
3726 begin 3885 begin
3727 if Is_Attribute_Result (N) then 3886 if Is_Attribute_Result (N) then
3728 Result_Seen := True; 3887 Result_Seen := True;
3729 return Abandon; 3888 return Abandon;
3730 3889
3890 -- Warn on infinite recursion if call is to current function
3891
3892 elsif Nkind (N) = N_Function_Call
3893 and then Is_Entity_Name (Name (N))
3894 and then Entity (Name (N)) = Subp_Id
3895 and then not Is_Potentially_Unevaluated (N)
3896 then
3897 Error_Msg_NE
3898 ("call to & within its postcondition will lead to infinite "
3899 & "recursion?", N, Subp_Id);
3900 return OK;
3901
3731 -- Continue the traversal 3902 -- Continue the traversal
3732 3903
3733 else 3904 else
3734 return OK; 3905 return OK;
3735 end if; 3906 end if;
4023 -- state refinement. 4194 -- state refinement.
4024 4195
4025 if SPARK_Mode_Is_Off (Pack) then 4196 if SPARK_Mode_Is_Off (Pack) then
4026 null; 4197 null;
4027 4198
4028 -- State refinement can only occur in a completing packge body. Do 4199 -- State refinement can only occur in a completing package body. Do
4029 -- not verify proper state refinement when the body is subject to 4200 -- not verify proper state refinement when the body is subject to
4030 -- pragma SPARK_Mode Off because this disables the requirement for 4201 -- pragma SPARK_Mode Off because this disables the requirement for
4031 -- state refinement. 4202 -- state refinement.
4032 4203
4033 elsif Present (Body_Id) 4204 elsif Present (Body_Id)
4918 ---------------------------------- 5089 ----------------------------------
4919 -- Collect_Primitive_Operations -- 5090 -- Collect_Primitive_Operations --
4920 ---------------------------------- 5091 ----------------------------------
4921 5092
4922 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is 5093 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4923 B_Type : constant Entity_Id := Base_Type (T); 5094 B_Type : constant Entity_Id := Base_Type (T);
4924 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4925 B_Scope : Entity_Id := Scope (B_Type);
4926 Op_List : Elist_Id;
4927 Formal : Entity_Id;
4928 Is_Prim : Boolean;
4929 Is_Type_In_Pkg : Boolean;
4930 Formal_Derived : Boolean := False;
4931 Id : Entity_Id;
4932 5095
4933 function Match (E : Entity_Id) return Boolean; 5096 function Match (E : Entity_Id) return Boolean;
4934 -- True if E's base type is B_Type, or E is of an anonymous access type 5097 -- True if E's base type is B_Type, or E is of an anonymous access type
4935 -- and the base type of its designated type is B_Type. 5098 -- and the base type of its designated type is B_Type.
4936 5099
4953 or else 5116 or else
4954 (Ada_Version >= Ada_2012 5117 (Ada_Version >= Ada_2012
4955 and then Ekind (Etyp) = E_Incomplete_Type 5118 and then Ekind (Etyp) = E_Incomplete_Type
4956 and then Full_View (Etyp) = B_Type); 5119 and then Full_View (Etyp) = B_Type);
4957 end Match; 5120 end Match;
5121
5122 -- Local variables
5123
5124 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5125 B_Scope : Entity_Id := Scope (B_Type);
5126 Op_List : Elist_Id;
5127 Eq_Prims_List : Elist_Id := No_Elist;
5128 Formal : Entity_Id;
5129 Is_Prim : Boolean;
5130 Is_Type_In_Pkg : Boolean;
5131 Formal_Derived : Boolean := False;
5132 Id : Entity_Id;
4958 5133
4959 -- Start of processing for Collect_Primitive_Operations 5134 -- Start of processing for Collect_Primitive_Operations
4960 5135
4961 begin 5136 begin
4962 -- For tagged types, the primitive operations are collected as they 5137 -- For tagged types, the primitive operations are collected as they
4994 end if; 5169 end if;
4995 5170
4996 -- Locate the primitive subprograms of the type 5171 -- Locate the primitive subprograms of the type
4997 5172
4998 else 5173 else
4999 -- The primitive operations appear after the base type, except 5174 -- The primitive operations appear after the base type, except if the
5000 -- if the derivation happens within the private part of B_Scope 5175 -- derivation happens within the private part of B_Scope and the type
5001 -- and the type is a private type, in which case both the type 5176 -- is a private type, in which case both the type and some primitive
5002 -- and some primitive operations may appear before the base 5177 -- operations may appear before the base type, and the list of
5003 -- type, and the list of candidates starts after the type. 5178 -- candidates starts after the type.
5004 5179
5005 if In_Open_Scopes (B_Scope) 5180 if In_Open_Scopes (B_Scope)
5006 and then Scope (T) = B_Scope 5181 and then Scope (T) = B_Scope
5007 and then In_Private_Part (B_Scope) 5182 and then In_Private_Part (B_Scope)
5008 then 5183 then
5009 Id := Next_Entity (T); 5184 Id := Next_Entity (T);
5010 5185
5011 -- In Ada 2012, If the type has an incomplete partial view, there 5186 -- In Ada 2012, If the type has an incomplete partial view, there may
5012 -- may be primitive operations declared before the full view, so 5187 -- be primitive operations declared before the full view, so we need
5013 -- we need to start scanning from the incomplete view, which is 5188 -- to start scanning from the incomplete view, which is earlier on
5014 -- earlier on the entity chain. 5189 -- the entity chain.
5015 5190
5016 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration 5191 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5017 and then Present (Incomplete_View (Parent (B_Type))) 5192 and then Present (Incomplete_View (Parent (B_Type)))
5018 then 5193 then
5019 Id := Defining_Entity (Incomplete_View (Parent (B_Type))); 5194 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5102 5277
5103 -- Include the subprogram in the list of primitives 5278 -- Include the subprogram in the list of primitives
5104 5279
5105 else 5280 else
5106 Append_Elmt (Id, Op_List); 5281 Append_Elmt (Id, Op_List);
5282
5283 -- Save collected equality primitives for later filtering
5284 -- (if we are processing a private type for which we can
5285 -- collect several candidates).
5286
5287 if Inherits_From_Tagged_Full_View (T)
5288 and then Chars (Id) = Name_Op_Eq
5289 and then Etype (First_Formal (Id)) =
5290 Etype (Next_Formal (First_Formal (Id)))
5291 then
5292 if No (Eq_Prims_List) then
5293 Eq_Prims_List := New_Elmt_List;
5294 end if;
5295
5296 Append_Elmt (Id, Eq_Prims_List);
5297 end if;
5107 end if; 5298 end if;
5108 end if; 5299 end if;
5109 end if; 5300 end if;
5110 5301
5111 Next_Entity (Id); 5302 Next_Entity (Id);
5119 then 5310 then
5120 B_Scope := System_Aux_Id; 5311 B_Scope := System_Aux_Id;
5121 Id := First_Entity (System_Aux_Id); 5312 Id := First_Entity (System_Aux_Id);
5122 end if; 5313 end if;
5123 end loop; 5314 end loop;
5315
5316 -- Filter collected equality primitives
5317
5318 if Inherits_From_Tagged_Full_View (T)
5319 and then Present (Eq_Prims_List)
5320 then
5321 declare
5322 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5323 Second : Elmt_Id;
5324
5325 begin
5326 pragma Assert (No (Next_Elmt (First))
5327 or else No (Next_Elmt (Next_Elmt (First))));
5328
5329 -- No action needed if we have collected a single equality
5330 -- primitive
5331
5332 if Present (Next_Elmt (First)) then
5333 Second := Next_Elmt (First);
5334
5335 if Is_Dispatching_Operation
5336 (Ultimate_Alias (Node (First)))
5337 then
5338 Remove (Op_List, Node (First));
5339
5340 elsif Is_Dispatching_Operation
5341 (Ultimate_Alias (Node (Second)))
5342 then
5343 Remove (Op_List, Node (Second));
5344
5345 else
5346 pragma Assert (False);
5347 raise Program_Error;
5348 end if;
5349 end if;
5350 end;
5351 end if;
5124 end if; 5352 end if;
5125 5353
5126 return Op_List; 5354 return Op_List;
5127 end Collect_Primitive_Operations; 5355 end Collect_Primitive_Operations;
5128 5356
5287 begin 5515 begin
5288 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then 5516 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5289 Set_Has_Delayed_Freeze (New_Ent); 5517 Set_Has_Delayed_Freeze (New_Ent);
5290 end if; 5518 end if;
5291 end Conditional_Delay; 5519 end Conditional_Delay;
5292
5293 ----------------------------
5294 -- Contains_Refined_State --
5295 ----------------------------
5296
5297 function Contains_Refined_State (Prag : Node_Id) return Boolean is
5298 function Has_State_In_Dependency (List : Node_Id) return Boolean;
5299 -- Determine whether a dependency list mentions a state with a visible
5300 -- refinement.
5301
5302 function Has_State_In_Global (List : Node_Id) return Boolean;
5303 -- Determine whether a global list mentions a state with a visible
5304 -- refinement.
5305
5306 function Is_Refined_State (Item : Node_Id) return Boolean;
5307 -- Determine whether Item is a reference to an abstract state with a
5308 -- visible refinement.
5309
5310 -----------------------------
5311 -- Has_State_In_Dependency --
5312 -----------------------------
5313
5314 function Has_State_In_Dependency (List : Node_Id) return Boolean is
5315 Clause : Node_Id;
5316 Output : Node_Id;
5317
5318 begin
5319 -- A null dependency list does not mention any states
5320
5321 if Nkind (List) = N_Null then
5322 return False;
5323
5324 -- Dependency clauses appear as component associations of an
5325 -- aggregate.
5326
5327 elsif Nkind (List) = N_Aggregate
5328 and then Present (Component_Associations (List))
5329 then
5330 Clause := First (Component_Associations (List));
5331 while Present (Clause) loop
5332
5333 -- Inspect the outputs of a dependency clause
5334
5335 Output := First (Choices (Clause));
5336 while Present (Output) loop
5337 if Is_Refined_State (Output) then
5338 return True;
5339 end if;
5340
5341 Next (Output);
5342 end loop;
5343
5344 -- Inspect the outputs of a dependency clause
5345
5346 if Is_Refined_State (Expression (Clause)) then
5347 return True;
5348 end if;
5349
5350 Next (Clause);
5351 end loop;
5352
5353 -- If we get here, then none of the dependency clauses mention a
5354 -- state with visible refinement.
5355
5356 return False;
5357
5358 -- An illegal pragma managed to sneak in
5359
5360 else
5361 raise Program_Error;
5362 end if;
5363 end Has_State_In_Dependency;
5364
5365 -------------------------
5366 -- Has_State_In_Global --
5367 -------------------------
5368
5369 function Has_State_In_Global (List : Node_Id) return Boolean is
5370 Item : Node_Id;
5371
5372 begin
5373 -- A null global list does not mention any states
5374
5375 if Nkind (List) = N_Null then
5376 return False;
5377
5378 -- Simple global list or moded global list declaration
5379
5380 elsif Nkind (List) = N_Aggregate then
5381
5382 -- The declaration of a simple global list appear as a collection
5383 -- of expressions.
5384
5385 if Present (Expressions (List)) then
5386 Item := First (Expressions (List));
5387 while Present (Item) loop
5388 if Is_Refined_State (Item) then
5389 return True;
5390 end if;
5391
5392 Next (Item);
5393 end loop;
5394
5395 -- The declaration of a moded global list appears as a collection
5396 -- of component associations where individual choices denote
5397 -- modes.
5398
5399 else
5400 Item := First (Component_Associations (List));
5401 while Present (Item) loop
5402 if Has_State_In_Global (Expression (Item)) then
5403 return True;
5404 end if;
5405
5406 Next (Item);
5407 end loop;
5408 end if;
5409
5410 -- If we get here, then the simple/moded global list did not
5411 -- mention any states with a visible refinement.
5412
5413 return False;
5414
5415 -- Single global item declaration
5416
5417 elsif Is_Entity_Name (List) then
5418 return Is_Refined_State (List);
5419
5420 -- An illegal pragma managed to sneak in
5421
5422 else
5423 raise Program_Error;
5424 end if;
5425 end Has_State_In_Global;
5426
5427 ----------------------
5428 -- Is_Refined_State --
5429 ----------------------
5430
5431 function Is_Refined_State (Item : Node_Id) return Boolean is
5432 Elmt : Node_Id;
5433 Item_Id : Entity_Id;
5434
5435 begin
5436 if Nkind (Item) = N_Null then
5437 return False;
5438
5439 -- States cannot be subject to attribute 'Result. This case arises
5440 -- in dependency relations.
5441
5442 elsif Nkind (Item) = N_Attribute_Reference
5443 and then Attribute_Name (Item) = Name_Result
5444 then
5445 return False;
5446
5447 -- Multiple items appear as an aggregate. This case arises in
5448 -- dependency relations.
5449
5450 elsif Nkind (Item) = N_Aggregate
5451 and then Present (Expressions (Item))
5452 then
5453 Elmt := First (Expressions (Item));
5454 while Present (Elmt) loop
5455 if Is_Refined_State (Elmt) then
5456 return True;
5457 end if;
5458
5459 Next (Elmt);
5460 end loop;
5461
5462 -- If we get here, then none of the inputs or outputs reference a
5463 -- state with visible refinement.
5464
5465 return False;
5466
5467 -- Single item
5468
5469 else
5470 Item_Id := Entity_Of (Item);
5471
5472 return
5473 Present (Item_Id)
5474 and then Ekind (Item_Id) = E_Abstract_State
5475 and then Has_Visible_Refinement (Item_Id);
5476 end if;
5477 end Is_Refined_State;
5478
5479 -- Local variables
5480
5481 Arg : constant Node_Id :=
5482 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
5483 Nam : constant Name_Id := Pragma_Name (Prag);
5484
5485 -- Start of processing for Contains_Refined_State
5486
5487 begin
5488 if Nam = Name_Depends then
5489 return Has_State_In_Dependency (Arg);
5490
5491 else pragma Assert (Nam = Name_Global);
5492 return Has_State_In_Global (Arg);
5493 end if;
5494 end Contains_Refined_State;
5495 5520
5496 ------------------------- 5521 -------------------------
5497 -- Copy_Component_List -- 5522 -- Copy_Component_List --
5498 ------------------------- 5523 -------------------------
5499 5524
5966 ------------------------- 5991 -------------------------
5967 -- Denotes_Same_Object -- 5992 -- Denotes_Same_Object --
5968 ------------------------- 5993 -------------------------
5969 5994
5970 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is 5995 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5971 Obj1 : Node_Id := A1;
5972 Obj2 : Node_Id := A2;
5973
5974 function Has_Prefix (N : Node_Id) return Boolean;
5975 -- Return True if N has attribute Prefix
5976
5977 function Is_Renaming (N : Node_Id) return Boolean; 5996 function Is_Renaming (N : Node_Id) return Boolean;
5978 -- Return true if N names a renaming entity 5997 -- Return true if N names a renaming entity
5979 5998
5980 function Is_Valid_Renaming (N : Node_Id) return Boolean; 5999 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5981 -- For renamings, return False if the prefix of any dereference within 6000 -- For renamings, return False if the prefix of any dereference within
5982 -- the renamed object_name is a variable, or any expression within the 6001 -- the renamed object_name is a variable, or any expression within the
5983 -- renamed object_name contains references to variables or calls on 6002 -- renamed object_name contains references to variables or calls on
5984 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3)) 6003 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5985 6004
5986 ----------------
5987 -- Has_Prefix --
5988 ----------------
5989
5990 function Has_Prefix (N : Node_Id) return Boolean is
5991 begin
5992 return
5993 Nkind_In (N,
5994 N_Attribute_Reference,
5995 N_Expanded_Name,
5996 N_Explicit_Dereference,
5997 N_Indexed_Component,
5998 N_Reference,
5999 N_Selected_Component,
6000 N_Slice);
6001 end Has_Prefix;
6002
6003 ----------------- 6005 -----------------
6004 -- Is_Renaming -- 6006 -- Is_Renaming --
6005 ----------------- 6007 -----------------
6006 6008
6007 function Is_Renaming (N : Node_Id) return Boolean is 6009 function Is_Renaming (N : Node_Id) return Boolean is
6008 begin 6010 begin
6009 return Is_Entity_Name (N) 6011 return
6010 and then Present (Renamed_Entity (Entity (N))); 6012 Is_Entity_Name (N) and then Present (Renamed_Entity (Entity (N)));
6011 end Is_Renaming; 6013 end Is_Renaming;
6012 6014
6013 ----------------------- 6015 -----------------------
6014 -- Is_Valid_Renaming -- 6016 -- Is_Valid_Renaming --
6015 ----------------------- 6017 -----------------------
6016 6018
6017 function Is_Valid_Renaming (N : Node_Id) return Boolean is 6019 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6018
6019 function Check_Renaming (N : Node_Id) return Boolean; 6020 function Check_Renaming (N : Node_Id) return Boolean;
6020 -- Recursive function used to traverse all the prefixes of N 6021 -- Recursive function used to traverse all the prefixes of N
6022
6023 --------------------
6024 -- Check_Renaming --
6025 --------------------
6021 6026
6022 function Check_Renaming (N : Node_Id) return Boolean is 6027 function Check_Renaming (N : Node_Id) return Boolean is
6023 begin 6028 begin
6024 if Is_Renaming (N) 6029 if Is_Renaming (N)
6025 and then not Check_Renaming (Renamed_Entity (Entity (N))) 6030 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6075 -- Start of processing for Is_Valid_Renaming 6080 -- Start of processing for Is_Valid_Renaming
6076 6081
6077 begin 6082 begin
6078 return Check_Renaming (N); 6083 return Check_Renaming (N);
6079 end Is_Valid_Renaming; 6084 end Is_Valid_Renaming;
6085
6086 -- Local variables
6087
6088 Obj1 : Node_Id := A1;
6089 Obj2 : Node_Id := A2;
6080 6090
6081 -- Start of processing for Denotes_Same_Object 6091 -- Start of processing for Denotes_Same_Object
6082 6092
6083 begin 6093 begin
6084 -- Both names statically denote the same stand-alone object or parameter 6094 -- Both names statically denote the same stand-alone object or parameter
6695 6705
6696 begin 6706 begin
6697 while Present (Decl) 6707 while Present (Decl)
6698 and then not (Nkind (Decl) in N_Declaration 6708 and then not (Nkind (Decl) in N_Declaration
6699 or else 6709 or else
6700 Nkind (Decl) in N_Later_Decl_Item) 6710 Nkind (Decl) in N_Later_Decl_Item
6711 or else
6712 Nkind (Decl) = N_Number_Declaration)
6701 loop 6713 loop
6702 Decl := Parent (Decl); 6714 Decl := Parent (Decl);
6703 end loop; 6715 end loop;
6704 6716
6705 return Decl; 6717 return Decl;
6880 -------------------------- 6892 --------------------------
6881 -- Enclosing_Subprogram -- 6893 -- Enclosing_Subprogram --
6882 -------------------------- 6894 --------------------------
6883 6895
6884 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is 6896 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6885 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E); 6897 Dyn_Scop : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6886 6898
6887 begin 6899 begin
6888 if Dynamic_Scope = Standard_Standard then 6900 if Dyn_Scop = Standard_Standard then
6889 return Empty; 6901 return Empty;
6890 6902
6891 elsif Dynamic_Scope = Empty then 6903 elsif Dyn_Scop = Empty then
6892 return Empty; 6904 return Empty;
6893 6905
6894 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then 6906 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
6895 return Corresponding_Spec (Parent (Parent (Dynamic_Scope))); 6907 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
6896 6908
6897 elsif Ekind (Dynamic_Scope) = E_Block 6909 elsif Ekind_In (Dyn_Scop, E_Block, E_Return_Statement) then
6898 or else Ekind (Dynamic_Scope) = E_Return_Statement 6910 return Enclosing_Subprogram (Dyn_Scop);
6911
6912 elsif Ekind (Dyn_Scop) = E_Entry then
6913
6914 -- For a task entry, return the enclosing subprogram of the
6915 -- task itself.
6916
6917 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
6918 return Enclosing_Subprogram (Dyn_Scop);
6919
6920 -- A protected entry is rewritten as a protected procedure which is
6921 -- the desired enclosing subprogram. This is relevant when unnesting
6922 -- a procedure local to an entry body.
6923
6924 else
6925 return Protected_Body_Subprogram (Dyn_Scop);
6926 end if;
6927
6928 elsif Ekind (Dyn_Scop) = E_Task_Type then
6929 return Get_Task_Body_Procedure (Dyn_Scop);
6930
6931 -- The scope may appear as a private type or as a private extension
6932 -- whose completion is a task or protected type.
6933
6934 elsif Ekind_In (Dyn_Scop, E_Limited_Private_Type,
6935 E_Record_Type_With_Private)
6936 and then Present (Full_View (Dyn_Scop))
6937 and then Ekind_In (Full_View (Dyn_Scop), E_Task_Type, E_Protected_Type)
6899 then 6938 then
6900 return Enclosing_Subprogram (Dynamic_Scope); 6939 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
6901 6940
6902 elsif Ekind (Dynamic_Scope) = E_Task_Type then 6941 -- No body is generated if the protected operation is eliminated
6903 return Get_Task_Body_Procedure (Dynamic_Scope); 6942
6904 6943 elsif Convention (Dyn_Scop) = Convention_Protected
6905 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type 6944 and then not Is_Eliminated (Dyn_Scop)
6906 and then Present (Full_View (Dynamic_Scope)) 6945 and then Present (Protected_Body_Subprogram (Dyn_Scop))
6907 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6908 then 6946 then
6909 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope)); 6947 return Protected_Body_Subprogram (Dyn_Scop);
6910
6911 -- No body is generated if the protected operation is eliminated
6912
6913 elsif Convention (Dynamic_Scope) = Convention_Protected
6914 and then not Is_Eliminated (Dynamic_Scope)
6915 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6916 then
6917 return Protected_Body_Subprogram (Dynamic_Scope);
6918 6948
6919 else 6949 else
6920 return Dynamic_Scope; 6950 return Dyn_Scop;
6921 end if; 6951 end if;
6922 end Enclosing_Subprogram; 6952 end Enclosing_Subprogram;
6923 6953
6924 -------------------------- 6954 --------------------------
6925 -- End_Keyword_Location -- 6955 -- End_Keyword_Location --
7101 pragma Assert 7131 pragma Assert
7102 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration); 7132 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7103 null; 7133 null;
7104 7134
7105 else 7135 else
7106 Set_Next_Entity (Prev, Next_Entity (E)); 7136 Link_Entities (Prev, Next_Entity (E));
7107 7137
7108 if No (Next_Entity (Prev)) then 7138 if No (Next_Entity (Prev)) then
7109 Set_Last_Entity (Current_Scope, Prev); 7139 Set_Last_Entity (Current_Scope, Prev);
7110 end if; 7140 end if;
7111 7141
7428 7458
7429 -- Obj : ...; 7459 -- Obj : ...;
7430 -- Ren : ... renames Obj; 7460 -- Ren : ... renames Obj;
7431 7461
7432 if Is_Entity_Name (Ren) then 7462 if Is_Entity_Name (Ren) then
7433 Id := Entity (Ren); 7463
7464 -- Do not follow a renaming that goes through a generic formal,
7465 -- because these entities are hidden and must not be referenced
7466 -- from outside the generic.
7467
7468 if Is_Hidden (Entity (Ren)) then
7469 exit;
7470
7471 else
7472 Id := Entity (Ren);
7473 end if;
7434 7474
7435 -- The reference renames a function result. Check the original 7475 -- The reference renames a function result. Check the original
7436 -- node in case expansion relocates the function call. 7476 -- node in case expansion relocates the function call.
7437 7477
7438 -- Ren : ... renames Func_Call; 7478 -- Ren : ... renames Func_Call;
7451 end loop; 7491 end loop;
7452 end if; 7492 end if;
7453 7493
7454 return Id; 7494 return Id;
7455 end Entity_Of; 7495 end Entity_Of;
7496
7497 --------------------------
7498 -- Examine_Array_Bounds --
7499 --------------------------
7500
7501 procedure Examine_Array_Bounds
7502 (Typ : Entity_Id;
7503 All_Static : out Boolean;
7504 Has_Empty : out Boolean)
7505 is
7506 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7507 -- Determine whether bound Bound is a suitable static bound
7508
7509 ------------------------
7510 -- Is_OK_Static_Bound --
7511 ------------------------
7512
7513 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7514 begin
7515 return
7516 not Error_Posted (Bound)
7517 and then Is_OK_Static_Expression (Bound);
7518 end Is_OK_Static_Bound;
7519
7520 -- Local variables
7521
7522 Hi_Bound : Node_Id;
7523 Index : Node_Id;
7524 Lo_Bound : Node_Id;
7525
7526 -- Start of processing for Examine_Array_Bounds
7527
7528 begin
7529 -- An unconstrained array type does not have static bounds, and it is
7530 -- not known whether they are empty or not.
7531
7532 if not Is_Constrained (Typ) then
7533 All_Static := False;
7534 Has_Empty := False;
7535
7536 -- A string literal has static bounds, and is not empty as long as it
7537 -- contains at least one character.
7538
7539 elsif Ekind (Typ) = E_String_Literal_Subtype then
7540 All_Static := True;
7541 Has_Empty := String_Literal_Length (Typ) > 0;
7542 end if;
7543
7544 -- Assume that all bounds are static and not empty
7545
7546 All_Static := True;
7547 Has_Empty := False;
7548
7549 -- Examine each index
7550
7551 Index := First_Index (Typ);
7552 while Present (Index) loop
7553 if Is_Discrete_Type (Etype (Index)) then
7554 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7555
7556 if Is_OK_Static_Bound (Lo_Bound)
7557 and then
7558 Is_OK_Static_Bound (Hi_Bound)
7559 then
7560 -- The static bounds produce an empty range
7561
7562 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7563 Has_Empty := True;
7564 end if;
7565
7566 -- Otherwise at least one of the bounds is not static
7567
7568 else
7569 All_Static := False;
7570 end if;
7571
7572 -- Otherwise the index is non-discrete, therefore not static
7573
7574 else
7575 All_Static := False;
7576 end if;
7577
7578 Next_Index (Index);
7579 end loop;
7580 end Examine_Array_Bounds;
7456 7581
7457 -------------------------- 7582 --------------------------
7458 -- Explain_Limited_Type -- 7583 -- Explain_Limited_Type --
7459 -------------------------- 7584 --------------------------
7460 7585
7833 -- Should always find it 7958 -- Should always find it
7834 7959
7835 raise Program_Error; 7960 raise Program_Error;
7836 end Find_Corresponding_Discriminant; 7961 end Find_Corresponding_Discriminant;
7837 7962
7963 -------------------
7964 -- Find_DIC_Type --
7965 -------------------
7966
7967 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
7968 Curr_Typ : Entity_Id;
7969 -- The current type being examined in the parent hierarchy traversal
7970
7971 DIC_Typ : Entity_Id;
7972 -- The type which carries the DIC pragma. This variable denotes the
7973 -- partial view when private types are involved.
7974
7975 Par_Typ : Entity_Id;
7976 -- The parent type of the current type. This variable denotes the full
7977 -- view when private types are involved.
7978
7979 begin
7980 -- The input type defines its own DIC pragma, therefore it is the owner
7981
7982 if Has_Own_DIC (Typ) then
7983 DIC_Typ := Typ;
7984
7985 -- Otherwise the DIC pragma is inherited from a parent type
7986
7987 else
7988 pragma Assert (Has_Inherited_DIC (Typ));
7989
7990 -- Climb the parent chain
7991
7992 Curr_Typ := Typ;
7993 loop
7994 -- Inspect the parent type. Do not consider subtypes as they
7995 -- inherit the DIC attributes from their base types.
7996
7997 DIC_Typ := Base_Type (Etype (Curr_Typ));
7998
7999 -- Look at the full view of a private type because the type may
8000 -- have a hidden parent introduced in the full view.
8001
8002 Par_Typ := DIC_Typ;
8003
8004 if Is_Private_Type (Par_Typ)
8005 and then Present (Full_View (Par_Typ))
8006 then
8007 Par_Typ := Full_View (Par_Typ);
8008 end if;
8009
8010 -- Stop the climb once the nearest parent type which defines a DIC
8011 -- pragma of its own is encountered or when the root of the parent
8012 -- chain is reached.
8013
8014 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8015
8016 Curr_Typ := Par_Typ;
8017 end loop;
8018 end if;
8019
8020 return DIC_Typ;
8021 end Find_DIC_Type;
8022
7838 ---------------------------------- 8023 ----------------------------------
7839 -- Find_Enclosing_Iterator_Loop -- 8024 -- Find_Enclosing_Iterator_Loop --
7840 ---------------------------------- 8025 ----------------------------------
7841 8026
7842 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is 8027 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7873 -------------------------- 8058 --------------------------
7874 -- Find_Enclosing_Scope -- 8059 -- Find_Enclosing_Scope --
7875 -------------------------- 8060 --------------------------
7876 8061
7877 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is 8062 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
7878 Par : Node_Id; 8063 Par : Node_Id;
7879 Spec_Id : Entity_Id;
7880 8064
7881 begin 8065 begin
7882 -- Examine the parent chain looking for a construct which defines a 8066 -- Examine the parent chain looking for a construct which defines a
7883 -- scope. 8067 -- scope.
7884 8068
7903 | N_Task_Type_Declaration 8087 | N_Task_Type_Declaration
7904 => 8088 =>
7905 return Defining_Entity (Par); 8089 return Defining_Entity (Par);
7906 8090
7907 -- The construct denotes a body, the proper scope is the entity of 8091 -- The construct denotes a body, the proper scope is the entity of
7908 -- the corresponding spec. 8092 -- the corresponding spec or that of the body if the body does not
8093 -- complete a previous declaration.
7909 8094
7910 when N_Entry_Body 8095 when N_Entry_Body
7911 | N_Package_Body 8096 | N_Package_Body
7912 | N_Protected_Body 8097 | N_Protected_Body
7913 | N_Subprogram_Body 8098 | N_Subprogram_Body
7914 | N_Task_Body 8099 | N_Task_Body
7915 => 8100 =>
7916 Spec_Id := Corresponding_Spec (Par); 8101 return Unique_Defining_Entity (Par);
7917
7918 -- The defining entity of a stand-alone subprogram body defines
7919 -- a scope.
7920
7921 if Nkind (Par) = N_Subprogram_Body and then No (Spec_Id) then
7922 return Defining_Entity (Par);
7923
7924 -- Otherwise there should be corresponding spec which defines a
7925 -- scope.
7926
7927 else
7928 pragma Assert (Present (Spec_Id));
7929
7930 return Spec_Id;
7931 end if;
7932 8102
7933 -- Special cases 8103 -- Special cases
7934 8104
7935 -- Blocks carry either a source or an internally-generated scope, 8105 -- Blocks carry either a source or an internally-generated scope,
7936 -- unless the block is a byproduct of exception handling. 8106 -- unless the block is a byproduct of exception handling.
8172 end if; 8342 end if;
8173 8343
8174 Context := Scope (Context); 8344 Context := Scope (Context);
8175 end loop; 8345 end loop;
8176 end Find_Placement_In_State_Space; 8346 end Find_Placement_In_State_Space;
8347
8348 -----------------------
8349 -- Find_Primitive_Eq --
8350 -----------------------
8351
8352 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8353 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8354 -- Search for the equality primitive; return Empty if the primitive is
8355 -- not found.
8356
8357 ------------------
8358 -- Find_Eq_Prim --
8359 ------------------
8360
8361 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8362 Prim : Entity_Id;
8363 Prim_Elmt : Elmt_Id;
8364
8365 begin
8366 Prim_Elmt := First_Elmt (Prims_List);
8367 while Present (Prim_Elmt) loop
8368 Prim := Node (Prim_Elmt);
8369
8370 -- Locate primitive equality with the right signature
8371
8372 if Chars (Prim) = Name_Op_Eq
8373 and then Etype (First_Formal (Prim)) =
8374 Etype (Next_Formal (First_Formal (Prim)))
8375 and then Base_Type (Etype (Prim)) = Standard_Boolean
8376 then
8377 return Prim;
8378 end if;
8379
8380 Next_Elmt (Prim_Elmt);
8381 end loop;
8382
8383 return Empty;
8384 end Find_Eq_Prim;
8385
8386 -- Local Variables
8387
8388 Eq_Prim : Entity_Id;
8389 Full_Type : Entity_Id;
8390
8391 -- Start of processing for Find_Primitive_Eq
8392
8393 begin
8394 if Is_Private_Type (Typ) then
8395 Full_Type := Underlying_Type (Typ);
8396 else
8397 Full_Type := Typ;
8398 end if;
8399
8400 if No (Full_Type) then
8401 return Empty;
8402 end if;
8403
8404 Full_Type := Base_Type (Full_Type);
8405
8406 -- When the base type itself is private, use the full view
8407
8408 if Is_Private_Type (Full_Type) then
8409 Full_Type := Underlying_Type (Full_Type);
8410 end if;
8411
8412 if Is_Class_Wide_Type (Full_Type) then
8413 Full_Type := Root_Type (Full_Type);
8414 end if;
8415
8416 if not Is_Tagged_Type (Full_Type) then
8417 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8418
8419 -- If this is an untagged private type completed with a derivation of
8420 -- an untagged private type whose full view is a tagged type, we use
8421 -- the primitive operations of the private parent type (since it does
8422 -- not have a full view, and also because its equality primitive may
8423 -- have been overridden in its untagged full view). If no equality was
8424 -- defined for it then take its dispatching equality primitive.
8425
8426 elsif Inherits_From_Tagged_Full_View (Typ) then
8427 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8428
8429 if No (Eq_Prim) then
8430 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8431 end if;
8432
8433 else
8434 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8435 end if;
8436
8437 return Eq_Prim;
8438 end Find_Primitive_Eq;
8177 8439
8178 ------------------------ 8440 ------------------------
8179 -- Find_Specific_Type -- 8441 -- Find_Specific_Type --
8180 ------------------------ 8442 ------------------------
8181 8443
8558 -- The discriminant *must* be in the Governed_By List 8820 -- The discriminant *must* be in the Governed_By List
8559 8821
8560 Assoc := First (Governed_By); 8822 Assoc := First (Governed_By);
8561 Find_Constraint : loop 8823 Find_Constraint : loop
8562 Discrim := First (Choices (Assoc)); 8824 Discrim := First (Choices (Assoc));
8563 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim) 8825 exit Find_Constraint when
8564 or else (Present (Corresponding_Discriminant (Entity (Discrim))) 8826 Chars (Discrim_Name) = Chars (Discrim)
8565 and then 8827 or else
8566 Chars (Corresponding_Discriminant (Entity (Discrim))) = 8828 (Present (Corresponding_Discriminant (Entity (Discrim)))
8567 Chars (Discrim_Name)) 8829 and then Chars (Corresponding_Discriminant
8568 or else Chars (Original_Record_Component (Entity (Discrim))) 8830 (Entity (Discrim))) = Chars (Discrim_Name))
8569 = Chars (Discrim_Name); 8831 or else
8832 Chars (Original_Record_Component (Entity (Discrim))) =
8833 Chars (Discrim_Name);
8570 8834
8571 if No (Next (Assoc)) then 8835 if No (Next (Assoc)) then
8572 if not Is_Constrained (Typ) 8836 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
8573 and then Is_Derived_Type (Typ) 8837
8574 and then Present (Stored_Constraint (Typ))
8575 then
8576 -- If the type is a tagged type with inherited discriminants, 8838 -- If the type is a tagged type with inherited discriminants,
8577 -- use the stored constraint on the parent in order to find 8839 -- use the stored constraint on the parent in order to find
8578 -- the values of discriminants that are otherwise hidden by an 8840 -- the values of discriminants that are otherwise hidden by an
8579 -- explicit constraint. Renamed discriminants are handled in 8841 -- explicit constraint. Renamed discriminants are handled in
8580 -- the code above. 8842 -- the code above.
8583 -- discriminant of the derived type, the call to obtain the 8845 -- discriminant of the derived type, the call to obtain the
8584 -- Corresponding_Discriminant field only retrieves the last 8846 -- Corresponding_Discriminant field only retrieves the last
8585 -- of them. We recover the constraint on the others from the 8847 -- of them. We recover the constraint on the others from the
8586 -- Stored_Constraint as well. 8848 -- Stored_Constraint as well.
8587 8849
8850 -- An inherited discriminant may have been constrained in a
8851 -- later ancestor (not the immediate parent) so we must examine
8852 -- the stored constraint of all of them to locate the inherited
8853 -- value.
8854
8588 declare 8855 declare
8856 C : Elmt_Id;
8589 D : Entity_Id; 8857 D : Entity_Id;
8590 C : Elmt_Id; 8858 T : Entity_Id := Typ;
8591 8859
8592 begin 8860 begin
8593 D := First_Discriminant (Etype (Typ)); 8861 while Is_Derived_Type (T) loop
8594 C := First_Elmt (Stored_Constraint (Typ)); 8862 if Present (Stored_Constraint (T)) then
8595 while Present (D) and then Present (C) loop 8863 D := First_Discriminant (Etype (T));
8596 if Chars (Discrim_Name) = Chars (D) then 8864 C := First_Elmt (Stored_Constraint (T));
8597 if Is_Entity_Name (Node (C)) 8865 while Present (D) and then Present (C) loop
8598 and then Entity (Node (C)) = Entity (Discrim) 8866 if Chars (Discrim_Name) = Chars (D) then
8599 then 8867 if Is_Entity_Name (Node (C))
8600 -- D is renamed by Discrim, whose value is given in 8868 and then Entity (Node (C)) = Entity (Discrim)
8601 -- Assoc. 8869 then
8602 8870 -- D is renamed by Discrim, whose value is
8603 null; 8871 -- given in Assoc.
8604 8872
8605 else 8873 null;
8606 Assoc := 8874
8607 Make_Component_Association (Sloc (Typ), 8875 else
8608 New_List 8876 Assoc :=
8609 (New_Occurrence_Of (D, Sloc (Typ))), 8877 Make_Component_Association (Sloc (Typ),
8610 Duplicate_Subexpr_No_Checks (Node (C))); 8878 New_List
8611 end if; 8879 (New_Occurrence_Of (D, Sloc (Typ))),
8612 exit Find_Constraint; 8880 Duplicate_Subexpr_No_Checks (Node (C)));
8881 end if;
8882
8883 exit Find_Constraint;
8884 end if;
8885
8886 Next_Discriminant (D);
8887 Next_Elmt (C);
8888 end loop;
8613 end if; 8889 end if;
8614 8890
8615 Next_Discriminant (D); 8891 -- Discriminant may be inherited from ancestor
8616 Next_Elmt (C); 8892
8893 T := Etype (T);
8617 end loop; 8894 end loop;
8618 end; 8895 end;
8619 end if; 8896 end if;
8620 end if; 8897 end if;
8621 8898
8622 if No (Next (Assoc)) then 8899 if No (Next (Assoc)) then
8623 Error_Msg_NE (" missing value for discriminant&", 8900 Error_Msg_NE
8624 First (Governed_By), Discrim_Name); 8901 (" missing value for discriminant&",
8902 First (Governed_By), Discrim_Name);
8903
8625 Report_Errors := True; 8904 Report_Errors := True;
8626 return; 8905 return;
8627 end if; 8906 end if;
8628 8907
8629 Next (Assoc); 8908 Next (Assoc);
9017 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then 9296 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9018 Btyp := Full_View (Btyp); 9297 Btyp := Full_View (Btyp);
9019 end if; 9298 end if;
9020 9299
9021 Lit := First_Literal (Btyp); 9300 Lit := First_Literal (Btyp);
9301
9302 -- Position in the enumeration type starts at 0
9303
9304 if UI_To_Int (Pos) < 0 then
9305 raise Constraint_Error;
9306 end if;
9307
9022 for J in 1 .. UI_To_Int (Pos) loop 9308 for J in 1 .. UI_To_Int (Pos) loop
9023 Next_Literal (Lit); 9309 Next_Literal (Lit);
9024 9310
9025 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error 9311 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9026 -- inside the loop to avoid calling Next_Literal on Empty. 9312 -- inside the loop to avoid calling Next_Literal on Empty.
9313 return Empty; 9599 return Empty;
9314 end if; 9600 end if;
9315 end Get_Iterable_Type_Primitive; 9601 end Get_Iterable_Type_Primitive;
9316 9602
9317 ---------------------------------- 9603 ----------------------------------
9318 -- Get_Library_Unit_Name_string -- 9604 -- Get_Library_Unit_Name_String --
9319 ---------------------------------- 9605 ----------------------------------
9320 9606
9321 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is 9607 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9322 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node); 9608 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9323 9609
10295 -------------------------------- 10581 --------------------------------
10296 -- State_Has_Enabled_Property -- 10582 -- State_Has_Enabled_Property --
10297 -------------------------------- 10583 --------------------------------
10298 10584
10299 function State_Has_Enabled_Property return Boolean is 10585 function State_Has_Enabled_Property return Boolean is
10300 Decl : constant Node_Id := Parent (Item_Id); 10586 Decl : constant Node_Id := Parent (Item_Id);
10301 Opt : Node_Id; 10587
10302 Opt_Nam : Node_Id; 10588 procedure Find_Simple_Properties
10303 Prop : Node_Id; 10589 (Has_External : out Boolean;
10304 Prop_Nam : Node_Id; 10590 Has_Synchronous : out Boolean);
10305 Props : Node_Id; 10591 -- Extract the simple properties associated with declaration Decl
10592
10593 function Is_Enabled_External_Property return Boolean;
10594 -- Determine whether property Property appears within the external
10595 -- property list of declaration Decl, and return its status.
10596
10597 ----------------------------
10598 -- Find_Simple_Properties --
10599 ----------------------------
10600
10601 procedure Find_Simple_Properties
10602 (Has_External : out Boolean;
10603 Has_Synchronous : out Boolean)
10604 is
10605 Opt : Node_Id;
10606
10607 begin
10608 -- Assume that none of the properties are available
10609
10610 Has_External := False;
10611 Has_Synchronous := False;
10612
10613 Opt := First (Expressions (Decl));
10614 while Present (Opt) loop
10615 if Nkind (Opt) = N_Identifier then
10616 if Chars (Opt) = Name_External then
10617 Has_External := True;
10618
10619 elsif Chars (Opt) = Name_Synchronous then
10620 Has_Synchronous := True;
10621 end if;
10622 end if;
10623
10624 Next (Opt);
10625 end loop;
10626 end Find_Simple_Properties;
10627
10628 ----------------------------------
10629 -- Is_Enabled_External_Property --
10630 ----------------------------------
10631
10632 function Is_Enabled_External_Property return Boolean is
10633 Opt : Node_Id;
10634 Opt_Nam : Node_Id;
10635 Prop : Node_Id;
10636 Prop_Nam : Node_Id;
10637 Props : Node_Id;
10638
10639 begin
10640 Opt := First (Component_Associations (Decl));
10641 while Present (Opt) loop
10642 Opt_Nam := First (Choices (Opt));
10643
10644 if Nkind (Opt_Nam) = N_Identifier
10645 and then Chars (Opt_Nam) = Name_External
10646 then
10647 Props := Expression (Opt);
10648
10649 -- Multiple properties appear as an aggregate
10650
10651 if Nkind (Props) = N_Aggregate then
10652
10653 -- Simple property form
10654
10655 Prop := First (Expressions (Props));
10656 while Present (Prop) loop
10657 if Chars (Prop) = Property then
10658 return True;
10659 end if;
10660
10661 Next (Prop);
10662 end loop;
10663
10664 -- Property with expression form
10665
10666 Prop := First (Component_Associations (Props));
10667 while Present (Prop) loop
10668 Prop_Nam := First (Choices (Prop));
10669
10670 -- The property can be represented in two ways:
10671 -- others => <value>
10672 -- <property> => <value>
10673
10674 if Nkind (Prop_Nam) = N_Others_Choice
10675 or else (Nkind (Prop_Nam) = N_Identifier
10676 and then Chars (Prop_Nam) = Property)
10677 then
10678 return Is_True (Expr_Value (Expression (Prop)));
10679 end if;
10680
10681 Next (Prop);
10682 end loop;
10683
10684 -- Single property
10685
10686 else
10687 return Chars (Props) = Property;
10688 end if;
10689 end if;
10690
10691 Next (Opt);
10692 end loop;
10693
10694 return False;
10695 end Is_Enabled_External_Property;
10696
10697 -- Local variables
10698
10699 Has_External : Boolean;
10700 Has_Synchronous : Boolean;
10701
10702 -- Start of processing for State_Has_Enabled_Property
10306 10703
10307 begin 10704 begin
10308 -- The declaration of an external abstract state appears as an 10705 -- The declaration of an external abstract state appears as an
10309 -- extension aggregate. If this is not the case, properties can never 10706 -- extension aggregate. If this is not the case, properties can
10310 -- be set. 10707 -- never be set.
10311 10708
10312 if Nkind (Decl) /= N_Extension_Aggregate then 10709 if Nkind (Decl) /= N_Extension_Aggregate then
10313 return False; 10710 return False;
10314 end if; 10711 end if;
10315 10712
10316 -- When External appears as a simple option, it automatically enables 10713 Find_Simple_Properties (Has_External, Has_Synchronous);
10317 -- all properties. 10714
10318 10715 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10319 Opt := First (Expressions (Decl)); 10716
10320 while Present (Opt) loop 10717 if Has_External then
10321 if Nkind (Opt) = N_Identifier 10718 return True;
10322 and then Chars (Opt) = Name_External 10719
10323 then 10720 -- Option External may enable or disable specific properties
10324 return True; 10721
10325 end if; 10722 elsif Is_Enabled_External_Property then
10326 10723 return True;
10327 Next (Opt); 10724
10328 end loop; 10725 -- Simple option Synchronous
10329 10726 --
10330 -- When External specifies particular properties, inspect those and 10727 -- enables disables
10331 -- find the desired one (if any). 10728 -- Asynch_Readers Effective_Reads
10332 10729 -- Asynch_Writers Effective_Writes
10333 Opt := First (Component_Associations (Decl)); 10730 --
10334 while Present (Opt) loop 10731 -- Note that both forms of External have higher precedence than
10335 Opt_Nam := First (Choices (Opt)); 10732 -- Synchronous (SPARK RM 7.1.4(10)).
10336 10733
10337 if Nkind (Opt_Nam) = N_Identifier 10734 elsif Has_Synchronous then
10338 and then Chars (Opt_Nam) = Name_External 10735 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10339 then 10736 end if;
10340 Props := Expression (Opt);
10341
10342 -- Multiple properties appear as an aggregate
10343
10344 if Nkind (Props) = N_Aggregate then
10345
10346 -- Simple property form
10347
10348 Prop := First (Expressions (Props));
10349 while Present (Prop) loop
10350 if Chars (Prop) = Property then
10351 return True;
10352 end if;
10353
10354 Next (Prop);
10355 end loop;
10356
10357 -- Property with expression form
10358
10359 Prop := First (Component_Associations (Props));
10360 while Present (Prop) loop
10361 Prop_Nam := First (Choices (Prop));
10362
10363 -- The property can be represented in two ways:
10364 -- others => <value>
10365 -- <property> => <value>
10366
10367 if Nkind (Prop_Nam) = N_Others_Choice
10368 or else (Nkind (Prop_Nam) = N_Identifier
10369 and then Chars (Prop_Nam) = Property)
10370 then
10371 return Is_True (Expr_Value (Expression (Prop)));
10372 end if;
10373
10374 Next (Prop);
10375 end loop;
10376
10377 -- Single property
10378
10379 else
10380 return Chars (Props) = Property;
10381 end if;
10382 end if;
10383
10384 Next (Opt);
10385 end loop;
10386 10737
10387 return False; 10738 return False;
10388 end State_Has_Enabled_Property; 10739 end State_Has_Enabled_Property;
10389 10740
10390 ----------------------------------- 10741 -----------------------------------
10512 -- Has_Full_Default_Initialization -- 10863 -- Has_Full_Default_Initialization --
10513 ------------------------------------- 10864 -------------------------------------
10514 10865
10515 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is 10866 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10516 Comp : Entity_Id; 10867 Comp : Entity_Id;
10517 Prag : Node_Id; 10868
10518 10869 begin
10519 begin 10870 -- A type subject to pragma Default_Initial_Condition may be fully
10520 -- A type subject to pragma Default_Initial_Condition is fully default 10871 -- default initialized depending on inheritance and the argument of
10521 -- initialized when the pragma appears with a non-null argument. Since 10872 -- the pragma. Since any type may act as the full view of a private
10522 -- any type may act as the full view of a private type, this check must 10873 -- type, this check must be performed prior to the specialized tests
10523 -- be performed prior to the specialized tests below. 10874 -- below.
10524 10875
10525 if Has_DIC (Typ) then 10876 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10526 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition); 10877 return True;
10527 pragma Assert (Present (Prag));
10528
10529 return Is_Verifiable_DIC_Pragma (Prag);
10530 end if; 10878 end if;
10531 10879
10532 -- A scalar type is fully default initialized if it is subject to aspect 10880 -- A scalar type is fully default initialized if it is subject to aspect
10533 -- Default_Value. 10881 -- Default_Value.
10534 10882
10591 else 10939 else
10592 return False; 10940 return False;
10593 end if; 10941 end if;
10594 end Has_Full_Default_Initialization; 10942 end Has_Full_Default_Initialization;
10595 10943
10944 -----------------------------------------------
10945 -- Has_Fully_Default_Initializing_DIC_Pragma --
10946 -----------------------------------------------
10947
10948 function Has_Fully_Default_Initializing_DIC_Pragma
10949 (Typ : Entity_Id) return Boolean
10950 is
10951 Args : List_Id;
10952 Prag : Node_Id;
10953
10954 begin
10955 -- A type that inherits pragma Default_Initial_Condition from a parent
10956 -- type is automatically fully default initialized.
10957
10958 if Has_Inherited_DIC (Typ) then
10959 return True;
10960
10961 -- Otherwise the type is fully default initialized only when the pragma
10962 -- appears without an argument, or the argument is non-null.
10963
10964 elsif Has_Own_DIC (Typ) then
10965 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10966 pragma Assert (Present (Prag));
10967 Args := Pragma_Argument_Associations (Prag);
10968
10969 -- The pragma appears without an argument in which case it defaults
10970 -- to True.
10971
10972 if No (Args) then
10973 return True;
10974
10975 -- The pragma appears with a non-null expression
10976
10977 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
10978 return True;
10979 end if;
10980 end if;
10981
10982 return False;
10983 end Has_Fully_Default_Initializing_DIC_Pragma;
10984
10596 -------------------- 10985 --------------------
10597 -- Has_Infinities -- 10986 -- Has_Infinities --
10598 -------------------- 10987 --------------------
10599 10988
10600 function Has_Infinities (E : Entity_Id) return Boolean is 10989 function Has_Infinities (E : Entity_Id) return Boolean is
10746 11135
10747 return 11136 return
10748 Present (Constits) 11137 Present (Constits)
10749 and then Nkind (Node (First_Elmt (Constits))) /= N_Null; 11138 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
10750 end Has_Non_Null_Refinement; 11139 end Has_Non_Null_Refinement;
11140
11141 -----------------------------
11142 -- Has_Non_Null_Statements --
11143 -----------------------------
11144
11145 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11146 Node : Node_Id;
11147
11148 begin
11149 if Is_Non_Empty_List (L) then
11150 Node := First (L);
11151
11152 loop
11153 if Nkind (Node) /= N_Null_Statement then
11154 return True;
11155 end if;
11156
11157 Next (Node);
11158 exit when Node = Empty;
11159 end loop;
11160 end if;
11161
11162 return False;
11163 end Has_Non_Null_Statements;
10751 11164
10752 ---------------------------------- 11165 ----------------------------------
10753 -- Has_Non_Trivial_Precondition -- 11166 -- Has_Non_Trivial_Precondition --
10754 ---------------------------------- 11167 ----------------------------------
10755 11168
11170 end if; 11583 end if;
11171 11584
11172 return Has_PE; 11585 return Has_PE;
11173 end Has_Preelaborable_Initialization; 11586 end Has_Preelaborable_Initialization;
11174 11587
11588 ----------------
11589 -- Has_Prefix --
11590 ----------------
11591
11592 function Has_Prefix (N : Node_Id) return Boolean is
11593 begin
11594 return
11595 Nkind_In (N, N_Attribute_Reference,
11596 N_Expanded_Name,
11597 N_Explicit_Dereference,
11598 N_Indexed_Component,
11599 N_Reference,
11600 N_Selected_Component,
11601 N_Slice);
11602 end Has_Prefix;
11603
11175 --------------------------- 11604 ---------------------------
11176 -- Has_Private_Component -- 11605 -- Has_Private_Component --
11177 --------------------------- 11606 ---------------------------
11178 11607
11179 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is 11608 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11280 ----------------------------- 11709 -----------------------------
11281 -- Has_Static_Array_Bounds -- 11710 -- Has_Static_Array_Bounds --
11282 ----------------------------- 11711 -----------------------------
11283 11712
11284 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is 11713 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11285 Ndims : constant Nat := Number_Dimensions (Typ); 11714 All_Static : Boolean;
11286 11715 Dummy : Boolean;
11287 Index : Node_Id; 11716
11288 Low : Node_Id; 11717 begin
11289 High : Node_Id; 11718 Examine_Array_Bounds (Typ, All_Static, Dummy);
11290 11719
11291 begin 11720 return All_Static;
11292 -- Unconstrained types do not have static bounds
11293
11294 if not Is_Constrained (Typ) then
11295 return False;
11296 end if;
11297
11298 -- First treat string literals specially, as the lower bound and length
11299 -- of string literals are not stored like those of arrays.
11300
11301 -- A string literal always has static bounds
11302
11303 if Ekind (Typ) = E_String_Literal_Subtype then
11304 return True;
11305 end if;
11306
11307 -- Treat all dimensions in turn
11308
11309 Index := First_Index (Typ);
11310 for Indx in 1 .. Ndims loop
11311
11312 -- In case of an illegal index which is not a discrete type, return
11313 -- that the type is not static.
11314
11315 if not Is_Discrete_Type (Etype (Index))
11316 or else Etype (Index) = Any_Type
11317 then
11318 return False;
11319 end if;
11320
11321 Get_Index_Bounds (Index, Low, High);
11322
11323 if Error_Posted (Low) or else Error_Posted (High) then
11324 return False;
11325 end if;
11326
11327 if Is_OK_Static_Expression (Low)
11328 and then
11329 Is_OK_Static_Expression (High)
11330 then
11331 null;
11332 else
11333 return False;
11334 end if;
11335
11336 Next (Index);
11337 end loop;
11338
11339 -- If we fall through the loop, all indexes matched
11340
11341 return True;
11342 end Has_Static_Array_Bounds; 11721 end Has_Static_Array_Bounds;
11722
11723 ---------------------------------------
11724 -- Has_Static_Non_Empty_Array_Bounds --
11725 ---------------------------------------
11726
11727 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11728 All_Static : Boolean;
11729 Has_Empty : Boolean;
11730
11731 begin
11732 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11733
11734 return All_Static and not Has_Empty;
11735 end Has_Static_Non_Empty_Array_Bounds;
11343 11736
11344 ---------------- 11737 ----------------
11345 -- Has_Stream -- 11738 -- Has_Stream --
11346 ---------------- 11739 ----------------
11347 11740
11932 return Present (Btyp) 12325 return Present (Btyp)
11933 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp)) 12326 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
11934 and then Reverse_Storage_Order (Btyp); 12327 and then Reverse_Storage_Order (Btyp);
11935 end In_Reverse_Storage_Order_Object; 12328 end In_Reverse_Storage_Order_Object;
11936 12329
12330 ------------------------------
12331 -- In_Same_Declarative_Part --
12332 ------------------------------
12333
12334 function In_Same_Declarative_Part
12335 (Context : Node_Id;
12336 N : Node_Id) return Boolean
12337 is
12338 Cont : Node_Id := Context;
12339 Nod : Node_Id;
12340
12341 begin
12342 if Nkind (Cont) = N_Compilation_Unit_Aux then
12343 Cont := Parent (Cont);
12344 end if;
12345
12346 Nod := Parent (N);
12347 while Present (Nod) loop
12348 if Nod = Cont then
12349 return True;
12350
12351 elsif Nkind_In (Nod, N_Accept_Statement,
12352 N_Block_Statement,
12353 N_Compilation_Unit,
12354 N_Entry_Body,
12355 N_Package_Body,
12356 N_Package_Declaration,
12357 N_Protected_Body,
12358 N_Subprogram_Body,
12359 N_Task_Body)
12360 then
12361 return False;
12362
12363 elsif Nkind (Nod) = N_Subunit then
12364 Nod := Corresponding_Stub (Nod);
12365
12366 else
12367 Nod := Parent (Nod);
12368 end if;
12369 end loop;
12370
12371 return False;
12372 end In_Same_Declarative_Part;
12373
11937 -------------------------------------- 12374 --------------------------------------
11938 -- In_Subprogram_Or_Concurrent_Unit -- 12375 -- In_Subprogram_Or_Concurrent_Unit --
11939 -------------------------------------- 12376 --------------------------------------
11940 12377
11941 function In_Subprogram_Or_Concurrent_Unit return Boolean is 12378 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12144 12581
12145 -- The type has no incomplete or private view 12582 -- The type has no incomplete or private view
12146 12583
12147 return Empty; 12584 return Empty;
12148 end Incomplete_Or_Partial_View; 12585 end Incomplete_Or_Partial_View;
12586
12587 ---------------------------------------
12588 -- Incomplete_View_From_Limited_With --
12589 ---------------------------------------
12590
12591 function Incomplete_View_From_Limited_With
12592 (Typ : Entity_Id) return Entity_Id
12593 is
12594 begin
12595 -- It might make sense to make this an attribute in Einfo, and set it
12596 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12597 -- slots for new attributes, and it seems a bit simpler to just search
12598 -- the Limited_View (if it exists) for an incomplete type whose
12599 -- Non_Limited_View is Typ.
12600
12601 if Ekind (Scope (Typ)) = E_Package
12602 and then Present (Limited_View (Scope (Typ)))
12603 then
12604 declare
12605 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12606 begin
12607 while Present (Ent) loop
12608 if Ekind (Ent) in Incomplete_Kind
12609 and then Non_Limited_View (Ent) = Typ
12610 then
12611 return Ent;
12612 end if;
12613
12614 Ent := Next_Entity (Ent);
12615 end loop;
12616 end;
12617 end if;
12618
12619 return Typ;
12620 end Incomplete_View_From_Limited_With;
12149 12621
12150 ---------------------------------- 12622 ----------------------------------
12151 -- Indexed_Component_Bit_Offset -- 12623 -- Indexed_Component_Bit_Offset --
12152 ---------------------------------- 12624 ----------------------------------
12153 12625
12342 else 12814 else
12343 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ)); 12815 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12344 end if; 12816 end if;
12345 end if; 12817 end if;
12346 end Inherit_Rep_Item_Chain; 12818 end Inherit_Rep_Item_Chain;
12819
12820 ------------------------------------
12821 -- Inherits_From_Tagged_Full_View --
12822 ------------------------------------
12823
12824 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
12825 begin
12826 return Is_Private_Type (Typ)
12827 and then Present (Full_View (Typ))
12828 and then Is_Private_Type (Full_View (Typ))
12829 and then not Is_Tagged_Type (Full_View (Typ))
12830 and then Present (Underlying_Type (Full_View (Typ)))
12831 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
12832 end Inherits_From_Tagged_Full_View;
12347 12833
12348 --------------------------------- 12834 ---------------------------------
12349 -- Insert_Explicit_Dereference -- 12835 -- Insert_Explicit_Dereference --
12350 --------------------------------- 12836 ---------------------------------
12351 12837
12455 12941
12456 Decl := Next (Decl); 12942 Decl := Next (Decl);
12457 end loop; 12943 end loop;
12458 end Inspect_Deferred_Constant_Completion; 12944 end Inspect_Deferred_Constant_Completion;
12459 12945
12946 -------------------------------
12947 -- Install_Elaboration_Model --
12948 -------------------------------
12949
12950 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
12951 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
12952 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
12953 -- Empty if there is no such pragma.
12954
12955 ------------------------------------
12956 -- Find_Elaboration_Checks_Pragma --
12957 ------------------------------------
12958
12959 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
12960 Item : Node_Id;
12961
12962 begin
12963 Item := First (L);
12964 while Present (Item) loop
12965 if Nkind (Item) = N_Pragma
12966 and then Pragma_Name (Item) = Name_Elaboration_Checks
12967 then
12968 return Item;
12969 end if;
12970
12971 Next (Item);
12972 end loop;
12973
12974 return Empty;
12975 end Find_Elaboration_Checks_Pragma;
12976
12977 -- Local variables
12978
12979 Args : List_Id;
12980 Model : Node_Id;
12981 Prag : Node_Id;
12982 Unit : Node_Id;
12983
12984 -- Start of processing for Install_Elaboration_Model
12985
12986 begin
12987 -- Nothing to do when the unit does not exist
12988
12989 if No (Unit_Id) then
12990 return;
12991 end if;
12992
12993 Unit := Parent (Unit_Declaration_Node (Unit_Id));
12994
12995 -- Nothing to do when the unit is not a library unit
12996
12997 if Nkind (Unit) /= N_Compilation_Unit then
12998 return;
12999 end if;
13000
13001 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13002
13003 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13004 -- elaboration model as specified by the pragma.
13005
13006 if Present (Prag) then
13007 Args := Pragma_Argument_Associations (Prag);
13008
13009 -- Guard against an illegal pragma. The sole argument must be an
13010 -- identifier which specifies either Dynamic or Static model.
13011
13012 if Present (Args) then
13013 Model := Get_Pragma_Arg (First (Args));
13014
13015 if Nkind (Model) = N_Identifier then
13016 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13017 end if;
13018 end if;
13019 end if;
13020 end Install_Elaboration_Model;
13021
12460 ----------------------------- 13022 -----------------------------
12461 -- Install_Generic_Formals -- 13023 -- Install_Generic_Formals --
12462 ----------------------------- 13024 -----------------------------
12463 13025
12464 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is 13026 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12482 begin 13044 begin
12483 SPARK_Mode := Mode; 13045 SPARK_Mode := Mode;
12484 SPARK_Mode_Pragma := Prag; 13046 SPARK_Mode_Pragma := Prag;
12485 end Install_SPARK_Mode; 13047 end Install_SPARK_Mode;
12486 13048
13049 --------------------------
13050 -- Invalid_Scalar_Value --
13051 --------------------------
13052
13053 function Invalid_Scalar_Value
13054 (Loc : Source_Ptr;
13055 Scal_Typ : Scalar_Id) return Node_Id
13056 is
13057 function Invalid_Binder_Value return Node_Id;
13058 -- Return a reference to the corresponding invalid value for type
13059 -- Scal_Typ as defined in unit System.Scalar_Values.
13060
13061 function Invalid_Float_Value return Node_Id;
13062 -- Return the invalid value of float type Scal_Typ
13063
13064 function Invalid_Integer_Value return Node_Id;
13065 -- Return the invalid value of integer type Scal_Typ
13066
13067 procedure Set_Invalid_Binder_Values;
13068 -- Set the contents of collection Invalid_Binder_Values
13069
13070 --------------------------
13071 -- Invalid_Binder_Value --
13072 --------------------------
13073
13074 function Invalid_Binder_Value return Node_Id is
13075 Val_Id : Entity_Id;
13076
13077 begin
13078 -- Initialize the collection of invalid binder values the first time
13079 -- around.
13080
13081 Set_Invalid_Binder_Values;
13082
13083 -- Obtain the corresponding variable from System.Scalar_Values which
13084 -- holds the invalid value for this type.
13085
13086 Val_Id := Invalid_Binder_Values (Scal_Typ);
13087 pragma Assert (Present (Val_Id));
13088
13089 return New_Occurrence_Of (Val_Id, Loc);
13090 end Invalid_Binder_Value;
13091
13092 -------------------------
13093 -- Invalid_Float_Value --
13094 -------------------------
13095
13096 function Invalid_Float_Value return Node_Id is
13097 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13098
13099 begin
13100 -- Pragma Invalid_Scalars did not specify an invalid value for this
13101 -- type. Fall back to the value provided by the binder.
13102
13103 if Value = No_Ureal then
13104 return Invalid_Binder_Value;
13105 else
13106 return Make_Real_Literal (Loc, Realval => Value);
13107 end if;
13108 end Invalid_Float_Value;
13109
13110 ---------------------------
13111 -- Invalid_Integer_Value --
13112 ---------------------------
13113
13114 function Invalid_Integer_Value return Node_Id is
13115 Value : constant Uint := Invalid_Integers (Scal_Typ);
13116
13117 begin
13118 -- Pragma Invalid_Scalars did not specify an invalid value for this
13119 -- type. Fall back to the value provided by the binder.
13120
13121 if Value = No_Uint then
13122 return Invalid_Binder_Value;
13123 else
13124 return Make_Integer_Literal (Loc, Intval => Value);
13125 end if;
13126 end Invalid_Integer_Value;
13127
13128 -------------------------------
13129 -- Set_Invalid_Binder_Values --
13130 -------------------------------
13131
13132 procedure Set_Invalid_Binder_Values is
13133 begin
13134 if not Invalid_Binder_Values_Set then
13135 Invalid_Binder_Values_Set := True;
13136
13137 -- Initialize the contents of the collection once since RTE calls
13138 -- are not cheap.
13139
13140 Invalid_Binder_Values :=
13141 (Name_Short_Float => RTE (RE_IS_Isf),
13142 Name_Float => RTE (RE_IS_Ifl),
13143 Name_Long_Float => RTE (RE_IS_Ilf),
13144 Name_Long_Long_Float => RTE (RE_IS_Ill),
13145 Name_Signed_8 => RTE (RE_IS_Is1),
13146 Name_Signed_16 => RTE (RE_IS_Is2),
13147 Name_Signed_32 => RTE (RE_IS_Is4),
13148 Name_Signed_64 => RTE (RE_IS_Is8),
13149 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13150 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13151 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13152 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13153 end if;
13154 end Set_Invalid_Binder_Values;
13155
13156 -- Start of processing for Invalid_Scalar_Value
13157
13158 begin
13159 if Scal_Typ in Float_Scalar_Id then
13160 return Invalid_Float_Value;
13161
13162 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13163 return Invalid_Integer_Value;
13164 end if;
13165 end Invalid_Scalar_Value;
13166
12487 ----------------------------- 13167 -----------------------------
12488 -- Is_Actual_Out_Parameter -- 13168 -- Is_Actual_Out_Parameter --
12489 ----------------------------- 13169 -----------------------------
12490 13170
12491 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is 13171 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
12619 ---------------------- 13299 ----------------------
12620 -- Is_Atomic_Object -- 13300 -- Is_Atomic_Object --
12621 ---------------------- 13301 ----------------------
12622 13302
12623 function Is_Atomic_Object (N : Node_Id) return Boolean is 13303 function Is_Atomic_Object (N : Node_Id) return Boolean is
12624 13304 function Is_Atomic_Entity (Id : Entity_Id) return Boolean;
12625 function Object_Has_Atomic_Components (N : Node_Id) return Boolean; 13305 pragma Inline (Is_Atomic_Entity);
12626 -- Determines if given object has atomic components 13306 -- Determine whether arbitrary entity Id is either atomic or has atomic
12627 13307 -- components.
12628 function Is_Atomic_Prefix (N : Node_Id) return Boolean; 13308
12629 -- If prefix is an implicit dereference, examine designated type 13309 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean;
13310 -- Determine whether prefix Pref of an indexed or selected component is
13311 -- an atomic object.
13312
13313 ----------------------
13314 -- Is_Atomic_Entity --
13315 ----------------------
13316
13317 function Is_Atomic_Entity (Id : Entity_Id) return Boolean is
13318 begin
13319 return Is_Atomic (Id) or else Has_Atomic_Components (Id);
13320 end Is_Atomic_Entity;
12630 13321
12631 ---------------------- 13322 ----------------------
12632 -- Is_Atomic_Prefix -- 13323 -- Is_Atomic_Prefix --
12633 ---------------------- 13324 ----------------------
12634 13325
12635 function Is_Atomic_Prefix (N : Node_Id) return Boolean is 13326 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean is
13327 Typ : constant Entity_Id := Etype (Pref);
13328
12636 begin 13329 begin
12637 if Is_Access_Type (Etype (N)) then 13330 if Is_Access_Type (Typ) then
12638 return 13331 return Has_Atomic_Components (Designated_Type (Typ));
12639 Has_Atomic_Components (Designated_Type (Etype (N))); 13332
12640 else 13333 elsif Is_Atomic_Entity (Typ) then
12641 return Object_Has_Atomic_Components (N); 13334 return True;
12642 end if; 13335
12643 end Is_Atomic_Prefix; 13336 elsif Is_Entity_Name (Pref)
12644 13337 and then Is_Atomic_Entity (Entity (Pref))
12645 ----------------------------------
12646 -- Object_Has_Atomic_Components --
12647 ----------------------------------
12648
12649 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
12650 begin
12651 if Has_Atomic_Components (Etype (N))
12652 or else Is_Atomic (Etype (N))
12653 then 13338 then
12654 return True; 13339 return True;
12655 13340
12656 elsif Is_Entity_Name (N) 13341 elsif Nkind (Pref) = N_Indexed_Component then
12657 and then (Has_Atomic_Components (Entity (N)) 13342 return Is_Atomic_Prefix (Prefix (Pref));
12658 or else Is_Atomic (Entity (N))) 13343
12659 then 13344 elsif Nkind (Pref) = N_Selected_Component then
12660 return True; 13345 return
12661 13346 Is_Atomic_Prefix (Prefix (Pref))
12662 elsif Nkind (N) = N_Selected_Component 13347 or else Is_Atomic (Entity (Selector_Name (Pref)));
12663 and then Is_Atomic (Entity (Selector_Name (N))) 13348 end if;
12664 then 13349
12665 return True; 13350 return False;
12666 13351 end Is_Atomic_Prefix;
12667 elsif Nkind (N) = N_Indexed_Component
12668 or else Nkind (N) = N_Selected_Component
12669 then
12670 return Is_Atomic_Prefix (Prefix (N));
12671
12672 else
12673 return False;
12674 end if;
12675 end Object_Has_Atomic_Components;
12676 13352
12677 -- Start of processing for Is_Atomic_Object 13353 -- Start of processing for Is_Atomic_Object
12678 13354
12679 begin 13355 begin
12680 -- Predicate is not relevant to subprograms 13356 if Is_Entity_Name (N) then
12681 13357 return Is_Atomic_Object_Entity (Entity (N));
12682 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then 13358
12683 return False; 13359 elsif Nkind (N) = N_Indexed_Component then
12684 13360 return Is_Atomic (Etype (N)) or else Is_Atomic_Prefix (Prefix (N));
12685 elsif Is_Atomic (Etype (N)) 13361
12686 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N))) 13362 elsif Nkind (N) = N_Selected_Component then
12687 then 13363 return
12688 return True; 13364 Is_Atomic (Etype (N))
12689 13365 or else Is_Atomic_Prefix (Prefix (N))
12690 elsif Nkind (N) = N_Selected_Component 13366 or else Is_Atomic (Entity (Selector_Name (N)));
12691 and then Is_Atomic (Entity (Selector_Name (N))) 13367 end if;
12692 then 13368
12693 return True; 13369 return False;
12694
12695 elsif Nkind (N) = N_Indexed_Component
12696 or else Nkind (N) = N_Selected_Component
12697 then
12698 return Is_Atomic_Prefix (Prefix (N));
12699
12700 else
12701 return False;
12702 end if;
12703 end Is_Atomic_Object; 13370 end Is_Atomic_Object;
13371
13372 -----------------------------
13373 -- Is_Atomic_Object_Entity --
13374 -----------------------------
13375
13376 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13377 begin
13378 return
13379 Is_Object (Id)
13380 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13381 end Is_Atomic_Object_Entity;
12704 13382
12705 ----------------------------- 13383 -----------------------------
12706 -- Is_Atomic_Or_VFA_Object -- 13384 -- Is_Atomic_Or_VFA_Object --
12707 ----------------------------- 13385 -----------------------------
12708 13386
12740 -- Is_Body_Or_Package_Declaration -- 13418 -- Is_Body_Or_Package_Declaration --
12741 ------------------------------------ 13419 ------------------------------------
12742 13420
12743 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is 13421 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
12744 begin 13422 begin
12745 return Nkind_In (N, N_Entry_Body, 13423 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
12746 N_Package_Body,
12747 N_Package_Declaration,
12748 N_Protected_Body,
12749 N_Subprogram_Body,
12750 N_Task_Body);
12751 end Is_Body_Or_Package_Declaration; 13424 end Is_Body_Or_Package_Declaration;
12752 13425
12753 ----------------------- 13426 -----------------------
12754 -- Is_Bounded_String -- 13427 -- Is_Bounded_String --
12755 ----------------------- 13428 -----------------------
12788 E_Entry_Family, 13461 E_Entry_Family,
12789 E_Function, 13462 E_Function,
12790 E_Package, 13463 E_Package,
12791 E_Procedure, 13464 E_Procedure,
12792 E_Protected_Type, 13465 E_Protected_Type,
12793 E_Task_Type)); 13466 E_Task_Type)
12794 13467 or else
13468 Is_Record_Type (Context_Id));
12795 return Scope_Within_Or_Same (Context_Id, Ref_Id); 13469 return Scope_Within_Or_Same (Context_Id, Ref_Id);
12796 end if; 13470 end if;
12797 end Is_CCT_Instance; 13471 end Is_CCT_Instance;
12798 13472
12799 ------------------------- 13473 -------------------------
13191 13865
13192 begin 13866 begin
13193 if Ekind (Proc_Nam) = E_Procedure 13867 if Ekind (Proc_Nam) = E_Procedure
13194 and then Present (Parameter_Specifications (Parent (Proc_Nam))) 13868 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13195 then 13869 then
13196 Param := Parameter_Type (First ( 13870 Param :=
13197 Parameter_Specifications (Parent (Proc_Nam)))); 13871 Parameter_Type
13198 13872 (First (Parameter_Specifications (Parent (Proc_Nam))));
13199 -- The formal may be an anonymous access type. 13873
13874 -- The formal may be an anonymous access type
13200 13875
13201 if Nkind (Param) = N_Access_Definition then 13876 if Nkind (Param) = N_Access_Definition then
13202 Param_Typ := Entity (Subtype_Mark (Param)); 13877 Param_Typ := Entity (Subtype_Mark (Param));
13203
13204 else 13878 else
13205 Param_Typ := Etype (Param); 13879 Param_Typ := Etype (Param);
13206 end if; 13880 end if;
13207 13881
13208 -- In the case where an Itype was created for a dispatchin call, the 13882 -- In the case where an Itype was created for a dispatchin call, the
13254 Typ : constant Entity_Id := Entity (N); 13928 Typ : constant Entity_Id := Entity (N);
13255 P : Node_Id; 13929 P : Node_Id;
13256 13930
13257 begin 13931 begin
13258 -- Simplest case: entity is a concurrent type and we are currently 13932 -- Simplest case: entity is a concurrent type and we are currently
13259 -- inside the body. This will eventually be expanded into a 13933 -- inside the body. This will eventually be expanded into a call to
13260 -- call to Self (for tasks) or _object (for protected objects). 13934 -- Self (for tasks) or _object (for protected objects).
13261 13935
13262 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then 13936 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13263 return True; 13937 return True;
13264 13938
13265 else 13939 else
13286 and then Nkind (Parent (P)) = N_Subtype_Declaration 13960 and then Nkind (Parent (P)) = N_Subtype_Declaration
13287 then 13961 then
13288 return True; 13962 return True;
13289 13963
13290 elsif Nkind (P) = N_Pragma 13964 elsif Nkind (P) = N_Pragma
13291 and then 13965 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
13292 Get_Pragma_Id (P) = Pragma_Predicate_Failure
13293 then 13966 then
13294 return True; 13967 return True;
13295 end if; 13968 end if;
13296 13969
13297 P := Parent (P); 13970 P := Parent (P);
13305 13978
13306 -------------------- 13979 --------------------
13307 -- Is_Declaration -- 13980 -- Is_Declaration --
13308 -------------------- 13981 --------------------
13309 13982
13310 function Is_Declaration (N : Node_Id) return Boolean is 13983 function Is_Declaration
13311 begin 13984 (N : Node_Id;
13312 return 13985 Body_OK : Boolean := True;
13313 Is_Declaration_Other_Than_Renaming (N) 13986 Concurrent_OK : Boolean := True;
13314 or else Is_Renaming_Declaration (N); 13987 Formal_OK : Boolean := True;
13315 end Is_Declaration; 13988 Generic_OK : Boolean := True;
13316 13989 Instantiation_OK : Boolean := True;
13317 ---------------------------------------- 13990 Renaming_OK : Boolean := True;
13318 -- Is_Declaration_Other_Than_Renaming -- 13991 Stub_OK : Boolean := True;
13319 ---------------------------------------- 13992 Subprogram_OK : Boolean := True;
13320 13993 Type_OK : Boolean := True) return Boolean
13321 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is 13994 is
13322 begin 13995 begin
13323 case Nkind (N) is 13996 case Nkind (N) is
13997
13998 -- Body declarations
13999
14000 when N_Proper_Body =>
14001 return Body_OK;
14002
14003 -- Concurrent type declarations
14004
14005 when N_Protected_Type_Declaration
14006 | N_Single_Protected_Declaration
14007 | N_Single_Task_Declaration
14008 | N_Task_Type_Declaration
14009 =>
14010 return Concurrent_OK or Type_OK;
14011
14012 -- Formal declarations
14013
14014 when N_Formal_Abstract_Subprogram_Declaration
14015 | N_Formal_Concrete_Subprogram_Declaration
14016 | N_Formal_Object_Declaration
14017 | N_Formal_Package_Declaration
14018 | N_Formal_Type_Declaration
14019 =>
14020 return Formal_OK;
14021
14022 -- Generic declarations
14023
14024 when N_Generic_Package_Declaration
14025 | N_Generic_Subprogram_Declaration
14026 =>
14027 return Generic_OK;
14028
14029 -- Generic instantiations
14030
14031 when N_Function_Instantiation
14032 | N_Package_Instantiation
14033 | N_Procedure_Instantiation
14034 =>
14035 return Instantiation_OK;
14036
14037 -- Generic renaming declarations
14038
14039 when N_Generic_Renaming_Declaration =>
14040 return Generic_OK or Renaming_OK;
14041
14042 -- Renaming declarations
14043
14044 when N_Exception_Renaming_Declaration
14045 | N_Object_Renaming_Declaration
14046 | N_Package_Renaming_Declaration
14047 | N_Subprogram_Renaming_Declaration
14048 =>
14049 return Renaming_OK;
14050
14051 -- Stub declarations
14052
14053 when N_Body_Stub =>
14054 return Stub_OK;
14055
14056 -- Subprogram declarations
14057
13324 when N_Abstract_Subprogram_Declaration 14058 when N_Abstract_Subprogram_Declaration
14059 | N_Entry_Declaration
14060 | N_Expression_Function
14061 | N_Subprogram_Declaration
14062 =>
14063 return Subprogram_OK;
14064
14065 -- Type declarations
14066
14067 when N_Full_Type_Declaration
14068 | N_Incomplete_Type_Declaration
14069 | N_Private_Extension_Declaration
14070 | N_Private_Type_Declaration
14071 | N_Subtype_Declaration
14072 =>
14073 return Type_OK;
14074
14075 -- Miscellaneous
14076
14077 when N_Component_Declaration
13325 | N_Exception_Declaration 14078 | N_Exception_Declaration
13326 | N_Expression_Function 14079 | N_Implicit_Label_Declaration
13327 | N_Full_Type_Declaration
13328 | N_Generic_Package_Declaration
13329 | N_Generic_Subprogram_Declaration
13330 | N_Number_Declaration 14080 | N_Number_Declaration
13331 | N_Object_Declaration 14081 | N_Object_Declaration
13332 | N_Package_Declaration 14082 | N_Package_Declaration
13333 | N_Private_Extension_Declaration
13334 | N_Private_Type_Declaration
13335 | N_Subprogram_Declaration
13336 | N_Subtype_Declaration
13337 => 14083 =>
13338 return True; 14084 return True;
13339 14085
13340 when others => 14086 when others =>
13341 return False; 14087 return False;
13342 end case; 14088 end case;
13343 end Is_Declaration_Other_Than_Renaming; 14089 end Is_Declaration;
13344 14090
13345 -------------------------------- 14091 --------------------------------
13346 -- Is_Declared_Within_Variant -- 14092 -- Is_Declared_Within_Variant --
13347 -------------------------------- 14093 --------------------------------
13348 14094
14532 when others => 15278 when others =>
14533 return False; 15279 return False;
14534 end case; 15280 end case;
14535 end Is_Name_Reference; 15281 end Is_Name_Reference;
14536 15282
15283 ------------------------------------
15284 -- Is_Non_Preelaborable_Construct --
15285 ------------------------------------
15286
15287 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15288
15289 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15290 -- intentionally unnested to avoid deep indentation of code.
15291
15292 Non_Preelaborable : exception;
15293 -- This exception is raised when the construct violates preelaborability
15294 -- to terminate the recursion.
15295
15296 procedure Visit (Nod : Node_Id);
15297 -- Semantically inspect construct Nod to determine whether it violates
15298 -- preelaborability. This routine raises Non_Preelaborable.
15299
15300 procedure Visit_List (List : List_Id);
15301 pragma Inline (Visit_List);
15302 -- Invoke Visit on each element of list List. This routine raises
15303 -- Non_Preelaborable.
15304
15305 procedure Visit_Pragma (Prag : Node_Id);
15306 pragma Inline (Visit_Pragma);
15307 -- Semantically inspect pragma Prag to determine whether it violates
15308 -- preelaborability. This routine raises Non_Preelaborable.
15309
15310 procedure Visit_Subexpression (Expr : Node_Id);
15311 pragma Inline (Visit_Subexpression);
15312 -- Semantically inspect expression Expr to determine whether it violates
15313 -- preelaborability. This routine raises Non_Preelaborable.
15314
15315 -----------
15316 -- Visit --
15317 -----------
15318
15319 procedure Visit (Nod : Node_Id) is
15320 begin
15321 case Nkind (Nod) is
15322
15323 -- Declarations
15324
15325 when N_Component_Declaration =>
15326
15327 -- Defining_Identifier is left out because it is not relevant
15328 -- for preelaborability.
15329
15330 Visit (Component_Definition (Nod));
15331 Visit (Expression (Nod));
15332
15333 when N_Derived_Type_Definition =>
15334
15335 -- Interface_List is left out because it is not relevant for
15336 -- preelaborability.
15337
15338 Visit (Record_Extension_Part (Nod));
15339 Visit (Subtype_Indication (Nod));
15340
15341 when N_Entry_Declaration =>
15342
15343 -- A protected type with at leat one entry is not preelaborable
15344 -- while task types are never preelaborable. This renders entry
15345 -- declarations non-preelaborable.
15346
15347 raise Non_Preelaborable;
15348
15349 when N_Full_Type_Declaration =>
15350
15351 -- Defining_Identifier and Discriminant_Specifications are left
15352 -- out because they are not relevant for preelaborability.
15353
15354 Visit (Type_Definition (Nod));
15355
15356 when N_Function_Instantiation
15357 | N_Package_Instantiation
15358 | N_Procedure_Instantiation
15359 =>
15360 -- Defining_Unit_Name and Name are left out because they are
15361 -- not relevant for preelaborability.
15362
15363 Visit_List (Generic_Associations (Nod));
15364
15365 when N_Object_Declaration =>
15366
15367 -- Defining_Identifier is left out because it is not relevant
15368 -- for preelaborability.
15369
15370 Visit (Object_Definition (Nod));
15371
15372 if Has_Init_Expression (Nod) then
15373 Visit (Expression (Nod));
15374
15375 elsif not Has_Preelaborable_Initialization
15376 (Etype (Defining_Entity (Nod)))
15377 then
15378 raise Non_Preelaborable;
15379 end if;
15380
15381 when N_Private_Extension_Declaration
15382 | N_Subtype_Declaration
15383 =>
15384 -- Defining_Identifier, Discriminant_Specifications, and
15385 -- Interface_List are left out because they are not relevant
15386 -- for preelaborability.
15387
15388 Visit (Subtype_Indication (Nod));
15389
15390 when N_Protected_Type_Declaration
15391 | N_Single_Protected_Declaration
15392 =>
15393 -- Defining_Identifier, Discriminant_Specifications, and
15394 -- Interface_List are left out because they are not relevant
15395 -- for preelaborability.
15396
15397 Visit (Protected_Definition (Nod));
15398
15399 -- A [single] task type is never preelaborable
15400
15401 when N_Single_Task_Declaration
15402 | N_Task_Type_Declaration
15403 =>
15404 raise Non_Preelaborable;
15405
15406 -- Pragmas
15407
15408 when N_Pragma =>
15409 Visit_Pragma (Nod);
15410
15411 -- Statements
15412
15413 when N_Statement_Other_Than_Procedure_Call =>
15414 if Nkind (Nod) /= N_Null_Statement then
15415 raise Non_Preelaborable;
15416 end if;
15417
15418 -- Subexpressions
15419
15420 when N_Subexpr =>
15421 Visit_Subexpression (Nod);
15422
15423 -- Special
15424
15425 when N_Access_To_Object_Definition =>
15426 Visit (Subtype_Indication (Nod));
15427
15428 when N_Case_Expression_Alternative =>
15429 Visit (Expression (Nod));
15430 Visit_List (Discrete_Choices (Nod));
15431
15432 when N_Component_Definition =>
15433 Visit (Access_Definition (Nod));
15434 Visit (Subtype_Indication (Nod));
15435
15436 when N_Component_List =>
15437 Visit_List (Component_Items (Nod));
15438 Visit (Variant_Part (Nod));
15439
15440 when N_Constrained_Array_Definition =>
15441 Visit_List (Discrete_Subtype_Definitions (Nod));
15442 Visit (Component_Definition (Nod));
15443
15444 when N_Delta_Constraint
15445 | N_Digits_Constraint
15446 =>
15447 -- Delta_Expression and Digits_Expression are left out because
15448 -- they are not relevant for preelaborability.
15449
15450 Visit (Range_Constraint (Nod));
15451
15452 when N_Discriminant_Specification =>
15453
15454 -- Defining_Identifier and Expression are left out because they
15455 -- are not relevant for preelaborability.
15456
15457 Visit (Discriminant_Type (Nod));
15458
15459 when N_Generic_Association =>
15460
15461 -- Selector_Name is left out because it is not relevant for
15462 -- preelaborability.
15463
15464 Visit (Explicit_Generic_Actual_Parameter (Nod));
15465
15466 when N_Index_Or_Discriminant_Constraint =>
15467 Visit_List (Constraints (Nod));
15468
15469 when N_Iterator_Specification =>
15470
15471 -- Defining_Identifier is left out because it is not relevant
15472 -- for preelaborability.
15473
15474 Visit (Name (Nod));
15475 Visit (Subtype_Indication (Nod));
15476
15477 when N_Loop_Parameter_Specification =>
15478
15479 -- Defining_Identifier is left out because it is not relevant
15480 -- for preelaborability.
15481
15482 Visit (Discrete_Subtype_Definition (Nod));
15483
15484 when N_Protected_Definition =>
15485
15486 -- End_Label is left out because it is not relevant for
15487 -- preelaborability.
15488
15489 Visit_List (Private_Declarations (Nod));
15490 Visit_List (Visible_Declarations (Nod));
15491
15492 when N_Range_Constraint =>
15493 Visit (Range_Expression (Nod));
15494
15495 when N_Record_Definition
15496 | N_Variant
15497 =>
15498 -- End_Label, Discrete_Choices, and Interface_List are left out
15499 -- because they are not relevant for preelaborability.
15500
15501 Visit (Component_List (Nod));
15502
15503 when N_Subtype_Indication =>
15504
15505 -- Subtype_Mark is left out because it is not relevant for
15506 -- preelaborability.
15507
15508 Visit (Constraint (Nod));
15509
15510 when N_Unconstrained_Array_Definition =>
15511
15512 -- Subtype_Marks is left out because it is not relevant for
15513 -- preelaborability.
15514
15515 Visit (Component_Definition (Nod));
15516
15517 when N_Variant_Part =>
15518
15519 -- Name is left out because it is not relevant for
15520 -- preelaborability.
15521
15522 Visit_List (Variants (Nod));
15523
15524 -- Default
15525
15526 when others =>
15527 null;
15528 end case;
15529 end Visit;
15530
15531 ----------------
15532 -- Visit_List --
15533 ----------------
15534
15535 procedure Visit_List (List : List_Id) is
15536 Nod : Node_Id;
15537
15538 begin
15539 if Present (List) then
15540 Nod := First (List);
15541 while Present (Nod) loop
15542 Visit (Nod);
15543 Next (Nod);
15544 end loop;
15545 end if;
15546 end Visit_List;
15547
15548 ------------------
15549 -- Visit_Pragma --
15550 ------------------
15551
15552 procedure Visit_Pragma (Prag : Node_Id) is
15553 begin
15554 case Get_Pragma_Id (Prag) is
15555 when Pragma_Assert
15556 | Pragma_Assert_And_Cut
15557 | Pragma_Assume
15558 | Pragma_Async_Readers
15559 | Pragma_Async_Writers
15560 | Pragma_Attribute_Definition
15561 | Pragma_Check
15562 | Pragma_Constant_After_Elaboration
15563 | Pragma_CPU
15564 | Pragma_Deadline_Floor
15565 | Pragma_Dispatching_Domain
15566 | Pragma_Effective_Reads
15567 | Pragma_Effective_Writes
15568 | Pragma_Extensions_Visible
15569 | Pragma_Ghost
15570 | Pragma_Secondary_Stack_Size
15571 | Pragma_Task_Name
15572 | Pragma_Volatile_Function
15573 =>
15574 Visit_List (Pragma_Argument_Associations (Prag));
15575
15576 -- Default
15577
15578 when others =>
15579 null;
15580 end case;
15581 end Visit_Pragma;
15582
15583 -------------------------
15584 -- Visit_Subexpression --
15585 -------------------------
15586
15587 procedure Visit_Subexpression (Expr : Node_Id) is
15588 procedure Visit_Aggregate (Aggr : Node_Id);
15589 pragma Inline (Visit_Aggregate);
15590 -- Semantically inspect aggregate Aggr to determine whether it
15591 -- violates preelaborability.
15592
15593 ---------------------
15594 -- Visit_Aggregate --
15595 ---------------------
15596
15597 procedure Visit_Aggregate (Aggr : Node_Id) is
15598 begin
15599 if not Is_Preelaborable_Aggregate (Aggr) then
15600 raise Non_Preelaborable;
15601 end if;
15602 end Visit_Aggregate;
15603
15604 -- Start of processing for Visit_Subexpression
15605
15606 begin
15607 case Nkind (Expr) is
15608 when N_Allocator
15609 | N_Qualified_Expression
15610 | N_Type_Conversion
15611 | N_Unchecked_Expression
15612 | N_Unchecked_Type_Conversion
15613 =>
15614 -- Subpool_Handle_Name and Subtype_Mark are left out because
15615 -- they are not relevant for preelaborability.
15616
15617 Visit (Expression (Expr));
15618
15619 when N_Aggregate
15620 | N_Extension_Aggregate
15621 =>
15622 Visit_Aggregate (Expr);
15623
15624 when N_Attribute_Reference
15625 | N_Explicit_Dereference
15626 | N_Reference
15627 =>
15628 -- Attribute_Name and Expressions are left out because they are
15629 -- not relevant for preelaborability.
15630
15631 Visit (Prefix (Expr));
15632
15633 when N_Case_Expression =>
15634
15635 -- End_Span is left out because it is not relevant for
15636 -- preelaborability.
15637
15638 Visit_List (Alternatives (Expr));
15639 Visit (Expression (Expr));
15640
15641 when N_Delta_Aggregate =>
15642 Visit_Aggregate (Expr);
15643 Visit (Expression (Expr));
15644
15645 when N_Expression_With_Actions =>
15646 Visit_List (Actions (Expr));
15647 Visit (Expression (Expr));
15648
15649 when N_If_Expression =>
15650 Visit_List (Expressions (Expr));
15651
15652 when N_Quantified_Expression =>
15653 Visit (Condition (Expr));
15654 Visit (Iterator_Specification (Expr));
15655 Visit (Loop_Parameter_Specification (Expr));
15656
15657 when N_Range =>
15658 Visit (High_Bound (Expr));
15659 Visit (Low_Bound (Expr));
15660
15661 when N_Slice =>
15662 Visit (Discrete_Range (Expr));
15663 Visit (Prefix (Expr));
15664
15665 -- Default
15666
15667 when others =>
15668
15669 -- The evaluation of an object name is not preelaborable,
15670 -- unless the name is a static expression (checked further
15671 -- below), or statically denotes a discriminant.
15672
15673 if Is_Entity_Name (Expr) then
15674 Object_Name : declare
15675 Id : constant Entity_Id := Entity (Expr);
15676
15677 begin
15678 if Is_Object (Id) then
15679 if Ekind (Id) = E_Discriminant then
15680 null;
15681
15682 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15683 and then Present (Discriminal_Link (Id))
15684 then
15685 null;
15686
15687 else
15688 raise Non_Preelaborable;
15689 end if;
15690 end if;
15691 end Object_Name;
15692
15693 -- A non-static expression is not preelaborable
15694
15695 elsif not Is_OK_Static_Expression (Expr) then
15696 raise Non_Preelaborable;
15697 end if;
15698 end case;
15699 end Visit_Subexpression;
15700
15701 -- Start of processing for Is_Non_Preelaborable_Construct
15702
15703 begin
15704 Visit (N);
15705
15706 -- At this point it is known that the construct is preelaborable
15707
15708 return False;
15709
15710 exception
15711
15712 -- The elaboration of the construct performs an action which violates
15713 -- preelaborability.
15714
15715 when Non_Preelaborable =>
15716 return True;
15717 end Is_Non_Preelaborable_Construct;
15718
14537 --------------------------------- 15719 ---------------------------------
14538 -- Is_Nontrivial_DIC_Procedure -- 15720 -- Is_Nontrivial_DIC_Procedure --
14539 --------------------------------- 15721 ---------------------------------
14540 15722
14541 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is 15723 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
14811 -- If this node is rewritten, then test the original form, if that is 15993 -- If this node is rewritten, then test the original form, if that is
14812 -- OK, then we consider the rewritten node OK (for example, if the 15994 -- OK, then we consider the rewritten node OK (for example, if the
14813 -- original node is a conversion, then Is_Variable will not be true 15995 -- original node is a conversion, then Is_Variable will not be true
14814 -- but we still want to allow the conversion if it converts a variable). 15996 -- but we still want to allow the conversion if it converts a variable).
14815 15997
14816 elsif Original_Node (AV) /= AV then 15998 elsif Is_Rewrite_Substitution (AV) then
14817 15999
14818 -- In Ada 2012, the explicit dereference may be a rewritten call to a 16000 -- In Ada 2012, the explicit dereference may be a rewritten call to a
14819 -- Reference function. 16001 -- Reference function.
14820 16002
14821 if Ada_Version >= Ada_2012 16003 if Ada_Version >= Ada_2012
14857 -- entry, function, or procedure in prefixed form where the prefix is 16039 -- entry, function, or procedure in prefixed form where the prefix is
14858 -- Obj_Ref. 16040 -- Obj_Ref.
14859 16041
14860 function Within_Check (Nod : Node_Id) return Boolean; 16042 function Within_Check (Nod : Node_Id) return Boolean;
14861 -- Determine whether an arbitrary node appears in a check node 16043 -- Determine whether an arbitrary node appears in a check node
14862
14863 function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
14864 -- Determine whether an arbitrary node appears in an entry, function, or
14865 -- procedure call.
14866 16044
14867 function Within_Volatile_Function (Id : Entity_Id) return Boolean; 16045 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
14868 -- Determine whether an arbitrary entity appears in a volatile function 16046 -- Determine whether an arbitrary entity appears in a volatile function
14869 16047
14870 --------------------------------- 16048 ---------------------------------
14924 end loop; 16102 end loop;
14925 16103
14926 return False; 16104 return False;
14927 end Within_Check; 16105 end Within_Check;
14928 16106
14929 ----------------------------
14930 -- Within_Subprogram_Call --
14931 ----------------------------
14932
14933 function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
14934 Par : Node_Id;
14935
14936 begin
14937 -- Climb the parent chain looking for a function or procedure call
14938
14939 Par := Nod;
14940 while Present (Par) loop
14941 if Nkind_In (Par, N_Entry_Call_Statement,
14942 N_Function_Call,
14943 N_Procedure_Call_Statement)
14944 then
14945 return True;
14946
14947 -- Prevent the search from going too far
14948
14949 elsif Is_Body_Or_Package_Declaration (Par) then
14950 exit;
14951 end if;
14952
14953 Par := Parent (Par);
14954 end loop;
14955
14956 return False;
14957 end Within_Subprogram_Call;
14958
14959 ------------------------------ 16107 ------------------------------
14960 -- Within_Volatile_Function -- 16108 -- Within_Volatile_Function --
14961 ------------------------------ 16109 ------------------------------
14962 16110
14963 function Within_Volatile_Function (Id : Entity_Id) return Boolean is 16111 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
15058 Obj_Ref => Context) 16206 Obj_Ref => Context)
15059 then 16207 then
15060 return True; 16208 return True;
15061 16209
15062 -- The volatile object appears as the prefix of attributes Address, 16210 -- The volatile object appears as the prefix of attributes Address,
15063 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size, 16211 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
15064 -- Storage_Size. 16212 -- Position, Size, Storage_Size.
15065 16213
15066 elsif Nkind (Context) = N_Attribute_Reference 16214 elsif Nkind (Context) = N_Attribute_Reference
15067 and then Prefix (Context) = Obj_Ref 16215 and then Prefix (Context) = Obj_Ref
15068 and then Nam_In (Attribute_Name (Context), Name_Address, 16216 and then Nam_In (Attribute_Name (Context), Name_Address,
15069 Name_Alignment, 16217 Name_Alignment,
15070 Name_Component_Size, 16218 Name_Component_Size,
16219 Name_First,
15071 Name_First_Bit, 16220 Name_First_Bit,
16221 Name_Last,
15072 Name_Last_Bit, 16222 Name_Last_Bit,
16223 Name_Length,
15073 Name_Position, 16224 Name_Position,
15074 Name_Size, 16225 Name_Size,
15075 Name_Storage_Size) 16226 Name_Storage_Size)
15076 then 16227 then
15077 return True; 16228 return True;
15335 Par : Node_Id; 16486 Par : Node_Id;
15336 Expr : Node_Id; 16487 Expr : Node_Id;
15337 16488
15338 begin 16489 begin
15339 Expr := N; 16490 Expr := N;
15340 Par := Parent (N); 16491 Par := N;
15341 16492
15342 -- A postcondition whose expression is a short-circuit is broken down 16493 -- A postcondition whose expression is a short-circuit is broken down
15343 -- into individual aspects for better exception reporting. The original 16494 -- into individual aspects for better exception reporting. The original
15344 -- short-circuit expression is rewritten as the second operand, and an 16495 -- short-circuit expression is rewritten as the second operand, and an
15345 -- occurrence of 'Old in that operand is potentially unevaluated. 16496 -- occurrence of 'Old in that operand is potentially unevaluated.
15346 -- See Sem_ch13.adb for details of this transformation. 16497 -- See sem_ch13.adb for details of this transformation. The reference
15347 16498 -- to 'Old may appear within an expression, so we must look for the
15348 if Nkind (Original_Node (Par)) = N_And_Then then 16499 -- enclosing pragma argument in the tree that contains the reference.
15349 return True; 16500
15350 end if; 16501 while Present (Par)
15351 16502 and then Nkind (Par) /= N_Pragma_Argument_Association
15352 while not Nkind_In (Par, N_If_Expression, 16503 loop
16504 if Is_Rewrite_Substitution (Par)
16505 and then Nkind (Original_Node (Par)) = N_And_Then
16506 then
16507 return True;
16508 end if;
16509
16510 Par := Parent (Par);
16511 end loop;
16512
16513 -- Other cases; 'Old appears within other expression (not the top-level
16514 -- conjunct in a postcondition) with a potentially unevaluated operand.
16515
16516 Par := Parent (Expr);
16517 while not Nkind_In (Par, N_And_Then,
15353 N_Case_Expression, 16518 N_Case_Expression,
15354 N_And_Then, 16519 N_If_Expression,
15355 N_Or_Else,
15356 N_In, 16520 N_In,
15357 N_Not_In, 16521 N_Not_In,
16522 N_Or_Else,
15358 N_Quantified_Expression) 16523 N_Quantified_Expression)
15359 loop 16524 loop
15360 Expr := Par; 16525 Expr := Par;
15361 Par := Parent (Par); 16526 Par := Parent (Par);
15362 16527
15403 else 16568 else
15404 return False; 16569 return False;
15405 end if; 16570 end if;
15406 end Is_Potentially_Unevaluated; 16571 end Is_Potentially_Unevaluated;
15407 16572
16573 -----------------------------------------
16574 -- Is_Predefined_Dispatching_Operation --
16575 -----------------------------------------
16576
16577 function Is_Predefined_Dispatching_Operation
16578 (E : Entity_Id) return Boolean
16579 is
16580 TSS_Name : TSS_Name_Type;
16581
16582 begin
16583 if not Is_Dispatching_Operation (E) then
16584 return False;
16585 end if;
16586
16587 Get_Name_String (Chars (E));
16588
16589 -- Most predefined primitives have internally generated names. Equality
16590 -- must be treated differently; the predefined operation is recognized
16591 -- as a homogeneous binary operator that returns Boolean.
16592
16593 if Name_Len > TSS_Name_Type'Last then
16594 TSS_Name :=
16595 TSS_Name_Type
16596 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16597
16598 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16599 or else
16600 (Chars (E) = Name_Op_Eq
16601 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16602 or else TSS_Name = TSS_Deep_Adjust
16603 or else TSS_Name = TSS_Deep_Finalize
16604 or else TSS_Name = TSS_Stream_Input
16605 or else TSS_Name = TSS_Stream_Output
16606 or else TSS_Name = TSS_Stream_Read
16607 or else TSS_Name = TSS_Stream_Write
16608 or else Is_Predefined_Interface_Primitive (E)
16609 then
16610 return True;
16611 end if;
16612 end if;
16613
16614 return False;
16615 end Is_Predefined_Dispatching_Operation;
16616
16617 ---------------------------------------
16618 -- Is_Predefined_Interface_Primitive --
16619 ---------------------------------------
16620
16621 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16622 begin
16623 -- In VM targets we don't restrict the functionality of this test to
16624 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16625 -- these primitives.
16626
16627 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16628 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16629 Name_uDisp_Conditional_Select,
16630 Name_uDisp_Get_Prim_Op_Kind,
16631 Name_uDisp_Get_Task_Id,
16632 Name_uDisp_Requeue,
16633 Name_uDisp_Timed_Select);
16634 end Is_Predefined_Interface_Primitive;
16635
16636 ---------------------------------------
16637 -- Is_Predefined_Internal_Operation --
16638 ---------------------------------------
16639
16640 function Is_Predefined_Internal_Operation
16641 (E : Entity_Id) return Boolean
16642 is
16643 TSS_Name : TSS_Name_Type;
16644
16645 begin
16646 if not Is_Dispatching_Operation (E) then
16647 return False;
16648 end if;
16649
16650 Get_Name_String (Chars (E));
16651
16652 -- Most predefined primitives have internally generated names. Equality
16653 -- must be treated differently; the predefined operation is recognized
16654 -- as a homogeneous binary operator that returns Boolean.
16655
16656 if Name_Len > TSS_Name_Type'Last then
16657 TSS_Name :=
16658 TSS_Name_Type
16659 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16660
16661 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16662 or else
16663 (Chars (E) = Name_Op_Eq
16664 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16665 or else TSS_Name = TSS_Deep_Adjust
16666 or else TSS_Name = TSS_Deep_Finalize
16667 or else Is_Predefined_Interface_Primitive (E)
16668 then
16669 return True;
16670 end if;
16671 end if;
16672
16673 return False;
16674 end Is_Predefined_Internal_Operation;
16675
15408 -------------------------------- 16676 --------------------------------
15409 -- Is_Preelaborable_Aggregate -- 16677 -- Is_Preelaborable_Aggregate --
15410 -------------------------------- 16678 --------------------------------
15411 16679
15412 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is 16680 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
15414 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ); 16682 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
15415 16683
15416 Anc_Part : Node_Id; 16684 Anc_Part : Node_Id;
15417 Assoc : Node_Id; 16685 Assoc : Node_Id;
15418 Choice : Node_Id; 16686 Choice : Node_Id;
15419 Comp_Typ : Entity_Id; 16687 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
15420 Expr : Node_Id; 16688 Expr : Node_Id;
15421 16689
15422 begin 16690 begin
15423 if Array_Aggr then 16691 if Array_Aggr then
15424 Comp_Typ := Component_Type (Aggr_Typ); 16692 Comp_Typ := Component_Type (Aggr_Typ);
15490 end loop; 16758 end loop;
15491 16759
15492 -- The type of the choice must have preelaborable initialization if 16760 -- The type of the choice must have preelaborable initialization if
15493 -- the association carries a <>. 16761 -- the association carries a <>.
15494 16762
16763 pragma Assert (Present (Comp_Typ));
15495 if Box_Present (Assoc) then 16764 if Box_Present (Assoc) then
15496 if not Has_Preelaborable_Initialization (Comp_Typ) then 16765 if not Has_Preelaborable_Initialization (Comp_Typ) then
15497 return False; 16766 return False;
15498 end if; 16767 end if;
15499 16768
16158 17427
16159 return Nkind (N) = N_Subprogram_Body_Stub 17428 return Nkind (N) = N_Subprogram_Body_Stub
16160 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body; 17429 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
16161 end Is_Subprogram_Stub_Without_Prior_Declaration; 17430 end Is_Subprogram_Stub_Without_Prior_Declaration;
16162 17431
17432 ---------------------------
17433 -- Is_Suitable_Primitive --
17434 ---------------------------
17435
17436 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17437 begin
17438 -- The Default_Initial_Condition and invariant procedures must not be
17439 -- treated as primitive operations even when they apply to a tagged
17440 -- type. These routines must not act as targets of dispatching calls
17441 -- because they already utilize class-wide-precondition semantics to
17442 -- handle inheritance and overriding.
17443
17444 if Ekind (Subp_Id) = E_Procedure
17445 and then (Is_DIC_Procedure (Subp_Id)
17446 or else
17447 Is_Invariant_Procedure (Subp_Id))
17448 then
17449 return False;
17450 end if;
17451
17452 return True;
17453 end Is_Suitable_Primitive;
17454
16163 -------------------------- 17455 --------------------------
16164 -- Is_Suspension_Object -- 17456 -- Is_Suspension_Object --
16165 -------------------------- 17457 --------------------------
16166 17458
16167 function Is_Suspension_Object (Id : Entity_Id) return Boolean is 17459 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
16199 return True; 17491 return True;
16200 17492
16201 -- The object is synchronized if it is atomic and Async_Writers is 17493 -- The object is synchronized if it is atomic and Async_Writers is
16202 -- enabled. 17494 -- enabled.
16203 17495
16204 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then 17496 elsif Is_Atomic_Object_Entity (Id)
17497 and then Async_Writers_Enabled (Id)
17498 then
16205 return True; 17499 return True;
16206 17500
16207 -- A constant is a synchronized object by default 17501 -- A constant is a synchronized object by default
16208 17502
16209 elsif Ekind (Id) = E_Constant then 17503 elsif Ekind (Id) = E_Constant then
16418 Comp_Typ : Entity_Id; 17712 Comp_Typ : Entity_Id;
16419 17713
16420 begin 17714 begin
16421 pragma Assert (Is_Record_Type (E)); 17715 pragma Assert (Is_Record_Type (E));
16422 17716
16423 Comp := First_Entity (E); 17717 Comp := First_Component (E);
16424 while Present (Comp) loop 17718 while Present (Comp) loop
16425 Comp_Typ := Etype (Comp); 17719 Comp_Typ := Underlying_Type (Etype (Comp));
16426 17720
16427 -- Recursive call if the record type has discriminants 17721 -- Recursive call if the record type has discriminants
16428 17722
16429 if Is_Record_Type (Comp_Typ) 17723 if Is_Record_Type (Comp_Typ)
16430 and then Has_Discriminants (Comp_Typ) 17724 and then Has_Discriminants (Comp_Typ)
16436 and then Is_Variable_Size_Array (Comp_Typ) 17730 and then Is_Variable_Size_Array (Comp_Typ)
16437 then 17731 then
16438 return True; 17732 return True;
16439 end if; 17733 end if;
16440 17734
16441 Next_Entity (Comp); 17735 Next_Component (Comp);
16442 end loop; 17736 end loop;
16443 17737
16444 return False; 17738 return False;
16445 end Is_Variable_Size_Record; 17739 end Is_Variable_Size_Record;
16446 17740
16607 declare 17901 declare
16608 E : constant Entity_Id := Entity (Orig_Node); 17902 E : constant Entity_Id := Entity (Orig_Node);
16609 K : constant Entity_Kind := Ekind (E); 17903 K : constant Entity_Kind := Ekind (E);
16610 17904
16611 begin 17905 begin
17906 if Is_Loop_Parameter (E) then
17907 return False;
17908 end if;
17909
16612 return (K = E_Variable 17910 return (K = E_Variable
16613 and then Nkind (Parent (E)) /= N_Exception_Handler) 17911 and then Nkind (Parent (E)) /= N_Exception_Handler)
16614 or else (K = E_Component 17912 or else (K = E_Component
16615 and then not In_Protected_Function (E)) 17913 and then not In_Protected_Function (E))
16616 or else K = E_Out_Parameter 17914 or else K = E_Out_Parameter
16683 return False; 17981 return False;
16684 end case; 17982 end case;
16685 end if; 17983 end if;
16686 end Is_Variable; 17984 end Is_Variable;
16687 17985
16688 ------------------------------
16689 -- Is_Verifiable_DIC_Pragma --
16690 ------------------------------
16691
16692 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
16693 Args : constant List_Id := Pragma_Argument_Associations (Prag);
16694
16695 begin
16696 -- To qualify as verifiable, a DIC pragma must have a non-null argument
16697
16698 return
16699 Present (Args)
16700 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
16701 end Is_Verifiable_DIC_Pragma;
16702
16703 --------------------------- 17986 ---------------------------
16704 -- Is_Visibly_Controlled -- 17987 -- Is_Visibly_Controlled --
16705 --------------------------- 17988 ---------------------------
16706 17989
16707 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is 17990 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
16836 ----------------------------- 18119 -----------------------------
16837 -- Iterate_Call_Parameters -- 18120 -- Iterate_Call_Parameters --
16838 ----------------------------- 18121 -----------------------------
16839 18122
16840 procedure Iterate_Call_Parameters (Call : Node_Id) is 18123 procedure Iterate_Call_Parameters (Call : Node_Id) is
18124 Actual : Node_Id := First_Actual (Call);
16841 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call)); 18125 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
16842 Actual : Node_Id := First_Actual (Call);
16843 18126
16844 begin 18127 begin
16845 while Present (Formal) and then Present (Actual) loop 18128 while Present (Formal) and then Present (Actual) loop
16846 Handle_Parameter (Formal, Actual); 18129 Handle_Parameter (Formal, Actual);
16847 Formal := Next_Formal (Formal); 18130
16848 Actual := Next_Actual (Actual); 18131 Next_Formal (Formal);
18132 Next_Actual (Actual);
16849 end loop; 18133 end loop;
18134
18135 pragma Assert (No (Formal));
18136 pragma Assert (No (Actual));
16850 end Iterate_Call_Parameters; 18137 end Iterate_Call_Parameters;
16851 18138
16852 --------------------------- 18139 ---------------------------
16853 -- Itype_Has_Declaration -- 18140 -- Itype_Has_Declaration --
16854 --------------------------- 18141 ---------------------------
17233 18520
17234 function Mark_Allocator (N : Node_Id) return Traverse_Result is 18521 function Mark_Allocator (N : Node_Id) return Traverse_Result is
17235 begin 18522 begin
17236 if Nkind (N) = N_Allocator then 18523 if Nkind (N) = N_Allocator then
17237 if Is_Dynamic then 18524 if Is_Dynamic then
18525 Set_Is_Static_Coextension (N, False);
17238 Set_Is_Dynamic_Coextension (N); 18526 Set_Is_Dynamic_Coextension (N);
17239 18527
17240 -- If the allocator expression is potentially dynamic, it may 18528 -- If the allocator expression is potentially dynamic, it may
17241 -- be expanded out of order and require dynamic allocation 18529 -- be expanded out of order and require dynamic allocation
17242 -- anyway, so we treat the coextension itself as dynamic. 18530 -- anyway, so we treat the coextension itself as dynamic.
17243 -- Potential optimization ??? 18531 -- Potential optimization ???
17244 18532
17245 elsif Nkind (Expression (N)) = N_Qualified_Expression 18533 elsif Nkind (Expression (N)) = N_Qualified_Expression
17246 and then Nkind (Expression (Expression (N))) = N_Op_Concat 18534 and then Nkind (Expression (Expression (N))) = N_Op_Concat
17247 then 18535 then
18536 Set_Is_Static_Coextension (N, False);
17248 Set_Is_Dynamic_Coextension (N); 18537 Set_Is_Dynamic_Coextension (N);
17249 else 18538 else
18539 Set_Is_Dynamic_Coextension (N, False);
17250 Set_Is_Static_Coextension (N); 18540 Set_Is_Static_Coextension (N);
17251 end if; 18541 end if;
17252 end if; 18542 end if;
17253 18543
17254 return OK; 18544 return OK;
17315 --------------------------------- 18605 ---------------------------------
17316 -- Mark_Elaboration_Attributes -- 18606 -- Mark_Elaboration_Attributes --
17317 --------------------------------- 18607 ---------------------------------
17318 18608
17319 procedure Mark_Elaboration_Attributes 18609 procedure Mark_Elaboration_Attributes
17320 (N_Id : Node_Or_Entity_Id; 18610 (N_Id : Node_Or_Entity_Id;
17321 Checks : Boolean := False; 18611 Checks : Boolean := False;
17322 Level : Boolean := False; 18612 Level : Boolean := False;
17323 Modes : Boolean := False) 18613 Modes : Boolean := False;
18614 Warnings : Boolean := False)
17324 is 18615 is
17325 function Elaboration_Checks_OK 18616 function Elaboration_Checks_OK
17326 (Target_Id : Entity_Id; 18617 (Target_Id : Entity_Id;
17327 Context_Id : Entity_Id) return Boolean; 18618 Context_Id : Entity_Id) return Boolean;
17328 -- Determine whether elaboration checks are enabled for target Target_Id 18619 -- Determine whether elaboration checks are enabled for target Target_Id
17381 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then 18672 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
17382 Set_Is_Elaboration_Checks_OK_Id (Id, 18673 Set_Is_Elaboration_Checks_OK_Id (Id,
17383 Elaboration_Checks_OK 18674 Elaboration_Checks_OK
17384 (Target_Id => Id, 18675 (Target_Id => Id,
17385 Context_Id => Scope (Id))); 18676 Context_Id => Scope (Id)));
17386 18677 end if;
17387 -- Entities do not need to capture their enclosing level. The Ghost 18678
17388 -- and SPARK modes in effect are already marked during analysis. 18679 -- Mark the status of elaboration warnings in effect. Do not reset
17389 18680 -- the status in case the entity is reanalyzed with warnings off.
17390 else 18681
17391 null; 18682 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18683 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
17392 end if; 18684 end if;
17393 end Mark_Elaboration_Attributes_Id; 18685 end Mark_Elaboration_Attributes_Id;
17394 18686
17395 -------------------------------------- 18687 --------------------------------------
17396 -- Mark_Elaboration_Attributes_Node -- 18688 -- Mark_Elaboration_Attributes_Node --
17501 18793
17502 if SPARK_Mode = On then 18794 if SPARK_Mode = On then
17503 Set_Is_SPARK_Mode_On_Node (N); 18795 Set_Is_SPARK_Mode_On_Node (N);
17504 end if; 18796 end if;
17505 end if; 18797 end if;
18798
18799 -- Mark the status of elaboration warnings in effect. Do not reset
18800 -- the status in case the node is reanalyzed with warnings off.
18801
18802 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
18803 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
18804 end if;
17506 end Mark_Elaboration_Attributes_Node; 18805 end Mark_Elaboration_Attributes_Node;
17507 18806
17508 -- Start of processing for Mark_Elaboration_Attributes 18807 -- Start of processing for Mark_Elaboration_Attributes
17509 18808
17510 begin 18809 begin
18810 -- Do not capture any elaboration-related attributes when switch -gnatH
18811 -- (legacy elaboration checking mode enabled) is in effect because the
18812 -- attributes are useless to the legacy model.
18813
18814 if Legacy_Elaboration_Checks then
18815 return;
18816 end if;
18817
17511 if Nkind (N_Id) in N_Entity then 18818 if Nkind (N_Id) in N_Entity then
17512 Mark_Elaboration_Attributes_Id (N_Id); 18819 Mark_Elaboration_Attributes_Id (N_Id);
17513 else 18820 else
17514 Mark_Elaboration_Attributes_Node (N_Id); 18821 Mark_Elaboration_Attributes_Node (N_Id);
17515 end if; 18822 end if;
17524 R_Typ : Node_Id) return Boolean 18831 R_Typ : Node_Id) return Boolean
17525 is 18832 is
17526 L_Ndims : constant Nat := Number_Dimensions (L_Typ); 18833 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
17527 R_Ndims : constant Nat := Number_Dimensions (R_Typ); 18834 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
17528 18835
17529 L_Index : Node_Id; 18836 L_Index : Node_Id := Empty; -- init to ...
17530 R_Index : Node_Id; 18837 R_Index : Node_Id := Empty; -- ...avoid warnings
17531 L_Low : Node_Id; 18838 L_Low : Node_Id;
17532 L_High : Node_Id; 18839 L_High : Node_Id;
17533 L_Len : Uint; 18840 L_Len : Uint;
17534 R_Low : Node_Id; 18841 R_Low : Node_Id;
17535 R_High : Node_Id; 18842 R_High : Node_Id;
17932 else 19239 else
17933 return False; 19240 return False;
17934 end if; 19241 end if;
17935 end Needs_One_Actual; 19242 end Needs_One_Actual;
17936 19243
19244 ---------------------------------
19245 -- Needs_Simple_Initialization --
19246 ---------------------------------
19247
19248 function Needs_Simple_Initialization
19249 (Typ : Entity_Id;
19250 Consider_IS : Boolean := True) return Boolean
19251 is
19252 Consider_IS_NS : constant Boolean :=
19253 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19254
19255 begin
19256 -- Never need initialization if it is suppressed
19257
19258 if Initialization_Suppressed (Typ) then
19259 return False;
19260 end if;
19261
19262 -- Check for private type, in which case test applies to the underlying
19263 -- type of the private type.
19264
19265 if Is_Private_Type (Typ) then
19266 declare
19267 RT : constant Entity_Id := Underlying_Type (Typ);
19268 begin
19269 if Present (RT) then
19270 return Needs_Simple_Initialization (RT);
19271 else
19272 return False;
19273 end if;
19274 end;
19275
19276 -- Scalar type with Default_Value aspect requires initialization
19277
19278 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19279 return True;
19280
19281 -- Cases needing simple initialization are access types, and, if pragma
19282 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19283 -- types.
19284
19285 elsif Is_Access_Type (Typ)
19286 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19287 then
19288 return True;
19289
19290 -- If Initialize/Normalize_Scalars is in effect, string objects also
19291 -- need initialization, unless they are created in the course of
19292 -- expanding an aggregate (since in the latter case they will be
19293 -- filled with appropriate initializing values before they are used).
19294
19295 elsif Consider_IS_NS
19296 and then Is_Standard_String_Type (Typ)
19297 and then
19298 (not Is_Itype (Typ)
19299 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19300 then
19301 return True;
19302
19303 else
19304 return False;
19305 end if;
19306 end Needs_Simple_Initialization;
19307
19308 -------------------------------------
19309 -- Needs_Variable_Reference_Marker --
19310 -------------------------------------
19311
19312 function Needs_Variable_Reference_Marker
19313 (N : Node_Id;
19314 Calls_OK : Boolean) return Boolean
19315 is
19316 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
19317 -- Deteremine whether variable reference Ref appears within a suitable
19318 -- context that allows the creation of a marker.
19319
19320 -----------------------------
19321 -- Within_Suitable_Context --
19322 -----------------------------
19323
19324 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
19325 Par : Node_Id;
19326
19327 begin
19328 Par := Ref;
19329 while Present (Par) loop
19330
19331 -- The context is not suitable when the reference appears within
19332 -- the formal part of an instantiation which acts as compilation
19333 -- unit because there is no proper list for the insertion of the
19334 -- marker.
19335
19336 if Nkind (Par) = N_Generic_Association
19337 and then Nkind (Parent (Par)) in N_Generic_Instantiation
19338 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
19339 then
19340 return False;
19341
19342 -- The context is not suitable when the reference appears within
19343 -- a pragma. If the pragma has run-time semantics, the reference
19344 -- will be reconsidered once the pragma is expanded.
19345
19346 elsif Nkind (Par) = N_Pragma then
19347 return False;
19348
19349 -- The context is not suitable when the reference appears within a
19350 -- subprogram call, and the caller requests this behavior.
19351
19352 elsif not Calls_OK
19353 and then Nkind_In (Par, N_Entry_Call_Statement,
19354 N_Function_Call,
19355 N_Procedure_Call_Statement)
19356 then
19357 return False;
19358
19359 -- Prevent the search from going too far
19360
19361 elsif Is_Body_Or_Package_Declaration (Par) then
19362 exit;
19363 end if;
19364
19365 Par := Parent (Par);
19366 end loop;
19367
19368 return True;
19369 end Within_Suitable_Context;
19370
19371 -- Local variables
19372
19373 Prag : Node_Id;
19374 Var_Id : Entity_Id;
19375
19376 -- Start of processing for Needs_Variable_Reference_Marker
19377
19378 begin
19379 -- No marker needs to be created when switch -gnatH (legacy elaboration
19380 -- checking mode enabled) is in effect because the legacy ABE mechanism
19381 -- does not use markers.
19382
19383 if Legacy_Elaboration_Checks then
19384 return False;
19385
19386 -- No marker needs to be created for ASIS because ABE diagnostics and
19387 -- checks are not performed in this mode.
19388
19389 elsif ASIS_Mode then
19390 return False;
19391
19392 -- No marker needs to be created when the reference is preanalyzed
19393 -- because the marker will be inserted in the wrong place.
19394
19395 elsif Preanalysis_Active then
19396 return False;
19397
19398 -- Only references warrant a marker
19399
19400 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
19401 return False;
19402
19403 -- Only source references warrant a marker
19404
19405 elsif not Comes_From_Source (N) then
19406 return False;
19407
19408 -- No marker needs to be created when the reference is erroneous, left
19409 -- in a bad state, or does not denote a variable.
19410
19411 elsif not (Present (Entity (N))
19412 and then Ekind (Entity (N)) = E_Variable
19413 and then Entity (N) /= Any_Id)
19414 then
19415 return False;
19416 end if;
19417
19418 Var_Id := Entity (N);
19419 Prag := SPARK_Pragma (Var_Id);
19420
19421 -- Both the variable and reference must appear in SPARK_Mode On regions
19422 -- because this elaboration scenario falls under the SPARK rules.
19423
19424 if not (Comes_From_Source (Var_Id)
19425 and then Present (Prag)
19426 and then Get_SPARK_Mode_From_Annotation (Prag) = On
19427 and then Is_SPARK_Mode_On_Node (N))
19428 then
19429 return False;
19430
19431 -- No marker needs to be created when the reference does not appear
19432 -- within a suitable context (see body for details).
19433
19434 -- Performance note: parent traversal
19435
19436 elsif not Within_Suitable_Context (N) then
19437 return False;
19438 end if;
19439
19440 -- At this point it is known that the variable reference will play a
19441 -- role in ABE diagnostics and requires a marker.
19442
19443 return True;
19444 end Needs_Variable_Reference_Marker;
19445
17937 ------------------------ 19446 ------------------------
17938 -- New_Copy_List_Tree -- 19447 -- New_Copy_List_Tree --
17939 ------------------------ 19448 ------------------------
17940 19449
17941 function New_Copy_List_Tree (List : List_Id) return List_Id is 19450 function New_Copy_List_Tree (List : List_Id) return List_Id is
18034 ------------------- 19543 -------------------
18035 -- New_Copy_Tree -- 19544 -- New_Copy_Tree --
18036 ------------------- 19545 -------------------
18037 19546
18038 function New_Copy_Tree 19547 function New_Copy_Tree
18039 (Source : Node_Id; 19548 (Source : Node_Id;
18040 Map : Elist_Id := No_Elist; 19549 Map : Elist_Id := No_Elist;
18041 New_Sloc : Source_Ptr := No_Location; 19550 New_Sloc : Source_Ptr := No_Location;
18042 New_Scope : Entity_Id := Empty) return Node_Id 19551 New_Scope : Entity_Id := Empty;
19552 Scopes_In_EWA_OK : Boolean := False) return Node_Id
18043 is 19553 is
18044 -- This routine performs low-level tree manipulations and needs access 19554 -- This routine performs low-level tree manipulations and needs access
18045 -- to the internals of the tree. 19555 -- to the internals of the tree.
18046 19556
18047 use Atree.Unchecked_Access; 19557 use Atree.Unchecked_Access;
18840 20350
18841 procedure Update_Semantic_Fields (Id : Entity_Id) is 20351 procedure Update_Semantic_Fields (Id : Entity_Id) is
18842 begin 20352 begin
18843 -- Discriminant_Constraint 20353 -- Discriminant_Constraint
18844 20354
18845 if Has_Discriminants (Base_Type (Id)) then 20355 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
18846 Set_Discriminant_Constraint (Id, Elist_Id ( 20356 Set_Discriminant_Constraint (Id, Elist_Id (
18847 Copy_Field_With_Replacement 20357 Copy_Field_With_Replacement
18848 (Field => Union_Id (Discriminant_Constraint (Id)), 20358 (Field => Union_Id (Discriminant_Constraint (Id)),
18849 Semantic => True))); 20359 Semantic => True)));
18850 end if; 20360 end if;
18872 Copy_Field_With_Replacement 20382 Copy_Field_With_Replacement
18873 (Field => Union_Id (Packed_Array_Impl_Type (Id)), 20383 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
18874 Semantic => True))); 20384 Semantic => True)));
18875 end if; 20385 end if;
18876 end if; 20386 end if;
20387
20388 -- Prev_Entity
20389
20390 Set_Prev_Entity (Id, Node_Id (
20391 Copy_Field_With_Replacement
20392 (Field => Union_Id (Prev_Entity (Id)),
20393 Semantic => True)));
18877 20394
18878 -- Next_Entity 20395 -- Next_Entity
18879 20396
18880 Set_Next_Entity (Id, Node_Id ( 20397 Set_Next_Entity (Id, Node_Id (
18881 Copy_Field_With_Replacement 20398 Copy_Field_With_Replacement
18952 20469
18953 begin 20470 begin
18954 pragma Assert (Nkind (Id) in N_Entity); 20471 pragma Assert (Nkind (Id) in N_Entity);
18955 pragma Assert (not Is_Itype (Id)); 20472 pragma Assert (not Is_Itype (Id));
18956 20473
18957 -- Nothing to do if the entity is not defined in the Actions list of 20474 -- Nothing to do when the entity is not defined in the Actions list
18958 -- an N_Expression_With_Actions node. 20475 -- of an N_Expression_With_Actions node.
18959 20476
18960 if EWA_Level = 0 then 20477 if EWA_Level = 0 then
18961 return; 20478 return;
18962 20479
18963 -- Nothing to do if the entity is defined within a scoping construct 20480 -- Nothing to do when the entity is defined in a scoping construct
18964 -- of an N_Expression_With_Actions node. 20481 -- within an N_Expression_With_Actions node, unless the caller has
18965 20482 -- requested their replication.
18966 elsif EWA_Inner_Scope_Level > 0 then 20483
20484 -- ??? should this restriction be eliminated?
20485
20486 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
18967 return; 20487 return;
18968 20488
18969 -- Nothing to do if the entity is not an object or a type. Relaxing 20489 -- Nothing to do when the entity does not denote a construct that
20490 -- may appear within an N_Expression_With_Actions node. Relaxing
18970 -- this restriction leads to a performance penalty. 20491 -- this restriction leads to a performance penalty.
18971 20492
18972 elsif not Ekind_In (Id, E_Constant, E_Variable) 20493 -- ??? this list is flaky, and may hide dormant bugs
20494
20495 elsif not Ekind_In (Id, E_Block,
20496 E_Constant,
20497 E_Label,
20498 E_Procedure,
20499 E_Variable)
18973 and then not Is_Type (Id) 20500 and then not Is_Type (Id)
18974 then 20501 then
18975 return; 20502 return;
18976 20503
18977 -- Nothing to do if the entity was already visited 20504 -- Nothing to do when the entity was already visited
18978 20505
18979 elsif NCT_Tables_In_Use 20506 elsif NCT_Tables_In_Use
18980 and then Present (NCT_New_Entities.Get (Id)) 20507 and then Present (NCT_New_Entities.Get (Id))
18981 then 20508 then
18982 return; 20509 return;
18983 20510
18984 -- Nothing to do if the declaration node of the entity is not within 20511 -- Nothing to do when the declaration node of the entity is not in
18985 -- the subtree being replicated. 20512 -- the subtree being replicated.
18986 20513
18987 elsif not In_Subtree 20514 elsif not In_Subtree
18988 (N => Declaration_Node (Id), 20515 (N => Declaration_Node (Id),
18989 Root => Source) 20516 Root => Source)
19297 begin 20824 begin
19298 pragma Assert (Nkind (Id) in N_Entity); 20825 pragma Assert (Nkind (Id) in N_Entity);
19299 20826
19300 -- Discriminant_Constraint 20827 -- Discriminant_Constraint
19301 20828
19302 if Has_Discriminants (Base_Type (Id)) then 20829 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
19303 Visit_Field 20830 Visit_Field
19304 (Field => Union_Id (Discriminant_Constraint (Id)), 20831 (Field => Union_Id (Discriminant_Constraint (Id)),
19305 Semantic => True); 20832 Semantic => True);
19306 end if; 20833 end if;
19307 20834
19468 (Kind : Entity_Kind; 20995 (Kind : Entity_Kind;
19469 Scope_Id : Entity_Id; 20996 Scope_Id : Entity_Id;
19470 Sloc_Value : Source_Ptr; 20997 Sloc_Value : Source_Ptr;
19471 Related_Id : Entity_Id; 20998 Related_Id : Entity_Id;
19472 Suffix : Character; 20999 Suffix : Character;
19473 Suffix_Index : Nat := 0; 21000 Suffix_Index : Int := 0;
19474 Prefix : Character := ' ') return Entity_Id 21001 Prefix : Character := ' ') return Entity_Id
19475 is 21002 is
19476 N : constant Entity_Id := 21003 N : constant Entity_Id :=
19477 Make_Defining_Identifier (Sloc_Value, 21004 Make_Defining_Identifier (Sloc_Value,
19478 New_External_Name 21005 New_External_Name
19502 Id_Char : Character) return Entity_Id 21029 Id_Char : Character) return Entity_Id
19503 is 21030 is
19504 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char); 21031 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
19505 21032
19506 begin 21033 begin
19507 Set_Ekind (N, Kind); 21034 Set_Ekind (N, Kind);
19508 Set_Is_Internal (N, True); 21035 Set_Is_Internal (N, True);
19509 Append_Entity (N, Scope_Id); 21036 Append_Entity (N, Scope_Id);
19510 21037
19511 if Kind in Type_Kind then 21038 if Kind in Type_Kind then
19512 Init_Size_Align (N); 21039 Init_Size_Align (N);
19513 end if; 21040 end if;
19514 21041
19518 ----------------- 21045 -----------------
19519 -- Next_Actual -- 21046 -- Next_Actual --
19520 ----------------- 21047 -----------------
19521 21048
19522 function Next_Actual (Actual_Id : Node_Id) return Node_Id is 21049 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
19523 N : Node_Id; 21050 Par : constant Node_Id := Parent (Actual_Id);
21051 N : Node_Id;
19524 21052
19525 begin 21053 begin
19526 -- If we are pointing at a positional parameter, it is a member of a 21054 -- If we are pointing at a positional parameter, it is a member of a
19527 -- node list (the list of parameters), and the next parameter is the 21055 -- node list (the list of parameters), and the next parameter is the
19528 -- next node on the list, unless we hit a parameter association, then 21056 -- next node on the list, unless we hit a parameter association, then
19538 if Nkind (N) = N_Parameter_Association then 21066 if Nkind (N) = N_Parameter_Association then
19539 21067
19540 -- In case of a build-in-place call, the call will no longer be a 21068 -- In case of a build-in-place call, the call will no longer be a
19541 -- call; it will have been rewritten. 21069 -- call; it will have been rewritten.
19542 21070
19543 if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement, 21071 if Nkind_In (Par, N_Entry_Call_Statement,
19544 N_Function_Call, 21072 N_Function_Call,
19545 N_Procedure_Call_Statement) 21073 N_Procedure_Call_Statement)
19546 then 21074 then
19547 return First_Named_Actual (Parent (Actual_Id)); 21075 return First_Named_Actual (Par);
21076
21077 -- In case of a call rewritten in GNATprove mode while "inlining
21078 -- for proof" go to the original call.
21079
21080 elsif Nkind (Par) = N_Null_Statement then
21081 pragma Assert
21082 (GNATprove_Mode
21083 and then
21084 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21085
21086 return First_Named_Actual (Original_Node (Par));
19548 else 21087 else
19549 return Empty; 21088 return Empty;
19550 end if; 21089 end if;
19551 else 21090 else
19552 return N; 21091 return N;
21252 else 22791 else
21253 Kind := Name_Ignore; 22792 Kind := Name_Ignore;
21254 end if; 22793 end if;
21255 end if; 22794 end if;
21256 22795
22796 -- In CodePeer mode and GNATprove mode, we need to consider all
22797 -- assertions, unless they are disabled. Force Name_Check on
22798 -- ignored assertions.
22799
22800 if Nam_In (Kind, Name_Ignore, Name_Off)
22801 and then (CodePeer_Mode or GNATprove_Mode)
22802 then
22803 Kind := Name_Check;
22804 end if;
22805
21257 return Kind; 22806 return Kind;
21258 end Policy_In_Effect; 22807 end Policy_In_Effect;
21259 22808
21260 ---------------------------------- 22809 ----------------------------------
21261 -- Predicate_Tests_On_Arguments -- 22810 -- Predicate_Tests_On_Arguments --
21713 -- prevents accidental clobbering of enabled attributes. 23262 -- prevents accidental clobbering of enabled attributes.
21714 23263
21715 if Has_Inheritable_Invariants (From_Typ) 23264 if Has_Inheritable_Invariants (From_Typ)
21716 and then not Has_Inheritable_Invariants (Typ) 23265 and then not Has_Inheritable_Invariants (Typ)
21717 then 23266 then
21718 Set_Has_Inheritable_Invariants (Typ, True); 23267 Set_Has_Inheritable_Invariants (Typ);
21719 end if; 23268 end if;
21720 23269
21721 if Has_Inherited_Invariants (From_Typ) 23270 if Has_Inherited_Invariants (From_Typ)
21722 and then not Has_Inherited_Invariants (Typ) 23271 and then not Has_Inherited_Invariants (Typ)
21723 then 23272 then
21724 Set_Has_Inherited_Invariants (Typ, True); 23273 Set_Has_Inherited_Invariants (Typ);
21725 end if; 23274 end if;
21726 23275
21727 if Has_Own_Invariants (From_Typ) 23276 if Has_Own_Invariants (From_Typ)
21728 and then not Has_Own_Invariants (Typ) 23277 and then not Has_Own_Invariants (Typ)
21729 then 23278 then
21730 Set_Has_Own_Invariants (Typ, True); 23279 Set_Has_Own_Invariants (Typ);
21731 end if; 23280 end if;
21732 23281
21733 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then 23282 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
21734 Set_Invariant_Procedure (Typ, Full_IP); 23283 Set_Invariant_Procedure (Typ, Full_IP);
21735 end if; 23284 end if;
21753 Refs : Elist_Id; 23302 Refs : Elist_Id;
21754 23303
21755 begin 23304 begin
21756 -- The variable is a constituent of a single protected/task type. Such 23305 -- The variable is a constituent of a single protected/task type. Such
21757 -- a variable acts as a component of the type and must appear within a 23306 -- a variable acts as a component of the type and must appear within a
21758 -- specific region (SPARK RM 9.3). Instead of recording the reference, 23307 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
21759 -- verify its legality now. 23308 -- verify its legality now.
21760 23309
21761 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then 23310 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
21762 Check_Part_Of_Reference (Var_Id, Ref); 23311 Check_Part_Of_Reference (Var_Id, Ref);
21763 23312
21857 else 23406 else
21858 return False; 23407 return False;
21859 end if; 23408 end if;
21860 end References_Generic_Formal_Type; 23409 end References_Generic_Formal_Type;
21861 23410
21862 ------------------- 23411 -------------------------------
21863 -- Remove_Entity -- 23412 -- Remove_Entity_And_Homonym --
21864 ------------------- 23413 -------------------------------
21865 23414
21866 procedure Remove_Entity (Id : Entity_Id) is 23415 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
21867 Scop : constant Entity_Id := Scope (Id); 23416 begin
21868 Prev_Id : Entity_Id; 23417 Remove_Entity (Id);
21869 23418 Remove_Homonym (Id);
21870 begin 23419 end Remove_Entity_And_Homonym;
21871 -- Remove the entity from the homonym chain. When the entity is the
21872 -- head of the chain, associate the entry in the name table with its
21873 -- homonym effectively making it the new head of the chain.
21874
21875 if Current_Entity (Id) = Id then
21876 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
21877
21878 -- Otherwise link the previous and next homonyms
21879
21880 else
21881 Prev_Id := Current_Entity (Id);
21882 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
21883 Prev_Id := Homonym (Prev_Id);
21884 end loop;
21885
21886 Set_Homonym (Prev_Id, Homonym (Id));
21887 end if;
21888
21889 -- Remove the entity from the scope entity chain. When the entity is
21890 -- the head of the chain, set the next entity as the new head of the
21891 -- chain.
21892
21893 if First_Entity (Scop) = Id then
21894 Prev_Id := Empty;
21895 Set_First_Entity (Scop, Next_Entity (Id));
21896
21897 -- Otherwise the entity is either in the middle of the chain or it acts
21898 -- as its tail. Traverse and link the previous and next entities.
21899
21900 else
21901 Prev_Id := First_Entity (Scop);
21902 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
21903 Next_Entity (Prev_Id);
21904 end loop;
21905
21906 Set_Next_Entity (Prev_Id, Next_Entity (Id));
21907 end if;
21908
21909 -- Handle the case where the entity acts as the tail of the scope entity
21910 -- chain.
21911
21912 if Last_Entity (Scop) = Id then
21913 Set_Last_Entity (Scop, Prev_Id);
21914 end if;
21915 end Remove_Entity;
21916 23420
21917 -------------------- 23421 --------------------
21918 -- Remove_Homonym -- 23422 -- Remove_Homonym --
21919 -------------------- 23423 --------------------
21920 23424
21921 procedure Remove_Homonym (E : Entity_Id) is 23425 procedure Remove_Homonym (Id : Entity_Id) is
21922 Prev : Entity_Id := Empty; 23426 Hom : Entity_Id;
21923 H : Entity_Id; 23427 Prev : Entity_Id := Empty;
21924 23428
21925 begin 23429 begin
21926 if E = Current_Entity (E) then 23430 if Id = Current_Entity (Id) then
21927 if Present (Homonym (E)) then 23431 if Present (Homonym (Id)) then
21928 Set_Current_Entity (Homonym (E)); 23432 Set_Current_Entity (Homonym (Id));
21929 else 23433 else
21930 Set_Name_Entity_Id (Chars (E), Empty); 23434 Set_Name_Entity_Id (Chars (Id), Empty);
21931 end if; 23435 end if;
21932 23436
21933 else 23437 else
21934 H := Current_Entity (E); 23438 Hom := Current_Entity (Id);
21935 while Present (H) and then H /= E loop 23439 while Present (Hom) and then Hom /= Id loop
21936 Prev := H; 23440 Prev := Hom;
21937 H := Homonym (H); 23441 Hom := Homonym (Hom);
21938 end loop; 23442 end loop;
21939 23443
21940 -- If E is not on the homonym chain, nothing to do 23444 -- If Id is not on the homonym chain, nothing to do
21941 23445
21942 if Present (H) then 23446 if Present (Hom) then
21943 Set_Homonym (Prev, Homonym (E)); 23447 Set_Homonym (Prev, Homonym (Id));
21944 end if; 23448 end if;
21945 end if; 23449 end if;
21946 end Remove_Homonym; 23450 end Remove_Homonym;
21947 23451
21948 ------------------------------ 23452 ------------------------------
21976 Formal : Entity_Id; 23480 Formal : Entity_Id;
21977 23481
21978 -- Start of processing for Remove_Overloaded_Entity 23482 -- Start of processing for Remove_Overloaded_Entity
21979 23483
21980 begin 23484 begin
21981 -- Remove the entity from both the homonym and scope chains 23485 Remove_Entity_And_Homonym (Id);
21982
21983 Remove_Entity (Id);
21984 23486
21985 -- The entity denotes a primitive subprogram. Remove it from the list of 23487 -- The entity denotes a primitive subprogram. Remove it from the list of
21986 -- primitives of the associated controlling type. 23488 -- primitives of the associated controlling type.
21987 23489
21988 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then 23490 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
22469 23971
22470 ------------------------- 23972 -------------------------
22471 -- Scalar_Part_Present -- 23973 -- Scalar_Part_Present --
22472 ------------------------- 23974 -------------------------
22473 23975
22474 function Scalar_Part_Present (T : Entity_Id) return Boolean is 23976 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
22475 C : Entity_Id; 23977 Val_Typ : constant Entity_Id := Validated_View (Typ);
22476 23978 Field : Entity_Id;
22477 begin 23979
22478 if Is_Scalar_Type (T) then 23980 begin
23981 if Is_Scalar_Type (Val_Typ) then
22479 return True; 23982 return True;
22480 23983
22481 elsif Is_Array_Type (T) then 23984 elsif Is_Array_Type (Val_Typ) then
22482 return Scalar_Part_Present (Component_Type (T)); 23985 return Scalar_Part_Present (Component_Type (Val_Typ));
22483 23986
22484 elsif Is_Record_Type (T) or else Has_Discriminants (T) then 23987 elsif Is_Record_Type (Val_Typ) then
22485 C := First_Component_Or_Discriminant (T); 23988 Field := First_Component_Or_Discriminant (Val_Typ);
22486 while Present (C) loop 23989 while Present (Field) loop
22487 if Scalar_Part_Present (Etype (C)) then 23990 if Scalar_Part_Present (Etype (Field)) then
22488 return True; 23991 return True;
22489 else
22490 Next_Component_Or_Discriminant (C);
22491 end if; 23992 end if;
23993
23994 Next_Component_Or_Discriminant (Field);
22492 end loop; 23995 end loop;
22493 end if; 23996 end if;
22494 23997
22495 return False; 23998 return False;
22496 end Scalar_Part_Present; 23999 end Scalar_Part_Present;
22519 while Present (Curr) and then Curr /= Standard_Standard loop 24022 while Present (Curr) and then Curr /= Standard_Standard loop
22520 Curr := Scope (Curr); 24023 Curr := Scope (Curr);
22521 24024
22522 if Curr = Outer then 24025 if Curr = Outer then
22523 return True; 24026 return True;
24027
24028 -- A selective accept body appears within a task type, but the
24029 -- enclosing subprogram is the procedure of the task body.
24030
24031 elsif Ekind (Curr) = E_Task_Type
24032 and then Outer = Task_Body_Procedure (Curr)
24033 then
24034 return True;
24035
24036 -- Ditto for the body of a protected operation
24037
24038 elsif Is_Subprogram (Curr)
24039 and then Outer = Protected_Body_Subprogram (Curr)
24040 then
24041 return True;
24042
24043 -- Outside of its scope, a synchronized type may just be private
24044
24045 elsif Is_Private_Type (Curr)
24046 and then Present (Full_View (Curr))
24047 and then Is_Concurrent_Type (Full_View (Curr))
24048 then
24049 return Scope_Within (Full_View (Curr), Outer);
22524 end if; 24050 end if;
22525 end loop; 24051 end loop;
22526 24052
22527 return False; 24053 return False;
22528 end Scope_Within; 24054 end Scope_Within;
22560 24086
22561 if Is_Type (E) 24087 if Is_Type (E)
22562 and then Is_Access_Subprogram_Type (Base_Type (E)) 24088 and then Is_Access_Subprogram_Type (Base_Type (E))
22563 and then Has_Foreign_Convention (E) 24089 and then Has_Foreign_Convention (E)
22564 then 24090 then
22565 24091 Set_Can_Use_Internal_Rep (E, False);
22566 -- A pragma Convention in an instance may apply to the subtype
22567 -- created for a formal, in which case we have already verified
22568 -- that conventions of actual and formal match and there is nothing
22569 -- to flag on the subtype.
22570
22571 if In_Instance then
22572 null;
22573 else
22574 Set_Can_Use_Internal_Rep (E, False);
22575 end if;
22576 end if; 24092 end if;
22577 24093
22578 -- If E is an object, including a component, and the type of E is an 24094 -- If E is an object, including a component, and the type of E is an
22579 -- anonymous access type with no convention set, then also set the 24095 -- anonymous access type with no convention set, then also set the
22580 -- convention of the anonymous access type. We do not do this for 24096 -- convention of the anonymous access type. We do not do this for
22948 end if; 24464 end if;
22949 24465
22950 Set_Entity (N, Val); 24466 Set_Entity (N, Val);
22951 end Set_Entity_With_Checks; 24467 end Set_Entity_With_Checks;
22952 24468
24469 ------------------------------
24470 -- Set_Invalid_Scalar_Value --
24471 ------------------------------
24472
24473 procedure Set_Invalid_Scalar_Value
24474 (Scal_Typ : Float_Scalar_Id;
24475 Value : Ureal)
24476 is
24477 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24478
24479 begin
24480 -- Detect an attempt to set a different value for the same scalar type
24481
24482 pragma Assert (Slot = No_Ureal);
24483 Slot := Value;
24484 end Set_Invalid_Scalar_Value;
24485
24486 ------------------------------
24487 -- Set_Invalid_Scalar_Value --
24488 ------------------------------
24489
24490 procedure Set_Invalid_Scalar_Value
24491 (Scal_Typ : Integer_Scalar_Id;
24492 Value : Uint)
24493 is
24494 Slot : Uint renames Invalid_Integers (Scal_Typ);
24495
24496 begin
24497 -- Detect an attempt to set a different value for the same scalar type
24498
24499 pragma Assert (Slot = No_Uint);
24500 Slot := Value;
24501 end Set_Invalid_Scalar_Value;
24502
22953 ------------------------ 24503 ------------------------
22954 -- Set_Name_Entity_Id -- 24504 -- Set_Name_Entity_Id --
22955 ------------------------ 24505 ------------------------
22956 24506
22957 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is 24507 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
23293 --------------------- 24843 ---------------------
23294 24844
23295 function Subprogram_Name (N : Node_Id) return String is 24845 function Subprogram_Name (N : Node_Id) return String is
23296 Buf : Bounded_String; 24846 Buf : Bounded_String;
23297 Ent : Node_Id := N; 24847 Ent : Node_Id := N;
24848 Nod : Node_Id;
23298 24849
23299 begin 24850 begin
23300 while Present (Ent) loop 24851 while Present (Ent) loop
23301 case Nkind (Ent) is 24852 case Nkind (Ent) is
23302 when N_Subprogram_Body => 24853 when N_Subprogram_Body =>
23303 Ent := Defining_Unit_Name (Specification (Ent)); 24854 Ent := Defining_Unit_Name (Specification (Ent));
23304 exit; 24855 exit;
23305 24856
23306 when N_Package_Body 24857 when N_Subprogram_Declaration =>
24858 Nod := Corresponding_Body (Ent);
24859
24860 if Present (Nod) then
24861 Ent := Nod;
24862 else
24863 Ent := Defining_Unit_Name (Specification (Ent));
24864 end if;
24865
24866 exit;
24867
24868 when N_Subprogram_Instantiation
24869 | N_Package_Body
23307 | N_Package_Specification 24870 | N_Package_Specification
23308 | N_Subprogram_Specification
23309 => 24871 =>
23310 Ent := Defining_Unit_Name (Ent); 24872 Ent := Defining_Unit_Name (Ent);
23311 exit; 24873 exit;
23312 24874
24875 when N_Protected_Type_Declaration =>
24876 Ent := Corresponding_Body (Ent);
24877 exit;
24878
23313 when N_Protected_Body 24879 when N_Protected_Body
23314 | N_Protected_Type_Declaration
23315 | N_Task_Body 24880 | N_Task_Body
23316 => 24881 =>
24882 Ent := Defining_Identifier (Ent);
23317 exit; 24883 exit;
23318 24884
23319 when others => 24885 when others =>
23320 null; 24886 null;
23321 end case; 24887 end case;
23322 24888
23323 Ent := Parent (Ent); 24889 Ent := Parent (Ent);
23324 end loop; 24890 end loop;
23325 24891
23326 if No (Ent) then 24892 if No (Ent) then
23327 return "unknown subprogram"; 24893 return "unknown subprogram:unknown file:0:0";
23328 end if; 24894 end if;
23329 24895
23330 -- If the subprogram is a child unit, use its simple name to start the 24896 -- If the subprogram is a child unit, use its simple name to start the
23331 -- construction of the fully qualified name. 24897 -- construction of the fully qualified name.
23332 24898
23333 if Nkind (Ent) = N_Defining_Program_Unit_Name then 24899 if Nkind (Ent) = N_Defining_Program_Unit_Name then
23334 Append_Entity_Name (Buf, Defining_Identifier (Ent)); 24900 Ent := Defining_Identifier (Ent);
23335 else 24901 end if;
23336 Append_Entity_Name (Buf, Ent); 24902
23337 end if; 24903 Append_Entity_Name (Buf, Ent);
24904
24905 -- Append homonym number if needed
24906
24907 if Nkind (N) in N_Entity and then Has_Homonym (N) then
24908 declare
24909 H : Entity_Id := Homonym (N);
24910 Nr : Nat := 1;
24911
24912 begin
24913 while Present (H) loop
24914 if Scope (H) = Scope (N) then
24915 Nr := Nr + 1;
24916 end if;
24917
24918 H := Homonym (H);
24919 end loop;
24920
24921 if Nr > 1 then
24922 Append (Buf, '#');
24923 Append (Buf, Nr);
24924 end if;
24925 end;
24926 end if;
24927
24928 -- Append source location of Ent to Buf so that the string will
24929 -- look like "subp:file:line:col".
24930
24931 declare
24932 Loc : constant Source_Ptr := Sloc (Ent);
24933 begin
24934 Append (Buf, ':');
24935 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
24936 Append (Buf, ':');
24937 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
24938 Append (Buf, ':');
24939 Append (Buf, Nat (Get_Column_Number (Loc)));
24940 end;
23338 24941
23339 return +Buf; 24942 return +Buf;
23340 end Subprogram_Name; 24943 end Subprogram_Name;
23341 24944
23342 ------------------------------- 24945 -------------------------------
23451 25054
23452 -- Merge the entity chain of the source scope with that of the 25055 -- Merge the entity chain of the source scope with that of the
23453 -- destination scope. 25056 -- destination scope.
23454 25057
23455 if Present (Last_Entity (To)) then 25058 if Present (Last_Entity (To)) then
23456 Set_Next_Entity (Last_Entity (To), Id); 25059 Link_Entities (Last_Entity (To), Id);
23457 else 25060 else
23458 Set_First_Entity (To, Id); 25061 Set_First_Entity (To, Id);
23459 end if; 25062 end if;
23460 25063
23461 Set_Last_Entity (To, Last_Entity (From)); 25064 Set_Last_Entity (To, Last_Entity (From));
24094 else 25697 else
24095 return Expr; 25698 return Expr;
24096 end if; 25699 end if;
24097 end Unqual_Conv; 25700 end Unqual_Conv;
24098 25701
25702 --------------------
25703 -- Validated_View --
25704 --------------------
25705
25706 function Validated_View (Typ : Entity_Id) return Entity_Id is
25707 Continue : Boolean;
25708 Val_Typ : Entity_Id;
25709
25710 begin
25711 Continue := True;
25712 Val_Typ := Base_Type (Typ);
25713
25714 -- Obtain the full view of the input type by stripping away concurrency,
25715 -- derivations, and privacy.
25716
25717 while Continue loop
25718 Continue := False;
25719
25720 if Is_Concurrent_Type (Val_Typ) then
25721 if Present (Corresponding_Record_Type (Val_Typ)) then
25722 Continue := True;
25723 Val_Typ := Corresponding_Record_Type (Val_Typ);
25724 end if;
25725
25726 elsif Is_Derived_Type (Val_Typ) then
25727 Continue := True;
25728 Val_Typ := Etype (Val_Typ);
25729
25730 elsif Is_Private_Type (Val_Typ) then
25731 if Present (Underlying_Full_View (Val_Typ)) then
25732 Continue := True;
25733 Val_Typ := Underlying_Full_View (Val_Typ);
25734
25735 elsif Present (Full_View (Val_Typ)) then
25736 Continue := True;
25737 Val_Typ := Full_View (Val_Typ);
25738 end if;
25739 end if;
25740 end loop;
25741
25742 return Val_Typ;
25743 end Validated_View;
25744
24099 ----------------------- 25745 -----------------------
24100 -- Visible_Ancestors -- 25746 -- Visible_Ancestors --
24101 ----------------------- 25747 -----------------------
24102 25748
24103 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is 25749 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
24181 25827
24182 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is 25828 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
24183 begin 25829 begin
24184 return Scope_Within_Or_Same (Scope (E), S); 25830 return Scope_Within_Or_Same (Scope (E), S);
24185 end Within_Scope; 25831 end Within_Scope;
25832
25833 ----------------------------
25834 -- Within_Subprogram_Call --
25835 ----------------------------
25836
25837 function Within_Subprogram_Call (N : Node_Id) return Boolean is
25838 Par : Node_Id;
25839
25840 begin
25841 -- Climb the parent chain looking for a function or procedure call
25842
25843 Par := N;
25844 while Present (Par) loop
25845 if Nkind_In (Par, N_Entry_Call_Statement,
25846 N_Function_Call,
25847 N_Procedure_Call_Statement)
25848 then
25849 return True;
25850
25851 -- Prevent the search from going too far
25852
25853 elsif Is_Body_Or_Package_Declaration (Par) then
25854 exit;
25855 end if;
25856
25857 Par := Parent (Par);
25858 end loop;
25859
25860 return False;
25861 end Within_Subprogram_Call;
24186 25862
24187 ---------------- 25863 ----------------
24188 -- Wrong_Type -- 25864 -- Wrong_Type --
24189 ---------------- 25865 ----------------
24190 25866