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_OptimizerBlocks_H |
51 | #define Patternist_OptimizerBlocks_H |
52 | |
53 | #include <private/qatomiccomparator_p.h> |
54 | #include <private/qexpression_p.h> |
55 | #include <private/qoptimizerframework_p.h> |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | namespace QPatternist |
60 | { |
61 | /** |
62 | * @short Identifies Expression instances by their Expression::id(). |
63 | * |
64 | * @author Frans englich <frans.englich@nokia.com> |
65 | * @ingroup Patternist_expressions |
66 | */ |
67 | class ByIDIdentifier : public ExpressionIdentifier |
68 | { |
69 | public: |
70 | ByIDIdentifier(const Expression::ID id); |
71 | virtual bool matches(const Expression::Ptr &expr) const; |
72 | private: |
73 | const Expression::ID m_id; |
74 | }; |
75 | |
76 | /** |
77 | * @short Identifies Expression instances based on their static type. |
78 | * |
79 | * BySequenceTypeIdentifier identifies Expression instances |
80 | * if their Expression::staticType() matches the requested one, |
81 | * regardless of whether the Expression is a particular one, such |
82 | * as AndExpression. |
83 | * |
84 | * For example, constructing a BySequenceTypeIdentifier while |
85 | * passing CommonSequenceTypes::EBV in its constructor will create |
86 | * a ExpressionIdentifier that returns @c true for a static type with |
87 | * item type <tt>xs:string</tt>, but returns @c false for a static type involving |
88 | * <tt>xs:date</tt>. |
89 | * |
90 | * @author Frans englich <frans.englich@nokia.com> |
91 | * @ingroup Patternist_expressions |
92 | */ |
93 | class BySequenceTypeIdentifier : public ExpressionIdentifier |
94 | { |
95 | public: |
96 | BySequenceTypeIdentifier(const SequenceType::Ptr &seqType); |
97 | |
98 | /** |
99 | * @returns @c true, if the static type of @p expr is matches |
100 | * the SequenceType passed in the BySequenceTypeIdentifier() |
101 | * constructor, otherwise @c false. |
102 | */ |
103 | virtual bool matches(const Expression::Ptr &expr) const; |
104 | |
105 | private: |
106 | const SequenceType::Ptr m_seqType; |
107 | }; |
108 | |
109 | /** |
110 | * @short Determines whether an Expression is a value or general comparison or both, |
111 | * with a certain operator. |
112 | * |
113 | * @author Frans englich <frans.englich@nokia.com> |
114 | * @ingroup Patternist_expressions |
115 | */ |
116 | class ComparisonIdentifier : public ExpressionIdentifier |
117 | { |
118 | public: |
119 | |
120 | /** |
121 | * @param comparatorHosts the possible parent that may have |
122 | * the operator. This may be Expression::IDGeneralComparison or |
123 | * Expression::IDValueComparison. The two values may also be OR'd, |
124 | * meaning any of them will do. |
125 | * |
126 | * @param op the operator that the comparator host must have. For example, |
127 | * if @p op is AtomicComparator::OperatorGreatorOrEqual this ComparisonIdentifier |
128 | * will match operator >= in the case of IDGeneralComparison and 'ge' in the |
129 | * case of IDValueComparison. |
130 | */ |
131 | ComparisonIdentifier(const QVector<Expression::ID> comparatorHosts, |
132 | const AtomicComparator::Operator op); |
133 | |
134 | /** |
135 | * @returns @c true, if @p expr is a ValueComparison with the operator |
136 | * passed in ComparisonIdentifier(). |
137 | */ |
138 | virtual bool matches(const Expression::Ptr &expr) const; |
139 | |
140 | private: |
141 | const QVector<Expression::ID> m_hosts; |
142 | const AtomicComparator::Operator m_op; |
143 | }; |
144 | |
145 | /** |
146 | * @short Matches numeric literals that are of type xs:integer and |
147 | * has a specific value. |
148 | * |
149 | * For example IntegerIdentifier(4) would match the former but |
150 | * not the latter operand in this expression: "4 + 5". |
151 | * |
152 | * @author Frans englich <frans.englich@nokia.com> |
153 | * @ingroup Patternist_expressions |
154 | */ |
155 | class IntegerIdentifier : public ExpressionIdentifier |
156 | { |
157 | public: |
158 | IntegerIdentifier(const xsInteger num); |
159 | virtual bool matches(const Expression::Ptr &expr) const; |
160 | |
161 | private: |
162 | const xsInteger m_num; |
163 | }; |
164 | |
165 | /** |
166 | * @short Matches boolean literals. |
167 | * |
168 | * For example BooleanIdentifier(true) would match the former but |
169 | * not the latter operand in this expression: "true() + false()". |
170 | * |
171 | * @author Frans englich <frans.englich@nokia.com> |
172 | * @ingroup Patternist_expressions |
173 | */ |
174 | class BooleanIdentifier : public ExpressionIdentifier |
175 | { |
176 | public: |
177 | BooleanIdentifier(const bool value); |
178 | virtual bool matches(const Expression::Ptr &expr) const; |
179 | |
180 | private: |
181 | const bool m_value; |
182 | }; |
183 | |
184 | /** |
185 | * @short Creates a particular Expression instance identified by an Expression::ID. |
186 | * |
187 | * For example, if ByIDCreator() is passed Expression::IDCountFN, create() |
188 | * will return CountFN instances. |
189 | * |
190 | * @author Frans englich <frans.englich@nokia.com> |
191 | * @ingroup Patternist_expressions |
192 | */ |
193 | class ByIDCreator : public ExpressionCreator |
194 | { |
195 | public: |
196 | /** |
197 | * Creates a ByIDCreator that creates expressions |
198 | * of the type that @p id identifies. |
199 | */ |
200 | ByIDCreator(const Expression::ID id); |
201 | virtual Expression::Ptr create(const Expression::List &operands, |
202 | const StaticContext::Ptr &context, |
203 | const SourceLocationReflection *const r) const; |
204 | |
205 | /** |
206 | * Creates an expression by id @p id with the arguments @p operands. |
207 | */ |
208 | static Expression::Ptr create(const Expression::ID id, |
209 | const Expression::List &operands, |
210 | const StaticContext::Ptr &context, |
211 | const SourceLocationReflection *const r); |
212 | |
213 | private: |
214 | const Expression::ID m_id; |
215 | }; |
216 | } |
217 | |
218 | QT_END_NAMESPACE |
219 | |
220 | #endif |
221 | |