Skip to content

Implement support for case statements in Ada #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gnat2goto/driver/tree_walk.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,7 @@ package body Tree_Walk is
-- Omit test, this is either `others`
-- or the last case of complete coverage
This_Test := This_Stmt;
Append_Op (Ret, This_Test);
else
This_Test := New_Irep (I_Code_Ifthenelse);
Set_Cond (This_Test,
Expand Down
11 changes: 11 additions & 0 deletions testsuite/gnat2goto/tests/case_statement/case_statement.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Case_Statement return String is
type Sensor_Type is (Elevation, Azimuth, Distance);
Sensor : Sensor_Type := Elevation;
begin
case Sensor is
when Elevation => return "Elevation sensor";
when Azimuth => return "Azimuth sensor";
when Distance => return "Distance sensor";
when others => return "";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert result

end case;
end Case_Statement;
1 change: 1 addition & 0 deletions testsuite/gnat2goto/tests/case_statement/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERIFICATION SUCCESSFUL
3 changes: 3 additions & 0 deletions testsuite/gnat2goto/tests/case_statement/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from test_support import *

prove()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function Case_Statement_Others_Only return String is
type Sensor_Type is (Elevation, Azimuth, Distance);
Sensor : Sensor_Type := Elevation;
begin
case Sensor is
when others => return "";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert

end case;
end Case_Statement_Others_Only;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERIFICATION SUCCESSFUL
3 changes: 3 additions & 0 deletions testsuite/gnat2goto/tests/case_statement_others_only/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from test_support import *

prove()