Skip to content

Commit

Permalink
Refactor Initialization/Preparation function logic
Browse files Browse the repository at this point in the history
By adding some logic to the mapping processor there is no longer need to
wrap Initialize (now "Preparation") function in a tuple, which feels
more logical.

Signed-off-by: Gunnar Andersson <[email protected]>
  • Loading branch information
gunnar-mb committed Oct 11, 2024
1 parent e30cf6d commit e8a66c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions other/franca/franca_to_ifex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import re

from ifex.model.ifex_ast_construction import add_constructors_to_ifex_ast_model, ifex_ast_as_yaml
from other.franca.rule_translator import Initialize, Constant, ListOf, Unsupported
from other.franca.rule_translator import Preparation, Constant, ListOf, Unsupported

def array_type_name(francaitem):
return translate_type_name(francaitem) + '[]' # Unbounded arrays for now
Expand All @@ -33,8 +33,8 @@ def concat_comments(list):
# If enumerator values are not given, we must use auto-generated values.
# IFEX model requires all enumerators to be given values.
enum_count = -1
def reset_enumerator_counter(_ignored):
print("***Resetting enum counter")
def reset_enumerator_counter():
#print("***Resetting enum counter")
global enum_count
enum_count = -1

Expand Down Expand Up @@ -72,7 +72,7 @@ def translate_integer_constant(franca_int_value):
(franca.Argument, ifex.Argument) : [
('type', 'datatype', translate_type_name), ],
(franca.Enumeration, ifex.Enumeration) : [
(Initialize(reset_enumerator_counter), None),
Preparation(reset_enumerator_counter),
('enumerators', 'options'),
('extends', Unsupported),

Expand Down
3 changes: 1 addition & 2 deletions other/franca/rule_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ def transform(mapping_table, input_obj):
# First loop: Perform the explicitly defined attribute conversions
# for those that are specified in the translation table.

# TODO: It should be possible to let the preparation_function be a closure, with predefined parameters.
for preparation_function, input_attr, output_attr, transform_function in [eval_mapping(m) for m in mappings]:
_log("INFO", f"Attribute mapping found: {input_attr=} -> {output_attr=} with {transform_function=}")

# TODO: It should be possible to let the preparation_function be a closure, with predefined parameters.
# To be investigated. Consider if it's better to go back to eval_mapping returning the function-wrapper
# object (Preparation) and not just the function.

Expand All @@ -259,7 +259,6 @@ def transform(mapping_table, input_obj):
transform_function = transform_function[0] if transform_function else lambda _ : _

# Explicitly ignored?

if output_attr is None:
_log("DEBUG", f"Ignoring {input_attr=} for {type(input_obj)} because it was mapped to None")
continue
Expand Down

0 comments on commit e8a66c0

Please sign in to comment.