oki?
This commit is contained in:
parent
c910178efd
commit
0b77bb8941
1 changed files with 44 additions and 7 deletions
|
|
@ -135,16 +135,43 @@ private:
|
||||||
else if (auto *function_def = dynamic_cast<const FunctionDef *>(&stmt))
|
else if (auto *function_def = dynamic_cast<const FunctionDef *>(&stmt))
|
||||||
{
|
{
|
||||||
write_indent();
|
write_indent();
|
||||||
output << "def " << function_def->name << "(";
|
if (function_def->name == "__init__")
|
||||||
if (function_def->params.size() > 0)
|
|
||||||
{
|
{
|
||||||
output << function_def->params[0];
|
output << "def initialize";
|
||||||
}
|
}
|
||||||
for (int i = 1; i < function_def->params.size(); i++)
|
else
|
||||||
{
|
{
|
||||||
output << ", " << function_def->params[i];
|
output << "def " << function_def->name << "";
|
||||||
}
|
}
|
||||||
output << ")\n";
|
bool l_paren = false;
|
||||||
|
bool comma = false;
|
||||||
|
for (size_t i = 0; i < function_def->params.size(); i++)
|
||||||
|
{
|
||||||
|
if (comma)
|
||||||
|
{
|
||||||
|
output << ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (function_def->params[i] != "self")
|
||||||
|
{
|
||||||
|
if (!l_paren)
|
||||||
|
{
|
||||||
|
output << "(";
|
||||||
|
l_paren = true;
|
||||||
|
}
|
||||||
|
output << function_def->params[i];
|
||||||
|
comma = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
comma = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (l_paren)
|
||||||
|
{
|
||||||
|
output << ")";
|
||||||
|
}
|
||||||
|
output << "\n";
|
||||||
indent_level++;
|
indent_level++;
|
||||||
for (const auto &s : function_def->body)
|
for (const auto &s : function_def->body)
|
||||||
{
|
{
|
||||||
|
|
@ -157,7 +184,7 @@ private:
|
||||||
else if (auto *class_def = dynamic_cast<const ClassDef *>(&stmt))
|
else if (auto *class_def = dynamic_cast<const ClassDef *>(&stmt))
|
||||||
{
|
{
|
||||||
write_indent();
|
write_indent();
|
||||||
output << "Class " << class_def->name << "\n";
|
output << "class " << class_def->name << "\n";
|
||||||
indent_level++;
|
indent_level++;
|
||||||
for (const auto &s : class_def->body)
|
for (const auto &s : class_def->body)
|
||||||
{
|
{
|
||||||
|
|
@ -207,6 +234,16 @@ private:
|
||||||
}
|
}
|
||||||
else if (auto *attr = dynamic_cast<const Attribute *>(&expr))
|
else if (auto *attr = dynamic_cast<const Attribute *>(&expr))
|
||||||
{
|
{
|
||||||
|
if (auto *id = dynamic_cast<const Identifier *>(attr->value.get()))
|
||||||
|
{
|
||||||
|
if (id->name == "self")
|
||||||
|
{
|
||||||
|
output << "@";
|
||||||
|
write(attr->attr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
generate_expr(*attr->value);
|
generate_expr(*attr->value);
|
||||||
output << "." << attr->attr;
|
output << "." << attr->attr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue