[flang] Back some changes out

Original-commit: flang-compiler/f18@7f6345ac62
Reviewed-on: https://github.com/flang-compiler/f18/pull/873
This commit is contained in:
peter klausler 2019-12-17 12:32:16 -08:00
parent cd1d3881f1
commit cfe146bfde
8 changed files with 28 additions and 35 deletions

View file

@ -171,10 +171,6 @@ StructureConstructor &StructureConstructor::Add(
GenericExprWrapper::~GenericExprWrapper() {}
bool GenericExprWrapper::operator==(const GenericExprWrapper &that) const {
return v == that.v;
}
GenericAssignmentWrapper::~GenericAssignmentWrapper() {}
template<TypeCategory CAT> int Expr<SomeKind<CAT>>::GetKind() const {

View file

@ -872,19 +872,19 @@ public:
// This wrapper class is used, by means of a forward reference with
// an owning pointer, to cache analyzed expressions in parse tree nodes.
// v is nullopt if an error occurred during expression analysis.
struct GenericExprWrapper {
GenericExprWrapper(std::optional<Expr<SomeType>> &&x) : v{std::move(x)} {}
GenericExprWrapper() {}
explicit GenericExprWrapper(std::optional<Expr<SomeType>> &&x)
: v{std::move(x)} {}
~GenericExprWrapper();
bool operator==(const GenericExprWrapper &) const;
std::optional<Expr<SomeType>> v;
std::optional<Expr<SomeType>> v; // vacant if error
};
// Like GenericExprWrapper but for analyzed assignments
struct GenericAssignmentWrapper {
GenericAssignmentWrapper(std::optional<Assignment> &&x) : v{std::move(x)} {}
explicit GenericAssignmentWrapper(Assignment &&x) : v{std::move(x)} {}
~GenericAssignmentWrapper();
std::optional<Assignment> v;
Assignment v;
};
FOR_EACH_CATEGORY_TYPE(extern template class Expr, )

View file

@ -803,7 +803,7 @@ public:
// R1001 - R1022
bool Pre(const Expr &x) {
if (asFortran_ && x.typedExpr.get()) {
if (asFortran_ && x.typedExpr) {
// Format the expression representation from semantics
asFortran_->expr(out_, *x.typedExpr);
return false;

View file

@ -2260,7 +2260,7 @@ static void FixMisparsedFunctionReference(
// Common handling of parser::Expr and parser::Variable
template<typename PARSED>
MaybeExpr ExpressionAnalyzer::ExprOrVariable(const PARSED &x) {
if (!x.typedExpr) { // not yet analyzed
if (!x.typedExpr) {
FixMisparsedFunctionReference(context_, x.u);
MaybeExpr result;
if constexpr (std::is_same_v<PARSED, parser::Expr>) {

View file

@ -89,8 +89,10 @@ namespace Fortran::evaluate {
class IntrinsicProcTable;
struct SetExprHelper {
SetExprHelper(GenericExprWrapper &&expr) : expr_{std::move(expr)} {}
void Set(parser::Expr::TypedExpr &x) { x->v = std::move(expr_.v); }
explicit SetExprHelper(GenericExprWrapper &&expr) : expr_{std::move(expr)} {}
void Set(parser::Expr::TypedExpr &x) {
x.reset(new GenericExprWrapper{std::move(expr_)});
}
void Set(const parser::Expr &x) { Set(x.typedExpr); }
void Set(const parser::Variable &x) { Set(x.typedExpr); }
template<typename T> void Set(const common::Indirection<T> &x) {
@ -107,13 +109,12 @@ struct SetExprHelper {
GenericExprWrapper expr_;
};
// Set the typedExpr data member to std::nullopt to indicate an error
template<typename T> void ResetExpr(const T &x) {
SetExprHelper{GenericExprWrapper{std::nullopt}}.Set(x);
SetExprHelper{GenericExprWrapper{/* error indicator */}}.Set(x);
}
template<typename T> void SetExpr(const T &x, GenericExprWrapper &&expr) {
SetExprHelper{std::move(expr)}.Set(x);
template<typename T> void SetExpr(const T &x, Expr<SomeType> &&expr) {
SetExprHelper{GenericExprWrapper{std::move(expr)}}.Set(x);
}
class ExpressionAnalyzer {
@ -197,7 +198,7 @@ public:
return std::nullopt;
} else {
// Save folded expression for later use
SetExpr(x, common::Clone(result));
SetExpr(x, common::Clone(*result));
}
}
return result;

View file

@ -393,7 +393,7 @@ bool ExprTypeKindIsDefault(
const evaluate::Assignment *GetAssignment(const parser::AssignmentStmt &x) {
const auto &typed{x.typedAssignment};
return typed && typed->v ? &*typed->v : nullptr;
return typed ? &typed->v : nullptr;
}
const Symbol *FindInterface(const Symbol &symbol) {

View file

@ -233,7 +233,7 @@ bool ExprTypeKindIsDefault(
struct GetExprHelper {
const SomeExpr *Get(const parser::Expr::TypedExpr &x) {
CHECK(x);
return x->v ? &*x->v : nullptr;
return x && x->v ? &*x->v : nullptr;
}
const SomeExpr *Get(const parser::Expr &x) { return Get(x.typedExpr); }
const SomeExpr *Get(const parser::Variable &x) { return Get(x.typedExpr); }

View file

@ -292,26 +292,22 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
Fortran::parser::AnalyzedObjectsAsFortran asFortran{
[](std::ostream &o, const Fortran::evaluate::GenericExprWrapper &x) {
if (x.v) {
o << *x.v;
x.v->AsFortran(o);
} else {
o << "(bad expression)";
}
},
[](std::ostream &o,
const Fortran::evaluate::GenericAssignmentWrapper &x) {
if (x.v) {
std::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::Assignment::IntrinsicAssignment
&y) { y.rhs.AsFortran(y.lhs.AsFortran(o) << '='); },
[&](const Fortran::evaluate::ProcedureRef &y) {
y.AsFortran(o << "CALL ");
},
},
x.v->u);
} else {
o << "(bad assignment)";
}
std::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::Assignment::IntrinsicAssignment
&y) { y.rhs.AsFortran(y.lhs.AsFortran(o) << '='); },
[&](const Fortran::evaluate::ProcedureRef &y) {
y.AsFortran(o << "CALL ");
},
},
x.v.u);
},
[](std::ostream &o, const Fortran::evaluate::ProcedureRef &x) {
x.AsFortran(o << "CALL ");