From 7bdf04b695a3380bd7c7b04a8a1fd7dd68c0196e Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Tue, 28 Aug 2018 10:14:43 -0700 Subject: [PATCH] [flang] Use is_same<> templates Original-commit: flang-compiler/f18@a47f6bacf09a032c46d9d26d7e3d07c5b96853ae Reviewed-on: https://github.com/flang-compiler/f18/pull/170 Tree-same-pre-rewrite: false --- flang/lib/semantics/resolve-labels.cc | 83 +++++++++++---------------- 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/flang/lib/semantics/resolve-labels.cc b/flang/lib/semantics/resolve-labels.cc index 747149723aca..c56f3062fb19 100644 --- a/flang/lib/semantics/resolve-labels.cc +++ b/flang/lib/semantics/resolve-labels.cc @@ -66,17 +66,11 @@ public: /// \brief Is this a legal DO terminator? /// Pattern match dependent on the standard we're enforcing +/// F18:R1131 (must be CONTINUE or END DO) template constexpr bool IsLegalDoTerm(const parser::Statement&) { - return false; -} -// F18:R1131 (must be CONTINUE or END DO) -template<> constexpr bool IsLegalDoTerm(const parser::Statement&) { - return true; -} -template<> constexpr bool IsLegalDoTerm(const parser::Statement>&) { - return true; + using EDS = parser::EndDoStmt; + return std::disjunction>, + std::is_same>::value; } template<> constexpr bool IsLegalDoTerm(const parser::Statement& A) { @@ -99,18 +93,38 @@ template<> constexpr bool IsLegalDoTerm(const parser::Statement constexpr bool IsFormat(const parser::Statement&) { - return false; -} -template<> constexpr bool IsFormat(const parser::Statement>&) { - return true; + return std::is_same>::value; } /// \brief Is this a legal branch target? /// Pattern match dependent on the standard we're enforcing template constexpr bool IsLegalBranchTarget(const parser:: Statement&) { - return false; + using LDS = parser::LabelDoStmt; + using EDS = parser::EndDoStmt; + return std::disjunction, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same>, + std::is_same, + std::is_same, + std::is_same>, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same>::value; } template<> constexpr bool IsLegalBranchTarget(const parser::Statement& A) { @@ -124,35 +138,7 @@ template<> constexpr bool IsLegalBranchTarget(const parser::Statement>(P) || std::get_if>(P)); } -#define Instantiate(TYPE) \ - template<> constexpr bool IsLegalBranchTarget(const parser:: \ - Statement&) { \ - return true; \ - } -Instantiate(parser::AssociateStmt) -Instantiate(parser::EndAssociateStmt) -Instantiate(parser::IfThenStmt) -Instantiate(parser::EndIfStmt) -Instantiate(parser::SelectCaseStmt) -Instantiate(parser::EndSelectStmt) -Instantiate(parser::SelectRankStmt) -Instantiate(parser::SelectTypeStmt) -Instantiate(common::Indirection) -Instantiate(parser::NonLabelDoStmt) -Instantiate(parser::EndDoStmt) -Instantiate(common::Indirection) -Instantiate(parser::BlockStmt) -Instantiate(parser::EndBlockStmt) -Instantiate(parser::CriticalStmt) -Instantiate(parser::EndCriticalStmt) -Instantiate(parser::ForallConstructStmt) -Instantiate(parser::ForallStmt) -Instantiate(parser::WhereConstructStmt) -Instantiate(parser::EndFunctionStmt) -Instantiate(parser::EndMpSubprogramStmt) -Instantiate(parser::EndProgramStmt) -Instantiate(parser::EndSubroutineStmt) -#undef Instantiate + template constexpr unsigned ConsTrgtFlags(const parser::Statement& S) { @@ -493,11 +479,10 @@ private: /// \param Label the name used by the \c CYCLE or \c EXIT template void CheckLabelContext(const char* const SStr, const A& Name) { - auto E{Names.crend()}; - for (auto I{Names.crbegin()}; I != E; ++I) { - if (*I == Name) + const auto E{Names.crend()}; + const auto I{std::find(Names.crbegin(), E, Name)}; + if (I != E) return; - } EH.Report(Index, "%s construct-name '%s' is not in scope"_err_en_US, SStr, Name.c_str()); NoErrors = false;