
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@137 014f5005-505e-4b48-8d0a-63407b615a7c
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
||
# Relational
|
||
# Copyright (C) 2009 Salvo "LtWorf" Tomaselli
|
||
#
|
||
# Relation is free software: you can redistribute it and/or modify
|
||
# it under the terms of the GNU General Public License as published by
|
||
# the Free Software Foundation, either version 3 of the License, or
|
||
# (at your option) any later version.
|
||
#
|
||
# This program is distributed in the hope that it will be useful,
|
||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
# GNU General Public License for more details.
|
||
#
|
||
# You should have received a copy of the GNU General Public License
|
||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
#
|
||
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
||
|
||
'''This module contains functions to perform various optimizations on the expression trees.
|
||
The list general_optimizations contains pointers to general functions, so they can be called
|
||
within a cycle.'''
|
||
|
||
import optimizer
|
||
|
||
def duplicated_select(n):
|
||
'''This function locates and deletes things like
|
||
σ a ( σ a(C)) and the ones like σ a ( σ b(C))'''
|
||
if n.name=='σ' and n.child.name=='σ':
|
||
if n.prop != n.child.prop: #Nested but different, joining them
|
||
n.prop = n.prop + " and " + n.child.prop
|
||
n.child=n.child.child
|
||
duplicated_select(n)
|
||
|
||
#recoursive scan
|
||
if n.kind==optimizer.UNARY:
|
||
duplicated_select(n.child)
|
||
elif n.kind==optimizer.BINARY:
|
||
duplicated_select(n.right)
|
||
duplicated_select(n.left)
|
||
return n
|
||
|
||
general_optimizations=[duplicated_select] |