diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-11-05 04:16:26 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-11-22 01:48:10 +0000 |
| commit | 5675d9d28007691c4f396abcd4b29a228150eeb4 (patch) | |
| tree | ff28ee180c2e904520168d953a6946574c94b18b /src/libsyntax/ext | |
| parent | 7b3eeea22c9b81f6e7277b79517a0dab25b9f383 (diff) | |
| download | rust-5675d9d28007691c4f396abcd4b29a228150eeb4.tar.gz rust-5675d9d28007691c4f396abcd4b29a228150eeb4.zip | |
Clean up directory ownership semantics.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 13 |
4 files changed, 28 insertions, 22 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index ddf4cf11f20..ddbca47429d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -18,7 +18,7 @@ use errors::DiagnosticBuilder; use ext::expand::{self, Expansion}; use ext::hygiene::Mark; use fold::{self, Folder}; -use parse::{self, parser}; +use parse::{self, parser, DirectoryOwnership}; use parse::token; use ptr::P; use symbol::Symbol; @@ -568,9 +568,7 @@ pub struct ExpansionData { pub depth: usize, pub backtrace: ExpnId, pub module: Rc<ModuleData>, - - // True if non-inline modules without a `#[path]` are forbidden at the root of this expansion. - pub no_noninline_mod: bool, + pub directory_ownership: DirectoryOwnership, } /// One of these is made during expansion and incrementally updated as we go; @@ -601,7 +599,7 @@ impl<'a> ExtCtxt<'a> { depth: 0, backtrace: NO_EXPANSION, module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }), - no_noninline_mod: false, + directory_ownership: DirectoryOwnership::Owned, }, } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 844fb77e29d..3e8f118ce62 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -21,7 +21,7 @@ use ext::base::*; use feature_gate::{self, Features}; use fold; use fold::*; -use parse::{ParseSess, PResult, lexer}; +use parse::{ParseSess, DirectoryOwnership, PResult, lexer}; use parse::parser::Parser; use parse::token; use print::pprust; @@ -727,9 +727,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } fn fold_block(&mut self, block: P<Block>) -> P<Block> { - let no_noninline_mod = mem::replace(&mut self.cx.current_expansion.no_noninline_mod, true); + let old_directory_ownership = self.cx.current_expansion.directory_ownership; + self.cx.current_expansion.directory_ownership = DirectoryOwnership::UnownedViaBlock; let result = noop_fold_block(block, self); - self.cx.current_expansion.no_noninline_mod = no_noninline_mod; + self.cx.current_expansion.directory_ownership = old_directory_ownership; result } @@ -768,7 +769,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { return noop_fold_item(item, self); } - let orig_no_noninline_mod = self.cx.current_expansion.no_noninline_mod; + let orig_directory_ownership = self.cx.current_expansion.directory_ownership; let mut module = (*self.cx.current_expansion.module).clone(); module.mod_path.push(item.ident); @@ -779,23 +780,28 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { if inline_module { if let Some(path) = attr::first_attr_value_str_by_name(&item.attrs, "path") { - self.cx.current_expansion.no_noninline_mod = false; + self.cx.current_expansion.directory_ownership = DirectoryOwnership::Owned; module.directory.push(&*path.as_str()); } else { module.directory.push(&*item.ident.name.as_str()); } } else { - self.cx.current_expansion.no_noninline_mod = false; - module.directory = + let mut path = PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner)); - module.directory.pop(); + let directory_ownership = match path.file_name().unwrap().to_str() { + Some("mod.rs") => DirectoryOwnership::Owned, + _ => DirectoryOwnership::UnownedViaMod, + }; + path.pop(); + module.directory = path; + self.cx.current_expansion.directory_ownership = directory_ownership; } let orig_module = mem::replace(&mut self.cx.current_expansion.module, Rc::new(module)); let result = noop_fold_item(item, self); self.cx.current_expansion.module = orig_module; - self.cx.current_expansion.no_noninline_mod = orig_no_noninline_mod; + self.cx.current_expansion.directory_ownership = orig_directory_ownership; return result; } // Ensure that test functions are accessible from the test harness. diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 320d49b6463..39b92c7d007 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -13,7 +13,7 @@ use syntax_pos::{self, Pos, Span}; use ext::base::*; use ext::base; use ext::build::AstBuilder; -use parse::token; +use parse::{token, DirectoryOwnership}; use parse; use print::pprust; use ptr::P; @@ -90,7 +90,8 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T }; // The file will be added to the code map by the parser 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); + let directory_ownership = DirectoryOwnership::Owned; + let p = parse::new_sub_parser_from_file(cx.parse_sess(), &path, directory_ownership, None, sp); struct ExpandResult<'a> { p: parse::parser::Parser<'a>, diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 59b8b50e88c..4164b4a93ec 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -19,7 +19,7 @@ use ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal}; use ext::tt::macro_parser::{parse, parse_failure_msg}; use parse::ParseSess; use parse::lexer::new_tt_reader; -use parse::parser::{Parser, Restrictions}; +use parse::parser::Parser; use parse::token::{self, NtTT, Token}; use parse::token::Token::*; use print; @@ -117,11 +117,12 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, let trncbr = new_tt_reader(&cx.parse_sess.span_diagnostic, Some(named_matches), rhs); 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, - false => Restrictions::empty(), - }; + let module = &cx.current_expansion.module; + p.directory.path = module.directory.clone(); + p.directory.ownership = cx.current_expansion.directory_ownership; + p.root_module_name = + module.mod_path.last().map(|id| (*id.name.as_str()).to_owned()); + p.check_unknown_macro_variable(); // Let the context choose how to interpret the result. // Weird, but useful for X-macros. |
