commit 5797acb03f0c663195c21f0def3cfadc10b58149
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Wed Jun 29 21:00:43 2011 -0400
Eliminate superfluous StateEdge class, adding 'src' field to Transition
libcpychecker/absinterp.py | 30 ++++++++++++------------------
libcpychecker/c_stdio.py | 4 ++--
libcpychecker/refcounts.py | 10 +++++-----
libcpychecker/visualizations.py | 10 +++++-----
4 files changed, 24 insertions(+), 30 deletions(-)
---
diff --git a/libcpychecker/absinterp.py b/libcpychecker/absinterp.py
index 065caf9..19e34ff 100644
--- a/libcpychecker/absinterp.py
+++ b/libcpychecker/absinterp.py
@@ -187,7 +187,7 @@ class State:
assert isinstance(lvalue, gcc.VarDecl) # for now
key = self.get_key_for_lvalue(lvalue)
new.data[key] = value
- return Transition(new, desc)
+ return Transition(self, new, desc)
def update_loc(self, newloc):
new = self.copy()
@@ -199,12 +199,15 @@ class State:
return self.update_loc(newloc)
class Transition:
- def __init__(self, nextstate, desc):
- self.nextstate = nextstate
+ def __init__(self, src, dest, desc):
+ assert isinstance(src, State)
+ assert isinstance(dest, State)
+ self.src = src
+ self.dest = dest
self.desc = desc
def __repr__(self):
- return 'Transition(%r, %r)' % (self.nextstate, self.desc)
+ return 'Transition(%r, %r)' % (self.dest, self.desc)
class Trace:
"""A sequence of State"""
@@ -321,7 +324,7 @@ def iter_traces(fun, stateclass, prefix=None):
result = []
for transition in transitions:
# Recurse:
- for trace in iter_traces(fun, stateclass, prefix.copy().add(transition.nextstate)):
+ for trace in iter_traces(fun, stateclass, prefix.copy().add(transition.dest)):
result.append(trace)
return result
else:
@@ -329,15 +332,6 @@ def iter_traces(fun, stateclass, prefix=None):
prefix.log(log, 'FINISHED TRACE', 1)
return [prefix]
-class StateEdge:
- def __init__(self, src, dest, transition):
- assert isinstance(src, State)
- assert isinstance(dest, State)
- assert isinstance(transition, Transition)
- self.src = src
- self.dest = dest
- self.transition = transition
-
class StateGraph:
"""
A graph of states, representing the various routes through a function,
@@ -350,7 +344,7 @@ class StateGraph:
assert isinstance(fun, gcc.Function)
self.fun = fun
self.states = []
- self.edges = []
+ self.transitions = []
self.stateclass = stateclass
logger('StateGraph.__init__(%r)' % fun)
@@ -384,11 +378,11 @@ class StateGraph:
for transition in transitions:
# FIXME: what about loops???
assert isinstance(transition, Transition)
- self.states.append(transition.nextstate)
- self.edges.append(StateEdge(curstate, transition.nextstate, transition))
+ self.states.append(transition.dest)
+ self.transitions.append(transition)
# Recurse:
- self._gather_states(transition.nextstate, curstate, logger)
+ self._gather_states(transition.dest, curstate, logger)
else:
# We're at a terminating state:
logger('FINISHED TRACE')
diff --git a/libcpychecker/c_stdio.py b/libcpychecker/c_stdio.py
index 8641b9e..bf4bd2a 100644
--- a/libcpychecker/c_stdio.py
+++ b/libcpychecker/c_stdio.py
@@ -53,7 +53,7 @@ def handle_c_stdio_function(state, fnname, stmt):
success = state.make_assignment(stmt.lhs,
file_ptr,
'%s() succeeded' % fnname)
- success.nextstate.acquire(file_ptr)
+ success.dest.acquire(file_ptr)
# The "failure" case:
failure = state.make_assignment(stmt.lhs,
@@ -75,7 +75,7 @@ def handle_c_stdio_function(state, fnname, stmt):
result = state.make_assignment(stmt.lhs,
AbstractValue(gcc.Type.int(), stmt),
'%s() succeeded' % fnname) # FIXME errno handling!
- result.nextstate.release(expr)
+ result.dest.release(expr)
return [result]
else:
# We claimed to handle this function, but didn't:
diff --git a/libcpychecker/refcounts.py b/libcpychecker/refcounts.py
index 7536669..9219714 100644
--- a/libcpychecker/refcounts.py
+++ b/libcpychecker/refcounts.py
@@ -80,7 +80,7 @@ class MyState(State):
assert isinstance(desc, str)
transition = State.make_assignment(self, key, value, desc)
if additional_ptr:
- transition.nextstate.owned_refs.append(additional_ptr)
+ transition.dest.owned_refs.append(additional_ptr)
return transition
def get_transitions(self, oldstate):
@@ -93,7 +93,7 @@ class MyState(State):
for loc in self.loc.next_locs():
newstate = self.copy()
newstate.loc = loc
- result.append(Transition(newstate, ''))
+ result.append(Transition(self, newstate, ''))
log('result: %s' % result)
return result
@@ -179,14 +179,14 @@ class MyState(State):
assert e
nextstate = self.update_loc(Location.get_block_start(e.dest))
nextstate.prior_bool = True
- return Transition(nextstate, 'taking True path')
+ return Transition(self, nextstate, 'taking True path')
def make_transition_for_false(stmt):
e = false_edge(self.loc.bb)
assert e
nextstate = self.update_loc(Location.get_block_start(e.dest))
nextstate.prior_bool = False
- return Transition(nextstate, 'taking False path')
+ return Transition(self, nextstate, 'taking False path')
log('stmt.exprcode: %s' % stmt.exprcode, 4)
log('stmt.exprtype: %s' % stmt.exprtype, 4)
@@ -250,7 +250,7 @@ class MyState(State):
if value in nextstate.owned_refs:
log('removing ownership of %s' % value)
nextstate.owned_refs.remove(value)
- return [Transition(nextstate, None)] # for now
+ return [Transition(self, nextstate, None)] # for now
def check_refcounts(fun, show_traces):
# Abstract interpretation:
diff --git a/libcpychecker/visualizations.py b/libcpychecker/visualizations.py
index 1659fae..64df793 100644
--- a/libcpychecker/visualizations.py
+++ b/libcpychecker/visualizations.py
@@ -111,14 +111,14 @@ class StateGraphPrettyPrinter(StatePrettyPrinter):
# self.block_id(state.loc.bb),
# state.loc.idx))
- for edge in self.sg.edges:
- if edge.transition.desc:
- attrliststr = '[label = "%s"]' % self.to_html(edge.transition.desc)
+ for transition in self.sg.transitions:
+ if transition.desc:
+ attrliststr = '[label = "%s"]' % self.to_html(transition.desc)
else:
attrliststr = ''
result += (' %s -> %s %s;\n'
- % (self.state_id(edge.src),
- self.state_id(edge.dest),
+ % (self.state_id(transition.src),
+ self.state_id(transition.dest),
attrliststr))
result += ' }\n';