Polaris: ArrayDims.cc Source File

ArrayDims.cc

Go to the documentation of this file.
00001 /// \file ArrayDims.cc
00002 /// \brief 
00003 ///
00004 #include "define.h"
00005 
00006 #ifdef POLARIS_GNU_PRAGMAS
00007 #pragma implementation
00008 #endif
00009 
00010 #include "ArrayDims.h"
00011 #include "BinRep.h"
00012 #include "Collection/Iterator.h"
00013 #include "Collection/Mutator.h"
00014 #include "Collection/Map.h"
00015 #include "Symbol/Symbol.h"
00016 
00017 template class TypedBaseMap<Symbol,ArrayDims>;
00018 template class ProtoMap<Symbol,ArrayDims>;
00019 template class Map<Symbol,ArrayDims>;
00020 template ostream & operator << (ostream &, const Map<Symbol,ArrayDims> &);
00021 template class KeyIterator<Symbol,ArrayDims>;
00022 
00023 template class TypedCollection<ArrayDims>;
00024 template class List<ArrayDims>; 
00025 template ostream &operator << (ostream &, const List<ArrayDims> &);
00026 template class Assign<ArrayDims>;
00027 template class Iterator<ArrayDims>;
00028 template class Mutator<ArrayDims>;
00029 
00030 ArrayDims::ArrayDims(const ArrayDims & dims)
00031 {
00032     #ifdef CLASS_INSTANCE_REGISTRY
00033     register_instance(ARRAY_DIMS, sizeof(ArrayDims), this);
00034     #endif
00035 
00036     *this = dims;
00037 }
00038 
00039 ArrayDims & 
00040 ArrayDims::operator = (const ArrayDims & dims)
00041 {
00042     List<ArrayBounds>::operator = ( dims );
00043 
00044     return (*this);
00045 }
00046 
00047 ArrayDims *
00048 ArrayDims::clone() const
00049 {
00050     return new ArrayDims( *this );
00051 }
00052 
00053 Listable *
00054 ArrayDims::listable_clone() const
00055 {
00056     return (Listable *) clone();
00057 }
00058 
00059 void 
00060 ArrayDims::convert(const BinRep & binstr, ExprTable & exprs)
00061 {
00062     /// ...  Erase any old entries if there are any
00063     clear();
00064 
00065     for (Iterator<BinRep> iter = binstr.to_tuple(); iter.valid(); ++iter)
00066         ins_last(new ArrayBounds(iter.current(), exprs));
00067 }
00068 
00069 void 
00070 ArrayDims::print(ostream & o) const
00071 {
00072     Iterator<ArrayBounds>    iter = *this;
00073 
00074     int             first_time;
00075 
00076     o << "(";
00077 
00078     for (first_time = 1; !iter.end(); iter.next(), first_time = 0) {
00079         if (!first_time)
00080             o << ", ";
00081         o << iter.current();
00082     }
00083 
00084     o << ")";
00085 }
00086 
00087 void 
00088 ArrayDims::print_all_colons(ostream & o) const
00089 {
00090     Iterator<ArrayBounds>    iter = *this;
00091 
00092     int             first_time;
00093 
00094     o << "(";
00095 
00096     for (first_time = 1; !iter.end(); iter.next(), first_time = 0) {
00097         if (!first_time)
00098             o << ", ";
00099         o << ":";
00100     }
00101 
00102     o << ")";
00103 }
00104 
00105 void 
00106 ArrayDims::print_last_star(ostream & o) const
00107 {
00108     Iterator<ArrayBounds>    iter = *this;
00109 
00110     int             first_time;
00111     ArrayBounds * last_bound = NULL;
00112 
00113     iter.set_to_last();  /// ...  prepare to get the last element
00114     if (iter.valid())
00115     last_bound = &(iter.current());
00116     else
00117     p_abort("Empty bounds list for array");
00118     
00119     iter.reset();        /// ...  now go forward from the beginning
00120     
00121     o << "(";
00122 
00123     for (first_time = 1; !iter.end(); iter.next(), first_time = 0) {
00124         if (!first_time)
00125             o << ", ";
00126     ArrayBounds & this_bound = iter.current();
00127     if (&this_bound == last_bound)
00128         o << "*";
00129     else
00130         o << this_bound;
00131     }
00132 
00133     o << ")";
00134 }
00135 
00136 int 
00137 ArrayDims::structures_OK() const
00138 {
00139     if (!List<ArrayBounds>::structures_OK()) {
00140         cerr << "In context of ArrayDims:\n" << flush;
00141         cerr << *this << endl;
00142         return 0;
00143     }
00144 
00145     return 1;
00146 }
00147 
00148 ArrayDims::ArrayDims()
00149 {
00150     #ifdef CLASS_INSTANCE_REGISTRY
00151     register_instance(ARRAY_DIMS, sizeof(ArrayDims), this);
00152     #endif
00153     /// ...  Nothing to do
00154 }
00155 
00156 ArrayDims::ArrayDims(const BinRep &binstr, ExprTable &exprs)
00157 {
00158     #ifdef CLASS_INSTANCE_REGISTRY
00159     register_instance(ARRAY_DIMS, sizeof(ArrayDims), this);
00160     #endif
00161 
00162     convert(binstr, exprs);
00163 }
00164 
00165 ostream & 
00166 operator << (ostream &o, const ArrayDims &dims)
00167 {
00168     dims.print(o);
00169     return o;
00170 }
00171 
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:37 2005