From fbeb9992b7a88d13b276b1d07219fe9211024c4a Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 3 Sep 2014 11:06:07 -0400 Subject: [PATCH 1/1] lib: remove remaining declaration of old-style attributes. Since new-style attributes still allows low-level access to the real attributes, the migration was easy; although some intrude imports where required. Signed-off-by: Jean Privat --- lib/c.nit | 2 + lib/dummy_array.nit | 13 +++-- lib/filter_stream.nit | 4 +- lib/hash_debug.nit | 4 +- lib/pnacl.nit | 4 ++ lib/socket/socket.nit | 1 + lib/standard/collection/abstract_collection.nit | 4 +- lib/standard/collection/array.nit | 21 ++++---- lib/standard/collection/hash_collection.nit | 58 +++++++++++------------ lib/standard/collection/list.nit | 12 ++--- lib/standard/collection/range.nit | 5 +- lib/standard/file.nit | 19 ++++---- lib/standard/stream.nit | 4 +- lib/standard/string.nit | 3 +- lib/standard/string_search.nit | 8 ++-- lib/string_experimentations/utf8.nit | 2 +- lib/string_experimentations/utf8_noindex.nit | 2 +- lib/symbol.nit | 2 +- lib/websocket.nit | 2 + 19 files changed, 86 insertions(+), 84 deletions(-) diff --git a/lib/c.nit b/lib/c.nit index c0bd650..fdc7e99 100644 --- a/lib/c.nit +++ b/lib/c.nit @@ -16,6 +16,8 @@ # Utilities and performant structure for the FFI with C module c +import standard +intrude import standard::collection::array # A thin wrapper around a `NativeCArray` adding length information abstract class CArray[E] diff --git a/lib/dummy_array.nit b/lib/dummy_array.nit index f939e49..21da4bd 100644 --- a/lib/dummy_array.nit +++ b/lib/dummy_array.nit @@ -13,11 +13,10 @@ class DummyArray super Set[Int] super ArrayCapable[Int] - var _capacity: Int - var _length: Int - redef fun length do return _length - var _keys: NativeArray[Int] - var _values: NativeArray[Int] + private var capacity: Int + redef var length: Int + private var keys: NativeArray[Int] + private var values: NativeArray[Int] redef fun add(value: Int) do @@ -87,8 +86,8 @@ end class DummyIterator super Iterator[Int] - var _array: DummyArray - var _pos: Int + private var array: DummyArray + private var pos: Int redef fun item: Int do diff --git a/lib/filter_stream.nit b/lib/filter_stream.nit index 32e5728..2797b67 100644 --- a/lib/filter_stream.nit +++ b/lib/filter_stream.nit @@ -38,7 +38,7 @@ end class StreamCat super FilterIStream - var _streams: Iterator[IStream] + private var streams: Iterator[IStream] redef fun eof: Bool do @@ -91,7 +91,7 @@ end class StreamDemux super FilterOStream - var _streams: Array[OStream] + private var streams: Array[OStream] redef fun is_writable: Bool do diff --git a/lib/hash_debug.nit b/lib/hash_debug.nit index d25c671..b618729 100644 --- a/lib/hash_debug.nit +++ b/lib/hash_debug.nit @@ -125,7 +125,7 @@ redef class HashCollection[K,N] redef fun node_at_idx(i,k) do sys.gt_count += 1 - sys.gt_tot_length += _length + sys.gt_tot_length += _the_length sys.gt_tot_cap += _capacity var c = _array[i] if c != null and c._next_in_bucklet != null then gt_collide(i,k) @@ -150,7 +150,7 @@ redef class HashCollection[K,N] do sys.st_count += 1 if _array[i] != null then st_collide(i,n) - sys.st_tot_length += _length + sys.st_tot_length += _the_length sys.st_tot_cap += _capacity super diff --git a/lib/pnacl.nit b/lib/pnacl.nit index e9b5407..a76784e 100644 --- a/lib/pnacl.nit +++ b/lib/pnacl.nit @@ -23,6 +23,10 @@ # # Provides PNaCl support for Nit. module pnacl is platform + +import standard +intrude import standard::stream + `{ #include #include diff --git a/lib/socket/socket.nit b/lib/socket/socket.nit index d82e1e5..7dee2ef 100644 --- a/lib/socket/socket.nit +++ b/lib/socket/socket.nit @@ -18,6 +18,7 @@ module socket import socket_c +intrude import standard::stream # Portal for communication between two machines class Socket diff --git a/lib/standard/collection/abstract_collection.nit b/lib/standard/collection/abstract_collection.nit index a806c57..9d37e15 100644 --- a/lib/standard/collection/abstract_collection.nit +++ b/lib/standard/collection/abstract_collection.nit @@ -202,7 +202,7 @@ private class ContainerIterator[E] redef var is_ok: Bool = true - var _container: Container[E] + private var container: Container[E] end # Items can be removed from this collection @@ -929,7 +929,7 @@ private class CoupleMapIterator[K: Object, E] _iter.next end - var _iter: Iterator[Couple[K,E]] + private var iter: Iterator[Couple[K,E]] init(i: Iterator[Couple[K,E]]) do _iter = i end diff --git a/lib/standard/collection/array.nit b/lib/standard/collection/array.nit index b23f533..61e8700 100644 --- a/lib/standard/collection/array.nit +++ b/lib/standard/collection/array.nit @@ -21,8 +21,7 @@ import abstract_collection abstract class AbstractArrayRead[E] super SequenceRead[E] - var _length: Int = 0 - redef fun length do return _length + redef var length = 0 redef fun is_empty do return _length == 0 @@ -347,14 +346,14 @@ class Array[E] end # The internal storage. - var _items: nullable NativeArray[E] = null + private var items: nullable NativeArray[E] = null # Do not use this method # FIXME: Remove it once modules can intrude non local modules fun intern_items: NativeArray[E] do return _items.as(not null) # The size of `_items`. - var _capacity: Int = 0 + private var capacity: Int = 0 redef fun ==(o) do @@ -391,9 +390,9 @@ private class ArrayIterator[E] _index = 0 end - var _index: Int = 0 - redef fun index do return _index - var _array: AbstractArrayRead[E] + redef var index = 0 + + private var array: AbstractArrayRead[E] end private class ArrayReverseIterator[E] @@ -417,7 +416,7 @@ class ArraySet[E: Object] super Set[E] # The stored elements. - var _array: Array[E] + private var array: Array[E] redef fun has(e) do return _array.has(e) @@ -475,7 +474,7 @@ private class ArraySetIterator[E: Object] init(iter: ArrayIterator[E]) do _iter = iter - var _iter: ArrayIterator[E] + private var iter: ArrayIterator[E] end @@ -531,7 +530,7 @@ class ArrayMap[K: Object, E] end # Internal storage. - var _items = new Array[Couple[K,E]] + private var items = new Array[Couple[K,E]] # fast remove the ith element of the array private fun remove_at_index(i: Int) @@ -541,7 +540,7 @@ class ArrayMap[K: Object, E] end # The last positive result given by a index(1) call - var _last_index: Int = 0 + private var last_index: Int = 0 # Where is the `key` in `_item`? # return -1 if not found diff --git a/lib/standard/collection/hash_collection.nit b/lib/standard/collection/hash_collection.nit index 2def742..7c90189 100644 --- a/lib/standard/collection/hash_collection.nit +++ b/lib/standard/collection/hash_collection.nit @@ -19,18 +19,18 @@ import array private abstract class HashCollection[K: Object, N: HashNode[Object]] super ArrayCapable[nullable N] - var _array: nullable NativeArray[nullable N] = null # Used to store items - var _capacity: Int = 0 # Size of _array - var _length: Int = 0 # Number of items in the map + private var array: nullable NativeArray[nullable N] = null # Used to store items + private var capacity: Int = 0 # Size of _array + private var the_length: Int = 0 # Number of items in the map - var _first_item: nullable N = null # First added item (used to visit items in nice order) - var _last_item: nullable N = null # Last added item (same) + private var first_item: nullable N = null # First added item (used to visit items in nice order) + private var last_item: nullable N = null # Last added item (same) # The last key accessed (used for cache) - var _last_accessed_key: nullable K = null + private var last_accessed_key: nullable K = null # The last node accessed (used for cache) - var _last_accessed_node: nullable N = null + private var last_accessed_node: nullable N = null # Return the index of the key k fun index_at(k: K): Int @@ -89,8 +89,8 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]] _last_accessed_node = node # Enlarge if needed - var l = _length - _length = l + 1 + var l = _the_length + _the_length = l + 1 # Magic values determined empirically # We do not want to enlarge too much @@ -123,7 +123,7 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]] end # Remove the item in the array - _length -= 1 + _the_length -= 1 prev = node._prev_in_bucklet next = node._next_in_bucklet if prev != null then @@ -146,7 +146,7 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]] _array[i] = null i -= 1 end - _length = 0 + _the_length = 0 _first_item = null _last_item = null _last_accessed_key = null @@ -157,7 +157,7 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]] do var old_cap = _capacity # get a new capacity - if cap < _length + 1 then cap = _length + 1 + if cap < _the_length + 1 then cap = _the_length + 1 if cap <= _capacity then return _capacity = cap _last_accessed_key = null @@ -191,12 +191,12 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]] end private abstract class HashNode[K: Object] - var _key: K + private var key: K type N: HashNode[K] - var _next_item: nullable N = null - var _prev_item: nullable N = null - var _prev_in_bucklet: nullable N = null - var _next_in_bucklet: nullable N = null + private var next_item: nullable N = null + private var prev_item: nullable N = null + private var prev_in_bucklet: nullable N = null + private var next_in_bucklet: nullable N = null init(k: K) do _key = k @@ -221,9 +221,9 @@ class HashMap[K: Object, V] redef fun iterator: HashMapIterator[K, V] do return new HashMapIterator[K,V](self) - redef fun length do return _length + redef fun length do return _the_length - redef fun is_empty do return _length == 0 + redef fun is_empty do return _the_length == 0 redef fun []=(key, v) do @@ -242,7 +242,7 @@ class HashMap[K: Object, V] init do _capacity = 0 - _length = 0 + _the_length = 0 enlarge(0) end @@ -345,7 +345,7 @@ end private class HashMapNode[K: Object, V] super HashNode[K] redef type N: HashMapNode[K, V] - var _value: V + private var value: V init(k: K, v: V) do @@ -383,10 +383,10 @@ class HashMapIterator[K: Object, V] end # The map to iterate on - var _map: HashMap[K, V] + private var map: HashMap[K, V] # The current node - var _node: nullable HashMapNode[K, V] + private var node: nullable HashMapNode[K, V] init(map: HashMap[K, V]) do @@ -401,13 +401,13 @@ class HashSet[E: Object] super Set[E] super HashCollection[E, HashSetNode[E]] - redef fun length do return _length + redef fun length do return _the_length - redef fun is_empty do return _length == 0 + redef fun is_empty do return _the_length == 0 redef fun first do - assert _length > 0 + assert _the_length > 0 return _first_item._key end @@ -436,7 +436,7 @@ class HashSet[E: Object] init do _capacity = 0 - _length = 0 + _the_length = 0 enlarge(0) end @@ -476,10 +476,10 @@ private class HashSetIterator[E: Object] end # The set to iterate on - var _set: HashSet[E] + private var set: HashSet[E] # The position in the internal map storage - var _node: nullable HashSetNode[E] + private var node: nullable HashSetNode[E] init(set: HashSet[E]) do diff --git a/lib/standard/collection/list.nit b/lib/standard/collection/list.nit index c5dc5dd..08a8459 100644 --- a/lib/standard/collection/list.nit +++ b/lib/standard/collection/list.nit @@ -210,10 +210,10 @@ class List[E] init from(coll: Collection[E]) do append(coll) # The first node of the list - var _head: nullable ListNode[E] + private var head: nullable ListNode[E] # The last node of the list - var _tail: nullable ListNode[E] + private var tail: nullable ListNode[E] # Get the `i`th node. get `null` otherwise. private fun get_node(i: Int): nullable ListNode[E] @@ -295,15 +295,13 @@ class ListIterator[E] end # The current list - var _list: List[E] + private var list: List[E] # The current node of the list - var _node: nullable ListNode[E] + private var node: nullable ListNode[E] # The index of the current node - var _index: Int - - redef fun index do return _index + redef var index # Remove the current item fun delete diff --git a/lib/standard/collection/range.nit b/lib/standard/collection/range.nit index e72771e..31ffaa2 100644 --- a/lib/standard/collection/range.nit +++ b/lib/standard/collection/range.nit @@ -76,9 +76,8 @@ end private class IteratorRange[E: Discrete] # Iterator on ranges. super Iterator[E] - var _range: Range[E] - var _item: E - redef fun item do return _item + private var range: Range[E] + redef var item redef fun is_ok do return _item < _range.after diff --git a/lib/standard/file.nit b/lib/standard/file.nit index f7883f6..3443105 100644 --- a/lib/standard/file.nit +++ b/lib/standard/file.nit @@ -36,7 +36,7 @@ abstract class FStream var path: nullable String = null # The FILE *. - var _file: nullable NativeFile = null + private var file: nullable NativeFile = null fun file_stat: FileStat do return _file.file_stat @@ -103,7 +103,7 @@ class OFStream redef fun write(s) do - assert _writable + assert _is_writable if s isa FlatText then write_native(s.to_cstring, s.length) else @@ -111,21 +111,18 @@ class OFStream end end - redef fun is_writable do return _writable - redef fun close do var i = _file.io_close - _writable = false + _is_writable = false end - # Is the file open in write mode - var _writable: Bool + redef var is_writable = false # Write `len` bytes from `native`. private fun write_native(native: NativeString, len: Int) do - assert _writable + assert _is_writable var err = _file.io_write(native, len) if err != len then # Big problem @@ -141,7 +138,7 @@ class OFStream print "Error: Opening file at '{path}' failed with '{sys.errno.strerror}'" end self.path = path - _writable = true + _is_writable = true end private init do end @@ -168,7 +165,7 @@ class Stdout private init do _file = new NativeFile.native_stdout path = "/dev/stdout" - _writable = true + _is_writable = true end end @@ -177,7 +174,7 @@ class Stderr private init do _file = new NativeFile.native_stderr path = "/dev/stderr" - _writable = true + _is_writable = true end end diff --git a/lib/standard/stream.nit b/lib/standard/stream.nit index d14e82f..5932daa 100644 --- a/lib/standard/stream.nit +++ b/lib/standard/stream.nit @@ -250,10 +250,10 @@ abstract class BufferedIStream redef fun eof do return _buffer_pos >= _buffer.length and end_reached # The buffer - var _buffer: nullable FlatBuffer = null + private var buffer: nullable FlatBuffer = null # The current position in the buffer - var _buffer_pos: Int = 0 + private var buffer_pos: Int = 0 # Fill the buffer protected fun fill_buffer is abstract diff --git a/lib/standard/string.nit b/lib/standard/string.nit index 70cf816..2ae29ef 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -16,6 +16,7 @@ module string import math import collection +intrude import collection::array `{ #include @@ -1968,7 +1969,7 @@ interface StringCapable end redef class Sys - var _args_cache: nullable Sequence[String] + private var args_cache: nullable Sequence[String] # The arguments of the program as given by the OS fun program_args: Sequence[String] diff --git a/lib/standard/string_search.nit b/lib/standard/string_search.nit index ef18e08..95ac9d5 100644 --- a/lib/standard/string_search.nit +++ b/lib/standard/string_search.nit @@ -149,10 +149,10 @@ class BM_Pattern end # searched motif - var _motif: String + private var motif: String # length of the motif - var _length: Int + private var length: Int private fun bc(e: Char): Int do @@ -164,10 +164,10 @@ class BM_Pattern end # good shifts - var _gs: Array[Int] + private var gs: Array[Int] # bad characters - var _bc_table: Map[Char, Int] + private var bc_table: Map[Char, Int] private fun compute_bc do diff --git a/lib/string_experimentations/utf8.nit b/lib/string_experimentations/utf8.nit index 7261820..14f8550 100644 --- a/lib/string_experimentations/utf8.nit +++ b/lib/string_experimentations/utf8.nit @@ -401,7 +401,7 @@ end redef class OFStream redef fun write(s) do - assert _writable + assert is_writable if s isa FlatText then if s isa FlatString then write_native(s.to_cstring, s.bytelen) diff --git a/lib/string_experimentations/utf8_noindex.nit b/lib/string_experimentations/utf8_noindex.nit index bf49334..16c2502 100644 --- a/lib/string_experimentations/utf8_noindex.nit +++ b/lib/string_experimentations/utf8_noindex.nit @@ -732,7 +732,7 @@ end redef class OFStream redef fun write(s) do - assert _writable + assert is_writable if s isa FlatText then write_native(s.to_cstring, s.bytelen) else for i in s.substrings do write_native(i.to_cstring, i.length) diff --git a/lib/symbol.nit b/lib/symbol.nit index d268763..1e9fb67 100644 --- a/lib/symbol.nit +++ b/lib/symbol.nit @@ -31,7 +31,7 @@ end # A symbol is a unique immutable string class Symbol - var _string: String + private var string: String redef fun to_s do return _string.to_s # Only used by String::to_symbol diff --git a/lib/websocket.nit b/lib/websocket.nit index 3179014..201fa92 100644 --- a/lib/websocket.nit +++ b/lib/websocket.nit @@ -22,6 +22,8 @@ import socket import sha1 import base64 +intrude import standard::stream + # Websocket compatible server, works as an extra layer to the original Sockets class WebSocket super BufferedIStream -- 1.7.9.5