Polaris: SharedBounds.cc Source File

SharedBounds.cc

Go to the documentation of this file.
00001 /// \file SharedBounds.cc
00002 ///
00003 #ifdef POLARIS_GNU_PRAGMAS
00004 #pragma implementation
00005 #endif
00006 ///
00007 #include <string.h>
00008 
00009 #include "SharedBounds.h"
00010 #include "BinRep.h"
00011 #include "Collection/Iterator.h"
00012 #include "Collection/List.h"
00013 #include "Expression/Expression.h"
00014 #include "ExprTable.h"
00015 
00016 template class TypedCollection<SharedBounds>;
00017 template class List<SharedBounds>;
00018 template ostream & operator << (ostream &, const List<SharedBounds> &);
00019 template class Assign<SharedBounds>;
00020 
00021 template class Iterator<SharedBounds>;
00022 
00023 SharedBounds::SharedBounds(const BinRep & binstr, ExprTable & exprs)
00024 {
00025     #ifdef CLASS_INSTANCE_REGISTRY
00026     register_instance(SHARED_BOUNDS, sizeof(SharedBounds), this);
00027     #endif
00028 
00029     _expr_list.make_static_list(2);
00030 
00031     for (Iterator<BinRep> iter = binstr.to_set(); iter.valid(); ++iter) {
00032         String          field;
00033 
00034         iter.current()[0].to_string(field);
00035 
00036         if (field == "lb") {
00037             int index = iter.current()[1].to_integer();
00038 
00039             _expr_list.modify(LOWER_SHARED_BOUND, exprs[index]);
00040         }
00041         else if (field == "ub") {
00042             int index = iter.current()[1].to_integer();
00043 
00044             _expr_list.modify(UPPER_SHARED_BOUND, exprs[index]);
00045         }
00046         else {
00047             cerr << "Error: SharedBounds: Unanticipated format: "
00048                  << binstr << "\n";
00049         }
00050     }
00051 }
00052 
00053 SharedBounds::SharedBounds(Expression * lower, Expression * upper)
00054 {
00055     #ifdef CLASS_INSTANCE_REGISTRY
00056     register_instance(SHARED_BOUNDS, sizeof(SharedBounds), this);
00057     #endif
00058 
00059     _expr_list.make_static_list(2);
00060 
00061     _expr_list.modify(LOWER_SHARED_BOUND, lower);
00062     _expr_list.modify(UPPER_SHARED_BOUND, upper);
00063 }
00064 
00065 void 
00066 SharedBounds::print(ostream & o) const
00067 {
00068     if (!lower_exists() && upper_exists()) 
00069         o << upper_guarded();
00070     else if (!lower_exists() && !upper_exists()) 
00071         o << "*";
00072     else {
00073         if (lower_exists())
00074             o << lower_guarded();
00075         else
00076             o << "*";
00077 
00078         o << ":";
00079 
00080         if (upper_exists())
00081             o << upper_guarded();
00082         else
00083             o << "*";
00084     }
00085 }
00086 
00087 SharedBounds & 
00088 SharedBounds::operator = (const SharedBounds & other) 
00089 {
00090     _expr_list.modify(LOWER_SHARED_BOUND, 
00091         (other.lower_exists() ? other.lower_guarded().clone() : 0));
00092 
00093     _expr_list.modify(UPPER_SHARED_BOUND, 
00094         (other.upper_exists() ? other.upper_guarded().clone() : 0));
00095 
00096     return *this;
00097 }
00098 
00099 SharedBounds::~SharedBounds()
00100 {
00101     #ifdef CLASS_INSTANCE_REGISTRY
00102     unregister_instance(SHARED_BOUNDS, this);
00103     #endif
00104 
00105     _expr_list.clear();
00106 }
00107 
00108 int 
00109 SharedBounds::structures_OK() const
00110 {
00111     if (lower_exists()) {
00112         if (!lower_guarded().structures_OK()) {
00113             cerr << "In context of SharedBounds:\n" << *this << endl;
00114             return 0;
00115         }
00116     }
00117 
00118     if (upper_exists()) {
00119         if (!upper_guarded().structures_OK()) {
00120             cerr << "In context of SharedBounds: " << *this << endl;
00121             return 0;
00122         }
00123     }
00124 
00125     return 1;
00126 }
00127 
00128 void 
00129 SharedBounds::lower(Expression * expr)
00130 {
00131     _expr_list.modify(LOWER_SHARED_BOUND, expr);
00132 }
00133 
00134 void 
00135 SharedBounds::upper(Expression * expr)
00136 {
00137     _expr_list.modify(UPPER_SHARED_BOUND, expr);
00138 }
00139 
00140 Listable       *
00141 SharedBounds::listable_clone() const
00142 {
00143     return new SharedBounds(*this);
00144 }
00145 
00146 const Expression & 
00147 SharedBounds::upper_guarded() const
00148 {
00149     p_assert(_expr_list.valid(UPPER_SHARED_BOUND),
00150              "SharedBounds::upper_guarded(): upper expression does not exist");
00151 
00152     return _expr_list[UPPER_SHARED_BOUND];
00153 }
00154 
00155 Expression & 
00156 SharedBounds::upper_guarded()
00157 {
00158     p_assert(_expr_list.valid(UPPER_SHARED_BOUND),
00159              "SharedBounds::upper_guarded(): upper expression does not exist");
00160 
00161     return _expr_list[UPPER_SHARED_BOUND];
00162 }
00163 
00164 const Expression & 
00165 SharedBounds::lower_guarded() const
00166 {
00167     p_assert(_expr_list.valid(LOWER_SHARED_BOUND),
00168         "SharedBounds::lower_guarded(): lower expression does not exist");
00169 
00170     return _expr_list[LOWER_SHARED_BOUND];
00171 }
00172 
00173 Expression & 
00174 SharedBounds::lower_guarded()
00175 {
00176     p_assert(_expr_list.valid(LOWER_SHARED_BOUND),
00177         "SharedBounds::lower_guarded(): lower expression does not exist");
00178 
00179     return _expr_list[LOWER_SHARED_BOUND];
00180 }
00181 
00182 List<Expression> & 
00183 SharedBounds::arg_list()
00184 {
00185     return _expr_list;
00186 }
00187  
00188 
00189 SharedBounds::SharedBounds(const SharedBounds & other)
00190 {
00191     #ifdef CLASS_INSTANCE_REGISTRY
00192     register_instance(SHARED_BOUNDS, sizeof(SharedBounds), this);
00193     #endif
00194 
00195     _expr_list.make_static_list(2);
00196 
00197     *this = other;
00198 }
00199 
00200 SharedBounds::SharedBounds()
00201 {
00202     #ifdef CLASS_INSTANCE_REGISTRY
00203     register_instance(SHARED_BOUNDS, sizeof(SharedBounds), this);
00204     #endif
00205 
00206     _expr_list.make_static_list(2);
00207 }
00208 
00209 int 
00210 SharedBounds::lower_exists() const
00211 {
00212     return _expr_list.valid(LOWER_SHARED_BOUND);
00213 }
00214 
00215 const Expression *
00216 SharedBounds::lower_ref() const
00217 {
00218     if (lower_exists())
00219         return & _expr_list[LOWER_SHARED_BOUND];
00220 
00221     return 0;
00222 }
00223 
00224 Expression *
00225 SharedBounds::lower_ref()
00226 {
00227     if (lower_exists())
00228         return & _expr_list[LOWER_SHARED_BOUND];
00229 
00230     return 0;
00231 }
00232 
00233 int 
00234 SharedBounds::upper_exists() const
00235 {
00236     return _expr_list.valid(UPPER_SHARED_BOUND);
00237 }
00238 
00239 const Expression *
00240 SharedBounds::upper_ref() const
00241 {
00242     if (upper_exists())
00243         return & _expr_list[UPPER_SHARED_BOUND];
00244 
00245     return 0;
00246 
00247 }
00248 
00249 Expression *
00250 SharedBounds::upper_ref()
00251 {
00252     if (upper_exists())
00253         return & _expr_list[UPPER_SHARED_BOUND];
00254 
00255     return 0;
00256 
00257 }
00258 
00259 ostream & 
00260 operator << (ostream & o, const SharedBounds & bounds) 
00261 {
00262     bounds.print(o);
00263     return o;
00264 }
00265 
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:06 2005