Search in sources :

Example 46 with Integer_Value

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

the class SingleLenghtRestriction method checkArraySize.

@Override
public /**
 * {@inheritDoc}
 */
void checkArraySize(final CompilationTimeStamp timestamp, final ArrayDimension dimension) {
    if (lastTimeChecked == null || dimension.getIsErroneous(timestamp) || value == null) {
        return;
    }
    boolean errorFlag = false;
    final long arraySize = dimension.getSize();
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(timestamp, chain);
    chain.release();
    if (Value_type.INTEGER_VALUE.equals(last.getValuetype()) && !last.getIsErroneous(timestamp)) {
        final BigInteger length = ((Integer_Value) last).getValueValue();
        final int compareResult = length.compareTo(BigInteger.valueOf(arraySize));
        if (compareResult != 0) {
            final String message = MessageFormat.format("There number of elements allowed by the length restriction ({0}) contradicts the array size ({1})", length, arraySize);
            value.getLocation().reportSemanticError(message);
            errorFlag = true;
        }
    }
    if (!errorFlag) {
        getLocation().reportSemanticWarning("Length restriction is useless for an array template");
    }
}
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 47 with Integer_Value

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

the class Port_Utility method checkConnectionEndpoint.

/**
 * Checks a reference to see if it really references a valid component
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param source
 *                the statement to report an error to, in case it is in
 *                a control part.
 * @param componentReference
 *                the reference of the component to be checked.
 * @param portReference
 *                the reference to a port of the component to be
 *                checked.
 * @param allowSystem
 *                tells if the system component should be allowed or not
 *                as an endpoint.
 *
 * @return the referenced component type, or null if there were
 *         problems.
 */
