Merge: Check missing return in attributes with a block
authorJean Privat <jean@pryen.org>
Wed, 21 Jan 2015 02:39:30 +0000 (09:39 +0700)
committerJean Privat <jean@pryen.org>
Wed, 21 Jan 2015 02:39:30 +0000 (09:39 +0700)
Fixes #1103

Pull-Request: #1114
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/nitiwiki/src/wiki_html.nit
contrib/nitiwiki/tests/res/nitiwiki_render.res
contrib/nitiwiki/tests/res/nitiwiki_status.res
lib/c.nit
lib/github/events.nit [new file with mode: 0644]
lib/glesv2/glesv2.nit
lib/sdl.nit

index 7f213b7..89546ce 100644 (file)
@@ -81,6 +81,7 @@ redef class WikiSection
                end
                var index = self.index
                if index isa WikiSectionIndex then
+                       wiki.message("Render auto-index for section {out_path}", 1)
                        index.is_dirty = true
                        add_child index
                end
@@ -322,6 +323,10 @@ class WikiSectionIndex
        # The section described by `self`.
        var section: WikiSection
 
+       redef fun title do return section.title
+
+       redef fun url do return section.url
+
        redef var is_dirty = false
 
        redef fun tpl_article do
index adf25a7..25f17ab 100644 (file)
@@ -1 +1,6 @@
 Render section out
+Render section out/sec1
+Render section out/sec2
+Render auto-index for section out/sec2
+Render section out/sec2/sub-sec21
+Render section out/sec2/sub-sec22
index 936a764..9eb2262 100644 (file)
@@ -6,5 +6,12 @@ url: http://localhost/
 There is modified files:
  + pages
  + /pages/index.md
+ + pages/sec1
+ + /pages/sec1/index.md
+ + pages/sec2
+ + pages/sec2/sub-sec21
+ + /pages/sec2/sub-sec21/index.md
+ + pages/sec2/sub-sec22
+ + /pages/sec2/sub-sec22/index.md
 
 Use nitiwiki --render to render modified files
index d94ae8e..ae1b875 100644 (file)
--- a/lib/c.nit
+++ b/lib/c.nit
@@ -70,10 +70,10 @@ extern class NativeCArray `{ void * `}
        type E: nullable Object
 
        # Get element at `index`.
-       fun [](index: E): E is abstract
+       fun [](index: Int): E is abstract
 
        # Set `val` at `index`.
-       fun []=(index: E, val: E) is abstract
+       fun []=(index: Int, val: E) is abstract
 
        # Return pointer to the address to the second element of this array
        #
