Search in sources :

Example 6 with FormalParameterList

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

the class Start_Referenced_Component_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    Component_Type compType = null;
    if (componentReference != null) {
        compType = Port_Utility.checkComponentReference(timestamp, this, componentReference, false, false);
    }
    if (dereferredValue == null) {
        return;
    }
    switch(dereferredValue.getValuetype()) {
        case EXPRESSION_VALUE:
            if (Operation_type.REFERS_OPERATION.equals(((Expression_Value) dereferredValue).getOperationType())) {
                dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `refers' operation," + " which does not specify any function type.");
                return;
            }
            break;
        case TTCN3_NULL_VALUE:
        case FAT_NULL_VALUE:
            dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `null' value, which does not specify any function type.");
            return;
        default:
            break;
    }
    dereferredValue.setLoweridToReference(timestamp);
    IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type != null) {
        type = type.getTypeRefdLast(timestamp);
    }
    if (type == null || type.getIsErroneous(timestamp)) {
        return;
    }
    if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
        dereferredValue.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument of `{0}''", type.getTypename()));
        return;
    }
    final Function_Type functionType = (Function_Type) type;
    if (functionType.isRunsOnSelf()) {
        dereferredValue.getLocation().reportSemanticError("The argument cannot be a function reference with 'runs on self' clause");
        return;
    }
    if (!functionType.checkStartable(timestamp, getLocation())) {
        return;
    }
    final IType runsOnType = functionType.getRunsOnType(timestamp);
    if (compType != null && runsOnType != null && !runsOnType.isCompatible(timestamp, compType, null, null, null)) {
        final String message = MessageFormat.format("Component type mismatch: the component reference os of type `{0}'', but functions of type `{1}'' run on `{2}''", compType.getTypename(), functionType.getTypename(), runsOnType.getTypename());
        componentReference.getLocation().reportSemanticError(message);
    }
    final IType returnType = functionType.getReturnType();
    if (returnType != null) {
        if (functionType.returnsTemplate()) {
            dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Function of type `{0}'' return a template of type `{1}''," + " which cannot be retrieved when the test component terminates", functionType.getTypename(), returnType.getTypename()));
        } else {
            IType lastType = returnType;
            boolean returnTypeCorrect = false;
            while (!returnTypeCorrect) {
                if (lastType.hasDoneAttribute()) {
                    returnTypeCorrect = true;
                    break;
                }
                if (lastType instanceof IReferencingType) {
                    final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final IType refd = ((IReferencingType) lastType).getTypeRefd(timestamp, refChain);
                    refChain.release();
                    if (lastType != refd) {
                        lastType = refd;
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }
            if (!returnTypeCorrect) {
                dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Return type of function type `{0}'' is `{1}'', which does not have the `done'' extension attibute." + " When the test component terminates the returnes value cannot be retrived with a `done'' operation", functionType.getTypename(), returnType.getTypename()));
            }
        }
    }
    actualParameterList2 = new ActualParameterList();
    final FormalParameterList formalParameters = functionType.getFormalParameters();
    if (!formalParameters.checkActualParameterList(timestamp, parameters, actualParameterList2)) {
        actualParameterList2.setFullNameParent(this);
        actualParameterList2.setMyScope(getMyScope());
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType)

Example 7 with FormalParameterList

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

the class Reference method generateCodeIsPresentBoundChosen.

/**
 * Generates code for checking if the reference
 * and the referred objects are bound or not.
 *
 * generate_code_ispresentbound in the compiler
 *
 * @param aData only used to update imports if needed
 * @param expression the expression for code generated
 * @param isTemplate if the reference is pointing to a template
 * @param optype true to generate code for isbound, false otherwise
 */
public void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final boolean isTemplate, final Operation_type optype, final String field) {
    final Assignment assignment = getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    final String ass_id = assignment.getGenNameFromScope(aData, expression.expression, myScope, null);
    String ass_id2 = ass_id;
    FormalParameterList formalParameterList;
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            formalParameterList = ((Def_Function) assignment).getFormalParameterList();
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            formalParameterList = ((Def_Extfunction) assignment).getFormalParameterList();
            break;
        case A_TEMPLATE:
            formalParameterList = ((Def_Template) assignment).getFormalParameterList();
            break;
        default:
            formalParameterList = null;
            break;
    }
    if (subReferences.size() > 0 && subReferences.get(0) instanceof ParameterisedSubReference) {
        final ParameterisedSubReference subReference = (ParameterisedSubReference) subReferences.get(0);
        final ExpressionStruct tempExpression = new ExpressionStruct();
        // FIXME should need the formal parameters and other
        // options
        subReference.getActualParameters().generateCodeAlias(aData, tempExpression);
        if (tempExpression.preamble.length() > 0) {
            expression.preamble.append(tempExpression.preamble);
        }
        ass_id2 = MessageFormat.format("{0}({1})", ass_id, tempExpression.expression);
    } else if (formalParameterList != null) {
        // the reference does not have an actual parameter list,
        // but the assignment has
        final ExpressionStruct tempExpression = new ExpressionStruct();
        final StringBuilder newId = new StringBuilder();
        newId.append(assignment.getGenNameFromScope(aData, tempExpression.expression, getMyScope(), null));
        newId.append("( ");
        // ((FieldSubReference)subReferences.get(0));
        for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
            if (i > 0) {
                tempExpression.expression.append(", ");
            }
            formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, tempExpression);
        }
        // expression);
        if (tempExpression.preamble.length() > 0) {
            expression.preamble.append(tempExpression.preamble);
        }
        newId.append(tempExpression.expression);
        newId.append(" )");
        ass_id2 = newId.toString();
    }
    if (subReferences.size() > 1) {
        final String tempGeneralId = aData.getTemporaryVariableName();
        final ExpressionStruct isboundExpression = new ExpressionStruct();
        isboundExpression.preamble.append(MessageFormat.format("boolean {0} = {1}.isBound();\n", tempGeneralId, ass_id2));
        final IType type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
        type.generateCodeIsPresentBoundChosen(aData, isboundExpression, subReferences, 1, tempGeneralId, ass_id2, isTemplate, optype, field);
        expression.preamble.append(isboundExpression.preamble);
        expression.preamble.append(isboundExpression.expression);
        expression.expression.append(tempGeneralId);
    } else {
        switch(optype) {
            case ISBOUND_OPERATION:
                expression.expression.append(MessageFormat.format("{0}.isBound()", ass_id2));
                break;
            case ISPRESENT_OPERATION:
                expression.expression.append(MessageFormat.format("{0}.isPresent({1})", ass_id2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
                break;
            case ISCHOOSEN_OPERATION:
                expression.expression.append(MessageFormat.format("{0}.isChosen({1})", ass_id2, field));
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for reference `" + getFullName() + "''");
                break;
        }
    }
}
Also used : IParameterisedAssignment(org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 8 with FormalParameterList

use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList 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 9 with FormalParameterList

use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList 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 10 with FormalParameterList

use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList 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)

Aggregations

FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)22 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)14 IType (org.eclipse.titan.designer.AST.IType)10 Assignment (org.eclipse.titan.designer.AST.Assignment)4 IValue (org.eclipse.titan.designer.AST.IValue)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)3 IParameterisedAssignment (org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment)3 Altstep_Type (org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type)3 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)3 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)2 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)2