Commit 2669a0e9 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Detect duplicate procedures

parent 44c9ff3d
...@@ -142,6 +142,9 @@ The background pattern was downloaded from www.subtlepatterns.com ...@@ -142,6 +142,9 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog Changelog
========= =========
1.5.12 (09/2016)
- Detect duplicate declaration of procedures
1.5.11 (09/2016) 1.5.11 (09/2016)
- Allow semicolon in the declaration of procedures after RETURNS keyword - Allow semicolon in the declaration of procedures after RETURNS keyword
......
...@@ -2026,8 +2026,15 @@ def composite_state(root, parent=None, context=None): ...@@ -2026,8 +2026,15 @@ def composite_state(root, parent=None, context=None):
comp.entry_procedure = new_proc comp.entry_procedure = new_proc
elif new_proc.inputString.strip().lower() == 'exit': elif new_proc.inputString.strip().lower() == 'exit':
comp.exit_procedure = new_proc comp.exit_procedure = new_proc
comp.content.inner_procedures.append(new_proc) # check for duplicate declaration
if any(each.inputString.lower() == new_proc.inputString.lower()
for each in chain(comp.content.inner_procedures,
context.procedures)):
errors.append(['Duplicate procedure Declaration: {}'
.format(new_proc.inputString),
[new_proc.pos_x, new_proc.pos_y], []])
# Add procedure to the context, to make it visible at scope level # Add procedure to the context, to make it visible at scope level
comp.content.inner_procedures.append(new_proc)
context.procedures.append(new_proc) context.procedures.append(new_proc)
elif child.type in (lexer.COMPOSITE_STATE, lexer.STATE_AGGREGATION): elif child.type in (lexer.COMPOSITE_STATE, lexer.STATE_AGGREGATION):
inner_composite.append(child) inner_composite.append(child)
...@@ -2202,9 +2209,17 @@ def procedure_post(proc, content, parent=None, context=None): ...@@ -2202,9 +2209,17 @@ def procedure_post(proc, content, parent=None, context=None):
inner_proc.append((new_proc, content)) inner_proc.append((new_proc, content))
errors.extend(err) errors.extend(err)
warnings.extend(warn) warnings.extend(warn)
proc.content.inner_procedures.append(new_proc) # check for duplicate declaration
err = any(each.inputString.lower() == new_proc.inputString.lower()
for each in chain(proc.content.inner_procedures,
context.procedures))
# Add procedure to the context, to make it visible at scope level # Add procedure to the context, to make it visible at scope level
context.procedures.append(new_proc) context.procedures.append(new_proc)
proc.content.inner_procedures.append(new_proc)
if err:
errors.append(['Duplicate declaration of procedure {}'
.format(new_proc.inputString),
[0, 0], []])
elif child.type == lexer.START: elif child.type == lexer.START:
# START transition (fills the mapping structure) # START transition (fills the mapping structure)
proc.content.start, err, warn = start(child, context=proc) proc.content.start, err, warn = start(child, context=proc)
...@@ -2527,11 +2542,18 @@ def text_area_content(root, ta_ast, context): ...@@ -2527,11 +2542,18 @@ def text_area_content(root, ta_ast, context):
errors.extend(err) errors.extend(err)
warnings.extend(warn) warnings.extend(warn)
try: try:
# Add procedure to the container (process or procedure) content = context.content.inner_procedures
context.content.inner_procedures.append(proc)
except AttributeError: except AttributeError:
# May not be any content in current context (eg System) # May not be any content in current context (eg System)
pass content = []
# check for duplicates
if any(each.inputString.lower() == proc.inputString.lower()
for each in chain(content, context.procedures)):
errors.append('Duplicate Procedure Declaration: {}'
.format(proc.inputString))
# Add procedure to the container (process or procedure) if any
content.append(proc)
# Add to context to make it visible at scope level # Add to context to make it visible at scope level
context.procedures.append(proc) context.procedures.append(proc)
# And add it to the TextArea AST for the text autocompletion # And add it to the TextArea AST for the text autocompletion
...@@ -2809,8 +2831,15 @@ def process_definition(root, parent=None, context=None): ...@@ -2809,8 +2831,15 @@ def process_definition(root, parent=None, context=None):
inner_proc.append((proc, content)) inner_proc.append((proc, content))
errors.extend(err) errors.extend(err)
warnings.extend(warn) warnings.extend(warn)
process.content.inner_procedures.append(proc) # check for duplicate declaration
if any(each.inputString.lower() == proc.inputString.lower()
for each in chain(process.content.inner_procedures,
process.procedures)):
errors.append(['Duplicate Procedure declaration: {}'
.format(proc.inputString),
[proc.pos_x, proc.pos_y], []])
# Add it at process level so that it is in the scope # Add it at process level so that it is in the scope
process.content.inner_procedures.append(proc)
process.procedures.append(proc) process.procedures.append(proc)
elif child.type == lexer.FLOATING_LABEL: elif child.type == lexer.FLOATING_LABEL:
lab, err, warn = floating_label( lab, err, warn = floating_label(
......
...@@ -1300,15 +1300,17 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -1300,15 +1300,17 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
# TODO check if symbol can have more than # TODO check if symbol can have more than
# one connection if there is already one, if start # one connection if there is already one, if start
# and end can be on the same symbol, etc. # and end can be on the same symbol, etc.
self.mode = 'wait_next_connection_point' # DISABLE CONNECTIONS FOR NOW
click_point = event.scenePos() pass
point = self.border_point(symb, click_point) # self.mode = 'wait_next_connection_point'
self.edge_points = [point] # click_point = event.scenePos()
self.temp_lines.append(self.addLine(point.x(), # point = self.border_point(symb, click_point)
point.y(), # self.edge_points = [point]
click_point.x(), # self.temp_lines.append(self.addLine(point.x(),
click_point.y())) # point.y(),
self.connection_start = symb # click_point.x(),
# click_point.y()))
# self.connection_start = symb
elif self.mode == 'wait_placement': elif self.mode == 'wait_placement':
try: try:
......
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