1fad3a1d3Sopenharmony_ciextern crate rustc_ast; 2fad3a1d3Sopenharmony_ciextern crate rustc_driver; 3fad3a1d3Sopenharmony_ciextern crate rustc_expand; 4fad3a1d3Sopenharmony_ciextern crate rustc_parse as parse; 5fad3a1d3Sopenharmony_ciextern crate rustc_session; 6fad3a1d3Sopenharmony_ciextern crate rustc_span; 7fad3a1d3Sopenharmony_ci 8fad3a1d3Sopenharmony_ciuse rustc_ast::ast; 9fad3a1d3Sopenharmony_ciuse rustc_ast::ptr::P; 10fad3a1d3Sopenharmony_ciuse rustc_session::parse::ParseSess; 11fad3a1d3Sopenharmony_ciuse rustc_span::source_map::FilePathMapping; 12fad3a1d3Sopenharmony_ciuse rustc_span::FileName; 13fad3a1d3Sopenharmony_ciuse std::panic; 14fad3a1d3Sopenharmony_ci 15fad3a1d3Sopenharmony_cipub fn librustc_expr(input: &str) -> Option<P<ast::Expr>> { 16fad3a1d3Sopenharmony_ci match panic::catch_unwind(|| { 17fad3a1d3Sopenharmony_ci let locale_resources = rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(); 18fad3a1d3Sopenharmony_ci let file_path_mapping = FilePathMapping::empty(); 19fad3a1d3Sopenharmony_ci let sess = ParseSess::new(locale_resources, file_path_mapping); 20fad3a1d3Sopenharmony_ci let e = parse::new_parser_from_source_str( 21fad3a1d3Sopenharmony_ci &sess, 22fad3a1d3Sopenharmony_ci FileName::Custom("test_precedence".to_string()), 23fad3a1d3Sopenharmony_ci input.to_string(), 24fad3a1d3Sopenharmony_ci ) 25fad3a1d3Sopenharmony_ci .parse_expr(); 26fad3a1d3Sopenharmony_ci match e { 27fad3a1d3Sopenharmony_ci Ok(expr) => Some(expr), 28fad3a1d3Sopenharmony_ci Err(mut diagnostic) => { 29fad3a1d3Sopenharmony_ci diagnostic.emit(); 30fad3a1d3Sopenharmony_ci None 31fad3a1d3Sopenharmony_ci } 32fad3a1d3Sopenharmony_ci } 33fad3a1d3Sopenharmony_ci }) { 34fad3a1d3Sopenharmony_ci Ok(Some(e)) => Some(e), 35fad3a1d3Sopenharmony_ci Ok(None) => None, 36fad3a1d3Sopenharmony_ci Err(_) => { 37fad3a1d3Sopenharmony_ci errorf!("librustc panicked\n"); 38fad3a1d3Sopenharmony_ci None 39fad3a1d3Sopenharmony_ci } 40fad3a1d3Sopenharmony_ci } 41fad3a1d3Sopenharmony_ci} 42fad3a1d3Sopenharmony_ci 43fad3a1d3Sopenharmony_cipub fn syn_expr(input: &str) -> Option<syn::Expr> { 44fad3a1d3Sopenharmony_ci match syn::parse_str(input) { 45fad3a1d3Sopenharmony_ci Ok(e) => Some(e), 46fad3a1d3Sopenharmony_ci Err(msg) => { 47fad3a1d3Sopenharmony_ci errorf!("syn failed to parse\n{:?}\n", msg); 48fad3a1d3Sopenharmony_ci None 49fad3a1d3Sopenharmony_ci } 50fad3a1d3Sopenharmony_ci } 51fad3a1d3Sopenharmony_ci} 52