← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/concat_operator into lp:zorba

 

William Candillon has proposed merging lp:~zorba-coders/zorba/concat_operator into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Markos Zaharioudakis (markos-za)
Related bugs:
  Bug #937120 in Zorba: "Improve error message for || "
  https://bugs.launchpad.net/zorba/+bug/937120
  Bug #942011 in Zorba: "translator should flatten a tree of StringConcatExprs"
  https://bugs.launchpad.net/zorba/+bug/942011

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/concat_operator/+merge/95147

 Optimize iterator generation for the concat operator.
-- 
https://code.launchpad.net/~zorba-coders/zorba/concat_operator/+merge/95147
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2012-02-28 20:45:43 +0000
+++ src/compiler/translator/translator.cpp	2012-02-29 10:59:26 +0000
@@ -9401,7 +9401,29 @@
   expr_t right = pop_nodestack();
   expr_t left  = pop_nodestack();
   concat_args.push_back(left);
-  concat_args.push_back(right);
+ 
+  //If the right leaf is the concat expr,
+  //we add directly its leafs to the new concat expr.
+  bool rightLeafIsConcatExpr = false;
+  if(right->get_expr_kind() == fo_expr_kind)
+  {
+    fo_expr* lFoExpr = dynamic_cast<fo_expr*>(right.getp());
+    if(lFoExpr->get_func() == GET_BUILTIN_FUNCTION(FN_CONCAT_N))
+    {
+      rightLeafIsConcatExpr = true;
+      csize i = 0;
+      for(i = 0; i < lFoExpr->num_args(); ++i)
+      {
+        concat_args.push_back(lFoExpr->get_arg(i));
+      }
+    }
+  }
+  
+  if(!rightLeafIsConcatExpr)
+  {
+    concat_args.push_back(right);
+  }
+
   rchandle<expr> concat = new fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(FN_CONCAT_N), concat_args); 
   push_nodestack(concat);
 }


Follow ups