Commit fb8bc7aa authored by dbarbera's avatar dbarbera
Browse files

Removed PrimPath node

parent dbc57a3f
......@@ -892,173 +892,6 @@ def _prim_selector(prim):
return stmts, ada_string, local_decl
@expression.register(ogAST.PrimPath)
def _prim_path(primary_id):
'''
Return the Ada string of an element list (path)
cases: a => 'l_a' (reference to a variable)
a_timer => 'a_timer' (reference to a timer)
a!b => a.b (field of a structure)
a!b if a is a CHOICE => TypeOfa_b_get(a)
a(Expression) => a(ExpressionSolver) (array index)
Expression can be complex (if-then-else-fi..)
'''
ada_string = ''
stmts, local_decl = [], []
# If first element is not a variable (can be a timer) do not add prefix
sep = 'l_' if find_var(primary_id.value[0]) else ''
sub_id = []
for pr_id in primary_id.value:
if type(pr_id) is not dict:
if pr_id.lower() == 'length':
special_op = 'Length'
continue
elif pr_id.lower() == 'present':
special_op = 'ChoiceKind'
continue
elif pr_id.lower() == 'abs':
special_op = 'Abs'
continue
elif pr_id.lower() == 'fix':
special_op = 'CastInt'
continue
elif pr_id.lower() == 'float':
special_op = 'CastReal'
continue
elif pr_id.lower() == 'power':
special_op = 'Power'
continue
special_op = ''
parent_kind, parent_typename = path_type(sub_id)
sub_id.append(pr_id)
if parent_kind == 'ChoiceType':
ada_string = ('asn1Scc{typename}_{p_id}_get({ada_string})'
.format(typename=parent_typename,
p_id=pr_id, ada_string=ada_string))
else:
ada_string += sep + pr_id
else:
if 'substring' in pr_id:
# substring: two parameters (range)
r1_stmts, r1_string, r1_local = \
expression(pr_id['substring'][0])
r2_stmts, r2_string, r2_local = \
expression(pr_id['substring'][1])
# should we add 1 in case of numerical values? (see index)
ada_string += '.Data({r1}..{r2})'.format(
r1=r1_string, r2=r2_string)
stmts.extend(r1_stmts)
stmts.extend(r2_stmts)
local_decl.extend(r1_local)
local_decl.extend(r2_local)
_, parent_typename = path_type(sub_id)
local_decl.append('tmp{idx} : aliased asn1Scc{parent_type};'
.format(idx=pr_id['tmpVar'],
parent_type=parent_typename))
# XXX types with fixed length: substrings will not work
if unicode.isnumeric(r1_string) and unicode.isnumeric(
r2_string):
length = int(r2_string) - int(r1_string) + 1
else:
length = ('{r2} - {r1} + 1'
.format(r2=r2_string, r1=r1_string))
stmts.append('tmp{idx}.Length := {length};'
.format(idx=pr_id['tmpVar'], length=length))
stmts.append('tmp{idx}.Data(1..{length}) := {data};'
.format(idx=pr_id['tmpVar'],
length=length, data=ada_string))
ada_string = 'tmp{idx}'.format(idx=pr_id['tmpVar'])
elif 'index' in pr_id:
# index is a list but it can have only one element
idx_stmts, idx_string, local_var = expression(
pr_id['index'][0])
if unicode.isnumeric(idx_string):
idx_string = int(idx_string) + 1
else:
idx_string = '1+Integer({idx})'.format(idx=idx_string)
ada_string += '.Data({idx})'.format(idx=idx_string)
stmts.extend(idx_stmts)
local_decl.extend(local_var)
elif 'procParams' in pr_id:
if special_op in ('Abs', 'CastInt', 'CastReal'):
# Return absolute value of a number
exp, = pr_id['procParams']
param_stmts, param_str, local_var = expression(exp)
stmts.extend(param_stmts)
local_decl.extend(local_var)
ada_string += '{op}({param})'.format(
param=param_str,
op='abs' if special_op == 'Abs' else
'Asn1Int' if special_op == 'CastInt'
else 'adaasn1rtl.Asn1Real'
if special_op == 'CastReal' else 'ERROR')
elif special_op == 'Power':
operands = [None, None]
for idx, param in enumerate(pr_id['procParams']):
stmt, operands[idx], local = expression(param)
stmts.extend(stmt)
local_decl.extend(local)
ada_string += '{op[0]} ** Natural({op[1]})'.format(
op=operands)
elif special_op == 'Length':
# Length of sequence of: take only the first parameter
exp, = pr_id['procParams']
exp_type = find_basic_type(exp.exprType)
min_length = getattr(exp_type, 'Min', None)
max_length = getattr(exp_type, 'Max', None)
if min_length is None or max_length is None:
error = '{} is not a SEQUENCE OF'.format(
exp.inputString)
LOG.error(error)
raise TypeError(error)
param_stmts, param_str, local_var = expression(
exp)
stmts.extend(param_stmts)
local_decl.extend(local_var)
if min_length == max_length:
ada_string += min_length
else:
ada_string += ('Asn1Int({e}.Length)'
.format(e=param_str))
elif special_op == 'ChoiceKind':
# User wants to know what CHOICE element is present
exp, = pr_id['procParams']
# Get the basic type to make sure it is a choice
exp_type = find_basic_type(exp.exprType)
# Also get the ASN.1 type name as it is
# needed to build the Ada expression
exp_typename = \
(getattr(exp.exprType, 'ReferencedTypeName',
None) or exp.exprType.kind).replace('-', '_')
if exp_type.kind != 'ChoiceType':
error = '{} is not a CHOICE'.format(exp.inputString)
LOG.error(error)
raise TypeError(error)
param_stmts, param_str, local_var = expression(
exp)
stmts.extend(param_stmts)
local_decl.extend(local_var)
ada_string += ('asn1Scc{t}_Kind({e})'.format(
t=exp_typename, e=param_str))
else:
ada_string += '('
# Take all params and join them with commas
list_of_params = []
for param in pr_id['procParams']:
param_stmt, param_str, local_var = (
expression(param))
list_of_params.append(param_str)
stmts.extend(param_stmt)
local_decl.extend(local_var)
ada_string += ', '.join(list_of_params)
ada_string += ')'
sep = '.'
return stmts, ada_string, local_decl
@expression.register(ogAST.ExprPlus)
@expression.register(ogAST.ExprMul)
@expression.register(ogAST.ExprMinus)
......
......@@ -380,7 +380,6 @@ def _rename_expr(ast, from_name, to_name):
rename_everything(ast.right, from_name, to_name)
@rename_everything.register(ogAST.PrimPath)
@rename_everything.register(ogAST.PrimVariable)
def _rename_path(ast, from_name, to_name):
''' Ultimate seek point for the renaming: primary path/variables '''
......
......@@ -92,7 +92,7 @@ def _process(process):
# Clear scope
LLVM['named_values'].clear()
# Create the function name and type
funct_name = str(process_name) + '_startup'
funct_name = str(process_name) + '_startup'
funct_type = core.Type.function(core.Type.void(), [])
# Create a function object
function = core.Function.new(LLVM['module'], funct_type, funct_name)
......@@ -166,20 +166,6 @@ def _primary_variable(prim):
pass
@expression.register(ogAST.PrimPath)
def _prim_path(primaryId):
'''
Return the string of an element list (path)
cases: a => 'l_a' (reference to a variable)
a_timer => 'a_timer' (reference to a timer)
a!b => a.b (field of a structure)
a!b if a is a CHOICE => TypeOfa_b_get(a)
a(Expression) => a(ExpressionSolver) (array index)
Expression can be complex (if-then-else-fi..)
'''
pass
@expression.register(ogAST.ExprPlus)
@expression.register(ogAST.ExprMul)
@expression.register(ogAST.ExprMinus)
......
......@@ -47,9 +47,7 @@ class Expression(object):
self.inputString = inputString
self.line = line
self.charPositionInLine = charPositionInLine
# left and right are of type Expression (absent for primaries)
self.left = None
self.right = None
# exprType is an ASN.1 type (as exported by asn1scc)
self.exprType = None
# Hint for code generators: intermediate storage identifier
......@@ -180,37 +178,24 @@ class Primary(Expression):
l=self.line, c=self.charPositionInLine)
# Subclasses of Primary - never use Primary directly
class PrimPath(Primary):
''' PrimPath is a list of elements needed to identify a value
For example, "i!j!k(5)" is stored as:
[ 'i', 'j', 'k', {'index':[Expression list]}]
(in that case, 5 is an index)
other example: "hello(world)" ->
['hello', {'procParams':[Expression list]'}]
(in that case, hello is an operator and world is its parameter)
'''
class PrimCall(Primary):
is_raw = False
class PrimCall(PrimPath):
pass
class PrimIndex(PrimPath):
pass
class PrimIndex(Primary):
is_raw = False
class PrimSubstring(PrimPath):
pass
class PrimSubstring(Primary):
is_raw = False
class PrimSelector(PrimPath):
pass
class PrimSelector(Primary):
is_raw = False
class PrimVariable(PrimPath):
pass
class PrimVariable(Primary):
is_raw = False
class PrimFPAR(PrimVariable):
......
......@@ -307,7 +307,7 @@ def is_constant(var):
return False
if isinstance(var, ogAST.PrimConstant):
return True
if DV and isinstance(var, ogAST.PrimPath):
if DV and isinstance(var, ogAST.PrimVariable):
for mod in DV.asn1Modules:
for constant in DV.exportedVariables[mod]:
if(constant.lower() == var.value[0].lower().replace('_', '-')):
......@@ -455,7 +455,7 @@ def check_and_fix_op_params(op_name, expr_list, context):
dataview_type = UNKNOWN_TYPE
expr = ogAST.ExprAssign()
expr.left = ogAST.PrimPath()
expr.left = ogAST.PrimVariable()
expr.left.exprType = dataview_type
expr.right = param
fix_expression_types(expr, context)
......@@ -786,7 +786,7 @@ def fix_expression_types(expr, context):
asn_type = asn_type.type
for idx, elem in enumerate(value.value):
check_expr = ogAST.ExprAssign()
check_expr.left = ogAST.PrimPath()
check_expr.left = ogAST.PrimVariable()
check_expr.left.exprType = asn_type
check_expr.right = elem
fix_expression_types(check_expr, context)
......@@ -820,7 +820,7 @@ def fix_expression_types(expr, context):
except AttributeError:
raise TypeError('Field not found: ' + field)
check_expr = ogAST.ExprAssign()
check_expr.left = ogAST.PrimPath()
check_expr.left = ogAST.PrimVariable()
check_expr.left.exprType = expected_type
check_expr.right = fd_expr
fix_expression_types(check_expr, context)
......@@ -841,7 +841,7 @@ def fix_expression_types(expr, context):
except AttributeError:
raise TypeError('Field not found in CHOICE: ' + field)
check_expr = ogAST.ExprAssign()
check_expr.left = ogAST.PrimPath()
check_expr.left = ogAST.PrimVariable()
check_expr.left.exprType = expected_type
check_expr.right = expr.right.value['value']
fix_expression_types(check_expr, context)
......@@ -850,7 +850,7 @@ def fix_expression_types(expr, context):
for det in ('then', 'else'):
# Recursively fix possibly missing types in the expression
check_expr = ogAST.ExprAssign()
check_expr.left = ogAST.PrimPath()
check_expr.left = ogAST.PrimVariable()
check_expr.left.exprType = expr.left.exprType
check_expr.right = expr.right.value[det]
fix_expression_types(check_expr, context)
......@@ -1551,7 +1551,7 @@ def variables(root, ta_ast, context):
errors.extend(err)
warnings.extend(warn)
expr = ogAST.ExprAssign()
expr.left = ogAST.PrimPath()
expr.left = ogAST.PrimVariable()
expr.left.inputString = var[-1]
expr.left.exprType = asn1_sort
expr.right = def_value
......@@ -1810,7 +1810,7 @@ def procedure(root, parent=None, context=None):
+ proc.inputString)
elif proc.return_type and each.return_expr:
check_expr = ogAST.ExprAssign()
check_expr.left = ogAST.PrimPath()
check_expr.left = ogAST.PrimVariable()
check_expr.left.exprType = proc.return_type
check_expr.right = each.return_expr
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment