Merge: Less warnings in lib
authorJean Privat <jean@pryen.org>
Fri, 28 Nov 2014 01:58:22 +0000 (20:58 -0500)
committerJean Privat <jean@pryen.org>
Fri, 28 Nov 2014 01:58:22 +0000 (20:58 -0500)
Pull-Request: #939
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/a_star.nit
lib/cpp.nit
lib/emscripten.nit
lib/gpio.nit
lib/libevent.nit
lib/mpi.nit
lib/privileges.nit
lib/sqlite3/sqlite3.nit

index 4108268..97925ff 100644 (file)
@@ -57,14 +57,14 @@ module a_star
 
 # General graph node
 class Node
+       # Type of the others nodes in the `graph`
        type N: Node
 
        # parent graph
        var graph: Graph[N, Link]
 
-       init(graph: Graph[N, Link])
+       init
        do
-               self.graph = graph
                graph.add_node(self)
        end
 
@@ -186,29 +186,36 @@ end
 
 # Link between two nodes and associated to a graph
 class Link
+       # Type of the nodes in `graph`
        type N: Node
+
+       # Type of the other links in `graph`
        type L: Link
 
+       # The graph to which belongs `self`
        var graph: Graph[N, L]
 
+       # Origin of this link
        var from: N
+
+       # Endpoint of this link
        var to: N
 
-       init(graph: Graph[N, L], from, to: N)
+       init
        do
-               self.graph = graph
-               self.from = from
-               self.to = to
-
                graph.add_link(self)
        end
 end
 
 # General graph
 class Graph[N: Node, L: Link]
+       # Nodes in this graph
        var nodes: Set[N] = new HashSet[N]
+
+       # Links in this graph
        var links: Set[L] = new HashSet[L]
 
+       # Add a `node` to this graph
        fun add_node(node: N): N
        do
                nodes.add(node)
@@ -216,6 +223,7 @@ class Graph[N: Node, L: Link]
                return node
        end
 
+       # Add a `link` to this graph
        fun add_link(link: L): L
        do
                links.add(link)
@@ -225,20 +233,22 @@ class Graph[N: Node, L: Link]
                return link
        end
 
-       # used to check if nodes have been searched in one pathfinding
-       var pathfinding_current_evocation: Int = 0
+       # Used to check if nodes have been searched in one pathfinding
+       private var pathfinding_current_evocation: Int = 0
 end
 
-# Result from pathfinding, a walkable path
+# Result from path finding and a walkable path
 class Path[N]
 
+       # The total cost of this path
        var total_cost: Int
 
+       # The list of nodes composing this path
        var nodes = new List[N]
 
-       init (cost: Int) do total_cost = cost
+       private var at: Int = 0
 
-       var at: Int = 0
+       # Step on the path and get the next node to travel
        fun step: N
        do
                assert nodes.length >= at else print "a_star::Path::step failed, is at_end_of_path"
@@ -249,16 +259,22 @@ class Path[N]
                return s
        end
 
+       # Peek at the next step of the path
        fun peek_step: N do return nodes[at]
 
+       # Are we at the end of this path?
        fun at_end_of_path: Bool do return at >= nodes.length
 end
 
 # Context related to an evocation of pathfinding
 class PathContext
+       # Type of the nodes in `graph`
        type N: Node
+
+       # Type of the links in `graph`
        type L: Link
 
+       # Graph to which is associated `self`
        var graph: Graph[N, L]
 
        # Worst cost of all the link's costs
@@ -273,6 +289,7 @@ class PathContext
        # Heuristic
        fun heuristic_cost(a, b: N): Int is abstract
 
+       # The worst cost suggested by the heuristic
        fun worst_heuristic_cost: Int is abstract
 end
 
@@ -292,12 +309,13 @@ class ConstantPathContext
        redef fun worst_heuristic_cost do return 0
 end
 
+# A `PathContext` for graphs with `WeightedLink`
 class WeightedPathContext
        super PathContext
 
        redef type L: WeightedLink
 
-       init(graph: Graph[N, L])
+       init
        do
                super
 
@@ -309,7 +327,7 @@ class WeightedPathContext
                self.worst_cost = worst_cost
        end
 
-       redef var worst_cost: Int
+       redef var worst_cost: Int is noinit
 
        redef fun cost(l) do
                return l.weight
@@ -319,17 +337,12 @@ class WeightedPathContext
        redef fun worst_heuristic_cost do return 0
 end
 
+# A `Link` with a `weight`
 class WeightedLink
        super Link
 
+       # The `weight`, or cost, of this link
        var weight: Int
-
-       init(graph: Graph[N, L], from, to: N, weight: Int)
-       do
-               super
-
-               self.weight = weight
-       end
 end
 
 # Advanced path conditions with customizable accept states
index 3d4daf6..6fe897a 100644 (file)
@@ -23,12 +23,14 @@ end
 extern class CppString in "C++" `{ std::string* `}
 end
 
-redef class String
-       fun to_cpp_string: CppString do return to_cstring.to_cpp_string
+redef class Text
+       # Get `self` as a `CppString`
+       fun to_cpp_string: CppString do return to_cstring.to_cpp_string(length)
 end
 
 redef class NativeString
-       fun to_cpp_string: CppString in "C++" `{
-               return new std::string(recv);
+       # Get `self` as a `CppString`
+       fun to_cpp_string(length: Int): CppString in "C++" `{
+               return new std::string(recv, length);
        `}
 end
index d46f4d1..3fd2fff 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# Platform for the _emscripten_ framework
+#
+# Importing this module from your project will tell _nitg_ to compile
+# to JavaScript for the _emscripten_ framework.
 module emscripten is platform
 
 `{
@@ -21,12 +25,16 @@ module emscripten is platform
        #include <gc.h>
 `}
 
-redef class String
+redef class Text
+       # Run `self` as JavaScript code
        fun run_js do run_js_native(self.escape_to_js.to_cstring)
+
        private fun run_js_native(script: NativeString) `{ emscripten_run_script(script); `}
 
-       fun escape_to_js: String do return self.replace('\n', "\\n")
+       # Escape the content of `self` to pass to JavaScript code
+       fun escape_to_js: Text do return replace('\n', "\\n")
 
+       # Raise a JavaScript alert
        fun alert do "alert('{self.escape_to_js}')".run_js
 end
 
index 820f608..cea53cb 100644 (file)
@@ -17,6 +17,8 @@
 # GPIO related functionnalities
 module gpio
 
+# A physical binary pin
 interface Pin
+       # Set the output of this pin
        fun write(high: Bool) is abstract
 end
index 525915c..9ff7ed0 100644 (file)
@@ -92,8 +92,9 @@ extern class NativeEventBase `{ struct event_base * `}
 
        # Create a new event_base to use with the rest of Libevent
        new `{ return event_base_new(); `}
+
+       # Has `self` been correctly initialized?
        fun is_valid: Bool do return not address_is_null
-       #fun creation_ok
 
        # Event dispatching loop
        #
@@ -154,7 +155,7 @@ class Connection
        # Write a string to the connection
        fun write(str: String)
        do
-               var res = native_buffer_event.write(str.to_cstring, str.length)
+               native_buffer_event.write(str.to_cstring, str.length)
        end
 
        # Write a file to the connection
@@ -175,6 +176,7 @@ end
 
 # A buffer event structure, strongly associated to a connection, an input buffer and an output_buffer
 extern class NativeBufferEvent `{ struct bufferevent * `}
+       # Write `length` bytes of `line`
        fun write(line: NativeString, length: Int): Int `{
                return bufferevent_write(recv, line, length);
        `}
@@ -205,6 +207,7 @@ extern class NativeEvBuffer `{ struct evbuffer * `}
        fun length: Int `{ return evbuffer_get_length(recv); `}
 end
 
+# An input buffer
 extern class InputNativeEvBuffer
        super NativeEvBuffer
 
@@ -212,6 +215,7 @@ extern class InputNativeEvBuffer
        fun drain(length: Int) `{ evbuffer_drain(recv, length); `}
 end
 
+# An output buffer
 extern class OutputNativeEvBuffer
        super NativeEvBuffer
 
@@ -270,6 +274,7 @@ end
 
 # Factory to listen on sockets and create new `Connection`
 class ConnectionFactory
+       # The `NativeEventBase` for the dispatch loop of this factory
        var event_base: NativeEventBase
 
        # On new connection, create the handler `Connection` object
index 20ff9af..1d8c406 100644 (file)
@@ -123,26 +123,34 @@ class MPI
                return deserialized
        end
 
+       # Send an empty buffer, only for the `tag`
        fun send_empty(dest: Rank, tag: Tag, comm: Comm): SuccessOrError
        `{
                return MPI_Send(NULL, 0, MPI_CHAR, dest, tag, comm);
        `}
 
+       # Receive an empty buffer, only for the `tag`
        fun recv_empty(dest: Rank, tag: Tag, comm: Comm): SuccessOrError
        `{
                return MPI_Recv(NULL, 0, MPI_CHAR, dest, tag, comm, MPI_STATUS_IGNORE);
        `}
 
-       fun native_send(data: NativeCArray, count: Int, data_type: DataType, dest: Rank, tag: Tag, comm: Comm): SuccessOrError
+       # Send a `NativeCArray` `buffer` with a given `count` of `data_type`
+       fun native_send(buffer: NativeCArray, count: Int, data_type: DataType, dest: Rank, tag: Tag, comm: Comm): SuccessOrError
        `{
-               return MPI_Send(data, count, data_type, dest, tag, comm);
+               return MPI_Send(buffer, count, data_type, dest, tag, comm);
        `}
 
-       fun native_recv(data: NativeCArray, count: Int, data_type: DataType, dest: Rank, tag: Tag, comm: Comm, status: Status): SuccessOrError
+       # Receive into a `NativeCArray` `buffer` with a given `count` of `data_type`
+       fun native_recv(buffer: NativeCArray, count: Int, data_type: DataType, dest: Rank, tag: Tag, comm: Comm, status: Status): SuccessOrError
        `{
-               return MPI_Recv(data, count, data_type, dest, tag, comm, status);
+               return MPI_Recv(buffer, count, data_type, dest, tag, comm, status);
        `}
 
+       # Probe for the next data to receive, store the result in `status`
+       #
+       # Note: If you encounter an error where the next receive does not correspond
+       # to the last `probe`, call this method twice to ensure a correct result.
        fun probe(source: Rank, tag: Tag, comm: Comm, status: Status): SuccessOrError
        `{
                return MPI_Probe(source, tag, comm, status);
@@ -157,8 +165,13 @@ end
 
 # An MPI communicator
 extern class Comm `{ MPI_Comm `}
+       # The _null_ communicator, targeting no processors
        new null_ `{ return MPI_COMM_NULL; `}
+
+       # The _world_ communicator, targeting all processors
        new world `{ return MPI_COMM_WORLD; `}
+
+       # The _self_ communicator, targeting this processor only
        new self_ `{ return MPI_COMM_SELF; `}
 
        # Number of processors in this communicator
@@ -278,6 +291,7 @@ end
 
 # An MPI rank within a communcator
 extern class Rank `{ int `}
+       # Special rank accepting any processor
        new any `{ return MPI_ANY_SOURCE; `}
 
        # This Rank as an `Int`
@@ -287,6 +301,7 @@ end
 
 # An MPI tag, can be defined using `Int::tag`
 extern class Tag `{ int `}
+       # Special tag accepting any tag
        new any `{ return MPI_ANY_TAG; `}
 
        # This tag as an `Int`
index 7a5503f..f17a28e 100644 (file)
@@ -75,8 +75,11 @@ class OptionUserAndGroup
 
        redef type VALUE: nullable UserGroup
 
-       init for_dropping_privileges do init("Drop privileges to user:group or simply user", "-u", "--usergroup")
-       init(help: String, names: String...) do super(help, null, names)
+       # Create an `OptionUserAndGroup` for dropping privileges
+       init for_dropping_privileges
+       do
+               init("Drop privileges to user:group or simply user", null, ["-u", "--usergroup"])
+       end
 
        redef fun convert(str)
        do
@@ -87,8 +90,7 @@ class OptionUserAndGroup
                        return new UserGroup(words[0], words[1])
                else
                        errors.add("Option {names.join(", ")} expected parameter in the format \"user:group\" or simply \"user\".\n")
-                       abort # FIXME only for nitc, remove and replace with next line when FFI is working in nitg
-                       #return null
+                       return null
                end
        end
 end
index 05cbed0..23b1ef7 100644 (file)
@@ -114,8 +114,6 @@ end
 class Statement
        private var native_statement: NativeStatement
 
-       private init(ns: NativeStatement) do self.native_statement = ns
-
        # Is this statement usable?
        var is_open = true
 
@@ -134,12 +132,11 @@ class Statement
        end
 end
 
+# A row from a `Statement`
 class StatementRow
        # Statement linked to `self`
        var statement: Statement
 
-       private init(s: Statement) do self.statement = s
-
        # Number of entries in this row
        #
        # require: `self.statement.is_open`
@@ -161,12 +158,6 @@ class StatementEntry
 
        private var index: Int
 
-       private init(s: Statement, i: Int)
-       do
-               self.statement = s
-               self.index = i
-       end
-
        # Name of the column
        #
        # require: `self.statement.is_open`
@@ -258,17 +249,15 @@ class StatementIterator
        # Statement linked to `self`
        var statement: Statement
 
-       private init(s: Statement)
+       init
        do
-               self.statement = s
-               self.item = new StatementRow(s)
-
+               self.item = new StatementRow(statement)
                self.is_ok = statement.native_statement.step.is_row
        end
 
-       redef var item: StatementRow
+       redef var item: StatementRow is noinit
 
-       redef var is_ok: Bool
+       redef var is_ok: Bool is noinit
 
        # require: `self.statement.is_open`
        redef fun next
@@ -310,12 +299,9 @@ end
 class Blob
        super Sqlite3Data
 
-       private init(pointer: Pointer, length: Int)
-       do
-               self.pointer = pointer
-               self.length = length
-       end
-
+       # Pointer to the beginning of the blob
        var pointer: Pointer
+
+       # Size of the blob
        var length: Int
 end