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 non-classwide Pre/Post aspects


This patch completes the implementation of the non-classwide versions
of the Pre/Post aspects. The following shows a simple test:

with Text_IO; use Text_IO;
procedure prepost is
   function F (X : Integer) return Integer with
   Pre  => X > 10,
   Post => F'Result = X + 1;

   function F (X : Integer) return Integer is
   begin
      if X = 13 then
         return X;
      else
         return X + 1;
      end if;
   end F;


begin
   Put_Line (F (11)'Img);

   begin
      Put_Line (F (10)'Img);
   exception
      when others =>
         Put_Line ("precondition fails");
   end;

   begin
      Put_Line (F (13)'Img);
   exception
      when others =>
         Put_Line ("postcondition fails");
   end;
end;

Compiled and run with -gnat12 -gnata, the output is:

 12
precondition fails
postcondition fails

The following test shows some error messages given now:

     1. package PrePostErr is
     2.    procedure P1 is abstract with
     3.      Pre  => True,
             |
        >>> aspect "Pre" requires 'Class for abstract subprogram

     4.      Post => False;
             |
        >>> aspect "Post" requires 'Class for abstract subprogram

     5.
     6.    procedure P2 is abstract;
     7.    pragma Precondition (True);
           |
        >>> pragma "Precondition" cannot be applied to abstract subprogram

     8.    pragma Postcondition (False);
           |
        >>> pragma "Postcondition" cannot be applied to abstract subprogram

     9.
    10.    procedure P3 with
    11.      Pre  => True,
    12.      Post => False;
    13.    pragma Precondition (True);
           |
        >>> pragma "Precondition" not allowed, "Pre" aspect given at line 11

    14.    pragma Postcondition (False);
           |
        >>> pragma "Postcondition" not allowed, "Post" aspect given at line 12

    15. end PrePostErr;

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

2010-10-12  Robert Dewar  <dewar@adacore.com>

	* par-ch13.adb (P_Aspect_Specifications): Fix handling of 'Class aspects
	* sem_ch13.adb (Analyze_Aspect_Specifications): Fix bad Sloc on aspects
	* sem_prag.adb (Fix_Error): Only change pragma names for pragmas from
	aspects.
	(Check_Optional_Identifier): Handle case of direct arguments
	(Chain_PPC): Test for abstract case, giving appropriate messages
	* sinfo.ads, sinfo.adb (Class_Present): Allowed on N_Pragma node

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]