Merge lp:~gislenius/zorba/jsoniq-truefalsenull into lp:~zorba-coders/zorba/jsoniq

Proposed by Ghislain Fourny
Status: Merged
Merged at revision: 10641
Proposed branch: lp:~gislenius/zorba/jsoniq-truefalsenull
Merge into: lp:~zorba-coders/zorba/jsoniq
Diff against target: 179 lines (+53/-37)
4 files modified
src/compiler/parser/xquery_parser.y (+5/-5)
src/compiler/parsetree/parsenodes.cpp (+4/-2)
src/compiler/parsetree/parsenodes.h (+5/-1)
src/compiler/translator/translator.cpp (+39/-29)
To merge this branch: bzr merge lp:~gislenius/zorba/jsoniq-truefalsenull
Reviewer Review Type Date Requested Status
Matthias Brantner Pending
Review via email: mp+91844@code.launchpad.net

Commit message

Allows standalone true, false, null expressions to be interpreted as booleans or nulls. User must now use ./true, ./false or ./null for XML navigation on elements named that way.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/compiler/parser/xquery_parser.y'
2--- src/compiler/parser/xquery_parser.y 2012-02-01 11:29:03 +0000
3+++ src/compiler/parser/xquery_parser.y 2012-02-07 15:07:14 +0000
4@@ -3866,7 +3866,7 @@
5 {
6 RelativePathExpr* rpe;
7
8- rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, NULL, $2);
9+ rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, NULL, $2, false);
10
11 $$ = new PathExpr(LOC(@$),
12 ParseConstants::path_leading_slash,
13@@ -3876,7 +3876,7 @@
14 {
15 RelativePathExpr* rpe;
16
17- rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, NULL, $2);
18+ rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, NULL, $2, false);
19
20 $$ = new PathExpr(LOC(@$),
21 ParseConstants::path_leading_slashslash,
22@@ -3910,17 +3910,17 @@
23 $$ = (as ?
24 new RelativePathExpr(LOC(@$),
25 ParseConstants::st_slash,
26- new ContextItemExpr( LOC(@$), true ), $1)
27+ new ContextItemExpr( LOC(@$), true ), $1, true)
28 :
29 $1);
30 }
31 | StepExpr SLASH RelativePathExpr
32 {
33- $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, $1, $3);
34+ $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, $1, $3, false);
35 }
36 | StepExpr SLASH_SLASH RelativePathExpr
37 {
38- $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, $1, $3);
39+ $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, $1, $3, false);
40 }
41 ;
42
43
44=== modified file 'src/compiler/parsetree/parsenodes.cpp'
45--- src/compiler/parsetree/parsenodes.cpp 2012-02-07 00:23:01 +0000
46+++ src/compiler/parsetree/parsenodes.cpp 2012-02-07 15:07:14 +0000
47@@ -2914,11 +2914,13 @@
48 const QueryLoc& loc_,
49 enum ParseConstants::steptype_t _step_type,
50 rchandle<exprnode> step,
51- rchandle<exprnode> rpe)
52+ rchandle<exprnode> rpe,
53+ bool implicit)
54 :
55 exprnode(loc_),
56 step_type(_step_type),
57- step_expr_h(step)
58+ step_expr_h(step),
59+ is_implicit_b(implicit)
60 {
61 RelativePathExpr* rpep = dynamic_cast<RelativePathExpr*>(rpe.getp());
62 if (rpep != NULL)
63
64=== modified file 'src/compiler/parsetree/parsenodes.h'
65--- src/compiler/parsetree/parsenodes.h 2012-02-01 11:29:03 +0000
66+++ src/compiler/parsetree/parsenodes.h 2012-02-07 15:07:14 +0000
67@@ -3541,19 +3541,23 @@
68 enum ParseConstants::steptype_t step_type;
69 rchandle<exprnode> step_expr_h;
70 rchandle<exprnode> relpath_expr_h;
71+ bool is_implicit_b;
72
73 public:
74 RelativePathExpr(
75 const QueryLoc&,
76 ParseConstants::steptype_t,
77 rchandle<exprnode>,
78- rchandle<exprnode>);
79+ rchandle<exprnode>,
80+ bool implicit);
81
82 enum ParseConstants::steptype_t get_step_type() const { return step_type; }
83
84 rchandle<exprnode> get_step_expr() const { return step_expr_h; }
85
86 rchandle<exprnode> get_relpath_expr() const { return relpath_expr_h; }
87+
88+ bool is_implicit() const { return is_implicit_b; }
89
90 virtual void accept(parsenode_visitor&) const;
91 };
92
93=== modified file 'src/compiler/translator/translator.cpp'
94--- src/compiler/translator/translator.cpp 2012-02-07 01:23:28 +0000
95+++ src/compiler/translator/translator.cpp 2012-02-07 15:07:14 +0000
96@@ -8281,44 +8281,54 @@
97
98 ParseConstants::pathtype_t pe_type = pe.get_type();
99
100- // terrible hack to allow for the value of a json pair to be
101- // null, true, false
102+ // terrible hack to allow for a standalone true, false or null to be
103+ // interpreted as a boolean. User must use ./true, ./false or ./null for
104+ // navigating XML elements named that way.
105 #ifdef ZORBA_WITH_JSON
106- if (pe_type == ParseConstants::path_relative &&
107- !theNodeStack.empty() && theNodeStack.top().dyn_cast<json_pair_expr>())
108+ if (pe_type == ParseConstants::path_relative)
109 {
110- RelativePathExpr* lRelPathExpr
111+ RelativePathExpr* lRootRelPathExpr
112 = dynamic_cast<RelativePathExpr*>(pe.get_relpath_expr().getp());
113- AxisStep* lStepExpr
114- = dynamic_cast<AxisStep*>(lRelPathExpr->get_relpath_expr().getp());
115- if (lStepExpr)
116+ ContextItemExpr* lStepExpr
117+ = dynamic_cast<ContextItemExpr*>(lRootRelPathExpr->get_step_expr().getp());
118+ AxisStep* lRelPathExpr
119+ = dynamic_cast<AxisStep*>(lRootRelPathExpr->get_relpath_expr().getp());
120+ // Only rewrites if expression consists of a context item step on the left
121+ // and of an axis step on the right,
122+ // AND if this context item was set implicitly by the parser, meaning,
123+ // the original expression was only an axis step.
124+ if (lRelPathExpr && lStepExpr && lRootRelPathExpr->is_implicit())
125 {
126 ForwardStep* lFwdStep
127- = dynamic_cast<ForwardStep*>(lStepExpr->get_forward_step().getp());
128+ = dynamic_cast<ForwardStep*>(lRelPathExpr->get_forward_step().getp());
129 if (lFwdStep && lFwdStep->get_axis_kind() == ParseConstants::axis_child)
130 {
131 AbbrevForwardStep* lAbbrFwdStep
132 = dynamic_cast<AbbrevForwardStep*>(lFwdStep->get_abbrev_step().getp());
133- const NameTest* lNodetest
134- = dynamic_cast<const NameTest*>(lAbbrFwdStep->get_node_test());
135- const rchandle<QName> lQName = lNodetest->getQName();
136- if (lQName && lQName->get_namespace() == "")
137- {
138- const zstring& lLocal = lQName->get_localname();
139- if (lLocal == "true")
140- {
141- push_nodestack(new const_expr(theRootSctx, loc, true));
142- return (void*)1;
143- } else if (lLocal == "false")
144- {
145- push_nodestack(new const_expr(theRootSctx, loc, false));
146- return (void*)1;
147- } else if (lLocal == "null")
148- {
149- store::Item_t lNull;
150- GENV_ITEMFACTORY->createJSONNull(lNull);
151- push_nodestack(new const_expr(theRootSctx, loc, lNull));
152- return (void*)1;
153+ if (lAbbrFwdStep) {
154+ const NameTest* lNodetest
155+ = dynamic_cast<const NameTest*>(lAbbrFwdStep->get_node_test());
156+ if (lNodetest) {
157+ const rchandle<QName> lQName = lNodetest->getQName();
158+ if (lQName && lQName->get_namespace() == "")
159+ {
160+ const zstring& lLocal = lQName->get_localname();
161+ if (lLocal == "true")
162+ {
163+ push_nodestack(new const_expr(theRootSctx, loc, true));
164+ return (void*)1;
165+ } else if (lLocal == "false")
166+ {
167+ push_nodestack(new const_expr(theRootSctx, loc, false));
168+ return (void*)1;
169+ } else if (lLocal == "null")
170+ {
171+ store::Item_t lNull;
172+ GENV_ITEMFACTORY->createJSONNull(lNull);
173+ push_nodestack(new const_expr(theRootSctx, loc, lNull));
174+ return (void*)1;
175+ }
176+ }
177 }
178 }
179 }

Subscribers

People subscribed via source and target branches

to all changes: