diff paraspace/dexfile.py @ 43:5cea19126a11

Fix issue of _build_refs() - _build_refs() does not handle dexfile.cond well when traveling. - fix it - Move from ref.get_value() to ref.set_value().
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 19 Jun 2011 19:36:36 +0800
parents c5cfc796af8b
children 71218ba3bc8a
line wrap: on
line diff
--- a/paraspace/dexfile.py	Sun Jun 19 14:26:09 2011 +0800
+++ b/paraspace/dexfile.py	Sun Jun 19 19:36:36 2011 +0800
@@ -23,26 +23,6 @@
     pass
 
 
-## \brief Get attribute of an object for a given path.
-#
-def _dex_tree_get_child(obj, child_name):
-    child_parts = child_name.split('.')
-    for child_part in child_parts:
-        if isinstance(obj, list):
-            idx = int(child_part)
-            obj = obj[idx]
-            continue
-        
-        if isinstance(obj, dexfile.switch):
-            assert obj.map[eval(child_part)] == obj.child_type
-            obj = obj.value
-            continue
-        
-        obj = getattr(obj, child_part)
-        pass
-    return obj
-
-
 def _to_uint(data):
     v = 0
     sh = 0
@@ -441,7 +421,7 @@
     def to_str():
         return ''
 
-    def set_value(self, parents):
+    def get_value(self, parents):
         pass
     pass
 
@@ -449,15 +429,19 @@
 ## \brief Reference to a value from a given path.
 #
 class value_ref(ref):
-    def set_value(self, parents):
+    def get_value(self, parents):
+        from paraspace.dex_deptracker import _resolve_name_path
+        from paraspace.dex_deptracker import _dex_tree_get_child
+        
         pparts = self.target_path.split('.')
-        clazz = pparts[0]
+        clazz_name = pparts[0]
+        clazz, dummy = _resolve_name_path(clazz_name)
         
         rev_parents = list(parents)
         rev_parents.reverse()
         
         for parent in rev_parents:
-            if isinstance(rev_parents, clazz):
+            if isinstance(parent, clazz):
                break
             pass
         else:
@@ -465,8 +449,7 @@
 
         attr_path = '.'.join(pparts[1:])
         value = _dex_tree_get_child(parent, attr_path)
-        self.target = value
-        pass
+        return value
     pass
 
 
@@ -603,6 +586,7 @@
     condition = None
     child_type = None
     value = None
+    is_true = None
     
     def __init__(self, cond, child_type):
         self.condition = cond
@@ -612,13 +596,17 @@
     def parse(self, parent, data, off):
         if self.condition(parent, data, off):
             value = self.child_type.parse(parent, data, off)
+            is_true = True
         else:
             value = None
+            is_true = False
             pass
 
         obj = cond(self.condition, self.child_type)
         obj.value = value
         obj.data_size = self.sizeof(obj)
+        obj.is_true = is_true
+        
         return obj
 
     def sizeof(self, v):