Search in sources :

Example 6 with Def_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.

the class Reference method generateConstRef.

public void generateConstRef(final JavaGenData aData, final ExpressionStruct expression) {
    if (referredAssignment == null) {
        // TODO: handle null
        return;
    }
    boolean isTemplate;
    switch(referredAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            isTemplate = false;
            break;
        case A_MODULEPAR_TEMPLATE:
        case A_TEMPLATE:
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            isTemplate = true;
            break;
        default:
            isTemplate = false;
            break;
    }
    FormalParameterList formalParameterList;
    switch(referredAssignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            formalParameterList = ((Def_Function) referredAssignment).getFormalParameterList();
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            formalParameterList = ((Def_Extfunction) referredAssignment).getFormalParameterList();
            break;
        case A_TEMPLATE:
            formalParameterList = ((Def_Template) referredAssignment).getFormalParameterList();
            break;
        default:
            formalParameterList = null;
            break;
    }
    final IType referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
    // ha parameterezett
    if (subReferences.get(0) instanceof ParameterisedSubReference) {
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
        expression.expression.append("( ");
        final ParameterisedSubReference temp = ((ParameterisedSubReference) subReferences.get(0));
        final ActualParameterList actualParameterList = temp.getActualParameters();
        if (actualParameterList != null) {
            actualParameterList.generateCodeAlias(aData, expression);
        }
        expression.expression.append(" )");
    } else if (formalParameterList != null) {
        // the reference does not have an actual parameter list, but the assignment has
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
        expression.expression.append("( ");
        // FieldSubReference temp = ((FieldSubReference)subReferences.get(0));
        for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
            if (i > 0) {
                expression.expression.append(", ");
            }
            formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, expression);
        }
        // temp.getActualParameters().generateCodeAlias(aData, expression);
        expression.expression.append(" )");
    } else {
        // TODO add fuzzy handling
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
    }
    generateCode(aData, expression, isTemplate, true, referedGovernor);
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Example 7 with Def_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.

the class Reference method generateCode.

/**
 * Add generated java code on this level.
 * @param aData only used to update imports if needed
 * @param expression the expression for code generated
 */
public void generateCode(final JavaGenData aData, final ExpressionStruct expression) {
    if (referredAssignment == null) {
        return;
    }
    boolean isTemplate;
    IType referedGovernor;
    switch(referredAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            isTemplate = false;
            referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
            break;
        case A_MODULEPAR_TEMPLATE:
        case A_TEMPLATE:
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            isTemplate = true;
            referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
            break;
        default:
            isTemplate = false;
            referedGovernor = null;
            break;
    }
    FormalParameterList formalParameterList;
    switch(referredAssignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            formalParameterList = ((Def_Function) referredAssignment).getFormalParameterList();
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            formalParameterList = ((Def_Extfunction) referredAssignment).getFormalParameterList();
            break;
        case A_TEMPLATE:
            formalParameterList = ((Def_Template) referredAssignment).getFormalParameterList();
            break;
        default:
            formalParameterList = null;
            break;
    }
    if (subReferences.get(0) instanceof ParameterisedSubReference) {
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
        expression.expression.append("( ");
        final ParameterisedSubReference temp = ((ParameterisedSubReference) subReferences.get(0));
        temp.getActualParameters().generateCodeAlias(aData, expression);
        expression.expression.append(" )");
    } else if (formalParameterList != null) {
        // the reference does not have an actual parameter list, but the assignment has
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
        expression.expression.append("( ");
        // FieldSubReference temp = ((FieldSubReference)subReferences.get(0));
        for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
            if (i > 0) {
                expression.expression.append(", ");
            }
            formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, expression);
        }
        // temp.getActualParameters().generateCodeAlias(aData, expression);
        expression.expression.append(" )");
    } else {
        // TODO add fuzzy handling
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
    }
    generateCode(aData, expression, isTemplate, false, referedGovernor);
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)

Example 8 with Def_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.

the class TemplateInstance method reArrangeInitCode.

/**
 * Walks through the templateinstance recursively and appends the java
 * initialization sequence of all (directly or indirectly) referenced
 * non-parameterized templates and the default values of all
 * parameterized templates to source and returns the resulting string.
 * Only objects belonging to module usageModule are initialized.
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param source the source for code generated
 * @param usageModule the module where the template is to be used.
 */
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
    if (derivedReference != null) {
        final List<ISubReference> subreferences = derivedReference.getSubreferences();
        if (subreferences != null && !subreferences.isEmpty() && subreferences.get(0) instanceof ParameterisedSubReference) {
            final ParameterisedSubReference subreference = (ParameterisedSubReference) subreferences.get(0);
            final ActualParameterList actualParameterList = subreference.getActualParameters();
            if (actualParameterList != null) {
                actualParameterList.reArrangeInitCode(aData, source, usageModule);
            }
        }
        final Assignment assignment = derivedReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment == null) {
            return;
        }
        if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
            final ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
            final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
            if (formalParameterList != null) {
                // the referred template is parameterized
                // the embedded referenced templates shall be visited
                template.reArrangeInitCode(aData, source, usageModule);
            // FIXME implement
            } else {
                // its entire body has to be initialized now
                if (assignment.getMyScope().getModuleScope() == usageModule) {
                    template.generateCodeInit(aData, source, template.get_lhs_name());
                }
            }
        }
    }
    if (templateBody != null) {
        templateBody.reArrangeInitCode(aData, source, usageModule);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Example 9 with Def_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.

the class TemplateInstance method checkBaseTypeCompatibility.

private IType checkBaseTypeCompatibility(final CompilationTimeStamp timestamp, final IType governor, final Assignment derivedAssignment, final boolean setBaseTemplate) {
    boolean internalSetBase = setBaseTemplate;
    IType tempGovernor = governor;
    if (tempGovernor == null) {
        tempGovernor = type;
    }
    final IType baseTemplateType = derivedAssignment.getType(timestamp);
    if (tempGovernor != null) {
        if (!tempGovernor.isCompatible(timestamp, baseTemplateType, null, null, null)) {
            derivedReference.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEBASETYPE, derivedAssignment.getFullName(), tempGovernor.getTypename(), baseTemplateType.getTypename()));
            if (type == null) {
                tempGovernor = baseTemplateType;
            }
            internalSetBase = false;
        }
    } else {
        tempGovernor = baseTemplateType;
    }
    if (internalSetBase && derivedAssignment instanceof Def_Template) {
        templateBody.setBaseTemplate(((Def_Template) derivedAssignment).getTemplate(timestamp));
    }
    return tempGovernor;
}
Also used : Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) IType(org.eclipse.titan.designer.AST.IType)

Example 10 with Def_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.

the class TypenameInDef method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
        return;
    }
    final Definition s = (Definition) node;
    check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
Also used : Def_ExternalConst(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst) Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)9 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)6 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)5 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 IValue (org.eclipse.titan.designer.AST.IValue)4 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)4 IType (org.eclipse.titan.designer.AST.IType)3 Reference (org.eclipse.titan.designer.AST.Reference)3 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)3 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)3 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Def_ModulePar (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar)2 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)2 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)2 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)2 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)2 Stack (java.util.Stack)1