src: migrate some modules to new constructors
authorJean Privat <privat@pryen.org>
Sat, 27 Sep 2014 12:15:57 +0000 (08:15 -0400)
committerJean Privat <privat@pryen.org>
Sat, 27 Sep 2014 12:17:36 +0000 (08:17 -0400)
Signed-off-by: Jean Privat <privat@pryen.org>

contrib/friendz/src/grid.nit
examples/circular_list.nit
lib/for_abuse.nit
lib/geometry/points_and_lines.nit
lib/mnit/tileset.nit
lib/nitcc_runtime.nit
lib/pipeline.nit

index 3913154..a097ff5 100644 (file)
@@ -13,13 +13,13 @@ module grid
 # Grid of monsters.
 class Grid
        # width of the current grid
-       var width: Int
+       var width: Int is noinit
 
        # maximum width of the grid
        var max_width: Int
 
        # height of the current grid
-       var height: Int
+       var height: Int is noinit
 
        # maximum height of the grid
        var max_height: Int
@@ -30,13 +30,7 @@ class Grid
        # the data grid
        private var grid = new Array[Array[Tile]]
 
-       init(mw,mh,nm: Int)
-       do
-               self.max_width = mw
-               self.max_height = mh
-               self.nb_monsters = mh
-               clear
-       end
+       init do clear
 
        # Reinitialize the grid with new empty tiles and monsters info
        fun clear
index c3ba1ed..dd4e54d 100644 (file)
@@ -120,11 +120,11 @@ end
 private class CircularListIterator[E]
        super IndexedIterator[E]
 
-       redef var index: Int
+       redef var index: Int = 0
 
        # The current node pointed.
        # Is null if the list is empty.
-       var node: nullable CLNode[E]
+       var node: nullable CLNode[E] is noinit
 
        # The list iterated.
        var list: CircularList[E]
@@ -144,11 +144,9 @@ private class CircularListIterator[E]
 
        redef fun item do return self.node.item
 
-       init(list: CircularList[E])
+       init
        do
                self.node = list.node
-               self.list = list
-               self.index = 0
        end
 end
 
index 2ee4d28..eeb8ed7 100644 (file)
@@ -46,9 +46,10 @@ end
 # Abuser iterator to read a file, see `file_open`
 private class ReadFileForAbuserIterator
        super Iterator[IFStream]
-       redef var item: IFStream
+       var path: String
+       redef var item: IFStream is noinit
        redef var is_ok = true
-       init(path: String)
+       init
        do
                # start of service is to open the file, and return in
                item = new IFStream.open(path)
@@ -94,21 +95,18 @@ end
 private class SortAbuserIterator[E]
        super Iterator[CompareQuery[E]]
        # The index of the big loop
-       var i: Int
+       var i: Int = 0
        # The index of the small loop
-       var j: Int
+       var j: Int = 0
        # The array to sort
        var array: Array[E]
        # The query used to communicate with the user.
        # For ecological concerns, a unique CompareQuery is instatiated.
-       var query: nullable CompareQuery[E]
+       var query: nullable CompareQuery[E] = null
        redef fun item do return query.as(not null)
-       init(array: Array[E])
+       init
        do
-               self.array = array
                # Initialize the algorithm, see `next` for the rest
-               i = 0
-               j = 0
                if not is_ok then return
                query = new CompareQuery[E](array[i], array[j])
        end
index 492d31f..14a67fb 100644 (file)
@@ -33,12 +33,6 @@ class Point[N: Numeric]
 
        redef var x: N
        redef var y: N
-
-       init(x, y: N)
-       do
-               self.x = x
-               self.y = y
-       end
 end
 
 # An abstract 3d point, strongly linked to its implementation `Point3d`
@@ -57,12 +51,6 @@ class Point3d[N: Numeric]
        super Point[N]
 
        redef var z: N
-
-       init(x, y, z: N)
-       do
-               super
-               self.z = z
-       end
 end
 
 # An abstract 2d line segment
@@ -82,12 +70,11 @@ class Line[N: Numeric]
        redef var point_left: P
        redef var point_right: P
 
-       init(a, b: P)
+       init
        do
-               if a.x < b.x then
-                       point_left = a
-                       point_right = b
-               else
+               var a = point_left
+               var b = point_right
+               if a.x > b.x then
                        point_left = b
                        point_right = a
                end
index 8495c51..568fad5 100644 (file)
@@ -28,12 +28,8 @@ class TileSet
        # The height of a tile
        var height: Int
 
-       init(image: Image, width: Int, height: Int)
+       init
        do
-               self.image = image
-               self.width = width
-               self.height = height
-
                self.nb_cols = image.width / width
                self.nb_rows = image.height / height
 
@@ -45,10 +41,10 @@ class TileSet
        end
 
        # The number of columns of tiles in the image
-       var nb_cols: Int
+       var nb_cols: Int is noinit
 
        # The number of rows of tiles in the image
-       var nb_rows: Int
+       var nb_rows: Int is noinit
 
        # Cache for images of tiles
        var subimages = new Array[Image]
@@ -72,12 +68,6 @@ class TileSetFont
        # Use space (' ') for holes in the tileset
        var chars: String
 
-       init(image: Image, width: Int, height: Int, chars: String)
-       do
-               super
-               self.chars = chars
-       end
-
        # Additional space to insert horizontally between characters
        # A negave value will display tile overlaped
        var hspace: Int = 0 is writable
index 74dcd43..9c5ec01 100644 (file)
@@ -276,7 +276,6 @@ class TreePrinterVisitor
        super Visitor
        var writer: OStream
        private var indent = 0
-       init(writer: OStream) do self.writer = writer
        redef fun visit(n)
        do
                for i in [0..indent[ do writer.write("  ")
index 0c422ed..da1b4c4 100644 (file)
@@ -294,13 +294,7 @@ private class PipeSkip[E]
        var source: Iterator[E]
        var skip_item: E
 
-       init(source: Iterator[E], skip_item: E)
-       do
-               self.source = source
-               self.skip_item = skip_item
-
-               do_skip
-       end
+       init do do_skip
 
        fun do_skip
        do
@@ -345,10 +339,8 @@ private class PipeSkipTail[E]
 
        var lasts = new List[E]
 
-       init(source: Iterator[E], length: Int)
+       init
        do
-               self.source = source
-               self.length = length
                var lasts = self.lasts
                while source.is_ok and lasts.length < length do
                        lasts.push(source.item)
@@ -375,13 +367,7 @@ private class PipeSelect[E]
 
        var predicate: Function[E, Bool]
 
-       init(source: Iterator[E], predicate: Function[E, Bool])
-       do
-               self.source = source
-               self.predicate = predicate
-
-               do_skip
-       end
+       init do do_skip
 
        fun do_skip
        do