Search in sources :

Example 6 with Signature_Type

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

the class Check_Getreply_Statement method generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression) {
    if (portReference != null) {
        portReference.generateCode(aData, expression);
        expression.expression.append(".check_getreply(");
        if (parameter != null) {
            // FIXME handle redirect
            parameter.generateCode(aData, expression, Restriction_type.TR_NONE);
            final IType signature = parameter.getTemplateBody().getMyGovernor();
            final IType signatureType = signature.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final IType returnType = ((Signature_Type) signatureType).getSignatureReturnType();
            if (returnType != null) {
                expression.expression.append(".set_value_template(");
                if (valueMatch != null) {
                    valueMatch.generateCode(aData, expression, Restriction_type.TR_NONE);
                } else {
                    // the value match is not present
                    // we must substitute it with ? in the signature template
                    expression.expression.append(MessageFormat.format("new {0}(template_sel.ANY_VALUE)", returnType.getGenNameTemplate(aData, expression.expression, myScope)));
                }
                expression.expression.append(')');
            }
            expression.expression.append(", ");
            generateCodeExprFromclause(aData, expression);
            // FIXME handle redirections
            expression.expression.append(", ");
            if (redirectSender == null) {
                expression.expression.append("null");
            } else {
                redirectSender.generateCode(aData, expression);
            }
        } else {
            // the signature template is not present
            generateCodeExprFromclause(aData, expression);
            expression.expression.append(", ");
            if (redirectSender == null) {
                expression.expression.append("null");
            } else {
                redirectSender.generateCode(aData, expression);
            }
        }
        // FIXME handle index redirection
        expression.expression.append(", null");
    } else {
        // the operation refers to any port
        expression.expression.append("TitanPort.any_check_getreply(");
        generateCodeExprFromclause(aData, expression);
        expression.expression.append(", ");
        if (redirectSender == null) {
            expression.expression.append("null");
        } else {
            redirectSender.generateCode(aData, expression);
        }
    }
    expression.expression.append(')');
}
Also used : Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 7 with Signature_Type

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

the class Port_Utility method checkSignatureReference.

/**
 * Checks a reference to see if it really references a valid signature
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param reference
 *                the reference to check.
 *
 * @return the referenced signature type, or null if there were
 *         problems.
 */
public static Signature_Type checkSignatureReference(final CompilationTimeStamp timestamp, final Reference reference) {
    if (reference == null) {
        return null;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return null;
    }
    if (!Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
        reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED1, assignment.getAssignmentName()));
        return null;
    }
    IType result = ((Def_Type) assignment).getType(timestamp);
    if (result == null) {
        return null;
    }
    result = result.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (result == null) {
        return null;
    }
    result = result.getTypeRefdLast(timestamp);
    switch(result.getTypetype()) {
        case TYPE_SIGNATURE:
            return (Signature_Type) result;
        case TYPE_PORT:
            reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED2, result.getTypename()));
            return null;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED3, result.getTypename()));
            return null;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 8 with Signature_Type

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

the class PortTypeBody method generateCode.

/**
 * Add generated java code on this level.
 * @param aData only used to update imports if needed
 * @param source the source code generated
 *
 * FIXME the implementation only serves as a minimal testing setup
 */
public void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String genName = myType.getGenNameOwn();
    final Scope myScope = myType.getMyScope();
    final PortDefinition portDefinition = new PortDefinition(genName, getFullName());
    if (inMessages != null) {
        for (int i = 0; i < inMessages.getNofTypes(); i++) {
            final IType inType = inMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(inType.getGenNameValue(aData, source, myScope), inType.getGenNameTemplate(aData, source, myScope), inType.getTypename());
            portDefinition.inMessages.add(info);
        }
    }
    if (outMessages != null) {
        for (int i = 0; i < outMessages.getNofTypes(); i++) {
            final IType outType = outMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(outType.getGenNameValue(aData, source, myScope), outType.getGenNameTemplate(aData, source, myScope), outType.getTypename());
            portDefinition.outMessages.add(info);
        }
    }
    if (inSignatures != null) {
        for (int i = 0; i < inSignatures.getNofTypes(); i++) {
            final IType outType = inSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, false);
            portDefinition.inProcedures.add(info);
        }
    }
    if (outSignatures != null) {
        for (int i = 0; i < outSignatures.getNofTypes(); i++) {
            final IType outType = outSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, signature.getSignatureReturnType() != null);
            portDefinition.outProcedures.add(info);
        }
    }
    switch(testportType) {
        case TP_REGULAR:
            portDefinition.testportType = TestportType.NORMAL;
            break;
        case TP_INTERNAL:
            portDefinition.testportType = TestportType.INTERNAL;
            break;
        case TP_ADDRESS:
            portDefinition.testportType = TestportType.ADDRESS;
            portDefinition.addressName = "TitanAddress";
            break;
        default:
            portDefinition.testportType = TestportType.NORMAL;
    }
    if (vardefs != null) {
        portDefinition.varDefs = new StringBuilder();
        portDefinition.varInit = new StringBuilder();
        for (int i = 0; i < vardefs.getNofAssignments(); i++) {
            final Definition def = vardefs.getAssignmentByIndex(i);
            String type = "";
            switch(def.getAssignmentType()) {
                case A_VAR:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    if (((Def_Var) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                case A_CONST:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    break;
                case A_VAR_TEMPLATE:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, myScope);
                    if (((Def_Var_Template) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                default:
                    // FATAL ERROR
                    break;
            }
            portDefinition.varDefs.append(MessageFormat.format("private {0} {1} = new {0}();\n", type, def.getGenName()));
        }
    }
    PortGenerator.generateClass(aData, source, portDefinition);
}
Also used : PortGenerator.messageTypeInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.messageTypeInfo) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) Scope(org.eclipse.titan.designer.AST.Scope) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) IType(org.eclipse.titan.designer.AST.IType) PortGenerator.procedureSignatureInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.procedureSignatureInfo)

