mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 11:29:20 +02:00
* transform tryfinally nodes with an empty try parts into the finally block
git-svn-id: trunk@11035 -
This commit is contained in:
parent
33b69b0bd2
commit
085d5423ac
@ -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
|
||||
*****************************************************************************}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user