+# 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.
+
+# Code generation
module objc_generator
import objc_model
class CodeGenerator
+ # Merge the calls to `alloc` and `init...` in a single constructor?
+ #
+ # If `true`, also the default behavior, initializing an extern Objective-C object looks like:
+ # ~~~nitish
+ # var o = new NSArray.init_with_array(some_other_array)
+ # ~~~
+ #
+ # If `false`, the object must first be allocated and then initialized.
+ # This is closer to the Objective-C behavior:
+ # ~~~nitish
+ # var o = new NSArray
+ # o.init_with_array(some_other_array)
+ # ~~~
+ var init_with_alloc = true is writable
+
fun generator(classes: Array[nullable ObjcClass]) do
- var init_with_alloc = true
for classe in classes do
var file = new FileWriter.open(classe.name + ".nit")
nit_class_generator(classe, file, init_with_alloc)
nit_method_generator(commented_method, file, init_with_alloc)
if commented_method != commented_methods.last then file.write("\n")
end
- file.write("\nend")
+ file.write "\nend\n"
end
fun new_nit_generator(classe: nullable ObjcClass, file: FileWriter, init_with_alloc: Bool) do