Commit a16cbe27 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Separate prefix for local variables

parent def9088e
...@@ -92,6 +92,7 @@ PROCEDURES = [] ...@@ -92,6 +92,7 @@ PROCEDURES = []
SHARED_LIB = False SHARED_LIB = False
UNICODE_SEP = u'\u00dc' UNICODE_SEP = u'\u00dc'
LPREFIX = u'l_'
@singledispatch @singledispatch
def generate(*args, **kwargs): def generate(*args, **kwargs):
...@@ -195,8 +196,8 @@ LD_LIBRARY_PATH=. taste-gui -l ...@@ -195,8 +196,8 @@ LD_LIBRARY_PATH=. taste-gui -l
dstr = array_content(def_value, dstr, varbty) dstr = array_content(def_value, dstr, varbty)
assert not dst and not dlocal, 'DCL: Expecting a ground expression' assert not dst and not dlocal, 'DCL: Expecting a ground expression'
process_level_decl.append( process_level_decl.append(
u'l_{n} : aliased {sort}{default};' u'{prefix}{n} : aliased {sort}{default};'
.format(n=var_name, .format(prefix=LPREFIX, n=var_name,
sort=type_name(var_type), sort=type_name(var_type),
default=u' := ' + dstr if def_value else u'')) default=u' := ' + dstr if def_value else u''))
...@@ -285,16 +286,16 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -285,16 +286,16 @@ package {process_name} is'''.format(process_name=process_name,
for var_name, (var_type, _) in process.variables.viewitems(): for var_name, (var_type, _) in process.variables.viewitems():
# Getters for local variables # Getters for local variables
process_level_decl.append("function l_{name}_size return integer " process_level_decl.append("function l_{name}_size return integer "
"is (l_{name}'Size/8) with Export, " "is ({prefix}{name}'Size/8) with Export,"
"Convention => C, " " Convention => C,"
'Link_Name => "{name}_size";' ' Link_Name => "{name}_size";'
.format(name=var_name)) .format(prefix=LPREFIX, name=var_name))
process_level_decl.append("function l_{name}_value" process_level_decl.append("function l_{name}_value"
" return access {sort} " " return access {sort} "
"is (l_{name}'access) with Export, " "is ({prefix}{name}'access) with Export,"
"Convention => C, " " Convention => C,"
'Link_Name => "{name}_value";' ' Link_Name => "{name}_value";'
.format(name=var_name, .format(prefix=LPREFIX, name=var_name,
sort=type_name(var_type))) sort=type_name(var_type)))
# Setters for local variables # Setters for local variables
setter_decl = "procedure dll_set_l_{name}(value: access {sort})"\ setter_decl = "procedure dll_set_l_{name}(value: access {sort})"\
...@@ -304,7 +305,7 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -304,7 +305,7 @@ package {process_name} is'''.format(process_name=process_name,
' "_set_{name}");'.format(name=var_name)) ' "_set_{name}");'.format(name=var_name))
dll_api.append('{} is'.format(setter_decl)) dll_api.append('{} is'.format(setter_decl))
dll_api.append('begin') dll_api.append('begin')
dll_api.append('l_{} := value.all;'.format(var_name)) dll_api.append('{}{} := value.all;'.format(LPREFIX, var_name))
dll_api.append('end dll_set_l_{};'.format(var_name)) dll_api.append('end dll_set_l_{};'.format(var_name))
dll_api.append('') dll_api.append('')
...@@ -386,8 +387,10 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -386,8 +387,10 @@ package {process_name} is'''.format(process_name=process_name,
for inp in input_def.parameters: for inp in input_def.parameters:
# Assign the (optional and unique) parameter # Assign the (optional and unique) parameter
# to the corresponding process variable # to the corresponding process variable
taste_template.append(u'l_{inp} := {tInp}.all;'.format( taste_template.append(u'{pre}{inp} := {tInp}.all;'
inp=inp, tInp=param_name)) .format(pre=LPREFIX,
inp=inp,
tInp=param_name))
# Execute the correponding transition # Execute the correponding transition
if input_def.transition: if input_def.transition:
taste_template.append(u'runTransition({idx});'.format( taste_template.append(u'runTransition({idx});'.format(
...@@ -399,8 +402,7 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -399,8 +402,7 @@ package {process_name} is'''.format(process_name=process_name,
taste_template.append('when others =>') taste_template.append('when others =>')
taste_template.append('null;') taste_template.append('null;')
taste_template.append('end case;') taste_template.append('end case;')
taste_template.append(u'end {sig_name};'.format( taste_template.append(u'end {};'.format(signal['name']))
sig_name=signal['name']))
taste_template.append('\n') taste_template.append('\n')
# for the .ads file, generate the declaration of the required interfaces # for the .ads file, generate the declaration of the required interfaces
...@@ -766,7 +768,7 @@ def _call_external_function(output, **kwargs): ...@@ -766,7 +768,7 @@ def _call_external_function(output, **kwargs):
# (If needed, i.e. if argument is not a local variable) # (If needed, i.e. if argument is not a local variable)
if param_direction == 'in' \ if param_direction == 'in' \
and (not (isinstance(param, ogAST.PrimVariable) and (not (isinstance(param, ogAST.PrimVariable)
and p_id.startswith('l_')) and p_id.startswith(LPREFIX))
or isinstance(param, ogAST.PrimFPAR)): or isinstance(param, ogAST.PrimFPAR)):
tmp_id = 'tmp{}'.format(out['tmpVars'][idx]) tmp_id = 'tmp{}'.format(out['tmpVars'][idx])
local_decl.append('{tmp} : aliased {sort};' local_decl.append('{tmp} : aliased {sort};'
...@@ -939,7 +941,7 @@ def expression(expr): ...@@ -939,7 +941,7 @@ def expression(expr):
@expression.register(ogAST.PrimVariable) @expression.register(ogAST.PrimVariable)
def _primary_variable(prim): def _primary_variable(prim):
''' Single variable reference ''' ''' Single variable reference '''
sep = u'l_' if find_var(prim.value[0]) else u'' sep = LPREFIX if find_var(prim.value[0]) else u''
ada_string = u'{sep}{name}'.format(sep=sep, name=prim.value[0]) ada_string = u'{sep}{name}'.format(sep=sep, name=prim.value[0])
...@@ -1904,8 +1906,8 @@ def _inner_procedure(proc, **kwargs): ...@@ -1904,8 +1906,8 @@ def _inner_procedure(proc, **kwargs):
params = [] params = []
for fpar in proc.fpar: for fpar in proc.fpar:
typename = type_name(fpar['type']) typename = type_name(fpar['type'])
params.append(u'l_{name}: in{out} {ptype}'.format( params.append(u'{prefix}{name}: in{out} {ptype}'.format(
name=fpar.get('name'), name=fpar.get('name'), prefix=LPREFIX,
out=' out' if fpar.get('direction') == 'out' else '', out=' out' if fpar.get('direction') == 'out' else '',
ptype=typename)) ptype=typename))
pi_header += ';'.join(params) pi_header += ';'.join(params)
...@@ -1939,8 +1941,8 @@ def _inner_procedure(proc, **kwargs): ...@@ -1939,8 +1941,8 @@ def _inner_procedure(proc, **kwargs):
if varbty.kind in ('SequenceOfType', 'OctetStringType'): if varbty.kind in ('SequenceOfType', 'OctetStringType'):
dstr = array_content(def_value, dstr, varbty) dstr = array_content(def_value, dstr, varbty)
assert not dst and not dlocal, 'Ground expression error' assert not dst and not dlocal, 'Ground expression error'
code.append(u'l_{name} : aliased {sort}{default};' code.append(u'{prefix}{name} : aliased {sort}{default};'
.format(name=var_name, .format(name=var_name, prefix=LPREFIX,
sort=typename, sort=typename,
default=' := ' + dstr if def_value else '')) default=' := ' + dstr if def_value else ''))
......
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