Search in sources :

Example 1 with TemporalReference

use of org.eclipse.titan.designer.AST.TemporalReference in project titan.EclipsePlug-ins by eclipse.

the class Assignment_Statement method checkVarAssignment.

private void checkVarAssignment(final CompilationTimeStamp timestamp, final Assignment assignment, final IValue value) {
    final IType varType = getType(timestamp, assignment);
    if (varType == null || value == null) {
        isErroneous = true;
        return;
    }
    final IType type = varType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (type == null) {
        isErroneous = true;
        return;
    }
    value.setMyGovernor(type);
    IValue lastValue = type.checkThisValueRef(timestamp, value);
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    lastValue = lastValue.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (Value_type.OMIT_VALUE.equals(lastValue.getValuetype())) {
        final ISubReference lastReference = reference.removeLastSubReference();
        if (lastReference == null || lastReference.getId() == null) {
            value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
            isErroneous = true;
            reference.addSubReference(lastReference);
            return;
        }
        final Identifier lastField = lastReference.getId();
        final List<ISubReference> baseReference = reference.getSubreferences(0, reference.getSubreferences().size() - 1);
        reference.addSubReference(lastReference);
        final Reference newReference = new TemporalReference(null, baseReference);
        newReference.clearStringElementReferencing();
        IType baseType = varType.getFieldType(timestamp, newReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
        if (baseType == null) {
            isErroneous = true;
            return;
        }
        baseType = baseType.getTypeRefdLast(timestamp);
        if (baseType.getIsErroneous(timestamp)) {
            isErroneous = true;
            return;
        }
        CompField componentField;
        switch(baseType.getTypetype()) {
            case TYPE_TTCN3_SEQUENCE:
                componentField = ((TTCN3_Sequence_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SEQUENCE:
                componentField = ((ASN1_Sequence_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_TTCN3_SET:
                componentField = ((TTCN3_Set_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SET:
                componentField = ((ASN1_Set_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            default:
                // TODO:check this!!!
                value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
                value.setIsErroneous(true);
                isErroneous = true;
                break;
        }
    } else {
        final boolean isStringElement = reference.refersToStringElement();
        selfReference = type.checkThisValue(timestamp, value, assignment, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, !isStringElement, false, isStringElement));
        if (isStringElement) {
            // The length of the right hand side should be 1
            final IType lastType = type.getTypeRefdLast(timestamp);
            int stringLength = 1;
            switch(lastType.getTypetype()) {
                case TYPE_BITSTRING:
                case TYPE_BITSTRING_A:
                    if (!Value_type.BITSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Bitstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_HEXSTRING:
                    if (!Value_type.HEXSTRING_VALUE.equals(lastValue.getValuetype())) {
                        lastValue = null;
                    } else {
                        stringLength = ((Hexstring_Value) lastValue).getValueLength();
                    }
                    break;
                case TYPE_OCTETSTRING:
                    if (!Value_type.OCTETSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Octetstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_CHARSTRING:
                case TYPE_NUMERICSTRING:
                case TYPE_PRINTABLESTRING:
                case TYPE_IA5STRING:
                case TYPE_VISIBLESTRING:
                case TYPE_UTCTIME:
                case TYPE_GENERALIZEDTIME:
                    if (!Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Charstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_UCHARSTRING:
                case TYPE_UTF8STRING:
                case TYPE_TELETEXSTRING:
                case TYPE_VIDEOTEXSTRING:
                case TYPE_GRAPHICSTRING:
                case TYPE_GENERALSTRING:
                case TYPE_UNIVERSALSTRING:
                case TYPE_BMPSTRING:
                case TYPE_OBJECTDESCRIPTOR:
                    if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((UniversalCharstring_Value) lastValue).getValueLength();
                    } else if (Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((Charstring_Value) lastValue).getValueLength();
                    } else {
                        return;
                    }
                    break;
                default:
                    lastValue = null;
                    return;
            }
            if (stringLength != 1) {
                final String message = MessageFormat.format("The length of the string to be assigned to a string element of type `{0}'' should be 1 instead of {1}", type.getTypename(), stringLength);
                value.getLocation().reportSemanticError(message);
                value.setIsErroneous(true);
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) IType(org.eclipse.titan.designer.AST.IType) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Aggregations

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 IType (org.eclipse.titan.designer.AST.IType)1 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)1 IValue (org.eclipse.titan.designer.AST.IValue)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 Reference (org.eclipse.titan.designer.AST.Reference)1 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)1 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)1 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)1 TemporalReference (org.eclipse.titan.designer.AST.TemporalReference)1