Commit aad72e28 authored by Adam Knapp's avatar Adam Knapp
Browse files

Lengthto semantic check update for bit- and octetstring (issue #419)


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent ae5cc26b
......@@ -937,19 +937,57 @@ public abstract class TTCN3_Set_Seq_Choice_BaseType extends Type implements ITyp
case TYPE_INTEGER:
case TYPE_INTEGER_A:
break;
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_OCTETSTRING:
if ((rawPar.fieldlength < 1 && fieldTypeLast.getSubtype() == null) ||
(rawPar.fieldlength < 1 && fieldTypeLast.getSubtype().get_length_restriction() < 1)) {
fieldId.getLocation().reportSemanticError("The length of this field must be specified either with `length()` subtyping or with the `FIELDLENGTH` attribute");
}
break;
case TYPE_TTCN3_CHOICE:
for (int fi = 0; fi < ((TTCN3_Choice_Type)fieldTypeLast).getNofComponents(); fi++) {
final Type_type tt = ((TTCN3_Choice_Type)fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
final Type compType = ((TTCN3_Choice_Type)fieldTypeLast).getComponentByIndex(fi).getType();
final Identifier compFiledId = ((TTCN3_Choice_Type)fieldTypeLast).getComponentByIndex(fi).getIdentifier();
switch (compType.getTypetype()) {
case TYPE_INTEGER:
case TYPE_INTEGER_A:
break;
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_OCTETSTRING:
if ((compType.rawAttribute == null && compType.getSubtype() == null) ||
(compType.rawAttribute.fieldlength < 1 && compType.getSubtype() == null) ||
(compType.rawAttribute == null && compType.getSubtype().get_length_restriction() < 1) ||
(compType.rawAttribute.fieldlength < 1 && compType.getSubtype().get_length_restriction() < 1)) {
compFiledId.getLocation().reportSemanticError("The length of this field must be specified either with `length()` subtyping or with the `FIELDLENGTH` attribute");
}
break;
default:
compFiledId.getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer, bitstring or octetstring fields");
break;
}
}
break;
case TYPE_ASN1_CHOICE:
for (int fi = 0; fi < ((ASN1_Choice_Type)fieldTypeLast).getNofComponents(); fi++) {
final Type_type tt = ((ASN1_Choice_Type)fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
final Type compType = ((ASN1_Choice_Type)fieldTypeLast).getComponentByIndex(fi).getType();
final Identifier compFiledId = ((TTCN3_Choice_Type)fieldTypeLast).getComponentByIndex(fi).getIdentifier();
switch (compType.getTypetype()) {
case TYPE_INTEGER:
case TYPE_INTEGER_A:
break;
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_OCTETSTRING:
if ((compType.rawAttribute.fieldlength < 1 && compType.getSubtype() == null) ||
(compType.rawAttribute.fieldlength < 1 && compType.getSubtype().get_length_restriction() < 1)) {
compFiledId.getLocation().reportSemanticError("The length of this field must be specified either with `length()` subtyping or with the `FIELDLENGTH` attribute");
}
break;
default:
compFiledId.getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer, bitstring or octetstring fields");
break;
}
}
break;
......@@ -964,7 +1002,8 @@ public abstract class TTCN3_Set_Seq_Choice_BaseType extends Type implements ITyp
break;
}
default:
getLocation().reportSemanticError(MessageFormat.format("The LENGTHTO field must be an integer or union type instead of `{0}''", fieldTypeLast.getTypename()));
fieldId.getLocation().reportSemanticError(MessageFormat.format("The LENGTHTO field must be an integer, bitstring, "
+ "octetstring or union type instead of `{0}''", fieldTypeLast.getTypename()));
break;
}
}
......
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