mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #12653 from nishant-sachdeva/selector_for_custom_errors
Added errorSelector field for custom errors
This commit is contained in:
commit
5db2907636
@ -4,12 +4,11 @@ Language Features:
|
||||
|
||||
|
||||
Compiler Features:
|
||||
|
||||
* JSON-AST: Added selector field for errors and events.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
|
||||
|
||||
### 0.8.12 (2022-02-16)
|
||||
|
||||
Language Features:
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <libsolutil/JSON.h>
|
||||
#include <libsolutil/UTF8.h>
|
||||
#include <libsolutil/CommonData.h>
|
||||
#include <libsolutil/Keccak256.h>
|
||||
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
||||
@ -493,24 +494,36 @@ bool ASTJsonConverter::visit(ModifierInvocation const& _node)
|
||||
bool ASTJsonConverter::visit(EventDefinition const& _node)
|
||||
{
|
||||
m_inEvent = true;
|
||||
setJsonNode(_node, "EventDefinition", {
|
||||
std::vector<pair<string, Json::Value>> _attributes = {
|
||||
make_pair("name", _node.name()),
|
||||
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
|
||||
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
|
||||
make_pair("parameters", toJson(_node.parameterList())),
|
||||
make_pair("anonymous", _node.isAnonymous())
|
||||
});
|
||||
};
|
||||
if (m_stackState >= CompilerStack::State::AnalysisPerformed)
|
||||
_attributes.emplace_back(
|
||||
make_pair(
|
||||
"eventSelector",
|
||||
toHex(u256(h256::Arith(util::keccak256(_node.functionType(true)->externalSignature()))))
|
||||
));
|
||||
|
||||
setJsonNode(_node, "EventDefinition", std::move(_attributes));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTJsonConverter::visit(ErrorDefinition const& _node)
|
||||
{
|
||||
setJsonNode(_node, "ErrorDefinition", {
|
||||
std::vector<pair<string, Json::Value>> _attributes = {
|
||||
make_pair("name", _node.name()),
|
||||
make_pair("nameLocation", sourceLocationToString(_node.nameLocation())),
|
||||
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
|
||||
make_pair("parameters", toJson(_node.parameterList()))
|
||||
});
|
||||
};
|
||||
if (m_stackState >= CompilerStack::State::AnalysisPerformed)
|
||||
_attributes.emplace_back(make_pair("errorSelector", _node.functionType(true)->externalIdentifierHex()));
|
||||
|
||||
setJsonNode(_node, "ErrorDefinition", std::move(_attributes));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,7 @@
|
||||
"src": "69:26:3",
|
||||
"text": "Some comment on Evt."
|
||||
},
|
||||
"eventSelector": "a69007916fc1145953e5a7032d7c3eab4b8e2f33ec59b0f71e732904eeede3a4",
|
||||
"id": 12,
|
||||
"name": "Evt",
|
||||
"nameLocation": "102:3:3",
|
||||
|
@ -30,6 +30,7 @@
|
||||
[
|
||||
{
|
||||
"anonymous": false,
|
||||
"eventSelector": "92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028",
|
||||
"id": 2,
|
||||
"name": "E",
|
||||
"nameLocation": "19:1:1",
|
||||
|
@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
event E(function() internal);
|
||||
}
|
||||
|
||||
// ----
|
@ -0,0 +1,78 @@
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"id": 8,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"abstract": false,
|
||||
"baseContracts": [],
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"id": 7,
|
||||
"name": "C",
|
||||
"nameLocation": "9:1:1",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"anonymous": false,
|
||||
"id": 6,
|
||||
"name": "E",
|
||||
"nameLocation": "23:1:1",
|
||||
"nodeType": "EventDefinition",
|
||||
"parameters":
|
||||
{
|
||||
"id": 5,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 4,
|
||||
"indexed": false,
|
||||
"mutability": "mutable",
|
||||
"name": "",
|
||||
"nameLocation": "-1:-1:-1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"src": "25:20:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 3,
|
||||
"nodeType": "FunctionTypeName",
|
||||
"parameterTypes":
|
||||
{
|
||||
"id": 1,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "33:2:1"
|
||||
},
|
||||
"returnParameterTypes":
|
||||
{
|
||||
"id": 2,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "44:0:1"
|
||||
},
|
||||
"src": "25:20:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"typeDescriptions": {},
|
||||
"visibility": "internal"
|
||||
},
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"src": "24:21:1"
|
||||
},
|
||||
"src": "17:29:1"
|
||||
}
|
||||
],
|
||||
"src": "0:48:1",
|
||||
"usedErrors": []
|
||||
}
|
||||
],
|
||||
"src": "0:49:1"
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"errorSelector": "c1599bd9",
|
||||
"id": 2,
|
||||
"name": "X",
|
||||
"nameLocation": "6:1:1",
|
||||
@ -127,6 +128,7 @@
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"errorSelector": "2bc80f3a",
|
||||
"id": 11,
|
||||
"name": "T",
|
||||
"nameLocation": "63:1:1",
|
||||
@ -145,7 +147,7 @@
|
||||
{
|
||||
"id": 17,
|
||||
"nodeType": "Block",
|
||||
"src": "97:8:1",
|
||||
"src": "92:8:1",
|
||||
"statements":
|
||||
[
|
||||
{
|
||||
@ -160,7 +162,7 @@
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 9,
|
||||
"src": "99:1:1",
|
||||
"src": "94:1:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_function_internal_nonpayable$__$returns$__$",
|
||||
@ -175,7 +177,7 @@
|
||||
"lValueRequested": false,
|
||||
"names": [],
|
||||
"nodeType": "FunctionCall",
|
||||
"src": "99:3:1",
|
||||
"src": "94:3:1",
|
||||
"tryCall": false,
|
||||
"typeDescriptions":
|
||||
{
|
||||
@ -185,7 +187,7 @@
|
||||
},
|
||||
"id": 16,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "99:3:1"
|
||||
"src": "94:3:1"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -209,17 +211,17 @@
|
||||
"id": 13,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "97:0:1"
|
||||
"src": "92:0:1"
|
||||
},
|
||||
"scope": 19,
|
||||
"src": "72:33:1",
|
||||
"stateMutability": "pure",
|
||||
"src": "72:28:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"virtual": false,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"scope": 20,
|
||||
"src": "40:67:1",
|
||||
"src": "40:62:1",
|
||||
"usedErrors":
|
||||
[
|
||||
2,
|
||||
@ -227,5 +229,5 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"src": "0:108:1"
|
||||
"src": "0:103:1"
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ error X();
|
||||
function f() { revert X(); }
|
||||
contract C {
|
||||
error T();
|
||||
function h() public pure { f(); }
|
||||
function h() public { f(); }
|
||||
}
|
||||
|
||||
// ----
|
||||
|
@ -108,7 +108,7 @@
|
||||
{
|
||||
"id": 17,
|
||||
"nodeType": "Block",
|
||||
"src": "97:8:1",
|
||||
"src": "92:8:1",
|
||||
"statements":
|
||||
[
|
||||
{
|
||||
@ -121,19 +121,19 @@
|
||||
"name": "f",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"src": "99:1:1",
|
||||
"src": "94:1:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"id": 15,
|
||||
"names": [],
|
||||
"nodeType": "FunctionCall",
|
||||
"src": "99:3:1",
|
||||
"src": "94:3:1",
|
||||
"tryCall": false,
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"id": 16,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "99:3:1"
|
||||
"src": "94:3:1"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -156,17 +156,17 @@
|
||||
"id": 13,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "97:0:1"
|
||||
"src": "92:0:1"
|
||||
},
|
||||
"src": "72:33:1",
|
||||
"stateMutability": "pure",
|
||||
"src": "72:28:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"virtual": false,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"src": "40:67:1",
|
||||
"src": "40:62:1",
|
||||
"usedErrors": []
|
||||
}
|
||||
],
|
||||
"src": "0:108:1"
|
||||
"src": "0:103:1"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user