From: Alexis Laferrière Date: Mon, 25 May 2015 19:29:35 +0000 (-0400) Subject: lib/standard: update to use `self` in C code X-Git-Tag: v0.7.5~19^2~7 X-Git-Url: http://nitlanguage.org lib/standard: update to use `self` in C code Signed-off-by: Alexis Laferrière --- diff --git a/lib/standard/bitset.nit b/lib/standard/bitset.nit index 32559d5..c5ed9df 100644 --- a/lib/standard/bitset.nit +++ b/lib/standard/bitset.nit @@ -1,4 +1,4 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). +# This file is part of NIT (http://www.nitlanguage.org). # # Copyright 2014 Julien Pagès # @@ -6,7 +6,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -36,9 +36,9 @@ redef class Int assert(index >= 0 && index < 32); if(value == 1) - return recv | (1 << index); + return self | (1 << index); else - return recv & ~(1 << index); + return self & ~(1 << index); `} # Returns the i-bit value of `self` @@ -50,7 +50,7 @@ redef class Int int op = 1 << index; - if((recv & op) == 0) + if((self & op) == 0) return 0; else return 1; @@ -84,7 +84,7 @@ redef class Int { for(i=bound; i>0; i/=2) { - if(recv & i) + if(self & i) count++; } } @@ -92,7 +92,7 @@ redef class Int { for(i=bound; i>0; i/=2) { - if(!(recv & i)) + if(!(self & i)) count++; } } @@ -109,7 +109,7 @@ redef class Int long int msb = 1L << 31; int pos = 31; - while(msb > 0 && !(recv & msb)) + while(msb > 0 && !(self & msb)) { msb /= 2; pos--; diff --git a/lib/standard/file.nit b/lib/standard/file.nit index 3548a25..5a89d10 100644 --- a/lib/standard/file.nit +++ b/lib/standard/file.nit @@ -1056,12 +1056,12 @@ redef class NativeString struct stat* stat_element; int res; stat_element = malloc(sizeof(struct stat)); - res = lstat(recv, stat_element); + res = lstat(self, stat_element); if (res == -1) return NULL; return stat_element; `} private fun file_mkdir: Bool is extern "string_NativeString_NativeString_file_mkdir_0" - private fun rmdir: Bool `{ return !rmdir(recv); `} + private fun rmdir: Bool `{ return !rmdir(self); `} private fun file_delete: Bool is extern "string_NativeString_NativeString_file_delete_0" private fun file_chdir: Bool is extern "string_NativeString_NativeString_file_chdir_0" private fun file_realpath: NativeString is extern "file_NativeString_realpath" @@ -1081,19 +1081,19 @@ private extern class NativeFileStat `{ struct stat * `} fun size: Int is extern "file_FileStat_FileStat_size_0" # Returns true if it is a regular file (not a device file, pipe, sockect, ...) - fun is_reg: Bool `{ return S_ISREG(recv->st_mode); `} + fun is_reg: Bool `{ return S_ISREG(self->st_mode); `} # Returns true if it is a directory - fun is_dir: Bool `{ return S_ISDIR(recv->st_mode); `} + fun is_dir: Bool `{ return S_ISDIR(self->st_mode); `} # Returns true if it is a character device - fun is_chr: Bool `{ return S_ISCHR(recv->st_mode); `} + fun is_chr: Bool `{ return S_ISCHR(self->st_mode); `} # Returns true if it is a block device - fun is_blk: Bool `{ return S_ISBLK(recv->st_mode); `} + fun is_blk: Bool `{ return S_ISBLK(self->st_mode); `} # Returns true if the type is fifo - fun is_fifo: Bool `{ return S_ISFIFO(recv->st_mode); `} + fun is_fifo: Bool `{ return S_ISFIFO(self->st_mode); `} # Returns true if the type is a link - fun is_lnk: Bool `{ return S_ISLNK(recv->st_mode); `} + fun is_lnk: Bool `{ return S_ISLNK(self->st_mode); `} # Returns true if the type is a socket - fun is_sock: Bool `{ return S_ISSOCK(recv->st_mode); `} + fun is_sock: Bool `{ return S_ISSOCK(self->st_mode); `} end # Instance of this class are standard FILE * pointers @@ -1102,11 +1102,11 @@ private extern class NativeFile `{ FILE* `} fun io_write(buf: NativeString, len: Int): Int is extern "file_NativeFile_NativeFile_io_write_2" fun write_byte(value: Int): Int `{ unsigned char b = (unsigned char)value; - return fwrite(&b, 1, 1, recv); + return fwrite(&b, 1, 1, self); `} fun io_close: Int is extern "file_NativeFile_NativeFile_io_close_0" fun file_stat: NativeFileStat is extern "file_NativeFile_NativeFile_file_stat_0" - fun fileno: Int `{ return fileno(recv); `} + fun fileno: Int `{ return fileno(self); `} # Flushes the buffer, forcing the write operation fun flush: Int is extern "fflush" # Used to specify how the buffering will be handled for the current stream. @@ -1126,12 +1126,12 @@ private extern class NativeDir `{ DIR* `} new opendir(path: NativeString) `{ return opendir(path); `} # Close a directory - fun closedir `{ closedir(recv); `} + fun closedir `{ closedir(self); `} # Read the next directory entry fun readdir: NativeString `{ struct dirent *de; - de = readdir(recv); + de = readdir(self); if (!de) return NULL; return de->d_name; `} diff --git a/lib/standard/math.nit b/lib/standard/math.nit index 9e1744f..8b5fecb 100644 --- a/lib/standard/math.nit +++ b/lib/standard/math.nit @@ -47,7 +47,7 @@ redef class Int # Returns the square root of `self` # # assert 16.sqrt == 4 - fun sqrt: Int `{ return sqrt(recv); `} + fun sqrt: Int `{ return sqrt(self); `} # Returns the greatest common divisor of `self` and `o` # @@ -158,7 +158,7 @@ redef class Float # assert 12.0.abs == 12.0 # assert (-34.56).abs == 34.56 # assert -34.56.abs == -34.56 - fun abs: Float `{ return fabs(recv); `} + fun abs: Float `{ return fabs(self); `} # Returns `self` raised at `e` power. # @@ -186,13 +186,13 @@ redef class Float # assert 1.9.ceil == 2.0 # assert 2.0.ceil == 2.0 # assert (-1.5).ceil == -1.0 - fun ceil: Float `{ return ceil(recv); `} + fun ceil: Float `{ return ceil(self); `} # assert 1.1.floor == 1.0 # assert 1.9.floor == 1.0 # assert 2.0.floor == 2.0 # assert (-1.5).floor == -2.0 - fun floor: Float `{ return floor(recv); `} + fun floor: Float `{ return floor(self); `} # Rounds the value of a float to its nearest integer value # diff --git a/lib/standard/posix.nit b/lib/standard/posix.nit index 1fe850d..7f4b24b 100644 --- a/lib/standard/posix.nit +++ b/lib/standard/posix.nit @@ -61,22 +61,22 @@ extern class Passwd `{struct passwd*`} new from_name(name: String) import String.to_cstring `{ return getpwnam( String_to_cstring(name) ); `} # Username - fun name: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_name); `} + fun name: String import NativeString.to_s `{ return NativeString_to_s(self->pw_name); `} # User password - fun passwd: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_passwd); `} + fun passwd: String import NativeString.to_s `{ return NativeString_to_s(self->pw_passwd); `} # User ID - fun uid: Int `{ return recv->pw_uid; `} + fun uid: Int `{ return self->pw_uid; `} # Group ID - fun gid: Int `{ return recv->pw_gid; `} + fun gid: Int `{ return self->pw_gid; `} # Home directory - fun dir: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_dir); `} + fun dir: String import NativeString.to_s `{ return NativeString_to_s(self->pw_dir); `} # Shell program - fun shell: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_shell); `} + fun shell: String import NativeString.to_s `{ return NativeString_to_s(self->pw_shell); `} end # Information on a user group @@ -88,13 +88,13 @@ extern class Group `{struct group*`} new from_name(name: String) import String.to_cstring `{ return getgrnam( String_to_cstring(name) ); `} # Name of this ground - fun name: String import NativeString.to_s `{ return NativeString_to_s(recv->gr_name); `} + fun name: String import NativeString.to_s `{ return NativeString_to_s(self->gr_name); `} # Encrypted password of this group - fun passwd: String import NativeString.to_s `{ return NativeString_to_s(recv->gr_passwd); `} + fun passwd: String import NativeString.to_s `{ return NativeString_to_s(self->gr_passwd); `} # Id of this group - fun gid: Int `{ return recv->gr_gid; `} + fun gid: Int `{ return self->gr_gid; `} # List of the members of the group fun mem: Array[String] import Array[String], Array[String].add, NativeString.to_s `{ @@ -102,7 +102,7 @@ extern class Group `{struct group*`} int m; Array_of_String ret; - mem = recv->gr_mem; + mem = self->gr_mem; ret = new_Array_of_String(); for (m = 0; mem[m] != NULL; m++) diff --git a/lib/standard/re.nit b/lib/standard/re.nit index a58aba0..24637cb 100644 --- a/lib/standard/re.nit +++ b/lib/standard/re.nit @@ -42,7 +42,7 @@ private extern class NativeRegex `{ regex_t* `} # Compile the regular expression `regex` into a form that is suitable for subsequent `regexec` searches fun regcomp(regex: NativeString, cflags: Int): Int `{ - return regcomp(recv, regex, cflags); + return regcomp(self, regex, cflags); `} # Match `string` against the precompiled pattern buffer of `self`, locating matches @@ -50,32 +50,32 @@ private extern class NativeRegex `{ regex_t* `} # `nmatch` and `pmatch` are used to provide information regarding the location of any matches. # `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`. fun regexec(string: NativeString, nmatch: Int, pmatch: NativeMatchArray, eflags: Int): Int `{ - return regexec(recv, string, nmatch, pmatch, eflags); + return regexec(self, string, nmatch, pmatch, eflags); `} # Match `string` against the precompiled pattern buffer of `self`, do not locate matches # # `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`. fun regexec_match_only(string: NativeString, eflags: Int): Int `{ - return regexec(recv, string, 0, NULL, eflags); + return regexec(self, string, 0, NULL, eflags); `} # Free the memory allocated to the pattern buffer by the compiling process # # Does not free the memory holding `self`, use `free` for this purpose. - fun regfree `{ regfree(recv); `} + fun regfree `{ regfree(self); `} # Turn the error codes that can be returned by both `regcomp` and `regexec` into error message strings fun regerror(errcode: Int): NativeString `{ - size_t len = regerror(errcode, recv, NULL, 0); + size_t len = regerror(errcode, self, NULL, 0); char *message = malloc(len); - regerror(errcode, recv, message, len); + regerror(errcode, self, message, len); return message; `} # Number of parenthetical subexpressions in this compiled regular expression - fun re_nsub: Int `{ return recv->re_nsub; `} + fun re_nsub: Int `{ return self->re_nsub; `} end # Flags for `NativeRegex::regcomp` @@ -96,7 +96,7 @@ private fun error_nomatch: Int `{ return REG_NOMATCH; `} private fun error_espace: Int `{ return REG_ESPACE; `} redef universal Int - private fun is_nomatch: Bool `{ return recv == REG_NOMATCH; `} + private fun is_nomatch: Bool `{ return self == REG_NOMATCH; `} end # An array of `regmatch_t` or a pointer to one @@ -105,17 +105,17 @@ private extern class NativeMatchArray `{ regmatch_t* `} new malloc(length: Int) `{ return malloc(length * sizeof(regmatch_t)); `} # The offset in string of the beginning of a substring - fun rm_so: Int `{ return recv->rm_so; `} + fun rm_so: Int `{ return self->rm_so; `} # The offset in string of the end of the substring - fun rm_eo: Int `{ return recv->rm_eo; `} + fun rm_eo: Int `{ return self->rm_eo; `} # Get a pointer to the element at `index`, can also be used as a subarray - fun [](index: Int): NativeMatchArray `{ return recv + index; `} + fun [](index: Int): NativeMatchArray `{ return self + index; `} end redef extern class NativeString - private fun substring_from(index: Int): NativeString `{ return recv + index; `} + private fun substring_from(index: Int): NativeString `{ return self + index; `} end redef class Text diff --git a/lib/standard/time.nit b/lib/standard/time.nit index e0b3867..99a9f35 100644 --- a/lib/standard/time.nit +++ b/lib/standard/time.nit @@ -41,20 +41,20 @@ extern class TimeT `{time_t`} new from_i(i: Int) `{ return i; `} # Update current time. - fun update `{ time(&recv); `} + fun update `{ time(&self); `} # Convert `self` to a human readable String. fun ctime: String import NativeString.to_s_with_copy `{ - return NativeString_to_s_with_copy( ctime(&recv) ); + return NativeString_to_s_with_copy( ctime(&self) ); `} # Difference in secondes from start (self if the end time) - fun difftime(start: TimeT): Float `{ return difftime(recv, start); `} + fun difftime(start: TimeT): Float `{ return difftime(self, start); `} redef fun to_s do return ctime.replace("\n", "") # Convert self to Int (expressed as seconds since epoch). - fun to_i: Int `{ return (int)recv; `} + fun to_i: Int `{ return (int)self; `} end # Time structure @@ -91,38 +91,38 @@ extern class Tm `{struct tm *`} `} # Convert `self` as a TimeT. - fun to_timet: TimeT `{ return mktime(recv); `} + fun to_timet: TimeT `{ return mktime(self); `} # Seconds after the minute. - fun sec: Int `{ return recv->tm_sec; `} + fun sec: Int `{ return self->tm_sec; `} # Minutes after the hour. - fun min: Int `{ return recv->tm_min; `} + fun min: Int `{ return self->tm_min; `} # hours since midnight. - fun hour: Int `{ return recv->tm_hour; `} + fun hour: Int `{ return self->tm_hour; `} # Day of the month. - fun mday: Int `{ return recv->tm_mday; `} + fun mday: Int `{ return self->tm_mday; `} # Months since January. - fun mon: Int `{ return recv->tm_mon; `} + fun mon: Int `{ return self->tm_mon; `} # Years since 1900. - fun year: Int `{ return recv->tm_year; `} + fun year: Int `{ return self->tm_year; `} # Days since Sunday. - fun wday: Int `{ return recv->tm_wday; `} + fun wday: Int `{ return self->tm_wday; `} # Days since January 1st. - fun yday: Int `{ return recv->tm_yday; `} + fun yday: Int `{ return self->tm_yday; `} # Is `self` in Daylight Saving Time. - fun is_dst: Bool `{ return recv->tm_isdst; `} + fun is_dst: Bool `{ return self->tm_isdst; `} # Convert `self` to a human readable String. fun asctime: String import NativeString.to_s_with_copy `{ - return NativeString_to_s_with_copy( asctime(recv) ); + return NativeString_to_s_with_copy( asctime(self) ); `} # Convert `self` to a human readable String corresponding to `format`. @@ -134,7 +134,7 @@ extern class Tm `{struct tm *`} buf = (char*)malloc(100); c_format = String_to_cstring(format); - res = strftime(buf, 100, c_format, recv); + res = strftime(buf, 100, c_format, self); String s = NativeString_to_s_with_copy(buf); free(buf); return s;