mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
RecordType: Carry field_properties
This should allow IsManagedType() calls within the RecordVal constructor and instead initialize slots based on the properties only. Could maybe also place into TypeDecl directly.
This commit is contained in:
parent
ae86da62f3
commit
108e9fca4c
2 changed files with 28 additions and 1 deletions
11
src/Type.cc
11
src/Type.cc
|
@ -18,6 +18,7 @@
|
||||||
#include "zeek/Traverse.h"
|
#include "zeek/Traverse.h"
|
||||||
#include "zeek/Val.h"
|
#include "zeek/Val.h"
|
||||||
#include "zeek/Var.h"
|
#include "zeek/Var.h"
|
||||||
|
#include "zeek/ZVal.h"
|
||||||
#include "zeek/module_util.h"
|
#include "zeek/module_util.h"
|
||||||
#include "zeek/zeekygen/IdentifierInfo.h"
|
#include "zeek/zeekygen/IdentifierInfo.h"
|
||||||
#include "zeek/zeekygen/Manager.h"
|
#include "zeek/zeekygen/Manager.h"
|
||||||
|
@ -1105,6 +1106,7 @@ void RecordType::AddField(unsigned int field, const TypeDecl* td) {
|
||||||
ASSERT(field == managed_fields.size());
|
ASSERT(field == managed_fields.size());
|
||||||
|
|
||||||
managed_fields.push_back(ZVal::IsManagedType(td->type));
|
managed_fields.push_back(ZVal::IsManagedType(td->type));
|
||||||
|
field_properties.push_back({.is_managed = ZVal::IsManagedType(td->type), .type_tag = td->type->Tag()});
|
||||||
|
|
||||||
// We defer error-checking until here so that we can keep deferred_inits
|
// We defer error-checking until here so that we can keep deferred_inits
|
||||||
// and managed_fields correctly tracking the associated fields.
|
// and managed_fields correctly tracking the associated fields.
|
||||||
|
@ -1539,6 +1541,15 @@ bool RecordType::IsDeferrable() const {
|
||||||
return std::ranges::all_of(creation_inits, is_deferrable);
|
return std::ranges::all_of(creation_inits, is_deferrable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RecordType::InitSlots(std::span<zeek::ZValSlot> slots) const {
|
||||||
|
int n = NumFields();
|
||||||
|
if ( slots.size() != field_properties.size() )
|
||||||
|
zeek::reporter->InternalError("wrong number of slots and slot properties");
|
||||||
|
|
||||||
|
for ( int i = 0; i < n; i++ )
|
||||||
|
slots[i] = field_properties[i];
|
||||||
|
}
|
||||||
|
|
||||||
FileType::FileType(TypePtr yield_type) : Type(TYPE_FILE), yield(std::move(yield_type)) {}
|
FileType::FileType(TypePtr yield_type) : Type(TYPE_FILE), yield(std::move(yield_type)) {}
|
||||||
|
|
||||||
FileType::~FileType() = default;
|
FileType::~FileType() = default;
|
||||||
|
|
18
src/Type.h
18
src/Type.h
|
@ -21,6 +21,7 @@ namespace zeek {
|
||||||
|
|
||||||
class Val;
|
class Val;
|
||||||
union ZVal;
|
union ZVal;
|
||||||
|
class ZValSlot;
|
||||||
class EnumVal;
|
class EnumVal;
|
||||||
class RecordVal;
|
class RecordVal;
|
||||||
class TableVal;
|
class TableVal;
|
||||||
|
@ -635,6 +636,11 @@ private:
|
||||||
|
|
||||||
using type_decl_list = PList<TypeDecl>;
|
using type_decl_list = PList<TypeDecl>;
|
||||||
|
|
||||||
|
struct RecordFieldProperties {
|
||||||
|
bool is_managed = false;
|
||||||
|
TypeTag type_tag = TYPE_VOID;
|
||||||
|
};
|
||||||
|
|
||||||
class RecordType final : public Type {
|
class RecordType final : public Type {
|
||||||
public:
|
public:
|
||||||
explicit RecordType(type_decl_list* types);
|
explicit RecordType(type_decl_list* types);
|
||||||
|
@ -692,7 +698,11 @@ public:
|
||||||
|
|
||||||
// Returns flags corresponding to which fields in the record
|
// Returns flags corresponding to which fields in the record
|
||||||
// have types requiring memory management (reference counting).
|
// have types requiring memory management (reference counting).
|
||||||
const std::vector<bool>& ManagedFields() const { return managed_fields; }
|
[[deprecated("Remove in v9.1: Unused and optimization related internal. Use FieldProperties() instead.")]]
|
||||||
|
const std::vector<bool>& ManagedFields() const {
|
||||||
|
return managed_fields;
|
||||||
|
}
|
||||||
|
const std::vector<RecordFieldProperties>& FieldProperties() const { return field_properties; }
|
||||||
|
|
||||||
int NumFields() const { return num_fields; }
|
int NumFields() const { return num_fields; }
|
||||||
int NumOrigFields() const { return num_orig_fields; }
|
int NumOrigFields() const { return num_orig_fields; }
|
||||||
|
@ -771,10 +781,16 @@ private:
|
||||||
const auto& DeferredInits() const { return deferred_inits; }
|
const auto& DeferredInits() const { return deferred_inits; }
|
||||||
const auto& CreationInits() const { return creation_inits; }
|
const auto& CreationInits() const { return creation_inits; }
|
||||||
|
|
||||||
|
// Initialize the slots using slot_properties.
|
||||||
|
void InitSlots(std::span<zeek::ZValSlot> slots) const;
|
||||||
|
|
||||||
// If we were willing to bound the size of records, then we could
|
// If we were willing to bound the size of records, then we could
|
||||||
// use std::bitset here instead.
|
// use std::bitset here instead.
|
||||||
std::vector<bool> managed_fields;
|
std::vector<bool> managed_fields;
|
||||||
|
|
||||||
|
// Field properties for ZvalSlot initialization
|
||||||
|
std::vector<RecordFieldProperties> field_properties;
|
||||||
|
|
||||||
// Number of fields in the type.
|
// Number of fields in the type.
|
||||||
int num_fields = 0;
|
int num_fields = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue