Search in sources :

Example 31 with Integer_Value

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

the class Bit2IntExpression method bit2int.

public static Integer_Value bit2int(final String bitString) {
    Integer_Value result = new Integer_Value(0);
    final byte[] bytes = bitString.getBytes();
    int startIndex = 0;
    while (startIndex < bytes.length && '0' == bytes[startIndex]) {
        startIndex++;
    }
    for (int i = startIndex; i < bytes.length; i++) {
        result = result.shiftLeft(1);
        if (bytes[i] == '1') {
            result = result.add(new Integer_Value(1));
        }
    }
    return result;
}
Also used : Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 32 with Integer_Value

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

the class Char2IntExpression 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 Integer_Value(cs.getExtractedString().charAt(0));
            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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) CharstringExtractor(org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)

Example 33 with Integer_Value

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

the class Def_Timer method checkArrayDuration.

private void checkArrayDuration(final CompilationTimeStamp timestamp, final IValue duration, final int startDimension) {
    final ArrayDimension dim = dimensions.get(startDimension);
    final boolean arraySizeKnown = !dim.getIsErroneous(timestamp);
    int arraySize = 0;
    if (arraySizeKnown) {
        arraySize = (int) dim.getSize();
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final Value v = (Value) duration.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (v.getIsErroneous(timestamp)) {
        // error
        return;
    }
    if (v.getValuetype() == Value_type.SEQUENCEOF_VALUE) {
        final SequenceOf_Value value = (SequenceOf_Value) v;
        final int nofComp = value.getNofComponents();
        // Value-list notation.
        if (!value.isIndexed()) {
            if (arraySizeKnown) {
                if (arraySize > nofComp) {
                    duration.getLocation().reportSemanticError("Too few elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
                } else if (arraySize < nofComp) {
                    duration.getLocation().reportSemanticError("Too many elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
                }
            }
            final boolean last_dim = startDimension + 1 >= dimensions.size();
            for (int i = 0; i < nofComp; ++i) {
                final IValue array_v = value.getValueByIndex(i);
                if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                if (last_dim) {
                    checkSingleDuration(timestamp, array_v);
                } else {
                    checkArrayDuration(timestamp, array_v, startDimension + 1);
                }
            }
        } else {
            // Indexed-notation.
            final boolean last_dim = startDimension + 1 >= dimensions.size();
            final Map<Integer, Integer> indexMap = new HashMap<Integer, Integer>();
            for (int i = 0; i < nofComp; ++i) {
                final IValue array_v = value.getValueByIndex(i);
                if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                if (last_dim) {
                    checkSingleDuration(timestamp, array_v);
                } else {
                    checkArrayDuration(timestamp, array_v, startDimension + 1);
                }
                final IValue array_index = value.getIndexByIndex(i);
                dim.checkIndex(timestamp, array_index, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                final IValue tmp = array_index.getValueRefdLast(timestamp, referenceChain);
                if (tmp.getValuetype() == Value_type.INTEGER_VALUE) {
                    final BigInteger index = ((Integer_Value) tmp).getValueValue();
                    if (index.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
                        array_index.getLocation().reportSemanticError(MessageFormat.format("An integer value less than {0} was expected for indexing timer array instead of {1}", Integer.MAX_VALUE, index));
                        array_index.setIsErroneous(true);
                    } else {
                        final int IndexValue = index.intValue();
                        if (indexMap.containsKey(IndexValue)) {
                            array_index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value {0} for timer array elements {1} and {2}", index, i + 1, indexMap.get(IndexValue)));
                            array_index.setIsErroneous(true);
                        } else {
                            indexMap.put(IndexValue, i + 1);
                        }
                    }
                }
            }
            // It's not possible to have "indexMap.size() > arraySize", since we
            // add only correct constant-index values into the map.  It's possible
            // to create partially initialized timer arrays.
            indexMap.clear();
        }
    } else {
        if (arraySizeKnown) {
            duration.getLocation().reportSemanticError("An array value (with " + arraySize + " elements) was expected as default duration of timer array");
        } else {
            duration.getLocation().reportSemanticError("An array value was expected as default duration of timer array");
        }
        duration.setIsErroneous(true);
    }
}
Also used : BigInteger(java.math.BigInteger) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) BigInteger(java.math.BigInteger) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Example 34 with Integer_Value

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

the class Def_Timer method hasDefaultDuration.

/**
 * Returns false if it is sure that the timer referred by array indices
 * reference does not have a default duration. Otherwise it returns
 * true.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle
 * @param reference
 *                might be NULL when examining a single timer.
 *
 * @return true if the timer has a default duration, false otherwise.
 */
public boolean hasDefaultDuration(final CompilationTimeStamp timestamp, final Reference reference) {
    if (defaultDuration == null) {
        return false;
    } else if (dimensions == null || reference == null) {
        return true;
    }
    IValue v = defaultDuration;
    final List<ISubReference> subreferences = reference.getSubreferences();
    final int nofDimensions = dimensions.size();
    final int nofReferences = subreferences.size() - 1;
    final int upperLimit = (nofDimensions < nofReferences) ? nofDimensions : nofReferences;
    for (int i = 0; i < upperLimit; i++) {
        v = v.getValueRefdLast(timestamp, null);
        if (Value_type.SEQUENCEOF_VALUE.equals(v.getValuetype())) {
            final ISubReference ref = subreferences.get(i + 1);
            if (!Subreference_type.arraySubReference.equals(ref.getReferenceType())) {
                return true;
            }
            final IValue index = ((ArraySubReference) ref).getValue();
            if (!Value_type.INTEGER_VALUE.equals(index.getValuetype())) {
                return true;
            }
            final long realIndex = ((Integer_Value) index).getValue() - dimensions.get(i).getOffset();
            if (realIndex >= 0 && realIndex < ((SequenceOf_Value) v).getNofComponents()) {
                v = ((SequenceOf_Value) v).getValueByIndex((int) realIndex);
            }
        }
    }
    return !Value_type.NOTUSED_VALUE.equals(v.getValuetype());
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 35 with Integer_Value

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

the class ASN1_Integer_Type method checkThisValueLimit.

// this method accepts REAL_VALUE
public void checkThisValueLimit(final CompilationTimeStamp timestamp, final IValue value, final ValueCheckingOptions valueCheckingOptions) {
    super.checkThisValue(timestamp, value, null, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (null == last || last.getIsErroneous(timestamp)) {
        return;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
        case REAL_VALUE:
            break;
        case NAMED_INTEGER_VALUE:
            if (null != namedNumbers) {
                // convert it into an integer value
                final Identifier name = ((Named_Integer_Value) last).getIdentifier();
                final NamedValue namedValue = namedNumbers.getNamedValueByName(name);
                IValue tempValue = namedValue.getValue();
                final ReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                tempValue = tempValue.getValueRefdLast(timestamp, referenceChain);
                referenceChain.release();
                if (!tempValue.getIsErroneous(timestamp) && Value_type.INTEGER_VALUE.equals(tempValue.getValuetype())) {
                    final int temp = ((Integer_Value) tempValue).intValue();
                    final Integer_Value converted = new Integer_Value(temp);
                    converted.copyGeneralProperties(value);
                    ((Named_Integer_Value) last).setCalculatedValue(converted);
                } else {
                // FIXME Most probably we were not able
                // to build the semantic structure for
                // something, because it is not yet
                // supported, like referenced values in
                // sets
                }
            }
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
            value.setIsErroneous(true);
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)91 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)87 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)23 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)19 IType (org.eclipse.titan.designer.AST.IType)17 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)15 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)15 BigInteger (java.math.BigInteger)13 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)12 Value (org.eclipse.titan.designer.AST.Value)12 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)9 HashMap (java.util.HashMap)8 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)8 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)8 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)8