Commit b554177a by Arnaud Charlet

[multiple changes]

2017-04-25  Justin Squirek  <squirek@adacore.com>

	* exp_ch3.adb (Freeze_Type): Add condition to always treat
	interface types as a partial view of a private type for the
	generation of invariant procedure bodies.
	* exp_util.adb, exp_util.ads (Add_Inherited_Invariants):
	Add a condition to get the Corresponding_Record_Type for
	concurrent types, add condition to return in the absence of a
	class in the pragma, remove call to Replace_Type_References,
	and add call to Replace_References.
	(Add_Interface_Invariatns),
	(Add_Parent_Invariants): Modify call to Add_Inherited_Invariants
	to including the working type T.
	(Add_Own_Invariants): Remove
	legacy condition for separate units, remove dispatching for ASIS
	and save a copy of the expression in the pragma expression.
	(Build_Invariant_Procedure_Body): Default initalize vars,
	remove return condition on interfaces, always use the
	private type for interfaces, and move the processing of types
	until after the processing of invariants for the full view.
	(Build_Invariant_Procedure_Declaration): Remove condition
	to return if an interface type is encountered and add
	condition to convert the formal parameter to its class-wide
	counterpart if Work_Typ is abstract.
	(Replace_Type): Add call to Remove_Controlling_Arguments.
	(Replace_Type_Ref): Remove class-wide dispatching for the current
	instance of the type.
	(Replace_Type_References): Remove parameter "Derived"
	(Remove_Controlling_Arguments): Created in order to removing
	the controlliong argument from calls to primitives in the case
	of the formal parameter being an class-wide abstract type.
	* sem_ch3.adb (Build_Assertion_Bodies_For_Type): Almost identical
	to the change made to Freeze_Type in exp_ch3. Add a condition
	to treat interface types as a partial view.
	* sem_prag.adb (Analyze_Pragma): Modify parameters in the call
	to Build_Invariant_Procedure_Declaration to properly generate a
	"partial" invariant procedure when Typ is an interface.

2017-04-25  Bob Duff  <duff@adacore.com>

	* a-numeri.ads: Go back to using brackets encoding for the Greek
	letter pi.

