From 3fc0f54b249f5cd12c254518031585b0bb42685a Mon Sep 17 00:00:00 2001 From: peter klausler Date: Mon, 19 Nov 2018 11:14:41 -0800 Subject: [PATCH] [flang] Analyze wrapped expressions Original-commit: flang-compiler/f18@b34db5d38f03b11b85890696569a22d506a98736 Reviewed-on: https://github.com/flang-compiler/f18/pull/228 --- flang/lib/semantics/expression.cc | 37 +++++++++++++++++++++++++++++++++++++ flang/lib/semantics/expression.h | 22 ++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index 5139f4a..396bc1a 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -1260,6 +1260,43 @@ evaluate::MaybeExpr AnalyzeExpr( return evaluate::ExprAnalyzer{context}.Analyze(expr); } +template +evaluate::MaybeExpr AnalyzeWrappedExpr( + SemanticsContext &context, const A &expr) { + evaluate::ExprAnalyzer ea{context}; + return evaluate::AnalyzeHelper(ea, expr); +} + +evaluate::MaybeExpr AnalyzeExpr( + SemanticsContext &context, const parser::Scalar &expr) { + return AnalyzeWrappedExpr(context, expr); +} +evaluate::MaybeExpr AnalyzeExpr( + SemanticsContext &context, const parser::Constant &expr) { + return AnalyzeWrappedExpr(context, expr); +} +evaluate::MaybeExpr AnalyzeExpr( + SemanticsContext &context, const parser::Integer &expr) { + return AnalyzeWrappedExpr(context, expr); +} +evaluate::MaybeExpr AnalyzeExpr(SemanticsContext &context, + const parser::Scalar> &expr) { + return AnalyzeWrappedExpr(context, expr); +} +evaluate::MaybeExpr AnalyzeExpr(SemanticsContext &context, + const parser::Scalar> &expr) { + return AnalyzeWrappedExpr(context, expr); +} +evaluate::MaybeExpr AnalyzeExpr(SemanticsContext &context, + const parser::Integer> &expr) { + return AnalyzeWrappedExpr(context, expr); +} +evaluate::MaybeExpr AnalyzeExpr(SemanticsContext &context, + const parser::Scalar>> + &expr) { + return AnalyzeWrappedExpr(context, expr); +} + class Mutator { public: Mutator(SemanticsContext &context) : context_{context} {} diff --git a/flang/lib/semantics/expression.h b/flang/lib/semantics/expression.h index 0d686f9..2ab9f9a 100644 --- a/flang/lib/semantics/expression.h +++ b/flang/lib/semantics/expression.h @@ -22,18 +22,36 @@ namespace Fortran::parser { struct Expr; struct Program; +template struct Scalar; +template struct Integer; +template struct Constant; } namespace Fortran::semantics { class SemanticsContext; -using MaybeExpr = std::optional>; - // Semantic analysis of one expression. std::optional> AnalyzeExpr( SemanticsContext &, const parser::Expr &); +std::optional> AnalyzeExpr( + SemanticsContext &, const parser::Scalar &); +std::optional> AnalyzeExpr( + SemanticsContext &, const parser::Constant &); +std::optional> AnalyzeExpr( + SemanticsContext &, const parser::Integer &); +std::optional> AnalyzeExpr( + SemanticsContext &, const parser::Scalar> &); +std::optional> AnalyzeExpr( + SemanticsContext &, const parser::Scalar> &); +std::optional> AnalyzeExpr( + SemanticsContext &, + const parser::Integer> &); +std::optional> AnalyzeExpr( + SemanticsContext &, + const parser::Scalar>> &); + // Semantic analysis of all expressions in a parse tree, which is // decorated with typed representations for top-level expressions. void AnalyzeExpressions(parser::Program &, SemanticsContext &); -- 2.7.4