Merge lp:~zorba-coders/zorba/feature-ModuleInfo into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Chris Hillery
Approved revision: 11243
Merged at revision: 11360
Proposed branch: lp:~zorba-coders/zorba/feature-ModuleInfo
Merge into: lp:zorba
Diff against target: 499 lines (+337/-2)
13 files modified
ChangeLog (+1/-0)
include/zorba/api_shared_types.h (+2/-0)
include/zorba/module_info.h (+52/-0)
include/zorba/xquery.h (+13/-0)
src/api/CMakeLists.txt (+1/-0)
src/api/module_info_impl.cpp (+29/-0)
src/api/module_info_impl.h (+50/-0)
src/api/xqueryimpl.cpp (+38/-1)
src/api/xqueryimpl.h (+3/-0)
src/compiler/api/compiler_api.cpp (+29/-1)
src/compiler/api/compiler_api.h (+4/-0)
test/api/CMakeLists.txt (+1/-0)
test/api/xquery.cpp (+114/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/feature-ModuleInfo
Reviewer Review Type Date Requested Status
Chris Hillery Approve
Matthias Brantner Approve
Review via email: mp+148616@code.launchpad.net

Commit message

Added XQuery::parse(std::istream& aQuery, ModuleInfo_t& aResult) to allow retrieval
of a module's target namespace without compiling it.

To post a comment you must log in.
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 :

The attempt to merge lp:~zorba-coders/zorba/feature-ModuleInfo into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job feature-ModuleInfo-2013-02-15T06-13-44.038Z is
  finished. The final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

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

The attempt to merge lp:~zorba-coders/zorba/feature-ModuleInfo into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job feature-ModuleInfo-2013-02-20T09-25-09.419Z is
  finished. The final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Chris Hillery (ceejatec) wrote :

Looks like you forgot to add xquery.cpp (test case?).

You added the new parse() virtual method to the public API not at the end of the XQuery class.

I don't like our XQuery API (what's the point behind creating an XQuery object that doesn't represent a query?), but I guess this new parse() function is consistent with it. But would it be useful to also have a function to retrieve a ModuleInfo from an XQuery that *has* been associated with a query, eg. from Zorba::compileQuery() ?

review: Needs Fixing
11242. By Matthias Brantner

added missing files

11243. By Matthias Brantner

moved virtual functions to the end

Revision history for this message
Chris Hillery (ceejatec) :
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 job feature-ModuleInfo-2013-04-10T09-43-56.347Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-02-15 21:39:41 +0000
3+++ ChangeLog 2013-02-20 16:09:23 +0000
4@@ -9,6 +9,7 @@
5 * New C++ and XQuery function (see module http://www.zorba-xquery.com/modules/item)
6 to estimate the size an item allocates in memory.
7 * Extended sequence types to include unions, as specified by XQuery v3.0
8+ * Added XQuery::parse(std::istream& aQuery, ModuleInfo_t& aResult) function.
9 * In store API, added ability to specify a stream's originating URI (file)
10 for streamable strings and base64Binary.
11 * Added millis-to-dateTime() function in datetime module.
12
13=== modified file 'include/zorba/api_shared_types.h'
14--- include/zorba/api_shared_types.h 2012-09-19 21:16:15 +0000
15+++ include/zorba/api_shared_types.h 2013-02-20 16:09:23 +0000
16@@ -45,6 +45,7 @@
17 class File;
18 class DirectoryIterator;
19 class Serializer;
20+ class ModuleInfo;
21
22 class DiagnosticHandler;
23 class QueryLocation;
24@@ -67,6 +68,7 @@
25 typedef zorba::SmartPtr<DirectoryIterator> DirectoryIterator_t;
26 typedef zorba::SmartPtr<Serializer> Serializer_t;
27 typedef zorba::SmartPtr<ItemSequence> ItemSequence_t;
28+ typedef zorba::SmartPtr<ModuleInfo> ModuleInfo_t;
29
30 // data handlers
31 class Item;
32
33=== added file 'include/zorba/module_info.h'
34--- include/zorba/module_info.h 1970-01-01 00:00:00 +0000
35+++ include/zorba/module_info.h 2013-02-20 16:09:23 +0000
36@@ -0,0 +1,52 @@
37+/*
38+ * Copyright 2013 The FLWOR Foundation.
39+ *
40+ * Licensed under the Apache License, Version 2.0 (the "License");
41+ * you may not use this file except in compliance with the License.
42+ * You may obtain a copy of the License at
43+ *
44+ * http://www.apache.org/licenses/LICENSE-2.0
45+ *
46+ * Unless required by applicable law or agreed to in writing, software
47+ * distributed under the License is distributed on an "AS IS" BASIS,
48+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49+ * See the License for the specific language governing permissions and
50+ * limitations under the License.
51+ */
52+#ifndef ZORBA_MODULE_INFO_H
53+#define ZORBA_MODULE_INFO_H
54+
55+#include <zorba/config.h>
56+#include <zorba/api_shared_types.h>
57+
58+namespace zorba {
59+
60+ /** \brief Information about a main or library module.
61+ *
62+ */
63+ class ZORBA_DLL_PUBLIC ModuleInfo : public SmartObject
64+ {
65+ public:
66+ virtual ~ModuleInfo() {}
67+
68+ /**
69+ * Return the target namespace of the module.
70+ *
71+ * @return the target namespace or the empty
72+ * string if the module is a main module.
73+ */
74+ virtual zorba::String
75+ getTargetNamespace() const = 0;
76+
77+ /**
78+ * @return true if the module is a library module,
79+ * false otherwise.
80+ */
81+ virtual bool
82+ isLibraryModule() const = 0;
83+
84+ }; /* class ModuleInfo */
85+
86+} // namespace zorba
87+#endif /* ZORBA_MODULE_INFO_H */
88+/* vim:set et sw=2 ts=2: */
89
90=== modified file 'include/zorba/xquery.h'
91--- include/zorba/xquery.h 2012-09-19 21:16:15 +0000
92+++ include/zorba/xquery.h 2013-02-20 16:09:23 +0000
93@@ -553,6 +553,19 @@
94 */
95 virtual double
96 getDocLoadingTime() const = 0;
97+
98+ /**
99+ * \brief Parse the given module String.
100+ *
101+ * This function parses the module string and returns some information
102+ * about the module.
103+ *
104+ * @param aQuery the query file to parse.
105+ * @param aResult some information about the module
106+ * @throw ZorbaException if an error occurs while parsing the query.
107+ */
108+ virtual void
109+ parse(std::istream& aQuery, ModuleInfo_t& aResult) = 0;
110 };
111
112
113
114=== modified file 'src/api/CMakeLists.txt'
115--- src/api/CMakeLists.txt 2013-02-01 06:03:17 +0000
116+++ src/api/CMakeLists.txt 2013-02-20 16:09:23 +0000
117@@ -60,6 +60,7 @@
118 streambuf.cpp
119 transcode_streambuf.cpp
120 uuid.cpp
121+ module_info_impl.cpp
122 )
123
124 IF (ZORBA_WITH_FILE_ACCESS)
125
126=== added file 'src/api/module_info_impl.cpp'
127--- src/api/module_info_impl.cpp 1970-01-01 00:00:00 +0000
128+++ src/api/module_info_impl.cpp 2013-02-20 16:09:23 +0000
129@@ -0,0 +1,29 @@
130+/*
131+ * Copyright 2013 The FLWOR Foundation.
132+ *
133+ * Licensed under the Apache License, Version 2.0 (the "License");
134+ * you may not use this file except in compliance with the License.
135+ * You may obtain a copy of the License at
136+ *
137+ * http://www.apache.org/licenses/LICENSE-2.0
138+ *
139+ * Unless required by applicable law or agreed to in writing, software
140+ * distributed under the License is distributed on an "AS IS" BASIS,
141+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142+ * See the License for the specific language governing permissions and
143+ * limitations under the License.
144+ */
145+#include "api/module_info_impl.h"
146+#include <zorba/zorba_string.h>
147+#include "zorbatypes/zstring.h"
148+#include "api/unmarshaller.h"
149+
150+namespace zorba {
151+
152+ ModuleInfoImpl::ModuleInfoImpl(const zstring& aTargetNamespace)
153+ : theTargetNamespace(Unmarshaller::newString(aTargetNamespace))
154+ {
155+ }
156+
157+} // namespace zorba
158+
159
160=== added file 'src/api/module_info_impl.h'
161--- src/api/module_info_impl.h 1970-01-01 00:00:00 +0000
162+++ src/api/module_info_impl.h 2013-02-20 16:09:23 +0000
163@@ -0,0 +1,50 @@
164+/*
165+ * Copyright 2013 The FLWOR Foundation.
166+ *
167+ * Licensed under the Apache License, Version 2.0 (the "License");
168+ * you may not use this file except in compliance with the License.
169+ * You may obtain a copy of the License at
170+ *
171+ * http://www.apache.org/licenses/LICENSE-2.0
172+ *
173+ * Unless required by applicable law or agreed to in writing, software
174+ * distributed under the License is distributed on an "AS IS" BASIS,
175+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
176+ * See the License for the specific language governing permissions and
177+ * limitations under the License.
178+ */
179+#ifndef ZORBA_MODULE_INFO_IMPL_H
180+#define ZORBA_MODULE_INFO_IMPL_H
181+
182+#include <zorba/module_info.h>
183+#include <zorba/zorba_string.h>
184+#include "common/shared_types.h"
185+
186+namespace zorba {
187+
188+ /**
189+ */
190+ class ZORBA_DLL_PUBLIC ModuleInfoImpl : public ModuleInfo
191+ {
192+ protected:
193+ String theTargetNamespace;
194+
195+ public:
196+ ModuleInfoImpl(const zstring& aTargetNamespace);
197+
198+ virtual zorba::String
199+ getTargetNamespace() const
200+ {
201+ return theTargetNamespace;
202+ }
203+
204+ virtual bool
205+ isLibraryModule() const
206+ {
207+ return theTargetNamespace.length() > 0;
208+ }
209+ }; /* class ModuleInfoImpl */
210+
211+} // namespace zorba
212+#endif /* ZORBA_MODULE_INFO_IMPL_H */
213+/* vim:set et sw=2 ts=2: */
214
215=== modified file 'src/api/xqueryimpl.cpp'
216--- src/api/xqueryimpl.cpp 2013-01-08 08:34:08 +0000
217+++ src/api/xqueryimpl.cpp 2013-02-20 16:09:23 +0000
218@@ -27,6 +27,7 @@
219 #include <zorba/diagnostic_list.h>
220 #include <zorba/sax2.h>
221 #include <zorba/audit_scoped.h>
222+#include <zorba/module_info.h>
223
224 #include <zorbatypes/URI.h>
225
226@@ -687,7 +688,6 @@
227 QUERY_CATCH
228 }
229
230-
231 /*******************************************************************************
232 A clone query shares its error handler and plan iterator tree with the original
233 query. The static and dynamic context of a clone query is a child of a static
234@@ -1622,6 +1622,43 @@
235 }
236
237 /*******************************************************************************
238+ Parse a query.
239+********************************************************************************/
240+void XQueryImpl::parse(std::istream& aQuery, ModuleInfo_t& aResult)
241+{
242+ SYNC_CODE(AutoMutex lock(&theMutex);)
243+
244+ try
245+ {
246+ checkNotClosed();
247+ checkNotCompiled();
248+
249+ if ( ! theStaticContext )
250+ {
251+ // no context given => use the default one (i.e. a child of the root sctx)
252+ theStaticContext = GENV.getRootStaticContext().create_child_context();
253+ }
254+ else
255+ {
256+ // otherwise create a child and we have ownership over that one
257+ theStaticContext = theStaticContext->create_child_context();
258+ }
259+
260+ zstring url;
261+ URI::encode_file_URI(theFileName, url);
262+
263+ theStaticContext->set_entity_retrieval_uri(url);
264+
265+ theCompilerCB->theRootSctx = theStaticContext;
266+
267+ XQueryCompiler lCompiler(theCompilerCB);
268+ aResult = lCompiler.parseInfo(aQuery, theFileName);
269+ }
270+ QUERY_CATCH
271+}
272+
273+
274+/*******************************************************************************
275
276 ********************************************************************************/
277 std::ostream& operator<<(std::ostream& os, const XQuery_t& aQuery)
278
279=== modified file 'src/api/xqueryimpl.h'
280--- src/api/xqueryimpl.h 2012-09-19 21:16:15 +0000
281+++ src/api/xqueryimpl.h 2013-02-20 16:09:23 +0000
282@@ -45,6 +45,7 @@
283 class dynamic_context;
284 class CompilerCB;
285 class StaticCollectionManagerSetImpl;
286+class ModuleInfo;
287
288
289 /*******************************************************************************
290@@ -400,6 +401,8 @@
291 void notifyAllWarnings() const;
292
293 bool isBoundVariable(const String& aNamespace, const String& aLocalname) const;
294+
295+ void parse(std::istream& aQuery, ModuleInfo_t& aResult);
296 };
297
298
299
300=== modified file 'src/compiler/api/compiler_api.cpp'
301--- src/compiler/api/compiler_api.cpp 2012-12-14 07:27:04 +0000
302+++ src/compiler/api/compiler_api.cpp 2013-02-20 16:09:23 +0000
303@@ -40,7 +40,6 @@
304
305 #include "compiler/parser/xquery_driver.h"
306 #include "compiler/parsetree/parsenodes.h"
307-#include "compiler/parsetree/parsenodes.h"
308 #include "compiler/parsetree/parsenode_print_xml_visitor.h"
309 #include "compiler/parsetree/parsenode_print_xqdoc_visitor.h"
310
311@@ -62,6 +61,7 @@
312 #include "zorbatypes/URI.h"
313
314 #include "api/auditimpl.h"
315+#include "api/module_info_impl.h"
316 #include <zorba/util/timer.h>
317
318
319@@ -204,6 +204,34 @@
320 return node;
321 }
322
323+/*******************************************************************************
324+
325+********************************************************************************/
326+ModuleInfo* XQueryCompiler::parseInfo(
327+ std::istream& aXQuery,
328+ const zstring& aFileName)
329+{
330+ parsenode_t lParseNode = parse(aXQuery, aFileName);
331+
332+ if (typeid (*lParseNode) == typeid (ParseErrorNode))
333+ {
334+ ParseErrorNode* pen = static_cast<ParseErrorNode *>(lParseNode.getp());
335+ throw XQUERY_EXCEPTION_VAR(pen->err,
336+ ERROR_PARAMS(pen->msg), ERROR_LOC(pen->get_location()));
337+ }
338+
339+ LibraryModule* lLibModule = dynamic_cast<LibraryModule*>(lParseNode.getp());
340+
341+ zstring lTargetNamespace;
342+
343+ if (lLibModule)
344+ {
345+ ModuleDecl* lDecl = lLibModule->get_decl().getp();
346+ lTargetNamespace = lDecl->get_target_namespace();
347+ }
348+
349+ return new ModuleInfoImpl(lTargetNamespace);
350+}
351
352 /*******************************************************************************
353
354
355=== modified file 'src/compiler/api/compiler_api.h'
356--- src/compiler/api/compiler_api.h 2012-11-09 23:14:53 +0000
357+++ src/compiler/api/compiler_api.h 2013-02-20 16:09:23 +0000
358@@ -52,6 +52,10 @@
359
360 parsenode_t parse(std::istream& aXQuery, const zstring& aFileName);
361
362+ ModuleInfo* parseInfo(
363+ std::istream& aXQuery,
364+ const zstring& aFileName);
365+
366 PlanIter_t compile(
367 std::istream& aXQuery,
368 const zstring& aFileName,
369
370=== modified file 'test/api/CMakeLists.txt'
371--- test/api/CMakeLists.txt 2012-10-08 12:09:36 +0000
372+++ test/api/CMakeLists.txt 2013-02-20 16:09:23 +0000
373@@ -16,6 +16,7 @@
374 APITests.cpp
375 itemfactory.cpp
376 xmldatamanager.cpp
377+ xquery.cpp
378 test_static_context.cpp
379 test_dynamic_context.cpp
380 serializer.cpp
381
382=== added file 'test/api/xquery.cpp'
383--- test/api/xquery.cpp 1970-01-01 00:00:00 +0000
384+++ test/api/xquery.cpp 2013-02-20 16:09:23 +0000
385@@ -0,0 +1,114 @@
386+/*
387+ * Copyright 2013 FLWOR Foundation.
388+ *
389+ * Licensed under the Apache License, Version 2.0 (the "License");
390+ * you may not use this file except in compliance with the License.
391+ * You may obtain a copy of the License at
392+ *
393+ * http://www.apache.org/licenses/LICENSE-2.0
394+ *
395+ * Unless required by applicable law or agreed to in writing, software
396+ * distributed under the License is distributed on an "AS IS" BASIS,
397+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
398+ * See the License for the specific language governing permissions and
399+ * limitations under the License.
400+ */
401+
402+#include <cassert>
403+#include <cstdlib>
404+#include <iostream>
405+#include <sstream>
406+#include <limits>
407+#include <string.h>
408+
409+#include <zorba/zorba.h>
410+#include <zorba/store_manager.h>
411+#include <zorba/zorba_exception.h>
412+#include <zorba/module_info.h>
413+
414+using namespace zorba;
415+
416+int
417+xquery_test_lib(Zorba* zorba)
418+{
419+ std::stringstream lQueryString;
420+ lQueryString
421+ << "module namespace foo = 'foo:bar';" << std::endl;
422+
423+ XQuery_t lQuery = zorba->createQuery();
424+
425+ ModuleInfo_t lInfo;
426+ lQuery->parse(lQueryString, lInfo);
427+
428+ if (lInfo->getTargetNamespace() != "foo:bar")
429+ return 1;
430+ else
431+ return 0;
432+}
433+
434+int
435+xquery_test_main(Zorba* zorba)
436+{
437+ std::stringstream lQueryString;
438+ lQueryString << "1+1" << std::endl;
439+
440+ XQuery_t lQuery = zorba->createQuery();
441+
442+ ModuleInfo_t lInfo;
443+ lQuery->parse(lQueryString, lInfo);
444+
445+ if (lInfo->isLibraryModule())
446+ return 1;
447+ else
448+ return 0;
449+}
450+
451+int
452+xquery_test_error(Zorba* zorba)
453+{
454+ try
455+ {
456+ std::stringstream lQueryString;
457+ lQueryString << "1+" << std::endl;
458+
459+ XQuery_t lQuery = zorba->createQuery();
460+
461+ ModuleInfo_t lInfo;
462+ lQuery->parse(lQueryString, lInfo);
463+
464+ return 1;
465+ } catch (ZorbaException& e)
466+ {
467+ std::cerr << e << std::endl;
468+ return 0;
469+ }
470+}
471+
472+int
473+xquery(int argc, char* argv[])
474+{
475+ Zorba* zorba = NULL;
476+ void* store = NULL;
477+
478+ store = zorba::StoreManager::getStore();
479+ zorba = Zorba::getInstance(store);
480+
481+ try
482+ {
483+ if (xquery_test_lib(zorba))
484+ return 1;
485+
486+ if (xquery_test_main(zorba))
487+ return 2;
488+
489+ if (xquery_test_error(zorba))
490+ return 3;
491+
492+ } catch (ZorbaException &e) {
493+ std::cerr << e << std::endl;
494+ return 4;
495+ }
496+
497+ return 0;
498+}
499+

Subscribers

People subscribed via source and target branches