Search in sources :

Example 6 with Def_Extfunction

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

the class Function_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;
    }
    Assignment assignment = null;
    switch(last.getValuetype()) {
        case FUNCTION_REFERENCE_VALUE:
            assignment = ((Function_Reference_Value) last).getReferredFunction();
            if (assignment == null) {
                value.setIsErroneous(true);
                return selfReference;
            }
            assignment.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(FUNCTIONREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    // external functions do not have runs on clauses
    if (assignment instanceof Def_Function) {
        formalParList.checkCompatibility(timestamp, ((Def_Function) assignment).getFormalParameterList(), value.getLocation());
        final IType tempRunsOnType = ((Def_Function) assignment).getRunsOnType(timestamp);
        if (tempRunsOnType != 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);
                    value.setLastTimeChecked(timestamp);
                    return selfReference;
                }
                final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
                if (runsOnScope != null) {
                    final Component_Type componentType = runsOnScope.getComponentType();
                    if (!tempRunsOnType.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(), assignment.getDescription(), tempRunsOnType.getTypename()));
                    }
                } else {
                    // compatibility using this component type as the scope
                    if (valueScope instanceof ComponentTypeBody) {
                        final ComponentTypeBody body = (ComponentTypeBody) valueScope;
                        if (!tempRunsOnType.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(), assignment.getDescription(), tempRunsOnType.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(), assignment.getDescription(), tempRunsOnType.getTypename()));
                    }
                }
            } else {
                if (runsOnRef == null) {
                    value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), assignment.getAssignmentName(), tempRunsOnType.getTypename()));
                    value.setIsErroneous(true);
                } else {
                    if (runsOnType != null && !tempRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
                        value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), assignment.getAssignmentName(), tempRunsOnType.getTypename()));
                        value.setIsErroneous(true);
                    }
                }
            }
        }
    }
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_EXT_FUNCTION:
            if (returnType != null) {
                value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a {1} of type `{2}'', but {3} does not have a return type", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription()));
            }
            break;
        case A_FUNCTION_RTEMP:
            {
                final Restriction_type restriction = ((Def_Function) assignment).getTemplateRestriction();
                if (!templateRestriction.equals(restriction)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template with {1} restriction, " + "but {2} returns a template with {3} restriction", getTypename(), Restriction_type.TR_NONE.equals(templateRestriction) ? "no" : templateRestriction.getDisplayName(), assignment.getDescription(), Restriction_type.TR_NONE.equals(restriction) ? "no" : restriction.getDisplayName()));
                }
                if (returnType != null) {
                    final IType tempReturnType = assignment.getType(timestamp);
                    if (!returnType.isIdentical(timestamp, tempReturnType)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}'', " + "but {3} returns a template of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
                    } else if (!returnsTemplate) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a value of type `{1}'', but {2} returns a template", getTypename(), returnType.getTypename(), assignment.getDescription()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a template of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
                }
                break;
            }
        case A_EXT_FUNCTION_RTEMP:
            {
                final Restriction_type restriction = ((Def_Extfunction) assignment).getTemplateRestriction();
                if (!templateRestriction.equals(restriction)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template with {1} restriction, " + "but {2} returns a template with {3} restriction", getTypename(), Restriction_type.TR_NONE.equals(templateRestriction) ? "no" : templateRestriction.getDisplayName(), assignment.getDescription(), Restriction_type.TR_NONE.equals(restriction) ? "no" : restriction.getDisplayName()));
                }
                if (returnType != null) {
                    final IType tempReturnType = assignment.getType(timestamp);
                    if (!returnType.isIdentical(timestamp, tempReturnType)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}'', " + "but {3} returns a template of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
                    } else if (!returnsTemplate) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a value of type `{1}'', but {2} returns a template", getTypename(), returnType.getTypename(), assignment.getDescription()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a template of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
                }
                break;
            }
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
            if (returnType != null) {
                final IType tempReturnType = assignment.getType(timestamp);
                if (!returnType.isIdentical(timestamp, tempReturnType)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}''," + " but {3} returns a value of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
                } else if (returnsTemplate) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template of type `{1}'', but {2} returns a value", getTypename(), returnType.getTypename(), assignment.getDescription()));
                }
            } else {
                value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a value of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
            }
            break;
        default:
            break;
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Scope(org.eclipse.titan.designer.AST.Scope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 7 with Def_Extfunction

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

Example 8 with Def_Extfunction

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

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

the class ReadOnlyInOutPar method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof FormalParameter) {
        final FormalParameter s = (FormalParameter) node;
        if (s.getMyParameterList().getMyDefinition() instanceof Def_Type) {
            return;
        }
        if (!s.getWritten() && !(s.getMyParameterList().getMyDefinition() instanceof Def_Extfunction)) {
            switch(s.getAssignmentType()) {
                case A_PAR_VAL_INOUT:
                case A_PAR_TEMP_INOUT:
                    final String msg = MessageFormat.format(READONLY, s.getDescription());
                    problems.report(s.getLocation(), msg);
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction)

Example 10 with Def_Extfunction

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

the class ReadOnlyOutPar method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof FormalParameter) {
        final FormalParameter s = (FormalParameter) node;
        if (s.getMyParameterList().getMyDefinition() instanceof Def_Type) {
            return;
        }
        if (!s.getWritten() && !(s.getMyParameterList().getMyDefinition() instanceof Def_Extfunction)) {
            switch(s.getAssignmentType()) {
                case A_PAR_VAL_OUT:
                case A_PAR_TEMP_OUT:
                    final String msg = MessageFormat.format(READONLY, s.getDescription());
                    problems.report(s.getLocation(), msg);
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction)

Aggregations

Def_Extfunction (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction)4 Assignment (org.eclipse.titan.designer.AST.Assignment)3 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)3 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)3 IType (org.eclipse.titan.designer.AST.IType)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)2 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)2 FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)2 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Scope (org.eclipse.titan.designer.AST.Scope)1 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)1 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)1 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)1