-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeclareMakerDelegate.xojo_code
208 lines (186 loc) · 5.09 KB
/
DeclareMakerDelegate.xojo_code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#tag Module
Protected Module DeclareMakerDelegate
#tag Method, Flags = &h0
Sub addRequiredConstant(aConst as String)
if consts.IndexOf(aConst) = -1 then
consts.Append aConst
end if
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Function capFirstLetter(txt as String) As String
dim first as String = txt.Left(1)
first = first.Uppercase
dim rest as String = txt.Mid(2)
Return first + rest
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function charCodeForType(type as String) As String
select case type
case "BOOL"
Return "B"
case "double"
Return "d"
case "NSString"
Return "*"
case "Void"
Return "v"
case "NSInteger"
Return "i"
case "NSUInteger"
Return "I"
case "CGRect" //////////
Return "{CGRect=ffff}"
case "CGPoint"
Return "{CGPoint=ff}"
case "CGSize"
Return "{CGSize=ff}"
case "NSPoint"
Return "{NSPoint=ff}"
case "NSSize"
Return "{NSSize=ff}"
case "NSRect"
Return "{NSRect=ffff}" //////////
case "CGFloat"
Return "f"
case "float"
Return "f"
else
Return "@"
end select
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function declareStringForType(typeString as String) As String
select case typeString
case "BOOL"
Return "Boolean"
case "double"
Return "Double"
case "NSString"
Return "CFStringRef"
case "Void"
Return ""
case "NSInteger"
Return "Integer"
case "NSUInteger"
Return "UInteger"
case "CGRect"
Return "CGRect"
case "CGPoint"
Return "CGPoint"
case "CGSize"
Return "CGSize"
case "NSPoint"
Return "NSPoint"
case "NSSize"
Return "NSSize"
case "NSRect"
Return "NSRect"
case "CGFloat"
Return "Double"
case "CLLocationAccuracy"
Return "Double"
case "CLLocationCoordinate2D"
Return "CLLocationCoordinate2D"
Case "CLLocationDegrees"
Return "Double"
case "CLLocationDirection"
Return "Double"
case "CLLocationDistance"
Return "Double"
Case "CLLocationSpeed"
Return "Double"
case "NSTimeInterval"
Return "Double"
case "float"
Return "Double"
else
Return "ptr"
end select
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function isPrimitiveType(txt as String) As Boolean
Return declareStringForType(txt) <> "Ptr"
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function NSObjectDelegate() As RBClass
dim result as new RBClass("NSObject")
dim privateConstructor as new RBMethod("Constructor","",RBConstantDefinitions.kPrivate)
privateConstructor.sourceLine = "//don't allow direct initialization"
dim publicConstructor as new RBMethod("Constructor","")
publicConstructor.addParameter "ref as ptr"
publicConstructor.sourceLine = "declare function retain lib FoundationLib selector ""retain"" (obj_id as ptr) as ptr"
publicConstructor.sourceLine = "m_id = retain(ref)"
dim destructor as new RBMethod("Destructor","")
destructor.sourceLine = "declare sub release lib FoundationLib selector ""release"" (obj_id as ptr)"
destructor.sourceLine = "release(m_id)"
dim id as new RBMethod("id","Ptr")
id.sourceLine = "Return self.m_id"
dim op_convert as new RBMethod("Operator_Convert","Ptr")
op_convert.sourceLine = "Return self.id"
dim init as new RBMethod("Initialize","Ptr")
init.IsShared = True
init.addParameter "obj_id as ptr"
init.sourceLine = "declare function init lib FoundationLib selector ""init"" (obj_id as ptr) as ptr"
init.sourceLine = "Return init(obj_id)"
dim alloc as new RBMethod("Allocate","Ptr")
alloc.IsShared = True
alloc.addParameter "clsRef as ptr"
alloc.sourceLine = "declare function alloc lib FoundationLib selector ""alloc"" (clsRef as ptr) as ptr"
alloc.sourceLine = "Return alloc(clsRef)"
dim m_id as new RBProperty("m_id","Ptr",RBConstantDefinitions.kPrivate)
result.addMethod privateConstructor
result.addMethod publicConstructor
result.addMethod destructor
result.addMethod id
result.addMethod op_convert
result.addMethod init
result.addMethod alloc
result.addProperty m_id
Return result
End Function
#tag EndMethod
#tag Property, Flags = &h1
Protected consts() As String
#tag EndProperty
#tag ViewBehavior
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag EndViewBehavior
End Module
#tag EndModule