1
#include <torch/csrc/jit/backends/backend_resolver.h>
2
#include <torch/csrc/jit/frontend/sugared_value.h>
3
#include <torch/custom_class.h>
12
struct ClassNamespaceValue : public SugaredValue {
13
explicit ClassNamespaceValue(c10::QualifiedName name)
14
: basename_(std::move(name)) {}
16
std::shared_ptr<SugaredValue> attr(
17
const SourceRange& loc,
19
const std::string& name) override {
20
auto fullName = c10::QualifiedName(basename_, name);
23
if (auto custom_class = getCustomClass(fullName.qualifiedName())) {
24
return std::make_shared<ClassValue>(custom_class);
28
return std::make_shared<ClassNamespaceValue>(std::move(fullName));
31
std::string kind() const override {
32
return "Class Namespace";
36
c10::QualifiedName basename_;
41
struct LoweredModuleResolver : public Resolver {
42
std::shared_ptr<SugaredValue> resolveValue(
43
const std::string& name,
45
const SourceRange& loc) override {
46
if (name == "torch") {
47
return std::make_shared<BuiltinModule>("aten");
48
} else if (name == "__torch__") {
49
return std::make_shared<ClassNamespaceValue>(c10::QualifiedName(name));
50
} else if (name == "Exception") {
51
return std::make_shared<ExceptionValue>(name);
57
TypePtr resolveType(const std::string& name, const SourceRange& loc)
64
std::shared_ptr<Resolver> loweredModuleResolver() {
65
std::shared_ptr<Resolver> resolver =
66
std::make_shared<LoweredModuleResolver>();