Commit f5899162 authored by Maxime Perrotin's avatar Maxime Perrotin

Add prefix to generated procedures (Ada)

parent 30d209be
......@@ -87,6 +87,7 @@ LOCAL_VAR = {}
OUT_SIGNALS = []
PROCEDURES = []
UNICODE_SEP = u'\u00dc'
@singledispatch
def generate(ast):
......@@ -110,7 +111,7 @@ def _process(process):
LOG.info('Generating Ada code for process ' + str(process_name))
# In case model has nested states, flatten everything
Helper.flatten(process, sep=u'\u00dc')
Helper.flatten(process, sep=UNICODE_SEP)
# Make an maping {input: {state: transition...}} in order to easily
# generate the lookup tables for the state machine runtime
......@@ -236,7 +237,7 @@ package {process_name} is'''.format(process_name=process_name,
taste_template.append(u'when {state} =>'.format(state=state))
input_def = mapping[signal['name']].get(state)
# Check for nested states to call optional exit procedure
sep = u'\u00dc'
sep = UNICODE_SEP
state_tree = state.split(sep)
context = process
exitlist = []
......@@ -435,7 +436,7 @@ def write_statement(param, newline):
code, string, local = expression(param)
if type_kind == 'OctetStringType':
# Octet string -> convert to Ada string
sep = u'\u00dc'
sep = UNICODE_SEP
last_it = u""
if isinstance(param, ogAST.PrimSubstring):
range_str = u"{}'Range".format(string)
......@@ -593,11 +594,12 @@ def _call_external_function(output):
# no need to use temporary variables, we are in pure Ada
list_of_params.append(p_id)
if list_of_params:
code.append(u'{proc}({params});'.format(
code.append(u'p{sep}{proc}({params});'.format(
sep=UNICODE_SEP,
proc=proc.inputString,
params=', '.join(list_of_params)))
else:
code.append(u'{};'.format(proc.inputString))
code.append(u'p{}{};'.format(UNICODE_SEP, proc.inputString))
return code, local_decl
......@@ -1665,7 +1667,8 @@ def _inner_procedure(proc):
VARIABLES.update({var['name']: (var['type'], None)})
# Build the procedure signature
pi_header = u'procedure {proc_name}'.format(proc_name=proc.inputString)
pi_header = u'procedure p{sep}{proc_name}'.format(sep=UNICODE_SEP,
proc_name=proc.inputString)
if proc.fpar:
pi_header += '('
params = []
......@@ -1722,7 +1725,8 @@ def _inner_procedure(proc):
code.append('begin')
code.extend(tr_code)
code.extend(code_labels)
code.append(u'end {procName};'.format(procName=proc.inputString))
code.append(u'end p{sep}{procName};'.format(sep=UNICODE_SEP,
procName=proc.inputString))
code.append('\n')
# Reset the scope to how it was prior to the procedure definition
......
......@@ -28,6 +28,7 @@ Type2 ::= BOOLEAN
Toto ::= SEQUENCE { elem-1 Type1, elem-2 Type2 }
SeqBool ::= SEQUENCE(SIZE(1..5)) OF BOOLEAN
Enum ::= ENUMERATED {enum1}
default-seqof SeqOf ::= {4,7,9}
default-str My-OctStr ::= 'DEADBEEF'H
......
......@@ -49,6 +49,21 @@ dcl test Some_Thing := 4;
/* CIF RETURN (181, 263), (35, 35) */
RETURN ;
ENDPROCEDURE;
/* CIF PROCEDURE (439, 309), (70, 35) */
PROCEDURE haha
/* CIF COMMENT (529, 309), (184, 35) */
COMMENT 'same name as a variable';
ENDPROCEDURE;
/* CIF PROCEDURE (414, 353), (124, 35) */
PROCEDURE default_seqof
/* CIF COMMENT (558, 353), (189, 35) */
COMMENT 'same name as a constant';
ENDPROCEDURE;
/* CIF PROCEDURE (430, 404), (78, 35) */
PROCEDURE enum1
/* CIF COMMENT (528, 404), (206, 35) */
COMMENT 'same name as an enum item';
ENDPROCEDURE;
/* CIF START (155, 216), (70, 35) */
START;
/* CIF NEXTSTATE (155, 266), (70, 35) */
......@@ -61,7 +76,13 @@ dcl test Some_Thing := 4;
CALL hehe(hihi);
/* CIF OUTPUT (286, 386), (89, 35) */
OUTPUT we(test);
/* CIF NEXTSTATE (296, 436), (70, 35) */
/* CIF PROCEDURECALL (296, 436), (70, 35) */
CALL haha;
/* CIF PROCEDURECALL (269, 486), (124, 35) */
CALL default_seqof;
/* CIF PROCEDURECALL (292, 536), (78, 35) */
CALL enum1;
/* CIF NEXTSTATE (296, 586), (70, 35) */
NEXTSTATE wait;
ENDSTATE;
ENDPROCESS og;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment