1//===- InputSectDesc.h ----------------------------------------------------===//
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#ifndef MCLD_SCRIPT_INPUTSECTDESC_H_
10#define MCLD_SCRIPT_INPUTSECTDESC_H_
11
12#include "mcld/Script/ScriptCommand.h"
13#include "mcld/Script/StringList.h"
14
15#include <cassert>
16
17namespace mcld {
18
19class OutputSectDesc;
20class WildcardPattern;
21
22/** \class InputSectDesc
23 *  \brief This class defines the interfaces to input section description.
24 */
25
26class InputSectDesc : public ScriptCommand {
27 public:
28  enum KeepPolicy { Keep, NoKeep };
29
30  struct Spec {
31    bool hasFile() const { return m_pWildcardFile != NULL; }
32    const WildcardPattern& file() const {
33      assert(hasFile());
34      return *m_pWildcardFile;
35    }
36
37    bool hasExcludeFiles() const {
38      return m_pExcludeFiles != NULL && !m_pExcludeFiles->empty();
39    }
40    const StringList& excludeFiles() const {
41      assert(hasExcludeFiles());
42      return *m_pExcludeFiles;
43    }
44
45    bool hasSections() const {
46      return m_pWildcardSections != NULL && !m_pWildcardSections->empty();
47    }
48    const StringList& sections() const {
49      assert(hasSections());
50      return *m_pWildcardSections;
51    }
52
53    bool operator==(const Spec& pRHS) const {
54      /* FIXME: currently I don't check the real content */
55      if (this == &pRHS)
56        return true;
57      if (m_pWildcardFile != pRHS.m_pWildcardFile)
58        return false;
59      if (m_pExcludeFiles != pRHS.m_pExcludeFiles)
60        return false;
61      if (m_pWildcardSections != pRHS.m_pWildcardSections)
62        return false;
63      return true;
64    }
65
66    WildcardPattern* m_pWildcardFile;
67    StringList* m_pExcludeFiles;
68    StringList* m_pWildcardSections;
69  };
70
71 public:
72  InputSectDesc(KeepPolicy pPolicy,
73                const Spec& pSpec,
74                const OutputSectDesc& pOutputDesc);
75  ~InputSectDesc();
76
77  KeepPolicy policy() const { return m_KeepPolicy; }
78
79  const Spec& spec() const { return m_Spec; }
80
81  void dump() const;
82
83  static bool classof(const ScriptCommand* pCmd) {
84    return pCmd->getKind() == ScriptCommand::INPUT_SECT_DESC;
85  }
86
87  void activate(Module& pModule);
88
89 private:
90  KeepPolicy m_KeepPolicy;
91  Spec m_Spec;
92  const OutputSectDesc& m_OutputSectDesc;
93};
94
95}  // namespace mcld
96
97#endif  // MCLD_SCRIPT_INPUTSECTDESC_H_
98