2018-06-18 21:09:56 +02:00
|
|
|
// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef FORTRAN_EVALUATE_EXPRESSION_H_
|
|
|
|
#define FORTRAN_EVALUATE_EXPRESSION_H_
|
|
|
|
|
2018-06-19 23:16:01 +02:00
|
|
|
#include "common.h"
|
2018-06-18 21:09:56 +02:00
|
|
|
#include "type.h"
|
2018-06-21 20:03:00 +02:00
|
|
|
#include <memory>
|
2018-06-20 20:55:10 +02:00
|
|
|
#include <ostream>
|
2018-06-18 21:09:56 +02:00
|
|
|
#include <variant>
|
|
|
|
|
|
|
|
namespace Fortran::evaluate {
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
// Some forward definitions
|
|
|
|
template<int KIND> struct IntegerExpr;
|
|
|
|
template<int KIND> struct RealExpr;
|
|
|
|
template<int KIND> struct ComplexExpr;
|
|
|
|
template<int KIND> struct CharacterExpr;
|
|
|
|
struct AnyIntegerExpr;
|
|
|
|
struct AnyRealExpr;
|
|
|
|
struct AnyComplexExpr;
|
|
|
|
struct AnyCharacterExpr;
|
|
|
|
struct AnyIntegerOrRealExpr;
|
|
|
|
|
|
|
|
template<int KIND> struct IntegerExpr {
|
|
|
|
using Result = Type<Category::Integer, KIND>;
|
|
|
|
using Operand = std::unique_ptr<IntegerExpr>;
|
2018-06-19 23:16:01 +02:00
|
|
|
using Constant = typename Result::Value;
|
|
|
|
struct Convert {
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<AnyIntegerOrRealExpr> x;
|
2018-06-19 23:16:01 +02:00
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct Unary {
|
2018-06-20 19:53:49 +02:00
|
|
|
Operand x;
|
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct Parentheses : public Unary {};
|
|
|
|
struct Negate : public Unary {};
|
|
|
|
struct Binary {
|
2018-06-20 19:53:49 +02:00
|
|
|
Operand x, y;
|
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct Add : public Binary {};
|
|
|
|
struct Subtract : public Binary {};
|
|
|
|
struct Multiply : public Binary {};
|
|
|
|
struct Divide : public Binary {};
|
|
|
|
struct Power : public Binary {};
|
2018-06-18 21:09:56 +02:00
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
IntegerExpr() = delete;
|
|
|
|
IntegerExpr(IntegerExpr &&) = default;
|
|
|
|
IntegerExpr(const Constant &x) : u{x} {}
|
|
|
|
IntegerExpr(std::int64_t n) : u{Constant{n}} {}
|
|
|
|
IntegerExpr(int n) : u{Constant{n}} {}
|
|
|
|
template<typename A> IntegerExpr(A &&x) : u{std::move(x)} {}
|
2018-06-21 21:47:28 +02:00
|
|
|
|
2018-06-21 01:50:27 +02:00
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-21 21:47:28 +02:00
|
|
|
|
2018-06-20 19:53:49 +02:00
|
|
|
std::variant<Constant, Convert, Parentheses, Negate, Add, Subtract, Multiply,
|
|
|
|
Divide, Power>
|
|
|
|
u;
|
2018-06-19 23:16:01 +02:00
|
|
|
};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
using DefaultIntegerExpr = IntegerExpr<DefaultInteger::kind>;
|
|
|
|
|
|
|
|
template<int KIND> struct RealExpr {
|
|
|
|
using Result = Type<Category::Real, KIND>;
|
|
|
|
using Operand = std::unique_ptr<RealExpr>;
|
2018-06-21 20:03:00 +02:00
|
|
|
using Constant = typename Result::Value;
|
|
|
|
struct Convert {
|
|
|
|
// N.B. Real->Complex and Complex->Real conversions are done with CMPLX
|
|
|
|
// and part access operations (resp.). Conversions between kinds of
|
|
|
|
// Complex are done via decomposition to Real and reconstruction.
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<AnyIntegerOrRealExpr> x;
|
2018-06-21 20:03:00 +02:00
|
|
|
};
|
|
|
|
struct Unary {
|
|
|
|
Operand x;
|
|
|
|
};
|
|
|
|
struct Parentheses : public Unary {};
|
|
|
|
struct Negate : public Unary {};
|
|
|
|
struct Binary {
|
|
|
|
Operand x, y;
|
|
|
|
};
|
|
|
|
struct Add : public Binary {};
|
|
|
|
struct Subtract : public Binary {};
|
|
|
|
struct Multiply : public Binary {};
|
|
|
|
struct Divide : public Binary {};
|
|
|
|
struct Power : public Binary {};
|
2018-06-21 21:47:28 +02:00
|
|
|
struct IntPower {
|
2018-06-21 20:03:00 +02:00
|
|
|
Operand x;
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<AnyIntegerExpr> y;
|
2018-06-19 23:16:01 +02:00
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct FromComplex {
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<ComplexExpr<KIND>> z;
|
2018-06-20 19:53:49 +02:00
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct RealPart : public FromComplex {};
|
|
|
|
struct AIMAG : public FromComplex {};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
RealExpr() = delete;
|
|
|
|
RealExpr(RealExpr &&) = default;
|
|
|
|
RealExpr(const Constant &x) : u{x} {}
|
|
|
|
template<typename A> RealExpr(A &&x) : u{std::move(x)} {}
|
2018-06-21 21:47:28 +02:00
|
|
|
|
2018-06-21 01:50:27 +02:00
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-21 21:47:28 +02:00
|
|
|
|
2018-06-20 19:53:49 +02:00
|
|
|
std::variant<Constant, Convert, Parentheses, Negate, Add, Subtract, Multiply,
|
2018-06-21 21:47:28 +02:00
|
|
|
Divide, Power, IntPower, RealPart, AIMAG>
|
2018-06-20 19:53:49 +02:00
|
|
|
u;
|
2018-06-19 23:16:01 +02:00
|
|
|
};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
template<int KIND> struct ComplexExpr {
|
|
|
|
using Result = Type<Category::Complex, KIND>;
|
|
|
|
using Operand = std::unique_ptr<ComplexExpr>;
|
2018-06-21 20:03:00 +02:00
|
|
|
using Constant = typename Result::Value;
|
|
|
|
struct Unary {
|
|
|
|
Operand x;
|
|
|
|
};
|
|
|
|
struct Parentheses : public Unary {};
|
|
|
|
struct Negate : public Unary {};
|
|
|
|
struct Binary {
|
|
|
|
Operand x, y;
|
|
|
|
};
|
|
|
|
struct Add : public Binary {};
|
|
|
|
struct Subtract : public Binary {};
|
|
|
|
struct Multiply : public Binary {};
|
|
|
|
struct Divide : public Binary {};
|
|
|
|
struct Power : public Binary {};
|
2018-06-21 21:47:28 +02:00
|
|
|
struct IntPower {
|
2018-06-21 20:03:00 +02:00
|
|
|
Operand x;
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<AnyIntegerExpr> y;
|
2018-06-21 20:03:00 +02:00
|
|
|
};
|
2018-06-20 19:53:49 +02:00
|
|
|
struct CMPLX {
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<RealExpr<KIND>> re, im;
|
2018-06-20 19:53:49 +02:00
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
ComplexExpr() = delete;
|
|
|
|
ComplexExpr(ComplexExpr &&) = default;
|
|
|
|
ComplexExpr(const Constant &x) : u{x} {}
|
|
|
|
template<typename A> ComplexExpr(A &&x) : u{std::move(x)} {}
|
2018-06-21 21:47:28 +02:00
|
|
|
|
2018-06-21 01:50:27 +02:00
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-21 21:47:28 +02:00
|
|
|
|
2018-06-20 19:53:49 +02:00
|
|
|
std::variant<Constant, Parentheses, Negate, Add, Subtract, Multiply, Divide,
|
2018-06-21 21:47:28 +02:00
|
|
|
Power, IntPower, CMPLX>
|
2018-06-20 19:53:49 +02:00
|
|
|
u;
|
2018-06-19 23:16:01 +02:00
|
|
|
};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
template<int KIND> struct CharacterExpr {
|
|
|
|
using Result = Type<Category::Character, KIND>;
|
|
|
|
using Operand = std::unique_ptr<CharacterExpr>;
|
|
|
|
using Constant = typename Result::Value;
|
|
|
|
using Length = IntegerExpr<IntrinsicTypeParameterType::kind>;
|
|
|
|
struct Concat {
|
|
|
|
Operand x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
CharacterExpr() = delete;
|
|
|
|
CharacterExpr(CharacterExpr &&) = default;
|
|
|
|
CharacterExpr(const Constant &x) : u{x} {}
|
|
|
|
CharacterExpr(CharacterExpr &&a, CharacterExpr &&b)
|
|
|
|
: u{Concat{std::make_unique<CharacterExpr>(std::move(a)),
|
|
|
|
std::make_unique<CharacterExpr>(std::move(b))}} {}
|
|
|
|
|
|
|
|
Length LEN() const;
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
|
|
|
|
|
|
|
std::variant<Constant, Concat> u;
|
|
|
|
};
|
|
|
|
|
2018-06-21 21:47:28 +02:00
|
|
|
// The Comparison class template is a helper for constructing logical
|
|
|
|
// expressions with polymorphism over all of the possible categories and
|
|
|
|
// kinds of comparable operands.
|
2018-06-21 20:03:00 +02:00
|
|
|
template<typename T> struct Comparison {
|
|
|
|
struct Binary {
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<T> x, y;
|
2018-06-20 19:53:49 +02:00
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct LT : public Binary {};
|
|
|
|
struct LE : public Binary {};
|
|
|
|
struct EQ : public Binary {};
|
|
|
|
struct NE : public Binary {};
|
|
|
|
struct GE : public Binary {};
|
|
|
|
struct GT : public Binary {};
|
|
|
|
|
|
|
|
Comparison() = delete;
|
|
|
|
Comparison(Comparison &&) = default;
|
|
|
|
template<typename A> Comparison(A &&x) : u{std::move(x)} {}
|
|
|
|
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
|
|
|
|
|
|
|
std::variant<LT, LE, EQ, NE, GE, GT> u;
|
|
|
|
};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
// COMPLEX admits only .EQ. and .NE. comparisons.
|
|
|
|
template<int KIND> struct Comparison<ComplexExpr<KIND>> {
|
2018-06-21 20:03:00 +02:00
|
|
|
struct Binary {
|
2018-06-22 00:35:25 +02:00
|
|
|
std::unique_ptr<ComplexExpr<KIND>> x, y;
|
2018-06-20 19:53:49 +02:00
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct EQ : public Binary {};
|
|
|
|
struct NE : public Binary {};
|
2018-06-19 23:16:01 +02:00
|
|
|
|
2018-06-21 20:03:00 +02:00
|
|
|
Comparison() = delete;
|
|
|
|
Comparison(Comparison &&) = default;
|
|
|
|
template<typename A> Comparison(A &&x) : u{std::move(x)} {}
|
2018-06-19 23:16:01 +02:00
|
|
|
|
2018-06-21 20:03:00 +02:00
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-19 23:16:01 +02:00
|
|
|
|
2018-06-21 20:03:00 +02:00
|
|
|
std::variant<EQ, NE> u;
|
|
|
|
};
|
2018-06-20 01:26:48 +02:00
|
|
|
|
2018-06-21 20:03:00 +02:00
|
|
|
struct IntegerComparison {
|
2018-06-21 21:47:28 +02:00
|
|
|
IntegerComparison() = delete;
|
|
|
|
IntegerComparison(IntegerComparison &&) = default;
|
|
|
|
template<typename A> IntegerComparison(A &&x) : u{std::move(x)} {}
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-22 00:35:25 +02:00
|
|
|
template<int KIND> using C = Comparison<IntegerExpr<KIND>>;
|
2018-06-21 20:03:00 +02:00
|
|
|
IntegerKindsVariant<C> u;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RealComparison {
|
2018-06-21 21:47:28 +02:00
|
|
|
RealComparison() = delete;
|
|
|
|
RealComparison(RealComparison &&) = default;
|
|
|
|
template<typename A> RealComparison(A &&x) : u{std::move(x)} {}
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-22 00:35:25 +02:00
|
|
|
template<int KIND> using C = Comparison<RealExpr<KIND>>;
|
2018-06-21 20:03:00 +02:00
|
|
|
RealKindsVariant<C> u;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ComplexComparison {
|
2018-06-21 21:47:28 +02:00
|
|
|
ComplexComparison() = delete;
|
|
|
|
ComplexComparison(ComplexComparison &&) = default;
|
|
|
|
template<typename A> ComplexComparison(A &&x) : u{std::move(x)} {}
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-22 00:35:25 +02:00
|
|
|
template<int KIND> using C = Comparison<ComplexExpr<KIND>>;
|
|
|
|
ComplexKindsVariant<C> u;
|
2018-06-21 20:03:00 +02:00
|
|
|
};
|
2018-06-19 23:16:01 +02:00
|
|
|
|
2018-06-21 20:03:00 +02:00
|
|
|
struct CharacterComparison {
|
2018-06-21 21:47:28 +02:00
|
|
|
CharacterComparison() = delete;
|
|
|
|
CharacterComparison(CharacterComparison &&) = default;
|
|
|
|
template<typename A> CharacterComparison(A &&x) : u{std::move(x)} {}
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-22 00:35:25 +02:00
|
|
|
template<int KIND> using C = Comparison<CharacterExpr<KIND>>;
|
2018-06-21 20:03:00 +02:00
|
|
|
CharacterKindsVariant<C> u;
|
|
|
|
};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
// No need to distinguish the various kinds of LOGICAL expression results.
|
|
|
|
struct LogicalExpr {
|
|
|
|
using Operand = std::unique_ptr<LogicalExpr>;
|
2018-06-21 21:47:28 +02:00
|
|
|
using Constant = bool;
|
2018-06-21 20:03:00 +02:00
|
|
|
struct Not {
|
|
|
|
Operand x;
|
2018-06-20 19:53:49 +02:00
|
|
|
};
|
2018-06-21 20:03:00 +02:00
|
|
|
struct Binary {
|
|
|
|
Operand x, y;
|
|
|
|
};
|
|
|
|
struct And : public Binary {};
|
|
|
|
struct Or : public Binary {};
|
|
|
|
struct Eqv : public Binary {};
|
|
|
|
struct Neqv : public Binary {};
|
2018-06-20 19:53:49 +02:00
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
LogicalExpr() = delete;
|
|
|
|
LogicalExpr(LogicalExpr &&) = default;
|
|
|
|
LogicalExpr(const Constant &x) : u{x} {}
|
2018-06-20 19:53:49 +02:00
|
|
|
template<int KIND>
|
2018-06-22 00:35:25 +02:00
|
|
|
LogicalExpr(Comparison<IntegerExpr<KIND>> &&x)
|
2018-06-20 19:53:49 +02:00
|
|
|
: u{IntegerComparison{std::move(x)}} {}
|
|
|
|
template<int KIND>
|
2018-06-22 00:35:25 +02:00
|
|
|
LogicalExpr(Comparison<RealExpr<KIND>> &&x)
|
2018-06-20 19:53:49 +02:00
|
|
|
: u{RealComparison{std::move(x)}} {}
|
|
|
|
template<int KIND>
|
2018-06-22 00:35:25 +02:00
|
|
|
LogicalExpr(Comparison<ComplexExpr<KIND>> &&x)
|
2018-06-20 19:53:49 +02:00
|
|
|
: u{ComplexComparison{std::move(x)}} {}
|
|
|
|
template<int KIND>
|
2018-06-22 00:35:25 +02:00
|
|
|
LogicalExpr(Comparison<CharacterExpr<KIND>> &&x)
|
2018-06-20 19:53:49 +02:00
|
|
|
: u{CharacterComparison{std::move(x)}} {}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> LogicalExpr(A &&x) : u{std::move(x)} {}
|
2018-06-20 01:26:48 +02:00
|
|
|
|
2018-06-21 01:50:27 +02:00
|
|
|
std::ostream &Dump(std::ostream &) const;
|
|
|
|
|
2018-06-20 19:53:49 +02:00
|
|
|
std::variant<Constant, Not, And, Or, Eqv, Neqv, IntegerComparison,
|
|
|
|
RealComparison, ComplexComparison, CharacterComparison>
|
|
|
|
u;
|
2018-06-19 23:16:01 +02:00
|
|
|
};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
// Dynamically polymorphic expressions that can hold any supported kind.
|
|
|
|
struct AnyIntegerExpr {
|
|
|
|
AnyIntegerExpr() = delete;
|
|
|
|
AnyIntegerExpr(AnyIntegerExpr &&) = default;
|
|
|
|
template<int KIND> AnyIntegerExpr(IntegerExpr<KIND> &&x) : u{x} {}
|
2018-06-21 01:50:27 +02:00
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-22 00:35:25 +02:00
|
|
|
IntegerKindsVariant<IntegerExpr> u;
|
2018-06-20 19:53:49 +02:00
|
|
|
};
|
2018-06-22 00:35:25 +02:00
|
|
|
struct AnyRealExpr {
|
|
|
|
AnyRealExpr() = delete;
|
|
|
|
AnyRealExpr(AnyRealExpr &&) = default;
|
|
|
|
template<int KIND> AnyRealExpr(RealExpr<KIND> &&x) : u{x} {}
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-20 19:53:49 +02:00
|
|
|
RealKindsVariant<RealExpr> u;
|
|
|
|
};
|
2018-06-22 00:35:25 +02:00
|
|
|
struct AnyComplexExpr {
|
|
|
|
AnyComplexExpr() = delete;
|
|
|
|
AnyComplexExpr(AnyComplexExpr &&) = default;
|
|
|
|
template<int KIND> AnyComplexExpr(ComplexExpr<KIND> &&x) : u{x} {}
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-20 19:53:49 +02:00
|
|
|
ComplexKindsVariant<ComplexExpr> u;
|
|
|
|
};
|
2018-06-22 00:35:25 +02:00
|
|
|
struct AnyCharacterExpr {
|
|
|
|
AnyCharacterExpr() = delete;
|
|
|
|
AnyCharacterExpr(AnyCharacterExpr &&) = default;
|
|
|
|
template<int KIND> AnyCharacterExpr(CharacterExpr<KIND> &&x) : u{x} {}
|
|
|
|
std::ostream &Dump(std::ostream &) const;
|
|
|
|
CharacterKindsVariant<CharacterExpr> u;
|
2018-06-20 19:53:49 +02:00
|
|
|
};
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
struct AnyIntegerOrRealExpr {
|
|
|
|
AnyIntegerOrRealExpr() = delete;
|
|
|
|
AnyIntegerOrRealExpr(AnyIntegerOrRealExpr &&) = default;
|
2018-06-20 19:53:49 +02:00
|
|
|
template<int KIND>
|
2018-06-22 00:35:25 +02:00
|
|
|
AnyIntegerOrRealExpr(IntegerExpr<KIND> &&x)
|
|
|
|
: u{AnyIntegerExpr{std::move(x)}} {}
|
2018-06-20 19:53:49 +02:00
|
|
|
template<int KIND>
|
2018-06-22 00:35:25 +02:00
|
|
|
AnyIntegerOrRealExpr(RealExpr<KIND> &&x) : u{AnyRealExpr{std::move(x)}} {}
|
|
|
|
template<typename A> AnyIntegerOrRealExpr(A &&x) : u{std::move(x)} {}
|
2018-06-21 21:47:28 +02:00
|
|
|
std::ostream &Dump(std::ostream &) const;
|
2018-06-22 00:35:25 +02:00
|
|
|
std::variant<AnyIntegerExpr, AnyRealExpr> u;
|
2018-06-19 23:16:01 +02:00
|
|
|
};
|
2018-06-20 20:55:10 +02:00
|
|
|
|
2018-06-21 01:50:27 +02:00
|
|
|
// Convenience functions and operator overloadings for expression construction.
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> A Parentheses(A &&x) {
|
|
|
|
return {typename A::Parentheses{{std::make_unique<A>(std::move(x))}}};
|
2018-06-21 01:50:27 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> A operator-(A &&x) {
|
|
|
|
return {typename A::Negate{{std::make_unique<A>(std::move(x))}}};
|
2018-06-20 20:55:10 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> A operator+(A &&x, A &&y) {
|
|
|
|
return {typename A::Add{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-20 20:55:10 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> A operator-(A &&x, A &&y) {
|
|
|
|
return {typename A::Subtract{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-20 20:55:10 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> A operator*(A &&x, A &&y) {
|
|
|
|
return {typename A::Multiply{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-20 20:55:10 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> A operator/(A &&x, A &&y) {
|
|
|
|
return {typename A::Divide{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-20 20:55:10 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> A Power(A &&x, A &&y) {
|
|
|
|
return {typename A::Power{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-21 01:50:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> Comparison<A> operator<(A &&x, A &&y) {
|
|
|
|
return {typename Comparison<A>::LT{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-21 20:03:00 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> Comparison<A> operator<=(A &&x, A &&y) {
|
|
|
|
return {typename Comparison<A>::LE{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-21 20:03:00 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> Comparison<A> operator==(A &&x, A &&y) {
|
|
|
|
return {typename Comparison<A>::EQ{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-21 20:03:00 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> Comparison<A> operator!=(A &&x, A &&y) {
|
|
|
|
return {typename Comparison<A>::NE{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-21 20:03:00 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> Comparison<A> operator>=(A &&x, A &&y) {
|
|
|
|
return {typename Comparison<A>::GE{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-21 20:03:00 +02:00
|
|
|
}
|
2018-06-22 00:35:25 +02:00
|
|
|
template<typename A> Comparison<A> operator>(A &&x, A &&y) {
|
|
|
|
return {typename Comparison<A>::GT{
|
|
|
|
{std::make_unique<A>(std::move(x)), std::make_unique<A>(std::move(y))}}};
|
2018-06-21 20:03:00 +02:00
|
|
|
}
|
2018-06-20 20:55:10 +02:00
|
|
|
|
2018-06-21 20:03:00 +02:00
|
|
|
// External instantiations
|
2018-06-22 00:35:25 +02:00
|
|
|
extern template struct IntegerExpr<1>;
|
|
|
|
extern template struct IntegerExpr<2>;
|
|
|
|
extern template struct IntegerExpr<4>;
|
|
|
|
extern template struct IntegerExpr<8>;
|
|
|
|
extern template struct IntegerExpr<16>;
|
|
|
|
extern template struct RealExpr<2>;
|
|
|
|
extern template struct RealExpr<4>;
|
|
|
|
extern template struct RealExpr<8>;
|
|
|
|
extern template struct RealExpr<10>;
|
|
|
|
extern template struct RealExpr<16>;
|
|
|
|
extern template struct ComplexExpr<2>;
|
|
|
|
extern template struct ComplexExpr<4>;
|
|
|
|
extern template struct ComplexExpr<8>;
|
|
|
|
extern template struct ComplexExpr<10>;
|
|
|
|
extern template struct ComplexExpr<16>;
|
|
|
|
extern template struct CharacterExpr<1>;
|
2018-06-18 21:09:56 +02:00
|
|
|
} // namespace Fortran::evaluate
|
|
|
|
#endif // FORTRAN_EVALUATE_EXPRESSION_H_
|