3 #include <fridh/symbol.hpp>
7 symbol_tree_node::symbol_tree_node():
8 type(symbol::uninitialised
),
11 //std::cout << "new symbol_tree_node default " << (void *)this << std::endl;
14 symbol_tree_node::symbol_tree_node(symbol_tree_node
const & other
)
19 symbol_tree_node::symbol_tree_node(symbol::type type
):
23 //std::cout << "new symbol_tree_node " << (void *)this << std::endl;
27 case symbol::function
:
28 function_pointer
= new function
;
31 case symbol::class_symbol
:
32 class_pointer
= new class_type
;
37 symbol_tree_node::~symbol_tree_node()
42 symbol_tree_node
& symbol_tree_node::operator=(symbol_tree_node
const & other
)
49 void symbol_tree_node::copy(symbol_tree_node
const & other
)
51 //std::cout << "symbol_tree_node " << (void *)this << " from " << (void *)&other << std::endl;
54 parent
= other
.parent
;
56 for(node_children::const_iterator i
= other
.children
.begin(), end
= other
.children
.end(); i
!= end
; i
++)
58 symbol_tree_node
* & node_pointer
= children
[i
->first
];
59 node_pointer
= new symbol_tree_node(*i
->second
);
60 node_pointer
->parent
= this;
63 #define COPY_MEMBER(type, member_type, member) \
65 member = new member_type(*other.member); \
70 COPY_MEMBER(function
, function
, function_pointer
);
71 COPY_MEMBER(class_symbol
, class_type
, class_pointer
);
72 COPY_MEMBER(module
, module
, module_pointer
);
79 void symbol_tree_node::destroy()
81 //std::cout << "~symbol_tree_node " << (void *)this << std::endl;
83 for(node_children::iterator i
= children
.begin(), end
= children
.end(); i
!= end
; i
++)
86 #define DELETE_MEMBER(type, member) \
93 DELETE_MEMBER(function
, function_pointer
);
94 DELETE_MEMBER(class_symbol
, class_pointer
);
95 DELETE_MEMBER(module
, module_pointer
);
98 type
= symbol::uninitialised
;
104 bool symbol_tree_node::exists(std::string
const & name
)
106 //std::cout << "exists " << (void *)this << std::endl;
108 node_children::iterator iterator
= children
.find(name
);
109 return iterator
!= children
.end();
112 bool symbol_tree_node::find_entity(std::string
const & name
, symbol_tree_node
* & output
)
114 node_children::iterator iterator
= children
.find(name
);
115 if(iterator
== children
.end())
119 return parent
->find_entity(name
, output
);
122 output
= iterator
->second
;