Polaris: ExprSet.cc Source File

ExprSet.cc

Go to the documentation of this file.
00001 ///
00002 ///
00003 /// \file ExprSet.cc
00004 ///
00005 #include "ExprSet.h"
00006 
00007 ExprSet::ExprSet()
00008 {
00009     /// ...  Nothing to do.
00010 }
00011 
00012 ExprSet::ExprSet(const ExprSet &other)
00013 {
00014     _expr_set = other._expr_set;
00015 }
00016 
00017 ExprSet::~ExprSet()
00018 {
00019     /// ...  Nothing to do.
00020 }
00021 
00022 ExprSet &
00023 ExprSet::operator = (const ExprSet &other)
00024 {
00025     _expr_set = other._expr_set;
00026     return *this;
00027 }
00028 
00029 const Expression &
00030 ExprSet::ins(Expression *expr)
00031 {
00032     Expression *pred;
00033     const Expression *rep = _representative(*expr, pred);
00034 
00035     if (rep)
00036     delete expr;
00037     else {
00038     _expr_set.ins_after(expr, pred);
00039     rep = expr;
00040     }
00041 
00042     return *rep;
00043 }
00044 
00045 void 
00046 ExprSet::del(Expression &expr)
00047 { 
00048     const Expression *rep = representative(expr);
00049     p_assert(rep,
00050          "The given expression to delete is not in the expression set.");
00051     _expr_set.del(* CASTAWAY(Expression *) rep);
00052 }
00053 
00054 void 
00055 ExprSet::clear()
00056 {
00057     _expr_set.clear();
00058 }
00059 
00060 bool
00061 ExprSet::member(Expression &expr) const
00062 {
00063     return (representative(expr) != 0);
00064 }
00065 
00066 const Expression *
00067 ExprSet::representative(const Expression &expr) const
00068 {
00069     Expression *pred;
00070     return _representative(CASTAWAY(Expression &)expr, pred);
00071 }
00072 
00073 const Expression *
00074 ExprSet::_representative(Expression &expr, Expression *& pred) const
00075 {
00076     expr.standardize();
00077     int expr_hash_value = expr.signature().hash_value();
00078     pred = 0;
00079     Expression *curr = (Expression*) _expr_set.first_ref();
00080 
00081     while (curr && expr_hash_value > curr->signature().hash_value()) {
00082     pred = curr;
00083     curr = (Expression *) curr->next_ref();
00084     }
00085 
00086     while (curr && expr_hash_value == curr->signature().hash_value()) {
00087     if (&expr == curr || expr.compare(*curr) == 0)
00088         return curr;
00089 
00090     pred = curr;
00091     curr = (Expression *) curr->next_ref();
00092     }
00093 
00094     return 0;
00095 }
00096 
00097 Iterator<Expression> 
00098 ExprSet::iterator() const
00099 {
00100     return Iterator<Expression>(_expr_set);
00101 }
00102 
00103 void
00104 ExprSet::print(ostream & o) const
00105 {
00106     _expr_set.print(o);
00107 }
00108 
00109 Listable *
00110 ExprSet::listable_clone(void) const
00111 {
00112     return new ExprSet(*this);
00113 }
00114 
00115 int 
00116 ExprSet::structures_OK() const
00117 {
00118     return _expr_set.structures_OK();
00119 }
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:52 2005