Search in sources :

Example 11 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class UnusedStartedFuncRetVal method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Start_Component_Statement) {
        final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
        final Start_Component_Statement s = (Start_Component_Statement) node;
        final Component_Type compType = Port_Utility.checkComponentReference(timestamp, s, s.getComponent(), false, false);
        final Assignment assignment = s.getFunctionInstanceReference().getRefdAssignment(timestamp, false);
        if (assignment == null) {
            return;
        }
        switch(assignment.getAssignmentType()) {
            case A_FUNCTION:
            case A_FUNCTION_RTEMP:
            case A_FUNCTION_RVAL:
                break;
            default:
                return;
        }
        final Def_Function function = (Def_Function) assignment;
        final IType runsOnType = function.getRunsOnType(timestamp);
        if (compType == null || runsOnType == null || !function.isStartable()) {
            return;
        }
        switch(function.getAssignmentType()) {
            case A_FUNCTION_RTEMP:
                break;
            case A_FUNCTION_RVAL:
                IType type = function.getType(timestamp);
                boolean returnTypeCorrect = false;
                while (!returnTypeCorrect) {
                    if (type.hasDoneAttribute()) {
                        returnTypeCorrect = true;
                        break;
                    }
                    if (type instanceof IReferencingType) {
                        final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        final IType refd = ((IReferencingType) type).getTypeRefd(timestamp, refChain);
                        refChain.release();
                        if (type != refd) {
                            type = refd;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (!returnTypeCorrect) {
                    final String msg = MessageFormat.format(PROBLEM, function.getDescription(), function.getType(timestamp).getTypename());
                    problems.report(s.getFunctionInstanceReference().getLocation(), msg);
                }
                break;
            default:
                break;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Start_Component_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Start_Component_Statement) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) IType(org.eclipse.titan.designer.AST.IType)

Example 12 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class Altstep_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    last.setMyGovernor(this);
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    Def_Altstep altstep = null;
    switch(last.getValuetype()) {
        case ALTSTEP_REFERENCE_VALUE:
            altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
            if (altstep == null) {
                setIsErroneous(true);
                return selfReference;
            }
            altstep.check(timestamp);
            break;
        case TTCN3_NULL_VALUE:
            value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
            return selfReference;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            return selfReference;
        default:
            value.getLocation().reportSemanticError(ALTSTEPREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    formalParList.checkCompatibility(timestamp, altstep.getFormalParameterList(), value.getLocation());
    final IType temporalRunsOnType = altstep.getRunsOnType(timestamp);
    if (temporalRunsOnType != null) {
        if (runsOnSelf) {
            // check against the runs on component type of the scope of the value
            final Scope valueScope = value.getMyScope();
            if (valueScope == null) {
                value.setIsErroneous(true);
                return selfReference;
            }
            final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
            if (runsOnScope != null) {
                final Component_Type componentType = runsOnScope.getComponentType();
                if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current scope " + "expects component type `{1}'', but {2} runs on `{3}''", getTypename(), componentType.getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            } else {
                // compatibility using this component type as the scope
                if (valueScope instanceof ComponentTypeBody) {
                    final ComponentTypeBody body = (ComponentTypeBody) valueScope;
                    if (!runsOnType.isCompatible(timestamp, body.getMyType(), null, null, null)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' " + "clause and the current component definition is of type `{1}'', but {2} runs on `{3}''", getTypename(), body.getMyType().getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' has a `runs on self'' clause and the current scope does not have a `runs on'' clause," + " but {1} runs on `{2}''", getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            }
        } else {
            if (runsOnRef == null) {
                value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                value.setIsErroneous(true);
            } else {
                if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                    value.setIsErroneous(true);
                }
            }
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, value);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Scope(org.eclipse.titan.designer.AST.Scope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 13 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class Testcase_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    last.setMyGovernor(this);
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    Def_Testcase testcase = null;
    switch(last.getValuetype()) {
        case TESTCASE_REFERENCE_VALUE:
            testcase = ((Testcase_Reference_Value) last).getReferredTestcase();
            if (testcase == null) {
                setIsErroneous(true);
                return selfReference;
            }
            testcase.check(timestamp);
            break;
        case TTCN3_NULL_VALUE:
            value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
            return selfReference;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            return selfReference;
        default:
            value.getLocation().reportSemanticError(TESTCASEREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    final Component_Type temporalRunsOnType = testcase.getRunsOnType(timestamp);
    if (temporalRunsOnType != null) {
        if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
            value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), testcase.getAssignmentName(), temporalRunsOnType.getTypename()));
            value.setIsErroneous(true);
        }
    }
    formalParList.checkCompatibility(timestamp, testcase.getFormalParameterList(), value.getLocation());
    Component_Type temporalSystemType = testcase.getSystemType(timestamp);
    if (temporalSystemType == null) {
        temporalSystemType = temporalRunsOnType;
    }
    if (systemRef == null) {
        if (temporalSystemType != null && runsOnType != null && !temporalSystemType.isCompatible(timestamp, runsOnType, null, null, null)) {
            value.getLocation().reportSemanticError(MessageFormat.format(SYSTEMCLAUSEMISMATCHERROR, getTypename(), runsOnType.getTypename(), testcase.getAssignmentName(), temporalSystemType.getTypename()));
            value.setIsErroneous(true);
        }
    } else {
        if (temporalSystemType != null && systemType != null && !temporalSystemType.isCompatible(timestamp, systemType, null, null, null)) {
            value.getLocation().reportSemanticError(MessageFormat.format(SYSTEMCLAUSEMISMATCHERROR, getTypename(), systemType.getTypename(), testcase.getAssignmentName(), temporalSystemType.getTypename()));
            value.setIsErroneous(true);
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, value);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)

Example 14 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class ComponentTypeBody method generateCode.

/**
 * Add generated java code on this level.
 *
 * @param aData only used to update imports if needed
 * @param source the source code generated
 */
public void generateCode(final JavaGenData aData, final StringBuilder source) {
    final StringBuilder init_comp = aData.getInitComp();
    init_comp.append("if(\"").append(identifier.getDisplayName()).append("\".equals(component_type)) {\n");
    if (extendsReferences != null) {
        boolean hasBaseComponents = false;
        for (final ComponentTypeBody cb : compatibleBodies) {
            if (cb.definitions.size() > 0) {
                if (!hasBaseComponents) {
                    init_comp.append("if(init_base_comps) {\n");
                    hasBaseComponents = true;
                }
                // TODO get_scope_mod_gen
                if (getModuleScope().equals(cb.getModuleScope())) {
                    init_comp.append("init_comp_type(\"");
                    init_comp.append(cb.getIdentifier().getDisplayName());
                    init_comp.append("\", false);\n");
                } else {
                    init_comp.append("//TODO implement Module_List");
                    init_comp.append("Module_List::initialize_component(\"");
                    init_comp.append(cb.getModuleScope().getIdentifier().getDisplayName());
                    init_comp.append("\", \"");
                    init_comp.append(cb.getIdentifier().getDisplayName());
                    init_comp.append("\", false);\n");
                }
            }
        }
        if (hasBaseComponents) {
            init_comp.append("}\n");
        }
    }
    for (final Definition def : definitions) {
        if (extendsGainedDefinitions.containsKey(def.getIdentifier().getName())) {
            def.generateCodeInitComp(aData, init_comp, extendsGainedDefinitions.get(def.getIdentifier().getName()));
        } else {
            def.generateCode(aData, true);
        }
    }
    init_comp.append("return true;\n");
    init_comp.append("} else ");
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)8 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)6 IValue (org.eclipse.titan.designer.AST.IValue)6 Assignment (org.eclipse.titan.designer.AST.Assignment)5 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)4 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)4 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)3 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Scope (org.eclipse.titan.designer.AST.Scope)2 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)2 Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)2 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)2 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1