Search in sources :

Example 1 with SignatureExceptions

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

the class Catch_Statement method checkCatch.

public static void checkCatch(final CompilationTimeStamp timestamp, final Statement statement, final String statementName, final Reference portReference, final Reference signatureReference, final TemplateInstance parameter, final boolean timeout, final TemplateInstance fromClause, final Reference redirectValue, final Reference redirectSender) {
    final Port_Type portType = Port_Utility.checkPortReference(timestamp, statement, portReference);
    if (signatureReference == null) {
        if (timeout) {
            if (portReference == null) {
                statement.getLocation().reportSemanticError(TIMEOUTONANYPORT);
            } else {
                if (portType != null) {
                    final PortTypeBody body = portType.getPortBody();
                    // in the compiler
                    if (OperationModes.OP_Message.equals(body.getOperationMode())) {
                        portReference.getLocation().reportSemanticError(MessageFormat.format(TIMEOUTONMESSAGEPORT, portType.getTypename()));
                    } else if (!body.getreplyAllowed(timestamp)) {
                        portReference.getLocation().reportSemanticError(MessageFormat.format(TIMEOUTWITHOUTOUTSIGNATURES, portType.getTypename()));
                    }
                }
            }
            if (statement instanceof Catch_Statement) {
                final Catch_Statement catchStatement = (Catch_Statement) statement;
                if (!catchStatement.inCall) {
                    statement.getLocation().reportSemanticError(TIMEOUTNOTPERMITTED1);
                } else if (!catchStatement.callHasTimer) {
                    statement.getLocation().reportSemanticError(TIMEOUTNOTPERMITTED2);
                }
            }
            if (fromClause != null) {
                fromClause.getLocation().reportSemanticError(TIMEOUTWITHFROM);
            }
            if (redirectSender != null) {
                redirectSender.getLocation().reportSemanticError(TIMEOUTWITHSENDERREDIRECT);
            }
        } else {
            if (portType != null) {
                final PortTypeBody body = portType.getPortBody();
                if (OperationModes.OP_Message.equals(body.getOperationMode())) {
                    portReference.getLocation().reportSemanticError(MessageFormat.format(MESSAGEPORT, statementName, portType.getTypename()));
                } else if (!body.catchAllowed(timestamp)) {
                    portReference.getLocation().reportSemanticError(MessageFormat.format(PORTWITHOUTEXCEPTIONSUPPORT, portType.getTypename()));
                }
            }
        }
        if (redirectValue != null) {
            redirectValue.getLocation().reportSemanticError(VALUEREDIRECTWITHOUTPARAMETER);
            Port_Utility.checkValueRedirect(timestamp, redirectValue, null);
        }
    } else {
        Signature_Type signature = Port_Utility.checkSignatureReference(timestamp, signatureReference);
        if (portType != null) {
            final PortTypeBody body = portType.getPortBody();
            if (OperationModes.OP_Message.equals(body.getOperationMode())) {
                portReference.getLocation().reportSemanticError(MessageFormat.format(MESSAGEPORT, statementName, portType.getTypename()));
            } else if (body.catchAllowed(timestamp)) {
                final TypeSet outSignatures = body.getOutSignatures();
                if (signature != null) {
                    if (!outSignatures.hasType(timestamp, signature)) {
                        signatureReference.getLocation().reportSemanticError(MessageFormat.format(MISSINGSIGNATURE, signature.getTypename(), portType.getTypename()));
                    }
                } else if (outSignatures.getNofTypes() == 1) {
                    signature = (Signature_Type) outSignatures.getTypeByIndex(0).getTypeRefdLast(timestamp);
                }
            } else {
                portReference.getLocation().reportSemanticError(MessageFormat.format(PORTWITHOUTEXCEPTIONSUPPORT, portType.getTypename()));
            }
        } else if (portReference == null) {
            if (parameter != null) {
                parameter.getLocation().reportSemanticError(MessageFormat.format(ANYPORTWITHPARAMETER, statementName));
            }
            if (redirectValue != null) {
                redirectValue.getLocation().reportSemanticError(MessageFormat.format(ANYPORTWITHVALUEREDIRECT, statementName));
            }
        }
        // the receive parameter must also be present
        IType exceptionType = null;
        boolean exceptionTypeDetermined = false;
        final boolean[] valueRedirectChecked = new boolean[] { false };
        if (signature != null) {
            final SignatureExceptions exceptions = signature.getSignatureExceptions();
            if (exceptions == null) {
                signatureReference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREWITHOUTEXCEPTIONS, signature.getTypename()));
            } else {
                if (exceptions.getNofExceptions() == 1) {
                    exceptionType = exceptions.getExceptionByIndex(0);
                } else if (parameter != null) {
                    exceptionType = Port_Utility.getIncomingType(timestamp, parameter, redirectValue, valueRedirectChecked);
                    if (exceptionType == null) {
                        parameter.getLocation().reportSemanticError(UNKNOWNEXCEPTIONTYPE);
                    } else {
                        final int nofCompatibleTypes = exceptions.getNofCompatibleExceptions(timestamp, exceptionType);
                        if (nofCompatibleTypes == 0) {
                            final String message = MessageFormat.format(MISSINGEXCEPTIONTYPE, exceptionType.getTypename(), signature.getTypename());
                            parameter.getLocation().reportSemanticError(message);
                        } else if (nofCompatibleTypes > 1) {
                            final String message = MessageFormat.format(AMBIGUOUSEXCEPTIONTYPE, exceptionType.getTypename(), signature.getTypename());
                            parameter.getLocation().reportSemanticError(message);
                        }
                    }
                }
                exceptionTypeDetermined = true;
            }
        }
        if (!exceptionTypeDetermined) {
            exceptionType = Port_Utility.getIncomingType(timestamp, parameter, redirectValue, valueRedirectChecked);
        }
        if (exceptionType != null && parameter != null) {
            parameter.check(timestamp, exceptionType);
            if (!valueRedirectChecked[0]) {
                Port_Utility.checkValueRedirect(timestamp, redirectValue, exceptionType);
            }
            exceptionType = exceptionType.getTypeRefdLast(timestamp);
            switch(exceptionType.getTypetype()) {
                case TYPE_SIGNATURE:
                    parameter.getLocation().reportSemanticError(MessageFormat.format(EXCEPTIONPARAMEXPECTED1, exceptionType.getTypename()));
                    break;
                case TYPE_PORT:
                    parameter.getLocation().reportSemanticError(MessageFormat.format(EXCEPTIONPARAMEXPECTED2, exceptionType.getTypename()));
                    break;
                case TYPE_DEFAULT:
                    parameter.getLocation().reportSemanticError(EXCEPTIONPARAMEXPECTED3);
                    break;
                default:
                    // accept it
                    break;
            }
        }
    }
    Port_Utility.checkFromClause(timestamp, statement, portType, fromClause, redirectSender);
}
Also used : SignatureExceptions(org.eclipse.titan.designer.AST.TTCN3.types.SignatureExceptions) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) TypeSet(org.eclipse.titan.designer.AST.TTCN3.types.TypeSet) Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with SignatureExceptions

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

