Commit 0fea901b by Arnaud Charlet

[multiple changes]

2014-08-04  Thomas Quinot  <quinot@adacore.com>

	* sem_ch5.adb: Minor reformatting.

2014-08-04  Ed Schonberg  <schonberg@adacore.com>

	* freeze.adb (Late_Freeze_Subprogram): Following AI05-151,
	a function can return a limited view of a type declared
	elsewhere. In that case the function cannot be frozen at the end
	of its enclosing package. If its first use is in a different unit,
	it cannot be frozen there, but if the call is legal the full view
	of the return type is available and the subprogram can now be
	frozen. However the freeze node cannot be inserted at the point
	of call, but rather must go in the package holding the function,
	so that the backend can process it in the proper context.

From-SVN: r213562
parent 11261647
2014-08-04 Thomas Quinot <quinot@adacore.com>
* sem_ch5.adb: Minor reformatting.
2014-08-04 Ed Schonberg <schonberg@adacore.com>
* freeze.adb (Late_Freeze_Subprogram): Following AI05-151,
a function can return a limited view of a type declared
elsewhere. In that case the function cannot be frozen at the end
of its enclosing package. If its first use is in a different unit,
it cannot be frozen there, but if the call is legal the full view
of the return type is available and the subprogram can now be
frozen. However the freeze node cannot be inserted at the point
of call, but rather must go in the package holding the function,
so that the backend can process it in the proper context.
2014-08-04 Robert Dewar <dewar@adacore.com> 2014-08-04 Robert Dewar <dewar@adacore.com>
* exp_ch5.adb, sem_ch5.adb, einfo.ads: Minor reformatting. * exp_ch5.adb, sem_ch5.adb, einfo.ads: Minor reformatting.
......
...@@ -1815,13 +1815,18 @@ package body Freeze is ...@@ -1815,13 +1815,18 @@ package body Freeze is
------------------- -------------------
function Freeze_Entity (E : Entity_Id; N : Node_Id) return List_Id is function Freeze_Entity (E : Entity_Id; N : Node_Id) return List_Id is
Loc : constant Source_Ptr := Sloc (N); Loc : constant Source_Ptr := Sloc (N);
Comp : Entity_Id;
F_Node : Node_Id;
Indx : Node_Id;
Formal : Entity_Id;
Atype : Entity_Id;
Test_E : Entity_Id := E; Test_E : Entity_Id := E;
Comp : Entity_Id; -- This could use a comment ???
F_Node : Node_Id;
Indx : Node_Id; Late_Freezing : Boolean := False;
Formal : Entity_Id; -- Used to detect attempt to freeze function declared in another unit
Atype : Entity_Id;
Result : List_Id := No_List; Result : List_Id := No_List;
-- List of freezing actions, left at No_List if none -- List of freezing actions, left at No_List if none
...@@ -1861,6 +1866,16 @@ package body Freeze is ...@@ -1861,6 +1866,16 @@ package body Freeze is
-- Determine whether an arbitrary entity is subject to Boolean aspect -- Determine whether an arbitrary entity is subject to Boolean aspect
-- Import and its value is specified as True. -- Import and its value is specified as True.
procedure Late_Freeze_Subprogram (E : Entity_Id);
-- Following AI05-151, a function can return a limited view of a type
-- declared elsewhere. In that case the function cannot be frozen at
-- the end of its enclosing package. If its first use is in a different
-- unit, it cannot be frozen there, but if the call is legal the full
-- view of the return type is available and the subprogram can now be
-- frozen. However the freeze node cannot be inserted at the point of
-- call, but rather must go in the package holding the function, so that
-- the backend can process it in the proper context.
procedure Wrap_Imported_Subprogram (E : Entity_Id); procedure Wrap_Imported_Subprogram (E : Entity_Id);
-- If E is an entity for an imported subprogram with pre/post-conditions -- If E is an entity for an imported subprogram with pre/post-conditions
-- then this procedure will create a wrapper to ensure that proper run- -- then this procedure will create a wrapper to ensure that proper run-
...@@ -1885,6 +1900,7 @@ package body Freeze is ...@@ -1885,6 +1900,7 @@ package body Freeze is
function After_Last_Declaration return Boolean is function After_Last_Declaration return Boolean is
Spec : constant Node_Id := Parent (Current_Scope); Spec : constant Node_Id := Parent (Current_Scope);
begin begin
if Nkind (Spec) = N_Package_Specification then if Nkind (Spec) = N_Package_Specification then
if Present (Private_Declarations (Spec)) then if Present (Private_Declarations (Spec)) then
...@@ -1894,6 +1910,7 @@ package body Freeze is ...@@ -1894,6 +1910,7 @@ package body Freeze is
else else
return False; return False;
end if; end if;
else else
return False; return False;
end if; end if;
...@@ -2013,8 +2030,7 @@ package body Freeze is ...@@ -2013,8 +2030,7 @@ package body Freeze is
else else
Error_Msg_N Error_Msg_N
("current instance must be an immutably limited " ("current instance must be an immutably limited "
& "type (RM-2012, 7.5 (8.1/3))", & "type (RM-2012, 7.5 (8.1/3))", Prefix (N));
Prefix (N));
end if; end if;
return Abandon; return Abandon;
...@@ -2182,8 +2198,7 @@ package body Freeze is ...@@ -2182,8 +2198,7 @@ package body Freeze is
Error_Msg_Name_1 := CN; Error_Msg_Name_1 := CN;
Error_Msg_Sloc := Sloc (Arr); Error_Msg_Sloc := Sloc (Arr);
Error_Msg_N Error_Msg_N
("pragma Pack affects convention % components #??", ("pragma Pack affects convention % components #??", PP);
PP);
Error_Msg_Name_1 := CN; Error_Msg_Name_1 := CN;
Error_Msg_N Error_Msg_N
("\array components may not have % compatible " ("\array components may not have % compatible "
...@@ -2260,6 +2275,7 @@ package body Freeze is ...@@ -2260,6 +2275,7 @@ package body Freeze is
Comp_Size_C : constant Node_Id := Comp_Size_C : constant Node_Id :=
Get_Attribute_Definition_Clause Get_Attribute_Definition_Clause
(Ent, Attribute_Component_Size); (Ent, Attribute_Component_Size);
begin begin
-- Warn if we have pack and component size so that the -- Warn if we have pack and component size so that the
-- pack is ignored. -- pack is ignored.
...@@ -2305,11 +2321,11 @@ package body Freeze is ...@@ -2305,11 +2321,11 @@ package body Freeze is
if Present (Pack_Pragma) then if Present (Pack_Pragma) then
Error_Msg_N Error_Msg_N
("??pragma Pack causes component size " ("??pragma Pack causes component size to be ^!",
& "to be ^!", Pack_Pragma); Pack_Pragma);
Error_Msg_N Error_Msg_N
("\??use Component_Size to set " ("\??use Component_Size to set desired value!",
& "desired value!", Pack_Pragma); Pack_Pragma);
end if; end if;
end if; end if;
...@@ -2531,8 +2547,7 @@ package body Freeze is ...@@ -2531,8 +2547,7 @@ package body Freeze is
Ilen := Ilen :=
Make_Attribute_Reference (Loc, Make_Attribute_Reference (Loc,
Prefix => Prefix => New_Occurrence_Of (Ityp, Loc),
New_Occurrence_Of (Ityp, Loc),
Attribute_Name => Name_Range_Length); Attribute_Name => Name_Range_Length);
Analyze_And_Resolve (Ilen); Analyze_And_Resolve (Ilen);
...@@ -2562,10 +2577,8 @@ package body Freeze is ...@@ -2562,10 +2577,8 @@ package body Freeze is
if Known_RM_Size (Arr) then if Known_RM_Size (Arr) then
declare declare
SizC : constant Node_Id := Size_Clause (Arr); SizC : constant Node_Id := Size_Clause (Arr);
Discard : Boolean; Discard : Boolean;
pragma Warnings (Off, Discard);
begin begin
-- It is not clear if it is possible to have no size clause -- It is not clear if it is possible to have no size clause
...@@ -3060,6 +3073,7 @@ package body Freeze is ...@@ -3060,6 +3073,7 @@ package body Freeze is
if Will_Be_Frozen then if Will_Be_Frozen then
Undelay_Type (Comp); Undelay_Type (Comp);
else else
if Present (Prev) then if Present (Prev) then
Set_Next_Entity (Prev, Next_Entity (Comp)); Set_Next_Entity (Prev, Next_Entity (Comp));
...@@ -3107,8 +3121,8 @@ package body Freeze is ...@@ -3107,8 +3121,8 @@ package body Freeze is
if Is_Entity_Name (Expression (Alloc)) then if Is_Entity_Name (Expression (Alloc)) then
Freeze_And_Append Freeze_And_Append
(Entity (Expression (Alloc)), N, Result); (Entity (Expression (Alloc)), N, Result);
elsif
Nkind (Expression (Alloc)) = N_Subtype_Indication elsif Nkind (Expression (Alloc)) = N_Subtype_Indication
then then
Freeze_And_Append Freeze_And_Append
(Entity (Subtype_Mark (Expression (Alloc))), (Entity (Subtype_Mark (Expression (Alloc))),
...@@ -3633,6 +3647,25 @@ package body Freeze is ...@@ -3633,6 +3647,25 @@ package body Freeze is
return False; return False;
end Has_Boolean_Aspect_Import; end Has_Boolean_Aspect_Import;
----------------------------
-- Late_Freeze_Subprogram --
----------------------------
procedure Late_Freeze_Subprogram (E : Entity_Id) is
Spec : constant Node_Id :=
Specification (Unit_Declaration_Node (Scope (E)));
Decls : List_Id;
begin
if Present (Private_Declarations (Spec)) then
Decls := Private_Declarations (Spec);
else
Decls := Visible_Declarations (Spec);
end if;
Append_List (Result, Decls);
end Late_Freeze_Subprogram;
------------------------------ ------------------------------
-- Wrap_Imported_Subprogram -- -- Wrap_Imported_Subprogram --
------------------------------ ------------------------------
...@@ -4165,6 +4198,16 @@ package body Freeze is ...@@ -4165,6 +4198,16 @@ package body Freeze is
if Ekind (E) = E_Function then if Ekind (E) = E_Function then
-- Check whether function is declared elsewhere.
Late_Freezing :=
Get_Source_Unit (E) /= Get_Source_Unit (N)
and then Expander_Active
and then Ekind (Scope (E)) = E_Package
and then Nkind (Unit_Declaration_Node (Scope (E)))
= N_Package_Declaration
and then not In_Open_Scopes (Scope (E));
-- Freeze return type -- Freeze return type
R_Type := Etype (E); R_Type := Etype (E);
...@@ -4325,6 +4368,11 @@ package body Freeze is ...@@ -4325,6 +4368,11 @@ package body Freeze is
Freeze_Subprogram (E); Freeze_Subprogram (E);
end if; end if;
if Late_Freezing then
Late_Freeze_Subprogram (E);
return No_List;
end if;
-- If warning on suspicious contracts then check for the case of -- If warning on suspicious contracts then check for the case of
-- a postcondition other than False for a No_Return subprogram. -- a postcondition other than False for a No_Return subprogram.
......
...@@ -2204,10 +2204,9 @@ package body Sem_Ch5 is ...@@ -2204,10 +2204,9 @@ package body Sem_Ch5 is
procedure Check_Predicate_Use (T : Entity_Id) is procedure Check_Predicate_Use (T : Entity_Id) is
begin begin
-- A predicated subtype is illegal in loops and related constructs -- A predicated subtype is illegal in loops and related constructs
-- if the predicate is not static, or else if it is a non-static -- if the predicate is not static, or if it is a non-static subtype
-- subtype of a statically predicated subtype. -- of a statically predicated subtype.
if Is_Discrete_Type (T) if Is_Discrete_Type (T)
and then Has_Predicates (T) and then Has_Predicates (T)
...@@ -2215,6 +2214,9 @@ package body Sem_Ch5 is ...@@ -2215,6 +2214,9 @@ package body Sem_Ch5 is
or else not Is_Static_Subtype (T) or else not Is_Static_Subtype (T)
or else Has_Dynamic_Predicate_Aspect (T)) or else Has_Dynamic_Predicate_Aspect (T))
then then
-- Seems a confusing message for the case of a static predicate
-- with a non-static subtype???
Bad_Predicated_Subtype_Use Bad_Predicated_Subtype_Use
("cannot use subtype& with non-static predicate for loop " ("cannot use subtype& with non-static predicate for loop "
& "iteration", Discrete_Subtype_Definition (N), & "iteration", Discrete_Subtype_Definition (N),
......
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