Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filterx expr constructor improvements #445

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/filterx/expr-assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ _assign_eval(FilterXExpr *s)
return _assign(self, value);
}

FilterXExpr *
filterx_nullv_assign_new(FilterXExpr *lhs, FilterXExpr *rhs)
{
FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1);

filterx_binary_op_init_instance(self, "nullv_assign", lhs, rhs);
self->super.eval = _nullv_assign_eval;
self->super.ignore_falsy_result = TRUE;
return &self->super;
}

/* NOTE: takes the object reference */
FilterXExpr *
Expand All @@ -113,3 +103,12 @@ filterx_assign_new(FilterXExpr *lhs, FilterXExpr *rhs)
self->super.ignore_falsy_result = TRUE;
return &self->super;
}

FilterXExpr *
filterx_nullv_assign_new(FilterXExpr *lhs, FilterXExpr *rhs)
{
FilterXExpr *self = filterx_assign_new(lhs, rhs);
self->type = "nullv_assign";
self->eval = _nullv_assign_eval;
return self;
}
6 changes: 3 additions & 3 deletions lib/filterx/expr-comparison.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ _eval_based_on_compare_mode(FilterXExpr *expr, gint compare_mode)
}

static FilterXObject *
_eval(FilterXExpr *s)
_eval_comparison(FilterXExpr *s)
{
FilterXComparison *self = (FilterXComparison *) s;

Expand Down Expand Up @@ -250,7 +250,7 @@ _optimize(FilterXExpr *s)
self->literal_rhs = _eval_based_on_compare_mode(self->super.rhs, compare_mode);

if (self->literal_lhs && self->literal_rhs)
return filterx_literal_new(_eval(&self->super.super));
return filterx_literal_new(_eval_comparison(&self->super.super));

return NULL;
}
Expand All @@ -273,7 +273,7 @@ filterx_comparison_new(FilterXExpr *lhs, FilterXExpr *rhs, gint operator)

filterx_binary_op_init_instance(&self->super, "comparison", lhs, rhs);
self->super.super.optimize = _optimize;
self->super.super.eval = _eval;
self->super.super.eval = _eval_comparison;
self->super.super.free_fn = _filterx_comparison_free;
self->operator = operator;

Expand Down
4 changes: 2 additions & 2 deletions lib/filterx/expr-compound.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ _eval_exprs(FilterXCompoundExpr *self, FilterXObject **result)
}

static FilterXObject *
_eval(FilterXExpr *s)
_eval_compound(FilterXExpr *s)
{
FilterXCompoundExpr *self = (FilterXCompoundExpr *) s;
FilterXObject *result = NULL;
Expand Down Expand Up @@ -220,7 +220,7 @@ filterx_compound_expr_new(gboolean return_value_of_last_expr)
FilterXCompoundExpr *self = g_new0(FilterXCompoundExpr, 1);

filterx_expr_init_instance(&self->super, "compound");
self->super.eval = _eval;
self->super.eval = _eval_compound;
self->super.optimize = _optimize;
self->super.init = _init;
self->super.deinit = _deinit;
Expand Down
6 changes: 3 additions & 3 deletions lib/filterx/expr-condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ _free(FilterXExpr *s)
}

