| 11 | |
| 12 | |
| 13 | abstract public class LFunctionType extends BObjectType<LFunction> { |
| 14 | |
| 15 | public static LFunctionType get(Version.FunctionType type) { |
| 16 | switch(type) { |
| 17 | case LUA50: return new LFunctionType50(); |
| 18 | case LUA51: return new LFunctionType51(); |
| 19 | case LUA52: return new LFunctionType52(); |
| 20 | case LUA53: return new LFunctionType53(); |
| 21 | case LUA54: return new LFunctionType54(); |
| 22 | default: throw new IllegalStateException(); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | protected static class LFunctionParseState { |
| 27 | |
| 28 | public LString name; |
| 29 | int lineBegin; |
| 30 | int lineEnd; |
| 31 | int lenUpvalues; |
| 32 | int lenParameter; |
| 33 | int vararg; |
| 34 | int maximumStackSize; |
| 35 | int length; |
| 36 | int[] code; |
| 37 | BList<LObject> constants; |
| 38 | BList<LFunction> functions; |
| 39 | BList<BInteger> lines; |
| 40 | BList<LAbsLineInfo> abslineinfo; |
| 41 | BList<LLocal> locals; |
| 42 | LUpvalue upvalues[]; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public LFunction parse(ByteBuffer buffer, BHeader header) { |
| 47 | if(header.debug) { |
| 48 | System.out.println("-- beginning to parse function"); |
| 49 | } |
| 50 | if(header.debug) { |
| 51 | System.out.println("-- parsing name...start...end...upvalues...params...varargs...stack"); |
| 52 | } |
| 53 | LFunctionParseState s = new LFunctionParseState(); |
| 54 | parse_main(buffer, header, s); |
| 55 | int[] lines = new int[s.lines.length.asInt()]; |
| 56 | for(int i = 0; i < lines.length; i++) { |
| 57 | lines[i] = s.lines.get(i).asInt(); |
| 58 | } |
| 59 | LAbsLineInfo[] abslineinfo = null; |
| 60 | if(s.abslineinfo != null) { |
| 61 | abslineinfo = s.abslineinfo.asArray(new LAbsLineInfo[s.abslineinfo.length.asInt()]); |
| 62 | } |
| 63 | LFunction lfunc = new LFunction(header, s.name, s.lineBegin, s.lineEnd, s.code, lines, abslineinfo, s.locals.asArray(new LLocal[s.locals.length.asInt()]), s.constants.asArray(new LObject[s.constants.length.asInt()]), s.upvalues, s.functions.asArray(new LFunction[s.functions.length.asInt()]), s.maximumStackSize, s.lenUpvalues, s.lenParameter, s.vararg); |
| 64 | for(LFunction child : lfunc.functions) { |
| 65 | child.parent = lfunc; |
| 66 | } |
| 67 | if(s.lines.length.asInt() == 0 && s.locals.length.asInt() == 0) { |
| 68 | lfunc.stripped = true; |
| 69 | } |
| 70 | return lfunc; |
nothing calls this directly
no outgoing calls
no test coverage detected