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 boolean isReferenceType(ValueType type) { if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); return !context.getCharacteristics().isStructure(className) && !className.equals(Address.class.getName()); } else { return type instanceof ValueType.Array; } }
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; } }
private ValueEmitter boxPrimitive(ValueType type) { if (!(type instanceof ValueType.Object)) { throw new EmitException("Can't convert " + this.type + " to " + type); } String targetClass = ((ValueType.Object) type).getClassName(); PrimitiveType primitiveType = ((ValueType.Primitive) this.type).getKind(); String boxClassName = getPrimitiveClassName(primitiveType); ValueEmitter result = invokeValueOf(boxClassName); if (!pe.hierarchy.isSuperType(targetClass, boxClassName, false)) { throw new EmitException("Can't convert " + this.type + " to " + targetClass); } return result; }
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("}"); }
public ValueEmitter invoke(InvocationType invokeType, String name, ValueType resultType, ValueEmitter... arguments) { return invoke(invokeType, ((ValueType.Object) type).getClassName(), name, resultType, arguments); }
public ProgramEmitter setField(String name, ValueEmitter value) { if (!(type instanceof ValueType.Object)) { throw new EmitException("Can't get field of non-object type: " + type); } String className = ((ValueType.Object) type).getClassName(); PutFieldInstruction insn = new PutFieldInstruction(); insn.setField(new FieldReference(className, name)); insn.setFieldType(type); insn.setInstance(variable); insn.setValue(value.getVariable()); pe.addInstruction(insn); return pe; }
@Override public void visit(CastExpr expr) { if (expr.getTarget() instanceof ValueType.Object) { String className = ((ValueType.Object) expr.getTarget()).getClassName(); if (context.getCharacteristics().isStructure(className) || className.equals(Address.class.getName())) { expr.getValue().acceptVisitor(this); return; } } writer.print("checkcast("); expr.getValue().acceptVisitor(this); writer.print(", ").print(names.forSupertypeFunction(expr.getTarget())).print(")"); }
private boolean matchCacheMiss(DependencyType type) { if (!type.getName().startsWith("[")) { return false; } String typeName = type.getName().substring(1); ValueType valueType = ValueType.parseIfPossible(typeName); if (valueType == null || valueType instanceof ValueType.Primitive) { return false; } if (valueType instanceof ValueType.Object) { typeName = ((ValueType.Object) valueType).getClassName(); } return itemTypeFilter.match(analyzer.getType(typeName)); }
private void reachGetComponentType(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(t -> { if (!t.getName().startsWith("[")) { return; } String typeName = t.getName().substring(1); if (typeName.charAt(0) == 'L') { typeName = ((ValueType.Object) ValueType.parse(typeName)).getClassName(); } method.getResult().getClassValueNode().propagate(agent.getType(typeName)); }); }
public void resolve() { if (resolved) { return; } resolved = true; if (!(type instanceof ValueType.Object)) { return; } String className = ((ValueType.Object) type).getClassName(); classReader = context.getClassSource().get(className); }
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 String[] getExpectedExceptions(MethodHolder method) { AnnotationHolder annot = method.getAnnotations().get(JUNIT4_TEST); if (annot == null) { return new String[0]; } AnnotationValue expected = annot.getValue("expected"); if (expected == null) { return new String[0]; } ValueType result = expected.getJavaClass(); return new String[] { ((ValueType.Object) result).getClassName() }; }
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; }
Variable unwrapReturnValue(CallLocation location, Variable var, ValueType type) { if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); ClassReader cls = classSource.get(className); if (cls != null && cls.getAnnotations().get(JSFunctor.class.getName()) != null) { return unwrapFunctor(location, var, cls); } } return unwrap(location, var, type); }
Variable wrapArgument(CallLocation location, Variable var, ValueType type, boolean byRef) { if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); ClassReader cls = classSource.get(className); if (cls != null && cls.getAnnotations().get(JSFunctor.class.getName()) != null) { return wrapFunctor(location, var, cls); } } return wrap(var, type, location.getSourceLocation(), byRef); }
public static String getClassLiteral(IntrinsicContext context, InvocationExpr invocation, Expr expr) { if (expr instanceof ConstantExpr) { Object cst = ((ConstantExpr) expr).getValue(); if (cst instanceof ValueType.Object) { return ((ValueType.Object) cst).getClassName(); } } context.getDiagnotics().error( new CallLocation(context.getCallingMethod(), invocation.getLocation()), "This method should take class literal"); return "java.lang.Object"; }
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)); } }