1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49
50#ifndef Patternist_NoneType_H
51#define Patternist_NoneType_H
52
53#include <private/qatomictype_p.h>
54#include <private/qsequencetype_p.h>
55
56QT_BEGIN_NAMESPACE
57
58namespace QPatternist
59{
60
61 /**
62 * @short Represents the special <tt>none</tt> type.
63 *
64 * @ingroup Patternist_types
65 * @see <a href="http://www.w3.org/TR/xquery-semantics/#sec_content_models">XQuery 1.0 and
66 * XPath 2.0 Formal Semantics, 2.4.3 Content models</a>
67 * @see <a href="http://www.w3.org/TR/xquery-semantics/#sec_fnerror">XQuery 1.0 and XPath 2.0
68 * Formal Semantics, 7.2.9 The fn:error function</a>
69 * @author Frans Englich <frans.englich@nokia.com>
70 */
71 class NoneType : public ItemType,
72 public SequenceType
73 {
74 public:
75 typedef QExplicitlySharedDataPointer<NoneType> Ptr;
76
77 bool itemMatches(const Item &item) const override;
78 bool xdtTypeMatches(const ItemType::Ptr &other) const override;
79
80 /**
81 * @returns always "none". That is, no namespace prefix
82 */
83 QString displayName(const NamePool::Ptr &np) const override;
84
85 /**
86 * @note The semantical meaning of this type's item type can
87 * surely be discussed. The function is provided due to
88 * it being mandated by the SequenceType base class.
89 *
90 * @returns always 'this' since NoneType is also an ItemType
91 */
92 ItemType::Ptr itemType() const override;
93
94 /**
95 * @note The semantical meaning of this type's cardinality
96 * can surely be discussed. The function is provided due to
97 * it being mandated by the SequenceType base class.
98 *
99 * @returns always Cardinality::zeroOrMore()
100 */
101 Cardinality cardinality() const override;
102
103 /**
104 * @returns always @c false
105 */
106 bool isAtomicType() const override;
107
108 /**
109 * This can be thought to be a weird function for this type(none). There
110 * is no atomized type for none, perhaps the best from a conceptual perspective
111 * would be to return @c null.
112 *
113 * This function returns BuiltinTypes::xsAnyAtomicType because
114 * the generic type checking code inserts an Atomizer in the AST
115 * when an error() function(or other node which has type none) is part of
116 * an operator expression(value/general comparison, arithmetics). The Atomizer
117 * returns the atomizedType() of its child, and by here returning xsAnyAtomicType,
118 * static operator lookup is postponed to runtime. Subsequently, expressions like error()
119 * works properly with other XPath expressions.
120 */
121 ItemType::Ptr atomizedType() const override;
122
123 /**
124 * @returns always @c false
125 */
126 bool isNodeType() const override;
127
128 /**
129 * @returns always item()
130 */
131 ItemType::Ptr xdtSuperType() const override;
132
133 /**
134 * @returns always @p other. The none type can be thought as
135 * disappearing when attempting to find the union of it and
136 * another type.
137 */
138 const ItemType &operator|(const ItemType &other) const override;
139
140 protected:
141
142 friend class CommonSequenceTypes;
143 NoneType();
144 };
145}
146
147QT_END_NAMESPACE
148
149#endif
150

source code of qtxmlpatterns/src/xmlpatterns/type/qnonetype_p.h