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

Fix issue with the "present" operator

parent c407f7fb
......@@ -175,6 +175,9 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
**3.2.1 (07/2020)**
- Fix issue with the "present" operator
**3.2.0 (07/2020)**
- Add basic support for state type/instance
......
......@@ -703,6 +703,9 @@ def check_call(name, params, context):
# check that the list of enumerants are identical. unfortunately we
# cannot check the ordering, as it is an unordered dict
if name == 'to_selector':
# if the sort is a subtype, it may not have a -selection suffix
# and an exception may be raised. FIXME : check "present" operator
# as the issue is already fixed there
return_type = types()[sort + '-selection'].type
else:
return_type = types()[sort].type
......@@ -828,8 +831,21 @@ def check_call(name, params, context):
elif name == 'present':
p, = params
sort = type_name (p.exprType) + "-selection"
return types()[sort].type
# When we get there, the parameter has been checked already and we
# know it is a CHOICE type.
# However it may be a subtype, and in the AST the choices are defined
# in the supertype, so we must find it and and the -selection suffix
# This suffix is added by the Asn1scc module.
sort = p.exprType
sort_name = type_name (sort)
try:
while sort.kind == "ReferenceType":
sort_name = sort.ReferencedTypeName
sort = types()[sort.ReferencedTypeName].type
except AttributeError:
# Native choice types don't have the kind field here
pass
return types()[sort_name + "-selection"].type
# choice_to_int: returns an integer corresponding to either the currently
# selected choice value (e.g. foo in CHOICE { foo INTEGER (..), ... } when
......@@ -3862,9 +3878,8 @@ def state(root, parent, context):
# Extract the complete string "state: instance"
start = inst_stop
stop = child.getTokenStopIndex()
full_string = token_stream(root).toString(start, stop)
state_def.inputString, state_def.instance_of = \
full_string, state_def.instance_of
state_def.inputString = token_stream(root).toString(start, stop)
state_def.instance_of = child.getChild(0).toString()
elif child.type == lexer.STATELIST:
# State name(state_def)
state_def.inputString = get_input_string(child)
......@@ -3912,7 +3927,12 @@ def state(root, parent, context):
'in substate "{}"'
.format(each, comp.statename.lower()))
try:
for statename in state_def.statelist:
# Use the statelist unless the state is an instance
if not state_def.instance_of:
statelist = state_def.statelist
else:
statelist = [state_def.instance_of]
for statename in statelist:
# check that input is not already defined
existing = context.mapping.get(statename.lower(), [])
dupl = set()
......@@ -3928,7 +3948,10 @@ def state(root, parent, context):
# then update the mapping state-input
context.mapping[statename.lower()].append(inp)
except KeyError as err:
stwarn.append(f'State definition missing - {str(err)}')
# missing state definition is caught at other places, no
# need to report here
pass
#stwarn.append(f'State definition missing - {str(err)}')
state_def.inputs.append(inp)
if inp.inputString.strip() == '*':
if asterisk_input:
......@@ -5453,6 +5476,18 @@ def parse_pr(files=None, string=None):
[t_x, t_y],
['PROCESS {}'.format(process.processName)]])
# TODO: do the same with JOIN/LABEL
# Check that all floating state instances (foo:bar) have a correspoding
# nested state defined.
state_types = set(st.instance_of.lower()
for st in process.content.states if st.instance_of)
comp_states = set(comp.statename.lower()
for comp in process.composite_states)
for missing in state_types - comp_states:
errors.append([f'Nested state definition missing : {missing}',
[0, 0],
['PROCESS {}'.format(process.processName)]])
return og_ast, warnings, errors
......
......@@ -140,7 +140,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '3.2.0'
__version__ = '3.2.1'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......@@ -2323,14 +2323,21 @@ clean:
pr_raw = Pr.parse_scene(scene, full_model=True
if not self.readonly_pr else False)
pr_data = str('\n'.join(pr_raw))
if pr_data:
ast, warnings, errors = ogParser.parse_pr(files=self.readonly_pr,
string=pr_data)
scene.semantic_errors = True if errors else False
log_errors(self.messages_window, errors, warnings,
clearfirst=False)
self.update_asn1_dock.emit(ast)
return "Done"
try:
if pr_data:
ast, warnings, errors = ogParser.parse_pr(
files=self.readonly_pr,
string=pr_data)
scene.semantic_errors = True if errors else False
log_errors(self.messages_window, errors, warnings,
clearfirst=False)
self.update_asn1_dock.emit(ast)
return "Done"
except Exception as err:
self.messages_window.addItem("Opengeode bug, PLEASE REPORT: "
+ str(err))
LOG.debug(str(traceback.format_exc()))
return "Syntax Errors"
def show_item(self, item):
'''
......
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