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