• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- WildcardPattern.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/Script/WildcardPattern.h"
10 
11 #include "mcld/Support/GCFactory.h"
12 #include "mcld/Support/raw_ostream.h"
13 
14 #include <llvm/Support/ManagedStatic.h>
15 #include <cassert>
16 
17 namespace mcld {
18 
19 typedef GCFactory<WildcardPattern, MCLD_SYMBOLS_PER_INPUT>
20     WildcardPatternFactory;
21 static llvm::ManagedStatic<WildcardPatternFactory> g_WildcardPatternFactory;
22 
23 //===----------------------------------------------------------------------===//
24 // WildcardPattern
25 //===----------------------------------------------------------------------===//
WildcardPattern()26 WildcardPattern::WildcardPattern() : m_bIsPrefix(false) {
27 }
28 
WildcardPattern(const std::string & pPattern,SortPolicy pPolicy)29 WildcardPattern::WildcardPattern(const std::string& pPattern,
30                                  SortPolicy pPolicy)
31     : StrToken(StrToken::Wildcard, pPattern), m_SortPolicy(pPolicy) {
32   if (pPattern.find_first_of('*') == (pPattern.size() - 1))
33     m_bIsPrefix = true;
34   else
35     m_bIsPrefix = false;
36 }
37 
~WildcardPattern()38 WildcardPattern::~WildcardPattern() {
39 }
40 
prefix() const41 llvm::StringRef WildcardPattern::prefix() const {
42   if (isPrefix())
43     return llvm::StringRef(name().c_str(), name().size() - 1);
44 
45   return llvm::StringRef(name());
46 }
47 
create(const std::string & pPattern,SortPolicy pPolicy)48 WildcardPattern* WildcardPattern::create(const std::string& pPattern,
49                                          SortPolicy pPolicy) {
50   WildcardPattern* result = g_WildcardPatternFactory->allocate();
51   new (result) WildcardPattern(pPattern, pPolicy);
52   return result;
53 }
54 
destroy(WildcardPattern * & pWildcardPattern)55 void WildcardPattern::destroy(WildcardPattern*& pWildcardPattern) {
56   g_WildcardPatternFactory->destroy(pWildcardPattern);
57   g_WildcardPatternFactory->deallocate(pWildcardPattern);
58   pWildcardPattern = NULL;
59 }
60 
clear()61 void WildcardPattern::clear() {
62   g_WildcardPatternFactory->clear();
63 }
64 
65 }  // namespace mcld
66