• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- MCLDInputTree.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/MC/MCLDInputTree.h"
10 #include "mcld/MC/InputFactory.h"
11 
12 using namespace mcld;
13 
14 InputTree::Succeeder InputTree::Afterward;
15 InputTree::Includer  InputTree::Downward;
16 
17 //===----------------------------------------------------------------------===//
18 // InputTree
InputTree(InputFactory & pInputFactory)19 InputTree::InputTree(InputFactory& pInputFactory)
20   : m_FileFactory(pInputFactory) {
21 }
22 
~InputTree()23 InputTree::~InputTree()
24 {
25 }
26 
merge(InputTree::iterator pPosition,const InputTree::Connector & pConnector,InputTree & pTree)27 InputTree& InputTree::merge(InputTree::iterator pPosition,
28                             const InputTree::Connector& pConnector,
29                             InputTree& pTree)
30 {
31   if (this == &pTree)
32     return *this;
33 
34   if (!pTree.empty()) {
35     pConnector.connect(pPosition, iterator(pTree.m_Root.node.right));
36     BinaryTreeBase<Input>::m_Root.summon(
37         pTree.BinaryTreeBase<Input>::m_Root);
38     BinaryTreeBase<Input>::m_Root.delegate(pTree.m_Root);
39     pTree.m_Root.node.left = pTree.m_Root.node.right = &pTree.m_Root.node;
40   }
41   return *this;
42 }
43 
insert(InputTree::iterator pPosition,const InputTree::Connector & pConnector,const std::string & pNamespec,const sys::fs::Path & pPath,unsigned int pType)44 InputTree& InputTree::insert(InputTree::iterator pPosition,
45                              const InputTree::Connector& pConnector,
46                              const std::string& pNamespec,
47                              const sys::fs::Path& pPath,
48                              unsigned int pType)
49 {
50   BinaryTree<Input>::node_type* node = createNode();
51   node->data = m_FileFactory.produce(pNamespec, pPath, pType);
52   pConnector.connect(pPosition, iterator(node));
53   return *this;
54 }
55 
enterGroup(InputTree::iterator pPosition,const InputTree::Connector & pConnector)56 InputTree& InputTree::enterGroup(InputTree::iterator pPosition,
57                                  const InputTree::Connector& pConnector)
58 {
59   NodeBase* node = createNode();
60   pConnector.connect(pPosition, iterator(node));
61   return *this;
62 }
63 
insert(InputTree::iterator pPosition,const InputTree::Connector & pConnector,const mcld::Input & pInput)64 InputTree& InputTree::insert(InputTree::iterator pPosition,
65                              const InputTree::Connector& pConnector,
66                              const mcld::Input& pInput)
67 {
68   BinaryTree<Input>::node_type* node = createNode();
69   node->data = const_cast<mcld::Input*>(&pInput);
70   pConnector.connect(pPosition, iterator(node));
71   return *this;
72 }
73 
74 
75 
76 //===----------------------------------------------------------------------===//
77 // non-member functions
isGroup(const InputTree::iterator & pos)78 bool mcld::isGroup(const InputTree::iterator& pos)
79 {
80   return !pos.hasData();
81 }
82 
isGroup(const InputTree::const_iterator & pos)83 bool mcld::isGroup(const InputTree::const_iterator& pos)
84 {
85   return !pos.hasData();
86 }
87 
isGroup(const InputTree::dfs_iterator & pos)88 bool mcld::isGroup(const InputTree::dfs_iterator& pos)
89 {
90   return !pos.hasData();
91 }
92 
isGroup(const InputTree::const_dfs_iterator & pos)93 bool mcld::isGroup(const InputTree::const_dfs_iterator& pos)
94 {
95   return !pos.hasData();
96 }
97 
isGroup(const InputTree::bfs_iterator & pos)98 bool mcld::isGroup(const InputTree::bfs_iterator& pos)
99 {
100   return !pos.hasData();
101 }
102 
isGroup(const InputTree::const_bfs_iterator & pos)103 bool mcld::isGroup(const InputTree::const_bfs_iterator& pos)
104 {
105   return !pos.hasData();
106 }
107 
108