Merge lp:~zorba-coders/zorba/feature-setvar-typed into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 11719
Merged at revision: 11718
Proposed branch: lp:~zorba-coders/zorba/feature-setvar-typed
Merge into: lp:zorba
Diff against target: 147 lines (+37/-7)
4 files modified
bin/zorbacmd.cpp (+1/-1)
include/zorba/dynamic_context.h (+8/-2)
src/api/dynamiccontextimpl.cpp (+24/-2)
src/api/dynamiccontextimpl.h (+4/-2)
To merge this branch: bzr merge lp:~zorba-coders/zorba/feature-setvar-typed
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+217313@code.launchpad.net

Commit message

1. Added the ability to do casting when setting the value of an external variable.
2. The zorba command now always requests casting.

Description of the change

1. Added the ability to do casting when setting the value of an external variable.
2. The zorba command now always requests casting.

To post a comment you must log in.
11719. By Paul J. Lucas

Added "cast" to other setVariable().

Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting criteria failed for the following merge proposals:

https://code.launchpad.net/~zorba-coders/zorba/feature-setvar-typed/+merge/217313 :
Votes: {'Approve': 1, 'Pending': 1}

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~zorba-coders/zorba/feature-setvar-typed/+merge/217313

Stage "CommitZorba" failed.

Check console output at http://jenkins.lambda.nu:8180/job/CommitZorba/323/console to view the results.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp 2014-02-20 00:58:25 +0000
+++ bin/zorbacmd.cpp 2014-04-25 23:55:27 +0000
@@ -250,7 +250,7 @@
250 dctx->setVariable( i->var_name, doc );250 dctx->setVariable( i->var_name, doc );
251 } else {251 } else {
252 Item item( zorba->getItemFactory()->createString( i->var_value ) );252 Item item( zorba->getItemFactory()->createString( i->var_value ) );
253 dctx->setVariable( i->var_name, item );253 dctx->setVariable( i->var_name, item, true );
254 }254 }
255 }255 }
256 catch ( ... ) {256 catch ( ... ) {
257257
=== modified file 'include/zorba/dynamic_context.h'
--- include/zorba/dynamic_context.h 2013-08-14 08:46:44 +0000
+++ include/zorba/dynamic_context.h 2014-04-25 23:55:27 +0000
@@ -59,13 +59,16 @@
59 *59 *
60 * @param aQName the QName that identifies the external variable.60 * @param aQName the QName that identifies the external variable.
61 * @param aItem the Item that is used as value for the variable.61 * @param aItem the Item that is used as value for the variable.
62 * @param cast If \c true, attempt to cast \a aItem to the type (if any) that
63 * the external variable was declared as.
62 * @return true if the variable has been set, false otherwise.64 * @return true if the variable has been set, false otherwise.
63 * @throw ZorbaException if an error occured (e.g. the given Item is not valid).65 * @throw ZorbaException if an error occured (e.g. the given Item is not valid).
64 */66 */
65 virtual bool67 virtual bool
66 setVariable(68 setVariable(
67 const String& aQName,69 const String& aQName,
68 const Item& aItem) = 0;70 const Item& aItem,
71 bool cast = false) = 0;
6972
70 /** 73 /**
71 * \brief Defines the external variable identified by an expanded QName and74 * \brief Defines the external variable identified by an expanded QName and
@@ -77,6 +80,8 @@
77 * @param aNamespace the namespace URI of the variable's expanded QName80 * @param aNamespace the namespace URI of the variable's expanded QName
78 * @param aLocalname the local name of the variable's expanded QName81 * @param aLocalname the local name of the variable's expanded QName
79 * @param aItem the Item that is used as value for the variable.82 * @param aItem the Item that is used as value for the variable.
83 * @param cast If \c true, attempt to cast \a aItem to the type (if any) that
84 * the external variable was declared as.
80 * @return true if the variable has been set successfully, false otherwise.85 * @return true if the variable has been set successfully, false otherwise.
81 * @throw ZorbaException if an error occured (e.g. the given Item is not valid).86 * @throw ZorbaException if an error occured (e.g. the given Item is not valid).
82 */87 */
@@ -84,7 +89,8 @@
84 setVariable(89 setVariable(
85 const String& inNamespace,90 const String& inNamespace,
86 const String& inLocalname,91 const String& inLocalname,
87 const Item& inValue) = 0;92 const Item& inValue,
93 bool cast = false) = 0;
8894
89 /**95 /**
90 * \brief Defines the external variable identified by aQName and assigns it96 * \brief Defines the external variable identified by aQName and assigns it
9197
=== modified file 'src/api/dynamiccontextimpl.cpp'
--- src/api/dynamiccontextimpl.cpp 2013-09-16 09:08:27 +0000
+++ src/api/dynamiccontextimpl.cpp 2014-04-25 23:55:27 +0000
@@ -36,6 +36,7 @@
36#include "api/item_iter_store.h"36#include "api/item_iter_store.h"
37#include "api/dynamiccontextimpl.h"37#include "api/dynamiccontextimpl.h"
3838
39#include "compiler/expression/var_expr.h"
39#include "compiler/parser/query_loc.h"40#include "compiler/parser/query_loc.h"
40#include "compiler/parsetree/parsenodes.h"41#include "compiler/parsetree/parsenodes.h"
41#include "compiler/api/compilercb.h"42#include "compiler/api/compilercb.h"
@@ -46,6 +47,7 @@
46#include "store/api/store.h"47#include "store/api/store.h"
47#include "store/api/item_factory.h"48#include "store/api/item_factory.h"
48#include "store/api/temp_seq.h"49#include "store/api/temp_seq.h"
50#include "types/casting.h"
4951
50#include "util/xml_util.h"52#include "util/xml_util.h"
5153
@@ -334,7 +336,8 @@
334bool DynamicContextImpl::setVariable(336bool DynamicContextImpl::setVariable(
335 const String& inNamespace,337 const String& inNamespace,
336 const String& inLocalname,338 const String& inLocalname,
337 const Item& inValue)339 const Item& inValue,
340 bool cast)
338{341{
339 ZORBA_DCTX_TRY342 ZORBA_DCTX_TRY
340 {343 {
@@ -364,6 +367,15 @@
364 throw;367 throw;
365 }368 }
366369
370 if ( cast && var->getType() ) {
371 store::Item_t cast_value;
372 GenericCast::castToAtomic(
373 cast_value, value, var->getType(), var->getVar()->get_type_manager(),
374 /*nsCtx*/ nullptr, QueryLoc::null
375 );
376 value = cast_value;
377 }
378
367 ulong varId = var->getId();379 ulong varId = var->getId();
368380
369 theCtx->add_variable(varId, value);381 theCtx->add_variable(varId, value);
@@ -380,7 +392,8 @@
380********************************************************************************/392********************************************************************************/
381bool DynamicContextImpl::setVariable(393bool DynamicContextImpl::setVariable(
382 const String& inVarName,394 const String& inVarName,
383 const Item& inValue)395 const Item& inValue,
396 bool cast)
384{397{
385 ZORBA_DCTX_TRY398 ZORBA_DCTX_TRY
386 {399 {
@@ -410,6 +423,15 @@
410 throw;423 throw;
411 }424 }
412425
426 if ( cast && var->getType() ) {
427 store::Item_t cast_value;
428 GenericCast::castToAtomic(
429 cast_value, value, var->getType(), var->getVar()->get_type_manager(),
430 /*nsCtx*/ nullptr, QueryLoc::null
431 );
432 value = cast_value;
433 }
434
413 ulong varId = var->getId();435 ulong varId = var->getId();
414436
415 theCtx->add_variable(varId, value);437 theCtx->add_variable(varId, value);
416438
=== modified file 'src/api/dynamiccontextimpl.h'
--- src/api/dynamiccontextimpl.h 2013-08-01 07:57:57 +0000
+++ src/api/dynamiccontextimpl.h 2014-04-25 23:55:27 +0000
@@ -96,13 +96,15 @@
96 virtual bool96 virtual bool
97 setVariable(97 setVariable(
98 const String& inVarName,98 const String& inVarName,
99 const Item& inValue);99 const Item& inValue,
100 bool cast = false);
100101
101 virtual bool102 virtual bool
102 setVariable(103 setVariable(
103 const String& inNamespace,104 const String& inNamespace,
104 const String& inLocalname,105 const String& inLocalname,
105 const Item& inValue);106 const Item& inValue,
107 bool cast = false);
106108
107 virtual bool109 virtual bool
108 setVariable(110 setVariable(

Subscribers

People subscribed via source and target branches