Search in sources :

Example 1 with SelectCase_Statement

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

the class SelectCoverage method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof SelectCase_Statement)) {
        return;
    }
    final SelectCase_Statement s = (SelectCase_Statement) node;
    final Value v = s.getExpression();
    if (v == null || v.getIsErroneous(timestamp)) {
        return;
    }
    // if there is an else branch, no smell will be reported
    final SelectCases scs = s.getSelectCases();
    if (scs == null || scs.getSelectCaseArray() == null) {
        return;
    }
    for (final SelectCase sc : scs.getSelectCaseArray()) {
        if (sc.hasElse()) {
            return;
        }
    }
    IType itype = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (itype instanceof Referenced_Type) {
        itype = itype.getTypeRefdLast(timestamp);
    }
    if (itype == null || !(itype instanceof TTCN3_Enumerated_Type)) {
        return;
    }
    final TTCN3_Enumerated_Type enumType = (TTCN3_Enumerated_Type) itype;
    // count number of items in enum, get all items from enum
    final EnumItemVisitor enumVisitor = new EnumItemVisitor();
    enumType.accept(enumVisitor);
    // count number of TemplateInstances in select, get used enum items
    final CaseVisitor caseVisitor = new CaseVisitor();
    scs.accept(caseVisitor);
    if (caseVisitor.isContainsUnfoldable()) {
        return;
    }
    final int casesSize = caseVisitor.getCount();
    final int enumSize = enumVisitor.getCount();
    if (enumSize > casesSize) {
        final List<Identifier> allEnumItems = enumVisitor.getItemsFound();
        final List<Identifier> usedEnumItems = caseVisitor.getItemsUsed();
        final String enumName = itype.getTypename();
        final String itemsNotCovered = getItemsNotCovered(allEnumItems, usedEnumItems);
        problems.report(v.getLocation(), MessageFormat.format(ERR_MSG, enumName, enumSize, casesSize, itemsNotCovered));
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Example 2 with SelectCase_Statement

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

the class SwitchOnBoolean method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof SelectCase_Statement) {
        final SelectCase_Statement s = (SelectCase_Statement) node;
        final Value expression = s.getExpression();
        final CompilationTimeStamp ct = CompilationTimeStamp.getBaseTimestamp();
        if (expression != null && Type_type.TYPE_BOOL.equals(expression.getExpressionReturntype(ct, Expected_Value_type.EXPECTED_DYNAMIC_VALUE))) {
            problems.report(expression.getLocation(), ERROR_MESSAGE);
        }
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Value(org.eclipse.titan.designer.AST.Value)

Example 3 with SelectCase_Statement

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

the class ConvertToEnum method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof SelectCase_Statement)) {
        return;
    }
    final SelectCase_Statement s = (SelectCase_Statement) node;
    final Value v = s.getExpression();
    if (v == null || v.getIsErroneous(timestamp)) {
        return;
    }
    final IType.Type_type type = v.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (!type.equals(Type_type.TYPE_TTCN3_ENUMERATED)) {
        final IType governor = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
        if (governor != null && !governor.getIsErroneous(timestamp)) {
            problems.report(v.getLocation(), MessageFormat.format(ERROR_MSG_SELECT, governor.getTypename()));
        }
    }
    final SelectCases scs = s.getSelectCases();
    if (scs == null || scs.getSelectCaseArray() == null) {
        return;
    }
    for (final SelectCase sc : scs.getSelectCaseArray()) {
        if (sc.hasElse()) {
            continue;
        }
        final CaseVisitor visitor = new CaseVisitor(problems);
        sc.accept(visitor);
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Value(org.eclipse.titan.designer.AST.Value) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with SelectCase_Statement

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

the class ReturnVisitor method visit.

@Override
public int visit(final IVisitableNode node) {
    // certain YES
    if (node instanceof Return_Statement) {
        certainty = ReturnCertainty.YES;
        return V_ABORT;
    }
    // 
    if (node instanceof StatementBlock || node instanceof StatementList) {
        final StatementBlockVisitor blockVis = new StatementBlockVisitor();
        node.accept(blockVis);
        certainty = blockVis.getCertainty();
        return V_SKIP;
    }
    // custom statements
    if (node instanceof While_Statement || node instanceof DoWhile_Statement || node instanceof For_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // conditional blocks: maximum MAYBE
        certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        return V_SKIP;
    }
    if (node instanceof If_Statement) {
        final If_Statement ifs = (If_Statement) node;
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        if (ifs.getStatementBlock() != null) {
            // must enter one block: maximum YES
            certainty = branchMerger.getCertainty();
        } else {
            // conditional blocks: maximum MAYBE
            certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        }
        return V_SKIP;
    }
    if (node instanceof Alt_Statement) {
        final AltGuards ags = ((Alt_Statement) node).getAltGuards();
        final BranchMerger branchMerger = new BranchMerger();
        ags.accept(branchMerger);
        if (ags.hasElse()) {
            // must enter one block: maximum YES
            certainty = branchMerger.getCertainty();
        } else {
            // conditional blocks: maximum MAYBE
            certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        }
        return V_SKIP;
    }
    if (node instanceof Interleave_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // conditional block: maximum MAYBE
        certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        return V_SKIP;
    }
    if (node instanceof StatementBlock_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // must enter block: maximum YES
        certainty = branchMerger.getCertainty();
        return V_SKIP;
    }
    if (node instanceof SelectCase_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // must enter one block: maximum YES
        certainty = branchMerger.getCertainty();
        return V_SKIP;
    }
    return V_ABORT;
}
Also used : For_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement) SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) Interleave_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Interleave_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement) StatementBlock_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock_Statement) AltGuards(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuards) Return_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) While_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.While_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement)

