This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] add support for function returning anon access type


Tested on i686-linux, committed on trunk.

In Ada 2005, a function may return an anonymous access type whose
designated type is only visible through a limited_with_clause. This
access type cannot be elaborated until the context includes a regular
with_clause on the defining package. In that sense such anonymous types
are akin to Taft Amendment types, and they must be handled within the
package body that typically will include the required with_clause. In
addition, these anonymous types must be elaborated in their scope of
definition, and not in a nested scope (such as within another subprogram
body). Therefore, itype references for them must be created before the
rest of the package body is analyzed.

 The following must compile quietly:

 gcc -c -gnat05 p2.adb

package P1 is
   type T1 is abstract tagged limited null record;
--
   function F (Self : not null access T1) return access T1'Class
     is abstract;
end P1;
--
with P1;
limited with P3;
package P2 is
   type T2 is abstract new P1.T1 with private;
--
   function F (Self : not null access T2) return access P1.T1'Class;
--
   function G (Self : not null access T2) return access P3.T3'Class
      is abstract;
private
   type T2 is abstract new P1.T1 with null record;
end P2;
--
with P2;
package P3 is
   type T3 is abstract new P2.T2 with null record;
end P3;
--
with P3;
package body P2 is
   type T2_Access is access all T2'Class;
--
   function F (Self : not null access T2) return access P1.T1'Class is
   begin
      return T2_Access (Self).G;
   end F;
end P2;

This patch fixes also a problem associated with the management of private
overridings. After this patch the execution of the following test
is correct.
--
package P is
   type I is interface;
   procedure A (X : I) is abstract;
   type T is new I with private;
   procedure A (X : T);
private
   type T is new I with null record;
   procedure B (X : T);
end;
package P.C is
   type U is new T with private;
private
   type U is new T with null record;
   overriding procedure B (X : U);
end;
package body P is
   procedure A (X : T) is
   begin
      B (T'Class (X)); -- redispatch
   end;
   procedure B (X : T) is
   begin
      raise Program_Error;
   end;
end;
package body P.C is
   procedure B (X : U) is
   begin
      null;  --  OK
   end;
end;
with P.C;
procedure Q is
   A_U : P.C.U;
begin
   A_U.A;
end;
--
Command: gnatmake -gnat05 q.adb

2006-10-31  Ed Schonberg  <schonberg@adacore.com>
	    Javier Miranda  <miranda@adacore.com>

	* sem_ch7.adb (Check_Anonymous_Access_Types): New procedure, subsidiary
	of Analyze_Package_Body, to create Itype references for anonymous
	access types created in the package declaration, whose designated types
	may have only a limited view.
	(Analyze_Package_Specification): For the private part of a nested
	package, install private_with_clauses of enclosing compilation unit if
	we are in its visible part.
	(Declare_Inherited_Private_Subprograms): Complete barrier
	to ensure that the primitive operation has an alias to some parent
	primitive. This is now required because, after the changes done for the
	implementation of abstract interfaces, the contents of the list of
	primitives has entities whose alias attribute references entities of
	such list of primitives.
	(Analyze_Package_Specification): Simplify code that handles parent units
	of instances and formal packages.
	(Uninstall_Declarations): Check the convention consistency among
	primitive overriding operations of a tagged record type.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]