From 284028d6dcd81c7315bf39d60f0c38da4965ac32 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 14 Nov 2008 04:39:52 -0500 Subject: [PATCH] Prepare default constructors --- lib/standard/abstract_collection.nit | 20 ++++++++++---------- lib/standard/array.nit | 6 +++--- lib/standard/hash.nit | 18 +++++++++--------- src/parser/parser.nit | 3 ++- src/parser/parser_tables.nit | 6 +++--- src/parser/xss/parser.xss | 9 +++++---- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/standard/abstract_collection.nit b/lib/standard/abstract_collection.nit index ee2acfb..a1ad3f8 100644 --- a/lib/standard/abstract_collection.nit +++ b/lib/standard/abstract_collection.nit @@ -38,7 +38,7 @@ import kernel # # This abstract class implements its others methods with an iterator. # Subclasses may redefine them with an efficient implementation. -class Collection[E] +interface Collection[E] # Get a new iterator on the collection. meth iterator: Iterator[E] is abstract @@ -67,7 +67,7 @@ end # Naive implementation of collections method # You only have to define iterator! -class NaiveCollection[E: Object] +interface NaiveCollection[E: Object] special Collection[E] redef meth is_empty do return length == 0 @@ -106,7 +106,7 @@ end # Instances of the Iterator class generates a series of elements, one at a time. # They are mainly used with collections. -class Iterator[E] +interface Iterator[E] # The current item. # Require `is_ok'. meth item: E is abstract @@ -166,7 +166,7 @@ special Iterator[E] end # Items can be removed from this collection -class RemovableCollection[E] +interface RemovableCollection[E] special Collection[E] # Remove all items meth clear is abstract @@ -179,7 +179,7 @@ special Collection[E] end # Items can be added to these collections. -class SimpleCollection[E] +interface SimpleCollection[E] special RemovableCollection[E] # Add an item in a collection. # Ensure col.has(item) @@ -198,7 +198,7 @@ end # ... # s.add(a) # s.has(b) # --> true -class Set[E] +interface Set[E] special SimpleCollection[E] redef meth has_only(item) @@ -239,7 +239,7 @@ end # map[u2] # -> v2 # map.has_key(u1) # -> true # map.has_key(u3) # -> false -class Map[K, E] +interface Map[K, E] special RemovableCollection[E] # Get the item at `key'. meth [](key: K): E is abstract @@ -268,7 +268,7 @@ special RemovableCollection[E] end # Iterators for Map. -class MapIterator[K, E] +interface MapIterator[K, E] special Iterator[E] # The key of the current item. meth key: K is abstract @@ -279,7 +279,7 @@ end # Indexed collection are ordoned collections. # The first item is 0. The last is `length'-1. -class IndexedCollection[E] +interface IndexedCollection[E] special Map[Int, E] special SimpleCollection[E] # Get the first item. @@ -350,7 +350,7 @@ special SimpleCollection[E] end # Iterators on indexed collections. -class IndexedIterator[E] +interface IndexedIterator[E] special MapIterator[Int, E] # The index of the current item. meth index: Int is abstract diff --git a/lib/standard/array.nit b/lib/standard/array.nit index ae227ec..5c63068 100644 --- a/lib/standard/array.nit +++ b/lib/standard/array.nit @@ -23,7 +23,7 @@ special IndexedCollection[E] meth enlarge(cap: Int) is abstract # The current length - redef readable attr _length: Int + redef readable attr _length: Int = 0 redef meth is_empty do return _length == 0 @@ -563,13 +563,13 @@ end # Native classes ############################################################## # Subclasses of this class can create native arrays -class ArrayCapable[E] +interface ArrayCapable[E] # Get a new array of `size' elements. protected meth calloc_array(size: Int): NativeArray[E] is intern end # Native C array (void ...). -class NativeArray[E] +universal NativeArray[E] meth [](index: Int): E is intern meth []=(index: Int, item: E) is intern meth copy_to(dest: NativeArray[E], length: Int) is intern diff --git a/lib/standard/hash.nit b/lib/standard/hash.nit index 0efd405..21331e5 100644 --- a/lib/standard/hash.nit +++ b/lib/standard/hash.nit @@ -64,18 +64,18 @@ end private class HashCollection[K: Object, N: HashNode[K], E: Object] special Collection[E] special ArrayCapable[N] - attr _array: NativeArray[N] # Used to store items - attr _capacity: Int # Size of _array - redef readable attr _length: Int # Number of items in the map + attr _array: NativeArray[N] = null # Used to store items + attr _capacity: Int = 0 # Size of _array + redef readable attr _length: Int = 0 # Number of items in the map - readable attr _first_item: N # First added item (used to visit items in nice order) - attr _last_item: N # Last added item (same) + readable attr _first_item: N = null # First added item (used to visit items in nice order) + attr _last_item: N = null # Last added item (same) # The last index accessed - attr _last_accessed_index: Int + attr _last_accessed_index: Int = -1 # The last key accessed - attr _last_accessed_key: K + attr _last_accessed_key: K = null # Return the index of the k element meth index_at(k: K): Int @@ -221,8 +221,8 @@ end private class HashNode[K] meth key: K is abstract type N: HashNode[K] - readable writable attr _next_item: N - readable writable attr _prev_item: N + readable writable attr _next_item: N = null + readable writable attr _prev_item: N = null end class HashMap[K, V] diff --git a/src/parser/parser.nit b/src/parser/parser.nit index 7026679..8fc7141 100644 --- a/src/parser/parser.nit +++ b/src/parser/parser.nit @@ -20,7 +20,8 @@ private class State end end -redef class Parser +class Parser +special ParserTable # Associated lexer attr _lexer: Lexer diff --git a/src/parser/parser_tables.nit b/src/parser/parser_tables.nit index bbfe24a..2299937 100644 --- a/src/parser/parser_tables.nit +++ b/src/parser/parser_tables.nit @@ -3,8 +3,8 @@ package parser_tables # Parser that build a full AST -class Parser - attr _action_table: Array[Array[Int]] +abstract class ParserTable + attr _action_table: Array[Array[Int]] = null private meth build_action_table do _action_table = once [ @@ -13219,7 +13219,7 @@ class Parser ] end - attr _goto_table: Array[Array[Int]] + attr _goto_table: Array[Array[Int]] = null private meth build_goto_table do _goto_table = once [ diff --git a/src/parser/xss/parser.xss b/src/parser/xss/parser.xss index 2f6d2db..6fc5fa2 100644 --- a/src/parser/xss/parser.xss +++ b/src/parser/xss/parser.xss @@ -33,7 +33,8 @@ private class State end end -redef class Parser +class Parser +special ParserTable # Associated lexer attr _lexer: Lexer @@ -278,8 +279,8 @@ $ end template $ template make_parser_tables() # Parser that build a full AST -class Parser - attr _action_table: Array[Array[Int]] +abstract class ParserTable + attr _action_table: Array[Array[Int]] = null private meth build_action_table do _action_table = once [ @@ -300,7 +301,7 @@ $ end foreach end $ end foreach - attr _goto_table: Array[Array[Int]] + attr _goto_table: Array[Array[Int]] = null private meth build_goto_table do _goto_table = once [ -- 1.7.9.5