Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.abstractexec.behavior')
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java2
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java79
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java137
3 files changed, 90 insertions, 128 deletions
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
index 6c07feddb..5a109bbe3 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
@@ -14,7 +14,6 @@ package org.eclipse.etrice.abstractexec.behavior;
import java.util.List;
-import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.genmodel.base.NullDiagnostician;
import org.eclipse.etrice.core.genmodel.base.NullLogger;
@@ -24,7 +23,6 @@ import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.GeneralProtocolClass;
import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.StateGraphItem;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.core.validation.IRoomValidator;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
index 72366bc69..17c374752 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
@@ -14,13 +14,18 @@ package org.eclipse.etrice.abstractexec.behavior;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.room.*;
+import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
+import org.eclipse.etrice.core.room.GeneralProtocolClass;
+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.SemanticsRule;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
public class ActiveRules {
private HashMap<InterfaceItem, EList<SemanticsRule>> rules ;
@@ -29,7 +34,7 @@ public class ActiveRules {
{
rules= new HashMap<InterfaceItem, EList<SemanticsRule>>();
}
- public ActiveRules(HashMap<InterfaceItem,EList<SemanticsRule>> r)
+ private ActiveRules(HashMap<InterfaceItem,EList<SemanticsRule>> r)
{
rules = r;
}
@@ -37,15 +42,9 @@ public class ActiveRules {
//rules which can be merged with the destination node
//also returns a boolean to determine if anything was changed so as to determine the
//condition for adding to the queue
- public boolean checkRules(List<MessageFromIf> msgList )
+ public void consumeMessages(List<MessageFromIf> msgList )
{
- System.out.println("Entering checkRules");
- System.out.println("Msgs contained in list : ");
- for(MessageFromIf msg : msgList)
- {
- System.out.println("Msgs : " + msg.getMessage().getName());
- }
- boolean changed = false; //to determine if there was any change in rule
+ //boolean changed = false; //to determine if there was any change in rule
//keeps a record of the ports contained in the msgList
Set<InterfaceItem> portList = new HashSet<InterfaceItem>();
HashMap<InterfaceItem, EList<SemanticsRule>> ruleChange = new HashMap<InterfaceItem, EList<SemanticsRule>>();
@@ -57,15 +56,9 @@ public class ActiveRules {
if(followUps.size()>0)
{
- System.out.println("Founded follow up rules for msg : " + msg.getMessage().getName());
- changed = true;
+ // changed = true;
ruleChange.put(port, followUps);
}
- else
- {
- System.out.println("Didn't find any follow up for : " + msg.getMessage().getName());
- }
-
}
//check also if there is a port in the ActiveRules port set which doesn't send any message
//in the action code
@@ -74,24 +67,36 @@ public class ActiveRules {
{
if(!portList.contains(ports))
{
- changed = true;
+ //changed = true;
ruleChange.put(ports, this.rules.get(ports));
}
}
-
this.rules = ruleChange;
- System.out.println("Exiting checkRules");
- return changed;
-
+ //return changed;
}
//merges the rules with the destination active rules
- public void merge(ActiveRules ar)
+ public boolean merge(ActiveRules ar)
{
- for(InterfaceItem port : this.rules.keySet())
+ /* for(InterfaceItem port : this.rules.keySet())
{
- this.rules.get(port).addAll(ar.rules.get(port));
+ //this.rules.get(port).addAll(ar.rules.get(port));
+
}
+ */
+ boolean added_at_least_one= false;
+ for(InterfaceItem port : ar.rules.keySet())
+ {
+ for(SemanticsRule rule : ar.rules.get(port))
+ {
+ if(!this.rules.get(port).contains(rule))
+ {
+ this.rules.get(port).add(rule);
+ added_at_least_one = true;
+ }
+ }
+ }
+ return added_at_least_one;
}
public ActiveRules createCopy()
{
@@ -106,11 +111,8 @@ public class ActiveRules {
//advances the pointer to the follow up messages if a message is found matching the rule
private EList<SemanticsRule> getFollowingRules(MessageFromIf msg)
{
- System.out.println("Entering getFollowingRules");
-
EList<SemanticsRule> follow = new BasicEList<SemanticsRule>();
List<SemanticsRule> toRemove = new ArrayList<SemanticsRule>();
-
if(this.rules.containsKey(msg.getFrom()))
{
for(SemanticsRule rule : this.rules.get(msg.getFrom()))
@@ -135,15 +137,26 @@ public class ActiveRules {
}
//this basically just adds the advanced rules back to the ruleSet
this.rules.get(msg.getFrom()).addAll(follow);
- System.out.println("Exiting getFollowingRules");
return follow;
}
+ public void buildInitLocalRules(ExpandedActorClass xpAct)
+ {
+ //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();
+ this.rules.put(port, ((ProtocolClass) gpc).getSemantics().getRules());
+ }
+
+
+ }
public void print()
{
- for(InterfaceItem port : rules.keySet())
+ for(InterfaceItem port : this.rules.keySet())
{
- System.out.print("Port : " + port.getName() + " : rules : " );
- for(SemanticsRule rule : rules.get(port))
+ System.out.println("Port : " + port.getName() + " : rules : " );
+ for(SemanticsRule rule : this.rules.get(port))
{
System.out.println(rule.getMsg().getName());
}
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