Search in sources :

Example 46 with Expected_Value_type

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

the class SubstractExpression 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)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            // If the operands exist they must be of the same type.
            lastValue = ((Integer_Value) last1).subtract((Integer_Value) last2);
            lastValue.copyGeneralProperties(this);
            break;
        case REAL_VALUE:
            final double f1 = ((Real_Value) last1).getValue();
            final double f2 = ((Real_Value) last2).getValue();
            lastValue = new Real_Value(f1 - f2);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 47 with Expected_Value_type

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

the class TestcasenameExpression 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;
    // unqualified name or "".
    if (myScope != null) {
        if (myScope instanceof StatementBlock) {
            final StatementBlock block = (StatementBlock) myScope;
            final Definition definition = block.getMyDefinition();
            if (definition == null) {
                // An error would be better here.
                lastValue = new Charstring_Value("");
                lastValue.copyGeneralProperties(this);
            } else {
                if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
                    lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                    lastValue.copyGeneralProperties(this);
                }
            }
        }
    }
    // Run-time evaluation.
    return lastValue;
}
Also used : Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 48 with Expected_Value_type

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

the class TimerRunningExpression 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 (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_TIMER:
            {
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, "timer", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
                }
                break;
            }
        case A_PAR_TIMER:
            if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
            }
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR2, assignment.getDescription()));
            setIsErroneous(true);
            break;
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, true, true, false);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)

Example 49 with Expected_Value_type

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

the class UndefRunningExpression 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) {
    setIsErroneous(false);
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_TIMER:
        case A_PAR_TIMER:
            {
                realExpression = new TimerRunningExpression(reference);
                realExpression.setMyScope(getMyScope());
                realExpression.setFullNameParent(this);
                realExpression.setLocation(getLocation());
                realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
                break;
            }
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            {
                final Referenced_Value value = new Referenced_Value(reference);
                value.setMyScope(getMyScope());
                value.setFullNameParent(this);
                value.getValueRefdLast(timestamp, referenceChain);
                realExpression = new ComponentRunnningExpression(value);
                realExpression.setMyScope(getMyScope());
                realExpression.setFullNameParent(this);
                realExpression.setLocation(getLocation());
                realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
                break;
            }
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format("First operand of operation `<timer or component> running'' should be timer or component reference instead of {0}", assignment.getDescription()));
            setIsErroneous(true);
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 50 with Expected_Value_type

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

the class Unichar2CharExpression 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_UCHARSTRING:
            final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last.isUnfoldable(timestamp)) {
                UniversalCharstring string;
                if (last instanceof Charstring_Value) {
                    // check not necessary, trivial case
                    return;
                } else if (last instanceof UniversalCharstring_Value) {
                    string = ((UniversalCharstring_Value) last).getValue();
                    if (string == null) {
                        setIsErroneous(true);
                        return;
                    }
                } else {
                    value.getLocation().reportSemanticError(OPERANDERROR1);
                    setIsErroneous(true);
                    return;
                }
                for (int i = 0; i < string.length(); i++) {
                    final UniversalChar uchar = string.get(i);
                    if (uchar.group() != 0 || uchar.plane() != 0 || uchar.row() != 0 || uchar.cell() > 127) {
                        value.getLocation().reportSemanticError(OPERANDERROR2);
                        setIsErroneous(true);
                        return;
                    }
                }
            }
            return;
        case TYPE_CHARSTRING:
            break;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            break;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
            }
            return;
    }
}
Also used : UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) 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) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) 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)149 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)54 IType (org.eclipse.titan.designer.AST.IType)47 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)45 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)39 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)31 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)24 ISubReference (org.eclipse.titan.designer.AST.ISubReference)21 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)21 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)20 Identifier (org.eclipse.titan.designer.AST.Identifier)17 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)17 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)14 Type (org.eclipse.titan.designer.AST.Type)14 Assignment (org.eclipse.titan.designer.AST.Assignment)13 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)13 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)12 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)11 Value (org.eclipse.titan.designer.AST.Value)11