Search in sources :

Example 11 with UniversalCharstring

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

the class Unichar2IntExpression 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);
    IValue last;
    switch(tempType) {
        case TYPE_UCHARSTRING:
        case TYPE_CHARSTRING:
            last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last.isUnfoldable(timestamp)) {
                final Value_type tempType1 = last.getValuetype();
                // UniversalCharstring string; // = ((UniversalCharstring_Value) last).getValue();
                switch(tempType1) {
                    case UNIVERSALCHARSTRING_VALUE:
                        {
                            final UniversalCharstring string = ((UniversalCharstring_Value) last).getValue();
                            if (string.isErrorneous()) {
                                value.getLocation().reportSemanticError(string.getErrorMessage());
                                setIsErroneous(true);
                            } else if (string.length() != 1) {
                                value.getLocation().reportSemanticError(OPERANDERROR2);
                                setIsErroneous(true);
                            }
                            break;
                        }
                    case CHARSTRING_VALUE:
                        {
                            final String originalString = ((Charstring_Value) last).getValue();
                            final CharstringExtractor cs = new CharstringExtractor(originalString);
                            if (cs.isErrorneous()) {
                                value.getLocation().reportSemanticError(cs.getErrorMessage());
                                setIsErroneous(true);
                            } else {
                                final String string = cs.getExtractedString();
                                if (string != null && string.length() != 1) {
                                    value.getLocation().reportSemanticError(OPERANDERROR2);
                                    setIsErroneous(true);
                                }
                            }
                        }
                    default:
                        // error???
                        break;
                }
            // switch
            }
            // if
            break;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            break;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
            }
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) CharstringExtractor(org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Example 12 with UniversalCharstring

use of org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring 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 13 with UniversalCharstring

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

the class ReplaceExpression 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 (templateInstance1 == null || value2 == null || value3 == null || templateInstance4 == null) {
        setIsErroneous(true);
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    ITTCN3Template temp = templateInstance1.getTemplateBody();
    final IValue value1 = ((SpecificValue_Template) temp).getSpecificValue();
    final IValue v1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue v2 = value2.getValueRefdLast(timestamp, referenceChain);
    final IValue v3 = value3.getValueRefdLast(timestamp, referenceChain);
    temp = templateInstance4.getTemplateBody();
    final IValue value4 = ((SpecificValue_Template) temp).getSpecificValue();
    final IValue v4 = value4.getValueRefdLast(timestamp, referenceChain);
    final Value_type vt = v1.getValuetype();
    final int index = ((Integer_Value) v2).intValue();
    final int len = ((Integer_Value) v3).intValue();
    switch(vt) {
        case BITSTRING_VALUE:
            {
                final String v1Str = ((Bitstring_Value) v1).getValue();
                final String v4Str = ((Bitstring_Value) v4).getValue();
                String result = v1Str.substring(0, index);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring(index + len));
                lastValue = new Bitstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case HEXSTRING_VALUE:
            {
                final String v1Str = ((Hexstring_Value) v1).getValue();
                final String v4Str = ((Hexstring_Value) v4).getValue();
                String result = v1Str.substring(0, index);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring(index + len));
                lastValue = new Hexstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case OCTETSTRING_VALUE:
            {
                final String v1Str = ((Octetstring_Value) v1).getValue();
                final String v4Str = ((Octetstring_Value) v4).getValue();
                String result = v1Str.substring(0, index * 2);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring((index + len) * 2));
                lastValue = new Octetstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case CHARSTRING_VALUE:
            {
                final String v1Str = ((Charstring_Value) v1).getValue();
                final String v4Str = ((Charstring_Value) v4).getValue();
                String result = v1Str.substring(0, index);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring(index + len));
                lastValue = new Charstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case UNIVERSALCHARSTRING_VALUE:
            {
                final UniversalCharstring v1Str = ((UniversalCharstring_Value) v1).getValue();
                final UniversalCharstring v4Str = ((UniversalCharstring_Value) v4).getValue();
                final UniversalCharstring result = v1Str.substring(0, index);
                // This append() is not like concat().
                result.append(v4Str);
                result.append(v1Str.substring(index + len));
                lastValue = new UniversalCharstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)

Example 14 with UniversalCharstring

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

Example 15 with UniversalCharstring

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

the class Unichar2CharExpression 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 byte[] bytes = new byte[] { (byte) uchar.cell() };
                lastValue = new Charstring_Value(new String(bytes));
                break;
            }
        case CHARSTRING_VALUE:
            {
                lastValue = new Charstring_Value(((Charstring_Value) last).getValue());
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : 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) UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Aggregations

UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)16 IValue (org.eclipse.titan.designer.AST.IValue)14 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)11 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)9 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)7 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)6 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)6 UniversalChar (org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar)5 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)4 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IType (org.eclipse.titan.designer.AST.IType)2 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)2 PatternString (org.eclipse.titan.designer.AST.TTCN3.templates.PatternString)2 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)2 Verdict_Value (org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value)2 TreeSet (java.util.TreeSet)1