Search in sources :

Example 61 with ExpressionStruct

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

the class ASN1_Choice_Type method generateCodeIsPresentBoundChosen.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, String field) {
    if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
        return;
    }
    if (subReferenceIndex >= subreferences.size()) {
        return;
    }
    final StringBuilder closingBrackets = new StringBuilder();
    if (isTemplate) {
        boolean anyvalueReturnValue = true;
        if (optype == Operation_type.ISPRESENT_OPERATION) {
            anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
        } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
            anyvalueReturnValue = false;
        }
        expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
        expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
        expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
        expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
        expression.expression.append("break;\n");
        expression.expression.append("case ANY_VALUE:\n");
        expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
        expression.expression.append("break;\n");
        expression.expression.append("case SPECIFIC_VALUE:{\n");
        closingBrackets.append("break;}\n");
        closingBrackets.append("default:\n");
        closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
        closingBrackets.append("break;\n");
        closingBrackets.append("}\n");
        closingBrackets.append("}\n");
    }
    final ISubReference subReference = subreferences.get(subReferenceIndex);
    if (!(subReference instanceof FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2}.union_selection_type.ALT_{3});\n", globalId, externalId, getGenNameValue(aData, expression.expression, myScope), FieldSubReference.getJavaGetterName(fieldId.getName())));
    expression.expression.append("}\n");
    final CompField compField = getComponentByName(fieldId);
    final Type nextType = compField.getType();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    closingBrackets.insert(0, "}\n");
    final String temporalId = aData.getTemporaryVariableName();
    final String temporalId2 = aData.getTemporaryVariableName();
    expression.expression.append(MessageFormat.format("{0}{1} {2} = new {0}{1}({3});\n", getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId));
    expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
    if (optype == Operation_type.ISBOUND_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
    } else if (optype == Operation_type.ISPRESENT_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isPresent({2});\n", globalId, temporalId2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
    } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
        if (subReferenceIndex == subreferences.size() - 1) {
            expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
            expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
            expression.expression.append("}\n");
        }
    }
    nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
    expression.expression.append(closingBrackets);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField)

Example 62 with ExpressionStruct

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

the class SelectCase method generateCode.

/**
 * Add generated java code for a single select case.
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param source the source code generated
 * @param name the name to compare the branch variables to (expression or temporary name)
 * @param unReachable tells whether this branch is already unreachable because of previous conditions
 */
public void generateCode(final JavaGenData aData, final StringBuilder source, final String name, final AtomicBoolean unreach) {
    ExpressionStruct expression = new ExpressionStruct();
    StringBuilder condition = new StringBuilder();
    if (templateInstances != null) {
        for (int i = 0; i < templateInstances.getNofTis(); i++) {
            final String tmp = aData.getTemporaryVariableName();
            final TemplateInstance templateInstance = templateInstances.getInstanceByIndex(i);
            final TTCN3Template templateBody = templateInstance.getTemplateBody();
            final boolean isValue = templateInstance.getDerivedReference() == null && templateBody.isValue(CompilationTimeStamp.getBaseTimestamp());
            final IType last = templateInstance.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
            if (i > 0) {
                condition.append(" || ");
            }
            if (isValue) {
                final String genName = last.getGenNameValue(aData, expression.expression, last.getMyScope());
                expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
                IValue value = templateBody.getValue();
                value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
                value.generateCodeExpressionMandatory(aData, expression, true);
                expression.expression.append(");\n");
                condition.append(MessageFormat.format("{0}.operatorEquals({1})", tmp, name));
            } else {
                final String genName = last.getGenNameTemplate(aData, expression.expression, last.getMyScope());
                expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
                templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
                expression.expression.append(");\n");
                condition.append(MessageFormat.format("{0}.match({1})", tmp, name));
            }
        }
        source.append(expression.preamble);
        source.append(expression.expression);
        source.append(expression.postamble);
        getLocation().update_location_object(aData, source);
        source.append("if (").append(condition).append(") {\n");
        statementBlock.generateCode(aData, source);
        source.append("}\n");
    } else {
        statementBlock.generateCode(aData, source);
        unreach.set(true);
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance) IType(org.eclipse.titan.designer.AST.IType)

Example 63 with ExpressionStruct

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

the class SelectUnionCase_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expressionStruct = new ExpressionStruct();
    expression.generateCodeExpression(aData, expressionStruct, true);
    source.append(expressionStruct.preamble);
    source.append(MessageFormat.format("switch({0}.get_selection()) '{'\n", expressionStruct.expression));
    selectUnionCases.generateCode(aData, source);
    source.append("}\n");
    source.append(expressionStruct.postamble);
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 64 with ExpressionStruct

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

the class Send_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    portReference.generateCode(aData, expression);
    expression.expression.append(".send(");
    final TTCN3Template templateBody = parameter.getTemplateBody();
    if (parameter.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
        // optimize for value
        final IValue value = ((SpecificValue_Template) templateBody).getValue();
        // FIXME check if casting is needed
        value.generateCodeExpressionMandatory(aData, expression, true);
    } else {
        // real template, can not be optimized
        parameter.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(", ");
    if (toClause == null) {
        expression.expression.append("new TitanComponent(TitanComponent.SYSTEM_COMPREF)");
    } else {
        toClause.generateCodeExpression(aData, expression, true);
    }
    expression.expression.append(")");
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 65 with ExpressionStruct

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

the class Setverdict_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    aData.addCommonLibraryImport("TTCN_Runtime");
    expression.expression.append("TTCN_Runtime.setverdict(");
    verdictValue.generateCodeExpression(aData, expression, false);
    if (verdictReason != null) {
        expression.expression.append(", ");
        final ExpressionStruct reason = new ExpressionStruct();
        verdictReason.generateCodeExpression(aData, reason);
        if (reason.preamble.length() > 0) {
            expression.preamble.append(reason.preamble);
        }
        if (reason.postamble.length() > 0) {
            expression.postamble.append(reason.postamble);
        }
        expression.expression.append(reason.expression);
        expression.expression.append(".getValue().toString()");
    }
    expression.expression.append(')');
    expression.mergeExpression(source);
}
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