Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix the doc generation for decl_module
  • Loading branch information
Guanqun Lu committed Sep 12, 2018
commit 48daef2586c4d469ef7028b84201a7d398c0e02c
37 changes: 25 additions & 12 deletions srml/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,9 @@ macro_rules! decl_module {
d.dispatch(origin)
}
}

__dispatch_impl_json_metadata! {
$mod_type $trait_instance $trait_name $call_type $origin_type
{$( $(#[doc = $doc_attr])* fn $fn_name(origin $(, $param_name : $param )*) -> $result; )*}
{$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $param_name : $param )*) -> $result; )*}
}
}
}
Expand Down Expand Up @@ -480,12 +479,11 @@ macro_rules! __dispatch_impl_json_metadata {
#[macro_export]
#[doc(hidden)]
macro_rules! __call_to_json {
// WITH AUX
(
$call_type:ident $origin_type:ty
{$(
$(#[doc = $doc_attr:tt])*
fn $fn_name:ident(origin
fn $fn_name:ident($from:ident
$(
, $param_name:ident : $param:ty
)*
Expand All @@ -496,7 +494,7 @@ macro_rules! __call_to_json {
r#"{ "name": ""#, stringify!($call_type),
r#"", "functions": {"#,
__functions_to_json!(""; 0; $origin_type; $(
fn $fn_name(origin $(, $param_name: $param )* ) -> $result;
fn $fn_name($from $(, $param_name: $param )* ) -> $result;
__function_doc_to_json!(""; $($doc_attr)*);
)*), " } }"
)
Expand All @@ -507,27 +505,30 @@ macro_rules! __call_to_json {
#[macro_export]
#[doc(hidden)]
macro_rules! __functions_to_json {
// WITHOUT AUX
// ROOT
(
$prefix_str:tt;
$fn_id:expr;
fn $fn_name:ident(
$($param_name:ident : $param:ty),*
$origin_type:ty;
fn $fn_name:ident(root
$(
, $param_name:ident : $param:ty
)*
) -> $result:ty;
$fn_doc:expr;
$($rest:tt)*
) => {
concat!($prefix_str, " ",
__function_to_json!(
fn $fn_name(
$($param_name : $param),*
$( $param_name : $param ),*
) -> $result;
$fn_doc;
$fn_id;
), __functions_to_json!(","; $fn_id + 1; $($rest)*)
), __functions_to_json!(","; $fn_id + 1; $origin_type; $($rest)*)
)
};
// WITH AUX
// NON ROOT
(
$prefix_str:tt;
$fn_id:expr;
Expand Down Expand Up @@ -583,6 +584,18 @@ macro_rules! __function_to_json {
r#" ], "description": ["#, $fn_doc, " ] }"
)
};
(
fn $fn_name:ident() -> $result:ty;
$fn_doc:tt;
$fn_id:expr;
) => {
concat!(
r#"""#, stringify!($fn_id), r#"""#,
r#": { "name": ""#, stringify!($fn_name),
r#"", "params": [ "#,
r#" ], "description": ["#, $fn_doc, " ] }"
)
};
}

/// Convert a function documentation attribute into its JSON representation.
Expand Down Expand Up @@ -661,7 +674,7 @@ mod tests {
r#" ], "description": [ ] }, "#,

r#""0 + 1 + 1 + 1 + 1": { "name": "aux_4", "params": [ "#,
r#"{ "name": "data", "type": "i32" }, "#,
r#"{ "name": "data", "type": "i32" }"#,
r#" ], "description": [ ] }"#,
r#" } }"#,
r#" }"#,
Expand Down