summary refs log tree commit diff
path: root/src/libsyntax/print/pprust.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-20 20:25:31 -0700
committerbors <bors@rust-lang.org>2013-07-20 20:25:31 -0700
commitd029ebfc5f69f830fe24b4c8a979970d9a7d297d (patch)
tree80d9e825ff9f805d15c98441560c6decf85f0739 /src/libsyntax/print/pprust.rs
parent8476419fefda988f66ab6b2a1847e402133a0a29 (diff)
parentcc760a647ac0094814f592d08813ebae0b3bec47 (diff)
downloadrust-d029ebfc5f69f830fe24b4c8a979970d9a7d297d.tar.gz
rust-d029ebfc5f69f830fe24b4c8a979970d9a7d297d.zip
auto merge of #7902 : huonw/rust/attr++, r=cmr,pcwalton
This does a number of things, but especially dramatically reduce the
number of allocations performed for operations involving attributes/
meta items:

- Converts ast::meta_item & ast::attribute and other associated enums
  to CamelCase.
- Converts several standalone functions in syntax::attr into methods,
  defined on two traits AttrMetaMethods & AttributeMethods. The former
  is common to both MetaItem and Attribute since the latter is a thin
  wrapper around the former.
- Deletes functions that are unnecessary due to iterators.
- Converts other standalone functions to use iterators and the generic
  AttrMetaMethods rather than allocating a lot of new vectors (e.g. the
  old code would have to allocate a new vector to use functions that
  operated on &[meta_item] on &[attribute].)
- Moves the core algorithm of the #[cfg] matching to syntax::attr,
  similar to find_inline_attr and find_linkage_metas.

This doesn't have much of an effect on the speed of #[cfg] stripping,
despite hugely reducing the number of allocations performed; presumably
most of the time is spent in the ast folder rather than doing attribute
checks.

Also fixes the Eq instance of MetaItem_ to correctly ignore spans, so
that `rustc --cfg 'foo(bar)'` now works.
Diffstat (limited to 'src/libsyntax/print/pprust.rs')
-rw-r--r--src/libsyntax/print/pprust.rs37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index f88b7b9a1f8..a74b89ce5f5 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -14,7 +14,7 @@ use ast;
 use ast_util;
 use opt_vec::OptVec;
 use opt_vec;
-use attr;
+use attr::{AttrMetaMethods, AttributeMethods};
 use codemap::{CodeMap, BytePos};
 use codemap;
 use diagnostic;
@@ -212,11 +212,11 @@ pub fn block_to_str(blk: &ast::blk, intr: @ident_interner) -> ~str {
     }
 }
 
-pub fn meta_item_to_str(mi: &ast::meta_item, intr: @ident_interner) -> ~str {
+pub fn meta_item_to_str(mi: &ast::MetaItem, intr: @ident_interner) -> ~str {
     to_str(mi, print_meta_item, intr)
 }
 
-pub fn attribute_to_str(attr: &ast::attribute, intr: @ident_interner) -> ~str {
+pub fn attribute_to_str(attr: &ast::Attribute, intr: @ident_interner) -> ~str {
     to_str(attr, print_attribute, intr)
 }
 
@@ -352,7 +352,7 @@ pub fn commasep_exprs(s: @ps, b: breaks, exprs: &[@ast::expr]) {
     commasep_cmnt(s, b, exprs, |p, &e| print_expr(p, e), |e| e.span);
 }
 
-pub fn print_mod(s: @ps, _mod: &ast::_mod, attrs: &[ast::attribute]) {
+pub fn print_mod(s: @ps, _mod: &ast::_mod, attrs: &[ast::Attribute]) {
     print_inner_attributes(s, attrs);
     for _mod.view_items.iter().advance |vitem| {
         print_view_item(s, vitem);
@@ -361,7 +361,7 @@ pub fn print_mod(s: @ps, _mod: &ast::_mod, attrs: &[ast::attribute]) {
 }
 
 pub fn print_foreign_mod(s: @ps, nmod: &ast::foreign_mod,
-                         attrs: &[ast::attribute]) {
+                         attrs: &[ast::Attribute]) {
     print_inner_attributes(s, attrs);
     for nmod.view_items.iter().advance |vitem| {
         print_view_item(s, vitem);
@@ -843,22 +843,22 @@ pub fn print_method(s: @ps, meth: &ast::method) {
     print_block_with_attrs(s, &meth.body, meth.attrs);
 }
 
-pub fn print_outer_attributes(s: @ps, attrs: &[ast::attribute]) {
+pub fn print_outer_attributes(s: @ps, attrs: &[ast::Attribute]) {
     let mut count = 0;
     for attrs.iter().advance |attr| {
         match attr.node.style {
-          ast::attr_outer => { print_attribute(s, attr); count += 1; }
+          ast::AttrOuter => { print_attribute(s, attr); count += 1; }
           _ => {/* fallthrough */ }
         }
     }
     if count > 0 { hardbreak_if_not_bol(s); }
 }
 
-pub fn print_inner_attributes(s: @ps, attrs: &[ast::attribute]) {
+pub fn print_inner_attributes(s: @ps, attrs: &[ast::Attribute]) {
     let mut count = 0;
     for attrs.iter().advance |attr| {
         match attr.node.style {
-          ast::attr_inner => {
+          ast::AttrInner => {
             print_attribute(s, attr);
             if !attr.node.is_sugared_doc {
                 word(s.s, ";");
@@ -871,16 +871,15 @@ pub fn print_inner_attributes(s: @ps, attrs: &[ast::attribute]) {
     if count > 0 { hardbreak_if_not_bol(s); }
 }
 
-pub fn print_attribute(s: @ps, attr: &ast::attribute) {
+pub fn print_attribute(s: @ps, attr: &ast::Attribute) {
     hardbreak_if_not_bol(s);
     maybe_print_comment(s, attr.span.lo);
     if attr.node.is_sugared_doc {
-        let meta = attr::attr_meta(*attr);
-        let comment = attr::get_meta_item_value_str(meta).get();
+        let comment = attr.value_str().get();
         word(s.s, comment);
     } else {
         word(s.s, "#[");
-        print_meta_item(s, attr.node.value);
+        print_meta_item(s, attr.meta());
         word(s.s, "]");
     }
 }
@@ -927,7 +926,7 @@ pub fn print_block_unclosed_indent(s: @ps, blk: &ast::blk, indented: uint) {
 
 pub fn print_block_with_attrs(s: @ps,
                               blk: &ast::blk,
-                              attrs: &[ast::attribute]) {
+                              attrs: &[ast::Attribute]) {
     print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs,
                                   true);
 }
@@ -946,7 +945,7 @@ pub fn print_possibly_embedded_block_(s: @ps,
                                       blk: &ast::blk,
                                       embedded: embed_type,
                                       indented: uint,
-                                      attrs: &[ast::attribute],
+                                      attrs: &[ast::Attribute],
                                       close_box: bool) {
     match blk.rules {
       ast::unsafe_blk => word_space(s, "unsafe"),
@@ -1793,16 +1792,16 @@ pub fn print_generics(s: @ps, generics: &ast::Generics) {
     }
 }
 
-pub fn print_meta_item(s: @ps, item: &ast::meta_item) {
+pub fn print_meta_item(s: @ps, item: &ast::MetaItem) {
     ibox(s, indent_unit);
     match item.node {
-      ast::meta_word(name) => word(s.s, name),
-      ast::meta_name_value(name, value) => {
+      ast::MetaWord(name) => word(s.s, name),
+      ast::MetaNameValue(name, value) => {
         word_space(s, name);
         word_space(s, "=");
         print_literal(s, @value);
       }
-      ast::meta_list(name, ref items) => {
+      ast::MetaList(name, ref items) => {
         word(s.s, name);
         popen(s);
         commasep(s,