summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPovilas Kanapickas <povilas@radix.lt>2021-07-30 22:58:44 +0300
committerPovilas Kanapickas <povilas@radix.lt>2021-07-30 22:58:44 +0300
commit4d678b162bf8a3b10e5bdf76df2be63d33c23381 (patch)
tree09c47bea1b442524c3c01debb12299346d240ab6
parent21414e7c447f18224c577ed5e32bd5d6e45c44f9 (diff)
c_client.py: Extract get_expr_field_names()
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
-rw-r--r--src/c_client.py61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/c_client.py b/src/c_client.py
index 39f162e..b987f4e 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -649,39 +649,42 @@ def _c_helper_resolve_field_names (prefix):
return all_fields
+
+def get_expr_field_names(expr):
+ """
+ returns a list of field names referenced in an expression
+ """
+ if expr.op is None or expr.op == 'calculate_len':
+ if expr.lenfield_name is not None:
+ return [expr.lenfield_name]
+ # constant value expr
+ return []
+
+ if expr.op == '~':
+ return get_expr_field_names(expr.rhs)
+ if expr.op == 'popcount':
+ return get_expr_field_names(expr.rhs)
+ if expr.op == 'sumof':
+ # sumof expr references another list,
+ # we need that list's length field here
+ field = None
+ for f in expr.lenfield_parent.fields:
+ if f.field_name == expr.lenfield_name:
+ field = f
+ break
+ if field is None:
+ raise Exception("list field '%s' referenced by sumof not found" % expr.lenfield_name)
+ # referenced list + its length field
+ return [expr.lenfield_name] + get_expr_field_names(field.type.expr)
+ if expr.op == 'enumref':
+ return []
+ return get_expr_field_names(expr.lhs) + get_expr_field_names(expr.rhs)
+
+
def get_expr_fields(self):
"""
get the Fields referenced by switch or list expression
"""
- def get_expr_field_names(expr):
- if expr.op is None or expr.op == 'calculate_len':
- if expr.lenfield_name is not None:
- return [expr.lenfield_name]
- else:
- # constant value expr
- return []
- else:
- if expr.op == '~':
- return get_expr_field_names(expr.rhs)
- elif expr.op == 'popcount':
- return get_expr_field_names(expr.rhs)
- elif expr.op == 'sumof':
- # sumof expr references another list,
- # we need that list's length field here
- field = None
- for f in expr.lenfield_parent.fields:
- if f.field_name == expr.lenfield_name:
- field = f
- break
- if field is None:
- raise Exception("list field '%s' referenced by sumof not found" % expr.lenfield_name)
- # referenced list + its length field
- return [expr.lenfield_name] + get_expr_field_names(field.type.expr)
- elif expr.op == 'enumref':
- return []
- else:
- return get_expr_field_names(expr.lhs) + get_expr_field_names(expr.rhs)
- # get_expr_field_names()
# resolve the field names with the parent structure(s)
unresolved_fields_names = get_expr_field_names(self.expr)