Search in sources :

Example 16 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class Operation_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());
        }
    }
    if (statement != null) {
        statement.check(timestamp);
    }
    if (statementblock != null) {
        statementblock.check(timestamp);
    }
    lastTimeChecked = timestamp;
}
Also used : 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)

Example 17 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class Scope method checkRunsOnScope.

/**
 * Checks that operations that can only be executed in definitions that
 * have a runs on scope, are really executed in such a definition. And
 * that the required runs on component is compatible with the runs on
 * component of the definition.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param assignment
 *                the assignment to check (used or referred to by the
 *                statement).
 * @param errorLocation
 *                the location to report the error to.
 * @param operation
 *                the name of the operation.
 */
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final Assignment assignment, final ILocateableNode errorLocation, final String operation) {
    Component_Type referencedComponent;
    switch(assignment.getAssignmentType()) {
        case A_ALTSTEP:
            referencedComponent = ((Def_Altstep) assignment).getRunsOnType(timestamp);
            break;
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            referencedComponent = ((Def_Function) assignment).getRunsOnType(timestamp);
            break;
        case A_TESTCASE:
            referencedComponent = ((Def_Testcase) assignment).getRunsOnType(timestamp);
            break;
        default:
            return;
    }
    if (referencedComponent == null) {
        return;
    }
    final RunsOnScope runsOnScope = getScopeRunsOn();
    if (runsOnScope == null) {
        errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED, operation, assignment.getDescription(), referencedComponent.getTypename()));
    } else {
        final Component_Type localType = runsOnScope.getComponentType();
        if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
            errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH, localType.getTypename(), operation, assignment.getDescription(), referencedComponent.getTypename()));
        }
    }
}
Also used : Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 18 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class Shorthand method check.

protected void check(final Statement s, final Problems problems) {
    if (s == null) {
        return;
    }
    // shorthand statements are ignored inside alt statements
    INamedNode curr = s;
    while (curr != null) {
        if (curr instanceof Alt_Statement || curr instanceof Call_Statement) {
            return;
        }
        curr = curr.getNameParent();
    }
    final StatementBlock sb = s.getMyStatementBlock();
    if (sb == null) {
        return;
    }
    final Definition d = sb.getMyDefinition();
    if (d == null) {
        return;
    }
    // shorthand statements are marked in functions, test cases and altsteps that have a 'runs on' clause
    if (d instanceof Def_Function && ((Def_Function) d).getRunsOnType(timestamp) != null) {
        problems.report(s.getLocation(), ERROR_MESSAGE_PREFIX + typename + ERROR_MESSAGE_SUFFIX);
        return;
    }
    if (d instanceof Def_Altstep || d instanceof Def_Testcase) {
        problems.report(s.getLocation(), ERROR_MESSAGE_PREFIX + typename + ERROR_MESSAGE_SUFFIX);
    }
}
Also used : Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) INamedNode(org.eclipse.titan.designer.AST.INamedNode) Call_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Call_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 19 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class UnusedRetval method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Unknown_Instance_Statement) {
        final Unknown_Instance_Statement u = (Unknown_Instance_Statement) node;
        final Statement s = u.getRealStatement();
        if (s instanceof Function_Instance_Statement) {
            final Function_Instance_Statement f = (Function_Instance_Statement) s;
            final Assignment assignment = f.getReference().getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            if (assignment != null) {
                String msg;
                switch(assignment.getAssignmentType()) {
                    case A_FUNCTION_RVAL:
                    case A_EXT_FUNCTION_RVAL:
                        msg = MessageFormat.format(UNUSEDRETURN1, assignment.getIdentifier().getDisplayName());
                        problems.report(f.getLocation(), msg);
                        break;
                    case A_FUNCTION_RTEMP:
                    case A_EXT_FUNCTION_RTEMP:
                        msg = MessageFormat.format(UNUSEDRETURN2, assignment.getIdentifier().getDisplayName());
                        problems.report(f.getLocation(), msg);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Unknown_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Instance_Statement) Function_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Function_Instance_Statement) Function_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Function_Instance_Statement) Unknown_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Instance_Statement)

Example 20 with Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.

the class IterateOnWrongArray method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof For_Statement)) {
        return;
    }
    final For_Statement fs = (For_Statement) node;
    // find the loop variable
    final LoopVariableFinder lvVisitor = new LoopVariableFinder();
    fs.accept(lvVisitor);
    final Reference loopVar = lvVisitor.getLoopVariable();
    if (loopVar == null) {
        return;
    }
    final Assignment loopVarDef = loopVar.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    if (loopVarDef == null) {
        return;
    }
    // find the array over which the loop iterates
    final Value finalExpr = fs.getFinalExpression();
    if (finalExpr == null) {
        return;
    }
    final FinalExprVisitor exprVisitor = new FinalExprVisitor();
    finalExpr.accept(exprVisitor);
    final List<Reference> arraysIterated = exprVisitor.getArraysIterated();
    if (arraysIterated.isEmpty()) {
        return;
    }
    /* search every statement block for references that has the loop variable in them and the
		 * reference differs from the reference of the array over which the for loop iterates */
    final StatementBlock sb = fs.getStatementBlock();
    if (sb == null) {
        return;
    }
    final StatementBlockVisitor sbVisitor = new StatementBlockVisitor(loopVar, arraysIterated);
    sb.accept(sbVisitor);
    final List<Reference> matchingRefs = sbVisitor.getMatchingReferences();
    for (final Reference r : matchingRefs) {
        if (r.getUsedOnLeftHandSide()) {
            continue;
        }
        problems.report(r.getLocation(), MessageFormat.format(ERR_MSG, loopVar));
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) For_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement) Reference(org.eclipse.titan.designer.AST.Reference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Value(org.eclipse.titan.designer.AST.Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) IValue(org.eclipse.titan.designer.AST.IValue) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)13 Assignment (org.eclipse.titan.designer.AST.Assignment)11 IValue (org.eclipse.titan.designer.AST.IValue)11 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)11 Reference (org.eclipse.titan.designer.AST.Reference)10 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)7 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Location (org.eclipse.titan.designer.AST.Location)6 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Module (org.eclipse.titan.designer.AST.Module)5 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)4 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)4 Receive_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement)4 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)4 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)4 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3