Commit 9d05f204 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Start working on Append constructs

parent 6e273ea2
......@@ -666,7 +666,7 @@ def check_type_compatibility(primary, type_ref, context): # type: -> [warnings]
'''
Check if an ogAST.Primary (raw value, enumerated, ASN.1 Value...)
is compatible with a given type (type_ref is an ASN1Scc type)
Does not return anything if OK, otherwise raises TypeError
Possibly returns a list of warnings; can raises TypeError
'''
warnings = [] # function returns a list of warnings
assert type_ref is not None
......@@ -749,9 +749,10 @@ def check_type_compatibility(primary, type_ref, context): # type: -> [warnings]
if type_ref.__name__ != 'Apnd' and \
(len(primary.value) < int(basic_type.Min) or
len(primary.value) > int(basic_type.Max)):
#print traceback.print_stack()
raise TypeError(str(len(primary.value)) +
' elements in SEQUENCE OF, while constraint is [' +
str(basic_type.Min) + '..' + str(basic_type.Max) + ']')
' element(s) in SEQUENCE OF, while constraint is [' +
str(basic_type.Min) + ' .. ' + str(basic_type.Max) + ']')
for elem in primary.value:
warnings.extend(check_type_compatibility(elem,
basic_type.type,
......@@ -1039,7 +1040,7 @@ def fix_expression_types(expr, context): # type: -> [warnings]
# the type of the raw PrimSequenceOf can be set now
value.exprType.type = asn_type
if isinstance(expr, ogAST.ExprIn):
if isinstance(expr, (ogAST.ExprIn, ogAST.ExprAppend)):
return warnings
if not expr.right.is_raw and not expr.left.is_raw:
......@@ -1438,6 +1439,13 @@ def append_expression(root, context):
left = find_basic_type(expr.left.exprType)
right = find_basic_type(expr.right.exprType)
# check that the appended value is of the right type
# TODO : need a complete analysis just like the in_expression above
# try:
# warnings.extend(compare_types(expr.right.exprType, ref_type))
# except TypeError as err:
# errors.append(error(root, str(err)))
for bty in (left, right):
if bty.kind != 'SequenceOfType' and not is_string(bty):
msg = 'Append can only be applied to types SequenceOf or String'
......
TASTE-Dataview DEFINITIONS ::=
BEGIN
MySeqOf ::= SEQUENCE (SIZE (1..10)) OF BOOLEAN
MySeqOf ::= SEQUENCE (SIZE (3..10)) OF BOOLEAN
MyBoolean ::= BOOLEAN
......
......@@ -20,11 +20,11 @@ system test;
/* CIF ENDTEXT */
/* CIF START (198, 56), (70, 35) */
START;
/* CIF task (133, 111), (199, 35) */
/* CIF task (132, 111), (201, 35) */
task s2 := { true, true, false, true };
/* CIF PROCEDURECALL (157, 161), (152, 35) */
call writeln ( length (s1) )
/* CIF comment (329, 161), (188, 35) */
/* CIF comment (329, 161), (189, 35) */
comment 'Uninitialized => will return 0';
/* CIF task (183, 216), (99, 35) */
task s1 := s2 (1,3)
......@@ -33,7 +33,7 @@ system test;
s1 (1, 3) := { true, false, true} provokes a bug';
/* CIF PROCEDURECALL (157, 271), (152, 35) */
call writeln ( length (s1) );
/* CIF task (170, 326), (126, 35) */
/* CIF task (149, 326), (167, 35) */
task s1 := s1 // { false };
/* CIF PROCEDURECALL (157, 381), (152, 35) */
call writeln ( length (s1) );
......
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