From bc140ed13ce20a4231684ee8044d2cb87c0261e5 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Thu, 4 Apr 2019 16:32:37 -0700 Subject: [PATCH] [flang] Address review comments. Change AnalyzeArraySpec and AnalyzeCoarraySpec to return resulting ArraySpec by value. Original-commit: flang-compiler/f18@0ae38143e530f867a7aa4392bfa09345c28ad7e3 Reviewed-on: https://github.com/flang-compiler/f18/pull/384 --- flang/lib/semantics/resolve-names-utils.cc | 29 ++++++++++++++--------------- flang/lib/semantics/resolve-names-utils.h | 9 ++++----- flang/lib/semantics/resolve-names.cc | 6 ++++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/flang/lib/semantics/resolve-names-utils.cc b/flang/lib/semantics/resolve-names-utils.cc index 3056f9d..262f772 100644 --- a/flang/lib/semantics/resolve-names-utils.cc +++ b/flang/lib/semantics/resolve-names-utils.cc @@ -167,16 +167,13 @@ static GenericKind MapIntrinsicOperator(IntrinsicOperator op) { class ArraySpecAnalyzer { public: - ArraySpecAnalyzer(ArraySpec &arraySpec, SemanticsContext &context) - : context_{context}, arraySpec_{arraySpec} { - CHECK(arraySpec.empty()); - } - void Analyze(const parser::ArraySpec &); - void Analyze(const parser::CoarraySpec &); + ArraySpecAnalyzer(SemanticsContext &context) : context_{context} {} + ArraySpec Analyze(const parser::ArraySpec &); + ArraySpec Analyze(const parser::CoarraySpec &); private: SemanticsContext &context_; - ArraySpec &arraySpec_; + ArraySpec arraySpec_; template void Analyze(const std::list &list) { for (const auto &elem : list) { @@ -195,16 +192,16 @@ private: Bound GetBound(const parser::SpecificationExpr &); }; -void AnalyzeArraySpec(ArraySpec &result, SemanticsContext &context, - const parser::ArraySpec &arraySpec) { - ArraySpecAnalyzer{result, context}.Analyze(arraySpec); +ArraySpec AnalyzeArraySpec( + SemanticsContext &context, const parser::ArraySpec &arraySpec) { + return ArraySpecAnalyzer{context}.Analyze(arraySpec); } -void AnalyzeCoarraySpec(ArraySpec &result, SemanticsContext &context, - const parser::CoarraySpec &coarraySpec) { - ArraySpecAnalyzer{result, context}.Analyze(coarraySpec); +ArraySpec AnalyzeCoarraySpec( + SemanticsContext &context, const parser::CoarraySpec &coarraySpec) { + return ArraySpecAnalyzer{context}.Analyze(coarraySpec); } -void ArraySpecAnalyzer::Analyze(const parser::ArraySpec &x) { +ArraySpec ArraySpecAnalyzer::Analyze(const parser::ArraySpec &x) { std::visit( common::visitors{ [&](const parser::DeferredShapeSpecList &y) { MakeDeferred(y.v); }, @@ -216,8 +213,9 @@ void ArraySpecAnalyzer::Analyze(const parser::ArraySpec &x) { [&](const auto &y) { Analyze(y); }, }, x.u); + return arraySpec_; } -void ArraySpecAnalyzer::Analyze(const parser::CoarraySpec &x) { +ArraySpec ArraySpecAnalyzer::Analyze(const parser::CoarraySpec &x) { std::visit( common::visitors{ [&](const parser::DeferredCoshapeSpecList &y) { MakeDeferred(y.v); }, @@ -228,6 +226,7 @@ void ArraySpecAnalyzer::Analyze(const parser::CoarraySpec &x) { }, }, x.u); + return arraySpec_; } void ArraySpecAnalyzer::Analyze(const parser::AssumedShapeSpec &x) { diff --git a/flang/lib/semantics/resolve-names-utils.h b/flang/lib/semantics/resolve-names-utils.h index 0f210d2..1e7170a 100644 --- a/flang/lib/semantics/resolve-names-utils.h +++ b/flang/lib/semantics/resolve-names-utils.h @@ -68,11 +68,10 @@ private: void Analyze(const parser::GenericSpec &); }; -// Analyze a parser::ArraySpec or parser::CoarraySpec into the provide ArraySpec -void AnalyzeArraySpec( - ArraySpec &, SemanticsContext &, const parser::ArraySpec &); -void AnalyzeCoarraySpec( - ArraySpec &, SemanticsContext &, const parser::CoarraySpec &); +// Analyze a parser::ArraySpec or parser::CoarraySpec +ArraySpec AnalyzeArraySpec(SemanticsContext &, const parser::ArraySpec &); +ArraySpec AnalyzeCoarraySpec( + SemanticsContext &context, const parser::CoarraySpec &); } diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 47328a4..cd1ee9d 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -1419,10 +1419,12 @@ bool ImplicitRulesVisitor::HandleImplicitNone( // ArraySpecVisitor implementation void ArraySpecVisitor::Post(const parser::ArraySpec &x) { - AnalyzeArraySpec(arraySpec_, context(), x); + CHECK(arraySpec_.empty()); + arraySpec_ = AnalyzeArraySpec(context(), x); } void ArraySpecVisitor::Post(const parser::CoarraySpec &x) { - AnalyzeCoarraySpec(coarraySpec_, context(), x); + CHECK(coarraySpec_.empty()); + coarraySpec_ = AnalyzeCoarraySpec(context(), x); } const ArraySpec &ArraySpecVisitor::arraySpec() { -- 2.7.4