diff options
author | Taylor Blau <me@ttaylorr.com> | 2022-01-06 22:50:12 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-01-07 00:14:55 +0300 |
commit | f2d275984d2b931b51f39d4019e78031a36cb2f0 (patch) | |
tree | 202aaf8fc8b07516953472ba588eb8fa33ae1c4b /grep.c | |
parent | e2b154277addad0a70b23d03c9156ac8e08c4a82 (diff) |
grep: extract grep_binexp() from grep_or_expr()
When constructing an OR node, the grep.c code uses `grep_or_expr()` to
make a node, assign its kind, and set its left and right children. The
same is not done for AND nodes.
Prepare to introduce a new `grep_and_expr()` function which will share
code with the existing implementation of `grep_or_expr()` by introducing
a new function which compiles either kind of binary expression, and
reimplement `grep_or_expr()` in terms of it.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -603,15 +603,22 @@ static struct grep_expr *grep_not_expr(struct grep_expr *expr) return z; } -static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right) +static struct grep_expr *grep_binexp(enum grep_expr_node kind, + struct grep_expr *left, + struct grep_expr *right) { struct grep_expr *z = xcalloc(1, sizeof(*z)); - z->node = GREP_NODE_OR; + z->node = kind; z->u.binary.left = left; z->u.binary.right = right; return z; } +static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right) +{ + return grep_binexp(GREP_NODE_OR, left, right); +} + static struct grep_expr *compile_pattern_or(struct grep_pat **); static struct grep_expr *compile_pattern_atom(struct grep_pat **list) { |