OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # TODO (qinmin): Need to refactor this file as base should not know about | 6 # TODO (qinmin): Need to refactor this file as base should not know about |
7 # higher level concepts. Currently this file has knowledge about higher level | 7 # higher level concepts. Currently this file has knowledge about higher level |
8 # java classes. | 8 # java classes. |
9 | 9 |
10 """Extracts native methods from a Java file and generates the JNI bindings. | 10 """Extracts native methods from a Java file and generates the JNI bindings. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 class CalledByNative(object): | 72 class CalledByNative(object): |
73 """Describes a java method exported to c/c++""" | 73 """Describes a java method exported to c/c++""" |
74 | 74 |
75 def __init__(self, **kwargs): | 75 def __init__(self, **kwargs): |
76 self.system_class = kwargs['system_class'] | 76 self.system_class = kwargs['system_class'] |
77 self.unchecked = kwargs['unchecked'] | 77 self.unchecked = kwargs['unchecked'] |
78 self.static = kwargs['static'] | 78 self.static = kwargs['static'] |
79 self.java_class_name = kwargs['java_class_name'] | 79 self.java_class_name = kwargs['java_class_name'] |
80 self.return_type = kwargs['return_type'] | 80 self.return_type = kwargs['return_type'] |
81 self.env_call = kwargs['env_call'] | |
82 self.name = kwargs['name'] | 81 self.name = kwargs['name'] |
83 self.params = kwargs['params'] | 82 self.params = kwargs['params'] |
84 self.method_id_var_name = kwargs.get('method_id_var_name', None) | 83 self.method_id_var_name = kwargs.get('method_id_var_name', None) |
| 84 self.is_constructor = kwargs.get('is_constructor', False) |
| 85 self.env_call = GetEnvCall(self.is_constructor, self.static, |
| 86 self.return_type) |
| 87 self.static_cast = GetStaticCastForReturnType(self.return_type) |
85 | 88 |
86 | 89 |
87 def JavaDataTypeToC(java_type): | 90 def JavaDataTypeToC(java_type): |
88 """Returns a C datatype for the given java type.""" | 91 """Returns a C datatype for the given java type.""" |
89 java_pod_type_map = { | 92 java_pod_type_map = { |
90 'int': 'jint', | 93 'int': 'jint', |
91 'byte': 'jbyte', | 94 'byte': 'jbyte', |
92 'boolean': 'jboolean', | 95 'boolean': 'jboolean', |
93 'long': 'jlong', | 96 'long': 'jlong', |
94 'double': 'jdouble', | 97 'double': 'jdouble', |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 'Ljava/util/ArrayList', | 133 'Ljava/util/ArrayList', |
131 'Ljava/util/HashMap', | 134 'Ljava/util/HashMap', |
132 'Ljava/util/List', | 135 'Ljava/util/List', |
133 'Landroid/content/Context', | 136 'Landroid/content/Context', |
134 'Landroid/graphics/Bitmap', | 137 'Landroid/graphics/Bitmap', |
135 'Landroid/graphics/Canvas', | 138 'Landroid/graphics/Canvas', |
136 'Landroid/graphics/Rect', | 139 'Landroid/graphics/Rect', |
137 'Landroid/graphics/RectF', | 140 'Landroid/graphics/RectF', |
138 'Landroid/graphics/Matrix', | 141 'Landroid/graphics/Matrix', |
139 'Landroid/graphics/Point', | 142 'Landroid/graphics/Point', |
| 143 'Landroid/graphics/SurfaceTexture$OnFrameAvailableListener', |
140 'Landroid/os/Message', | 144 'Landroid/os/Message', |
141 'Landroid/view/KeyEvent', | 145 'Landroid/view/KeyEvent', |
142 'Landroid/view/Surface', | 146 'Landroid/view/Surface', |
143 'Landroid/view/View', | 147 'Landroid/view/View', |
144 'Landroid/webkit/ValueCallback', | 148 'Landroid/webkit/ValueCallback', |
145 'Ljava/io/InputStream', | 149 'Ljava/io/InputStream', |
146 'Ljava/nio/ByteBuffer', | 150 'Ljava/nio/ByteBuffer', |
147 'Ljava/util/Vector', | 151 'Ljava/util/Vector', |
148 ] | 152 ] |
149 app_param_list = [ | 153 app_param_list = [ |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 if param[-2:] == '[]': | 206 if param[-2:] == '[]': |
203 prefix = '[' | 207 prefix = '[' |
204 param = param[:-2] | 208 param = param[:-2] |
205 # Generic? | 209 # Generic? |
206 if '<' in param: | 210 if '<' in param: |
207 param = param[:param.index('<')] | 211 param = param[:param.index('<')] |
208 if param in pod_param_map: | 212 if param in pod_param_map: |
209 return prefix + pod_param_map[param] | 213 return prefix + pod_param_map[param] |
210 for qualified_name in object_param_list + app_param_list: | 214 for qualified_name in object_param_list + app_param_list: |
211 if (qualified_name.endswith('/' + param) or | 215 if (qualified_name.endswith('/' + param) or |
212 qualified_name.endswith('$' + param.replace('.', '$'))): | 216 qualified_name.endswith('$' + param.replace('.', '$')) or |
| 217 qualified_name == 'L' + param): |
213 return prefix + qualified_name + ';' | 218 return prefix + qualified_name + ';' |
214 else: | 219 else: |
215 return UNKNOWN_JAVA_TYPE_PREFIX + prefix + param + ';' | 220 return UNKNOWN_JAVA_TYPE_PREFIX + prefix + param + ';' |
216 | 221 |
217 | 222 |
218 def JniSignature(params, returns, wrap): | 223 def JniSignature(params, returns, wrap): |
219 """Returns the JNI signature for the given datatypes.""" | 224 """Returns the JNI signature for the given datatypes.""" |
220 items = ['('] | 225 items = ['('] |
221 items += [JavaParamToJni(param.datatype) for param in params] | 226 items += [JavaParamToJni(param.datatype) for param in params] |
222 items += [')'] | 227 items += [')'] |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 static='static' in match.group('qualifiers'), | 295 static='static' in match.group('qualifiers'), |
291 java_class_name=match.group('java_class_name'), | 296 java_class_name=match.group('java_class_name'), |
292 native_class_name=match.group('native_class_name'), | 297 native_class_name=match.group('native_class_name'), |
293 return_type=match.group('return'), | 298 return_type=match.group('return'), |
294 name=match.group('name').replace('native', ''), | 299 name=match.group('name').replace('native', ''), |
295 params=ParseParams(match.group('params'))) | 300 params=ParseParams(match.group('params'))) |
296 natives += [native] | 301 natives += [native] |
297 return natives | 302 return natives |
298 | 303 |
299 | 304 |
300 def GetEnvCallForReturnType(return_type): | 305 def GetStaticCastForReturnType(return_type): |
| 306 if return_type == 'String': |
| 307 return 'jstring' |
| 308 return None |
| 309 |
| 310 |
| 311 def GetEnvCall(is_constructor, is_static, return_type): |
301 """Maps the types availabe via env->Call__Method.""" | 312 """Maps the types availabe via env->Call__Method.""" |
302 env_call_map = {'boolean': ('Boolean', ''), | 313 if is_constructor: |
303 'byte': ('Byte', ''), | 314 return 'NewObject' |
304 'char': ('Char', ''), | 315 env_call_map = {'boolean': 'Boolean', |
305 'short': ('Short', ''), | 316 'byte': 'Byte', |
306 'int': ('Int', ''), | 317 'char': 'Char', |
307 'long': ('Long', ''), | 318 'short': 'Short', |
308 'float': ('Float', ''), | 319 'int': 'Int', |
309 'void': ('Void', ''), | 320 'long': 'Long', |
310 'double': ('Double', ''), | 321 'float': 'Float', |
311 'String': ('Object', 'jstring'), | 322 'void': 'Void', |
312 'Object': ('Object', ''), | 323 'double': 'Double', |
| 324 'Object': 'Object', |
313 } | 325 } |
314 return env_call_map.get(return_type, ('Object', '')) | 326 call = env_call_map.get(return_type, 'Object') |
| 327 if is_static: |
| 328 call = 'Static' + call |
| 329 return 'Call' + call + 'Method' |
315 | 330 |
316 | 331 |
317 def GetMangledMethodName(name, jni_signature): | 332 def GetMangledMethodName(name, jni_signature): |
318 """Returns a mangled method name for a (name, jni_signature) pair. | 333 """Returns a mangled method name for a (name, jni_signature) pair. |
319 | 334 |
320 The returned name can be used as a C identifier and will be unique for all | 335 The returned name can be used as a C identifier and will be unique for all |
321 valid overloads of the same method. | 336 valid overloads of the same method. |
322 | 337 |
323 Args: | 338 Args: |
324 name: string. | 339 name: string. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 ParseError: if unable to parse. | 397 ParseError: if unable to parse. |
383 """ | 398 """ |
384 called_by_natives = [] | 399 called_by_natives = [] |
385 for match in re.finditer(RE_CALLED_BY_NATIVE, contents): | 400 for match in re.finditer(RE_CALLED_BY_NATIVE, contents): |
386 called_by_natives += [CalledByNative( | 401 called_by_natives += [CalledByNative( |
387 system_class=False, | 402 system_class=False, |
388 unchecked='Unchecked' in match.group('Unchecked'), | 403 unchecked='Unchecked' in match.group('Unchecked'), |
389 static='static' in match.group('prefix'), | 404 static='static' in match.group('prefix'), |
390 java_class_name=match.group('annotation') or '', | 405 java_class_name=match.group('annotation') or '', |
391 return_type=match.group('return_type'), | 406 return_type=match.group('return_type'), |
392 env_call=GetEnvCallForReturnType(match.group('return_type')), | |
393 name=match.group('name'), | 407 name=match.group('name'), |
394 params=ParseParams(match.group('params')))] | 408 params=ParseParams(match.group('params')))] |
395 # Check for any @CalledByNative occurrences that weren't matched. | 409 # Check for any @CalledByNative occurrences that weren't matched. |
396 unmatched_lines = re.sub(RE_CALLED_BY_NATIVE, '', contents).split('\n') | 410 unmatched_lines = re.sub(RE_CALLED_BY_NATIVE, '', contents).split('\n') |
397 for line1, line2 in zip(unmatched_lines, unmatched_lines[1:]): | 411 for line1, line2 in zip(unmatched_lines, unmatched_lines[1:]): |
398 if '@CalledByNative' in line1: | 412 if '@CalledByNative' in line1: |
399 raise ParseError('could not parse @CalledByNative method signature', | 413 raise ParseError('could not parse @CalledByNative method signature', |
400 line1, line2) | 414 line1, line2) |
401 return MangleCalledByNatives(called_by_natives) | 415 return MangleCalledByNatives(called_by_natives) |
402 | 416 |
403 | 417 |
404 class JNIFromJavaP(object): | 418 class JNIFromJavaP(object): |
405 """Uses 'javap' to parse a .class file and generate the JNI header file.""" | 419 """Uses 'javap' to parse a .class file and generate the JNI header file.""" |
406 | 420 |
407 def __init__(self, contents, namespace): | 421 def __init__(self, contents, namespace): |
408 self.contents = contents | 422 self.contents = contents |
409 self.namespace = namespace | 423 self.namespace = namespace |
410 self.fully_qualified_class = re.match('.*?class (.*?) ', | 424 self.fully_qualified_class = re.match('.*?class (?P<class_name>.*?) ', |
411 contents[1]).group(1) | 425 contents[1]).group('class_name') |
412 self.fully_qualified_class = self.fully_qualified_class.replace('.', '/') | 426 self.fully_qualified_class = self.fully_qualified_class.replace('.', '/') |
413 self.java_class_name = self.fully_qualified_class.split('/')[-1] | 427 self.java_class_name = self.fully_qualified_class.split('/')[-1] |
414 if not self.namespace: | 428 if not self.namespace: |
415 self.namespace = 'JNI_' + self.java_class_name | 429 self.namespace = 'JNI_' + self.java_class_name |
416 re_method = re.compile('(.*?)(\w+?) (\w+?)\((.*?)\)') | 430 re_method = re.compile('(?P<prefix>.*?)(?P<return_type>\w+?) (?P<name>\w+?)' |
| 431 '\((?P<params>.*?)\)') |
417 self.called_by_natives = [] | 432 self.called_by_natives = [] |
418 for method in contents[2:]: | 433 for content in contents[2:]: |
419 match = re.match(re_method, method) | 434 match = re.match(re_method, content) |
420 if not match: | 435 if not match: |
421 continue | 436 continue |
422 self.called_by_natives += [CalledByNative( | 437 self.called_by_natives += [CalledByNative( |
423 system_class=True, | 438 system_class=True, |
424 unchecked=False, | 439 unchecked=False, |
425 static='static' in match.group(1), | 440 static='static' in match.group('prefix'), |
426 java_class_name='', | 441 java_class_name='', |
427 return_type=match.group(2), | 442 return_type=match.group('return_type'), |
428 name=match.group(3), | 443 name=match.group('name'), |
429 params=ParseParams(match.group(4)), | 444 params=ParseParams(match.group('params').replace('.', '/')))] |
430 env_call=GetEnvCallForReturnType(match.group(2)))] | 445 re_constructor = re.compile('.*? public ' + |
| 446 self.fully_qualified_class.replace('/', '.') + |
| 447 '\((?P<params>.*?)\)') |
| 448 for content in contents[2:]: |
| 449 match = re.match(re_constructor, content) |
| 450 if not match: |
| 451 continue |
| 452 self.called_by_natives += [CalledByNative( |
| 453 system_class=False, |
| 454 unchecked=False, |
| 455 static=False, |
| 456 java_class_name='', |
| 457 return_type=self.fully_qualified_class, |
| 458 name='Constructor', |
| 459 params=ParseParams(match.group('params').replace('.', '/')), |
| 460 is_constructor=True)] |
431 self.called_by_natives = MangleCalledByNatives(self.called_by_natives) | 461 self.called_by_natives = MangleCalledByNatives(self.called_by_natives) |
432 self.inl_header_file_generator = InlHeaderFileGenerator( | 462 self.inl_header_file_generator = InlHeaderFileGenerator( |
433 self.namespace, self.fully_qualified_class, [], self.called_by_natives) | 463 self.namespace, self.fully_qualified_class, [], self.called_by_natives) |
434 | 464 |
435 def GetContent(self): | 465 def GetContent(self): |
436 return self.inl_header_file_generator.GetContent() | 466 return self.inl_header_file_generator.GetContent() |
437 | 467 |
438 @staticmethod | 468 @staticmethod |
439 def CreateFromClass(class_file, namespace): | 469 def CreateFromClass(class_file, namespace): |
440 class_name = os.path.splitext(os.path.basename(class_file))[0] | 470 class_name = os.path.splitext(os.path.basename(class_file))[0] |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 function_header_with_unused_template = Template("""\ | 769 function_header_with_unused_template = Template("""\ |
740 ${FUNCTION_SIGNATURE} __attribute__ ((unused)); | 770 ${FUNCTION_SIGNATURE} __attribute__ ((unused)); |
741 ${FUNCTION_SIGNATURE} {""") | 771 ${FUNCTION_SIGNATURE} {""") |
742 template = Template(""" | 772 template = Template(""" |
743 static jmethodID g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; | 773 static jmethodID g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; |
744 ${FUNCTION_HEADER} | 774 ${FUNCTION_HEADER} |
745 /* Must call RegisterNativesImpl() */ | 775 /* Must call RegisterNativesImpl() */ |
746 DCHECK(g_${JAVA_CLASS}_clazz); | 776 DCHECK(g_${JAVA_CLASS}_clazz); |
747 DCHECK(g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}); | 777 DCHECK(g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}); |
748 ${RETURN_DECLARATION} | 778 ${RETURN_DECLARATION} |
749 ${PRE_CALL}env->Call${STATIC}${ENV_CALL}Method(${FIRST_PARAM_IN_CALL}, | 779 ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL}, |
750 g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}${PARAMS_IN_CALL})${POST_CALL}; | 780 g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}${PARAMS_IN_CALL})${POST_CALL}; |
751 ${CHECK_EXCEPTION} | 781 ${CHECK_EXCEPTION} |
752 ${RETURN_CLAUSE} | 782 ${RETURN_CLAUSE} |
753 }""") | 783 }""") |
754 if called_by_native.static: | 784 if called_by_native.static or called_by_native.is_constructor: |
755 first_param_in_declaration = '' | 785 first_param_in_declaration = '' |
756 first_param_in_call = ('g_%s_clazz' % | 786 first_param_in_call = ('g_%s_clazz' % |
757 (called_by_native.java_class_name or | 787 (called_by_native.java_class_name or |
758 self.class_name)) | 788 self.class_name)) |
759 else: | 789 else: |
760 first_param_in_declaration = ', jobject obj' | 790 first_param_in_declaration = ', jobject obj' |
761 first_param_in_call = 'obj' | 791 first_param_in_call = 'obj' |
762 params_in_declaration = self.GetCalledByNativeParamsInDeclaration( | 792 params_in_declaration = self.GetCalledByNativeParamsInDeclaration( |
763 called_by_native) | 793 called_by_native) |
764 if params_in_declaration: | 794 if params_in_declaration: |
765 params_in_declaration = ', ' + params_in_declaration | 795 params_in_declaration = ', ' + params_in_declaration |
766 params_for_call = ', '.join(param.name | 796 params_for_call = ', '.join(param.name |
767 for param in called_by_native.params) | 797 for param in called_by_native.params) |
768 if params_for_call: | 798 if params_for_call: |
769 params_for_call = ', ' + params_for_call | 799 params_for_call = ', ' + params_for_call |
770 pre_call = '' | 800 pre_call = '' |
771 post_call = '' | 801 post_call = '' |
772 if called_by_native.env_call[1]: | 802 if called_by_native.static_cast: |
773 pre_call = 'static_cast<%s>(' % called_by_native.env_call[1] | 803 pre_call = 'static_cast<%s>(' % called_by_native.static_cast |
774 post_call = ')' | 804 post_call = ')' |
775 check_exception = '' | 805 check_exception = '' |
776 if not called_by_native.unchecked: | 806 if not called_by_native.unchecked: |
777 check_exception = 'base::android::CheckException(env);' | 807 check_exception = 'base::android::CheckException(env);' |
778 return_type = JavaDataTypeToC(called_by_native.return_type) | 808 return_type = JavaDataTypeToC(called_by_native.return_type) |
779 return_declaration = '' | 809 return_declaration = '' |
780 return_clause = '' | 810 return_clause = '' |
781 if return_type != 'void': | 811 if return_type != 'void': |
782 pre_call = ' ' + pre_call | 812 pre_call = ' ' + pre_call |
783 return_declaration = return_type + ' ret =' | 813 return_declaration = return_type + ' ret =' |
784 if re.match(RE_SCOPED_JNI_RETURN_TYPES, return_type): | 814 if re.match(RE_SCOPED_JNI_RETURN_TYPES, return_type): |
785 return_type = 'ScopedJavaLocalRef<' + return_type + '>' | 815 return_type = 'ScopedJavaLocalRef<' + return_type + '>' |
786 return_clause = 'return ' + return_type + '(env, ret);' | 816 return_clause = 'return ' + return_type + '(env, ret);' |
787 else: | 817 else: |
788 return_clause = 'return ret;' | 818 return_clause = 'return ret;' |
789 values = { | 819 values = { |
790 'JAVA_CLASS': called_by_native.java_class_name or self.class_name, | 820 'JAVA_CLASS': called_by_native.java_class_name or self.class_name, |
791 'METHOD': called_by_native.name, | 821 'METHOD': called_by_native.name, |
792 'RETURN_TYPE': return_type, | 822 'RETURN_TYPE': return_type, |
793 'RETURN_DECLARATION': return_declaration, | 823 'RETURN_DECLARATION': return_declaration, |
794 'RETURN_CLAUSE': return_clause, | 824 'RETURN_CLAUSE': return_clause, |
795 'FIRST_PARAM_IN_DECLARATION': first_param_in_declaration, | 825 'FIRST_PARAM_IN_DECLARATION': first_param_in_declaration, |
796 'PARAMS_IN_DECLARATION': params_in_declaration, | 826 'PARAMS_IN_DECLARATION': params_in_declaration, |
797 'STATIC': 'Static' if called_by_native.static else '', | 827 'STATIC': 'Static' if called_by_native.static else '', |
798 'PRE_CALL': pre_call, | 828 'PRE_CALL': pre_call, |
799 'POST_CALL': post_call, | 829 'POST_CALL': post_call, |
800 'ENV_CALL': called_by_native.env_call[0], | 830 'ENV_CALL': called_by_native.env_call, |
801 'FIRST_PARAM_IN_CALL': first_param_in_call, | 831 'FIRST_PARAM_IN_CALL': first_param_in_call, |
802 'PARAMS_IN_CALL': params_for_call, | 832 'PARAMS_IN_CALL': params_for_call, |
803 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, | 833 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, |
804 'CHECK_EXCEPTION': check_exception, | 834 'CHECK_EXCEPTION': check_exception, |
805 } | 835 } |
806 values['FUNCTION_SIGNATURE'] = ( | 836 values['FUNCTION_SIGNATURE'] = ( |
807 function_signature_template.substitute(values)) | 837 function_signature_template.substitute(values)) |
808 if called_by_native.system_class: | 838 if called_by_native.system_class: |
809 values['FUNCTION_HEADER'] = ( | 839 values['FUNCTION_HEADER'] = ( |
810 function_header_with_unused_template.substitute(values)) | 840 function_header_with_unused_template.substitute(values)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 values = {'JAVA_CLASS': clazz} | 897 values = {'JAVA_CLASS': clazz} |
868 ret += [template.substitute(values)] | 898 ret += [template.substitute(values)] |
869 return '\n'.join(ret) | 899 return '\n'.join(ret) |
870 | 900 |
871 def GetMethodIDImpl(self, called_by_native): | 901 def GetMethodIDImpl(self, called_by_native): |
872 """Returns the implementation of GetMethodID.""" | 902 """Returns the implementation of GetMethodID.""" |
873 template = Template("""\ | 903 template = Template("""\ |
874 g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = | 904 g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = |
875 base::android::Get${STATIC}MethodID( | 905 base::android::Get${STATIC}MethodID( |
876 env, g_${JAVA_CLASS}_clazz, | 906 env, g_${JAVA_CLASS}_clazz, |
877 "${NAME}", | 907 "${JNI_NAME}", |
878 ${JNI_SIGNATURE}); | 908 ${JNI_SIGNATURE}); |
879 """) | 909 """) |
| 910 jni_name = called_by_native.name |
| 911 jni_return_type = called_by_native.return_type |
| 912 if called_by_native.is_constructor: |
| 913 jni_name = '<init>' |
| 914 jni_return_type = 'void' |
880 values = { | 915 values = { |
881 'JAVA_CLASS': called_by_native.java_class_name or self.class_name, | 916 'JAVA_CLASS': called_by_native.java_class_name or self.class_name, |
882 'NAME': called_by_native.name, | 917 'JNI_NAME': jni_name, |
883 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, | 918 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, |
884 'STATIC': 'Static' if called_by_native.static else '', | 919 'STATIC': 'Static' if called_by_native.static else '', |
885 'JNI_SIGNATURE': JniSignature(called_by_native.params, | 920 'JNI_SIGNATURE': JniSignature(called_by_native.params, |
886 called_by_native.return_type, | 921 jni_return_type, |
887 True) | 922 True) |
888 } | 923 } |
889 return template.substitute(values) | 924 return template.substitute(values) |
890 | 925 |
891 | 926 |
892 def WrapOutput(output): | 927 def WrapOutput(output): |
893 ret = [] | 928 ret = [] |
894 for line in output.splitlines(): | 929 for line in output.splitlines(): |
895 # Do not wrap lines under 80 characters or preprocessor directives. | 930 # Do not wrap lines under 80 characters or preprocessor directives. |
896 if len(line) < 80 or line.lstrip()[:1] == '#': | 931 if len(line) < 80 or line.lstrip()[:1] == '#': |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 input_file = options.input_file | 1022 input_file = options.input_file |
988 output_file = None | 1023 output_file = None |
989 if options.output_dir: | 1024 if options.output_dir: |
990 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1025 root_name = os.path.splitext(os.path.basename(input_file))[0] |
991 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1026 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
992 GenerateJNIHeader(input_file, output_file, options.namespace) | 1027 GenerateJNIHeader(input_file, output_file, options.namespace) |
993 | 1028 |
994 | 1029 |
995 if __name__ == '__main__': | 1030 if __name__ == '__main__': |
996 sys.exit(main(sys.argv)) | 1031 sys.exit(main(sys.argv)) |
OLD | NEW |