[cfe-commits] r45111 - in /cfe/trunk: Lex/HeaderMap.cpp include/clang/Lex/HeaderMap.h
Chris Lattner
sabre at nondot.org
Mon Dec 17 10:44:10 PST 2007
Author: lattner
Date: Mon Dec 17 12:44:09 2007
New Revision: 45111
URL: http://llvm.org/viewvc/llvm-project?rev=45111&view=rev
Log:
Finish hooking up the scaffolding for headermaps. They can now do everything
except resolve lookups.
Modified:
cfe/trunk/Lex/HeaderMap.cpp
cfe/trunk/include/clang/Lex/HeaderMap.h
Modified: cfe/trunk/Lex/HeaderMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/HeaderMap.cpp?rev=45111&r1=45110&r2=45111&view=diff
==============================================================================
--- cfe/trunk/Lex/HeaderMap.cpp (original)
+++ cfe/trunk/Lex/HeaderMap.cpp Mon Dec 17 12:44:09 2007
@@ -44,11 +44,11 @@
unsigned FileSize = FE->getSize();
if (FileSize <= sizeof(HMapHeader)) return 0;
- llvm::scoped_ptr<const llvm::MemoryBuffer> File(
+ llvm::scoped_ptr<const llvm::MemoryBuffer> FileBuffer(
llvm::MemoryBuffer::getFile(FE->getName(), strlen(FE->getName()), 0,
FE->getSize()));
- if (File == 0) return 0; // Unreadable file?
- const char *FileStart = File->getBufferStart();
+ if (FileBuffer == 0) return 0; // Unreadable file?
+ const char *FileStart = FileBuffer->getBufferStart();
// We know the file is at least as big as the header, check it now.
const HMapHeader *Header = reinterpret_cast<const HMapHeader*>(FileStart);
@@ -65,8 +65,21 @@
NeedsByteSwap = true; // Mixed endianness headermap.
else
return 0; // Not a header map.
-
- return 0;
+
+ // Okay, everything looks good, create the header map.
+ HeaderMap *NewHM = new HeaderMap(FileBuffer.get(), NeedsByteSwap);
+ FileBuffer.reset(); // Don't deallocate the buffer on return.
+ return NewHM;
+}
+
+HeaderMap::~HeaderMap() {
+ delete FileBuffer;
+}
+
+
+/// getFileName - Return the filename of the headermap.
+const char *HeaderMap::getFileName() const {
+ return FileBuffer->getBufferIdentifier();
}
/// LookupFile - Check to see if the specified relative filename is located in
Modified: cfe/trunk/include/clang/Lex/HeaderMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderMap.h?rev=45111&r1=45110&r2=45111&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderMap.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderMap.h Mon Dec 17 12:44:09 2007
@@ -14,8 +14,9 @@
#ifndef LLVM_CLANG_LEX_HEADERMAP_H
#define LLVM_CLANG_LEX_HEADERMAP_H
-#include <string>
-
+namespace llvm {
+ class MemoryBuffer;
+}
namespace clang {
class FileEntry;
class FileManager;
@@ -27,7 +28,16 @@
class HeaderMap {
HeaderMap(const HeaderMap&); // DO NOT IMPLEMENT
void operator=(const HeaderMap&); // DO NOT IMPLEMENT
+
+ const llvm::MemoryBuffer *FileBuffer;
+ bool NeedsBSwap;
+
+ HeaderMap(const llvm::MemoryBuffer *File, bool BSwap)
+ : FileBuffer(File), NeedsBSwap(BSwap) {
+ }
public:
+ ~HeaderMap();
+
/// HeaderMap::Create - This attempts to load the specified file as a header
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
static const HeaderMap *Create(const FileEntry *FE);
@@ -38,10 +48,7 @@
FileManager &FM) const;
/// getFileName - Return the filename of the headermap.
- const char *getFileName() const {
- return "";
- }
-
+ const char *getFileName() const;
};
} // end namespace clang.
More information about the cfe-commits
mailing list