Search in sources :

Example 26 with Value

use of org.eclipse.titan.designer.AST.Value 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 27 with Value

use of org.eclipse.titan.designer.AST.Value 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 28 with Value

use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.

the class UnusedStartedRefFuncRetVal method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Start_Referenced_Component_Statement) {
        final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
        final Start_Referenced_Component_Statement s = (Start_Referenced_Component_Statement) node;
        final Value dereferredValue = s.getDereferredValue();
        if (dereferredValue == null) {
            return;
        }
        switch(dereferredValue.getValuetype()) {
            case EXPRESSION_VALUE:
                if (Operation_type.REFERS_OPERATION.equals(((Expression_Value) dereferredValue).getOperationType())) {
                    return;
                }
                break;
            case TTCN3_NULL_VALUE:
            case FAT_NULL_VALUE:
                return;
            default:
                break;
        }
        IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (type != null) {
            type = type.getTypeRefdLast(timestamp);
        }
        if (type == null || type.getIsErroneous(timestamp)) {
            return;
        }
        if (!(type instanceof Function_Type)) {
            return;
        }
        final Function_Type functionType = (Function_Type) type;
        if (functionType.isRunsOnSelf()) {
            return;
        }
        if (!functionType.isStartable(timestamp)) {
            return;
        }
        final IType returnType = functionType.getReturnType();
        if (returnType == null) {
            return;
        }
        if (functionType.returnsTemplate()) {
            return;
        }
        IType lastType = returnType;
        boolean returnTypeCorrect = false;
        while (!returnTypeCorrect) {
            if (lastType.hasDoneAttribute()) {
                returnTypeCorrect = true;
                break;
            }
            if (lastType instanceof IReferencingType) {
                final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                final IType refd = ((IReferencingType) lastType).getTypeRefd(timestamp, refChain);
                refChain.release();
                if (lastType != refd) {
                    lastType = refd;
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        if (!returnTypeCorrect) {
            final String msg = MessageFormat.format(PROBLEM, functionType.getTypename(), returnType.getTypename());
            problems.report(dereferredValue.getLocation(), msg);
        }
    }
}
Also used : IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Start_Referenced_Component_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Start_Referenced_Component_Statement) IType(org.eclipse.titan.designer.AST.IType)

Example 29 with Value

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

Example 30 with Value

use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.

the class LogicInversion method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof If_Statement) {
        final If_Statement s = (If_Statement) node;
        if (s.getStatementBlock() == null) {
            return;
        }
        final If_Clauses ifClauses = s.getIfClauses();
        if (ifClauses == null) {
            return;
        }
        final List<If_Clause> clauses = ifClauses.getClauses();
        if (clauses.size() != 1) {
            return;
        }
        final Value expression = clauses.get(0).getExpression();
        if (expression != null && Value_type.EXPRESSION_VALUE.equals(expression.getValuetype()) && Operation_type.NOT_OPERATION.equals(((Expression_Value) expression).getOperationType())) {
            problems.report(s.getLocation(), ERROR_MESSAGE);
        }
    }
}
Also used : Value(org.eclipse.titan.designer.AST.Value) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) If_Clauses(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clauses) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause)

Aggregations

Value (org.eclipse.titan.designer.AST.Value)71 IValue (org.eclipse.titan.designer.AST.IValue)63 ISubReference (org.eclipse.titan.designer.AST.ISubReference)50 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)41 IType (org.eclipse.titan.designer.AST.IType)34 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)18 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)18 Identifier (org.eclipse.titan.designer.AST.Identifier)12 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)6 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)6 BigInteger (java.math.BigInteger)5 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)5 HashMap (java.util.HashMap)4 SelectCase_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement)4 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Reference (org.eclipse.titan.designer.AST.Reference)3