Search in sources :

Example 16 with Def_Function

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

the class Return_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    genRestrictionCheck = false;
    final Definition definition = myStatementBlock.getMyDefinition();
    if (definition == null) {
        location.reportSemanticError(USAGEINCONTROLPART);
        return;
    }
    switch(definition.getAssignmentType()) {
        case A_FUNCTION:
            if (template != null) {
                template.getLocation().reportSemanticError(UNEXPECTEDRETURNVALUE);
            }
            break;
        case A_FUNCTION_RVAL:
            final Type returnType = ((Def_Function) definition).getType(timestamp);
            if (template == null) {
                location.reportSemanticError(MessageFormat.format(MISSINGVALUE, returnType.getTypename()));
                break;
            }
            if (!template.isValue(timestamp)) {
                template.getLocation().reportSemanticError(SPECIFICVALUEEXPECTED);
                break;
            }
            // General:
            template.setMyGovernor(returnType);
            final IValue value = template.getValue();
            if (value != null) {
                value.setMyGovernor(returnType);
                returnType.checkThisValueRef(timestamp, value);
                returnType.checkThisValue(timestamp, value, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
            }
            break;
        case A_FUNCTION_RTEMP:
            if (template == null) {
                location.reportSemanticError(MessageFormat.format(MISSINGTEMPLATE, ((Def_Function) definition).getType(timestamp).getTypename()));
            } else {
                final Type returnType1 = ((Def_Function) definition).getType(timestamp);
                template.setMyGovernor(returnType1);
                final ITTCN3Template temporalTemplate1 = returnType1.checkThisTemplateRef(timestamp, template, Expected_Value_type.EXPECTED_TEMPLATE, null);
                temporalTemplate1.checkThisTemplateGeneric(timestamp, returnType1, true, /* isModified */
                true, /* allowOmit */
                true, /* allowAnyOrOmit */
                true, /* subCheck */
                true, /* implicitOmit */
                null);
                genRestrictionCheck = TemplateRestriction.check(timestamp, definition, temporalTemplate1, null);
            }
            break;
        case A_ALTSTEP:
            if (template != null) {
                template.getLocation().reportSemanticError(ALTSTEPRETURNINGVALUE);
            }
            break;
        default:
            location.reportSemanticError(MessageFormat.format(UNEXPETEDRETURNSTATEMENT, definition.getAssignmentName()));
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Type(org.eclipse.titan.designer.AST.Type) IValue(org.eclipse.titan.designer.AST.IValue) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 17 with Def_Function

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

the class Start_Component_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    final Component_Type componentType = Port_Utility.checkComponentReference(timestamp, this, componentReference, false, false);
    final Assignment assignment = functionInstanceReference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RTEMP:
        case A_FUNCTION_RVAL:
            break;
        default:
            functionInstanceReference.getLocation().reportSemanticError(MessageFormat.format(REFERENCETOFUNCTIONWASEXPECTED, assignment.getDescription()));
            return;
    }
    final Def_Function function = (Def_Function) assignment;
    if (!function.checkStartable(timestamp, getLocation())) {
        return;
    }
    final IType runsOnType = function.getRunsOnType(timestamp);
    if (componentType == null || runsOnType == null) {
        return;
    }
    if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
        componentReference.getLocation().reportSemanticError(MessageFormat.format(COMPONENTTYPEMISMATCH, componentType.getTypename(), function.getDescription(), runsOnType.getTypename()));
    }
    switch(function.getAssignmentType()) {
        case A_FUNCTION_RTEMP:
            functionInstanceReference.getLocation().reportSemanticWarning(MessageFormat.format(TEMPLATERETURN, function.getFullName(), function.getType(timestamp).getTypename()));
            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 message = MessageFormat.format(RETURNWITHOUTDONE, function.getDescription(), function.getType(timestamp).getTypename());
                    functionInstanceReference.getLocation().reportSemanticWarning(message);
                }
                break;
            }
        default:
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) 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 18 with Def_Function

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

the class FunctionContext method process_internal.

@Override
protected void process_internal() {
    final Def_Function func = getNode();
    final FormalParameterList fpl = func.getFormalParameterList();
    final ParameterListVisitor vis = new ParameterListVisitor();
    fpl.accept(vis);
    paramIds = vis.getResult();
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 19 with Def_Function

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

the class RefersExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (referred == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || referredAssignment == null) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    switch(referredAssignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RTEMP:
        case A_FUNCTION_RVAL:
            lastValue = new Function_Reference_Value((Def_Function) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
            lastValue = new Function_Reference_Value((Def_Extfunction) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_ALTSTEP:
            lastValue = new Altstep_Reference_Value((Def_Altstep) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        case A_TESTCASE:
            lastValue = new Testcase_Reference_Value((Def_Testcase) referredAssignment);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Altstep_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Altstep_Reference_Value) Testcase_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Testcase_Reference_Value) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 20 with Def_Function

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

the class RunsOnScopeReduction method process.

@Override
protected void process(IVisitableNode node, Problems problems) {
    final Set<Identifier> definitions = new HashSet<Identifier>();
    final Identifier componentIdentifier;
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    final Identifier identifier;
    boolean isTestCase = false;
    if (node instanceof Def_Function) {
        final Def_Function variable = (Def_Function) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else if (node instanceof Def_Altstep) {
        final Def_Altstep variable = (Def_Altstep) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else {
        final Def_Testcase variable = (Def_Testcase) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
        isTestCase = true;
    }
    final ReferenceCheck chek = new ReferenceCheck();
    node.accept(chek);
    definitions.addAll(chek.getIdentifiers());
    if (definitions.isEmpty()) {
        if (isTestCase) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.", componentIdentifier.getDisplayName()));
        } else {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used, can be removed.", componentIdentifier.getDisplayName()));
        }
    } else if (!definitions.contains(componentIdentifier)) {
        ArrayList<Identifier> list = new ArrayList<Identifier>(definitions);
        if (definitions.size() == 1) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use `{1}'' component.", componentIdentifier.getName(), list.get(0).getDisplayName()));
        } else {
            // FIXME: implement other cases
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used.", componentIdentifier.getDisplayName()));
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ArrayList(java.util.ArrayList) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) HashSet(java.util.HashSet)

Aggregations

Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)17 Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)8 Assignment (org.eclipse.titan.designer.AST.Assignment)6 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)5 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)5 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)5 ArrayList (java.util.ArrayList)4 IType (org.eclipse.titan.designer.AST.IType)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 IValue (org.eclipse.titan.designer.AST.IValue)3 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)3 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)3 HashMap (java.util.HashMap)2 DeleteEdit (org.eclipse.text.edits.DeleteEdit)2 InsertEdit (org.eclipse.text.edits.InsertEdit)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 TextEdit (org.eclipse.text.edits.TextEdit)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2