Search in sources :

Example 6 with ExpressionStruct

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

the class ReplaceExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    if (lastValue != null && lastValue != this) {
        lastValue.generateCodeExpression(aData, expression, true);
        return;
    }
    final IValue lastValue2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    final IValue lastValue3 = value3.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    // TODO handle the needs conversion case
    final Type_type expressionType = templateInstance1.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    switch(expressionType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            aData.addCommonLibraryImport("AdditionalFunctions");
            expression.expression.append("AdditionalFunctions.replace( ");
            templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(", ");
            if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                lastValue2.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue2).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                lastValue3.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue3).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(')');
            break;
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
            // TODO: need to test
            templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(".replace( ");
            if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                lastValue2.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue2).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                lastValue3.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue3).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(')');
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 7 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 generateCodeInitMandatory.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateCodeInitMandatory(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);
        generateCodeExpressionOptionalFieldReference(aData, expression, reference);
        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 8 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 generateSingleExpression.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateSingleExpression(final JavaGenData aData) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last != this && last.canGenerateSingleExpression() && last.getMyScope().getModuleScope() == myScope.getModuleScope()) {
        return last.generateSingleExpression(aData);
    }
    final ExpressionStruct expression = new ExpressionStruct();
    reference.generateConstRef(aData, expression);
    return expression.expression;
}
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 9 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 generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final boolean forceObject) {
    if (lastValue != null && lastValue != this) {
        lastValue.generateCodeExpression(aData, expression, forceObject);
        return;
    }
    if (canGenerateSingleExpression()) {
        if (returnsNative() && forceObject) {
            final IType gov = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            expression.expression.append(MessageFormat.format("new {0}(", gov.getGenNameValue(aData, new StringBuilder(), myScope)));
            expression.expression.append(generateSingleExpression(aData));
            expression.expression.append(")");
        } else {
            expression.expression.append(generateSingleExpression(aData));
        }
        return;
    }
    if (returnsNative() && forceObject) {
        final ExpressionStruct tempExpression = new ExpressionStruct();
        generateCodeExpressionExpression(aData, tempExpression);
        final IType gov = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
        expression.preamble.append(tempExpression.preamble);
        expression.expression.append(MessageFormat.format("new {0}(", gov.getGenNameValue(aData, new StringBuilder(), myScope)));
        expression.expression.append(tempExpression.expression);
        expression.expression.append(")");
    } else {
        generateCodeExpressionExpression(aData, expression);
    }
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) IType(org.eclipse.titan.designer.AST.IType)

Example 10 with ExpressionStruct

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

the class ActivateDereferedExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), chain);
    chain.release();
    if (last.getValuetype() == Value_type.ALTSTEP_REFERENCE_VALUE) {
        // the referred testcase is known
        final Def_Testcase testcase = ((Testcase_Reference_Value) last).getReferredTestcase();
        expression.expression.append(MessageFormat.format("{0}(", testcase.getGenNameFromScope(aData, expression.expression, myScope, "activate_")));
    } else {
        // the referred testcase is unknown
        value.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".activate(");
    }
    actualParameters.generateCodeAlias(aData, expression);
    expression.expression.append(')');
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Testcase_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Testcase_Reference_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

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