Skip to content

Commit

Permalink
auto merge of rust-lang#7903 : michaelwoerister/rust/end_of_spanned, …
Browse files Browse the repository at this point in the history
…r=jdm

Continuation of rust-lang#7826.

AST spanned<T> refactoring, AST type renamings:

`crate => Crate`
`local => Local`
`blk => Block`
`crate_num => CrateNum`
`crate_cfg => CrateConfig`
`field => Field`

Also, Crate, Field and Local are not wrapped in spanned<T> anymore.
  • Loading branch information
bors committed Jul 22, 2013
2 parents 7a3eaf8 + 5aee3e0 commit 52b7fc1
Show file tree
Hide file tree
Showing 84 changed files with 553 additions and 564 deletions.
6 changes: 3 additions & 3 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ pub mod write {
*/

pub fn build_link_meta(sess: Session,
c: &ast::crate,
c: &ast::Crate,
output: &Path,
symbol_hasher: &mut hash::State)
-> LinkMeta {
Expand All @@ -498,12 +498,12 @@ pub fn build_link_meta(sess: Session,
cmh_items: ~[@ast::MetaItem]
}

fn provided_link_metas(sess: Session, c: &ast::crate) ->
fn provided_link_metas(sess: Session, c: &ast::Crate) ->
ProvidedMetas {
let mut name = None;
let mut vers = None;
let mut cmh_items = ~[];
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
let linkage_metas = attr::find_linkage_metas(c.attrs);
attr::require_unique_names(sess.diagnostic(), linkage_metas);
for linkage_metas.iter().advance |meta| {
match meta.name_str_pair() {
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn source_name(input: &input) -> @str {
}
pub fn default_configuration(sess: Session, argv0: @str, input: &input) ->
ast::crate_cfg {
ast::CrateConfig {
let (libc, tos) = match sess.targ_cfg.os {
session::os_win32 => (@"msvcrt.dll", @"win32"),
session::os_macos => (@"libc.dylib", @"macos"),
Expand Down Expand Up @@ -96,14 +96,14 @@ pub fn default_configuration(sess: Session, argv0: @str, input: &input) ->
mk(@"build_input", source_name(input))];
}

pub fn append_configuration(cfg: &mut ast::crate_cfg, name: @str) {
pub fn append_configuration(cfg: &mut ast::CrateConfig, name: @str) {
if !cfg.iter().any(|mi| mi.name() == name) {
cfg.push(attr::mk_word_item(name))
}
}

pub fn build_configuration(sess: Session, argv0: @str, input: &input) ->
ast::crate_cfg {
ast::CrateConfig {
// Combine the configuration requested by the session (command line) with
// some default and generated configuration items
let default_cfg = default_configuration(sess, argv0, input);
Expand All @@ -117,11 +117,11 @@ pub fn build_configuration(sess: Session, argv0: @str, input: &input) ->

// Convert strings provided as --cfg [cfgspec] into a crate_cfg
fn parse_cfgspecs(cfgspecs: ~[~str],
demitter: diagnostic::Emitter) -> ast::crate_cfg {
demitter: diagnostic::Emitter) -> ast::CrateConfig {
do cfgspecs.consume_iter().transform |s| {
let sess = parse::new_parse_sess(Some(demitter));
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
}.collect::<ast::crate_cfg>()
}.collect::<ast::CrateConfig>()
}

pub enum input {
Expand All @@ -132,8 +132,8 @@ pub enum input {
str_input(@str)
}

pub fn parse_input(sess: Session, cfg: ast::crate_cfg, input: &input)
-> @ast::crate {
pub fn parse_input(sess: Session, cfg: ast::CrateConfig, input: &input)
-> @ast::Crate {
match *input {
file_input(ref file) => {
parse::parse_crate_from_file(&(*file), cfg, sess.parse_sess)
Expand Down Expand Up @@ -167,11 +167,11 @@ pub enum compile_phase {

#[fixed_stack_segment]
pub fn compile_rest(sess: Session,
cfg: ast::crate_cfg,
cfg: ast::CrateConfig,
phases: compile_upto,
outputs: Option<@OutputFilenames>,
curr: Option<@ast::crate>)
-> (Option<@ast::crate>, Option<ty::ctxt>) {
curr: Option<@ast::Crate>)
-> (Option<@ast::Crate>, Option<ty::ctxt>) {

let time_passes = sess.time_passes();

Expand Down Expand Up @@ -372,11 +372,11 @@ pub fn compile_rest(sess: Session,
}

pub fn compile_upto(sess: Session,
cfg: ast::crate_cfg,
cfg: ast::CrateConfig,
input: &input,
upto: compile_phase,
outputs: Option<@OutputFilenames>)
-> (Option<@ast::crate>, Option<ty::ctxt>) {
-> (Option<@ast::Crate>, Option<ty::ctxt>) {
let time_passes = sess.time_passes();
let crate = time(time_passes,
~"parsing",
Expand All @@ -395,7 +395,7 @@ pub fn compile_upto(sess: Session,
Some(crate))
}

pub fn compile_input(sess: Session, cfg: ast::crate_cfg, input: &input,
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
outdir: &Option<Path>, output: &Option<Path>) {
let upto = if sess.opts.parse_only { cu_parse }
else if sess.opts.no_trans { cu_no_trans }
Expand All @@ -404,7 +404,7 @@ pub fn compile_input(sess: Session, cfg: ast::crate_cfg, input: &input,
compile_upto(sess, cfg, input, upto, Some(outputs));
}

pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &input,
ppm: pp_mode) {
fn ann_paren_for_expr(node: pprust::ann_node) {
match node {
Expand Down
15 changes: 8 additions & 7 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub struct options {
// items to the crate config, and during parsing the entire crate config
// will be added to the crate AST node. This should not be used for
// anything except building the full crate config prior to parsing.
cfg: ast::crate_cfg,
cfg: ast::CrateConfig,
binary: @str,
test: bool,
parse_only: bool,
Expand Down Expand Up @@ -357,7 +357,7 @@ pub fn expect<T:Clone>(sess: Session, opt: Option<T>, msg: &fn() -> ~str)
}

pub fn building_library(req_crate_type: crate_type,
crate: &ast::crate,
crate: &ast::Crate,
testing: bool) -> bool {
match req_crate_type {
bin_crate => false,
Expand All @@ -367,7 +367,7 @@ pub fn building_library(req_crate_type: crate_type,
false
} else {
match syntax::attr::first_attr_value_str_by_name(
crate.node.attrs,
crate.attrs,
"crate_type") {
Some(s) => "lib" == s,
_ => false
Expand Down Expand Up @@ -402,19 +402,20 @@ mod test {
attr::mk_attr(attr::mk_name_value_item_str(@"crate_type", t))
}

fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {
fn make_crate(with_bin: bool, with_lib: bool) -> @ast::Crate {
let mut attrs = ~[];
if with_bin {
attrs.push(make_crate_type_attr(@"bin"));
}
if with_lib {
attrs.push(make_crate_type_attr(@"lib"));
}
@codemap::respan(codemap::dummy_sp(), ast::crate_ {
@ast::Crate {
module: ast::_mod { view_items: ~[], items: ~[] },
attrs: attrs,
config: ~[]
})
config: ~[],
span: codemap::dummy_sp(),
}
}

#[test]
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ struct Context {

// Support conditional compilation by transforming the AST, stripping out
// any items that do not belong in the current configuration
pub fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate {
pub fn strip_unconfigured_items(crate: @ast::Crate) -> @ast::Crate {
do strip_items(crate) |attrs| {
in_cfg(crate.node.config, attrs)
in_cfg(crate.config, attrs)
}
}

pub fn strip_items(crate: &ast::crate, in_cfg: in_cfg_pred)
-> @ast::crate {
pub fn strip_items(crate: &ast::Crate, in_cfg: in_cfg_pred)
-> @ast::Crate {

let ctxt = @Context { in_cfg: in_cfg };

Expand Down Expand Up @@ -131,16 +131,16 @@ fn filter_stmt(cx: @Context, stmt: @ast::stmt) ->

fn fold_block(
cx: @Context,
b: &ast::blk,
b: &ast::Block,
fld: @fold::ast_fold
) -> ast::blk {
) -> ast::Block {
let resulting_stmts = do b.stmts.iter().filter_map |a| {
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
}.collect();
let filtered_view_items = do b.view_items.iter().filter_map |a| {
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
}.collect();
ast::blk {
ast::Block {
view_items: filtered_view_items,
stmts: resulting_stmts,
expr: b.expr.map(|x| fld.fold_expr(*x)),
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/front/std_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,30 @@ use syntax::fold;

static STD_VERSION: &'static str = "0.8-pre";

pub fn maybe_inject_libstd_ref(sess: Session, crate: @ast::crate)
-> @ast::crate {
pub fn maybe_inject_libstd_ref(sess: Session, crate: @ast::Crate)
-> @ast::Crate {
if use_std(crate) {
inject_libstd_ref(sess, crate)
} else {
crate
}
}

fn use_std(crate: &ast::crate) -> bool {
!attr::contains_name(crate.node.attrs, "no_std")
fn use_std(crate: &ast::Crate) -> bool {
!attr::contains_name(crate.attrs, "no_std")
}

fn no_prelude(attrs: &[ast::Attribute]) -> bool {
attr::contains_name(attrs, "no_implicit_prelude")
}

fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
fn inject_libstd_ref(sess: Session, crate: &ast::Crate) -> @ast::Crate {
fn spanned<T>(x: T) -> codemap::spanned<T> {
codemap::spanned { node: x, span: dummy_sp() }
}

let precursor = @fold::AstFoldFns {
fold_crate: |crate, span, fld| {
fold_crate: |crate, fld| {
let n1 = sess.next_node_id();
let vi1 = ast::view_item {
node: ast::view_item_extern_mod(
Expand All @@ -68,11 +69,10 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
}

// FIXME #2543: Bad copy.
let new_crate = ast::crate_ {
ast::Crate {
module: new_module,
..(*crate).clone()
};
(new_crate, span)
}
},
fold_item: |item, fld| {
if !no_prelude(item.attrs) {
Expand Down
26 changes: 13 additions & 13 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Test {

struct TestCtxt {
sess: session::Session,
crate: @ast::crate,
crate: @ast::Crate,
path: ~[ast::ident],
ext_cx: @ExtCtxt,
testfns: ~[Test]
Expand All @@ -46,12 +46,12 @@ struct TestCtxt {
// Traverse the crate, collecting all the test functions, eliding any
// existing main functions, and synthesizing a main test harness
pub fn modify_for_testing(sess: session::Session,
crate: @ast::crate)
-> @ast::crate {
crate: @ast::Crate)
-> @ast::Crate {
// We generate the test harness when building in the 'test'
// configuration, either with the '--test' or '--cfg test'
// command line options.
let should_test = attr::contains_name(crate.node.config, "test");
let should_test = attr::contains_name(crate.config, "test");

if should_test {
generate_test_harness(sess, crate)
Expand All @@ -61,8 +61,8 @@ pub fn modify_for_testing(sess: session::Session,
}

fn generate_test_harness(sess: session::Session,
crate: @ast::crate)
-> @ast::crate {
crate: @ast::Crate)
-> @ast::Crate {
let cx: @mut TestCtxt = @mut TestCtxt {
sess: sess,
crate: crate,
Expand All @@ -81,7 +81,7 @@ fn generate_test_harness(sess: session::Session,
});

let precursor = @fold::AstFoldFns {
fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ),
fold_crate: |a,b| fold_crate(cx, a, b),
fold_item: |a,b| fold_item(cx, a, b),
fold_mod: |a,b| fold_mod(cx, a, b),.. *fold::default_ast_fold()};

Expand All @@ -91,7 +91,7 @@ fn generate_test_harness(sess: session::Session,
return res;
}

fn strip_test_functions(crate: &ast::crate) -> @ast::crate {
fn strip_test_functions(crate: &ast::Crate) -> @ast::Crate {
// When not compiling with --test we should not compile the
// #[test] functions
do config::strip_items(crate) |attrs| {
Expand Down Expand Up @@ -132,13 +132,13 @@ fn fold_mod(cx: @mut TestCtxt,
fold::noop_fold_mod(&mod_nomain, fld)
}

fn fold_crate(cx: @mut TestCtxt, c: &ast::crate_, fld: @fold::ast_fold)
-> ast::crate_ {
fn fold_crate(cx: @mut TestCtxt, c: &ast::Crate, fld: @fold::ast_fold)
-> ast::Crate {
let folded = fold::noop_fold_crate(c, fld);

// Add a special __test module to the crate that will contain code
// generated for the test harness
ast::crate_ {
ast::Crate {
module: add_test_module(cx, &folded.module),
.. folded
}
Expand Down Expand Up @@ -236,7 +236,7 @@ fn is_ignored(cx: @mut TestCtxt, i: @ast::item) -> bool {
do i.attrs.iter().any |attr| {
// check ignore(cfg(foo, bar))
"ignore" == attr.name() && match attr.meta_item_list() {
Some(ref cfgs) => attr::test_cfg(cx.crate.node.config, cfgs.iter().transform(|x| *x)),
Some(ref cfgs) => attr::test_cfg(cx.crate.config, cfgs.iter().transform(|x| *x)),
None => true
}
}
Expand Down Expand Up @@ -370,7 +370,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item {
}

fn is_extra(cx: &TestCtxt) -> bool {
let items = attr::find_linkage_metas(cx.crate.node.attrs);
let items = attr::find_linkage_metas(cx.crate.attrs);
match attr::last_meta_item_value_str_by_name(items, "name") {
Some(s) if "extra" == s => true,
_ => false
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use syntax::ast;
// Traverses an AST, reading all the information about use'd crates and extern
// libraries necessary for later resolving, typechecking, linking, etc.
pub fn read_crates(diag: @span_handler,
crate: &ast::crate,
crate: &ast::Crate,
cstore: @mut cstore::CStore,
filesearch: @FileSearch,
os: loader::os,
Expand Down Expand Up @@ -118,14 +118,14 @@ struct Env {
os: loader::os,
statik: bool,
crate_cache: @mut ~[cache_entry],
next_crate_num: ast::crate_num,
next_crate_num: ast::CrateNum,
intr: @ident_interner
}

fn visit_crate(e: &Env, c: &ast::crate) {
fn visit_crate(e: &Env, c: &ast::Crate) {
let cstore = e.cstore;

for c.node.attrs.iter().filter(|m| "link_args" == m.name()).advance |a| {
for c.attrs.iter().filter(|m| "link_args" == m.name()).advance |a| {
match a.value_str() {
Some(ref linkarg) => {
cstore::add_used_link_args(cstore, *linkarg);
Expand Down Expand Up @@ -237,7 +237,7 @@ fn resolve_crate(e: @mut Env,
metas: ~[@ast::MetaItem],
hash: @str,
span: span)
-> ast::crate_num {
-> ast::CrateNum {
let metas = metas_with_ident(token::ident_to_str(&ident), metas);

match existing_match(e, metas, hash) {
Expand Down
Loading

0 comments on commit 52b7fc1

Please sign in to comment.