1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 #ifndef ZORBA_TYPEIMPL_H
18 #define ZORBA_TYPEIMPL_H
19 
20 #include "common/shared_types.h"
21 
22 #include "types/node_test.h"
23 #include "types/typeconstants.h"
24 #include "types/typemanager.h"
25 
26 #include "zorbatypes/rchandle.h"
27 
28 #include "store/api/item_handle.h"
29 #include "store/api/item.h"
30 
31 #include "system/globalenv.h"
32 
33 #include "zorbaserialization/class_serializer.h"
34 
35 namespace zorba
36 {
37 
38 
39 /***************************************************************************//**
40 
41   Class XQType and its subtypes implement xquery's SequenceType spec as well as
42   XMLSchema types.
43 
44   ***************
45   SequenceTypes:
46   ***************
47 
48   SequenceType ::= ("empty-sequence" "(" ")") | (ItemType OccurrenceIndicator?)
49 
50   ItemType ::= KindTest
51       | ("item" "(" ")")
52       | AtomicType
53       | JSONTest
54       | StructuredItemTest
55 
56   OccurrenceIndicator ::= "?" | "*" | "+"
57 
58   AtomicType ::= QName (** may be built-in or user-defined **)
59 
60   KindTest ::= DocumentTest |
61                ElementTest |
62                AttributeTest |
63                SchemaElementTest |
64                SchemaAttributeTest |
65                PITest |
66                CommentTest |
67                TextTest |
68                AnyKindTest
69 
70   DocumentTest ::= "document-node" "(" (ElementTest | SchemaElementTest)? ")"
71 
72   ElementTest ::= "element" "(" (ElementNameOrWildcard ("," TypeName "?"?)?)? ")"
73 
74   SchemaElementTest ::= "schema-element" "(" ElementDeclaration ")"
75 
76   ElementNameOrWildcard ::= ElementName | "*"
77 
78   ElementDeclaration ::= ElementName
79 
80   ElementName ::= QName
81 
82   AttributeTest ::= "attribute" "(" (AttribNameOrWildcard ("," TypeName)?)? ")"
83 
84   SchemaAttributeTest ::= "schema-attribute" "(" AttributeDeclaration ")"
85 
86   AttributeDeclaration ::= AttributeName
87 
88   AttribNameOrWildcard ::= AttributeName | "*"
89 
90   AttributeName ::= QName
91 
92   TypeName ::= QName (** may be built-in or user-defined, simple or complex **)
93 
94   PITest ::= "processing-instruction" "(" (NCName | StringLiteral)? ")"
95 
96   CommentTest ::= "comment" "(" ")"
97 
98   TextTest ::= "text" "(" ")"
99 
100   AnyKindTest ::= "node" "(" ")"
101 
102   JSONTest ::= JSONItemTest |
103                JSONObjectTest |
104                JSONArrayTest
105 
106   JSONItemTest ::= "json-item" "(" ")"
107 
108   JSONObjectTest ::= "object" "(" ")"
109 
110   JSONArrayTest ::= "array" "(" ItemType? ")"
111 
112   StructuredItemTest ::= "structured-item" "(" ")"
113 
114 
115   ******************
116   XML Schema Types:
117   ******************
118 
119   XML Schema Type Dichotomies:
120 
121   1. Built-in vs. user-derived datatypes
122   2. Primitive vs. derived datatypes
123   3. Atomic vs. list vs. union datatypes
124   4. Simple vs. complex.
125 
126   1. Built-in datatypes are those which are defined in XMLSchema specification.
127      They are all simple types (no complex built-in types).
128      They can be either atomic or list (no union built-in types).
129      They can be either primitive or derived.
130 
131      User-derived datatypes are those derived datatypes that are defined by
132      individual schema designers. They are always derived. They can be atomic,
133      list, or union, and simple or complex.
134 
135 
136   2. Primitive datatypes are those that are not defined in terms of other
137      datatypes; they exist ab initio. Primitive types are always atomic and
138      built-in.
139 
140      Derived datatypes are those that are defined in terms of other datatypes.
141      They may be built-in or user-defined, atomic, list, or union, and simple
142      or complex.
143 
144      Notes:
145 
146      Every xml schema type T, except from xs:AnyType has a "baseType" P, which
147      is the parent of T in the type hierarchy. This is true even for primitive
148      types: their baseType is xs:anyAtomicType.
149 
150      If T is a type derived from another type D and its base type is P, then D
151      and P may or may not be the same type. For example, list types are derived
152      from their "itemType" (see below), but their "baseType" is always the
153      xs:anySimpleType.
154 
155 
156   3. Atomic datatypes are those having values which are regarded as being
157      indivisible. Atomic datatypes can be built-in or user-defined, and
158      primitive or derived. They are always simple types.
159 
160      A list datatype is derived from an atomic or a union datatype, known as
161      the "itemType" of the list datatype. This yields a datatype whose value
162      space is composed of finite-length sequences of values from the value
163      space of the itemType. List types may be built-in or user-defined. They
164      are always derived and simple types.
165 
166      A union datatype is derived from one or more atomic, list or other union
167      datatypes, known as the "memberTypes" of that union datatype. The value
168      space of a union datatype is the union of the value spaces memberTypes.
169      Union types are always user-defined, derived, simple types.
170 
171   4. Simple types are all the types that are atomic, list, or union types.
172      Everything else is complex types. Complex types are used to describe
173      the internal structure of element or document nodes that contain other
174      elements and/or attributes.
175 
176   XMLSchema allows anonymous types, but XQuery Data Model requires that all
177   XMLSchema types have a name, which is a qname and uniquely identifies the
178   type among all types in the "database" and the in-scope schema definitions.
179 
180 
181   *******************************************************
182   The intersection of SequenceTypes and XMLSchema types:
183   *******************************************************
184 
185   Atomic types represent the intersection between the categories of sequence type
186   and xml schema type. An atomic type, such as xs:integer or my:hatsize, is both a
187   sequence type and a schema type.
188 
189 
190   **********************************************
191   Zorba Built-in types (see root_typemanager.h):
192   **********************************************
193 
194   We preallocate XQType objs for the following sequence types:
195 
196   - The empty-sequence()
197 
198   - xs:anyType*, xs:anySimpleType*, and xs:untyped*
199 
200   - XML Data Mode and XMLSchema both define 45 atomic, built-in types (including
201     xs:anyAtomicType and xs:untypedAtomic). For each such atomic type T, we
202     preallocate 4 XQType objs representing the sequence tyoes T, T?, T*, and T+.
203 
204   - item(), item()?, item()+, item()*
205 
206   - N(), N()?, N()+, N()*, where N is one of node, document-node, text, comment,
207     or processing-instruction.
208 
209   - N(xs:untyped), N(xs:untyped)?, N(xs:untyped)+, N(xs:untyped)*, where N is
210     one of node or document. Note that these types are not really expressible
211     via the SequenceType syntax, but we include them in zorba because they are
212     convenient for certain type-related optimizations.
213 
214   - element(*, xs:anyType), element(*, xs:anyType)?, element(*, xs:anyType)+,
215     element(*, xs:anyType)*
216 
217   - element(*, xs:untyped), element(*, xs:untyped)?, element(*, xs:untyped)+,
218     element(*, xs:untyped)*
219 
220   - attribute(*, xs:anySimpleType), attribute(*, xs:anySimpleType)?,
221     attribute(*, xs:anySimpleType)+, attribute(*, xs:anySimpleType)*
222 
223   - attribute(*, xs:untypedAtomic), attribute(*, xs:untypedAtomic)?,
224     attribute(*, xs:untypedAtomic)+, attribute(*, xs:untypedAtomic)*
225 
226   - structured-item(), structured-item()?,
227     structured-item()+, structured-item()*
228 
229   - The none type
230 
231 
232   *********************
233   XQType Data Members:
234   *********************
235 
236   theManager:
237   -----------
238   XQType instances are created via methods provided by TypeManager and its
239   subclasses. m_manager is a pointer back to the specific TypeManager that
240   created this XQType.
241 
242   theKind:
243   --------
244   The "kind" of this type. One "kind" per each concrete subclass of XQType.
245   See TypeKind enum below
246 
247   theQuantifier:
248   --------------
249   The quantifier of this type.
250 
251   theIsBuiltin:
252   -------------
253   Whether the type is built-in or not. For built-in types refernce counting based
254   garbage collection does not apply; these types are deleted when the root
255   TypeManager is deleted during engine shutdown.
256 
257 ********************************************************************************/
258 class XQType : public SimpleRCObject
259 {
260 public:
261   //
262   // TypeKind contains one enum code for each concrete subclass of XQType
263   //
264   // ATTENTION !!!! The order of the enum values is important because they are
265   // used as indexes into the KIND_STRINGS array !!!!
266   //
267   typedef enum
268   {
269     NONE_KIND = 0,           // special kind of "type" defined by the formal
270                              // semantics. it represents the absence of type.
271                              // for example, the static type of the fn:error
272                              // function is "none". (quantifier = 1)
273 
274     EMPTY_KIND = 1,              // empty-sequence() (quanttifier = ?)
275 
276     ITEM_KIND = 2,               // item() + quantifier
277 
278     ATOMIC_TYPE_KIND = 3,        // atomic, built-in type + quantifier
279 
280     STRUCTURED_ITEM_KIND = 4,    // structured-item() + quantifier
281 
282     NODE_TYPE_KIND = 5,          // KindTest + quantifier
283 
284     JSON_TYPE_KIND = 6,          // JSONTest + quantifier
285 
286     FUNCTION_TYPE_KIND = 7,      // function(...) as ... + quantifier
287 
288     ANY_TYPE_KIND = 8,           // xs:anyType (quanttifier = *)
289 
290     ANY_SIMPLE_TYPE_KIND = 9,    // xs:anySimpleType (quanttifier = *)
291 
292     ANY_FUNCTION_TYPE_KIND = 10, // function(*)
293 
294     UNTYPED_KIND = 11,           // xs:untyped (quanttifier = *)
295 
296     USER_DEFINED_KIND = 12,      // Named, user-defined XMLSchema type (may be atomic,
297                                  // list, union, or complex) + quantifier
298 
299     MAX_TYPE_KIND
300   } TypeKind;
301 
302   //
303   // The content kind of a complex type
304   //
305   typedef enum
306   {
307     MIXED_CONTENT_KIND,         // any kind of children nodes
308     ELEMENT_ONLY_CONTENT_KIND,  // no text nodes as children
309     SIMPLE_CONTENT_KIND,        // no element nodes as children
310     EMPTY_CONTENT_KIND,         // empty (no children at all)
311   } content_kind_t;
312 
313 
314   static std::string contentKindStr(XQType::content_kind_t contentKind);
315 
316 protected:
317   static const char            * KIND_STRINGS[XQType::MAX_TYPE_KIND];
318 
319   TypeManager                  * theManager;
320   TypeKind                       theKind;
321   TypeConstants::quantifier_t    theQuantifier;
322   bool                           theIsBuiltin;
323 
324 
325 public:
326   SERIALIZABLE_ABSTRACT_CLASS(XQType)
327   SERIALIZABLE_CLASS_CONSTRUCTOR2(XQType, SimpleRCObject)
328   void serialize(::zorba::serialization::Archiver& ar);
329 
330 public:
~XQType()331   virtual ~XQType() { }
332 
free()333   void free()
334   {
335     if (!theIsBuiltin)
336       delete this;
337   }
338 
get_manager()339   TypeManager* get_manager() const { return theManager; }
340 
type_kind()341   TypeKind type_kind() const { return theKind; }
342 
get_quantifier()343   TypeConstants::quantifier_t get_quantifier() const { return theQuantifier; }
344 
is_builtin()345   bool is_builtin() const { return theIsBuiltin; }
346 
is_empty()347   bool is_empty() const { return theKind == XQType::EMPTY_KIND; }
348 
is_none()349   bool is_none() const { return theKind == XQType::NONE_KIND; }
350 
351   int max_card() const;
352 
353   int min_card() const;
354 
355   int card() const;
356 
isList()357   virtual bool isList() const { return false; }
358 
content_kind()359   virtual content_kind_t content_kind() const { return MIXED_CONTENT_KIND; };
360 
get_qname()361   virtual store::Item_t get_qname() const { return store::ItemHandle<store::Item>(); }
362 
getBaseBuiltinType()363   virtual xqtref_t getBaseBuiltinType() const { return this; }
364 
365   virtual std::ostream& serialize_ostream(std::ostream& os) const;
366 
367   std::string toString() const;
368 
369   std::string toSchemaString() const;
370 
371 protected:
372   XQType(
373       const TypeManager* manager,
374       TypeKind type_kind,
375       TypeConstants::quantifier_t quantifier,
376       bool builtin);
377 };
378 
379 
380 /***************************************************************************//**
381   NONE is a special sequence "type" defined by the formal semantics. It
382   represents the "absence" of type. For example, the static type of the fn:error
383   function is "none".
384 
385   NONE type has quantifier ONE
386   NONE type is considered a subtype of every other type.
387 ********************************************************************************/
388 class NoneXQType : public XQType
389 {
390 public:
391   NoneXQType(const TypeManager* manager, bool builtin = false);
392 
content_kind()393   content_kind_t content_kind() const { return EMPTY_CONTENT_KIND; };
394 
395  public:
396   SERIALIZABLE_CLASS(NoneXQType)
397   SERIALIZABLE_CLASS_CONSTRUCTOR2(NoneXQType, XQType)
398   void serialize(::zorba::serialization::Archiver& ar);
399 };
400 
401 
402 /***************************************************************************//**
403   Represents the empty sequence
404 ********************************************************************************/
405 class EmptyXQType : public XQType
406 {
407 public:
408   EmptyXQType(const TypeManager* manager, bool builtin = false);
409 
content_kind()410   content_kind_t content_kind() const { return EMPTY_CONTENT_KIND; };
411 
412  public:
413   SERIALIZABLE_CLASS(EmptyXQType)
414   SERIALIZABLE_CLASS_CONSTRUCTOR2(EmptyXQType, XQType)
415   void serialize(::zorba::serialization::Archiver& ar);
416 };
417 
418 
419 /******************************************************************************
420   Class ItemXQType represents sequence types item(), item()?, item()*, or item()+
421 *******************************************************************************/
422 class ItemXQType : public XQType
423 {
424 public:
425   ItemXQType(
426       const TypeManager* tm,
427       TypeConstants::quantifier_t q,
428       bool builtin = false);
429 
430  public:
431   SERIALIZABLE_CLASS(ItemXQType)
432   SERIALIZABLE_CLASS_CONSTRUCTOR2(ItemXQType, XQType)
433   void serialize(::zorba::serialization::Archiver& ar);
434 };
435 
436 
437 /***************************************************************************//**
438   Class AtomicXQType represents all the sequence types whose ItemType is one
439   of the 45 XQDM builtin atomic types.
440 ********************************************************************************/
441 class AtomicXQType : public XQType
442 {
443 public:
444    static const char* ATOMIC_TYPE_CODE_STRINGS[store::XS_LAST];
445 
446 private:
447    store::SchemaTypeCode m_type_code;
448 
449 public:
450   SERIALIZABLE_CLASS(AtomicXQType)
451   SERIALIZABLE_CLASS_CONSTRUCTOR2(AtomicXQType, XQType)
452   void serialize(::zorba::serialization::Archiver& ar);
453 
454 public:
455   AtomicXQType(
456       const TypeManager* manager,
457       store::SchemaTypeCode type_code,
458       TypeConstants::quantifier_t quantifier,
459       bool builtin = false)
460     :
XQType(manager,ATOMIC_TYPE_KIND,quantifier,builtin)461     XQType(manager, ATOMIC_TYPE_KIND, quantifier, builtin),
462     m_type_code(type_code)
463   {
464   }
465 
get_type_code()466   store::SchemaTypeCode get_type_code() const { return m_type_code; }
467 
content_kind()468   content_kind_t content_kind() const { return SIMPLE_CONTENT_KIND; };
469 
470   store::Item_t get_qname() const;
471 
472   virtual std::ostream& serialize_ostream(std::ostream& os) const;
473 };
474 
475 
476 /******************************************************************************
477   Class StructuredItemXQType represents sequence types structured-item(),
478   structured-item()?, structured-item()*, or structured-item()+
479 *******************************************************************************/
480 class StructuredItemXQType : public XQType
481 {
482 public:
483   StructuredItemXQType(
484       const TypeManager* tm,
485       TypeConstants::quantifier_t quant,
486       bool builtin = false);
487 
488  public:
489   SERIALIZABLE_CLASS(StructuredItemXQType)
490   SERIALIZABLE_CLASS_CONSTRUCTOR2(StructuredItemXQType, XQType)
491   void serialize(::zorba::serialization::Archiver& ar);
492 };
493 
494 
495 #ifdef ZORBA_WITH_JSON
496 /***************************************************************************//**
497   Class JSONXQType represents all the sequence types whose ItemType is a
498   JSONTest.
499 ********************************************************************************/
500 class JSONXQType : public XQType
501 {
502 private:
503   store::StoreConsts::JSONItemKind  theJSONKind;
504 
505 public:
506   SERIALIZABLE_CLASS(JSONXQType)
507   SERIALIZABLE_CLASS_CONSTRUCTOR2(JSONXQType, XQType)
508   void serialize(::zorba::serialization::Archiver& ar);
509 
510 public:
511   JSONXQType(
512       const TypeManager* manager,
513       store::StoreConsts::JSONItemKind kind,
514       TypeConstants::quantifier_t quantifier,
515       bool builtin = false);
516 
get_json_kind()517   store::StoreConsts::JSONItemKind get_json_kind() const { return theJSONKind; }
518 
519   std::ostream& serialize_ostream(std::ostream& os) const;
520 };
521 #endif
522 
523 
524 /***************************************************************************//**
525   Class NodeXQType represents all the sequence types whose ItemType is a
526   KindTest.
527 ********************************************************************************/
528 class NodeXQType : public XQType
529 {
530   friend class XQType;
531 
532 private:
533   store::StoreConsts::NodeKind  m_node_kind;
534   store::Item_t                 m_node_name;
535   xqtref_t                      theContentType;
536   bool                          m_nillable;
537   bool                          m_schema_test;
538 
539 public:
540   SERIALIZABLE_CLASS(NodeXQType)
541   SERIALIZABLE_CLASS_CONSTRUCTOR2(NodeXQType, XQType)
542   void serialize(::zorba::serialization::Archiver& ar);
543 
544 public:
545   NodeXQType(
546       const TypeManager* manager,
547       store::StoreConsts::NodeKind nodeKind,
548       const store::Item_t& nodeName,
549       const xqtref_t& contentType,
550       TypeConstants::quantifier_t quantifier,
551       bool nillable,
552       bool schematest,
553       bool builtin = false);
554 
555   NodeXQType(
556       const NodeXQType& source,
557       TypeConstants::quantifier_t quantifier);
558 
get_node_kind()559   store::StoreConsts::NodeKind get_node_kind() const { return m_node_kind; }
560 
get_node_name()561   store::Item* get_node_name() const { return m_node_name.getp(); }
562 
is_schema_test()563   bool is_schema_test() const { return m_schema_test; }
564 
get_content_type()565   const XQType* get_content_type() const { return theContentType.getp(); }
566 
get_nillable()567   bool get_nillable() const { return m_nillable; }
568 
569   bool is_untyped() const;
570 
content_kind()571   content_kind_t content_kind() const { return MIXED_CONTENT_KIND; };
572 
573   bool is_equal(const TypeManager* tm, const NodeXQType& supertype) const;
574 
575   bool is_subtype(
576       const TypeManager* tm,
577       const NodeXQType& supertype,
578       const QueryLoc& loc) const;
579 
580   bool is_supertype(
581       const TypeManager* tm,
582       const store::Item* subitem,
583       const QueryLoc& loc) const;
584 
585   virtual std::ostream& serialize_ostream(std::ostream& os) const;
586 
587 protected:
588   std::string toSchemaStringInternal() const;
589 };
590 
591 
592 /******************************************************************************
593   function(*)
594 *******************************************************************************/
595 class AnyFunctionXQType : public XQType
596 {
597 public:
598   AnyFunctionXQType(const TypeManager* manager, bool builtin = false)
599     :
XQType(manager,ANY_FUNCTION_TYPE_KIND,TypeConstants::QUANT_STAR,builtin)600     XQType(manager, ANY_FUNCTION_TYPE_KIND, TypeConstants::QUANT_STAR, builtin)
601   {
602   }
603 
604   AnyFunctionXQType(
605       const TypeManager* manager,
606       TypeConstants::quantifier_t quantifier,
607       bool builtin = false)
608     :
XQType(manager,ANY_FUNCTION_TYPE_KIND,quantifier,builtin)609     XQType(manager, ANY_FUNCTION_TYPE_KIND, quantifier, builtin)
610   {
611   }
612 
613  public:
614   SERIALIZABLE_CLASS(AnyFunctionXQType)
615   SERIALIZABLE_CLASS_CONSTRUCTOR2(AnyFunctionXQType, XQType)
616   void serialize(::zorba::serialization::Archiver& ar);
617 };
618 
619 
620 /***************************************************************************//**
621   Class FunctionXQType represents all the sequence types whose ItemType is a
622   FunctionType.
623 ********************************************************************************/
624 class FunctionXQType : public XQType
625 {
626 private:
627   std::vector<xqtref_t>         m_param_types;
628   xqtref_t                      m_return_type;
629 
630 public:
631   SERIALIZABLE_CLASS(FunctionXQType)
632   SERIALIZABLE_CLASS_CONSTRUCTOR2(FunctionXQType, XQType)
633   void serialize(::zorba::serialization::Archiver& ar);
634 
635 public:
636   FunctionXQType(
637         const TypeManager* manager,
638         const std::vector<xqtref_t>& aParamTypes,
639         const xqtref_t& aReturnType,
640         TypeConstants::quantifier_t quantifier,
641         bool builtin = false);
642 
643   const std::vector<xqtref_t>&
get_param_types()644   get_param_types() const { return m_param_types; }
645 
646   const xqtref_t&
647   operator[](size_t i) const { return m_param_types[i]; }
648 
649   size_t
get_number_params()650   get_number_params() const { return m_param_types.size(); }
651 
get_return_type()652   xqtref_t get_return_type() const { return m_return_type; }
653 
654   bool is_equal(const TypeManager* tm, const FunctionXQType& supertype) const;
655 
656   bool is_subtype(const TypeManager* tm, const FunctionXQType& supertype) const;
657 
658   virtual std::ostream& serialize_ostream(std::ostream& os) const;
659 };
660 
661 
662 /***************************************************************************//**
663   Represents :
664 
665   (a) a XMLSchema user-defined type that describes the content of an element
666       or attribute node, or
667   (b) a sequence type whose ItemType is a user0defined atomic type.
668 
669   Note: unless the user-defined tpye is an atomic one, the quentifier of
670   "this" must be QUANT_ONE.
671 
672   m_qname          : The name of this user-defined type. The actual type
673                      definition is stored in the TypeManger that created this
674                      type (and is pointed to my theManager). The TypeManager
675                      also stores the mapping from the type name to the type
676                      definition.
677   m_base_type      : The baseType of this type. NULL for list or union types.
678   m_typeCategory   : Whether this is an atomic, list, union, or complex type.
679   m_contentKind    : This type's content kind, if this is a complex type. One
680                      of empty, simple, element-only, or mixed.
681   m_listItemType   : This type's itemType, if this is a list type.
682   m_unionItemTypes : This type's memberTypes, if this is a union type.
683 ********************************************************************************/
684 class UserDefinedXQType : public XQType
685 {
686 public:
687   enum type_category_t
688   {
689     ATOMIC_TYPE,  // atomic types: ex: int, date, token, string
690     LIST_TYPE,    // list of simple types: ex: list of int: "1 2 33"
691     UNION_TYPE,   // union of simple types: ShirtSize int or string: "8", "small"
692                   // ATOMIC, LIST and UNION types are all SIMPLE types: i.e.
693                   // their representation is a text value
694     COMPLEX_TYPE  // complex types: they represent structure
695   };
696 
697 
698 private:
699   store::Item_t           m_qname;
700   xqtref_t                m_baseType;
701   type_category_t         m_typeCategory;
702   content_kind_t          m_contentKind;
703   std::vector<xqtref_t>   m_unionItemTypes;
704   xqtref_t                m_listItemType;
705 
706 public:
707   SERIALIZABLE_CLASS(UserDefinedXQType)
708   SERIALIZABLE_CLASS_CONSTRUCTOR2(UserDefinedXQType, XQType)
709   void serialize(::zorba::serialization::Archiver& ar);
710 
711 public:
712   // constructor for Atomic and Complex types
713   UserDefinedXQType(
714         const TypeManager *manager,
715         store::Item_t qname,
716         const xqtref_t& baseType,
717         TypeConstants::quantifier_t quantifier,
718         type_category_t typeCategory,
719         content_kind_t contentKind);
720 
721   // Constructor for List types
722   UserDefinedXQType(
723         const TypeManager *manager,
724         store::Item_t qname,
725         const xqtref_t& baseType,
726         TypeConstants::quantifier_t quantifier,
727         const XQType* listItemType);
728 
729   // Constructor for Union types
730   UserDefinedXQType(
731         const TypeManager *manager,
732         store::Item_t qname,
733         const xqtref_t& baseType,
734         TypeConstants::quantifier_t quantifier,
735         std::vector<xqtref_t>& unionItemTypes);
736 
~UserDefinedXQType()737   virtual ~UserDefinedXQType() {}
738 
content_kind()739   virtual content_kind_t content_kind() const { return m_contentKind; };
740 
get_qname()741   store::Item_t get_qname() const { return m_qname;    }
742 
isAtomic()743   bool isAtomic() const { return m_typeCategory == ATOMIC_TYPE;  }
744 
isList()745   bool isList() const { return m_typeCategory == LIST_TYPE;    }
746 
isUnion()747   bool isUnion() const { return m_typeCategory == UNION_TYPE;   }
748 
isComplex()749   bool isComplex() const { return m_typeCategory == COMPLEX_TYPE; }
750 
getTypeCategory()751   type_category_t getTypeCategory() const { return m_typeCategory; }
752 
getBaseType()753   xqtref_t getBaseType() const { return m_baseType; }
754 
755   xqtref_t getBaseBuiltinType() const;
756 
getListItemType()757   const XQType* getListItemType() const { return m_listItemType.getp(); }
758 
getUnionItemTypes()759   const std::vector<xqtref_t>& getUnionItemTypes() const { return m_unionItemTypes; }
760 
761   bool isSuperTypeOf(const TypeManager* tm, const XQType& subType) const;
762 
763   bool isSubTypeOf(const TypeManager* tm, const XQType& superType) const;
764 
765   static std::string typeCategoryStr(type_category_t typeCategory);
766 
767   virtual std::ostream& serialize_ostream(std::ostream& os) const;
768 };
769 
770 
771 /***************************************************************************//**
772   xs:untyped
773 ********************************************************************************/
774 class UntypedXQType : public XQType
775 {
776 public:
777   UntypedXQType(const TypeManager* manager, bool builtin = false)
778     :
XQType(manager,UNTYPED_KIND,TypeConstants::QUANT_STAR,builtin)779     XQType(manager, UNTYPED_KIND, TypeConstants::QUANT_STAR, builtin)
780   {
781   }
782 
783   store::Item_t get_qname() const;
784 
785  public:
786   SERIALIZABLE_CLASS(UntypedXQType)
787   SERIALIZABLE_CLASS_CONSTRUCTOR2(UntypedXQType, XQType)
788   void serialize(::zorba::serialization::Archiver& ar);
789 };
790 
791 
792 /******************************************************************************
793   xs:anyType
794 *******************************************************************************/
795 class AnyXQType : public XQType
796 {
797 public:
798   AnyXQType(const TypeManager* manager, bool builtin = false)
799     :
XQType(manager,ANY_TYPE_KIND,TypeConstants::QUANT_STAR,builtin)800     XQType(manager, ANY_TYPE_KIND, TypeConstants::QUANT_STAR, builtin)
801   {
802   }
803 
804   store::Item_t get_qname() const;
805 
806  public:
807   SERIALIZABLE_CLASS(AnyXQType)
808   SERIALIZABLE_CLASS_CONSTRUCTOR2(AnyXQType, XQType)
809   void serialize(::zorba::serialization::Archiver& ar);
810 };
811 
812 
813 /******************************************************************************
814   xs:anySimpleType
815 *******************************************************************************/
816 class AnySimpleXQType : public XQType
817 {
818 public:
819   AnySimpleXQType(const TypeManager* manager, bool builtin = false)
820     :
XQType(manager,ANY_SIMPLE_TYPE_KIND,TypeConstants::QUANT_STAR,builtin)821     XQType(manager, ANY_SIMPLE_TYPE_KIND, TypeConstants::QUANT_STAR, builtin)
822   {
823   }
824 
content_kind()825   content_kind_t content_kind() const { return SIMPLE_CONTENT_KIND; };
826 
827   store::Item_t get_qname() const;
828 
829 public:
830   SERIALIZABLE_CLASS(AnySimpleXQType)
831   SERIALIZABLE_CLASS_CONSTRUCTOR2(AnySimpleXQType, XQType)
832   void serialize(::zorba::serialization::Archiver& ar);
833 };
834 
835 
836 }
837 
838 #endif /* ZORBA_TYPEIMPL_H */
839 
840 /*
841  * Local variables:
842  * mode: c++
843  * End:
844  */
845 /* vim:set et sw=2 ts=2: */
846