Use kind in json AST for free function.

This commit is contained in:
chriseth 2020-08-06 14:10:42 +02:00
parent 8d92fd1c04
commit 2ff954ec2d
68 changed files with 9 additions and 93 deletions

View File

@ -360,8 +360,7 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
std::vector<pair<string, Json::Value>> attributes = {
make_pair("name", _node.name()),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("kind", TokenTraits::toString(_node.kind())),
make_pair("freeFunction", _node.isFree()),
make_pair("kind", _node.isFree() ? "freeFunction" : TokenTraits::toString(_node.kind())),
make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
make_pair("visibility", Declaration::visibilityToString(visibility)),
make_pair("virtual", _node.markedVirtual()),

View File

@ -381,6 +381,7 @@ ASTPointer<FunctionDefinition> ASTJsonImporter::createFunctionDefinition(Json::V
astAssert(_node["kind"].isString(), "Expected 'kind' to be a string!");
Token kind;
bool freeFunction = false;
string kindStr = member(_node, "kind").asString();
if (kindStr == "constructor")
@ -391,6 +392,11 @@ ASTPointer<FunctionDefinition> ASTJsonImporter::createFunctionDefinition(Json::V
kind = Token::Fallback;
else if (kindStr == "receive")
kind = Token::Receive;
else if (kindStr == "freeFunction")
{
kind = Token::Function;
freeFunction = true;
}
else
astAssert(false, "Expected 'kind' to be one of [constructor, function, fallback, receive]");
@ -399,16 +405,7 @@ ASTPointer<FunctionDefinition> ASTJsonImporter::createFunctionDefinition(Json::V
modifiers.push_back(createModifierInvocation(mod));
Visibility vis = Visibility::Default;
bool const freeFunction = _node.isMember("freeFunction") ? _node["freeFunction"].asBool() : false;
if (kind == Token::Constructor)
{
}
else if (freeFunction)
astAssert(
vis == Visibility::Internal || vis == Visibility::Default,
"Expected internal or default visibility for free function."
);
else
if (!freeFunction)
vis = visibility(_node);
return createASTNode<FunctionDefinition>(
_node,

View File

@ -58,7 +58,6 @@ JSON AST:
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": true,
"kind": "constructor",
@ -121,7 +120,6 @@ JSON AST:
{
"attributes":
{
"freeFunction": false,
"functionSelector": "af11c34c",
"implemented": true,
"isConstructor": false,

View File

@ -1 +1 @@
{"sources":{"A":{"ast":{"absolutePath":"A","exportedSymbols":{"C":[6]},"id":7,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:0"},{"abstract":false,"baseContracts":[],"contractDependencies":[],"contractKind":"contract","documentation":null,"fullyImplemented":true,"id":6,"linearizedBaseContracts":[6],"name":"C","nodeType":"ContractDefinition","nodes":[{"body":{"id":4,"nodeType":"Block","src":"97:2:0","statements":[]},"documentation":null,"freeFunction":false,"functionSelector":"26121ff0","id":5,"implemented":true,"kind":"function","modifiers":[],"name":"f","nodeType":"FunctionDefinition","overrides":null,"parameters":{"id":2,"nodeType":"ParameterList","parameters":[],"src":"82:2:0"},"returnParameters":{"id":3,"nodeType":"ParameterList","parameters":[],"src":"97:0:0"},"scope":6,"src":"72:27:0","stateMutability":"pure","virtual":false,"visibility":"public"}],"scope":7,"src":"59:42:0"}],"src":"36:65:0"},"id":0}}}
{"sources":{"A":{"ast":{"absolutePath":"A","exportedSymbols":{"C":[6]},"id":7,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:0"},{"abstract":false,"baseContracts":[],"contractDependencies":[],"contractKind":"contract","documentation":null,"fullyImplemented":true,"id":6,"linearizedBaseContracts":[6],"name":"C","nodeType":"ContractDefinition","nodes":[{"body":{"id":4,"nodeType":"Block","src":"97:2:0","statements":[]},"documentation":null,"functionSelector":"26121ff0","id":5,"implemented":true,"kind":"function","modifiers":[],"name":"f","nodeType":"FunctionDefinition","overrides":null,"parameters":{"id":2,"nodeType":"ParameterList","parameters":[],"src":"82:2:0"},"returnParameters":{"id":3,"nodeType":"ParameterList","parameters":[],"src":"97:0:0"},"scope":6,"src":"72:27:0","stateMutability":"pure","virtual":false,"visibility":"public"}],"scope":7,"src":"59:42:0"}],"src":"36:65:0"},"id":0}}}

View File

@ -34,7 +34,6 @@
"src": "37:4:1",
"statements": []
},
"freeFunction": false,
"id": 4,
"implemented": true,
"kind": "constructor",

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": true,
"kind": "constructor",

View File

@ -462,7 +462,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "fc68521a",
"id": 38,
"implemented": true,

View File

@ -91,7 +91,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "fc68521a",
"implemented": true,
"isConstructor": false,

View File

@ -131,7 +131,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "b582ec5f",
"id": 5,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "b582ec5f",
"implemented": true,
"isConstructor": false,

View File

@ -56,7 +56,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "e2179b8e",
"id": 5,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "e2179b8e",
"implemented": true,
"isConstructor": false,

View File

@ -118,7 +118,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "b8c9d365",
"id": 5,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "b8c9d365",
"implemented": true,
"isConstructor": false,

View File

@ -68,7 +68,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "ece866b9",
"id": 5,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "ece866b9",
"implemented": true,
"isConstructor": false,

View File

@ -131,7 +131,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "e2179b8e",
"id": 5,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "e2179b8e",
"implemented": true,
"isConstructor": false,

View File

@ -95,7 +95,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 7,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -196,7 +196,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "ffae15ba",
"id": 10,
"implemented": true,

View File

@ -112,7 +112,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "ffae15ba",
"implemented": true,
"isConstructor": false,

View File

@ -72,7 +72,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "5a2ee019",
"id": 5,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "5a2ee019",
"implemented": true,
"isConstructor": false,

View File

@ -180,7 +180,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 5,
"implemented": true,

View File

@ -95,7 +95,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "e2179b8e",
"id": 5,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "e2179b8e",
"implemented": true,
"isConstructor": false,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -121,7 +121,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 8,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -34,7 +34,6 @@
"src": "28:4:1",
"statements": []
},
"freeFunction": false,
"id": 4,
"implemented": true,
"kind": "constructor",

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": true,
"kind": "constructor",

View File

@ -216,7 +216,6 @@
"src": "162:25:3",
"text": "Some comment on fn."
},
"freeFunction": false,
"functionSelector": "a4a2c40b",
"id": 22,
"implemented": true,

View File

@ -161,7 +161,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "a4a2c40b",
"implemented": true,
"isConstructor": false,

View File

@ -34,7 +34,6 @@
"src": "43:5:1",
"statements": []
},
"freeFunction": false,
"id": 4,
"implemented": true,
"kind": "fallback",

View File

@ -34,7 +34,6 @@
"src": "42:5:1",
"statements": []
},
"freeFunction": false,
"id": 4,
"implemented": true,
"kind": "receive",
@ -69,7 +68,6 @@
"src": "78:5:1",
"statements": []
},
"freeFunction": false,
"id": 8,
"implemented": true,
"kind": "fallback",

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": false,
"kind": "receive",
@ -101,7 +100,6 @@
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": false,
"kind": "fallback",

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": false,
"kind": "fallback",

View File

@ -34,7 +34,6 @@
"src": "34:2:1",
"statements": []
},
"freeFunction": false,
"id": 4,
"implemented": true,
"kind": "fallback",

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": false,
"kind": "fallback",

View File

@ -34,7 +34,6 @@
"src": "120:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "d6cd4974",
"id": 16,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "d6cd4974",
"implemented": true,
"isConstructor": false,

View File

@ -134,7 +134,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 10,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -142,7 +142,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 14,
"implemented": true,

View File

@ -79,7 +79,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -94,7 +94,6 @@
"src": "64:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "28811f59",
"id": 13,
"implemented": true,

View File

@ -102,7 +102,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "28811f59",
"implemented": true,
"isConstructor": false,

View File

@ -94,7 +94,6 @@
"src": "64:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "28811f59",
"id": 13,
"implemented": true,

View File

@ -102,7 +102,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "28811f59",
"implemented": true,
"isConstructor": false,

View File

@ -94,7 +94,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 8,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -42,7 +42,6 @@
"src": "36:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "a399b6a2",
"id": 4,
"implemented": true,
@ -114,7 +113,6 @@
"nodes":
[
{
"freeFunction": false,
"functionSelector": "c2985578",
"id": 10,
"implemented": false,
@ -154,7 +152,6 @@
"src": "115:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "a399b6a2",
"id": 15,
"implemented": true,
@ -246,7 +243,6 @@
"src": "170:3:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "c2985578",
"id": 23,
"implemented": true,
@ -293,7 +289,6 @@
"src": "212:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "a399b6a2",
"id": 30,
"implemented": true,

View File

@ -46,7 +46,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "a399b6a2",
"implemented": true,
"isConstructor": false,
@ -155,7 +154,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "c2985578",
"implemented": false,
"isConstructor": false,
@ -210,7 +208,6 @@
[
4
],
"freeFunction": false,
"functionSelector": "a399b6a2",
"implemented": true,
"isConstructor": false,
@ -337,7 +334,6 @@
[
10
],
"freeFunction": false,
"functionSelector": "c2985578",
"implemented": true,
"isConstructor": false,
@ -417,7 +413,6 @@
[
15
],
"freeFunction": false,
"functionSelector": "a399b6a2",
"implemented": true,
"isConstructor": false,

View File

@ -34,7 +34,6 @@
"src": "42:5:1",
"statements": []
},
"freeFunction": false,
"id": 4,
"implemented": true,
"kind": "receive",

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"implemented": true,
"isConstructor": false,
"kind": "receive",

View File

@ -88,7 +88,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 10,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -99,7 +99,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 11,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -131,7 +131,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 11,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -95,7 +95,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 8,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -42,7 +42,6 @@
"src": "45:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 4,
"implemented": true,
@ -97,7 +96,6 @@
"src": "95:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 9,
"implemented": true,
@ -201,7 +199,6 @@
"src": "160:2:1",
"statements": []
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 21,
"implemented": true,

View File

@ -46,7 +46,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,
@ -138,7 +137,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,
@ -274,7 +272,6 @@
4,
9
],
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,

View File

@ -95,7 +95,6 @@
}
]
},
"freeFunction": false,
"functionSelector": "26121ff0",
"id": 8,
"implemented": true,

View File

@ -38,7 +38,6 @@
{
"attributes":
{
"freeFunction": false,
"functionSelector": "26121ff0",
"implemented": true,
"isConstructor": false,