Commit ff81221b by Ed Schonberg Committed by Arnaud Charlet

2008-05-20 Ed Schonberg <schonberg@adacore.com>

	* sem_ch8.adb
	(Note_Redundant_Use): Diagnose a redundant use within a subprogram body
	when there is a use clause for the same entity in the context.
	(Analyze_Subprogram_Renaming): A renaming_as_body is legal if it is
	created for a stream attribute of an abstract type or interface type.

From-SVN: r135641
parent 5ff22245
...@@ -1721,24 +1721,28 @@ package body Sem_Ch8 is ...@@ -1721,24 +1721,28 @@ package body Sem_Ch8 is
Set_Corresponding_Spec (N, Rename_Spec); Set_Corresponding_Spec (N, Rename_Spec);
-- Deal with special case of Input and Output stream functions -- Deal with special case of stream functions of abstract types
-- and interfaces.
if Nkind (Unit_Declaration_Node (Rename_Spec)) = if Nkind (Unit_Declaration_Node (Rename_Spec)) =
N_Abstract_Subprogram_Declaration N_Abstract_Subprogram_Declaration
then then
-- Input and Output stream functions are abstract if the object -- Input stream functions are abstract if the object type is
-- type is abstract. However, these functions may receive explicit -- abstract. Similarly, all default stream functions for an
-- declarations in representation clauses, making the attribute -- interface type are abstract. However, these suprograms may
-- subprograms usable as defaults in subsequent type extensions. -- receive explicit declarations in representation clauses, making
-- the attribute subprograms usable as defaults in subsequent
-- type extensions.
-- In this case we rewrite the declaration to make the subprogram -- In this case we rewrite the declaration to make the subprogram
-- non-abstract. We remove the previous declaration, and insert -- non-abstract. We remove the previous declaration, and insert
-- the new one at the point of the renaming, to prevent premature -- the new one at the point of the renaming, to prevent premature
-- access to unfrozen types. The new declaration reuses the -- access to unfrozen types. The new declaration reuses the
-- specification of the previous one, and must not be analyzed. -- specification of the previous one, and must not be analyzed.
pragma Assert (Is_TSS (Rename_Spec, TSS_Stream_Output) pragma Assert
or else Is_TSS (Rename_Spec, TSS_Stream_Input)); (Is_Primitive (Entity (Nam))
and then
Is_Abstract_Type (Find_Dispatching_Type (Entity (Nam))));
declare declare
Old_Decl : constant Node_Id := Old_Decl : constant Node_Id :=
Unit_Declaration_Node (Rename_Spec); Unit_Declaration_Node (Rename_Spec);
...@@ -3777,8 +3781,8 @@ package body Sem_Ch8 is ...@@ -3777,8 +3781,8 @@ package body Sem_Ch8 is
E := Homonyms; E := Homonyms;
while Present (E) loop while Present (E) loop
-- If entity is immediately visible or potentially use -- If entity is immediately visible or potentially use visible, then
-- visible, then process the entity and we are done. -- process the entity and we are done.
if Is_Immediately_Visible (E) then if Is_Immediately_Visible (E) then
goto Immediately_Visible_Entity; goto Immediately_Visible_Entity;
...@@ -3958,15 +3962,15 @@ package body Sem_Ch8 is ...@@ -3958,15 +3962,15 @@ package body Sem_Ch8 is
-- Come here with E set to the first immediately visible entity on -- Come here with E set to the first immediately visible entity on
-- the homonym chain. This is the one we want unless there is another -- the homonym chain. This is the one we want unless there is another
-- immediately visible entity further on in the chain for a more -- immediately visible entity further on in the chain for an inner
-- inner scope (RM 8.3(8)). -- scope (RM 8.3(8)).
<<Immediately_Visible_Entity>> declare <<Immediately_Visible_Entity>> declare
Level : Int; Level : Int;
Scop : Entity_Id; Scop : Entity_Id;
begin begin
-- Find scope level of initial entity. When compiling through -- Find scope level of initial entity. When compiling through
-- Rtsfind, the previous context is not completely invisible, and -- Rtsfind, the previous context is not completely invisible, and
-- an outer entity may appear on the chain, whose scope is below -- an outer entity may appear on the chain, whose scope is below
-- the entry for Standard that delimits the current scope stack. -- the entry for Standard that delimits the current scope stack.
...@@ -4243,8 +4247,8 @@ package body Sem_Ch8 is ...@@ -4243,8 +4247,8 @@ package body Sem_Ch8 is
P_Name := Entity (Prefix (N)); P_Name := Entity (Prefix (N));
O_Name := P_Name; O_Name := P_Name;
-- If the prefix is a renamed package, look for the entity -- If the prefix is a renamed package, look for the entity in the
-- in the original package. -- original package.
if Ekind (P_Name) = E_Package if Ekind (P_Name) = E_Package
and then Present (Renamed_Object (P_Name)) and then Present (Renamed_Object (P_Name))
...@@ -4335,10 +4339,10 @@ package body Sem_Ch8 is ...@@ -4335,10 +4339,10 @@ package body Sem_Ch8 is
if No (Id) or else Chars (Id) /= Chars (Selector) then if No (Id) or else Chars (Id) /= Chars (Selector) then
Set_Etype (N, Any_Type); Set_Etype (N, Any_Type);
-- If we are looking for an entity defined in System, try to -- If we are looking for an entity defined in System, try to find it
-- find it in the child package that may have been provided as -- in the child package that may have been provided as an extension
-- an extension to System. The Extend_System pragma will have -- to System. The Extend_System pragma will have supplied the name of
-- supplied the name of the extension, which may have to be loaded. -- the extension, which may have to be loaded.
if Chars (P_Name) = Name_System if Chars (P_Name) = Name_System
and then Scope (P_Name) = Standard_Standard and then Scope (P_Name) = Standard_Standard
...@@ -4368,9 +4372,8 @@ package body Sem_Ch8 is ...@@ -4368,9 +4372,8 @@ package body Sem_Ch8 is
return; return;
else else
-- If the prefix is a single concurrent object, use its -- If the prefix is a single concurrent object, use its name in
-- name in the error message, rather than that of the -- the error message, rather than that of the anonymous type.
-- anonymous type.
if Is_Concurrent_Type (P_Name) if Is_Concurrent_Type (P_Name)
and then Is_Internal_Name (Chars (P_Name)) and then Is_Internal_Name (Chars (P_Name))
...@@ -4917,7 +4920,6 @@ package body Sem_Ch8 is ...@@ -4917,7 +4920,6 @@ package body Sem_Ch8 is
-- in the expansion of record equality). -- in the expansion of record equality).
elsif Present (Entity (Selector_Name (N))) then elsif Present (Entity (Selector_Name (N))) then
if No (Etype (N)) if No (Etype (N))
or else Etype (N) = Any_Type or else Etype (N) = Any_Type
then then
...@@ -6145,6 +6147,16 @@ package body Sem_Ch8 is ...@@ -6145,6 +6147,16 @@ package body Sem_Ch8 is
end; end;
end if; end if;
-- Finally, if the current use clause is in the context then
-- the clause is redundant when it is nested within the unit.
elsif Nkind (Parent (Cur_Use)) = N_Compilation_Unit
and then Nkind (Parent (Parent (Clause))) /= N_Compilation_Unit
and then Get_Source_Unit (Cur_Use) = Get_Source_Unit (Clause)
then
Redundant := Clause;
Prev_Use := Cur_Use;
else else
null; null;
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