llvm.org GIT mirror llvm / c5f8757
Add getHeader helper and move ToHeader to the cpp file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185933 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
2 changed file(s) with 11 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
3535 uint64_t getSize() const;
3636 };
3737
38 static const ArchiveMemberHeader *ToHeader(const char *base) {
39 return reinterpret_cast(base);
40 }
41
4238 class Archive : public Binary {
4339 virtual void anchor();
4440 public:
4844 StringRef Data;
4945 /// \brief Offset from Data to the start of the file.
5046 uint16_t StartOfFile;
47
48 const ArchiveMemberHeader *getHeader() const {
49 return reinterpret_cast(Data.data());
50 }
5151
5252 public:
5353 Child(const Archive *Parent, const char *Start);
6363 Child getNext() const;
6464
6565 error_code getName(StringRef &Result) const;
66 StringRef getRawName() const { return ToHeader(Data.data())->getName(); }
66 StringRef getRawName() const { return getHeader()->getName(); }
6767 /// \return the size of the archive member without the header or padding.
6868 uint64_t getSize() const { return Data.size() - StartOfFile; }
6969
6060 return ret;
6161 }
6262
63 static const ArchiveMemberHeader *toHeader(const char *base) {
64 return reinterpret_cast(base);
65 }
66
6367 Archive::Child::Child(const Archive *Parent, const char *Start)
6468 : Parent(Parent) {
6569 if (!Start)
6670 return;
6771
68 const ArchiveMemberHeader *Header = ToHeader(Start);
72 const ArchiveMemberHeader *Header = toHeader(Start);
6973 Data = StringRef(Start, sizeof(ArchiveMemberHeader) + Header->getSize());
7074
7175 // Setup StartOfFile and PaddingBytes.
269273 const char *Loc = Data->getBufferStart() + strlen(Magic);
270274 Child c(this, Loc);
271275 // Skip internals at the beginning of an archive.
272 if (skip_internal && isInternalMember(*ToHeader(Loc)))
276 if (skip_internal && isInternalMember(*toHeader(Loc)))
273277 return c.getNext();
274278 return c;
275279 }