Remove declare but not implemented methods.
[oota-llvm.git] / include / llvm / Object / Archive.h
1 //===- Archive.h - ar archive file format -----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the ar archive file format class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_OBJECT_ARCHIVE_H
15 #define LLVM_OBJECT_ARCHIVE_H
16
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Object/Binary.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/MemoryBuffer.h"
21
22 namespace llvm {
23 namespace object {
24 struct ArchiveMemberHeader {
25   char Name[16];
26   char LastModified[12];
27   char UID[6];
28   char GID[6];
29   char AccessMode[8];
30   char Size[10]; ///< Size of data, not including header or padding.
31   char Terminator[2];
32
33   /// Get the name without looking up long names.
34   llvm::StringRef getName() const;
35
36   uint64_t getSize() const;
37 };
38
39 static const ArchiveMemberHeader *ToHeader(const char *base) {
40   return reinterpret_cast<const ArchiveMemberHeader *>(base);
41 }
42
43 class Archive : public Binary {
44   virtual void anchor();
45 public:
46   class Child {
47     const Archive *Parent;
48     /// \brief Includes header but not padding byte.
49     StringRef Data;
50     /// \brief Offset from Data to the start of the file.
51     uint16_t StartOfFile;
52
53   public:
54     Child(const Archive *p, StringRef d);
55
56     bool operator ==(const Child &other) const {
57       return (Parent == other.Parent) && (Data.begin() == other.Data.begin());
58     }
59
60     bool operator <(const Child &other) const {
61       return Data.begin() < other.Data.begin();
62     }
63
64     Child getNext() const;
65
66     error_code getName(StringRef &Result) const;
67     StringRef getRawName() const { return ToHeader(Data.data())->getName(); }
68     /// \return the size of the archive member without the header or padding.
69     uint64_t getSize() const { return Data.size() - StartOfFile; }
70
71     StringRef getBuffer() const {
72       return StringRef(Data.data() + StartOfFile, getSize());
73     }
74
75     error_code getMemoryBuffer(OwningPtr<MemoryBuffer> &Result,
76                                bool FullPath = false) const;
77
78     error_code getAsBinary(OwningPtr<Binary> &Result) const;
79   };
80
81   class child_iterator {
82     Child child;
83   public:
84     child_iterator() : child(Child(0, StringRef())) {}
85     child_iterator(const Child &c) : child(c) {}
86     const Child* operator->() const {
87       return &child;
88     }
89
90     bool operator==(const child_iterator &other) const {
91       return child == other.child;
92     }
93
94     bool operator!=(const child_iterator &other) const {
95       return !(*this == other);
96     }
97
98     bool operator <(const child_iterator &other) const {
99       return child < other.child;
100     }
101
102     child_iterator& operator++() {  // Preincrement
103       child = child.getNext();
104       return *this;
105     }
106   };
107
108   class Symbol {
109     const Archive *Parent;
110     uint32_t SymbolIndex;
111     uint32_t StringIndex; // Extra index to the string.
112
113   public:
114     bool operator ==(const Symbol &other) const {
115       return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
116     }
117
118     Symbol(const Archive *p, uint32_t symi, uint32_t stri)
119       : Parent(p)
120       , SymbolIndex(symi)
121       , StringIndex(stri) {}
122     error_code getName(StringRef &Result) const;
123     error_code getMember(child_iterator &Result) const;
124     Symbol getNext() const;
125   };
126
127   class symbol_iterator {
128     Symbol symbol;
129   public:
130     symbol_iterator(const Symbol &s) : symbol(s) {}
131     const Symbol *operator->() const {
132       return &symbol;
133     }
134
135     bool operator==(const symbol_iterator &other) const {
136       return symbol == other.symbol;
137     }
138
139     bool operator!=(const symbol_iterator &other) const {
140       return !(*this == other);
141     }
142
143     symbol_iterator& operator++() {  // Preincrement
144       symbol = symbol.getNext();
145       return *this;
146     }
147   };
148
149   Archive(MemoryBuffer *source, error_code &ec);
150
151   enum Kind {
152     K_GNU,
153     K_BSD,
154     K_COFF
155   };
156
157   Kind kind() const { 
158     return Format;
159   }
160
161   child_iterator begin_children(bool skip_internal = true) const;
162   child_iterator end_children() const;
163
164   symbol_iterator begin_symbols() const;
165   symbol_iterator end_symbols() const;
166
167   // Cast methods.
168   static inline bool classof(Binary const *v) {
169     return v->isArchive();
170   }
171
172   // check if a symbol is in the archive
173   child_iterator findSym(StringRef name) const;
174
175 private:
176   child_iterator SymbolTable;
177   child_iterator StringTable;
178   Kind Format;
179 };
180
181 }
182 }
183
184 #endif