Type: init_type() returns IntrusivePtr

This commit is contained in:
Max Kellermann 2020-03-03 19:01:54 +01:00
parent cf11d78483
commit f0a357cadf
4 changed files with 10 additions and 10 deletions

View file

@ -3112,7 +3112,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr<ListExpr> constructor_li
SetType(make_intrusive<TableType>(make_intrusive<TypeList>(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr)); SetType(make_intrusive<TableType>(make_intrusive<TypeList>(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr));
else else
{ {
SetType({AdoptRef{}, init_type(op.get())}); SetType(init_type(op.get()));
if ( ! type ) if ( ! type )
SetError(); SetError();
@ -3225,7 +3225,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
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>(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr));
else else
SetType({AdoptRef{}, init_type(op.get())}); SetType(init_type(op.get()));
} }
if ( ! type ) if ( ! type )

View file

@ -1983,7 +1983,7 @@ static BroType* reduce_type(BroType* t)
return t; return t;
} }
BroType* init_type(Expr* init) IntrusivePtr<BroType> init_type(Expr* init)
{ {
if ( init->Tag() != EXPR_LIST ) if ( init->Tag() != EXPR_LIST )
{ {
@ -1999,7 +1999,7 @@ BroType* init_type(Expr* init)
return nullptr; return nullptr;
} }
return t.release(); return t;
} }
ListExpr* init_list = init->AsListExpr(); ListExpr* init_list = init->AsListExpr();
@ -2017,7 +2017,7 @@ BroType* init_type(Expr* init)
if ( e0->IsRecordElement(0) ) if ( e0->IsRecordElement(0) )
// ListExpr's know how to build a record from their // ListExpr's know how to build a record from their
// components. // components.
return init_list->InitType().release(); return init_list->InitType();
auto t = e0->InitType(); auto t = e0->InitType();
@ -2049,7 +2049,7 @@ BroType* init_type(Expr* init)
if ( t->Tag() == TYPE_TABLE && ! t->AsTableType()->IsSet() ) if ( t->Tag() == TYPE_TABLE && ! t->AsTableType()->IsSet() )
// A list of table elements. // A list of table elements.
return t.release(); return t;
// A set. If the index type isn't yet a type list, make // A set. If the index type isn't yet a type list, make
// it one, as that's what's required for creating a set type. // it one, as that's what's required for creating a set type.
@ -2060,7 +2060,7 @@ BroType* init_type(Expr* init)
t = std::move(tl); t = std::move(tl);
} }
return new SetType({AdoptRef{}, t.release()->AsTypeList()}, nullptr); return make_intrusive<SetType>(IntrusivePtr{AdoptRef{}, t.release()->AsTypeList()}, nullptr);
} }
bool is_atomic_type(const BroType* t) bool is_atomic_type(const BroType* t)

View file

@ -725,7 +725,7 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2);
IntrusivePtr<BroType> merge_type_list(ListExpr* elements); IntrusivePtr<BroType> merge_type_list(ListExpr* elements);
// Given an expression, infer its type when used for an initialization. // Given an expression, infer its type when used for an initialization.
extern BroType* init_type(Expr* init); IntrusivePtr<BroType> init_type(Expr* init);
// Returns true if argument is an atomic type. // Returns true if argument is an atomic type.
bool is_atomic_type(const BroType* t); bool is_atomic_type(const BroType* t);

View file

@ -64,7 +64,7 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
if ( id->Type() && id->Type()->Tag() != TYPE_ERROR ) if ( id->Type() && id->Type()->Tag() != TYPE_ERROR )
{ {
if ( dt != VAR_REDEF && if ( dt != VAR_REDEF &&
(! init || ! do_init || (! t && ! (t = {AdoptRef{}, init_type(init.get())}))) ) (! init || ! do_init || (! t && ! (t = init_type(init.get())))) )
{ {
id->Error("already defined", init.get()); id->Error("already defined", init.get());
return; return;
@ -103,7 +103,7 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
return; return;
} }
t = {AdoptRef{}, init_type(init.get())}; t = init_type(init.get());
if ( ! t ) if ( ! t )
{ {
id->SetType({AdoptRef{}, error_type()}); id->SetType({AdoptRef{}, error_type()});