Search in sources :

Example 31 with Bitstring_Value

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

the class Str2BitExpression 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) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    if (last.getIsErroneous(timestamp)) {
        return lastValue;
    }
    switch(last.getValuetype()) {
        case CHARSTRING_VALUE:
            final String string = ((Charstring_Value) last).getValue();
            lastValue = new Bitstring_Value(string);
            break;
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : 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)

Example 32 with Bitstring_Value

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

the class SubstrExpression method checkExpressionOperandsHelper.

private void checkExpressionOperandsHelper(final CompilationTimeStamp timestamp, final IValue value1, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (value1 == null || value2 == null || value3 == null || getIsErroneous(timestamp)) {
        return;
    }
    long valueSize = -1;
    if (!value1.isUnfoldable(timestamp)) {
        IValue temp = value1.setLoweridToReference(timestamp);
        temp = temp.getValueRefdLast(timestamp, referenceChain);
        switch(temp.getValuetype()) {
            case BITSTRING_VALUE:
                valueSize = ((Bitstring_Value) temp).getValueLength();
                break;
            case HEXSTRING_VALUE:
                valueSize = ((Hexstring_Value) temp).getValueLength();
                break;
            case OCTETSTRING_VALUE:
                valueSize = ((Octetstring_Value) temp).getValueLength();
                break;
            case CHARSTRING_VALUE:
                valueSize = ((Charstring_Value) temp).getValueLength();
                break;
            case UNIVERSALCHARSTRING_VALUE:
                valueSize = ((UniversalCharstring_Value) temp).getValueLength();
                break;
            case SEQUENCEOF_VALUE:
                valueSize = ((SequenceOf_Value) temp).getNofComponents();
                if (valueSize == 0) {
                    templateInstance1.getLocation().reportSemanticError(OPERANDERROR11);
                }
                break;
            case SETOF_VALUE:
                valueSize = ((SetOf_Value) temp).getNofComponents();
                if (valueSize == 0) {
                    templateInstance1.getLocation().reportSemanticError(OPERANDERROR11);
                }
                break;
            default:
                break;
        }
    }
    if (valueSize < 0) {
        return;
    }
    if (value2.isUnfoldable(timestamp)) {
        if (!value3.isUnfoldable(timestamp)) {
            final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
            final long last3Value = ((Integer_Value) last3).getValue();
            if (last3Value > valueSize) {
                location.reportSemanticError(MessageFormat.format(OPERANDERROR6, last3Value, valueSize));
                setIsErroneous(true);
            }
        }
    } else {
        final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
        final long last2Value = ((Integer_Value) last2).getValue();
        if (value3.isUnfoldable(timestamp)) {
            if (last2Value > valueSize) {
                location.reportSemanticError(MessageFormat.format(OPERANDERROR7, last2Value, valueSize));
                setIsErroneous(true);
            }
        } else {
            final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
            final long last3Value = ((Integer_Value) last3).getValue();
            if (last2Value + last3Value > valueSize) {
                location.reportSemanticError(MessageFormat.format(OPERANDERROR8, last2Value, last3Value, valueSize));
                setIsErroneous(true);
            }
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 33 with Bitstring_Value

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

the class Hex2BitExpression 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 HEXSTRING_VALUE:
            final String temp = ((Hexstring_Value) last).getValue();
            lastValue = new Bitstring_Value(hex2bit(temp));
            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)

Example 34 with Bitstring_Value

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

the class IncorrectRotate method getFirstRotateOperandLength.

/**
 * @param ct the compilation timestamp to be used
 * @param value the first operand of the rotate operation
 * @return the length of the first operand if it can be determined
 */
private static long getFirstRotateOperandLength(final CompilationTimeStamp ct, final Value value) {
    if (value == null) {
        return 0;
    }
    final Type_type tempType = value.getExpressionReturntype(ct, null);
    final IValue refd = value.getValueRefdLast(ct, null);
    long valueSize = 0;
    switch(tempType) {
        case TYPE_BITSTRING:
            if (Value_type.BITSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Bitstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_HEXSTRING:
            if (Value_type.HEXSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Hexstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_OCTETSTRING:
            if (Value_type.OCTETSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Octetstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_CHARSTRING:
            if (Value_type.CHARSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Charstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_UCHARSTRING:
            if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((UniversalCharstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_SET_OF:
            if (Value_type.SEQUENCEOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SequenceOf_Value) value).getNofComponents();
            } else if (Value_type.SETOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SetOf_Value) value).getNofComponents();
            }
            break;
        case TYPE_SEQUENCE_OF:
            if (Value_type.SEQUENCEOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SequenceOf_Value) value).getNofComponents();
            } else if (Value_type.SETOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SetOf_Value) value).getNofComponents();
            }
            break;
        case TYPE_ARRAY:
            if (Value_type.SEQUENCEOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SequenceOf_Value) value).getNofComponents();
            }
            if (Value_type.ARRAY_VALUE.equals(value.getValuetype())) {
                valueSize = ((Array_Value) value).getNofComponents();
            }
            break;
        default:
            break;
    }
    return valueSize;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)

