summaryrefslogtreecommitdiff
path: root/src/xmlpatterns/expr/qoptimizerblocks_p.h
blob: 722f628d03ab0a6f49e1c1fcb7dbd6ae421fe290 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtXmlPatterns module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.

#ifndef Patternist_OptimizerBlocks_H
#define Patternist_OptimizerBlocks_H

#include <private/qatomiccomparator_p.h>
#include <private/qexpression_p.h>
#include <private/qoptimizerframework_p.h>

QT_BEGIN_NAMESPACE

namespace QPatternist
{
    /**
     * @short Identifies Expression instances by their Expression::id().
     *
     * @author Frans englich <frans.englich@nokia.com>
     * @ingroup Patternist_expressions
     */
    class ByIDIdentifier : public ExpressionIdentifier
    {
    public:
        ByIDIdentifier(const Expression::ID id);
        virtual bool matches(const Expression::Ptr &expr) const;
    private:
        const Expression::ID m_id;
    };

    /**
     * @short Identifies Expression instances based on their static type.
     *
     * BySequenceTypeIdentifier identifies Expression instances
     * if their Expression::staticType() matches the requested one,
     * regardless of whether the Expression is a particular one, such
     * as AndExpression.
     *
     * For example, constructing a BySequenceTypeIdentifier while
     * passing CommonSequenceTypes::EBV in its constructor will create
     * a ExpressionIdentifier that returns @c true for a static type with
     * item type <tt>xs:string</tt>, but returns @c false for a static type involving
     * <tt>xs:date</tt>.
     *
     * @author Frans englich <frans.englich@nokia.com>
     * @ingroup Patternist_expressions
     */
    class BySequenceTypeIdentifier : public ExpressionIdentifier
    {
    public:
        BySequenceTypeIdentifier(const SequenceType::Ptr &seqType);

        /**
         * @returns @c true, if the static type of @p expr is matches
         * the SequenceType passed in the BySequenceTypeIdentifier()
         * constructor, otherwise @c false.
         */
        virtual bool matches(const Expression::Ptr &expr) const;

    private:
        const SequenceType::Ptr m_seqType;
    };

    /**
     * @short Determines whether an Expression is a value or general comparison or both,
     * with a certain operator.
     *
     * @author Frans englich <frans.englich@nokia.com>
     * @ingroup Patternist_expressions
     */
    class ComparisonIdentifier : public ExpressionIdentifier
    {
    public:

        /**
         * @param comparatorHosts the possible parent that may have
         * the operator. This may be Expression::IDGeneralComparison or
         * Expression::IDValueComparison. The two values may also be OR'd,
         * meaning any of them will do.
         *
         * @param op the operator that the comparator host must have. For example,
         * if @p op is AtomicComparator::OperatorGreatorOrEqual this ComparisonIdentifier
         * will match operator >= in the case of IDGeneralComparison and 'ge' in the
         * case of IDValueComparison.
         */
        ComparisonIdentifier(const QVector<Expression::ID> comparatorHosts,
                             const AtomicComparator::Operator op);

        /**
         * @returns @c true, if @p expr is a ValueComparison with the operator
         * passed in ComparisonIdentifier().
         */
        virtual bool matches(const Expression::Ptr &expr) const;

    private:
        const QVector<Expression::ID> m_hosts;
        const AtomicComparator::Operator m_op;
    };

    /**
     * @short Matches numeric literals that are of type xs:integer and
     * has a specific value.
     *
     * For example IntegerIdentifier(4) would match the former but
     * not the latter operand in this expression: "4 + 5".
     *
     * @author Frans englich <frans.englich@nokia.com>
     * @ingroup Patternist_expressions
     */
    class IntegerIdentifier : public ExpressionIdentifier
    {
    public:
        IntegerIdentifier(const xsInteger num);
        virtual bool matches(const Expression::Ptr &expr) const;

    private:
        const xsInteger m_num;
    };

    /**
     * @short Matches boolean literals.
     *
     * For example BooleanIdentifier(true) would match the former but
     * not the latter operand in this expression: "true() + false()".
     *
     * @author Frans englich <frans.englich@nokia.com>
     * @ingroup Patternist_expressions
     */
    class BooleanIdentifier : public ExpressionIdentifier
    {
    public:
        BooleanIdentifier(const bool value);
        virtual bool matches(const Expression::Ptr &expr) const;

    private:
        const bool m_value;
    };

    /**
     * @short Creates a particular Expression instance identified by an Expression::ID.
     *
     * For example, if ByIDCreator() is passed Expression::IDCountFN, create()
     * will return CountFN instances.
     *
     * @author Frans englich <frans.englich@nokia.com>
     * @ingroup Patternist_expressions
     */
    class ByIDCreator : public ExpressionCreator
    {
    public:
        /**
         * Creates a ByIDCreator that creates expressions
         * of the type that @p id identifies.
         */
        ByIDCreator(const Expression::ID id);
        virtual Expression::Ptr create(const Expression::List &operands,
                                       const StaticContext::Ptr &context,
                                       const SourceLocationReflection *const r) const;

        /**
         * Creates an expression by id @p id with the arguments @p operands.
         */
        static Expression::Ptr create(const Expression::ID id,
                                      const Expression::List &operands,
                                      const StaticContext::Ptr &context,
                                      const SourceLocationReflection *const r);

    private:
        const Expression::ID m_id;
    };
}

QT_END_NAMESPACE

#endif