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