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] Improve support class-wide interface conversions in .NET


This patch improves the support for interface conversions in the .NET/JVM
compiler extending the current support for attribute 'tag and adding the
missing runtime checks required in interface conversions when the tag of
the source is unknown at compile time. After this patch the following test
compiles and executes well.

with GNAT.IO; use GNAT.IO;
procedure Main is
   package Pkg is
      type Iface is interface;
      procedure Print (Obj : in out Iface) is abstract;

      type Parent is tagged record
         Id : Natural := 1;
      end record;

      type Child is new Parent and Iface with null record;
      procedure Print (Obj : in out Child);

      function New_Child return Iface'Class;
   end Pkg;

   package body Pkg is
      procedure Print (Obj : in out Child) is
      begin
         Put_Line ("child" & Obj.Id'Img);
      end Print;

      function New_Child return Iface'Class is
      begin
         return Obj : Child do
            Obj.Id := 3;
         end return;
      end New_Child;
   end Pkg;
   use Pkg;
   
   C : Iface'Class  := New_Child;
begin
   Print (C);
end Main;

Command: dotnet-gnatmake -gnat05 main; ./main.exe
 Output: child 3

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-04  Javier Miranda  <miranda@adacore.com>

	* exp_ch7.adb (Expand_N_Package_Body, Expand_N_Package_Declaration):
	Remove code which takes care of building TSDs.
	* rtsfind.ads (RE_Check_Interface_Conversion): New entity.
	* exp_ch4.adb (Apply_Accessibility_Check): Add support for generating
	the accessibility check in VM targets.
	* exp_disp.adb (Make_VM_TSD): Spec moved to exp_disp.ads
	(Building_Static_DT): Now returns false for VM targets.
	(Build_VM_TSDs): Removed.
	(Expand_Interface_Conversion): Generate missing runtime check for
	conversions to interface types whose target type is unknown at compile
	time.
	(Make_VM_TSD): Add missing code to disable the generation of calls to
	Check_TSD if the tagged type is not defined at library level, or not
	has a representation clause specifying its external tag, or -gnatdQ is
	active.
	* exp_disp.ads (Build_VM_TSDs): Removed.
	(Make_VM_TSDs): Spec relocated from exp_disp.adb
	* sem_disp.adb (Check_Dispatching_Operation): No code required to
	register primitives in the dispatch tables in VM targets.
	* exp_ch3.adb (Expand_N_Object_Declaration): Remove wrong expansion of
	initialization of class-wide interface objects in VM targets.
	(Expand_Freeze_Record_Type): For VM targets call Make_VM_TSD (instead
	of Make_DT).

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]