Search in sources :

Example 61 with CompField

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

the class Sequence_Value method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 * generate_code_init_se in the compiler
 */
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (convertedValue != null) {
        return convertedValue.generateCodeInit(aData, source, name);
    }
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    int nofComps = 0;
    switch(type.getTypetype()) {
        case TYPE_TTCN3_SEQUENCE:
            nofComps = ((TTCN3_Sequence_Type) type).getNofComponents();
            break;
        case TYPE_ASN1_SEQUENCE:
            nofComps = ((ASN1_Sequence_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
    }
    if (nofComps == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
        return source;
    }
    CompField compField = null;
    for (int i = 0; i < nofComps; i++) {
        switch(type.getTypetype()) {
            case TYPE_TTCN3_SEQUENCE:
                compField = ((TTCN3_Sequence_Type) type).getComponentByIndex(i);
                break;
            case TYPE_ASN1_SEQUENCE:
                compField = ((ASN1_Sequence_Type) type).getComponentByIndex(i);
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
        }
        final Identifier fieldName = compField.getIdentifier();
        IValue fieldValue;
        if (hasComponentWithName(fieldName)) {
            fieldValue = getComponentByName(fieldName).getValue();
            if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
                continue;
            } else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
                fieldValue = null;
            }
        } else // TODO add support for asn default values when needed
        {
            continue;
        }
        final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
        if (fieldValue != null) {
            // TODO handle the case when temporary reference is needed
            final StringBuilder embeddedName = new StringBuilder();
            embeddedName.append(name);
            embeddedName.append(".get");
            embeddedName.append(javaGetterName);
            embeddedName.append("()");
            if (compField.isOptional()) /*&& fieldValue.isCompound() */
            {
                embeddedName.append(".get()");
            }
            // TODO add extra handling for optional fields
            fieldValue.generateCodeInit(aData, source, embeddedName.toString());
        } else {
            aData.addBuiltinTypeImport("Base_Template.template_sel");
            source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
        }
    }
    return source;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IType(org.eclipse.titan.designer.AST.IType)

Example 62 with CompField

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

