├── .gitignore ├── .travis.before_install.sh ├── .travis.yml ├── AndroidManifest.xml ├── CHANGELOG.md ├── COPYING.LGPLv2.1 ├── Makefile ├── README.md ├── configure ├── get-deps.sh ├── include └── j4a │ ├── j4a_base.c │ └── j4a_base.h ├── jni ├── Android.mk ├── Application.mk └── j4a │ └── j4a_allclasses.c ├── src ├── .gitignore ├── ast.hpp ├── ast__context.cpp ├── ast__context.hpp ├── ast__def.hpp ├── ast__forward.hpp ├── ast__namespace.cpp ├── ast__namespace.hpp ├── ast_annotation.cpp ├── ast_annotation.hpp ├── ast_argument.cpp ├── ast_argument.hpp ├── ast_class.cpp ├── ast_class.hpp ├── ast_compilation_unit.cpp ├── ast_compilation_unit.hpp ├── ast_constructor.cpp ├── ast_constructor.hpp ├── ast_field.cpp ├── ast_field.hpp ├── ast_identifier.cpp ├── ast_identifier.hpp ├── ast_import.hpp ├── ast_member.cpp ├── ast_member.hpp ├── ast_method.cpp ├── ast_method.hpp ├── ast_modifier.hpp ├── ast_node.cpp ├── ast_node.hpp ├── ast_primitive_type.hpp ├── ast_property_accessor.cpp ├── ast_property_accessor.hpp ├── ast_reference_type.cpp ├── ast_reference_type.hpp ├── ast_type.hpp ├── bison.j4a.y ├── flex.j4a.l ├── j4a.h ├── j4a__def.h ├── j4a__yy.h ├── j4a_object.h ├── j4a_ref_ptr.h ├── j4a_string.cpp ├── j4a_string.h ├── j4a_string.internal.h ├── j4a_string_pool.cpp ├── j4a_string_pool.h └── main.cpp ├── test ├── i_java │ ├── android │ │ ├── media │ │ │ ├── AudioTrack.java │ │ │ ├── MediaCodec.java │ │ │ ├── MediaCrypto.java │ │ │ ├── MediaFormat.java │ │ │ └── PlaybackParams.java │ │ └── os │ │ │ ├── Build.java │ │ │ └── Bundle.java │ ├── java │ │ ├── nio │ │ │ ├── Buffer.java │ │ │ └── ByteBuffer.java │ │ └── util │ │ │ └── ArrayList.java │ ├── test │ │ └── ReturnPrimitive.java │ └── tv │ │ └── danmaku │ │ └── ijk │ │ └── media │ │ └── player │ │ ├── IjkMediaPlayer.java │ │ └── misc │ │ └── IMediaDataSource.java └── ref_c │ ├── android │ ├── media │ │ ├── AudioTrack.c │ │ ├── AudioTrack.h │ │ ├── AudioTrack.include.j4a │ │ ├── AudioTrack.loader.j4a │ │ ├── MediaCodec.c │ │ ├── MediaCodec.h │ │ ├── MediaCodec.include.j4a │ │ ├── MediaCodec.loader.j4a │ │ ├── MediaFormat.c │ │ ├── MediaFormat.h │ │ ├── MediaFormat.include.j4a │ │ ├── MediaFormat.loader.j4a │ │ ├── PlaybackParams.c │ │ ├── PlaybackParams.h │ │ ├── PlaybackParams.include.j4a │ │ └── PlaybackParams.loader.j4a │ └── os │ │ ├── Build.c │ │ ├── Build.h │ │ ├── Build.include.j4a │ │ ├── Build.loader.j4a │ │ ├── Bundle.c │ │ ├── Bundle.h │ │ ├── Bundle.include.j4a │ │ └── Bundle.loader.j4a │ ├── java │ ├── nio │ │ ├── Buffer.c │ │ ├── Buffer.h │ │ ├── Buffer.include.j4a │ │ ├── Buffer.loader.j4a │ │ ├── ByteBuffer.c │ │ ├── ByteBuffer.h │ │ ├── ByteBuffer.include.j4a │ │ └── ByteBuffer.loader.j4a │ └── util │ │ ├── ArrayList.c │ │ ├── ArrayList.h │ │ ├── ArrayList.include.j4a │ │ └── ArrayList.loader.j4a │ ├── test │ ├── ReturnPrimitive.c │ ├── ReturnPrimitive.h │ ├── ReturnPrimitive.include.j4a │ └── ReturnPrimitive.loader.j4a │ └── tv │ └── danmaku │ └── ijk │ └── media │ └── player │ ├── IjkMediaPlayer.c │ ├── IjkMediaPlayer.h │ ├── IjkMediaPlayer.include.j4a │ ├── IjkMediaPlayer.loader.j4a │ └── misc │ ├── IMediaDataSource.c │ ├── IMediaDataSource.h │ ├── IMediaDataSource.include.j4a │ └── IMediaDataSource.loader.j4a ├── tools └── build_contrib.sh └── xcode ├── jni4android.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── jni4android ├── jni4android.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── jni4android └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.d 3 | /config.h 4 | /config.mak 5 | /contrib 6 | /j4a 7 | /jni/j4a 8 | /output 9 | /test/o_c 10 | 11 | # Object files 12 | *.o 13 | *.ko 14 | *.obj 15 | *.elf 16 | 17 | # Precompiled Headers 18 | *.gch 19 | *.pch 20 | 21 | # Libraries 22 | *.lib 23 | *.a 24 | *.la 25 | *.lo 26 | 27 | # Shared objects (inc. Windows DLLs) 28 | *.dll 29 | *.so 30 | *.so.* 31 | *.dylib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | *.i*86 38 | *.x86_64 39 | *.hex 40 | 41 | # Debug files 42 | *.dSYM/ 43 | 44 | # Xcode 45 | # 46 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 47 | 48 | ## Build generated 49 | build/ 50 | DerivedData 51 | 52 | ## Various settings 53 | *.pbxuser 54 | !default.pbxuser 55 | *.mode1v3 56 | !default.mode1v3 57 | *.mode2v3 58 | !default.mode2v3 59 | *.perspectivev3 60 | !default.perspectivev3 61 | xcuserdata 62 | 63 | ## Other 64 | *.xccheckout 65 | *.moved-aside 66 | *.xcuserstate 67 | *.xcscmblueprint 68 | 69 | ## Obj-C/Swift specific 70 | *.hmap 71 | *.ipa 72 | 73 | # CocoaPods 74 | # 75 | # We recommend against adding the Pods directory to your .gitignore. However 76 | # you should judge for yourself, the pros and cons are mentioned at: 77 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 78 | # 79 | # Pods/ 80 | 81 | # Carthage 82 | # 83 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 84 | # Carthage/Checkouts 85 | 86 | Carthage/Build 87 | 88 | # fastlane 89 | # 90 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 91 | # screenshots whenever they are needed. 92 | # For more information about the recommended setup visit: 93 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 94 | 95 | fastlane/report.xml 96 | fastlane/screenshots 97 | 98 | -------------------------------------------------------------------------------- /.travis.before_install.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # 3 | # copyright (c) 2015 Zhang Rui 4 | # 5 | # This file is part of jni4android. 6 | # 7 | # jni4android is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Lesser General Public 9 | # License as published by the Free Software Foundation; either 10 | # version 2.1 of the License, or (at your option) any later version. 11 | # 12 | # jni4android is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with jni4android; if not, write to the Free Software 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | #/ 21 | 22 | echo ".travis.before_install: $TRAVIS_OS_NAME" 23 | case "$TRAVIS_OS_NAME" in 24 | osx) 25 | brew update 26 | brew outdated flex || brew upgrade flex 27 | # bison in homebrew is too old 28 | # brew outdated bison || brew upgrade bison 29 | ;; 30 | esac 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | os: 3 | - linux 4 | - osx 5 | sudo: false 6 | compiler: clang 7 | cache: 8 | timeout: 86400 9 | directories: 10 | - contrib 11 | addons: 12 | apt: 13 | packages: 14 | - flex 15 | before_install: 16 | - ./.travis.before_install.sh 17 | before_script: 18 | - ./get-deps.sh -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilibili/jni4android/8af3ea54d340b56e9f695edb5e7452f1c8ee5d4a/AndroidManifest.xml -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | tag next: 2 | -------------------------------- 3 | 4 | tag v0.0.3: 5 | -------------------------------- 6 | - fix a bug caused by wrong usage of single instance for primitive type 7 | 8 | tag v0.0.2: 9 | -------------------------------- 10 | - fix serval bugs 11 | - add missing support for char, short, double 12 | 13 | tag v0.0.1: 14 | -------------------------------- 15 | - init 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include config.mak 2 | CPPFLAGS = -g -std=c++11 -I./src -Wno-deprecated-register 3 | YACC_FLAGS = --debug --verbose -d 4 | YYLEX_FLAGS = 5 | J4A = ./j4a 6 | ROOT_CLASS_INCLUDES = jni/j4a/j4a_allclasses.include.h 7 | ROOT_CLASS_LOADERS = jni/j4a/j4a_allclasses.loader.h 8 | 9 | all: j4a 10 | 11 | CXX_SRCS = \ 12 | src/ast_annotation.cpp \ 13 | src/ast_argument.cpp \ 14 | src/ast_class.cpp \ 15 | src/ast_compilation_unit.cpp \ 16 | src/ast_constructor.cpp \ 17 | src/ast_field.cpp \ 18 | src/ast_identifier.cpp \ 19 | src/ast_member.cpp \ 20 | src/ast_method.cpp \ 21 | src/ast_node.cpp \ 22 | src/ast_property_accessor.cpp \ 23 | src/ast_reference_type.cpp \ 24 | src/ast__context.cpp \ 25 | src/ast__namespace.cpp \ 26 | src/j4a_string_pool.cpp \ 27 | src/j4a_string.cpp \ 28 | src/flex.j4a.yy.cpp \ 29 | src/bison.j4a.tab.cpp \ 30 | src/main.cpp \ 31 | 32 | CXX_OBJS := $(CXX_SRCS:.cpp=.o) 33 | CXX_DEPS := $(CXX_OBJS:.o=.d) 34 | -include $(CXX_DEPS) 35 | 36 | $(CXX_OBJS): config.mak config.h Makefile src/bison.j4a.tab.cpp src/flex.j4a.yy.cpp 37 | 38 | $(CXX_OBJS): %.o: %.cpp 39 | $(CXX) $(CPPFLAGS) -MM -MT $@ -MF $(patsubst %.o,%.d,$@) $< 40 | $(CXX) $(CPPFLAGS) -c -o $@ $< 41 | 42 | j4a: $(CXX_OBJS) 43 | $(CXX) -o j4a $(CXX_OBJS) 44 | 45 | 46 | 47 | # YACC 48 | YACC_DEPS = \ 49 | src/bison.j4a.y \ 50 | 51 | src/bison.j4a.tab.cpp: $(YACC_DEPS) 52 | $(YACC) $(YACC_FLAGS) -o $@ src/bison.j4a.y 53 | 54 | j4acc: src/bison.j4a.tab.cpp 55 | $(CXX) -o src/j4acc bison.j4a.tab.cpp 56 | 57 | 58 | # YYLEX 59 | YYLEX_DEPS = \ 60 | src/flex.j4a.l \ 61 | src/bison.j4a.tab.cpp \ 62 | 63 | src/flex.j4a.yy.cpp: $(YYLEX_DEPS) 64 | $(YYLEX) $(YYLEX_FLAGS) -o $@ src/flex.j4a.l 65 | 66 | j4alex: src/flex.j4a.yy.cpp 67 | $(CXX) -o src/j4alex flex.j4a.yy.cpp 68 | 69 | 70 | # test java -> c 71 | TEST_JAVA_SRCS = \ 72 | test/i_java/java/nio/Buffer.java \ 73 | test/i_java/java/nio/ByteBuffer.java \ 74 | test/i_java/java/util/ArrayList.java \ 75 | test/i_java/android/media/AudioTrack.java \ 76 | test/i_java/android/media/MediaCodec.java \ 77 | test/i_java/android/media/MediaFormat.java \ 78 | test/i_java/android/media/PlaybackParams.java \ 79 | test/i_java/android/os/Build.java \ 80 | test/i_java/android/os/Bundle.java \ 81 | test/i_java/test/ReturnPrimitive.java \ 82 | test/i_java/tv/danmaku/ijk/media/player/misc/IMediaDataSource.java \ 83 | test/i_java/tv/danmaku/ijk/media/player/IjkMediaPlayer.java \ 84 | 85 | TEST_C_SRCS := $(TEST_JAVA_SRCS:test/i_java/%.java=jni/j4a/class/%.c) 86 | TEST_H_SRCS := $(TEST_C_SRCS:%.c=%.h) 87 | 88 | $(TEST_C_SRCS): jni/j4a/class/%.c: j4a 89 | 90 | $(TEST_C_SRCS): jni/j4a/class/%.c: test/i_java/%.java 91 | ifneq ("$<", "jni/j4a/class/.c") 92 | @mkdir -p $(shell dirname $@) 93 | $(J4A) -c $< -o $@ 94 | @cat jni/j4a/class/$*.include.j4a >> $(ROOT_CLASS_INCLUDES) 95 | @echo >> $(ROOT_CLASS_INCLUDES) 96 | @cat jni/j4a/class/$*.loader.j4a >> $(ROOT_CLASS_LOADERS) 97 | @echo >> $(ROOT_CLASS_LOADERS) 98 | @#cp $@ test/ref_c/$*.c 99 | @#cp jni/j4a/class/$*.h test/ref_c/$*.h 100 | @diff test/ref_c/$*.c $@ 101 | @diff test/ref_c/$*.h jni/j4a/class/$*.h 102 | @diff test/ref_c/$*.include.j4a jni/j4a/class/$*.include.j4a 103 | @diff test/ref_c/$*.loader.j4a jni/j4a/class/$*.loader.j4a 104 | endif 105 | 106 | test: j4a resettest $(TEST_C_SRCS) 107 | 108 | resettest: 109 | @rm -f $(TEST_C_SRCS) 110 | @rm -f $(ROOT_CLASS_INCLUDES) 111 | @rm -f $(ROOT_CLASS_LOADERS) 112 | @mkdir -p jni 113 | @cp -r include/* jni/ 114 | 115 | 116 | 117 | install: j4a 118 | @mkdir -p $(BINDIR) 119 | @cp ./j4a $(BINDIR)/ 120 | @mkdir -p $(INCDIR) 121 | @cp -r include/* $(INCDIR)/ 122 | 123 | 124 | 125 | # ----- 126 | .PHONY: all test clean install 127 | 128 | clean: resettest 129 | rm -f $(CXX_OBJS) 130 | rm -f $(CXX_DEPS) 131 | rm -f j4a 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jni4android 2 | 3 | [![Build Status](https://travis-ci.org/Bilibili/jni4android.svg?branch=master)](https://travis-ci.org/Bilibili/jni4android) 4 | 5 | Generate C wrapper from Pseudo-Java 6 | 7 | ### My Build Environment 8 | - Common 9 | - Mac OS X 10.10.5 10 | - Xcode 7.2 (7C68) 11 | - flex 2.5.35 Apple(flex-31) 12 | - bison (GNU Bison) 3.0.4 13 | - [HomeBrew](http://brew.sh) 14 | - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 15 | - brew install git 16 | - brew install flex 17 | - brew install bison 18 | 19 | ### Build 20 | 21 | ``` 22 | git clone https://github.com/Bilibili/jni4android.git jni4android 23 | cd jni4android 24 | 25 | # build dependencies 26 | # you don't have to run this if you have bison 3.x installed 27 | ./get-deps.sh 28 | 29 | ./configure 30 | make 31 | ``` 32 | 33 | ### Usage 34 | 35 | ``` 36 | Usage: 37 | j4a -h 38 | j4a -c [-o ] 39 | 40 | Startup: 41 | -c, --compile compile file. 42 | -h, --help print this help. 43 | -o, --output output file. 44 | ``` 45 | 46 | ### Example 47 | 48 | - input https://github.com/Bilibili/jni4android/blob/master/test/i_java/android/media/AudioTrack.java 49 | - output https://github.com/Bilibili/jni4android/blob/master/test/ref_c/android/media/AudioTrack.h 50 | - output https://github.com/Bilibili/jni4android/blob/master/test/ref_c/android/media/AudioTrack.c 51 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # 3 | # copyright (c) 2015 Zhang Rui 4 | # 5 | # This file is part of jni4android. 6 | # 7 | # jni4android is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Lesser General Public 9 | # License as published by the Free Software Foundation; either 10 | # version 2.1 of the License, or (at your option) any later version. 11 | # 12 | # jni4android is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with jni4android; if not, write to the Free Software 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | #/ 21 | 22 | build_root_dir=`pwd` 23 | 24 | die_unknown(){ 25 | echo "Unknown option \"$1\"." 26 | echo "See $0 --help for available options." 27 | exit 1 28 | } 29 | 30 | is_in(){ 31 | value=$1 32 | shift 33 | for var in $*; do 34 | [ $var = $value ] && return 0 35 | done 36 | return 1 37 | } 38 | 39 | 40 | 41 | #----- define options ----- 42 | PATHS_LIST=" 43 | bindir 44 | incdir 45 | prefix 46 | " 47 | 48 | CMDLINE_SET=" 49 | $PATHS_LIST 50 | cxx 51 | yacc 52 | yylex 53 | " 54 | 55 | 56 | 57 | #----- init options ----- 58 | opt_prefix_default="output" 59 | opt_cxx_default="clang++" 60 | opt_yacc_default="bison" 61 | opt_yylex_default="flex" 62 | 63 | 64 | 65 | # auto detect bison 66 | YACC_LIST=" 67 | $build_root_dir/contrib/build/bin/bison 68 | /usr/local/opt/bison/bin/bison 69 | " 70 | for alter_yacc in $YACC_LIST; do 71 | if [ -f $alter_yacc ]; then 72 | opt_yacc_default=$alter_yacc 73 | break 74 | fi 75 | done 76 | #if [ -f "$build_root_dir/contrib/bin/bison" ]; then 77 | # opt_yacc_default="$build_root_dir/contrib/bin/bison" 78 | #elif [ -f "/usr/local/opt/bison/bin/bison" ]; then 79 | # opt_yacc_default="/usr/local/opt/bison/bin/bison" 80 | #fi 81 | 82 | 83 | 84 | for optname in $CMDLINE_SET; do 85 | eval opt_$optname= 86 | done 87 | 88 | 89 | 90 | 91 | show_help(){ 92 | cat < config.mak < config.h < 4 | # 5 | # This file is part of jni4android. 6 | # 7 | # jni4android is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Lesser General Public 9 | # License as published by the Free Software Foundation; either 10 | # version 2.1 of the License, or (at your option) any later version. 11 | # 12 | # jni4android is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with jni4android; if not, write to the Free Software 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | #/ 21 | 22 | build_bison() { 23 | local mod="bison" 24 | local ver="3.0.4" 25 | local url="ftp://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz" 26 | if [ ! -f contrib/build/bin/bison ]; then 27 | tools/build_contrib.sh $mod $ver $url 28 | fi 29 | } 30 | 31 | build_bison 32 | -------------------------------------------------------------------------------- /include/j4a/j4a_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A_BASE_H 22 | #define J4A_BASE_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #ifndef J4A_UNUSED 31 | #define J4A_UNUSED(x) x __attribute__((unused)) 32 | #endif 33 | 34 | #define J4A_LOG_TAG "J4A" 35 | #define J4A_VLOGV(...) __android_log_vprint(ANDROID_LOG_VERBOSE, J4A_LOG_TAG, __VA_ARGS__) 36 | #define J4A_VLOGD(...) __android_log_vprint(ANDROID_LOG_DEBUG, J4A_LOG_TAG, __VA_ARGS__) 37 | #define J4A_VLOGI(...) __android_log_vprint(ANDROID_LOG_INFO, J4A_LOG_TAG, __VA_ARGS__) 38 | #define J4A_VLOGW(...) __android_log_vprint(ANDROID_LOG_WARN, J4A_LOG_TAG, __VA_ARGS__) 39 | #define J4A_VLOGE(...) __android_log_vprint(ANDROID_LOG_ERROR, J4A_LOG_TAG, __VA_ARGS__) 40 | 41 | #define J4A_ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, J4A_LOG_TAG, __VA_ARGS__) 42 | #define J4A_ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, J4A_LOG_TAG, __VA_ARGS__) 43 | #define J4A_ALOGI(...) __android_log_print(ANDROID_LOG_INFO, J4A_LOG_TAG, __VA_ARGS__) 44 | #define J4A_ALOGW(...) __android_log_print(ANDROID_LOG_WARN, J4A_LOG_TAG, __VA_ARGS__) 45 | #define J4A_ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, J4A_LOG_TAG, __VA_ARGS__) 46 | 47 | #define J4A_FUNC_FAIL_TRACE() do {J4A_ALOGE("%s: failed\n", __func__);} while (0) 48 | #define J4A_FUNC_FAIL_TRACE1(x__) do {J4A_ALOGE("%s: failed: %s\n", __func__, x__);} while (0) 49 | #define J4A_FUNC_FAIL_TRACE2(x1__, x2__) do {J4A_ALOGE("%s: failed: %s %s\n", __func__, x1__, x2__);} while (0) 50 | 51 | #define J4A_LOAD_CLASS(class__) \ 52 | do { \ 53 | ret = J4A_loadClass__J4AC_##class__(env); \ 54 | if (ret) \ 55 | goto fail; \ 56 | } while (0) 57 | 58 | /******************** 59 | * Exception Handle 60 | ********************/ 61 | 62 | bool J4A_ExceptionCheck__throwAny(JNIEnv *env); 63 | bool J4A_ExceptionCheck__catchAll(JNIEnv *env); 64 | int J4A_ThrowExceptionOfClass(JNIEnv* env, jclass clazz, const char* msg); 65 | int J4A_ThrowException(JNIEnv* env, const char* class_sign, const char* msg); 66 | int J4A_ThrowIllegalStateException(JNIEnv *env, const char* msg); 67 | 68 | /******************** 69 | * References 70 | ********************/ 71 | jclass J4A_NewGlobalRef__catchAll(JNIEnv *env, jobject obj); 72 | void J4A_DeleteLocalRef(JNIEnv *env, jobject obj); 73 | void J4A_DeleteLocalRef__p(JNIEnv *env, jobject *obj); 74 | void J4A_DeleteGlobalRef(JNIEnv *env, jobject obj); 75 | void J4A_DeleteGlobalRef__p(JNIEnv *env, jobject *obj); 76 | 77 | void J4A_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *c_str); 78 | void J4A_ReleaseStringUTFChars__p(JNIEnv *env, jstring str, const char **c_str); 79 | 80 | /******************** 81 | * Class Load 82 | ********************/ 83 | 84 | int J4A_LoadAll__catchAll(JNIEnv *env); 85 | jclass J4A_FindClass__catchAll(JNIEnv *env, const char *class_sign); 86 | jclass J4A_FindClass__asGlobalRef__catchAll(JNIEnv *env, const char *class_sign); 87 | 88 | jmethodID J4A_GetMethodID__catchAll(JNIEnv *env, jclass clazz, const char *method_name, const char *method_sign); 89 | jmethodID J4A_GetStaticMethodID__catchAll(JNIEnv *env, jclass clazz, const char *method_name, const char *method_sign); 90 | 91 | jfieldID J4A_GetFieldID__catchAll(JNIEnv *env, jclass clazz, const char *field_name, const char *method_sign); 92 | jfieldID J4A_GetStaticFieldID__catchAll(JNIEnv *env, jclass clazz, const char *field_name, const char *method_sign); 93 | 94 | /******************** 95 | * Misc Functions 96 | ********************/ 97 | 98 | jbyteArray J4A_NewByteArray__catchAll(JNIEnv *env, jsize capacity); 99 | jbyteArray J4A_NewByteArray__asGlobalRef__catchAll(JNIEnv *env, jsize capacity); 100 | 101 | int J4A_GetSystemAndroidApiLevel(JNIEnv *env); 102 | 103 | #endif//J4A_INTERNAL_H 104 | -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # copyright (c) 2016 Zhang Rui 3 | # 4 | # This file is part of ijkPlayer. 5 | # 6 | # ijkPlayer is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public 8 | # License as published by the Free Software Foundation; either 9 | # version 2.1 of the License, or (at your option) any later version. 10 | # 11 | # ijkPlayer is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with ijkPlayer; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | LOCAL_PATH := $(call my-dir) 21 | 22 | include $(CLEAR_VARS) 23 | 24 | LOCAL_CFLAGS += -std=c99 25 | LOCAL_C_INCLUDES += $(LOCAL_PATH) 26 | 27 | # LOCAL_STATIC_LIBRARIES += cpufeatures 28 | # $(call import-module,android/cpufeatures) 29 | 30 | LOCAL_SRC_FILES += j4a/j4a_allclasses.c 31 | LOCAL_SRC_FILES += j4a/j4a_base.c 32 | LOCAL_SRC_FILES += j4a/class/android/media/AudioTrack.c 33 | LOCAL_SRC_FILES += j4a/class/android/media/MediaCodec.c 34 | LOCAL_SRC_FILES += j4a/class/android/media/MediaFormat.c 35 | LOCAL_SRC_FILES += j4a/class/android/media/PlaybackParams.c 36 | LOCAL_SRC_FILES += j4a/class/android/os/Build.c 37 | LOCAL_SRC_FILES += j4a/class/android/os/Bundle.c 38 | LOCAL_SRC_FILES += j4a/class/java/nio/Buffer.c 39 | LOCAL_SRC_FILES += j4a/class/java/nio/ByteBuffer.c 40 | LOCAL_SRC_FILES += j4a/class/java/util/ArrayList.c 41 | LOCAL_SRC_FILES += j4a/class/tv/danmaku/ijk/media/player/IjkMediaPlayer.c 42 | LOCAL_SRC_FILES += j4a/class/tv/danmaku/ijk/media/player/misc/IMediaDataSource.c 43 | 44 | LOCAL_MODULE := j4a 45 | include $(BUILD_STATIC_LIBRARY) 46 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | # 2 | # copyright (c) 2016 Zhang Rui 3 | # 4 | # This file is part of ijkPlayer. 5 | # 6 | # ijkPlayer is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public 8 | # License as published by the Free Software Foundation; either 9 | # version 2.1 of the License, or (at your option) any later version. 10 | # 11 | # ijkPlayer is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with ijkPlayer; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | APP_OPTIM := release 21 | APP_PLATFORM := android-9 22 | APP_ABI := armeabi-v7a 23 | NDK_TOOLCHAIN_VERSION=4.8 24 | APP_PIE := false 25 | -------------------------------------------------------------------------------- /jni/j4a/j4a_allclasses.c: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "j4a/j4a_base.h" 22 | #include "j4a/j4a_allclasses.include.h" 23 | 24 | int J4A_LoadAll__catchAll(JNIEnv *env) 25 | { 26 | int ret = 0; 27 | 28 | #include "j4a/j4a_allclasses.loader.h" 29 | 30 | fail: 31 | return ret; 32 | } 33 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.output 2 | bison.j4a.tab.cpp 3 | bison.j4a.tab.hpp 4 | flex.j4a.yy.cpp 5 | -------------------------------------------------------------------------------- /src/ast.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST__HPP 22 | #define J4A__AST__HPP 23 | 24 | #include "ast_identifier.hpp" 25 | #include "ast_import.hpp" 26 | #include "ast_type.hpp" 27 | #include "ast_primitive_type.hpp" 28 | #include "ast_reference_type.hpp" 29 | #include "ast_member.hpp" 30 | #include "ast_field.hpp" 31 | #include "ast_argument.hpp" 32 | #include "ast_constructor.hpp" 33 | #include "ast_method.hpp" 34 | #include "ast_class.hpp" 35 | #include "ast_compilation_unit.hpp" 36 | #include "ast__context.hpp" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/ast__context.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast__context.hpp" 22 | 23 | #include "ast.hpp" 24 | 25 | using namespace ast; 26 | 27 | Context *Context::s_instance; 28 | 29 | Namespace *Context::get_local_namespace() 30 | { 31 | assert(!m_namespace_stack.empty()); 32 | return m_namespace_stack.back(); 33 | } 34 | 35 | void Context::push_local_namespace(Namespace *local_namespace) 36 | { 37 | m_namespace_stack.push_back(local_namespace); 38 | } 39 | 40 | void Context::pop_local_namespace() 41 | { 42 | assert(!m_namespace_stack.empty()); 43 | m_namespace_stack.pop_back(); 44 | } 45 | 46 | void Context::add_java_package(const char *package_name) 47 | { 48 | get_global_name_space()->add_class_identifier(ast::Identifier::create_by_split(package_name, '.')); 49 | } 50 | 51 | Identifier *Context::find_identifier(Node *node, const j4a::string& name) 52 | { 53 | Identifier *qid = NULL; 54 | 55 | CompilationUnit *this_compilation_unit = node->get_this_compilation_unit(); 56 | if (this_compilation_unit) { 57 | // before AST build 58 | Class *this_class = node->get_this_class(); 59 | while (this_class) { 60 | qid = this_class->get_local_namespace()->find_identifier(name); 61 | if (qid) 62 | return qid; 63 | 64 | if (!this_class->get_parent()) 65 | break; 66 | 67 | this_class = this_class->get_parent()->get_this_class(); 68 | } 69 | 70 | qid = this_compilation_unit->get_local_namespace()->find_identifier(name); 71 | if (qid) 72 | return qid; 73 | } else { 74 | // after AST build 75 | NamespaceStack::reverse_iterator rbegin = m_namespace_stack.rbegin(); 76 | NamespaceStack::reverse_iterator rend = m_namespace_stack.rend(); 77 | 78 | for (NULL; rbegin != rend; ++rbegin) { 79 | qid = (*rbegin)->find_identifier(name); 80 | if (qid) 81 | return qid; 82 | } 83 | } 84 | 85 | qid = get_global_name_space()->find_identifier(name); 86 | return qid; 87 | } 88 | -------------------------------------------------------------------------------- /src/ast__context.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST__CONTEXT__HPP 22 | #define J4A__AST__CONTEXT__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast__namespace.hpp" 26 | #include "ast_identifier.hpp" 27 | #include 28 | #include 29 | #include 30 | 31 | NS_AST_BEGIN 32 | 33 | class QualifiedIdentifier; 34 | class Class; 35 | 36 | class Context 37 | { 38 | public: 39 | typedef std::vector NamespaceStack; 40 | typedef std::deque NodePool; 41 | 42 | AST_PROPERTY_DEFINE(std::string, h_file_path); 43 | AST_PROPERTY_DEFINE(std::string, c_file_path); 44 | AST_PROPERTY_DEFINE(std::string, j4a_include_file_path); 45 | AST_PROPERTY_DEFINE(std::string, j4a_loader_file_path); 46 | AST_PROPERTY_DEFINE(std::string, java_class_dir); 47 | AST_PROPERTY_DEFINE(Namespace*, global_name_space); 48 | 49 | public: 50 | void add_java_package(const char *package_name); 51 | 52 | Identifier *find_identifier(Node *node, const j4a::string& name); 53 | 54 | Namespace *get_local_namespace(); 55 | void push_local_namespace(Namespace *local_namespace); 56 | void pop_local_namespace(); 57 | 58 | j4a::string get_sign_in_method(j4a::string name); 59 | 60 | template 61 | T* put(T *node) 62 | { 63 | m_node_pool.push_back(node); 64 | return node; 65 | } 66 | 67 | private: 68 | Context() { 69 | Namespace *global_namespace = new Namespace(); 70 | set_global_name_space(global_namespace); 71 | } 72 | 73 | public: 74 | static Context *instance() { 75 | if (!s_instance) { 76 | s_instance = new Context(); 77 | } 78 | return s_instance; 79 | } 80 | 81 | private: 82 | NamespaceStack m_namespace_stack; 83 | NodePool m_node_pool; 84 | static Context *s_instance; 85 | }; 86 | 87 | NS_AST_END 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/ast__forward.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A_AST__FORWARD__H 22 | #define J4A_AST__FORWARD__H 23 | 24 | #include 25 | #include "j4a_string.h" 26 | #include "j4a_object.h" 27 | #include "j4a_ref_ptr.h" 28 | 29 | #define NS_AST_BEGIN namespace ast { 30 | #define NS_AST_END } 31 | 32 | NS_AST_BEGIN 33 | 34 | // https://docs.oracle.com/javase/specs/jls/se7/html/jls-18.html 35 | class Annotation; 36 | class Annotations; 37 | class Argument; 38 | class ArgumentList; 39 | class Class; 40 | class ClassIdentifier; 41 | class CompilationUnit; 42 | class Constructor; 43 | class Field; 44 | class Identifier; 45 | class ImportList; 46 | class MemberList; 47 | class Method; 48 | class MethodList; 49 | class ModifierSet; 50 | class Node; 51 | class PrimitiveType; 52 | class ReferenceType; 53 | class Type; 54 | 55 | NS_AST_END 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/ast__namespace.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast__namespace.hpp" 22 | #include 23 | #include 24 | #include "ast__context.hpp" 25 | #include "ast_class.hpp" 26 | 27 | using namespace ast; 28 | 29 | void Namespace::add_package_identifier(Identifier *package_identifier) 30 | { 31 | DIR *d; 32 | struct dirent *dir; 33 | 34 | assert(package_identifier); 35 | d = opendir(Context::instance()->get_java_class_dir().c_str()); 36 | if (d) { 37 | while ((dir = readdir(d)) != NULL) { 38 | const char *ext = strchr(dir->d_name, '.'); 39 | if (ext && 0 == strcmp(ext, ".java")) { 40 | j4a::string class_name(dir->d_name, ext - dir->d_name); 41 | add_class_identifier(Identifier::create_with_prefix(class_name, package_identifier)); 42 | } 43 | } 44 | closedir(d); 45 | } 46 | } 47 | 48 | void Namespace::add_class_identifier(Identifier *class_identifier) 49 | { 50 | j4a::string name = class_identifier->get_name(); 51 | j4a::string full_name = class_identifier->get_java_long_name(); 52 | m_id_map[name] = class_identifier; 53 | m_id_map[full_name] = class_identifier; 54 | 55 | Identifier::pointer_type outer_class = class_identifier->get_outer_class_identifier(); 56 | if (!outer_class) 57 | return; 58 | 59 | Identifier::pointer_type inner_identifier = Identifier::create(class_identifier->get_name()); 60 | Identifier::pointer_type outer_identifier = inner_identifier; 61 | while (outer_class) { 62 | outer_identifier->set_prefix(Identifier::create(outer_class->get_name())); 63 | outer_identifier = outer_identifier->get_prefix(); 64 | 65 | j4a::string relative_name = inner_identifier->get_java_long_name(); 66 | Identifier::pointer_type relative_identifier = Identifier::create_by_split(relative_name.c_str()); 67 | m_id_map[relative_name] = relative_identifier; 68 | 69 | outer_class = outer_class->get_outer_class_identifier(); 70 | } 71 | } 72 | 73 | Identifier *Namespace::find_identifier(const j4a::string &name) 74 | { 75 | IdentifierMap::iterator find = m_id_map.find(name); 76 | return find == m_id_map.end() ? NULL : find->second.get(); 77 | } 78 | -------------------------------------------------------------------------------- /src/ast__namespace.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST__NAMESPACE__HPP 22 | #define J4A__AST__NAMESPACE__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_identifier.hpp" 26 | 27 | NS_AST_BEGIN 28 | 29 | class Namespace 30 | { 31 | public: 32 | AST_PROPERTY_DEFINE(Identifier::pointer_type, identifier); 33 | 34 | public: 35 | typedef std::map IdentifierMap; 36 | typedef IdentifierMap::iterator iterator; 37 | 38 | iterator begin() {return m_id_map.begin();} 39 | iterator end() {return m_id_map.end();} 40 | 41 | void add_package_identifier(Identifier *package_identifier); 42 | void add_class_identifier(Identifier *class_identifier); 43 | template 44 | void add_class_identifiers(T begin, T end) { 45 | for (NULL; begin != end; ++begin) { 46 | add_class_identifier(*begin); 47 | } 48 | } 49 | 50 | Identifier *find_identifier(const j4a::string &name); 51 | 52 | void clear() {m_id_map.clear();} 53 | 54 | private: 55 | IdentifierMap m_id_map; 56 | }; 57 | 58 | NS_AST_END 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/ast_annotation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_annotation.hpp" 22 | #include "ast__context.hpp" 23 | 24 | using namespace ast; 25 | -------------------------------------------------------------------------------- /src/ast_annotation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_ANNOTATION__HPP 22 | #define J4A__AST_ANNOTATION__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_identifier.hpp" 26 | 27 | NS_AST_BEGIN 28 | 29 | class Annotation: public Identifier 30 | { 31 | public: 32 | AST_IMPLEMENT(Annotation); 33 | AST_CREATE_NAMED___(Annotation, Identifier); 34 | 35 | AST_PROPERTY_DEFINE(j4a::string, value); 36 | 37 | public: 38 | // @Override 39 | virtual void debug_print(int indent) override { 40 | if (get_value().is_null()) 41 | std::cout << "@" << get_name() << std::endl; 42 | else 43 | std::cout << "@" << get_name() << "(" << get_value() << ")" << std::endl; 44 | } 45 | }; 46 | 47 | class Annotations: public IdentifierMap 48 | { 49 | public: 50 | AST_IMPLEMENT(Annotations); 51 | AST_CREATE_NONAME__(Annotations, IdentifierMap); 52 | 53 | public: 54 | // @Override 55 | virtual void debug_print(int indent) override { 56 | iterator begin = this->begin(); 57 | iterator end = this->end(); 58 | 59 | for (NULL; begin != end; ++begin) { 60 | begin->second->debug_print(indent); 61 | } 62 | } 63 | }; 64 | 65 | NS_AST_END 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/ast_argument.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_argument.hpp" 22 | #include "ast__context.hpp" 23 | 24 | using namespace ast; 25 | -------------------------------------------------------------------------------- /src/ast_argument.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_ARGUMENT__HPP 22 | #define J4A__AST_ARGUMENT__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_type.hpp" 26 | 27 | NS_AST_BEGIN 28 | 29 | class Argument: public Identifier 30 | { 31 | public: 32 | AST_IMPLEMENT(Argument); 33 | AST_CREATE_NAMED___(Argument, Identifier); 34 | 35 | AST_CHILD_DEFINE(Type, type); 36 | 37 | public: 38 | // @Override 39 | virtual void debug_print(int indent) override { 40 | get_type()->debug_print(0); 41 | std::cout << " " << get_name(); 42 | } 43 | }; 44 | 45 | class ArgumentList: public NodeList 46 | { 47 | public: 48 | AST_IMPLEMENT(ArgumentList); 49 | AST_CREATE_NONAME__(ArgumentList, NodeList); 50 | 51 | // @Override 52 | virtual void debug_print(int indent) override { 53 | iterator begin = this->begin(); 54 | iterator end = this->end(); 55 | 56 | if (begin != end) { 57 | (*begin)->debug_print(indent); 58 | ++begin; 59 | 60 | for (NULL; begin != end; ++begin) { 61 | printf(", "); 62 | (*begin)->debug_print(indent); 63 | } 64 | } 65 | } 66 | }; 67 | 68 | NS_AST_END 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/ast_class.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_class.hpp" 22 | #include "ast_identifier.hpp" 23 | #include "ast_compilation_unit.hpp" 24 | 25 | using namespace ast; 26 | 27 | j4a::string Class::get_c_jni_sign() 28 | { 29 | std::ostringstream os; 30 | if (get_parent()->get_this_class()) { 31 | // inner class 32 | os << get_parent()->get_this_class()->get_c_jni_sign(); 33 | os << "$"; 34 | } else { 35 | os << get_this_package()->get_c_jni_sign(); 36 | os << "/"; 37 | } 38 | os << get_name(); 39 | return os; 40 | } 41 | 42 | //@Override 43 | j4a::string Class::get_c_jni_id_name() 44 | { 45 | return "id"; 46 | } 47 | 48 | //@Override 49 | void Class::build_c_func_decl(std::ostream &os) 50 | { 51 | get_member_list()->build_all_c_func_decl(os); 52 | if (get_parent()->get_this_class() == NULL) { 53 | // do not export inner class loader 54 | os << "int J4A_loadClass__" << get_c_class_name() << "(JNIEnv *env);" << std::endl; 55 | } 56 | } 57 | 58 | //@Override 59 | void Class::build_c_simple_func_decl(std::ostream &os) 60 | { 61 | get_member_list()->build_all_c_simple_func_decl(os); 62 | if (get_parent()->get_this_class() == NULL) { 63 | // do not export inner class loader 64 | os << "#define" 65 | << " J4A_loadClass__" << get_c_simple_class_name() 66 | << " J4A_loadClass__" << get_c_class_name() 67 | << std::endl; 68 | } 69 | } 70 | 71 | //@Override 72 | void Class::build_c_class_decl(std::ostream &os) 73 | { 74 | get_member_list()->build_all_c_class_decl(os); 75 | 76 | os << std::endl; 77 | os << build_indent() << "typedef struct " << get_c_class_name() << " {" << std::endl; 78 | os << build_indent() << " jclass id;" << std::endl; 79 | get_member_list()->build_all_c_member_id_decl(os); 80 | os << build_indent() << "} " << get_c_class_name() << ";" << std::endl; 81 | os << build_indent() << "static " << get_c_class_name() << " " << get_c_jni_class_instance() << ";" << std::endl; 82 | } 83 | 84 | //@Override 85 | void Class::build_c_member_id_load(std::ostream &os) 86 | { 87 | os << std::endl; 88 | os << build_indent() << "ret = J4A_loadClass__" << get_c_class_name() << "(env);" << std::endl; 89 | os << build_indent() << "if (ret)" << std::endl; 90 | os << build_indent() << " goto fail;" << std::endl; 91 | } 92 | 93 | //@Override 94 | void Class::build_c_func_impl(std::ostream &os) 95 | { 96 | bool need_label_ignore = false; 97 | get_member_list()->build_all_c_func_impl(os); 98 | 99 | os << std::endl; 100 | os << "int J4A_loadClass__" << get_c_class_name() << "(JNIEnv *env)" << std::endl; 101 | os << "{" << std::endl; 102 | os << " int ret = -1;" << std::endl; 103 | os << " const char *J4A_UNUSED(name) = NULL;" << std::endl; 104 | os << " const char *J4A_UNUSED(sign) = NULL;" << std::endl; 105 | os << " jclass J4A_UNUSED(class_id) = NULL;" << std::endl; 106 | os << " int J4A_UNUSED(api_level) = 0;" << std::endl; 107 | os << std::endl; 108 | os << " if (" << get_c_jni_id() << " != NULL)" << std::endl; 109 | os << " return 0;" << std::endl; 110 | 111 | Annotation *annotation = get_annotation_at("MinApi"); 112 | if (annotation) { 113 | need_label_ignore = true; 114 | os << std::endl; 115 | os << " api_level = J4A_GetSystemAndroidApiLevel(env);\n" << std::endl; 116 | os << " if (api_level < " << annotation->get_value() << ") {" << std::endl; 117 | os << " J4A_ALOGW(" << j4a::make_quoted("J4ALoader: Ignore: '%s' need API %d\\n") << ", " << j4a::make_quoted(get_java_long_name()) << ", api_level);" << std::endl; 118 | os << " goto ignore;" << std::endl; 119 | os << " }" << std::endl; 120 | } 121 | 122 | os << std::endl; 123 | os << " sign = \"" << get_c_jni_sign() << "\";" << std::endl; 124 | os << " " << get_c_jni_id() << " = J4A_FindClass__asGlobalRef__catchAll(env, sign);" << std::endl; 125 | os << " if (" << get_c_jni_id() << " == NULL)" << std::endl; 126 | os << " goto fail;" << std::endl; 127 | get_member_list()->build_all_c_member_id_load(os); 128 | os << std::endl; 129 | os << " J4A_ALOGD(" << j4a::make_quoted("J4ALoader: OK: '%s' loaded\\n") << ", " << j4a::make_quoted(get_java_long_name()) << ");" << std::endl; 130 | if (need_label_ignore) 131 | os << "ignore:" << std::endl; 132 | os << " ret = 0;" << std::endl; 133 | os << "fail:" << std::endl; 134 | os << " return ret;" << std::endl; 135 | os << "}" << std::endl; 136 | } 137 | -------------------------------------------------------------------------------- /src/ast_class.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_CLASS__HPP 22 | #define J4A__AST_CLASS__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast__namespace.hpp" 26 | #include "ast_member.hpp" 27 | 28 | NS_AST_BEGIN 29 | 30 | class Class: public Member 31 | { 32 | public: 33 | AST_IMPLEMENT(Class); 34 | AST_CREATE_NAMED___(Class, Member); 35 | AST_CREATE_POINTER_(Class, Member, Identifier); 36 | 37 | AST_PROPERTY_DEFINE(Namespace*, local_namespace) = new Namespace(); 38 | AST_PROPERTY_DEFINE(bool, is_interface) = false; 39 | 40 | AST_CHILD_DEFINE(MemberList, member_list); 41 | 42 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_sign); 43 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_id_name); 44 | 45 | public: 46 | j4a::string get_c_jni_class_instance() { 47 | std::ostringstream os; 48 | os << "class_" << get_c_class_name(); 49 | return os; 50 | } 51 | 52 | bool need_c_simple_class_name() { 53 | return get_annotation_at("SimpleCClassName") != NULL; 54 | } 55 | 56 | public: 57 | // class Member 58 | // @Override 59 | virtual void build_c_func_decl(std::ostream &os) override; 60 | virtual void build_c_simple_func_decl(std::ostream &os) override; 61 | // @Override 62 | virtual void build_c_class_decl(std::ostream &os) override; 63 | // @Override 64 | // virtual void build_c_member_id_decl(std::ostream &os) override; 65 | // @Override 66 | virtual void build_c_member_id_load(std::ostream &os) override; 67 | // @Override 68 | virtual void build_c_func_impl(std::ostream &os) override; 69 | 70 | // class Identifier 71 | virtual j4a::string get_java_long_name() override { 72 | if (get_parent()) { 73 | std::ostringstream os; 74 | if (get_parent()->get_this_class()) { 75 | // inner class 76 | os << get_parent()->get_this_class()->get_java_long_name(); 77 | os << "$"; 78 | } else { 79 | os << get_parent()->get_this_package()->get_java_long_name(); 80 | os << "."; 81 | } 82 | os << get_name(); 83 | return os; 84 | } else { 85 | return Member::get_java_long_name(); 86 | } 87 | } 88 | 89 | // class Node 90 | // @Override 91 | virtual Class *get_this_class() override {return this;} 92 | 93 | j4a::string get_c_class_name(bool with_prefix = true) { 94 | std::ostringstream os; 95 | if (get_parent()->get_this_class()) { 96 | // inner class 97 | os << get_parent()->get_this_class()->get_c_class_name(); 98 | os << "__"; 99 | } else { 100 | if (with_prefix) { 101 | os << "J4AC_"; 102 | } 103 | os << get_this_package()->get_c_long_name(); 104 | os << "_"; 105 | } 106 | os << get_name(); 107 | return os; 108 | } 109 | 110 | j4a::string get_c_simple_class_name() { 111 | std::ostringstream os; 112 | if (get_parent()->get_this_class()) { 113 | // inner class 114 | os << get_parent()->get_this_class()->get_c_simple_class_name(); 115 | os << "__"; 116 | } else { 117 | os << "J4AC_"; 118 | } 119 | os << get_name(); 120 | return os; 121 | } 122 | 123 | // @Override 124 | virtual void debug_print(int indent) override { 125 | get_annotations()->debug_print(indent); 126 | get_modifier_set()->debug_print(indent); 127 | if (get_is_interface()) { 128 | std::cout << "class "; 129 | } else { 130 | std::cout << "interface "; 131 | } 132 | std::cout << get_name() << " " << std::endl; 133 | get_member_list()->debug_print(indent + 4); 134 | std::cout << j4a::fill(' ', indent) << "};" << std::endl; 135 | } 136 | }; 137 | 138 | NS_AST_END 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /src/ast_compilation_unit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_compilation_unit.hpp" 22 | 23 | #include 24 | #include 25 | #include "ast_method.hpp" 26 | #include "ast_class.hpp" 27 | #include "ast__context.hpp" 28 | 29 | using namespace ast; 30 | 31 | static const char *J4A_LICENSE_HEADER = 32 | "/*\n" 33 | " * Copyright (C) 2015 Zhang Rui \n" 34 | " *\n" 35 | " * Licensed under the Apache License, Version 2.0 (the \"License\");\n" 36 | " * you may not use this file except in compliance with the License.\n" 37 | " * You may obtain a copy of the License at\n" 38 | " *\n" 39 | " * http://www.apache.org/licenses/LICENSE-2.0\n" 40 | " *\n" 41 | " * Unless required by applicable law or agreed to in writing, software\n" 42 | " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" 43 | " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" 44 | " * See the License for the specific language governing permissions and\n" 45 | " * limitations under the License.\n" 46 | " */\n" 47 | "\n" 48 | "/*\n" 49 | " * https://github.com/Bilibili/jni4android\n" 50 | " * This file is automatically generated by jni4android, do not modify.\n" 51 | " */\n"; 52 | 53 | void CompilationUnit::do_build( 54 | std::ostream &h_os, 55 | std::ostream &c_os, 56 | std::ostream &j4a_include_stream, 57 | std::ostream &j4a_loader_stream) 58 | { 59 | Class *clazz = get_clazz(); 60 | 61 | printf("==========\n"); 62 | // printf("%s\n", __func__); 63 | 64 | // .h 65 | h_os << J4A_LICENSE_HEADER << std::endl; 66 | h_os << "#ifndef " << get_header_macro() << std::endl; 67 | h_os << "#define " << get_header_macro() << std::endl; 68 | h_os << std::endl; 69 | h_os << "#include \"j4a/j4a_base.h\"" << std::endl; 70 | h_os << std::endl; 71 | 72 | clazz->build_c_func_decl(h_os); 73 | h_os << std::endl; 74 | if (clazz->need_c_simple_class_name()) { 75 | h_os << "#define J4A_HAVE_SIMPLE__" << clazz->get_c_class_name() << std::endl; 76 | h_os << std::endl; 77 | clazz->build_c_simple_func_decl(h_os); 78 | h_os << std::endl; 79 | } 80 | h_os << "#endif//" << get_header_macro() << std::endl; 81 | 82 | // .c 83 | c_os << J4A_LICENSE_HEADER << std::endl; 84 | c_os << "#include \"" << clazz->get_name() << ".h\"" << std::endl; 85 | 86 | clazz->build_c_class_decl(c_os); 87 | clazz->build_c_func_impl(c_os); 88 | 89 | // .include.j4a 90 | j4a_include_stream << "#include \"" << get_include_path() << "\""; 91 | 92 | // .loader.j4a 93 | j4a_loader_stream << " J4A_LOAD_CLASS(" << clazz->get_c_class_name(false) << ");"; 94 | } 95 | 96 | void CompilationUnit::build() 97 | { 98 | std::ofstream h_stream; 99 | std::ofstream c_stream; 100 | std::ofstream j4a_include_stream; 101 | std::ofstream j4a_loader_stream; 102 | std::ostream *h_stream_ptr = &std::cout; 103 | std::ostream *c_stream_ptr = &std::cout; 104 | std::ostream *j4a_include_stream_ptr = &std::cout; 105 | std::ostream *j4a_loader_stream_ptr = &std::cout; 106 | 107 | if (!Context::instance()->get_h_file_path().empty()) { 108 | h_stream.open(Context::instance()->get_h_file_path().c_str()); 109 | if (!h_stream.is_open()) { 110 | printf("failed to open output .h file %s\n", Context::instance()->get_h_file_path().c_str()); 111 | return; 112 | } 113 | h_stream_ptr = &h_stream; 114 | } 115 | 116 | if (!Context::instance()->get_c_file_path().empty()) { 117 | c_stream.open(Context::instance()->get_c_file_path().c_str()); 118 | if (!c_stream) { 119 | printf("failed to open output .c file %s\n", Context::instance()->get_c_file_path().c_str()); 120 | return; 121 | } 122 | c_stream_ptr = &c_stream; 123 | } 124 | 125 | if (!Context::instance()->get_j4a_include_file_path().empty()) { 126 | j4a_include_stream.open(Context::instance()->get_j4a_include_file_path().c_str()); 127 | if (!j4a_include_stream) { 128 | printf("failed to open output .include.j4a file %s\n", Context::instance()->get_j4a_include_file_path().c_str()); 129 | return; 130 | } 131 | j4a_include_stream_ptr = &j4a_include_stream; 132 | } 133 | 134 | if (!Context::instance()->get_j4a_loader_file_path().empty()) { 135 | j4a_loader_stream.open(Context::instance()->get_j4a_loader_file_path().c_str()); 136 | if (!j4a_loader_stream) { 137 | printf("failed to open output .loader.j4a file %s\n", Context::instance()->get_j4a_loader_file_path().c_str()); 138 | return; 139 | } 140 | j4a_loader_stream_ptr = &j4a_loader_stream; 141 | } 142 | 143 | do_build(*h_stream_ptr, *c_stream_ptr, *j4a_include_stream_ptr, *j4a_loader_stream_ptr); 144 | } 145 | -------------------------------------------------------------------------------- /src/ast_compilation_unit.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_COMPILATION_UNIT__HPP 22 | #define J4A__AST_COMPILATION_UNIT__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast__namespace.hpp" 26 | #include "ast_identifier.hpp" 27 | #include "ast_import.hpp" 28 | #include "ast_class.hpp" 29 | 30 | NS_AST_BEGIN 31 | 32 | class CompilationUnit: public Node 33 | { 34 | public: 35 | AST_IMPLEMENT(CompilationUnit); 36 | AST_CREATE_NONAME__(CompilationUnit, Node); 37 | 38 | AST_PROPERTY_DEFINE(Namespace*, local_namespace) = new Namespace(); 39 | 40 | AST_CHILD_DEFINE(ImportList, import_list); 41 | AST_CHILD_DEFINE(Class, clazz); 42 | AST_CHILD_DEFINE(Identifier, package); 43 | 44 | public: 45 | j4a::string get_header_macro() { 46 | std::ostringstream os; 47 | os << "J4A__"; 48 | os << get_package()->get_c_long_name(); 49 | os << "_"; 50 | os << get_clazz()->get_name(); 51 | os << "__H"; 52 | return os; 53 | } 54 | 55 | j4a::string get_include_path() { 56 | std::ostringstream os; 57 | os << "j4a/class/"; 58 | os << get_package()->get_fs_long_path(); 59 | os << "/"; 60 | os << get_clazz()->get_name(); 61 | os << ".h"; 62 | return os; 63 | } 64 | 65 | void do_build(std::ostream&, std::ostream&, std::ostream&, std::ostream&); 66 | void build(); 67 | 68 | public: 69 | // @Override 70 | virtual CompilationUnit *get_this_compilation_unit() override {return this;} 71 | // output 72 | virtual void debug_print(int indent) override { 73 | get_package()->debug_print(0); 74 | printf(";\n"); 75 | get_import_list()->debug_print(0); 76 | printf("\n"); 77 | get_clazz()->debug_print(0); 78 | printf("\n"); 79 | } 80 | }; 81 | 82 | NS_AST_END 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/ast_constructor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_constructor.hpp" 22 | #include "ast_class.hpp" 23 | 24 | using namespace ast; 25 | 26 | j4a::string Constructor::get_c_jni_sign() 27 | { 28 | std::ostringstream os; 29 | os << "("; 30 | 31 | ArgumentList::iterator begin = get_argument_list()->begin(); 32 | ArgumentList::iterator end = get_argument_list()->end(); 33 | for (NULL; begin != end; ++begin) { 34 | os << (*begin)->get_type()->get_c_sign_in_method(); 35 | } 36 | 37 | os << ")V"; 38 | return os; 39 | } 40 | 41 | j4a::string Constructor::get_c_jni_id_name() 42 | { 43 | std::ostringstream os; 44 | os << "constructor_" << get_name(); 45 | return os; 46 | } 47 | 48 | j4a::string Constructor::get_c_jni_method_name() 49 | { 50 | return ""; 51 | } 52 | 53 | j4a::string Constructor::get_c_call_api() 54 | { 55 | return "NewObject"; 56 | } 57 | 58 | j4a::string Constructor::get_c_call_object_id() 59 | { 60 | return get_this_class()->get_c_jni_id(); 61 | } 62 | 63 | bool Constructor::get_c_call_need_this() 64 | { 65 | return false; 66 | } 67 | -------------------------------------------------------------------------------- /src/ast_constructor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_CONSTRUCTOR__HPP 22 | #define J4A__AST_CONSTRUCTOR__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_method.hpp" 26 | #include "ast_field.hpp" 27 | 28 | NS_AST_BEGIN 29 | 30 | class Constructor: public Method 31 | { 32 | public: 33 | AST_IMPLEMENT(Constructor); 34 | AST_CREATE_NAMED___(Constructor, Method); 35 | 36 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_sign); 37 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_id_name); 38 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_method_name); 39 | 40 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_call_api); 41 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_call_object_id); 42 | AST_GETTER_DECL_OVERRIDE(bool, c_call_need_this); 43 | 44 | public: 45 | virtual void debug_print(int indent) override { 46 | std::cout << j4a::fill(' ', indent); 47 | 48 | get_modifier_set()->debug_print(0); 49 | std::cout << get_name() << "("; 50 | get_argument_list()->debug_print(0); 51 | std::cout << ");" << std::endl; 52 | } 53 | }; 54 | 55 | NS_AST_END 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/ast_field.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_field.hpp" 22 | #include "ast_class.hpp" 23 | #include "ast_property_accessor.hpp" 24 | 25 | using namespace ast; 26 | 27 | //@Override 28 | j4a::string Field::get_c_jni_sign() 29 | { 30 | return get_type()->get_c_sign_in_method(); 31 | } 32 | 33 | //@Override 34 | j4a::string Field::get_c_jni_id_name() 35 | { 36 | std::ostringstream os; 37 | os << "field_" << get_name(); 38 | return os; 39 | } 40 | 41 | //@Override 42 | void Field::build_c_func_decl(std::ostream &os) 43 | { 44 | PropertyGetter::create_for_field(this)->build_c_func_decl(os); 45 | PropertySetter::create_for_field(this)->build_c_func_decl(os); 46 | } 47 | 48 | //@Override 49 | void Field::build_c_simple_func_decl(std::ostream &os) 50 | { 51 | PropertyGetter::create_for_field(this)->build_c_simple_func_decl(os); 52 | PropertySetter::create_for_field(this)->build_c_simple_func_decl(os); 53 | } 54 | 55 | //@Override 56 | void Field::build_c_member_id_decl(std::ostream &os) 57 | { 58 | os << build_indent() << "jfieldID " << get_c_jni_id_name() << ";" << std::endl; 59 | } 60 | 61 | //@Override 62 | void Field::build_c_member_id_load(std::ostream &os) 63 | { 64 | os << std::endl; 65 | os << build_indent() << "class_id = " << get_this_class()->get_c_jni_id() << ";\n"; 66 | os << build_indent() << "name = \"" << get_name() << "\";\n"; 67 | os << build_indent() << "sign = \"" << get_c_jni_sign() << "\";\n"; 68 | os << build_indent() << get_c_jni_id() << " = " << (is_static() ? "J4A_GetStaticFieldID__catchAll" : "J4A_GetFieldID__catchAll") 69 | << "(env, class_id, name, sign);\n"; 70 | os << build_indent() << "if (" << get_c_jni_id() << " == NULL)\n"; 71 | os << build_indent() << " goto fail;\n"; 72 | } 73 | 74 | //@Override 75 | void Field::build_c_func_impl(std::ostream &os) 76 | { 77 | PropertyGetter::create_for_field(this)->build_c_func_impl(os); 78 | PropertySetter::create_for_field(this)->build_c_func_impl(os); 79 | } 80 | -------------------------------------------------------------------------------- /src/ast_field.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_FIELD__HPP 22 | #define J4A__AST_FIELD__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_member.hpp" 26 | 27 | NS_AST_BEGIN 28 | 29 | class Field: public Member 30 | { 31 | public: 32 | AST_IMPLEMENT(Field); 33 | AST_CREATE_NAMED___(Field, Member); 34 | 35 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_sign); 36 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_id_name); 37 | 38 | public: 39 | // class Member 40 | virtual void build_c_func_decl(std::ostream &os) override; 41 | virtual void build_c_simple_func_decl(std::ostream &os) override; 42 | // virtual void build_c_class_decl(std::ostream &os) override {;} 43 | virtual void build_c_member_id_decl(std::ostream &os) override; 44 | virtual void build_c_member_id_load(std::ostream &os) override; 45 | virtual void build_c_func_impl(std::ostream &os) override; 46 | 47 | // class Node 48 | // @Override 49 | virtual void debug_print(int indent) override { 50 | std::cout << j4a::fill(' ', indent); 51 | 52 | get_modifier_set()->debug_print(0); 53 | get_type()->debug_print(0); 54 | std::cout << " " << get_name() << ";" << std::endl; 55 | } 56 | }; 57 | 58 | NS_AST_END 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/ast_identifier.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_identifier.hpp" 22 | #include "ast__context.hpp" 23 | #include 24 | 25 | using namespace ast; 26 | 27 | Identifier* Identifier::create(const j4a::string& name) 28 | { 29 | Identifier* identifier = new Identifier(name); 30 | identifier->put_in_pool(); 31 | return identifier; 32 | } 33 | 34 | Identifier* Identifier::create_with_prefix(const j4a::string& name, Identifier *parent) 35 | { 36 | Identifier* identifier = create(name); 37 | identifier->set_prefix(parent); 38 | return identifier; 39 | } 40 | 41 | Identifier* Identifier::create_by_split(const char *long_name, char separator) 42 | { 43 | Identifier* identifier = NULL; 44 | 45 | const char *lookup = long_name; 46 | const char *next = strchr(lookup, separator); 47 | while (next && next > lookup) { 48 | j4a::string child_id = j4a::string(lookup, next - lookup); 49 | 50 | identifier = create_with_prefix(child_id, identifier); 51 | 52 | lookup = next + 1; 53 | next = strchr(lookup, separator); 54 | } 55 | 56 | if (*lookup) { 57 | identifier = create_with_prefix(lookup, identifier); 58 | } 59 | 60 | return identifier; 61 | } 62 | 63 | 64 | Identifier::pointer_type Identifier::get_outer_class_identifier() 65 | { 66 | Identifier::pointer_type prefix = get_prefix(); 67 | if (!prefix) 68 | return NULL; 69 | 70 | if (prefix->is_class_identifier()) 71 | return prefix; 72 | 73 | return prefix->get_outer_class_identifier(); 74 | } 75 | 76 | j4a::string Identifier::get_java_long_name() 77 | { 78 | std::ostringstream os; 79 | 80 | Identifier::pointer_type prefix = get_prefix(); 81 | if (prefix) { 82 | os << prefix->get_java_long_name(); 83 | os << "."; 84 | } 85 | 86 | os << get_name(); 87 | return j4a::string(os); 88 | } 89 | 90 | j4a::string Identifier::get_c_long_name() 91 | { 92 | std::ostringstream os; 93 | 94 | Identifier::pointer_type prefix = get_prefix(); 95 | if (prefix) { 96 | os << prefix->get_c_long_name(); 97 | os << "_"; 98 | } 99 | 100 | os << get_name(); 101 | return j4a::string(os); 102 | } 103 | 104 | j4a::string Identifier::get_c_jni_sign() 105 | { 106 | std::ostringstream os; 107 | 108 | Identifier::pointer_type prefix = get_prefix(); 109 | if (prefix) { 110 | os << prefix->get_c_jni_sign(); 111 | os << "/"; 112 | } 113 | 114 | os << get_name(); 115 | return os.str(); 116 | } 117 | 118 | j4a::string Identifier::get_fs_long_path() 119 | { 120 | std::ostringstream os; 121 | 122 | Identifier::pointer_type prefix = get_prefix(); 123 | if (prefix) { 124 | os << prefix->get_fs_long_path(); 125 | os << "/"; 126 | } 127 | 128 | os << get_name(); 129 | return os.str(); 130 | } 131 | 132 | 133 | 134 | j4a::string ClassIdentifier::get_c_jni_sign() 135 | { 136 | std::ostringstream os; 137 | 138 | Identifier::pointer_type prefix = get_prefix(); 139 | if (prefix) { 140 | os << prefix->get_c_jni_sign(); 141 | if (get_outer_class_identifier()) 142 | os << "$"; 143 | else 144 | os << "/"; 145 | } 146 | 147 | os << get_name(); 148 | return os.str(); 149 | } 150 | -------------------------------------------------------------------------------- /src/ast_identifier.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_QUALIFIED_IDNETIFIER__HPP 22 | #define J4A__AST_QUALIFIED_IDNETIFIER__HPP 23 | 24 | #include "ast_node.hpp" 25 | 26 | NS_AST_BEGIN 27 | 28 | class Identifier: public Node 29 | { 30 | public: 31 | AST_IMPLEMENT(Identifier); 32 | 33 | AST_PROPERTY_DEFINE(pointer_type, prefix); 34 | AST_GETTER_DEFINE(j4a::string, name); 35 | 36 | AST_GETTER_DECL(pointer_type, outer_class_identifier); 37 | AST_GETTER_DECL(j4a::string, java_long_name); 38 | AST_GETTER_DECL(j4a::string, c_long_name); 39 | AST_GETTER_DECL(j4a::string, c_jni_sign); 40 | AST_GETTER_DECL(j4a::string, fs_long_path); 41 | 42 | virtual bool is_class_identifier() {return false;} 43 | 44 | public: 45 | virtual void debug_print(int indent) override { 46 | if (get_prefix()) { 47 | get_prefix()->debug_print(indent); 48 | std::cout << "." << std::endl; 49 | } 50 | std::cout << get_name(); 51 | } 52 | 53 | protected: 54 | explicit Identifier(const j4a::string &name): AST_PROPERTY(name)(name) {init(NULL);} 55 | explicit Identifier(Node *other): Node(other) {init(other);} 56 | private: 57 | void init(Node *other) { 58 | if (other) { 59 | Identifier *other_ = dynamic_cast(other); 60 | if (other_) { 61 | AST_PROPERTY(name) = other_->get_name(); 62 | set_prefix(other_->get_prefix()); 63 | } 64 | } 65 | } 66 | public: 67 | static Identifier* create(const j4a::string& name); 68 | static Identifier* create_with_prefix(const j4a::string& name, Identifier *prefix); 69 | static Identifier* create_by_split(const char *long_name, char separator = '.'); 70 | }; 71 | 72 | 73 | 74 | template 75 | class IdentifierMap: public Node 76 | { 77 | public: 78 | typedef j4a::string key_type; 79 | typedef T element_type; 80 | typedef typename element_type::pointer_type element_pointer_type; 81 | typedef typename std::map container; 82 | typedef typename container::iterator iterator; 83 | 84 | iterator begin() {return m_node_map.begin();} 85 | iterator end() {return m_node_map.end();} 86 | 87 | void insert(element_type *node) {_insert(node);} 88 | void insert(element_pointer_type node) {_insert(node.get());} 89 | 90 | // void assign(NamedNodeMap *node_map) {m_node_map = node_map->m_node_map;} 91 | size_t size() {return m_node_map.size();} 92 | 93 | element_pointer_type get_at(const char *name) {return _get_at(name);} 94 | element_pointer_type get_at(const j4a::string &name) {return _get_at(name);} 95 | 96 | private: 97 | container m_node_map; 98 | 99 | private: 100 | element_pointer_type _get_at(const key_type &name) { 101 | iterator find = m_node_map.find(name); 102 | if (find == m_node_map.end()) 103 | return element_pointer_type(NULL); 104 | return find->second; 105 | } 106 | 107 | void _insert(T *node) { 108 | key_type name = node->get_name(); 109 | 110 | iterator find = m_node_map.find(name); 111 | assert(find == m_node_map.end()); 112 | if (find != m_node_map.end()) { 113 | if (find->second) 114 | find->second->set_parent(NULL); 115 | find->second = node; 116 | } else { 117 | m_node_map.insert(std::make_pair(name, node)); 118 | } 119 | 120 | node->set_parent(this); 121 | } 122 | 123 | public: 124 | AST_IMPLEMENT_ABSTRACT(IdentifierMap); 125 | protected: 126 | explicit IdentifierMap() {;} 127 | explicit IdentifierMap(IdentifierMap *other): Node(other) { 128 | iterator begin = this->begin(); 129 | iterator end = this->end(); 130 | 131 | for (NULL; begin != end; ++begin) { 132 | insert(begin->second); 133 | } 134 | } 135 | public: 136 | // static pointer_type make_ptr() {return pointer_type(new class__());} 137 | }; 138 | 139 | 140 | 141 | class ClassIdentifier: public Identifier 142 | { 143 | public: 144 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_sign); 145 | 146 | virtual bool is_class_identifier() override {return true;} 147 | 148 | public: 149 | AST_IMPLEMENT(ClassIdentifier); 150 | protected: 151 | explicit ClassIdentifier(const j4a::string &name): Identifier(name) {init(NULL);} 152 | explicit ClassIdentifier(Node *other): Identifier(other) {init(other);} 153 | private: 154 | void init(Node *other) {;} 155 | public: 156 | static pointer_type make_ptr(const j4a::string &name) {return pointer_type(new ClassIdentifier(name));} 157 | static pointer_type make_ptr(Node *other) {return pointer_type(new ClassIdentifier(other));} 158 | }; 159 | 160 | NS_AST_END 161 | 162 | #endif 163 | -------------------------------------------------------------------------------- /src/ast_import.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_IMPORT__HPP 22 | #define J4A__AST_IMPORT__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_node.hpp" 26 | #include "ast_identifier.hpp" 27 | 28 | NS_AST_BEGIN 29 | 30 | class ImportList: public NodeList 31 | { 32 | public: 33 | AST_IMPLEMENT(ImportList); 34 | AST_CREATE_NONAME__(ImportList, NodeList); 35 | 36 | public: 37 | // @Override 38 | virtual void debug_print(int indent) override { 39 | if (size() > 0) { 40 | printf("\n"); 41 | 42 | iterator begin = this->begin(); 43 | iterator end = this->end(); 44 | 45 | for (NULL; begin != end; ++begin) { 46 | printf("import "); 47 | (*begin)->debug_print(indent); 48 | printf(";\n"); 49 | } 50 | } 51 | } 52 | }; 53 | 54 | NS_AST_END 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/ast_member.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_member.hpp" 22 | #include "ast_class.hpp" 23 | 24 | using namespace ast; 25 | 26 | j4a::string Member::get_c_jni_id() 27 | { 28 | std::ostringstream os; 29 | os << get_this_class()->get_c_jni_class_instance(); 30 | os << "." << get_c_jni_id_name(); 31 | return os; 32 | } 33 | 34 | void MemberList::build_all_c_class_decl(std::ostream &os) 35 | { 36 | MemberList::iterator begin = this->begin(); 37 | MemberList::iterator end = this->end(); 38 | 39 | for (NULL; begin != end; ++begin) { 40 | (*begin)->reset_build_format(); 41 | 42 | (*begin)->build_c_class_decl(os); 43 | 44 | (*begin)->reset_build_format(); 45 | } 46 | } 47 | 48 | void MemberList::build_all_c_func_decl(std::ostream &os) 49 | { 50 | if (this->size() > 0) { 51 | MemberList::iterator begin = this->begin(); 52 | MemberList::iterator end = this->end(); 53 | 54 | for (NULL; begin != end; ++begin) { 55 | (*begin)->reset_build_format(); 56 | 57 | (*begin)->build_c_func_decl(os); 58 | 59 | (*begin)->reset_build_format(); 60 | } 61 | } 62 | } 63 | 64 | void MemberList::build_all_c_simple_func_decl(std::ostream &os) 65 | { 66 | if (this->size() > 0) { 67 | MemberList::iterator begin = this->begin(); 68 | MemberList::iterator end = this->end(); 69 | 70 | for (NULL; begin != end; ++begin) { 71 | (*begin)->reset_build_format(); 72 | 73 | (*begin)->build_c_simple_func_decl(os); 74 | 75 | (*begin)->reset_build_format(); 76 | } 77 | } 78 | } 79 | 80 | void MemberList::build_all_c_member_id_decl(std::ostream &os) 81 | { 82 | if (this->size() > 0) { 83 | MemberList::iterator begin = this->begin(); 84 | MemberList::iterator end = this->end(); 85 | 86 | os << std::endl; 87 | for (NULL; begin != end; ++begin) { 88 | (*begin)->reset_build_format(); 89 | (*begin)->set_build_indent(get_this_class()->get_build_indent() + 4); 90 | 91 | (*begin)->build_c_member_id_decl(os); 92 | 93 | (*begin)->reset_build_format(); 94 | } 95 | } 96 | } 97 | 98 | void MemberList::build_all_c_member_id_load(std::ostream &os) 99 | { 100 | if (this->size() > 0) { 101 | MemberList::iterator begin = this->begin(); 102 | MemberList::iterator end = this->end(); 103 | 104 | for (NULL; begin != end; ++begin) { 105 | (*begin)->reset_build_format(); 106 | (*begin)->set_build_indent(get_this_class()->get_build_indent() + 4); 107 | 108 | (*begin)->build_c_member_id_load(os); 109 | 110 | (*begin)->reset_build_format(); 111 | } 112 | } 113 | } 114 | 115 | void MemberList::build_all_c_func_impl(std::ostream &os) 116 | { 117 | if (this->size() > 0) { 118 | MemberList::iterator begin = this->begin(); 119 | MemberList::iterator end = this->end(); 120 | 121 | for (NULL; begin != end; ++begin) { 122 | (*begin)->reset_build_format(); 123 | 124 | (*begin)->build_c_func_impl(os); 125 | 126 | (*begin)->reset_build_format(); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/ast_member.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_MEMBER__HPP 22 | #define J4A__AST_MEMBER__HPP 23 | 24 | #include 25 | #include 26 | #include "ast__def.hpp" 27 | #include "ast_node.hpp" 28 | #include "ast_identifier.hpp" 29 | #include "ast_annotation.hpp" 30 | #include "ast_modifier.hpp" 31 | #include "ast_type.hpp" 32 | 33 | NS_AST_BEGIN 34 | 35 | class Member: public Identifier 36 | { 37 | public: 38 | AST_IMPLEMENT_ABSTRACT(Member); 39 | AST_CREATE_NAMED____ABSTRACT(Member, Identifier); 40 | AST_CREATE_POINTER__ABSTRACT(Member, Identifier, Identifier); 41 | 42 | AST_CHILD_DEFINE(Annotations, annotations); 43 | AST_CHILD_DEFINE(ModifierSet, modifier_set); 44 | AST_CHILD_DEFINE(Type, type); 45 | 46 | AST_GETTER_DECL_0(j4a::string, c_jni_sign); 47 | AST_GETTER_DECL_0(j4a::string, c_jni_id_name); 48 | AST_GETTER_DECL(j4a::string, c_jni_id); 49 | AST_PROPERTY_DEFINE(int, build_indent) = 0; 50 | 51 | public: 52 | Annotation *get_annotation_at(const char *name) { 53 | return get_annotations()->get_at(name).get(); 54 | } 55 | 56 | bool is_public() {return get_modifier_set()->has_token(T_PUBLIC);} 57 | bool is_private() {return get_modifier_set()->has_token(T_PRIVATE);} 58 | bool is_protected() {return get_modifier_set()->has_token(T_PROTECTED);} 59 | bool is_static() {return get_modifier_set()->has_token(T_STATIC);} 60 | bool is_final() {return get_modifier_set()->has_token(T_FINAL);} 61 | 62 | void reset_build_format() { 63 | set_build_indent(0); 64 | } 65 | 66 | void increase_build_indent(int increase) { 67 | set_build_indent(get_build_indent() + increase); 68 | } 69 | 70 | j4a::fill build_indent() {return j4a::fill(' ', get_build_indent());} 71 | 72 | public: 73 | // .h files 74 | virtual void build_c_func_decl(std::ostream &os) {;} 75 | virtual void build_c_simple_func_decl(std::ostream &os) {;} 76 | 77 | // .c files 78 | virtual void build_c_class_decl(std::ostream &os) {;} 79 | virtual void build_c_member_id_decl(std::ostream &os) {;} 80 | virtual void build_c_member_id_load(std::ostream &os) {;} 81 | virtual void build_c_func_impl(std::ostream &os) {;} 82 | }; 83 | 84 | 85 | class MemberList: public NodeList 86 | { 87 | public: 88 | AST_IMPLEMENT(MemberList); 89 | AST_CREATE_NONAME__(MemberList, NodeList); 90 | 91 | // class Node 92 | virtual void debug_print(int indent) override { 93 | iterator begin = this->begin(); 94 | iterator end = this->end(); 95 | 96 | for (NULL; begin != end; ++begin) { 97 | (*begin)->debug_print(indent); 98 | } 99 | } 100 | 101 | // .h files 102 | void build_all_c_func_decl(std::ostream &os); 103 | void build_all_c_simple_func_decl(std::ostream &os); 104 | 105 | // .c files 106 | void build_all_c_class_decl(std::ostream &os); 107 | void build_all_c_member_id_decl(std::ostream &os); 108 | void build_all_c_member_id_load(std::ostream &os); 109 | void build_all_c_func_impl(std::ostream &os); 110 | }; 111 | 112 | NS_AST_END 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /src/ast_method.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_METHOD__HPP 22 | #define J4A__AST_METHOD__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_member.hpp" 26 | #include "ast_argument.hpp" 27 | 28 | NS_AST_BEGIN 29 | 30 | class Method: public Member 31 | { 32 | public: 33 | AST_IMPLEMENT(Method); 34 | AST_CREATE_NAMED___(Method, Member); 35 | 36 | AST_CHILD_DEFINE(ArgumentList, argument_list); 37 | 38 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_sign); 39 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_jni_id_name); 40 | AST_GETTER_DECL(j4a::string, c_jni_method_name); 41 | 42 | AST_GETTER_DECL(j4a::string, c_call_api); 43 | AST_GETTER_DECL(j4a::string, c_call_object_id); 44 | AST_GETTER_DECL(j4a::string, c_call_method_id); 45 | AST_GETTER_DECL(bool, c_call_need_this); 46 | 47 | private: 48 | static const int FLAG_NORMAL; 49 | static const int FLAG_CATCH_ALL; 50 | static const int FLAG_WITH_C_STRING; 51 | static const int FLAG_AS_GLOBAL_REF; 52 | static const int FLAG_AS_C_BUFFER; 53 | static const int FLAG_SIMPLE_NAME; 54 | 55 | bool _has_string_arg(); 56 | 57 | void _build_class_id(std::ostream &os); 58 | void _build_c_call_jni_statement(std::ostream &os, int flags); 59 | void _build_c_func_name(std::ostream &os, int flags); 60 | void _build_c_func_decl_statement(std::ostream &os, int flags); 61 | void _build_c_func_call_statement(std::ostream &os, int flags); 62 | void _build_c_func_string_argument_cast_statements(std::ostream &os, int flags); 63 | void _build_c_func_string_argument_release_statements(std::ostream &os, int flags); 64 | void _build_c_func_impl_void_type_statement(std::ostream &os, int flags); 65 | void _build_c_func_impl_reference_type_statement(std::ostream &os, int flags); 66 | void _build_c_func_impl_primitive_type_statement(std::ostream &os, int flags); 67 | 68 | public: 69 | virtual void build_c_func_decl(std::ostream &os) override; 70 | virtual void build_c_simple_func_decl(std::ostream &os) override; 71 | // virtual void build_c_class_decl(std::ostream &os); 72 | virtual void build_c_member_id_decl(std::ostream &os) override; 73 | virtual void build_c_member_id_load(std::ostream &os) override; 74 | virtual void build_c_func_impl(std::ostream &os) override; 75 | 76 | // class Node 77 | // @Override 78 | virtual Method *get_this_method() override {return this;} 79 | // @Override 80 | virtual void debug_print(int indent) override { 81 | std::cout << j4a::fill(' ', indent); 82 | 83 | get_modifier_set()->debug_print(0); 84 | get_type()->debug_print(0); 85 | std::cout << " " << get_name() << "("; 86 | get_argument_list()->debug_print(0); 87 | std::cout << ");" << std::endl; 88 | } 89 | 90 | private: 91 | typedef std::map SimpleNameMap; 92 | std::map m_simple_name_map; 93 | }; 94 | 95 | NS_AST_END 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /src/ast_modifier.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_MODIFIER__HPP 22 | #define J4A__AST_MODIFIER__HPP 23 | 24 | #include 25 | #include "ast__def.hpp" 26 | #include "ast_node.hpp" 27 | 28 | NS_AST_BEGIN 29 | 30 | class ModifierSet: public Node 31 | { 32 | public: 33 | AST_IMPLEMENT(ModifierSet); 34 | AST_CREATE_NONAME__(ModifierSet, Node); 35 | 36 | public: 37 | typedef std::set::iterator iterator; 38 | 39 | iterator begin() {return m_modifier_set.begin();} 40 | iterator end() {return m_modifier_set.end();} 41 | 42 | size_t size() {return m_modifier_set.size();} 43 | bool has_token(int token) {return m_modifier_set.find(token) != end();} 44 | void insert_token(int token) { 45 | switch (token) { 46 | case T_PUBLIC: 47 | case T_PRIVATE: 48 | case T_PROTECTED: 49 | if (has_token(T_PUBLIC) || has_token(T_PRIVATE) || has_token(T_PROTECTED)) { 50 | printf("[Error]: multiple public/private/protected modifier!\n"); 51 | } 52 | break; 53 | } 54 | m_modifier_set.insert(token); 55 | } 56 | 57 | bool is_public() {return has_token(T_PUBLIC);} 58 | bool is_private() {return has_token(T_PRIVATE);} 59 | bool is_protected() {return has_token(T_PROTECTED);} 60 | bool is_static() {return has_token(T_STATIC);} 61 | bool is_final() {return has_token(T_FINAL);} 62 | 63 | public: 64 | std::set m_modifier_set; 65 | 66 | public: 67 | // @Override 68 | virtual void debug_print(int indent) override { 69 | std::cout << j4a::fill(' ', indent); 70 | 71 | if (is_public()) 72 | std::cout << "public "; 73 | else if (is_protected()) 74 | std::cout << "protected "; 75 | else if (is_private()) 76 | std::cout << "private "; 77 | 78 | if (is_static()) 79 | std::cout << "static "; 80 | if (is_final()) 81 | std::cout << "final "; 82 | } 83 | }; 84 | 85 | NS_AST_END 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/ast_node.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_node.hpp" 22 | #include "ast_compilation_unit.hpp" 23 | #include "ast__context.hpp" 24 | 25 | using namespace ast; 26 | 27 | void Node::init(Node *other) 28 | { 29 | if (other) { 30 | set_parent(other->get_parent()); 31 | } else { 32 | set_parent(NULL); 33 | } 34 | } 35 | 36 | void Node::put_in_pool() 37 | { 38 | Context::instance()->put(this); 39 | } 40 | 41 | Method *Node::get_this_method() 42 | { 43 | if (!get_parent()) 44 | return NULL; 45 | 46 | return get_parent()->get_this_method(); 47 | } 48 | 49 | CompilationUnit *Node::get_this_compilation_unit() 50 | { 51 | if (!get_parent()) 52 | return NULL; 53 | 54 | return get_parent()->get_this_compilation_unit(); 55 | } 56 | 57 | Class *Node::get_this_class() 58 | { 59 | if (!get_parent()) 60 | return NULL; 61 | 62 | return get_parent()->get_this_class(); 63 | } 64 | 65 | Identifier *Node::get_this_package() 66 | { 67 | if (!get_this_compilation_unit()) 68 | return NULL; 69 | 70 | return get_this_compilation_unit()->get_package(); 71 | } 72 | -------------------------------------------------------------------------------- /src/ast_node.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_NODE__HPP 22 | #define J4A__AST_NODE__HPP 23 | 24 | #include 25 | #include 26 | #include "ast__def.hpp" 27 | 28 | NS_AST_BEGIN 29 | 30 | class File; 31 | class Class; 32 | class Method; 33 | 34 | class IContext 35 | { 36 | public: 37 | }; 38 | 39 | class Node: public j4a::object 40 | { 41 | public: 42 | AST_IMPLEMENT(Node); 43 | 44 | AST_PROPERTY_DEFINE(Node*, parent); 45 | AST_GETTER_DECL(Class*, this_class); 46 | AST_GETTER_DECL(CompilationUnit*, this_compilation_unit); 47 | AST_GETTER_DECL(Method*, this_method); 48 | AST_GETTER_DECL(Identifier*, this_package); 49 | 50 | public: 51 | // output 52 | virtual void debug_print(int indent) {;} 53 | protected: 54 | void put_in_pool(); 55 | 56 | protected: 57 | explicit Node() {init(NULL);} 58 | explicit Node(Node *other) {init(other);} 59 | private: 60 | void init(Node *other); 61 | }; 62 | 63 | 64 | 65 | template 66 | class NodeList: public Node 67 | { 68 | public: 69 | typedef T element_type; 70 | typedef typename T::pointer_type element_pointer_type; 71 | typedef typename std::list container; 72 | typedef typename container::iterator iterator; 73 | 74 | iterator begin() {return m_node_list.begin();} 75 | iterator end() {return m_node_list.end();} 76 | 77 | element_pointer_type back() {return m_node_list.back();} 78 | 79 | void push_back(element_type *node) {m_node_list.push_back(node); node->set_parent(this);} 80 | void push_back(element_pointer_type node) {m_node_list.push_back(node.get()); node->set_parent(this);} 81 | 82 | // FIXME: deep copy 83 | void assign(NodeList *node_list) {m_node_list = node_list->m_node_list;} 84 | size_t size() {return m_node_list.size();} 85 | bool empty() {return m_node_list.empty();} 86 | 87 | private: 88 | container m_node_list; 89 | 90 | public: 91 | AST_IMPLEMENT_ABSTRACT(NodeList); 92 | protected: 93 | explicit NodeList() {;} 94 | explicit NodeList(NodeList *other): Node(other) { 95 | iterator begin = this->begin(); 96 | iterator end = this->end(); 97 | 98 | for (NULL; begin != end; ++begin) { 99 | element_pointer_type node = *begin; 100 | if (!node.is_null()) 101 | continue; 102 | 103 | push_back((T*)node.get()); 104 | } 105 | } 106 | public: 107 | // static pointer_type make_ptr() {return pointer_type(new class__());} 108 | }; 109 | 110 | NS_AST_END 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /src/ast_primitive_type.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_PRIMITIVE_TYPE__HPP 22 | #define J4A__AST_PRIMITIVE_TYPE__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_type.hpp" 26 | 27 | NS_AST_BEGIN 28 | 29 | class PrimitiveType: public Type 30 | { 31 | public: 32 | AST_IMPLEMENT_ABSTRACT(PrimitiveType); 33 | protected: 34 | explicit PrimitiveType(const j4a::string& name, int token): Type(name), m_token(token) {;} 35 | 36 | public: 37 | // @Override 38 | virtual bool is_reference_type() override {return get_is_array();} 39 | virtual bool is_void_type() override {return m_token == T_VOID;} 40 | virtual bool is_string_type() override {return false;} 41 | 42 | private: 43 | const int m_token; 44 | }; 45 | 46 | #define AST_DEFINE__PrimitiveType(class__, token_id__, name__, ctype__, c_sign__, c_name_in_call_api, default__) \ 47 | class class__: public PrimitiveType \ 48 | { \ 49 | public: \ 50 | AST_IMPLEMENT(class__); \ 51 | private: \ 52 | explicit class__(): PrimitiveType(name__, token_id__) {;} \ 53 | public: \ 54 | static class__ *create() \ 55 | { \ 56 | pointer_type instance = new class__(); \ 57 | instance->put_in_pool(); \ 58 | return instance; \ 59 | } \ 60 | public: \ 61 | virtual j4a::string get_c_type() override { \ 62 | if (get_is_array()) \ 63 | return ctype__ "Array"; \ 64 | else \ 65 | return ctype__; \ 66 | } \ 67 | virtual j4a::string get_c_sign_in_method() override { \ 68 | if (get_is_array()) { \ 69 | std::ostringstream os; \ 70 | os << "[" << c_sign__; \ 71 | return os; \ 72 | } else \ 73 | return c_sign__; \ 74 | } \ 75 | virtual j4a::string get_c_default_value() override { \ 76 | if (get_is_array()) { \ 77 | return "NULL"; \ 78 | } else \ 79 | return default__; \ 80 | } \ 81 | virtual j4a::string get_c_call_instance_method_api() override { \ 82 | std::ostringstream os; \ 83 | os << "Call" << (get_is_array() ? "Object" : c_name_in_call_api) << "Method"; \ 84 | return os; \ 85 | } \ 86 | virtual j4a::string get_c_call_static_method_api() override { \ 87 | std::ostringstream os; \ 88 | os << "CallStatic" << (get_is_array() ? "Object" : c_name_in_call_api) << "Method"; \ 89 | return os; \ 90 | } \ 91 | virtual j4a::string get_c_get_instance_field_api() override { \ 92 | std::ostringstream os; \ 93 | os << "Get" << (get_is_array() ? "Object" : c_name_in_call_api) << "Field"; \ 94 | return os; \ 95 | } \ 96 | virtual j4a::string get_c_get_static_field_api() override { \ 97 | std::ostringstream os; \ 98 | os << "GetStatic" << (get_is_array() ? "Object" : c_name_in_call_api) << "Field"; \ 99 | return os; \ 100 | } \ 101 | virtual j4a::string get_c_set_instance_field_api() override { \ 102 | std::ostringstream os; \ 103 | os << "Set" << (get_is_array() ? "Object" : c_name_in_call_api) << "Field"; \ 104 | return os; \ 105 | } \ 106 | virtual j4a::string get_c_set_static_field_api() override { \ 107 | std::ostringstream os; \ 108 | os << "SetStatic" << (get_is_array() ? "Object" : c_name_in_call_api) << "Field"; \ 109 | return os; \ 110 | } \ 111 | }; 112 | 113 | AST_DEFINE__PrimitiveType(BooleanType, T_BOOLEAN, "boolean", "jboolean", "Z", "Boolean", "false"); 114 | AST_DEFINE__PrimitiveType(ByteType, T_BYTE, "byte", "jbyte", "B", "Byte", "0"); 115 | AST_DEFINE__PrimitiveType(FloatType, T_FLOAT, "float", "jfloat", "F", "Float", "0"); 116 | AST_DEFINE__PrimitiveType(DoubleType, T_DOUBLE, "double", "jdouble", "D", "Double", "0"); 117 | AST_DEFINE__PrimitiveType(CharType, T_CHAR, "char", "jchar", "C", "Char", "0"); 118 | AST_DEFINE__PrimitiveType(ShortType, T_SHORT, "short", "jshort", "S", "Short", "0"); 119 | AST_DEFINE__PrimitiveType(IntType, T_INT, "int", "jint", "I", "Int", "0"); 120 | AST_DEFINE__PrimitiveType(LongType, T_LONG, "long", "jlong", "J", "Long", "0"); 121 | AST_DEFINE__PrimitiveType(VoidType, T_VOID, "void", "void", "V", "Void", ""); 122 | 123 | NS_AST_END 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /src/ast_property_accessor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_property_accessor.hpp" 22 | #include "ast_class.hpp" 23 | 24 | using namespace ast; 25 | 26 | j4a::string PropertyGetter::get_c_call_api() 27 | { 28 | if (is_static()) { 29 | return get_field()->get_type()->get_c_get_static_field_api(); 30 | } else { 31 | return get_field()->get_type()->get_c_get_instance_field_api(); 32 | } 33 | } 34 | 35 | j4a::string PropertyGetter::get_c_call_method_id() 36 | { 37 | std::ostringstream os; 38 | os << get_this_class()->get_c_jni_class_instance() << "." << get_field()->get_c_jni_id_name(); 39 | return os; 40 | } 41 | 42 | 43 | 44 | j4a::string PropertySetter::get_c_call_api() 45 | { 46 | if (is_static()) { 47 | return get_field()->get_type()->get_c_set_static_field_api(); 48 | } else { 49 | return get_field()->get_type()->get_c_set_instance_field_api(); 50 | } 51 | } 52 | 53 | j4a::string PropertySetter::get_c_call_method_id() 54 | { 55 | std::ostringstream os; 56 | os << get_this_class()->get_c_jni_class_instance() << "." << get_field()->get_c_jni_id_name(); 57 | return os; 58 | } 59 | -------------------------------------------------------------------------------- /src/ast_property_accessor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_PROPERTY_ACCESSOR__HPP 22 | #define J4A__AST_PROPERTY_ACCESSOR__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_method.hpp" 26 | #include "ast_field.hpp" 27 | #include "ast_primitive_type.hpp" 28 | 29 | NS_AST_BEGIN 30 | 31 | class PropertyAccessor: public Method 32 | { 33 | public: 34 | AST_IMPLEMENT_ABSTRACT(PropertyAccessor); 35 | AST_CREATE_NAMED____ABSTRACT(PropertyAccessor, Method) 36 | 37 | AST_PROPERTY_DEFINE(Field*, field); 38 | 39 | public: 40 | void setup_for_field(Field* field) 41 | { 42 | set_field(field); 43 | 44 | set_annotations(field->get_annotations()); 45 | set_modifier_set(field->get_modifier_set()); 46 | set_parent(field->get_parent()); 47 | } 48 | }; 49 | 50 | 51 | 52 | 53 | class PropertyGetter: public PropertyAccessor 54 | { 55 | public: 56 | AST_IMPLEMENT(PropertyGetter); 57 | AST_CREATE_NAMED___(PropertyGetter, PropertyAccessor) 58 | 59 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_call_api); 60 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_call_method_id); 61 | 62 | public: 63 | static PropertyGetter *create_for_field(Field *field) 64 | { 65 | PropertyGetter *getter = create(field->get_name() + "__get"); 66 | getter->setup_for_field(field); 67 | 68 | getter->set_type(field->get_type()); 69 | getter->set_argument_list(ArgumentList::create()); 70 | return getter; 71 | } 72 | }; 73 | 74 | 75 | 76 | class PropertySetter: public PropertyAccessor 77 | { 78 | public: 79 | AST_IMPLEMENT(PropertySetter); 80 | AST_CREATE_NAMED___(PropertySetter, PropertyAccessor) 81 | 82 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_call_api); 83 | AST_GETTER_DECL_OVERRIDE(j4a::string, c_call_method_id); 84 | 85 | public: 86 | static PropertySetter *create_for_field(Field *field) 87 | { 88 | PropertySetter *setter = create(field->get_name() + "__set"); 89 | setter->setup_for_field(field); 90 | 91 | setter->set_type(VoidType::create()); 92 | 93 | Argument::pointer_type argument = Argument::create("value"); 94 | argument->set_type(field->get_type()); 95 | 96 | ArgumentList::pointer_type argument_list = ArgumentList::create(); 97 | argument_list->push_back(argument); 98 | 99 | setter->set_argument_list(argument_list); 100 | 101 | return setter; 102 | } 103 | }; 104 | 105 | NS_AST_END 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /src/ast_reference_type.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "ast_reference_type.hpp" 22 | #include "ast_identifier.hpp" 23 | #include "ast_class.hpp" 24 | #include "ast__context.hpp" 25 | 26 | using namespace ast; 27 | 28 | bool ReferenceType::is_string_type() 29 | { 30 | if (0 == get_name().compare("String")) { 31 | if (0 == _get_java_long_name().compare("java.lang.String")) { 32 | return true; 33 | } 34 | } 35 | 36 | return false; 37 | } 38 | 39 | j4a::string ReferenceType::_get_java_long_name() 40 | { 41 | Identifier *Identifier = Context::instance()->find_identifier(this, get_name()); 42 | if (Identifier) { 43 | if (get_is_array()) { 44 | return Identifier->get_java_long_name() + "[]"; 45 | } else { 46 | return Identifier->get_java_long_name(); 47 | } 48 | } 49 | 50 | return ""; 51 | } 52 | 53 | j4a::string ReferenceType::get_c_type() 54 | { 55 | if (get_is_array()) 56 | return "jobjectArray"; 57 | 58 | if (is_string_type()) 59 | return "jstring"; 60 | 61 | return "jobject"; 62 | } 63 | 64 | j4a::string ReferenceType::get_c_sign_in_method() 65 | { 66 | Identifier::pointer_type Identifier = Context::instance()->find_identifier(this, get_name()); 67 | if (Identifier) { 68 | std::ostringstream os; 69 | if (get_is_array()) 70 | os << "["; 71 | os << "L" << Identifier->get_c_jni_sign() << ";"; 72 | return os; 73 | } 74 | 75 | return ""; 76 | } 77 | -------------------------------------------------------------------------------- /src/ast_reference_type.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_REFERENCE_TYPE__HPP 22 | #define J4A__AST_REFERENCE_TYPE__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_type.hpp" 26 | 27 | NS_AST_BEGIN 28 | 29 | class ReferenceType: public Type 30 | { 31 | public: 32 | AST_IMPLEMENT(ReferenceType); 33 | AST_CREATE_NAMED___(ReferenceType, Type); 34 | AST_CREATE_POINTER_(ReferenceType, Type, Identifier); 35 | 36 | public: 37 | virtual bool is_reference_type() override {return true;} 38 | virtual bool is_void_type() override {return false;} 39 | virtual bool is_string_type() override; 40 | 41 | virtual j4a::string get_c_type() override; 42 | virtual j4a::string get_c_sign_in_method() override; 43 | virtual j4a::string get_c_default_value() override {return "NULL";} 44 | 45 | virtual j4a::string get_c_call_instance_method_api() override {return "CallObjectMethod";} 46 | virtual j4a::string get_c_call_static_method_api() override {return "CallStaticObjectMethod";} 47 | virtual j4a::string get_c_get_instance_field_api() override {return "GetObjectField";} 48 | virtual j4a::string get_c_get_static_field_api() override {return "GetStaticObjectField";} 49 | virtual j4a::string get_c_set_instance_field_api() override {return "SetObjectField";} 50 | virtual j4a::string get_c_set_static_field_api() override {return "SetStaticObjectField";} 51 | 52 | private: 53 | j4a::string _get_java_long_name(); 54 | }; 55 | 56 | NS_AST_END 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/ast_type.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__AST_TYPE__HPP 22 | #define J4A__AST_TYPE__HPP 23 | 24 | #include "ast__def.hpp" 25 | #include "ast_identifier.hpp" 26 | 27 | NS_AST_BEGIN 28 | 29 | class Type: public Identifier 30 | { 31 | public: 32 | AST_IMPLEMENT_ABSTRACT(Type); 33 | AST_CREATE_NAMED____ABSTRACT(Type, Identifier); 34 | 35 | AST_PROPERTY_DEFINE(bool, is_array) = false; 36 | protected: 37 | explicit Type(Node *other): Identifier(other) {init(other);} 38 | private: 39 | void init(Node *other) { 40 | if (other) { 41 | Type *other_ = dynamic_cast(other); 42 | if (other_) 43 | set_is_array(other_->get_is_array()); 44 | } 45 | } 46 | 47 | AST_GETTER_DECL_0(j4a::string, c_type); 48 | AST_GETTER_DECL_0(j4a::string, c_sign_in_method); 49 | AST_GETTER_DECL_0(j4a::string, c_default_value); 50 | 51 | AST_GETTER_DECL_0(j4a::string, c_call_instance_method_api); 52 | AST_GETTER_DECL_0(j4a::string, c_call_static_method_api); 53 | AST_GETTER_DECL_0(j4a::string, c_get_instance_field_api); 54 | AST_GETTER_DECL_0(j4a::string, c_get_static_field_api); 55 | AST_GETTER_DECL_0(j4a::string, c_set_instance_field_api); 56 | AST_GETTER_DECL_0(j4a::string, c_set_static_field_api); 57 | 58 | public: 59 | virtual bool is_reference_type() = 0; 60 | virtual bool is_void_type() = 0; 61 | virtual bool is_string_type() = 0; 62 | 63 | // @Override 64 | virtual void debug_print(int indent) override { 65 | if (get_is_array()) { 66 | std::cout << get_name() << "[]" << std::endl; 67 | } else { 68 | std::cout << get_name(); 69 | } 70 | } 71 | }; 72 | 73 | NS_AST_END 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/flex.j4a.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include "j4a__yy.h" 4 | #include "j4a_object.h" 5 | #include "j4a_string.h" 6 | #include "j4a_string_pool.h" 7 | #include "bison.j4a.tab.hpp" 8 | %} 9 | %option yylineno 10 | %option noyywrap 11 | 12 | ID ([a-zA-Z_][a-zA-Z0-9_]*) 13 | INTEGER ([0-9]*) 14 | WHITESPACE ([ \t\v\r\n]) 15 | 16 | %% 17 | 18 | "," {return yytext[0];} 19 | "." {return yytext[0];} 20 | ";" {return yytext[0];} 21 | "{" {return yytext[0];} 22 | "}" {return yytext[0];} 23 | "[" {return yytext[0];} 24 | "]" {return yytext[0];} 25 | "(" {return yytext[0];} 26 | ")" {return yytext[0];} 27 | "@" {return yytext[0];} 28 | 29 | "package" {return T_PACKAGE;} 30 | "import" {return T_IMPORT;} 31 | 32 | "boolean" {return T_BOOLEAN;} 33 | "byte" {return T_BYTE;} 34 | "float" {return T_FLOAT;} 35 | "double" {return T_DOUBLE;} 36 | "char" {return T_CHAR;} 37 | "short" {return T_SHORT;} 38 | "int" {return T_INT;} 39 | "long" {return T_LONG;} 40 | "void" {return T_VOID;} 41 | 42 | "private" {return T_PRIVATE;} 43 | "protected" {return T_PROTECTED;} 44 | "public" {return T_PUBLIC;} 45 | 46 | "abstract" {return T_ABSTRACT;} 47 | "final" {return T_FINAL;} 48 | "static" {return T_STATIC;} 49 | 50 | "class" {return T_CLASS;} 51 | "interface" {return T_INTERFACE;} 52 | 53 | \n {yylineno++;} 54 | {WHITESPACE} {;} 55 | {INTEGER} {FLEX_LOGF(":%s\n", yytext); yylval.string = j4a::make_managed_str_ptr(yytext); return T_INTEGER_LITERAL;} 56 | {ID} {FLEX_LOGF(":%s\n", yytext); yylval.string = j4a::make_managed_str_ptr(yytext); return T_ID;} 57 | <> {yyterminate(); return T_EOF;} 58 | . {FLEX_LOGF("Unknown token at line %d: '%s'\n", yylineno, yytext); yyterminate();} 59 | 60 | %% 61 | -------------------------------------------------------------------------------- /src/j4a.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__H 22 | #define J4A__H 23 | 24 | #include "j4a__def.h" 25 | #include "j4a_string.h" 26 | #include "j4a_string_pool.h" 27 | #include "j4a_object.h" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/j4a__def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__DEF__H 22 | #define J4A__DEF__H 23 | 24 | // System Headers 25 | #include 26 | 27 | // C Headers 28 | #include 29 | #include 30 | 31 | // C++ Headers 32 | #include 33 | #include 34 | 35 | #define NS_J4A_BEGIN namespace j4a { 36 | #define NS_J4A_END } 37 | 38 | #define NS_GLOBAL_BEGIN namespace global { 39 | #define NS_GLOBAL_END } 40 | 41 | NS_J4A_BEGIN 42 | 43 | class string; 44 | 45 | class fill 46 | { 47 | public: 48 | fill(char ch, int width): m_ch(ch), m_width(width) {;} 49 | char m_ch; 50 | int m_width; 51 | }; 52 | 53 | NS_GLOBAL_BEGIN 54 | 55 | template 56 | inline std::basic_ostream& 57 | operator<<(std::basic_ostream& os, 58 | const std::auto_ptr >& str) 59 | { 60 | return os << str->c_str(); 61 | } 62 | 63 | template 64 | inline std::basic_ostream& 65 | operator<<(std::basic_ostream& os, const j4a::fill& rhs) 66 | { 67 | for (int i = 0; i < rhs.m_width; ++i) 68 | os << rhs.m_ch; 69 | return os; 70 | } 71 | 72 | NS_GLOBAL_END 73 | 74 | NS_J4A_END 75 | 76 | using namespace j4a::global; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/j4a__yy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__YY__H 22 | #define J4A__YY__H 23 | 24 | #include 25 | #include 26 | #include "j4a__def.h" 27 | 28 | #define FLEX_LOGF printf 29 | #define BISON_LOGF printf 30 | #define BISON_DELETE(x__) do {delete x__; x__ = NULL;} while(0) 31 | 32 | extern int yylex(); 33 | extern FILE *yyin; 34 | extern FILE *yyout; 35 | extern int yylineno; 36 | inline static void yyerror(const char *s) { printf("ERROR: at line %d\n\t%s\n", yylineno, s);} 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/j4a_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__OBJECT__H 22 | #define J4A__OBJECT__H 23 | 24 | #include 25 | #include "j4a__def.h" 26 | #include "j4a_ref_ptr.h" 27 | 28 | NS_J4A_BEGIN 29 | 30 | class object 31 | { 32 | public: 33 | int add_ref() const 34 | { 35 | return __sync_add_and_fetch(&m_ref_count, 1); 36 | } 37 | 38 | int release() const 39 | { 40 | int ref_count = __sync_sub_and_fetch(&m_ref_count, 1); 41 | assert(ref_count >= 0); 42 | if (ref_count == 0) 43 | delete this; 44 | return ref_count; 45 | } 46 | 47 | int _get_ref() const {return m_ref_count;} 48 | 49 | private: 50 | volatile mutable int m_ref_count; 51 | 52 | protected: 53 | object(): m_ref_count(0) {;} 54 | virtual ~object() {;} 55 | 56 | private: 57 | object(const object&); 58 | object &operator=(const object&); 59 | }; 60 | 61 | typedef ref_ptr object_ptr; 62 | 63 | NS_J4A_END 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/j4a_ref_ptr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2015 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A__REF_PTR__H 22 | #define J4A__REF_PTR__H 23 | 24 | #include "j4a__def.h" 25 | 26 | NS_J4A_BEGIN 27 | 28 | template 29 | class ref_ptr 30 | { 31 | public: 32 | typedef T element_type; 33 | typedef ref_ptr my_type; 34 | 35 | void release() 36 | { 37 | if (m_p) { 38 | m_p->release(); 39 | m_p = NULL; 40 | } 41 | } 42 | 43 | void assign(T* p) {do_assign(p);} 44 | void assign(const my_type &p) {do_assign(p.m_p);} 45 | template 46 | void assign(T1*& p) {do_assign(static_cast(p));} 47 | template 48 | void assign(const ref_ptr& r) {do_assign(static_cast(r.get()));} 49 | 50 | T* get() const {return static_cast(m_p);} 51 | T* detach() {T *p = m_p; m_p = NULL; return p;} 52 | bool is_null() const {return !m_p;} 53 | 54 | T* operator->() const {return m_p;} 55 | T& operator*() const {return *m_p;} 56 | operator bool() const {return !!m_p;} 57 | operator T*() const {return m_p;} 58 | 59 | private: 60 | void do_assign(T* p) 61 | { 62 | if (m_p == p) 63 | return; 64 | 65 | if (p) 66 | p->add_ref(); 67 | 68 | release(); 69 | m_p = p; 70 | } 71 | 72 | public: 73 | ref_ptr(): m_p(NULL) {;} 74 | ref_ptr(T* p): m_p(NULL) {assign(p);} 75 | ~ref_ptr() {release();} 76 | 77 | ref_ptr(const my_type& r): m_p(NULL) {assign(r);} 78 | my_type& operator=(const my_type& r) {assign(r); return *this;} 79 | 80 | template 81 | ref_ptr(T1* p): m_p(NULL) {assign(p);} 82 | template 83 | my_type& operator=(T1* p) {assign(p); return *this;} 84 | 85 | template 86 | ref_ptr(const ref_ptr& r): m_p(NULL) {assign(r);} 87 | template 88 | my_type& operator=(const ref_ptr& r) {assign(r); return *this;} 89 | 90 | private: 91 | mutable T *m_p; 92 | }; 93 | 94 | NS_J4A_END 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /src/j4a_string.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "j4a_string.h" 22 | #include "j4a_string.internal.h" 23 | #include 24 | 25 | using namespace j4a; 26 | 27 | const std::shared_ptr& string::shared_ptr_() const 28 | { 29 | return m_data_shared_ptr; 30 | } 31 | 32 | std::shared_ptr& string::shared_ptr_() 33 | { 34 | if (!m_data_shared_ptr.unique()) 35 | m_data_shared_ptr.reset(new string_data(*m_data_shared_ptr)); 36 | 37 | return m_data_shared_ptr; 38 | } 39 | 40 | const std::string& string::shared_string_() const 41 | { 42 | return shared_ptr_()->string(); 43 | } 44 | 45 | std::string& string::shared_string_() 46 | { 47 | return shared_ptr_()->string(); 48 | } 49 | 50 | string::~string() 51 | { 52 | 53 | } 54 | 55 | string::string(): m_data_shared_ptr(new string_data()) 56 | { 57 | } 58 | 59 | string::string(const string& str): m_data_shared_ptr(str.m_data_shared_ptr) 60 | { 61 | } 62 | 63 | string& string::assign(const string& str) 64 | { 65 | m_data_shared_ptr = str.m_data_shared_ptr; 66 | return *this; 67 | } 68 | 69 | string& string::assign(const char* str) 70 | { 71 | if (m_data_shared_ptr.unique()) { 72 | m_data_shared_ptr->assign(str); 73 | } else { 74 | m_data_shared_ptr.reset(new string_data(str)); 75 | } 76 | 77 | return *this; 78 | } 79 | 80 | string& string::do_assign(const std::string& str) 81 | { 82 | if (m_data_shared_ptr.unique()) { 83 | m_data_shared_ptr->assign(str.c_str()); 84 | } else { 85 | m_data_shared_ptr.reset(new string_data(str)); 86 | } 87 | 88 | return *this; 89 | } 90 | 91 | string& string::assign(const std::string& str) 92 | { 93 | return do_assign(str); 94 | } 95 | 96 | string& string::assign(const std::ostringstream& str) 97 | { 98 | return do_assign(str.str()); 99 | } 100 | 101 | string& string::assign(const string& str, size_type pos, size_type len) 102 | { 103 | return do_assign(std::string(str.shared_string_(), pos, npos)); 104 | } 105 | 106 | string& string::assign(const char* s, size_type n) 107 | { 108 | return do_assign(std::string(s, n)); 109 | } 110 | 111 | string& string::assign(size_type n, char c) 112 | { 113 | return do_assign(std::string(n, c)); 114 | } 115 | 116 | template 117 | string& string::assign(InputIterator first, InputIterator last) 118 | { 119 | return do_assign(std::string(first, last)); 120 | } 121 | 122 | string& string::append(const string& str) 123 | { 124 | shared_string_().append(str.shared_string_()); 125 | return *this; 126 | } 127 | 128 | string& string::append(const string& str, size_type subpos, size_type sublen) 129 | { 130 | shared_string_().append(str.shared_string_(), subpos, sublen); 131 | return *this; 132 | } 133 | 134 | string& string::append(const char* s) 135 | { 136 | shared_string_().append(s); 137 | return *this; 138 | } 139 | 140 | string& string::append(const char* s, size_type n) 141 | { 142 | shared_string_().append(s, n); 143 | return *this; 144 | } 145 | 146 | string& string::append(size_type n, char c) 147 | { 148 | shared_string_().append(n, c); 149 | return *this; 150 | } 151 | 152 | template 153 | string& string::append(InputIterator first, InputIterator last) 154 | { 155 | shared_string_().append(first, last); 156 | return *this; 157 | } 158 | 159 | int string::compare(const string& str) const 160 | { 161 | return shared_string_().compare(str.shared_string_()); 162 | } 163 | 164 | int string::compare(size_type pos, size_type len, const string& str) const 165 | { 166 | return shared_string_().compare(pos, len, str.shared_string_()); 167 | } 168 | 169 | int string::compare(size_type pos, size_type len, const string& str, size_type subpos, size_type sublen) const 170 | { 171 | return shared_string_().compare(pos, len, str.shared_string_(), subpos, sublen); 172 | } 173 | 174 | int string::compare(const char* s) const 175 | { 176 | return shared_string_().compare(s); 177 | } 178 | 179 | int string::compare(size_type pos, size_type len, const char* s) const 180 | { 181 | return shared_string_().compare(pos, len, s); 182 | } 183 | 184 | int string::compare(size_type pos, size_type len, const char* s, size_type n) const 185 | { 186 | return shared_string_().compare(pos, len, s, n); 187 | } 188 | 189 | bool string::operator<(const string &rhs) const 190 | { 191 | return shared_string_() < rhs.shared_string_(); 192 | } 193 | 194 | bool string::is_null() const 195 | { 196 | return shared_ptr_()->is_null(); 197 | } 198 | 199 | const std::string& string::std_str() const 200 | { 201 | return shared_string_(); 202 | } 203 | 204 | string string::quoted(char quote_char) const 205 | { 206 | std::string quoted; 207 | quoted.reserve(shared_string_().length() + 2); 208 | quoted.append(1, quote_char); 209 | quoted.append(shared_string_()); 210 | quoted.append(1, quote_char); 211 | return quoted; 212 | } 213 | -------------------------------------------------------------------------------- /src/j4a_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A_STRING__H 22 | #define J4A_STRING__H 23 | 24 | #include "j4a__def.h" 25 | #include 26 | #include 27 | #include 28 | 29 | NS_J4A_BEGIN 30 | 31 | class string_data; 32 | 33 | class string 34 | { 35 | public: 36 | typedef std::string::size_type size_type; 37 | static const size_type npos = std::string::npos; 38 | 39 | ~string(); 40 | string(); 41 | string(const string& str); 42 | string(const char* str) {assign(str);} 43 | string(const std::string& str) {assign(str);} 44 | string(const std::ostringstream& str) {assign(str);} 45 | string(const string& str, size_type pos, size_type len = npos) {assign(str, pos, len);} 46 | string(const char* s, size_type n) {assign(s, n);} 47 | string(size_type n, char c) {assign(n, c);} 48 | template 49 | string(InputIterator first, InputIterator last) {assign(first, last);} 50 | 51 | string& operator=(const string& str) {return assign(str);} 52 | string& operator=(const char* str) {return assign(str);} 53 | string& operator=(const std::string& str) {return assign(str);} 54 | string& operator=(const std::ostringstream& str) {return assign(str);} 55 | bool operator<(const string &str) const; 56 | string& operator+=(const string& str) {return append(str);} 57 | string& operator+=(const char* str) {return append(str);} 58 | string& operator+=(const char str) {return append(1, str);} 59 | 60 | string& assign(const string& str); 61 | string& assign(const char* str); 62 | string& assign(const std::string& str); 63 | string& assign(const std::ostringstream& str); 64 | string& assign(const string& str, size_type pos, size_type len = npos); 65 | string& assign(const char* s, size_type n); 66 | string& assign(size_type n, char c); 67 | template 68 | string& assign(InputIterator first, InputIterator last); 69 | 70 | string& append(const string& str); 71 | string& append(const string& str, size_type subpos, size_type sublen); 72 | string& append(const char* s); 73 | string& append(const char* s, size_type n); 74 | string& append(size_type n, char c); 75 | template 76 | string& append(InputIterator first, InputIterator last); 77 | 78 | int compare(const string& str) const; 79 | int compare(size_type pos, size_type len, const string& str) const; 80 | int compare(size_type pos, size_type len, const string& str, size_type subpos, size_type sublen) const; 81 | int compare(const char* s) const; 82 | int compare(size_type pos, size_type len, const char* s) const; 83 | int compare(size_type pos, size_type len, const char* s, size_type n) const; 84 | 85 | 86 | bool is_null() const; 87 | const std::string& std_str() const; 88 | const char* c_str() const {return std_str().c_str();} 89 | 90 | string quoted(char quote_char = '"') const; 91 | 92 | private: 93 | const std::shared_ptr& shared_ptr_() const; 94 | std::shared_ptr& shared_ptr_(); 95 | const std::string& shared_string_() const; 96 | std::string& shared_string_(); 97 | 98 | // copy on write 99 | std::shared_ptr m_data_shared_ptr; 100 | 101 | string& do_assign(const std::string& str); 102 | }; 103 | 104 | inline string make_quoted(const string& text, char quote_char = '"') 105 | { 106 | return text.quoted(quote_char); 107 | } 108 | 109 | inline string make_quoted(const char *text, char quote_char = '"') 110 | { 111 | return string(text).quoted(quote_char); 112 | } 113 | 114 | NS_GLOBAL_BEGIN 115 | 116 | inline bool operator<(const string &lhs, const string &rhs) 117 | { 118 | if (lhs.is_null()) 119 | return !rhs.is_null(); 120 | 121 | if (rhs.is_null()) 122 | return false; 123 | 124 | return lhs.std_str() < rhs.std_str(); 125 | } 126 | 127 | inline string operator+(const string& lhs, const string& rhs) {string r(lhs); return r += rhs;} 128 | inline string operator+(const string& lhs, const char* rhs) {string r(lhs); return r += rhs;} 129 | inline string operator+(const char* lhs, const string& rhs) {string r(lhs); return r += rhs;} 130 | inline string operator+(const string& lhs, char rhs) {string r(lhs); return r += rhs;} 131 | inline string operator+(char lhs, const string& rhs) {string r(1, lhs); return r += rhs;} 132 | 133 | inline std::ostream& 134 | operator<<(std::ostream& os, const string& rhs) {return os << rhs.std_str();} 135 | 136 | NS_GLOBAL_END 137 | 138 | NS_J4A_END 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /src/j4a_string.internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A_STRING__INTERNAL__H 22 | #define J4A_STRING__INTERNAL__H 23 | 24 | #include "j4a__def.h" 25 | #include 26 | 27 | NS_J4A_BEGIN 28 | 29 | class string_data 30 | { 31 | public: 32 | string_data(): m_is_null(true) 33 | { 34 | } 35 | 36 | string_data(const std::string& rhs): m_is_null(false), m_string(rhs) 37 | { 38 | } 39 | 40 | string_data(const char* rhs): m_is_null(true) 41 | { 42 | assign(rhs); 43 | } 44 | 45 | const std::string& string() const {return m_string;} 46 | std::string& string() {return m_string;} 47 | bool is_null() const {return this->m_is_null;} 48 | 49 | void assign(const char *str) 50 | { 51 | if (str) { 52 | this->m_string = str; 53 | this->m_is_null = true; 54 | } else { 55 | this->m_string = std::string(); 56 | this->m_is_null = false; 57 | } 58 | } 59 | 60 | void assign(const std::string& str) 61 | { 62 | this->m_string = str; 63 | this->m_is_null = false; 64 | } 65 | 66 | private: 67 | std::string m_string; 68 | bool m_is_null; 69 | }; 70 | 71 | NS_J4A_END 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/j4a_string_pool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "j4a_string_pool.h" 22 | 23 | using namespace j4a; 24 | 25 | string_pool &string_pool::instance() 26 | { 27 | static string_pool s_instance; 28 | return s_instance; 29 | } 30 | 31 | const string& string_pool::obtain_string_ref(const char *text) 32 | { 33 | return *m_pool.insert(text).first; 34 | } 35 | 36 | const string* string_pool::obtain_string_ptr(const char *text) 37 | { 38 | return &obtain_string_ref(text); 39 | } 40 | -------------------------------------------------------------------------------- /src/j4a_string_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2016 Zhang Rui 3 | * 4 | * This file is part of jni4android. 5 | * 6 | * jni4android is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * jni4android is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with jni4android; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef J4A_STRING_POOL__H 22 | #define J4A_STRING_POOL__H 23 | 24 | #include "j4a_string.h" 25 | #include 26 | 27 | NS_J4A_BEGIN 28 | 29 | class string_pool 30 | { 31 | public: 32 | typedef std::set pool; 33 | 34 | static string_pool &instance(); 35 | const string& obtain_string_ref(const char *text); 36 | const string* obtain_string_ptr(const char *text); 37 | 38 | private: 39 | string_pool() {;} 40 | 41 | pool m_pool; 42 | }; 43 | 44 | inline const string* make_managed_str_ptr(const char *text) 45 | { 46 | return string_pool::instance().obtain_string_ptr(text); 47 | } 48 | 49 | NS_J4A_END 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /test/i_java/android/media/AudioTrack.java: -------------------------------------------------------------------------------- 1 | package android.media; 2 | 3 | @SimpleCClassName 4 | public class AudioTrack { 5 | public AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode); 6 | 7 | public static int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat); 8 | public static float getMaxVolume(); 9 | public static float getMinVolume(); 10 | public static int getNativeOutputSampleRate (int streamType); 11 | 12 | public void play(); 13 | public void pause(); 14 | public void stop(); 15 | public void flush(); 16 | public void release(); 17 | 18 | public int write(byte[] audioData, int offsetInBytes, int sizeInBytes); 19 | 20 | public int setStereoVolume(float leftGain, float rightGain); 21 | public int getAudioSessionId(); 22 | 23 | @MinApi(23) 24 | public PlaybackParams getPlaybackParams(); 25 | @MinApi(23) 26 | void setPlaybackParams(PlaybackParams params); 27 | } 28 | -------------------------------------------------------------------------------- /test/i_java/android/media/MediaCodec.java: -------------------------------------------------------------------------------- 1 | package android.media; 2 | 3 | import java.nio.ByteBuffer; 4 | import android.view.Surface; 5 | 6 | @SimpleCClassName 7 | @MinApi(16) 8 | public class MediaCodec { 9 | public static class BufferInfo { 10 | public int flags; 11 | public int offset; 12 | public long presentationTimeUs; 13 | public int size; 14 | 15 | public BufferInfo(); 16 | } 17 | 18 | public static MediaCodec createByCodecName(String name); 19 | 20 | public void configure(MediaFormat format, Surface surface, MediaCrypto crypto, int flags); 21 | 22 | public final MediaFormat getOutputFormat(); 23 | 24 | public ByteBuffer[] getInputBuffers(); 25 | 26 | public final int dequeueInputBuffer(long timeoutUs); 27 | public final void queueInputBuffer(int index, int offset, int size, long presentationTimeUs, int flags); 28 | 29 | public final int dequeueOutputBuffer(MediaCodec.BufferInfo info, long timeoutUs); 30 | public final void releaseOutputBuffer(int index, boolean render); 31 | 32 | public final void start(); 33 | public final void stop(); 34 | public final void flush(); 35 | public final void release(); 36 | } 37 | -------------------------------------------------------------------------------- /test/i_java/android/media/MediaCrypto.java: -------------------------------------------------------------------------------- 1 | package android.media; 2 | 3 | @Hide 4 | @MinApi(16) 5 | public class MediaCrypto { 6 | } 7 | -------------------------------------------------------------------------------- /test/i_java/android/media/MediaFormat.java: -------------------------------------------------------------------------------- 1 | package android.media; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | @SimpleCClassName 6 | @MinApi(16) 7 | public class MediaFormat { 8 | public MediaFormat(); 9 | 10 | public final static MediaFormat createVideoFormat(String mime, int width, int height); 11 | 12 | public final int getInteger(String name); 13 | public final void setInteger(String name, int value); 14 | public final void setByteBuffer(String name, ByteBuffer bytes); 15 | } 16 | -------------------------------------------------------------------------------- /test/i_java/android/media/PlaybackParams.java: -------------------------------------------------------------------------------- 1 | package android.media; 2 | 3 | @SimpleCClassName 4 | @MinApi(23) 5 | public class PlaybackParams { 6 | public PlaybackParams setSpeed(float speed); 7 | } 8 | -------------------------------------------------------------------------------- /test/i_java/android/os/Build.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class Build { 4 | public static class VERSION { 5 | public static final int SDK_INT; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/i_java/android/os/Bundle.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | import java.util.ArrayList; 4 | 5 | @SimpleCClassName 6 | public class Bundle { 7 | public Bundle(); 8 | 9 | public int getInt(String key, int defaultValue); 10 | public void putInt(String key, int value); 11 | 12 | public String getString(String key); 13 | public void putString(String key, String value); 14 | 15 | public void putParcelableArrayList(String key, ArrayList value); 16 | } 17 | -------------------------------------------------------------------------------- /test/i_java/java/nio/Buffer.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public class Buffer { 4 | } 5 | -------------------------------------------------------------------------------- /test/i_java/java/nio/ByteBuffer.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | import android.os.Build; 4 | 5 | @SimpleCClassName 6 | public class ByteBuffer { 7 | public static ByteBuffer allocate(int capacity); 8 | public static ByteBuffer allocateDirect(int capacity); 9 | public final Buffer limit(int newLimit); 10 | 11 | public char getChar(); 12 | public short getShort(); 13 | public int getInt(); 14 | public long getLong(); 15 | public float getFloat(); 16 | public double getDouble(); 17 | 18 | public ByteBuffer putChar(char value); 19 | public ByteBuffer putShort(short value); 20 | public ByteBuffer putInt(int value); 21 | public ByteBuffer putLong(long value); 22 | public ByteBuffer putFloat(float value); 23 | public ByteBuffer putDouble(double value); 24 | } 25 | -------------------------------------------------------------------------------- /test/i_java/java/util/ArrayList.java: -------------------------------------------------------------------------------- 1 | package java.util; 2 | 3 | @SimpleCClassName 4 | public class ArrayList { 5 | public ArrayList(); 6 | boolean add(Object object); 7 | } 8 | -------------------------------------------------------------------------------- /test/i_java/test/ReturnPrimitive.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | @SimpleCClassName 4 | public interface ReturnPrimitive { 5 | public int getIntArray(int[] iArr); 6 | public float getFloatArray(float[] fArr); 7 | public double getDoubleArray(double[] iArr); 8 | } 9 | -------------------------------------------------------------------------------- /test/i_java/tv/danmaku/ijk/media/player/IjkMediaPlayer.java: -------------------------------------------------------------------------------- 1 | package tv.danmaku.ijk.media.player; 2 | 3 | import android.os.Bundle; 4 | 5 | @SimpleCClassName 6 | public class IjkMediaPlayer { 7 | private long mNativeMediaPlayer; 8 | private long mNativeMediaDataSource; 9 | 10 | private static void postEventFromNative(Object weakThiz, int what, int arg1, int arg2, Object obj); 11 | private static String onSelectCodec(Object weakThiz, String mimeType, int profile, int level); 12 | private static boolean onNativeInvoke(Object weakThiz, int what, Bundle args); 13 | } 14 | -------------------------------------------------------------------------------- /test/i_java/tv/danmaku/ijk/media/player/misc/IMediaDataSource.java: -------------------------------------------------------------------------------- 1 | package tv.danmaku.ijk.media.player.misc; 2 | 3 | @SimpleCClassName 4 | public interface IMediaDataSource { 5 | int readAt(long position, byte[] buffer, int offset, int size); 6 | long getSize(); 7 | void close(); 8 | } 9 | -------------------------------------------------------------------------------- /test/ref_c/android/media/AudioTrack.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/android/media/AudioTrack.h" -------------------------------------------------------------------------------- /test/ref_c/android/media/AudioTrack.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(android_media_AudioTrack); -------------------------------------------------------------------------------- /test/ref_c/android/media/MediaCodec.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/android/media/MediaCodec.h" -------------------------------------------------------------------------------- /test/ref_c/android/media/MediaCodec.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(android_media_MediaCodec); -------------------------------------------------------------------------------- /test/ref_c/android/media/MediaFormat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__android_media_MediaFormat__H 23 | #define J4A__android_media_MediaFormat__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | jobject J4AC_android_media_MediaFormat__MediaFormat(JNIEnv *env); 28 | jobject J4AC_android_media_MediaFormat__MediaFormat__catchAll(JNIEnv *env); 29 | jobject J4AC_android_media_MediaFormat__MediaFormat__asGlobalRef__catchAll(JNIEnv *env); 30 | jobject J4AC_android_media_MediaFormat__createVideoFormat(JNIEnv *env, jstring mime, jint width, jint height); 31 | jobject J4AC_android_media_MediaFormat__createVideoFormat__catchAll(JNIEnv *env, jstring mime, jint width, jint height); 32 | jobject J4AC_android_media_MediaFormat__createVideoFormat__asGlobalRef__catchAll(JNIEnv *env, jstring mime, jint width, jint height); 33 | jobject J4AC_android_media_MediaFormat__createVideoFormat__withCString(JNIEnv *env, const char *mime_cstr__, jint width, jint height); 34 | jobject J4AC_android_media_MediaFormat__createVideoFormat__withCString__catchAll(JNIEnv *env, const char *mime_cstr__, jint width, jint height); 35 | jobject J4AC_android_media_MediaFormat__createVideoFormat__withCString__asGlobalRef__catchAll(JNIEnv *env, const char *mime_cstr__, jint width, jint height); 36 | jint J4AC_android_media_MediaFormat__getInteger(JNIEnv *env, jobject thiz, jstring name); 37 | jint J4AC_android_media_MediaFormat__getInteger__catchAll(JNIEnv *env, jobject thiz, jstring name); 38 | jint J4AC_android_media_MediaFormat__getInteger__withCString(JNIEnv *env, jobject thiz, const char *name_cstr__); 39 | jint J4AC_android_media_MediaFormat__getInteger__withCString__catchAll(JNIEnv *env, jobject thiz, const char *name_cstr__); 40 | void J4AC_android_media_MediaFormat__setInteger(JNIEnv *env, jobject thiz, jstring name, jint value); 41 | void J4AC_android_media_MediaFormat__setInteger__catchAll(JNIEnv *env, jobject thiz, jstring name, jint value); 42 | void J4AC_android_media_MediaFormat__setInteger__withCString(JNIEnv *env, jobject thiz, const char *name_cstr__, jint value); 43 | void J4AC_android_media_MediaFormat__setInteger__withCString__catchAll(JNIEnv *env, jobject thiz, const char *name_cstr__, jint value); 44 | void J4AC_android_media_MediaFormat__setByteBuffer(JNIEnv *env, jobject thiz, jstring name, jobject bytes); 45 | void J4AC_android_media_MediaFormat__setByteBuffer__catchAll(JNIEnv *env, jobject thiz, jstring name, jobject bytes); 46 | void J4AC_android_media_MediaFormat__setByteBuffer__withCString(JNIEnv *env, jobject thiz, const char *name_cstr__, jobject bytes); 47 | void J4AC_android_media_MediaFormat__setByteBuffer__withCString__catchAll(JNIEnv *env, jobject thiz, const char *name_cstr__, jobject bytes); 48 | int J4A_loadClass__J4AC_android_media_MediaFormat(JNIEnv *env); 49 | 50 | #define J4A_HAVE_SIMPLE__J4AC_android_media_MediaFormat 51 | 52 | #define J4AC_MediaFormat__MediaFormat J4AC_android_media_MediaFormat__MediaFormat 53 | #define J4AC_MediaFormat__MediaFormat__asGlobalRef__catchAll J4AC_android_media_MediaFormat__MediaFormat__asGlobalRef__catchAll 54 | #define J4AC_MediaFormat__MediaFormat__catchAll J4AC_android_media_MediaFormat__MediaFormat__catchAll 55 | #define J4AC_MediaFormat__createVideoFormat J4AC_android_media_MediaFormat__createVideoFormat 56 | #define J4AC_MediaFormat__createVideoFormat__asGlobalRef__catchAll J4AC_android_media_MediaFormat__createVideoFormat__asGlobalRef__catchAll 57 | #define J4AC_MediaFormat__createVideoFormat__catchAll J4AC_android_media_MediaFormat__createVideoFormat__catchAll 58 | #define J4AC_MediaFormat__createVideoFormat__withCString J4AC_android_media_MediaFormat__createVideoFormat__withCString 59 | #define J4AC_MediaFormat__createVideoFormat__withCString__asGlobalRef__catchAll J4AC_android_media_MediaFormat__createVideoFormat__withCString__asGlobalRef__catchAll 60 | #define J4AC_MediaFormat__createVideoFormat__withCString__catchAll J4AC_android_media_MediaFormat__createVideoFormat__withCString__catchAll 61 | #define J4AC_MediaFormat__getInteger J4AC_android_media_MediaFormat__getInteger 62 | #define J4AC_MediaFormat__getInteger__catchAll J4AC_android_media_MediaFormat__getInteger__catchAll 63 | #define J4AC_MediaFormat__getInteger__withCString J4AC_android_media_MediaFormat__getInteger__withCString 64 | #define J4AC_MediaFormat__getInteger__withCString__catchAll J4AC_android_media_MediaFormat__getInteger__withCString__catchAll 65 | #define J4AC_MediaFormat__setInteger J4AC_android_media_MediaFormat__setInteger 66 | #define J4AC_MediaFormat__setInteger__catchAll J4AC_android_media_MediaFormat__setInteger__catchAll 67 | #define J4AC_MediaFormat__setInteger__withCString J4AC_android_media_MediaFormat__setInteger__withCString 68 | #define J4AC_MediaFormat__setInteger__withCString__catchAll J4AC_android_media_MediaFormat__setInteger__withCString__catchAll 69 | #define J4AC_MediaFormat__setByteBuffer J4AC_android_media_MediaFormat__setByteBuffer 70 | #define J4AC_MediaFormat__setByteBuffer__catchAll J4AC_android_media_MediaFormat__setByteBuffer__catchAll 71 | #define J4AC_MediaFormat__setByteBuffer__withCString J4AC_android_media_MediaFormat__setByteBuffer__withCString 72 | #define J4AC_MediaFormat__setByteBuffer__withCString__catchAll J4AC_android_media_MediaFormat__setByteBuffer__withCString__catchAll 73 | #define J4A_loadClass__J4AC_MediaFormat J4A_loadClass__J4AC_android_media_MediaFormat 74 | 75 | #endif//J4A__android_media_MediaFormat__H 76 | -------------------------------------------------------------------------------- /test/ref_c/android/media/MediaFormat.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/android/media/MediaFormat.h" -------------------------------------------------------------------------------- /test/ref_c/android/media/MediaFormat.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(android_media_MediaFormat); -------------------------------------------------------------------------------- /test/ref_c/android/media/PlaybackParams.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #include "PlaybackParams.h" 23 | 24 | typedef struct J4AC_android_media_PlaybackParams { 25 | jclass id; 26 | 27 | jmethodID method_setSpeed; 28 | } J4AC_android_media_PlaybackParams; 29 | static J4AC_android_media_PlaybackParams class_J4AC_android_media_PlaybackParams; 30 | 31 | jobject J4AC_android_media_PlaybackParams__setSpeed(JNIEnv *env, jobject thiz, jfloat speed) 32 | { 33 | return (*env)->CallObjectMethod(env, thiz, class_J4AC_android_media_PlaybackParams.method_setSpeed, speed); 34 | } 35 | 36 | jobject J4AC_android_media_PlaybackParams__setSpeed__catchAll(JNIEnv *env, jobject thiz, jfloat speed) 37 | { 38 | jobject ret_object = J4AC_android_media_PlaybackParams__setSpeed(env, thiz, speed); 39 | if (J4A_ExceptionCheck__catchAll(env) || !ret_object) { 40 | return NULL; 41 | } 42 | 43 | return ret_object; 44 | } 45 | 46 | jobject J4AC_android_media_PlaybackParams__setSpeed__asGlobalRef__catchAll(JNIEnv *env, jobject thiz, jfloat speed) 47 | { 48 | jobject ret_object = NULL; 49 | jobject local_object = J4AC_android_media_PlaybackParams__setSpeed__catchAll(env, thiz, speed); 50 | if (J4A_ExceptionCheck__catchAll(env) || !local_object) { 51 | ret_object = NULL; 52 | goto fail; 53 | } 54 | 55 | ret_object = J4A_NewGlobalRef__catchAll(env, local_object); 56 | if (!ret_object) { 57 | ret_object = NULL; 58 | goto fail; 59 | } 60 | 61 | fail: 62 | J4A_DeleteLocalRef__p(env, &local_object); 63 | return ret_object; 64 | } 65 | 66 | int J4A_loadClass__J4AC_android_media_PlaybackParams(JNIEnv *env) 67 | { 68 | int ret = -1; 69 | const char *J4A_UNUSED(name) = NULL; 70 | const char *J4A_UNUSED(sign) = NULL; 71 | jclass J4A_UNUSED(class_id) = NULL; 72 | int J4A_UNUSED(api_level) = 0; 73 | 74 | if (class_J4AC_android_media_PlaybackParams.id != NULL) 75 | return 0; 76 | 77 | api_level = J4A_GetSystemAndroidApiLevel(env); 78 | 79 | if (api_level < 23) { 80 | J4A_ALOGW("J4ALoader: Ignore: '%s' need API %d\n", "android.media.PlaybackParams", api_level); 81 | goto ignore; 82 | } 83 | 84 | sign = "android/media/PlaybackParams"; 85 | class_J4AC_android_media_PlaybackParams.id = J4A_FindClass__asGlobalRef__catchAll(env, sign); 86 | if (class_J4AC_android_media_PlaybackParams.id == NULL) 87 | goto fail; 88 | 89 | class_id = class_J4AC_android_media_PlaybackParams.id; 90 | name = "setSpeed"; 91 | sign = "(F)Landroid/media/PlaybackParams;"; 92 | class_J4AC_android_media_PlaybackParams.method_setSpeed = J4A_GetMethodID__catchAll(env, class_id, name, sign); 93 | if (class_J4AC_android_media_PlaybackParams.method_setSpeed == NULL) 94 | goto fail; 95 | 96 | J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "android.media.PlaybackParams"); 97 | ignore: 98 | ret = 0; 99 | fail: 100 | return ret; 101 | } 102 | -------------------------------------------------------------------------------- /test/ref_c/android/media/PlaybackParams.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__android_media_PlaybackParams__H 23 | #define J4A__android_media_PlaybackParams__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | jobject J4AC_android_media_PlaybackParams__setSpeed(JNIEnv *env, jobject thiz, jfloat speed); 28 | jobject J4AC_android_media_PlaybackParams__setSpeed__catchAll(JNIEnv *env, jobject thiz, jfloat speed); 29 | jobject J4AC_android_media_PlaybackParams__setSpeed__asGlobalRef__catchAll(JNIEnv *env, jobject thiz, jfloat speed); 30 | int J4A_loadClass__J4AC_android_media_PlaybackParams(JNIEnv *env); 31 | 32 | #define J4A_HAVE_SIMPLE__J4AC_android_media_PlaybackParams 33 | 34 | #define J4AC_PlaybackParams__setSpeed J4AC_android_media_PlaybackParams__setSpeed 35 | #define J4AC_PlaybackParams__setSpeed__asGlobalRef__catchAll J4AC_android_media_PlaybackParams__setSpeed__asGlobalRef__catchAll 36 | #define J4AC_PlaybackParams__setSpeed__catchAll J4AC_android_media_PlaybackParams__setSpeed__catchAll 37 | #define J4A_loadClass__J4AC_PlaybackParams J4A_loadClass__J4AC_android_media_PlaybackParams 38 | 39 | #endif//J4A__android_media_PlaybackParams__H 40 | -------------------------------------------------------------------------------- /test/ref_c/android/media/PlaybackParams.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/android/media/PlaybackParams.h" -------------------------------------------------------------------------------- /test/ref_c/android/media/PlaybackParams.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(android_media_PlaybackParams); -------------------------------------------------------------------------------- /test/ref_c/android/os/Build.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #include "Build.h" 23 | 24 | typedef struct J4AC_android_os_Build__VERSION { 25 | jclass id; 26 | 27 | jfieldID field_SDK_INT; 28 | } J4AC_android_os_Build__VERSION; 29 | static J4AC_android_os_Build__VERSION class_J4AC_android_os_Build__VERSION; 30 | 31 | typedef struct J4AC_android_os_Build { 32 | jclass id; 33 | 34 | } J4AC_android_os_Build; 35 | static J4AC_android_os_Build class_J4AC_android_os_Build; 36 | 37 | jint J4AC_android_os_Build__VERSION__SDK_INT__get(JNIEnv *env) 38 | { 39 | return (*env)->GetStaticIntField(env, class_J4AC_android_os_Build__VERSION.id, class_J4AC_android_os_Build__VERSION.field_SDK_INT); 40 | } 41 | 42 | jint J4AC_android_os_Build__VERSION__SDK_INT__get__catchAll(JNIEnv *env) 43 | { 44 | jint ret_value = J4AC_android_os_Build__VERSION__SDK_INT__get(env); 45 | if (J4A_ExceptionCheck__catchAll(env)) { 46 | return 0; 47 | } 48 | 49 | return ret_value; 50 | } 51 | 52 | void J4AC_android_os_Build__VERSION__SDK_INT__set(JNIEnv *env, jint value) 53 | { 54 | (*env)->SetStaticIntField(env, class_J4AC_android_os_Build__VERSION.id, class_J4AC_android_os_Build__VERSION.field_SDK_INT, value); 55 | } 56 | 57 | void J4AC_android_os_Build__VERSION__SDK_INT__set__catchAll(JNIEnv *env, jint value) 58 | { 59 | J4AC_android_os_Build__VERSION__SDK_INT__set(env, value); 60 | J4A_ExceptionCheck__catchAll(env); 61 | } 62 | 63 | int J4A_loadClass__J4AC_android_os_Build__VERSION(JNIEnv *env) 64 | { 65 | int ret = -1; 66 | const char *J4A_UNUSED(name) = NULL; 67 | const char *J4A_UNUSED(sign) = NULL; 68 | jclass J4A_UNUSED(class_id) = NULL; 69 | int J4A_UNUSED(api_level) = 0; 70 | 71 | if (class_J4AC_android_os_Build__VERSION.id != NULL) 72 | return 0; 73 | 74 | sign = "android/os/Build$VERSION"; 75 | class_J4AC_android_os_Build__VERSION.id = J4A_FindClass__asGlobalRef__catchAll(env, sign); 76 | if (class_J4AC_android_os_Build__VERSION.id == NULL) 77 | goto fail; 78 | 79 | class_id = class_J4AC_android_os_Build__VERSION.id; 80 | name = "SDK_INT"; 81 | sign = "I"; 82 | class_J4AC_android_os_Build__VERSION.field_SDK_INT = J4A_GetStaticFieldID__catchAll(env, class_id, name, sign); 83 | if (class_J4AC_android_os_Build__VERSION.field_SDK_INT == NULL) 84 | goto fail; 85 | 86 | J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "android.os.Build$VERSION"); 87 | ret = 0; 88 | fail: 89 | return ret; 90 | } 91 | 92 | int J4A_loadClass__J4AC_android_os_Build(JNIEnv *env) 93 | { 94 | int ret = -1; 95 | const char *J4A_UNUSED(name) = NULL; 96 | const char *J4A_UNUSED(sign) = NULL; 97 | jclass J4A_UNUSED(class_id) = NULL; 98 | int J4A_UNUSED(api_level) = 0; 99 | 100 | if (class_J4AC_android_os_Build.id != NULL) 101 | return 0; 102 | 103 | sign = "android/os/Build"; 104 | class_J4AC_android_os_Build.id = J4A_FindClass__asGlobalRef__catchAll(env, sign); 105 | if (class_J4AC_android_os_Build.id == NULL) 106 | goto fail; 107 | 108 | ret = J4A_loadClass__J4AC_android_os_Build__VERSION(env); 109 | if (ret) 110 | goto fail; 111 | 112 | J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "android.os.Build"); 113 | ret = 0; 114 | fail: 115 | return ret; 116 | } 117 | -------------------------------------------------------------------------------- /test/ref_c/android/os/Build.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__android_os_Build__H 23 | #define J4A__android_os_Build__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | jint J4AC_android_os_Build__VERSION__SDK_INT__get(JNIEnv *env); 28 | jint J4AC_android_os_Build__VERSION__SDK_INT__get__catchAll(JNIEnv *env); 29 | void J4AC_android_os_Build__VERSION__SDK_INT__set(JNIEnv *env, jint value); 30 | void J4AC_android_os_Build__VERSION__SDK_INT__set__catchAll(JNIEnv *env, jint value); 31 | int J4A_loadClass__J4AC_android_os_Build(JNIEnv *env); 32 | 33 | #endif//J4A__android_os_Build__H 34 | -------------------------------------------------------------------------------- /test/ref_c/android/os/Build.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/android/os/Build.h" -------------------------------------------------------------------------------- /test/ref_c/android/os/Build.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(android_os_Build); -------------------------------------------------------------------------------- /test/ref_c/android/os/Bundle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__android_os_Bundle__H 23 | #define J4A__android_os_Bundle__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | jobject J4AC_android_os_Bundle__Bundle(JNIEnv *env); 28 | jobject J4AC_android_os_Bundle__Bundle__catchAll(JNIEnv *env); 29 | jobject J4AC_android_os_Bundle__Bundle__asGlobalRef__catchAll(JNIEnv *env); 30 | jint J4AC_android_os_Bundle__getInt(JNIEnv *env, jobject thiz, jstring key, jint defaultValue); 31 | jint J4AC_android_os_Bundle__getInt__catchAll(JNIEnv *env, jobject thiz, jstring key, jint defaultValue); 32 | jint J4AC_android_os_Bundle__getInt__withCString(JNIEnv *env, jobject thiz, const char *key_cstr__, jint defaultValue); 33 | jint J4AC_android_os_Bundle__getInt__withCString__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__, jint defaultValue); 34 | void J4AC_android_os_Bundle__putInt(JNIEnv *env, jobject thiz, jstring key, jint value); 35 | void J4AC_android_os_Bundle__putInt__catchAll(JNIEnv *env, jobject thiz, jstring key, jint value); 36 | void J4AC_android_os_Bundle__putInt__withCString(JNIEnv *env, jobject thiz, const char *key_cstr__, jint value); 37 | void J4AC_android_os_Bundle__putInt__withCString__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__, jint value); 38 | jstring J4AC_android_os_Bundle__getString(JNIEnv *env, jobject thiz, jstring key); 39 | jstring J4AC_android_os_Bundle__getString__catchAll(JNIEnv *env, jobject thiz, jstring key); 40 | jstring J4AC_android_os_Bundle__getString__asGlobalRef__catchAll(JNIEnv *env, jobject thiz, jstring key); 41 | const char *J4AC_android_os_Bundle__getString__asCBuffer(JNIEnv *env, jobject thiz, jstring key, char *out_buf, int out_len); 42 | const char *J4AC_android_os_Bundle__getString__asCBuffer__catchAll(JNIEnv *env, jobject thiz, jstring key, char *out_buf, int out_len); 43 | jstring J4AC_android_os_Bundle__getString__withCString(JNIEnv *env, jobject thiz, const char *key_cstr__); 44 | jstring J4AC_android_os_Bundle__getString__withCString__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__); 45 | jstring J4AC_android_os_Bundle__getString__withCString__asGlobalRef__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__); 46 | const char *J4AC_android_os_Bundle__getString__withCString__asCBuffer(JNIEnv *env, jobject thiz, const char *key_cstr__, char *out_buf, int out_len); 47 | const char *J4AC_android_os_Bundle__getString__withCString__asCBuffer__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__, char *out_buf, int out_len); 48 | void J4AC_android_os_Bundle__putString(JNIEnv *env, jobject thiz, jstring key, jstring value); 49 | void J4AC_android_os_Bundle__putString__catchAll(JNIEnv *env, jobject thiz, jstring key, jstring value); 50 | void J4AC_android_os_Bundle__putString__withCString(JNIEnv *env, jobject thiz, const char *key_cstr__, const char *value_cstr__); 51 | void J4AC_android_os_Bundle__putString__withCString__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__, const char *value_cstr__); 52 | void J4AC_android_os_Bundle__putParcelableArrayList(JNIEnv *env, jobject thiz, jstring key, jobject value); 53 | void J4AC_android_os_Bundle__putParcelableArrayList__catchAll(JNIEnv *env, jobject thiz, jstring key, jobject value); 54 | void J4AC_android_os_Bundle__putParcelableArrayList__withCString(JNIEnv *env, jobject thiz, const char *key_cstr__, jobject value); 55 | void J4AC_android_os_Bundle__putParcelableArrayList__withCString__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__, jobject value); 56 | int J4A_loadClass__J4AC_android_os_Bundle(JNIEnv *env); 57 | 58 | #define J4A_HAVE_SIMPLE__J4AC_android_os_Bundle 59 | 60 | #define J4AC_Bundle__Bundle J4AC_android_os_Bundle__Bundle 61 | #define J4AC_Bundle__Bundle__asGlobalRef__catchAll J4AC_android_os_Bundle__Bundle__asGlobalRef__catchAll 62 | #define J4AC_Bundle__Bundle__catchAll J4AC_android_os_Bundle__Bundle__catchAll 63 | #define J4AC_Bundle__getInt J4AC_android_os_Bundle__getInt 64 | #define J4AC_Bundle__getInt__catchAll J4AC_android_os_Bundle__getInt__catchAll 65 | #define J4AC_Bundle__getInt__withCString J4AC_android_os_Bundle__getInt__withCString 66 | #define J4AC_Bundle__getInt__withCString__catchAll J4AC_android_os_Bundle__getInt__withCString__catchAll 67 | #define J4AC_Bundle__putInt J4AC_android_os_Bundle__putInt 68 | #define J4AC_Bundle__putInt__catchAll J4AC_android_os_Bundle__putInt__catchAll 69 | #define J4AC_Bundle__putInt__withCString J4AC_android_os_Bundle__putInt__withCString 70 | #define J4AC_Bundle__putInt__withCString__catchAll J4AC_android_os_Bundle__putInt__withCString__catchAll 71 | #define J4AC_Bundle__getString J4AC_android_os_Bundle__getString 72 | #define J4AC_Bundle__getString__asCBuffer J4AC_android_os_Bundle__getString__asCBuffer 73 | #define J4AC_Bundle__getString__asCBuffer__catchAll J4AC_android_os_Bundle__getString__asCBuffer__catchAll 74 | #define J4AC_Bundle__getString__asGlobalRef__catchAll J4AC_android_os_Bundle__getString__asGlobalRef__catchAll 75 | #define J4AC_Bundle__getString__catchAll J4AC_android_os_Bundle__getString__catchAll 76 | #define J4AC_Bundle__getString__withCString J4AC_android_os_Bundle__getString__withCString 77 | #define J4AC_Bundle__getString__withCString__asCBuffer J4AC_android_os_Bundle__getString__withCString__asCBuffer 78 | #define J4AC_Bundle__getString__withCString__asCBuffer__catchAll J4AC_android_os_Bundle__getString__withCString__asCBuffer__catchAll 79 | #define J4AC_Bundle__getString__withCString__asGlobalRef__catchAll J4AC_android_os_Bundle__getString__withCString__asGlobalRef__catchAll 80 | #define J4AC_Bundle__getString__withCString__catchAll J4AC_android_os_Bundle__getString__withCString__catchAll 81 | #define J4AC_Bundle__putString J4AC_android_os_Bundle__putString 82 | #define J4AC_Bundle__putString__catchAll J4AC_android_os_Bundle__putString__catchAll 83 | #define J4AC_Bundle__putString__withCString J4AC_android_os_Bundle__putString__withCString 84 | #define J4AC_Bundle__putString__withCString__catchAll J4AC_android_os_Bundle__putString__withCString__catchAll 85 | #define J4AC_Bundle__putParcelableArrayList J4AC_android_os_Bundle__putParcelableArrayList 86 | #define J4AC_Bundle__putParcelableArrayList__catchAll J4AC_android_os_Bundle__putParcelableArrayList__catchAll 87 | #define J4AC_Bundle__putParcelableArrayList__withCString J4AC_android_os_Bundle__putParcelableArrayList__withCString 88 | #define J4AC_Bundle__putParcelableArrayList__withCString__catchAll J4AC_android_os_Bundle__putParcelableArrayList__withCString__catchAll 89 | #define J4A_loadClass__J4AC_Bundle J4A_loadClass__J4AC_android_os_Bundle 90 | 91 | #endif//J4A__android_os_Bundle__H 92 | -------------------------------------------------------------------------------- /test/ref_c/android/os/Bundle.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/android/os/Bundle.h" -------------------------------------------------------------------------------- /test/ref_c/android/os/Bundle.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(android_os_Bundle); -------------------------------------------------------------------------------- /test/ref_c/java/nio/Buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #include "Buffer.h" 23 | 24 | typedef struct J4AC_java_nio_Buffer { 25 | jclass id; 26 | } J4AC_java_nio_Buffer; 27 | static J4AC_java_nio_Buffer class_J4AC_java_nio_Buffer; 28 | 29 | int J4A_loadClass__J4AC_java_nio_Buffer(JNIEnv *env) 30 | { 31 | int ret = -1; 32 | const char *J4A_UNUSED(name) = NULL; 33 | const char *J4A_UNUSED(sign) = NULL; 34 | jclass J4A_UNUSED(class_id) = NULL; 35 | int J4A_UNUSED(api_level) = 0; 36 | 37 | if (class_J4AC_java_nio_Buffer.id != NULL) 38 | return 0; 39 | 40 | sign = "java/nio/Buffer"; 41 | class_J4AC_java_nio_Buffer.id = J4A_FindClass__asGlobalRef__catchAll(env, sign); 42 | if (class_J4AC_java_nio_Buffer.id == NULL) 43 | goto fail; 44 | 45 | J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "java.nio.Buffer"); 46 | ret = 0; 47 | fail: 48 | return ret; 49 | } 50 | -------------------------------------------------------------------------------- /test/ref_c/java/nio/Buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__java_nio_Buffer__H 23 | #define J4A__java_nio_Buffer__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | int J4A_loadClass__J4AC_java_nio_Buffer(JNIEnv *env); 28 | 29 | #endif//J4A__java_nio_Buffer__H 30 | -------------------------------------------------------------------------------- /test/ref_c/java/nio/Buffer.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/java/nio/Buffer.h" -------------------------------------------------------------------------------- /test/ref_c/java/nio/Buffer.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(java_nio_Buffer); -------------------------------------------------------------------------------- /test/ref_c/java/nio/ByteBuffer.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/java/nio/ByteBuffer.h" -------------------------------------------------------------------------------- /test/ref_c/java/nio/ByteBuffer.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(java_nio_ByteBuffer); -------------------------------------------------------------------------------- /test/ref_c/java/util/ArrayList.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #include "ArrayList.h" 23 | 24 | typedef struct J4AC_java_util_ArrayList { 25 | jclass id; 26 | 27 | jmethodID constructor_ArrayList; 28 | jmethodID method_add; 29 | } J4AC_java_util_ArrayList; 30 | static J4AC_java_util_ArrayList class_J4AC_java_util_ArrayList; 31 | 32 | jobject J4AC_java_util_ArrayList__ArrayList(JNIEnv *env) 33 | { 34 | return (*env)->NewObject(env, class_J4AC_java_util_ArrayList.id, class_J4AC_java_util_ArrayList.constructor_ArrayList); 35 | } 36 | 37 | jobject J4AC_java_util_ArrayList__ArrayList__catchAll(JNIEnv *env) 38 | { 39 | jobject ret_object = J4AC_java_util_ArrayList__ArrayList(env); 40 | if (J4A_ExceptionCheck__catchAll(env) || !ret_object) { 41 | return NULL; 42 | } 43 | 44 | return ret_object; 45 | } 46 | 47 | jobject J4AC_java_util_ArrayList__ArrayList__asGlobalRef__catchAll(JNIEnv *env) 48 | { 49 | jobject ret_object = NULL; 50 | jobject local_object = J4AC_java_util_ArrayList__ArrayList__catchAll(env); 51 | if (J4A_ExceptionCheck__catchAll(env) || !local_object) { 52 | ret_object = NULL; 53 | goto fail; 54 | } 55 | 56 | ret_object = J4A_NewGlobalRef__catchAll(env, local_object); 57 | if (!ret_object) { 58 | ret_object = NULL; 59 | goto fail; 60 | } 61 | 62 | fail: 63 | J4A_DeleteLocalRef__p(env, &local_object); 64 | return ret_object; 65 | } 66 | 67 | jboolean J4AC_java_util_ArrayList__add(JNIEnv *env, jobject thiz, jobject object) 68 | { 69 | return (*env)->CallBooleanMethod(env, thiz, class_J4AC_java_util_ArrayList.method_add, object); 70 | } 71 | 72 | jboolean J4AC_java_util_ArrayList__add__catchAll(JNIEnv *env, jobject thiz, jobject object) 73 | { 74 | jboolean ret_value = J4AC_java_util_ArrayList__add(env, thiz, object); 75 | if (J4A_ExceptionCheck__catchAll(env)) { 76 | return false; 77 | } 78 | 79 | return ret_value; 80 | } 81 | 82 | int J4A_loadClass__J4AC_java_util_ArrayList(JNIEnv *env) 83 | { 84 | int ret = -1; 85 | const char *J4A_UNUSED(name) = NULL; 86 | const char *J4A_UNUSED(sign) = NULL; 87 | jclass J4A_UNUSED(class_id) = NULL; 88 | int J4A_UNUSED(api_level) = 0; 89 | 90 | if (class_J4AC_java_util_ArrayList.id != NULL) 91 | return 0; 92 | 93 | sign = "java/util/ArrayList"; 94 | class_J4AC_java_util_ArrayList.id = J4A_FindClass__asGlobalRef__catchAll(env, sign); 95 | if (class_J4AC_java_util_ArrayList.id == NULL) 96 | goto fail; 97 | 98 | class_id = class_J4AC_java_util_ArrayList.id; 99 | name = ""; 100 | sign = "()V"; 101 | class_J4AC_java_util_ArrayList.constructor_ArrayList = J4A_GetMethodID__catchAll(env, class_id, name, sign); 102 | if (class_J4AC_java_util_ArrayList.constructor_ArrayList == NULL) 103 | goto fail; 104 | 105 | class_id = class_J4AC_java_util_ArrayList.id; 106 | name = "add"; 107 | sign = "(Ljava/lang/Object;)Z"; 108 | class_J4AC_java_util_ArrayList.method_add = J4A_GetMethodID__catchAll(env, class_id, name, sign); 109 | if (class_J4AC_java_util_ArrayList.method_add == NULL) 110 | goto fail; 111 | 112 | J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "java.util.ArrayList"); 113 | ret = 0; 114 | fail: 115 | return ret; 116 | } 117 | -------------------------------------------------------------------------------- /test/ref_c/java/util/ArrayList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__java_util_ArrayList__H 23 | #define J4A__java_util_ArrayList__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | jobject J4AC_java_util_ArrayList__ArrayList(JNIEnv *env); 28 | jobject J4AC_java_util_ArrayList__ArrayList__catchAll(JNIEnv *env); 29 | jobject J4AC_java_util_ArrayList__ArrayList__asGlobalRef__catchAll(JNIEnv *env); 30 | jboolean J4AC_java_util_ArrayList__add(JNIEnv *env, jobject thiz, jobject object); 31 | jboolean J4AC_java_util_ArrayList__add__catchAll(JNIEnv *env, jobject thiz, jobject object); 32 | int J4A_loadClass__J4AC_java_util_ArrayList(JNIEnv *env); 33 | 34 | #define J4A_HAVE_SIMPLE__J4AC_java_util_ArrayList 35 | 36 | #define J4AC_ArrayList__ArrayList J4AC_java_util_ArrayList__ArrayList 37 | #define J4AC_ArrayList__ArrayList__asGlobalRef__catchAll J4AC_java_util_ArrayList__ArrayList__asGlobalRef__catchAll 38 | #define J4AC_ArrayList__ArrayList__catchAll J4AC_java_util_ArrayList__ArrayList__catchAll 39 | #define J4AC_ArrayList__add J4AC_java_util_ArrayList__add 40 | #define J4AC_ArrayList__add__catchAll J4AC_java_util_ArrayList__add__catchAll 41 | #define J4A_loadClass__J4AC_ArrayList J4A_loadClass__J4AC_java_util_ArrayList 42 | 43 | #endif//J4A__java_util_ArrayList__H 44 | -------------------------------------------------------------------------------- /test/ref_c/java/util/ArrayList.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/java/util/ArrayList.h" -------------------------------------------------------------------------------- /test/ref_c/java/util/ArrayList.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(java_util_ArrayList); -------------------------------------------------------------------------------- /test/ref_c/test/ReturnPrimitive.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #include "ReturnPrimitive.h" 23 | 24 | typedef struct J4AC_test_ReturnPrimitive { 25 | jclass id; 26 | 27 | jmethodID method_getIntArray; 28 | jmethodID method_getFloatArray; 29 | jmethodID method_getDoubleArray; 30 | } J4AC_test_ReturnPrimitive; 31 | static J4AC_test_ReturnPrimitive class_J4AC_test_ReturnPrimitive; 32 | 33 | jint J4AC_test_ReturnPrimitive__getIntArray(JNIEnv *env, jobject thiz, jintArray iArr) 34 | { 35 | return (*env)->CallIntMethod(env, thiz, class_J4AC_test_ReturnPrimitive.method_getIntArray, iArr); 36 | } 37 | 38 | jint J4AC_test_ReturnPrimitive__getIntArray__catchAll(JNIEnv *env, jobject thiz, jintArray iArr) 39 | { 40 | jint ret_value = J4AC_test_ReturnPrimitive__getIntArray(env, thiz, iArr); 41 | if (J4A_ExceptionCheck__catchAll(env)) { 42 | return 0; 43 | } 44 | 45 | return ret_value; 46 | } 47 | 48 | jfloat J4AC_test_ReturnPrimitive__getFloatArray(JNIEnv *env, jobject thiz, jfloatArray fArr) 49 | { 50 | return (*env)->CallFloatMethod(env, thiz, class_J4AC_test_ReturnPrimitive.method_getFloatArray, fArr); 51 | } 52 | 53 | jfloat J4AC_test_ReturnPrimitive__getFloatArray__catchAll(JNIEnv *env, jobject thiz, jfloatArray fArr) 54 | { 55 | jfloat ret_value = J4AC_test_ReturnPrimitive__getFloatArray(env, thiz, fArr); 56 | if (J4A_ExceptionCheck__catchAll(env)) { 57 | return 0; 58 | } 59 | 60 | return ret_value; 61 | } 62 | 63 | jdouble J4AC_test_ReturnPrimitive__getDoubleArray(JNIEnv *env, jobject thiz, jdoubleArray iArr) 64 | { 65 | return (*env)->CallDoubleMethod(env, thiz, class_J4AC_test_ReturnPrimitive.method_getDoubleArray, iArr); 66 | } 67 | 68 | jdouble J4AC_test_ReturnPrimitive__getDoubleArray__catchAll(JNIEnv *env, jobject thiz, jdoubleArray iArr) 69 | { 70 | jdouble ret_value = J4AC_test_ReturnPrimitive__getDoubleArray(env, thiz, iArr); 71 | if (J4A_ExceptionCheck__catchAll(env)) { 72 | return 0; 73 | } 74 | 75 | return ret_value; 76 | } 77 | 78 | int J4A_loadClass__J4AC_test_ReturnPrimitive(JNIEnv *env) 79 | { 80 | int ret = -1; 81 | const char *J4A_UNUSED(name) = NULL; 82 | const char *J4A_UNUSED(sign) = NULL; 83 | jclass J4A_UNUSED(class_id) = NULL; 84 | int J4A_UNUSED(api_level) = 0; 85 | 86 | if (class_J4AC_test_ReturnPrimitive.id != NULL) 87 | return 0; 88 | 89 | sign = "test/ReturnPrimitive"; 90 | class_J4AC_test_ReturnPrimitive.id = J4A_FindClass__asGlobalRef__catchAll(env, sign); 91 | if (class_J4AC_test_ReturnPrimitive.id == NULL) 92 | goto fail; 93 | 94 | class_id = class_J4AC_test_ReturnPrimitive.id; 95 | name = "getIntArray"; 96 | sign = "([I)I"; 97 | class_J4AC_test_ReturnPrimitive.method_getIntArray = J4A_GetMethodID__catchAll(env, class_id, name, sign); 98 | if (class_J4AC_test_ReturnPrimitive.method_getIntArray == NULL) 99 | goto fail; 100 | 101 | class_id = class_J4AC_test_ReturnPrimitive.id; 102 | name = "getFloatArray"; 103 | sign = "([F)F"; 104 | class_J4AC_test_ReturnPrimitive.method_getFloatArray = J4A_GetMethodID__catchAll(env, class_id, name, sign); 105 | if (class_J4AC_test_ReturnPrimitive.method_getFloatArray == NULL) 106 | goto fail; 107 | 108 | class_id = class_J4AC_test_ReturnPrimitive.id; 109 | name = "getDoubleArray"; 110 | sign = "([D)D"; 111 | class_J4AC_test_ReturnPrimitive.method_getDoubleArray = J4A_GetMethodID__catchAll(env, class_id, name, sign); 112 | if (class_J4AC_test_ReturnPrimitive.method_getDoubleArray == NULL) 113 | goto fail; 114 | 115 | J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "test.ReturnPrimitive"); 116 | ret = 0; 117 | fail: 118 | return ret; 119 | } 120 | -------------------------------------------------------------------------------- /test/ref_c/test/ReturnPrimitive.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__test_ReturnPrimitive__H 23 | #define J4A__test_ReturnPrimitive__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | jint J4AC_test_ReturnPrimitive__getIntArray(JNIEnv *env, jobject thiz, jintArray iArr); 28 | jint J4AC_test_ReturnPrimitive__getIntArray__catchAll(JNIEnv *env, jobject thiz, jintArray iArr); 29 | jfloat J4AC_test_ReturnPrimitive__getFloatArray(JNIEnv *env, jobject thiz, jfloatArray fArr); 30 | jfloat J4AC_test_ReturnPrimitive__getFloatArray__catchAll(JNIEnv *env, jobject thiz, jfloatArray fArr); 31 | jdouble J4AC_test_ReturnPrimitive__getDoubleArray(JNIEnv *env, jobject thiz, jdoubleArray iArr); 32 | jdouble J4AC_test_ReturnPrimitive__getDoubleArray__catchAll(JNIEnv *env, jobject thiz, jdoubleArray iArr); 33 | int J4A_loadClass__J4AC_test_ReturnPrimitive(JNIEnv *env); 34 | 35 | #define J4A_HAVE_SIMPLE__J4AC_test_ReturnPrimitive 36 | 37 | #define J4AC_ReturnPrimitive__getIntArray J4AC_test_ReturnPrimitive__getIntArray 38 | #define J4AC_ReturnPrimitive__getIntArray__catchAll J4AC_test_ReturnPrimitive__getIntArray__catchAll 39 | #define J4AC_ReturnPrimitive__getFloatArray J4AC_test_ReturnPrimitive__getFloatArray 40 | #define J4AC_ReturnPrimitive__getFloatArray__catchAll J4AC_test_ReturnPrimitive__getFloatArray__catchAll 41 | #define J4AC_ReturnPrimitive__getDoubleArray J4AC_test_ReturnPrimitive__getDoubleArray 42 | #define J4AC_ReturnPrimitive__getDoubleArray__catchAll J4AC_test_ReturnPrimitive__getDoubleArray__catchAll 43 | #define J4A_loadClass__J4AC_ReturnPrimitive J4A_loadClass__J4AC_test_ReturnPrimitive 44 | 45 | #endif//J4A__test_ReturnPrimitive__H 46 | -------------------------------------------------------------------------------- /test/ref_c/test/ReturnPrimitive.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/test/ReturnPrimitive.h" -------------------------------------------------------------------------------- /test/ref_c/test/ReturnPrimitive.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(test_ReturnPrimitive); -------------------------------------------------------------------------------- /test/ref_c/tv/danmaku/ijk/media/player/IjkMediaPlayer.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/tv/danmaku/ijk/media/player/IjkMediaPlayer.h" -------------------------------------------------------------------------------- /test/ref_c/tv/danmaku/ijk/media/player/IjkMediaPlayer.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(tv_danmaku_ijk_media_player_IjkMediaPlayer); -------------------------------------------------------------------------------- /test/ref_c/tv/danmaku/ijk/media/player/misc/IMediaDataSource.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #include "IMediaDataSource.h" 23 | 24 | typedef struct J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource { 25 | jclass id; 26 | 27 | jmethodID method_readAt; 28 | jmethodID method_getSize; 29 | jmethodID method_close; 30 | } J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource; 31 | static J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource; 32 | 33 | jint J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__readAt(JNIEnv *env, jobject thiz, jlong position, jbyteArray buffer, jint offset, jint size) 34 | { 35 | return (*env)->CallIntMethod(env, thiz, class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_readAt, position, buffer, offset, size); 36 | } 37 | 38 | jint J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__readAt__catchAll(JNIEnv *env, jobject thiz, jlong position, jbyteArray buffer, jint offset, jint size) 39 | { 40 | jint ret_value = J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__readAt(env, thiz, position, buffer, offset, size); 41 | if (J4A_ExceptionCheck__catchAll(env)) { 42 | return 0; 43 | } 44 | 45 | return ret_value; 46 | } 47 | 48 | jlong J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__getSize(JNIEnv *env, jobject thiz) 49 | { 50 | return (*env)->CallLongMethod(env, thiz, class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_getSize); 51 | } 52 | 53 | jlong J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__getSize__catchAll(JNIEnv *env, jobject thiz) 54 | { 55 | jlong ret_value = J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__getSize(env, thiz); 56 | if (J4A_ExceptionCheck__catchAll(env)) { 57 | return 0; 58 | } 59 | 60 | return ret_value; 61 | } 62 | 63 | void J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__close(JNIEnv *env, jobject thiz) 64 | { 65 | (*env)->CallVoidMethod(env, thiz, class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_close); 66 | } 67 | 68 | void J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__close__catchAll(JNIEnv *env, jobject thiz) 69 | { 70 | J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__close(env, thiz); 71 | J4A_ExceptionCheck__catchAll(env); 72 | } 73 | 74 | int J4A_loadClass__J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource(JNIEnv *env) 75 | { 76 | int ret = -1; 77 | const char *J4A_UNUSED(name) = NULL; 78 | const char *J4A_UNUSED(sign) = NULL; 79 | jclass J4A_UNUSED(class_id) = NULL; 80 | int J4A_UNUSED(api_level) = 0; 81 | 82 | if (class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.id != NULL) 83 | return 0; 84 | 85 | sign = "tv/danmaku/ijk/media/player/misc/IMediaDataSource"; 86 | class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.id = J4A_FindClass__asGlobalRef__catchAll(env, sign); 87 | if (class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.id == NULL) 88 | goto fail; 89 | 90 | class_id = class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.id; 91 | name = "readAt"; 92 | sign = "(J[BII)I"; 93 | class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_readAt = J4A_GetMethodID__catchAll(env, class_id, name, sign); 94 | if (class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_readAt == NULL) 95 | goto fail; 96 | 97 | class_id = class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.id; 98 | name = "getSize"; 99 | sign = "()J"; 100 | class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_getSize = J4A_GetMethodID__catchAll(env, class_id, name, sign); 101 | if (class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_getSize == NULL) 102 | goto fail; 103 | 104 | class_id = class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.id; 105 | name = "close"; 106 | sign = "()V"; 107 | class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_close = J4A_GetMethodID__catchAll(env, class_id, name, sign); 108 | if (class_J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource.method_close == NULL) 109 | goto fail; 110 | 111 | J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "tv.danmaku.ijk.media.player.misc.IMediaDataSource"); 112 | ret = 0; 113 | fail: 114 | return ret; 115 | } 116 | -------------------------------------------------------------------------------- /test/ref_c/tv/danmaku/ijk/media/player/misc/IMediaDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Zhang Rui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * https://github.com/Bilibili/jni4android 19 | * This file is automatically generated by jni4android, do not modify. 20 | */ 21 | 22 | #ifndef J4A__tv_danmaku_ijk_media_player_misc_IMediaDataSource__H 23 | #define J4A__tv_danmaku_ijk_media_player_misc_IMediaDataSource__H 24 | 25 | #include "j4a/j4a_base.h" 26 | 27 | jint J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__readAt(JNIEnv *env, jobject thiz, jlong position, jbyteArray buffer, jint offset, jint size); 28 | jint J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__readAt__catchAll(JNIEnv *env, jobject thiz, jlong position, jbyteArray buffer, jint offset, jint size); 29 | jlong J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__getSize(JNIEnv *env, jobject thiz); 30 | jlong J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__getSize__catchAll(JNIEnv *env, jobject thiz); 31 | void J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__close(JNIEnv *env, jobject thiz); 32 | void J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__close__catchAll(JNIEnv *env, jobject thiz); 33 | int J4A_loadClass__J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource(JNIEnv *env); 34 | 35 | #define J4A_HAVE_SIMPLE__J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource 36 | 37 | #define J4AC_IMediaDataSource__readAt J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__readAt 38 | #define J4AC_IMediaDataSource__readAt__catchAll J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__readAt__catchAll 39 | #define J4AC_IMediaDataSource__getSize J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__getSize 40 | #define J4AC_IMediaDataSource__getSize__catchAll J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__getSize__catchAll 41 | #define J4AC_IMediaDataSource__close J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__close 42 | #define J4AC_IMediaDataSource__close__catchAll J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource__close__catchAll 43 | #define J4A_loadClass__J4AC_IMediaDataSource J4A_loadClass__J4AC_tv_danmaku_ijk_media_player_misc_IMediaDataSource 44 | 45 | #endif//J4A__tv_danmaku_ijk_media_player_misc_IMediaDataSource__H 46 | -------------------------------------------------------------------------------- /test/ref_c/tv/danmaku/ijk/media/player/misc/IMediaDataSource.include.j4a: -------------------------------------------------------------------------------- 1 | #include "j4a/class/tv/danmaku/ijk/media/player/misc/IMediaDataSource.h" -------------------------------------------------------------------------------- /test/ref_c/tv/danmaku/ijk/media/player/misc/IMediaDataSource.loader.j4a: -------------------------------------------------------------------------------- 1 | J4A_LOAD_CLASS(tv_danmaku_ijk_media_player_misc_IMediaDataSource); -------------------------------------------------------------------------------- /tools/build_contrib.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # 3 | # copyright (c) 2015 Zhang Rui 4 | # 5 | # This file is part of jni4android. 6 | # 7 | # jni4android is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Lesser General Public 9 | # License as published by the Free Software Foundation; either 10 | # version 2.1 of the License, or (at your option) any later version. 11 | # 12 | # jni4android is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with jni4android; if not, write to the Free Software 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | #/ 21 | 22 | MOD_NAME=$1 23 | MOD_VERSION=$2 24 | MOD_URL=$3 25 | MOD_VERSION_NAME=$MOD_NAME-$MOD_VERSION 26 | MOD_ROOT_DIR=`pwd` 27 | 28 | if [ -z $1 -o -z $2 ]; then 29 | echo "Missing module name or url\"$1\"." 30 | exit 1 31 | fi 32 | 33 | MOD_TARBALL_NAME=$(echo $MOD_URL | sed 's/.*\///' | sed 's/[\?\#].*//') 34 | MOD_TARBALL_DIR=contrib/tarballs 35 | MOD_TARBALL_PATH=$MOD_TARBALL_DIR/$MOD_TARBALL_NAME 36 | MOD_TARBALL_TEMP_PATH=$MOD_TARBALL_DIR/$MOD_TARBALL_NAME.tmp 37 | 38 | MOD_BUILD_DIR=contrib/build 39 | MOD_BUILD_SRC_DIR=$MOD_BUILD_DIR/src 40 | MOD_BUILD_SRC_PATH=$MOD_BUILD_SRC_DIR/$MOD_NAME 41 | MOD_BUILD_SRC_PATH=$MOD_BUILD_SRC_DIR/$MOD_NAME 42 | MOD_BUILD_SRC_VERSION_PATH=$MOD_BUILD_SRC_DIR/$MOD_VERSION_NAME 43 | 44 | MOD_BUILD_EXTRACT_NAME=$MOD_NAME-$MOD_VERSION 45 | MOD_BUILD_EXTRACT_PATH=$MOD_BUILD_SRC_DIR/$MOD_BUILD_EXTRACT_NAME 46 | 47 | ######################################## 48 | # download and extract 49 | echo " > check contrib $MOD_NAME" 50 | mkdir -p $MOD_TARBALL_DIR 51 | mkdir -p $MOD_BUILD_SRC_DIR 52 | 53 | if [ ! -d $MOD_BUILD_SRC_VERSION_PATH ]; then 54 | if [ ! -f $MOD_TARBALL_PATH ]; then 55 | echo "download from $MOD_URL" 56 | wget -O $MOD_TARBALL_TEMP_PATH $MOD_URL 57 | mv $MOD_TARBALL_TEMP_PATH $MOD_TARBALL_PATH 58 | fi 59 | 60 | if [ ! -d $MOD_BUILD_SRC_VERSION_PATH ]; then 61 | echo "extract $MOD_TARBALL_PATH" 62 | tar -zxvf $MOD_TARBALL_PATH -C $MOD_BUILD_SRC_DIR 63 | fi 64 | 65 | if [ -h $MOD_BUILD_SRC_PATH ]; then 66 | rm $MOD_BUILD_SRC_PATH 67 | fi 68 | fi 69 | 70 | if [ ! -h $MOD_BUILD_SRC_PATH ]; then 71 | echo "link $MOD_BUILD_SRC_VERSION_PATH" 72 | cd $MOD_BUILD_SRC_DIR 73 | ln -s $MOD_VERSION_NAME $MOD_NAME 74 | cd - 75 | fi 76 | 77 | ######################################## 78 | # download and extract 79 | echo " > build contrib $MOD_NAME" 80 | 81 | MOD_BUILD_PREFIX=$MOD_ROOT_DIR/$MOD_BUILD_DIR 82 | MOD_BUILD_BIN_DIR=$MOD_ROOT_DIR/$MOD_BUILD_DIR/bin 83 | MOD_BUILD_INC_DIR=$MOD_ROOT_DIR/$MOD_BUILD_DIR/include 84 | MOD_BUILD_LIB_DIR=$MOD_ROOT_DIR/$MOD_BUILD_DIR/lib 85 | MOD_BUILD_OBJ_DIR=$MOD_ROOT_DIR/$MOD_BUILD_DIR/obj 86 | 87 | mkdir -p $MOD_BUILD_BIN_DIR 88 | mkdir -p $MOD_BUILD_INC_DIR 89 | mkdir -p $MOD_BUILD_LIB_DIR 90 | mkdir -p $MOD_BUILD_OBJ_DIR 91 | 92 | cd $MOD_BUILD_SRC_PATH 93 | ./configure --prefix=$MOD_BUILD_PREFIX 94 | make install 95 | cd - 96 | -------------------------------------------------------------------------------- /xcode/jni4android.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /xcode/jni4android/jni4android.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /xcode/jni4android/jni4android/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // jni4android 4 | // 5 | // Created by Zhang Rui on 16/1/5. 6 | // Copyright © 2016年 Zhang Rui. All rights reserved. 7 | // 8 | 9 | #include 10 | 11 | int main(int argc, const char * argv[]) { 12 | // insert code here... 13 | std::cout << "Hello, World!\n"; 14 | return 0; 15 | } 16 | --------------------------------------------------------------------------------