feat(macros/generate/convert/auxiliary): Merge comments in c
```c /** comment one */ /** comment two */ /** comment three */ ``` is just not as readable as: ```c /** * comment one * comment two * comment three */ ```
This commit is contained in:
parent
37ba451362
commit
bb101c14fb
|
@ -25,7 +25,25 @@ use crate::parser::command_spec::Attribute;
|
|||
impl Attribute {
|
||||
pub fn to_auxiliary_c(&self) -> String {
|
||||
if let Attribute::doc(doc_comment) = self {
|
||||
format!("/**\n {}\n*/", doc_comment)
|
||||
format!("/**\n*{}\n*/", doc_comment)
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
}
|
||||
/// Merge mergable attributes (for example doc comments)
|
||||
pub fn to_auxiliary_c_merged(attributes: &[Self]) -> String {
|
||||
let doc_comments = attributes
|
||||
.iter()
|
||||
.map(|attr| {
|
||||
if let Attribute::doc(doc_comment) = attr {
|
||||
format!("*{}\n", doc_comment)
|
||||
} else {
|
||||
attr.to_auxiliary_c()
|
||||
}
|
||||
})
|
||||
.collect::<String>();
|
||||
if !attributes.is_empty() {
|
||||
format!("/**\n{}*/", doc_comments)
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
|
|
|
@ -24,11 +24,7 @@ use crate::parser::command_spec::{Attribute, DocIdentifier, Enumeration};
|
|||
|
||||
impl Enumeration {
|
||||
pub fn to_auxiliary_c(&self) -> String {
|
||||
let doc_comments: String = self
|
||||
.attributes
|
||||
.iter()
|
||||
.map(Attribute::to_auxiliary_c)
|
||||
.collect::<String>();
|
||||
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||
let ident = &self.identifier.to_auxiliary_c();
|
||||
let states = self
|
||||
.states
|
||||
|
|
|
@ -27,11 +27,7 @@ use crate::parser::command_spec::{Attribute, Function, Identifier, NamedType};
|
|||
|
||||
impl Function {
|
||||
pub fn to_auxiliary_c(&self, namespaces: &[&Identifier]) -> String {
|
||||
let doc_comments: String = self
|
||||
.attributes
|
||||
.iter()
|
||||
.map(Attribute::to_auxiliary_c)
|
||||
.collect::<String>();
|
||||
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||
let ident = self.identifier.to_c_with_path(namespaces);
|
||||
let inputs: Vec<TokenStream2> = self.inputs.iter().map(NamedType::to_auxiliary_c).collect();
|
||||
|
||||
|
|
|
@ -24,11 +24,7 @@ use crate::parser::command_spec::{Attribute, DocIdentifier};
|
|||
|
||||
impl DocIdentifier {
|
||||
pub fn to_auxiliary_c(&self) -> String {
|
||||
let doc_comments: String = self
|
||||
.attributes
|
||||
.iter()
|
||||
.map(Attribute::to_auxiliary_c)
|
||||
.collect::<String>();
|
||||
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||
let ident = &self.name;
|
||||
format!("{}{},", doc_comments, ident)
|
||||
}
|
||||
|
|
|
@ -102,11 +102,7 @@ impl Namespace {
|
|||
}
|
||||
pub fn to_auxiliary_c_full_typedef(&self) -> String {
|
||||
let ident = format_ident!("{}", self.name.name);
|
||||
let doc_comments = self
|
||||
.attributes
|
||||
.iter()
|
||||
.map(Attribute::to_auxiliary_c)
|
||||
.collect::<String>();
|
||||
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||
|
||||
let functions: TokenStream2 = self
|
||||
.functions
|
||||
|
|
|
@ -24,11 +24,7 @@ use crate::parser::command_spec::{Attribute, DocNamedType, Structure};
|
|||
|
||||
impl Structure {
|
||||
pub fn to_auxiliary_c(&self) -> String {
|
||||
let doc_comments: String = self
|
||||
.attributes
|
||||
.iter()
|
||||
.map(Attribute::to_auxiliary_c)
|
||||
.collect::<String>();
|
||||
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||
let ident = self.identifier.to_rust();
|
||||
let contents = self
|
||||
.contents
|
||||
|
|
|
@ -24,11 +24,7 @@ use crate::parser::command_spec::{Attribute, DocNamedType};
|
|||
|
||||
impl DocNamedType {
|
||||
pub fn to_auxiliary_c(&self) -> String {
|
||||
let doc_comments: String = self
|
||||
.attributes
|
||||
.iter()
|
||||
.map(Attribute::to_auxiliary_c)
|
||||
.collect::<String>();
|
||||
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||
let ident = &self.name.to_rust();
|
||||
let r#type = self.r#type.to_auxiliary_c(false);
|
||||
format!("{}{} {};", doc_comments, r#type, ident)
|
||||
|
|
Reference in New Issue