forked from OSchip/llvm-project
[flang] Eliminate DefaultInteger
Original-commit: flang-compiler/f18@1760b9ccc5 Reviewed-on: https://github.com/flang-compiler/f18/pull/213 Tree-same-pre-rewrite: false
This commit is contained in:
parent
d2f36b9d76
commit
76effcc5fb
|
@ -669,6 +669,46 @@ struct GenericExprWrapper {
|
|||
Expr<SomeType> v;
|
||||
};
|
||||
|
||||
// When an Expr holds something that is a Variable (i.e., a Designator
|
||||
// or pointer-valued FunctionRef), return a copy of its contents in
|
||||
// a Variable.
|
||||
template<typename A>
|
||||
std::optional<Variable<A>> AsVariable(const Expr<A> &expr) {
|
||||
using Variant = decltype(Variable<A>::u);
|
||||
return std::visit(
|
||||
[](const auto &x) -> std::optional<Variable<A>> {
|
||||
if constexpr (common::HasMember<std::decay_t<decltype(x)>, Variant>) {
|
||||
return std::make_optional<Variable<A>>(x);
|
||||
}
|
||||
return std::nullopt;
|
||||
},
|
||||
expr.u);
|
||||
}
|
||||
|
||||
// Predicate: true when an expression is a variable reference
|
||||
template<typename A> bool IsVariable(const Expr<A> &expr) {
|
||||
return AsVariable(expr).has_value();
|
||||
}
|
||||
|
||||
template<TypeCategory CATEGORY>
|
||||
bool IsVariable(const Expr<SomeKind<CATEGORY>> &expr) {
|
||||
return std::visit([](const auto &x) { return IsVariable(x); }, expr.u);
|
||||
}
|
||||
|
||||
template<> inline bool IsVariable(const Expr<SomeDerived> &) { return true; }
|
||||
|
||||
template<> inline bool IsVariable(const Expr<SomeType> &expr) {
|
||||
return std::visit(
|
||||
[](const auto &x) {
|
||||
if constexpr (!std::is_same_v<BOZLiteralConstant,
|
||||
std::decay_t<decltype(x)>>) {
|
||||
return IsVariable(x);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
expr.u);
|
||||
}
|
||||
|
||||
FOR_EACH_CATEGORY_TYPE(extern template class Expr)
|
||||
FOR_EACH_TYPE_AND_KIND(extern template struct ExpressionBase)
|
||||
|
||||
|
|
|
@ -164,9 +164,6 @@ template<typename T> using Scalar = typename std::decay_t<T>::Scalar;
|
|||
template<TypeCategory CATEGORY, typename T>
|
||||
using SameKind = Type<CATEGORY, std::decay_t<T>::kind>;
|
||||
|
||||
// TODO: Eliminate this type!
|
||||
using DefaultInteger = Type<TypeCategory::Integer, 4>;
|
||||
|
||||
using SubscriptInteger = Type<TypeCategory::Integer, 8>;
|
||||
using LogicalResult = Type<TypeCategory::Logical, 1>;
|
||||
using LargestReal = Type<TypeCategory::Real, 16>;
|
||||
|
|
|
@ -70,14 +70,15 @@ CoarrayRef::CoarrayRef(std::vector<const Symbol *> &&c,
|
|||
CHECK(!base_.empty());
|
||||
}
|
||||
|
||||
CoarrayRef &CoarrayRef::set_stat(Variable<DefaultInteger> &&v) {
|
||||
stat_ = CopyableIndirection<Variable<DefaultInteger>>::Make(std::move(v));
|
||||
CoarrayRef &CoarrayRef::set_stat(Expr<SomeInteger> &&v) {
|
||||
CHECK(IsVariable(v));
|
||||
stat_ = CopyableIndirection<Expr<SomeInteger>>::Make(std::move(v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
CoarrayRef &CoarrayRef::set_team(
|
||||
Variable<DefaultInteger> &&v, bool isTeamNumber) {
|
||||
team_ = CopyableIndirection<Variable<DefaultInteger>>::Make(std::move(v));
|
||||
CoarrayRef &CoarrayRef::set_team(Expr<SomeInteger> &&v, bool isTeamNumber) {
|
||||
CHECK(IsVariable(v));
|
||||
team_ = CopyableIndirection<Expr<SomeInteger>>::Make(std::move(v));
|
||||
teamIsTeamNumber_ = isTeamNumber;
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -132,9 +132,11 @@ public:
|
|||
CLASS_BOILERPLATE(CoarrayRef)
|
||||
CoarrayRef(std::vector<const Symbol *> &&,
|
||||
std::vector<Expr<SubscriptInteger>> &&,
|
||||
std::vector<Expr<SubscriptInteger>> &&); // TODO: stat & team?
|
||||
CoarrayRef &set_stat(Variable<DefaultInteger> &&);
|
||||
CoarrayRef &set_team(Variable<DefaultInteger> &&, bool isTeamNumber = false);
|
||||
std::vector<Expr<SubscriptInteger>> &&);
|
||||
// These integral expressions for STAT= and TEAM= must be variables
|
||||
// (i.e., Designator or pointer-valued FunctionRef).
|
||||
CoarrayRef &set_stat(Expr<SomeInteger> &&);
|
||||
CoarrayRef &set_team(Expr<SomeInteger> &&, bool isTeamNumber = false);
|
||||
|
||||
int Rank() const;
|
||||
const Symbol *GetSymbol(bool first) const {
|
||||
|
@ -150,7 +152,7 @@ public:
|
|||
private:
|
||||
std::vector<const Symbol *> base_;
|
||||
std::vector<Expr<SubscriptInteger>> subscript_, cosubscript_;
|
||||
std::optional<CopyableIndirection<Variable<DefaultInteger>>> stat_, team_;
|
||||
std::optional<CopyableIndirection<Expr<SomeInteger>>> stat_, team_;
|
||||
bool teamIsTeamNumber_{false}; // false: TEAM=, true: TEAM_NUMBER=
|
||||
};
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "../../lib/evaluate/expression.h"
|
||||
#include "../../lib/evaluate/tools.h"
|
||||
#include "testing.h"
|
||||
#include "../../lib/evaluate/tools.h"
|
||||
#include "../../lib/parser/message.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
@ -30,7 +30,7 @@ template<typename A> std::string Dump(const A &x) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
using DefaultIntegerExpr = Expr<DefaultInteger>;
|
||||
using DefaultIntegerExpr = Expr<Type<TypeCategory::Integer, 4>>;
|
||||
TEST(DefaultIntegerExpr::Result::Dump() == "Integer(4)");
|
||||
MATCH("666_4", Dump(DefaultIntegerExpr{666}));
|
||||
MATCH("(-1_4)", Dump(-DefaultIntegerExpr{1}));
|
||||
|
|
Loading…
Reference in New Issue