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

Commit message:
Add try/catch extension to introspect the end line and end column number of the 
error.

Requested reviews:
  William Candillon (wcandillon)
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/trycatch-extension/+merge/152171

Add try/catch extension to introspect the end line and end column number of the 
error.
This extension is especially useful for Zorba support in IDEs.
-- 
https://code.launchpad.net/~zorba-coders/zorba/trycatch-extension/+merge/152171
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp	2013-03-05 16:40:27 +0000
+++ src/compiler/codegen/plan_visitor.cpp	2013-03-07 13:24:42 +0000
@@ -2093,6 +2093,12 @@
       case catch_clause::zerr_data_column_no:
         rcc.theVars[TryCatchIterator::CatchClause::zerr_data_column_no] = *vec;
         break;
+      case catch_clause::zerr_line_no_end:
+        rcc.theVars[TryCatchIterator::CatchClause::zerr_line_no_end] = *vec;
+        break;
+      case catch_clause::zerr_column_no_end:
+        rcc.theVars[TryCatchIterator::CatchClause::zerr_column_no_end] = *vec;
+        break;
       case catch_clause::zerr_stack_trace:
         rcc.theVars[TryCatchIterator::CatchClause::zerr_stack_trace] = *vec;
         break;

=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h	2013-03-05 12:34:19 +0000
+++ src/compiler/expression/expr.h	2013-03-07 13:24:42 +0000
@@ -989,6 +989,8 @@
     zerr_data_uri,
     zerr_data_line_no,
     zerr_data_column_no,
+    zerr_line_no_end,
+    zerr_column_no_end,
     zerr_stack_trace
   };
 

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2013-03-07 10:10:10 +0000
+++ src/compiler/translator/translator.cpp	2013-03-07 13:24:42 +0000
@@ -7862,7 +7862,7 @@
   push_scope();
 
   store::Item_t lCode, lDesc, lValue, lModule, lLineNo, lColumnNo,
-                lDataURI, lDataLineNo, lDataColumnNo, lStackTrace;
+                lDataURI, lDataLineNo, lDataColumnNo, lLineNoEnd, lColumnNoEnd, lStackTrace;
 
   GENV_ITEMFACTORY->createQName(lCode, XQUERY_ERR_NS, "", "code");
   GENV_ITEMFACTORY->createQName(lDesc, XQUERY_ERR_NS, "", "description");
@@ -7873,6 +7873,8 @@
   GENV_ITEMFACTORY->createQName(lDataURI, ZORBA_ERR_NS, "", "data-uri");
   GENV_ITEMFACTORY->createQName(lDataLineNo, ZORBA_ERR_NS, "", "data-line-number");
   GENV_ITEMFACTORY->createQName(lDataColumnNo, ZORBA_ERR_NS, "", "data-column-number");
+  GENV_ITEMFACTORY->createQName(lLineNoEnd, ZORBA_ERR_NS, "", "line-number-end");
+  GENV_ITEMFACTORY->createQName(lColumnNoEnd, ZORBA_ERR_NS, "", "column-number-end");
   GENV_ITEMFACTORY->createQName(lStackTrace, ZORBA_ERR_NS, "", "stack-trace");
 
   cc->add_var(catch_clause::err_code,
@@ -7902,6 +7904,12 @@
   cc->add_var(catch_clause::zerr_data_column_no,
       bind_var(loc, lDataColumnNo, var_expr::catch_var, theRTM.INTEGER_TYPE_QUESTION));
 
+  cc->add_var(catch_clause::zerr_line_no_end,
+      bind_var(loc, lLineNoEnd, var_expr::catch_var, theRTM.INTEGER_TYPE_QUESTION));
+
+  cc->add_var(catch_clause::zerr_column_no_end,
+      bind_var(loc, lColumnNoEnd, var_expr::catch_var, theRTM.INTEGER_TYPE_QUESTION));
+
   cc->add_var(catch_clause::zerr_stack_trace,
       bind_var(loc, lStackTrace, var_expr::catch_var, theRTM.ITEM_TYPE_QUESTION));
 

=== modified file 'src/runtime/core/trycatch.cpp'
--- src/runtime/core/trycatch.cpp	2013-02-26 04:12:43 +0000
+++ src/runtime/core/trycatch.cpp	2013-03-07 13:24:42 +0000
@@ -585,6 +585,62 @@
         }
         break;
       }
