private boolean matchSignature(ClassHierarchy hierarchy, MethodReader functionMethod, MethodReader candidateMethod) { if (functionMethod.parameterCount() > candidateMethod.parameterCount()) { return false; } for (int i = 0; i < functionMethod.parameterCount(); ++i) { if (!hierarchy.isSuperType(functionMethod.parameterType(i), candidateMethod.parameterType(i), false)) { return false; } } return true; }
@Override public boolean optimize(MethodOptimizationContext context, Program program) { MethodReader method = context.getMethod(); return new LoopInversionImpl(program, method.getReference(), method.parameterCount() + 1).apply(); } }
private MethodReference createCallbackMethod(MethodReader method) { int paramCount = method.parameterCount(); if (!method.hasModifier(ElementModifier.STATIC)) { paramCount++; } ValueType[] signature = new ValueType[paramCount + 1]; for (int i = 0; i < paramCount; ++i) { signature[i] = ValueType.object(JSObject.class.getName()); } signature[paramCount] = method.getResultType() == ValueType.VOID ? ValueType.VOID : ValueType.object(JSObject.class.getName()); return new MethodReference(location.getMethod().getClassName(), method.getName() + "$jsocb$_" + idGenerator++, signature); }
private boolean isProperSetter(MethodReader method) { if (method.parameterCount() != 1 || !typeHelper.isSupportedType(method.parameterType(0)) || method.getResultType() != ValueType.VOID) { return false; } return extractSuggestedPropertyName(method) != null || isProperPrefix(method.getName(), "set"); }
private MethodModel findMetaMethod(MethodReader method) { ClassReader cls = classSource.get(method.getOwnerName()); boolean isStatic = method.hasModifier(ElementModifier.STATIC); int expectedParameterCount = (isStatic ? 0 : 1) + method.parameterCount(); for (MethodReader meta : cls.getMethods()) { if (meta == method || !meta.getName().equals(method.getName()) || meta.getResultType() != ValueType.VOID || meta.parameterCount() != expectedParameterCount) { continue; if (meta.parameterCount() == 0 || meta.parameterType(0).isObject(Value.class)) { return null; for (int i = 0; i < method.parameterCount(); ++i) { ValueType proxyParam = meta.parameterType(i + paramOffset); if (proxyParam.isObject(ReflectClass.class)) {
csLiveIn.clear(0, method.parameterCount() + 1); blockLiveIn.put(insn, csLiveIn);
boolean[] byRefParams = new boolean[method.parameterCount() + 1]; if (!validateSignature(method, callLocation, byRefParams)) { return false; newInvoke.setMethod(JSMethods.invoke(method.parameterCount())); newInvoke.setType(InvocationType.SPECIAL); newInvoke.setReceiver(result);
private boolean isProperGetter(MethodReader method) { if (method.parameterCount() > 0 || !typeHelper.isSupportedType(method.getResultType())) { return false; } if (extractSuggestedPropertyName(method) != null) { return true; } if (method.getResultType().equals(ValueType.BOOLEAN)) { if (isProperPrefix(method.getName(), "is")) { return true; } } return isProperPrefix(method.getName(), "get"); }
AnnotationValue paramsValue = bodyAnnot.getValue("params"); int jsParamCount = paramsValue != null ? paramsValue.getList().size() : 0; if (methodToProcess.parameterCount() != jsParamCount) { diagnostics.error(location, "JSBody method {{m0}} declares " + methodToProcess.parameterCount() + " parameters, but annotation specifies " + jsParamCount, methodToProcess.getReference()); return; int paramCount = methodToProcess.parameterCount(); if (!isStatic) { ++paramCount;
private boolean processJSBodyInvocation(MethodReader method, CallLocation callLocation, InvokeInstruction invoke, MethodHolder methodToProcess) { boolean[] byRefParams = new boolean[method.parameterCount()]; validateSignature(method, callLocation, byRefParams); if (invoke.getInstance() != null) {
public static MethodHolder copyMethod(MethodReader method, boolean withProgram) { MethodHolder copy = new MethodHolder(method.getDescriptor()); copy.setLevel(method.getLevel()); copy.getModifiers().addAll(method.readModifiers()); if (method.getProgram() != null && withProgram) { copy.setProgram(ProgramUtils.copy(method.getProgram())); } copyAnnotations(method.getAnnotations(), copy.getAnnotations()); if (method.getAnnotationDefault() != null) { copy.setAnnotationDefault(copyAnnotationValue(method.getAnnotationDefault())); } for (int i = 0; i < method.parameterCount(); ++i) { copyAnnotations(method.parameterAnnotation(i), copy.parameterAnnotation(i)); } return copy; }
ValueType.object(calleeRef.getClassName()))); Variable[] args = new Variable[callee.parameterCount()]; for (int i = 0; i < callee.parameterCount(); ++i) { args[i] = marshaller.unwrapReturnValue(location, program.variableAt(paramIndex++), callee.parameterType(i));
boolean[] used = new boolean[escaping.length]; for (int i = 0; i <= method.parameterCount(); ++i) { used[i] = true;
private void validateSignature(MethodReader method) { if (!method.hasModifier(ElementModifier.STATIC)) { if (!typeHelper.isJavaScriptClass(method.getOwnerName())) { diagnostics.error(location, "Can't call method {{m0}} of non-JS class", method.getReference()); } } for (int i = 0; i < method.parameterCount(); ++i) { if (!typeHelper.isSupportedType(method.parameterType(i))) { diagnostics.error(location, "Invalid type {{t0}} of parameter " + (i + 1) + " of method {{m1}}", method.parameterType(i), method.getReference()); } } if (method.getResultType() != ValueType.VOID && !typeHelper.isSupportedType(method.getResultType())) { diagnostics.error(location, "Invalid type {{t0}} of return value of method {{m1}}", method.getResultType(), method.getReference()); } }
private void renderCallable(SourceWriter writer, MethodReader method) throws IOException { writer.append("function(obj,").ws().append("args)").ws().append("{").indent().softNewLine(); initClass(writer, method); if (method.getResultType() != ValueType.VOID) { writer.append("return "); } writer.appendMethodBody(method.getReference()); writer.append('('); boolean first = true; if (!method.hasModifier(ElementModifier.STATIC)) { writer.append("obj").ws(); first = false; } for (int i = 0; i < method.parameterCount(); ++i) { if (!first) { writer.append(',').ws(); } first = false; int index = i; unboxIfNecessary(writer, method.parameterType(i), () -> writer.append("args[" + index + "]")); } writer.append(");").softNewLine(); if (method.getResultType() == ValueType.VOID) { writer.append("return null;").softNewLine(); } writer.outdent().append("}"); }
private void handleNewInstance(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getConstructors) .addLocation(location) .getVariable(0).getClassValueNode(); classValueNode.addConsumer(reflectedType -> { if (reflectedType.getName().startsWith("[")) { return; } Set<MethodDescriptor> accessibleMethods = getAccessibleMethods(agent, reflectedType.getName()); ClassReader cls = agent.getClassSource().get(reflectedType.getName()); for (MethodDescriptor methodDescriptor : accessibleMethods) { MethodReader calledMethod = cls.getMethod(methodDescriptor); MethodDependency calledMethodDep = agent.linkMethod(calledMethod.getReference()).addLocation(location); calledMethodDep.use(); for (int i = 0; i < calledMethod.parameterCount(); ++i) { propagateSet(agent, methodDescriptor.parameterType(i), method.getVariable(1).getArrayItem(), calledMethodDep.getVariable(i + 1), location); } calledMethodDep.getVariable(0).propagate(reflectedType); linkClassIfNecessary(agent, calledMethod, location); } }); classValueNode.connect(method.getResult()); }
private void handleInvoke(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getMethods) .addLocation(location) .getVariable(0).getClassValueNode(); classValueNode.addConsumer(reflectedType -> { if (reflectedType.getName().startsWith("[")) { return; } Set<MethodDescriptor> accessibleMethods = getAccessibleMethods(agent, reflectedType.getName()); ClassReader cls = agent.getClassSource().get(reflectedType.getName()); for (MethodDescriptor methodDescriptor : accessibleMethods) { MethodReader calledMethod = cls.getMethod(methodDescriptor); MethodDependency calledMethodDep = agent.linkMethod(calledMethod.getReference()).addLocation(location); calledMethodDep.use(); for (int i = 0; i < calledMethod.parameterCount(); ++i) { propagateSet(agent, methodDescriptor.parameterType(i), method.getVariable(2).getArrayItem(), calledMethodDep.getVariable(i + 1), location); } propagateSet(agent, ValueType.object(reflectedType.getName()), method.getVariable(1), calledMethodDep.getVariable(0), location); propagateGet(agent, calledMethod.getResultType(), calledMethodDep.getResult(), method.getResult(), location); linkClassIfNecessary(agent, calledMethod, location); } }); }
appendProperty(writer, "parameterTypes", false, () -> { writer.append('['); for (int i = 0; i < method.parameterCount(); ++i) { if (i > 0) { writer.append(',').ws();
Arrays.fill(defLocation, -1); Instruction[] constantInstructions = new Instruction[program.variableCount()]; for (int i = 0; i <= context.getMethod().parameterCount(); ++i) { defLocation[i] = 0;
int argumentCount = methodImpl.method.parameterCount(); @SuppressWarnings("unchecked") ValueImpl<Object>[] arguments = (ValueImpl<Object>[]) new ValueImpl<?>[argumentCount];