summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohit Agrawal2012-07-30 14:43:54 (EDT)
committerRohit Agrawal2012-07-30 14:43:54 (EDT)
commitbc0a551d74fea7de6ea091106889ff8c89d3c809 (patch)
treecec619d0aaf2a460aa5c8f500235d1385e897683
parent7861f1f3b2bfb68e33a625ad56331253c80e19c9 (diff)
downloadorg.eclipse.etrice-bc0a551d74fea7de6ea091106889ff8c89d3c809.zip
org.eclipse.etrice-bc0a551d74fea7de6ea091106889ff8c89d3c809.tar.gz
org.eclipse.etrice-bc0a551d74fea7de6ea091106889ff8c89d3c809.tar.bz2
[CQ6589] : Proposal Generator Class along with minor changes in otherrefs/changes/18/7018/1
classes 1. I authored 100% of the content I contributed 2. I have the rights to donate the content to Eclipse 3. I contribute the content under the EPL Change-Id: I0b75a205ecdf0af4b57baaa5f3449963fa96c89c
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java15
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java22
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java92
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ReachabilityCheck.java20
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java57
5 files changed, 152 insertions, 54 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 5a109bb..0ed4d50 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,6 +14,7 @@ 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;
@@ -23,6 +24,7 @@ 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.State;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.core.validation.IRoomValidator;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
@@ -71,8 +73,17 @@ public class AbstractExecutionValidator implements IRoomValidator {
System.out.println("Final printing of rules : ");
checker.printRules();
System.out.println("Rule checking for " + xpac.getActorClass().getName() + " is over");
-
- //TreeIterator<EObject> it = xpac.getStateMachine().eAllContents();
+ ProposalGenerator propGen = new ProposalGenerator(xpac,checker);
+ TreeIterator<EObject> it = xpac.getStateMachine().eAllContents();
+ while(it.hasNext())
+ {
+ EObject obj = it.next();
+ if(obj instanceof State)
+ {
+ State st = (State) obj;
+ propGen.getProposals(st);
+ }
+ }
}
}
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 17c3747..8b719d3 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
@@ -38,6 +38,17 @@ public class ActiveRules {
{
rules = r;
}
+ public Set<InterfaceItem> getPortList()
+ {
+ return rules.keySet();
+ }
+ public EList<SemanticsRule> getRulesForPort(InterfaceItem port)
+ {
+ if(rules.containsKey(port))
+ return rules.get(port);
+ else
+ return null;
+ }
//checks for currently active rules against a message list and modifies the
//rules which can be merged with the destination node
//also returns a boolean to determine if anything was changed so as to determine the
@@ -56,7 +67,6 @@ public class ActiveRules {
if(followUps.size()>0)
{
- // changed = true;
ruleChange.put(port, followUps);
}
}
@@ -67,24 +77,16 @@ public class ActiveRules {
{
if(!portList.contains(ports))
{
- //changed = true;
ruleChange.put(ports, this.rules.get(ports));
}
}
this.rules = ruleChange;
- //return changed;
}
//merges the rules with the destination active rules
public boolean merge(ActiveRules ar)
{
- /* for(InterfaceItem port : this.rules.keySet())
- {
- //this.rules.get(port).addAll(ar.rules.get(port));
-
- }
- */
- boolean added_at_least_one= false;
+ boolean added_at_least_one= false;
for(InterfaceItem port : ar.rules.keySet())
{
for(SemanticsRule rule : ar.rules.get(port))
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
new file mode 100644
index 0000000..9bde5b0
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
@@ -0,0 +1,92 @@
+package org.eclipse.etrice.abstractexec.behavior;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+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.InterfaceItem;
+import org.eclipse.etrice.core.room.MessageFromIf;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.SemanticsRule;
+import org.eclipse.etrice.core.room.State;
+
+public class ProposalGenerator {
+ private ExpandedActorClass xpac ;
+ private SemanticsCheck checker;
+ public ProposalGenerator(ExpandedActorClass xp , SemanticsCheck chk)
+ {
+ xpac = xp;
+ checker = chk;
+ }
+ public void getProposals(State st )
+ {
+ ActiveRules rules = checker.getActiveRules(st);
+ xpac.getActiveTriggers(st);
+ List<MessageFromIf> outgoingProposal = new LinkedList<MessageFromIf>();
+ List<MessageFromIf> incomingProposal = new LinkedList<MessageFromIf>();
+ Set<SemanticsRule> rulesToIgnore = new HashSet<SemanticsRule>();
+ for(ActiveTrigger trigger : xpac.getActiveTriggers(st))
+ {
+ MessageFromIf mifTrig = RoomFactory.eINSTANCE.createMessageFromIf();
+ mifTrig.setFrom(trigger.getIfitem());
+ mifTrig.setMessage(trigger.getMsg());
+ Port port = (Port) mifTrig.getFrom();
+ if(rules.getPortList().contains(port))
+ {
+ EList<SemanticsRule> ruleList = rules.getRulesForPort(port);
+ for(SemanticsRule curRules : ruleList)
+ {
+ if(curRules.getMsg()==mifTrig.getMessage())
+ {
+ //mark this rule for ignoring while generating proposals
+ //as they have already been taken care of
+ rulesToIgnore.add(curRules);
+ }
+ else
+ {
+ // issue a warning
+ rulesToIgnore.add(curRules);
+ }
+ }
+ }
+ }
+ // now start generating proposals by listing all the rules and ignoring the ones
+ //marked above
+ for(InterfaceItem item : rules.getPortList())
+ {
+ for(SemanticsRule ruleToCheck : rules.getRulesForPort(item))
+ {
+ if(!rulesToIgnore.contains(ruleToCheck))
+ {
+ MessageFromIf mif = RoomFactory.eINSTANCE.createMessageFromIf();
+ mif.setFrom(item);
+ mif.setMessage(ruleToCheck.getMsg());
+ if(((Port)item).isConjugated())
+ {
+ incomingProposal.add(mif);
+ }
+ else
+ {
+ outgoingProposal.add(mif);
+ }
+
+ }
+ }
+ }
+ System.out.println("Proposals for : " + st.getName());
+ for(MessageFromIf msg : outgoingProposal)
+ {
+ System.out.println("Outgoing msg proposal : " + msg.getMessage().getName());
+ }
+ for(MessageFromIf msg : incomingProposal)
+ {
+ System.out.println("Incoming msg proposal : " + msg.getMessage().getName());
+ }
+ }
+
+}
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 007a6b0..96eef05 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
@@ -13,18 +13,24 @@
package org.eclipse.etrice.abstractexec.behavior;
-import java.util.*;
-
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Set;
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.EntryPoint;
+import org.eclipse.etrice.core.room.InitialTransition;
+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;
-import org.eclipse.etrice.generator.base.DefaultTranslationProvider;
-import org.eclipse.etrice.generator.base.DetailCodeTranslator;
public class ReachabilityCheck {
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 a9fc40b..0e9c613 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
@@ -32,8 +32,8 @@ import org.eclipse.etrice.core.room.Transition;
import org.eclipse.etrice.core.room.util.RoomHelpers;
public class SemanticsCheck {
- Queue<StateGraphNode> queue;
- public Set<StateGraphNode> visited;
+ private Queue<StateGraphNode> queue;
+ private Set<StateGraphNode> visited;
private ExpandedActorClass xpAct;
private HashMap<StateGraphItem, ActiveRules> mapToRules = new HashMap<StateGraphItem, ActiveRules>();
private ActionCodeAnalyzer codeAnalyzer;
@@ -47,11 +47,8 @@ public class SemanticsCheck {
public void checkSemantics()
{
StateGraph graph = xpAct.getStateMachine();
- // buildLocalRules();
ActiveRules localRules = new ActiveRules();
localRules.buildInitLocalRules(xpAct);
- // System.out.println("Printing init rules : ");
- // localRules.print();
addStartingPoints(graph, localRules);
doTraversal();
}
@@ -59,7 +56,6 @@ public class SemanticsCheck {
private void addStartingPoints(StateGraph graph, ActiveRules localRules)
{
EList<Transition> transitions = graph.getTransitions();
- // EList<TrPoint> trPoint = graph.getTrPoints();
for(Transition trans : transitions)
if(trans instanceof InitialTransition)
{
@@ -73,7 +69,7 @@ public class SemanticsCheck {
boolean rulesChanged = false;
if(mapToRules.containsKey(cur))
{
- rulesChanged = mapToRules.get(cur).merge(localRules);
+ rulesChanged = mapToRules.get(cur).merge(localRules);
}
else {
mapToRules.put(cur,localRules);
@@ -83,16 +79,7 @@ public class SemanticsCheck {
break;
}
- //add transition points
- /*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());
- }
- } */
- }
+ }
private void doTraversal()
{
while(!queue.isEmpty())
@@ -105,9 +92,7 @@ public class SemanticsCheck {
visited.add(node);
if(node instanceof State)
{
- //List<MessageFromIf> completeList = new LinkedList<MessageFromIf>();
State st = (State) node;
- //mapToRules.get(st).checkRules(codeAnalyzer.analyze(st.getEntryCode()));
if(RoomHelpers.hasDirectSubStructure(st))
{
addStartingPoints(st.getSubgraph(), mapToRules.get(st));
@@ -124,8 +109,7 @@ public class SemanticsCheck {
StateGraphNode target = xpAct.getNode(trans.getTo());
List<MessageFromIf> msgList = new LinkedList<MessageFromIf>();
//create a list of codes here in the order
- // trigger, action , exit
- //entry code has already been added and merged
+ // trigger, exit, action, entry
msgList.add(mifTrig);
StateGraph triggerContext = (StateGraph) trans.eContainer();
State exitCalled = st;
@@ -157,22 +141,17 @@ 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);
- // }
for(Transition trans : xpAct.getOutgoingTransitions(node))
{
- ActiveRules tempRule = mapToRules.get(node).createCopy();
- List<MessageFromIf> msgList = codeAnalyzer.analyze(trans.getAction());
- StateGraphNode target = xpAct.getNode(trans.getTo());
- if(target instanceof State)
- {
- msgList.addAll(codeAnalyzer.analyze(((State) target).getEntryCode()));
- }
- tempRule.consumeMessages(msgList);
- addAndMergeRules(target, tempRule);
-
+ ActiveRules tempRule = mapToRules.get(node).createCopy();
+ List<MessageFromIf> msgList = codeAnalyzer.analyze(trans.getAction());
+ StateGraphNode target = xpAct.getNode(trans.getTo());
+ if(target instanceof State)
+ {
+ msgList.addAll(codeAnalyzer.analyze(((State) target).getEntryCode()));
+ }
+ tempRule.consumeMessages(msgList);
+ addAndMergeRules(target, tempRule);
}
}
}
@@ -202,4 +181,12 @@ public class SemanticsCheck {
mapToRules.get(item).print();
}
}
+ public ActiveRules getActiveRules(StateGraphItem item)
+ {
+ if(mapToRules.containsKey(item))
+ return mapToRules.get(item);
+ else
+ return null;
+ }
+
}