~juan457/+junk/zorba

« back to all changes in this revision

Viewing changes to exprtree/eval.cpp

  • Committer: paulped at ETHZ
  • Date: 2007-01-25 19:55:55 UTC
  • Revision ID: svn-v4:8046edc3-af21-0410-8661-ec7318497eea:trunk/zorba:334
added nodeid service to context
added a test data directory 'wordlists'
miscellaneous bug fixes, unit testing improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
namespace xqp {
26
26
 
27
27
 
 
28
/*...........................................
 
29
        : expr                                    :
 
30
        :.........................................:
 
31
*/
 
32
 
28
33
rchandle<item_iterator> expr::eval(
29
34
        context& ctx)
30
35
{
35
40
}
36
41
 
37
42
 
 
43
/*...........................................
 
44
        : literal expr                            :
 
45
        :.........................................:
 
46
*/
 
47
 
38
48
rchandle<item_iterator> literal_expr::eval(
39
49
        context& ctx)
40
50
{
42
52
        cout << __FUNCTION__ << endl;
43
53
#endif
44
54
        switch (type) {
45
 
        case lit_string: return new singleton_iterator(ctx,ctx.symtab.get(sref)); 
 
55
        case lit_string: {
 
56
        return new singleton_iterator(ctx,ctx.string_storage.get(sref));
 
57
        }
46
58
        case lit_integer: return new singleton_iterator(ctx,ival);
47
59
        case lit_decimal: return new singleton_iterator(ctx,decval);
48
60
        case lit_double: return new singleton_iterator(ctx,dval);
51
63
}
52
64
 
53
65
 
 
66
/*...........................................
 
67
        : expr_list                               :
 
68
        :.........................................:
 
69
*/
 
70
 
54
71
rchandle<item_iterator> expr_list::eval(
55
72
        context & ctx) 
56
73
{
68
85
}
69
86
 
70
87
 
 
88
/*...........................................
 
89
        : var_expr                                :
 
90
        :.........................................:
 
91
*/
 
92
 
71
93
rchandle<item_iterator> var_expr::eval(
72
94
        context & ctx) 
73
95
{
85
107
}
86
108
 
87
109
 
 
110
/*...........................................
 
111
        : flwor_expr                              :
 
112
        :.........................................:
 
113
*/
 
114
 
88
115
rchandle<item_iterator> flwor_expr::eval(
89
116
        context & ctx) 
90
117
{
123
150
}
124
151
 
125
152
 
 
153
/*...........................................
 
154
        : quantified_expr                         :
 
155
        :.........................................:
 
156
*/
 
157
 
126
158
rchandle<item_iterator> quantified_expr::eval(
127
159
        context & ctx) 
128
160
{
149
181
}
150
182
 
151
183
 
 
184
/*...........................................
 
185
        : typeswitch_expr                         :
 
186
        :.........................................:
 
187
*/
 
188
 
152
189
rchandle<item_iterator> typeswitch_expr::eval(
153
190
        context & ctx)
154
191
{
169
206
}
170
207
 
171
208
 
 
209
/*...........................................
 
210
        : if_expr                                 :
 
211
        :.........................................:
 
212
*/
 
213
 
172
214
rchandle<item_iterator> if_expr::eval(
173
215
        context & ctx)
174
216
{
187
229
}
188
230
 
189
231
 
 
232
/*...........................................
 
233
        : fo_expr                                 :
 
234
        :.........................................:
 
235
*/
 
236
 
190
237
rchandle<item_iterator> fo_expr::eval(
191
238
        context & ctx)
192
239
{
203
250
}
204
251
 
205
252
 
 
253
/*...........................................
 
254
        : text_expr                               :
 
255
        :.........................................:
 
256
*/
 
257
 
206
258
rchandle<item_iterator> text_expr::eval(
207
259
        context & ctx)
208
260
{
209
261
        Assert<null_pointer>(text_expr_h!=NULL);
210
262
        rchandle<item_iterator> it_h = text_expr_h->eval(ctx);
211
 
        item_iterator* it_p = &*it_h;
212
 
        Assert<null_pointer>(it_p!=NULL);
213
 
        ostringstream oss;
214
 
        while (!it_p->done()) {
215
 
                rchandle<item> i_h = it_p->next();
216
 
                item* i_p = &*i_h;
217
 
                Assert<null_pointer>(i_p!=NULL);
218
 
                i_p->put(oss,ctx);
219
 
        }
220
 
        rchandle<text_node> tnode_h = new text_node(rand(),oss.str(),NULL);
 
263
        string content = it_h->string_value(ctx);
 
264
 
 
265
        rchandle<text_node> tnode_h =
 
266
                new text_node(ctx.next_nodeid(),content,ctx.context_nodeid());
 
267
 
221
268
        return new singleton_iterator(ctx, &*tnode_h);
222
269
}
223
270
 
224
271
 
 
272
/*...........................................
 
273
        : comment_expr                            :
 
274
        :.........................................:
 
275
*/
 
276
 
225
277
rchandle<item_iterator> comment_expr::eval(
226
278
        context & ctx)
227
279
{
231
283
 
232
284
 
233
285
 
234
 
 
235
 
 
236
 
 
 
286
/*...........................................
 
287
        : doc_expr                                :
 
288
        :.........................................:
 
289
*/
 
290
 
 
291
rchandle<item_iterator> doc_expr::eval(
 
292
        context t& ctx) 
 
293
{
 
294
        Assert<null_pointer>(docuri_h!=NULL);
 
295
        return docuri_h->eval(ctx);
 
296
}
 
297
 
 
298
 
 
299
 
 
300
/*...........................................
 
301
        : elem_expr                               :
 
302
        :.........................................:
 
303
*/
 
304
 
 
305
rchandle<item_iterator> elem_expr::eval(
 
306
        context & ctx) 
 
307
{
 
308
        Assert<bad_arg>(qname_h!=NULL || qname_expr_h!=NULL);
 
309
        if (qname_h!=NULL) {
 
310
                qname_h->put(os,ctx) << ">\n";
 
311
        }
 
312
        else {
 
313
                qname_expr_h->put(os,ctx) << ">\n";
 
314
        }
 
315
        vector<nsbinding>::const_iterator it = begin();
 
316
        vector<nsbinding>::const_iterator en = end();
 
317
        for (; it!=en; ++it) {
 
318
                nsbinding nsb = *it;
 
319
                string ncname = nsb.first;
 
320
                string nsuri = nsb.second;
 
321
                os << INDENT << "xmlns:" << ncname << "=\"" << nsuri << "\"\n"; UNDENT;
 
322
        }
 
323
        Assert<null_pointer>(content_expr_h!=NULL);
 
324
        content_expr_h->put(os,ctx);
 
325
}
 
326
 
 
327
 
 
328
 
 
329
/*...........................................
 
330
        : attr_expr                               :
 
331
        :.........................................:
 
332
*/
 
333
 
 
334
rchandle<item_iterator> attr_expr::eval(
 
335
        context & ctx) 
 
336
{
 
337
        Assert<bad_arg>(qname_h!=NULL || qname_expr_h!=NULL);
 
338
        if (qname_h!=NULL) {
 
339
                qname_h->put(os,ctx);
 
340
        }
 
341
        else {
 
342
                qname_expr_h->put(os,ctx);
 
343
        }
 
344
 
 
345
        Assert<null_pointer>(val_expr_h!=NULL);
 
346
        rchandle<item_iterator> val_h = val_expr_h->eval(ctx);
 
347
 
 
348
 
 
349
        rchandle<item> i_h = ctx.get_context_item();
 
350
        elem_node* n_p = dynamic_cast<elem_node*>(&*i_h);
 
351
        if (n_p==NULL) {
 
352
                throw xqp_exception(__FUNCTION__,"expecting element node parent");
 
353
        }
 
354
 
 
355
        rchandle<attr_node> anode_h =
 
356
                new attr_node(rand(), name_h, value, n_p->get_nodeid());
 
357
 
 
358
        return new singleton_iterator(ctx, &*anode_h);
 
359
 
 
360
}
237
361
 
238
362
 
239
363