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/82572

converted variable assignment to a full-blown expression instead of a function 
+ fixed a bug with the cloning of var_decl_expr
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/82572
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp	2011-10-24 02:42:07 +0000
+++ src/compiler/codegen/plan_visitor.cpp	2011-11-17 17:26:00 +0000
@@ -636,6 +636,41 @@
 }
 
 
+/***************************************************************************//**
+
+********************************************************************************/
+bool begin_visit(var_set_expr& v)
+{
+  CODEGEN_TRACE_IN("");
+  return true;
+}
+
+
+void end_visit(var_set_expr& v)
+{
+  CODEGEN_TRACE_OUT("");
+
+  const var_expr* varExpr = v.get_var_expr();
+
+  xqtref_t exprType = v.get_expr()->get_return_type();
+
+  PlanIter_t exprIter = pop_itstack();
+
+  CtxVarAssignIterator* iter = 
+  new CtxVarAssignIterator(sctx,
+                           qloc,
+                           varExpr->get_unique_id(),
+                           varExpr->get_name(),
+                           (varExpr->get_kind() == var_expr::local_var),
+                           exprIter);
+  
+  if (exprType->get_quantifier() == TypeConstants::QUANT_ONE)
+    iter->setSingleItem();
+
+  push_itstack(iter);
+}
+
+
 /*******************************************************************************
   VarRef expr
 ********************************************************************************/

=== modified file 'src/compiler/expression/abstract_expr_visitor.h'
--- src/compiler/expression/abstract_expr_visitor.h	2011-06-14 17:26:33 +0000
+++ src/compiler/expression/abstract_expr_visitor.h	2011-11-17 17:26:00 +0000
@@ -84,6 +84,7 @@
   EXPR_VISITOR_METHODS (block_expr);
   EXPR_VISITOR_METHODS (apply_expr);
   EXPR_VISITOR_METHODS (var_decl_expr);
+  EXPR_VISITOR_METHODS (var_set_expr);
   EXPR_VISITOR_METHODS (exit_expr);
   EXPR_VISITOR_METHODS (exit_catcher_expr);
   EXPR_VISITOR_METHODS (flowctl_expr);

=== modified file 'src/compiler/expression/expr_annotations.cpp'
--- src/compiler/expression/expr_annotations.cpp	2011-06-14 17:26:33 +0000
+++ src/compiler/expression/expr_annotations.cpp	2011-11-17 17:26:00 +0000
@@ -19,64 +19,6 @@
 
 namespace zorba {
 
-#if 0
-void SourceFinder::findSources(expr *e)
-{
-  switch(e->get_expr_kind()) 
-  {
-  case flwor_expr_kind:
-  case gflwor_expr_kind:
-    findSources(static_cast<flwor_expr *>(e)->getReturnExpr());
-    break;
-
-  case fo_expr_kind:
-  {
-    fo_expr *fo = static_cast<fo_expr *>(e);
-    const function *fn = fo->get_func();
-    if (fn->isSource()) {
-      m_sources.insert(fo);
-    } else {
-      findSourcesInChildren(fo);
-    }
-  }
-  break;
-
-  case var_expr_kind:
-  {
-    var_expr *var = static_cast<var_expr *>(e);
-    switch(var->get_kind()) {
-    case var_expr::for_var:
-    case var_expr::let_var:
-      findSources(&*var->get_flwor_clause()->get_expr());
-      break;
-      
-    case var_expr::context_var:
-    case var_expr::param_var:
-      m_sources.insert(var);
-      break;
-      
-    default:
-      break;
-    }
-  }
-  break;
-
-  default:
-    findSourcesInChildren(e);
-    break;
-  }
-}
-
-void SourceFinder::findSourcesInChildren(expr *e)
-{
-  for(expr_iterator i = e->expr_begin(); !i.done(); ++i) {
-    if (*i != NULL) {
-      findSources(*i);
-    }
-  }
-}
-#endif
-
 
 bool ExpressionPropertyComputer::returnsDuplicateNodes(expr *e)
 {

=== modified file 'src/compiler/expression/expr_base.cpp'
--- src/compiler/expression/expr_base.cpp	2011-08-12 10:21:10 +0000
+++ src/compiler/expression/expr_base.cpp	2011-11-17 17:26:00 +0000
@@ -50,7 +50,7 @@
 
 static xqtref_t print_expr_and_type(expr* e, xqtref_t t)
 {
-  if (Properties::instance()->printStaticTypes ())
+  if (Properties::instance()->printStaticTypes())
   {
     std::cout << "Return type for " << e << ":\n";
     e->put(std::cout);
@@ -85,10 +85,10 @@
 bool expr::is_sequential(short theScriptingKind)
 {
   return (theScriptingKind & (VAR_SETTING_EXPR |
-                             APPLYING_EXPR |
-                             EXITING_EXPR |
-                             BREAKING_EXPR | 
-                             SEQUENTIAL_FUNC_EXPR)) != 0;
+                              APPLYING_EXPR |
+                              EXITING_EXPR |
+                              BREAKING_EXPR | 
+                              SEQUENTIAL_FUNC_EXPR)) != 0;
 }
 
 
@@ -751,18 +751,25 @@
   {
     const fo_expr* foExpr = static_cast<const fo_expr *>(this);
     const function* func = foExpr->get_func();
-    ulong numArgs = foExpr->num_args();
+    csize numArgs = foExpr->num_args();
 
-    for (ulong i = 0; i < numArgs; ++i) {
+    for (csize i = 0; i < numArgs; ++i) 
+    {
       const expr* argExpr = foExpr->get_arg(i);
 
-      if (func->isMap(i)) {
-        if (argExpr->is_map_internal(e, found) && found) {
+      if (func->isMap(i)) 
+      {
+        if (argExpr->is_map_internal(e, found) && found) 
+        {
           return true;
-        } else if (found) {
+        }
+        else if (found)
+        {
           return false;
         }
-      } else if (argExpr->contains_expr(e)) {
+      }
+      else if (argExpr->contains_expr(e))
+      {
         return false;
       }
     }
@@ -775,9 +782,9 @@
   {
     const flwor_expr* flworExpr = static_cast<const flwor_expr *>(this);
     bool haveOrderBy = false;
-    ulong numClauses = flworExpr->num_clauses();
+    csize numClauses = flworExpr->num_clauses();
 
-    for (ulong i = 0; i < numClauses; ++i)
+    for (csize i = 0; i < numClauses; ++i)
     {
       const flwor_clause* clause = (*flworExpr)[i];
 
@@ -845,8 +852,8 @@
 
         const orderby_clause* obc = static_cast<const orderby_clause*>(clause);
 
-        ulong numColumns = obc->num_columns();
-        for (ulong k = 0; k < numColumns; ++k)
+        csize numColumns = obc->num_columns();
+        for (csize k = 0; k < numColumns; ++k)
         {
           if (obc->get_column_expr(k)->contains_expr(e))
             return false;
@@ -858,7 +865,7 @@
       default:
         ZORBA_ASSERT(false);
       }
-    }
+    } // for each clause
 
     if (found)
     {
@@ -971,6 +978,7 @@
     return false; // TODO
 
   case var_decl_expr_kind:
+  case var_set_expr_kind:
   {
     return !contains_expr(e);
   }

=== modified file 'src/compiler/expression/expr_base.h'
--- src/compiler/expression/expr_base.h	2011-07-29 06:13:28 +0000
+++ src/compiler/expression/expr_base.h	2011-11-17 17:26:00 +0000
@@ -89,6 +89,7 @@
 
   block_expr_kind,
   var_decl_expr_kind,
+  var_set_expr_kind,
   apply_expr_kind,
   exit_expr_kind,
   exit_catcher_expr_kind,

=== modified file 'src/compiler/expression/expr_classes.h'
--- src/compiler/expression/expr_classes.h	2011-06-14 17:26:33 +0000
+++ src/compiler/expression/expr_classes.h	2011-11-17 17:26:00 +0000
@@ -60,6 +60,7 @@
   class block_expr; 
   class apply_expr;
   class var_decl_expr;
+  class var_set_expr;
   class exit_expr;
   class exit_catcher_expr; 
   class while_expr; 

=== modified file 'src/compiler/expression/expr_iter.cpp'
--- src/compiler/expression/expr_iter.cpp	2011-09-20 14:33:34 +0000
+++ src/compiler/expression/expr_iter.cpp	2011-11-17 17:26:00 +0000
@@ -592,6 +592,15 @@
     break;
   }
 
+  case var_set_expr_kind:
+  {
+    var_set_expr* varSetExpr = static_cast<var_set_expr*>(theExpr);
+    EXPR_ITER_BEGIN();
+    EXPR_ITER_NEXT(varSetExpr->theExpr);
+    EXPR_ITER_END();
+    break;
+  }
+
   case flowctl_expr_kind:
   {
     EXPR_ITER_BEGIN();

=== modified file 'src/compiler/expression/expr_put.cpp'
--- src/compiler/expression/expr_put.cpp	2011-06-14 17:26:33 +0000
+++ src/compiler/expression/expr_put.cpp	2011-11-17 17:26:00 +0000
@@ -424,7 +424,7 @@
   return os;
 }
 
-ostream& eval_expr::put( ostream& os) const
+ostream& eval_expr::put(ostream& os) const
 {
   BEGIN_PUT( eval_expr );
   for (ulong i = 0; i < theArgs.size(); i++)
@@ -438,15 +438,15 @@
   END_PUT();
 }
 
-ostream& function_trace_expr::put( ostream& os) const
+ostream& function_trace_expr::put(ostream& os) const
 {
-  BEGIN_PUT( function_trace_expr );
-  theExpr->put (os);
+  BEGIN_PUT(function_trace_expr);
+  theExpr->put(os);
   END_PUT();
 }
 
 
-ostream& apply_expr::put( ostream& os) const
+ostream& apply_expr::put(ostream& os) const
 {
   BEGIN_PUT(apply_expr);
   theExpr->put(os);
@@ -454,32 +454,46 @@
 }
 
 
-ostream& var_decl_expr::put( ostream& os) const
+ostream& var_decl_expr::put(ostream& os) const
 {
-  BEGIN_PUT( var_decl_expr );
+  BEGIN_PUT(var_decl_expr);
+
   theVarExpr->put(os);
   if (theInitExpr)
     theInitExpr->put(os);
-  END_PUT();
-}
-
-
-ostream& if_expr::put( ostream& os) const
-{
-  BEGIN_PUT( if_expr );
+
+  END_PUT();
+}
+
+
+ostream& var_set_expr::put(ostream& os) const
+{
+  BEGIN_PUT(var_set_expr);
+
+  theVarExpr->put(os);
+  theExpr->put(os);
+
+  END_PUT();
+}
+
+
+ostream& if_expr::put(ostream& os) const
+{
+  BEGIN_PUT(if_expr);
   theCondExpr->put(os);
   PUT_SUB("THEN", theThenExpr);
   PUT_SUB("ELSE", theElseExpr);
   END_PUT();
 }
 
-ostream& fo_expr::put( ostream& os) const
+
+ostream& fo_expr::put(ostream& os) const
 {
   const store::Item* qname = theFunction->getName();
   BEGIN_PUT2( qname->getStringValue() << "/" << num_args() );
-  ulong numArgs = (ulong)theArgs.size();
+  csize numArgs = theArgs.size();
 
-  for (ulong i = 0; i < numArgs; ++i)
+  for (csize i = 0; i < numArgs; ++i)
   {
     theArgs[i]->put(os);
   }

=== modified file 'src/compiler/expression/expr_type.cpp'
--- src/compiler/expression/expr_type.cpp	2011-08-12 10:21:10 +0000
+++ src/compiler/expression/expr_type.cpp	2011-11-17 17:26:00 +0000
@@ -650,19 +650,16 @@
     return;
   }
 
+  case var_set_expr_kind:
+  {
+    theType = rtm.EMPTY_TYPE;
+    return;
+  }
+
   case exit_expr_kind:
   {
-    // TODO: should this be the empty-sequence type ???? Or should we check
-    // for an exit operand when computing the type of any other expr and
-    // just skip the exit ????
-#if 0
-    exit_expr* e = static_cast<exit_expr*>(this);
-    newType = e->theExpr->get_return_type();
-    break;
-#else
     theType = rtm.EMPTY_TYPE;
     return;
-#endif
   }
 
   case exit_catcher_expr_kind:

=== modified file 'src/compiler/expression/expr_visitor.h'
--- src/compiler/expression/expr_visitor.h	2011-06-14 17:26:33 +0000
+++ src/compiler/expression/expr_visitor.h	2011-11-17 17:26:00 +0000
@@ -81,6 +81,7 @@
 
   DECL_EXPR_VISITOR_VISIT_MEM_FNS(block_expr);
   DECL_EXPR_VISITOR_VISIT_MEM_FNS(var_decl_expr);
+  DECL_EXPR_VISITOR_VISIT_MEM_FNS(var_set_expr);
   DECL_EXPR_VISITOR_VISIT_MEM_FNS(apply_expr);
   DECL_EXPR_VISITOR_VISIT_MEM_FNS(exit_expr);
   DECL_EXPR_VISITOR_VISIT_MEM_FNS(exit_catcher_expr);

=== modified file 'src/compiler/expression/fo_expr.cpp'
--- src/compiler/expression/fo_expr.cpp	2011-07-29 06:13:28 +0000
+++ src/compiler/expression/fo_expr.cpp	2011-11-17 17:26:00 +0000
@@ -151,7 +151,7 @@
 void fo_expr::compute_scripting_kind()
 {
   const function* func = get_func();
-  ulong numArgs = num_args();
+  csize numArgs = num_args();
 
   if (func->getKind() == FunctionConsts::OP_CONCATENATE_N)
   {
@@ -159,7 +159,7 @@
 
     theScriptingKind = VACUOUS_EXPR;
 
-    for (ulong i = 0; i < numArgs; ++i)
+    for (csize i = 0; i < numArgs; ++i)
     {
       if (theArgs[i] == NULL)
         continue;
@@ -202,26 +202,13 @@
 
     checkScriptingKind();
   }
-  else if (func->getKind() == FunctionConsts::OP_VAR_ASSIGN_1)
-  {
-    assert(numArgs == 2);
-
-    expr* valueExpr = theArgs[1];
-
-    theScriptingKind = VAR_SETTING_EXPR;
-    theScriptingKind |= valueExpr->get_scripting_detail();
-    theScriptingKind &= ~VACUOUS_EXPR;
-    theScriptingKind &= ~SIMPLE_EXPR;
-
-    checkScriptingKind();
-  }
   else
   {
     theScriptingKind = func->getScriptingKind();
 
     bool vacuous = (theScriptingKind == VACUOUS_EXPR);
 
-    for (ulong i = 0; i < numArgs; ++i)
+    for (csize i = 0; i < numArgs; ++i)
     {
       if (theArgs[i] == NULL)
         continue;
@@ -272,7 +259,7 @@
 
   std::auto_ptr<fo_expr> fo(new fo_expr(theSctx, get_loc(), get_func()));
 
-  for (ulong i = 0; i < theArgs.size(); ++i)
+  for (csize i = 0; i < theArgs.size(); ++i)
     fo->theArgs.push_back(theArgs[i]->clone(subst));
 
   fo->theScriptingKind  = theScriptingKind;

=== modified file 'src/compiler/expression/script_exprs.cpp'
--- src/compiler/expression/script_exprs.cpp	2011-08-26 15:58:33 +0000
+++ src/compiler/expression/script_exprs.cpp	2011-11-17 17:26:00 +0000
@@ -38,6 +38,9 @@
 SERIALIZABLE_CLASS_VERSIONS(var_decl_expr)
 END_SERIALIZABLE_CLASS_VERSIONS(var_decl_expr)
 
+SERIALIZABLE_CLASS_VERSIONS(var_set_expr)
+END_SERIALIZABLE_CLASS_VERSIONS(var_set_expr)
+
 SERIALIZABLE_CLASS_VERSIONS(exit_expr)
 END_SERIALIZABLE_CLASS_VERSIONS(exit_expr)
 
@@ -53,6 +56,7 @@
 DEF_EXPR_ACCEPT(block_expr)
 DEF_EXPR_ACCEPT(apply_expr)
 DEF_EXPR_ACCEPT(var_decl_expr)
+DEF_EXPR_ACCEPT(var_set_expr)
 DEF_EXPR_ACCEPT(exit_expr)
 DEF_EXPR_ACCEPT(exit_catcher_expr)
 DEF_EXPR_ACCEPT(flowctl_expr)
@@ -83,15 +87,10 @@
 }
 
 
-void block_expr::add_at(ulong pos, const expr_t& arg)
+void block_expr::add_at(csize pos, const expr_t& arg)
 {
-#ifndef NDEBUG
-  if (arg->get_expr_kind() == fo_expr_kind)
-  {
-    fo_expr* fo = static_cast<fo_expr*>(arg.getp());
-    assert(fo->get_func()->getKind() != FunctionConsts::OP_VAR_ASSIGN_1);
-  }
-#endif
+  assert(arg->get_expr_kind() != var_set_expr_kind);
+
   theArgs.insert(theArgs.begin() + pos, arg);
   compute_scripting_kind2(NULL, false);
 }
@@ -193,7 +192,7 @@
 expr_t block_expr::clone(substitution_t& subst) const
 {
   checked_vector<expr_t> seq2;
-  for (unsigned i = 0; i < theArgs.size(); ++i)
+  for (csize i = 0; i < theArgs.size(); ++i)
     seq2.push_back(theArgs[i]->clone(subst));
 
   return new block_expr(theSctx, get_loc(), true, seq2, NULL);
@@ -290,11 +289,12 @@
 
 expr_t var_decl_expr::clone(substitution_t& s) const
 {
-  assert(theVarExpr.getp() == theVarExpr->clone(s).getp());
+  var_expr_t varCopy(new var_expr(*theVarExpr));
+  s[theVarExpr.getp()] = varCopy.getp();
 
   return new var_decl_expr(theSctx,
                            get_loc(),
-                           theVarExpr,
+                           varCopy,
                            (theInitExpr ? theInitExpr->clone(s) : NULL));
 }
 
@@ -302,6 +302,63 @@
 /*******************************************************************************
 
 ********************************************************************************/
+var_set_expr::var_set_expr(
+    static_context* sctx,
+    const QueryLoc& loc,
+    const var_expr_t& varExpr,
+    const expr_t& setExpr)
+  :
+  expr(sctx, loc, var_set_expr_kind),
+  theVarExpr(varExpr),
+  theExpr(setExpr)
+{
+  assert(varExpr->get_kind() == var_expr::prolog_var || 
+         varExpr->get_kind() == var_expr::local_var);
+
+  compute_scripting_kind();
+
+  // var_set_expr is unfoldable because it requires access to the dyn ctx.
+  setUnfoldable(ANNOTATION_TRUE_FIXED);
+}
+
+
+void var_set_expr::serialize(::zorba::serialization::Archiver& ar)
+{
+  serialize_baseclass(ar, (expr*)this);
+  ar & theVarExpr;
+  ar & theExpr;
+}
+
+
+void var_set_expr::compute_scripting_kind()
+{
+  checkNonUpdating(theExpr);
+
+  theScriptingKind = VAR_SETTING_EXPR;
+  theScriptingKind |= theExpr->get_scripting_detail();
+  theScriptingKind &= ~VACUOUS_EXPR;
+  theScriptingKind &= ~SIMPLE_EXPR;
+
+  checkScriptingKind();
+}
+
+
+expr_t var_set_expr::clone(substitution_t& s) const
+{
+  expr_t varClone = theVarExpr->clone(s);
+
+  ZORBA_ASSERT(varClone->get_expr_kind() == var_expr_kind);
+
+  return new var_set_expr(theSctx,
+                          get_loc(),
+                          static_cast<var_expr*>(varClone.getp()),
+                          theExpr->clone(s));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
 exit_expr::exit_expr(
     static_context* sctx,
     const QueryLoc& loc,

=== modified file 'src/compiler/expression/script_exprs.h'
--- src/compiler/expression/script_exprs.h	2011-08-16 11:25:55 +0000
+++ src/compiler/expression/script_exprs.h	2011-11-17 17:26:00 +0000
@@ -135,13 +135,13 @@
       std::vector<expr_t>& seq,
       std::vector<var_expr*>* assignedVars);
 
-  void add_at(ulong pos, const expr_t& arg);
-
-  ulong size() const { return (ulong)theArgs.size(); }
-
-  const expr_t& operator[](ulong i) const { return theArgs[i]; }
-
-  expr_t& operator[](ulong i) { return theArgs[i]; }
+  void add_at(csize pos, const expr_t& arg);
+
+  csize size() const { return theArgs.size(); }
+
+  const expr_t& operator[](csize i) const { return theArgs[i]; }
+
+  expr_t& operator[](csize i) { return theArgs[i]; }
 
   expr_t clone(substitution_t& s) const;
 
@@ -260,6 +260,52 @@
 
 
 /*******************************************************************************
+
+  AssignStatement ::= "$" VarName ":=" ExprSingle ";"
+
+  The RHS of the assignment must be a non-updating expr.
+
+  var_set_expr is used to assign a value to a prolog or block-local var. During
+  runtime, the function computes theExpr and stores the resulting value inside 
+  the appropriate dynamic ctx (global or local), at the location that is identified
+  by the variable id.
+********************************************************************************/
+class var_set_expr : public expr 
+{
+  friend class ExprIterator;
+  friend class expr;
+
+protected:
+  var_expr_t theVarExpr;
+  expr_t     theExpr;
+
+public:
+  SERIALIZABLE_CLASS(var_set_expr)
+  SERIALIZABLE_CLASS_CONSTRUCTOR2(var_set_expr, expr)
+  void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+  var_set_expr(
+      static_context* sctx,
+      const QueryLoc& loc,
+      const var_expr_t& varExpr,
+      const expr_t& setExpr);
+
+  var_expr* get_var_expr() const { return theVarExpr.getp(); }
+
+  expr* get_expr() const { return theExpr.getp(); }
+
+  void compute_scripting_kind();
+
+  expr_t clone(substitution_t& s) const;
+
+  void accept(expr_visitor&);
+
+  std::ostream& put(std::ostream&) const;
+};
+
+
+/*******************************************************************************
   ExitExpr ::= "exit" "with" ExprSingle
 ********************************************************************************/
 class exit_expr : public expr 

=== modified file 'src/compiler/expression/var_expr.h'
--- src/compiler/expression/var_expr.h	2011-11-01 14:26:48 +0000
+++ src/compiler/expression/var_expr.h	2011-11-17 17:26:00 +0000
@@ -133,10 +133,10 @@
 
 public:
   var_expr(
-        static_context* sctx,
-        const QueryLoc& loc,
-        var_kind k,
-        store::Item* name);
+      static_context* sctx,
+      const QueryLoc& loc,
+      var_kind k,
+      store::Item* name);
 
   ulong get_unique_id() const { return theUniqueId; }
 

=== modified file 'src/compiler/rewriter/rules/nodeid_rules.cpp'
--- src/compiler/rewriter/rules/nodeid_rules.cpp	2011-11-10 14:06:57 +0000
+++ src/compiler/rewriter/rules/nodeid_rules.cpp	2011-11-17 17:26:00 +0000
@@ -124,9 +124,9 @@
   case block_expr_kind :
   {
     block_expr* seqExpr = static_cast<block_expr *>(node);
-    ulong numChildren = seqExpr->size();
+    csize numChildren = seqExpr->size();
 
-    for (ulong i = 0; i < numChildren-1; ++i)
+    for (csize i = 0; i < numChildren-1; ++i)
     {
       expr_t& child = (*seqExpr)[i];
       set_ignores_sorted_nodes(child.getp(), ANNOTATION_TRUE);
@@ -163,6 +163,7 @@
   }
 
   case var_decl_expr_kind :
+  case var_set_expr_kind :
   {
     break;
   }
@@ -193,7 +194,7 @@
     // Process the clauses in reverse order so that by the time we reach the
     // definition of a LET var, we know if the LET var sequence must be in
     // doc order and/or without duplicates.
-    ulong i = flwor->num_clauses();
+    csize i = flwor->num_clauses();
     for (; i > 0; --i)
     {
       flwor_clause* clause = flwor->get_clause(i-1);
@@ -248,9 +249,9 @@
         // apply the rule recursively on the orderby exprs
         orderby_clause* oc = static_cast<orderby_clause*>(clause);
       
-        ulong numExprs = oc->num_columns();
+        csize numExprs = oc->num_columns();
       
-        for (ulong i = 0; i < numExprs; ++i)
+        for (csize i = 0; i < numExprs; ++i)
         {
           apply(rCtx, oc->get_column_expr(i), modified);
         }
@@ -376,9 +377,9 @@
     
     FunctionConsts::FunctionKind fkind = f->getKind();
     
-    ulong numArgs = fo->num_args();
+    csize numArgs = fo->num_args();
     
-    for (ulong i = 0; i < numArgs; ++i)
+    for (csize i = 0; i < numArgs; ++i)
     {
       expr* arg = fo->get_arg(i);
         

=== modified file 'src/compiler/rewriter/tools/dataflow_annotations.cpp'
--- src/compiler/rewriter/tools/dataflow_annotations.cpp	2011-08-12 10:21:10 +0000
+++ src/compiler/rewriter/tools/dataflow_annotations.cpp	2011-11-17 17:26:00 +0000
@@ -60,6 +60,10 @@
     compute_var_decl_expr(static_cast<var_decl_expr*>(e));
     break;
 
+  case var_set_expr_kind:
+    compute_var_set_expr(static_cast<var_set_expr*>(e));
+    break;
+
   case block_expr_kind:
     compute_block_expr(static_cast<block_expr *>(e));
     break;
@@ -293,6 +297,16 @@
 /*******************************************************************************
 
 ********************************************************************************/
+void DataflowAnnotationsComputer::compute_var_set_expr(var_set_expr* e)
+{
+  generic_compute(e);
+  default_walk(e);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
 void DataflowAnnotationsComputer::compute_block_expr(block_expr* e)
 {
   default_walk(e);

=== modified file 'src/compiler/rewriter/tools/dataflow_annotations.h'
--- src/compiler/rewriter/tools/dataflow_annotations.h	2011-06-14 17:26:33 +0000
+++ src/compiler/rewriter/tools/dataflow_annotations.h	2011-11-17 17:26:00 +0000
@@ -36,6 +36,7 @@
   void compute_block_expr(block_expr* e);
   void compute_wrapper_expr(wrapper_expr* e);
   void compute_var_expr(var_expr* e);
+  void compute_var_set_expr(var_set_expr* e);
   void compute_flwor_expr(flwor_expr* e);
   void compute_trycatch_expr(trycatch_expr* e);
   void compute_promote_expr(promote_expr* e);

=== modified file 'src/compiler/rewriter/tools/expr_tools.cpp'
--- src/compiler/rewriter/tools/expr_tools.cpp	2011-10-05 19:22:52 +0000
+++ src/compiler/rewriter/tools/expr_tools.cpp	2011-11-17 17:26:00 +0000
@@ -269,17 +269,17 @@
         const group_clause* gc = static_cast<const group_clause *>(c);
 
         const flwor_clause::rebind_list_t& gvars = gc->get_grouping_vars();
-        unsigned numGroupVars = (unsigned)gvars.size();
+        csize numGroupVars = gvars.size();
 
-        for (unsigned i = 0; i < numGroupVars; ++i)
+        for (csize i = 0; i < numGroupVars; ++i)
         {
           add_var(gvars[i].second.getp(), numVars, varidmap, idvarmap);
         }
 
         const flwor_clause::rebind_list_t& ngvars = gc->get_nongrouping_vars();
-        unsigned numNonGroupVars = (unsigned)ngvars.size();
+        csize numNonGroupVars = ngvars.size();
 
-        for (unsigned i = 0; i < numNonGroupVars; ++i)
+        for (csize i = 0; i < numNonGroupVars; ++i)
         {
           add_var(ngvars[i].second.getp(), numVars, varidmap, idvarmap);
         }
@@ -299,8 +299,8 @@
       else if (c->get_kind() == flwor_clause::order_clause)
       {
         const orderby_clause* obc = static_cast<const orderby_clause *>(c);
-        ulong numExprs = obc->num_columns();
-        for (ulong i = 0; i < numExprs; ++i)
+        csize numExprs = obc->num_columns();
+        for (csize i = 0; i < numExprs; ++i)
         {
           index_flwor_vars(obc->get_column_expr(i), numVars, varidmap, idvarmap);
         }

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2011-11-16 04:02:48 +0000
+++ src/compiler/translator/translator.cpp	2011-11-17 17:26:00 +0000
@@ -1838,17 +1838,17 @@
 
   The corresponding expr created here (and added to stmts) are:
 
-  1. var_dec_expr(varExpr, initExpr)
-
-  2. var_dec_expr(varExpr, initExpr)
-
-     In this case, the var_dec_expr will be a NOOP if a value has been assigned
+  1. var_decl_expr(varExpr, initExpr)
+
+  2. var_decl_expr(varExpr, initExpr)
+
+     In this case, the var_decl_expr will be a NOOP if a value has been assigned
      to the external var via the c++ api. If so, this value overrides the
      initializing expr in the prolog.
 
-  3. var_dec_expr(varExpr)
+  3. var_decl_expr(varExpr)
 
-  4. var_dec_expr(varExpr)
+  4. var_decl_expr(varExpr)
 
      In this case, the variable must be initialized via the c++ api before the
      query is executed, and it is this external intialization that will declare
@@ -5457,11 +5457,7 @@
   if (varType != NULL)
     valueExpr = new treat_expr(theRootSctx, loc, valueExpr, varType, err::XPTY0004);
 
-  push_nodestack(new fo_expr(theRootSctx,
-                             loc,
-                             GET_BUILTIN_FUNCTION(OP_VAR_ASSIGN_1),
-                             ve,
-                             valueExpr));
+  push_nodestack(new var_set_expr(theRootSctx, loc, ve, valueExpr));
 
   theAssignedVars.back().push_back(ve.getp());
 }

=== modified file 'src/functions/func_var_decl.cpp'
--- src/functions/func_var_decl.cpp	2011-07-29 06:13:28 +0000
+++ src/functions/func_var_decl.cpp	2011-11-17 17:26:00 +0000
@@ -32,63 +32,6 @@
 
 
 /*******************************************************************************
-  ctxvar-assign(varExpr, initExpr)
-
-  This internal function is used to initialize prolog variables (including the
-  context item, if it is declared in the prolog) that do have an initializing
-  expr, or to assign a value to a prolog or block-local var. During runtime,
-  the function computes the initExpr and stores the resulting value inside the
-  appropriate dynamic ctx (global or local), at the location that is identified
-  by the variable id.
-********************************************************************************/
-class ctx_var_assign : public function
-{
-public:
-  ctx_var_assign(const signature& sig) 
-    :
-    function(sig, FunctionConsts::OP_VAR_ASSIGN_1)
-  {
-  }
-
-  bool accessesDynCtx() const { return true; }
-
-  short getScriptingKind() const { return VAR_SETTING_EXPR; }
-
-  CODEGEN_DECL();
-};
-
-
-PlanIter_t ctx_var_assign::codegen(
-    CompilerCB* cb,
-    static_context* sctx,
-    const QueryLoc& loc,
-    std::vector<PlanIter_t>& argv,
-    AnnotationHolder& ann) const
-{
-  const fo_expr& foExpr = static_cast<const fo_expr&>(ann);
-
-  assert(foExpr.get_arg(0)->get_expr_kind() == var_expr_kind);
-
-  const var_expr* varExpr = static_cast<const var_expr*>(foExpr.get_arg(0));
-
-  xqtref_t exprType = foExpr.get_arg(1)->get_return_type();
-
-  CtxVarAssignIterator* iter = 
-  new CtxVarAssignIterator(sctx,
-                           loc,
-                           varExpr->get_unique_id(),
-                           varExpr->get_name(),
-                           (varExpr->get_kind() == var_expr::local_var),
-                           argv[1]);
-  
-  if (exprType->get_quantifier() == TypeConstants::QUANT_ONE)
-    iter->setSingleItem();
-
-  return iter;
-}
-
-
-/*******************************************************************************
   ctxvar-get(varExpr)
 
   An "artificial" function that is needed by the optimizer only. During runtime,
@@ -142,12 +85,6 @@
 {
   const char* zorba_op_ns = static_context::ZORBA_OP_NS.c_str();
 
-  DECL(sctx, ctx_var_assign,
-       (createQName(zorba_op_ns, "", "ctxvar-assign"),
-        GENV_TYPESYSTEM.ITEM_TYPE_ONE,
-        GENV_TYPESYSTEM.ITEM_TYPE_STAR,
-        GENV_TYPESYSTEM.EMPTY_TYPE));
-
   DECL(sctx, ctx_var_get,
        (createQName(zorba_op_ns, "", "ctxvar-get"),
         GENV_TYPESYSTEM.ITEM_TYPE_ONE,

=== modified file 'src/functions/function_consts.h'
--- src/functions/function_consts.h	2011-07-28 15:28:16 +0000
+++ src/functions/function_consts.h	2011-11-17 17:26:00 +0000
@@ -205,7 +205,6 @@
   OP_AND_N,
   OP_OR_N,
 
-  OP_VAR_ASSIGN_1,
   OP_VAR_GET_1,
 
   OP_EITHER_NODES_OR_ATOMICS_1,

-- 
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