The `neo` module can be used to save or load a model from a Neo4j graph database.
Next pull requests will bring tools based on `neo`.
Pull-Request: #606
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
NITCOPT=
-all: tools doc/stdlib/index.html
+all: tools
docs: doc/stdlib/index.html doc/nitc/index.html
- #cd doc; make
tools:
cd src; make
+++ /dev/null
-all:
- ./git-gen-version.sh
- rubber --pdf --inplace nitreference/nitreference.tex
- rubber --pdf --inplace developpez/nit.tex
-
-clean:
- rm nit_version.sty 2> /dev/null || true
- rubber --clean --inplace nitreference/nitreference.tex
- rubber --clean --inplace developpez/nit.tex
-
-distclean: clean
- rm nitreference/nitreference.pdf developpez/nit.pdf 2> /dev/null || true
+++ /dev/null
-#!/bin/sh
-
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2008 Jean Privat <jean@pryen.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.
-
-# This program is used to generate version number from git refs.
-# The version number is stored in a dedicated Nit module.
-
-gen_version() {
- if ! grep "$*" nit_version.sty >/dev/null 2>&1; then
- cat > nit_version.sty<<END
-% This file was generated by git-gen-version.sh
-\\newcommand\\nitversion{$*}
-END
- echo "Version $*"
- fi
-}
-
-VN=$(git describe --always HEAD 2>/dev/null)
-if [ "$?" != "0" ]; then
- if [ -r ../VERSION ]; then
- VN="$(cat ../VERSION)"
- else
- echo >&2 "Error: no VERSION file and not a .git repository."
- exit 1
- fi
-fi
-if [ -z "$VN" ]; then
- VN="undefined"
-fi
-if [ -n "$1" ]; then
- VN="${VN}-$1"
-fi
-if [ -n "$(git diff HEAD 2>/dev/null)" ]; then
- VN="${VN}-dirty"
-fi
-
-gen_version "$VN"
# Classic moles game
#
# This is a minimal practical example of the mnit framework.
-module moles
+module moles is
+ app_name("Crazy Groundhogs")
+end
import mnit
android:
mkdir -p bin
- ../../bin/nitg -o bin/simple.apk src/simple_android.nit
+ ../../bin/nitg -o bin/simple.apk src/complete_simple_android.nit
clean:
rm -rf bin
--- /dev/null
+#FIXME: Improper way of resolving unjustified metadata conflict
+module complete_simple_android is
+ app_name("test all")
+ java_package("org.nitlanguage.test_all")
+ app_version(1, 0)
+end
+
+import test_bundle
+import test_audio
+import test_shared_preferences
+import test_assets_and_resources
+import test_target_api
import simple
import mnit_android
-import android::bundle
-import android::shared_preferences
-import android::assets_and_resources
-import android::audio
+import serialization
in "Java" `{
import android.content.Context;
`}
redef class App
- var soundsp: Sound
- var soundmp: Sound
-
- redef fun init_window
- do
- super
- manage_audio_mode
- # retrieve sound
- soundsp = load_sound("sound.ogg")
- soundmp = load_music("xylofon.ogg")
- default_mediaplayer.looping = true
- default_mediaplayer.prepare
- soundmp.play
- end
-
redef fun input( ie )
do
if ie isa PointerEvent and ie.depressed then
- do_java_stuff
- test_bundle
- test_shared_preferences
- soundsp.play
- test_assets
- test_resources
+ test_java_ffi
end
return super
end
- #testing the assets manager
- fun test_assets
- do
- assert asset_manager.bitmap("fighter.png") != null
- end
-
- #testing the resources manager
- fun test_resources do
- assert resource_manager.string("string_test") == "string test"
- assert resource_manager.boolean("test_bool") == true
- assert resource_manager.dimension("test_dimen_1") != null
- assert resource_manager.dimension("test_dimen_2") != null
- end
-
- fun test_bundle
- do
- var bundle = new Bundle(self)
-
- bundle["anInt"] = 1
- bundle["aFloat"] = 1.1
- bundle["aString"] = "A string"
- bundle["aBool"] = true
-
- var int_array = new Array[Int]
- var bool_array = new Array[Bool]
-
- var value = true
-
- for i in [0..5] do
- int_array.add(i)
- bool_array.add(value)
- value = not value
- end
-
- bundle["anArrayOfInt"] = int_array
- bundle["anArrayOfBool"] = bool_array
-
- assert bundle.int("anInt", 0) == 1
- assert bundle.int("wrongInt", 0) == 0
- assert bundle.float("aFloat", 0.0) == 1.1
- assert bundle.float("wrongFloat", 0.0) == 0.0
- assert bundle.string("aString") == "A string"
- assert bundle.string("wrongString") == null
- assert bundle.bool("aBool", false)
- assert bundle.bool("wrongBool", false) == false
-
- var int_array_test = bundle.array_of_int("anArrayOfInt")
- var bool_array_test = bundle.array_of_bool("anArrayOfBool")
-
- value = true
-
- for i in [0..5] do
- assert int_array_test[i] == i
- assert bool_array_test[i] == value
- value = not value
- end
-
- assert bundle.size == 6
- assert bundle.has("aBool")
- assert not bundle.is_empty
-
- bundle.remove("aString")
- bundle.remove("anArrayOfBool")
-
- assert bundle.string("aString") == null
- assert bundle.array_of_bool("anArrayOfBool") == null
-
- # Serializable tests
- var p1 = new Point(10, 10)
- bundle["aPoint"] = p1
- var p2 = bundle.deserialize("aPoint")
-
- assert p1.to_s == p2.to_s
-
- var point_array = new Array[Point]
-
- for i in [0..5] do point_array.add(new Point(i, i))
-
- bundle["anArrayOfPoint"] = point_array
-
- var deserialized_point_array = bundle.deserialize_array("anArrayOfPoint")
-
- for i in [0..5] do
- var point = new Point(i, i)
- assert deserialized_point_array[i].to_s == point.to_s
- end
-
- bundle.clear
-
- assert bundle.keys.is_empty
- assert bundle.is_empty
- end
-
- fun test_shared_preferences
- do
- # Private mode tests
- var sp = new SharedPreferences.privately(self, "test")
- sp.add_bool("a_boolean", true)
- sp.add_float("a_float", 66.6)
- sp.add_int("an_int", 666)
- sp.add_int("a_second_int", 666777)
- sp.add_long("a_long", 6666666666)
- sp.add_string("a_string", "A string")
- sp["another_int"] = 85
- sp["yet_another_string"] = "Another string"
- sp.remove("a_second_int")
-
- # Serialized object test
- var my_point = new Point(10, 10)
- sp["a_point"] = my_point
- var my_deserialized_point = sp["a_point"]
- assert my_point.to_s == my_deserialized_point.to_s
-
- assert sp.bool("a_boolean", false) == true
- assert sp.bool("wrong_boolean", false) == false
- assert sp.float("a_float", 0.0) != 0.0
- assert sp.float("wrong_float", 0.0) == 0.0
- assert sp.int("an_int", 0) == 666
- assert sp.int("a_second_int", 0) == 0
- assert sp.long("a_long", 0) == 6666666666
- assert sp.long("wrong_long", 0) == 0
- assert sp.string("a_string", "ERROR!") == "A string"
- assert sp.string("wrong_string", "ERROR!") == "ERROR!"
- assert sp.long("another_int", 0) == 85
- assert sp.string("yet_another_string", "ERROR!") == "Another string"
- assert sp.has("an_int") == true
- assert sp.has("a_second_int") == false
-
- sp.clear
- assert sp.all == null
-
- sp.destroy
- end
-
- fun do_java_stuff import native_activity in "Java" `{
+ fun test_java_ffi import native_activity in "Java" `{
// + Log (no context needed)
android.util.Log.d("mnit_simple", "Java within NIT!!!");
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
+#
+# 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.
+
+# Test for the asserts_and_resources module of App.nit framework
+module test_assets_and_resources
+
+import simple_android
+import android::assets_and_resources
+
+redef class App
+ redef fun input( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ test_assets
+ test_resources
+ end
+ return super
+ end
+
+ # Testing the assets manager
+ fun test_assets
+ do
+ assert asset_manager.bitmap("fighter.png") != null
+ end
+
+ # Testing the resources manager
+ fun test_resources do
+ assert resource_manager.string("string_test") == "string test"
+ assert resource_manager.boolean("test_bool") == true
+ assert resource_manager.dimension("test_dimen_1") != null
+ assert resource_manager.dimension("test_dimen_2") != null
+ end
+end
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
+#
+# 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.
+
+# Test for the audio module of App.nit framework
+module test_audio
+
+import simple_android
+import android::audio
+
+redef class App
+ var soundsp: Sound
+ var soundmp: Sound
+
+ redef fun init_window
+ do
+ super
+ manage_audio_mode
+
+ # Retrieve sound
+ soundsp = load_sound("sound.ogg")
+ soundmp = load_music("xylofon.ogg")
+ default_mediaplayer.looping = true
+ default_mediaplayer.prepare
+ soundmp.play
+ end
+
+ redef fun input( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ soundsp.play
+ end
+ return super
+ end
+end
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
+#
+# 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.
+
+# Test for the bundle module of App.nit framework
+module test_bundle
+
+import simple_android
+import android::bundle
+
+redef class App
+ redef fun input ( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ test_bundle
+ end
+ return super
+ end
+
+ fun test_bundle
+ do
+ var bundle = new Bundle(self)
+
+ bundle["anInt"] = 1
+ bundle["aFloat"] = 1.1
+ bundle["aString"] = "A string"
+ bundle["aBool"] = true
+
+ var int_array = new Array[Int]
+ var bool_array = new Array[Bool]
+
+ var value = true
+
+ for i in [0..5] do
+ int_array.add(i)
+ bool_array.add(value)
+ value = not value
+ end
+
+ bundle["anArrayOfInt"] = int_array
+ bundle["anArrayOfBool"] = bool_array
+
+ assert bundle.int("anInt", 0) == 1
+ assert bundle.int("wrongInt", 0) == 0
+ assert bundle.float("aFloat", 0.0) == 1.1
+ assert bundle.float("wrongFloat", 0.0) == 0.0
+ assert bundle.string("aString") == "A string"
+ assert bundle.string("wrongString") == null
+ assert bundle.bool("aBool", false)
+ assert bundle.bool("wrongBool", false) == false
+
+ var int_array_test = bundle.array_of_int("anArrayOfInt")
+ var bool_array_test = bundle.array_of_bool("anArrayOfBool")
+
+ value = true
+
+ for i in [0..5] do
+ assert int_array_test[i] == i
+ assert bool_array_test[i] == value
+ value = not value
+ end
+
+ assert bundle.size == 6
+ assert bundle.has("aBool")
+ assert not bundle.is_empty
+
+ bundle.remove("aString")
+ bundle.remove("anArrayOfBool")
+
+ assert bundle.string("aString") == null
+ assert bundle.array_of_bool("anArrayOfBool") == null
+
+ # Serializable tests
+ var p1 = new Point(10, 10)
+ bundle["aPoint"] = p1
+ var p2 = bundle.deserialize("aPoint")
+
+ assert p1.to_s == p2.to_s
+
+ var point_array = new Array[Point]
+
+ for i in [0..5] do point_array.add(new Point(i, i))
+
+ bundle["anArrayOfPoint"] = point_array
+
+ var deserialized_point_array = bundle.deserialize_array("anArrayOfPoint")
+
+ for i in [0..5] do
+ var point = new Point(i, i)
+ assert deserialized_point_array[i].to_s == point.to_s
+ end
+
+ bundle.clear
+
+ assert bundle.keys.is_empty
+ assert bundle.is_empty
+ end
+end
+
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
+#
+# 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.
+
+# Test for the shared_preferences module of App.nit framework
+module test_shared_preferences
+
+import simple_android
+import android::shared_preferences
+
+redef class App
+ redef fun input ( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ test_shared_preferences
+ end
+ return super
+ end
+
+ fun test_shared_preferences
+ do
+ # Private mode tests
+ var sp = new SharedPreferences.privately(self, "test")
+ sp.add_bool("a_boolean", true)
+ sp.add_float("a_float", 66.6)
+ sp.add_int("an_int", 666)
+ sp.add_int("a_second_int", 666777)
+ sp.add_long("a_long", 6666666666)
+ sp.add_string("a_string", "A string")
+ sp["another_int"] = 85
+ sp["yet_another_string"] = "Another string"
+ sp.remove("a_second_int")
+
+ # Serialized object test
+ var my_point = new Point(10, 10)
+ sp["a_point"] = my_point
+ var my_deserialized_point = sp["a_point"]
+ assert my_point.to_s == my_deserialized_point.to_s
+
+ assert sp.bool("a_boolean", false) == true
+ assert sp.bool("wrong_boolean", false) == false
+ assert sp.float("a_float", 0.0) != 0.0
+ assert sp.float("wrong_float", 0.0) == 0.0
+ assert sp.int("an_int", 0) == 666
+ assert sp.int("a_second_int", 0) == 0
+ assert sp.long("a_long", 0) == 6666666666
+ assert sp.long("wrong_long", 0) == 0
+ assert sp.string("a_string", "ERROR!") == "A string"
+ assert sp.string("wrong_string", "ERROR!") == "ERROR!"
+ assert sp["another_int"] == 85
+ assert sp["yet_another_string"] == "Another string"
+ assert sp.has("an_int") == true
+ assert sp.has("a_second_int") == false
+
+ sp.clear
+ assert sp.all == null
+
+ sp.destroy
+ end
+end
# Test for the API level related annotations
module test_target_api is
- min_sdk_version(10)
- max_sdk_version(19)
- target_sdk_version(11)
+ min_api_version(10)
+ max_api_version(19)
+ target_api_version(11)
end
import simple_android
redef type SELF: NativeResources
fun get_assets:NativeAssetManager in "Java" `{ return recv.getAssets(); `}
- fun get_color(id: Int): Int in "Java" `{ return recv.getColor(id); `}
- fun get_boolean(id: Int): Bool in "Java" `{ return recv.getBoolean(id); `}
- fun get_dimension(id: Int): Int in "Java" `{ return (int)recv.getDimension(id); `}
- fun get_drawable(id: Int): NativeDrawable in "Java" `{ return recv.getDrawable(id); `}
+ fun get_color(id: Int): Int in "Java" `{ return recv.getColor((int)id); `}
+ fun get_boolean(id: Int): Bool in "Java" `{ return recv.getBoolean((int)id); `}
+ fun get_dimension(id: Int): Int in "Java" `{ return (int)recv.getDimension((int)id); `}
+ fun get_drawable(id: Int): NativeDrawable in "Java" `{ return recv.getDrawable((int)id); `}
fun get_identifier(name, def_type, def_package: JavaString): Int in "Java" `{ return recv.getIdentifier(name, def_type, def_package); `}
- fun get_integer(id: Int): Int in "Java" `{ return recv.getInteger(id); `}
- fun get_string(id: Int): JavaString in "Java" `{ return recv.getString(id); `}
- fun get_resource_entry_name(resid: Int): JavaString in "Java" `{ return recv.getResourceEntryName(resid); `}
- fun get_resource_name(resid: Int): JavaString in "Java" `{ return recv.getResourceName(resid); `}
- fun get_resource_pakage_name(resid: Int): JavaString in "Java" `{ return recv.getResourcePackageName(resid); `}
- fun get_resource_type_name(resid: Int): JavaString in "Java" `{ return recv.getResourceTypeName(resid); `}
+ fun get_integer(id: Int): Int in "Java" `{ return recv.getInteger((int)id); `}
+ fun get_string(id: Int): JavaString in "Java" `{ return recv.getString((int)id); `}
+ fun get_resource_entry_name(resid: Int): JavaString in "Java" `{ return recv.getResourceEntryName((int)resid); `}
+ fun get_resource_name(resid: Int): JavaString in "Java" `{ return recv.getResourceName((int)resid); `}
+ fun get_resource_pakage_name(resid: Int): JavaString in "Java" `{ return recv.getResourcePackageName((int)resid); `}
+ fun get_resource_type_name(resid: Int): JavaString in "Java" `{ return recv.getResourceTypeName((int)resid); `}
end
# Resource manager for android resources placed in the `res` folder of your app
# Create a NativeBitmap using a resource ID and the NativeResources
# Called by the ResourceManager
- new from_resources(res: NativeResources, id: Int) in "Java" `{ return BitmapFactory.decodeResource(res, id); `}
+ new from_resources(res: NativeResources, id: Int) in "Java" `{ return BitmapFactory.decodeResource(res, (int)id); `}
fun width: Int in "Java" `{ return recv.getWidth(); `}
fun height: Int in "Java" `{ return recv.getHeight(); `}
end
redef type SELF: NativeAudioManager
fun mode: Int in "Java" `{ return recv.getMode(); `}
- fun mode=(i: Int) in "Java" `{ recv.setMode(i); `}
+ fun mode=(i: Int) in "Java" `{ recv.setMode((int)i); `}
fun wired_headset_on: Bool in "Java" `{ return recv.isWiredHeadsetOn(); `}
fun wired_headset_on=(b: Bool) in "Java" `{ recv.setWiredHeadsetOn(b); `}
fun speakerphone_on: Bool in "Java" `{ return recv.isSpeakerphoneOn(); `}
}
`}
- fun create(context: NativeActivity, id: Int): NativeMediaPlayer in "Java" `{ return recv.create(context, id); `}
+ fun create(context: NativeActivity, id: Int): NativeMediaPlayer in "Java" `{ return recv.create(context, (int)id); `}
fun pause in "Java" `{ recv.pause(); `}
fun stop in "Java" `{ recv.stop(); `}
fun playing: Bool in "Java" `{ return recv.isPlaying(); `}
fun looping=(b: Bool) in "Java" `{ recv.setLooping(b); `}
fun volume=(vol: Float) in "Java" `{ recv.setVolume((float)vol, (float)vol); `}
fun both_volume(left_volume, right_volume: Float) in "Java" `{ recv.setVolume((float)left_volume, (float)right_volume); `}
- fun stream_type=(stream_type: Int) in "Java" `{ recv.setAudioStreamType(stream_type); `}
+ fun stream_type=(stream_type: Int) in "Java" `{ recv.setAudioStreamType((int)stream_type); `}
fun data_source_fd(fd: NativeFileDescriptor, start_offset, length: Int) in "Java" `{
try {
recv.setDataSource(fd, start_offset, length);
redef type SELF: NativeSoundPool
new(max_streams, stream_type, src_quality: Int) in "Java" `{
- return new SoundPool(max_streams, stream_type, src_quality);
+ return new SoundPool((int)max_streams, (int)stream_type, (int)src_quality);
`}
- fun load_asset_fd(afd: NativeAssetFileDescriptor, priority: Int): Int in "Java" `{ return recv.load(afd, priority); `}
- fun load_id(context: NativeActivity, resid, priority: Int): Int in "Java" `{ return recv.load(context, resid, priority); `}
- fun load_path(path: JavaString, priority: Int): Int in "Java" `{ return recv.load(path, priority); `}
+ fun load_asset_fd(afd: NativeAssetFileDescriptor, priority: Int): Int in "Java" `{ return recv.load(afd, (int)priority); `}
+ fun load_id(context: NativeActivity, resid, priority: Int): Int in "Java" `{ return recv.load(context, (int)resid, (int)priority); `}
+ fun load_path(path: JavaString, priority: Int): Int in "Java" `{ return recv.load(path, (int)priority); `}
fun play(sound_id: Int, left_volume, right_volume: Float, priority, l: Int, rate: Float): Int in "Java" `{
- return recv.play(sound_id, (float)left_volume, (float)right_volume, priority, l, (float)rate);
+ return recv.play((int)sound_id, (float)left_volume, (float)right_volume, (int)priority, (int)l, (float)rate);
`}
- fun pause(stream_id: Int) in "Java" `{ recv.pause(stream_id); `}
+ fun pause(stream_id: Int) in "Java" `{ recv.pause((int)stream_id); `}
fun auto_pause in "Java" `{ recv.autoPause(); `}
fun auto_resume in "Java" `{ recv.autoResume(); `}
- fun resume(stream_id: Int) in "Java" `{ recv.resume(stream_id); `}
- fun set_loop(stream_id, l: Int) in "Java" `{ recv.setLoop(stream_id, l); `}
- fun set_priority(stream_id, priority: Int) in "Java" `{ recv.setPriority(stream_id, priority); `}
- fun set_rate(stream_id: Int, rate: Float) in "Java" `{ recv.setRate(stream_id, (float)rate); `}
- fun set_volume(stream_id: Int, left_volume, right_volume: Float) in "Java" `{ recv.setVolume(stream_id, (float)left_volume, (float)right_volume); `}
- fun stop(stream_id: Int) in "Java" `{ recv.stop(stream_id); `}
- fun unload(sound_id: Int): Bool in "Java" `{ return recv.unload(sound_id); `}
+ fun resume(stream_id: Int) in "Java" `{ recv.resume((int)stream_id); `}
+ fun set_loop(stream_id, l: Int) in "Java" `{ recv.setLoop((int)stream_id, (int)l); `}
+ fun set_priority(stream_id, priority: Int) in "Java" `{ recv.setPriority((int)stream_id, (int)priority); `}
+ fun set_rate(stream_id: Int, rate: Float) in "Java" `{ recv.setRate((int)stream_id, (float)rate); `}
+ fun set_volume(stream_id: Int, left_volume, right_volume: Float) in "Java" `{ recv.setVolume((int)stream_id, (float)left_volume, (float)right_volume); `}
+ fun stop(stream_id: Int) in "Java" `{ recv.stop((int)stream_id); `}
+ fun unload(sound_id: Int): Bool in "Java" `{ return recv.unload((int)sound_id); `}
end
fun put_integer_array_list(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
ArrayList<Integer> java_array =
- new ArrayList<Integer>(Array_of_Int_length(value));
+ new ArrayList<Integer>((int) Array_of_Int_length(value));
for(int i=0; i < java_array.size(); ++i)
java_array.add((int) Array_of_Int__index(value, i));
`}
fun put_string_array_list(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
- ArrayList<String> java_array = new ArrayList<String>(Array_of_JavaString_length(value));
+ ArrayList<String> java_array = new ArrayList<String>((int)Array_of_JavaString_length(value));
for(int i=0; i < java_array.size(); ++i)
java_array.add(Array_of_JavaString__index(value, i));
fun put_char_sequence_array_list(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
ArrayList<CharSequence> java_array =
- new ArrayList<CharSequence>(Array_of_JavaString_length(value));
+ new ArrayList<CharSequence>((int)Array_of_JavaString_length(value));
for(int i=0; i < java_array.size(); ++i)
java_array.add(Array_of_JavaString__index(value, i));
`}
fun put_boolean_array(key: JavaString, value: Array[Bool])
import Array[Bool].length, Array[Bool].[] in "Java" `{
- boolean[] java_array = new boolean[Array_of_Bool_length(value)];
+ boolean[] java_array = new boolean[(int)Array_of_Bool_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Bool__index(value, i);
`}
fun put_byte_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
- byte[] java_array = new byte[Array_of_Int_length(value)];
+ byte[] java_array = new byte[(int)Array_of_Int_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = (byte) Array_of_Int__index(value, i);
`}
fun put_short_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
- short[] java_array = new short[Array_of_Int_length(value)];
+ short[] java_array = new short[(int)Array_of_Int_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = (short) Array_of_Int__index(value, i);
`}
fun put_char_array(key: JavaString, value: Array[Char])
import Array[Char].length, Array[Char].[] in "Java" `{
- char[] java_array = new char[Array_of_Char_length(value)];
+ char[] java_array = new char[(int)Array_of_Char_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Char__index(value, i);
`}
fun put_int_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
- int[] java_array = new int[Array_of_Int_length(value)];
+ int[] java_array = new int[(int)Array_of_Int_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = (int) Array_of_Int__index(value, i);
`}
fun put_long_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
- long[] java_array = new long[Array_of_Int_length(value)];
+ long[] java_array = new long[(int)Array_of_Int_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Int__index(value, i);
`}
fun put_float_array(key: JavaString, value: Array[Float])
import Array[Float].length, Array[Float].[] in "Java" `{
- float[] java_array = new float[Array_of_Float_length(value)];
+ float[] java_array = new float[(int)Array_of_Float_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = (float) Array_of_Float__index(value, i);
`}
fun put_double_array(key: JavaString, value: Array[Float])
import Array[Float].length, Array[Float].[] in "Java" `{
- double[] java_array = new double[Array_of_Float_length(value)];
+ double[] java_array = new double[(int)Array_of_Float_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Float__index(value, i);
`}
fun put_string_array(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
- String[] java_array = new String[Array_of_JavaString_length(value)];
+ String[] java_array = new String[(int)Array_of_JavaString_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_JavaString__index(value, i);
`}
fun put_char_sequence_array(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
- CharSequence[] java_array = new CharSequence[Array_of_JavaString_length(value)];
+ CharSequence[] java_array = new CharSequence[(int)Array_of_JavaString_length(value)];
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_JavaString__index(value, i);
`}
fun get_int(key: JavaString): Int in "Java" `{ return recv.getInt(key); `}
fun get_int_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
- return (int) recv.getInt(key, (int) def_value);
+ return recv.getInt(key, (int) def_value);
`}
- # FIXME: Get rid of the int cast as soon as the ffi is fixed
- fun get_long(key: JavaString): Int in "Java" `{ return (int) recv.getLong(key); `}
- # FIXME: Get rid of the int cast as soon as the ffi is fixed
+ fun get_long(key: JavaString): Int in "Java" `{ return recv.getLong(key); `}
fun get_long_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
- return (int) recv.getLong(key);
+ return recv.getLong(key);
`}
fun get_float(key: JavaString): Float in "Java" `{
return (float) recv.getFloat(key);
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
- Array_of_Int_add(nit_array, (int) java_array[i]);
+ Array_of_Int_add(nit_array, java_array[i]);
return nit_array;
`}
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
- Array_of_Int_add(nit_array, (int) java_array[i]);
+ Array_of_Int_add(nit_array, java_array[i]);
return nit_array;
`}
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
- Array_of_Int_add(nit_array, (int) java_array[i]);
+ Array_of_Int_add(nit_array, java_array[i]);
return nit_array;
`}
`}
fun write(one_byte: Int) in "Java" `{
try {
- recv.write(one_byte);
+ recv.write((byte)one_byte);
}catch(IOException e){
e.printStackTrace();
}
fun get_int(key: JavaString, def_value: Int): Int in "Java" `{
int return_value;
try {
- return_value = recv.getInt(key, def_value);
+ return_value = recv.getInt(key, (int)def_value);
} catch (ClassCastException e) {
return def_value;
}
return return_value;
`}
- #FIXME: Get rid of the `int` cast when the ffi is fixed
fun get_long(key: JavaString, def_value: Int): Int in "Java" `{
long return_value;
try {
return recv.putFloat(key, (float) value);
`}
fun put_int(key: JavaString, value: Int): NativeSharedPreferencesEditor in "Java" `{
- return recv.putInt(key, value);
+ return recv.putInt(key, (int)value);
`}
fun put_long(key: JavaString, value: Int): NativeSharedPreferencesEditor in "Java" `{
return recv.putLong(key, value);
// Uses default SharedPreferences if file_name is an empty String
if (file_name.equals("")) {
- sp = context.getPreferences( mode);
+ sp = context.getPreferences((int)mode);
} else {
- sp = context.getSharedPreferences(file_name, mode);
+ sp = context.getSharedPreferences(file_name, (int)mode);
}
SharedPreferences.Editor editor = sp.edit();
# Mainly generated method to return the next instance of the givent
# class by name
- fun deserialize_class(class_name: String): Object do abort
+ fun deserialize_class(class_name: String): Object do
+ print "Error: doesn't know how to deserialize class \"{class_name}\""
+ abort
+ end
end
# Instances of this class can be passed to `Serializer::serialize`
end
# C function to convert an nit Int to a NativeString (char*)
- private fun native_int_to_s(len: Int): NativeString is extern "native_int_to_s"
+ private fun native_int_to_s: NativeString is extern "native_int_to_s"
# return displayable int in base 10 and signed
#
# assert 1.to_s == "1"
# assert (-123).to_s == "-123"
redef fun to_s do
- var len = digit_count(10)
- return native_int_to_s(len).to_s_with_length(len)
+ return native_int_to_s.to_s
end
# return displayable int in hexadecimal
#include "string_nit.h"
// Integer to NativeString method
-char* native_int_to_s(int recv, int len){
- char* str = malloc(len + 1);
- sprintf(str, "%d", recv);
+char* native_int_to_s(long recv){
+ int len = snprintf(NULL, 0, "%ld", recv);
+ char* str = malloc(len);
+ sprintf(str, "%ld", recv);
return str;
}
* another product.
*/
-char* native_int_to_s(int recv, int len);
+char* native_int_to_s(long recv);
#endif
redef class AAttrPropdef
redef fun compile_to_c(v, mpropdef, arguments)
do
- if arguments.length == 1 then
- var res = v.read_attribute(self.mpropdef.mproperty, arguments.first)
+ if mpropdef == mreadpropdef then
+ assert arguments.length == 1
+ var res
+ if is_lazy then
+ var nexpr = n_expr
+ assert nexpr != null
+ var set
+ var ret = self.mpropdef.static_mtype
+ var useiset = ret.ctype == "val*" and not ret isa MNullableType
+ var guard = self.mlazypropdef.mproperty
+ if useiset then
+ set = v.isset_attribute(self.mpropdef.mproperty, arguments.first)
+ else
+ set = v.read_attribute(guard, arguments.first)
+ end
+ v.add("if(likely({set})) \{")
+ res = v.read_attribute(self.mpropdef.mproperty, arguments.first)
+ v.add("\} else \{")
+ var value = v.expr(nexpr, self.mpropdef.static_mtype)
+ v.write_attribute(self.mpropdef.mproperty, arguments.first, value)
+ v.assign(res, value)
+ if not useiset then
+ var true_v = v.new_expr("1", v.bool_type)
+ v.write_attribute(guard, arguments.first, true_v)
+ end
+ v.add("\}")
+ else
+ res = v.read_attribute(self.mpropdef.mproperty, arguments.first)
+ end
v.assign(v.frame.returnvar.as(not null), res)
- else
+ else if mpropdef == mwritepropdef then
+ assert arguments.length == 2
v.write_attribute(self.mpropdef.mproperty, arguments.first, arguments[1])
+ if is_lazy then
+ var ret = self.mpropdef.static_mtype
+ var useiset = ret.ctype == "val*" and not ret isa MNullableType
+ if not useiset then
+ v.write_attribute(self.mlazypropdef.mproperty, arguments.first, v.new_expr("1", v.bool_type))
+ end
+ end
+ else
+ abort
end
end
fun init_expr(v: AbstractCompilerVisitor, recv: RuntimeVariable)
do
var nexpr = self.n_expr
- if nexpr != null then
+ if nexpr != null and not is_lazy then
var oldnode = v.current_node
v.current_node = self
var old_frame = v.frame
var i = 1
# Collect undefined attributes
for npropdef in self.n_propdefs do
- if npropdef isa AAttrPropdef and npropdef.n_expr == null then
+ if npropdef isa AAttrPropdef and npropdef.n_expr == null and not npropdef.noinit then
v.write_attribute(npropdef.mpropdef.mproperty, recv, arguments[i])
i += 1
end
res_dir = "res"
end
if res_dir.file_exists then
+ # copy the res folder to .nit_compile
res_dir = res_dir.realpath
var target_res_dir = "{android_project_root}"
- if target_res_dir.file_exists then
- # copy the res folder to .nit_compile
- toolcontext.exec_and_check(["cp", "-R", res_dir, target_res_dir], "Android project error")
- end
+ toolcontext.exec_and_check(["cp", "-R", res_dir, target_res_dir], "Android project error")
+ else
+ # Create our own custom `res/values/string.xml` with the App name
+"""<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">{{{app_name}}}</string>
+</resources>""".write_to_file "{dir}/res/values/strings.xml"
end
-
end
redef fun write_makefile(compiler, compile_dir, cfiles)
import modelbuilder
import literal
+redef class Prod
+ super ANode
+
+ # Try to get its single annotation with a given name
+ # If there is no such an annotation, null is returned.
+ # If there is more than one annotation, a error message is printed and the first annotation is returned
+ fun get_single_annotation(name: String, modelbuilder: ModelBuilder): nullable AAnnotation
+ do
+ var res = get_annotations(name)
+ if res.is_empty then return null
+ if res.length > 1 then
+ modelbuilder.error(res[1], "Error: multiple annotation `{name}`. A previous one is defined line {res[0].location.line_start}")
+ end
+ return res.first
+ end
+
+ # Return all its annotations of a given name in the order of their declaration
+ # Retun an empty array if no such an annotation.
+ fun get_annotations(name: String): Array[AAnnotation]
+ do
+ var res = new Array[AAnnotation]
+ var nas = n_annotations
+ if nas == null then return res
+ for na in nas.n_items do
+ if na.name != name then continue
+ res.add(na)
+ end
+ return res
+ end
+end
+
redef class AAnnotation
# The name of the annotation
fun name: String
modelbuilder.error(self, "Annotation error: \"{name}\" expects a single Int as argument.")
return null
end
+
+ # Get the single argument of `self` as an identifier.
+ # Raise error and return null on any inconsistency.
+ fun arg_as_id(modelbuilder: ModelBuilder): nullable String
+ do
+ var args = n_args
+ if args.length == 1 then
+ var arg = args.first.as_id
+ if arg != null then return arg
+ end
+
+ modelbuilder.error(self, "Annotation error: \"{name}\" expects a single identifier as argument.")
+ return null
+ end
end
redef class AAtArg
redef class ToolContext
var extern_classes_typing_phase_ast: Phase = new ExternClassesTypingPhaseAst(self, [ffi_language_assignation_phase])
- var extern_classes_typing_phase_model: Phase = new ExternClassesTypingPhaseModel(self, [extern_classes_typing_phase_ast, modelize_class_phase])
+ var extern_classes_typing_phase_model: Phase = new ExternClassesTypingPhaseModel(self,
+ [extern_classes_typing_phase_ast, modelize_class_phase, modelize_property_phase])
end
# Assigns the `ftype` to class definitions, work on the AST only
replace('/', ".").replace('$', ".").replace(' ', "").replace('\n',"")
if mclass.name == "Bool" then return "boolean"
if mclass.name == "Char" then return "char"
- if mclass.name == "Int" then return "int"
+ if mclass.name == "Int" then return "long"
if mclass.name == "Float" then return "double"
return super
end
if ftype isa ForeignJavaType then return "jobject"
if mclass.name == "Bool" then return "jboolean"
if mclass.name == "Char" then return "jchar"
- if mclass.name == "Int" then return "jint"
+ if mclass.name == "Int" then return "jlong"
if mclass.name == "Float" then return "jdouble"
return super
end
end
if mclass.name == "Bool" then return "Z"
if mclass.name == "Char" then return "C"
- if mclass.name == "Int" then return "I"
+ if mclass.name == "Int" then return "J"
if mclass.name == "Float" then return "D"
return super
end
if ftype isa ForeignJavaType then return "Object"
if mclass.name == "Bool" then return "Boolean"
if mclass.name == "Char" then return "Char"
- if mclass.name == "Int" then return "Int"
+ if mclass.name == "Int" then return "Long"
if mclass.name == "Float" then return "Double"
return super
end
# Force easy warnings before intraproc-errors
phases.add_edge(scope_phase, simple_misc_analysis_phase)
# Code genrated by the serialization phase must be analyzed for literals
- phases.add_edge(literal_phase, serialization_phase)
+ phases.add_edge(literal_phase, serialization_phase_pre_model)
+ phases.add_edge(modelize_class_phase, serialization_phase_pre_model)
return true
end
end
assert mtype isa MClassType
var sc = mtype.mclass
if not parents.has(sc) or sc == objectclass then
- warning(ntype, "Warning: superfluous super-class {mtype} in class {mclassdef.mclass}.")
+ # Skip the warning on generated code
+ if ntype.location.file != null and not ntype.location.file.filename.is_empty then
+ warning(ntype, "Warning: superfluous super-class {mtype} in class {mclassdef.mclass}.")
+ end
else if not seen_parents.has_key(sc) then
seen_parents[sc] = ntype
else
module modelize_property
import modelize_class
+import annotation
redef class ToolContext
var modelize_property_phase: Phase = new ModelizePropertyPhase(self, [modelize_class_phase])
var mparameters = new Array[MParameter]
var anode: nullable ANode = null
for npropdef in nclassdef.n_propdefs do
- if npropdef isa AAttrPropdef and npropdef.n_expr == null then
+ if npropdef isa AAttrPropdef then
if npropdef.mpropdef == null then return # Skip broken attribute
+ var at = npropdef.get_single_annotation("noinit", self)
+ if at != null then
+ npropdef.noinit = true
+ if npropdef.n_expr != null then
+ self.error(at, "Error: `noinit` attributes cannot have an initial value")
+ end
+ continue # Skip noinit attributes
+ end
+ if npropdef.n_expr != null then continue
var paramname = npropdef.mpropdef.mproperty.name.substring_from(1)
var ret_type = npropdef.mpropdef.static_mtype
if ret_type == null then return
redef class AAttrPropdef
redef type MPROPDEF: MAttributeDef
+ # Is the node tagged `noinit`?
+ var noinit = false
+
+ # Is the node taggeg lazy?
+ var is_lazy = false
+
+ # The guard associated to a lasy attribute.
+ # Because some engines does not have a working `isset`,
+ # this additionnal attribute is used to guard the lazy initialization.
+ # TODO: to remove once isset is correctly implemented
+ var mlazypropdef: nullable MAttributeDef
+
# The associated getter (read accessor) if any
var mreadpropdef: nullable MMethodDef writable
# The associated setter (write accessor) if any
var mwritepropdef: nullable MMethodDef writable
+
redef fun build_property(modelbuilder, mclassdef)
do
var mclass = mclassdef.mclass
modelbuilder.mpropdef2npropdef[mreadpropdef] = self
mreadpropdef.mdoc = mpropdef.mdoc
+ var atlazy = self.get_single_annotation("lazy", modelbuilder)
+ if atlazy != null then
+ if n_expr == null then
+ modelbuilder.error(atlazy, "Error: a lazy attribute needs a value")
+ end
+ is_lazy = true
+ var mlazyprop = new MAttribute(mclassdef, "lazy _" + name, none_visibility)
+ var mlazypropdef = new MAttributeDef(mclassdef, mlazyprop, self.location)
+ self.mlazypropdef = mlazypropdef
+ end
+
+ var atreadonly = self.get_single_annotation("readonly", modelbuilder)
+ if atreadonly != null then
+ if n_expr == null then
+ modelbuilder.error(atreadonly, "Error: a readonly attribute needs a value")
+ end
+ # No setter, so just leave
+ return
+ end
+
var writename = name + "="
var nwritable = self.n_writable
+ var atwritable = self.get_single_annotation("writable", modelbuilder)
+ if atwritable != null then
+ if not atwritable.n_args.is_empty then
+ writename = atwritable.arg_as_id(modelbuilder) or else writename
+ end
+ end
var mwriteprop = modelbuilder.try_get_mproperty_by_name(nid2, mclassdef, writename).as(nullable MMethod)
var nwkwredef: nullable Token = null
if nwritable != null then nwkwredef = nwritable.n_kwredef
+ if atwritable != null then nwkwredef = atwritable.n_kwredef
if mwriteprop == null then
var mvisibility
if nwritable != null then
mvisibility = new_property_visibility(modelbuilder, mclassdef, nwritable.n_visibility)
+ else if atwritable != null then
+ mvisibility = new_property_visibility(modelbuilder, mclassdef, atwritable.n_visibility)
else
mvisibility = private_visibility
end
if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef or else n_kwredef, true, mwriteprop) then return
if nwritable != null then
check_redef_property_visibility(modelbuilder, nwritable.n_visibility, mwriteprop)
+ else if atwritable != null then
+ check_redef_property_visibility(modelbuilder, atwritable.n_visibility, mwriteprop)
end
end
mclassdef.mprop2npropdef[mwriteprop] = self
mreadpropdef.msignature = msignature
end
- var msritepropdef = self.mwritepropdef
+ var mwritepropdef = self.mwritepropdef
if mwritepropdef != null then
var name: String
if n_id != null then
var msignature = new MSignature([mparameter], null)
mwritepropdef.msignature = msignature
end
+
+ var mlazypropdef = self.mlazypropdef
+ if mlazypropdef != null then
+ mlazypropdef.static_mtype = modelbuilder.model.get_mclasses_by_name("Bool").first.mclass_type
+ end
end
redef fun check_signature(modelbuilder)
recv.attributes[mproperty] = value
end
+ # Is the attribute `mproperty` initialized the instance `recv`?
+ fun isset_attribute(mproperty: MAttribute, recv: Instance): Bool
+ do
+ assert recv isa MutableInstance
+ return recv.attributes.has_key(mproperty)
+ end
+
# Collect attributes of a type in the order of their init
fun collect_attr_propdef(mtype: MType): Array[AAttrPropdef]
do
var recv = args.first
assert recv isa MutableInstance
var attr = self.mpropdef.mproperty
- if args.length == 1 then
- return v.read_attribute(attr, recv)
- else
+ if mpropdef == mreadpropdef then
+ assert args.length == 1
+ if not is_lazy or v.isset_attribute(attr, recv) then return v.read_attribute(attr, recv)
+ return evaluate_expr(v, recv)
+ else if mpropdef == mwritepropdef then
assert args.length == 2
v.write_attribute(attr, recv, args[1])
return null
+ else
+ abort
end
end
# Evaluate and set the default value of the attribute in `recv`
private fun init_expr(v: NaiveInterpreter, recv: Instance)
do
- assert recv isa MutableInstance
+ if is_lazy then return
var nexpr = self.n_expr
if nexpr != null then
- var f = new Frame(self, self.mpropdef.as(not null), [recv])
- v.frames.unshift(f)
- var val = v.expr(nexpr)
- assert val != null
- v.frames.shift
- assert not v.is_escaping
- v.write_attribute(self.mpropdef.mproperty, recv, val)
+ evaluate_expr(v, recv)
return
end
var mtype = self.mpropdef.static_mtype.as(not null)
v.write_attribute(self.mpropdef.mproperty, recv, v.null_instance)
end
end
+
+ private fun evaluate_expr(v: NaiveInterpreter, recv: Instance): Instance
+ do
+ assert recv isa MutableInstance
+ var nexpr = self.n_expr
+ assert nexpr != null
+ var f = new Frame(self, self.mpropdef.as(not null), [recv])
+ v.frames.unshift(f)
+ var val = v.expr(nexpr)
+ assert val != null
+ v.frames.shift
+ assert not v.is_escaping
+ v.write_attribute(self.mpropdef.mproperty, recv, val)
+ return val
+ end
end
redef class AClassdef
var i = 1
# Collect undefined attributes
for npropdef in self.n_propdefs do
- if npropdef isa AAttrPropdef and npropdef.n_expr == null then
+ if npropdef isa AAttrPropdef and not npropdef.noinit and npropdef.n_expr == null then
v.write_attribute(npropdef.mpropdef.mproperty, recv, args[i])
i += 1
end
if recv == null then return null
if recv.mtype isa MNullType then fatal(v, "Receiver is null")
var mproperty = self.mproperty.as(not null)
- assert recv isa MutableInstance
- return v.bool_instance(recv.attributes.has_key(mproperty))
+ return v.bool_instance(v.isset_attribute(mproperty, recv))
end
end
# Create a tool context to handle options and paths
var toolcontext = new ToolContext
-toolcontext.tooldescription = "Usage: nitmetrics [OPTION]... <file.nit>...\mComputes various metrics on Nit programs."
+toolcontext.tooldescription = "Usage: nitmetrics [OPTION]... <file.nit>...\nComputes various metrics on Nit programs."
# We do not add other options, so process them now!
toolcontext.process_options(args)
if name == "Bool" then return "int"
if name == "Char" then return "char"
if name == "Float" then return "double"
- if name == "Int" then return "int"
+ if name == "Int" then return "long"
if name == "NativeString" then return "char*"
if mclass.kind == extern_kind then
var ctype = mclass.ctype
if name == "Bool" then return "int"
if name == "Char" then return "char"
if name == "Float" then return "double"
- if name == "Int" then return "int"
+ if name == "Int" then return "long"
if name == "NativeString" then return "char*"
if mclass.kind == extern_kind then return "void*"
return "struct nitni_instance *"
return nexpr
end
+ # Parse a super class declaration
+ # Fatal error if the `string` is not a syntactically correct super class declaration
+ fun parse_superclass(string: String): ASuperclass
+ do
+ var mod_string = "class Dummy\nsuper {string}\nend"
+ var nclassdef = parse_classdef(mod_string).as(AStdClassdef)
+ var nsuperclasses = nclassdef.n_superclasses
+ if nsuperclasses.length != 1 then
+ self.fatal_error(null, "Fatal Error: not a super class declaration")
+ abort
+ end
+ return nsuperclasses.first
+ end
+
# Try to parse the `string` as something
#
# Returns the first possible syntacticaly correct type among:
import phase
import parser_util
+import modelize_property
+intrude import modelize_class
redef class ToolContext
- var serialization_phase: Phase = new SerializationPhase(self, null)
+ var serialization_phase_pre_model: Phase = new SerializationPhasePreModel(self, null)
+ var serialization_phase_post_model: Phase = new SerializationPhasePostModel(self,
+ [modelize_class_phase, serialization_phase_pre_model])
+
+ private fun place_holder_type_name: String do return "PlaceHolderTypeWhichShouldNotExist"
end
-# TODO automaticaly add Serializable as a super class
-# TODO Sequences
# TODO add annotations on attributes (volatile, sensitive or do_not_serialize?)
-private class SerializationPhase
+private class SerializationPhasePreModel
super Phase
redef fun process_annotated_node(nclassdef, nat)
return
end
+ # Add `super Serializable`
+ var sc = toolcontext.parse_superclass("Serializable")
+ sc.location = nat.location
+ nclassdef.n_superclasses.add sc
+
generate_serialization_method(nclassdef)
generate_deserialization_init(nclassdef)
redef fun process_nmodule(nmodule)
do
+ # Clear the cache of constructors to review before adding to it
+ nmodule.inits_to_retype.clear
+
# collect all classes
var auto_serializable_nclassdefs = new Array[AStdClassdef]
for nclassdef in nmodule.n_classdefs do
code.add " v.notify_of_creation self"
for attribute in npropdefs do if attribute isa AAttrPropdef then
- if attribute.n_type == null then
- toolcontext.error(attribute.location, "NOT YET IMPLEMENTED: all attributes of an auto_serialized class definition must define a type.")
- continue
+ var n_type = attribute.n_type
+ var type_name
+ if n_type == null then
+ # Use a place holder, we will replace it with the infered type after the model phases
+ type_name = toolcontext.place_holder_type_name
+ else
+ type_name = n_type.type_name
end
var name = attribute.name
- var type_name = attribute.type_name
+
code.add ""
code.add "\tvar {name} = v.deserialize_attribute(\"{name}\")"
- code.add "\tassert {name} isa {type_name} else print \"Expected attribute '{name}' to be of type '{type_name}'\""
+ code.add "\tassert {name} isa {type_name} else print \"Unsupported type for attribute '{name}', got '\{{name}.class_name\}' (ex {type_name})\""
code.add "\tself.{name} = {name}"
end
code.add "end"
- npropdefs.add(toolcontext.parse_propdef(code.join("\n")))
+
+ var npropdef = toolcontext.parse_propdef(code.join("\n")).as(AConcreteInitPropdef)
+ npropdefs.add npropdef
+ nclassdef.parent.as(AModule).inits_to_retype.add npropdef
end
# Added to the abstract serialization service
code.add " redef fun deserialize_class(name)"
code.add " do"
else
- toolcontext.error(deserializer_npropdef.location, "Annotation error: you cannont define Deserializer::deserialize_class in a module where you use \"auto_serializable\".")
+ toolcontext.error(deserializer_npropdef.location, "Annotation error: you cannot define Deserializer::deserialize_class in a module where you use \"auto_serializable\".")
return
end
for nclassdef in nclassdefs do
var name = nclassdef.n_id.text
- if not name.chars.has('[') then # FIXME this is a temporary hack
+ if nclassdef.n_formaldefs.is_empty then
code.add " if name == \"{name}\" then return new {name}.from_deserializer(self)"
end
end
end
end
+private class SerializationPhasePostModel
+ super Phase
+
+ redef fun process_nmodule(nmodule)
+ do
+ for npropdef in nmodule.inits_to_retype do
+ var v = new PreciseTypeVisitor(npropdef, npropdef.mpropdef.mclassdef, toolcontext)
+ npropdef.accept_precise_type_visitor v
+ end
+ end
+end
+
+# Visitor on generated constructors to replace the expected type of deserialized attributes
+private class PreciseTypeVisitor
+ super Visitor
+
+ var npropdef: AConcreteInitPropdef
+ var mclassdef: MClassDef
+ var toolcontext: ToolContext
+
+ init(npropdef: AConcreteInitPropdef, mclassdef: MClassDef, toolcontext: ToolContext)
+ do
+ self.npropdef = npropdef
+ self.mclassdef = mclassdef
+ self.toolcontext = toolcontext
+ end
+
+ redef fun visit(n) do n.accept_precise_type_visitor(self)
+end
+
+redef class ANode
+ private fun accept_precise_type_visitor(v: PreciseTypeVisitor) do visit_all(v)
+end
+
+redef class AIsaExpr
+ redef fun accept_precise_type_visitor(v)
+ do
+ if n_type.collect_text != v.toolcontext.place_holder_type_name then return
+
+ var attr_name = "_" + n_expr.collect_text
+ for mattrdef in v.mclassdef.mpropdefs do
+ if mattrdef isa MAttributeDef and mattrdef.name == attr_name then
+ var new_ntype = v.toolcontext.parse_something(mattrdef.static_mtype.to_s)
+ n_type.replace_with new_ntype
+ break
+ end
+ end
+ end
+end
+
redef class AAttrPropdef
private fun name: String
do
if n_id == null then return n_id2.text
return n_id.text
end
+end
+redef class AType
private fun type_name: String
do
- var name = n_type.n_id.text
+ var name = n_id.text
- if n_type.n_kwnullable != null then name = "nullable {name}"
+ if n_kwnullable != null then name = "nullable {name}"
- var types = n_type.n_types
+ var types = n_types
if not types.is_empty then
var params = new Array[String]
- for t in types do params.add(t.n_id.text)
+ for t in types do params.add(t.type_name)
return "{name}[{params.join(", ")}]"
else return name
end
return null
end
+
+ private var inits_to_retype = new Array[AConcreteInitPropdef]
end
redef class AStdClassdef
protected var a2: Object = self
private var a3: Object = self
- var a4: Object writable = self
- protected var a5: Object writable = self
- private var a6: Object writable = self
+ var a4: Object = self is writable
+ protected var a5: Object = self is writable
+ private var a6: Object = self is writable
- var a7: Object protected writable = self
- protected var a8: Object protected writable = self
- private var a9: Object protected writable = self
+ var a7: Object = self is protected writable
+ protected var a8: Object = self is protected writable
+ private var a9: Object = self is protected writable
- var a10: Object private writable = self
- protected var a11: Object private writable = self
- private var a12: Object private writable = self
+ var a10: Object = self is private writable
+ protected var a11: Object = self is private writable
+ private var a12: Object = self is private writable
var cpt: Int = 0
class B
super A
redef var foo: Int = 20
- var bar: Int redef writable = 30
- redef var baz: Int redef writable = 40
+ var bar: Int = 30 is redef writable
+ redef var baz: Int = 40 is redef writable
end
class C
super A
#alt1#var foo: Int = 10
#alt2#redef var foo: Int = 10
- #alt3#var foo: Int writable = 10
- #alt4#redef var foo: Int writable = 10
- #alt5#var foo: Int redef writable = 10
- #alt6#redef var foo: Int redef writable = 10
+ #alt3#var foo: Int = 10 is writable
+ #alt4#redef var foo: Int = 10 is writable
+ #alt5#var foo: Int = 10 is redef writable
+ #alt6#redef var foo: Int = 10 is redef writable
#alt7#redef var foo
#alt11#var bar: Int = 20
#alt12#redef var bar: Int = 20
- #alt13#var bar: Int writable = 20
- #alt14#redef var bar: Int writable = 20
- #alt15#var bar: Int redef writable = 20
- #alt16#redef var bar: Int redef writable = 20
+ #alt13#var bar: Int = 20 is writable
+ #alt14#redef var bar: Int = 20 is writable
+ #alt15#var bar: Int = 20 is redef writable
+ #alt16#redef var bar: Int = 20 is redef writable
#alt17#redef var bar
#alt21#var baz: Int = 30
#alt22#redef var baz: Int = 30
- #alt23#var baz: Int writable = 30
- #alt24#redef var baz: Int writable = 30
- #alt25#var baz: Int redef writable = 30
- #alt26#redef var baz: Int redef writable = 30
+ #alt23#var baz: Int = 30 is writable
+ #alt24#redef var baz: Int = 30 is writable
+ #alt25#var baz: Int = 30 is redef writable
+ #alt26#redef var baz: Int = 30 is redef writable
#alt27#redef var baz
end
i.output
super(i+30)
end
- redef var vaz: Int redef writable = 40
+ redef var vaz: Int = 40 is redef writable
end
var b = new B
class B
super A
#alt1#redef var foo: Bool = true
- #alt2#var bar: Bool redef writable = true
- #alt3#redef var baz: Bool redef writable = true
+ #alt2#var bar: Bool = true is redef writable
+ #alt3#redef var baz: Bool = true is redef writable
end
var b = new B
--- /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 kernel
+
+class Foo
+ var a1: Object = fa1 is lazy
+ var a2: Object = fa2 is lazy
+ fun fa1: Object do
+ 1.output
+ return 10
+ end
+ fun fa2: Object do
+ 2.output
+ return 20
+ end
+ #alt1#var a3: Object is lazy
+end
+
+var f = new Foo
+f.a1.output
+f.a1.output
+f.a2.output
+f.a2.output
+'\n'.output
+
+var g = new Foo
+g.a2.output
+g.a1.output
+g.a2.output
+g.a1.output
+'\n'.output
+
+var h = new Foo
+h.a1 = 100
+h.a1.output
+h.a1.output
--- /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 kernel
+
+class Foo
+ var a1: Int = fa1 is lazy
+ var a2: Int = fa2 is lazy
+ fun fa1: Int do
+ 1.output
+ return 10
+ end
+ fun fa2: Int do
+ 2.output
+ return 20
+ end
+end
+
+var f = new Foo
+f.a1.output
+f.a1.output
+f.a2.output
+f.a2.output
+'\n'.output
+
+var g = new Foo
+g.a2.output
+g.a1.output
+g.a2.output
+g.a1.output
+'\n'.output
+
+var h = new Foo
+h.a1 = 100
+h.a1.output
+h.a1.output
--- /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 kernel
+
+class Foo
+ var a1: nullable Object = fa1 is lazy
+ var a2: nullable Object = fa2 is lazy
+ fun fa1: nullable Object do
+ 1.output
+ return 10
+ end
+ fun fa2: nullable Object do
+ 2.output
+ return 20
+ end
+end
+
+fun o(o: nullable Object)
+do
+ if o == null then
+ 'n'.output
+ '\n'.output
+ else
+ o.output
+ end
+end
+
+var f = new Foo
+o f.a1
+o f.a1
+o f.a2
+o f.a2
+'\n'.output
+
+var g = new Foo
+o g.a2
+o g.a1
+o g.a2
+o g.a1
+'\n'.output
+
+var h = new Foo
+h.a1 = 100
+h.a1.output
+h.a1.output
--- /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 kernel
+
+class A
+ fun foo: Int do return 1
+ fun set_bar(i: Int) do i.output
+ fun baz: Int do return 4
+ fun set_baz(i: Int) do i.output
+ fun zz do end
+end
+
+class B
+ super A
+ redef var foo: Int = 20 is writable(set_foo)
+ var bar: Int = 30 is redef writable(set_bar)
+ redef var baz: Int = 40 is writable(set_baz)
+ #alt2#var z: Int is writable(set_baz)
+ #alt3#var z: Int is writable(zz)
+ #alt4#var z: Int is redef writable(zz)
+end
+
+class C
+ super B
+ fun foo=(i: Int) do set_foo(i)
+ fun bar=(i: Int) do set_bar(i)
+ fun baz=(i: Int) do set_baz(i)
+end
+
+var a = new A
+a.foo.output
+a.set_bar 2
+a.set_baz 3
+a.baz.output
+
+'\n'.output
+
+var b = new B
+b.set_foo 10
+#alt1#b.foo = 10
+b.foo.output
+b.set_bar 20
+b.bar.output
+b.set_baz 30
+b.baz.output
+
+'\n'.output
+
+var c = new C
+c.foo = 100
+c.foo.output
+c.bar = 200
+c.bar.output
+c.baz = 300
+c.baz.output
--- /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 kernel
+
+class Foo
+ var a1 = 1 is readonly
+ fun run
+ do
+ #alt1#a1 = 2
+ #alt2#_a1 = 3 #hack
+ a1.output
+ end
+ #alt3# var a2: Int is readonly
+end
+
+var f = new Foo
+f.run
--- /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 kernel
+
+class A
+ var x: Object is noinit #alt1,3# var x: Object
+ var y: Object is noinit #alt2,3# var y: Object
+ fun work
+ do
+ if isset _x then x.output
+ if isset _y then y.output
+ 0.output
+ end
+ #alt5#var z: Object = 5 is noinit
+end
+
+var a: A
+a = new A#alt1#a = new A(2)#alt2#a = new A(30)#alt3#a = new A(4, 40)#alt4#a=new A(5)
+a.work
protected fun proA(a: A) do end
private fun priA(a: A) do end
- var vpubA: nullable A writable
- protected var vproA: nullable A protected writable
+ var vpubA: nullable A is writable
+ protected var vproA: nullable A is protected writable
private var vpriA: nullable A
- var vpubA2 writable = new A
- protected var vproA2 protected writable = new A
+ var vpubA2 = new A is writable
+ protected var vproA2 = new A is protected writable
private var vpriA2 = new A
#alt1#fun pubB(a: B) do end
#alt2#protected fun proB(a: B) do end
private fun priB(a: B) do end
- #alt3#var vpubB: nullable B writable
- #alt4#protected var vproB: nullable B protected writable
+ #alt3#var vpubB: nullable B is writable
+ #alt4#protected var vproB: nullable B is protected writable
private var vpriB: nullable B
- #alt5#var vpubB2 writable = new B
- #alt6#protected var vproB2 protected writable = new B
+ #alt5#var vpubB2 = new B is writable
+ #alt6#protected var vproB2 = new B is protected writable
private var vpriB2 = new B
init do end
#alt7#protected fun proA(a: A) do end
private fun priA(a: A) do end
- var vpubA: nullable A writable
- #alt7#protected var vproA: nullable A protected writable
+ var vpubA: nullable A is writable
+ #alt7#protected var vproA: nullable A is protected writable
private var vpriA: nullable A
- var vpubA2 writable = new A
- #alt7#protected var vproA2 protected writable = new A
+ var vpubA2 = new A is writable
+ #alt7#protected var vproA2 = new A is protected writable
private var vpriA2 = new A
fun pubB(a: B) do end
#alt7#protected fun proB(a: B) do end
private fun priB(a: B) do end
- var vpubB: nullable B writable
- #alt7#protected var vproB: nullable B protected writable
+ var vpubB: nullable B is writable
+ #alt7#protected var vproB: nullable B is protected writable
private var vpriB: nullable B
- var vpubB2 writable = new B
- #alt7#protected var vproB2 protected writable = new B
+ var vpubB2 = new B is writable
+ #alt7#protected var vproB2 = new B is protected writable
private var vpriB2 = new B
init do end
#alt2#protected fun proA(a: A) do end
private fun priA(a: A) do end
- #alt3#var vpubA: nullable A writable
- #alt4#protected var vproA: nullable A protected writable
+ #alt3#var vpubA: nullable A is writable
+ #alt4#protected var vproA: nullable A is protected writable
private var vpriA: nullable A
- #alt5#var vpubA2 writable = new A
- #alt6#protected var vproA2 protected writable = new A
+ #alt5#var vpubA2 = new A is writable
+ #alt6#protected var vproA2 = new A is protected writable
private var vpriA2 = new A
init do end
fun pubA(a: A) do end
private fun priA(a: A) do end
- var vpubA: nullable A writable
+ var vpubA: nullable A is writable
private var vpriA: nullable A
- var vpubA2 writable = new A
+ var vpubA2 = new A is writable
private var vpriA2 = new A
init do end
class A
type E: T
- var e: nullable E writable = null
+ var e: nullable E = null is writable
end
class B
class A
type E: T
- var e: nullable E writable = null
+ var e: nullable E = null is writable
end
class B
class C
super A
- var tab: nullable Array[E] writable
+ var tab: nullable Array[E] is writable
init do end
end
type F: E
type F2: F
- var e: E writable
- var f: F writable
- var f2: F2 writable
+ var e: E is writable
+ var f: F is writable
+ var f2: F2 is writable
init(e: E, f: F, f2: F2)
do
class A
type E: F
type F: E
- var e: nullable E writable = null
+ var e: nullable E = null is writable
init do end
end
--- /dev/null
+1
+10
+10
+2
+20
+20
+
+2
+20
+1
+10
+20
+10
+
+100
+100
--- /dev/null
+alt/base_attr_lazy_alt1.nit:28,20--23: Error: a lazy attribute needs a value
--- /dev/null
+1
+10
+10
+2
+20
+20
+
+2
+20
+1
+10
+20
+10
+
+100
+100
--- /dev/null
+1
+10
+10
+2
+20
+20
+
+2
+20
+1
+10
+20
+10
+
+100
+100
--- /dev/null
+1
+2
+3
+4
+
+10
+20
+30
+
+100
+200
+300
--- /dev/null
+alt/base_attr_named_setters_alt1.nit:52,1--10: Error: Method 'foo=' doesn't exists in B.
--- /dev/null
+alt/base_attr_named_setters_alt2.nit:30,6: Error: A property set_baz is already defined in class B at line 29.
--- /dev/null
+alt/base_attr_named_setters_alt3.nit:31,6: Redef error: B::zz is an inherited property. To redefine it, add the redef keyword.
--- /dev/null
+alt/base_attr_named_setters_alt4.nit:32,9--11: Redef Error: 1 parameters found, 0 expected. Signature is base_attr_named_setters_alt4#B#zz
--- /dev/null
+alt/base_attr_readonly_alt1.nit:21,3--8: Error: Method or variable 'a1=' unknown in Foo.
--- /dev/null
+alt/base_attr_readonly_alt3.nit:25,17--24: Error: a readonly attribute needs a value
--- /dev/null
+alt/base_init_noinit_alt4.nit:30,3--10: Error: Incorrect number of parameters. Got 1, expected 0. Signature is
--- /dev/null
+alt/base_init_noinit_alt5.nit:26,23--28: Error: `noinit` attributes cannot have an initial value
alt/base_prot_sig_alt7.nit:46,2--10: Error: The only legal visibility for properties in a private class is private.
alt/base_prot_sig_alt7.nit:50,2--10: Error: The only legal visibility for properties in a private class is private.
-alt/base_prot_sig_alt7.nit:50,34--42: Error: The only legal visibility for properties in a private class is private.
+alt/base_prot_sig_alt7.nit:50,37--45: Error: The only legal visibility for properties in a private class is private.
alt/base_prot_sig_alt7.nit:54,2--10: Error: The only legal visibility for properties in a private class is private.
-alt/base_prot_sig_alt7.nit:54,23--31: Error: The only legal visibility for properties in a private class is private.
+alt/base_prot_sig_alt7.nit:54,34--42: Error: The only legal visibility for properties in a private class is private.
alt/base_prot_sig_alt7.nit:58,2--10: Error: The only legal visibility for properties in a private class is private.
alt/base_prot_sig_alt7.nit:62,2--10: Error: The only legal visibility for properties in a private class is private.
-alt/base_prot_sig_alt7.nit:62,34--42: Error: The only legal visibility for properties in a private class is private.
+alt/base_prot_sig_alt7.nit:62,37--45: Error: The only legal visibility for properties in a private class is private.
alt/base_prot_sig_alt7.nit:66,2--10: Error: The only legal visibility for properties in a private class is private.
-alt/base_prot_sig_alt7.nit:66,23--31: Error: The only legal visibility for properties in a private class is private.
+alt/base_prot_sig_alt7.nit:66,34--42: Error: The only legal visibility for properties in a private class is private.
--- /dev/null
+Not executable (platform?)
-Usage: nitmetrics [OPTION]... <file.nit>...mComputes various metrics on Nit programs.
+Usage: nitmetrics [OPTION]... <file.nit>...
+Computes various metrics on Nit programs.
Use --help for help
# Simple class
class A
auto_serializable
- super Serializable
- var b: Bool
+ var b = false
var c: Char
var f: Float
- var i: Int
- var s: String
+ var i = 123
+ var s = "asdf"
var n: nullable Int
init(b: Bool, c: Char, f: Float, i: Int, s: String, n: nullable Int)
# Composed of an A and a B
class C
auto_serializable
- super Serializable
var a: A
- var b: B
+ var b = new B(false, 'b', 123.123, 2345, "hjkl", 12, 1111, "qwer")
var aa: A
init(a: A, b: B)
redef fun output in "Java" `{
for (Object i: recv) {
- System.out.println((int)i);
+ System.out.println((long)i);
}
`}
class Gen3[H: Int]
super Gen1[H, Char]
- redef var e: H redef writable
- redef var f_: Char redef writable = 'N'
+ redef var e: H is redef writable
+ redef var f_: Char = 'N' is redef writable
redef fun f: Char do return f_ end
redef fun f=(x: Char) do f_ = x end
# Simple class
class A
auto_serializable
- super Serializable
- var b: Bool
+ var b = false
var c: Char
var f: Float
- var i: Int
- var s: String
+ var i = 123
+ var s = "asdf"
var n: nullable Int
- var array: Array[nullable Object] = new Array[nullable Object].with_items(88, "hello", null)
+ var array = new Array[nullable Object].with_items(88, "hello", null)
init(b: Bool, c: Char, f: Float, i: Int, s: String, n: nullable Int)
do
# Composed of an A and a B
class C
auto_serializable
- super Serializable
var a: A
- var b: B
+ var b = new B(false, 'b', 123.123, 2345, "hjkl", 12, 1111, "qwer")
var aa: A
init(a: A, b: B)