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
6aac21a9
Commit
6aac21a9
authored
Apr 11, 2019
by
Maxime Perrotin
Browse files
Support "x in {enum1Value1, enumValue2}" decisions
parent
a5f381d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
opengeode/ogAST.py
View file @
6aac21a9
...
...
@@ -174,14 +174,16 @@ class Primary(Expression):
is_raw
=
True
def
__init__
(
self
,
inputString
=
''
,
line
=-
1
,
charPositionInLine
=-
1
,
primary
=
None
):
primary
=
None
,
debugLine
=-
1
):
''' Initialize common primary attributes '''
self
.
debugLine
=
debugLine
if
primary
:
self
.
inputString
=
primary
.
inputString
self
.
line
=
primary
.
line
self
.
charPositionInLine
=
primary
.
charPositionInLine
self
.
value
=
primary
.
value
self
.
exprType
=
primary
.
exprType
self
.
debugLine
=
primary
.
debugLine
else
:
self
.
inputString
=
inputString
self
.
line
=
line
...
...
opengeode/ogParser.py
View file @
6aac21a9
...
...
@@ -31,6 +31,7 @@ import math
import
operator
import
logging
import
traceback
from
inspect
import
currentframe
,
getframeinfo
import
binascii
from
textwrap
import
dedent
from
itertools
import
chain
,
permutations
,
combinations
...
...
@@ -168,6 +169,9 @@ new_ref_type = lambda refname: \
type_name
=
lambda
t
:
\
t
.
kind
if
t
.
kind
!=
'ReferenceType'
else
t
.
ReferencedTypeName
# return the line number of this python module, useful for debugging
lineno
=
lambda
:
currentframe
().
f_back
.
f_lineno
# user may create SDL (non-asn1) types with the newtype keyword
# they are stored in a dedicated dictionary with the same structure
# as the ASN1SCC generated python AST
...
...
@@ -686,7 +690,7 @@ def check_call(name, params, context):
for
idx
,
param
in
enumerate
(
params
):
warnings
=
[]
expr
=
ogAST
.
ExprAssign
()
expr
.
left
=
ogAST
.
PrimVariable
()
expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
()
)
expr
.
left
.
exprType
=
sign
[
idx
][
'type'
]
expr
.
right
=
param
...
...
@@ -1220,9 +1224,8 @@ def fix_enumerated_and_choice(expr_enum, context):
warnings
=
[]
kind
=
find_basic_type
(
expr_enum
.
left
.
exprType
).
kind
if
kind
in
(
'EnumeratedType'
,
'StateEnumeratedType'
):
prim
=
ogAST
.
PrimEnumeratedValue
(
primary
=
expr_enum
.
right
)
elif
kind
==
'ChoiceEnumeratedType'
:
# does not exist anymore, REMOVE
prim
=
ogAST
.
PrimChoiceDeterminant
(
primary
=
expr_enum
.
right
)
prim
=
ogAST
.
PrimEnumeratedValue
(
primary
=
expr_enum
.
right
,
debugLine
=
lineno
())
try
:
warnings
.
extend
(
check_type_compatibility
(
prim
,
expr_enum
.
left
.
exprType
,
...
...
@@ -1262,7 +1265,7 @@ def fix_expression_types(expr, context): # type: -> [warnings]
asn_type
=
asn_type
.
type
for
idx
,
elem
in
enumerate
(
value
.
value
):
check_expr
=
ogAST
.
ExprAssign
()
check_expr
.
left
=
ogAST
.
PrimVariable
()
check_expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
()
)
check_expr
.
left
.
exprType
=
asn_type
check_expr
.
right
=
elem
warnings
.
extend
(
fix_expression_types
(
check_expr
,
context
))
...
...
@@ -1299,7 +1302,7 @@ def fix_expression_types(expr, context): # type: -> [warnings]
except
AttributeError
:
raise
TypeError
(
'Field not found: '
+
field
)
check_expr
=
ogAST
.
ExprAssign
()
check_expr
.
left
=
ogAST
.
PrimVariable
()
check_expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
()
)
check_expr
.
left
.
exprType
=
expected_type
check_expr
.
right
=
fd_expr
warnings
.
extend
(
fix_expression_types
(
check_expr
,
context
))
...
...
@@ -1320,7 +1323,7 @@ def fix_expression_types(expr, context): # type: -> [warnings]
except
AttributeError
:
raise
TypeError
(
'Field not found in CHOICE: '
+
field
)
check_expr
=
ogAST
.
ExprAssign
()
check_expr
.
left
=
ogAST
.
PrimVariable
()
check_expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
()
)
check_expr
.
left
.
exprType
=
expected_type
check_expr
.
right
=
expr
.
right
.
value
[
'value'
]
warnings
.
extend
(
fix_expression_types
(
check_expr
,
context
))
...
...
@@ -1333,7 +1336,8 @@ def fix_expression_types(expr, context): # type: -> [warnings]
for
det
in
(
'then'
,
'else'
):
# Recursively fix possibly missing types in the expression
check_expr
=
ogAST
.
ExprAssign
()
check_expr
.
left
=
ogAST
.
PrimVariable
()
check_expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
())
check_expr
.
left
.
inputString
=
expr
.
left
.
inputString
# for debug
check_expr
.
left
.
exprType
=
expr
.
left
.
exprType
check_expr
.
right
=
expr
.
right
.
value
[
det
]
warnings
.
extend
(
fix_expression_types
(
check_expr
,
context
))
...
...
@@ -1407,7 +1411,9 @@ def primary_variable(root, context):
elif
is_fpar
(
name
,
context
):
prim
=
ogAST
.
PrimFPAR
()
else
:
prim
=
ogAST
.
PrimVariable
()
# We create a variable reference , but it may be a enumerated value,
# it will be replaced later during type resolution
prim
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
())
prim
.
value
=
[
name
]
prim
.
exprType
=
UNKNOWN_TYPE
...
...
@@ -1793,7 +1799,7 @@ def relational_expression(root, context):
def
in_expression
(
root
,
context
):
''' In expression analysis '''
# Left and right are reversed for IN operator
#
WARNING:
Left and right are reversed for IN operator
root
.
children
[
0
],
root
.
children
[
1
]
=
root
.
children
[
1
],
root
.
children
[
0
]
expr
,
errors
,
warnings
=
binary_expression
(
root
,
context
)
...
...
@@ -1810,6 +1816,7 @@ def in_expression(root, context):
msg
=
'IN expression: right part must be a list'
errors
.
append
(
error
(
root
,
msg
))
return
expr
,
errors
,
warnings
expr
.
left
.
exprType
=
ref_type
if
find_basic_type
(
ref_type
).
kind
==
'EnumeratedType'
:
...
...
@@ -1817,6 +1824,24 @@ def in_expression(root, context):
expr
.
left
.
exprType
=
left_type
# if left is raw we must check each element with the type on the right
# in "foo in {enum1, enum2}" we must check that enum1 and enum2 are both
# of the same type as foo
if
expr
.
left
.
is_raw
and
not
expr
.
right
.
is_raw
:
# we must check that all entries are compatible with ref_type
# and if they were variables, but are in fact raw enumerants, they
# must be changed from ogAST.PrimVariable to ogAST.PrimEnumeratedValue
for
idx
,
value
in
enumerate
(
expr
.
left
.
value
):
check_expr
=
ogAST
.
ExprAssign
()
check_expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
())
check_expr
.
left
.
exprType
=
ref_type
check_expr
.
right
=
value
try
:
warnings
.
extend
(
fix_expression_types
(
check_expr
,
context
))
except
TypeError
as
err
:
errors
.
append
(
error
(
root
,
str
(
err
)))
expr
.
left
.
value
[
idx
]
=
check_expr
.
right
try
:
warnings
.
extend
(
compare_types
(
expr
.
right
.
exprType
,
ref_type
))
except
TypeError
as
err
:
...
...
@@ -2394,7 +2419,7 @@ def variables(root, ta_ast, context):
errors
.
extend
(
err
)
warnings
.
extend
(
warn
)
expr
=
ogAST
.
ExprAssign
()
expr
.
left
=
ogAST
.
PrimVariable
()
expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
()
)
expr
.
left
.
inputString
=
var
[
-
1
]
expr
.
left
.
exprType
=
asn1_sort
expr
.
right
=
def_value
...
...
@@ -2778,7 +2803,7 @@ def procedure_post(proc, content, parent=None, context=None):
[
0
,
0
],
[]])
elif
proc
.
return_type
and
each
.
return_expr
:
check_expr
=
ogAST
.
ExprAssign
()
check_expr
.
left
=
ogAST
.
PrimVariable
()
check_expr
.
left
=
ogAST
.
PrimVariable
(
debugLine
=
lineno
()
)
check_expr
.
left
.
exprType
=
proc
.
return_type
check_expr
.
right
=
each
.
return_expr
try
:
...
...
tests/regression/test-in-expression/dataview-uniq.asn
View file @
6aac21a9
...
...
@@ -30,6 +30,8 @@ Toto ::= SEQUENCE { elem-1 Type1, elem-2 Type2 }
SeqBool ::= SEQUENCE(SIZE(1..5)) OF BOOLEAN
Enum-T ::= ENUMERATED {enum1, enum2, enum3}
ForTheSakeOfIt ::= SEQUENCE (SIZE (2)) OF Enum-T
default-seqof SeqOf ::= {4,7,9}
default-str My-OctStr ::= 'DEADBEEF'H
...
...
tests/regression/test-in-expression/og.pr
View file @
6aac21a9
...
...
@@ -24,62 +24,68 @@ system og;
connect c and r;
/* CIF PROCESS (225, 49), (150, 75) */
process og;
/* CIF TEXT (57, 58), (
290
, 173) */
/* CIF TEXT (57, 58), (
321
, 173) */
dcl test Some_Thing := 4;
dcl someEnum Enum_T := enum2;
dcl somSeq Toto := {elem_1 1, elem_2 false};
dcl testincase ForTheSakeOfIt := {enum1, enum2};
/* CIF ENDTEXT */
/* CIF START (
371
, 221), (70, 35) */
/* CIF START (
556
, 221), (70, 35) */
START;
/* CIF decision (348, 276), (115, 50) */
/* CIF task (492, 276), (197, 35) */
task testincase := {enum1, enum2};
/* CIF decision (533, 326), (115, 50) */
decision test in { 1,2,3,4};
/* CIF ANSWER (
287
, 3
4
6), (70, 23) */
/* CIF ANSWER (
472
, 3
9
6), (70, 23) */
(true):
/* CIF PROCEDURECALL (
266, 38
9), (112, 35) */
/* CIF PROCEDURECALL (
451, 43
9), (112, 35) */
call writeln('OK 1');
/* CIF ANSWER (
416
, 3
4
6), (70, 23) */
/* CIF ANSWER (
601
, 3
9
6), (70, 23) */
(false):
/* CIF PROCEDURECALL (
383, 38
9), (135, 35) */
/* CIF PROCEDURECALL (
568, 43
9), (135, 35) */
call writeln('ERROR 1');
enddecision;
/* CIF decision (
359
, 4
3
9), (93, 50) */
/* CIF decision (
544
, 4
8
9), (93, 50) */
decision 3 in {1,2,3,4};
/* CIF ANSWER (
293
, 5
0
9), (70, 23) */
/* CIF ANSWER (
478
, 5
5
9), (70, 23) */
(true):
/* CIF PROCEDURECALL (
268, 55
2), (119, 35) */
/* CIF PROCEDURECALL (
453, 60
2), (119, 35) */
call writeln('OK 2');
/* CIF ANSWER (
427
, 5
0
9), (70, 23) */
/* CIF ANSWER (
612
, 5
5
9), (70, 23) */
(false):
/* CIF PROCEDURECALL (
391, 55
2), (142, 35) */
/* CIF PROCEDURECALL (
576, 60
2), (142, 35) */
call writeln('ERROR 2');
enddecision;
/* CIF decision (
306
, 6
0
2), (200, 50) */
/* CIF decision (
491
, 6
5
2), (200, 50) */
decision someEnum in {enum1, enum2};
/* CIF ANSWER (
290, 67
2), (70, 23) */
/* CIF ANSWER (
475, 72
2), (70, 23) */
(true):
/* CIF PROCEDURECALL (
265
, 7
1
5), (119, 35) */
/* CIF PROCEDURECALL (
450
, 7
6
5), (119, 35) */
call writeln('OK 3');
/* CIF ANSWER (
430, 67
2), (70, 23) */
/* CIF ANSWER (
615, 72
2), (70, 23) */
(false):
/* CIF PROCEDURECALL (
394
, 7
1
5), (142, 35) */
/* CIF PROCEDURECALL (
579
, 7
6
5), (142, 35) */
call writeln('ERROR 3');
enddecision;
/* CIF decision (
203, 76
5), (406, 50) */
/* CIF decision (
388, 81
5), (406, 50) */
decision 'someSeq in {{elem_1 1, elem_2 false}, {elem_1 0, elem_2 true}}'
/* CIF comment (
629, 77
2), (226, 35) */
/* CIF comment (
814, 82
2), (226, 35) */
comment 'cause bug in Ada backend: FIXME';
/* CIF ANSWER (
290
, 8
3
5), (70, 23) */
/* CIF ANSWER (
475
, 8
8
5), (70, 23) */
(true):
/* CIF PROCEDURECALL (
265, 87
8), (119, 35) */
/* CIF PROCEDURECALL (
450, 92
8), (119, 35) */
call writeln('OK 5');
/* CIF ANSWER (
430
, 8
3
5), (70, 23) */
/* CIF ANSWER (
615
, 8
8
5), (70, 23) */
(false):
/* CIF PROCEDURECALL (
394, 87
8), (142, 35) */
/* CIF PROCEDURECALL (
579, 92
8), (142, 35) */
call writeln('ERROR 5');
enddecision;
/* CIF NEXTSTATE (
371
, 9
2
8), (70, 35) */
/* CIF NEXTSTATE (
556
, 9
7
8), (70, 35) */
NEXTSTATE wait;
/* CIF state (826, 332), (70, 35) */
state wait;
...
...
tests/regression/test-in-expression/og.pr.ini
View file @
6aac21a9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
\x
ff
\0\0\x
3
\x
b8
\0\0\x
3
\x
65
\0\0\0\x
4
\0\0\0\x
4
\0\0\0\b\0\0\0\b\x
fc
\0\0\0\x
2
\0\0\0\0\0\0\0\x
1
\0\0\0\x
16
\0
S
\0\x
44
\0
L
\0
\0
T
\0
o
\0
o
\0
l
\0\x
62
\0\x
61
\0
r
\x
3
\0\0\0\0\x
ff
\x
ff
\x
ff
\x
ff
\0\0\0\0\0\0\0\0\0\0\0\x
2
\0\0\0\x
1
\0\0\0\x
18
\0\x
46
\0
i
\0
l
\0\x
65
\0
\0
T
\0
o
\0
o
\0
l
\0\x
62
\0\x
61
\0
r
\x
1
\0\0\0\0\x
ff
\x
ff
\x
ff
\x
ff
\0\0\0\0\0\0\0\0
)"
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