Search in sources :

Example 16 with Octetstring_Value

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

the class Or4bExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    String str1;
    String str2;
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            str1 = ((Bitstring_Value) last1).getValue();
            str2 = ((Bitstring_Value) last2).getValue();
            lastValue = new Bitstring_Value(or4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            str1 = ((Hexstring_Value) last1).getValue();
            str2 = ((Hexstring_Value) last2).getValue();
            lastValue = new Hexstring_Value(or4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            str1 = ((Octetstring_Value) last1).getValue();
            str2 = ((Octetstring_Value) last2).getValue();
            lastValue = new Octetstring_Value(or4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 17 with Octetstring_Value

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

the class EncodeBase64Expression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case OCTETSTRING_VALUE:
            {
                final String octetString = ((Octetstring_Value) last).getValue();
                lastValue = new Charstring_Value(calculateValue(octetString));
                lastValue.copyGeneralProperties(this);
                break;
            }
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)

Example 18 with Octetstring_Value

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

the class And4bExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        setIsErroneous(true);
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    String str1;
    String str2;
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            str1 = ((Bitstring_Value) last1).getValue();
            str2 = ((Bitstring_Value) last2).getValue();
            lastValue = new Bitstring_Value(and4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            str1 = ((Hexstring_Value) last1).getValue();
            str2 = ((Hexstring_Value) last2).getValue();
            lastValue = new Hexstring_Value(and4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            str1 = ((Octetstring_Value) last1).getValue();
            str2 = ((Octetstring_Value) last2).getValue();
            lastValue = new Octetstring_Value(and4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 19 with Octetstring_Value

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

the class Assignment_Statement method checkVarAssignment.

private void checkVarAssignment(final CompilationTimeStamp timestamp, final Assignment assignment, final IValue value) {
    final IType varType = getType(timestamp, assignment);
    if (varType == null || value == null) {
        isErroneous = true;
        return;
    }
    final IType type = varType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (type == null) {
        isErroneous = true;
        return;
    }
    value.setMyGovernor(type);
    IValue lastValue = type.checkThisValueRef(timestamp, value);
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    lastValue = lastValue.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (Value_type.OMIT_VALUE.equals(lastValue.getValuetype())) {
        final ISubReference lastReference = reference.removeLastSubReference();
        if (lastReference == null || lastReference.getId() == null) {
            value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
            isErroneous = true;
            reference.addSubReference(lastReference);
            return;
        }
        final Identifier lastField = lastReference.getId();
        final List<ISubReference> baseReference = reference.getSubreferences(0, reference.getSubreferences().size() - 1);
        reference.addSubReference(lastReference);
        final Reference newReference = new TemporalReference(null, baseReference);
        newReference.clearStringElementReferencing();
        IType baseType = varType.getFieldType(timestamp, newReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
        if (baseType == null) {
            isErroneous = true;
            return;
        }
        baseType = baseType.getTypeRefdLast(timestamp);
        if (baseType.getIsErroneous(timestamp)) {
            isErroneous = true;
            return;
        }
        CompField componentField;
        switch(baseType.getTypetype()) {
            case TYPE_TTCN3_SEQUENCE:
                componentField = ((TTCN3_Sequence_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SEQUENCE:
                componentField = ((ASN1_Sequence_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_TTCN3_SET:
                componentField = ((TTCN3_Set_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SET:
                componentField = ((ASN1_Set_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            default:
                // TODO:check this!!!
                value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
                value.setIsErroneous(true);
                isErroneous = true;
                break;
        }
    } else {
        final boolean isStringElement = reference.refersToStringElement();
        selfReference = type.checkThisValue(timestamp, value, assignment, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, !isStringElement, false, isStringElement));
        if (isStringElement) {
            // The length of the right hand side should be 1
            final IType lastType = type.getTypeRefdLast(timestamp);
            int stringLength = 1;
            switch(lastType.getTypetype()) {
                case TYPE_BITSTRING:
                case TYPE_BITSTRING_A:
                    if (!Value_type.BITSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Bitstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_HEXSTRING:
                    if (!Value_type.HEXSTRING_VALUE.equals(lastValue.getValuetype())) {
                        lastValue = null;
                    } else {
                        stringLength = ((Hexstring_Value) lastValue).getValueLength();
                    }
                    break;
                case TYPE_OCTETSTRING:
                    if (!Value_type.OCTETSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Octetstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_CHARSTRING:
                case TYPE_NUMERICSTRING:
                case TYPE_PRINTABLESTRING:
                case TYPE_IA5STRING:
                case TYPE_VISIBLESTRING:
                case TYPE_UTCTIME:
                case TYPE_GENERALIZEDTIME:
                    if (!Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Charstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_UCHARSTRING:
                case TYPE_UTF8STRING:
                case TYPE_TELETEXSTRING:
                case TYPE_VIDEOTEXSTRING:
                case TYPE_GRAPHICSTRING:
                case TYPE_GENERALSTRING:
                case TYPE_UNIVERSALSTRING:
                case TYPE_BMPSTRING:
                case TYPE_OBJECTDESCRIPTOR:
                    if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((UniversalCharstring_Value) lastValue).getValueLength();
                    } else if (Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((Charstring_Value) lastValue).getValueLength();
                    } else {
                        return;
                    }
                    break;
                default:
                    lastValue = null;
                    return;
            }
            if (stringLength != 1) {
                final String message = MessageFormat.format("The length of the string to be assigned to a string element of type `{0}'' should be 1 instead of {1}", type.getTypename(), stringLength);
                value.getLocation().reportSemanticError(message);
                value.setIsErroneous(true);
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) IType(org.eclipse.titan.designer.AST.IType) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 20 with Octetstring_Value

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

the class SubType method addTtcnSingle.

/**
 * add TTCN-3 single value sub-type constraint to this sub-type
 */
private boolean addTtcnSingle(final CompilationTimeStamp timestamp, final Value value, final int restrictionIndex) {
    value.setMyScope(myOwner.getMyScope());
    value.setMyGovernor(myOwner);
    final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getTypename() + ".<single_restriction_" + restrictionIndex + ">");
    value.setFullNameParent(bridge);
    IValue last = myOwner.checkThisValueRef(timestamp, value);
    // check if this is type reference, if not then fall through
    final IValue refValue = value.setLoweridToReference(timestamp);
    // Value_type.REFERENCED_VALUE);
    if (refValue.getValuetype() == Value.Value_type.REFERENCED_VALUE) {
        final Reference ref = ((Referenced_Value) refValue).getReference();
        final Assignment ass = ref.getRefdAssignment(timestamp, false);
        if (ass == null) {
            // definition was not found, error was reported
            return false;
        }
        if (ass.getAssignmentType() == Assignment.Assignment_type.A_TYPE) {
            IType t = ass.getType(timestamp);
            t.check(timestamp);
            if (t.getIsErroneous(timestamp)) {
                return false;
            }
            final List<ISubReference> subrefs = ref.getSubreferences();
            if (subrefs.size() > 1) {
                // if there were sub-references then get the referenced field's type
                t = t.getFieldType(timestamp, ref, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
                if ((t == null) || t.getIsErroneous(timestamp)) {
                    return false;
                }
                t.check(timestamp);
                if (t.getIsErroneous(timestamp)) {
                    return false;
                }
            }
            if (!t.isIdentical(timestamp, myOwner)) {
                value.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' must refer to a type which has the same root type as this type", ref.getDisplayName()));
                return false;
            }
            // check subtype of referenced type
            final SubType tSt = t.getSubtype();
            if ((tSt == null) || (tSt.subtypeConstraint == null)) {
                value.getLocation().reportSemanticError(MessageFormat.format("Type referenced by `{0}'' does not have a subtype", ref.getDisplayName()));
                return false;
            }
            // check circular sub-type reference
            if (!addParentSubtype(tSt)) {
                return false;
            }
            if (tSt.getIsErroneous(timestamp)) {
                return false;
            }
            if (tSt.subtypeType != subtypeType) {
                ErrorReporter.INTERNAL_ERROR();
                return false;
            }
            // add the sub-type as union
            if (subtypeConstraint == null) {
                subtypeConstraint = tSt.subtypeConstraint;
            } else {
                subtypeConstraint = subtypeConstraint.union(tSt.subtypeConstraint);
            }
            return true;
        }
    }
    myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    last = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp) || last.isUnfoldable(timestamp)) {
        return false;
    }
    // create a single value constraint
    SubtypeConstraint sc;
    switch(subtypeType) {
        case ST_INTEGER:
            sc = new RangeListConstraint(new IntegerLimit(((Integer_Value) last).getValueValue()));
            break;
        case ST_FLOAT:
            sc = new RealRangeListConstraint(((Real_Value) last).getValue());
            break;
        case ST_BOOLEAN:
            sc = new BooleanListConstraint(((Boolean_Value) last).getValue());
            break;
        case ST_VERDICTTYPE:
            sc = new VerdicttypeListConstraint(((Verdict_Value) last).getValue());
            break;
        case ST_BITSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.BITSTRING, ((Bitstring_Value) last).getValue());
            break;
        case ST_HEXSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.HEXSTRING, ((Hexstring_Value) last).getValue());
            break;
        case ST_OCTETSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.OCTETSTRING, ((Octetstring_Value) last).getValue());
            break;
        case ST_CHARSTRING:
            if (last.getValuetype() != Value.Value_type.CHARSTRING_VALUE) {
                return false;
            }
            sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new StringValueConstraint(((Charstring_Value) last).getValue()));
            break;
        case ST_UNIVERSAL_CHARSTRING:
            switch(last.getValuetype()) {
                case CHARSTRING_VALUE:
                    sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(new UniversalCharstring(((Charstring_Value) last).getValue())));
                    break;
                case UNIVERSALCHARSTRING_VALUE:
                    sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(((UniversalCharstring_Value) last).getValue()));
                    break;
                default:
                    return false;
            }
            break;
        case ST_OBJID:
        case ST_ENUM:
        case ST_UNION:
        case ST_RECORD:
        case ST_SET:
        case ST_FUNCTION:
        case ST_ALTSTEP:
        case ST_TESTCASE:
            sc = new ValueListConstraint(last);
            break;
        case ST_RECORDOF:
        case ST_SETOF:
            sc = new ValueListAndSizeConstraint(last);
            break;
        default:
            ErrorReporter.INTERNAL_ERROR();
            return false;
    }
    // add next value using union operation
    if (subtypeConstraint == null) {
        subtypeConstraint = sc;
    } else {
        subtypeConstraint = subtypeConstraint.union(sc);
    }
    return true;
}
Also used : IType(org.eclipse.titan.designer.AST.IType) Assignment(org.eclipse.titan.designer.AST.Assignment) 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) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) ISubReference(org.eclipse.titan.designer.AST.ISubReference)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)40 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)28 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)17 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)17 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)15 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)15 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)9 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)7 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)6 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)4 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)3 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IType (org.eclipse.titan.designer.AST.IType)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2