Search in sources :

Example 46 with Charstring_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Charstring_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 47 with Charstring_Value

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

the class Str2FloatExpression 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) {
    if (value == null) {
        return;
    }
    value.setLoweridToReference(timestamp);
    final Type_type tempType = value.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_CHARSTRING:
            final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last.isUnfoldable(timestamp)) {
                String string = ((Charstring_Value) last).getValue();
                string = string.trim();
                if (string.equals("infinity") || string.equals("-infinity") || string.equals("not_a_number")) {
                    return;
                }
                str2floatState state = str2floatState.S_INITIAL;
                // S_ERR: error was found, stop
                for (int i = 0; i < string.length(); i++) {
                    final char c = string.charAt(i);
                    switch(state) {
                        case S_INITIAL:
                            if (c == '+' || c == '-') {
                                state = str2floatState.S_FIRST_M;
                            } else if (c == '0') {
                                state = str2floatState.S_ZERO_M;
                            } else if (c >= '1' && c <= '9') {
                                state = str2floatState.S_MORE_M;
                            } else if (Character.isWhitespace(c)) {
                                value.getLocation().reportSemanticWarning("Leading whitespace was detected and ignored in the operand of operation `str2float''");
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case // first mantissa digit
                        S_FIRST_M:
                            if (c == '0') {
                                state = str2floatState.S_ZERO_M;
                            } else if (c >= '1' && c <= '9') {
                                state = str2floatState.S_MORE_M;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case // leading mantissa zero
                        S_ZERO_M:
                            if (c == '.') {
                                state = str2floatState.S_FIRST_F;
                            } else if (c == 'E' || c == 'e') {
                                state = str2floatState.S_INITIAL_E;
                            } else if (c >= '0' && c <= '9') {
                                value.getLocation().reportSemanticWarning("Leading zero digit was detected and ignored in the operand of operation `str2float''");
                                state = str2floatState.S_MORE_M;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_MORE_M:
                            if (c == '.') {
                                state = str2floatState.S_FIRST_F;
                            } else if (c == 'E' || c == 'e') {
                                state = str2floatState.S_INITIAL_E;
                            } else if (c >= '0' && c <= '9') {
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_FIRST_F:
                            if (c >= '0' && c <= '9') {
                                state = str2floatState.S_MORE_F;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_MORE_F:
                            if (c == 'E' || c == 'e') {
                                state = str2floatState.S_INITIAL_E;
                            } else if (c >= '0' && c <= '9') {
                            } else if (Character.isWhitespace(c)) {
                                state = str2floatState.S_END;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_INITIAL_E:
                            if (c == '+' || c == '-') {
                                state = str2floatState.S_FIRST_E;
                            } else if (c == '0') {
                                state = str2floatState.S_ZERO_E;
                            } else if (c >= '1' && c <= '9') {
                                state = str2floatState.S_MORE_E;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_FIRST_E:
                            if (c == '0') {
                                state = str2floatState.S_ZERO_E;
                            } else if (c >= '1' && c <= '9') {
                                state = str2floatState.S_MORE_E;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_ZERO_E:
                            if (c >= '0' && c <= '9') {
                                value.getLocation().reportSemanticWarning("Leading zero digit was detected and ignored in the exponent of the operation `str2float''");
                                state = str2floatState.S_MORE_E;
                            } else if (Character.isWhitespace(c)) {
                                state = str2floatState.S_END;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_MORE_E:
                            if (c >= '0' && c <= '9') {
                            } else if (Character.isWhitespace(c)) {
                                state = str2floatState.S_END;
                            } else {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        case S_END:
                            if (Character.isWhitespace(c)) {
                                state = str2floatState.S_ERR;
                            }
                            break;
                        default:
                            break;
                    }
                    if (state == str2floatState.S_ERR) {
                        value.getLocation().reportSemanticError(MessageFormat.format("The argument of function str2float(), which is {0}, does not represent a valid float value. Invalid character {1} was found at index {2}. ", string, c, i));
                        setIsErroneous(true);
                        break;
                    }
                }
                switch(state) {
                    case S_INITIAL:
                        value.getLocation().reportSemanticError(MessageFormat.format("The argument of function str2float(), which is {0}, should be a string containing a valid float value instead of an empty string.", string));
                        setIsErroneous(true);
                        break;
                    case S_FIRST_M:
                        value.getLocation().reportSemanticError(MessageFormat.format("The argument of function str2float(), which is {0}, should be a string containing a valid float value, but only a sign character was detected.", string));
                        setIsErroneous(true);
                        break;
                    case S_ZERO_M:
                    case S_MORE_M:
                        // OK now (decimal dot missing after mantissa)
                        break;
                    case S_FIRST_F:
                        // OK now (fraction part missing)
                        break;
                    case S_INITIAL_E:
                    case S_FIRST_E:
                        value.getLocation().reportSemanticError(MessageFormat.format("The argument of function str2float(), which is {0}, should be a string containing a valid float value, but the exponent is missing after the `E' sign.", string));
                        setIsErroneous(true);
                        break;
                    case S_END:
                        // trailing whitespace is ok.
                        break;
                    default:
                        break;
                }
            }
            return;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            return;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
            }
            return;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 48 with Charstring_Value

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

the class Str2IntExpression 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:
            {
                String string = ((Charstring_Value) last).getValue();
                string = string.trim();
                try {
                    lastValue = new Integer_Value(string);
                } catch (NumberFormatException e) {
                    // It seems to be a double check. The string
                    // must hold a
                    // valid number at this point. The exception is
                    // thrown by
                    // BigInteger not Integer_Value.
                    lastValue = new Integer_Value(0L);
                }
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 49 with Charstring_Value

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

the class Str2OctExpression 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 Octetstring_Value(string.toUpperCase());
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 50 with Charstring_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Charstring_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)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)53 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)44 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)17 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)16 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)13 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)13 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)12 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)11 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)11 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)9 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)6 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)6 IType (org.eclipse.titan.designer.AST.IType)5 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)4 Reference (org.eclipse.titan.designer.AST.Reference)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 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)4 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)3