mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Change base_type() to return const-ref, deprecate base_type_no_ref()
This commit is contained in:
parent
2aa84eb86e
commit
bb25f5d568
6 changed files with 34 additions and 39 deletions
|
@ -141,7 +141,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
|
|||
if ( ! tag )
|
||||
return nullptr;
|
||||
|
||||
return base_type(static_cast<TypeTag>(*tag)).release();
|
||||
return base_type(static_cast<TypeTag>(*tag))->Ref();
|
||||
}
|
||||
|
||||
IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state)
|
||||
|
|
20
src/Type.cc
20
src/Type.cc
|
@ -1365,7 +1365,7 @@ BroType* VectorType::YieldType()
|
|||
// return any as that's what other code historically expects for type
|
||||
// comparisions.
|
||||
if ( IsUnspecifiedVector() )
|
||||
return base_type_no_ref(TYPE_ANY);
|
||||
return ::base_type(TYPE_ANY).get();
|
||||
|
||||
return yield_type.get();
|
||||
}
|
||||
|
@ -1431,26 +1431,22 @@ void VectorType::DescribeReST(ODesc* d, bool roles_only) const
|
|||
d->Add(fmt(":zeek:type:`%s`", yield_type->GetName().c_str()));
|
||||
}
|
||||
|
||||
BroType* base_type_no_ref(TypeTag tag)
|
||||
const IntrusivePtr<BroType>& base_type(TypeTag tag)
|
||||
{
|
||||
static BroType* base_types[NUM_TYPES];
|
||||
static IntrusivePtr<BroType> base_types[NUM_TYPES];
|
||||
|
||||
// We could check here that "tag" actually corresponds to a BRO
|
||||
// basic type.
|
||||
|
||||
int t = int(tag);
|
||||
if ( ! base_types[t] )
|
||||
// We could check here that "tag" actually corresponds to a basic type.
|
||||
if ( ! base_types[tag] )
|
||||
{
|
||||
base_types[t] = new BroType(tag, true);
|
||||
base_types[tag] = make_intrusive<BroType>(tag, true);
|
||||
// Give the base types a pseudo-location for easier identification.
|
||||
Location l(type_name(tag), 0, 0, 0, 0);
|
||||
base_types[t]->SetLocationInfo(&l);
|
||||
base_types[tag]->SetLocationInfo(&l);
|
||||
}
|
||||
|
||||
return base_types[t];
|
||||
return base_types[tag];
|
||||
}
|
||||
|
||||
|
||||
// Returns true if t1 is initialization-compatible with t2 (i.e., if an
|
||||
// initializer with type t1 can be used to initialize a value with type t2),
|
||||
// false otherwise. Assumes that t1's tag is different from t2's. Note
|
||||
|
|
12
src/Type.h
12
src/Type.h
|
@ -757,16 +757,16 @@ extern OpaqueType* ocsp_resp_opaque_type;
|
|||
extern OpaqueType* paraglob_type;
|
||||
|
||||
// Returns the basic (non-parameterized) type with the given type.
|
||||
// The reference count of the type is not increased.
|
||||
BroType* base_type_no_ref(TypeTag tag);
|
||||
const IntrusivePtr<BroType>& base_type(TypeTag tag);
|
||||
|
||||
// Returns the basic (non-parameterized) type with the given type.
|
||||
// The caller assumes responsibility for a reference to the type.
|
||||
inline IntrusivePtr<BroType> base_type(TypeTag tag)
|
||||
{ return {NewRef{}, base_type_no_ref(tag)}; }
|
||||
// The reference count of the type is not increased.
|
||||
[[deprecated("Remove in v4.1. Use ::base_type() instead")]]
|
||||
inline BroType* base_type_no_ref(TypeTag tag)
|
||||
{ return base_type(tag).get(); }
|
||||
|
||||
// Returns the basic error type.
|
||||
inline IntrusivePtr<BroType> error_type() { return base_type(TYPE_ERROR); }
|
||||
inline const 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
|
||||
// done in the context of an initialization. If match_record_field_names is
|
||||
|
|
|
@ -1122,7 +1122,7 @@ IntrusivePtr<Val> StringVal::DoClone(CloneState* state)
|
|||
}
|
||||
|
||||
PatternVal::PatternVal(RE_Matcher* re)
|
||||
: Val(base_type_no_ref(TYPE_PATTERN))
|
||||
: Val(base_type(TYPE_PATTERN).get())
|
||||
{
|
||||
val.re_val = re;
|
||||
}
|
||||
|
@ -1130,7 +1130,6 @@ PatternVal::PatternVal(RE_Matcher* re)
|
|||
PatternVal::~PatternVal()
|
||||
{
|
||||
delete AsPattern();
|
||||
Unref(type); // base_type() ref'd it, so did our base constructor
|
||||
}
|
||||
|
||||
bool PatternVal::AddTo(Val* v, bool /* is_first_init */) const
|
||||
|
|
|
@ -126,7 +126,7 @@ union BroValUnion {
|
|||
class Val : public BroObj {
|
||||
public:
|
||||
Val(double d, TypeTag t)
|
||||
: val(d), type(base_type(t).release())
|
||||
: val(d), type(base_type(t)->Ref())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public:
|
|||
}
|
||||
|
||||
Val()
|
||||
: val(bro_int_t(0)), type(base_type(TYPE_ERROR).release())
|
||||
: val(bro_int_t(0)), type(base_type(TYPE_ERROR)->Ref())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ protected:
|
|||
|
||||
template<typename V>
|
||||
Val(V &&v, TypeTag t) noexcept
|
||||
: val(std::forward<V>(v)), type(base_type(t).release())
|
||||
: val(std::forward<V>(v)), type(base_type(t)->Ref())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
30
src/parse.y
30
src/parse.y
|
@ -843,72 +843,72 @@ enum_body_elem:
|
|||
type:
|
||||
TOK_BOOL {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_BOOL).release();
|
||||
$$ = base_type(TYPE_BOOL)->Ref();
|
||||
}
|
||||
|
||||
| TOK_INT {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_INT).release();
|
||||
$$ = base_type(TYPE_INT)->Ref();
|
||||
}
|
||||
|
||||
| TOK_COUNT {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_COUNT).release();
|
||||
$$ = base_type(TYPE_COUNT)->Ref();
|
||||
}
|
||||
|
||||
| TOK_COUNTER {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_COUNTER).release();
|
||||
$$ = base_type(TYPE_COUNTER)->Ref();
|
||||
}
|
||||
|
||||
| TOK_DOUBLE {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_DOUBLE).release();
|
||||
$$ = base_type(TYPE_DOUBLE)->Ref();
|
||||
}
|
||||
|
||||
| TOK_TIME {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_TIME).release();
|
||||
$$ = base_type(TYPE_TIME)->Ref();
|
||||
}
|
||||
|
||||
| TOK_INTERVAL {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_INTERVAL).release();
|
||||
$$ = base_type(TYPE_INTERVAL)->Ref();
|
||||
}
|
||||
|
||||
| TOK_STRING {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_STRING).release();
|
||||
$$ = base_type(TYPE_STRING)->Ref();
|
||||
}
|
||||
|
||||
| TOK_PATTERN {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_PATTERN).release();
|
||||
$$ = base_type(TYPE_PATTERN)->Ref();
|
||||
}
|
||||
|
||||
| TOK_TIMER {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_TIMER).release();
|
||||
$$ = base_type(TYPE_TIMER)->Ref();
|
||||
}
|
||||
|
||||
| TOK_PORT {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_PORT).release();
|
||||
$$ = base_type(TYPE_PORT)->Ref();
|
||||
}
|
||||
|
||||
| TOK_ADDR {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_ADDR).release();
|
||||
$$ = base_type(TYPE_ADDR)->Ref();
|
||||
}
|
||||
|
||||
| TOK_SUBNET {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_SUBNET).release();
|
||||
$$ = base_type(TYPE_SUBNET)->Ref();
|
||||
}
|
||||
|
||||
| TOK_ANY {
|
||||
set_location(@1);
|
||||
$$ = base_type(TYPE_ANY).release();
|
||||
$$ = base_type(TYPE_ANY)->Ref();
|
||||
}
|
||||
|
||||
| TOK_TABLE '[' type_list ']' TOK_OF type
|
||||
|
@ -1012,7 +1012,7 @@ type:
|
|||
NullStmt here;
|
||||
if ( $1 )
|
||||
$1->Error("not a Zeek type", &here);
|
||||
$$ = error_type().release();
|
||||
$$ = error_type()->Ref();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue