Search in sources :

Example 31 with Real_Value

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

the class UnaryMinusExpression 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 INTEGER_VALUE:
            lastValue = ((Integer_Value) last).negate();
            lastValue.copyGeneralProperties(this);
            break;
        case REAL_VALUE:
            final double tempFloat = ((Real_Value) last).getValue();
            lastValue = new Real_Value(-1 * tempFloat);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 32 with Real_Value

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

the class ValueRange method generateCodeInit.

/**
 * Add generated java code for initializing a template
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param source the source for code generated
 * @param name the name to init
 */
public void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    aData.addBuiltinTypeImport("Base_Template.template_sel");
    final ExpressionStruct expression = new ExpressionStruct();
    final StringBuilder initStatement = new StringBuilder();
    initStatement.append(name);
    initStatement.append(".setType( template_sel.VALUE_RANGE );\n");
    if (min != null) {
        final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = min.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), chain);
        chain.release();
        if (!last.getValuetype().equals(Value_type.REAL_VALUE) || ((Real_Value) last).getValue() != Double.NEGATIVE_INFINITY) {
            last.generateCodeExpression(aData, expression, false);
            initStatement.append(name);
            initStatement.append(".setMin( ");
            initStatement.append(expression.expression);
            initStatement.append(" );\n");
        }
    }
    if (minExclusive) {
        switch(typeType) {
            case TYPE_INTEGER:
            case TYPE_REAL:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                initStatement.append(name);
                initStatement.append(".setMinExclusive(true);\n");
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing lower bound `" + getFullName() + "''");
        }
    }
    if (max != null) {
        final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = max.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), chain);
        chain.release();
        if (!last.getValuetype().equals(Value_type.REAL_VALUE) || ((Real_Value) last).getValue() != Double.POSITIVE_INFINITY) {
            expression.expression = new StringBuilder();
            last.generateCodeExpression(aData, expression, false);
            initStatement.append(name);
            initStatement.append(".setMax( ");
            initStatement.append(expression.expression);
            initStatement.append(" );\n");
        }
    }
    if (maxExclusive) {
        switch(typeType) {
            case TYPE_INTEGER:
            case TYPE_REAL:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                initStatement.append(name);
                initStatement.append(".setMaxExclusive(true);\n");
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing upper bound `" + getFullName() + "''");
        }
    }
    if (expression.preamble.length() > 0 || expression.postamble.length() > 0) {
        source.append("{\n");
        source.append(expression.preamble);
        source.append(initStatement);
        source.append(expression.postamble);
        source.append("}\n");
    } else {
        source.append(initStatement);
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 33 with Real_Value

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

the class Integer_Type method checkBoundary.

private IValue checkBoundary(final CompilationTimeStamp timestamp, final Value value, final BOUNDARY_TYPE btype) {
    if (value == null) {
        return null;
    }
    value.setMyGovernor(this);
    IValue temp = checkThisValueRef(timestamp, value);
    checkThisValueLimit(timestamp, temp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false);
    temp = temp.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
    if (Value_type.REAL_VALUE.equals(temp.getValuetype())) {
        if (((Real_Value) temp).isNegativeInfinity()) {
            if (BOUNDARY_TYPE.UPPER.equals(btype)) {
                value.getLocation().reportSemanticError(INCORRECTUPPERBOUNDARY);
                value.setIsErroneous(true);
            }
            return temp;
        } else if (((Real_Value) temp).isPositiveInfinity()) {
            if (BOUNDARY_TYPE.LOWER.equals(btype)) {
                value.getLocation().reportSemanticError(INCORRECTLOWERBOUNDARY);
                value.setIsErroneous(true);
            }
            return temp;
        } else {
            value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
            value.setIsErroneous(true);
            return null;
        }
    }
    switch(temp.getValuetype()) {
        case INTEGER_VALUE:
            break;
        default:
            temp = null;
            break;
    }
    return temp;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 34 with Real_Value

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

the class Integer_Type method checkThisValueLimit.

/**
 * Checks if a given value is a valid integer limit.
 * <p>
 * The special float values infinity and -infinity are valid integer range limits too.
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expectedValue the kind of the value to be expected
 * @param incompleteAllowed true if an incomplete value can be accepted at the given location, false otherwise
 * @param omitAllowed true if the omit value can be accepted at the given location, false otherwise
 * @param subCheck true if the subtypes should also be checked.
 * @param implicitOmit true if the implicit omit optional attribute was set for the value, false otherwise
 */
public void checkThisValueLimit(final CompilationTimeStamp timestamp, final IValue value, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean omitAllowed, final boolean subCheck, final boolean implicitOmit) {
    super.checkThisValue(timestamp, value, null, new ValueCheckingOptions(expectedValue, incompleteAllowed, omitAllowed, subCheck, implicitOmit, false));
    final IValue last = value.getValueRefdLast(timestamp, expectedValue, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            break;
        case REAL_VALUE:
            {
                final Real_Value real = (Real_Value) last;
                if (!real.isNegativeInfinity() && !real.isPositiveInfinity()) {
                    value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
                    value.setIsErroneous(true);
                }
                break;
            }
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
            value.setIsErroneous(true);
    }
    if (subCheck) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)33 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)27 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 IType (org.eclipse.titan.designer.AST.IType)9 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)9 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)5 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)5 Assignment (org.eclipse.titan.designer.AST.Assignment)4 EnumItem (org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)4 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)4 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)2 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2