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] AI-286, 395 and PR 10671


Tested on i686-linux, committed on mainline.

Ada 2005 AI-286 adds pragma Assert and Assertion_Policy, for details
see www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00286.TXT?rev=1.19
For assert, the only change is to allow pragma argument identifiers
(Check, Message) and also this is no longer a GNAT pragma. Pragma
Assertion_Policy is new for GNAT.

The following set of test files can be used

with Q;
procedure P is
   M : Integer := 5;
begin
   null;
   pragma Assert (Check => M = 6, Message => "M is not 6");
end;
package Q is
   X : Integer := 3;
   pragma Assert (Check => X = 4);
end Q;
pragma Assertion_Policy (Check);
with Q;
procedure R is
   M : Integer := 5;
begin
   null;
   pragma Assert (Check => M = 6, Message => "M is not 6");
end;
pragma Assertion_Policy (Ignore);
procedure S is
   M : Integer := 5;
begin
   null;
   pragma Assert (Check => M = 6, Message => "M is not 6");
end;
And finally a gnat.adc file with one line:
pragma Assertion_Policy (Check);
The following test script:
gnatmake -f -q p
p
gnatmake -f -q -gnatA p
p
gnatmake -f -q -gnatA -gnata p
p
gnatmake -f -q r
r
gnatmake -f -q s -gnata
s
will generate the output:
--
p.adb:6:04: warning: assertion will fail at run-time
q.ads:3:04: warning: assertion will fail at run-time

raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : q.ads:3
p.adb:6:04: warning: assertion will fail at run-time
q.ads:3:04: warning: assertion will fail at run-time

raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : q.ads:3
r.adb:7:04: warning: assertion will fail at run-time
q.ads:3:04: warning: assertion will fail at run-time

raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : q.ads:3
--
Ada 2005 AI-395 introduces the notion of subprograms that become
obsolescent in Ada 2005, but are fine in Ada 95. These are some
functions in Ada.Characters.Handling that are moved now to
Ada.Characters.Conversions, a new package. We need a mechanism
for flagging these as obsolescent only in Ada 2005 mode. To do
this we have chosen to extend the GNAT pragma Obsolescent with
a second argument, Ada_05, which is present means that the pragma
is only active in Ada 2005 mode.

A test program is:

procedure K is
   procedure R;
   pragma Obsolescent ("(Ada 2005) use mumble instead", Ada_05);
   procedure R is begin null; end;
begin
   R;
end;

which compiles silently in Ada 95 mode even if -gnatwj is used, but
in Ada 2005 mode (-gnat05) with -gnatj, generates the warning:

k.adb:6:04: warning: call to obsolescent subprogram "R"
k.adb:6:04: warning: (Ada 2005) use mumble instead

--
Fix also PR ada/10671
These changes are error message enhancements that address PR 10671.
This PR is actually written as a bug report, which comes from the
incorrect expectation that the use of pragma argument identifiers
in pragmas allows arbitrary ordering of parameters as in subprogram
calls. Although this certainly seems a reasonable assumption (e.g.
encouraged by the rule in RM 2.4(8) see also PR 15613), it is not
in fact the case. Arguments must be in strict sequence, regardless
of the use of identifiers. This is true of all RM defined pragmas,
and generally we follow this lead for GNAT defined pragmas (the
exception being for the DEC pragmas which always allowed reordering
based on the identifier names).

So in fact the error message reported in PR 10671 is not incorrect,
but it is certainly not as helpful as it could be, and this patch
improves the error messages, as shown by the example in the PR:

procedure Btest is
   procedure Boot;
   pragma Machine_Attribute
     (Attribute_Name => "section ("".bootloader"")",
      Entity => Boot);

   procedure Boot is
   begin
      null;
   end;
begin
   null;
end;

which now generates the error messages:

btest.adb:5:07: parameters out of order for pragma "Machine_Attribute"
btest.adb:5:07: "Entity" must appear before "Attribute_Name"

2005-06-14  Robert Dewar  <dewar@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>

	PR ada/10671

	* sem_prag.adb: Implement pragma Persistent_BSS
	Remove obsolete pragma Persistent_Data, Persistent_Object
	Set Ada_Version_Explicit, for implementation of AI-362
	Test Ada_Version_Explicit for Preelaborate_05 and Pure_05
	Add processing for pragma Pure_05 and Preelaborate_05
	Add processing for Assertion_Policy pragma
	Add pragma identifiers for Assert
	(Analyze_Pragma, case Assert): Check number of arguments
	(Process_Inline): Additional guard against an illegal program, where the
	argument of the pragma is undefined, and warnings on redundant
	constructs are enabled.
	(Analyze_Pragma, case Obsolescent): Allow an optional second argument
	Ada_05 to this pragma, specifying that the pragma is only active in
	Ada_05 mode.
	(Check_Arg_Order): New procedure
	Add appropriate calls to this procedure throughout
	Also throughout, check entity name before doing any other checks

	* snames.h snames.ads, snames.adb: Add pragma Persistent_BSS
	Remove obsolete pragma Persistent_Data, Persistent_Object
	Add entries for pragma Pure_05 and Preelaborate_05
	Add entries for Assertion_Policy pragma and associated names
	Add some names for pragma argument processing

	* tbuild.ads, tbuild.adb: (Make_Linker_Section_Pragma): New function

Attachment: difs.49
Description: Text document


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