浏览代码

* set varstate before parsing the instruction block in for statements

peter 20 年之前
父节点
当前提交
e24eb1f631
共有 2 个文件被更改,包括 26 次插入15 次删除
  1. 9 13
      compiler/nflw.pas
  2. 17 2
      compiler/pstatmnt.pas

+ 9 - 13
compiler/nflw.pas

@@ -679,6 +679,11 @@ implementation
          result:=nil;
          resulttype:=voidtype;
 
+         { process the loopvar, from and to, varstates are already set }
+         resulttypepass(left);
+         resulttypepass(right);
+         resulttypepass(t1);
+
          {Can we spare the first comparision?}
          if (t1.nodetype=ordconstn) and
             (right.nodetype=ordconstn) and
@@ -694,18 +699,6 @@ implementation
             ) then
            exclude(loopflags,lnf_testatbegin);
 
-         { process the loopvar, from and to }
-         resulttypepass(left);
-         resulttypepass(right);
-         resulttypepass(t1);
-
-         { first set the varstate for from and to, so
-           uses of loopvar in those expressions will also
-           trigger a warning when it is not used yet }
-         set_varstate(right,vs_used,true);
-         set_varstate(t1,vs_used,true);
-         set_varstate(left,vs_used,false);
-
          { Make sure that the loop var and the
            from and to values are compatible types }
          inserttypeconv(right,left.resulttype);
@@ -1401,7 +1394,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.107  2005-01-31 16:16:21  peter
+  Revision 1.108  2005-01-31 20:23:53  peter
+    * set varstate before parsing the instruction block in for statements
+
+  Revision 1.107  2005/01/31 16:16:21  peter
     * for-node cleanup, checking for uninitialzed from and to values
       is now supported
 

+ 17 - 2
compiler/pstatmnt.pas

@@ -387,10 +387,22 @@ implementation
          hto:=comp_expr(true);
          consume(_DO);
 
+         { first set the varstate for from and to, so
+           uses of loopvar in those expressions will also
+           trigger a warning when it is not used yet. This
+           needs to be done before the instruction block is
+           parsed to have a valid hloopvar }
+         resulttypepass(hfrom);
+         set_varstate(hfrom,vs_used,true);
+         resulttypepass(hto);
+         set_varstate(hto,vs_used,true);
+         resulttypepass(hloopvar);
+         set_varstate(hloopvar,vs_used,false);
+
          { ... now the instruction block }
          hblock:=statement;
 
-         { variable is not used a loop counter anymore }
+         { variable is not used for loop counter anymore }
          if assigned(loopvarsym) then
            exclude(loopvarsym.varoptions,vo_is_loop_counter);
 
@@ -1145,7 +1157,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.150  2005-01-31 16:16:21  peter
+  Revision 1.151  2005-01-31 20:23:53  peter
+    * set varstate before parsing the instruction block in for statements
+
+  Revision 1.150  2005/01/31 16:16:21  peter
     * for-node cleanup, checking for uninitialzed from and to values
       is now supported