summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gnat.dg/opt1.adb
blob: 69bb8136d04b5fa8826a492800ec4f27851acde2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- { dg-do compile }
-- { dg-options "-O -gnatws" }

package body Opt1 is

   function De_Linear_Index
     (Index       : Natural;
      D           : Natural;
      Ind_Lengths : Dimention_Length)
      return        Dimension_Indexes
   is
      Len     : Natural := 1;
      Tmp_Ind : Natural := Index;
      Tmp_Res : Natural;
      Result  : Dimension_Indexes (1 .. D);
   begin
      for J in 1 .. D loop
         Len := Len * Ind_Lengths (J);
      end loop;

      for J in Result'Range loop
         Result (J) := Tmp_Res;
         Tmp_Ind := Tmp_Ind - Len * (Result (J) - 1);
      end loop;

      return Result;
   end;

end Opt1;