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

Propose to check semantics when saving

parent ec42b0dd
......@@ -124,6 +124,7 @@ MODULES = [
# Define custom UserRoles
ANCHOR = Qt.UserRole + 1
try:
import LlvmGenerator
MODULES.append(LlvmGenerator)
......@@ -425,6 +426,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
# Keep a track of highlighted symbols: { symbol: brush }
self.highlighted = {}
self.refresh_requested = False
# Flag indicating the presence of unsolved semantic errors in the model
self.semantic_errors = False
def close(self):
''' close function is needed by py.test-qt '''
......@@ -1031,7 +1034,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
Optionally take a QGraphicsView to use as parent for modals '''
pr_raw = Pr.parse_scene(self)
pr_data = unicode('\n'.join(pr_raw))
ast, _, _ = ogParser.parse_pr(string=pr_data)
ast, _, err = ogParser.parse_pr(string=pr_data)
self.semantic_errors = True if err else False
try:
process_ast, = ast.processes
except ValueError:
......@@ -1815,7 +1819,7 @@ class SDL_View(QtGui.QGraphicsView, object):
try:
if item.allow_nesting:
item.double_click()
ctx = unicode(item.context_name) #__class__.__name__.lower())
ctx = unicode(item.context_name)
if not isinstance(item.nested_scene, SDL_Scene):
msg_box = QtGui.QMessageBox(self)
msg_box.setWindowTitle('Create nested symbol')
......@@ -1896,10 +1900,31 @@ class SDL_View(QtGui.QGraphicsView, object):
LOG.info('No scene - nothing to save')
return False
# check syntax and raise a big warning before saving
if not autosave:
self.messages_window.clear()
if not autosave and not scene.global_syntax_check():
# Propose to check semantics if the last check had errors
syntax_errors = None
if not autosave and (scene.semantic_errors
or not self.is_model_clean()):
msg_box = QtGui.QMessageBox(self)
msg_box.setIcon(QtGui.QMessageBox.Question)
msg_box.setWindowTitle('OpenGEODE - Check Semantics')
msg_box.setText("We recommend to make a semantic check of the "
"model now.\n\n"
"Choose Apply to perform this check "
"and Discard otherwise.")
msg_box.setStandardButtons(QtGui.QMessageBox.Apply
| QtGui.QMessageBox.Discard)
msg_box.setDefaultButton(QtGui.QMessageBox.Apply)
res = msg_box.exec_()
if res == QtGui.QMessageBox.Apply:
syntex_error = True if self.check_model() == "Syntax Errors" \
else False
# check syntax (if not done) and raise a big warning before saving
if syntax_errors is True or (syntax_errors is None
and not autosave
and not scene.global_syntax_check()):
LOG.error('Syntax errors must be fixed NOW '
'or you may not be able to reload the model')
msg_box = QtGui.QMessageBox(self)
......@@ -2079,22 +2104,24 @@ class SDL_View(QtGui.QGraphicsView, object):
self.messages_window.addItem("Checking syntax")
if not scene.global_syntax_check():
self.messages_window.addItem("Aborted. Fix syntax errors first")
return
return "Syntax Errors"
self.messages_window.addItem("No syntax errors")
self.messages_window.addItem("Checking semantics")
if scene.context not in ('process', 'state', 'procedure', 'block'):
# check can only be done on SDL diagrams
return
return "Non-SDL"
pr_raw = Pr.parse_scene(scene, full_model=True
if not self.readonly_pr else False)
pr_data = unicode('\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"
def show_item(self, item):
'''
......@@ -2165,6 +2192,7 @@ class SDL_View(QtGui.QGraphicsView, object):
if pr_data:
ast, warnings, errors = ogParser.parse_pr(files=self.readonly_pr,
string=pr_data)
scene.semantic_errors = True if errors else False
process, = ast.processes
log_errors(self.messages_window, errors, warnings)
if len(errors) > 0:
......
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