Search in sources :

Example 71 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Assignment_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    if (reference == null || template == null) {
        return;
    }
    final boolean rhsCopied = selfReference;
    // TODO this is actually much more complicated
    final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), true);
    if (assignment == null) {
        // TODO: handle null
        return;
    }
    boolean isValue;
    switch(assignment.getAssignmentType()) {
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_PAR_VAL:
        case A_VAR:
            isValue = true;
            break;
        default:
            isValue = false;
            break;
    }
    boolean isOptional = false;
    if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
        isOptional = true;
    }
    if (isValue) {
        final String rhsCopy = aData.getTemporaryVariableName();
        String rhsRef = rhsCopy;
        if (rhsCopied) {
            source.append("{\n");
            if (isOptional) {
                source.append(MessageFormat.format("Optional<{0}> {1} = new Optional<{0}>({0}.class);\n", template.getMyGovernor().getGenNameValue(aData, source, myScope), rhsCopy));
                rhsRef += ".get()";
            } else {
                source.append(MessageFormat.format("{0} {1} = new {0}();\n", template.getMyGovernor().getGenNameValue(aData, source, myScope), rhsCopy));
            }
        }
        final IValue value = template.getValue();
        // TODO handle needs_conv
        if (reference.getSubreferences().size() > 1) {
            if (value.canGenerateSingleExpression()) {
                final ExpressionStruct expression = new ExpressionStruct();
                reference.generateCode(aData, expression);
                source.append(expression.preamble);
                String temp;
                IType type = getType(CompilationTimeStamp.getBaseTimestamp(), assignment);
                type = type.getFieldType(CompilationTimeStamp.getBaseTimestamp(), reference, 1, Expected_Value_type.EXPECTED_TEMPLATE, false);
                // if (value.getValuetype() != Value_type.OMIT_VALUE && (isOptional || type.getTypetypeTtcn3() != value.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE))) {
                if (value.getValuetype() != Value_type.OMIT_VALUE && value.getValuetype() != Value_type.REFERENCED_VALUE && (isOptional || type.getTypetypeTtcn3() != value.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE))) {
                    temp = MessageFormat.format("new {0}({1})", value.getMyGovernor().getGenNameValue(aData, source, myScope), value.generateSingleExpression(aData));
                } else {
                    temp = value.generateSingleExpression(aData).toString();
                }
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", rhsCopy, temp));
                    expression.expression.append(MessageFormat.format(".assign({0});\n", rhsCopy));
                } else {
                    expression.expression.append(MessageFormat.format(".assign({0});\n", temp));
                }
                source.append(expression.expression);
                source.append(expression.postamble);
            } else {
                final String tempID = aData.getTemporaryVariableName();
                final String typeGenname = value.getMyGovernor().getGenNameValue(aData, source, myScope);
                final ExpressionStruct leftExpression = new ExpressionStruct();
                reference.generateCode(aData, leftExpression);
                if (rhsCopied) {
                    // TODO handle needs conversion case
                    value.generateCodeInit(aData, source, rhsRef);
                } else if (isOptional) {
                    leftExpression.expression.append(".get()");
                }
                source.append("{\n");
                source.append(leftExpression.preamble);
                if (reference.refersToStringElement()) {
                    // LHS is a string element
                    aData.addBuiltinTypeImport(typeGenname + "_Element");
                    source.append(MessageFormat.format("{0}_Element {1} = {2};\n", typeGenname, tempID, leftExpression.expression));
                } else {
                    source.append(MessageFormat.format("{0} {1} = {2};\n", typeGenname, tempID, leftExpression.expression));
                }
                source.append(leftExpression.postamble);
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", tempID, rhsCopy));
                } else {
                    // TODO handle needs conversion
                    value.generateCodeInit(aData, source, tempID);
                }
                source.append("}\n");
            }
        } else {
            // left hand side is a single assignment
            final String name = assignment.getGenNameFromScope(aData, source, myScope, null);
            if (!isOptional && value.getValuetype() == Value_type.REFERENCED_VALUE) {
                final Reference rightReference = ((Referenced_Value) value).getReference();
                final Assignment rightAssignment = rightReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), true);
                if (rightAssignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(rightReference.getSubreferences())) {
                    value.generateCodeInitMandatory(aData, source, rhsCopied ? rhsCopy : name);
                } else {
                    value.generateCodeInit(aData, source, rhsCopied ? rhsCopy : name);
                }
            } else {
                value.generateCodeInit(aData, source, rhsCopied ? rhsCopy : name);
            }
            if (rhsCopied) {
                source.append(MessageFormat.format("{0}.assign({1});\n", name, rhsCopy));
            }
        }
        if (rhsCopied) {
            source.append("}\n");
        }
    } else {
        final String rhsCopy = aData.getTemporaryVariableName();
        if (rhsCopied) {
            source.append("{\n");
            source.append(MessageFormat.format("{0} {1} = new {0}();\n", template.getMyGovernor().getGenNameTemplate(aData, source, myScope), rhsCopy));
        }
        // TODO handle needs_conv
        if (reference.getSubreferences().size() > 1) {
            if ((templateRestriction != Restriction_type.TR_NONE || !generateRestrictionCheck) && template.hasSingleExpression()) {
                final ExpressionStruct expression = new ExpressionStruct();
                reference.generateCode(aData, expression);
                source.append(expression.preamble);
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", rhsCopy, template.getSingleExpression(aData, false)));
                    expression.expression.append(MessageFormat.format(".assign({0});\n", rhsCopy));
                } else {
                    expression.expression.append(MessageFormat.format(".assign({0});\n", template.getSingleExpression(aData, false)));
                }
                expression.mergeExpression(source);
            } else {
                final String tempID = aData.getTemporaryVariableName();
                final ExpressionStruct expression = new ExpressionStruct();
                reference.generateCode(aData, expression);
                if (rhsCopied) {
                    // TODO handle needs conversion case
                    template.generateCodeInit(aData, source, rhsCopy);
                }
                source.append("{\n");
                source.append(expression.preamble);
                final IType governor = template.getMyGovernor();
                source.append(MessageFormat.format("{0} {1} = {2};\n", governor.getGenNameTemplate(aData, source, template.getMyScope()), tempID, expression.expression));
                source.append(expression.postamble);
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", tempID, rhsCopy));
                } else {
                    // TODO handle needs conversion case
                    if (Type_type.TYPE_SEQUENCE_OF.equals(governor.getTypetype()) || Type_type.TYPE_ARRAY.equals(governor.getTypetype())) {
                        source.append(MessageFormat.format("{0}.removeAllPermutations();\n", tempID));
                    }
                    template.generateCodeInit(aData, source, tempID);
                }
                if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
                    TemplateRestriction.generateRestrictionCheckCode(aData, source, location, tempID, templateRestriction);
                }
                source.append("}\n");
            }
        } else {
            // left hand side is a single assignment
            final String rhsName = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false).getGenNameFromScope(aData, source, myScope, "");
            final IType governor = template.getMyGovernor();
            if (Type_type.TYPE_SEQUENCE_OF.equals(governor.getTypetype()) || Type_type.TYPE_ARRAY.equals(governor.getTypetype())) {
                source.append(MessageFormat.format("{0}.removeAllPermutations();\n", rhsCopied ? rhsCopy : rhsName));
            }
            template.generateCodeInit(aData, source, rhsCopied ? rhsCopy : rhsName);
            if (rhsCopied) {
                source.append(MessageFormat.format("{0}.assign({1});\n", rhsName, rhsCopy));
            }
            if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
                TemplateRestriction.generateRestrictionCheckCode(aData, source, location, rhsName, templateRestriction);
            }
        }
        if (rhsCopied) {
            source.append("}\n");
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 72 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Def_ExternalConst method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isUsed = false;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_EXTERNALCONSTANT, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    final IType astType = type.getTypeRefdLast(timestamp);
    switch(astType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, astType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, astType.getFullName()));
            break;
        default:
            break;
    }
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
}
Also used : IType(org.eclipse.titan.designer.AST.IType)

