Skip to content

Commit 9b95511

Browse files
author
Sonny Martin
committed
Add support for N_Block_Statement node
1 parent 72463ae commit 9b95511

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

gnat2goto/driver/tree_walk.adb

+15-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ package body Tree_Walk is
206206
with Pre => Nkind (N) = N_Loop_Statement,
207207
Post => Kind (Do_Loop_Statement'Result) in Class_Code;
208208

209+
function Do_N_Block_Statement (N : Node_Id) return Irep
210+
with Pre => Nkind (N) = N_Block_Statement,
211+
Post => Kind (Do_N_Block_Statement'Result) = I_Code_Block;
212+
209213
procedure Do_Object_Declaration (N : Node_Id; Block : Irep)
210214
with Pre => Nkind (N) = N_Object_Declaration
211215
and then Kind (Block) = I_Code_Block;
@@ -429,6 +433,7 @@ package body Tree_Walk is
429433
function Report_Unhandled_Node_Irep (N : Node_Id;
430434
Fun_Name : String;
431435
Message : String) return Irep;
436+
432437
function Report_Unhandled_Node_Kind (N : Node_Id;
433438
Fun_Name : String;
434439
Message : String) return Irep_Kind;
@@ -2777,6 +2782,15 @@ package body Tree_Walk is
27772782
return Loop_Wrapper;
27782783
end Do_Loop_Statement;
27792784

2785+
-----------------------------------------
2786+
-- Do_N_Block_Statement (nested declares)
2787+
-----------------------------------------
2788+
2789+
function Do_N_Block_Statement (N : Node_Id) return Irep is
2790+
begin
2791+
return Do_Subprogram_Or_Block (N);
2792+
end Do_N_Block_Statement;
2793+
27802794
---------------
27812795
-- Do_Pragma --
27822796
---------------
@@ -5110,7 +5124,7 @@ package body Tree_Walk is
51105124
Append_Op (Block, Do_Loop_Statement (N));
51115125

51125126
when N_Block_Statement =>
5113-
Warn_Unhandled_Construct (Statement, "block");
5127+
Append_Op (Block, Do_N_Block_Statement (N));
51145128

51155129
when N_Handled_Sequence_Of_Statements => -- this seems incorrct
51165130
-- It should be block_statement

testsuite/gnat2goto/tests/statement_new_block_N_Block_Statement/Statement_Block.adb

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function Statement_Block return Integer is
2+
Var1 : Integer :=1;
3+
Var2 : Integer;
4+
5+
function Sum_Plus_Three(Left, Right : Integer) return Integer is
6+
Local1 : Integer;
7+
begin
8+
declare
9+
Local2 : Integer := 1;
10+
begin
11+
Local1 := Local2 + Var1 + 1;
12+
Pragma Assert (Local1=3);
13+
end;
14+
return (Left + Right + Local1);
15+
end Sum_Plus_Three;
16+
17+
begin
18+
----------------------------------------
19+
-- the below nested function call works, but is out of scope
20+
-- and nested functions are not yet fully supported / tested
21+
----------------------------------------
22+
-- Var1 := Sum_Plus_Three(3,4);
23+
-- pragma Assert (Var1=10);
24+
----------------------------------------
25+
26+
declare
27+
Var3 : Integer :=2;
28+
begin
29+
Var2 := Var3;
30+
pragma Assert (Var2=2);
31+
declare
32+
Var4 : Integer := Var3;
33+
begin
34+
Var2 := Var4 + Var2;
35+
Pragma Assert (Var2=4);
36+
end;
37+
end;
38+
39+
declare
40+
Var5 : Integer := 6;
41+
begin
42+
Var2 := Var5 + Var2;
43+
end;
44+
45+
pragma Assert (Var2=10);
46+
return Var2;
47+
end Statement_Block;

testsuite/gnat2goto/tests/statement_new_block_N_Block_Statement/test.opt

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERIFICATION SUCCESSFUL

0 commit comments

Comments
 (0)