diff --git a/lib/github/events.nit b/lib/github/events.nit
new file mode 100644 (file)
index 0000000..b6e5af3
--- /dev/null
@@ -0,0 +1,302 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Events are emitted by Github Hooks.
+#
+# See <https://developer.github.com/v3/activity/events/types/>
+module events
+
+import api
+
+# Github event stub.
+class GithubEvent
+
+       # Github API client.
+       var api: GithubAPI
+
+       # Json representation of `self`.
+       var json: JsonObject is noinit
+
+       init do
+               json = new JsonObject
+       end
+
+       # Init `self` from a `json` object.
+       init from_json(api: GithubAPI, json: JsonObject) do
+               self.api = api
+               self.json = json
+       end
+
+       # Action performed by the event.
+       fun action: String do return json["action"].to_s
+
+       # Repo where this event occured.
+       fun repo: Repo do
+               return new Repo.from_json(api, json["repository"].as(JsonObject))
+       end
+end
+
+# Triggered when a commit comment is created.
+class CommitCommentEvent
+       super GithubEvent
+
+       # The `Comment` itself.
+       fun comment: CommitComment do
+               return new CommitComment.from_json(api, repo, json["comment"].as(JsonObject))
+       end
+end
+
+# Triggered when a repository, branch, or tag is created.
+class CreateEvent
+       super GithubEvent
+
+       # Oject type that was created.
+       #
+       # Can be one of `repository`, `branch`, or `tag`.
+       fun ref_type: String do return json["ref_type"].to_s
+
+       # Git ref (or null if only a repository was created).
+       fun ref: String do return json["ref"].to_s
+
+       # Name of the repo's default branch (usually master).
+       fun master_branch: String do return json["master_branch"].to_s
+
+       # Repo's current description.
+       fun description: String do return json["description"].to_s
+end
+
+# Triggered when a branch or a tag is deleted.
+class DeleteEvent
+       super GithubEvent
+
+       # Object type that was deleted.
+       #
+       # Can be one of `repository`, `branch`, or `tag`.
+       fun ref_type: String do return json["ref_type"].to_s
+
+       # Git ref (or null if only a repository was deleted).
+       fun ref: String do return json["ref"].to_s
+end
+
+# Triggered when a new snapshot is deployed.
+#
+# Deployement are mainly used with integration testing servers.
+class DeploymentEvent
+       super GithubEvent
+
+       # Commit SHA for which this deployment was created.
+       fun sha: String do return json["sha"].to_s
+
+       # Name of repository for this deployment, formatted as :owner/:repo.
+       fun name: String do return json["name"].to_s
+
+       # Optional extra information for this deployment.
+       fun payload: nullable String do
+               if not json.has_key("payload") then return null
+               return json["payload"].to_s
+       end
+
+       # Optional environment to deploy to.
+       # Default: "production"
+       fun environment: nullable String do
+               if not json.has_key("environment") then return null
+               return json["environment"].to_s
+       end
+
+       # Optional human-readable description added to the deployment.
+       fun description: nullable String do
+               if not json.has_key("description") then return null
+               return json["description"].to_s
+       end
+end
+
+# Triggered when a deployement's status changes.
+class DeploymentStatusEvent
+       super GithubEvent
+
+       # New deployment state.
+       #
+       # Can be `pending`, `success`, `failure`, or `error`.
+       fun state: String do return json["state"].to_s
+
+       # Optional link added to the status.
+       fun target_url: nullable String do
+               if not json.has_key("target_url") then return null
+               return json["target_url"].to_s
+       end
+
+       # Deployment hash that this status is associated with.
+       fun deployment: String do return json["deployment"].to_s
+
+       # Optional human-readable description added to the status.
+       fun description: nullable String do
+               if not json.has_key("description") then return null
+               return json["description"].to_s
+       end
+end
+
+# Triggered when a user forks a repository.
+class ForkEvent
+       super GithubEvent
+
+       # Created repository.
+       fun forkee: Repo do return new Repo.from_json(api, json["forkee"].as(JsonObject))
+end
+
+# Triggered when an issue comment is created.
+class IssueCommentEvent
+       super GithubEvent
+
+       # `Issue` the comment belongs to.
+       fun issue: Issue do
+               return new Issue.from_json(api, repo, json["issue"].as(JsonObject))
+       end
+
+       # The `Comment` itself.
+       fun comment: IssueComment do
+               return new IssueComment.from_json(api, repo, json["comment"].as(JsonObject))
+       end
+end
+
+# Triggered when an event occurs on an issue.
+#
+# Triggered when an issue is assigned, unassigned, labeled, unlabeled,
+# opened, closed or reopened.
+class IssuesEvent
+       super GithubEvent
+
+       # The `Issue` itself.
+       fun issue: Issue do return new Issue.from_json(api, repo, json["issue"].as(JsonObject))
+
+       # Optional `Label` that was added or removed from the issue.
+       fun lbl: nullable Label do
+               if not json.has_key("label") then return null
+               return new Label.from_json(api, repo, json["label"].as(JsonObject))
+       end
+
+       # Optional `User` that was assigned or unassigned from the issue.
+       fun assignee: nullable User do
+               if not json.has_key("assignee") then return null
+               return new User.from_json(api, json["assignee"].as(JsonObject))
+       end
+end
+
+# Triggered when a user is added as a collaborator to a repository.
+class MemberEvent
+       super GithubEvent
+
+       # `User` that was added.
+       fun member: User do return new User.from_json(api, json["member"].as(JsonObject))
+end
+
+# Triggered when an event occurs on a pull request.
+#
+# Triggered when a pull request is assigned, unassigned,
+# labeled, unlabeled, opened, closed, reopened, or synchronized.
+class PullRequestEvent
+       super GithubEvent
+
+       # The pull request number.
+       fun number: Int do return json["number"].as(Int)
+
+       # The `PullRequest` itself.
+       fun pull: PullRequest do
+               return new PullRequest.from_json(api, repo, json["pull_request"].as(JsonObject))
+       end
+end
+
+# Triggered when a comment is created on a pull request diff.
+class PullRequestReviewCommentEvent
+       super GithubEvent
+
+       # The `Comment` itself.
+       fun comment: ReviewComment do
+               return new ReviewComment.from_json(api, repo, json["comment"].as(JsonObject))
+       end
+
+       # `PullRequest` the `comment` belongs to.
+       fun pull: PullRequest do
+               return new PullRequest.from_json(api, repo, json["pull_request"].as(JsonObject))
+       end
+end
+
+# Triggered when a repository branch is pushed to.
+class PushEvent
+       super GithubEvent
+
+       # SHA of the HEAD commit on the repository.
+       fun head: String do return json["head"].to_s
+
+       # Full Git ref that was pushed.
+       #
+       # Example: “refs/heads/master”
+       fun ref: String do return json["ref"].to_s
+
+       # Number of commits in the push.
+       fun size: Int do return json["size"].as(Int)
+
+       # Array of pushed commits.
+       fun commits: Array[Commit] do
+               var res = new Array[Commit]
+               var arr = json["commits"].as(JsonArray)
+               for obj in arr do
+                       if not obj isa JsonObject then continue
+                       res.add api.load_commit(repo, obj["sha"].to_s).as(not null)
+               end
+               return res
+       end
+end
+
+# Triggered when the status of a Git commit changes.
+class StatusEvent
+       super GithubEvent
+
+       # The `Commit` itself.
+       fun commit: Commit do
+               return api.load_commit(repo, json["sha"].to_s).as(not null)
+       end
+
+       # New state.
+       #
+       # Can be `pending`, `success`, `failure`, or `error`.
+       fun state: String do return json["state"].to_s
+
+       # Optional human-readable description added to the status.
+       fun description: nullable String do
+               if not json.has_key("description") then return null
+               return json["description"].to_s
+       end
+
+       # Optional link added to the status.
+       fun target_url: nullable String do
+               if not json.has_key("target_url") then return null
+               return json["target_url"].to_s
+       end
+
+       # Array of branches containing the status' SHA.
+       #
+       # Each branch contains the given SHA,
+       # but the SHA may or may not be the head of the branch.
+       #
+       # The array includes a maximum of 10 branches.
+       fun branches: Array[Branch] do
+               var res = new Array[Branch]
+               var arr = json["branches"].as(JsonArray)
+               for obj in arr do
+                       if not obj isa JsonObject then continue
+                       res.add api.load_branch(repo, obj["name"].to_s).as(not null)
+               end
+               return res
+       end
+end
index 01ca43c..06803ae 100644 (file)
@@ -146,15 +146,21 @@ extern class GLProgram `{GLuint`}
                return active_attrib_name_native(index, max_size).to_s
        end
        private fun active_attrib_name_native(index, max_size: Int): NativeString `{
+               // We get more values than we need, for compatibility. At least the
+               // NVidia driver tries to fill them even if NULL.
+
                char *name = malloc(max_size);
-               glGetActiveAttrib(recv, index, max_size, NULL, NULL, NULL, name);
+               int size;
+               GLenum type;
+               glGetActiveAttrib(recv, index, max_size, NULL, &size, &type, name);
                return name;
        `}
 
        # Size of the active attribute at `index`
        fun active_attrib_size(index: Int): Int `{
                int size;
-               glGetActiveAttrib(recv, index, 0, NULL, NULL, &size, NULL);
+               GLenum type;
+               glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
                return size;
        `}
 
@@ -162,8 +168,9 @@ extern class GLProgram `{GLuint`}
        #
        # May only be float related data types (single float, vectors and matrix).
        fun active_attrib_type(index: Int): GLFloatDataType `{
+               int size;
                GLenum type;
-               glGetActiveAttrib(recv, index, 0, NULL, &type, NULL, NULL);
+               glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
                return type;
        `}
 
@@ -175,14 +182,17 @@ extern class GLProgram `{GLuint`}
        end
        private fun active_uniform_name_native(index, max_size: Int): NativeString `{
                char *name = malloc(max_size);
-               glGetActiveUniform(recv, index, max_size, NULL, NULL, NULL, name);
+               int size;
+               GLenum type;
+               glGetActiveUniform(recv, index, max_size, NULL, &size, &type, name);
                return name;
        `}
 
        # Size of the active uniform at `index`
        fun active_uniform_size(index: Int): Int `{
                int size;
-               glGetActiveUniform(recv, index, 0, NULL, NULL, &size, NULL);
+               GLenum type;
+               glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
                return size;
        `}
 
@@ -190,8 +200,9 @@ extern class GLProgram `{GLuint`}
        #
        # May be any data type supported by OpenGL ES 2.0 shaders.
        fun active_uniform_type(index: Int): GLDataType `{
-               GLenum type;
-               glGetActiveUniform(recv, index, 0, NULL, &type, NULL, NULL);
+               int size;
+               GLenum type = 0;
+               glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
                return type;
        `}
 end
