本文整理汇总了Java中jdk.nashorn.internal.codegen.types.Type.isObject方法的典型用法代码示例。如果您正苦于以下问题:Java Type.isObject方法的具体用法?Java Type.isObject怎么用?Java Type.isObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.codegen.types.Type
的用法示例。
在下文中一共展示了Type.isObject方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例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;
}
示例3: convertOptimisticReturnValue
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
void convertOptimisticReturnValue() {
if (isOptimistic) {
final Type optimisticType = getOptimisticCoercedType();
if(!optimisticType.isObject()) {
method.load(optimistic.getProgramPoint());
if(optimisticType.isInteger()) {
method.invoke(ENSURE_INT);
} else if(optimisticType.isLong()) {
method.invoke(ENSURE_LONG);
} else if(optimisticType.isNumber()) {
method.invoke(ENSURE_NUMBER);
} else {
throw new AssertionError(optimisticType);
}
}
}
}
示例4: setReturnType
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
/**
* Set the function return type
* @param lc lexical context
* @param returnType new return type
* @return function node or a new one if state was changed
*/
public FunctionNode setReturnType(final LexicalContext lc, final Type returnType) {
//we never bother with object types narrower than objects, that will lead to byte code verification errors
//as for instance even if we know we are returning a string from a method, the code generator will always
//treat it as an object, at least for now
final Type type = returnType.isObject() ? Type.OBJECT : returnType;
if (this.returnType == type) {
return this;
}
return Node.replaceInLexicalContext(
lc,
this,
new FunctionNode(
this,
lastToken,
endParserState,
flags,
name,
type,
compileUnit,
body,
parameters,
thisProperties,
rootClass, source, namespace
));
}
示例5: 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) {
if (name.length() > LARGE_STRING_THRESHOLD) { // use getIndex for extremely long names
return load(name).dynamicGetIndex(valueType, flags, isMethod);
}
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(NameCodec.encode(name),
Type.getMethodDescriptor(type, Type.OBJECT), LINKERBOOTSTRAP, flags | dynGetOperation(isMethod, isIndex));
pushType(type);
convert(valueType); //most probably a nop
return this;
}
示例6: setReturnType
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
/**
* Set the function return type
* @param lc lexical context
* @param returnType new return type
* @return function node or a new one if state was changed
*/
public FunctionNode setReturnType(final LexicalContext lc, final Type returnType) {
//we never bother with object types narrower than objects, that will lead to byte code verification errors
//as for instance even if we know we are returning a string from a method, the code generator will always
//treat it as an object, at least for now
final Type type = returnType.isObject() ? Type.OBJECT : returnType;
if (this.returnType == type) {
return this;
}
return Node.replaceInLexicalContext(
lc,
this,
new FunctionNode(
this,
lastToken,
endParserState,
flags,
name,
type,
compileUnit,
compilationState,
body,
parameters,
thisProperties,
rootClass, source, namespace
));
}
示例7: decideType
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
private static Type decideType(final Type lhsType, final Type rhsType) {
// Compare this to getWidestOperationType() for ADD and ASSIGN_ADD cases. There's some similar logic, but these
// are optimistic decisions, meaning that we don't have to treat boolean addition separately (as it'll become
// int addition in the general case anyway), and that we also don't conservatively widen sums of ints to
// longs, or sums of longs to doubles.
if(isString(lhsType) || isString(rhsType)) {
return Type.CHARSEQUENCE;
}
// NOTE: We don't have optimistic object-to-(int, long) conversions. Therefore, if any operand is an Object, we
// bail out of optimism here and presume a conservative Object return value, as the object's ToPrimitive() can
// end up returning either a number or a string, and their common supertype is Object, for better or worse.
final Type widest = Type.widest(undefinedToNumber(booleanToInt(lhsType)), undefinedToNumber(booleanToInt(rhsType)));
return widest.isObject() ? Type.OBJECT : widest;
}
示例8: getTypeChar
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
private static char getTypeChar(final Type type) {
if(type == Type.UNDEFINED) {
return 'U';
} else if(type.isObject()) {
return 'O';
} else if(type == Type.BOOLEAN) {
return 'Z';
}
return type.getBytecodeStackType();
}
示例9: convert
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
/**
* Pop element from stack, convert to given type
*
* @param to type to convert to
*
* @return the method emitter
*/
MethodEmitter convert(final Type to) {
final Type from = peekType();
final Type type = from.convert(method, to);
if (type != null) {
if (!from.isEquivalentTo(to)) {
debug("convert", from, "->", to);
}
if (type != from) {
final int l0 = stack.getTopLocalLoad();
popType();
pushType(type);
// NOTE: conversions from a primitive type are considered to preserve the "load" property of the value
// on the stack. Otherwise we could introduce temporary locals in a deoptimized rest-of (e.g. doing an
// "i < x.length" where "i" is int and ".length" gets deoptimized to long would end up converting i to
// long with "ILOAD i; I2L; LSTORE tmp; LLOAD tmp;"). Such additional temporary would cause an error
// when restoring the state of the function for rest-of execution, as the not-yet deoptimized variant
// would have the (now invalidated) assumption that "x.length" is an int, so it wouldn't have the I2L,
// and therefore neither the subsequent LSTORE tmp; LLOAD tmp;. By making sure conversions from a
// primitive type don't erase the "load" information, we don't introduce temporaries in the deoptimized
// rest-of that didn't exist in the more optimistic version that triggered the deoptimization.
// NOTE: as a more general observation, we could theoretically track the operations required to
// reproduce any stack value as long as they are all local loads, constant loads, and stack operations.
// We won't go there in the current system
if(!from.isObject()) {
stack.markLocalLoad(l0);
}
}
}
return this;
}
示例10: firstTypeGuess
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
/**
* The first type to try to use for this generated runtime node
*
* @return a type
*/
public Type firstTypeGuess() {
Type widest = Type.UNKNOWN;
for (final Type type : parameterTypes) {
if (type.isObject()) {
continue;
}
widest = Type.widest(type, widest);
}
widest = Type.widest(widest, firstTypeGuessForObject(request));
return widest;
}
示例11: convertOptimisticReturnValue
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
void convertOptimisticReturnValue() {
if (isOptimistic) {
final Type optimisticType = getOptimisticCoercedType();
if(!optimisticType.isObject()) {
method.load(optimistic.getProgramPoint());
if(optimisticType.isInteger()) {
method.invoke(ENSURE_INT);
} else if(optimisticType.isNumber()) {
method.invoke(ENSURE_NUMBER);
} else {
throw new AssertionError(optimisticType);
}
}
}
}
示例12: debug
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
private void debug(final int padConstant, final Object... args) {
if (debug) {
final StringBuilder sb = new StringBuilder();
int pad;
sb.append('#');
sb.append(++linePrefix);
pad = 5 - sb.length();
while (pad > 0) {
sb.append(' ');
pad--;
}
if (isReachable() && !stack.isEmpty()) {
sb.append("{");
sb.append(stack.size());
sb.append(":");
for (int pos = 0; pos < stack.size(); pos++) {
final Type t = stack.peek(pos);
if (t == Type.SCOPE) {
sb.append("scope");
} else if (t == Type.THIS) {
sb.append("this");
} else if (t.isObject()) {
String desc = t.getDescriptor();
int i;
for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) {
sb.append('[');
}
desc = desc.substring(i);
final int slash = desc.lastIndexOf('/');
if (slash != -1) {
desc = desc.substring(slash + 1, desc.length() - 1);
}
if ("Object".equals(desc)) {
sb.append('O');
} else {
sb.append(desc);
}
} else {
sb.append(t.getDescriptor());
}
final int loadIndex = stack.localLoads[stack.sp - 1 - pos];
if(loadIndex != Label.Stack.NON_LOAD) {
sb.append('(').append(loadIndex).append(')');
}
if (pos + 1 < stack.size()) {
sb.append(' ');
}
}
sb.append('}');
sb.append(' ');
}
pad = padConstant - sb.length();
while (pad > 0) {
sb.append(' ');
pad--;
}
for (final Object arg : args) {
sb.append(arg);
sb.append(' ');
}
if (context.getEnv() != null) { //early bootstrap code doesn't have inited context yet
log.info(sb);
if (DEBUG_TRACE_LINE == linePrefix) {
new Throwable().printStackTrace(log.getOutputStream());
}
}
}
}
示例13: descFor
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
private static char descFor(final Type type) {
if (type.isObject()) {
return 'O';
}
return type.getDescriptor().charAt(0);
}
示例14: objectToNumber
import jdk.nashorn.internal.codegen.types.Type; //导入方法依赖的package包/类
private static Type objectToNumber(final Type t) {
return t.isObject() ? Type.NUMBER : t;
}