Skip to content

Commit

Permalink
filterx: simplify constructors for nullv assignments
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Dec 30, 2024
1 parent e2f5242 commit fbe55f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 46 deletions.
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;
}
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;
}

0 comments on commit fbe55f3

Please sign in to comment.