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 
44 QT_BEGIN_NAMESPACE
45 
46 using namespace QPatternist;
47 
48 #define implMathVisit(ownerClass, visitor, mather, validOps)                            \
49 AtomicTypeVisitorResult::Ptr                                                            \
50 ownerClass##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)                   \
63 AtomicTypeVisitorResult::Ptr                                                            \
64 ownerClass##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)                \
76 AtomicTypeVisitorResult::Ptr                                                            \
77 ownerClass##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 
89 static const AtomicMathematician::Operators AllMathOperators(AtomicMathematician::Add       |
90                                                              AtomicMathematician::Div       |
91                                                              AtomicMathematician::IDiv      |
92                                                              AtomicMathematician::Mod       |
93                                                              AtomicMathematician::Multiply  |
94                                                              AtomicMathematician::Substract);
95 
96 static const AtomicMathematician::Operators DivMultiply(AtomicMathematician::Multiply       |
97                                                         AtomicMathematician::Div);
98 
99 static const AtomicMathematician::Operators DurationOps(AtomicMathematician::Div            |
100                                                         AtomicMathematician::Substract      |
101                                                         AtomicMathematician::Add);
102 
103 static const AtomicMathematician::Operators DTOps(AtomicMathematician::Substract            |
104                                                   AtomicMathematician::Add);
105 
106 implReportingMathVisit(Double,           DecimalType,            DoubleMathematician,    AllMathOperators)
107 implReportingMathVisit(Double,           DoubleType,             DoubleMathematician,    AllMathOperators)
108 implReportingMathVisit(Double,           FloatType,              DoubleMathematician,    AllMathOperators)
109 implReportingMathVisit(Double,           IntegerType,            DoubleMathematician,    AllMathOperators)
110 implRevReportingMathVisit(Double,           YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
111 implRevReportingMathVisit(Double,           DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
112 
113 implReportingMathVisit(Float,            DecimalType,            FloatMathematician,     AllMathOperators)
114 implReportingMathVisit(Float,            DoubleType,    DoubleMathematician,    AllMathOperators)
115 implReportingMathVisit(Float,            FloatType,              FloatMathematician,     AllMathOperators)
116 implReportingMathVisit(Float,            IntegerType,            FloatMathematician,     AllMathOperators)
117 implRevReportingMathVisit(Float,            YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
118 implRevReportingMathVisit(Float,            DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
119 
120 implReportingMathVisit(Decimal, DecimalType,            DecimalMathematician,   AllMathOperators)
121 implReportingMathVisit(Decimal,          DoubleType,    DoubleMathematician,    AllMathOperators)
122 implReportingMathVisit(Decimal,          FloatType,              FloatMathematician,     AllMathOperators)
123 implReportingMathVisit(Decimal, IntegerType,            DecimalMathematician,   AllMathOperators)
124 implRevReportingMathVisit(Decimal,          YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
125 implRevReportingMathVisit(Decimal,          DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
126 
127 implReportingMathVisit(Integer, DecimalType,            DecimalMathematician,   AllMathOperators)
128 implReportingMathVisit(Integer,          DoubleType,    DoubleMathematician,    AllMathOperators)
129 implReportingMathVisit(Integer,          FloatType,              FloatMathematician,     AllMathOperators)
130 implReportingMathVisit(Integer, IntegerType,            IntegerMathematician,   AllMathOperators)
131 implRevReportingMathVisit(Integer,          YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
132 implRevReportingMathVisit(Integer,          DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
133 
134 implRevReportingMathVisit(DayTimeDuration,  DateTimeType,           DateTimeDurationMathematician,       AtomicMathematician::Add)
135 implRevReportingMathVisit(DayTimeDuration,  DateType,               DateTimeDurationMathematician,       AtomicMathematician::Add)
136 implMathVisit(DayTimeDuration,  DayTimeDurationType,    DurationDurationMathematician, DurationOps)
137 implReportingMathVisit(DayTimeDuration,  DecimalType,   DurationNumericMathematician,  DivMultiply)
138 implReportingMathVisit(DayTimeDuration,  DoubleType,    DurationNumericMathematician,  DivMultiply)
139 implReportingMathVisit(DayTimeDuration,  FloatType,     DurationNumericMathematician,  DivMultiply)
140 implReportingMathVisit(DayTimeDuration,  IntegerType,   DurationNumericMathematician,  DivMultiply)
141 implRevReportingMathVisit(DayTimeDuration,  SchemaTimeType,               DateTimeDurationMathematician,       AtomicMathematician::Add)
142 
143 implRevReportingMathVisit(YearMonthDuration, DateTimeType,          DateTimeDurationMathematician,       AtomicMathematician::Add)
144 implRevReportingMathVisit(YearMonthDuration, DateType,              DateTimeDurationMathematician,       AtomicMathematician::Add)
145 implReportingMathVisit(YearMonthDuration, DecimalType,  DurationNumericMathematician,  DivMultiply)
146 implReportingMathVisit(YearMonthDuration, DoubleType,   DurationNumericMathematician,  DivMultiply)
147 implReportingMathVisit(YearMonthDuration, FloatType,    DurationNumericMathematician,  DivMultiply)
148 implReportingMathVisit(YearMonthDuration, IntegerType,  DurationNumericMathematician,  DivMultiply)
149 implMathVisit(YearMonthDuration, YearMonthDurationType, DurationDurationMathematician, DurationOps)
150 
151 implMathVisit(Date,              DateType,              AbstractDateTimeMathematician,
152               AtomicMathematician::Substract)
153 implReportingMathVisit(Date,     YearMonthDurationType, DateTimeDurationMathematician,       DTOps)
154 implReportingMathVisit(Date,     DayTimeDurationType,   DateTimeDurationMathematician,       DTOps)
155 
156 implMathVisit(SchemaTime,              SchemaTimeType,              AbstractDateTimeMathematician,
157               AtomicMathematician::Substract)
158 implReportingMathVisit(SchemaTime,     DayTimeDurationType,   DateTimeDurationMathematician,       DTOps)
159 
160 implMathVisit(DateTime,          DateTimeType,          AbstractDateTimeMathematician,
161               AtomicMathematician::Substract)
162 implReportingMathVisit(DateTime, YearMonthDurationType, DateTimeDurationMathematician,       DTOps)
163 implReportingMathVisit(DateTime, DayTimeDurationType,   DateTimeDurationMathematician,       DTOps)
164 
165 #undef implMathVisit
166 #undef implReportingMathVisit
167 #undef implRevReportingMathVisit
168 
169 QT_END_NAMESPACE
170