diff --git a/README.md b/README.md index 64f011d83154cdd59d408be2f2fdc11a4d07edf3..dab0371d7a6a7993a8073288e1354c3b9f025cb2 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,6 @@ rename_args = "[None|GeckoCase|LowerCase|UpperCase|PascalCase|CamelCase|SnakeCas [struct] # A rule to use to rename field names rename_fields = "[None|GeckoCase|LowerCase|UpperCase|PascalCase|CamelCase|SnakeCase|ScreamingSnakeCase|QualifiedScreamingSnakeCase]" -# Whether to generate helper template specialization for generics -generic_template_specialization = true # Whether to derive an operator== for all structs derive_eq = false # Whether to derive an operator!= for all structs diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index 74bf4c9a2016b4fbff12e8c2dc338364b555be6b..4487b7f285fd64d26158feaaef4879bba86b7b1d 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -9,8 +9,7 @@ use std::fs; use bindgen::config::{Config, Language}; use bindgen::ir::{Constant, ItemContainer, Function, Static}; -use bindgen::monomorph::TemplateSpecialization; -use bindgen::writer::{ListType, Source, SourceWriter}; +use bindgen::writer::{Source, SourceWriter}; /// A bindings header that can be written. pub struct Bindings { @@ -19,7 +18,6 @@ pub struct Bindings { constants: Vec<Constant>, items: Vec<ItemContainer>, functions: Vec<Function>, - template_specializations: Vec<TemplateSpecialization>, } impl Bindings { @@ -27,15 +25,13 @@ impl Bindings { constants: Vec<Constant>, globals: Vec<Static>, items: Vec<ItemContainer>, - functions: Vec<Function>, - template_specializations: Vec<TemplateSpecialization>) -> Bindings { + functions: Vec<Function>) -> Bindings { Bindings { config: config, globals: globals, constants: constants, items: items, functions: functions, - template_specializations: template_specializations, } } @@ -152,38 +148,6 @@ impl Bindings { out.new_line(); } - if self.config.structure.generic_template_specialization && - self.config.language == Language::Cxx { - self.open_namespaces(&mut out); - for template in &self.template_specializations { - out.new_line_if_not_start(); - out.write("template<"); - for (i, param) in template.generic.generic_params.iter().enumerate() { - if i != 0 { - out.write(", ") - } - write!(out, "typename {}", param); - } - out.write(">"); - out.new_line(); - write!(out, "struct {};", template.generic.name); - out.new_line(); - - for &(ref monomorph_path, ref generic_values) in &template.monomorphs { - out.new_line(); - out.write("template<>"); - out.new_line(); - write!(out, "struct {}<", template.generic.name); - out.write_horizontal_source_list(generic_values, ListType::Join(", ")); - write!(out, "> : public {}", monomorph_path); - out.open_brace(); - out.close_brace(true); - out.new_line(); - } - } - self.close_namespaces(&mut out); - } - if let Some(ref f) = self.config.autogen_warning { out.new_line_if_not_start(); write!(out, "{}", f); diff --git a/src/bindgen/builder.rs b/src/bindgen/builder.rs index 5dc5654365094cb95e9c97918150bae0ad09ddb6..57de1114087a1d6dfe7c20fe1b23cec63a773433 100644 --- a/src/bindgen/builder.rs +++ b/src/bindgen/builder.rs @@ -121,12 +121,6 @@ impl Builder { self } - #[allow(unused)] - pub fn with_generic_template_specialization(mut self, generic_template_specialization: bool) -> Builder { - self.config.structure.generic_template_specialization = generic_template_specialization; - self - } - #[allow(unused)] pub fn with_documentation(mut self, documentation: bool) -> Builder { self.config.documentation = documentation; diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index a7114716f93de12e3414b30089ad192baa08c8f9..c3c26617553e1c3d95cbca5671bfdf21cf666f7f 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -146,8 +146,6 @@ impl FunctionConfig { pub struct StructConfig { /// The rename rule to apply to the name of struct fields pub rename_fields: Option<RenameRule>, - /// Whether to generate helper template specialization for generics - pub generic_template_specialization: bool, /// Whether to generate a piecewise equality operator pub derive_eq: bool, /// Whether to generate a piecewise inequality operator @@ -166,7 +164,6 @@ impl Default for StructConfig { fn default() -> StructConfig { StructConfig { rename_fields: None, - generic_template_specialization: true, derive_eq: false, derive_neq: false, derive_lt: false, diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs index 3e8a60d1c04ec3a884f72b3d9eb5f2dc13e859f9..af534ea76f8bfc648635dc03492349115daeea65 100644 --- a/src/bindgen/library.rs +++ b/src/bindgen/library.rs @@ -10,7 +10,7 @@ use bindgen::config::{Config, Language}; use bindgen::dependencies::Dependencies; use bindgen::ir::{Constant, Enum, Function, ItemContainer, ItemMap, Item}; use bindgen::ir::{OpaqueItem, Path, Specialization, Static, Struct, Typedef, Union}; -use bindgen::monomorph::{Monomorphs, TemplateSpecialization}; +use bindgen::monomorph::Monomorphs; #[derive(Debug, Clone)] pub struct Library { @@ -24,7 +24,6 @@ pub struct Library { typedefs: ItemMap<Typedef>, specializations: ItemMap<Specialization>, functions: Vec<Function>, - template_specializations: Vec<TemplateSpecialization>, } impl Library { @@ -49,7 +48,6 @@ impl Library { typedefs: typedefs, specializations: specializations, functions: functions, - template_specializations: Vec::new(), } } @@ -74,27 +72,18 @@ impl Library { global.add_dependencies(&self, &mut dependencies); }); - if self.config.structure.generic_template_specialization && - self.config.language == Language::Cxx { - for template_specialization in &self.template_specializations { - template_specialization.add_dependencies(&self, &mut dependencies); - } - } - dependencies.sort(); let items = dependencies.order; let constants = self.constants.to_vec(); let globals = self.globals.to_vec(); let functions = mem::replace(&mut self.functions, Vec::new()); - let template_specializations = mem::replace(&mut self.template_specializations, Vec::new()); Ok(Bindings::new(self.config.clone(), constants, globals, items, - functions, - template_specializations)) + functions)) } pub fn get_items(&self, p: &Path) -> Option<Vec<ItemContainer>> { @@ -327,7 +316,5 @@ impl Library { for x in &mut self.functions { x.mangle_paths(&monomorphs); } - - self.template_specializations = monomorphs.drain_template_specializations(); } } diff --git a/src/bindgen/monomorph.rs b/src/bindgen/monomorph.rs index 1f05fd75c4b7cbd3824f1a2ef90d3f47cd8e186c..ea70009b7a4c84bb58c878c51605badd320c0458 100644 --- a/src/bindgen/monomorph.rs +++ b/src/bindgen/monomorph.rs @@ -3,35 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::collections::HashMap; -use std::collections::BTreeMap; use std::mem; -use bindgen::dependencies::Dependencies; use bindgen::ir::{GenericPath, OpaqueItem, Path, Struct, Type, Union}; -use bindgen::library::Library; - -#[derive(Clone, Debug)] -pub struct TemplateSpecialization { - pub generic: Struct, - pub monomorphs: Vec<(Path, Vec<Type>)>, -} - -impl TemplateSpecialization { - fn new(generic: Struct) -> TemplateSpecialization { - TemplateSpecialization { - generic: generic, - monomorphs: Vec::new(), - } - } - - pub fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { - for &(_, ref generic_values) in &self.monomorphs { - for generic_value in generic_values { - generic_value.add_dependencies(library, out); - } - } - } -} #[derive(Clone, Debug)] pub struct Monomorphs { @@ -39,7 +13,6 @@ pub struct Monomorphs { opaques: Vec<OpaqueItem>, structs: Vec<Struct>, unions: Vec<Union>, - templates: BTreeMap<Path, TemplateSpecialization>, } impl Monomorphs { @@ -49,7 +22,6 @@ impl Monomorphs { opaques: Vec::new(), structs: Vec::new(), unions: Vec::new(), - templates: BTreeMap::new(), } } @@ -61,12 +33,6 @@ impl Monomorphs { generic: &Struct, monomorph: Struct, parameters: Vec<Type>) { - // Add extra information for struct instantiations so we can use template - // specialization to make using the type more ergonomic. - self.templates.entry(generic.name.clone()) - .or_insert_with(|| TemplateSpecialization::new(generic.clone())) - .monomorphs.push((monomorph.name.clone(), parameters.clone())); - let replacement_path = GenericPath::new(generic.name.clone(), parameters); debug_assert!(generic.generic_params.len() > 0); @@ -117,22 +83,4 @@ impl Monomorphs { pub fn drain_unions(&mut self) -> Vec<Union> { mem::replace(&mut self.unions, Vec::new()) } - - pub fn drain_template_specializations(&mut self) -> Vec<TemplateSpecialization> { - let mut not_mangled = mem::replace(&mut self.templates, BTreeMap::new()); - let mut mangled = Vec::new(); - - // The generic type arguments in `templates` need to be mangled - for (_, template) in &mut not_mangled { - for &mut (_, ref mut generic_values) in &mut template.monomorphs { - for generic_value in generic_values { - generic_value.mangle_paths(&self); - } - } - - mangled.push(template.clone()); - } - - mangled - } } diff --git a/tests/rust/monomorph-1.toml b/tests/rust/monomorph-1.toml deleted file mode 100644 index 02f1ccc9dcf78cc8dab79569bb62041f2040529e..0000000000000000000000000000000000000000 --- a/tests/rust/monomorph-1.toml +++ /dev/null @@ -1,2 +0,0 @@ -[struct] -generic_template_specialization = true diff --git a/tests/rust/monomorph-3.toml b/tests/rust/monomorph-3.toml deleted file mode 100644 index 02f1ccc9dcf78cc8dab79569bb62041f2040529e..0000000000000000000000000000000000000000 --- a/tests/rust/monomorph-3.toml +++ /dev/null @@ -1,2 +0,0 @@ -[struct] -generic_template_specialization = true