Type: base_type() returns IntrusivePtr

This commit is contained in:
Max Kellermann 2020-03-03 19:03:45 +01:00
parent f0a357cadf
commit 6495193aae
16 changed files with 104 additions and 104 deletions

View file

@ -173,7 +173,7 @@ void DNS_Mgr_mapping_delete_func(void* v)
static TableVal* empty_addr_set() static TableVal* empty_addr_set()
{ {
IntrusivePtr<BroType> addr_t{AdoptRef{}, base_type(TYPE_ADDR)}; auto addr_t = base_type(TYPE_ADDR);
auto set_index = make_intrusive<TypeList>(addr_t); auto set_index = make_intrusive<TypeList>(addr_t);
set_index->Append(std::move(addr_t)); set_index->Append(std::move(addr_t));
auto s = make_intrusive<SetType>(std::move(set_index), nullptr); auto s = make_intrusive<SetType>(std::move(set_index), nullptr);

View file

@ -134,7 +134,7 @@ bool Expr::IsError() const
void Expr::SetError() void Expr::SetError()
{ {
SetType({AdoptRef{}, error_type()}); SetType(error_type());
} }
void Expr::SetError(const char* msg) void Expr::SetError(const char* msg)
@ -879,9 +879,9 @@ void BinaryExpr::PromoteType(TypeTag t, bool is_vector)
PromoteOps(t); PromoteOps(t);
if ( is_vector) if ( is_vector)
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(t)})); SetType(make_intrusive<VectorType>(base_type(t)));
else else
SetType(IntrusivePtr{AdoptRef{}, base_type(t)}); SetType(base_type(t));
} }
CloneExpr::CloneExpr(IntrusivePtr<Expr> arg_op) CloneExpr::CloneExpr(IntrusivePtr<Expr> arg_op)
@ -1015,7 +1015,7 @@ ComplementExpr::ComplementExpr(IntrusivePtr<Expr> arg_op)
if ( bt != TYPE_COUNT ) if ( bt != TYPE_COUNT )
ExprError("requires \"count\" operand"); ExprError("requires \"count\" operand");
else else
SetType({AdoptRef{}, base_type(TYPE_COUNT)}); SetType(base_type(TYPE_COUNT));
} }
IntrusivePtr<Val> ComplementExpr::Fold(Val* v) const IntrusivePtr<Val> ComplementExpr::Fold(Val* v) const
@ -1035,7 +1035,7 @@ NotExpr::NotExpr(IntrusivePtr<Expr> arg_op)
if ( ! IsIntegral(bt) && bt != TYPE_BOOL ) if ( ! IsIntegral(bt) && bt != TYPE_BOOL )
ExprError("requires an integral or boolean operand"); ExprError("requires an integral or boolean operand");
else else
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
} }
IntrusivePtr<Val> NotExpr::Fold(Val* v) const IntrusivePtr<Val> NotExpr::Fold(Val* v) const
@ -1059,7 +1059,7 @@ PosExpr::PosExpr(IntrusivePtr<Expr> arg_op)
if ( IsIntegral(bt) ) if ( IsIntegral(bt) )
// Promote count and counter to int. // Promote count and counter to int.
base_result_type = {AdoptRef{}, base_type(TYPE_INT)}; base_result_type = base_type(TYPE_INT);
else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE ) else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE )
base_result_type = {NewRef{}, t}; base_result_type = {NewRef{}, t};
else else
@ -1097,7 +1097,7 @@ NegExpr::NegExpr(IntrusivePtr<Expr> arg_op)
if ( IsIntegral(bt) ) if ( IsIntegral(bt) )
// Promote count and counter to int. // Promote count and counter to int.
base_result_type = {AdoptRef{}, base_type(TYPE_INT)}; base_result_type = base_type(TYPE_INT);
else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE ) else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE )
base_result_type = {NewRef{}, t}; base_result_type = {NewRef{}, t};
else else
@ -1126,9 +1126,9 @@ SizeExpr::SizeExpr(IntrusivePtr<Expr> arg_op)
return; return;
if ( op->Type()->InternalType() == TYPE_INTERNAL_DOUBLE ) if ( op->Type()->InternalType() == TYPE_INTERNAL_DOUBLE )
SetType({AdoptRef{}, base_type(TYPE_DOUBLE)}); SetType(base_type(TYPE_DOUBLE));
else else
SetType({AdoptRef{}, base_type(TYPE_COUNT)}); SetType(base_type(TYPE_COUNT));
} }
IntrusivePtr<Val> SizeExpr::Eval(Frame* f) const IntrusivePtr<Val> SizeExpr::Eval(Frame* f) const
@ -1165,15 +1165,15 @@ AddExpr::AddExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
IntrusivePtr<BroType> base_result_type; IntrusivePtr<BroType> base_result_type;
if ( bt1 == TYPE_TIME && bt2 == TYPE_INTERVAL ) if ( bt1 == TYPE_TIME && bt2 == TYPE_INTERVAL )
base_result_type = {AdoptRef{}, base_type(bt1)}; base_result_type = base_type(bt1);
else if ( bt2 == TYPE_TIME && bt1 == TYPE_INTERVAL ) else if ( bt2 == TYPE_TIME && bt1 == TYPE_INTERVAL )
base_result_type = {AdoptRef{}, base_type(bt2)}; base_result_type = base_type(bt2);
else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL ) else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL )
base_result_type = {AdoptRef{}, base_type(bt1)}; base_result_type = base_type(bt1);
else if ( BothArithmetic(bt1, bt2) ) else if ( BothArithmetic(bt1, bt2) )
PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get()));
else if ( BothString(bt1, bt2) ) else if ( BothString(bt1, bt2) )
base_result_type = {AdoptRef{}, base_type(bt1)}; base_result_type = base_type(bt1);
else else
ExprError("requires arithmetic operands"); ExprError("requires arithmetic operands");
@ -1209,9 +1209,9 @@ AddToExpr::AddToExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
if ( BothArithmetic(bt1, bt2) ) if ( BothArithmetic(bt1, bt2) )
PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get()));
else if ( BothString(bt1, bt2) ) else if ( BothString(bt1, bt2) )
SetType({AdoptRef{}, base_type(bt1)}); SetType(base_type(bt1));
else if ( BothInterval(bt1, bt2) ) else if ( BothInterval(bt1, bt2) )
SetType({AdoptRef{}, base_type(bt1)}); SetType(base_type(bt1));
else if ( IsVector(bt1) ) else if ( IsVector(bt1) )
{ {
@ -1296,13 +1296,13 @@ SubExpr::SubExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
IntrusivePtr<BroType> base_result_type; IntrusivePtr<BroType> base_result_type;
if ( bt1 == TYPE_TIME && bt2 == TYPE_INTERVAL ) if ( bt1 == TYPE_TIME && bt2 == TYPE_INTERVAL )
base_result_type = {AdoptRef{}, base_type(bt1)}; base_result_type = base_type(bt1);
else if ( bt1 == TYPE_TIME && bt2 == TYPE_TIME ) else if ( bt1 == TYPE_TIME && bt2 == TYPE_TIME )
SetType({AdoptRef{}, base_type(TYPE_INTERVAL)}); SetType(base_type(TYPE_INTERVAL));
else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL ) else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL )
base_result_type = {AdoptRef{}, base_type(bt1)}; base_result_type = base_type(bt1);
else if ( t1->IsSet() && t2->IsSet() ) else if ( t1->IsSet() && t2->IsSet() )
{ {
@ -1340,7 +1340,7 @@ RemoveFromExpr::RemoveFromExpr(IntrusivePtr<Expr> arg_op1,
if ( BothArithmetic(bt1, bt2) ) if ( BothArithmetic(bt1, bt2) )
PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get()));
else if ( BothInterval(bt1, bt2) ) else if ( BothInterval(bt1, bt2) )
SetType({AdoptRef{}, base_type(bt1)}); SetType(base_type(bt1));
else else
ExprError("requires two arithmetic operands"); ExprError("requires two arithmetic operands");
} }
@ -1430,9 +1430,9 @@ DivideExpr::DivideExpr(IntrusivePtr<Expr> arg_op1,
else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL ) else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL )
{ {
if ( is_vector(op1.get()) || is_vector(op2.get()) ) if ( is_vector(op1.get()) || is_vector(op2.get()) )
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(TYPE_DOUBLE)})); SetType(make_intrusive<VectorType>(base_type(TYPE_DOUBLE)));
else else
SetType({AdoptRef{}, base_type(TYPE_DOUBLE)}); SetType(base_type(TYPE_DOUBLE));
} }
else else
ExprError("division of interval requires arithmetic operand"); ExprError("division of interval requires arithmetic operand");
@ -1443,7 +1443,7 @@ DivideExpr::DivideExpr(IntrusivePtr<Expr> arg_op1,
else if ( bt1 == TYPE_ADDR && ! is_vector(op2.get()) && else if ( bt1 == TYPE_ADDR && ! is_vector(op2.get()) &&
(bt2 == TYPE_COUNT || bt2 == TYPE_INT) ) (bt2 == TYPE_COUNT || bt2 == TYPE_INT) )
SetType({AdoptRef{}, base_type(TYPE_SUBNET)}); SetType(base_type(TYPE_SUBNET));
else else
ExprError("requires arithmetic operands"); ExprError("requires arithmetic operands");
@ -1519,10 +1519,10 @@ BoolExpr::BoolExpr(BroExprTag arg_tag,
{ {
if ( ! (is_vector(op1.get()) && is_vector(op2.get())) ) if ( ! (is_vector(op1.get()) && is_vector(op2.get())) )
reporter->Warning("mixing vector and scalar operands is deprecated"); reporter->Warning("mixing vector and scalar operands is deprecated");
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(TYPE_BOOL)})); SetType(make_intrusive<VectorType>(base_type(TYPE_BOOL)));
} }
else else
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
} }
else else
ExprError("requires boolean operands"); ExprError("requires boolean operands");
@ -1669,9 +1669,9 @@ BitExpr::BitExpr(BroExprTag arg_tag,
if ( bt1 == TYPE_COUNTER && bt2 == TYPE_COUNTER ) if ( bt1 == TYPE_COUNTER && bt2 == TYPE_COUNTER )
ExprError("cannot apply a bitwise operator to two \"counter\" operands"); ExprError("cannot apply a bitwise operator to two \"counter\" operands");
else if ( is_vector(op1.get()) || is_vector(op2.get()) ) else if ( is_vector(op1.get()) || is_vector(op2.get()) )
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(TYPE_COUNT)})); SetType(make_intrusive<VectorType>(base_type(TYPE_COUNT)));
else else
SetType({AdoptRef{}, base_type(TYPE_COUNT)}); SetType(base_type(TYPE_COUNT));
} }
else if ( bt1 == TYPE_PATTERN ) else if ( bt1 == TYPE_PATTERN )
@ -1681,7 +1681,7 @@ BitExpr::BitExpr(BroExprTag arg_tag,
else if ( tag == EXPR_XOR ) else if ( tag == EXPR_XOR )
ExprError("'^' operator does not apply to patterns"); ExprError("'^' operator does not apply to patterns");
else else
SetType({AdoptRef{}, base_type(TYPE_PATTERN)}); SetType(base_type(TYPE_PATTERN));
} }
else if ( t1->IsSet() && t2->IsSet() ) else if ( t1->IsSet() && t2->IsSet() )
@ -1717,9 +1717,9 @@ EqExpr::EqExpr(BroExprTag arg_tag,
bt2 = t2->AsVectorType()->YieldType()->Tag(); bt2 = t2->AsVectorType()->YieldType()->Tag();
if ( is_vector(op1.get()) || is_vector(op2.get()) ) if ( is_vector(op1.get()) || is_vector(op2.get()) )
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(TYPE_BOOL)})); SetType(make_intrusive<VectorType>(base_type(TYPE_BOOL)));
else else
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
if ( BothArithmetic(bt1, bt2) ) if ( BothArithmetic(bt1, bt2) )
PromoteOps(max_type(bt1, bt2)); PromoteOps(max_type(bt1, bt2));
@ -1819,9 +1819,9 @@ RelExpr::RelExpr(BroExprTag arg_tag,
bt2 = t2->AsVectorType()->YieldType()->Tag(); bt2 = t2->AsVectorType()->YieldType()->Tag();
if ( is_vector(op1.get()) || is_vector(op2.get()) ) if ( is_vector(op1.get()) || is_vector(op2.get()) )
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(TYPE_BOOL)})); SetType(make_intrusive<VectorType>(base_type(TYPE_BOOL)));
else else
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
if ( BothArithmetic(bt1, bt2) ) if ( BothArithmetic(bt1, bt2) )
PromoteOps(max_type(bt1, bt2)); PromoteOps(max_type(bt1, bt2));
@ -1899,9 +1899,9 @@ CondExpr::CondExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2,
op3 = make_intrusive<ArithCoerceExpr>(std::move(op3), t); op3 = make_intrusive<ArithCoerceExpr>(std::move(op3), t);
if ( is_vector(op2.get()) ) if ( is_vector(op2.get()) )
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(t)})); SetType(make_intrusive<VectorType>(base_type(t)));
else else
SetType({AdoptRef{}, base_type(t)}); SetType(base_type(t));
} }
else if ( bt2 != bt3 ) else if ( bt2 != bt3 )
@ -2511,13 +2511,13 @@ IndexExpr::IndexExpr(IntrusivePtr<Expr> arg_op1,
else if ( ! op1->Type()->YieldType() ) else if ( ! op1->Type()->YieldType() )
{ {
if ( IsString(op1->Type()->Tag()) && match_type == MATCHES_INDEX_SCALAR ) if ( IsString(op1->Type()->Tag()) && match_type == MATCHES_INDEX_SCALAR )
SetType({AdoptRef{}, base_type(TYPE_STRING)}); SetType(base_type(TYPE_STRING));
else else
// It's a set - so indexing it yields void. We don't // It's a set - so indexing it yields void. We don't
// directly generate an error message, though, since this // directly generate an error message, though, since this
// expression might be part of an add/delete statement, // expression might be part of an add/delete statement,
// rather than yielding a value. // rather than yielding a value.
SetType({AdoptRef{}, base_type(TYPE_VOID)}); SetType(base_type(TYPE_VOID));
} }
else if ( match_type == MATCHES_INDEX_SCALAR ) else if ( match_type == MATCHES_INDEX_SCALAR )
@ -2982,7 +2982,7 @@ HasFieldExpr::HasFieldExpr(IntrusivePtr<Expr> arg_op,
else if ( rt->IsFieldDeprecated(field) ) else if ( rt->IsFieldDeprecated(field) )
reporter->Warning("%s", rt->GetFieldDeprecationWarning(field, true).c_str()); reporter->Warning("%s", rt->GetFieldDeprecationWarning(field, true).c_str());
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
} }
} }
@ -3109,7 +3109,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr<ListExpr> constructor_li
else else
{ {
if ( op->AsListExpr()->Exprs().empty() ) if ( op->AsListExpr()->Exprs().empty() )
SetType(make_intrusive<TableType>(make_intrusive<TypeList>(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr)); SetType(make_intrusive<TableType>(make_intrusive<TypeList>(base_type(TYPE_ANY)), nullptr));
else else
{ {
SetType(init_type(op.get())); SetType(init_type(op.get()));
@ -3223,7 +3223,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
else else
{ {
if ( op->AsListExpr()->Exprs().empty() ) if ( op->AsListExpr()->Exprs().empty() )
SetType(make_intrusive<::SetType>(make_intrusive<TypeList>(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr)); SetType(make_intrusive<::SetType>(make_intrusive<TypeList>(base_type(TYPE_ANY)), nullptr));
else else
SetType(init_type(op.get())); SetType(init_type(op.get()));
} }
@ -3343,7 +3343,7 @@ VectorConstructorExpr::VectorConstructorExpr(IntrusivePtr<ListExpr> constructor_
// vector(). // vector().
// By default, assign VOID type here. A vector with // By default, assign VOID type here. A vector with
// void type set is seen as an unspecified vector. // void type set is seen as an unspecified vector.
SetType(make_intrusive<::VectorType>(IntrusivePtr{AdoptRef{}, base_type(TYPE_VOID)})); SetType(make_intrusive<::VectorType>(base_type(TYPE_VOID)));
return; return;
} }
@ -3479,11 +3479,11 @@ ArithCoerceExpr::ArithCoerceExpr(IntrusivePtr<Expr> arg_op, TypeTag t)
if ( IsVector(bt) ) if ( IsVector(bt) )
{ {
SetType(make_intrusive<VectorType>(IntrusivePtr{AdoptRef{}, base_type(t)})); SetType(make_intrusive<VectorType>(base_type(t)));
vbt = op->Type()->AsVectorType()->YieldType()->Tag(); vbt = op->Type()->AsVectorType()->YieldType()->Tag();
} }
else else
SetType({AdoptRef{}, base_type(t)}); SetType(base_type(t));
if ( (bt == TYPE_ENUM) != (t == TYPE_ENUM) ) if ( (bt == TYPE_ENUM) != (t == TYPE_ENUM) )
ExprError("can't convert to/from enumerated type"); ExprError("can't convert to/from enumerated type");
@ -3903,7 +3903,7 @@ ScheduleExpr::ScheduleExpr(IntrusivePtr<Expr> arg_when,
if ( bt != TYPE_TIME && bt != TYPE_INTERVAL ) if ( bt != TYPE_TIME && bt != TYPE_INTERVAL )
ExprError("schedule expression requires a time or time interval"); ExprError("schedule expression requires a time or time interval");
else else
SetType({AdoptRef{}, base_type(TYPE_TIMER)}); SetType(base_type(TYPE_TIMER));
} }
bool ScheduleExpr::IsPure() const bool ScheduleExpr::IsPure() const
@ -3990,7 +3990,7 @@ InExpr::InExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
SetError(); SetError();
} }
else else
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
} }
else if ( op1->Type()->Tag() == TYPE_RECORD ) else if ( op1->Type()->Tag() == TYPE_RECORD )
@ -4013,13 +4013,13 @@ InExpr::InExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
SetError(); SetError();
} }
else else
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
} }
} }
else if ( op1->Type()->Tag() == TYPE_STRING && else if ( op1->Type()->Tag() == TYPE_STRING &&
op2->Type()->Tag() == TYPE_STRING ) op2->Type()->Tag() == TYPE_STRING )
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
else else
{ {
@ -4030,14 +4030,14 @@ InExpr::InExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
{ {
if ( op2->Type()->Tag() == TYPE_SUBNET ) if ( op2->Type()->Tag() == TYPE_SUBNET )
{ {
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
return; return;
} }
if ( op2->Type()->Tag() == TYPE_TABLE && if ( op2->Type()->Tag() == TYPE_TABLE &&
op2->Type()->AsTableType()->IsSubNetIndex() ) op2->Type()->AsTableType()->IsSubNetIndex() )
{ {
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
return; return;
} }
} }
@ -4050,7 +4050,7 @@ InExpr::InExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
if ( ! op2->Type()->MatchesIndex(lop1) ) if ( ! op2->Type()->MatchesIndex(lop1) )
SetError("not an index type"); SetError("not an index type");
else else
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
} }
} }
@ -4935,7 +4935,7 @@ void CastExpr::ExprDescribe(ODesc* d) const
IsExpr::IsExpr(IntrusivePtr<Expr> arg_op, IntrusivePtr<BroType> arg_t) IsExpr::IsExpr(IntrusivePtr<Expr> arg_op, IntrusivePtr<BroType> arg_t)
: UnaryExpr(EXPR_IS, std::move(arg_op)), t(std::move(arg_t)) : UnaryExpr(EXPR_IS, std::move(arg_op)), t(std::move(arg_t))
{ {
SetType({AdoptRef{}, base_type(TYPE_BOOL)}); SetType(base_type(TYPE_BOOL));
} }
IntrusivePtr<Val> IsExpr::Fold(Val* v) const IntrusivePtr<Val> IsExpr::Fold(Val* v) const

