public ThisVariable(IClass clazz) { this.globalVariableMeta = new Field(clazz, clazz, clazz, Opcodes.ACC_FINAL, ASConstants.THIS); }
@Override public final IClass getDeclaringClass() { return getMeta().getDeclaringClass(); }
@Override public IClass getResultType() { return globalVariableMeta.getType(); }
@Override public void push(MethodExecuteContext context) { if (!IClassUtils.visible(context.getMethod().getDeclaringClass(), meta.getDirectOwnerType(), meta.getDeclaringClass(), meta.getModifiers())) { throw new IllegalArgumentException("Cannot access field " + meta.getDeclaringClass() + "#" + meta.getName() + " from " + context.getMethod().getDeclaringClass()); } if (LOG.isPrintEnabled()) { LOG.print("get field " + meta.getName() + " from class " + meta.getDirectOwnerType().getName() + " and push to stack!"); } context.getInstructions().getStatic(owner.getType(), meta.getName(), meta.getType().getType()); }
if(gv.getName().equals(name)){ found.add(gv); try { java.lang.reflect.Field f = fieldOwner.getDeclaredField(name); found.add(new Field(this, classLoader.getType(fieldOwner), classLoader.getType(f.getType()), f.getModifiers(), name)); try { java.lang.reflect.Field f = inter.getDeclaredField(name); found.add(new Field(ProductClass.this, classLoader.getType(inter), classLoader.getType(f.getType()), f.getModifiers(), name)); errorSuffix.append(field.getDeclaringClass()).append(',');
@Override public void doExecute(MethodExecuteContext context) { if(LOG.isPrintEnabled()){ LOG.print("assign value to global variable '" + var.getMeta().getName() + "' from " + value ); } value.push(context); autoCast(context); context.getInstructions().putStatic(var.getOwner().getType(), var.getMeta().getName(), var.getMeta().getType().getType()); }
final LinkedList<Field> found = new LinkedList<>(); for (Field gv : getFields()) { if (gv.getName().equals(name)) { found.add(gv); errorSuffix.append(field.getDeclaringClass()).append(',');
@Override public GlobalVariable field(String name) { if(this.getResultType() instanceof ArrayClass){ throw new ASMSupportException("Cannot get global variable from array type variable : " + this); } try { Field field = getResultType().getField(name); if(Modifiers.isStatic(field.getModifiers())){ return new StaticGlobalVariable(field.getDeclaringClass(), field); } else { return new NonStaticGlobalVariable(this, field); } } catch (NoSuchFieldException e) { throw new ASMSupportException(e); } }
@Override public void execute(ClassExecuteContext context) { if(value != null && !Modifiers.isStatic(modifiers)) { throw new ASMSupportException("The initial value '" + value + "' of field '" + name + "' is invalided, cause by the field is not static, and the initial value only support static field."); } if(value != null && value instanceof Boolean) { value = (Boolean) value ? 1 : 0; } context.getClassVisitor().visitField( fe.getModifiers(), name, fe.getType().getDescription(), null, value).visitEnd(); }
@Override public GlobalVariable field(String name) { if(value != null && value instanceof IClass) { try { Field field = ((IClass)value).getField(name); if(Modifiers.isStatic(field.getModifiers())) { return new StaticGlobalVariable((IClass)value, field); } else { throw new ASMSupportException("No such field " + name); } } catch (NoSuchFieldException e) { throw new ASMSupportException(e); } } return null; } }
@Override public void push(MethodExecuteContext context) { if(!IClassUtils.visible(context.getMethod().getDeclaringClass(), meta.getDirectOwnerType(), meta.getDeclaringClass(), meta.getModifiers())){ throw new IllegalArgumentException("Cannot access field " + meta.getDeclaringClass() + "#" + meta.getName() + " from " + context.getMethod().getDeclaringClass()); } if(LOG.isPrintEnabled()){ LOG.print("Get field " + meta.getName() + " from variable " + meta.getName() + " and push to stack!"); } owner.push(context); context.getInstructions().getField(meta.getDirectOwnerType().getType(), meta.getName(), meta.getType().getType()); }
/** * * @param var */ public void commonPutField(ExplicitVariable var) { if (var instanceof LocalVariable) { storeInsn((LocalVariable) var); } else if (var instanceof NonStaticGlobalVariable) { NonStaticGlobalVariable gv = (NonStaticGlobalVariable) var; putField(gv.getOwner().getResultType().getType(), gv.getMeta().getName(), gv .getMeta().getType().getType()); } else if (var instanceof StaticGlobalVariable) { StaticGlobalVariable gv = (StaticGlobalVariable) var; putStatic(gv.getOwner().getType(), gv.getMeta().getName(), gv.getMeta().getType() .getType()); } }
@Override public final GlobalVariable field(String name) { if(this.getResultType() instanceof ArrayClass){ throw new ASMSupportException("Cannot get global variable from array type variable : " + this); } try { Field field = getMeta().getType().getField(name); if(Modifiers.isStatic(field.getModifiers())){ return new StaticGlobalVariable(field.getDeclaringClass(), field); } else { return new NonStaticGlobalVariable(this, field); } } catch (NoSuchFieldException e) { throw new ASMSupportException(e); } }
@Override public void doExecute(MethodExecuteContext context) { if(LOG.isPrintEnabled()){ LOG.print("assign value to global variable '" + var.getMeta().getName() + "' from " + value ); } KernelProgramBlock block = getParent(); if(Modifier.isStatic(block.getMethod().getMeta().getModifiers())){ throw new ASMSupportException("Current method " + block.getMethod() + " is static cannot use non-static field " + var.getMeta().getName() ); } var.getOwner().push(context); value.push(context); autoCast(context); context.getInstructions().putField(var.getOwner().getResultType().getType(), var.getMeta().getName(), var.getMeta().getType().getType()); }
@Override protected boolean process(Class<?> inter) { try { java.lang.reflect.Field f = inter.getDeclaredField(name); found.add(new Field(ProductClass.this, classLoader.getType(inter), classLoader.getType(f.getType()), f.getModifiers(), name)); return true; } catch (NoSuchFieldException e) { return false; } } }.loop(reallyClass.getInterfaces());
@Override public IClass getResultType() { return field.getType(); }
@Override public void initialized(ClassExecuteContext context) { MutableClass owner = (MutableClass) context.getOwner(); owner.addField(fe = new Field(owner, owner, type, modifiers, name)); }
@Override public IClass getResultType() { return meta.getType(); }
public SuperVariable(IClass clazz) { this.field = new Field( clazz.getSuperclass(), clazz.getSuperclass(), clazz.getSuperclass(), Opcodes.ACC_FINAL, ASConstants.SUPER); }
@Override public IClass getResultType() { return meta.getType(); }