mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #14119 from veniger/natspec-struct
Adds NatSpec to AST for struct definitions.
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"exportedSymbols":
|
||||
{
|
||||
"Example":
|
||||
[
|
||||
8
|
||||
]
|
||||
},
|
||||
"id": 9,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"canonicalName": "Example",
|
||||
"documentation":
|
||||
{
|
||||
"id": 1,
|
||||
"nodeType": "StructuredDocumentation",
|
||||
"src": "0:112:1",
|
||||
"text": "@title example of title\n @author example of author\n @notice example of notice\n @dev example of dev"
|
||||
},
|
||||
"id": 8,
|
||||
"members":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 3,
|
||||
"mutability": "mutable",
|
||||
"name": "text",
|
||||
"nameLocation": "140:4:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 8,
|
||||
"src": "133:11:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_string_storage_ptr",
|
||||
"typeString": "string"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
"id": 2,
|
||||
"name": "string",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "133:6:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_string_storage_ptr",
|
||||
"typeString": "string"
|
||||
}
|
||||
},
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"id": 5,
|
||||
"mutability": "mutable",
|
||||
"name": "valid",
|
||||
"nameLocation": "155:5:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 8,
|
||||
"src": "150:10:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
"id": 4,
|
||||
"name": "bool",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "150:4:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
},
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"id": 7,
|
||||
"mutability": "mutable",
|
||||
"name": "value",
|
||||
"nameLocation": "174:5:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 8,
|
||||
"src": "166:13:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
},
|
||||
"typeName":
|
||||
{
|
||||
"id": 6,
|
||||
"name": "uint256",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "166:7:1",
|
||||
"typeDescriptions":
|
||||
{
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
}
|
||||
},
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"name": "Example",
|
||||
"nameLocation": "119:7:1",
|
||||
"nodeType": "StructDefinition",
|
||||
"scope": 9,
|
||||
"src": "112:70:1",
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"src": "112:71:1"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/// @title example of title
|
||||
/// @author example of author
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
struct Example {
|
||||
string text;
|
||||
bool valid;
|
||||
uint256 value;
|
||||
}
|
||||
|
||||
// ----
|
||||
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"id": 9,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"documentation":
|
||||
{
|
||||
"id": 1,
|
||||
"nodeType": "StructuredDocumentation",
|
||||
"src": "0:112:1",
|
||||
"text": "@title example of title\n @author example of author\n @notice example of notice\n @dev example of dev"
|
||||
},
|
||||
"id": 8,
|
||||
"members":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 3,
|
||||
"mutability": "mutable",
|
||||
"name": "text",
|
||||
"nameLocation": "140:4:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"src": "133:11:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 2,
|
||||
"name": "string",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "133:6:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"id": 5,
|
||||
"mutability": "mutable",
|
||||
"name": "valid",
|
||||
"nameLocation": "155:5:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"src": "150:10:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 4,
|
||||
"name": "bool",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "150:4:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"id": 7,
|
||||
"mutability": "mutable",
|
||||
"name": "value",
|
||||
"nameLocation": "174:5:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"src": "166:13:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 6,
|
||||
"name": "uint256",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "166:7:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"name": "Example",
|
||||
"nameLocation": "119:7:1",
|
||||
"nodeType": "StructDefinition",
|
||||
"src": "112:70:1",
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"src": "112:71:1"
|
||||
}
|
||||
@@ -1076,6 +1076,41 @@ BOOST_AUTO_TEST_CASE(dev_author_at_function)
|
||||
expectNatspecError(sourceCode);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_no_docs)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
/// @title example of title
|
||||
/// @author example of author
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
struct Example {
|
||||
string text;
|
||||
bool valid;
|
||||
uint256 value;
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
char const* devDoc = R"ABCDEF(
|
||||
{
|
||||
"kind": "dev",
|
||||
"methods": {},
|
||||
"version": 1
|
||||
})ABCDEF";
|
||||
|
||||
checkNatspec(sourceCode, "C", devDoc, false);
|
||||
|
||||
char const* userDoc = R"ABCDEF(
|
||||
{
|
||||
"kind": "user",
|
||||
"methods": {},
|
||||
"version": 1
|
||||
})ABCDEF";
|
||||
|
||||
checkNatspec(sourceCode, "C", userDoc, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(enum_no_docs)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
||||
@@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
|
||||
BOOST_CHECK_EQUAL(c.type()->identifier(), "t_type$_t_contract$_MyContract$$$_$2_$");
|
||||
BOOST_CHECK_EQUAL(ContractType(c, true).identifier(), "t_super$_MyContract$$$_$2");
|
||||
|
||||
StructDefinition s(++id, {}, make_shared<string>("Struct"), {}, {});
|
||||
StructDefinition s(++id, {}, make_shared<string>("Struct"), {}, {}, {});
|
||||
s.annotation().recursive = false;
|
||||
BOOST_CHECK_EQUAL(s.type()->identifier(), "t_type$_t_struct$_Struct_$3_storage_ptr_$");
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
/// @title example of title
|
||||
/// @author example of author
|
||||
/// @notice example of notice
|
||||
/// @dev example of dev
|
||||
struct Example {
|
||||
string text;
|
||||
bool valid;
|
||||
uint256 value;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
Reference in New Issue
Block a user