Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2012-12-19 08:27:30 -0500
committerJuergen Haug2012-12-19 08:27:30 -0500
commit46ed5e424ec9adb3b915e421894970db0ac93046 (patch)
treeb090c557bf94c962f98642697f3e6a1ab89bec8b /plugins/org.eclipse.etrice.abstractexec.behavior
parent5ea296dc49f44f20c97bf396b9939f77d735f5e0 (diff)
downloadorg.eclipse.etrice-46ed5e424ec9adb3b915e421894970db0ac93046.tar.gz
org.eclipse.etrice-46ed5e424ec9adb3b915e421894970db0ac93046.tar.xz
org.eclipse.etrice-46ed5e424ec9adb3b915e421894970db0ac93046.zip
[abstractexec] added reachability tests
Diffstat (limited to 'plugins/org.eclipse.etrice.abstractexec.behavior')
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityCheck.java201
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityValidator.java3
2 files changed, 98 insertions, 106 deletions
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityCheck.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityCheck.java
index 4a1e4521e..4e282a50b 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityCheck.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityCheck.java
@@ -11,133 +11,124 @@
*
*******************************************************************************/
-
package org.eclipse.etrice.abstractexec.behavior;
import java.util.*;
-
import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.genmodel.etricegen.ActiveTrigger;
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
import org.eclipse.etrice.core.room.*;
import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.base.DefaultTranslationProvider;
-import org.eclipse.etrice.generator.base.DetailCodeTranslator;
-
public class ReachabilityCheck {
-Queue<StateGraphNode> queue;
-public Set<StateGraphItem> visited;
-private ExpandedActorClass xpAct;
-private Set<StateGraphItem> exitUsed;
-public ReachabilityCheck (ExpandedActorClass xpac) {
- queue= new LinkedList<StateGraphNode>();
- xpAct = xpac;
- visited = new HashSet<StateGraphItem>();
- exitUsed = new HashSet<StateGraphItem>();
-}
-public void computeReachability() {
- StateGraph graph = xpAct.getStateMachine();
- addStartingPoints(graph, true);
- doTraversal();
-}
+ Queue<StateGraphNode> queue;
+ public Set<StateGraphItem> visited;
+ private ExpandedActorClass xpAct;
+ private Set<StateGraphItem> exitUsed;
-private void addStartingPoints(StateGraph graph, boolean add_initial)
-{
-
- EList<Transition> transitions = graph.getTransitions();
- EList<TrPoint> trPoint = graph.getTrPoints();
- if(add_initial)
- for(Transition trans : transitions)
- if(trans instanceof InitialTransition)
- {
- visited.add(trans);
- StateGraphNode cur = xpAct.getNode(trans.getTo());
- if(!visited.contains(cur)) queue.add(cur);
- break;
- }
- for(TrPoint tp : trPoint)
- {
- if(tp instanceof TransitionPoint && !visited.contains(tp) ) {
- queue.add(tp);
- }
+ public ReachabilityCheck(ExpandedActorClass xpac) {
+ queue = new LinkedList<StateGraphNode>();
+ xpAct = xpac;
+ visited = new HashSet<StateGraphItem>();
+ exitUsed = new HashSet<StateGraphItem>();
}
-
- //add transition points
-}
-private void doTraversal() {
- while(!queue.isEmpty())
- {
- StateGraphNode node = queue.poll();
- Visit(node);
- //System.out.println("Visited node : " + node.getName());
+
+ public void computeReachability() {
+ StateGraph graph = xpAct.getStateMachine();
+ addStartingPoints(graph, true);
+ doTraversal();
}
-}
-public boolean isExitUsed(StateGraphItem item)
-{
- return exitUsed.contains(item);
-}
-public boolean isReachable(StateGraphItem item)
-{
-
- return visited.contains(item);
-}
-private void Visit(StateGraphNode node)
-{
- visited.add(node);
- if(node instanceof State)
- {
- State st = (State) node;
- if(RoomHelpers.hasDirectSubStructure(st))
- {
- addStartingPoints(st.getSubgraph(),true);
- }
- else
- {
- for(ActiveTrigger trigger : xpAct.getActiveTriggers(st))
- {
- for(Transition trans : trigger.getTransitions())
- {
+
+ private void addStartingPoints(StateGraph graph, boolean add_initial) {
+
+ EList<Transition> transitions = graph.getTransitions();
+ EList<TrPoint> trPoint = graph.getTrPoints();
+ if (add_initial)
+ for (Transition trans : transitions)
+ if (trans instanceof InitialTransition) {
visited.add(trans);
- StateGraphNode target = xpAct.getNode(trans.getTo());
- if(!visited.contains(target)) {
- queue.add(target);
- StateGraph triggerContext = (StateGraph) trans.eContainer();
- State exitCalled = st;
- while(true)
- {
- exitUsed.add(exitCalled);
- if(exitCalled.eContainer()==triggerContext) break;
- exitCalled = (State) exitCalled.eContainer().eContainer();
- }
- }
+ StateGraphNode cur = xpAct.getNode(trans.getTo());
+ if (!visited.contains(cur))
+ queue.add(cur);
+ break;
}
+ for (TrPoint tp : trPoint) {
+ if (tp instanceof TransitionPoint && !visited.contains(tp)) {
+ queue.add(tp);
}
}
+
+ // add transition points
}
- else {
- if(node instanceof EntryPoint)
- {
- State container = (State) node.eContainer().eContainer();
- visited.add(container);
+
+ private void doTraversal() {
+ while (!queue.isEmpty()) {
+ StateGraphNode node = queue.poll();
+ if (!visited.contains(node))
+ Visit(node);
+ // System.out.println("Visited node : " + node.getName());
}
- for(Transition trans : xpAct.getOutgoingTransitions(node))
- {
- visited.add(trans);
- StateGraphNode target = xpAct.getNode(trans.getTo());
- if(!visited.contains(target))
- {
- queue.add(target);
-
+ }
+
+ public boolean isExitUsed(StateGraphItem item) {
+ return exitUsed.contains(item);
+ }
+
+ public boolean isReachable(StateGraphItem item) {
+
+ return visited.contains(item);
+ }
+
+ private void Visit(StateGraphNode node) {
+ visited.add(node);
+ if (node instanceof State) {
+ State st = (State) node;
+ if (RoomHelpers.hasDirectSubStructure(st)) {
+ addStartingPoints(st.getSubgraph(), true);
+ } else {
+ for (ActiveTrigger trigger : xpAct.getActiveTriggers(st)) {
+ for (Transition trans : trigger.getTransitions()) {
+ visited.add(trans);
+ StateGraphNode target = xpAct.getNode(trans.getTo());
+ if (!visited.contains(target)) {
+ queue.add(target);
+ StateGraph triggerContext = (StateGraph) trans
+ .eContainer();
+ State exitCalled = st;
+ while (true) {
+ exitUsed.add(exitCalled);
+ if (exitCalled.eContainer() == triggerContext)
+ break;
+ exitCalled = (State) exitCalled.eContainer()
+ .eContainer();
+ }
+ }
+ }
+ }
+ }
+ } else {
+ if (node instanceof EntryPoint) {
+ // if container has no initial transition then mark it visited
+ boolean markVisited = true;
+ State container = (State) node.eContainer().eContainer();
+ StateGraph parentGraph = container.getSubgraph();
+ for (Transition tr : parentGraph.getTransitions())
+ if (tr instanceof InitialTransition)
+ markVisited = false;
+ if (markVisited)
+ visited.add(container);
+ }
+ for (Transition trans : xpAct.getOutgoingTransitions(node)) {
+ visited.add(trans);
+ StateGraphNode target = xpAct.getNode(trans.getTo());
+ if (!visited.contains(target)) {
+ queue.add(target);
+
+ }
}
}
- }
-
-}
+ }
}
-
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityValidator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityValidator.java
index 406ecf6d0..c4774b55c 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityValidator.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityValidator.java
@@ -29,6 +29,7 @@ import org.eclipse.xtext.validation.ValidationMessageAcceptor;
public class ReachabilityValidator implements IRoomValidator {
+ public static String DIAG_CODE_UNREACHABLE = "etrice.unreachable";
@Override
public void validate(EObject object, ValidationMessageAcceptor messageAcceptor) {
@@ -63,7 +64,7 @@ public class ReachabilityValidator implements IRoomValidator {
messageAcceptor.acceptWarning(
"Unreachable state/point of graph",
xpac.getOrig(toCheck).eContainer(), xpac.getOrig(toCheck).eContainingFeature(), idx,
- "UNREACHABLE", toCheck.getName());
+ DIAG_CODE_UNREACHABLE, toCheck.getName());
}
}
}

Back to the top