Move IntrusivePtr and utility methods to the zeek namespace

This commit is contained in:
Tim Wojtulewicz 2020-06-24 16:40:00 -04:00
parent 4668378d91
commit 9364e6a5b7
255 changed files with 3761 additions and 3730 deletions

View file

@ -71,7 +71,7 @@ Type::Type(zeek::TypeTag t, bool arg_base_type)
{
}
IntrusivePtr<Type> Type::ShallowClone()
zeek::IntrusivePtr<Type> Type::ShallowClone()
{
switch ( tag ) {
case TYPE_VOID:
@ -89,7 +89,7 @@ IntrusivePtr<Type> Type::ShallowClone()
case TYPE_ADDR:
case TYPE_SUBNET:
case TYPE_ANY:
return make_intrusive<Type>(tag, base_type);
return zeek::make_intrusive<Type>(tag, base_type);
default:
reporter->InternalError("cloning illegal base Type");
@ -111,7 +111,7 @@ int Type::MatchesIndex(zeek::detail::ListExpr* const index) const
return DOES_NOT_MATCH_INDEX;
}
const IntrusivePtr<Type>& Type::Yield() const
const zeek::IntrusivePtr<Type>& Type::Yield() const
{
return Type::nil;
}
@ -163,7 +163,7 @@ bool TypeList::AllMatch(const Type* t, bool is_init) const
return true;
}
void TypeList::Append(IntrusivePtr<Type> t)
void TypeList::Append(zeek::IntrusivePtr<Type> t)
{
if ( pure_type && ! same_type(t, pure_type) )
reporter->InternalError("pure type-list violation");
@ -172,7 +172,7 @@ void TypeList::Append(IntrusivePtr<Type> t)
types.emplace_back(std::move(t));
}
void TypeList::AppendEvenIfNotPure(IntrusivePtr<Type> t)
void TypeList::AppendEvenIfNotPure(zeek::IntrusivePtr<Type> t)
{
if ( pure_type && ! same_type(t, pure_type) )
pure_type = nullptr;
@ -317,7 +317,7 @@ bool IndexType::IsSubNetIndex() const
return false;
}
TableType::TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield)
TableType::TableType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<Type> yield)
: IndexType(TYPE_TABLE, std::move(ind), std::move(yield))
{
if ( ! indices )
@ -344,9 +344,9 @@ TableType::TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield)
}
}
IntrusivePtr<Type> TableType::ShallowClone()
zeek::IntrusivePtr<Type> TableType::ShallowClone()
{
return make_intrusive<TableType>(indices, yield_type);
return zeek::make_intrusive<TableType>(indices, yield_type);
}
bool TableType::IsUnspecifiedTable() const
@ -355,7 +355,7 @@ bool TableType::IsUnspecifiedTable() const
return indices->GetTypes().empty();
}
SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr> arg_elements)
SetType::SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::detail::ListExpr> arg_elements)
: TableType(std::move(ind), nullptr), elements(std::move(arg_elements))
{
if ( elements )
@ -378,8 +378,8 @@ SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr
else if ( tl.size() == 1 )
{
IntrusivePtr<Type> ft{NewRef{}, flatten_type(tl[0].get())};
indices = make_intrusive<TypeList>(ft);
zeek::IntrusivePtr<Type> ft{zeek::NewRef{}, flatten_type(tl[0].get())};
indices = zeek::make_intrusive<TypeList>(ft);
indices->Append(std::move(ft));
}
@ -396,24 +396,24 @@ SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr
return;
}
indices = make_intrusive<TypeList>(t);
indices = zeek::make_intrusive<TypeList>(t);
indices->Append(std::move(t));
}
}
}
}
IntrusivePtr<Type> SetType::ShallowClone()
zeek::IntrusivePtr<Type> SetType::ShallowClone()
{
return make_intrusive<SetType>(indices, elements);
return zeek::make_intrusive<SetType>(indices, elements);
}
SetType::~SetType() = default;
FuncType::FuncType(IntrusivePtr<RecordType> arg_args,
IntrusivePtr<Type> arg_yield, FunctionFlavor arg_flavor)
FuncType::FuncType(zeek::IntrusivePtr<RecordType> arg_args,
zeek::IntrusivePtr<Type> arg_yield, FunctionFlavor arg_flavor)
: Type(TYPE_FUNC), args(std::move(arg_args)),
arg_types(make_intrusive<TypeList>()), yield(std::move(arg_yield))
arg_types(zeek::make_intrusive<TypeList>()), yield(std::move(arg_yield))
{
flavor = arg_flavor;
@ -441,9 +441,9 @@ FuncType::FuncType(IntrusivePtr<RecordType> arg_args,
prototypes.emplace_back(Prototype{false, args, std::move(offsets)});
}
IntrusivePtr<Type> FuncType::ShallowClone()
zeek::IntrusivePtr<Type> FuncType::ShallowClone()
{
auto f = make_intrusive<FuncType>();
auto f = zeek::make_intrusive<FuncType>();
f->args = args;
f->arg_types = arg_types;
f->yield = yield;
@ -481,16 +481,16 @@ int FuncType::MatchesIndex(zeek::detail::ListExpr* const index) const
bool FuncType::CheckArgs(const type_list* args, bool is_init) const
{
std::vector<IntrusivePtr<Type>> as;
std::vector<zeek::IntrusivePtr<Type>> as;
as.reserve(args->length());
for ( auto a : *args )
as.emplace_back(NewRef{}, a);
as.emplace_back(zeek::NewRef{}, a);
return CheckArgs(as, is_init);
}
bool FuncType::CheckArgs(const std::vector<IntrusivePtr<Type>>& args,
bool FuncType::CheckArgs(const std::vector<zeek::IntrusivePtr<Type>>& args,
bool is_init) const
{
const auto& my_args = arg_types->GetTypes();
@ -609,8 +609,8 @@ std::optional<FuncType::Prototype> FuncType::FindPrototype(const RecordType& arg
return {};
}
TypeDecl::TypeDecl(const char* i, IntrusivePtr<Type> t,
IntrusivePtr<zeek::detail::Attributes> arg_attrs)
TypeDecl::TypeDecl(const char* i, zeek::IntrusivePtr<Type> t,
zeek::IntrusivePtr<zeek::detail::Attributes> arg_attrs)
: type(std::move(t)),
attrs(std::move(arg_attrs)),
id(i)
@ -658,12 +658,12 @@ RecordType::RecordType(type_decl_list* arg_types) : Type(TYPE_RECORD)
// in this case the clone is actually not so shallow, since
// it gets modified by everyone.
IntrusivePtr<Type> RecordType::ShallowClone()
zeek::IntrusivePtr<Type> RecordType::ShallowClone()
{
auto pass = new type_decl_list();
for ( const auto& type : *types )
pass->push_back(new TypeDecl(*type));
return make_intrusive<RecordType>(pass);
return zeek::make_intrusive<RecordType>(pass);
}
RecordType::~RecordType()
@ -682,7 +682,7 @@ bool RecordType::HasField(const char* field) const
return FieldOffset(field) >= 0;
}
IntrusivePtr<Val> RecordType::FieldDefault(int field) const
zeek::IntrusivePtr<Val> RecordType::FieldDefault(int field) const
{
const TypeDecl* td = FieldDecl(field);
@ -794,31 +794,31 @@ static string container_type_name(const Type* ft)
return s;
}
IntrusivePtr<TableVal> RecordType::GetRecordFieldsVal(const RecordVal* rv) const
zeek::IntrusivePtr<TableVal> RecordType::GetRecordFieldsVal(const RecordVal* rv) const
{
static auto record_field = zeek::id::find_type<RecordType>("record_field");
static auto record_field_table = zeek::id::find_type<TableType>("record_field_table");
auto rval = make_intrusive<TableVal>(record_field_table);
auto rval = zeek::make_intrusive<TableVal>(record_field_table);
for ( int i = 0; i < NumFields(); ++i )
{
const auto& ft = GetFieldType(i);
const TypeDecl* fd = FieldDecl(i);
IntrusivePtr<Val> fv;
zeek::IntrusivePtr<Val> fv;
if ( rv )
fv = rv->GetField(i);
bool logged = (fd->attrs && fd->GetAttr(zeek::detail::ATTR_LOG) != nullptr);
auto nr = make_intrusive<RecordVal>(record_field);
auto nr = zeek::make_intrusive<RecordVal>(record_field);
string s = container_type_name(ft.get());
nr->Assign(0, make_intrusive<StringVal>(s));
nr->Assign(0, zeek::make_intrusive<StringVal>(s));
nr->Assign(1, val_mgr->Bool(logged));
nr->Assign(2, std::move(fv));
nr->Assign(3, FieldDefault(i));
auto field_name = make_intrusive<StringVal>(FieldName(i));
auto field_name = zeek::make_intrusive<StringVal>(FieldName(i));
rval->Assign(std::move(field_name), std::move(nr));
}
@ -845,9 +845,9 @@ const char* RecordType::AddFields(const type_decl_list& others,
if ( add_log_attr )
{
if ( ! td->attrs )
td->attrs = make_intrusive<zeek::detail::Attributes>(td->type, true, false);
td->attrs = zeek::make_intrusive<zeek::detail::Attributes>(td->type, true, false);
td->attrs->AddAttr(make_intrusive<zeek::detail::Attr>(zeek::detail::ATTR_LOG));
td->attrs->AddAttr(zeek::make_intrusive<zeek::detail::Attr>(zeek::detail::ATTR_LOG));
}
types->push_back(td);
@ -1028,7 +1028,7 @@ void SubNetType::Describe(ODesc* d) const
d->Add(int(Tag()));
}
FileType::FileType(IntrusivePtr<Type> yield_type)
FileType::FileType(zeek::IntrusivePtr<Type> yield_type)
: Type(TYPE_FILE), yield(std::move(yield_type))
{
}
@ -1083,12 +1083,12 @@ EnumType::EnumType(const EnumType* e)
SetName(e->GetName());
}
IntrusivePtr<Type> EnumType::ShallowClone()
zeek::IntrusivePtr<Type> EnumType::ShallowClone()
{
if ( counter == 0 )
return make_intrusive<EnumType>(GetName());
return zeek::make_intrusive<EnumType>(GetName());
return make_intrusive<EnumType>(this);
return zeek::make_intrusive<EnumType>(this);
}
EnumType::~EnumType() = default;
@ -1137,11 +1137,11 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
if ( ! id )
{
id = install_ID(name, module_name.c_str(), true, is_export);
id->SetType({NewRef{}, this});
id->SetType({zeek::NewRef{}, this});
id->SetEnumConst();
if ( deprecation )
id->MakeDeprecated({NewRef{}, deprecation});
id->MakeDeprecated({zeek::NewRef{}, deprecation});
zeekygen_mgr->Identifier(std::move(id));
}
@ -1164,7 +1164,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
AddNameInternal(module_name, name, val, is_export);
if ( vals.find(val) == vals.end() )
vals[val] = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, val);
vals[val] = zeek::make_intrusive<EnumVal>(zeek::IntrusivePtr{zeek::NewRef{}, this}, val);
set<Type*> types = Type::GetAliases(GetName());
set<Type*>::const_iterator it;
@ -1213,13 +1213,13 @@ EnumType::enum_name_list EnumType::Names() const
return n;
}
const IntrusivePtr<EnumVal>& EnumType::GetVal(bro_int_t i)
const zeek::IntrusivePtr<EnumVal>& EnumType::GetVal(bro_int_t i)
{
auto it = vals.find(i);
if ( it == vals.end() )
{
auto ev = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, i);
auto ev = zeek::make_intrusive<EnumVal>(zeek::IntrusivePtr{zeek::NewRef{}, this}, i);
return vals.emplace(i, std::move(ev)).first->second;
}
@ -1303,19 +1303,19 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const
}
}
VectorType::VectorType(IntrusivePtr<Type> element_type)
VectorType::VectorType(zeek::IntrusivePtr<Type> element_type)
: Type(TYPE_VECTOR), yield_type(std::move(element_type))
{
}
IntrusivePtr<Type> VectorType::ShallowClone()
zeek::IntrusivePtr<Type> VectorType::ShallowClone()
{
return make_intrusive<VectorType>(yield_type);
return zeek::make_intrusive<VectorType>(yield_type);
}
VectorType::~VectorType() = default;
const IntrusivePtr<Type>& VectorType::Yield() const
const zeek::IntrusivePtr<Type>& VectorType::Yield() const
{
// Work around the fact that we use void internally to mark a vector
// as being unspecified. When looking at its yield type, we need to
@ -1684,8 +1684,8 @@ TypeTag max_type(TypeTag t1, TypeTag t2)
}
}
IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const IntrusivePtr<Type>& arg_t2)
zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& arg_t1,
const zeek::IntrusivePtr<Type>& arg_t2)
{
auto t1 = arg_t1.get();
auto t2 = arg_t2.get();
@ -1758,7 +1758,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const auto& tl1 = it1->GetIndexTypes();
const auto& tl2 = it2->GetIndexTypes();
IntrusivePtr<TypeList> tl3;
zeek::IntrusivePtr<TypeList> tl3;
if ( tl1.size() != tl2.size() )
{
@ -1766,7 +1766,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr;
}
tl3 = make_intrusive<TypeList>();
tl3 = zeek::make_intrusive<TypeList>();
for ( auto i = 0u; i < tl1.size(); ++i )
{
@ -1779,7 +1779,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const auto& y1 = t1->Yield();
const auto& y2 = t2->Yield();
IntrusivePtr<Type> y3;
zeek::IntrusivePtr<Type> y3;
if ( y1 || y2 )
{
@ -1795,9 +1795,9 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
}
if ( t1->IsSet() )
return make_intrusive<SetType>(std::move(tl3), nullptr);
return zeek::make_intrusive<SetType>(std::move(tl3), nullptr);
else
return make_intrusive<TableType>(std::move(tl3), std::move(y3));
return zeek::make_intrusive<TableType>(std::move(tl3), std::move(y3));
}
case TYPE_FUNC:
@ -1810,12 +1810,12 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const FuncType* ft1 = (const FuncType*) t1;
const FuncType* ft2 = (const FuncType*) t1;
auto args = cast_intrusive<RecordType>(merge_types(ft1->Params(),
auto args = zeek::cast_intrusive<RecordType>(merge_types(ft1->Params(),
ft2->Params()));
auto yield = t1->Yield() ?
merge_types(t1->Yield(), t2->Yield()) : nullptr;
return make_intrusive<FuncType>(std::move(args), std::move(yield),
return zeek::make_intrusive<FuncType>(std::move(args), std::move(yield),
ft1->Flavor());
}
@ -1845,7 +1845,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
tdl3->push_back(new TypeDecl(copy_string(td1->id), std::move(tdl3_i)));
}
return make_intrusive<RecordType>(tdl3);
return zeek::make_intrusive<RecordType>(tdl3);
}
case TYPE_LIST:
@ -1888,7 +1888,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr;
}
auto tl3 = make_intrusive<TypeList>();
auto tl3 = zeek::make_intrusive<TypeList>();
for ( auto i = 0u; i < l1.size(); ++i )
tl3->Append(merge_types(l1[i], l2[i]));
@ -1903,7 +1903,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr;
}
return make_intrusive<VectorType>(merge_types(t1->Yield(), t2->Yield()));
return zeek::make_intrusive<VectorType>(merge_types(t1->Yield(), t2->Yield()));
case TYPE_FILE:
if ( ! same_type(t1->Yield(), t2->Yield()) )
@ -1912,7 +1912,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr;
}
return make_intrusive<FileType>(merge_types(t1->Yield(), t2->Yield()));
return zeek::make_intrusive<FileType>(merge_types(t1->Yield(), t2->Yield()));
case TYPE_UNION:
reporter->InternalError("union type in merge_types()");
@ -1924,7 +1924,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
}
}
IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements)
zeek::IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements)
{
TypeList* tl_type = elements->GetType()->AsTypeList();
const auto& tl = tl_type->GetTypes();
@ -1969,7 +1969,7 @@ static Type* reduce_type(Type* t)
return t;
}
IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
zeek::IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
{
if ( init->Tag() != zeek::detail::EXPR_LIST )
{
@ -2008,7 +2008,7 @@ IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
auto t = e0->InitType();
if ( t )
t = {NewRef{}, reduce_type(t.get())};
t = {zeek::NewRef{}, reduce_type(t.get())};
if ( ! t )
return nullptr;
@ -2016,10 +2016,10 @@ IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
for ( int i = 1; t && i < el.length(); ++i )
{
auto el_t = el[i]->InitType();
IntrusivePtr<Type> ti;
zeek::IntrusivePtr<Type> ti;
if ( el_t )
ti = {NewRef{}, reduce_type(el_t.get())};
ti = {zeek::NewRef{}, reduce_type(el_t.get())};
if ( ! ti )
return nullptr;
@ -2044,12 +2044,12 @@ IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
// it one, as that's what's required for creating a set type.
if ( t->Tag() != TYPE_LIST )
{
auto tl = make_intrusive<TypeList>(t);
auto tl = zeek::make_intrusive<TypeList>(t);
tl->Append(std::move(t));
t = std::move(tl);
}
return make_intrusive<SetType>(cast_intrusive<TypeList>(std::move(t)),
return zeek::make_intrusive<SetType>(zeek::cast_intrusive<TypeList>(std::move(t)),
nullptr);
}
@ -2068,14 +2068,14 @@ bool is_atomic_type(const Type& t)
}
}
const IntrusivePtr<Type>& base_type(zeek::TypeTag tag)
const zeek::IntrusivePtr<Type>& base_type(zeek::TypeTag tag)
{
static IntrusivePtr<Type> base_types[NUM_TYPES];
static zeek::IntrusivePtr<Type> base_types[NUM_TYPES];
// We could check here that "tag" actually corresponds to a basic type.
if ( ! base_types[tag] )
{
base_types[tag] = make_intrusive<Type>(tag, true);
base_types[tag] = zeek::make_intrusive<Type>(tag, true);
// Give the base types a pseudo-location for easier identification.
Location l(type_name(tag), 0, 0, 0, 0);
base_types[tag]->SetLocationInfo(&l);