当前位置: 首页>>代码示例>>Java>>正文


Java Type类代码示例

本文整理汇总了Java中jdk.nashorn.internal.codegen.types.Type的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Type类属于jdk.nashorn.internal.codegen.types包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCallSiteType

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
MethodType getCallSiteType(final FunctionNode functionNode) {
    final Type[] types = paramTypeMap.get(functionNode.getId());
    if (types == null) {
        return null;
    }

    MethodType mt = MethodType.methodType(returnTypeMap.get(functionNode.getId()).getTypeClass());
    if (needsCallee) {
        mt = mt.appendParameterTypes(ScriptFunction.class);
    }

    mt = mt.appendParameterTypes(Object.class); //this

    for (final Type type : types) {
        if (type == null) {
            return null; // not all parameter information is supplied
        }
        mt = mt.appendParameterTypes(type.getTypeClass());
    }

    return mt;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:TypeMap.java

示例2: dynamicGet

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
/**
 * Generate dynamic getter. Pop scope from stack. Push result
 *
 * @param valueType type of the value to set
 * @param name      name of property
 * @param flags     call site flags
 * @param isMethod  should it prefer retrieving methods
 * @param isIndex   is this an index operation?
 * @return the method emitter
 */
MethodEmitter dynamicGet(final Type valueType, final String name, final int flags, final boolean isMethod, final boolean isIndex) {
    debug("dynamic_get", name, valueType, getProgramPoint(flags));

    Type type = valueType;
    if (type.isObject() || type.isBoolean()) {
        type = Type.OBJECT; //promote e.g strings to object generic setter
    }

    popType(Type.SCOPE);
    method.visitInvokeDynamicInsn(dynGetOperation(isMethod, isIndex) + ':' + NameCodec.encode(name),
            Type.getMethodDescriptor(type, Type.OBJECT), LINKERBOOTSTRAP, flags);

    pushType(type);
    convert(valueType); //most probably a nop

    return this;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:MethodEmitter.java

示例3: enterReturnNode

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExprType = visitExpressionOnEmptyStack(returnExpr).type;
    } else {
        assertTypeStackIsEmpty();
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:LocalVariableTypesCalculator.java

示例4: evaluate

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
@Override
protected void evaluate() {
    final Expression lhs = assignNode.lhs();
    final Expression rhs = assignNode.rhs();
    final Type widestOperationType = assignNode.getWidestOperationType();
    final TypeBounds bounds = new TypeBounds(assignNode.getType(), widestOperationType);
    new OptimisticOperation(assignNode, bounds) {
        @Override
        void loadStack() {
            final boolean forceConversionSeparation;
            if (isValid(getProgramPoint()) || widestOperationType == Type.NUMBER) {
                forceConversionSeparation = false;
            } else {
                final Type operandType = Type.widest(booleanToInt(objectToNumber(lhs.getType())), booleanToInt(objectToNumber(rhs.getType())));
                forceConversionSeparation = operandType.narrowerThan(widestOperationType);
            }
            loadBinaryOperands(lhs, rhs, bounds, true, forceConversionSeparation);
        }
        @Override
        void consumeStack() {
            op(this);
        }
    }.emit(getOptimisticIgnoreCountForSelfModifyingExpression(lhs));
    method.convert(assignNode.getType());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:CodeGenerator.java

示例5: computeElementType

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
private static Type computeElementType(final Expression[] value) {
    Type widestElementType = Type.INT;

    for (final Expression elem : value) {
        if (elem == null) {
            widestElementType = widestElementType.widest(Type.OBJECT); //no way to represent undefined as number
            break;
        }

        final Type type = elem.getType().isUnknown() ? Type.OBJECT : elem.getType();
        if (type.isBoolean()) {
            //TODO fix this with explicit boolean types
            widestElementType = widestElementType.widest(Type.OBJECT);
            break;
        }

        widestElementType = widestElementType.widest(type);
        if (widestElementType.isObject()) {
            break;
        }
    }
    return widestElementType;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:LiteralNode.java

示例6: getDynamicSignature

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:MethodEmitter.java

示例7: requestRecompile

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
boolean requestRecompile(final RewriteException e) {
    final Type retType            = e.getReturnType();
    final Type previousFailedType = invalidatedProgramPoints.put(e.getProgramPoint(), retType);

    if (previousFailedType != null && !previousFailedType.narrowerThan(retType)) {
        final StackTraceElement[] stack      = e.getStackTrace();
        final String              functionId = stack.length == 0 ?
                data.getName() :
                stack[0].getClassName() + "." + stack[0].getMethodName();

        log.info("RewriteException for an already invalidated program point ", e.getProgramPoint(), " in ", functionId, ". This is okay for a recursive function invocation, but a bug otherwise.");

        return false;
    }

    SwitchPoint.invalidateAll(new SwitchPoint[] { optimisticAssumptions });

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:CompiledFunction.java

示例8: enterReturnNode

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
    if(!reachable) {
        return false;
    }

    final Expression returnExpr = returnNode.getExpression();
    final Type returnExprType;
    if(returnExpr != null) {
        returnExpr.accept(this);
        returnExprType = getType(returnExpr);
    } else {
        returnExprType = Type.UNDEFINED;
    }
    returnType = Type.widestReturnType(returnType, returnExprType);
    doesNotContinueSequentially();
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:LocalVariableTypesCalculator.java

示例9: ensureInt

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
@SuppressWarnings("unused")
private static int ensureInt(final double arg, final int programPoint) {
    if (JSType.isStrictlyRepresentableAsInt(arg)) {
        return (int)arg;
    }
    throw new UnwarrantedOptimismException(arg, programPoint, Type.NUMBER);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:OptimisticReturnFilters.java

示例10: OptimisticOperation

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
OptimisticOperation(final Optimistic optimistic, final TypeBounds resultBounds) {
    this.optimistic = optimistic;
    this.expression = (Expression)optimistic;
    this.resultBounds = resultBounds;
    this.isOptimistic = isOptimistic(optimistic) && useOptimisticTypes() &&
            // Operation is only effectively optimistic if its type, after being coerced into the result bounds
            // is narrower than the upper bound.
            resultBounds.within(Type.generic(((Expression)optimistic).getType())).narrowerThan(resultBounds.widest);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:CodeGenerator.java

示例11: load

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
/**
 * Push a String constant to the stack
 *
 * @param s value of the String
 *
 * @return the method emitter
 */
MethodEmitter load(final String s) {
    debug("load string", s);

    if (s == null) {
        loadNull();
        return this;
    }

    //NASHORN-142 - split too large string
    final int length = s.length();
    if (length > LARGE_STRING_THRESHOLD) {

        _new(StringBuilder.class);
        dup();
        load(length);
        invoke(constructorNoLookup(StringBuilder.class, int.class));

        for (int n = 0; n < length; n += LARGE_STRING_THRESHOLD) {
            final String part = s.substring(n, Math.min(n + LARGE_STRING_THRESHOLD, length));
            load(part);
            stringBuilderAppend();
        }

        invoke(virtualCallNoLookup(StringBuilder.class, "toString", String.class));

        return this;
    }

    pushType(Type.OBJECT.ldc(method, s));
    return this;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:MethodEmitter.java

示例12: storeIdentWithCatchConversion

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
private void storeIdentWithCatchConversion(final IdentNode identNode, final Type type) {
    // Assignments happening in try/catch blocks need to ensure that they also store a possibly wider typed value
    // that will be live at the exit from the try block
    final LocalVariableConversion conversion = identNode.getLocalVariableConversion();
    final Symbol symbol = identNode.getSymbol();
    if(conversion != null && conversion.isLive()) {
        assert symbol == conversion.getSymbol();
        assert symbol.isBytecodeLocal();
        // Only a single conversion from the target type to the join type is expected.
        assert conversion.getNext() == null;
        assert conversion.getFrom() == type;
        // We must propagate potential type change to the catch block
        final Label catchLabel = catchLabels.peek();
        assert catchLabel != METHOD_BOUNDARY; // ident conversion only exists in try blocks
        assert catchLabel.isReachable();
        final Type joinType = conversion.getTo();
        final Label.Stack catchStack = catchLabel.getStack();
        final int joinSlot = symbol.getSlot(joinType);
        // With nested try/catch blocks (incl. synthetic ones for finally), we can have a supposed conversion for
        // the exception symbol in the nested catch, but it isn't live in the outer catch block, so prevent doing
        // conversions for it. E.g. in "try { try { ... } catch(e) { e = 1; } } catch(e2) { ... }", we must not
        // introduce an I->O conversion on "e = 1" assignment as "e" is not live in "catch(e2)".
        if(catchStack.getUsedSlotsWithLiveTemporaries() > joinSlot) {
            method.dup();
            method.convert(joinType);
            method.store(symbol, joinType);
            catchLabel.getStack().onLocalStore(joinType, joinSlot, true);
            method.canThrow(catchLabel);
            // Store but keep the previous store live too.
            method.store(symbol, type, false);
            return;
        }
    }

    method.store(symbol, type, true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:CodeGenerator.java

示例13: createEmptyGetter

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String name) {
    if (NashornCallSiteDescriptor.isOptimistic(desc)) {
        throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
    }

    return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()),
            NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck), getProtoSwitchPoint(name, null),
            explicitInstanceOfCheck ? null : ClassCastException.class);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:ScriptObject.java

示例14: fieldType

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
@SuppressWarnings("fallthrough")
private static Type fieldType(final String desc) {
    switch (desc) {
    case "Z":
    case "B":
    case "C":
    case "S":
    case "I":
        return Type.INT;
    case "F":
        assert false;
    case "D":
        return Type.NUMBER;
    case "J":
        return Type.LONG;
    default:
        assert desc.startsWith("[") || desc.startsWith("L") : desc + " is not an object type";
        switch (desc.charAt(0)) {
        case 'L':
            return Type.OBJECT;
        case '[':
            return Type.typeFor(Array.newInstance(fieldType(desc.substring(1)).getTypeClass(), 0).getClass());
        default:
            assert false;
        }
        return Type.OBJECT;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:MethodEmitter.java

示例15: computePresets

import jdk.nashorn.internal.codegen.types.Type; //导入依赖的package包/类
static Object computePresets(final Expression[] value, final Type elementType, final int[] postsets) {
    assert !elementType.isUnknown();
    if (elementType.isInteger()) {
        return presetIntArray(value, postsets);
    } else if (elementType.isNumeric()) {
        return presetDoubleArray(value, postsets);
    } else {
        return presetObjectArray(value, postsets);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:LiteralNode.java


注:本文中的jdk.nashorn.internal.codegen.types.Type类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。