mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7921 from ghallak/func-selector-ast-json
Add function selector to FunctionDefinition AST JSON
This commit is contained in:
commit
bdd338a8de
@ -38,6 +38,7 @@ Language Features:
|
||||
* Introduce ``virtual`` and ``override`` keywords.
|
||||
* Modify ``push(element)`` for dynamic storage arrays such that it does not return the new length anymore.
|
||||
* Yul: Introduce ``leave`` statement that exits the current function.
|
||||
* JSON AST: Add the function selector of each externally-visible FunctonDefinition to the AST JSON export.
|
||||
|
||||
Compiler Features:
|
||||
* Allow revert strings to be stripped from the binary using the ``--revert-strings`` option or the ``settings.debug.revertStrings`` setting.
|
||||
|
@ -368,6 +368,11 @@ string FunctionDefinition::externalSignature() const
|
||||
return TypeProvider::function(*this)->externalSignature();
|
||||
}
|
||||
|
||||
string FunctionDefinition::externalIdentifierHex() const
|
||||
{
|
||||
return TypeProvider::function(*this)->externalIdentifierHex();
|
||||
}
|
||||
|
||||
FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
|
||||
{
|
||||
if (!m_annotation)
|
||||
@ -596,6 +601,12 @@ set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() c
|
||||
return set<Location>{ Location::Unspecified };
|
||||
}
|
||||
|
||||
string VariableDeclaration::externalIdentifierHex() const
|
||||
{
|
||||
solAssert(isStateVariable() && isPublic(), "Can only be called for public state variables");
|
||||
return TypeProvider::function(*this)->externalIdentifierHex();
|
||||
}
|
||||
|
||||
TypePointer VariableDeclaration::type() const
|
||||
{
|
||||
return annotation().type;
|
||||
|
@ -708,6 +708,9 @@ public:
|
||||
/// arguments separated by commas all enclosed in parentheses without any spaces.
|
||||
std::string externalSignature() const;
|
||||
|
||||
/// @returns the external identifier of this function (the hash of the signature) as a hex string.
|
||||
std::string externalIdentifierHex() const;
|
||||
|
||||
ContractDefinition::ContractKind inContractKind() const;
|
||||
|
||||
TypePointer type() const override;
|
||||
@ -807,6 +810,9 @@ public:
|
||||
/// @returns a set of allowed storage locations for the variable.
|
||||
std::set<Location> allowedDataLocations() const;
|
||||
|
||||
/// @returns the external identifier of this variable (the hash of the signature) as a hex string (works only for public state variables).
|
||||
std::string externalIdentifierHex() const;
|
||||
|
||||
TypePointer type() const override;
|
||||
|
||||
/// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned.
|
||||
|
@ -362,6 +362,8 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
|
||||
make_pair("implemented", _node.isImplemented()),
|
||||
make_pair("scope", idOrNull(_node.scope()))
|
||||
};
|
||||
if (_node.isPartOfExternalInterface())
|
||||
attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
|
||||
if (!_node.annotation().baseFunctions.empty())
|
||||
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
|
||||
if (m_legacy)
|
||||
@ -384,6 +386,8 @@ bool ASTJsonConverter::visit(VariableDeclaration const& _node)
|
||||
make_pair("scope", idOrNull(_node.scope())),
|
||||
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
||||
};
|
||||
if (_node.isStateVariable() && _node.isPublic())
|
||||
attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
|
||||
if (m_inEvent)
|
||||
attributes.emplace_back("indexed", _node.isIndexed());
|
||||
if (!_node.annotation().baseFunctions.empty())
|
||||
|
@ -3174,6 +3174,11 @@ u256 FunctionType::externalIdentifier() const
|
||||
return FixedHash<4>::Arith(FixedHash<4>(dev::keccak256(externalSignature())));
|
||||
}
|
||||
|
||||
string FunctionType::externalIdentifierHex() const
|
||||
{
|
||||
return FixedHash<4>(dev::keccak256(externalSignature())).hex();
|
||||
}
|
||||
|
||||
bool FunctionType::isPure() const
|
||||
{
|
||||
// TODO: replace this with m_stateMutability == StateMutability::Pure once
|
||||
|
@ -1190,6 +1190,8 @@ public:
|
||||
std::string externalSignature() const;
|
||||
/// @returns the external identifier of this function (the hash of the signature).
|
||||
u256 externalIdentifier() const;
|
||||
/// @returns the external identifier of this function (the hash of the signature) as a hex string.
|
||||
std::string externalIdentifierHex() const;
|
||||
Declaration const& declaration() const
|
||||
{
|
||||
solAssert(m_declaration, "Requested declaration from a FunctionType that has none");
|
||||
|
@ -123,6 +123,7 @@ JSON AST:
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "af11c34c",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -1 +1 @@
|
||||
{"sources":{"A":{"ast":{"absolutePath":"A","exportedSymbols":{"C":[6]},"id":7,"nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"0: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":"61:2:0","statements":[]},"documentation":null,"id":5,"implemented":true,"kind":"function","modifiers":[],"name":"f","nodeType":"FunctionDefinition","overrides":null,"parameters":{"id":2,"nodeType":"ParameterList","parameters":[],"src":"46:2:0"},"returnParameters":{"id":3,"nodeType":"ParameterList","parameters":[],"src":"61:0:0"},"scope":6,"src":"36:27:0","stateMutability":"pure","virtual":false,"visibility":"public"}],"scope":7,"src":"23:42:0"}],"src":"0:65:0"},"id":0}}}
|
||||
{"sources":{"A":{"ast":{"absolutePath":"A","exportedSymbols":{"C":[6]},"id":7,"nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"0: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":"61: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":"46:2:0"},"returnParameters":{"id":3,"nodeType":"ParameterList","parameters":[],"src":"61:0:0"},"scope":6,"src":"36:27:0","stateMutability":"pure","virtual":false,"visibility":"public"}],"scope":7,"src":"23:42:0"}],"src":"0:65:0"},"id":0}}}
|
||||
|
@ -29,6 +29,7 @@
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"functionSelector": "97682884",
|
||||
"id": 4,
|
||||
"name": "m",
|
||||
"nodeType": "VariableDeclaration",
|
||||
@ -489,6 +490,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "fc68521a",
|
||||
"id": 38,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"constant": false,
|
||||
"functionSelector": "97682884",
|
||||
"name": "m",
|
||||
"overrides": null,
|
||||
"scope": 39,
|
||||
@ -93,6 +94,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "fc68521a",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -132,6 +132,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "b582ec5f",
|
||||
"id": 5,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "b582ec5f",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -119,6 +119,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "b8c9d365",
|
||||
"id": 5,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "b8c9d365",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -69,6 +69,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "ece866b9",
|
||||
"id": 5,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "ece866b9",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -132,6 +132,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "e2179b8e",
|
||||
"id": 5,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "e2179b8e",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -200,6 +200,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "ffae15ba",
|
||||
"id": 10,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -117,6 +117,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "ffae15ba",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -73,6 +73,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "5a2ee019",
|
||||
"id": 5,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "5a2ee019",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -165,6 +165,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 5,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -124,6 +124,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 8,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -150,6 +150,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": "Some comment on fn.",
|
||||
"functionSelector": "a4a2c40b",
|
||||
"id": 14,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -109,6 +109,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": "Some comment on fn.",
|
||||
"functionSelector": "a4a2c40b",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -36,6 +36,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "d6cd4974",
|
||||
"id": 16,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "d6cd4974",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -142,6 +142,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 10,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -149,6 +149,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 14,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -83,6 +83,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -99,6 +99,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "28811f59",
|
||||
"id": 13,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -107,6 +107,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "28811f59",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -99,6 +99,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "28811f59",
|
||||
"id": 13,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -107,6 +107,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "28811f59",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -89,6 +89,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 7,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -44,6 +44,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "a399b6a2",
|
||||
"id": 4,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
@ -120,6 +121,7 @@
|
||||
{
|
||||
"body": null,
|
||||
"documentation": null,
|
||||
"functionSelector": "c2985578",
|
||||
"id": 10,
|
||||
"implemented": false,
|
||||
"kind": "function",
|
||||
@ -160,6 +162,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "a399b6a2",
|
||||
"id": 15,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
@ -254,6 +257,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "c2985578",
|
||||
"id": 23,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
@ -300,6 +304,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "a399b6a2",
|
||||
"id": 30,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -48,6 +48,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "a399b6a2",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
@ -163,6 +164,7 @@
|
||||
{
|
||||
"body": null,
|
||||
"documentation": null,
|
||||
"functionSelector": "c2985578",
|
||||
"implemented": false,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
@ -218,6 +220,7 @@
|
||||
4
|
||||
],
|
||||
"documentation": null,
|
||||
"functionSelector": "a399b6a2",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
@ -349,6 +352,7 @@
|
||||
10
|
||||
],
|
||||
"documentation": null,
|
||||
"functionSelector": "c2985578",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
@ -428,6 +432,7 @@
|
||||
15
|
||||
],
|
||||
"documentation": null,
|
||||
"functionSelector": "a399b6a2",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -93,6 +93,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 10,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -105,6 +105,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 11,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -127,6 +127,7 @@
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 10,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -40,6 +40,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
@ -44,6 +44,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 4,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
@ -100,6 +101,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 9,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
@ -209,6 +211,7 @@
|
||||
"statements": []
|
||||
},
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"id": 21,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
|
@ -48,6 +48,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
@ -141,6 +142,7 @@
|
||||
"attributes":
|
||||
{
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
@ -286,6 +288,7 @@
|
||||
9
|
||||
],
|
||||
"documentation": null,
|
||||
"functionSelector": "26121ff0",
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"kind": "function",
|
||||
|
Loading…
Reference in New Issue
Block a user