Commits

Ronan Lamy committed aacb3f4

Add SpaceOperation.replace()

Comments (0)

Files changed (3)

rpython/flowspace/model.py

         return "%r = %s(%s)" % (self.result, self.opname,
                                 ", ".join(map(repr, self.args)))
 
+    def replace(self, mapping):
+        newargs = [mapping.get(arg, arg) for arg in self.args]
+        newresult = mapping.get(self.result, self.result)
+        return type(self)(self.opname, newargs, newresult, self.offset)
+
 class Atom(object):
     def __init__(self, name):
         self.__name__ = name # make save_global happy

rpython/flowspace/operation.py

         self.result = Variable()
         self.offset = -1
 
+    def replace(self, mapping):
+        newargs = [mapping.get(arg, arg) for arg in self.args]
+        newresult = mapping.get(self.result, self.result)
+        newop = type(self)(*newargs)
+        newop.result = newresult
+        newop.offset = self.offset
+        return newop
+
     @classmethod
     def make_sc(cls):
         def sc_operator(space, *args_w):

rpython/translator/simplify.py

             def rename(v):
                 return renaming.get(v, v)
             def rename_op(op):
-                args = [rename(a) for a in op.args]
-                op = SpaceOperation(op.opname, args, rename(op.result), op.offset)
+                op = op.replace(renaming)
                 # special case...
                 if op.opname == 'indirect_call':
                     if isinstance(op.args[0], Constant):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.