the class Signature_Type method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String genName = getGenNameOwn();
    final ArrayList<SignatureParameter> parameters = new ArrayList<SignatureParameter>();
    for (int i = 0; i < formalParList.getNofParameters(); i++) {
        final SignatureFormalParameter formalPar = formalParList.getParameterByIndex(i);
        final Type type = formalPar.getType();
        SignatureGenerator.signatureParamaterDirection direction;
        switch(formalPar.getDirection()) {
            case PARAM_OUT:
                direction = signatureParamaterDirection.PAR_OUT;
                break;
            case PARAM_INOUT:
                direction = signatureParamaterDirection.PAR_INOUT;
                break;
            default:
                direction = signatureParamaterDirection.PAR_IN;
                break;
        }
        final SignatureParameter temp = new SignatureParameter(direction, type.getGenNameValue(aData, source, myScope), type.getGenNameTemplate(aData, source, myScope), formalPar.getIdentifier().getName());
        parameters.add(temp);
    }
    SignatureReturnType signatueReturnType = null;
    if (returnType != null) {
        signatueReturnType = new SignatureReturnType(returnType.getGenNameValue(aData, source, myScope), returnType.getGenNameTemplate(aData, source, myScope));
    }
    final ArrayList<SignatureException> signatureExceptions = new ArrayList<SignatureGenerator.SignatureException>();
    if (exceptions != null) {
        for (int i = 0; i < exceptions.getNofExceptions(); i++) {
            final Type exceptionType = exceptions.getExceptionByIndex(i);
            final IType last = exceptionType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final SignatureException temp = new SignatureException(last.getGenNameValue(aData, source, myScope), last.getGenNameTemplate(aData, source, myScope), last.getFullName());
            signatureExceptions.add(temp);
        }
    }
    final SignatureDefinition def = new SignatureDefinition(genName, getFullName(), parameters, signatueReturnType, noBlock, signatureExceptions);
    SignatureGenerator.generateClasses(aData, source, def);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : SignatureDefinition(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureDefinition) ArrayList(java.util.ArrayList) SignatureException(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureException) IType(org.eclipse.titan.designer.AST.IType) SignatureReturnType(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureReturnType) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) SignatureParameter(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureParameter) SignatureGenerator.signatureParamaterDirection(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.signatureParamaterDirection) SignatureReturnType(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureReturnType)