index 5225f9f..16695e2 100644 (file)
@@ -21,6 +21,7 @@ module sdl is
 end
 
 import mnit_display
+import c
 
 in "C header" `{
        #include <unistd.h>
@@ -160,7 +161,26 @@ extern class SDLDisplay `{SDL_Surface *`}
        fun warp_mouse(x,y: Int) `{ SDL_WarpMouse(x, y); `}
 
        # Show or hide the cursor
-       fun show_cursor(show: Bool) `{ SDL_ShowCursor(show); `}
+       fun show_cursor=(val: Bool) `{ SDL_ShowCursor(val? SDL_ENABLE: SDL_DISABLE); `}
+
+       # Is the cursor visible?
+       fun show_cursor: Bool `{ SDL_ShowCursor(SDL_QUERY); `}
+
+       # Grab or release the input
+       fun grab_input=(val: Bool) `{ SDL_WM_GrabInput(val? SDL_GRAB_ON: SDL_GRAB_OFF); `}
+
+       # Is the input grabbed?
+       fun grab_input: Bool `{ SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON; `}
+
+       # Are instances of `SDLMouseMotionEvent` ignored?
+       fun ignore_mouse_motion_events: Bool `{
+               return SDL_EventState(SDL_MOUSEMOTION, SDL_QUERY);
+       `}
+
+       # Do not raise instances of `SDLMouseMotionEvent` if `val`
+       fun ignore_mouse_motion_events=(val: Bool) `{
+               SDL_EventState(SDL_MOUSEMOTION, val? SDL_IGNORE: SDL_ENABLE);
+       `}
 end
 
 # Basic Drawing figures
@@ -225,6 +245,12 @@ extern class SDLImage
        redef fun height: Int `{ return recv->h; `}
 
        fun is_ok: Bool do return not address_is_null
+
+       # Returns a reference to the pixels of the texture
+       fun pixels: NativeCByteArray `{ return recv->pixels; `}
+
+       # Does this texture has an alpha mask?
+       fun amask: Bool `{ return recv->format->Amask; `}
 end
 
 # A simple rectangle
@@ -284,10 +310,10 @@ class SDLMouseButtonEvent
        fun is_left_button: Bool do return button == 1
 
        # Is this event raised by the right button?
-       fun is_right_button: Bool do return button == 2
+       fun is_right_button: Bool do return button == 3
 
        # Is this event raised by the middle button?
-       fun is_middle_button: Bool do return button == 3
+       fun is_middle_button: Bool do return button == 2
 
        # Is this event raised by the wheel going down?
        fun is_down_wheel: Bool do return button == 4