Polaris: Data.cc Source File

Data.cc

Go to the documentation of this file.
00001 ///
00002 ///
00003 /// \file Data.cc
00004 ///
00005 #include "define.h"
00006 
00007 #ifdef POLARIS_GNU_PRAGMAS
00008 #pragma implementation
00009 #endif
00010 
00011 #include "Data.h"
00012 #include "BinRep.h"
00013 #include "ExprTable.h"
00014 #include "Symbol/Symbol.h"
00015 #include "Expression/DoExpr.h"
00016 #include "Expression/NonBinaryExpr.h"
00017 #include "Expression/ArrayRefExpr.h"
00018 #include "Collection/Iterator.h"
00019 #include "Collection/List.h"
00020 #include "Collection/Mutator.h"
00021 
00022 template class TypedCollection<Data>;
00023 template class List<Data>;
00024 template ostream & operator << (ostream &, const List<Data> &);
00025 template class Assign<Data>;
00026 
00027 template class Iterator<Data>;
00028 template class Mutator<Data>;
00029 
00030 ostream & 
00031 operator << (ostream & o, const Data & d) 
00032 {
00033     return o << d.variable_list() << " /" << d.value_list() << "/";
00034 }
00035 
00036 Data::Data()
00037 {
00038     #ifdef CLASS_INSTANCE_REGISTRY
00039     register_instance(DATA_CLASS, sizeof(Data), this);
00040     #endif
00041 }
00042 
00043 Data::Data(const BinRep & binstr, ExprTable & etable)
00044 {
00045     #ifdef CLASS_INSTANCE_REGISTRY
00046     register_instance(DATA_CLASS, sizeof(Data), this);
00047     #endif
00048 
00049     p_assert( binstr.to_tuple().entries() == 2,
00050           "Binstring must have 2 entries for a DATA statement");
00051     
00052     Iterator<BinRep> iter = binstr.to_tuple();
00053     
00054     Expression *ex;
00055     
00056     ex = convert_expr(iter.current(), etable, "DataStmt")->clone();
00057     
00058         p_assert( ex, "can not convert variable list" );
00059 
00060     variable_list( (CommaExpr *) ex );
00061 
00062     mark_initialized(variable_list());
00063 
00064     ++iter;
00065 
00066     ex = convert_expr(iter.current(), etable, "DataStmt")->clone();
00067 
00068     p_assert( ex, "can not convert value list" );
00069 
00070     value_list((CommaExpr *) ex );
00071 }
00072 
00073 Data::~Data()
00074 {
00075     #ifdef CLASS_INSTANCE_REGISTRY
00076     unregister_instance(DATA_CLASS, this);
00077     #endif
00078 }
00079 
00080 const CommaExpr &
00081 Data::variable_list() const
00082 {
00083     return (*(this->_variable_list));
00084 }
00085 
00086 CommaExpr &
00087 Data::variable_list()
00088 {
00089     return (*(this->_variable_list));
00090 }
00091 
00092 const CommaExpr &
00093 Data::value_list() const
00094 {
00095     return (*(this->_value_list));
00096 }
00097 
00098 CommaExpr &
00099 Data::value_list()
00100 {
00101     return (*(this->_value_list));
00102 }
00103 
00104 void
00105 Data::variable_list(CommaExpr * varlist)
00106 {
00107     this->_variable_list = varlist;
00108 }
00109 
00110 void
00111 Data::value_list(CommaExpr * vallist)
00112 {
00113     this->_value_list = vallist;
00114 }
00115 
00116 Data           *
00117 Data::clone() const
00118 {
00119     return new Data(*this);
00120 }
00121 
00122 Listable       *
00123 Data::listable_clone() const
00124 {
00125     return clone();
00126 }
00127 
00128 /// This print function is to satisfy Listable::print(...)
00129 
00130 void
00131 Data::print(ostream & o) const
00132 {
00133     o << "DATA ";
00134     _variable_list->print_debug(o, 1);
00135     o << " / ";
00136     _value_list->print_debug(o, 1);
00137     o << " /\n";
00138 }
00139 
00140 
00141 ///   Takes as input an expression, which is assumed to
00142 ///   be a "CommaExpr" of variables that will be initialized in the DATA
00143 ///   statement.  The expressions on the comma-list can be either IDExpr's,
00144 ///   ArrayRefExpr's, or DoExpr's - no other expressions may appear in a 
00145 ///   DATA statement.  This routine marks all the symbols it finds as 
00146 ///   "initialized" because they appear in the DATA statement.
00147 
00148 void 
00149 mark_initialized(CommaExpr & expr)
00150 {
00151 
00152     for (Iterator<Expression> viter = ((NonBinaryExpr &) expr).arg_list();
00153                               viter.valid(); ++viter) {
00154         OP_TYPE         vop = viter.current().op();
00155 
00156         switch (vop) {
00157         case ID_OP:
00158             viter.current().symbol().initial_value(IS_INITIALIZED);
00159             break;
00160 
00161         case ARRAY_REF_OP:
00162             ((ArrayRefExpr &) 
00163             viter.current()).base_variable_ref()->initial_value(IS_INITIALIZED);
00164             break;
00165 
00166         case DO_OP:
00167             mark_initialized((CommaExpr &) 
00168                 ((DoExpr &) viter.current()).iolist());
00169             break;
00170 
00171         default:
00172             p_abort("DATA statement - invalid variable list");
00173         }
00174     }
00175 }
00176 
00177 /// RELINK---------------------------------------------------------------
00178 
00179 void
00180 Data::relink_ptrs(ProgramUnit & p)
00181 {
00182     _variable_list->relink_eptrs(p);
00183     _value_list->relink_eptrs(p);
00184 }
00185 
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:43 2005