Deprecate ID::Type(), replace with GetType()

This commit is contained in:
Jon Siwek 2020-05-07 20:47:33 -07:00
parent 6e647416d5
commit 3f07c57523
24 changed files with 111 additions and 106 deletions

2
NEWS
View file

@ -155,6 +155,8 @@ Deprecated Functionality
- ``ID::AsType()`` is deprecated, use ``ID::IsType()`` and ``ID::GetType()``. - ``ID::AsType()`` is deprecated, use ``ID::IsType()`` and ``ID::GetType()``.
- ``ID::Type()`` is deprecated, use ``ID::GetType()``.
Zeek 3.1.0 Zeek 3.1.0
========== ==========

View file

@ -207,7 +207,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
return; return;
} }
if ( ! id->Type()->AsFuncType() ) if ( ! id->GetType()->AsFuncType() )
{ {
debug_msg("Function %s not declared.\n", id->Name()); debug_msg("Function %s not declared.\n", id->Name());
plr.type = plrUnknown; plr.type = plrUnknown;

View file

@ -65,7 +65,7 @@ void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
for ( const auto& sym : syms ) for ( const auto& sym : syms )
{ {
ID* nextid = sym.second.get(); ID* nextid = sym.second.get();
if ( ! func_only || nextid->Type()->Tag() == TYPE_FUNC ) if ( ! func_only || nextid->GetType()->Tag() == TYPE_FUNC )
if ( ! regexec (&re, nextid->Name(), 0, 0, 0) ) if ( ! regexec (&re, nextid->Name(), 0, 0, 0) )
matches.push_back(nextid); matches.push_back(nextid);
} }

View file

@ -44,10 +44,10 @@ FuncType* EventHandler::FType(bool check_export)
if ( ! id ) if ( ! id )
return nullptr; return nullptr;
if ( id->Type()->Tag() != TYPE_FUNC ) if ( id->GetType()->Tag() != TYPE_FUNC )
return nullptr; return nullptr;
type = id->Type()->AsFuncType(); type = id->GetType()->AsFuncType();
return type; return type;
} }

View file

@ -219,9 +219,9 @@ NameExpr::NameExpr(IntrusivePtr<ID> arg_id, bool const_init)
in_const_init = const_init; in_const_init = const_init;
if ( id->IsType() ) if ( id->IsType() )
SetType(make_intrusive<TypeType>(IntrusivePtr{NewRef{}, id->Type()})); SetType(make_intrusive<TypeType>(id->GetType()));
else else
SetType({NewRef{}, id->Type()}); SetType(id->GetType());
EventHandler* h = event_registry->Lookup(id->Name()); EventHandler* h = event_registry->Lookup(id->Name());
if ( h ) if ( h )
@ -233,7 +233,7 @@ IntrusivePtr<Val> NameExpr::Eval(Frame* f) const
IntrusivePtr<Val> v; IntrusivePtr<Val> v;
if ( id->IsType() ) if ( id->IsType() )
return make_intrusive<Val>(id->Type(), true); return make_intrusive<Val>(id->GetType().get(), true);
if ( id->IsGlobal() ) if ( id->IsGlobal() )
v = {NewRef{}, id->ID_Val()}; v = {NewRef{}, id->ID_Val()};
@ -4262,7 +4262,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr<function_ingredients> arg_ing,
ingredients = std::move(arg_ing); ingredients = std::move(arg_ing);
outer_ids = std::move(arg_outer_ids); outer_ids = std::move(arg_outer_ids);
SetType({NewRef{}, ingredients->id->Type()}); SetType(ingredients->id->GetType());
// Install a dummy version of the function globally for use only // Install a dummy version of the function globally for use only
// when broker provides a closure. // when broker provides a closure.
@ -4307,7 +4307,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr<function_ingredients> arg_ing,
auto v = make_intrusive<Val>(dummy_func); auto v = make_intrusive<Val>(dummy_func);
Unref(dummy_func); Unref(dummy_func);
id->SetVal(std::move(v)); id->SetVal(std::move(v));
id->SetType({NewRef{}, ingredients->id->Type()}); id->SetType(ingredients->id->GetType());
id->SetConst(); id->SetConst();
} }

View file

