Skip to content

parser: Disable conditionally class constants #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bin/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ fn parse_args(args: &[String]) -> ParseResult {
options.gen_bitfield_methods = false;
ix += 1;
}
"-no-class-constants" => {
options.class_constants = false;
ix += 1;
}
"-dtor-attr" => {
if ix + 1 >= args_len {
return ParseResult::ParseErr("Missing dtor attr".to_string());
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ impl<'a> Builder<'a> {
self
}

pub fn disable_class_constants(&mut self) -> &mut Self {
self.options.class_constants = false;
self
}

pub fn generate(&self) -> Result<Bindings, ()> {
Bindings::generate(&self.options, self.logger, None)
}
Expand Down Expand Up @@ -152,6 +157,8 @@ pub struct BindgenOptions {
pub enable_cxx_namespaces: bool,
pub rename_types: bool,
pub derive_debug: bool,
/// Wether to generate C++ class constants.
pub class_constants: bool,
pub override_enum_ty: String,
pub raw_lines: Vec<String>,
/// Attributes for a type with destructor
Expand All @@ -176,6 +183,7 @@ impl Default for BindgenOptions {
derive_debug: true,
enable_cxx_namespaces: false,
override_enum_ty: "".to_string(),
class_constants: true,
raw_lines: vec![],
dtor_attrs: vec![],
clang_args: vec![],
Expand Down Expand Up @@ -295,6 +303,7 @@ fn parse_headers(options: &BindgenOptions, logger: &Logger) -> Result<ModuleMap,
builtins: options.builtins,
match_pat: options.match_pat.clone(),
emit_ast: options.emit_ast,
class_constants: options.class_constants,
ignore_functions: options.ignore_functions,
fail_on_unknown_type: options.fail_on_unknown_type,
enable_cxx_namespaces: options.enable_cxx_namespaces,
Expand Down
5 changes: 5 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct ClangParserOptions {
pub fail_on_unknown_type: bool,
pub ignore_functions: bool,
pub enable_cxx_namespaces: bool,
pub class_constants: bool,
pub override_enum_ty: Option<il::IKind>,
pub clang_args: Vec<String>,
pub opaque_types: Vec<String>,
Expand Down Expand Up @@ -990,6 +991,10 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
ci.has_non_type_template_params = true;
}
CXCursor_VarDecl => {
if !ctx.options.class_constants {
return CXChildVisit_Continue;
}

let linkage = cursor.linkage();
if linkage != CXLinkage_External && linkage != CXLinkage_UniqueExternal {
return CXChildVisit_Continue;
Expand Down