Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ast attributes every where (remove HIR attributes). #28399

Merged
merged 1 commit into from
Sep 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/front/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use metadata::inline::InlinedItem as II;
use middle::def_id::DefId;

use syntax::abi;
use syntax::ast::{Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
use syntax::ast::{self, Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
use syntax::codemap::{Span, Spanned};
use syntax::parse::token;

Expand Down Expand Up @@ -538,7 +538,7 @@ impl<'ast> Map<'ast> {

/// Given a node ID, get a list of of attributes associated with the AST
/// corresponding to the Node ID
pub fn attrs(&self, id: NodeId) -> &'ast [Attribute] {
pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] {
let attrs = match self.find(id) {
Some(NodeItem(i)) => Some(&i.attrs[..]),
Some(NodeForeignItem(fi)) => Some(&fi.attrs[..]),
Expand Down
48 changes: 7 additions & 41 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ use std::cell::RefCell;
use std::cmp;
use std::mem;
use syntax::ast_util::IdVisitingOperation;
use rustc_front::attr::{self, AttrMetaMethods};
use rustc_front::util;
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::Span;
use syntax::parse::token::InternedString;
use syntax::ast;
use rustc_front::hir;
use rustc_front::visit::{self, Visitor, FnKind};
use rustc_front::util;
use syntax::visit::Visitor as SyntaxVisitor;
use syntax::diagnostic;

Expand Down Expand Up @@ -286,7 +286,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $($args:expr),*) => ({
/// Parse the lint attributes into a vector, with `Err`s for malformed lint
/// attributes. Writing this as an iterator is an enormous mess.
// See also the hir version just below.
pub fn gather_attrs(attrs: &[hir::Attribute])
pub fn gather_attrs(attrs: &[ast::Attribute])
-> Vec<Result<(InternedString, Level, Span), Span>> {
let mut out = vec!();
for attr in attrs {
Expand All @@ -299,39 +299,7 @@ pub fn gather_attrs(attrs: &[hir::Attribute])

let meta = &attr.node.value;
let metas = match meta.node {
hir::MetaList(_, ref metas) => metas,
_ => {
out.push(Err(meta.span));
continue;
}
};

for meta in metas {
out.push(match meta.node {
hir::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
_ => Err(meta.span),
});
}
}
out
}
// Copy-pasted from the above function :-(
pub fn gather_attrs_from_hir(attrs: &[::rustc_front::hir::Attribute])
-> Vec<Result<(InternedString, Level, Span), Span>> {
use ::rustc_front::attr::AttrMetaMethods;

let mut out = vec!();
for attr in attrs {
let level = match Level::from_str(&attr.name()) {
None => continue,
Some(lvl) => lvl,
};

::rustc_front::attr::mark_used(attr);

let meta = &attr.node.value;
let metas = match meta.node {
::rustc_front::hir::MetaList(_, ref metas) => metas,
ast::MetaList(_, ref metas) => metas,
_ => {
out.push(Err(meta.span));
continue;
Expand All @@ -340,9 +308,7 @@ pub fn gather_attrs_from_hir(attrs: &[::rustc_front::hir::Attribute])

for meta in metas {
out.push(match meta.node {
::rustc_front::hir::MetaWord(ref lint_name) => {
Ok((lint_name.clone(), level, meta.span))
}
ast::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
_ => Err(meta.span),
});
}
Expand Down Expand Up @@ -454,7 +420,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
/// current lint context, call the provided function, then reset the
/// lints in effect to their previous state.
fn with_lint_attrs<F>(&mut self,
attrs: &[hir::Attribute],
attrs: &[ast::Attribute],
f: F) where
F: FnOnce(&mut Context),
{
Expand Down Expand Up @@ -675,7 +641,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
visit::walk_path(self, p);
}

fn visit_attribute(&mut self, attr: &hir::Attribute) {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
run_lints!(self, check_attribute, attr);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use syntax::ast;
use rustc_front::hir;

pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs,
gather_attrs_from_hir, GatherNodeLevels};
GatherNodeLevels};

/// Specification of a single lint.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -158,14 +158,14 @@ pub trait LintPass {
fn check_explicit_self(&mut self, _: &Context, _: &hir::ExplicitSelf) { }
fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
fn check_path(&mut self, _: &Context, _: &hir::Path, _: ast::NodeId) { }
fn check_attribute(&mut self, _: &Context, _: &hir::Attribute) { }
fn check_attribute(&mut self, _: &Context, _: &ast::Attribute) { }

/// Called when entering a syntax node that can have lint attributes such
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
fn enter_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
fn enter_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }

/// Counterpart to `enter_lint_attrs`.
fn exit_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
}

/// A lint pass boxed up as a trait object.
Expand Down
11 changes: 4 additions & 7 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ use syntax::abi;
use syntax::codemap::{self, Span, mk_sp, Pos};
use syntax::parse;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::parse::token::InternedString;
use syntax::util::small_vector::SmallVector;
use rustc_front::visit;
use rustc_front::hir;
use rustc_front::attr as attr_front;
use rustc_front::attr::AttrMetaMethods;
use rustc_front::lowering::unlower_attribute;
use log;

pub struct LocalCrateReader<'a, 'b:'a> {
Expand Down Expand Up @@ -79,10 +77,9 @@ fn dump_crates(cstore: &CStore) {
fn should_link(i: &ast::Item) -> bool {
!attr::contains_name(&i.attrs, "no_link")
}

// Dup for the hir
fn should_link_hir(i: &hir::Item) -> bool {
!attr_front::contains_name(&i.attrs, "no_link")
!attr::contains_name(&i.attrs, "no_link")
}

struct CrateInfo {
Expand Down Expand Up @@ -329,7 +326,7 @@ impl<'a> CrateReader<'a> {
let attrs = decoder::get_crate_attributes(data);
for attr in &attrs {
if &attr.name()[..] == "staged_api" {
match attr.node.value.node { hir::MetaWord(_) => return true, _ => (/*pass*/) }
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
}
}

Expand Down Expand Up @@ -483,7 +480,7 @@ impl<'a> CrateReader<'a> {
p.abort_if_errors();
macros.push(ast::MacroDef {
ident: name.ident(),
attrs: attrs.iter().map(|a| unlower_attribute(a)).collect(),
attrs: attrs,
id: ast::DUMMY_NODE_ID,
span: span,
imported_from: Some(item.ident),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use util::nodemap::FnvHashMap;

use std::rc::Rc;
use syntax::ast;
use rustc_front::attr;
use syntax::attr;
use rustc_front::hir;

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn get_methods_if_impl(cstore: &cstore::CStore,

pub fn get_item_attrs(cstore: &cstore::CStore,
def_id: DefId)
-> Vec<hir::Attribute> {
-> Vec<ast::Attribute> {
let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_item_attrs(&*cdata, def_id.node)
}
Expand All @@ -197,7 +197,7 @@ pub fn get_struct_field_names(cstore: &cstore::CStore, def: DefId) -> Vec<ast::N
}

pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: DefId) -> FnvHashMap<ast::NodeId,
Vec<hir::Attribute>> {
Vec<ast::Attribute>> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_struct_field_attrs(&*cdata)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::rc::Rc;
use std::path::PathBuf;
use flate::Bytes;
use syntax::ast;
use rustc_front::attr;
use syntax::attr;
use syntax::codemap;
use syntax::parse::token;
use syntax::parse::token::IdentInterner;
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub use self::DefLike::*;
use self::Family::*;

use front::map as ast_map;
use rustc_front::print::pprust;
use rustc_front::hir;

use back::svh::Svh;
Expand Down Expand Up @@ -46,12 +45,13 @@ use std::str;
use rbml::reader;
use rbml;
use serialize::Decodable;
use rustc_front::attr;
use syntax::attr;
use syntax::parse::token::{IdentInterner, special_idents};
use syntax::parse::token;
use syntax::ast;
use syntax::abi;
use syntax::codemap;
use syntax::print::pprust;
use syntax::ptr::P;


Expand Down Expand Up @@ -1041,7 +1041,7 @@ pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,

pub fn get_item_attrs(cdata: Cmd,
orig_node_id: ast::NodeId)
-> Vec<hir::Attribute> {
-> Vec<ast::Attribute> {
// The attributes for a tuple struct are attached to the definition, not the ctor;
// we assume that someone passing in a tuple struct ctor is actually wanting to
// look at the definition
Expand All @@ -1051,7 +1051,7 @@ pub fn get_item_attrs(cdata: Cmd,
get_attributes(item)
}

pub fn get_struct_field_attrs(cdata: Cmd) -> FnvHashMap<ast::NodeId, Vec<hir::Attribute>> {
pub fn get_struct_field_attrs(cdata: Cmd) -> FnvHashMap<ast::NodeId, Vec<ast::Attribute>> {
let data = rbml::Doc::new(cdata.data());
let fields = reader::get_doc(data, tag_struct_fields);
reader::tagged_docs(fields, tag_struct_field).map(|field| {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId)
})).collect()
}

fn get_meta_items(md: rbml::Doc) -> Vec<P<hir::MetaItem>> {
fn get_meta_items(md: rbml::Doc) -> Vec<P<ast::MetaItem>> {
reader::tagged_docs(md, tag_meta_item_word).map(|meta_item_doc| {
let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
let n = token::intern_and_get_ident(nd.as_str_slice());
Expand All @@ -1100,7 +1100,7 @@ fn get_meta_items(md: rbml::Doc) -> Vec<P<hir::MetaItem>> {
})).collect()
}

fn get_attributes(md: rbml::Doc) -> Vec<hir::Attribute> {
fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
match reader::maybe_get_doc(md, tag_attributes) {
Some(attrs_d) => {
reader::tagged_docs(attrs_d, tag_attribute).map(|attr_doc| {
Expand All @@ -1113,9 +1113,9 @@ fn get_attributes(md: rbml::Doc) -> Vec<hir::Attribute> {
assert_eq!(meta_items.len(), 1);
let meta_item = meta_items.into_iter().nth(0).unwrap();
codemap::Spanned {
node: hir::Attribute_ {
node: ast::Attribute_ {
id: attr::mk_attr_id(),
style: hir::AttrOuter,
style: ast::AttrOuter,
value: meta_item,
is_sugared_doc: is_sugared_doc,
},
Expand All @@ -1139,7 +1139,7 @@ fn list_crate_attributes(md: rbml::Doc, hash: &Svh,
write!(out, "\n\n")
}

pub fn get_crate_attributes(data: &[u8]) -> Vec<hir::Attribute> {
pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> {
get_attributes(rbml::Doc::new(data))
}

Expand Down Expand Up @@ -1337,7 +1337,7 @@ pub fn get_plugin_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
}

pub fn each_exported_macro<F>(data: &[u8], intr: &IdentInterner, mut f: F) where
F: FnMut(ast::Name, Vec<hir::Attribute>, String) -> bool,
F: FnMut(ast::Name, Vec<ast::Attribute>, String) -> bool,
{
let macros = reader::get_doc(rbml::Doc::new(data), tag_macro_defs);
for macro_doc in reader::tagged_docs(macros, tag_macro_def) {
Expand Down
Loading