[Ada] Better expansion of short-circuit, conditional expressions

Submitted by Arnaud Charlet on June 18, 2010, 10:20 a.m.


Message ID 20100618102056.GA15158@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 18, 2010, 10:20 a.m.
This patch enables use of the new N_Expression_With_Actions node
by default when using the gcc back end. The following test program:

procedure ExprActions (A, B, C : Natural; M, N : String) is
   if (A = 23 and then M (1 .. A) = N (1 .. B))
     or else M (A .. B) = M (B .. C)
   end if;
end ExprActions;

Now generates the following -gnatG output by default (previous to this
patch, this output required the use of the -gnatd.X switch).

procedure expractions (a : natural; b : natural; c : natural; m :
  string; n : string) is
   subtype expractions__S2b is string (n'first(1) .. n'last(1));
   subtype expractions__S1b is string (m'first(1) .. m'last(1));
   if (a = 23 and then
         [constraint_error when
           a >= 1 and then (1 < m'first(1) or else integer(a) > m'last(
           "range check failed"]
         [subtype expractions__T3b is integer range 1 .. a]
         [subtype expractions__T4b is string (expractions__T3b)]
         reference expractions__T4b[constraint_error when
           b >= 1 and then (1 < n'first(1) or else integer(b) > n'last(
           "range check failed"]
         [subtype expractions__T5b is integer range 1 .. b]
         [subtype expractions__T6b is string (expractions__T5b)]
         reference expractions__T6b
      in m (1 .. a) = n (1 .. b) end
   ) or else
         [constraint_error when
           b >= a and then (integer(a) < m'first(1) or else integer(b) >
           "range check failed"]
         [subtype expractions__T7b is integer range a .. b]
         [subtype expractions__T8b is string (expractions__T7b)]
         reference expractions__T8b[constraint_error when
           c >= b and then (integer(b) < m'first(1) or else integer(c) >
           "range check failed"]
         [subtype expractions__T9b is integer range b .. c]
         [subtype expractions__T10b is string (expractions__T9b)]
         reference expractions__T10b
      in m (a .. b) = m (b .. c) end
   end if;
end expractions;

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

2010-06-18  Robert Dewar  <dewar@adacore.com>

	* gnat1drv.adb (Adjust_Global_Switches): Set Use_Expression_With_Actions
	true for gcc.

Patch hide | download patch | download mbox

Index: gnat1drv.adb
--- gnat1drv.adb	(revision 160971)
+++ gnat1drv.adb	(working copy)
@@ -353,11 +353,11 @@  procedure Gnat1drv is
          Use_Expression_With_Actions := False;
-         --  Otherwise normal gcc back end, for now still turn usage off by
-         --  default.
+         --  Otherwise normal gcc back end, which does implement this feature
+         --  so by default we allow its use.
-         Use_Expression_With_Actions := False;
+         Use_Expression_With_Actions := True;
       end if;
       --  Set switch indicating if back end can handle limited types, and