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 small changes #443

Merged
merged 3 commits into from
Jan 17, 2025
Merged
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
4 changes: 3 additions & 1 deletion lib/filterx/filterx-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ filterx_expr_optimize(FilterXExpr *self)
optimized = filterx_expr_optimize(optimized);

msg_trace("FilterX: expression optimized",
filterx_expr_format_location_tag(self));
filterx_expr_format_location_tag(self),
evt_tag_str("old_type", self->type),
evt_tag_str("new_type", optimized->type));
bazsi marked this conversation as resolved.
Show resolved Hide resolved
if (self->lloc)
{
/* copy location information to the optimized representation */
Expand Down
23 changes: 13 additions & 10 deletions lib/filterx/filterx-grammar.ym
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,18 @@ plus_assignment
| expr '[' expr ']' KW_PLUS_ASSIGN expr { $$ = filterx_set_subscript_new(filterx_expr_ref($1), filterx_expr_ref($3), filterx_operator_plus_new(filterx_get_subscript_new($1, $3), $6)); }
| expr '.' identifier KW_PLUS_ASSIGN expr
{
$$ = filterx_setattr_new(filterx_expr_ref($1), filterx_config_frozen_string(configuration, $3), filterx_operator_plus_new(filterx_getattr_new($1, filterx_config_frozen_string(configuration, $3)), $5));
free($3);
$$ = filterx_setattr_new(filterx_expr_ref($1),
filterx_config_frozen_string(configuration, $3),
filterx_operator_plus_new(filterx_getattr_new($1, filterx_config_frozen_string(configuration, $3)),
$5));
free($3);
}
;


assignment
/* TODO extract lvalues */
: variable KW_ASSIGN expr { $$ = filterx_assign_new($1, $3); }
: variable KW_ASSIGN expr { $$ = filterx_assign_new($1, $3); }
| expr '.' identifier KW_ASSIGN expr { $$ = filterx_setattr_new($1, filterx_config_frozen_string(configuration, $3), $5); free($3); }
| expr '[' expr ']' KW_ASSIGN expr { $$ = filterx_set_subscript_new($1, $3, $6); }
| expr '[' ']' KW_ASSIGN expr { $$ = filterx_set_subscript_new($1, NULL, $5); }
Expand Down Expand Up @@ -308,7 +311,7 @@ generator_assignment
;

generator_plus_assignment
: variable KW_PLUS_ASSIGN expr_generator { $$ = $3; filterx_generator_set_fillable($3, $1); }
: variable KW_PLUS_ASSIGN expr_generator { $$ = $3; filterx_generator_set_fillable($3, $1); }
| expr '[' expr ']' KW_PLUS_ASSIGN expr_generator { $$ = $6; filterx_generator_set_fillable($6, filterx_get_subscript_new($1, $3)); }
| expr '.' identifier KW_PLUS_ASSIGN expr_generator { $$ = $5; filterx_generator_set_fillable($5, filterx_getattr_new($1, filterx_config_frozen_string(configuration, $3))); free($3);}

Expand Down Expand Up @@ -397,16 +400,16 @@ declaration
}
;

expr: __expr { $$ = $1; filterx_expr_set_location($1, lexer, &@1); }
expr: __expr { $$ = _assign_location($1, lexer, &@1); }

__expr
: expr_value
| function_call
| expr_operator
| '(' expr ')' { $$ = $2; }
| KW_ISSET '(' expr ')' { $$ = filterx_isset_new($3); }
| KW_DROP { $$ = filterx_expr_drop_msg(); }
| KW_DONE { $$ = filterx_expr_done(); }
| '(' expr ')' { $$ = $2; }
| KW_ISSET '(' expr ')' { $$ = filterx_isset_new($3); }
| KW_DROP { $$ = filterx_expr_drop_msg(); }
| KW_DONE { $$ = filterx_expr_done(); }
;

expr_operator
Expand All @@ -417,7 +420,7 @@ expr_operator
| default
/* TODO extract lvalues */
| expr '.' identifier { $$ = filterx_getattr_new($1, filterx_config_frozen_string(configuration, $3)); free($3); }
| expr '[' expr ']' { $$ = filterx_get_subscript_new($1, $3); }
| expr '[' expr ']' { $$ = filterx_get_subscript_new($1, $3); }
;

boolalg_operator
Expand Down
6 changes: 2 additions & 4 deletions lib/filterx/filterx-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,10 @@ _filterx_ref_add(FilterXObject *s, FilterXObject *object)
return filterx_object_add_object(self->value, object);
}

/* NOTE: fastpath is in the header as an inline function */
FilterXObject *
filterx_ref_new(FilterXObject *value)
_filterx_ref_new(FilterXObject *value)
{
if (!value || value->readonly || !_filterx_type_is_referenceable(value->type))
return value;

if (filterx_object_is_type(value, &FILTERX_TYPE_NAME(ref)))
{
FilterXRef *absorbed_ref = (FilterXRef *) value;
Expand Down
12 changes: 10 additions & 2 deletions lib/filterx/filterx-ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ typedef struct _FilterXRef
} FilterXRef;


FilterXObject *filterx_ref_new(FilterXObject *value);

/* Call them only where downcasting to a specific type is needed, the returned object should only be used locally. */
FilterXObject *filterx_ref_unwrap_ro(FilterXObject *s);
FilterXObject *filterx_ref_unwrap_rw(FilterXObject *s);
Expand All @@ -60,4 +58,14 @@ _filterx_type_is_referenceable(FilterXType *t)
return t->is_mutable && t != &FILTERX_TYPE_NAME(ref);
}

FilterXObject *_filterx_ref_new(FilterXObject *value);

static inline FilterXObject *
filterx_ref_new(FilterXObject *value)
{
if (!value || value->readonly || !_filterx_type_is_referenceable(value->type))
return value;
return _filterx_ref_new(value);
}

#endif
Loading