Search in sources :

Example 1 with Catch_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement in project titan.EclipsePlug-ins by eclipse.

the class Call_Statement method checkCallBody.

/**
 * Checks the response and exception handling part of a call operation.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 * @param portType
 *                the port type of the actual call statement.
 * @param signature
 *                the signature type of the actual call statement.
 */
private void checkCallBody(final CompilationTimeStamp timestamp, final Port_Type portType, final IType signature) {
    boolean hasCatchTimeout = false;
    for (int i = 0; i < altGuards.getNofAltguards(); i++) {
        final AltGuard altGuard = altGuards.getAltguardByIndex(i);
        if (!altguard_type.AG_OP.equals(altGuard.getType())) {
            continue;
        }
        final Statement statement = ((Operation_Altguard) altGuard).getGuardStatement();
        if (Statement_type.S_CATCH.equals(statement.getType())) {
            ((Catch_Statement) statement).setCallSettings(true, timerValue != null);
            hasCatchTimeout |= ((Catch_Statement) statement).hasTimeout();
        }
    }
    altGuards.setMyLaicStmt(altGuards, null);
    altGuards.setMyAltguards(altGuards);
    altGuards.check(timestamp);
    if (portType != null) {
        // operation.
        for (int i = 0; i < altGuards.getNofAltguards(); i++) {
            final AltGuard altguard = altGuards.getAltguardByIndex(i);
            if (!altguard_type.AG_OP.equals(altguard.getType())) {
                continue;
            }
            final Statement statement = ((Operation_Altguard) altguard).getGuardStatement();
            if (statement.getIsErroneous()) {
                continue;
            }
            switch(statement.getType()) {
                case S_GETREPLY:
                    {
                        final Reference tempPortReference = ((Getreply_Statement) statement).getPortReference();
                        if (tempPortReference == null) {
                            final String message = MessageFormat.format("The `{0}'' operation must refer to the same port as the previous `call'' statement: `{1}'' was expected instead of `any port''", statement.getStatementName(), portReference.getId().getDisplayName());
                            statement.getLocation().reportSemanticError(message);
                        } else if (!portReference.getId().equals(tempPortReference.getId())) {
                            final String message = MessageFormat.format("The `{0}'' operation refers to a different port than the previous `call'' statement: `{1}'' was expected instead of `{2}''", statement.getStatementName(), portReference.getId().getDisplayName(), tempPortReference.getId().getDisplayName());
                            tempPortReference.getLocation().reportSemanticError(message);
                        }
                        final TemplateInstance instance = ((Getreply_Statement) statement).getReceiveParameter();
                        if (instance != null) {
                            final IType tempSignature = instance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                            if (tempSignature != null && signature != null && !signature.isCompatible(timestamp, tempSignature, null, null, null)) {
                                final String message = MessageFormat.format(GETRPELYTOWRONGSIGNATURE, signature.getTypename(), tempSignature.getTypename());
                                instance.getLocation().reportSemanticError(message);
                            }
                        }
                        break;
                    }
                case S_CATCH:
                    final Reference tempPortReference = ((Catch_Statement) statement).getPortReference();
                    if (tempPortReference == null) {
                        final String message = MessageFormat.format("The `{0}'' operation must refer to the same port as the previous `call'' statement: `{1}'' was expected instead of `any port''", statement.getStatementName(), portReference.getId().getDisplayName());
                        statement.getLocation().reportSemanticError(message);
                    } else if (!portReference.getId().equals(tempPortReference.getId())) {
                        final String message = MessageFormat.format("The `{0}'' operation refers to a different port than the previous `call'' statement: `{1}'' was expected instead of `{2}''", statement.getStatementName(), portReference.getId().getDisplayName(), tempPortReference.getId().getDisplayName());
                        tempPortReference.getLocation().reportSemanticError(message);
                    }
                    final Signature_Type tempSignature = ((Catch_Statement) statement).getSignatureType();
                    if (tempSignature != null && signature != null && !signature.isCompatible(timestamp, tempSignature, null, null, null)) {
                        final String message = MessageFormat.format("The `catch'' operation refers to a different signature than the previous `call'' statement: `{0}'' was expected instead of `{1}''", signature.getTypename(), tempSignature.getTypename());
                        statement.getLocation().reportSemanticError(message);
                    }
                    break;
                default:
                    break;
            }
        }
    }
    if (timerValue != null && !hasCatchTimeout) {
        location.reportSemanticWarning("The call operation has a timer, but the timeout expection is not cought");
    }
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with Catch_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement 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 3 with Catch_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement in project titan.EclipsePlug-ins by eclipse.

the class Shorthand method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Timeout_Statement) {
        typename = NAME_TIMEOUT;
    } else if (node instanceof Receive_Port_Statement) {
        typename = NAME_RECEIVE;
    } else if (node instanceof Trigger_Port_Statement) {
        typename = NAME_TRIGGER;
    } else if (node instanceof Getcall_Statement) {
        typename = NAME_GETCALL;
    } else if (node instanceof Catch_Statement) {
        typename = NAME_CATCH;
    } else if (node instanceof Check_Port_Statement) {
        typename = NAME_CHECK;
    } else if (node instanceof Check_Receive_Port_Statement) {
        typename = NAME_CHECK_RECEIVE;
    } else if (node instanceof Check_Getcall_Statement) {
        typename = NAME_CHECK_GETCALL;
    } else if (node instanceof Check_Catch_Statement) {
        typename = NAME_CHECK_CATCH;
    } else if (node instanceof Check_Getreply_Statement) {
        typename = NAME_CHECK_GETREPLY;
    } else if (node instanceof Getreply_Statement) {
        typename = NAME_GETREPLY;
    } else if (node instanceof Done_Statement) {
        typename = NAME_DONE;
    } else if (node instanceof Killed_Statement) {
        typename = NAME_KILLED;
    } else {
        return;
    }
    final Statement s = (Statement) node;
    check(s, problems);
}
Also used : Done_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement) Check_Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getcall_Statement) Killed_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Killed_Statement) Call_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Call_Statement) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Check_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Port_Statement) Check_Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Catch_Statement) Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement) Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getreply_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) Check_Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getreply_Statement) Trigger_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Trigger_Port_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getcall_Statement) Killed_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Killed_Statement) Done_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement) Check_Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Receive_Port_Statement) Check_Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getcall_Statement) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Check_Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Receive_Port_Statement) Check_Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Catch_Statement) Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement) Trigger_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Trigger_Port_Statement) Check_Catch_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Catch_Statement) Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getcall_Statement) Check_Getcall_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getcall_Statement) Check_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Port_Statement) Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Getreply_Statement) Check_Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getreply_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) Check_Getreply_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getreply_Statement) Check_Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Check_Receive_Port_Statement)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)2 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)2 Reference (org.eclipse.titan.designer.AST.Reference)1 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)1 Call_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Call_Statement)1 Catch_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Catch_Statement)1 Check_Catch_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Check_Catch_Statement)1 Check_Getcall_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getcall_Statement)1 Check_Getreply_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Check_Getreply_Statement)1 Check_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Check_Port_Statement)1 Check_Receive_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Check_Receive_Port_Statement)1 Done_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement)1 Getcall_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Getcall_Statement)1 Getreply_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Getreply_Statement)1 Killed_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Killed_Statement)1 Receive_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement)1 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)1 Timeout_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement)1 Trigger_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Trigger_Port_Statement)1 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)1