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] Write Itype values in dg listing


Tested on i686-linux, committed on trunk

This patch implements handling of record types in the new routine to
write output Itype values. There are two cases, with and without an
explicitly built declaration. Both are now handled.

A test program is:

with Ada.Text_IO; use Ada.Text_IO;
package body Pak2 is
   function F (Whence : Day) return Pak1.Ptr is
   begin
      return new Derived_Data'(Whence => Whence, X => 123);
   end F;
   X : Pak1.Ptr;
   Y : aliased Derived_Data := (Whence => Sun, X => 456);
begin
   Put_Line ("From function return:");
   X := F (Wed);
   if X.Kind'Valid then
      Put_Line ("X.Kind = " & X.Kind'Img);
   else
      Put_Line ("X.Kind has invalid representation");
   end if;
   Put_Line ("From aliased initialized object:");
   X := Y'Access;
   if X.Kind'Valid then
      Put_Line ("X.Kind = " & X.Kind'Img);
   else
      Put_Line ("X.Kind has invalid representation");
   end if;
end Pak2;

This patch also implements an enhancement to the output of reconstructed
expanded source listings (-gnatD/G switch output). This output now
includes a representation of itypes (internally generated types for
which no type declaration is present in the tree). A test program is

procedure Q is
   R : String (1 .. 10);
   type H is new String (1 .. 10);
   type HH is access H;
   HHH : HH;
begin
   R (1 .. 5) := R (6 .. 10);
   HHH := new H'("Abcdeabcde");
end;

which, compiled with -gnatG -gnatws, generates:

Source recreated from tree for Q (body)
---------------------------------------


procedure q is
   subtype q__TrS is string (1 .. 10);
   r : string (1 .. 10);
   [type q__ThB is array (positive range <>) of character]
   subtype q__h is q__ThB (1 .. 10);
   type q__hh is access q__h;
   hhh : q__hh := null;
begin
   r ({1 .. 5}) := r ({6 .. 10});
   hhh := new q__h'("Abcdeabcde");
   return;
end q;

Here the line listing q__ThB is the new output

Protected types that have interface progenitors are tagged types, but
they are not limited records, so a separate check must be made to allow
private components that are themselves limited.
the following must compile quietly:
gcc -c -gnatc -gnat05 p-c.ads
--
package P is
    type Timer is synchronized interface;
    procedure Await_Alarm (This : in out Timer) is abstract;
end P;
--
package P.C is
    type L is limited null record;
    protected type Alarm is new Timer with
       overriding entry Await_Alarm;
    private
       X : L;  -- compiler complains about this decl
    end Alarm;
end P.C;

If the parent of the full-view is an interface we perform a transformation
of the tree to ensure that it has the same parent than the partial-view.
This work is needed because the list of interfaces of the full-view can
be given in any order. After this change the following test must compile
without errors:
--
procedure do_test is
  package Pkg is
     type A is interface;
     type B is interface and A;
     type D is new B with private;
  private
     type D is new A and B with null record;
  end Pkg;
--
begin
   null;
end do_test;

2005-12-05  Robert Dewar  <dewar@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>
	    Javier Miranda  <miranda@adacore.com>
	    Hristian Kirtchev  <kirtchev@adacore.com>

	* einfo.adb (Itype_Printed): New flag
	(Is_Limited_Type): Derived types do not inherit limitedness from
	interface progenitors.
	(Is_Return_By_Reference_Type): Predicate does not apply to limited
	interfaces.

	* einfo.ads (Itype_Printed): New flag
	Move Is_Wrapper_Package to proper section
	Add missing Inline for Is_Volatile

	* output.ads, output.adb (Write_Erase_Char): New procedure
	(Save/Restore_Output_Buffer): New procedures
	(Save/Restore_Output_Buffer): New procedures

	* sprint.ads, sprint.adb (Write_Itype): Handle case of record itypes
	Add missing support for anonymous access type
	(Write_Id): Insert calls to Write_Itype
	(Write_Itype): New procedure to output itypes

	* par-ch12.adb (P_Formal_Derived_Type_Definition): In Ada 2005, handle
	use of "limited" in declaration.

	* sinfo.ads, sinfo.adb: 
	Formal derived types can carry an explicit "limited" indication.

	* sem_ch3.adb: Add with and use of Targparm.
	(Create_Component): If Frontend_Layout_On_Target is True and the
	copied component does not have a known static Esize, then reset
	the size and positional fields of the new component.
	(Analyze_Component_Declaration): A limited component is
	legal within a protected type that implements an interface.
	(Collect_Interfaces): Do not add to the list the interfaces that
	are implemented by the ancestors.
	(Derived_Type_Declaration): If the parent of the full-view is an
	interface perform a transformation of the tree to ensure that it has
	the same parent than the partial-view. This simplifies the job of the
	expander in order to generate the correct object layout, and it is
	needed because the list of interfaces of the full-view can be given in
	any order.
	(Process_Full_View): The parent of the full-view does not need to be
	a descendant of the parent of the partial view if both parents are
	interfaces.
	(Analyze_Private_Extension_Declaration): If declaration has an explicit
	"limited" the parent must be a limited type.
	(Build_Derived_Record_Type): A derived type that is explicitly limited
	must have limited ancestor and progenitors.
	(Build_Derived_Type): Ditto.
	(Process_Full_View): Verify that explicit uses of "limited" in partial
	and full declarations are consistent.
	(Find_Ancestor_Interface): Remove function.
	(Collect_Implemented_Interfaces): New procedure used to gather all
	implemented interfaces by a type.
	(Contain_Interface): New function used to check whether an interface is
	present in a list.
	(Find_Hidden_Interface): New function used to determine whether two
	lists of interfaces constitute a set equality. If not, the first
	differing interface is returned.
	(Process_Full_View): Improve the check for the "no hidden interface"
	rule as defined by AI-396.

Attachment: difs.15
Description: Text document


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