Search in sources :

Example 6 with Port_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Port_Type in project titan.EclipsePlug-ins by eclipse.

the class Clear_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    final Port_Type portType = Port_Utility.checkPortReference(timestamp, this, portReference);
    if (portType != null && !portType.getPortBody().hasQueue(timestamp)) {
        portReference.getLocation().reportSemanticError(MessageFormat.format(QUEUELESSPORT, portType.getTypename()));
    }
    lastTimeChecked = timestamp;
}
Also used : Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)

Example 7 with Port_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Port_Type in project titan.EclipsePlug-ins by eclipse.

the class Connect_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    IType portType1;
    IType portType2;
    PortTypeBody body1;
    PortTypeBody body2;
    portType1 = Port_Utility.checkConnectionEndpoint(timestamp, this, componentReference1, portReference1, false);
    if (portType1 == null) {
        body1 = null;
    } else {
        body1 = ((Port_Type) portType1).getPortBody();
    }
    portType2 = Port_Utility.checkConnectionEndpoint(timestamp, this, componentReference2, portReference2, false);
    if (portType2 == null) {
        body2 = null;
    } else {
        body2 = ((Port_Type) portType2).getPortBody();
    }
    if (portType1 == null || portType2 == null || body1 == null || body2 == null) {
        lastTimeChecked = timestamp;
        return;
    }
    if (!body1.isConnectable(timestamp, body2) || (body1 != body2 && !body2.isConnectable(timestamp, body1))) {
        location.reportSemanticError(MessageFormat.format(INCONSISTENTCONNECTION, portType1.getTypename(), portType2.getTypename()));
        body1.reportConnectionErrors(timestamp, body2, location);
        if (body1 != body2) {
            body2.reportConnectionErrors(timestamp, body1, location);
        }
    }
    lastTimeChecked = timestamp;
}
Also used : PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody) IType(org.eclipse.titan.designer.AST.IType)

Example 8 with Port_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Port_Type 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 9 with Port_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Port_Type in project titan.EclipsePlug-ins by eclipse.

the class Port_Utility method checkFromClause.

/**
 * Checks a from clause reference and a sender redirect to see if they
 * really references valid component types.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param source
 *                the source statement to report errors to.
 * @param portType
 *                the type of the port used in the statement. Used to
 *                find the address type in effect.
 * @param fromClause
 *                the from clause to check
 * @param redirectSender
 *                the sender redirect to check.
 */
