mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Change BroType::ShallowClone() to return IntrusivePtr
This commit is contained in:
parent
b05e5c7686
commit
89dd668aff
3 changed files with 28 additions and 26 deletions
30
src/Type.cc
30
src/Type.cc
|
@ -69,7 +69,7 @@ BroType::BroType(TypeTag t, bool arg_base_type)
|
|||
{
|
||||
}
|
||||
|
||||
BroType* BroType::ShallowClone()
|
||||
IntrusivePtr<BroType> BroType::ShallowClone()
|
||||
{
|
||||
switch ( tag ) {
|
||||
case TYPE_VOID:
|
||||
|
@ -87,7 +87,7 @@ BroType* BroType::ShallowClone()
|
|||
case TYPE_ADDR:
|
||||
case TYPE_SUBNET:
|
||||
case TYPE_ANY:
|
||||
return new BroType(tag, base_type);
|
||||
return make_intrusive<BroType>(tag, base_type);
|
||||
|
||||
default:
|
||||
reporter->InternalError("cloning illegal base BroType");
|
||||
|
@ -346,9 +346,9 @@ TableType::TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<BroType> yield)
|
|||
}
|
||||
}
|
||||
|
||||
TableType* TableType::ShallowClone()
|
||||
IntrusivePtr<BroType> TableType::ShallowClone()
|
||||
{
|
||||
return new TableType(indices, yield_type);
|
||||
return make_intrusive<TableType>(indices, yield_type);
|
||||
}
|
||||
|
||||
bool TableType::IsUnspecifiedTable() const
|
||||
|
@ -419,9 +419,9 @@ SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<ListExpr> arg_elements
|
|||
}
|
||||
}
|
||||
|
||||
SetType* SetType::ShallowClone()
|
||||
IntrusivePtr<BroType> SetType::ShallowClone()
|
||||
{
|
||||
return new SetType(indices, elements);
|
||||
return make_intrusive<SetType>(indices, elements);
|
||||
}
|
||||
|
||||
SetType::~SetType() = default;
|
||||
|
@ -457,9 +457,9 @@ FuncType::FuncType(IntrusivePtr<RecordType> arg_args,
|
|||
prototypes.emplace_back(Prototype{false, args, std::move(offsets)});
|
||||
}
|
||||
|
||||
FuncType* FuncType::ShallowClone()
|
||||
IntrusivePtr<BroType> FuncType::ShallowClone()
|
||||
{
|
||||
auto f = new FuncType();
|
||||
auto f = make_intrusive<FuncType>();
|
||||
f->args = {NewRef{}, args->AsRecordType()};
|
||||
f->arg_types = {NewRef{}, arg_types->AsTypeList()};
|
||||
f->yield = yield;
|
||||
|
@ -672,12 +672,12 @@ RecordType::RecordType(type_decl_list* arg_types) : BroType(TYPE_RECORD)
|
|||
|
||||
// in this case the clone is actually not so shallow, since
|
||||
// it gets modified by everyone.
|
||||
RecordType* RecordType::ShallowClone()
|
||||
IntrusivePtr<BroType> RecordType::ShallowClone()
|
||||
{
|
||||
auto pass = new type_decl_list();
|
||||
for ( const auto& type : *types )
|
||||
pass->push_back(new TypeDecl(*type));
|
||||
return new RecordType(pass);
|
||||
return make_intrusive<RecordType>(pass);
|
||||
}
|
||||
|
||||
RecordType::~RecordType()
|
||||
|
@ -1128,12 +1128,12 @@ EnumType::EnumType(const EnumType* e)
|
|||
SetName(e->GetName());
|
||||
}
|
||||
|
||||
EnumType* EnumType::ShallowClone()
|
||||
IntrusivePtr<BroType> EnumType::ShallowClone()
|
||||
{
|
||||
if ( counter == 0 )
|
||||
return new EnumType(GetName());
|
||||
return make_intrusive<EnumType>(GetName());
|
||||
|
||||
return new EnumType(this);
|
||||
return make_intrusive<EnumType>(this);
|
||||
}
|
||||
|
||||
EnumType::~EnumType() = default;
|
||||
|
@ -1356,9 +1356,9 @@ VectorType::VectorType(IntrusivePtr<BroType> element_type)
|
|||
{
|
||||
}
|
||||
|
||||
VectorType* VectorType::ShallowClone()
|
||||
IntrusivePtr<BroType> VectorType::ShallowClone()
|
||||
{
|
||||
return new VectorType(yield_type);
|
||||
return make_intrusive<VectorType>(yield_type);
|
||||
}
|
||||
|
||||
VectorType::~VectorType() = default;
|
||||
|
|
22
src/Type.h
22
src/Type.h
|
@ -151,7 +151,7 @@ public:
|
|||
// Clone operations will mostly be implemented in the derived classes;
|
||||
// in addition cloning will be limited to classes that can be reached by
|
||||
// the script-level.
|
||||
virtual BroType* ShallowClone();
|
||||
virtual IntrusivePtr<BroType> ShallowClone();
|
||||
|
||||
TypeTag Tag() const { return tag; }
|
||||
InternalTypeTag InternalType() const { return internal_tag; }
|
||||
|
@ -415,7 +415,7 @@ class TableType : public IndexType {
|
|||
public:
|
||||
TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<BroType> yield);
|
||||
|
||||
TableType* ShallowClone() override;
|
||||
IntrusivePtr<BroType> ShallowClone() override;
|
||||
|
||||
// Returns true if this table type is "unspecified", which is
|
||||
// what one gets using an empty "set()" or "table()" constructor.
|
||||
|
@ -430,7 +430,7 @@ public:
|
|||
SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<ListExpr> arg_elements);
|
||||
~SetType() override;
|
||||
|
||||
SetType* ShallowClone() override;
|
||||
IntrusivePtr<BroType> ShallowClone() override;
|
||||
|
||||
ListExpr* SetElements() const { return elements.get(); }
|
||||
|
||||
|
@ -453,7 +453,7 @@ public:
|
|||
|
||||
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<BroType> yield,
|
||||
function_flavor f);
|
||||
FuncType* ShallowClone() override;
|
||||
IntrusivePtr<BroType> ShallowClone() override;
|
||||
|
||||
~FuncType() override;
|
||||
|
||||
|
@ -493,6 +493,8 @@ public:
|
|||
{ return prototypes; }
|
||||
|
||||
protected:
|
||||
friend IntrusivePtr<FuncType> make_intrusive<FuncType>();
|
||||
|
||||
FuncType() : BroType(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
|
||||
IntrusivePtr<RecordType> args;
|
||||
IntrusivePtr<TypeList> arg_types;
|
||||
|
@ -504,7 +506,7 @@ protected:
|
|||
class TypeType final : public BroType {
|
||||
public:
|
||||
explicit TypeType(IntrusivePtr<BroType> t) : BroType(TYPE_TYPE), type(std::move(t)) {}
|
||||
TypeType* ShallowClone() override { return new TypeType(type); }
|
||||
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<TypeType>(type); }
|
||||
|
||||
BroType* Type() { return type.get(); }
|
||||
const BroType* Type() const { return type.get(); }
|
||||
|
@ -534,7 +536,7 @@ typedef PList<TypeDecl> type_decl_list;
|
|||
class RecordType final : public BroType {
|
||||
public:
|
||||
explicit RecordType(type_decl_list* types);
|
||||
RecordType* ShallowClone() override;
|
||||
IntrusivePtr<BroType> ShallowClone() override;
|
||||
|
||||
~RecordType() override;
|
||||
|
||||
|
@ -604,7 +606,7 @@ public:
|
|||
class FileType final : public BroType {
|
||||
public:
|
||||
explicit FileType(IntrusivePtr<BroType> yield_type);
|
||||
FileType* ShallowClone() override { return new FileType(yield); }
|
||||
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<FileType>(yield); }
|
||||
~FileType() override;
|
||||
|
||||
BroType* YieldType() override;
|
||||
|
@ -618,7 +620,7 @@ protected:
|
|||
class OpaqueType final : public BroType {
|
||||
public:
|
||||
explicit OpaqueType(const std::string& name);
|
||||
OpaqueType* ShallowClone() override { return new OpaqueType(name); }
|
||||
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<OpaqueType>(name); }
|
||||
~OpaqueType() override { };
|
||||
|
||||
const std::string& Name() const { return name; }
|
||||
|
@ -638,7 +640,7 @@ public:
|
|||
|
||||
explicit EnumType(const EnumType* e);
|
||||
explicit EnumType(const std::string& arg_name);
|
||||
EnumType* ShallowClone() override;
|
||||
IntrusivePtr<BroType> ShallowClone() override;
|
||||
~EnumType() override;
|
||||
|
||||
// The value of this name is next internal counter value, starting
|
||||
|
@ -688,7 +690,7 @@ protected:
|
|||
class VectorType final : public BroType {
|
||||
public:
|
||||
explicit VectorType(IntrusivePtr<BroType> t);
|
||||
VectorType* ShallowClone() override;
|
||||
IntrusivePtr<BroType> ShallowClone() override;
|
||||
~VectorType() override;
|
||||
BroType* YieldType() override;
|
||||
const BroType* YieldType() const override;
|
||||
|
|
|
@ -363,7 +363,7 @@ void add_type(ID* id, IntrusivePtr<BroType> t, attr_list* attr)
|
|||
tnew = std::move(t);
|
||||
else
|
||||
// Clone the type to preserve type name aliasing.
|
||||
tnew = {AdoptRef{}, t->ShallowClone()};
|
||||
tnew = t->ShallowClone();
|
||||
|
||||
BroType::AddAlias(new_type_name, tnew.get());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue