00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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