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 using 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 {
23 if (this == &pTree)
24 return *this;
25
26 if (!pTree.empty()) {
27 pMover.connect(pRoot, iterator(pTree.m_Root.node.right));
28 BinaryTreeBase<Input>::m_Root.summon(
29 pTree.BinaryTreeBase<Input>::m_Root);
30 BinaryTreeBase<Input>::m_Root.delegate(pTree.m_Root);
31 pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node;
32 }
33 return *this;
34 }
35
enterGroup(TreeIteratorBase pRoot,const InputTree::Mover & pMover)36 InputTree& InputTree::enterGroup(TreeIteratorBase pRoot,
37 const InputTree::Mover& pMover)
38 {
39 NodeBase* node = createNode();
40 pMover.connect(pRoot, iterator(node));
41 return *this;
42 }
43
insert(TreeIteratorBase pRoot,const InputTree::Mover & pMover,mcld::Input & pInput)44 InputTree& InputTree::insert(TreeIteratorBase pRoot,
45 const InputTree::Mover& pMover,
46 mcld::Input& pInput)
47 {
48 BinaryTree<Input>::node_type* node = createNode();
49 node->data = &pInput;
50 pMover.connect(pRoot, iterator(node));
51 return *this;
52 }
53
54 //===----------------------------------------------------------------------===//
55 // non-member functions
56 //===----------------------------------------------------------------------===//
isGroup(const InputTree::iterator & pos)57 bool mcld::isGroup(const InputTree::iterator& pos)
58 {
59 return !pos.hasData() && !pos.isRoot();
60 }
61
isGroup(const InputTree::const_iterator & pos)62 bool mcld::isGroup(const InputTree::const_iterator& pos)
63 {
64 return !pos.hasData() && !pos.isRoot();
65 }
66
isGroup(const InputTree::dfs_iterator & pos)67 bool mcld::isGroup(const InputTree::dfs_iterator& pos)
68 {
69 return !pos.hasData() && !pos.isRoot();
70 }
71
isGroup(const InputTree::const_dfs_iterator & pos)72 bool mcld::isGroup(const InputTree::const_dfs_iterator& pos)
73 {
74 return !pos.hasData() && !pos.isRoot();
75 }
76
isGroup(const InputTree::bfs_iterator & pos)77 bool mcld::isGroup(const InputTree::bfs_iterator& pos)
78 {
79 return !pos.hasData() && !pos.isRoot();
80 }
81
isGroup(const InputTree::const_bfs_iterator & pos)82 bool mcld::isGroup(const InputTree::const_bfs_iterator& pos)
83 {
84 return !pos.hasData() && !pos.isRoot();
85 }
86
87