Example 9 with Signature_Type

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

the class Reply_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 = null;
    boolean signatureDetermined = false;
    if (portType != null) {
        // the port type is known
        final PortTypeBody portTypeBody = portType.getPortBody();
        final TypeSet inSignatures = portTypeBody.getInSignatures();
        if (OperationModes.OP_Message.equals(portTypeBody.getOperationMode())) {
            portReference.getLocation().reportSemanticError(MessageFormat.format(REPLYONMESSAGEPORT, portType.getTypename()));
        } else if (inSignatures != null) {
            if (inSignatures.getNofTypes() == 1) {
                signature = inSignatures.getTypeByIndex(0);
            } else {
                signature = Port_Utility.getOutgoingType(timestamp, parameter);
                if (signature == null) {
                    parameter.getLocation().reportSemanticError(UNKNOWNINCOMINGSIGNATURE);
                } else {
                    if (!inSignatures.hasType(timestamp, signature)) {
                        parameter.getLocation().reportSemanticError(MessageFormat.format(INCOMINGSIGNATURENOTPRESENT, signature.getTypename(), portType.getTypename()));
                    }
                }
            }
            signatureDetermined = true;
        } else {
            portReference.getLocation().reportSemanticError(MessageFormat.format(NOINCOMINGSIGNATURES, portType.getTypename()));
        }
    }
    if (!signatureDetermined) {
        signature = Port_Utility.getOutgoingType(timestamp, parameter);
    }
    if (signature != null) {
        parameter.check(timestamp, signature);
        signature = signature.getTypeRefdLast(timestamp);
        Type returnType = null;
        switch(signature.getTypetype()) {
            case TYPE_SIGNATURE:
                if (((Signature_Type) signature).isNonblocking()) {
                    getLocation().reportSemanticError(MessageFormat.format("Operation `reply'' is not applicable to non-blocking signature `{0}''", signature.getTypename()));
                } else {
                    returnType = ((Signature_Type) signature).getSignatureReturnType();
                }
                // checking the presence/absence of reply value
                if (replyValue != null) {
                    if (returnType == null) {
                        final String message = MessageFormat.format("Unexpected return value. Signature `{0}'' does not have return type", signature.getTypename());
                        replyValue.getLocation().reportSemanticError(message);
                    }
                } else if (returnType != null) {
                    getLocation().reportSemanticError(MessageFormat.format("Missing return value. Signature `{0}'' returns type `{1}''", signature.getTypename(), returnType.getTypename()));
                }
                break;
            default:
                parameter.getLocation().reportSemanticError(MessageFormat.format("The type of parameter is `{0}'', which is not a signature", signature.getTypename()));
                break;
        }
        // checking the reply value if present
        if (replyValue != null && returnType != null) {
            replyValue.setMyGovernor(returnType);
            final IValue temp = returnType.checkThisValueRef(timestamp, replyValue);
            returnType.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
        }
        Port_Utility.checkToClause(timestamp, this, portType, toClause);
    }
    lastTimeChecked = timestamp;
}
Also used : Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) 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) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 10 with Signature_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type 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)13 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)11 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)6 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)6 TypeSet (org.eclipse.titan.designer.AST.TTCN3.types.TypeSet)6 Type (org.eclipse.titan.designer.AST.Type)4 Assignment (org.eclipse.titan.designer.AST.Assignment)2 IValue (org.eclipse.titan.designer.AST.IValue)2 SignatureExceptions (org.eclipse.titan.designer.AST.TTCN3.types.SignatureExceptions)2 SignatureFormalParameter (org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter)2 SignatureFormalParameterList (org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameterList)2 HashMap (java.util.HashMap)1 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)1 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)1 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)1 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)1 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 Location (org.eclipse.titan.designer.AST.Location)1