mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Change Scope::GenerateTemporary() to return IntrusivePtr
This commit is contained in:
parent
a13899c95e
commit
46e23b49fb
5 changed files with 24 additions and 22 deletions
|
@ -72,9 +72,9 @@ IntrusivePtr<ID> Scope::Remove(std::string_view name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ID* Scope::GenerateTemporary(const char* name)
|
||||
IntrusivePtr<ID> Scope::GenerateTemporary(const char* name)
|
||||
{
|
||||
return new ID(name, SCOPE_FUNCTION, false);
|
||||
return make_intrusive<ID>(name, SCOPE_FUNCTION, false);
|
||||
}
|
||||
|
||||
id_list* Scope::GetInits()
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
size_t Length() const { return local.size(); }
|
||||
const auto& Vars() { return local; }
|
||||
|
||||
ID* GenerateTemporary(const char* name);
|
||||
IntrusivePtr<ID> GenerateTemporary(const char* name);
|
||||
|
||||
// Returns the list of variables needing initialization, and
|
||||
// removes it from this Scope.
|
||||
|
|
13
src/Var.cc
13
src/Var.cc
|
@ -458,8 +458,9 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl
|
|||
return true;
|
||||
}
|
||||
|
||||
void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
||||
bool is_redef, IntrusivePtr<FuncType> t,
|
||||
void begin_func(IntrusivePtr<ID> id, const char* module_name,
|
||||
function_flavor flavor, bool is_redef,
|
||||
IntrusivePtr<FuncType> t,
|
||||
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs)
|
||||
{
|
||||
if ( flavor == FUNC_FLAVOR_EVENT )
|
||||
|
@ -512,7 +513,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
|||
}
|
||||
|
||||
if ( prototype->deprecated )
|
||||
t->Warn("use of deprecated prototype", id);
|
||||
t->Warn("use of deprecated prototype", id.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -521,7 +522,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
|||
if ( canonical_arg_types_match(decl, t.get()) )
|
||||
prototype = decl->Prototypes()[0];
|
||||
else
|
||||
t->Error("use of undeclared alternate prototype", id);
|
||||
t->Error("use of undeclared alternate prototype", id.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,7 +558,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
|||
else
|
||||
id->SetType(t);
|
||||
|
||||
push_scope({NewRef{}, id}, std::move(attrs));
|
||||
push_scope(std::move(id), std::move(attrs));
|
||||
|
||||
const auto& args = t->Params();
|
||||
int num_args = args->NumFields();
|
||||
|
@ -579,7 +580,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
|||
|
||||
if ( Attr* depr_attr = find_attr(current_scope()->Attrs().get(),
|
||||
ATTR_DEPRECATED) )
|
||||
id->MakeDeprecated(depr_attr->GetExpr());
|
||||
current_scope()->GetID()->MakeDeprecated(depr_attr->GetExpr());
|
||||
}
|
||||
|
||||
class OuterIDBindingFinder : public TraversalCallback {
|
||||
|
|
|
@ -38,8 +38,9 @@ extern IntrusivePtr<Expr> add_and_assign_local(IntrusivePtr<ID> id,
|
|||
extern void add_type(ID* id, IntrusivePtr<BroType> t,
|
||||
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr);
|
||||
|
||||
extern void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
||||
bool is_redef, IntrusivePtr<FuncType> t,
|
||||
extern void begin_func(IntrusivePtr<ID> id, const char* module_name,
|
||||
function_flavor flavor, bool is_redef,
|
||||
IntrusivePtr<FuncType> t,
|
||||
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs = nullptr);
|
||||
|
||||
extern void end_func(IntrusivePtr<Stmt> body);
|
||||
|
|
22
src/parse.y
22
src/parse.y
|
@ -134,7 +134,6 @@ bool resolving_global_ID = false;
|
|||
bool defining_global_ID = false;
|
||||
std::vector<int> saved_in_init;
|
||||
|
||||
ID* func_id = 0;
|
||||
static Location func_hdr_location;
|
||||
EnumType *cur_enum_type = 0;
|
||||
static ID* cur_decl_type_id = 0;
|
||||
|
@ -496,15 +495,15 @@ expr:
|
|||
| '$' TOK_ID func_params '='
|
||||
{
|
||||
func_hdr_location = @1;
|
||||
func_id = current_scope()->GenerateTemporary("anonymous-function");
|
||||
auto func_id = current_scope()->GenerateTemporary("anonymous-function");
|
||||
func_id->SetInferReturnType(true);
|
||||
begin_func(func_id, current_module.c_str(), FUNC_FLAVOR_FUNCTION,
|
||||
0, {AdoptRef{}, $3});
|
||||
begin_func(std::move(func_id), current_module.c_str(),
|
||||
FUNC_FLAVOR_FUNCTION, false,
|
||||
{AdoptRef{}, $3});
|
||||
}
|
||||
lambda_body
|
||||
{
|
||||
$$ = new FieldAssignExpr($2, IntrusivePtr{AdoptRef{}, $6});
|
||||
Unref(func_id);
|
||||
}
|
||||
|
||||
| expr TOK_IN expr
|
||||
|
@ -1180,7 +1179,7 @@ func_hdr:
|
|||
TOK_FUNCTION def_global_id func_params opt_attr
|
||||
{
|
||||
IntrusivePtr id{AdoptRef{}, $2};
|
||||
begin_func(id.get(), current_module.c_str(),
|
||||
begin_func(id, current_module.c_str(),
|
||||
FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3},
|
||||
std::unique_ptr<std::vector<IntrusivePtr<Attr>>>{$4});
|
||||
$$ = $3;
|
||||
|
@ -1195,7 +1194,7 @@ func_hdr:
|
|||
reporter->Error("event %s() is no longer available, use zeek_%s() instead", name, base.c_str());
|
||||
}
|
||||
|
||||
begin_func($2, current_module.c_str(),
|
||||
begin_func({NewRef{}, $2}, current_module.c_str(),
|
||||
FUNC_FLAVOR_EVENT, 0, {NewRef{}, $3},
|
||||
std::unique_ptr<std::vector<IntrusivePtr<Attr>>>{$4});
|
||||
$$ = $3;
|
||||
|
@ -1204,14 +1203,14 @@ func_hdr:
|
|||
{
|
||||
$3->ClearYieldType(FUNC_FLAVOR_HOOK);
|
||||
$3->SetYieldType(base_type(TYPE_BOOL));
|
||||
begin_func($2, current_module.c_str(),
|
||||
begin_func({NewRef{}, $2}, current_module.c_str(),
|
||||
FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3},
|
||||
std::unique_ptr<std::vector<IntrusivePtr<Attr>>>{$4});
|
||||
$$ = $3;
|
||||
}
|
||||
| TOK_REDEF TOK_EVENT event_id func_params opt_attr
|
||||
{
|
||||
begin_func($3, current_module.c_str(),
|
||||
begin_func({NewRef{}, $3}, current_module.c_str(),
|
||||
FUNC_FLAVOR_EVENT, 1, {NewRef{}, $4},
|
||||
std::unique_ptr<std::vector<IntrusivePtr<Attr>>>{$5});
|
||||
$$ = $4;
|
||||
|
@ -1275,8 +1274,9 @@ anonymous_function:
|
|||
begin_func:
|
||||
func_params
|
||||
{
|
||||
$$ = current_scope()->GenerateTemporary("anonymous-function");
|
||||
begin_func($$, current_module.c_str(), FUNC_FLAVOR_FUNCTION, 0, {AdoptRef{}, $1});
|
||||
auto id = current_scope()->GenerateTemporary("anonymous-function");
|
||||
begin_func(id, current_module.c_str(), FUNC_FLAVOR_FUNCTION, 0, {AdoptRef{}, $1});
|
||||
$$ = id.release();
|
||||
}
|
||||
;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue