1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Model of the parsed Objective-C files
18 # Model of all the analyzed Objective-C classes
20 # All analyzed classes
21 var classes
= new Array[ObjcClass]
23 # Is `objc_type` known by this model?
24 fun knows_type
(objc_type
: Text): Bool
27 if c
.name
== objc_type
then return true
30 return imported_types
.has
(objc_type
)
33 # Are all types in the signature or `method` known by this model?
34 fun knows_all_types
(method
: ObjcMethod): Bool
36 for param
in method
.params
do
37 if param
.is_single
then break
38 if not knows_type
(param
.return_type
) then return false
41 var r
= method
.return_type
42 return r
== "void" or r
== "id" or knows_type
(r
)
45 # Objective-C types available in imported modules
47 # TODO seach in existing wrappers
48 private var imported_types
: Array[String] = ["NSObject", "NSString"]
53 # Name of the super classes
54 var super_names
= new Array[String]
56 # Name of this Objective-C class
59 # Attributes of this Objective-C class
60 var attributes
= new Array[ObjcAttribute]
62 # Methods of this Objective-C class
63 var methods
= new Array[ObjcMethod]
66 # Method of an `ObjcClass`
70 # Is this a static class method declared with '+'? Otherwise it's an instance method.
71 var is_class_property
: Bool = false is writable
73 # Parameters of the method
74 var params
= new Array[ObjcParam]
76 # Return type as a `String`
77 var return_type
: String is noinit
, writable
79 # Does this method look like a constructor/method?
80 fun is_init
: Bool do return params
.first
.name
.has_prefix
("init") and not is_class_property
83 # Attribute of an `ObjcClass`
87 # Name of this attribute
88 var name
: String is noinit
, writable
90 # Type of this attribute
91 var return_type
: String is noinit
, writable
94 # Property of an `ObjcClass`
97 var objc_class
: ObjcClass
99 # Is this property to be commented out?
100 var is_commented
= false is writable
103 # Parameter of an `ObjcMethod`
105 # Parameter name, used by the caller (e.g. `withObject` in `withObject: (NSObject*) obj`)
106 var name
: String is noinit
, writable
108 # Type of the parameter name
109 var return_type
: String is noinit
, writable
111 # Argument name, used within the body (e.g. `obj` in `withObject: (NSObject*) obj`)
112 var variable_name
: String is noinit
, writable
114 # Is this a primitive array? with at least one `[]`.
115 var is_table
= false is writable
117 # Is this a pointer type?
118 var is_pointer
= false is writable
120 # Is this a parameter with only a `name`?
121 var is_single
= false is writable
125 if is_single
then return name
126 return "{name}:({return_type}){variable_name}"