Search in sources :

Example 16 with ActualParameterList

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

the class Unknown_Applied_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (dereferredValue == null) {
        return;
    }
    dereferredValue.setLoweridToReference(timestamp);
    IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (type != null) {
        type = type.getTypeRefdLast(timestamp);
    }
    if (type == null) {
        return;
    }
    final ActualParameterList tempActualParameters = new ActualParameterList();
    FormalParameterList formalParameterList;
    switch(type.getTypetype()) {
        case TYPE_FUNCTION:
            if (realStatement == null || !Statement_type.S_FUNCTION_APPLIED.equals(realStatement.getType())) {
                realStatement = new Function_Applied_Statement(dereferredValue, actualParameterList, tempActualParameters);
                realStatement.setFullNameParent(this);
                realStatement.setLocation(location);
                realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
            }
            realStatement.check(timestamp);
            if (((Function_Type) type).getReturnType() != null) {
                location.reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNUSEDFUNCTIONRETURNVALUES, GeneralConstants.WARNING, null), MessageFormat.format(UNUSEDRETURNVALUE, type.getTypename()));
            }
            formalParameterList = ((Function_Type) type).getFormalParameters();
            formalParameterList.checkActualParameterList(timestamp, actualParameterList, tempActualParameters);
            break;
        case TYPE_ALTSTEP:
            if (realStatement == null || !Statement_type.S_ALTSTEP_APPLIED.equals(realStatement.getType())) {
                realStatement = new Altstep_Applied_Statement(dereferredValue, actualParameterList, tempActualParameters);
                realStatement.setFullNameParent(this);
                realStatement.setLocation(location);
                realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
            }
            realStatement.check(timestamp);
            formalParameterList = ((Altstep_Type) type).getFormalParameters();
            formalParameterList.checkActualParameterList(timestamp, actualParameterList, tempActualParameters);
            break;
        default:
            dereferredValue.getLocation().reportSemanticError(MessageFormat.format(FUNCTIONORALTSTEPVALUEXPECTED, type.getTypename()));
            break;
    }
    if (myStatementBlock != null) {
        myStatementBlock.checkRunsOnScope(timestamp, type, this, "call");
    }
    tempActualParameters.setFullNameParent(this);
    tempActualParameters.setMyScope(myScope);
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType)

Example 17 with ActualParameterList

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

