summaryrefslogtreecommitdiff
path: root/src/parser/memory_mapped_input_buffer.h
diff options
context:
space:
mode:
authorChristopher L. Conway <christopherleeconway@gmail.com>2010-03-30 20:22:33 +0000
committerChristopher L. Conway <christopherleeconway@gmail.com>2010-03-30 20:22:33 +0000
commit8730e9320a833a9eb0e65074f9988950b7424c0c (patch)
tree1cb09404256743e208fece079ba473595e05edcd /src/parser/memory_mapped_input_buffer.h
parent8c87c05ac56a5f29b2ae1e658f2d7d3b7b588163 (diff)
Merging from branches/antlr3 (r246:354)
Diffstat (limited to 'src/parser/memory_mapped_input_buffer.h')
-rw-r--r--src/parser/memory_mapped_input_buffer.h64
1 files changed, 8 insertions, 56 deletions
diff --git a/src/parser/memory_mapped_input_buffer.h b/src/parser/memory_mapped_input_buffer.h
index e1639a072..88ba2183a 100644
--- a/src/parser/memory_mapped_input_buffer.h
+++ b/src/parser/memory_mapped_input_buffer.h
@@ -14,69 +14,21 @@
#ifndef __CVC4__PARSER__MEMORY_MAPPED_INPUT_BUFFER_H
#define __CVC4__PARSER__MEMORY_MAPPED_INPUT_BUFFER_H
-#include <cstdio>
-#include <cerrno>
-
-#include <fcntl.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <sys/mman.h>
-#include <sys/stat.h>
-
-#include <antlr/InputBuffer.hpp>
-
-#include "util/Assert.h"
-#include "util/exception.h"
+#include <antlr3input.h>
+#include <string>
namespace CVC4 {
namespace parser {
-class MemoryMappedInputBuffer : public antlr::InputBuffer {
-
-public:
- MemoryMappedInputBuffer(const std::string& filename) {
- struct stat st;
- if( stat(filename.c_str(), &st) == -1 ) {
- char buf[80];
- const char* errMsg = strerror_r(errno, buf, sizeof(buf));
- throw Exception("unable to stat() file `" + filename + "': " + errMsg);
- }
- d_size = st.st_size;
-
- int fd = open(filename.c_str(), O_RDONLY);
- if( fd == -1 ) {
- char buf[80];
- const char* errMsg = strerror_r(errno, buf, sizeof(buf));
- throw Exception("unable to fopen() file `" + filename + "': " + errMsg);
- }
-
- d_start = static_cast< const char * >(
- mmap( 0, d_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0 ) );
- if( intptr_t( d_start ) == -1 ) {
- char buf[80];
- const char* errMsg = strerror_r(errno, buf, sizeof(buf));
- throw Exception("unable to mmap() file `" + filename + "': " + errMsg);
- }
- d_cur = d_start;
- d_end = d_start + d_size;
- }
+extern "C" {
- ~MemoryMappedInputBuffer() {
- munmap((void*) d_start, d_size);
- }
+pANTLR3_INPUT_STREAM
+MemoryMappedInputBufferNew(const std::string& filename);
- inline int getChar() {
- Assert( d_cur >= d_start && d_cur <= d_end );
- return d_cur == d_end ? EOF : *d_cur++;
- }
+}
-private:
- unsigned long int d_size;
- const char *d_start, *d_end, *d_cur;
-};
+}
+}
-}/* CVC4::parser namespace */
-}/* CVC4 namespace */
#endif /* __CVC4__PARSER__MEMORY_MAPPED_INPUT_BUFFER_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback