@@ -20,7 +20,7 @@ import back::{x86, x86_64};
20
20
21
21
tag pp_mode { ppm_normal; ppm_expanded; ppm_typed; ppm_identified; }
22
22
23
- fn default_configuration ( sess : session , argv0 : str , input : str ) ->
23
+ fn default_configuration ( sess : session:: session , argv0 : str , input : str ) ->
24
24
ast:: crate_cfg {
25
25
let libc =
26
26
alt sess. targ_cfg . os {
@@ -48,7 +48,7 @@ fn default_configuration(sess: session, argv0: str, input: str) ->
48
48
mk ( "build_input" , input) ] ;
49
49
}
50
50
51
- fn build_configuration ( sess : session , argv0 : str , input : str ) ->
51
+ fn build_configuration ( sess : session:: session , argv0 : str , input : str ) ->
52
52
ast:: crate_cfg {
53
53
// Combine the configuration requested by the session (command line) with
54
54
// some default and generated configuration items
@@ -76,27 +76,31 @@ fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
76
76
77
77
fn input_is_stdin ( filename : str ) -> bool { filename == "-" }
78
78
79
- fn parse_input ( sess : session , cfg : ast:: crate_cfg , input : str )
80
- -> { crate : @ast:: crate , src : str } {
81
- let src = get_input_str ( sess, input) ;
82
- let crate = if !input_is_stdin ( input) {
79
+ fn parse_input ( sess : session:: session , cfg : ast:: crate_cfg , input : str ) ->
80
+ @ast:: crate {
81
+ if !input_is_stdin ( input) {
83
82
parser:: parse_crate_from_file ( input, cfg, sess. parse_sess )
84
- } else {
85
- parser:: parse_crate_from_source_str ( input, src, cfg, sess. parse_sess )
86
- } ;
87
- { crate : crate , src: src}
83
+ } else { parse_input_src ( sess, cfg, input) . crate }
88
84
}
89
85
90
- fn get_input_str ( sess : session , infile : str ) -> str {
91
- let stream = if !input_is_stdin ( infile) {
86
+ fn parse_input_src ( sess : session:: session , cfg : ast:: crate_cfg , infile : str )
87
+ -> { crate : @ast:: crate , src : str } {
88
+ let src_stream = if infile != "-" {
92
89
alt io:: file_reader ( infile) {
93
90
result:: ok ( reader) { reader }
94
91
result:: err ( e) {
95
92
sess. fatal ( e)
96
93
}
97
94
}
98
- } else { io:: stdin ( ) } ;
99
- str:: unsafe_from_bytes ( stream. read_whole_stream ( ) )
95
+ } else {
96
+ io:: stdin ( )
97
+ } ;
98
+ let srcbytes = src_stream. read_whole_stream ( ) ;
99
+ let src = str:: unsafe_from_bytes ( srcbytes) ;
100
+ let crate =
101
+ parser:: parse_crate_from_source_str ( infile, src, cfg,
102
+ sess. parse_sess ) ;
103
+ ret { crate: crate , src : src} ;
100
104
}
101
105
102
106
fn time < T > ( do_it : bool , what : str , thunk : fn @( ) -> T ) -> T {
@@ -109,7 +113,7 @@ fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
109
113
ret rv;
110
114
}
111
115
112
- fn inject_libcore_reference ( sess : session ,
116
+ fn inject_libcore_reference ( sess : session:: session ,
113
117
crate : @ast:: crate ) -> @ast:: crate {
114
118
115
119
fn spanned < T : copy > ( x : T ) -> @ast:: spanned < T > {
@@ -130,22 +134,14 @@ fn inject_libcore_reference(sess: session,
130
134
with crate . node } with * crate }
131
135
}
132
136
133
- enum compile_upto {
134
- cu_parse;
135
- cu_expand;
136
- cu_typeck;
137
- cu_no_trans;
138
- cu_everything;
139
- }
140
137
141
- fn compile_upto ( sess : session , cfg : ast:: crate_cfg ,
142
- input : str , upto : compile_upto ,
143
- outputs : option:: t < output_filenames > )
144
- -> { crate : @ast:: crate , tcx : option:: t < ty:: ctxt > , src : str } {
138
+ fn compile_input ( sess : session:: session , cfg : ast:: crate_cfg , input : str ,
139
+ outdir : option:: t < str > , output : option:: t < str > ) {
140
+
145
141
let time_passes = sess. opts . time_passes ;
146
- let { crate , src } =
142
+ let crate =
147
143
time ( time_passes, "parsing" , bind parse_input ( sess, cfg, input) ) ;
148
- if upto == cu_parse { ret { crate : crate , tcx : none , src : src } ; }
144
+ if sess . opts . parse_only { ret; }
149
145
150
146
sess. building_library =
151
147
session:: building_library ( sess. opts . crate_type , crate ) ;
@@ -160,7 +156,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
160
156
time ( time_passes, "expansion" ,
161
157
bind syntax:: ext:: expand:: expand_crate ( sess, crate ) ) ;
162
158
163
- if upto == cu_expand { ret { crate: crate , tcx : none, src : src} ; }
164
159
if sess. opts . libcore {
165
160
crate = inject_libcore_reference ( sess, crate ) ;
166
161
}
@@ -182,9 +177,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
182
177
let ( method_map, dict_map) =
183
178
time ( time_passes, "typechecking" ,
184
179
bind typeck:: check_crate ( ty_cx, impl_map, crate ) ) ;
185
-
186
- if upto == cu_typeck { ret { crate: crate , tcx : some ( ty_cx) , src : src} ; }
187
-
188
180
time ( time_passes, "block-use checking" ,
189
181
bind middle:: block_use:: check_crate ( ty_cx, crate ) ) ;
190
182
time ( time_passes, "function usage" ,
@@ -203,9 +195,9 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
203
195
bind last_use:: find_last_uses ( crate , def_map, ref_map, ty_cx) ) ;
204
196
time ( time_passes, "kind checking" ,
205
197
bind kind:: check_crate ( ty_cx, method_map, last_uses, crate ) ) ;
198
+ if sess. opts . no_trans { ret; }
206
199
207
- if upto == cu_no_trans { ret { crate: crate , tcx : some ( ty_cx) , src : src} ; }
208
- let outputs = option:: get ( outputs) ;
200
+ let outputs = build_output_filenames ( input, outdir, output, sess) ;
209
201
210
202
let ( llmod, link_meta) =
211
203
time ( time_passes, "translation" ,
@@ -220,25 +212,14 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
220
212
sess. opts . output_type != link:: output_type_exe ||
221
213
sess. opts . static && sess. building_library ;
222
214
223
- if stop_after_codegen { ret { crate : crate , tcx : some ( ty_cx ) , src : src } ; }
215
+ if stop_after_codegen { ret; }
224
216
225
217
time ( time_passes, "Linking" ,
226
218
bind link:: link_binary ( sess, outputs. obj_filename ,
227
219
outputs. out_filename , link_meta) ) ;
228
- ret { crate: crate , tcx : some ( ty_cx) , src : src} ;
229
220
}
230
221
231
- fn compile_input ( sess : session , cfg : ast:: crate_cfg , input : str ,
232
- outdir : option:: t < str > , output : option:: t < str > ) {
233
-
234
- let upto = if sess. opts . parse_only { cu_parse }
235
- else if sess. opts . no_trans { cu_no_trans }
236
- else { cu_everything } ;
237
- let outputs = build_output_filenames ( input, outdir, output, sess) ;
238
- compile_upto ( sess, cfg, input, upto, some ( outputs) ) ;
239
- }
240
-
241
- fn pretty_print_input ( sess : session , cfg : ast:: crate_cfg , input : str ,
222
+ fn pretty_print_input ( sess : session:: session , cfg : ast:: crate_cfg , input : str ,
242
223
ppm : pp_mode ) {
243
224
fn ann_paren_for_expr ( node : pprust:: ann_node ) {
244
225
alt node { pprust : : node_expr ( s, expr) { pprust:: popen ( s) ; } _ { } }
@@ -279,23 +260,30 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
279
260
// to collect comments and literals, and we need to support reading
280
261
// from stdin, we're going to just suck the source into a string
281
262
// so both the parser and pretty-printer can use it.
282
- let upto = alt ppm {
283
- ppm_expanded. { cu_expand }
284
- ppm_typed. { cu_typeck }
285
- _ { cu_parse }
286
- } ;
287
- let { crate , tcx, src} = compile_upto ( sess, cfg, input, upto, none) ;
263
+ let crate_src = parse_input_src ( sess, cfg, input) ;
264
+ let crate = crate_src. crate ;
265
+ let src = crate_src. src ;
288
266
289
- let ann: pprust :: pp_ann = pprust :: no_ann ( ) ;
267
+ let ann;
290
268
alt ppm {
269
+ ppm_expanded. {
270
+ crate = syntax:: ext:: expand:: expand_crate ( sess, crate ) ;
271
+ ann = pprust:: no_ann ( ) ;
272
+ }
291
273
ppm_typed. {
292
- ann = { pre : ann_paren_for_expr,
293
- post : bind ann_typed_post ( option:: get ( tcx) , _) } ;
274
+ crate = syntax:: ext:: expand:: expand_crate ( sess, crate ) ;
275
+ let amap = middle:: ast_map:: map_crate ( * crate ) ;
276
+ let { def_map, impl_map, _} =
277
+ resolve:: resolve_crate ( sess, amap, crate ) ;
278
+ let freevars = freevars:: annotate_freevars ( def_map, crate ) ;
279
+ let ty_cx = ty:: mk_ctxt ( sess, def_map, amap, freevars) ;
280
+ typeck:: check_crate ( ty_cx, impl_map, crate ) ;
281
+ ann = { pre: ann_paren_for_expr, post: bind ann_typed_post ( ty_cx, _) } ;
294
282
}
295
283
ppm_identified. {
296
284
ann = { pre: ann_paren_for_expr, post: ann_identified_post} ;
297
285
}
298
- ppm_expanded . | ppm_normal . { }
286
+ ppm_normal. { ann = pprust :: no_ann ( ) ; }
299
287
}
300
288
pprust:: print_crate ( sess. codemap , sess. diagnostic , crate , input,
301
289
io:: string_reader ( src) , io:: stdout ( ) , ann) ;
@@ -465,7 +453,7 @@ fn build_session_options(match: getopts::match,
465
453
}
466
454
467
455
fn build_session ( sopts : @session:: options , input : str ,
468
- demitter : diagnostic:: emitter ) -> session {
456
+ demitter : diagnostic:: emitter ) -> session:: session {
469
457
let target_cfg = build_target_config ( sopts, demitter) ;
470
458
let cstore = cstore:: mk_cstore ( ) ;
471
459
let filesearch = filesearch:: mk_filesearch (
@@ -492,7 +480,7 @@ fn build_session(sopts: @session::options, input: str,
492
480
working_dir: fs:: dirname ( input) }
493
481
}
494
482
495
- fn parse_pretty ( sess : session , & & name: str ) -> pp_mode {
483
+ fn parse_pretty ( sess : session:: session , & & name: str ) -> pp_mode {
496
484
if str:: eq ( name, "normal" ) {
497
485
ret ppm_normal;
498
486
} else if str:: eq ( name, "expanded" ) {
@@ -521,13 +509,11 @@ fn opts() -> [getopts::opt] {
521
509
optflag ( "warn-unused-imports" ) ] ;
522
510
}
523
511
524
- type output_filenames = @{ out_filename : str , obj_filename : str } ;
525
-
526
512
fn build_output_filenames ( ifile : str ,
527
513
odir : option:: t < str > ,
528
514
ofile : option:: t < str > ,
529
- sess : session )
530
- -> output_filenames {
515
+ sess : session:: session )
516
+ -> @ { out_filename : str , obj_filename : str } {
531
517
let obj_path = "" ;
532
518
let out_path: str = "" ;
533
519
let sopts = sess. opts ;
@@ -613,7 +599,7 @@ fn early_error(emitter: diagnostic::emitter, msg: str) -> ! {
613
599
fail;
614
600
}
615
601
616
- fn list_metadata ( sess : session , path : str , out : io:: writer ) {
602
+ fn list_metadata ( sess : session:: session , path : str , out : io:: writer ) {
617
603
metadata:: creader:: list_file_metadata ( sess, path, out) ;
618
604
}
619
605
0 commit comments