Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
bc59f08a
Commit
bc59f08a
authored
Jul 21, 2014
by
Maxime Perrotin
Browse files
Added support for closed ranges in decision answers
parent
50e6c9c5
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
AdaGenerator.py
View file @
bc59f08a
...
...
@@ -1374,9 +1374,22 @@ def _decision(dec):
code
.
extend
(
stmt
)
local_decl
.
extend
(
tr_decl
)
sep
=
'elsif '
elif
a
.
kind
==
'close_range'
:
elif
a
.
kind
==
'closed_range'
:
cl0_stmts
,
cl0_str
,
cl0_decl
=
expression
(
a
.
closedRange
[
0
])
cl1_stmts
,
cl1_str
,
cl1_decl
=
expression
(
a
.
closedRange
[
1
])
code
.
extend
(
cl0_stmts
)
local_decl
.
extend
(
cl0_decl
)
code
.
extend
(
cl1_stmts
)
local_decl
.
extend
(
cl1_decl
)
code
.
append
(
'{sep} {dec} >= {cl0} and {dec} <= {cl1} then'
.
format
(
sep
=
sep
,
dec
=
q_str
,
cl0
=
cl0_str
,
cl1
=
cl1_str
))
if
a
.
transition
:
stmt
,
tr_decl
=
generate
(
a
.
transition
)
else
:
stmt
,
tr_decl
=
[
'null;'
],
[]
code
.
extend
(
stmt
)
local_decl
.
extend
(
tr_decl
)
sep
=
'elsif '
# TODO support close_range
elif
a
.
kind
==
'informal_text'
:
continue
elif
a
.
kind
==
'else'
:
...
...
ogParser.py
View file @
bc59f08a
...
...
@@ -2794,8 +2794,13 @@ def alternative_part(root, parent, context):
coord
=
True
elif
child
.
type
==
lexer
.
CLOSED_RANGE
:
ans
.
kind
=
'closed_range'
ans
.
closedRange
=
[
float
(
child
.
getChild
(
0
).
toString
()),
float
(
child
.
getChild
(
1
).
toString
())]
cl0
,
err0
,
warn0
=
expression
(
child
.
getChild
(
0
),
context
)
cl1
,
err1
,
warn1
=
expression
(
child
.
getChild
(
1
),
context
)
errors
.
extend
(
err0
)
errors
.
extend
(
err1
)
warnings
.
extend
(
warn0
)
warnings
.
extend
(
warn1
)
ans
.
closedRange
=
[
cl0
,
cl1
]
elif
child
.
type
==
lexer
.
CONSTANT
:
ans
.
kind
=
'constant'
ans
.
constant
,
err
,
warn
=
expression
(
...
...
@@ -2896,23 +2901,43 @@ def decision(root, parent, context):
else
:
warnings
.
append
([
'Unsupported DECISION child type: '
+
str
(
child
.
type
),
[
dec
.
pos_x
,
dec
.
pos_y
]])
# Make type checks to be sure that question and answers are compatible
for
ans
in
dec
.
answers
:
if
ans
.
kind
in
(
'constant'
,
'open_range'
):
expr
=
ans
.
openRangeOp
()
# Make type checks to be sure that question and answers are compatible
for
ans
in
dec
.
answers
:
if
ans
.
kind
in
(
'constant'
,
'open_range'
):
expr
=
ans
.
openRangeOp
()
expr
.
left
=
dec
.
question
expr
.
right
=
ans
.
constant
try
:
fix_expression_types
(
expr
,
context
)
if
dec
.
question
.
exprType
==
UNKNOWN_TYPE
:
dec
.
question
=
expr
.
left
ans
.
constant
=
expr
.
right
except
(
AttributeError
,
TypeError
)
as
err
:
errors
.
append
(
'Types are incompatible in DECISION: '
'question ('
+
expr
.
left
.
inputString
+
', type= '
+
type_name
(
expr
.
left
.
exprType
)
+
'), answer ('
+
expr
.
right
.
inputString
+
', type= '
+
type_name
(
expr
.
right
.
exprType
)
+
') '
+
str
(
err
))
elif
ans
.
kind
==
'closed_range'
:
if
not
is_numeric
(
dec
.
question
.
exprType
):
errors
.
append
(
'Closed range are only for numerical types'
)
continue
for
ast_type
,
idx
in
zip
((
ogAST
.
ExprGe
,
ogAST
.
ExprLe
),
(
0
,
1
)):
expr
=
ast_type
()
expr
.
left
=
dec
.
question
expr
.
right
=
ans
.
c
onstant
expr
.
right
=
ans
.
c
losedRange
[
idx
]
try
:
fix_expression_types
(
expr
,
context
)
if
dec
.
question
.
exprType
==
UNKNOWN_TYPE
:
dec
.
question
=
expr
.
left
ans
.
c
onstant
=
expr
.
right
ans
.
c
losedRange
[
idx
]
=
expr
.
right
except
(
AttributeError
,
TypeError
)
as
err
:
errors
.
append
(
'Types are incompatible in DECISION: '
'question ('
+
expr
.
left
.
inputString
+
', type= '
+
type_name
(
expr
.
left
.
exprType
)
+
'), answer ('
+
expr
.
right
.
inputString
+
', type= '
+
type_name
(
expr
.
right
.
exprType
)
+
') '
+
str
(
err
))
return
dec
,
errors
,
warnings
...
...
sdl92.g
View file @
bc59f08a
...
...
@@ -670,7 +670,7 @@ range_condition
closed_range
: a=
INT ':' b=INT
: a=
expression ':' b=expression
-> ^(CLOSED_RANGE $a $b);
...
...
sdl92Lexer.py
View file @
bc59f08a
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-07-
17 20:45:59
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-07-
21 13:25:47
import
sys
from
antlr3
import
*
...
...
sdl92Parser.py
View file @
bc59f08a
This diff is collapsed.
Click to expand it.
tests/regression/test6/myfunction.pr
View file @
bc59f08a
...
...
@@ -51,137 +51,146 @@ endfor;
ENDPROCEDURE;
/* CIF START (603, 0), (76, 39) */
START;
/* CIF TASK (562, 54), (157, 98) */
/* CIF DECISION (587, 54), (107, 50) */
DECISION someint + 1
/* CIF COMMENT (714, 61), (146, 35) */
COMMENT 'Test closed range';
/* CIF ANSWER (546, 124), (99, 33) */
(0:998):
/* CIF ANSWER (707, 124), (99, 23) */
(2:otherint):
ENDDECISION;
/* CIF TASK (562, 192), (157, 98) */
TASK for x in range(4):
call writeln(x);
endfor,
for x in range(0,4,1):
call writeln(x);
endfor
/* CIF COMMENT (739,
85
), (208, 35) */
/* CIF COMMENT (739,
223
), (208, 35) */
COMMENT 'Check consistent behaviour';
/* CIF PROCEDURECALL (553,
167
), (175, 35) */
/* CIF PROCEDURECALL (553,
305
), (175, 35) */
CALL writeln(-(someint + 1))
/* CIF COMMENT (748,
167
), (226, 38) */
/* CIF COMMENT (748,
305
), (226, 38) */
COMMENT 'Test unary on expression result
should display -3';
/* CIF PROCEDURECALL (542,
217
), (197, 35) */
/* CIF PROCEDURECALL (542,
355
), (197, 35) */
CALL writeln(not(true or false))
/* CIF COMMENT (759,
217
), (187, 38) */
/* CIF COMMENT (759,
355
), (187, 38) */
COMMENT 'test unary on expression
should display FALSE';
/* CIF PROCEDURECALL (586,
267
), (110, 35) */
/* CIF PROCEDURECALL (586,
405
), (110, 35) */
CALL writeln(str)
/* CIF COMMENT (716,
267
), (231, 35) */
/* CIF COMMENT (716,
405
), (231, 35) */
COMMENT 'Test writeln with an octet string';
/* CIF PROCEDURECALL (586,
317
), (110, 35) */
/* CIF PROCEDURECALL (586,
455
), (110, 35) */
CALL writeln(str)
/* CIF COMMENT (716,
317
), (254, 35) */
/* CIF COMMENT (716,
455
), (254, 35) */
COMMENT 'Write again to check local variables';
/* CIF PROCEDURECALL (558,
367
), (165, 35) */
/* CIF PROCEDURECALL (558,
505
), (165, 35) */
CALL writeln(variable_str)
/* CIF COMMENT (743,
367
), (275, 35) */
/* CIF COMMENT (743,
505
), (275, 35) */
COMMENT 'Write a non-fixed length OCTET STRING';
/* CIF PROCEDURECALL (541,
417
), (199, 38) */
/* CIF PROCEDURECALL (541,
555
), (199, 38) */
CALL writeln(variable_str // '!!!')
/* CIF COMMENT (760,
418
), (117, 35) */
/* CIF COMMENT (760,
556
), (117, 35) */
COMMENT 'with APPEND';
/* CIF PROCEDURECALL (465,
470
), (352, 35) */
/* CIF PROCEDURECALL (465,
608
), (352, 35) */
CALL writeln(if someint>0 then variable_str else other fi)
/* CIF COMMENT (837,
470
), (275, 35) */
/* CIF COMMENT (837,
608
), (275, 35) */
COMMENT 'Write a non-fixed lenght OCTET STRING';
/* CIF PROCEDURECALL (552,
520
), (177, 35) */
/* CIF PROCEDURECALL (552,
658
), (177, 35) */
CALL writeln(1 + (-otherint))
/* CIF COMMENT (749,
520
), (266, 35) */
/* CIF COMMENT (749,
658
), (266, 35) */
COMMENT 'Test the op_minus in a sub-expression';
/* CIF PROCEDURECALL (430,
5
70), (421, 35) */
/* CIF PROCEDURECALL (430, 70
8
), (421, 35) */
CALL writeln(-someint, if someint>0 then ' is ' else 'Foo' fi, not true)
/* CIF COMMENT (871,
5
70), (291, 35) */
/* CIF COMMENT (871, 70
8
), (291, 35) */
COMMENT 'Various tests with strings, ternary, op_not';
/* CIF PROCEDURECALL (514,
620
), (254, 35) */
/* CIF PROCEDURECALL (514,
758
), (254, 35) */
CALL write(if someint>0 then 2 else 1 fi)
/* CIF COMMENT (788,
620
), (220, 35) */
/* CIF COMMENT (788,
758
), (220, 35) */
COMMENT 'test ternary with raw numbers';
/* CIF PROCEDURECALL (496,
670
), (289, 35) */
/* CIF PROCEDURECALL (496,
808
), (289, 35) */
CALL write(if someint>0 then someint else 1 fi)
/* CIF COMMENT (805,
670
), (308, 35) */
/* CIF COMMENT (805,
808
), (308, 35) */
COMMENT 'test ternary with mixed variable/raw number';
/* CIF PROCEDURECALL (577,
720
), (128, 35) */
/* CIF PROCEDURECALL (577,
858
), (128, 35) */
CALL writeln(bar(1))
/* CIF COMMENT (725,
720
), (100, 35) */
/* CIF COMMENT (725,
858
), (100, 35) */
COMMENT 'test index';
/* CIF PROCEDURECALL (532,
770
), (217, 35) */
/* CIF PROCEDURECALL (532,
908
), (217, 35) */
CALL writeln(opnot, ' ', not opnot)
/* CIF COMMENT (769,
770
), (191, 35) */
/* CIF COMMENT (769,
908
), (191, 35) */
COMMENT 'test op_not with variable';
/* CIF TASK (480,
820
), (321, 35) */
/* CIF TASK (480,
958
), (321, 35) */
TASK someInt := if someint = 0 then someint else 0 fi;
/* CIF TASK (542,
870
), (197, 35) */
/* CIF TASK (542,
1008
), (197, 35) */
TASK otherint := num(testenum);
/* CIF PROCEDURECALL (513,
920
), (256, 35) */
/* CIF PROCEDURECALL (513,
1058
), (256, 35) */
CALL writeln(otherint, num(testenum)+1)
/* CIF COMMENT (789,
890
), (401, 98) */
/* CIF COMMENT (789,
1028
), (401, 98) */
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,
996
), (273, 87) */
/* CIF DECISION (504,
1134
), (273, 87) */
DECISION someint /=0 and then (10 / someInt > 0)
or else someint = 0
/* CIF COMMENT (793, 1
005
), (179, 68) */
/* CIF COMMENT (793, 1
143
), (179, 68) */
COMMENT 'Using "and else" is the
short-circuit form. The
second part should not
be evaluated.';
/* CIF ANSWER (561, 1
103
), (70, 23) */
/* CIF ANSWER (561, 1
241
), (70, 23) */
(true):
/* CIF TASK (541, 1
141
), (110, 35) */
/* CIF TASK (541, 1
279
), (110, 35) */
TASK someInt := 2;
/* CIF PROCEDURECALL (537, 1
191
), (117, 38) */
/* CIF PROCEDURECALL (537, 1
329
), (117, 38) */
CALL writeln('OK');
/* CIF ANSWER (664, 1
103
), (70, 23) */
/* CIF ANSWER (664, 1
241
), (70, 23) */
(false):
ENDDECISION;
/* CIF NEXTSTATE (608, 1
244
), (65, 33) */
/* CIF NEXTSTATE (608, 1
382
), (65, 33) */
NEXTSTATE Wait;
/* CIF STATE (608, 1
244
), (65, 33) */
/* CIF STATE (608, 1
382
), (65, 33) */
STATE Wait;
/* CIF INPUT (865, 1
297
), (89, 33) */
/* CIF INPUT (865, 1
435
), (89, 33) */
INPUT mytimer;
/* CIF PROCEDURECALL (818, 1
345
), (182, 33) */
/* CIF PROCEDURECALL (818, 1
483
), (182, 33) */
CALL writeln('timer expired');
/* CIF PROCEDURECALL (829, 1
393
), (160, 33) */
/* CIF PROCEDURECALL (829, 1
531
), (160, 33) */
CALL factorial(3, someint);
/* CIF NEXTSTATE (877, 1
441
), (65, 33) */
/* CIF NEXTSTATE (877, 1
579
), (65, 33) */
NEXTSTATE Wait;
/* CIF INPUT (421, 1
297
), (181, 33) */
/* CIF INPUT (421, 1
435
), (181, 33) */
INPUT start_something (toto);
/* CIF OUTPUT (376, 1
345
), (270, 33) */
/* CIF OUTPUT (376, 1
483
), (270, 33) */
OUTPUT result_data((toto+1) mod 2147483647);
/* CIF PROCEDURECALL (436, 1
393
), (150, 48) */
/* CIF PROCEDURECALL (436, 1
531
), (150, 48) */
CALL writeln
('Hello Toto', toto);
/* CIF PROCEDURECALL (413, 1
456
), (196, 33) */
/* CIF PROCEDURECALL (413, 1
594
), (196, 33) */
CALL set_timer(1000, myTimer);
/* CIF TASK (346, 1
504
), (330, 35) */
/* CIF TASK (346, 1
642
), (330, 35) */
TASK largeReal := power(someReal, 2);
/* CIF PROCEDURECALL (282, 1
554
), (458, 35) */
/* CIF PROCEDURECALL (282, 1
692
), (458, 35) */
CALL writeln(someReal, ' ** 2' , ' == ', largeReal, ' (should be 2.25 )');
/* CIF TASK (411, 1
604
), (201, 35) */
/* CIF TASK (411, 1
742
), (201, 35) */
TASK someReal := float(someInt);
/* CIF TASK (391, 1
654
), (241, 35) */
/* CIF TASK (391, 1
792
), (241, 35) */
TASK someInt := fix(someReal) mod 255;
/* CIF TASK (435, 1
704
), (152, 35) */
/* CIF TASK (435, 1
842
), (152, 35) */
TASK opnot := not opnot;
/* CIF TASK (430, 1
754
), (163, 35) */
/* CIF TASK (430, 1
892
), (163, 35) */
TASK 'someint := -someint'
/* CIF COMMENT (613, 1
754
), (196, 35) */
/* CIF COMMENT (613, 1
892
), (196, 35) */
COMMENT 'XXX should raise an error!';
/* CIF TASK (429, 1
804
), (164, 35) */
/* CIF TASK (429, 1
942
), (164, 35) */
TASK someint := (-8) mod 5;
/* CIF NEXTSTATE (480, 1
854
), (63, 33) */
/* CIF NEXTSTATE (480, 1
992
), (63, 33) */
NEXTSTATE wait;
ENDSTATE;
ENDPROCESS myfunction;
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment