User-defined operators: AST

This commit is contained in:
wechman
2023-02-22 00:06:17 +01:00
committed by Kamil Śliwak
parent fa0d3a44a7
commit 9a36438441
7 changed files with 141 additions and 5 deletions
+29 -1
View File
@@ -22,6 +22,7 @@
*/
#include <libsolidity/ast/ASTJsonImporter.h>
#include <libsolidity/ast/UserDefinableOperators.h>
#include <libyul/AsmJsonImporter.h>
#include <libyul/AST.h>
@@ -397,15 +398,42 @@ ASTPointer<InheritanceSpecifier> ASTJsonImporter::createInheritanceSpecifier(Jso
ASTPointer<UsingForDirective> ASTJsonImporter::createUsingForDirective(Json::Value const& _node)
{
vector<ASTPointer<IdentifierPath>> functions;
vector<optional<Token>> operators;
if (_node.isMember("libraryName"))
{
astAssert(!_node["libraryName"].isArray());
astAssert(!_node["libraryName"]["operator"]);
functions.emplace_back(createIdentifierPath(_node["libraryName"]));
operators.emplace_back(nullopt);
}
else if (_node.isMember("functionList"))
for (Json::Value const& function: _node["functionList"])
functions.emplace_back(createIdentifierPath(function["function"]));
{
if (function.isMember("function"))
{
astAssert(!function.isMember("operator"));
astAssert(!function.isMember("definition"));
functions.emplace_back(createIdentifierPath(function["function"]));
operators.emplace_back(nullopt);
}
else
{
astAssert(function.isMember("operator"));
astAssert(function.isMember("definition"));
Token const operatorName = scanSingleToken(function["operator"]);
astAssert(util::contains(frontend::userDefinableOperators, operatorName));
functions.emplace_back(createIdentifierPath(function["definition"]));
operators.emplace_back(operatorName);
}
}
return createASTNode<UsingForDirective>(
_node,
std::move(functions),
std::move(operators),
!_node.isMember("libraryName"),
_node["typeName"].isNull() ? nullptr : convertJsonToASTNode<TypeName>(_node["typeName"]),
memberAsBool(_node, "global")