nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7d1fad7
)
Prepare default constructors
author
Jean Privat
<jean@pryen.org>
Fri, 14 Nov 2008 09:39:52 +0000
(
04:39
-0500)
committer
Jean Privat
<jean@pryen.org>
Fri, 14 Nov 2008 09:39:52 +0000
(
04:39
-0500)
lib/standard/abstract_collection.nit
patch
|
blob
|
history
lib/standard/array.nit
patch
|
blob
|
history
lib/standard/hash.nit
patch
|
blob
|
history
src/parser/parser.nit
patch
|
blob
|
history
src/parser/parser_tables.nit
patch
|
blob
|
history
src/parser/xss/parser.xss
patch
|
blob
|
history
diff --git
a/lib/standard/abstract_collection.nit
b/lib/standard/abstract_collection.nit
index
ee2acfb
..
a1ad3f8
100644
(file)
--- 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.
#
# 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
# 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!
# 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
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.
# 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
# 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
end
# Items can be removed from this collection
-class RemovableCollection[E]
+interface RemovableCollection[E]
special Collection[E]
# Remove all items
meth clear is abstract
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.
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)
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
# ...
# s.add(a)
# s.has(b) # --> true
-class Set[E]
+interface Set[E]
special SimpleCollection[E]
redef meth has_only(item)
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
# 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
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.
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
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.
# 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.
special Map[Int, E]
special SimpleCollection[E]
# Get the first item.
@@
-350,7
+350,7
@@
special SimpleCollection[E]
end
# Iterators on indexed collections.
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
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
(file)
--- 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
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
redef meth is_empty do return _length == 0
@@
-563,13
+563,13
@@
end
# Native classes ##############################################################
# Subclasses of this class can create native arrays
# 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 ...).
# 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
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
(file)
--- 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]
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
# The last index accessed
- attr _last_accessed_index: Int
+ attr _last_accessed_index: Int = -1
# The last key accessed
# 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
# 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]
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]
end
class HashMap[K, V]
diff --git
a/src/parser/parser.nit
b/src/parser/parser.nit
index
7026679
..
8fc7141
100644
(file)
--- a/
src/parser/parser.nit
+++ b/
src/parser/parser.nit
@@
-20,7
+20,8
@@
private class State
end
end
end
end
-redef class Parser
+class Parser
+special ParserTable
# Associated lexer
attr _lexer: Lexer
# Associated lexer
attr _lexer: Lexer
diff --git
a/src/parser/parser_tables.nit
b/src/parser/parser_tables.nit
index
bbfe24a
..
2299937
100644
(file)
--- 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
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 [
private meth build_action_table
do
_action_table = once [
@@
-13219,7
+13219,7
@@
class Parser
]
end
]
end
- attr _goto_table: Array[Array[Int]]
+ attr _goto_table: Array[Array[Int]] = null
private meth build_goto_table
do
_goto_table = once [
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
(file)
--- a/
src/parser/xss/parser.xss
+++ b/
src/parser/xss/parser.xss
@@
-33,7
+33,8
@@
private class State
end
end
end
end
-redef class Parser
+class Parser
+special ParserTable
# Associated lexer
attr _lexer: Lexer
# Associated lexer
attr _lexer: Lexer
@@
-278,8
+279,8
@@
$ end template
$ template make_parser_tables()
# Parser that build a full AST
$ 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 [
private meth build_action_table
do
_action_table = once [
@@
-300,7
+301,7
@@
$ end foreach
end
$ 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 [
private meth build_goto_table
do
_goto_table = once [