diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-07-31 00:04:06 -0700 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-09-03 10:02:36 +1200 |
| commit | facdf2ebb1dce9400a8c8ef0d85d7d278654effb (patch) | |
| tree | 3ba46bd98df35b4b5d1bc5f1ba491d14adb6f373 /src/librustc/metadata | |
| parent | cfd76b364cd01695517467299618ef63f1c0cc07 (diff) | |
| download | rust-facdf2ebb1dce9400a8c8ef0d85d7d278654effb.tar.gz rust-facdf2ebb1dce9400a8c8ef0d85d7d278654effb.zip | |
Add an intital HIR and lowering step
Diffstat (limited to 'src/librustc/metadata')
| -rw-r--r-- | src/librustc/metadata/creader.rs | 77 | ||||
| -rw-r--r-- | src/librustc/metadata/csearch.rs | 17 | ||||
| -rw-r--r-- | src/librustc/metadata/cstore.rs | 4 | ||||
| -rw-r--r-- | src/librustc/metadata/decoder.rs | 81 | ||||
| -rw-r--r-- | src/librustc/metadata/encoder.rs | 40 | ||||
| -rw-r--r-- | src/librustc/metadata/inline.rs | 27 | ||||
| -rw-r--r-- | src/librustc/metadata/macro_import.rs | 5 | ||||
| -rw-r--r-- | src/librustc/metadata/tydecode.rs | 14 | ||||
| -rw-r--r-- | src/librustc/metadata/tyencode.rs | 39 |
9 files changed, 173 insertions, 131 deletions
diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 3f182b4d2b5..d758b253441 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -21,6 +21,7 @@ use metadata::decoder; use metadata::loader; use metadata::loader::CratePaths; use util::nodemap::FnvHashMap; +use front::map as hir_map; use std::cell::{RefCell, Cell}; use std::path::PathBuf; @@ -29,20 +30,22 @@ use std::fs; use syntax::ast; use syntax::abi; -use syntax::attr; -use syntax::attr::AttrMetaMethods; use syntax::codemap::{self, Span, mk_sp, Pos}; use syntax::parse; +use syntax::attr; use syntax::parse::token::InternedString; -use syntax::visit; use syntax::util::small_vector::SmallVector; -use ast_map; +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> { sess: &'a Session, creader: CrateReader<'a>, - ast_map: &'a ast_map::Map<'b>, + ast_map: &'a hir_map::Map<'b>, } pub struct CrateReader<'a> { @@ -52,7 +55,7 @@ pub struct CrateReader<'a> { } impl<'a, 'b, 'v> visit::Visitor<'v> for LocalCrateReader<'a, 'b> { - fn visit_item(&mut self, a: &ast::Item) { + fn visit_item(&mut self, a: &hir::Item) { self.process_item(a); visit::walk_item(self, a); } @@ -77,6 +80,11 @@ 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") +} + struct CrateInfo { ident: String, name: String, @@ -188,6 +196,31 @@ impl<'a> CrateReader<'a> { } } + // Dup of the above, but for the hir + fn extract_crate_info_hir(&self, i: &hir::Item) -> Option<CrateInfo> { + match i.node { + hir::ItemExternCrate(ref path_opt) => { + debug!("resolving extern crate stmt. ident: {} path_opt: {:?}", + i.ident, path_opt); + let name = match *path_opt { + Some(name) => { + validate_crate_name(Some(self.sess), &name.as_str(), + Some(i.span)); + name.to_string() + } + None => i.ident.to_string(), + }; + Some(CrateInfo { + ident: i.ident.to_string(), + name: name, + id: i.id, + should_link: should_link_hir(i), + }) + } + _ => None + } + } + fn existing_match(&self, name: &str, hash: Option<&Svh>, kind: PathKind) -> Option<ast::CrateNum> { let mut ret = None; @@ -295,7 +328,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 { ast::MetaWord(_) => return true, _ => (/*pass*/) } + match attr.node.value.node { hir::MetaWord(_) => return true, _ => (/*pass*/) } } } @@ -425,11 +458,11 @@ impl<'a> CrateReader<'a> { } /// Read exported macros. - pub fn read_exported_macros(&mut self, krate: &ast::Item) -> Vec<ast::MacroDef> { - let ci = self.extract_crate_info(krate).unwrap(); - let ekrate = self.read_extension_crate(krate.span, &ci); + pub fn read_exported_macros(&mut self, item: &ast::Item) -> Vec<ast::MacroDef> { + let ci = self.extract_crate_info(item).unwrap(); + let ekrate = self.read_extension_crate(item.span, &ci); - let source_name = format!("<{} macros>", krate.ident); + let source_name = format!("<{} macros>", item.ident); let mut macros = vec![]; decoder::each_exported_macro(ekrate.metadata.as_slice(), &*self.sess.cstore.intr, @@ -449,10 +482,10 @@ impl<'a> CrateReader<'a> { p.abort_if_errors(); macros.push(ast::MacroDef { ident: name.ident(), - attrs: attrs, + attrs: attrs.iter().map(|a| unlower_attribute(a)).collect(), id: ast::DUMMY_NODE_ID, span: span, - imported_from: Some(krate.ident), + imported_from: Some(item.ident), // overridden in plugin/load.rs export: false, use_locally: false, @@ -639,7 +672,7 @@ impl<'a> CrateReader<'a> { } impl<'a, 'b> LocalCrateReader<'a, 'b> { - pub fn new(sess: &'a Session, map: &'a ast_map::Map<'b>) -> LocalCrateReader<'a, 'b> { + pub fn new(sess: &'a Session, map: &'a hir_map::Map<'b>) -> LocalCrateReader<'a, 'b> { LocalCrateReader { sess: sess, creader: CrateReader::new(sess), @@ -650,7 +683,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> { // Traverses an AST, reading all the information about use'd crates and // extern libraries necessary for later resolving, typechecking, linking, // etc. - pub fn read_crates(&mut self, krate: &ast::Crate) { + pub fn read_crates(&mut self, krate: &hir::Crate) { self.process_crate(krate); visit::walk_crate(self, krate); self.creader.inject_allocator_crate(); @@ -665,7 +698,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> { self.creader.register_statically_included_foreign_items(); } - fn process_crate(&self, c: &ast::Crate) { + fn process_crate(&self, c: &hir::Crate) { for a in c.attrs.iter().filter(|m| m.name() == "link_args") { match a.value_str() { Some(ref linkarg) => self.sess.cstore.add_used_link_args(&linkarg), @@ -674,14 +707,14 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> { } } - fn process_item(&mut self, i: &ast::Item) { + fn process_item(&mut self, i: &hir::Item) { match i.node { - ast::ItemExternCrate(_) => { - if !should_link(i) { + hir::ItemExternCrate(_) => { + if !should_link_hir(i) { return; } - match self.creader.extract_crate_info(i) { + match self.creader.extract_crate_info_hir(i) { Some(info) => { let (cnum, cmeta, _) = self.creader.resolve_crate(&None, &info.ident, @@ -698,12 +731,12 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> { None => () } } - ast::ItemForeignMod(ref fm) => self.process_foreign_mod(i, fm), + hir::ItemForeignMod(ref fm) => self.process_foreign_mod(i, fm), _ => { } } } - fn process_foreign_mod(&mut self, i: &ast::Item, fm: &ast::ForeignMod) { + fn process_foreign_mod(&mut self, i: &hir::Item, fm: &hir::ForeignMod) { if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic || fm.abi == abi::PlatformIntrinsic { return; } diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 79d98880164..91c7ac48918 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -10,7 +10,7 @@ // Searching for information from the cstore -use ast_map; +use front::map as ast_map; use metadata::common::*; use metadata::cstore; use metadata::decoder; @@ -23,7 +23,8 @@ use rbml; use rbml::reader; use std::rc::Rc; use syntax::ast; -use syntax::attr; +use rustc_front::attr; +use rustc_front::hir; use syntax::diagnostic::expect; use std::collections::hash_map::HashMap; @@ -32,7 +33,7 @@ use std::collections::hash_map::HashMap; pub struct MethodInfo { pub name: ast::Name, pub def_id: DefId, - pub vis: ast::Visibility, + pub vis: hir::Visibility, } pub fn get_symbol(cstore: &cstore::CStore, def: DefId) -> String { @@ -55,7 +56,7 @@ pub fn each_lang_item<F>(cstore: &cstore::CStore, pub fn each_child_of_item<F>(cstore: &cstore::CStore, def_id: DefId, callback: F) where - F: FnMut(decoder::DefLike, ast::Name, ast::Visibility), + F: FnMut(decoder::DefLike, ast::Name, hir::Visibility), { let crate_data = cstore.get_crate_data(def_id.krate); let get_crate_data = |cnum| { @@ -72,7 +73,7 @@ pub fn each_child_of_item<F>(cstore: &cstore::CStore, pub fn each_top_level_item_of_crate<F>(cstore: &cstore::CStore, cnum: ast::CrateNum, callback: F) where - F: FnMut(decoder::DefLike, ast::Name, ast::Visibility), + F: FnMut(decoder::DefLike, ast::Name, hir::Visibility), { let crate_data = cstore.get_crate_data(cnum); let get_crate_data = |cnum| { @@ -190,7 +191,7 @@ pub fn get_methods_if_impl(cstore: &cstore::CStore, pub fn get_item_attrs(cstore: &cstore::CStore, def_id: DefId) - -> Vec<ast::Attribute> { + -> Vec<hir::Attribute> { let cdata = cstore.get_crate_data(def_id.krate); decoder::get_item_attrs(&*cdata, def_id.node) } @@ -201,7 +202,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) -> HashMap<ast::NodeId, - Vec<ast::Attribute>> { + Vec<hir::Attribute>> { let cdata = cstore.get_crate_data(def.krate); decoder::get_struct_field_attrs(&*cdata) } @@ -269,7 +270,7 @@ pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: DefId, pub fn get_impl_polarity<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) - -> Option<ast::ImplPolarity> + -> Option<hir::ImplPolarity> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 9179a0a1871..838f78163f0 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -27,12 +27,12 @@ use std::rc::Rc; use std::path::PathBuf; use flate::Bytes; use syntax::ast; -use syntax::attr; +use rustc_front::attr; use syntax::codemap; use syntax::parse::token; use syntax::parse::token::IdentInterner; use syntax::util::small_vector::SmallVector; -use ast_map; +use front::map as ast_map; // A map from external crate numbers (as decoded from some crate file) to // local crate numbers (as generated during this session). Each external diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index bceccc622af..5991b79896b 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -15,7 +15,10 @@ pub use self::DefLike::*; use self::Family::*; -use ast_map; +use front::map as ast_map; +use rustc_front::print::pprust; +use rustc_front::hir; + use back::svh::Svh; use metadata::cstore::crate_metadata; use metadata::common::*; @@ -45,15 +48,15 @@ use std::str; use rbml::reader; use rbml; use serialize::Decodable; -use syntax::abi; -use syntax::attr; +use rustc_front::attr; use syntax::parse::token::{IdentInterner, special_idents}; use syntax::parse::token; -use syntax::print::pprust; use syntax::ast; +use syntax::abi; use syntax::codemap; use syntax::ptr::P; + pub type Cmd<'a> = &'a crate_metadata; // A function that takes a def_id relative to the crate being searched and @@ -158,26 +161,26 @@ fn item_family(item: rbml::Doc) -> Family { } } -fn item_visibility(item: rbml::Doc) -> ast::Visibility { +fn item_visibility(item: rbml::Doc) -> hir::Visibility { match reader::maybe_get_doc(item, tag_items_data_item_visibility) { - None => ast::Public, + None => hir::Public, Some(visibility_doc) => { match reader::doc_as_u8(visibility_doc) as char { - 'y' => ast::Public, - 'i' => ast::Inherited, + 'y' => hir::Public, + 'i' => hir::Inherited, _ => panic!("unknown visibility character") } } } } -fn fn_constness(item: rbml::Doc) -> ast::Constness { +fn fn_constness(item: rbml::Doc) -> hir::Constness { match reader::maybe_get_doc(item, tag_items_data_item_constness) { - None => ast::Constness::NotConst, + None => hir::Constness::NotConst, Some(constness_doc) => { match reader::doc_as_u8(constness_doc) as char { - 'c' => ast::Constness::Const, - 'n' => ast::Constness::NotConst, + 'c' => hir::Constness::Const, + 'n' => hir::Constness::NotConst, _ => panic!("unknown constness character") } } @@ -343,12 +346,12 @@ fn item_to_def_like(cdata: Cmd, item: rbml::Doc, did: DefId) -> DefLike { } } -fn parse_unsafety(item_doc: rbml::Doc) -> ast::Unsafety { +fn parse_unsafety(item_doc: rbml::Doc) -> hir::Unsafety { let unsafety_doc = reader::get_doc(item_doc, tag_unsafety); if reader::doc_as_u8(unsafety_doc) != 0 { - ast::Unsafety::Unsafe + hir::Unsafety::Unsafe } else { - ast::Unsafety::Normal + hir::Unsafety::Normal } } @@ -357,12 +360,12 @@ fn parse_paren_sugar(item_doc: rbml::Doc) -> bool { reader::doc_as_u8(paren_sugar_doc) != 0 } -fn parse_polarity(item_doc: rbml::Doc) -> ast::ImplPolarity { +fn parse_polarity(item_doc: rbml::Doc) -> hir::ImplPolarity { let polarity_doc = reader::get_doc(item_doc, tag_polarity); if reader::doc_as_u8(polarity_doc) != 0 { - ast::ImplPolarity::Negative + hir::ImplPolarity::Negative } else { - ast::ImplPolarity::Positive + hir::ImplPolarity::Positive } } @@ -560,7 +563,7 @@ pub fn get_repr_attrs(cdata: Cmd, id: ast::NodeId) -> Vec<attr::ReprAttr> { pub fn get_impl_polarity<'tcx>(cdata: Cmd, id: ast::NodeId) - -> Option<ast::ImplPolarity> + -> Option<hir::ImplPolarity> { let item_doc = lookup_item(id, cdata.data()); let fam = item_family(item_doc); @@ -633,7 +636,7 @@ fn each_child_of_item_or_crate<F, G>(intr: Rc<IdentInterner>, item_doc: rbml::Doc, mut get_crate_data: G, mut callback: F) where - F: FnMut(DefLike, ast::Name, ast::Visibility), + F: FnMut(DefLike, ast::Name, hir::Visibility), G: FnMut(ast::CrateNum) -> Rc<crate_metadata>, { // Iterate over all children. @@ -722,7 +725,7 @@ fn each_child_of_item_or_crate<F, G>(intr: Rc<IdentInterner>, let def_like = item_to_def_like(crate_data, child_item_doc, child_def_id); // These items have a public visibility because they're part of // a public re-export. - callback(def_like, token::intern(name), ast::Public); + callback(def_like, token::intern(name), hir::Public); } } } @@ -733,7 +736,7 @@ pub fn each_child_of_item<F, G>(intr: Rc<IdentInterner>, id: ast::NodeId, get_crate_data: G, callback: F) where - F: FnMut(DefLike, ast::Name, ast::Visibility), + F: FnMut(DefLike, ast::Name, hir::Visibility), G: FnMut(ast::CrateNum) -> Rc<crate_metadata>, { // Find the item. @@ -756,7 +759,7 @@ pub fn each_top_level_item_of_crate<F, G>(intr: Rc<IdentInterner>, cdata: Cmd, get_crate_data: G, callback: F) where - F: FnMut(DefLike, ast::Name, ast::Visibility), + F: FnMut(DefLike, ast::Name, hir::Visibility), G: FnMut(ast::CrateNum) -> Rc<crate_metadata>, { let root_doc = rbml::Doc::new(cdata.data()); @@ -810,10 +813,10 @@ pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeI } fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory { - fn get_mutability(ch: u8) -> ast::Mutability { + fn get_mutability(ch: u8) -> hir::Mutability { match ch as char { - 'i' => ast::MutImmutable, - 'm' => ast::MutMutable, + 'i' => hir::MutImmutable, + 'm' => hir::MutMutable, _ => panic!("unknown mutability character: `{}`", ch as char), } } @@ -1074,7 +1077,7 @@ pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd, pub fn get_item_attrs(cdata: Cmd, orig_node_id: ast::NodeId) - -> Vec<ast::Attribute> { + -> Vec<hir::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 @@ -1084,7 +1087,7 @@ pub fn get_item_attrs(cdata: Cmd, get_attributes(item) } -pub fn get_struct_field_attrs(cdata: Cmd) -> HashMap<ast::NodeId, Vec<ast::Attribute>> { +pub fn get_struct_field_attrs(cdata: Cmd) -> HashMap<ast::NodeId, Vec<hir::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| { @@ -1094,10 +1097,10 @@ pub fn get_struct_field_attrs(cdata: Cmd) -> HashMap<ast::NodeId, Vec<ast::Attri }).collect() } -fn struct_field_family_to_visibility(family: Family) -> ast::Visibility { +fn struct_field_family_to_visibility(family: Family) -> hir::Visibility { match family { - PublicField => ast::Public, - InheritedField => ast::Inherited, + PublicField => hir::Public, + InheritedField => hir::Inherited, _ => panic!() } } @@ -1113,7 +1116,7 @@ pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId) })).collect() } -fn get_meta_items(md: rbml::Doc) -> Vec<P<ast::MetaItem>> { +fn get_meta_items(md: rbml::Doc) -> Vec<P<hir::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()); @@ -1134,7 +1137,7 @@ fn get_meta_items(md: rbml::Doc) -> Vec<P<ast::MetaItem>> { })).collect() } -fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> { +fn get_attributes(md: rbml::Doc) -> Vec<hir::Attribute> { match reader::maybe_get_doc(md, tag_attributes) { Some(attrs_d) => { reader::tagged_docs(attrs_d, tag_attribute).map(|attr_doc| { @@ -1147,9 +1150,9 @@ fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> { assert_eq!(meta_items.len(), 1); let meta_item = meta_items.into_iter().nth(0).unwrap(); codemap::Spanned { - node: ast::Attribute_ { + node: hir::Attribute_ { id: attr::mk_attr_id(), - style: ast::AttrOuter, + style: hir::AttrOuter, value: meta_item, is_sugared_doc: is_sugared_doc, }, @@ -1173,7 +1176,7 @@ fn list_crate_attributes(md: rbml::Doc, hash: &Svh, write!(out, "\n\n") } -pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> { +pub fn get_crate_attributes(data: &[u8]) -> Vec<hir::Attribute> { get_attributes(rbml::Doc::new(data)) } @@ -1371,7 +1374,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<ast::Attribute>, String) -> bool, + F: FnMut(ast::Name, Vec<hir::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) { @@ -1453,8 +1456,8 @@ pub fn is_typedef(cdata: Cmd, id: ast::NodeId) -> bool { pub fn is_const_fn(cdata: Cmd, id: ast::NodeId) -> bool { let item_doc = lookup_item(id, cdata.data()); match fn_constness(item_doc) { - ast::Constness::Const => true, - ast::Constness::NotConst => false, + hir::Constness::Const => true, + hir::Constness::NotConst => false, } } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 3f59d70642d..8085c643f19 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -13,7 +13,6 @@ #![allow(unused_must_use)] // everything is just a MemWriter, can't fail #![allow(non_camel_case_types)] -use ast_map::{self, LinkedPath, PathElem, PathElems}; use back::svh::Svh; use session::config; use metadata::common::*; @@ -35,17 +34,20 @@ use std::io::prelude::*; use std::io::{Cursor, SeekFrom}; use std::rc::Rc; use syntax::abi; -use syntax::ast::{self, NodeId}; -use syntax::attr; -use syntax::attr::AttrMetaMethods; +use syntax::ast::{NodeId, Name, CRATE_NODE_ID, CrateNum}; use syntax::diagnostic::SpanHandler; use syntax::parse::token::special_idents; -use syntax::print::pprust; -use syntax::visit::Visitor; -use syntax::visit; use syntax; use rbml::writer::Encoder; +use rustc_front::hir as ast; +use rustc_front::visit::Visitor; +use rustc_front::visit; +use rustc_front::attr; +use rustc_front::attr::AttrMetaMethods; +use front::map::{LinkedPath, PathElem, PathElems}; +use front::map as ast_map; + pub type EncodeInlinedItem<'a> = Box<FnMut(&EncodeContext, &mut Encoder, InlinedItemRef) + 'a>; @@ -72,11 +74,11 @@ pub struct EncodeContext<'a, 'tcx: 'a> { pub reachable: &'a NodeSet, } -fn encode_name(rbml_w: &mut Encoder, name: ast::Name) { +fn encode_name(rbml_w: &mut Encoder, name: Name) { rbml_w.wr_tagged_str(tag_paths_data_name, &name.as_str()); } -fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Name) { +fn encode_impl_type_basename(rbml_w: &mut Encoder, name: Name) { rbml_w.wr_tagged_str(tag_item_impl_type_basename, &name.as_str()); } @@ -130,7 +132,7 @@ fn encode_item_variances(rbml_w: &mut Encoder, fn encode_bounds_and_type_for_item<'a, 'tcx>(rbml_w: &mut Encoder, ecx: &EncodeContext<'a, 'tcx>, - id: ast::NodeId) { + id: NodeId) { encode_bounds_and_type(rbml_w, ecx, &ecx.tcx.lookup_item_type(DefId::local(id)), @@ -343,7 +345,7 @@ fn encode_path<PI: Iterator<Item=PathElem>>(rbml_w: &mut Encoder, path: PI) { fn encode_reexported_static_method(rbml_w: &mut Encoder, exp: &def::Export, method_def_id: DefId, - method_name: ast::Name) { + method_name: Name) { debug!("(encode reexported static method) {}::{}", exp.name, method_name); rbml_w.start_tag(tag_items_data_item_reexport); @@ -500,7 +502,7 @@ fn encode_info_for_mod(ecx: &EncodeContext, attrs: &[ast::Attribute], id: NodeId, path: PathElems, - name: ast::Name, + name: Name, vis: ast::Visibility) { rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, DefId::local(id)); @@ -655,7 +657,7 @@ fn encode_info_for_struct<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, fn encode_info_for_struct_ctor(ecx: &EncodeContext, rbml_w: &mut Encoder, - name: ast::Name, + name: Name, ctor_id: NodeId, index: &mut Vec<entry<i64>>, struct_id: NodeId) { @@ -1475,7 +1477,7 @@ fn encode_info_for_item(ecx: &EncodeContext, rbml_w.end_tag(); } } - ast::ItemExternCrate(_) | ast::ItemUse(_) |ast::ItemMac(..) => { + ast::ItemExternCrate(_) | ast::ItemUse(_) => { // these are encoded separately } } @@ -1588,14 +1590,14 @@ fn encode_info_for_items(ecx: &EncodeContext, let mut index = Vec::new(); rbml_w.start_tag(tag_items_data); index.push(entry { - val: ast::CRATE_NODE_ID as i64, + val: CRATE_NODE_ID as i64, pos: rbml_w.mark_stable_position(), }); encode_info_for_mod(ecx, rbml_w, &krate.module, &[], - ast::CRATE_NODE_ID, + CRATE_NODE_ID, [].iter().cloned().chain(LinkedPath::empty()), syntax::parse::token::special_idents::invalid.name, ast::Public); @@ -1727,7 +1729,7 @@ fn encode_defaulted(rbml_w: &mut Encoder, is_defaulted: bool) { rbml_w.wr_tagged_u8(tag_defaulted_trait, byte); } -fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) { +fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[Name]) { rbml_w.start_tag(tag_associated_type_names); for &name in names { rbml_w.wr_tagged_str(tag_associated_type_name, &name.as_str()); @@ -1745,7 +1747,7 @@ fn encode_polarity(rbml_w: &mut Encoder, polarity: ast::ImplPolarity) { fn encode_crate_deps(rbml_w: &mut Encoder, cstore: &cstore::CStore) { fn get_ordered_deps(cstore: &cstore::CStore) - -> Vec<(ast::CrateNum, Rc<cstore::crate_metadata>)> { + -> Vec<(CrateNum, Rc<cstore::crate_metadata>)> { // Pull the cnums and name,vers,hash out of cstore let mut deps = Vec::new(); cstore.iter_crate_data(|cnum, val| { @@ -1856,7 +1858,7 @@ fn encode_macro_defs(rbml_w: &mut Encoder, encode_attributes(rbml_w, &def.attrs); rbml_w.wr_tagged_str(tag_macro_def_body, - &pprust::tts_to_string(&def.body)); + &::syntax::print::pprust::tts_to_string(&def.body)); rbml_w.end_tag(); } diff --git a/src/librustc/metadata/inline.rs b/src/librustc/metadata/inline.rs index b311784def8..a5ca68e4350 100644 --- a/src/librustc/metadata/inline.rs +++ b/src/librustc/metadata/inline.rs @@ -9,11 +9,11 @@ // except according to those terms. use middle::def_id::DefId; -use syntax::ast; -use syntax::ast_util::{IdRange, IdRangeComputingVisitor, - IdVisitor, IdVisitingOperation}; +use rustc_front::hir; +use rustc_front::util::IdVisitor; +use syntax::ast_util::{IdRange, IdRangeComputingVisitor, IdVisitingOperation}; use syntax::ptr::P; -use syntax::visit::Visitor; +use rustc_front::visit::Visitor; use self::InlinedItem::*; /// The data we save and restore about an inlined item or method. This is not @@ -21,18 +21,18 @@ use self::InlinedItem::*; /// that we trans. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum InlinedItem { - Item(P<ast::Item>), - TraitItem(DefId /* impl id */, P<ast::TraitItem>), - ImplItem(DefId /* impl id */, P<ast::ImplItem>), - Foreign(P<ast::ForeignItem>), + Item(P<hir::Item>), + TraitItem(DefId /* impl id */, P<hir::TraitItem>), + ImplItem(DefId /* impl id */, P<hir::ImplItem>), + Foreign(P<hir::ForeignItem>), } -/// A borrowed version of `ast::InlinedItem`. +/// A borrowed version of `hir::InlinedItem`. pub enum InlinedItemRef<'a> { - Item(&'a ast::Item), - TraitItem(DefId, &'a ast::TraitItem), - ImplItem(DefId, &'a ast::ImplItem), - Foreign(&'a ast::ForeignItem) + Item(&'a hir::Item), + TraitItem(DefId, &'a hir::TraitItem), + ImplItem(DefId, &'a hir::ImplItem), + Foreign(&'a hir::ForeignItem) } impl InlinedItem { @@ -62,4 +62,3 @@ impl InlinedItem { visitor.result() } } - diff --git a/src/librustc/metadata/macro_import.rs b/src/librustc/metadata/macro_import.rs index 08975bab600..527f5919e2d 100644 --- a/src/librustc/metadata/macro_import.rs +++ b/src/librustc/metadata/macro_import.rs @@ -14,13 +14,14 @@ use session::Session; use metadata::creader::CrateReader; use std::collections::{HashSet, HashMap}; -use syntax::ast; -use syntax::attr; use syntax::codemap::Span; use syntax::parse::token; +use syntax::ast; +use syntax::attr; use syntax::visit; use syntax::visit::Visitor; use syntax::attr::AttrMetaMethods; +use rustc_front::attr::AttrMetaMethods as FrontAttrMetaMethods; struct MacroLoader<'a> { sess: &'a Session, diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 0c802356af1..643cf132de2 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -18,6 +18,8 @@ pub use self::DefIdSource::*; +use rustc_front::hir; + use middle::def_id::DefId; use middle::region; use middle::subst; @@ -467,10 +469,10 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> { } } - fn parse_mutability(&mut self) -> ast::Mutability { + fn parse_mutability(&mut self) -> hir::Mutability { match self.peek() { - 'm' => { self.next(); ast::MutMutable } - _ => { ast::MutImmutable } + 'm' => { self.next(); hir::MutMutable } + _ => { hir::MutImmutable } } } @@ -742,10 +744,10 @@ fn parse_defid(buf: &[u8]) -> DefId { DefId { krate: crate_num, node: def_num } } -fn parse_unsafety(c: char) -> ast::Unsafety { +fn parse_unsafety(c: char) -> hir::Unsafety { match c { - 'u' => ast::Unsafety::Unsafe, - 'n' => ast::Unsafety::Normal, + 'u' => hir::Unsafety::Unsafe, + 'n' => hir::Unsafety::Normal, _ => panic!("parse_unsafety: bad unsafety {}", c) } } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 70345dc8bad..d7554c4cf75 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -24,8 +24,9 @@ use middle::ty::ParamTy; use middle::ty::{self, Ty}; use util::nodemap::FnvHashMap; +use rustc_front::hir; + use syntax::abi::Abi; -use syntax::ast; use syntax::diagnostic::SpanHandler; use rbml::writer::Encoder; @@ -64,26 +65,26 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) { ty::TyChar => mywrite!(w, "c"), ty::TyInt(t) => { match t { - ast::TyIs => mywrite!(w, "is"), - ast::TyI8 => mywrite!(w, "MB"), - ast::TyI16 => mywrite!(w, "MW"), - ast::TyI32 => mywrite!(w, "ML"), - ast::TyI64 => mywrite!(w, "MD") + hir::TyIs => mywrite!(w, "is"), + hir::TyI8 => mywrite!(w, "MB"), + hir::TyI16 => mywrite!(w, "MW"), + hir::TyI32 => mywrite!(w, "ML"), + hir::TyI64 => mywrite!(w, "MD") } } ty::TyUint(t) => { match t { - ast::TyUs => mywrite!(w, "us"), - ast::TyU8 => mywrite!(w, "Mb"), - ast::TyU16 => mywrite!(w, "Mw"), - ast::TyU32 => mywrite!(w, "Ml"), - ast::TyU64 => mywrite!(w, "Md") + hir::TyUs => mywrite!(w, "us"), + hir::TyU8 => mywrite!(w, "Mb"), + hir::TyU16 => mywrite!(w, "Mw"), + hir::TyU32 => mywrite!(w, "Ml"), + hir::TyU64 => mywrite!(w, "Md") } } ty::TyFloat(t) => { match t { - ast::TyF32 => mywrite!(w, "Mf"), - ast::TyF64 => mywrite!(w, "MF"), + hir::TyF32 => mywrite!(w, "Mf"), + hir::TyF64 => mywrite!(w, "MF"), } } ty::TyEnum(def, substs) => { @@ -179,10 +180,10 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) { } } -fn enc_mutability(w: &mut Encoder, mt: ast::Mutability) { +fn enc_mutability(w: &mut Encoder, mt: hir::Mutability) { match mt { - ast::MutImmutable => (), - ast::MutMutable => mywrite!(w, "m"), + hir::MutImmutable => (), + hir::MutMutable => mywrite!(w, "m"), } } @@ -314,10 +315,10 @@ pub fn enc_trait_ref<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, enc_substs(w, cx, s.substs); } -fn enc_unsafety(w: &mut Encoder, p: ast::Unsafety) { +fn enc_unsafety(w: &mut Encoder, p: hir::Unsafety) { match p { - ast::Unsafety::Normal => mywrite!(w, "n"), - ast::Unsafety::Unsafe => mywrite!(w, "u"), + hir::Unsafety::Normal => mywrite!(w, "n"), + hir::Unsafety::Unsafe => mywrite!(w, "u"), } } |
