Remove obsolete template specialization

This commit is contained in:
Ingvar Stepanyan
2017-11-15 22:50:13 +00:00
committed by Ryan Hunt
parent 8fddc5d0a9
commit 4ee1a8bcc8
8 changed files with 4 additions and 120 deletions
-2
View File
@@ -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
+2 -38
View File
@@ -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);
-6
View File
@@ -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;
-3
View File
@@ -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,
+2 -15
View File
@@ -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();
}
}
-52
View File
@@ -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
}
}
-2
View File
@@ -1,2 +0,0 @@
[struct]
generic_template_specialization = true
-2
View File
@@ -1,2 +0,0 @@
[struct]
generic_template_specialization = true