Search in sources :

Example 41 with CompField

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

the class ASN1_Sequence_Type method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    if (components == null) {
        return;
    }
    final String className = getGenNameOwn();
    final String classReadableName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final List<FieldInfo> namesList = new ArrayList<FieldInfo>();
    boolean hasOptional = false;
    for (int i = 0; i < components.getNofComps(); i++) {
        final CompField compField = components.getCompByIndex(i);
        final IType cfType = compField.getType();
        final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(), false, cfType.getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
        hasOptional |= compField.isOptional();
        namesList.add(fi);
    }
    for (int i = 0; i < components.getNofComps(); i++) {
        final CompField compField = components.getCompByIndex(i);
        final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
        compField.getType().generateCode(aData, tempSource);
    }
    final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
    RecordSetCodeGenerator.generateValueClass(aData, source, className, classReadableName, namesList, hasOptional, true, hasRaw, null);
    RecordSetCodeGenerator.generateTemplateClass(aData, source, className, classReadableName, namesList, hasOptional, false);
    generateCodeForCodingHandlers(aData, source);
}
Also used : CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) ArrayList(java.util.ArrayList) FieldInfo(org.eclipse.titan.designer.AST.TTCN3.types.RecordSetCodeGenerator.FieldInfo) IType(org.eclipse.titan.designer.AST.IType)

Example 42 with CompField

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

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

the class ASN1_Sequence_Type method getFieldType.

// This is the same as in ASN1_Set_type
@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
            return null;
        case fieldSubReference:
            if (components == null) {
                return null;
            }
            final Identifier id = subreference.getId();
            final CompField compField = components.getCompByName(id);
            if (compField == null) {
                subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
                return null;
            }
            if (interruptIfOptional && compField.isOptional()) {
                return null;
            }
            final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
            return compField.getType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Example 44 with CompField

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

the class ASN1_Set_Seq_Choice_BaseType method resolveReference.

@Override
public /**
 * {@inheritDoc}
 */
Declaration resolveReference(final Reference reference, final int subRefIdx, final ISubReference lastSubreference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    int actualIndex = subRefIdx;
    while (actualIndex < subreferences.size() && subreferences.get(actualIndex) instanceof ArraySubReference) {
        ++actualIndex;
    }
    if (actualIndex == subreferences.size()) {
        return null;
    }
    final Identifier fieldID = subreferences.get(actualIndex).getId();
    if (subreferences.get(actualIndex) == lastSubreference) {
        return Declaration.createInstance(getDefiningAssignment(), fieldID);
    }
    final CompField compField = getComponentByName(fieldID);
    final IType compFieldType = compField.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (compFieldType instanceof IReferenceableElement) {
        final Declaration decl = ((IReferenceableElement) compFieldType).resolveReference(reference, actualIndex + 1, lastSubreference);
        return decl != null ? decl : Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
    }
    return null;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) IReferenceableElement(org.eclipse.titan.designer.AST.IReferenceableElement) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 45 with CompField

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

the class ASN1_Set_Seq_Choice_BaseType method setGenerateCoderFunctions.

@Override
public /**
 * {@inheritDoc}
 */
void setGenerateCoderFunctions(final CompilationTimeStamp timestamp, final MessageEncoding_type encodingType) {
    switch(encodingType) {
        case RAW:
            break;
        default:
            return;
    }
    if (getGenerateCoderFunctions(encodingType)) {
        // already set
        return;
    }
    codersToGenerate.add(encodingType);
    for (int i = 0; i < components.getNofComps(); i++) {
        final CompField compField = components.getCompByIndex(i);
        compField.getType().getTypeRefdLast(timestamp).setGenerateCoderFunctions(timestamp, encodingType);
    }
}
Also used : CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)64 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)62 Identifier (org.eclipse.titan.designer.AST.Identifier)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)32 Type (org.eclipse.titan.designer.AST.Type)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)19 IValue (org.eclipse.titan.designer.AST.IValue)19 ArrayList (java.util.ArrayList)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)10 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)10 HashMap (java.util.HashMap)9 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)9 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)9 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)9 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)8 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)8 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)8 Value (org.eclipse.titan.designer.AST.Value)8 Reference (org.eclipse.titan.designer.AST.Reference)6