forked from zeromq/zproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zproject_java_lib.gsl
232 lines (204 loc) · 8.32 KB
/
zproject_java_lib.gsl
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# JNI common functions
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/imatix/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
# This file is part of zproject.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
function resolve_container (container)
# Type of container shown to Java apps
my.container.jni_java_type = ""
# Type of container passed to native code
my.container.jni_jni_type = ""
# Mapping from Java to JNI type
my.container.jni_mapping = "$(my.container.name:camel)"
# Is the container a known class type?
my.container.jni_is_class = 0
# Is the container a self_p reference?
my.container.jni_self_p = 0
if my.container.type = "nothing"
my.container.jni_java_type = "void"
my.container.jni_jni_type = "void"
elsif my.container.type = "anything" \
| my.container.type = "sockish" \
| my.container.type = "size" \
| my.container.type = "time" \
| my.container.type = "msecs" \
| my.container.type = "file_size"
my.container.jni_java_type = "long"
my.container.jni_jni_type = "jlong"
elsif my.container.type = "boolean"
my.container.jni_java_type = "boolean"
my.container.jni_jni_type = "jboolean"
elsif my.container.type = "byte"
my.container.jni_java_type = "byte"
my.container.jni_jni_type = "jbyte"
elsif my.container.type = "char"
my.container.jni_java_type = "char"
my.container.jni_jni_type = "jchar"
elsif my.container.type = "integer"
my.container.jni_java_type = "int"
my.container.jni_jni_type = "jint"
elsif my.container.type = "number"
if my.container.size ?= "1"
my.container.jni_java_type = "byte"
my.container.jni_jni_type = "jbyte"
elsif my.container.size = 2
my.container.jni_java_type = "short"
my.container.jni_jni_type = "jshort"
elsif my.container.size = 4
my.container.jni_java_type = "int"
my.container.jni_jni_type = "jint"
elsif my.container.size = 8
my.container.jni_java_type = "long"
my.container.jni_jni_type = "jlong"
endif
elsif my.container.type = "real"
my.container.jni_java_type = "float"
my.container.jni_jni_type = "jfloat"
elsif my.container.type = "buffer"
if my.container.by_reference
return 1 # Skip methods that do this
endif
my.container.jni_java_type = "byte []"
my.container.jni_jni_type = "jbyteArray"
elsif my.container.type = "string"
if my.container.by_reference
return 1 # Skip methods that do this
endif
my.container.jni_java_type = "String"
my.container.jni_jni_type = "jstring"
elsif my.container.type = "format"
my.container.jni_java_type = "String"
my.container.jni_jni_type = "jstring"
elsif count (project.class, class.c_name = my.container.type & !defined (class.api))
return 1 # Refers to class that has no API model
elsif my.container.name = "self_p"
my.container.jni_self_p = 1
elsif count (project.class, class.c_name = my.container.type) \
| count (project->dependencies.class, class.c_name = my.container.type)
my.container.jni_java_type = "$(my.container.type:pascal)"
my.container.jni_mapping = "$(my.container.name:camel).self"
my.container.jni_shim_type = "long"
my.container.jni_jni_type = "jlong"
my.container.jni_is_class = 1
elsif my.container.callback ?= 1
return 1 # Don't implement callbacks yet
elsif my.container.type = "va_list" \
| my.container.type = "FILE" \
| my.container.type = "zmq_pollitem" \
| my.container.type = "socket"
return 1
else
abort "Unhandled type '$(my.container.type:)' in $(class.c_name)"
endif
# By default, shim gets Java type
my.container.jni_shim_type ?= my.container.jni_java_type
return 0 # Seems to be OK
endfunction
function resolve_method (method)
my.method.okay = 1
if my.method.name = "clone" \
| my.method.name = "close" \
| my.method.name = "equals" \
| my.method.name = "finalize" \
| my.method.name = "getClass" \
| my.method.name = "hashCode" \
| my.method.name = "toString" \
| my.method.name = "notify" \
| my.method.name = "notifyAll" \
| my.method.name = "wait"
my.method.jni_name = "$(name:pascal)" # Leading capital letter
else
my.method.jni_name = "$(name:camel)"
endif
my.method.jni_method_signature = ""
if my.method.singleton = 1
my.method.jni_shim_signature_java = ""
my.method.jni_shim_signature_c = ""
my.method.jni_shim_invocation_java = ""
my.method.jni_native_invocation_c = ""
comma = ""
else
my.method.jni_shim_signature_java = "long self"
my.method.jni_shim_signature_c = "jlong self"
my.method.jni_shim_invocation_java = "self"
my.method.jni_native_invocation_c = "($(class.c_name)_t *) (intptr_t) self"
comma = ", "
endif
for my.method.argument
if resolve_container (argument) = 1
my.method.okay = 0
#echo "Skipping $(class.name).$(my.method.name) - can't deal with argument type $(argument.type)"
last
endif
if variadic = 1
if va_start <> "format"
jni_method_signature += " []"
jni_shim_invocation_java += " [0]"
endif
elsif jni_self_p = 1
jni_shim_signature_java += "$(comma)long self"
jni_shim_invocation_java += "$(comma)self"
jni_shim_signature_c += "$(comma)jlong self"
jni_native_invocation_c += "$(comma)($(argument.c_type)) &self"
my.method.return_self_p = 1
my.method->return.jni_shim_type = "long"
else
if jni_method_signature <> ""
jni_method_signature += ", "
endif
jni_method_signature += "$(argument.jni_java_type:) $(argument.name:camel)"
jni_shim_signature_java += "$(comma)$(argument.jni_shim_type:) $(argument.name:camel)"
jni_shim_signature_c += "$(comma)$(argument.jni_jni_type:) $(argument.c_name)"
jni_shim_invocation_java += "$(comma)$(argument.jni_mapping:)"
if type = "format"
jni_native_invocation_c += "$(comma)\"%s\", $(argument.c_name)_"
elsif type = "string" | type = "buffer"
jni_native_invocation_c += "$(comma)$(argument.c_name)_"
elsif by_reference = 1
jni_native_invocation_c += "$(comma)($(argument.c_type)) (intptr_t) &$(argument.c_name)"
elsif jni_is_class = 1 | type = "anything" | type = "sockish"
jni_native_invocation_c += "$(comma)($(argument.c_type)) (intptr_t) $(argument.c_name)"
else
jni_native_invocation_c += "$(comma)($(argument.c_type)) $(argument.c_name)"
endif
endif
comma = ", "
endfor
for my.method.return
if resolve_container (return)
my.method.okay = 0
#echo "Skipping $(class.name).$(my.method.name) - can't deal with return type $(return.type:)"
else
# returned buffers need a size attribute
if type = "buffer" & !defined (return.size)
my.method.okay = 0
#echo "Skipping $(class.name).$(my.method.name) - can't return unsized fresh buffer"
endif
endif
endfor
endfunction
function resolve_class (class)
if defined (my.class.api) & !my.class.private
my.class.okay = 1
for constructor
resolve_method (constructor)
if index () = 1 & constructor.okay = 0
my.class.okay = 0
endif
endfor
for destructor
resolve_method (destructor)
endfor
for method
resolve_method (method)
endfor
else
my.class.okay = 0
endif
endfunction