Selaa lähdekoodia

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

git-svn-id: trunk@11035 -
florian 17 vuotta sitten
vanhempi
commit
085d5423ac
2 muutettua tiedostoa jossa 41 lisäystä ja 0 poistoa
  1. 15 0
      compiler/nflw.pas
  2. 26 0
      compiler/nutils.pas

+ 15 - 0
compiler/nflw.pas

@@ -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
 *****************************************************************************}

+ 26 - 0
compiler/nutils.pas

@@ -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.