Commit 1e87ba1b authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Added writeln support for OCTET STRINGs in Ada backend

parent 023b0538
......@@ -355,7 +355,7 @@ package {process_name} is'''.format(process_name=process_name,
code_labels.extend(code_label)
# Declare the local variables needed by the transitions in the template
decl = ['{line}'.format(line=l)
decl = [u'{line}'.format(line=l)
for l in local_decl_transitions]
taste_template.extend(decl)
taste_template.append('begin')
......@@ -429,8 +429,17 @@ def write_statement(param, newline):
# Raw string
string = '"' + param.value[1:-1].replace('"', "'") + '"'
else:
# XXX Cannot print an octet string like that...
code, string, local = expression(param)
if type_kind == 'OctetStringType':
# Octet string -> convert to Ada string
sep = u'\u00dc'
local.append(u'{}{}str : String(1 .. {});'
.format(string, sep, basic_type.Max))
code.extend([u"for i in {}.Data'Range loop".format(string),
u"{st}{sep}str(i) := Character'Val({st}.Data(i));"
.format(st=string, sep=sep),
u"end loop;"])
string = u"{}{}str".format(string, sep)
elif type_kind in ('IntegerType', 'RealType',
'BooleanType', 'Integer32Type'):
code, string, local = expression(param)
......@@ -444,7 +453,7 @@ def write_statement(param, newline):
cast = 'Integer'
string = u"{cast}'Image({s})".format(cast=cast, s=string)
else:
error = ('Unsupported parameter in write call ' +
error = (u'Unsupported parameter in write call ' +
param.inputString)
LOG.error(error)
raise TypeError(error)
......@@ -503,7 +512,6 @@ def _call_external_function(output):
tmp_id = 'tmp' + str(out['tmpVars'][0])
local_decl.append('{} : aliased Asn1Int;'
.format(tmp_id))
#local_decl.append('{} : aliased Interfaces.Integer_64' asn1SccT_Uint32;'.format(tmp_id))
code.append('{tmp} := {val};'.format(tmp=tmp_id, val=t_val))
code.append("SET_{timer}({value}'access);"
.format(timer=p_id, value=tmp_id))
......
/* CIF PROCESS (150, 150), (150, 75) */
PROCESS og;
/* CIF TEXT (-679, -140), (298, 286) */
/* CIF TEXT (0, 0), (298, 286) */
-- A Demo to test octet strings
-- using various symbols.
......@@ -17,163 +17,165 @@ dcl foo MyInteger := 3;
dcl alwaysTrue Type2 := 3 in {1,2,3};
dcl alwaysFalse Type2 := 0 in {1,2,3};
/* CIF ENDTEXT */
/* CIF START (-252, -114), (100, 50) */
/* CIF START (427, 26), (100, 50) */
START;
/* CIF TASK (-284, -49), (164, 53) */
/* CIF TASK (395, 91), (164, 53) */
TASK test := 5,
test := abs(-4+1),
test := abs(test)
/* CIF COMMENT (-100, -40), (183, 35) */
/* CIF COMMENT (579, 100), (183, 35) */
COMMENT 'Task with unicode: voilà!';
/* CIF TASK (-304, 19), (204, 50) */
/* CIF TASK (375, 159), (204, 50) */
TASK first_msg := 'Say hello first!'
/* CIF COMMENT (-80, 19), (148, 50) */
/* CIF COMMENT (599, 159), (148, 50) */
COMMENT 'String assignment';
/* CIF TASK (-284, 84), (165, 50) */
/* CIF PROCEDURECALL (402, 224), (149, 35) */
CALL writeln(first_msg);
/* CIF TASK (394, 274), (165, 50) */
TASK seq := default_seqof,
seq := {1,2,3}
/* CIF COMMENT (-100, 84), (204, 50) */
/* CIF COMMENT (579, 274), (204, 50) */
COMMENT 'default_seqof is a constant
defined in the ASN.1 model';
/* CIF TASK (-333, 149), (263, 50) */
/* CIF TASK (345, 339), (263, 50) */
TASK seq := seq // {4, test} // default_seqof
/* CIF COMMENT (-50, 149), (156, 50) */
/* CIF COMMENT (629, 339), (156, 50) */
COMMENT 'Concatenate
two SEQUENCE OF';
/* CIF TASK (-270, 214), (137, 50) */
/* CIF TASK (408, 404), (137, 50) */
TASK 'seq(1) := seq(2)';
/* CIF TASK (-298, 279), (193, 50) */
/* CIF TASK (380, 469), (193, 50) */
TASK seq := seq(1,2) // seq(4,5)
/* CIF COMMENT (-86, 279), (166, 50) */
/* CIF COMMENT (593, 469), (166, 50) */
COMMENT 'Remove 3rd element';
/* CIF DECISION (-254, 344), (104, 70) */
/* CIF DECISION (425, 534), (104, 70) */
DECISION test in seq
/* CIF COMMENT (-130, 359), (170, 39) */
/* CIF COMMENT (549, 549), (170, 39) */
COMMENT 'Test the "in" operator
Unicode test: Ï';
/* CIF ANSWER (-344, 434), (100, 35) */
/* CIF ANSWER (335, 624), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (-371, 484), (154, 50) */
/* CIF PROCEDURECALL (308, 674), (154, 50) */
CALL writeln('All OK (1)');
/* CIF ANSWER (-181, 434), (100, 35) */
/* CIF ANSWER (498, 624), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (-213, 484), (164, 50) */
/* CIF PROCEDURECALL (466, 674), (164, 50) */
CALL writeln('NOT OK (1)')
/* CIF COMMENT (-29, 491), (117, 35) */
/* CIF COMMENT (650, 681), (117, 35) */
COMMENT 'Call UnicÔDË';
ENDDECISION;
/* CIF DECISION (-252, 549), (100, 70) */
/* CIF DECISION (427, 739), (100, 70) */
DECISION 3 in seq;
/* CIF ANSWER (-338, 639), (100, 35) */
/* CIF ANSWER (341, 829), (100, 35) */
(TRUE):
/* CIF PROCEDURECALL (-370, 689), (164, 50) */
/* CIF PROCEDURECALL (309, 879), (164, 50) */
CALL writeln('NOT OK (2)');
/* CIF ANSWER (-166, 639), (100, 35) */
/* CIF ANSWER (513, 829), (100, 35) */
(FALSE):
/* CIF PROCEDURECALL (-196, 689), (161, 50) */
/* CIF PROCEDURECALL (482, 879), (161, 50) */
CALL writeln('All OK (2)');
ENDDECISION;
/* CIF NEXTSTATE (-252, 754), (100, 50) */
/* CIF NEXTSTATE (427, 944), (100, 50) */
NEXTSTATE Wait;
/* CIF STATE (420, 11), (100, 50) */
/* CIF STATE (1204, 151), (100, 50) */
STATE Running;
/* CIF INPUT (420, 81), (100, 50) */
/* CIF INPUT (1204, 221), (100, 50) */
INPUT go(msg);
/* CIF DECISION (418, 146), (103, 70) */
/* CIF DECISION (1202, 286), (103, 70) */
DECISION msg
/* CIF COMMENT (542, 156), (111, 50) */
/* CIF COMMENT (1326, 296), (111, 50) */
COMMENT 'Switch-case
on strings';
/* CIF ANSWER (670, 236), (100, 35) */
/* CIF ANSWER (1454, 376), (100, 35) */
('egg'):
/* CIF TASK (649, 286), (141, 50) */
/* CIF TASK (1433, 426), (141, 50) */
TASK msg := msg // '!!'
/* CIF COMMENT (811, 286), (118, 50) */
/* CIF COMMENT (1595, 426), (118, 50) */
COMMENT 'Concatenate
strings';
/* CIF OUTPUT (645, 351), (150, 50) */
/* CIF OUTPUT (1429, 491), (150, 50) */
OUTPUT rezult(default_str)
/* CIF COMMENT (810, 349), (161, 53) */
/* CIF COMMENT (1594, 489), (161, 53) */
COMMENT 'Send a constant
defined in the ASN.1
model';
/* CIF NEXTSTATE (670, 416), (100, 50) */
/* CIF NEXTSTATE (1454, 556), (100, 50) */
NEXTSTATE Running
/* CIF COMMENT (790, 423), (96, 35) */
/* CIF COMMENT (1574, 563), (96, 35) */
COMMENT 'Néxtaytè';
/* CIF ANSWER (94, 236), (100, 35) */
/* CIF ANSWER (878, 376), (100, 35) */
('end'):
/* CIF OUTPUT (88, 286), (112, 50) */
/* CIF OUTPUT (872, 426), (112, 50) */
OUTPUT rezult
('Goodbye!');
/* CIF NEXTSTATE (94, 353), (100, 50) */
/* CIF NEXTSTATE (878, 493), (100, 50) */
NEXTSTATE Wait;
/* CIF ANSWER (258, 236), (100, 35) */
/* CIF ANSWER (1042, 376), (100, 35) */
ELSE:
/* CIF TASK (237, 286), (141, 50) */
/* CIF TASK (1021, 426), (141, 50) */
TASK msg := msg // '!'
/* CIF COMMENT (399, 286), (118, 50) */
/* CIF COMMENT (1183, 426), (118, 50) */
COMMENT 'Concatenate
strings';
/* CIF TASK (210, 351), (195, 50) */
/* CIF TASK (994, 491), (195, 50) */
TASK msg := msg(3,4) // msg(1,2)
/* CIF COMMENT (426, 351), (209, 53) */
/* CIF COMMENT (1210, 491), (209, 53) */
COMMENT 'Concatenate two substrings
(can be used to remove an
element from a list)';
/* CIF TASK (226, 416), (163, 50) */
/* CIF TASK (1010, 556), (163, 50) */
TASK msg := first_msg(1, 2)
/* CIF COMMENT (402, 413), (177, 53) */
/* CIF COMMENT (1186, 553), (177, 53) */
COMMENT 'Substring
TODO check range
against current Length';
/* CIF OUTPUT (254, 481), (108, 50) */
/* CIF OUTPUT (1038, 621), (108, 50) */
OUTPUT rezult(msg);
/* CIF NEXTSTATE (258, 546), (100, 50) */
/* CIF NEXTSTATE (1042, 686), (100, 50) */
NEXTSTATE Running;
ENDDECISION;
ENDSTATE;
/* CIF STATE (-252, 754), (100, 50) */
/* CIF STATE (427, 944), (100, 50) */
STATE Wait;
/* CIF INPUT (-252, 824), (100, 50) */
/* CIF INPUT (427, 1014), (100, 50) */
INPUT go(msg)
/* CIF COMMENT (-132, 831), (120, 35) */
/* CIF COMMENT (547, 1021), (120, 35) */
COMMENT 'Ïñpût unicode';
/* CIF DECISION (-259, 889), (114, 70) */
/* CIF DECISION (420, 1079), (114, 70) */
DECISION msg = 'hello'
/* CIF COMMENT (-125, 899), (128, 50) */
/* CIF COMMENT (554, 1089), (128, 50) */
COMMENT 'Boolean test
on string value';
/* CIF ANSWER (-41, 979), (100, 35) */
/* CIF ANSWER (638, 1169), (100, 35) */
(FALSE):
/* CIF OUTPUT (-60, 1029), (139, 50) */
/* CIF OUTPUT (618, 1219), (139, 50) */
OUTPUT rezult(first_msg)
/* CIF COMMENT (98, 1036), (85, 35) */
/* CIF COMMENT (777, 1226), (85, 35) */
COMMENT 'OûtpUT';
/* CIF NEXTSTATE (-41, 1094), (100, 50) */
/* CIF NEXTSTATE (638, 1284), (100, 50) */
NEXTSTATE Wait;
/* CIF ANSWER (-312, 979), (100, 35) */
/* CIF ANSWER (367, 1169), (100, 35) */
(TRUE):
/* CIF OUTPUT (-334, 1029), (145, 50) */
/* CIF OUTPUT (344, 1219), (145, 50) */
OUTPUT rezult('Welcome')
/* CIF COMMENT (-170, 1029), (95, 50) */
/* CIF COMMENT (509, 1219), (95, 50) */
COMMENT 'Send raw
string';
/* CIF DECISION (-311, 1094), (98, 50) */
/* CIF DECISION (368, 1284), (98, 50) */
DECISION 3 in {1,2,3};
/* CIF ANSWER (-351, 1164), (88, 23) */
/* CIF ANSWER (328, 1354), (88, 23) */
(1 in {1,2}):
/* CIF ANSWER (-261, 1164), (88, 23) */
/* CIF ANSWER (418, 1354), (88, 23) */
(0 in {1,2}):
ENDDECISION;
/* CIF DECISION (-311, 1222), (98, 50) */
/* CIF DECISION (368, 1417), (98, 50) */
DECISION 4 in {1,2,3};
/* CIF ANSWER (-342, 1292), (70, 23) */
/* CIF ANSWER (337, 1487), (70, 23) */
(true):
/* CIF ANSWER (-252, 1292), (70, 23) */
/* CIF ANSWER (427, 1487), (70, 23) */
(false):
ENDDECISION;
/* CIF NEXTSTATE (-312, 1345), (100, 50) */
/* CIF NEXTSTATE (367, 1525), (100, 50) */
NEXTSTATE Running;
ENDDECISION;
ENDSTATE;
......
[C Code] Running test
abc
0
-2 is FALSE
2 2 1
......
/* CIF PROCESS (148, 150), (150, 75) */
PROCESS myfunction;
/* CIF TEXT (0, 17), (296, 368) */
/* CIF TEXT (0, 17), (296, 383) */
-- Timers defined in the interface view
-- Use SET_TIMER (value, timer name)
-- and RESET_TIMER (timer name) in a
......@@ -23,6 +23,7 @@ dcl otherint T_uint8 := 1;
-- To test 'op_not'
dcl opnot T_boolean := not true;
dcl str MyOctStr := 'abc';
dcl bar SeqInt := { 1,1 };
/* CIF ENDTEXT */
......@@ -45,75 +46,77 @@ endfor;
ENDPROCEDURE;
/* CIF START (591, 0), (100, 50) */
START;
/* CIF PROCEDURECALL (552, 65), (177, 35) */
/* CIF PROCEDURECALL (586, 65), (110, 35) */
CALL writeln(str);
/* CIF PROCEDURECALL (552, 115), (177, 35) */
CALL writeln(1 + (-otherint));
/* CIF PROCEDURECALL (430, 115), (421, 35) */
/* CIF PROCEDURECALL (430, 165), (421, 35) */
CALL writeln(-someint, if someint>0 then ' is ' else 'Foo' fi, not true);
/* CIF PROCEDURECALL (514, 165), (254, 35) */
/* CIF PROCEDURECALL (514, 215), (254, 35) */
CALL write(if someint>0 then 2 else 1 fi);
/* CIF PROCEDURECALL (496, 215), (289, 35) */
/* CIF PROCEDURECALL (496, 265), (289, 35) */
CALL write(if someint>0 then someint else 1 fi);
/* CIF PROCEDURECALL (577, 265), (128, 35) */
/* CIF PROCEDURECALL (577, 315), (128, 35) */
CALL writeln(bar(1));
/* CIF PROCEDURECALL (532, 315), (217, 35) */
/* CIF PROCEDURECALL (532, 365), (217, 35) */
CALL writeln(opnot, ' ', not opnot);
/* CIF TASK (480, 365), (321, 35) */
/* CIF TASK (480, 415), (321, 35) */
TASK someInt := if someint = 0 then someint else 0 fi;
/* CIF DECISION (504, 415), (273, 87) */
/* CIF DECISION (504, 465), (273, 87) */
DECISION someint /=0 and then (10 / someInt > 0)
or else someint = 0
/* CIF COMMENT (793, 424), (179, 68) */
/* CIF COMMENT (793, 474), (179, 68) */
COMMENT 'Using "and else" is the
short-circuit form. The
second part should not
be evaluated.';
/* CIF ANSWER (561, 522), (70, 23) */
/* CIF ANSWER (561, 572), (70, 23) */
(true):
/* CIF TASK (541, 560), (110, 35) */
/* CIF TASK (541, 610), (110, 35) */
TASK someInt := 2;
/* CIF PROCEDURECALL (537, 610), (117, 38) */
/* CIF PROCEDURECALL (537, 660), (117, 38) */
CALL writeln('OK');
/* CIF ANSWER (664, 522), (70, 23) */
/* CIF ANSWER (664, 572), (70, 23) */
(false):
ENDDECISION;
/* CIF NEXTSTATE (608, 663), (65, 33) */
/* CIF NEXTSTATE (608, 713), (65, 33) */
NEXTSTATE Wait;
/* CIF STATE (608, 663), (65, 33) */
/* CIF STATE (608, 713), (65, 33) */
STATE Wait;
/* CIF INPUT (865, 716), (89, 33) */
/* CIF INPUT (865, 766), (89, 33) */
INPUT mytimer;
/* CIF PROCEDURECALL (818, 764), (182, 33) */
/* CIF PROCEDURECALL (818, 814), (182, 33) */
CALL writeln('timer expired');
/* CIF PROCEDURECALL (829, 812), (160, 33) */
/* CIF PROCEDURECALL (829, 862), (160, 33) */
CALL factorial(3, someint);
/* CIF NEXTSTATE (877, 860), (65, 33) */
/* CIF NEXTSTATE (877, 910), (65, 33) */
NEXTSTATE Wait;
/* CIF INPUT (421, 716), (181, 33) */
/* CIF INPUT (421, 766), (181, 33) */
INPUT start_something (toto);
/* CIF OUTPUT (376, 764), (270, 33) */
/* CIF OUTPUT (376, 814), (270, 33) */
OUTPUT result_data((toto+1) mod 2147483647);
/* CIF PROCEDURECALL (436, 812), (150, 48) */
/* CIF PROCEDURECALL (436, 862), (150, 48) */
CALL writeln
('Hello Toto', toto);
/* CIF PROCEDURECALL (413, 875), (196, 33) */
/* CIF PROCEDURECALL (413, 925), (196, 33) */
CALL set_timer(1000, myTimer);
/* CIF TASK (346, 923), (330, 35) */
/* CIF TASK (346, 973), (330, 35) */
TASK largeReal := power(someReal, 2);
/* CIF PROCEDURECALL (282, 973), (458, 35) */
/* CIF PROCEDURECALL (282, 1023), (458, 35) */
CALL writeln(someReal, ' ** 2' , ' == ', largeReal, ' (should be 2.25 )');
/* CIF TASK (411, 1023), (201, 35) */
/* CIF TASK (411, 1073), (201, 35) */
TASK someReal := float(someInt);
/* CIF TASK (391, 1073), (241, 35) */
/* CIF TASK (391, 1123), (241, 35) */
TASK someInt := fix(someReal) mod 255;
/* CIF TASK (435, 1123), (152, 35) */
/* CIF TASK (435, 1173), (152, 35) */
TASK opnot := not opnot;
/* CIF TASK (430, 1173), (163, 35) */
/* CIF TASK (430, 1223), (163, 35) */
TASK 'someint := -someint'
/* CIF COMMENT (613, 1173), (196, 35) */
/* CIF COMMENT (613, 1223), (196, 35) */
COMMENT 'XXX should raise an error!';
/* CIF TASK (429, 1223), (164, 35) */
/* CIF TASK (429, 1273), (164, 35) */
TASK someint := (-8) mod 5;
/* CIF NEXTSTATE (480, 1273), (63, 33) */
/* CIF NEXTSTATE (480, 1323), (63, 33) */
NEXTSTATE wait;
ENDSTATE;
ENDPROCESS myfunction;
\ 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