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] The GNAT attribute 'Img can be renamed as a function.


This patch treats the GNAT-specific 'Img attribute as a callable entity which
therefore can be renamed as a function.  The prefix of the attribute reference
is an object rather than a subtype, and it is not evaluated at the point of the
renaming declaration.

Executing the following :

   gnatmake -q inst
   inst

must yield:

    12345
    456
   F2 =  456, Flag = TRUE
   F2 =  789, Flag = FALSE

---
with Text_IO; use Text_IO;
procedure Inst is
   generic
      with function F return String;
   procedure Gen;
   procedure Gen is begin
      Put_Line (F);
   end Gen;

   V : Integer;
   procedure Inst_Img is new Gen (V'Img);

   Table : array (Boolean) of Integer := (123, 456);
   Flag : Boolean := False;
   
   function F2 return String;
   function F2 return String renames Table(Flag)'Img;

begin
   V := 12345;
   Inst_Img;

   Table (False) := 789;
   Flag := True;

   Put_Line (Table (Flag)'Img);
   Put_Line ("F2 = " & F2 & ", Flag = " & Boolean'Image (Flag));

   Flag := False;
   Put_Line ("F2 = " & F2 & ", Flag = " & Boolean'Image (Flag));
end Inst;

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

2013-07-08  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch8.adb (Attribute_Renaming): Treat 'Img as an attribute
	that can be renamed as a function.

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]