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
c806f6b1
Commit
c806f6b1
authored
Jan 23, 2015
by
Maxime Perrotin
Browse files
Complete template for inner procedures
parent
b511a5a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
opengeode/StgBackend.py
View file @
c806f6b1
...
...
@@ -99,27 +99,11 @@ def _process(process, simu=False, stgfile='ada_source.st', **kwargs):
VARIABLES
.
update
(
process
.
variables
)
# Initialize array of strings containing all local declarations
process_decl
=
[]
process_vars
=
[]
process_decl
,
process_vars
=
dcl
(
process
,
simu
)
# Generate the code to declare process-level variables
process_level_decl
=
[]
for
var_name
,
(
var_type
,
def_value
)
in
process
.
variables
.
viewitems
():
dcl_template
=
STG
.
getInstanceOf
(
"dcl"
)
dcl_template
[
'simu'
]
=
simu
if
def_value
:
# Expression must be a ground expression, i.e. must not
# require temporary variable to store computed result
dst
,
dstr
,
dlocal
=
expression
(
def_value
)
varbty
=
find_basic_type
(
var_type
)
if
varbty
.
kind
in
(
'SequenceOfType'
,
'OctetStringType'
):
dstr
=
array_content
(
def_value
,
dstr
,
varbty
)
assert
not
dst
and
not
dlocal
,
'DCL: Expecting a ground expression'
var
=
{
'name'
:
var_name
,
'sort'
:
type_name
(
var_type
)}
dcl_template
[
'var'
]
=
var
process_vars
.
append
(
var
)
dcl_template
[
'def_expr'
]
=
dstr
if
def_value
else
''
process_decl
.
append
(
str
(
dcl_template
))
# Set the DCL declarations variable in the process template
process_template
[
'decl'
]
=
process_decl
...
...
@@ -1728,56 +1712,53 @@ def _inner_procedure(proc, **kwargs):
local_decl
=
[
str
(
declaration_template
)]
if
not
proc
.
external
:
# Generate the code for the procedure itself
definition_template
=
STG
.
getInstanceOf
(
"procedure_definition"
)
definition_template
[
'header'
]
=
str
(
signature_template
)
definition_template
[
'name'
]
=
proc
.
inputString
# Generate the code for the procedure itself
# local variables and code of the START transition
decl
=
[]
for
var_name
,
(
var_type
,
def_value
)
in
proc
.
variables
.
viewitems
():
dcl_template
=
STG
.
getInstanceOf
(
"dcl"
)
if
def_value
:
# Expression must be a ground expression, i.e. must not
# require temporary variable to store computed result
dst
,
dstr
,
dlocal
=
expression
(
def_value
)
varbty
=
find_basic_type
(
var_type
)
if
varbty
.
kind
in
(
'SequenceOfType'
,
'OctetStringType'
):
dstr
=
array_content
(
def_value
,
dstr
,
varbty
)
assert
not
dst
and
not
dlocal
,
'Ground expression error'
var
=
{
'name'
:
var_name
,
'sort'
:
type_name
(
var_type
)}
dcl_template
[
'var'
]
=
var
dcl_template
[
'def_expr'
]
=
dstr
if
def_value
else
''
decl
.
append
(
str
(
dcl_template
))
definition_template
[
'decl'
]
=
decl
# XXX HERE
definition_template
[
'dcl'
],
_
=
dcl
(
proc
,
simu
=
False
)
# Look for labels in the diagram and transform them in floating labels
Helper
.
inner_labels_to_floating
(
proc
)
if
proc
.
content
.
start
:
tr_code
,
tr_decl
=
generate
(
proc
.
content
.
start
.
transition
)
else
:
tr_code
,
tr_decl
=
[
'null; -- Empty procedure'
],
[]
start_code
,
other_decl
=
generate
(
proc
.
content
.
start
.
transition
)
definition_template
[
'start'
]
=
start_code
# Generate code for the floating labels
code_labels
=
[]
for
label
in
proc
.
content
.
floating_labels
:
code_label
,
label_decl
=
generate
(
label
)
code_labels
.
extend
(
code_label
)
tr_decl
.
extend
(
label_decl
)
code
.
extend
(
set
(
tr_decl
))
code
.
append
(
'begin'
)
code
.
extend
(
tr_code
)
code
.
extend
(
code_labels
)
code
.
append
(
u
'end p{sep}{procName};'
.
format
(
sep
=
UNICODE_SEP
,
procName
=
proc
.
inputString
))
code
.
append
(
'
\n
'
)
other_decl
.
extend
(
label_decl
)
definition_template
[
'other_decl'
]
=
set
(
other_decl
)
definition_template
[
'labels'
]
=
code_labels
# Reset the scope to how it was prior to the procedure definition
VARIABLES
.
clear
()
VARIABLES
.
update
(
outer_scope
)
return
code
,
local_decl
return
str
(
definition_template
),
local_decl
def
dcl
(
entity
,
simu
):
''' Generate the code to declare variables '''
decl
,
arr_vars
=
[],
[]
for
var_name
,
(
var_type
,
def_value
)
in
entity
.
variables
.
viewitems
():
dcl_template
=
STG
.
getInstanceOf
(
"dcl"
)
dcl_template
[
'simu'
]
=
simu
if
def_value
:
# Expression must be a ground expression, i.e. must not
# require temporary variable to store computed result
dst
,
dstr
,
dlocal
=
expression
(
def_value
)
varbty
=
find_basic_type
(
var_type
)
if
varbty
.
kind
in
(
'SequenceOfType'
,
'OctetStringType'
):
dstr
=
array_content
(
def_value
,
dstr
,
varbty
)
assert
not
dst
and
not
dlocal
,
'DCL: Expecting a ground expression'
var
=
{
'name'
:
var_name
,
'sort'
:
type_name
(
var_type
)}
dcl_template
[
'var'
]
=
var
arr_vars
.
append
(
var
)
dcl_template
[
'def_expr'
]
=
dstr
if
def_value
else
''
result
.
append
(
str
(
dcl_template
))
return
decl
,
arr_vars
def
string_payload
(
prim
,
ada_string
):
...
...
opengeode/ada_body.st
View file @
c806f6b1
...
...
@@ -104,19 +104,24 @@ pragma Export(C, dll_set_l_<var.name>, "_set_<var.name>");
/*
Code
for
a
(
stateless
)
procedure
*/
procedure_definition
(
header
,
name
,
d
e
cl
,
code
,
labels
)
:
:=
<<
procedure_definition
(
header
,
name
,
dcl
,
other_decl
,
start
,
labels
)
:
:=
<<
<
header
>
is
<
if
(
d
e
cl
)
>
<
if
(
dcl
)
>
--
Procedure
local
variables
declared
in
textboxes
<
decl
;
separator=
"\n"
>
<
dcl
;
separator=
"\n"
>
<
endif
>
<
if
(
other_decl
)
>
--
Other
local
declarations
needed
to
support
all
SDL
constructs
<
other_decl
;
separator=
"\n"
>
<
endif
>
begin
<
code
>
<
if
(!
code
)
>
<
start
>
<
if
(!
start
)
>
null
;
--
Empty
procedure
<
endif
>
<
labels
>
end
p<\
u00dc
><
name
>
;
>>
...
...
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