aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-07 03:41:55 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-07 03:41:55 +0100
commit07e3d15b97f771ee42ff9a585debecb51fb1a3f3 (patch)
tree2d94b7e7239d9b15df6006335c06809aa79b1ccf /src/mds-kbdc
parentmds-kbdc: parse function calls (diff)
downloadmds-07e3d15b97f771ee42ff9a585debecb51fb1a3f3.tar.gz
mds-07e3d15b97f771ee42ff9a585debecb51fb1a3f3.tar.bz2
mds-07e3d15b97f771ee42ff9a585debecb51fb1a3f3.tar.xz
mds-kbdc: track side-effects
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/mds-kbdc/compile-layout.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index 0b608db..01587c2 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -100,6 +100,11 @@ static mds_kbdc_tree_t* last_value_statement = NULL;
*/
static char32_t** current_return_value = NULL;
+/**
+ * Whether ‘\set/3’ has been called
+ */
+static int have_side_effect = 0;
+
/**
@@ -356,11 +361,10 @@ static int call_function(mds_kbdc_tree_t* restrict tree, const char* restrict na
name, arg_count);
}
- /* TODO side-effect if `is_set` */
-
/* Call the function. */
*return_value = builtin_function_invoke(name, arg_count, arguments);
fail_if (*return_value == NULL);
+ have_side_effect |= is_set;
done:
@@ -2221,7 +2225,7 @@ static int check_nonnul(mds_kbdc_tree_t* restrict tree)
*/
static int compile_map(mds_kbdc_tree_map_t* restrict tree)
{
- int bad = 0;
+ int bad = 0, old_have_side_effect = have_side_effect;
mds_kbdc_include_stack_t* restrict include_stack = NULL;
mds_kbdc_tree_t* seq = NULL;
mds_kbdc_tree_t* res = NULL;
@@ -2231,6 +2235,8 @@ static int compile_map(mds_kbdc_tree_map_t* restrict tree)
int r, saved_errno;
mds_kbdc_tree_t* previous_last_value_statement = last_value_statement;
+ have_side_effect = 0;
+
/* Duplicate arguments and evaluate function calls,
variable dereferences and escapes in the mapping
input sequence. */
@@ -2293,12 +2299,13 @@ static int compile_map(mds_kbdc_tree_map_t* restrict tree)
/* Check that the value-statement is inside a function call, or has
side-effects by directly or indirectly calling ‘\set/3’ on an
array that is not shadowed by an inner function- or macro-call. */
- if (r /* TODO was there a side-effect? enter if no */)
+ if (r && !have_side_effect)
{
NEW_ERROR(tree, ERROR, "value-statement outside function without side-effects");
tree->processed = PROCESS_LEVEL;
}
- /* TODO if we have side-effects: ```last_value_statement = NULL;``` */
+ if (have_side_effect)
+ last_value_statement = NULL;
/* Check whether we made a previous value-statement unnecessary. */
if (previous_last_value_statement)
@@ -2314,6 +2321,7 @@ static int compile_map(mds_kbdc_tree_map_t* restrict tree)
done:
mds_kbdc_tree_free(seq);
mds_kbdc_tree_free(res);
+ have_side_effect = old_have_side_effect;
return 0;
FAIL_BEGIN;
mds_kbdc_include_stack_free(include_stack);
@@ -2322,6 +2330,7 @@ static int compile_map(mds_kbdc_tree_map_t* restrict tree)
mds_kbdc_tree_free(res);
tree->sequence = old_seq;
tree->result = old_res;
+ have_side_effect = old_have_side_effect;
FAIL_END;
}