Search in sources :

Example 1 with IValue

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

the class ShiftLeftExpression 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 stringSize = 0;
    long shiftSize = 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())) {
                    stringSize = ((Bitstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_HEXSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
                    stringSize = ((Hexstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_OCTETSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
                    stringSize = ((Octetstring_Value) tempValue).getValueLength();
                }
                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;
                    }
                    shiftSize = ((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 (shiftSize < 0) {
                            location.reportConfigurableSemanticProblem(severity, NEGATIVESHIFTPROBLEM);
                        } else if (shiftSize == 0) {
                            location.reportConfigurableSemanticProblem(severity, ZEROSHIFTPROBLEM);
                        } else if (shiftSize > stringSize) {
                            location.reportConfigurableSemanticProblem(severity, MessageFormat.format(TOOBIGSHIFTPROBLEM, stringSize, shiftSize));
                        }
                    }
                }
                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)

Example 2 with IValue

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

the class ShiftRightExpression 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);
    String string;
    long shiftSize;
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            string = ((Bitstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).getValue();
            lastValue = new Bitstring_Value(shiftRight(string, shiftSize));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            string = ((Hexstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).getValue();
            lastValue = new Hexstring_Value(shiftRight(string, shiftSize));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            string = ((Octetstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).getValue() * 2;
            lastValue = new Octetstring_Value(shiftRight(string, shiftSize));
            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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 3 with IValue

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

the class ShiftRightExpression 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 stringSize = 0;
    long shiftSize = 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())) {
                    stringSize = ((Bitstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_HEXSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
                    stringSize = ((Hexstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_OCTETSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
                    stringSize = ((Octetstring_Value) tempValue).getValueLength();
                }
                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;
                    }
                    shiftSize = ((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 (shiftSize < 0) {
                            location.reportConfigurableSemanticProblem(severity, NEGATIVESHIFTPROBLEM);
                        } else if (shiftSize == 0) {
                            location.reportConfigurableSemanticProblem(severity, ZEROSHIFTPROBLEM);
                        } else if (shiftSize > stringSize) {
                            location.reportConfigurableSemanticProblem(severity, MessageFormat.format(TOOBIGSHIFTPROBLEM, stringSize, shiftSize));
                        }
                    }
                }
                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)

Example 4 with IValue

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

the class ShiftRightExpression method getExpressionReturntype.

@Override
public /**
 * {@inheritDoc}
 */
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    final IValue last = getValueRefdLast(timestamp, expectedValue, null);
    if (last == null || value1 == null) {
        return Type_type.TYPE_UNDEFINED;
    }
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return Type_type.TYPE_UNDEFINED;
    }
    value1.setLoweridToReference(timestamp);
    final Type_type tempType = value1.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
            return tempType;
        case TYPE_UNDEFINED:
            return tempType;
        default:
            setIsErroneous(true);
            return Type_type.TYPE_UNDEFINED;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 5 with IValue

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

the class SizeOfExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template templateBody = templateInstance.getTemplateBody();
    // FIXME actually a bit more complex
    if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
        final IValue value = ((SpecificValue_Template) templateBody).getValue();
        // FIXME implement support for cast
        value.generateCodeExpressionMandatory(aData, expression, true);
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".sizeOf()");
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)431 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)105 IType (org.eclipse.titan.designer.AST.IType)97 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)79 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)78 ISubReference (org.eclipse.titan.designer.AST.ISubReference)49 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)41 Value (org.eclipse.titan.designer.AST.Value)35 Identifier (org.eclipse.titan.designer.AST.Identifier)34 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)33 Assignment (org.eclipse.titan.designer.AST.Assignment)30 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)28 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)26 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)25 Reference (org.eclipse.titan.designer.AST.Reference)25 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)23 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)22 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)22 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)21 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)21