View file

@ -57,7 +57,7 @@ BroFile::BroFile(FILE* arg_f)
Init(); Init();
f = arg_f; f = arg_f;
name = access = 0; name = access = 0;
t = base_type(TYPE_STRING); t = base_type(TYPE_STRING).release();
is_open = (f != 0); is_open = (f != 0);
} }
@ -67,7 +67,7 @@ BroFile::BroFile(FILE* arg_f, const char* arg_name, const char* arg_access)
f = arg_f; f = arg_f;
name = copy_string(arg_name); name = copy_string(arg_name);
access = copy_string(arg_access); access = copy_string(arg_access);
t = base_type(TYPE_STRING); t = base_type(TYPE_STRING).release();
is_open = (f != 0); is_open = (f != 0);
} }
@ -77,7 +77,7 @@ BroFile::BroFile(const char* arg_name, const char* arg_access, BroType* arg_t)
f = 0; f = 0;
name = copy_string(arg_name); name = copy_string(arg_name);
access = copy_string(arg_access); access = copy_string(arg_access);
t = arg_t ? arg_t : base_type(TYPE_STRING); t = arg_t ? arg_t : base_type(TYPE_STRING).release();
if ( streq(name, "/dev/stdin") ) if ( streq(name, "/dev/stdin") )
f = stdin; f = stdin;

View file

@ -314,7 +314,7 @@ TraversalCode ID::Traverse(TraversalCallback* cb) const
void ID::Error(const char* msg, const BroObj* o2) void ID::Error(const char* msg, const BroObj* o2)
{ {
BroObj::Error(msg, o2, 1); BroObj::Error(msg, o2, 1);
SetType({AdoptRef{}, error_type()}); SetType(error_type());
} }
void ID::Describe(ODesc* d) const void ID::Describe(ODesc* d) const

View file

@ -143,7 +143,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
if ( ! tag ) if ( ! tag )
return nullptr; return nullptr;
return base_type(static_cast<TypeTag>(*tag)); return base_type(static_cast<TypeTag>(*tag)).release();
} }
IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state) IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state)

View file

@ -146,7 +146,7 @@ RuleConditionEval::RuleConditionEval(const char* func)
TypeList tl; TypeList tl;
tl.Append({NewRef{}, internal_type("signature_state")}); tl.Append({NewRef{}, internal_type("signature_state")});
tl.Append({AdoptRef{}, base_type(TYPE_STRING)}); tl.Append(base_type(TYPE_STRING));
if ( ! f->CheckArgs(tl.Types()) ) if ( ! f->CheckArgs(tl.Types()) )
rules_error("eval function parameters must be a 'signature_state' " rules_error("eval function parameters must be a 'signature_state' "

View file

@ -1114,7 +1114,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
BroType* t = (*loop_vars)[0]->Type(); BroType* t = (*loop_vars)[0]->Type();
if ( ! t ) if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, {AdoptRef{}, base_type(TYPE_COUNT)}, add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT),
INIT_NONE, 0, 0, VAR_REGULAR); INIT_NONE, 0, 0, VAR_REGULAR);
else if ( ! IsIntegral(t->Tag()) ) else if ( ! IsIntegral(t->Tag()) )
@ -1135,7 +1135,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
BroType* t = (*loop_vars)[0]->Type(); BroType* t = (*loop_vars)[0]->Type();
if ( ! t ) if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, add_local({NewRef{}, (*loop_vars)[0]},
{AdoptRef{}, base_type(TYPE_STRING)}, base_type(TYPE_STRING),
INIT_NONE, 0, 0, VAR_REGULAR); INIT_NONE, 0, 0, VAR_REGULAR);
else if ( t->Tag() != TYPE_STRING ) else if ( t->Tag() != TYPE_STRING )

