Search in sources :

Example 1 with ExpressionStruct

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

the class SizeOfExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template templateBody = templateInstance.getTemplateBody();
    // FIXME actually a bit more complex
    if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
        final IValue value = ((SpecificValue_Template) templateBody).getValue();
        // FIXME implement support for cast
        value.generateCodeExpressionMandatory(aData, expression, true);
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".sizeOf()");
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 2 with ExpressionStruct

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

the class SubstrExpression 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.subString( ");
                final ITTCN3Template temp = templateInstance1.getTemplateBody();
                if (temp.isValue(CompilationTimeStamp.getBaseTimestamp())) {
                    final IValue value = temp.getValue();
                    value.generateCodeExpressionMandatory(aData, expression, true);
                } else {
                    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(')');
                break;
            }
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
            templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(".substr( ");
            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(')');
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) 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 3 with ExpressionStruct

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

the class IsBoundExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template template = templateInstance.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        final IValue value = ((SpecificValue_Template) template).getSpecificValue();
        if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
            final Reference reference = ((Referenced_Value) value).getReference();
            if (reference != null) {
                final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
                if (assignment != null) {
                    switch(assignment.getAssignmentType()) {
                        case A_TEMPLATE:
                        case A_VAR_TEMPLATE:
                        case A_MODULEPAR_TEMPLATE:
                        case A_EXT_FUNCTION_RTEMP:
                        case A_FUNCTION_RTEMP:
                        case A_PAR_TEMP_IN:
                        case A_PAR_TEMP_OUT:
                        case A_PAR_TEMP_INOUT:
                            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
                            return;
                        default:
                            break;
                    }
                }
                reference.generateCodeIsPresentBoundChosen(aData, expression, false, getOperationType(), null);
                return;
            }
        } else {
            // FIXME cast_needed case
            value.generateCodeExpressionMandatory(aData, expression, true);
        }
    } else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
        final Reference reference = ((Referenced_Template) template).getReference();
        if (reference != null) {
            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
            return;
        }
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".isBound()");
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 4 with ExpressionStruct

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

the class IsPresentExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template template = templateInstance.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        final IValue value = ((SpecificValue_Template) template).getSpecificValue();
        if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
            final Reference reference = ((Referenced_Value) value).getReference();
            if (reference != null) {
                final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
                if (assignment != null) {
                    switch(assignment.getAssignmentType()) {
                        case A_TEMPLATE:
                        case A_VAR_TEMPLATE:
                        case A_MODULEPAR_TEMPLATE:
                        case A_EXT_FUNCTION_RTEMP:
                        case A_FUNCTION_RTEMP:
                        case A_PAR_TEMP_IN:
                        case A_PAR_TEMP_OUT:
                        case A_PAR_TEMP_INOUT:
                            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
                            return;
                        default:
                            break;
                    }
                }
                reference.generateCodeIsPresentBoundChosen(aData, expression, false, getOperationType(), null);
                return;
            }
        } else {
            // FIXME cast_needed case
            value.generateCodeExpressionMandatory(aData, expression, true);
        }
    } else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
        final Reference reference = ((Referenced_Template) template).getReference();
        if (reference != null) {
            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
            return;
        }
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".isPresent()");
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 5 with ExpressionStruct

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

the class Value method generateCodeTmp.

/**
 * as above
 *  @param aData the structure to put imports into and get temporal variable names from.
 *  @param source the source code to be updated
 *  @param init is the content to be generated before the current value
 */
public StringBuilder generateCodeTmp(final JavaGenData aData, final StringBuilder source, final StringBuilder init) {
    final ExpressionStruct expression = new ExpressionStruct();
    generateCodeExpressionMandatory(aData, expression, false);
    if (expression.preamble.length() > 0 || expression.postamble.length() > 0) {
        String typeName;
        final String tempId = aData.getTemporaryVariableName();
        final IType lastType = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        if (Type_type.TYPE_BOOL.equals(lastType.getTypetype())) {
            typeName = "boolean";
        } else {
            typeName = myGovernor.getGenNameValue(aData, init, myScope);
        }
        init.append(MessageFormat.format("{0} {1};\n", typeName, tempId));
        init.append("{\n");
        if (expression.preamble.length() > 0) {
            init.append(expression.preamble);
        }
        if (Type_type.TYPE_BOOL.equals(lastType.getTypetype()) && !returnsNative()) {
            init.append(MessageFormat.format("{0} = TitanBoolean.getNative({1});\n", tempId, expression.expression));
        } else {
            init.append(MessageFormat.format("{0} = {1};\n", tempId, expression.expression));
        }
        if (expression.postamble.length() > 0) {
            init.append(expression.postamble);
        }
        init.append("}\n");
        source.append(tempId);
    } else {
        source.append(expression.expression);
    }
    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