Search in sources :

Example 96 with Integer_Value

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

the class AbstractOfType method getSubrefsAsArray.

@Override
public /**
 * {@inheritDoc}
 */
boolean getSubrefsAsArray(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final List<Integer> subrefsArray, final List<IType> typeArray) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return true;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    if (subreference.getReferenceType() != Subreference_type.arraySubReference) {
        ErrorReporter.INTERNAL_ERROR();
        return false;
    }
    final Value indexValue = ((ArraySubReference) subreference).getValue();
    if (indexValue == null) {
        ErrorReporter.INTERNAL_ERROR();
        return false;
    }
    final IValue last = indexValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_CONSTANT, null);
    if (last == null) {
        ErrorReporter.INTERNAL_ERROR();
        return false;
    }
    if (last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_CONSTANT) != Type_type.TYPE_INTEGER) {
        return false;
    }
    if (!Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
        return false;
    }
    final Integer_Value lastInteger = (Integer_Value) last;
    if (lastInteger.isNative()) {
        final int fieldIndex = (int) lastInteger.getValue();
        if (fieldIndex < 0) {
            return false;
        }
        subrefsArray.add(fieldIndex);
        typeArray.add(this);
    } else {
        return false;
    }
    if (ofType == null) {
        ErrorReporter.INTERNAL_ERROR();
        return false;
    }
    return ofType.getSubrefsAsArray(timestamp, reference, actualSubReference + 1, subrefsArray, typeArray);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 97 with Integer_Value

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

the class AbstractOfType method isSubtypeCompatible.

/**
 * Checks that the provided type is sub-type compatible with the actual
 * set of type.
 * <p>
 * In case of sequence/set/array this means that the number of their
 * fields fulfills the length restriction of the set of type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle
 * @param other
 *                the type to check against.
 *
 * @return true if they are sub-type compatible, false otherwise.
 */
public boolean isSubtypeCompatible(final CompilationTimeStamp timestamp, final IType other) {
    if (subType == null || other == null) {
        return true;
    }
    long nofComponents;
    switch(other.getTypetype()) {
        case TYPE_ASN1_SEQUENCE:
            nofComponents = ((ASN1_Sequence_Type) other).getNofComponents(timestamp);
            break;
        case TYPE_TTCN3_SEQUENCE:
            nofComponents = ((TTCN3_Sequence_Type) other).getNofComponents();
            break;
        case TYPE_ASN1_SET:
            nofComponents = ((ASN1_Set_Type) other).getNofComponents(timestamp);
            break;
        case TYPE_TTCN3_SET:
            nofComponents = ((TTCN3_Set_Type) other).getNofComponents();
            break;
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
            if (other.getSubtype() == null) {
                return true;
            }
            return subType.isCompatible(timestamp, other.getSubtype());
        case TYPE_ARRAY:
            {
                final ArrayDimension dimension = ((Array_Type) other).getDimension();
                if (dimension.getIsErroneous(timestamp)) {
                    return false;
                }
                nofComponents = dimension.getSize();
                break;
            }
        default:
            return false;
    }
    final List<ParsedSubType> tempRestrictions = new ArrayList<ParsedSubType>(1);
    final Integer_Value length = new Integer_Value(nofComponents);
    tempRestrictions.add(new Length_ParsedSubType(new SingleLenghtRestriction(length)));
    final SubType tempSubtype = new SubType(getSubtypeType(), this, tempRestrictions, null);
    tempSubtype.check(timestamp);
    return subType.isCompatible(timestamp, tempSubtype);
}
Also used : ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) ArrayList(java.util.ArrayList) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) SingleLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)

Example 98 with Integer_Value

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

the class Array_Type method checkThisValueArray.

