Commit 8d030c7b authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix case sensitivity check in enumerations

parent 41299ab0
......@@ -627,10 +627,11 @@ def check_type_compatibility(primary, type_ref, context):
# If type ref is an enumeration, check that the value is valid
# Note, when using the "present" operator of a CHOICE type, the
# resulting value is actually an EnumeratedType
enumerant = primary.inputString.replace('_', '-')
corr_type = basic_type.EnumValues.get(enumerant)
if corr_type:
return
enumerant = primary.inputString.replace('_', '-').lower()
for each in basic_type.EnumValues.keys():
if each.lower() == enumerant:
# Found -> all OK
return
else:
err = ('Value "' + primary.inputString +
'" not in this enumeration: ' +
......@@ -3110,8 +3111,7 @@ def alternative_part(root, parent, context):
ans.closedRange = [cl0, cl1]
elif child.type == lexer.CONSTANT:
ans.kind = 'constant'
ans.constant, err, warn = expression(
child.getChild(0), context)
ans.constant, err, warn = expression(child.getChild(0), context)
errors.extend(err)
warnings.extend(warn)
ans.openRangeOp = ogAST.ExprEq
......@@ -3287,7 +3287,8 @@ def decision(root, parent, context):
ans.inputString),
[ans_x, ans_y], []])
else:
warnings.append('Unsupported range expression')
warnings.append(['Unsupported range expression',
[ans_x, ans_y], []])
if not reachable:
warnings.append(['Decision "{}": '
'Unreachable branch "{}"'
......@@ -3414,14 +3415,18 @@ def decision(root, parent, context):
# (5) check coverage of enumerated types
if is_enum:
# check duplicate answers
answers = list(chain.from_iterable(covered_ranges.viewvalues()))
answers = [a.lower()
for a in chain.from_iterable(covered_ranges.viewvalues())]
dupl = [a for a, v in Counter(answers).items() if v > 1]
if dupl:
qerr.append('Decision "{}": duplicate answers "{}"'
.format(dec.inputString, '", "'.join(dupl)))
enumerants = [en.replace('-', '_') for en in q_basic.EnumValues.keys()]
enumerants = [en.replace('-', '_').lower()
for en in q_basic.EnumValues.keys()]
# check for missing answers
if set(answers) != set(enumerants) and not has_else:
print set(answers)
print set(enumerants)
qerr.append('Decision "{}": Missing branches for answer(s) "{}"'
.format(dec.inputString,
'", "'.join(set(enumerants) - set(answers))))
......
......@@ -861,7 +861,7 @@ class ASN1Viewer(TextSymbol):
blackbold = ['\\b{}\\b'.format(word) for word in (
'DEFINITIONS', 'AUTOMATIC', 'TAGS', 'BEGIN', 'END', 'INTEGER',
'OCTET', 'STRING', 'BIT', 'REAL', 'SEQUENCE', 'OF', 'WITH',
'IMPORTS', 'FROM', 'SIZE', 'CHOICE', 'BOOLEAN')]
'IMPORTS', 'FROM', 'SIZE', 'CHOICE', 'BOOLEAN', 'ENUMERATED')]
# pylint: disable=R0904
......
......@@ -13,7 +13,8 @@ SeqBoolFix ::= SEQUENCE (SIZE(2)) OF BOOLEAN
SeqEnum ::= SEQUENCE (SIZE(1..5)) OF ENUMERATED { hello, world }
SeqEnumFix ::= SEQUENCE (SIZE(2)) OF ENUMERATED { hello, world }
Enum ::= ENUMERATED {a, b, c, d}
Enum ::= ENUMERATED {a, b, c, d, eE}
Choice ::= CHOICE {c1 BOOLEAN, cDe2 BOOLEAN}
END
......
......@@ -2,7 +2,7 @@
PROCESS orchestrator
/* CIF COMMENT (405, 192), (71, 35) */
COMMENT 'Hello';
/* CIF TEXT (39, 94), (293, 233) */
/* CIF TEXT (39, 94), (293, 263) */
dcl seq tastE_Peek_id_list;
dcl fixed FixedString := 'Hello';
......@@ -18,6 +18,8 @@ dcl seqen2 SeqEnumFix := { hello, world };
dcl myenum Enum := a;
dcl check tasTE_Peek_id;
dcl choice choice;
/* CIF ENDTEXT */
/* CIF START (428, 223), (100, 45) */
START;
......@@ -67,7 +69,31 @@ endfor;
/* CIF ANSWER (488, 1081), (70, 23) */
('b'):
ENDDECISION;
/* CIF NEXTSTATE (419, 1119), (118, 50) */
/* CIF DECISION (433, 1119), (89, 50) */
DECISION myenum
/* CIF COMMENT (542, 1126), (183, 35) */
COMMENT 'Check case insensitivity';
/* CIF ANSWER (250, 1189), (70, 23) */
(a):
/* CIF ANSWER (330, 1189), (70, 23) */
(B):
/* CIF ANSWER (410, 1189), (70, 23) */
(c):
/* CIF ANSWER (488, 1189), (70, 23) */
(d):
/* CIF ANSWER (576, 1189), (70, 23) */
(Ee):
ENDDECISION;
/* CIF DECISION (408, 1227), (138, 50) */
DECISION present(choice)
/* CIF COMMENT (566, 1234), (183, 35) */
COMMENT 'Check case insensitivity';
/* CIF ANSWER (361, 1297), (70, 23) */
(cde2):
/* CIF ANSWER (532, 1297), (70, 23) */
ELSE:
ENDDECISION;
/* CIF NEXTSTATE (419, 1335), (116, 33) */
NEXTSTATE Wait_for_GUI;
/* CIF STATE (423, 163), (118, 50) */
STATE Wait_for_GUI;
......
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