mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
tracking of expressions used to define/redef variables
This commit is contained in:
parent
1f15f53f4b
commit
cf79c05e3a
3 changed files with 21 additions and 1 deletions
|
@ -285,6 +285,11 @@ const AttrPtr& ID::GetAttr(AttrTag t) const
|
||||||
return attrs ? attrs->Find(t) : Attr::nil;
|
return attrs ? attrs->Find(t) : Attr::nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ID::AddInitExpr(ExprPtr init_expr)
|
||||||
|
{
|
||||||
|
init_exprs.emplace_back(std::move(init_expr));
|
||||||
|
}
|
||||||
|
|
||||||
bool ID::IsDeprecated() const
|
bool ID::IsDeprecated() const
|
||||||
{
|
{
|
||||||
return GetAttr(ATTR_DEPRECATED) != nullptr;
|
return GetAttr(ATTR_DEPRECATED) != nullptr;
|
||||||
|
|
11
src/ID.h
11
src/ID.h
|
@ -112,6 +112,10 @@ public:
|
||||||
|
|
||||||
const AttrPtr& GetAttr(AttrTag t) const;
|
const AttrPtr& GetAttr(AttrTag t) const;
|
||||||
|
|
||||||
|
void AddInitExpr(ExprPtr init_expr);
|
||||||
|
const std::vector<ExprPtr>& GetInitExprs() const
|
||||||
|
{ return init_exprs; }
|
||||||
|
|
||||||
bool IsDeprecated() const;
|
bool IsDeprecated() const;
|
||||||
|
|
||||||
void MakeDeprecated(ExprPtr deprecation);
|
void MakeDeprecated(ExprPtr deprecation);
|
||||||
|
@ -156,6 +160,13 @@ protected:
|
||||||
int offset;
|
int offset;
|
||||||
ValPtr val;
|
ValPtr val;
|
||||||
AttributesPtr attrs;
|
AttributesPtr attrs;
|
||||||
|
|
||||||
|
// Expressions used to initialize the identifier, for use by
|
||||||
|
// the scripts-to-C++ compiler. We need to track all of them
|
||||||
|
// because it's possible that a global value gets created using
|
||||||
|
// one of the earlier instances rather than the last one.
|
||||||
|
std::vector<ExprPtr> init_exprs;
|
||||||
|
|
||||||
// contains list of functions that are called when an option changes
|
// contains list of functions that are called when an option changes
|
||||||
std::multimap<int, FuncPtr> option_handlers;
|
std::multimap<int, FuncPtr> option_handlers;
|
||||||
|
|
||||||
|
|
|
@ -244,6 +244,8 @@ static void build_global(ID* id, Type* t, InitClass ic, Expr* e,
|
||||||
|
|
||||||
add_global(id_ptr, std::move(t_ptr), ic, e_ptr, std::move(attrs_ptr), dt);
|
add_global(id_ptr, std::move(t_ptr), ic, e_ptr, std::move(attrs_ptr), dt);
|
||||||
|
|
||||||
|
id->AddInitExpr(e_ptr);
|
||||||
|
|
||||||
if ( dt == VAR_REDEF )
|
if ( dt == VAR_REDEF )
|
||||||
zeekygen_mgr->Redef(id, ::filename, ic, std::move(e_ptr));
|
zeekygen_mgr->Redef(id, ::filename, ic, std::move(e_ptr));
|
||||||
else
|
else
|
||||||
|
@ -261,7 +263,9 @@ static StmtPtr build_local(ID* id, Type* t, InitClass ic, Expr* e,
|
||||||
auto attrs_ptr = attrs ? std::make_unique<std::vector<AttrPtr>>(*attrs) : nullptr;
|
auto attrs_ptr = attrs ? std::make_unique<std::vector<AttrPtr>>(*attrs) : nullptr;
|
||||||
|
|
||||||
auto init = add_local(std::move(id_ptr), std::move(t_ptr), ic,
|
auto init = add_local(std::move(id_ptr), std::move(t_ptr), ic,
|
||||||
std::move(e_ptr), std::move(attrs_ptr), dt);
|
e_ptr, std::move(attrs_ptr), dt);
|
||||||
|
|
||||||
|
id->AddInitExpr(std::move(e_ptr));
|
||||||
|
|
||||||
if ( do_coverage )
|
if ( do_coverage )
|
||||||
script_coverage_mgr.AddStmt(init.get());
|
script_coverage_mgr.AddStmt(init.get());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue