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

Resolve expression that are always true (or false)

parent 42c4baca
......@@ -1335,7 +1335,14 @@ def not_expression(root, context):
bty = find_basic_type(expr.expr.exprType)
if bty.kind in ('BooleanType', ):
expr.exprType = BOOLEAN
if expr.expr.is_raw:
expr.expr.value = ['true'] \
if expr.expr.value == ['false'] else ['false']
warnings.append(warning
(root, 'Expression is always '+ expr.expr.value[0]))
expr = expr.expr
else:
expr.exprType = BOOLEAN
elif bty.kind == 'BitStringType':
expr.exprType = expr.expr.exprType
elif bty.kind == 'SequenceOfType' and \
......
/* CIF PROCESS (200, 143), (150, 75) */
PROCESS myfunction;
/* CIF TEXT (0, 17), (296, 458) */
/* CIF TEXT (0, 17), (345, 648) */
-- Timers defined in the interface view
-- Use SET_TIMER (value, timer name)
-- and RESET_TIMER (timer name) in a
......@@ -31,166 +31,170 @@ dcl other String := 'World';
dcl bar SeqInt := { 1,1 };
dcl testenum MyEnum := world;
dcl VeryTrue t_boolean := not false;
/* CIF ENDTEXT */
/* CIF PROCEDURE (1172, 490), (91, 35) */
/* CIF PROCEDURE (1172, 490), (104, 35) */
PROCEDURE factorial;
/* CIF TEXT (29, 42), (215, 53) */
/* CIF TEXT (29, 42), (269, 53) */
fpar in N MyInteger,
in/out result MyInteger;
/* CIF ENDTEXT */
/* CIF START (298, 33), (70, 35) */
START;
/* CIF TASK (284, 83), (97, 35) */
/* CIF TASK (275, 83), (116, 35) */
TASK result := 1;
/* CIF TASK (223, 133), (220, 53) */
/* CIF TASK (194, 133), (278, 68) */
TASK for x in range(1, n+1):
result := (result * x) mod 255
endfor;
/* CIF RETURN (315, 201), (35, 35) */
/* CIF RETURN (315, 216), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF START (603, 0), (76, 39) */
START;
/* CIF DECISION (587, 54), (107, 50) */
/* CIF TASK (541, 54), (200, 35) */
TASK verytrue := not false;
/* CIF DECISION (576, 104), (129, 50) */
DECISION someint + 1
/* CIF COMMENT (714, 61), (146, 35) */
/* CIF COMMENT (714, 111), (176, 35) */
COMMENT 'Test closed range';
/* CIF ANSWER (546, 124), (99, 33) */
/* CIF ANSWER (546, 174), (99, 33) */
(0:998):
/* CIF ANSWER (707, 124), (99, 23) */
/* CIF ANSWER (707, 174), (116, 28) */
(2:otherint):
ENDDECISION;
/* CIF TASK (562, 192), (157, 98) */
/* CIF TASK (542, 242), (198, 128) */
TASK for x in range(4):
call writeln(x);
endfor,
for x in range(0,4,1):
call writeln(x);
endfor
/* CIF COMMENT (739, 223), (208, 35) */
/* CIF COMMENT (872, 280), (256, 35) */
COMMENT 'Check consistent behaviour';
/* CIF PROCEDURECALL (553, 305), (175, 35) */
/* CIF PROCEDURECALL (532, 385), (217, 35) */
CALL writeln(-(someint + 1))
/* CIF COMMENT (748, 305), (226, 38) */
/* CIF COMMENT (850, 334), (283, 48) */
COMMENT 'Test unary on expression result
should display -3';
/* CIF PROCEDURECALL (542, 355), (197, 35) */
/* CIF PROCEDURECALL (519, 435), (244, 35) */
CALL writeln(not(true or false))
/* CIF COMMENT (759, 355), (187, 38) */
/* CIF COMMENT (759, 405), (232, 48) */
COMMENT 'test unary on expression
should display FALSE';
/* CIF PROCEDURECALL (586, 405), (110, 35) */
/* CIF PROCEDURECALL (576, 485), (130, 35) */
CALL writeln(str)
/* CIF COMMENT (716, 405), (231, 35) */
/* CIF COMMENT (716, 455), (285, 35) */
COMMENT 'Test writeln with an octet string';
/* CIF PROCEDURECALL (586, 455), (110, 35) */
/* CIF PROCEDURECALL (576, 535), (130, 35) */
CALL writeln(str)
/* CIF COMMENT (716, 455), (254, 35) */
/* CIF COMMENT (716, 505), (310, 35) */
COMMENT 'Write again to check local variables';
/* CIF PROCEDURECALL (558, 505), (165, 35) */
/* CIF PROCEDURECALL (541, 585), (199, 35) */
CALL writeln(variable_str)
/* CIF COMMENT (743, 505), (275, 35) */
/* CIF COMMENT (743, 555), (346, 35) */
COMMENT 'Write a non-fixed length OCTET STRING';
/* CIF PROCEDURECALL (541, 555), (199, 38) */
/* CIF PROCEDURECALL (519, 635), (244, 38) */
CALL writeln(variable_str // '!!!')
/* CIF COMMENT (760, 556), (117, 35) */
/* CIF COMMENT (760, 606), (140, 35) */
COMMENT 'with APPEND';
/* CIF PROCEDURECALL (465, 608), (352, 35) */
/* CIF PROCEDURECALL (421, 688), (440, 35) */
CALL writeln(if someint>0 then variable_str else other fi)
/* CIF COMMENT (837, 608), (275, 35) */
/* CIF COMMENT (837, 658), (346, 35) */
COMMENT 'Write a non-fixed lenght OCTET STRING';
/* CIF PROCEDURECALL (552, 658), (177, 35) */
/* CIF PROCEDURECALL (532, 738), (218, 35) */
CALL writeln(1 + (-otherint))
/* CIF COMMENT (749, 658), (266, 35) */
/* CIF COMMENT (749, 708), (333, 35) */
COMMENT 'Test the op_minus in a sub-expression';
/* CIF PROCEDURECALL (430, 708), (421, 35) */
/* CIF PROCEDURECALL (382, 788), (518, 35) */
CALL writeln(-someint, if someint>0 then ' is ' else 'Foo' fi, not true)
/* CIF COMMENT (871, 708), (291, 35) */
/* CIF COMMENT (871, 758), (364, 35) */
COMMENT 'Various tests with strings, ternary, op_not';
/* CIF PROCEDURECALL (514, 758), (254, 35) */
/* CIF PROCEDURECALL (486, 838), (310, 35) */
CALL write(if someint>0 then 2 else 1 fi)
/* CIF COMMENT (788, 758), (220, 35) */
/* CIF COMMENT (894, 830), (277, 35) */
COMMENT 'test ternary with raw numbers';
/* CIF PROCEDURECALL (496, 808), (289, 35) */
/* CIF PROCEDURECALL (459, 888), (363, 35) */
CALL write(if someint>0 then someint else 1 fi)
/* CIF COMMENT (805, 808), (308, 35) */
/* CIF COMMENT (863, 891), (388, 35) */
COMMENT 'test ternary with mixed variable/raw number';
/* CIF PROCEDURECALL (577, 858), (128, 35) */
/* CIF PROCEDURECALL (563, 938), (156, 35) */
CALL writeln(bar(1))
/* CIF COMMENT (725, 858), (100, 35) */
/* CIF COMMENT (744, 936), (116, 35) */
COMMENT 'test index';
/* CIF PROCEDURECALL (532, 908), (217, 35) */
/* CIF PROCEDURECALL (510, 988), (261, 35) */
CALL writeln(opnot, ' ', not opnot)
/* CIF COMMENT (769, 908), (191, 35) */
/* CIF COMMENT (814, 994), (231, 35) */
COMMENT 'test op_not with variable';
/* CIF TASK (480, 958), (321, 35) */
/* CIF TASK (437, 1038), (408, 35) */
TASK someInt := if someint = 0 then someint else 0 fi;
/* CIF TASK (542, 1008), (197, 35) */
/* CIF TASK (517, 1088), (248, 35) */
TASK otherint := num(testenum);
/* CIF PROCEDURECALL (513, 1058), (256, 35) */
/* CIF PROCEDURECALL (479, 1138), (324, 35) */
CALL writeln(otherint, num(testenum)+1)
/* CIF COMMENT (789, 1028), (401, 98) */
/* CIF COMMENT (919, 1088), (506, 128) */
COMMENT 'Will display 1 2 with the Ada generator
* even if the ASN.1 model specifies explicit values *
because Ada has no operator to get the explicit value,
even if it is set as representation clause. Enumerated values
are logical states, not integers in Ada - as in ASN.1
';
/* CIF DECISION (504, 1134), (273, 87) */
/* CIF DECISION (465, 1202), (352, 87) */
DECISION someint /=0 and then (10 / someInt > 0)
or else someint = 0
/* CIF COMMENT (793, 1143), (179, 68) */
/* CIF COMMENT (889, 1239), (219, 88) */
COMMENT 'Using "and else" is the
short-circuit form. The
second part should not
be evaluated.';
/* CIF ANSWER (561, 1241), (70, 23) */
/* CIF ANSWER (561, 1309), (73, 28) */
(true):
/* CIF TASK (541, 1279), (110, 35) */
/* CIF TASK (530, 1352), (135, 35) */
TASK someInt := 2;
/* CIF PROCEDURECALL (537, 1329), (117, 38) */
/* CIF PROCEDURECALL (527, 1402), (140, 38) */
CALL writeln('OK');
/* CIF ANSWER (664, 1241), (70, 23) */
/* CIF ANSWER (664, 1309), (78, 28) */
(false):
ENDDECISION;
/* CIF NEXTSTATE (608, 1382), (65, 33) */
/* CIF NEXTSTATE (605, 1455), (72, 33) */
NEXTSTATE Wait;
/* CIF STATE (608, 1382), (65, 33) */
/* CIF STATE (605, 1455), (72, 33) */
STATE Wait;
/* CIF INPUT (865, 1435), (89, 33) */
/* CIF INPUT (865, 1508), (104, 33) */
INPUT mytimer;
/* CIF PROCEDURECALL (818, 1483), (182, 33) */
/* CIF PROCEDURECALL (806, 1556), (221, 33) */
CALL writeln('timer expired');
/* CIF PROCEDURECALL (829, 1531), (160, 33) */
/* CIF PROCEDURECALL (819, 1604), (196, 33) */
CALL factorial(3, someint);
/* CIF NEXTSTATE (877, 1579), (65, 33) */
/* CIF NEXTSTATE (881, 1652), (72, 33) */
NEXTSTATE Wait;
/* CIF INPUT (421, 1435), (181, 33) */
/* CIF INPUT (421, 1508), (217, 33) */
INPUT start_something (toto);
/* CIF OUTPUT (376, 1483), (270, 33) */
/* CIF OUTPUT (355, 1556), (348, 33) */
OUTPUT result_data((toto+1) mod 2147483647);
/* CIF PROCEDURECALL (436, 1531), (150, 48) */
/* CIF PROCEDURECALL (440, 1604), (178, 48) */
CALL writeln
('Hello Toto', toto);
/* CIF PROCEDURECALL (413, 1594), (196, 33) */
/* CIF PROCEDURECALL (406, 1667), (246, 33) */
CALL set_timer(1000, myTimer);
/* CIF TASK (346, 1642), (330, 35) */
/* CIF TASK (364, 1715), (330, 35) */
TASK largeReal := power(someReal, 2);
/* CIF PROCEDURECALL (282, 1692), (458, 35) */
/* CIF PROCEDURECALL (272, 1765), (515, 35) */
CALL writeln(someReal, ' ** 2' , ' == ', largeReal, ' (should be 2.25 )');
/* CIF TASK (411, 1742), (201, 35) */
/* CIF TASK (403, 1815), (252, 35) */
TASK someReal := float(someInt);
/* CIF TASK (391, 1792), (241, 35) */
/* CIF TASK (376, 1865), (307, 35) */
TASK someInt := fix(someReal) mod 255;
/* CIF TASK (435, 1842), (152, 35) */
/* CIF TASK (437, 1915), (185, 35) */
TASK opnot := not opnot;
/* CIF TASK (430, 1892), (163, 35) */
/* CIF TASK (429, 1965), (200, 35) */
TASK 'someint := -someint'
/* CIF COMMENT (613, 1892), (196, 35) */
/* CIF COMMENT (613, 1951), (243, 35) */
COMMENT 'XXX should raise an error!';
/* CIF TASK (429, 1942), (164, 35) */
/* CIF TASK (427, 2015), (204, 35) */
TASK someint := (-8) mod 5;
/* CIF NEXTSTATE (480, 1992), (63, 33) */
/* CIF NEXTSTATE (494, 2065), (70, 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