View file

@ -100,7 +100,7 @@ int BroType::MatchesIndex(ListExpr* const index) const
if ( index->Exprs().length() != 1 && index->Exprs().length() != 2 ) if ( index->Exprs().length() != 1 && index->Exprs().length() != 2 )
return DOES_NOT_MATCH_INDEX; return DOES_NOT_MATCH_INDEX;
if ( check_and_promote_exprs_to_type(index, ::base_type(TYPE_INT)) ) if ( check_and_promote_exprs_to_type(index, ::base_type(TYPE_INT).get()) )
return MATCHES_INDEX_SCALAR; return MATCHES_INDEX_SCALAR;
} }
@ -1307,10 +1307,10 @@ BroType* VectorType::YieldType()
// comparisions. // comparisions.
if ( IsUnspecifiedVector() ) if ( IsUnspecifiedVector() )
{ {
BroType* ret = ::base_type(TYPE_ANY); auto ret = ::base_type(TYPE_ANY);
Unref(ret); // unref, because this won't be held by anyone.
assert(ret); assert(ret);
return ret; // release, because this won't be held by anyone.
return ret.release();
} }
return yield_type.get(); return yield_type.get();
@ -1324,10 +1324,10 @@ const BroType* VectorType::YieldType() const
// comparisions. // comparisions.
if ( IsUnspecifiedVector() ) if ( IsUnspecifiedVector() )
{ {
BroType* ret = ::base_type(TYPE_ANY); auto ret = ::base_type(TYPE_ANY);
Unref(ret); // unref, because this won't be held by anyone.
assert(ret); assert(ret);
return ret; // release, because this won't be held by anyone.
return ret.release();
} }
return yield_type.get(); return yield_type.get();
@ -1711,7 +1711,7 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2)
TypeTag tg2 = t2->Tag(); TypeTag tg2 = t2->Tag();
if ( BothArithmetic(tg1, tg2) ) if ( BothArithmetic(tg1, tg2) )
return {AdoptRef{}, base_type(max_type(tg1, tg2))}; return base_type(max_type(tg1, tg2));
if ( tg1 != tg2 ) if ( tg1 != tg2 )
{ {
@ -1731,7 +1731,7 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2)
case TYPE_BOOL: case TYPE_BOOL:
case TYPE_ANY: case TYPE_ANY:
case TYPE_ERROR: case TYPE_ERROR:
return {AdoptRef{}, base_type(tg1)}; return base_type(tg1);
case TYPE_ENUM: case TYPE_ENUM:
{ {

View file

@ -687,11 +687,11 @@ BroType* base_type_no_ref(TypeTag tag);
// Returns the basic (non-parameterized) type with the given type. // Returns the basic (non-parameterized) type with the given type.
// The caller assumes responsibility for a reference to the type. // The caller assumes responsibility for a reference to the type.
inline BroType* base_type(TypeTag tag) inline IntrusivePtr<BroType> base_type(TypeTag tag)
{ return base_type_no_ref(tag)->Ref(); } { return {NewRef{}, base_type_no_ref(tag)}; }
// Returns the basic error type. // Returns the basic error type.
inline BroType* error_type() { return base_type(TYPE_ERROR); } inline IntrusivePtr<BroType> error_type() { return base_type(TYPE_ERROR); }
// True if the two types are equivalent. If is_init is true then the test is // True if the two types are equivalent. If is_init is true then the test is
// done in the context of an initialization. If match_record_field_names is // done in the context of an initialization. If match_record_field_names is

View file

@ -49,7 +49,7 @@ static FileType* GetStringFileType() noexcept
{ {
static FileType* string_file_type = 0; static FileType* string_file_type = 0;
if ( ! string_file_type ) if ( ! string_file_type )
string_file_type = new FileType({AdoptRef{}, base_type(TYPE_STRING)}); string_file_type = new FileType(base_type(TYPE_STRING));
return string_file_type; return string_file_type;
} }
@ -1125,7 +1125,7 @@ IntrusivePtr<Val> StringVal::DoClone(CloneState* state)
val.string_val->Len(), 1))); val.string_val->Len(), 1)));
} }
PatternVal::PatternVal(RE_Matcher* re) : Val(base_type(TYPE_PATTERN)) PatternVal::PatternVal(RE_Matcher* re) : Val(base_type(TYPE_PATTERN).release())
{ {
val.re_val = re; val.re_val = re;
} }
@ -1185,7 +1185,7 @@ IntrusivePtr<Val> PatternVal::DoClone(CloneState* state)
} }
ListVal::ListVal(TypeTag t) ListVal::ListVal(TypeTag t)
: Val(new TypeList({NewRef{}, t == TYPE_ANY ? 0 : base_type_no_ref(t)})) : Val(new TypeList(t == TYPE_ANY ? nullptr : base_type(t)))
{ {
tag = t; tag = t;
} }
@ -1235,7 +1235,7 @@ TableVal* ListVal::ConvertToSet() const
Internal("conversion of heterogeneous list to set"); Internal("conversion of heterogeneous list to set");
auto set_index = make_intrusive<TypeList>(IntrusivePtr{NewRef{}, type->AsTypeList()->PureType()}); auto set_index = make_intrusive<TypeList>(IntrusivePtr{NewRef{}, type->AsTypeList()->PureType()});
set_index->Append({AdoptRef{}, base_type(tag)}); set_index->Append(base_type(tag));
auto s = make_intrusive<SetType>(std::move(set_index), nullptr); auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
TableVal* t = new TableVal(std::move(s)); TableVal* t = new TableVal(std::move(s));

