forked from OSchip/llvm-project
[flang] Simplify some of the if-return-else-return expansions while possibly
keeping things readable. Original-commit: flang-compiler/f18@55b7e18763 Reviewed-on: https://github.com/flang-compiler/f18/pull/170 Tree-same-pre-rewrite: false
This commit is contained in:
parent
57eb3cd6f9
commit
20cc4d5134
|
@ -57,23 +57,13 @@ using SourceStmtList = std::vector<SourceStatementInfoTuplePOD>;
|
||||||
|
|
||||||
const bool isStrictF18{false}; // FIXME - make a command-line option
|
const bool isStrictF18{false}; // FIXME - make a command-line option
|
||||||
|
|
||||||
bool HasScope(ProxyForScope scope) {
|
bool HasScope(ProxyForScope scope) { return scope != ProxyForScope{0u}; }
|
||||||
if (scope != ProxyForScope{0u}) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// F18:R1131
|
// F18:R1131
|
||||||
template<typename A>
|
template<typename A>
|
||||||
constexpr bool IsLegalDoTerm(const parser::Statement<A> &) {
|
constexpr bool IsLegalDoTerm(const parser::Statement<A> &) {
|
||||||
if (std::is_same_v<A, common::Indirection<parser::EndDoStmt>> ||
|
return std::is_same_v<A, common::Indirection<parser::EndDoStmt>> ||
|
||||||
std::is_same_v<A, parser::EndDoStmt>) {
|
std::is_same_v<A, parser::EndDoStmt>;
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
constexpr bool IsLegalDoTerm(
|
constexpr bool IsLegalDoTerm(
|
||||||
|
@ -83,23 +73,20 @@ constexpr bool IsLegalDoTerm(
|
||||||
return true;
|
return true;
|
||||||
} else if (isStrictF18) {
|
} else if (isStrictF18) {
|
||||||
return false;
|
return false;
|
||||||
} else if (!(std::holds_alternative<
|
|
||||||
common::Indirection<parser::ArithmeticIfStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<common::Indirection<parser::CycleStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<common::Indirection<parser::ExitStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<common::Indirection<parser::StopStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<common::Indirection<parser::GotoStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<
|
|
||||||
common::Indirection<parser::ReturnStmt>>(
|
|
||||||
actionStmt.statement.u))) {
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return !(
|
||||||
|
std::holds_alternative<common::Indirection<parser::ArithmeticIfStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::CycleStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::ExitStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::StopStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::GotoStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::ReturnStmt>>(
|
||||||
|
actionStmt.statement.u));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,18 +125,16 @@ constexpr bool IsLegalBranchTarget(
|
||||||
const parser::Statement<parser::ActionStmt> &actionStmt) {
|
const parser::Statement<parser::ActionStmt> &actionStmt) {
|
||||||
if (!isStrictF18) {
|
if (!isStrictF18) {
|
||||||
return true;
|
return true;
|
||||||
} else if (
|
|
||||||
!(std::holds_alternative<common::Indirection<parser::ArithmeticIfStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<common::Indirection<parser::AssignStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<common::Indirection<parser::AssignedGotoStmt>>(
|
|
||||||
actionStmt.statement.u) ||
|
|
||||||
std::holds_alternative<common::Indirection<parser::PauseStmt>>(
|
|
||||||
actionStmt.statement.u))) {
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return !(
|
||||||
|
std::holds_alternative<common::Indirection<parser::ArithmeticIfStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::AssignStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::AssignedGotoStmt>>(
|
||||||
|
actionStmt.statement.u) ||
|
||||||
|
std::holds_alternative<common::Indirection<parser::PauseStmt>>(
|
||||||
|
actionStmt.statement.u));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,20 +158,12 @@ bool BothEqOrNone(const std::optional<parser::Name> &name_a,
|
||||||
const std::optional<parser::Name> &name_b) {
|
const std::optional<parser::Name> &name_b) {
|
||||||
if (name_a.has_value()) {
|
if (name_a.has_value()) {
|
||||||
if (name_b.has_value()) {
|
if (name_b.has_value()) {
|
||||||
if (name_a->ToString() == name_b->ToString()) {
|
return name_a->ToString() == name_b->ToString();
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!name_b.has_value()) {
|
return !name_b.has_value();
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,11 +172,7 @@ bool PresentAndEq(const std::optional<parser::Name> &name_a,
|
||||||
if (!name_a.has_value()) {
|
if (!name_a.has_value()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (name_b.has_value()) {
|
} else if (name_b.has_value()) {
|
||||||
if (name_a->ToString() == name_b->ToString()) {
|
return name_a->ToString() == name_b->ToString();
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue