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
a683085a
Commit
a683085a
authored
Nov 11, 2014
by
Maxime Perrotin
Browse files
Support optional fields in sequence
parent
98b58eb1
Changes
4
Hide whitespace changes
Inline
Side-by-side
AdaGenerator.py
View file @
a683085a
...
...
@@ -1355,7 +1355,8 @@ def _sequence(seq):
ada_string
=
u
"{}'("
.
format
(
type_name
(
seq
.
exprType
))
sep
=
''
type_children
=
find_basic_type
(
seq
.
exprType
).
Children
optional_fields
=
{
field
.
lower
():
False
optional_fields
=
{
field
.
lower
().
replace
(
'-'
,
'_'
):
{
'present'
:
False
,
'ref'
:
(
field
,
val
)}
for
field
,
val
in
type_children
.
viewitems
()
if
val
.
Optional
==
'True'
}
present_fields
=
[]
...
...
@@ -1373,17 +1374,31 @@ def _sequence(seq):
ada_string
+=
u
"{} {} => {}"
.
format
(
sep
,
elem
,
value_str
)
if
elem
.
lower
()
in
optional_fields
:
# Set optional field presence
optional_fields
[
elem
.
lower
()]
=
True
optional_fields
[
elem
.
lower
()]
[
'present'
]
=
True
sep
=
u
', '
stmts
.
extend
(
value_stmts
)
local_decl
.
extend
(
local_var
)
# Process optional fields
if
optional_fields
:
sep
=
''
absent_fields
=
((
fd_name
,
fd_data
[
'ref'
])
for
fd_name
,
fd_data
in
optional_fields
.
viewitems
()
if
not
fd_data
[
'present'
])
for
fd_name
,
fd_data
in
absent_fields
:
fd_type
=
fd_data
[
1
].
type
if
fd_type
.
kind
==
'ReferenceType'
:
value
=
u
'{}_Init'
.
format
(
type_name
(
fd_type
))
elif
fd_type
.
kind
==
'BooleanType'
:
value
=
u
'False'
elif
fd_type
in
(
'IntegerType'
,
'RealType'
):
value
=
fd_type
.
Min
ada_string
+=
u
'{}{} => {}'
.
format
(
sep
,
fd_name
,
value
)
sep
=
u
', '
ada_string
+=
u
', Exist => ('
for
fd_name
,
fd_present
in
optional_fields
.
viewitems
():
sep
=
''
for
fd_name
,
fd_data
in
optional_fields
.
viewitems
():
ada_string
+=
u
'{}{} => {}'
.
format
(
sep
,
fd_name
,
'1'
if
fd_present
else
'0'
)
'1'
if
fd_data
[
'present'
]
else
'0'
)
sep
=
u
', '
ada_string
+=
u
')'
ada_string
+=
')'
...
...
ogParser.py
View file @
a683085a
...
...
@@ -688,32 +688,40 @@ def check_type_compatibility(primary, type_ref, context):
and
basic_type
.
kind
==
'SequenceType'
:
user_nb_elem
=
len
(
primary
.
value
.
keys
())
type_nb_elem
=
len
(
basic_type
.
Children
.
keys
())
if
user_nb_elem
!=
type_nb_elem
:
raise
TypeError
(
'Wrong number of fields in SEQUENCE of type {}'
.
format
(
type_name
(
type_ref
)))
else
:
for
field
,
fd_data
in
basic_type
.
Children
.
viewitems
():
ufield
=
field
.
replace
(
'-'
,
'_'
)
if
ufield
not
in
primary
.
value
:
raise
TypeError
(
'Missing field {field} in SEQUENCE'
' of type {t1} '
.
format
(
field
=
ufield
,
t1
=
type_name
(
type_ref
)))
optional_fields
=
[
field
.
lower
().
replace
(
'-'
,
'_'
)
for
field
,
val
in
basic_type
.
Children
.
viewitems
()
if
val
.
Optional
==
'True'
]
user_fields
=
[
field
.
lower
()
for
field
in
primary
.
value
.
keys
()]
# if user_nb_elem != type_nb_elem:
# raise TypeError('Wrong number of fields in SEQUENCE of type {}'
# .format(type_name(type_ref)))
# else:
for
field
,
fd_data
in
basic_type
.
Children
.
viewitems
():
ufield
=
field
.
replace
(
'-'
,
'_'
)
if
ufield
.
lower
()
not
in
optional_fields
\
and
ufield
.
lower
()
not
in
user_fields
:
raise
TypeError
(
'Missing mandatory field {field} in SEQUENCE'
' of type {t1} '
.
format
(
field
=
ufield
,
t1
=
type_name
(
type_ref
)))
elif
field
.
lower
()
not
in
user_fields
:
# Optional field not set - OK
continue
else
:
# If the user field is a raw value
if
primary
.
value
[
ufield
].
is_raw
:
check_type_compatibility
(
primary
.
value
[
ufield
],
fd_data
.
type
,
context
)
else
:
# If the user field is a raw value
if
primary
.
value
[
ufield
].
is_raw
:
check_type_compatibility
(
primary
.
value
[
ufield
],
fd_data
.
type
,
context
)
else
:
# Compare the types for semantic equivalence
try
:
compare_types
(
primary
.
value
[
ufield
].
exprType
,
fd_data
.
type
)
except
TypeError
as
err
:
raise
TypeError
(
'Field '
+
ufield
+
' is not of the proper type, i.e. '
+
type_name
(
fd_data
.
type
)
+
' - '
+
str
(
err
))
# Compare the types for semantic equivalence
try
:
compare_types
(
primary
.
value
[
ufield
].
exprType
,
fd_data
.
type
)
except
TypeError
as
err
:
raise
TypeError
(
'Field '
+
ufield
+
' is not of the proper type, i.e. '
+
type_name
(
fd_data
.
type
)
+
' - '
+
str
(
err
))
return
elif
isinstance
(
primary
,
ogAST
.
PrimChoiceItem
)
\
and
basic_type
.
kind
.
startswith
(
'Choice'
):
...
...
tests/regression/test-debug/dataview-uniq.asn
View file @
a683085a
...
...
@@ -16,7 +16,7 @@ SeqEnumFix ::= SEQUENCE (SIZE(2)) OF ENUMERATED { hello, world }
Enum ::= ENUMERATED {a, b, c, d, eE}
Choice ::= CHOICE {c1 BOOLEAN, cDe2 BOOLEAN}
SeqOpt ::= SEQUENCE { a BOOLEAN OPTIONAL }
SeqOpt ::= SEQUENCE { a BOOLEAN OPTIONAL
, b BOOLEAN, c SEQUENCE { a BOOLEAN } OPTIONAL, d OCTET STRING (SIZE (0..10)) OPTIONAL
}
SeqNonOpt ::= SEQUENCE { a BOOLEAN }
END
...
...
tests/regression/test-debug/orchestrator.pr
View file @
a683085a
...
...
@@ -2,7 +2,7 @@
PROCESS orchestrator
/* CIF COMMENT (405, 192), (71, 35) */
COMMENT 'Hello';
/* CIF TEXT (39, 94), (
293
, 293) */
/* CIF TEXT (39, 94), (
389
, 293) */
dcl seq tastE_Peek_id_list;
dcl fixed FixedString := 'Hello';
...
...
@@ -21,97 +21,101 @@ dcl check tasTE_Peek_id;
dcl choice choice;
dcl opt SeqOpt := { a TRUE
};
dcl opt SeqOpt := { a TRUE
, b FALSE }; -- test optional fields
/* CIF ENDTEXT */
/* CIF PROCEDURE (727, 175), (106, 35) */
PROCEDURE emptyproc;
ENDPROCEDURE;
/* CIF START (
438
, 22
3
), (80, 36) */
/* CIF START (
502
, 22
4
), (80, 36) */
START;
/* CIF DECISION (428, 274), (99, 50) */
/* CIF TASK (474, 275), (136, 35) */
TASK opt := { b TRUE }
/* CIF COMMENT (630, 275), (155, 35) */
COMMENT 'Test optional fields';
/* CIF DECISION (492, 325), (99, 50) */
DECISION 'informal'
/* CIF COMMENT (
547, 281
), (179, 53) */
/* CIF COMMENT (
611, 332
), (179, 53) */
COMMENT 'Informal decision -
check that it is ignored
by the code generator';
/* CIF ANSWER (
398
, 3
44
), (70, 33) */
/* CIF ANSWER (
462
, 3
95
), (70, 33) */
('a'):
/* CIF ANSWER (
488
, 3
44
), (70, 33) */
/* CIF ANSWER (
552
, 3
95
), (70, 33) */
('2'):
ENDDECISION;
/* CIF TASK (
366, 392
), (223, 38) */
/* CIF TASK (
430, 443
), (223, 38) */
TASK seqboolean := {true, false},
seqboolean := not {true, false};
/* CIF TASK (
396
, 4
45
), (164, 53) */
/* CIF TASK (
460
, 4
96
), (164, 53) */
TASK for x in seqen:
call writeln(num(x));
endfor;
/* CIF TASK (
396
, 5
13
), (164, 53) */
/* CIF TASK (
460
, 5
64
), (164, 53) */
TASK for x in seqen2:
call writeln(num(x));
endfor;
/* CIF TASK (
397, 581
), (162, 53) */
/* CIF TASK (
461, 632
), (162, 53) */
TASK for x in seqboolean:
call writeln(x);
endfor
/* CIF COMMENT (
579, 590
), (168, 38) */
/* CIF COMMENT (
643, 641
), (168, 38) */
COMMENT 'FOR with a basic type';
/* CIF TASK (
367, 649
), (222, 35) */
/* CIF TASK (
431, 700
), (222, 35) */
TASK seqboolean := not seqboolean
/* CIF COMMENT (6
09, 649
), (279, 35) */
/* CIF COMMENT (6
73, 700
), (279, 35) */
COMMENT 'check NOT on a SEQUENCE of BOOLEAN';
/* CIF TASK (
397, 699
), (162, 53) */
/* CIF TASK (
461, 750
), (162, 53) */
TASK for x in seqboolean:
call writeln(x);
endfor;
/* CIF TASK (4
15, 767
), (126, 38) */
/* CIF TASK (4
79, 818
), (126, 38) */
TASK fixed := 'hello';
/* CIF TASK (4
03
, 8
20
), (149, 35) */
/* CIF TASK (4
67
, 8
71
), (149, 35) */
TASK variable := 'HELLO';
/* CIF PROCEDURECALL (
390, 870
), (176, 35) */
/* CIF PROCEDURECALL (
454, 921
), (176, 35) */
CALL writeln(variable // '!!!');
/* CIF PROCEDURECALL (
342
, 9
20
), (272, 35) */
/* CIF PROCEDURECALL (
406
, 9
71
), (272, 35) */
CALL writeln(variable // variable // variable);
/* CIF TASK (4
32, 970
), (91, 35) */
/* CIF TASK (4
96, 1021
), (91, 35) */
TASK seq := {1};
/* CIF TASK (4
01
, 10
20
), (153, 35) */
/* CIF TASK (4
65
, 10
71
), (153, 35) */
TASK seq := {1} // {2} // {3};
/* CIF TASK (
392, 1070
), (172, 35) */
/* CIF TASK (
456, 1121
), (172, 35) */
TASK seq := seq // {2} // {1};
/* CIF DECISION (
443
, 11
20
), (70, 50) */
/* CIF DECISION (
507
, 11
71
), (70, 50) */
DECISION any;
/* CIF ANSWER (
398, 1190
), (70, 23) */
/* CIF ANSWER (
462, 1241
), (70, 23) */
('a'):
/* CIF ANSWER (
488, 1190
), (70, 23) */
/* CIF ANSWER (
552, 1241
), (70, 23) */
('b'):
ENDDECISION;
/* CIF DECISION (4
33
, 12
28
), (89, 50) */
/* CIF DECISION (4
97
, 12
79
), (89, 50) */
DECISION myenum
/* CIF COMMENT (
542
, 12
35
), (183, 35) */
/* CIF COMMENT (
606
, 12
86
), (183, 35) */
COMMENT 'Check case insensitivity';
/* CIF ANSWER (
250, 1298
), (70, 23) */
/* CIF ANSWER (
314, 1349
), (70, 23) */
(a):
/* CIF ANSWER (3
30
, 1
298
), (70, 23) */
/* CIF ANSWER (3
94
, 1
349
), (70, 23) */
(B):
/* CIF ANSWER (4
10
, 1
298
), (70, 23) */
/* CIF ANSWER (4
74
, 1
349
), (70, 23) */
(c):
/* CIF ANSWER (
488, 1298
), (70, 23) */
/* CIF ANSWER (
552, 1349
), (70, 23) */
(d):
/* CIF ANSWER (
576, 1298
), (70, 23) */
/* CIF ANSWER (
640, 1349
), (70, 23) */
(Ee):
ENDDECISION;
/* CIF DECISION (4
09
, 13
36
), (138, 50) */
/* CIF DECISION (4
73
, 13
87
), (138, 50) */
DECISION present(choice)
/* CIF COMMENT (
566
, 134
3
), (183, 35) */
/* CIF COMMENT (
630
, 13
9
4), (183, 35) */
COMMENT 'Check case insensitivity';
/* CIF ANSWER (
361
, 14
06
), (70, 23) */
/* CIF ANSWER (
425
, 14
57
), (70, 23) */
(cde2):
/* CIF ANSWER (5
32
, 14
06
), (70, 23) */
/* CIF ANSWER (5
96
, 14
57
), (70, 23) */
ELSE:
ENDDECISION;
/* CIF NEXTSTATE (4
19
, 14
44
), (116, 33) */
/* CIF NEXTSTATE (4
83
, 14
95
), (116, 33) */
NEXTSTATE Wait_for_GUI;
/* CIF STATE (4
24
, 163), (116, 33) */
/* CIF STATE (4
38
, 163), (116, 33) */
STATE Wait_for_GUI;
ENDSTATE;
ENDPROCESS orchestrator;
\ 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