View file

@ -129,7 +129,7 @@ union BroValUnion {
class Val : public BroObj { class Val : public BroObj {
public: public:
Val(double d, TypeTag t) Val(double d, TypeTag t)
: val(d), type(base_type(t)) : val(d), type(base_type(t).release())
{ {
} }
@ -146,7 +146,7 @@ public:
} }
Val() Val()
: val(bro_int_t(0)), type(base_type(TYPE_ERROR)) : val(bro_int_t(0)), type(base_type(TYPE_ERROR).release())
{ {
} }
@ -355,7 +355,7 @@ protected:
template<typename V> template<typename V>
Val(V &&v, TypeTag t) noexcept Val(V &&v, TypeTag t) noexcept
: val(std::forward<V>(v)), type(base_type(t)) : val(std::forward<V>(v)), type(base_type(t).release())
{ {
} }

View file

@ -106,7 +106,7 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
t = init_type(init.get()); t = init_type(init.get());
if ( ! t ) if ( ! t )
{ {
id->SetType({AdoptRef{}, error_type()}); id->SetType(error_type());
return; return;
} }
} }

View file

@ -38,7 +38,7 @@
VectorVal* create_vector_of_count() VectorVal* create_vector_of_count()
{ {
VectorType* vt = new VectorType({AdoptRef{}, base_type(TYPE_COUNT)}); VectorType* vt = new VectorType(base_type(TYPE_COUNT));
VectorVal* vv = new VectorVal(vt); VectorVal* vv = new VectorVal(vt);
Unref(vt); Unref(vt);
return vv; return vv;

View file

@ -271,7 +271,7 @@ RecordVal* MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n,
auth_flavors_count = max_auth_flavors; auth_flavors_count = max_auth_flavors;
} }
VectorType* enum_vector = new VectorType({AdoptRef{}, base_type(TYPE_ENUM)}); VectorType* enum_vector = new VectorType(base_type(TYPE_ENUM));
VectorVal* auth_flavors = new VectorVal(enum_vector); VectorVal* auth_flavors = new VectorVal(enum_vector);
Unref(enum_vector); Unref(enum_vector);

View file

@ -2555,7 +2555,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
index_type = {NewRef{}, enum_id->Type()->AsEnumType()}; index_type = {NewRef{}, enum_id->Type()->AsEnumType()};
} }
else else
index_type = {NewRef{}, base_type_no_ref(stag)}; index_type = base_type(stag);
set_index = make_intrusive<TypeList>(index_type); set_index = make_intrusive<TypeList>(index_type);
set_index->Append(std::move(index_type)); set_index->Append(std::move(index_type));
@ -2579,14 +2579,14 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
BroType* type; BroType* type;
if ( val->val.vector_val.size == 0 && val->subtype == TYPE_VOID ) if ( val->val.vector_val.size == 0 && val->subtype == TYPE_VOID )
// don't know type - unspecified table. // don't know type - unspecified table.
type = base_type(TYPE_ANY); type = base_type(TYPE_ANY).release();
else else
{ {
// all entries have to have the same type... // all entries have to have the same type...
if ( val->subtype == TYPE_VOID ) if ( val->subtype == TYPE_VOID )
type = base_type(val->val.vector_val.vals[0]->type); type = base_type(val->val.vector_val.vals[0]->type).release();
else else
type = base_type(val->subtype); type = base_type(val->subtype).release();
} }
VectorType* vt = new VectorType({NewRef{}, type}); VectorType* vt = new VectorType({NewRef{}, type});

