mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2025-02-16 06:28:41 +00:00
Merge pull request #246 from dtolnay/pragma
#pragma once needs to be above includes
This commit is contained in:
commit
a05bb4ecd4
@ -127,9 +127,6 @@ impl Display for Includes {
|
||||
writeln!(f, "#include <BaseTsd.h>")?;
|
||||
writeln!(f, "#endif")?;
|
||||
}
|
||||
if *self != Self::default() {
|
||||
writeln!(f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -51,16 +51,15 @@ impl OutFile {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepend(&mut self, section: String) {
|
||||
let content = self.content.get_mut();
|
||||
content.bytes.splice(..0, section.into_bytes());
|
||||
}
|
||||
|
||||
pub fn write_fmt(&self, args: Arguments) {
|
||||
let content = &mut *self.content.borrow_mut();
|
||||
Write::write_fmt(content, args).unwrap();
|
||||
}
|
||||
|
||||
pub fn extend(&self, other: &Self) {
|
||||
self.content.borrow_mut().write_bytes(&other.content.borrow().bytes);
|
||||
}
|
||||
|
||||
pub fn content(&self) -> Vec<u8> {
|
||||
self.content.borrow().bytes.clone()
|
||||
}
|
||||
@ -68,7 +67,14 @@ impl OutFile {
|
||||
|
||||
impl Write for Content {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
if !s.is_empty() {
|
||||
self.write_bytes(s.as_bytes());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Content {
|
||||
fn write_bytes(&mut self, b: &[u8]) {
|
||||
if !b.is_empty() {
|
||||
if !self.blocks_pending.is_empty() {
|
||||
if !self.bytes.is_empty() {
|
||||
self.bytes.push(b'\n');
|
||||
@ -84,8 +90,7 @@ impl Write for Content {
|
||||
}
|
||||
self.section_pending = false;
|
||||
}
|
||||
self.bytes.extend_from_slice(s.as_bytes());
|
||||
self.bytes.extend_from_slice(b);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,6 @@ pub(super) fn gen(
|
||||
let mut out_file = OutFile::new(namespace.clone(), header);
|
||||
let out = &mut out_file;
|
||||
|
||||
if header {
|
||||
writeln!(out, "#pragma once");
|
||||
}
|
||||
|
||||
out.include.extend(opt.include);
|
||||
for api in apis {
|
||||
if let Api::Include(include) = api {
|
||||
@ -114,9 +110,17 @@ pub(super) fn gen(
|
||||
write_generic_instantiations(out, types);
|
||||
}
|
||||
|
||||
out.prepend(out.include.to_string());
|
||||
|
||||
out_file
|
||||
// We collected necessary includes lazily while generating the above. Now
|
||||
// put it all together.
|
||||
let mut full_file = OutFile::new(namespace.clone(), header);
|
||||
let full = &mut full_file;
|
||||
if header {
|
||||
writeln!(full, "#pragma once");
|
||||
}
|
||||
write!(full, "{}", out.include);
|
||||
full.next_section();
|
||||
full.extend(out);
|
||||
full_file
|
||||
}
|
||||
|
||||
fn write_includes(out: &mut OutFile, types: &Types) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user