00001 /*-------------------------------------------------------------------- 00002 * code_tree.h 00003 * 00004 */ 00005 00006 #ifndef CODE_TREE_H 00007 #define CODE_TREE_H 00008 00009 #include "visual/visual.h" 00010 00011 #include "suif_vnode.h" 00012 #include "suifkernel/suifkernel_forwarders.h" 00013 00014 class code_fragment { 00015 friend class code_tree; 00016 00017 protected: 00018 int f_line; 00019 int l_line; 00020 SuifObject *tn; 00021 00022 code_fragment *son; 00023 code_fragment *last_son; 00024 code_fragment *next; 00025 00026 void free_subtree(); 00027 00028 public: 00029 code_fragment( SuifObject *node ); 00030 ~code_fragment(); 00031 00032 code_fragment *child() { return son; } 00033 code_fragment *last_child() { return last_son; } 00034 code_fragment *next_sib() { return next; } 00035 00036 00037 void select( vtext* text, bool add = false ) { 00038 vnode* vn = create_vnode( tn ); 00039 text->select( vn, add ); 00040 00041 for ( code_fragment* son = this->son; son; son = son->next ) { 00042 son->select( text, true ); 00043 } 00044 } 00045 00046 00047 void select_code_fragments( vtext* text, bool sub_nodes = true ) { 00048 vnode* vn = vman->find_vnode( this ); 00049 if ( vn ) { 00050 text->select( vn, sub_nodes ); 00051 } 00052 00053 if ( sub_nodes ) { 00054 for ( code_fragment* son = this->son; son; son = son->next ) { 00055 son->select( text, sub_nodes ); 00056 } 00057 } 00058 } 00059 00060 00061 void set_node( SuifObject * node ) { tn = node; } 00062 SuifObject *node() { return tn; } 00063 int first_line() { return f_line; } 00064 int last_line() { return l_line; } 00065 void set_first_line( int line ) { f_line = line;} 00066 void set_last_line( int line ) { l_line = line; } 00067 00068 void add_son(code_fragment *f); 00069 code_fragment *lookup(SuifObject *tn); 00070 }; 00071 00072 struct code_range { 00073 int first_line; 00074 int last_line; 00075 00076 code_range(int first, int last) { 00077 first_line = first; 00078 last_line = last; 00079 } 00080 }; 00081 00082 typedef code_range (*map_tn_fn)(SuifObject *tn, void *client_data); 00083 00084 class code_tree { 00085 code_fragment *root; 00086 00087 map_tn_fn map_fn; 00088 void *client_data; 00089 00090 code_fragment *map_to_source( SuifObject* tn, code_fragment* ); 00091 static void create_tags(code_fragment* f, tag_node *parent_tag); 00092 00093 static void print_helper(FILE *fd, code_fragment *f, int depth); 00094 00095 public: 00096 code_tree(); 00097 virtual ~code_tree(); 00098 00099 void *id; // for attaching additional identifying info 00100 00101 code_fragment *get_root() { return root; } 00102 void set_map_fn( map_tn_fn fn, void* data ) { 00103 map_fn = fn; client_data = data; 00104 } 00105 00106 void build( SuifObject* z ); 00107 virtual code_fragment* lookup( SuifObject* tn ); 00108 00109 void create_tags( vtext* text ); 00110 //@@@ void suif_to_code_prop(vprop *suif_prop, vprop *code_prop); 00111 00112 void print( FILE* fd ); 00113 00114 }; 00115 00116 #endif // CODE_TREE_H