the class Sequence_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    if (convertedValue != null && convertedValue != this) {
        final IValue temp = convertedValue.getReferencedSubValue(timestamp, reference, actualSubReference, refChain);
        if (temp != null && temp.getIsErroneous(timestamp)) {
            setIsErroneous(true);
        }
        return temp;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return null;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            CompField compField;
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SEQUENCE:
                    if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    if (values.hasNamedValueWithName(fieldId)) {
                        return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    compField = ((TTCN3_Sequence_Type) type).getComponentByName(fieldId.getDisplayName());
                    if (compField.isOptional()) {
                        // create an explicit omit value
                        final Value result = new Omit_Value();
                        final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                        result.setFullNameParent(bridge);
                        result.setMyScope(getMyScope());
                        return result;
                    }
                    if (!reference.getUsedInIsbound()) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound record field `{0}''", fieldId.getDisplayName()));
                    }
                    return null;
                case TYPE_ASN1_SEQUENCE:
                    if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    if (values.hasNamedValueWithName(fieldId)) {
                        return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
                    if (compField.isOptional()) {
                        // create an explicit omit value
                        final Value result = new Omit_Value();
                        final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                        result.setFullNameParent(bridge);
                        result.setMyScope(getMyScope());
                        return result;
                    } else if (compField.hasDefault()) {
                        return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    return null;
                default:
                    return null;
            }
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 63 with CompField

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

the class Set_Value method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 * generate_code_init_se in the compiler
 */
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    int nofComps = 0;
    switch(type.getTypetype()) {
        case TYPE_TTCN3_SET:
            nofComps = ((TTCN3_Set_Type) type).getNofComponents();
            break;
        case TYPE_ASN1_SET:
            nofComps = ((ASN1_Set_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
    }
    if (nofComps == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
        return source;
    }
    CompField compField = null;
    for (int i = 0; i < nofComps; i++) {
        switch(type.getTypetype()) {
            case TYPE_TTCN3_SET:
                compField = ((TTCN3_Set_Type) type).getComponentByIndex(i);
                break;
            case TYPE_ASN1_SET:
                compField = ((ASN1_Set_Type) type).getComponentByIndex(i);
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
        }
        final Identifier fieldName = compField.getIdentifier();
        IValue fieldValue;
        if (hasComponentWithName(fieldName)) {
            fieldValue = getComponentByName(fieldName).getValue();
            if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
                continue;
            } else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
                fieldValue = null;
            }
        } else // TODO add support for asn default values when needed
        {
            continue;
        }
        final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
        if (fieldValue != null) {
            // TODO handle the case when temporary reference is needed
            final StringBuilder embeddedName = new StringBuilder();
            embeddedName.append(name);
            embeddedName.append(".get");
            embeddedName.append(javaGetterName);
            embeddedName.append("()");
            if (compField.isOptional()) /*&& fieldValue.isCompound() */
            {
                embeddedName.append(".get()");
            }
            // TODO add extra handling for optional fields
            fieldValue.generateCodeInit(aData, source, embeddedName.toString());
        } else {
            aData.addBuiltinTypeImport("Base_Template.template_sel");
            source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
        }
    }
    return source;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IType(org.eclipse.titan.designer.AST.IType)

Example 64 with CompField

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

the class Set_Value method checkEquality.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkEquality(final CompilationTimeStamp timestamp, final IValue other) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = other.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (!Value_type.SET_VALUE.equals(last.getValuetype())) {
        return false;
    }
    if (myGovernor == null) {
        return false;
    }
    final Set_Value otherSet = (Set_Value) last;
    if (values.getSize() != otherSet.values.getSize()) {
        return false;
    }
    int nofComps = 0;
    final IType leftGovernor = myGovernor.getTypeRefdLast(timestamp);
    switch(leftGovernor.getTypetype()) {
        case TYPE_TTCN3_SET:
            nofComps = ((TTCN3_Set_Type) leftGovernor).getNofComponents();
            break;
        case TYPE_ASN1_SET:
            nofComps = ((ASN1_Set_Type) leftGovernor).getNofComponents(timestamp);
            break;
        default:
            return false;
    }
    CompField compField = null;
    for (int i = 0; i < nofComps; i++) {
        switch(leftGovernor.getTypetype()) {
            case TYPE_TTCN3_SET:
                compField = ((TTCN3_Set_Type) leftGovernor).getComponentByIndex(i);
                break;
            case TYPE_ASN1_SET:
                compField = ((ASN1_Set_Type) leftGovernor).getComponentByIndex(i);
                break;
            default:
                return false;
        }
        final Identifier fieldName = compField.getIdentifier();
        if (hasComponentWithName(fieldName)) {
            final IValue leftValue = getComponentByName(fieldName).getValue();
            if (otherSet.hasComponentWithName(fieldName)) {
                final IValue otherValue = otherSet.getComponentByName(fieldName).getValue();
                if ((Value_type.OMIT_VALUE.equals(leftValue.getValuetype()) && !Value_type.OMIT_VALUE.equals(otherValue.getValuetype())) || (!Value_type.OMIT_VALUE.equals(leftValue.getValuetype()) && Value_type.OMIT_VALUE.equals(otherValue.getValuetype()))) {
                    return false;
                }
                if (!leftValue.checkEquality(timestamp, otherValue)) {
                    return false;
                }
            } else {
                if (compField.hasDefault()) {
                    if (!leftValue.checkEquality(timestamp, compField.getDefault())) {
                        return false;
                    }
                } else {
                    if (!Value_type.OMIT_VALUE.equals(leftValue.getValuetype())) {
                        return false;
                    }
                }
            }
        } else {
            if (otherSet.hasComponentWithName(fieldName)) {
                final IValue otherValue = otherSet.getComponentByName(fieldName).getValue();
                if (compField.hasDefault()) {
                    if (Value_type.OMIT_VALUE.equals(otherValue.getValuetype())) {
                        return false;
                    }
                    if (!compField.getDefault().checkEquality(timestamp, otherValue)) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) IType(org.eclipse.titan.designer.AST.IType)

Example 65 with CompField

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

the class Set_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return null;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SET:
                    if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    break;
                case TYPE_ASN1_SET:
                    if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    break;
                default:
                    return null;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
            }
            if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
                if (!reference.getUsedInIsbound()) {
                    subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound set field `{0}''", fieldId.getDisplayName()));
                }
                // this is an error, that was already reported
                return null;
            }
            final CompField compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
            } else if (compField.hasDefault()) {
                return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
            }
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            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) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

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