Commit 6c19dc8f authored by Alfons Laarman's avatar Alfons Laarman

Optimize unless code

parent b81fb4a0
...@@ -155,10 +155,17 @@ public class Automaton implements Iterable<State> { ...@@ -155,10 +155,17 @@ public class Automaton implements Iterable<State> {
Transition n = t.duplicateFrom(s); Transition n = t.duplicateFrom(s);
n.setUnlessPriority(priority); n.setUnlessPriority(priority);
} }
s.nextUnless();
} }
escape.delete(); escape.delete();
} }
public void finalize() {
for (State s : this) {
s.finalize();
}
}
/** /**
* @return The number of states that are reachable from the current starting state. * @return The number of states that are reachable from the current starting state.
*/ */
......
...@@ -167,6 +167,8 @@ public class State { ...@@ -167,6 +167,8 @@ public class State {
} }
} }
boolean end, accept, progress;
/** /**
* Returns true when this state is an ending state. A {@link State} is an ending state when * Returns true when this state is an ending state. A {@link State} is an ending state when
* either it has one or more {@link EndTransition} or {@link NeverEndTransition} going out of * either it has one or more {@link EndTransition} or {@link NeverEndTransition} going out of
...@@ -174,12 +176,7 @@ public class State { ...@@ -174,12 +176,7 @@ public class State {
* @return true when this state is an ending state. * @return true when this state is an ending state.
*/ */
public boolean isEndingState() { public boolean isEndingState() {
for (Transition trans : out) { return end;
if (trans instanceof EndTransition ||
null == trans.getTo())
return true;
}
return hasLabelPrefix(LABEL_END);
} }
/** /**
...@@ -188,7 +185,7 @@ public class State { ...@@ -188,7 +185,7 @@ public class State {
* @return true when this state is and acceptance state. * @return true when this state is and acceptance state.
*/ */
public boolean isAcceptState() { public boolean isAcceptState() {
return hasLabelPrefix(LABEL_ACCEPT); return accept;
} }
/** /**
...@@ -197,9 +194,32 @@ public class State { ...@@ -197,9 +194,32 @@ public class State {
* @return true when this state is and progress state. * @return true when this state is and progress state.
*/ */
public boolean isProgressState() { public boolean isProgressState() {
return progress;
}
private boolean checkEndingState() {
for (Transition trans : out) {
if (trans instanceof EndTransition ||
null == trans.getTo())
return true;
}
return hasLabelPrefix(LABEL_END);
}
private boolean checkAcceptState() {
return hasLabelPrefix(LABEL_ACCEPT);
}
private boolean checkProgressState() {
return hasLabelPrefix(LABEL_PROGRESS); return hasLabelPrefix(LABEL_PROGRESS);
} }
public void finalize() {
end = checkEndingState();
progress = checkProgressState();
accept = checkAcceptState();
}
/** /**
* @param index * @param index
* The index of the output transition. * The index of the output transition.
...@@ -383,4 +403,8 @@ public class State { ...@@ -383,4 +403,8 @@ public class State {
public int nextUnless() { public int nextUnless() {
return unlesses++; return unlesses++;
} }
public int unlesses() {
return unlesses;
}
} }
...@@ -210,6 +210,10 @@ public class LTSminTreeWalker { ...@@ -210,6 +210,10 @@ public class LTSminTreeWalker {
instantiate(); instantiate();
bindByReferenceCalls(); bindByReferenceCalls();
for (ProcInstance p : spec) {
p.getAutomaton().finalize();
}
LTSminModel model = new LTSminModel(name, spec); LTSminModel model = new LTSminModel(name, spec);
createModelTransitions(model); createModelTransitions(model);
createModelAssertions(model); createModelAssertions(model);
...@@ -505,10 +509,9 @@ public class LTSminTreeWalker { ...@@ -505,10 +509,9 @@ public class LTSminTreeWalker {
instance.setEnabler(e); instance.setEnabler(e);
for (Variable var : p.getVariables()) { for (Variable var : p.getVariables()) {
Variable newvar = instantiate(var, instance); Variable newvar = instantiate(var, instance);
if (newvar.getName().equals(Promela.C_STATE_PROC_COUNTER))
newvar.setAssignedTo(); // Process counter is always assigned to
instance.addVariable(newvar, p.getArguments().contains(var)); instance.addVariable(newvar, p.getArguments().contains(var));
} }
instance.getPC().setAssignedTo();
instance.lastArgument(); instance.lastArgument();
HashMap<State, State> seen = new HashMap<State, State>(); HashMap<State, State> seen = new HashMap<State, State>();
instantiate(p.getStartState(), instance.getStartState(), seen, instance); instantiate(p.getStartState(), instance.getStartState(), seen, instance);
...@@ -986,9 +989,11 @@ public class LTSminTreeWalker { ...@@ -986,9 +989,11 @@ public class LTSminTreeWalker {
} }
}} }}
for (LTSminTransition lt : begin.getOut()) { if (state.unlesses() > 0) {
createUnlessGuards (lt); for (LTSminTransition lt : begin.getOut()) {
} createUnlessGuards (lt);
}
}
// update stack table // update stack table
removeSearchStack (begin); removeSearchStack (begin);
...@@ -1077,11 +1082,11 @@ public class LTSminTreeWalker { ...@@ -1077,11 +1082,11 @@ public class LTSminTreeWalker {
private List<LTSminTransition> createStateTransition(Transition t, private List<LTSminTransition> createStateTransition(Transition t,
Transition n) { Transition n) {
++debug.say_indent; ++debug.say_indent;
if(n!=null) { // if(n!=null) {
debug.say(MessageKind.DEBUG, "Handling trans: " + t.getClass().getName() + " || " + n.getClass().getName()); // debug.say(MessageKind.DEBUG, "Handling trans: " + t.getClass().getName() + " || " + n.getClass().getName());
} else { // } else {
debug.say(MessageKind.DEBUG, "Handling trans: " + t.getClass().getName()); // debug.say(MessageKind.DEBUG, "Handling trans: " + t.getClass().getName());
} // }
--debug.say_indent; --debug.say_indent;
LinkedList<LTSminTransition> list = new LinkedList<LTSminTransition>(); LinkedList<LTSminTransition> list = new LinkedList<LTSminTransition>();
...@@ -1162,7 +1167,7 @@ public class LTSminTreeWalker { ...@@ -1162,7 +1167,7 @@ public class LTSminTreeWalker {
continue; // skip dead transitions continue; // skip dead transitions
} }
list.add(lt); list.add(lt);
}} }}
return list; return list;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment