From fbe55f3a38695570fb2fce7f87870b5ced544422 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Mon, 23 Dec 2024 14:50:27 +0100 Subject: [PATCH] filterx: simplify constructors for nullv assignments Signed-off-by: Balazs Scheidler --- lib/filterx/expr-assign.c | 19 +++++++++---------- lib/filterx/expr-set-subscript.c | 24 ++++++++---------------- lib/filterx/expr-setattr.c | 30 ++++++++++-------------------- 3 files changed, 27 insertions(+), 46 deletions(-) diff --git a/lib/filterx/expr-assign.c b/lib/filterx/expr-assign.c index 0f4ff3baa..55581d8fe 100644 --- a/lib/filterx/expr-assign.c +++ b/lib/filterx/expr-assign.c @@ -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 * @@ -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; +} diff --git a/lib/filterx/expr-set-subscript.c b/lib/filterx/expr-set-subscript.c index dbcb9e1c7..3c9ffe985 100644 --- a/lib/filterx/expr-set-subscript.c +++ b/lib/filterx/expr-set-subscript.c @@ -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; @@ -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; } diff --git a/lib/filterx/expr-setattr.c b/lib/filterx/expr-setattr.c index aaa21ae86..ad8c5536c 100644 --- a/lib/filterx/expr-setattr.c +++ b/lib/filterx/expr-setattr.c @@ -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; @@ -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; }