Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenGEODE
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
TASTE
OpenGEODE
Commits
bf495611
Commit
bf495611
authored
Feb 07, 2019
by
Maxime Perrotin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for the "val" operator
as per ISS request
parent
e728ee23
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
83 additions
and
28 deletions
+83
-28
README.md
README.md
+5
-0
opengeode/AdaGenerator.py
opengeode/AdaGenerator.py
+10
-0
opengeode/ogParser.py
opengeode/ogParser.py
+25
-0
opengeode/opengeode.py
opengeode/opengeode.py
+1
-1
tests/regression/test-choice-determinant/dataview.asn
tests/regression/test-choice-determinant/dataview.asn
+3
-0
tests/regression/test-choice-determinant/toto.pr
tests/regression/test-choice-determinant/toto.pr
+35
-23
tests/regression/test-demo2callers/check
tests/regression/test-demo2callers/check
+0
-0
tests/regression/test-eds1/testsc_simu/testsc_simu.sh
tests/regression/test-eds1/testsc_simu/testsc_simu.sh
+4
-4
tests/regression/test-uart/check
tests/regression/test-uart/check
+0
-0
No files found.
README.md
View file @
bf495611
...
...
@@ -134,6 +134,11 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
2.
0.20 (02/2019)
-
Added "val" operator to convert a number to an enumerant
useage: someVal := val (0, MyEnumeratedType)
with someVal of type MyEnumeratedType. Will return the first enumerant
2.
0.19 (01/2019)
-
for CHOICE types variables can be declared with enumerated type
corresponding to the choice distriminant. CHOICE type is suffixed by
...
...
opengeode/AdaGenerator.py
View file @
bf495611
...
...
@@ -1604,6 +1604,16 @@ def _prim_call(prim, **kwargs):
.
format
(
sort
=
sort_name
,
var_type
=
var_typename
,
var_str
=
var_str
)
elif
ident
==
'val'
:
variable
,
target_type
=
params
var_typename
=
type_name
(
variable
.
exprType
)
var_stmts
,
var_str
,
var_decl
=
expression
(
variable
,
readonly
=
1
)
stmts
.
extend
(
var_stmts
)
local_decl
.
extend
(
var_decl
)
sort_name
=
'asn1Scc'
+
target_type
.
value
[
0
].
replace
(
'-'
,
'_'
)
ada_string
+=
"{sort}'Val ({var_str})"
\
.
format
(
sort
=
sort_name
,
var_str
=
var_str
)
elif
ident
==
'num'
:
# User wants to get an enumerated corresponding integer value
exp
=
params
[
0
]
...
...
opengeode/ogParser.py
View file @
bf495611
...
...
@@ -141,6 +141,10 @@ SPECIAL_OPERATORS = {
{
'type'
:
ENUMERATED
,
'direction'
:
'in'
},
{
'type'
:
ANY_TYPE
,
'direction'
:
'in'
}
],
'val'
:
[
# to convert a number to an enumerated type value
{
'type'
:
UNSIGNED
,
'direction'
:
'in'
},
# eg. 1
{
'type'
:
ANY_TYPE
,
'direction'
:
'in'
}
# eg. MyChoice
],
}
# Container to keep a list of types mapped from ANTLR Tokens
...
...
@@ -591,6 +595,27 @@ def check_call(name, params, context):
return
type
(
'Exist'
,
(
object
,),
{
'kind'
:
'BooleanType'
})
elif
name
==
'val'
:
# val converts a positive number to a enumeration literal
# the first parameter is the number and the second is the type name
# of the enumeration. It is equivalent in Ada to EnumType'Val(number)
if
len
(
params
)
!=
2
:
raise
TypeError
(
name
+
" takes 2 parameters: number, type"
)
variable
,
target_type
=
params
variable_sort
=
find_basic_type
(
variable
.
exprType
)
if
variable_sort
.
kind
!=
'IntegerType'
:
raise
TypeError
(
name
+
': First parameter is not an number'
)
sort_name
=
target_type
.
value
[
0
]
# raw string of the type to cast
for
sort
in
types
().
keys
():
if
sort
.
lower
().
replace
(
'-'
,
'_'
)
==
\
sort_name
.
lower
().
replace
(
'-'
,
'_'
):
break
else
:
raise
TypeError
(
name
+
': type '
+
sort_name
+
'not found'
)
# we could check if the range of the number is compatible with the
# number of values...
return_type
=
types
()[
sort
].
type
return
return_type
elif
name
in
(
'to_selector'
,
'to_enum'
):
if
len
(
params
)
!=
2
:
...
...
opengeode/opengeode.py
View file @
bf495611
...
...
@@ -141,7 +141,7 @@ except ImportError:
__all__
=
[
'opengeode'
,
'SDL_Scene'
,
'SDL_View'
,
'parse'
]
__version__
=
'2.0.
19
'
__version__
=
'2.0.
20
'
if
hasattr
(
sys
,
'frozen'
):
# Detect if we are running on Windows (py2exe-generated)
...
...
tests/regression/test-choice-determinant/dataview.asn
View file @
bf495611
...
...
@@ -6,4 +6,7 @@ BEGIN
}
MyEnum ::= ENUMERATED { foo, bar }
MyInt ::= INTEGER (0 .. 1)
END
tests/regression/test-choice-determinant/toto.pr
View file @
bf495611
...
...
@@ -21,59 +21,71 @@ system toto;
dcl val MyChoice, det MyEnum;
dcl choice_selectors MyChoice_selection := foo;
dcl pos MyInt;
/* CIF ENDTEXT */
/* CIF START (240, 89), (70, 35) */
START;
/* CIF task (160, 144), (229, 35) */
task choice_selectors := present(val);
/* CIF decision (222, 19
4
), (106, 50) */
/* CIF decision (222, 19
9
), (106, 50) */
decision present (val);
/* CIF ANSWER (195, 26
4
), (70, 24) */
/* CIF ANSWER (195, 26
9
), (70, 24) */
(foo):
/* CIF ANSWER (285, 26
4
), (70, 24) */
/* CIF ANSWER (285, 26
9
), (70, 24) */
(bar):
enddecision;
/* CIF decision (222, 30
3
), (106, 50) */
/* CIF decision (222, 30
8
), (106, 50) */
decision present (val);
/* CIF ANSWER (166, 37
3
), (129, 24) */
/* CIF ANSWER (166, 37
8
), (129, 24) */
(choice_selectors):
/* CIF ANSWER (315, 37
3
), (70, 24) */
/* CIF ANSWER (315, 37
8
), (70, 24) */
else:
enddecision;
/* CIF decision (210, 41
2
), (129, 50) */
/* CIF decision (210, 41
7
), (129, 50) */
decision choice_selectors;
/* CIF ANSWER (223, 48
2
), (103, 24) */
/* CIF ANSWER (223, 48
7
), (103, 24) */
(present(val)):
/* CIF ANSWER (346, 48
2
), (70, 24) */
/* CIF ANSWER (346, 48
7
), (70, 24) */
else:
enddecision;
/* CIF task (233, 52
1
), (83, 35) */
/* CIF task (233, 52
6
), (83, 35) */
task det := foo;
/* CIF task (189, 576), (171, 40) */
/* CIF task (215, 581), (119, 35) */
task pos := num (det);
/* CIF PROCEDURECALL (137, 636), (276, 35) */
call writeln ('num(det) = ', pos, ' (should be 0)');
/* CIF task (189, 686), (171, 40) */
task choice_selectors := bar;
/* CIF task (113,
63
6), (324, 40) */
/* CIF task (113,
74
6), (324, 40) */
task choice_selectors := to_selector (det, MyChoice);
/* CIF PROCEDURECALL (120,
69
6), (309, 35) */
/* CIF PROCEDURECALL (120,
80
6), (309, 35) */
call writeln (choice_selectors, ' (should be FOO)');
/* CIF task (233,
75
1), (83, 35) */
/* CIF task (233,
86
1), (83, 35) */
task det := bar;
/* CIF task (124,
80
1), (302, 40) */
/* CIF task (124,
91
1), (302, 40) */
task det := to_enum (choice_selectors, MyEnum);
/* CIF PROCEDURECALL (120,
86
1), (309, 35) */
/* CIF PROCEDURECALL (120,
97
1), (309, 35) */
call writeln (det, ' (should be FOO)');
/* CIF task (233,
91
6), (83, 35) */
/* CIF task (233,
102
6), (83, 35) */
task det := bar;
/* CIF task (113,
97
1), (324, 40) */
/* CIF task (113,
108
1), (324, 40) */
task choice_selectors := to_selector (det, MyChoice);
/* CIF PROCEDURECALL (120, 1
03
1), (309, 35) */
/* CIF PROCEDURECALL (120, 1
14
1), (309, 35) */
call writeln (choice_selectors, ' (should be BAR)');
/* CIF task (233, 1
08
6), (83, 35) */
/* CIF task (233, 1
19
6), (83, 35) */
task det := foo;
/* CIF task (124, 1
14
1), (302, 40) */
/* CIF task (124, 1
25
1), (302, 40) */
task det := to_enum (choice_selectors, MyEnum);
/* CIF PROCEDURECALL (120, 1
20
1), (309, 35) */
/* CIF PROCEDURECALL (120, 1
31
1), (309, 35) */
call writeln (det, ' (should be BAR)');
/* CIF NEXTSTATE (243, 1251), (64, 35) */
/* CIF task (193, 1366), (164, 35) */
task det := val (0, MyEnum)
/* CIF comment (377, 1366), (133, 35) */
comment 'convert 0 to foo';
/* CIF PROCEDURECALL (120, 1421), (309, 35) */
call writeln (det, ' (should be FOO)');
/* CIF NEXTSTATE (243, 1471), (64, 35) */
NEXTSTATE hop;
/* CIF state (528, 360), (70, 35) */
state hop;
...
...
tests/regression/test-demo2callers/check
View file @
bf495611
No preview for this file type
tests/regression/test-eds1/testsc_simu/testsc_simu.sh
View file @
bf495611
#!/bin/bash -e
rm
-rf
testsc_simu
mkdir
-p
testsc_simu
cp
/home/taste/opengeode-github/tests/regression/test-eds1/testsc_simu/testsc.pr dataview.asn testsc_simu
cp
/home/taste/opengeode-github/tests/regression/test-eds1/testsc_simu/testsc.pr
/home/taste/opengeode-github/tests/regression/test-eds1/testsc_simu/
dataview.asn testsc_simu
cd
testsc_simu
opengeode testsc.pr
--shared
cat
dataview.asn
>>
dataview-uniq.asn
mono
$(
which asn1.exe
)
-Ada
-typePrefix
asn1Scc
-equal
dataview.asn
mono
$(
which asn1.exe
)
-c
-typePrefix
asn1Scc
-equal
dataview.asn
cat
/home/taste/opengeode-github/tests/regression/test-eds1/testsc_simu/
dataview.asn
>>
dataview-uniq.asn
mono
$(
which asn1.exe
)
-Ada
-typePrefix
asn1Scc
-equal
/home/taste/opengeode-github/tests/regression/test-eds1/testsc_simu/
dataview.asn
mono
$(
which asn1.exe
)
-c
-typePrefix
asn1Scc
-equal
/home/taste/opengeode-github/tests/regression/test-eds1/testsc_simu/
dataview.asn
gnatmake
-fPIC
-gnat2012
-c
*
.adb
gnatbind
-n
-Llibtestsc
testsc
gnatmake
-fPIC
-c
-gnat2012
b~testsc.adb
...
...
tests/regression/test-uart/check
View file @
bf495611
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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