From 0ff94b9d0be3b9c53ba7375db69a44db313eed09 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Mon, 1 Apr 2019 15:52:49 -0700 Subject: [PATCH] [flang] Define and use UnlabeledStatement<> for if & forall Original-commit: flang-compiler/f18@028e6aba6cd0ca40533401fcd4bab38e94f1f43a Reviewed-on: https://github.com/flang-compiler/f18/pull/373 Tree-same-pre-rewrite: false --- flang/lib/parser/dump-parse-tree.h | 6 +- flang/lib/parser/grammar.h | 7 +- flang/lib/parser/parse-tree-visitor.h | 8 +- flang/lib/parser/parse-tree.h | 17 +- flang/lib/parser/stmt-parser.h | 9 ++ flang/lib/semantics/assignment.cc | 297 +++++++++++++++++----------------- flang/lib/semantics/check-if-stmt.cc | 6 +- 7 files changed, 187 insertions(+), 163 deletions(-) diff --git a/flang/lib/parser/dump-parse-tree.h b/flang/lib/parser/dump-parse-tree.h index f427b1a..818e03e 100644 --- a/flang/lib/parser/dump-parse-tree.h +++ b/flang/lib/parser/dump-parse-tree.h @@ -790,8 +790,10 @@ public: bool Pre(const parser::CharBlock &) { return true; } void Post(const parser::CharBlock &) {} - template bool Pre(const parser::Statement &) { return true; } - template void Post(const parser::Statement &) {} + template bool Pre(const parser::UnlabeledStatement &) { + return true; + } + template void Post(const parser::UnlabeledStatement &) {} template bool Pre(const common::Indirection &) { return true; } template void Post(const common::Indirection &) {} diff --git a/flang/lib/parser/grammar.h b/flang/lib/parser/grammar.h index 66ce639b..10963ea 100644 --- a/flang/lib/parser/grammar.h +++ b/flang/lib/parser/grammar.h @@ -2015,8 +2015,8 @@ TYPE_CONTEXT_PARSER("END FORALL statement"_en_US, // R1055 forall-stmt -> FORALL concurrent-header forall-assignment-stmt TYPE_CONTEXT_PARSER("FORALL statement"_en_US, - construct( - "FORALL" >> indirect(concurrentHeader), forallAssignmentStmt)) + construct("FORALL" >> indirect(concurrentHeader), + unlabeledStatement(forallAssignmentStmt))) // R1101 block -> [execution-part-construct]... constexpr auto block{many(executionPartConstruct)}; @@ -2201,7 +2201,8 @@ TYPE_CONTEXT_PARSER("IF construct"_en_US, // R1139 if-stmt -> IF ( scalar-logical-expr ) action-stmt TYPE_CONTEXT_PARSER("IF statement"_en_US, - construct("IF" >> parenthesized(scalarLogicalExpr), actionStmt)) + construct("IF" >> parenthesized(scalarLogicalExpr), + unlabeledStatement(actionStmt))) // R1140 case-construct -> // select-case-stmt [case-stmt block]... end-select-stmt diff --git a/flang/lib/parser/parse-tree-visitor.h b/flang/lib/parser/parse-tree-visitor.h index 7c9e2ae..4434106 100644 --- a/flang/lib/parser/parse-tree-visitor.h +++ b/flang/lib/parser/parse-tree-visitor.h @@ -291,17 +291,17 @@ template void Walk(DefaultChar &x, M &mutator) { } } -template void Walk(const Statement &x, V &visitor) { +template +void Walk(const UnlabeledStatement &x, V &visitor) { if (visitor.Pre(x)) { - // N.B. the label is not traversed Walk(x.source, visitor); Walk(x.statement, visitor); visitor.Post(x); } } -template void Walk(Statement &x, M &mutator) { +template +void Walk(UnlabeledStatement &x, M &mutator) { if (mutator.Pre(x)) { - // N.B. the label is not traversed Walk(x.source, mutator); Walk(x.statement, mutator); mutator.Post(x); diff --git a/flang/lib/parser/parse-tree.h b/flang/lib/parser/parse-tree.h index 5e5925a..c1dcdff 100644 --- a/flang/lib/parser/parse-tree.h +++ b/flang/lib/parser/parse-tree.h @@ -323,13 +323,16 @@ using Label = std::uint64_t; // validated later, must be in [1..99999] // A wrapper for xzy-stmt productions that are statements, so that // source provenances and labels have a uniform representation. -template struct Statement { - Statement(std::optional &&lab, A &&s) - : label(std::move(lab)), statement(std::move(s)) {} +template struct UnlabeledStatement { + explicit UnlabeledStatement(A &&s) : statement(std::move(s)) {} CharBlock source; - std::optional