From 97d7b398e4da89bbfb18b1232d6e1b8474fe683c Mon Sep 17 00:00:00 2001 From: Pete Steinfeld Date: Tue, 10 Sep 2019 14:42:34 -0700 Subject: [PATCH] [flang] Combined the implementations to ```Pre()``` and ```Post()``` functions that call `PushConstruct()``` and ```PopConstruct()``` following a genius suggestion from Peter. Original-commit: flang-compiler/f18@be2a03ebf479be8eda2529e6c47a7d44a073c455 Reviewed-on: https://github.com/flang-compiler/f18/pull/686 --- flang/lib/semantics/semantics.cc | 131 +++---------------------------- 1 file changed, 9 insertions(+), 122 deletions(-) diff --git a/flang/lib/semantics/semantics.cc b/flang/lib/semantics/semantics.cc index 32e8caab3dbd..fbb54647bc41 100644 --- a/flang/lib/semantics/semantics.cc +++ b/flang/lib/semantics/semantics.cc @@ -57,10 +57,18 @@ public: : C{context}..., context_{context} {} template bool Pre(const N &node) { + if constexpr (common::HasMember) { + context_.PushConstruct(node); + } Enter(node); return true; } - template void Post(const N &node) { Leave(node); } + template void Post(const N &node) { + Leave(node); + if constexpr (common::HasMember) { + context_.PopConstruct(); + } + } template bool Pre(const parser::Statement &node) { context_.set_location(node.source); @@ -81,127 +89,6 @@ public: context_.set_location(std::nullopt); } - bool Pre(const parser::AssociateConstruct &associateConstruct) { - context_.PushConstruct(associateConstruct); - Enter(associateConstruct); - return true; - } - - bool Pre(const parser::BlockConstruct &blockConstruct) { - context_.PushConstruct(blockConstruct); - Enter(blockConstruct); - return true; - } - - bool Pre(const parser::CaseConstruct &caseConstruct) { - context_.PushConstruct(caseConstruct); - Enter(caseConstruct); - return true; - } - - bool Pre(const parser::CriticalConstruct &criticalConstruct) { - context_.PushConstruct(criticalConstruct); - Enter(criticalConstruct); - return true; - } - - bool Pre(const parser::ChangeTeamConstruct &changeTeamConstruct) { - context_.PushConstruct(changeTeamConstruct); - Enter(changeTeamConstruct); - return true; - } - - bool Pre(const parser::DoConstruct &doConstruct) { - context_.PushConstruct(doConstruct); - Enter(doConstruct); - return true; - } - - bool Pre(const parser::ForAllConstruct &forAllConstruct) { - context_.PushConstruct(&forAllConstruct); - Enter(forAllConstruct); - return true; - } - - bool Pre(const parser::IfConstruct &ifConstruct) { - context_.PushConstruct(ifConstruct); - Enter(ifConstruct); - return true; - } - - bool Pre(const parser::SelectRankConstruct &selectRankConstruct) { - context_.PushConstruct(selectRankConstruct); - Enter(selectRankConstruct); - return true; - } - - bool Pre(const parser::SelectTypeConstruct &selectTypeConstruct) { - context_.PushConstruct(selectTypeConstruct); - Enter(selectTypeConstruct); - return true; - } - - bool Pre(const parser::WhereConstruct &whereConstruct) { - context_.PushConstruct(whereConstruct); - Enter(whereConstruct); - return true; - } - - void Post(const parser::AssociateConstruct &associateConstruct) { - Leave(associateConstruct); - context_.PopConstruct(); - } - - void Post(const parser::BlockConstruct &blockConstruct) { - Leave(blockConstruct); - context_.PopConstruct(); - } - - void Post(const parser::CaseConstruct &caseConstruct) { - Leave(caseConstruct); - context_.PopConstruct(); - } - - void Post(const parser::DoConstruct &doConstruct) { - Leave(doConstruct); - context_.PopConstruct(); - } - - void Post(const parser::CriticalConstruct &criticalConstruct) { - Leave(criticalConstruct); - context_.PopConstruct(); - } - - void Post(const parser::ChangeTeamConstruct &changeTeamConstruct) { - Leave(changeTeamConstruct); - context_.PopConstruct(); - } - - void Post(const parser::ForAllConstruct &forAllConstruct) { - Leave(forAllConstruct); - context_.PopConstruct(); - } - - void Post(const parser::IfConstruct &ifConstruct) { - Leave(ifConstruct); - context_.PopConstruct(); - } - - void Post(const parser::SelectRankConstruct &selectRankConstruct) { - Leave(selectRankConstruct); - context_.PopConstruct(); - } - - void Post(const parser::SelectTypeConstruct &selectTypeConstruct) { - Leave(selectTypeConstruct); - context_.PopConstruct(); - } - - void Post(const parser::WhereConstruct &whereConstruct) { - Leave(whereConstruct); - context_.PopConstruct(); - } - bool Walk(const parser::Program &program) { parser::Walk(program, *this); return !context_.AnyFatalError();