Skip to content

Commit 9f558e3

Browse files
petrochenkovemilio
authored andcommitted
enum: enum_name -> tag_name
1 parent 8997277 commit 9f558e3

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/bindgen/ir/enumeration.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub struct Enum {
281281

282282
impl Enum {
283283
/// Name of the generated tag enum.
284-
fn enum_name(&self) -> &str {
284+
fn tag_name(&self) -> &str {
285285
self.tag.as_deref().unwrap_or_else(|| self.export_name())
286286
}
287287

@@ -598,7 +598,7 @@ impl Source for Enum {
598598
let size = self.repr.ty.map(|ty| ty.to_primitive().to_repr_c(config));
599599
let has_data = self.tag.is_some();
600600
let inline_tag_field = Self::inline_tag_field(&self.repr);
601-
let enum_name = self.enum_name();
601+
let tag_name = self.tag_name();
602602

603603
let condition = self.cfg.to_condition(config);
604604
condition.write_before(config, out);
@@ -614,7 +614,7 @@ impl Source for Enum {
614614
}
615615

616616
// Emit the tag enum and everything related to it.
617-
self.write_tag_enum(config, out, size, has_data, inline_tag_field, enum_name);
617+
self.write_tag_enum(config, out, size, has_data, inline_tag_field, tag_name);
618618

619619
// If the enum has data, we need to emit structs for the variants and gather them together.
620620
if has_data {
@@ -630,7 +630,7 @@ impl Source for Enum {
630630
}
631631

632632
// Emit tag field that is separate from all variants.
633-
self.write_tag_field(config, out, size, inline_tag_field, enum_name);
633+
self.write_tag_field(config, out, size, inline_tag_field, tag_name);
634634
out.new_line();
635635

636636
// Open union of all variants with data, only in the non-inline tag scenario.
@@ -653,7 +653,7 @@ impl Source for Enum {
653653
}
654654

655655
// Emit convenience methods for the struct or enum for the data.
656-
self.write_derived_functions_data(config, out, inline_tag_field, enum_name);
656+
self.write_derived_functions_data(config, out, inline_tag_field, tag_name);
657657

658658
// Emit the post_body section, if relevant.
659659
if let Some(body) = config.export.post_body(&self.path) {
@@ -685,15 +685,15 @@ impl Enum {
685685
size: Option<&str>,
686686
has_data: bool,
687687
inline_tag_field: bool,
688-
enum_name: &str,
688+
tag_name: &str,
689689
) {
690690
// Open the tag enum.
691691
match config.language {
692692
Language::C => {
693693
if let Some(prim) = size {
694694
// If we need to specify size, then we have no choice but to create a typedef,
695695
// so `config.style` is not respected.
696-
write!(out, "enum {}", enum_name);
696+
write!(out, "enum {}", tag_name);
697697

698698
if config.cpp_compatible_c() {
699699
out.new_line();
@@ -710,7 +710,7 @@ impl Enum {
710710
}
711711
out.write("enum");
712712
if config.style.generate_tag() {
713-
write!(out, " {}", enum_name);
713+
write!(out, " {}", tag_name);
714714
}
715715
}
716716
}
@@ -727,7 +727,7 @@ impl Enum {
727727
}
728728
}
729729

730-
write!(out, " {}", enum_name);
730+
write!(out, " {}", tag_name);
731731
if let Some(prim) = size {
732732
write!(out, " : {}", prim);
733733
}
@@ -738,7 +738,7 @@ impl Enum {
738738
// so `config.style` is not respected.
739739
write!(out, "cdef enum");
740740
} else {
741-
write!(out, "{}enum {}", config.style.cython_def(), enum_name);
741+
write!(out, "{}enum {}", config.style.cython_def(), tag_name);
742742
}
743743
}
744744
}
@@ -755,7 +755,7 @@ impl Enum {
755755
// Close the tag enum.
756756
if config.language == Language::C && size.is_none() && config.style.generate_typedef() {
757757
out.close_brace(false);
758-
write!(out, " {};", enum_name);
758+
write!(out, " {};", tag_name);
759759
} else {
760760
out.close_brace(true);
761761
}
@@ -771,7 +771,7 @@ impl Enum {
771771

772772
if config.language != Language::Cxx {
773773
out.new_line();
774-
write!(out, "{} {} {};", config.language.typedef(), prim, enum_name);
774+
write!(out, "{} {} {};", config.language.typedef(), prim, tag_name);
775775
}
776776

777777
if config.cpp_compatible_c() {
@@ -781,7 +781,7 @@ impl Enum {
781781
}
782782

783783
// Emit convenience methods for the tag enum.
784-
self.write_derived_functions_enum(config, out, has_data, inline_tag_field, enum_name);
784+
self.write_derived_functions_enum(config, out, has_data, inline_tag_field, tag_name);
785785
}
786786

787787
/// The code here mirrors the beginning of `Struct::write` and `Union::write`.
@@ -847,7 +847,7 @@ impl Enum {
847847
out: &mut SourceWriter<F>,
848848
size: Option<&str>,
849849
inline_tag_field: bool,
850-
enum_name: &str,
850+
tag_name: &str,
851851
) {
852852
// C++ allows accessing only common initial sequence of union
853853
// fields so we have to wrap the tag field into an anonymous struct.
@@ -862,7 +862,7 @@ impl Enum {
862862
out.write("enum ");
863863
}
864864

865-
write!(out, "{} tag;", enum_name);
865+
write!(out, "{} tag;", tag_name);
866866

867867
if wrap_tag {
868868
out.close_brace(true);
@@ -902,7 +902,7 @@ impl Enum {
902902
out: &mut SourceWriter<F>,
903903
has_data: bool,
904904
inline_tag_field: bool,
905-
enum_name: &str,
905+
tag_name: &str,
906906
) {
907907
if config.language != Language::Cxx {
908908
return;
@@ -942,7 +942,7 @@ impl Enum {
942942
"{} std::ostream& operator<<(std::ostream& {}, const {}& {})",
943943
if has_data { "friend" } else { "inline" },
944944
stream,
945-
enum_name,
945+
tag_name,
946946
instance,
947947
);
948948

@@ -952,9 +952,9 @@ impl Enum {
952952
write!(
953953
out,
954954
"using {} = {}::{};",
955-
enum_name,
955+
tag_name,
956956
self.export_name(),
957-
enum_name
957+
tag_name
958958
);
959959
out.new_line();
960960
}
@@ -966,7 +966,7 @@ impl Enum {
966966
.map(|x| {
967967
format!(
968968
"case {}::{}: {} << \"{}\"; break;",
969-
enum_name, x.export_name, stream, x.export_name
969+
tag_name, x.export_name, stream, x.export_name
970970
)
971971
})
972972
.collect();
@@ -996,9 +996,9 @@ impl Enum {
996996
write!(
997997
out,
998998
"using {} = {}::{};",
999-
enum_name,
999+
tag_name,
10001000
self.export_name(),
1001-
enum_name
1001+
tag_name
10021002
);
10031003
out.new_line();
10041004

@@ -1012,7 +1012,7 @@ impl Enum {
10121012
if let VariantBody::Body { ref name, .. } = x.body {
10131013
format!(
10141014
"case {}::{}: {} << {}{}{}.{}; break;",
1015-
enum_name,
1015+
tag_name,
10161016
x.export_name,
10171017
stream,
10181018
if inline_tag_field { "" } else { &tag_str },
@@ -1023,7 +1023,7 @@ impl Enum {
10231023
} else {
10241024
format!(
10251025
"case {}::{}: {} << {}; break;",
1026-
enum_name, x.export_name, stream, tag_str,
1026+
tag_name, x.export_name, stream, tag_str,
10271027
)
10281028
}
10291029
})
@@ -1044,7 +1044,7 @@ impl Enum {
10441044
config: &Config,
10451045
out: &mut SourceWriter<F>,
10461046
inline_tag_field: bool,
1047-
enum_name: &str,
1047+
tag_name: &str,
10481048
) {
10491049
if config.language != Language::Cxx {
10501050
return;
@@ -1133,7 +1133,7 @@ impl Enum {
11331133
}
11341134

11351135
out.new_line();
1136-
write!(out, "result.tag = {}::{};", enum_name, variant.export_name);
1136+
write!(out, "result.tag = {}::{};", tag_name, variant.export_name);
11371137
out.new_line();
11381138
write!(out, "return result;");
11391139
out.close_brace(false);
@@ -1145,7 +1145,7 @@ impl Enum {
11451145
// FIXME: create a config for method case
11461146
write!(out, "bool Is{}() const", variant.export_name);
11471147
out.open_brace();
1148-
write!(out, "return tag == {}::{};", enum_name, variant.export_name);
1148+
write!(out, "return tag == {}::{};", tag_name, variant.export_name);
11491149
out.close_brace(false);
11501150

11511151
let assert_name = match config.enumeration.cast_assert_name {

0 commit comments

Comments
 (0)