Skip to content

Add support for N_Block_Statement node #156

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 1 commit into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion gnat2goto/driver/tree_walk.adb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ package body Tree_Walk is
with Pre => Nkind (N) = N_Loop_Statement,
Post => Kind (Do_Loop_Statement'Result) in Class_Code;

function Do_N_Block_Statement (N : Node_Id) return Irep
with Pre => Nkind (N) = N_Block_Statement,
Post => Kind (Do_N_Block_Statement'Result) = I_Code_Block;

procedure Do_Object_Declaration (N : Node_Id; Block : Irep)
with Pre => Nkind (N) = N_Object_Declaration
and then Kind (Block) = I_Code_Block;
Expand Down Expand Up @@ -1949,6 +1953,15 @@ package body Tree_Walk is
return Loop_Wrapper;
end Do_Loop_Statement;

-----------------------------------------
-- Do_N_Block_Statement (nested declares)
-----------------------------------------

function Do_N_Block_Statement (N : Node_Id) return Irep is
begin
return Do_Subprogram_Or_Block (N);
end Do_N_Block_Statement;

---------------
-- Do_Pragma --
---------------
Expand Down Expand Up @@ -4024,7 +4037,7 @@ package body Tree_Walk is
Append_Op (Block, Do_Loop_Statement (N));

when N_Block_Statement =>
Warn_Unhandled_Construct (Statement, "block");
Append_Op (Block, Do_N_Block_Statement (N));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not append do_subprogram_or_block directly?

Copy link
Contributor Author

@sonodtt sonodtt Mar 12, 2019

Choose a reason for hiding this comment

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

Interface. Wrapper. Consistent with others. If impl. changes in future, has further checks etc - then this does not change, and the (consistent) structure is in place. Also the wrapper function has space for ... comments!


when N_Handled_Sequence_Of_Statements => -- this seems incorrct
-- It should be block_statement
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function Statement_Block return Integer is
Var1 : Integer :=1;
Var2 : Integer;

function Sum_Plus_Three(Left, Right : Integer) return Integer is
Local1 : Integer;
begin
declare
Local2 : Integer := 1;
begin
Local1 := Local2 + Var1 + 1;
Pragma Assert (Local1=3);
end;
return (Left + Right + Local1);
end Sum_Plus_Three;

begin
----------------------------------------
-- the below nested function call works, but is out of scope
-- and nested functions are not yet fully supported / tested
----------------------------------------
-- Var1 := Sum_Plus_Three(3,4);
-- pragma Assert (Var1=10);
----------------------------------------

declare
Var3 : Integer :=2;
begin
Var2 := Var3;
pragma Assert (Var2=2);
declare
Var4 : Integer := Var3;
begin
Var2 := Var4 + Var2;
Pragma Assert (Var2=4);
end;
end;

declare
Var5 : Integer := 6;
begin
Var2 := Var5 + Var2;
end;

pragma Assert (Var2=10);
return Var2;
end Statement_Block;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[4] file statement_block.adb line 12 assertion: SUCCESS
[1] file statement_block.adb line 30 assertion: SUCCESS
[2] file statement_block.adb line 35 assertion: SUCCESS
[3] file statement_block.adb line 45 assertion: SUCCESS
VERIFICATION SUCCESSFUL