| 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 """Extracts native methods from a Java file and generates the JNI bindings. | 6 """Extracts native methods from a Java file and generates the JNI bindings. |
| 7 If you change this, please run and update the tests.""" | 7 If you change this, please run and update the tests.""" |
| 8 | 8 |
| 9 import collections | 9 import collections |
| 10 import errno | 10 import errno |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 if is_method: | 1015 if is_method: |
| 1016 optional_error_return = JavaReturnValueToC(native.return_type) | 1016 optional_error_return = JavaReturnValueToC(native.return_type) |
| 1017 if optional_error_return: | 1017 if optional_error_return: |
| 1018 optional_error_return = ', ' + optional_error_return | 1018 optional_error_return = ', ' + optional_error_return |
| 1019 values.update({ | 1019 values.update({ |
| 1020 'OPTIONAL_ERROR_RETURN': optional_error_return, | 1020 'OPTIONAL_ERROR_RETURN': optional_error_return, |
| 1021 'PARAM0_NAME': native.params[0].name, | 1021 'PARAM0_NAME': native.params[0].name, |
| 1022 'P0_TYPE': native.p0_type, | 1022 'P0_TYPE': native.p0_type, |
| 1023 }) | 1023 }) |
| 1024 template = Template("""\ | 1024 template = Template("""\ |
| 1025 extern "C" __attribute__((visibility("default"))) | 1025 JNI_GENERATOR_EXPORT ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { |
| 1026 ${RETURN} ${STUB_NAME}(JNIEnv* env, | |
| 1027 ${PARAMS_IN_STUB}) { | |
| 1028 ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME}); | 1026 ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME}); |
| 1029 CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN}); | 1027 CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN}); |
| 1030 return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL}; | 1028 return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL}; |
| 1031 } | 1029 } |
| 1032 """) | 1030 """) |
| 1033 else: | 1031 else: |
| 1034 template = Template(""" | 1032 template = Template(""" |
| 1035 static ${RETURN_DECLARATION} ${NAME}(JNIEnv* env, ${PARAMS}); | 1033 static ${RETURN_DECLARATION} ${NAME}(JNIEnv* env, ${PARAMS}); |
| 1036 | 1034 |
| 1037 extern "C" __attribute__((visibility("default"))) | 1035 JNI_GENERATOR_EXPORT ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { |
| 1038 ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { | |
| 1039 return ${NAME}(${PARAMS_IN_CALL})${POST_CALL}; | 1036 return ${NAME}(${PARAMS_IN_CALL})${POST_CALL}; |
| 1040 } | 1037 } |
| 1041 """) | 1038 """) |
| 1042 | 1039 |
| 1043 return template.substitute(values) | 1040 return template.substitute(values) |
| 1044 | 1041 |
| 1045 def GetArgument(self, param): | 1042 def GetArgument(self, param): |
| 1046 if param.datatype == 'int': | 1043 if param.datatype == 'int': |
| 1047 return 'as_jint(' + param.name + ')' | 1044 return 'as_jint(' + param.name + ')' |
| 1048 elif re.match(RE_SCOPED_JNI_TYPES, JavaDataTypeToC(param.datatype)): | 1045 elif re.match(RE_SCOPED_JNI_TYPES, JavaDataTypeToC(param.datatype)): |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1375 root_name = os.path.splitext(os.path.basename(input_file))[0] |
| 1379 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1376 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
| 1380 GenerateJNIHeader(input_file, output_file, options) | 1377 GenerateJNIHeader(input_file, output_file, options) |
| 1381 | 1378 |
| 1382 if options.depfile: | 1379 if options.depfile: |
| 1383 build_utils.WriteDepfile(options.depfile, output_file) | 1380 build_utils.WriteDepfile(options.depfile, output_file) |
| 1384 | 1381 |
| 1385 | 1382 |
| 1386 if __name__ == '__main__': | 1383 if __name__ == '__main__': |
| 1387 sys.exit(main(sys.argv)) | 1384 sys.exit(main(sys.argv)) |
| OLD | NEW |