Search in sources :

Example 21 with Port_Type

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

the class PortTypeBody method checkUserAttribute.

/**
 * Checks the attributes for the specific case when the port is of user type.
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 */
private void checkUserAttribute(final CompilationTimeStamp timestamp) {
    if (providerReference == null) {
        return;
    }
    providerType = null;
    PortTypeBody providerBody = null;
    final Assignment assignment = providerReference.getRefdAssignment(timestamp, true);
    if (assignment != null) {
        if (Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
            final IType type = assignment.getType(timestamp).getTypeRefdLast(timestamp);
            if (Type_type.TYPE_PORT.equals(type.getTypetype())) {
                providerType = type;
                providerBody = ((Port_Type) type).getPortBody();
            } else {
                providerReference.getLocation().reportSemanticError(MessageFormat.format("Type reference `{0}'' does not refer to a port type", providerReference.getDisplayName()));
            }
        } else {
            providerReference.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' does not refer to a type", providerReference.getDisplayName()));
        }
    }
    // checking the consistency of attributes in this and provider_body
    if (providerBody != null && !TestPortAPI_type.TP_INTERNAL.equals(testportType)) {
        if (!PortType_type.PT_PROVIDER.equals(providerBody.portType)) {
            providerReference.getLocation().reportSemanticError(MessageFormat.format("The referenced port type `{0}'' must have the `provider'' attribute", providerType.getTypename()));
        }
        switch(providerBody.testportType) {
            case TP_REGULAR:
                if (TestPortAPI_type.TP_ADDRESS.equals(testportType)) {
                    providerReference.getLocation().reportSemanticError(MessageFormat.format("Attribute `address'' cannot be used because the provider port type `{0}''" + " does not have attribute `address''", providerType.getTypename()));
                }
                break;
            case TP_INTERNAL:
                providerReference.getLocation().reportSemanticError(MessageFormat.format("Missing attribute `internal''. Provider port type `{0}'' has attribute `internal''," + " which must be also present here", providerType.getTypename()));
                break;
            case TP_ADDRESS:
                break;
            default:
                break;
        }
        // inherit the test port API type from the provider
        testportType = providerBody.testportType;
    }
    // check the incoming mappings
    if (inMappings != null && inMappings.getNofMappings() != 0) {
        inMappings.check(timestamp);
        if (providerBody != null) {
            if (providerBody.inMessages != null) {
                // check if all source types are present on the `in' list of the provider
                for (int i = 0, size = inMappings.getNofMappings(); i < size; i++) {
                    final Type sourceType = inMappings.getMappingByIndex(i).getSourceType();
                    // }
                    if (sourceType != null && !providerBody.inMessages.hasType(timestamp, sourceType)) {
                        sourceType.getLocation().reportSemanticError(MessageFormat.format("Source type `{0}'' of the `in'' mapping is not present " + "on the list of incoming messages in provider port type `{1}''", sourceType.getTypename(), providerType.getTypename()));
                    }
                }
                // check if all types of the `in' list of the provider are handled by the mappings
                for (int i = 0, size = providerBody.inMessages.getNofTypes(); i < size; i++) {
                    final IType messageType = providerBody.inMessages.getTypeByIndex(i);
                    if (!inMappings.hasMappingForType(timestamp, messageType)) {
                        inMappings.getLocation().reportSemanticError(MessageFormat.format("Incoming message type `{0}'' of provider port type `{1}'' is not handled by the incoming mappings", messageType.getTypename(), providerType.getTypename()));
                        inMappings.hasMappingForType(timestamp, messageType);
                    }
                }
            } else {
                inMappings.getLocation().reportSemanticError(MessageFormat.format("Invalid incoming mappings. Provider port type `{0}' does not have incoming message types'", providerType.getTypename()));
            }
        }
        // checking target types
        for (int i = 0, size = inMappings.getNofMappings(); i < size; i++) {
            final TypeMapping mapping = inMappings.getMappingByIndex(i);
            for (int j = 0, nofTargets = mapping.getNofTargets(); j < nofTargets; j++) {
                final Type targetType = mapping.getTargetByIndex(j).getTargetType();
                if (targetType != null && (inMessages == null || !inMessages.hasType(timestamp, targetType))) {
                    targetType.getLocation().reportSemanticError(MessageFormat.format("Target type `{0}'' of the `in'' mapping is not present on the list of incoming messages in user port type `{1}''", targetType.getTypename(), myType.getTypename()));
                }
            }
        }
    } else if (providerBody != null && providerBody.inMessages != null) {
        location.reportSemanticError(MessageFormat.format("Missing `in'' mappings to handle the incoming message types of provider port type `{0}''", providerType.getTypename()));
    }
    if (outMappings != null && outMappings.getNofMappings() != 0) {
        outMappings.check(timestamp);
        if (outMessages != null) {
            // check if all source types are present on the `in' list of the provider
            for (int i = 0, size = outMappings.getNofMappings(); i < size; i++) {
                final Type sourceType = outMappings.getMappingByIndex(i).getSourceType();
                if (sourceType != null && !outMessages.hasType(timestamp, sourceType)) {
                    sourceType.getLocation().reportSemanticError(MessageFormat.format("Source type `{0}'' of the `out'' mapping is not present on the list of outgoing messages in user port type `{1}''", sourceType.getTypename(), myType.getTypename()));
                }
            }
            // check if all types of the `in' list of the provider are handled by the mappings
            for (int i = 0, size = outMessages.getNofTypes(); i < size; i++) {
                final IType messageType = outMessages.getTypeByIndex(i);
                if (!outMappings.hasMappingForType(timestamp, messageType)) {
                    outMappings.getLocation().reportSemanticError(MessageFormat.format("Outgoing message type `{0}'' of user port type `{1}'' is not handled by the outgoing mappings", messageType.getTypename(), myType.getTypename()));
                }
            }
        } else {
            outMappings.getLocation().reportSemanticError(MessageFormat.format("Invalid outgoing mappings. User port type `{0}'' does not have outgoing message types", myType.getTypename()));
        }
        // checking target types
        if (providerBody != null) {
            for (int i = 0, size = outMappings.getNofMappings(); i < size; i++) {
                final TypeMapping mapping = outMappings.getMappingByIndex(i);
                for (int j = 0, nofTargets = mapping.getNofTargets(); j < nofTargets; j++) {
                    final Type targetType = mapping.getTargetByIndex(j).getTargetType();
                    if (targetType != null && (providerBody.outMessages == null || !providerBody.outMessages.hasType(timestamp, targetType))) {
                        targetType.getLocation().reportSemanticError(MessageFormat.format("Target type `{0}'' of the `out'' mapping is not present " + "on the list of outgoing messages in provider port type `{1}''", targetType.getTypename(), providerType.getTypename()));
                    }
                }
            }
        }
    } else if (outMessages != null) {
        location.reportSemanticError(MessageFormat.format("Missing `out'' mapping to handle the outgoing message types of user port type `{0}''", myType.getTypename()));
    }
    // checking the compatibility of signature lists
    if (providerBody == null) {
        return;
    }
    if (inSignatures != null) {
        for (int i = 0, size = inSignatures.getNofTypes(); i < size; i++) {
            final IType signatureType = inSignatures.getTypeByIndex(i);
            if (providerBody.inSignatures == null || !providerBody.inSignatures.hasType(timestamp, signatureType)) {
                final IType last = signatureType.getTypeRefdLast(timestamp);
                if (!last.getIsErroneous(timestamp) && Type_type.TYPE_SIGNATURE.equals(last.getTypetype())) {
                    final Signature_Type lastSignature = (Signature_Type) last;
                    if (!lastSignature.isNonblocking() || lastSignature.getSignatureExceptions() != null) {
                        signatureType.getLocation().reportSemanticError(MessageFormat.format("Incoming signature `{0}'' of user port type `{1}'' is not present on the list " + "of incoming signatures in provider port type `{2}''", signatureType.getTypename(), myType.getTypename(), providerType.getTypename()));
                    }
                }
            }
        }
    }
    if (providerBody.inSignatures != null) {
        for (int i = 0, size = providerBody.inSignatures.getNofTypes(); i < size; i++) {
            final IType signatureType = providerBody.inSignatures.getTypeByIndex(i);
            if (inSignatures == null || !inSignatures.hasType(timestamp, signatureType)) {
                location.reportSemanticError(MessageFormat.format("Incoming signature `{0}'' of provider port type `{1}'' " + "is not present on the list of incoming signatures in user port type `{2}''", signatureType.getTypename(), providerType.getTypename(), myType.getTypename()));
            }
        }
    }
    if (outSignatures != null) {
        for (int i = 0, size = outSignatures.getNofTypes(); i < size; i++) {
            final IType signatureType = outSignatures.getTypeByIndex(i);
            if (providerBody.outSignatures == null || !providerBody.outSignatures.hasType(timestamp, signatureType)) {
                signatureType.getLocation().reportSemanticError(MessageFormat.format("Outgoing signature `{0}'' of user port type `{1}'' is not present " + "on the list of outgoing signatures in provider port type `{2}''", signatureType.getTypename(), myType.getTypename(), providerType.getTypename()));
            }
        }
    }
    if (providerBody.outSignatures != null) {
        for (int i = 0, size = providerBody.outSignatures.getNofTypes(); i < size; i++) {
            final IType signatureType = providerBody.outSignatures.getTypeByIndex(i);
            if (outSignatures == null || !outSignatures.hasType(timestamp, signatureType)) {
                final IType last = signatureType.getTypeRefdLast(timestamp);
                if (!last.getIsErroneous(timestamp) && Type_type.TYPE_SIGNATURE.equals(last.getTypetype())) {
                    final Signature_Type lastSignature = (Signature_Type) last;
                    if (!lastSignature.isNonblocking() || lastSignature.getSignatureExceptions() != null) {
                        location.reportSemanticError(MessageFormat.format("Outgoing signature `{0}'' of provider port type `{1}'' is not present " + "on the list of outgoing signatures in user port type `{2}''", signatureType.getTypename(), providerType.getTypename(), myType.getTypename()));
                    }
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) TestportType(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.TestportType) Attribute_Type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) TypeMapping(org.eclipse.titan.designer.AST.TTCN3.attributes.TypeMapping) 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