Merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba

Proposed by Markos Zaharioudakis
Status: Merged
Merged at revision: 11583
Proposed branch: lp:~zorba-coders/zorba/markos-scratch
Merge into: lp:zorba
Diff against target: 676 lines (+185/-130)
6 files modified
bin/zorbacmd.cpp (+1/-0)
src/api/staticcontextimpl.cpp (+165/-100)
src/api/staticcontextimpl.h (+8/-12)
src/api/zorbaimpl.cpp (+6/-13)
src/api/zorbaimpl.h (+3/-4)
src/context/root_static_context.cpp (+2/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/markos-scratch
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Review via email: mp+178692@code.launchpad.net

Commit message

removed StaticContextImpl::checkInvokable() method ==> small optimization for invoke()
changed static base uri for root static context

Description of the change

removed StaticContextImpl::checkInvokable() method ==> small optimization for invoke()
changed static base uri for root static context

To post a comment you must log in.
11197. By Markos Zaharioudakis

merge from trunk

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/178692

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

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 2013-08-05 11:24:53 +0000
3+++ bin/zorbacmd.cpp 2013-08-06 09:14:29 +0000
4@@ -904,6 +904,7 @@
5 ItemSequence_t docsSeq = docMgr->availableDocuments();
6 Iterator_t lIter = docsSeq->getIterator();
7 lIter->open();
8+
9 Item uri;
10 std::vector<Item> docURIs;
11 while (lIter->next(uri))
12
13=== modified file 'src/api/staticcontextimpl.cpp'
14--- src/api/staticcontextimpl.cpp 2013-08-05 11:54:06 +0000
15+++ src/api/staticcontextimpl.cpp 2013-08-06 09:14:29 +0000
16@@ -962,6 +962,9 @@
17 }
18
19
20+/*******************************************************************************
21+
22+********************************************************************************/
23 void
24 StaticContextImpl::getFunctions(
25 const String& aFnNameUri,
26@@ -992,6 +995,9 @@
27 }
28
29
30+/*******************************************************************************
31+
32+********************************************************************************/
33 void
34 StaticContextImpl::getFunctionAnnotations(
35 const Item& aQName,
36@@ -1020,6 +1026,9 @@
37 }
38
39
40+/*******************************************************************************
41+
42+********************************************************************************/
43 void
44 StaticContextImpl::setContextItemStaticType(TypeIdentifier_t type)
45 {
46@@ -1032,6 +1041,9 @@
47 }
48
49
50+/*******************************************************************************
51+
52+********************************************************************************/
53 TypeIdentifier_t
54 StaticContextImpl::getContextItemStaticType() const
55 {
56@@ -1044,6 +1056,9 @@
57 }
58
59
60+/*******************************************************************************
61+
62+********************************************************************************/
63 void
64 StaticContextImpl::setTraceStream(std::ostream& os)
65 {
66@@ -1051,6 +1066,9 @@
67 }
68
69
70+/*******************************************************************************
71+
72+********************************************************************************/
73 void
74 StaticContextImpl::resetTraceStream()
75 {
76@@ -1058,6 +1076,9 @@
77 }
78
79
80+/*******************************************************************************
81+
82+********************************************************************************/
83 bool
84 StaticContextImpl::getOption(const Item& aQName, String& aOptionValue) const
85 {
86@@ -1083,6 +1104,9 @@
87 }
88
89
90+/*******************************************************************************
91+
92+********************************************************************************/
93 void
94 StaticContextImpl::declareOption(const Item& aQName, const String& aOptionValue)
95 {
96@@ -1099,6 +1123,9 @@
97 }
98
99
100+/*******************************************************************************
101+
102+********************************************************************************/
103 void StaticContextImpl::loadProlog(
104 const String& prolog,
105 const Zorba_CompilerHints_t& hints)
106@@ -1119,6 +1146,9 @@
107 }
108
109
110+/*******************************************************************************
111+
112+********************************************************************************/
113 static void
114 toInternalPath(
115 const std::vector<String>& aPublicStrings,
116@@ -1140,6 +1170,9 @@
117 }
118
119
120+/*******************************************************************************
121+
122+********************************************************************************/
123 static void
124 toPublicPath(
125 const std::vector<zstring>& aInternalStrings,
126@@ -1153,6 +1186,9 @@
127 }
128
129
130+/*******************************************************************************
131+
132+********************************************************************************/
133 void
134 StaticContextImpl::setURIPath(const std::vector<String> &aURIPath)
135 {
136@@ -1168,6 +1204,10 @@
137 }
138 }
139
140+
141+/*******************************************************************************
142+
143+********************************************************************************/
144 void
145 StaticContextImpl::getURIPath(std::vector<String> &aURIPath) const
146 {
147@@ -1183,6 +1223,10 @@
148 }
149 }
150
151+
152+/*******************************************************************************
153+
154+********************************************************************************/
155 void
156 StaticContextImpl::getFullURIPath(std::vector<String> &aURIPath) const
157 {
158@@ -1198,6 +1242,10 @@
159 }
160 }
161
162+
163+/*******************************************************************************
164+
165+********************************************************************************/
166 void
167 StaticContextImpl::setLibPath(const std::vector<String> &aLibPath)
168 {
169@@ -1213,6 +1261,10 @@
170 }
171 }
172
173+
174+/*******************************************************************************
175+
176+********************************************************************************/
177 void
178 StaticContextImpl::getLibPath(std::vector<String> &aLibPath) const
179 {
180@@ -1228,6 +1280,10 @@
181 }
182 }
183
184+
185+/*******************************************************************************
186+
187+********************************************************************************/
188 void
189 StaticContextImpl::getFullLibPath(std::vector<String> &aLibPath) const
190 {
191@@ -1243,6 +1299,10 @@
192 }
193 }
194
195+
196+/*******************************************************************************
197+
198+********************************************************************************/
199 void StaticContextImpl::setModulePaths(const std::vector<String>& aModulePaths)
200 {
201 try
202@@ -1258,6 +1318,10 @@
203 }
204 }
205
206+
207+/*******************************************************************************
208+
209+********************************************************************************/
210 void StaticContextImpl::getModulePaths(std::vector<String>& aModulePaths) const
211 {
212 try
213@@ -1276,6 +1340,9 @@
214 }
215
216
217+/*******************************************************************************
218+
219+********************************************************************************/
220 void
221 StaticContextImpl::getFullModulePaths( std::vector<String>& aFullModulePaths ) const
222 {
223@@ -1295,6 +1362,9 @@
224 }
225
226
227+/*******************************************************************************
228+
229+********************************************************************************/
230 String
231 StaticContextImpl::resolve(const String& aRelativeUri) const
232 {
233@@ -1313,6 +1383,9 @@
234 }
235
236
237+/*******************************************************************************
238+
239+********************************************************************************/
240 String
241 StaticContextImpl::resolve(const String& aRelativeUri, const String& aBaseUri) const
242 {
243@@ -1332,6 +1405,9 @@
244 }
245
246
247+/*******************************************************************************
248+
249+********************************************************************************/
250 bool
251 StaticContextImpl::validate(
252 const Item& rootNode,
253@@ -1375,6 +1451,9 @@
254 }
255
256
257+/*******************************************************************************
258+
259+********************************************************************************/
260 bool
261 StaticContextImpl::validate(
262 const Item& rootElement,
263@@ -1450,14 +1529,75 @@
264 }
265
266
267-/**
268- * construct the query to call invoke
269- * for the QName of the function and for each argument,
270- * the query declares an external variable ($qname, $arg_1, ..., $arg_n)
271- * which needs to be bound before execution.
272- */
273-String
274-StaticContextImpl::createInvokeQuery(const Function_t& aFunc, size_t aArity) const
275+/*******************************************************************************
276+
277+********************************************************************************/
278+ItemSequence_t StaticContextImpl::invoke(
279+ const Item& aQName,
280+ const std::vector<ItemSequence_t>& aArgs) const
281+{
282+ try
283+ {
284+ store::Item_t qname = Unmarshaller::getInternalItem(aQName);
285+
286+ if (qname->getTypeCode() != store::XS_QNAME)
287+ {
288+ throw XQUERY_EXCEPTION(err::XPTY0004, ERROR_PARAMS(ZED(BadType_23o), "xs:QName"));
289+ }
290+
291+ csize numArgs = aArgs.size();
292+
293+ // test if function with given #args exists
294+ function* func = theCtx->lookup_fn(qname.getp(), numArgs);
295+
296+ if (!func)
297+ {
298+ throw XQUERY_EXCEPTION(err::XPST0017,
299+ ERROR_PARAMS(qname->getStringValue(), ZED(FunctionUndeclared_3), numArgs));
300+ }
301+
302+ String queryStr = createInvokeQuery(func, numArgs);
303+
304+ XQuery_t query(new XQueryImpl());
305+
306+ // compile without any hints
307+ Zorba_CompilerHints_t lHints;
308+ StaticContext_t querySctx = new StaticContextImpl(*this);
309+
310+ query->compile(queryStr, querySctx, lHints);
311+
312+ // bind qname and params
313+ DynamicContext* queryDctx = query->getDynamicContext();
314+
315+ queryDctx->setVariable("", "xxx-func-name", aQName);
316+
317+ for (csize i = 0; i < numArgs; ++i)
318+ {
319+ std::ostringstream argName;
320+ argName << "arg" << i;
321+ queryDctx->setVariable("", argName.str(), aArgs[i]->getIterator());
322+ }
323+
324+ // the XQueryImpl object needs to live as long as its iterator
325+ // because the iterator returned as a result of the query
326+ // contains a reference to the query in order to do cleanup work.
327+ // The same is true for this sctx
328+ return new InvokeItemSequence(query, const_cast<StaticContextImpl*>(this));
329+ }
330+ catch (ZorbaException const& e)
331+ {
332+ ZorbaImpl::notifyError(theDiagnosticHandler, e);
333+ return 0;
334+ }
335+}
336+
337+
338+/*******************************************************************************
339+
340+********************************************************************************/
341+std::string StaticContextImpl::createInvokeQuery(
342+ const function* func,
343+ csize arity)
344 {
345 std::ostringstream lOut;
346
347@@ -1467,7 +1607,7 @@
348 << std::endl
349 << "declare variable $xxx-func-name as xs:QName" << " external;" << std::endl;
350
351- for (size_t i = 0; i < aArity; ++i)
352+ for (csize i = 0; i < arity; ++i)
353 {
354 lOut << "declare variable $arg" << i << " external;" << std::endl;
355 }
356@@ -1477,16 +1617,16 @@
357 // call updating, sequential, or simple invoke function
358 lOut << "ref:invoke";
359
360- if (aFunc->isUpdating())
361+ if (func->isUpdating())
362 lOut << "-u";
363- else if (aFunc->isSequential())
364+ else if (func->isSequential())
365 lOut << "-s";
366- else if (!aFunc->isDeterministic())
367+ else if (!func->isDeterministic())
368 lOut << "-n";
369
370 // args
371 lOut << "($xxx-func-name";
372- for (size_t i = 0; i < aArity; ++i)
373+ for (csize i = 0; i < arity; ++i)
374 {
375 lOut << ", $arg" << i;
376 }
377@@ -1495,93 +1635,6 @@
378 }
379
380
381-Function_t
382-StaticContextImpl::checkInvokable(const Item& aQName, size_t aNumArgs) const
383-{
384- store::Item* qname = Unmarshaller::getInternalItem(aQName);
385-
386- if (qname->getTypeCode() != store::XS_QNAME)
387- {
388- throw XQUERY_EXCEPTION(err::XPTY0004,
389- ERROR_PARAMS(ZED(BadType_23o), "xs:QName" ));
390- }
391-
392- // test if function with given #args exists
393- Function_t lFunc;
394-
395- std::vector<Function_t> lFunctions;
396- findFunctions(aQName, lFunctions);
397-
398- if (lFunctions.empty())
399- {
400- throw XQUERY_EXCEPTION(err::XPST0017,
401- ERROR_PARAMS(aQName.getStringValue(), ZED(FunctionUndeclared_3), aNumArgs));
402- }
403-
404- for (std::vector<Function_t>::const_iterator lIter = lFunctions.begin();
405- lIter != lFunctions.end(); ++lIter)
406- {
407- if ((*lIter)->isVariadic() || (*lIter)->getArity() == aNumArgs)
408- {
409- lFunc = (*lIter);
410- break;
411- }
412- }
413-
414- if (!lFunc)
415- {
416- throw XQUERY_EXCEPTION(err::XPST0017,
417- ERROR_PARAMS(aQName.getStringValue(), ZED(FunctionUndeclared_3), aNumArgs));
418- }
419-
420- return lFunc;
421-}
422-
423-
424-ItemSequence_t
425-StaticContextImpl::invoke(
426- const Item& aQName,
427- const std::vector<ItemSequence_t>& aArgs) const
428-{
429- try
430- {
431- Function_t lFunc = checkInvokable(aQName, aArgs.size());
432-
433- String lStr = createInvokeQuery(lFunc, aArgs.size());
434-
435- std::auto_ptr<XQueryImpl> impl(new XQueryImpl());
436-
437- // compile without any hints
438- Zorba_CompilerHints_t lHints;
439- StaticContext_t lSctx = new StaticContextImpl(*this);
440-
441- impl->compile(lStr, lSctx, lHints);
442-
443- // bind qname and params
444- DynamicContext* lDCtx = impl->getDynamicContext();
445- lDCtx->setVariable("xxx-func-name", aQName);
446- for (size_t i = 0; i < aArgs.size(); ++i)
447- {
448- std::ostringstream lArgName;
449- lArgName << "arg" << i;
450- lDCtx->setVariable(lArgName.str(), aArgs[i]->getIterator());
451- }
452-
453- // the XQueryImpl object needs to live as long as its iterator
454- // because the iterator returned as a result of the query
455- // contains a reference to the query in order to do cleanup work.
456- // The same is true for this sctx
457- return new InvokeItemSequence(impl.release(),
458- const_cast<StaticContextImpl*>(this));
459- }
460- catch (ZorbaException const& e)
461- {
462- ZorbaImpl::notifyError(theDiagnosticHandler, e);
463- return 0;
464- }
465-}
466-
467-
468 StaticCollectionManager*
469 StaticContextImpl::getStaticCollectionManager() const
470 {
471@@ -1600,6 +1653,9 @@
472 }
473
474
475+/*******************************************************************************
476+
477+********************************************************************************/
478 void
479 StaticContextImpl::setAuditEvent(audit::Event* anEvent)
480 {
481@@ -1607,6 +1663,9 @@
482 }
483
484
485+/*******************************************************************************
486+
487+********************************************************************************/
488 audit::Event*
489 StaticContextImpl::getAuditEvent() const
490 {
491@@ -1614,6 +1673,9 @@
492 }
493
494
495+/*******************************************************************************
496+
497+********************************************************************************/
498 void
499 StaticContextImpl::getExternalVariables(Iterator_t& aVarsIter) const
500 {
501@@ -1658,6 +1720,7 @@
502 return fetch(aURI, aEntityKind, "UTF-8");
503 }
504
505+
506 Item
507 StaticContextImpl::fetch(
508 const String& aURI,
509@@ -1700,12 +1763,14 @@
510 return 0;
511 }
512
513+
514 Item
515 StaticContextImpl::fetchBinary(const String& aURI) const
516 {
517 return fetchBinary(aURI, "SOME_CONTENT");
518 }
519
520+
521 Item
522 StaticContextImpl::fetchBinary(
523 const String& aURI,
524
525=== modified file 'src/api/staticcontextimpl.h'
526--- src/api/staticcontextimpl.h 2013-03-25 23:02:19 +0000
527+++ src/api/staticcontextimpl.h 2013-08-06 09:14:29 +0000
528@@ -27,9 +27,11 @@
529
530 namespace zorba {
531
532- class DiagnosticHandler;
533- class StaticCollectionManagerImpl;
534- class static_context;
535+class DiagnosticHandler;
536+class StaticCollectionManagerImpl;
537+class static_context;
538+class function;
539+
540
541 /*******************************************************************************
542
543@@ -72,6 +74,9 @@
544 // allow for lazy creation
545 mutable StaticCollectionManagerImpl * theCollectionMgr;
546
547+protected:
548+ static std::string createInvokeQuery(const function*, size_t aArity);
549+
550 private:
551 StaticContextImpl(const StaticContextImpl&);
552
553@@ -322,17 +327,8 @@
554 virtual Item
555 fetchBinary(const String& aURI, const String& aEntityKind) const;
556
557-protected:
558- String
559- createInvokeQuery(const Function_t&, size_t aArity) const;
560-
561- Function_t
562- checkInvokable(const Item& aQName, size_t aNumArgs) const;
563-
564-public:
565 virtual void
566 clearBaseURI();
567-
568 };
569
570 } // namespace zorba
571
572=== modified file 'src/api/zorbaimpl.cpp'
573--- src/api/zorbaimpl.cpp 2013-08-05 11:54:06 +0000
574+++ src/api/zorbaimpl.cpp 2013-08-06 09:14:29 +0000
575@@ -19,16 +19,16 @@
576
577 #include <istream>
578 #include <zorba/diagnostic_list.h>
579-//#include <zorba/function.h>
580 #include <zorba/store_manager.h>
581 #include <zorba/query_location.h>
582
583 #include "api/xqueryimpl.h"
584 #include "api/staticcontextimpl.h"
585+#include "api/documentmanagerimpl.h"
586 #include "api/itemfactoryimpl.h"
587 #include "api/unmarshaller.h"
588 #include "api/xmldatamanagerimpl.h"
589-#include "api/item_iter_vector.h"
590+//#include "api/item_iter_vector.h"
591 #include "api/auditimpl.h"
592
593 #include "zorbautils/fatal.h"
594@@ -233,8 +233,10 @@
595 DiagnosticHandler* aDiagnosticHandler)
596 {
597 XQuery_t lXQuery(new XQueryImpl());
598+
599 if (aDiagnosticHandler != 0)
600 lXQuery->registerDiagnosticHandler(aDiagnosticHandler);
601+
602 lXQuery->compile(aQuery, aStaticContext, aHints);
603 return lXQuery;
604 }
605@@ -243,9 +245,9 @@
606 /*******************************************************************************
607
608 ********************************************************************************/
609-StaticContext_t ZorbaImpl::createStaticContext(DiagnosticHandler* aDiagnosticHandler)
610+StaticContext_t ZorbaImpl::createStaticContext(DiagnosticHandler* handler)
611 {
612- return StaticContext_t(new StaticContextImpl(aDiagnosticHandler));
613+ return new StaticContextImpl(handler);
614 }
615
616
617@@ -311,14 +313,5 @@
618 }
619
620
621-void ZorbaImpl::checkItem(const store::Item_t& aItem)
622-{
623- if (!aItem)
624- throw ZORBA_EXCEPTION(
625- zerr::ZAPI0014_INVALID_ARGUMENT, ERROR_PARAMS( "null", ZED( BadItem ) )
626- );
627-}
628-
629-
630 } // namespace zorba
631 /* vim:set et sw=2 ts=2: */
632
633=== modified file 'src/api/zorbaimpl.h'
634--- src/api/zorbaimpl.h 2013-08-05 11:24:53 +0000
635+++ src/api/zorbaimpl.h 2013-08-06 09:14:29 +0000
636@@ -75,15 +75,14 @@
637
638 static void notifyWarning(DiagnosticHandler*, XQueryWarning const&);
639
640- static void checkItem(const store::Item_t& aItem);
641-
642-public:
643+ public:
644
645 virtual ~ZorbaImpl();
646
647 void shutdown() { shutdownInternal(true); }
648
649 int runUriTest() const;
650+
651 int runDebuggerProtocolTest() const;
652
653 XQuery_t createQuery(DiagnosticHandler* aDiagnosticHandler = 0);
654@@ -128,7 +127,7 @@
655 const Zorba_CompilerHints_t& aHints,
656 DiagnosticHandler* aDiagnosticHandler = 0);
657
658- StaticContext_t createStaticContext(DiagnosticHandler* aDiagnosticHandler = 0);
659+ StaticContext_t createStaticContext(DiagnosticHandler* handler = 0);
660
661 XmlDataManager_t getXmlDataManager();
662
663
664=== modified file 'src/context/root_static_context.cpp'
665--- src/context/root_static_context.cpp 2013-07-01 18:59:06 +0000
666+++ src/context/root_static_context.cpp 2013-08-06 09:14:29 +0000
667@@ -127,7 +127,8 @@
668 {
669 QueryLoc loc;
670
671- theImplementationBaseUri = ZORBA_NS;
672+ theImplementationBaseUri = "file:///";
673+ set_entity_retrieval_uri(theImplementationBaseUri);
674 compute_base_uri();
675
676 set_language_kind(StaticContextConsts::language_kind_xquery);

Subscribers

People subscribed via source and target branches