Skip to content

Commit 9b26510

Browse files
committed
implement class
1 parent a63bdc7 commit 9b26510

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,21 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
14871487
}
14881488
}
14891489

1490+
void visit_ClassDef(const AST::ClassDef_t &x) {
1491+
SymbolTable *parent_scope = current_scope;
1492+
current_scope = al.make_new<SymbolTable>(parent_scope);
1493+
for (size_t i=0; i<x.n_body; i++) {
1494+
visit_stmt(*x.m_body[i]);
1495+
}
1496+
tmp = ASR::make_ClassType_t(al, x.base.base.loc, current_scope,
1497+
x.m_name, ASR::abiType::Source, ASR::accessType::Public);
1498+
tmp = ASR::make_Class_t(al, x.base.base.loc,
1499+
ASR::down_cast<ASR::symbol_t>(tmp), nullptr, 0);
1500+
ASR::symbol_t * t = ASR::down_cast<ASR::symbol_t>(tmp);
1501+
parent_scope->scope[x.m_name] = t;
1502+
current_scope = parent_scope;
1503+
}
1504+
14901505
void create_GenericProcedure(const Location &loc) {
14911506
for(auto &p: overload_defs) {
14921507
std::string def_name = p.first;

0 commit comments

Comments
 (0)