Commit cffde7b0 authored by Maxime Perrotin's avatar Maxime Perrotin

Fix a few more int/uint issues

parent d2afcc9e
......@@ -97,6 +97,16 @@ SHARED_LIB = False
UNICODE_SEP = u'\u00dc'
LPREFIX = u'ctxt'
def is_numeric(string):
''' Return true if value is a number '''
try:
float(string)
except ValueError:
return False
return True
def external_ri_list(process):
''' Helper function: create a list of RI with proper signature
Used for the formal parameters of generic packages when using process type
......@@ -1390,7 +1400,7 @@ def _task_forloop(task, **kwargs):
else:
# Step is not directly supported in Ada, we need to use 'while'
stmt.extend(['declare',
u'{it} : Asn1Int := {start};'
u'{it} : Integer := {start};'
.format(it=loop['var'],
start=start_str),
'',
......@@ -1490,9 +1500,11 @@ def _prim_call(prim):
local_decl.extend(local_var)
ada_string += '{op}({param})'.format(
param=param_str,
op='abs' if ident == 'abs' else
op='Asn1UInt (abs' if ident == 'abs' else
'Asn1Int' if ident == 'fix' else 'Asn1Real'
if ident == 'float' else 'ERROR')
if ident == 'abs':
ada_string += ')'
elif ident == 'power':
operands = [None, None]
for idx, param in enumerate(params):
......@@ -1730,7 +1742,6 @@ def _primary_state_reference(prim):
''' Reference to the current state '''
return [], u'{}.state'.format(LPREFIX), []
@expression.register(ogAST.ExprPlus)
@expression.register(ogAST.ExprMul)
@expression.register(ogAST.ExprMinus)
......@@ -1751,15 +1762,9 @@ def _basic_operators(expr):
if isinstance (expr, ogAST.ExprMod):
bt = find_basic_type(expr.exprType)
right_is_numeric, left_is_numeric = True, True
try:
float(left_str)
except ValueError:
left_is_numeric = False
try:
float(right_str)
except ValueError:
right_is_numeric = False
# Check if either side is a literal number
right_is_numeric = is_numeric(right_str)
left_is_numeric = is_numeric(left_str)
lbty = find_basic_type(expr.left.exprType)
rbty = find_basic_type(expr.right.exprType)
......@@ -1988,7 +1993,11 @@ 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'(-Asn1Int({expr}))'.format(op=expr.operand, expr=expr_str)
if not is_numeric(expr_str):
ada_string = u'(-Asn1Int({expr}))'.format(op=expr.operand,
expr=expr_str)
else:
ada_string = u'(-{expr})'.format(expr=expr_str)
code.extend(expr_stmts)
local_decl.extend(expr_local)
return code, unicode(ada_string), local_decl
......
......@@ -4163,7 +4163,11 @@ def assign(root, context):
ogAST.ExprMod,
ogAST.PrimSequenceOf,
ogAST.PrimStringLiteral)):
expr.right.exprType = expr.left.exprType
if isinstance(expr.right, ogAST.PrimCall) \
and expr.right.value[0] == 'abs':
pass
else:
expr.right.exprType = expr.left.exprType
# XXX I don't understand why we don't set the type of right
# to the same value as left in case of ExprAppend
# Setting it - I did not see any place in the Ada backend where
......
......@@ -13,6 +13,7 @@ MyChoice ::= CHOICE {
},
f BOOLEAN
}
NegativeInt ::= INTEGER (-10..10)
Some-Thing ::= MyInteger
......
/* CIF PROCESS (149, 150), (150, 75) */
PROCESS og;
process og;
/* CIF TEXT (2755, 9), (298, 286) */
-- A Demo to test octet strings
-- using various symbols.
-- check that types are case insensitive
DCL first_msg, msg my_octStr;
DCL seq SeqOf;
DCL test Some_Thing;
dcl foo MyInteger := 3;
-- Unicode comments: héhé hôhÖ
dcl alwaysTrue Type2 := 3 in {1,2,3};
dcl alwaysFalse Type2 := 0 in {1,2,3};
dcl seqofbool seqBool := { true, true};
-- using various symbols.
-- check that types are case insensitive
DCL first_msg, msg my_octStr;
DCL seq SeqOf;
DCL test Some_Thing;
DCL nonPosInt NegativeInt := -5;
dcl foo MyInteger := 3;
-- Unicode comments: héhé hôhÖ
dcl alwaysTrue Type2 := 3 in {1,2,3};
dcl alwaysFalse Type2 := 0 in {1,2,3};
dcl seqofbool seqBool := { true, true};
/* CIF ENDTEXT */
/* CIF START (1427, 35), (100, 50) */
START;
/* CIF TASK (1370, 100), (214, 83) */
TASK test := 5,
/* CIF task (1370, 100), (214, 83) */
task test := 5,
test := power(test, 1),
test := abs(-4+1),
test := abs(test)
/* CIF COMMENT (1603, 123), (183, 35) */
COMMENT 'Task with unicode: voilà!';
/* CIF TASK (1375, 198), (204, 50) */
TASK first_msg := 'Say hello first!'
/* CIF COMMENT (1599, 198), (148, 50) */
COMMENT 'String assignment';
/* CIF PROCEDURECALL (1389, 263), (177, 35) */
CALL writeln( first_msg(1,2));
/* CIF PROCEDURECALL (1374, 313), (207, 35) */
CALL writeln( not (not not true));
/* CIF TASK (1395, 363), (165, 50) */
TASK seq := default_seqof,
/* CIF comment (1603, 123), (183, 35) */
comment 'Task with unicode: voilà!';
/* CIF task (1378, 203), (198, 38) */
task Nonposint := abs (Nonposint),
Nonposint := abs (-5);
/* CIF task (1375, 259), (204, 50) */
task first_msg := 'Say hello first!'
/* CIF comment (1599, 259), (148, 50) */
comment 'String assignment';
/* CIF PROCEDURECALL (1388, 324), (177, 35) */
call writeln( first_msg(1,2));
/* CIF PROCEDURECALL (1373, 374), (207, 35) */
call writeln( not (not not true));
/* CIF task (1394, 424), (165, 50) */
task seq := default_seqof,
seq := {1,2,3}
/* CIF COMMENT (1579, 363), (204, 50) */
COMMENT 'default_seqof is a constant
/* CIF comment (1579, 424), (204, 50) */
comment 'default_seqof is a constant
defined in the ASN.1 model';
/* CIF TASK (1346, 428), (263, 50) */
TASK seq := seq // {4, test} // default_seqof
/* CIF COMMENT (1629, 428), (156, 50) */
COMMENT 'Concatenate
/* CIF task (1345, 489), (263, 50) */
task seq := seq // {4, test} // default_seqof
/* CIF comment (1629, 489), (156, 50) */
comment 'Concatenate
two SEQUENCE OF';
/* CIF TASK (1409, 493), (137, 50) */
TASK 'seq(1) := seq(2)';
/* CIF TASK (1383, 558), (189, 50) */
TASK seq := seq(0,1) // seq(3, 4)
/* CIF COMMENT (1590, 558), (166, 50) */
COMMENT 'Remove 3rd element';
/* CIF TASK (1407, 623), (140, 53) */
TASK for x in seq:
/* CIF task (1408, 554), (137, 50) */
task 'seq(1) := seq(2)';
/* CIF task (1382, 619), (189, 50) */
task seq := seq(0,1) // seq(3, 4)
/* CIF comment (1590, 619), (166, 50) */
comment 'Remove 3rd element';
/* CIF task (1407, 684), (140, 53) */
task for x in seq:
call writeln(x);
endfor;
/* CIF PROCEDURECALL (1395, 691), (164, 35) */
CALL writeln('test=', test);
/* CIF DECISION (1425, 741), (104, 70) */
DECISION test in seq
/* CIF COMMENT (1549, 756), (170, 39) */
COMMENT 'Test the "in" operator
/* CIF PROCEDURECALL (1395, 752), (164, 35) */
call writeln('test=', test);
/* CIF decision (1425, 802), (104, 70) */
decision test in seq
/* CIF comment (1549, 817), (170, 39) */
comment 'Test the "in" operator
Unicode test: Ï';
/* CIF ANSWER (1335, 831), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (1308, 881), (154, 50) */
CALL writeln('All OK (1)');
/* CIF ANSWER (1498, 831), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (1466, 881), (164, 50) */
CALL writeln('NOT OK (1)')
/* CIF COMMENT (1650, 888), (117, 35) */
COMMENT 'Call UnicÔDË';
ENDDECISION;
/* CIF DECISION (1427, 946), (100, 70) */
DECISION 3 in seq
/* CIF COMMENT (1547, 963), (256, 35) */
COMMENT 'test==3 so it should also return true';
/* CIF ANSWER (1341, 1036), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (1309, 1086), (164, 50) */
CALL writeln('ALL OK (2)');
/* CIF ANSWER (1513, 1036), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (1481, 1086), (164, 50) */
CALL writeln('NOT OK (2)');
ENDDECISION;
/* CIF NEXTSTATE (1427, 1151), (100, 50) */
/* CIF ANSWER (1335, 892), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (1308, 942), (154, 50) */
call writeln('All OK (1)');
/* CIF ANSWER (1498, 892), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (1466, 942), (164, 50) */
call writeln('NOT OK (1)')
/* CIF comment (1650, 949), (117, 35) */
comment 'Call UnicÔDË';
enddecision;
/* CIF decision (1427, 1007), (100, 70) */
decision 3 in seq
/* CIF comment (1547, 1024), (256, 35) */
comment 'test==3 so it should also return true';
/* CIF ANSWER (1341, 1097), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (1309, 1147), (164, 50) */
call writeln('ALL OK (2)');
/* CIF ANSWER (1513, 1097), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (1481, 1147), (164, 50) */
call writeln('NOT OK (2)');
enddecision;
/* CIF NEXTSTATE (1427, 1212), (100, 50) */
NEXTSTATE Wait;
/* CIF STATE (2204, 160), (100, 50) */
STATE Running;
/* CIF INPUT (2204, 230), (100, 50) */
INPUT go(msg);
/* CIF PROCEDURECALL (2203, 300), (101, 35) */
CALL writeln(msg);
/* CIF DECISION (2203, 350), (103, 70) */
DECISION msg
/* CIF COMMENT (2326, 360), (111, 50) */
COMMENT 'Switch-case
/* CIF state (2204, 160), (100, 50) */
state Running;
/* CIF input (2204, 230), (100, 50) */
input go(msg);
/* CIF PROCEDURECALL (2202, 300), (103, 35) */
call writeln(msg);
/* CIF decision (2202, 350), (103, 70) */
decision msg
/* CIF comment (2326, 360), (111, 50) */
comment 'Switch-case
on strings';
/* CIF ANSWER (2454, 440), (100, 35) */
('egg'):
/* CIF TASK (2434, 490), (141, 50) */
TASK msg := msg // '!!'
/* CIF COMMENT (2595, 490), (118, 50) */
COMMENT 'Concatenate
/* CIF ANSWER (2454, 440), (100, 35) */
('egg'):
/* CIF task (2433, 490), (141, 50) */
task msg := msg // '!!'
/* CIF comment (2595, 490), (118, 50) */
comment 'Concatenate
strings';
/* CIF OUTPUT (2429, 555), (150, 50) */
OUTPUT rezult(default_str)
/* CIF COMMENT (2594, 553), (161, 53) */
COMMENT 'Send a constant
/* CIF output (2429, 555), (150, 50) */
output rezult(default_str)
/* CIF comment (2594, 553), (161, 53) */
comment 'Send a constant
defined in the ASN.1
model';
/* CIF NEXTSTATE (2454, 620), (100, 50) */
NEXTSTATE Running
/* CIF COMMENT (2574, 627), (96, 35) */
COMMENT 'Néxtaytè';
/* CIF ANSWER (1864, 440), (100, 35) */
('end'):
/* CIF OUTPUT (1858, 490), (112, 50) */
OUTPUT rezult
/* CIF NEXTSTATE (2454, 620), (100, 50) */
NEXTSTATE Running
/* CIF comment (2574, 627), (96, 35) */
comment 'Néxtaytè';
/* CIF ANSWER (1864, 440), (100, 35) */
('end'):
/* CIF output (1858, 490), (112, 50) */
output rezult
('Goodbye!');
/* CIF NEXTSTATE (1864, 557), (100, 50) */
NEXTSTATE Wait;
/* CIF ANSWER (2042, 440), (100, 35) */
ELSE:
/* CIF TASK (2022, 490), (141, 50) */
TASK msg := msg // '!'
/* CIF COMMENT (2183, 490), (118, 50) */
COMMENT 'Concatenate
/* CIF NEXTSTATE (1864, 557), (100, 50) */
NEXTSTATE Wait;
/* CIF ANSWER (2042, 440), (100, 35) */
ELSE:
/* CIF task (2021, 490), (141, 50) */
task msg := msg // '!'
/* CIF comment (2183, 490), (118, 50) */
comment 'Concatenate
strings';
/* CIF PROCEDURECALL (2009, 560), (165, 35) */
CALL writeln('msg//! = ', msg);
/* CIF TASK (1995, 610), (195, 50) */
TASK msg := msg(3,4) // msg(1,2)
/* CIF COMMENT (2210, 610), (209, 53) */
COMMENT 'Concatenate two substrings
/* CIF PROCEDURECALL (2008, 560), (167, 35) */
call writeln('msg//! = ', msg);
/* CIF task (1994, 610), (195, 50) */
task msg := msg(3,4) // msg(1,2)
/* CIF comment (2210, 610), (209, 53) */
comment 'Concatenate two substrings
(can be used to remove an
element from a list)';
/* CIF PROCEDURECALL (1980, 680), (224, 35) */
CALL writeln('msg(3,4)//(1,2) = ',msg);
/* CIF TASK (2011, 730), (163, 50) */
TASK msg := first_msg(1, 2)
/* CIF COMMENT (2186, 727), (177, 53) */
COMMENT 'Substring
/* CIF PROCEDURECALL (1980, 680), (224, 35) */
call writeln('msg(3,4)//(1,2) = ',msg);
/* CIF task (2010, 730), (163, 50) */
task msg := first_msg(1, 2)
/* CIF comment (2186, 727), (177, 53) */
comment 'Substring
TODO check range
against current Length';
/* CIF PROCEDURECALL (1992, 800), (199, 35) */
CALL writeln('first_msg(1,2)=',msg)
/* CIF COMMENT (2212, 800), (98, 35) */
COMMENT 'should be ay';
/* CIF OUTPUT (2038, 850), (108, 50) */
OUTPUT rezult(msg);
/* CIF NEXTSTATE (2042, 915), (100, 50) */
NEXTSTATE Running;
ENDDECISION;
ENDSTATE;
/* CIF STATE (1427, 1151), (100, 50) */
STATE Wait;
/* CIF INPUT (1427, 1221), (100, 50) */
INPUT go(msg)
/* CIF COMMENT (1547, 1228), (120, 35) */
COMMENT 'Ïñpût unicode';
/* CIF DECISION (1420, 1286), (114, 70) */
DECISION msg = 'hello'
/* CIF COMMENT (1554, 1296), (128, 50) */
COMMENT 'Boolean test
/* CIF PROCEDURECALL (1992, 800), (200, 35) */
call writeln('first_msg(1,2)=',msg)
/* CIF comment (2212, 800), (100, 35) */
comment 'should be ay';
/* CIF output (2038, 850), (108, 50) */
output rezult(msg);
/* CIF NEXTSTATE (2042, 915), (100, 50) */
NEXTSTATE Running;
enddecision;
endstate;
/* CIF state (1427, 1212), (100, 50) */
state Wait;
/* CIF input (1427, 1282), (100, 50) */
input go(msg)
/* CIF comment (1547, 1289), (120, 35) */
comment 'Ïñpût unicode';
/* CIF decision (1420, 1347), (114, 70) */
decision msg = 'hello'
/* CIF comment (1554, 1357), (128, 50) */
comment 'Boolean test
on string value';
/* CIF ANSWER (1638, 1376), (100, 35) */
(FALSE):
/* CIF OUTPUT (1619, 1426), (139, 50) */
OUTPUT rezult(first_msg)
/* CIF COMMENT (1777, 1433), (85, 35) */
COMMENT 'OûtpUT';
/* CIF NEXTSTATE (1638, 1491), (100, 50) */
NEXTSTATE Wait;
/* CIF ANSWER (1367, 1376), (100, 35) */
(TRUE):
/* CIF OUTPUT (1345, 1426), (145, 50) */
OUTPUT rezult('Welcome')
/* CIF COMMENT (1509, 1426), (95, 50) */
COMMENT 'Send raw
/* CIF ANSWER (1638, 1437), (100, 35) */
(FALSE):
/* CIF output (1618, 1487), (139, 50) */
output rezult(first_msg)
/* CIF comment (1777, 1494), (85, 35) */
comment 'OûtpUT';
/* CIF NEXTSTATE (1638, 1552), (100, 50) */
NEXTSTATE Wait;
/* CIF ANSWER (1367, 1437), (100, 35) */
(TRUE):
/* CIF output (1344, 1487), (145, 50) */
output rezult('Welcome')
/* CIF comment (1509, 1487), (95, 50) */
comment 'Send raw
string';
/* CIF DECISION (1368, 1491), (98, 50) */
DECISION 3 in {1,2,3};
/* CIF ANSWER (1328, 1561), (88, 33) */
(1 in {1,2}):
/* CIF ANSWER (1418, 1561), (88, 33) */
(0 in {1,2}):
ENDDECISION;
/* CIF DECISION (1368, 1609), (98, 50) */
DECISION 4 in {1,2,3};
/* CIF ANSWER (1339, 1679), (66, 33) */
(true):
/* CIF ANSWER (1422, 1679), (70, 33) */
(false):
ENDDECISION;
/* CIF NEXTSTATE (1367, 1727), (100, 50) */
NEXTSTATE Running;
ENDDECISION;
ENDSTATE;
ENDPROCESS og;
\ No newline at end of file
/* CIF decision (1368, 1552), (98, 50) */
decision 3 in {1,2,3};
/* CIF ANSWER (1328, 1622), (88, 33) */
(1 in {1,2}):
/* CIF ANSWER (1418, 1622), (88, 33) */
(0 in {1,2}):
enddecision;
/* CIF decision (1368, 1670), (98, 50) */
decision 4 in {1,2,3};
/* CIF ANSWER (1339, 1740), (66, 33) */
(true):
/* CIF ANSWER (1422, 1740), (70, 33) */
(false):
enddecision;
/* CIF NEXTSTATE (1367, 1788), (100, 50) */
NEXTSTATE Running;
enddecision;
endstate;
endprocess og;
\ 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