Browse Source

* fix and simplify twhilerepeatnode.internalsimplify

florian 2 weeks ago
parent
commit
7b2b51e6f3
2 changed files with 15 additions and 7 deletions
  1. 3 3
      compiler/nflw.pas
  2. 12 4
      compiler/nutils.pas

+ 3 - 3
compiler/nflw.pas

@@ -1363,9 +1363,9 @@ implementation
            (tordconstnode(taddnode(left).right).value=0)) then
           begin
             p:=GetLastStatement(right);
-            if assigned(p) and (tstatementnode(p).left.nodetype=inlinen) and (tinlinenode(tstatementnode(p).left).inlinenumber=in_dec_x) and
-              taddnode(left).left.isequal(tcallparanode(tinlinenode(tstatementnode(p).left).left).left) and
-              not(assigned(tcallparanode(tinlinenode(tstatementnode(p).left).left).right)) then
+            if assigned(p) and (p.nodetype=inlinen) and (tinlinenode(p).inlinenumber=in_dec_x) and
+              taddnode(left).left.isequal(tcallparanode(tinlinenode(p).left).left) and
+              not(assigned(tcallparanode(tinlinenode(p).left).right)) then
               begin
                 result:=cifnode.create_internal(left.getcopy,getcopy,nil);
                 include(twhilerepeatnode(tifnode(result).right).loopflags,lnf_checknegate);

+ 12 - 4
compiler/nutils.pas

@@ -1674,12 +1674,20 @@ implementation
         Result:=p;
         while assigned(Result) do
           begin
-            if (Result.nodetype=statementn) and assigned(tstatementnode(Result).next) then
-              Result:=tstatementnode(Result).next
+            if Result.nodetype=statementn then
+              begin
+                if assigned(tstatementnode(Result).next) then
+                  Result:=tstatementnode(Result).next
+                else if tstatementnode(Result).statement.nodetype=blockn then
+                  Result:=tblocknode(tstatementnode(Result).left).statements
+                else
+                  begin
+                    Result:=tstatementnode(Result).statement;
+                    exit;
+                  end;
+              end
             else if Result.nodetype=blockn then
               Result:=tblocknode(Result).statements
-            else if (Result.nodetype=statementn) and (tstatementnode(Result).statement.nodetype=blockn) then
-              Result:=tblocknode(tstatementnode(Result).left).statements
             else
               exit;
           end;