Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RoboSim warning #25

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<unit id="org.eclipse.xpand" version="0.0.0"/>
<unit id="org.eclipse.xtend" version="0.0.0"/>
<unit id="org.eclipse.xtend.typesystem.emf" version="0.0.0"/>
<repository location="http://download.eclipse.org/releases/2020-03"/>
<repository location="https://download.eclipse.org/releases/2021-12"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.emf.mwe2.launcher.feature.group" version="0.0.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ import circus.robocalc.robochart.CommunicationStmt
import circus.robocalc.robosim.OutputCommunication
import circus.robocalc.robochart.Call
import circus.robocalc.robosim.SimOperationDef
import circus.robocalc.robosim.ExecStatement
import circus.robocalc.robochart.SeqStatement
import circus.robocalc.robochart.Statement
import circus.robocalc.robochart.IfStmt
import org.eclipse.internal.xpand2.ast.IfStatement
import circus.robocalc.robochart.Skip
import circus.robocalc.robochart.ClockReset
import circus.robocalc.robochart.ParStmt

/**
* This class contains custom validation rules.
Expand All @@ -88,6 +96,7 @@ class RoboSimValidator extends AbstractRoboSimValidator {
public final static String CYCLE_MUST_BE_BOOLEAN_EXPRESSION = "cycleMustBeBooleanExpression"
public final static String CONST_CYCLE_MUST_BE_NAME_CYCLE = "constCycleMustBeNameCycle"
public final static String CONST_CYCLE_MUST_BE_BOOLEAN = "constCycleMustBeBoolean"
public final static String SELF_TRANSITION_WITHOUT_EXEC = "selfTrasitionWithoutExec";

@Inject extension RoboSimTypeProvider

Expand Down Expand Up @@ -949,4 +958,73 @@ class RoboSimValidator extends AbstractRoboSimValidator {

}

@Check
def selfTrasitionWithoutExecTriggerAndExecStatement(Transition t) {
if (t.source == t.target){
if (t.trigger===null && t.action===null){
warning(
'Self-transition of state ' + t.source.name + ' does not have an exec. This may lead to a livelock.',
RoboChartPackage.Literals.TRANSITION__TRIGGER,
'selfTrasitionWithoutExecTriggerAndExecStatement')
}

}
}

@Check
def selfTrasitionWithoutExec(Transition t) {
if (t.source == t.target && t.trigger === null && t.action!==null && !(t.action instanceof ExecStatement)){
if ((t.action instanceof Skip) || (t.action instanceof ClockReset) || (t.action instanceof Assignment)
|| (t.action instanceof OutputCommunication) || (t.action instanceof Call))
warning(
'Self-transition of state ' + t.source.name + ' does not have an exec. This may lead to a livelock.',
RoboChartPackage.Literals.TRANSITION__ACTION,
'selfTrasitionWithoutExec')

else{if ((t.action instanceof SeqStatement) || (t.action instanceof IfStatement) || (t.action instanceof ParStmt)){
val res = statementContainsExecStatement(t.action);
if (!res){
warning(
'Self transition of state ' + t.source.name + ' does not have an exec. This may lead to a livelock.',
RoboChartPackage.Literals.TRANSITION__ACTION,
'selfTrasitionWithoutExec')
}
}
}

}
}




def boolean statementContainsExecStatement(Statement s) {

var res = false;

if (s instanceof ExecStatement){
return true;

}
else if (s instanceof IfStmt){
res = statementContainsExecStatement(s.then);
if (res) return res
else
res = statementContainsExecStatement(s.^else);

}
else if (s instanceof SeqStatement) {
for (s2 : s.statements){
res = statementContainsExecStatement(s2);
if (res) return res
}
}
else if (s instanceof ParStmt){
res = statementContainsExecStatement(s.stmt);

}
return res;
}


}
Loading