* transform tryfinally nodes with an empty try parts into the finally block

git-svn-id: trunk@11035 -
This commit is contained in:
florian 2008-05-22 11:30:46 +00:00
parent 33b69b0bd2
commit 085d5423ac
2 changed files with 41 additions and 0 deletions

View File

@ -181,6 +181,7 @@ interface
constructor create_implicit(l,r,_t1:tnode);virtual;
function pass_typecheck:tnode;override;
function pass_1 : tnode;override;
function simplify: tnode;override;
end;
ttryfinallynodeclass = class of ttryfinallynode;
@ -1276,6 +1277,20 @@ implementation
end;
function ttryfinallynode.simplify: tnode;
begin
result:=nil;
{ if the try contains no code, we can kill
the try and except and return only the
finally part }
if has_no_code(left) then
begin
result:=right;
right:=nil;
end;
end;
{*****************************************************************************
TONNODE
*****************************************************************************}

View File

@ -82,6 +82,10 @@ interface
{ tries to simplify the given node }
procedure dosimplify(var n : tnode);
{ returns true if n is only a tree of administrative nodes
containing no code }
function has_no_code(n : tnode) : boolean;
procedure propaccesslist_to_node(var p1:tnode;st:TSymtable;pl:tpropaccesslist);
function node_to_propaccesslist(p1:tnode):tpropaccesslist;
@ -905,4 +909,26 @@ implementation
end;
function has_no_code(n : tnode) : boolean;
begin
if n=nil then
begin
result:=true;
exit;
end;
result:=false;
case n.nodetype of
nothingn:
begin
result:=true;
exit;
end;
blockn:
begin
result:=has_no_code(tblocknode(n).left);
exit;
end;
end;
end;
end.