Skip to content

Commit

Permalink
ConditionWrite for Condition
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Aug 12, 2024
1 parent 3939d81 commit 56b0e19
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/bindgen/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,33 +328,43 @@ pub trait ConditionWrite {
fn write_after<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>);
}

impl ConditionWrite for Condition {
fn write_before<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>) {
if config.language == Language::Cython {
out.write("IF ");
self.write(config, out);
out.open_brace();
} else {
out.push_set_spaces(0);
out.write("#if ");
self.write(config, out);
out.pop_set_spaces();
out.new_line();
}
}

fn write_after<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>) {
if config.language == Language::Cython {
out.close_brace(false);
} else {
out.new_line();
out.push_set_spaces(0);
out.write("#endif");
out.pop_set_spaces();
}
}
}

impl ConditionWrite for Option<Condition> {
fn write_before<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>) {
if let Some(ref cfg) = *self {
if config.language == Language::Cython {
out.write("IF ");
cfg.write(config, out);
out.open_brace();
} else {
out.push_set_spaces(0);
out.write("#if ");
cfg.write(config, out);
out.pop_set_spaces();
out.new_line();
}
if let Some(cfg) = self {
cfg.write_before(config, out)
}
}

fn write_after<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>) {
if self.is_some() {
if config.language == Language::Cython {
out.close_brace(false);
} else {
out.new_line();
out.push_set_spaces(0);
out.write("#endif");
out.pop_set_spaces();
}
if let Some(cfg) = self {
cfg.write_after(config, out);
}
}
}

0 comments on commit 56b0e19

Please sign in to comment.