| 482 | // register a method |
| 483 | template <typename Func, typename... Extra> |
| 484 | void RegisterMethod(const char* name, bool is_static, Func&& func, Extra&&... extra) { |
| 485 | using FuncInfo = ::tvm::ffi::details::FunctionInfo<std::decay_t<Func>>; |
| 486 | MethodInfoBuilder info; |
| 487 | info.name = TVMFFIByteArray{name, std::char_traits<char>::length(name)}; |
| 488 | info.doc = TVMFFIByteArray{nullptr, 0}; |
| 489 | info.flags = 0; |
| 490 | if (is_static) { |
| 491 | info.flags |= kTVMFFIFieldFlagBitMaskIsStaticMethod; |
| 492 | } |
| 493 | |
| 494 | auto method_name = std::string(type_key_) + "." + name; |
| 495 | |
| 496 | // if an overload method exists, register to existing overload function |
| 497 | if (const auto overload_it = registered_fields_.find(name); |
| 498 | overload_it != registered_fields_.end()) { |
| 499 | ::tvm::ffi::details::OverloadBase* overload_ptr = overload_it->second; |
| 500 | return overload_ptr->Register(NewOverload(std::move(method_name), std::forward<Func>(func))); |
| 501 | } |
| 502 | |
| 503 | // first time registering overload method |
| 504 | auto [method, overload_ptr] = |
| 505 | GetOverloadMethod(std::move(method_name), std::forward<Func>(func)); |
| 506 | registered_fields_.try_emplace(name, overload_ptr); |
| 507 | |
| 508 | info.method = AnyView(method).CopyToTVMFFIAny(); |
| 509 | info.metadata_.emplace_back("type_schema", FuncInfo::TypeSchema()); |
| 510 | // apply method info traits |
| 511 | ((ApplyMethodInfoTrait(&info, std::forward<Extra>(extra)), ...)); |
| 512 | std::string metadata_str = Metadata::ToJSON(info.metadata_); |
| 513 | info.metadata = TVMFFIByteArray{metadata_str.c_str(), metadata_str.size()}; |
| 514 | TVM_FFI_CHECK_SAFE_CALL(TVMFFITypeRegisterMethod(type_index_, &info)); |
| 515 | } |
| 516 | |
| 517 | std::unordered_map<std::string, ::tvm::ffi::details::OverloadBase*> registered_fields_; |
| 518 | }; |
nothing calls this directly
no test coverage detected