Search in sources :

Example 11 with Sequence_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Sequence_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case SEQUENCE_VALUE:
            if (last.isAsn()) {
                selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case SEQUENCEOF_VALUE:
            if (((SequenceOf_Value) last).isIndexed()) {
                value.getLocation().reportSemanticError(MessageFormat.format("Indexed assignment notation cannot be used for record type `{0}''", getFullName()));
                value.setIsErroneous(true);
            } else {
                last = last.setValuetype(timestamp, Value_type.SEQUENCE_VALUE);
                if (last.isAsn()) {
                    selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
                } else {
                    selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
                }
            }
            break;
        case UNDEFINED_BLOCK:
            last = last.setValuetype(timestamp, Value_type.SEQUENCE_VALUE);
            selfReference = checkThisValueSeq(timestamp, (Sequence_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(SEQUANCEEPECTED, getFullName()));
            value.setIsErroneous(true);
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)

Example 12 with Sequence_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value in project titan.EclipsePlug-ins by eclipse.

the class SubType method checkThisValue.

/**
 * Checks if a given value is valid according to this sub-type.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 */
public void checkThisValue(final CompilationTimeStamp timestamp, final IValue value) {
    if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
        return;
    }
    if (value.getIsErroneous(timestamp)) {
        return;
    }
    final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    boolean isValid = true;
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            if (subtypeType != SubType_type.ST_INTEGER) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(new IntegerLimit(((Integer_Value) last).getValueValue()));
            break;
        case REAL_VALUE:
            if (subtypeType == SubType_type.ST_FLOAT) {
                isValid = subtypeConstraint.isElement(((Real_Value) last).getValue());
                break;
            } else if (subtypeType == SubType_type.ST_INTEGER) {
                final Real_Value real = (Real_Value) last;
                if (real.isNegativeInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MINIMUM);
                    break;
                } else if (real.isPositiveInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MAXIMUM);
                    break;
                }
            }
            ErrorReporter.INTERNAL_ERROR();
            return;
        case BOOLEAN_VALUE:
            if (subtypeType != SubType_type.ST_BOOLEAN) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Boolean_Value) last).getValue());
            break;
        case VERDICT_VALUE:
            if (subtypeType != SubType_type.ST_VERDICTTYPE) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Verdict_Value) last).getValue());
            break;
        case BITSTRING_VALUE:
            if (subtypeType != SubType_type.ST_BITSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Bitstring_Value) last).getValue());
            break;
        case HEXSTRING_VALUE:
            if (subtypeType != SubType_type.ST_HEXSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Hexstring_Value) last).getValue());
            break;
        case OCTETSTRING_VALUE:
            if (subtypeType != SubType_type.ST_OCTETSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Octetstring_Value) last).getValue());
            break;
        case CHARSTRING_VALUE:
            switch(subtypeType) {
                case ST_CHARSTRING:
                    isValid = subtypeConstraint.isElement(((Charstring_Value) last).getValue());
                    break;
                case ST_UNIVERSAL_CHARSTRING:
                    isValid = subtypeConstraint.isElement(new UniversalCharstring(((Charstring_Value) last).getValue()));
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR();
                    return;
            }
            break;
        case UNIVERSALCHARSTRING_VALUE:
            if (subtypeType != SubType_type.ST_UNIVERSAL_CHARSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((UniversalCharstring_Value) last).getValue());
            break;
        case SEQUENCEOF_VALUE:
        case SETOF_VALUE:
        case OBJECTID_VALUE:
        case ENUMERATED_VALUE:
        case CHOICE_VALUE:
        case SEQUENCE_VALUE:
        case SET_VALUE:
        case FUNCTION_REFERENCE_VALUE:
        case ALTSTEP_REFERENCE_VALUE:
        case TESTCASE_REFERENCE_VALUE:
            if (value.isUnfoldable(timestamp)) {
                return;
            }
            isValid = subtypeConstraint.isElement(last);
            break;
        default:
            return;
    }
    if (!isValid) {
        value.getLocation().reportSemanticError(MessageFormat.format("{0} is not a valid value for type `{1}'' which has subtype {2}", last.createStringRepresentation(), myOwner.getTypename(), subtypeConstraint.toString()));
    }
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 13 with Sequence_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Set_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case SEQUENCE_VALUE:
            last = last.setValuetype(timestamp, Value_type.SET_VALUE);
            if (last.isAsn()) {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case SEQUENCEOF_VALUE:
            if (((SequenceOf_Value) last).isIndexed()) {
                value.getLocation().reportSemanticError(MessageFormat.format("Indexed assignment notation cannot be used for SET type `{0}''", getFullName()));
                value.setIsErroneous(true);
            } else {
                final SequenceOf_Value temporalValue = (SequenceOf_Value) last;
                if (temporalValue.getNofComponents() == 0) {
                    if (getNofComponents(timestamp) == 0) {
                        last = last.setValuetype(timestamp, Value_type.SET_VALUE);
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format(NONEMPTYEXPECTED, getFullName()));
                        value.setIsErroneous(true);
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? VALUELISTNOTATIONERRORASN1 : VALUELISTNOTATIONERRORTTCN3, getFullName()));
                    value.setIsErroneous(true);
                }
            }
            break;
        case SET_VALUE:
            if (last.isAsn()) {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case UNDEFINED_BLOCK:
            last = last.setValuetype(timestamp, Value_type.SET_VALUE);
            selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? SETVALUEXPECTEDASN1 : SETVALUEXPECTEDTTCN3, getFullName()));
            value.setIsErroneous(true);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Set_Value(org.eclipse.titan.designer.AST.TTCN3.values.Set_Value)

