00001 #ifndef wali_wpds_WPDS_GUARD
00002 #define wali_wpds_WPDS_GUARD 1
00003
00004
00005
00006
00007
00008
00009 #include "wali/Common.hpp"
00010 #include "wali/Printable.hpp"
00011 #include "wali/HashMap.hpp"
00012 #include "wali/KeyContainer.hpp"
00013 #include "wali/SemElem.hpp"
00014 #include "wali/Worklist.hpp"
00015
00016
00017 #include "wali/wfa/WFA.hpp"
00018 #include "wali/wfa/TransFunctor.hpp"
00019
00020
00021 #include "wali/wpds/Wrapper.hpp"
00022
00023
00024 #include <iostream>
00025 #include <set>
00026
00027 namespace wali
00028 {
00029 template< typename T > class Worklist;
00030
00031 namespace wfa
00032 {
00033 class ITrans;
00034 }
00035
00036 namespace wpds
00037 {
00038
00039 class Config;
00040 class rule_t;
00041 class RuleFunctor;
00042 class ConstRuleFunctor;
00043
00044
00045
00046
00047 class WPDS : public Printable, public wfa::ConstTransFunctor
00048 {
00049
00050 public:
00051 static const std::string XMLTag;
00052
00053 protected:
00054 typedef HashMap< KeyPair,Config * > chash_t;
00055 typedef chash_t::iterator iterator;
00056 typedef chash_t::const_iterator const_iterator;
00057
00058
00059
00060
00061
00062
00063
00064 typedef HashMap< Key, std::list< rule_t > > r2hash_t;
00065
00066 private:
00067
00068 public:
00069
00070 WPDS();
00071 WPDS( ref_ptr<Wrapper> wrapper );
00072 WPDS( const WPDS& w );
00073 virtual ~WPDS();
00074
00075
00076
00077
00078 virtual void clear();
00079
00080
00081
00082
00083 void setWorklist( ref_ptr< Worklist<wfa::ITrans> > wl );
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 virtual bool add_rule(
00094 Key from_state,
00095 Key from_stack,
00096 Key to_state,
00097 sem_elem_t se );
00098
00099
00100
00101
00102
00103
00104
00105
00106 virtual bool add_rule(
00107 Key from_state,
00108 Key from_stack,
00109 Key to_state,
00110 Key to_stack1,
00111 sem_elem_t se );
00112
00113
00114
00115
00116
00117
00118
00119
00120 virtual bool add_rule(
00121 Key from_state,
00122 Key from_stack,
00123 Key to_state,
00124 Key to_stack1,
00125 Key to_stack2,
00126 sem_elem_t se );
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 virtual bool replace_rule(
00137 Key from_state,
00138 Key from_stack,
00139 Key to_state,
00140 sem_elem_t se );
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 virtual bool replace_rule(
00151 Key from_state,
00152 Key from_stack,
00153 Key to_state,
00154 Key to_stack1,
00155 sem_elem_t se );
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 virtual bool replace_rule(
00166 Key from_state,
00167 Key from_stack,
00168 Key to_state,
00169 Key to_stack1,
00170 Key to_stack2,
00171 sem_elem_t se );
00172
00173
00174
00175
00176
00177
00178
00179
00180 virtual wfa::WFA prestar( wfa::WFA const & input );
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 virtual void prestar( wfa::WFA const & input, wfa::WFA & output );
00195
00196
00197
00198
00199
00200
00201
00202
00203 virtual wfa::WFA poststar( wfa::WFA const & input );
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 virtual void poststar( wfa::WFA const & input, wfa::WFA & output );
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 virtual std::ostream & print( std::ostream & o ) const;
00229
00230
00231
00232
00233
00234
00235
00236
00237 virtual std::ostream & marshall( std::ostream & o ) const;
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 virtual std::ostream & print_dot(
00254 std::ostream & o,
00255 bool print_state=false) const;
00256
00257
00258
00259
00260
00261
00262
00263 virtual int count_rules( ) const;
00264
00265
00266
00267
00268
00269
00270
00271
00272 virtual void for_each( ConstRuleFunctor &func ) const;
00273
00274
00275
00276
00277
00278
00279
00280
00281 virtual void for_each( RuleFunctor &func );
00282
00283
00284
00285
00286 virtual void operator()( wfa::ITrans const * t );
00287
00288 bool is_pds_state(wali::Key k) const;
00289 int num_pds_states() const { return (int) pds_states.size(); }
00290 const std::set<wali::Key>& get_states() const { return pds_states; }
00291
00292
00293
00294
00295
00296
00297
00298
00299 Key constructCFG(std::set<Key> &entries, std::map<Key, Key> &entryState, wfa::WFA &cfg);
00300
00301 sem_elem_t get_theZero() {return theZero; }
00302 protected:
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 virtual bool add_rule(
00315 Key from_state,
00316 Key from_stack,
00317 Key to_state,
00318 Key to_stack1,
00319 Key to_stack2,
00320 sem_elem_t se,
00321 bool replace_weight,
00322 rule_t& r );
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 virtual bool add_rule(
00333 Key from_state,
00334 Key from_stack,
00335 Key to_state,
00336 Key to_stack1,
00337 Key to_stack2,
00338 sem_elem_t se,
00339 rule_t& r );
00340
00341
00342
00343
00344 virtual void setupOutput( wfa::WFA const & input, wfa::WFA& fa );
00345
00346
00347
00348
00349 virtual void unlinkOutput( wfa::WFA& fa );
00350
00351
00352
00353
00354 virtual void prestarSetupFixpoint( wfa::WFA const & input, wfa::WFA& fa );
00355
00356
00357
00358
00359 virtual void prestarComputeFixpoint( wfa::WFA& fa );
00360
00361
00362
00363
00364 virtual void pre( wfa::ITrans * t, wfa::WFA& fa );
00365
00366
00367
00368
00369 virtual void prestar_handle_call(
00370 wfa::ITrans * t1 ,
00371 wfa::ITrans * t2,
00372 rule_t & r,
00373 sem_elem_t delta
00374 );
00375
00376
00377
00378
00379 virtual void prestar_handle_trans(
00380 wfa::ITrans * t,
00381 wfa::WFA & ca ,
00382 rule_t & r,
00383 sem_elem_t delta );
00384
00385
00386
00387
00388 virtual void poststarSetupFixpoint( wfa::WFA const & input, wfa::WFA& fa );
00389
00390
00391
00392
00393 virtual void poststarComputeFixpoint( wfa::WFA& fa );
00394
00395
00396
00397
00398 virtual void post( wfa::ITrans * t, wfa::WFA& fa );
00399
00400
00401
00402
00403 virtual void poststar_handle_eps_trans(
00404 wfa::ITrans *teps,
00405 wfa::ITrans *tprime,
00406 sem_elem_t delta
00407 );
00408
00409
00410
00411
00412 virtual void poststar_handle_trans(
00413 wfa::ITrans * t ,
00414 wfa::WFA & ca ,
00415 rule_t & r,
00416 sem_elem_t delta
00417 );
00418
00419
00420
00421
00422
00423
00424
00425
00426 virtual Key gen_state( Key state, Key stack );
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 virtual Config * make_config( Key state, Key stack );
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 virtual bool make_rule(
00457 Config *f,
00458 Config *t,
00459 Key stk2,
00460 bool replace_weight,
00461 rule_t& r );
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 virtual bool make_rule(
00474 Config *f,
00475 Config *t,
00476 Key stk2,
00477
00478 rule_t& r );
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 virtual Config * find_config( Key state, Key stack );
00489
00490
00491
00492
00493
00494
00495 virtual bool get_from_worklist( wfa::ITrans * & );
00496
00497
00498
00499
00500
00501 virtual void update(
00502 Key from, Key stack, Key to,
00503 sem_elem_t se, Config * cfg );
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513 virtual wfa::ITrans* update_prime(
00514 Key from,
00515 wfa::ITrans* call,
00516 rule_t r,
00517 sem_elem_t delta,
00518 sem_elem_t wWithRule
00519 );
00520
00521
00522
00523
00524 const chash_t & config_map() const {
00525 return configs;
00526 }
00527
00528
00529
00530
00531 chash_t & config_map() {
00532 return configs;
00533 }
00534 private:
00535
00536 protected:
00537 ref_ptr<Wrapper> wrapper;
00538 ref_ptr< Worklist<wfa::ITrans> > worklist;
00539 chash_t configs;
00540 std::set< Config * > rule_zeroes;
00541 r2hash_t r2hash;
00542
00543
00544
00545
00546
00547 wfa::WFA* currentOutputWFA;
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557 sem_elem_t theZero;
00558 std::set<wali::Key> pds_states;
00559
00560 private:
00561
00562 };
00563
00564 }
00565
00566 }
00567
00568 #endif // wali_wpds_WPDS_GUARD
00569