public static IType checkConnectionEndpoint(final CompilationTimeStamp timestamp, final Statement source, final Value componentReference, final PortReference portReference, final boolean allowSystem) {
    final IType componentType = checkComponentReference(timestamp, source, componentReference, true, allowSystem);
    if (portReference == null) {
        return componentType;
    }
    if (componentType == null) {
        // the component type can not be determined
        final List<ISubReference> subreferences = portReference.getSubreferences();
        if (subreferences.size() > 1) {
            // check array indices
            for (int i = 0; i < subreferences.size(); i++) {
                final ISubReference subreference = subreferences.get(i);
                if (subreference instanceof ArraySubReference) {
                    final Value value = ((ArraySubReference) subreference).getValue();
                    value.setLoweridToReference(timestamp);
                    final Type_type temporalType1 = value.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                    switch(temporalType1) {
                        case TYPE_INTEGER:
                            {
                                final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                                final IValue last1 = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
                                referenceChain.release();
                                if (!last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
                                    if (((Integer_Value) last1).signum() < 0) {
                                        value.getLocation().reportSemanticError(ArraySubReference.NATIVEINTEGEREXPECTED);
                                        value.setIsErroneous(true);
                                    }
                                }
                                break;
                            }
                        case TYPE_UNDEFINED:
                            value.setIsErroneous(true);
                            break;
                        default:
                            if (!value.getIsErroneous(timestamp)) {
                                value.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
                                value.setIsErroneous(true);
                            }
                            break;
                    }
                }
            }
        }
        return null;
    }
    final ComponentTypeBody componentBody = ((Component_Type) componentType).getComponentBody();
    portReference.setBaseScope(componentBody);
    portReference.setComponent((Component_Type) componentType);
    // for compatibility
    portReference.getRefdAssignment(timestamp, false);
    final Identifier portIdentifier = portReference.getId();
    if (!componentBody.hasLocalAssignmentWithId(portIdentifier)) {
        portReference.getLocation().reportSemanticError(MessageFormat.format(NOPORTWITHNAME, componentType.getTypename(), portIdentifier.getDisplayName()));
        return null;
    }
    final Assignment assignment = componentBody.getLocalAssignmentById(portIdentifier);
    if (assignment == null) {
        return null;
    }
    if (!Assignment_type.A_PORT.semanticallyEquals(assignment.getAssignmentType())) {
        portReference.getLocation().reportSemanticError(MessageFormat.format(DEFINITIONNOTPORT, portIdentifier.getDisplayName(), componentType.getTypename(), assignment.getAssignmentName()));
        return null;
    }
    final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
    if (dimensions != null) {
        dimensions.checkIndices(timestamp, portReference, "port", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    } else if (portReference.getSubreferences().size() > 1) {
        portReference.getLocation().reportSemanticError(MessageFormat.format("Port `{0}'' is not an array. The reference cannot have field or array sub-references", portIdentifier.getDisplayName()));
    }
    Port_Type portType = ((Def_Port) assignment).getType(timestamp);
    if (portType != null) {
        final PortTypeBody portBody = portType.getPortBody();
        if (PortType_type.PT_USER.equals(portBody.getPortType())) {
            final IType providerType = portBody.getProviderType();
            if (providerType instanceof Port_Type) {
                portType = (Port_Type) providerType;
            }
        }
    }
    return portType;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Def_Port(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) PortType_type(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody.PortType_type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)

Example 48 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 checkThisValueSetOf.

/**
 * Checks the SequenceOf_value kind value against this type.
 * SequenceOf_value kinds have to be converted before calling this
 * function.
 * <p>
 * Please note, that this function can only be called once we know for
 * sure that the value is of set-of type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 * @param expectedValue
 *                the kind of value expected here.
 * @param incompleteAllowed
 *                wheather incomplete value is allowed or not.
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the value, false otherwise
 */
public boolean checkThisValueSetOf(final CompilationTimeStamp timestamp, final SetOf_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    if (value.isIndexed()) {
        boolean checkHoles = Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
        BigInteger maxIndex = BigInteger.valueOf(-1);
        final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(value.getNofComponents());
        for (int i = 0, size = value.getNofComponents(); i < size; i++) {
            final IValue component = value.getValueByIndex(i);
            final Value index = value.getIndexByIndex(i);
            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(getOfType());
            final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
            selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
        }
        if (checkHoles && maxIndex.compareTo(BigInteger.valueOf(indexMap.size() - 1)) != 0) {
            value.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
        }
    } else {
        for (int i = 0, size = value.getNofComponents(); i < size; i++) {
            final IValue component = value.getValueByIndex(i);
            component.setMyGovernor(getOfType());
            if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
                if (!incompleteAllowed) {
                    component.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                }
            } else {
                final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
                selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    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) 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) BigInteger(java.math.BigInteger)

Example 49 with Integer_Value

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

the class TTCN3Template method getReferencedArrayTemplate.

/**
 * Checks whether array indexing is allowed for a given template sub
 * reference or not.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param arrayIndex
 *                the index to check.
 * @param referenceChain
 *                the reference chain use to detect circular references.
 */
protected ITTCN3Template getReferencedArrayTemplate(final CompilationTimeStamp timestamp, final IValue arrayIndex, final IReferenceChain referenceChain) {
    switch(getTemplatetype()) {
        case OMIT_VALUE:
        case ANY_VALUE:
        case ANY_OR_OMIT:
        case VALUE_LIST:
        case COMPLEMENTED_LIST:
        case SUPERSET_MATCH:
        case SUBSET_MATCH:
            arrayIndex.getLocation().reportSemanticError(MessageFormat.format("Reference with index to an element of {0} `{1}''", getTemplateTypeName(), getFullName()));
            break;
        default:
            break;
    }
    IValue indexValue = arrayIndex.setLoweridToReference(timestamp);
    indexValue = indexValue.getValueRefdLast(timestamp, referenceChain);
    if (indexValue.getIsErroneous(timestamp)) {
        return null;
    }
    long index = 0;
    if (!indexValue.isUnfoldable(timestamp)) {
        if (Value_type.INTEGER_VALUE.equals(indexValue.getValuetype())) {
            index = ((Integer_Value) indexValue).getValue();
        } else {
            arrayIndex.getLocation().reportSemanticError("An integer value was expected as index");
            return null;
        }
    } else {
        return null;
    }
    final IType tempType = myGovernor.getTypeRefdLast(timestamp);
    if (tempType.getIsErroneous(timestamp)) {
        return null;
    }
    switch(tempType.getTypetype()) {
        case TYPE_SEQUENCE_OF:
            if (index < 0) {
                final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `sequence of'' type `{1}''", index, tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            } else if (!Template_type.TEMPLATE_LIST.equals(getTemplatetype())) {
                return null;
            } else {
                final int nofElements = ((Template_List) this).getNofTemplates();
                if (index > nofElements) {
                    final String message = MessageFormat.format("Index overflow in a template of `sequence of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
            }
            break;
        case TYPE_SET_OF:
            if (index < 0) {
                final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `set of'' type `{1}''", index, tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            } else if (!Template_type.TEMPLATE_LIST.equals(getTemplatetype())) {
                return null;
            } else {
                final int nofElements = ((Template_List) this).getNofTemplates();
                if (index > nofElements) {
                    final String message = MessageFormat.format("Index overflow in a template of `set of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
            }
            break;
        case TYPE_ARRAY:
            {
                final ArrayDimension dimension = ((Array_Type) tempType).getDimension();
                dimension.checkIndex(timestamp, indexValue, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                if (Template_type.TEMPLATE_LIST.equals(getTemplatetype()) && !dimension.getIsErroneous(timestamp)) {
                    // re-base the index
                    index -= dimension.getOffset();
                    if (index < 0 || index > ((Template_List) this).getNofTemplates()) {
                        arrayIndex.getLocation().reportSemanticError(MessageFormat.format("The index value {0} is outside the array indexable range", index + dimension.getOffset()));
                        return null;
                    }
                } else {
                    return null;
                }
                break;
            }
        default:
            {
                final String message = MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            }
    }
    if (this instanceof Template_List) {
        final TTCN3Template returnValue = ((Template_List) this).getTemplateByIndex((int) index);
        if (Template_type.TEMPLATE_NOTUSED.equals(returnValue.getTemplatetype())) {
            if (baseTemplate != null) {
                return baseTemplate.getTemplateReferencedLast(timestamp, referenceChain).getReferencedArrayTemplate(timestamp, indexValue, referenceChain);
            }
            return null;
        }
        return returnValue;
    } else {
        return null;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) IType(org.eclipse.titan.designer.AST.IType)

Example 50 with Integer_Value

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

the class Template_List method getReferencedArrayTemplate.

@Override
protected /**
 * {@inheritDoc}
 */
ITTCN3Template getReferencedArrayTemplate(final CompilationTimeStamp timestamp, final IValue arrayIndex, final IReferenceChain referenceChain) {
    IValue indexValue = arrayIndex.setLoweridToReference(timestamp);
    indexValue = indexValue.getValueRefdLast(timestamp, referenceChain);
    if (indexValue.getIsErroneous(timestamp)) {
        return null;
    }
    long index = 0;
    if (!indexValue.isUnfoldable(timestamp)) {
        if (Value_type.INTEGER_VALUE.equals(indexValue.getValuetype())) {
            index = ((Integer_Value) indexValue).getValue();
        } else {
            arrayIndex.getLocation().reportSemanticError("An integer value was expected as index");
            return null;
        }
    } else {
        return null;
    }
    final IType tempType = myGovernor.getTypeRefdLast(timestamp);
    if (tempType.getIsErroneous(timestamp)) {
        return null;
    }
    switch(tempType.getTypetype()) {
        case TYPE_SEQUENCE_OF:
            {
                if (index < 0) {
                    final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `sequence of'' type `{1}''", index, tempType.getTypename());
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                final int nofElements = getNofTemplates();
                if (!(index < nofElements)) {
                    final String message = MessageFormat.format("Index overflow in a template of `sequence of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                break;
            }
        case TYPE_SET_OF:
            {
                if (index < 0) {
                    final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `set of'' type `{1}''", index, tempType.getTypename());
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                final int nofElements = getNofTemplates();
                if (!(index < nofElements)) {
                    final String message = MessageFormat.format("Index overflow in a template of `set of'' type `{0}'': the index is {1}, but the template has only {2} elements", tempType.getTypename(), index, nofElements);
                    arrayIndex.getLocation().reportSemanticError(message);
                    return null;
                }
                break;
            }
        case TYPE_ARRAY:
            {
                final ArrayDimension dimension = ((Array_Type) tempType).getDimension();
                dimension.checkIndex(timestamp, indexValue, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                if (!dimension.getIsErroneous(timestamp)) {
                    // re-base the index
                    index -= dimension.getOffset();
                    if (index < 0 || !(index < getNofTemplates())) {
                        arrayIndex.getLocation().reportSemanticError(MessageFormat.format("The index value {0} is outside the array indexable range", index + dimension.getOffset()));
                        return null;
                    }
                } else {
                    return null;
                }
                break;
            }
        default:
            {
                final String message = MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename());
                arrayIndex.getLocation().reportSemanticError(message);
                return null;
            }
    }
    final ITTCN3Template returnValue = getTemplateByIndex((int) index);
    if (Template_type.TEMPLATE_NOTUSED.equals(returnValue.getTemplatetype())) {
        if (baseTemplate != null) {
            return baseTemplate.getTemplateReferencedLast(timestamp, referenceChain).getReferencedArrayTemplate(timestamp, indexValue, referenceChain);
        }
        return null;
    }
    return returnValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) IType(org.eclipse.titan.designer.AST.IType)

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