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:
Benedikt Peetz 2024-03-27 10:17:38 +01:00
parent 37ba451362
commit bb101c14fb
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
7 changed files with 25 additions and 31 deletions

View File

@ -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()
}

View File

@ -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

View File

@ -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();

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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)