update(userspace/engine): support undefining macros

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
Jason Dellaluce 2022-03-17 17:35:50 +00:00 committed by poiana
parent 20c59970f5
commit a0a87e443f
2 changed files with 3 additions and 3 deletions

View File

@ -38,7 +38,6 @@ void filter_macro_resolver::set_macro(
string name,
shared_ptr<libsinsp::filter::ast::expr> macro)
{
auto it = m_macros.find(name);
m_macros[name] = macro;
}
@ -120,7 +119,7 @@ void filter_macro_resolver::visit(ast::value_expr* e)
// of identier-only children from either a 'not',
// an 'and' or an 'or'.
auto macro = m_macros.find(e->value);
if (macro != m_macros.end())
if (macro != m_macros.end() && macro->second) // skip null-ptr macros
{
ast::expr* new_node = ast::clone(macro->second.get());
new_node->accept(this); // this sets m_last_node

View File

@ -44,7 +44,8 @@ class filter_macro_resolver: private libsinsp::filter::ast::expr_visitor
/*!
\brief Defines a new macro to be substituted in filters. If called
multiple times for the same macro name, the previous definition
gets overridden.
gets overridden. A macro can be undefined by setting a null
AST pointer.
\param name The name of the macro.
\param macro The AST of the macro.
*/