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
1e9e06f9
Commit
1e9e06f9
authored
Mar 06, 2019
by
Maxime Perrotin
Browse files
Introduce operator choice_to_int
parent
64abba54
Changes
6
Hide whitespace changes
Inline
Side-by-side
opengeode/AdaGenerator.py
View file @
1e9e06f9
...
...
@@ -1650,6 +1650,32 @@ def _prim_call(prim, **kwargs):
stmts
.
extend
(
param_stmts
)
local_decl
.
extend
(
local_var
)
ada_string
+=
(
'{}.Kind'
.
format
(
param_str
))
elif
ident
==
'choice_to_int'
:
p1
,
p2
=
params
sort
=
find_basic_type
(
p1
.
exprType
)
assert
(
sort
.
kind
==
'ChoiceType'
)
# normally checked by the parser
param_stmts
,
varstr
,
local_var
=
expression
(
p1
,
readonly
=
1
)
stmts
.
extend
(
param_stmts
)
local_decl
.
extend
(
local_var
)
param_stmts
,
defaultstr
,
local_var
=
expression
(
p2
,
readonly
=
1
)
stmts
.
extend
(
param_stmts
)
local_decl
.
extend
(
local_var
)
ada_string
+=
(
u
'(case {var}.Kind is '
.
format
(
var
=
varstr
))
choices
=
[]
need_default
=
False
for
child_name
,
descr
in
sort
.
Children
.
viewitems
():
child_id
=
descr
.
EnumID
child_sort
=
find_basic_type
(
descr
.
type
)
if
not
child_sort
.
kind
.
startswith
(
'Integer'
):
need_default
=
True
continue
choices
.
append
(
u
'when {child_id} => {var}.{name}'
.
format
(
child_id
=
child_id
,
var
=
varstr
,
name
=
child_name
))
if
need_default
:
choices
.
append
(
u
'when others => {}'
.
format
(
defaultstr
))
ada_string
+=
u
', '
.
join
(
choices
)
+
')'
elif
ident
==
'exist'
:
# User wants to know if an optional field is present or not
selector
=
params
[
0
]
# type PrimSelector
...
...
opengeode/ogParser.py
View file @
1e9e06f9
...
...
@@ -145,6 +145,11 @@ SPECIAL_OPERATORS = {
{
'type'
:
UNSIGNED
,
'direction'
:
'in'
},
# eg. 1
{
'type'
:
ANY_TYPE
,
'direction'
:
'in'
}
# eg. MyChoice
],
'choice_to_int'
:
[
# to return the value of a numerical choice item
{
'type'
:
CHOICE
,
'direction'
:
'in'
},
# choice variable
{
'type'
:
NUMERICAL
,
'direction'
:
'in'
}
# default value
],
}
# Container to keep a list of types mapped from ANTLR Tokens
...
...
@@ -768,11 +773,16 @@ def check_call(name, params, context):
sort
=
type_name
(
p
.
exprType
)
+
"-selection"
return
types
()[
sort
].
type
# return type('Present', (object,), {
# 'kind': 'ChoiceEnumeratedType',
# 'EnumValues': param_btys[0].Children
# })
#
# choice_to_int: returns an integer corresponding to either the currently
# selected choice value (e.g. foo in CHOICE { foo INTEGER (..), ... } when
# foo is the current choice). or a default, user-defined value if the
# current choice is not numerical. The first parameter is an instance of
# a CHOICE type, and the second parameter is the default value.
elif
name
==
'choice_to_int'
:
p1
,
_
=
params
#sort = type_name (p1.exprType)
return
type
(
'choice_to_int'
,
(
INTEGER
,),
{})
elif
name
==
'round'
:
return
type
(
'Round'
,
(
REAL
,),
{
'Min'
:
str
(
round
(
float
(
param_btys
[
0
].
Min
))),
...
...
tests/regression/test-choice/dataview.asn
View file @
1e9e06f9
...
...
@@ -24,6 +24,17 @@ c3 ChoiceWithEmptySeq ::= b: {}
c4 ChoiceWithEmptySeq ::= c: NULL
c5 AnotherEmptySeq ::= {}
MyInt ::= INTEGER (-10..10)
-- choice to test the choice_to_int internal operator
Parameters ::= CHOICE {
one INTEGER (0..255),
two MyInt,
three BOOLEAN
}
-- Type below is accepted by ASN.1 compiler but that's wrong
-- c6 ChoiceWithEmptySeq ::= b: c5
...
...
tests/regression/test-choice/og.pr
View file @
1e9e06f9
SYSTEM
og;
/* CIF TEXT (159, 221), (2
8
9, 188) */
system
og;
/* CIF TEXT (159, 221), (29
0
, 188) */
-- Text area for declarations and comments
use dv comment 'dataview.asn';
signal dd;
signal we;
use dv comment 'dataview.asn';
signal dd;
signal we;
/* CIF ENDTEXT */
CHANNEL
c
FROM ENV TO og WITH
dd;
FROM og TO ENV WITH
we;
ENDCHANNEL
;
BLOCK
og;
SIGNALROUTE
r
FROM ENV TO og WITH
dd;
FROM og TO ENV WITH
we;
CONNECT c AND
r;
channel
c
from env to og with
dd;
from og to env with
we;
endchannel
;
block
og;
signalroute
r
from env to og with
dd;
from og to env with
we;
connect c and
r;
/* CIF PROCESS (225, 50), (150, 75) */
PROCESS
og;
/* CIF TEXT (70, 60), (337, 1
30
) */
process
og;
/* CIF TEXT (70, 60), (337, 1
84
) */
-- Test choice assignments and access
dcl ch ChoiceWithEmptySeq;
dcl em EmptySeq := {};
dcl eso SeqOf := {};
dcl ch ChoiceWithEmptySeq;
dcl em EmptySeq := {};
dcl eso SeqOf := {};
dcl param Parameters := one : 5;
dcl param2 Parameters;
/* CIF ENDTEXT */
/* CIF START (
174
, 228), (70, 35) */
/* CIF START (
445
, 228), (70, 35) */
START;
/* CIF
TASK (160
, 278), (98, 35) */
TASK
ch := b: {};
/* CIF
TASK (166
, 328), (85, 35) */
TASK
eso := {};
/* CIF
TASK (156
, 378), (106, 35) */
TASK
em := ch!b
/* CIF
COMMENT (278
, 376), (177, 40) */
COMMENT
'This is ok, there should
/* CIF
task (431
, 278), (98, 35) */
task
ch := b: {};
/* CIF
task (437
, 328), (85, 35) */
task
eso := {};
/* CIF
task (427
, 378), (106, 35) */
task
em := ch!b
/* CIF
comment (549
, 376), (177, 40) */
comment
'This is ok, there should
be no warning raised';
/* CIF
TASK (145
, 433), (127, 35) */
TASK
ch:= d: {a TRUE}
/* CIF
COMMENT (292
, 433), (17
0
,
38
) */
COMMENT
'No error, but
/* CIF
task (416
, 433), (127, 35) */
task
ch:= d: {a TRUE}
/* CIF
comment (563
, 433), (17
5
,
40
) */
comment
'No error, but
ch!d!a := TRUE would fail';
/* CIF NEXTSTATE (174, 483), (70, 35) */
/* CIF task (309, 488), (341, 35) */
task param2 := three : (choice_to_int (param, 10) < 10);
/* CIF NEXTSTATE (445, 538), (70, 35) */
NEXTSTATE wait;
/* CIF
STATE (474
, 233), (70, 35) */
STATE
wait;
/* CIF
INPUT (467
, 288), (84, 35) */
INPUT
dd;
/* CIF
OUTPUT (464
, 338), (89, 35) */
OUTPUT
we;
/* CIF NEXTSTATE (
474
, 388), (70, 35) */
/* CIF
state (758
, 233), (70, 35) */
state
wait;
/* CIF
input (751
, 288), (84, 35) */
input
dd;
/* CIF
output (748
, 338), (89, 35) */
output
we;
/* CIF NEXTSTATE (
758
, 388), (70, 35) */
NEXTSTATE wait;
ENDSTATE;
ENDPROCESS og;
ENDBLOCK;
ENDSYSTEM;
\ No newline at end of file
endstate;
endprocess og;
endblock;
endsystem;
\ No newline at end of file
tests/regression/test-demo2callers/check
View file @
1e9e06f9
No preview for this file type
tests/regression/test-uart/check
View file @
1e9e06f9
No preview for this file type
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