Search in sources :

Example 6 with TTCN3_Set_Type

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

the class InsertFieldWizardInputPage method checkName.

public void checkName() {
    final Identifier id = new Identifier(Identifier_type.ID_TTCN, nameField.getText().trim());
    settings.setId(id);
    if (!Identifier.isValidInTtcn(settings.getId().getName())) {
        nameErrorMessage = INVALIDNAME;
        nameDone = false;
    } else {
        final IType type = selection.getType(CompilationTimeStamp.getBaseTimestamp());
        if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
            final TTCN3_Set_Seq_Choice_BaseType ss = (TTCN3_Set_Seq_Choice_BaseType) type;
            if (ss.hasComponentWithName(settings.getId().getName())) {
                nameErrorMessage = NAMEEXISTS;
                nameDone = false;
            } else {
                nameErrorMessage = "";
                nameDone = true;
            }
        }
    }
    setErrorMessage(positionErrorMessage + typeErrorMessage + nameErrorMessage + valueErrorMessage);
    setPageComplete(posDone && typeDone && nameDone && valueDone);
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) 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)

Example 7 with TTCN3_Set_Type

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

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

the class Set_Value method setGenNameRecursive.

@Override
public /**
 * {@inheritDoc}
 */
void setGenNameRecursive(final String parameterGenName) {
    super.setGenNameRecursive(parameterGenName);
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    if (governor == null) {
        return;
    }
    final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
        for (int i = 0; i < values.getSize(); i++) {
            final String name = values.getNamedValueByIndex(i).getName().getName();
            if (((TTCN3_Set_Type) type).hasComponentWithName(name)) {
                final StringBuilder embeddedName = new StringBuilder(parameterGenName);
                embeddedName.append('.');
                embeddedName.append(name);
                embeddedName.append("()");
                if (((TTCN3_Set_Type) type).getComponentByName(name).isOptional()) {
                    embeddedName.append(".get()");
                }
                values.getNamedValueByIndex(i).getValue().setGenNameRecursive(embeddedName.toString());
            }
        }
    }
}
Also used : TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 9 with TTCN3_Set_Type

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

use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type 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)12 Identifier (org.eclipse.titan.designer.AST.Identifier)9 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)8 TTCN3_Set_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type)7 IValue (org.eclipse.titan.designer.AST.IValue)6 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)5 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)4 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)3 TTCN3_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType)3 Value (org.eclipse.titan.designer.AST.Value)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)2 Type (org.eclipse.titan.designer.AST.Type)2 ArrayList (java.util.ArrayList)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1