aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/ghost.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2015-10-23 12:29:50 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2015-10-23 12:29:50 +0200
commit95fef24ff9a7ed0a90781fd153e797d086aa2647 (patch)
tree2a4be0b79d3f141cce4d13d50043a78f201a3374 /gcc/ada/ghost.adb
parent2e885093958b6f2d8383c929cd662cae87fe11fe (diff)
downloadgcc-95fef24ff9a7ed0a90781fd153e797d086aa2647.zip
gcc-95fef24ff9a7ed0a90781fd153e797d086aa2647.tar.gz
gcc-95fef24ff9a7ed0a90781fd153e797d086aa2647.tar.bz2
[multiple changes]
2015-10-23 Bob Duff <duff@adacore.com> * exp_strm.adb (Build_Record_Or_Elementary_Input_Function): Use Underlying_Type for B_Typ, in case the Typ is a subtype of a type with unknown discriminants. * g-awk.ads: Minor style fix in comment 2015-10-23 Hristian Kirtchev <kirtchev@adacore.com> * debug.adb: Document the use of debug switch -gnatd.5. * einfo.adb: Code reformatting. (Is_Ghost_Entity): Moved from ghost.adb. * einfo.ads New synthesized attribute Is_Ghost_Enity along with usage in nodes and pragma Inline. (Is_Ghost_Entity: Moved from ghost.ads. * exp_ch3.adb Code reformatting. (Expand_Freeze_Array_Type): Capture, set and restore the Ghost mode. (Expand_Freeze_Class_Wide_Type): Capture, set and restore the Ghost mode. (Expand_Freeze_Enumeration_Type): Capture, set and restore the Ghost mode. (Expand_Freeze_Record_Type): Capture, set and restore the Ghost mode. * exp_ch6.adb (Expand_Subprogram_Contract): Do not expand the contract of an ignored Ghost subprogram. * exp_ch13.adb Add with and use clauses for Ghost. (Expand_N_Freeze_Entity): Capture, set and restore the Ghost mode. * exp_dbug.adb (Get_External_Name): Code reformatting. Add a special prefix for ignored Ghost entities or when requested by -gnatd.5 for any Ghost entity. * exp_dbug.ads Document the use of prefix "_ghost_" for ignored Ghost entities. * exp_prag.adb (Expand_Pragma_Check): Capture, set and restore the Ghost mode. (Expand_Pragma_Loop_Variant): Use In_Assertion_Expr to signal the original context. * ghost.adb (Check_Ghost_Overriding): Code cleanup. (Is_Ghost_Entity): Moved to einfo.adb. (Is_OK_Declaration): Move the assertion expression check to the outer level. (Is_OK_Ghost_Context): An assertion expression is a valid Ghost context. * ghost.ads (Is_Ghost_Entity): Moved to einfo.ads. * sem_ch3.adb (Analyze_Object_Contract): A source Ghost object cannot be imported or exported. Mark internally generated objects as Ghost when applicable. (Make_Class_Wide_Type): Inherit the ghostness of the root tagged type. * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Mark a stand alone subprogram body as Ghost when applicable. (Analyze_Subprogram_Declaration): Mark internally generated subprograms as Ghost when applicable. * sem_ch7.adb: Code cleanup. * sem_ch13.adb (Add_Invariants): Add various formal parameters to break dependency on global variables. (Build_Invariant_Procedure): Code cleanup. Capture, set and restore the Ghost mode. * sem_res.adb (Resolve_Actuals): The actual parameter of a source Ghost subprogram whose formal is of mode IN OUT or OUT must be a Ghost variable. 2015-10-23 Hristian Kirtchev <kirtchev@adacore.com> * sem_ch8.adb Code cleanup. (Find_Expanded_Name): Replace the call to In_Pragmas_Depends_Or_Global with a call to In_Abstract_View_Pragma. (In_Abstract_View_Pragma): New routine. (In_Pragmas_Depends_Or_Global): Removed. * sem_prag.adb (Analyze_Part_Of): Catch a case where indicator Part_Of denotes the abstract view of a variable. From-SVN: r229224
Diffstat (limited to 'gcc/ada/ghost.adb')
-rw-r--r--gcc/ada/ghost.adb77
1 files changed, 33 insertions, 44 deletions
diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index 7380d9a..cabcc2b 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -229,11 +229,6 @@ package body Ghost is
elsif Is_Subject_To_Ghost (Decl) then
return True;
-
- -- The declaration appears within an assertion expression
-
- elsif In_Assertion_Expr > 0 then
- return True;
end if;
-- Special cases
@@ -338,13 +333,13 @@ package body Ghost is
if Is_Ghost_Pragma (Prag) then
return True;
- -- An assertion expression is a Ghost pragma when it contains a
+ -- An assertion expression pragma is Ghost when it contains a
-- reference to a Ghost entity (SPARK RM 6.9(11)).
elsif Assertion_Expression_Pragma (Prag_Id) then
-- Predicates are excluded from this category when they do
- -- not apply to a Ghost subtype (SPARK RM 6.9(12)).
+ -- not apply to a Ghost subtype (SPARK RM 6.9(11)).
if Nam_In (Prag_Nam, Name_Dynamic_Predicate,
Name_Predicate,
@@ -413,27 +408,17 @@ package body Ghost is
-- Special cases
- elsif Nkind (Stmt) = N_If_Statement then
-
- -- An if statement is a suitable context for a Ghost entity if
- -- it is the byproduct of assertion expression expansion. Note
- -- that the assertion expression may not be related to a Ghost
- -- entity, but it may still contain references to Ghost
- -- entities.
-
- if Nkind (Original_Node (Stmt)) = N_Pragma
- and then Assertion_Expression_Pragma
- (Get_Pragma_Id (Original_Node (Stmt)))
- then
- return True;
-
- -- The expansion of pragma Contract_Cases produces various if
- -- statements to evaluate all case guards. This is a suitable
- -- context as Contract_Cases is an assertion expression.
+ -- An if statement is a suitable context for a Ghost entity if it
+ -- is the byproduct of assertion expression expansion. Note that
+ -- the assertion expression may not be related to a Ghost entity,
+ -- but it may still contain references to Ghost entities.
- elsif In_Assertion_Expr > 0 then
- return True;
- end if;
+ elsif Nkind (Stmt) = N_If_Statement
+ and then Nkind (Original_Node (Stmt)) = N_Pragma
+ and then Assertion_Expression_Pragma
+ (Get_Pragma_Id (Original_Node (Stmt)))
+ then
+ return True;
end if;
return False;
@@ -487,13 +472,26 @@ package body Ghost is
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
- return False;
+ exit;
end if;
Par := Parent (Par);
end loop;
- return False;
+ -- The expansion of assertion expression pragmas and attribute Old
+ -- may cause a legal Ghost entity reference to become illegal due
+ -- to node relocation. Check the In_Assertion_Expr counter as last
+ -- resort to try and infer the original legal context.
+
+ if In_Assertion_Expr > 0 then
+ return True;
+
+ -- Otherwise the context is not suitable for a reference to a
+ -- Ghost entity.
+
+ else
+ return False;
+ end if;
end if;
end Is_OK_Ghost_Context;
@@ -592,32 +590,32 @@ package body Ghost is
(Subp : Entity_Id;
Overridden_Subp : Entity_Id)
is
- Par_Subp : Entity_Id;
+ Over_Subp : Entity_Id;
begin
if Present (Subp) and then Present (Overridden_Subp) then
- Par_Subp := Ultimate_Alias (Overridden_Subp);
+ Over_Subp := Ultimate_Alias (Overridden_Subp);
-- The Ghost policy in effect at the point of declaration of a parent
-- and an overriding subprogram must match (SPARK RM 6.9(17)).
- if Is_Checked_Ghost_Entity (Par_Subp)
+ if Is_Checked_Ghost_Entity (Over_Subp)
and then Is_Ignored_Ghost_Entity (Subp)
then
Error_Msg_N ("incompatible ghost policies in effect", Subp);
- Error_Msg_Sloc := Sloc (Par_Subp);
+ Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # with ghost policy `Check`", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N ("\overridden # with ghost policy `Ignore`", Subp);
- elsif Is_Ignored_Ghost_Entity (Par_Subp)
+ elsif Is_Ignored_Ghost_Entity (Over_Subp)
and then Is_Checked_Ghost_Entity (Subp)
then
Error_Msg_N ("incompatible ghost policies in effect", Subp);
- Error_Msg_Sloc := Sloc (Par_Subp);
+ Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # with ghost policy `Ignore`", Subp);
Error_Msg_Sloc := Sloc (Subp);
@@ -686,15 +684,6 @@ package body Ghost is
Ignored_Ghost_Units.Init;
end Initialize;
- ---------------------
- -- Is_Ghost_Entity --
- ---------------------
-
- function Is_Ghost_Entity (Id : Entity_Id) return Boolean is
- begin
- return Is_Checked_Ghost_Entity (Id) or else Is_Ignored_Ghost_Entity (Id);
- end Is_Ghost_Entity;
-
-------------------------
-- Is_Subject_To_Ghost --
-------------------------