@ -271,7 +271,7 @@ BroFunc::BroFunc(ID* arg_id, IntrusivePtr<Stmt> arg_body, id_list* aggr_inits,
: Func(BRO_FUNC) : Func(BRO_FUNC)
{ {
name = arg_id->Name(); name = arg_id->Name();
type = {NewRef{}, arg_id->Type()}; type = arg_id->GetType();
frame_size = arg_frame_size; frame_size = arg_frame_size;
if ( arg_body ) if ( arg_body )
@ -593,7 +593,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
if ( id->HasVal() ) if ( id->HasVal() )
reporter->InternalError("built-in function %s multiply defined", Name()); reporter->InternalError("built-in function %s multiply defined", Name());
type = {NewRef{}, id->Type()}; type = id->GetType();
id->SetVal(make_intrusive<Val>(this)); id->SetVal(make_intrusive<Val>(this));
} }

View file

@ -167,7 +167,7 @@ void ID::UpdateValAttrs()
if ( val && val->Type()->Tag() == TYPE_FILE ) if ( val && val->Type()->Tag() == TYPE_FILE )
val->AsFile()->SetAttrs(attrs.get()); val->AsFile()->SetAttrs(attrs.get());
if ( Type()->Tag() == TYPE_FUNC ) if ( GetType()->Tag() == TYPE_FUNC )
{ {
Attr* attr = attrs->FindAttr(ATTR_ERROR_HANDLER); Attr* attr = attrs->FindAttr(ATTR_ERROR_HANDLER);
@ -175,13 +175,13 @@ void ID::UpdateValAttrs()
event_registry->SetErrorHandler(Name()); event_registry->SetErrorHandler(Name());
} }
if ( Type()->Tag() == TYPE_RECORD ) if ( GetType()->Tag() == TYPE_RECORD )
{ {
Attr* attr = attrs->FindAttr(ATTR_LOG); Attr* attr = attrs->FindAttr(ATTR_LOG);
if ( attr ) if ( attr )
{ {
// Apply &log to all record fields. // Apply &log to all record fields.
RecordType* rt = Type()->AsRecordType(); RecordType* rt = GetType()->AsRecordType();
for ( int i = 0; i < rt->NumFields(); ++i ) for ( int i = 0; i < rt->NumFields(); ++i )
{ {
TypeDecl* fd = rt->FieldDecl(i); TypeDecl* fd = rt->FieldDecl(i);
@ -211,7 +211,7 @@ void ID::MakeDeprecated(IntrusivePtr<Expr> deprecation)
return; return;
attr_list* attr = new attr_list{new Attr(ATTR_DEPRECATED, std::move(deprecation))}; attr_list* attr = new attr_list{new Attr(ATTR_DEPRECATED, std::move(deprecation))};
AddAttrs(make_intrusive<Attributes>(attr, IntrusivePtr{NewRef{}, Type()}, false, IsGlobal())); AddAttrs(make_intrusive<Attributes>(attr, GetType(), false, IsGlobal()));
} }
std::string ID::GetDeprecationWarning() const std::string ID::GetDeprecationWarning() const
@ -261,7 +261,7 @@ void ID::SetOption()
if ( ! IsRedefinable() ) if ( ! IsRedefinable() )
{ {
attr_list* attr = new attr_list{new Attr(ATTR_REDEF)}; attr_list* attr = new attr_list{new Attr(ATTR_REDEF)};
AddAttrs(make_intrusive<Attributes>(attr, IntrusivePtr{NewRef{}, Type()}, false, IsGlobal())); AddAttrs(make_intrusive<Attributes>(attr, GetType(), false, IsGlobal()));
} }
} }

View file

@ -38,16 +38,18 @@ public:
void SetType(IntrusivePtr<BroType> t); void SetType(IntrusivePtr<BroType> t);
[[deprecated("Remove in v4.1. Use GetType().")]]
BroType* Type() { return type.get(); } BroType* Type() { return type.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]]
const BroType* Type() const { return type.get(); } const BroType* Type() const { return type.get(); }
const IntrusivePtr<BroType>& GetType() const const IntrusivePtr<BroType>& GetType() const
{ return type; } { return type; }
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]] [[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
BroType* AsType() { return is_type ? Type() : nullptr; } BroType* AsType() { return is_type ? GetType().get() : nullptr; }
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]] [[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
const BroType* AsType() const { return is_type ? Type() : nullptr; } const BroType* AsType() const { return is_type ? GetType().get() : nullptr; }
bool IsType() const bool IsType() const
{ return is_type; } { return is_type; }

View file

@ -133,7 +133,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
if ( ! id->IsType() ) if ( ! id->IsType() )
return nullptr; return nullptr;
return id->Type()->Ref(); return id->GetType()->Ref();
} }
auto tag = caf::get_if<uint64_t>(&(*v)[1]); auto tag = caf::get_if<uint64_t>(&(*v)[1]);

View file

@ -136,10 +136,10 @@ RuleConditionEval::RuleConditionEval(const char* func)
return; return;
} }
if ( id->Type()->Tag() == TYPE_FUNC ) if ( id->GetType()->Tag() == TYPE_FUNC )
{ {
// Validate argument quantity and type. // Validate argument quantity and type.
FuncType* f = id->Type()->AsFuncType(); FuncType* f = id->GetType()->AsFuncType();
if ( f->Yield()->Tag() != TYPE_BOOL ) if ( f->Yield()->Tag() != TYPE_BOOL )
rules_error("eval function type must yield a 'bool'", func); rules_error("eval function type must yield a 'bool'", func);
@ -163,7 +163,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state,
return false; return false;
} }
if ( id->Type()->Tag() != TYPE_FUNC ) if ( id->GetType()->Tag() != TYPE_FUNC )
return id->ID_Val()->AsBool(); return id->ID_Val()->AsBool();
// Call function with a signature_state value as argument. // Call function with a signature_state value as argument.

