@@ -66,7 +66,7 @@ use pretty::{PpMode, UserIdentifiedItem};
6666use rustc_resolve as resolve;
6767use rustc_save_analysis as save;
6868use rustc_trans:: back:: link;
69- use rustc:: session:: { config, Session , build_session, CompileResult } ;
69+ use rustc:: session:: { self , config, Session , build_session, CompileResult } ;
7070use rustc:: session:: config:: { Input , PrintRequest , OutputType , ErrorOutputType } ;
7171use rustc:: session:: config:: { get_unstable_features_setting, nightly_options} ;
7272use rustc:: middle:: cstore:: CrateStore ;
@@ -91,13 +91,11 @@ use std::thread;
9191
9292use rustc:: session:: early_error;
9393
94- use syntax:: ast;
95- use syntax:: parse:: { self , PResult } ;
96- use syntax:: errors;
94+ use syntax:: { ast, errors, diagnostics} ;
95+ use syntax:: codemap:: { CodeMap , FileLoader , RealFileLoader } ;
9796use syntax:: errors:: emitter:: Emitter ;
98- use syntax:: diagnostics;
99- use syntax:: parse:: token;
10097use syntax:: feature_gate:: { GatedCfg , UnstableFeatures } ;
98+ use syntax:: parse:: { self , PResult , token} ;
10199
102100#[ cfg( test) ]
103101pub mod test;
@@ -148,11 +146,20 @@ pub fn run(args: Vec<String>) -> isize {
148146 0
149147}
150148
151- // Parse args and run the compiler. This is the primary entry point for rustc.
152- // See comments on CompilerCalls below for details about the callbacks argument.
153149pub fn run_compiler < ' a > ( args : & [ String ] ,
154150 callbacks : & mut CompilerCalls < ' a > )
155151 -> ( CompileResult , Option < Session > ) {
152+ run_compiler_with_file_loader ( args, callbacks, box RealFileLoader )
153+ }
154+
155+ // Parse args and run the compiler. This is the primary entry point for rustc.
156+ // See comments on CompilerCalls below for details about the callbacks argument.
157+ // The FileLoader provides a way to load files from sources other than the file system.
158+ pub fn run_compiler_with_file_loader < ' a , L > ( args : & [ String ] ,
159+ callbacks : & mut CompilerCalls < ' a > ,
160+ loader : Box < L > )
161+ -> ( CompileResult , Option < Session > )
162+ where L : FileLoader + ' static {
156163 macro_rules! do_or_return { ( $expr: expr, $sess: expr) => {
157164 match $expr {
158165 Compilation :: Stop => return ( Ok ( ( ) ) , $sess) ,
@@ -189,7 +196,12 @@ pub fn run_compiler<'a>(args: &[String],
189196 } ;
190197
191198 let cstore = Rc :: new ( CStore :: new ( token:: get_ident_interner ( ) ) ) ;
192- let sess = build_session ( sopts, input_file_path, descriptions, cstore. clone ( ) ) ;
199+ let codemap = Rc :: new ( CodeMap :: with_file_loader ( loader) ) ;
200+ let sess = session:: build_session_with_codemap ( sopts,
201+ input_file_path,
202+ descriptions,
203+ cstore. clone ( ) ,
204+ codemap) ;
193205 rustc_lint:: register_builtins ( & mut sess. lint_store . borrow_mut ( ) , Some ( & sess) ) ;
194206 let mut cfg = config:: build_configuration ( & sess) ;
195207 target_features:: add_configuration ( & mut cfg, & sess) ;
0 commit comments