Example 35 with Bitstring_Value

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

the class SpecificValue_Template method checkTemplateSpecificLengthRestriction.

@Override
protected /**
 * {@inheritDoc}
 */
void checkTemplateSpecificLengthRestriction(final CompilationTimeStamp timestamp, final Type_type typeType) {
    IValue value = getValue();
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    value = value.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    switch(value.getValuetype()) {
        case BITSTRING_VALUE:
            if (Type_type.TYPE_BITSTRING.equals(typeType)) {
                lengthRestriction.checkNofElements(timestamp, ((Bitstring_Value) value).getValueLength(), false, false, false, this);
            }
            break;
        case HEXSTRING_VALUE:
            if (Type_type.TYPE_HEXSTRING.equals(typeType)) {
                lengthRestriction.checkNofElements(timestamp, ((Hexstring_Value) value).getValueLength(), false, false, false, this);
            }
            break;
        case OCTETSTRING_VALUE:
            if (Type_type.TYPE_OCTETSTRING.equals(typeType)) {
                lengthRestriction.checkNofElements(timestamp, ((Octetstring_Value) value).getValueLength(), false, false, false, this);
            }
            break;
        case CHARSTRING_VALUE:
            if (Type_type.TYPE_CHARSTRING.equals(typeType)) {
                lengthRestriction.checkNofElements(timestamp, ((Charstring_Value) value).getValueLength(), false, false, false, this);
            } else if (Type_type.TYPE_UCHARSTRING.equals(typeType)) {
                value = value.setValuetype(timestamp, Value_type.UNIVERSALCHARSTRING_VALUE);
                lengthRestriction.checkNofElements(timestamp, ((UniversalCharstring_Value) value).getValueLength(), false, false, false, this);
            }
            break;
        case UNIVERSALCHARSTRING_VALUE:
            if (Type_type.TYPE_UCHARSTRING.equals(typeType)) {
                lengthRestriction.checkNofElements(timestamp, ((UniversalCharstring_Value) value).getValueLength(), false, false, false, this);
            }
            break;
        case SEQUENCEOF_VALUE:
            if (Type_type.TYPE_SEQUENCE_OF.equals(typeType)) {
                lengthRestriction.checkNofElements(timestamp, ((SequenceOf_Value) value).getNofComponents(), false, false, false, this);
            }
            break;
        case SETOF_VALUE:
            if (Type_type.TYPE_SET_OF.equals(typeType)) {
                lengthRestriction.checkNofElements(timestamp, ((SetOf_Value) value).getNofComponents(), false, false, false, this);
            }
            break;
        case OMIT_VALUE:
            lengthRestriction.getLocation().reportSemanticError("Length restriction cannot be used with omit value");
            break;
        default:
            // they are either correct or not applicable to the type
            break;
    }
}
Also used : UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)33 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)25 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_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 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)12 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)9 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)6 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)4 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)4 IType (org.eclipse.titan.designer.AST.IType)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 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Reference (org.eclipse.titan.designer.AST.Reference)2