/// Parse a rust file, and generate the corresponding C++ code
Parse a rust file, and generate the corresponding C++ code
Parse a rust file and generate the corresponding C ++ code
pub fn generate(src: &std::path::Path) -> Codegen {
        let result : Arc<Mutex<Option<Codegen>>> = Arc::new(Mutex::new(None));
        let result_ = result.clone();
        let src = src.to_owned();
        rustc_driver::monitor(move || {
            let sess = parse::ParseSess::new();
            let krate = match parse::parse_crate_from_file(&src, Vec::new(), &sess) {
                Ok(krate) => krate,
                Err(mut err) => {
                    err.emit();
                    sess.span_diagnostic.abort_if_errors();
                    unreachable!();
                }
            };
            let cfg = expand::ExpansionConfig::default("foo".to_string());
            let mut resolver = DummyResolver;
            let ecx = ExtCtxt::new(&sess, Vec::new(), cfg, &mut resolver);
            let mut visitor = CodegenVisitor::new(&ecx);
            visit::walk_crate(&mut visitor, &krate);
            let code = visitor.code();
            let deps = sess.codemap().files.borrow().iter()
                .filter(|fmap| fmap.is_real_file())
                .filter(|fmap| !fmap.is_imported())
                .map(|fmap| fmap.name.clone())
                .collect();
            *result.lock().expect("lock poisoned") = Some(Codegen {
                code: code,
                deps: deps,
            });
            sess.span_diagnostic.abort_if_errors();
        });
        let value = result_.lock().expect("lock poisoned")
                           .take().expect("missing result");
        value
    }
pub fn generate ( src : & std :: path :: Path ) -> Codegen { let result : Arc < Mutex < Option < Codegen > > > = Arc :: new ( Mutex :: new ( None ) ) ; let result_ = result . clone ( ) ; let src = src . to_owned ( ) ; rustc_driver :: monitor ( move | | { let sess = parse :: ParseSess :: new ( ) ; let krate = match parse :: parse_crate_from_file ( & src , Vec :: new ( ) , & sess ) { Ok ( krate ) => krate , Err ( mut err ) => { err . emit ( ) ; sess . span_diagnostic . abort_if_errors ( ) ; unreachable ! ( ) ; } } ; let cfg = expand :: ExpansionConfig :: default ( " " . to_string ( ) ) ; let mut resolver = DummyResolver ; let ecx = ExtCtxt :: new ( & sess , Vec :: new ( ) , cfg , & mut resolver ) ; let mut visitor = CodegenVisitor :: new ( & ecx ) ; visit :: walk_crate ( & mut visitor , & krate ) ; let code = visitor . code ( ) ; let deps = sess . codemap ( ) . files . borrow ( ) . iter ( ) . filter ( | fmap | fmap . is_real_file ( ) ) . filter ( | fmap | ! fmap . is_imported ( ) ) . map ( | fmap | fmap . name . clone ( ) ) . collect ( ) ; * result . lock ( ) . expect ( " " ) = Some ( Codegen { code : code , deps : deps , } ) ; sess . span_diagnostic . abort_if_errors ( ) ; } ) ; let value = result_ . lock ( ) . expect ( " " ) . take ( ) . expect ( " " ) ; value }
Parse a rust file, and generate the corresponding C++ code
Parse a rust file and generate the corresponding C ++ code
src
&std::path::Path