private boolean checkThisValueArray(final CompilationTimeStamp timestamp, final IValue originalValue, final Assignment lhs, final Array_Value lastValue, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    if (dimension == null) {
        return false;
    }
    boolean selfReference = false;
    final int nofValues = lastValue.getNofComponents();
    if (!dimension.getIsErroneous(timestamp) && dimension.getSize() < nofValues) {
        originalValue.getLocation().reportSemanticError(MessageFormat.format(TOOMANYEXPECTED, dimension.getSize(), nofValues));
        originalValue.setIsErroneous(true);
    }
    if (lastValue.isIndexed()) {
        boolean checkHoles = !dimension.getIsErroneous(timestamp) && Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
        final long arraySize = dimension.getSize();
        BigInteger maxIndex = BigInteger.valueOf(-1);
        final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(lastValue.getNofComponents());
        for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
            final IValue component = lastValue.getValueByIndex(i);
            final Value index = lastValue.getIndexByIndex(i);
            dimension.checkIndex(timestamp, index, expectedValue);
            final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            final IValue indexLast = index.getValueRefdLast(timestamp, referenceChain);
            referenceChain.release();
            if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(indexLast.getValuetype())) {
                checkHoles = false;
            } else {
                final BigInteger tempIndex = ((Integer_Value) indexLast).getValueValue();
                if (tempIndex.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
                    index.getLocation().reportSemanticError(MessageFormat.format("A integer value less than `{0}'' was expected for indexing type `{1}'' instead of `{2}''", Integer.MAX_VALUE, getTypename(), tempIndex));
                    checkHoles = false;
                } else if (tempIndex.compareTo(BigInteger.ZERO) == -1) {
                    index.getLocation().reportSemanticError(MessageFormat.format("A non-negative integer value was expected for indexing type `{0}'' instead of `{1}''", getTypename(), tempIndex));
                    checkHoles = false;
                } else if (indexMap.containsKey(tempIndex)) {
                    index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value `{0}'' for components {1} and {2}", tempIndex, indexMap.get(tempIndex), i + 1));
                    checkHoles = false;
                } else {
                    indexMap.put(tempIndex, Integer.valueOf(i + 1));
                    if (maxIndex.compareTo(tempIndex) == -1) {
                        maxIndex = tempIndex;
                    }
                }
            }
            component.setMyGovernor(elementType);
            final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
            selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
        }
        if (checkHoles) {
            if (indexMap.size() < arraySize) {
                lastValue.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
                originalValue.setIsErroneous(true);
            }
        }
    } else {
        if (!dimension.getIsErroneous(timestamp)) {
            final long arraySize = dimension.getSize();
            if (arraySize > nofValues) {
                originalValue.getLocation().reportSemanticError(MessageFormat.format("Too few elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
                originalValue.setIsErroneous(true);
            } else if (arraySize < nofValues) {
                originalValue.getLocation().reportSemanticError(MessageFormat.format("Too many elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
                originalValue.setIsErroneous(true);
            }
        }
        for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
            final IValue component = lastValue.getValueByIndex(i);
            component.setMyGovernor(elementType);
            if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
                if (!incompleteAllowed) {
                    component.getLocation().reportSemanticError(AbstractOfType.INCOMPLETEPRESENTERROR);
                }
            } else {
                final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
                selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
            }
        }
    }
    return selfReference;
}
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) IValue(org.eclipse.titan.designer.AST.IValue) Array_Value(org.eclipse.titan.designer.AST.TTCN3.values.Array_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

Example 99 with Integer_Value

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

the class RangeLenghtRestriction method checkNofElements.

@Override
public /**
 * {@inheritDoc}
 */
void checkNofElements(final CompilationTimeStamp timestamp, final int nofElements, final boolean lessAllowed, final boolean moreAllowed, final boolean hasAnyornone, final ILocateableNode locatable) {
    if (lower == null) {
        return;
    }
    if (!lessAllowed) {
        final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = lower.getValueRefdLast(timestamp, chain);
        chain.release();
        if (Value_type.INTEGER_VALUE.equals(last.getValuetype()) && !last.getIsErroneous(timestamp)) {
            final BigInteger length = ((Integer_Value) last).getValueValue();
            if (length.compareTo(BigInteger.valueOf(nofElements)) == 1) {
                final String message = MessageFormat.format("There are fewer ({0}) elements than it is allowed by the length restriction (at least {1})", nofElements, length);
                locatable.getLocation().reportSemanticError(message);
            }
        }
    }
    if (upper == null) {
        return;
    }
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = upper.getValueRefdLast(timestamp, chain);
    chain.release();
    if (Value_type.INTEGER_VALUE.equals(last.getValuetype()) && !last.getIsErroneous(timestamp)) {
        final BigInteger length = ((Integer_Value) last).getValueValue();
        if (length.compareTo(BigInteger.valueOf(nofElements)) == -1 && !moreAllowed) {
            final String message = MessageFormat.format("There are more ({0} {1}) elements than it is allowed by the length restriction ({2})", hasAnyornone ? "at least" : "", nofElements, length);
            locatable.getLocation().reportSemanticError(message);
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

Example 100 with Integer_Value

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

the class RangeLenghtRestriction method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    final Integer_Type integer = new Integer_Type();
    lower.setMyGovernor(integer);
    IValue last = integer.checkThisValueRef(timestamp, lower);
    integer.checkThisValueLimit(timestamp, last, expectedValue, false, false, true, false);
    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue valueLower = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    BigInteger lowerInt;
    switch(valueLower.getValuetype()) {
        case INTEGER_VALUE:
            {
                lowerInt = ((Integer_Value) valueLower).getValueValue();
                if (lowerInt.compareTo(BigInteger.ZERO) == -1) {
                    final String message = MessageFormat.format("The lower boundary of the length restriction must be a non-negative integer value instead of {0}", lowerInt);
                    valueLower.getLocation().reportSemanticError(message);
                }
                break;
            }
        default:
            lowerInt = BigInteger.ZERO;
            break;
    }
    if (upper == null) {
        return;
    }
    upper.setMyGovernor(integer);
    last = integer.checkThisValueRef(timestamp, upper);
    integer.checkThisValueLimit(timestamp, last, expectedValue, false, false, true, false);
    chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue valueUpper = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    BigInteger upperInt;
    switch(valueUpper.getValuetype()) {
        case INTEGER_VALUE:
            {
                upperInt = ((Integer_Value) valueUpper).getValueValue();
                if (upperInt.compareTo(BigInteger.ZERO) == -1) {
                    final String message = MessageFormat.format("The upper boundary of the length restriction must be a non-negative integer value instead of {0}", upperInt);
                    valueUpper.getLocation().reportSemanticError(message);
                } else if (upperInt.compareTo(lowerInt) == -1) {
                    getLocation().reportSemanticError(MessageFormat.format("The upper boundary of the length restriction ({0}) cannot be smaller than the lower boundary {1}", upperInt, lowerInt));
                }
                break;
            }
        default:
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

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