Commit 0a36105d by Javier Miranda Committed by Arnaud Charlet

einfo.ads, einfo.adb (Available_View): New synthesized attribute applicable to…

einfo.ads, einfo.adb (Available_View): New synthesized attribute applicable to types that have the With_Type flag set.

2007-04-20  Javier Miranda  <miranda@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>
	    Robert Dewar  <dewar@adacore.com>
	    Eric Botcazou  <ebotcazou@adacore.com>
	    Arnaud Charlet  <charlet@adacore.com>

	* einfo.ads, einfo.adb (Available_View): New synthesized attribute
	applicable to types that have the With_Type flag set. Returns the
	non-limited view of the type, if available, otherwise the type itself.
	For class-wide types, there is no direct link in the tree, so we have
	to retrieve the class-wide type of the non-limited view of the Etype.
	New attributes Static_Initialization and Static_Elaboration_Desired.
	Remove the pragma Thread_Body, and the associated flag
	Is_Thread_Body in entities, and all related code.
	(Suppress_Value_Tracking_On_Call): New flag
	E_Exception has Esize and Alignment fields
	(Universal_Aliasing): New function.
	(Set_Universal_Aliasing): New procedure.
	(Write_Entity_Flags): Deal with Universal_Aliasing flag.
	(Check_Nested_Access): New procedure.
	(Has_Up_Level_Access, Set_Has_Up_Level_Access): New procedures.
	(Find_Direct_Name, Note_Possible_Modification): Use Check_Nested_Access.
	(Related_Interface): New attribute. Present in dispatch table pointer
	components of records. Set to point to the entity of the corresponding
	interface type.
	(Is_By_Reference_Type): Recurse on the full view of an incomplete type.
	(Original_Access_Type): Remove, not needed.
	(Root_Type): Handle properly subtypes of class-wide-types.
	Update comments.

	* sem_ch4.adb (Analyze_Explicit_Dereference): Add support for
	class-wide types visible through limited-with clauses.
	(Try_Primitive_Operation): When examining all primitive operations of a
	tagged type, do not consider subprograms labeled as hidden unless they
	belong to a private generic type with a tagged parent.
	(Try_Object_Operation): Extensive rewriting, to handle properly various
	overloading cases, when several ancestors may have class-wide operations
	that are possible candidates, and when the overloaded functions return
	array types and have defaulted parameters so that the call may be
	interpreted as an indexing.
	(Analyze_Allocator): Remove Mark_Allocator and its invocation.
	(Process_Function_Call): use Next, rather than Next_Actual, to analyze
	successive actuals before analyzing the call itself.
	(Try_Primitive_Operation): A primitive operation is compatible with the
	prefix if the prefix has a synchronized type and the type of the formal
	is its corresponding record, as can be the case when the primitive
	operation is declared outside of the body of the type.
	(Traverse_Homonyms): New subprocedure of Try_Class_Wide_Operation, to
	perform homonym traversal, looking for class-wide operation matches
	(formerly done in statements of Try_Class_Wide_Operation). Matches on
	access parameters are now restricted to anonymous access types.
	(Mark_Allocator): An allocator with a discriminant association parent is
	a coextension.
	(Try_One_Prefix_Interpretation): If the type of the object is
	incomplete, as can be happen when it is a limited view obtained through
	a limited_with_clause, the selected component is not part of a prefixed
	call.
	(Complete_Object_Operation): Diagnose properly an object that is not
	aliased when the corresponding controlling formal is an access
	parameter.
	(Try_Primitive_Operation, Try_Class_Wide_Operation): Diagnose properly
	ambiguous calls in prefixed notation, where two primitives differ only
	in that the controlling argument of one is an access parameter.

	* sem_ch6.adb (Has_Single_Return): Add guard in code that determines
	whether a function that returns an unconstrained type can be inlined.
	(Process_Formals): Diagnose properly the illegal use of an incomplete
	type in the profile of an access_to_subprogram declaration.
	(Check_Synchronized_Overriding): Nothing check for concurrent types, the
	operations are attached to the corresponding record.
	(Analyze_Subprogram_Specification): Add variables Formal and Formal_Typ.
	When processing a primitive of a concurrent type which implements an
	interface change the type of all controlling formals to that of the
	corresponding record type.
	(Check_Synchronized_Overriding): Relax the conditional logic when trying
	to determine the tagged type to which a primitive belongs.
	(Check_Conventions): Capture condition to ignore a primitive operation
	(which is shared between the loop in Check_Conventions and the one in
	Check_Convention) in a new local function Skip_Check.
	(Check_Convention): Rename Prim_Op to Second_Prim_Op to avoid possible
	confusion with Check_Conventions' own Prim_Op local variable.
	(Create_Extra_Formals): Test for a tagged result type rather than a
	controlling result when determining whether to add a BIP_Alloc_Form
	formal and a BIP_Final_List formal to the function.
	(Check_Conformance); For parameters that are anonymous access types,
	subtype conformance requires that the not null and the constant
	indicators must match
	(Check_Synchronized_Overriding): New parameter Formal_Typ. Add machinery
	to retrieve the appropriate type when processing a concurrent type
	declared within a generic. Minor comment reformatting. Change invocation
	of Overrides_Synchronized_Primitive to Find_Overridden_Synchronized_Pri-
	mitive.
	(Analyze_Subprogram_Body): If the return type of a function is an
	anonymous access to the limited view of a class-wide type, and the
	non-limited view of the type is available, update the type of the
	function so that code can be generated.
	(Process_Formals): In case of access-subtype itype whose designated
	type is also an itype (situation that happens now with access to
	subprograms) we mark the access-type itype with the Has_Delayed_Freeze
	attribute to avoid backend problems.
	(Check_Return_Subtype_Indication): Replace R_Type with R_Stm_Type in
	init of R_Stm_Type_Is_Anon_Access. Also check that base types of the
	anonymous types' designated types are same before testing
	Subtypes_Statically_Match.
	(Create_Extra_Formals): Test for a named access parameter that is a
	controlling formal as an additional condition for adding an
	accessibility level formal. This can occur in the subp type created for
	dispatching calls in Expand_Dispatching_Call, and allows calling
	Create_Extra_Formals from that procedure rather than special-casing the
	extra formals there.
	(Create_Extra_Formals): Add BIP_Alloc_Form and BIP_Final_List formals
	when the function has a controlling result.
	(Check_Returns): Add much more knowledge of the optimization of local
	raise statements to gotos, to retain proper warnings in this case.
	(Check_Statement_Sequence): Ignore N_Push_xxx_Label and N_Pop_xxx_Label
	nodes when looking for last statement.

	* sem_type.ads, sem_type.adb (Specific_Type): Add support for
	class-wide types visible through limited with clauses.
	(Add_One_Interp): If the operands are anonymous access types, the
	predefined operator on universal_access is immediately visibles
	(Find_Unique_Type): Handle anonymous access to subprogram types just as
	other anonymous access types.
	(Disambiguate): Take into account CIL convention.
	(Interface_Present_In_Ancestor): Add support for class-wide interfaces.

