@@ -22,14 +22,13 @@ enum pp_mode { ppm_normal, ppm_expanded, ppm_typed, ppm_identified, }
22
22
23
23
fn default_configuration ( sess : session , argv0 : str , input : str ) ->
24
24
ast:: crate_cfg {
25
- let libc =
26
- alt sess. targ_cfg . os {
27
- session:: os_win32 { "msvcrt.dll" }
28
- session:: os_macos { "libc.dylib" }
29
- session:: os_linux { "libc.so.6" }
30
- session:: os_freebsd { "libc.so.7" }
31
- _ { "libc.so" }
32
- } ;
25
+ let libc = alt sess. targ_cfg . os {
26
+ session:: os_win32 { "msvcrt.dll" }
27
+ session:: os_macos { "libc.dylib" }
28
+ session:: os_linux { "libc.so.6" }
29
+ session:: os_freebsd { "libc.so.7" }
30
+ _ { "libc.so" }
31
+ } ;
33
32
34
33
let mk = attr:: mk_name_value_item_str;
35
34
@@ -77,26 +76,13 @@ fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
77
76
fn input_is_stdin ( filename : str ) -> bool { filename == "-" }
78
77
79
78
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
+ -> @ast:: crate {
80
+ if !input_is_stdin ( input) {
83
81
parser:: parse_crate_from_file ( input, cfg, sess. parse_sess )
84
82
} else {
83
+ let src = @str:: unsafe_from_bytes ( io:: stdin ( ) . read_whole_stream ( ) ) ;
85
84
parser:: parse_crate_from_source_str ( input, src, cfg, sess. parse_sess )
86
- } ;
87
- { crate : crate , src: src}
88
- }
89
-
90
- fn get_input_str ( sess : session , infile : str ) -> @str {
91
- let stream = if !input_is_stdin ( infile) {
92
- alt io:: file_reader ( infile) {
93
- result:: ok ( reader) { reader }
94
- result:: err ( e) {
95
- sess. fatal ( e)
96
- }
97
- }
98
- } else { io:: stdin ( ) } ;
99
- @str:: unsafe_from_bytes ( stream. read_whole_stream ( ) )
85
+ }
100
86
}
101
87
102
88
fn time < T > ( do_it : bool , what : str , thunk : fn @( ) -> T ) -> T {
@@ -141,11 +127,11 @@ enum compile_upto {
141
127
fn compile_upto ( sess : session , cfg : ast:: crate_cfg ,
142
128
input : str , upto : compile_upto ,
143
129
outputs : option:: t < output_filenames > )
144
- -> { crate : @ast:: crate , tcx : option:: t < ty:: ctxt > , src : @ str } {
130
+ -> { crate : @ast:: crate , tcx : option:: t < ty:: ctxt > } {
145
131
let time_passes = sess. opts . time_passes ;
146
- let { crate , src } =
147
- time ( time_passes , "parsing" , bind parse_input ( sess, cfg, input) ) ;
148
- if upto == cu_parse { ret { crate: crate , tcx : none, src : src } ; }
132
+ let crate = time ( time_passes , "parsing" ,
133
+ bind parse_input ( sess, cfg, input) ) ;
134
+ if upto == cu_parse { ret { crate: crate , tcx : none} ; }
149
135
150
136
sess. building_library = session:: building_library (
151
137
sess. opts . crate_type , crate , sess. opts . test ) ;
@@ -160,7 +146,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
160
146
time ( time_passes, "expansion" ,
161
147
bind syntax:: ext:: expand:: expand_crate ( sess, crate ) ) ;
162
148
163
- if upto == cu_expand { ret { crate: crate , tcx : none, src : src } ; }
149
+ if upto == cu_expand { ret { crate: crate , tcx : none} ; }
164
150
if sess. opts . libcore {
165
151
crate = inject_libcore_reference ( sess, crate ) ;
166
152
}
@@ -183,7 +169,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
183
169
time ( time_passes, "typechecking" ,
184
170
bind typeck:: check_crate ( ty_cx, impl_map, crate ) ) ;
185
171
186
- if upto == cu_typeck { ret { crate: crate , tcx : some ( ty_cx) , src : src } ; }
172
+ if upto == cu_typeck { ret { crate: crate , tcx : some ( ty_cx) } ; }
187
173
188
174
time ( time_passes, "block-use checking" ,
189
175
bind middle:: block_use:: check_crate ( ty_cx, crate ) ) ;
@@ -206,7 +192,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
206
192
207
193
lint:: check_crate ( ty_cx, crate , sess. opts . lint_opts , time_passes) ;
208
194
209
- if upto == cu_no_trans { ret { crate: crate , tcx : some ( ty_cx) , src : src } ; }
195
+ if upto == cu_no_trans { ret { crate: crate , tcx : some ( ty_cx) } ; }
210
196
let outputs = option:: get ( outputs) ;
211
197
212
198
let ( llmod, link_meta) =
@@ -222,12 +208,12 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
222
208
sess. opts . output_type != link:: output_type_exe ||
223
209
sess. opts . static && sess. building_library ;
224
210
225
- if stop_after_codegen { ret { crate: crate , tcx : some ( ty_cx) , src : src } ; }
211
+ if stop_after_codegen { ret { crate: crate , tcx : some ( ty_cx) } ; }
226
212
227
213
time ( time_passes, "Linking" ,
228
214
bind link:: link_binary ( sess, outputs. obj_filename ,
229
215
outputs. out_filename , link_meta) ) ;
230
- ret { crate: crate , tcx : some ( ty_cx) , src : src } ;
216
+ ret { crate: crate , tcx : some ( ty_cx) } ;
231
217
}
232
218
233
219
fn compile_input ( sess : session , cfg : ast:: crate_cfg , input : str ,
@@ -286,7 +272,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
286
272
ppm_typed { cu_typeck }
287
273
_ { cu_parse }
288
274
} ;
289
- let { crate , tcx, src } = compile_upto ( sess, cfg, input, upto, none) ;
275
+ let { crate , tcx} = compile_upto ( sess, cfg, input, upto, none) ;
290
276
291
277
let ann: pprust:: pp_ann = pprust:: no_ann ( ) ;
292
278
alt ppm {
@@ -299,6 +285,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
299
285
}
300
286
ppm_expanded | ppm_normal { }
301
287
}
288
+ let src = codemap:: get_filemap ( sess. codemap , input) . src ;
302
289
pprust:: print_crate ( sess. codemap , sess. span_diagnostic , crate , input,
303
290
io:: string_reader ( * src) , io:: stdout ( ) , ann) ;
304
291
}
0 commit comments