Move everything in util.h to zeek::util namespace.

This commit includes renaming a number of methods prefixed with bro_ to be prefixed with zeek_.
This commit is contained in:
Tim Wojtulewicz 2020-08-06 10:40:24 -07:00
parent 8862b585fa
commit 8d2d867a65
179 changed files with 1277 additions and 1033 deletions

View file

@ -266,7 +266,7 @@ void Type::Describe(ODesc* d) const
void Type::DescribeReST(ODesc* d, bool roles_only) const
{
d->Add(fmt(":zeek:type:`%s`", type_name(Tag())));
d->Add(zeek::util::fmt(":zeek:type:`%s`", type_name(Tag())));
}
void Type::SetError()
@ -339,7 +339,7 @@ unsigned int TypeList::MemoryAllocation() const
for ( const auto& t : types )
size += t->MemoryAllocation();
size += pad_size(types.capacity() * sizeof(decltype(types)::value_type));
size += zeek::util::pad_size(types.capacity() * sizeof(decltype(types)::value_type));
return Type::MemoryAllocation()
+ padded_sizeof(*this) - padded_sizeof(Type)
@ -553,8 +553,8 @@ FuncType::FuncType(RecordTypePtr arg_args,
else if ( has_default_arg )
{
const char* err_str = fmt("required parameter '%s' must precede "
"default parameters", td->id);
const char* err_str = zeek::util::fmt("required parameter '%s' must precede "
"default parameters", td->id);
args->Error(err_str);
}
@ -621,8 +621,8 @@ bool FuncType::CheckArgs(const std::vector<TypePtr>& args,
if ( my_args.size() != args.size() )
{
Warn(fmt("Wrong number of arguments for function. Expected %zu, got %zu.",
args.size(), my_args.size()));
Warn(zeek::util::fmt("Wrong number of arguments for function. Expected %zu, got %zu.",
args.size(), my_args.size()));
return false;
}
@ -631,8 +631,8 @@ bool FuncType::CheckArgs(const std::vector<TypePtr>& args,
for ( size_t i = 0; i < my_args.size(); ++i )
if ( ! same_type(args[i], my_args[i], is_init) )
{
Warn(fmt("Type mismatch in function argument #%zu. Expected %s, got %s.",
i, type_name(args[i]->Tag()), type_name(my_args[i]->Tag())));
Warn(zeek::util::fmt("Type mismatch in function argument #%zu. Expected %s, got %s.",
i, type_name(args[i]->Tag()), type_name(my_args[i]->Tag())));
success = false;
}
@ -719,7 +719,7 @@ std::optional<FuncType::Prototype> FuncType::FindPrototype(const RecordType& arg
const auto& desired_type = args.GetFieldType(i);
if ( ! same_type(ptype, desired_type) ||
! streq(args.FieldName(i), p.args->FieldName(i)) )
! zeek::util::streq(args.FieldName(i), p.args->FieldName(i)) )
{
matched = false;
break;
@ -744,7 +744,7 @@ TypeDecl::TypeDecl(const TypeDecl& other)
type = other.type;
attrs = other.attrs;
id = copy_string(other.id);
id = zeek::util::copy_string(other.id);
}
TypeDecl::~TypeDecl()
@ -821,7 +821,7 @@ int RecordType::FieldOffset(const char* field) const
loop_over_list(*types, i)
{
TypeDecl* td = (*types)[i];
if ( streq(td->id, field) )
if ( zeek::util::streq(td->id, field) )
return i;
}
@ -1045,7 +1045,7 @@ void RecordType::DescribeFieldsReST(ODesc* d, bool func_args) const
d->Add("<recursion>");
else
{
if ( num_fields == 1 && streq(td->id, "va_args") &&
if ( num_fields == 1 && zeek::util::streq(td->id, "va_args") &&
td->type->Tag() == TYPE_ANY )
// This was a BIF using variable argument list
d->Add("...");
@ -1122,11 +1122,11 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const
result = deprecation->DeprecationMessage();
if ( result.empty() )
return fmt("deprecated (%s%s$%s)", GetName().c_str(), has_check ? "?" : "",
FieldName(field));
return zeek::util::fmt("deprecated (%s%s$%s)", GetName().c_str(), has_check ? "?" : "",
FieldName(field));
else
return fmt("deprecated (%s%s$%s): %s", GetName().c_str(), has_check ? "?" : "",
FieldName(field), result.c_str());
return zeek::util::fmt("deprecated (%s%s$%s): %s", GetName().c_str(), has_check ? "?" : "",
FieldName(field), result.c_str());
}
return "";
@ -1182,7 +1182,7 @@ void OpaqueType::Describe(ODesc* d) const
void OpaqueType::DescribeReST(ODesc* d, bool roles_only) const
{
d->Add(fmt(":zeek:type:`%s` of %s", type_name(Tag()), name.c_str()));
d->Add(zeek::util::fmt(":zeek:type:`%s` of %s", type_name(Tag()), name.c_str()));
}
EnumType::EnumType(const string& name)
@ -1373,9 +1373,9 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const
d->PushIndent();
if ( roles_only )
d->Add(fmt(":zeek:enum:`%s`", it->second.c_str()));
d->Add(zeek::util::fmt(":zeek:enum:`%s`", it->second.c_str()));
else
d->Add(fmt(".. zeek:enum:: %s %s", it->second.c_str(), GetName().c_str()));
d->Add(zeek::util::fmt(".. zeek:enum:: %s %s", it->second.c_str(), GetName().c_str()));
using zeekygen::IdentifierInfo;
IdentifierInfo* doc = zeekygen_mgr->GetIdentifierInfo(it->second);
@ -1491,12 +1491,12 @@ void VectorType::Describe(ODesc* d) const
void VectorType::DescribeReST(ODesc* d, bool roles_only) const
{
d->Add(fmt(":zeek:type:`%s` of ", type_name(Tag())));
d->Add(zeek::util::fmt(":zeek:type:`%s` of ", type_name(Tag())));
if ( yield_type->GetName().empty() )
yield_type->DescribeReST(d, roles_only);
else
d->Add(fmt(":zeek:type:`%s`", yield_type->GetName().c_str()));
d->Add(zeek::util::fmt(":zeek:type:`%s`", yield_type->GetName().c_str()));
}
// Returns true if t1 is initialization-compatible with t2 (i.e., if an
@ -1628,7 +1628,7 @@ bool same_type(const Type& arg_t1, const Type& arg_t2,
const TypeDecl* td1 = rt1->FieldDecl(i);
const TypeDecl* td2 = rt2->FieldDecl(i);
if ( (match_record_field_names && ! streq(td1->id, td2->id)) ||
if ( (match_record_field_names && ! zeek::util::streq(td1->id, td2->id)) ||
! same_type(td1->type, td2->type, is_init, match_record_field_names) )
return false;
}
@ -1856,8 +1856,8 @@ TypePtr merge_types(const TypePtr& arg_t1,
// there creating clones of the type, so safer to compare name.
if ( t1->GetName() != t2->GetName() )
{
std::string msg = fmt("incompatible enum types: '%s' and '%s'",
t1->GetName().data(), t2->GetName().data());
std::string msg = zeek::util::fmt("incompatible enum types: '%s' and '%s'",
t1->GetName().data(), t2->GetName().data());
t1->Error(msg.data(), t2);
return nullptr;
@ -1875,10 +1875,10 @@ TypePtr merge_types(const TypePtr& arg_t1,
// actually see those changes from the redef.
return id->GetType();
std::string msg = fmt("incompatible enum types: '%s' and '%s'"
" ('%s' enum type ID is invalid)",
t1->GetName().data(), t2->GetName().data(),
t1->GetName().data());
std::string msg = zeek::util::fmt("incompatible enum types: '%s' and '%s'"
" ('%s' enum type ID is invalid)",
t1->GetName().data(), t2->GetName().data(),
t1->GetName().data());
t1->Error(msg.data(), t2);
return nullptr;
}
@ -1967,14 +1967,14 @@ TypePtr merge_types(const TypePtr& arg_t1,
const TypeDecl* td2 = rt2->FieldDecl(i);
auto tdl3_i = merge_types(td1->type, td2->type);
if ( ! streq(td1->id, td2->id) || ! tdl3_i )
if ( ! zeek::util::streq(td1->id, td2->id) || ! tdl3_i )
{
t1->Error("incompatible record fields", t2);
delete tdl3;
return nullptr;
}
tdl3->push_back(new TypeDecl(copy_string(td1->id), std::move(tdl3_i)));
tdl3->push_back(new TypeDecl(zeek::util::copy_string(td1->id), std::move(tdl3_i)));
}
return zeek::make_intrusive<RecordType>(tdl3);