lib: remove NativeFileCapable
authorJean Privat <jean@pryen.org>
Thu, 23 Feb 2012 17:50:45 +0000 (12:50 -0500)
committerJean Privat <jean@pryen.org>
Mon, 27 Feb 2012 21:19:50 +0000 (16:19 -0500)
Methods are moved as constructors in the NativeFile extern class.

Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/file.nit
lib/standard/file_nit.h

index de73438..4871113 100644 (file)
@@ -51,7 +51,6 @@ end
 # File Abstract Stream
 class FStream
        super IOS
-       super NativeFileCapable
        # The path of the file.
        readable var _path: nullable String = null
 
@@ -73,7 +72,7 @@ class IFStream
        fun reopen
        do
                if not eof then close
-               _file = io_open_read(_path.to_cstring)
+               _file = new NativeFile.io_open_read(_path.to_cstring)
                _end_reached = false
                _buffer_pos = 0
                _buffer.clear
@@ -104,7 +103,7 @@ class IFStream
        do
                _path = path
                prepare_buffer(10)
-               _file = io_open_read(_path.to_cstring)
+               _file = new NativeFile.io_open_read(_path.to_cstring)
                assert cant_open_file: _file != null
        end
 
@@ -148,7 +147,7 @@ class OFStream
        # Open the file at `path' for writing.
        init open(path: String)
        do
-               _file = io_open_write(path.to_cstring)
+               _file = new NativeFile.io_open_write(path.to_cstring)
                assert cant_open_file: _file != null
                _path = path
                _writable = true
@@ -163,7 +162,7 @@ end
 class Stdin
        super IFStream
        private init do
-               _file = native_stdin
+               _file = new NativeFile.native_stdin
                _path = "/dev/stdin"
                prepare_buffer(1)
        end
@@ -172,7 +171,7 @@ end
 class Stdout
        super OFStream
        private init do
-               _file = native_stdout
+               _file = new NativeFile.native_stdout
                _path = "/dev/stdout"
                _writable = true
        end
@@ -181,7 +180,7 @@ end
 class Stderr
        super OFStream
        private init do
-               _file = native_stderr
+               _file = new NativeFile.native_stderr
                _path = "/dev/stderr"
                _writable = true
        end
@@ -333,14 +332,12 @@ private extern NativeFile
        fun io_write(buf: NativeString, len: Int): Int is extern "file_NativeFile_NativeFile_io_write_2"
        fun io_close: Int is extern "file_NativeFile_NativeFile_io_close_0"
        fun file_stat: FileStat is extern "file_NativeFile_NativeFile_file_stat_0"
-end
 
-private interface NativeFileCapable
-       fun io_open_read(path: NativeString): NativeFile is extern "file_NativeFileCapable_NativeFileCapable_io_open_read_1"
-       fun io_open_write(path: NativeString): NativeFile is extern "file_NativeFileCapable_NativeFileCapable_io_open_write_1"
-       fun native_stdin: NativeFile is extern "file_NativeFileCapable_NativeFileCapable_native_stdin_0"
-       fun native_stdout: NativeFile is extern "file_NativeFileCapable_NativeFileCapable_native_stdout_0"
-       fun native_stderr: NativeFile is extern "file_NativeFileCapable_NativeFileCapable_native_stderr_0"
+       new io_open_read(path: NativeString) is extern "file_NativeFileCapable_NativeFileCapable_io_open_read_1"
+       new io_open_write(path: NativeString) is extern "file_NativeFileCapable_NativeFileCapable_io_open_write_1"
+       new native_stdin is extern "file_NativeFileCapable_NativeFileCapable_native_stdin_0"
+       new native_stdout is extern "file_NativeFileCapable_NativeFileCapable_native_stdout_0"
+       new native_stderr is extern "file_NativeFileCapable_NativeFileCapable_native_stderr_0"
 end
 
 # Standard input.
index de67757..6fa2a0e 100644 (file)
@@ -29,12 +29,12 @@ extern int string_NativeString_NativeString_file_delete_0(char *f);
 #define file_NativeFile_NativeFile_io_write_2(p, b, l) fwrite((b), 1, (l), (FILE*)(p))
 #define file_NativeFile_NativeFile_io_close_0(self) fclose((FILE*)(self))
 
-#define file_NativeFileCapable_NativeFileCapable_io_open_read_1(self, p0) fopen((p0), "r")
+#define file_NativeFileCapable_NativeFileCapable_io_open_read_1(p0) fopen((p0), "r")
 
-#define file_NativeFileCapable_NativeFileCapable_io_open_write_1(self, p0) fopen((p0), "w")
-#define file_NativeFileCapable_NativeFileCapable_native_stdin_0(self) stdin
-#define file_NativeFileCapable_NativeFileCapable_native_stdout_0(self) stdout
-#define file_NativeFileCapable_NativeFileCapable_native_stderr_0(self) stderr
+#define file_NativeFileCapable_NativeFileCapable_io_open_write_1(p0) fopen((p0), "w")
+#define file_NativeFileCapable_NativeFileCapable_native_stdin_0() stdin
+#define file_NativeFileCapable_NativeFileCapable_native_stdout_0() stdout
+#define file_NativeFileCapable_NativeFileCapable_native_stderr_0() stderr
 #define file_FileStat_FileStat_mode_0(self) (((struct stat*)self)->st_mode)
 #define file_FileStat_FileStat_atime_0(self) (((struct stat*)self)->st_atime)
 #define file_FileStat_FileStat_ctime_0(self) (((struct stat*)self)->st_ctime)