Search in sources :

Example 56 with ExpressionStruct

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

the class ASN1_Set_Seq_Choice_BaseType 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();
    final CompField compField = getComponentByName(fieldId);
    final Type nextType = compField.getType();
    final boolean nextOptional = !isTemplate && compField.isOptional();
    if (nextOptional) {
        expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
        closingBrackets.insert(0, "}\n");
        final String temporalId = aData.getTemporaryVariableName();
        expression.expression.append(MessageFormat.format("Optional<{0}{1}> {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
        if (subReferenceIndex == subreferences.size() - 1) {
            expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
            expression.expression.append("case OPTIONAL_UNBOUND:\n");
            expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
            expression.expression.append("break;\n");
            expression.expression.append("case OPTIONAL_OMIT:\n");
            expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, optype == Operation_type.ISBOUND_OPERATION ? "true" : "false"));
            expression.expression.append("break;\n");
            expression.expression.append("default:\n");
            expression.expression.append("{\n");
            final String temporalId2 = aData.getTemporaryVariableName();
            expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
            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}.isChosen({2});\n", globalId, temporalId2, field));
            }
            expression.expression.append("break;}\n");
            expression.expression.append("}\n");
            // at the end of the reference chain
            nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
        } else {
            // still more to go
            expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
            expression.expression.append("case OPTIONAL_UNBOUND:\n");
            expression.expression.append("case OPTIONAL_OMIT:\n");
            expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
            expression.expression.append("break;\n");
            expression.expression.append("default:\n");
            expression.expression.append("break;\n");
            expression.expression.append("}\n");
            expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
            closingBrackets.insert(0, "}\n");
            final String temporalId2 = aData.getTemporaryVariableName();
            expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
            expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
            nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
        }
    } else {
        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}.{2}({3});\n", globalId, temporalId2, subReferenceIndex != subreferences.size() - 1 ? "isBound" : "isPresent", subReferenceIndex == subreferences.size() - 1 && 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) Type(org.eclipse.titan.designer.AST.Type) ASN1Type(org.eclipse.titan.designer.AST.ASN1.ASN1Type) 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 57 with ExpressionStruct

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

the class ASN1_Set_Type method isPresentAnyvalueEmbeddedField.

@Override
public /**
 * {@inheritDoc}
 */
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
    if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
        return true;
    }
    if (beginIndex >= subreferences.size()) {
        return true;
    }
    final ISubReference subReference = subreferences.get(beginIndex);
    if (!(subReference instanceof FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return true;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    final CompField compField = getComponentByName(fieldId);
    if (compField.isOptional()) {
        return false;
    }
    return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField)

Example 58 with ExpressionStruct

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

the class Referenced_Value method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last == this) {
        final ExpressionStruct expression = new ExpressionStruct();
        expression.expression.append(name);
        expression.expression.append(".assign(");
        reference.generateConstRef(aData, expression);
        expression.expression.append(")");
        expression.mergeExpression(source);
        return source;
    }
    // the code generation is based on the referred value
    if (last.canGenerateSingleExpression() && myScope.getModuleScope() == last.getMyScope().getModuleScope()) {
        // simple substitution for in-line values within the same module
        source.append(MessageFormat.format("{0}.assign({1});\n", name, last.generateSingleExpression(aData)));
    } else {
        // TODO might need initialization see needs_init_precede
        // TODO Value.cc:generate_code_init_refd
        source.append(MessageFormat.format("{0}.assign({1});\n", name, last.getGenNameOwn(myScope)));
    }
    return source;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 59 with ExpressionStruct

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

the class ComponentCreateExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    aData.addCommonLibraryImport("TTCN_Runtime");
    expression.expression.append("TTCN_Runtime.create_component(");
    // the type of the component (module name and identifier)
    final Assignment assignment = componentReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    if (assignment == null || !Assignment_type.A_TYPE.equals(assignment.getAssignmentType())) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    IType componentType = assignment.getType(CompilationTimeStamp.getBaseTimestamp()).getFieldType(CompilationTimeStamp.getBaseTimestamp(), componentReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (componentType == null) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    componentType = componentType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (!Type_type.TYPE_COMPONENT.equals(componentType.getTypetype())) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    ((Component_Type) componentType).getComponentBody().generateCodeComponentTypeName(expression);
    expression.expression.append(", ");
    // third argument: component name
    if (name != null) {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = name.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
        referenceChain.release();
        if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
            // TODO check why translate
            expression.expression.append(MessageFormat.format("\"{0}\"", ((Charstring_Value) last).getValue()));
        } else {
            name.generateCodeExpressionMandatory(aData, expression, false);
        }
    } else {
        expression.expression.append("null");
    }
    expression.expression.append(", ");
    // fourth argument location
    if (location != null) {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = location.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
        referenceChain.release();
        if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
            // TODO check why translate
            expression.expression.append(MessageFormat.format("\"{0}\"", ((Charstring_Value) last).getValue()));
        } else {
            location.generateCodeExpressionMandatory(aData, expression, false);
        }
    } else {
        expression.expression.append("null");
    }
    // fifth argument: alive flag
    expression.expression.append(MessageFormat.format(", {0})", isAlive ? "true" : "false"));
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) IType(org.eclipse.titan.designer.AST.IType)

Example 60 with ExpressionStruct

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

the class Expression_Value method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    final ExpressionStruct expression = new ExpressionStruct();
    expression.expression.append(name);
    expression.expression.append(".assign(");
    generateCodeExpression(aData, expression, false);
    expression.expression.append(')');
    expression.mergeExpression(source);
    return 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