Commit 780edb14 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Minor fix in primary expressions

parent 49b62df6
......@@ -368,7 +368,8 @@ def fix_special_operators(op_name, expr_list, context):
raise TypeError('Length operator works only on strings/lists')
elif op_name.lower() == 'present' and basic.kind != 'ChoiceType':
raise TypeError('Present operator works only on CHOICE types')
elif op_name.lower() in ('abs', 'float', 'fix') and not is_numeric(basic):
elif op_name.lower() in ('abs', 'float', 'fix') \
and not is_numeric(basic):
raise TypeError('"{}" operator needs a numerical parameter'.format(
op_name))
elif op_name.lower() == 'power':
......@@ -1294,23 +1295,32 @@ def primary_call(root, context):
params_bty = [find_basic_type(p.exprType) for p in params]
if ident == 'present':
node.exprType = type('present', (object,), {
'kind': 'ChoiceEnumeratedType',
'EnumValues': params_bty[0].Children
})
try:
node.exprType = type('present', (object,), {
'kind': 'ChoiceEnumeratedType',
'EnumValues': params_bty[0].Children
})
except AttributeError:
errors.append(error(root, 'Parameter type is not a CHOICE'))
elif ident in ('length', 'fix'):
# result is an integer type with range of the param type
node.exprType = type('fix', (INTEGER,), {
'Min': params_bty[0].Min,
'Max': params_bty[0].Max
})
try:
node.exprType = type('fix', (INTEGER,), {
'Min': params_bty[0].Min,
'Max': params_bty[0].Max
})
except AttributeError:
errors.append(error(root, 'Parameter type has no range'))
elif ident == 'float':
node.exprType = type('float_op', (REAL,), {
'Min': params_bty[0].Min,
'Max': params_bty[0].Max
})
try:
node.exprType = type('float_op', (REAL,), {
'Min': params_bty[0].Min,
'Max': params_bty[0].Max
})
except AttributeError:
errors.append(error(root, 'Parameter type has no range'))
elif ident == 'power':
try:
......@@ -1322,12 +1332,18 @@ def primary_call(root, context):
})
except OverflowError:
errors.append(error(root, 'Result can exceeds 64-bits'))
except AttributeError:
errors.append(error(root, 'Parameter type has no range'))
elif ident == 'abs':
node.exprType = type('Abs', (params_bty[0],), {
'Min': str(max(float(params_bty[0].Min), 0)),
'Max': str(max(float(params_bty[0].Max), 0))
})
try:
node.exprType = type('Abs', (params_bty[0],), {
'Min': str(max(float(params_bty[0].Min), 0)),
'Max': str(max(float(params_bty[0].Max), 0))
})
except AttributeError:
msg = 'Type Error, check the parameter'
errors.append(error(root, '"Abs" parameter type has no range'))
return node, errors, warnings
......
/* CIF PROCESS (150, 150), (150, 75) */
/* CIF PROCESS (149, 150), (150, 75) */
PROCESS og;
/* CIF TEXT (0, 0), (298, 286) */
-- A Demo to test octet strings
......@@ -19,63 +19,64 @@ dcl alwaysFalse Type2 := 0 in {1,2,3};
/* CIF ENDTEXT */
/* CIF START (427, 26), (100, 50) */
START;
/* CIF TASK (395, 91), (164, 53) */
/* CIF TASK (393, 91), (168, 83) */
TASK test := 5,
test := power(test, 1),
test := abs(-4+1),
test := abs(test)
/* CIF COMMENT (579, 100), (183, 35) */
/* CIF COMMENT (581, 114), (183, 35) */
COMMENT 'Task with unicode: voilà!';
/* CIF TASK (375, 159), (204, 50) */
/* CIF TASK (375, 189), (204, 50) */
TASK first_msg := 'Say hello first!'
/* CIF COMMENT (599, 159), (148, 50) */
/* CIF COMMENT (599, 189), (148, 50) */
COMMENT 'String assignment';
/* CIF PROCEDURECALL (402, 224), (149, 35) */
/* CIF PROCEDURECALL (402, 254), (149, 35) */
CALL writeln(first_msg);
/* CIF TASK (394, 274), (165, 50) */
/* CIF TASK (394, 304), (165, 50) */
TASK seq := default_seqof,
seq := {1,2,3}
/* CIF COMMENT (579, 274), (204, 50) */
/* CIF COMMENT (579, 304), (204, 50) */
COMMENT 'default_seqof is a constant
defined in the ASN.1 model';
/* CIF TASK (345, 339), (263, 50) */
/* CIF TASK (345, 369), (263, 50) */
TASK seq := seq // {4, test} // default_seqof
/* CIF COMMENT (629, 339), (156, 50) */
/* CIF COMMENT (629, 369), (156, 50) */
COMMENT 'Concatenate
two SEQUENCE OF';
/* CIF TASK (408, 404), (137, 50) */
/* CIF TASK (408, 434), (137, 50) */
TASK 'seq(1) := seq(2)';
/* CIF TASK (380, 469), (193, 50) */
/* CIF TASK (380, 499), (193, 50) */
TASK seq := seq(1,2) // seq(4,5)
/* CIF COMMENT (593, 469), (166, 50) */
/* CIF COMMENT (593, 499), (166, 50) */
COMMENT 'Remove 3rd element';
/* CIF DECISION (425, 534), (104, 70) */
/* CIF DECISION (425, 564), (104, 70) */
DECISION test in seq
/* CIF COMMENT (549, 549), (170, 39) */
/* CIF COMMENT (549, 579), (170, 39) */
COMMENT 'Test the "in" operator
Unicode test: Ï';
/* CIF ANSWER (335, 624), (100, 35) */
/* CIF ANSWER (335, 654), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (308, 674), (154, 50) */
/* CIF PROCEDURECALL (308, 704), (154, 50) */
CALL writeln('All OK (1)');
/* CIF ANSWER (498, 624), (100, 35) */
/* CIF ANSWER (498, 654), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (466, 674), (164, 50) */
/* CIF PROCEDURECALL (466, 704), (164, 50) */
CALL writeln('NOT OK (1)')
/* CIF COMMENT (650, 681), (117, 35) */
/* CIF COMMENT (650, 711), (117, 35) */
COMMENT 'Call UnicÔDË';
ENDDECISION;
/* CIF DECISION (427, 739), (100, 70) */
/* CIF DECISION (427, 769), (100, 70) */
DECISION 3 in seq;
/* CIF ANSWER (341, 829), (100, 35) */
/* CIF ANSWER (341, 859), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (309, 879), (164, 50) */
/* CIF PROCEDURECALL (309, 909), (164, 50) */
CALL writeln('NOT OK (2)');
/* CIF ANSWER (513, 829), (100, 35) */
/* CIF ANSWER (513, 859), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (482, 879), (161, 50) */
/* CIF PROCEDURECALL (482, 909), (161, 50) */
CALL writeln('All OK (2)');
ENDDECISION;
/* CIF NEXTSTATE (427, 944), (100, 50) */
/* CIF NEXTSTATE (427, 974), (100, 50) */
NEXTSTATE Wait;
/* CIF STATE (1204, 151), (100, 50) */
STATE Running;
......@@ -135,47 +136,47 @@ against current Length';
NEXTSTATE Running;
ENDDECISION;
ENDSTATE;
/* CIF STATE (427, 944), (100, 50) */
/* CIF STATE (427, 974), (100, 50) */
STATE Wait;
/* CIF INPUT (427, 1014), (100, 50) */
/* CIF INPUT (427, 1044), (100, 50) */
INPUT go(msg)
/* CIF COMMENT (547, 1021), (120, 35) */
/* CIF COMMENT (547, 1051), (120, 35) */
COMMENT 'Ïñpût unicode';
/* CIF DECISION (420, 1079), (114, 70) */
/* CIF DECISION (420, 1109), (114, 70) */
DECISION msg = 'hello'
/* CIF COMMENT (554, 1089), (128, 50) */
/* CIF COMMENT (554, 1119), (128, 50) */
COMMENT 'Boolean test
on string value';
/* CIF ANSWER (638, 1169), (100, 35) */
/* CIF ANSWER (638, 1199), (100, 35) */
(FALSE):
/* CIF OUTPUT (618, 1219), (139, 50) */
/* CIF OUTPUT (618, 1249), (139, 50) */
OUTPUT rezult(first_msg)
/* CIF COMMENT (777, 1226), (85, 35) */
/* CIF COMMENT (777, 1256), (85, 35) */
COMMENT 'OûtpUT';
/* CIF NEXTSTATE (638, 1284), (100, 50) */
/* CIF NEXTSTATE (638, 1314), (100, 50) */
NEXTSTATE Wait;
/* CIF ANSWER (367, 1169), (100, 35) */
/* CIF ANSWER (367, 1199), (100, 35) */
(TRUE):
/* CIF OUTPUT (344, 1219), (145, 50) */
/* CIF OUTPUT (344, 1249), (145, 50) */
OUTPUT rezult('Welcome')
/* CIF COMMENT (509, 1219), (95, 50) */
/* CIF COMMENT (509, 1249), (95, 50) */
COMMENT 'Send raw
string';
/* CIF DECISION (368, 1284), (98, 50) */
/* CIF DECISION (368, 1314), (98, 50) */
DECISION 3 in {1,2,3};
/* CIF ANSWER (328, 1354), (88, 23) */
/* CIF ANSWER (328, 1384), (88, 23) */
(1 in {1,2}):
/* CIF ANSWER (418, 1354), (88, 23) */
/* CIF ANSWER (418, 1384), (88, 23) */
(0 in {1,2}):
ENDDECISION;
/* CIF DECISION (368, 1417), (98, 50) */
/* CIF DECISION (368, 1462), (98, 50) */
DECISION 4 in {1,2,3};
/* CIF ANSWER (337, 1487), (70, 23) */
/* CIF ANSWER (337, 1532), (70, 23) */
(true):
/* CIF ANSWER (427, 1487), (70, 23) */
/* CIF ANSWER (427, 1532), (70, 23) */
(false):
ENDDECISION;
/* CIF NEXTSTATE (367, 1525), (100, 50) */
/* CIF NEXTSTATE (367, 1585), (100, 50) */
NEXTSTATE Running;
ENDDECISION;
ENDSTATE;
......
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