Search in sources :

Example 1 with TypeCompatibilityInfo

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

the class ASN1_Set_Type method isCompatible.

@Override
public /**
 * {@inheritDoc}
 */
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
    check(timestamp);
    otherType.check(timestamp);
    final IType temp = otherType.getTypeRefdLast(timestamp);
    if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
        return true;
    }
    if (info == null || noStructuredTypeCompatibility) {
        return this == temp;
    }
    switch(temp.getTypetype()) {
        case TYPE_ASN1_SET:
            {
                final ASN1_Set_Type tempType = (ASN1_Set_Type) temp;
                if (this == tempType) {
                    return true;
                }
                if (getNofComponents(timestamp) != tempType.getNofComponents(timestamp)) {
                    info.setErrorStr(NOFFIELDSDONTMATCH);
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
                    final CompField cf = getComponentByIndex(i);
                    final CompField tempTypeCompField = tempType.getComponentByIndex(i);
                    final IType compFieldType = cf.getType().getTypeRefdLast(timestamp);
                    final IType tempTypeCompFieldType = tempTypeCompField.getType().getTypeRefdLast(timestamp);
                    if (cf.isOptional() != tempTypeCompField.isOptional()) {
                        final String compFieldName = cf.getIdentifier().getDisplayName();
                        final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldName);
                        info.appendOp2Ref("." + tempTypeCompFieldName);
                        info.setOp1Type(compFieldType);
                        info.setOp2Type(tempTypeCompFieldType);
                        info.setErrorStr(BADOPTIONALITY);
                        return false;
                    }
                    lChain.markState();
                    rChain.markState();
                    lChain.add(compFieldType);
                    rChain.add(tempTypeCompFieldType);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, tempTypeCompFieldType, false);
                    if (!compFieldType.equals(tempTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, tempTypeCompFieldType, infoTemp, lChain, rChain)) {
                        final String compFieldName = cf.getIdentifier().getDisplayName();
                        final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldName + infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + tempTypeCompFieldName + infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_TTCN3_SET:
            {
                final TTCN3_Set_Type tempType = (TTCN3_Set_Type) temp;
                if (getNofComponents(timestamp) != tempType.getNofComponents()) {
                    info.setErrorStr(NOFFIELDSDONTMATCH);
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
                    final CompField compField = getComponentByIndex(i);
                    final CompField tempTypeCompField = tempType.getComponentByIndex(i);
                    final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
                    final IType tempTypeCompFieldType = tempTypeCompField.getType().getTypeRefdLast(timestamp);
                    if (compField.isOptional() != tempTypeCompField.isOptional()) {
                        final String compFieldName = compField.getIdentifier().getDisplayName();
                        final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldName);
                        info.appendOp2Ref("." + tempTypeCompFieldName);
                        info.setOp1Type(compFieldType);
                        info.setOp2Type(tempTypeCompFieldType);
                        info.setErrorStr(BADOPTIONALITY);
                        return false;
                    }
                    lChain.markState();
                    rChain.markState();
                    lChain.add(compFieldType);
                    rChain.add(tempTypeCompFieldType);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, tempTypeCompFieldType, false);
                    if (!compFieldType.equals(tempTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, tempTypeCompFieldType, infoTemp, lChain, rChain)) {
                        final String compFieldName = compField.getIdentifier().getDisplayName();
                        final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldName + infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + tempTypeCompFieldName + infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_SET_OF:
            {
                final SetOf_Type tempType = (SetOf_Type) temp;
                if (!tempType.isSubtypeCompatible(timestamp, this)) {
                    info.setErrorStr("Incompatible set of/SET OF subtypes");
                    return false;
                }
                final int nofComps = getNofComponents(timestamp);
                if (nofComps == 0) {
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0; i < nofComps; i++) {
                    final CompField compField = getComponentByIndex(i);
                    final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
                    final IType temporalTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(compFieldType);
                    rChain.add(temporalTypeOfType);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeOfType, false);
                    if (!compFieldType.equals(temporalTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeOfType, infoTemp, lChain, rChain)) {
                        info.appendOp1Ref("." + compField.getIdentifier().getDisplayName() + infoTemp.getOp1RefStr());
                        if (infoTemp.getOp2RefStr().length() > 0) {
                            info.appendOp2Ref("[]");
                        }
                        info.appendOp2Ref(infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_ASN1_CHOICE:
        case TYPE_TTCN3_CHOICE:
        case TYPE_ANYTYPE:
            info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
            return false;
        case TYPE_ASN1_SEQUENCE:
        case TYPE_TTCN3_SEQUENCE:
        case TYPE_SEQUENCE_OF:
        case TYPE_ARRAY:
            info.setErrorStr(NOTCOMPATIBLESETSETOF);
            return false;
        default:
            return false;
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with TypeCompatibilityInfo

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

the class Referenced_Template method checkThisTemplateGeneric.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplateGeneric(final CompilationTimeStamp timestamp, final IType type, final boolean isModified, final boolean allowOmit, final boolean allowAnyOrOmit, final boolean subCheck, final boolean implicitOmit, final Assignment lhs) {
    if (getIsErroneous(timestamp) || reference == null) {
        return false;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return false;
    }
    final boolean selfReference = lhs == assignment;
    assignment.check(timestamp);
    IType governor = assignment.getType(timestamp);
    if (governor != null) {
        governor = governor.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    }
    if (governor == null) {
        setIsErroneous(true);
        return selfReference;
    }
    final TypeCompatibilityInfo info = new TypeCompatibilityInfo(type, governor, true);
    if (!type.isCompatible(timestamp, governor, info, null, null)) {
        final IType last = type.getTypeRefdLast(timestamp);
        switch(last.getTypetype()) {
            case TYPE_PORT:
                // no such thing exists, remain silent
                break;
            case TYPE_SIGNATURE:
                getLocation().reportSemanticError(MessageFormat.format(TYPEMISSMATCH1, type.getTypename(), governor.getTypename()));
                setIsErroneous(true);
                break;
            default:
                getLocation().reportSemanticError(MessageFormat.format(TYPEMISSMATCH2, type.getTypename(), governor.getTypename()));
                setIsErroneous(true);
                break;
        }
    }
    // check for circular references
    final ITTCN3Template temp = getTemplateReferencedLast(timestamp);
    if (temp != this) {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(CIRCULARTEMPLATEREFERENCE, true);
        final boolean referencedHasImplicitOmit = hasTemplateImpliciteOmit(timestamp, referenceChain);
        referenceChain.release();
    }
    return selfReference;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) IType(org.eclipse.titan.designer.AST.IType)

Example 3 with TypeCompatibilityInfo

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

the class Array_Type method isCompatible.

@Override
public /**
 * {@inheritDoc}
 */
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
    check(timestamp);
    otherType.check(timestamp);
    final IType temp = otherType.getTypeRefdLast(timestamp);
    if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
        return true;
    }
    if (info == null || noStructuredTypeCompatibility) {
        return this == temp;
    }
    switch(temp.getTypetype()) {
        case TYPE_ASN1_SEQUENCE:
            {
                final ASN1_Sequence_Type tempType = (ASN1_Sequence_Type) temp;
                final int tempTypeNofComps = tempType.getNofComponents(timestamp);
                if (tempTypeNofComps == 0) {
                    return false;
                }
                final long thisNofComps = getDimension().getSize();
                if (thisNofComps != tempTypeNofComps) {
                    info.setErrorStr(MessageFormat.format(NOFFIELDSDONTMATCH, thisNofComps, tempTypeNofComps));
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0; i < tempTypeNofComps; i++) {
                    final CompField tempTypeCf = tempType.getComponentByIndex(i);
                    final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
                    final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(tempElementType);
                    rChain.add(tempTypeCfType);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeCfType, false);
                    if (!tempElementType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
                        info.appendOp1Ref(infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_TTCN3_SEQUENCE:
            {
                final TTCN3_Sequence_Type tempType = (TTCN3_Sequence_Type) temp;
                final int tempTypeNofComps = tempType.getNofComponents();
                if (tempTypeNofComps == 0) {
                    return false;
                }
                final long nofComps = getDimension().getSize();
                if (nofComps != tempTypeNofComps) {
                    info.setErrorStr(MessageFormat.format(NOFFIELDSDONTMATCH, nofComps, tempTypeNofComps));
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0; i < tempTypeNofComps; i++) {
                    final CompField tempTypeCf = tempType.getComponentByIndex(i);
                    final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
                    final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(tempElementType);
                    rChain.add(tempTypeCfType);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeCfType, false);
                    if (!tempElementType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
                        info.appendOp1Ref(infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + tempTypeCf.getIdentifier().getDisplayName() + infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_SEQUENCE_OF:
            {
                final SequenceOf_Type tempType = (SequenceOf_Type) temp;
                if (!tempType.isSubtypeCompatible(timestamp, this)) {
                    info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
                    return false;
                }
                final IType tempTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
                final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                lChain.markState();
                rChain.markState();
                lChain.add(tempElementType);
                rChain.add(tempTypeOfType);
                final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeOfType, false);
                if (!tempElementType.equals(tempTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeOfType, infoTemp, lChain, rChain)) {
                    info.appendOp1Ref(infoTemp.getOp1RefStr());
                    if (infoTemp.getOp2RefStr().length() > 0) {
                        info.appendOp2Ref("[]");
                    }
                    info.appendOp2Ref(infoTemp.getOp2RefStr());
                    info.setOp1Type(infoTemp.getOp1Type());
                    info.setOp2Type(infoTemp.getOp2Type());
                    info.setErrorStr(infoTemp.getErrorStr());
                    lChain.previousState();
                    rChain.previousState();
                    return false;
                }
                info.setNeedsConversion(true);
                lChain.previousState();
                rChain.previousState();
                return true;
            }
        case TYPE_ARRAY:
            {
                final Array_Type tempType = (Array_Type) temp;
                if (this == tempType) {
                    return true;
                }
                if (dimension != null && tempType.dimension != null && !dimension.isIdentical(timestamp, tempType.dimension)) {
                    info.setErrorStr(BADARRAYDIMENSION);
                    return false;
                }
                final IType tempElementType = getElementType().getTypeRefdLast(timestamp);
                final IType tempTypeElementType = tempType.getElementType().getTypeRefdLast(timestamp);
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                lChain.markState();
                rChain.markState();
                lChain.add(tempElementType);
                rChain.add(tempTypeElementType);
                final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(tempElementType, tempTypeElementType, false);
                if (!tempElementType.equals(tempTypeElementType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !tempElementType.isCompatible(timestamp, tempTypeElementType, infoTemp, lChain, rChain)) {
                    info.appendOp1Ref(infoTemp.getOp1RefStr());
                    info.appendOp2Ref(infoTemp.getOp2RefStr());
                    info.setOp1Type(infoTemp.getOp1Type());
                    info.setOp2Type(infoTemp.getOp2Type());
                    info.setErrorStr(infoTemp.getErrorStr());
                    lChain.previousState();
                    rChain.previousState();
                    return false;
                }
                info.setNeedsConversion(true);
                lChain.previousState();
                rChain.previousState();
                return true;
            }
        case TYPE_ASN1_CHOICE:
        case TYPE_TTCN3_CHOICE:
        case TYPE_ANYTYPE:
            info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
            return false;
        case TYPE_ASN1_SET:
        case TYPE_TTCN3_SET:
        case TYPE_SET_OF:
            info.setErrorStr(NOTCOMPATIBLESETSETOF);
            return false;
        default:
            return false;
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with TypeCompatibilityInfo

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

the class ASN1_Sequence_Type method isCompatible.

@Override
public /**
 * {@inheritDoc}
 */
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
    check(timestamp);
    otherType.check(timestamp);
    final IType temp = otherType.getTypeRefdLast(timestamp);
    if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
        return true;
    }
    if (info == null || noStructuredTypeCompatibility) {
        return this == temp;
    }
    switch(temp.getTypetype()) {
        case TYPE_ASN1_SEQUENCE:
            {
                final ASN1_Sequence_Type temporalType = (ASN1_Sequence_Type) temp;
                if (this == temporalType) {
                    return true;
                }
                if (getNofComponents(timestamp) != temporalType.getNofComponents(timestamp)) {
                    info.setErrorStr(NOFFIELDSDONTMATCH);
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(temporalType);
                }
                for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
                    final CompField compField = getComponentByIndex(i);
                    final CompField temporalTypeCompField = temporalType.getComponentByIndex(i);
                    final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
                    final IType temporalTypeCompFieldType = temporalTypeCompField.getType().getTypeRefdLast(timestamp);
                    if (compField.isOptional() != temporalTypeCompField.isOptional()) {
                        final String compFieldName = compField.getIdentifier().getDisplayName();
                        final String temporalTypeCompFieldName = temporalTypeCompField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldName);
                        info.appendOp2Ref("." + temporalTypeCompFieldName);
                        info.setOp1Type(compFieldType);
                        info.setOp2Type(temporalTypeCompFieldType);
                        info.setErrorStr(BADOPTIONALITY);
                        return false;
                    }
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeCompFieldType, false);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(compFieldType);
                    rChain.add(temporalTypeCompFieldType);
                    if (!compFieldType.equals(temporalTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeCompFieldType, infoTemp, lChain, rChain)) {
                        final String compFieldame = compField.getIdentifier().getDisplayName();
                        final String temporalTypeCompFieldName = temporalTypeCompField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldame + infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + temporalTypeCompFieldName + infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_TTCN3_SEQUENCE:
            {
                final TTCN3_Sequence_Type tempType = (TTCN3_Sequence_Type) temp;
                if (getNofComponents(timestamp) != tempType.getNofComponents()) {
                    info.setErrorStr(NOFFIELDSDONTMATCH);
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
                    final CompField compField = getComponentByIndex(i);
                    final CompField tempTypeComponentField = tempType.getComponentByIndex(i);
                    final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
                    final IType temporalTypeCompFieldType = tempTypeComponentField.getType().getTypeRefdLast(timestamp);
                    if (compField.isOptional() != tempTypeComponentField.isOptional()) {
                        final String compFieldName = compField.getIdentifier().getDisplayName();
                        final String temporalTypeCompFieldName = tempTypeComponentField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldName);
                        info.appendOp2Ref("." + temporalTypeCompFieldName);
                        info.setOp1Type(compFieldType);
                        info.setOp2Type(temporalTypeCompFieldType);
                        info.setErrorStr(BADOPTIONALITY);
                        return false;
                    }
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeCompFieldType, false);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(compFieldType);
                    rChain.add(temporalTypeCompFieldType);
                    if (!compFieldType.equals(temporalTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeCompFieldType, infoTemp, lChain, rChain)) {
                        final String compFieldName = compField.getIdentifier().getDisplayName();
                        final String tempTypeCompFieldName = tempTypeComponentField.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + compFieldName + infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + tempTypeCompFieldName + infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_SEQUENCE_OF:
            {
                final SequenceOf_Type temporalType = (SequenceOf_Type) temp;
                if (!temporalType.isSubtypeCompatible(timestamp, this)) {
                    info.setErrorStr("Incompatible record of/SEQUENCE OF subtypes");
                    return false;
                }
                final int thisNofComps = getNofComponents(timestamp);
                if (thisNofComps == 0) {
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(temporalType);
                }
                for (int i = 0; i < thisNofComps; i++) {
                    final CompField compField = getComponentByIndex(i);
                    final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
                    final IType temporalTypeOfType = temporalType.getOfType().getTypeRefdLast(timestamp);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeOfType, false);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(compFieldType);
                    rChain.add(temporalTypeOfType);
                    if (!compFieldType.equals(temporalTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeOfType, infoTemp, lChain, rChain)) {
                        info.appendOp1Ref("." + compField.getIdentifier().getDisplayName() + infoTemp.getOp1RefStr());
                        if (infoTemp.getOp2RefStr().length() > 0) {
                            info.appendOp2Ref("[]");
                        }
                        info.appendOp2Ref(infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_ARRAY:
            {
                final int nofComps = getNofComponents(timestamp);
                if (nofComps == 0) {
                    return false;
                }
                final Array_Type temporalType = (Array_Type) temp;
                final long temporalTypeNofComps = temporalType.getDimension().getSize();
                if (nofComps != temporalTypeNofComps) {
                    info.setErrorStr(MessageFormat.format(NOFFIELDSDIMENSIONDONTMATCH, nofComps, temporalTypeNofComps));
                    return false;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(temporalType);
                }
                for (int i = 0; i < nofComps; i++) {
                    final CompField compField = getComponentByIndex(i);
                    final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
                    final IType tempTypeElementType = temporalType.getElementType().getTypeRefdLast(timestamp);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, tempTypeElementType, false);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(compFieldType);
                    rChain.add(tempTypeElementType);
                    if (!compFieldType.equals(tempTypeElementType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, tempTypeElementType, infoTemp, lChain, rChain)) {
                        info.appendOp1Ref("." + compField.getIdentifier().getDisplayName() + infoTemp.getOp1RefStr());
                        info.appendOp2Ref(infoTemp.getOp2RefStr());
                        info.setOp1Type(infoTemp.getOp1Type());
                        info.setOp2Type(infoTemp.getOp2Type());
                        info.setErrorStr(infoTemp.getErrorStr());
                        lChain.previousState();
                        rChain.previousState();
                        return false;
                    }
                    lChain.previousState();
                    rChain.previousState();
                }
                info.setNeedsConversion(true);
                return true;
            }
        case TYPE_ASN1_CHOICE:
        case TYPE_TTCN3_CHOICE:
        case TYPE_ANYTYPE:
            info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
            return false;
        case TYPE_ASN1_SET:
        case TYPE_TTCN3_SET:
        case TYPE_SET_OF:
            info.setErrorStr(NOTCOMPATIBLESETSETOF);
            return false;
        default:
            return false;
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) IType(org.eclipse.titan.designer.AST.IType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)

Example 5 with TypeCompatibilityInfo

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

the class ExpressionUtilities method checkExpressionOperatorCompatibilityInternal.

// the same as the previous but the last arg is template
private static void checkExpressionOperatorCompatibilityInternal(final CompilationTimeStamp timestamp, final Expression_Value expression, final IReferenceChain referenceChain, final Expected_Value_type expectedValue, final IValue param1, final TemplateInstance param2) {
    if (expression == null || param1 == null || param2 == null) {
        return;
    }
    if (param1.getIsErroneous(timestamp) || param2.getTemplateBody().getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    IValue operand1 = param1;
    final TemplateInstance operand2 = param2;
    final Type_type tempType1 = operand1.getExpressionReturntype(timestamp, expectedValue);
    final Type_type tempType2 = operand2.getExpressionReturntype(timestamp, expectedValue);
    ITTCN3Template temp2 = operand2.getTemplateBody();
    if (Type_type.TYPE_UNDEFINED.equals(tempType1)) {
        if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
            if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype())) {
                if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
                    final Scope scope = expression.getMyScope();
                    final Module module = scope.getModuleScope();
                    final Identifier identifier = ((Undefined_LowerIdentifier_Value) operand1).getIdentifier();
                    if (scope.hasAssignmentWithId(timestamp, identifier) || module.hasImportedAssignmentWithID(timestamp, identifier)) {
                        operand1 = operand1.setLoweridToReference(timestamp);
                        checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                        return;
                    }
                    final Identifier identifier2 = ((Undefined_LowerIdentifier_Value) ((SpecificValue_Template) temp2).getSpecificValue()).getIdentifier();
                    if (scope.hasAssignmentWithId(timestamp, identifier2) || module.hasImportedAssignmentWithID(timestamp, identifier2)) {
                        temp2 = temp2.setLoweridToReference(timestamp);
                        checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                        return;
                    }
                } else {
                    operand1 = operand1.setLoweridToReference(timestamp);
                    checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                    return;
                }
            } else if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
                temp2 = temp2.setLoweridToReference(timestamp);
                // To avoid infinite loop:
                final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
                if (operand2 == tempTemplateInstance2) {
                    return;
                }
                checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
                return;
            }
            if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
                return;
            }
            expression.getLocation().reportSemanticError(UNDETERMINABLEOPERANDSERROR);
            expression.setIsErroneous(true);
            return;
        }
        if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType2)) {
            operand1 = operand1.setLoweridToReference(timestamp);
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
            return;
        }
    } else if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
        if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType1)) {
            temp2 = temp2.setLoweridToReference(timestamp);
            // To avoid infinite loop:
            final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
            if (operand2 == tempTemplateInstance2) {
                return;
            }
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
            return;
        }
    }
    final IType type1 = operand1.getExpressionGovernor(timestamp, expectedValue);
    final IType type2 = operand2.getExpressionGovernor(timestamp, expectedValue);
    if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    if (type1 != null) {
        if (type2 != null) {
            final TypeCompatibilityInfo info1 = new TypeCompatibilityInfo(type1, type2, true);
            final TypeCompatibilityInfo info2 = new TypeCompatibilityInfo(type2, type1, true);
            final boolean retVal1 = type1.isCompatible(timestamp, type2, info1, null, null);
            final boolean retVal2 = type2.isCompatible(timestamp, type1, info2, null, null);
            if (!retVal1 && !retVal2) {
                expression.getLocation().reportSemanticError(info1.toString());
                expression.setIsErroneous(true);
                return;
            }
            if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
                if (info1.getNeedsConversion()) {
                    expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type1.getTypename(), type2.getTypename()));
                } else if (info2.getNeedsConversion()) {
                    expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type2.getTypename(), type1.getTypename()));
                }
            }
        } else {
            temp2.setMyGovernor(type1);
            final ITTCN3Template tempValue = type1.checkThisTemplateRef(timestamp, temp2);
            if (Template_type.OMIT_VALUE.equals(temp2.getTemplatetype()) || (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.OMIT_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()))) {
                operand1.checkExpressionOmitComparison(timestamp, expectedValue);
            } else {
                type1.checkThisTemplate(timestamp, tempValue, false, false, null);
                final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) tempValue);
                if (operand2 == tempTemplateInstance2) {
                    return;
                }
                checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
                return;
            }
        }
    } else if (type2 != null) {
        operand1.setMyGovernor(type2);
        final IValue tempValue = type2.checkThisValueRef(timestamp, operand1);
        if (Value_type.OMIT_VALUE.equals(operand1.getValuetype())) {
        // temp2.check_expression_omit_comparison(timestamp,
        // expectedValue); ???
        } else {
            type2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, false, false, false));
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, tempValue, operand2);
            return;
        }
    } else {
        if (Type_type.TYPE_UNDEFINED.equals(tempType1) || Type_type.TYPE_UNDEFINED.equals(tempType2)) {
            expression.getLocation().reportSemanticError(PLEASEUSEREFERENCES);
            expression.setIsErroneous(true);
            return;
        }
        if (!Type.isCompatible(timestamp, tempType1, tempType2, false, false) && !Type.isCompatible(timestamp, tempType2, tempType1, false, false)) {
            expression.getLocation().reportSemanticError(INCOMPATIBLEOPERANDERROR);
            expression.setIsErroneous(true);
        }
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Scope(org.eclipse.titan.designer.AST.Scope) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Module(org.eclipse.titan.designer.AST.Module) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)10 TypeCompatibilityInfo (org.eclipse.titan.designer.AST.TypeCompatibilityInfo)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)8 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)5 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)3 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)2 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Module (org.eclipse.titan.designer.AST.Module)2 Scope (org.eclipse.titan.designer.AST.Scope)2 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)2 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)2 Assignment (org.eclipse.titan.designer.AST.Assignment)1 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)1 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)1 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)1 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)1 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)1