Because you do not deserve privacy.
Pull-Request: #1818
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
#ifdef ANDROID
#include <android/log.h>
#define PRINT_ERROR(...) ((void)__android_log_print(ANDROID_LOG_WARN, "nit", __VA_ARGS__))
+
+ // FIXME bring back when the GC is fixed in Android
+ #undef WITH_LIBGC
#else
#define PRINT_ERROR(...) ((void)fprintf(stderr, __VA_ARGS__))
#endif
--- /dev/null
+# 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.
+
+# Android implementation of `app:http_request`
+module http_request is
+ android_manifest """<uses-permission android:name="android.permission.INTERNET" />"""
+end
+
+intrude import app::http_request
+import ui
+
+in "Java" `{
+ import org.apache.http.client.methods.HttpGet;
+ import org.apache.http.impl.client.DefaultHttpClient;
+ import org.apache.http.HttpResponse;
+ import org.apache.http.HttpStatus;
+ import org.apache.http.StatusLine;
+ import java.io.ByteArrayOutputStream;
+`}
+
+redef class App
+ redef fun run_on_ui_thread(task) do app.native_activity.run_on_ui_thread task
+end
+
+redef class Text
+
+ redef fun http_get
+ do
+ jni_env.push_local_frame 8
+ var juri = self.to_java_string
+ var jrep = java_http_get(juri)
+
+ assert not jrep.is_java_null
+
+ var res
+ if jrep.is_exception then
+ jrep = jrep.as_exception
+ res = new HttpRequestResult(null, new IOError(jrep.message.to_s))
+ else if jrep.is_http_response then
+ jrep = jrep.as_http_response
+ res = new HttpRequestResult(jrep.content.to_s, null, jrep.status_code)
+ else abort
+
+ jni_env.pop_local_frame
+ return res
+ end
+end
+
+redef class AsyncHttpRequest
+
+ redef fun main
+ do
+ var res = super
+ jvm.detach_current_thread
+ return res
+ end
+end
+
+redef class JavaObject
+ private fun is_exception: Bool in "Java" `{ return self instanceof Exception; `}
+ private fun as_exception: JavaException in "Java" `{ return (Exception)self; `}
+
+ private fun is_http_response: Bool in "Java" `{ return self instanceof HttpResponse; `}
+ private fun as_http_response: JavaHttpResponse in "Java" `{ return (HttpResponse)self; `}
+end
+
+private fun java_http_get(uri: JavaString): JavaObject in "Java" `{
+ try {
+ DefaultHttpClient client = new DefaultHttpClient();
+ HttpGet get = new HttpGet(uri);
+ return client.execute(get);
+ } catch (Exception ex) {
+ return ex;
+ }
+`}
+
+private extern class JavaHttpResponse in "Java" `{ org.apache.http.HttpResponse `}
+ super JavaObject
+
+ fun status_code: Int in "Java" `{ return self.getStatusLine().getStatusCode(); `}
+
+ fun content: JavaString in "Java" `{
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ self.getEntity().writeTo(out);
+ out.close();
+ return out.toString();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ return "";
+ }
+ `}
+end
--- /dev/null
+# 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.
+
+# HTTP request services: `AsyncHttpRequest` and `Text::http_get`
+module http_request
+
+import app_base
+import pthreads
+import json::serialization
+
+import linux::http_request is conditional(linux)
+import android::http_request is conditional(android)
+
+redef class App
+ # Platform specific service to execute `task` on the main/UI thread
+ fun run_on_ui_thread(task: Task) is abstract
+end
+
+# Thread executing an HTTP request and deserializing JSON asynchronously
+#
+# This class defines four methods acting on the main/UI thread,
+# they should be implemented as needed:
+# * before
+# * on_load
+# * on_fail
+# * after
+class AsyncHttpRequest
+ super Thread
+
+ # Root URI of the remote server
+ fun rest_server_uri: String is abstract
+
+ # Action, or path, for this request within the `rest_server_uri`
+ fun rest_action: String is abstract
+
+ # Should the response content be deserialized from JSON?
+ var deserialize_json = true is writable
+
+ redef fun start
+ do
+ before
+ super
+ end
+
+ redef fun main
+ do
+ var uri = rest_server_uri / rest_action
+
+ # Execute REST request
+ var rep = uri.http_get
+ if rep.is_error then
+ app.run_on_ui_thread new RestRunnableOnFail(self, rep.error)
+ return null
+ end
+
+ if not deserialize_json then
+ app.run_on_ui_thread new RestRunnableOnLoad(self, rep)
+ return null
+ end
+
+ # Deserialize
+ var deserializer = new JsonDeserializer(rep.value)
+ var res = deserializer.deserialize
+ if deserializer.errors.not_empty then
+ app.run_on_ui_thread new RestRunnableOnFail(self, deserializer.errors.first)
+ end
+
+ app.run_on_ui_thread new RestRunnableOnLoad(self, res)
+ return null
+ end
+
+ # Prepare the UI or other parts of the program before executing the REST request
+ fun before do end
+
+ # Invoked when the HTTP request returned valid data
+ #
+ # If `deserialize_json`, the default behavior, this method is invoked only if deserialization was successful.
+ # In this case, `result` may be any deserialized object.
+ #
+ # Otherwise, if `not deserialize_json`, `result` contains the content of the response as a `String`.
+ fun on_load(result: nullable Object) do end
+
+ # Invoked when the HTTP request has failed and no data was received or deserialization failed
+ fun on_fail(error: Error) do print_error "REST request '{rest_action}' failed with: {error}"
+
+ # Complete this request whether it was a success or not
+ fun after do end
+end
+
+redef class Text
+ # Execute an HTTP GET request synchronously at the URI `self`
+ #
+ # ~~~nitish
+ # var response = "http://example.org/".http_get
+ # if response.is_error then
+ # print_error response.error
+ # else
+ # print "HTTP status code: {response.code}"
+ # print response.value
+ # end
+ # ~~~
+ private fun http_get: HttpRequestResult is abstract
+end
+
+# Result of a call to `Text::http_get`
+#
+# Users should first check if `is_error` to use `error`.
+# Otherwise they can use `value` to get the content of the response
+# and `code` for the HTTP status code.
+class HttpRequestResult
+ super MaybeError[String, Error]
+
+ # The HTTP status code, if any
+ var maybe_code: nullable Int
+
+ # The status code
+ # Require: `not is_error`
+ fun code: Int do return maybe_code.as(not null)
+end
+
+private abstract class HttpRequestTask
+ super Task
+
+ # `AsyncHttpRequest` to which send callbacks
+ var sender_thread: AsyncHttpRequest
+end
+
+private class RestRunnableOnLoad
+ super HttpRequestTask
+
+ var res: nullable Object
+
+ redef fun main
+ do
+ sender_thread.on_load(res)
+ sender_thread.after
+ end
+end
+
+private class RestRunnableOnFail
+ super HttpRequestTask
+
+ var error: Error
+
+ redef fun main
+ do
+ sender_thread.on_fail(error)
+ sender_thread.after
+ end
+end
# REQUIRE: `not is_error`
fun value: V do return maybe_value.as(V)
- # The require
+ # The error
# REQUIRE: `is_error`
fun error: E do return maybe_error.as(E)
tags=lib
maintainer=Jean Privat <jean@pryen.org>
license=Apache-2.0
+more_contributors=Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>, Romain Chanoir <romain.chanoir@viacesi.fr>, Christophe Gigax <christophe.gigax@viacesi.fr>, Frédéric Vachon <fredvac@gmail.com>, Jean-Sebastien Gelinas <calestar@gmail.com>, Alexandre Blondin Massé <alexandre.blondin.masse@gmail.com>, Johan Kayser <johan.kayser@viacesi.fr>, Johann Dubois <johann.dubois@outlook.com>, Julien Pagès <julien.projet@gmail.com>
[upstream]
browse=https://github.com/nitlang/nit/tree/master/lib/core
git=https://github.com/nitlang/nit.git
import gtk_core
`{
-#ifdef GdkCallback_run
- // Callback to GdkCallaback::run
- gboolean nit_gdk_callback(gpointer user_data) {
- GdkCallback_decr_ref(user_data);
- return GdkCallback_run(user_data);
+#ifdef Task_gdk_main
+ // Callback to Task::gdk_main
+ gboolean nit_gdk_callback_task(gpointer user_data) {
+ Task_decr_ref(user_data);
+ return Task_gdk_main(user_data);
}
#endif
`}
-# Callback to pass to `gdk_threads_add_idle`
-class GdkCallback
+redef class Task
# Small unit of code executed by the GDK loop when idle
#
- # Returns true if this object should be invoked again.
- fun run: Bool do return false
+ # Returns `true` if this object should be invoked again.
+ fun gdk_main: Bool
+ do
+ main
+ return false
+ end
end
# Add a callback to execute whenever there are no higher priority events pending
-fun gdk_threads_add_idle(callback: GdkCallback): Int import GdkCallback.run `{
- GdkCallback_incr_ref(callback);
- return gdk_threads_add_idle(&nit_gdk_callback, callback);
+fun gdk_threads_add_idle(task: Task): Int import Task.gdk_main `{
+ Task_incr_ref(task);
+ return gdk_threads_add_idle(&nit_gdk_callback_task, task);
`}
return to_java_string.to_s
end
end
+
+# Java class: java.lang.Throwable
+extern class JavaThrowable in "Java" `{ java.lang.Throwable `}
+ super JavaObject
+
+ # Java implementation: java.lang.String java.lang.Throwable.getMessage()
+ fun message: JavaString in "Java" `{
+ return self.getMessage();
+ `}
+
+ # Java implementation: java.lang.String java.lang.Throwable.getLocalizedMessage()
+ fun localized_message: JavaString in "Java" `{
+ return self.getLocalizedMessage();
+ `}
+
+ # Java implementation: java.lang.Throwable.printStackTrace()
+ fun print_stack_trace in "Java" `{
+ self.printStackTrace();
+ `}
+
+ # Java implementation: java.lang.Throwable java.lang.Throwable.getCause()
+ fun cause: JavaThrowable in "Java" `{
+ return self.getCause();
+ `}
+
+ redef fun new_global_ref import sys, Sys.jni_env `{
+ Sys sys = JavaThrowable_sys(self);
+ JNIEnv *env = Sys_jni_env(sys);
+ return (*env)->NewGlobalRef(env, self);
+ `}
+
+ redef fun pop_from_local_frame_with_env(jni_env) `{
+ return (*jni_env)->PopLocalFrame(jni_env, self);
+ `}
+end
+
+# Java class: java.lang.Exception
+extern class JavaException in "Java" `{ java.lang.Exception `}
+ super JavaThrowable
+
+ redef fun new_global_ref import sys, Sys.jni_env `{
+ Sys sys = JavaException_sys(self);
+ JNIEnv *env = Sys_jni_env(sys);
+ return (*env)->NewGlobalRef(env, self);
+ `}
+
+ redef fun pop_from_local_frame_with_env(jni_env) `{
+ return (*jni_env)->PopLocalFrame(jni_env, self);
+ `}
+end
end
end
+redef class Text
+
+ # Deserialize a `nullable Object` from this JSON formatted string
+ #
+ # Warning: Deserialization errors are reported with `print_error` and
+ # may be returned as a partial object or as `null`.
+ #
+ # This method is not appropriate when errors need to be handled programmatically,
+ # manually use a `JsonDeserializer` in such cases.
+ fun from_json_string: nullable Object
+ do
+ var deserializer = new JsonDeserializer(self)
+ var res = deserializer.deserialize
+ if deserializer.errors.not_empty then
+ print_error "Deserialization Errors: {deserializer.errors.join(", ")}"
+ end
+ return res
+ end
+end
+
redef class Serializable
private fun serialize_to_json(v: JsonSerializer)
do
v.stream.write "\}"
end
+ # Serialize this object to a JSON string with metadata for deserialization
+ fun to_json_string: String
+ do
+ var stream = new StringWriter
+ var serializer = new JsonSerializer(stream)
+ serializer.serialize self
+ stream.close
+ return stream.to_s
+ end
+
# Serialize this object to plain JSON
#
# This is a shortcut using `JsonSerializer::plain_json`,
end
end
- redef init from_deserializer(v: Deserializer)
+ redef init from_deserializer(v)
do
super
if v isa JsonDeserializer then
end
end
- # Instantiate a new `Array` from its serialized representation.
- redef init from_deserializer(v: Deserializer)
+ redef init from_deserializer(v)
do
super
}
return env;
`}
+
+ # Detach the calling thread from this JVM
+ fun detach_current_thread import jni_error `{
+ int res = (*self)->DetachCurrentThread(self);
+ if (res != JNI_OK) {
+ JavaVM_jni_error(NULL, "Could not detach current thread to Java VM", res);
+ }
+ `}
end
# Represents a jni JNIEnv, which is a thread in a JavaVM
redef fun write_byte(byte) do native_buffer_event.write_byte(byte)
+ redef fun write_bytes(bytes) do native_buffer_event.write(bytes.items, bytes.length)
+
# Write a file to the connection
#
- # require: `path.file_exists`
+ # If `not path.file_exists`, the method returns.
fun write_file(path: String)
do
- assert path.file_exists
-
var file = new FileReader.open(path)
- var output = native_buffer_event.output_buffer
- var fd = file.fd
- var length = file.file_stat.size
+ if file.last_error != null then
+ var error = new IOError("Failed to open file at '{path}'")
+ error.cause = file.last_error
+ self.last_error = error
+ file.close
+ return
+ end
+
+ var stat = file.file_stat
+ if stat == null then
+ last_error = new IOError("Failed to stat file at '{path}'")
+ file.close
+ return
+ end
- output.add_file(fd, 0, length)
+ var err = native_buffer_event.output_buffer.add_file(file.fd, 0, stat.size)
+ if err then
+ last_error = new IOError("Failed to add file at '{path}'")
+ file.close
+ end
end
end
# The input buffer associated to `self`
fun input_buffer: InputNativeEvBuffer `{ return bufferevent_get_input(self); `}
+
+ # Read data from this buffer
+ fun read_buffer(buf: NativeEvBuffer): Int `{ return bufferevent_read_buffer(self, buf); `}
+
+ # Write data to this buffer
+ fun write_buffer(buf: NativeEvBuffer): Int `{ return bufferevent_write_buffer(self, buf); `}
end
# A single buffer
--- /dev/null
+# 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.
+
+# Implementation of `app::http_request` using GDK and Curl
+module http_request
+
+intrude import app::http_request
+private import curl
+private import gtk::gdk
+
+redef class App
+ redef fun run_on_ui_thread(task) do gdk_threads_add_idle task
+end
+
+redef class Text
+ redef fun http_get
+ do
+ var req = new CurlHTTPRequest(to_s)
+ var rep = req.execute
+ if rep isa CurlResponseSuccess then
+ return new HttpRequestResult(rep.body_str, null, rep.status_code)
+ else
+ assert rep isa CurlResponseFailed
+ var error = new IOError(rep.error_msg)
+ return new HttpRequestResult(null, error)
+ end
+ end
+end
# Examples
-Want to see `nitcorn` in action? Examples are available at ../../examples/nitcorn/src/.
+Want to see `nitcorn` in action? Examples are available at `examples/nitcorn/src/`.
# Features and TODO list
Stephan Michaud and Maxime Bélanger.
It has been adapted to a library, and is currently maintained, by Alexis Laferrière.
-
-Other contributors:
-
-* Alexandre Terrasa
all:
mkdir -p bin/
- ../../../bin/nitc --dir bin src/nitcorn_hello_world.nit src/file_server_on_port_80.nit
+ ../../../bin/nitc --dir bin src/nitcorn_hello_world.nit src/simple_file_server.nit
xymus.net:
mkdir -p bin/
# See the License for the specific language governing permissions and
# limitations under the License.
-# Basic file server on port 80, usually requires `root` to execute
+# Basic file server on port 80 by default, may require `root` to execute
#
# To be safe, it is recommended to run this program with its own username:
# `sudo file_server -u nitcorn:www`
-module file_server_on_port_80
+module simple_file_server
import nitcorn
import privileges
# Prepare options
var opts = new OptionContext
var opt_drop = new OptionUserAndGroup.for_dropping_privileges
-opt_drop.mandatory = true
+var opt_port = new OptionInt("Server port", 80, "--port", "-p")
var opt_help = new OptionBool("Print this message", "--help", "-h")
-opts.add_option(opt_drop, opt_help)
-opts.parse(args)
+opts.add_option(opt_drop, opt_port, opt_help)
+opts.parse args
# Check options errors and help
if not opts.errors.is_empty or opt_help.value then
end
# Serve everything with a standard FilesHandler
-var vh = new VirtualHost("localhost:80")
+var vh = new VirtualHost("localhost:{opt_port.value}")
vh.routes.add new Route(null, new FileServer("www/hello_world/"))
var factory = new HttpFactory.and_libevent
factory.config.virtual_hosts.add vh
response.header["Content-Type"] = media_types["html"].as(not null)
else
# It's a single file
- var file = new FileReader.open(local_file)
- response.body = file.read_all
+ response.files.add local_file
var ext = local_file.file_extension
if ext != null then
response.header["Content-Type"] = media_type
else response.header["Content-Type"] = "application/octet-stream"
end
-
- file.close
end
else response = new HttpResponse(404)
# Body of this response
var body = "" is writable
+ # Files appended after `body`
+ var files = new Array[String]
+
# Finalize this response before sending it over HTTP
fun finalize
do
# Set the content length if not already set
if not header.keys.has("Content-Length") then
- header["Content-Length"] = body.bytelen.to_s
+ # Size of the body
+ var len = body.bytelen
+
+ # Size of included files
+ for path in files do
+ # TODO handle these error cases elsewhere, an error here will result in an invalid response
+ if not path.file_exists then
+ print_error "File does not exists at '{path}'"
+ continue
+ end
+
+ var stat = path.file_stat
+ if stat == null then
+ print_error "Failed to stat file at '{path}'"
+ continue
+ end
+
+ len += stat.size
+ end
+
+ # Set header
+ header["Content-Length"] = len.to_s
end
# Set server ID
tags=network,lib
maintainer=Alexis Laferrière <alexis.laf@xymus.net>
license=Apache-2.0
+more_contributors=Jean-Philippe Caissy <jean-philippe.caissy@shopify.com>, Guillaume Auger, Frederic Sevillano, Justin Michaud-Ouellette, Stephan Michaud, Maxime Bélanger
[upstream]
browse=https://github.com/nitlang/nit/tree/master/lib/nitcorn/
git=https://github.com/nitlang/nit.git
# Send back a response
write response.to_s
+ for path in response.files do write_file path
+
close
end
end
v.serialize_attribute("item", first)
end
end
+
+redef class Error
+ super Serializable
+
+ redef init from_deserializer(v)
+ do
+ v.notify_of_creation self
+
+ var message = v.deserialize_attribute("message")
+ if not message isa String then message = ""
+ init message
+
+ var cause = v.deserialize_attribute("cause")
+ if cause isa nullable Error then self.cause = cause
+ end
+
+ redef fun core_serialize_to(v)
+ do
+ v.serialize_attribute("message", message)
+ v.serialize_attribute("cause", cause)
+ end
+end
v.add_decl("int main(int argc, char** argv) \{")
end
+ v.add "#ifndef ANDROID"
v.add("signal(SIGABRT, sig_handler);")
v.add("signal(SIGFPE, sig_handler);")
v.add("signal(SIGILL, sig_handler);")
v.add("signal(SIGINT, sig_handler);")
v.add("signal(SIGTERM, sig_handler);")
v.add("signal(SIGSEGV, sig_handler);")
+ v.add "#endif"
v.add("signal(SIGPIPE, SIG_IGN);")
v.add("glob_argc = argc; glob_argv = argv;")
# Here we load an process all modules passed on the command line
var mmodules = modelbuilder.parse(arguments)
-if mmodules.is_empty then
- toolcontext.check_errors
- toolcontext.errors_info
- if toolcontext.error_count > 0 then exit(1) else exit(0)
-end
+if mmodules.is_empty then toolcontext.quit
modelbuilder.run_phases
v.add_abort("type null")
v.add("\}")
v.add("if({t}->table_size < 0) \{")
- v.add("PRINT_ERROR(\"Insantiation of a dead type: %s\\n\", {t}->name);")
+ v.add("PRINT_ERROR(\"Instantiation of a dead type: %s\\n\", {t}->name);")
v.add_abort("type dead")
v.add("\}")
end
for cb in callbacks do
jni_methods.add_all(cb.jni_methods_declaration(self))
end
+ for cb in callbacks_used_from_java.types do
+ jni_methods.add_all(cb.jni_methods_declaration(self))
+ end
var cf = new CFunction("void nit_ffi_with_java_register_natives(JNIEnv* env, jclass jclazz)")
cf.exprs.add """
# Used by `JavaLanguage::compile_extern_method` when calling JNI's `CallStatic*Method`.
# This strategy is used by JNI to type the return of callbacks to Java.
private fun jni_signature_alt: String do return "Int"
+
+ redef fun compile_callback_to_java(mmodule, mainmodule, ccu)
+ do
+ var java_file = mmodule.java_file
+ if java_file == null then return
+
+ for variation in ["incr", "decr"] do
+ var friendly_name = "{mangled_cname}_{variation}_ref"
+
+ # C
+ var csignature = "void {mmodule.impl_java_class_name}_{friendly_name}(JNIEnv *env, jclass clazz, jint object)"
+ var cf = new CFunction("JNIEXPORT {csignature}")
+ cf.exprs.add "\tnitni_global_ref_{variation}((void*)(long)object);"
+ ccu.add_non_static_local_function cf
+
+ # Java
+ java_file.class_content.add "private native static void {friendly_name}(int object);\n"
+ end
+ end
+
+ redef fun jni_methods_declaration(from_mmodule)
+ do
+ var arr = new Array[String]
+ for variation in ["incr", "decr"] do
+ var friendly_name = "{mangled_cname}_{variation}_ref"
+ var jni_format = "(I)V"
+ var cname = "{from_mmodule.impl_java_class_name}_{friendly_name}"
+ arr.add """{"{{{friendly_name}}}", "{{{jni_format}}}", {{{cname}}}}"""
+ end
+
+ return arr
+ end
end
redef class MClassType
if toolcontext.opt_only_parse.value then
self.toolcontext.info("*** ONLY PARSE...", 1)
- exit(0)
+ self.toolcontext.quit
end
return mmodules.to_a
if toolcontext.opt_only_parse.value then
self.toolcontext.info("*** ONLY PARSE...", 1)
- exit(0)
+ self.toolcontext.quit
end
return mmodules.to_a
if toolcontext.opt_only_metamodel.value then
self.toolcontext.info("*** ONLY METAMODEL", 1)
- exit(0)
+ toolcontext.quit
end
end
# REQUIRE: classes of imported modules are already build. (let `phase` do the job)
private fun build_classes(nmodule: AModule)
do
- var errcount = toolcontext.error_count
# Force building recursively
if nmodule.build_classes_is_done then return
nmodule.build_classes_is_done = true
if nimp != null then build_classes(nimp)
end
- if errcount != toolcontext.error_count then return
-
# Create all classes
# process AStdClassdef before so that non-AStdClassdef classes can be attached to existing ones, if any
for nclassdef in nmodule.n_classdefs do
self.build_a_mclass(nmodule, nclassdef)
end
- if errcount != toolcontext.error_count then return
-
# Create all classdefs
for nclassdef in nmodule.n_classdefs do
if not nclassdef isa AStdClassdef then continue
self.build_a_mclassdef(nmodule, nclassdef)
end
- if errcount != toolcontext.error_count then return
-
# Create inheritance on all classdefs
for nclassdef in nmodule.n_classdefs do
self.collect_a_mclassdef_inheritance(nmodule, nclassdef)
end
- if errcount != toolcontext.error_count then return
-
# Create the mclassdef hierarchy
for mclassdef in mmodule.mclassdefs do
mclassdef.add_in_hierarchy
end
- if errcount != toolcontext.error_count then return
-
# Check inheritance
for nclassdef in nmodule.n_classdefs do
self.check_supertypes(nmodule, nclassdef)
end
- if errcount != toolcontext.error_count then return
-
# Check unchecked ntypes
for nclassdef in nmodule.n_classdefs do
if nclassdef isa AStdClassdef then
end
end
- if errcount != toolcontext.error_count then return
-
# Check clash of ancestors
for nclassdef in nmodule.n_classdefs do
var mclassdef = nclassdef.mclassdef
end
end
- if errcount != toolcontext.error_count then return
-
# TODO: Check that the super-class is not intrusive
# Check that the superclasses are not already known (by transitivity)
for nclassdef in nmodule.n_classdefs do
- if not nclassdef isa AStdClassdef then continue
+ if not nclassdef isa AStdClassdef or nclassdef.is_broken then continue
var mclassdef = nclassdef.mclassdef
if mclassdef == null then continue
modelbuilder.run_phases
-if toolcontext.opt_only_metamodel.value then exit(0)
+if toolcontext.opt_only_metamodel.value then toolcontext.quit
var mainmodule = toolcontext.make_main_module(mmodules)
end
var contributors = mpackage.contributors
+ var more_contributors = mpackage.metadata("package.more_contributors")
+ if more_contributors != null then
+ for c in more_contributors.split(",") do
+ contributors.add c.trim
+ end
+ end
if not contributors.is_empty then
res.add "<h3>Contributors</h3>\n<ul class=\"box\">"
for c in contributors do
if mtype isa MGenericType and
mtype.is_subtype(m, null, serializable_type) and
mtype.is_visible_from(mmodule) and
+ mtype.mclass.kind == concrete_kind and
not compiled_types.has(mtype) then
compiled_types.add mtype
mmodules.add_all modelbuilder.parse(opt_mixins.value)
modelbuilder.run_phases
-if toolcontext.opt_only_metamodel.value then exit(0)
+if toolcontext.opt_only_metamodel.value then toolcontext.quit
var mainmodule: nullable MModule
redef fun name do return "android"
- redef fun supports_libgc do return true
+ redef fun supports_libgc do return false
redef fun supports_libunwind do return false
## Generate Application.mk
dir = "{android_project_root}/jni/"
"""
-APP_ABI := armeabi armeabi-v7a x86 mips
+APP_ABI := armeabi armeabi-v7a x86
APP_PLATFORM := android-{{{app_target_api}}}
""".write_to_file "{dir}/Application.mk"
fun do_auto_super_init(modelbuilder: ModelBuilder)
do
var mclassdef = self.parent.as(AClassdef).mclassdef
- if mclassdef == null then return # skip error
+ if mclassdef == null or mclassdef.is_broken then return # skip error
var mpropdef = self.mpropdef
- if mpropdef == null then return # skip error
+ if mpropdef == null or mpropdef.is_broken then return # skip error
var mmodule = mpropdef.mclassdef.mmodule
var anchor = mclassdef.bound_mtype
var recvtype = mclassdef.mclass.mclass_type
if candidate.is_root_init then continue
var candidatedefs = candidate.lookup_definitions(mmodule, anchor)
+ if candidatedefs.is_empty then
+ # skip broken
+ is_broken = true
+ return
+ end
var candidatedef = candidatedefs.first
# TODO, we drop the others propdefs in the callsite, that is not great :(
var the_root_init_mmethod = modelbuilder.the_root_init_mmethod
if the_root_init_mmethod != null and auto_super_inits.is_empty then
var candidatedefs = the_root_init_mmethod.lookup_definitions(mmodule, anchor)
+ if candidatedefs.is_empty then
+ # skip broken
+ is_broken = true
+ return
+ end
# Search the longest-one and checks for conflict
var candidatedef = candidatedefs.first
#node.debug("Unsafe typing: expected {sup}, got {sub}")
return sup
end
+ if sup isa MBottomType then return null # Skip error
if sub.need_anchor then
var u = anchor_to(sub)
self.modelbuilder.error(node, "Type Error: expected `{sup}`, got `{sub}: {u}`.")
var mtype = v.visit_expr(g.n_expr)
if mtype == null then return
g.do_type_iterator(v, mtype)
+ if g.is_broken then is_broken = true
end
v.visit_stmt(n_block)
return tags.has("all") or tags.has(tag)
end
+ # Output all current stacked messages, total and exit the program
+ #
+ # If there is no error, exit with 0, else exit with 1.
+ fun quit
+ do
+ check_errors
+ errors_info
+ if error_count > 0 then exit(1) else exit(0)
+ end
+
# Output all current stacked messages
#
# Return true if no errors occurred.
# limitations under the License.
var i = [4, '4']
+i.first.output
var toto: Int
var toto: Object
end
+
+var a = new A
+a.toto.output
_toto = 't'
end
end
+
+var a = new A(1)
+a.m
end
class C[E: Object, F: Object]
end
+
+var c = new C
+c.output
class A[E: Object]
end
+
+var a = new A
+a.output
end
class A[E: Object]
end
+
+var a = new A
+a.output
# limitations under the License.
var i: Int = '4'
+i.output
# limitations under the License.
for i in 5 do
+ i.output
end
class A[T]
var k: T[Int]
end
+
+var a = new A[Object]
+a.output
class G[Foo]
type Bar: Object
end
+
+var g = new G[Object]
fun toto: Int
do
end
+
+toto.output
return 0
end
end
+
+toto.output
return 1
end
end
+
+toto.output
return 1
end
end
+
+toto.output
return 1
end
end
+
+toto.output
super G1
super G2
end
+
+var g = new G3
+g.output
# limitations under the License.
if 5 then
+ 1.output
end
super Array[Int]
super Array[Char]
end
+
+var a = new A
+a.output
super A
super B
end
+
+var c = new C
+c.output
super A[Int]
super B[Char]
end
+
+var c = new C
+c.output
super Array[E]
super List[F]
end
+
+var a = new A[Int, Int]
+a.output
class C
super A
end
+
+var a = new A
+a.output
redef class Object
var toto: Bool
end
+
+toto.output
redef class Int
var toto: Object
end
+
+1.toto.output
# limitations under the License.
if 5 and true then
+ 1.output
end
# limitations under the License.
while 5 do
+ 1.output
end
fun toto(a: Int) do end
fun toto(a: Char) do end
end
+
+var a = new A
+a.toto(1)
fun toto(a: Int) do end
fun toto(a: Int): Int do return 0 end
end
+
+var a = new A
+a.toto(1).output
class A end
class A end
+var a = new A
+a.output
redef class A end
redef class A end
+var a = new A
+a.output
import kernel
redef class Fail end
+
+var f = new Fail
+f.output
redef class C
redef var a: Int
end
+
+var c = new C(new B)
+c.a.output
redef class C
redef fun s do end
end
+
+var c = new C(new B)
+c.s.output
redef class C
redef fun r(x: C) do end
end
+
+var c = new C(new B)
+c.r
redef class C
redef fun r(x: B): B do return self end
end
+
+var c = new C(new B)
+c.r
redef class C
redef fun s: Int do return 1 end
end
+
+var c = new C(new B)
+c.s.output
do
return
end
+
+toto.output
do
return '4'
end
+
+(toto+1).output
# limitations under the License.
if true or 6 then
+ 1.output
end
super A
redef fun foo: Int do return 3
end
+
+var a = new A
+a.foo.output
+
+var b = new B
+b.foo
+
+var c = new C
+c.foo
super A
redef var a: Object = 2
end
+
+var b = new B
+b.a.output
super A
redef fun toto do end
end
+
+var b = new B
+b.toto.output
super A
redef fun toto(c: Object) do end
end
+
+var b = new B
+b.toto(true)
super A
redef fun toto(c: Char) do end
end
+
+var b = new B
+b.toto(true)
class B
super A
-redef fun toto: Int do return 2end
+redef fun toto: Int do return 2 end
end
+
+var b = new B
+b.toto.output
super A
redef fun toto: Char do return 'a' end
end
+
+var b = new B
+b.toto.output
super
end
end
+
+var a = new A
+a.foo
super Fail
end
+var a = new A
+a.output
super Array[Fail]
end
+var b = new B
+b.output
class D[T: Array[Fail]]
end
+
+var c = new C[Int]
+c.output
+var d = new D[Int]
+d.output
fun md: Array[Fail] do return 0
end
+var e = new E
+e.output
+var f = new F
+f.output
+var g = new G
+g.a.output
+g.ma(1)
+g.mb(1)
+g.mc(1).output
+g.md(1).output
# limitations under the License.
var i = new Canard
+i.output
+++ /dev/null
-Mandatory option -u, --usergroup not found.
-Usage: file_server [Options]
- -u, --usergroup Drop privileges to user:group or simply user
- --help, -h Print this message
--- /dev/null
+libevent warning: Opening localhost:80 failed
--- /dev/null
+# 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.
+
+import java
+
+class A
+ fun foo in "Java" `{
+ A_incr_ref(self);
+ System.out.println("a");
+ A_decr_ref(self);
+ System.out.println("b");
+ `}
+end
+
+var a = new A
+a.foo