in src/bindgen/ir/enumeration.rs [504:598]
fn rename_for_config(&mut self, config: &Config) {
config.export.rename(&mut self.export_name);
if config.language != Language::Cxx && self.tag.is_some() {
// it makes sense to always prefix Tag with type name in C
let new_tag = format!("{}_Tag", self.export_name);
if self.repr.style == ReprStyle::Rust {
for variant in &mut self.variants {
if let VariantBody::Body { ref mut body, .. } = variant.body {
let path = Path::new(new_tag.clone());
let generic_path = GenericPath::new(path, vec![]);
body.fields[0].ty = Type::Path(generic_path);
}
}
}
self.tag = Some(new_tag);
}
for variant in &mut self.variants {
reserved::escape(&mut variant.export_name);
if let Some(discriminant) = &mut variant.discriminant {
discriminant.rename_for_config(config);
}
if let VariantBody::Body {
ref mut name,
ref mut body,
..
} = variant.body
{
body.rename_for_config(config);
reserved::escape(name);
}
}
if self
.annotations
.bool("prefix-with-name")
.unwrap_or(config.enumeration.prefix_with_name)
{
let separator = if config.export.mangle.remove_underscores {
""
} else {
"_"
};
for variant in &mut self.variants {
variant.export_name =
format!("{}{}{}", self.export_name, separator, variant.export_name);
if let VariantBody::Body { ref mut body, .. } = variant.body {
body.export_name =
format!("{}{}{}", self.export_name, separator, body.export_name());
}
}
}
let rules = self.annotations.parse_atom::<RenameRule>("rename-all");
let rules = rules
.as_ref()
.unwrap_or(&config.enumeration.rename_variants);
if let Some(r) = rules.not_none() {
self.variants = self
.variants
.iter()
.map(|variant| {
EnumVariant::new(
r.apply(
&variant.export_name,
IdentifierType::EnumVariant {
prefix: &self.export_name,
},
)
.into_owned(),
variant.discriminant.clone(),
match variant.body {
VariantBody::Empty(..) => variant.body.clone(),
VariantBody::Body {
ref name,
ref body,
inline,
inline_casts,
} => VariantBody::Body {
name: r.apply(name, IdentifierType::StructMember).into_owned(),
body: body.clone(),
inline,
inline_casts,
},
},
variant.cfg.clone(),
variant.documentation.clone(),
)
})
.collect();
}
}