1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
52 #ifndef Patternist_OptimizerBlocks_H
53 #define Patternist_OptimizerBlocks_H
55 #include <private/qatomiccomparator_p.h>
56 #include <private/qexpression_p.h>
57 #include <private/qoptimizerframework_p.h>
66 * @short Identifies Expression instances by their Expression::id().
68 * @author Frans englich <frans.englich@nokia.com>
69 * @ingroup Patternist_expressions
71 class ByIDIdentifier : public ExpressionIdentifier
74 ByIDIdentifier(const Expression::ID id);
75 virtual bool matches(const Expression::Ptr &expr) const;
77 const Expression::ID m_id;
81 * @short Identifies Expression instances based on their static type.
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
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
94 * @author Frans englich <frans.englich@nokia.com>
95 * @ingroup Patternist_expressions
97 class BySequenceTypeIdentifier : public ExpressionIdentifier
100 BySequenceTypeIdentifier(const SequenceType::Ptr &seqType);
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.
107 virtual bool matches(const Expression::Ptr &expr) const;
110 const SequenceType::Ptr m_seqType;
114 * @short Determines whether an Expression is a value or general comparison or both,
115 * with a certain operator.
117 * @author Frans englich <frans.englich@nokia.com>
118 * @ingroup Patternist_expressions
120 class ComparisonIdentifier : public ExpressionIdentifier
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.
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.
135 ComparisonIdentifier(const QVector<Expression::ID> comparatorHosts,
136 const AtomicComparator::Operator op);
139 * @returns @c true, if @p expr is a ValueComparison with the operator
140 * passed in ComparisonIdentifier().
142 virtual bool matches(const Expression::Ptr &expr) const;
145 const QVector<Expression::ID> m_hosts;
146 const AtomicComparator::Operator m_op;
150 * @short Matches numeric literals that are of type xs:integer and
151 * has a specific value.
153 * For example IntegerIdentifier(4) would match the former but
154 * not the latter operand in this expression: "4 + 5".
156 * @author Frans englich <frans.englich@nokia.com>
157 * @ingroup Patternist_expressions
159 class IntegerIdentifier : public ExpressionIdentifier
162 IntegerIdentifier(const xsInteger num);
163 virtual bool matches(const Expression::Ptr &expr) const;
166 const xsInteger m_num;
170 * @short Matches boolean literals.
172 * For example BooleanIdentifier(true) would match the former but
173 * not the latter operand in this expression: "true() + false()".
175 * @author Frans englich <frans.englich@nokia.com>
176 * @ingroup Patternist_expressions
178 class BooleanIdentifier : public ExpressionIdentifier
181 BooleanIdentifier(const bool value);
182 virtual bool matches(const Expression::Ptr &expr) const;
189 * @short Creates a particular Expression instance identified by an Expression::ID.
191 * For example, if ByIDCreator() is passed Expression::IDCountFN, create()
192 * will return CountFN instances.
194 * @author Frans englich <frans.englich@nokia.com>
195 * @ingroup Patternist_expressions
197 class ByIDCreator : public ExpressionCreator
201 * Creates a ByIDCreator that creates expressions
202 * of the type that @p id identifies.
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;
210 * Creates an expression by id @p id with the arguments @p operands.
212 static Expression::Ptr create(const Expression::ID id,
213 const Expression::List &operands,
214 const StaticContext::Ptr &context,
215 const SourceLocationReflection *const r);
218 const Expression::ID m_id;