Example 5 with SelectCase_Statement

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

the class SelectWithNumbersSorted method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof SelectCase_Statement)) {
        return;
    }
    final SelectCase_Statement s = (SelectCase_Statement) node;
    final Value v = s.getExpression();
    if (v == null || v.getIsErroneous(timestamp)) {
        return;
    }
    final SelectCases scs = s.getSelectCases();
    if (scs == null || scs.getSelectCaseArray() == null) {
        return;
    }
    // if there is an else branch, no smell will be reported
    for (final SelectCase sc : scs.getSelectCaseArray()) {
        if (sc.hasElse()) {
            return;
        }
    }
    IType itype = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    // TODO Kristof: az ellenorzes folosleges.
    if (itype instanceof Referenced_Type) {
        itype = itype.getTypeRefdLast(timestamp);
    }
    if (itype == null || !(itype instanceof Integer_Type)) {
        return;
    }
    // count number of cases in select, get used integer type case-items
    final CaseVisitorInteger caseVisitorInteger = new CaseVisitorInteger();
    scs.accept(caseVisitorInteger);
    if (caseVisitorInteger.containsUnfoldable()) {
        return;
    }
    final List<Long> usedIntegerItems = caseVisitorInteger.getItemsUsed();
    if (!checkIfIntegerCasesSorted(usedIntegerItems)) {
        problems.report(s.getLocation(), ERR_MSG);
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

SelectCase_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement)5 Value (org.eclipse.titan.designer.AST.Value)4 IType (org.eclipse.titan.designer.AST.IType)3 SelectCase (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase)3 SelectCases (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases)3 IValue (org.eclipse.titan.designer.AST.IValue)2 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)2 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 AltGuards (org.eclipse.titan.designer.AST.TTCN3.statements.AltGuards)1 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)1 DoWhile_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement)1 For_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement)1 If_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement)1 Interleave_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Interleave_Statement)1 Return_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement)1 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)1 StatementBlock_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock_Statement)1 While_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.While_Statement)1 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)1