diff --git a/src/Func.h b/src/Func.h index 8b31976e69..f6808484d5 100644 --- a/src/Func.h +++ b/src/Func.h @@ -291,6 +291,9 @@ protected: */ virtual void SetCaptures(Frame* f); + // Captures when using ZVal block instead of a Frame. + std::unique_ptr> captures_vec; + private: size_t frame_size = 0; @@ -304,9 +307,6 @@ private: OffsetMap* captures_offset_mapping = nullptr; - // Captures when using ZVal block instead of a Frame. - std::unique_ptr> captures_vec; - // The most recently added/updated body ... StmtPtr current_body; diff --git a/src/Type.h b/src/Type.h index c5c52bc095..4f1f4e702d 100644 --- a/src/Type.h +++ b/src/Type.h @@ -35,6 +35,7 @@ class CompositeHash; class Expr; class ListExpr; class ZAMCompiler; +class CPPRuntime; using ExprPtr = IntrusivePtr; using ListExprPtr = IntrusivePtr; @@ -752,6 +753,7 @@ private: class CreationInitsOptimizer; friend zeek::RecordVal; friend zeek::detail::ZAMCompiler; + friend zeek::detail::CPPRuntime; const auto& DeferredInits() const { return deferred_inits; } const auto& CreationInits() const { return creation_inits; } diff --git a/src/script_opt/CPP/RuntimeOps.cc b/src/script_opt/CPP/RuntimeOps.cc index b6bfde35b8..03973a2e74 100644 --- a/src/script_opt/CPP/RuntimeOps.cc +++ b/src/script_opt/CPP/RuntimeOps.cc @@ -194,11 +194,7 @@ void remove_element__CPP(TableValPtr aggr, ListValPtr indices) { check_iterators__CPP(iterators_invalidated); } -// A helper function that takes a parallel vectors of attribute tags -// and values and returns a collective AttributesPtr corresponding to -// those instantiated attributes. For attributes that don't have -// associated expressions, the corresponding value should be nil. -static AttributesPtr build_attrs__CPP(vector attr_tags, vector attr_vals) { +AttributesPtr build_attrs__CPP(IntVec attr_tags, vector attr_vals) { vector attrs; int nattrs = attr_tags.size(); for ( auto i = 0; i < nattrs; ++i ) { @@ -243,7 +239,7 @@ TableValPtr table_constructor__CPP(vector indices, vector vals, return aggr; } -void assign_attrs__CPP(IDPtr id, std::vector attr_tags, std::vector attr_vals) { +void assign_attrs__CPP(IDPtr id, IntVec attr_tags, ValVec attr_vals) { id->SetAttrs(build_attrs__CPP(std::move(attr_tags), std::move(attr_vals))); } diff --git a/src/script_opt/CPP/RuntimeOps.h b/src/script_opt/CPP/RuntimeOps.h index 1722f4c9bc..6a31f8c1a7 100644 --- a/src/script_opt/CPP/RuntimeOps.h +++ b/src/script_opt/CPP/RuntimeOps.h @@ -18,7 +18,16 @@ namespace detail { class CPPRuntime { public: - static auto RawOptField(const RecordValPtr& rv, int field) { return rv->RawOptField(field); } + static auto& RawField(const RecordValPtr& rv, int field) { return rv->RawField(field); } + static auto& RawField(RecordVal* rv, int field) { return rv->RawField(field); } + static auto& RawOptField(const RecordValPtr& rv, int field) { return rv->RawOptField(field); } + static auto& RawOptField(RecordVal* rv, int field) { return rv->RawOptField(field); } + + static const auto& GetCreationInits(const RecordType* rt) { return rt->CreationInits(); } + + static RecordVal* BuildRecordVal(RecordTypePtr t, std::vector> init_vals) { + return new RecordVal(std::move(t), std::move(init_vals)); + } }; // Returns the concatenation of the given strings.