private void suggestForType(ValueType type, StringBuilder sb) { if (type instanceof ValueType.Object) { suggestForClass(((ValueType.Object) type).getClassName(), sb); } else if (type instanceof ValueType.Array) { sb.append("Arr_"); suggestForType(((ValueType.Array) type).getItemType(), sb); } else { sb.append(type.toString()); } }
private void collectTypes(List<String> classNames) { for (String className : classNames) { types.add(ValueType.object(className)); } types.add(ValueType.object("java.lang.Class")); for (ValueType type : context.getNames().getTypes()) { if (type instanceof ValueType.Array) { types.add(ValueType.object("java.lang.Object")); } while (true) { if (!types.add(type)) { break; } if (!(type instanceof ValueType.Array)) { break; } type = ((ValueType.Array) type).getItemType(); } } }
public static boolean needsVirtualTable(Characteristics characteristics, ValueType type) { if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); if (className.equals(Address.class.getName())) { return false; } return !characteristics.isStructure(className); } else if (type instanceof ValueType.Array) { return needsVirtualTable(characteristics, ((ValueType.Array) type).getItemType()); } else { return true; } }
@Override public void createArray(VariableReader receiver, ValueType itemType, List<? extends VariableReader> dimensions) { DependencyNode node = getNode(receiver); for (int i = 0; i < dimensions.size(); ++i) { if (node == null) { break; } String itemTypeStr; if (itemType instanceof ValueType.Object) { itemTypeStr = ((ValueType.Object) itemType).getClassName(); } else { itemTypeStr = itemType.toString(); } node.propagate(getAnalyzer().getType(itemTypeStr)); node = node.getArrayItem(); itemType = ((ValueType.Array) itemType).getItemType(); } String className = extractClassName(itemType); if (className != null) { getAnalyzer().linkClass(className); } }
public boolean isSuperType(ValueType superType, ValueType subType, boolean defaultValue) { if (superType.equals(subType)) { return true; } if (superType instanceof ValueType.Primitive || subType instanceof ValueType.Primitive) { return false; } if (superType.isObject("java.lang.Object")) { return true; } if (superType instanceof ValueType.Object && subType instanceof ValueType.Object) { return isSuperType(((ValueType.Object) superType).getClassName(), ((ValueType.Object) subType).getClassName(), defaultValue); } else if (superType instanceof ValueType.Array & subType instanceof ValueType.Array) { return isSuperType(((ValueType.Array) superType).getItemType(), ((ValueType.Array) subType).getItemType(), defaultValue); } else { return false; } }
private Variable unwrapArray(CallLocation location, Variable var, ValueType.Array type) { ValueType itemType = type; int degree = 0; while (itemType instanceof ValueType.Array) { ++degree; itemType = ((ValueType.Array) itemType).getItemType(); } CastInstruction castInsn = new CastInstruction(); castInsn.setValue(var); castInsn.setTargetType(ValueType.parse(JSArrayReader.class)); var = program.createVariable(); castInsn.setReceiver(var); castInsn.setLocation(location.getSourceLocation()); replacement.add(castInsn); var = degree == 1 ? unwrapSingleDimensionArray(location, var, itemType) : unwrapMultiDimensionArray(location, var, itemType, degree); return var; }
private ValueType getWrappedType(ValueType type) { if (type instanceof ValueType.Array) { ValueType itemType = ((ValueType.Array) type).getItemType(); if (itemType instanceof ValueType.Array) { return ValueType.parse(Object[].class); } else { return ValueType.arrayOf(getWrappedType(itemType)); } } else if (type instanceof ValueType.Object) { if (type.isObject(String.class)) { return type; } else { return JSMethods.JS_OBJECT; } } else { return type; } }
public boolean isSupportedType(ValueType type) { if (type == ValueType.VOID) { return false; } if (type instanceof ValueType.Primitive) { switch (((ValueType.Primitive) type).getKind()) { case LONG: return false; default: return true; } } else if (type instanceof ValueType.Array) { return isSupportedType(((ValueType.Array) type).getItemType()); } else if (type instanceof ValueType.Object) { String typeName = ((ValueType.Object) type).getClassName(); return typeName.equals("java.lang.String") || isJavaScriptClass(typeName); } else { return false; } }
private void generateIsSupertypeFunction(ValueType type) { String name = context.getNames().forSupertypeFunction(type); vtableForwardWriter.println("static int32_t " + name + "(JavaClass*);"); isSupertypeWriter.println("static int32_t " + name + "(JavaClass* cls) {").indent(); if (type instanceof ValueType.Object) { generateIsSuperclassFunction(((ValueType.Object) type).getClassName()); } else if (type instanceof ValueType.Primitive) { generateIsSuperPrimitiveFunction((ValueType.Primitive) type); } else if (type == ValueType.VOID) { generateIsSuperclassFunction("java.lang.Void"); } else if (type instanceof ValueType.Array) { generateIsSuperArrayFunction(((ValueType.Array) type).getItemType()); } isSupertypeWriter.outdent().println("}"); }
@Override DependencyNode createArrayItemNode(DependencyNode parent) { ValueType itemTypeFilter = parent.typeFilter instanceof ValueType.Array ? ((ValueType.Array) parent.typeFilter).getItemType() : null; DependencyNode node = createNode(itemTypeFilter); node.degree = parent.degree + 1; node.method = parent.method; if (DependencyAnalyzer.shouldTag) { node.tag = parent.tag + "["; } return node; }
public ValueEmitter getElement(ValueEmitter index) { if (!(type instanceof ValueType.Array)) { throw new EmitException("Can't get element of non-array type: " + type); } ValueEmitter array = unwrapArray(); Variable result = pe.getProgram().createVariable(); ValueType.Array arrayType = (ValueType.Array) array.getType(); GetElementInstruction insn = new GetElementInstruction(getArrayElementType(arrayType.getItemType())); insn.setArray(array.variable); insn.setIndex(index.widenToInteger().variable); insn.setReceiver(result); pe.addInstruction(insn); return pe.var(result, ((ValueType.Array) type).getItemType()); }
private ValueEmitter unwrapArray() { ValueType elementType = ((ValueType.Array) type).getItemType(); Variable result = pe.getProgram().createVariable(); UnwrapArrayInstruction insn = new UnwrapArrayInstruction(getArrayElementType(elementType)); insn.setArray(variable); insn.setReceiver(result); pe.addInstruction(insn); return pe.var(result, type); }
private ValueType rename(ValueType type) { if (type instanceof ValueType.Array) { ValueType itemType = ((ValueType.Array) type).getItemType(); return referenceCache.getCached(ValueType.arrayOf(rename(itemType))); } else if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); return referenceCache.getCached(ValueType.object(classNameMapper.map(className))); } else { return type; } }
private void visitType(ValueType type) { while (type instanceof ValueType.Array) { type = ((ValueType.Array) type).getItemType(); } if (type instanceof ValueType.Object) { String clsName = ((ValueType.Object) type).getClassName(); consumer.consume(clsName); consumer.consumeFunction("$rt_cls"); } } @Override
protected final String extractClassName(ValueType itemType) { while (itemType instanceof ValueType.Array) { itemType = ((ValueType.Array) itemType).getItemType(); } return itemType instanceof ValueType.Object ? ((ValueType.Object) itemType).getClassName() : null; }
private boolean checkClass(TextLocation location, ValueType type) { while (type instanceof ValueType.Array) { type = ((ValueType.Array) type).getItemType(); } if (type instanceof ValueType.Object) { return checkClass(location, ((ValueType.Object) type).getClassName()); } return true; }
public boolean isSubtypeOf(ValueType supertype) { if (supertype instanceof ValueType.Object) { return !(this instanceof Primitive); } else if (supertype instanceof Array && this instanceof Array) { return ((Array) this).getItemType().isSubtypeOf(((Array) supertype).getItemType()); } else { return false; } }
private void linkType(DependencyAgent agent, ValueType type) { while (type instanceof ValueType.Array) { type = ((ValueType.Array) type).getItemType(); } if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); agent.linkClass(className); typesInReflectableSignaturesNode.propagate(agent.getType(className)); } }
private ValueType simplifyParamType(ValueType type) { if (type instanceof ValueType.Object) { return ValueType.object("java.lang.Object"); } else if (type instanceof ValueType.Array) { ValueType.Array array = (ValueType.Array) type; return ValueType.arrayOf(simplifyParamType(array.getItemType())); } else { return type; } } }
@Override public ReflectClass<?> getComponentType() { if (!(type instanceof ValueType.Array)) { return null; } ValueType componentType = ((ValueType.Array) type).getItemType(); return context.getClass(componentType); }