00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 #ifndef lestes__std___dumper_hh___included 00029 #define lestes__std___dumper_hh___included 00030 00031 /*! \file 00032 The actual dumper for general use within the project. 00033 \author Rudo 00034 */ 00035 #include <lestes/common.hh> 00036 #include <lestes/std/dumper_visitor.hh> 00037 #include <lestes/std/list.hh> 00038 #include <lestes/std/set.hh> 00039 #include <lestes/std/ucn_string.hh> 00040 #include <ostream> 00041 00042 package(lestes); 00043 package(std); 00044 00045 class dumper : public dumper_visitor { 00046 public: 00047 //! Dumps every instance reachable from start_at to given ostream. Returns given ostream. 00048 static ::std::ostream & dump( ::std::ostream & output_to, ptr<object> start_at, 00049 bool respect_barriers = true ); 00050 virtual void visit_object( ptr<object> o ); 00051 virtual void visit_nodump(); 00052 virtual void visit_lint( lint ); 00053 virtual void visit_ulint( ulint ); 00054 virtual void visit_bool( bool ); 00055 virtual void visit_lstring( const lstring & ); 00056 virtual void visit_ucn_string( const ucn_string & ); 00057 private: 00058 typedef list< srp<object> > queue_type; 00059 typedef set< srp<object> > set_type; 00060 //! return value from visit_XXX; null for simple_type visits 00061 bool was_simple; 00062 ::std::ostream &stream; 00063 //! enqueues o into queue, iff o was not yet visited 00064 void try_enqueue( ptr<object> o, ptr<queue_type> queue, ptr<set_type> visited ); 00065 //! should the dumper respect barriers (see object::dump_barrier) 00066 const bool respect_barriers; 00067 protected: 00068 void gc_mark(); 00069 dumper( ::std::ostream &a_stream, bool a_respect_barriers ); 00070 //! Does the actual dumping. Has got to be a non-static method, as we are a visitor :) 00071 void the_dump( ptr<object> start_at ); 00072 }; 00073 00074 class readable_dumper : public dumper_visitor { 00075 public: 00076 //! Dumps every instance reachable from start_at to given ostream. Returns given ostream. 00077 static ::std::ostream & dump( ::std::ostream & output_to, ptr<object> start_at, 00078 bool respect_barriers = true ); 00079 virtual void visit_object( ptr<object> o ); 00080 virtual void visit_nodump(); 00081 virtual void visit_lint( lint i ); 00082 virtual void visit_ulint( ulint i ); 00083 virtual void visit_bool( bool i ); 00084 virtual void visit_lstring( const lstring &i ); 00085 virtual void visit_ucn_string( const ucn_string &i ); 00086 protected: 00087 void gc_mark(); 00088 void follow( ptr<object> o ); 00089 readable_dumper( ::std::ostream &a_stream, bool a_respect_barriers ); 00090 public: 00091 // for technical (testing:) reasons this "must" be public 00092 typedef set< srp<object> > set_type; 00093 private: 00094 srp<set_type> visited; 00095 ::std::ostream &stream; 00096 ulint uid; 00097 //! should the dumper respect barriers (see object::dump_barrier) 00098 const bool respect_barriers; 00099 bool after_barrier; 00100 }; 00101 00102 end_package(std); 00103 end_package(lestes); 00104 00105 #endif // lestes__std___dumper_hh___included
1.5.1-20070107