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));
}
}
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);
}
}
}
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);
}
}
}
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));
}
}
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);
}
}
}
Aggregations