8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use rustc;
12
- use rustc:: { driver, middle} ;
11
+ use rustc:: driver:: { config, driver, session} ;
13
12
use rustc:: middle:: { privacy, ty} ;
14
13
use rustc:: lint;
15
14
use rustc:: back:: link;
16
15
17
- use syntax:: ast;
16
+ use syntax:: { ast, ast_map , codemap , diagnostic } ;
18
17
use syntax:: parse:: token;
19
- use syntax;
18
+ use syntax:: ptr :: P ;
20
19
21
20
use std:: cell:: RefCell ;
22
- use std:: gc:: GC ;
23
21
use std:: os;
24
22
use std:: collections:: { HashMap , HashSet } ;
25
23
use arena:: TypedArena ;
@@ -30,15 +28,15 @@ use clean::Clean;
30
28
31
29
/// Are we generating documentation (`Typed`) or tests (`NotTyped`)?
32
30
pub enum MaybeTyped < ' tcx > {
33
- Typed ( middle :: ty:: ctxt < ' tcx > ) ,
34
- NotTyped ( driver :: session:: Session )
31
+ Typed ( ty:: ctxt < ' tcx > ) ,
32
+ NotTyped ( session:: Session )
35
33
}
36
34
37
35
pub type ExternalPaths = RefCell < Option < HashMap < ast:: DefId ,
38
36
( Vec < String > , clean:: TypeKind ) > > > ;
39
37
40
38
pub struct DocContext < ' tcx > {
41
- pub krate : ast:: Crate ,
39
+ pub krate : & ' tcx ast:: Crate ,
42
40
pub maybe_typed : MaybeTyped < ' tcx > ,
43
41
pub src : Path ,
44
42
pub external_paths : ExternalPaths ,
@@ -49,7 +47,7 @@ pub struct DocContext<'tcx> {
49
47
}
50
48
51
49
impl < ' tcx > DocContext < ' tcx > {
52
- pub fn sess < ' a > ( & ' a self ) -> & ' a driver :: session:: Session {
50
+ pub fn sess < ' a > ( & ' a self ) -> & ' a session:: Session {
53
51
match self . maybe_typed {
54
52
Typed ( ref tcx) => & tcx. sess ,
55
53
NotTyped ( ref sess) => sess
@@ -80,91 +78,82 @@ pub struct CrateAnalysis {
80
78
81
79
pub type Externs = HashMap < String , Vec < String > > ;
82
80
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 ) {
94
84
95
- let input = FileInput ( cpath. clone ( ) ) ;
85
+ // Parse, resolve, and typecheck the given crate.
86
+
87
+ let input = driver:: FileInput ( cpath. clone ( ) ) ;
96
88
97
89
let warning_lint = lint:: builtin:: WARNINGS . name_lower ( ) ;
98
90
99
- let sessopts = driver :: config:: Options {
91
+ let sessopts = config:: Options {
100
92
maybe_sysroot : Some ( os:: self_exe_path ( ) . unwrap ( ) . dir_path ( ) ) ,
101
93
addl_lib_search_paths : RefCell :: new ( libs) ,
102
- crate_types : vec ! ( driver :: config:: CrateTypeRlib ) ,
94
+ crate_types : vec ! ( config:: CrateTypeRlib ) ,
103
95
lint_opts : vec ! ( ( warning_lint, lint:: Allow ) ) ,
104
96
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 ( )
107
99
} ;
108
100
109
101
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 ) ;
112
104
let span_diagnostic_handler =
113
- syntax :: diagnostic:: mk_span_handler ( diagnostic_handler, codemap) ;
105
+ diagnostic:: mk_span_handler ( diagnostic_handler, codemap) ;
114
106
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) ;
118
110
119
- let mut cfg = build_configuration ( & sess) ;
111
+ let mut cfg = config :: build_configuration ( & sess) ;
120
112
for cfg_ in cfgs. move_iter ( ) {
121
113
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_) ) ) ) ;
123
115
}
124
116
125
- let krate = phase_1_parse_input ( & sess, cfg, & input) ;
117
+ let krate = driver :: phase_1_parse_input ( & sess, cfg, & input) ;
126
118
127
119
let name = link:: find_crate_name ( Some ( & sess) , krate. attrs . as_slice ( ) ,
128
120
& input) ;
129
121
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) ;
133
127
134
- let driver:: driver:: CrateAnalysis {
128
+ let type_arena = TypedArena :: new ( ) ;
129
+ let driver:: CrateAnalysis {
135
130
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) ;
137
132
138
- debug ! ( "crate: {:?}" , krate) ;
139
- ( DocContext {
140
- krate : krate,
133
+ let ctxt = DocContext {
134
+ krate : ty_cx. map . krate ( ) ,
141
135
maybe_typed : Typed ( ty_cx) ,
142
136
src : cpath. clone ( ) ,
143
137
external_traits : RefCell :: new ( Some ( HashMap :: new ( ) ) ) ,
144
138
external_typarams : RefCell :: new ( Some ( HashMap :: new ( ) ) ) ,
145
139
external_paths : RefCell :: new ( Some ( HashMap :: new ( ) ) ) ,
146
140
inlined : RefCell :: new ( Some ( HashSet :: new ( ) ) ) ,
147
141
populated_crate_impls : RefCell :: new ( HashSet :: new ( ) ) ,
148
- } , CrateAnalysis {
142
+ } ;
143
+ debug ! ( "crate: {:?}" , ctxt. krate) ;
144
+
145
+ let analysis = CrateAnalysis {
149
146
exported_items : exported_items,
150
147
public_items : public_items,
151
148
external_paths : RefCell :: new ( None ) ,
152
149
external_traits : RefCell :: new ( None ) ,
153
150
external_typarams : RefCell :: new ( None ) ,
154
151
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
+ } ;
164
153
165
154
let krate = {
166
155
let mut v = RustdocVisitor :: new ( & ctxt, Some ( & analysis) ) ;
167
- v. visit ( & ctxt. krate ) ;
156
+ v. visit ( ctxt. krate ) ;
168
157
v. clean ( & ctxt)
169
158
} ;
170
159
0 commit comments