fixed bug #514236
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 8 Feb 2002 12:09:25 +0000 (12:09 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 8 Feb 2002 12:09:25 +0000 (12:09 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1906 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/SDCCicode.c

index 4e92814703d6836911229db21266e698fb73ab4f..ff46ece9a0a5353603a08d744c21ba40bdcad498 100644 (file)
@@ -477,8 +477,7 @@ resolveChildren:
 /*-----------------------------------------------------------------*/
 /* setAstLineno - walks a ast tree & sets the line number          */
 /*-----------------------------------------------------------------*/
-int 
-setAstLineno (ast * tree, int lineno)
+int setAstLineno (ast * tree, int lineno)
 {
   if (!tree)
     return 0;
@@ -1520,8 +1519,7 @@ isConformingBody (ast * pbody, symbol * sym, ast * body)
   /* if we reach the end or a leaf then true */
   if (!pbody || IS_AST_LINK (pbody) || IS_AST_VALUE (pbody))
     return TRUE;
-
-
+  
   /* if anything else is "volatile" */
   if (IS_VOLATILE (TETYPE (pbody)))
     return FALSE;
@@ -1532,6 +1530,10 @@ isConformingBody (ast * pbody, symbol * sym, ast * body)
     {
 /*------------------------------------------------------------------*/
     case '[':
+      // if the loopvar is used as an index
+      if (astHasSymbol(pbody->right, sym)) {
+       return FALSE;
+      }
       return isConformingBody (pbody->right, sym, body);
 
 /*------------------------------------------------------------------*/
@@ -1800,14 +1802,15 @@ reverseLoop (ast * loop, symbol * sym, ast * init, ast * end)
   rloop = newNode (NULLOP,
                   createIf (newAst_VALUE (symbolVal (sym)),
                             newNode (GOTO,
-                  newAst_VALUE (symbolVal (AST_FOR (loop, continueLabel))),
+                                     newAst_VALUE (symbolVal (AST_FOR (loop, continueLabel))),
                                      NULL), NULL),
                   newNode ('=',
                            newAst_VALUE (symbolVal (sym)),
                            end));
-
+  
   replLoopSym (loop->left, sym);
-
+  setAstLineno (rloop, init->lineno);
+  
   rloop = newNode (NULLOP,
                   newNode ('=',
                            newAst_VALUE (symbolVal (sym)),
@@ -1817,12 +1820,13 @@ reverseLoop (ast * loop, symbol * sym, ast * init, ast * end)
                                         loop->left,
                                         newNode (NULLOP,
                                                  newNode (SUB_ASSIGN,
-                                            newAst_VALUE (symbolVal (sym)),
-                                            newAst_VALUE (constVal ("1"))),
+                                                          newAst_VALUE (symbolVal (sym)),
+                                                          newAst_VALUE (constVal ("1"))),
                                                  rloop))));
-
+  
+  rloop->lineno=init->lineno;
   return decorateType (rloop);
-
+  
 }
 
 /*-----------------------------------------------------------------*/
index bf2deb1f2758f05e04c6dab2c0d2cbb16b18c3ea..0f3e0725ad90725de33233b577fb63f7942c93fb 100644 (file)
@@ -2991,7 +2991,7 @@ geniCodeFunctionBody (ast * tree,int lvl)
 
   /* create a proc icode */
   ic = newiCode (FUNCTION, func, NULL);
-  ic->lineno = OP_SYMBOL (func)->lineDef;
+  lineno=ic->lineno = OP_SYMBOL (func)->lineDef;
 
   ADDTOCHAIN (ic);
 
@@ -3331,6 +3331,7 @@ ast2iCode (ast * tree,int lvl)
   operand *right = NULL;
   if (!tree)
     return NULL;
+
   /* set the global variables for filename & line number */
   if (tree->filename)
     filename = tree->filename;