Example 3 with SignatureExceptions

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

the class Raise_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);
    IType signature = Port_Utility.checkSignatureReference(timestamp, signatureReference);
    if (portType != null) {
        final PortTypeBody portTypeBody = portType.getPortBody();
        final TypeSet inSignatures = portTypeBody.getInSignatures();
        if (OperationModes.OP_Message.equals(portTypeBody.getOperationMode())) {
            portReference.getLocation().reportSemanticError(MessageFormat.format(RAISEONPORT, portType.getTypename()));
        } else if (inSignatures != null) {
            if (signature != null) {
                if (!inSignatures.hasType(timestamp, signature)) {
                    portReference.getLocation().reportSemanticError(MessageFormat.format(SIGNATURENOTPRESENT, signature.getTypename(), portType.getTypename()));
                }
            } else if (inSignatures.getNofTypes() == 1) {
                signature = inSignatures.getTypeByIndex(0).getTypeRefdLast(timestamp);
            }
        } else {
            portReference.getLocation().reportSemanticError(MessageFormat.format(NOINCOMINGSIGNATURES, portType.getTypename()));
        }
    }
    IType exception = null;
    boolean exceptionDetermined = false;
    if (signature != null) {
        final SignatureExceptions exceptions = ((Signature_Type) signature).getSignatureExceptions();
        if (exceptions == null) {
            signatureReference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREWITHOUTEXCEPTIONS, signature.getTypename()));
        } else {
            if (exceptions.getNofExceptions() == 1) {
                exception = exceptions.getExceptionByIndex(0);
            } else {
                exception = Port_Utility.getOutgoingType(timestamp, parameter);
                if (exception == null) {
                    parameter.getLocation().reportSemanticError(UNKNOWNEXCEPTIONTYPE);
                } else {
                    final int nofCompatibleTypes = exceptions.getNofCompatibleExceptions(timestamp, exception);
                    if (nofCompatibleTypes == 0) {
                        parameter.getLocation().reportSemanticError(MessageFormat.format(TYPENOTONEXCEPTIONLIST, exception.getTypename(), signature.getTypename()));
                    } else if (nofCompatibleTypes > 1) {
                        parameter.getLocation().reportSemanticError(MessageFormat.format(AMBIGUOUSEXCEPTION, exception.getTypename(), signature.getTypename()));
                    }
                }
            }
            exceptionDetermined = true;
        }
    }
    if (!exceptionDetermined) {
        exception = Port_Utility.getOutgoingType(timestamp, parameter);
    }
    if (exception != null) {
        parameter.check(timestamp, exception);
        exception = exception.getTypeRefdLast(timestamp);
        switch(exception.getTypetype()) {
            case TYPE_SIGNATURE:
                parameter.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXCEPTION, exception.getTypename()));
                break;
            case TYPE_PORT:
                parameter.getLocation().reportSemanticError(MessageFormat.format(PORTEXCEPTION, exception.getTypename()));
                break;
            case TYPE_DEFAULT:
                parameter.getLocation().reportSemanticError(MessageFormat.format(DEFAULTEXCEPTION, exception.getTypename()));
                break;
            default:
                break;
        }
    }
    parameter.getTemplateBody().checkSpecificValue(timestamp, false);
    Port_Utility.checkToClause(timestamp, this, portType, toClause);
    lastTimeChecked = timestamp;
}
Also used : SignatureExceptions(org.eclipse.titan.designer.AST.TTCN3.types.SignatureExceptions) TypeSet(org.eclipse.titan.designer.AST.TTCN3.types.TypeSet) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)3 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)2 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)2 SignatureExceptions (org.eclipse.titan.designer.AST.TTCN3.types.SignatureExceptions)2 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)2 TypeSet (org.eclipse.titan.designer.AST.TTCN3.types.TypeSet)2 ArrayList (java.util.ArrayList)1 SignatureDefinition (org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureDefinition)1 SignatureException (org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureException)1 SignatureParameter (org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureParameter)1 SignatureReturnType (org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureReturnType)1 SignatureGenerator.signatureParamaterDirection (org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.signatureParamaterDirection)1 Type (org.eclipse.titan.designer.AST.Type)1