| 6 | import unluac.parse.LFunction; |
| 7 | |
| 8 | public class Function { |
| 9 | |
| 10 | private Version version; |
| 11 | private Constant[] constants; |
| 12 | private final CodeExtract extract; |
| 13 | |
| 14 | public Function(LFunction function) { |
| 15 | version = function.header.version; |
| 16 | constants = new Constant[function.constants.length]; |
| 17 | for(int i = 0; i < constants.length; i++) { |
| 18 | constants[i] = new Constant(function.constants[i]); |
| 19 | } |
| 20 | extract = function.header.extractor; |
| 21 | } |
| 22 | |
| 23 | public boolean isConstant(int register) { |
| 24 | return extract.is_k(register); |
| 25 | } |
| 26 | |
| 27 | public int constantIndex(int register) { |
| 28 | return extract.get_k(register); |
| 29 | } |
| 30 | |
| 31 | public ConstantExpression getGlobalName(int constantIndex) { |
| 32 | Constant constant = constants[constantIndex]; |
| 33 | if(!constant.isIdentifierPermissive(version)) throw new IllegalStateException(); |
| 34 | return new ConstantExpression(constant, true, constantIndex); |
| 35 | } |
| 36 | |
| 37 | public ConstantExpression getConstantExpression(int constantIndex) { |
| 38 | Constant constant = constants[constantIndex]; |
| 39 | return new ConstantExpression(constant, constant.isIdentifier(version), constantIndex); |
| 40 | } |
| 41 | |
| 42 | public GlobalExpression getGlobalExpression(int constantIndex) { |
| 43 | return new GlobalExpression(getGlobalName(constantIndex), constantIndex); |
| 44 | } |
| 45 | |
| 46 | public Version getVersion() { |
| 47 | return version; |
| 48 | } |
| 49 | |
| 50 | } |
nothing calls this directly
no outgoing calls
no test coverage detected