Implements AST JSON import for function call options.

This commit is contained in:
Erik Kundt 2020-01-23 14:33:51 +01:00 committed by chriseth
parent 8e7aef63f0
commit 893fb4d05b
2 changed files with 23 additions and 0 deletions

View File

@ -192,6 +192,8 @@ ASTPointer<ASTNode> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _js
return createBinaryOperation(_json);
if (nodeType == "FunctionCall")
return createFunctionCall(_json);
if (nodeType == "FunctionCallOptions")
return createFunctionCallOptions(_json);
if (nodeType == "NewExpression")
return createNewExpression(_json);
if (nodeType == "MemberAccess")
@ -752,6 +754,26 @@ ASTPointer<FunctionCall> ASTJsonImporter::createFunctionCall(Json::Value const&
);
}
ASTPointer<FunctionCallOptions> ASTJsonImporter::createFunctionCallOptions(Json::Value const& _node)
{
std::vector<ASTPointer<Expression>> options;
for (auto& option: member(_node, "options"))
options.push_back(convertJsonToASTNode<Expression>(option));
std::vector<ASTPointer<ASTString>> names;
for (auto& name: member(_node, "names"))
{
astAssert(name.isString(), "Expected 'names' members to be strings!");
names.push_back(make_shared<ASTString>(name.asString()));
}
return createASTNode<FunctionCallOptions>(
_node,
convertJsonToASTNode<Expression>(member(_node, "expression")),
options,
names
);
}
ASTPointer<NewExpression> ASTJsonImporter::createNewExpression(Json::Value const& _node)
{
return createASTNode<NewExpression>(

View File

@ -111,6 +111,7 @@ private:
ASTPointer<UnaryOperation> createUnaryOperation(Json::Value const& _node);
ASTPointer<BinaryOperation> createBinaryOperation(Json::Value const& _node);
ASTPointer<FunctionCall> createFunctionCall(Json::Value const& _node);
ASTPointer<FunctionCallOptions> createFunctionCallOptions(Json::Value const& _node);
ASTPointer<NewExpression> createNewExpression(Json::Value const& _node);
ASTPointer<MemberAccess> createMemberAccess(Json::Value const& _node);
ASTPointer<IndexAccess> createIndexAccess(Json::Value const& _node);