From-SVN: r125390
parent 109949cd
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
......@@ -167,9 +167,9 @@ package body Sem_Type is
-- multiple interpretations. Interpretations can be added to only one
-- node at a time.
function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
-- If T1 and T2 are compatible, return the one that is not
-- universal or is not a "class" type (any_character, etc).
function Specific_Type (Typ_1, Typ_2 : Entity_Id) return Entity_Id;
-- If Typ_1 and Typ_2 are compatible, return the one that is not universal
-- or is not a "class" type (any_character, etc).
--------------------
-- Add_One_Interp --
......@@ -344,6 +344,7 @@ package body Sem_Type is
or else Nkind (N) = N_Expanded_Name
or else (Nkind (N) in N_Op and then E = Entity (N))
or else In_Instance
or else Ekind (Vis_Type) = E_Anonymous_Access_Type
then
null;
......@@ -1332,9 +1333,9 @@ package body Sem_Type is
elsif Present (Act2)
and then Nkind (Act2) in N_Op
and then Is_Overloaded (Act2)
and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
and then (Nkind (Right_Opnd (Act2)) = N_Integer_Literal
or else
Nkind (Right_Opnd (Act1)) = N_Real_Literal)
Nkind (Right_Opnd (Act2)) = N_Real_Literal)
and then Has_Compatible_Type (Act2, Standard_Boolean)
then
-- The preference rule on the first actual is not
......@@ -1451,6 +1452,19 @@ package body Sem_Type is
end if;
end if;
-- Check for overloaded CIL convention stuff because the CIL libraries
-- do sick things like Console.WriteLine where it matches
-- two different overloads, so just pick the first ???
if Convention (Nam1) = Convention_CIL
and then Convention (Nam2) = Convention_CIL
and then Ekind (Nam1) = Ekind (Nam2)
and then (Ekind (Nam1) = E_Procedure
or else Ekind (Nam1) = E_Function)
then
return It2;
end if;
-- If the context is universal, the predefined operator is preferred.
-- This includes bounds in numeric type declarations, and expressions
-- in type conversions. If no interpretation yields a universal type,
......@@ -1869,14 +1883,19 @@ package body Sem_Type is
-- is no rule in 4.6 that allows "access Integer" to be converted to P.
elsif Ada_Version >= Ada_05
and then Ekind (Etype (L)) = E_Anonymous_Access_Type
and then
(Ekind (Etype (L)) = E_Anonymous_Access_Type
or else
Ekind (Etype (L)) = E_Anonymous_Access_Subprogram_Type)
and then Is_Access_Type (Etype (R))
and then Ekind (Etype (R)) /= E_Access_Type
then
return Etype (L);
elsif Ada_Version >= Ada_05
and then Ekind (Etype (R)) = E_Anonymous_Access_Type
and then
(Ekind (Etype (R)) = E_Anonymous_Access_Type
or else Ekind (Etype (R)) = E_Anonymous_Access_Subprogram_Type)
and then Is_Access_Type (Etype (L))
and then Ekind (Etype (L)) /= E_Access_Type
then
......@@ -2058,17 +2077,22 @@ package body Sem_Type is
Iface : Entity_Id) return Boolean
is
Target_Typ : Entity_Id;
Iface_Typ : Entity_Id;
function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean;
-- Returns True if Typ or some ancestor of Typ implements Iface
-------------------------------
-- Iface_Present_In_Ancestor --
-------------------------------
function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean is
E : Entity_Id;
AI : Entity_Id;
Elmt : Elmt_Id;
begin
if Typ = Iface then
if Typ = Iface_Typ then
return True;
end if;
......@@ -2091,7 +2115,7 @@ package body Sem_Type is
while Present (Elmt) loop
AI := Node (Elmt);
if AI = Iface or else Is_Ancestor (Iface, AI) then
if AI = Iface_Typ or else Is_Ancestor (Iface_Typ, AI) then
return True;
end if;
......@@ -2109,7 +2133,7 @@ package body Sem_Type is
-- Check if the current type is a direct derivation of the
-- interface
if Etype (E) = Iface then
if Etype (E) = Iface_Typ then
return True;
end if;
......@@ -2128,6 +2152,16 @@ package body Sem_Type is
-- Start of processing for Interface_Present_In_Ancestor
begin
if Is_Class_Wide_Type (Iface) then
Iface_Typ := Etype (Iface);
else
Iface_Typ := Iface;
end if;
-- Handle subtypes
Iface_Typ := Base_Type (Iface_Typ);
if Is_Access_Type (Typ) then
Target_Typ := Etype (Directly_Designated_Type (Typ));
else
......@@ -2138,20 +2172,22 @@ package body Sem_Type is
Target_Typ := Corresponding_Concurrent_Type (Target_Typ);
end if;
Target_Typ := Base_Type (Target_Typ);
-- In case of concurrent types we can't use the Corresponding Record_Typ
-- to look for the interface because it is built by the expander (and
-- hence it is not always available). For this reason we traverse the
-- list of interfaces (available in the parent of the concurrent type)
if Is_Concurrent_Type (Target_Typ) then
if Present (Interface_List (Parent (Base_Type (Target_Typ)))) then
if Present (Interface_List (Parent (Target_Typ))) then
declare
AI : Node_Id;
begin
AI := First (Interface_List (Parent (Base_Type (Target_Typ))));
AI := First (Interface_List (Parent (Target_Typ)));
while Present (AI) loop
if Etype (AI) = Iface then
if Etype (AI) = Iface_Typ then
return True;
elsif Present (Abstract_Interfaces (Etype (AI)))
......@@ -2674,7 +2710,9 @@ package body Sem_Type is
-- Specific_Type --
-------------------
function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
function Specific_Type (Typ_1, Typ_2 : Entity_Id) return Entity_Id is
T1 : constant Entity_Id := Available_View (Typ_1);
T2 : constant Entity_Id := Available_View (Typ_2);
B1 : constant Entity_Id := Base_Type (T1);
B2 : constant Entity_Id := Base_Type (T2);
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
......@@ -207,8 +207,9 @@ package Sem_Type is
(Typ : Entity_Id;
Iface : Entity_Id) return Boolean;
-- Ada 2005 (AI-251): Typ must be a tagged record type/subtype and Iface
-- must be an abstract interface type. This function is used to check if
-- Typ or some ancestor of Typ implements Iface.
-- must be an abstract interface type (or a class-wide abstract interface).
-- This function is used to check if Typ or some ancestor of Typ implements
-- Iface (returning True only if so).
function Intersect_Types (L, R : Node_Id) return Entity_Id;
-- Find the common interpretation to two analyzed nodes. If one of the
......
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