Range.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002     This file is part of PHP-AST Project by Romain Gaucher (http://rgaucher.info).
00003 
00004     PHP-AST is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     PHP-AST/ORACLE is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with PHP-AST.  If not, see <http://www.gnu.org/licenses/>.
00016 ------------------------------------------------------------------------------*/
00017 
00018 #ifndef __RANGE_H
00019 #define __RANGE_H
00020 
00021 #include "AbstractVisitor.h"
00022 #include <cmath>
00023 
00024 template<typename T>
00025 void swap(T& a, T &b) {
00026     T c(b);
00027     b=a;
00028     a=c;
00029 }
00030 
00031 
00032 template<typename T>
00033 struct Bound
00034 {
00035     T lower;
00036     T upper;
00037     Bound() {}
00038     Bound(const Bound& _r) : lower(_r.lower),upper(_r.upper) {
00039         if (lower > upper)
00040             swap<T>(lower,upper);
00041     }
00042     Bound& operator=(const Bound& _r) {
00043         lower = _r.lower;
00044         upper = _r.upper;
00045         if (lower > upper)
00046             swap<T>(lower,upper);
00047         return *this;
00048     }
00049 };
00050 
00051 template<typename T>
00052 bool operator==(const Bound<T>& b1, const Bound<T>& b2) {
00053     return b1.lower == b2.lower && b1.upper == b2.upper;
00054 }
00055 
00056 template<typename T>
00057 static bool is_in(const Bound<T>& b1, const Bound<T>& b2) {
00058     if (b1.lower >=b1.lower && b1.upper <= b2.upper)
00059         return true;
00060     return false;
00061 }
00062 
00063 static Bound<int> Empty;
00064 
00065 template<typename T>
00066 static bool overlap(const Bound<T>& min, const Bound<T>& max) {
00067     if (min.upper >= max.lower)
00068         return true;
00069     return false;
00070 }
00071 
00072 template<typename T>
00073 struct Range
00074 {
00075     Bound<T> min;
00076     Bound<T> max;
00077 
00078     Range() {}
00079     Range(const Range& _r) : min(_r.min),max(_r.max) {}
00080     Range& operator=(const Bound<T>& _r) {
00081         min = _r.min;
00082         max = _r.max;
00083         return *this;
00084     }
00085 };
00086 
00087 class RangeChecker : public AbstractVisitor
00088 {
00089   public:
00090     RangeChecker() {}
00091     virtual ~RangeChecker() {}
00092     virtual RangeChecker operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0,
00093                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00094 };
00095 
00096 #endif

Generated on Wed Feb 27 20:31:06 2008 for php.ast.svn.src. by  doxygen 1.5.3