00001 /* 00002 * suif_utils.h 00003 */ 00004 00005 #ifndef SUIF_UTILS_H 00006 #define SUIF_UTILS_H 00007 class vnode; 00008 00009 #include <fstream.h> 00010 #include "basicnodes/basic_forwarders.h" 00011 #include "suifnodes/suif_forwarders.h" 00012 #include "common/suif_list.h" 00013 #include "common/i_integer.h" 00014 #include "common/formatted.h" 00015 #include "suifkernel/suifkernel_forwarders.h" 00016 #include "suifkernel/suif_walker.h" 00017 00018 #include "suifprinter/suifprinter.h" 00019 00020 list<ProcedureSymbol*> * 00021 get_procedure_list( FileSetBlock *file_set, 00022 bool flag_export=true, 00023 bool flag_static=true, 00024 bool flag_nested=false, 00025 bool flag_defs_only = true ); 00026 00027 00028 ProcedureDefinition* get_procedure_definition( SuifObject* node ); 00029 bool is_same_procedure( ProcedureDefinition* p1, SuifObject* p2 ); 00030 FileBlock* get_file_block( SuifObject* node ); 00031 SuifObject* last_zot( SuifObject* z ); 00032 IInteger get_line_number(Annote* z ); 00033 String get_file_name( Annote* z ); 00034 00035 class stopping_suif_visitor : public SuifWalker { 00036 protected: 00037 bool stop; 00038 public: 00039 stopping_suif_visitor(SuifEnv *suif_env):SuifWalker(suif_env) { stop=false; } 00040 virtual bool stop_iterating() const { return stop; } 00041 ApplyStatus operator() (SuifObject *zot) { return Continue; } 00042 00043 }; 00044 00045 bool iterate_over(SuifObject *start_zot, 00046 stopping_suif_visitor *vis, 00047 s_count_t start_comp = 0, 00048 bool do_root = true ); 00049 00050 bool iterate_next( SuifObject *start_zot, 00051 stopping_suif_visitor *vis, 00052 SuifObject *stop_at=0, 00053 s_count_t start_comp = 0 ); 00054 00055 bool iterate_right_to_left( SuifObject *start_zot, 00056 stopping_suif_visitor *vis, 00057 s_count_t start_comp = 0, 00058 bool do_root = true ); 00059 00060 bool iterate_previous( SuifObject *start_zot, 00061 stopping_suif_visitor *vis, 00062 SuifObject *stop_at=0, 00063 bool check_self = false ); 00064 00065 FileBlock *get_file_block( SuifObject* node ); 00066 00067 IInteger find_source_line( SuifObject *tn, String &file_name ); 00068 00069 SuifObject *map_line_to_tree_node( SuifObject *root, int line ); 00070 00071 FileBlock *find_file_block( String src_file); 00072 00073 class suif_utils { 00074 public: 00075 static String get_path( FileBlock* fb ); 00076 static bool is_absolute( String file ); 00077 static bool is_same_file( String name1, String name2 ); 00078 static String get_source_file( FileBlock* fb ); 00079 static SuifObject* get_zot( vnode* vn ); 00080 }; 00081 00082 //------------------------------------------------------------------------ 00083 //------------------------------------------------------------------------ 00084 // Copied from suifx/zot_class.h: Should be appropriately replaced later. 00085 //------------------------------------------------------------------------ 00086 //------------------------------------------------------------------------ 00087 // 00088 // We cheat here. We should be implementing this as a moudle but 00089 // for now we do not do that - we treat it as a class and (elsewhere) 00090 // we init the module we derive from, not this one 00091 class zot_print_helper : public SuifPrinterModule 00092 { 00093 protected: 00094 zot_print_helper(SuifEnv *env) : SuifPrinterModule(env) {SuifPrinterModule::init(); } 00095 00096 public: 00097 virtual ~zot_print_helper(void) { } 00098 00099 virtual void print_zot(const SuifObject *the_zot, fstream&the_ion) = 0; 00100 virtual void print_zot_ref(const SuifObject *the_zot, fstream&the_ion) = 0; 00101 virtual int indentation_level(void) const = 0; 00102 virtual void add_indentation(int additional_amount) = 0; 00103 virtual void remove_indentation(int removed_amount) = 0; 00104 virtual void print_zot_prefix(const SuifObject *the_zot, fstream&the_ion) = 0; 00105 virtual void print_zot_continuation_prefix(const SuifObject *the_zot, 00106 fstream&the_ion) = 0; 00107 FormattedText formatted_text; 00108 00109 }; 00110 00111 class default_zot_print_helper : public zot_print_helper 00112 { 00113 private: 00114 int _current_indentation; 00115 00116 public: 00117 default_zot_print_helper(SuifEnv *env) : zot_print_helper(env),_current_indentation(0) { } 00118 virtual ~default_zot_print_helper(void) { } 00119 00120 void print_zot(const SuifObject *the_zot, fstream&the_ion); 00121 void print_zot_ref(const SuifObject *the_zot, fstream&the_ion); 00122 int indentation_level(void) const { return _current_indentation; } 00123 void add_indentation(int additional_amount); 00124 void remove_indentation(int removed_amount); 00125 void print_zot_prefix(const SuifObject *the_zot, fstream&the_ion); 00126 void print_zot_continuation_prefix(const SuifObject *the_zot, fstream&the_ion); 00127 }; 00128 00129 #endif // SUIF_UTILS_H