2018-06-27 00:18:53 +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_VARIABLE_H_
|
|
|
|
#define FORTRAN_EVALUATE_VARIABLE_H_
|
|
|
|
|
2018-07-07 00:12:33 +02:00
|
|
|
#include "common.h"
|
|
|
|
#include "expression-forward.h"
|
|
|
|
#include "../common/idioms.h"
|
|
|
|
#include "../common/indirection.h"
|
|
|
|
#include "../semantics/symbol.h"
|
2018-06-27 00:18:53 +02:00
|
|
|
#include <optional>
|
2018-07-07 00:12:33 +02:00
|
|
|
#include <ostream>
|
2018-06-27 00:18:53 +02:00
|
|
|
#include <variant>
|
2018-07-04 00:14:48 +02:00
|
|
|
#include <vector>
|
2018-06-27 00:18:53 +02:00
|
|
|
|
|
|
|
namespace Fortran::evaluate {
|
|
|
|
|
2018-07-04 00:14:48 +02:00
|
|
|
struct DataRef;
|
|
|
|
struct Variable;
|
|
|
|
struct ActualArg;
|
2018-07-07 00:12:33 +02:00
|
|
|
struct Label;
|
2018-06-27 00:18:53 +02:00
|
|
|
|
2018-07-04 00:14:48 +02:00
|
|
|
using semantics::Symbol;
|
2018-06-27 00:18:53 +02:00
|
|
|
|
|
|
|
struct Component {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(Component)
|
|
|
|
Component(const DataRef &b, const Symbol &c) : base{b}, sym{&c} {}
|
|
|
|
Component(common::Indirection<DataRef> &&b, const Symbol &c)
|
|
|
|
: base{std::move(b)}, sym{&c} {}
|
|
|
|
common::Indirection<DataRef> base;
|
|
|
|
const Symbol *sym;
|
2018-06-27 00:18:53 +02:00
|
|
|
};
|
|
|
|
|
2018-07-07 00:12:33 +02:00
|
|
|
using SubscriptExpr = common::Indirection<DefaultIntegerExpr>;
|
2018-06-27 00:18:53 +02:00
|
|
|
|
|
|
|
struct Triplet {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(Triplet)
|
|
|
|
Triplet(std::optional<SubscriptExpr> &&, std::optional<SubscriptExpr> &&,
|
|
|
|
std::optional<SubscriptExpr> &&);
|
2018-07-04 00:14:48 +02:00
|
|
|
std::optional<SubscriptExpr> lower, upper, stride;
|
2018-06-27 00:18:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Subscript {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(Subscript)
|
|
|
|
explicit Subscript(const SubscriptExpr &s) : u{s} {}
|
2018-07-04 00:14:48 +02:00
|
|
|
explicit Subscript(SubscriptExpr &&s) : u{std::move(s)} {}
|
2018-07-07 00:12:33 +02:00
|
|
|
explicit Subscript(const Triplet &t) : u{t} {}
|
2018-07-04 00:14:48 +02:00
|
|
|
explicit Subscript(Triplet &&t) : u{std::move(t)} {}
|
|
|
|
std::variant<SubscriptExpr, Triplet> u;
|
2018-06-27 00:18:53 +02:00
|
|
|
};
|
|
|
|
|
2018-07-04 00:14:48 +02:00
|
|
|
struct ArrayRef {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(ArrayRef)
|
|
|
|
ArrayRef(const Symbol &n, std::vector<Subscript> &&ss)
|
|
|
|
: u{&n}, subscript(std::move(ss)) {}
|
|
|
|
ArrayRef(Component &&c, std::vector<Subscript> &&ss)
|
|
|
|
: u{std::move(c)}, subscript(std::move(ss)) {}
|
|
|
|
std::variant<const Symbol *, Component> u;
|
2018-07-04 00:14:48 +02:00
|
|
|
std::vector<Subscript> subscript;
|
2018-06-27 00:18:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CoarrayRef {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(CoarrayRef)
|
2018-07-04 00:14:48 +02:00
|
|
|
CoarrayRef(const Symbol &n, std::vector<SubscriptExpr> &&s)
|
2018-07-07 00:12:33 +02:00
|
|
|
: u{&n}, cosubscript(std::move(s)) {}
|
2018-07-04 00:14:48 +02:00
|
|
|
CoarrayRef(Component &&c, std::vector<SubscriptExpr> &&s)
|
2018-07-07 00:12:33 +02:00
|
|
|
: u{std::move(c)}, cosubscript(std::move(s)) {}
|
2018-07-04 00:14:48 +02:00
|
|
|
CoarrayRef(ArrayRef &&a, std::vector<SubscriptExpr> &&s)
|
2018-07-07 00:12:33 +02:00
|
|
|
: u{std::move(a)}, cosubscript(std::move(s)) {}
|
|
|
|
std::variant<const Symbol *, Component, ArrayRef> u;
|
2018-07-04 00:14:48 +02:00
|
|
|
std::vector<SubscriptExpr> cosubscript;
|
2018-07-07 00:12:33 +02:00
|
|
|
std::optional<common::Indirection<Variable>> stat, team, teamNumber;
|
2018-07-04 00:14:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DataRef {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(DataRef)
|
|
|
|
explicit DataRef(const Symbol &n) : u{&n} {}
|
2018-07-04 00:14:48 +02:00
|
|
|
explicit DataRef(Component &&c) : u{std::move(c)} {}
|
|
|
|
explicit DataRef(ArrayRef &&a) : u{std::move(a)} {}
|
|
|
|
explicit DataRef(CoarrayRef &&c) : u{std::move(c)} {}
|
2018-07-07 00:12:33 +02:00
|
|
|
std::variant<const Symbol *, Component, ArrayRef, CoarrayRef> u;
|
2018-07-04 00:14:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Substring {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(Substring)
|
2018-07-04 00:14:48 +02:00
|
|
|
Substring(DataRef &&d, std::optional<SubscriptExpr> &&f,
|
|
|
|
std::optional<SubscriptExpr> &&l)
|
|
|
|
: u{std::move(d)}, first{std::move(f)}, last{std::move(l)} {}
|
|
|
|
Substring(std::string &&s, std::optional<SubscriptExpr> &&f,
|
|
|
|
std::optional<SubscriptExpr> &&l)
|
|
|
|
: u{std::move(s)}, first{std::move(f)}, last{std::move(l)} {}
|
|
|
|
std::variant<DataRef, std::string> u;
|
|
|
|
std::optional<SubscriptExpr> first, last;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ComplexPart {
|
2018-07-07 00:12:33 +02:00
|
|
|
ENUM_CLASS(Part, RE, IM)
|
|
|
|
CLASS_BOILERPLATE(ComplexPart)
|
2018-07-04 00:14:48 +02:00
|
|
|
ComplexPart(DataRef &&z, Part p) : complex{std::move(z)}, part{p} {}
|
|
|
|
DataRef complex;
|
|
|
|
Part part;
|
2018-06-27 00:18:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Designator {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(Designator)
|
2018-07-04 00:14:48 +02:00
|
|
|
explicit Designator(DataRef &&d) : u{std::move(d)} {}
|
|
|
|
explicit Designator(Substring &&s) : u{std::move(s)} {}
|
|
|
|
explicit Designator(ComplexPart &&c) : u{std::move(c)} {}
|
|
|
|
std::variant<DataRef, Substring, ComplexPart> u;
|
2018-06-27 00:18:53 +02:00
|
|
|
};
|
|
|
|
|
2018-07-04 00:14:48 +02:00
|
|
|
struct ProcedureDesignator {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(ProcedureDesignator)
|
|
|
|
explicit ProcedureDesignator(const Symbol &n) : u{&n} {}
|
|
|
|
explicit ProcedureDesignator(const Component &c) : u{c} {}
|
|
|
|
explicit ProcedureDesignator(Component &&c) : u{std::move(c)} {}
|
|
|
|
std::variant<const Symbol *, Component> u;
|
2018-07-04 00:14:48 +02:00
|
|
|
};
|
|
|
|
|
2018-07-07 00:12:33 +02:00
|
|
|
struct ProcedureRef { // TODO split off FunctionRef without alt returns
|
|
|
|
CLASS_BOILERPLATE(ProcedureRef)
|
2018-07-04 00:14:48 +02:00
|
|
|
ProcedureRef(
|
2018-07-07 00:12:33 +02:00
|
|
|
ProcedureDesignator &&p, std::vector<common::Indirection<ActualArg>> &&a)
|
|
|
|
: proc{std::move(p)}, argument(std::move(a)) {}
|
2018-07-04 00:14:48 +02:00
|
|
|
ProcedureDesignator proc;
|
2018-07-07 00:12:33 +02:00
|
|
|
std::vector<common::Indirection<ActualArg>> argument;
|
2018-06-27 00:18:53 +02:00
|
|
|
};
|
|
|
|
|
2018-07-04 00:14:48 +02:00
|
|
|
struct Variable {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(Variable)
|
|
|
|
explicit Variable(Designator &&d) : u{std::move(d)} {}
|
2018-07-04 00:14:48 +02:00
|
|
|
explicit Variable(ProcedureRef &&p) : u{std::move(p)} {}
|
|
|
|
std::variant<Designator, ProcedureRef> u;
|
|
|
|
};
|
|
|
|
|
2018-07-07 00:12:33 +02:00
|
|
|
struct Label { // TODO: this is a placeholder
|
|
|
|
CLASS_BOILERPLATE(Label)
|
|
|
|
explicit Label(int lab) : label{lab} {}
|
|
|
|
int label;
|
|
|
|
};
|
|
|
|
|
2018-07-04 00:14:48 +02:00
|
|
|
struct ActualArg {
|
2018-07-07 00:12:33 +02:00
|
|
|
CLASS_BOILERPLATE(ActualArg)
|
|
|
|
explicit ActualArg(GenericExpr &&x) : u{std::move(x)} {}
|
2018-07-04 00:14:48 +02:00
|
|
|
explicit ActualArg(Variable &&x) : u{std::move(x)} {}
|
2018-07-07 00:12:33 +02:00
|
|
|
explicit ActualArg(const Label &l) : u{&l} {}
|
|
|
|
std::variant<common::Indirection<GenericExpr>, Variable, const Label *> u;
|
2018-07-04 00:14:48 +02:00
|
|
|
};
|
2018-06-27 00:18:53 +02:00
|
|
|
} // namespace Fortran::evaluate
|
2018-07-07 00:12:33 +02:00
|
|
|
|
|
|
|
// This inclusion must follow the definitions in this header due to
|
|
|
|
// mutual references.
|
|
|
|
#include "expression.h"
|
|
|
|
|
2018-06-27 00:18:53 +02:00
|
|
|
#endif // FORTRAN_EVALUATE_VARIABLE_H_
|