convert ast::attribute_ and ast::view_item to a struct
This commit is contained in:
parent
eafed93d72
commit
4b0f702608
@ -345,7 +345,7 @@ mod test {
|
||||
use syntax::ast_util;
|
||||
|
||||
fn make_crate_type_attr(+t: ~str) -> ast::attribute {
|
||||
ast_util::respan(ast_util::dummy_sp(), {
|
||||
ast_util::respan(ast_util::dummy_sp(), ast::attribute_ {
|
||||
style: ast::attr_outer,
|
||||
value: ast_util::respan(ast_util::dummy_sp(),
|
||||
ast::meta_name_value(
|
||||
|
@ -45,22 +45,21 @@ fn inject_libcore_ref(sess: Session,
|
||||
let precursor = @fold::AstFoldFns {
|
||||
fold_crate: |crate, span, fld| {
|
||||
let n1 = sess.next_node_id();
|
||||
let vi1 = @{node: ast::view_item_use(sess.ident_of(~"core"),
|
||||
~[],
|
||||
n1),
|
||||
attrs: ~[
|
||||
spanned({
|
||||
style: ast::attr_inner,
|
||||
value: spanned(ast::meta_name_value(
|
||||
~"vers",
|
||||
spanned(ast::lit_str(
|
||||
@CORE_VERSION.to_str()))
|
||||
)),
|
||||
is_sugared_doc: false
|
||||
})
|
||||
],
|
||||
vis: ast::private,
|
||||
span: dummy_sp()};
|
||||
let vi1 = @ast::view_item {
|
||||
node: ast::view_item_use(sess.ident_of(~"core"), ~[], n1),
|
||||
attrs: ~[
|
||||
spanned(ast::attribute_ {
|
||||
style: ast::attr_inner,
|
||||
value: spanned(ast::meta_name_value(
|
||||
~"vers",
|
||||
spanned(ast::lit_str(@CORE_VERSION.to_str()))
|
||||
)),
|
||||
is_sugared_doc: false
|
||||
})
|
||||
],
|
||||
vis: ast::private,
|
||||
span: dummy_sp()
|
||||
};
|
||||
|
||||
let vis = vec::append(~[vi1], crate.module.view_items);
|
||||
let mut new_module = {
|
||||
@ -88,10 +87,10 @@ fn inject_libcore_ref(sess: Session,
|
||||
};
|
||||
|
||||
let vp = @spanned(ast::view_path_glob(prelude_path, n2));
|
||||
let vi2 = @{node: ast::view_item_import(~[vp]),
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: dummy_sp()};
|
||||
let vi2 = @ast::view_item { node: ast::view_item_import(~[vp]),
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: dummy_sp() };
|
||||
|
||||
let vis = vec::append(~[vi2], module.view_items);
|
||||
|
||||
|
@ -268,7 +268,7 @@ fn mk_std(cx: test_ctxt) -> @ast::view_item {
|
||||
let vi = ast::view_item_use(cx.sess.ident_of(~"std"),
|
||||
~[@mi],
|
||||
cx.sess.next_node_id());
|
||||
let vi = {
|
||||
let vi = ast::view_item {
|
||||
node: vi,
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
|
@ -1034,10 +1034,14 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
|
||||
assert (vec::len(meta_items) == 1u);
|
||||
let meta_item = meta_items[0];
|
||||
attrs.push(
|
||||
ast::spanned { node: { style: ast::attr_outer,
|
||||
value: /*bad*/copy *meta_item,
|
||||
is_sugared_doc: false },
|
||||
span: ast_util::dummy_sp()});
|
||||
ast::spanned {
|
||||
node: ast::attribute_ {
|
||||
style: ast::attr_outer,
|
||||
value: /*bad*/copy *meta_item,
|
||||
is_sugared_doc: false,
|
||||
},
|
||||
span: ast_util::dummy_sp()
|
||||
});
|
||||
};
|
||||
}
|
||||
option::None => ()
|
||||
|
@ -1393,8 +1393,12 @@ enum view_path_ {
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type view_item = {node: view_item_, attrs: ~[attribute],
|
||||
vis: visibility, span: span};
|
||||
struct view_item {
|
||||
node: view_item_,
|
||||
attrs: ~[attribute],
|
||||
vis: visibility,
|
||||
span: span,
|
||||
}
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
@ -1424,7 +1428,11 @@ impl attr_style : cmp::Eq {
|
||||
// doc-comments are promoted to attributes that have is_sugared_doc = true
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool};
|
||||
struct attribute_ {
|
||||
style: attr_style,
|
||||
value: meta_item,
|
||||
is_sugared_doc: bool,
|
||||
}
|
||||
|
||||
/*
|
||||
trait_refs appear in impls.
|
||||
|
@ -91,19 +91,20 @@ fn mk_word_item(name: ~str) -> @ast::meta_item {
|
||||
}
|
||||
|
||||
fn mk_attr(item: @ast::meta_item) -> ast::attribute {
|
||||
return dummy_spanned({style: ast::attr_inner, value: *item,
|
||||
is_sugared_doc: false});
|
||||
dummy_spanned(ast::attribute_ { style: ast::attr_inner,
|
||||
value: *item,
|
||||
is_sugared_doc: false })
|
||||
}
|
||||
|
||||
fn mk_sugared_doc_attr(text: ~str,
|
||||
+lo: BytePos, +hi: BytePos) -> ast::attribute {
|
||||
let lit = spanned(lo, hi, ast::lit_str(@text));
|
||||
let attr = {
|
||||
let attr = ast::attribute_ {
|
||||
style: doc_comment_style(text),
|
||||
value: spanned(lo, hi, ast::meta_name_value(~"doc", lit)),
|
||||
is_sugared_doc: true
|
||||
};
|
||||
return spanned(lo, hi, attr);
|
||||
spanned(lo, hi, attr)
|
||||
}
|
||||
|
||||
/* Conversion */
|
||||
|
@ -173,10 +173,10 @@ fn mk_glob_use(cx: ext_ctxt, sp: span,
|
||||
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
|
||||
span: sp,
|
||||
};
|
||||
@{node: ast::view_item_import(~[glob]),
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: sp}
|
||||
@ast::view_item { node: ast::view_item_import(~[glob]),
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: sp }
|
||||
}
|
||||
fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
|
||||
ident: ast::ident, ex: @ast::expr) -> @ast::stmt {
|
||||
|
@ -219,7 +219,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
||||
|
||||
// XXX: Would be nice if our generated code didn't violate
|
||||
// Rust coding conventions
|
||||
let non_camel_case_attribute = respan(dummy_sp(), {
|
||||
let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ {
|
||||
style: ast::attr_outer,
|
||||
value: respan(dummy_sp(),
|
||||
ast::meta_list(~"allow", ~[
|
||||
@ -306,7 +306,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
||||
span: ast_util::dummy_sp()
|
||||
}
|
||||
]);
|
||||
let vi = @{
|
||||
let vi = @ast::view_item {
|
||||
node: vi,
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
|
@ -114,10 +114,14 @@ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
|
||||
}
|
||||
//used in noop_fold_item and noop_fold_crate
|
||||
fn fold_attribute_(at: attribute, fld: ast_fold) -> attribute {
|
||||
spanned { node: { style: at.node.style,
|
||||
value: *fold_meta_item_(@at.node.value, fld),
|
||||
is_sugared_doc: at.node.is_sugared_doc },
|
||||
span: fld.new_span(at.span) }
|
||||
spanned {
|
||||
node: ast::attribute_ {
|
||||
style: at.node.style,
|
||||
value: *fold_meta_item_(@at.node.value, fld),
|
||||
is_sugared_doc: at.node.is_sugared_doc,
|
||||
},
|
||||
span: fld.new_span(at.span),
|
||||
}
|
||||
}
|
||||
//used in noop_fold_foreign_item and noop_fold_fn_decl
|
||||
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
|
||||
@ -679,11 +683,13 @@ impl ast_fold_fns: ast_fold {
|
||||
}
|
||||
fn fold_view_item(&&x: @view_item) ->
|
||||
@view_item {
|
||||
return @{node: (self.fold_view_item)(x.node, self as ast_fold),
|
||||
attrs: vec::map(x.attrs, |a|
|
||||
@ast::view_item {
|
||||
node: (self.fold_view_item)(x.node, self as ast_fold),
|
||||
attrs: vec::map(x.attrs, |a|
|
||||
fold_attribute_(*a, self as ast_fold)),
|
||||
vis: x.vis,
|
||||
span: (self.new_span)(x.span)};
|
||||
vis: x.vis,
|
||||
span: (self.new_span)(x.span),
|
||||
}
|
||||
}
|
||||
fn fold_foreign_item(&&x: @foreign_item)
|
||||
-> @foreign_item {
|
||||
|
@ -72,8 +72,9 @@ impl Parser: parser_attr {
|
||||
let meta_item = self.parse_meta_item();
|
||||
self.expect(token::RBRACKET);
|
||||
let mut hi = self.span.hi;
|
||||
return spanned(lo, hi, {style: style, value: *meta_item,
|
||||
is_sugared_doc: false});
|
||||
return spanned(lo, hi, ast::attribute_ { style: style,
|
||||
value: *meta_item,
|
||||
is_sugared_doc: false });
|
||||
}
|
||||
|
||||
// Parse attributes that appear after the opening of an item, each
|
||||
@ -101,8 +102,9 @@ impl Parser: parser_attr {
|
||||
// It's not really an inner attribute
|
||||
let outer_attr =
|
||||
spanned(attr.span.lo, attr.span.hi,
|
||||
{style: ast::attr_outer, value: attr.node.value,
|
||||
is_sugared_doc: false});
|
||||
ast::attribute_ { style: ast::attr_outer,
|
||||
value: attr.node.value,
|
||||
is_sugared_doc: false });
|
||||
next_outer_attrs += ~[outer_attr];
|
||||
break;
|
||||
}
|
||||
|
@ -3276,12 +3276,12 @@ impl Parser {
|
||||
// extern mod foo;
|
||||
let metadata = self.parse_optional_meta();
|
||||
self.expect(token::SEMI);
|
||||
return iovi_view_item(@{
|
||||
iovi_view_item(@ast::view_item {
|
||||
node: view_item_use(ident, metadata, self.get_id()),
|
||||
attrs: attrs,
|
||||
vis: visibility,
|
||||
span: mk_sp(lo, self.last_span.hi)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_type_decl() -> {lo: BytePos, ident: ident} {
|
||||
@ -3573,7 +3573,7 @@ impl Parser {
|
||||
} else if self.eat_keyword(~"use") {
|
||||
let view_item = self.parse_use();
|
||||
self.expect(token::SEMI);
|
||||
return iovi_view_item(@{
|
||||
return iovi_view_item(@ast::view_item {
|
||||
node: view_item,
|
||||
attrs: attrs,
|
||||
vis: visibility,
|
||||
@ -3582,7 +3582,7 @@ impl Parser {
|
||||
} else if self.eat_keyword(~"export") {
|
||||
let view_paths = self.parse_view_paths();
|
||||
self.expect(token::SEMI);
|
||||
return iovi_view_item(@{
|
||||
return iovi_view_item(@ast::view_item {
|
||||
node: view_item_export(view_paths),
|
||||
attrs: attrs,
|
||||
vis: visibility,
|
||||
@ -3780,8 +3780,10 @@ impl Parser {
|
||||
fail;
|
||||
};
|
||||
self.expect(token::SEMI);
|
||||
@{node: node, attrs: attrs,
|
||||
vis: vis, span: mk_sp(lo, self.last_span.hi)}
|
||||
@ast::view_item { node: node,
|
||||
attrs: attrs,
|
||||
vis: vis,
|
||||
span: mk_sp(lo, self.last_span.hi) }
|
||||
}
|
||||
|
||||
fn parse_items_and_view_items(+first_item_attrs: ~[attribute],
|
||||
|
Loading…
x
Reference in New Issue
Block a user