Mercurial > paraspace
changeset 18:f36b14d1f122
collect dependencies for classes in dexfile.py
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 01 Jun 2011 17:51:24 +0800 |
parents | d0806672da04 |
children | 6008b9a9d33e |
files | paraspace/dexfile.py |
diffstat | 1 files changed, 58 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/paraspace/dexfile.py Wed Jun 01 13:42:11 2011 +0800 +++ b/paraspace/dexfile.py Wed Jun 01 17:51:24 2011 +0800 @@ -1344,6 +1344,58 @@ pass +_nest_types = (array, cond, switch) + + +def _dig_clazz(clazz_name, clazz, population): + deps = {} + + for attr in dir(clazz): + namelist = [clazz_name, attr] + value_type = getattr(clazz, attr) + while isinstance(value_type, _nest_types) or \ + (type(value_type) == type and + issubclass(value_type, _nest_types)): + if isinstance(value_type, array): + namelist.append('items') + value_type = value_type.child_type + elif isinstance(value_type, cond): + namelist.append('value') + value_type = value_type.child_type + elif isinstance(value_type, switch): + namelist.append('value') + value_type = value_type.child_type + pass + pass + + if isinstance(value_type, depend): + from_name = '.'.join(namelist) + if isinstance(value_type, depend_off): + depend_name = value_type.depend_on + deps[from_name] = (depend_off, depend_name) + elif isinstance(value_type, depend_off_rel): + depend_name = value_type.depend_on + relative_to = value_type.relative_to + deps[from_name] = (depend_off_rel, depend_name, relative_to) + pass + pass + pass + return deps + +def collect_dependencies(): + population = dict([(name, value) + for name, value in globals().items() + if name.startswith('_DEX_')]) + + all_deps = {} + for clazz_name, clazz in population.items(): + deps = _dig_clazz(clazz_name, clazz, population) + all_deps.update(deps) + pass + + return all_deps + + if __name__ == '__main__': dex = DEXFile.open('../data/testdata1.dex') @@ -1412,4 +1464,10 @@ map.types[map.type], map.size, map.offset) + pass + + import pprint + print + print 'Dependencies' + pprint.pprint(collect_dependencies()) pass