Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java')
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java137
1 files changed, 44 insertions, 93 deletions
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java
index f749d360c..a9fc40bef 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java
@@ -18,123 +18,87 @@ import java.util.List;
import java.util.Queue;
import java.util.Set;
-import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.etrice.core.genmodel.etricegen.ActiveTrigger;
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
-import org.eclipse.etrice.core.room.EntryPoint;
-import org.eclipse.etrice.core.room.GeneralProtocolClass;
import org.eclipse.etrice.core.room.InitialTransition;
-import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.MessageFromIf;
-import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.SemanticsRule;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StateGraphItem;
import org.eclipse.etrice.core.room.StateGraphNode;
-import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.Transition;
-import org.eclipse.etrice.core.room.TransitionPoint;
import org.eclipse.etrice.core.room.util.RoomHelpers;
public class SemanticsCheck {
Queue<StateGraphNode> queue;
- public Set<StateGraphItem> visited;
+ public Set<StateGraphNode> visited;
private ExpandedActorClass xpAct;
- private Set<StateGraphItem> exitUsed;
private HashMap<StateGraphItem, ActiveRules> mapToRules = new HashMap<StateGraphItem, ActiveRules>();
private ActionCodeAnalyzer codeAnalyzer;
- private ActiveRules localRules;
public SemanticsCheck (ExpandedActorClass xpac) {
queue= new LinkedList<StateGraphNode>();
xpAct = xpac;
- visited = new HashSet<StateGraphItem>();
- exitUsed = new HashSet<StateGraphItem>();
+ visited = new HashSet<StateGraphNode>();
codeAnalyzer = new ActionCodeAnalyzer(xpac.getActorClass());
-
}
public void checkSemantics()
{
- System.out.println("Checking semantics");
StateGraph graph = xpAct.getStateMachine();
- buildLocalRules();
- addStartingPoints(graph, true, localRules);
+ // buildLocalRules();
+ ActiveRules localRules = new ActiveRules();
+ localRules.buildInitLocalRules(xpAct);
+ // System.out.println("Printing init rules : ");
+ // localRules.print();
+ addStartingPoints(graph, localRules);
doTraversal();
}
- private void buildLocalRules()
- {
- System.out.println("Buidling Local Rules");
- HashMap<InterfaceItem, EList<SemanticsRule>> locals = new HashMap<InterfaceItem, EList<SemanticsRule>>();
- List<InterfaceItem> portList = RoomHelpers.getAllInterfaceItems(xpAct.getActorClass());
- for(InterfaceItem port : portList)
- {
- GeneralProtocolClass gpc = port.getGeneralProtocol();
- locals.put(port, ((ProtocolClass) gpc).getSemantics().getRules());
- }
- localRules = new ActiveRules(locals);
- System.out.println("Exiting building local rules");
- }
- private void addStartingPoints(StateGraph graph, boolean add_initial, ActiveRules localRules)
+
+ private void addStartingPoints(StateGraph graph, ActiveRules localRules)
{
- System.out.println("Adding starting points");
EList<Transition> transitions = graph.getTransitions();
- EList<TrPoint> trPoint = graph.getTrPoints();
- if(add_initial)
+ // EList<TrPoint> trPoint = graph.getTrPoints();
for(Transition trans : transitions)
if(trans instanceof InitialTransition)
{
- visited.add(trans);
StateGraphNode cur = xpAct.getNode(trans.getTo());
List<MessageFromIf> msgList = codeAnalyzer.analyze(trans.getAction());
if(cur instanceof State)
{
msgList.addAll(codeAnalyzer.analyze(((State) cur).getEntryCode()));
}
-
- System.out.println("Analyzing code in init : " + trans.getName());
- boolean rulesChanged = localRules.checkRules(msgList);
- System.out.println("Rules changed for init : " + rulesChanged);
-
- if(!visited.contains(cur) || rulesChanged) queue.add(cur);
- if(mapToRules.containsKey(cur))
-
- {
- System.out.println("Added "+ cur.getName() + " in if of mapToRules");
- mapToRules.get(cur).merge(localRules);
- }
- else {
- // System.out.println("Added "+ cur.getName() + " in else of mapToRules and localRules added are as follows");
- // localRules.print();
- mapToRules.put(cur,localRules);
+ localRules.consumeMessages(msgList);
+ boolean rulesChanged = false;
+ if(mapToRules.containsKey(cur))
+ {
+ rulesChanged = mapToRules.get(cur).merge(localRules);
+ }
+ else {
+ mapToRules.put(cur,localRules);
+ rulesChanged = true;
}
+ if(!visited.contains(cur) || rulesChanged) queue.add(cur);
+
break;
}
//add transition points
- for(TrPoint tp : trPoint)
+ /*for(TrPoint tp : trPoint)
{
// CANT DETERMINE HOW TO MERGE RULES HERE
if(tp instanceof TransitionPoint && !visited.contains(tp) ) {
queue.add(tp);
mapToRules.put(tp, new ActiveRules());
}
- }
-
- System.out.println("Exiting Adding starting points");
+ } */
}
private void doTraversal()
{
- System.out.println("adding traversal");
while(!queue.isEmpty())
{
- System.out.println("Visiting : " + queue.peek().getName());
- //this.printRules();
Visit(queue.poll());
-
}
- System.out.println("Exiting traversal");
}
private void Visit(StateGraphNode node)
{
@@ -146,7 +110,7 @@ public class SemanticsCheck {
//mapToRules.get(st).checkRules(codeAnalyzer.analyze(st.getEntryCode()));
if(RoomHelpers.hasDirectSubStructure(st))
{
- addStartingPoints(st.getSubgraph(),true, mapToRules.get(st));
+ addStartingPoints(st.getSubgraph(), mapToRules.get(st));
}
else
{
@@ -157,7 +121,6 @@ public class SemanticsCheck {
mifTrig.setMessage(trigger.getMsg());
for(Transition trans : trigger.getTransitions())
{
- visited.add(trans);
StateGraphNode target = xpAct.getNode(trans.getTo());
List<MessageFromIf> msgList = new LinkedList<MessageFromIf>();
//create a list of codes here in the order
@@ -170,7 +133,6 @@ public class SemanticsCheck {
{
//this is where all the exit code is added
msgList.addAll(codeAnalyzer.analyze(exitCalled.getExitCode()));
- exitUsed.add(exitCalled);
if(exitCalled.eContainer()==triggerContext) break;
exitCalled = (State) exitCalled.eContainer().eContainer();
}
@@ -180,21 +142,14 @@ public class SemanticsCheck {
msgList.addAll(codeAnalyzer.analyze(((State) target).getEntryCode()));
}
ActiveRules tempRule = mapToRules.get(node).createCopy();
- //System.out.println("Cur rules before temp checking : ");
- // mapToRules.get(node).print();
- ActiveRules orig = mapToRules.get(node);
- boolean rulesChanged = tempRule.checkRules(msgList);
- // System.out.println("Copy rules after checking : ");
- // tempRule.print();
- // System.out.println("Orig rules after temp checking : ");
- // mapToRules.get(node).print();
- addAndMergeRules( target, rulesChanged, tempRule);
+ tempRule.consumeMessages(msgList);
+ addAndMergeRules( target, tempRule);
}
}
}
}
else {
- /* If the current node is an Entry/Exit/Transition pt ,
+ /* If the current node is an Entry/Exit/Transition/Choice pt ,
* then only the action code in the outgoing transition needs to be considered
* For this, a copy of the ActiveRules of the current node is created
* and is checked against each outgoing transition for Rule changes
@@ -202,10 +157,10 @@ public class SemanticsCheck {
* then the destination rules are merged with the current rules and destination
* node is added to the current queue.
*/
- if(node instanceof EntryPoint){
- State container = (State) node.eContainer().eContainer();
- visited.add(container);
- }
+ // if(node instanceof EntryPoint){
+ // State container = (State) node.eContainer().eContainer();
+ // visited.add(container);
+ // }
for(Transition trans : xpAct.getOutgoingTransitions(node))
{
ActiveRules tempRule = mapToRules.get(node).createCopy();
@@ -215,29 +170,25 @@ public class SemanticsCheck {
{
msgList.addAll(codeAnalyzer.analyze(((State) target).getEntryCode()));
}
- boolean rulesChanged = tempRule.checkRules(msgList);
- visited.add(trans);
-
- addAndMergeRules(target, rulesChanged, tempRule);
+ tempRule.consumeMessages(msgList);
+ addAndMergeRules(target, tempRule);
}
}
}
- private void addAndMergeRules(StateGraphNode target, boolean rulesChanged, ActiveRules tempRule)
+ private void addAndMergeRules(StateGraphNode target, ActiveRules tempRule)
{
- //System.out.println("Before merging : ");
- //mapToRules.get(source).print();
+ boolean rulesChanged = false;
+ if(mapToRules.containsKey(target))
+ {
+ rulesChanged = mapToRules.get(target).merge(tempRule);
+ }
+ else {
+ mapToRules.put(target,tempRule);
+ rulesChanged = true;
+ }
if(!visited.contains(target) || rulesChanged) {
queue.add(target);
- if(mapToRules.containsKey(target))
- {
- mapToRules.get(target).merge(tempRule);
- }
- else {
- mapToRules.put(target,tempRule);
- // System.out.println("adding in merge condition : ");
- // tempRule.print();
- }
}
}

Back to the top