rustc: Support 'companion mod's for crates and directory mods

Under this scheme when parsing foo.rc the parser will also look for
foo.rs to fill in the crate-level module, and when evaluating a
directory module directive it will look for a .rs file with the
same name as the directory.
This commit is contained in:
Brian Anderson 2011-10-29 01:21:43 -07:00
parent 2cebef095e
commit e0f44730e8
11 changed files with 88 additions and 14 deletions

View file

@ -1,5 +1,5 @@
import std::{io, vec, str, option, either, result};
import std::{io, vec, str, option, either, result, fs};
import std::option::{some, none};
import std::either::{left, right};
import std::map::{hashmap, new_str_hash};
@ -2599,13 +2599,15 @@ fn parse_crate_from_crate_file(input: str, cfg: ast::crate_cfg,
mutable chpos: p.get_chpos(),
mutable byte_pos: p.get_byte_pos(),
cfg: p.get_cfg()};
let m = eval::eval_crate_directives_to_mod(cx, cdirs, prefix);
let (companionmod, _) = fs::splitext(fs::basename(input));
let (m, attrs) = eval::eval_crate_directives_to_mod(
cx, cdirs, prefix, option::some(companionmod));
let hi = p.get_hi_pos();
expect(p, token::EOF);
ret @spanned(lo, hi,
{directives: cdirs,
module: m,
attrs: crate_attrs,
attrs: crate_attrs + attrs,
config: p.get_cfg()});
}