Skip to content

Commit

Permalink
ada: Refactor s-pack* units to remove multiple returns
Browse files Browse the repository at this point in the history
The aim of this refactoring is to replace multiple returns from
branches of case and if statements by a single return statement
with a conditional expression. This is more readable and
maintainable, and also conformant with a Highly Recommended
design principle of ISO 26262-6.

gcc/ada/

	* libgnat/s-pack03.adb: Update copyright year; refactor return statements.
	* libgnat/s-pack05.adb: Likewise.
	* libgnat/s-pack06.adb: Likewise.
	* libgnat/s-pack07.adb: Likewise.
	* libgnat/s-pack09.adb: Likewise.
	* libgnat/s-pack10.adb: Likewise.
	* libgnat/s-pack100.adb: Likewise.
	* libgnat/s-pack101.adb: Likewise.
	* libgnat/s-pack102.adb: Likewise.
	* libgnat/s-pack103.adb: Likewise.
	* libgnat/s-pack104.adb: Likewise.
	* libgnat/s-pack105.adb: Likewise.
	* libgnat/s-pack106.adb: Likewise.
	* libgnat/s-pack107.adb: Likewise.
	* libgnat/s-pack108.adb: Likewise.
	* libgnat/s-pack109.adb: Likewise.
	* libgnat/s-pack11.adb: Likewise.
	* libgnat/s-pack110.adb: Likewise.
	* libgnat/s-pack111.adb: Likewise.
	* libgnat/s-pack112.adb: Likewise.
	* libgnat/s-pack113.adb: Likewise.
	* libgnat/s-pack114.adb: Likewise.
	* libgnat/s-pack115.adb: Likewise.
	* libgnat/s-pack116.adb: Likewise.
	* libgnat/s-pack117.adb: Likewise.
	* libgnat/s-pack118.adb: Likewise.
	* libgnat/s-pack119.adb: Likewise.
	* libgnat/s-pack12.adb: Likewise.
	* libgnat/s-pack120.adb: Likewise.
	* libgnat/s-pack121.adb: Likewise.
	* libgnat/s-pack122.adb: Likewise.
	* libgnat/s-pack123.adb: Likewise.
	* libgnat/s-pack124.adb: Likewise.
	* libgnat/s-pack125.adb: Likewise.
	* libgnat/s-pack126.adb: Likewise.
	* libgnat/s-pack127.adb: Likewise.
	* libgnat/s-pack13.adb: Likewise.
	* libgnat/s-pack14.adb: Likewise.
	* libgnat/s-pack15.adb: Likewise.
	* libgnat/s-pack17.adb: Likewise.
	* libgnat/s-pack18.adb: Likewise.
	* libgnat/s-pack19.adb: Likewise.
	* libgnat/s-pack20.adb: Likewise.
	* libgnat/s-pack21.adb: Likewise.
	* libgnat/s-pack22.adb: Likewise.
	* libgnat/s-pack23.adb: Likewise.
	* libgnat/s-pack24.adb: Likewise.
	* libgnat/s-pack25.adb: Likewise.
	* libgnat/s-pack26.adb: Likewise.
	* libgnat/s-pack27.adb: Likewise.
	* libgnat/s-pack28.adb: Likewise.
	* libgnat/s-pack29.adb: Likewise.
	* libgnat/s-pack30.adb: Likewise.
	* libgnat/s-pack31.adb: Likewise.
	* libgnat/s-pack33.adb: Likewise.
	* libgnat/s-pack34.adb: Likewise.
	* libgnat/s-pack35.adb: Likewise.
	* libgnat/s-pack36.adb: Likewise.
	* libgnat/s-pack37.adb: Likewise.
	* libgnat/s-pack38.adb: Likewise.
	* libgnat/s-pack39.adb: Likewise.
	* libgnat/s-pack40.adb: Likewise.
	* libgnat/s-pack41.adb: Likewise.
	* libgnat/s-pack42.adb: Likewise.
	* libgnat/s-pack43.adb: Likewise.
	* libgnat/s-pack44.adb: Likewise.
	* libgnat/s-pack45.adb: Likewise.
	* libgnat/s-pack46.adb: Likewise.
	* libgnat/s-pack47.adb: Likewise.
	* libgnat/s-pack48.adb: Likewise.
	* libgnat/s-pack49.adb: Likewise.
	* libgnat/s-pack50.adb: Likewise.
	* libgnat/s-pack51.adb: Likewise.
	* libgnat/s-pack52.adb: Likewise.
	* libgnat/s-pack53.adb: Likewise.
	* libgnat/s-pack54.adb: Likewise.
	* libgnat/s-pack55.adb: Likewise.
	* libgnat/s-pack56.adb: Likewise.
	* libgnat/s-pack57.adb: Likewise.
	* libgnat/s-pack58.adb: Likewise.
	* libgnat/s-pack59.adb: Likewise.
	* libgnat/s-pack60.adb: Likewise.
	* libgnat/s-pack61.adb: Likewise.
	* libgnat/s-pack62.adb: Likewise.
	* libgnat/s-pack63.adb: Likewise.
	* libgnat/s-pack65.adb: Likewise.
	* libgnat/s-pack66.adb: Likewise.
	* libgnat/s-pack67.adb: Likewise.
	* libgnat/s-pack68.adb: Likewise.
	* libgnat/s-pack69.adb: Likewise.
	* libgnat/s-pack70.adb: Likewise.
	* libgnat/s-pack71.adb: Likewise.
	* libgnat/s-pack72.adb: Likewise.
	* libgnat/s-pack73.adb: Likewise.
	* libgnat/s-pack74.adb: Likewise.
	* libgnat/s-pack75.adb: Likewise.
	* libgnat/s-pack76.adb: Likewise.
	* libgnat/s-pack77.adb: Likewise.
	* libgnat/s-pack78.adb: Likewise.
	* libgnat/s-pack79.adb: Likewise.
	* libgnat/s-pack80.adb: Likewise.
	* libgnat/s-pack81.adb: Likewise.
	* libgnat/s-pack82.adb: Likewise.
	* libgnat/s-pack83.adb: Likewise.
	* libgnat/s-pack84.adb: Likewise.
	* libgnat/s-pack85.adb: Likewise.
	* libgnat/s-pack86.adb: Likewise.
	* libgnat/s-pack87.adb: Likewise.
	* libgnat/s-pack88.adb: Likewise.
	* libgnat/s-pack89.adb: Likewise.
	* libgnat/s-pack90.adb: Likewise.
	* libgnat/s-pack91.adb: Likewise.
	* libgnat/s-pack92.adb: Likewise.
	* libgnat/s-pack93.adb: Likewise.
	* libgnat/s-pack94.adb: Likewise.
	* libgnat/s-pack95.adb: Likewise.
	* libgnat/s-pack96.adb: Likewise.
	* libgnat/s-pack97.adb: Likewise.
	* libgnat/s-pack98.adb: Likewise.
	* libgnat/s-pack99.adb: Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.
  • Loading branch information
