Skip to content

Commit

Permalink
AST import and export for revert statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Mar 18, 2021
1 parent 9be6164 commit 8758b4c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libsolidity/ast/ASTJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,14 @@ bool ASTJsonConverter::visit(EmitStatement const& _node)
return false;
}

bool ASTJsonConverter::visit(RevertStatement const& _node)
{
setJsonNode(_node, "RevertStatement", {
make_pair("errorCall", toJson(_node.errorCall()))
});
return false;
}

bool ASTJsonConverter::visit(VariableDeclarationStatement const& _node)
{
Json::Value varDecs(Json::arrayValue);
Expand Down
1 change: 1 addition & 0 deletions libsolidity/ast/ASTJsonConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class ASTJsonConverter: public ASTConstVisitor
bool visit(Return const& _node) override;
bool visit(Throw const& _node) override;
bool visit(EmitStatement const& _node) override;
bool visit(RevertStatement const& _node) override;
bool visit(VariableDeclarationStatement const& _node) override;
bool visit(ExpressionStatement const& _node) override;
bool visit(Conditional const& _node) override;
Expand Down
11 changes: 11 additions & 0 deletions libsolidity/ast/ASTJsonImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ ASTPointer<ASTNode> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _js
return createReturn(_json);
if (nodeType == "EmitStatement")
return createEmitStatement(_json);
if (nodeType == "RevertStatement")
return createRevertStatement(_json);
if (nodeType == "Throw")
return createThrow(_json);
if (nodeType == "VariableDeclarationStatement")
Expand Down Expand Up @@ -747,6 +749,15 @@ ASTPointer<EmitStatement> ASTJsonImporter::createEmitStatement(Json::Value const
);
}

ASTPointer<RevertStatement> ASTJsonImporter::createRevertStatement(Json::Value const& _node)
{
return createASTNode<RevertStatement>(
_node,
nullOrASTString(_node, "documentation"),
createFunctionCall(member(_node, "errorCall"))
);
}

ASTPointer<VariableDeclarationStatement> ASTJsonImporter::createVariableDeclarationStatement(Json::Value const& _node)
{
std::vector<ASTPointer<VariableDeclaration>> variables;
Expand Down
1 change: 1 addition & 0 deletions libsolidity/ast/ASTJsonImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class ASTJsonImporter
ASTPointer<Return> createReturn(Json::Value const& _node);
ASTPointer<Throw> createThrow(Json::Value const& _node);
ASTPointer<EmitStatement> createEmitStatement(Json::Value const& _node);
ASTPointer<RevertStatement> createRevertStatement(Json::Value const& _node);
ASTPointer<VariableDeclarationStatement> createVariableDeclarationStatement(Json::Value const& _node);
ASTPointer<ExpressionStatement> createExpressionStatement(Json::Value const& _node);
ASTPointer<Conditional> createConditional(Json::Value const& _node);
Expand Down

0 comments on commit 8758b4c

Please sign in to comment.