Search in sources :

Example 36 with ExpressionStruct

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

the class Referenced_Template method generateRearrangeInitCodeReferenced.

private void generateRearrangeInitCodeReferenced(final JavaGenData aData, final StringBuilder source, final ExpressionStruct expression) {
    /**
     * Initially we can assume that:
     * - this is a referenced template and a part of a non-parameterized template
     * - u.ref.ref points to (a field of) a non-parameterized template within the same module as this.
     * - this ensures that the do-while loop will run at least twice (i.e. the first continue statement will be reached in the first iteration)
     */
    final Stack<ISubReference> referenceStack = new Stack<ISubReference>();
    ITTCN3Template template = this;
    for (; ; ) {
        if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
            final Reference reference = ((Referenced_Template) template).getReference();
            final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            /**
             * Don't follow the reference if:
             *  - the referenced definition is not a template
             *  - the referenced template is parameterized or
             *  - the referenced template is in different module
             */
            if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE && ((Def_Template) assignment).getFormalParameterList() == null && assignment.getMyScope().getModuleScope() == myScope.getModuleScope()) {
                // accumulate the sub-references of the referred reference
                final List<ISubReference> subReferences = reference.getSubreferences();
                if (subReferences != null && subReferences.size() > 1) {
                    for (int i = subReferences.size(); i > 1; i--) {
                        referenceStack.push(subReferences.get(i - 1));
                    }
                }
                // jump to the referred top-level template
                template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
                // start the iteration from the beginning
                continue;
            } else {
                // the reference cannot be followed
                break;
            }
        }
        // stop if there are no sub-references
        if (referenceStack.isEmpty()) {
            break;
        }
        // take the topmost sub-reference
        final ISubReference subReference = referenceStack.peek();
        if (subReference instanceof FieldSubReference) {
            if (template.getTemplatetype() != Template_type.NAMED_TEMPLATE_LIST) {
                break;
            }
            // the field reference can be followed
            final Identifier fieldId = ((FieldSubReference) subReference).getId();
            template = ((Named_Template_List) template).getNamedTemplate(fieldId).getTemplate();
        } else {
            // trying to follow an array reference
            if (template.getTemplatetype() != Template_type.TEMPLATE_LIST) {
                break;
            }
            IValue arrayIndex = ((ArraySubReference) subReference).getValue();
            final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            arrayIndex = arrayIndex.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
            referenceChain.release();
            if (arrayIndex.getValuetype() != Value_type.INTEGER_VALUE) {
                break;
            }
            // the index is available at compilation time
            long index = ((Integer_Value) arrayIndex).getValue();
            // index transformation in case of arrays
            if (template.getMyGovernor().getTypetype() == Type_type.TYPE_ARRAY) {
                index = index - ((Array_Type) template.getMyGovernor()).getDimension().getOffset();
            }
            template = ((Template_List) template).getTemplateByIndex((int) index);
        }
        // the topmost sub-reference was processed
        // it can be erased from the stack
        referenceStack.pop();
    }
    // the smallest dependent template is now in t
    // generate the initializer sequence for t
    template.generateCodeInit(aData, source, template.get_lhs_name());
    // the equivalent Java code of the referenced template is composed of the
    // genname of t and the remained sub-references in refstack
    expression.expression.append(template.getGenNameOwn(myScope));
    while (!referenceStack.isEmpty()) {
        final ISubReference subReference = referenceStack.pop();
        if (subReference instanceof FieldSubReference) {
            expression.expression.append(MessageFormat.format(".get{0}()", FieldSubReference.getJavaGetterName(((FieldSubReference) subReference).getId().getName())));
        } else {
            expression.expression.append(".getAt(");
            ((ArraySubReference) subReference).getValue().generateCodeExpression(aData, expression, false);
            expression.expression.append(')');
        }
    }
}
Also used : FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Stack(java.util.Stack) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 37 with ExpressionStruct

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

the class Referenced_Template method getSingleExpression.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder getSingleExpression(final JavaGenData aData, final boolean castIsNeeded) {
    final StringBuilder result = new StringBuilder();
    if (castIsNeeded && (lengthRestriction != null || isIfpresent)) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing referenced template `" + getFullName() + "''");
        return result;
    }
    final ExpressionStruct expression = new ExpressionStruct();
    reference.generateCode(aData, expression);
    if (expression.preamble.length() > 0 || expression.postamble.length() > 0) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing referenced template `" + getFullName() + "''");
        return result;
    }
    result.append(expression.expression);
    return result;
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 38 with ExpressionStruct

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

the class Receive_Port_Statement method generateCode.

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

Example 39 with ExpressionStruct

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

the class Start_Component_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    final Assignment func = functionInstanceReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    final Def_Function function = (Def_Function) func;
    expression.expression.append(MessageFormat.format("{0}(", func.getGenNameFromScope(aData, source, myScope, "start_")));
    componentReference.generateCodeExpression(aData, expression, false);
    FormalParameterList formalParameterList = function.getFormalParameterList();
    if (formalParameterList.getNofParameters() > 0) {
        expression.expression.append(',');
        ISubReference subReference = functionInstanceReference.getSubreferences().get(0);
        ((ParameterisedSubReference) subReference).getActualParameters().generateCodeNoAlias(aData, expression);
    }
    expression.expression.append(')');
    expression.mergeExpression(source);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 40 with ExpressionStruct

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

the class Start_Referenced_Component_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = dereferredValue.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last.getValuetype() == Value_type.FUNCTION_REFERENCE_VALUE) {
        Definition definition = ((Function_Reference_Value) last).getReferredFunction();
        expression.expression.append(MessageFormat.format("{0}(", definition.getGenNameFromScope(aData, source, myScope, "start_")));
    } else {
        dereferredValue.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".start(");
    }
    componentReference.generateCodeExpression(aData, expression, false);
    if (actualParameterList2.getNofParameters() > 0) {
        expression.expression.append(", ");
        actualParameterList2.generateCodeNoAlias(aData, expression);
    }
    expression.expression.append(')');
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value)

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