mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Deprecate ID::Type(), replace with GetType()
This commit is contained in:
parent
6e647416d5
commit
3f07c57523
24 changed files with 111 additions and 106 deletions
2
NEWS
2
NEWS
|
@ -155,6 +155,8 @@ Deprecated Functionality
|
|||
|
||||
- ``ID::AsType()`` is deprecated, use ``ID::IsType()`` and ``ID::GetType()``.
|
||||
|
||||
- ``ID::Type()`` is deprecated, use ``ID::GetType()``.
|
||||
|
||||
Zeek 3.1.0
|
||||
==========
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
|
|||
return;
|
||||
}
|
||||
|
||||
if ( ! id->Type()->AsFuncType() )
|
||||
if ( ! id->GetType()->AsFuncType() )
|
||||
{
|
||||
debug_msg("Function %s not declared.\n", id->Name());
|
||||
plr.type = plrUnknown;
|
||||
|
|
|
@ -65,7 +65,7 @@ void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
|
|||
for ( const auto& sym : syms )
|
||||
{
|
||||
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) )
|
||||
matches.push_back(nextid);
|
||||
}
|
||||
|
|
|
@ -44,10 +44,10 @@ FuncType* EventHandler::FType(bool check_export)
|
|||
if ( ! id )
|
||||
return nullptr;
|
||||
|
||||
if ( id->Type()->Tag() != TYPE_FUNC )
|
||||
if ( id->GetType()->Tag() != TYPE_FUNC )
|
||||
return nullptr;
|
||||
|
||||
type = id->Type()->AsFuncType();
|
||||
type = id->GetType()->AsFuncType();
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
10
src/Expr.cc
10
src/Expr.cc
|
@ -219,9 +219,9 @@ NameExpr::NameExpr(IntrusivePtr<ID> arg_id, bool const_init)
|
|||
in_const_init = const_init;
|
||||
|
||||
if ( id->IsType() )
|
||||
SetType(make_intrusive<TypeType>(IntrusivePtr{NewRef{}, id->Type()}));
|
||||
SetType(make_intrusive<TypeType>(id->GetType()));
|
||||
else
|
||||
SetType({NewRef{}, id->Type()});
|
||||
SetType(id->GetType());
|
||||
|
||||
EventHandler* h = event_registry->Lookup(id->Name());
|
||||
if ( h )
|
||||
|
@ -233,7 +233,7 @@ IntrusivePtr<Val> NameExpr::Eval(Frame* f) const
|
|||
IntrusivePtr<Val> v;
|
||||
|
||||
if ( id->IsType() )
|
||||
return make_intrusive<Val>(id->Type(), true);
|
||||
return make_intrusive<Val>(id->GetType().get(), true);
|
||||
|
||||
if ( id->IsGlobal() )
|
||||
v = {NewRef{}, id->ID_Val()};
|
||||
|
@ -4262,7 +4262,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr<function_ingredients> arg_ing,
|
|||
ingredients = std::move(arg_ing);
|
||||
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
|
||||
// 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);
|
||||
Unref(dummy_func);
|
||||
id->SetVal(std::move(v));
|
||||
id->SetType({NewRef{}, ingredients->id->Type()});
|
||||
id->SetType(ingredients->id->GetType());
|
||||
id->SetConst();
|
||||
}
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ BroFunc::BroFunc(ID* arg_id, IntrusivePtr<Stmt> arg_body, id_list* aggr_inits,
|
|||
: Func(BRO_FUNC)
|
||||
{
|
||||
name = arg_id->Name();
|
||||
type = {NewRef{}, arg_id->Type()};
|
||||
type = arg_id->GetType();
|
||||
frame_size = arg_frame_size;
|
||||
|
||||
if ( arg_body )
|
||||
|
@ -593,7 +593,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
|
|||
if ( id->HasVal() )
|
||||
reporter->InternalError("built-in function %s multiply defined", Name());
|
||||
|
||||
type = {NewRef{}, id->Type()};
|
||||
type = id->GetType();
|
||||
id->SetVal(make_intrusive<Val>(this));
|
||||
}
|
||||
|
||||
|
|
10
src/ID.cc
10
src/ID.cc
|
@ -167,7 +167,7 @@ void ID::UpdateValAttrs()
|
|||
if ( val && val->Type()->Tag() == TYPE_FILE )
|
||||
val->AsFile()->SetAttrs(attrs.get());
|
||||
|
||||
if ( Type()->Tag() == TYPE_FUNC )
|
||||
if ( GetType()->Tag() == TYPE_FUNC )
|
||||
{
|
||||
Attr* attr = attrs->FindAttr(ATTR_ERROR_HANDLER);
|
||||
|
||||
|
@ -175,13 +175,13 @@ void ID::UpdateValAttrs()
|
|||
event_registry->SetErrorHandler(Name());
|
||||
}
|
||||
|
||||
if ( Type()->Tag() == TYPE_RECORD )
|
||||
if ( GetType()->Tag() == TYPE_RECORD )
|
||||
{
|
||||
Attr* attr = attrs->FindAttr(ATTR_LOG);
|
||||
if ( attr )
|
||||
{
|
||||
// Apply &log to all record fields.
|
||||
RecordType* rt = Type()->AsRecordType();
|
||||
RecordType* rt = GetType()->AsRecordType();
|
||||
for ( int i = 0; i < rt->NumFields(); ++i )
|
||||
{
|
||||
TypeDecl* fd = rt->FieldDecl(i);
|
||||
|
@ -211,7 +211,7 @@ void ID::MakeDeprecated(IntrusivePtr<Expr> deprecation)
|
|||
return;
|
||||
|
||||
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
|
||||
|
@ -261,7 +261,7 @@ void ID::SetOption()
|
|||
if ( ! IsRedefinable() )
|
||||
{
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
6
src/ID.h
6
src/ID.h
|
@ -38,16 +38,18 @@ public:
|
|||
|
||||
void SetType(IntrusivePtr<BroType> t);
|
||||
|
||||
[[deprecated("Remove in v4.1. Use GetType().")]]
|
||||
BroType* Type() { return type.get(); }
|
||||
[[deprecated("Remove in v4.1. Use GetType().")]]
|
||||
const BroType* Type() const { return type.get(); }
|
||||
|
||||
const IntrusivePtr<BroType>& GetType() const
|
||||
{ return type; }
|
||||
|
||||
[[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().")]]
|
||||
const BroType* AsType() const { return is_type ? Type() : nullptr; }
|
||||
const BroType* AsType() const { return is_type ? GetType().get() : nullptr; }
|
||||
|
||||
bool IsType() const
|
||||
{ return is_type; }
|
||||
|
|
|
@ -133,7 +133,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
|
|||
if ( ! id->IsType() )
|
||||
return nullptr;
|
||||
|
||||
return id->Type()->Ref();
|
||||
return id->GetType()->Ref();
|
||||
}
|
||||
|
||||
auto tag = caf::get_if<uint64_t>(&(*v)[1]);
|
||||
|
|
|
@ -136,10 +136,10 @@ RuleConditionEval::RuleConditionEval(const char* func)
|
|||
return;
|
||||
}
|
||||
|
||||
if ( id->Type()->Tag() == TYPE_FUNC )
|
||||
if ( id->GetType()->Tag() == TYPE_FUNC )
|
||||
{
|
||||
// Validate argument quantity and type.
|
||||
FuncType* f = id->Type()->AsFuncType();
|
||||
FuncType* f = id->GetType()->AsFuncType();
|
||||
|
||||
if ( f->Yield()->Tag() != TYPE_BOOL )
|
||||
rules_error("eval function type must yield a 'bool'", func);
|
||||
|
@ -163,7 +163,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state,
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( id->Type()->Tag() != TYPE_FUNC )
|
||||
if ( id->GetType()->Tag() != TYPE_FUNC )
|
||||
return id->ID_Val()->AsBool();
|
||||
|
||||
// Call function with a signature_state value as argument.
|
||||
|
|
|
@ -26,14 +26,14 @@ Scope::Scope(IntrusivePtr<ID> id, attr_list* al)
|
|||
|
||||
if ( id )
|
||||
{
|
||||
BroType* id_type = scope_id->Type();
|
||||
const auto& id_type = scope_id->GetType();
|
||||
|
||||
if ( id_type->Tag() == TYPE_ERROR )
|
||||
return;
|
||||
else if ( id_type->Tag() != TYPE_FUNC )
|
||||
reporter->InternalError("bad scope id");
|
||||
|
||||
FuncType* ft = id->Type()->AsFuncType();
|
||||
FuncType* ft = id->GetType()->AsFuncType();
|
||||
return_type = ft->Yield();
|
||||
}
|
||||
}
|
||||
|
|
45
src/Stmt.cc
45
src/Stmt.cc
|
@ -190,7 +190,7 @@ static IntrusivePtr<EnumVal> lookup_enum_val(const char* module_name, const char
|
|||
assert(id);
|
||||
assert(id->IsEnumConst());
|
||||
|
||||
EnumType* et = id->Type()->AsEnumType();
|
||||
EnumType* et = id->GetType()->AsEnumType();
|
||||
|
||||
int index = et->Lookup(module_name, name);
|
||||
assert(index >= 0);
|
||||
|
@ -530,7 +530,7 @@ void Case::Describe(ODesc* d) const
|
|||
d->SP();
|
||||
d->Add("type");
|
||||
d->SP();
|
||||
t[i]->Type()->Describe(d);
|
||||
t[i]->GetType()->Describe(d);
|
||||
|
||||
if ( t[i]->Name() )
|
||||
{
|
||||
|
@ -677,9 +677,9 @@ SwitchStmt::SwitchStmt(IntrusivePtr<Expr> index, case_list* arg_cases)
|
|||
|
||||
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");
|
||||
continue;
|
||||
|
@ -744,7 +744,7 @@ bool SwitchStmt::AddCaseLabelTypeMapping(ID* t, int idx)
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -782,9 +782,9 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
|
|||
for ( auto i : case_label_type_list )
|
||||
{
|
||||
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_id = id;
|
||||
|
@ -815,7 +815,7 @@ IntrusivePtr<Val> SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) con
|
|||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -1080,17 +1080,18 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
|
|||
for ( auto i = 0u; i < indices.size(); 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()) )
|
||||
(*loop_vars)[i]->Type()->Error("type clash in iteration",
|
||||
ind_type.get());
|
||||
if ( ! same_type(lvt.get(), ind_type.get()) )
|
||||
lvt->Error("type clash in iteration", ind_type.get());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
add_local({NewRef{}, (*loop_vars)[i]}, ind_type, INIT_NONE,
|
||||
add_local({NewRef{}, lv}, ind_type, INIT_NONE,
|
||||
nullptr, nullptr, VAR_REGULAR);
|
||||
}
|
||||
}
|
||||
|
@ -1104,7 +1105,8 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
|
|||
return;
|
||||
}
|
||||
|
||||
BroType* t = (*loop_vars)[0]->Type();
|
||||
const auto& t = (*loop_vars)[0]->GetType();
|
||||
|
||||
if ( ! t )
|
||||
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT),
|
||||
INIT_NONE, nullptr, nullptr, VAR_REGULAR);
|
||||
|
@ -1124,7 +1126,8 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
|
|||
return;
|
||||
}
|
||||
|
||||
BroType* t = (*loop_vars)[0]->Type();
|
||||
const auto& t = (*loop_vars)[0]->GetType();
|
||||
|
||||
if ( ! t )
|
||||
add_local({NewRef{}, (*loop_vars)[0]},
|
||||
base_type(TYPE_STRING),
|
||||
|
@ -1151,10 +1154,10 @@ ForStmt::ForStmt(id_list* arg_loop_vars,
|
|||
const auto& yield_type = e->Type()->AsTableType()->Yield();
|
||||
|
||||
// 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()) )
|
||||
value_var->Type()->Error("type clash in iteration", yield_type.get());
|
||||
if ( ! same_type(value_var->GetType().get(), yield_type.get()) )
|
||||
value_var->GetType()->Error("type clash in iteration", yield_type.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1422,7 +1425,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr<Expr> arg_e)
|
|||
return;
|
||||
}
|
||||
|
||||
FuncType* ft = s->ScopeID()->Type()->AsFuncType();
|
||||
FuncType* ft = s->ScopeID()->GetType()->AsFuncType();
|
||||
const auto& yt = ft->Yield();
|
||||
|
||||
if ( s->ScopeID()->DoInferReturnType() )
|
||||
|
@ -1653,7 +1656,7 @@ IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
|
|||
|
||||
for ( const auto& aggr : *inits )
|
||||
{
|
||||
BroType* t = aggr->Type();
|
||||
const auto& t = aggr->GetType();
|
||||
|
||||
Val* v = nullptr;
|
||||
|
||||
|
@ -1665,7 +1668,7 @@ IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
|
|||
v = new VectorVal(t->AsVectorType());
|
||||
break;
|
||||
case TYPE_TABLE:
|
||||
v = new TableVal({NewRef{}, t->AsTableType()}, {NewRef{}, aggr->Attrs()});
|
||||
v = new TableVal(cast_intrusive<TableType>(t), {NewRef{}, aggr->Attrs()});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -1766,12 +1766,12 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2)
|
|||
// (potentially) avoiding a pitfall mentioned earlier about clones.
|
||||
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
|
||||
// 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
|
||||
// actually see those changes from the redef.
|
||||
return {NewRef{}, id->Type()};
|
||||
return id->GetType();
|
||||
|
||||
std::string msg = fmt("incompatible enum types: '%s' and '%s'"
|
||||
" ('%s' enum type ID is invalid)",
|
||||
|
|
24
src/Var.cc
24
src/Var.cc
|
@ -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,
|
||||
const IntrusivePtr<Expr>& init)
|
||||
{
|
||||
if ( ! IsFunc(id->Type()->Tag()) )
|
||||
if ( ! IsFunc(id->GetType()->Tag()) )
|
||||
return false;
|
||||
|
||||
if ( ! IsFunc(t->Tag()) )
|
||||
|
@ -41,7 +41,7 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs,
|
|||
return false;
|
||||
}
|
||||
|
||||
auto canon_ft = id->Type()->AsFuncType();
|
||||
auto canon_ft = id->GetType()->AsFuncType();
|
||||
auto alt_ft = t->AsFuncType();
|
||||
|
||||
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,
|
||||
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();
|
||||
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 )
|
||||
{
|
||||
if ( IsFunc(id->Type()->Tag()) )
|
||||
if ( IsFunc(id->GetType()->Tag()) )
|
||||
add_prototype(id, t.get(), attr, init);
|
||||
else
|
||||
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 ( ! id->Type() )
|
||||
if ( ! id->GetType() )
|
||||
{
|
||||
id->Error("\"redef\" used but not previously defined");
|
||||
return;
|
||||
}
|
||||
|
||||
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 &&
|
||||
(! 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.
|
||||
if ( ! same_type(t.get(), id->Type()) )
|
||||
if ( ! same_type(t.get(), id->GetType().get()) )
|
||||
{
|
||||
id->Error("redefinition changes type", init.get());
|
||||
return;
|
||||
|
@ -469,9 +469,9 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
|||
|
||||
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());
|
||||
|
||||
if ( prototype )
|
||||
|
@ -766,7 +766,7 @@ BroType* internal_type(const char* name)
|
|||
if ( ! id )
|
||||
reporter->InternalError("internal type %s missing", name);
|
||||
|
||||
return id->Type();
|
||||
return id->GetType().get();
|
||||
}
|
||||
|
||||
Func* internal_func(const char* name)
|
||||
|
|
|
@ -1196,12 +1196,12 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu)
|
|||
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 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -2509,7 +2509,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
index_type = {NewRef{}, enum_id->Type()->AsEnumType()};
|
||||
index_type = enum_id->GetType();
|
||||
}
|
||||
else
|
||||
index_type = base_type(stag);
|
||||
|
@ -2572,7 +2572,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
EnumType* t = id->Type()->AsEnumType();
|
||||
EnumType* t = id->GetType()->AsEnumType();
|
||||
int intval = t->Lookup(id->ModuleName(), id->Name());
|
||||
if ( intval < 0 )
|
||||
{
|
||||
|
|
|
@ -35,19 +35,19 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
|
|||
if ( ! id->IsOption() )
|
||||
continue;
|
||||
|
||||
if ( id->Type()->Tag() == TYPE_RECORD ||
|
||||
! input::Manager::IsCompatibleType(id->Type()) )
|
||||
if ( id->GetType()->Tag() == TYPE_RECORD ||
|
||||
! 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;
|
||||
}
|
||||
|
||||
TypeTag primary = id->Type()->Tag();
|
||||
TypeTag primary = id->GetType()->Tag();
|
||||
TypeTag secondary = TYPE_VOID;
|
||||
if ( primary == TYPE_TABLE )
|
||||
secondary = id->Type()->AsSetType()->Indices()->GetPureType()->Tag();
|
||||
secondary = id->GetType()->AsSetType()->Indices()->GetPureType()->Tag();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -82,12 +82,12 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool
|
|||
if ( same_type(val->Type(), bro_broker::DataVal::ScriptDataType()) )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -95,22 +95,22 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool
|
|||
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()->AsTableType()->IsUnspecifiedTable() )
|
||||
{
|
||||
// Just coerce an empty/unspecified table to the right type.
|
||||
auto tv = make_intrusive<TableVal>(
|
||||
IntrusivePtr{NewRef{}, i->Type()->AsTableType()},
|
||||
cast_intrusive<TableType>(i->GetType()),
|
||||
IntrusivePtr{NewRef{}, i->ID_Val()->AsTableVal()->Attrs()});
|
||||
auto rval = call_option_handlers_and_set_value(ID, i, std::move(tv), location);
|
||||
return val_mgr->Bool(rval);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -185,10 +185,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int &
|
|||
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'",
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -199,10 +199,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int &
|
|||
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'",
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
30
src/parse.y
30
src/parse.y
|
@ -155,14 +155,15 @@ static void parser_redef_enum (ID *id)
|
|||
/* Redef an enum. id points to the enum to be redefined.
|
||||
Let cur_enum_type point to it. */
|
||||
assert(cur_enum_type == NULL);
|
||||
|
||||
// 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());
|
||||
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());
|
||||
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() )
|
||||
{
|
||||
auto ctor_type = $1->AsNameExpr()->Id()->Type();
|
||||
const auto& ctor_type = $1->AsNameExpr()->Id()->GetType();
|
||||
|
||||
switch ( ctor_type->Tag() ) {
|
||||
case TYPE_RECORD:
|
||||
{
|
||||
auto rce = make_intrusive<RecordConstructorExpr>(
|
||||
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));
|
||||
}
|
||||
break;
|
||||
|
||||
case TYPE_TABLE:
|
||||
if ( ctor_type->IsTable() )
|
||||
$$ = new TableConstructorExpr({AdoptRef{}, $4}, 0,
|
||||
{NewRef{}, ctor_type});
|
||||
$$ = new TableConstructorExpr({AdoptRef{}, $4}, 0, ctor_type);
|
||||
else
|
||||
$$ = new SetConstructorExpr({AdoptRef{}, $4}, 0,
|
||||
{NewRef{}, ctor_type});
|
||||
$$ = new SetConstructorExpr({AdoptRef{}, $4}, 0, ctor_type);
|
||||
|
||||
break;
|
||||
|
||||
case TYPE_VECTOR:
|
||||
$$ = new VectorConstructorExpr({AdoptRef{}, $4},
|
||||
{NewRef{}, ctor_type});
|
||||
$$ = new VectorConstructorExpr({AdoptRef{}, $4}, ctor_type);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -697,7 +695,7 @@ expr:
|
|||
if ( id->IsDeprecated() )
|
||||
reporter->Warning("%s", id->GetDeprecationWarning().c_str());
|
||||
|
||||
if ( ! id->Type() )
|
||||
if ( ! id->GetType() )
|
||||
{
|
||||
id->Error("undeclared variable");
|
||||
id->SetType(error_type());
|
||||
|
@ -706,7 +704,7 @@ expr:
|
|||
|
||||
else if ( id->IsEnumConst() )
|
||||
{
|
||||
EnumType* t = id->Type()->AsEnumType();
|
||||
EnumType* t = id->GetType()->AsEnumType();
|
||||
int intval = t->Lookup(id->ModuleName(),
|
||||
id->Name());
|
||||
if ( intval < 0 )
|
||||
|
@ -1006,7 +1004,7 @@ type:
|
|||
|
||||
| resolve_id
|
||||
{
|
||||
if ( ! $1 || ! ($$ = $1->IsType() ? $1->Type() : nullptr) )
|
||||
if ( ! $1 || ! ($$ = $1->IsType() ? $1->GetType().get() : nullptr) )
|
||||
{
|
||||
NullStmt here;
|
||||
if ( $1 )
|
||||
|
@ -1137,7 +1135,7 @@ decl:
|
|||
{
|
||||
cur_decl_type_id = 0;
|
||||
|
||||
if ( ! $3->Type() )
|
||||
if ( ! $3->GetType() )
|
||||
$3->Error("unknown identifier");
|
||||
else
|
||||
extend_record($3, $8, $11);
|
||||
|
@ -1817,7 +1815,7 @@ global_or_event_id:
|
|||
|
||||
if ( $$->IsDeprecated() )
|
||||
{
|
||||
BroType* t = $$->Type();
|
||||
const auto& t = $$->GetType();
|
||||
|
||||
if ( t->Tag() != TYPE_FUNC ||
|
||||
t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION )
|
||||
|
|
|
@ -1171,7 +1171,7 @@ IntrusivePtr<RecordVal> Supervisor::Node::ToRecord() const
|
|||
|
||||
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 ) {
|
||||
case BifEnum::Supervisor::LOGGER:
|
||||
|
@ -1192,7 +1192,7 @@ bool Supervisor::SupervisedNode::InitCluster() const
|
|||
if ( config.cluster.empty() )
|
||||
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_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger");
|
||||
auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal();
|
||||
|
|
|
@ -1951,7 +1951,7 @@ function global_ids%(%): id_table
|
|||
{
|
||||
ID* id = global.second.get();
|
||||
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(2, val_mgr->Bool(id->IsConst()));
|
||||
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());
|
||||
|
||||
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");
|
||||
IntrusivePtr<TableType> tt{NewRef{}, internal_type("record_field_table")->AsTableType()};
|
||||
return make_intrusive<TableVal>(std::move(tt));
|
||||
}
|
||||
|
||||
return id->Type()->AsRecordType()->GetRecordFieldsVal();
|
||||
return id->GetType()->AsRecordType()->GetRecordFieldsVal();
|
||||
}
|
||||
|
||||
return rec->GetRecordFields();
|
||||
|
|
|
@ -116,7 +116,7 @@ string IdentifierInfo::DoReStructuredText(bool roles_only) const
|
|||
if ( i > 0 )
|
||||
d.NL();
|
||||
|
||||
if ( IsFunc(id->Type()->Tag()) )
|
||||
if ( IsFunc(id->GetType()->Tag()) )
|
||||
{
|
||||
string s = comments[i];
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ void Manager::StartType(IntrusivePtr<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)
|
||||
|
@ -300,7 +300,7 @@ void Manager::Identifier(IntrusivePtr<ID> id)
|
|||
|
||||
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).
|
||||
id_info->AddComments(comment_buffer);
|
||||
|
|
|
@ -191,9 +191,9 @@ void ScriptInfo::DoInitPostScript()
|
|||
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:
|
||||
DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a hook",
|
||||
id->Name(), name.c_str());
|
||||
|
@ -243,7 +243,7 @@ void ScriptInfo::DoInitPostScript()
|
|||
continue;
|
||||
}
|
||||
|
||||
if ( id->Type()->Tag() == TYPE_ENUM )
|
||||
if ( id->GetType()->Tag() == TYPE_ENUM )
|
||||
// Enums are always referenced/documented from the type's
|
||||
// documentation.
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue