libsyntax: Convert ast::attribute_ to store a @meta_item
This commit is contained in:
parent
b26d434ad1
commit
5b9e110eab
14 changed files with 28 additions and 27 deletions
|
@ -358,7 +358,7 @@ pub mod test {
|
||||||
pub fn make_crate_type_attr(+t: ~str) -> ast::attribute {
|
pub fn make_crate_type_attr(+t: ~str) -> ast::attribute {
|
||||||
codemap::respan(codemap::dummy_sp(), ast::attribute_ {
|
codemap::respan(codemap::dummy_sp(), ast::attribute_ {
|
||||||
style: ast::attr_outer,
|
style: ast::attr_outer,
|
||||||
value: codemap::respan(codemap::dummy_sp(),
|
value: @codemap::respan(codemap::dummy_sp(),
|
||||||
ast::meta_name_value(
|
ast::meta_name_value(
|
||||||
@~"crate_type",
|
@~"crate_type",
|
||||||
codemap::respan(codemap::dummy_sp(),
|
codemap::respan(codemap::dummy_sp(),
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn inject_libcore_ref(sess: Session,
|
||||||
attrs: ~[
|
attrs: ~[
|
||||||
spanned(ast::attribute_ {
|
spanned(ast::attribute_ {
|
||||||
style: ast::attr_inner,
|
style: ast::attr_inner,
|
||||||
value: spanned(ast::meta_name_value(
|
value: @spanned(ast::meta_name_value(
|
||||||
@~"vers",
|
@~"vers",
|
||||||
spanned(ast::lit_str(@CORE_VERSION.to_str()))
|
spanned(ast::lit_str(@CORE_VERSION.to_str()))
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -994,7 +994,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
|
||||||
codemap::spanned {
|
codemap::spanned {
|
||||||
node: ast::attribute_ {
|
node: ast::attribute_ {
|
||||||
style: ast::attr_outer,
|
style: ast::attr_outer,
|
||||||
value: /*bad*/copy *meta_item,
|
value: meta_item,
|
||||||
is_sugared_doc: false,
|
is_sugared_doc: false,
|
||||||
},
|
},
|
||||||
span: codemap::dummy_sp()
|
span: codemap::dummy_sp()
|
||||||
|
|
|
@ -1020,7 +1020,7 @@ fn write_int(writer: io::Writer, &&n: int) {
|
||||||
writer.write_be_u32(n as u32);
|
writer.write_be_u32(n as u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_meta_item(ebml_w: writer::Encoder, mi: meta_item) {
|
fn encode_meta_item(ebml_w: writer::Encoder, mi: @meta_item) {
|
||||||
match mi.node {
|
match mi.node {
|
||||||
meta_word(name) => {
|
meta_word(name) => {
|
||||||
ebml_w.start_tag(tag_meta_item_word);
|
ebml_w.start_tag(tag_meta_item_word);
|
||||||
|
@ -1050,7 +1050,7 @@ fn encode_meta_item(ebml_w: writer::Encoder, mi: meta_item) {
|
||||||
ebml_w.writer.write(str::to_bytes(*name));
|
ebml_w.writer.write(str::to_bytes(*name));
|
||||||
ebml_w.end_tag();
|
ebml_w.end_tag();
|
||||||
for items.each |inner_item| {
|
for items.each |inner_item| {
|
||||||
encode_meta_item(ebml_w, **inner_item);
|
encode_meta_item(ebml_w, *inner_item);
|
||||||
}
|
}
|
||||||
ebml_w.end_tag();
|
ebml_w.end_tag();
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,7 +316,7 @@ struct LanguageItemCollector {
|
||||||
|
|
||||||
impl LanguageItemCollector {
|
impl LanguageItemCollector {
|
||||||
fn match_and_collect_meta_item(&self, item_def_id: def_id,
|
fn match_and_collect_meta_item(&self, item_def_id: def_id,
|
||||||
meta_item: meta_item) {
|
meta_item: @meta_item) {
|
||||||
match meta_item.node {
|
match meta_item.node {
|
||||||
meta_name_value(key, literal) => {
|
meta_name_value(key, literal) => {
|
||||||
match literal.node {
|
match literal.node {
|
||||||
|
@ -368,10 +368,10 @@ impl LanguageItemCollector {
|
||||||
visit_item: |item| {
|
visit_item: |item| {
|
||||||
for item.attrs.each |attribute| {
|
for item.attrs.each |attribute| {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*this).match_and_collect_meta_item(local_def(item
|
(*this).match_and_collect_meta_item(
|
||||||
.id),
|
local_def(item.id),
|
||||||
attribute.node
|
attribute.node.value
|
||||||
.value);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1142,7 +1142,7 @@ pub enum attr_style { attr_outer, attr_inner, }
|
||||||
#[deriving_eq]
|
#[deriving_eq]
|
||||||
pub struct attribute_ {
|
pub struct attribute_ {
|
||||||
style: attr_style,
|
style: attr_style,
|
||||||
value: meta_item,
|
value: @meta_item,
|
||||||
is_sugared_doc: bool,
|
is_sugared_doc: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,16 +51,17 @@ pub fn mk_word_item(name: @~str) -> @ast::meta_item {
|
||||||
|
|
||||||
pub fn mk_attr(item: @ast::meta_item) -> ast::attribute {
|
pub fn mk_attr(item: @ast::meta_item) -> ast::attribute {
|
||||||
dummy_spanned(ast::attribute_ { style: ast::attr_inner,
|
dummy_spanned(ast::attribute_ { style: ast::attr_inner,
|
||||||
value: *item,
|
value: item,
|
||||||
is_sugared_doc: false })
|
is_sugared_doc: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_sugared_doc_attr(text: ~str,
|
pub fn mk_sugared_doc_attr(+text: ~str,
|
||||||
+lo: BytePos, +hi: BytePos) -> ast::attribute {
|
+lo: BytePos, +hi: BytePos) -> ast::attribute {
|
||||||
|
let style = doc_comment_style(text);
|
||||||
let lit = spanned(lo, hi, ast::lit_str(@text));
|
let lit = spanned(lo, hi, ast::lit_str(@text));
|
||||||
let attr = ast::attribute_ {
|
let attr = ast::attribute_ {
|
||||||
style: doc_comment_style(text),
|
style: style,
|
||||||
value: spanned(lo, hi, ast::meta_name_value(@~"doc", lit)),
|
value: @spanned(lo, hi, ast::meta_name_value(@~"doc", lit)),
|
||||||
is_sugared_doc: true
|
is_sugared_doc: true
|
||||||
};
|
};
|
||||||
spanned(lo, hi, attr)
|
spanned(lo, hi, attr)
|
||||||
|
@ -69,7 +70,7 @@ pub fn mk_sugared_doc_attr(text: ~str,
|
||||||
/* Conversion */
|
/* Conversion */
|
||||||
|
|
||||||
pub fn attr_meta(attr: ast::attribute) -> @ast::meta_item {
|
pub fn attr_meta(attr: ast::attribute) -> @ast::meta_item {
|
||||||
@attr.node.value
|
attr.node.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the meta_items from inside a vector of attributes
|
// Get the meta_items from inside a vector of attributes
|
||||||
|
@ -79,7 +80,7 @@ pub fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
|
||||||
|
|
||||||
pub fn desugar_doc_attr(attr: &ast::attribute) -> ast::attribute {
|
pub fn desugar_doc_attr(attr: &ast::attribute) -> ast::attribute {
|
||||||
if attr.node.is_sugared_doc {
|
if attr.node.is_sugared_doc {
|
||||||
let comment = get_meta_item_value_str(@attr.node.value).get();
|
let comment = get_meta_item_value_str(attr.node.value).get();
|
||||||
let meta = mk_name_value_item_str(@~"doc",
|
let meta = mk_name_value_item_str(@~"doc",
|
||||||
@strip_doc_comment_decoration(*comment));
|
@strip_doc_comment_decoration(*comment));
|
||||||
mk_attr(meta)
|
mk_attr(meta)
|
||||||
|
@ -91,7 +92,7 @@ pub fn desugar_doc_attr(attr: &ast::attribute) -> ast::attribute {
|
||||||
/* Accessors */
|
/* Accessors */
|
||||||
|
|
||||||
pub pure fn get_attr_name(attr: &ast::attribute) -> @~str {
|
pub pure fn get_attr_name(attr: &ast::attribute) -> @~str {
|
||||||
get_meta_item_name(@attr.node.value)
|
get_meta_item_name(attr.node.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn get_meta_item_name(meta: @ast::meta_item) -> @~str {
|
pub pure fn get_meta_item_name(meta: @ast::meta_item) -> @~str {
|
||||||
|
|
|
@ -110,7 +110,7 @@ mod syntax {
|
||||||
pub fn expand_auto_encode(
|
pub fn expand_auto_encode(
|
||||||
cx: ext_ctxt,
|
cx: ext_ctxt,
|
||||||
span: span,
|
span: span,
|
||||||
_mitem: ast::meta_item,
|
_mitem: @ast::meta_item,
|
||||||
in_items: ~[@ast::item]
|
in_items: ~[@ast::item]
|
||||||
) -> ~[@ast::item] {
|
) -> ~[@ast::item] {
|
||||||
fn is_auto_encode(a: &ast::attribute) -> bool {
|
fn is_auto_encode(a: &ast::attribute) -> bool {
|
||||||
|
@ -165,7 +165,7 @@ pub fn expand_auto_encode(
|
||||||
pub fn expand_auto_decode(
|
pub fn expand_auto_decode(
|
||||||
cx: ext_ctxt,
|
cx: ext_ctxt,
|
||||||
span: span,
|
span: span,
|
||||||
_mitem: ast::meta_item,
|
_mitem: @ast::meta_item,
|
||||||
in_items: ~[@ast::item]
|
in_items: ~[@ast::item]
|
||||||
) -> ~[@ast::item] {
|
) -> ~[@ast::item] {
|
||||||
fn is_auto_decode(a: &ast::attribute) -> bool {
|
fn is_auto_decode(a: &ast::attribute) -> bool {
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub struct MacroDef {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ItemDecorator =
|
pub type ItemDecorator =
|
||||||
fn@(ext_ctxt, span, ast::meta_item, ~[@ast::item]) -> ~[@ast::item];
|
fn@(ext_ctxt, span, @ast::meta_item, ~[@ast::item]) -> ~[@ast::item];
|
||||||
|
|
||||||
pub struct SyntaxExpanderTT {
|
pub struct SyntaxExpanderTT {
|
||||||
expander: SyntaxExpanderTTFun,
|
expander: SyntaxExpanderTTFun,
|
||||||
|
|
|
@ -58,7 +58,7 @@ type ExpandDerivingEnumDefFn = &fn(ext_ctxt,
|
||||||
|
|
||||||
pub fn expand_deriving_eq(cx: ext_ctxt,
|
pub fn expand_deriving_eq(cx: ext_ctxt,
|
||||||
span: span,
|
span: span,
|
||||||
_mitem: meta_item,
|
_mitem: @meta_item,
|
||||||
in_items: ~[@item])
|
in_items: ~[@item])
|
||||||
-> ~[@item] {
|
-> ~[@item] {
|
||||||
expand_deriving(cx,
|
expand_deriving(cx,
|
||||||
|
@ -70,7 +70,7 @@ pub fn expand_deriving_eq(cx: ext_ctxt,
|
||||||
|
|
||||||
pub fn expand_deriving_iter_bytes(cx: ext_ctxt,
|
pub fn expand_deriving_iter_bytes(cx: ext_ctxt,
|
||||||
span: span,
|
span: span,
|
||||||
_mitem: meta_item,
|
_mitem: @meta_item,
|
||||||
in_items: ~[@item])
|
in_items: ~[@item])
|
||||||
-> ~[@item] {
|
-> ~[@item] {
|
||||||
expand_deriving(cx,
|
expand_deriving(cx,
|
||||||
|
|
|
@ -227,7 +227,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
|
||||||
// Rust coding conventions
|
// Rust coding conventions
|
||||||
let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ {
|
let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ {
|
||||||
style: ast::attr_outer,
|
style: ast::attr_outer,
|
||||||
value: respan(dummy_sp(),
|
value: @respan(dummy_sp(),
|
||||||
ast::meta_list(@~"allow", ~[
|
ast::meta_list(@~"allow", ~[
|
||||||
@respan(dummy_sp(),
|
@respan(dummy_sp(),
|
||||||
ast::meta_word(
|
ast::meta_word(
|
||||||
|
|
|
@ -98,7 +98,7 @@ fn fold_attribute_(at: attribute, fld: ast_fold) -> attribute {
|
||||||
spanned {
|
spanned {
|
||||||
node: ast::attribute_ {
|
node: ast::attribute_ {
|
||||||
style: at.node.style,
|
style: at.node.style,
|
||||||
value: *fold_meta_item_(@at.node.value, fld),
|
value: fold_meta_item_(at.node.value, fld),
|
||||||
is_sugared_doc: at.node.is_sugared_doc,
|
is_sugared_doc: at.node.is_sugared_doc,
|
||||||
},
|
},
|
||||||
span: fld.new_span(at.span),
|
span: fld.new_span(at.span),
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl parser_attr for Parser {
|
||||||
self.expect(token::RBRACKET);
|
self.expect(token::RBRACKET);
|
||||||
let mut hi = self.span.hi;
|
let mut hi = self.span.hi;
|
||||||
return spanned(lo, hi, ast::attribute_ { style: style,
|
return spanned(lo, hi, ast::attribute_ { style: style,
|
||||||
value: *meta_item,
|
value: meta_item,
|
||||||
is_sugared_doc: false });
|
is_sugared_doc: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -904,7 +904,7 @@ pub fn print_attribute(s: @ps, attr: ast::attribute) {
|
||||||
word(s.s, *comment);
|
word(s.s, *comment);
|
||||||
} else {
|
} else {
|
||||||
word(s.s, ~"#[");
|
word(s.s, ~"#[");
|
||||||
print_meta_item(s, @attr.node.value);
|
print_meta_item(s, attr.node.value);
|
||||||
word(s.s, ~"]");
|
word(s.s, ~"]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue