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#include "qabstractfloatmathematician_p.h"
41#include "qatomicmathematicianlocators_p.h"
42#include "qatomicmathematicians_p.h"
43
44QT_BEGIN_NAMESPACE
45
46using namespace QPatternist;
47
48#define implMathVisit(ownerClass, visitor, mather, validOps) \
49AtomicTypeVisitorResult::Ptr \
50ownerClass##MathematicianLocator::visit(const visitor *, const qint16 opIn, \
51 const SourceLocationReflection *const r) const \
52{ \
53 Q_UNUSED(r) \
54 /* Note the extra paranteses around validOps. */ \
55 const AtomicComparator::Operator op = AtomicComparator::Operator(opIn); \
56 if (((validOps) & op) == op) \
57 return AtomicTypeVisitorResult::Ptr(new mather()); \
58 else \
59 return AtomicTypeVisitorResult::Ptr(); \
60}
61
62#define implReportingMathVisit(ownerClass, visitor, mather, validOps) \
63AtomicTypeVisitorResult::Ptr \
64ownerClass##MathematicianLocator::visit(const visitor *, const qint16 opIn, \
65 const SourceLocationReflection *const r) const \
66{ \
67 const AtomicComparator::Operator op = AtomicComparator::Operator(opIn); \
68 /* Note the extra paranteses around validOps. */ \
69 if (((validOps) & op) == op) \
70 return AtomicTypeVisitorResult::Ptr(new mather(r)); \
71 else \
72 return AtomicTypeVisitorResult::Ptr(); \
73}
74
75#define implRevReportingMathVisit(ownerClass, visitor, mather, validOps) \
76AtomicTypeVisitorResult::Ptr \
77ownerClass##MathematicianLocator::visit(const visitor *, const qint16 opIn, \
78 const SourceLocationReflection *const r) const \
79{ \
80 const AtomicComparator::Operator op = AtomicComparator::Operator(opIn); \
81 /* Note the extra paranteses around validOps. */ \
82 if (((validOps) & op) == op) \
83 return AtomicTypeVisitorResult::Ptr(new OperandSwitcherMathematician( \
84 AtomicMathematician::Ptr(new mather(r)))); \
85 else \
86 return AtomicTypeVisitorResult::Ptr(); \
87}
88
89static const AtomicMathematician::Operators AllMathOperators(AtomicMathematician::Add |
90 AtomicMathematician::Div |
91 AtomicMathematician::IDiv |
92 AtomicMathematician::Mod |
93 AtomicMathematician::Multiply |
94 AtomicMathematician::Substract);
95
96static const AtomicMathematician::Operators DivMultiply(AtomicMathematician::Multiply |
97 AtomicMathematician::Div);
98
99static const AtomicMathematician::Operators DurationOps(AtomicMathematician::Div |
100 AtomicMathematician::Substract |
101 AtomicMathematician::Add);
102
103static const AtomicMathematician::Operators DTOps(AtomicMathematician::Substract |
104 AtomicMathematician::Add);
105
106implReportingMathVisit(Double, DecimalType, DoubleMathematician, AllMathOperators)
107implReportingMathVisit(Double, DoubleType, DoubleMathematician, AllMathOperators)
108implReportingMathVisit(Double, FloatType, DoubleMathematician, AllMathOperators)
109implReportingMathVisit(Double, IntegerType, DoubleMathematician, AllMathOperators)
110implRevReportingMathVisit(Double, YearMonthDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
111implRevReportingMathVisit(Double, DayTimeDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
112
113implReportingMathVisit(Float, DecimalType, FloatMathematician, AllMathOperators)
114implReportingMathVisit(Float, DoubleType, DoubleMathematician, AllMathOperators)
115implReportingMathVisit(Float, FloatType, FloatMathematician, AllMathOperators)
116implReportingMathVisit(Float, IntegerType, FloatMathematician, AllMathOperators)
117implRevReportingMathVisit(Float, YearMonthDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
118implRevReportingMathVisit(Float, DayTimeDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
119
120implReportingMathVisit(Decimal, DecimalType, DecimalMathematician, AllMathOperators)
121implReportingMathVisit(Decimal, DoubleType, DoubleMathematician, AllMathOperators)
122implReportingMathVisit(Decimal, FloatType, FloatMathematician, AllMathOperators)
123implReportingMathVisit(Decimal, IntegerType, DecimalMathematician, AllMathOperators)
124implRevReportingMathVisit(Decimal, YearMonthDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
125implRevReportingMathVisit(Decimal, DayTimeDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
126
127implReportingMathVisit(Integer, DecimalType, DecimalMathematician, AllMathOperators)
128implReportingMathVisit(Integer, DoubleType, DoubleMathematician, AllMathOperators)
129implReportingMathVisit(Integer, FloatType, FloatMathematician, AllMathOperators)
130implReportingMathVisit(Integer, IntegerType, IntegerMathematician, AllMathOperators)
131implRevReportingMathVisit(Integer, YearMonthDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
132implRevReportingMathVisit(Integer, DayTimeDurationType, DurationNumericMathematician, AtomicMathematician::Multiply)
133
134implRevReportingMathVisit(DayTimeDuration, DateTimeType, DateTimeDurationMathematician, AtomicMathematician::Add)
135implRevReportingMathVisit(DayTimeDuration, DateType, DateTimeDurationMathematician, AtomicMathematician::Add)
136implMathVisit(DayTimeDuration, DayTimeDurationType, DurationDurationMathematician, DurationOps)
137implReportingMathVisit(DayTimeDuration, DecimalType, DurationNumericMathematician, DivMultiply)
138implReportingMathVisit(DayTimeDuration, DoubleType, DurationNumericMathematician, DivMultiply)
139implReportingMathVisit(DayTimeDuration, FloatType, DurationNumericMathematician, DivMultiply)
140implReportingMathVisit(DayTimeDuration, IntegerType, DurationNumericMathematician, DivMultiply)
141implRevReportingMathVisit(DayTimeDuration, SchemaTimeType, DateTimeDurationMathematician, AtomicMathematician::Add)
142
143implRevReportingMathVisit(YearMonthDuration, DateTimeType, DateTimeDurationMathematician, AtomicMathematician::Add)
144implRevReportingMathVisit(YearMonthDuration, DateType, DateTimeDurationMathematician, AtomicMathematician::Add)
145implReportingMathVisit(YearMonthDuration, DecimalType, DurationNumericMathematician, DivMultiply)
146implReportingMathVisit(YearMonthDuration, DoubleType, DurationNumericMathematician, DivMultiply)
147implReportingMathVisit(YearMonthDuration, FloatType, DurationNumericMathematician, DivMultiply)
148implReportingMathVisit(YearMonthDuration, IntegerType, DurationNumericMathematician, DivMultiply)
149implMathVisit(YearMonthDuration, YearMonthDurationType, DurationDurationMathematician, DurationOps)
150
151implMathVisit(Date, DateType, AbstractDateTimeMathematician,
152 AtomicMathematician::Substract)
153implReportingMathVisit(Date, YearMonthDurationType, DateTimeDurationMathematician, DTOps)
154implReportingMathVisit(Date, DayTimeDurationType, DateTimeDurationMathematician, DTOps)
155
156implMathVisit(SchemaTime, SchemaTimeType, AbstractDateTimeMathematician,
157 AtomicMathematician::Substract)
158implReportingMathVisit(SchemaTime, DayTimeDurationType, DateTimeDurationMathematician, DTOps)
159
160implMathVisit(DateTime, DateTimeType, AbstractDateTimeMathematician,
161 AtomicMathematician::Substract)
162implReportingMathVisit(DateTime, YearMonthDurationType, DateTimeDurationMathematician, DTOps)
163implReportingMathVisit(DateTime, DayTimeDurationType, DateTimeDurationMathematician, DTOps)
164
165#undef implMathVisit
166#undef implReportingMathVisit
167#undef implRevReportingMathVisit
168
169QT_END_NAMESPACE
170

source code of qtxmlpatterns/src/xmlpatterns/type/qatomicmathematicianlocators.cpp