/** * Get {@code null} value * * @param type * @return */ public static Value getNullValue(IClass type) { if (type.isPrimitive()) { throw new IllegalArgumentException("the type of null value cannot be primitive type!"); } return defaultValue(type); }
protected StaticMethodInvoker(KernelProgramBlock block, IClass owner, String name, KernelParam[] arguments) { super(block, owner, name, arguments); if (owner.isPrimitive()) { throw new IllegalArgumentException("Cannot call static method from primitive"); } setSaveReference(false); }
private String getDescription(IClass root, int dim) { StringBuilder nameKey = new StringBuilder(); while (dim-- > 0) { nameKey.append('['); } if (root.isPrimitive()) { nameKey.append(root.getDescription()); } else { nameKey.append(root.getDescription()); } return nameKey.toString(); }
/** * Check the specify whether or not as an arithmetical operation factor. */ public static boolean isArithmetical(IClass type) { if (type.isPrimitive() && !type.getName().equals(boolean.class.getName())) { return true; } else if (isPrimitiveWrapAClass(type) && !type.getName().equals(Boolean.class.getName())) { return true; } return false; }
@Override public final KernelCast checkcast(KernelParam cc, IClass to) { if (to.isPrimitive()) { throw new IllegalArgumentException("Cannot check cast to type " + to + " from " + cc.getResultType()); } return OperatorFactory.newOperator(KernelCast.class, new Class<?>[] { KernelProgramBlock.class, KernelParam.class, IClass.class }, getExecutor(), cc, to); }
/** * * @param block * @param argumentClasses * @param arguments */ protected ConstructorInvoker(KernelProgramBlock block, IClass argumentClasses, KernelParam[] arguments) { super(block, argumentClasses, ASConstants.INIT, arguments); if (argumentClasses.isPrimitive()) { throw new IllegalArgumentException("Cannot new a primitive class"); }else if(argumentClasses.isAbstract()){ throw new IllegalArgumentException(argumentClasses.getName() + "is an abstract class cannot new an abstract class"); } //default to don't save return result reference of this method. setSaveReference(false); }
@Override protected void verifyArgument() { if(obj.getResultType().isPrimitive()){ throw new ASMSupportException("Incompatible conditional operand types " + obj.getResultType() + " int and " + type); } }
protected final void checkFactorForNumerical(IClass ftrCls){ if(!ftrCls.isPrimitive() || ftrCls.equals(getType(boolean.class))){ throw new ASMSupportException("this operator " + getOperatorSymbol().getSymbol() + " cannot support for type " + ftrCls ); } }
@Override protected void verifyArgument() { IClass leftPrimitiveType = IClassUtils.getPrimitiveAClass(leftFactor.getResultType()); IClass rightPrimitiveType = IClassUtils.getPrimitiveAClass(rightFactor.getResultType()); if(!(leftPrimitiveType.equals(getType(boolean.class)) && rightPrimitiveType.equals(getType(boolean.class))) && leftPrimitiveType.isPrimitive() && rightPrimitiveType.isPrimitive()){ checkFactorForNumerical(leftPrimitiveType); checkFactorForNumerical(rightPrimitiveType); } }
@Override public boolean match(IClass type, ClassHolder holder) { return type.isPrimitive() || type.isChildOrEqual(holder.getType(CharSequence.class)) || IClassUtils.isPrimitiveWrapAClass(type); }
private void cast(MethodExecuteContext context, IClass from, IClass to){ Instructions instructions = context.getInstructions(); if(from.isPrimitive() && to.isPrimitive()){ instructions.cast(from.getType(), to.getType()); }else if(from.isPrimitive()){ instructions.box(from.getType()); }else if(IClassUtils.isPrimitiveWrapAClass(from) && to.isPrimitive()){ Type primType = Instructions.getUnBoxedType(from.getType()); instructions.unbox(from.getType()); instructions.cast(primType, to.getType()); } }
protected AbstractCrement(KernelProgramBlock block, KernelParam factor, Operator operator) { super(block, operator); IClass resultType = factor.getResultType(); if(resultType != null && !getType(boolean.class).equals(resultType) && !getType(Boolean.class).equals(resultType) && (IClassUtils.isPrimitiveWrapAClass(resultType) || resultType.isPrimitive())) { this.factor = factor; } else { throw new ASMSupportException("Can't do '" + operator + "' on : " + factor); } }
protected final void checkFactor(IClass ftrCls){ if(ftrCls.isPrimitive() || IClassUtils.isPrimitiveWrapAClass(ftrCls)){ if(ftrCls.equals(getType(boolean.class)) || ftrCls.equals(getType(float.class)) || ftrCls.equals(getType(double.class)) || ftrCls.equals(getType(Boolean.class)) || ftrCls.equals(getType(Float.class)) || ftrCls.equals(getType(Double.class))){ throw new ASMSupportException("this operator " + getOperatorSymbol().getSymbol() + " cannot support for type " + ftrCls ); } } }
protected CommonMethodInvoker(KernelProgramBlock block, KernelParam objRef, String name, KernelParam[] arguments) { super(block, objRef.getResultType(), name, arguments); this.callObjReference = objRef; if(callObjReference.getResultType().isPrimitive()){ throw new IllegalArgumentException("Cannot invoke method at primitive type \"" + callObjReference.getResultType() + "\" : must be a non-primitive variable"); } if(callObjReference instanceof MethodInvoker){ //set the method caller to save reference; ((MethodInvoker)callObjReference).setSaveReference(true); } else { //default to don't save return result reference of this method. setSaveReference(false); } }
/** * <strong>4.10 Subtyping</strong> * <p>The subtype and supertype relations are binary relations on types.</p> * <p>get direct super type</p> * @param subType * @return */ public static IClass[] directSuperType(IClass subType) { if(subType.isPrimitive()) { IClass type = directSuperAmongPrimitiveType(subType); if(type == null) { return null; } else { return new IClass[]{type}; } } else if (subType.isArray()) { return directSuperAmongArrayType(subType); } else { return directSuperAmongClassAndInterfaceType(subType); } }
@Override public void doExecute(MethodExecuteContext context) { KernelProgramBlock block = getParent(); orginal.push(context); IClass from = orginal.getResultType(); if(to.equals(from)){ return; } if(from.isPrimitive() && to.isPrimitive()){ if(LOG.isPrintEnabled()) { LOG.print("checkcast from " + from + " to " + to ); } if(from.getCastOrder() > to.getCastOrder() || (from.equals(block.getType(char.class)) && to.equals(block.getType(short.class))) || (to.equals(block.getType(char.class)) && from.equals(block.getType(short.class)))){ context.getInstructions().cast(from.getType(), to.getType()); return; } } if(LOG.isPrintEnabled()) { LOG.print("checkcast from " + from + " to " + to ); } context.getInstructions().checkCast(to.getType()); }
protected final void invokeVerify(IClass a) { if (a.isInterface()) { throw new MethodInvokeException("The class " + getExecutor().getMethodDeclaringClass() + " is a interface and interfaces have no static methods"); } if (a.isPrimitive()) { throw new MethodInvokeException("the class " + getExecutor().getMethodDeclaringClass() + " is a primitive and primitive cannot as a method invoker owner"); } }
@Override protected void init() { if (lock.getResultType() == null || lock.getResultType().isPrimitive() || lock.getResultType().getType().equals(Type.VOID_TYPE)) { throw new IllegalArgumentException(lock + " is not a valid type's argument for the synchronized statement"); } lock.asArgument(); AbstractMethodBody methodBody = getMethod().getBody(); methodBody.addExceptionTableEntry(monitorenter, monitorexit, excetpionStart, null); methodBody.addExceptionTableEntry(excetpionStart, excetpionEnd, excetpionStart, null); }
@Override protected void verifyArgument() { if(leftFactor.getResultType().isPrimitive() && isNullValue(rightFactor)) { throw new ASMSupportException("The operator '" + getOperatorSymbol().getSymbol() + "' cannot be applied to " + leftFactor.getResultType().getName() + ", null"); } else if (rightFactor.getResultType().isPrimitive() && isNullValue(leftFactor)) { throw new ASMSupportException("The operator '" + getOperatorSymbol().getSymbol() + "' cannot be applied to null, " + rightFactor.getResultType().getName()); } super.verifyArgument(); }
private void pushFactorToStack(MethodExecuteContext context, KernelParam factor) { IClass factorCls = factor.getResultType(); Instructions instructions = context.getInstructions(); // factor to stack LOG.print("push the first arithmetic factor to stack"); factor.push(context); IClass factorPrimitiveAClass = factorCls; // unbox if needs if (!factorCls.isPrimitive()) { LOG.print("unbox " + factorCls); instructions.unbox(factorCls.getType()); factorPrimitiveAClass = IClassUtils.getPrimitiveAClass(factorCls); } // cast if needs if (factorPrimitiveAClass.getCastOrder() < targetClass.getCastOrder() && targetClass.getCastOrder() > getType(int.class).getCastOrder()) { LOG.print("cast factor from " + factorCls + " to " + targetClass); instructions.cast(factorPrimitiveAClass.getType(), targetClass.getType()); } }