+      case CatchClause::zerr_line_no_end:
+      {
+        LetVarConstIter lErrorLineVarIter = lIter->second.begin();
+        LetVarConstIter lErrorLineVarIterEnd = lIter->second.end();
+
+
+        for ( ; lErrorLineVarIter != lErrorLineVarIterEnd; lErrorLineVarIter++ )
+        {
+          store::Iterator_t lErrorLineIter;
+
+          XQueryException const *ue;
+	        if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&
+               ue->has_source() ) {
+            store::Item_t lErrorLineItem;
+            GENV_ITEMFACTORY->createInteger(
+                lErrorLineItem, xs_integer(ue->source_line_end()));
+            lErrorLineIter = new ItemIterator(lErrorLineItem);
+	        }
+          else
+          {
+            lErrorLineIter = new ItemIterator();
+          }
+          lErrorLineIter->open();
+          state->theErrorIters.push_back(lErrorLineIter);
+          (*lErrorLineVarIter)->bind(lErrorLineIter, planState);
+        }
+      }
+      break;
+      case CatchClause::zerr_column_no_end:
+      {
+        LetVarConstIter lErrorColumnVarIter = lIter->second.begin();
+        LetVarConstIter lErrorColumnVarIterEnd = lIter->second.end();
+
+        for ( ; lErrorColumnVarIter != lErrorColumnVarIterEnd; lErrorColumnVarIter++ )
+        {
+          store::Iterator_t lErrorColumnIter;
+
+          XQueryException const *ue;
+	        if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&
+               ue->has_source() ) {
+            store::Item_t lErrorColumnItem;
+            GENV_ITEMFACTORY->createInteger(
+                lErrorColumnItem, xs_integer(ue->source_column_end()));
+            lErrorColumnIter = new ItemIterator(lErrorColumnItem);
+	        }
+          else
+          {
+            lErrorColumnIter = new ItemIterator();
+          }
+          lErrorColumnIter->open();
+          state->theErrorIters.push_back(lErrorColumnIter);
+          (*lErrorColumnVarIter)->bind(lErrorColumnIter, planState);
+        }
+      break;
+      }
+
 
       case CatchClause::zerr_stack_trace:
       {

=== modified file 'src/runtime/core/trycatch.h'
--- src/runtime/core/trycatch.h	2013-02-26 04:12:43 +0000
+++ src/runtime/core/trycatch.h	2013-03-07 13:24:42 +0000
@@ -61,6 +61,8 @@
       err_module,
       err_line_no,
       err_column_no,
+      zerr_line_no_end,
+      zerr_column_no_end,
       zerr_data_uri,
       zerr_data_line_no,
       zerr_data_column_no,

=== added file 'test/rbkt/ExpQueryResults/zorba/trycatch/trycatch16.xml.res'
--- test/rbkt/ExpQueryResults/zorba/trycatch/trycatch16.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/trycatch/trycatch16.xml.res	2013-03-07 13:24:42 +0000
@@ -0,0 +1,1 @@
+5 3 7 4

=== added file 'test/rbkt/Queries/zorba/trycatch/trycatch16.xq'
--- test/rbkt/Queries/zorba/trycatch/trycatch16.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/trycatch/trycatch16.xq	2013-03-07 13:24:42 +0000
@@ -0,0 +1,13 @@
+declare namespace err = "http://www.w3.org/2005/xqt-errors";;
+declare namespace zerr = "http://www.zorba-xquery.com/errors";;
+
+try {
+  1
+  div
+  0
+} catch * {
+  $err:line-number,
+  $err:column-number,
+  $zerr:line-number-end,
+  $zerr:column-number-end
+}

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