static FilterXObject *
_eval(FilterXExpr *s)
_eval_conditional(FilterXExpr *s)
{
FilterXConditional *self = (FilterXConditional *) s;
FilterXObject *condition_value = filterx_expr_eval(self->condition);
Expand Down Expand Up @@ -201,7 +201,7 @@ filterx_conditional_new(FilterXExpr *condition)
{
FilterXConditional *self = g_new0(FilterXConditional, 1);
filterx_expr_init_instance(&self->super, "conditional");
self->super.eval = _eval;
self->super.eval = _eval_conditional;
self->super.optimize = _optimize;
self->super.init = _init;
self->super.deinit = _deinit;
Expand All @@ -215,7 +215,7 @@ FilterXExpr *
filterx_conditional_find_tail(FilterXExpr *s)
{
/* check if this is a FilterXConditional instance */
if (s->eval != _eval)
if (s->eval != _eval_conditional)
return NULL;

FilterXConditional *self = (FilterXConditional *) s;
Expand Down
4 changes: 2 additions & 2 deletions lib/filterx/expr-done.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "filterx/object-primitive.h"

static FilterXObject *
_eval(FilterXExpr *s)
_eval_done(FilterXExpr *s)
{
FilterXEvalContext *context = filterx_eval_get_context();
context->eval_control_modifier = FXC_DONE;
Expand All @@ -41,7 +41,7 @@ filterx_expr_done(void)
{
FilterXExpr *self = g_new0(FilterXExpr, 1);
filterx_expr_init_instance(self, "done");
self->eval = _eval;
self->eval = _eval_done;

return self;
}
4 changes: 2 additions & 2 deletions lib/filterx/expr-drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "filterx/object-primitive.h"

static FilterXObject *
_eval(FilterXExpr *s)
_eval_drop(FilterXExpr *s)
{
FilterXEvalContext *context = filterx_eval_get_context();
context->eval_control_modifier = FXC_DROP;
Expand All @@ -40,7 +40,7 @@ filterx_expr_drop_msg(void)
{
FilterXExpr *self = g_new0(FilterXExpr, 1);
filterx_expr_init_instance(self, "drop");
self->eval = _eval;
self->eval = _eval_drop;

return self;
}
6 changes: 3 additions & 3 deletions lib/filterx/expr-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ filterx_generator_set_fillable(FilterXExpr *s, FilterXExpr *fillable)
}

static FilterXObject *
_eval(FilterXExpr *s)
_eval_generator(FilterXExpr *s)
{
FilterXExprGenerator *self = (FilterXExprGenerator *) s;

Expand All @@ -52,7 +52,7 @@ _eval(FilterXExpr *s)
gboolean
filterx_expr_is_generator(FilterXExpr *s)
{
return s && s->eval == _eval;
return s && s->eval == _eval_generator;
}

FilterXExpr *
Expand All @@ -71,7 +71,7 @@ filterx_generator_init_instance(FilterXExpr *s)
s->optimize = filterx_generator_optimize_method;
s->init = filterx_generator_init_method;
s->deinit = filterx_generator_deinit_method;
s->eval = _eval;
s->eval = _eval_generator;
s->ignore_falsy_result = TRUE;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/filterx/expr-get-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct _FilterXGetSubscript
} FilterXGetSubscript;

static FilterXObject *
_eval(FilterXExpr *s)
_eval_get_subscript(FilterXExpr *s)
{
FilterXGetSubscript *self = (FilterXGetSubscript *) s;
FilterXObject *result = NULL;
Expand Down Expand Up @@ -158,7 +158,7 @@ filterx_get_subscript_new(FilterXExpr *operand, FilterXExpr *key)
FilterXGetSubscript *self = g_new0(FilterXGetSubscript, 1);

filterx_expr_init_instance(&self->super, "get_subscript");
self->super.eval = _eval;
self->super.eval = _eval_get_subscript;
self->super.is_set = _isset;
self->super.unset = _unset;
self->super.optimize = _optimize;
Expand Down
4 changes: 2 additions & 2 deletions lib/filterx/expr-getattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct _FilterXGetAttr
} FilterXGetAttr;

static FilterXObject *
_eval(FilterXExpr *s)
_eval_getattr(FilterXExpr *s)
{
FilterXGetAttr *self = (FilterXGetAttr *) s;

Expand Down Expand Up @@ -137,7 +137,7 @@ filterx_getattr_new(FilterXExpr *operand, FilterXString *attr_name)
FilterXGetAttr *self = g_new0(FilterXGetAttr, 1);

filterx_expr_init_instance(&self->super, "getattr");
self->super.eval = _eval;
self->super.eval = _eval_getattr;
self->super.unset = _unset;
self->super.is_set = _isset;
self->super.optimize = _optimize;
Expand Down
4 changes: 2 additions & 2 deletions lib/filterx/expr-isset.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "filterx/object-primitive.h"

static FilterXObject *
_eval(FilterXExpr *s)
_eval_isset(FilterXExpr *s)
{
FilterXUnaryOp *self = (FilterXUnaryOp *) s;

Expand All @@ -37,6 +37,6 @@ filterx_isset_new(FilterXExpr *expr)
{
FilterXUnaryOp *self = g_new0(FilterXUnaryOp, 1);
filterx_unary_op_init_instance(self, "isset", expr);
self->super.eval = _eval;
self->super.eval = _eval_isset;
return &self->super;
}
6 changes: 3 additions & 3 deletions lib/filterx/expr-literal.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef struct _FilterXLiteral
} FilterXLiteral;

static FilterXObject *
_eval(FilterXExpr *s)
_eval_literal(FilterXExpr *s)
{
FilterXLiteral *self = (FilterXLiteral *) s;
return filterx_object_ref(self->object);
Expand All @@ -50,7 +50,7 @@ filterx_literal_new(FilterXObject *object)
FilterXLiteral *self = g_new0(FilterXLiteral, 1);

filterx_expr_init_instance(&self->super, "literal");
self->super.eval = _eval;
self->super.eval = _eval_literal;
self->super.free_fn = _free;
self->object = object;
return &self->super;
Expand All @@ -59,5 +59,5 @@ filterx_literal_new(FilterXObject *object)
gboolean
filterx_expr_is_literal(FilterXExpr *expr)
{
return expr->eval == _eval;
return expr->eval == _eval_literal;
}
4 changes: 2 additions & 2 deletions lib/filterx/expr-null-coalesce.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct _FilterXNullCoalesce
};

static FilterXObject *
_eval(FilterXExpr *s)
_eval_null_coalesce(FilterXExpr *s)
{
FilterXNullCoalesce *self = (FilterXNullCoalesce *) s;

Expand Down Expand Up @@ -86,7 +86,7 @@ filterx_null_coalesce_new(FilterXExpr *lhs, FilterXExpr *rhs)
{
FilterXNullCoalesce *self = g_new0(FilterXNullCoalesce, 1);
filterx_binary_op_init_instance(&self->super, "null_coalesce", lhs, rhs);
self->super.super.eval = _eval;
self->super.super.eval = _eval_null_coalesce;
self->super.super.optimize = _optimize;
return &self->super.super;
}
6 changes: 3 additions & 3 deletions lib/filterx/expr-plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct FilterXOperatorPlus
} FilterXOperatorPlus;

static FilterXObject *
_eval(FilterXExpr *s)
_eval_plus(FilterXExpr *s)
{
FilterXOperatorPlus *self = (FilterXOperatorPlus *) s;

Expand Down Expand Up @@ -72,7 +72,7 @@ _optimize(FilterXExpr *s)
self->literal_rhs = filterx_expr_eval(self->super.rhs);

if (self->literal_lhs && self->literal_rhs)
return filterx_literal_new(_eval(&self->super.super));
return filterx_literal_new(_eval_plus(&self->super.super));
return NULL;
}

Expand All @@ -92,7 +92,7 @@ filterx_operator_plus_new(FilterXExpr *lhs, FilterXExpr *rhs)
FilterXOperatorPlus *self = g_new0(FilterXOperatorPlus, 1);
filterx_binary_op_init_instance(&self->super, "plus", lhs, rhs);
self->super.super.optimize = _optimize;
self->super.super.eval = _eval;
self->super.super.eval = _eval_plus;
self->super.super.free_fn = _filterx_operator_plus_free;

return &self->super.super;
Expand Down
24 changes: 8 additions & 16 deletions lib/filterx/expr-set-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ _free(FilterXExpr *s)
}

FilterXExpr *
filterx_nullv_set_subscript_new(FilterXExpr *object, FilterXExpr *key, FilterXExpr *new_value)
filterx_set_subscript_new(FilterXExpr *object, FilterXExpr *key, FilterXExpr *new_value)
{
FilterXSetSubscript *self = g_new0(FilterXSetSubscript, 1);

filterx_expr_init_instance(&self->super, "nullv_set_subscript");
self->super.eval = _nullv_set_subscript_eval;
filterx_expr_init_instance(&self->super, "set_subscript");
self->super.eval = _set_subscript_eval;
self->super.optimize = _optimize;
self->super.init = _init;
self->super.deinit = _deinit;
Expand All @@ -224,19 +224,11 @@ filterx_nullv_set_subscript_new(FilterXExpr *object, FilterXExpr *key, FilterXEx
}

FilterXExpr *
filterx_set_subscript_new(FilterXExpr *object, FilterXExpr *key, FilterXExpr *new_value)
filterx_nullv_set_subscript_new(FilterXExpr *object, FilterXExpr *key, FilterXExpr *new_value)
{
FilterXSetSubscript *self = g_new0(FilterXSetSubscript, 1);
FilterXExpr *self = filterx_set_subscript_new(object, key, new_value);

filterx_expr_init_instance(&self->super, "set_subscript");
self->super.eval = _set_subscript_eval;
self->super.optimize = _optimize;
self->super.init = _init;
self->super.deinit = _deinit;
self->super.free_fn = _free;
self->object = object;
self->key = key;
self->new_value = new_value;
self->super.ignore_falsy_result = TRUE;
return &self->super;
self->type = "nullv_set_subscript";
self->eval = _nullv_set_subscript_eval;
return self;
}
30 changes: 10 additions & 20 deletions lib/filterx/expr-setattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,14 @@ _free(FilterXExpr *s)
filterx_expr_free_method(s);
}

/* Takes reference of object and new_value */
FilterXExpr *
filterx_nullv_setattr_new(FilterXExpr *object, FilterXString *attr_name, FilterXExpr *new_value)
filterx_setattr_new(FilterXExpr *object, FilterXString *attr_name, FilterXExpr *new_value)
{
FilterXSetAttr *self = g_new0(FilterXSetAttr, 1);

filterx_expr_init_instance(&self->super, "nullv_setattr");
self->super.eval = _nullv_setattr_eval;
filterx_expr_init_instance(&self->super, "setattr");
self->super.eval = _setattr_eval;
self->super.optimize = _optimize;
self->super.init = _init;
self->super.deinit = _deinit;
Expand All @@ -196,28 +197,17 @@ filterx_nullv_setattr_new(FilterXExpr *object, FilterXString *attr_name, FilterX

self->new_value = new_value;
self->super.ignore_falsy_result = TRUE;

/* NOTE: name borrows the string value from the string object */
self->super.name = filterx_string_get_value_ref(self->attr, NULL);
return &self->super;
}

/* Takes reference of object and new_value */
FilterXExpr *
filterx_setattr_new(FilterXExpr *object, FilterXString *attr_name, FilterXExpr *new_value)
filterx_nullv_setattr_new(FilterXExpr *object, FilterXString *attr_name, FilterXExpr *new_value)
{
FilterXSetAttr *self = g_new0(FilterXSetAttr, 1);

filterx_expr_init_instance(&self->super, "setattr");
self->super.eval = _setattr_eval;
self->super.optimize = _optimize;
self->super.init = _init;
self->super.deinit = _deinit;
self->super.free_fn = _free;
self->object = object;

self->attr = (FilterXObject *) attr_name;

self->new_value = new_value;
self->super.ignore_falsy_result = TRUE;
return &self->super;
FilterXExpr *self = filterx_setattr_new(object, attr_name, new_value);
self->type = "nullv_setattr";
self->eval = _nullv_setattr_eval;
return self;
}
4 changes: 2 additions & 2 deletions lib/filterx/expr-template.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef struct _FilterXTemplate
} FilterXTemplate;

static FilterXObject *
_eval(FilterXExpr *s)
_eval_template(FilterXExpr *s)
{
FilterXTemplate *self = (FilterXTemplate *) s;
FilterXEvalContext *context = filterx_eval_get_context();
Expand Down Expand Up @@ -72,7 +72,7 @@ filterx_template_new(LogTemplate *template)
FilterXTemplate *self = g_new0(FilterXTemplate, 1);

filterx_expr_init_instance(&self->super, "template");
self->super.eval = _eval;
self->super.eval = _eval_template;
self->super.free_fn = _free;
self->template = template;
return &self->super;
Expand Down
Loading
Loading