1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | //
|
---|
43 | // W A R N I N G
|
---|
44 | // -------------
|
---|
45 | //
|
---|
46 | // This file is not part of the Qt API. It exists purely as an
|
---|
47 | // implementation detail. This header file may change from version to
|
---|
48 | // version without notice, or even be removed.
|
---|
49 | //
|
---|
50 | // We mean it.
|
---|
51 |
|
---|
52 | #ifndef Patternist_OptimizerBlocks_H
|
---|
53 | #define Patternist_OptimizerBlocks_H
|
---|
54 |
|
---|
55 | #include "qatomiccomparator_p.h"
|
---|
56 | #include "qexpression_p.h"
|
---|
57 | #include "qoptimizerframework_p.h"
|
---|
58 |
|
---|
59 | QT_BEGIN_HEADER
|
---|
60 |
|
---|
61 | QT_BEGIN_NAMESPACE
|
---|
62 |
|
---|
63 | namespace QPatternist
|
---|
64 | {
|
---|
65 | /**
|
---|
66 | * @short Identifies Expression instances by their Expression::id().
|
---|
67 | *
|
---|
68 | * @author Frans englich <[email protected]>
|
---|
69 | * @ingroup Patternist_expressions
|
---|
70 | */
|
---|
71 | class ByIDIdentifier : public ExpressionIdentifier
|
---|
72 | {
|
---|
73 | public:
|
---|
74 | ByIDIdentifier(const Expression::ID id);
|
---|
75 | virtual bool matches(const Expression::Ptr &expr) const;
|
---|
76 | private:
|
---|
77 | const Expression::ID m_id;
|
---|
78 | };
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * @short Identifies Expression instances based on their static type.
|
---|
82 | *
|
---|
83 | * BySequenceTypeIdentifier identifies Expression instances
|
---|
84 | * if their Expression::staticType() matches the requested one,
|
---|
85 | * regardless of whether the Expression is a particular one, such
|
---|
86 | * as AndExpression.
|
---|
87 | *
|
---|
88 | * For example, constructing a BySequenceTypeIdentifier while
|
---|
89 | * passing CommonSequenceTypes::EBV in its constructor will create
|
---|
90 | * a ExpressionIdentifier that returns @c true for a static type with
|
---|
91 | * item type <tt>xs:string</tt>, but returns @c false for a static type involving
|
---|
92 | * <tt>xs:date</tt>.
|
---|
93 | *
|
---|
94 | * @author Frans englich <[email protected]>
|
---|
95 | * @ingroup Patternist_expressions
|
---|
96 | */
|
---|
97 | class BySequenceTypeIdentifier : public ExpressionIdentifier
|
---|
98 | {
|
---|
99 | public:
|
---|
100 | BySequenceTypeIdentifier(const SequenceType::Ptr &seqType);
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * @returns @c true, if the static type of @p expr is matches
|
---|
104 | * the SequenceType passed in the BySequenceTypeIdentifier()
|
---|
105 | * constructor, otherwise @c false.
|
---|
106 | */
|
---|
107 | virtual bool matches(const Expression::Ptr &expr) const;
|
---|
108 |
|
---|
109 | private:
|
---|
110 | const SequenceType::Ptr m_seqType;
|
---|
111 | };
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * @short Determines whether an Expression is a value or general comparison or both,
|
---|
115 | * with a certain operator.
|
---|
116 | *
|
---|
117 | * @author Frans englich <[email protected]>
|
---|
118 | * @ingroup Patternist_expressions
|
---|
119 | */
|
---|
120 | class ComparisonIdentifier : public ExpressionIdentifier
|
---|
121 | {
|
---|
122 | public:
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * @param comparatorHosts the possible parent that may have
|
---|
126 | * the operator. This may be Expression::IDGeneralComparison or
|
---|
127 | * Expression::IDValueComparison. The two values may also be OR'd,
|
---|
128 | * meaning any of them will do.
|
---|
129 | *
|
---|
130 | * @param op the operator that the comparator host must have. For example,
|
---|
131 | * if @p op is AtomicComparator::OperatorGreatorOrEqual this ComparisonIdentifier
|
---|
132 | * will match operator >= in the case of IDGeneralComparison and 'ge' in the
|
---|
133 | * case of IDValueComparison.
|
---|
134 | */
|
---|
135 | ComparisonIdentifier(const QVector<Expression::ID> comparatorHosts,
|
---|
136 | const AtomicComparator::Operator op);
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * @returns @c true, if @p expr is a ValueComparison with the operator
|
---|
140 | * passed in ComparisonIdentifier().
|
---|
141 | */
|
---|
142 | virtual bool matches(const Expression::Ptr &expr) const;
|
---|
143 |
|
---|
144 | private:
|
---|
145 | const QVector<Expression::ID> m_hosts;
|
---|
146 | const AtomicComparator::Operator m_op;
|
---|
147 | };
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * @short Matches numeric literals that are of type xs:integer and
|
---|
151 | * has a specific value.
|
---|
152 | *
|
---|
153 | * For example IntegerIdentifier(4) would match the former but
|
---|
154 | * not the latter operand in this expression: "4 + 5".
|
---|
155 | *
|
---|
156 | * @author Frans englich <[email protected]>
|
---|
157 | * @ingroup Patternist_expressions
|
---|
158 | */
|
---|
159 | class IntegerIdentifier : public ExpressionIdentifier
|
---|
160 | {
|
---|
161 | public:
|
---|
162 | IntegerIdentifier(const xsInteger num);
|
---|
163 | virtual bool matches(const Expression::Ptr &expr) const;
|
---|
164 |
|
---|
165 | private:
|
---|
166 | const xsInteger m_num;
|
---|
167 | };
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * @short Matches boolean literals.
|
---|
171 | *
|
---|
172 | * For example BooleanIdentifier(true) would match the former but
|
---|
173 | * not the latter operand in this expression: "true() + false()".
|
---|
174 | *
|
---|
175 | * @author Frans englich <[email protected]>
|
---|
176 | * @ingroup Patternist_expressions
|
---|
177 | */
|
---|
178 | class BooleanIdentifier : public ExpressionIdentifier
|
---|
179 | {
|
---|
180 | public:
|
---|
181 | BooleanIdentifier(const bool value);
|
---|
182 | virtual bool matches(const Expression::Ptr &expr) const;
|
---|
183 |
|
---|
184 | private:
|
---|
185 | const bool m_value;
|
---|
186 | };
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * @short Creates a particular Expression instance identified by an Expression::ID.
|
---|
190 | *
|
---|
191 | * For example, if ByIDCreator() is passed Expression::IDCountFN, create()
|
---|
192 | * will return CountFN instances.
|
---|
193 | *
|
---|
194 | * @author Frans englich <[email protected]>
|
---|
195 | * @ingroup Patternist_expressions
|
---|
196 | */
|
---|
197 | class ByIDCreator : public ExpressionCreator
|
---|
198 | {
|
---|
199 | public:
|
---|
200 | /**
|
---|
201 | * Creates a ByIDCreator that creates expressions
|
---|
202 | * of the type that @p id identifies.
|
---|
203 | */
|
---|
204 | ByIDCreator(const Expression::ID id);
|
---|
205 | virtual Expression::Ptr create(const Expression::List &operands,
|
---|
206 | const StaticContext::Ptr &context,
|
---|
207 | const SourceLocationReflection *const r) const;
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * Creates an expression by id @p id with the arguments @p operands.
|
---|
211 | */
|
---|
212 | static Expression::Ptr create(const Expression::ID id,
|
---|
213 | const Expression::List &operands,
|
---|
214 | const StaticContext::Ptr &context,
|
---|
215 | const SourceLocationReflection *const r);
|
---|
216 |
|
---|
217 | private:
|
---|
218 | const Expression::ID m_id;
|
---|
219 | };
|
---|
220 | }
|
---|
221 |
|
---|
222 | QT_END_NAMESPACE
|
---|
223 |
|
---|
224 | QT_END_HEADER
|
---|
225 |
|
---|
226 | #endif
|
---|