public static void checkFromClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final TemplateInstance fromClause, final Reference redirectSender) {
    IType addressType = null;
    if (portType != null) {
        addressType = portType.getPortBody().getAddressType(timestamp);
    } else if (source != null && source.getMyStatementBlock() != null) {
        final Module module = source.getMyStatementBlock().getModuleScope();
        if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
            addressType = ((TTCN3Module) module).getAddressType(timestamp);
        }
    }
    boolean senderRedirectChecked = false;
    IType fromClauseType = null;
    if (fromClause != null) {
        fromClauseType = fromClause.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
        ITTCN3Template templateBody = fromClause.getTemplateBody();
        if (fromClauseType == null) {
            if (addressType != null) {
                templateBody = addressType.checkThisTemplateRef(timestamp, templateBody);
            } else {
                templateBody = templateBody.setLoweridToReference(timestamp);
            }
            fromClauseType = templateBody.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
        }
        if (fromClauseType == null) {
            fromClauseType = checkSenderRedirect(timestamp, addressType, redirectSender);
            senderRedirectChecked = true;
        }
        if (fromClauseType == null) {
            // trying to figure out whether the template is
            // a component reference or an SUT address
            boolean isComponentReference;
            if (Type_type.TYPE_COMPONENT.equals(templateBody.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE))) {
                isComponentReference = true;
            } else {
                switch(templateBody.getTemplatetype()) {
                    case SPECIFIC_VALUE:
                        // treat 'null' as component
                        // reference
                        isComponentReference = Value_type.TTCN3_NULL_VALUE.equals(((SpecificValue_Template) templateBody).getSpecificValue().getValuetype());
                        break;
                    case ANY_VALUE:
                    case ANY_OR_OMIT:
                        isComponentReference = true;
                        break;
                    default:
                        isComponentReference = false;
                        break;
                }
            }
            if (isComponentReference) {
                // the argument is a component
                // reference: get a pool type
                fromClauseType = TypeFactory.createType(Type_type.TYPE_COMPONENT);
            } else if (addressType != null) {
                // the argument is not a component
                // reference: try the address type
                fromClauseType = addressType;
            }
        }
        if (fromClauseType != null) {
            fromClause.check(timestamp, fromClauseType);
            if (addressType == null || !addressType.isCompatible(timestamp, fromClauseType, null, null, null)) {
                // from_clause_type must be a component
                // type
                final IType last = fromClauseType.getTypeRefdLast(timestamp);
                if (last.getIsErroneous(timestamp)) {
                    fromClauseType = null;
                } else if (Type_type.TYPE_COMPONENT.equals(last.getTypetype())) {
                    if (Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype())) {
                        checkComponentReference(timestamp, source, ((SpecificValue_Template) templateBody).getSpecificValue(), true, true);
                    }
                } else {
                    final String message = MessageFormat.format("The type of the template should be a component type {0} instead of `{1}''", (addressType == null) ? "" : "or the `address' type ", fromClauseType.getTypename());
                    fromClause.getLocation().reportSemanticError(message);
                    fromClauseType = null;
                }
            }
        } else {
            fromClause.getLocation().reportSemanticError("Cannot determine the type of the template");
        }
    }
    if (!senderRedirectChecked) {
        final IType senderRedirectType = checkSenderRedirect(timestamp, addressType, redirectSender);
        if (fromClauseType != null && senderRedirectType != null && !fromClauseType.isIdentical(timestamp, senderRedirectType)) {
            final String message = MessageFormat.format("The types in `from'' clause and `sender'' redirect are not the same: `{0}'' was expected instead of `{1}''", fromClauseType.getTypename(), senderRedirectType.getTypename());
            senderRedirectType.getLocation().reportSemanticError(message);
        }
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IType(org.eclipse.titan.designer.AST.IType)

Example 10 with Port_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Port_Type in project titan.EclipsePlug-ins by eclipse.

the class Port_Utility method checkToClause.

/**
 * Checks a to clause reference to see if it really references valid
 * component type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param source
 *                the source statement of this check.
 * @param portType
 *                the type of the port used in the statement. Used to
 *                find the address type in effect.
 * @param toClause
 *                the to clause to check
 */
public static void checkToClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final IValue toClause) {
    if (toClause == null) {
        return;
    }
    IType addressType = null;
    if (portType != null) {
        addressType = portType.getPortBody().getAddressType(timestamp);
    } else if (source != null) {
        final Module module = source.getMyStatementBlock().getModuleScope();
        if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
            addressType = ((TTCN3Module) module).getAddressType(timestamp);
        }
    }
    if (addressType == null) {
        checkComponentReference(timestamp, source, toClause, true, true);
    } else {
        // detect possible enumerated values (address may be an
        // enumerated type)
        final IValue temp = addressType.checkThisValueRef(timestamp, toClause);
        // try to figure out whether the argument is a component
        // reference or an SUT address
        boolean isAddress;
        final IType governor = temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (governor == null) {
            isAddress = !Type_type.TYPE_COMPONENT.equals(temp.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE));
        } else {
            isAddress = addressType.isCompatible(timestamp, governor, null, null, null);
        }
        if (isAddress) {
            addressType.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
        } else {
            checkComponentReference(timestamp, source, temp, true, true);
        }
    }
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IValue(org.eclipse.titan.designer.AST.IValue) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)18 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)13 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)13 TypeSet (org.eclipse.titan.designer.AST.TTCN3.types.TypeSet)8 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)7 IValue (org.eclipse.titan.designer.AST.IValue)6 Assignment (org.eclipse.titan.designer.AST.Assignment)3 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)3 Type (org.eclipse.titan.designer.AST.Type)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Module (org.eclipse.titan.designer.AST.Module)2 Def_Port (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port)2 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)2 SignatureExceptions (org.eclipse.titan.designer.AST.TTCN3.types.SignatureExceptions)2 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1