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