Skip to content

Commit

Permalink
syntax::print -> new crate rustc_ast_pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 1, 2020
1 parent 98fd6a5 commit e233331
Show file tree
Hide file tree
Showing 62 changed files with 129 additions and 81 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock
Expand Up @@ -3093,6 +3093,7 @@ dependencies = [
"rustc-rayon",
"rustc-rayon-core",
"rustc_apfloat",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3359,6 +3360,7 @@ version = "0.0.0"
dependencies = [
"log",
"rustc",
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
Expand All @@ -3375,6 +3377,7 @@ name = "rustc_ast_passes"
version = "0.0.0"
dependencies = [
"log",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand All @@ -3385,10 +3388,21 @@ dependencies = [
"syntax",
]

[[package]]
name = "rustc_ast_pretty"
version = "0.0.0"
dependencies = [
"log",
"rustc_data_structures",
"rustc_span",
"syntax",
]

[[package]]
name = "rustc_attr"
version = "0.0.0"
dependencies = [
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand All @@ -3406,6 +3420,7 @@ version = "0.0.0"
dependencies = [
"fmt_macros",
"log",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3526,6 +3541,7 @@ dependencies = [
"lazy_static 1.4.0",
"log",
"rustc",
"rustc_ast_pretty",
"rustc_codegen_utils",
"rustc_data_structures",
"rustc_error_codes",
Expand Down Expand Up @@ -3572,6 +3588,7 @@ version = "0.0.0"
dependencies = [
"log",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3602,6 +3619,7 @@ version = "0.0.0"
name = "rustc_hir"
version = "0.0.0"
dependencies = [
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
"rustc_index",
Expand Down Expand Up @@ -3693,6 +3711,7 @@ version = "0.0.0"
dependencies = [
"log",
"rustc",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3734,6 +3753,7 @@ dependencies = [
"log",
"memmap",
"rustc",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3762,6 +3782,7 @@ dependencies = [
"polonius-engine",
"rustc",
"rustc_apfloat",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3805,6 +3826,7 @@ version = "0.0.0"
dependencies = [
"bitflags",
"log",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3872,6 +3894,7 @@ dependencies = [
"log",
"rustc",
"rustc_ast_lowering",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand All @@ -3893,6 +3916,7 @@ dependencies = [
"rls-data",
"rls-span",
"rustc",
"rustc_ast_pretty",
"rustc_codegen_utils",
"rustc_data_structures",
"rustc_hir",
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/Cargo.toml
Expand Up @@ -21,6 +21,8 @@ rustc-rayon = "0.3.0"
rustc-rayon-core = "0.3.0"
polonius-engine = "0.11.0"
rustc_apfloat = { path = "../librustc_apfloat" }
# FIXME(Centril): remove this dependency when stuff is moved to rustc_lint.
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_attr = { path = "../librustc_attr" }
rustc_feature = { path = "../librustc_feature" }
rustc_hir = { path = "../librustc_hir" }
Expand Down
1 change: 1 addition & 0 deletions src/librustc_ast_lowering/Cargo.toml
Expand Up @@ -12,6 +12,7 @@ doctest = false
[dependencies]
log = { version = "0.4", features = ["release_max_level_info", "std"] }
rustc = { path = "../librustc" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_hir = { path = "../librustc_hir" }
rustc_target = { path = "../librustc_target" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/lib.rs
Expand Up @@ -38,6 +38,7 @@ use rustc::dep_graph::DepGraph;
use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
use rustc::hir::map::Map;
use rustc::{bug, span_bug};
use rustc_ast_pretty::pprust;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
Expand All @@ -60,7 +61,6 @@ use syntax::ast;
use syntax::ast::*;
use syntax::attr;
use syntax::node_id::NodeMap;
use syntax::print::pprust;
use syntax::token::{self, Nonterminal, Token};
use syntax::tokenstream::{TokenStream, TokenTree};
use syntax::visit::{self, Visitor};
Expand Down
1 change: 1 addition & 0 deletions src/librustc_ast_passes/Cargo.toml
Expand Up @@ -10,6 +10,7 @@ path = "lib.rs"

[dependencies]
log = "0.4"
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_attr = { path = "../librustc_attr" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/ast_validation.rs
Expand Up @@ -6,6 +6,7 @@
// This pass is supposed to perform only simple checks not requiring name resolution
// or type checking or some other kind of complex analysis.

use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{struct_span_err, Applicability, FatalError};
use rustc_parse::validate_attr;
Expand All @@ -19,7 +20,6 @@ use std::mem;
use syntax::ast::*;
use syntax::attr;
use syntax::expand::is_proc_macro_attr;
use syntax::print::pprust;
use syntax::visit::{self, Visitor};
use syntax::walk_list;

Expand Down
16 changes: 16 additions & 0 deletions src/librustc_ast_pretty/Cargo.toml
@@ -0,0 +1,16 @@
[package]
authors = ["The Rust Project Developers"]
name = "rustc_ast_pretty"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_ast_pretty"
path = "lib.rs"
doctest = false

[dependencies]
log = "0.4"
rustc_span = { path = "../librustc_span" }
rustc_data_structures = { path = "../librustc_data_structures" }
syntax = { path = "../libsyntax" }
@@ -1,4 +1,4 @@
use crate::print::pp::Printer;
use crate::pp::Printer;
use std::borrow::Cow;

impl Printer {
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_ast_pretty/lib.rs
@@ -0,0 +1,6 @@
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]

mod helpers;
pub mod pp;
pub mod pprust;
File renamed without changes.
23 changes: 11 additions & 12 deletions src/libsyntax/print/pprust.rs → src/librustc_ast_pretty/pprust.rs
@@ -1,21 +1,20 @@
use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
use crate::ast::{Attribute, GenericArg, MacArgs};
use crate::ast::{GenericBound, SelfKind, TraitBoundModifier};
use crate::attr;
use crate::print::pp::Breaks::{Consistent, Inconsistent};
use crate::print::pp::{self, Breaks};
use crate::ptr::P;
use crate::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
use crate::tokenstream::{self, TokenStream, TokenTree};
use crate::util::classify;
use crate::util::comments;
use crate::util::parser::{self, AssocOp, Fixity};
use crate::pp::Breaks::{Consistent, Inconsistent};
use crate::pp::{self, Breaks};

use rustc_data_structures::sync::Once;
use rustc_span::edition::Edition;
use rustc_span::source_map::{dummy_spanned, SourceMap, Spanned};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{BytePos, FileName, Span};
use syntax::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
use syntax::ast::{Attribute, GenericArg, MacArgs};
use syntax::ast::{GenericBound, SelfKind, TraitBoundModifier};
use syntax::attr;
use syntax::ptr::P;
use syntax::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
use syntax::tokenstream::{self, TokenStream, TokenTree};
use syntax::util::parser::{self, AssocOp, Fixity};
use syntax::util::{classify, comments};

use std::borrow::Cow;

Expand Down
@@ -1,9 +1,9 @@
use super::*;

use crate::ast;
use crate::with_default_globals;
use rustc_span;
use rustc_span::source_map::{dummy_spanned, respan};
use syntax::ast;
use syntax::attr::with_default_globals;

fn fun_to_string(
decl: &ast::FnDecl,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_attr/Cargo.toml
Expand Up @@ -10,6 +10,7 @@ path = "lib.rs"
doctest = false

[dependencies]
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
rustc_errors = { path = "../librustc_errors" }
rustc_span = { path = "../librustc_span" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_attr/builtin.rs
Expand Up @@ -2,6 +2,7 @@

use super::{find_by_name, mark_used};

use rustc_ast_pretty::pprust;
use rustc_errors::{struct_span_err, Applicability, Handler};
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
use rustc_macros::HashStable_Generic;
Expand All @@ -10,7 +11,6 @@ use rustc_span::hygiene::Transparency;
use rustc_span::{symbol::sym, symbol::Symbol, Span};
use std::num::NonZeroU32;
use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem};
use syntax::print::pprust;

pub fn is_builtin_attr(attr: &Attribute) -> bool {
attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()
Expand Down
1 change: 1 addition & 0 deletions src/librustc_builtin_macros/Cargo.toml
Expand Up @@ -12,6 +12,7 @@ doctest = false
[dependencies]
fmt_macros = { path = "../libfmt_macros" }
log = "0.4"
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_attr = { path = "../librustc_attr" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/assert.rs
@@ -1,11 +1,11 @@
use rustc_errors::{Applicability, DiagnosticBuilder};

use rustc_ast_pretty::pprust;
use rustc_expand::base::*;
use rustc_parse::parser::Parser;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP};
use syntax::ast::{self, *};
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::token::{self, TokenKind};
use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/log_syntax.rs
@@ -1,14 +1,14 @@
use rustc_ast_pretty::pprust;
use rustc_expand::base;
use rustc_span;
use syntax::print;
use syntax::tokenstream::TokenStream;

pub fn expand_log_syntax<'cx>(
_cx: &'cx mut base::ExtCtxt<'_>,
sp: rustc_span::Span,
tts: TokenStream,
) -> Box<dyn base::MacResult + 'cx> {
println!("{}", print::pprust::tts_to_string(tts));
println!("{}", pprust::tts_to_string(tts));

// any so that `log_syntax` can be invoked as an expression and item.
base::DummyResult::any_valid(sp)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/proc_macro_harness.rs
@@ -1,5 +1,6 @@
use std::mem;

use rustc_ast_pretty::pprust;
use rustc_expand::base::{ExtCtxt, Resolver};
use rustc_expand::expand::{AstFragment, ExpansionConfig};
use rustc_session::parse::ParseSess;
Expand All @@ -10,7 +11,6 @@ use smallvec::smallvec;
use syntax::ast::{self, Ident};
use syntax::attr;
use syntax::expand::is_proc_macro_attr;
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::visit::{self, Visitor};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/source_util.rs
@@ -1,11 +1,11 @@
use rustc_ast_pretty::pprust;
use rustc_expand::base::{self, *};
use rustc_expand::panictry;
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser, DirectoryOwnership};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
use rustc_span::symbol::Symbol;
use rustc_span::{self, Pos, Span};
use syntax::ast;
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::token;
use syntax::tokenstream::TokenStream;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/test.rs
Expand Up @@ -2,13 +2,13 @@
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
use crate::util::check_builtin_macro_attribute;

use rustc_ast_pretty::pprust;
use rustc_expand::base::*;
use rustc_span::source_map::respan;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;
use syntax::ast;
use syntax::attr;
use syntax::print::pprust;

use std::iter;

Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/Cargo.toml
Expand Up @@ -14,6 +14,7 @@ lazy_static = "1.0"
log = "0.4"
env_logger = { version = "0.7", default-features = false }
rustc = { path = "../librustc" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_target = { path = "../librustc_target" }
rustc_lint = { path = "../librustc_lint" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_driver/pretty.rs
Expand Up @@ -5,14 +5,13 @@ use rustc::session::config::{Input, PpMode, PpSourceMode};
use rustc::session::Session;
use rustc::ty::{self, TyCtxt};
use rustc::util::common::ErrorReported;
use rustc_ast_pretty::pprust;
use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::print as pprust_hir;
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};

use rustc_span::FileName;
use syntax::ast;
use syntax::print::pprust;

use std::cell::Cell;
use std::fs::File;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_expand/Cargo.toml
Expand Up @@ -14,6 +14,7 @@ doctest = false
rustc_serialize = { path = "../libserialize", package = "serialize" }
log = "0.4"
rustc_span = { path = "../librustc_span" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_ast_passes = { path = "../librustc_ast_passes" }
rustc_attr = { path = "../librustc_attr" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down

0 comments on commit e233331

Please sign in to comment.