View file

@ -26,14 +26,14 @@ Scope::Scope(IntrusivePtr<ID> id, attr_list* al)
if ( id ) if ( id )
{ {
BroType* id_type = scope_id->Type(); const auto& id_type = scope_id->GetType();
if ( id_type->Tag() == TYPE_ERROR ) if ( id_type->Tag() == TYPE_ERROR )
return; return;
else if ( id_type->Tag() != TYPE_FUNC ) else if ( id_type->Tag() != TYPE_FUNC )
reporter->InternalError("bad scope id"); reporter->InternalError("bad scope id");
FuncType* ft = id->Type()->AsFuncType(); FuncType* ft = id->GetType()->AsFuncType();
return_type = ft->Yield(); return_type = ft->Yield();
} }
} }

View file

@ -190,7 +190,7 @@ static IntrusivePtr<EnumVal> lookup_enum_val(const char* module_name, const char
assert(id); assert(id);
assert(id->IsEnumConst()); assert(id->IsEnumConst());
EnumType* et = id->Type()->AsEnumType(); EnumType* et = id->GetType()->AsEnumType();
int index = et->Lookup(module_name, name); int index = et->Lookup(module_name, name);
assert(index >= 0); assert(index >= 0);
@ -530,7 +530,7 @@ void Case::Describe(ODesc* d) const
d->SP(); d->SP();
d->Add("type"); d->Add("type");
d->SP(); d->SP();
t[i]->Type()->Describe(d); t[i]->GetType()->Describe(d);
if ( t[i]->Name() ) if ( t[i]->Name() )
{ {
@ -677,9 +677,9 @@ SwitchStmt::SwitchStmt(IntrusivePtr<Expr> index, case_list* arg_cases)
for ( const auto& t : *tl ) for ( const auto& t : *tl )
{ {
BroType* ct = t->Type(); const auto& ct = t->GetType();
if ( ! can_cast_value_to_type(e->Type(), ct) ) if ( ! can_cast_value_to_type(e->Type(), ct.get()) )
{ {
c->Error("cannot cast switch expression to case type"); c->Error("cannot cast switch expression to case type");
continue; continue;
@ -744,7 +744,7 @@ bool SwitchStmt::AddCaseLabelTypeMapping(ID* t, int idx)
{ {
for ( auto i : case_label_type_list ) for ( auto i : case_label_type_list )
{ {
if ( same_type(i.first->Type(), t->Type()) ) if ( same_type(i.first->GetType().get(), t->GetType().get()) )
return false; return false;
} }
@ -782,9 +782,9 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
for ( auto i : case_label_type_list ) for ( auto i : case_label_type_list )
{ {
auto id = i.first; auto id = i.first;
auto type = id->Type(); const auto& type = id->GetType();
if ( can_cast_value_to_type(v, type) ) if ( can_cast_value_to_type(v, type.get()) )
{ {
label_idx = i.second; label_idx = i.second;
label_id = id; label_id = id;
@ -815,7 +815,7 @@ IntrusivePtr<Val> SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) con
if ( matching_id ) if ( matching_id )
{ {
auto cv = cast_value_to_type(v, matching_id->Type()); auto cv = cast_value_to_type(v, matching_id->GetType().get());
f->SetElement(matching_id, cv.release()); f->SetElement(matching_id, cv.release());
} }
@ -1080,17 +1080,18 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
for ( auto i = 0u; i < indices.size(); i++ ) for ( auto i = 0u; i < indices.size(); i++ )
{ {
const auto& ind_type = indices[i]; const auto& ind_type = indices[i];
const auto& lv = (*loop_vars)[i];
const auto& lvt = lv->GetType();
if ( (*loop_vars)[i]->Type() ) if ( lvt )
{ {
if ( ! same_type((*loop_vars)[i]->Type(), ind_type.get()) ) if ( ! same_type(lvt.get(), ind_type.get()) )
(*loop_vars)[i]->Type()->Error("type clash in iteration", lvt->Error("type clash in iteration", ind_type.get());
ind_type.get());
} }
else else
{ {
add_local({NewRef{}, (*loop_vars)[i]}, ind_type, INIT_NONE, add_local({NewRef{}, lv}, ind_type, INIT_NONE,
nullptr, nullptr, VAR_REGULAR); nullptr, nullptr, VAR_REGULAR);
} }
} }
@ -1104,7 +1105,8 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
return; return;
} }
BroType* t = (*loop_vars)[0]->Type(); const auto& t = (*loop_vars)[0]->GetType();
if ( ! t ) if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT), add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT),
INIT_NONE, nullptr, nullptr, VAR_REGULAR); INIT_NONE, nullptr, nullptr, VAR_REGULAR);
@ -1124,7 +1126,8 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
return; return;
} }
BroType* t = (*loop_vars)[0]->Type(); const auto& t = (*loop_vars)[0]->GetType();
if ( ! t ) if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, add_local({NewRef{}, (*loop_vars)[0]},
base_type(TYPE_STRING), base_type(TYPE_STRING),
@ -1151,10 +1154,10 @@ ForStmt::ForStmt(id_list* arg_loop_vars,
const auto& yield_type = e->Type()->AsTableType()->Yield(); const auto& yield_type = e->Type()->AsTableType()->Yield();
// Verify value_vars type if its already been defined // Verify value_vars type if its already been defined
if ( value_var->Type() ) if ( value_var->GetType() )
{ {
if ( ! same_type(value_var->Type(), yield_type.get()) ) if ( ! same_type(value_var->GetType().get(), yield_type.get()) )
value_var->Type()->Error("type clash in iteration", yield_type.get()); value_var->GetType()->Error("type clash in iteration", yield_type.get());
} }
else else
{ {
@ -1422,7 +1425,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr<Expr> arg_e)
return; return;
} }
FuncType* ft = s->ScopeID()->Type()->AsFuncType(); FuncType* ft = s->ScopeID()->GetType()->AsFuncType();
const auto& yt = ft->Yield(); const auto& yt = ft->Yield();
if ( s->ScopeID()->DoInferReturnType() ) if ( s->ScopeID()->DoInferReturnType() )
@ -1653,7 +1656,7 @@ IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
for ( const auto& aggr : *inits ) for ( const auto& aggr : *inits )
{ {
BroType* t = aggr->Type(); const auto& t = aggr->GetType();
Val* v = nullptr; Val* v = nullptr;
@ -1665,7 +1668,7 @@ IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
v = new VectorVal(t->AsVectorType()); v = new VectorVal(t->AsVectorType());
break; break;
case TYPE_TABLE: case TYPE_TABLE:
v = new TableVal({NewRef{}, t->AsTableType()}, {NewRef{}, aggr->Attrs()}); v = new TableVal(cast_intrusive<TableType>(t), {NewRef{}, aggr->Attrs()});
break; break;
default: default:
break; break;

View file

@ -1766,12 +1766,12 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2)
// (potentially) avoiding a pitfall mentioned earlier about clones. // (potentially) avoiding a pitfall mentioned earlier about clones.
auto id = global_scope()->Lookup(t1->GetName()); auto id = global_scope()->Lookup(t1->GetName());
if ( id && id->IsType() && id->Type()->Tag() == TYPE_ENUM ) if ( id && id->IsType() && id->GetType()->Tag() == TYPE_ENUM )
// It should make most sense to return the real type here rather // It should make most sense to return the real type here rather
// than a copy since it may be redef'd later in parsing. If we // than a copy since it may be redef'd later in parsing. If we
// return a copy, then whoever is using this return value won't // return a copy, then whoever is using this return value won't
// actually see those changes from the redef. // actually see those changes from the redef.
return {NewRef{}, id->Type()}; return id->GetType();
std::string msg = fmt("incompatible enum types: '%s' and '%s'" std::string msg = fmt("incompatible enum types: '%s' and '%s'"
" ('%s' enum type ID is invalid)", " ('%s' enum type ID is invalid)",

View file

@ -32,7 +32,7 @@ static IntrusivePtr<Val> init_val(Expr* init, const BroType* t,
static bool add_prototype(ID* id, BroType* t, attr_list* attrs, static bool add_prototype(ID* id, BroType* t, attr_list* attrs,
const IntrusivePtr<Expr>& init) const IntrusivePtr<Expr>& init)
{ {
if ( ! IsFunc(id->Type()->Tag()) ) if ( ! IsFunc(id->GetType()->Tag()) )
return false; return false;
if ( ! IsFunc(t->Tag()) ) if ( ! IsFunc(t->Tag()) )
@ -41,7 +41,7 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs,
return false; return false;
} }
auto canon_ft = id->Type()->AsFuncType(); auto canon_ft = id->GetType()->AsFuncType();
auto alt_ft = t->AsFuncType(); auto alt_ft = t->AsFuncType();
if ( canon_ft->Flavor() != alt_ft->Flavor() ) if ( canon_ft->Flavor() != alt_ft->Flavor() )
@ -110,9 +110,9 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
IntrusivePtr<Expr> init, attr_list* attr, decl_type dt, IntrusivePtr<Expr> init, attr_list* attr, decl_type dt,
bool do_init) bool do_init)
{ {
if ( id->Type() ) if ( id->GetType() )
{ {
if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->Type()->Tag())) ) if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->GetType()->Tag())) )
{ {
BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get(); BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get();
if ( dt != VAR_REDEF ) if ( dt != VAR_REDEF )
@ -121,7 +121,7 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
else if ( dt != VAR_REDEF || init || ! attr ) else if ( dt != VAR_REDEF || init || ! attr )
{ {
if ( IsFunc(id->Type()->Tag()) ) if ( IsFunc(id->GetType()->Tag()) )
add_prototype(id, t.get(), attr, init); add_prototype(id, t.get(), attr, init);
else else
id->Error("already defined", init.get()); id->Error("already defined", init.get());
@ -132,17 +132,17 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
if ( dt == VAR_REDEF ) if ( dt == VAR_REDEF )
{ {
if ( ! id->Type() ) if ( ! id->GetType() )
{ {
id->Error("\"redef\" used but not previously defined"); id->Error("\"redef\" used but not previously defined");
return; return;
} }
if ( ! t ) if ( ! t )
t = {NewRef{}, id->Type()}; t = id->GetType();
} }
if ( id->Type() && id->Type()->Tag() != TYPE_ERROR ) if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR )
{ {
if ( dt != VAR_REDEF && if ( dt != VAR_REDEF &&
(! init || ! do_init || (! t && ! (t = init_type(init.get())))) ) (! init || ! do_init || (! t && ! (t = init_type(init.get())))) )
@ -152,7 +152,7 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
} }
// Allow redeclaration in order to initialize. // Allow redeclaration in order to initialize.
if ( ! same_type(t.get(), id->Type()) ) if ( ! same_type(t.get(), id->GetType().get()) )
{ {
id->Error("redefinition changes type", init.get()); id->Error("redefinition changes type", init.get());
return; return;
@ -469,9 +469,9 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
std::optional<FuncType::Prototype> prototype; std::optional<FuncType::Prototype> prototype;
if ( id->Type() ) if ( id->GetType() )
{ {
auto decl = id->Type()->AsFuncType(); auto decl = id->GetType()->AsFuncType();
prototype = func_type_check(decl, t.get()); prototype = func_type_check(decl, t.get());
if ( prototype ) if ( prototype )
@ -766,7 +766,7 @@ BroType* internal_type(const char* name)
if ( ! id ) if ( ! id )
reporter->InternalError("internal type %s missing", name); reporter->InternalError("internal type %s missing", name);
return id->Type(); return id->GetType().get();
} }
Func* internal_func(const char* name) Func* internal_func(const char* name)

View file

@ -1196,12 +1196,12 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu)
return false; return false;
} }
auto val = data_to_val(std::move(id_value), id->Type()); auto val = data_to_val(std::move(id_value), id->GetType().get());
if ( ! val ) if ( ! val )
{ {
reporter->Error("Failed to receive ID with unsupported type: %s (%s)", reporter->Error("Failed to receive ID with unsupported type: %s (%s)",
id_name.c_str(), type_name(id->Type()->Tag())); id_name.c_str(), type_name(id->GetType()->Tag()));
return false; return false;
} }

View file

@ -2509,7 +2509,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
return nullptr; return nullptr;
} }
index_type = {NewRef{}, enum_id->Type()->AsEnumType()}; index_type = enum_id->GetType();
} }
else else
index_type = base_type(stag); index_type = base_type(stag);
@ -2572,7 +2572,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
return nullptr; return nullptr;
} }
EnumType* t = id->Type()->AsEnumType(); EnumType* t = id->GetType()->AsEnumType();
int intval = t->Lookup(id->ModuleName(), id->Name()); int intval = t->Lookup(id->ModuleName(), id->Name());
if ( intval < 0 ) if ( intval < 0 )
{ {

View file

@ -35,19 +35,19 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
if ( ! id->IsOption() ) if ( ! id->IsOption() )
continue; continue;
if ( id->Type()->Tag() == TYPE_RECORD || if ( id->GetType()->Tag() == TYPE_RECORD ||
! input::Manager::IsCompatibleType(id->Type()) ) ! input::Manager::IsCompatibleType(id->GetType().get()) )
{ {
option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->Type()->Tag()); option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->GetType()->Tag());
continue; continue;
} }
TypeTag primary = id->Type()->Tag(); TypeTag primary = id->GetType()->Tag();
TypeTag secondary = TYPE_VOID; TypeTag secondary = TYPE_VOID;
if ( primary == TYPE_TABLE ) if ( primary == TYPE_TABLE )
secondary = id->Type()->AsSetType()->Indices()->GetPureType()->Tag(); secondary = id->GetType()->AsSetType()->Indices()->GetPureType()->Tag();
else if ( primary == TYPE_VECTOR ) else if ( primary == TYPE_VECTOR )
secondary = id->Type()->AsVectorType()->Yield()->Tag(); secondary = id->GetType()->AsVectorType()->Yield()->Tag();
option_types[id->Name()] = std::make_tuple(primary, secondary); option_types[id->Name()] = std::make_tuple(primary, secondary);
} }

