Search in sources :

Example 11 with ASN1_Set_Type

use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_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 (getNofComponents() != 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(); i < size; i++) {
                    final CompField cf = getComponentByIndex(i);
                    final CompField tempTypeCf = tempType.getComponentByIndex(i);
                    final IType cfType = cf.getType().getTypeRefdLast(timestamp);
                    final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
                    if (cf.isOptional() != tempTypeCf.isOptional()) {
                        final String cfName = cf.getIdentifier().getDisplayName();
                        final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + cfName);
                        info.appendOp2Ref("." + tempTypeCfName);
                        info.setOp1Type(cfType);
                        info.setOp2Type(tempTypeCfType);
                        info.setErrorStr(BADOPTIONALITY);
                        return false;
                    }
                    lChain.markState();
                    rChain.markState();
                    lChain.add(cfType);
                    rChain.add(tempTypeCfType);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeCfType, false);
                    if (!cfType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
                        final String cfName = cf.getIdentifier().getDisplayName();
                        final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + cfName + infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + tempTypeCfName + 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 (this == tempType) {
                    return true;
                }
                if (getNofComponents() != 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(); i < size; i++) {
                    final CompField cf = getComponentByIndex(i);
                    final CompField tempTypeCf = tempType.getComponentByIndex(i);
                    final IType cfType = cf.getType().getTypeRefdLast(timestamp);
                    final IType tempTypeCfType = tempTypeCf.getType().getTypeRefdLast(timestamp);
                    if (cf.isOptional() != tempTypeCf.isOptional()) {
                        final String cfName = cf.getIdentifier().getDisplayName();
                        final String tempTypeCompFieldName = tempTypeCf.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + cfName);
                        info.appendOp2Ref("." + tempTypeCompFieldName);
                        info.setOp1Type(cfType);
                        info.setOp2Type(tempTypeCfType);
                        info.setErrorStr(BADOPTIONALITY);
                        return false;
                    }
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeCfType, false);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(cfType);
                    rChain.add(tempTypeCfType);
                    if (!cfType.equals(tempTypeCfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeCfType, infoTemp, lChain, rChain)) {
                        final String cfName = cf.getIdentifier().getDisplayName();
                        final String tempTypeCfName = tempTypeCf.getIdentifier().getDisplayName();
                        info.appendOp1Ref("." + cfName + infoTemp.getOp1RefStr());
                        info.appendOp2Ref("." + tempTypeCfName + 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();
                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 cf = getComponentByIndex(i);
                    final IType cfType = cf.getType().getTypeRefdLast(timestamp);
                    final IType tempTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
                    final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(cfType, tempTypeOfType, false);
                    lChain.markState();
                    rChain.markState();
                    lChain.add(cfType);
                    rChain.add(tempTypeOfType);
                    if (!cfType.equals(tempTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !cfType.isCompatible(timestamp, tempTypeOfType, infoTemp, lChain, rChain)) {
                        info.appendOp1Ref("." + cf.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;
                    }
                }
                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_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) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 12 with ASN1_Set_Type

use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type in project titan.EclipsePlug-ins by eclipse.

the class Named_Template_List method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    if (asValue != null) {
        asValue.generateCodeInit(aData, source, name);
        return;
    }
    if (myGovernor == null) {
        return;
    }
    // FIXME actually a bit more complex
    final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (type == null) {
        return;
    }
    if (namedTemplates.getNofTemplates() == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
    }
    // else is not needed as the loop will not run
    for (int i = 0; i < namedTemplates.getNofTemplates(); i++) {
        final NamedTemplate namedTemplate = namedTemplates.getTemplateByIndex(i);
        final String fieldName = namedTemplate.getName().getName();
        // FIXME handle needs_temp_ref case
        final String generatedFieldName = FieldSubReference.getJavaGetterName(fieldName);
        final TTCN3Template template = namedTemplate.getTemplate();
        if (template.needsTemporaryReference()) {
            Type fieldType;
            switch(type.getTypetype()) {
                case TYPE_SIGNATURE:
                    fieldType = ((Signature_Type) type).getParameterByName(fieldName).getType();
                    break;
                case TYPE_TTCN3_SEQUENCE:
                    fieldType = ((TTCN3_Sequence_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_TTCN3_SET:
                    fieldType = ((TTCN3_Set_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_ASN1_SEQUENCE:
                    fieldType = ((ASN1_Sequence_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ASN1_SET:
                    fieldType = ((ASN1_Set_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ASN1_CHOICE:
                    fieldType = ((ASN1_Choice_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_TTCN3_CHOICE:
                    fieldType = ((TTCN3_Choice_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_OPENTYPE:
                    fieldType = ((Open_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ANYTYPE:
                    fieldType = ((Anytype_Type) type).getComponentByName(fieldName).getType();
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing named template list `" + getFullName() + "''");
                    return;
            }
            final String tempId = aData.getTemporaryVariableName();
            source.append("{\n");
            source.append(MessageFormat.format("{0} {1} = {2}.get{3}();\n", fieldType.getGenNameTemplate(aData, source, myScope), tempId, name, generatedFieldName));
            template.generateCodeInit(aData, source, tempId);
            source.append("}\n");
        } else {
            final String embeddedName = MessageFormat.format("{0}.get{1}()", name, generatedFieldName);
            template.generateCodeInit(aData, source, embeddedName);
        }
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IType(org.eclipse.titan.designer.AST.IType) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)

Aggregations

ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)10 IType (org.eclipse.titan.designer.AST.IType)9 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)7 Identifier (org.eclipse.titan.designer.AST.Identifier)7 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)6 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)5 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)5 ISubReference (org.eclipse.titan.designer.AST.ISubReference)5 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)4 ArrayList (java.util.ArrayList)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 IValue (org.eclipse.titan.designer.AST.IValue)3 Value (org.eclipse.titan.designer.AST.Value)3 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 Assignment (org.eclipse.titan.designer.AST.Assignment)2 Reference (org.eclipse.titan.designer.AST.Reference)2 AbstractOfType (org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType)2 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)2 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)2 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)2