Commit 6d7fdbaf authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Robustness in casse of syntax error

parent 6ca54a82
...@@ -47,6 +47,8 @@ class Expression(object): ...@@ -47,6 +47,8 @@ class Expression(object):
self.inputString = inputString self.inputString = inputString
self.line = line self.line = line
self.charPositionInLine = charPositionInLine self.charPositionInLine = charPositionInLine
# Binary expressions have two sides
self.right = self.left = None
# exprType is an ASN.1 type (as exported by asn1scc) # exprType is an ASN.1 type (as exported by asn1scc)
self.exprType = None self.exprType = None
......
...@@ -994,7 +994,7 @@ def expression_list(root, context): ...@@ -994,7 +994,7 @@ def expression_list(root, context):
def primary_variable(root, context): def primary_variable(root, context):
''' Primary Variable analysis ''' ''' Primary Variable analysis '''
name = root.children[0].text name = getattr(root.getChild(0), 'text', 'error')
errors, warnings = [], [] errors, warnings = [], []
if is_asn1constant(name): if is_asn1constant(name):
...@@ -1683,8 +1683,11 @@ def primary(root, context): ...@@ -1683,8 +1683,11 @@ def primary(root, context):
warnings.append( warnings.append(
warning(root, 'Octet string literal not supported yet')) warning(root, 'Octet string literal not supported yet'))
else: else:
# TODO: return error message errors.append('Parsing error (token {}, line {}, "{}")'
raise NotImplementedError .format(sdl92Parser.tokenNames[root.type],
root.getLine(),
get_input_string(root)))
prim = ogAST.Primary()
prim.inputString = get_input_string(root) prim.inputString = get_input_string(root)
prim.tmpVar = tmp() prim.tmpVar = tmp()
...@@ -3528,9 +3531,13 @@ def assign(root, context): ...@@ -3528,9 +3531,13 @@ def assign(root, context):
warnings.extend(warn) warnings.extend(warn)
errors.extend(err) errors.extend(err)
expr.right, err, warn = expression(root.children[1], context) try:
errors.extend(err) expr.right, err, warn = expression(root.children[1], context)
warnings.extend(warn) except NotImplementedError as nie:
errors.append(str(nie))
else:
errors.extend(err)
warnings.extend(warn)
try: try:
fix_expression_types(expr, context) fix_expression_types(expr, context)
...@@ -3539,20 +3546,25 @@ def assign(root, context): ...@@ -3539,20 +3546,25 @@ def assign(root, context):
if basic.kind.startswith(('Integer', 'Real')): if basic.kind.startswith(('Integer', 'Real')):
check_range(basic, find_basic_type(expr.right.exprType)) check_range(basic, find_basic_type(expr.right.exprType))
except(AttributeError, TypeError) as err: except(AttributeError, TypeError) as err:
errors.append('Type mismatch: left (' + errors.append(u'In "{exp}": Type mismatch ({lty} vs {rty} - {errstr})'
expr.left.inputString + ', type= ' + .format(exp=expr.inputString,
type_name(expr.left.exprType) + '), right (' + lty=type_name(expr.left.exprType) if
expr.right.inputString + ', type= ' + expr.left and expr.left.exprType
(type_name(expr.right.exprType) else 'Undefined',
if expr.right.exprType else 'Unknown') + ') ' + str(err)) rty=type_name(expr.right.exprType) if
expr.right and expr.right.exprType
else 'Undefined',
errstr=str(err)))
except Warning as warn: except Warning as warn:
warnings.append('Expression "{}": {}' warnings.append('Expression "{}": {}'
.format(expr.inputString, str(warn))) .format(expr.inputString, str(warn)))
if expr.right.exprType == UNKNOWN_TYPE or not \ else:
isinstance(expr.right, (ogAST.ExprAppend, # In "else" branch because in case of exception right side may be None
ogAST.PrimSequenceOf, if expr.right.exprType == UNKNOWN_TYPE or not \
ogAST.PrimStringLiteral)): isinstance(expr.right, (ogAST.ExprAppend,
expr.right.exprType = expr.left.exprType ogAST.PrimSequenceOf,
ogAST.PrimStringLiteral)):
expr.right.exprType = expr.left.exprType
return expr, errors, warnings return expr, errors, warnings
......
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