Auto merge of #37431 - jseyfried:refactor_crate_config, r=eddyb
Move `CrateConfig` from `Crate` to `ParseSess` This is a syntax-[breaking-change]. Most breakage can be fixed by removing a `CrateConfig` argument. r? @eddyb
This commit is contained in:
commit
6062e7ed3d
39 changed files with 130 additions and 298 deletions
|
@ -136,10 +136,8 @@ impl FromStr for TokenStream {
|
|||
fn from_str(src: &str) -> Result<TokenStream, LexError> {
|
||||
__internal::with_parse_sess(|sess| {
|
||||
let src = src.to_string();
|
||||
let cfg = Vec::new();
|
||||
let name = "<proc-macro source code>".to_string();
|
||||
let mut parser = parse::new_parser_from_source_str(sess, cfg, name,
|
||||
src);
|
||||
let mut parser = parse::new_parser_from_source_str(sess, name, src);
|
||||
let mut ret = TokenStream { inner: Vec::new() };
|
||||
loop {
|
||||
match parser.parse_item() {
|
||||
|
|
|
@ -124,7 +124,6 @@ impl<'a> LoweringContext<'a> {
|
|||
hir::Crate {
|
||||
module: self.lower_mod(&c.module),
|
||||
attrs: self.lower_attrs(&c.attrs),
|
||||
config: c.config.clone().into(),
|
||||
span: c.span,
|
||||
exported_macros: c.exported_macros.iter().map(|m| self.lower_macro_def(m)).collect(),
|
||||
items: items,
|
||||
|
|
|
@ -413,7 +413,6 @@ pub type CrateConfig = HirVec<P<MetaItem>>;
|
|||
pub struct Crate {
|
||||
pub module: Mod,
|
||||
pub attrs: HirVec<Attribute>,
|
||||
pub config: CrateConfig,
|
||||
pub span: Span,
|
||||
pub exported_macros: HirVec<MacroDef>,
|
||||
|
||||
|
|
|
@ -1237,10 +1237,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
|||
pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
|
||||
cfgspecs.into_iter().map(|s| {
|
||||
let sess = parse::ParseSess::new();
|
||||
let mut parser = parse::new_parser_from_source_str(&sess,
|
||||
Vec::new(),
|
||||
"cfgspec".to_string(),
|
||||
s.to_string());
|
||||
let mut parser =
|
||||
parse::new_parser_from_source_str(&sess, "cfgspec".to_string(), s.to_string());
|
||||
|
||||
let meta_item = panictry!(parser.parse_meta_item());
|
||||
|
||||
if !parser.reader.is_eof() {
|
||||
|
|
|
@ -67,7 +67,6 @@ pub struct Resolutions {
|
|||
|
||||
pub fn compile_input(sess: &Session,
|
||||
cstore: &CStore,
|
||||
cfg: ast::CrateConfig,
|
||||
input: &Input,
|
||||
outdir: &Option<PathBuf>,
|
||||
output: &Option<PathBuf>,
|
||||
|
@ -91,7 +90,7 @@ pub fn compile_input(sess: &Session,
|
|||
// large chunks of memory alive and we want to free them as soon as
|
||||
// possible to keep the peak memory usage low
|
||||
let (outputs, trans) = {
|
||||
let krate = match phase_1_parse_input(sess, cfg, input) {
|
||||
let krate = match phase_1_parse_input(sess, input) {
|
||||
Ok(krate) => krate,
|
||||
Err(mut parse_error) => {
|
||||
parse_error.emit();
|
||||
|
@ -482,23 +481,17 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn phase_1_parse_input<'a>(sess: &'a Session,
|
||||
cfg: ast::CrateConfig,
|
||||
input: &Input)
|
||||
-> PResult<'a, ast::Crate> {
|
||||
pub fn phase_1_parse_input<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
|
||||
let continue_after_error = sess.opts.debugging_opts.continue_parse_after_error;
|
||||
sess.diagnostic().set_continue_after_error(continue_after_error);
|
||||
|
||||
let krate = time(sess.time_passes(), "parsing", || {
|
||||
match *input {
|
||||
Input::File(ref file) => {
|
||||
parse::parse_crate_from_file(file, cfg.clone(), &sess.parse_sess)
|
||||
parse::parse_crate_from_file(file, &sess.parse_sess)
|
||||
}
|
||||
Input::Str { ref input, ref name } => {
|
||||
parse::parse_crate_from_source_str(name.clone(),
|
||||
input.clone(),
|
||||
cfg.clone(),
|
||||
&sess.parse_sess)
|
||||
parse::parse_crate_from_source_str(name.clone(), input.clone(), &sess.parse_sess)
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
@ -636,7 +629,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
|
|||
// its contents but the results of name resolution on those contents. Hopefully we'll push
|
||||
// this back at some point.
|
||||
let _ignore = sess.dep_graph.in_ignore();
|
||||
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name, krate.config.clone());
|
||||
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name);
|
||||
crate_loader.preprocess(&krate);
|
||||
let resolver_arenas = Resolver::arenas();
|
||||
let mut resolver =
|
||||
|
@ -677,7 +670,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
|
|||
should_test: sess.opts.test,
|
||||
..syntax::ext::expand::ExpansionConfig::default(crate_name.to_string())
|
||||
};
|
||||
let mut ecx = ExtCtxt::new(&sess.parse_sess, krate.config.clone(), cfg, &mut resolver);
|
||||
let mut ecx = ExtCtxt::new(&sess.parse_sess, cfg, &mut resolver);
|
||||
let err_count = ecx.parse_sess.span_diagnostic.err_count();
|
||||
|
||||
let krate = ecx.monotonic_expander().expand_crate(krate);
|
||||
|
|
|
@ -205,24 +205,20 @@ pub fn run_compiler<'a>(args: &[String],
|
|||
|
||||
let loader = file_loader.unwrap_or(box RealFileLoader);
|
||||
let codemap = Rc::new(CodeMap::with_file_loader(loader));
|
||||
let sess = session::build_session_with_codemap(sopts,
|
||||
&dep_graph,
|
||||
input_file_path,
|
||||
descriptions,
|
||||
cstore.clone(),
|
||||
codemap,
|
||||
emitter_dest);
|
||||
let mut sess = session::build_session_with_codemap(
|
||||
sopts, &dep_graph, input_file_path, descriptions, cstore.clone(), codemap, emitter_dest,
|
||||
);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
|
||||
let mut cfg = config::build_configuration(&sess, cfg);
|
||||
target_features::add_configuration(&mut cfg, &sess);
|
||||
sess.parse_sess.config = cfg;
|
||||
|
||||
do_or_return!(callbacks.late_callback(&matches, &sess, &cfg, &input, &odir, &ofile),
|
||||
Some(sess));
|
||||
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess));
|
||||
|
||||
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
|
||||
let control = callbacks.build_controller(&sess, &matches);
|
||||
(driver::compile_input(&sess, &cstore, cfg, &input, &odir, &ofile,
|
||||
Some(plugins), &control),
|
||||
(driver::compile_input(&sess, &cstore, &input, &odir, &ofile, Some(plugins), &control),
|
||||
Some(sess))
|
||||
}
|
||||
|
||||
|
@ -310,7 +306,6 @@ pub trait CompilerCalls<'a> {
|
|||
fn late_callback(&mut self,
|
||||
_: &getopts::Matches,
|
||||
_: &Session,
|
||||
_: &ast::CrateConfig,
|
||||
_: &Input,
|
||||
_: &Option<PathBuf>,
|
||||
_: &Option<PathBuf>)
|
||||
|
@ -439,7 +434,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
}
|
||||
let dep_graph = DepGraph::new(sopts.build_dep_graph());
|
||||
let cstore = Rc::new(CStore::new(&dep_graph));
|
||||
let sess = build_session(sopts.clone(),
|
||||
let mut sess = build_session(sopts.clone(),
|
||||
&dep_graph,
|
||||
None,
|
||||
descriptions.clone(),
|
||||
|
@ -447,11 +442,10 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let mut cfg = config::build_configuration(&sess, cfg.clone());
|
||||
target_features::add_configuration(&mut cfg, &sess);
|
||||
let should_stop = RustcDefaultCalls::print_crate_info(&sess,
|
||||
&cfg,
|
||||
None,
|
||||
odir,
|
||||
ofile);
|
||||
sess.parse_sess.config = cfg;
|
||||
let should_stop =
|
||||
RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
|
||||
|
||||
if should_stop == Compilation::Stop {
|
||||
return None;
|
||||
}
|
||||
|
@ -467,12 +461,11 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
fn late_callback(&mut self,
|
||||
matches: &getopts::Matches,
|
||||
sess: &Session,
|
||||
cfg: &ast::CrateConfig,
|
||||
input: &Input,
|
||||
odir: &Option<PathBuf>,
|
||||
ofile: &Option<PathBuf>)
|
||||
-> Compilation {
|
||||
RustcDefaultCalls::print_crate_info(sess, cfg, Some(input), odir, ofile)
|
||||
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile)
|
||||
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input))
|
||||
}
|
||||
|
||||
|
@ -593,7 +586,6 @@ impl RustcDefaultCalls {
|
|||
|
||||
|
||||
fn print_crate_info(sess: &Session,
|
||||
cfg: &ast::CrateConfig,
|
||||
input: Option<&Input>,
|
||||
odir: &Option<PathBuf>,
|
||||
ofile: &Option<PathBuf>)
|
||||
|
@ -649,8 +641,8 @@ impl RustcDefaultCalls {
|
|||
let allow_unstable_cfg = UnstableFeatures::from_environment()
|
||||
.is_nightly_build();
|
||||
|
||||
for cfg in cfg {
|
||||
if !allow_unstable_cfg && GatedCfg::gate(&*cfg).is_some() {
|
||||
for cfg in &sess.parse_sess.config {
|
||||
if !allow_unstable_cfg && GatedCfg::gate(cfg).is_some() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1036,13 +1028,10 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
|
|||
fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<ast::Attribute>> {
|
||||
match *input {
|
||||
Input::File(ref ifile) => {
|
||||
parse::parse_crate_attrs_from_file(ifile, Vec::new(), &sess.parse_sess)
|
||||
parse::parse_crate_attrs_from_file(ifile, &sess.parse_sess)
|
||||
}
|
||||
Input::Str { ref name, ref input } => {
|
||||
parse::parse_crate_attrs_from_source_str(name.clone(),
|
||||
input.clone(),
|
||||
Vec::new(),
|
||||
&sess.parse_sess)
|
||||
parse::parse_crate_attrs_from_source_str(name.clone(), input.clone(), &sess.parse_sess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,12 +106,11 @@ fn test_env<F>(source_string: &str,
|
|||
let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler,
|
||||
Rc::new(CodeMap::new()), cstore.clone());
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let krate_config = Vec::new();
|
||||
let input = config::Input::Str {
|
||||
name: driver::anon_src(),
|
||||
input: source_string.to_string(),
|
||||
};
|
||||
let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap();
|
||||
let krate = driver::phase_1_parse_input(&sess, &input).unwrap();
|
||||
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
|
||||
driver::phase_2_configure_and_expand(
|
||||
&sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()),
|
||||
|
|
|
@ -264,7 +264,7 @@ impl<'a, 'tcx, 'm> DirtyCleanMetadataVisitor<'a, 'tcx, 'm> {
|
|||
/// flag called `foo`.
|
||||
fn check_config(tcx: TyCtxt, attr: &ast::Attribute) -> bool {
|
||||
debug!("check_config(attr={:?})", attr);
|
||||
let config = &tcx.map.krate().config;
|
||||
let config = &tcx.sess.parse_sess.config;
|
||||
debug!("check_config: config={:?}", config);
|
||||
for item in attr.meta_item_list().unwrap_or(&[]) {
|
||||
if item.check_name(CFG) {
|
||||
|
|
|
@ -52,7 +52,6 @@ pub struct CrateLoader<'a> {
|
|||
next_crate_num: CrateNum,
|
||||
foreign_item_map: FnvHashMap<String, Vec<ast::NodeId>>,
|
||||
local_crate_name: String,
|
||||
local_crate_config: ast::CrateConfig,
|
||||
}
|
||||
|
||||
fn dump_crates(cstore: &CStore) {
|
||||
|
@ -144,18 +143,13 @@ enum LoadResult {
|
|||
}
|
||||
|
||||
impl<'a> CrateLoader<'a> {
|
||||
pub fn new(sess: &'a Session,
|
||||
cstore: &'a CStore,
|
||||
local_crate_name: &str,
|
||||
local_crate_config: ast::CrateConfig)
|
||||
-> Self {
|
||||
pub fn new(sess: &'a Session, cstore: &'a CStore, local_crate_name: &str) -> Self {
|
||||
CrateLoader {
|
||||
sess: sess,
|
||||
cstore: cstore,
|
||||
next_crate_num: cstore.next_crate_num(),
|
||||
foreign_item_map: FnvHashMap(),
|
||||
local_crate_name: local_crate_name.to_owned(),
|
||||
local_crate_config: local_crate_config,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -541,7 +535,6 @@ impl<'a> CrateLoader<'a> {
|
|||
// NB: Don't use parse::parse_tts_from_source_str because it parses with
|
||||
// quote_depth > 0.
|
||||
let mut p = parse::new_parser_from_source_str(&self.sess.parse_sess,
|
||||
self.local_crate_config.clone(),
|
||||
source_name.clone(),
|
||||
def.body);
|
||||
let lo = p.span.lo;
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn load_plugins(sess: &Session,
|
|||
krate: &ast::Crate,
|
||||
crate_name: &str,
|
||||
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrar> {
|
||||
let mut loader = PluginLoader::new(sess, cstore, crate_name, krate.config.clone());
|
||||
let mut loader = PluginLoader::new(sess, cstore, crate_name);
|
||||
|
||||
// do not report any error now. since crate attributes are
|
||||
// not touched by expansion, every use of plugin without
|
||||
|
@ -89,14 +89,10 @@ pub fn load_plugins(sess: &Session,
|
|||
}
|
||||
|
||||
impl<'a> PluginLoader<'a> {
|
||||
fn new(sess: &'a Session,
|
||||
cstore: &'a CStore,
|
||||
crate_name: &str,
|
||||
crate_config: ast::CrateConfig)
|
||||
-> PluginLoader<'a> {
|
||||
fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> Self {
|
||||
PluginLoader {
|
||||
sess: sess,
|
||||
reader: CrateLoader::new(sess, cstore, crate_name, crate_config),
|
||||
reader: CrateLoader::new(sess, cstore, crate_name),
|
||||
plugins: vec![],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> {
|
|||
/// Scan for a `cfg="foo"` attribute and check whether we have a
|
||||
/// cfg flag called `foo`.
|
||||
fn check_config(&self, attr: &ast::Attribute) -> bool {
|
||||
let config = &self.tcx.map.krate().config;
|
||||
let config = &self.tcx.sess.parse_sess.config;
|
||||
let value = self.field(attr, CFG);
|
||||
debug!("check_config(config={:?}, value={:?})", config, value);
|
||||
if config.iter().any(|c| c.check_name(&value[..])) {
|
||||
|
|
|
@ -163,14 +163,16 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
let dep_graph = DepGraph::new(false);
|
||||
let _ignore = dep_graph.in_ignore();
|
||||
let cstore = Rc::new(CStore::new(&dep_graph));
|
||||
let sess = session::build_session_(sessopts, &dep_graph, cpath, diagnostic_handler,
|
||||
codemap, cstore.clone());
|
||||
let mut sess = session::build_session_(
|
||||
sessopts, &dep_graph, cpath, diagnostic_handler, codemap, cstore.clone()
|
||||
);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
|
||||
let mut cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs));
|
||||
target_features::add_configuration(&mut cfg, &sess);
|
||||
sess.parse_sess.config = cfg;
|
||||
|
||||
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
|
||||
let krate = panictry!(driver::phase_1_parse_input(&sess, &input));
|
||||
|
||||
let name = link::find_crate_name(Some(&sess), &krate.attrs, &input);
|
||||
|
||||
|
|
|
@ -73,24 +73,20 @@ pub fn run(input: &str,
|
|||
};
|
||||
|
||||
let codemap = Rc::new(CodeMap::new());
|
||||
let diagnostic_handler = errors::Handler::with_tty_emitter(ColorConfig::Auto,
|
||||
true,
|
||||
false,
|
||||
Some(codemap.clone()));
|
||||
let handler =
|
||||
errors::Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(codemap.clone()));
|
||||
|
||||
let dep_graph = DepGraph::new(false);
|
||||
let _ignore = dep_graph.in_ignore();
|
||||
let cstore = Rc::new(CStore::new(&dep_graph));
|
||||
let sess = session::build_session_(sessopts,
|
||||
&dep_graph,
|
||||
Some(input_path.clone()),
|
||||
diagnostic_handler,
|
||||
codemap,
|
||||
cstore.clone());
|
||||
let mut sess = session::build_session_(
|
||||
sessopts, &dep_graph, Some(input_path.clone()), handler, codemap, cstore.clone(),
|
||||
);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
sess.parse_sess.config =
|
||||
config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
|
||||
|
||||
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
|
||||
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
|
||||
let krate = panictry!(driver::phase_1_parse_input(&sess, &input));
|
||||
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
|
||||
phase_2_configure_and_expand(
|
||||
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
|
||||
|
@ -236,18 +232,16 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
|||
|
||||
let dep_graph = DepGraph::new(false);
|
||||
let cstore = Rc::new(CStore::new(&dep_graph));
|
||||
let sess = session::build_session_(sessopts,
|
||||
&dep_graph,
|
||||
None,
|
||||
diagnostic_handler,
|
||||
codemap,
|
||||
cstore.clone());
|
||||
let mut sess = session::build_session_(
|
||||
sessopts, &dep_graph, None, diagnostic_handler, codemap, cstore.clone(),
|
||||
);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
|
||||
let outdir = Mutex::new(TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir"));
|
||||
let libdir = sess.target_filesearch(PathKind::All).get_lib_path();
|
||||
let mut control = driver::CompileController::basic();
|
||||
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
|
||||
sess.parse_sess.config =
|
||||
config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
|
||||
let out = Some(outdir.lock().unwrap().path().to_path_buf());
|
||||
|
||||
if no_run {
|
||||
|
@ -255,9 +249,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
|||
}
|
||||
|
||||
let res = panic::catch_unwind(AssertUnwindSafe(|| {
|
||||
driver::compile_input(&sess, &cstore, cfg.clone(),
|
||||
&input, &out,
|
||||
&None, None, &control)
|
||||
driver::compile_input(&sess, &cstore, &input, &out, &None, None, &control)
|
||||
}));
|
||||
|
||||
match res {
|
||||
|
|
|
@ -477,7 +477,6 @@ pub type CrateConfig = Vec<P<MetaItem>>;
|
|||
pub struct Crate {
|
||||
pub module: Mod,
|
||||
pub attrs: Vec<Attribute>,
|
||||
pub config: CrateConfig,
|
||||
pub span: Span,
|
||||
pub exported_macros: Vec<MacroDef>,
|
||||
}
|
||||
|
|
|
@ -501,10 +501,7 @@ pub fn requests_inline(attrs: &[Attribute]) -> bool {
|
|||
}
|
||||
|
||||
/// Tests if a cfg-pattern matches the cfg set
|
||||
pub fn cfg_matches(cfgs: &[P<MetaItem>], cfg: &ast::MetaItem,
|
||||
sess: &ParseSess,
|
||||
features: Option<&Features>)
|
||||
-> bool {
|
||||
pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) -> bool {
|
||||
match cfg.node {
|
||||
ast::MetaItemKind::List(ref pred, ref mis) => {
|
||||
for mi in mis.iter() {
|
||||
|
@ -518,10 +515,10 @@ pub fn cfg_matches(cfgs: &[P<MetaItem>], cfg: &ast::MetaItem,
|
|||
// that they won't fail with the loop above.
|
||||
match &pred[..] {
|
||||
"any" => mis.iter().any(|mi| {
|
||||
cfg_matches(cfgs, mi.meta_item().unwrap(), sess, features)
|
||||
cfg_matches(mi.meta_item().unwrap(), sess, features)
|
||||
}),
|
||||
"all" => mis.iter().all(|mi| {
|
||||
cfg_matches(cfgs, mi.meta_item().unwrap(), sess, features)
|
||||
cfg_matches(mi.meta_item().unwrap(), sess, features)
|
||||
}),
|
||||
"not" => {
|
||||
if mis.len() != 1 {
|
||||
|
@ -529,7 +526,7 @@ pub fn cfg_matches(cfgs: &[P<MetaItem>], cfg: &ast::MetaItem,
|
|||
return false;
|
||||
}
|
||||
|
||||
!cfg_matches(cfgs, mis[0].meta_item().unwrap(), sess, features)
|
||||
!cfg_matches(mis[0].meta_item().unwrap(), sess, features)
|
||||
},
|
||||
p => {
|
||||
span_err!(sess.span_diagnostic, cfg.span, E0537, "invalid predicate `{}`", p);
|
||||
|
@ -541,7 +538,7 @@ pub fn cfg_matches(cfgs: &[P<MetaItem>], cfg: &ast::MetaItem,
|
|||
if let (Some(feats), Some(gated_cfg)) = (features, GatedCfg::gate(cfg)) {
|
||||
gated_cfg.check_and_emit(sess, feats);
|
||||
}
|
||||
contains(cfgs, cfg)
|
||||
contains(&sess.config, cfg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ use util::small_vector::SmallVector;
|
|||
|
||||
/// A folder that strips out items that do not belong in the current configuration.
|
||||
pub struct StripUnconfigured<'a> {
|
||||
pub config: &'a ast::CrateConfig,
|
||||
pub should_test: bool,
|
||||
pub sess: &'a ParseSess,
|
||||
pub features: Option<&'a Features>,
|
||||
|
@ -32,7 +31,6 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool)
|
|||
let features;
|
||||
{
|
||||
let mut strip_unconfigured = StripUnconfigured {
|
||||
config: &krate.config.clone(),
|
||||
should_test: should_test,
|
||||
sess: sess,
|
||||
features: None,
|
||||
|
@ -107,7 +105,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||
use attr::cfg_matches;
|
||||
match (cfg.meta_item(), mi.meta_item()) {
|
||||
(Some(cfg), Some(mi)) =>
|
||||
if cfg_matches(self.config, &cfg, self.sess, self.features) {
|
||||
if cfg_matches(&cfg, self.sess, self.features) {
|
||||
self.process_cfg_attr(respan(mi.span, ast::Attribute_ {
|
||||
id: attr::mk_attr_id(),
|
||||
style: attr.node.style,
|
||||
|
@ -148,7 +146,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||
return true;
|
||||
}
|
||||
|
||||
attr::cfg_matches(self.config, mis[0].meta_item().unwrap(), self.sess, self.features)
|
||||
attr::cfg_matches(mis[0].meta_item().unwrap(), self.sess, self.features)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -574,7 +574,6 @@ pub struct ExpansionData {
|
|||
/// -> expn_info of their expansion context stored into their span.
|
||||
pub struct ExtCtxt<'a> {
|
||||
pub parse_sess: &'a parse::ParseSess,
|
||||
pub cfg: ast::CrateConfig,
|
||||
pub ecfg: expand::ExpansionConfig<'a>,
|
||||
pub crate_root: Option<&'static str>,
|
||||
pub resolver: &'a mut Resolver,
|
||||
|
@ -583,13 +582,12 @@ pub struct ExtCtxt<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ExtCtxt<'a> {
|
||||
pub fn new(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig,
|
||||
pub fn new(parse_sess: &'a parse::ParseSess,
|
||||
ecfg: expand::ExpansionConfig<'a>,
|
||||
resolver: &'a mut Resolver)
|
||||
-> ExtCtxt<'a> {
|
||||
ExtCtxt {
|
||||
parse_sess: parse_sess,
|
||||
cfg: cfg,
|
||||
ecfg: ecfg,
|
||||
crate_root: None,
|
||||
resolver: resolver,
|
||||
|
@ -617,11 +615,11 @@ impl<'a> ExtCtxt<'a> {
|
|||
|
||||
pub fn new_parser_from_tts(&self, tts: &[tokenstream::TokenTree])
|
||||
-> parser::Parser<'a> {
|
||||
parse::tts_to_parser(self.parse_sess, tts.to_vec(), self.cfg().clone())
|
||||
parse::tts_to_parser(self.parse_sess, tts.to_vec())
|
||||
}
|
||||
pub fn codemap(&self) -> &'a CodeMap { self.parse_sess.codemap() }
|
||||
pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess }
|
||||
pub fn cfg(&self) -> &ast::CrateConfig { &self.cfg }
|
||||
pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config }
|
||||
pub fn call_site(&self) -> Span {
|
||||
self.codemap().with_expn_info(self.backtrace(), |ei| match ei {
|
||||
Some(expn_info) => expn_info.call_site,
|
||||
|
|
|
@ -293,11 +293,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
}
|
||||
|
||||
fn collect_invocations(&mut self, expansion: Expansion) -> (Expansion, Vec<Invocation>) {
|
||||
let crate_config = mem::replace(&mut self.cx.cfg, Vec::new());
|
||||
let result = {
|
||||
let mut collector = InvocationCollector {
|
||||
cfg: StripUnconfigured {
|
||||
config: &crate_config,
|
||||
should_test: self.cx.ecfg.should_test,
|
||||
sess: self.cx.parse_sess,
|
||||
features: self.cx.ecfg.features,
|
||||
|
@ -308,7 +306,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
};
|
||||
(expansion.fold_with(&mut collector), collector.invocations)
|
||||
};
|
||||
self.cx.cfg = crate_config;
|
||||
|
||||
if self.monotonic {
|
||||
let err_count = self.cx.parse_sess.span_diagnostic.err_count();
|
||||
|
@ -646,7 +643,7 @@ fn string_to_tts(text: String, parse_sess: &ParseSess) -> Vec<TokenTree> {
|
|||
.new_filemap(String::from("<macro expansion>"), None, text);
|
||||
|
||||
let lexer = lexer::StringReader::new(&parse_sess.span_diagnostic, filemap);
|
||||
let mut parser = Parser::new(parse_sess, Vec::new(), Box::new(lexer));
|
||||
let mut parser = Parser::new(parse_sess, Box::new(lexer));
|
||||
panictry!(parser.parse_all_token_trees())
|
||||
}
|
||||
|
||||
|
|
|
@ -331,7 +331,6 @@ pub mod rt {
|
|||
panictry!(parse::parse_item_from_source_str(
|
||||
"<quote expansion>".to_string(),
|
||||
s,
|
||||
self.cfg().clone(),
|
||||
self.parse_sess())).expect("parse error")
|
||||
}
|
||||
|
||||
|
@ -339,7 +338,6 @@ pub mod rt {
|
|||
panictry!(parse::parse_stmt_from_source_str(
|
||||
"<quote expansion>".to_string(),
|
||||
s,
|
||||
self.cfg().clone(),
|
||||
self.parse_sess())).expect("parse error")
|
||||
}
|
||||
|
||||
|
@ -347,7 +345,6 @@ pub mod rt {
|
|||
panictry!(parse::parse_expr_from_source_str(
|
||||
"<quote expansion>".to_string(),
|
||||
s,
|
||||
self.cfg().clone(),
|
||||
self.parse_sess()))
|
||||
}
|
||||
|
||||
|
@ -355,7 +352,6 @@ pub mod rt {
|
|||
panictry!(parse::parse_tts_from_source_str(
|
||||
"<quote expansion>".to_string(),
|
||||
s,
|
||||
self.cfg().clone(),
|
||||
self.parse_sess()))
|
||||
}
|
||||
}
|
||||
|
@ -920,14 +916,6 @@ fn expand_parse_call(cx: &ExtCtxt,
|
|||
tts: &[TokenTree]) -> P<ast::Expr> {
|
||||
let (cx_expr, tts_expr) = expand_tts(cx, sp, tts);
|
||||
|
||||
let cfg_call = || cx.expr_method_call(
|
||||
sp, cx.expr_ident(sp, id_ext("ext_cx")),
|
||||
id_ext("cfg"), Vec::new());
|
||||
|
||||
let cfg_clone_call = || cx.expr_method_call(
|
||||
sp, cfg_call(),
|
||||
id_ext("clone"), Vec::new());
|
||||
|
||||
let parse_sess_call = || cx.expr_method_call(
|
||||
sp, cx.expr_ident(sp, id_ext("ext_cx")),
|
||||
id_ext("parse_sess"), Vec::new());
|
||||
|
@ -935,7 +923,7 @@ fn expand_parse_call(cx: &ExtCtxt,
|
|||
let new_parser_call =
|
||||
cx.expr_call(sp,
|
||||
cx.expr_ident(sp, id_ext("new_parser_from_tts")),
|
||||
vec!(parse_sess_call(), cfg_clone_call(), tts_expr));
|
||||
vec!(parse_sess_call(), tts_expr));
|
||||
|
||||
let path = vec![id_ext("syntax"), id_ext("ext"), id_ext("quote"), id_ext(parse_method)];
|
||||
let mut args = vec![cx.expr_mut_addr_of(sp, new_parser_call)];
|
||||
|
|
|
@ -92,15 +92,8 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T
|
|||
None => return DummyResult::expr(sp),
|
||||
};
|
||||
// The file will be added to the code map by the parser
|
||||
let p =
|
||||
parse::new_sub_parser_from_file(cx.parse_sess(),
|
||||
cx.cfg().clone(),
|
||||
&res_rel_file(cx,
|
||||
sp,
|
||||
Path::new(&file)),
|
||||
true,
|
||||
None,
|
||||
sp);
|
||||
let path = res_rel_file(cx, sp, Path::new(&file));
|
||||
let p = parse::new_sub_parser_from_file(cx.parse_sess(), &path, true, None, sp);
|
||||
|
||||
struct ExpandResult<'a> {
|
||||
p: parse::parser::Parser<'a>,
|
||||
|
|
|
@ -78,7 +78,6 @@ pub use self::NamedMatch::*;
|
|||
pub use self::ParseResult::*;
|
||||
use self::TokenTreeOrTokenTreeVec::*;
|
||||
|
||||
use ast;
|
||||
use ast::Ident;
|
||||
use syntax_pos::{self, BytePos, mk_sp, Span};
|
||||
use codemap::Spanned;
|
||||
|
@ -280,11 +279,7 @@ pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(sess: &ParseSess,
|
||||
cfg: &ast::CrateConfig,
|
||||
mut rdr: TtReader,
|
||||
ms: &[TokenTree])
|
||||
-> NamedParseResult {
|
||||
pub fn parse(sess: &ParseSess, mut rdr: TtReader, ms: &[TokenTree]) -> NamedParseResult {
|
||||
let mut cur_eis = SmallVector::one(initial_matcher_pos(ms.to_owned(),
|
||||
None,
|
||||
rdr.peek().sp.lo));
|
||||
|
@ -482,7 +477,7 @@ pub fn parse(sess: &ParseSess,
|
|||
rdr.next_token();
|
||||
} else /* bb_eis.len() == 1 */ {
|
||||
rdr.next_tok = {
|
||||
let mut rust_parser = Parser::new(sess, cfg.clone(), Box::new(&mut rdr));
|
||||
let mut rust_parser = Parser::new(sess, Box::new(&mut rdr));
|
||||
let mut ei = bb_eis.pop().unwrap();
|
||||
if let TokenTree::Token(span, MatchNt(_, ident)) = ei.top_elts.get_tt(ei.idx) {
|
||||
let match_cur = ei.match_cur;
|
||||
|
|
|
@ -115,7 +115,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
|
|||
// rhs has holes ( `$id` and `$(...)` that need filled)
|
||||
let trncbr =
|
||||
new_tt_reader(&cx.parse_sess.span_diagnostic, Some(named_matches), rhs);
|
||||
let mut p = Parser::new(cx.parse_sess(), cx.cfg().clone(), Box::new(trncbr));
|
||||
let mut p = Parser::new(cx.parse_sess(), Box::new(trncbr));
|
||||
p.directory = cx.current_expansion.module.directory.clone();
|
||||
p.restrictions = match cx.current_expansion.no_noninline_mod {
|
||||
true => Restrictions::NO_NONINLINE_MOD,
|
||||
|
@ -220,7 +220,7 @@ pub fn compile(sess: &ParseSess, def: &ast::MacroDef) -> SyntaxExtension {
|
|||
// Parse the macro_rules! invocation (`none` is for no interpolations):
|
||||
let arg_reader = new_tt_reader(&sess.span_diagnostic, None, def.body.clone());
|
||||
|
||||
let argument_map = match parse(sess, &Vec::new(), arg_reader, &argument_gram) {
|
||||
let argument_map = match parse(sess, arg_reader, &argument_gram) {
|
||||
Success(m) => m,
|
||||
Failure(sp, tok) => {
|
||||
let s = parse_failure_msg(tok);
|
||||
|
|
|
@ -972,10 +972,8 @@ pub fn noop_fold_mod<T: Folder>(Mod {inner, items}: Mod, folder: &mut T) -> Mod
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_macros, span}: Crate,
|
||||
pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, mut exported_macros, span}: Crate,
|
||||
folder: &mut T) -> Crate {
|
||||
let config = folder.fold_meta_items(config);
|
||||
|
||||
let mut items = folder.fold_item(P(ast::Item {
|
||||
ident: keywords::Invalid.ident(),
|
||||
attrs: attrs,
|
||||
|
@ -1009,7 +1007,6 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_mac
|
|||
Crate {
|
||||
module: module,
|
||||
attrs: attrs,
|
||||
config: config,
|
||||
exported_macros: exported_macros,
|
||||
span: span,
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
//! The main parser interface
|
||||
|
||||
use ast;
|
||||
use ast::{self, CrateConfig};
|
||||
use codemap::CodeMap;
|
||||
use syntax_pos::{self, Span, FileMap};
|
||||
use errors::{Handler, ColorConfig, DiagnosticBuilder};
|
||||
|
@ -44,13 +44,14 @@ pub mod obsolete;
|
|||
pub struct ParseSess {
|
||||
pub span_diagnostic: Handler, // better be the same as the one in the reader!
|
||||
pub unstable_features: UnstableFeatures,
|
||||
pub config: CrateConfig,
|
||||
/// Used to determine and report recursive mod inclusions
|
||||
included_mod_stack: RefCell<Vec<PathBuf>>,
|
||||
code_map: Rc<CodeMap>,
|
||||
}
|
||||
|
||||
impl ParseSess {
|
||||
pub fn new() -> ParseSess {
|
||||
pub fn new() -> Self {
|
||||
let cm = Rc::new(CodeMap::new());
|
||||
let handler = Handler::with_tty_emitter(ColorConfig::Auto,
|
||||
true,
|
||||
|
@ -63,6 +64,7 @@ impl ParseSess {
|
|||
ParseSess {
|
||||
span_diagnostic: handler,
|
||||
unstable_features: UnstableFeatures::from_environment(),
|
||||
config: Vec::new(),
|
||||
included_mod_stack: RefCell::new(vec![]),
|
||||
code_map: code_map
|
||||
}
|
||||
|
@ -78,146 +80,90 @@ impl ParseSess {
|
|||
// uses a HOF to parse anything, and <source> includes file and
|
||||
// source_str.
|
||||
|
||||
pub fn parse_crate_from_file<'a>(input: &Path,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
-> PResult<'a, ast::Crate> {
|
||||
let mut parser = new_parser_from_file(sess, cfg, input);
|
||||
pub fn parse_crate_from_file<'a>(input: &Path, sess: &'a ParseSess) -> PResult<'a, ast::Crate> {
|
||||
let mut parser = new_parser_from_file(sess, input);
|
||||
parser.parse_crate_mod()
|
||||
}
|
||||
|
||||
pub fn parse_crate_attrs_from_file<'a>(input: &Path,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_crate_attrs_from_file<'a>(input: &Path, sess: &'a ParseSess)
|
||||
-> PResult<'a, Vec<ast::Attribute>> {
|
||||
let mut parser = new_parser_from_file(sess, cfg, input);
|
||||
let mut parser = new_parser_from_file(sess, input);
|
||||
parser.parse_inner_attributes()
|
||||
}
|
||||
|
||||
pub fn parse_crate_from_source_str<'a>(name: String,
|
||||
source: String,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_crate_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
|
||||
-> PResult<'a, ast::Crate> {
|
||||
let mut p = new_parser_from_source_str(sess,
|
||||
cfg,
|
||||
name,
|
||||
source);
|
||||
p.parse_crate_mod()
|
||||
new_parser_from_source_str(sess, name, source).parse_crate_mod()
|
||||
}
|
||||
|
||||
pub fn parse_crate_attrs_from_source_str<'a>(name: String,
|
||||
source: String,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_crate_attrs_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
|
||||
-> PResult<'a, Vec<ast::Attribute>> {
|
||||
let mut p = new_parser_from_source_str(sess,
|
||||
cfg,
|
||||
name,
|
||||
source);
|
||||
p.parse_inner_attributes()
|
||||
new_parser_from_source_str(sess, name, source).parse_inner_attributes()
|
||||
}
|
||||
|
||||
pub fn parse_expr_from_source_str<'a>(name: String,
|
||||
source: String,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_expr_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
|
||||
-> PResult<'a, P<ast::Expr>> {
|
||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||
p.parse_expr()
|
||||
new_parser_from_source_str(sess, name, source).parse_expr()
|
||||
}
|
||||
|
||||
/// Parses an item.
|
||||
///
|
||||
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and`Err`
|
||||
/// when a syntax error occurred.
|
||||
pub fn parse_item_from_source_str<'a>(name: String,
|
||||
source: String,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_item_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
|
||||
-> PResult<'a, Option<P<ast::Item>>> {
|
||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||
p.parse_item()
|
||||
new_parser_from_source_str(sess, name, source).parse_item()
|
||||
}
|
||||
|
||||
pub fn parse_meta_from_source_str<'a>(name: String,
|
||||
source: String,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_meta_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
|
||||
-> PResult<'a, P<ast::MetaItem>> {
|
||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||
p.parse_meta_item()
|
||||
new_parser_from_source_str(sess, name, source).parse_meta_item()
|
||||
}
|
||||
|
||||
pub fn parse_stmt_from_source_str<'a>(name: String,
|
||||
source: String,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_stmt_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
|
||||
-> PResult<'a, Option<ast::Stmt>> {
|
||||
let mut p = new_parser_from_source_str(
|
||||
sess,
|
||||
cfg,
|
||||
name,
|
||||
source
|
||||
);
|
||||
p.parse_stmt()
|
||||
new_parser_from_source_str(sess, name, source).parse_stmt()
|
||||
}
|
||||
|
||||
// Warning: This parses with quote_depth > 0, which is not the default.
|
||||
pub fn parse_tts_from_source_str<'a>(name: String,
|
||||
source: String,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: &'a ParseSess)
|
||||
pub fn parse_tts_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
|
||||
-> PResult<'a, Vec<tokenstream::TokenTree>> {
|
||||
let mut p = new_parser_from_source_str(
|
||||
sess,
|
||||
cfg,
|
||||
name,
|
||||
source
|
||||
);
|
||||
let mut p = new_parser_from_source_str(sess, name, source);
|
||||
p.quote_depth += 1;
|
||||
// right now this is re-creating the token trees from ... token trees.
|
||||
p.parse_all_token_trees()
|
||||
}
|
||||
|
||||
// Create a new parser from a source string
|
||||
pub fn new_parser_from_source_str<'a>(sess: &'a ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
name: String,
|
||||
source: String)
|
||||
pub fn new_parser_from_source_str<'a>(sess: &'a ParseSess, name: String, source: String)
|
||||
-> Parser<'a> {
|
||||
filemap_to_parser(sess, sess.codemap().new_filemap(name, None, source), cfg)
|
||||
filemap_to_parser(sess, sess.codemap().new_filemap(name, None, source))
|
||||
}
|
||||
|
||||
/// Create a new parser, handling errors as appropriate
|
||||
/// if the file doesn't exist
|
||||
pub fn new_parser_from_file<'a>(sess: &'a ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
path: &Path) -> Parser<'a> {
|
||||
filemap_to_parser(sess, file_to_filemap(sess, path, None), cfg)
|
||||
pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path) -> Parser<'a> {
|
||||
filemap_to_parser(sess, file_to_filemap(sess, path, None))
|
||||
}
|
||||
|
||||
/// Given a session, a crate config, a path, and a span, add
|
||||
/// the file at the given path to the codemap, and return a parser.
|
||||
/// On an error, use the given span as the source of the problem.
|
||||
pub fn new_sub_parser_from_file<'a>(sess: &'a ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
path: &Path,
|
||||
owns_directory: bool,
|
||||
module_name: Option<String>,
|
||||
sp: Span) -> Parser<'a> {
|
||||
let mut p = filemap_to_parser(sess, file_to_filemap(sess, path, Some(sp)), cfg);
|
||||
let mut p = filemap_to_parser(sess, file_to_filemap(sess, path, Some(sp)));
|
||||
p.owns_directory = owns_directory;
|
||||
p.root_module_name = module_name;
|
||||
p
|
||||
}
|
||||
|
||||
/// Given a filemap and config, return a parser
|
||||
pub fn filemap_to_parser<'a>(sess: &'a ParseSess,
|
||||
filemap: Rc<FileMap>,
|
||||
cfg: ast::CrateConfig) -> Parser<'a> {
|
||||
pub fn filemap_to_parser<'a>(sess: &'a ParseSess, filemap: Rc<FileMap>, ) -> Parser<'a> {
|
||||
let end_pos = filemap.end_pos;
|
||||
let mut parser = tts_to_parser(sess, filemap_to_tts(sess, filemap), cfg);
|
||||
let mut parser = tts_to_parser(sess, filemap_to_tts(sess, filemap));
|
||||
|
||||
if parser.token == token::Eof && parser.span == syntax_pos::DUMMY_SP {
|
||||
parser.span = syntax_pos::mk_sp(end_pos, end_pos);
|
||||
|
@ -228,18 +174,13 @@ pub fn filemap_to_parser<'a>(sess: &'a ParseSess,
|
|||
|
||||
// must preserve old name for now, because quote! from the *existing*
|
||||
// compiler expands into it
|
||||
pub fn new_parser_from_tts<'a>(sess: &'a ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
tts: Vec<tokenstream::TokenTree>)
|
||||
pub fn new_parser_from_tts<'a>(sess: &'a ParseSess, tts: Vec<tokenstream::TokenTree>)
|
||||
-> Parser<'a> {
|
||||
tts_to_parser(sess, tts, cfg)
|
||||
tts_to_parser(sess, tts)
|
||||
}
|
||||
|
||||
pub fn new_parser_from_ts<'a>(sess: &'a ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
ts: tokenstream::TokenStream)
|
||||
-> Parser<'a> {
|
||||
tts_to_parser(sess, ts.to_tts(), cfg)
|
||||
pub fn new_parser_from_ts<'a>(sess: &'a ParseSess, ts: tokenstream::TokenStream) -> Parser<'a> {
|
||||
tts_to_parser(sess, ts.to_tts())
|
||||
}
|
||||
|
||||
|
||||
|
@ -266,18 +207,15 @@ pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>)
|
|||
-> Vec<tokenstream::TokenTree> {
|
||||
// it appears to me that the cfg doesn't matter here... indeed,
|
||||
// parsing tt's probably shouldn't require a parser at all.
|
||||
let cfg = Vec::new();
|
||||
let srdr = lexer::StringReader::new(&sess.span_diagnostic, filemap);
|
||||
let mut p1 = Parser::new(sess, cfg, Box::new(srdr));
|
||||
let mut p1 = Parser::new(sess, Box::new(srdr));
|
||||
panictry!(p1.parse_all_token_trees())
|
||||
}
|
||||
|
||||
/// Given tts and cfg, produce a parser
|
||||
pub fn tts_to_parser<'a>(sess: &'a ParseSess,
|
||||
tts: Vec<tokenstream::TokenTree>,
|
||||
cfg: ast::CrateConfig) -> Parser<'a> {
|
||||
/// Given tts and the ParseSess, produce a parser
|
||||
pub fn tts_to_parser<'a>(sess: &'a ParseSess, tts: Vec<tokenstream::TokenTree>) -> Parser<'a> {
|
||||
let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, tts);
|
||||
let mut p = Parser::new(sess, cfg, Box::new(trdr));
|
||||
let mut p = Parser::new(sess, Box::new(trdr));
|
||||
p.check_unknown_macro_variable();
|
||||
p
|
||||
}
|
||||
|
@ -1057,13 +995,13 @@ mod tests {
|
|||
|
||||
let name = "<source>".to_string();
|
||||
let source = "/// doc comment\r\nfn foo() {}".to_string();
|
||||
let item = parse_item_from_source_str(name.clone(), source, Vec::new(), &sess)
|
||||
let item = parse_item_from_source_str(name.clone(), source, &sess)
|
||||
.unwrap().unwrap();
|
||||
let doc = first_attr_value_str_by_name(&item.attrs, "doc").unwrap();
|
||||
assert_eq!(&doc[..], "/// doc comment");
|
||||
|
||||
let source = "/// doc comment\r\n/// line 2\r\nfn foo() {}".to_string();
|
||||
let item = parse_item_from_source_str(name.clone(), source, Vec::new(), &sess)
|
||||
let item = parse_item_from_source_str(name.clone(), source, &sess)
|
||||
.unwrap().unwrap();
|
||||
let docs = item.attrs.iter().filter(|a| &*a.name() == "doc")
|
||||
.map(|a| a.value_str().unwrap().to_string()).collect::<Vec<_>>();
|
||||
|
@ -1071,7 +1009,7 @@ mod tests {
|
|||
assert_eq!(&docs[..], b);
|
||||
|
||||
let source = "/** doc comment\r\n * with CRLF */\r\nfn foo() {}".to_string();
|
||||
let item = parse_item_from_source_str(name, source, Vec::new(), &sess).unwrap().unwrap();
|
||||
let item = parse_item_from_source_str(name, source, &sess).unwrap().unwrap();
|
||||
let doc = first_attr_value_str_by_name(&item.attrs, "doc").unwrap();
|
||||
assert_eq!(&doc[..], "/** doc comment\n * with CRLF */");
|
||||
}
|
||||
|
@ -1080,7 +1018,7 @@ mod tests {
|
|||
fn ttdelim_span() {
|
||||
let sess = ParseSess::new();
|
||||
let expr = parse::parse_expr_from_source_str("foo".to_string(),
|
||||
"foo!( fn main() { body } )".to_string(), vec![], &sess).unwrap();
|
||||
"foo!( fn main() { body } )".to_string(), &sess).unwrap();
|
||||
|
||||
let tts = match expr.node {
|
||||
ast::ExprKind::Mac(ref mac) => mac.node.tts.clone(),
|
||||
|
|
|
@ -15,7 +15,7 @@ use ast::Unsafety;
|
|||
use ast::{Mod, Arg, Arm, Attribute, BindingMode, TraitItemKind};
|
||||
use ast::Block;
|
||||
use ast::{BlockCheckMode, CaptureBy};
|
||||
use ast::{Constness, Crate, CrateConfig};
|
||||
use ast::{Constness, Crate};
|
||||
use ast::Defaultness;
|
||||
use ast::EnumDef;
|
||||
use ast::{Expr, ExprKind, RangeLimits};
|
||||
|
@ -271,7 +271,6 @@ pub struct Parser<'a> {
|
|||
pub span: Span,
|
||||
/// the span of the previous token:
|
||||
pub prev_span: Span,
|
||||
pub cfg: CrateConfig,
|
||||
/// the previous token kind
|
||||
prev_token_kind: PrevTokenKind,
|
||||
lookahead_buffer: LookaheadBuffer,
|
||||
|
@ -358,11 +357,7 @@ impl From<P<Expr>> for LhsExpr {
|
|||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn new(sess: &'a ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
mut rdr: Box<Reader+'a>)
|
||||
-> Parser<'a>
|
||||
{
|
||||
pub fn new(sess: &'a ParseSess, mut rdr: Box<Reader+'a>) -> Self {
|
||||
let tok0 = rdr.real_token();
|
||||
let span = tok0.sp;
|
||||
let mut directory = match span {
|
||||
|
@ -374,7 +369,6 @@ impl<'a> Parser<'a> {
|
|||
Parser {
|
||||
reader: rdr,
|
||||
sess: sess,
|
||||
cfg: cfg,
|
||||
token: tok0.tok,
|
||||
span: span,
|
||||
prev_span: span,
|
||||
|
@ -5328,7 +5322,6 @@ impl<'a> Parser<'a> {
|
|||
fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> {
|
||||
let (in_cfg, outer_attrs) = {
|
||||
let mut strip_unconfigured = ::config::StripUnconfigured {
|
||||
config: &self.cfg,
|
||||
sess: self.sess,
|
||||
should_test: false, // irrelevant
|
||||
features: None, // don't perform gated feature checking
|
||||
|
@ -5496,12 +5489,7 @@ impl<'a> Parser<'a> {
|
|||
included_mod_stack.push(path.clone());
|
||||
drop(included_mod_stack);
|
||||
|
||||
let mut p0 = new_sub_parser_from_file(self.sess,
|
||||
self.cfg.clone(),
|
||||
&path,
|
||||
owns_directory,
|
||||
Some(name),
|
||||
id_sp);
|
||||
let mut p0 = new_sub_parser_from_file(self.sess, &path, owns_directory, Some(name), id_sp);
|
||||
let mod_inner_lo = p0.span.lo;
|
||||
let mod_attrs = p0.parse_inner_attributes()?;
|
||||
let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?;
|
||||
|
@ -6195,7 +6183,6 @@ impl<'a> Parser<'a> {
|
|||
Ok(ast::Crate {
|
||||
attrs: self.parse_inner_attributes()?,
|
||||
module: self.parse_mod_items(&token::Eof, lo)?,
|
||||
config: self.cfg.clone(),
|
||||
span: mk_sp(lo, self.span.lo),
|
||||
exported_macros: Vec::new(),
|
||||
})
|
||||
|
|
|
@ -274,7 +274,7 @@ fn generate_test_harness(sess: &ParseSess,
|
|||
let mut cx: TestCtxt = TestCtxt {
|
||||
sess: sess,
|
||||
span_diagnostic: sd,
|
||||
ext_cx: ExtCtxt::new(sess, vec![], ExpansionConfig::default("test".to_string()), resolver),
|
||||
ext_cx: ExtCtxt::new(sess, ExpansionConfig::default("test".to_string()), resolver),
|
||||
path: Vec::new(),
|
||||
testfns: Vec::new(),
|
||||
reexport_test_harness_main: reexport_test_harness_main,
|
||||
|
|
|
@ -220,7 +220,7 @@ impl TokenTree {
|
|||
None,
|
||||
tts.iter().cloned().collect(),
|
||||
true);
|
||||
macro_parser::parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtch)
|
||||
macro_parser::parse(cx.parse_sess(), arg_rdr, mtch)
|
||||
}
|
||||
|
||||
/// Check if this TokenTree is equal to the other, regardless of span information.
|
||||
|
|
|
@ -25,10 +25,7 @@ pub fn string_to_tts(source_str: String) -> Vec<tokenstream::TokenTree> {
|
|||
|
||||
/// Map string to parser (via tts)
|
||||
pub fn string_to_parser<'a>(ps: &'a ParseSess, source_str: String) -> Parser<'a> {
|
||||
new_parser_from_source_str(ps,
|
||||
Vec::new(),
|
||||
"bogofile".to_string(),
|
||||
source_str)
|
||||
new_parser_from_source_str(ps, "bogofile".to_string(), source_str)
|
||||
}
|
||||
|
||||
fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T where
|
||||
|
|
|
@ -107,7 +107,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
|
|||
if p2.token != token::Eof {
|
||||
let mut extra_tts = panictry!(p2.parse_all_token_trees());
|
||||
extra_tts.extend(tts[first_colon..].iter().cloned());
|
||||
p = parse::tts_to_parser(cx.parse_sess, extra_tts, cx.cfg().clone());
|
||||
p = parse::tts_to_parser(cx.parse_sess, extra_tts);
|
||||
}
|
||||
|
||||
asm = s;
|
||||
|
|
|
@ -32,6 +32,6 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
|
|||
return DummyResult::expr(sp);
|
||||
}
|
||||
|
||||
let matches_cfg = attr::cfg_matches(&cx.cfg, &cfg, cx.parse_sess, cx.ecfg.features);
|
||||
let matches_cfg = attr::cfg_matches(&cfg, cx.parse_sess, cx.ecfg.features);
|
||||
MacEager::expr(cx.expr_bool(sp, matches_cfg))
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn modify(sess: &ParseSess,
|
|||
handler: &errors::Handler,
|
||||
features: &Features) -> ast::Crate {
|
||||
let ecfg = ExpansionConfig::default("proc_macro".to_string());
|
||||
let mut cx = ExtCtxt::new(sess, Vec::new(), ecfg, resolver);
|
||||
let mut cx = ExtCtxt::new(sess, ecfg, resolver);
|
||||
|
||||
let mut collect = CollectCustomDerives {
|
||||
derives: Vec::new(),
|
||||
|
|
|
@ -56,8 +56,7 @@ fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
|
|||
fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree])
|
||||
-> Box<MacResult+'static> {
|
||||
// Parse an expression and emit it unchanged.
|
||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(),
|
||||
cx.cfg().clone(), tts.to_vec());
|
||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), tts.to_vec());
|
||||
let expr = parser.parse_expr().unwrap();
|
||||
MacEager::expr(quote_expr!(&mut *cx, $expr))
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ fn main() {
|
|||
let ps = syntax::parse::ParseSess::new();
|
||||
let mut resolver = syntax::ext::base::DummyResolver;
|
||||
let mut cx = syntax::ext::base::ExtCtxt::new(
|
||||
&ps, vec![],
|
||||
&ps,
|
||||
syntax::ext::expand::ExpansionConfig::default("qquote".to_string()),
|
||||
&mut resolver);
|
||||
cx.bt_push(syntax::codemap::ExpnInfo {
|
||||
|
|
|
@ -27,7 +27,7 @@ fn main() {
|
|||
let ps = syntax::parse::ParseSess::new();
|
||||
let mut resolver = syntax::ext::base::DummyResolver;
|
||||
let mut cx = syntax::ext::base::ExtCtxt::new(
|
||||
&ps, vec![],
|
||||
&ps,
|
||||
syntax::ext::expand::ExpansionConfig::default("qquote".to_string()),
|
||||
&mut resolver);
|
||||
cx.bt_push(syntax::codemap::ExpnInfo {
|
||||
|
|
|
@ -67,12 +67,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
|||
let (sess, cstore) = basic_sess(sysroot);
|
||||
let cfg = build_configuration(&sess, vec![]);
|
||||
let control = CompileController::basic();
|
||||
|
||||
compile_input(&sess, &cstore,
|
||||
cfg,
|
||||
&Input::Str { name: anon_src(), input: code },
|
||||
&None,
|
||||
&Some(output),
|
||||
None,
|
||||
&control);
|
||||
let input = Input::Str { name: anon_src(), input: code };
|
||||
compile_input(&sess, &cstore, &input, &None, &Some(output), None, &control);
|
||||
}
|
||||
|
|
|
@ -31,10 +31,7 @@ use std::fmt;
|
|||
// Copied out of syntax::util::parser_testing
|
||||
|
||||
pub fn string_to_parser<'a>(ps: &'a ParseSess, source_str: String) -> Parser<'a> {
|
||||
new_parser_from_source_str(ps,
|
||||
Vec::new(),
|
||||
"bogofile".to_string(),
|
||||
source_str)
|
||||
new_parser_from_source_str(ps, "bogofile".to_string(), source_str)
|
||||
}
|
||||
|
||||
fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> PResult<'a, T> where
|
||||
|
|
|
@ -60,7 +60,7 @@ fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResu
|
|||
// See Issue #15750
|
||||
fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree]) -> Box<MacResult + 'static> {
|
||||
// Parse an expression and emit it unchanged.
|
||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg().clone(), tts.to_vec());
|
||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), tts.to_vec());
|
||||
let expr = parser.parse_expr().unwrap();
|
||||
MacEager::expr(quote_expr!(&mut *cx, $expr))
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ impl<'a> CompilerCalls<'a> for TestCalls {
|
|||
fn late_callback(&mut self,
|
||||
_: &getopts::Matches,
|
||||
_: &Session,
|
||||
_: &ast::CrateConfig,
|
||||
_: &Input,
|
||||
_: &Option<PathBuf>,
|
||||
_: &Option<PathBuf>)
|
||||
|
|
|
@ -23,7 +23,7 @@ fn main() {
|
|||
let ps = syntax::parse::ParseSess::new();
|
||||
let mut resolver = syntax::ext::base::DummyResolver;
|
||||
let mut cx = syntax::ext::base::ExtCtxt::new(
|
||||
&ps, vec![],
|
||||
&ps,
|
||||
syntax::ext::expand::ExpansionConfig::default("qquote".to_string()),
|
||||
&mut resolver);
|
||||
cx.bt_push(syntax::codemap::ExpnInfo {
|
||||
|
|
Loading…
Add table
Reference in a new issue