1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Casing
; use Casing
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Exp_Ch11
; use Exp_Ch11
;
33 with Exp_Util
; use Exp_Util
;
34 with Expander
; use Expander
;
35 with Inline
; use Inline
;
36 with Namet
; use Namet
;
37 with Nlists
; use Nlists
;
38 with Nmake
; use Nmake
;
40 with Restrict
; use Restrict
;
41 with Rident
; use Rident
;
42 with Rtsfind
; use Rtsfind
;
44 with Sem_Ch8
; use Sem_Ch8
;
45 with Sem_Util
; use Sem_Util
;
46 with Sinfo
; use Sinfo
;
47 with Sinput
; use Sinput
;
48 with Snames
; use Snames
;
49 with Stringt
; use Stringt
;
50 with Stand
; use Stand
;
51 with Tbuild
; use Tbuild
;
52 with Uintp
; use Uintp
;
53 with Validsw
; use Validsw
;
55 package body Exp_Prag
is
57 -----------------------
58 -- Local Subprograms --
59 -----------------------
61 function Arg1
(N
: Node_Id
) return Node_Id
;
62 function Arg2
(N
: Node_Id
) return Node_Id
;
63 function Arg3
(N
: Node_Id
) return Node_Id
;
64 -- Obtain specified pragma argument expression
66 procedure Expand_Pragma_Abort_Defer
(N
: Node_Id
);
67 procedure Expand_Pragma_Check
(N
: Node_Id
);
68 procedure Expand_Pragma_Common_Object
(N
: Node_Id
);
69 procedure Expand_Pragma_Import_Or_Interface
(N
: Node_Id
);
70 procedure Expand_Pragma_Inspection_Point
(N
: Node_Id
);
71 procedure Expand_Pragma_Interrupt_Priority
(N
: Node_Id
);
72 procedure Expand_Pragma_Loop_Variant
(N
: Node_Id
);
73 procedure Expand_Pragma_Psect_Object
(N
: Node_Id
);
74 procedure Expand_Pragma_Relative_Deadline
(N
: Node_Id
);
75 procedure Expand_Pragma_Suppress_Initialization
(N
: Node_Id
);
77 procedure Undo_Initialization
(Def_Id
: Entity_Id
; N
: Node_Id
);
78 -- This procedure is used to undo initialization already done for Def_Id,
79 -- which is always an E_Variable, in response to the occurrence of the
80 -- pragma N, a pragma Interface, Import, or Suppress_Initialization. In all
81 -- these cases we want no initialization to occur, but we have already done
82 -- the initialization by the time we see the pragma, so we have to undo it.
88 function Arg1
(N
: Node_Id
) return Node_Id
is
89 Arg
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
92 and then Nkind
(Arg
) = N_Pragma_Argument_Association
94 return Expression
(Arg
);
104 function Arg2
(N
: Node_Id
) return Node_Id
is
105 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
113 Arg
: constant Node_Id
:= Next
(Arg1
);
116 and then Nkind
(Arg
) = N_Pragma_Argument_Association
118 return Expression
(Arg
);
130 function Arg3
(N
: Node_Id
) return Node_Id
is
131 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
139 Arg
: Node_Id
:= Next
(Arg1
);
148 and then Nkind
(Arg
) = N_Pragma_Argument_Association
150 return Expression
(Arg
);
159 ---------------------------
160 -- Expand_Contract_Cases --
161 ---------------------------
163 -- Pragma Contract_Cases is expanded in the following manner:
166 -- Count : Natural := 0;
167 -- Flag_1 : Boolean := False;
169 -- Flag_N : Boolean := False;
170 -- Flag_N+1 : Boolean := False; -- when "others" present
175 -- <preconditions (if any)>
177 -- -- Evaluate all case guards
179 -- if Case_Guard_1 then
181 -- Count := Count + 1;
184 -- if Case_Guard_N then
186 -- Count := Count + 1;
189 -- -- Emit errors depending on the number of case guards that
190 -- -- evaluated to True.
193 -- raise Assertion_Error with "xxx contract cases incomplete";
195 -- Flag_N+1 := True; -- when "others" present
197 -- elsif Count > 1 then
199 -- Str0 : constant String :=
200 -- "contract cases overlap for subprogram ABC";
201 -- Str1 : constant String :=
203 -- Str0 & "case guard at xxx evaluates to True"
205 -- StrN : constant String :=
207 -- StrN-1 & "case guard at xxx evaluates to True"
210 -- raise Assertion_Error with StrN;
214 -- -- Evaluate all attribute 'Old prefixes found in the selected
218 -- Pref_1 := <prefix of 'Old found in Consequence_1>
221 -- Pref_M := <prefix of 'Old found in Consequence_N>
224 -- procedure _Postconditions is
226 -- <postconditions (if any)>
228 -- if Flag_1 and then not Consequence_1 then
229 -- raise Assertion_Error with "failed contract case at xxx";
232 -- if Flag_N[+1] and then not Consequence_N[+1] then
233 -- raise Assertion_Error with "failed contract case at xxx";
235 -- end _Postconditions;
240 procedure Expand_Contract_Cases
244 Stmts
: in out List_Id
)
246 Loc
: constant Source_Ptr
:= Sloc
(CCs
);
248 procedure Case_Guard_Error
251 Error_Loc
: Source_Ptr
;
252 Msg
: in out Entity_Id
);
253 -- Given a declarative list Decls, status flag Flag, the location of the
254 -- error and a string Msg, construct the following check:
255 -- Msg : constant String :=
257 -- Msg & "case guard at Error_Loc evaluates to True"
259 -- The resulting code is added to Decls
261 procedure Consequence_Error
262 (Checks
: in out Node_Id
;
265 -- Given an if statement Checks, status flag Flag and a consequence
266 -- Conseq, construct the following check:
267 -- [els]if Flag and then not Conseq then
268 -- raise Assertion_Error
269 -- with "failed contract case at Sloc (Conseq)";
271 -- The resulting code is added to Checks
273 function Declaration_Of
(Id
: Entity_Id
) return Node_Id
;
274 -- Given the entity Id of a boolean flag, generate:
275 -- Id : Boolean := False;
277 procedure Expand_Attributes_In_Consequence
279 Evals
: in out Node_Id
;
282 -- Perform specialized expansion of all attribute 'Old references found
283 -- in consequence Conseq such that at runtime only prefixes coming from
284 -- the selected consequence are evaluated. Similarly expand attribute
285 -- 'Result references by replacing them with identifier _result which
286 -- resolves to the sole formal parameter of procedure _Postconditions.
287 -- Any temporaries generated in the process are added to declarations
288 -- Decls. Evals is a complex if statement tasked with the evaluation of
289 -- all prefixes coming from a single selected consequence. Flag is the
290 -- corresponding case guard flag. Conseq is the consequence expression.
292 function Increment
(Id
: Entity_Id
) return Node_Id
;
293 -- Given the entity Id of a numerical variable, generate:
296 function Set
(Id
: Entity_Id
) return Node_Id
;
297 -- Given the entity Id of a boolean variable, generate:
300 ----------------------
301 -- Case_Guard_Error --
302 ----------------------
304 procedure Case_Guard_Error
307 Error_Loc
: Source_Ptr
;
308 Msg
: in out Entity_Id
)
310 New_Line
: constant Character := Character'Val (10);
311 New_Msg
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
315 Store_String_Char
(New_Line
);
316 Store_String_Chars
(" case guard at ");
317 Store_String_Chars
(Build_Location_String
(Error_Loc
));
318 Store_String_Chars
(" evaluates to True");
321 -- New_Msg : constant String :=
323 -- Msg & "case guard at Error_Loc evaluates to True"
327 Make_Object_Declaration
(Loc
,
328 Defining_Identifier
=> New_Msg
,
329 Constant_Present
=> True,
330 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
332 Make_If_Expression
(Loc
,
333 Expressions
=> New_List
(
334 New_Occurrence_Of
(Flag
, Loc
),
337 Left_Opnd
=> New_Occurrence_Of
(Msg
, Loc
),
338 Right_Opnd
=> Make_String_Literal
(Loc
, End_String
)),
340 New_Occurrence_Of
(Msg
, Loc
)))));
343 end Case_Guard_Error
;
345 -----------------------
346 -- Consequence_Error --
347 -----------------------
349 procedure Consequence_Error
350 (Checks
: in out Node_Id
;
359 -- Flag and then not Conseq
363 Left_Opnd
=> New_Occurrence_Of
(Flag
, Loc
),
366 Right_Opnd
=> Relocate_Node
(Conseq
)));
369 -- raise Assertion_Error
370 -- with "failed contract case at Sloc (Conseq)";
373 Store_String_Chars
("failed contract case at ");
374 Store_String_Chars
(Build_Location_String
(Sloc
(Conseq
)));
377 Make_Procedure_Call_Statement
(Loc
,
379 New_Occurrence_Of
(RTE
(RE_Raise_Assert_Failure
), Loc
),
380 Parameter_Associations
=> New_List
(
381 Make_String_Literal
(Loc
, End_String
)));
385 Make_Implicit_If_Statement
(CCs
,
387 Then_Statements
=> New_List
(Error
));
390 if No
(Elsif_Parts
(Checks
)) then
391 Set_Elsif_Parts
(Checks
, New_List
);
394 Append_To
(Elsif_Parts
(Checks
),
395 Make_Elsif_Part
(Loc
,
397 Then_Statements
=> New_List
(Error
)));
399 end Consequence_Error
;
405 function Declaration_Of
(Id
: Entity_Id
) return Node_Id
is
408 Make_Object_Declaration
(Loc
,
409 Defining_Identifier
=> Id
,
410 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
411 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
414 --------------------------------------
415 -- Expand_Attributes_In_Consequence --
416 --------------------------------------
418 procedure Expand_Attributes_In_Consequence
420 Evals
: in out Node_Id
;
424 Eval_Stmts
: List_Id
:= No_List
;
425 -- The evaluation sequence expressed as assignment statements of all
426 -- prefixes of attribute 'Old found in the current consequence.
428 function Expand_Attributes
(N
: Node_Id
) return Traverse_Result
;
429 -- Determine whether an arbitrary node denotes attribute 'Old or
430 -- 'Result and if it does, perform all expansion-related actions.
432 -----------------------
433 -- Expand_Attributes --
434 -----------------------
436 function Expand_Attributes
(N
: Node_Id
) return Traverse_Result
is
444 if Nkind
(N
) = N_Attribute_Reference
445 and then Attribute_Name
(N
) = Name_Old
448 Temp
:= Make_Temporary
(Loc
, 'T', Pref
);
449 Set_Etype
(Temp
, Etype
(Pref
));
451 -- Generate a temporary to capture the value of the prefix:
452 -- Temp : <Pref type>;
453 -- Place that temporary at the beginning of declarations, to
454 -- prevent anomalies in the GNATprove flow-analysis pass in
455 -- the precondition procedure that follows.
458 Make_Object_Declaration
(Loc
,
459 Defining_Identifier
=> Temp
,
461 New_Occurrence_Of
(Etype
(Pref
), Loc
));
462 Set_No_Initialization
(Decl
);
464 Prepend_To
(Decls
, Decl
);
467 -- Evaluate the prefix, generate:
470 if No
(Eval_Stmts
) then
471 Eval_Stmts
:= New_List
;
474 Append_To
(Eval_Stmts
,
475 Make_Assignment_Statement
(Loc
,
476 Name
=> New_Occurrence_Of
(Temp
, Loc
),
477 Expression
=> Pref
));
479 -- Ensure that the prefix is valid
481 if Validity_Checks_On
and then Validity_Check_Operands
then
485 -- Replace the original attribute 'Old by a reference to the
486 -- generated temporary.
488 Rewrite
(N
, New_Occurrence_Of
(Temp
, Loc
));
492 elsif Is_Attribute_Result
(N
) then
493 Rewrite
(N
, Make_Identifier
(Loc
, Name_uResult
));
497 end Expand_Attributes
;
499 procedure Expand_Attributes_In
is
500 new Traverse_Proc
(Expand_Attributes
);
502 -- Start of processing for Expand_Attributes_In_Consequence
505 -- Inspect the consequence and expand any attribute 'Old and 'Result
506 -- references found within.
508 Expand_Attributes_In
(Conseq
);
510 -- The consequence does not contain any attribute 'Old references
512 if No
(Eval_Stmts
) then
516 -- Augment the machinery to trigger the evaluation of all prefixes
517 -- found in the step above. If Eval is empty, then this is the first
518 -- consequence to yield expansion of 'Old. Generate:
521 -- <evaluation statements>
526 Make_Implicit_If_Statement
(CCs
,
527 Condition
=> New_Occurrence_Of
(Flag
, Loc
),
528 Then_Statements
=> Eval_Stmts
);
530 -- Otherwise generate:
532 -- <evaluation statements>
536 if No
(Elsif_Parts
(Evals
)) then
537 Set_Elsif_Parts
(Evals
, New_List
);
540 Append_To
(Elsif_Parts
(Evals
),
541 Make_Elsif_Part
(Loc
,
542 Condition
=> New_Occurrence_Of
(Flag
, Loc
),
543 Then_Statements
=> Eval_Stmts
));
545 end Expand_Attributes_In_Consequence
;
551 function Increment
(Id
: Entity_Id
) return Node_Id
is
554 Make_Assignment_Statement
(Loc
,
555 Name
=> New_Occurrence_Of
(Id
, Loc
),
558 Left_Opnd
=> New_Occurrence_Of
(Id
, Loc
),
559 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
566 function Set
(Id
: Entity_Id
) return Node_Id
is
569 Make_Assignment_Statement
(Loc
,
570 Name
=> New_Occurrence_Of
(Id
, Loc
),
571 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
));
576 Aggr
: constant Node_Id
:=
578 (Pragma_Argument_Associations
(CCs
)));
579 Case_Guard
: Node_Id
;
583 Conseq_Checks
: Node_Id
:= Empty
;
585 Count_Decl
: Node_Id
;
586 Error_Decls
: List_Id
;
591 Multiple_PCs
: Boolean;
592 Old_Evals
: Node_Id
:= Empty
;
593 Others_Decl
: Node_Id
;
594 Others_Flag
: Entity_Id
:= Empty
;
597 -- Start of processing for Expand_Contract_Cases
600 -- Do nothing if pragma is not enabled. If pragma is disabled, it has
601 -- already been rewritten as a Null statement.
603 if Is_Ignored
(CCs
) then
606 -- Guard against malformed contract cases
608 elsif Nkind
(Aggr
) /= N_Aggregate
then
612 Multiple_PCs
:= List_Length
(Component_Associations
(Aggr
)) > 1;
614 -- Create the counter which tracks the number of case guards that
617 -- Count : Natural := 0;
619 Count
:= Make_Temporary
(Loc
, 'C');
621 Make_Object_Declaration
(Loc
,
622 Defining_Identifier
=> Count
,
623 Object_Definition
=> New_Occurrence_Of
(Standard_Natural
, Loc
),
624 Expression
=> Make_Integer_Literal
(Loc
, 0));
626 Prepend_To
(Decls
, Count_Decl
);
627 Analyze
(Count_Decl
);
629 -- Create the base error message for multiple overlapping case guards
631 -- Msg_Str : constant String :=
632 -- "contract cases overlap for subprogram Subp_Id";
635 Msg_Str
:= Make_Temporary
(Loc
, 'S');
638 Store_String_Chars
("contract cases overlap for subprogram ");
639 Store_String_Chars
(Get_Name_String
(Chars
(Subp_Id
)));
641 Error_Decls
:= New_List
(
642 Make_Object_Declaration
(Loc
,
643 Defining_Identifier
=> Msg_Str
,
644 Constant_Present
=> True,
645 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
646 Expression
=> Make_String_Literal
(Loc
, End_String
)));
649 -- Process individual post cases
651 Post_Case
:= First
(Component_Associations
(Aggr
));
652 while Present
(Post_Case
) loop
653 Case_Guard
:= First
(Choices
(Post_Case
));
654 Conseq
:= Expression
(Post_Case
);
656 -- The "others" choice requires special processing
658 if Nkind
(Case_Guard
) = N_Others_Choice
then
659 Others_Flag
:= Make_Temporary
(Loc
, 'F');
660 Others_Decl
:= Declaration_Of
(Others_Flag
);
662 Prepend_To
(Decls
, Others_Decl
);
663 Analyze
(Others_Decl
);
665 -- Check possible overlap between a case guard and "others"
667 if Multiple_PCs
and Exception_Extra_Info
then
669 (Decls
=> Error_Decls
,
671 Error_Loc
=> Sloc
(Case_Guard
),
675 -- Inspect the consequence and perform special expansion of any
676 -- attribute 'Old and 'Result references found within.
678 Expand_Attributes_In_Consequence
684 -- Check the corresponding consequence of "others"
687 (Checks
=> Conseq_Checks
,
694 -- Create the flag which tracks the state of its associated case
697 Flag
:= Make_Temporary
(Loc
, 'F');
698 Flag_Decl
:= Declaration_Of
(Flag
);
700 Prepend_To
(Decls
, Flag_Decl
);
703 -- The flag is set when the case guard is evaluated to True
704 -- if Case_Guard then
706 -- Count := Count + 1;
710 Make_Implicit_If_Statement
(CCs
,
711 Condition
=> Relocate_Node
(Case_Guard
),
712 Then_Statements
=> New_List
(
716 Append_To
(Decls
, If_Stmt
);
719 -- Check whether this case guard overlaps with another one
721 if Multiple_PCs
and Exception_Extra_Info
then
723 (Decls
=> Error_Decls
,
725 Error_Loc
=> Sloc
(Case_Guard
),
729 -- Inspect the consequence and perform special expansion of any
730 -- attribute 'Old and 'Result references found within.
732 Expand_Attributes_In_Consequence
738 -- The corresponding consequence of the case guard which evaluated
739 -- to True must hold on exit from the subprogram.
742 (Checks
=> Conseq_Checks
,
750 -- Raise Assertion_Error when none of the case guards evaluate to True.
751 -- The only exception is when we have "others", in which case there is
752 -- no error because "others" acts as a default True.
757 if Present
(Others_Flag
) then
758 CG_Stmts
:= New_List
(Set
(Others_Flag
));
761 -- raise Assertion_Error with "xxx contract cases incomplete";
765 Store_String_Chars
(Build_Location_String
(Loc
));
766 Store_String_Chars
(" contract cases incomplete");
768 CG_Stmts
:= New_List
(
769 Make_Procedure_Call_Statement
(Loc
,
771 New_Occurrence_Of
(RTE
(RE_Raise_Assert_Failure
), Loc
),
772 Parameter_Associations
=> New_List
(
773 Make_String_Literal
(Loc
, End_String
))));
777 Make_Implicit_If_Statement
(CCs
,
780 Left_Opnd
=> New_Occurrence_Of
(Count
, Loc
),
781 Right_Opnd
=> Make_Integer_Literal
(Loc
, 0)),
782 Then_Statements
=> CG_Stmts
);
784 -- Detect a possible failure due to several case guards evaluating to
788 -- elsif Count > 0 then
792 -- raise Assertion_Error with <Msg_Str>;
796 Set_Elsif_Parts
(CG_Checks
, New_List
(
797 Make_Elsif_Part
(Loc
,
800 Left_Opnd
=> New_Occurrence_Of
(Count
, Loc
),
801 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
803 Then_Statements
=> New_List
(
804 Make_Block_Statement
(Loc
,
805 Declarations
=> Error_Decls
,
806 Handled_Statement_Sequence
=>
807 Make_Handled_Sequence_Of_Statements
(Loc
,
808 Statements
=> New_List
(
809 Make_Procedure_Call_Statement
(Loc
,
812 (RTE
(RE_Raise_Assert_Failure
), Loc
),
813 Parameter_Associations
=> New_List
(
814 New_Occurrence_Of
(Msg_Str
, Loc
))))))))));
817 Append_To
(Decls
, CG_Checks
);
820 -- Once all case guards are evaluated and checked, evaluate any prefixes
821 -- of attribute 'Old founds in the selected consequence.
823 if Present
(Old_Evals
) then
824 Append_To
(Decls
, Old_Evals
);
828 -- Raise Assertion_Error when the corresponding consequence of a case
829 -- guard that evaluated to True fails.
835 Append_To
(Stmts
, Conseq_Checks
);
836 end Expand_Contract_Cases
;
838 ---------------------
839 -- Expand_N_Pragma --
840 ---------------------
842 procedure Expand_N_Pragma
(N
: Node_Id
) is
843 Pname
: constant Name_Id
:= Pragma_Name
(N
);
846 -- Note: we may have a pragma whose Pragma_Identifier field is not a
847 -- recognized pragma, and we must ignore it at this stage.
849 if Is_Pragma_Name
(Pname
) then
850 case Get_Pragma_Id
(Pname
) is
852 -- Pragmas requiring special expander action
854 when Pragma_Abort_Defer
=>
855 Expand_Pragma_Abort_Defer
(N
);
858 Expand_Pragma_Check
(N
);
860 when Pragma_Common_Object
=>
861 Expand_Pragma_Common_Object
(N
);
863 when Pragma_Import
=>
864 Expand_Pragma_Import_Or_Interface
(N
);
866 when Pragma_Inspection_Point
=>
867 Expand_Pragma_Inspection_Point
(N
);
869 when Pragma_Interface
=>
870 Expand_Pragma_Import_Or_Interface
(N
);
872 when Pragma_Interrupt_Priority
=>
873 Expand_Pragma_Interrupt_Priority
(N
);
875 when Pragma_Loop_Variant
=>
876 Expand_Pragma_Loop_Variant
(N
);
878 when Pragma_Psect_Object
=>
879 Expand_Pragma_Psect_Object
(N
);
881 when Pragma_Relative_Deadline
=>
882 Expand_Pragma_Relative_Deadline
(N
);
884 when Pragma_Suppress_Initialization
=>
885 Expand_Pragma_Suppress_Initialization
(N
);
887 -- All other pragmas need no expander action
895 -------------------------------
896 -- Expand_Pragma_Abort_Defer --
897 -------------------------------
899 -- An Abort_Defer pragma appears as the first statement in a handled
900 -- statement sequence (right after the begin). It defers aborts for
901 -- the entire statement sequence, but not for any declarations or
902 -- handlers (if any) associated with this statement sequence.
904 -- The transformation is to transform
906 -- pragma Abort_Defer;
915 -- when all others =>
916 -- Abort_Undefer.all;
919 -- Abort_Undefer_Direct;
922 procedure Expand_Pragma_Abort_Defer
(N
: Node_Id
) is
923 Loc
: constant Source_Ptr
:= Sloc
(N
);
927 Blk
: constant Entity_Id
:=
928 New_Internal_Entity
(E_Block
, Current_Scope
, Sloc
(N
), 'B');
929 AUD
: constant Entity_Id
:= RTE
(RE_Abort_Undefer_Direct
);
932 Stms
:= New_List
(Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
934 Stm
:= Remove_Next
(N
);
940 Make_Handled_Sequence_Of_Statements
(Loc
,
942 At_End_Proc
=> New_Occurrence_Of
(AUD
, Loc
));
944 -- Present the Abort_Undefer_Direct function to the backend so that it
945 -- can inline the call to the function.
947 Add_Inlined_Body
(AUD
, N
);
950 Make_Block_Statement
(Loc
,
951 Handled_Statement_Sequence
=> HSS
));
953 Set_Scope
(Blk
, Current_Scope
);
954 Set_Etype
(Blk
, Standard_Void_Type
);
955 Set_Identifier
(N
, New_Occurrence_Of
(Blk
, Sloc
(N
)));
956 Expand_At_End_Handler
(HSS
, Blk
);
958 end Expand_Pragma_Abort_Defer
;
960 --------------------------
961 -- Expand_Pragma_Check --
962 --------------------------
964 procedure Expand_Pragma_Check
(N
: Node_Id
) is
965 Cond
: constant Node_Id
:= Arg2
(N
);
966 Nam
: constant Name_Id
:= Chars
(Arg1
(N
));
969 Loc
: constant Source_Ptr
:= Sloc
(First_Node
(Cond
));
970 -- Source location used in the case of a failed assertion: point to the
971 -- failing condition, not Loc. Note that the source location of the
972 -- expression is not usually the best choice here, because it points to
973 -- the location of the topmost tree node, which may be an operator in
974 -- the middle of the source text of the expression. For example, it gets
975 -- located on the last AND keyword in a chain of boolean expressiond
976 -- AND'ed together. It is best to put the message on the first character
977 -- of the condition, which is the effect of the First_Node call here.
978 -- This source location is used to build the default exception message,
979 -- and also as the sloc of the call to the runtime subprogram raising
980 -- Assert_Failure, so that coverage analysis tools can relate the
981 -- call to the failed check.
984 -- Nothing to do if pragma is ignored
986 if Is_Ignored
(N
) then
990 -- Since this check is active, we rewrite the pragma into a
991 -- corresponding if statement, and then analyze the statement
993 -- The normal case expansion transforms:
995 -- pragma Check (name, condition [,message]);
999 -- if not condition then
1000 -- System.Assertions.Raise_Assert_Failure (Str);
1003 -- where Str is the message if one is present, or the default of
1004 -- name failed at file:line if no message is given (the "name failed
1005 -- at" is omitted for name = Assertion, since it is redundant, given
1006 -- that the name of the exception is Assert_Failure.)
1008 -- Also, instead of "XXX failed at", we generate slightly
1009 -- different messages for some of the contract assertions (see
1010 -- code below for details).
1012 -- An alternative expansion is used when the No_Exception_Propagation
1013 -- restriction is active and there is a local Assert_Failure handler.
1014 -- This is not a common combination of circumstances, but it occurs in
1015 -- the context of Aunit and the zero footprint profile. In this case we
1018 -- if not condition then
1019 -- raise Assert_Failure;
1022 -- This will then be transformed into a goto, and the local handler will
1023 -- be able to handle the assert error (which would not be the case if a
1024 -- call is made to the Raise_Assert_Failure procedure).
1026 -- We also generate the direct raise if the Suppress_Exception_Locations
1027 -- is active, since we don't want to generate messages in this case.
1029 -- Note that the reason we do not always generate a direct raise is that
1030 -- the form in which the procedure is called allows for more efficient
1031 -- breakpointing of assertion errors.
1033 -- Generate the appropriate if statement. Note that we consider this to
1034 -- be an explicit conditional in the source, not an implicit if, so we
1035 -- do not call Make_Implicit_If_Statement.
1037 -- Case where we generate a direct raise
1039 if ((Debug_Flag_Dot_G
1040 or else Restriction_Active
(No_Exception_Propagation
))
1041 and then Present
(Find_Local_Handler
(RTE
(RE_Assert_Failure
), N
)))
1042 or else (Opt
.Exception_Locations_Suppressed
and then No
(Arg3
(N
)))
1045 Make_If_Statement
(Loc
,
1046 Condition
=> Make_Op_Not
(Loc
, Right_Opnd
=> Cond
),
1047 Then_Statements
=> New_List
(
1048 Make_Raise_Statement
(Loc
,
1049 Name
=> New_Occurrence_Of
(RTE
(RE_Assert_Failure
), Loc
)))));
1051 -- Case where we call the procedure
1054 -- If we have a message given, use it
1056 if Present
(Arg3
(N
)) then
1057 Msg
:= Get_Pragma_Arg
(Arg3
(N
));
1059 -- Here we have no string, so prepare one
1063 Loc_Str
: constant String := Build_Location_String
(Loc
);
1068 -- For Assert, we just use the location
1070 if Nam
= Name_Assert
then
1073 -- For predicate, we generate the string "predicate failed
1074 -- at yyy". We prefer all lower case for predicate.
1076 elsif Nam
= Name_Predicate
then
1077 Add_Str_To_Name_Buffer
("predicate failed at ");
1079 -- For special case of Precondition/Postcondition the string is
1080 -- "failed xx from yy" where xx is precondition/postcondition
1081 -- in all lower case. The reason for this different wording is
1082 -- that the failure is not at the point of occurrence of the
1083 -- pragma, unlike the other Check cases.
1085 elsif Nam_In
(Nam
, Name_Precondition
, Name_Postcondition
) then
1086 Get_Name_String
(Nam
);
1087 Insert_Str_In_Name_Buffer
("failed ", 1);
1088 Add_Str_To_Name_Buffer
(" from ");
1090 -- For special case of Invariant, the string is "failed
1091 -- invariant from yy", to be consistent with the string that is
1092 -- generated for the aspect case (the code later on checks for
1093 -- this specific string to modify it in some cases, so this is
1094 -- functionally important).
1096 elsif Nam
= Name_Invariant
then
1097 Add_Str_To_Name_Buffer
("failed invariant from ");
1099 -- For all other checks, the string is "xxx failed at yyy"
1100 -- where xxx is the check name with current source file casing.
1103 Get_Name_String
(Nam
);
1104 Set_Casing
(Identifier_Casing
(Current_Source_File
));
1105 Add_Str_To_Name_Buffer
(" failed at ");
1108 -- In all cases, add location string
1110 Add_Str_To_Name_Buffer
(Loc_Str
);
1112 -- Build the message
1114 Msg
:= Make_String_Literal
(Loc
, Name_Buffer
(1 .. Name_Len
));
1118 -- Now rewrite as an if statement
1121 Make_If_Statement
(Loc
,
1122 Condition
=> Make_Op_Not
(Loc
, Right_Opnd
=> Cond
),
1123 Then_Statements
=> New_List
(
1124 Make_Procedure_Call_Statement
(Loc
,
1126 New_Occurrence_Of
(RTE
(RE_Raise_Assert_Failure
), Loc
),
1127 Parameter_Associations
=> New_List
(Relocate_Node
(Msg
))))));
1132 -- If new condition is always false, give a warning
1134 if Warn_On_Assertion_Failure
1135 and then Nkind
(N
) = N_Procedure_Call_Statement
1136 and then Is_RTE
(Entity
(Name
(N
)), RE_Raise_Assert_Failure
)
1138 -- If original condition was a Standard.False, we assume that this is
1139 -- indeed intended to raise assert error and no warning is required.
1141 if Is_Entity_Name
(Original_Node
(Cond
))
1142 and then Entity
(Original_Node
(Cond
)) = Standard_False
1146 elsif Nam
= Name_Assert
then
1147 Error_Msg_N
("?A?assertion will fail at run time", N
);
1150 Error_Msg_N
("?A?check will fail at run time", N
);
1153 end Expand_Pragma_Check
;
1155 ---------------------------------
1156 -- Expand_Pragma_Common_Object --
1157 ---------------------------------
1159 -- Use a machine attribute to replicate semantic effect in DEC Ada
1161 -- pragma Machine_Attribute (intern_name, "common_object", extern_name);
1163 -- For now we do nothing with the size attribute ???
1165 -- Note: Psect_Object shares this processing
1167 procedure Expand_Pragma_Common_Object
(N
: Node_Id
) is
1168 Loc
: constant Source_Ptr
:= Sloc
(N
);
1170 Internal
: constant Node_Id
:= Arg1
(N
);
1171 External
: constant Node_Id
:= Arg2
(N
);
1174 -- Psect value upper cased as string literal
1176 Iloc
: constant Source_Ptr
:= Sloc
(Internal
);
1177 Eloc
: constant Source_Ptr
:= Sloc
(External
);
1181 -- Acquire Psect value and fold to upper case
1183 if Present
(External
) then
1184 if Nkind
(External
) = N_String_Literal
then
1185 String_To_Name_Buffer
(Strval
(External
));
1187 Get_Name_String
(Chars
(External
));
1193 Make_String_Literal
(Eloc
, Strval
=> String_From_Name_Buffer
);
1196 Get_Name_String
(Chars
(Internal
));
1199 Make_String_Literal
(Iloc
, Strval
=> String_From_Name_Buffer
);
1202 Ploc
:= Sloc
(Psect
);
1204 -- Insert the pragma
1206 Insert_After_And_Analyze
(N
,
1208 Chars
=> Name_Machine_Attribute
,
1209 Pragma_Argument_Associations
=> New_List
(
1210 Make_Pragma_Argument_Association
(Iloc
,
1211 Expression
=> New_Copy_Tree
(Internal
)),
1212 Make_Pragma_Argument_Association
(Eloc
,
1214 Make_String_Literal
(Sloc
=> Ploc
, Strval
=> "common_object")),
1215 Make_Pragma_Argument_Association
(Ploc
,
1216 Expression
=> New_Copy_Tree
(Psect
)))));
1217 end Expand_Pragma_Common_Object
;
1219 ---------------------------------------
1220 -- Expand_Pragma_Import_Or_Interface --
1221 ---------------------------------------
1223 procedure Expand_Pragma_Import_Or_Interface
(N
: Node_Id
) is
1227 -- In Relaxed_RM_Semantics, support old Ada 83 style:
1228 -- pragma Import (Entity, "external name");
1230 if Relaxed_RM_Semantics
1231 and then List_Length
(Pragma_Argument_Associations
(N
)) = 2
1232 and then Chars
(Pragma_Identifier
(N
)) = Name_Import
1233 and then Nkind
(Arg2
(N
)) = N_String_Literal
1235 Def_Id
:= Entity
(Arg1
(N
));
1237 Def_Id
:= Entity
(Arg2
(N
));
1240 -- Variable case (we have to undo any initialization already done)
1242 if Ekind
(Def_Id
) = E_Variable
then
1243 Undo_Initialization
(Def_Id
, N
);
1245 -- Case of exception with convention C++
1247 elsif Ekind
(Def_Id
) = E_Exception
1248 and then Convention
(Def_Id
) = Convention_CPP
1250 -- Import a C++ convention
1253 Loc
: constant Source_Ptr
:= Sloc
(N
);
1254 Rtti_Name
: constant Node_Id
:= Arg3
(N
);
1255 Dum
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
1257 Lang_Char
: Node_Id
;
1258 Foreign_Data
: Node_Id
;
1261 Exdata
:= Component_Associations
(Expression
(Parent
(Def_Id
)));
1263 Lang_Char
:= Next
(First
(Exdata
));
1265 -- Change the one-character language designator to 'C'
1267 Rewrite
(Expression
(Lang_Char
),
1268 Make_Character_Literal
(Loc
,
1270 Char_Literal_Value
=> UI_From_Int
(Character'Pos ('C'))));
1271 Analyze
(Expression
(Lang_Char
));
1273 -- Change the value of Foreign_Data
1275 Foreign_Data
:= Next
(Next
(Next
(Next
(Lang_Char
))));
1277 Insert_Actions
(Def_Id
, New_List
(
1278 Make_Object_Declaration
(Loc
,
1279 Defining_Identifier
=> Dum
,
1280 Object_Definition
=>
1281 New_Occurrence_Of
(Standard_Character
, Loc
)),
1284 Chars
=> Name_Import
,
1285 Pragma_Argument_Associations
=> New_List
(
1286 Make_Pragma_Argument_Association
(Loc
,
1287 Expression
=> Make_Identifier
(Loc
, Name_Ada
)),
1289 Make_Pragma_Argument_Association
(Loc
,
1290 Expression
=> Make_Identifier
(Loc
, Chars
(Dum
))),
1292 Make_Pragma_Argument_Association
(Loc
,
1293 Chars
=> Name_External_Name
,
1294 Expression
=> Relocate_Node
(Rtti_Name
))))));
1296 Rewrite
(Expression
(Foreign_Data
),
1297 Unchecked_Convert_To
(Standard_A_Char
,
1298 Make_Attribute_Reference
(Loc
,
1299 Prefix
=> Make_Identifier
(Loc
, Chars
(Dum
)),
1300 Attribute_Name
=> Name_Address
)));
1301 Analyze
(Expression
(Foreign_Data
));
1304 -- No special expansion required for any other case
1309 end Expand_Pragma_Import_Or_Interface
;
1311 -------------------------------------
1312 -- Expand_Pragma_Initial_Condition --
1313 -------------------------------------
1315 procedure Expand_Pragma_Initial_Condition
(Spec_Or_Body
: Node_Id
) is
1316 Loc
: constant Source_Ptr
:= Sloc
(Spec_Or_Body
);
1319 Init_Cond
: Node_Id
;
1321 Pack_Id
: Entity_Id
;
1324 if Nkind
(Spec_Or_Body
) = N_Package_Body
then
1325 Pack_Id
:= Corresponding_Spec
(Spec_Or_Body
);
1327 if Present
(Handled_Statement_Sequence
(Spec_Or_Body
)) then
1328 List
:= Statements
(Handled_Statement_Sequence
(Spec_Or_Body
));
1330 -- The package body lacks statements, create an empty list
1335 Set_Handled_Statement_Sequence
(Spec_Or_Body
,
1336 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> List
));
1339 elsif Nkind
(Spec_Or_Body
) = N_Package_Declaration
then
1340 Pack_Id
:= Defining_Entity
(Spec_Or_Body
);
1342 if Present
(Visible_Declarations
(Specification
(Spec_Or_Body
))) then
1343 List
:= Visible_Declarations
(Specification
(Spec_Or_Body
));
1345 -- The package lacks visible declarations, create an empty list
1350 Set_Visible_Declarations
(Specification
(Spec_Or_Body
), List
);
1353 -- This routine should not be used on anything other than packages
1356 raise Program_Error
;
1359 Init_Cond
:= Get_Pragma
(Pack_Id
, Pragma_Initial_Condition
);
1361 -- The caller should check whether the package is subject to pragma
1362 -- Initial_Condition.
1364 pragma Assert
(Present
(Init_Cond
));
1367 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Init_Cond
)));
1369 -- The assertion expression was found to be illegal, do not generate the
1370 -- runtime check as it will repeat the illegality.
1372 if Error_Posted
(Init_Cond
) or else Error_Posted
(Expr
) then
1377 -- pragma Check (Initial_Condition, <Expr>);
1381 Chars
=> Name_Check
,
1382 Pragma_Argument_Associations
=> New_List
(
1383 Make_Pragma_Argument_Association
(Loc
,
1384 Expression
=> Make_Identifier
(Loc
, Name_Initial_Condition
)),
1386 Make_Pragma_Argument_Association
(Loc
,
1387 Expression
=> New_Copy_Tree
(Expr
))));
1389 Append_To
(List
, Check
);
1391 end Expand_Pragma_Initial_Condition
;
1393 ------------------------------------
1394 -- Expand_Pragma_Inspection_Point --
1395 ------------------------------------
1397 -- If no argument is given, then we supply a default argument list that
1398 -- includes all objects declared at the source level in all subprograms
1399 -- that enclose the inspection point pragma.
1401 procedure Expand_Pragma_Inspection_Point
(N
: Node_Id
) is
1402 Loc
: constant Source_Ptr
:= Sloc
(N
);
1409 if No
(Pragma_Argument_Associations
(N
)) then
1413 while S
/= Standard_Standard
loop
1414 E
:= First_Entity
(S
);
1415 while Present
(E
) loop
1416 if Comes_From_Source
(E
)
1417 and then Is_Object
(E
)
1418 and then not Is_Entry_Formal
(E
)
1419 and then Ekind
(E
) /= E_Component
1420 and then Ekind
(E
) /= E_Discriminant
1421 and then Ekind
(E
) /= E_Generic_In_Parameter
1422 and then Ekind
(E
) /= E_Generic_In_Out_Parameter
1425 Make_Pragma_Argument_Association
(Loc
,
1426 Expression
=> New_Occurrence_Of
(E
, Loc
)));
1435 Set_Pragma_Argument_Associations
(N
, A
);
1438 -- Expand the arguments of the pragma. Expanding an entity reference
1439 -- is a noop, except in a protected operation, where a reference may
1440 -- have to be transformed into a reference to the corresponding prival.
1441 -- Are there other pragmas that may require this ???
1443 Assoc
:= First
(Pragma_Argument_Associations
(N
));
1445 while Present
(Assoc
) loop
1446 Expand
(Expression
(Assoc
));
1449 end Expand_Pragma_Inspection_Point
;
1451 --------------------------------------
1452 -- Expand_Pragma_Interrupt_Priority --
1453 --------------------------------------
1455 -- Supply default argument if none exists (System.Interrupt_Priority'Last)
1457 procedure Expand_Pragma_Interrupt_Priority
(N
: Node_Id
) is
1458 Loc
: constant Source_Ptr
:= Sloc
(N
);
1461 if No
(Pragma_Argument_Associations
(N
)) then
1462 Set_Pragma_Argument_Associations
(N
, New_List
(
1463 Make_Pragma_Argument_Association
(Loc
,
1465 Make_Attribute_Reference
(Loc
,
1467 New_Occurrence_Of
(RTE
(RE_Interrupt_Priority
), Loc
),
1468 Attribute_Name
=> Name_Last
))));
1470 end Expand_Pragma_Interrupt_Priority
;
1472 --------------------------------
1473 -- Expand_Pragma_Loop_Variant --
1474 --------------------------------
1476 -- Pragma Loop_Variant is expanded in the following manner:
1480 -- for | while ... loop
1481 -- <preceding source statements>
1482 -- pragma Loop_Variant
1483 -- (Increases => Incr_Expr,
1484 -- Decreases => Decr_Expr);
1485 -- <succeeding source statements>
1490 -- Curr_1 : <type of Incr_Expr>;
1491 -- Curr_2 : <type of Decr_Expr>;
1492 -- Old_1 : <type of Incr_Expr>;
1493 -- Old_2 : <type of Decr_Expr>;
1494 -- Flag : Boolean := False;
1496 -- for | while ... loop
1497 -- <preceding source statements>
1504 -- Curr_1 := <Incr_Expr>;
1505 -- Curr_2 := <Decr_Expr>;
1508 -- if Curr_1 /= Old_1 then
1509 -- pragma Check (Loop_Variant, Curr_1 > Old_1);
1511 -- pragma Check (Loop_Variant, Curr_2 < Old_2);
1517 -- <succeeding source statements>
1520 procedure Expand_Pragma_Loop_Variant
(N
: Node_Id
) is
1521 Loc
: constant Source_Ptr
:= Sloc
(N
);
1523 Last_Var
: constant Node_Id
:= Last
(Pragma_Argument_Associations
(N
));
1525 Curr_Assign
: List_Id
:= No_List
;
1526 Flag_Id
: Entity_Id
:= Empty
;
1527 If_Stmt
: Node_Id
:= Empty
;
1528 Old_Assign
: List_Id
:= No_List
;
1529 Loop_Scop
: Entity_Id
;
1530 Loop_Stmt
: Node_Id
;
1533 procedure Process_Variant
(Variant
: Node_Id
; Is_Last
: Boolean);
1534 -- Process a single increasing / decreasing termination variant. Flag
1535 -- Is_Last should be set when processing the last variant.
1537 ---------------------
1538 -- Process_Variant --
1539 ---------------------
1541 procedure Process_Variant
(Variant
: Node_Id
; Is_Last
: Boolean) is
1545 Old_Val
: Node_Id
) return Node_Id
;
1546 -- Generate a comparison between Curr_Val and Old_Val depending on
1547 -- the change mode (Increases / Decreases) of the variant.
1556 Old_Val
: Node_Id
) return Node_Id
1559 if Chars
(Variant
) = Name_Increases
then
1560 return Make_Op_Gt
(Loc
, Curr_Val
, Old_Val
);
1561 else pragma Assert
(Chars
(Variant
) = Name_Decreases
);
1562 return Make_Op_Lt
(Loc
, Curr_Val
, Old_Val
);
1568 Expr
: constant Node_Id
:= Expression
(Variant
);
1569 Expr_Typ
: constant Entity_Id
:= Etype
(Expr
);
1570 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1571 Loop_Loc
: constant Source_Ptr
:= Sloc
(Loop_Stmt
);
1572 Curr_Id
: Entity_Id
;
1576 -- Start of processing for Process_Variant
1579 -- All temporaries generated in this routine must be inserted before
1580 -- the related loop statement. Ensure that the proper scope is on the
1581 -- stack when analyzing the temporaries. Note that we also use the
1582 -- Sloc of the related loop.
1584 Push_Scope
(Scope
(Loop_Scop
));
1586 -- Step 1: Create the declaration of the flag which controls the
1587 -- behavior of the assertion on the first iteration of the loop.
1589 if No
(Flag_Id
) then
1592 -- Flag : Boolean := False;
1594 Flag_Id
:= Make_Temporary
(Loop_Loc
, 'F');
1596 Insert_Action
(Loop_Stmt
,
1597 Make_Object_Declaration
(Loop_Loc
,
1598 Defining_Identifier
=> Flag_Id
,
1599 Object_Definition
=>
1600 New_Occurrence_Of
(Standard_Boolean
, Loop_Loc
),
1602 New_Occurrence_Of
(Standard_False
, Loop_Loc
)));
1604 -- Prevent an unwanted optimization where the Current_Value of
1605 -- the flag eliminates the if statement which stores the variant
1606 -- values coming from the previous iteration.
1608 -- Flag : Boolean := False;
1610 -- if Flag then -- condition rewritten to False
1611 -- Old_N := Curr_N; -- and if statement eliminated
1617 Set_Current_Value
(Flag_Id
, Empty
);
1620 -- Step 2: Create the temporaries which store the old and current
1621 -- values of the associated expression.
1624 -- Curr : <type of Expr>;
1626 Curr_Id
:= Make_Temporary
(Loc
, 'C');
1628 Insert_Action
(Loop_Stmt
,
1629 Make_Object_Declaration
(Loop_Loc
,
1630 Defining_Identifier
=> Curr_Id
,
1631 Object_Definition
=> New_Occurrence_Of
(Expr_Typ
, Loop_Loc
)));
1634 -- Old : <type of Expr>;
1636 Old_Id
:= Make_Temporary
(Loc
, 'P');
1638 Insert_Action
(Loop_Stmt
,
1639 Make_Object_Declaration
(Loop_Loc
,
1640 Defining_Identifier
=> Old_Id
,
1641 Object_Definition
=> New_Occurrence_Of
(Expr_Typ
, Loop_Loc
)));
1643 -- Restore original scope after all temporaries have been analyzed
1647 -- Step 3: Store value of the expression from the previous iteration
1649 if No
(Old_Assign
) then
1650 Old_Assign
:= New_List
;
1656 Append_To
(Old_Assign
,
1657 Make_Assignment_Statement
(Loc
,
1658 Name
=> New_Occurrence_Of
(Old_Id
, Loc
),
1659 Expression
=> New_Occurrence_Of
(Curr_Id
, Loc
)));
1661 -- Step 4: Store the current value of the expression
1663 if No
(Curr_Assign
) then
1664 Curr_Assign
:= New_List
;
1670 Append_To
(Curr_Assign
,
1671 Make_Assignment_Statement
(Loc
,
1672 Name
=> New_Occurrence_Of
(Curr_Id
, Loc
),
1673 Expression
=> Relocate_Node
(Expr
)));
1675 -- Step 5: Create corresponding assertion to verify change of value
1678 -- pragma Check (Loop_Variant, Curr <|> Old);
1682 Chars
=> Name_Check
,
1683 Pragma_Argument_Associations
=> New_List
(
1684 Make_Pragma_Argument_Association
(Loc
,
1685 Expression
=> Make_Identifier
(Loc
, Name_Loop_Variant
)),
1686 Make_Pragma_Argument_Association
(Loc
,
1689 Curr_Val
=> New_Occurrence_Of
(Curr_Id
, Loc
),
1690 Old_Val
=> New_Occurrence_Of
(Old_Id
, Loc
)))));
1693 -- if Curr /= Old then
1696 if No
(If_Stmt
) then
1698 -- When there is just one termination variant, do not compare the
1699 -- old and current value for equality, just check the pragma.
1705 Make_If_Statement
(Loc
,
1708 Left_Opnd
=> New_Occurrence_Of
(Curr_Id
, Loc
),
1709 Right_Opnd
=> New_Occurrence_Of
(Old_Id
, Loc
)),
1710 Then_Statements
=> New_List
(Prag
));
1719 Set_Else_Statements
(If_Stmt
, New_List
(Prag
));
1722 -- elsif Curr /= Old then
1726 if Elsif_Parts
(If_Stmt
) = No_List
then
1727 Set_Elsif_Parts
(If_Stmt
, New_List
);
1730 Append_To
(Elsif_Parts
(If_Stmt
),
1731 Make_Elsif_Part
(Loc
,
1734 Left_Opnd
=> New_Occurrence_Of
(Curr_Id
, Loc
),
1735 Right_Opnd
=> New_Occurrence_Of
(Old_Id
, Loc
)),
1736 Then_Statements
=> New_List
(Prag
)));
1738 end Process_Variant
;
1740 -- Start of processing for Expand_Pragma_Loop_Variant
1743 -- If pragma is not enabled, rewrite as Null statement. If pragma is
1744 -- disabled, it has already been rewritten as a Null statement.
1746 if Is_Ignored
(N
) then
1747 Rewrite
(N
, Make_Null_Statement
(Loc
));
1752 -- Locate the enclosing loop for which this assertion applies. In the
1753 -- case of Ada 2012 array iteration, we might be dealing with nested
1754 -- loops. Only the outermost loop has an identifier.
1757 while Present
(Loop_Stmt
) loop
1758 if Nkind
(Loop_Stmt
) = N_Loop_Statement
1759 and then Present
(Identifier
(Loop_Stmt
))
1764 Loop_Stmt
:= Parent
(Loop_Stmt
);
1767 Loop_Scop
:= Entity
(Identifier
(Loop_Stmt
));
1769 -- Create the circuitry which verifies individual variants
1771 Variant
:= First
(Pragma_Argument_Associations
(N
));
1772 while Present
(Variant
) loop
1773 Process_Variant
(Variant
, Is_Last
=> Variant
= Last_Var
);
1778 -- Construct the segment which stores the old values of all expressions.
1785 Make_If_Statement
(Loc
,
1786 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
1787 Then_Statements
=> Old_Assign
));
1789 -- Update the values of all expressions
1791 Insert_Actions
(N
, Curr_Assign
);
1793 -- Add the assertion circuitry to test all changes in expressions.
1802 Make_If_Statement
(Loc
,
1803 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
1804 Then_Statements
=> New_List
(If_Stmt
),
1805 Else_Statements
=> New_List
(
1806 Make_Assignment_Statement
(Loc
,
1807 Name
=> New_Occurrence_Of
(Flag_Id
, Loc
),
1808 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)))));
1810 -- Note: the pragma has been completely transformed into a sequence of
1811 -- corresponding declarations and statements. We leave it in the tree
1812 -- for documentation purposes. It will be ignored by the backend.
1814 end Expand_Pragma_Loop_Variant
;
1816 --------------------------------
1817 -- Expand_Pragma_Psect_Object --
1818 --------------------------------
1820 -- Convert to Common_Object, and expand the resulting pragma
1822 procedure Expand_Pragma_Psect_Object
(N
: Node_Id
)
1823 renames Expand_Pragma_Common_Object
;
1825 -------------------------------------
1826 -- Expand_Pragma_Relative_Deadline --
1827 -------------------------------------
1829 procedure Expand_Pragma_Relative_Deadline
(N
: Node_Id
) is
1830 P
: constant Node_Id
:= Parent
(N
);
1831 Loc
: constant Source_Ptr
:= Sloc
(N
);
1834 -- Expand the pragma only in the case of the main subprogram. For tasks
1835 -- the expansion is done in exp_ch9. Generate a call to Set_Deadline
1836 -- at Clock plus the relative deadline specified in the pragma. Time
1837 -- values are translated into Duration to allow for non-private
1838 -- addition operation.
1840 if Nkind
(P
) = N_Subprogram_Body
then
1843 Make_Procedure_Call_Statement
(Loc
,
1844 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Deadline
), Loc
),
1845 Parameter_Associations
=> New_List
(
1846 Unchecked_Convert_To
(RTE
(RO_RT_Time
),
1849 Make_Function_Call
(Loc
,
1850 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
1851 New_List
(Make_Function_Call
(Loc
,
1852 New_Occurrence_Of
(RTE
(RE_Clock
), Loc
)))),
1854 Unchecked_Convert_To
(Standard_Duration
, Arg1
(N
)))))));
1858 end Expand_Pragma_Relative_Deadline
;
1860 -------------------------------------------
1861 -- Expand_Pragma_Suppress_Initialization --
1862 -------------------------------------------
1864 procedure Expand_Pragma_Suppress_Initialization
(N
: Node_Id
) is
1865 Def_Id
: constant Entity_Id
:= Entity
(Arg1
(N
));
1868 -- Variable case (we have to undo any initialization already done)
1870 if Ekind
(Def_Id
) = E_Variable
then
1871 Undo_Initialization
(Def_Id
, N
);
1873 end Expand_Pragma_Suppress_Initialization
;
1875 -------------------------
1876 -- Undo_Initialization --
1877 -------------------------
1879 procedure Undo_Initialization
(Def_Id
: Entity_Id
; N
: Node_Id
) is
1880 Init_Call
: Node_Id
;
1883 -- When applied to a variable, the default initialization must not be
1884 -- done. As it is already done when the pragma is found, we just get rid
1885 -- of the call the initialization procedure which followed the object
1886 -- declaration. The call is inserted after the declaration, but validity
1887 -- checks may also have been inserted and thus the initialization call
1888 -- does not necessarily appear immediately after the object declaration.
1890 -- We can't use the freezing mechanism for this purpose, since we have
1891 -- to elaborate the initialization expression when it is first seen (so
1892 -- this elaboration cannot be deferred to the freeze point).
1894 -- Find and remove generated initialization call for object, if any
1896 Init_Call
:= Remove_Init_Call
(Def_Id
, Rep_Clause
=> N
);
1898 -- Any default initialization expression should be removed (e.g.
1899 -- null defaults for access objects, zero initialization of packed
1900 -- bit arrays). Imported objects aren't allowed to have explicit
1901 -- initialization, so the expression must have been generated by
1904 if No
(Init_Call
) and then Present
(Expression
(Parent
(Def_Id
))) then
1905 Set_Expression
(Parent
(Def_Id
), Empty
);
1908 -- The object may not have any initialization, but in the presence of
1909 -- Initialize_Scalars code is inserted after then declaration, which
1910 -- must now be removed as well. The code carries the same source
1911 -- location as the declaration itself.
1913 if Initialize_Scalars
and then Is_Array_Type
(Etype
(Def_Id
)) then
1918 Init
:= Next
(Parent
(Def_Id
));
1919 while not Comes_From_Source
(Init
)
1920 and then Sloc
(Init
) = Sloc
(Def_Id
)
1928 end Undo_Initialization
;