Commit 6a4d72a6 by Ed Schonberg Committed by Arnaud Charlet

sem_ch8.adb (Analyze_Subprogram_Renaming): When renaming an attribute as a actual in an instance...

2008-07-30  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch8.adb (Analyze_Subprogram_Renaming): When renaming an attribute
	as a actual in an instance, check for a missing attribute to prevent
	program_error on an illegal program.
	
	* exp_util.adb (Find_Prim_Op): Rather than Assert (False), raise program
	error if primitive is not found, so that exception can be handled
	elsewhere on illegal programs.

From-SVN: r138322
parent 706d7459
...@@ -1581,7 +1581,10 @@ package body Exp_Util is ...@@ -1581,7 +1581,10 @@ package body Exp_Util is
or else Etype (First_Entity (Op)) = Etype (Last_Entity (Op))); or else Etype (First_Entity (Op)) = Etype (Last_Entity (Op)));
Next_Elmt (Prim); Next_Elmt (Prim);
pragma Assert (Present (Prim));
if No (Prim) then
raise Program_Error;
end if;
end loop; end loop;
return Node (Prim); return Node (Prim);
...@@ -1608,7 +1611,10 @@ package body Exp_Util is ...@@ -1608,7 +1611,10 @@ package body Exp_Util is
Prim := First_Elmt (Primitive_Operations (Typ)); Prim := First_Elmt (Primitive_Operations (Typ));
while not Is_TSS (Node (Prim), Name) loop while not Is_TSS (Node (Prim), Name) loop
Next_Elmt (Prim); Next_Elmt (Prim);
pragma Assert (Present (Prim));
if No (Prim) then
raise Program_Error;
end if;
end loop; end loop;
return Node (Prim); return Node (Prim);
......
...@@ -1578,25 +1578,44 @@ package body Sem_Ch8 is ...@@ -1578,25 +1578,44 @@ package body Sem_Ch8 is
-- an abstract formal subprogram must be dispatching -- an abstract formal subprogram must be dispatching
-- operation). -- operation).
case Attribute_Name (Nam) is begin
when Name_Input => case Attribute_Name (Nam) is
Stream_Prim := when Name_Input =>
Find_Prim_Op (Prefix_Type, TSS_Stream_Input); Stream_Prim :=
when Name_Output => Find_Prim_Op (Prefix_Type, TSS_Stream_Input);
Stream_Prim := when Name_Output =>
Find_Prim_Op (Prefix_Type, TSS_Stream_Output); Stream_Prim :=
when Name_Read => Find_Prim_Op (Prefix_Type, TSS_Stream_Output);
Stream_Prim := when Name_Read =>
Find_Prim_Op (Prefix_Type, TSS_Stream_Read); Stream_Prim :=
when Name_Write => Find_Prim_Op (Prefix_Type, TSS_Stream_Read);
Stream_Prim := when Name_Write =>
Find_Prim_Op (Prefix_Type, TSS_Stream_Write); Stream_Prim :=
when others => Find_Prim_Op (Prefix_Type, TSS_Stream_Write);
Error_Msg_N when others =>
("attribute must be a primitive dispatching operation", Error_Msg_N
Nam); ("attribute must be a primitive"
return; & " dispatching operation", Nam);
end case; return;
end case;
exception
-- If no operation was found, and the type is limited,
-- the user should have defined one.
when Program_Error =>
if Is_Limited_Type (Prefix_Type) then
Error_Msg_NE
("stream operation not defined for type&",
N, Prefix_Type);
return;
-- Otherwise, compiler should have generated default.
else
raise;
end if;
end;
-- Rewrite the attribute into the name of its corresponding -- Rewrite the attribute into the name of its corresponding
-- primitive dispatching subprogram. We can then proceed with -- primitive dispatching subprogram. We can then proceed with
......
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