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] Itype references for anonymous access return type.


In general itypes are elaborated by the back-end at the point of use. In some
cases the point of use may appear in a scope nested within the scope of
definition, and in that case we must inssrt an itype_reference node to force
gigi to elaborate the type earlier. Postconditions are another context in
which the first reference may appear nested within the defining context; for
the postcondition procedure we create an internal _Result variable to capture
the value of the function before return. The declaration for _result will force
the elaboration of the anonymous return type out of scope unless there is a
previous reference in the proper scope.

The following must compile quietly:

   gcc -c -gnata -gnat05 instance_singleton.ads

---
with Singleton;
pragma elaborate_all (singleton);
package instance_singleton is
   type t_item is tagged null record;

   procedure initialize (item : in out t_item'class) is null;

   package mon_singleton is new singleton (t_item, initialize);
end instance_singleton;
---
generic
   type T_Item is tagged limited private;
   with procedure Initialize (Item : in out T_Item'Class);
package Singleton is
   pragma Elaborate_Body;
   function Instance_Of return access T_Item;
private
   Instance : access T_Item;
end Singleton;
---
package body Singleton is

   function Instance_Of return access T_Item is
      pragma Postcondition (Instance /= null);
   begin
      return Instance;
   end Instance_Of;

begin
   Instance := new T_Item;
   Initialize (Instance.all);
end Singleton;

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

2008-08-04  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Access_Definition): Create an itype reference for an
	anonymous access return type of a regular function that is not a
	compilation unit.

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]