Search in sources :

Example 1 with UniversalChar

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

the class Unichar2IntExpression 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 UNIVERSALCHARSTRING_VALUE:
            {
                final UniversalCharstring string = ((UniversalCharstring_Value) last).getValue();
                final UniversalChar uchar = string.get(0);
                final int result = (uchar.group() << 24) | (uchar.plane() << 16) | (uchar.row() << 8) | uchar.cell();
                lastValue = new Integer_Value(result);
                break;
            }
        case CHARSTRING_VALUE:
            {
                final String string = ((Charstring_Value) last).getValue();
                lastValue = new Integer_Value(string.charAt(0));
                break;
            }
        default:
            setIsErroneous(true);
            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) UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Example 2 with UniversalChar

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

Example 3 with UniversalChar

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

the class UCharLimit method toString.

@Override
public /**
 * {@inheritDoc}
 */
void toString(final StringBuilder sb) {
    final UniversalChar uc = new UniversalChar(value);
    sb.append(uc.toString());
}
Also used : UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar)

Example 4 with UniversalChar

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

the class Unichar2OctExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    // TODO: reimplement if needed
    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 UNIVERSALCHARSTRING_VALUE:
            {
                final UniversalCharstring string = ((UniversalCharstring_Value) last).getValue();
                final UniversalChar uchar = string.get(0);
                final byte[] bytes = new byte[] { (byte) uchar.cell() };
                lastValue = new Octetstring_Value(new String(bytes));
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 5 with UniversalChar

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

the class Int2UnicharExpression 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)) {
        return lastValue;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            {
                final long i = ((Integer_Value) last).getValue();
                final long group = (i >> 24) & 0xFF;
                final long plane = (i >> 16) & 0xFF;
                final long row = (i >> 8) & 0xFF;
                final long cell = i & 0xFF;
                lastValue = new UniversalCharstring_Value(new UniversalCharstring(new UniversalChar((int) group, (int) plane, (int) row, (int) cell)));
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Aggregations

UniversalChar (org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar)6 IValue (org.eclipse.titan.designer.AST.IValue)5 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)5 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)2 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)1 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)1