1 //===- InputTree.cpp ------------------------------------------------------===//
2 //
3 // The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #include "mcld/InputTree.h"
10
11 namespace mcld {
12
13 InputTree::Succeeder InputTree::Afterward;
14 InputTree::Includer InputTree::Downward;
15
16 //===----------------------------------------------------------------------===//
17 // InputTree
18 //===----------------------------------------------------------------------===//
merge(TreeIteratorBase pRoot,const InputTree::Mover & pMover,InputTree & pTree)19 InputTree& InputTree::merge(TreeIteratorBase pRoot,
20 const InputTree::Mover& pMover,
21 InputTree& pTree) {
22 if (this == &pTree)
23 return *this;
24
25 if (!pTree.empty()) {
26 pMover.connect(pRoot, pTree.m_Root.node.right);
27 BinaryTreeBase<Input>::m_Root.summon(pTree.BinaryTreeBase<Input>::m_Root);
28 BinaryTreeBase<Input>::m_Root.delegate(pTree.m_Root);
29 pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node;
30 }
31 return *this;
32 }
33
enterGroup(TreeIteratorBase pRoot,const InputTree::Mover & pMover)34 InputTree& InputTree::enterGroup(TreeIteratorBase pRoot,
35 const InputTree::Mover& pMover) {
36 NodeBase* node = createNode();
37 pMover.connect(pRoot, node);
38 return *this;
39 }
40
insert(TreeIteratorBase pRoot,const InputTree::Mover & pMover,Input & pInput)41 InputTree& InputTree::insert(TreeIteratorBase pRoot,
42 const InputTree::Mover& pMover,
43 Input& pInput) {
44 BinaryTree<Input>::node_type* node = createNode();
45 node->data = &pInput;
46 pMover.connect(pRoot, node);
47 return *this;
48 }
49
50 //===----------------------------------------------------------------------===//
51 // non-member functions
52 //===----------------------------------------------------------------------===//
isGroup(const InputTree::iterator & pos)53 bool isGroup(const InputTree::iterator& pos) {
54 return !pos.hasData() && !pos.isRoot();
55 }
56
isGroup(const InputTree::const_iterator & pos)57 bool isGroup(const InputTree::const_iterator& pos) {
58 return !pos.hasData() && !pos.isRoot();
59 }
60
isGroup(const InputTree::dfs_iterator & pos)61 bool isGroup(const InputTree::dfs_iterator& pos) {
62 return !pos.hasData() && !pos.isRoot();
63 }
64
isGroup(const InputTree::const_dfs_iterator & pos)65 bool isGroup(const InputTree::const_dfs_iterator& pos) {
66 return !pos.hasData() && !pos.isRoot();
67 }
68
isGroup(const InputTree::bfs_iterator & pos)69 bool isGroup(const InputTree::bfs_iterator& pos) {
70 return !pos.hasData() && !pos.isRoot();
71 }
72
isGroup(const InputTree::const_bfs_iterator & pos)73 bool isGroup(const InputTree::const_bfs_iterator& pos) {
74 return !pos.hasData() && !pos.isRoot();
75 }
76
77 } // namespace mcld
78