changeset 93:2fa9b6f21344

Add DEXFile_linked to model linked DEX
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 25 Jul 2011 13:23:02 +0800
parents 1728795c29b7
children 88645ab29aeb
files paraspace/dexfile.py paraspace/tests/injection_test.py
diffstat 2 files changed, 39 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dexfile.py	Mon Jul 25 10:01:14 2011 +0800
+++ b/paraspace/dexfile.py	Mon Jul 25 13:23:02 2011 +0800
@@ -1658,6 +1658,36 @@
     pass
 
 
+## \brief A linked version of a DEXFile.
+#
+# Instances of this class was built from instances of DEXFile.
+# Dependencies are linked to depend-on objects; the target of a
+# dependence.
+#
+class DEXFile_linked(DEXFile):
+    def _copy_attributes(self, dex):
+        super(DEXFile_linked, self).__init__()
+        for attr, value in dex.__dict__.items():
+            setattr(self, attr, value)
+            pass
+        pass
+
+    ## \brief Factory function to return a DEXFile_linked of given DEXFile.
+    @staticmethod
+    def build_dependencies(dex, dep_decls):
+        from paraspace.dex_deptracker import build_dependencies
+
+        if not isinstance(dex, DEXFile):
+            raise TypeError, 'first argument must be an instance of DEXFile'
+        
+        linked = DEXFile_linked()
+        build_dependencies(dex, dep_decls)
+        linked._copy_attributes(dex)
+        
+        return linked
+    pass
+
+
 if __name__ == '__main__':
     import sys
     
--- a/paraspace/tests/injection_test.py	Mon Jul 25 10:01:14 2011 +0800
+++ b/paraspace/tests/injection_test.py	Mon Jul 25 13:23:02 2011 +0800
@@ -3,7 +3,7 @@
 
 def _install_dexfile_4_deptracker():
     global dexfile
-    import imp
+    import imp, sys
     from paraspace import dex_deptracker
     
     try:
@@ -14,6 +14,8 @@
     dex_deptracker.dexfile = new_dexfile
     dexfile = new_dexfile
     dex_deptracker._nest_types = (dexfile.array, dexfile.cond, dexfile.switch)
+    
+    sys.modules['paraspace.dexfile'] = new_dexfile
     pass
 
 
@@ -30,10 +32,14 @@
     
     helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex')
     helloworld_dex = dexfile.DEXFile.open(helloworld_fn)
-    build_dependencies(helloworld_dex, all_dep_decls)
+    helloworld_linked = \
+        dexfile.DEXFile_linked.build_dependencies(helloworld_dex,
+                                                  all_dep_decls)
 
     fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex')
     fakefile_dex = dexfile.DEXFile.open(fakefile_fn)
-    build_dependencies(fakefile_dex, all_dep_decls)
+    fakefile_linked = \
+        dexfile.DEXFile_linked.build_dependencies(fakefile_dex,
+                                                  all_dep_decls)
     pass