JFunc.java revision edbf3b6af777b721cd2a1ef461947e51e88241e1
1 2import java.util.ArrayList; 3import java.util.List; 4 5public class JFunc { 6 7 String className = "com.google.android.gles_jni.GL11Impl"; 8 9 CFunc cfunc; 10 JType ftype; 11 String fname; 12 13 List<String> argNames = new ArrayList<String>(); 14 List<JType> argTypes = new ArrayList<JType>(); 15 List<Integer> argCIndices = new ArrayList<Integer>(); 16 17 boolean hasBufferArg = false; 18 boolean hasTypedBufferArg = false; 19 ArrayList<String> bufferArgNames = new ArrayList<String>(); 20 21 public JFunc(CFunc cfunc) { 22 this.cfunc = cfunc; 23 } 24 25 public CFunc getCFunc() { 26 return cfunc; 27 } 28 29 public void setName(String fname) { 30 this.fname = fname; 31 } 32 33 public String getName() { 34 return fname; 35 } 36 37 public void setType(JType ftype) { 38 this.ftype = ftype; 39 } 40 41 public JType getType() { 42 return ftype; 43 } 44 45 public void setClassName(String className) { 46 this.className = className; 47 } 48 49 public String getClassName() { 50 return className; 51 } 52 53 public boolean hasBufferArg() { 54 return hasBufferArg; 55 } 56 57 public boolean hasTypedBufferArg() { 58 return hasTypedBufferArg; 59 } 60 61 public String getBufferArgName(int index) { 62 return bufferArgNames.get(index); 63 } 64 65 public void addArgument(String argName, JType argType, int cindex) { 66 argNames.add(argName); 67 argTypes.add(argType); 68 argCIndices.add(new Integer(cindex)); 69 70 if (argType.isBuffer()) { 71 hasBufferArg = true; 72 bufferArgNames.add(argName); 73 } 74 if (argType.isTypedBuffer()) { 75 hasTypedBufferArg = true; 76 bufferArgNames.add(argName); 77 } 78 } 79 80 public int getNumArgs() { 81 return argNames.size(); 82 } 83 84 public int getArgIndex(String name) { 85 int len = argNames.size(); 86 for (int i = 0; i < len; i++) { 87 if (name.equals(argNames.get(i))) { 88 return i; 89 } 90 } 91 return -1; 92 } 93 94 public String getArgName(int index) { 95 return argNames.get(index); 96 } 97 98 public JType getArgType(int index) { 99 return argTypes.get(index); 100 } 101 102 public int getArgCIndex(int index) { 103 return argCIndices.get(index).intValue(); 104 } 105 106 public static JFunc convert(CFunc cfunc, boolean useArray) { 107 JFunc jfunc = new JFunc(cfunc); 108 jfunc.setName(cfunc.getName()); 109 jfunc.setType(JType.convert(cfunc.getType(), false)); 110 111 int numArgs = cfunc.getNumArgs(); 112 int numOffsets = 0; 113 for (int i = 0; i < numArgs; i++) { 114 CType cArgType = cfunc.getArgType(i); 115 if (cArgType.isTypedPointer() && useArray) { 116 ++numOffsets; 117 } 118 } 119 120 for (int i = 0; i < numArgs; i++) { 121 String cArgName = cfunc.getArgName(i); 122 CType cArgType = cfunc.getArgType(i); 123 124 jfunc.addArgument(cArgName, JType.convert(cArgType, useArray), i); 125 if (cArgType.isTypedPointer() && useArray) { 126 if (numOffsets > 1) { 127 jfunc.addArgument(cArgName + "Offset", new JType("int"), i); 128 } else { 129 jfunc.addArgument("offset", new JType("int"), i); 130 } 131 } 132 } 133 134 return jfunc; 135 } 136 137 public String toString() { 138 String s = "Function " + fname + " returns " + ftype + ": "; 139 for (int i = 0; i < argNames.size(); i++) { 140 if (i > 0) { 141 s += ", "; 142 } 143 s += argTypes.get(i) + " " + argNames.get(i); 144 } 145 return s; 146 } 147 148} 149