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] New -gnatyB switch, check Boolean short circuit ops


This style switch implements the GNAT style rule for use of boolean
operators. This rule requires use of AND THEN/OR ELSE rather than
AND/OR in all contexts except modular types, array types, and simple
stand-lone boolean variables and constants.

The following example is compiled with -gnatld7 -gnatyB -gnatws

     1. procedure checkandor is
     2.    A, B : Boolean;
     3.    type R is array (1 .. 16) of Boolean;
     4.    RA1, RA2 : R;
     5.    type M is mod 2 ** 32;
     6.    M1, M2 : M;
     7. begin
     8.    if (M1 AND M2) = 0 then null; end if;
     9.    RA1 := RA1 and RA2;
    10.    if A = B then null; end if;
    11.    if M1 > 3 AND M2 < 10 then null; end if;
                     |
        >>> (style) "and then" required

    12.    if M1 > 4 or M2 > 10 then null; end if;
                     |
        >>> (style) "or else" required

    13. end;

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

2009-07-22  Robert Dewar  <dewar@adacore.com>

	* sem_res.adb (Check_No_Direct_Boolean_Operators): Add check for -gnatyB
	* style.ads, styleg.adb, styleg.ads (Check_Boolean_Operator): New
	procedure.
	* usage.adb, stylesw.ads, stylesw.adb: Add handling of -gnatyB switch
	* gnat_ugn.texi: Add documentation of -gnatyB
	* vms_data.ads: Add entry for -gnatyB (STYLE=BOOLEAN_OPERATORS)

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]