Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch 
into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/100323

Fixed bug #967864 (var substitution did not update theFreeVars property)
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/100323
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-03-29 22:01:26 +0000
+++ ChangeLog	2012-04-01 05:08:00 +0000
@@ -6,6 +6,7 @@
   * Extended API for Python, Java, PHP and Ruby.
 
 Bug Fixes/Other Changes:
+  * Fixed bug #967864 (var substitution did not update theFreeVars property)
   * Fixed bug in window iterator (binding the end vars in the output tuple stream)
   * Fixed bug #866547 (protect index-join rule from general flwor)
   * Fixed bug #967428 (do not hoist index creation outside a try-catch)

=== modified file 'src/compiler/rewriter/rules/flwor_rules.cpp'
--- src/compiler/rewriter/rules/flwor_rules.cpp	2012-03-28 05:19:57 +0000
+++ src/compiler/rewriter/rules/flwor_rules.cpp	2012-04-01 05:08:00 +0000
@@ -71,8 +71,9 @@
 class SubstVars : public PrePostRewriteRule
 {
 protected:
-  const var_expr   * theVarExpr;
-  expr             * theSubstExpr;
+  const var_expr     * theVarExpr;
+  expr               * theSubstExpr;
+  std::vector<expr*>   thePath;
 
 public:
   SubstVars(const var_expr* var, expr* subst)
@@ -91,12 +92,32 @@
 
 RULE_REWRITE_PRE(SubstVars)
 {
-  return (node == theVarExpr) ? theSubstExpr : NULL;
+  thePath.push_back(node);
+
+  if (node == theVarExpr)
+  {
+    std::vector<expr*>::iterator ite = thePath.begin();
+    std::vector<expr*>::iterator end = thePath.end();
+    for (; ite != end; ++ite)
+    {
+      expr::FreeVars& vars = (*ite)->getFreeVars();
+      vars.erase(theVarExpr);
+      vars.insert(theSubstExpr->getFreeVars().begin(),
+                  theSubstExpr->getFreeVars().end());
+    }
+
+    return theSubstExpr;
+  }
+  else
+  {
+    return NULL;
+  }
 }
 
 
 RULE_REWRITE_POST(SubstVars)
 {
+  thePath.pop_back();
   return NULL;
 }
 
@@ -286,6 +307,9 @@
         --i;
 
         flwor.compute_return_type(true, NULL);
+
+        std::cout << "After eliminating var : " << std::endl;
+        rCtx.getRoot()->put(std::cout) << std::endl;
       }
     }
     else if (c.get_kind() == flwor_clause::let_clause)
@@ -333,6 +357,9 @@
         --numClauses;
         --numForLetClauses;
         --i;
+        
+        std::cout << "After eliminating var : " << std::endl;
+        rCtx.getRoot()->put(std::cout) << std::endl;
       }
       else if (domainQuant == TypeConstants::QUANT_ONE)
       {

=== modified file 'src/compiler/rewriter/tools/expr_tools.h'
--- src/compiler/rewriter/tools/expr_tools.h	2012-03-28 05:19:57 +0000
+++ src/compiler/rewriter/tools/expr_tools.h	2012-04-01 05:08:00 +0000
@@ -46,7 +46,11 @@
 namespace expr_tools
 {
 
-int count_variable_uses(const expr* root, const var_expr* var, RewriterContext* rCtx, int limit);
+int count_variable_uses(
+    const expr* root, 
+    const var_expr* var, 
+    RewriterContext* rCtx, 
+    int limit);
 
 
 /*******************************************************************************

=== added file 'test/rbkt/ExpQueryResults/zorba/optim/flwor_vars_01.xml.res'
--- test/rbkt/ExpQueryResults/zorba/optim/flwor_vars_01.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/optim/flwor_vars_01.xml.res	2012-04-01 05:08:00 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<count meaning="yes"/>

=== added file 'test/rbkt/Queries/zorba/optim/flwor_vars_01.xq'
--- test/rbkt/Queries/zorba/optim/flwor_vars_01.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/optim/flwor_vars_01.xq	2012-04-01 05:08:00 +0000
@@ -0,0 +1,10 @@
+
+declare context item := 
+<doc>
+  <count meaning="yes"/>
+</doc>;
+
+ 
+let $y := ./count[@meaning eq "yes"]
+let $output := if (./@level = 3) then $y else $y
+return if (./@nr = 3) then <b>{$output}</b> else $output

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to