| Kenny Root | bd393b7 | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2006 The Android Open Source Project | 
|  | 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 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | import java.io.PrintStream; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | import java.util.ArrayList; | 
|  | 19 | import java.util.HashSet; | 
|  | 20 | import java.util.Iterator; | 
|  | 21 | import java.util.List; | 
|  | 22 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 23 | public class JniCodeEmitter { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | static final boolean mUseCPlusPlus = true; | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 26 | protected boolean mUseContextPointer = true; | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 27 | protected boolean mUseStaticMethods = false; | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 28 | protected boolean mUseSimpleMethodNames = false; | 
|  | 29 | protected boolean mUseHideCommentForAPI = false; | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 30 | protected String mClassPathName; | 
|  | 31 | protected ParameterChecker mChecker; | 
|  | 32 | protected List<String> nativeRegistrations = new ArrayList<String>(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | boolean needsExit; | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 34 | protected static String indent = "    "; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | HashSet<String> mFunctionsEmitted = new HashSet<String>(); | 
|  | 36 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 37 | public static String getJniName(JType jType) { | 
|  | 38 | String jniName = ""; | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 39 | if (jType.isEGLHandle()) { | 
|  | 40 | return (jType.isArray() ? "[" : "" ) + "Landroid/opengl/" + jType.getBaseType() + ";"; | 
|  | 41 | } else if (jType.isClass()) { | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 42 | return "L" + jType.getBaseType() + ";"; | 
|  | 43 | } else if (jType.isArray()) { | 
|  | 44 | jniName = "["; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | } | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 46 |  | 
|  | 47 | String baseType = jType.getBaseType(); | 
|  | 48 | if (baseType.equals("int")) { | 
|  | 49 | jniName += "I"; | 
|  | 50 | } else if (baseType.equals("float")) { | 
|  | 51 | jniName += "F"; | 
|  | 52 | } else if (baseType.equals("boolean")) { | 
|  | 53 | jniName += "Z"; | 
|  | 54 | } else if (baseType.equals("short")) { | 
|  | 55 | jniName += "S"; | 
|  | 56 | } else if (baseType.equals("long")) { | 
| Andy McFadden | 7284145 | 2013-03-01 16:25:32 -0800 | [diff] [blame] | 57 | jniName += "J"; | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 58 | } else if (baseType.equals("byte")) { | 
|  | 59 | jniName += "B"; | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 60 | } else if (baseType.equals("String")) { | 
|  | 61 | jniName += "Ljava/lang/String;"; | 
|  | 62 | } else if (baseType.equals("void")) { | 
|  | 63 | // nothing. | 
|  | 64 | } else { | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 65 | throw new RuntimeException("Unknown primitive basetype " + baseType); | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 66 | } | 
|  | 67 | return jniName; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 70 | public void emitCode(CFunc cfunc, String original, | 
|  | 71 | PrintStream javaInterfaceStream, | 
|  | 72 | PrintStream javaImplStream, | 
|  | 73 | PrintStream cStream) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | JFunc jfunc; | 
|  | 75 | String signature; | 
|  | 76 | boolean duplicate; | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 77 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | if (cfunc.hasTypedPointerArg()) { | 
|  | 79 | jfunc = JFunc.convert(cfunc, true); | 
|  | 80 |  | 
|  | 81 | // Don't emit duplicate functions | 
|  | 82 | // These may appear because they are defined in multiple | 
|  | 83 | // Java interfaces (e.g., GL11/GL11ExtensionPack) | 
|  | 84 | signature = jfunc.toString(); | 
|  | 85 | duplicate = false; | 
|  | 86 | if (mFunctionsEmitted.contains(signature)) { | 
|  | 87 | duplicate = true; | 
|  | 88 | } else { | 
|  | 89 | mFunctionsEmitted.add(signature); | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | if (!duplicate) { | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 93 | emitNativeDeclaration(jfunc, javaImplStream); | 
|  | 94 | emitJavaCode(jfunc, javaImplStream); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | } | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 96 | if (javaInterfaceStream != null) { | 
|  | 97 | emitJavaInterfaceCode(jfunc, javaInterfaceStream); | 
|  | 98 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | if (!duplicate) { | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 100 | emitJniCode(jfunc, cStream); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | } | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 102 | // Don't create IOBuffer versions of the EGL functions | 
|  | 103 | if (cfunc.hasEGLHandleArg()) { | 
|  | 104 | return; | 
|  | 105 | } | 
| Courtney Goeltzenleuchter | b28648c | 2018-07-18 09:38:47 -0600 | [diff] [blame] | 106 | // eglGetPlatformDisplay does not have any EGLHandleArgs | 
|  | 107 | // but we do not want to create IOBuffers of this, so | 
|  | 108 | // exit | 
|  | 109 | if (cfunc.getName().equals("eglGetPlatformDisplay")) { | 
|  | 110 | return; | 
|  | 111 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | } | 
|  | 113 |  | 
|  | 114 | jfunc = JFunc.convert(cfunc, false); | 
|  | 115 |  | 
|  | 116 | signature = jfunc.toString(); | 
|  | 117 | duplicate = false; | 
|  | 118 | if (mFunctionsEmitted.contains(signature)) { | 
|  | 119 | duplicate = true; | 
|  | 120 | } else { | 
|  | 121 | mFunctionsEmitted.add(signature); | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 | if (!duplicate) { | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 125 | emitNativeDeclaration(jfunc, javaImplStream); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | } | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 127 | if (javaInterfaceStream != null) { | 
|  | 128 | emitJavaInterfaceCode(jfunc, javaInterfaceStream); | 
|  | 129 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | if (!duplicate) { | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 131 | emitJavaCode(jfunc, javaImplStream); | 
|  | 132 | emitJniCode(jfunc, cStream); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | } | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | public void emitNativeDeclaration(JFunc jfunc, PrintStream out) { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 137 | if (mUseHideCommentForAPI) { | 
|  | 138 | out.println("    /* @hide C function " + jfunc.getCFunc().getOriginal() + " */"); | 
|  | 139 | out.println(); | 
|  | 140 | } else { | 
|  | 141 | out.println("    // C function " + jfunc.getCFunc().getOriginal()); | 
|  | 142 | out.println(); | 
|  | 143 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 |  | 
|  | 145 | emitFunction(jfunc, out, true, false); | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | public void emitJavaInterfaceCode(JFunc jfunc, PrintStream out) { | 
|  | 149 | emitFunction(jfunc, out, false, true); | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | public void emitJavaCode(JFunc jfunc, PrintStream out) { | 
|  | 153 | emitFunction(jfunc, out, false, false); | 
|  | 154 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 155 |  | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 156 | boolean isPointerFunc(JFunc jfunc) { | 
|  | 157 | String name = jfunc.getName(); | 
|  | 158 | return (name.endsWith("Pointer") || name.endsWith("PointerOES")) | 
|  | 159 | && jfunc.getCFunc().hasPointerArg(); | 
|  | 160 | } | 
|  | 161 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 162 | void emitFunctionCall(JFunc jfunc, PrintStream out, String iii, boolean grabArray) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | boolean isVoid = jfunc.getType().isVoid(); | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 164 | boolean isPointerFunc = isPointerFunc(jfunc); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 |  | 
|  | 166 | if (!isVoid) { | 
|  | 167 | out.println(iii + | 
|  | 168 | jfunc.getType() + " _returnValue;"); | 
|  | 169 | } | 
|  | 170 | out.println(iii + | 
|  | 171 | (isVoid ? "" : "_returnValue = ") + | 
|  | 172 | jfunc.getName() + | 
|  | 173 | (isPointerFunc ? "Bounds" : "" ) + | 
|  | 174 | "("); | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 175 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | int numArgs = jfunc.getNumArgs(); | 
|  | 177 | for (int i = 0; i < numArgs; i++) { | 
|  | 178 | String argName = jfunc.getArgName(i); | 
|  | 179 | JType argType = jfunc.getArgType(i); | 
|  | 180 |  | 
|  | 181 | if (grabArray && argType.isTypedBuffer()) { | 
|  | 182 | String typeName = argType.getBaseType(); | 
|  | 183 | typeName = typeName.substring(9, typeName.length() - 6); | 
|  | 184 | out.println(iii + indent + "get" + typeName + "Array(" + argName + "),"); | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 185 | out.print(iii + indent + "getOffset(" + argName + ")"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | } else { | 
|  | 187 | out.print(iii + indent + argName); | 
|  | 188 | } | 
|  | 189 | if (i == numArgs - 1) { | 
|  | 190 | if (isPointerFunc) { | 
|  | 191 | out.println(","); | 
|  | 192 | out.println(iii + indent + argName + ".remaining()"); | 
|  | 193 | } else { | 
|  | 194 | out.println(); | 
|  | 195 | } | 
|  | 196 | } else { | 
|  | 197 | out.println(","); | 
|  | 198 | } | 
|  | 199 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 200 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | out.println(iii + ");"); | 
|  | 202 | } | 
|  | 203 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 204 | void printIfcheckPostamble(PrintStream out, boolean isBuffer, boolean emitExceptionCheck, | 
|  | 205 | String iii) { | 
| Mathias Agopian | bf13ba5 | 2013-02-22 19:34:06 -0800 | [diff] [blame] | 206 | printIfcheckPostamble(out, isBuffer, emitExceptionCheck, | 
|  | 207 | "offset", "_remaining", iii); | 
|  | 208 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 210 | void printIfcheckPostamble(PrintStream out, boolean isBuffer, boolean emitExceptionCheck, | 
|  | 211 | String offset, String remaining, String iii) { | 
| Mathias Agopian | bf13ba5 | 2013-02-22 19:34:06 -0800 | [diff] [blame] | 212 | out.println(iii + "    default:"); | 
|  | 213 | out.println(iii + "        _needed = 1;"); | 
|  | 214 | out.println(iii + "        break;"); | 
|  | 215 | out.println(iii + "}"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 |  | 
| Mathias Agopian | bf13ba5 | 2013-02-22 19:34:06 -0800 | [diff] [blame] | 217 | out.println(iii + "if (" + remaining + " < _needed) {"); | 
|  | 218 | out.println(iii + indent + "_exception = 1;"); | 
|  | 219 | out.println(iii + indent + | 
|  | 220 | "_exceptionType = \"java/lang/IllegalArgumentException\";"); | 
|  | 221 | out.println(iii + indent + | 
|  | 222 | "_exceptionMessage = \"" + | 
|  | 223 | (isBuffer ? "remaining()" : "length - " + offset) + | 
|  | 224 | " < needed\";"); | 
|  | 225 | out.println(iii + indent + "goto exit;"); | 
|  | 226 | out.println(iii + "}"); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 227 |  | 
| Mathias Agopian | bf13ba5 | 2013-02-22 19:34:06 -0800 | [diff] [blame] | 228 | needsExit = true; | 
|  | 229 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 231 | boolean isNullAllowed(CFunc cfunc, String cname) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 233 | int index = 1; | 
|  | 234 | if (checks != null) { | 
|  | 235 | while (index < checks.length) { | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 236 | if (checks[index].equals("nullAllowed") && | 
|  | 237 | checks[index + 1].equals(cname)) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | return true; | 
|  | 239 | } else { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 240 | index = skipOneCheck(checks, index); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | } | 
|  | 242 | } | 
|  | 243 | } | 
|  | 244 | return false; | 
|  | 245 | } | 
|  | 246 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 247 | boolean hasCheckTest(CFunc cfunc) { | 
|  | 248 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 249 | int index = 1; | 
|  | 250 | if (checks != null) { | 
|  | 251 | while (index < checks.length) { | 
|  | 252 | if (checks[index].startsWith("check")) { | 
|  | 253 | return true; | 
|  | 254 | } else { | 
|  | 255 | index = skipOneCheck(checks, index); | 
|  | 256 | } | 
|  | 257 | } | 
|  | 258 | } | 
|  | 259 | return false; | 
|  | 260 | } | 
|  | 261 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 262 | boolean hasCheckTest(CFunc cfunc, String cname) { | 
|  | 263 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 264 | int index = 1; | 
|  | 265 | if (checks != null) { | 
|  | 266 | while (index < checks.length) { | 
|  | 267 | if (checks[index].startsWith("check") && | 
|  | 268 | cname != null && cname.equals(checks[index + 1])) { | 
|  | 269 | return true; | 
|  | 270 | } else { | 
|  | 271 | index = skipOneCheck(checks, index); | 
|  | 272 | } | 
|  | 273 | } | 
|  | 274 | } | 
|  | 275 | return false; | 
|  | 276 | } | 
|  | 277 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 278 | boolean hasIfTest(CFunc cfunc) { | 
|  | 279 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 280 | int index = 1; | 
|  | 281 | if (checks != null) { | 
|  | 282 | while (index < checks.length) { | 
|  | 283 | if (checks[index].startsWith("ifcheck")) { | 
|  | 284 | return true; | 
|  | 285 | } else { | 
|  | 286 | index = skipOneCheck(checks, index); | 
|  | 287 | } | 
|  | 288 | } | 
|  | 289 | } | 
|  | 290 | return false; | 
|  | 291 | } | 
|  | 292 |  | 
|  | 293 | int skipOneCheck(String[] checks, int index) { | 
|  | 294 | if (checks[index].equals("return")) { | 
|  | 295 | index += 2; | 
|  | 296 | } else if (checks[index].startsWith("check")) { | 
|  | 297 | index += 3; | 
|  | 298 | } else if (checks[index].startsWith("sentinel")) { | 
|  | 299 | index += 3; | 
|  | 300 | } else if (checks[index].equals("ifcheck")) { | 
|  | 301 | index += 5; | 
|  | 302 | } else if (checks[index].equals("unsupported")) { | 
|  | 303 | index += 1; | 
|  | 304 | } else if (checks[index].equals("requires")) { | 
|  | 305 | index += 2; | 
|  | 306 | } else if (checks[index].equals("nullAllowed")) { | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 307 | index += 2; | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 308 | } else { | 
|  | 309 | System.out.println("Error: unknown keyword \"" + | 
|  | 310 | checks[index] + "\""); | 
|  | 311 | System.exit(0); | 
|  | 312 | } | 
|  | 313 |  | 
|  | 314 | return index; | 
|  | 315 | } | 
|  | 316 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | String getErrorReturnValue(CFunc cfunc) { | 
|  | 318 | CType returnType = cfunc.getType(); | 
|  | 319 | boolean isVoid = returnType.isVoid(); | 
|  | 320 | if (isVoid) { | 
|  | 321 | return null; | 
|  | 322 | } | 
|  | 323 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 324 | if (returnType.getBaseType().startsWith("EGL")) { | 
|  | 325 | return "(" + returnType.getDeclaration() + ") 0"; | 
|  | 326 | } | 
|  | 327 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 329 |  | 
|  | 330 | int index = 1; | 
|  | 331 | if (checks != null) { | 
|  | 332 | while (index < checks.length) { | 
|  | 333 | if (checks[index].equals("return")) { | 
|  | 334 | return checks[index + 1]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | } else { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 336 | index = skipOneCheck(checks, index); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | } | 
|  | 338 | } | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 | return null; | 
|  | 342 | } | 
|  | 343 |  | 
|  | 344 | boolean isUnsupportedFunc(CFunc cfunc) { | 
|  | 345 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 346 | int index = 1; | 
|  | 347 | if (checks != null) { | 
|  | 348 | while (index < checks.length) { | 
|  | 349 | if (checks[index].equals("unsupported")) { | 
|  | 350 | return true; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | } else { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 352 | index = skipOneCheck(checks, index); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | } | 
|  | 354 | } | 
|  | 355 | } | 
|  | 356 | return false; | 
|  | 357 | } | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 358 |  | 
| Jack Palevich | e44e45c | 2010-01-28 20:28:32 +0800 | [diff] [blame] | 359 | String isRequiresFunc(CFunc cfunc) { | 
|  | 360 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 361 | int index = 1; | 
|  | 362 | if (checks != null) { | 
|  | 363 | while (index < checks.length) { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 364 | if (checks[index].equals("requires")) { | 
| Jack Palevich | e44e45c | 2010-01-28 20:28:32 +0800 | [diff] [blame] | 365 | return checks[index+1]; | 
| Jack Palevich | e44e45c | 2010-01-28 20:28:32 +0800 | [diff] [blame] | 366 | } else { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 367 | index = skipOneCheck(checks, index); | 
| Jack Palevich | e44e45c | 2010-01-28 20:28:32 +0800 | [diff] [blame] | 368 | } | 
|  | 369 | } | 
|  | 370 | } | 
|  | 371 | return null; | 
|  | 372 | } | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 373 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | void emitNativeBoundsChecks(CFunc cfunc, String cname, PrintStream out, | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 375 | boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 |  | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 377 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 |  | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 379 | boolean lastWasIfcheck = false; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 |  | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 381 | int index = 1; | 
|  | 382 | if (checks != null) { | 
|  | 383 | while (index < checks.length) { | 
|  | 384 | if (checks[index].startsWith("check")) { | 
|  | 385 | if (lastWasIfcheck) { | 
|  | 386 | printIfcheckPostamble(out, isBuffer, emitExceptionCheck, | 
|  | 387 | offset, remaining, iii); | 
|  | 388 | } | 
|  | 389 | lastWasIfcheck = false; | 
|  | 390 | if (cname != null && !cname.equals(checks[index + 1])) { | 
|  | 391 | index += 3; | 
|  | 392 | continue; | 
|  | 393 | } | 
|  | 394 | out.println(iii + "if (" + remaining + " < " + checks[index + 2] + ") {"); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 395 | out.println(iii + indent + "_exception = 1;"); | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 396 | String exceptionClassName = "java/lang/IllegalArgumentException"; | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 397 | // If the "check" keyword was of the form | 
|  | 398 | // "check_<class name>", use the class name in the | 
|  | 399 | // exception to be thrown | 
|  | 400 | int underscore = checks[index].indexOf('_'); | 
|  | 401 | if (underscore >= 0) { | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 402 | String abbr = checks[index].substring(underscore + 1); | 
|  | 403 | if (abbr.equals("AIOOBE")) { | 
|  | 404 | exceptionClassName = "java/lang/ArrayIndexOutOfBoundsException"; | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 405 | } else { | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 406 | throw new RuntimeException("unknown exception abbreviation: " + abbr); | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 407 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | } | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 409 | out.println(iii + indent + | 
|  | 410 | "_exceptionType = \""+exceptionClassName+"\";"); | 
|  | 411 | out.println(iii + indent + | 
|  | 412 | "_exceptionMessage = \"" + | 
|  | 413 | (isBuffer ? "remaining()" : "length - " + | 
|  | 414 | offset) + " < " + checks[index + 2] + | 
|  | 415 | " < needed\";"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 |  | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 417 | out.println(iii + indent + "goto exit;"); | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 418 | out.println(iii + "}"); | 
|  | 419 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 420 | needsExit = true; | 
|  | 421 |  | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 422 | index += 3; | 
|  | 423 | } else if (checks[index].equals("ifcheck")) { | 
|  | 424 | String[] matches = checks[index + 4].split(","); | 
|  | 425 |  | 
|  | 426 | if (!lastWasIfcheck) { | 
|  | 427 | out.println(iii + "int _needed;"); | 
|  | 428 | out.println(iii + "switch (" + checks[index + 3] + ") {"); | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 | for (int i = 0; i < matches.length; i++) { | 
|  | 432 | out.println("#if defined(" + matches[i] + ")"); | 
|  | 433 | out.println(iii + "    case " + matches[i] + ":"); | 
|  | 434 | out.println("#endif // defined(" + matches[i] + ")"); | 
|  | 435 | } | 
|  | 436 | out.println(iii + "        _needed = " + checks[index + 2] + ";"); | 
|  | 437 | out.println(iii + "        break;"); | 
|  | 438 |  | 
|  | 439 | lastWasIfcheck = true; | 
|  | 440 | index += 5; | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 441 | } else { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 442 | index = skipOneCheck(checks, index); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | } | 
|  | 444 | } | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 445 | } | 
|  | 446 |  | 
|  | 447 | if (lastWasIfcheck) { | 
|  | 448 | printIfcheckPostamble(out, isBuffer, emitExceptionCheck, iii); | 
|  | 449 | } | 
|  | 450 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 452 | void emitSentinelCheck(CFunc cfunc, String cname, PrintStream out, | 
|  | 453 | boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) { | 
|  | 454 |  | 
|  | 455 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 456 |  | 
|  | 457 | int index = 1; | 
|  | 458 | if (checks != null) { | 
|  | 459 | while (index < checks.length) { | 
|  | 460 | if (checks[index].startsWith("sentinel")) { | 
|  | 461 | if (cname != null && !cname.equals(checks[index + 1])) { | 
|  | 462 | index += 3; | 
|  | 463 | continue; | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | out.println(iii + cname + "_sentinel = false;"); | 
|  | 467 | out.println(iii + "for (int i = " + remaining + | 
|  | 468 | " - 1; i >= 0; i--)  {"); | 
|  | 469 | out.println(iii + indent + "if (" + cname + | 
|  | 470 | "[i] == " + checks[index + 2] + "){"); | 
|  | 471 | out.println(iii + indent + indent + | 
|  | 472 | cname + "_sentinel = true;"); | 
|  | 473 | out.println(iii + indent + indent + "break;"); | 
|  | 474 | out.println(iii + indent + "}"); | 
|  | 475 | out.println(iii + "}"); | 
|  | 476 | out.println(iii + | 
|  | 477 | "if (" + cname + "_sentinel == false) {"); | 
|  | 478 | out.println(iii + indent + "_exception = 1;"); | 
|  | 479 | out.println(iii + indent + | 
|  | 480 | "_exceptionType = \"java/lang/IllegalArgumentException\";"); | 
|  | 481 | out.println(iii + indent + "_exceptionMessage = \"" + cname + | 
|  | 482 | " must contain " + checks[index + 2] + "!\";"); | 
|  | 483 | out.println(iii + indent + "goto exit;"); | 
|  | 484 | out.println(iii + "}"); | 
|  | 485 |  | 
|  | 486 | needsExit = true; | 
|  | 487 | index += 3; | 
|  | 488 | } else { | 
|  | 489 | index = skipOneCheck(checks, index); | 
|  | 490 | } | 
|  | 491 | } | 
|  | 492 | } | 
|  | 493 | } | 
|  | 494 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 495 | void emitStringCheck(CFunc cfunc, String cname, PrintStream out, String iii) { | 
|  | 496 |  | 
|  | 497 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 498 |  | 
|  | 499 | int index = 1; | 
|  | 500 | if (checks != null) { | 
|  | 501 | while (index < checks.length) { | 
|  | 502 | if (checks[index].startsWith("check")) { | 
|  | 503 | if (cname != null && !cname.equals(checks[index + 1])) { | 
|  | 504 | index += 3; | 
|  | 505 | continue; | 
|  | 506 | } | 
|  | 507 | out.println(iii + "_stringlen = _env->GetStringUTFLength(" + cname + ");"); | 
|  | 508 | out.println(iii + "if (" + checks[index + 2] + " > _stringlen) {"); | 
|  | 509 | out.println(iii + indent + "_exception = 1;"); | 
|  | 510 | out.println(iii + indent + | 
|  | 511 | "_exceptionType = \"java/lang/ArrayIndexOutOfBoundsException\";"); | 
|  | 512 | out.println(iii + indent + | 
|  | 513 | "_exceptionMessage = \"length of " + cname + " is shorter than " + | 
|  | 514 | checks[index + 2] + " argument\";"); | 
|  | 515 | out.println(iii + indent + "goto exit;"); | 
|  | 516 | out.println(iii + "}"); | 
|  | 517 | index += 3; | 
|  | 518 | needsExit = true; | 
|  | 519 | } else { | 
|  | 520 | index = skipOneCheck(checks, index); | 
|  | 521 | } | 
|  | 522 | } | 
|  | 523 | } | 
|  | 524 | } | 
|  | 525 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 526 | void emitLocalVariablesForSentinel(CFunc cfunc, PrintStream out) { | 
|  | 527 |  | 
|  | 528 | String[] checks = mChecker.getChecks(cfunc.getName()); | 
|  | 529 |  | 
|  | 530 | int index = 1; | 
|  | 531 | if (checks != null) { | 
|  | 532 | while (index < checks.length) { | 
|  | 533 | if (checks[index].startsWith("sentinel")) { | 
|  | 534 | String cname = checks[index + 1]; | 
|  | 535 | out.println(indent + "bool " + cname + "_sentinel = false;"); | 
|  | 536 |  | 
|  | 537 | index += 3; | 
|  | 538 |  | 
|  | 539 | } else { | 
|  | 540 | index = skipOneCheck(checks, index); | 
|  | 541 | } | 
|  | 542 | } | 
|  | 543 | } | 
|  | 544 | } | 
|  | 545 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 546 | boolean hasNonConstArg(JFunc jfunc, CFunc cfunc, List<Integer> nonPrimitiveArgs) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | if (nonPrimitiveArgs.size() > 0) { | 
|  | 548 | for (int i = nonPrimitiveArgs.size() - 1; i >= 0; i--) { | 
|  | 549 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
|  | 550 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 551 | if (jfunc.getArgType(idx).isArray()) { | 
|  | 552 | if (!cfunc.getArgType(cIndex).isConst()) { | 
|  | 553 | return true; | 
|  | 554 | } | 
|  | 555 | } else if (jfunc.getArgType(idx).isBuffer()) { | 
|  | 556 | if (!cfunc.getArgType(cIndex).isConst()) { | 
|  | 557 | return true; | 
|  | 558 | } | 
|  | 559 | } | 
|  | 560 | } | 
|  | 561 | } | 
|  | 562 |  | 
|  | 563 | return false; | 
|  | 564 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 565 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | /** | 
|  | 567 | * Emit a function in several variants: | 
|  | 568 | * | 
|  | 569 | * if nativeDecl: public native <returntype> func(args); | 
|  | 570 | * | 
|  | 571 | * if !nativeDecl: | 
|  | 572 | *   if interfaceDecl:  public <returntype> func(args); | 
|  | 573 | *   if !interfaceDecl: public <returntype> func(args) { body } | 
|  | 574 | */ | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 575 | void emitFunction(JFunc jfunc, PrintStream out, boolean nativeDecl, boolean interfaceDecl) { | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 576 | boolean isPointerFunc = isPointerFunc(jfunc); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 |  | 
|  | 578 | if (!nativeDecl && !interfaceDecl && !isPointerFunc) { | 
|  | 579 | // If it's not a pointer function, we've already emitted it | 
|  | 580 | // with nativeDecl == true | 
|  | 581 | return; | 
|  | 582 | } | 
|  | 583 |  | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 584 | String maybeStatic = mUseStaticMethods ? "static " : ""; | 
|  | 585 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | if (isPointerFunc) { | 
|  | 587 | out.println(indent + | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 588 | (nativeDecl ? "private " + maybeStatic +"native " : | 
|  | 589 | (interfaceDecl ? "" : "public ") + maybeStatic) + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | jfunc.getType() + " " + | 
|  | 591 | jfunc.getName() + | 
|  | 592 | (nativeDecl ? "Bounds" : "") + | 
|  | 593 | "("); | 
|  | 594 | } else { | 
|  | 595 | out.println(indent + | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 596 | (nativeDecl ? "public " + maybeStatic +"native " : | 
|  | 597 | (interfaceDecl ? "" : "public ") + maybeStatic) + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | jfunc.getType() + " " + | 
|  | 599 | jfunc.getName() + | 
|  | 600 | "("); | 
|  | 601 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 602 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | int numArgs = jfunc.getNumArgs(); | 
|  | 604 | for (int i = 0; i < numArgs; i++) { | 
|  | 605 | String argName = jfunc.getArgName(i); | 
|  | 606 | JType argType = jfunc.getArgType(i); | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 607 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | out.print(indent + indent + argType + " " + argName); | 
|  | 609 | if (i == numArgs - 1) { | 
|  | 610 | if (isPointerFunc && nativeDecl) { | 
|  | 611 | out.println(","); | 
|  | 612 | out.println(indent + indent + "int remaining"); | 
|  | 613 | } else { | 
|  | 614 | out.println(); | 
|  | 615 | } | 
|  | 616 | } else { | 
|  | 617 | out.println(","); | 
|  | 618 | } | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | if (nativeDecl || interfaceDecl) { | 
|  | 622 | out.println(indent + ");"); | 
|  | 623 | } else { | 
|  | 624 | out.println(indent + ") {"); | 
|  | 625 |  | 
|  | 626 | String iii = indent + indent; | 
|  | 627 |  | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 628 | // emitBoundsChecks(jfunc, out, iii); | 
|  | 629 | emitFunctionCall(jfunc, out, iii, false); | 
|  | 630 |  | 
|  | 631 | // Set the pointer after we call the native code, so that if | 
|  | 632 | // the native code throws an exception we don't modify the | 
|  | 633 | // pointer. We assume that the native code is written so that | 
|  | 634 | // if an exception is thrown, then the underlying glXXXPointer | 
|  | 635 | // function will not have been called. | 
|  | 636 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | String fname = jfunc.getName(); | 
|  | 638 | if (isPointerFunc) { | 
|  | 639 | // TODO - deal with VBO variants | 
|  | 640 | if (fname.equals("glColorPointer")) { | 
|  | 641 | out.println(iii + "if ((size == 4) &&"); | 
|  | 642 | out.println(iii + "    ((type == GL_FLOAT) ||"); | 
|  | 643 | out.println(iii + "     (type == GL_UNSIGNED_BYTE) ||"); | 
|  | 644 | out.println(iii + "     (type == GL_FIXED)) &&"); | 
|  | 645 | out.println(iii + "    (stride >= 0)) {"); | 
|  | 646 | out.println(iii + indent + "_colorPointer = pointer;"); | 
|  | 647 | out.println(iii + "}"); | 
|  | 648 | } else if (fname.equals("glNormalPointer")) { | 
|  | 649 | out.println(iii + "if (((type == GL_FLOAT) ||"); | 
|  | 650 | out.println(iii + "     (type == GL_BYTE) ||"); | 
|  | 651 | out.println(iii + "     (type == GL_SHORT) ||"); | 
|  | 652 | out.println(iii + "     (type == GL_FIXED)) &&"); | 
|  | 653 | out.println(iii + "    (stride >= 0)) {"); | 
|  | 654 | out.println(iii + indent + "_normalPointer = pointer;"); | 
|  | 655 | out.println(iii + "}"); | 
|  | 656 | } else if (fname.equals("glTexCoordPointer")) { | 
|  | 657 | out.println(iii + "if (((size == 2) ||"); | 
|  | 658 | out.println(iii + "     (size == 3) ||"); | 
|  | 659 | out.println(iii + "     (size == 4)) &&"); | 
|  | 660 | out.println(iii + "    ((type == GL_FLOAT) ||"); | 
|  | 661 | out.println(iii + "     (type == GL_BYTE) ||"); | 
|  | 662 | out.println(iii + "     (type == GL_SHORT) ||"); | 
|  | 663 | out.println(iii + "     (type == GL_FIXED)) &&"); | 
|  | 664 | out.println(iii + "    (stride >= 0)) {"); | 
|  | 665 | out.println(iii + indent + "_texCoordPointer = pointer;"); | 
|  | 666 | out.println(iii + "}"); | 
|  | 667 | } else if (fname.equals("glVertexPointer")) { | 
|  | 668 | out.println(iii + "if (((size == 2) ||"); | 
|  | 669 | out.println(iii + "     (size == 3) ||"); | 
|  | 670 | out.println(iii + "     (size == 4)) &&"); | 
|  | 671 | out.println(iii + "    ((type == GL_FLOAT) ||"); | 
|  | 672 | out.println(iii + "     (type == GL_BYTE) ||"); | 
|  | 673 | out.println(iii + "     (type == GL_SHORT) ||"); | 
|  | 674 | out.println(iii + "     (type == GL_FIXED)) &&"); | 
|  | 675 | out.println(iii + "    (stride >= 0)) {"); | 
|  | 676 | out.println(iii + indent + "_vertexPointer = pointer;"); | 
|  | 677 | out.println(iii + "}"); | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 678 | } else if (fname.equals("glPointSizePointerOES")) { | 
|  | 679 | out.println(iii + "if (((type == GL_FLOAT) ||"); | 
|  | 680 | out.println(iii + "     (type == GL_FIXED)) &&"); | 
|  | 681 | out.println(iii + "    (stride >= 0)) {"); | 
|  | 682 | out.println(iii + indent + "_pointSizePointerOES = pointer;"); | 
|  | 683 | out.println(iii + "}"); | 
|  | 684 | } else if (fname.equals("glMatrixIndexPointerOES")) { | 
|  | 685 | out.println(iii + "if (((size == 2) ||"); | 
|  | 686 | out.println(iii + "     (size == 3) ||"); | 
|  | 687 | out.println(iii + "     (size == 4)) &&"); | 
|  | 688 | out.println(iii + "    ((type == GL_FLOAT) ||"); | 
|  | 689 | out.println(iii + "     (type == GL_BYTE) ||"); | 
|  | 690 | out.println(iii + "     (type == GL_SHORT) ||"); | 
|  | 691 | out.println(iii + "     (type == GL_FIXED)) &&"); | 
|  | 692 | out.println(iii + "    (stride >= 0)) {"); | 
|  | 693 | out.println(iii + indent + "_matrixIndexPointerOES = pointer;"); | 
|  | 694 | out.println(iii + "}"); | 
|  | 695 | } else if (fname.equals("glWeightPointer")) { | 
|  | 696 | out.println(iii + "if (((size == 2) ||"); | 
|  | 697 | out.println(iii + "     (size == 3) ||"); | 
|  | 698 | out.println(iii + "     (size == 4)) &&"); | 
|  | 699 | out.println(iii + "    ((type == GL_FLOAT) ||"); | 
|  | 700 | out.println(iii + "     (type == GL_BYTE) ||"); | 
|  | 701 | out.println(iii + "     (type == GL_SHORT) ||"); | 
|  | 702 | out.println(iii + "     (type == GL_FIXED)) &&"); | 
|  | 703 | out.println(iii + "    (stride >= 0)) {"); | 
|  | 704 | out.println(iii + indent + "_weightPointerOES = pointer;"); | 
|  | 705 | out.println(iii + "}"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | } | 
|  | 707 | } | 
|  | 708 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | boolean isVoid = jfunc.getType().isVoid(); | 
|  | 710 |  | 
|  | 711 | if (!isVoid) { | 
|  | 712 | out.println(indent + indent + "return _returnValue;"); | 
|  | 713 | } | 
|  | 714 | out.println(indent + "}"); | 
|  | 715 | } | 
|  | 716 | out.println(); | 
|  | 717 | } | 
|  | 718 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 719 | public void addNativeRegistration(String s) { | 
|  | 720 | nativeRegistrations.add(s); | 
|  | 721 | } | 
|  | 722 |  | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 723 | public void emitNativeRegistration(String registrationFunctionName, | 
|  | 724 | PrintStream cStream) { | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 725 | cStream.println("static const char *classPathName = \"" + | 
|  | 726 | mClassPathName + | 
|  | 727 | "\";"); | 
|  | 728 | cStream.println(); | 
|  | 729 |  | 
| Daniel Micay | c4e95a3 | 2015-09-21 13:17:57 -0400 | [diff] [blame] | 730 | cStream.println("static const JNINativeMethod methods[] = {"); | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 731 |  | 
|  | 732 | cStream.println("{\"_nativeClassInit\", \"()V\", (void*)nativeClassInit },"); | 
|  | 733 |  | 
|  | 734 | Iterator<String> i = nativeRegistrations.iterator(); | 
|  | 735 | while (i.hasNext()) { | 
|  | 736 | cStream.println(i.next()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 738 |  | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 739 | cStream.println("};"); | 
|  | 740 | cStream.println(); | 
|  | 741 |  | 
|  | 742 |  | 
| Jack Palevich | 427f585 | 2009-04-15 19:13:17 -0700 | [diff] [blame] | 743 | cStream.println("int " + registrationFunctionName + "(JNIEnv *_env)"); | 
| Jack Palevich | ffac1ef | 2009-04-14 19:00:09 -0700 | [diff] [blame] | 744 | cStream.println("{"); | 
|  | 745 | cStream.println(indent + | 
|  | 746 | "int err;"); | 
|  | 747 |  | 
|  | 748 | cStream.println(indent + | 
|  | 749 | "err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods));"); | 
|  | 750 |  | 
|  | 751 | cStream.println(indent + "return err;"); | 
|  | 752 | cStream.println("}"); | 
|  | 753 | } | 
|  | 754 |  | 
|  | 755 | public JniCodeEmitter() { | 
|  | 756 | super(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | } | 
|  | 758 |  | 
|  | 759 | String getJniType(JType jType) { | 
|  | 760 | if (jType.isVoid()) { | 
|  | 761 | return "void"; | 
|  | 762 | } | 
|  | 763 |  | 
|  | 764 | String baseType = jType.getBaseType(); | 
|  | 765 | if (jType.isPrimitive()) { | 
|  | 766 | if (baseType.equals("String")) { | 
|  | 767 | return "jstring"; | 
|  | 768 | } else { | 
|  | 769 | return "j" + baseType; | 
|  | 770 | } | 
|  | 771 | } else if (jType.isArray()) { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 772 | return jType.isClass() ? "jobjectArray" : "j" + baseType + "Array"; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | } else { | 
|  | 774 | return "jobject"; | 
|  | 775 | } | 
|  | 776 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 777 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | String getJniMangledName(String name) { | 
|  | 779 | name = name.replaceAll("_", "_1"); | 
|  | 780 | name = name.replaceAll(";", "_2"); | 
|  | 781 | name = name.replaceAll("\\[", "_3"); | 
|  | 782 | return name; | 
|  | 783 | } | 
|  | 784 |  | 
|  | 785 | public void emitJniCode(JFunc jfunc, PrintStream out) { | 
|  | 786 | CFunc cfunc = jfunc.getCFunc(); | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 787 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | // Emit comment identifying original C function | 
|  | 789 | // | 
|  | 790 | // Example: | 
|  | 791 | // | 
|  | 792 | // /* void glClipPlanef ( GLenum plane, const GLfloat *equation ) */ | 
|  | 793 | // | 
|  | 794 | out.println("/* " + cfunc.getOriginal() + " */"); | 
|  | 795 |  | 
|  | 796 | // Emit JNI signature (name) | 
|  | 797 | // | 
|  | 798 | // Example: | 
|  | 799 | // | 
|  | 800 | // void | 
|  | 801 | // android_glClipPlanef__I_3FI | 
|  | 802 | // | 
|  | 803 |  | 
|  | 804 | String outName = "android_" + jfunc.getName(); | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 805 | boolean isPointerFunc = isPointerFunc(jfunc); | 
| Jesse Hall | 071fc66 | 2013-04-10 01:17:34 -0700 | [diff] [blame] | 806 | boolean isPointerOffsetFunc = | 
|  | 807 | (outName.endsWith("Pointer") || outName.endsWith("PointerOES") || | 
|  | 808 | outName.endsWith("glDrawElements") || | 
|  | 809 | outName.endsWith("glDrawRangeElements") || | 
|  | 810 | outName.endsWith("glTexImage2D") || | 
|  | 811 | outName.endsWith("glTexSubImage2D") || | 
|  | 812 | outName.endsWith("glCompressedTexImage2D") || | 
|  | 813 | outName.endsWith("glCompressedTexSubImage2D") || | 
|  | 814 | outName.endsWith("glTexImage3D") || | 
|  | 815 | outName.endsWith("glTexSubImage3D") || | 
|  | 816 | outName.endsWith("glCompressedTexImage3D") || | 
|  | 817 | outName.endsWith("glCompressedTexSubImage3D") || | 
|  | 818 | outName.endsWith("glReadPixels")) | 
|  | 819 | && !jfunc.getCFunc().hasPointerArg(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | if (isPointerFunc) { | 
|  | 821 | outName += "Bounds"; | 
|  | 822 | } | 
|  | 823 |  | 
|  | 824 | out.print("static "); | 
|  | 825 | out.println(getJniType(jfunc.getType())); | 
|  | 826 | out.print(outName); | 
|  | 827 |  | 
|  | 828 | String rsignature = getJniName(jfunc.getType()); | 
|  | 829 |  | 
|  | 830 | String signature = ""; | 
|  | 831 | int numArgs = jfunc.getNumArgs(); | 
|  | 832 | for (int i = 0; i < numArgs; i++) { | 
|  | 833 | JType argType = jfunc.getArgType(i); | 
|  | 834 | signature += getJniName(argType); | 
|  | 835 | } | 
|  | 836 | if (isPointerFunc) { | 
|  | 837 | signature += "I"; | 
|  | 838 | } | 
|  | 839 |  | 
|  | 840 | // Append signature to function name | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 841 | String sig = getJniMangledName(signature).replace('.', '_').replace('/', '_'); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 842 | if (!mUseSimpleMethodNames) { | 
|  | 843 | out.print("__" + sig); | 
|  | 844 | outName += "__" + sig; | 
|  | 845 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 846 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | signature = signature.replace('.', '/'); | 
|  | 848 | rsignature = rsignature.replace('.', '/'); | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 849 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | out.println(); | 
|  | 851 | if (rsignature.length() == 0) { | 
|  | 852 | rsignature = "V"; | 
|  | 853 | } | 
|  | 854 |  | 
|  | 855 | String s = "{\"" + | 
|  | 856 | jfunc.getName() + | 
|  | 857 | (isPointerFunc ? "Bounds" : "") + | 
|  | 858 | "\", \"(" + signature +")" + | 
|  | 859 | rsignature + | 
|  | 860 | "\", (void *) " + | 
|  | 861 | outName + | 
|  | 862 | " },"; | 
|  | 863 | nativeRegistrations.add(s); | 
|  | 864 |  | 
|  | 865 | List<Integer> nonPrimitiveArgs = new ArrayList<Integer>(); | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 866 | List<Integer> stringArgs = new ArrayList<Integer>(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | int numBufferArgs = 0; | 
|  | 868 | List<String> bufferArgNames = new ArrayList<String>(); | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 869 | List<JType> bufferArgTypes = new ArrayList<JType>(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 |  | 
|  | 871 | // Emit JNI signature (arguments) | 
|  | 872 | // | 
|  | 873 | // Example: | 
|  | 874 | // | 
|  | 875 | // (JNIEnv *_env, jobject this, jint plane, jfloatArray equation_ref, jint offset) { | 
|  | 876 | // | 
|  | 877 | out.print("  (JNIEnv *_env, jobject _this"); | 
|  | 878 | for (int i = 0; i < numArgs; i++) { | 
|  | 879 | out.print(", "); | 
|  | 880 | JType argType = jfunc.getArgType(i); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 881 | String suffix = ""; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | if (!argType.isPrimitive()) { | 
|  | 883 | if (argType.isArray()) { | 
|  | 884 | suffix = "_ref"; | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 885 | } else if (argType.isBuffer()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | suffix = "_buf"; | 
|  | 887 | } | 
|  | 888 | nonPrimitiveArgs.add(new Integer(i)); | 
|  | 889 | if (jfunc.getArgType(i).isBuffer()) { | 
|  | 890 | int cIndex = jfunc.getArgCIndex(i); | 
|  | 891 | String cname = cfunc.getArgName(cIndex); | 
|  | 892 | bufferArgNames.add(cname); | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 893 | bufferArgTypes.add(jfunc.getArgType(i)); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | numBufferArgs++; | 
|  | 895 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | } | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 897 |  | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 898 | if (argType.isString()) { | 
|  | 899 | stringArgs.add(new Integer(i)); | 
|  | 900 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 |  | 
|  | 902 | out.print(getJniType(argType) + " " + jfunc.getArgName(i) + suffix); | 
|  | 903 | } | 
|  | 904 | if (isPointerFunc) { | 
|  | 905 | out.print(", jint remaining"); | 
|  | 906 | } | 
|  | 907 | out.println(") {"); | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 908 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | int numArrays = 0; | 
|  | 910 | int numBuffers = 0; | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 911 | int numStrings = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | for (int i = 0; i < nonPrimitiveArgs.size(); i++) { | 
|  | 913 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 914 | JType argType = jfunc.getArgType(idx); | 
|  | 915 | if (argType.isArray()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | ++numArrays; | 
|  | 917 | } | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 918 | if (argType.isBuffer()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | ++numBuffers; | 
|  | 920 | } | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 921 | if (argType.isString()) { | 
|  | 922 | ++numStrings; | 
|  | 923 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | } | 
|  | 925 |  | 
|  | 926 | // Emit method body | 
|  | 927 |  | 
|  | 928 | // Emit local variable declarations for _exception and _returnValue | 
|  | 929 | // | 
|  | 930 | // Example: | 
|  | 931 | // | 
|  | 932 | // android::gl::ogles_context_t *ctx; | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 933 | // | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | // jint _exception; | 
|  | 935 | // GLenum _returnValue; | 
|  | 936 | // | 
|  | 937 | CType returnType = cfunc.getType(); | 
|  | 938 | boolean isVoid = returnType.isVoid(); | 
|  | 939 |  | 
|  | 940 | boolean isUnsupported = isUnsupportedFunc(cfunc); | 
|  | 941 | if (isUnsupported) { | 
|  | 942 | out.println(indent + | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 943 | "jniThrowException(_env, \"java/lang/UnsupportedOperationException\","); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | out.println(indent + | 
|  | 945 | "    \"" + cfunc.getName() + "\");"); | 
|  | 946 | if (!isVoid) { | 
|  | 947 | String retval = getErrorReturnValue(cfunc); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 948 | if (cfunc.getType().isEGLHandle()) { | 
|  | 949 | String baseType = cfunc.getType().getBaseType().toLowerCase(); | 
|  | 950 | out.println(indent + | 
|  | 951 | "return toEGLHandle(_env, " + baseType + "Class, " + | 
|  | 952 | baseType + "Constructor, " + retval + ");"); | 
|  | 953 | } else { | 
|  | 954 | out.println(indent + "return " + retval + ";"); | 
|  | 955 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | } | 
|  | 957 | out.println("}"); | 
|  | 958 | out.println(); | 
|  | 959 | return; | 
|  | 960 | } | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 961 |  | 
| Jack Palevich | e44e45c | 2010-01-28 20:28:32 +0800 | [diff] [blame] | 962 | String requiresExtension = isRequiresFunc(cfunc); | 
|  | 963 | if (requiresExtension != null) { | 
|  | 964 | out.println(indent + | 
|  | 965 | "if (! supportsExtension(_env, _this, have_" + requiresExtension + "ID)) {"); | 
|  | 966 | out.println(indent + indent + | 
| Elliott Hughes | 9875750 | 2011-04-08 20:01:01 -0700 | [diff] [blame] | 967 | "jniThrowException(_env, \"java/lang/UnsupportedOperationException\","); | 
| Jack Palevich | e44e45c | 2010-01-28 20:28:32 +0800 | [diff] [blame] | 968 | out.println(indent + indent + | 
|  | 969 | "    \"" + cfunc.getName() + "\");"); | 
|  | 970 | if (isVoid) { | 
|  | 971 | out.println(indent + indent + "    return;"); | 
|  | 972 | } else { | 
|  | 973 | String retval = getErrorReturnValue(cfunc); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 974 | if (cfunc.getType().isEGLHandle()) { | 
|  | 975 | String baseType = cfunc.getType().getBaseType().toLowerCase(); | 
|  | 976 | out.println(indent + | 
|  | 977 | "return toEGLHandle(_env, " + baseType + "Class, " + | 
|  | 978 | baseType + "Constructor, " + retval + ");"); | 
|  | 979 | } else { | 
|  | 980 | out.println(indent + "return " + retval + ";"); | 
|  | 981 | } | 
| Jack Palevich | e44e45c | 2010-01-28 20:28:32 +0800 | [diff] [blame] | 982 | } | 
|  | 983 | out.println(indent + "}"); | 
|  | 984 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | if (mUseContextPointer) { | 
|  | 986 | out.println(indent + | 
|  | 987 | "android::gl::ogles_context_t *ctx = getContext(_env, _this);"); | 
|  | 988 | } | 
|  | 989 |  | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 990 | boolean initializeReturnValue = stringArgs.size() > 0; | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 991 | boolean emitExceptionCheck = ((numArrays > 0 || numStrings > 0) | 
|  | 992 | && (hasNonConstArg(jfunc, cfunc, nonPrimitiveArgs) | 
|  | 993 | || (cfunc.hasPointerArg() && numArrays > 0)) | 
| Romain Guy | 7969999 | 2016-12-05 12:26:42 -0800 | [diff] [blame] | 994 | || (numBufferArgs > 0) | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 995 | || hasCheckTest(cfunc) | 
|  | 996 | || hasIfTest(cfunc)) | 
|  | 997 | || (stringArgs.size() > 0); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | // mChecker.getChecks(cfunc.getName()) != null | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | // Emit an _exeption variable if there will be error checks | 
|  | 1000 | if (emitExceptionCheck) { | 
|  | 1001 | out.println(indent + "jint _exception = 0;"); | 
| Mathias Agopian | bf13ba5 | 2013-02-22 19:34:06 -0800 | [diff] [blame] | 1002 | out.println(indent + "const char * _exceptionType = NULL;"); | 
|  | 1003 | out.println(indent + "const char * _exceptionMessage = NULL;"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | } | 
|  | 1005 |  | 
|  | 1006 | // Emit a single _array or multiple _XXXArray variables | 
|  | 1007 | if (numBufferArgs == 1) { | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1008 | JType bufferType = bufferArgTypes.get(0); | 
|  | 1009 | if (bufferType.isTypedBuffer()) { | 
|  | 1010 | String typedArrayType = getJniType(bufferType.getArrayTypeForTypedBuffer()); | 
|  | 1011 | out.println(indent + typedArrayType + " _array = (" + typedArrayType + ") 0;"); | 
|  | 1012 | } else { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | out.println(indent + "jarray _array = (jarray) 0;"); | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1014 | } | 
|  | 1015 | out.println(indent + "jint _bufferOffset = (jint) 0;"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | } else { | 
|  | 1017 | for (int i = 0; i < numBufferArgs; i++) { | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1018 | JType bufferType = bufferArgTypes.get(0); | 
|  | 1019 | if (bufferType.isTypedBuffer()) { | 
|  | 1020 | String typedArrayType = getJniType(bufferType.getArrayTypeForTypedBuffer()); | 
|  | 1021 | out.println(indent + typedArrayType + " _" + bufferArgNames.get(i) + | 
|  | 1022 | "Array = (" + typedArrayType + ") 0;"); | 
|  | 1023 | } else { | 
|  | 1024 | out.println(indent + "jarray _" + bufferArgNames.get(i) + | 
|  | 1025 | "Array = (jarray) 0;"); | 
|  | 1026 | } | 
| Thomas Tafertshofer | e58a97b | 2012-07-12 11:16:20 -0700 | [diff] [blame] | 1027 | out.println(indent + "jint _" + bufferArgNames.get(i) + | 
|  | 1028 | "BufferOffset = (jint) 0;"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | } | 
|  | 1030 | } | 
|  | 1031 | if (!isVoid) { | 
|  | 1032 | String retval = getErrorReturnValue(cfunc); | 
|  | 1033 | if (retval != null) { | 
|  | 1034 | out.println(indent + returnType.getDeclaration() + | 
|  | 1035 | " _returnValue = " + retval + ";"); | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1036 | } else if (initializeReturnValue) { | 
|  | 1037 | out.println(indent + returnType.getDeclaration() + | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1038 | " _returnValue = 0;"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | } else { | 
|  | 1040 | out.println(indent + returnType.getDeclaration() + | 
|  | 1041 | " _returnValue;"); | 
|  | 1042 | } | 
|  | 1043 | } | 
|  | 1044 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1045 | // Emit local variable declarations for EGL Handles | 
|  | 1046 | // | 
|  | 1047 | // Example: | 
|  | 1048 | // | 
|  | 1049 | // EGLSurface surface_native = (EGLHandle)fromEGLHandle(_env, surfaceClass, surfaceConstructor, surface); | 
|  | 1050 | // | 
|  | 1051 | if (nonPrimitiveArgs.size() > 0) { | 
|  | 1052 | for (int i = 0; i < nonPrimitiveArgs.size(); i++) { | 
|  | 1053 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
|  | 1054 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 1055 | String cname = cfunc.getArgName(cIndex); | 
|  | 1056 |  | 
|  | 1057 | if (jfunc.getArgType(idx).isBuffer() | 
|  | 1058 | || jfunc.getArgType(idx).isArray() | 
|  | 1059 | || !jfunc.getArgType(idx).isEGLHandle()) | 
|  | 1060 | continue; | 
|  | 1061 |  | 
|  | 1062 | CType type = cfunc.getArgType(jfunc.getArgCIndex(idx)); | 
|  | 1063 | String decl = type.getDeclaration(); | 
|  | 1064 | out.println(indent + | 
|  | 1065 | decl + " " + cname + "_native = (" + | 
|  | 1066 | decl + ") fromEGLHandle(_env, " + | 
|  | 1067 | type.getBaseType().toLowerCase() + | 
|  | 1068 | "GetHandleID, " + jfunc.getArgName(idx) + | 
|  | 1069 | ");"); | 
|  | 1070 | } | 
|  | 1071 | } | 
|  | 1072 |  | 
|  | 1073 | // Emit local variable declarations for element/sentinel checks | 
|  | 1074 | // | 
|  | 1075 | // Example: | 
|  | 1076 | // | 
|  | 1077 | // bool attrib_list_sentinel_found = false; | 
|  | 1078 | // | 
|  | 1079 | emitLocalVariablesForSentinel(cfunc, out); | 
|  | 1080 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | // Emit local variable declarations for pointer arguments | 
|  | 1082 | // | 
|  | 1083 | // Example: | 
|  | 1084 | // | 
|  | 1085 | // GLfixed *eqn_base; | 
|  | 1086 | // GLfixed *eqn; | 
|  | 1087 | // | 
|  | 1088 | String offset = "offset"; | 
|  | 1089 | String remaining = "_remaining"; | 
|  | 1090 | if (nonPrimitiveArgs.size() > 0) { | 
|  | 1091 | for (int i = 0; i < nonPrimitiveArgs.size(); i++) { | 
|  | 1092 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
|  | 1093 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 1094 | String cname = cfunc.getArgName(cIndex); | 
|  | 1095 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1096 | if (!jfunc.getArgType(idx).isBuffer() && !jfunc.getArgType(idx).isArray()) | 
|  | 1097 | continue; | 
|  | 1098 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | CType type = cfunc.getArgType(jfunc.getArgCIndex(idx)); | 
|  | 1100 | String decl = type.getDeclaration(); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1101 | if (jfunc.getArgType(idx).isArray() && !jfunc.getArgType(idx).isClass()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | out.println(indent + | 
|  | 1103 | decl + | 
|  | 1104 | (decl.endsWith("*") ? "" : " ") + | 
|  | 1105 | jfunc.getArgName(idx) + | 
|  | 1106 | "_base = (" + decl + ") 0;"); | 
|  | 1107 | } | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1108 | remaining = ((numArrays + numBuffers) <= 1) ? "_remaining" : | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | "_" + cname + "Remaining"; | 
|  | 1110 | out.println(indent + | 
|  | 1111 | "jint " + remaining + ";"); | 
|  | 1112 | out.println(indent + | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1113 | decl + | 
|  | 1114 | (decl.endsWith("*") ? "" : " ") + | 
|  | 1115 | jfunc.getArgName(idx) + | 
|  | 1116 | " = (" + decl + ") 0;"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | } | 
|  | 1118 |  | 
|  | 1119 | out.println(); | 
|  | 1120 | } | 
|  | 1121 |  | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1122 | // Emit local variable declaration for strings | 
|  | 1123 | if (stringArgs.size() > 0) { | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1124 | boolean requiresStringLengthCheck = false; | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1125 | for (int i = 0; i < stringArgs.size(); i++) { | 
|  | 1126 | int idx = stringArgs.get(i).intValue(); | 
|  | 1127 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 1128 | String cname = cfunc.getArgName(cIndex); | 
|  | 1129 |  | 
|  | 1130 | out.println(indent + "const char* _native" + cname + " = 0;"); | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1131 | if (hasCheckTest(cfunc, cname)) { | 
|  | 1132 | requiresStringLengthCheck = true; | 
|  | 1133 | } | 
|  | 1134 | } | 
|  | 1135 |  | 
|  | 1136 | if (requiresStringLengthCheck) { | 
|  | 1137 | out.println(indent + "jsize _stringlen = 0;"); | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1138 | } | 
|  | 1139 |  | 
|  | 1140 | out.println(); | 
|  | 1141 | } | 
|  | 1142 |  | 
|  | 1143 | // Null pointer checks and GetStringUTFChars | 
|  | 1144 | if (stringArgs.size() > 0) { | 
|  | 1145 | for (int i = 0; i < stringArgs.size(); i++) { | 
|  | 1146 | int idx = stringArgs.get(i).intValue(); | 
|  | 1147 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 1148 | String cname = cfunc.getArgName(cIndex); | 
|  | 1149 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1150 | boolean nullAllowed = isNullAllowed(cfunc, cname); | 
|  | 1151 | String nullAllowedIndent = nullAllowed ? indent : ""; | 
|  | 1152 |  | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1153 | CType type = cfunc.getArgType(jfunc.getArgCIndex(idx)); | 
|  | 1154 | String decl = type.getDeclaration(); | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1155 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1156 | if (nullAllowed) { | 
|  | 1157 | out.println(indent + "if (" + cname + ") {"); | 
|  | 1158 | } else { | 
|  | 1159 | needsExit = true; | 
|  | 1160 | out.println(indent + "if (!" + cname + ") {"); | 
|  | 1161 | out.println(indent + indent + "_exception = 1;"); | 
|  | 1162 | out.println(indent + indent + | 
|  | 1163 | "_exceptionType = \"java/lang/IllegalArgumentException\";"); | 
|  | 1164 | out.println(indent + indent + | 
|  | 1165 | "_exceptionMessage = \"" + cname + " == null\";"); | 
|  | 1166 | out.println(indent + indent + "goto exit;"); | 
|  | 1167 | out.println(indent + "}"); | 
|  | 1168 | } | 
|  | 1169 |  | 
|  | 1170 | out.println(nullAllowedIndent + indent + "_native" + cname + | 
|  | 1171 | " = _env->GetStringUTFChars(" + cname + ", 0);"); | 
|  | 1172 |  | 
|  | 1173 | emitStringCheck(cfunc, cname, out, nullAllowedIndent + indent); | 
|  | 1174 |  | 
|  | 1175 | if (nullAllowed) { | 
|  | 1176 | out.println(indent + "}"); | 
|  | 1177 | } | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1178 | } | 
|  | 1179 |  | 
|  | 1180 | out.println(); | 
|  | 1181 | } | 
|  | 1182 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1183 | // Emit 'GetPrimitiveArrayCritical' for non-object arrays | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | // Emit 'GetPointer' calls for Buffer pointers | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | if (nonPrimitiveArgs.size() > 0) { | 
|  | 1186 | for (int i = 0; i < nonPrimitiveArgs.size(); i++) { | 
|  | 1187 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
|  | 1188 | int cIndex = jfunc.getArgCIndex(idx); | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1189 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | String cname = cfunc.getArgName(cIndex); | 
|  | 1191 | offset = numArrays <= 1 ? "offset" : | 
|  | 1192 | cname + "Offset"; | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1193 | remaining = ((numArrays + numBuffers) <= 1) ? "_remaining" : | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | "_" + cname + "Remaining"; | 
|  | 1195 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1196 | boolean nullAllowed = isNullAllowed(cfunc, cname); | 
|  | 1197 | String nullAllowedIndent = nullAllowed ? indent : ""; | 
|  | 1198 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1199 | if (jfunc.getArgType(idx).isArray() | 
|  | 1200 | && !jfunc.getArgType(idx).isEGLHandle()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | needsExit = true; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1203 | if (nullAllowed) { | 
|  | 1204 | out.println(indent + "if (" + cname + "_ref) {"); | 
|  | 1205 | } | 
|  | 1206 | else | 
|  | 1207 | { | 
|  | 1208 | out.println(indent + "if (!" + cname + "_ref) {"); | 
|  | 1209 | out.println(indent + indent + "_exception = 1;"); | 
|  | 1210 | out.println(indent + indent + | 
|  | 1211 | "_exceptionType = " + | 
|  | 1212 | "\"java/lang/IllegalArgumentException\";"); | 
|  | 1213 | out.println(indent + indent + | 
|  | 1214 | "_exceptionMessage = \"" + cname + | 
|  | 1215 | " == null\";"); | 
|  | 1216 | out.println(indent + indent + "goto exit;"); | 
|  | 1217 | out.println(indent + "}"); | 
|  | 1218 | } | 
|  | 1219 |  | 
|  | 1220 | out.println(nullAllowedIndent + indent + "if (" + offset + | 
|  | 1221 | " < 0) {"); | 
|  | 1222 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1223 | "_exception = 1;"); | 
|  | 1224 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1225 | "_exceptionType = " + | 
|  | 1226 | "\"java/lang/IllegalArgumentException\";"); | 
|  | 1227 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1228 | "_exceptionMessage = \"" + offset +" < 0\";"); | 
|  | 1229 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1230 | "goto exit;"); | 
|  | 1231 | out.println(nullAllowedIndent + indent + "}"); | 
|  | 1232 |  | 
|  | 1233 | out.println(nullAllowedIndent + indent + remaining + " = " + | 
|  | 1234 | (mUseCPlusPlus ? "_env" : "(*_env)") + | 
|  | 1235 | "->GetArrayLength(" + | 
|  | 1236 | (mUseCPlusPlus ? "" : "_env, ") + | 
|  | 1237 | cname + "_ref) - " + offset + ";"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 |  | 
|  | 1239 | emitNativeBoundsChecks(cfunc, cname, out, false, | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1240 | emitExceptionCheck, offset, remaining, | 
|  | 1241 | nullAllowedIndent + indent); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1243 | out.println(nullAllowedIndent + indent + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | cname + | 
|  | 1245 | "_base = (" + | 
|  | 1246 | cfunc.getArgType(cIndex).getDeclaration() + | 
|  | 1247 | ")"); | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1248 | String arrayGetter = jfunc.getArgType(idx).getArrayGetterForPrimitiveArray(); | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1249 | out.println(nullAllowedIndent + indent + "    " + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | (mUseCPlusPlus ? "_env" : "(*_env)") + | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1251 | "->" + arrayGetter + "(" + | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1252 | (mUseCPlusPlus ? "" : "_env, ") + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | jfunc.getArgName(idx) + | 
|  | 1254 | "_ref, (jboolean *)0);"); | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1255 | out.println(nullAllowedIndent + indent + | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1256 | cname + " = " + cname + "_base + " + offset + ";"); | 
|  | 1257 |  | 
|  | 1258 | emitSentinelCheck(cfunc, cname, out, false, | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1259 | emitExceptionCheck, offset, remaining, | 
|  | 1260 | nullAllowedIndent + indent); | 
|  | 1261 |  | 
|  | 1262 | if (nullAllowed) { | 
|  | 1263 | out.println(indent + "}"); | 
|  | 1264 | } | 
|  | 1265 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | out.println(); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1267 | } else if (jfunc.getArgType(idx).isArray() | 
|  | 1268 | && jfunc.getArgType(idx).isEGLHandle()) { | 
|  | 1269 | needsExit = true; | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1270 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1271 | if (nullAllowed) { | 
|  | 1272 | out.println(indent + "if (" + cname + "_ref) {"); | 
|  | 1273 | } | 
|  | 1274 | else | 
|  | 1275 | { | 
|  | 1276 | out.println(indent + "if (!" + cname + "_ref) {"); | 
|  | 1277 | out.println(indent + indent + "_exception = 1;"); | 
|  | 1278 | out.println(indent + indent + "_exceptionType = " + | 
|  | 1279 | "\"java/lang/IllegalArgumentException\";"); | 
|  | 1280 | out.println(indent + indent + "_exceptionMessage = \"" + | 
|  | 1281 | cname +" == null\";"); | 
|  | 1282 | out.println(indent + indent + "goto exit;"); | 
|  | 1283 | out.println(indent + "}"); | 
|  | 1284 | } | 
|  | 1285 |  | 
|  | 1286 | out.println(nullAllowedIndent + indent + "if (" + offset + | 
|  | 1287 | " < 0) {"); | 
|  | 1288 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1289 | "_exception = 1;"); | 
|  | 1290 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1291 | "_exceptionType = " + | 
|  | 1292 | "\"java/lang/IllegalArgumentException\";"); | 
|  | 1293 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1294 | "_exceptionMessage = \"" + offset +" < 0\";"); | 
|  | 1295 | out.println(nullAllowedIndent + indent + indent + | 
|  | 1296 | "goto exit;"); | 
|  | 1297 | out.println(nullAllowedIndent + indent + "}"); | 
|  | 1298 |  | 
|  | 1299 | out.println(nullAllowedIndent + indent + remaining + " = " + | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1300 | (mUseCPlusPlus ? "_env" : "(*_env)") + | 
|  | 1301 | "->GetArrayLength(" + | 
|  | 1302 | (mUseCPlusPlus ? "" : "_env, ") + | 
|  | 1303 | cname + "_ref) - " + offset + ";"); | 
|  | 1304 | emitNativeBoundsChecks(cfunc, cname, out, false, | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1305 | emitExceptionCheck, offset, remaining, | 
|  | 1306 | nullAllowedIndent + indent); | 
|  | 1307 | out.println(nullAllowedIndent + indent + | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1308 | jfunc.getArgName(idx) + " = new " + | 
|  | 1309 | cfunc.getArgType(cIndex).getBaseType() + | 
|  | 1310 | "["+ remaining + "];"); | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1311 |  | 
|  | 1312 | if (nullAllowed) { | 
|  | 1313 | out.println(indent + "}"); | 
|  | 1314 | } | 
|  | 1315 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1316 | out.println(); | 
|  | 1317 | } else if (jfunc.getArgType(idx).isBuffer()) { | 
| Romain Guy | 7969999 | 2016-12-05 12:26:42 -0800 | [diff] [blame] | 1318 | needsExit = needsExit || (!nullAllowed && !isPointerFunc); | 
|  | 1319 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1320 | String array = numBufferArgs <= 1 ? "_array" : | 
| Thomas Tafertshofer | e58a97b | 2012-07-12 11:16:20 -0700 | [diff] [blame] | 1321 | "_" + cfunc.getArgName(cIndex) + "Array"; | 
|  | 1322 | String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" : | 
|  | 1323 | "_" + cfunc.getArgName(cIndex) + "BufferOffset"; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1325 | nullAllowed = nullAllowed || isPointerFunc; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | if (nullAllowed) { | 
|  | 1327 | out.println(indent + "if (" + cname + "_buf) {"); | 
|  | 1328 | out.print(indent); | 
|  | 1329 | } | 
| Romain Guy | 7969999 | 2016-12-05 12:26:42 -0800 | [diff] [blame] | 1330 | else | 
|  | 1331 | { | 
|  | 1332 | out.println(indent + "if (!" + cname + "_buf) {"); | 
|  | 1333 | out.println(indent + indent + "_exception = 1;"); | 
|  | 1334 | out.println(indent + indent + "_exceptionType = " + | 
|  | 1335 | "\"java/lang/IllegalArgumentException\";"); | 
|  | 1336 | out.println(indent + indent + "_exceptionMessage = \"" + | 
|  | 1337 | cname +" == null\";"); | 
|  | 1338 | out.println(indent + indent + "goto exit;"); | 
|  | 1339 | out.println(indent + "}"); | 
|  | 1340 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1341 |  | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1342 | if (isPointerFunc) { | 
|  | 1343 | out.println(indent + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | cname + | 
|  | 1345 | " = (" + | 
|  | 1346 | cfunc.getArgType(cIndex).getDeclaration() + | 
| Jack Palevich | 6eedc8d | 2009-05-15 18:13:34 -0700 | [diff] [blame] | 1347 | ") getDirectBufferPointer(_env, " + | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1348 | cname + "_buf);"); | 
|  | 1349 | String iii = "    "; | 
| Jack Palevich | 5afdc87 | 2009-10-21 11:02:44 -0700 | [diff] [blame] | 1350 | out.println(iii + indent + "if ( ! " + cname + " ) {"); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1351 | out.println(iii + indent + indent + "return;"); | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1352 | out.println(iii + indent + "}"); | 
|  | 1353 | } else { | 
|  | 1354 | out.println(indent + | 
|  | 1355 | cname + | 
|  | 1356 | " = (" + | 
|  | 1357 | cfunc.getArgType(cIndex).getDeclaration() + | 
|  | 1358 | ")getPointer(_env, " + | 
|  | 1359 | cname + | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1360 | "_buf, (jarray*)&" + array + ", &" + remaining + ", &" + bufferOffset + | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1361 | ");"); | 
|  | 1362 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1363 |  | 
| Jack Palevich | 5afdc87 | 2009-10-21 11:02:44 -0700 | [diff] [blame] | 1364 | emitNativeBoundsChecks(cfunc, cname, out, true, | 
|  | 1365 | emitExceptionCheck, | 
|  | 1366 | offset, remaining, nullAllowed ? "        " : "    "); | 
|  | 1367 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | if (nullAllowed) { | 
|  | 1369 | out.println(indent + "}"); | 
|  | 1370 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | } | 
|  | 1372 | } | 
|  | 1373 | } | 
|  | 1374 |  | 
| Thomas Tafertshofer | e58a97b | 2012-07-12 11:16:20 -0700 | [diff] [blame] | 1375 | // Emit 'GetPrimitiveArrayCritical' for pointers if needed | 
|  | 1376 | if (nonPrimitiveArgs.size() > 0) { | 
|  | 1377 | for (int i = 0; i < nonPrimitiveArgs.size(); i++) { | 
|  | 1378 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
|  | 1379 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 1380 |  | 
|  | 1381 | if(!jfunc.getArgType(idx).isBuffer() || isPointerFunc) continue; | 
|  | 1382 |  | 
|  | 1383 | String cname = cfunc.getArgName(cIndex); | 
|  | 1384 | String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" : | 
|  | 1385 | "_" + cname + "BufferOffset"; | 
|  | 1386 | String array = numBufferArgs <= 1 ? "_array" : | 
|  | 1387 | "_" + cfunc.getArgName(cIndex) + "Array"; | 
|  | 1388 |  | 
| Pablo Ceballos | b62e242 | 2015-10-01 18:25:56 -0700 | [diff] [blame] | 1389 | boolean nullAllowed = isNullAllowed(cfunc, cname) || | 
|  | 1390 | isPointerFunc; | 
| Thomas Tafertshofer | 36b285e | 2012-07-23 16:52:32 -0700 | [diff] [blame] | 1391 | if (nullAllowed) { | 
|  | 1392 | out.println(indent + "if (" + cname + "_buf && " + cname +" == NULL) {"); | 
|  | 1393 | } else { | 
|  | 1394 | out.println(indent + "if (" + cname +" == NULL) {"); | 
|  | 1395 | } | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1396 | JType argType = jfunc.getArgType(idx); | 
|  | 1397 | if (argType.isTypedBuffer()) { | 
|  | 1398 | String arrayGetter = argType.getArrayTypeForTypedBuffer().getArrayGetterForPrimitiveArray(); | 
|  | 1399 | out.println(indent + indent + "char * _" + cname + "Base = (char *)_env->" + arrayGetter + "(" + array + ", (jboolean *) 0);"); | 
|  | 1400 | out.println(indent + indent + cname + " = (" +cfunc.getArgType(cIndex).getDeclaration() +") (_" + cname + "Base + " + bufferOffset + ");"); | 
|  | 1401 | out.println(indent + "}"); | 
|  | 1402 | } else { | 
|  | 1403 | out.println(indent + indent + "char * _" + cname + "Base = (char *)_env->GetPrimitiveArrayCritical(" + array + ", (jboolean *) 0);"); | 
|  | 1404 | out.println(indent + indent + cname + " = (" +cfunc.getArgType(cIndex).getDeclaration() +") (_" + cname + "Base + " + bufferOffset + ");"); | 
|  | 1405 | out.println(indent + "}"); | 
|  | 1406 | } | 
| Thomas Tafertshofer | e58a97b | 2012-07-12 11:16:20 -0700 | [diff] [blame] | 1407 | } | 
|  | 1408 | } | 
|  | 1409 |  | 
|  | 1410 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | if (!isVoid) { | 
|  | 1412 | out.print(indent + "_returnValue = "); | 
|  | 1413 | } else { | 
|  | 1414 | out.print(indent); | 
|  | 1415 | } | 
|  | 1416 | String name = cfunc.getName(); | 
|  | 1417 |  | 
|  | 1418 | if (mUseContextPointer) { | 
|  | 1419 | name = name.substring(2, name.length()); // Strip off 'gl' prefix | 
|  | 1420 | name = name.substring(0, 1).toLowerCase() + | 
|  | 1421 | name.substring(1, name.length()); | 
|  | 1422 | out.print("ctx->procs."); | 
|  | 1423 | } | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1424 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | out.print(name + (isPointerFunc ? "Bounds" : "") + "("); | 
|  | 1426 |  | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1427 | numArgs = cfunc.getNumArgs(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | if (numArgs == 0) { | 
|  | 1429 | if (mUseContextPointer) { | 
|  | 1430 | out.println("ctx);"); | 
|  | 1431 | } else { | 
|  | 1432 | out.println(");"); | 
|  | 1433 | } | 
|  | 1434 | } else { | 
|  | 1435 | if (mUseContextPointer) { | 
|  | 1436 | out.println("ctx,"); | 
|  | 1437 | } else { | 
|  | 1438 | out.println(); | 
|  | 1439 | } | 
|  | 1440 | for (int i = 0; i < numArgs; i++) { | 
|  | 1441 | String typecast; | 
| Jesse Hall | 071fc66 | 2013-04-10 01:17:34 -0700 | [diff] [blame] | 1442 | if (i == numArgs - 1 && isPointerOffsetFunc) { | 
| Ashok Bhat | d8f0961 | 2014-02-15 12:51:43 +0000 | [diff] [blame] | 1443 | typecast = "reinterpret_cast<GLvoid *>"; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | } else { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1445 | typecast = "(" + cfunc.getArgType(i).getDeclaration() + ")"; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | } | 
|  | 1447 | out.print(indent + indent + | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1448 | typecast); | 
|  | 1449 |  | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1450 | if (cfunc.getArgType(i).isConstCharPointer()) { | 
|  | 1451 | out.print("_native"); | 
|  | 1452 | } | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1453 |  | 
| Thomas Tafertshofer | e58a97b | 2012-07-12 11:16:20 -0700 | [diff] [blame] | 1454 | if (cfunc.getArgType(i).isEGLHandle() && | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1455 | !cfunc.getArgType(i).isPointer()){ | 
|  | 1456 | out.print(cfunc.getArgName(i)+"_native"); | 
| Ashok Bhat | d8f0961 | 2014-02-15 12:51:43 +0000 | [diff] [blame] | 1457 | } else if (i == numArgs - 1 && isPointerOffsetFunc){ | 
|  | 1458 | out.print("("+cfunc.getArgName(i)+")"); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1459 | } else { | 
|  | 1460 | out.print(cfunc.getArgName(i)); | 
|  | 1461 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 |  | 
|  | 1463 | if (i == numArgs - 1) { | 
|  | 1464 | if (isPointerFunc) { | 
|  | 1465 | out.println(","); | 
|  | 1466 | out.println(indent + indent + "(GLsizei)remaining"); | 
|  | 1467 | } else { | 
|  | 1468 | out.println(); | 
|  | 1469 | } | 
|  | 1470 | } else { | 
|  | 1471 | out.println(","); | 
|  | 1472 | } | 
|  | 1473 | } | 
|  | 1474 | out.println(indent + ");"); | 
|  | 1475 | } | 
|  | 1476 |  | 
|  | 1477 | if (needsExit) { | 
|  | 1478 | out.println(); | 
|  | 1479 | out.println("exit:"); | 
|  | 1480 | needsExit = false; | 
|  | 1481 | } | 
|  | 1482 |  | 
| Thomas Tafertshofer | e58a97b | 2012-07-12 11:16:20 -0700 | [diff] [blame] | 1483 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | if (nonPrimitiveArgs.size() > 0) { | 
|  | 1485 | for (int i = nonPrimitiveArgs.size() - 1; i >= 0; i--) { | 
|  | 1486 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
|  | 1487 |  | 
|  | 1488 | int cIndex = jfunc.getArgCIndex(idx); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1489 | if (jfunc.getArgType(idx).isArray() && !jfunc.getArgType(idx).isClass()) { | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1490 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | // If the argument is 'const', GL will not write to it. | 
|  | 1492 | // In this case, we can use the 'JNI_ABORT' flag to avoid | 
|  | 1493 | // the need to write back to the Java array | 
|  | 1494 | out.println(indent + | 
|  | 1495 | "if (" + jfunc.getArgName(idx) + "_base) {"); | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1496 | String arrayReleaser = jfunc.getArgType(idx).getArrayReleaserForPrimitiveArray(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | out.println(indent + indent + | 
|  | 1498 | (mUseCPlusPlus ? "_env" : "(*_env)") + | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1499 | "->" + arrayReleaser + "(" + | 
| Jack Palevich | 6cbca50 | 2009-04-13 16:22:25 -0700 | [diff] [blame] | 1500 | (mUseCPlusPlus ? "" : "_env, ") + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | jfunc.getArgName(idx) + "_ref, " + | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1502 | "(j" + jfunc.getArgType(idx).getBaseType() + "*)" + cfunc.getArgName(cIndex) + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | "_base,"); | 
|  | 1504 | out.println(indent + indent + indent + | 
|  | 1505 | (cfunc.getArgType(cIndex).isConst() ? | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1506 | "JNI_ABORT" : "_exception ? JNI_ABORT: 0" ) + | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | ");"); | 
|  | 1508 | out.println(indent + "}"); | 
|  | 1509 | } else if (jfunc.getArgType(idx).isBuffer()) { | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1510 | if (! isPointerFunc) { | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1511 | JType argType = jfunc.getArgType(idx); | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1512 | String array = numBufferArgs <= 1 ? "_array" : | 
| Thomas Tafertshofer | e58a97b | 2012-07-12 11:16:20 -0700 | [diff] [blame] | 1513 | "_" + cfunc.getArgName(cIndex) + "Array"; | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1514 | out.println(indent + "if (" + array + ") {"); | 
| Hiroshi Yamauchi | 569bc1b | 2015-05-13 13:11:30 -0700 | [diff] [blame] | 1515 | if (argType.isTypedBuffer()) { | 
|  | 1516 | String arrayReleaser = | 
|  | 1517 | argType.getArrayTypeForTypedBuffer().getArrayReleaserForPrimitiveArray(); | 
|  | 1518 | out.println(indent + indent + | 
|  | 1519 | "_env->" + arrayReleaser + "(" + array + ", " + | 
|  | 1520 | "(j" + argType.getArrayTypeForTypedBuffer().getBaseType() + "*)" + | 
|  | 1521 | cfunc.getArgName(cIndex) + | 
|  | 1522 | ", " + | 
|  | 1523 | (cfunc.getArgType(cIndex).isConst() ? | 
|  | 1524 | "JNI_ABORT" : (emitExceptionCheck ? | 
|  | 1525 | "_exception ? JNI_ABORT : 0" : "0")) + | 
|  | 1526 | ");"); | 
|  | 1527 | } else { | 
|  | 1528 | out.println(indent + indent + | 
|  | 1529 | "releasePointer(_env, " + array + ", " + | 
|  | 1530 | cfunc.getArgName(cIndex) + | 
|  | 1531 | ", " + | 
|  | 1532 | (cfunc.getArgType(cIndex).isConst() ? | 
|  | 1533 | "JNI_FALSE" : (emitExceptionCheck ? | 
|  | 1534 | "_exception ? JNI_FALSE : JNI_TRUE" : "JNI_TRUE")) + | 
|  | 1535 | ");"); | 
|  | 1536 | } | 
| Jack Palevich | 46d25a3 | 2009-05-07 18:28:29 -0700 | [diff] [blame] | 1537 | out.println(indent + "}"); | 
|  | 1538 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1539 | } | 
|  | 1540 | } | 
|  | 1541 | } | 
|  | 1542 |  | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1543 | // Emit local variable declaration for strings | 
|  | 1544 | if (stringArgs.size() > 0) { | 
|  | 1545 | for (int i = 0; i < stringArgs.size(); i++) { | 
|  | 1546 | int idx = stringArgs.get(i).intValue(); | 
|  | 1547 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 1548 | String cname = cfunc.getArgName(cIndex); | 
|  | 1549 |  | 
|  | 1550 | out.println(indent + "if (_native" + cname + ") {"); | 
|  | 1551 | out.println(indent + "    _env->ReleaseStringUTFChars(" + cname + ", _native" + cname + ");"); | 
|  | 1552 | out.println(indent + "}"); | 
|  | 1553 | } | 
|  | 1554 |  | 
|  | 1555 | out.println(); | 
|  | 1556 | } | 
|  | 1557 |  | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1558 | // Copy results back to java arrays | 
|  | 1559 | if (nonPrimitiveArgs.size() > 0) { | 
|  | 1560 | for (int i = nonPrimitiveArgs.size() - 1; i >= 0; i--) { | 
|  | 1561 | int idx = nonPrimitiveArgs.get(i).intValue(); | 
|  | 1562 | int cIndex = jfunc.getArgCIndex(idx); | 
|  | 1563 | String baseType = cfunc.getArgType(cIndex).getBaseType().toLowerCase(); | 
|  | 1564 | if (jfunc.getArgType(idx).isArray() && jfunc.getArgType(idx).isClass()) { | 
|  | 1565 | remaining  = ((numArrays + numBuffers) <= 1) ? "_remaining" : | 
|  | 1566 | "_" + cfunc.getArgName(cIndex) + "Remaining"; | 
|  | 1567 | offset = numArrays <= 1 ? "offset" : cfunc.getArgName(cIndex) + "Offset"; | 
|  | 1568 | out.println(indent + | 
|  | 1569 | "if (" + jfunc.getArgName(idx) + ") {"); | 
|  | 1570 | out.println(indent + indent + | 
|  | 1571 | "for (int i = 0; i < " + remaining + "; i++) {"); | 
|  | 1572 | out.println(indent + indent + indent + | 
|  | 1573 | "jobject " + cfunc.getArgName(cIndex) + | 
|  | 1574 | "_new = toEGLHandle(_env, " + baseType + | 
|  | 1575 | "Class, " + baseType + "Constructor, " + | 
|  | 1576 | cfunc.getArgName(cIndex) + "[i]);"); | 
|  | 1577 | out.println(indent + indent + indent + | 
|  | 1578 | (mUseCPlusPlus ? "_env" : "(*_env)") + | 
|  | 1579 | "->SetObjectArrayElement(" + | 
|  | 1580 | (mUseCPlusPlus ? "" : "_env, ") + | 
|  | 1581 | cfunc.getArgName(cIndex) + | 
|  | 1582 | "_ref, i + " + offset + ", " + | 
|  | 1583 | cfunc.getArgName(cIndex) + "_new);"); | 
|  | 1584 | out.println(indent + indent + "}"); | 
|  | 1585 | out.println(indent + indent + | 
|  | 1586 | "delete[] " + jfunc.getArgName(idx) + ";"); | 
|  | 1587 | out.println(indent + "}"); | 
|  | 1588 | } | 
|  | 1589 | } | 
|  | 1590 | } | 
|  | 1591 |  | 
|  | 1592 |  | 
|  | 1593 | // Throw exception if there is one | 
|  | 1594 | if (emitExceptionCheck) { | 
|  | 1595 | out.println(indent + "if (_exception) {"); | 
|  | 1596 | out.println(indent + indent + | 
|  | 1597 | "jniThrowException(_env, _exceptionType, _exceptionMessage);"); | 
|  | 1598 | out.println(indent + "}"); | 
|  | 1599 |  | 
|  | 1600 | } | 
|  | 1601 |  | 
| Jack Palevich | 50d0b14 | 2009-11-19 16:34:55 +0800 | [diff] [blame] | 1602 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | if (!isVoid) { | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1604 | if (cfunc.getType().isEGLHandle()) { | 
|  | 1605 | String baseType = cfunc.getType().getBaseType().toLowerCase(); | 
|  | 1606 | out.println(indent + | 
|  | 1607 | "return toEGLHandle(_env, " + baseType + "Class, " + | 
|  | 1608 | baseType + "Constructor, _returnValue);"); | 
|  | 1609 | } else { | 
| Jesse Hall | 68fc8bb | 2013-04-10 01:01:00 -0700 | [diff] [blame] | 1610 | out.println(indent + "return (" + | 
|  | 1611 | getJniType(jfunc.getType()) + ")_returnValue;"); | 
| Thomas Tafertshofer | 66a42db | 2012-06-15 16:22:43 -0700 | [diff] [blame] | 1612 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | } | 
|  | 1614 |  | 
|  | 1615 | out.println("}"); | 
|  | 1616 | out.println(); | 
|  | 1617 | } | 
|  | 1618 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | } |