Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-08-11 11:56:58 -0400
committerHenrik Rentz-Reichert2012-08-11 11:56:58 -0400
commite9cf09877525d980f13ccf8537281467e2ecbd81 (patch)
tree47b843d624dbded8fd32aafc82aea56adbaf2f40 /plugins/org.eclipse.etrice.abstractexec.behavior
parent7c4cf98eca44aaff0987a4f45b8b95bb2f002e37 (diff)
downloadorg.eclipse.etrice-e9cf09877525d980f13ccf8537281467e2ecbd81.tar.gz
org.eclipse.etrice-e9cf09877525d980f13ccf8537281467e2ecbd81.tar.xz
org.eclipse.etrice-e9cf09877525d980f13ccf8537281467e2ecbd81.zip
[modelcheck] code from Rohit with some changes
- formatted - bug fixes - improved tracing
Diffstat (limited to 'plugins/org.eclipse.etrice.abstractexec.behavior')
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/.options8
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java49
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java254
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java153
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java258
5 files changed, 351 insertions, 371 deletions
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/.options b/plugins/org.eclipse.etrice.abstractexec.behavior/.options
index 21d07f708..d2483c955 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/.options
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/.options
@@ -1,2 +1,8 @@
org.eclipse.etrice.abstractexec.behavior/debug=true
-org.eclipse.etrice.abstractexec.behavior/trace/proposals=true \ No newline at end of file
+org.eclipse.etrice.abstractexec.behavior/trace/proposals=true
+org.eclipse.etrice.abstractexec.behavior/trace/checks=true
+org.eclipse.etrice.abstractexec.behavior/trace/checks/level=1
+org.eclipse.etrice.abstractexec.behavior/trace/rules=true
+org.eclipse.etrice.abstractexec.behavior/trace/rules/level=2
+org.eclipse.etrice.abstractexec.behavior/trace/abstractexec=true
+org.eclipse.etrice.abstractexec.behavior/trace/abstractexec/name=AETest
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 d37edc387..d449d9a11 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.core.runtime.Platform;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.genmodel.base.NullDiagnostician;
@@ -35,6 +36,18 @@ import org.eclipse.xtext.validation.ValidationMessageAcceptor;
*/
public class AbstractExecutionValidator implements IRoomValidator {
+ private static boolean traceExec = false;
+ private static String traceName = "";
+ static {
+ if (Activator.getDefault().isDebugging()) {
+ String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/abstractexec");
+ if (value != null && value.equalsIgnoreCase(Boolean.toString(true))) {
+ traceExec = true;
+ }
+ traceName = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/abstractexec/name");
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.etrice.core.validation.IRoomValidator#validate(org.eclipse.emf.ecore.EObject, org.eclipse.xtext.validation.ValidationMessageAcceptor)
*/
@@ -45,24 +58,34 @@ public class AbstractExecutionValidator implements IRoomValidator {
return;
ActorClass ac = (ActorClass) object;
- System.out.println("Checking class " + ac.getName());
- boolean allProtocolsWithSemantics = true;
+
+ if (traceExec && !ac.getName().equals(traceName))
+ return;
+
+ if (traceExec)
+ System.out.println("AbstractExecutionValidator checking class " + ac.getName());
+
+ boolean oneProtocolsWithSemantics = false;
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());
+
+ if (traceExec)
+ System.out.println(" Checking protocolClass " + pc.getName() + " for semantics");
+
+ if (((ProtocolClass) pc).getSemantics() != null) {
+ oneProtocolsWithSemantics = true;
+ if (traceExec)
+ System.out.println(" Will execute because semantics defined for "+ pc.getName());
break;
}
}
- if (allProtocolsWithSemantics) {
+ if (oneProtocolsWithSemantics) {
// begin abstract execution on state machine of expanded actor class
- System.out.println("Reached where all ports have protocols");
+ System.out.println(" Reached where at least one interface items has semantics");
NullDiagnostician diagnostician = new NullDiagnostician();
GeneratorModelBuilder builder = new GeneratorModelBuilder(new NullLogger(), diagnostician);
ExpandedActorClass xpac = builder.createExpandedActorClass(ac);
@@ -70,9 +93,10 @@ public class AbstractExecutionValidator implements IRoomValidator {
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");
+// System.out.println("Final printing of rules : ");
+// checker.printRules();
+ if (traceExec)
+ System.out.println(" Rule checking for " + xpac.getActorClass().getName() + " is over");
TreeIterator<EObject> it = xpac.getStateMachine().eAllContents();
while(it.hasNext())
@@ -94,7 +118,8 @@ public class AbstractExecutionValidator implements IRoomValidator {
}
}
}
-
+ if (traceExec)
+ System.out.println("AbstractExecutionValidator done checking class " + ac.getName());
}
}
}
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 79be256a4..c12e67349 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
@@ -13,15 +13,14 @@ package org.eclipse.etrice.abstractexec.behavior;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
import org.eclipse.etrice.core.room.GeneralProtocolClass;
+import org.eclipse.etrice.core.room.InSemanticsRule;
import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.MessageFromIf;
import org.eclipse.etrice.core.room.ProtocolClass;
@@ -29,174 +28,137 @@ import org.eclipse.etrice.core.room.SemanticsRule;
import org.eclipse.etrice.core.room.util.RoomHelpers;
public class ActiveRules {
- private HashMap<InterfaceItem, EList<SemanticsRule>> rules ;
- private static boolean traceProposals = false;
- static
- {
- if (Activator.getDefault().isDebugging())
- {
- String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/proposals");
- if (value!=null && value.equalsIgnoreCase(Boolean.toString(true)))
- {
- traceProposals = true;
- }
- }
-}
- public ActiveRules()
- {
- rules= new HashMap<InterfaceItem, EList<SemanticsRule>>();
+ private HashMap<InterfaceItem, List<SemanticsRule>> rules;
+ private static boolean traceRules = false;
+ private static int traceLevel = 0;
+ static {
+ if (Activator.getDefault().isDebugging()) {
+ String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/rules");
+ if (value != null && value.equalsIgnoreCase(Boolean.toString(true))) {
+ traceRules = true;
+ }
+ value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/rules/level");
+ if (value != null) {
+ traceLevel = Integer.parseInt(value);
+ }
+ }
}
- private ActiveRules(HashMap<InterfaceItem,EList<SemanticsRule>> r)
- {
+
+ private static final int TRACE_RESULT = 1;
+ private static final int TRACE_DETAILS = 2;
+
+ public ActiveRules() {
+ rules = new HashMap<InterfaceItem, List<SemanticsRule>>();
+ }
+
+ private ActiveRules(HashMap<InterfaceItem, List<SemanticsRule>> r) {
rules = r;
}
- public Set<InterfaceItem> getPortList()
- {
+
+ public Set<InterfaceItem> getPortList() {
return rules.keySet();
}
- public EList<SemanticsRule> getRulesForPort(InterfaceItem port)
- {
+
+ public List<SemanticsRule> getRulesForPort(InterfaceItem port) {
return rules.get(port);
}
- //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 void consumeMessages(List<MessageFromIf> msgList )
- {
- //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)
- {
- ruleChange.put(port, followUps);
- }
- }
- //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))
- {
- ruleChange.put(ports, this.rules.get(ports));
+
+ // checks for currently active rules against a message list and modifies the
+ // rules which can be merged with the destination node
+ public void consumeMessages(List<MessageFromIf> msgList) {
+ for (MessageFromIf msg : msgList) {
+ List<SemanticsRule> localRules = rules.get(msg.getFrom());
+ if (localRules!=null) {
+ SemanticsRule match = null;
+ for (SemanticsRule rule : localRules) {
+ if (rule.getMsg() == msg.getMessage()) {
+ match = rule;
+ break;
+ }
+ }
+
+ if (match!=null) {
+ if (traceRules && traceLevel>=TRACE_DETAILS)
+ System.out.println(" found match for "+msg.getMessage().getName());
+
+ // discard all alternatives
+ localRules.clear();
+
+ // and add all follow ups
+ localRules.addAll(match.getFollowUps());
+ }
+ else {
+ // TODO: issue a warning?
+ }
}
}
- this.rules = ruleChange;
}
-
- //merges the rules with the destination active rules
- public boolean merge(ActiveRules ar)
- {
- boolean added_at_least_one= false;
- for(InterfaceItem port : ar.rules.keySet())
- {
- for(SemanticsRule rule : ar.rules.get(port))
- {
- if(this.rules.containsKey(port))
- {
- if(!this.rules.get(port).contains(rule))
- {
- this.rules.get(port).add(rule);
- added_at_least_one = true;
+
+ // merges the rules with the destination active rules
+ public boolean merge(ActiveRules ar) {
+ boolean added_at_least_one = false;
+ for (Entry<InterfaceItem, List<SemanticsRule>> entry : ar.rules.entrySet()) {
+ for (SemanticsRule rule : entry.getValue()) {
+ InterfaceItem ifitem = entry.getKey();
+ if (rules.containsKey(ifitem)) {
+ if (!rules.get(ifitem).contains(rule)) {
+ rules.get(ifitem).add(rule);
+ added_at_least_one = true;
}
}
- else
- {
- EList<SemanticsRule> tempList = new BasicEList<SemanticsRule>();
- tempList.add(rule);
- this.rules.put(port, tempList);
- added_at_least_one = true;
+ else {
+ List<SemanticsRule> tempList = new ArrayList<SemanticsRule>();
+ tempList.add(rule);
+ rules.put(ifitem, tempList);
+ added_at_least_one = true;
}
}
}
+
+ if (traceRules && traceLevel>=TRACE_DETAILS)
+ System.out.println(" merge changed rules");
+
return added_at_least_one;
}
- 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);
+
+ public ActiveRules createCopy() {
+ HashMap<InterfaceItem, List<SemanticsRule>> newRules = new HashMap<InterfaceItem, List<SemanticsRule>>();
+ for (InterfaceItem ifitem : rules.keySet()) {
+ newRules.put(ifitem, new ArrayList<SemanticsRule>(rules.get(ifitem)));
}
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)
- {
- 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);
- if(traceProposals)
- {
- System.out.println("Rule fulfilled by msg : " + msg.getMessage().getName());
- System.out.println("Rule being removed : " + rule.getMsg().getName());
- }
- }
- else
- {
- //add the rule for removing since it is violated by the current msg
- if(traceProposals)
- {
- System.out.println("Rule violated by msg : " + msg.getMessage().getName());
- System.out.println("Rule being removed : " + rule.getMsg().getName());
- }
- toRemove.add(rule);
- }
- }
+
+ public void buildInitLocalRules(ExpandedActorClass xpAct) {
+ // HashMap<InterfaceItem, EList<SemanticsRule>> locals = new
+ // HashMap<InterfaceItem, EList<SemanticsRule>>();
+ List<InterfaceItem> portList = RoomHelpers.getAllInterfaceItems(xpAct.getActorClass());
+ for (InterfaceItem ifitem : portList) {
+ GeneralProtocolClass gpc = ifitem.getGeneralProtocol();
+ if (gpc instanceof ProtocolClass && ((ProtocolClass) gpc).getSemantics()!=null)
+ rules.put(ifitem, ((ProtocolClass) gpc).getSemantics().getRules());
}
- //remove the discarded rules now
- for(SemanticsRule rule : toRemove)
- {
- if(rules.containsKey(msg.getFrom()))
- {
- this.rules.get(msg.getFrom()).remove(rule);
+
+ }
+
+ public void print() {
+ for (InterfaceItem port : rules.keySet()) {
+ System.out.println(" Rules for Port " + port.getName() + ":");
+ for (SemanticsRule rule : rules.get(port)) {
+ printRule(rule, " ");
}
}
- //this basically just adds the advanced rules back to the ruleSet
- if(rules.containsKey(msg.getFrom()))
- {
- this.rules.get(msg.getFrom()).addAll(follow);
- }
- 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 printRule(SemanticsRule rule, String indent) {
+ if (rule instanceof InSemanticsRule)
+ System.out.println(indent+"in: "+rule.getMsg().getName());
+ else
+ System.out.println(indent+"out: "+rule.getMsg().getName());
- }
- public void print()
- {
- for(InterfaceItem port : this.rules.keySet())
- {
- System.out.println("Port : " + port.getName() + " : rules : " );
- for(SemanticsRule rule : this.rules.get(port))
- {
- System.out.println(rule.getMsg().getName());
- }
+ // recursion
+ for (SemanticsRule sr : rule.getFollowUps()) {
+ printRule(sr, indent+" ");
}
}
}
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
index 207e56d60..1b25434d7 100644
--- 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
@@ -16,132 +16,117 @@ import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.Platform;
-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.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.util.RoomHelpers;
public class ProposalGenerator {
- private ExpandedActorClass xpac ;
+ private ExpandedActorClass xpac;
private SemanticsCheck checker;
- private List<MessageFromIf> outgoingProposal = new LinkedList<MessageFromIf>();
- private List<MessageFromIf> incomingProposal = new LinkedList<MessageFromIf>();
- private List<ActiveTrigger> warningTrigger = new LinkedList<ActiveTrigger>();
+ private List<MessageFromIf> outgoingProposal = new LinkedList<MessageFromIf>();
+ private List<MessageFromIf> incomingProposal = new LinkedList<MessageFromIf>();
+ //private List<ActiveTrigger> warningTrigger = new LinkedList<ActiveTrigger>();
private static boolean traceProposals = false;
- static
- {
- if (Activator.getDefault().isDebugging())
- {
- String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/proposals");
- if (value!=null && value.equalsIgnoreCase(Boolean.toString(true)))
- {
- traceProposals = true;
- }
- }
+ static {
+ if (Activator.getDefault().isDebugging()) {
+ String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/proposals");
+ if (value != null && value.equalsIgnoreCase(Boolean.toString(true))) {
+ traceProposals = true;
+ }
+ }
}
- public ProposalGenerator(ExpandedActorClass xp , SemanticsCheck chk)
- {
+
+ public ProposalGenerator(ExpandedActorClass xp, SemanticsCheck chk) {
xpac = xp;
checker = chk;
}
- public List<MessageFromIf> getIncomingProposals()
- {
+
+ public List<MessageFromIf> getIncomingProposals() {
return incomingProposal;
}
- public List<MessageFromIf> getOutgoingProposals()
- {
+
+ public List<MessageFromIf> getOutgoingProposals() {
return outgoingProposal;
}
- public List<ActiveTrigger> getWarningTriggers()
- {
- return warningTrigger;
- }
- public boolean getProposals(State st )
- {
- boolean issueWarning = false;
+
+// public List<ActiveTrigger> getWarningTriggers() {
+// return warningTrigger;
+// }
+
+ public boolean getProposals(State st) {
ActiveRules rules = checker.getActiveRules(st);
- //in case the state is disconnected component of the graph
- if(rules==null)
+
+ // in case the state is disconnected component of the graph
+ if (rules == null)
return false;
- xpac.getActiveTriggers(st);
+ boolean issueWarning = false;
+ outgoingProposal.clear();
+ incomingProposal.clear();
+
+ xpac.getActiveTriggers(st);
Set<SemanticsRule> rulesToIgnore = new HashSet<SemanticsRule>();
- for(ActiveTrigger trigger : xpac.getActiveTriggers(st))
- {
+ for (ActiveTrigger trigger : xpac.getActiveTriggers(st)) {
Port port = (Port) trigger.getIfitem();
- if(rules.getPortList().contains(port))
- {
- EList<SemanticsRule> ruleList = rules.getRulesForPort(port);
- for(SemanticsRule curRule : ruleList)
- {
- //mark this rule for ignoring while generating proposals
- //as they have already been taken care of
- if(curRule.getMsg()==trigger.getMsg())
- {
+ if (rules.getPortList().contains(port)) {
+ List<SemanticsRule> ruleList = rules.getRulesForPort(port);
+ for (SemanticsRule curRule : ruleList) {
+ // mark this rule for ignoring while generating proposals
+ // as they have already been taken care of
+ if (curRule.getMsg() == trigger.getMsg()) {
rulesToIgnore.add(curRule);
}
- else
- {
- // issue a warning
- if(traceProposals)
- {
- System.out.println("Violation of rules with trigger msg : " + trigger.getMsg().getName());
+ /*else {
+ // issue a warning
+ if (traceProposals) {
+ System.out.println("Violation of rules with trigger msg : "
+ + trigger.getMsg().getName());
}
- issueWarning= true;
+ issueWarning = true;
warningTrigger.add(trigger);
- }
+ }*/
}
}
}
- // 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))
- {
+
+ // 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());
- ProtocolClass pc = (ProtocolClass) ruleToCheck.getMsg().eContainer();
- if(pc.getIncomingMessages().contains(ruleToCheck.getMsg()))
- {
- if(((Port)item).isConjugated())
- outgoingProposal.add(mif);
- else
- incomingProposal.add(mif);
+ boolean isOutgoing = RoomHelpers.getMessageList(item, true).contains(ruleToCheck.getMsg());
+ if (isOutgoing) {
+ outgoingProposal.add(mif);
}
- else if (pc.getOutgoingMessages().contains(ruleToCheck.getMsg()))
- {
- if(((Port)item).isConjugated())
- incomingProposal.add(mif);
- else
- outgoingProposal.add(mif);
+ else {
+ incomingProposal.add(mif);
}
-
+
}
}
}
- if(traceProposals)
- {
- 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());
- }
+ if (traceProposals) {
+ System.out.println(" Proposals for : " + st.getName());
+
+ for (MessageFromIf msg : outgoingProposal) {
+ System.out.println(" Outgoing msg proposal : " + msg.getFrom().getName()+"."+msg.getMessage().getName()+"()");
+ }
+ for (MessageFromIf msg : incomingProposal) {
+ System.out.println(" Incoming msg proposal : " + msg.getMessage().getName() + " from " + msg.getFrom().getName());
+ }
}
+
return issueWarning;
}
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 7258a9d09..146c3245d 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
@@ -36,196 +36,198 @@ public class SemanticsCheck {
private Queue<StateGraphNode> queue;
private Set<StateGraphNode> visited;
private ExpandedActorClass xpAct;
- private HashMap<StateGraphItem, ActiveRules> mapToRules = new HashMap<StateGraphItem, ActiveRules>();
+ private HashMap<StateGraphItem, ActiveRules> mapToRules = new HashMap<StateGraphItem, ActiveRules>();
private ActionCodeAnalyzer codeAnalyzer;
- private static boolean traceProposals = false;
- static
- {
- if (Activator.getDefault().isDebugging())
- {
- String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/proposals");
- if (value!=null && value.equalsIgnoreCase(Boolean.toString(true)))
- {
- traceProposals = true;
- }
- }
-}
- public SemanticsCheck (ExpandedActorClass xpac) {
- queue= new LinkedList<StateGraphNode>();
+
+ private static boolean traceChecks = false;
+ private static int traceLevel = 0;
+ static {
+ if (Activator.getDefault().isDebugging()) {
+ String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/checks");
+ if (value != null && value.equalsIgnoreCase(Boolean.toString(true))) {
+ traceChecks = true;
+ }
+ value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/checks/level");
+ if (value != null) {
+ traceLevel = Integer.parseInt(value);
+ }
+ }
+ }
+
+ private static final int TRACE_RESULT = 1;
+ private static final int TRACE_DETAILS = 2;
+
+ public SemanticsCheck(ExpandedActorClass xpac) {
+ queue = new LinkedList<StateGraphNode>();
xpAct = xpac;
visited = new HashSet<StateGraphNode>();
codeAnalyzer = new ActionCodeAnalyzer(xpac.getActorClass());
}
- public void checkSemantics()
- {
- StateGraph graph = xpAct.getStateMachine();
+ public void checkSemantics() {
+ if (traceChecks)
+ System.out.println("checkSemantics: check of ActorClass "+xpAct.getActorClass().getName());
+
+ StateGraph graph = xpAct.getStateMachine();
ActiveRules localRules = new ActiveRules();
localRules.buildInitLocalRules(xpAct);
addStartingPoints(graph, localRules);
doTraversal();
+
+ if (traceChecks) {
+ if (traceLevel>=TRACE_RESULT)
+ printRules();
+
+ System.out.println("checkSemantics: done with check of ActorClass "+xpAct.getActorClass().getName());
+ }
}
-
- private void addStartingPoints(StateGraph graph, ActiveRules localRules)
- {
+
+ private void addStartingPoints(StateGraph graph, ActiveRules localRules) {
EList<Transition> transitions = graph.getTransitions();
- for(Transition trans : transitions)
- if(trans instanceof InitialTransition)
- {
+ for (Transition trans : transitions)
+ if (trans instanceof InitialTransition) {
StateGraphNode cur = xpAct.getNode(trans.getTo());
- List<MessageFromIf> msgList = codeAnalyzer.analyze(trans.getAction());
- if(cur instanceof State)
- {
- msgList.addAll(codeAnalyzer.analyze(((State) cur).getEntryCode()));
+ List<MessageFromIf> msgList = codeAnalyzer.analyze(trans
+ .getAction());
+ if (cur instanceof State) {
+ msgList.addAll(codeAnalyzer.analyze(((State) cur)
+ .getEntryCode()));
}
- localRules.consumeMessages(msgList);
+ 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);
-
+ 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;
}
- }
- private void doTraversal()
- {
- while(!queue.isEmpty())
- {
+ }
+
+ private void doTraversal() {
+ while (!queue.isEmpty()) {
Visit(queue.poll());
}
}
- private void Visit(StateGraphNode node)
- {
+
+ private void Visit(StateGraphNode node) {
visited.add(node);
- if(node instanceof State)
- {
+ if (node instanceof State) {
State st = (State) node;
- if(RoomHelpers.hasDirectSubStructure(st))
- {
+ if (RoomHelpers.hasDirectSubStructure(st)) {
addStartingPoints(st.getSubgraph(), mapToRules.get(st));
}
- else
- {
- for(ActiveTrigger trigger : xpAct.getActiveTriggers(st))
- {
- if(traceProposals)
- {
- System.out.println("Currently visiting : " + st.getName());
- System.out.println("Trigger : " + trigger.getMsg().getName());
+ else {
+ for (ActiveTrigger trigger : xpAct.getActiveTriggers(st)) {
+ if (traceChecks && traceLevel>=TRACE_DETAILS) {
+ System.out.println(" Currently visiting: " + st.getName());
+ System.out.println(" Trigger: " + trigger.getMsg().getName());
}
+
MessageFromIf mifTrig = RoomFactory.eINSTANCE.createMessageFromIf();
mifTrig.setFrom(trigger.getIfitem());
mifTrig.setMessage(trigger.getMsg());
- for(Transition trans : trigger.getTransitions())
- {
+ for (Transition trans : trigger.getTransitions()) {
StateGraphNode target = xpAct.getNode(trans.getTo());
List<MessageFromIf> msgList = new LinkedList<MessageFromIf>();
- //create a list of codes here in the order
- // trigger, exit, action, entry
+ // create a list of codes here in the order
+ // trigger, exit, action, entry
msgList.add(mifTrig);
StateGraph triggerContext = (StateGraph) trans.eContainer();
State exitCalled = st;
- while(true)
- {
- //this is where all the exit code is added
+ while (true) {
+ // this is where all the exit code is added
msgList.addAll(codeAnalyzer.analyze(exitCalled.getExitCode()));
- if(exitCalled.eContainer()==triggerContext) break;
+ if (exitCalled.eContainer() == triggerContext)
+ break;
exitCalled = (State) exitCalled.eContainer().eContainer();
}
msgList.addAll(codeAnalyzer.analyze(trans.getAction()));
- if(target instanceof State)
- {
+ if (target instanceof State) {
msgList.addAll(codeAnalyzer.analyze(((State) target).getEntryCode()));
}
ActiveRules tempRule = mapToRules.get(node).createCopy();
- if(traceProposals)
- {
- System.out.println("Messages in msglist before consuming: ");
- for(MessageFromIf msg : msgList)
- {
- System.out.println("Msg : " + msg.getMessage().getName());
+
+ if (traceChecks && traceLevel>=TRACE_DETAILS) {
+ System.out.println(" Messages in msglist before consuming: ");
+ for (MessageFromIf msg : msgList) {
+ System.out.println(" Msg: "+ msg.getMessage().getName());
}
}
- if(traceProposals)
- {
- System.out.println("rules before consuming message list : ");
+ if (traceChecks && traceLevel>=TRACE_DETAILS) {
+ System.out.println(" rules before consuming message list : ");
printRules();
}
tempRule.consumeMessages(msgList);
- if(traceProposals)
- System.out.println("Messages consumed");
- addAndMergeRules( target, tempRule);
- if(traceProposals)
- {
- System.out.println("rules after consuming and merging message list : ");
+
+ if (traceChecks && traceLevel>=TRACE_DETAILS)
+ System.out.println(" Messages consumed");
+
+ addAndMergeRules(target, tempRule);
+
+ if (traceChecks && traceLevel>=TRACE_DETAILS) {
+ System.out.println(" rules after consuming and merging message list : ");
printRules();
}
-
+
}
}
}
- }
- else {
- /* 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
- * 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.
- */
- for(Transition trans : xpAct.getOutgoingTransitions(node))
- {
+ } else {
+ /*
+ * 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 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.
+ */
+ for (Transition trans : xpAct.getOutgoingTransitions(node)) {
ActiveRules tempRule = mapToRules.get(node).createCopy();
- List<MessageFromIf> msgList = codeAnalyzer.analyze(trans.getAction());
+ List<MessageFromIf> msgList = codeAnalyzer.analyze(trans
+ .getAction());
StateGraphNode target = xpAct.getNode(trans.getTo());
- if(target instanceof State)
- {
- msgList.addAll(codeAnalyzer.analyze(((State) target).getEntryCode()));
- }
+ if (target instanceof State) {
+ msgList.addAll(codeAnalyzer.analyze(((State) target)
+ .getEntryCode()));
+ }
tempRule.consumeMessages(msgList);
- addAndMergeRules(target, tempRule);
+ addAndMergeRules(target, tempRule);
}
}
}
- private void addAndMergeRules(StateGraphNode target, ActiveRules tempRule)
- {
+
+ private void addAndMergeRules(StateGraphNode target, ActiveRules tempRule) {
boolean rulesChanged = false;
- if(mapToRules.containsKey(target))
- {
+ if (mapToRules.containsKey(target)) {
rulesChanged = mapToRules.get(target).merge(tempRule);
- }
- else {
- mapToRules.put(target,tempRule);
+ } else {
+ mapToRules.put(target, tempRule);
rulesChanged = true;
- }
- if(!visited.contains(target) || rulesChanged) {
+ }
+ if (!visited.contains(target) || rulesChanged) {
queue.add(target);
- }
-
+ }
+
}
- 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();
+
+ public void printRules() {
+ System.out.println(" Current Rules: ");
+ 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();
}
}
- public ActiveRules getActiveRules(StateGraphItem item)
- {
- if(mapToRules.containsKey(item))
- return mapToRules.get(item);
- else
- return null;
+
+ public ActiveRules getActiveRules(StateGraphItem item) {
+ return mapToRules.get(item);
}
-
+
}

Back to the top