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
1=== modified file 'bin/zorbacmd.cpp'
2--- bin/zorbacmd.cpp 2014-02-20 00:58:25 +0000
3+++ bin/zorbacmd.cpp 2014-04-25 23:55:27 +0000
4@@ -250,7 +250,7 @@
5 dctx->setVariable( i->var_name, doc );
6 } else {
7 Item item( zorba->getItemFactory()->createString( i->var_value ) );
8- dctx->setVariable( i->var_name, item );
9+ dctx->setVariable( i->var_name, item, true );
10 }
11 }
12 catch ( ... ) {
13
14=== modified file 'include/zorba/dynamic_context.h'
15--- include/zorba/dynamic_context.h 2013-08-14 08:46:44 +0000
16+++ include/zorba/dynamic_context.h 2014-04-25 23:55:27 +0000
17@@ -59,13 +59,16 @@
18 *
19 * @param aQName the QName that identifies the external variable.
20 * @param aItem the Item that is used as value for the variable.
21+ * @param cast If \c true, attempt to cast \a aItem to the type (if any) that
22+ * the external variable was declared as.
23 * @return true if the variable has been set, false otherwise.
24 * @throw ZorbaException if an error occured (e.g. the given Item is not valid).
25 */
26 virtual bool
27 setVariable(
28 const String& aQName,
29- const Item& aItem) = 0;
30+ const Item& aItem,
31+ bool cast = false) = 0;
32
33 /**
34 * \brief Defines the external variable identified by an expanded QName and
35@@ -77,6 +80,8 @@
36 * @param aNamespace the namespace URI of the variable's expanded QName
37 * @param aLocalname the local name of the variable's expanded QName
38 * @param aItem the Item that is used as value for the variable.
39+ * @param cast If \c true, attempt to cast \a aItem to the type (if any) that
40+ * the external variable was declared as.
41 * @return true if the variable has been set successfully, false otherwise.
42 * @throw ZorbaException if an error occured (e.g. the given Item is not valid).
43 */
44@@ -84,7 +89,8 @@
45 setVariable(
46 const String& inNamespace,
47 const String& inLocalname,
48- const Item& inValue) = 0;
49+ const Item& inValue,
50+ bool cast = false) = 0;
51
52 /**
53 * \brief Defines the external variable identified by aQName and assigns it
54
55=== modified file 'src/api/dynamiccontextimpl.cpp'
56--- src/api/dynamiccontextimpl.cpp 2013-09-16 09:08:27 +0000
57+++ src/api/dynamiccontextimpl.cpp 2014-04-25 23:55:27 +0000
58@@ -36,6 +36,7 @@
59 #include "api/item_iter_store.h"
60 #include "api/dynamiccontextimpl.h"
61
62+#include "compiler/expression/var_expr.h"
63 #include "compiler/parser/query_loc.h"
64 #include "compiler/parsetree/parsenodes.h"
65 #include "compiler/api/compilercb.h"
66@@ -46,6 +47,7 @@
67 #include "store/api/store.h"
68 #include "store/api/item_factory.h"
69 #include "store/api/temp_seq.h"
70+#include "types/casting.h"
71
72 #include "util/xml_util.h"
73
74@@ -334,7 +336,8 @@
75 bool DynamicContextImpl::setVariable(
76 const String& inNamespace,
77 const String& inLocalname,
78- const Item& inValue)
79+ const Item& inValue,
80+ bool cast)
81 {
82 ZORBA_DCTX_TRY
83 {
84@@ -364,6 +367,15 @@
85 throw;
86 }
87
88+ if ( cast && var->getType() ) {
89+ store::Item_t cast_value;
90+ GenericCast::castToAtomic(
91+ cast_value, value, var->getType(), var->getVar()->get_type_manager(),
92+ /*nsCtx*/ nullptr, QueryLoc::null
93+ );
94+ value = cast_value;
95+ }
96+
97 ulong varId = var->getId();
98
99 theCtx->add_variable(varId, value);
100@@ -380,7 +392,8 @@
101 ********************************************************************************/
102 bool DynamicContextImpl::setVariable(
103 const String& inVarName,
104- const Item& inValue)
105+ const Item& inValue,
106+ bool cast)
107 {
108 ZORBA_DCTX_TRY
109 {
110@@ -410,6 +423,15 @@
111 throw;
112 }
113
114+ if ( cast && var->getType() ) {
115+ store::Item_t cast_value;
116+ GenericCast::castToAtomic(
117+ cast_value, value, var->getType(), var->getVar()->get_type_manager(),
118+ /*nsCtx*/ nullptr, QueryLoc::null
119+ );
120+ value = cast_value;
121+ }
122+
123 ulong varId = var->getId();
124
125 theCtx->add_variable(varId, value);
126
127=== modified file 'src/api/dynamiccontextimpl.h'
128--- src/api/dynamiccontextimpl.h 2013-08-01 07:57:57 +0000
129+++ src/api/dynamiccontextimpl.h 2014-04-25 23:55:27 +0000
130@@ -96,13 +96,15 @@
131 virtual bool
132 setVariable(
133 const String& inVarName,
134- const Item& inValue);
135+ const Item& inValue,
136+ bool cast = false);
137
138 virtual bool
139 setVariable(
140 const String& inNamespace,
141 const String& inLocalname,
142- const Item& inValue);
143+ const Item& inValue,
144+ bool cast = false);
145
146 virtual bool
147 setVariable(

Subscribers

People subscribed via source and target branches