t-14 authored and ouuleilei-bot committed Jul 18, 2023
1 parent c2d62cd commit 3814da8
Show file tree
Hide file tree
Showing 120 changed files with 4,071 additions and 4,248 deletions.
47 changes: 23 additions & 24 deletions gcc/ada/libgnat/s-pack03.adb
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,29 @@ package body System.Pack_03 is
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;

else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
return
(if Rev_SSO then
(case N07 (Uns (N) mod 8) is
when 0 => RC.E0,
when 1 => RC.E1,
when 2 => RC.E2,
when 3 => RC.E3,
when 4 => RC.E4,
when 5 => RC.E5,
when 6 => RC.E6,
when 7 => RC.E7)

else
(case N07 (Uns (N) mod 8) is
when 0 => C.E0,
when 1 => C.E1,
when 2 => C.E2,
when 3 => C.E3,
when 4 => C.E4,
when 5 => C.E5,
when 6 => C.E6,
when 7 => C.E7)
);
end Get_03;

------------
Expand Down
47 changes: 23 additions & 24 deletions gcc/ada/libgnat/s-pack05.adb
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,29 @@ package body System.Pack_05 is
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;

else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
return
(if Rev_SSO then
(case N07 (Uns (N) mod 8) is
when 0 => RC.E0,
when 1 => RC.E1,
when 2 => RC.E2,
when 3 => RC.E3,
when 4 => RC.E4,
when 5 => RC.E5,
when 6 => RC.E6,
when 7 => RC.E7)

else
(case N07 (Uns (N) mod 8) is
when 0 => C.E0,
when 1 => C.E1,
when 2 => C.E2,
when 3 => C.E3,
when 4 => C.E4,
when 5 => C.E5,
when 6 => C.E6,
when 7 => C.E7)
);
end Get_05;

------------
Expand Down
94 changes: 46 additions & 48 deletions gcc/ada/libgnat/s-pack06.adb
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,29 @@ package body System.Pack_06 is
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;

else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
return
(if Rev_SSO then
(case N07 (Uns (N) mod 8) is
when 0 => RC.E0,
when 1 => RC.E1,
when 2 => RC.E2,
when 3 => RC.E3,
when 4 => RC.E4,
when 5 => RC.E5,
when 6 => RC.E6,
when 7 => RC.E7)

else
(case N07 (Uns (N) mod 8) is
when 0 => C.E0,
when 1 => C.E1,
when 2 => C.E2,
when 3 => C.E3,
when 4 => C.E4,
when 5 => C.E5,
when 6 => C.E6,
when 7 => C.E7)
);
end Get_06;

-------------
Expand All @@ -143,30 +142,29 @@ package body System.Pack_06 is
C : ClusterU_Ref with Address => A'Address, Import;
RC : Rev_ClusterU_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;

else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
return
(if Rev_SSO then
(case N07 (Uns (N) mod 8) is
when 0 => RC.E0,
when 1 => RC.E1,
when 2 => RC.E2,
when 3 => RC.E3,
when 4 => RC.E4,
when 5 => RC.E5,
when 6 => RC.E6,
when 7 => RC.E7)

else
(case N07 (Uns (N) mod 8) is
when 0 => C.E0,
when 1 => C.E1,
when 2 => C.E2,
when 3 => C.E3,
when 4 => C.E4,
when 5 => C.E5,
when 6 => C.E6,
when 7 => C.E7)
);
end GetU_06;

------------
Expand Down
47 changes: 23 additions & 24 deletions gcc/ada/libgnat/s-pack07.adb
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,29 @@ package body System.Pack_07 is
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;

else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
return
(if Rev_SSO then
(case N07 (Uns (N) mod 8) is
when 0 => RC.E0,
when 1 => RC.E1,
when 2 => RC.E2,
when 3 => RC.E3,
when 4 => RC.E4,
when 5 => RC.E5,
when 6 => RC.E6,
when 7 => RC.E7)

else
(case N07 (Uns (N) mod 8) is
when 0 => C.E0,
when 1 => C.E1,
when 2 => C.E2,
when 3 => C.E3,
when 4 => C.E4,
when 5 => C.E5,
when 6 => C.E6,
when 7 => C.E7)
);
end Get_07;

------------
Expand Down
47 changes: 23 additions & 24 deletions gcc/ada/libgnat/s-pack09.adb
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,29 @@ package body System.Pack_09 is
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;

else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
return
(if Rev_SSO then
(case N07 (Uns (N) mod 8) is
when 0 => RC.E0,
when 1 => RC.E1,
when 2 => RC.E2,
when 3 => RC.E3,
when 4 => RC.E4,
when 5 => RC.E5,
when 6 => RC.E6,
when 7 => RC.E7)

else
(case N07 (Uns (N) mod 8) is
when 0 => C.E0,
when 1 => C.E1,
when 2 => C.E2,
when 3 => C.E3,
when 4 => C.E4,
when 5 => C.E5,
when 6 => C.E6,
when 7 => C.E7)
);
end Get_09;

------------
Expand Down
Loading

0 comments on commit 3814da8

Please sign in to comment.