diff options
-rw-r--r-- | src/lib.rs | 42 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/options.rs | 9 | ||||
-rw-r--r-- | src/uses.rs | 105 |
4 files changed, 1 insertions, 159 deletions
@@ -65,7 +65,6 @@ mod clang; mod ir; mod parse; mod regex_set; -mod uses; pub mod callbacks; @@ -76,7 +75,6 @@ doc_mod!(clang, clang_docs); doc_mod!(ir, ir_docs); doc_mod!(parse, parse_docs); doc_mod!(regex_set, regex_set_docs); -doc_mod!(uses, uses_docs); mod codegen { include!(concat!(env!("OUT_DIR"), "/codegen.rs")); @@ -265,11 +263,6 @@ impl Builder { output_vector.push(prefix.clone()); } - if let Some(ref dummy) = self.options.dummy_uses { - output_vector.push("--dummy-uses".into()); - output_vector.push(dummy.clone()); - } - if self.options.emit_ast { output_vector.push("--emit-clang-ast".into()); } @@ -519,13 +512,6 @@ impl Builder { self } - /// Generate a C/C++ file that includes the header and has dummy uses of - /// every type defined in the header. - pub fn dummy_uses<T: Into<String>>(mut self, dummy_uses: T) -> Builder { - self.options.dummy_uses = Some(dummy_uses.into()); - self - } - /// Hide the given type from the generated bindings. Regular expressions are /// supported. pub fn hide_type<T: AsRef<str>>(mut self, arg: T) -> Builder { @@ -1001,10 +987,6 @@ pub struct BindgenOptions { /// Unsaved files for input. pub input_unsaved_files: Vec<clang::UnsavedFile>, - /// Generate a dummy C/C++ file that includes the header and has dummy uses - /// of all types defined therein. See the `uses` module for more. - pub dummy_uses: Option<String>, - /// A user-provided visitor to allow customizing different kinds of /// situations. pub parse_callbacks: Option<Box<callbacks::ParseCallbacks>>, @@ -1094,7 +1076,6 @@ impl Default for BindgenOptions { clang_args: vec![], input_header: None, input_unsaved_files: vec![], - dummy_uses: None, parse_callbacks: None, codegen_config: CodegenConfig::all(), conservative_inline_namespaces: false, @@ -1277,29 +1258,6 @@ impl<'ctx> Bindings<'ctx> { try!(eof(&mut ps.s)); ps.s.out.flush() } - - /// Generate and write dummy uses of all the types we parsed, if we've been - /// requested to do so in the options. - /// - /// See the `uses` module for more information. - pub fn write_dummy_uses(&mut self) -> io::Result<()> { - let file = if let Some(ref dummy_path) = - self.context.options().dummy_uses { - Some(try!(OpenOptions::new() - .write(true) - .truncate(true) - .create(true) - .open(dummy_path))) - } else { - None - }; - - if let Some(file) = file { - try!(uses::generate_dummy_uses(&mut self.context, file)); - } - - Ok(()) - } } /// Determines whether the given cursor is in any of the files matched by the diff --git a/src/main.rs b/src/main.rs index 9cd4f806..32248cb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,11 +64,9 @@ pub fn main() { std::process::exit(1); } - let mut bindings = builder_result.unwrap(); + let bindings = builder_result.unwrap(); bindings.write(output) .expect("Unable to write output"); - bindings.write_dummy_uses() - .expect("Unable to write dummy uses to file."); } Err(error) => { println!("{}", error); diff --git a/src/options.rs b/src/options.rs index 3d54eb39..f2ed5494 100644 --- a/src/options.rs +++ b/src/options.rs @@ -88,11 +88,6 @@ pub fn builder_from_flags<I> // All positional arguments after the end of options marker, `--` Arg::with_name("clang-args") .multiple(true), - Arg::with_name("dummy-uses") - .long("dummy-uses") - .help("For testing purposes, generate a C/C++ file containing \ - dummy uses of all types defined in the input header.") - .takes_value(true), Arg::with_name("emit-clang-ast") .long("emit-clang-ast") .help("Output the Clang AST for debugging purposes."), @@ -282,10 +277,6 @@ pub fn builder_from_flags<I> builder = builder.ctypes_prefix(prefix); } - if let Some(dummy) = matches.value_of("dummy-uses") { - builder = builder.dummy_uses(dummy); - } - if let Some(links) = matches.values_of("dynamic") { for library in links { builder = builder.link(library); diff --git a/src/uses.rs b/src/uses.rs deleted file mode 100644 index fc7c126e..00000000 --- a/src/uses.rs +++ /dev/null @@ -1,105 +0,0 @@ -//! Take in our IR and output a C/C++ file with dummy uses of each IR type. -//! -//! Say that we had this C++ header, `header.hpp`: -//! -//! ```c++ -//! class Point { -//! int x; -//! int y; -//! } -//! -//! enum Bar { -//! THIS, -//! THAT, -//! OTHER -//! } -//! ``` -//! -//! If we generated dummy uses for this header, we would get a `.cpp` file like -//! this: -//! -//! ```c++ -//! #include "header.hpp" -//! -//! void dummy(Point*) {} -//! void dummy(Bar*) {} -//! ``` -//! -//! This is useful because we can compile this `.cpp` file into an object file, -//! and then compare its debugging information to the debugging information -//! generated for our Rust bindings. These two sets of debugging information had -//! better agree on the C/C++ types' physical layout, or else our bindings are -//! incorrect! -//! -//! "But you still haven't explained why we have to generate the dummy uses" you -//! complain. Well if the types are never used, then they are elided when the -//! C/C++ compiler generates debugging information. - -use ir::context::BindgenContext; -use ir::item::{Item, ItemAncestors, ItemCanonicalName}; -use ir::template::TemplateParameters; -use std::io; - -// Like `canonical_path`, except we always take namespaces into account, ignore -// the generated names of anonymous items, and return a `String`. -// -// TODO: Would it be easier to try and demangle the USR? -fn namespaced_name(ctx: &BindgenContext, item: &Item) -> String { - let mut names: Vec<_> = item.ancestors(ctx) - .map(|id| ctx.resolve_item(id).canonical_name(ctx)) - .filter(|name| !name.starts_with("_bindgen_")) - .collect(); - names.reverse(); - names.join("::") -} - -/// Generate the dummy uses for all the items in the given context, and write -/// the dummy uses to `dest`. -pub fn generate_dummy_uses<W>(ctx: &mut BindgenContext, - mut dest: W) - -> io::Result<()> - where W: io::Write, -{ - ctx.gen(|ctx| { - let input_header = ctx.options() - .input_header - .as_ref() - .expect("Should not generate dummy uses without an input header"); - - try!(writeln!(dest, "/* automatically generated by rust-bindgen */")); - try!(writeln!(dest, "")); - try!(writeln!(dest, "#include \"{}\"", input_header)); - try!(writeln!(dest, "")); - - let type_items = ctx.whitelisted_items() - .iter() - .cloned() - .map(|id| ctx.resolve_item(id)) - .filter(|item| { - // We only want type items. - if let Some(ty) = item.kind().as_type() { - // However, we don't want anonymous types, as we can't - // generate dummy uses for them. - ty.name().is_some() && - // Nor do we want builtin types or named template type - // arguments. Again, we can't generate dummy uses for - // these. - !ty.is_builtin_or_named() && - // And finally, we won't be creating any dummy - // instantiations, so ignore template declarations and - // instantiations. - item.all_template_params(ctx).is_none() - } else { - false - } - }) - .map(|item| namespaced_name(ctx, item)) - .enumerate(); - - for (idx, name) in type_items { - try!(writeln!(dest, "void dummy{}({}*) {{ }}", idx, name)); - } - - Ok(()) - }) -} |