mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change some AST elements to post visit.
This commit is contained in:
parent
dee1c1109c
commit
7c62193524
@ -86,7 +86,7 @@ string IRGeneratorForStatements::code() const
|
|||||||
return m_code.str();
|
return m_code.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRGeneratorForStatements::visit(VariableDeclarationStatement const& _varDeclStatement)
|
void IRGeneratorForStatements::endVisit(VariableDeclarationStatement const& _varDeclStatement)
|
||||||
{
|
{
|
||||||
for (auto const& decl: _varDeclStatement.declarations())
|
for (auto const& decl: _varDeclStatement.declarations())
|
||||||
if (decl)
|
if (decl)
|
||||||
@ -96,8 +96,6 @@ bool IRGeneratorForStatements::visit(VariableDeclarationStatement const& _varDec
|
|||||||
{
|
{
|
||||||
solUnimplementedAssert(_varDeclStatement.declarations().size() == 1, "");
|
solUnimplementedAssert(_varDeclStatement.declarations().size() == 1, "");
|
||||||
|
|
||||||
expression->accept(*this);
|
|
||||||
|
|
||||||
VariableDeclaration const& varDecl = *_varDeclStatement.declarations().front();
|
VariableDeclaration const& varDecl = *_varDeclStatement.declarations().front();
|
||||||
m_code <<
|
m_code <<
|
||||||
"let " <<
|
"let " <<
|
||||||
@ -110,8 +108,6 @@ bool IRGeneratorForStatements::visit(VariableDeclarationStatement const& _varDec
|
|||||||
for (auto const& decl: _varDeclStatement.declarations())
|
for (auto const& decl: _varDeclStatement.declarations())
|
||||||
if (decl)
|
if (decl)
|
||||||
m_code << "let " << m_context.localVariableName(*decl) << "\n";
|
m_code << "let " << m_context.localVariableName(*decl) << "\n";
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRGeneratorForStatements::visit(Assignment const& _assignment)
|
bool IRGeneratorForStatements::visit(Assignment const& _assignment)
|
||||||
@ -171,7 +167,7 @@ bool IRGeneratorForStatements::visit(Break const&)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRGeneratorForStatements::visit(Return const& _return)
|
void IRGeneratorForStatements::endVisit(Return const& _return)
|
||||||
{
|
{
|
||||||
if (Expression const* value = _return.expression())
|
if (Expression const* value = _return.expression())
|
||||||
{
|
{
|
||||||
@ -182,8 +178,6 @@ bool IRGeneratorForStatements::visit(Return const& _return)
|
|||||||
for (auto const& retVariable: returnParameters)
|
for (auto const& retVariable: returnParameters)
|
||||||
types.push_back(retVariable->annotation().type);
|
types.push_back(retVariable->annotation().type);
|
||||||
|
|
||||||
value->accept(*this);
|
|
||||||
|
|
||||||
// TODO support tuples
|
// TODO support tuples
|
||||||
solUnimplementedAssert(types.size() == 1, "Multi-returns not implemented.");
|
solUnimplementedAssert(types.size() == 1, "Multi-returns not implemented.");
|
||||||
m_code <<
|
m_code <<
|
||||||
@ -193,7 +187,6 @@ bool IRGeneratorForStatements::visit(Return const& _return)
|
|||||||
"\n";
|
"\n";
|
||||||
}
|
}
|
||||||
m_code << "return_flag := 0\n" << "break\n";
|
m_code << "return_flag := 0\n" << "break\n";
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
|
void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
|
||||||
@ -227,7 +220,7 @@ void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||||
{
|
{
|
||||||
solUnimplementedAssert(
|
solUnimplementedAssert(
|
||||||
_functionCall.annotation().kind == FunctionCallKind::FunctionCall ||
|
_functionCall.annotation().kind == FunctionCallKind::FunctionCall ||
|
||||||
@ -241,13 +234,12 @@ bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
|||||||
{
|
{
|
||||||
solAssert(funcType->category() == Type::Category::TypeType, "Expected category to be TypeType");
|
solAssert(funcType->category() == Type::Category::TypeType, "Expected category to be TypeType");
|
||||||
solAssert(_functionCall.arguments().size() == 1, "Expected one argument for type conversion");
|
solAssert(_functionCall.arguments().size() == 1, "Expected one argument for type conversion");
|
||||||
_functionCall.arguments().front()->accept(*this);
|
|
||||||
|
|
||||||
defineExpression(_functionCall) <<
|
defineExpression(_functionCall) <<
|
||||||
expressionAsType(*_functionCall.arguments().front(), *_functionCall.annotation().type) <<
|
expressionAsType(*_functionCall.arguments().front(), *_functionCall.annotation().type) <<
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionTypePointer functionType = dynamic_cast<FunctionType const*>(funcType);
|
FunctionTypePointer functionType = dynamic_cast<FunctionType const*>(funcType);
|
||||||
@ -281,14 +273,10 @@ bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
|||||||
{
|
{
|
||||||
vector<string> args;
|
vector<string> args;
|
||||||
for (unsigned i = 0; i < arguments.size(); ++i)
|
for (unsigned i = 0; i < arguments.size(); ++i)
|
||||||
{
|
|
||||||
arguments[i]->accept(*this);
|
|
||||||
|
|
||||||
if (functionType->takesArbitraryParameters())
|
if (functionType->takesArbitraryParameters())
|
||||||
args.emplace_back(m_context.variable(*arguments[i]));
|
args.emplace_back(m_context.variable(*arguments[i]));
|
||||||
else
|
else
|
||||||
args.emplace_back(expressionAsType(*arguments[i], *parameterTypes[i]));
|
args.emplace_back(expressionAsType(*arguments[i], *parameterTypes[i]));
|
||||||
}
|
|
||||||
|
|
||||||
if (auto identifier = dynamic_cast<Identifier const*>(&_functionCall.expression()))
|
if (auto identifier = dynamic_cast<Identifier const*>(&_functionCall.expression()))
|
||||||
{
|
{
|
||||||
@ -301,12 +289,10 @@ bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
|||||||
"(" <<
|
"(" <<
|
||||||
joinHumanReadable(args) <<
|
joinHumanReadable(args) <<
|
||||||
")\n";
|
")\n";
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_functionCall.expression().accept(*this);
|
|
||||||
|
|
||||||
// @TODO The function can very well return multiple vars.
|
// @TODO The function can very well return multiple vars.
|
||||||
args = vector<string>{m_context.variable(_functionCall.expression())} + args;
|
args = vector<string>{m_context.variable(_functionCall.expression())} + args;
|
||||||
defineExpression(_functionCall) <<
|
defineExpression(_functionCall) <<
|
||||||
@ -319,7 +305,6 @@ bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
|||||||
default:
|
default:
|
||||||
solUnimplemented("");
|
solUnimplemented("");
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRGeneratorForStatements::visit(InlineAssembly const& _inlineAsm)
|
bool IRGeneratorForStatements::visit(InlineAssembly const& _inlineAsm)
|
||||||
|
@ -45,14 +45,14 @@ public:
|
|||||||
|
|
||||||
std::string code() const;
|
std::string code() const;
|
||||||
|
|
||||||
bool visit(VariableDeclarationStatement const& _variableDeclaration) override;
|
void endVisit(VariableDeclarationStatement const& _variableDeclaration) override;
|
||||||
bool visit(Assignment const& _assignment) override;
|
bool visit(Assignment const& _assignment) override;
|
||||||
bool visit(ForStatement const& _forStatement) override;
|
bool visit(ForStatement const& _forStatement) override;
|
||||||
bool visit(Continue const& _continueStatement) override;
|
bool visit(Continue const& _continueStatement) override;
|
||||||
bool visit(Break const& _breakStatement) override;
|
bool visit(Break const& _breakStatement) override;
|
||||||
bool visit(Return const& _return) override;
|
void endVisit(Return const& _return) override;
|
||||||
void endVisit(BinaryOperation const& _binOp) override;
|
void endVisit(BinaryOperation const& _binOp) override;
|
||||||
bool visit(FunctionCall const& _funCall) override;
|
void endVisit(FunctionCall const& _funCall) override;
|
||||||
bool visit(InlineAssembly const& _inlineAsm) override;
|
bool visit(InlineAssembly const& _inlineAsm) override;
|
||||||
bool visit(Identifier const& _identifier) override;
|
bool visit(Identifier const& _identifier) override;
|
||||||
bool visit(Literal const& _literal) override;
|
bool visit(Literal const& _literal) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user