Skip to content

Commit 63bc3b4

Browse files
committed
Support importing StructType
1 parent 09bc19d commit 63bc3b4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,22 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
454454
ASR::accessType::Public
455455
);
456456
return ASR::down_cast<ASR::symbol_t>(fn);
457+
} else if (ASR::is_a<ASR::StructType_t>(*t)) {
458+
ASR::StructType_t *st = ASR::down_cast<ASR::StructType_t>(t);
459+
// `st` is the StructType in a module. Now we construct
460+
// an ExternalSymbol that points to it.
461+
Str name;
462+
name.from_str(al, new_sym_name);
463+
char *cname = name.c_str(al);
464+
ASR::asr_t *est = ASR::make_ExternalSymbol_t(
465+
al, st->base.base.loc,
466+
/* a_symtab */ current_scope,
467+
/* a_name */ cname,
468+
(ASR::symbol_t*)st,
469+
m->m_name, nullptr, 0, st->m_name,
470+
ASR::accessType::Public
471+
);
472+
return ASR::down_cast<ASR::symbol_t>(est);
457473
} else if (ASR::is_a<ASR::Variable_t>(*t)) {
458474
ASR::Variable_t *mv = ASR::down_cast<ASR::Variable_t>(t);
459475
// `mv` is the Variable in a module. Now we construct
@@ -501,7 +517,7 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
501517
return import_from_module(al, mt, current_scope, std::string(mt->m_name),
502518
cur_sym_name, new_sym_name, loc);
503519
} else {
504-
throw SemanticError("Only Subroutines, Functions, Variables and "
520+
throw SemanticError("Only Subroutines, Functions, StructType, Variables and "
505521
"ExternalSymbol are currently supported in 'import'", loc);
506522
}
507523
LCOMPILERS_ASSERT(false);

0 commit comments

Comments
 (0)