1.1 --- a/encoders.py Sun Feb 19 19:06:22 2017 +0100
1.2 +++ b/encoders.py Sun Feb 19 22:24:36 2017 +0100
1.3 @@ -218,6 +218,10 @@
1.4 "<context>", "<set_context>", "<test_context_revert>", "<test_context_static>",
1.5 )
1.6
1.7 +context_op_functions = (
1.8 + "<test_context_revert>", "<test_context_static>",
1.9 + )
1.10 +
1.11 reference_acting_ops = attribute_ops + checked_ops + typename_ops
1.12 attribute_producing_ops = attribute_loading_ops + checked_loading_ops
1.13
1.14 @@ -289,6 +293,11 @@
1.15 if op in context_ops:
1.16 a.insert(0, context_index)
1.17
1.18 + # Add the local context array to certain operations.
1.19 +
1.20 + if op in context_op_functions:
1.21 + a.append("__tmp_contexts")
1.22 +
1.23 # Define any argument string.
1.24
1.25 if a:
2.1 --- a/templates/ops.c Sun Feb 19 19:06:22 2017 +0100
2.2 +++ b/templates/ops.c Sun Feb 19 22:24:36 2017 +0100
2.3 @@ -249,6 +249,25 @@
2.4 return __new_wrapper(context, attr);
2.5 }
2.6
2.7 +__attr __test_context_revert(int target, __ref context, __attr attr, __ref contexts[])
2.8 +{
2.9 + /* Revert the local context to that employed by the attribute if the
2.10 + supplied context is not appropriate. */
2.11 +
2.12 + if (!__test_context_update(context, attr))
2.13 + contexts[target] = __CONTEXT_AS_VALUE(attr).value;
2.14 + return attr;
2.15 +}
2.16 +
2.17 +__attr __test_context_static(int target, __ref context, __ref value, __ref contexts[])
2.18 +{
2.19 + /* Set the local context to the specified context if appropriate. */
2.20 +
2.21 + if (__test_context_update(context, (__attr) {.value=value}))
2.22 + contexts[target] = context;
2.23 + return (__attr) {.value=value};
2.24 +}
2.25 +
2.26 /* Context testing for invocations. */
2.27
2.28 int __type_method_invocation(__ref context, __attr target)
3.1 --- a/templates/ops.h Sun Feb 19 19:06:22 2017 +0100
3.2 +++ b/templates/ops.h Sun Feb 19 22:24:36 2017 +0100
3.3 @@ -73,21 +73,8 @@
3.4 int __test_context_update(__ref context, __attr attr);
3.5 __attr __test_context(__ref context, __attr attr);
3.6 __attr __update_context(__ref context, __attr attr);
3.7 -
3.8 -/* Revert the local context to that employed by the attribute if the supplied
3.9 - context is not appropriate. */
3.10 -
3.11 -#define __test_context_revert(__TARGET, __CONTEXT, __ATTR) \
3.12 - (__test_context_update(__CONTEXT, __ATTR) \
3.13 - ? __ATTR \
3.14 - : (__set_context(__TARGET, __CONTEXT_AS_VALUE(__ATTR)), __ATTR))
3.15 -
3.16 -/* Set the local context to the specified context if appropriate. */
3.17 -
3.18 -#define __test_context_static(__TARGET, __CONTEXT, __REF) \
3.19 - (__test_context_update(__CONTEXT, (__attr) {.value=__REF}) \
3.20 - ? (__set_context(__TARGET, (__attr) {.value=__CONTEXT}), (__attr) {.value=__REF}) \
3.21 - : (__attr) {.value=__REF})
3.22 +__attr __test_context_revert(int target, __ref context, __attr attr, __ref contexts[]);
3.23 +__attr __test_context_static(int target, __ref context, __ref value, __ref contexts[]);
3.24
3.25 #define __get_context(__TARGET) (__tmp_contexts[__TARGET])
3.26 #define __set_context(__TARGET, __ATTR) (__tmp_contexts[__TARGET] = (__ATTR).value)