Skip to content

Commit 36608a6

Browse files
committed
Change how enum constants are output
1 parent 5345bae commit 36608a6

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

crates/header-translator/src/library.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,11 @@ impl fmt::Display for Library {
131131

132132
writeln!(f)?;
133133

134-
for (name, file) in &self.files {
134+
for (file_name, file) in &self.files {
135135
// NOTE: some SDK files have '+' in the file name
136-
let name = name.replace('+', "_");
136+
let file_name = file_name.replace('+', "_");
137137
for stmt in &file.stmts {
138-
let mut iter = stmt.declared_types().filter(|item| !item.starts_with('_'));
139-
if let Some(item) = iter.next() {
138+
if let Some(name) = stmt.name() {
140139
// Use a set to deduplicate features, and to have them in
141140
// a consistent order
142141
let mut features = BTreeSet::new();
@@ -163,9 +162,20 @@ impl fmt::Display for Library {
163162
}
164163
}
165164

166-
writeln!(f, "pub use self::__{name}::{{{item}")?;
167-
for item in iter {
168-
writeln!(f, ", {item}")?;
165+
let visibility = if name.starts_with('_') {
166+
"pub(crate)"
167+
} else {
168+
"pub"
169+
};
170+
171+
write!(f, "{visibility} use self::__{file_name}::{{{name}}};")?;
172+
}
173+
174+
let extra_declared_types = stmt.extra_declared_types();
175+
if !extra_declared_types.is_empty() {
176+
write!(f, "pub use self::__{file_name}::{{")?;
177+
for item in extra_declared_types {
178+
writeln!(f, " {item},")?;
169179
}
170180
writeln!(f, "}};")?;
171181
}

crates/header-translator/src/stmt.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ impl Stmt {
12601260
}
12611261
}
12621262

1263-
pub(crate) fn declared_types(&self) -> impl Iterator<Item = &str> {
1263+
pub(crate) fn name(&self) -> Option<&str> {
12641264
match self {
12651265
Stmt::ClassDecl { id, skipped, .. } => {
12661266
if *skipped {
@@ -1280,14 +1280,14 @@ impl Stmt {
12801280
Stmt::FnDecl { .. } => None,
12811281
Stmt::AliasDecl { id, .. } => Some(&*id.name),
12821282
}
1283-
.into_iter()
1284-
.chain({
1285-
if let Stmt::EnumDecl { variants, .. } = self {
1286-
variants.iter().map(|(name, _, _)| &**name).collect()
1287-
} else {
1288-
vec![]
1289-
}
1290-
})
1283+
}
1284+
1285+
pub(crate) fn extra_declared_types(&self) -> Vec<&str> {
1286+
if let Stmt::EnumDecl { variants, .. } = self {
1287+
variants.iter().map(|(name, _, _)| &**name).collect()
1288+
} else {
1289+
vec![]
1290+
}
12911291
}
12921292
}
12931293

crates/icrate/src/generated

0 commit comments

Comments
 (0)