summaryrefslogtreecommitdiff
path: root/grc/core/generator/Generator.py
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2016-05-17 13:23:18 +0200
committerSebastian Koslowski <koslowski@kit.edu>2016-05-25 16:26:31 +0200
commit6647de1109cd0dffbb8668797a5bd98f54ffa053 (patch)
tree4631afde8935f7fdf5b2547a392a212c6c23484e /grc/core/generator/Generator.py
parentd5fcce9cb94df8825cf0388663f2d2f1ac16441a (diff)
grc-refactor: minor clean-up of callback generator code
Diffstat (limited to 'grc/core/generator/Generator.py')
-rw-r--r--grc/core/generator/Generator.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/grc/core/generator/Generator.py b/grc/core/generator/Generator.py
index 4788711a17..ba272aba3f 100644
--- a/grc/core/generator/Generator.py
+++ b/grc/core/generator/Generator.py
@@ -141,7 +141,7 @@ class TopBlockGenerator(object):
pass
return code
- blocks = expr_utils.sort_objects(
+ blocks_all = expr_utils.sort_objects(
filter(lambda b: b.get_enabled() and not b.get_bypassed(), fg.blocks),
lambda b: b.get_id(), _get_block_sort_text
)
@@ -150,7 +150,7 @@ class TopBlockGenerator(object):
Messages.send_warning("The block {!r} is deprecated.".format(key))
# List of regular blocks (all blocks minus the special ones)
- blocks = filter(lambda b: b not in (imports + parameters), blocks)
+ blocks = filter(lambda b: b not in (imports + parameters), blocks_all)
for block in blocks:
key = block.get_key()
@@ -214,20 +214,22 @@ class TopBlockGenerator(object):
connection_templates = fg.get_parent().connection_templates
msgs = filter(lambda c: c.is_msg(), fg.get_enabled_connections())
+
# List of variable names
var_ids = [var.get_id() for var in parameters + variables]
- # Prepend self.
- replace_dict = dict([(var_id, 'self.%s' % var_id) for var_id in var_ids])
- # List of callbacks
- callbacks = [
- expr_utils.expr_replace(cb, replace_dict)
- for cb in sum([block.get_callbacks() for block in fg.get_enabled_blocks()], [])
- ]
+ replace_dict = dict((var_id, 'self.' + var_id) for var_id in var_ids)
+ callbacks_all = []
+ for block in blocks_all:
+ callbacks_all.extend(expr_utils.expr_replace(cb, replace_dict) for cb in block.get_callbacks())
+
# Map var id to callbacks
- var_id2cbs = dict([
- (var_id, filter(lambda c: expr_utils.get_variable_dependencies(c, [var_id]), callbacks))
- for var_id in var_ids
- ])
+ def uses_var_id():
+ return expr_utils.get_variable_dependencies(callback, [var_id])
+
+ callbacks = {}
+ for var_id in var_ids:
+ callbacks[var_id] = [callback for callback in callbacks_all if uses_var_id()]
+
# Load the namespace
namespace = {
'title': title,
@@ -241,7 +243,7 @@ class TopBlockGenerator(object):
'connection_templates': connection_templates,
'msgs': msgs,
'generate_options': self._generate_options,
- 'var_id2cbs': var_id2cbs,
+ 'callbacks': callbacks,
}
# Build the template
t = Template(open(FLOW_GRAPH_TEMPLATE, 'r').read(), namespace)