Example 73 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class 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(".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_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 74 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Getreply_Statement method checkGetreply.

public static void checkGetreply(final CompilationTimeStamp timestamp, final Statement source, final String statementName, final Reference portReference, final TemplateInstance parameter, final TemplateInstance valueMatch, final TemplateInstance fromClause, final Reference redirectValue, final Parameter_Redirect redirectParameter, final Reference redirectSender) {
    final Port_Type portType = Port_Utility.checkPortReference(timestamp, source, portReference);
    if (parameter == null) {
        if (portType != null) {
            final PortTypeBody body = portType.getPortBody();
            if (!body.getreplyAllowed(timestamp)) {
                if (OperationModes.OP_Message.equals(body.getOperationMode())) {
                    portReference.getLocation().reportSemanticError(MessageFormat.format(GETREPLYONMESSAGEPORT, statementName, portType.getTypename()));
                } else {
                    portReference.getLocation().reportSemanticError(MessageFormat.format(GETREPLYNOTSUPPORTEDONPORT, portType.getTypename()));
                }
            }
        }
        if (redirectValue != null) {
            redirectValue.getLocation().reportSemanticError(VALUEREDIRECTWITHOUTSIGNATURE);
            Port_Utility.checkValueRedirect(timestamp, redirectValue, null);
        }
        if (redirectParameter != null) {
            // true?
            redirectParameter.check(timestamp, null, true);
            redirectParameter.getLocation().reportSemanticError(PARAMETERREDIRECTWITHOUTSIGNATURE);
        }
    } else {
        IType signature = null;
        boolean signatureDetermined = false;
        if (portType != null) {
            final PortTypeBody body = portType.getPortBody();
            if (OperationModes.OP_Message.equals(body.getOperationMode())) {
                portReference.getLocation().reportSemanticError(MessageFormat.format(GETREPLYONMESSAGEPORT, statementName, portType.getTypename()));
            } else if (body.getreplyAllowed(timestamp)) {
                final TypeSet outSignatures = body.getOutSignatures();
                if (outSignatures.getNofTypes() == 1) {
                    signature = outSignatures.getTypeByIndex(0);
                } else {
                    signature = Port_Utility.getOutgoingType(timestamp, parameter);
                    if (signature == null) {
                        parameter.getLocation().reportSemanticError(UNKNOWNSIGNATURETYPE);
                    } else {
                        if (!outSignatures.hasType(timestamp, signature)) {
                            parameter.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREMISSING, signature.getTypename(), portType.getTypename()));
                        }
                    }
                }
                signatureDetermined = true;
            } else {
                portReference.getLocation().reportSemanticError(MessageFormat.format(GETREPLYNOTSUPPORTEDONPORT, portType.getTypename()));
            }
        } else if (portReference == null) {
            // the statement refers to any port or there was
            // a syntax error
            parameter.getLocation().reportSemanticError(MessageFormat.format(ANYPORTWITHPARAMETER, statementName));
            if (valueMatch != null) {
                valueMatch.getLocation().reportSemanticError(MessageFormat.format(ANYPORTWITHVALUEMATCH, statementName));
            }
            if (redirectValue != null) {
                redirectValue.getLocation().reportSemanticError(MessageFormat.format(ANYPORTWITHVALUEREDIRECTION, statementName));
            }
            if (redirectParameter != null) {
                redirectParameter.getLocation().reportSemanticError(MessageFormat.format(ANYPORTWITHPARAMETERREDIRECTION, statementName));
            }
        }
        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:
                    {
                        final Signature_Type signatureType = (Signature_Type) signature;
                        if (signatureType.isNonblocking()) {
                            final String message = MessageFormat.format(NONBLOCKINGSIGNATURE, statementName, signatureType.getTypename());
                            source.getLocation().reportSemanticError(message);
                        } else {
                            returnType = signatureType.getSignatureReturnType();
                        }
                        if (redirectParameter != null) {
                            redirectParameter.check(timestamp, signatureType, true);
                        }
                        if (returnType == null) {
                            if (valueMatch != null) {
                                valueMatch.getLocation().reportSemanticError(MessageFormat.format(VALUEMATCHWITHOUTRETURNTYPE, signature.getTypename()));
                            }
                            if (redirectValue != null) {
                                final String message = MessageFormat.format(VALUEREDIRECTWITHOUTRETURNTYPE, signature.getTypename());
                                redirectValue.getLocation().reportSemanticError(message);
                            }
                        }
                        break;
                    }
                default:
                    parameter.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED, signature.getTypename()));
                    if (redirectParameter != null) {
                        redirectParameter.checkErroneous(timestamp);
                    }
                    break;
            }
            if (valueMatch != null) {
                if (returnType != null) {
                    valueMatch.check(timestamp, returnType);
                }
            }
            Port_Utility.checkValueRedirect(timestamp, redirectValue, returnType);
        }
    }
    Port_Utility.checkFromClause(timestamp, source, portType, fromClause, redirectSender);
}
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) 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)

Example 75 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Altguard method generateCodeInvokeInstance.

/**
 * Generate code for an alt guard
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param expression the expression to generate the source to
 */
public void generateCodeInvokeInstance(final JavaGenData aData, final ExpressionStruct expression) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last.getValuetype() == Value_type.ALTSTEP_REFERENCE_VALUE) {
        Def_Altstep altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
        expression.expression.append(MessageFormat.format("{0}_instance(", altstep.getGenNameFromScope(aData, expression.expression, myScope, "")));
        actualParameterList.generateCodeAlias(aData, expression);
    } else {
        value.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".invoke(");
        IType governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
        governor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        actualParameterList.generateCodeAlias(aData, expression);
    }
    expression.expression.append(')');
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Altstep_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Altstep_Reference_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)414 IValue (org.eclipse.titan.designer.AST.IValue)94 ISubReference (org.eclipse.titan.designer.AST.ISubReference)82 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)65 Identifier (org.eclipse.titan.designer.AST.Identifier)49 Assignment (org.eclipse.titan.designer.AST.Assignment)40 Value (org.eclipse.titan.designer.AST.Value)34 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)27 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)21 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)21 Reference (org.eclipse.titan.designer.AST.Reference)21 Type (org.eclipse.titan.designer.AST.Type)20 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)18 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)17 ArrayList (java.util.ArrayList)16 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)15 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)14 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)13