PropConstMap.hGo to the documentation of this file.00001
00002 #ifndef _PROPCONSTMAP_H
00003 #define _PROPCONSTMAP_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #include <stream.h>
00061
00062 #include "../Expression/Expression.h"
00063 #include "../Statement/Statement.h"
00064 #include "../Symbol/Symbol.h"
00065 #include "../Collection/Map.h"
00066 #include "../Array.h"
00067 #include "../IntElem.h"
00068 #include "../IntSet.h"
00069 #include "../p-assert.h"
00070
00071 class PropConstValue : public Listable {
00072 public:
00073 PropConstValue(const Expression &expr, const Statement &stmt,
00074 int stmt_toporder, const Map<Symbol,IntElem> &candidates);
00075 PropConstValue(const PropConstValue &other);
00076 virtual ~PropConstValue();
00077
00078 inline const Expression &expr() const;
00079
00080
00081 inline const Statement &stmt() const;
00082
00083
00084 inline const IntSet &use_set() const;
00085
00086
00087 inline int stmt_toporder() const;
00088 inline void stmt_toporder(int val);
00089
00090
00091
00092
00093 virtual Listable *listable_clone() const;
00094 virtual void print(ostream &o) const;
00095 virtual int structures_OK() const;
00096
00097
00098 private:
00099 Expression *_expr;
00100 const Statement *_stmt;
00101 IntSet _use_set;
00102 Boolean _has_integer_val;
00103 int _integer_val;
00104 int _toporder;
00105 };
00106
00107 enum CONST_STATE {
00108 MAY_BE_CONST,
00109 CONST,
00110 NON_CONST,
00111 };
00112
00113 class PropConstElem {
00114 public:
00115 PropConstElem();
00116
00117
00118 PropConstElem(const PropConstElem &);
00119 ~PropConstElem();
00120
00121 inline const Statement *last_mod() const;
00122
00123
00124
00125
00126 const Expression &expr() const;
00127
00128
00129 const IntSet &use_set() const;
00130
00131
00132
00133 const PropConstValue &const_val() const;
00134
00135
00136 inline CONST_STATE state() const;
00137
00138
00139 void constant(const PropConstValue &const_val);
00140
00141
00142
00143
00144 void non_const(const Statement &);
00145
00146
00147
00148
00149 void intersect(const PropConstElem &other, const Statement &curr_stmt);
00150
00151
00152
00153
00154
00155 PropConstElem &operator = (const PropConstElem &);
00156
00157
00158 int operator == (const PropConstElem &) const;
00159 inline int operator != (const PropConstElem &) const;
00160
00161
00162
00163
00164
00165 void print(ostream &o) const;
00166 friend ostream & operator << (ostream &o, const PropConstElem &pce);
00167
00168
00169 int structures_OK(void) const;
00170
00171
00172
00173 private:
00174 const Statement *_last_mod;
00175 const PropConstValue *_const_val;
00176
00177 Boolean _const_equal(const PropConstElem &) const;
00178 };
00179
00180 class PropConstIntMap {
00181 public:
00182 PropConstIntMap(int num_consts, const Array<Symbol *> &tag_to_candidate);
00183 PropConstIntMap(const PropConstIntMap &other);
00184 virtual ~PropConstIntMap();
00185
00186 inline const Array<Symbol *> &tag_to_candidate() const;
00187
00188
00189 CONST_STATE state(int sym_tag) const;
00190
00191
00192 void constant(int sym_tag, int const_val);
00193
00194
00195
00196 void non_const(int sym_tag);
00197
00198
00199 int int_const_val(int sym_tag) const;
00200
00201
00202
00203 inline int entries() const;
00204
00205
00206 void all_non_const();
00207
00208
00209 void intersect(const PropConstIntMap &other);
00210
00211
00212 PropConstIntMap &operator = (const PropConstIntMap &other);
00213
00214
00215 int operator == (const PropConstIntMap &) const;
00216 inline int operator != (const PropConstIntMap &) const;
00217
00218
00219 void print(ostream &o) const;
00220 friend ostream & operator << (ostream &o, const PropConstIntMap &pcm);
00221
00222
00223 void pretty_print(ostream &o) const;
00224
00225
00226
00227 int structures_OK(void) const;
00228
00229
00230
00231 private:
00232 Array<int> _const_map;
00233 IntSet _const_elems;
00234 IntSet _undefined_elems;
00235 const Array<Symbol *> *_tag_to_candidate;
00236
00237 };
00238
00239 class PropConstMap {
00240 public:
00241 PropConstMap(int num_consts, const Array<Symbol *> &tag_to_candidate);
00242 PropConstMap(const PropConstMap &other);
00243 virtual ~PropConstMap();
00244
00245 inline const Array<Symbol *> &tag_to_candidate() const;
00246
00247
00248 inline PropConstElem &operator [] (int sym_tag) const;
00249
00250
00251
00252 inline int entries() const;
00253
00254
00255 void all_non_const(const Statement &stmt);
00256
00257
00258 inline CONST_STATE int_state(int sym_tag) const;
00259
00260
00261
00262 inline void int_const(int sym_tag, int const_val);
00263
00264
00265
00266 inline void int_non_const(int sym_tag);
00267
00268
00269 inline int int_const_val(int sym_tag) const;
00270
00271
00272
00273 void intersect(const PropConstMap &other, const Statement &stmt);
00274
00275
00276 PropConstMap &operator = (const PropConstMap &other);
00277
00278
00279 int operator == (const PropConstMap &) const;
00280 inline int operator != (const PropConstMap &) const;
00281
00282
00283 void print(ostream &o) const;
00284 friend ostream & operator << (ostream &o, const PropConstMap &pcm);
00285
00286
00287 void pretty_print(ostream &o) const;
00288
00289
00290
00291 int structures_OK(void) const;
00292
00293
00294
00295 private:
00296 Array<PropConstElem> _const_map;
00297
00298 PropConstIntMap _int_const_map;
00299
00300 const Array<Symbol *> *_tag_to_candidate;
00301
00302 };
00303
00304
00305
00306
00307
00308 inline const Expression &
00309 PropConstValue::expr() const
00310 {
00311 return *_expr;
00312 }
00313
00314 inline const Statement &
00315 PropConstValue::stmt() const
00316 {
00317 return *_stmt;
00318 }
00319
00320 inline const IntSet &
00321 PropConstValue::use_set() const
00322 {
00323 return _use_set;
00324 }
00325
00326 inline int
00327 PropConstValue::stmt_toporder() const
00328 {
00329 return _toporder;
00330 }
00331
00332 inline void
00333 PropConstValue::stmt_toporder(int val)
00334 {
00335 _toporder = val;
00336 }
00337
00338 inline const Statement *
00339 PropConstElem::last_mod() const
00340 {
00341 return _last_mod;
00342 }
00343
00344 inline CONST_STATE
00345 PropConstElem::state() const
00346 {
00347 if (! _last_mod)
00348 return MAY_BE_CONST;
00349 else if (_const_val)
00350 return CONST;
00351 else
00352 return NON_CONST;
00353 }
00354
00355 inline int
00356 PropConstElem::operator != (const PropConstElem &other) const
00357 {
00358 return (! (*this == other));
00359 }
00360
00361 inline const Array<Symbol *> &
00362 PropConstIntMap::tag_to_candidate() const
00363 {
00364 return *_tag_to_candidate;
00365 }
00366
00367 inline int
00368 PropConstIntMap::entries() const
00369 {
00370 return _const_map.entries();
00371 }
00372
00373 inline int
00374 PropConstIntMap::operator != (const PropConstIntMap &other) const
00375 {
00376 return (! (*this == other));
00377 }
00378
00379 inline const Array<Symbol *> &
00380 PropConstMap::tag_to_candidate() const
00381 {
00382 return *_tag_to_candidate;
00383 }
00384
00385 inline PropConstElem &
00386 PropConstMap::operator [] (int sym_tag) const
00387 {
00388 return CASTAWAY(PropConstElem &) _const_map[sym_tag];
00389 }
00390
00391 inline int
00392 PropConstMap::entries() const
00393 {
00394 return _const_map.entries();
00395 }
00396
00397 inline CONST_STATE
00398 PropConstMap::int_state(int sym_tag) const
00399 {
00400 return _int_const_map.state(sym_tag);
00401 }
00402
00403 inline void
00404 PropConstMap::int_const(int sym_tag, int const_val)
00405 {
00406 _int_const_map.constant(sym_tag, const_val);
00407 }
00408
00409 inline void
00410 PropConstMap::int_non_const(int sym_tag)
00411 {
00412 _int_const_map.non_const(sym_tag);
00413 }
00414
00415 inline int
00416 PropConstMap::int_const_val(int sym_tag) const
00417 {
00418 return _int_const_map.int_const_val(sym_tag);
00419 }
00420
00421 inline int
00422 PropConstMap::operator != (const PropConstMap &other) const
00423 {
00424 return (! (*this == other));
00425 }
00426
00427 #endif
|