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 {
|
impl Attribute {
|
||||||
pub fn to_auxiliary_c(&self) -> String {
|
pub fn to_auxiliary_c(&self) -> String {
|
||||||
if let Attribute::doc(doc_comment) = self {
|
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 {
|
} else {
|
||||||
"".to_owned()
|
"".to_owned()
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,7 @@ use crate::parser::command_spec::{Attribute, DocIdentifier, Enumeration};
|
||||||
|
|
||||||
impl Enumeration {
|
impl Enumeration {
|
||||||
pub fn to_auxiliary_c(&self) -> String {
|
pub fn to_auxiliary_c(&self) -> String {
|
||||||
let doc_comments: String = self
|
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||||
.attributes
|
|
||||||
.iter()
|
|
||||||
.map(Attribute::to_auxiliary_c)
|
|
||||||
.collect::<String>();
|
|
||||||
let ident = &self.identifier.to_auxiliary_c();
|
let ident = &self.identifier.to_auxiliary_c();
|
||||||
let states = self
|
let states = self
|
||||||
.states
|
.states
|
||||||
|
|
|
@ -27,11 +27,7 @@ use crate::parser::command_spec::{Attribute, Function, Identifier, NamedType};
|
||||||
|
|
||||||
impl Function {
|
impl Function {
|
||||||
pub fn to_auxiliary_c(&self, namespaces: &[&Identifier]) -> String {
|
pub fn to_auxiliary_c(&self, namespaces: &[&Identifier]) -> String {
|
||||||
let doc_comments: String = self
|
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||||
.attributes
|
|
||||||
.iter()
|
|
||||||
.map(Attribute::to_auxiliary_c)
|
|
||||||
.collect::<String>();
|
|
||||||
let ident = self.identifier.to_c_with_path(namespaces);
|
let ident = self.identifier.to_c_with_path(namespaces);
|
||||||
let inputs: Vec<TokenStream2> = self.inputs.iter().map(NamedType::to_auxiliary_c).collect();
|
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 {
|
impl DocIdentifier {
|
||||||
pub fn to_auxiliary_c(&self) -> String {
|
pub fn to_auxiliary_c(&self) -> String {
|
||||||
let doc_comments: String = self
|
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||||
.attributes
|
|
||||||
.iter()
|
|
||||||
.map(Attribute::to_auxiliary_c)
|
|
||||||
.collect::<String>();
|
|
||||||
let ident = &self.name;
|
let ident = &self.name;
|
||||||
format!("{}{},", doc_comments, ident)
|
format!("{}{},", doc_comments, ident)
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,11 +102,7 @@ impl Namespace {
|
||||||
}
|
}
|
||||||
pub fn to_auxiliary_c_full_typedef(&self) -> String {
|
pub fn to_auxiliary_c_full_typedef(&self) -> String {
|
||||||
let ident = format_ident!("{}", self.name.name);
|
let ident = format_ident!("{}", self.name.name);
|
||||||
let doc_comments = self
|
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||||
.attributes
|
|
||||||
.iter()
|
|
||||||
.map(Attribute::to_auxiliary_c)
|
|
||||||
.collect::<String>();
|
|
||||||
|
|
||||||
let functions: TokenStream2 = self
|
let functions: TokenStream2 = self
|
||||||
.functions
|
.functions
|
||||||
|
|
|
@ -24,11 +24,7 @@ use crate::parser::command_spec::{Attribute, DocNamedType, Structure};
|
||||||
|
|
||||||
impl Structure {
|
impl Structure {
|
||||||
pub fn to_auxiliary_c(&self) -> String {
|
pub fn to_auxiliary_c(&self) -> String {
|
||||||
let doc_comments: String = self
|
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||||
.attributes
|
|
||||||
.iter()
|
|
||||||
.map(Attribute::to_auxiliary_c)
|
|
||||||
.collect::<String>();
|
|
||||||
let ident = self.identifier.to_rust();
|
let ident = self.identifier.to_rust();
|
||||||
let contents = self
|
let contents = self
|
||||||
.contents
|
.contents
|
||||||
|
|
|
@ -24,11 +24,7 @@ use crate::parser::command_spec::{Attribute, DocNamedType};
|
||||||
|
|
||||||
impl DocNamedType {
|
impl DocNamedType {
|
||||||
pub fn to_auxiliary_c(&self) -> String {
|
pub fn to_auxiliary_c(&self) -> String {
|
||||||
let doc_comments: String = self
|
let doc_comments: String = Attribute::to_auxiliary_c_merged(&self.attributes);
|
||||||
.attributes
|
|
||||||
.iter()
|
|
||||||
.map(Attribute::to_auxiliary_c)
|
|
||||||
.collect::<String>();
|
|
||||||
let ident = &self.name.to_rust();
|
let ident = &self.name.to_rust();
|
||||||
let r#type = self.r#type.to_auxiliary_c(false);
|
let r#type = self.r#type.to_auxiliary_c(false);
|
||||||
format!("{}{} {};", doc_comments, r#type, ident)
|
format!("{}{} {};", doc_comments, r#type, ident)
|
||||||
|
|
Reference in New Issue