Skip to content
Snippets Groups Projects
Commit ce3274a74fba authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

refactor rewrite_shared_optional to be cleaner and avoid uncessary method call. Breaks cw compat

parent 1cf957d402bf
No related branches found
No related tags found
No related merge requests found
...@@ -465,50 +465,48 @@ ...@@ -465,50 +465,48 @@
"""if variable is shared across multiple scopes, need some tree """if variable is shared across multiple scopes, need some tree
rewriting rewriting
""" """
if var.scope is var.stmt: # allocate a new variable
# allocate a new variable newvar = var.stmt.make_variable()
newvar = var.stmt.make_variable() newvar.prepare_annotation()
newvar.prepare_annotation() for vref in var.references():
for vref in var.references(): if vref.scope is exists:
if vref.scope is exists: rel = vref.relation()
rel = vref.relation() vref.unregister_reference()
vref.unregister_reference() newvref = VariableRef(newvar)
newvref = VariableRef(newvar) vref.parent.replace(vref, newvref)
vref.parent.replace(vref, newvref) # update stinfo structure which may have already been
# update stinfo structure which may have already been # partially processed
# partially processed if rel in var.stinfo['rhsrelations']:
if rel in var.stinfo['rhsrelations']: lhs, rhs = rel.get_parts()
lhs, rhs = rel.get_parts() if vref is rhs.children[0] and \
if vref is rhs.children[0] and \ self.schema.rschema(rel.r_type).final:
self.schema.rschema(rel.r_type).final: update_attrvars(newvar, rel, lhs)
update_attrvars(newvar, rel, lhs) lhsvar = getattr(lhs, 'variable', None)
lhsvar = getattr(lhs, 'variable', None) var.stinfo['attrvars'].remove( (lhsvar, rel.r_type) )
var.stinfo['attrvars'].remove( (lhsvar, rel.r_type) ) if var.stinfo['attrvar'] is lhsvar:
if var.stinfo['attrvar'] is lhsvar: if var.stinfo['attrvars']:
if var.stinfo['attrvars']: var.stinfo['attrvar'] = iter(var.stinfo['attrvars']).next()
var.stinfo['attrvar'] = iter(var.stinfo['attrvars']).next() else:
else: var.stinfo['attrvar'] = None
var.stinfo['attrvar'] = None var.stinfo['rhsrelations'].remove(rel)
var.stinfo['rhsrelations'].remove(rel) newvar.stinfo['rhsrelations'].add(rel)
newvar.stinfo['rhsrelations'].add(rel) for stinfokey in ('blocsimplification','typerels', 'uidrels',
for stinfokey in ('blocsimplification','typerels', 'uidrels', 'relations', 'optrelations'):
'relations', 'optrelations'): try:
try: var.stinfo[stinfokey].remove(rel)
var.stinfo[stinfokey].remove(rel) newvar.stinfo[stinfokey].add(rel)
newvar.stinfo[stinfokey].add(rel) except KeyError:
except KeyError: continue
continue # shared references
# shared references newvar.stinfo['constnode'] = var.stinfo['constnode']
newvar.stinfo['constnode'] = var.stinfo['constnode'] if newvar.stmt.solutions: # solutions already computed
if newvar.stmt.solutions: # solutions already computed newvar.stinfo['possibletypes'] = var.stinfo['possibletypes']
newvar.stinfo['possibletypes'] = var.stinfo['possibletypes'] for sol in newvar.stmt.solutions:
for sol in newvar.stmt.solutions: sol[newvar.name] = sol[var.name]
sol[newvar.name] = sol[var.name] rel = exists.add_relation(var, 'identity', newvar)
rel = exists.add_relation(var, 'identity', newvar) # we have to force visit of the introduced relation
# we have to force visit of the introduced relation self.visit_relation(rel, exists, exists)
self.visit_relation(rel, exists, exists) return newvar
return newvar
return None
# tree nodes ############################################################## # tree nodes ##############################################################
...@@ -539,10 +537,8 @@ ...@@ -539,10 +537,8 @@
if not isinstance(exists, Exists): if not isinstance(exists, Exists):
exists = None exists = None
if lhsvar is not None: if lhsvar is not None:
if exists is not None: if exists is not None and lhsvar.scope is lhsvar.stmt:
newvar = self.rewrite_shared_optional(exists, lhsvar) lhsvar = self.rewrite_shared_optional(exists, lhsvar)
if newvar is not None:
lhsvar = newvar
lhsvar.stinfo['blocsimplification'].add(relation) lhsvar.stinfo['blocsimplification'].add(relation)
if relation.optional == 'both': if relation.optional == 'both':
lhsvar.stinfo['optrelations'].add(relation) lhsvar.stinfo['optrelations'].add(relation)
...@@ -550,10 +546,8 @@ ...@@ -550,10 +546,8 @@
lhsvar.stinfo['optrelations'].add(relation) lhsvar.stinfo['optrelations'].add(relation)
try: try:
rhsvar = rhs.children[0].variable rhsvar = rhs.children[0].variable
if exists is not None: if exists is not None and rhsvar.scope is rhsvar.stmt:
newvar = self.rewrite_shared_optional(exists, rhsvar) rhsvar = self.rewrite_shared_optional(exists, rhsvar)
if newvar is not None:
rhsvar = newvar
rhsvar.stinfo['blocsimplification'].add(relation) rhsvar.stinfo['blocsimplification'].add(relation)
if relation.optional == 'right': if relation.optional == 'right':
rhsvar.stinfo['optrelations'].add(relation) rhsvar.stinfo['optrelations'].add(relation)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment