Parcourir la source

* remove statements with only a nothing node when they are the only children of a block

git-svn-id: trunk@29628 -
florian il y a 10 ans
Parent
commit
7b7aa8d542
1 fichiers modifiés avec 22 ajouts et 10 suppressions
  1. 22 10
      compiler/nbas.pas

+ 22 - 10
compiler/nbas.pas

@@ -540,18 +540,30 @@ implementation
         {  main program body, and those nodes should always be blocknodes }
         {  since that's what the compiler expects elsewhere.              }
 
-        { if the current block contains only one statement, and   }
-        { this one statement only contains another block, replace }
-        { this block with that other block.                       }
         if assigned(left) and
-           not assigned(tstatementnode(left).right) and
-           (tstatementnode(left).left.nodetype = blockn) then
+           not assigned(tstatementnode(left).right) then
           begin
-            result:=tstatementnode(left).left;
-            tstatementnode(left).left:=nil;
-            { make sure the nf_block_with_exit flag is safeguarded }
-            result.flags:=result.flags+(flags*[nf_block_with_exit,nf_usercode_entry]);
-            exit;
+            case tstatementnode(left).left.nodetype of
+              blockn:
+                begin
+                  { if the current block contains only one statement, and
+                    this one statement only contains another block, replace
+                    this block with that other block.                       }
+                  result:=tstatementnode(left).left;
+                  tstatementnode(left).left:=nil;
+                  { make sure the nf_block_with_exit flag is safeguarded }
+                  result.flags:=result.flags+(flags*[nf_block_with_exit,nf_usercode_entry]);
+                  exit;
+                end;
+              nothingn:
+                begin
+                  { if the block contains only a statement with a nothing node,
+                    get rid of the statement }
+                  left.Free;
+                  left:=nil;
+                  exit;
+                end;
+            end;
           end;
       end;