From 6961c9a4c2fe8612db222bfd1693e38f7a43a2cd Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 29 Nov 2022 16:07:17 -0500 Subject: expr: Remove the synthetic flag Only diagnostics cares about this, and we can just check if the pointers are equal. --- src/diag.c | 14 ++++++++------ src/expr.h | 2 -- src/opt.c | 5 ----- src/parse.c | 9 --------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/diag.c b/src/diag.c index 80d988f..c5e139e 100644 --- a/src/diag.c +++ b/src/diag.c @@ -114,12 +114,14 @@ static bool highlight_expr_recursive(const struct bfs_ctx *ctx, const struct bfs bool ret = false; - if (!expr->synthetic) { - size_t i = expr->argv - ctx->argv; - for (size_t j = 0; j < expr->argc; ++j) { - assert(i + j < ctx->argc); - args[i + j] = true; - ret = true; + for (size_t i = 0; i < ctx->argc; ++i) { + if (&ctx->argv[i] == expr->argv) { + for (size_t j = 0; j < expr->argc; ++j) { + assert(i + j < ctx->argc); + args[i + j] = true; + ret = true; + } + break; } } diff --git a/src/expr.h b/src/expr.h index 22f569e..2de8958 100644 --- a/src/expr.h +++ b/src/expr.h @@ -110,8 +110,6 @@ struct bfs_expr { bool always_true; /** Whether this expression always evaluates to false. */ bool always_false; - /** Whether this expression doesn't appear on the command line. */ - bool synthetic; /** Estimated cost. */ float cost; diff --git a/src/opt.c b/src/opt.c index fa2e66c..f7f80d7 100644 --- a/src/opt.c +++ b/src/opt.c @@ -366,10 +366,6 @@ static struct bfs_expr *negate_expr(struct bfs_expr *rhs, char **argv) { return NULL; } - if (argv == &fake_not_arg) { - expr->synthetic = true; - } - expr->lhs = NULL; expr->rhs = rhs; return expr; @@ -404,7 +400,6 @@ static struct bfs_expr *de_morgan(const struct opt_state *state, struct bfs_expr expr->eval_fn = eval_and; expr->argv = &fake_and_arg; } - expr->synthetic = true; expr->lhs = negate_expr(expr->lhs, argv); expr->rhs = negate_expr(expr->rhs, argv); diff --git a/src/parse.c b/src/parse.c index f7c114d..2136bb5 100644 --- a/src/parse.c +++ b/src/parse.c @@ -79,7 +79,6 @@ struct bfs_expr bfs_true = { .argv = &fake_true_arg, .pure = true, .always_true = true, - .synthetic = true, .cost = FAST_COST, .probability = 1.0, }; @@ -90,7 +89,6 @@ struct bfs_expr bfs_false = { .argv = &fake_false_arg, .pure = true, .always_false = true, - .synthetic = true, .cost = FAST_COST, .probability = 0.0, }; @@ -129,7 +127,6 @@ struct bfs_expr *bfs_expr_new(bfs_eval_fn *eval_fn, size_t argc, char **argv) { expr->pure = false; expr->always_true = false; expr->always_false = false; - expr->synthetic = false; expr->cost = FAST_COST; expr->probability = 0.5; expr->evaluations = 0; @@ -186,10 +183,6 @@ static struct bfs_expr *new_binary_expr(bfs_eval_fn *eval_fn, struct bfs_expr *l expr->rhs = rhs; assert(bfs_expr_has_children(expr)); - if (argv == &fake_and_arg || argv == &fake_or_arg) { - expr->synthetic = true; - } - expr->persistent_fds = lhs->persistent_fds + rhs->persistent_fds; if (lhs->ephemeral_fds > rhs->ephemeral_fds) { expr->ephemeral_fds = lhs->ephemeral_fds; @@ -2011,7 +2004,6 @@ static struct bfs_expr *parse_nohidden(struct parser_state *state, int arg1, int hidden->probability = 0.01; hidden->pure = true; - hidden->synthetic = true; if (parse_exclude(state, hidden) != 0) { return NULL; @@ -3639,7 +3631,6 @@ static struct bfs_expr *parse_whole_expr(struct parser_state *state) { goto fail; } init_print_expr(state, print); - print->synthetic = true; expr = new_binary_expr(eval_and, expr, print, &fake_and_arg); if (!expr) { -- cgit v1.2.3