Commit ee511a20 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Support 'state' primary in expressions

parent d745b6c8
......@@ -1183,6 +1183,12 @@ def _prim_selector(prim):
return stmts, unicode(ada_string), local_decl
@expression.register(ogAST.PrimStateReference)
def _primary_state_reference(prim):
''' Reference to the current state '''
return [], u'state', []
@expression.register(ogAST.ExprPlus)
@expression.register(ogAST.ExprMul)
@expression.register(ogAST.ExprMinus)
......@@ -1446,7 +1452,8 @@ def _enumerated_value(primary):
for each in basic.EnumValues:
if each.lower() == enumerant:
break
ada_string = (u'asn1Scc' + basic.EnumValues[each].EnumID)
prefix = type_name(basic)
ada_string = (prefix + basic.EnumValues[each].EnumID)
return [], unicode(ada_string), []
......@@ -1466,7 +1473,7 @@ def _choice_determinant(primary):
def _integer(primary):
''' Generate code for a raw numerical value '''
if float(primary.value[0]) < 0:
# Parentesize negative integers for maintaining
# Put brackets around negative integers for maintaining
# the precedence in the generated code
ada_string = u'({})'.format(primary.value[0])
else:
......@@ -2047,6 +2054,10 @@ def type_name(a_type, use_prefix=True):
return u'String'
elif a_type.kind == 'ChoiceEnumeratedType':
return u'Asn1Int'
elif a_type.kind == 'StateEnumeratedType':
return u''
elif a_type.kind == 'EnumeratedType':
return u'asn1Scc'
else:
raise NotImplementedError('Type name for {}'.format(a_type.kind))
......
......@@ -224,6 +224,13 @@ class PrimConstant(Primary):
is_raw = False
class PrimStateReference(Primary):
''' This primary ("state" keyword) is used only in stop conditions and
possibly in the future in observers, to reference the state of the system
'''
is_raw = False
class PrimBitStringLiteral(Primary):
''' Not supported yet '''
pass
......
......@@ -881,7 +881,7 @@ def fix_enumerated_and_choice(expr_enum, context):
''' If left side of the expression is of Enumerated or Choice type,
check if right side is a literal of that sort, and update type '''
kind = find_basic_type(expr_enum.left.exprType).kind
if kind == 'EnumeratedType':
if kind in ('EnumeratedType', 'StateEnumeratedType'):
prim = ogAST.PrimEnumeratedValue(primary=expr_enum.right)
elif kind == 'ChoiceEnumeratedType':
prim = ogAST.PrimChoiceDeterminant(primary=expr_enum.right)
......@@ -907,6 +907,7 @@ def fix_expression_types(expr, context):
typed_expr = side
ref_type = typed_expr.exprType
# If a side is a raw Sequence Of with unknown type, try to resolve it
for side_a, side_b in permutations(('left', 'right')):
value = getattr(expr, side_a) # get expr.left then expr.right
......@@ -1721,6 +1722,13 @@ def primary(root, context):
prim = ogAST.PrimOctetStringLiteral()
warnings.append(
warning(root, 'Octet string literal not supported yet'))
elif root.type == lexer.STATE:
prim = ogAST.PrimStateReference()
prim.exprType = ENUMERATED()
prim.exprType.kind = 'StateEnumeratedType'
prim.exprType.EnumValues = {value: type('', (object,),
{'EnumID': value})
for value in context.mapping.viewkeys()}
else:
errors.append('Parsing error (token {}, line {}, "{}")'
.format(sdl92Parser.tokenNames[root.type],
......
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