Example 14 with Sequence_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value in project titan.EclipsePlug-ins by eclipse.

the class Open_Type method checkThisValue.

// FIXME add tests
@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (null == last || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    this.check(timestamp);
    switch(last.getValuetype()) {
        case SEQUENCE_VALUE:
            if (value.isAsn()) {
                value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
                value.setIsErroneous(true);
            } else {
                last = last.setValuetype(timestamp, Value_type.CHOICE_VALUE);
                if (!last.getIsErroneous(timestamp)) {
                    selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
                }
            }
            break;
        case CHOICE_VALUE:
            selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
            break;
        default:
            if (value.isAsn()) {
                value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
            } else {
                value.getLocation().reportSemanticError(MessageFormat.format(UNIONEXPECTED, getFullName()));
            }
            value.setIsErroneous(true);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Choice_Value(org.eclipse.titan.designer.AST.TTCN3.values.Choice_Value)

Example 15 with Sequence_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value in project titan.EclipsePlug-ins by eclipse.

the class Sequence_Value method checkEquality.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkEquality(final CompilationTimeStamp timestamp, final IValue other) {
    if (convertedValue != null && convertedValue != this) {
        return convertedValue.checkEquality(timestamp, other);
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = other.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (!Value_type.SEQUENCE_VALUE.equals(last.getValuetype())) {
        return false;
    }
    if (myGovernor == null) {
        return false;
    }
    final Sequence_Value otherSequence = (Sequence_Value) last;
    if (values.getSize() != otherSequence.values.getSize()) {
        return false;
    }
    int nofComps = 0;
    final IType leftGovernor = myGovernor.getTypeRefdLast(timestamp);
    switch(leftGovernor.getTypetype()) {
        case TYPE_TTCN3_SEQUENCE:
            nofComps = ((TTCN3_Sequence_Type) leftGovernor).getNofComponents();
            break;
        case TYPE_ASN1_SEQUENCE:
            nofComps = ((ASN1_Sequence_Type) leftGovernor).getNofComponents(timestamp);
            break;
        default:
            return false;
    }
    CompField compField = null;
    for (int i = 0; i < nofComps; i++) {
        switch(leftGovernor.getTypetype()) {
            case TYPE_TTCN3_SEQUENCE:
                compField = ((TTCN3_Sequence_Type) leftGovernor).getComponentByIndex(i);
                break;
            case TYPE_ASN1_SEQUENCE:
                compField = ((ASN1_Sequence_Type) leftGovernor).getComponentByIndex(i);
                break;
            default:
                return false;
        }
        final Identifier fieldName = compField.getIdentifier();
        if (hasComponentWithName(fieldName)) {
            final IValue leftValue = getComponentByName(fieldName).getValue();
            if (otherSequence.hasComponentWithName(fieldName)) {
                final IValue otherValue = otherSequence.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 (otherSequence.hasComponentWithName(fieldName)) {
                final IValue otherValue = otherSequence.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)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)16 Sequence_Value (org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value)6 IType (org.eclipse.titan.designer.AST.IType)5 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Identifier (org.eclipse.titan.designer.AST.Identifier)4 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)4 Type (org.eclipse.titan.designer.AST.Type)4 HashMap (java.util.HashMap)3 Choice_Value (org.eclipse.titan.designer.AST.TTCN3.values.Choice_Value)3 Location (org.eclipse.titan.designer.AST.Location)2 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)2 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)2 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)2 Omit_Value (org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)2 Set_Value (org.eclipse.titan.designer.AST.TTCN3.values.Set_Value)2 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 InsertEdit (org.eclipse.text.edits.InsertEdit)1 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)1