summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohit Agrawal2012-07-13 06:07:50 (EDT)
committer Rohit Agrawal2012-07-13 06:07:50 (EDT)
commitb95e20645b53171e593e6260a3925d6ea5d0922a (patch)
treea638d94c39f6959ab75ea44e1891d5b307a9864b
parentdd1a7841f5b8f5535387da259309fcddf760feb2 (diff)
downloadorg.eclipse.etrice-b95e20645b53171e593e6260a3925d6ea5d0922a.zip
org.eclipse.etrice-b95e20645b53171e593e6260a3925d6ea5d0922a.tar.gz
org.eclipse.etrice-b95e20645b53171e593e6260a3925d6ea5d0922a.tar.bz2
[CQ6589] Semantics Validator Classesrefs/changes/59/6759/1
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: I104be5270cc808d5a83ee2a44106072d4c6021e1
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java42
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java152
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java254
3 files changed, 419 insertions, 29 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 73c24b5..6c07fed 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
@@ -45,53 +45,37 @@ public class AbstractExecutionValidator implements IRoomValidator {
return;
ActorClass ac = (ActorClass) object;
-
+ System.out.println("Checking class " + ac.getName());
boolean allProtocolsWithSemantics = true;
List<InterfaceItem> ifItems = RoomHelpers.getAllInterfaceItems(ac);
for (InterfaceItem item : ifItems) {
GeneralProtocolClass pc = item.getGeneralProtocol();
if (!(pc instanceof ProtocolClass))
continue;
-
+ System.out.println("Checking protocolClass " + pc.getName() + " for semantics");
if (((ProtocolClass) pc).getSemantics() == null) {
allProtocolsWithSemantics = false;
+ System.out.println("Wont execute coz semantics missing for "+ pc.getName());
break;
}
}
if (allProtocolsWithSemantics) {
// begin abstract execution on state machine of expanded actor class
-
+ System.out.println("Reached where all ports have protocols");
NullDiagnostician diagnostician = new NullDiagnostician();
GeneratorModelBuilder builder = new GeneratorModelBuilder(new NullLogger(), diagnostician);
ExpandedActorClass xpac = builder.createExpandedActorClass(ac);
- if (xpac != null && !diagnostician.isFailed()) {
- // ActionCodeAnalyzer analyzer = new ActionCodeAnalyzer(ac);
-// ReachabilityCheck checker = new ReachabilityCheck(xpac);
-// checker.computeReachability();
-
- TreeIterator<EObject> it = xpac.getStateMachine().eAllContents();
- while (it.hasNext()) {
- EObject item = it.next();
- if (item instanceof StateGraphItem)
- {
- StateGraphItem toCheck = (StateGraphItem) item;
- if (false/*!checker.isReachable(toCheck)*/) {
- System.out.println("Unreachable "+ toCheck.getName());
-
- EObject orig = xpac.getOrig(toCheck);
- EObject container = orig.eContainer();
- @SuppressWarnings("unchecked")
- int idx = ((List<? extends EObject>)container.eGet(orig.eContainingFeature())).indexOf(orig);
-
- messageAcceptor.acceptWarning(
- "Unreachable state/point of graph",
- container, toCheck.eContainingFeature(), idx,
- "UNREACHABLE", toCheck.getName());
- }
- }
- }
+ if (xpac != null && !diagnostician.isFailed() ) {
+ SemanticsCheck checker = new SemanticsCheck(xpac);
+ checker.checkSemantics();
+ 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();
+
}
}
}
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
new file mode 100644
index 0000000..72366bc
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Rohit Agrawal (initial contribution)
+ *
+ *******************************************************************************/
+
+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.*;
+
+public class ActiveRules {
+ private HashMap<InterfaceItem, EList<SemanticsRule>> rules ;
+
+ public ActiveRules()
+ {
+ rules= new HashMap<InterfaceItem, EList<SemanticsRule>>();
+ }
+ public ActiveRules(HashMap<InterfaceItem,EList<SemanticsRule>> r)
+ {
+ rules = r;
+ }
+ //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
+ //condition for adding to the queue
+ public boolean checkRules(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
+ //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>>();
+ for(MessageFromIf msg : msgList)
+ {
+ InterfaceItem port = msg.getFrom();
+ portList.add(port);
+ EList<SemanticsRule> followUps = this.getFollowingRules(msg);
+
+ if(followUps.size()>0)
+ {
+ System.out.println("Founded follow up rules for msg : " + msg.getMessage().getName());
+ 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
+ //since the active rules of that port would need to be merged without change
+ for(InterfaceItem ports : this.rules.keySet())
+ {
+ if(!portList.contains(ports))
+ {
+ changed = true;
+ ruleChange.put(ports, this.rules.get(ports));
+ }
+ }
+
+ this.rules = ruleChange;
+ System.out.println("Exiting checkRules");
+ return changed;
+
+ }
+
+ //merges the rules with the destination active rules
+ public void merge(ActiveRules ar)
+ {
+ for(InterfaceItem port : this.rules.keySet())
+ {
+ this.rules.get(port).addAll(ar.rules.get(port));
+ }
+ }
+ public ActiveRules createCopy()
+ {
+ HashMap<InterfaceItem, EList<SemanticsRule>> newRules= new HashMap<InterfaceItem, EList<SemanticsRule>>();
+ for(InterfaceItem port : this.rules.keySet())
+ {
+ EList<SemanticsRule> list = new BasicEList<SemanticsRule>(this.rules.get(port));
+ newRules.put(port, list);
+ }
+ return new ActiveRules(newRules);
+ }
+ //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()))
+ {
+ if(rule.getMsg()== msg.getMessage())
+ {
+ follow.addAll(rule.getFollowUps());
+ //added for removal so it can be replaced the followUp rules
+ toRemove.add(rule);
+ }
+ else
+ {
+ //add the rule for removing since it is violated by the current msg
+ toRemove.add(rule);
+ }
+ }
+ }
+ //remove the discarded rules now
+ for(SemanticsRule rule : toRemove)
+ {
+ this.rules.get(msg.getFrom()).remove(rule);
+ }
+ //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 print()
+ {
+ for(InterfaceItem port : rules.keySet())
+ {
+ System.out.print("Port : " + port.getName() + " : rules : " );
+ for(SemanticsRule rule : 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
new file mode 100644
index 0000000..f749d36
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java
@@ -0,0 +1,254 @@
+/*******************************************************************************
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Rohit Agrawal (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.abstractexec.behavior;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+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;
+ 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>();
+ codeAnalyzer = new ActionCodeAnalyzer(xpac.getActorClass());
+
+ }
+
+ public void checkSemantics()
+ {
+ System.out.println("Checking semantics");
+ StateGraph graph = xpAct.getStateMachine();
+ buildLocalRules();
+ addStartingPoints(graph, true, 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)
+ {
+ System.out.println("Adding starting points");
+ 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());
+ 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);
+ }
+ 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());
+ }
+ }
+
+ 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)
+ {
+ 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(),true, mapToRules.get(st));
+ }
+ else
+ {
+ for(ActiveTrigger trigger : xpAct.getActiveTriggers(st))
+ {
+ MessageFromIf mifTrig = RoomFactory.eINSTANCE.createMessageFromIf();
+ mifTrig.setFrom(trigger.getIfitem());
+ 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
+ // trigger, action , exit
+ //entry code has already been added and merged
+ msgList.add(mifTrig);
+ StateGraph triggerContext = (StateGraph) trans.eContainer();
+ State exitCalled = st;
+ while(true)
+ {
+ //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();
+ }
+ msgList.addAll(codeAnalyzer.analyze(trans.getAction()));
+ if(target instanceof State)
+ {
+ 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);
+ }
+ }
+ }
+ }
+ else {
+ /* If the current node is an Entry/Exit/Transition 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
+ * If there is any rule change or if the destination state hasn't been visited
+ * 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()));
+ }
+ boolean rulesChanged = tempRule.checkRules(msgList);
+ visited.add(trans);
+
+ addAndMergeRules(target, rulesChanged, tempRule);
+
+ }
+ }
+ }
+ private void addAndMergeRules(StateGraphNode target, boolean rulesChanged, ActiveRules tempRule)
+ {
+ //System.out.println("Before merging : ");
+ //mapToRules.get(source).print();
+ 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();
+ }
+ }
+
+ }
+ public void printRules()
+ {
+ System.out.println("Rules So Far : ");
+ System.out.println("MapToRules size : " + this.mapToRules.size());
+ for(StateGraphItem item : this.mapToRules.keySet())
+ {
+ System.out.println("Rules for : " + item.getName() + " : " );
+ mapToRules.get(item).print();
+ }
+ }
+}