Exemple #1
0
        private void addNonStaticMethods(CompilerContext context, ClassVisitor cv)
        {
            MethodVisitor mv;

            // public int exec(int returnAddress, int alternativeReturnAddress, bool isJump) throws Exception;
            mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.ExecMethodName, context.ExecMethodDesc, null, exceptions);
            mv.visitCode();
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, ClassName, context.StaticExecMethodName, context.StaticExecMethodDesc);
            mv.visitInsn(Opcodes.IRETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();

            // private static IExecutable e;
            FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, context.ReplaceFieldName, executableDescriptor, null, null);

            fv.visitEnd();

            // public void setExecutable(IExecutable e);
            mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.ReplaceMethodName, context.ReplaceMethodDesc, null, exceptions);
            mv.visitCode();
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitFieldInsn(Opcodes.PUTSTATIC, ClassName, context.ReplaceFieldName, executableDescriptor);
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(1, 2);
            mv.visitEnd();

            // public IExecutable getExecutable();
            mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.GetMethodName, context.GetMethodDesc, null, exceptions);
            mv.visitCode();
            mv.visitFieldInsn(Opcodes.GETSTATIC, ClassName, context.ReplaceFieldName, executableDescriptor);
            mv.visitInsn(Opcodes.ARETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        public override void Field(FieldReference field, Expression value)
        {
            //keep track of all static field->value, and initiate in <clinit> in done
            if (Modifier.isStatic(field.Modifiers()) && value != null)
            {
                _staticFields[field] = value;
            }
            FieldVisitor fieldVisitor = _classVisitor.visitField(field.Modifiers(), field.Name(), typeName(field.Type()), signature(field.Type()), null);

            fieldVisitor.visitEnd();
        }