enhance rewrite_shared_optional so one can specify where the new identity relation should be added (used by cw multi-sources planner) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 07 Jan 2011 14:54:19 +0100
branchstable
changeset 606 0672043cd73a
parent 604 f10d26835b70
child 607 ae02408da51e
enhance rewrite_shared_optional so one can specify where the new identity relation should be added (used by cw multi-sources planner)
nodes.py
stcheck.py
--- a/nodes.py	Wed Nov 03 16:43:34 2010 +0100
+++ b/nodes.py	Fri Jan 07 14:54:19 2011 +0100
@@ -440,7 +440,12 @@
             return False
         rhs = self.children[1]
         if isinstance(rhs, Comparison):
-            rhs = rhs.children[0]
+            try:
+                rhs = rhs.children[0]
+            except:
+                print 'opppp', rhs
+                print rhs.root
+                raise
         # else: relation used in SET OR DELETE selection
         return ((isinstance(rhs, Constant) and rhs.type == 'etype')
                 or (isinstance(rhs, Function) and rhs.name == 'IN'))
--- a/stcheck.py	Wed Nov 03 16:43:34 2010 +0100
+++ b/stcheck.py	Fri Jan 07 14:54:19 2011 +0100
@@ -27,7 +27,7 @@
 from rql._exceptions import BadRQLQuery
 from rql.utils import function_description
 from rql.nodes import (Relation, VariableRef, Constant, Not, Exists, Function,
-                       Variable, variable_refs)
+                       And, Variable, variable_refs, make_relation)
 from rql.stmts import Union
 
 
@@ -517,7 +517,7 @@
                 for vref in term.get_nodes(VariableRef):
                     bloc_simplification(vref.variable, term)
 
-    def rewrite_shared_optional(self, exists, var):
+    def rewrite_shared_optional(self, exists, var, identity_rel_scope=None):
         """if variable is shared across multiple scopes, need some tree
         rewriting
         """
@@ -574,9 +574,14 @@
             newvar.stinfo['possibletypes'] = var.stinfo['possibletypes']
             for sol in newvar.stmt.solutions:
                 sol[newvar.name] = sol[var.name]
-        rel = exists.add_relation(var, 'identity', newvar)
+        if identity_rel_scope is None:
+            rel = exists.add_relation(var, 'identity', newvar)
+            identity_rel_scope = exists
+        else:
+            rel = make_relation(var, 'identity', (newvar,), VariableRef)
+            exists.parent.replace(exists, And(exists, Exists(rel)))
         # we have to force visit of the introduced relation
-        self.visit_relation(rel, exists)
+        self.visit_relation(rel, identity_rel_scope)
         return newvar
 
     # tree nodes ##############################################################