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

Merge branch 'master' of https://github.com/dbrabera/opengeode

parents c12b7184 07edee91
......@@ -589,7 +589,6 @@ def _call_external_function(output):
def _task_assign(task):
''' A list of assignments in a task symbol '''
code, local_decl = [], []
ada_string = ''
if task.comment:
code.extend(traceability(task.comment))
for expr in task.elems:
......@@ -850,8 +849,6 @@ def _prim_substring(prim):
stmts.extend(receiver_stms)
local_decl.extend(receiver_decl)
receiver_ty_name = receiver.exprType.ReferencedTypeName.replace('-', '_')
r1_stmts, r1_string, r1_local = expression(prim.value[1]['substring'][0])
r2_stmts, r2_string, r2_local = expression(prim.value[1]['substring'][1])
......@@ -923,6 +920,7 @@ def _basic_operators(expr):
local_decl.extend(right_local)
return code, unicode(ada_string), local_decl
@expression.register(ogAST.ExprAssign)
def _assign_expression(expr):
''' Assignment: almost the same a basic operators, except for strings '''
......@@ -949,6 +947,7 @@ def _assign_expression(expr):
local_decl.extend(right_local)
return code, '', local_decl
@expression.register(ogAST.ExprOr)
@expression.register(ogAST.ExprAnd)
@expression.register(ogAST.ExprXor)
......@@ -993,12 +992,29 @@ def _bitwise_operators(expr):
@expression.register(ogAST.ExprNot)
def _not_expression(expr):
''' Generate the code for a not expression '''
code, local_decl = [], []
expr_stmts, expr_str, expr_local = expression(expr.expr)
basic_type = find_basic_type(expr.exprType)
if basic_type.kind != 'BooleanType':
expr_payload = expr_str + string_payload(expr.expr, expr_str)
ada_string = u'(Data => (not {expr}))'.format(expr=expr_payload)
else:
ada_string = u'(not {expr})'.format(expr=expr_str)
code.extend(expr_stmts)
local_decl.extend(expr_local)
return code, unicode(ada_string), local_decl
@expression.register(ogAST.ExprNeg)
def _unary_operator(expr):
''' Generate the code for an unary expression '''
def _neg_expression(expr):
''' Generate the code for a negative expression '''
code, local_decl = [], []
expr_stmts, expr_str, expr_local = expression(expr.expr)
ada_string = u'({op} {expr})'.format(op=expr.operand, expr=expr_str)
ada_string = u'(-{expr})'.format(op=expr.operand, expr=expr_str)
code.extend(expr_stmts)
local_decl.extend(expr_local)
return code, unicode(ada_string), local_decl
......@@ -1581,7 +1597,6 @@ def string_payload(prim, ada_string):
prim_basic = find_basic_type(prim.exprType)
payload = ''
if prim_basic.kind in ('SequenceOfType', 'OctetStringType'):
range_string = ''
if int(prim_basic.Min) != int(prim_basic.Max):
payload = u'.Data(1..{}.Length)'.format(ada_string)
else:
......@@ -1589,7 +1604,6 @@ def string_payload(prim, ada_string):
return payload
def find_basic_type(a_type):
''' Return the ASN.1 basic type of a_type '''
basic_type = a_type
......
......@@ -1060,8 +1060,8 @@ def logic_expression(root, context):
continue
elif bty.kind == 'BitStringType' and bty.Min == bty.Max:
continue
elif bty.kind == 'SequenceOfType' and bty.type.kind == 'BooleanType'\
and bty.Min == bty.Max:
elif bty.kind == 'SequenceOfType' and bty.Min == bty.Max \
and find_basic_type(bty.type).kind == 'BooleanType':
continue
else:
msg = 'Bitwise operators only work with Booleans, ' \
......@@ -1212,7 +1212,8 @@ def not_expression(root, context):
expr.exprType = BOOLEAN
elif bty.kind == 'BitStringType':
expr.exprType = expr.expr.exprType
elif bty.kind == 'SequenceOfType' and bty.type.kind == 'BooleanType':
elif bty.kind == 'SequenceOfType' and \
find_basic_type(bty.type).kind == 'BooleanType':
expr.exprType = expr.expr.exprType
else:
msg = 'Bitwise operators only work with booleans '\
......
......@@ -6,8 +6,8 @@ Integer ::= INTEGER(-9223372036854775808..9223372036854775807)
Real ::= REAL (-100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0 .. 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0)
CharString ::= OCTET STRING (SIZE(0..100))
IntegerFixSeqof ::= SEQUENCE (SIZE(3)) OF Integer
IntegerVarSeqof ::= SEQUENCE (SIZE(0..100)) OF Integer
FixSeqof ::= SEQUENCE (SIZE(3)) OF Integer
VarSeqof ::= SEQUENCE (SIZE(0..100)) OF Integer
Seq ::= SEQUENCE {
i Integer,
......@@ -26,4 +26,6 @@ NestedSeq ::= SEQUENCE {
}
}
BoolSeqOf ::= SEQUENCE (SIZE(2)) OF Boolean
END
/* CIF PROCESS (145, 158), (150, 75) */
PROCESS expressions;
/* CIF TEXT (358, 168), (303, 168) */
/* CIF TEXT (350, 175), (303, 216) */
DCL i Integer;
DCL f Real;
DCL b Boolean;
DCL s CharString;
DCL fixSeqOf1 IntegerFixSeqof;
DCL fixSeqOf2 IntegerFixSeqof;
DCL varSeqOf1 IntegerVarSeqof;
DCL varSeqOf2 IntegerVarSeqof;
DCL fixSeqOf1 FixSeqof;
DCL fixSeqOf2 FixSeqof;
DCL varSeqOf1 VarSeqof;
DCL varSeqOf2 VarSeqof;
DCL seq Seq;
DCL nestedSeq NestedSeq;
DCL boolSeqOf1 BoolSeqOf;
DCL boolSeqOf2 BoolSeqOf;
DCL boolSeqOf3 BoolSeqOf;
/* CIF ENDTEXT */
/* CIF START (0, 0), (100, 50) */
START;
......@@ -122,51 +125,79 @@ DCL nestedSeq NestedSeq;
TASK s := 'HELLO';
/* CIF PROCEDURECALL (-191, 2700), (484, 35) */
CALL assert(s // s // s = 'HELLOHELLOHELLO', 's // s // s = "HELLOHELLOHELLO"');
/* CIF TASK (-148, 2750), (399, 35) */
/* CIF TASK (-66, 2750), (235, 35) */
TASK boolSeqOf1 := {true, false};
/* CIF TASK (-66, 2800), (235, 35) */
TASK boolSeqOf2 := {false, true};
/* CIF TASK (-99, 2850), (301, 35) */
TASK boolSeqOf3 := boolSeqOf1 and boolSeqOf2;
/* CIF PROCEDURECALL (-98, 2900), (298, 35) */
CALL assert(not boolSeqOf3(0), 'boolSeqOf3(0)');
/* CIF PROCEDURECALL (-110, 2950), (322, 35) */
CALL assert(not boolSeqOf3(1),'not boolSeqOf3(1)');
/* CIF TASK (-99, 3000), (301, 35) */
TASK boolSeqOf3 := boolSeqOf1 or boolSeqOf2;
/* CIF PROCEDURECALL (-86, 3050), (274, 35) */
CALL assert(boolSeqOf3(0), 'boolSeqOf3(0)');
/* CIF PROCEDURECALL (-86, 3100), (274, 35) */
CALL assert(boolSeqOf3(1), 'boolSeqOf3(1)');
/* CIF TASK (-99, 3150), (301, 35) */
TASK boolSeqOf3 := boolSeqOf1 xor boolSeqOf2;
/* CIF PROCEDURECALL (-86, 3200), (274, 35) */
CALL assert(boolSeqOf3(0), 'boolSeqOf3(0)');
/* CIF PROCEDURECALL (-86, 3250), (274, 35) */
CALL assert(boolSeqOf3(1), 'boolSeqOf3(1)');
/* CIF TASK (-60, 3300), (223, 35) */
TASK boolSeqOf3 := not boolSeqOf1;
/* CIF PROCEDURECALL (-110, 3350), (322, 35) */
CALL assert(not boolSeqOf3(0), 'not boolSeqOf3(0)');
/* CIF PROCEDURECALL (-86, 3400), (274, 35) */
CALL assert(boolSeqOf3(1), 'boolSeqOf3(1)');
/* CIF TASK (-148, 3450), (399, 35) */
TASK '------------------------------- Unary expressions -------------------------------';
/* CIF TASK (3, 2800), (95, 35) */
/* CIF TASK (3, 3500), (95, 35) */
TASK b := false;
/* CIF PROCEDURECALL (-29, 2850), (160, 35) */
/* CIF PROCEDURECALL (-29, 3550), (160, 35) */
CALL assert(not b, 'not b');
/* CIF TASK (14, 2900), (73, 35) */
/* CIF TASK (14, 3600), (73, 35) */
TASK i := 10;
/* CIF PROCEDURECALL (-37, 2950), (177, 35) */
/* CIF PROCEDURECALL (-37, 3650), (177, 35) */
CALL assert(-i = -10, '-i = -10');
/* CIF TASK (-151, 3000), (405, 35) */
/* CIF TASK (-151, 3700), (405, 35) */
TASK '------------------------------- Primary Expression -------------------------------';
/* CIF PROCEDURECALL (-84, 3050), (271, 35) */
/* CIF PROCEDURECALL (-84, 3750), (271, 35) */
CALL assert(((1 + 1) * 4) = 8, '((1 + 1) * 4) = 8');
/* CIF PROCEDURECALL (-157, 3100), (417, 35) */
/* CIF PROCEDURECALL (-157, 3800), (417, 35) */
CALL assert(if true then 1 else 2 fi = 1, 'if true then 1 else 2 fi = 1');
/* CIF PROCEDURECALL (-183, 3150), (468, 35) */
/* CIF PROCEDURECALL (-183, 3850), (468, 35) */
CALL assert(if false then 1.0 else 2.0 fi = 2.0, 'if false then 1.0 else 2.0 fi = 2.0');
/* CIF PROCEDURECALL (-475, 3200), (1052, 35) */
/* CIF PROCEDURECALL (-475, 3900), (1052, 35) */
CALL assert(if false then false else (if true then (if false then false else true fi) else false fi) fi, 'if false then false else (if true then (if false then false else true fi) else false fi) fi');
/* CIF TASK (-183, 3250), (468, 35) */
/* CIF TASK (-183, 3950), (468, 35) */
TASK '------------------------------- Extended Primary Expressions -------------------------------';
/* CIF TASK (-30, 3300), (163, 35) */
/* CIF TASK (-30, 4000), (163, 35) */
TASK fixSeqOf1 := {2, 3, 4};
/* CIF PROCEDURECALL (-95, 3350), (293, 35) */
/* CIF PROCEDURECALL (-95, 4050), (293, 35) */
CALL assert(fixSeqOf1(1) = 3, 'fixSeqOf1(1) = 3');
/* CIF TASK (-31, 3400), (164, 35) */
/* CIF TASK (-31, 4100), (164, 35) */
TASK varSeqOf1 := {2, 3, 4};
/* CIF PROCEDURECALL (-99, 3450), (300, 35) */
/* CIF PROCEDURECALL (-99, 4150), (300, 35) */
CALL assert(varSeqOf1(1) = 3, 'varSeqOf1(1) = 3');
/* CIF TASK (-68, 3500), (239, 35) */
/* CIF TASK (-68, 4200), (239, 35) */
TASK seq := {i 1, b true, f 1.0, s 'HELLO'};
/* CIF PROCEDURECALL (-47, 3550), (196, 35) */
/* CIF PROCEDURECALL (-47, 4250), (196, 35) */
CALL assert(seq!i = 1, 'seq!i = 1');
/* CIF PROCEDURECALL (-69, 3600), (241, 35) */
/* CIF PROCEDURECALL (-69, 4300), (241, 35) */
CALL assert(seq!b = true, 'seq!b = true');
/* CIF PROCEDURECALL (-59, 3650), (221, 35) */
/* CIF PROCEDURECALL (-59, 4350), (221, 35) */
CALL assert(seq!f = 1.0, 'seq!f = 1.0');
/* CIF PROCEDURECALL (-93, 3700), (289, 35) */
/* CIF PROCEDURECALL (-93, 4400), (289, 35) */
CALL assert(seq!s = 'HELLO', 'seq!s = "HELLO"');
/* CIF TASK (-51, 3750), (204, 35) */
/* CIF TASK (-51, 4450), (204, 35) */
TASK nestedSeq := {a {b {c {d 9}}}};
/* CIF PROCEDURECALL (-126, 3800), (354, 35) */
/* CIF PROCEDURECALL (-126, 4500), (354, 35) */
CALL assert(nestedSeq!a!b!c!d = 9, 'nestedSeq!a!b!c!d = 9');
/* CIF NEXTSTATE (1, 3850), (100, 50) */
/* CIF NEXTSTATE (1, 4550), (100, 50) */
NEXTSTATE Wait;
ENDSTATE;
ENDPROCESS expressions;
\ No newline at end of file
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