lib/SIL/SILDeclRef.cpp
MethodDispatch
swift::getMethodDispatch(AbstractFunctionDecl *method) {
  // Final methods can be statically referenced.
  if (method->isFinal())
    return MethodDispatch::Static;
  // Some methods are forced to be statically dispatched.
  if (method->hasForcedStaticDispatch())
    return MethodDispatch::Static;

  // Import-as-member declarations are always statically referenced.
  if (method->isImportAsMember())
    return MethodDispatch::Static;

  // If this declaration is in a class but not marked final, then it is
  // always dynamically dispatched.
  auto dc = method->getDeclContext();
  if (isa<ClassDecl>(dc))
    return MethodDispatch::Class;

  // Class extension methods are only dynamically dispatched if they're
  // dispatched by objc_msgSend, which happens if they're foreign or dynamic.
  if (dc->getAsClassOrClassExtensionContext()) {
    if (method->hasClangNode())
      return MethodDispatch::Class;
    if (auto fd = dyn_cast<FuncDecl>(method)) {
      if (fd->isAccessor() && fd->getAccessorStorageDecl()->hasClangNode())
        return MethodDispatch::Class;
    }
    if (method->isDynamic())
      return MethodDispatch::Class;
  }

  // Otherwise, it can be referenced statically.
  return MethodDispatch::Static;
}
/// Get the method dispatch mechanism for a method.
Get the method dispatch mechanism for a method.
Get the method dispatch mechanism for a method .
MethodDispatch
swift::getMethodDispatch(AbstractFunctionDecl *method) {
  if (method->isFinal())
    return MethodDispatch::Static;
  if (method->hasForcedStaticDispatch())
    return MethodDispatch::Static;
  if (method->isImportAsMember())
    return MethodDispatch::Static;
  auto dc = method->getDeclContext();
  if (isa<ClassDecl>(dc))
    return MethodDispatch::Class;
  if (dc->getAsClassOrClassExtensionContext()) {
    if (method->hasClangNode())
      return MethodDispatch::Class;
    if (auto fd = dyn_cast<FuncDecl>(method)) {
      if (fd->isAccessor() && fd->getAccessorStorageDecl()->hasClangNode())
        return MethodDispatch::Class;
    }
    if (method->isDynamic())
      return MethodDispatch::Class;
  }
  return MethodDispatch::Static;
}
MethodDispatch swift :: getMethodDispatch ( AbstractFunctionDecl * method ) { if ( method -> isFinal ( ) ) return MethodDispatch :: Static ; if ( method -> hasForcedStaticDispatch ( ) ) return MethodDispatch :: Static ; if ( method -> isImportAsMember ( ) ) return MethodDispatch :: Static ; auto dc = method -> getDeclContext ( ) ; if ( isa < ClassDecl > ( dc ) ) return MethodDispatch :: Class ; if ( dc -> getAsClassOrClassExtensionContext ( ) ) { if ( method -> hasClangNode ( ) ) return MethodDispatch :: Class ; if ( auto fd = dyn_cast < FuncDecl > ( method ) ) { if ( fd -> isAccessor ( ) && fd -> getAccessorStorageDecl ( ) -> hasClangNode ( ) ) return MethodDispatch :: Class ; } if ( method -> isDynamic ( ) ) return MethodDispatch :: Class ; } return MethodDispatch :: Static ; }
Get the method dispatch mechanism for a method.
Get the method dispatch mechanism for a method .
// Final methods can be statically referenced. // Some methods are forced to be statically dispatched. // Import-as-member declarations are always statically referenced. // If this declaration is in a class but not marked final, then it is // always dynamically dispatched. // Class extension methods are only dynamically dispatched if they're // dispatched by objc_msgSend, which happens if they're foreign or dynamic. // Otherwise, it can be referenced statically.