diff options
| author | Bryanskiy <ivakin.kir@gmail.com> | 2024-09-30 21:07:36 +0300 |
|---|---|---|
| committer | Bryanskiy <ivakin.kir@gmail.com> | 2025-05-04 22:03:15 +0300 |
| commit | 14535312b522c0524dd94633cc6a49992b12cecd (patch) | |
| tree | f397262aa2e597623ac7dc9a721da0360398808d /compiler/rustc_ast_pretty/src/pprust/state.rs | |
| parent | 62c5f58f57670ce65e7fec34f8c4ba00c27da2d9 (diff) | |
| download | rust-14535312b522c0524dd94633cc6a49992b12cecd.tar.gz rust-14535312b522c0524dd94633cc6a49992b12cecd.zip | |
Initial support for dynamically linked crates
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust/state.rs')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 28d5eb87c27..0990c9b27eb 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -221,6 +221,7 @@ pub struct State<'a> { pub s: pp::Printer, comments: Option<Comments<'a>>, ann: &'a (dyn PpAnn + 'a), + is_sdylib_interface: bool, } const INDENT_UNIT: isize = 4; @@ -237,9 +238,36 @@ pub fn print_crate<'a>( edition: Edition, g: &AttrIdGenerator, ) -> String { + let mut s = State { + s: pp::Printer::new(), + comments: Some(Comments::new(sm, filename, input)), + ann, + is_sdylib_interface: false, + }; + + print_crate_inner(&mut s, krate, is_expanded, edition, g); + s.s.eof() +} + +pub fn print_crate_as_interface( + krate: &ast::Crate, + edition: Edition, + g: &AttrIdGenerator, +) -> String { let mut s = - State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann }; + State { s: pp::Printer::new(), comments: None, ann: &NoAnn, is_sdylib_interface: true }; + print_crate_inner(&mut s, krate, false, edition, g); + s.s.eof() +} + +fn print_crate_inner<'a>( + s: &mut State<'a>, + krate: &ast::Crate, + is_expanded: bool, + edition: Edition, + g: &AttrIdGenerator, +) { // We need to print shebang before anything else // otherwise the resulting code will not compile // and shebang will be useless. @@ -282,8 +310,7 @@ pub fn print_crate<'a>( s.print_item(item); } s.print_remaining_comments(); - s.ann.post(&mut s, AnnNode::Crate(krate)); - s.s.eof() + s.ann.post(s, AnnNode::Crate(krate)); } /// Should two consecutive tokens be printed with a space between them? @@ -1111,7 +1138,7 @@ impl<'a> PrintState<'a> for State<'a> { impl<'a> State<'a> { pub fn new() -> State<'a> { - State { s: pp::Printer::new(), comments: None, ann: &NoAnn } + State { s: pp::Printer::new(), comments: None, ann: &NoAnn, is_sdylib_interface: false } } fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G) |
