DataList.ccGo to the documentation of this file.00001
00002
00003
00004
00005 #include "define.h"
00006
00007 #ifdef POLARIS_GNU_PRAGMAS
00008 #pragma implementation
00009 #endif
00010
00011 #include <stdlib.h>
00012 #include <strstream.h>
00013
00014 #include "BinRep.h"
00015 #include "Collection/Iterator.h"
00016 #include "DataList.h"
00017 #include "VDL.h"
00018 #include "debug.h"
00019 #include "p-assert.h"
00020 #include "split_line.h"
00021 #include "wide_output.h"
00022
00023 ostream &
00024 operator << (ostream & o, DataList & data)
00025 {
00026 o << "{\n";
00027
00028 Iterator<Data> iter = data;
00029
00030 while (iter.valid()) {
00031 o << "DATA " << iter.current() << "\n";
00032 ++iter;
00033 }
00034
00035 o << "}\n";
00036
00037 return o;
00038 }
00039
00040 DataList::DataList()
00041 {
00042 #ifdef CLASS_INSTANCE_REGISTRY
00043 register_instance(DATA_LIST, sizeof(DataList), this);
00044 #endif
00045 }
00046
00047 DataList::~DataList()
00048 {
00049 #ifdef CLASS_INSTANCE_REGISTRY
00050 unregister_instance(DATA_LIST, this);
00051 #endif
00052 }
00053
00054 void
00055 DataList::relink_ptrs( ProgramUnit &p)
00056 {
00057 Iterator<Data> iter = *this;
00058
00059 while (iter.valid()) {
00060 iter.current().relink_ptrs( p );
00061 ++iter;
00062 }
00063 }
00064
00065 DataList::DataList(const DataList & d)
00066 {
00067 #ifdef CLASS_INSTANCE_REGISTRY
00068 register_instance(DATA_LIST, sizeof(DataList), this);
00069 #endif
00070
00071 *this = d;
00072 }
00073
00074 DataList &
00075 DataList::operator = (const DataList & d)
00076 {
00077 clear();
00078 List<Data>::operator = ( d );
00079
00080 return (*this);
00081 }
00082
00083 DataList *
00084 DataList::clone() const
00085 {
00086 return new DataList(*this);
00087 }
00088
00089 DataList::DataList(const BinRep &binstr, ExprTable &etable)
00090 {
00091 #ifdef CLASS_INSTANCE_REGISTRY
00092 register_instance(DATA_LIST, sizeof(DataList), this);
00093 #endif
00094
00095 for (Iterator<BinRep> iter=binstr.to_tuple(); iter.valid(); ++iter)
00096 ins_last( new Data( iter.current(), etable) );
00097 }
00098
00099 void
00100 DataList::write(ostream & o, int space_for_label,
00101 int max_line_len GIV(FORTRAN_MAX_LINE_LEN)) const
00102 {
00103 Iterator<Data> iter = (List<Data> &) *this;
00104
00105 while (iter.valid()) {
00106 ostrstream line;
00107 line << "DATA " << iter.current();
00108 line << '\0';
00109 String linestr = line.str();
00110 if (space_for_label == 0)
00111 blank_wide_output( o );
00112 split_line(o, space_for_label, "", -1, linestr, max_line_len);
00113 ++iter;
00114 }
00115 }
00116
00117 int
00118 DataList::structures_OK() const
00119 {
00120 if (!List<Data>::structures_OK()) {
00121 cerr << "In context of a DataList.\n";
00122 return 0;
00123 }
00124
00125 return 1;
00126 }
00127
00128 void
00129 DataList::exchange_convert( VDL &vdl )
00130 {
00131 BinRep *b = CASTAWAY(BinRep *) vdl.data_ref();
00132
00133 if ( this->entries() > 0 ) {
00134 List<BinRep> *L = new List<BinRep>;
00135
00136 L->ins_last(new BinRep( "data_expr" ));
00137 L->ins_last(new BinRep( new List<BinRep> ));
00138
00139 b->to_set().ins( new BinRep( L ) );
00140
00141 for (Iterator<Data> iter = (*this); iter.valid(); ++iter) {
00142 Data &dt = iter.current();
00143 List<BinRep> &L = b->find_ref( "data_expr" )->to_tuple();
00144 BinRep *br;
00145
00146 br = new BinRep( new List<BinRep> );
00147
00148 br->to_tuple().ins_last(
00149 new BinRep( dt.variable_list().exchange_expr(vdl) ));
00150 br->to_tuple().ins_last(
00151 new BinRep( dt.value_list().exchange_expr(vdl) ));
00152
00153 L.ins_last( br );
00154 }
00155 }
00156 }
00157
|