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