mirror of
https://gitlab.com/scemama/irpf90.git
synced 2025-01-03 01:55:42 +01:00
Rework needed_by
This commit is contained in:
parent
cb7838d068
commit
93b2aca745
@ -57,29 +57,89 @@ def main():
|
||||
if command_line.do_graph:
|
||||
# Create a dot reprenstion of the dependency graph.
|
||||
# Merge inside a subgraph the Entity provided together
|
||||
|
||||
comm_world.t_filename_parsed_text # Initialize entity need. Dirty I know.
|
||||
from util import mangled, l_dummy_entity
|
||||
|
||||
print 'digraph { '
|
||||
from util import l_dummy_entity, split_l_set
|
||||
#print len(comm_world.d_entity)
|
||||
#print sum(len(i.needs) for i in comm_world.d_entity.values())
|
||||
#print l_dummy_entity(comm_world.d_entity)
|
||||
#print len(l_dummy_entity(comm_world.d_entity))
|
||||
#print sum(len(i) for i in l_dummy_entity(comm_world.d_entity))
|
||||
|
||||
from util import mangled
|
||||
for name,entity in comm_world.d_entity.items():
|
||||
if entity.is_main:
|
||||
|
||||
if entity.needs:
|
||||
print ' %s -> { %s } ' % (name, ' ; '.join(entity.needs))
|
||||
if entity.others_entity_name:
|
||||
print ' subgraph cluster%s {' % name
|
||||
print ' %s ' % ' '.join([entity.name] + entity.others_entity_name)
|
||||
l_main_usr = set([entity for entity in comm_world.d_entity.values() if entity.is_main])
|
||||
l_main_head_usr = set([entity for entity in l_main_usr if entity.others_entity_name])
|
||||
l_main_atomic_usr = l_main_usr - l_main_head_usr
|
||||
|
||||
print 'digraph Full { '
|
||||
for e in comm_world.d_entity.values():
|
||||
if e.needs:
|
||||
print ' %s -> { %s } ' % (e.name, ' '.join(e.needs))
|
||||
|
||||
print '}'
|
||||
print ''
|
||||
|
||||
print 'digraph Small { '
|
||||
print ' graph [ordering="out"];'
|
||||
for e in l_main_head_usr:
|
||||
print ' subgraph cluster%s {' % e.name
|
||||
print ' %s ' % ' '.join([e.name] + e.others_entity_name)
|
||||
print ' }'
|
||||
|
||||
for i,s in enumerate(l_dummy_entity(comm_world.d_entity)):
|
||||
|
||||
|
||||
l_set_dummy_name= l_dummy_entity(comm_world.d_entity)
|
||||
for i,s in enumerate(l_set_dummy_name):
|
||||
print ' subgraph cluster%s {' % i
|
||||
print ' %s ' % ' '.join(s)
|
||||
print ' color = blue'
|
||||
print ' }'
|
||||
|
||||
|
||||
# We do exactly like the multi-provider.
|
||||
l_main_dummy_name, s_exculde_dummy_name = split_l_set(l_set_dummy_name)
|
||||
from util import flatten
|
||||
l_dummy_name = flatten(l_set_dummy_name)
|
||||
l_main_head_dummy = [comm_world.d_entity[name] for name in l_main_dummy_name]
|
||||
|
||||
|
||||
# Optimisation
|
||||
# 1) We merge the depency of multiple-provider. All entity into a multiple provider are the same.
|
||||
# 2) For the automatic one, we draw only the arrow for one parent.
|
||||
|
||||
for e in (e for e in l_main_atomic_usr if e.needs and e.name not in l_dummy_name):
|
||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
||||
if set(e.needs) != needs_filter:
|
||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
||||
for s in needs_filter:
|
||||
if s in l_dummy_name:
|
||||
print ' %s -> { %s } [color=blue, penwidth=2]' % (e.name, s)
|
||||
|
||||
else:
|
||||
print ' %s -> { %s }' % (e.name, s)
|
||||
else:
|
||||
print ' %s -> { %s }' % (e.name, ' ; '.join(e.needs))
|
||||
|
||||
for e in (e for e in l_main_head_usr if e.needs and e.name not in l_dummy_name):
|
||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
||||
if set(e.needs) != needs_filter:
|
||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
||||
for s in needs_filter:
|
||||
if s in l_dummy_name:
|
||||
print ' %s -> { %s } [color=blue, penwidth=2]' % (e.name, s)
|
||||
|
||||
else:
|
||||
print ' %s -> { %s } [penwidth=2]' % (e.name, s)
|
||||
else:
|
||||
print ' %s -> { %s } [penwidth=2]' % (e.name, ' ; '.join(e.needs))
|
||||
|
||||
for e in (e for e in l_main_head_dummy if e.needs):
|
||||
print ' %s -> { %s } [color=blue, penwidth=2]' % (e.name, ' ; '.join(e.needs))
|
||||
|
||||
print '}'
|
||||
|
||||
|
||||
return
|
||||
|
||||
|
||||
|
@ -507,16 +507,16 @@ def build_needs(parsed_text, subroutines, stuple, variables):
|
||||
# - Create the pointer copy
|
||||
# - Add the value (so it add also to the pointer reference...)
|
||||
|
||||
for v in variables:
|
||||
main = variables[v].same_as
|
||||
if main != v:
|
||||
variables[v].needed_by = variables[main].needed_by
|
||||
# for v in variables:
|
||||
# main = variables[v].same_as
|
||||
# if main != v:
|
||||
# variables[v].needed_by = variables[main].needed_by
|
||||
|
||||
for v in variables:
|
||||
var = variables[v]
|
||||
if var.is_main:
|
||||
# if var.is_main:
|
||||
for x in var.needs:
|
||||
variables[x].needed_by.append(var.same_as)
|
||||
variables[x].needed_by.append(var.name)
|
||||
|
||||
for var in variables.values():
|
||||
var.needed_by = uniquify(var.needed_by)
|
||||
|
20
src/util.py
20
src/util.py
@ -256,7 +256,7 @@ def OrderedUniqueList(l):
|
||||
return sorted(set(l))
|
||||
|
||||
def flatten(l_2d):
|
||||
# (List [ List[Any] ]) -> List
|
||||
# (List [ Iter[Any] ]) -> List
|
||||
'''Construct a copy of the 2d list collapsed into one dimension.
|
||||
|
||||
Note:
|
||||
@ -287,7 +287,7 @@ def build_dim(l_dim, colons=False):
|
||||
|
||||
def mangled(l_ent, d_ent):
|
||||
# (List, Dict[str,Entity]) -> list
|
||||
'''Create a uniq list of provider'''
|
||||
'''Create a uniq list of providier (merge the multione) '''
|
||||
return OrderedUniqueList(d_ent[name].same_as for name in l_ent)
|
||||
|
||||
def build_use(l_ent, d_ent):
|
||||
@ -323,11 +323,21 @@ def che_merge(sets):
|
||||
|
||||
|
||||
def l_dummy_entity(d_entity):
|
||||
# Dict[str:Entity] -> List[set]
|
||||
from itertools import combinations
|
||||
l_candidate_botom = [ (i,j) for i,j in combinations(d_entity.keys(),2) if d_entity[i].children == d_entity[j].children]
|
||||
l_dummy = [set([i,j]) for i,j in l_candidate_botom if d_entity[i].parents == d_entity[j].parents]
|
||||
l_candidate_botom = [ (i,j) for i,j in combinations(d_entity.keys(),2) if d_entity[i].needs == d_entity[j].needs]
|
||||
l_dummy = [set([i,j]) for i,j in l_candidate_botom if d_entity[i].needed_by == d_entity[j].needed_by]
|
||||
|
||||
return che_merge(l_dummy)
|
||||
l_merge = che_merge(l_dummy)
|
||||
return [l_set for l_set in l_merge if all(d_entity[e].is_main for e in l_set)]
|
||||
|
||||
def split_l_set(l_set_org):
|
||||
#(List[set] -> (List, Set)
|
||||
'''Split the list of set into a list of Head and and the concetenad of all the tail
|
||||
|
||||
|
||||
Note: Head and Tail a not defined in set. Head in one element of the set, and tail the rest.
|
||||
'''
|
||||
l_set = [set(s) for s in l_set_org]
|
||||
l_main = [ s.pop() for s in l_set]
|
||||
return l_main, set(flatten(l_set))
|
||||
|
Loading…
Reference in New Issue
Block a user