the class Invoke_Altguard method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    if (expression != null) {
        final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
        final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_BOOL.equals(temporalType)) {
            last.getLocation().reportSemanticError(BOOLEANEXPECTED);
            expression.setIsErroneous(true);
        }
        if (expression.getMyGovernor() == null) {
            expression.setMyGovernor(new Boolean_Type());
        }
    }
    IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type == null) {
        lastTimeChecked = timestamp;
        return;
    }
    type = type.getTypeRefdLast(timestamp);
    if (type == null || type.getIsErroneous(timestamp)) {
        lastTimeChecked = timestamp;
        return;
    }
    if (!Type_type.TYPE_ALTSTEP.equals(type.getTypetype())) {
        value.getLocation().reportSemanticError(MessageFormat.format("A value of type altstep was expected instead of `{0}''", type.getTypename()));
        lastTimeChecked = timestamp;
        return;
    }
    value.getMyScope().checkRunsOnScope(timestamp, type, this, "call");
    final FormalParameterList formalParmaterList = ((Altstep_Type) type).getFormalParameters();
    actualParameterList = new ActualParameterList();
    formalParmaterList.checkActualParameterList(timestamp, parsedParameters, actualParameterList);
    if (statementblock != null) {
        statementblock.check(timestamp);
    }
    lastTimeChecked = timestamp;
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IValue(org.eclipse.titan.designer.AST.IValue) Boolean_Type(org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Altstep_Type(org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 18 with ActualParameterList

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

the class Testcase_Instance_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    source.append("\t\t");
    final ExpressionStruct expression = new ExpressionStruct();
    final Assignment testcase = testcaseReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    expression.expression.append(MessageFormat.format("{0}(", testcase.getGenNameFromScope(aData, source, myScope, "testcase_")));
    final List<ISubReference> subReferences = testcaseReference.getSubreferences();
    if (!subReferences.isEmpty() && subReferences.get(0) instanceof ParameterisedSubReference) {
        final ActualParameterList actualParList = ((ParameterisedSubReference) subReferences.get(0)).getActualParameters();
        if (actualParList.getNofParameters() > 0) {
            actualParList.generateCodeAlias(aData, expression);
            expression.expression.append(", ");
        }
    }
    if (timerValue != null) {
        expression.expression.append("true, ");
        timerValue.generateCodeExpression(aData, expression, true);
        expression.expression.append(')');
    } else {
        aData.addBuiltinTypeImport("TitanFloat");
        aData.addBuiltinTypeImport("Ttcn3Float");
        expression.expression.append("false, new TitanFloat( new Ttcn3Float( 0.0 ) ))");
    }
    expression.mergeExpression(source);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Example 19 with ActualParameterList

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

the class FormalParameterList method checkActualParameterList.

/**
 * Check if a list of parsed actual parameters is semantically correct
 * according to a list of formal parameters (the called entity).
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param instances
 *                the list of actual parameters containing both the
 *                named and the unnamed part converted into an unnamed
 *                list, that is full and in correct order.
 * @param actualParameters
 *                the list of actual parameters returned for later
 *                usage.
 *
 * @return true if a semantic error was found, false otherwise
 */
private boolean checkActualParameterList(final CompilationTimeStamp timestamp, final TemplateInstances instances, final ActualParameterList actualParameters) {
    boolean isErroneous = false;
    if (minimumNofParameters == parameters.size()) {
        if (instances.getNofTis() != parameters.size()) {
            instances.getLocation().reportSemanticError(MessageFormat.format("Too {0} parameters: {1} was expected instead of {2}", (instances.getNofTis() < parameters.size()) ? "few" : "many", parameters.size(), instances.getNofTis()));
            isErroneous = true;
        }
    } else {
        if (instances.getNofTis() < minimumNofParameters) {
            instances.getLocation().reportSemanticError(MessageFormat.format("Too few parameters: at least {0} was expected instaed of {1}", minimumNofParameters, instances.getNofTis()));
            isErroneous = true;
        } else if (instances.getNofTis() > parameters.size()) {
            instances.getLocation().reportSemanticError(MessageFormat.format("Too many parameters: at most {0} was expected instead of {1}", parameters.size(), instances.getNofTis()));
            isErroneous = true;
        }
    }
    final int upperLimit = (instances.getNofTis() < parameters.size()) ? instances.getNofTis() : parameters.size();
    for (int i = 0; i < upperLimit; i++) {
        final TemplateInstance instance = instances.getInstanceByIndex(i);
        final FormalParameter formalParameter = parameters.get(i);
        if (instance.getType() == null && instance.getDerivedReference() == null && Template_type.TEMPLATE_NOTUSED.equals(instance.getTemplateBody().getTemplatetype())) {
            if (formalParameter.hasDefaultValue()) {
                final ActualParameter defaultValue = formalParameter.getDefaultValue();
                final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
                actualParameters.addParameter(temp);
                if (defaultValue == null || defaultValue.getIsErroneous()) {
                    isErroneous = true;
                } else {
                    temp.setLocation(defaultValue.getLocation());
                }
            } else if (instance.getTemplateBody().getIsErroneous(timestamp)) {
                instances.getLocation().reportSemanticError(MessageFormat.format(MISSINGPARAMETER, formalParameter.getIdentifier().getDisplayName()));
                isErroneous = true;
            } else {
                instance.getLocation().reportSemanticError("Not used symbol (`-'') cannot be used for parameter that does not have a default value");
                final ActualParameter temp = new Value_ActualParameter(null);
                temp.setLocation(instances.getLocation());
                temp.setIsErroneous();
                actualParameters.addParameter(temp);
                isErroneous = true;
            }
        } else {
            final ActualParameter actualParameter = formalParameter.checkActualParameter(timestamp, instance, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
            actualParameter.setLocation(instance.getLocation());
            actualParameters.addParameter(actualParameter);
            if (actualParameter.getIsErroneous()) {
                isErroneous = true;
            }
        }
    }
    for (int i = upperLimit; i < parameters.size(); i++) {
        final FormalParameter formalParameter = parameters.get(i);
        if (formalParameter.hasDefaultValue()) {
            final ActualParameter defaultValue = formalParameter.getDefaultValue();
            final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
            actualParameters.addParameter(temp);
            if (defaultValue == null || defaultValue.getIsErroneous()) {
                isErroneous = true;
            } else {
                temp.setLocation(defaultValue.getLocation());
            }
        } else {
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setLocation(instances.getLocation());
            temp.setIsErroneous();
            actualParameters.addParameter(temp);
            isErroneous = true;
        }
    }
    return isErroneous;
}
Also used : TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 20 with ActualParameterList

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

the class ExecuteDereferedExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (value != null) {
        IType type;
        value.setLoweridToReference(timestamp);
        final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_TEMPLATE, referenceChain);
        if (last.getIsErroneous(timestamp)) {
            type = null;
        } else {
            type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
            if (type != null) {
                type = type.getTypeRefdLast(timestamp);
            }
        }
        if (type == null || type.getIsErroneous(timestamp)) {
            setIsErroneous(true);
        } else if (Type_type.TYPE_TESTCASE.equals(type.getTypetype())) {
            final FormalParameterList formalParameters = ((Testcase_Type) type).getFormalParameters();
            actualParameters = new ActualParameterList();
            final boolean isErroneous = formalParameters.checkActualParameterList(timestamp, actualParameterList, actualParameters);
            if (isErroneous) {
                setIsErroneous(true);
            }
        } else {
            value.getLocation().reportSemanticError(MessageFormat.format("Reference to a value of type testcase was expected in the argument of `derefers()'' instead of `{0}''", type.getTypename()));
            setIsErroneous(true);
        }
    }
    if (timerValue != null) {
        timerValue.setLoweridToReference(timestamp);
        final Type_type tempType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(tempType) {
            case TYPE_REAL:
                final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
                if (!last.isUnfoldable(timestamp)) {
                    final Real_Value real = (Real_Value) last;
                    final double i = real.getValue();
                    if (i < 0.0) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real.createStringRepresentation()));
                    } else if (real.isPositiveInfinity()) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(FLOATEXPECTED, real.createStringRepresentation()));
                    }
                }
                return;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                return;
            default:
                if (!isErroneous) {
                    timerValue.getLocation().reportSemanticError(OPERANDERROR);
                    setIsErroneous(true);
                }
                return;
        }
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, true, false, false);
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Aggregations

ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)18 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)13 IType (org.eclipse.titan.designer.AST.IType)9 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)6 Assignment (org.eclipse.titan.designer.AST.Assignment)5 IValue (org.eclipse.titan.designer.AST.IValue)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)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 HashMap (java.util.HashMap)2 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)2 NamedParameter (org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter)2 NamedParameters (org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters)2 NotUsed_Template (org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template)2 TemplateInstances (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1