From-SVN: r247204
parent c9e9c3ac
2017-04-25 Justin Squirek <squirek@adacore.com>
* exp_ch3.adb (Freeze_Type): Add condition to always treat
interface types as a partial view of a private type for the
generation of invariant procedure bodies.
* exp_util.adb, exp_util.ads (Add_Inherited_Invariants):
Add a condition to get the Corresponding_Record_Type for
concurrent types, add condition to return in the absence of a
class in the pragma, remove call to Replace_Type_References,
and add call to Replace_References.
(Add_Interface_Invariatns),
(Add_Parent_Invariants): Modify call to Add_Inherited_Invariants
to including the working type T.
(Add_Own_Invariants): Remove
legacy condition for separate units, remove dispatching for ASIS
and save a copy of the expression in the pragma expression.
(Build_Invariant_Procedure_Body): Default initalize vars,
remove return condition on interfaces, always use the
private type for interfaces, and move the processing of types
until after the processing of invariants for the full view.
(Build_Invariant_Procedure_Declaration): Remove condition
to return if an interface type is encountered and add
condition to convert the formal parameter to its class-wide
counterpart if Work_Typ is abstract.
(Replace_Type): Add call to Remove_Controlling_Arguments.
(Replace_Type_Ref): Remove class-wide dispatching for the current
instance of the type.
(Replace_Type_References): Remove parameter "Derived"
(Remove_Controlling_Arguments): Created in order to removing
the controlliong argument from calls to primitives in the case
of the formal parameter being an class-wide abstract type.
* sem_ch3.adb (Build_Assertion_Bodies_For_Type): Almost identical
to the change made to Freeze_Type in exp_ch3. Add a condition
to treat interface types as a partial view.
* sem_prag.adb (Analyze_Pragma): Modify parameters in the call
to Build_Invariant_Procedure_Declaration to properly generate a
"partial" invariant procedure when Typ is an interface.
2017-04-25 Bob Duff <duff@adacore.com>
* a-numeri.ads: Go back to using brackets encoding for the Greek
letter pi.
2017-04-25 Ed Schonberg <schonberg@adacore.com>
* sem_ch3.adb (Derive_Subprogram): Implement rule in RM 6.1.1
......
......@@ -18,20 +18,14 @@ package Ada.Numerics is
Argument_Error : exception;
pragma Wide_Character_Encoding (UTF8);
-- For the Greek letter Pi below. Note that this pragma cannot immediately
-- precede that character, because then the encoding gets set too late.
Pi : constant :=
3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511;
π : constant := Pi;
["03C0"] : constant := Pi;
-- This is the Greek letter Pi (for Ada 2005 AI-388). Note that it is
-- conforming to have this constant present even in Ada 95 mode, as there
-- is no way for a normal mode Ada 95 program to reference this identifier.
pragma Wide_Character_Encoding (BRACKETS);
e : constant :=
2.71828_18284_59045_23536_02874_71352_66249_77572_47093_69996;
......
......@@ -7529,7 +7529,22 @@ package body Exp_Ch3 is
-- class-wide invariants from parent types or interfaces, and invariants
-- on array elements or record components.
if Has_Invariants (Def_Id) then
if Is_Interface (Def_Id) then
-- Interfaces are treated as the partial view of a private type in
-- order to achieve uniformity with the general case. As a result, an
-- interface receives only a "partial" invariant procedure which is
-- never called.
if Has_Own_Invariants (Def_Id) then
Build_Invariant_Procedure_Body
(Typ => Def_Id,
Partial_Invariant => Is_Interface (Def_Id));
end if;
-- Non-interface types
elsif Has_Invariants (Def_Id) then
Build_Invariant_Procedure_Body (Def_Id);
end if;
......
......@@ -1062,10 +1062,9 @@ package Exp_Util is
-- the internally-generated inherited primitive of Deriv_Typ.
procedure Replace_Type_References
(Expr : Node_Id;
Typ : Entity_Id;
Obj_Id : Entity_Id;
Dispatch : Boolean := False);
(Expr : Node_Id;
Typ : Entity_Id;
Obj_Id : Entity_Id);
-- Substitute all references of the current instance of type Typ with
-- references to formal parameter Obj_Id within expression Expr.
......
......@@ -2279,12 +2279,32 @@ package body Sem_Ch3 is
if Nkind (Context) = N_Package_Specification then
-- Preanalyze and resolve the class-wide invariants of an
-- interface at the end of whichever declarative part has the
-- interface type. Note that an interface may be declared in
-- any non-package declarative part, but reaching the end of
-- such a declarative part will always freeze the type and
-- generate the invariant procedure (see Freeze_Type).
if Is_Interface (Typ) then
-- Interfaces are treated as the partial view of a private
-- type in order to achieve uniformity with the general
-- case. As a result, an interface receives only a "partial"
-- invariant procedure which is never called.
if Has_Own_Invariants (Typ) then
Build_Invariant_Procedure_Body
(Typ => Typ,
Partial_Invariant => True);
end if;
-- Preanalyze and resolve the invariants of a private type
-- at the end of the visible declarations to catch potential
-- errors. Inherited class-wide invariants are not included
-- because they have already been resolved.
if Decls = Visible_Declarations (Context)
elsif Decls = Visible_Declarations (Context)
and then Ekind_In (Typ, E_Limited_Private_Type,
E_Private_Type,
E_Record_Type_With_Private)
......@@ -15315,10 +15335,9 @@ package body Sem_Ch3 is
New_Overloaded_Entity (New_Subp, Derived_Type);
-- Implement rule in 6.1.1 (15) : if subprogram inherits non-conforming
-- classwide preconditions and the derived type is abstract, the
-- derived operation is abstract as well if parent subprogram is not
-- abstract or null.
-- Ada RM 6.1.1 (15): If a subprogram inherits non-conforming class-wide
-- preconditions and the derived type is abstract, the derived operation
-- is abstract as well if parent subprogram is not abstract or null.
if Is_Abstract_Type (Derived_Type)
and then Has_Non_Trivial_Precondition (Parent_Subp)
......
......@@ -17113,10 +17113,14 @@ package body Sem_Prag is
Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
-- Create the declaration of the invariant procedure which will
-- verify the invariant at run-time. Note that interfaces do not
-- carry such a declaration.
Build_Invariant_Procedure_Declaration (Typ);
-- verify the invariant at run-time. Interfaces are treated as the
-- partial view of a private type in order to achieve uniformity
-- with the general case. As a result, an interface receives only
-- a "partial" invariant procedure which is never called.
Build_Invariant_Procedure_Declaration
(Typ => Typ,
Partial_Invariant => Is_Interface (Typ));
end Invariant;
----------------
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