mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-03-31 23:29:38 +00:00
Successfully break cycle.
This commit is contained in:
parent
50433ac860
commit
448849ac4b
@ -66,32 +66,32 @@ def process_input_files(filenames, options):
|
||||
fa.analyze_program(program)
|
||||
|
||||
if options.dump_fallthru_info:
|
||||
fallthru_map = dict(fa.fallthru_map)
|
||||
sys.stdout.write(json.dumps(fallthru_map, indent=4, sort_keys=True))
|
||||
sys.stdout.write("\n")
|
||||
|
||||
fa.find_ancestors()
|
||||
|
||||
if options.debug and options.dump_fallthru_info:
|
||||
sys.stdout.write("*** ancestors:\n")
|
||||
sys.stdout.write(json.dumps(fa.ancestor_map, indent=4, sort_keys=True))
|
||||
sys.stdout.write(json.dumps(fa.fallthru_map, indent=4, sort_keys=True))
|
||||
sys.stdout.write("\n")
|
||||
|
||||
fa.find_cycles()
|
||||
|
||||
if fa.cycles_found:
|
||||
while fa.cycles_found:
|
||||
if options.dump_fallthru_info:
|
||||
|
||||
if options.debug:
|
||||
sys.stdout.write("*** ancestors:\n")
|
||||
sys.stdout.write(json.dumps(fa.ancestor_map, indent=4, sort_keys=True))
|
||||
sys.stdout.write("\n")
|
||||
|
||||
sys.stdout.write("*** cycles found:\n")
|
||||
sys.stdout.write(json.dumps(sorted(fa.cycles_found), indent=4, sort_keys=True))
|
||||
sys.stdout.write("\n")
|
||||
|
||||
fa.break_cycles()
|
||||
fa.break_cycle()
|
||||
|
||||
if options.dump_fallthru_info and fallthru_map != fa.fallthru_map:
|
||||
sys.stdout.write("*** after breaking cycles:\n")
|
||||
if options.dump_fallthru_info:
|
||||
sys.stdout.write("*** after breaking cycle:\n")
|
||||
sys.stdout.write(json.dumps(fa.fallthru_map, indent=4, sort_keys=True))
|
||||
sys.stdout.write("\n")
|
||||
|
||||
fa.find_cycles()
|
||||
|
||||
if options.analyze_only:
|
||||
return
|
||||
|
||||
|
@ -24,25 +24,27 @@ class FallthruAnalyzer(object):
|
||||
self.fallthru_map = dict([(k, sorted(v)) for k, v in fallthru_map.iteritems()])
|
||||
return self.fallthru_map
|
||||
|
||||
def find_ancestors(self):
|
||||
def find_cycles(self):
|
||||
self.ancestor_map = {}
|
||||
for key in self.fallthru_map:
|
||||
ancestors = set()
|
||||
make_transitive_closure(self.fallthru_map, key, ancestors)
|
||||
self.ancestor_map[key] = sorted(ancestors)
|
||||
return self.ancestor_map
|
||||
|
||||
def find_cycles(self):
|
||||
self.cycles_found = set()
|
||||
for key in self.ancestor_map:
|
||||
if key in self.ancestor_map[key]:
|
||||
self.cycles_found.add(key)
|
||||
|
||||
return self.cycles_found
|
||||
|
||||
def break_cycles(self):
|
||||
def break_cycle(self):
|
||||
cycle_to_break = sorted(self.cycles_found)[0]
|
||||
cycles_to_break = set([cycle_to_break])
|
||||
|
||||
new_fallthru_map = {}
|
||||
for key in self.fallthru_map:
|
||||
values = set(self.fallthru_map[key]) - self.cycles_found
|
||||
values = set(self.fallthru_map[key]) - cycles_to_break
|
||||
if values:
|
||||
new_fallthru_map[key] = sorted(values)
|
||||
self.fallthru_map = new_fallthru_map
|
||||
|
@ -139,7 +139,7 @@ fall through to the other.
|
||||
= "bar",
|
||||
= "foo"
|
||||
= ]
|
||||
= *** after breaking cycles:
|
||||
= *** after breaking cycle:
|
||||
= {
|
||||
= "bar": [
|
||||
= "foo"
|
||||
|
Loading…
x
Reference in New Issue
Block a user