Search in sources :

Example 16 with Array_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type 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 17 with Array_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Var method generateCodeString.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
    final String genName = getGenName();
    final String typeGeneratedName = type.getGenNameValue(aData, source, getMyScope());
    if (type.getTypetype() == Type_type.TYPE_ARRAY) {
        final Array_Type arrayType = (Array_Type) type;
        final StringBuilder sb = aData.getCodeForType(arrayType.getGenNameOwn());
        arrayType.generateCodeValue(aData, sb);
    }
    if (initialValue != null && initialValue.canGenerateSingleExpression()) {
        final ExpressionStruct expression = new ExpressionStruct();
        initialValue.generateCodeExpressionMandatory(aData, expression, false);
        if (initialValue.returnsNative() || initialValue.getValuetype() == Value_type.REFERENCED_VALUE || initialValue.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE || type.getTypetypeTtcn3() != initialValue.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE)) {
            source.append(MessageFormat.format("{0} {1} = new {0}({2});\n", typeGeneratedName, genName, expression.expression));
        } else {
            source.append(MessageFormat.format("{0} {1} = {2};\n", typeGeneratedName, genName, expression.expression));
        }
    } else {
        source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeGeneratedName, genName));
        if (initialValue != null) {
            initialValue.generateCodeInit(aData, source, genName);
        }
    }
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Example 18 with Array_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Var method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final boolean cleanUp) {
    final String genName = getGenName();
    final StringBuilder sb = aData.getSrc();
    final StringBuilder source = new StringBuilder();
    final StringBuilder initComp = aData.getInitComp();
    if (!isLocal()) {
        source.append("\tpublic static final ");
    }
    final String typeGeneratedName = type.getGenNameValue(aData, source, getMyScope());
    if (type.getTypetype() == Type_type.TYPE_ARRAY) {
        final Array_Type arrayType = (Array_Type) type;
        final StringBuilder sbforTemp = aData.getCodeForType(arrayType.getGenNameOwn());
        arrayType.generateCodeValue(aData, sbforTemp);
    }
    source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeGeneratedName, genName));
    sb.append(source);
    if (initialValue != null) {
        initialValue.generateCodeInit(aData, initComp, genName);
    } else if (cleanUp) {
        initComp.append(genName);
        initComp.append(".cleanUp();\n");
    }
}
Also used : Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Example 19 with Array_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Var_Template method generateCodeString.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
    final String genName = getGenName();
    // FIXME temporal code until generate_code_object is supported for templates
    final String typeGeneratedName = type.getGenNameTemplate(aData, source, getMyScope());
    if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
        final Array_Type arrayType = (Array_Type) type;
        final StringBuilder sb = aData.getCodeForType(arrayType.getGenNameOwn());
        arrayType.generateCodeValue(aData, sb);
        arrayType.generateCodeTemplate(aData, sb);
    }
    source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeGeneratedName, genName));
    if (initialValue != null) {
        initialValue.generateCodeInit(aData, source, genName);
        if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
            TemplateRestriction.generateRestrictionCheckCode(aData, source, location, genName, templateRestriction);
        }
    }
}
Also used : Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Example 20 with Array_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Template method generateCodeString.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
    final String genName = getGenName();
    if (formalParList == null) {
        final String typeName = type.getGenNameTemplate(aData, source, getMyScope());
        if (baseTemplate == null) {
            if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
                final Array_Type arrayType = (Array_Type) type;
                final StringBuilder sb = aData.getCodeForType(arrayType.getGenNameOwn());
                arrayType.generateCodeValue(aData, sb);
                arrayType.generateCodeTemplate(aData, sb);
            }
            source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeName, genName));
            if (body != null) {
                // TODO can optimize for single expressions;
                body.generateCodeInit(aData, source, genName);
            }
        } else {
            source.append(MessageFormat.format("{0} {1} = new {0}({2});\n", typeName, genName, baseTemplate.getGenNameFromScope(aData, source, myScope, "")));
            if (body != null) {
                body.generateCodeInit(aData, source, genName);
            }
        }
    } else {
        source.append(MessageFormat.format("Code generation for parameterized local template `{0}' is not supported", identifier.getDisplayName()));
    }
    if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
        TemplateRestriction.generateRestrictionCheckCode(aData, source, location, genName, templateRestriction);
    }
}
Also used : Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Aggregations

Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)19 IType (org.eclipse.titan.designer.AST.IType)13 IValue (org.eclipse.titan.designer.AST.IValue)10 Assignment (org.eclipse.titan.designer.AST.Assignment)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)6 ArrayDimension (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)6 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)6 Reference (org.eclipse.titan.designer.AST.Reference)5 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)5 ArrayList (java.util.ArrayList)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)4 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)4 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)3 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)2 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2