make externally available the expression used for initializating a record field

This commit is contained in:
Vern Paxson 2024-04-08 17:54:58 -04:00 committed by Tim Wojtulewicz
parent 88ef6cb5b6
commit 9fe7d8581f
2 changed files with 10 additions and 1 deletions

View file

@ -854,6 +854,8 @@ void TypeDecl::DescribeReST(ODesc* d, bool roles_only) const {
namespace detail { namespace detail {
ExprPtr FieldInit::InitExpr() const { return nullptr; }
// A record field initialization that directly assigns a fixed value ... // A record field initialization that directly assigns a fixed value ...
class DirectFieldInit final : public FieldInit { class DirectFieldInit final : public FieldInit {
public: public:
@ -884,7 +886,7 @@ private:
class ExprFieldInit final : public FieldInit { class ExprFieldInit final : public FieldInit {
public: public:
// Initialization requires evaluating the given expression, // 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). // coercion for some records).
ExprFieldInit(detail::ExprPtr _init_expr, TypePtr _init_type) ExprFieldInit(detail::ExprPtr _init_expr, TypePtr _init_type)
: init_expr(std::move(_init_expr)), init_type(std::move(_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; } bool IsDeferrable() const override { return false; }
ExprPtr InitExpr() const override { return init_expr; }
private: private:
detail::ExprPtr init_expr; detail::ExprPtr init_expr;
TypePtr init_type; TypePtr init_type;

View file

@ -36,6 +36,7 @@ class Expr;
class ListExpr; class ListExpr;
class ZAMCompiler; class ZAMCompiler;
using ExprPtr = IntrusivePtr<Expr>;
using ListExprPtr = IntrusivePtr<ListExpr>; using ListExprPtr = IntrusivePtr<ListExpr>;
// The following tracks how to initialize a given record field. // The following tracks how to initialize a given record field.
@ -48,6 +49,10 @@ public:
// Can initialization of the field be deferred? // Can initialization of the field be deferred?
virtual bool IsDeferrable() const { return true; } 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 } // namespace detail