size_t n_input;
const struct macro_expander *me;
const struct macro_expansion_stack *stack;
- bool *expand;
};
static void
return true;
}
-struct expr_context
- {
- const struct macro_expander *me;
- const struct macro_expansion_stack *stack;
- };
-
-static char *macro_evaluate_or (const struct expr_context *ctx,
+static char *macro_evaluate_or (const struct macro_expander *me,
+ const struct macro_expansion_stack *stack,
const struct macro_token **tokens,
const struct macro_token *end);
static char *
-macro_evaluate_literal (const struct expr_context *ctx,
+macro_evaluate_literal (const struct macro_expander *me,
+ const struct macro_expansion_stack *stack,
const struct macro_token **tokens,
const struct macro_token *end)
{
if (p->token.type == T_LPAREN)
{
p++;
- char *value = macro_evaluate_or (ctx, &p, end);
+ char *value = macro_evaluate_or (me, stack, &p, end);
if (!value)
return NULL;
if (p >= end || p->token.type != T_RPAREN)
{
free (value);
- macro_error (ctx->stack, p < end ? p : NULL,
+ macro_error (stack, p < end ? p : NULL,
_("Expecting ')' in macro expression."));
return NULL;
}
}
else if (p->token.type == T_RPAREN)
{
- macro_error (ctx->stack, p, _("Expecting literal or function invocation "
- "in macro expression."));
+ macro_error (stack, p, _("Expecting literal or function invocation "
+ "in macro expression."));
return NULL;
}
struct parse_macro_function_ctx fctx = {
.input = p,
.n_input = end - p,
- .me = ctx->me,
- .stack = ctx->stack,
+ .me = me,
+ .stack = stack,
};
struct string function_output = DS_EMPTY_INITIALIZER;
size_t function_consumed = parse_function_arg (&fctx, 0, &function_output);
struct string unquoted = DS_EMPTY_INITIALIZER;
- if (unquote_string (ds_cstr (&function_output), ctx->me->segmenter_mode,
+ if (unquote_string (ds_cstr (&function_output), me->segmenter_mode,
&unquoted))
{
ds_swap (&function_output, &unquoted);
}
static char *
-macro_evaluate_relational (const struct expr_context *ctx,
+macro_evaluate_relational (const struct macro_expander *me,
+ const struct macro_expansion_stack *stack,
const struct macro_token **tokens,
const struct macro_token *end)
{
const struct macro_token *p = *tokens;
- char *lhs = macro_evaluate_literal (ctx, &p, end);
+ char *lhs = macro_evaluate_literal (me, stack, &p, end);
if (!lhs)
return NULL;
}
p++;
- char *rhs = macro_evaluate_literal (ctx, &p, end);
+ char *rhs = macro_evaluate_literal (me, stack, &p, end);
if (!rhs)
{
free (lhs);
}
struct string lhs_tmp, rhs_tmp;
- int cmp = strcmp (unquote_string_in_place (lhs, ctx->me->segmenter_mode,
+ int cmp = strcmp (unquote_string_in_place (lhs, me->segmenter_mode,
&lhs_tmp),
- unquote_string_in_place (rhs, ctx->me->segmenter_mode,
+ unquote_string_in_place (rhs, me->segmenter_mode,
&rhs_tmp));
ds_destroy (&lhs_tmp);
ds_destroy (&rhs_tmp);
}
static char *
-macro_evaluate_not (const struct expr_context *ctx,
+macro_evaluate_not (const struct macro_expander *me,
+ const struct macro_expansion_stack *stack,
const struct macro_token **tokens,
const struct macro_token *end)
{
negations++;
}
- char *operand = macro_evaluate_relational (ctx, &p, end);
+ char *operand = macro_evaluate_relational (me, stack, &p, end);
if (!operand || !negations)
{
*tokens = p;
}
static char *
-macro_evaluate_and (const struct expr_context *ctx,
+macro_evaluate_and (const struct macro_expander *me,
+ const struct macro_expansion_stack *stack,
const struct macro_token **tokens,
const struct macro_token *end)
{
const struct macro_token *p = *tokens;
- char *lhs = macro_evaluate_not (ctx, &p, end);
+ char *lhs = macro_evaluate_not (me, stack, &p, end);
if (!lhs)
return NULL;
|| ss_equals (p->representation, ss_cstr ("&"))))
{
p++;
- char *rhs = macro_evaluate_not (ctx, &p, end);
+ char *rhs = macro_evaluate_not (me, stack, &p, end);
if (!rhs)
{
free (lhs);
}
static char *
-macro_evaluate_or (const struct expr_context *ctx,
+macro_evaluate_or (const struct macro_expander *me,
+ const struct macro_expansion_stack *stack,
const struct macro_token **tokens,
const struct macro_token *end)
{
const struct macro_token *p = *tokens;
- char *lhs = macro_evaluate_and (ctx, &p, end);
+ char *lhs = macro_evaluate_and (me, stack, &p, end);
if (!lhs)
return NULL;
|| ss_equals (p->representation, ss_cstr ("|"))))
{
p++;
- char *rhs = macro_evaluate_and (ctx, &p, end);
+ char *rhs = macro_evaluate_and (me, stack, &p, end);
if (!rhs)
{
free (lhs);
const struct macro_expander *me,
const struct macro_expansion_stack *stack)
{
- const struct expr_context ctx = {
- .me = me,
- .stack = stack,
- };
- return macro_evaluate_or (&ctx, tokens, *tokens + n_tokens);
+ return macro_evaluate_or (me, stack, tokens, *tokens + n_tokens);
}
static bool