Commit 892e0f98 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Minor code refactoring

parent 7abbb982
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
using the ASN.1 "Space-Certified" compiler for data type definition. using the ASN.1 "Space-Certified" compiler for data type definition.
(See TASTE documentation for more information) (See TASTE documentation for more information)
The design is very flexible and can be used as basis for The design is flexible and can be used as basis for other backends.
generating other backends.
Entry point: Entry point:
The AST of the model that is parsed is described in ogAST.py The AST of the model that is parsed is described in ogAST.py
...@@ -22,13 +21,15 @@ ...@@ -22,13 +21,15 @@
singledispatch mechanism, that needs to be called to generate the code singledispatch mechanism, that needs to be called to generate the code
of any AST element. of any AST element.
Most functions return two values: "code" and "local_decl", containing The generate function returns two values: "code" and "local_decl",
a set of statements and a set of local variables (that can be later containing a set of statements and a set of local variables
placed anywhere in the code). (that can be later placed anywhere in the code).
Functions corresponding to the AST entries that are related to Expressions (all classes derived from ogAST.Expression) are generated
expressions return three values: "code", "ada_string" and "local_decl". using the "expression" visitor (singledispatch set of function).
The additional "ada_string" value is the usable string that corresponds
Expressions return three values: "code", "ada_string" and "local_decl".
The "ada_string" value is the usable string that corresponds
to the result of the expression evaluation. to the result of the expression evaluation.
For example, take the SDL statement "OUTPUT hello(a+5)" For example, take the SDL statement "OUTPUT hello(a+5)"
...@@ -69,8 +70,6 @@ ...@@ -69,8 +70,6 @@
import logging import logging
from itertools import chain
from singledispatch import singledispatch from singledispatch import singledispatch
import ogAST import ogAST
...@@ -125,7 +124,7 @@ def _process(process): ...@@ -125,7 +124,7 @@ def _process(process):
if def_value: if def_value:
# Expression must be a ground expression, i.e. must not # Expression must be a ground expression, i.e. must not
# require temporary variable to store computed result # require temporary variable to store computed result
dst, dstr, dlocal = generate(def_value) dst, dstr, dlocal = expression(def_value)
assert not dst and not dlocal, 'DCL: Expecting a ground expression' assert not dst and not dlocal, 'DCL: Expecting a ground expression'
process_level_decl.append( process_level_decl.append(
'l_{n} : aliased asn1Scc{t}{default};'.format( 'l_{n} : aliased asn1Scc{t}{default};'.format(
...@@ -415,10 +414,10 @@ def write_statement(param, newline): ...@@ -415,10 +414,10 @@ def write_statement(param, newline):
string = '"' + param.value[1:-1].replace('"', "'") + '"' string = '"' + param.value[1:-1].replace('"', "'") + '"'
else: else:
# XXX Cannot print an octet string like that... # XXX Cannot print an octet string like that...
code, string, local = generate(param) code, string, local = expression(param)
elif type_kind in ('IntegerType', 'RealType', elif type_kind in ('IntegerType', 'RealType',
'BooleanType', 'Integer32Type'): 'BooleanType', 'Integer32Type'):
code, string, local = generate(param) code, string, local = expression(param)
if type_kind == 'IntegerType': if type_kind == 'IntegerType':
cast = "Interfaces.Integer_64" cast = "Interfaces.Integer_64"
elif type_kind == 'RealType': elif type_kind == 'RealType':
...@@ -470,7 +469,7 @@ def _call_external_function(output): ...@@ -470,7 +469,7 @@ def _call_external_function(output):
elif signal_name.lower() == 'reset_timer': elif signal_name.lower() == 'reset_timer':
# built-in operator for resetting timers. param = timer name # built-in operator for resetting timers. param = timer name
param, = out['params'] param, = out['params']
p_code, p_id, p_local = generate(param) p_code, p_id, p_local = expression(param)
code.extend(p_code) code.extend(p_code)
local_decl.extend(p_local) local_decl.extend(p_local)
code.append('RESET_{};'.format(p_id)) code.append('RESET_{};'.format(p_id))
...@@ -478,8 +477,8 @@ def _call_external_function(output): ...@@ -478,8 +477,8 @@ def _call_external_function(output):
elif signal_name.lower() == 'set_timer': elif signal_name.lower() == 'set_timer':
# built-in operator for setting a timer: SET(1000, timer_name) # built-in operator for setting a timer: SET(1000, timer_name)
timer_value, timer_id = out['params'] timer_value, timer_id = out['params']
t_code, t_val, t_local = generate(timer_value) t_code, t_val, t_local = expression(timer_value)
p_code, p_id, p_local = generate(timer_id) p_code, p_id, p_local = expression(timer_id)
code.extend(t_code) code.extend(t_code)
code.extend(p_code) code.extend(p_code)
local_decl.extend(t_local) local_decl.extend(t_local)
...@@ -518,7 +517,7 @@ def _call_external_function(output): ...@@ -518,7 +517,7 @@ def _call_external_function(output):
param_direction = out_sig.fpar[idx]['direction'] param_direction = out_sig.fpar[idx]['direction']
typename = param_type.ReferencedTypeName.replace('-', '_') typename = param_type.ReferencedTypeName.replace('-', '_')
p_code, p_id, p_local = generate(param) p_code, p_id, p_local = expression(param)
code.extend(p_code) code.extend(p_code)
local_decl.extend(p_local) local_decl.extend(p_local)
# Create a temporary variable for input parameters only # Create a temporary variable for input parameters only
...@@ -545,7 +544,7 @@ def _call_external_function(output): ...@@ -545,7 +544,7 @@ def _call_external_function(output):
# inner procedure call # inner procedure call
list_of_params = [] list_of_params = []
for param in out.get('params', []): for param in out.get('params', []):
p_code, p_id, p_local = generate(param) p_code, p_id, p_local = expression(param)
code.extend(p_code) code.extend(p_code)
local_decl.extend(p_local) local_decl.extend(p_local)
# no need to use temporary variables, we are in pure Ada # no need to use temporary variables, we are in pure Ada
...@@ -568,7 +567,7 @@ def _task_assign(task): ...@@ -568,7 +567,7 @@ def _task_assign(task):
code.extend(traceability(task.comment)) code.extend(traceability(task.comment))
for expr in task.elems: for expr in task.elems:
code.extend(traceability(expr)) code.extend(traceability(expr))
code_assign, ada_string, decl_assign = generate(expr) code_assign, ada_string, decl_assign = expression(expr)
code.extend(code_assign) code.extend(code_assign)
code.append(ada_string[1:-1] + ';') code.append(ada_string[1:-1] + ';')
local_decl.extend(decl_assign) local_decl.extend(decl_assign)
...@@ -600,7 +599,7 @@ def _task_forloop(task): ...@@ -600,7 +599,7 @@ def _task_forloop(task):
if loop['range']: if loop['range']:
start_str, stop_str = '0', '' start_str, stop_str = '0', ''
if loop['range']['start']: if loop['range']['start']:
start_stmt, start_str, start_local = generate\ start_stmt, start_str, start_local = expression\
(loop['range']['start']) (loop['range']['start'])
local_decl.extend(start_local) local_decl.extend(start_local)
stmt.extend(start_stmt) stmt.extend(start_stmt)
...@@ -609,7 +608,7 @@ def _task_forloop(task): ...@@ -609,7 +608,7 @@ def _task_forloop(task):
start_str = 'Integer({})'.format(start_str) start_str = 'Integer({})'.format(start_str)
if loop['range']['step'] == 1: if loop['range']['step'] == 1:
start_str += '..' start_str += '..'
stop_stmt, stop_str, stop_local = generate(loop['range']['stop']) stop_stmt, stop_str, stop_local = expression(loop['range']['stop'])
local_decl.extend(stop_local) local_decl.extend(stop_local)
stmt.extend(stop_stmt) stmt.extend(stop_stmt)
if isinstance(loop['range']['stop'], ogAST.PrimInteger): if isinstance(loop['range']['stop'], ogAST.PrimInteger):
...@@ -631,7 +630,7 @@ def _task_forloop(task): ...@@ -631,7 +630,7 @@ def _task_forloop(task):
else: else:
# case of form: FOR x in SEQUENCE OF # case of form: FOR x in SEQUENCE OF
elem_type = loop['type'].ReferencedTypeName.replace('-', '_') elem_type = loop['type'].ReferencedTypeName.replace('-', '_')
list_stmt, list_str, list_local = generate(loop['list']) list_stmt, list_str, list_local = expression(loop['list'])
basic_type = find_basic_type(loop['list'].exprType) basic_type = find_basic_type(loop['list'].exprType)
range_cond = "{}.Data'Range".format(list_str)\ range_cond = "{}.Data'Range".format(list_str)\
if basic_type.Min == basic_type.Max\ if basic_type.Min == basic_type.Max\
...@@ -668,15 +667,26 @@ def _task_forloop(task): ...@@ -668,15 +667,26 @@ def _task_forloop(task):
return stmt, local_decl return stmt, local_decl
@generate.register(ogAST.PrimVariable) @singledispatch
def expression(expr):
''' Generate the code for Expression-classes, returning 3 things:
- list of statements
- useable string corresponding to the evaluation of the expression,
- list of local declarations
'''
_ = expr
raise TypeError('Unsupported expression: ' + str(expr))
return [], '', []
@expression.register(ogAST.PrimVariable)
def _primary_variable(prim): def _primary_variable(prim):
''' Single variable reference ''' ''' Single variable reference '''
sep = 'l_' if find_var(prim.value[0]) else '' sep = 'l_' if find_var(prim.value[0]) else ''
return [], '{sep}{name}'.format(sep=sep, name=prim.value[0]), [] return [], '{sep}{name}'.format(sep=sep, name=prim.value[0]), []
@generate.register(ogAST.PrimPath) @expression.register(ogAST.PrimPath)
def _prim_path(primaryId): def _prim_path(primary_id):
''' '''
Return the Ada string of an element list (path) Return the Ada string of an element list (path)
cases: a => 'l_a' (reference to a variable) cases: a => 'l_a' (reference to a variable)
...@@ -690,10 +700,10 @@ def _prim_path(primaryId): ...@@ -690,10 +700,10 @@ def _prim_path(primaryId):
stmts, local_decl = [], [] stmts, local_decl = [], []
# If first element is not a variable (can be a timer) do not add prefix # If first element is not a variable (can be a timer) do not add prefix
sep = 'l_' if find_var(primaryId.value[0]) else '' sep = 'l_' if find_var(primary_id.value[0]) else ''
sub_id = [] sub_id = []
for pr_id in primaryId.value: for pr_id in primary_id.value:
if type(pr_id) is not dict: if type(pr_id) is not dict:
if pr_id.lower() == 'length': if pr_id.lower() == 'length':
special_op = 'Length' special_op = 'Length'
...@@ -716,10 +726,10 @@ def _prim_path(primaryId): ...@@ -716,10 +726,10 @@ def _prim_path(primaryId):
else: else:
if 'substring' in pr_id: if 'substring' in pr_id:
# substring: two parameters (range) # substring: two parameters (range)
r1_stmts, r1_string, r1_local = generate( r1_stmts, r1_string, r1_local = \
pr_id['substring'][0]) expression(pr_id['substring'][0])
r2_stmts, r2_string, r2_local = generate( r2_stmts, r2_string, r2_local = \
pr_id['substring'][1]) expression(pr_id['substring'][1])
# should we add 1 in case of numerical values? (see index) # should we add 1 in case of numerical values? (see index)
ada_string += '.Data({r1}..{r2})'.format( ada_string += '.Data({r1}..{r2})'.format(
r1=r1_string, r2=r2_string) r1=r1_string, r2=r2_string)
...@@ -747,7 +757,7 @@ def _prim_path(primaryId): ...@@ -747,7 +757,7 @@ def _prim_path(primaryId):
ada_string = 'tmp{idx}'.format(idx=pr_id['tmpVar']) ada_string = 'tmp{idx}'.format(idx=pr_id['tmpVar'])
elif 'index' in pr_id: elif 'index' in pr_id:
# index is a list but it can have only one element # index is a list but it can have only one element
idx_stmts, idx_string, local_var = generate( idx_stmts, idx_string, local_var = expression(
pr_id['index'][0]) pr_id['index'][0])
if unicode.isnumeric(idx_string): if unicode.isnumeric(idx_string):
idx_string = int(idx_string) + 1 idx_string = int(idx_string) + 1
...@@ -766,7 +776,7 @@ def _prim_path(primaryId): ...@@ -766,7 +776,7 @@ def _prim_path(primaryId):
.format(exp.inputString)) .format(exp.inputString))
LOG.error(error) LOG.error(error)
raise TypeError(error) raise TypeError(error)
param_stmts, param_str, local_var = generate(exp) param_stmts, param_str, local_var = expression(exp)
stmts.extend(param_stmts) stmts.extend(param_stmts)
local_decl.extend(local_var) local_decl.extend(local_var)
ada_string += 'abs(' + param_str + ')' ada_string += 'abs(' + param_str + ')'
...@@ -782,7 +792,7 @@ def _prim_path(primaryId): ...@@ -782,7 +792,7 @@ def _prim_path(primaryId):
exp.inputString) exp.inputString)
LOG.error(error) LOG.error(error)
raise TypeError(error) raise TypeError(error)
param_stmts, param_str, local_var = generate( param_stmts, param_str, local_var = expression(
exp) exp)
stmts.extend(param_stmts) stmts.extend(param_stmts)
local_decl.extend(local_var) local_decl.extend(local_var)
...@@ -805,7 +815,7 @@ def _prim_path(primaryId): ...@@ -805,7 +815,7 @@ def _prim_path(primaryId):
error = '{} is not a CHOICE'.format(exp.inputString) error = '{} is not a CHOICE'.format(exp.inputString)
LOG.error(error) LOG.error(error)
raise TypeError(error) raise TypeError(error)
param_stmts, param_str, local_var = generate( param_stmts, param_str, local_var = expression(
exp) exp)
stmts.extend(param_stmts) stmts.extend(param_stmts)
local_decl.extend(local_var) local_decl.extend(local_var)
...@@ -817,7 +827,7 @@ def _prim_path(primaryId): ...@@ -817,7 +827,7 @@ def _prim_path(primaryId):
list_of_params = [] list_of_params = []
for param in pr_id['procParams']: for param in pr_id['procParams']:
param_stmt, param_str, local_var = ( param_stmt, param_str, local_var = (
generate(param)) expression(param))
list_of_params.append(param_str) list_of_params.append(param_str)
stmts.extend(param_stmt) stmts.extend(param_stmt)
local_decl.extend(local_var) local_decl.extend(local_var)
...@@ -827,24 +837,24 @@ def _prim_path(primaryId): ...@@ -827,24 +837,24 @@ def _prim_path(primaryId):
return stmts, ada_string, local_decl return stmts, ada_string, local_decl
@generate.register(ogAST.ExprPlus) @expression.register(ogAST.ExprPlus)
@generate.register(ogAST.ExprMul) @expression.register(ogAST.ExprMul)
@generate.register(ogAST.ExprMinus) @expression.register(ogAST.ExprMinus)
@generate.register(ogAST.ExprEq) @expression.register(ogAST.ExprEq)
@generate.register(ogAST.ExprNeq) @expression.register(ogAST.ExprNeq)
@generate.register(ogAST.ExprGt) @expression.register(ogAST.ExprGt)
@generate.register(ogAST.ExprGe) @expression.register(ogAST.ExprGe)
@generate.register(ogAST.ExprLt) @expression.register(ogAST.ExprLt)
@generate.register(ogAST.ExprLe) @expression.register(ogAST.ExprLe)
@generate.register(ogAST.ExprDiv) @expression.register(ogAST.ExprDiv)
@generate.register(ogAST.ExprMod) @expression.register(ogAST.ExprMod)
@generate.register(ogAST.ExprRem) @expression.register(ogAST.ExprRem)
@generate.register(ogAST.ExprAssign) @expression.register(ogAST.ExprAssign)
def _basic_operators(expr): def _basic_operators(expr):
''' Expressions with two sides ''' ''' Expressions with two sides '''
code, local_decl = [], [] code, local_decl = [], []
left_stmts, left_str, left_local = generate(expr.left) left_stmts, left_str, left_local = expression(expr.left)
right_stmts, right_str, right_local = generate(expr.right) right_stmts, right_str, right_local = expression(expr.right)
ada_string = '({left} {op} {right})'.format( ada_string = '({left} {op} {right})'.format(
left=left_str, op=expr.operand, right=right_str) left=left_str, op=expr.operand, right=right_str)
code.extend(left_stmts) code.extend(left_stmts)
...@@ -853,14 +863,14 @@ def _basic_operators(expr): ...@@ -853,14 +863,14 @@ def _basic_operators(expr):
local_decl.extend(right_local) local_decl.extend(right_local)
return code, ada_string, local_decl return code, ada_string, local_decl
@generate.register(ogAST.ExprOr) @expression.register(ogAST.ExprOr)
@generate.register(ogAST.ExprAnd) @expression.register(ogAST.ExprAnd)
@generate.register(ogAST.ExprXor) @expression.register(ogAST.ExprXor)
def _bitwise_operators(expr): def _bitwise_operators(expr):
''' Logical operators ''' ''' Logical operators '''
code, local_decl = [], [] code, local_decl = [], []
left_stmts, left_str, left_local = generate(expr.left) left_stmts, left_str, left_local = expression(expr.left)
right_stmts, right_str, right_local = generate(expr.right) right_stmts, right_str, right_local = expression(expr.right)
basic_type = find_basic_type(expr.exprType) basic_type = find_basic_type(expr.exprType)
if basic_type.kind != 'BooleanType': if basic_type.kind != 'BooleanType':
# Sequence of boolean or bit string # Sequence of boolean or bit string
...@@ -889,7 +899,7 @@ def _bitwise_operators(expr): ...@@ -889,7 +899,7 @@ def _bitwise_operators(expr):
return code, ada_string, local_decl return code, ada_string, local_decl
@generate.register(ogAST.ExprAppend) @expression.register(ogAST.ExprAppend)
def _append(expr): def _append(expr):
''' Generate code for the APPEND construct: a // b ''' ''' Generate code for the APPEND construct: a // b '''
stmts, ada_string, local_decl = [], '', [] stmts, ada_string, local_decl = [], '', []
...@@ -907,8 +917,8 @@ def _append(expr): ...@@ -907,8 +917,8 @@ def _append(expr):
# expr.right.var.stringLiteral[1:-1] + ') > ' + # expr.right.var.stringLiteral[1:-1] + ') > ' +
# str(basic_type_expr.Max)) # str(basic_type_expr.Max))
left_stmts, left_str, left_local = generate(expr.left) left_stmts, left_str, left_local = expression(expr.left)
right_stmts, right_str, right_local = generate(expr.right) right_stmts, right_str, right_local = expression(expr.right)
stmts.extend(left_stmts) stmts.extend(left_stmts)
stmts.extend(right_stmts) stmts.extend(right_stmts)
local_decl.extend(left_local) local_decl.extend(left_local)
...@@ -958,7 +968,7 @@ def _append(expr): ...@@ -958,7 +968,7 @@ def _append(expr):
return stmts, ada_string, local_decl return stmts, ada_string, local_decl
@generate.register(ogAST.ExprIn) @expression.register(ogAST.ExprIn)
def _expr_in(expr): def _expr_in(expr):
''' IN expressions: check if item is in a SEQUENCE OF ''' ''' IN expressions: check if item is in a SEQUENCE OF '''
# Check if item is in a SEQUENCE OF # Check if item is in a SEQUENCE OF
...@@ -966,8 +976,8 @@ def _expr_in(expr): ...@@ -966,8 +976,8 @@ def _expr_in(expr):
ada_string = 'tmp{}'.format(expr.tmpVar) ada_string = 'tmp{}'.format(expr.tmpVar)
stmts = [] stmts = []
local_decl = ['{} : BOOLEAN := False;'.format(ada_string)] local_decl = ['{} : BOOLEAN := False;'.format(ada_string)]
left_stmts, left_str, left_local = generate(expr.left) left_stmts, left_str, left_local = expression(expr.left)
right_stmts, right_str, right_local = generate(expr.right) right_stmts, right_str, right_local = expression(expr.right)
stmts.extend(left_stmts) stmts.extend(left_stmts)
stmts.extend(right_stmts) stmts.extend(right_stmts)
local_decl.extend(left_local) local_decl.extend(left_local)
...@@ -989,7 +999,7 @@ def _expr_in(expr): ...@@ -989,7 +999,7 @@ def _expr_in(expr):
return stmts, ada_string, local_decl return stmts, ada_string, local_decl
@generate.register(ogAST.PrimEnumeratedValue) @expression.register(ogAST.PrimEnumeratedValue)
def _enumerated_value(primary): def _enumerated_value(primary):
''' Generate code for an enumerated value ''' ''' Generate code for an enumerated value '''
enumerant = primary.value[0].replace('_', '-') enumerant = primary.value[0].replace('_', '-')
...@@ -998,7 +1008,7 @@ def _enumerated_value(primary): ...@@ -998,7 +1008,7 @@ def _enumerated_value(primary):
return [], ada_string, [] return [], ada_string, []
@generate.register(ogAST.PrimChoiceDeterminant) @expression.register(ogAST.PrimChoiceDeterminant)
def _choice_determinant(primary): def _choice_determinant(primary):
''' Generate code for a choice determinant (enumerated) ''' ''' Generate code for a choice determinant (enumerated) '''
enumerant = primary.value[0].replace('_', '-') enumerant = primary.value[0].replace('_', '-')
...@@ -1006,15 +1016,15 @@ def _choice_determinant(primary): ...@@ -1006,15 +1016,15 @@ def _choice_determinant(primary):
return [], ada_string, [] return [], ada_string, []
@generate.register(ogAST.PrimInteger) @expression.register(ogAST.PrimInteger)
@generate.register(ogAST.PrimReal) @expression.register(ogAST.PrimReal)
@generate.register(ogAST.PrimBoolean) @expression.register(ogAST.PrimBoolean)
def _integer(primary): def _integer(primary):
''' Generate code for a raw integer/real/boolean value ''' ''' Generate code for a raw integer/real/boolean value '''
return [], primary.value[0], [] return [], primary.value[0], []
@generate.register(ogAST.PrimEmptyString) @expression.register(ogAST.PrimEmptyString)
def _empty_string(primary): def _empty_string(primary):
''' Generate code for an empty SEQUENCE OF: {} ''' ''' Generate code for an empty SEQUENCE OF: {} '''
ada_string = 'asn1Scc{typeRef}_Init'.format( ada_string = 'asn1Scc{typeRef}_Init'.format(
...@@ -1022,7 +1032,7 @@ def _empty_string(primary): ...@@ -1022,7 +1032,7 @@ def _empty_string(primary):
return [], ada_string, [] return [], ada_string, []
@generate.register(ogAST.PrimStringLiteral) @expression.register(ogAST.PrimStringLiteral)
def _string_literal(primary): def _string_literal(primary):
''' Generate code for a string (Octet String) ''' ''' Generate code for a string (Octet String) '''
basic_type = find_basic_type(primary.exprType) basic_type = find_basic_type(primary.exprType)
...@@ -1040,20 +1050,20 @@ def _string_literal(primary): ...@@ -1040,20 +1050,20 @@ def _string_literal(primary):
return [], ada_string, [] return [], ada_string, []
@generate.register(ogAST.PrimConstant) @expression.register(ogAST.PrimConstant)
def _constant(primary): def _constant(primary):
''' Generate code for a reference to an ASN.1 constant ''' ''' Generate code for a reference to an ASN.1 constant '''
return [], primary.value[0], [] return [], primary.value[0], []
@generate.register(ogAST.PrimMantissaBaseExp) @expression.register(ogAST.PrimMantissaBaseExp)
def _mantissa_base_exp(primary): def _mantissa_base_exp(primary):
''' Generate code for a Real with Mantissa-base-Exponent representation ''' ''' Generate code for a Real with Mantissa-base-Exponent representation '''
# TODO # TODO
_ = primary _ = primary
return [], '', [] return [], '', []
@generate.register(ogAST.PrimIfThenElse) @expression.register(ogAST.PrimIfThenElse)
def _if_then_else(ifThenElse): def _if_then_else(ifThenElse):
''' Return string and statements for ternary operator ''' ''' Return string and statements for ternary operator '''
resType = ifThenElse.exprType resType = ifThenElse.exprType
...@@ -1061,9 +1071,9 @@ def _if_then_else(ifThenElse): ...@@ -1061,9 +1071,9 @@ def _if_then_else(ifThenElse):
local_decl = ['tmp{idx} : asn1Scc{resType};'.format( local_decl = ['tmp{idx} : asn1Scc{resType};'.format(
idx=ifThenElse.value['tmpVar'], idx=ifThenElse.value['tmpVar'],
resType=resType.ReferencedTypeName.replace('-', '_'))] resType=resType.ReferencedTypeName.replace('-', '_'))]
if_stmts, if_str, if_local = generate(ifThenElse.value['if']) if_stmts, if_str, if_local = expression(ifThenElse.value['if'])
then_stmts, then_str, then_local = generate(ifThenElse.value['then']) then_stmts, then_str, then_local = expression(ifThenElse.value['then'])
else_stmts, else_str, else_local = generate(ifThenElse.value['else']) else_stmts, else_str, else_local = expression(ifThenElse.value['else'])
stmts.extend(if_stmts) stmts.extend(if_stmts)
stmts.extend(then_stmts) stmts.extend(then_stmts)
stmts.extend(else_stmts) stmts.extend(else_stmts)
...@@ -1082,7 +1092,7 @@ def _if_then_else(ifThenElse): ...@@ -1082,7 +1092,7 @@ def _if_then_else(ifThenElse):
return stmts, ada_string, local_decl return stmts, ada_string, local_decl
@generate.register(ogAST.PrimSequence) @expression.register(ogAST.PrimSequence)
def _sequence(seq): def _sequence(seq):
''' Return Ada string for an ASN.1 SEQUENCE ''' ''' Return Ada string for an ASN.1 SEQUENCE '''
stmts, local_decl = [], [] stmts, local_decl = [], []
...@@ -1097,7 +1107,7 @@ def _sequence(seq): ...@@ -1097,7 +1107,7 @@ def _sequence(seq):
delem = elem.replace('_', '-') delem = elem.replace('_', '-')
value.exprType = (TYPES value.exprType = (TYPES
[seqType.ReferencedTypeName].type.Children[delem].type) [seqType.ReferencedTypeName].type.Children[delem].type)
value_stmts, value_str, local_var = generate(value) value_stmts, value_str, local_var = expression(value)
ada_string += sep + elem + ' => ' + value_str ada_string += sep + elem + ' => ' + value_str
sep = ', ' sep = ', '
stmts.extend(value_stmts) stmts.extend(value_stmts)
...@@ -1106,7 +1116,7 @@ def _sequence(seq): ...@@ -1106,7 +1116,7 @@ def _sequence(seq):
return stmts, ada_string, local_decl return stmts, ada_string, local_decl
@generate.register(ogAST.PrimSequenceOf)