aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/s-gearop.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2012-03-07 15:45:51 +0100
committerArnaud Charlet <charlet@gcc.gnu.org>2012-03-07 15:45:51 +0100
commite761d11c7d31ef7adc8b58865fe7627d154cec3e (patch)
tree547ce03558b4baf7b4fb08c1682c061d275f1ccc /gcc/ada/s-gearop.adb
parent62db841a08b9e833bd30e5fe7d8de00d5a250b74 (diff)
downloadgcc-e761d11c7d31ef7adc8b58865fe7627d154cec3e.zip
gcc-e761d11c7d31ef7adc8b58865fe7627d154cec3e.tar.gz
gcc-e761d11c7d31ef7adc8b58865fe7627d154cec3e.tar.bz2
[multiple changes]
2012-03-07 Gary Dismukes <dismukes@adacore.com> * exp_ch4.adb (Apply_Accessibility_Check): Call Remove_Side_Effects in the build-in-place case, to ensure that we capture the call and don't end up with two calls. 2012-03-07 Javier Miranda <miranda@adacore.com> * exp_ch6.adb (Expand_Inlined_Call): Skip inlining of functions that return unconstrained types using an extended return statement since the support for inlining these functions has not been yet added to the frontend. * s-vaflop.adb, s-vaflop-vms-alpha.adb: Code reorganization. * a-ngrear.ads: Replace all the Inline_Always pragmas by pragma Inline. * a-ngrear.adb (Eigenvalues, Transpose): Restructured to use extended return statement. * a-strsup.adb, a-stzsup.adb, a-stwisu.adb (Concat, Super_Slice, Super_To_String): Restructured to use extended return statement. * a-chahan.adb (To_Basic, To_Lower, To_Upper): Restructured to use extended return statement. * s-gearop.adb (Diagonal, Matrix_Elementwise_Operation, Vector_Elementwise_Operation, Matrix_Elementwise_Operation, Matrix_Matrix_Scalar_Elementwise_Operation, Vector_Vector_Elementwise_Operation, Vector_Vector_Scalar_Elementwise_Operation, Matrix_Scalar_Elementwise_Operation, Vector_Scalar_Elementwise_Operation, Scalar_Matrix_Elementwise_Operation, Scalar_Vector_Elementwise_Operation, Matrix_Matrix_Product, Matrix_Vector_Product, Outer_Product, Unit_Matrix, Unit_Vector, Vector_Matrix_Product): Restructured to use extended return statement. 2012-03-07 Vincent Pucci <pucci@adacore.com> * sem_ch5.adb (One_Bound): Minor reformatting. 2012-03-07 Tristan Gingold <gingold@adacore.com> * s-osinte-vms-ia64.adb, s-osinte-vms-ia64.ads, s-osinte-vms.adb, s-osinte-vms.ads, gcc-interface/Makefile.in: Merge s-osinte-vms and s-osinte-vms-ia64. From-SVN: r185051
Diffstat (limited to 'gcc/ada/s-gearop.adb')
-rw-r--r--gcc/ada/s-gearop.adb356
1 files changed, 163 insertions, 193 deletions
diff --git a/gcc/ada/s-gearop.adb b/gcc/ada/s-gearop.adb
index db18a7e..3d9e4bf 100644
--- a/gcc/ada/s-gearop.adb
+++ b/gcc/ada/s-gearop.adb
@@ -51,14 +51,12 @@ package body System.Generic_Array_Operations is
function Diagonal (A : Matrix) return Vector is
N : constant Natural := Natural'Min (A'Length (1), A'Length (2));
- R : Vector (A'First (1) .. A'First (1) + N - 1);
-
begin
- for J in 0 .. N - 1 loop
- R (R'First + J) := A (A'First (1) + J, A'First (2) + J);
- end loop;
-
- return R;
+ return R : Vector (A'First (1) .. A'First (1) + N - 1) do
+ for J in 0 .. N - 1 loop
+ R (R'First + J) := A (A'First (1) + J, A'First (2) + J);
+ end loop;
+ end return;
end Diagonal;
--------------------------
@@ -386,16 +384,14 @@ package body System.Generic_Array_Operations is
----------------------------------
function Matrix_Elementwise_Operation (X : X_Matrix) return Result_Matrix is
- R : Result_Matrix (X'Range (1), X'Range (2));
-
begin
- for J in R'Range (1) loop
- for K in R'Range (2) loop
- R (J, K) := Operation (X (J, K));
+ return R : Result_Matrix (X'Range (1), X'Range (2)) do
+ for J in R'Range (1) loop
+ for K in R'Range (2) loop
+ R (J, K) := Operation (X (J, K));
+ end loop;
end loop;
- end loop;
-
- return R;
+ end return;
end Matrix_Elementwise_Operation;
----------------------------------
@@ -403,14 +399,12 @@ package body System.Generic_Array_Operations is
----------------------------------
function Vector_Elementwise_Operation (X : X_Vector) return Result_Vector is
- R : Result_Vector (X'Range);
-
begin
- for J in R'Range loop
- R (J) := Operation (X (J));
- end loop;
-
- return R;
+ return R : Result_Vector (X'Range) do
+ for J in R'Range loop
+ R (J) := Operation (X (J));
+ end loop;
+ end return;
end Vector_Elementwise_Operation;
-----------------------------------------
@@ -421,29 +415,27 @@ package body System.Generic_Array_Operations is
(Left : Left_Matrix;
Right : Right_Matrix) return Result_Matrix
is
- R : Result_Matrix (Left'Range (1), Left'Range (2));
-
begin
- if Left'Length (1) /= Right'Length (1)
+ return R : Result_Matrix (Left'Range (1), Left'Range (2)) do
+ if Left'Length (1) /= Right'Length (1)
or else
- Left'Length (2) /= Right'Length (2)
- then
- raise Constraint_Error with
- "matrices are of different dimension in elementwise operation";
- end if;
+ Left'Length (2) /= Right'Length (2)
+ then
+ raise Constraint_Error with
+ "matrices are of different dimension in elementwise operation";
+ end if;
- for J in R'Range (1) loop
- for K in R'Range (2) loop
- R (J, K) :=
- Operation
- (Left (J, K),
- Right
- (J - R'First (1) + Right'First (1),
- K - R'First (2) + Right'First (2)));
+ for J in R'Range (1) loop
+ for K in R'Range (2) loop
+ R (J, K) :=
+ Operation
+ (Left (J, K),
+ Right
+ (J - R'First (1) + Right'First (1),
+ K - R'First (2) + Right'First (2)));
+ end loop;
end loop;
- end loop;
-
- return R;
+ end return;
end Matrix_Matrix_Elementwise_Operation;
------------------------------------------------
@@ -453,31 +445,28 @@ package body System.Generic_Array_Operations is
function Matrix_Matrix_Scalar_Elementwise_Operation
(X : X_Matrix;
Y : Y_Matrix;
- Z : Z_Scalar) return Result_Matrix
- is
- R : Result_Matrix (X'Range (1), X'Range (2));
-
+ Z : Z_Scalar) return Result_Matrix is
begin
- if X'Length (1) /= Y'Length (1)
+ return R : Result_Matrix (X'Range (1), X'Range (2)) do
+ if X'Length (1) /= Y'Length (1)
or else
- X'Length (2) /= Y'Length (2)
- then
- raise Constraint_Error with
- "matrices are of different dimension in elementwise operation";
- end if;
+ X'Length (2) /= Y'Length (2)
+ then
+ raise Constraint_Error with
+ "matrices are of different dimension in elementwise operation";
+ end if;
- for J in R'Range (1) loop
- for K in R'Range (2) loop
- R (J, K) :=
- Operation
- (X (J, K),
- Y (J - R'First (1) + Y'First (1),
- K - R'First (2) + Y'First (2)),
- Z);
+ for J in R'Range (1) loop
+ for K in R'Range (2) loop
+ R (J, K) :=
+ Operation
+ (X (J, K),
+ Y (J - R'First (1) + Y'First (1),
+ K - R'First (2) + Y'First (2)),
+ Z);
+ end loop;
end loop;
- end loop;
-
- return R;
+ end return;
end Matrix_Matrix_Scalar_Elementwise_Operation;
-----------------------------------------
@@ -488,19 +477,17 @@ package body System.Generic_Array_Operations is
(Left : Left_Vector;
Right : Right_Vector) return Result_Vector
is
- R : Result_Vector (Left'Range);
-
begin
- if Left'Length /= Right'Length then
- raise Constraint_Error with
- "vectors are of different length in elementwise operation";
- end if;
-
- for J in R'Range loop
- R (J) := Operation (Left (J), Right (J - R'First + Right'First));
- end loop;
+ return R : Result_Vector (Left'Range) do
+ if Left'Length /= Right'Length then
+ raise Constraint_Error with
+ "vectors are of different length in elementwise operation";
+ end if;
- return R;
+ for J in R'Range loop
+ R (J) := Operation (Left (J), Right (J - R'First + Right'First));
+ end loop;
+ end return;
end Vector_Vector_Elementwise_Operation;
------------------------------------------------
@@ -510,21 +497,18 @@ package body System.Generic_Array_Operations is
function Vector_Vector_Scalar_Elementwise_Operation
(X : X_Vector;
Y : Y_Vector;
- Z : Z_Scalar) return Result_Vector
- is
- R : Result_Vector (X'Range);
-
+ Z : Z_Scalar) return Result_Vector is
begin
- if X'Length /= Y'Length then
- raise Constraint_Error with
- "vectors are of different length in elementwise operation";
- end if;
-
- for J in R'Range loop
- R (J) := Operation (X (J), Y (J - X'First + Y'First), Z);
- end loop;
+ return R : Result_Vector (X'Range) do
+ if X'Length /= Y'Length then
+ raise Constraint_Error with
+ "vectors are of different length in elementwise operation";
+ end if;
- return R;
+ for J in R'Range loop
+ R (J) := Operation (X (J), Y (J - X'First + Y'First), Z);
+ end loop;
+ end return;
end Vector_Vector_Scalar_Elementwise_Operation;
-----------------------------------------
@@ -535,16 +519,14 @@ package body System.Generic_Array_Operations is
(Left : Left_Matrix;
Right : Right_Scalar) return Result_Matrix
is
- R : Result_Matrix (Left'Range (1), Left'Range (2));
-
begin
- for J in R'Range (1) loop
- for K in R'Range (2) loop
- R (J, K) := Operation (Left (J, K), Right);
+ return R : Result_Matrix (Left'Range (1), Left'Range (2)) do
+ for J in R'Range (1) loop
+ for K in R'Range (2) loop
+ R (J, K) := Operation (Left (J, K), Right);
+ end loop;
end loop;
- end loop;
-
- return R;
+ end return;
end Matrix_Scalar_Elementwise_Operation;
-----------------------------------------
@@ -555,14 +537,12 @@ package body System.Generic_Array_Operations is
(Left : Left_Vector;
Right : Right_Scalar) return Result_Vector
is
- R : Result_Vector (Left'Range);
-
begin
- for J in R'Range loop
- R (J) := Operation (Left (J), Right);
- end loop;
-
- return R;
+ return R : Result_Vector (Left'Range) do
+ for J in R'Range loop
+ R (J) := Operation (Left (J), Right);
+ end loop;
+ end return;
end Vector_Scalar_Elementwise_Operation;
-----------------------------------------
@@ -573,16 +553,14 @@ package body System.Generic_Array_Operations is
(Left : Left_Scalar;
Right : Right_Matrix) return Result_Matrix
is
- R : Result_Matrix (Right'Range (1), Right'Range (2));
-
begin
- for J in R'Range (1) loop
- for K in R'Range (2) loop
- R (J, K) := Operation (Left, Right (J, K));
+ return R : Result_Matrix (Right'Range (1), Right'Range (2)) do
+ for J in R'Range (1) loop
+ for K in R'Range (2) loop
+ R (J, K) := Operation (Left, Right (J, K));
+ end loop;
end loop;
- end loop;
-
- return R;
+ end return;
end Scalar_Matrix_Elementwise_Operation;
-----------------------------------------
@@ -593,14 +571,12 @@ package body System.Generic_Array_Operations is
(Left : Left_Scalar;
Right : Right_Vector) return Result_Vector
is
- R : Result_Vector (Right'Range);
-
begin
- for J in R'Range loop
- R (J) := Operation (Left, Right (J));
- end loop;
-
- return R;
+ return R : Result_Vector (Right'Range) do
+ for J in R'Range loop
+ R (J) := Operation (Left, Right (J));
+ end loop;
+ end return;
end Scalar_Vector_Elementwise_Operation;
----------
@@ -662,31 +638,30 @@ package body System.Generic_Array_Operations is
(Left : Left_Matrix;
Right : Right_Matrix) return Result_Matrix
is
- R : Result_Matrix (Left'Range (1), Right'Range (2));
-
begin
- if Left'Length (2) /= Right'Length (1) then
- raise Constraint_Error with
- "incompatible dimensions in matrix multiplication";
- end if;
+ return R : Result_Matrix (Left'Range (1), Right'Range (2)) do
+ if Left'Length (2) /= Right'Length (1) then
+ raise Constraint_Error with
+ "incompatible dimensions in matrix multiplication";
+ end if;
- for J in R'Range (1) loop
- for K in R'Range (2) loop
- declare
- S : Result_Scalar := Zero;
+ for J in R'Range (1) loop
+ for K in R'Range (2) loop
+ declare
+ S : Result_Scalar := Zero;
- begin
- for M in Left'Range (2) loop
- S := S + Left (J, M) *
- Right (M - Left'First (2) + Right'First (1), K);
- end loop;
+ begin
+ for M in Left'Range (2) loop
+ S := S + Left (J, M) *
+ Right
+ (M - Left'First (2) + Right'First (1), K);
+ end loop;
- R (J, K) := S;
- end;
+ R (J, K) := S;
+ end;
+ end loop;
end loop;
- end loop;
-
- return R;
+ end return;
end Matrix_Matrix_Product;
----------------------------
@@ -766,28 +741,27 @@ package body System.Generic_Array_Operations is
(Left : Matrix;
Right : Right_Vector) return Result_Vector
is
- R : Result_Vector (Left'Range (1));
-
begin
- if Left'Length (2) /= Right'Length then
- raise Constraint_Error with
- "incompatible dimensions in matrix-vector multiplication";
- end if;
-
- for J in Left'Range (1) loop
- declare
- S : Result_Scalar := Zero;
+ return R : Result_Vector (Left'Range (1)) do
+ if Left'Length (2) /= Right'Length then
+ raise Constraint_Error with
+ "incompatible dimensions in matrix-vector multiplication";
+ end if;
- begin
- for K in Left'Range (2) loop
- S := S + Left (J, K) * Right (K - Left'First (2) + Right'First);
- end loop;
+ for J in Left'Range (1) loop
+ declare
+ S : Result_Scalar := Zero;
- R (J) := S;
- end;
- end loop;
+ begin
+ for K in Left'Range (2) loop
+ S := S + Left (J, K)
+ * Right (K - Left'First (2) + Right'First);
+ end loop;
- return R;
+ R (J) := S;
+ end;
+ end loop;
+ end return;
end Matrix_Vector_Product;
-------------------
@@ -798,16 +772,14 @@ package body System.Generic_Array_Operations is
(Left : Left_Vector;
Right : Right_Vector) return Matrix
is
- R : Matrix (Left'Range, Right'Range);
-
begin
- for J in R'Range (1) loop
- for K in R'Range (2) loop
- R (J, K) := Left (J) * Right (K);
+ return R : Matrix (Left'Range, Right'Range) do
+ for J in R'Range (1) loop
+ for K in R'Range (2) loop
+ R (J, K) := Left (J) * Right (K);
+ end loop;
end loop;
- end loop;
-
- return R;
+ end return;
end Outer_Product;
-----------------
@@ -884,17 +856,16 @@ package body System.Generic_Array_Operations is
First_1 : Integer := 1;
First_2 : Integer := 1) return Matrix
is
- R : Matrix (First_1 .. Check_Unit_Last (First_1, Order, First_1),
- First_2 .. Check_Unit_Last (First_2, Order, First_2));
-
begin
- R := (others => (others => Zero));
+ return R : Matrix (First_1 .. Check_Unit_Last (First_1, Order, First_1),
+ First_2 .. Check_Unit_Last (First_2, Order, First_2))
+ do
+ R := (others => (others => Zero));
- for J in 0 .. Order - 1 loop
- R (First_1 + J, First_2 + J) := One;
- end loop;
-
- return R;
+ for J in 0 .. Order - 1 loop
+ R (First_1 + J, First_2 + J) := One;
+ end loop;
+ end return;
end Unit_Matrix;
-----------------
@@ -906,11 +877,11 @@ package body System.Generic_Array_Operations is
Order : Positive;
First : Integer := 1) return Vector
is
- R : Vector (First .. Check_Unit_Last (Index, Order, First));
begin
- R := (others => Zero);
- R (Index) := One;
- return R;
+ return R : Vector (First .. Check_Unit_Last (Index, Order, First)) do
+ R := (others => Zero);
+ R (Index) := One;
+ end return;
end Unit_Vector;
---------------------------
@@ -921,28 +892,27 @@ package body System.Generic_Array_Operations is
(Left : Left_Vector;
Right : Matrix) return Result_Vector
is
- R : Result_Vector (Right'Range (2));
-
begin
- if Left'Length /= Right'Length (2) then
- raise Constraint_Error with
- "incompatible dimensions in vector-matrix multiplication";
- end if;
-
- for J in Right'Range (2) loop
- declare
- S : Result_Scalar := Zero;
+ return R : Result_Vector (Right'Range (2)) do
+ if Left'Length /= Right'Length (2) then
+ raise Constraint_Error with
+ "incompatible dimensions in vector-matrix multiplication";
+ end if;
- begin
- for K in Right'Range (1) loop
- S := S + Left (J - Right'First (1) + Left'First) * Right (K, J);
- end loop;
+ for J in Right'Range (2) loop
+ declare
+ S : Result_Scalar := Zero;
- R (J) := S;
- end;
- end loop;
+ begin
+ for K in Right'Range (1) loop
+ S := S + Left (J - Right'First (1)
+ + Left'First) * Right (K, J);
+ end loop;
- return R;
+ R (J) := S;
+ end;
+ end loop;
+ end return;
end Vector_Matrix_Product;
end System.Generic_Array_Operations;