Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

41
LINES

< > BotCompany Repo | #1034745 // newPreciseCall - better method resolution with primitive conversion

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (5407L) is out of date.

sbool newPreciseCall_debug;

sO newPreciseCall(O o, S method, O... args) ctex {
  if (o == null) null;
  bool staticCall = o instanceof Class;
  Class c = staticCall ? (Class) o : o.getClass();
  O target = staticCall ? null : o;
  
  _MethodCache cache = callOpt_getCache(c);
  L<Method> methods = cache.cache.get(method);
  Method best = null;
  int bestScore = Int.MAX_VALUE;
  bool widening;
  if (newPreciseCall_debug)
    printVars("newPreciseCall", +method, +staticCall, +c, methods := l(methods));
    
  if (methods != null) for (Method m : methods) {
    if (staticCall && !isStaticMethod(m)) continue;
    
    int score = methodApplicabilityScore_withPrimitiveWidening(m, args);
    if (score == 0)
      ret invokeMethod(m, target, args);
    
    if (newPreciseCall_debug)
      print("Method score: " + m + " " + score);
        
    if (abs(score) < bestScore) {
      best = m;
      bestScore = abs(score);
      widening = score < 0;
    }
  }
  
  if (best != null)
    if (widening)
      ret invokeMethodWithWidening(best, target, args);
    else
      ret invokeMethod(best, target, args);
    
  ret callWithVarargs(o, method, args); // TODO: make this precise too
}

Author comment

Began life as a copy of #1007856

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034745
Snippet name: newPreciseCall - better method resolution with primitive conversion
Eternal ID of this version: #1034745/15
Text MD5: 0553bd45fef2edcacf07cb3ea20db101
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-08 03:51:01
Source code size: 1232 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 173 / 277
Version history: 14 change(s)
Referenced in: [show references]