use a subclass of TableType for incremental construction of compiled scripts

This commit is contained in:
Vern Paxson 2023-03-07 10:15:18 -08:00 committed by Arne Welzel
parent c0dd2b4e81
commit a934acc4f1
3 changed files with 17 additions and 12 deletions

View file

@ -398,16 +398,6 @@ class TableType : public IndexType
public:
TableType(TypeListPtr ind, TypePtr yield);
// Used by script compilation to update a "stub" table type
// (which is specified by using a nil "ind" value in the constructor)
// with its actual index & yield - necessary for dealing with
// recursive types.
void SetIndexAndYield(TypeListPtr ind, TypePtr yield)
{
ind = std::move(indices);
yield_type = std::move(yield);
}
/**
* Assesses whether an &expire_func attribute's function type is compatible
* with this table type.

View file

@ -16,6 +16,21 @@ using FuncValPtr = IntrusivePtr<zeek::FuncVal>;
namespace detail
{
// A version of TableType that allows us to first build a "stub" and
// then fill in its actual index & yield later - necessary for dealing
// with recursive types.
class CPPTableType : public TableType
{
public:
CPPTableType() : TableType(nullptr, nullptr){};
void SetIndexAndYield(TypeListPtr ind, TypePtr yield)
{
ind = std::move(indices);
yield_type = std::move(yield);
}
};
// An initialization hook for a collection of compiled-to-C++ functions
// (the result of a single invocation of the compiler on a set of scripts).
using CPP_init_func = void (*)();

View file

@ -272,7 +272,7 @@ void CPP_TypeInits::PreInit(InitsManager* im, int offset, ValElemVec& init_vals)
}
else if ( tag == TYPE_TABLE )
inits_vec[offset] = make_intrusive<TableType>(nullptr, nullptr);
inits_vec[offset] = make_intrusive<CPPTableType>();
// else no pre-initialization needed
}
@ -399,7 +399,7 @@ TypePtr CPP_TypeInits::BuildTypeList(InitsManager* im, ValElemVec& init_vals, in
TypePtr CPP_TypeInits::BuildTableType(InitsManager* im, ValElemVec& init_vals, int offset) const
{
auto t = cast_intrusive<TableType>(inits_vec[offset]);
auto t = cast_intrusive<CPPTableType>(inits_vec[offset]);
ASSERT(t);
auto index = cast_intrusive<TypeList>(im->Types(init_vals[1]));