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

Detect more type incompatibilities

parent 70b4452e
......@@ -146,6 +146,8 @@ Changelog
- Bugfix - Ada backend failed when there were continuous signals in
nested states but none at root level (missing end if)
- Load fix when there is no dataview
- Additional type checks
1.5.7 (09/2016)
- Bugfix - Update completion list of process symbol
- Sort ASN.1 types in data dictionary
......
......@@ -525,6 +525,11 @@ def check_call(name, params, context):
received = type_name(expr.right.exprType)
raise TypeError('Expected type {} in call to {} ({} received)'.
format(expected, name, received))
except Warning as warn:
expected = type_name(sign[idx]['type'])
received = type_name(expr.right.exprType)
raise Warning('Expected type {} in call to {} ({} received)'.
format(expected, name, received))
if sign[idx].get('direction') != 'in' \
and not isinstance(expr.right, ogAST.PrimVariable):
......@@ -774,8 +779,7 @@ def check_type_compatibility(primary, type_ref, context):
compare_types(
primary.value[casefield].exprType, fd_data.type)
except TypeError as err:
raise TypeError('Field ' + ufield +
' is not of the proper type, i.e. ' +
raise TypeError('Field "' + ufield + '" not of type ' +
type_name(fd_data.type) +
' - ' + str(err))
return
......@@ -857,7 +861,11 @@ def compare_types(type_a, type_b):
Compare two types, return if they are semantically equivalent,
otherwise raise TypeError
'''
mismatch = ''
if type_a.kind == 'ReferenceType' and type_b.kind == 'ReferenceType':
if type_a.ReferencedTypeName != type_b.ReferencedTypeName:
mismatch = '"{}" is not "{}"'.format(type_a.ReferencedTypeName,
type_b.ReferencedTypeName)
type_a = find_basic_type(type_a)
type_b = find_basic_type(type_b)
......@@ -893,20 +901,30 @@ def compare_types(type_a, type_b):
compare_types(type_a.type, type_b.type)
raise Warning('Size constraints mismatch - risk of overflow')
# TODO: Check that OctetString types have compatible range
return
elif type_a.kind == 'SequenceType' and mismatch:
raise TypeError(mismatch)
elif mismatch:
raise Warning(mismatch)
else:
return
elif is_string(type_a) and is_string(type_b):
return
elif is_integer(type_a) and is_integer(type_b):
return
if mismatch:
raise Warning(mismatch)
else:
return
elif is_real(type_a) and is_real(type_b):
return
if mismatch:
raise Warning(mismatch)
else:
return
else:
raise TypeError('Incompatible types {} and {}'.format(
type_name(type_a),
type_name(type_b)
))
def find_variable_type(var, context):
''' Look for a variable name in the context and return its type '''
......@@ -3360,6 +3378,8 @@ def outputbody(root, context):
LOG.debug('[outputbody] call check_and_fix_op_params : '
+ get_input_string(root) + str(op_err))
LOG.debug(str(traceback.format_exc()))
except Warning as warn:
warnings.append('{} - {}'.format(str(warn), get_input_string(root)))
if body['params']:
body['tmpVars'] = []
for _ in body['params']:
......@@ -3629,6 +3649,9 @@ def decision(root, parent, context):
expr.right.inputString + ', type= ' +
type_name(expr.right.exprType) + ') ' + str(err),
[ans_x, ans_y], []])
except Warning as warn:
warnings.append(['Type mismatch: ' + str(warn), [ans_x, ans_y],
[]])
elif ans.kind == 'closed_range':
if not is_numeric(dec.question.exprType):
errors.append(['Closed range are only for numerical types',
......
......@@ -9,10 +9,7 @@ test-parse:
$(OPENGEODE) og.pr --check
test-ada:
$(OPENGEODE) og.pr --toAda
$(ASN1SCC) -Ada dataview-uniq.asn -typePrefix asn1Scc -equal
$(GNATMAKE) -O$(O) -c *.adb
$(GNATBIND) -n og.ali
@echo 'Nothing to test - test-parse must retun errors'
test-c:
$(OPENGEODE) og.pr --toC
......
SYSTEM NpalDsap;
/* CIF TEXT (57, 262), (445, 263) */
/* CIF TEXT (57, 40), (406, 38) */
-- the type checker must detect all type errors
-- the code generator must complain that there is no START symbol
/* CIF ENDTEXT */
/* CIF TEXT (40, 256), (304, 53) */
USE DataModel comment 'dataview-uniq.asn';
SIGNAL MyIn(TotoT1);
SIGNAL MyIn(TotoT1);
/* CIF ENDTEXT */
CHANNEL c
FROM ENV TO NpalDsap WITH MyIn;
......@@ -11,7 +15,7 @@ SYSTEM NpalDsap;
SIGNALROUTE r
FROM ENV TO NpalDsap WITH MyIn;
CONNECT c AND r;
/* CIF PROCESS (250, 150), (150, 75) */
/* CIF PROCESS (202, 149), (150, 75) */
PROCESS NpalDsap;
/* CIF TEXT (0, 0), (380, 156) */
dcl test1 TotoT1;
......@@ -20,15 +24,15 @@ dcl test2 TotoT2;
dcl toto TotoT1;
/* CIF ENDTEXT */
/* CIF STATE (414, 17), (83, 35) */
/* CIF STATE (497, 17), (83, 35) */
STATE TestState;
/* CIF INPUT (409, 72), (92, 35) */
INPUT MyIn(test1);
/* CIF TASK (391, 127), (127, 35) */
/* CIF PROVIDED (510, 72), (58, 23) */
PROVIDED TRUE;
/* CIF TASK (476, 115), (127, 35) */
TASK test1 := { a toto };
/* CIF TASK (389, 182), (131, 35) */
/* CIF TASK (474, 170), (131, 35) */
TASK test1 := { a test2 };
/* CIF NEXTSTATE (420, 232), (70, 35) */
/* CIF NEXTSTATE (504, 225), (70, 35) */
NEXTSTATE -;
ENDSTATE;
ENDPROCESS NpalDsap;
......
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