diff --git a/src/Type.cc b/src/Type.cc index 923a71c23f..245565a16b 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -854,6 +854,8 @@ void TypeDecl::DescribeReST(ODesc* d, bool roles_only) const { namespace detail { +ExprPtr FieldInit::InitExpr() const { return nullptr; } + // A record field initialization that directly assigns a fixed value ... class DirectFieldInit final : public FieldInit { public: @@ -884,7 +886,7 @@ private: class ExprFieldInit final : public FieldInit { public: // Initialization requires evaluating the given expression, - // yielding the a value of the given type (which might require + // yielding a value of the given type (which might require // coercion for some records). ExprFieldInit(detail::ExprPtr _init_expr, TypePtr _init_type) : init_expr(std::move(_init_expr)), init_type(std::move(_init_type)) { @@ -910,6 +912,8 @@ public: bool IsDeferrable() const override { return false; } + ExprPtr InitExpr() const override { return init_expr; } + private: detail::ExprPtr init_expr; TypePtr init_type; diff --git a/src/Type.h b/src/Type.h index 440094705a..71fe57ea46 100644 --- a/src/Type.h +++ b/src/Type.h @@ -36,6 +36,7 @@ class Expr; class ListExpr; class ZAMCompiler; +using ExprPtr = IntrusivePtr; using ListExprPtr = IntrusivePtr; // The following tracks how to initialize a given record field. @@ -48,6 +49,10 @@ public: // Can initialization of the field be deferred? virtual bool IsDeferrable() const { return true; } + + // Returns the expression evaluated to initialize the field, if any. + // (Used for script optimization.) + virtual ExprPtr InitExpr() const; }; } // namespace detail