88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use rustc;
12- use rustc:: { driver, middle} ;
11+ use rustc:: driver:: { config, driver, session} ;
1312use rustc:: middle:: { privacy, ty} ;
1413use rustc:: lint;
1514use rustc:: back:: link;
1615
17- use syntax:: ast;
16+ use syntax:: { ast, ast_map , codemap , diagnostic } ;
1817use syntax:: parse:: token;
19- use syntax;
18+ use syntax:: ptr :: P ;
2019
2120use std:: cell:: RefCell ;
22- use std:: gc:: GC ;
2321use std:: os;
2422use std:: collections:: { HashMap , HashSet } ;
2523use arena:: TypedArena ;
@@ -30,15 +28,15 @@ use clean::Clean;
3028
3129/// Are we generating documentation (`Typed`) or tests (`NotTyped`)?
3230pub enum MaybeTyped < ' tcx > {
33- Typed ( middle :: ty:: ctxt < ' tcx > ) ,
34- NotTyped ( driver :: session:: Session )
31+ Typed ( ty:: ctxt < ' tcx > ) ,
32+ NotTyped ( session:: Session )
3533}
3634
3735pub type ExternalPaths = RefCell < Option < HashMap < ast:: DefId ,
3836 ( Vec < String > , clean:: TypeKind ) > > > ;
3937
4038pub struct DocContext < ' tcx > {
41- pub krate : ast:: Crate ,
39+ pub krate : & ' tcx ast:: Crate ,
4240 pub maybe_typed : MaybeTyped < ' tcx > ,
4341 pub src : Path ,
4442 pub external_paths : ExternalPaths ,
@@ -49,7 +47,7 @@ pub struct DocContext<'tcx> {
4947}
5048
5149impl < ' tcx > DocContext < ' tcx > {
52- pub fn sess < ' a > ( & ' a self ) -> & ' a driver :: session:: Session {
50+ pub fn sess < ' a > ( & ' a self ) -> & ' a session:: Session {
5351 match self . maybe_typed {
5452 Typed ( ref tcx) => & tcx. sess ,
5553 NotTyped ( ref sess) => sess
@@ -80,91 +78,82 @@ pub struct CrateAnalysis {
8078
8179pub type Externs = HashMap < String , Vec < String > > ;
8280
83- /// Parses, resolves, and typechecks the given crate
84- fn get_ast_and_resolve < ' tcx > ( cpath : & Path , libs : Vec < Path > , cfgs : Vec < String > ,
85- externs : Externs , triple : Option < String > ,
86- type_arena : & ' tcx TypedArena < ty:: t_box_ > )
87- -> ( DocContext < ' tcx > , CrateAnalysis ) {
88- use syntax:: codemap:: dummy_spanned;
89- use rustc:: driver:: driver:: { FileInput ,
90- phase_1_parse_input,
91- phase_2_configure_and_expand,
92- phase_3_run_analysis_passes} ;
93- use rustc:: driver:: config:: build_configuration;
81+ pub fn run_core ( libs : Vec < Path > , cfgs : Vec < String > , externs : Externs ,
82+ cpath : & Path , triple : Option < String > )
83+ -> ( clean:: Crate , CrateAnalysis ) {
9484
95- let input = FileInput ( cpath. clone ( ) ) ;
85+ // Parse, resolve, and typecheck the given crate.
86+
87+ let input = driver:: FileInput ( cpath. clone ( ) ) ;
9688
9789 let warning_lint = lint:: builtin:: WARNINGS . name_lower ( ) ;
9890
99- let sessopts = driver :: config:: Options {
91+ let sessopts = config:: Options {
10092 maybe_sysroot : Some ( os:: self_exe_path ( ) . unwrap ( ) . dir_path ( ) ) ,
10193 addl_lib_search_paths : RefCell :: new ( libs) ,
102- crate_types : vec ! ( driver :: config:: CrateTypeRlib ) ,
94+ crate_types : vec ! ( config:: CrateTypeRlib ) ,
10395 lint_opts : vec ! ( ( warning_lint, lint:: Allow ) ) ,
10496 externs : externs,
105- target_triple : triple. unwrap_or ( driver:: driver :: host_triple ( ) . to_string ( ) ) ,
106- ..rustc :: driver :: config:: basic_options ( ) . clone ( )
97+ target_triple : triple. unwrap_or ( driver:: host_triple ( ) . to_string ( ) ) ,
98+ ..config:: basic_options ( ) . clone ( )
10799 } ;
108100
109101
110- let codemap = syntax :: codemap:: CodeMap :: new ( ) ;
111- let diagnostic_handler = syntax :: diagnostic:: default_handler ( syntax :: diagnostic:: Auto , None ) ;
102+ let codemap = codemap:: CodeMap :: new ( ) ;
103+ let diagnostic_handler = diagnostic:: default_handler ( diagnostic:: Auto , None ) ;
112104 let span_diagnostic_handler =
113- syntax :: diagnostic:: mk_span_handler ( diagnostic_handler, codemap) ;
105+ diagnostic:: mk_span_handler ( diagnostic_handler, codemap) ;
114106
115- let sess = driver :: session:: build_session_ ( sessopts,
116- Some ( cpath. clone ( ) ) ,
117- span_diagnostic_handler) ;
107+ let sess = session:: build_session_ ( sessopts,
108+ Some ( cpath. clone ( ) ) ,
109+ span_diagnostic_handler) ;
118110
119- let mut cfg = build_configuration ( & sess) ;
111+ let mut cfg = config :: build_configuration ( & sess) ;
120112 for cfg_ in cfgs. move_iter ( ) {
121113 let cfg_ = token:: intern_and_get_ident ( cfg_. as_slice ( ) ) ;
122- cfg. push ( box ( GC ) dummy_spanned ( ast:: MetaWord ( cfg_) ) ) ;
114+ cfg. push ( P ( codemap :: dummy_spanned ( ast:: MetaWord ( cfg_) ) ) ) ;
123115 }
124116
125- let krate = phase_1_parse_input ( & sess, cfg, & input) ;
117+ let krate = driver :: phase_1_parse_input ( & sess, cfg, & input) ;
126118
127119 let name = link:: find_crate_name ( Some ( & sess) , krate. attrs . as_slice ( ) ,
128120 & input) ;
129121
130- let ( krate, ast_map)
131- = phase_2_configure_and_expand ( & sess, krate, name. as_slice ( ) , None )
132- . expect ( "phase_2_configure_and_expand aborted in rustdoc!" ) ;
122+ let krate = driver:: phase_2_configure_and_expand ( & sess, krate, name. as_slice ( ) , None )
123+ . expect ( "phase_2_configure_and_expand aborted in rustdoc!" ) ;
124+
125+ let mut forest = ast_map:: Forest :: new ( krate) ;
126+ let ast_map = driver:: assign_node_ids_and_map ( & sess, & mut forest) ;
133127
134- let driver:: driver:: CrateAnalysis {
128+ let type_arena = TypedArena :: new ( ) ;
129+ let driver:: CrateAnalysis {
135130 exported_items, public_items, ty_cx, ..
136- } = phase_3_run_analysis_passes ( sess, & krate , ast_map, type_arena, name) ;
131+ } = driver :: phase_3_run_analysis_passes ( sess, ast_map, & type_arena, name) ;
137132
138- debug ! ( "crate: {:?}" , krate) ;
139- ( DocContext {
140- krate : krate,
133+ let ctxt = DocContext {
134+ krate : ty_cx. map . krate ( ) ,
141135 maybe_typed : Typed ( ty_cx) ,
142136 src : cpath. clone ( ) ,
143137 external_traits : RefCell :: new ( Some ( HashMap :: new ( ) ) ) ,
144138 external_typarams : RefCell :: new ( Some ( HashMap :: new ( ) ) ) ,
145139 external_paths : RefCell :: new ( Some ( HashMap :: new ( ) ) ) ,
146140 inlined : RefCell :: new ( Some ( HashSet :: new ( ) ) ) ,
147141 populated_crate_impls : RefCell :: new ( HashSet :: new ( ) ) ,
148- } , CrateAnalysis {
142+ } ;
143+ debug ! ( "crate: {:?}" , ctxt. krate) ;
144+
145+ let analysis = CrateAnalysis {
149146 exported_items : exported_items,
150147 public_items : public_items,
151148 external_paths : RefCell :: new ( None ) ,
152149 external_traits : RefCell :: new ( None ) ,
153150 external_typarams : RefCell :: new ( None ) ,
154151 inlined : RefCell :: new ( None ) ,
155- } )
156- }
157-
158- pub fn run_core ( libs : Vec < Path > , cfgs : Vec < String > , externs : Externs ,
159- path : & Path , triple : Option < String > )
160- -> ( clean:: Crate , CrateAnalysis ) {
161- let type_arena = TypedArena :: new ( ) ;
162- let ( ctxt, analysis) = get_ast_and_resolve ( path, libs, cfgs, externs,
163- triple, & type_arena) ;
152+ } ;
164153
165154 let krate = {
166155 let mut v = RustdocVisitor :: new ( & ctxt, Some ( & analysis) ) ;
167- v. visit ( & ctxt. krate ) ;
156+ v. visit ( ctxt. krate ) ;
168157 v. clean ( & ctxt)
169158 } ;
170159
0 commit comments