Merge lp:~zorba-coders/zorba/bug924987 into lp:zorba

Proposed by Till Westmann
Status: Merged
Approved by: Till Westmann
Approved revision: 10647
Merged at revision: 10704
Proposed branch: lp:~zorba-coders/zorba/bug924987
Merge into: lp:zorba
Diff against target: 906 lines (+606/-45)
13 files modified
include/zorba/identtypes.h (+16/-2)
include/zorba/typeident.h (+34/-1)
src/api/CMakeLists.txt (+1/-0)
src/api/identtypesimpl.cpp (+60/-0)
src/api/typeidentimpl.cpp (+146/-12)
src/types/typemanagerimpl.cpp (+26/-0)
src/types/typeops.cpp (+73/-27)
src/types/typeops.h (+3/-3)
test/unit/CMakeLists.txt (+4/-0)
test/unit/module5.xq (+20/-0)
test/unit/module6.xq (+38/-0)
test/unit/schema1.xsd (+21/-0)
test/unit/staticcollectionmanager.cpp (+164/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug924987
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Till Westmann Approve
Review via email: mp+96047@code.launchpad.net

This proposal supersedes a proposal from 2012-02-01.

Commit message

fixes bug 924987
- extended TypeIdentifier to also support schema-element, schema-attribute
  and namespace-node sequence types
- fixed TypeOps::get_type_identifier
- added a test to the staticcollectionmanager unit test
- added operator<< for TypeIdentifier

Description of the change

fixes bug 924987
- extended TypeIdentifier to also support schema-element, schema-attribute
  and namespace-node sequence types
- fixed TypeOps::get_type_identifier
- added a test to the staticcollectionmanager unit test
- added operator<< for TypeIdentifier

To post a comment you must log in.
Revision history for this message
Till Westmann (tillw) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job bug924987-2012-02-01T22-33-57.831Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 1 Approve, 2 Pending.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote : Posted in a previous version of this proposal

1. Zorba does not support the (optional) namespace nodes and associated sequence types. So, the releted code should be removed.

2. Why do the createSchemaElementType and createSchemaAttributeType have a contentType param? This is not according to the sequence type syntax and should be removed.

3. Just curious: why doesn't the emit() method print out the type using the w3c sequence type syntax?

4. An XQType of USER_DEFINED_KIND (i.e., an instance of the UserDefinedXQType class) represents a sequence type only if the type is atomic. So, in TypeOps::get_type_identifier(), a TypeIdentifier should be created only is the type is atomic; otherwise an error should be thrown (or an assertion triggered).

5. To be complete, the TypeManagerImpl::create_type(const TypeIdentifier& ident) method should also be fixed. It's up to you whether you want to do it or not.

Revision history for this message
Markos Zaharioudakis (markos-za) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Till Westmann (tillw) wrote : Posted in a previous version of this proposal

1. ok

2. I see your point, but I think that I need information about the content type. Is there a way to get that from the public API? (I looked over the public static context and didn't see something obvious.)

3. Good question. Actually, the type doesn't really reflect the structure of a sequence type. But as it is, it is an extension of the existing on and thus probably compatible.

4. That's interesting. It seems that the schema types also end up there. At least that's how I used it. I had a "as schema-element(...)" declaration and the content type of the ELEMENT_KIND was a USER_DEFINED_KIND.

5. I'll look at that, but first we need to make sure that points 2-4 are clarified.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Till Westmann (tillw) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Till Westmann (tillw) wrote :

All points should be fixed.

For 4. I've introduced a new parameter 'nested' that specifies, if the call to TypeOps::get_type_identifier is a nested call. If it is a nested call (from another invocation of TypeOps::get_type_identifier) the 'nested' is true and it is allowed to create type identifiers for non-atomic user-defined types. Otherwise the 'nested' is false and we assert, that the type in question is atomic. The default values of 'nested' is 'false', so that all existing calls to TypeOps::get_type_identifier will behave as required for sequence types.

Is this solution ok?

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

Validation queue job bug924987-2012-03-06T03-44-04.388Z is finished. The final status was:

All tests succeeded!

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

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 2 Pending.

lp:~zorba-coders/zorba/bug924987 updated
10646. By Markos Zaharioudakis

TypeManagerImpl::create_type() method

10647. By Markos Zaharioudakis

fix in TypeIdentifier::emitItemType() method + cosmetic

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

Till I have made some small changes to the branch. Take a look. If you approve, then let's merge the branch.

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Till Westmann (tillw) wrote :

Looks good.

Thanks!

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 bug924987-2012-03-06T14-10-21.545Z 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 'include/zorba/identtypes.h'
2--- include/zorba/identtypes.h 2011-09-21 14:49:55 +0000
3+++ include/zorba/identtypes.h 2012-03-06 10:37:20 +0000
4@@ -17,6 +17,7 @@
5 #define ZORBA_TYPEIDENT_TYPES_API_H
6
7 #include <zorba/config.h>
8+#include <iostream>
9
10 namespace zorba {
11 class ZORBA_DLL_PUBLIC IdentTypes {
12@@ -32,17 +33,30 @@
13 ANY_NODE_TYPE, // node()
14 ITEM_TYPE, // item()
15 EMPTY_TYPE, // empty-sequence()
16- INVALID_TYPE,
17+ SCHEMA_ELEMENT_TYPE,
18+ SCHEMA_ATTRIBUTE_TYPE,
19+ INVALID_TYPE
20 } kind_t;
21+
22+ static char const *const kind_string_of[];
23
24 typedef enum {
25 QUANT_ONE,
26 QUANT_QUESTION,
27 QUANT_PLUS,
28- QUANT_STAR,
29+ QUANT_STAR
30 } quantifier_t;
31+
32+ static char const *const quantifier_string_of[];
33 };
34 }
35
36+namespace std {
37+
38+ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::IdentTypes::kind_t ik);
39+ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::IdentTypes::quantifier_t iq);
40+
41+}
42+
43 #endif
44 /* vim:set et sw=2 ts=2: */
45
46=== modified file 'include/zorba/typeident.h'
47--- include/zorba/typeident.h 2011-06-14 17:26:33 +0000
48+++ include/zorba/typeident.h 2012-03-06 10:37:20 +0000
49@@ -20,6 +20,7 @@
50 #include <zorba/api_shared_types.h>
51 #include <zorba/identtypes.h>
52 #include <zorba/zorba_string.h>
53+#include <iostream>
54
55 namespace zorba {
56
57@@ -61,7 +62,7 @@
58 createAttributeType(
59 const String& uri,
60 bool uriWildcard,
61- const String& localNameName,
62+ const String& localName,
63 bool localNameWildcard,
64 TypeIdentifier_t contentType,
65 IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE
66@@ -108,6 +109,22 @@
67 TypeIdentifier_t
68 createEmptyType();
69
70+ static
71+ TypeIdentifier_t
72+ createSchemaElementType(
73+ const String& uri,
74+ const String& localName,
75+ IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE
76+ );
77+
78+ static
79+ TypeIdentifier_t
80+ createSchemaAttributeType(
81+ const String& uri,
82+ const String& localName,
83+ IdentTypes::quantifier_t quantifier = IdentTypes::QUANT_ONE
84+ );
85+
86 IdentTypes::kind_t
87 getKind() const;
88
89@@ -129,9 +146,18 @@
90 TypeIdentifier_t
91 getContentType() const;
92
93+ std::ostream&
94+ emit(std::ostream&) const;
95+
96 private:
97 TypeIdentifier();
98
99+ std::ostream&
100+ emitItemType(std::ostream&) const;
101+
102+ std::ostream&
103+ emitName(std::ostream&) const;
104+
105 IdentTypes::kind_t m_kind;
106 IdentTypes::quantifier_t m_quantifier;
107 String m_uri;
108@@ -148,5 +174,12 @@
109
110 } /* namespace zorba */
111
112+namespace std {
113+
114+ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::TypeIdentifier& ti);
115+ZORBA_DLL_PUBLIC ostream& operator<<(ostream& o, const zorba::TypeIdentifier_t ti);
116+
117+}
118+
119 #endif /* ZORBA_TYPES_TYPEIDENT_H */
120 /* vim:set et sw=2 ts=2: */
121
122=== modified file 'src/api/CMakeLists.txt'
123--- src/api/CMakeLists.txt 2012-02-16 14:11:02 +0000
124+++ src/api/CMakeLists.txt 2012-03-06 10:37:20 +0000
125@@ -27,6 +27,7 @@
126 zorba_string.cpp
127 itemfactoryimpl.cpp
128 item.cpp
129+ identtypesimpl.cpp
130 typeidentimpl.cpp
131 unmarshaller.cpp
132 xmldatamanagerimpl.cpp
133
134=== added file 'src/api/identtypesimpl.cpp'
135--- src/api/identtypesimpl.cpp 1970-01-01 00:00:00 +0000
136+++ src/api/identtypesimpl.cpp 2012-03-06 10:37:20 +0000
137@@ -0,0 +1,60 @@
138+/*
139+ * Copyright 2006-2008 The FLWOR Foundation.
140+ *
141+ * Licensed under the Apache License, Version 2.0 (the "License");
142+ * you may not use this file except in compliance with the License.
143+ * You may obtain a copy of the License at
144+ *
145+ * http://www.apache.org/licenses/LICENSE-2.0
146+ *
147+ * Unless required by applicable law or agreed to in writing, software
148+ * distributed under the License is distributed on an "AS IS" BASIS,
149+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
150+ * See the License for the specific language governing permissions and
151+ * limitations under the License.
152+ */
153+
154+#include <zorba/identtypes.h>
155+
156+namespace zorba {
157+
158+char const *const IdentTypes::kind_string_of[] = {
159+ "NAMED",
160+ "element",
161+ "attribute",
162+ "document-node",
163+ "processing-instruction",
164+ "text",
165+ "comment",
166+ "node",
167+ "item",
168+ "empty-sequence",
169+ "schema-element",
170+ "schema-attribute",
171+ "INVALID",
172+ 0
173+};
174+
175+char const *const IdentTypes::quantifier_string_of[] = {
176+ "",
177+ "?",
178+ "+",
179+ "*",
180+ 0
181+};
182+
183+}
184+
185+namespace std {
186+
187+ostream& operator<<(ostream& o, const zorba::IdentTypes::kind_t ik) {
188+ return o << zorba::IdentTypes::kind_string_of[ik];
189+}
190+
191+ostream& operator<<(ostream& o, const zorba::IdentTypes::quantifier_t iq) {
192+ return o << zorba::IdentTypes::quantifier_string_of[iq];
193+}
194+
195+}
196+
197+/* vim:set et sw=2 ts=2: */
198
199=== modified file 'src/api/typeidentimpl.cpp'
200--- src/api/typeidentimpl.cpp 2011-09-15 11:46:01 +0000
201+++ src/api/typeidentimpl.cpp 2012-03-06 10:37:20 +0000
202@@ -20,23 +20,28 @@
203
204 #include <zorba/typeident.h>
205
206+#include "diagnostics/assert.h"
207+
208 namespace zorba {
209
210 TypeIdentifier::TypeIdentifier()
211- : m_kind(IdentTypes::INVALID_TYPE),
212- m_quantifier(IdentTypes::QUANT_ONE),
213- m_uri(""),
214- m_uriWildcard(false),
215- m_localName(""),
216- m_localNameWildcard(false),
217- m_contentType()
218+ :
219+ m_kind(IdentTypes::INVALID_TYPE),
220+ m_quantifier(IdentTypes::QUANT_ONE),
221+ m_uri(""),
222+ m_uriWildcard(false),
223+ m_localName(""),
224+ m_localNameWildcard(false),
225+ m_contentType()
226 {
227 }
228
229+
230 TypeIdentifier::~TypeIdentifier()
231 {
232 }
233
234+
235 IdentTypes::kind_t TypeIdentifier::getKind() const
236 {
237 return m_kind;
238@@ -101,6 +106,9 @@
239 TypeIdentifier_t contentType,
240 IdentTypes::quantifier_t quantifier)
241 {
242+ // not sure why those were 2 different flags, we maintain 2 flags for
243+ // compatibility, but they always need to be the same
244+ ZORBA_ASSERT(uriWildcard == localNameWildcard);
245 TypeIdentifier_t ti(new TypeIdentifier());
246 ti->m_kind = IdentTypes::ELEMENT_TYPE;
247 ti->m_quantifier = quantifier;
248@@ -122,6 +130,9 @@
249 TypeIdentifier_t contentType,
250 IdentTypes::quantifier_t quantifier)
251 {
252+ // not sure why those were 2 different flags, we maintain 2 flags for
253+ // compatibility, but they always need to be the same
254+ ZORBA_ASSERT(uriWildcard == localNameWildcard);
255 TypeIdentifier_t ti(new TypeIdentifier());
256 ti->m_kind = IdentTypes::ATTRIBUTE_TYPE;
257 ti->m_quantifier = quantifier;
258@@ -202,11 +213,134 @@
259 {
260 TypeIdentifier_t ti(new TypeIdentifier());
261 ti->m_kind = IdentTypes::EMPTY_TYPE;
262-
263- return ti;
264-}
265-
266-}
267+ ti->m_quantifier = IdentTypes::QUANT_ONE;
268+
269+ return ti;
270+}
271+
272+TypeIdentifier_t TypeIdentifier::createSchemaElementType(
273+ const String& uri,
274+ const String& localName,
275+ IdentTypes::quantifier_t quantifier)
276+{
277+ TypeIdentifier_t ti(new TypeIdentifier());
278+ ti->m_kind = IdentTypes::SCHEMA_ELEMENT_TYPE;
279+ ti->m_quantifier = quantifier;
280+ ti->m_uri = uri;
281+ ti->m_uriWildcard = false;
282+ ti->m_localName = localName;
283+ ti->m_localNameWildcard = false;
284+
285+ return ti;
286+}
287+
288+
289+TypeIdentifier_t TypeIdentifier::createSchemaAttributeType(
290+ const String& uri,
291+ const String& localName,
292+ IdentTypes::quantifier_t quantifier)
293+{
294+ TypeIdentifier_t ti(new TypeIdentifier());
295+ ti->m_kind = IdentTypes::SCHEMA_ATTRIBUTE_TYPE;
296+ ti->m_quantifier = quantifier;
297+ ti->m_uri = uri;
298+ ti->m_uriWildcard = false;
299+ ti->m_localName = localName;
300+ ti->m_localNameWildcard = false;
301+
302+ return ti;
303+}
304+
305+
306+std::ostream& TypeIdentifier::emit(std::ostream& os) const
307+{
308+ emitItemType(os);
309+ return os << m_quantifier;
310+}
311+
312+
313+std::ostream& TypeIdentifier::emitItemType(std::ostream& os) const
314+{
315+ if (m_kind == IdentTypes::NAMED_TYPE)
316+ {
317+ return emitName(os);
318+ }
319+
320+ os << m_kind;
321+
322+ switch (m_kind)
323+ {
324+ case IdentTypes::DOCUMENT_TYPE:
325+ os << "(";
326+ if (m_contentType != NULL)
327+ {
328+ os << m_contentType;
329+ }
330+ return os << ")";
331+
332+ case IdentTypes::ELEMENT_TYPE:
333+ case IdentTypes::ATTRIBUTE_TYPE:
334+ os << "(";
335+ if (m_uriWildcard)
336+ {
337+ os << "*";
338+ }
339+ else
340+ {
341+ emitName(os);
342+ }
343+ if (! m_contentType.isNull())
344+ {
345+ os << "," << m_contentType;
346+ }
347+ return os << ")";
348+
349+ case IdentTypes::SCHEMA_ELEMENT_TYPE:
350+ case IdentTypes::SCHEMA_ATTRIBUTE_TYPE:
351+ os << "(";
352+ emitName(os);
353+ return os << ")";
354+
355+ case IdentTypes::ANY_NODE_TYPE:
356+ case IdentTypes::COMMENT_TYPE:
357+ case IdentTypes::EMPTY_TYPE:
358+ case IdentTypes::ITEM_TYPE:
359+ case IdentTypes::PI_TYPE:
360+ case IdentTypes::TEXT_TYPE:
361+ return os << "()";
362+
363+ case IdentTypes::INVALID_TYPE:
364+ return os;
365+
366+ case IdentTypes::NAMED_TYPE:
367+ default:
368+ ZORBA_ASSERT(false);
369+ }
370+}
371+
372+
373+std::ostream& TypeIdentifier::emitName(std::ostream& os) const
374+{
375+ return os << "{" << m_uri << "}" << m_localName;
376+}
377+
378+}
379+
380+namespace std
381+{
382+
383+ostream& operator<<(ostream& o, const zorba::TypeIdentifier& ti)
384+{
385+ return ti.emit(o);
386+}
387+
388+ostream& operator<<(ostream& o, const zorba::TypeIdentifier_t ti)
389+{
390+ return ti->emit(o);
391+}
392+
393+}
394+
395
396 #endif
397 /* vim:set et sw=2 ts=2: */
398
399=== modified file 'src/types/typemanagerimpl.cpp'
400--- src/types/typemanagerimpl.cpp 2012-01-26 19:56:14 +0000
401+++ src/types/typemanagerimpl.cpp 2012-03-06 10:37:20 +0000
402@@ -1045,6 +1045,32 @@
403 case IdentTypes::EMPTY_TYPE:
404 return create_empty_type();
405
406+ case IdentTypes::SCHEMA_ELEMENT_TYPE:
407+ {
408+ store::Item_t ename;
409+ GENV_ITEMFACTORY->createQName(ename,
410+ ident.getUri().c_str(),
411+ NULL,
412+ ident.getLocalName().c_str());
413+
414+ return create_schema_element_type(ename.getp(),
415+ q,
416+ QueryLoc::null);
417+ }
418+
419+ case IdentTypes::SCHEMA_ATTRIBUTE_TYPE:
420+ {
421+ store::Item_t aname;
422+ GENV_ITEMFACTORY->createQName(aname,
423+ ident.getUri().c_str(),
424+ NULL,
425+ ident.getLocalName().c_str());
426+
427+ return create_schema_attribute_type(aname,
428+ q,
429+ QueryLoc::null);
430+ }
431+
432 default:
433 break;
434 }
435
436=== modified file 'src/types/typeops.cpp'
437--- src/types/typeops.cpp 2012-01-30 15:23:21 +0000
438+++ src/types/typeops.cpp 2012-03-06 10:37:20 +0000
439@@ -1177,9 +1177,10 @@
440 /*******************************************************************************
441
442 ********************************************************************************/
443-type_ident_ref_t TypeOps::get_type_identifier(
444+TypeIdentifier_t TypeOps::get_type_identifier(
445 const TypeManager* tm,
446- const XQType& type)
447+ const XQType& type,
448+ bool nested)
449 {
450 RootTypeManager& rtm = GENV_TYPESYSTEM;
451
452@@ -1190,6 +1191,7 @@
453 {
454 const AtomicXQType& at = static_cast<const AtomicXQType&>(type);
455 store::Item* qname = rtm.m_atomic_typecode_qname_map[at.get_type_code()];
456+
457 return TypeIdentifier::createNamedType(
458 Unmarshaller::newString(qname->getNamespace()),
459 Unmarshaller::newString(qname->getLocalName()),
460@@ -1200,12 +1202,13 @@
461 {
462 const NodeXQType& nt = static_cast<const NodeXQType&>(type);
463
464- type_ident_ref_t content_type = (nt.get_content_type() != NULL ?
465- get_type_identifier(tm, *nt.get_content_type()) :
466- type_ident_ref_t());
467-
468 const store::Item* nodeName = nt.get_node_name();
469
470+ TypeIdentifier_t content_type;
471+
472+ if (nt.get_content_type() != NULL && !nt.is_schema_test())
473+ content_type = get_type_identifier(tm, *nt.get_content_type(), true);
474+
475 switch(nt.get_node_kind())
476 {
477 case store::StoreConsts::anyNode:
478@@ -1225,34 +1228,67 @@
479
480 case store::StoreConsts::elementNode:
481 {
482- String uri( Unmarshaller::newString( nodeName->getNamespace() ) );
483- String local( Unmarshaller::newString( nodeName->getLocalName() ) );
484-
485- return TypeIdentifier::createElementType(uri,
486- nodeName == NULL,
487- local,
488- nodeName == NULL,
489- content_type,
490- q);
491+ if (nt.is_schema_test())
492+ {
493+ ZORBA_ASSERT(nodeName);
494+ String uri( Unmarshaller::newString( nodeName->getNamespace() ) );
495+ String local( Unmarshaller::newString( nodeName->getLocalName() ) );
496+
497+ return TypeIdentifier::createSchemaElementType(uri, local, q);
498+ }
499+ else
500+ {
501+ String uri;
502+ String local;
503+ if (nodeName)
504+ {
505+ uri = nodeName->getNamespace().c_str();
506+ local = nodeName->getLocalName().c_str();
507+ }
508+
509+ return TypeIdentifier::createElementType(uri,
510+ nodeName == NULL,
511+ local,
512+ nodeName == NULL,
513+ content_type,
514+ q);
515+ }
516 }
517 case store::StoreConsts::attributeNode:
518 {
519- String uri( Unmarshaller::newString( nodeName->getNamespace() ) );
520- String local( Unmarshaller::newString( nodeName->getLocalName() ) );
521-
522- return TypeIdentifier::createAttributeType(uri,
523- nodeName == NULL,
524- local,
525- nodeName == NULL,
526- content_type,
527- q);
528+ if (nt.is_schema_test())
529+ {
530+ ZORBA_ASSERT(nodeName);
531+ String uri( Unmarshaller::newString( nodeName->getNamespace() ) );
532+ String local( Unmarshaller::newString( nodeName->getLocalName() ) );
533+
534+ return TypeIdentifier::createSchemaAttributeType(uri, local, q);
535+ }
536+ else
537+ {
538+ String uri;
539+ String local;
540+ if (nodeName)
541+ {
542+ uri = nodeName->getNamespace().c_str();
543+ local = nodeName->getLocalName().c_str();
544+ }
545+
546+ return TypeIdentifier::createAttributeType(uri,
547+ nodeName == NULL,
548+ local,
549+ nodeName == NULL,
550+ content_type,
551+ q);
552+ }
553 }
554 default:
555 // cannot happen
556 ZORBA_ASSERT(false);
557- return type_ident_ref_t();
558+ return NULL;
559 }
560 }
561+
562 case XQType::ANY_TYPE_KIND:
563 return TypeIdentifier::createNamedType(
564 Unmarshaller::newString( rtm.XS_ANY_TYPE_QNAME->getNamespace() ),
565@@ -1281,13 +1317,23 @@
566 return TypeIdentifier::createEmptyType();
567
568 case XQType::USER_DEFINED_KIND:
569- //TODO for Vinayak return type identifier
570+ {
571+ ZORBA_ASSERT(nested || is_atomic(tm, type));
572+
573+ store::Item* lQname = type.get_qname().getp();
574+
575+ return TypeIdentifier::createNamedType(
576+ Unmarshaller::newString( lQname->getNamespace() ),
577+ Unmarshaller::newString( lQname->getLocalName() ),
578+ q
579+ );
580+ }
581 default:
582 break;
583 }
584
585 ZORBA_ASSERT(false);
586- return type_ident_ref_t();
587+ return NULL;
588 }
589
590
591
592=== modified file 'src/types/typeops.h'
593--- src/types/typeops.h 2012-01-11 10:30:49 +0000
594+++ src/types/typeops.h 2012-03-06 10:37:20 +0000
595@@ -31,7 +31,6 @@
596 namespace zorba
597 {
598
599-typedef TypeIdentifier_t type_ident_ref_t;
600
601 // exported for unit testing only
602 class ZORBA_DLL_PUBLIC TypeOps
603@@ -254,9 +253,10 @@
604 * The invariant that is guaranteed is:
605 * is_subtype(_t_, create_type(*get_type_identifier(_t_))) == true
606 */
607- static type_ident_ref_t get_type_identifier(
608+ static TypeIdentifier_t get_type_identifier(
609 const TypeManager* tm,
610- const XQType& type);
611+ const XQType& type,
612+ bool nested = false);
613
614 /*
615 * Writes a textual representation of the given type to the output stream.
616
617=== modified file 'test/unit/CMakeLists.txt'
618--- test/unit/CMakeLists.txt 2012-02-27 14:46:27 +0000
619+++ test/unit/CMakeLists.txt 2012-03-06 10:37:20 +0000
620@@ -71,6 +71,10 @@
621 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module2.xq ${CMAKE_CURRENT_BINARY_DIR}/module2.xq)
622 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module3.xq ${CMAKE_CURRENT_BINARY_DIR}/module3.xq)
623 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module4.xq ${CMAKE_CURRENT_BINARY_DIR}/module4.xq)
624+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module5.xq ${CMAKE_CURRENT_BINARY_DIR}/module5.xq)
625+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/module6.xq ${CMAKE_CURRENT_BINARY_DIR}/module6.xq)
626+
627+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/schema1.xsd ${CMAKE_CURRENT_BINARY_DIR}/schema1.xsd)
628
629 SET(UNIT_TESTS_SRCS
630 path_resolver.cpp
631
632=== added file 'test/unit/module5.xq'
633--- test/unit/module5.xq 1970-01-01 00:00:00 +0000
634+++ test/unit/module5.xq 2012-03-06 10:37:20 +0000
635@@ -0,0 +1,20 @@
636+(:
637+ : Copyright 2006-2009 The FLWOR Foundation.
638+ :
639+ : Licensed under the Apache License, Version 2.0 (the "License");
640+ : you may not use this file except in compliance with the License.
641+ : You may obtain a copy of the License at
642+ :
643+ : http://www.apache.org/licenses/LICENSE-2.0
644+ :
645+ : Unless required by applicable law or agreed to in writing, software
646+ : distributed under the License is distributed on an "AS IS" BASIS,
647+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
648+ : See the License for the specific language governing permissions and
649+ : limitations under the License.
650+:)
651+
652+import module namespace mod6 = "http://www.mod6.com/" at "file:///${CMAKE_CURRENT_BINARY_DIR}/module6.xq";
653+
654+1+1
655+
656
657=== added file 'test/unit/module6.xq'
658--- test/unit/module6.xq 1970-01-01 00:00:00 +0000
659+++ test/unit/module6.xq 2012-03-06 10:37:20 +0000
660@@ -0,0 +1,38 @@
661+(:
662+ : Copyright 2006-2009 The FLWOR Foundation.
663+ :
664+ : Licensed under the Apache License, Version 2.0 (the "License");
665+ : you may not use this file except in compliance with the License.
666+ : You may obtain a copy of the License at
667+ :
668+ : http://www.apache.org/licenses/LICENSE-2.0
669+ :
670+ : Unless required by applicable law or agreed to in writing, software
671+ : distributed under the License is distributed on an "AS IS" BASIS,
672+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
673+ : See the License for the specific language governing permissions and
674+ : limitations under the License.
675+:)
676+
677+module namespace mod6 = "http://www.mod6.com/";
678+
679+declare namespace ann = "http://www.zorba-xquery.com/annotations";
680+
681+import schema namespace s = "http://www.zorba-xquery.com/schemas/simple" at "file:///${CMAKE_CURRENT_BINARY_DIR}/schema1.xsd";
682+
683+declare collection mod6:coll01 as document-node(element(s:product))*;
684+declare collection mod6:coll02 as document-node(element(*, s:ProductType))*;
685+declare collection mod6:coll03 as document-node(schema-element(s:product))*;
686+
687+declare collection mod6:coll04 as element(s:product)*;
688+declare collection mod6:coll05 as element(*, s:ProductType)*;
689+declare collection mod6:coll06 as schema-element(s:product)*;
690+
691+declare collection mod6:coll07 as attribute(s:zip-code)*;
692+declare collection mod6:coll08 as attribute(*, s:ZipType)*;
693+declare collection mod6:coll09 as schema-attribute(s:zip-code)*;
694+
695+declare collection mod6:coll10 as comment();
696+declare collection mod6:coll11 as processing-instruction()?;
697+declare collection mod6:coll12 as text()+;
698+declare collection mod6:coll13 as node()*;
699
700=== added file 'test/unit/schema1.xsd'
701--- test/unit/schema1.xsd 1970-01-01 00:00:00 +0000
702+++ test/unit/schema1.xsd 2012-03-06 10:37:20 +0000
703@@ -0,0 +1,21 @@
704+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
705+ targetNamespace="http://www.zorba-xquery.com/schemas/simple"
706+ xmlns="http://www.zorba-xquery.com/schemas/simple"
707+ elementFormDefault="qualified">
708+
709+ <xs:element name="product" type="ProductType"/>
710+
711+ <xs:complexType name="ProductType">
712+ <xs:attribute name="data" type="xs:base64Binary"/>
713+ <xs:attribute name="string" type="xs:string"/>
714+ </xs:complexType>
715+
716+ <xs:attribute name="zip-code" type="ZipType"/>
717+
718+ <xs:simpleType name="ZipType">
719+ <xs:restriction base="xs:string">
720+ <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
721+ </xs:restriction>
722+ </xs:simpleType>
723+
724+</xs:schema>
725\ No newline at end of file
726
727=== modified file 'test/unit/staticcollectionmanager.cpp'
728--- test/unit/staticcollectionmanager.cpp 2012-01-11 17:30:25 +0000
729+++ test/unit/staticcollectionmanager.cpp 2012-03-06 10:37:20 +0000
730@@ -259,6 +259,165 @@
731 return i == 1;
732 }
733
734+bool
735+check_types(StaticCollectionManager* aColMgr,
736+ ItemFactory* aFac,
737+ const char* const aCollName,
738+ int aDepth,
739+ IdentTypes::kind_t someKinds[],
740+ IdentTypes::quantifier_t someQuantifiers[])
741+{
742+ Item lCollName = aFac->createQName("http://www.mod6.com/", aCollName);
743+ if (! aColMgr->isDeclaredCollection(lCollName)) {
744+ std::cout << "no collection "
745+ << lCollName.getStringValue().c_str()
746+ << std::endl;
747+ return false;
748+ }
749+ aColMgr->createCollection(lCollName);
750+ Collection_t lCollection = aColMgr->getCollection(lCollName);
751+ zorba::TypeIdentifier_t lType = lCollection->getType();
752+ std::cout << lType << std::endl;
753+
754+ for (int i = 0; i < aDepth; ++i) {
755+ if (lType->getKind() != someKinds[i]) {
756+ std::cout << lType << std::endl;
757+ return false;
758+ }
759+ if (lType->getQuantifier() != someQuantifiers[i]) {
760+ std::cout << lType << std::endl;
761+ return false;
762+ }
763+ lType = lType->getContentType();
764+ }
765+ assert(lType.isNull());
766+
767+ aColMgr->deleteCollection(lCollName);
768+ return true;
769+}
770+
771+bool
772+staticcollectionamanger5(zorba::Zorba* z)
773+{
774+ std::ifstream lIn("module5.xq");
775+ zorba::XQuery_t lQuery = z->createQuery();
776+
777+ try {
778+ Zorba_CompilerHints lHints;
779+ lQuery->compile(lIn, lHints);
780+ } catch (zorba::XQueryException &e) {
781+ std::cout << e << std::endl;
782+ return false;
783+ } catch (...) {
784+ std::cout << "compilation failed" << std::endl;
785+ return false;
786+ }
787+
788+ StaticCollectionManager* lColMgr = lQuery->getStaticCollectionManager();
789+ ItemFactory* lFac = z->getItemFactory();
790+
791+ IdentTypes::kind_t lC01Kinds[] = { IdentTypes::DOCUMENT_TYPE,
792+ IdentTypes::ELEMENT_TYPE,
793+ IdentTypes::NAMED_TYPE };
794+ IdentTypes::quantifier_t lC01Quants[] = { IdentTypes::QUANT_STAR,
795+ IdentTypes::QUANT_ONE,
796+ // this '*' is probably a bug
797+ IdentTypes::QUANT_STAR };
798+ if (!check_types(lColMgr, lFac, "coll01", 3, lC01Kinds, lC01Quants)) {
799+ return false;
800+ }
801+
802+ IdentTypes::kind_t lC02Kinds[] = { IdentTypes::DOCUMENT_TYPE,
803+ IdentTypes::ELEMENT_TYPE,
804+ IdentTypes::NAMED_TYPE };
805+ IdentTypes::quantifier_t lC02Quants[] = { IdentTypes::QUANT_STAR,
806+ IdentTypes::QUANT_ONE,
807+ IdentTypes::QUANT_ONE };
808+ if (!check_types(lColMgr, lFac, "coll02", 3, lC02Kinds, lC02Quants)) {
809+ return false;
810+ }
811+
812+ IdentTypes::kind_t lC03Kinds[] = { IdentTypes::DOCUMENT_TYPE,
813+ IdentTypes::SCHEMA_ELEMENT_TYPE };
814+ IdentTypes::quantifier_t lC03Quants[] = { IdentTypes::QUANT_STAR,
815+ IdentTypes::QUANT_ONE };
816+ if (!check_types(lColMgr, lFac, "coll03", 2, lC03Kinds, lC03Quants)) {
817+ return false;
818+ }
819+
820+ IdentTypes::kind_t lC04Kinds[] = { IdentTypes::ELEMENT_TYPE,
821+ IdentTypes::NAMED_TYPE };
822+ IdentTypes::quantifier_t lC04Quants[] = { IdentTypes::QUANT_STAR,
823+ // this '*' is probably a bug
824+ IdentTypes::QUANT_STAR };
825+ if (!check_types(lColMgr, lFac, "coll04", 2, lC04Kinds, lC04Quants)) {
826+ return false;
827+ }
828+
829+ IdentTypes::kind_t lC05Kinds[] = { IdentTypes::ELEMENT_TYPE,
830+ IdentTypes::NAMED_TYPE };
831+ IdentTypes::quantifier_t lC05Quants[] = { IdentTypes::QUANT_STAR,
832+ IdentTypes::QUANT_ONE };
833+ if (!check_types(lColMgr, lFac, "coll05", 2, lC05Kinds, lC05Quants)) {
834+ return false;
835+ }
836+
837+ IdentTypes::kind_t lC06Kinds[] = { IdentTypes::SCHEMA_ELEMENT_TYPE };
838+ IdentTypes::quantifier_t lC06Quants[] = { IdentTypes::QUANT_STAR };
839+ if (!check_types(lColMgr, lFac, "coll06", 1, lC06Kinds, lC06Quants)) {
840+ return false;
841+ }
842+
843+ IdentTypes::kind_t lC07Kinds[] = { IdentTypes::ATTRIBUTE_TYPE,
844+ IdentTypes::NAMED_TYPE };
845+ IdentTypes::quantifier_t lC07Quants[] = { IdentTypes::QUANT_STAR,
846+ // this '*' is probably a bug
847+ IdentTypes::QUANT_STAR };
848+ if (!check_types(lColMgr, lFac, "coll07", 2, lC07Kinds, lC07Quants)) {
849+ return false;
850+ }
851+
852+ IdentTypes::kind_t lC08Kinds[] = { IdentTypes::ATTRIBUTE_TYPE,
853+ IdentTypes::NAMED_TYPE };
854+ IdentTypes::quantifier_t lC08Quants[] = { IdentTypes::QUANT_STAR,
855+ IdentTypes::QUANT_ONE };
856+ if (!check_types(lColMgr, lFac, "coll08", 2, lC08Kinds, lC08Quants)) {
857+ return false;
858+ }
859+
860+ IdentTypes::kind_t lC09Kinds[] = { IdentTypes::SCHEMA_ATTRIBUTE_TYPE };
861+ IdentTypes::quantifier_t lC09Quants[] = { IdentTypes::QUANT_STAR };
862+ if (!check_types(lColMgr, lFac, "coll09", 1, lC09Kinds, lC09Quants)) {
863+ return false;
864+ }
865+
866+ IdentTypes::kind_t lC10Kinds[] = { IdentTypes::COMMENT_TYPE };
867+ IdentTypes::quantifier_t lC10Quants[] = { IdentTypes::QUANT_ONE };
868+ if (!check_types(lColMgr, lFac, "coll10", 1, lC10Kinds, lC10Quants)) {
869+ return false;
870+ }
871+
872+ IdentTypes::kind_t lC11Kinds[] = { IdentTypes::PI_TYPE };
873+ IdentTypes::quantifier_t lC11Quants[] = { IdentTypes::QUANT_QUESTION };
874+ if (!check_types(lColMgr, lFac, "coll11", 1, lC11Kinds, lC11Quants)) {
875+ return false;
876+ }
877+
878+ IdentTypes::kind_t lC12Kinds[] = { IdentTypes::TEXT_TYPE };
879+ IdentTypes::quantifier_t lC12Quants[] = { IdentTypes::QUANT_PLUS };
880+ if (!check_types(lColMgr, lFac, "coll12", 1, lC12Kinds, lC12Quants)) {
881+ return false;
882+ }
883+
884+ IdentTypes::kind_t lC13Kinds[] = { IdentTypes::ANY_NODE_TYPE };
885+ IdentTypes::quantifier_t lC13Quants[] = { IdentTypes::QUANT_STAR };
886+ if (!check_types(lColMgr, lFac, "coll13", 1, lC13Kinds, lC13Quants)) {
887+ return false;
888+ }
889+
890+ return true;
891+}
892+
893 int
894 staticcollectionmanager(int argc, char* argv[])
895 {
896@@ -287,6 +446,11 @@
897 return 4;
898 std::cout << std::endl;
899
900+ std::cout << "executing example 5" << std::endl;
901+ if (!staticcollectionamanger5(z))
902+ return 5;
903+ std::cout << std::endl;
904+
905 return 0;
906 }
907

Subscribers

People subscribed via source and target branches