View file

@ -82,12 +82,12 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool
if ( same_type(val->Type(), bro_broker::DataVal::ScriptDataType()) ) if ( same_type(val->Type(), bro_broker::DataVal::ScriptDataType()) )
{ {
auto dv = static_cast<bro_broker::DataVal*>(val->AsRecordVal()->Lookup(0)); auto dv = static_cast<bro_broker::DataVal*>(val->AsRecordVal()->Lookup(0));
auto val_from_data = dv->castTo(i->Type()); auto val_from_data = dv->castTo(i->GetType().get());
if ( ! val_from_data ) if ( ! val_from_data )
{ {
builtin_error(fmt("Incompatible type for set of ID '%s': got broker data '%s', need '%s'", builtin_error(fmt("Incompatible type for set of ID '%s': got broker data '%s', need '%s'",
ID->CheckString(), dv->data.get_type_name(), type_name(i->Type()->Tag()))); ID->CheckString(), dv->data.get_type_name(), type_name(i->GetType()->Tag())));
return val_mgr->False(); return val_mgr->False();
} }
@ -95,22 +95,22 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool
return val_mgr->Bool(rval); return val_mgr->Bool(rval);
} }
if ( ! same_type(i->Type(), val->Type()) ) if ( ! same_type(i->GetType().get(), val->Type()) )
{ {
if ( i->Type()->Tag() == TYPE_TABLE && if ( i->GetType()->Tag() == TYPE_TABLE &&
val->Type()->Tag() == TYPE_TABLE && val->Type()->Tag() == TYPE_TABLE &&
val->Type()->AsTableType()->IsUnspecifiedTable() ) val->Type()->AsTableType()->IsUnspecifiedTable() )
{ {
// Just coerce an empty/unspecified table to the right type. // Just coerce an empty/unspecified table to the right type.
auto tv = make_intrusive<TableVal>( auto tv = make_intrusive<TableVal>(
IntrusivePtr{NewRef{}, i->Type()->AsTableType()}, cast_intrusive<TableType>(i->GetType()),
IntrusivePtr{NewRef{}, i->ID_Val()->AsTableVal()->Attrs()}); IntrusivePtr{NewRef{}, i->ID_Val()->AsTableVal()->Attrs()});
auto rval = call_option_handlers_and_set_value(ID, i, std::move(tv), location); auto rval = call_option_handlers_and_set_value(ID, i, std::move(tv), location);
return val_mgr->Bool(rval); return val_mgr->Bool(rval);
} }
builtin_error(fmt("Incompatible type for set of ID '%s': got '%s', need '%s'", builtin_error(fmt("Incompatible type for set of ID '%s': got '%s', need '%s'",
ID->CheckString(), type_name(val->Type()->Tag()), type_name(i->Type()->Tag()))); ID->CheckString(), type_name(val->Type()->Tag()), type_name(i->GetType()->Tag())));
return val_mgr->False(); return val_mgr->False();
} }
@ -185,10 +185,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int &
return val_mgr->False(); return val_mgr->False();
} }
if ( ! same_type(args[1].get(), i->Type()) ) if ( ! same_type(args[1].get(), i->GetType().get()) )
{ {
builtin_error(fmt("Second argument of passed function has to be %s in Option::on_change for ID '%s'; got '%s'", builtin_error(fmt("Second argument of passed function has to be %s in Option::on_change for ID '%s'; got '%s'",
type_name(i->Type()->Tag()), ID->CheckString(), type_name(args[1]->Tag()))); type_name(i->GetType()->Tag()), ID->CheckString(), type_name(args[1]->Tag())));
return val_mgr->False(); return val_mgr->False();
} }
@ -199,10 +199,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int &
return val_mgr->False(); return val_mgr->False();
} }
if ( ! same_type(on_change->Type()->AsFuncType()->Yield().get(), i->Type()) ) if ( ! same_type(on_change->Type()->AsFuncType()->Yield().get(), i->GetType().get()) )
{ {
builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'", builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'",
type_name(i->Type()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->Yield()->Tag()))); type_name(i->GetType()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->Yield()->Tag())));
return val_mgr->False(); return val_mgr->False();
} }

View file

@ -155,14 +155,15 @@ static void parser_redef_enum (ID *id)
/* Redef an enum. id points to the enum to be redefined. /* Redef an enum. id points to the enum to be redefined.
Let cur_enum_type point to it. */ Let cur_enum_type point to it. */
assert(cur_enum_type == NULL); assert(cur_enum_type == NULL);
// abort on errors; enums need to be accessible to continue parsing // abort on errors; enums need to be accessible to continue parsing
if ( ! id->Type() ) if ( ! id->GetType() )
reporter->FatalError("unknown enum identifier \"%s\"", id->Name()); reporter->FatalError("unknown enum identifier \"%s\"", id->Name());
else else
{ {
if ( ! id->Type() || id->Type()->Tag() != TYPE_ENUM ) if ( ! id->GetType() || id->GetType()->Tag() != TYPE_ENUM )
reporter->FatalError("identifier \"%s\" is not an enum", id->Name()); reporter->FatalError("identifier \"%s\" is not an enum", id->Name());
cur_enum_type = id->Type()->AsEnumType(); cur_enum_type = id->GetType()->AsEnumType();
} }
} }
@ -608,31 +609,28 @@ expr:
if ( $1->Tag() == EXPR_NAME && $1->AsNameExpr()->Id()->IsType() ) if ( $1->Tag() == EXPR_NAME && $1->AsNameExpr()->Id()->IsType() )
{ {
auto ctor_type = $1->AsNameExpr()->Id()->Type(); const auto& ctor_type = $1->AsNameExpr()->Id()->GetType();
switch ( ctor_type->Tag() ) { switch ( ctor_type->Tag() ) {
case TYPE_RECORD: case TYPE_RECORD:
{ {
auto rce = make_intrusive<RecordConstructorExpr>( auto rce = make_intrusive<RecordConstructorExpr>(
IntrusivePtr<ListExpr>{AdoptRef{}, $4}); IntrusivePtr<ListExpr>{AdoptRef{}, $4});
IntrusivePtr<RecordType> rt{NewRef{}, ctor_type->AsRecordType()}; auto rt = cast_intrusive<RecordType>(ctor_type);
$$ = new RecordCoerceExpr(std::move(rce), std::move(rt)); $$ = new RecordCoerceExpr(std::move(rce), std::move(rt));
} }
break; break;
case TYPE_TABLE: case TYPE_TABLE:
if ( ctor_type->IsTable() ) if ( ctor_type->IsTable() )
$$ = new TableConstructorExpr({AdoptRef{}, $4}, 0, $$ = new TableConstructorExpr({AdoptRef{}, $4}, 0, ctor_type);
{NewRef{}, ctor_type});
else else
$$ = new SetConstructorExpr({AdoptRef{}, $4}, 0, $$ = new SetConstructorExpr({AdoptRef{}, $4}, 0, ctor_type);
{NewRef{}, ctor_type});
break; break;
case TYPE_VECTOR: case TYPE_VECTOR:
$$ = new VectorConstructorExpr({AdoptRef{}, $4}, $$ = new VectorConstructorExpr({AdoptRef{}, $4}, ctor_type);
{NewRef{}, ctor_type});
break; break;
default: default:
@ -697,7 +695,7 @@ expr:
if ( id->IsDeprecated() ) if ( id->IsDeprecated() )
reporter->Warning("%s", id->GetDeprecationWarning().c_str()); reporter->Warning("%s", id->GetDeprecationWarning().c_str());
if ( ! id->Type() ) if ( ! id->GetType() )
{ {
id->Error("undeclared variable"); id->Error("undeclared variable");
id->SetType(error_type()); id->SetType(error_type());
@ -706,7 +704,7 @@ expr:
else if ( id->IsEnumConst() ) else if ( id->IsEnumConst() )
{ {
EnumType* t = id->Type()->AsEnumType(); EnumType* t = id->GetType()->AsEnumType();
int intval = t->Lookup(id->ModuleName(), int intval = t->Lookup(id->ModuleName(),
id->Name()); id->Name());
if ( intval < 0 ) if ( intval < 0 )
@ -1006,7 +1004,7 @@ type:
| resolve_id | resolve_id
{ {
if ( ! $1 || ! ($$ = $1->IsType() ? $1->Type() : nullptr) ) if ( ! $1 || ! ($$ = $1->IsType() ? $1->GetType().get() : nullptr) )
{ {
NullStmt here; NullStmt here;
if ( $1 ) if ( $1 )
@ -1137,7 +1135,7 @@ decl:
{ {
cur_decl_type_id = 0; cur_decl_type_id = 0;
if ( ! $3->Type() ) if ( ! $3->GetType() )
$3->Error("unknown identifier"); $3->Error("unknown identifier");
else else
extend_record($3, $8, $11); extend_record($3, $8, $11);
@ -1817,7 +1815,7 @@ global_or_event_id:
if ( $$->IsDeprecated() ) if ( $$->IsDeprecated() )
{ {
BroType* t = $$->Type(); const auto& t = $$->GetType();
if ( t->Tag() != TYPE_FUNC || if ( t->Tag() != TYPE_FUNC ||
t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION )

View file

@ -1171,7 +1171,7 @@ IntrusivePtr<RecordVal> Supervisor::Node::ToRecord() const
static IntrusivePtr<Val> supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) static IntrusivePtr<Val> supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role)
{ {
static auto node_type = global_scope()->Lookup("Cluster::NodeType")->Type()->AsEnumType(); static auto node_type = global_scope()->Lookup("Cluster::NodeType")->GetType()->AsEnumType();
switch ( role ) { switch ( role ) {
case BifEnum::Supervisor::LOGGER: case BifEnum::Supervisor::LOGGER:
@ -1192,7 +1192,7 @@ bool Supervisor::SupervisedNode::InitCluster() const
if ( config.cluster.empty() ) if ( config.cluster.empty() )
return false; return false;
auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->Type()->AsRecordType(); auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->GetType()->AsRecordType();
auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes"); auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes");
auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger"); auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger");
auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal(); auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal();

View file

@ -1951,7 +1951,7 @@ function global_ids%(%): id_table
{ {
ID* id = global.second.get(); ID* id = global.second.get();
auto rec = make_intrusive<RecordVal>(script_id); auto rec = make_intrusive<RecordVal>(script_id);
rec->Assign(0, make_intrusive<StringVal>(type_name(id->Type()->Tag()))); rec->Assign(0, make_intrusive<StringVal>(type_name(id->GetType()->Tag())));
rec->Assign(1, val_mgr->Bool(id->IsExport())); rec->Assign(1, val_mgr->Bool(id->IsExport()));
rec->Assign(2, val_mgr->Bool(id->IsConst())); rec->Assign(2, val_mgr->Bool(id->IsConst()));
rec->Assign(3, val_mgr->Bool(id->IsEnumConst())); rec->Assign(3, val_mgr->Bool(id->IsEnumConst()));
@ -2003,14 +2003,14 @@ function record_fields%(rec: any%): record_field_table
{ {
auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString()); auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString());
if ( ! id || ! id->IsType() || id->Type()->Tag() != TYPE_RECORD ) if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD )
{ {
reporter->Error("record_fields string argument does not name a record type"); reporter->Error("record_fields string argument does not name a record type");
IntrusivePtr<TableType> tt{NewRef{}, internal_type("record_field_table")->AsTableType()}; IntrusivePtr<TableType> tt{NewRef{}, internal_type("record_field_table")->AsTableType()};
return make_intrusive<TableVal>(std::move(tt)); return make_intrusive<TableVal>(std::move(tt));
} }
return id->Type()->AsRecordType()->GetRecordFieldsVal(); return id->GetType()->AsRecordType()->GetRecordFieldsVal();
} }
return rec->GetRecordFields(); return rec->GetRecordFields();

View file

@ -116,7 +116,7 @@ string IdentifierInfo::DoReStructuredText(bool roles_only) const
if ( i > 0 ) if ( i > 0 )
d.NL(); d.NL();
if ( IsFunc(id->Type()->Tag()) ) if ( IsFunc(id->GetType()->Tag()) )
{ {
string s = comments[i]; string s = comments[i];

View file

@ -274,7 +274,7 @@ void Manager::StartType(IntrusivePtr<ID> id)
static bool IsEnumType(ID* id) static bool IsEnumType(ID* id)
{ {
return id->IsType() ? id->Type()->Tag() == TYPE_ENUM : false; return id->IsType() ? id->GetType()->Tag() == TYPE_ENUM : false;
} }
void Manager::Identifier(IntrusivePtr<ID> id) void Manager::Identifier(IntrusivePtr<ID> id)
@ -300,7 +300,7 @@ void Manager::Identifier(IntrusivePtr<ID> id)
if ( id_info ) if ( id_info )
{ {
if ( IsFunc(id_info->GetID()->Type()->Tag()) ) if ( IsFunc(id_info->GetID()->GetType()->Tag()) )
{ {
// Function may already been seen (declaration versus body). // Function may already been seen (declaration versus body).
id_info->AddComments(comment_buffer); id_info->AddComments(comment_buffer);

View file

@ -191,9 +191,9 @@ void ScriptInfo::DoInitPostScript()
continue; continue;
} }
if ( IsFunc(id->Type()->Tag()) ) if ( IsFunc(id->GetType()->Tag()) )
{ {
switch ( id->Type()->AsFuncType()->Flavor() ) { switch ( id->GetType()->AsFuncType()->Flavor() ) {
case FUNC_FLAVOR_HOOK: case FUNC_FLAVOR_HOOK:
DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a hook", DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a hook",
id->Name(), name.c_str()); id->Name(), name.c_str());
@ -243,7 +243,7 @@ void ScriptInfo::DoInitPostScript()
continue; continue;
} }
if ( id->Type()->Tag() == TYPE_ENUM ) if ( id->GetType()->Tag() == TYPE_ENUM )
// Enums are always referenced/documented from the type's // Enums are always referenced/documented from the type's
// documentation. // documentation.
continue; continue;