mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds JSON import / export for structured documentation.
This commit is contained in:
@@ -208,6 +208,8 @@ ASTPointer<ASTNode> ASTJsonImporter::convertJsonToASTNode(Json::Value const& _js
|
||||
return createElementaryTypeNameExpression(_json);
|
||||
if (nodeType == "Literal")
|
||||
return createLiteral(_json);
|
||||
if (nodeType == "StructuredDocumentation")
|
||||
return createDocumentation(_json);
|
||||
else
|
||||
astAssert(false, "Unknown type of ASTNode: " + nodeType);
|
||||
}
|
||||
@@ -283,7 +285,7 @@ ASTPointer<ContractDefinition> ASTJsonImporter::createContractDefinition(Json::V
|
||||
return createASTNode<ContractDefinition>(
|
||||
_node,
|
||||
make_shared<ASTString>(_node["name"].asString()),
|
||||
nullOrASTString(_node, "documentation"),
|
||||
_node["documentation"].isNull() ? nullptr : createDocumentation(member(_node, "documentation")),
|
||||
baseContracts,
|
||||
subNodes,
|
||||
contractKind(_node),
|
||||
@@ -397,7 +399,7 @@ ASTPointer<FunctionDefinition> ASTJsonImporter::createFunctionDefinition(Json::V
|
||||
kind,
|
||||
memberAsBool(_node, "virtual"),
|
||||
_node["overrides"].isNull() ? nullptr : createOverrideSpecifier(member(_node, "overrides")),
|
||||
nullOrASTString(_node, "documentation"),
|
||||
_node["documentation"].isNull() ? nullptr : createDocumentation(member(_node, "documentation")),
|
||||
createParameterList(member(_node, "parameters")),
|
||||
modifiers,
|
||||
createParameterList(member(_node, "returnParameters")),
|
||||
@@ -428,7 +430,7 @@ ASTPointer<ModifierDefinition> ASTJsonImporter::createModifierDefinition(Json::V
|
||||
return createASTNode<ModifierDefinition>(
|
||||
_node,
|
||||
memberAsASTString(_node, "name"),
|
||||
nullOrASTString(_node,"documentation"),
|
||||
_node["documentation"].isNull() ? nullptr : createDocumentation(member(_node, "documentation")),
|
||||
createParameterList(member(_node, "parameters")),
|
||||
memberAsBool(_node, "virtual"),
|
||||
_node["overrides"].isNull() ? nullptr : createOverrideSpecifier(member(_node, "overrides")),
|
||||
@@ -453,7 +455,7 @@ ASTPointer<EventDefinition> ASTJsonImporter::createEventDefinition(Json::Value c
|
||||
return createASTNode<EventDefinition>(
|
||||
_node,
|
||||
memberAsASTString(_node, "name"),
|
||||
nullOrASTString(_node, "documentation"),
|
||||
_node["documentation"].isNull() ? nullptr : createDocumentation(member(_node, "documentation")),
|
||||
createParameterList(member(_node, "parameters")),
|
||||
memberAsBool(_node, "anonymous")
|
||||
);
|
||||
@@ -842,6 +844,18 @@ ASTPointer<ASTNode> ASTJsonImporter::createLiteral(Json::Value const& _node)
|
||||
);
|
||||
}
|
||||
|
||||
ASTPointer<StructuredDocumentation> ASTJsonImporter::createDocumentation(Json::Value const& _node)
|
||||
{
|
||||
static string const textString = "text";
|
||||
|
||||
astAssert(member(_node, textString).isString(), "'text' must be a string");
|
||||
|
||||
return createASTNode<StructuredDocumentation>(
|
||||
_node,
|
||||
make_shared<ASTString>(_node[textString].asString())
|
||||
);
|
||||
}
|
||||
|
||||
// ===== helper functions ==========
|
||||
|
||||
Json::Value ASTJsonImporter::member(Json::Value const& _node, string const& _name)
|
||||
|
||||
Reference in New Issue
Block a user