-
Notifications
You must be signed in to change notification settings - Fork 171
Implement class #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement class #391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1487,6 +1487,21 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> { | |
} | ||
} | ||
|
||
void visit_ClassDef(const AST::ClassDef_t &x) { | ||
SymbolTable *parent_scope = current_scope; | ||
current_scope = al.make_new<SymbolTable>(parent_scope); | ||
for (size_t i=0; i<x.n_body; i++) { | ||
visit_stmt(*x.m_body[i]); | ||
} | ||
tmp = ASR::make_ClassType_t(al, x.base.base.loc, current_scope, | ||
x.m_name, ASR::abiType::Source, ASR::accessType::Public); | ||
tmp = ASR::make_Class_t(al, x.base.base.loc, | ||
ASR::down_cast<ASR::symbol_t>(tmp), nullptr, 0); | ||
ASR::symbol_t * t = ASR::down_cast<ASR::symbol_t>(tmp); | ||
parent_scope->scope[x.m_name] = t; | ||
Comment on lines
+1496
to
+1501
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @certik Does this look good? On Python code: class Foo:
def __init__(self, p):
return p ASR:
Also, what is the difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a bug in printing an error message, I just created an issue #398 to fix that. Yes, I think that is a constructor. Fortran does not have constructors in this sense, so I would tackle those a little bit later. We should add whatever we need into ASR, but first let's get something like this working:
I am not quite sure where you should annotate the variables inside the class, whether how I did it, or some other way. The other thing we need are structs, which we can represent already in ASR, we just need some syntax in Python, possibly the "data classes" or whatever it is called:
And it works like a struct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To annotate that
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The way you did it seems fine. |
||
current_scope = parent_scope; | ||
} | ||
|
||
void create_GenericProcedure(const Location &loc) { | ||
for(auto &p: overload_defs) { | ||
std::string def_name = p.first; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Class
ASR node is used for a variable type, so in here we should just remove it.