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] Implement new attribute Library_Level


This implements a new attribute Standard'Library_Level (Standard is
the only allowed prefix), which returns a Boolean value which is True
if the attribute is evaluated at the library level (e.g. with a package
declaration), and false if evaluated elsewhere (e.g. within a subprogram
body). In the case of generics, the value indicates the placement
of the instantiation, not the template, and indeed the use of this
attribute within a generic is the intended common application
as shown in this example:

     1. generic
     2. package LLTestP is
     3.    pragma Compile_Time_Warning
     4.      (not Standard'Library_Level,
     5.       "LLTest should be instantiated at library level");
     6. end;

     1. with LLTestP;
     2. package LLTestP1 is
     3.    package P is new LLTestP;
     4.    P1L : constant Boolean := Standard'Library_Level;
     5. end;

     1. with LLTestP;
     2. with LLTestP1; use LLTestP1;
     3. with Text_IO; use Text_IO;
     4. procedure LLTest is
     5.    package P1 is new LLTestP;
           |
        >>> warning: in instantiation at lltestp.ads:4
        >>> warning: LLTest should be instantiated at library level

     6. begin
     7.    Put_Line (Boolean'Image (Standard'Library_Level));
     8.    Put_Line (Boolean'Image (P1L));
     9. end;

When run, LLTest outputs:

FALSE
TRUE

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

2013-10-14  Robert Dewar  <dewar@adacore.com>

	* exp_attr.adb (Expand_N_Attribute_Reference): Add error
	entry for Library_Level attribute (which should not survive
	to expansion)
	* gnat_rm.texi: Document attribute Library_Level
	* sem_attr.adb (Analyze_Attribute, case Library_Level): Implement
	this new attribute (Set_Boolean_Result): Replaces Set_Result
	(Check_Standard_Prefix): Document that Check_E0 is called
	(Check_System_Prefix): New procedure
	* snames.ads-tmpl: Add entry for Library_Level attribute

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]