Search in sources :

Example 16 with UniversalCharstring_Value

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

the class RotateRightExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    Type_type tempType1 = null;
    Type_type tempType2 = null;
    long valueSize = 0;
    long rotationSize = 0;
    IValue tempValue;
    if (value1 != null) {
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType1) {
            case TYPE_BITSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.BITSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Bitstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_HEXSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Hexstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_OCTETSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Octetstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_CHARSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.CHARSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Charstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_UCHARSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((UniversalCharstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_SET_OF:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    tempValue = tempValue.setValuetype(timestamp, Value_type.SETOF_VALUE);
                }
                if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SetOf_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_SEQUENCE_OF:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SequenceOf_Value) tempValue).getNofComponents();
                } else if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SetOf_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_ARRAY:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    tempValue = tempValue.setValuetype(timestamp, Value_type.ARRAY_VALUE);
                }
                if (Value_type.ARRAY_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Array_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(FIRSTOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_INTEGER:
                tempValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.INTEGER_VALUE.equals(tempValue.getValuetype()) && !getIsErroneous(timestamp)) {
                    if (!((Integer_Value) tempValue).isNative()) {
                        value2.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERSECONDOPERANDERROR, ((Integer_Value) tempValue).getValueValue()));
                        setIsErroneous(true);
                        break;
                    }
                    rotationSize = ((Integer_Value) tempValue).getValue();
                    if (value1 != null && !value1.isUnfoldable(timestamp)) {
                        final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINCORRECTSHIFTROTATESIZE, GeneralConstants.WARNING, null);
                        if (valueSize == 0 || valueSize == 1) {
                            location.reportConfigurableSemanticProblem(severity, EFFECTLESSROTATION);
                        } else if (rotationSize < 0) {
                            location.reportConfigurableSemanticProblem(severity, NEGATIVEROTATEPROBLEM);
                        } else if (rotationSize == 0) {
                            location.reportConfigurableSemanticProblem(severity, ZEROROTATEPROBLEM);
                        } else if (rotationSize > valueSize) {
                            location.reportConfigurableSemanticProblem(severity, MessageFormat.format(TOOBIGROTATEPROBLEM, valueSize, rotationSize, rotationSize % valueSize));
                        }
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(SECONDOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)

Example 17 with UniversalCharstring_Value

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

the class Int2UnicharExpression 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)) {
        return lastValue;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            {
                final long i = ((Integer_Value) last).getValue();
                final long group = (i >> 24) & 0xFF;
                final long plane = (i >> 16) & 0xFF;
                final long row = (i >> 8) & 0xFF;
                final long cell = i & 0xFF;
                lastValue = new UniversalCharstring_Value(new UniversalCharstring(new UniversalChar((int) group, (int) plane, (int) row, (int) cell)));
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Example 18 with UniversalCharstring_Value

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

the class LengthofExpression 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 (templateInstance == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody();
    final IValue value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
    int length;
    switch(value.getValuetype()) {
        case CHARSTRING_VALUE:
            length = ((Charstring_Value) value).getValueLength();
            break;
        case UNIVERSALCHARSTRING_VALUE:
            length = ((UniversalCharstring_Value) value).getValueLength();
            break;
        case BITSTRING_VALUE:
            length = ((Bitstring_Value) value).getValueLength();
            break;
        case HEXSTRING_VALUE:
            length = ((Hexstring_Value) value).getValueLength();
            break;
        case OCTETSTRING_VALUE:
            length = ((Octetstring_Value) value).getValueLength();
            break;
        case SEQUENCEOF_VALUE:
            length = ((SequenceOf_Value) value).getNofComponents();
            break;
        case SETOF_VALUE:
            length = ((SetOf_Value) value).getNofComponents();
            break;
        case ARRAY_VALUE:
            length = ((Array_Value) value).getNofComponents();
            break;
        default:
            setIsErroneous(true);
            return lastValue;
    }
    lastValue = new Integer_Value(length);
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 19 with UniversalCharstring_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_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 20 with UniversalCharstring_Value

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

the class Unichar2CharExpression 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)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case UNIVERSALCHARSTRING_VALUE:
            {
                final UniversalCharstring string = ((UniversalCharstring_Value) last).getValue();
                final UniversalChar uchar = string.get(0);
                final byte[] bytes = new byte[] { (byte) uchar.cell() };
                lastValue = new Charstring_Value(new String(bytes));
                break;
            }
        case CHARSTRING_VALUE:
            {
                lastValue = new Charstring_Value(((Charstring_Value) last).getValue());
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)23 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)14 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)14 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)11 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)9 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)8 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)7 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)7 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)5 UniversalChar (org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar)5 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 IType (org.eclipse.titan.designer.AST.IType)3 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)3 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)2