Skip to content

Commit a228915

Browse files
author
Eric Reed
committed
---
yaml --- r: 64478 b: refs/heads/snap-stage3 c: 968f7f5 h: refs/heads/master v: v3
1 parent c8f6400 commit a228915

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+968
-856
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: cc760a647ac0094814f592d08813ebae0b3bec47
4+
refs/heads/snap-stage3: 968f7f5d3d64b481fb68651d9274768fe5e98853
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/back/link.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use std::vec;
3636
use syntax::ast;
3737
use syntax::ast_map::{path, path_mod, path_name};
3838
use syntax::attr;
39-
use syntax::attr::{AttrMetaMethods};
4039
use syntax::print::pprust;
4140
use syntax::parse::token;
4241

@@ -503,7 +502,7 @@ pub fn build_link_meta(sess: Session,
503502
struct ProvidedMetas {
504503
name: Option<@str>,
505504
vers: Option<@str>,
506-
cmh_items: ~[@ast::MetaItem]
505+
cmh_items: ~[@ast::meta_item]
507506
}
508507

509508
fn provided_link_metas(sess: Session, c: &ast::crate) ->
@@ -514,10 +513,18 @@ pub fn build_link_meta(sess: Session,
514513
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
515514
attr::require_unique_names(sess.diagnostic(), linkage_metas);
516515
for linkage_metas.iter().advance |meta| {
517-
match meta.name_str_pair() {
518-
Some((n, value)) if "name" == n => name = Some(value),
519-
Some((n, value)) if "vers" == n => vers = Some(value),
520-
_ => cmh_items.push(*meta)
516+
match attr::get_meta_item_value_str(*meta) {
517+
Some(value) => {
518+
let item_name : &str = attr::get_meta_item_name(*meta);
519+
match item_name {
520+
// Changing attr would avoid the need for the copy
521+
// here
522+
"name" => name = Some(value),
523+
"vers" => vers = Some(value),
524+
_ => cmh_items.push(*meta)
525+
}
526+
},
527+
None => cmh_items.push(*meta)
521528
}
522529
}
523530

@@ -530,7 +537,7 @@ pub fn build_link_meta(sess: Session,
530537

531538
// This calculates CMH as defined above
532539
fn crate_meta_extras_hash(symbol_hasher: &mut hash::State,
533-
cmh_items: ~[@ast::MetaItem],
540+
cmh_items: ~[@ast::meta_item],
534541
dep_hashes: ~[@str]) -> @str {
535542
fn len_and_str(s: &str) -> ~str {
536543
fmt!("%u_%s", s.len(), s)
@@ -542,16 +549,16 @@ pub fn build_link_meta(sess: Session,
542549

543550
let cmh_items = attr::sort_meta_items(cmh_items);
544551

545-
fn hash(symbol_hasher: &mut hash::State, m: &@ast::MetaItem) {
552+
fn hash(symbol_hasher: &mut hash::State, m: &@ast::meta_item) {
546553
match m.node {
547-
ast::MetaNameValue(key, value) => {
554+
ast::meta_name_value(key, value) => {
548555
write_string(symbol_hasher, len_and_str(key));
549556
write_string(symbol_hasher, len_and_str_lit(value));
550557
}
551-
ast::MetaWord(name) => {
558+
ast::meta_word(name) => {
552559
write_string(symbol_hasher, len_and_str(name));
553560
}
554-
ast::MetaList(name, ref mis) => {
561+
ast::meta_list(name, ref mis) => {
555562
write_string(symbol_hasher, len_and_str(name));
556563
for mis.iter().advance |m_| {
557564
hash(symbol_hasher, m_);

branches/snap-stage3/src/librustc/driver/driver.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use extra::getopts;
3434
use syntax::ast;
3535
use syntax::abi;
3636
use syntax::attr;
37-
use syntax::attr::{AttrMetaMethods};
3837
use syntax::codemap;
3938
use syntax::diagnostic;
4039
use syntax::parse;
@@ -96,9 +95,12 @@ pub fn default_configuration(sess: Session, argv0: @str, input: &input) ->
9695
mk(@"build_input", source_name(input))];
9796
}
9897

99-
pub fn append_configuration(cfg: &mut ast::crate_cfg, name: @str) {
100-
if !cfg.iter().any(|mi| mi.name() == name) {
101-
cfg.push(attr::mk_word_item(name))
98+
pub fn append_configuration(cfg: ast::crate_cfg, name: @str)
99+
-> ast::crate_cfg {
100+
if attr::contains_name(cfg, name) {
101+
cfg
102+
} else {
103+
vec::append_one(cfg, attr::mk_word_item(name))
102104
}
103105
}
104106

@@ -107,11 +109,18 @@ pub fn build_configuration(sess: Session, argv0: @str, input: &input) ->
107109
// Combine the configuration requested by the session (command line) with
108110
// some default and generated configuration items
109111
let default_cfg = default_configuration(sess, argv0, input);
110-
let mut user_cfg = sess.opts.cfg.clone();
112+
let user_cfg = sess.opts.cfg.clone();
111113
// If the user wants a test runner, then add the test cfg
112-
if sess.opts.test { append_configuration(&mut user_cfg, @"test") }
114+
let user_cfg = if sess.opts.test {
115+
append_configuration(user_cfg, @"test")
116+
} else {
117+
user_cfg
118+
};
119+
113120
// If the user requested GC, then add the GC cfg
114-
append_configuration(&mut user_cfg, if sess.opts.gc { @"gc" } else { @"nogc" });
121+
let user_cfg = append_configuration(
122+
user_cfg,
123+
if sess.opts.gc { @"gc" } else { @"nogc" });
115124
return vec::append(user_cfg, default_cfg);
116125
}
117126

@@ -121,7 +130,7 @@ fn parse_cfgspecs(cfgspecs: ~[~str],
121130
do cfgspecs.consume_iter().transform |s| {
122131
let sess = parse::new_parse_sess(Some(demitter));
123132
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
124-
}.collect::<ast::crate_cfg>()
133+
}.collect()
125134
}
126135

127136
pub enum input {
@@ -206,7 +215,6 @@ pub fn compile_rest(sess: Session,
206215
crate = time(time_passes, ~"configuration 2", ||
207216
front::config::strip_unconfigured_items(crate));
208217

209-
210218
crate = time(time_passes, ~"maybe building test harness", ||
211219
front::test::modify_for_testing(sess, crate));
212220
}
@@ -862,7 +870,7 @@ pub struct OutputFilenames {
862870
pub fn build_output_filenames(input: &input,
863871
odir: &Option<Path>,
864872
ofile: &Option<Path>,
865-
attrs: &[ast::Attribute],
873+
attrs: &[ast::attribute],
866874
sess: Session)
867875
-> @OutputFilenames {
868876
let obj_path;
@@ -904,10 +912,12 @@ pub fn build_output_filenames(input: &input,
904912
let linkage_metas = attr::find_linkage_metas(attrs);
905913
if !linkage_metas.is_empty() {
906914
// But if a linkage meta is present, that overrides
907-
let maybe_name = linkage_metas.iter().find_(|m| "name" == m.name());
908-
match maybe_name.chain(|m| m.value_str()) {
909-
Some(s) => stem = s,
910-
_ => ()
915+
let maybe_matches = attr::find_meta_items_by_name(linkage_metas, "name");
916+
if !maybe_matches.is_empty() {
917+
match attr::get_meta_item_value_str(maybe_matches[0]) {
918+
Some(s) => stem = s,
919+
_ => ()
920+
}
911921
}
912922
// If the name is missing, we just default to the filename
913923
// version
@@ -1001,8 +1011,7 @@ mod test {
10011011
@"rustc", matches, diagnostic::emit);
10021012
let sess = build_session(sessopts, diagnostic::emit);
10031013
let cfg = build_configuration(sess, @"whatever", &str_input(@""));
1004-
let mut test_items = cfg.iter().filter(|m| "test" == m.name());
1005-
assert!(test_items.next().is_some());
1006-
assert!(test_items.next().is_none());
1014+
let test_items = attr::find_meta_items_by_name(cfg, "test");
1015+
assert_eq!(test_items.len(), 1u);
10071016
}
10081017
}

branches/snap-stage3/src/librustc/driver/session.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ pub fn building_library(req_crate_type: crate_type,
369369
match syntax::attr::first_attr_value_str_by_name(
370370
crate.node.attrs,
371371
"crate_type") {
372-
Some(s) => "lib" == s,
372+
Some(s) if "lib" == s => true,
373373
_ => false
374374
}
375375
}
@@ -395,11 +395,18 @@ mod test {
395395
use driver::session::{unknown_crate};
396396

397397
use syntax::ast;
398-
use syntax::attr;
399398
use syntax::codemap;
400399

401-
fn make_crate_type_attr(t: @str) -> ast::Attribute {
402-
attr::mk_attr(attr::mk_name_value_item_str(@"crate_type", t))
400+
fn make_crate_type_attr(t: @str) -> ast::attribute {
401+
codemap::respan(codemap::dummy_sp(), ast::attribute_ {
402+
style: ast::attr_outer,
403+
value: @codemap::respan(codemap::dummy_sp(),
404+
ast::meta_name_value(
405+
@"crate_type",
406+
codemap::respan(codemap::dummy_sp(),
407+
ast::lit_str(t)))),
408+
is_sugared_doc: false
409+
})
403410
}
404411

405412
fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {

branches/snap-stage3/src/librustc/front/config.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::option;
1313
use syntax::{ast, fold, attr};
1414

15-
type in_cfg_pred = @fn(attrs: &[ast::Attribute]) -> bool;
15+
type in_cfg_pred = @fn(attrs: &[ast::attribute]) -> bool;
1616

1717
struct Context {
1818
in_cfg: in_cfg_pred
@@ -175,6 +175,31 @@ fn trait_method_in_cfg(cx: @Context, meth: &ast::trait_method) -> bool {
175175

176176
// Determine if an item should be translated in the current crate
177177
// configuration based on the item's attributes
178-
fn in_cfg(cfg: &[@ast::MetaItem], attrs: &[ast::Attribute]) -> bool {
179-
attr::test_cfg(cfg, attrs.iter().transform(|x| *x))
178+
fn in_cfg(cfg: &[@ast::meta_item], attrs: &[ast::attribute]) -> bool {
179+
metas_in_cfg(cfg, attr::attr_metas(attrs))
180+
}
181+
182+
pub fn metas_in_cfg(cfg: &[@ast::meta_item],
183+
metas: &[@ast::meta_item]) -> bool {
184+
// The "cfg" attributes on the item
185+
let cfg_metas = attr::find_meta_items_by_name(metas, "cfg");
186+
187+
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
188+
// so we can match against them. This is the list of configurations for
189+
// which the item is valid
190+
let cfg_metas = cfg_metas.consume_iter()
191+
.filter_map(|i| attr::get_meta_item_list(i))
192+
.collect::<~[~[@ast::meta_item]]>();
193+
194+
if cfg_metas.iter().all(|c| c.is_empty()) { return true; }
195+
196+
cfg_metas.iter().any(|cfg_meta| {
197+
cfg_meta.iter().all(|cfg_mi| {
198+
match cfg_mi.node {
199+
ast::meta_list(s, ref it) if "not" == s
200+
=> it.iter().all(|mi| !attr::contains(cfg, *mi)),
201+
_ => attr::contains(cfg, *cfg_mi)
202+
}
203+
})
204+
})
180205
}

branches/snap-stage3/src/librustc/front/std_inject.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ pub fn maybe_inject_libstd_ref(sess: Session, crate: @ast::crate)
3030
}
3131

3232
fn use_std(crate: &ast::crate) -> bool {
33-
!attr::contains_name(crate.node.attrs, "no_std")
33+
!attr::attrs_contains_name(crate.node.attrs, "no_std")
3434
}
35-
fn no_prelude(attrs: &[ast::Attribute]) -> bool {
36-
attr::contains_name(attrs, "no_implicit_prelude")
35+
fn no_prelude(attrs: &[ast::attribute]) -> bool {
36+
attr::attrs_contains_name(attrs, "no_implicit_prelude")
3737
}
3838

3939
fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
@@ -48,8 +48,14 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
4848
node: ast::view_item_extern_mod(
4949
sess.ident_of("std"), ~[], n1),
5050
attrs: ~[
51-
attr::mk_attr(
52-
attr::mk_name_value_item_str(@"vers", STD_VERSION.to_managed()))
51+
spanned(ast::attribute_ {
52+
style: ast::attr_inner,
53+
value: @spanned(ast::meta_name_value(
54+
@"vers",
55+
spanned(ast::lit_str(STD_VERSION.to_managed()))
56+
)),
57+
is_sugared_doc: false
58+
})
5359
],
5460
vis: ast::private,
5561
span: dummy_sp()

0 commit comments

Comments
 (0)