projects
/
pspp
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
113114a
)
Get rid of expr_context.
author
Ben Pfaff
<blp@cs.stanford.edu>
Sun, 4 Jul 2021 21:39:26 +0000
(14:39 -0700)
committer
Ben Pfaff
<blp@cs.stanford.edu>
Sun, 4 Jul 2021 21:39:26 +0000
(14:39 -0700)
src/language/lexer/macro.c
patch
|
blob
|
history
diff --git
a/src/language/lexer/macro.c
b/src/language/lexer/macro.c
index 31bacec52d7ea29b4cc036ebb492ac24dfd55435..3b17d90f38a977220d77492ec83321e4c1c5ec91 100644
(file)
--- a/
src/language/lexer/macro.c
+++ b/
src/language/lexer/macro.c
@@
-896,7
+896,6
@@
struct parse_macro_function_ctx
size_t n_input;
const struct macro_expander *me;
const struct macro_expansion_stack *stack;
size_t n_input;
const struct macro_expander *me;
const struct macro_expansion_stack *stack;
- bool *expand;
};
static void
};
static void
@@
-1271,18
+1270,14
@@
expand_macro_function (struct parse_macro_function_ctx *ctx,
return true;
}
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 *
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)
{
const struct macro_token **tokens,
const struct macro_token *end)
{
@@
-1292,13
+1287,13
@@
macro_evaluate_literal (const struct expr_context *ctx,
if (p->token.type == T_LPAREN)
{
p++;
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);
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;
}
_("Expecting ')' in macro expression."));
return NULL;
}
@@
-1308,21
+1303,21
@@
macro_evaluate_literal (const struct expr_context *ctx,
}
else if (p->token.type == T_RPAREN)
{
}
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,
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;
};
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);
&unquoted))
{
ds_swap (&function_output, &unquoted);
@@
-1372,12
+1367,13
@@
parse_relational_op (const struct macro_token *mt)
}
static char *
}
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;
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;
if (!lhs)
return NULL;
@@
-1389,7
+1385,7
@@
macro_evaluate_relational (const struct expr_context *ctx,
}
p++;
}
p++;
- char *rhs = macro_evaluate_literal (
ctx
, &p, end);
+ char *rhs = macro_evaluate_literal (
me, stack
, &p, end);
if (!rhs)
{
free (lhs);
if (!rhs)
{
free (lhs);
@@
-1397,9
+1393,9
@@
macro_evaluate_relational (const struct expr_context *ctx,
}
struct string lhs_tmp, rhs_tmp;
}
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),
&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);
&rhs_tmp));
ds_destroy (&lhs_tmp);
ds_destroy (&rhs_tmp);
@@
-1419,7
+1415,8
@@
macro_evaluate_relational (const struct expr_context *ctx,
}
static char *
}
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)
{
const struct macro_token **tokens,
const struct macro_token *end)
{
@@
-1434,7
+1431,7
@@
macro_evaluate_not (const struct expr_context *ctx,
negations++;
}
negations++;
}
- char *operand = macro_evaluate_relational (
ctx
, &p, end);
+ char *operand = macro_evaluate_relational (
me, stack
, &p, end);
if (!operand || !negations)
{
*tokens = p;
if (!operand || !negations)
{
*tokens = p;
@@
-1448,12
+1445,13
@@
macro_evaluate_not (const struct expr_context *ctx,
}
static char *
}
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;
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;
if (!lhs)
return NULL;
@@
-1462,7
+1460,7
@@
macro_evaluate_and (const struct expr_context *ctx,
|| ss_equals (p->representation, ss_cstr ("&"))))
{
p++;
|| 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);
if (!rhs)
{
free (lhs);
@@
-1479,12
+1477,13
@@
macro_evaluate_and (const struct expr_context *ctx,
}
static char *
}
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;
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;
if (!lhs)
return NULL;
@@
-1493,7
+1492,7
@@
macro_evaluate_or (const struct expr_context *ctx,
|| ss_equals (p->representation, ss_cstr ("|"))))
{
p++;
|| 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);
if (!rhs)
{
free (lhs);
@@
-1514,11
+1513,7
@@
macro_evaluate_expression (const struct macro_token **tokens, size_t n_tokens,
const struct macro_expander *me,
const struct macro_expansion_stack *stack)
{
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
}
static bool