Search in sources :

Example 21 with Octetstring_Value

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

the class SubType method checkThisValue.

/**
 * Checks if a given value is valid according to this sub-type.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 */
public void checkThisValue(final CompilationTimeStamp timestamp, final IValue value) {
    if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
        return;
    }
    if (value.getIsErroneous(timestamp)) {
        return;
    }
    final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    boolean isValid = true;
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            if (subtypeType != SubType_type.ST_INTEGER) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(new IntegerLimit(((Integer_Value) last).getValueValue()));
            break;
        case REAL_VALUE:
            if (subtypeType == SubType_type.ST_FLOAT) {
                isValid = subtypeConstraint.isElement(((Real_Value) last).getValue());
                break;
            } else if (subtypeType == SubType_type.ST_INTEGER) {
                final Real_Value real = (Real_Value) last;
                if (real.isNegativeInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MINIMUM);
                    break;
                } else if (real.isPositiveInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MAXIMUM);
                    break;
                }
            }
            ErrorReporter.INTERNAL_ERROR();
            return;
        case BOOLEAN_VALUE:
            if (subtypeType != SubType_type.ST_BOOLEAN) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Boolean_Value) last).getValue());
            break;
        case VERDICT_VALUE:
            if (subtypeType != SubType_type.ST_VERDICTTYPE) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Verdict_Value) last).getValue());
            break;
        case BITSTRING_VALUE:
            if (subtypeType != SubType_type.ST_BITSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Bitstring_Value) last).getValue());
            break;
        case HEXSTRING_VALUE:
            if (subtypeType != SubType_type.ST_HEXSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Hexstring_Value) last).getValue());
            break;
        case OCTETSTRING_VALUE:
            if (subtypeType != SubType_type.ST_OCTETSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Octetstring_Value) last).getValue());
            break;
        case CHARSTRING_VALUE:
            switch(subtypeType) {
                case ST_CHARSTRING:
                    isValid = subtypeConstraint.isElement(((Charstring_Value) last).getValue());
                    break;
                case ST_UNIVERSAL_CHARSTRING:
                    isValid = subtypeConstraint.isElement(new UniversalCharstring(((Charstring_Value) last).getValue()));
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR();
                    return;
            }
            break;
        case UNIVERSALCHARSTRING_VALUE:
            if (subtypeType != SubType_type.ST_UNIVERSAL_CHARSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((UniversalCharstring_Value) last).getValue());
            break;
        case SEQUENCEOF_VALUE:
        case SETOF_VALUE:
        case OBJECTID_VALUE:
        case ENUMERATED_VALUE:
        case CHOICE_VALUE:
        case SEQUENCE_VALUE:
        case SET_VALUE:
        case FUNCTION_REFERENCE_VALUE:
        case ALTSTEP_REFERENCE_VALUE:
        case TESTCASE_REFERENCE_VALUE:
            if (value.isUnfoldable(timestamp)) {
                return;
            }
            isValid = subtypeConstraint.isElement(last);
            break;
        default:
            return;
    }
    if (!isValid) {
        value.getLocation().reportSemanticError(MessageFormat.format("{0} is not a valid value for type `{1}'' which has subtype {2}", last.createStringRepresentation(), myOwner.getTypename(), subtypeConstraint.toString()));
    }
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) 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) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 22 with Octetstring_Value

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

the class DecodeBase64Expression 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)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case CHARSTRING_VALUE:
            final String tempBitstring = ((Charstring_Value) last).getValue();
            lastValue = new Octetstring_Value(calculateValue(tempBitstring));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 23 with Octetstring_Value

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

the class Bit2OctExpression 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)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case BITSTRING_VALUE:
            final String tempBitstring = ((Bitstring_Value) last).getValue();
            lastValue = new Octetstring_Value(bit2oct(tempBitstring));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 24 with Octetstring_Value

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

the class Char2OctExpression 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)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case CHARSTRING_VALUE:
            final String string = ((Charstring_Value) last).getValue();
            final CharstringExtractor cs = new CharstringExtractor(string);
            lastValue = new Octetstring_Value(char2oct(cs.getExtractedString()));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) CharstringExtractor(org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 25 with Octetstring_Value

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

the class Def_Function_Writer method writeAssignmentStatement.

// updated
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
    StringBuilder functionString = new StringBuilder("");
    if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
        SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
        if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
            // TODO assignments for indexed bitstrings
            functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
            functionString.append(functionAssignIdentifiers.get(assignCounter) + functionAssignValues.get(assignCounter) + ";\r\n");
        // TODO: add logging here
        }
    }
    /*StringBuilder functionString = new StringBuilder("");

		if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
			SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();

			if (specValTemplate.getSpecificValue() instanceof Bitstring_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BITSTRING(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Integer_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Charstring_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new CHARSTRING(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Boolean_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BOOLEAN("
						+ functionAssignValues.get(assignCounter) + ");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
						+ functionAssignValues.get(assignCounter) + ";\r\n");

				// TODO: add logging here
			}

			if (specValTemplate.getSpecificValue() instanceof Referenced_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
						+ functionAssignValues.get(assignCounter) + ";\r\n");

				// TODO: add logging here
			}

			if ((specValTemplate.getSpecificValue() instanceof AddExpression)
					|| (specValTemplate.getSpecificValue() instanceof SubstractExpression)
					|| (specValTemplate.getSpecificValue() instanceof MultiplyExpression)
					|| (specValTemplate.getSpecificValue() instanceof DivideExpression)
					|| (specValTemplate.getSpecificValue() instanceof ModuloExpression)
					|| (specValTemplate.getSpecificValue() instanceof RemainderExpression)) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter)
						+ functionAssignValues.get(assignCounter) + ";\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

		}
*/
    return functionString.toString();
}
Also used : Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) StringConcatenationExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.StringConcatenationExpression) Not4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Not4bExpression) RotateLeftExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RotateLeftExpression) ShiftRightExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ShiftRightExpression) Or4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Or4bExpression) RemainderExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) UnaryMinusExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.UnaryMinusExpression) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) RotateRightExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RotateRightExpression) MultiplyExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) DivideExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression) AddExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression) ShiftLeftExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ShiftLeftExpression) SubstractExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression) And4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.And4bExpression) Xor4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Xor4bExpression) ModuloExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)40 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)28 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)17 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)17 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)15 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)15 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)9 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)7 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)6 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)4 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)3 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IType (org.eclipse.titan.designer.AST.IType)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2