Commit ae3d8837 by Hristian Kirtchev Committed by Arnaud Charlet

sem_ch13.adb (Build_Invariant_Procedure): Reimplement the invariant procedure…

sem_ch13.adb (Build_Invariant_Procedure): Reimplement the invariant procedure spec and body insertion.

2016-04-20  Hristian Kirtchev  <kirtchev@adacore.com>

	* sem_ch13.adb (Build_Invariant_Procedure):
	Reimplement the invariant procedure spec and body insertion.

From-SVN: r235239
parent 776fbb74
2016-04-20 Hristian Kirtchev <kirtchev@adacore.com> 2016-04-20 Hristian Kirtchev <kirtchev@adacore.com>
* sem_ch13.adb (Build_Invariant_Procedure):
Reimplement the invariant procedure spec and body insertion.
2016-04-20 Hristian Kirtchev <kirtchev@adacore.com>
* sem_ch13.adb (Add_Invariant): Do not replace * sem_ch13.adb (Add_Invariant): Do not replace
the saved expression of an invariatn aspect when inheriting the saved expression of an invariatn aspect when inheriting
a class-wide type invariant as this clobbers the existing a class-wide type invariant as this clobbers the existing
......
...@@ -8335,46 +8335,40 @@ package body Sem_Ch13 is ...@@ -8335,46 +8335,40 @@ package body Sem_Ch13 is
Make_Handled_Sequence_Of_Statements (Loc, Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts)); Statements => Stmts));
-- Insert procedure declaration and spec at the appropriate points. -- The processing of an invariant pragma immediately generates the
-- If declaration is already analyzed, it was processed by the -- invariant procedure spec, inserts it into the tree and analyzes
-- generated pragma. -- it. If the spec has not been analyzed, then the invariant pragma
-- is being inherited and requires manual insertion and analysis.
if Present (Priv_Decls) then if not Analyzed (PDecl) then
Append_To (Vis_Decls, PDecl);
-- The spec goes at the end of visible declarations, but they have Analyze (PDecl);
-- already been analyzed, so we need to explicitly do the analyze. end if;
if not Analyzed (PDecl) then
Append_To (Vis_Decls, PDecl);
Analyze (PDecl);
end if;
-- The body goes at the end of the private declarations, which we -- The invariant procedure body is inserted at the end of the private
-- have not analyzed yet, so we do not need to perform an explicit -- declarations.
-- analyze call. We skip this if there are no private declarations
-- (this is an error that will be caught elsewhere);
if Present (Priv_Decls) then
Append_To (Priv_Decls, PBody); Append_To (Priv_Decls, PBody);
-- If the invariant appears on the full view of a type, the -- If the invariant appears on the full view of a private type,
-- analysis of the private part is complete, and we must -- then the analysis of the private part is already completed.
-- analyze the new body explicitly. -- Manually analyze the new body in this case, otherwise wait
-- for the analysis of the private declarations to process the
-- body.
if In_Private_Part (Current_Scope) then if In_Private_Part (Current_Scope) then
Analyze (PBody); Analyze (PBody);
end if; end if;
-- If there are no private declarations this may be an error that -- Otherwise there are no private declarations. This is either an
-- will be diagnosed elsewhere. However, if this is a non-private -- error or the related type is a private extension in which case
-- type that inherits invariants, it needs no completion and there -- it does not need a completion in a private part. Insert the body
-- may be no private part. In this case insert invariant procedure -- and the end of the visible declarations and analyze immediately
-- at end of current declarative list, and analyze at once, given -- because the related type is about to be frozen.
-- that the type is about to be frozen.
elsif not Is_Private_Type (Typ) then else
Append_To (Vis_Decls, PDecl);
Append_To (Vis_Decls, PBody); Append_To (Vis_Decls, PBody);
Analyze (PDecl);
Analyze (PBody); Analyze (PBody);
end if; end if;
end if; end if;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment