Ejemplo n.º 1
0
 def wrap_terminal(self, o):
     v = self._expr2variable.get(o)
     if v is None:
         if o in self._duplications:
             v = Variable(o)
             self._expr2variable[o] = v
         else:
             v = o
     return v
Ejemplo n.º 2
0
    def reconstruct_variable(self, o):
        # Check variable cache to reuse previously transformed variable if possible
        e, l = o.operands()
        v = self._variable_cache.get(l)
        if v is not None:
            return v

        # Visit the expression our variable represents
        e2 = self.visit(e)

        # Always reconstruct Variable (with same label)
        v = Variable(e2, l)
        self._variable_cache[l] = v
        return v
Ejemplo n.º 3
0
    def expr(self, o, *ops):
        v = self._expr2variable.get(o)
        if v is None:
            oo = o
            # reconstruct if necessary
            if not ops == o.operands():
                o = o._uflclass(*ops)

            if (oo in self._duplications) or (o in self._duplications):
                v = Variable(o)
                self._expr2variable[o] = v
                self._expr2variable[oo] = v
            else:
                v = o
        return v
Ejemplo n.º 4
0
 def variable(self, o):
     e, l = o.operands()
     v = self._expr2variable.get(e)
     if v is None:
         e2 = self.visit(e)
         # Unwrap expression from the newly created Variable wrapper
         # unless the original expression was a Variable, in which
         # case we possibly need to keep the label for correctness.
         if (not isinstance(e, Variable)) and isinstance(e2, Variable):
             e2 = e2._expression
         v = self._expr2variable.get(e2)
         if v is None:
             v = Variable(e2, l)
             self._expr2variable[e] = v
             self._expr2variable[e2] = v
     return v
Ejemplo n.º 5
0
    def reuse_variable(self, o):
        # Check variable cache to reuse previously transformed variable if possible
        e, l = o.operands()
        v = self._variable_cache.get(l)
        if v is not None:
            return v

        # Visit the expression our variable represents
        e2 = self.visit(e)

        # If the expression is the same, reuse Variable object
        if e == e2:
            v = o
        else:
            # Recreate Variable (with same label)
            v = Variable(e2, l)

        # Cache variable
        self._variable_cache[l] = v
        return v