View file

@ -702,7 +702,7 @@ expr:
if ( ! id->Type() ) if ( ! id->Type() )
{ {
id->Error("undeclared variable"); id->Error("undeclared variable");
id->SetType({AdoptRef{}, error_type()}); id->SetType(error_type());
$$ = new NameExpr(std::move(id)); $$ = new NameExpr(std::move(id));
} }
@ -844,72 +844,72 @@ enum_body_elem:
type: type:
TOK_BOOL { TOK_BOOL {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_BOOL); $$ = base_type(TYPE_BOOL).release();
} }
| TOK_INT { | TOK_INT {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_INT); $$ = base_type(TYPE_INT).release();
} }
| TOK_COUNT { | TOK_COUNT {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_COUNT); $$ = base_type(TYPE_COUNT).release();
} }
| TOK_COUNTER { | TOK_COUNTER {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_COUNTER); $$ = base_type(TYPE_COUNTER).release();
} }
| TOK_DOUBLE { | TOK_DOUBLE {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_DOUBLE); $$ = base_type(TYPE_DOUBLE).release();
} }
| TOK_TIME { | TOK_TIME {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_TIME); $$ = base_type(TYPE_TIME).release();
} }
| TOK_INTERVAL { | TOK_INTERVAL {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_INTERVAL); $$ = base_type(TYPE_INTERVAL).release();
} }
| TOK_STRING { | TOK_STRING {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_STRING); $$ = base_type(TYPE_STRING).release();
} }
| TOK_PATTERN { | TOK_PATTERN {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_PATTERN); $$ = base_type(TYPE_PATTERN).release();
} }
| TOK_TIMER { | TOK_TIMER {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_TIMER); $$ = base_type(TYPE_TIMER).release();
} }
| TOK_PORT { | TOK_PORT {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_PORT); $$ = base_type(TYPE_PORT).release();
} }
| TOK_ADDR { | TOK_ADDR {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_ADDR); $$ = base_type(TYPE_ADDR).release();
} }
| TOK_SUBNET { | TOK_SUBNET {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_SUBNET); $$ = base_type(TYPE_SUBNET).release();
} }
| TOK_ANY { | TOK_ANY {
set_location(@1); set_location(@1);
$$ = base_type(TYPE_ANY); $$ = base_type(TYPE_ANY).release();
} }
| TOK_TABLE '[' type_list ']' TOK_OF type | TOK_TABLE '[' type_list ']' TOK_OF type
@ -985,7 +985,7 @@ type:
| TOK_HOOK '(' formal_args ')' | TOK_HOOK '(' formal_args ')'
{ {
set_location(@1, @3); set_location(@1, @3);
$$ = new FuncType({AdoptRef{}, $3}, {AdoptRef{}, base_type(TYPE_BOOL)}, FUNC_FLAVOR_HOOK); $$ = new FuncType({AdoptRef{}, $3}, base_type(TYPE_BOOL), FUNC_FLAVOR_HOOK);
} }
| TOK_FILE TOK_OF type | TOK_FILE TOK_OF type
@ -997,7 +997,7 @@ type:
| TOK_FILE | TOK_FILE
{ {
set_location(@1); set_location(@1);
$$ = new FileType({AdoptRef{}, base_type(TYPE_STRING)}); $$ = new FileType(base_type(TYPE_STRING));
} }
| TOK_OPAQUE TOK_OF TOK_ID | TOK_OPAQUE TOK_OF TOK_ID
@ -1013,7 +1013,7 @@ type:
NullStmt here; NullStmt here;
if ( $1 ) if ( $1 )
$1->Error("not a Zeek type", &here); $1->Error("not a Zeek type", &here);
$$ = error_type(); $$ = error_type().release();
} }
else else
{ {
@ -1204,7 +1204,7 @@ func_hdr:
| TOK_HOOK def_global_id func_params opt_attr | TOK_HOOK def_global_id func_params opt_attr
{ {
$3->ClearYieldType(FUNC_FLAVOR_HOOK); $3->ClearYieldType(FUNC_FLAVOR_HOOK);
$3->SetYieldType({AdoptRef{}, base_type(TYPE_BOOL)}); $3->SetYieldType(base_type(TYPE_BOOL));
begin_func($2, current_module.c_str(), begin_func($2, current_module.c_str(),
FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3}, $4); FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3}, $4);
$$ = $3; $$ = $3;
@ -1280,7 +1280,7 @@ func_params:
'(' formal_args ')' ':' type '(' formal_args ')' ':' type
{ $$ = new FuncType({AdoptRef{}, $2}, {AdoptRef{}, $5}, FUNC_FLAVOR_FUNCTION); } { $$ = new FuncType({AdoptRef{}, $2}, {AdoptRef{}, $5}, FUNC_FLAVOR_FUNCTION); }
| '(' formal_args ')' | '(' formal_args ')'
{ $$ = new FuncType({AdoptRef{}, $2}, {AdoptRef{}, base_type(TYPE_VOID)}, FUNC_FLAVOR_FUNCTION); } { $$ = new FuncType({AdoptRef{}, $2}, base_type(TYPE_VOID), FUNC_FLAVOR_FUNCTION); }
; ;
opt_type: opt_type: