#
# 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
# 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
# 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
end
# Items can be removed from this collection
-class RemovableCollection[E]
+interface RemovableCollection[E]
special Collection[E]
# Remove all items
meth clear is abstract
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)
# ...
# s.add(a)
# s.has(b) # --> true
-class Set[E]
+interface Set[E]
special SimpleCollection[E]
redef meth has_only(item)
# 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
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
# 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.
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
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
# 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
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
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
end
-redef class Parser
+class Parser
+special ParserTable
# Associated lexer
attr _lexer: Lexer
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 [
]
end
- attr _goto_table: Array[Array[Int]]
+ attr _goto_table: Array[Array[Int]] = null
private meth build_goto_table
do
_goto_table = once [
end
end
-redef class Parser
+class Parser
+special ParserTable
# Associated lexer
attr _lexer: Lexer
$ 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 [
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 [