Search in sources :

Example 11 with ArraySubReference

use of org.eclipse.titan.designer.AST.ArraySubReference 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 12 with ArraySubReference

use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.

the class IA5String_Type method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 13 with ArraySubReference

use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.

the class NumericString_Type method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 14 with ArraySubReference

use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.

the class UTCTime_Type method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 15 with ArraySubReference

use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.

the class UniversalString_Type method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Aggregations

ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)47 ISubReference (org.eclipse.titan.designer.AST.ISubReference)46 IValue (org.eclipse.titan.designer.AST.IValue)42 Value (org.eclipse.titan.designer.AST.Value)39 IType (org.eclipse.titan.designer.AST.IType)19 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)11 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)11 Identifier (org.eclipse.titan.designer.AST.Identifier)5 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)4 Assignment (org.eclipse.titan.designer.AST.Assignment)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)3 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)3 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BigInteger (java.math.BigInteger)2 IReferenceableElement (org.eclipse.titan.designer.AST.IReferenceableElement)2 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Array_Value (org.eclipse.titan.designer.AST.TTCN3.values.Array_Value)2 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)2