refactor(userspace/engine): add run() overload in filter_macro_resolver to support shared_ptrs

This change allows working with safety with AST nodes wrapped into shared pointers.

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
Jason Dellaluce 2022-04-06 13:00:26 +00:00 committed by poiana
parent cf83a91d4e
commit c2cac5af92
2 changed files with 19 additions and 0 deletions

View File

@ -34,6 +34,20 @@ bool filter_macro_resolver::run(libsinsp::filter::ast::expr*& filter)
return !m_resolved_macros.empty();
}
bool filter_macro_resolver::run(std::shared_ptr<libsinsp::filter::ast::expr>& filter)
{
m_unknown_macros.clear();
m_resolved_macros.clear();
m_last_node_changed = false;
m_last_node = filter.get();
filter->accept(this);
if (m_last_node_changed)
{
filter.reset(m_last_node);
}
return !m_resolved_macros.empty();
}
void filter_macro_resolver::set_macro(
string name,
shared_ptr<libsinsp::filter::ast::expr> macro)

View File

@ -40,6 +40,11 @@ class filter_macro_resolver: private libsinsp::filter::ast::expr_visitor
\return true if at least one of the defined macros is resolved
*/
bool run(libsinsp::filter::ast::expr*& filter);
/*!
\brief Version of run() that works with shared pointers
*/
bool run(std::shared_ptr<libsinsp::filter::ast::expr>& filter);
/*!
\brief Defines a new macro to be substituted in filters. If called