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