Mercurial > paraspace
comparison paraspace/dexfile.py @ 140:d4e794249b0f
Fixing back to back association and encoding issue
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 11 Aug 2011 09:20:46 +0800 |
parents | 987fead83ce3 |
children | 90690a001172 |
comparison
equal
deleted
inserted
replaced
139:0704e23009e4 | 140:d4e794249b0f |
---|---|
435 self.right_ref = right_ref | 435 self.right_ref = right_ref |
436 pass | 436 pass |
437 | 437 |
438 ## \brief Associate elements from left list to elements from right list | 438 ## \brief Associate elements from left list to elements from right list |
439 # | 439 # |
440 def build_associations(self, left, right): | 440 def build_associations(self, parent): |
441 from paraspace.dex_deptracker import _dex_tree_get_child | |
442 from paraspace.dex_deptracker import _dex_tree_set_child | |
443 from paraspace.dex_deptracker import _split_name_path_clazz_attr | |
444 | |
445 left_attr = _split_name_path_clazz_attr(self.left) | |
446 right_attr = _split_name_path_clazz_attr(self.right) | |
447 left = _dex_tree_get_child(parent, left_attr) | |
448 right = _dex_tree_get_child(parent, right_attr) | |
449 | |
441 assert len(left) == len(right) | 450 assert len(left) == len(right) |
442 for le, re in map(None, left, right): | 451 for le, re in map(None, left, right): |
443 self._update_refs(le, re) | 452 self._update_refs(le, re) |
453 pass | |
454 pass | |
455 pass | |
456 | |
457 | |
458 ## \brief Back to back association. | |
459 # | |
460 # For any two consequence elements in an array that applied this association, | |
461 # later element will depend on earlier one and/or in reversed. | |
462 # This type declares the association. | |
463 # | |
464 class back2back(_objs_asso): | |
465 def __init__(self, left, left_ref, right_ref): | |
466 if not isinstance(left, array): | |
467 raise TypeError, 'back_type must be an array' | |
468 self.left = left | |
469 self.right = left | |
470 self.left_ref = left_ref | |
471 self.right_ref = right_ref | |
472 pass | |
473 | |
474 def build_associations(self, parent): | |
475 from paraspace.dex_deptracker import _dex_tree_get_child | |
476 from paraspace.dex_deptracker import _dex_tree_set_child | |
477 from paraspace.dex_deptracker import _split_name_path_clazz_attr | |
478 | |
479 dummy, attr = _split_name_path_clazz_attr(self.left) | |
480 target_array = _dex_tree_get_child(parent, attr) | |
481 if not isinstance(target_array, array): | |
482 raise TypeError, 'left of %x must be an array' % (repr(self)) | |
483 | |
484 left_ref_attr = _split_name_path_clazz_attr(self.left_ref) | |
485 right_ref_attr = _split_name_path_clazz_attr(self.right_ref) | |
486 for left, right in map(None, target_array[:-1], target_array[1:]): | |
487 _dex_tree_set_child(left, left_ref_attr, right) | |
488 _dex_tree_set_child(right, right_ref_attr, left) | |
444 pass | 489 pass |
445 pass | 490 pass |
446 pass | 491 pass |
447 | 492 |
448 | 493 |
612 return ('items',) | 657 return ('items',) |
613 pass | 658 pass |
614 | 659 |
615 | 660 |
616 class array_sorted(array): | 661 class array_sorted(array): |
662 pass | |
663 | |
664 | |
665 class array_relative(array): | |
617 pass | 666 pass |
618 | 667 |
619 | 668 |
620 class composite(relocatable): | 669 class composite(relocatable): |
621 child_names = None | 670 child_names = None |
903 return self.back_type.sizeof(child) | 952 return self.back_type.sizeof(child) |
904 pass | 953 pass |
905 | 954 |
906 | 955 |
907 class depend_idx(depend): | 956 class depend_idx(depend): |
908 def sizeof(self, v): | |
909 from paraspace.dex_deptracker import _resolve_name_path | |
910 from paraspace.dex_deptracker import _skip_marker_clazz | |
911 | |
912 depon_clazz, dummy = _resolve_name_path(self.depend_on) | |
913 depon_clazz = _skip_marker_clazz(depon_clazz) | |
914 do_child_clazz = depon_clazz.child_type # depon_clazz must be an array | |
915 | |
916 if type(do_child_clazz) == type and \ | |
917 isinstance(v, do_child_clazz): | |
918 v = v.data_idx | |
919 elif type(do_child_clazz) != type and \ | |
920 isinstance(v, do_child_clazz.__class__): | |
921 v = v.data_idx | |
922 pass | |
923 v = self.back_type.sizeof(v) | |
924 return v | |
925 | |
926 def compute_size(self, child): | 957 def compute_size(self, child): |
927 pass | 958 pass |
928 | 959 |
929 def sizeof(self, child): | 960 def sizeof(self, child): |
930 if isinstance(child, composite): | 961 if isinstance(child, composite): |
931 return self.back_type.sizeof(child.data_idx) | 962 return self.back_type.sizeof(child.data_idx) |
932 return self.back_type.sizeof(child) | 963 return self.back_type.sizeof(child) |
964 pass | |
965 | |
966 | |
967 class depend_idx_rel(depend): | |
968 def __init__(self, relative_to, depend_on): | |
969 super(depend_idx_rel, self).__init__(depend_on) | |
970 self.relative_to = relative_to | |
971 pass | |
972 | |
973 def compute_size(self, child): | |
974 pass | |
975 | |
976 def sizeof(self, child): | |
977 from paraspace.dex_deptracker import _dex_tree_set_child | |
978 | |
979 relative = _dex_tree_get_child([child], self.relative_to) | |
980 | |
981 if isinstance(child, composite): | |
982 return self.back_type.sizeof(child.data_idx - relative.data_idx) | |
983 return self.back_type.sizeof(child - relative) | |
933 pass | 984 pass |
934 | 985 |
935 | 986 |
936 class _DEX_header(composite): | 987 class _DEX_header(composite): |
937 magic = rawstr(8) | 988 magic = rawstr(8) |
1188 pass | 1239 pass |
1189 | 1240 |
1190 | 1241 |
1191 class _DEX_ClassData(composite): | 1242 class _DEX_ClassData(composite): |
1192 header = _DEX_ClassDataHeader | 1243 header = _DEX_ClassDataHeader |
1193 staticFields = array('header.staticFieldsSize', _DEX_Field) | 1244 staticFields = array_relative('header.staticFieldsSize', _DEX_Field) |
1194 instanceFields = array('header.instanceFieldsSize', _DEX_Field) | 1245 instanceFields = array_relative('header.instanceFieldsSize', _DEX_Field) |
1195 directMethods = array('header.directMethodsSize', _DEX_Method) | 1246 directMethods = array_relative('header.directMethodsSize', _DEX_Method) |
1196 virtualMethods = array('header.virtualMethodsSize', _DEX_Method) | 1247 virtualMethods = array_relative('header.virtualMethodsSize', _DEX_Method) |
1197 | 1248 |
1198 child_names = \ | 1249 child_names = \ |
1199 'header ' \ | 1250 'header ' \ |
1200 'staticFields instanceFields directMethods virtualMethods'.split() | 1251 'staticFields instanceFields directMethods virtualMethods'.split() |
1201 pass | 1252 pass |