Skip to content

Commit

Permalink
Fix decorator handling in AST to ASR for structs
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Dec 30, 2022
1 parent 0ccfbf8 commit 9f9e9a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,25 @@ static inline ASR::symbol_t *get_asr_owner(const ASR::symbol_t *sym) {
return ASR::down_cast<ASR::symbol_t>(s->asr_owner);
}

static inline ASR::symbol_t *get_asr_owner(const ASR::expr_t *expr) {
switch( expr->type ) {
case ASR::exprType::Var: {
return ASRUtils::get_asr_owner(ASR::down_cast<ASR::Var_t>(expr)->m_v);
}
case ASR::exprType::StructInstanceMember: {
return ASRUtils::get_asr_owner(ASR::down_cast<ASR::StructInstanceMember_t>(expr)->m_m);
}
case ASR::exprType::GetPointer: {
return ASRUtils::get_asr_owner(ASR::down_cast<ASR::GetPointer_t>(expr)->m_arg);
}
default: {
throw LCompilersException("Cannot find the ASR owner of underlying symbol of expression "
+ std::to_string(expr->type));
}
}
return nullptr;
}

// Returns the Module_t the symbol is in, or nullptr if not in a module
// or no asr_owner yet
static inline ASR::Module_t *get_sym_module0(const ASR::symbol_t *sym) {
Expand Down
1 change: 1 addition & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
if( AST::is_a<AST::Name_t>(*decorators[i]) ) {
AST::Name_t* dc_name = AST::down_cast<AST::Name_t>(decorators[i]);
is_dataclass_ = std::string(dc_name->m_id) == "dataclass";
is_packed = is_packed || std::string(dc_name->m_id) == "packed";
} else if( AST::is_a<AST::Call_t>(*decorators[i]) ) {
AST::Call_t* dc_call = AST::down_cast<AST::Call_t>(decorators[i]);
AST::Name_t* dc_name = AST::down_cast<AST::Name_t>(dc_call->m_func);
Expand Down

0 comments on commit 9f9e9a5

Please sign in to comment.