1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2014-2017, 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 Alloc
; use Alloc
;
27 with Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
33 with Namet
; use Namet
;
34 with Nlists
; use Nlists
;
35 with Nmake
; use Nmake
;
37 with Sem_Aux
; use Sem_Aux
;
38 with Sem_Disp
; use Sem_Disp
;
39 with Sem_Eval
; use Sem_Eval
;
40 with Sem_Prag
; use Sem_Prag
;
41 with Sem_Res
; use Sem_Res
;
42 with Sem_Util
; use Sem_Util
;
43 with Sinfo
; use Sinfo
;
44 with Snames
; use Snames
;
49 -- The following table contains the N_Compilation_Unit node for a unit that
50 -- is either subject to pragma Ghost with policy Ignore or contains ignored
51 -- Ghost code. The table is used in the removal of ignored Ghost code from
54 package Ignored_Ghost_Units
is new Table
.Table
(
55 Table_Component_Type
=> Node_Id
,
56 Table_Index_Type
=> Int
,
58 Table_Initial
=> Alloc
.Ignored_Ghost_Units_Initial
,
59 Table_Increment
=> Alloc
.Ignored_Ghost_Units_Increment
,
60 Table_Name
=> "Ignored_Ghost_Units");
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 function Ghost_Entity
(N
: Node_Id
) return Entity_Id
;
67 -- Find the entity of a reference to a Ghost entity. Return Empty if there
70 procedure Install_Ghost_Mode
(Mode
: Name_Id
);
71 -- Install a specific Ghost mode denoted by Mode by setting global variable
74 function Is_Subject_To_Ghost
(N
: Node_Id
) return Boolean;
75 -- Determine whether declaration or body N is subject to aspect or pragma
76 -- Ghost. This routine must be used in cases where pragma Ghost has not
77 -- been analyzed yet, but the context needs to establish the "ghostness"
80 procedure Mark_Ghost_Declaration_Or_Body
83 -- Mark the defining entity of declaration or body N as Ghost depending on
84 -- mode Mode. Mark all formals parameters when N denotes a subprogram or a
87 procedure Propagate_Ignored_Ghost_Code
(N
: Node_Id
);
88 -- Signal all enclosing scopes that they now contain at least one ignored
89 -- Ghost node denoted by N. Add the compilation unit containing N to table
90 -- Ignored_Ghost_Units for post processing.
92 ----------------------------
93 -- Add_Ignored_Ghost_Unit --
94 ----------------------------
96 procedure Add_Ignored_Ghost_Unit
(Unit
: Node_Id
) is
98 pragma Assert
(Nkind
(Unit
) = N_Compilation_Unit
);
100 -- Avoid duplicates in the table as pruning the same unit more than once
101 -- is wasteful. Since ignored Ghost code tends to be grouped up, check
102 -- the contents of the table in reverse.
104 for Index
in reverse Ignored_Ghost_Units
.First
..
105 Ignored_Ghost_Units
.Last
107 -- If the unit is already present in the table, do not add it again
109 if Unit
= Ignored_Ghost_Units
.Table
(Index
) then
114 -- If we get here, then this is the first time the unit is being added
116 Ignored_Ghost_Units
.Append
(Unit
);
117 end Add_Ignored_Ghost_Unit
;
119 ----------------------------
120 -- Check_Ghost_Completion --
121 ----------------------------
123 procedure Check_Ghost_Completion
124 (Prev_Id
: Entity_Id
;
125 Compl_Id
: Entity_Id
)
127 Policy
: constant Name_Id
:= Policy_In_Effect
(Name_Ghost
);
130 -- Nothing to do if one of the views is missing
132 if No
(Prev_Id
) or else No
(Compl_Id
) then
135 -- The Ghost policy in effect at the point of declaration and at the
136 -- point of completion must match (SPARK RM 6.9(14)).
138 elsif Is_Checked_Ghost_Entity
(Prev_Id
)
139 and then Policy
= Name_Ignore
141 Error_Msg_Sloc
:= Sloc
(Compl_Id
);
143 Error_Msg_N
("incompatible ghost policies in effect", Prev_Id
);
144 Error_Msg_N
("\& declared with ghost policy `Check`", Prev_Id
);
145 Error_Msg_N
("\& completed # with ghost policy `Ignore`", Prev_Id
);
147 elsif Is_Ignored_Ghost_Entity
(Prev_Id
)
148 and then Policy
= Name_Check
150 Error_Msg_Sloc
:= Sloc
(Compl_Id
);
152 Error_Msg_N
("incompatible ghost policies in effect", Prev_Id
);
153 Error_Msg_N
("\& declared with ghost policy `Ignore`", Prev_Id
);
154 Error_Msg_N
("\& completed # with ghost policy `Check`", Prev_Id
);
156 end Check_Ghost_Completion
;
158 -------------------------
159 -- Check_Ghost_Context --
160 -------------------------
162 procedure Check_Ghost_Context
(Ghost_Id
: Entity_Id
; Ghost_Ref
: Node_Id
) is
163 procedure Check_Ghost_Policy
(Id
: Entity_Id
; Ref
: Node_Id
);
164 -- Verify that the Ghost policy at the point of declaration of entity Id
165 -- matches the policy at the point of reference Ref. If this is not the
166 -- case emit an error at Ref.
168 function Is_OK_Ghost_Context
(Context
: Node_Id
) return Boolean;
169 -- Determine whether node Context denotes a Ghost-friendly context where
170 -- a Ghost entity can safely reside (SPARK RM 6.9(10)).
172 -------------------------
173 -- Is_OK_Ghost_Context --
174 -------------------------
176 function Is_OK_Ghost_Context
(Context
: Node_Id
) return Boolean is
177 function Is_OK_Declaration
(Decl
: Node_Id
) return Boolean;
178 -- Determine whether node Decl is a suitable context for a reference
179 -- to a Ghost entity. To qualify as such, Decl must either
181 -- * Define a Ghost entity
183 -- * Be subject to pragma Ghost
185 function Is_OK_Pragma
(Prag
: Node_Id
) return Boolean;
186 -- Determine whether node Prag is a suitable context for a reference
187 -- to a Ghost entity. To qualify as such, Prag must either
189 -- * Be an assertion expression pragma
191 -- * Denote pragma Global, Depends, Initializes, Refined_Global,
192 -- Refined_Depends or Refined_State.
194 -- * Specify an aspect of a Ghost entity
196 -- * Contain a reference to a Ghost entity
198 function Is_OK_Statement
(Stmt
: Node_Id
) return Boolean;
199 -- Determine whether node Stmt is a suitable context for a reference
200 -- to a Ghost entity. To qualify as such, Stmt must either
202 -- * Denote a procedure call to a Ghost procedure
204 -- * Denote an assignment statement whose target is Ghost
206 -----------------------
207 -- Is_OK_Declaration --
208 -----------------------
210 function Is_OK_Declaration
(Decl
: Node_Id
) return Boolean is
211 function In_Subprogram_Body_Profile
(N
: Node_Id
) return Boolean;
212 -- Determine whether node N appears in the profile of a subprogram
215 --------------------------------
216 -- In_Subprogram_Body_Profile --
217 --------------------------------
219 function In_Subprogram_Body_Profile
(N
: Node_Id
) return Boolean is
220 Spec
: constant Node_Id
:= Parent
(N
);
223 -- The node appears in a parameter specification in which case
224 -- it is either the parameter type or the default expression or
225 -- the node appears as the result definition of a function.
228 (Nkind
(N
) = N_Parameter_Specification
230 (Nkind
(Spec
) = N_Function_Specification
231 and then N
= Result_Definition
(Spec
)))
232 and then Nkind
(Parent
(Spec
)) = N_Subprogram_Body
;
233 end In_Subprogram_Body_Profile
;
240 -- Start of processing for Is_OK_Declaration
243 if Is_Ghost_Declaration
(Decl
) then
248 -- A reference to a Ghost entity may appear within the profile of
249 -- a subprogram body. This context is treated as suitable because
250 -- it duplicates the context of the corresponding spec. The real
251 -- check was already performed during the analysis of the spec.
253 elsif In_Subprogram_Body_Profile
(Decl
) then
256 -- A reference to a Ghost entity may appear within an expression
257 -- function which is still being analyzed. This context is treated
258 -- as suitable because it is not yet known whether the expression
259 -- function is an initial declaration or a completion. The real
260 -- check is performed when the expression function is expanded.
262 elsif Nkind
(Decl
) = N_Expression_Function
263 and then not Analyzed
(Decl
)
267 -- References to Ghost entities may be relocated in internally
270 elsif Nkind
(Decl
) = N_Subprogram_Body
271 and then not Comes_From_Source
(Decl
)
273 Subp_Id
:= Corresponding_Spec
(Decl
);
275 if Present
(Subp_Id
) then
277 -- The context is the internally built _Postconditions
278 -- procedure, which is OK because the real check was done
279 -- before expansion activities.
281 if Chars
(Subp_Id
) = Name_uPostconditions
then
286 Original_Node
(Unit_Declaration_Node
(Subp_Id
));
288 -- The original context is an expression function that
289 -- has been split into a spec and a body. The context is
290 -- OK as long as the initial declaration is Ghost.
292 if Nkind
(Subp_Decl
) = N_Expression_Function
then
293 return Is_Ghost_Declaration
(Subp_Decl
);
297 -- Otherwise this is either an internal body or an internal
298 -- completion. Both are OK because the real check was done
299 -- before expansion activities.
307 end Is_OK_Declaration
;
313 function Is_OK_Pragma
(Prag
: Node_Id
) return Boolean is
314 procedure Check_Policies
(Prag_Nam
: Name_Id
);
315 -- Verify that the Ghost policy in effect is the same as the
316 -- assertion policy for pragma name Prag_Nam. Emit an error if
317 -- this is not the case.
323 procedure Check_Policies
(Prag_Nam
: Name_Id
) is
324 AP
: constant Name_Id
:= Check_Kind
(Prag_Nam
);
325 GP
: constant Name_Id
:= Policy_In_Effect
(Name_Ghost
);
328 -- If the Ghost policy in effect at the point of a Ghost entity
329 -- reference is Ignore, then the assertion policy of the pragma
330 -- must be Ignore (SPARK RM 6.9(18)).
332 if GP
= Name_Ignore
and then AP
/= Name_Ignore
then
334 ("incompatible ghost policies in effect",
337 ("\ghost entity & has policy `Ignore`",
338 Ghost_Ref
, Ghost_Id
);
340 Error_Msg_Name_1
:= AP
;
342 ("\assertion expression has policy %", Ghost_Ref
);
351 -- Start of processing for Is_OK_Pragma
354 if Nkind
(Prag
) = N_Pragma
then
355 Prag_Id
:= Get_Pragma_Id
(Prag
);
356 Prag_Nam
:= Original_Aspect_Pragma_Name
(Prag
);
358 -- A pragma that applies to a Ghost construct or specifies an
359 -- aspect of a Ghost entity is a Ghost pragma (SPARK RM 6.9(3))
361 if Is_Ghost_Pragma
(Prag
) then
364 -- An assertion expression pragma is Ghost when it contains a
365 -- reference to a Ghost entity (SPARK RM 6.9(10)).
367 elsif Assertion_Expression_Pragma
(Prag_Id
) then
369 -- Ensure that the assertion policy and the Ghost policy are
370 -- compatible (SPARK RM 6.9(18)).
372 Check_Policies
(Prag_Nam
);
375 -- Several pragmas that may apply to a non-Ghost entity are
376 -- treated as Ghost when they contain a reference to a Ghost
377 -- entity (SPARK RM 6.9(11)).
379 elsif Nam_In
(Prag_Nam
, Name_Global
,
383 Name_Refined_Depends
,
393 ---------------------
394 -- Is_OK_Statement --
395 ---------------------
397 function Is_OK_Statement
(Stmt
: Node_Id
) return Boolean is
399 -- An assignment statement is Ghost when the target is a Ghost
402 if Nkind
(Stmt
) = N_Assignment_Statement
then
403 return Is_Ghost_Assignment
(Stmt
);
405 -- A procedure call is Ghost when it calls a Ghost procedure
407 elsif Nkind
(Stmt
) = N_Procedure_Call_Statement
then
408 return Is_Ghost_Procedure_Call
(Stmt
);
412 -- An if statement is a suitable context for a Ghost entity if it
413 -- is the byproduct of assertion expression expansion. Note that
414 -- the assertion expression may not be related to a Ghost entity,
415 -- but it may still contain references to Ghost entities.
417 elsif Nkind
(Stmt
) = N_If_Statement
418 and then Nkind
(Original_Node
(Stmt
)) = N_Pragma
419 and then Assertion_Expression_Pragma
420 (Get_Pragma_Id
(Original_Node
(Stmt
)))
432 -- Start of processing for Is_OK_Ghost_Context
435 -- The context is Ghost when it appears within a Ghost package or
438 if Ghost_Mode
> None
then
441 -- A Ghost type may be referenced in a use_type clause
442 -- (SPARK RM 6.9.10).
444 elsif Present
(Parent
(Context
))
445 and then Nkind
(Parent
(Context
)) = N_Use_Type_Clause
449 -- Routine Expand_Record_Extension creates a parent subtype without
450 -- inserting it into the tree. There is no good way of recognizing
451 -- this special case as there is no parent. Try to approximate the
454 elsif No
(Parent
(Context
)) and then Is_Tagged_Type
(Ghost_Id
) then
457 -- Otherwise climb the parent chain looking for a suitable Ghost
462 while Present
(Par
) loop
463 if Is_Ignored_Ghost_Node
(Par
) then
466 -- A reference to a Ghost entity can appear within an aspect
467 -- specification (SPARK RM 6.9(10)).
469 elsif Nkind
(Par
) = N_Aspect_Specification
then
472 elsif Is_OK_Declaration
(Par
) then
475 elsif Is_OK_Pragma
(Par
) then
478 elsif Is_OK_Statement
(Par
) then
481 -- Prevent the search from going too far
483 elsif Is_Body_Or_Package_Declaration
(Par
) then
490 -- The expansion of assertion expression pragmas and attribute Old
491 -- may cause a legal Ghost entity reference to become illegal due
492 -- to node relocation. Check the In_Assertion_Expr counter as last
493 -- resort to try and infer the original legal context.
495 if In_Assertion_Expr
> 0 then
498 -- Otherwise the context is not suitable for a reference to a
505 end Is_OK_Ghost_Context
;
507 ------------------------
508 -- Check_Ghost_Policy --
509 ------------------------
511 procedure Check_Ghost_Policy
(Id
: Entity_Id
; Ref
: Node_Id
) is
512 Policy
: constant Name_Id
:= Policy_In_Effect
(Name_Ghost
);
515 -- The Ghost policy in effect a the point of declaration and at the
516 -- point of use must match (SPARK RM 6.9(13)).
518 if Is_Checked_Ghost_Entity
(Id
)
519 and then Policy
= Name_Ignore
520 and then May_Be_Lvalue
(Ref
)
522 Error_Msg_Sloc
:= Sloc
(Ref
);
524 Error_Msg_N
("incompatible ghost policies in effect", Ref
);
525 Error_Msg_NE
("\& declared with ghost policy `Check`", Ref
, Id
);
526 Error_Msg_NE
("\& used # with ghost policy `Ignore`", Ref
, Id
);
528 elsif Is_Ignored_Ghost_Entity
(Id
) and then Policy
= Name_Check
then
529 Error_Msg_Sloc
:= Sloc
(Ref
);
531 Error_Msg_N
("incompatible ghost policies in effect", Ref
);
532 Error_Msg_NE
("\& declared with ghost policy `Ignore`", Ref
, Id
);
533 Error_Msg_NE
("\& used # with ghost policy `Check`", Ref
, Id
);
535 end Check_Ghost_Policy
;
537 -- Start of processing for Check_Ghost_Context
540 -- Once it has been established that the reference to the Ghost entity
541 -- is within a suitable context, ensure that the policy at the point of
542 -- declaration and at the point of use match.
544 if Is_OK_Ghost_Context
(Ghost_Ref
) then
545 Check_Ghost_Policy
(Ghost_Id
, Ghost_Ref
);
547 -- Otherwise the Ghost entity appears in a non-Ghost context and affects
548 -- its behavior or value (SPARK RM 6.9(10,11)).
551 Error_Msg_N
("ghost entity cannot appear in this context", Ghost_Ref
);
553 end Check_Ghost_Context
;
555 ----------------------------
556 -- Check_Ghost_Overriding --
557 ----------------------------
559 procedure Check_Ghost_Overriding
561 Overridden_Subp
: Entity_Id
)
563 Deriv_Typ
: Entity_Id
;
564 Over_Subp
: Entity_Id
;
567 if Present
(Subp
) and then Present
(Overridden_Subp
) then
568 Over_Subp
:= Ultimate_Alias
(Overridden_Subp
);
569 Deriv_Typ
:= Find_Dispatching_Type
(Subp
);
571 -- A Ghost primitive of a non-Ghost type extension cannot override an
572 -- inherited non-Ghost primitive (SPARK RM 6.9(8)).
574 if Is_Ghost_Entity
(Subp
)
575 and then Present
(Deriv_Typ
)
576 and then not Is_Ghost_Entity
(Deriv_Typ
)
577 and then not Is_Ghost_Entity
(Over_Subp
)
578 and then not Is_Abstract_Subprogram
(Over_Subp
)
580 Error_Msg_N
("incompatible overriding in effect", Subp
);
582 Error_Msg_Sloc
:= Sloc
(Over_Subp
);
583 Error_Msg_N
("\& declared # as non-ghost subprogram", Subp
);
585 Error_Msg_Sloc
:= Sloc
(Subp
);
586 Error_Msg_N
("\overridden # with ghost subprogram", Subp
);
589 -- A non-Ghost primitive of a type extension cannot override an
590 -- inherited Ghost primitive (SPARK RM 6.9(8)).
592 if Is_Ghost_Entity
(Over_Subp
)
593 and then not Is_Ghost_Entity
(Subp
)
594 and then not Is_Abstract_Subprogram
(Subp
)
596 Error_Msg_N
("incompatible overriding in effect", Subp
);
598 Error_Msg_Sloc
:= Sloc
(Over_Subp
);
599 Error_Msg_N
("\& declared # as ghost subprogram", Subp
);
601 Error_Msg_Sloc
:= Sloc
(Subp
);
602 Error_Msg_N
("\overridden # with non-ghost subprogram", Subp
);
605 if Present
(Deriv_Typ
)
606 and then not Is_Ignored_Ghost_Entity
(Deriv_Typ
)
608 -- When a tagged type is either non-Ghost or checked Ghost and
609 -- one of its primitives overrides an inherited operation, the
610 -- overridden operation of the ancestor type must be ignored Ghost
611 -- if the primitive is ignored Ghost (SPARK RM 6.9(17)).
613 if Is_Ignored_Ghost_Entity
(Subp
) then
615 -- Both the parent subprogram and overriding subprogram are
618 if Is_Ignored_Ghost_Entity
(Over_Subp
) then
621 -- The parent subprogram carries policy Check
623 elsif Is_Checked_Ghost_Entity
(Over_Subp
) then
625 ("incompatible ghost policies in effect", Subp
);
627 Error_Msg_Sloc
:= Sloc
(Over_Subp
);
629 ("\& declared # with ghost policy `Check`", Subp
);
631 Error_Msg_Sloc
:= Sloc
(Subp
);
633 ("\overridden # with ghost policy `Ignore`", Subp
);
635 -- The parent subprogram is non-Ghost
639 ("incompatible ghost policies in effect", Subp
);
641 Error_Msg_Sloc
:= Sloc
(Over_Subp
);
642 Error_Msg_N
("\& declared # as non-ghost subprogram", Subp
);
644 Error_Msg_Sloc
:= Sloc
(Subp
);
646 ("\overridden # with ghost policy `Ignore`", Subp
);
649 -- When a tagged type is either non-Ghost or checked Ghost and
650 -- one of its primitives overrides an inherited operation, the
651 -- the primitive of the tagged type must be ignored Ghost if the
652 -- overridden operation is ignored Ghost (SPARK RM 6.9(17)).
654 elsif Is_Ignored_Ghost_Entity
(Over_Subp
) then
656 -- Both the parent subprogram and the overriding subprogram are
659 if Is_Ignored_Ghost_Entity
(Subp
) then
662 -- The overriding subprogram carries policy Check
664 elsif Is_Checked_Ghost_Entity
(Subp
) then
666 ("incompatible ghost policies in effect", Subp
);
668 Error_Msg_Sloc
:= Sloc
(Over_Subp
);
670 ("\& declared # with ghost policy `Ignore`", Subp
);
672 Error_Msg_Sloc
:= Sloc
(Subp
);
674 ("\overridden # with Ghost policy `Check`", Subp
);
676 -- The overriding subprogram is non-Ghost
680 ("incompatible ghost policies in effect", Subp
);
682 Error_Msg_Sloc
:= Sloc
(Over_Subp
);
684 ("\& declared # with ghost policy `Ignore`", Subp
);
686 Error_Msg_Sloc
:= Sloc
(Subp
);
688 ("\overridden # with non-ghost subprogram", Subp
);
693 end Check_Ghost_Overriding
;
695 ---------------------------
696 -- Check_Ghost_Primitive --
697 ---------------------------
699 procedure Check_Ghost_Primitive
(Prim
: Entity_Id
; Typ
: Entity_Id
) is
701 -- The Ghost policy in effect at the point of declaration of a primitive
702 -- operation and a tagged type must match (SPARK RM 6.9(16)).
704 if Is_Tagged_Type
(Typ
) then
705 if Is_Checked_Ghost_Entity
(Prim
)
706 and then Is_Ignored_Ghost_Entity
(Typ
)
708 Error_Msg_N
("incompatible ghost policies in effect", Prim
);
710 Error_Msg_Sloc
:= Sloc
(Typ
);
712 ("\tagged type & declared # with ghost policy `Ignore`",
715 Error_Msg_Sloc
:= Sloc
(Prim
);
717 ("\primitive subprogram & declared # with ghost policy `Check`",
720 elsif Is_Ignored_Ghost_Entity
(Prim
)
721 and then Is_Checked_Ghost_Entity
(Typ
)
723 Error_Msg_N
("incompatible ghost policies in effect", Prim
);
725 Error_Msg_Sloc
:= Sloc
(Typ
);
727 ("\tagged type & declared # with ghost policy `Check`",
730 Error_Msg_Sloc
:= Sloc
(Prim
);
732 ("\primitive subprogram & declared # with ghost policy `Ignore`",
736 end Check_Ghost_Primitive
;
738 ----------------------------
739 -- Check_Ghost_Refinement --
740 ----------------------------
742 procedure Check_Ghost_Refinement
744 State_Id
: Entity_Id
;
746 Constit_Id
: Entity_Id
)
749 if Is_Ghost_Entity
(State_Id
) then
750 if Is_Ghost_Entity
(Constit_Id
) then
752 -- The Ghost policy in effect at the point of abstract state
753 -- declaration and constituent must match (SPARK RM 6.9(15)).
755 if Is_Checked_Ghost_Entity
(State_Id
)
756 and then Is_Ignored_Ghost_Entity
(Constit_Id
)
758 Error_Msg_Sloc
:= Sloc
(Constit
);
759 SPARK_Msg_N
("incompatible ghost policies in effect", State
);
762 ("\abstract state & declared with ghost policy `Check`",
765 ("\constituent & declared # with ghost policy `Ignore`",
768 elsif Is_Ignored_Ghost_Entity
(State_Id
)
769 and then Is_Checked_Ghost_Entity
(Constit_Id
)
771 Error_Msg_Sloc
:= Sloc
(Constit
);
772 SPARK_Msg_N
("incompatible ghost policies in effect", State
);
775 ("\abstract state & declared with ghost policy `Ignore`",
778 ("\constituent & declared # with ghost policy `Check`",
782 -- A constituent of a Ghost abstract state must be a Ghost entity
783 -- (SPARK RM 7.2.2(12)).
787 ("constituent of ghost state & must be ghost",
791 end Check_Ghost_Refinement
;
797 function Ghost_Entity
(N
: Node_Id
) return Entity_Id
is
801 -- When the reference denotes a subcomponent, recover the related
802 -- object (SPARK RM 6.9(1)).
805 while Nkind_In
(Ref
, N_Explicit_Dereference
,
807 N_Selected_Component
,
813 if Is_Entity_Name
(Ref
) then
820 --------------------------------
821 -- Implements_Ghost_Interface --
822 --------------------------------
824 function Implements_Ghost_Interface
(Typ
: Entity_Id
) return Boolean is
825 Iface_Elmt
: Elmt_Id
;
828 -- Traverse the list of interfaces looking for a Ghost interface
830 if Is_Tagged_Type
(Typ
) and then Present
(Interfaces
(Typ
)) then
831 Iface_Elmt
:= First_Elmt
(Interfaces
(Typ
));
832 while Present
(Iface_Elmt
) loop
833 if Is_Ghost_Entity
(Node
(Iface_Elmt
)) then
837 Next_Elmt
(Iface_Elmt
);
842 end Implements_Ghost_Interface
;
848 procedure Initialize
is
850 Ignored_Ghost_Units
.Init
;
853 ------------------------
854 -- Install_Ghost_Mode --
855 ------------------------
857 procedure Install_Ghost_Mode
(Mode
: Ghost_Mode_Type
) is
860 end Install_Ghost_Mode
;
862 procedure Install_Ghost_Mode
(Mode
: Name_Id
) is
864 if Mode
= Name_Check
then
867 elsif Mode
= Name_Ignore
then
868 Ghost_Mode
:= Ignore
;
870 elsif Mode
= Name_None
then
873 end Install_Ghost_Mode
;
875 -------------------------
876 -- Is_Ghost_Assignment --
877 -------------------------
879 function Is_Ghost_Assignment
(N
: Node_Id
) return Boolean is
883 -- An assignment statement is Ghost when its target denotes a Ghost
886 if Nkind
(N
) = N_Assignment_Statement
then
887 Id
:= Ghost_Entity
(Name
(N
));
889 return Present
(Id
) and then Is_Ghost_Entity
(Id
);
893 end Is_Ghost_Assignment
;
895 --------------------------
896 -- Is_Ghost_Declaration --
897 --------------------------
899 function Is_Ghost_Declaration
(N
: Node_Id
) return Boolean is
903 -- A declaration is Ghost when it elaborates a Ghost entity or is
904 -- subject to pragma Ghost.
906 if Is_Declaration
(N
) then
907 Id
:= Defining_Entity
(N
);
909 return Is_Ghost_Entity
(Id
) or else Is_Subject_To_Ghost
(N
);
913 end Is_Ghost_Declaration
;
915 ---------------------
916 -- Is_Ghost_Pragma --
917 ---------------------
919 function Is_Ghost_Pragma
(N
: Node_Id
) return Boolean is
921 return Is_Checked_Ghost_Pragma
(N
) or else Is_Ignored_Ghost_Pragma
(N
);
924 -----------------------------
925 -- Is_Ghost_Procedure_Call --
926 -----------------------------
928 function Is_Ghost_Procedure_Call
(N
: Node_Id
) return Boolean is
932 -- A procedure call is Ghost when it invokes a Ghost procedure
934 if Nkind
(N
) = N_Procedure_Call_Statement
then
935 Id
:= Ghost_Entity
(Name
(N
));
937 return Present
(Id
) and then Is_Ghost_Entity
(Id
);
941 end Is_Ghost_Procedure_Call
;
943 ---------------------------
944 -- Is_Ignored_Ghost_Unit --
945 ---------------------------
947 function Is_Ignored_Ghost_Unit
(N
: Node_Id
) return Boolean is
949 -- Inspect the original node of the unit in case removal of ignored
950 -- Ghost code has already taken place.
953 Nkind
(N
) = N_Compilation_Unit
954 and then Is_Ignored_Ghost_Entity
955 (Defining_Entity
(Original_Node
(Unit
(N
))));
956 end Is_Ignored_Ghost_Unit
;
958 -------------------------
959 -- Is_Subject_To_Ghost --
960 -------------------------
962 function Is_Subject_To_Ghost
(N
: Node_Id
) return Boolean is
963 function Enables_Ghostness
(Arg
: Node_Id
) return Boolean;
964 -- Determine whether aspect or pragma argument Arg enables "ghostness"
966 -----------------------
967 -- Enables_Ghostness --
968 -----------------------
970 function Enables_Ghostness
(Arg
: Node_Id
) return Boolean is
976 if Nkind
(Expr
) = N_Pragma_Argument_Association
then
977 Expr
:= Get_Pragma_Arg
(Expr
);
980 -- Determine whether the expression of the aspect or pragma is static
983 if Present
(Expr
) then
984 Preanalyze_And_Resolve
(Expr
);
987 Is_OK_Static_Expression
(Expr
)
988 and then Is_True
(Expr_Value
(Expr
));
990 -- Otherwise Ghost defaults to True
995 end Enables_Ghostness
;
999 Id
: constant Entity_Id
:= Defining_Entity
(N
);
1002 Prev_Id
: Entity_Id
;
1004 -- Start of processing for Is_Subject_To_Ghost
1007 -- The related entity of the declaration has not been analyzed yet, do
1008 -- not inspect its attributes.
1010 if Ekind
(Id
) = E_Void
then
1013 elsif Is_Ghost_Entity
(Id
) then
1016 -- The completion of a type or a constant is not fully analyzed when the
1017 -- reference to the Ghost entity is resolved. Because the completion is
1018 -- not marked as Ghost yet, inspect the partial view.
1020 elsif Is_Record_Type
(Id
)
1021 or else Ekind
(Id
) = E_Constant
1022 or else (Nkind
(N
) = N_Object_Declaration
1023 and then Constant_Present
(N
))
1025 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
1027 if Present
(Prev_Id
) and then Is_Ghost_Entity
(Prev_Id
) then
1032 -- Examine the aspect specifications (if any) looking for aspect Ghost
1034 if Permits_Aspect_Specifications
(N
) then
1035 Asp
:= First
(Aspect_Specifications
(N
));
1036 while Present
(Asp
) loop
1037 if Chars
(Identifier
(Asp
)) = Name_Ghost
then
1038 return Enables_Ghostness
(Expression
(Asp
));
1047 -- When the context is a [generic] package declaration, pragma Ghost
1048 -- resides in the visible declarations.
1050 if Nkind_In
(N
, N_Generic_Package_Declaration
,
1051 N_Package_Declaration
)
1053 Decl
:= First
(Visible_Declarations
(Specification
(N
)));
1055 -- When the context is a package or a subprogram body, pragma Ghost
1056 -- resides in the declarative part.
1058 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
1059 Decl
:= First
(Declarations
(N
));
1061 -- Otherwise pragma Ghost appears in the declarations following N
1063 elsif Is_List_Member
(N
) then
1067 while Present
(Decl
) loop
1068 if Nkind
(Decl
) = N_Pragma
1069 and then Pragma_Name
(Decl
) = Name_Ghost
1072 Enables_Ghostness
(First
(Pragma_Argument_Associations
(Decl
)));
1074 -- A source construct ends the region where pragma Ghost may appear,
1075 -- stop the traversal. Check the original node as source constructs
1076 -- may be rewritten into something else by expansion.
1078 elsif Comes_From_Source
(Original_Node
(Decl
)) then
1086 end Is_Subject_To_Ghost
;
1094 Ignored_Ghost_Units
.Release
;
1095 Ignored_Ghost_Units
.Locked
:= True;
1098 -----------------------------------
1099 -- Mark_And_Set_Ghost_Assignment --
1100 -----------------------------------
1102 procedure Mark_And_Set_Ghost_Assignment
(N
: Node_Id
) is
1106 -- An assignment statement becomes Ghost when its target denotes a Ghost
1107 -- object. Install the Ghost mode of the target.
1109 Id
:= Ghost_Entity
(Name
(N
));
1111 if Present
(Id
) then
1112 if Is_Checked_Ghost_Entity
(Id
) then
1113 Install_Ghost_Mode
(Check
);
1115 elsif Is_Ignored_Ghost_Entity
(Id
) then
1116 Install_Ghost_Mode
(Ignore
);
1118 Set_Is_Ignored_Ghost_Node
(N
);
1119 Propagate_Ignored_Ghost_Code
(N
);
1122 end Mark_And_Set_Ghost_Assignment
;
1124 -----------------------------
1125 -- Mark_And_Set_Ghost_Body --
1126 -----------------------------
1128 procedure Mark_And_Set_Ghost_Body
1130 Spec_Id
: Entity_Id
)
1132 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
1133 Policy
: Name_Id
:= No_Name
;
1136 -- A body becomes Ghost when it is subject to aspect or pragma Ghost
1138 if Is_Subject_To_Ghost
(N
) then
1139 Policy
:= Policy_In_Effect
(Name_Ghost
);
1141 -- A body declared within a Ghost region is automatically Ghost
1142 -- (SPARK RM 6.9(2)).
1144 elsif Ghost_Mode
= Check
then
1145 Policy
:= Name_Check
;
1147 elsif Ghost_Mode
= Ignore
then
1148 Policy
:= Name_Ignore
;
1150 -- Inherit the "ghostness" of the previous declaration when the body
1151 -- acts as a completion.
1153 elsif Present
(Spec_Id
) then
1154 if Is_Checked_Ghost_Entity
(Spec_Id
) then
1155 Policy
:= Name_Check
;
1157 elsif Is_Ignored_Ghost_Entity
(Spec_Id
) then
1158 Policy
:= Name_Ignore
;
1162 -- The Ghost policy in effect at the point of declaration and at the
1163 -- point of completion must match (SPARK RM 6.9(14)).
1165 Check_Ghost_Completion
1166 (Prev_Id
=> Spec_Id
,
1167 Compl_Id
=> Body_Id
);
1169 -- Mark the body as its formals as Ghost
1171 Mark_Ghost_Declaration_Or_Body
(N
, Policy
);
1173 -- Install the appropriate Ghost mode
1175 Install_Ghost_Mode
(Policy
);
1176 end Mark_And_Set_Ghost_Body
;
1178 -----------------------------------
1179 -- Mark_And_Set_Ghost_Completion --
1180 -----------------------------------
1182 procedure Mark_And_Set_Ghost_Completion
1184 Prev_Id
: Entity_Id
)
1186 Compl_Id
: constant Entity_Id
:= Defining_Entity
(N
);
1187 Policy
: Name_Id
:= No_Name
;
1190 -- A completion elaborated in a Ghost region is automatically Ghost
1191 -- (SPARK RM 6.9(2)).
1193 if Ghost_Mode
= Check
then
1194 Policy
:= Name_Check
;
1196 elsif Ghost_Mode
= Ignore
then
1197 Policy
:= Name_Ignore
;
1199 -- The completion becomes Ghost when its initial declaration is also
1202 elsif Is_Checked_Ghost_Entity
(Prev_Id
) then
1203 Policy
:= Name_Check
;
1205 elsif Is_Ignored_Ghost_Entity
(Prev_Id
) then
1206 Policy
:= Name_Ignore
;
1209 -- The Ghost policy in effect at the point of declaration and at the
1210 -- point of completion must match (SPARK RM 6.9(14)).
1212 Check_Ghost_Completion
1213 (Prev_Id
=> Prev_Id
,
1214 Compl_Id
=> Compl_Id
);
1216 -- Mark the completion as Ghost
1218 Mark_Ghost_Declaration_Or_Body
(N
, Policy
);
1220 -- Install the appropriate Ghost mode
1222 Install_Ghost_Mode
(Policy
);
1223 end Mark_And_Set_Ghost_Completion
;
1225 ------------------------------------
1226 -- Mark_And_Set_Ghost_Declaration --
1227 ------------------------------------
1229 procedure Mark_And_Set_Ghost_Declaration
(N
: Node_Id
) is
1231 Policy
: Name_Id
:= No_Name
;
1234 -- A declaration becomes Ghost when it is subject to aspect or pragma
1237 if Is_Subject_To_Ghost
(N
) then
1238 Policy
:= Policy_In_Effect
(Name_Ghost
);
1240 -- A declaration elaborated in a Ghost region is automatically Ghost
1241 -- (SPARK RM 6.9(2)).
1243 elsif Ghost_Mode
= Check
then
1244 Policy
:= Name_Check
;
1246 elsif Ghost_Mode
= Ignore
then
1247 Policy
:= Name_Ignore
;
1249 -- A child package or subprogram declaration becomes Ghost when its
1250 -- parent is Ghost (SPARK RM 6.9(2)).
1252 elsif Nkind_In
(N
, N_Generic_Function_Renaming_Declaration
,
1253 N_Generic_Package_Declaration
,
1254 N_Generic_Package_Renaming_Declaration
,
1255 N_Generic_Procedure_Renaming_Declaration
,
1256 N_Generic_Subprogram_Declaration
,
1257 N_Package_Declaration
,
1258 N_Package_Renaming_Declaration
,
1259 N_Subprogram_Declaration
,
1260 N_Subprogram_Renaming_Declaration
)
1261 and then Present
(Parent_Spec
(N
))
1263 Par_Id
:= Defining_Entity
(Unit
(Parent_Spec
(N
)));
1265 if Is_Checked_Ghost_Entity
(Par_Id
) then
1266 Policy
:= Name_Check
;
1268 elsif Is_Ignored_Ghost_Entity
(Par_Id
) then
1269 Policy
:= Name_Ignore
;
1273 -- Mark the declaration and its formals as Ghost
1275 Mark_Ghost_Declaration_Or_Body
(N
, Policy
);
1277 -- Install the appropriate Ghost mode
1279 Install_Ghost_Mode
(Policy
);
1280 end Mark_And_Set_Ghost_Declaration
;
1282 --------------------------------------
1283 -- Mark_And_Set_Ghost_Instantiation --
1284 --------------------------------------
1286 procedure Mark_And_Set_Ghost_Instantiation
1290 Policy
: Name_Id
:= No_Name
;
1293 -- An instantiation becomes Ghost when it is subject to pragma Ghost
1295 if Is_Subject_To_Ghost
(N
) then
1296 Policy
:= Policy_In_Effect
(Name_Ghost
);
1298 -- An instantiation declaration within a Ghost region is automatically
1299 -- Ghost (SPARK RM 6.9(2)).
1301 elsif Ghost_Mode
= Check
then
1302 Policy
:= Name_Check
;
1304 elsif Ghost_Mode
= Ignore
then
1305 Policy
:= Name_Ignore
;
1307 -- Inherit the "ghostness" of the generic unit
1309 elsif Is_Checked_Ghost_Entity
(Gen_Id
) then
1310 Policy
:= Name_Check
;
1312 elsif Is_Ignored_Ghost_Entity
(Gen_Id
) then
1313 Policy
:= Name_Ignore
;
1316 -- Mark the instantiation as Ghost
1318 Mark_Ghost_Declaration_Or_Body
(N
, Policy
);
1320 -- Install the appropriate Ghost mode
1322 Install_Ghost_Mode
(Policy
);
1323 end Mark_And_Set_Ghost_Instantiation
;
1325 ---------------------------------------
1326 -- Mark_And_Set_Ghost_Procedure_Call --
1327 ---------------------------------------
1329 procedure Mark_And_Set_Ghost_Procedure_Call
(N
: Node_Id
) is
1333 -- A procedure call becomes Ghost when the procedure being invoked is
1334 -- Ghost. Install the Ghost mode of the procedure.
1336 Id
:= Ghost_Entity
(Name
(N
));
1338 if Present
(Id
) then
1339 if Is_Checked_Ghost_Entity
(Id
) then
1340 Install_Ghost_Mode
(Check
);
1342 elsif Is_Ignored_Ghost_Entity
(Id
) then
1343 Install_Ghost_Mode
(Ignore
);
1345 Set_Is_Ignored_Ghost_Node
(N
);
1346 Propagate_Ignored_Ghost_Code
(N
);
1349 end Mark_And_Set_Ghost_Procedure_Call
;
1351 ------------------------------------
1352 -- Mark_Ghost_Declaration_Or_Body --
1353 ------------------------------------
1355 procedure Mark_Ghost_Declaration_Or_Body
1359 Id
: constant Entity_Id
:= Defining_Entity
(N
);
1361 Mark_Formals
: Boolean := False;
1363 Param_Id
: Entity_Id
;
1366 -- Mark the related node and its entity
1368 if Mode
= Name_Check
then
1369 Mark_Formals
:= True;
1370 Set_Is_Checked_Ghost_Entity
(Id
);
1372 elsif Mode
= Name_Ignore
then
1373 Mark_Formals
:= True;
1374 Set_Is_Ignored_Ghost_Entity
(Id
);
1375 Set_Is_Ignored_Ghost_Node
(N
);
1376 Propagate_Ignored_Ghost_Code
(N
);
1379 -- Mark all formal parameters when the related node denotes a subprogram
1380 -- or a body. The traversal is performed via the specification because
1381 -- the related subprogram or body may be unanalyzed.
1383 -- ??? could extra formal parameters cause a Ghost leak?
1386 and then Nkind_In
(N
, N_Abstract_Subprogram_Declaration
,
1387 N_Formal_Abstract_Subprogram_Declaration
,
1388 N_Formal_Concrete_Subprogram_Declaration
,
1389 N_Generic_Subprogram_Declaration
,
1391 N_Subprogram_Body_Stub
,
1392 N_Subprogram_Declaration
,
1393 N_Subprogram_Renaming_Declaration
)
1395 Param
:= First
(Parameter_Specifications
(Specification
(N
)));
1396 while Present
(Param
) loop
1397 Param_Id
:= Defining_Entity
(Param
);
1399 if Mode
= Name_Check
then
1400 Set_Is_Checked_Ghost_Entity
(Param_Id
);
1402 elsif Mode
= Name_Ignore
then
1403 Set_Is_Ignored_Ghost_Entity
(Param_Id
);
1409 end Mark_Ghost_Declaration_Or_Body
;
1411 -----------------------
1412 -- Mark_Ghost_Clause --
1413 -----------------------
1415 procedure Mark_Ghost_Clause
(N
: Node_Id
) is
1416 Nam
: Node_Id
:= Empty
;
1419 if Nkind
(N
) = N_Use_Package_Clause
then
1420 Nam
:= First
(Names
(N
));
1422 elsif Nkind
(N
) = N_Use_Type_Clause
then
1423 Nam
:= First
(Subtype_Marks
(N
));
1425 elsif Nkind
(N
) = N_With_Clause
then
1430 and then Is_Entity_Name
(Nam
)
1431 and then Present
(Entity
(Nam
))
1432 and then Is_Ignored_Ghost_Entity
(Entity
(Nam
))
1434 Set_Is_Ignored_Ghost_Node
(N
);
1435 Propagate_Ignored_Ghost_Code
(N
);
1437 end Mark_Ghost_Clause
;
1439 -----------------------
1440 -- Mark_Ghost_Pragma --
1441 -----------------------
1443 procedure Mark_Ghost_Pragma
1448 -- A pragma becomes Ghost when it encloses a Ghost entity or relates to
1451 if Is_Checked_Ghost_Entity
(Id
) then
1452 Set_Is_Checked_Ghost_Pragma
(N
);
1454 elsif Is_Ignored_Ghost_Entity
(Id
) then
1455 Set_Is_Ignored_Ghost_Pragma
(N
);
1456 Set_Is_Ignored_Ghost_Node
(N
);
1457 Propagate_Ignored_Ghost_Code
(N
);
1459 end Mark_Ghost_Pragma
;
1461 -------------------------
1462 -- Mark_Ghost_Renaming --
1463 -------------------------
1465 procedure Mark_Ghost_Renaming
1469 Policy
: Name_Id
:= No_Name
;
1472 -- A renaming becomes Ghost when it renames a Ghost entity
1474 if Is_Checked_Ghost_Entity
(Id
) then
1475 Policy
:= Name_Check
;
1477 elsif Is_Ignored_Ghost_Entity
(Id
) then
1478 Policy
:= Name_Ignore
;
1481 Mark_Ghost_Declaration_Or_Body
(N
, Policy
);
1482 end Mark_Ghost_Renaming
;
1484 ----------------------------------
1485 -- Propagate_Ignored_Ghost_Code --
1486 ----------------------------------
1488 procedure Propagate_Ignored_Ghost_Code
(N
: Node_Id
) is
1493 -- Traverse the parent chain looking for blocks, packages, and
1494 -- subprograms or their respective bodies.
1497 while Present
(Nod
) loop
1500 if Nkind
(Nod
) = N_Block_Statement
1501 and then Present
(Identifier
(Nod
))
1503 Scop
:= Entity
(Identifier
(Nod
));
1505 elsif Nkind_In
(Nod
, N_Package_Body
,
1506 N_Package_Declaration
,
1508 N_Subprogram_Declaration
)
1510 Scop
:= Defining_Entity
(Nod
);
1513 -- The current node denotes a scoping construct
1515 if Present
(Scop
) then
1517 -- Stop the traversal when the scope already contains ignored
1518 -- Ghost code as all enclosing scopes have already been marked.
1520 if Contains_Ignored_Ghost_Code
(Scop
) then
1523 -- Otherwise mark this scope and keep climbing
1526 Set_Contains_Ignored_Ghost_Code
(Scop
);
1530 Nod
:= Parent
(Nod
);
1533 -- The unit containing the ignored Ghost code must be post processed
1534 -- before invoking the back end.
1536 Add_Ignored_Ghost_Unit
(Cunit
(Get_Code_Unit
(N
)));
1537 end Propagate_Ignored_Ghost_Code
;
1539 -------------------------------
1540 -- Remove_Ignored_Ghost_Code --
1541 -------------------------------
1543 procedure Remove_Ignored_Ghost_Code
is
1544 procedure Prune_Tree
(Root
: Node_Id
);
1545 -- Remove all code marked as ignored Ghost from the tree of denoted by
1552 procedure Prune_Tree
(Root
: Node_Id
) is
1553 procedure Prune
(N
: Node_Id
);
1554 -- Remove a given node from the tree by rewriting it into null
1556 function Prune_Node
(N
: Node_Id
) return Traverse_Result
;
1557 -- Determine whether node N denotes an ignored Ghost construct. If
1558 -- this is the case, rewrite N as a null statement. See the body for
1565 procedure Prune
(N
: Node_Id
) is
1567 -- Destroy any aspects that may be associated with the node
1569 if Permits_Aspect_Specifications
(N
) and then Has_Aspects
(N
) then
1573 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
1580 function Prune_Node
(N
: Node_Id
) return Traverse_Result
is
1584 -- Do not prune compilation unit nodes because many mechanisms
1585 -- depend on their presence. Note that context items are still
1588 if Nkind
(N
) = N_Compilation_Unit
then
1591 -- The node is either declared as ignored Ghost or is a byproduct
1592 -- of expansion. Destroy it and stop the traversal on this branch.
1594 elsif Is_Ignored_Ghost_Node
(N
) then
1598 -- Scoping constructs such as blocks, packages, subprograms and
1599 -- bodies offer some flexibility with respect to pruning.
1601 elsif Nkind_In
(N
, N_Block_Statement
,
1603 N_Package_Declaration
,
1605 N_Subprogram_Declaration
)
1607 if Nkind
(N
) = N_Block_Statement
then
1608 Id
:= Entity
(Identifier
(N
));
1610 Id
:= Defining_Entity
(N
);
1613 -- The scoping construct contains both living and ignored Ghost
1614 -- code, let the traversal prune all relevant nodes.
1616 if Contains_Ignored_Ghost_Code
(Id
) then
1619 -- Otherwise the construct contains only living code and should
1626 -- Otherwise keep searching for ignored Ghost nodes
1633 procedure Prune_Nodes
is new Traverse_Proc
(Prune_Node
);
1635 -- Start of processing for Prune_Tree
1641 -- Start of processing for Remove_Ignored_Ghost_Code
1644 for Index
in Ignored_Ghost_Units
.First
.. Ignored_Ghost_Units
.Last
loop
1645 Prune_Tree
(Ignored_Ghost_Units
.Table
(Index
));
1647 end Remove_Ignored_Ghost_Code
;
1649 ------------------------
1650 -- Restore_Ghost_Mode --
1651 ------------------------
1653 procedure Restore_Ghost_Mode
(Mode
: Ghost_Mode_Type
) is
1656 end Restore_Ghost_Mode
;
1658 --------------------
1659 -- Set_Ghost_Mode --
1660 --------------------
1662 procedure Set_Ghost_Mode
(N
: Node_Or_Entity_Id
) is
1663 procedure Set_Ghost_Mode_From_Entity
(Id
: Entity_Id
);
1664 -- Install the Ghost mode of entity Id
1666 --------------------------------
1667 -- Set_Ghost_Mode_From_Entity --
1668 --------------------------------
1670 procedure Set_Ghost_Mode_From_Entity
(Id
: Entity_Id
) is
1672 if Is_Checked_Ghost_Entity
(Id
) then
1673 Install_Ghost_Mode
(Check
);
1674 elsif Is_Ignored_Ghost_Entity
(Id
) then
1675 Install_Ghost_Mode
(Ignore
);
1677 Install_Ghost_Mode
(None
);
1679 end Set_Ghost_Mode_From_Entity
;
1685 -- Start of processing for Set_Ghost_Mode
1688 -- The Ghost mode of an assignment statement depends on the Ghost mode
1691 if Nkind
(N
) = N_Assignment_Statement
then
1692 Id
:= Ghost_Entity
(Name
(N
));
1694 if Present
(Id
) then
1695 Set_Ghost_Mode_From_Entity
(Id
);
1698 -- The Ghost mode of a body or a declaration depends on the Ghost mode
1699 -- of its defining entity.
1701 elsif Is_Body
(N
) or else Is_Declaration
(N
) then
1702 Set_Ghost_Mode_From_Entity
(Defining_Entity
(N
));
1704 -- The Ghost mode of an entity depends on the entity itself
1706 elsif Nkind
(N
) in N_Entity
then
1707 Set_Ghost_Mode_From_Entity
(N
);
1709 -- The Ghost mode of a [generic] freeze node depends on the Ghost mode
1710 -- of the entity being frozen.
1712 elsif Nkind_In
(N
, N_Freeze_Entity
, N_Freeze_Generic_Entity
) then
1713 Set_Ghost_Mode_From_Entity
(Entity
(N
));
1715 -- The Ghost mode of a pragma depends on the associated entity. The
1716 -- property is encoded in the pragma itself.
1718 elsif Nkind
(N
) = N_Pragma
then
1719 if Is_Checked_Ghost_Pragma
(N
) then
1720 Install_Ghost_Mode
(Check
);
1721 elsif Is_Ignored_Ghost_Pragma
(N
) then
1722 Install_Ghost_Mode
(Ignore
);
1724 Install_Ghost_Mode
(None
);
1727 -- The Ghost mode of a procedure call depends on the Ghost mode of the
1728 -- procedure being invoked.
1730 elsif Nkind
(N
) = N_Procedure_Call_Statement
then
1731 Id
:= Ghost_Entity
(Name
(N
));
1733 if Present
(Id
) then
1734 Set_Ghost_Mode_From_Entity
(Id
);
1739 -------------------------
1740 -- Set_Is_Ghost_Entity --
1741 -------------------------
1743 procedure Set_Is_Ghost_Entity
(Id
: Entity_Id
) is
1744 Policy
: constant Name_Id
:= Policy_In_Effect
(Name_Ghost
);
1746 if Policy
= Name_Check
then
1747 Set_Is_Checked_Ghost_Entity
(Id
);
1748 elsif Policy
= Name_Ignore
then
1749 Set_Is_Ignored_Ghost_Entity
(Id
);
1751 end Set_Is_Ghost_Entity
;