relational/relational/optimizations.py
2009-04-29 07:25:39 +00:00

43 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- 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]