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
c4bae792
Commit
c4bae792
authored
Nov 25, 2015
by
Maxime Perrotin
Browse files
Generate Ada code for continuous signals
parent
0dc96941
Changes
3
Hide whitespace changes
Inline
Side-by-side
opengeode/AdaGenerator.py
View file @
c4bae792
...
...
@@ -743,14 +743,23 @@ package {process_name} is'''.format(process_name=process_name,
.
format
(
ctxt
=
LPREFIX
,
s1
=
agg_name
,
s2
=
each
.
statename
,
sep
=
UNICODE_SEP
,
s3
=
statename
,
first
=
'els'
if
done
else
''
))
taste_template
.
append
(
u
'null;'
)
for
provided_clause
in
cs_item
:
trId
=
process
.
transitions
.
index
\
(
provided_clause
.
transition
)
code
,
loc
=
generate
(
provided_clause
.
trigger
,
branch_to
=
trId
)
taste_template
.
extend
(
code
)
done
.
append
(
statename
)
break
for
statename
in
process
.
cs_mapping
.
viewkeys
()
-
done
:
cs_item
=
process
.
cs_mapping
[
statename
]
taste_template
.
append
(
u
'{first}if trId = -1 and {}.state = {} then'
.
format
(
LPREFIX
,
statename
,
first
=
'els'
if
done
else
''
))
taste_template
.
append
(
u
'null;'
)
for
provided_clause
in
cs_item
:
trId
=
process
.
transitions
.
index
(
provided_clause
.
transition
)
code
,
loc
=
generate
(
provided_clause
.
trigger
,
branch_to
=
trId
)
taste_template
.
extend
(
code
)
if
process
.
cs_mapping
:
taste_template
.
append
(
u
'end if;'
)
...
...
@@ -777,8 +786,6 @@ package {process_name} is'''.format(process_name=process_name,
if
simu
:
with
open
(
u
'{}_interface.aadl'
.
format
(
process_name
),
'w'
)
as
aadl
:
aadl
.
write
(
u
'
\n
'
.
join
(
minicv
).
encode
(
'latin1'
))
if
not
simu
:
with
open
(
'{}_simu.sh'
.
format
(
process_name
),
'w'
)
as
bash_script
:
bash_script
.
write
(
simu_script
)
...
...
@@ -1872,8 +1879,19 @@ def _choiceitem(choice):
@
generate
.
register
(
ogAST
.
Decision
)
def
_decision
(
dec
,
**
kwargs
):
''' generate the code for a decision '''
def
_decision
(
dec
,
branch_to
=
None
,
**
kwargs
):
''' Generate the code for a decision
A decision is made of a question and some answers ; each answer may
be followed by a transition (ogAST.Transition). The code of the
transition is by default generated, but it is possible to generate only
the code of the question and reference a transition Id (trId) if
the reference number is passed to the branch_to parameter.
This option is used for example when generating the code of
continuous signal: the code is generated in the <<next_transition>>
part, while the code of the transition already exists in the
part above. The need is only to set the id of the next transition.
XXX has to be done also in the C backend
'''
code
,
local_decl
=
[],
[]
if
dec
.
kind
==
'any'
:
LOG
.
warning
(
'Ada backend does not support the "ANY" statement'
)
...
...
@@ -1929,12 +1947,15 @@ def _decision(dec, **kwargs):
op
=
a
.
openRangeOp
.
operand
,
ans
=
ans_str
)
code
.
append
(
sep
+
exp
+
' then'
)
if
a
.
transition
:
stmt
,
tr_decl
=
generate
(
a
.
transition
)
if
not
branch_to
:
if
a
.
transition
:
stmt
,
tr_decl
=
generate
(
a
.
transition
)
else
:
stmt
,
tr_decl
=
[
'null;'
],
[]
code
.
extend
(
stmt
)
local_decl
.
extend
(
tr_decl
)
else
:
stmt
,
tr_decl
=
[
'null;'
],
[]
code
.
extend
(
stmt
)
local_decl
.
extend
(
tr_decl
)
code
.
append
(
'trId := {};'
.
format
(
branch_to
))
sep
=
'elsif '
elif
a
.
kind
==
'closed_range'
:
cl0_stmts
,
cl0_str
,
cl0_decl
=
expression
(
a
.
closedRange
[
0
])
...
...
@@ -1945,12 +1966,15 @@ def _decision(dec, **kwargs):
local_decl
.
extend
(
cl1_decl
)
code
.
append
(
'{sep} {dec} >= {cl0} and {dec} <= {cl1} then'
.
format
(
sep
=
sep
,
dec
=
q_str
,
cl0
=
cl0_str
,
cl1
=
cl1_str
))
if
a
.
transition
:
stmt
,
tr_decl
=
generate
(
a
.
transition
)
if
not
branch_to
:
if
a
.
transition
:
stmt
,
tr_decl
=
generate
(
a
.
transition
)
else
:
stmt
,
tr_decl
=
[
'null;'
],
[]
code
.
extend
(
stmt
)
local_decl
.
extend
(
tr_decl
)
else
:
stmt
,
tr_decl
=
[
'null;'
],
[]
code
.
extend
(
stmt
)
local_decl
.
extend
(
tr_decl
)
code
.
append
(
'trId := {};'
.
format
(
branch_to
))
sep
=
'elsif '
elif
a
.
kind
==
'informal_text'
:
continue
...
...
opengeode/ogAST.py
View file @
c4bae792
...
...
@@ -616,7 +616,7 @@ class ContinuousSignal(Input):
def
__init__
(
self
):
''' Difference with Input: trigger is an expression '''
super
(
ContinuousSignal
,
self
).
__init__
()
#
Expres
sion triggering the transition
#
Deci
sion triggering the transition
self
.
trigger
=
None
# Priority (integer)
self
.
priority
=
0
...
...
opengeode/ogParser.py
View file @
c4bae792
...
...
@@ -2752,12 +2752,26 @@ def process_definition(root, parent=None, context=None):
def
continuous_signal
(
root
,
parent
,
context
):
''' Parse a PROVIDED clause in a continuous signal '''
i
=
ogAST
.
ContinuousSignal
()
dec
=
ogAST
.
Decision
()
ans
=
ogAST
.
Answer
()
warnings
,
errors
=
[],
[]
# Keep track of the number of terminator statements in the transition
# useful if we want to render graphs from the SDL model
terminators
=
len
(
context
.
terminators
)
i
.
trigger
,
exp_err
,
exp_warn
=
expression
(
root
.
getChild
(
0
),
context
)
i
.
inputString
=
i
.
trigger
.
inputString
dec
.
question
,
exp_err
,
exp_warn
=
expression
(
root
.
getChild
(
0
),
context
)
dec
.
inputString
=
dec
.
question
.
inputString
dec
.
line
=
dec
.
question
.
line
dec
.
charPositionInLine
=
dec
.
question
.
charPositionInLine
dec
.
kind
=
'question'
ans
.
inputString
=
'true'
ans
.
openRangeOp
=
ogAST
.
ExprEq
ans
.
kind
=
'constant'
ans
.
constant
=
ogAST
.
PrimBoolean
()
ans
.
constant
.
value
=
[
'true'
]
ans
.
constant
.
exprType
=
BOOLEAN
dec
.
answers
=
[
ans
]
i
.
trigger
=
dec
i
.
inputString
=
dec
.
inputString
for
child
in
root
.
children
[
1
:]:
if
child
.
type
==
lexer
.
CIF
:
# Get symbol coordinates
...
...
@@ -2770,12 +2784,14 @@ def continuous_signal(root, parent, context):
errors
.
extend
(
err
)
warnings
.
extend
(
warn
)
i
.
transition
=
trans
ans
.
transition
=
trans
# Associate a reference to the transition to the list of inputs
# The reference is an index to process.transitions table
context
.
transitions
.
append
(
trans
)
i
.
transition_id
=
len
(
context
.
transitions
)
-
1
elif
child
.
type
==
lexer
.
COMMENT
:
i
.
comment
,
_
,
_
=
end
(
child
)
dec
.
comment
=
i
.
comment
elif
child
.
type
==
lexer
.
HYPERLINK
:
i
.
hyperlink
=
child
.
getChild
(
0
).
toString
()[
1
:
-
1
]
elif
child
.
type
==
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