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

Add support for process FPAR in the grammar

parent cb9c88cd
...@@ -36,6 +36,7 @@ import genericSymbols ...@@ -36,6 +36,7 @@ import genericSymbols
import logging import logging
from itertools import chain from itertools import chain
from singledispatch import singledispatch from singledispatch import singledispatch
from ogParser import type_name
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
...@@ -150,6 +151,18 @@ def _automaton(ast, scene): ...@@ -150,6 +151,18 @@ def _automaton(ast, scene):
pass pass
else: else:
top_level_symbols.append(new_state) top_level_symbols.append(new_state)
# If the source .pr contained FPAR outside a textbox, create one
if ast.parent.fpar:
text_area = ogAST.TextArea()
fpars = ('{} {}'.format(fp['name'],
type_name(fp['type']).replace('-', '_'))
for fp in ast.parent.fpar)
text_area.inputString = ("-- Formal parameters\n"
"fpar {};".format(',\n '.join(fpars)))
text_area.pos_x = scene.itemsBoundingRect().x() - 200
text_area.pos_y = scene.itemsBoundingRect().y()
top_level_symbols.append(render(text_area, scene))
return top_level_symbols return top_level_symbols
......
...@@ -844,6 +844,10 @@ class Process(object): ...@@ -844,6 +844,10 @@ class Process(object):
# (Includes inner procedures) # (Includes inner procedures)
self.content = Automaton(parent=self) self.content = Automaton(parent=self)
# Process formal parameters - list of dict:
# [{'name': str, 'type': str}]
self.fpar = []
# List of timers (strings) declared in the process # List of timers (strings) declared in the process
self.timers = [] self.timers = []
......
...@@ -1052,7 +1052,7 @@ def is_fpar(name, context): ...@@ -1052,7 +1052,7 @@ def is_fpar(name, context):
name = name.lower() name = name.lower()
if isinstance(context, ogAST.Procedure): if isinstance(context, ogAST.Procedure):
for each in context.fpar: for each in context.fpar:
if each['name'].lower() == name: if each['name'].lower() == name.lower():
return True return True
return False return False
...@@ -2326,7 +2326,7 @@ def text_area_content(root, ta_ast, context): ...@@ -2326,7 +2326,7 @@ def text_area_content(root, ta_ast, context):
context.fpar = params context.fpar = params
ta_ast.fpar = params ta_ast.fpar = params
except AttributeError: except AttributeError:
errors.append('Only procedures can have an FPAR section') errors.append('Entity cannot have an FPAR section')
elif child.type == lexer.TIMER: elif child.type == lexer.TIMER:
timers = [timer.text.lower() for timer in child.children] timers = [timer.text.lower() for timer in child.children]
context.timers.extend(timers) context.timers.extend(timers)
...@@ -2524,7 +2524,7 @@ def system_definition(root, parent): ...@@ -2524,7 +2524,7 @@ def system_definition(root, parent):
textarea, err, warn = text_area(child, context=system) textarea, err, warn = text_area(child, context=system)
system.signals.extend(textarea.signals) system.signals.extend(textarea.signals)
if textarea.fpar: if textarea.fpar:
errors.append('FPAR shall be declared only in procedures') errors.append('FPAR cannot be declared at system level')
if textarea.timers: if textarea.timers:
errors.append('Timers shall be declared only in a process') errors.append('Timers shall be declared only in a process')
# Update list of ASN.1 files - if any # Update list of ASN.1 files - if any
...@@ -2624,6 +2624,12 @@ def process_definition(root, parent=None, context=None): ...@@ -2624,6 +2624,12 @@ def process_definition(root, parent=None, context=None):
elif child.type == lexer.NUMBER_OF_INSTANCES: elif child.type == lexer.NUMBER_OF_INSTANCES:
# Number of instances - discarded (working on a single process) # Number of instances - discarded (working on a single process)
pass pass
elif child.type == lexer.PFPAR:
# Process formal parameters
params, err, warn = fpar(child)
errors.extend(err)
warnings.extend(warn)
process.fpar = params
elif child.type == lexer.PROCEDURE: elif child.type == lexer.PROCEDURE:
proc, content, err, warn = procedure_pre( proc, content, err, warn = procedure_pre(
child, parent=None, context=process) child, parent=None, context=process)
......
...@@ -58,6 +58,7 @@ tokens { ...@@ -58,6 +58,7 @@ tokens {
FLOATING_LABEL; FLOATING_LABEL;
FOR; FOR;
FPAR; FPAR;
PFPAR;
GROUND; GROUND;
HYPERLINK; HYPERLINK;
IF; IF;
...@@ -220,12 +221,24 @@ process_definition ...@@ -220,12 +221,24 @@ process_definition
: PROCESS process_id number_of_instances? REFERENCED end : PROCESS process_id number_of_instances? REFERENCED end
-> ^(PROCESS process_id number_of_instances? REFERENCED) -> ^(PROCESS process_id number_of_instances? REFERENCED)
| cif? PROCESS process_id number_of_instances? end | cif? PROCESS process_id number_of_instances? end
pfpar?
(text_area | procedure | composite_state)* (text_area | procedure | composite_state)*
processBody? ENDPROCESS process_id? processBody? ENDPROCESS process_id?
end end
-> ^(PROCESS cif? process_id number_of_instances? end? -> ^(PROCESS cif? process_id number_of_instances? end? pfpar?
text_area* procedure* composite_state* processBody?); text_area* procedure* composite_state* processBody?);
// Process formal parameters
pfpar
: FPAR parameters_of_sort
(',' parameters_of_sort)*
end
-> ^(PFPAR parameters_of_sort+);
parameters_of_sort
: variable_id (',' variable_id)* sort
-> ^(PARAM variable_id+ sort);
// procedure: missing the RETURNS statement // procedure: missing the RETURNS statement
// (TODO - but check new SDL2000 syntax that has no RETURNS token) // (TODO - but check new SDL2000 syntax that has no RETURNS token)
......
Supports Markdown
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