Search in sources :

Example 16 with ExpressionStruct

use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.

the class Altstep_Instance_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    reference.generateConstRef(aData, expression);
    expression.mergeExpression(source);
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 17 with ExpressionStruct

use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct 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 18 with ExpressionStruct

use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.

the class Template_ActualParameter method generateCodeDefaultValue.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeDefaultValue(final JavaGenData aData, final StringBuilder source) {
    if (template == null) {
        return;
    }
    final TTCN3Template temp = template.getTemplateBody();
    final Reference baseReference = template.getDerivedReference();
    if (baseReference != null) {
        final ExpressionStruct expression = new ExpressionStruct();
        expression.expression.append(MessageFormat.format("{0}.assign(", temp.get_lhs_name()));
        baseReference.generateCode(aData, expression);
        expression.expression.append(')');
    }
// FIXME handle the needs conversion case
// temp.generateCodeInit(aData, source, temp.get_lhs_name());
// FIXME generate restriction check code if needed
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 19 with ExpressionStruct

use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.

the class Template_ActualParameter method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final ExpressionStruct expression) {
    // TODO not complete implementation pl. copye_needed missing
    if (template != null) {
        final StringBuilder expressionExpression = new StringBuilder();
        final ExpressionStruct tempExpression = new ExpressionStruct();
        template.generateCode(aData, tempExpression, genRestrictionCheck);
        if (tempExpression.preamble.length() > 0) {
            expression.preamble.append(tempExpression.preamble);
        }
        if (tempExpression.postamble.length() == 0) {
            expressionExpression.append(tempExpression.expression);
        } else {
            // make sure the postambles of the parameters are executed before the
            // function call itself (needed if the template contains function calls
            // with lazy or fuzzy parameters)
            final String tempId = aData.getTemporaryVariableName();
            template.getTemplateBody().getMyGovernor().getGenNameTemplate(aData, expression.preamble, myScope);
            expression.preamble.append(" ");
            expression.preamble.append(tempId);
            expression.preamble.append("(");
            expression.preamble.append(tempExpression.expression);
            expression.preamble.append(")");
            expression.preamble.append(tempExpression.postamble);
            expressionExpression.append(tempId);
        }
        // TODO copy might be needed here
        expression.expression.append(expressionExpression);
    }
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 20 with ExpressionStruct

use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.

the class Value_ActualParameter method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final ExpressionStruct expression) {
    // TODO not complete implementation pl. copy_needed, formal parameter missing
    if (value != null) {
        final StringBuilder expressionExpression = new StringBuilder();
        final ExpressionStruct valueExpression = new ExpressionStruct();
        value.generateCodeExpression(aData, valueExpression, true);
        if (valueExpression.preamble.length() > 0) {
            expression.preamble.append(valueExpression.preamble);
        }
        if (valueExpression.postamble.length() == 0) {
            expressionExpression.append(valueExpression.expression);
        } else {
            // make sure the postambles of the parameters are executed before the
            // function call itself (needed if the value contains function calls
            // with lazy or fuzzy parameters)
            final String tempId = aData.getTemporaryVariableName();
            value.getMyGovernor().getGenNameValue(aData, expression.preamble, myScope);
            expression.preamble.append(" ");
            expression.preamble.append(tempId);
            expression.preamble.append("(");
            expression.preamble.append(valueExpression.expression);
            expression.preamble.append(")");
            expression.preamble.append(valueExpression.postamble);
            expressionExpression.append(tempId);
        }
        // TODO copy might be needed here
        expression.expression.append(expressionExpression);
    }
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Aggregations

ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)79 IValue (org.eclipse.titan.designer.AST.IValue)38 IType (org.eclipse.titan.designer.AST.IType)22 Assignment (org.eclipse.titan.designer.AST.Assignment)21 ISubReference (org.eclipse.titan.designer.AST.ISubReference)19 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)17 Reference (org.eclipse.titan.designer.AST.Reference)15 Identifier (org.eclipse.titan.designer.AST.Identifier)10 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)9 ArrayList (java.util.ArrayList)8 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)8 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)7 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)7 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)7 Type (org.eclipse.titan.designer.AST.Type)7 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)6 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)6 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)6 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)4