1
Fork 0

libsyntax: Renamed types, traits and enum variants to CamelCase.

This commit is contained in:
Eduard Burtescu 2014-01-09 15:05:33 +02:00
parent 63ba93f91d
commit 6b221768cf
142 changed files with 4221 additions and 4324 deletions

View file

@ -38,7 +38,8 @@ use extra::hex::ToHex;
use extra::tempfile::TempDir; use extra::tempfile::TempDir;
use syntax::abi; use syntax::abi;
use syntax::ast; use syntax::ast;
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name}; use syntax::ast_map::{PathMod, PathName, PathPrettyName};
use syntax::ast_map;
use syntax::attr; use syntax::attr;
use syntax::attr::AttrMetaMethods; use syntax::attr::AttrMetaMethods;
use syntax::crateid::CrateId; use syntax::crateid::CrateId;
@ -583,7 +584,7 @@ pub fn sanitize(s: &str) -> ~str {
return result; return result;
} }
pub fn mangle(sess: Session, ss: path, pub fn mangle(sess: Session, ss: ast_map::Path,
hash: Option<&str>, vers: Option<&str>) -> ~str { hash: Option<&str>, vers: Option<&str>) -> ~str {
// Follow C++ namespace-mangling style, see // Follow C++ namespace-mangling style, see
// http://en.wikipedia.org/wiki/Name_mangling for more info. // http://en.wikipedia.org/wiki/Name_mangling for more info.
@ -609,7 +610,7 @@ pub fn mangle(sess: Session, ss: path,
// First, connect each component with <len, name> pairs. // First, connect each component with <len, name> pairs.
for s in ss.iter() { for s in ss.iter() {
match *s { match *s {
path_name(s) | path_mod(s) | path_pretty_name(s, _) => { PathName(s) | PathMod(s) | PathPrettyName(s, _) => {
push(sess.str_of(s)) push(sess.str_of(s))
} }
} }
@ -625,7 +626,7 @@ pub fn mangle(sess: Session, ss: path,
let mut hash = match hash { Some(s) => s.to_owned(), None => ~"" }; let mut hash = match hash { Some(s) => s.to_owned(), None => ~"" };
for s in ss.iter() { for s in ss.iter() {
match *s { match *s {
path_pretty_name(_, extra) => { PathPrettyName(_, extra) => {
let hi = (extra >> 32) as u32 as uint; let hi = (extra >> 32) as u32 as uint;
let lo = extra as u32 as uint; let lo = extra as u32 as uint;
hash.push_char(EXTRA_CHARS[hi % EXTRA_CHARS.len()] as char); hash.push_char(EXTRA_CHARS[hi % EXTRA_CHARS.len()] as char);
@ -647,7 +648,7 @@ pub fn mangle(sess: Session, ss: path,
} }
pub fn exported_name(sess: Session, pub fn exported_name(sess: Session,
path: path, path: ast_map::Path,
hash: &str, hash: &str,
vers: &str) -> ~str { vers: &str) -> ~str {
// The version will get mangled to have a leading '_', but it makes more // The version will get mangled to have a leading '_', but it makes more
@ -662,7 +663,7 @@ pub fn exported_name(sess: Session,
} }
pub fn mangle_exported_name(ccx: &CrateContext, pub fn mangle_exported_name(ccx: &CrateContext,
path: path, path: ast_map::Path,
t: ty::t) -> ~str { t: ty::t) -> ~str {
let hash = get_symbol_hash(ccx, t); let hash = get_symbol_hash(ccx, t);
return exported_name(ccx.sess, path, return exported_name(ccx.sess, path,
@ -676,8 +677,8 @@ pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
let s = ppaux::ty_to_short_str(ccx.tcx, t); let s = ppaux::ty_to_short_str(ccx.tcx, t);
let hash = get_symbol_hash(ccx, t); let hash = get_symbol_hash(ccx, t);
return mangle(ccx.sess, return mangle(ccx.sess,
~[path_name(ccx.sess.ident_of(name)), ~[PathName(ccx.sess.ident_of(name)),
path_name(ccx.sess.ident_of(s))], PathName(ccx.sess.ident_of(s))],
Some(hash.as_slice()), Some(hash.as_slice()),
None); None);
} }
@ -689,20 +690,21 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext,
let hash = get_symbol_hash(ccx, t); let hash = get_symbol_hash(ccx, t);
let (_, name) = gensym_name(name); let (_, name) = gensym_name(name);
return mangle(ccx.sess, return mangle(ccx.sess,
~[path_name(ccx.sess.ident_of(s)), name], ~[PathName(ccx.sess.ident_of(s)), name],
Some(hash.as_slice()), Some(hash.as_slice()),
None); None);
} }
pub fn mangle_internal_name_by_path_and_seq(ccx: &CrateContext, pub fn mangle_internal_name_by_path_and_seq(ccx: &CrateContext,
mut path: path, mut path: ast_map::Path,
flav: &str) -> ~str { flav: &str) -> ~str {
let (_, name) = gensym_name(flav); let (_, name) = gensym_name(flav);
path.push(name); path.push(name);
mangle(ccx.sess, path, None, None) mangle(ccx.sess, path, None, None)
} }
pub fn mangle_internal_name_by_path(ccx: &CrateContext, path: path) -> ~str { pub fn mangle_internal_name_by_path(ccx: &CrateContext,
path: ast_map::Path) -> ~str {
mangle(ccx.sess, path, None, None) mangle(ccx.sess, path, None, None)
} }

View file

@ -164,7 +164,7 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &input)
pub fn phase_2_configure_and_expand(sess: Session, pub fn phase_2_configure_and_expand(sess: Session,
cfg: ast::CrateConfig, cfg: ast::CrateConfig,
mut crate: ast::Crate) mut crate: ast::Crate)
-> (ast::Crate, syntax::ast_map::map) { -> (ast::Crate, syntax::ast_map::Map) {
let time_passes = sess.time_passes(); let time_passes = sess.time_passes();
sess.building_library.set(session::building_library(sess.opts, &crate)); sess.building_library.set(session::building_library(sess.opts, &crate));
@ -220,7 +220,7 @@ pub struct CrateAnalysis {
/// structures carrying the results of the analysis. /// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes(sess: Session, pub fn phase_3_run_analysis_passes(sess: Session,
crate: &ast::Crate, crate: &ast::Crate,
ast_map: syntax::ast_map::map) -> CrateAnalysis { ast_map: syntax::ast_map::Map) -> CrateAnalysis {
let time_passes = sess.time_passes(); let time_passes = sess.time_passes();
@ -515,29 +515,29 @@ struct IdentifiedAnnotation {
contents: (), contents: (),
} }
impl pprust::pp_ann for IdentifiedAnnotation { impl pprust::PpAnn for IdentifiedAnnotation {
fn pre(&self, node: pprust::ann_node) { fn pre(&self, node: pprust::AnnNode) {
match node { match node {
pprust::node_expr(s, _) => pprust::popen(s), pprust::NodeExpr(s, _) => pprust::popen(s),
_ => () _ => ()
} }
} }
fn post(&self, node: pprust::ann_node) { fn post(&self, node: pprust::AnnNode) {
match node { match node {
pprust::node_item(s, item) => { pprust::NodeItem(s, item) => {
pp::space(&mut s.s); pp::space(&mut s.s);
pprust::synth_comment(s, item.id.to_str()); pprust::synth_comment(s, item.id.to_str());
} }
pprust::node_block(s, blk) => { pprust::NodeBlock(s, blk) => {
pp::space(&mut s.s); pp::space(&mut s.s);
pprust::synth_comment(s, ~"block " + blk.id.to_str()); pprust::synth_comment(s, ~"block " + blk.id.to_str());
} }
pprust::node_expr(s, expr) => { pprust::NodeExpr(s, expr) => {
pp::space(&mut s.s); pp::space(&mut s.s);
pprust::synth_comment(s, expr.id.to_str()); pprust::synth_comment(s, expr.id.to_str());
pprust::pclose(s); pprust::pclose(s);
} }
pprust::node_pat(s, pat) => { pprust::NodePat(s, pat) => {
pp::space(&mut s.s); pp::space(&mut s.s);
pprust::synth_comment(s, ~"pat " + pat.id.to_str()); pprust::synth_comment(s, ~"pat " + pat.id.to_str());
} }
@ -549,17 +549,17 @@ struct TypedAnnotation {
analysis: CrateAnalysis, analysis: CrateAnalysis,
} }
impl pprust::pp_ann for TypedAnnotation { impl pprust::PpAnn for TypedAnnotation {
fn pre(&self, node: pprust::ann_node) { fn pre(&self, node: pprust::AnnNode) {
match node { match node {
pprust::node_expr(s, _) => pprust::popen(s), pprust::NodeExpr(s, _) => pprust::popen(s),
_ => () _ => ()
} }
} }
fn post(&self, node: pprust::ann_node) { fn post(&self, node: pprust::AnnNode) {
let tcx = self.analysis.ty_cx; let tcx = self.analysis.ty_cx;
match node { match node {
pprust::node_expr(s, expr) => { pprust::NodeExpr(s, expr) => {
pp::space(&mut s.s); pp::space(&mut s.s);
pp::word(&mut s.s, "as"); pp::word(&mut s.s, "as");
pp::space(&mut s.s); pp::space(&mut s.s);
@ -589,16 +589,16 @@ pub fn pretty_print_input(sess: Session,
PpmIdentified | PpmExpandedIdentified => { PpmIdentified | PpmExpandedIdentified => {
@IdentifiedAnnotation { @IdentifiedAnnotation {
contents: (), contents: (),
} as @pprust::pp_ann } as @pprust::PpAnn
} }
PpmTyped => { PpmTyped => {
let ast_map = ast_map.expect("--pretty=typed missing ast_map"); let ast_map = ast_map.expect("--pretty=typed missing ast_map");
let analysis = phase_3_run_analysis_passes(sess, &crate, ast_map); let analysis = phase_3_run_analysis_passes(sess, &crate, ast_map);
@TypedAnnotation { @TypedAnnotation {
analysis: analysis analysis: analysis
} as @pprust::pp_ann } as @pprust::PpAnn
} }
_ => @pprust::no_ann::new() as @pprust::pp_ann, _ => @pprust::NoAnn as @pprust::PpAnn,
}; };
let src = sess.codemap.get_filemap(source_name(input)).src; let src = sess.codemap.get_filemap(source_name(input)).src;
@ -662,10 +662,10 @@ pub fn build_target_config(sopts: @session::options,
"unknown architecture: " + sopts.target_triple) "unknown architecture: " + sopts.target_triple)
}; };
let (int_type, uint_type) = match arch { let (int_type, uint_type) = match arch {
abi::X86 => (ast::ty_i32, ast::ty_u32), abi::X86 => (ast::TyI32, ast::TyU32),
abi::X86_64 => (ast::ty_i64, ast::ty_u64), abi::X86_64 => (ast::TyI64, ast::TyU64),
abi::Arm => (ast::ty_i32, ast::ty_u32), abi::Arm => (ast::TyI32, ast::TyU32),
abi::Mips => (ast::ty_i32, ast::ty_u32) abi::Mips => (ast::TyI32, ast::TyU32)
}; };
let target_triple = sopts.target_triple.clone(); let target_triple = sopts.target_triple.clone();
let target_strs = match arch { let target_strs = match arch {
@ -1116,7 +1116,7 @@ pub fn build_output_filenames(input: &input,
} }
pub fn early_error(emitter: &diagnostic::Emitter, msg: &str) -> ! { pub fn early_error(emitter: &diagnostic::Emitter, msg: &str) -> ! {
emitter.emit(None, msg, diagnostic::fatal); emitter.emit(None, msg, diagnostic::Fatal);
fail!(); fail!();
} }

View file

@ -19,7 +19,7 @@ use middle::lint;
use syntax::attr::AttrMetaMethods; use syntax::attr::AttrMetaMethods;
use syntax::ast::NodeId; use syntax::ast::NodeId;
use syntax::ast::{int_ty, uint_ty}; use syntax::ast::{IntTy, UintTy};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::diagnostic; use syntax::diagnostic;
use syntax::parse::ParseSess; use syntax::parse::ParseSess;
@ -35,8 +35,8 @@ pub struct config {
os: abi::Os, os: abi::Os,
arch: abi::Architecture, arch: abi::Architecture,
target_strs: target_strs::t, target_strs: target_strs::t,
int_type: int_ty, int_type: IntTy,
uint_type: uint_ty, uint_type: UintTy,
} }
pub static verbose: uint = 1 << 0; pub static verbose: uint = 1 << 0;
@ -368,7 +368,7 @@ impl Session_ {
} }
// pointless function, now... // pointless function, now...
pub fn intr(&self) -> @syntax::parse::token::ident_interner { pub fn intr(&self) -> @syntax::parse::token::IdentInterner {
token::get_ident_interner() token::get_ident_interner()
} }
} }

View file

@ -24,6 +24,6 @@ impl ast_map::FoldOps for NodeIdAssigner {
} }
} }
pub fn assign_node_ids_and_map(sess: Session, crate: ast::Crate) -> (ast::Crate, ast_map::map) { pub fn assign_node_ids_and_map(sess: Session, crate: ast::Crate) -> (ast::Crate, ast_map::Map) {
ast_map::map_crate(sess.diagnostic(), crate, NodeIdAssigner { sess: sess }) ast_map::map_crate(sess.diagnostic(), crate, NodeIdAssigner { sess: sess })
} }

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use syntax::fold::ast_fold; use syntax::fold::Folder;
use syntax::{ast, fold, attr}; use syntax::{ast, fold, attr};
use syntax::codemap; use syntax::codemap;
@ -24,18 +24,17 @@ pub fn strip_unconfigured_items(crate: ast::Crate) -> ast::Crate {
strip_items(crate, |attrs| in_cfg(config, attrs)) strip_items(crate, |attrs| in_cfg(config, attrs))
} }
impl<'a> fold::ast_fold for Context<'a> { impl<'a> fold::Folder for Context<'a> {
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod { fn fold_mod(&mut self, module: &ast::Mod) -> ast::Mod {
fold_mod(self, module) fold_mod(self, module)
} }
fn fold_block(&mut self, block: ast::P<ast::Block>) -> ast::P<ast::Block> { fn fold_block(&mut self, block: ast::P<ast::Block>) -> ast::P<ast::Block> {
fold_block(self, block) fold_block(self, block)
} }
fn fold_foreign_mod(&mut self, foreign_module: &ast::foreign_mod) fn fold_foreign_mod(&mut self, foreign_mod: &ast::ForeignMod) -> ast::ForeignMod {
-> ast::foreign_mod { fold_foreign_mod(self, foreign_mod)
fold_foreign_mod(self, foreign_module)
} }
fn fold_item_underscore(&mut self, item: &ast::item_) -> ast::item_ { fn fold_item_underscore(&mut self, item: &ast::Item_) -> ast::Item_ {
fold_item_underscore(self, item) fold_item_underscore(self, item)
} }
} }
@ -49,8 +48,8 @@ pub fn strip_items(crate: ast::Crate,
ctxt.fold_crate(crate) ctxt.fold_crate(crate)
} }
fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::view_item) fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::ViewItem)
-> Option<&'r ast::view_item> { -> Option<&'r ast::ViewItem> {
if view_item_in_cfg(cx, view_item) { if view_item_in_cfg(cx, view_item) {
Some(view_item) Some(view_item)
} else { } else {
@ -58,7 +57,7 @@ fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::view_item)
} }
} }
fn fold_mod(cx: &mut Context, m: &ast::_mod) -> ast::_mod { fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
let filtered_items = m.items.iter() let filtered_items = m.items.iter()
.filter(|&a| item_in_cfg(cx, *a)) .filter(|&a| item_in_cfg(cx, *a))
.flat_map(|&x| cx.fold_item(x).move_iter()) .flat_map(|&x| cx.fold_item(x).move_iter())
@ -66,14 +65,14 @@ fn fold_mod(cx: &mut Context, m: &ast::_mod) -> ast::_mod {
let filtered_view_items = m.view_items.iter().filter_map(|a| { let filtered_view_items = m.view_items.iter().filter_map(|a| {
filter_view_item(cx, a).map(|x| cx.fold_view_item(x)) filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
}).collect(); }).collect();
ast::_mod { ast::Mod {
view_items: filtered_view_items, view_items: filtered_view_items,
items: filtered_items items: filtered_items
} }
} }
fn filter_foreign_item(cx: &Context, item: @ast::foreign_item) fn filter_foreign_item(cx: &Context, item: @ast::ForeignItem)
-> Option<@ast::foreign_item> { -> Option<@ast::ForeignItem> {
if foreign_item_in_cfg(cx, item) { if foreign_item_in_cfg(cx, item) {
Some(item) Some(item)
} else { } else {
@ -81,7 +80,7 @@ fn filter_foreign_item(cx: &Context, item: @ast::foreign_item)
} }
} }
fn fold_foreign_mod(cx: &mut Context, nm: &ast::foreign_mod) -> ast::foreign_mod { fn fold_foreign_mod(cx: &mut Context, nm: &ast::ForeignMod) -> ast::ForeignMod {
let filtered_items = nm.items let filtered_items = nm.items
.iter() .iter()
.filter_map(|a| filter_foreign_item(cx, *a)) .filter_map(|a| filter_foreign_item(cx, *a))
@ -89,41 +88,41 @@ fn fold_foreign_mod(cx: &mut Context, nm: &ast::foreign_mod) -> ast::foreign_mod
let filtered_view_items = nm.view_items.iter().filter_map(|a| { let filtered_view_items = nm.view_items.iter().filter_map(|a| {
filter_view_item(cx, a).map(|x| cx.fold_view_item(x)) filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
}).collect(); }).collect();
ast::foreign_mod { ast::ForeignMod {
abis: nm.abis, abis: nm.abis,
view_items: filtered_view_items, view_items: filtered_view_items,
items: filtered_items items: filtered_items
} }
} }
fn fold_item_underscore(cx: &mut Context, item: &ast::item_) -> ast::item_ { fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
let item = match *item { let item = match *item {
ast::item_impl(ref a, ref b, c, ref methods) => { ast::ItemImpl(ref a, ref b, c, ref methods) => {
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m)) let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
.map(|x| *x).collect(); .map(|x| *x).collect();
ast::item_impl((*a).clone(), (*b).clone(), c, methods) ast::ItemImpl((*a).clone(), (*b).clone(), c, methods)
} }
ast::item_trait(ref a, ref b, ref methods) => { ast::ItemTrait(ref a, ref b, ref methods) => {
let methods = methods.iter() let methods = methods.iter()
.filter(|m| trait_method_in_cfg(cx, *m) ) .filter(|m| trait_method_in_cfg(cx, *m) )
.map(|x| (*x).clone()) .map(|x| (*x).clone())
.collect(); .collect();
ast::item_trait((*a).clone(), (*b).clone(), methods) ast::ItemTrait((*a).clone(), (*b).clone(), methods)
} }
ast::item_struct(def, ref generics) => { ast::ItemStruct(def, ref generics) => {
ast::item_struct(fold_struct(cx, def), generics.clone()) ast::ItemStruct(fold_struct(cx, def), generics.clone())
} }
ast::item_enum(ref def, ref generics) => { ast::ItemEnum(ref def, ref generics) => {
let mut variants = def.variants.iter().map(|c| c.clone()).filter(|m| { let mut variants = def.variants.iter().map(|c| c.clone()).filter(|m| {
(cx.in_cfg)(m.node.attrs) (cx.in_cfg)(m.node.attrs)
}).map(|v| { }).map(|v| {
match v.node.kind { match v.node.kind {
ast::tuple_variant_kind(..) => v, ast::TupleVariantKind(..) => v,
ast::struct_variant_kind(def) => { ast::StructVariantKind(def) => {
let def = fold_struct(cx, def); let def = fold_struct(cx, def);
@codemap::Spanned { @codemap::Spanned {
node: ast::variant_ { node: ast::Variant_ {
kind: ast::struct_variant_kind(def), kind: ast::StructVariantKind(def),
..v.node.clone() ..v.node.clone()
}, },
..*v ..*v
@ -131,7 +130,7 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::item_) -> ast::item_ {
} }
} }
}); });
ast::item_enum(ast::enum_def { ast::ItemEnum(ast::EnumDef {
variants: variants.collect(), variants: variants.collect(),
}, generics.clone()) }, generics.clone())
} }
@ -141,11 +140,11 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::item_) -> ast::item_ {
fold::noop_fold_item_underscore(&item, cx) fold::noop_fold_item_underscore(&item, cx)
} }
fn fold_struct(cx: &Context, def: &ast::struct_def) -> @ast::struct_def { fn fold_struct(cx: &Context, def: &ast::StructDef) -> @ast::StructDef {
let mut fields = def.fields.iter().map(|c| c.clone()).filter(|m| { let mut fields = def.fields.iter().map(|c| c.clone()).filter(|m| {
(cx.in_cfg)(m.node.attrs) (cx.in_cfg)(m.node.attrs)
}); });
@ast::struct_def { @ast::StructDef {
fields: fields.collect(), fields: fields.collect(),
ctor_id: def.ctor_id, ctor_id: def.ctor_id,
} }
@ -183,26 +182,26 @@ fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
}) })
} }
fn item_in_cfg(cx: &Context, item: @ast::item) -> bool { fn item_in_cfg(cx: &Context, item: &ast::Item) -> bool {
return (cx.in_cfg)(item.attrs); return (cx.in_cfg)(item.attrs);
} }
fn foreign_item_in_cfg(cx: &Context, item: @ast::foreign_item) -> bool { fn foreign_item_in_cfg(cx: &Context, item: &ast::ForeignItem) -> bool {
return (cx.in_cfg)(item.attrs); return (cx.in_cfg)(item.attrs);
} }
fn view_item_in_cfg(cx: &Context, item: &ast::view_item) -> bool { fn view_item_in_cfg(cx: &Context, item: &ast::ViewItem) -> bool {
return (cx.in_cfg)(item.attrs); return (cx.in_cfg)(item.attrs);
} }
fn method_in_cfg(cx: &Context, meth: @ast::method) -> bool { fn method_in_cfg(cx: &Context, meth: &ast::Method) -> bool {
return (cx.in_cfg)(meth.attrs); return (cx.in_cfg)(meth.attrs);
} }
fn trait_method_in_cfg(cx: &Context, meth: &ast::trait_method) -> bool { fn trait_method_in_cfg(cx: &Context, meth: &ast::TraitMethod) -> bool {
match *meth { match *meth {
ast::required(ref meth) => (cx.in_cfg)(meth.attrs), ast::Required(ref meth) => (cx.in_cfg)(meth.attrs),
ast::provided(@ref meth) => (cx.in_cfg)(meth.attrs) ast::Provided(@ref meth) => (cx.in_cfg)(meth.attrs)
} }
} }

View file

@ -100,12 +100,12 @@ impl Visitor<()> for Context {
} }
} }
fn visit_view_item(&mut self, i: &ast::view_item, _: ()) { fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
match i.node { match i.node {
ast::view_item_use(ref paths) => { ast::ViewItemUse(ref paths) => {
for path in paths.iter() { for path in paths.iter() {
match path.node { match path.node {
ast::view_path_glob(..) => { ast::ViewPathGlob(..) => {
self.gate_feature("globs", path.span, self.gate_feature("globs", path.span,
"glob import statements are \ "glob import statements are \
experimental and possibly buggy"); experimental and possibly buggy");
@ -119,7 +119,7 @@ impl Visitor<()> for Context {
visit::walk_view_item(self, i, ()) visit::walk_view_item(self, i, ())
} }
fn visit_item(&mut self, i: &ast::item, _:()) { fn visit_item(&mut self, i: &ast::Item, _:()) {
for attr in i.attrs.iter() { for attr in i.attrs.iter() {
if "thread_local" == attr.name() { if "thread_local" == attr.name() {
self.gate_feature("thread_local", i.span, self.gate_feature("thread_local", i.span,
@ -129,10 +129,10 @@ impl Visitor<()> for Context {
} }
} }
match i.node { match i.node {
ast::item_enum(ref def, _) => { ast::ItemEnum(ref def, _) => {
for variant in def.variants.iter() { for variant in def.variants.iter() {
match variant.node.kind { match variant.node.kind {
ast::struct_variant_kind(..) => { ast::StructVariantKind(..) => {
self.gate_feature("struct_variant", variant.span, self.gate_feature("struct_variant", variant.span,
"enum struct variants are \ "enum struct variants are \
experimental and possibly buggy"); experimental and possibly buggy");
@ -142,7 +142,7 @@ impl Visitor<()> for Context {
} }
} }
ast::item_foreign_mod(..) => { ast::ItemForeignMod(..) => {
if attr::contains_name(i.attrs, "link_args") { if attr::contains_name(i.attrs, "link_args") {
self.gate_feature("link_args", i.span, self.gate_feature("link_args", i.span,
"the `link_args` attribute is not portable \ "the `link_args` attribute is not portable \
@ -157,8 +157,8 @@ impl Visitor<()> for Context {
visit::walk_item(self, i, ()); visit::walk_item(self, i, ());
} }
fn visit_mac(&mut self, macro: &ast::mac, _: ()) { fn visit_mac(&mut self, macro: &ast::Mac, _: ()) {
let ast::mac_invoc_tt(ref path, _, _) = macro.node; let ast::MacInvocTT(ref path, _, _) = macro.node;
if path.segments.last().identifier == self.sess.ident_of("macro_rules") { if path.segments.last().identifier == self.sess.ident_of("macro_rules") {
self.gate_feature("macro_rules", path.span, "macro definitions are \ self.gate_feature("macro_rules", path.span, "macro definitions are \
@ -173,14 +173,14 @@ impl Visitor<()> for Context {
fn visit_ty(&mut self, t: &ast::Ty, _: ()) { fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
match t.node { match t.node {
ast::ty_closure(closure) if closure.onceness == ast::Once && ast::TyClosure(closure) if closure.onceness == ast::Once &&
closure.sigil != ast::OwnedSigil => { closure.sigil != ast::OwnedSigil => {
self.gate_feature("once_fns", t.span, self.gate_feature("once_fns", t.span,
"once functions are \ "once functions are \
experimental and likely to be removed"); experimental and likely to be removed");
}, },
ast::ty_box(_) => { self.gate_box(t.span); } ast::TyBox(_) => { self.gate_box(t.span); }
_ => {} _ => {}
} }

View file

@ -16,7 +16,7 @@ use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::codemap::DUMMY_SP; use syntax::codemap::DUMMY_SP;
use syntax::codemap; use syntax::codemap;
use syntax::fold::ast_fold; use syntax::fold::Folder;
use syntax::fold; use syntax::fold;
use syntax::opt_vec; use syntax::opt_vec;
use syntax::util::small_vector::SmallVector; use syntax::util::small_vector::SmallVector;
@ -55,41 +55,41 @@ struct StandardLibraryInjector {
sess: Session, sess: Session,
} }
impl fold::ast_fold for StandardLibraryInjector { impl fold::Folder for StandardLibraryInjector {
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate { fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
let mut vis = ~[ast::view_item { let mut vis = ~[ast::ViewItem {
node: ast::view_item_extern_mod(self.sess.ident_of("std"), node: ast::ViewItemExternMod(self.sess.ident_of("std"),
Some((format!("std\\#{}", VERSION).to_managed(), Some((format!("std\\#{}", VERSION).to_managed(),
ast::CookedStr)), ast::CookedStr)),
ast::DUMMY_NODE_ID), ast::DUMMY_NODE_ID),
attrs: ~[], attrs: ~[],
vis: ast::private, vis: ast::Private,
span: DUMMY_SP span: DUMMY_SP
}]; }];
if use_uv(&crate) && !self.sess.building_library.get() { if use_uv(&crate) && !self.sess.building_library.get() {
vis.push(ast::view_item { vis.push(ast::ViewItem {
node: ast::view_item_extern_mod(self.sess.ident_of("green"), node: ast::ViewItemExternMod(self.sess.ident_of("green"),
Some((format!("green\\#{}", VERSION).to_managed(), Some((format!("green\\#{}", VERSION).to_managed(),
ast::CookedStr)), ast::CookedStr)),
ast::DUMMY_NODE_ID), ast::DUMMY_NODE_ID),
attrs: ~[], attrs: ~[],
vis: ast::private, vis: ast::Private,
span: DUMMY_SP span: DUMMY_SP
}); });
vis.push(ast::view_item { vis.push(ast::ViewItem {
node: ast::view_item_extern_mod(self.sess.ident_of("rustuv"), node: ast::ViewItemExternMod(self.sess.ident_of("rustuv"),
Some((format!("rustuv\\#{}", VERSION).to_managed(), Some((format!("rustuv\\#{}", VERSION).to_managed(),
ast::CookedStr)), ast::CookedStr)),
ast::DUMMY_NODE_ID), ast::DUMMY_NODE_ID),
attrs: ~[], attrs: ~[],
vis: ast::private, vis: ast::Private,
span: DUMMY_SP span: DUMMY_SP
}); });
} }
vis.push_all(crate.module.view_items); vis.push_all(crate.module.view_items);
let mut new_module = ast::_mod { let mut new_module = ast::Mod {
view_items: vis, view_items: vis,
..crate.module.clone() ..crate.module.clone()
}; };
@ -106,7 +106,7 @@ impl fold::ast_fold for StandardLibraryInjector {
} }
} }
fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> { fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> {
if !no_prelude(item.attrs) { if !no_prelude(item.attrs) {
// only recur if there wasn't `#[no_implicit_prelude];` // only recur if there wasn't `#[no_implicit_prelude];`
// on this item, i.e. this means that the prelude is not // on this item, i.e. this means that the prelude is not
@ -117,7 +117,7 @@ impl fold::ast_fold for StandardLibraryInjector {
} }
} }
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod { fn fold_mod(&mut self, module: &ast::Mod) -> ast::Mod {
let prelude_path = ast::Path { let prelude_path = ast::Path {
span: DUMMY_SP, span: DUMMY_SP,
global: false, global: false,
@ -135,19 +135,18 @@ impl fold::ast_fold for StandardLibraryInjector {
], ],
}; };
let vp = @spanned(ast::view_path_glob(prelude_path, let vp = @spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
ast::DUMMY_NODE_ID)); let vi2 = ast::ViewItem {
let vi2 = ast::view_item { node: ast::ViewItemUse(~[vp]),
node: ast::view_item_use(~[vp]),
attrs: ~[], attrs: ~[],
vis: ast::private, vis: ast::Private,
span: DUMMY_SP, span: DUMMY_SP,
}; };
let vis = vec::append(~[vi2], module.view_items); let vis = vec::append(~[vi2], module.view_items);
// FIXME #2543: Bad copy. // FIXME #2543: Bad copy.
let new_module = ast::_mod { let new_module = ast::Mod {
view_items: vis, view_items: vis,
..(*module).clone() ..(*module).clone()
}; };

View file

@ -23,7 +23,7 @@ use syntax::attr;
use syntax::codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute}; use syntax::codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
use syntax::codemap; use syntax::codemap;
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
use syntax::fold::ast_fold; use syntax::fold::Folder;
use syntax::fold; use syntax::fold;
use syntax::opt_vec; use syntax::opt_vec;
use syntax::print::pprust; use syntax::print::pprust;
@ -67,7 +67,7 @@ struct TestHarnessGenerator {
cx: TestCtxt, cx: TestCtxt,
} }
impl fold::ast_fold for TestHarnessGenerator { impl fold::Folder for TestHarnessGenerator {
fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate { fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate {
let folded = fold::noop_fold_crate(c, self); let folded = fold::noop_fold_crate(c, self);
@ -79,7 +79,7 @@ impl fold::ast_fold for TestHarnessGenerator {
} }
} }
fn fold_item(&mut self, i: @ast::item) -> SmallVector<@ast::item> { fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
{ {
let mut path = self.cx.path.borrow_mut(); let mut path = self.cx.path.borrow_mut();
path.get().push(i.ident); path.get().push(i.ident);
@ -89,8 +89,8 @@ impl fold::ast_fold for TestHarnessGenerator {
if is_test_fn(&self.cx, i) || is_bench_fn(i) { if is_test_fn(&self.cx, i) || is_bench_fn(i) {
match i.node { match i.node {
ast::item_fn(_, purity, _, _, _) ast::ItemFn(_, purity, _, _, _)
if purity == ast::unsafe_fn => { if purity == ast::UnsafeFn => {
let sess = self.cx.sess; let sess = self.cx.sess;
sess.span_fatal(i.span, sess.span_fatal(i.span,
"unsafe functions cannot be used for \ "unsafe functions cannot be used for \
@ -123,13 +123,13 @@ impl fold::ast_fold for TestHarnessGenerator {
res res
} }
fn fold_mod(&mut self, m: &ast::_mod) -> ast::_mod { fn fold_mod(&mut self, m: &ast::Mod) -> ast::Mod {
// Remove any #[main] from the AST so it doesn't clash with // Remove any #[main] from the AST so it doesn't clash with
// the one we're going to add. Only if compiling an executable. // the one we're going to add. Only if compiling an executable.
fn nomain(cx: &TestCtxt, item: @ast::item) -> @ast::item { fn nomain(cx: &TestCtxt, item: @ast::Item) -> @ast::Item {
if !cx.sess.building_library.get() { if !cx.sess.building_library.get() {
@ast::item { @ast::Item {
attrs: item.attrs.iter().filter_map(|attr| { attrs: item.attrs.iter().filter_map(|attr| {
if "main" != attr.name() { if "main" != attr.name() {
Some(*attr) Some(*attr)
@ -144,7 +144,7 @@ impl fold::ast_fold for TestHarnessGenerator {
} }
} }
let mod_nomain = ast::_mod { let mod_nomain = ast::Mod {
view_items: m.view_items.clone(), view_items: m.view_items.clone(),
items: m.items.iter().map(|i| nomain(&self.cx, *i)).collect(), items: m.items.iter().map(|i| nomain(&self.cx, *i)).collect(),
}; };
@ -190,14 +190,14 @@ fn strip_test_functions(crate: ast::Crate) -> ast::Crate {
}) })
} }
fn is_test_fn(cx: &TestCtxt, i: @ast::item) -> bool { fn is_test_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
let has_test_attr = attr::contains_name(i.attrs, "test"); let has_test_attr = attr::contains_name(i.attrs, "test");
fn has_test_signature(i: @ast::item) -> bool { fn has_test_signature(i: @ast::Item) -> bool {
match &i.node { match &i.node {
&ast::item_fn(ref decl, _, _, ref generics, _) => { &ast::ItemFn(ref decl, _, _, ref generics, _) => {
let no_output = match decl.output.node { let no_output = match decl.output.node {
ast::ty_nil => true, ast::TyNil => true,
_ => false _ => false
}; };
decl.inputs.is_empty() decl.inputs.is_empty()
@ -219,15 +219,15 @@ fn is_test_fn(cx: &TestCtxt, i: @ast::item) -> bool {
return has_test_attr && has_test_signature(i); return has_test_attr && has_test_signature(i);
} }
fn is_bench_fn(i: @ast::item) -> bool { fn is_bench_fn(i: @ast::Item) -> bool {
let has_bench_attr = attr::contains_name(i.attrs, "bench"); let has_bench_attr = attr::contains_name(i.attrs, "bench");
fn has_test_signature(i: @ast::item) -> bool { fn has_test_signature(i: @ast::Item) -> bool {
match i.node { match i.node {
ast::item_fn(ref decl, _, _, ref generics, _) => { ast::ItemFn(ref decl, _, _, ref generics, _) => {
let input_cnt = decl.inputs.len(); let input_cnt = decl.inputs.len();
let no_output = match decl.output.node { let no_output = match decl.output.node {
ast::ty_nil => true, ast::TyNil => true,
_ => false _ => false
}; };
let tparm_cnt = generics.ty_params.len(); let tparm_cnt = generics.ty_params.len();
@ -243,7 +243,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
return has_bench_attr && has_test_signature(i); return has_bench_attr && has_test_signature(i);
} }
fn is_ignored(cx: &TestCtxt, i: @ast::item) -> bool { fn is_ignored(cx: &TestCtxt, i: @ast::Item) -> bool {
i.attrs.iter().any(|attr| { i.attrs.iter().any(|attr| {
// check ignore(cfg(foo, bar)) // check ignore(cfg(foo, bar))
"ignore" == attr.name() && match attr.meta_item_list() { "ignore" == attr.name() && match attr.meta_item_list() {
@ -253,13 +253,13 @@ fn is_ignored(cx: &TestCtxt, i: @ast::item) -> bool {
}) })
} }
fn should_fail(i: @ast::item) -> bool { fn should_fail(i: @ast::Item) -> bool {
attr::contains_name(i.attrs, "should_fail") attr::contains_name(i.attrs, "should_fail")
} }
fn add_test_module(cx: &TestCtxt, m: &ast::_mod) -> ast::_mod { fn add_test_module(cx: &TestCtxt, m: &ast::Mod) -> ast::Mod {
let testmod = mk_test_module(cx); let testmod = mk_test_module(cx);
ast::_mod { ast::Mod {
items: vec::append_one(m.items.clone(), testmod), items: vec::append_one(m.items.clone(), testmod),
..(*m).clone() ..(*m).clone()
} }
@ -284,28 +284,28 @@ mod __test {
*/ */
fn mk_std(cx: &TestCtxt) -> ast::view_item { fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
let id_extra = cx.sess.ident_of("extra"); let id_extra = cx.sess.ident_of("extra");
let vi = if cx.is_extra { let vi = if cx.is_extra {
ast::view_item_use( ast::ViewItemUse(
~[@nospan(ast::view_path_simple(id_extra, ~[@nospan(ast::ViewPathSimple(id_extra,
path_node(~[id_extra]), path_node(~[id_extra]),
ast::DUMMY_NODE_ID))]) ast::DUMMY_NODE_ID))])
} else { } else {
ast::view_item_extern_mod(id_extra, ast::ViewItemExternMod(id_extra,
Some((format!("extra\\#{}", VERSION).to_managed(), Some((format!("extra\\#{}", VERSION).to_managed(),
ast::CookedStr)), ast::CookedStr)),
ast::DUMMY_NODE_ID) ast::DUMMY_NODE_ID)
}; };
ast::view_item { ast::ViewItem {
node: vi, node: vi,
attrs: ~[], attrs: ~[],
vis: ast::public, vis: ast::Public,
span: DUMMY_SP span: DUMMY_SP
} }
} }
fn mk_test_module(cx: &TestCtxt) -> @ast::item { fn mk_test_module(cx: &TestCtxt) -> @ast::Item {
// Link to extra // Link to extra
let view_items = ~[mk_std(cx)]; let view_items = ~[mk_std(cx)];
@ -322,22 +322,22 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
} }
)).unwrap(); )).unwrap();
let testmod = ast::_mod { let testmod = ast::Mod {
view_items: view_items, view_items: view_items,
items: ~[mainfn, tests], items: ~[mainfn, tests],
}; };
let item_ = ast::item_mod(testmod); let item_ = ast::ItemMod(testmod);
// This attribute tells resolve to let us call unexported functions // This attribute tells resolve to let us call unexported functions
let resolve_unexported_attr = let resolve_unexported_attr =
attr::mk_attr(attr::mk_word_item(@"!resolve_unexported")); attr::mk_attr(attr::mk_word_item(@"!resolve_unexported"));
let item = ast::item { let item = ast::Item {
ident: cx.sess.ident_of("__test"), ident: cx.sess.ident_of("__test"),
attrs: ~[resolve_unexported_attr], attrs: ~[resolve_unexported_attr],
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: item_, node: item_,
vis: ast::public, vis: ast::Public,
span: DUMMY_SP, span: DUMMY_SP,
}; };
@ -375,7 +375,7 @@ fn path_node_global(ids: ~[ast::Ident]) -> ast::Path {
} }
} }
fn mk_tests(cx: &TestCtxt) -> @ast::item { fn mk_tests(cx: &TestCtxt) -> @ast::Item {
// The vector of test_descs for this crate // The vector of test_descs for this crate
let test_descs = mk_test_descs(cx); let test_descs = mk_test_descs(cx);
@ -422,8 +422,8 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
debug!("encoding {}", ast_util::path_name_i(path)); debug!("encoding {}", ast_util::path_name_i(path));
let name_lit: ast::lit = let name_lit: ast::Lit =
nospan(ast::lit_str(ast_util::path_name_i(path).to_managed(), ast::CookedStr)); nospan(ast::LitStr(ast_util::path_name_i(path).to_managed(), ast::CookedStr));
let name_expr = @ast::Expr { let name_expr = @ast::Expr {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,

View file

@ -363,8 +363,8 @@ impl diagnostic::Emitter for RustcEmitter {
fn emit(&self, fn emit(&self,
cmsp: Option<(&codemap::CodeMap, codemap::Span)>, cmsp: Option<(&codemap::CodeMap, codemap::Span)>,
msg: &str, msg: &str,
lvl: diagnostic::level) { lvl: diagnostic::Level) {
if lvl == diagnostic::fatal { if lvl == diagnostic::Fatal {
let this = unsafe { cast::transmute_mut(self) }; let this = unsafe { cast::transmute_mut(self) };
this.ch_capture.send(fatal) this.ch_capture.send(fatal)
} }
@ -434,7 +434,7 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
diagnostic::DefaultEmitter.emit( diagnostic::DefaultEmitter.emit(
None, None,
diagnostic::ice_msg("unexpected failure"), diagnostic::ice_msg("unexpected failure"),
diagnostic::error); diagnostic::Error);
let xs = [ let xs = [
~"the compiler hit an unexpected failure path. \ ~"the compiler hit an unexpected failure path. \
@ -446,7 +446,7 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
for note in xs.iter() { for note in xs.iter() {
diagnostic::DefaultEmitter.emit(None, diagnostic::DefaultEmitter.emit(None,
*note, *note,
diagnostic::note) diagnostic::Note)
} }
} }
// Fail so the process returns a failure code // Fail so the process returns a failure code

View file

@ -83,11 +83,11 @@ pub static tag_item_super_trait_ref: uint = 0x33u;
// discriminator value for variants // discriminator value for variants
pub static tag_disr_val: uint = 0x34u; pub static tag_disr_val: uint = 0x34u;
// used to encode ast_map::path and ast_map::path_elt // used to encode ast_map::Path and ast_map::PathElem
pub static tag_path: uint = 0x40u; pub static tag_path: uint = 0x40u;
pub static tag_path_len: uint = 0x41u; pub static tag_path_len: uint = 0x41u;
pub static tag_path_elt_mod: uint = 0x42u; pub static tag_path_elem_mod: uint = 0x42u;
pub static tag_path_elt_name: uint = 0x43u; pub static tag_path_elem_name: uint = 0x43u;
pub static tag_item_field: uint = 0x44u; pub static tag_item_field: uint = 0x44u;
pub static tag_struct_mut: uint = 0x45u; pub static tag_struct_mut: uint = 0x45u;
@ -191,9 +191,9 @@ pub static tag_impls_impl: uint = 0x84;
pub static tag_items_data_item_inherent_impl: uint = 0x85; pub static tag_items_data_item_inherent_impl: uint = 0x85;
pub static tag_items_data_item_extension_impl: uint = 0x86; pub static tag_items_data_item_extension_impl: uint = 0x86;
pub static tag_path_elt_pretty_name: uint = 0x87; pub static tag_path_elem_pretty_name: uint = 0x87;
pub static tag_path_elt_pretty_name_ident: uint = 0x88; pub static tag_path_elem_pretty_name_ident: uint = 0x88;
pub static tag_path_elt_pretty_name_extra: uint = 0x89; pub static tag_path_elem_pretty_name_extra: uint = 0x89;
pub static tag_region_param_def: uint = 0x100; pub static tag_region_param_def: uint = 0x100;
pub static tag_region_param_def_ident: uint = 0x101; pub static tag_region_param_def_ident: uint = 0x101;

View file

@ -24,7 +24,7 @@ use syntax::attr::AttrMetaMethods;
use syntax::codemap::{Span, DUMMY_SP}; use syntax::codemap::{Span, DUMMY_SP};
use syntax::diagnostic::SpanHandler; use syntax::diagnostic::SpanHandler;
use syntax::parse::token; use syntax::parse::token;
use syntax::parse::token::ident_interner; use syntax::parse::token::IdentInterner;
use syntax::crateid::CrateId; use syntax::crateid::CrateId;
use syntax::visit; use syntax::visit;
@ -33,7 +33,7 @@ use syntax::visit;
pub fn read_crates(sess: Session, pub fn read_crates(sess: Session,
crate: &ast::Crate, crate: &ast::Crate,
os: loader::Os, os: loader::Os,
intr: @ident_interner) { intr: @IdentInterner) {
let mut e = Env { let mut e = Env {
sess: sess, sess: sess,
os: os, os: os,
@ -58,11 +58,11 @@ struct ReadCrateVisitor<'a> {
} }
impl<'a> visit::Visitor<()> for ReadCrateVisitor<'a> { impl<'a> visit::Visitor<()> for ReadCrateVisitor<'a> {
fn visit_view_item(&mut self, a: &ast::view_item, _: ()) { fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) {
visit_view_item(self.e, a); visit_view_item(self.e, a);
visit::walk_view_item(self, a, ()); visit::walk_view_item(self, a, ());
} }
fn visit_item(&mut self, a: &ast::item, _: ()) { fn visit_item(&mut self, a: &ast::Item, _: ()) {
visit_item(self.e, a); visit_item(self.e, a);
visit::walk_item(self, a, ()); visit::walk_item(self, a, ());
} }
@ -114,7 +114,7 @@ struct Env {
os: loader::Os, os: loader::Os,
crate_cache: @RefCell<~[cache_entry]>, crate_cache: @RefCell<~[cache_entry]>,
next_crate_num: ast::CrateNum, next_crate_num: ast::CrateNum,
intr: @ident_interner intr: @IdentInterner
} }
fn visit_crate(e: &Env, c: &ast::Crate) { fn visit_crate(e: &Env, c: &ast::Crate) {
@ -130,9 +130,9 @@ fn visit_crate(e: &Env, c: &ast::Crate) {
} }
} }
fn visit_view_item(e: &mut Env, i: &ast::view_item) { fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
match i.node { match i.node {
ast::view_item_extern_mod(ident, path_opt, id) => { ast::ViewItemExternMod(ident, path_opt, id) => {
let ident = token::ident_to_str(&ident); let ident = token::ident_to_str(&ident);
debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}", debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}",
ident, path_opt); ident, path_opt);
@ -164,9 +164,9 @@ fn visit_view_item(e: &mut Env, i: &ast::view_item) {
} }
} }
fn visit_item(e: &Env, i: &ast::item) { fn visit_item(e: &Env, i: &ast::Item) {
match i.node { match i.node {
ast::item_foreign_mod(ref fm) => { ast::ItemForeignMod(ref fm) => {
if fm.abis.is_rust() || fm.abis.is_intrinsic() { if fm.abis.is_rust() || fm.abis.is_intrinsic() {
return; return;
} }

View file

@ -26,8 +26,8 @@ use syntax::diagnostic::expect;
pub struct StaticMethodInfo { pub struct StaticMethodInfo {
ident: ast::Ident, ident: ast::Ident,
def_id: ast::DefId, def_id: ast::DefId,
purity: ast::purity, purity: ast::Purity,
vis: ast::visibility, vis: ast::Visibility,
} }
pub fn get_symbol(cstore: @cstore::CStore, def: ast::DefId) -> ~str { pub fn get_symbol(cstore: @cstore::CStore, def: ast::DefId) -> ~str {
@ -55,7 +55,7 @@ pub fn each_child_of_item(cstore: @cstore::CStore,
def_id: ast::DefId, def_id: ast::DefId,
callback: |decoder::DefLike, callback: |decoder::DefLike,
ast::Ident, ast::Ident,
ast::visibility|) { ast::Visibility|) {
let crate_data = cstore.get_crate_data(def_id.crate); let crate_data = cstore.get_crate_data(def_id.crate);
let get_crate_data: decoder::GetCrateDataCb = |cnum| { let get_crate_data: decoder::GetCrateDataCb = |cnum| {
cstore.get_crate_data(cnum) cstore.get_crate_data(cnum)
@ -72,7 +72,7 @@ pub fn each_top_level_item_of_crate(cstore: @cstore::CStore,
cnum: ast::CrateNum, cnum: ast::CrateNum,
callback: |decoder::DefLike, callback: |decoder::DefLike,
ast::Ident, ast::Ident,
ast::visibility|) { ast::Visibility|) {
let crate_data = cstore.get_crate_data(cnum); let crate_data = cstore.get_crate_data(cnum);
let get_crate_data: decoder::GetCrateDataCb = |cnum| { let get_crate_data: decoder::GetCrateDataCb = |cnum| {
cstore.get_crate_data(cnum) cstore.get_crate_data(cnum)
@ -83,20 +83,20 @@ pub fn each_top_level_item_of_crate(cstore: @cstore::CStore,
callback) callback)
} }
pub fn get_item_path(tcx: ty::ctxt, def: ast::DefId) -> ast_map::path { pub fn get_item_path(tcx: ty::ctxt, def: ast::DefId) -> ast_map::Path {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.crate);
let path = decoder::get_item_path(cdata, def.node); let path = decoder::get_item_path(cdata, def.node);
// FIXME #1920: This path is not always correct if the crate is not linked // FIXME #1920: This path is not always correct if the crate is not linked
// into the root namespace. // into the root namespace.
vec::append(~[ast_map::path_mod(tcx.sess.ident_of( vec::append(~[ast_map::PathMod(tcx.sess.ident_of(
cdata.name))], path) cdata.name))], path)
} }
pub enum found_ast { pub enum found_ast {
found(ast::inlined_item), found(ast::InlinedItem),
found_parent(ast::DefId, ast::inlined_item), found_parent(ast::DefId, ast::InlinedItem),
not_found, not_found,
} }
@ -133,7 +133,7 @@ pub fn get_method(tcx: ty::ctxt, def: ast::DefId) -> ty::Method {
pub fn get_method_name_and_explicit_self(cstore: @cstore::CStore, pub fn get_method_name_and_explicit_self(cstore: @cstore::CStore,
def: ast::DefId) def: ast::DefId)
-> (ast::Ident, ast::explicit_self_) -> (ast::Ident, ast::ExplicitSelf_)
{ {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.crate);
decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node) decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node)
@ -257,7 +257,7 @@ pub fn get_impl_method(cstore: @cstore::CStore,
pub fn get_item_visibility(cstore: @cstore::CStore, pub fn get_item_visibility(cstore: @cstore::CStore,
def_id: ast::DefId) def_id: ast::DefId)
-> ast::visibility { -> ast::Visibility {
let cdata = cstore.get_crate_data(def_id.crate); let cdata = cstore.get_crate_data(def_id.crate);
decoder::get_item_visibility(cdata, def_id.node) decoder::get_item_visibility(cdata, def_id.node)
} }

View file

@ -18,7 +18,7 @@ use metadata::loader;
use std::cell::RefCell; use std::cell::RefCell;
use std::hashmap::HashMap; use std::hashmap::HashMap;
use syntax::ast; use syntax::ast;
use syntax::parse::token::ident_interner; use syntax::parse::token::IdentInterner;
// A map from external crate numbers (as decoded from some crate file) to // A map from external crate numbers (as decoded from some crate file) to
// local crate numbers (as generated during this session). Each external // local crate numbers (as generated during this session). Each external
@ -66,14 +66,14 @@ pub struct CStore {
priv used_crate_sources: RefCell<~[CrateSource]>, priv used_crate_sources: RefCell<~[CrateSource]>,
priv used_libraries: RefCell<~[(~str, NativeLibaryKind)]>, priv used_libraries: RefCell<~[(~str, NativeLibaryKind)]>,
priv used_link_args: RefCell<~[~str]>, priv used_link_args: RefCell<~[~str]>,
intr: @ident_interner intr: @IdentInterner
} }
// Map from NodeId's of local extern mod statements to crate numbers // Map from NodeId's of local extern mod statements to crate numbers
type extern_mod_crate_map = HashMap<ast::NodeId, ast::CrateNum>; type extern_mod_crate_map = HashMap<ast::NodeId, ast::CrateNum>;
impl CStore { impl CStore {
pub fn new(intr: @ident_interner) -> CStore { pub fn new(intr: @IdentInterner) -> CStore {
CStore { CStore {
metas: RefCell::new(HashMap::new()), metas: RefCell::new(HashMap::new()),
extern_mod_crate_map: RefCell::new(HashMap::new()), extern_mod_crate_map: RefCell::new(HashMap::new()),

View file

@ -36,7 +36,7 @@ use extra::ebml;
use extra::serialize::Decodable; use extra::serialize::Decodable;
use syntax::ast_map; use syntax::ast_map;
use syntax::attr; use syntax::attr;
use syntax::parse::token::{ident_interner, special_idents}; use syntax::parse::token::{IdentInterner, special_idents};
use syntax::print::pprust; use syntax::print::pprust;
use syntax::ast; use syntax::ast;
use syntax::codemap; use syntax::codemap;
@ -152,14 +152,14 @@ fn item_family(item: ebml::Doc) -> Family {
} }
} }
fn item_visibility(item: ebml::Doc) -> ast::visibility { fn item_visibility(item: ebml::Doc) -> ast::Visibility {
match reader::maybe_get_doc(item, tag_items_data_item_visibility) { match reader::maybe_get_doc(item, tag_items_data_item_visibility) {
None => ast::public, None => ast::Public,
Some(visibility_doc) => { Some(visibility_doc) => {
match reader::doc_as_u8(visibility_doc) as char { match reader::doc_as_u8(visibility_doc) as char {
'y' => ast::public, 'y' => ast::Public,
'n' => ast::private, 'n' => ast::Private,
'i' => ast::inherited, 'i' => ast::Inherited,
_ => fail!("unknown visibility character") _ => fail!("unknown visibility character")
} }
} }
@ -306,7 +306,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> ~[ast::DefId] {
return ids; return ids;
} }
pub fn item_path(item_doc: ebml::Doc) -> ast_map::path { pub fn item_path(item_doc: ebml::Doc) -> ast_map::Path {
let path_doc = reader::get_doc(item_doc, tag_path); let path_doc = reader::get_doc(item_doc, tag_path);
let len_doc = reader::get_doc(path_doc, tag_path_len); let len_doc = reader::get_doc(path_doc, tag_path_len);
@ -314,21 +314,21 @@ pub fn item_path(item_doc: ebml::Doc) -> ast_map::path {
let mut result = vec::with_capacity(len); let mut result = vec::with_capacity(len);
reader::docs(path_doc, |tag, elt_doc| { reader::docs(path_doc, |tag, elt_doc| {
if tag == tag_path_elt_mod { if tag == tag_path_elem_mod {
let str = elt_doc.as_str_slice(); let str = elt_doc.as_str_slice();
result.push(ast_map::path_mod(token::str_to_ident(str))); result.push(ast_map::PathMod(token::str_to_ident(str)));
} else if tag == tag_path_elt_name { } else if tag == tag_path_elem_name {
let str = elt_doc.as_str_slice(); let str = elt_doc.as_str_slice();
result.push(ast_map::path_name(token::str_to_ident(str))); result.push(ast_map::PathName(token::str_to_ident(str)));
} else if tag == tag_path_elt_pretty_name { } else if tag == tag_path_elem_pretty_name {
let name_doc = reader::get_doc(elt_doc, let name_doc = reader::get_doc(elt_doc,
tag_path_elt_pretty_name_ident); tag_path_elem_pretty_name_ident);
let extra_doc = reader::get_doc(elt_doc, let extra_doc = reader::get_doc(elt_doc,
tag_path_elt_pretty_name_extra); tag_path_elem_pretty_name_extra);
let str = name_doc.as_str_slice(); let str = name_doc.as_str_slice();
let extra = reader::doc_as_u64(extra_doc); let extra = reader::doc_as_u64(extra_doc);
result.push(ast_map::path_pretty_name(token::str_to_ident(str), result.push(ast_map::PathPrettyName(token::str_to_ident(str),
extra)); extra));
} else { } else {
// ignore tag_path_len element // ignore tag_path_len element
} }
@ -338,7 +338,7 @@ pub fn item_path(item_doc: ebml::Doc) -> ast_map::path {
return result; return result;
} }
fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::Ident { fn item_name(intr: @IdentInterner, item: ebml::Doc) -> ast::Ident {
let name = reader::get_doc(item, tag_paths_data_name); let name = reader::get_doc(item, tag_paths_data_name);
let string = name.as_str_slice(); let string = name.as_str_slice();
match intr.find_equiv(&string) { match intr.find_equiv(&string) {
@ -354,12 +354,12 @@ pub fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
ImmStatic => DlDef(ast::DefStatic(did, false)), ImmStatic => DlDef(ast::DefStatic(did, false)),
MutStatic => DlDef(ast::DefStatic(did, true)), MutStatic => DlDef(ast::DefStatic(did, true)),
Struct => DlDef(ast::DefStruct(did)), Struct => DlDef(ast::DefStruct(did)),
UnsafeFn => DlDef(ast::DefFn(did, ast::unsafe_fn)), UnsafeFn => DlDef(ast::DefFn(did, ast::UnsafeFn)),
Fn => DlDef(ast::DefFn(did, ast::impure_fn)), Fn => DlDef(ast::DefFn(did, ast::ImpureFn)),
ForeignFn => DlDef(ast::DefFn(did, ast::extern_fn)), ForeignFn => DlDef(ast::DefFn(did, ast::ExternFn)),
StaticMethod | UnsafeStaticMethod => { StaticMethod | UnsafeStaticMethod => {
let purity = if fam == UnsafeStaticMethod { ast::unsafe_fn } else let purity = if fam == UnsafeStaticMethod { ast::UnsafeFn } else
{ ast::impure_fn }; { ast::ImpureFn };
// def_static_method carries an optional field of its enclosing // def_static_method carries an optional field of its enclosing
// trait or enclosing impl (if this is an inherent static method). // trait or enclosing impl (if this is an inherent static method).
// So we need to detect whether this is in a trait or not, which // So we need to detect whether this is in a trait or not, which
@ -475,7 +475,7 @@ pub fn get_impl_vtables(cdata: Cmd,
} }
pub fn get_impl_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId, pub fn get_impl_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
name: ast::Ident) -> Option<ast::DefId> { name: ast::Ident) -> Option<ast::DefId> {
let items = reader::get_doc(reader::Doc(cdata.data()), tag_items); let items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
let mut found = None; let mut found = None;
@ -524,13 +524,13 @@ pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
}) })
} }
fn each_child_of_item_or_crate(intr: @ident_interner, fn each_child_of_item_or_crate(intr: @IdentInterner,
cdata: Cmd, cdata: Cmd,
item_doc: ebml::Doc, item_doc: ebml::Doc,
get_crate_data: GetCrateDataCb, get_crate_data: GetCrateDataCb,
callback: |DefLike, callback: |DefLike,
ast::Ident, ast::Ident,
ast::visibility|) { ast::Visibility|) {
// Iterate over all children. // Iterate over all children.
let _ = reader::tagged_docs(item_doc, tag_mod_child, |child_info_doc| { let _ = reader::tagged_docs(item_doc, tag_mod_child, |child_info_doc| {
let child_def_id = reader::with_doc_data(child_info_doc, let child_def_id = reader::with_doc_data(child_info_doc,
@ -644,7 +644,7 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
cdata.cnum); cdata.cnum);
// These items have a public visibility because they're part of // These items have a public visibility because they're part of
// a public re-export. // a public re-export.
callback(def_like, token::str_to_ident(name), ast::public); callback(def_like, token::str_to_ident(name), ast::Public);
} }
} }
@ -653,11 +653,11 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
} }
/// Iterates over each child of the given item. /// Iterates over each child of the given item.
pub fn each_child_of_item(intr: @ident_interner, pub fn each_child_of_item(intr: @IdentInterner,
cdata: Cmd, cdata: Cmd,
id: ast::NodeId, id: ast::NodeId,
get_crate_data: GetCrateDataCb, get_crate_data: GetCrateDataCb,
callback: |DefLike, ast::Ident, ast::visibility|) { callback: |DefLike, ast::Ident, ast::Visibility|) {
// Find the item. // Find the item.
let root_doc = reader::Doc(cdata.data()); let root_doc = reader::Doc(cdata.data());
let items = reader::get_doc(root_doc, tag_items); let items = reader::get_doc(root_doc, tag_items);
@ -674,12 +674,12 @@ pub fn each_child_of_item(intr: @ident_interner,
} }
/// Iterates over all the top-level crate items. /// Iterates over all the top-level crate items.
pub fn each_top_level_item_of_crate(intr: @ident_interner, pub fn each_top_level_item_of_crate(intr: @IdentInterner,
cdata: Cmd, cdata: Cmd,
get_crate_data: GetCrateDataCb, get_crate_data: GetCrateDataCb,
callback: |DefLike, callback: |DefLike,
ast::Ident, ast::Ident,
ast::visibility|) { ast::Visibility|) {
let root_doc = reader::Doc(cdata.data()); let root_doc = reader::Doc(cdata.data());
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info); let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
let crate_items_doc = reader::get_doc(misc_info_doc, let crate_items_doc = reader::get_doc(misc_info_doc,
@ -692,15 +692,15 @@ pub fn each_top_level_item_of_crate(intr: @ident_interner,
callback) callback)
} }
pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> ast_map::path { pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> ast_map::Path {
item_path(lookup_item(id, cdata.data())) item_path(lookup_item(id, cdata.data()))
} }
pub type decode_inlined_item<'a> = 'a |cdata: @cstore::crate_metadata, pub type decode_inlined_item<'a> = 'a |cdata: @cstore::crate_metadata,
tcx: ty::ctxt, tcx: ty::ctxt,
path: ast_map::path, path: ast_map::Path,
par_doc: ebml::Doc| par_doc: ebml::Doc|
-> Option<ast::inlined_item>; -> Option<ast::InlinedItem>;
pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt, pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt,
id: ast::NodeId, id: ast::NodeId,
@ -730,7 +730,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt,
} }
} }
pub fn get_enum_variants(intr: @ident_interner, cdata: Cmd, id: ast::NodeId, pub fn get_enum_variants(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
tcx: ty::ctxt) -> ~[@ty::VariantInfo] { tcx: ty::ctxt) -> ~[@ty::VariantInfo] {
let data = cdata.data(); let data = cdata.data();
let items = reader::get_doc(reader::Doc(data), tag_items); let items = reader::get_doc(reader::Doc(data), tag_items);
@ -760,13 +760,13 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
// for variants -- TEST -- tjc // for variants -- TEST -- tjc
id: *did, id: *did,
disr_val: disr_val, disr_val: disr_val,
vis: ast::inherited}); vis: ast::Inherited});
disr_val += 1; disr_val += 1;
} }
return infos; return infos;
} }
fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ { fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
fn get_mutability(ch: u8) -> ast::Mutability { fn get_mutability(ch: u8) -> ast::Mutability {
match ch as char { match ch as char {
'i' => ast::MutImmutable, 'i' => ast::MutImmutable,
@ -780,21 +780,17 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
let explicit_self_kind = string[0]; let explicit_self_kind = string[0];
match explicit_self_kind as char { match explicit_self_kind as char {
's' => { return ast::sty_static; } 's' => ast::SelfStatic,
'v' => { return ast::sty_value(get_mutability(string[1])); } 'v' => ast::SelfValue(get_mutability(string[1])),
'@' => { return ast::sty_box(get_mutability(string[1])); } '@' => ast::SelfBox(get_mutability(string[1])),
'~' => { return ast::sty_uniq(get_mutability(string[1])); } '~' => ast::SelfUniq(get_mutability(string[1])),
'&' => { // FIXME(#4846) expl. region
// FIXME(#4846) expl. region '&' => ast::SelfRegion(None, get_mutability(string[1])),
return ast::sty_region(None, get_mutability(string[1])); _ => fail!("unknown self type code: `{}`", explicit_self_kind as char)
}
_ => {
fail!("unknown self type code: `{}`", explicit_self_kind as char);
}
} }
} }
fn item_impl_methods(intr: @ident_interner, cdata: Cmd, item: ebml::Doc, fn item_impl_methods(intr: @IdentInterner, cdata: Cmd, item: ebml::Doc,
tcx: ty::ctxt) -> ~[@ty::Method] { tcx: ty::ctxt) -> ~[@ty::Method] {
let mut rslt = ~[]; let mut rslt = ~[];
reader::tagged_docs(item, tag_item_impl_method, |doc| { reader::tagged_docs(item, tag_item_impl_method, |doc| {
@ -807,7 +803,7 @@ fn item_impl_methods(intr: @ident_interner, cdata: Cmd, item: ebml::Doc,
} }
/// Returns information about the given implementation. /// Returns information about the given implementation.
pub fn get_impl(intr: @ident_interner, cdata: Cmd, impl_id: ast::NodeId, pub fn get_impl(intr: @IdentInterner, cdata: Cmd, impl_id: ast::NodeId,
tcx: ty::ctxt) tcx: ty::ctxt)
-> ty::Impl { -> ty::Impl {
let data = cdata.data(); let data = cdata.data();
@ -823,9 +819,9 @@ pub fn get_impl(intr: @ident_interner, cdata: Cmd, impl_id: ast::NodeId,
} }
pub fn get_method_name_and_explicit_self( pub fn get_method_name_and_explicit_self(
intr: @ident_interner, intr: @IdentInterner,
cdata: Cmd, cdata: Cmd,
id: ast::NodeId) -> (ast::Ident, ast::explicit_self_) id: ast::NodeId) -> (ast::Ident, ast::ExplicitSelf_)
{ {
let method_doc = lookup_item(id, cdata.data()); let method_doc = lookup_item(id, cdata.data());
let name = item_name(intr, method_doc); let name = item_name(intr, method_doc);
@ -833,7 +829,7 @@ pub fn get_method_name_and_explicit_self(
(name, explicit_self) (name, explicit_self)
} }
pub fn get_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId, pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
tcx: ty::ctxt) -> ty::Method tcx: ty::ctxt) -> ty::Method
{ {
let method_doc = lookup_item(id, cdata.data()); let method_doc = lookup_item(id, cdata.data());
@ -893,7 +889,7 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
Decodable::decode(&mut decoder) Decodable::decode(&mut decoder)
} }
pub fn get_provided_trait_methods(intr: @ident_interner, cdata: Cmd, pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,
id: ast::NodeId, tcx: ty::ctxt) -> id: ast::NodeId, tcx: ty::ctxt) ->
~[@ty::Method] { ~[@ty::Method] {
let data = cdata.data(); let data = cdata.data();
@ -947,7 +943,7 @@ pub fn get_type_name_if_impl(cdata: Cmd,
ret ret
} }
pub fn get_static_methods_if_impl(intr: @ident_interner, pub fn get_static_methods_if_impl(intr: @IdentInterner,
cdata: Cmd, cdata: Cmd,
node_id: ast::NodeId) node_id: ast::NodeId)
-> Option<~[StaticMethodInfo]> { -> Option<~[StaticMethodInfo]> {
@ -977,8 +973,8 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
StaticMethod | UnsafeStaticMethod => { StaticMethod | UnsafeStaticMethod => {
let purity; let purity;
match item_family(impl_method_doc) { match item_family(impl_method_doc) {
StaticMethod => purity = ast::impure_fn, StaticMethod => purity = ast::ImpureFn,
UnsafeStaticMethod => purity = ast::unsafe_fn, UnsafeStaticMethod => purity = ast::UnsafeFn,
_ => fail!() _ => fail!()
} }
@ -1009,16 +1005,16 @@ pub fn get_item_attrs(cdata: Cmd,
}); });
} }
fn struct_field_family_to_visibility(family: Family) -> ast::visibility { fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
match family { match family {
PublicField => ast::public, PublicField => ast::Public,
PrivateField => ast::private, PrivateField => ast::Private,
InheritedField => ast::inherited, InheritedField => ast::Inherited,
_ => fail!() _ => fail!()
} }
} }
pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId) pub fn get_struct_fields(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId)
-> ~[ty::field_ty] { -> ~[ty::field_ty] {
let data = cdata.data(); let data = cdata.data();
let item = lookup_item(id, data); let item = lookup_item(id, data);
@ -1042,7 +1038,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
result.push(ty::field_ty { result.push(ty::field_ty {
name: special_idents::unnamed_field.name, name: special_idents::unnamed_field.name,
id: did, id: did,
vis: ast::inherited, vis: ast::Inherited,
}); });
true true
}); });
@ -1050,7 +1046,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
} }
pub fn get_item_visibility(cdata: Cmd, id: ast::NodeId) pub fn get_item_visibility(cdata: Cmd, id: ast::NodeId)
-> ast::visibility { -> ast::Visibility {
item_visibility(lookup_item(id, cdata.data())) item_visibility(lookup_item(id, cdata.data()))
} }
@ -1109,7 +1105,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::Attribute] {
return attrs; return attrs;
} }
fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str, fn list_crate_attributes(intr: @IdentInterner, md: ebml::Doc, hash: &str,
out: &mut io::Writer) { out: &mut io::Writer) {
write!(out, "=Crate Attributes ({})=\n", hash); write!(out, "=Crate Attributes ({})=\n", hash);
@ -1179,7 +1175,7 @@ pub fn get_crate_vers(data: &[u8]) -> @str {
} }
} }
pub fn list_crate_metadata(intr: @ident_interner, bytes: &[u8], pub fn list_crate_metadata(intr: @IdentInterner, bytes: &[u8],
out: &mut io::Writer) { out: &mut io::Writer) {
let hash = get_crate_hash(bytes); let hash = get_crate_hash(bytes);
let md = reader::Doc(bytes); let md = reader::Doc(bytes);

View file

@ -49,16 +49,16 @@ use writer = extra::ebml::writer;
// used by astencode: // used by astencode:
type abbrev_map = @RefCell<HashMap<ty::t, tyencode::ty_abbrev>>; type abbrev_map = @RefCell<HashMap<ty::t, tyencode::ty_abbrev>>;
/// A borrowed version of ast::inlined_item. /// A borrowed version of ast::InlinedItem.
pub enum InlinedItemRef<'a> { pub enum InlinedItemRef<'a> {
ii_item_ref(&'a ast::item), IIItemRef(&'a ast::Item),
ii_method_ref(ast::DefId, bool, &'a ast::method), IIMethodRef(ast::DefId, bool, &'a ast::Method),
ii_foreign_ref(&'a ast::foreign_item) IIForeignRef(&'a ast::ForeignItem)
} }
pub type encode_inlined_item<'a> = 'a |ecx: &EncodeContext, pub type encode_inlined_item<'a> = 'a |ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
ii: InlinedItemRef|; ii: InlinedItemRef|;
pub struct EncodeParams<'a> { pub struct EncodeParams<'a> {
@ -318,17 +318,17 @@ fn encode_parent_item(ebml_w: &mut writer::Encoder, id: DefId) {
fn encode_struct_fields(ecx: &EncodeContext, fn encode_struct_fields(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
def: @struct_def) { def: @StructDef) {
for f in def.fields.iter() { for f in def.fields.iter() {
match f.node.kind { match f.node.kind {
named_field(ident, vis) => { NamedField(ident, vis) => {
ebml_w.start_tag(tag_item_field); ebml_w.start_tag(tag_item_field);
encode_struct_field_family(ebml_w, vis); encode_struct_field_family(ebml_w, vis);
encode_name(ecx, ebml_w, ident); encode_name(ecx, ebml_w, ident);
encode_def_id(ebml_w, local_def(f.node.id)); encode_def_id(ebml_w, local_def(f.node.id));
ebml_w.end_tag(); ebml_w.end_tag();
} }
unnamed_field => { UnnamedField => {
ebml_w.start_tag(tag_item_unnamed_field); ebml_w.start_tag(tag_item_unnamed_field);
encode_def_id(ebml_w, local_def(f.node.id)); encode_def_id(ebml_w, local_def(f.node.id));
ebml_w.end_tag(); ebml_w.end_tag();
@ -340,8 +340,8 @@ fn encode_struct_fields(ecx: &EncodeContext,
fn encode_enum_variant_info(ecx: &EncodeContext, fn encode_enum_variant_info(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
id: NodeId, id: NodeId,
variants: &[P<variant>], variants: &[P<Variant>],
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
index: @RefCell<~[entry<i64>]>, index: @RefCell<~[entry<i64>]>,
generics: &ast::Generics) { generics: &ast::Generics) {
debug!("encode_enum_variant_info(id={:?})", id); debug!("encode_enum_variant_info(id={:?})", id);
@ -362,20 +362,20 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id); encode_def_id(ebml_w, def_id);
match variant.node.kind { match variant.node.kind {
ast::tuple_variant_kind(_) => encode_family(ebml_w, 'v'), ast::TupleVariantKind(_) => encode_family(ebml_w, 'v'),
ast::struct_variant_kind(_) => encode_family(ebml_w, 'V') ast::StructVariantKind(_) => encode_family(ebml_w, 'V')
} }
encode_name(ecx, ebml_w, variant.node.name); encode_name(ecx, ebml_w, variant.node.name);
encode_parent_item(ebml_w, local_def(id)); encode_parent_item(ebml_w, local_def(id));
encode_visibility(ebml_w, variant.node.vis); encode_visibility(ebml_w, variant.node.vis);
encode_attributes(ebml_w, variant.node.attrs); encode_attributes(ebml_w, variant.node.attrs);
match variant.node.kind { match variant.node.kind {
ast::tuple_variant_kind(ref args) ast::TupleVariantKind(ref args)
if args.len() > 0 && generics.ty_params.len() == 0 => { if args.len() > 0 && generics.ty_params.len() == 0 => {
encode_symbol(ecx, ebml_w, variant.node.id); encode_symbol(ecx, ebml_w, variant.node.id);
} }
ast::tuple_variant_kind(_) => {}, ast::TupleVariantKind(_) => {},
ast::struct_variant_kind(def) => { ast::StructVariantKind(def) => {
let idx = encode_info_for_struct(ecx, ebml_w, path, let idx = encode_info_for_struct(ecx, ebml_w, path,
def.fields, index); def.fields, index);
encode_struct_fields(ecx, ebml_w, def); encode_struct_fields(ecx, ebml_w, def);
@ -390,7 +390,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
encode_bounds_and_type(ebml_w, ecx, encode_bounds_and_type(ebml_w, ecx,
&lookup_item_type(ecx.tcx, def_id)); &lookup_item_type(ecx.tcx, def_id));
encode_path(ecx, ebml_w, path, encode_path(ecx, ebml_w, path,
ast_map::path_name(variant.node.name)); ast_map::PathName(variant.node.name));
ebml_w.end_tag(); ebml_w.end_tag();
disr_val += 1; disr_val += 1;
i += 1; i += 1;
@ -399,23 +399,23 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
fn encode_path(ecx: &EncodeContext, fn encode_path(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
name: ast_map::path_elt) { name: ast_map::PathElem) {
fn encode_path_elt(ecx: &EncodeContext, fn encode_path_elem(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
elt: ast_map::path_elt) { elt: ast_map::PathElem) {
match elt { match elt {
ast_map::path_mod(n) => { ast_map::PathMod(n) => {
ebml_w.wr_tagged_str(tag_path_elt_mod, ecx.tcx.sess.str_of(n)); ebml_w.wr_tagged_str(tag_path_elem_mod, ecx.tcx.sess.str_of(n));
} }
ast_map::path_name(n) => { ast_map::PathName(n) => {
ebml_w.wr_tagged_str(tag_path_elt_name, ecx.tcx.sess.str_of(n)); ebml_w.wr_tagged_str(tag_path_elem_name, ecx.tcx.sess.str_of(n));
} }
ast_map::path_pretty_name(n, extra) => { ast_map::PathPrettyName(n, extra) => {
ebml_w.start_tag(tag_path_elt_pretty_name); ebml_w.start_tag(tag_path_elem_pretty_name);
ebml_w.wr_tagged_str(tag_path_elt_pretty_name_ident, ebml_w.wr_tagged_str(tag_path_elem_pretty_name_ident,
ecx.tcx.sess.str_of(n)); ecx.tcx.sess.str_of(n));
ebml_w.wr_tagged_u64(tag_path_elt_pretty_name_extra, extra); ebml_w.wr_tagged_u64(tag_path_elem_pretty_name_extra, extra);
ebml_w.end_tag(); ebml_w.end_tag();
} }
} }
@ -424,9 +424,9 @@ fn encode_path(ecx: &EncodeContext,
ebml_w.start_tag(tag_path); ebml_w.start_tag(tag_path);
ebml_w.wr_tagged_u32(tag_path_len, (path.len() + 1) as u32); ebml_w.wr_tagged_u32(tag_path_len, (path.len() + 1) as u32);
for pe in path.iter() { for pe in path.iter() {
encode_path_elt(ecx, ebml_w, *pe); encode_path_elem(ecx, ebml_w, *pe);
} }
encode_path_elt(ecx, ebml_w, name); encode_path_elem(ecx, ebml_w, name);
ebml_w.end_tag(); ebml_w.end_tag();
} }
@ -457,7 +457,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
let implementations = implementations.borrow(); let implementations = implementations.borrow();
for &base_impl in implementations.get().iter() { for &base_impl in implementations.get().iter() {
for &m in base_impl.methods.iter() { for &m in base_impl.methods.iter() {
if m.explicit_self == ast::sty_static { if m.explicit_self == ast::SelfStatic {
encode_reexported_static_method(ecx, ebml_w, exp, encode_reexported_static_method(ecx, ebml_w, exp,
m.def_id, m.ident); m.def_id, m.ident);
} }
@ -478,7 +478,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
match trait_methods_cache.get().find(&exp.def_id) { match trait_methods_cache.get().find(&exp.def_id) {
Some(methods) => { Some(methods) => {
for &m in methods.iter() { for &m in methods.iter() {
if m.explicit_self == ast::sty_static { if m.explicit_self == ast::SelfStatic {
encode_reexported_static_method(ecx, ebml_w, exp, encode_reexported_static_method(ecx, ebml_w, exp,
m.def_id, m.ident); m.def_id, m.ident);
} }
@ -492,11 +492,11 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
fn encode_reexported_static_methods(ecx: &EncodeContext, fn encode_reexported_static_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
mod_path: &[ast_map::path_elt], mod_path: &[ast_map::PathElem],
exp: &middle::resolve::Export2) { exp: &middle::resolve::Export2) {
let items = ecx.tcx.items.borrow(); let items = ecx.tcx.items.borrow();
match items.get().find(&exp.def_id.node) { match items.get().find(&exp.def_id.node) {
Some(&ast_map::node_item(item, path)) => { Some(&ast_map::NodeItem(item, path)) => {
let original_name = ecx.tcx.sess.str_of(item.ident); let original_name = ecx.tcx.sess.str_of(item.ident);
// //
@ -533,10 +533,10 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
/// * For enums, iterates through the node IDs of the variants. /// * For enums, iterates through the node IDs of the variants.
/// ///
/// * For newtype structs, iterates through the node ID of the constructor. /// * For newtype structs, iterates through the node ID of the constructor.
fn each_auxiliary_node_id(item: @item, callback: |NodeId| -> bool) -> bool { fn each_auxiliary_node_id(item: @Item, callback: |NodeId| -> bool) -> bool {
let mut continue_ = true; let mut continue_ = true;
match item.node { match item.node {
item_enum(ref enum_def, _) => { ItemEnum(ref enum_def, _) => {
for variant in enum_def.variants.iter() { for variant in enum_def.variants.iter() {
continue_ = callback(variant.node.id); continue_ = callback(variant.node.id);
if !continue_ { if !continue_ {
@ -544,12 +544,12 @@ fn each_auxiliary_node_id(item: @item, callback: |NodeId| -> bool) -> bool {
} }
} }
} }
item_struct(struct_def, _) => { ItemStruct(struct_def, _) => {
// If this is a newtype struct, return the constructor. // If this is a newtype struct, return the constructor.
match struct_def.ctor_id { match struct_def.ctor_id {
Some(ctor_id) if struct_def.fields.len() > 0 && Some(ctor_id) if struct_def.fields.len() > 0 &&
struct_def.fields[0].node.kind == struct_def.fields[0].node.kind ==
ast::unnamed_field => { ast::UnnamedField => {
continue_ = callback(ctor_id); continue_ = callback(ctor_id);
} }
_ => {} _ => {}
@ -564,7 +564,7 @@ fn each_auxiliary_node_id(item: @item, callback: |NodeId| -> bool) -> bool {
fn encode_reexports(ecx: &EncodeContext, fn encode_reexports(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
id: NodeId, id: NodeId,
path: &[ast_map::path_elt]) { path: &[ast_map::PathElem]) {
debug!("(encoding info for module) encoding reexports for {}", id); debug!("(encoding info for module) encoding reexports for {}", id);
let reexports2 = ecx.reexports2.borrow(); let reexports2 = ecx.reexports2.borrow();
match reexports2.get().find(&id) { match reexports2.get().find(&id) {
@ -597,11 +597,11 @@ fn encode_reexports(ecx: &EncodeContext,
fn encode_info_for_mod(ecx: &EncodeContext, fn encode_info_for_mod(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
md: &_mod, md: &Mod,
id: NodeId, id: NodeId,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
name: Ident, name: Ident,
vis: visibility) { vis: Visibility) {
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(id)); encode_def_id(ebml_w, local_def(id));
encode_family(ebml_w, 'm'); encode_family(ebml_w, 'm');
@ -622,7 +622,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
}); });
match item.node { match item.node {
item_impl(..) => { ItemImpl(..) => {
let (ident, did) = (item.ident, item.id); let (ident, did) = (item.ident, item.id);
debug!("(encoding info for module) ... encoding impl {} \ debug!("(encoding info for module) ... encoding impl {} \
({:?}/{:?})", ({:?}/{:?})",
@ -638,11 +638,11 @@ fn encode_info_for_mod(ecx: &EncodeContext,
} }
} }
encode_path(ecx, ebml_w, path, ast_map::path_mod(name)); encode_path(ecx, ebml_w, path, ast_map::PathMod(name));
encode_visibility(ebml_w, vis); encode_visibility(ebml_w, vis);
// Encode the reexports of this module, if this module is public. // Encode the reexports of this module, if this module is public.
if vis == public { if vis == Public {
debug!("(encoding info for module) encoding reexports for {}", id); debug!("(encoding info for module) encoding reexports for {}", id);
encode_reexports(ecx, ebml_w, id, path); encode_reexports(ecx, ebml_w, id, path);
} }
@ -651,47 +651,47 @@ fn encode_info_for_mod(ecx: &EncodeContext,
} }
fn encode_struct_field_family(ebml_w: &mut writer::Encoder, fn encode_struct_field_family(ebml_w: &mut writer::Encoder,
visibility: visibility) { visibility: Visibility) {
encode_family(ebml_w, match visibility { encode_family(ebml_w, match visibility {
public => 'g', Public => 'g',
private => 'j', Private => 'j',
inherited => 'N' Inherited => 'N'
}); });
} }
fn encode_visibility(ebml_w: &mut writer::Encoder, visibility: visibility) { fn encode_visibility(ebml_w: &mut writer::Encoder, visibility: Visibility) {
ebml_w.start_tag(tag_items_data_item_visibility); ebml_w.start_tag(tag_items_data_item_visibility);
let ch = match visibility { let ch = match visibility {
public => 'y', Public => 'y',
private => 'n', Private => 'n',
inherited => 'i', Inherited => 'i',
}; };
ebml_w.wr_str(str::from_char(ch)); ebml_w.wr_str(str::from_char(ch));
ebml_w.end_tag(); ebml_w.end_tag();
} }
fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explicit_self_) { fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::ExplicitSelf_) {
ebml_w.start_tag(tag_item_trait_method_explicit_self); ebml_w.start_tag(tag_item_trait_method_explicit_self);
// Encode the base self type. // Encode the base self type.
match explicit_self { match explicit_self {
sty_static => { SelfStatic => {
ebml_w.writer.write(&[ 's' as u8 ]); ebml_w.writer.write(&[ 's' as u8 ]);
} }
sty_value(m) => { SelfValue(m) => {
ebml_w.writer.write(&[ 'v' as u8 ]); ebml_w.writer.write(&[ 'v' as u8 ]);
encode_mutability(ebml_w, m); encode_mutability(ebml_w, m);
} }
sty_region(_, m) => { SelfRegion(_, m) => {
// FIXME(#4846) encode custom lifetime // FIXME(#4846) encode custom lifetime
ebml_w.writer.write(&[ '&' as u8 ]); ebml_w.writer.write(&[ '&' as u8 ]);
encode_mutability(ebml_w, m); encode_mutability(ebml_w, m);
} }
sty_box(m) => { SelfBox(m) => {
ebml_w.writer.write(&[ '@' as u8 ]); ebml_w.writer.write(&[ '@' as u8 ]);
encode_mutability(ebml_w, m); encode_mutability(ebml_w, m);
} }
sty_uniq(m) => { SelfUniq(m) => {
ebml_w.writer.write(&[ '~' as u8 ]); ebml_w.writer.write(&[ '~' as u8 ]);
encode_mutability(ebml_w, m); encode_mutability(ebml_w, m);
} }
@ -727,8 +727,8 @@ fn encode_provided_source(ebml_w: &mut writer::Encoder,
/* Returns an index of items in this class */ /* Returns an index of items in this class */
fn encode_info_for_struct(ecx: &EncodeContext, fn encode_info_for_struct(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
fields: &[struct_field], fields: &[StructField],
global_index: @RefCell<~[entry<i64>]>) global_index: @RefCell<~[entry<i64>]>)
-> ~[entry<i64>] { -> ~[entry<i64>] {
/* Each class has its own index, since different classes /* Each class has its own index, since different classes
@ -739,8 +739,8 @@ fn encode_info_for_struct(ecx: &EncodeContext,
private fields to get the offsets right */ private fields to get the offsets right */
for field in fields.iter() { for field in fields.iter() {
let (nm, vis) = match field.node.kind { let (nm, vis) = match field.node.kind {
named_field(nm, vis) => (nm, vis), NamedField(nm, vis) => (nm, vis),
unnamed_field => (special_idents::unnamed_field, inherited) UnnamedField => (special_idents::unnamed_field, Inherited)
}; };
let id = field.node.id; let id = field.node.id;
@ -757,7 +757,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
tcx.sess.str_of(nm), id); tcx.sess.str_of(nm), id);
encode_struct_field_family(ebml_w, vis); encode_struct_field_family(ebml_w, vis);
encode_name(ecx, ebml_w, nm); encode_name(ecx, ebml_w, nm);
encode_path(ecx, ebml_w, path, ast_map::path_name(nm)); encode_path(ecx, ebml_w, path, ast_map::PathName(nm));
encode_type(ecx, ebml_w, node_id_to_type(tcx, id)); encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
encode_def_id(ebml_w, local_def(id)); encode_def_id(ebml_w, local_def(id));
ebml_w.end_tag(); ebml_w.end_tag();
@ -767,7 +767,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
fn encode_info_for_struct_ctor(ecx: &EncodeContext, fn encode_info_for_struct_ctor(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
name: ast::Ident, name: ast::Ident,
ctor_id: NodeId, ctor_id: NodeId,
index: @RefCell<~[entry<i64>]>, index: @RefCell<~[entry<i64>]>,
@ -785,7 +785,7 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
encode_family(ebml_w, 'f'); encode_family(ebml_w, 'f');
encode_name(ecx, ebml_w, name); encode_name(ecx, ebml_w, name);
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, ctor_id)); encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, ctor_id));
encode_path(ecx, ebml_w, path, ast_map::path_name(name)); encode_path(ecx, ebml_w, path, ast_map::PathName(name));
encode_parent_item(ebml_w, local_def(struct_id)); encode_parent_item(ebml_w, local_def(struct_id));
let item_symbols = ecx.item_symbols.borrow(); let item_symbols = ecx.item_symbols.borrow();
@ -810,7 +810,7 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
encode_explicit_self(ebml_w, method_ty.explicit_self); encode_explicit_self(ebml_w, method_ty.explicit_self);
let purity = method_ty.fty.purity; let purity = method_ty.fty.purity;
match method_ty.explicit_self { match method_ty.explicit_self {
ast::sty_static => { ast::SelfStatic => {
encode_family(ebml_w, purity_static_method_family(purity)); encode_family(ebml_w, purity_static_method_family(purity));
} }
_ => encode_family(ebml_w, purity_fn_family(purity)) _ => encode_family(ebml_w, purity_fn_family(purity))
@ -821,10 +821,10 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
fn encode_info_for_method(ecx: &EncodeContext, fn encode_info_for_method(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
m: &ty::Method, m: &ty::Method,
impl_path: &[ast_map::path_elt], impl_path: &[ast_map::PathElem],
is_default_impl: bool, is_default_impl: bool,
parent_id: NodeId, parent_id: NodeId,
ast_method_opt: Option<@method>) { ast_method_opt: Option<@Method>) {
debug!("encode_info_for_method: {:?} {}", m.def_id, debug!("encode_info_for_method: {:?} {}", m.def_id,
ecx.tcx.sess.str_of(m.ident)); ecx.tcx.sess.str_of(m.ident));
@ -837,7 +837,7 @@ fn encode_info_for_method(ecx: &EncodeContext,
let tpt = lookup_item_type(ecx.tcx, m.def_id); let tpt = lookup_item_type(ecx.tcx, m.def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt); encode_bounds_and_type(ebml_w, ecx, &tpt);
encode_path(ecx, ebml_w, impl_path, ast_map::path_name(m.ident)); encode_path(ecx, ebml_w, impl_path, ast_map::PathName(m.ident));
match ast_method_opt { match ast_method_opt {
Some(ast_method) => encode_attributes(ebml_w, ast_method.attrs), Some(ast_method) => encode_attributes(ebml_w, ast_method.attrs),
None => () None => ()
@ -849,7 +849,7 @@ fn encode_info_for_method(ecx: &EncodeContext,
|| should_inline(ast_method.attrs) { || should_inline(ast_method.attrs) {
(ecx.encode_inlined_item)( (ecx.encode_inlined_item)(
ecx, ebml_w, impl_path, ecx, ebml_w, impl_path,
ii_method_ref(local_def(parent_id), false, ast_method)); IIMethodRef(local_def(parent_id), false, ast_method));
} else { } else {
encode_symbol(ecx, ebml_w, m.def_id.node); encode_symbol(ecx, ebml_w, m.def_id.node);
} }
@ -858,19 +858,19 @@ fn encode_info_for_method(ecx: &EncodeContext,
ebml_w.end_tag(); ebml_w.end_tag();
} }
fn purity_fn_family(p: purity) -> char { fn purity_fn_family(p: Purity) -> char {
match p { match p {
unsafe_fn => 'u', UnsafeFn => 'u',
impure_fn => 'f', ImpureFn => 'f',
extern_fn => 'e' ExternFn => 'e'
} }
} }
fn purity_static_method_family(p: purity) -> char { fn purity_static_method_family(p: Purity) -> char {
match p { match p {
unsafe_fn => 'U', UnsafeFn => 'U',
impure_fn => 'F', ImpureFn => 'F',
_ => fail!("extern fn can't be static") _ => fail!("extern fn can't be static")
} }
} }
@ -921,13 +921,13 @@ fn encode_extension_implementations(ecx: &EncodeContext,
fn encode_info_for_item(ecx: &EncodeContext, fn encode_info_for_item(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
item: &item, item: &Item,
index: @RefCell<~[entry<i64>]>, index: @RefCell<~[entry<i64>]>,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
vis: ast::visibility) { vis: ast::Visibility) {
let tcx = ecx.tcx; let tcx = ecx.tcx;
fn add_to_index(item: &item, ebml_w: &writer::Encoder, fn add_to_index(item: &Item, ebml_w: &writer::Encoder,
index: @RefCell<~[entry<i64>]>) { index: @RefCell<~[entry<i64>]>) {
let mut index = index.borrow_mut(); let mut index = index.borrow_mut();
index.get().push(entry { index.get().push(entry {
@ -942,7 +942,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
let def_id = local_def(item.id); let def_id = local_def(item.id);
match item.node { match item.node {
item_static(_, m, _) => { ItemStatic(_, m, _) => {
add_to_index(); add_to_index();
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id); encode_def_id(ebml_w, def_id);
@ -954,7 +954,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_symbol(ecx, ebml_w, item.id); encode_symbol(ecx, ebml_w, item.id);
encode_name(ecx, ebml_w, item.ident); encode_name(ecx, ebml_w, item.ident);
let elt = ast_map::path_pretty_name(item.ident, item.id as u64); let elt = ast_map::PathPrettyName(item.ident, item.id as u64);
encode_path(ecx, ebml_w, path, elt); encode_path(ecx, ebml_w, path, elt);
let non_inlineable; let non_inlineable;
@ -964,12 +964,12 @@ fn encode_info_for_item(ecx: &EncodeContext,
} }
if !non_inlineable { if !non_inlineable {
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item_ref(item)); (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item));
} }
encode_visibility(ebml_w, vis); encode_visibility(ebml_w, vis);
ebml_w.end_tag(); ebml_w.end_tag();
} }
item_fn(_, purity, _, ref generics, _) => { ItemFn(_, purity, _, ref generics, _) => {
add_to_index(); add_to_index();
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id); encode_def_id(ebml_w, def_id);
@ -977,17 +977,17 @@ fn encode_info_for_item(ecx: &EncodeContext,
let tps_len = generics.ty_params.len(); let tps_len = generics.ty_params.len();
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ecx, ebml_w, item.ident); encode_name(ecx, ebml_w, item.ident);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident));
encode_attributes(ebml_w, item.attrs); encode_attributes(ebml_w, item.attrs);
if tps_len > 0u || should_inline(item.attrs) { if tps_len > 0u || should_inline(item.attrs) {
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item_ref(item)); (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item));
} else { } else {
encode_symbol(ecx, ebml_w, item.id); encode_symbol(ecx, ebml_w, item.id);
} }
encode_visibility(ebml_w, vis); encode_visibility(ebml_w, vis);
ebml_w.end_tag(); ebml_w.end_tag();
} }
item_mod(ref m) => { ItemMod(ref m) => {
add_to_index(); add_to_index();
encode_info_for_mod(ecx, encode_info_for_mod(ecx,
ebml_w, ebml_w,
@ -997,13 +997,13 @@ fn encode_info_for_item(ecx: &EncodeContext,
item.ident, item.ident,
item.vis); item.vis);
} }
item_foreign_mod(ref fm) => { ItemForeignMod(ref fm) => {
add_to_index(); add_to_index();
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id); encode_def_id(ebml_w, def_id);
encode_family(ebml_w, 'n'); encode_family(ebml_w, 'n');
encode_name(ecx, ebml_w, item.ident); encode_name(ecx, ebml_w, item.ident);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident));
// Encode all the items in this module. // Encode all the items in this module.
for foreign_item in fm.items.iter() { for foreign_item in fm.items.iter() {
@ -1014,18 +1014,18 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_visibility(ebml_w, vis); encode_visibility(ebml_w, vis);
ebml_w.end_tag(); ebml_w.end_tag();
} }
item_ty(..) => { ItemTy(..) => {
add_to_index(); add_to_index();
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id); encode_def_id(ebml_w, def_id);
encode_family(ebml_w, 'y'); encode_family(ebml_w, 'y');
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ecx, ebml_w, item.ident); encode_name(ecx, ebml_w, item.ident);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident));
encode_visibility(ebml_w, vis); encode_visibility(ebml_w, vis);
ebml_w.end_tag(); ebml_w.end_tag();
} }
item_enum(ref enum_definition, ref generics) => { ItemEnum(ref enum_definition, ref generics) => {
add_to_index(); add_to_index();
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
@ -1038,8 +1038,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
for v in (*enum_definition).variants.iter() { for v in (*enum_definition).variants.iter() {
encode_variant_id(ebml_w, local_def(v.node.id)); encode_variant_id(ebml_w, local_def(v.node.id));
} }
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item_ref(item)); (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item));
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident));
// Encode inherent implementations for this enumeration. // Encode inherent implementations for this enumeration.
encode_inherent_implementations(ecx, ebml_w, def_id); encode_inherent_implementations(ecx, ebml_w, def_id);
@ -1055,7 +1055,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
index, index,
generics); generics);
} }
item_struct(struct_def, _) => { ItemStruct(struct_def, _) => {
/* First, encode the fields /* First, encode the fields
These come first because we need to write them to make These come first because we need to write them to make
the index, and the index needs to be in the item for the the index, and the index needs to be in the item for the
@ -1075,7 +1075,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_item_variances(ebml_w, ecx, item.id); encode_item_variances(ebml_w, ecx, item.id);
encode_name(ecx, ebml_w, item.ident); encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs); encode_attributes(ebml_w, item.attrs);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident));
encode_visibility(ebml_w, vis); encode_visibility(ebml_w, vis);
/* Encode def_ids for each field and method /* Encode def_ids for each field and method
@ -1083,7 +1083,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
needs to know*/ needs to know*/
encode_struct_fields(ecx, ebml_w, struct_def); encode_struct_fields(ecx, ebml_w, struct_def);
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item_ref(item)); (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item));
// Encode inherent implementations for this structure. // Encode inherent implementations for this structure.
encode_inherent_implementations(ecx, ebml_w, def_id); encode_inherent_implementations(ecx, ebml_w, def_id);
@ -1096,7 +1096,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// If this is a tuple- or enum-like struct, encode the type of the // If this is a tuple- or enum-like struct, encode the type of the
// constructor. // constructor.
if struct_def.fields.len() > 0 && if struct_def.fields.len() > 0 &&
struct_def.fields[0].node.kind == ast::unnamed_field { struct_def.fields[0].node.kind == ast::UnnamedField {
let ctor_id = match struct_def.ctor_id { let ctor_id = match struct_def.ctor_id {
Some(ctor_id) => ctor_id, Some(ctor_id) => ctor_id,
None => ecx.tcx.sess.bug("struct def didn't have ctor id"), None => ecx.tcx.sess.bug("struct def didn't have ctor id"),
@ -1111,7 +1111,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
def_id.node); def_id.node);
} }
} }
item_impl(_, ref opt_trait, ty, ref ast_methods) => { ItemImpl(_, ref opt_trait, ty, ref ast_methods) => {
// We need to encode information about the default methods we // We need to encode information about the default methods we
// have inherited, so we drive this based on the impl structure. // have inherited, so we drive this based on the impl structure.
let impls = tcx.impls.borrow(); let impls = tcx.impls.borrow();
@ -1125,8 +1125,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(ecx, ebml_w, item.ident); encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs); encode_attributes(ebml_w, item.attrs);
match ty.node { match ty.node {
ast::ty_path(ref path, ref bounds, _) if path.segments ast::TyPath(ref path, ref bounds, _) if path.segments
.len() == 1 => { .len() == 1 => {
assert!(bounds.is_none()); assert!(bounds.is_none());
encode_impl_type_basename(ecx, ebml_w, encode_impl_type_basename(ecx, ebml_w,
ast_util::path_to_ident(path)); ast_util::path_to_ident(path));
@ -1180,7 +1180,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
ast_method) ast_method)
} }
} }
item_trait(_, ref super_traits, ref ms) => { ItemTrait(_, ref super_traits, ref ms) => {
add_to_index(); add_to_index();
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id); encode_def_id(ebml_w, def_id);
@ -1204,7 +1204,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
ebml_w.wr_str(def_to_str(method_def_id)); ebml_w.wr_str(def_to_str(method_def_id));
ebml_w.end_tag(); ebml_w.end_tag();
} }
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident));
// FIXME(#8559): This should use the tcx's supertrait cache instead of // FIXME(#8559): This should use the tcx's supertrait cache instead of
// reading the AST's list, because the former has already filtered out // reading the AST's list, because the former has already filtered out
// the builtin-kinds-as-supertraits. See corresponding fixme in decoder. // the builtin-kinds-as-supertraits. See corresponding fixme in decoder.
@ -1240,11 +1240,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_parent_item(ebml_w, def_id); encode_parent_item(ebml_w, def_id);
let mut trait_path = vec::append(~[], path); let mut trait_path = vec::append(~[], path);
trait_path.push(ast_map::path_name(item.ident)); trait_path.push(ast_map::PathName(item.ident));
encode_path(ecx, ebml_w, trait_path, ast_map::path_name(method_ty.ident)); encode_path(ecx, ebml_w, trait_path, ast_map::PathName(method_ty.ident));
match method_ty.explicit_self { match method_ty.explicit_self {
sty_static => { SelfStatic => {
encode_family(ebml_w, encode_family(ebml_w,
purity_static_method_family( purity_static_method_family(
method_ty.fty.purity)); method_ty.fty.purity));
@ -1261,16 +1261,16 @@ fn encode_info_for_item(ecx: &EncodeContext,
} }
match ms[i] { match ms[i] {
required(ref tm) => { Required(ref tm) => {
encode_attributes(ebml_w, tm.attrs); encode_attributes(ebml_w, tm.attrs);
encode_method_sort(ebml_w, 'r'); encode_method_sort(ebml_w, 'r');
} }
provided(m) => { Provided(m) => {
encode_attributes(ebml_w, m.attrs); encode_attributes(ebml_w, m.attrs);
// If this is a static method, we've already encoded // If this is a static method, we've already encoded
// this. // this.
if method_ty.explicit_self != sty_static { if method_ty.explicit_self != SelfStatic {
// XXX: I feel like there is something funny going on. // XXX: I feel like there is something funny going on.
let tpt = ty::lookup_item_type(tcx, method_def_id); let tpt = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt); encode_bounds_and_type(ebml_w, ecx, &tpt);
@ -1278,7 +1278,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_method_sort(ebml_w, 'p'); encode_method_sort(ebml_w, 'p');
(ecx.encode_inlined_item)( (ecx.encode_inlined_item)(
ecx, ebml_w, path, ecx, ebml_w, path,
ii_method_ref(def_id, true, m)); IIMethodRef(def_id, true, m));
} }
} }
@ -1288,15 +1288,15 @@ fn encode_info_for_item(ecx: &EncodeContext,
// Encode inherent implementations for this trait. // Encode inherent implementations for this trait.
encode_inherent_implementations(ecx, ebml_w, def_id); encode_inherent_implementations(ecx, ebml_w, def_id);
} }
item_mac(..) => fail!("item macros unimplemented") ItemMac(..) => fail!("item macros unimplemented")
} }
} }
fn encode_info_for_foreign_item(ecx: &EncodeContext, fn encode_info_for_foreign_item(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
nitem: &foreign_item, nitem: &ForeignItem,
index: @RefCell<~[entry<i64>]>, index: @RefCell<~[entry<i64>]>,
path: &ast_map::path, path: &ast_map::Path,
abi: AbiSet) { abi: AbiSet) {
{ {
let mut index = index.borrow_mut(); let mut index = index.borrow_mut();
@ -1308,20 +1308,20 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
match nitem.node { match nitem.node {
foreign_item_fn(..) => { ForeignItemFn(..) => {
encode_def_id(ebml_w, local_def(nitem.id)); encode_def_id(ebml_w, local_def(nitem.id));
encode_family(ebml_w, purity_fn_family(impure_fn)); encode_family(ebml_w, purity_fn_family(ImpureFn));
encode_bounds_and_type(ebml_w, ecx, encode_bounds_and_type(ebml_w, ecx,
&lookup_item_type(ecx.tcx,local_def(nitem.id))); &lookup_item_type(ecx.tcx,local_def(nitem.id)));
encode_name(ecx, ebml_w, nitem.ident); encode_name(ecx, ebml_w, nitem.ident);
if abi.is_intrinsic() { if abi.is_intrinsic() {
(ecx.encode_inlined_item)(ecx, ebml_w, *path, ii_foreign_ref(nitem)); (ecx.encode_inlined_item)(ecx, ebml_w, *path, IIForeignRef(nitem));
} else { } else {
encode_symbol(ecx, ebml_w, nitem.id); encode_symbol(ecx, ebml_w, nitem.id);
} }
encode_path(ecx, ebml_w, *path, ast_map::path_name(nitem.ident)); encode_path(ecx, ebml_w, *path, ast_map::PathName(nitem.ident));
} }
foreign_item_static(_, mutbl) => { ForeignItemStatic(_, mutbl) => {
encode_def_id(ebml_w, local_def(nitem.id)); encode_def_id(ebml_w, local_def(nitem.id));
if mutbl { if mutbl {
encode_family(ebml_w, 'b'); encode_family(ebml_w, 'b');
@ -1331,7 +1331,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id)); encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
encode_symbol(ecx, ebml_w, nitem.id); encode_symbol(ecx, ebml_w, nitem.id);
encode_name(ecx, ebml_w, nitem.ident); encode_name(ecx, ebml_w, nitem.ident);
encode_path(ecx, ebml_w, *path, ast_map::path_name(nitem.ident)); encode_path(ecx, ebml_w, *path, ast_map::PathName(nitem.ident));
} }
} }
ebml_w.end_tag(); ebml_w.end_tag();
@ -1339,14 +1339,14 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
fn my_visit_expr(_e: &Expr) { } fn my_visit_expr(_e: &Expr) { }
fn my_visit_item(i: &item, fn my_visit_item(i: &Item,
items: ast_map::map, items: ast_map::Map,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
ecx_ptr: *int, ecx_ptr: *int,
index: @RefCell<~[entry<i64>]>) { index: @RefCell<~[entry<i64>]>) {
let items = items.borrow(); let items = items.borrow();
match items.get().get_copy(&i.id) { match items.get().get_copy(&i.id) {
ast_map::node_item(_, pt) => { ast_map::NodeItem(_, pt) => {
let mut ebml_w = unsafe { let mut ebml_w = unsafe {
ebml_w.unsafe_clone() ebml_w.unsafe_clone()
}; };
@ -1358,14 +1358,14 @@ fn my_visit_item(i: &item,
} }
} }
fn my_visit_foreign_item(ni: &foreign_item, fn my_visit_foreign_item(ni: &ForeignItem,
items: ast_map::map, items: ast_map::Map,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
ecx_ptr:*int, ecx_ptr:*int,
index: @RefCell<~[entry<i64>]>) { index: @RefCell<~[entry<i64>]>) {
let items = items.borrow(); let items = items.borrow();
match items.get().get_copy(&ni.id) { match items.get().get_copy(&ni.id) {
ast_map::node_foreign_item(_, abi, _, pt) => { ast_map::NodeForeignItem(_, abi, _, pt) => {
debug!("writing foreign item {}::{}", debug!("writing foreign item {}::{}",
ast_map::path_to_str( ast_map::path_to_str(
*pt, *pt,
@ -1392,7 +1392,7 @@ fn my_visit_foreign_item(ni: &foreign_item,
struct EncodeVisitor<'a,'b> { struct EncodeVisitor<'a,'b> {
ebml_w_for_visit_item: &'a mut writer::Encoder<'b>, ebml_w_for_visit_item: &'a mut writer::Encoder<'b>,
ecx_ptr:*int, ecx_ptr:*int,
items: ast_map::map, items: ast_map::Map,
index: @RefCell<~[entry<i64>]>, index: @RefCell<~[entry<i64>]>,
} }
@ -1401,7 +1401,7 @@ impl<'a,'b> visit::Visitor<()> for EncodeVisitor<'a,'b> {
visit::walk_expr(self, ex, ()); visit::walk_expr(self, ex, ());
my_visit_expr(ex); my_visit_expr(ex);
} }
fn visit_item(&mut self, i: &item, _: ()) { fn visit_item(&mut self, i: &Item, _: ()) {
visit::walk_item(self, i, ()); visit::walk_item(self, i, ());
my_visit_item(i, my_visit_item(i,
self.items, self.items,
@ -1409,7 +1409,7 @@ impl<'a,'b> visit::Visitor<()> for EncodeVisitor<'a,'b> {
self.ecx_ptr, self.ecx_ptr,
self.index); self.index);
} }
fn visit_foreign_item(&mut self, ni: &foreign_item, _: ()) { fn visit_foreign_item(&mut self, ni: &ForeignItem, _: ()) {
visit::walk_foreign_item(self, ni, ()); visit::walk_foreign_item(self, ni, ());
my_visit_foreign_item(ni, my_visit_foreign_item(ni,
self.items, self.items,
@ -1438,7 +1438,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
CRATE_NODE_ID, CRATE_NODE_ID,
[], [],
syntax::parse::token::special_idents::invalid, syntax::parse::token::special_idents::invalid,
public); Public);
let items = ecx.tcx.items; let items = ecx.tcx.items;
// See comment in `encode_side_tables_for_ii` in astencode // See comment in `encode_side_tables_for_ii` in astencode
@ -1531,7 +1531,7 @@ fn encode_meta_item(ebml_w: &mut writer::Encoder, mi: @MetaItem) {
} }
MetaNameValue(name, value) => { MetaNameValue(name, value) => {
match value.node { match value.node {
lit_str(value, _) => { LitStr(value, _) => {
ebml_w.start_tag(tag_meta_item_name_value); ebml_w.start_tag(tag_meta_item_name_value);
ebml_w.start_tag(tag_meta_item_name); ebml_w.start_tag(tag_meta_item_name);
ebml_w.writer.write(name.as_bytes()); ebml_w.writer.write(name.as_bytes());
@ -1698,9 +1698,9 @@ struct ImplVisitor<'a,'b> {
} }
impl<'a,'b> Visitor<()> for ImplVisitor<'a,'b> { impl<'a,'b> Visitor<()> for ImplVisitor<'a,'b> {
fn visit_item(&mut self, item: &item, _: ()) { fn visit_item(&mut self, item: &Item, _: ()) {
match item.node { match item.node {
item_impl(_, Some(ref trait_ref), _, _) => { ItemImpl(_, Some(ref trait_ref), _, _) => {
let def_map = self.ecx.tcx.def_map; let def_map = self.ecx.tcx.def_map;
let def_map = def_map.borrow(); let def_map = def_map.borrow();
let trait_def = def_map.get().get_copy(&trait_ref.ref_id); let trait_def = def_map.get().get_copy(&trait_ref.ref_id);

View file

@ -20,7 +20,7 @@ use metadata::filesearch::{FileMatches, FileDoesntMatch};
use metadata::filesearch; use metadata::filesearch;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::diagnostic::SpanHandler; use syntax::diagnostic::SpanHandler;
use syntax::parse::token::ident_interner; use syntax::parse::token::IdentInterner;
use syntax::crateid::CrateId; use syntax::crateid::CrateId;
use syntax::attr; use syntax::attr;
use syntax::attr::AttrMetaMethods; use syntax::attr::AttrMetaMethods;
@ -52,7 +52,7 @@ pub struct Context {
version: @str, version: @str,
hash: @str, hash: @str,
os: Os, os: Os,
intr: @ident_interner intr: @IdentInterner
} }
pub struct Library { pub struct Library {
@ -376,7 +376,7 @@ pub fn read_meta_section_name(os: Os) -> &'static str {
} }
// A diagnostic function for dumping crate metadata to an output stream // A diagnostic function for dumping crate metadata to an output stream
pub fn list_file_metadata(intr: @ident_interner, pub fn list_file_metadata(intr: @IdentInterner,
os: Os, os: Os,
path: &Path, path: &Path,
out: &mut io::Writer) { out: &mut io::Writer) {

View file

@ -302,16 +302,16 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
'u' => return ty::mk_uint(), 'u' => return ty::mk_uint(),
'M' => { 'M' => {
match next(st) { match next(st) {
'b' => return ty::mk_mach_uint(ast::ty_u8), 'b' => return ty::mk_mach_uint(ast::TyU8),
'w' => return ty::mk_mach_uint(ast::ty_u16), 'w' => return ty::mk_mach_uint(ast::TyU16),
'l' => return ty::mk_mach_uint(ast::ty_u32), 'l' => return ty::mk_mach_uint(ast::TyU32),
'd' => return ty::mk_mach_uint(ast::ty_u64), 'd' => return ty::mk_mach_uint(ast::TyU64),
'B' => return ty::mk_mach_int(ast::ty_i8), 'B' => return ty::mk_mach_int(ast::TyI8),
'W' => return ty::mk_mach_int(ast::ty_i16), 'W' => return ty::mk_mach_int(ast::TyI16),
'L' => return ty::mk_mach_int(ast::ty_i32), 'L' => return ty::mk_mach_int(ast::TyI32),
'D' => return ty::mk_mach_int(ast::ty_i64), 'D' => return ty::mk_mach_int(ast::TyI64),
'f' => return ty::mk_mach_float(ast::ty_f32), 'f' => return ty::mk_mach_float(ast::TyF32),
'F' => return ty::mk_mach_float(ast::ty_f64), 'F' => return ty::mk_mach_float(ast::TyF64),
_ => fail!("parse_ty: bad numeric type") _ => fail!("parse_ty: bad numeric type")
} }
} }
@ -463,12 +463,12 @@ fn parse_hex(st: &mut PState) -> uint {
}; };
} }
fn parse_purity(c: char) -> purity { fn parse_purity(c: char) -> Purity {
match c { match c {
'u' => unsafe_fn, 'u' => UnsafeFn,
'i' => impure_fn, 'i' => ImpureFn,
'c' => extern_fn, 'c' => ExternFn,
_ => fail!("parse_purity: bad purity {}", c) _ => fail!("parse_purity: bad purity {}", c)
} }
} }

View file

@ -249,26 +249,26 @@ fn enc_sty(w: &mut MemWriter, cx: @ctxt, st: &ty::sty) {
ty::ty_char => mywrite!(w, "c"), ty::ty_char => mywrite!(w, "c"),
ty::ty_int(t) => { ty::ty_int(t) => {
match t { match t {
ty_i => mywrite!(w, "i"), TyI => mywrite!(w, "i"),
ty_i8 => mywrite!(w, "MB"), TyI8 => mywrite!(w, "MB"),
ty_i16 => mywrite!(w, "MW"), TyI16 => mywrite!(w, "MW"),
ty_i32 => mywrite!(w, "ML"), TyI32 => mywrite!(w, "ML"),
ty_i64 => mywrite!(w, "MD") TyI64 => mywrite!(w, "MD")
} }
} }
ty::ty_uint(t) => { ty::ty_uint(t) => {
match t { match t {
ty_u => mywrite!(w, "u"), TyU => mywrite!(w, "u"),
ty_u8 => mywrite!(w, "Mb"), TyU8 => mywrite!(w, "Mb"),
ty_u16 => mywrite!(w, "Mw"), TyU16 => mywrite!(w, "Mw"),
ty_u32 => mywrite!(w, "Ml"), TyU32 => mywrite!(w, "Ml"),
ty_u64 => mywrite!(w, "Md") TyU64 => mywrite!(w, "Md")
} }
} }
ty::ty_float(t) => { ty::ty_float(t) => {
match t { match t {
ty_f32 => mywrite!(w, "Mf"), TyF32 => mywrite!(w, "Mf"),
ty_f64 => mywrite!(w, "MF"), TyF64 => mywrite!(w, "MF"),
} }
} }
ty::ty_enum(def, ref substs) => { ty::ty_enum(def, ref substs) => {
@ -349,11 +349,11 @@ fn enc_sigil(w: &mut MemWriter, sigil: Sigil) {
} }
} }
fn enc_purity(w: &mut MemWriter, p: purity) { fn enc_purity(w: &mut MemWriter, p: Purity) {
match p { match p {
impure_fn => mywrite!(w, "i"), ImpureFn => mywrite!(w, "i"),
unsafe_fn => mywrite!(w, "u"), UnsafeFn => mywrite!(w, "u"),
extern_fn => mywrite!(w, "c") ExternFn => mywrite!(w, "c")
} }
} }

View file

@ -27,7 +27,7 @@ use util::ppaux::ty_to_str;
use syntax::{ast, ast_map, ast_util, codemap, fold}; use syntax::{ast, ast_map, ast_util, codemap, fold};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::diagnostic::SpanHandler; use syntax::diagnostic::SpanHandler;
use syntax::fold::ast_fold; use syntax::fold::Folder;
use syntax::parse::token; use syntax::parse::token;
use syntax; use syntax;
@ -62,8 +62,8 @@ struct DecodeContext {
struct ExtendedDecodeContext { struct ExtendedDecodeContext {
dcx: @DecodeContext, dcx: @DecodeContext,
from_id_range: ast_util::id_range, from_id_range: ast_util::IdRange,
to_id_range: ast_util::id_range to_id_range: ast_util::IdRange
} }
trait tr { trait tr {
@ -79,13 +79,13 @@ trait tr_intern {
pub fn encode_inlined_item(ecx: &e::EncodeContext, pub fn encode_inlined_item(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
ii: e::InlinedItemRef, ii: e::InlinedItemRef,
maps: Maps) { maps: Maps) {
let ident = match ii { let ident = match ii {
e::ii_item_ref(i) => i.ident, e::IIItemRef(i) => i.ident,
e::ii_foreign_ref(i) => i.ident, e::IIForeignRef(i) => i.ident,
e::ii_method_ref(_, _, m) => m.ident, e::IIMethodRef(_, _, m) => m.ident,
}; };
debug!("> Encoding inlined item: {}::{} ({})", debug!("> Encoding inlined item: {}::{} ({})",
ast_map::path_to_str(path, token::get_ident_interner()), ast_map::path_to_str(path, token::get_ident_interner()),
@ -110,9 +110,9 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext,
pub fn decode_inlined_item(cdata: @cstore::crate_metadata, pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
tcx: ty::ctxt, tcx: ty::ctxt,
maps: Maps, maps: Maps,
path: &[ast_map::path_elt], path: &[ast_map::PathElem],
par_doc: ebml::Doc) par_doc: ebml::Doc)
-> Option<ast::inlined_item> { -> Option<ast::InlinedItem> {
let dcx = @DecodeContext { let dcx = @DecodeContext {
cdata: cdata, cdata: cdata,
tcx: tcx, tcx: tcx,
@ -138,9 +138,9 @@ pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
path.to_owned(), path.to_owned(),
raw_ii); raw_ii);
let ident = match ii { let ident = match ii {
ast::ii_item(i) => i.ident, ast::IIItem(i) => i.ident,
ast::ii_foreign(i) => i.ident, ast::IIForeign(i) => i.ident,
ast::ii_method(_, _, m) => m.ident, ast::IIMethod(_, _, m) => m.ident,
}; };
debug!("Fn named: {}", tcx.sess.str_of(ident)); debug!("Fn named: {}", tcx.sess.str_of(ident));
debug!("< Decoded inlined fn: {}::{}", debug!("< Decoded inlined fn: {}::{}",
@ -148,7 +148,7 @@ pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
tcx.sess.str_of(ident)); tcx.sess.str_of(ident));
decode_side_tables(xcx, ast_doc); decode_side_tables(xcx, ast_doc);
match ii { match ii {
ast::ii_item(i) => { ast::IIItem(i) => {
debug!(">>> DECODED ITEM >>>\n{}\n<<< DECODED ITEM <<<", debug!(">>> DECODED ITEM >>>\n{}\n<<< DECODED ITEM <<<",
syntax::print::pprust::item_to_str(i, tcx.sess.intr())); syntax::print::pprust::item_to_str(i, tcx.sess.intr()));
} }
@ -163,13 +163,13 @@ pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
// Enumerating the IDs which appear in an AST // Enumerating the IDs which appear in an AST
fn reserve_id_range(sess: Session, fn reserve_id_range(sess: Session,
from_id_range: ast_util::id_range) -> ast_util::id_range { from_id_range: ast_util::IdRange) -> ast_util::IdRange {
// Handle the case of an empty range: // Handle the case of an empty range:
if from_id_range.empty() { return from_id_range; } if from_id_range.empty() { return from_id_range; }
let cnt = from_id_range.max - from_id_range.min; let cnt = from_id_range.max - from_id_range.min;
let to_id_min = sess.reserve_node_ids(cnt); let to_id_min = sess.reserve_node_ids(cnt);
let to_id_max = to_id_min + cnt; let to_id_max = to_id_min + cnt;
ast_util::id_range { min: to_id_min, max: to_id_max } ast_util::IdRange { min: to_id_min, max: to_id_max }
} }
impl ExtendedDecodeContext { impl ExtendedDecodeContext {
@ -296,7 +296,7 @@ impl<D:serialize::Decoder> def_id_decoder_helpers for D {
// We also have to adjust the spans: for now we just insert a dummy span, // We also have to adjust the spans: for now we just insert a dummy span,
// but eventually we should add entries to the local codemap as required. // but eventually we should add entries to the local codemap as required.
fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::inlined_item) { fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::InlinedItem) {
ebml_w.start_tag(c::tag_tree as uint); ebml_w.start_tag(c::tag_tree as uint);
item.encode(ebml_w); item.encode(ebml_w);
ebml_w.end_tag(); ebml_w.end_tag();
@ -304,7 +304,7 @@ fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::inlined_item) {
struct NestedItemsDropper; struct NestedItemsDropper;
impl ast_fold for NestedItemsDropper { impl Folder for NestedItemsDropper {
fn fold_block(&mut self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> { fn fold_block(&mut self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> {
let stmts_sans_items = blk.stmts.iter().filter_map(|stmt| { let stmts_sans_items = blk.stmts.iter().filter_map(|stmt| {
match stmt.node { match stmt.node {
@ -343,19 +343,19 @@ impl ast_fold for NestedItemsDropper {
// As it happens, trans relies on the fact that we do not export // As it happens, trans relies on the fact that we do not export
// nested items, as otherwise it would get confused when translating // nested items, as otherwise it would get confused when translating
// inlined items. // inlined items.
fn simplify_ast(ii: e::InlinedItemRef) -> ast::inlined_item { fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem {
let mut fld = NestedItemsDropper; let mut fld = NestedItemsDropper;
match ii { match ii {
// HACK we're not dropping items. // HACK we're not dropping items.
e::ii_item_ref(i) => ast::ii_item(fold::noop_fold_item(i, &mut fld) e::IIItemRef(i) => ast::IIItem(fold::noop_fold_item(i, &mut fld)
.expect_one("expected one item")), .expect_one("expected one item")),
e::ii_method_ref(d, p, m) => ast::ii_method(d, p, fold::noop_fold_method(m, &mut fld)), e::IIMethodRef(d, p, m) => ast::IIMethod(d, p, fold::noop_fold_method(m, &mut fld)),
e::ii_foreign_ref(i) => ast::ii_foreign(fold::noop_fold_foreign_item(i, &mut fld)) e::IIForeignRef(i) => ast::IIForeign(fold::noop_fold_foreign_item(i, &mut fld))
} }
} }
fn decode_ast(par_doc: ebml::Doc) -> ast::inlined_item { fn decode_ast(par_doc: ebml::Doc) -> ast::InlinedItem {
let chi_doc = par_doc.get(c::tag_tree as uint); let chi_doc = par_doc.get(c::tag_tree as uint);
let mut d = reader::Decoder(chi_doc); let mut d = reader::Decoder(chi_doc);
Decodable::decode(&mut d) Decodable::decode(&mut d)
@ -376,18 +376,18 @@ impl ast_map::FoldOps for AstRenumberer {
fn renumber_and_map_ast(xcx: @ExtendedDecodeContext, fn renumber_and_map_ast(xcx: @ExtendedDecodeContext,
diag: @SpanHandler, diag: @SpanHandler,
map: ast_map::map, map: ast_map::Map,
path: ast_map::path, path: ast_map::Path,
ii: ast::inlined_item) -> ast::inlined_item { ii: ast::InlinedItem) -> ast::InlinedItem {
ast_map::map_decoded_item(diag, map, path, AstRenumberer { xcx: xcx }, |fld| { ast_map::map_decoded_item(diag, map, path, AstRenumberer { xcx: xcx }, |fld| {
match ii { match ii {
ast::ii_item(i) => { ast::IIItem(i) => {
ast::ii_item(fld.fold_item(i).expect_one("expected one item")) ast::IIItem(fld.fold_item(i).expect_one("expected one item"))
} }
ast::ii_method(d, is_provided, m) => { ast::IIMethod(d, is_provided, m) => {
ast::ii_method(xcx.tr_def_id(d), is_provided, fld.fold_method(m)) ast::IIMethod(xcx.tr_def_id(d), is_provided, fld.fold_method(m))
} }
ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i)) ast::IIForeign(i) => ast::IIForeign(fld.fold_foreign_item(i))
} }
}) })
} }
@ -595,7 +595,7 @@ impl<'a> read_method_map_entry_helper for reader::Decoder<'a> {
explicit_self: this.read_struct_field("explicit_self", explicit_self: this.read_struct_field("explicit_self",
2, 2,
|this| { |this| {
let explicit_self: ast::explicit_self_ = Decodable::decode(this); let explicit_self: ast::ExplicitSelf_ = Decodable::decode(this);
explicit_self explicit_self
}), }),
origin: this.read_struct_field("origin", 1, |this| { origin: this.read_struct_field("origin", 1, |this| {
@ -921,7 +921,7 @@ impl<'a,'b> ast_util::IdVisitingOperation for
fn encode_side_tables_for_ii(ecx: &e::EncodeContext, fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
maps: Maps, maps: Maps,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
ii: &ast::inlined_item) { ii: &ast::InlinedItem) {
ebml_w.start_tag(c::tag_table as uint); ebml_w.start_tag(c::tag_table as uint);
let mut new_ebml_w = unsafe { let mut new_ebml_w = unsafe {
ebml_w.unsafe_clone() ebml_w.unsafe_clone()
@ -1418,14 +1418,14 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
// Testing of astencode_gen // Testing of astencode_gen
#[cfg(test)] #[cfg(test)]
fn encode_item_ast(ebml_w: &mut writer::Encoder, item: @ast::item) { fn encode_item_ast(ebml_w: &mut writer::Encoder, item: @ast::Item) {
ebml_w.start_tag(c::tag_tree as uint); ebml_w.start_tag(c::tag_tree as uint);
(*item).encode(ebml_w); (*item).encode(ebml_w);
ebml_w.end_tag(); ebml_w.end_tag();
} }
#[cfg(test)] #[cfg(test)]
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item { fn decode_item_ast(par_doc: ebml::Doc) -> @ast::Item {
let chi_doc = par_doc.get(c::tag_tree as uint); let chi_doc = par_doc.get(c::tag_tree as uint);
let mut d = reader::Decoder(chi_doc); let mut d = reader::Decoder(chi_doc);
@Decodable::decode(&mut d) @Decodable::decode(&mut d)
@ -1464,7 +1464,7 @@ fn mk_ctxt() -> @fake_ext_ctxt {
} }
#[cfg(test)] #[cfg(test)]
fn roundtrip(in_item: Option<@ast::item>) { fn roundtrip(in_item: Option<@ast::Item>) {
use std::io::mem::MemWriter; use std::io::mem::MemWriter;
let in_item = in_item.unwrap(); let in_item = in_item.unwrap();
@ -1515,15 +1515,15 @@ fn test_simplification() {
return alist {eq_fn: eq_int, data: ~[]}; return alist {eq_fn: eq_int, data: ~[]};
} }
).unwrap(); ).unwrap();
let item_in = e::ii_item_ref(item); let item_in = e::IIItemRef(item);
let item_out = simplify_ast(item_in); let item_out = simplify_ast(item_in);
let item_exp = ast::ii_item(quote_item!(cx, let item_exp = ast::IIItem(quote_item!(cx,
fn new_int_alist<B>() -> alist<int, B> { fn new_int_alist<B>() -> alist<int, B> {
return alist {eq_fn: eq_int, data: ~[]}; return alist {eq_fn: eq_int, data: ~[]};
} }
).unwrap()); ).unwrap());
match (item_out, item_exp) { match (item_out, item_exp) {
(ast::ii_item(item_out), ast::ii_item(item_exp)) => { (ast::IIItem(item_out), ast::IIItem(item_exp)) => {
assert!(pprust::item_to_str(item_out, assert!(pprust::item_to_str(item_out,
token::get_ident_interner()) token::get_ident_interner())
== pprust::item_to_str(item_exp, == pprust::item_to_str(item_exp,

View file

@ -51,7 +51,7 @@ impl<'a> Visitor<()> for CheckLoanCtxt<'a> {
fn visit_pat(&mut self, p: &ast::Pat, _: ()) { fn visit_pat(&mut self, p: &ast::Pat, _: ()) {
check_loans_in_pat(self, p); check_loans_in_pat(self, p);
} }
fn visit_fn(&mut self, fk: &visit::fn_kind, fd: &ast::fn_decl, fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
b: &ast::Block, s: Span, n: ast::NodeId, _: ()) { b: &ast::Block, s: Span, n: ast::NodeId, _: ()) {
check_loans_in_fn(self, fk, fd, b, s, n); check_loans_in_fn(self, fk, fd, b, s, n);
} }
@ -682,19 +682,18 @@ impl<'a> CheckLoanCtxt<'a> {
} }
fn check_loans_in_fn<'a>(this: &mut CheckLoanCtxt<'a>, fn check_loans_in_fn<'a>(this: &mut CheckLoanCtxt<'a>,
fk: &visit::fn_kind, fk: &visit::FnKind,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
sp: Span, sp: Span,
id: ast::NodeId) { id: ast::NodeId) {
match *fk { match *fk {
visit::fk_item_fn(..) | visit::FkItemFn(..) | visit::FkMethod(..) => {
visit::fk_method(..) => {
// Don't process nested items. // Don't process nested items.
return; return;
} }
visit::fk_fn_block(..) => { visit::FkFnBlock(..) => {
check_captured_variables(this, id, sp); check_captured_variables(this, id, sp);
} }
} }

View file

@ -28,12 +28,12 @@ use util::ppaux::{Repr};
use std::cell::RefCell; use std::cell::RefCell;
use syntax::ast; use syntax::ast;
use syntax::ast_util::id_range; use syntax::ast_util::IdRange;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::visit; use syntax::visit;
use syntax::visit::{Visitor, fn_kind}; use syntax::visit::{Visitor, FnKind};
use syntax::ast::{Expr, fn_decl, Block, NodeId, Stmt, Pat, Local}; use syntax::ast::{Expr, FnDecl, Block, NodeId, Stmt, Pat, Local};
mod lifetime; mod lifetime;
mod restrictions; mod restrictions;
@ -67,7 +67,7 @@ mod gather_moves;
/// because it would have to be rooted for a region greater than `root_ub`. /// because it would have to be rooted for a region greater than `root_ub`.
struct GatherLoanCtxt<'a> { struct GatherLoanCtxt<'a> {
bccx: &'a BorrowckCtxt, bccx: &'a BorrowckCtxt,
id_range: id_range, id_range: IdRange,
move_data: move_data::MoveData, move_data: move_data::MoveData,
all_loans: @RefCell<~[Loan]>, all_loans: @RefCell<~[Loan]>,
item_ub: ast::NodeId, item_ub: ast::NodeId,
@ -81,7 +81,7 @@ impl<'a> visit::Visitor<()> for GatherLoanCtxt<'a> {
fn visit_block(&mut self, b: &Block, _: ()) { fn visit_block(&mut self, b: &Block, _: ()) {
gather_loans_in_block(self, b); gather_loans_in_block(self, b);
} }
fn visit_fn(&mut self, fk: &fn_kind, fd: &fn_decl, b: &Block, fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block,
s: Span, n: NodeId, _: ()) { s: Span, n: NodeId, _: ()) {
gather_loans_in_fn(self, fk, fd, b, s, n); gather_loans_in_fn(self, fk, fd, b, s, n);
} }
@ -98,16 +98,14 @@ impl<'a> visit::Visitor<()> for GatherLoanCtxt<'a> {
// #7740: Do not visit items here, not even fn items nor methods // #7740: Do not visit items here, not even fn items nor methods
// of impl items; the outer loop in borrowck/mod will visit them // of impl items; the outer loop in borrowck/mod will visit them
// for us in turn. Thus override visit_item's walk with a no-op. // for us in turn. Thus override visit_item's walk with a no-op.
fn visit_item(&mut self, _: &ast::item, _: ()) { } fn visit_item(&mut self, _: &ast::Item, _: ()) { }
} }
pub fn gather_loans(bccx: &BorrowckCtxt, pub fn gather_loans(bccx: &BorrowckCtxt, decl: &ast::FnDecl, body: &ast::Block)
decl: &ast::fn_decl, -> (IdRange, @RefCell<~[Loan]>, move_data::MoveData) {
body: &ast::Block)
-> (id_range, @RefCell<~[Loan]>, move_data::MoveData) {
let mut glcx = GatherLoanCtxt { let mut glcx = GatherLoanCtxt {
bccx: bccx, bccx: bccx,
id_range: id_range::max(), id_range: IdRange::max(),
all_loans: @RefCell::new(~[]), all_loans: @RefCell::new(~[]),
item_ub: body.id, item_ub: body.id,
repeating_ids: ~[body.id], repeating_ids: ~[body.id],
@ -129,19 +127,16 @@ fn add_pat_to_id_range(this: &mut GatherLoanCtxt,
visit::walk_pat(this, p, ()); visit::walk_pat(this, p, ());
} }
fn gather_loans_in_fn(this: &mut GatherLoanCtxt, fn gather_loans_in_fn(this: &mut GatherLoanCtxt, fk: &FnKind,
fk: &fn_kind, decl: &ast::FnDecl, body: &ast::Block,
decl: &ast::fn_decl, sp: Span, id: ast::NodeId) {
body: &ast::Block,
sp: Span,
id: ast::NodeId) {
match fk { match fk {
&visit::fk_item_fn(..) | &visit::fk_method(..) => { &visit::FkItemFn(..) | &visit::FkMethod(..) => {
fail!("cannot occur, due to visit_item override"); fail!("cannot occur, due to visit_item override");
} }
// Visit closures as part of the containing item. // Visit closures as part of the containing item.
&visit::fk_fn_block(..) => { &visit::FkFnBlock(..) => {
this.push_repeating_id(body.id); this.push_repeating_id(body.id);
visit::walk_fn(this, fk, decl, body, sp, id, ()); visit::walk_fn(this, fk, decl, body, sp, id, ());
this.pop_repeating_id(body.id); this.pop_repeating_id(body.id);
@ -677,7 +672,7 @@ impl<'a> GatherLoanCtxt<'a> {
} }
fn gather_fn_arg_patterns(&mut self, fn gather_fn_arg_patterns(&mut self,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block) { body: &ast::Block) {
/*! /*!
* Walks the patterns for fn arguments, checking that they * Walks the patterns for fn arguments, checking that they

View file

@ -28,8 +28,8 @@ use syntax::ast_map;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::parse::token; use syntax::parse::token;
use syntax::visit; use syntax::visit;
use syntax::visit::{Visitor,fn_kind}; use syntax::visit::{Visitor, FnKind};
use syntax::ast::{fn_decl,Block,NodeId}; use syntax::ast::{FnDecl, Block, NodeId};
macro_rules! if_ok( macro_rules! if_ok(
($inp: expr) => ( ($inp: expr) => (
@ -61,7 +61,7 @@ impl Clone for LoanDataFlowOperator {
pub type LoanDataFlow = DataFlowContext<LoanDataFlowOperator>; pub type LoanDataFlow = DataFlowContext<LoanDataFlowOperator>;
impl Visitor<()> for BorrowckCtxt { impl Visitor<()> for BorrowckCtxt {
fn visit_fn(&mut self, fk: &fn_kind, fd: &fn_decl, fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl,
b: &Block, s: Span, n: NodeId, _: ()) { b: &Block, s: Span, n: NodeId, _: ()) {
borrowck_fn(self, fk, fd, b, s, n); borrowck_fn(self, fk, fd, b, s, n);
} }
@ -114,18 +114,17 @@ pub fn check_crate(tcx: ty::ctxt,
} }
fn borrowck_fn(this: &mut BorrowckCtxt, fn borrowck_fn(this: &mut BorrowckCtxt,
fk: &visit::fn_kind, fk: &FnKind,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
sp: Span, sp: Span,
id: ast::NodeId) { id: ast::NodeId) {
match fk { match fk {
&visit::fk_fn_block(..) => { &visit::FkFnBlock(..) => {
// Closures are checked as part of their containing fn item. // Closures are checked as part of their containing fn item.
} }
&visit::fk_item_fn(..) | &visit::FkItemFn(..) | &visit::FkMethod(..) => {
&visit::fk_method(..) => {
debug!("borrowck_fn(id={:?})", id); debug!("borrowck_fn(id={:?})", id);
// Check the body of fn items. // Check the body of fn items.
@ -553,7 +552,7 @@ impl BorrowckCtxt {
move_data::MoveExpr => { move_data::MoveExpr => {
let items = self.tcx.items.borrow(); let items = self.tcx.items.borrow();
let (expr_ty, expr_span) = match items.get().find(&move.id) { let (expr_ty, expr_span) = match items.get().find(&move.id) {
Some(&ast_map::node_expr(expr)) => { Some(&ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, expr), expr.span) (ty::expr_ty_adjusted(self.tcx, expr), expr.span)
} }
r => self.tcx.sess.bug(format!("MoveExpr({:?}) maps to {:?}, not Expr", r => self.tcx.sess.bug(format!("MoveExpr({:?}) maps to {:?}, not Expr",
@ -581,7 +580,7 @@ impl BorrowckCtxt {
move_data::Captured => { move_data::Captured => {
let items = self.tcx.items.borrow(); let items = self.tcx.items.borrow();
let (expr_ty, expr_span) = match items.get().find(&move.id) { let (expr_ty, expr_span) = match items.get().find(&move.id) {
Some(&ast_map::node_expr(expr)) => { Some(&ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, expr), expr.span) (ty::expr_ty_adjusted(self.tcx, expr), expr.span)
} }
r => self.tcx.sess.bug(format!("Captured({:?}) maps to {:?}, not Expr", r => self.tcx.sess.bug(format!("Captured({:?}) maps to {:?}, not Expr",
@ -771,7 +770,7 @@ impl BorrowckCtxt {
LpVar(id) => { LpVar(id) => {
let items = self.tcx.items.borrow(); let items = self.tcx.items.borrow();
match items.get().find(&id) { match items.get().find(&id) {
Some(&ast_map::node_local(ref ident, _)) => { Some(&ast_map::NodeLocal(ref ident, _)) => {
out.push_str(token::ident_to_str(ident)); out.push_str(token::ident_to_str(ident));
} }
r => { r => {

View file

@ -566,7 +566,7 @@ impl FlowedMoveData {
pub fn new(move_data: MoveData, pub fn new(move_data: MoveData,
tcx: ty::ctxt, tcx: ty::ctxt,
method_map: typeck::method_map, method_map: typeck::method_map,
id_range: ast_util::id_range, id_range: ast_util::IdRange,
body: &ast::Block) body: &ast::Block)
-> FlowedMoveData { -> FlowedMoveData {
let mut dfcx_moves = { let mut dfcx_moves = {

View file

@ -23,14 +23,14 @@ use syntax::visit;
struct CheckCrateVisitor { struct CheckCrateVisitor {
sess: Session, sess: Session,
ast_map: ast_map::map, ast_map: ast_map::Map,
def_map: resolve::DefMap, def_map: resolve::DefMap,
method_map: typeck::method_map, method_map: typeck::method_map,
tcx: ty::ctxt, tcx: ty::ctxt,
} }
impl Visitor<bool> for CheckCrateVisitor { impl Visitor<bool> for CheckCrateVisitor {
fn visit_item(&mut self, i: &item, env: bool) { fn visit_item(&mut self, i: &Item, env: bool) {
check_item(self, self.sess, self.ast_map, self.def_map, i, env); check_item(self, self.sess, self.ast_map, self.def_map, i, env);
} }
fn visit_pat(&mut self, p: &Pat, env: bool) { fn visit_pat(&mut self, p: &Pat, env: bool) {
@ -44,7 +44,7 @@ impl Visitor<bool> for CheckCrateVisitor {
pub fn check_crate(sess: Session, pub fn check_crate(sess: Session,
crate: &Crate, crate: &Crate,
ast_map: ast_map::map, ast_map: ast_map::Map,
def_map: resolve::DefMap, def_map: resolve::DefMap,
method_map: typeck::method_map, method_map: typeck::method_map,
tcx: ty::ctxt) { tcx: ty::ctxt) {
@ -61,23 +61,23 @@ pub fn check_crate(sess: Session,
pub fn check_item(v: &mut CheckCrateVisitor, pub fn check_item(v: &mut CheckCrateVisitor,
sess: Session, sess: Session,
ast_map: ast_map::map, ast_map: ast_map::Map,
def_map: resolve::DefMap, def_map: resolve::DefMap,
it: &item, it: &Item,
_is_const: bool) { _is_const: bool) {
match it.node { match it.node {
item_static(_, _, ex) => { ItemStatic(_, _, ex) => {
v.visit_expr(ex, true); v.visit_expr(ex, true);
check_item_recursion(sess, ast_map, def_map, it); check_item_recursion(sess, ast_map, def_map, it);
} }
item_enum(ref enum_definition, _) => { ItemEnum(ref enum_definition, _) => {
for var in (*enum_definition).variants.iter() { for var in (*enum_definition).variants.iter() {
for ex in var.node.disr_expr.iter() { for ex in var.node.disr_expr.iter() {
v.visit_expr(*ex, true); v.visit_expr(*ex, true);
}
} }
} }
} _ => visit::walk_item(v, it, false)
_ => visit::walk_item(v, it, false)
} }
} }
@ -86,7 +86,7 @@ pub fn check_pat(v: &mut CheckCrateVisitor, p: &Pat, _is_const: bool) {
match e.node { match e.node {
ExprVstore( ExprVstore(
@Expr { node: ExprLit(@codemap::Spanned { @Expr { node: ExprLit(@codemap::Spanned {
node: lit_str(..), node: LitStr(..),
..}), ..}),
.. }, .. },
ExprVstoreUniq ExprVstoreUniq
@ -120,7 +120,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
"cannot do allocations in constant expressions"); "cannot do allocations in constant expressions");
return; return;
} }
ExprLit(@codemap::Spanned {node: lit_str(..), ..}) => { } ExprLit(@codemap::Spanned {node: LitStr(..), ..}) => { }
ExprBinary(..) | ExprUnary(..) => { ExprBinary(..) | ExprUnary(..) => {
let method_map = method_map.borrow(); let method_map = method_map.borrow();
if method_map.get().contains_key(&e.id) { if method_map.get().contains_key(&e.id) {
@ -211,9 +211,9 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
} }
struct CheckItemRecursionVisitor<'a> { struct CheckItemRecursionVisitor<'a> {
root_it: &'a item, root_it: &'a Item,
sess: Session, sess: Session,
ast_map: ast_map::map, ast_map: ast_map::Map,
def_map: resolve::DefMap, def_map: resolve::DefMap,
idstack: ~[NodeId] idstack: ~[NodeId]
} }
@ -221,9 +221,9 @@ struct CheckItemRecursionVisitor<'a> {
// Make sure a const item doesn't recursively refer to itself // Make sure a const item doesn't recursively refer to itself
// FIXME: Should use the dependency graph when it's available (#1356) // FIXME: Should use the dependency graph when it's available (#1356)
pub fn check_item_recursion(sess: Session, pub fn check_item_recursion(sess: Session,
ast_map: ast_map::map, ast_map: ast_map::Map,
def_map: resolve::DefMap, def_map: resolve::DefMap,
it: &item) { it: &Item) {
let mut visitor = CheckItemRecursionVisitor { let mut visitor = CheckItemRecursionVisitor {
root_it: it, root_it: it,
@ -236,7 +236,7 @@ pub fn check_item_recursion(sess: Session,
} }
impl<'a> Visitor<()> for CheckItemRecursionVisitor<'a> { impl<'a> Visitor<()> for CheckItemRecursionVisitor<'a> {
fn visit_item(&mut self, it: &item, _: ()) { fn visit_item(&mut self, it: &Item, _: ()) {
if self.idstack.iter().any(|x| x == &(it.id)) { if self.idstack.iter().any(|x| x == &(it.id)) {
self.sess.span_fatal(self.root_it.span, "recursive constant"); self.sess.span_fatal(self.root_it.span, "recursive constant");
} }
@ -254,7 +254,7 @@ impl<'a> Visitor<()> for CheckItemRecursionVisitor<'a> {
ast_util::is_local(def_id) => { ast_util::is_local(def_id) => {
let ast_map = self.ast_map.borrow(); let ast_map = self.ast_map.borrow();
match ast_map.get().get_copy(&def_id.node) { match ast_map.get().get_copy(&def_id.node) {
ast_map::node_item(it, _) => { ast_map::NodeItem(it, _) => {
self.visit_item(it, ()); self.visit_item(it, ());
} }
_ => fail!("const not bound to an item") _ => fail!("const not bound to an item")

View file

@ -29,7 +29,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: &ast::Crate) {
} }
impl Visitor<Context> for CheckLoopVisitor { impl Visitor<Context> for CheckLoopVisitor {
fn visit_item(&mut self, i: &ast::item, _cx: Context) { fn visit_item(&mut self, i: &ast::Item, _cx: Context) {
visit::walk_item(self, i, Normal); visit::walk_item(self, i, Normal);
} }

View file

@ -25,7 +25,7 @@ use syntax::ast::*;
use syntax::ast_util::{unguarded_pat, walk_pat}; use syntax::ast_util::{unguarded_pat, walk_pat};
use syntax::codemap::{Span, DUMMY_SP, Spanned}; use syntax::codemap::{Span, DUMMY_SP, Spanned};
use syntax::visit; use syntax::visit;
use syntax::visit::{Visitor,fn_kind}; use syntax::visit::{Visitor, FnKind};
struct MatchCheckCtxt { struct MatchCheckCtxt {
tcx: ty::ctxt, tcx: ty::ctxt,
@ -44,7 +44,7 @@ impl Visitor<()> for CheckMatchVisitor {
fn visit_local(&mut self, l: &Local, _: ()) { fn visit_local(&mut self, l: &Local, _: ()) {
check_local(self, self.cx, l, ()); check_local(self, self.cx, l, ());
} }
fn visit_fn(&mut self, fk: &fn_kind, fd: &fn_decl, b: &Block, s: Span, n: NodeId, _: ()) { fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, n: NodeId, _: ()) {
check_fn(self, self.cx, fk, fd, b, s, n, ()); check_fn(self, self.cx, fk, fd, b, s, n, ());
} }
} }
@ -843,8 +843,8 @@ fn check_local(v: &mut CheckMatchVisitor,
fn check_fn(v: &mut CheckMatchVisitor, fn check_fn(v: &mut CheckMatchVisitor,
cx: &MatchCheckCtxt, cx: &MatchCheckCtxt,
kind: &visit::fn_kind, kind: &FnKind,
decl: &fn_decl, decl: &FnDecl,
body: &Block, body: &Block,
sp: Span, sp: Span,
id: NodeId, id: NodeId,
@ -879,7 +879,7 @@ fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool {
is_refutable(cx, sub) is_refutable(cx, sub)
} }
PatWild | PatWildMulti | PatIdent(_, _, None) => { false } PatWild | PatWildMulti | PatIdent(_, _, None) => { false }
PatLit(@Expr {node: ExprLit(@Spanned { node: lit_nil, ..}), ..}) => { PatLit(@Expr {node: ExprLit(@Spanned { node: LitNil, ..}), ..}) => {
// "()" // "()"
false false
} }

View file

@ -97,7 +97,7 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,
enum_def: ast::DefId, enum_def: ast::DefId,
variant_def: ast::DefId) variant_def: ast::DefId)
-> Option<@Expr> { -> Option<@Expr> {
fn variant_expr(variants: &[ast::P<ast::variant>], id: ast::NodeId) -> Option<@Expr> { fn variant_expr(variants: &[ast::P<ast::Variant>], id: ast::NodeId) -> Option<@Expr> {
for variant in variants.iter() { for variant in variants.iter() {
if variant.node.id == id { if variant.node.id == id {
return variant.node.disr_expr; return variant.node.disr_expr;
@ -111,8 +111,8 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&enum_def.node) { match items.get().find(&enum_def.node) {
None => None, None => None,
Some(&ast_map::node_item(it, _)) => match it.node { Some(&ast_map::NodeItem(it, _)) => match it.node {
item_enum(ast::enum_def { variants: ref variants }, _) => { ItemEnum(ast::EnumDef { variants: ref variants }, _) => {
variant_expr(*variants, variant_def.node) variant_expr(*variants, variant_def.node)
} }
_ => None _ => None
@ -140,8 +140,8 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,
maps, maps,
/*bad*/ c.clone(), /*bad*/ c.clone(),
d)) { d)) {
csearch::found(ast::ii_item(item)) => match item.node { csearch::found(ast::IIItem(item)) => match item.node {
item_enum(ast::enum_def { variants: ref variants }, _) => { ItemEnum(ast::EnumDef { variants: ref variants }, _) => {
variant_expr(*variants, variant_def.node) variant_expr(*variants, variant_def.node)
} }
_ => None _ => None
@ -164,8 +164,8 @@ pub fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::DefId)
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&def_id.node) { match items.get().find(&def_id.node) {
None => None, None => None,
Some(&ast_map::node_item(it, _)) => match it.node { Some(&ast_map::NodeItem(it, _)) => match it.node {
item_static(_, ast::MutImmutable, const_expr) => { ItemStatic(_, ast::MutImmutable, const_expr) => {
Some(const_expr) Some(const_expr)
} }
_ => None _ => None
@ -189,8 +189,8 @@ pub fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::DefId)
}; };
let e = match csearch::maybe_get_item_ast(tcx, def_id, let e = match csearch::maybe_get_item_ast(tcx, def_id,
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, c, d)) { |a, b, c, d| astencode::decode_inlined_item(a, b, maps, c, d)) {
csearch::found(ast::ii_item(item)) => match item.node { csearch::found(ast::IIItem(item)) => match item.node {
item_static(_, ast::MutImmutable, const_expr) => Some(const_expr), ItemStatic(_, ast::MutImmutable, const_expr) => Some(const_expr),
_ => None _ => None
}, },
_ => None _ => None
@ -219,7 +219,7 @@ impl ConstEvalVisitor {
let cn = match e.node { let cn = match e.node {
ast::ExprLit(lit) => { ast::ExprLit(lit) => {
match lit.node { match lit.node {
ast::lit_str(..) | ast::lit_float(..) => general_const, ast::LitStr(..) | ast::LitFloat(..) => general_const,
_ => integral_const _ => integral_const
} }
} }
@ -497,19 +497,19 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
} }
} }
pub fn lit_to_const(lit: &lit) -> const_val { pub fn lit_to_const(lit: &Lit) -> const_val {
match lit.node { match lit.node {
lit_str(s, _) => const_str(s), LitStr(s, _) => const_str(s),
lit_binary(data) => const_binary(data), LitBinary(data) => const_binary(data),
lit_char(n) => const_uint(n as u64), LitChar(n) => const_uint(n as u64),
lit_int(n, _) => const_int(n), LitInt(n, _) => const_int(n),
lit_uint(n, _) => const_uint(n), LitUint(n, _) => const_uint(n),
lit_int_unsuffixed(n) => const_int(n), LitIntUnsuffixed(n) => const_int(n),
lit_float(n, _) => const_float(from_str::<f64>(n).unwrap() as f64), LitFloat(n, _) => const_float(from_str::<f64>(n).unwrap() as f64),
lit_float_unsuffixed(n) => LitFloatUnsuffixed(n) =>
const_float(from_str::<f64>(n).unwrap() as f64), const_float(from_str::<f64>(n).unwrap() as f64),
lit_nil => const_int(0i64), LitNil => const_int(0i64),
lit_bool(b) => const_bool(b) LitBool(b) => const_bool(b)
} }
} }
@ -535,6 +535,6 @@ pub fn lit_expr_eq(tcx: middle::ty::ctxt, a: &Expr, b: &Expr) -> Option<bool> {
compare_lit_exprs(tcx, a, b).map(|val| val == 0) compare_lit_exprs(tcx, a, b).map(|val| val == 0)
} }
pub fn lit_eq(a: &lit, b: &lit) -> Option<bool> { pub fn lit_eq(a: &Lit, b: &Lit) -> Option<bool> {
compare_const_vals(&lit_to_const(a), &lit_to_const(b)).map(|val| val == 0) compare_const_vals(&lit_to_const(a), &lit_to_const(b)).map(|val| val == 0)
} }

View file

@ -24,7 +24,7 @@ use std::vec;
use std::hashmap::HashMap; use std::hashmap::HashMap;
use syntax::ast; use syntax::ast;
use syntax::ast_util; use syntax::ast_util;
use syntax::ast_util::id_range; use syntax::ast_util::IdRange;
use syntax::print::{pp, pprust}; use syntax::print::{pp, pprust};
use middle::ty; use middle::ty;
use middle::typeck; use middle::typeck;
@ -87,13 +87,13 @@ struct LoopScope<'a> {
break_bits: ~[uint] break_bits: ~[uint]
} }
impl<O:DataFlowOperator> pprust::pp_ann for DataFlowContext<O> { impl<O:DataFlowOperator> pprust::PpAnn for DataFlowContext<O> {
fn pre(&self, node: pprust::ann_node) { fn pre(&self, node: pprust::AnnNode) {
let (ps, id) = match node { let (ps, id) = match node {
pprust::node_expr(ps, expr) => (ps, expr.id), pprust::NodeExpr(ps, expr) => (ps, expr.id),
pprust::node_block(ps, blk) => (ps, blk.id), pprust::NodeBlock(ps, blk) => (ps, blk.id),
pprust::node_item(ps, _) => (ps, 0), pprust::NodeItem(ps, _) => (ps, 0),
pprust::node_pat(ps, pat) => (ps, pat.id) pprust::NodePat(ps, pat) => (ps, pat.id)
}; };
if self.nodeid_to_bitset.contains_key(&id) { if self.nodeid_to_bitset.contains_key(&id) {
@ -127,7 +127,7 @@ impl<O:DataFlowOperator> DataFlowContext<O> {
pub fn new(tcx: ty::ctxt, pub fn new(tcx: ty::ctxt,
method_map: typeck::method_map, method_map: typeck::method_map,
oper: O, oper: O,
id_range: id_range, id_range: IdRange,
bits_per_id: uint) -> DataFlowContext<O> { bits_per_id: uint) -> DataFlowContext<O> {
let words_per_id = (bits_per_id + uint::bits - 1) / uint::bits; let words_per_id = (bits_per_id + uint::bits - 1) / uint::bits;
@ -353,9 +353,8 @@ impl<O:DataFlowOperator+Clone+'static> DataFlowContext<O> {
} }
fn pretty_print_to(@self, wr: ~io::Writer, blk: &ast::Block) { fn pretty_print_to(@self, wr: ~io::Writer, blk: &ast::Block) {
let mut ps = pprust::rust_printer_annotated(wr, let mut ps = pprust::rust_printer_annotated(wr, self.tcx.sess.intr(),
self.tcx.sess.intr(), self as @pprust::PpAnn);
self as @pprust::pp_ann);
pprust::cbox(&mut ps, pprust::indent_unit); pprust::cbox(&mut ps, pprust::indent_unit);
pprust::ibox(&mut ps, 0u); pprust::ibox(&mut ps, 0u);
pprust::print_block(&mut ps, blk); pprust::print_block(&mut ps, blk);

View file

@ -27,7 +27,7 @@ use syntax::visit::Visitor;
use syntax::visit; use syntax::visit;
// Any local node that may call something in its body block should be // Any local node that may call something in its body block should be
// explored. For example, if it's a live node_item that is a // explored. For example, if it's a live NodeItem that is a
// function, then we should explore its block to check for codes that // function, then we should explore its block to check for codes that
// may need to be marked as live. // may need to be marked as live.
fn should_explore(tcx: ty::ctxt, def_id: ast::DefId) -> bool { fn should_explore(tcx: ty::ctxt, def_id: ast::DefId) -> bool {
@ -37,10 +37,10 @@ fn should_explore(tcx: ty::ctxt, def_id: ast::DefId) -> bool {
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&def_id.node) { match items.get().find(&def_id.node) {
Some(&ast_map::node_item(..)) Some(&ast_map::NodeItem(..))
| Some(&ast_map::node_method(..)) | Some(&ast_map::NodeMethod(..))
| Some(&ast_map::node_foreign_item(..)) | Some(&ast_map::NodeForeignItem(..))
| Some(&ast_map::node_trait_method(..)) => true, | Some(&ast_map::NodeTraitMethod(..)) => true,
_ => false _ => false
} }
} }
@ -144,27 +144,27 @@ impl MarkSymbolVisitor {
} }
} }
fn visit_node(&mut self, node: &ast_map::ast_node) { fn visit_node(&mut self, node: &ast_map::Node) {
match *node { match *node {
ast_map::node_item(item, _) => { ast_map::NodeItem(item, _) => {
match item.node { match item.node {
ast::item_fn(..) ast::ItemFn(..)
| ast::item_ty(..) | ast::ItemTy(..)
| ast::item_enum(..) | ast::ItemEnum(..)
| ast::item_struct(..) | ast::ItemStruct(..)
| ast::item_static(..) => { | ast::ItemStatic(..) => {
visit::walk_item(self, item, ()); visit::walk_item(self, item, ());
} }
_ => () _ => ()
} }
} }
ast_map::node_trait_method(trait_method, _, _) => { ast_map::NodeTraitMethod(trait_method, _, _) => {
visit::walk_trait_method(self, trait_method, ()); visit::walk_trait_method(self, trait_method, ());
} }
ast_map::node_method(method, _, _) => { ast_map::NodeMethod(method, _, _) => {
visit::walk_block(self, method.body, ()); visit::walk_block(self, method.body, ());
} }
ast_map::node_foreign_item(foreign_item, _, _, _) => { ast_map::NodeForeignItem(foreign_item, _, _, _) => {
visit::walk_foreign_item(self, foreign_item, ()); visit::walk_foreign_item(self, foreign_item, ());
} }
_ => () _ => ()
@ -190,7 +190,7 @@ impl Visitor<()> for MarkSymbolVisitor {
visit::walk_path(self, path, ()); visit::walk_path(self, path, ());
} }
fn visit_item(&mut self, _item: &ast::item, _: ()) { fn visit_item(&mut self, _item: &ast::Item, _: ()) {
// Do not recurse into items. These items will be added to the // Do not recurse into items. These items will be added to the
// worklist and recursed into manually if necessary. // worklist and recursed into manually if necessary.
} }
@ -204,14 +204,14 @@ struct TraitMethodSeeder {
} }
impl Visitor<()> for TraitMethodSeeder { impl Visitor<()> for TraitMethodSeeder {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
match item.node { match item.node {
ast::item_impl(_, Some(ref _trait_ref), _, ref methods) => { ast::ItemImpl(_, Some(ref _trait_ref), _, ref methods) => {
for method in methods.iter() { for method in methods.iter() {
self.worklist.push(method.id); self.worklist.push(method.id);
} }
} }
ast::item_mod(..) | ast::item_fn(..) => { ast::ItemMod(..) | ast::ItemFn(..) => {
visit::walk_item(self, item, ()); visit::walk_item(self, item, ());
} }
_ => () _ => ()
@ -265,19 +265,19 @@ fn find_live(tcx: ty::ctxt,
symbol_visitor.live_symbols symbol_visitor.live_symbols
} }
fn should_warn(item: &ast::item) -> bool { fn should_warn(item: &ast::Item) -> bool {
match item.node { match item.node {
ast::item_static(..) ast::ItemStatic(..)
| ast::item_fn(..) | ast::ItemFn(..)
| ast::item_enum(..) | ast::ItemEnum(..)
| ast::item_struct(..) => true, | ast::ItemStruct(..) => true,
_ => false _ => false
} }
} }
fn get_struct_ctor_id(item: &ast::item) -> Option<ast::NodeId> { fn get_struct_ctor_id(item: &ast::Item) -> Option<ast::NodeId> {
match item.node { match item.node {
ast::item_struct(struct_def, _) => struct_def.ctor_id, ast::ItemStruct(struct_def, _) => struct_def.ctor_id,
_ => None _ => None
} }
} }
@ -335,7 +335,7 @@ impl DeadVisitor {
} }
impl Visitor<()> for DeadVisitor { impl Visitor<()> for DeadVisitor {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
let ctor_id = get_struct_ctor_id(item); let ctor_id = get_struct_ctor_id(item);
if !self.symbol_is_live(item.id, ctor_id) && should_warn(item) { if !self.symbol_is_live(item.id, ctor_id) && should_warn(item) {
self.warn_dead_code(item.id, item.span, &item.ident); self.warn_dead_code(item.id, item.span, &item.ident);
@ -343,19 +343,19 @@ impl Visitor<()> for DeadVisitor {
visit::walk_item(self, item, ()); visit::walk_item(self, item, ());
} }
fn visit_foreign_item(&mut self, fi: &ast::foreign_item, _: ()) { fn visit_foreign_item(&mut self, fi: &ast::ForeignItem, _: ()) {
if !self.symbol_is_live(fi.id, None) { if !self.symbol_is_live(fi.id, None) {
self.warn_dead_code(fi.id, fi.span, &fi.ident); self.warn_dead_code(fi.id, fi.span, &fi.ident);
} }
visit::walk_foreign_item(self, fi, ()); visit::walk_foreign_item(self, fi, ());
} }
fn visit_fn(&mut self, fk: &visit::fn_kind, fn visit_fn(&mut self, fk: &visit::FnKind,
_: &ast::fn_decl, block: &ast::Block, _: &ast::FnDecl, block: &ast::Block,
span: codemap::Span, id: ast::NodeId, _: ()) { span: codemap::Span, id: ast::NodeId, _: ()) {
// Have to warn method here because methods are not ast::item // Have to warn method here because methods are not ast::Item
match *fk { match *fk {
visit::fk_method(..) => { visit::FkMethod(..) => {
let ident = visit::name_of_fn(fk); let ident = visit::name_of_fn(fk);
if !self.symbol_is_live(id, None) { if !self.symbol_is_live(id, None) {
self.warn_dead_code(id, span, &ident); self.warn_dead_code(id, span, &ident);
@ -367,10 +367,10 @@ impl Visitor<()> for DeadVisitor {
} }
// Overwrite so that we don't warn the trait method itself. // Overwrite so that we don't warn the trait method itself.
fn visit_trait_method(&mut self, trait_method: &ast::trait_method, _: ()) { fn visit_trait_method(&mut self, trait_method: &ast::TraitMethod, _: ()) {
match *trait_method { match *trait_method {
ast::provided(method) => visit::walk_block(self, method.body, ()), ast::Provided(method) => visit::walk_block(self, method.body, ()),
ast::required(_) => () ast::Required(_) => ()
} }
} }
} }

View file

@ -29,8 +29,8 @@ enum UnsafeContext {
fn type_is_unsafe_function(ty: ty::t) -> bool { fn type_is_unsafe_function(ty: ty::t) -> bool {
match ty::get(ty).sty { match ty::get(ty).sty {
ty::ty_bare_fn(ref f) => f.purity == ast::unsafe_fn, ty::ty_bare_fn(ref f) => f.purity == ast::UnsafeFn,
ty::ty_closure(ref f) => f.purity == ast::unsafe_fn, ty::ty_closure(ref f) => f.purity == ast::UnsafeFn,
_ => false, _ => false,
} }
} }
@ -81,14 +81,14 @@ impl EffectCheckVisitor {
} }
impl Visitor<()> for EffectCheckVisitor { impl Visitor<()> for EffectCheckVisitor {
fn visit_fn(&mut self, fn_kind: &visit::fn_kind, fn_decl: &ast::fn_decl, fn visit_fn(&mut self, fn_kind: &visit::FnKind, fn_decl: &ast::FnDecl,
block: &ast::Block, span: Span, node_id: ast::NodeId, _:()) { block: &ast::Block, span: Span, node_id: ast::NodeId, _:()) {
let (is_item_fn, is_unsafe_fn) = match *fn_kind { let (is_item_fn, is_unsafe_fn) = match *fn_kind {
visit::fk_item_fn(_, _, purity, _) => visit::FkItemFn(_, _, purity, _) =>
(true, purity == ast::unsafe_fn), (true, purity == ast::UnsafeFn),
visit::fk_method(_, _, method) => visit::FkMethod(_, _, method) =>
(true, method.purity == ast::unsafe_fn), (true, method.purity == ast::UnsafeFn),
_ => (false, false), _ => (false, false),
}; };

View file

@ -11,7 +11,7 @@
use driver::session; use driver::session;
use driver::session::Session; use driver::session::Session;
use syntax::ast::{Crate, NodeId, item, item_fn}; use syntax::ast::{Crate, NodeId, Item, ItemFn};
use syntax::ast_map; use syntax::ast_map;
use syntax::attr; use syntax::attr;
use syntax::codemap::Span; use syntax::codemap::Span;
@ -22,7 +22,7 @@ use syntax::visit::Visitor;
struct EntryContext { struct EntryContext {
session: Session, session: Session,
ast_map: ast_map::map, ast_map: ast_map::Map,
// The top-level function called 'main' // The top-level function called 'main'
main_fn: Option<(NodeId, Span)>, main_fn: Option<(NodeId, Span)>,
@ -39,12 +39,12 @@ struct EntryContext {
} }
impl Visitor<()> for EntryContext { impl Visitor<()> for EntryContext {
fn visit_item(&mut self, item: &item, _:()) { fn visit_item(&mut self, item: &Item, _:()) {
find_item(item, self); find_item(item, self);
} }
} }
pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map) { pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::Map) {
if session.building_library.get() { if session.building_library.get() {
// No need to find a main function // No need to find a main function
return; return;
@ -70,14 +70,14 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map)
configure_main(&mut ctxt); configure_main(&mut ctxt);
} }
fn find_item(item: &item, ctxt: &mut EntryContext) { fn find_item(item: &Item, ctxt: &mut EntryContext) {
match item.node { match item.node {
item_fn(..) => { ItemFn(..) => {
if item.ident.name == special_idents::main.name { if item.ident.name == special_idents::main.name {
{ {
let ast_map = ctxt.ast_map.borrow(); let ast_map = ctxt.ast_map.borrow();
match ast_map.get().find(&item.id) { match ast_map.get().find(&item.id) {
Some(&ast_map::node_item(_, path)) => { Some(&ast_map::NodeItem(_, path)) => {
if path.len() == 0 { if path.len() == 0 {
// This is a top-level function so can be 'main' // This is a top-level function so can be 'main'
if ctxt.main_fn.is_none() { if ctxt.main_fn.is_none() {

View file

@ -20,7 +20,6 @@ use syntax::codemap::Span;
use syntax::{ast, ast_util}; use syntax::{ast, ast_util};
use syntax::visit; use syntax::visit;
use syntax::visit::Visitor; use syntax::visit::Visitor;
use syntax::ast::{item};
// A vector of defs representing the free variables referred to in a function. // A vector of defs representing the free variables referred to in a function.
// (The def_upvar will already have been stripped). // (The def_upvar will already have been stripped).
@ -40,7 +39,7 @@ struct CollectFreevarsVisitor {
impl Visitor<int> for CollectFreevarsVisitor { impl Visitor<int> for CollectFreevarsVisitor {
fn visit_item(&mut self, _: &item, _: int) { fn visit_item(&mut self, _: &ast::Item, _: int) {
// ignore_item // ignore_item
} }
@ -112,7 +111,7 @@ struct AnnotateFreevarsVisitor {
} }
impl Visitor<()> for AnnotateFreevarsVisitor { impl Visitor<()> for AnnotateFreevarsVisitor {
fn visit_fn(&mut self, fk: &visit::fn_kind, fd: &ast::fn_decl, fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
blk: &ast::Block, s: Span, nid: ast::NodeId, _: ()) { blk: &ast::Block, s: Span, nid: ast::NodeId, _: ()) {
let vars = collect_freevars(self.def_map, blk); let vars = collect_freevars(self.def_map, blk);
self.freevars.insert(nid, vars); self.freevars.insert(nid, vars);

View file

@ -62,7 +62,7 @@ impl Visitor<()> for Context {
check_expr(self, ex); check_expr(self, ex);
} }
fn visit_fn(&mut self, fk: &visit::fn_kind, fd: &fn_decl, fn visit_fn(&mut self, fk: &visit::FnKind, fd: &FnDecl,
b: &Block, s: Span, n: NodeId, _: ()) { b: &Block, s: Span, n: NodeId, _: ()) {
check_fn(self, fk, fd, b, s, n); check_fn(self, fk, fd, b, s, n);
} }
@ -70,7 +70,7 @@ impl Visitor<()> for Context {
fn visit_ty(&mut self, t: &Ty, _: ()) { fn visit_ty(&mut self, t: &Ty, _: ()) {
check_ty(self, t); check_ty(self, t);
} }
fn visit_item(&mut self, i: &item, _: ()) { fn visit_item(&mut self, i: &Item, _: ()) {
check_item(self, i); check_item(self, i);
} }
} }
@ -116,7 +116,7 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
} }
} }
fn check_impl_of_trait(cx: &mut Context, it: &item, trait_ref: &trait_ref, self_type: &Ty) { fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_type: &Ty) {
let def_map = cx.tcx.def_map.borrow(); let def_map = cx.tcx.def_map.borrow();
let ast_trait_def = def_map.get() let ast_trait_def = def_map.get()
.find(&trait_ref.ref_id) .find(&trait_ref.ref_id)
@ -145,7 +145,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &item, trait_ref: &trait_ref, self_
// If this is a destructor, check kinds. // If this is a destructor, check kinds.
if cx.tcx.lang_items.drop_trait() == Some(trait_def_id) { if cx.tcx.lang_items.drop_trait() == Some(trait_def_id) {
match self_type.node { match self_type.node {
ty_path(_, ref bounds, path_node_id) => { TyPath(_, ref bounds, path_node_id) => {
assert!(bounds.is_none()); assert!(bounds.is_none());
let struct_def = def_map.get().get_copy(&path_node_id); let struct_def = def_map.get().get_copy(&path_node_id);
let struct_did = ast_util::def_id_of_def(struct_def); let struct_did = ast_util::def_id_of_def(struct_def);
@ -159,10 +159,10 @@ fn check_impl_of_trait(cx: &mut Context, it: &item, trait_ref: &trait_ref, self_
} }
} }
fn check_item(cx: &mut Context, item: &item) { fn check_item(cx: &mut Context, item: &Item) {
if !attr::contains_name(item.attrs, "unsafe_destructor") { if !attr::contains_name(item.attrs, "unsafe_destructor") {
match item.node { match item.node {
item_impl(_, Some(ref trait_ref), self_type, _) => { ItemImpl(_, Some(ref trait_ref), self_type, _) => {
check_impl_of_trait(cx, item, trait_ref, self_type); check_impl_of_trait(cx, item, trait_ref, self_type);
} }
_ => {} _ => {}
@ -246,8 +246,8 @@ fn with_appropriate_checker(cx: &Context,
// to the copy/move kind bounds. Then recursively check the function body. // to the copy/move kind bounds. Then recursively check the function body.
fn check_fn( fn check_fn(
cx: &mut Context, cx: &mut Context,
fk: &visit::fn_kind, fk: &visit::FnKind,
decl: &fn_decl, decl: &FnDecl,
body: &Block, body: &Block,
sp: Span, sp: Span,
fn_id: NodeId) { fn_id: NodeId) {
@ -353,20 +353,20 @@ fn check_trait_cast(cx: &mut Context, source_ty: ty::t, target_ty: ty::t, span:
fn check_ty(cx: &mut Context, aty: &Ty) { fn check_ty(cx: &mut Context, aty: &Ty) {
match aty.node { match aty.node {
ty_path(_, _, id) => { TyPath(_, _, id) => {
let node_type_substs = cx.tcx.node_type_substs.borrow(); let node_type_substs = cx.tcx.node_type_substs.borrow();
let r = node_type_substs.get().find(&id); let r = node_type_substs.get().find(&id);
for ts in r.iter() { for ts in r.iter() {
let def_map = cx.tcx.def_map.borrow(); let def_map = cx.tcx.def_map.borrow();
let did = ast_util::def_id_of_def(def_map.get().get_copy(&id)); let did = ast_util::def_id_of_def(def_map.get().get_copy(&id));
let type_param_defs = let type_param_defs =
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs; ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
for (&ty, type_param_def) in ts.iter().zip(type_param_defs.iter()) { for (&ty, type_param_def) in ts.iter().zip(type_param_defs.iter()) {
check_typaram_bounds(cx, aty.id, aty.span, ty, type_param_def) check_typaram_bounds(cx, aty.id, aty.span, ty, type_param_def)
} }
} }
} }
_ => {} _ => {}
} }
visit::walk_ty(cx, aty, ()); visit::walk_ty(cx, aty, ());
} }

View file

@ -109,7 +109,7 @@ struct LanguageItemVisitor<'a> {
} }
impl<'a> Visitor<()> for LanguageItemVisitor<'a> { impl<'a> Visitor<()> for LanguageItemVisitor<'a> {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
match extract(item.attrs) { match extract(item.attrs) {
Some(value) => { Some(value) => {
let item_index = self.this.item_refs.find_equiv(&value).map(|x| *x); let item_index = self.this.item_refs.find_equiv(&value).map(|x| *x);

View file

@ -380,7 +380,7 @@ struct Context<'a> {
method_map: typeck::method_map, method_map: typeck::method_map,
// Items exported by the crate; used by the missing_doc lint. // Items exported by the crate; used by the missing_doc lint.
exported_items: &'a privacy::ExportedItems, exported_items: &'a privacy::ExportedItems,
// The id of the current `ast::struct_def` being walked. // The id of the current `ast::StructDef` being walked.
cur_struct_def_id: ast::NodeId, cur_struct_def_id: ast::NodeId,
// Whether some ancestor of the current node was marked // Whether some ancestor of the current node was marked
// #[doc(hidden)]. // #[doc(hidden)].
@ -569,7 +569,7 @@ fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
ast::ExprWhile(cond, _) => { ast::ExprWhile(cond, _) => {
match cond.node { match cond.node {
ast::ExprLit(@codemap::Spanned { ast::ExprLit(@codemap::Spanned {
node: ast::lit_bool(true), ..}) => node: ast::LitBool(true), ..}) =>
{ {
cx.span_lint(while_true, e.span, cx.span_lint(while_true, e.span,
"denote infinite loops with loop { ... }"); "denote infinite loops with loop { ... }");
@ -623,14 +623,14 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
ast::ExprLit(lit) => { ast::ExprLit(lit) => {
match ty::get(ty::expr_ty(cx.tcx, e)).sty { match ty::get(ty::expr_ty(cx.tcx, e)).sty {
ty::ty_int(t) => { ty::ty_int(t) => {
let int_type = if t == ast::ty_i { let int_type = if t == ast::TyI {
cx.tcx.sess.targ_cfg.int_type cx.tcx.sess.targ_cfg.int_type
} else { t }; } else { t };
let (min, max) = int_ty_range(int_type); let (min, max) = int_ty_range(int_type);
let mut lit_val: i64 = match lit.node { let mut lit_val: i64 = match lit.node {
ast::lit_int(v, _) => v, ast::LitInt(v, _) => v,
ast::lit_uint(v, _) => v as i64, ast::LitUint(v, _) => v as i64,
ast::lit_int_unsuffixed(v) => v, ast::LitIntUnsuffixed(v) => v,
_ => fail!() _ => fail!()
}; };
if cx.negated_expr_id == e.id { if cx.negated_expr_id == e.id {
@ -642,14 +642,14 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
} }
}, },
ty::ty_uint(t) => { ty::ty_uint(t) => {
let uint_type = if t == ast::ty_u { let uint_type = if t == ast::TyU {
cx.tcx.sess.targ_cfg.uint_type cx.tcx.sess.targ_cfg.uint_type
} else { t }; } else { t };
let (min, max) = uint_ty_range(uint_type); let (min, max) = uint_ty_range(uint_type);
let lit_val: u64 = match lit.node { let lit_val: u64 = match lit.node {
ast::lit_int(v, _) => v as u64, ast::LitInt(v, _) => v as u64,
ast::lit_uint(v, _) => v, ast::LitUint(v, _) => v,
ast::lit_int_unsuffixed(v) => v as u64, ast::LitIntUnsuffixed(v) => v as u64,
_ => fail!() _ => fail!()
}; };
if lit_val < min || lit_val > max { if lit_val < min || lit_val > max {
@ -688,23 +688,23 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
// for int & uint, be conservative with the warnings, so that the // for int & uint, be conservative with the warnings, so that the
// warnings are consistent between 32- and 64-bit platforms // warnings are consistent between 32- and 64-bit platforms
fn int_ty_range(int_ty: ast::int_ty) -> (i64, i64) { fn int_ty_range(int_ty: ast::IntTy) -> (i64, i64) {
match int_ty { match int_ty {
ast::ty_i => (i64::min_value, i64::max_value), ast::TyI => (i64::min_value, i64::max_value),
ast::ty_i8 => (i8::min_value as i64, i8::max_value as i64), ast::TyI8 => (i8::min_value as i64, i8::max_value as i64),
ast::ty_i16 => (i16::min_value as i64, i16::max_value as i64), ast::TyI16 => (i16::min_value as i64, i16::max_value as i64),
ast::ty_i32 => (i32::min_value as i64, i32::max_value as i64), ast::TyI32 => (i32::min_value as i64, i32::max_value as i64),
ast::ty_i64 => (i64::min_value, i64::max_value) ast::TyI64 => (i64::min_value, i64::max_value)
} }
} }
fn uint_ty_range(uint_ty: ast::uint_ty) -> (u64, u64) { fn uint_ty_range(uint_ty: ast::UintTy) -> (u64, u64) {
match uint_ty { match uint_ty {
ast::ty_u => (u64::min_value, u64::max_value), ast::TyU => (u64::min_value, u64::max_value),
ast::ty_u8 => (u8::min_value as u64, u8::max_value as u64), ast::TyU8 => (u8::min_value as u64, u8::max_value as u64),
ast::ty_u16 => (u16::min_value as u64, u16::max_value as u64), ast::TyU16 => (u16::min_value as u64, u16::max_value as u64),
ast::ty_u32 => (u32::min_value as u64, u32::max_value as u64), ast::TyU32 => (u32::min_value as u64, u32::max_value as u64),
ast::ty_u64 => (u64::min_value, u64::max_value) ast::TyU64 => (u64::min_value, u64::max_value)
} }
} }
@ -723,9 +723,9 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
let (min, max) = int_ty_range(int_ty); let (min, max) = int_ty_range(int_ty);
let lit_val: i64 = match lit.node { let lit_val: i64 = match lit.node {
ast::ExprLit(li) => match li.node { ast::ExprLit(li) => match li.node {
ast::lit_int(v, _) => v, ast::LitInt(v, _) => v,
ast::lit_uint(v, _) => v as i64, ast::LitUint(v, _) => v as i64,
ast::lit_int_unsuffixed(v) => v, ast::LitIntUnsuffixed(v) => v,
_ => return true _ => return true
}, },
_ => fail!() _ => fail!()
@ -736,9 +736,9 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
let (min, max): (u64, u64) = uint_ty_range(uint_ty); let (min, max): (u64, u64) = uint_ty_range(uint_ty);
let lit_val: u64 = match lit.node { let lit_val: u64 = match lit.node {
ast::ExprLit(li) => match li.node { ast::ExprLit(li) => match li.node {
ast::lit_int(v, _) => v as u64, ast::LitInt(v, _) => v as u64,
ast::lit_uint(v, _) => v, ast::LitUint(v, _) => v,
ast::lit_int_unsuffixed(v) => v as u64, ast::LitIntUnsuffixed(v) => v as u64,
_ => return true _ => return true
}, },
_ => fail!() _ => fail!()
@ -758,18 +758,18 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
} }
} }
fn check_item_ctypes(cx: &Context, it: &ast::item) { fn check_item_ctypes(cx: &Context, it: &ast::Item) {
fn check_ty(cx: &Context, ty: &ast::Ty) { fn check_ty(cx: &Context, ty: &ast::Ty) {
match ty.node { match ty.node {
ast::ty_path(_, _, id) => { ast::TyPath(_, _, id) => {
let def_map = cx.tcx.def_map.borrow(); let def_map = cx.tcx.def_map.borrow();
match def_map.get().get_copy(&id) { match def_map.get().get_copy(&id) {
ast::DefPrimTy(ast::ty_int(ast::ty_i)) => { ast::DefPrimTy(ast::TyInt(ast::TyI)) => {
cx.span_lint(ctypes, ty.span, cx.span_lint(ctypes, ty.span,
"found rust type `int` in foreign module, while \ "found rust type `int` in foreign module, while \
libc::c_int or libc::c_long should be used"); libc::c_int or libc::c_long should be used");
} }
ast::DefPrimTy(ast::ty_uint(ast::ty_u)) => { ast::DefPrimTy(ast::TyUint(ast::TyU)) => {
cx.span_lint(ctypes, ty.span, cx.span_lint(ctypes, ty.span,
"found rust type `uint` in foreign module, while \ "found rust type `uint` in foreign module, while \
libc::c_uint or libc::c_ulong should be used"); libc::c_uint or libc::c_ulong should be used");
@ -785,12 +785,12 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
_ => () _ => ()
} }
} }
ast::ty_ptr(ref mt) => { check_ty(cx, mt.ty) } ast::TyPtr(ref mt) => { check_ty(cx, mt.ty) }
_ => () _ => {}
} }
} }
fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) { fn check_foreign_fn(cx: &Context, decl: &ast::FnDecl) {
for input in decl.inputs.iter() { for input in decl.inputs.iter() {
check_ty(cx, input.ty); check_ty(cx, input.ty);
} }
@ -798,13 +798,11 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
} }
match it.node { match it.node {
ast::item_foreign_mod(ref nmod) if !nmod.abis.is_intrinsic() => { ast::ItemForeignMod(ref nmod) if !nmod.abis.is_intrinsic() => {
for ni in nmod.items.iter() { for ni in nmod.items.iter() {
match ni.node { match ni.node {
ast::foreign_item_fn(decl, _) => { ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, decl),
check_foreign_fn(cx, decl); ast::ForeignItemStatic(t, _) => check_ty(cx, t)
}
ast::foreign_item_static(t, _) => { check_ty(cx, t); }
} }
} }
} }
@ -854,12 +852,12 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
} }
} }
fn check_heap_item(cx: &Context, it: &ast::item) { fn check_heap_item(cx: &Context, it: &ast::Item) {
match it.node { match it.node {
ast::item_fn(..) | ast::ItemFn(..) |
ast::item_ty(..) | ast::ItemTy(..) |
ast::item_enum(..) | ast::ItemEnum(..) |
ast::item_struct(..) => check_heap_type(cx, it.span, ast::ItemStruct(..) => check_heap_type(cx, it.span,
ty::node_id_to_type(cx.tcx, ty::node_id_to_type(cx.tcx,
it.id)), it.id)),
_ => () _ => ()
@ -867,7 +865,7 @@ fn check_heap_item(cx: &Context, it: &ast::item) {
// If it's a struct, we also have to check the fields' types // If it's a struct, we also have to check the fields' types
match it.node { match it.node {
ast::item_struct(struct_def, _) => { ast::ItemStruct(struct_def, _) => {
for struct_field in struct_def.fields.iter() { for struct_field in struct_def.fields.iter() {
check_heap_type(cx, struct_field.span, check_heap_type(cx, struct_field.span,
ty::node_id_to_type(cx.tcx, ty::node_id_to_type(cx.tcx,
@ -977,7 +975,7 @@ fn check_path_statement(cx: &Context, s: &ast::Stmt) {
} }
} }
fn check_item_non_camel_case_types(cx: &Context, it: &ast::item) { fn check_item_non_camel_case_types(cx: &Context, it: &ast::Item) {
fn is_camel_case(cx: ty::ctxt, ident: ast::Ident) -> bool { fn is_camel_case(cx: ty::ctxt, ident: ast::Ident) -> bool {
let ident = cx.sess.str_of(ident); let ident = cx.sess.str_of(ident);
assert!(!ident.is_empty()); assert!(!ident.is_empty());
@ -999,13 +997,13 @@ fn check_item_non_camel_case_types(cx: &Context, it: &ast::item) {
} }
match it.node { match it.node {
ast::item_ty(..) | ast::item_struct(..) => { ast::ItemTy(..) | ast::ItemStruct(..) => {
check_case(cx, "type", it.ident, it.span) check_case(cx, "type", it.ident, it.span)
} }
ast::item_trait(..) => { ast::ItemTrait(..) => {
check_case(cx, "trait", it.ident, it.span) check_case(cx, "trait", it.ident, it.span)
} }
ast::item_enum(ref enum_definition, _) => { ast::ItemEnum(ref enum_definition, _) => {
check_case(cx, "type", it.ident, it.span); check_case(cx, "type", it.ident, it.span);
for variant in enum_definition.variants.iter() { for variant in enum_definition.variants.iter() {
check_case(cx, "variant", variant.node.name, variant.span); check_case(cx, "variant", variant.node.name, variant.span);
@ -1015,10 +1013,10 @@ fn check_item_non_camel_case_types(cx: &Context, it: &ast::item) {
} }
} }
fn check_item_non_uppercase_statics(cx: &Context, it: &ast::item) { fn check_item_non_uppercase_statics(cx: &Context, it: &ast::Item) {
match it.node { match it.node {
// only check static constants // only check static constants
ast::item_static(_, ast::MutImmutable, _) => { ast::ItemStatic(_, ast::MutImmutable, _) => {
let s = cx.tcx.sess.str_of(it.ident); let s = cx.tcx.sess.str_of(it.ident);
// check for lowercase letters rather than non-uppercase // check for lowercase letters rather than non-uppercase
// ones (some scripts don't have a concept of // ones (some scripts don't have a concept of
@ -1112,7 +1110,7 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
ast::ExprVstore(e2, ast::ExprVstoreUniq) | ast::ExprVstore(e2, ast::ExprVstoreUniq) |
ast::ExprVstore(e2, ast::ExprVstoreBox) => { ast::ExprVstore(e2, ast::ExprVstoreBox) => {
match e2.node { match e2.node {
ast::ExprLit(@codemap::Spanned{node: ast::lit_str(..), ..}) | ast::ExprLit(@codemap::Spanned{node: ast::LitStr(..), ..}) |
ast::ExprVec(..) => VectorAllocation, ast::ExprVec(..) => VectorAllocation,
_ => return _ => return
} }
@ -1182,19 +1180,19 @@ fn check_missing_doc_attrs(cx: &Context,
} }
} }
fn check_missing_doc_item(cx: &Context, it: &ast::item) { fn check_missing_doc_item(cx: &Context, it: &ast::Item) {
let desc = match it.node { let desc = match it.node {
ast::item_fn(..) => "a function", ast::ItemFn(..) => "a function",
ast::item_mod(..) => "a module", ast::ItemMod(..) => "a module",
ast::item_enum(..) => "an enum", ast::ItemEnum(..) => "an enum",
ast::item_struct(..) => "a struct", ast::ItemStruct(..) => "a struct",
ast::item_trait(..) => "a trait", ast::ItemTrait(..) => "a trait",
_ => return _ => return
}; };
check_missing_doc_attrs(cx, Some(it.id), it.attrs, it.span, desc); check_missing_doc_attrs(cx, Some(it.id), it.attrs, it.span, desc);
} }
fn check_missing_doc_method(cx: &Context, m: &ast::method) { fn check_missing_doc_method(cx: &Context, m: &ast::Method) {
let did = ast::DefId { let did = ast::DefId {
crate: ast::LOCAL_CRATE, crate: ast::LOCAL_CRATE,
node: m.id node: m.id
@ -1231,16 +1229,16 @@ fn check_missing_doc_ty_method(cx: &Context, tm: &ast::TypeMethod) {
check_missing_doc_attrs(cx, Some(tm.id), tm.attrs, tm.span, "a type method"); check_missing_doc_attrs(cx, Some(tm.id), tm.attrs, tm.span, "a type method");
} }
fn check_missing_doc_struct_field(cx: &Context, sf: &ast::struct_field) { fn check_missing_doc_struct_field(cx: &Context, sf: &ast::StructField) {
match sf.node.kind { match sf.node.kind {
ast::named_field(_, vis) if vis != ast::private => ast::NamedField(_, vis) if vis != ast::Private =>
check_missing_doc_attrs(cx, Some(cx.cur_struct_def_id), sf.node.attrs, check_missing_doc_attrs(cx, Some(cx.cur_struct_def_id), sf.node.attrs,
sf.span, "a struct field"), sf.span, "a struct field"),
_ => {} _ => {}
} }
} }
fn check_missing_doc_variant(cx: &Context, v: &ast::variant) { fn check_missing_doc_variant(cx: &Context, v: &ast::Variant) {
check_missing_doc_attrs(cx, Some(v.node.id), v.node.attrs, v.span, "a variant"); check_missing_doc_attrs(cx, Some(v.node.id), v.node.attrs, v.span, "a variant");
} }
@ -1345,7 +1343,7 @@ fn check_stability(cx: &Context, e: &ast::Expr) {
} }
impl<'a> Visitor<()> for Context<'a> { impl<'a> Visitor<()> for Context<'a> {
fn visit_item(&mut self, it: &ast::item, _: ()) { fn visit_item(&mut self, it: &ast::Item, _: ()) {
self.with_lint_attrs(it.attrs, |cx| { self.with_lint_attrs(it.attrs, |cx| {
check_item_ctypes(cx, it); check_item_ctypes(cx, it);
check_item_non_camel_case_types(cx, it); check_item_non_camel_case_types(cx, it);
@ -1360,14 +1358,14 @@ impl<'a> Visitor<()> for Context<'a> {
}) })
} }
fn visit_foreign_item(&mut self, it: &ast::foreign_item, _: ()) { fn visit_foreign_item(&mut self, it: &ast::ForeignItem, _: ()) {
self.with_lint_attrs(it.attrs, |cx| { self.with_lint_attrs(it.attrs, |cx| {
check_attrs_usage(cx, it.attrs); check_attrs_usage(cx, it.attrs);
visit::walk_foreign_item(cx, it, ()); visit::walk_foreign_item(cx, it, ());
}) })
} }
fn visit_view_item(&mut self, i: &ast::view_item, _: ()) { fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
self.with_lint_attrs(i.attrs, |cx| { self.with_lint_attrs(i.attrs, |cx| {
check_attrs_usage(cx, i.attrs); check_attrs_usage(cx, i.attrs);
visit::walk_view_item(cx, i, ()); visit::walk_view_item(cx, i, ());
@ -1414,14 +1412,14 @@ impl<'a> Visitor<()> for Context<'a> {
visit::walk_stmt(self, s, ()); visit::walk_stmt(self, s, ());
} }
fn visit_fn(&mut self, fk: &visit::fn_kind, decl: &ast::fn_decl, fn visit_fn(&mut self, fk: &visit::FnKind, decl: &ast::FnDecl,
body: &ast::Block, span: Span, id: ast::NodeId, _: ()) { body: &ast::Block, span: Span, id: ast::NodeId, _: ()) {
let recurse = |this: &mut Context| { let recurse = |this: &mut Context| {
visit::walk_fn(this, fk, decl, body, span, id, ()); visit::walk_fn(this, fk, decl, body, span, id, ());
}; };
match *fk { match *fk {
visit::fk_method(_, _, m) => { visit::FkMethod(_, _, m) => {
self.with_lint_attrs(m.attrs, |cx| { self.with_lint_attrs(m.attrs, |cx| {
check_missing_doc_method(cx, m); check_missing_doc_method(cx, m);
check_attrs_usage(cx, m.attrs); check_attrs_usage(cx, m.attrs);
@ -1447,7 +1445,7 @@ impl<'a> Visitor<()> for Context<'a> {
} }
fn visit_struct_def(&mut self, fn visit_struct_def(&mut self,
s: &ast::struct_def, s: &ast::StructDef,
i: ast::Ident, i: ast::Ident,
g: &ast::Generics, g: &ast::Generics,
id: ast::NodeId, id: ast::NodeId,
@ -1458,7 +1456,7 @@ impl<'a> Visitor<()> for Context<'a> {
self.cur_struct_def_id = old_id; self.cur_struct_def_id = old_id;
} }
fn visit_struct_field(&mut self, s: &ast::struct_field, _: ()) { fn visit_struct_field(&mut self, s: &ast::StructField, _: ()) {
self.with_lint_attrs(s.node.attrs, |cx| { self.with_lint_attrs(s.node.attrs, |cx| {
check_missing_doc_struct_field(cx, s); check_missing_doc_struct_field(cx, s);
check_attrs_usage(cx, s.node.attrs); check_attrs_usage(cx, s.node.attrs);
@ -1467,7 +1465,7 @@ impl<'a> Visitor<()> for Context<'a> {
}) })
} }
fn visit_variant(&mut self, v: &ast::variant, g: &ast::Generics, _: ()) { fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, _: ()) {
self.with_lint_attrs(v.node.attrs, |cx| { self.with_lint_attrs(v.node.attrs, |cx| {
check_missing_doc_variant(cx, v); check_missing_doc_variant(cx, v);
check_attrs_usage(cx, v.node.attrs); check_attrs_usage(cx, v.node.attrs);

View file

@ -122,7 +122,7 @@ use syntax::codemap::Span;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
use syntax::print::pprust::{expr_to_str, block_to_str}; use syntax::print::pprust::{expr_to_str, block_to_str};
use syntax::{visit, ast_util}; use syntax::{visit, ast_util};
use syntax::visit::{Visitor,fn_kind}; use syntax::visit::{Visitor, FnKind};
#[deriving(Eq)] #[deriving(Eq)]
struct Variable(uint); struct Variable(uint);
@ -164,7 +164,7 @@ fn live_node_kind_to_str(lnk: LiveNodeKind, cx: ty::ctxt) -> ~str {
struct LivenessVisitor; struct LivenessVisitor;
impl Visitor<@IrMaps> for LivenessVisitor { impl Visitor<@IrMaps> for LivenessVisitor {
fn visit_fn(&mut self, fk: &fn_kind, fd: &fn_decl, b: &Block, s: Span, n: NodeId, e: @IrMaps) { fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, n: NodeId, e: @IrMaps) {
visit_fn(self, fk, fd, b, s, n, e); visit_fn(self, fk, fd, b, s, n, e);
} }
fn visit_local(&mut self, l: &Local, e: @IrMaps) { visit_local(self, l, e); } fn visit_local(&mut self, l: &Local, e: @IrMaps) { visit_local(self, l, e); }
@ -364,7 +364,7 @@ impl IrMaps {
} }
impl Visitor<()> for Liveness { impl Visitor<()> for Liveness {
fn visit_fn(&mut self, fk: &fn_kind, fd: &fn_decl, b: &Block, s: Span, n: NodeId, _: ()) { fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, n: NodeId, _: ()) {
check_fn(self, fk, fd, b, s, n); check_fn(self, fk, fd, b, s, n);
} }
fn visit_local(&mut self, l: &Local, _: ()) { fn visit_local(&mut self, l: &Local, _: ()) {
@ -379,8 +379,8 @@ impl Visitor<()> for Liveness {
} }
fn visit_fn(v: &mut LivenessVisitor, fn visit_fn(v: &mut LivenessVisitor,
fk: &visit::fn_kind, fk: &FnKind,
decl: &fn_decl, decl: &FnDecl,
body: &Block, body: &Block,
sp: Span, sp: Span,
id: NodeId, id: NodeId,
@ -407,16 +407,16 @@ fn visit_fn(v: &mut LivenessVisitor,
// Add `this`, whether explicit or implicit. // Add `this`, whether explicit or implicit.
match *fk { match *fk {
visit::fk_method(_, _, method) => { visit::FkMethod(_, _, method) => {
match method.explicit_self.node { match method.explicit_self.node {
sty_value(_) | sty_region(..) | sty_box(_) | sty_uniq(_) => { SelfValue(_) | SelfRegion(..) | SelfBox(_) | SelfUniq(_) => {
fn_maps.add_variable(Arg(method.self_id, fn_maps.add_variable(Arg(method.self_id,
special_idents::self_)); special_idents::self_));
} }
sty_static => {} SelfStatic => {}
} }
} }
visit::fk_item_fn(..) | visit::fk_fn_block(..) => {} visit::FkItemFn(..) | visit::FkFnBlock(..) => {}
} }
// gather up the various local variables, significant expressions, // gather up the various local variables, significant expressions,
@ -932,7 +932,7 @@ impl Liveness {
// _______________________________________________________________________ // _______________________________________________________________________
pub fn compute(&self, decl: &fn_decl, body: &Block) -> LiveNode { pub fn compute(&self, decl: &FnDecl, body: &Block) -> LiveNode {
// if there is a `break` or `again` at the top level, then it's // if there is a `break` or `again` at the top level, then it's
// effectively a return---this only occurs in `for` loops, // effectively a return---this only occurs in `for` loops,
// where the body is really a closure. // where the body is really a closure.
@ -957,7 +957,7 @@ impl Liveness {
entry_ln entry_ln
} }
pub fn propagate_through_fn_block(&self, _: &fn_decl, blk: &Block) pub fn propagate_through_fn_block(&self, _: &FnDecl, blk: &Block)
-> LiveNode { -> LiveNode {
// the fallthrough exit is only for those cases where we do not // the fallthrough exit is only for those cases where we do not
// explicitly return: // explicitly return:
@ -1554,8 +1554,8 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
} }
fn check_fn(_v: &Liveness, fn check_fn(_v: &Liveness,
_fk: &visit::fn_kind, _fk: &FnKind,
_decl: &fn_decl, _decl: &FnDecl,
_body: &Block, _body: &Block,
_sp: Span, _sp: Span,
_id: NodeId) { _id: NodeId) {
@ -1573,7 +1573,7 @@ impl Liveness {
pub fn check_ret(&self, pub fn check_ret(&self,
id: NodeId, id: NodeId,
sp: Span, sp: Span,
_fk: &visit::fn_kind, _fk: &FnKind,
entry_ln: LiveNode) { entry_ln: LiveNode) {
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() { if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
// if no_ret_var is live, then we fall off the end of the // if no_ret_var is live, then we fall off the end of the
@ -1665,7 +1665,7 @@ impl Liveness {
if name.len() == 0 || name[0] == ('_' as u8) { None } else { Some(name) } if name.len() == 0 || name[0] == ('_' as u8) { None } else { Some(name) }
} }
pub fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) { pub fn warn_about_unused_args(&self, decl: &FnDecl, entry_ln: LiveNode) {
for arg in decl.inputs.iter() { for arg in decl.inputs.iter() {
pat_util::pat_bindings(self.tcx.def_map, pat_util::pat_bindings(self.tcx.def_map,
arg.pat, arg.pat,

View file

@ -193,7 +193,7 @@ enum UseMode {
} }
impl visit::Visitor<()> for VisitContext { impl visit::Visitor<()> for VisitContext {
fn visit_fn(&mut self, fk: &visit::fn_kind, fd: &fn_decl, fn visit_fn(&mut self, fk: &visit::FnKind, fd: &FnDecl,
b: &Block, s: Span, n: NodeId, _: ()) { b: &Block, s: Span, n: NodeId, _: ()) {
compute_modes_for_fn(self, fk, fd, b, s, n); compute_modes_for_fn(self, fk, fd, b, s, n);
} }
@ -248,8 +248,8 @@ fn compute_modes_for_local<'a>(cx: &mut VisitContext,
} }
fn compute_modes_for_fn(cx: &mut VisitContext, fn compute_modes_for_fn(cx: &mut VisitContext,
fk: &visit::fn_kind, fk: &visit::FnKind,
decl: &fn_decl, decl: &FnDecl,
body: &Block, body: &Block,
span: Span, span: Span,
id: NodeId) { id: NodeId) {

View file

@ -50,20 +50,20 @@ struct ParentVisitor {
} }
impl Visitor<()> for ParentVisitor { impl Visitor<()> for ParentVisitor {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
self.parents.insert(item.id, self.curparent); self.parents.insert(item.id, self.curparent);
let prev = self.curparent; let prev = self.curparent;
match item.node { match item.node {
ast::item_mod(..) => { self.curparent = item.id; } ast::ItemMod(..) => { self.curparent = item.id; }
// Enum variants are parented to the enum definition itself beacuse // Enum variants are parented to the enum definition itself beacuse
// they inherit privacy // they inherit privacy
ast::item_enum(ref def, _) => { ast::ItemEnum(ref def, _) => {
for variant in def.variants.iter() { for variant in def.variants.iter() {
// If variants are private, then their logical "parent" is // If variants are private, then their logical "parent" is
// the enclosing module because everyone in the enclosing // the enclosing module because everyone in the enclosing
// module can still use the private variant // module can still use the private variant
if variant.node.vis == ast::private { if variant.node.vis == ast::Private {
self.parents.insert(variant.node.id, self.curparent); self.parents.insert(variant.node.id, self.curparent);
// Otherwise, if the variant is public, then the parent is // Otherwise, if the variant is public, then the parent is
@ -80,11 +80,11 @@ impl Visitor<()> for ParentVisitor {
// method to the root. In this case, if the trait is private, then // method to the root. In this case, if the trait is private, then
// parent all the methods to the trait to indicate that they're // parent all the methods to the trait to indicate that they're
// private. // private.
ast::item_trait(_, _, ref methods) if item.vis != ast::public => { ast::ItemTrait(_, _, ref methods) if item.vis != ast::Public => {
for m in methods.iter() { for m in methods.iter() {
match *m { match *m {
ast::provided(ref m) => self.parents.insert(m.id, item.id), ast::Provided(ref m) => self.parents.insert(m.id, item.id),
ast::required(ref m) => self.parents.insert(m.id, item.id), ast::Required(ref m) => self.parents.insert(m.id, item.id),
}; };
} }
} }
@ -95,12 +95,12 @@ impl Visitor<()> for ParentVisitor {
self.curparent = prev; self.curparent = prev;
} }
fn visit_foreign_item(&mut self, a: &ast::foreign_item, _: ()) { fn visit_foreign_item(&mut self, a: &ast::ForeignItem, _: ()) {
self.parents.insert(a.id, self.curparent); self.parents.insert(a.id, self.curparent);
visit::walk_foreign_item(self, a, ()); visit::walk_foreign_item(self, a, ());
} }
fn visit_fn(&mut self, a: &visit::fn_kind, b: &ast::fn_decl, fn visit_fn(&mut self, a: &visit::FnKind, b: &ast::FnDecl,
c: &ast::Block, d: Span, id: ast::NodeId, _: ()) { c: &ast::Block, d: Span, id: ast::NodeId, _: ()) {
// We already took care of some trait methods above, otherwise things // We already took care of some trait methods above, otherwise things
// like impl methods and pub trait methods are parented to the // like impl methods and pub trait methods are parented to the
@ -111,7 +111,7 @@ impl Visitor<()> for ParentVisitor {
visit::walk_fn(self, a, b, c, d, id, ()); visit::walk_fn(self, a, b, c, d, id, ());
} }
fn visit_struct_def(&mut self, s: &ast::struct_def, i: ast::Ident, fn visit_struct_def(&mut self, s: &ast::StructDef, i: ast::Ident,
g: &ast::Generics, n: ast::NodeId, _: ()) { g: &ast::Generics, n: ast::NodeId, _: ()) {
// Struct constructors are parented to their struct definitions because // Struct constructors are parented to their struct definitions because
// they essentially are the struct definitions. // they essentially are the struct definitions.
@ -124,14 +124,14 @@ impl Visitor<()> for ParentVisitor {
// all the fields. // all the fields.
for field in s.fields.iter() { for field in s.fields.iter() {
let vis = match field.node.kind { let vis = match field.node.kind {
ast::named_field(_, vis) => vis, ast::NamedField(_, vis) => vis,
ast::unnamed_field => continue ast::UnnamedField => continue
}; };
// Private fields are scoped to this module, so parent them directly // Private fields are scoped to this module, so parent them directly
// to the module instead of the struct. This is similar to the case // to the module instead of the struct. This is similar to the case
// of private enum variants. // of private enum variants.
if vis == ast::private { if vis == ast::Private {
self.parents.insert(field.node.id, self.curparent); self.parents.insert(field.node.id, self.curparent);
// Otherwise public fields are scoped to the visibility of the // Otherwise public fields are scoped to the visibility of the
@ -196,9 +196,9 @@ impl<'a> EmbargoVisitor<'a> {
} }
impl<'a> Visitor<()> for EmbargoVisitor<'a> { impl<'a> Visitor<()> for EmbargoVisitor<'a> {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
let orig_all_pub = self.prev_public; let orig_all_pub = self.prev_public;
self.prev_public = orig_all_pub && item.vis == ast::public; self.prev_public = orig_all_pub && item.vis == ast::Public;
if self.prev_public { if self.prev_public {
self.public_items.insert(item.id); self.public_items.insert(item.id);
} }
@ -207,11 +207,11 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
match item.node { match item.node {
// impls/extern blocks do not break the "public chain" because they // impls/extern blocks do not break the "public chain" because they
// cannot have visibility qualifiers on them anyway // cannot have visibility qualifiers on them anyway
ast::item_impl(..) | ast::item_foreign_mod(..) => {} ast::ItemImpl(..) | ast::ItemForeignMod(..) => {}
// Traits are a little special in that even if they themselves are // Traits are a little special in that even if they themselves are
// not public they may still be exported. // not public they may still be exported.
ast::item_trait(..) => { ast::ItemTrait(..) => {
self.prev_exported = self.exported_trait(item.id); self.prev_exported = self.exported_trait(item.id);
} }
@ -219,7 +219,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
// `pub` is explicitly listed. // `pub` is explicitly listed.
_ => { _ => {
self.prev_exported = self.prev_exported =
(orig_all_exported && item.vis == ast::public) || (orig_all_exported && item.vis == ast::Public) ||
self.reexports.contains(&item.id); self.reexports.contains(&item.id);
} }
} }
@ -230,9 +230,9 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
match item.node { match item.node {
// Enum variants inherit from their parent, so if the enum is // Enum variants inherit from their parent, so if the enum is
// public all variants are public unless they're explicitly priv // public all variants are public unless they're explicitly priv
ast::item_enum(ref def, _) if public_first => { ast::ItemEnum(ref def, _) if public_first => {
for variant in def.variants.iter() { for variant in def.variants.iter() {
if variant.node.vis != ast::private { if variant.node.vis != ast::Private {
self.exported_items.insert(variant.node.id); self.exported_items.insert(variant.node.id);
} }
} }
@ -257,9 +257,9 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
// undefined symbols at linkage time if this case is not handled. // undefined symbols at linkage time if this case is not handled.
// //
// * Private trait impls for private types can be completely ignored // * Private trait impls for private types can be completely ignored
ast::item_impl(_, _, ref ty, ref methods) => { ast::ItemImpl(_, _, ref ty, ref methods) => {
let public_ty = match ty.node { let public_ty = match ty.node {
ast::ty_path(_, _, id) => { ast::TyPath(_, _, id) => {
let def_map = self.tcx.def_map.borrow(); let def_map = self.tcx.def_map.borrow();
match def_map.get().get_copy(&id) { match def_map.get().get_copy(&id) {
ast::DefPrimTy(..) => true, ast::DefPrimTy(..) => true,
@ -281,9 +281,9 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
if public_ty || public_trait { if public_ty || public_trait {
for method in methods.iter() { for method in methods.iter() {
let meth_public = match method.explicit_self.node { let meth_public = match method.explicit_self.node {
ast::sty_static => public_ty, ast::SelfStatic => public_ty,
_ => true, _ => true,
} && method.vis == ast::public; } && method.vis == ast::Public;
if meth_public || tr.is_some() { if meth_public || tr.is_some() {
self.exported_items.insert(method.id); self.exported_items.insert(method.id);
} }
@ -293,14 +293,14 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
// Default methods on traits are all public so long as the trait // Default methods on traits are all public so long as the trait
// is public // is public
ast::item_trait(_, _, ref methods) if public_first => { ast::ItemTrait(_, _, ref methods) if public_first => {
for method in methods.iter() { for method in methods.iter() {
match *method { match *method {
ast::provided(ref m) => { ast::Provided(ref m) => {
debug!("provided {}", m.id); debug!("provided {}", m.id);
self.exported_items.insert(m.id); self.exported_items.insert(m.id);
} }
ast::required(ref m) => { ast::Required(ref m) => {
debug!("required {}", m.id); debug!("required {}", m.id);
self.exported_items.insert(m.id); self.exported_items.insert(m.id);
} }
@ -309,7 +309,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
} }
// Struct constructors are public if the struct is all public. // Struct constructors are public if the struct is all public.
ast::item_struct(ref def, _) if public_first => { ast::ItemStruct(ref def, _) if public_first => {
match def.ctor_id { match def.ctor_id {
Some(id) => { self.exported_items.insert(id); } Some(id) => { self.exported_items.insert(id); }
None => {} None => {}
@ -325,13 +325,13 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
self.prev_public = orig_all_pub; self.prev_public = orig_all_pub;
} }
fn visit_foreign_item(&mut self, a: &ast::foreign_item, _: ()) { fn visit_foreign_item(&mut self, a: &ast::ForeignItem, _: ()) {
if self.prev_exported && a.vis == ast::public { if self.prev_exported && a.vis == ast::Public {
self.exported_items.insert(a.id); self.exported_items.insert(a.id);
} }
} }
fn visit_mod(&mut self, m: &ast::_mod, _sp: Span, id: ast::NodeId, _: ()) { fn visit_mod(&mut self, m: &ast::Mod, _sp: Span, id: ast::NodeId, _: ()) {
// This code is here instead of in visit_item so that the // This code is here instead of in visit_item so that the
// crate module gets processed as well. // crate module gets processed as well.
if self.prev_exported { if self.prev_exported {
@ -402,7 +402,7 @@ impl<'a> PrivacyVisitor<'a> {
None => { None => {
debug!("privacy - found a method {:?}", debug!("privacy - found a method {:?}",
meth.vis); meth.vis);
if meth.vis == ast::public { if meth.vis == ast::Public {
Allowable Allowable
} else { } else {
ExternallyDenied ExternallyDenied
@ -449,30 +449,30 @@ impl<'a> PrivacyVisitor<'a> {
// invocation. // invocation.
// FIXME(#10573) is this the right behavior? Why not consider // FIXME(#10573) is this the right behavior? Why not consider
// where the method was defined? // where the method was defined?
Some(&ast_map::node_method(ref m, imp, _)) => { Some(&ast_map::NodeMethod(ref m, imp, _)) => {
match ty::impl_trait_ref(self.tcx, imp) { match ty::impl_trait_ref(self.tcx, imp) {
Some(..) => return Allowable, Some(..) => return Allowable,
_ if m.vis == ast::public => return Allowable, _ if m.vis == ast::Public => return Allowable,
_ => m.vis _ => m.vis
} }
} }
Some(&ast_map::node_trait_method(..)) => { Some(&ast_map::NodeTraitMethod(..)) => {
return Allowable; return Allowable;
} }
// This is not a method call, extract the visibility as one // This is not a method call, extract the visibility as one
// would normally look at it // would normally look at it
Some(&ast_map::node_item(it, _)) => it.vis, Some(&ast_map::NodeItem(it, _)) => it.vis,
Some(&ast_map::node_foreign_item(_, _, v, _)) => v, Some(&ast_map::NodeForeignItem(_, _, v, _)) => v,
Some(&ast_map::node_variant(ref v, _, _)) => { Some(&ast_map::NodeVariant(ref v, _, _)) => {
// sadly enum variants still inherit visibility, so only // sadly enum variants still inherit visibility, so only
// break out of this is explicitly private // break out of this is explicitly private
if v.node.vis == ast::private { break } if v.node.vis == ast::Private { break }
ast::public // need to move up a level (to the enum) ast::Public // need to move up a level (to the enum)
} }
_ => ast::public, _ => ast::Public,
}; };
if vis != ast::public { break } if vis != ast::Public { break }
// if we've reached the root, then everything was allowable and this // if we've reached the root, then everything was allowable and this
// access is public. // access is public.
if closest_private_id == ast::CRATE_NODE_ID { return Allowable } if closest_private_id == ast::CRATE_NODE_ID { return Allowable }
@ -540,10 +540,10 @@ impl<'a> PrivacyVisitor<'a> {
} }
let items = self.tcx.items.borrow(); let items = self.tcx.items.borrow();
match items.get().find(&id) { match items.get().find(&id) {
Some(&ast_map::node_item(item, _)) => { Some(&ast_map::NodeItem(item, _)) => {
let desc = match item.node { let desc = match item.node {
ast::item_mod(..) => "module", ast::ItemMod(..) => "module",
ast::item_trait(..) => "trait", ast::ItemTrait(..) => "trait",
_ => return false, _ => return false,
}; };
let msg = format!("{} `{}` is private", desc, let msg = format!("{} `{}` is private", desc,
@ -565,7 +565,7 @@ impl<'a> PrivacyVisitor<'a> {
for field in fields.iter() { for field in fields.iter() {
if field.name != ident.name { continue; } if field.name != ident.name { continue; }
// public fields are public everywhere // public fields are public everywhere
if field.vis != ast::private { break } if field.vis != ast::Private { break }
if !is_local(field.id) || if !is_local(field.id) ||
!self.private_accessible(field.id.node) { !self.private_accessible(field.id.node) {
self.tcx.sess.span_err(span, format!("field `{}` is private", self.tcx.sess.span_err(span, format!("field `{}` is private",
@ -638,7 +638,7 @@ impl<'a> PrivacyVisitor<'a> {
} }
impl<'a> Visitor<()> for PrivacyVisitor<'a> { impl<'a> Visitor<()> for PrivacyVisitor<'a> {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
// Do not check privacy inside items with the resolve_unexported // Do not check privacy inside items with the resolve_unexported
// attribute. This is used for the test runner. // attribute. This is used for the test runner.
if attr::contains_name(item.attrs, "!resolve_unexported") { if attr::contains_name(item.attrs, "!resolve_unexported") {
@ -722,15 +722,14 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
visit::walk_expr(self, expr, ()); visit::walk_expr(self, expr, ());
} }
fn visit_view_item(&mut self, a: &ast::view_item, _: ()) { fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) {
match a.node { match a.node {
ast::view_item_extern_mod(..) => {} ast::ViewItemExternMod(..) => {}
ast::view_item_use(ref uses) => { ast::ViewItemUse(ref uses) => {
for vpath in uses.iter() { for vpath in uses.iter() {
match vpath.node { match vpath.node {
ast::view_path_simple(..) | ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
ast::view_path_glob(..) => {} ast::ViewPathList(_, ref list, _) => {
ast::view_path_list(_, ref list, _) => {
for pid in list.iter() { for pid in list.iter() {
debug!("privacy - list {}", pid.node.id); debug!("privacy - list {}", pid.node.id);
let seg = ast::PathSegment { let seg = ast::PathSegment {
@ -796,7 +795,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
visit::walk_pat(self, pattern, ()); visit::walk_pat(self, pattern, ());
} }
fn visit_foreign_item(&mut self, fi: &ast::foreign_item, _: ()) { fn visit_foreign_item(&mut self, fi: &ast::ForeignItem, _: ()) {
self.in_foreign = true; self.in_foreign = true;
visit::walk_foreign_item(self, fi, ()); visit::walk_foreign_item(self, fi, ());
self.in_foreign = false; self.in_foreign = false;
@ -818,7 +817,7 @@ struct SanePrivacyVisitor {
} }
impl Visitor<()> for SanePrivacyVisitor { impl Visitor<()> for SanePrivacyVisitor {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
if self.in_fn { if self.in_fn {
self.check_all_inherited(item); self.check_all_inherited(item);
} else { } else {
@ -826,14 +825,14 @@ impl Visitor<()> for SanePrivacyVisitor {
} }
let orig_in_fn = util::replace(&mut self.in_fn, match item.node { let orig_in_fn = util::replace(&mut self.in_fn, match item.node {
ast::item_mod(..) => false, // modules turn privacy back on ast::ItemMod(..) => false, // modules turn privacy back on
_ => self.in_fn, // otherwise we inherit _ => self.in_fn, // otherwise we inherit
}); });
visit::walk_item(self, item, ()); visit::walk_item(self, item, ());
self.in_fn = orig_in_fn; self.in_fn = orig_in_fn;
} }
fn visit_fn(&mut self, fk: &visit::fn_kind, fd: &ast::fn_decl, fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
b: &ast::Block, s: Span, n: ast::NodeId, _: ()) { b: &ast::Block, s: Span, n: ast::NodeId, _: ()) {
// This catches both functions and methods // This catches both functions and methods
let orig_in_fn = util::replace(&mut self.in_fn, true); let orig_in_fn = util::replace(&mut self.in_fn, true);
@ -847,42 +846,42 @@ impl SanePrivacyVisitor {
/// ensures that there are no extraneous qualifiers that don't actually do /// ensures that there are no extraneous qualifiers that don't actually do
/// anything. In theory these qualifiers wouldn't parse, but that may happen /// anything. In theory these qualifiers wouldn't parse, but that may happen
/// later on down the road... /// later on down the road...
fn check_sane_privacy(&self, item: &ast::item) { fn check_sane_privacy(&self, item: &ast::Item) {
let tcx = self.tcx; let tcx = self.tcx;
let check_inherited = |sp: Span, vis: ast::visibility, note: &str| { let check_inherited = |sp: Span, vis: ast::Visibility, note: &str| {
if vis != ast::inherited { if vis != ast::Inherited {
tcx.sess.span_err(sp, "unnecessary visibility qualifier"); tcx.sess.span_err(sp, "unnecessary visibility qualifier");
if note.len() > 0 { if note.len() > 0 {
tcx.sess.span_note(sp, note); tcx.sess.span_note(sp, note);
} }
} }
}; };
let check_not_priv = |sp: Span, vis: ast::visibility, note: &str| { let check_not_priv = |sp: Span, vis: ast::Visibility, note: &str| {
if vis == ast::private { if vis == ast::Private {
tcx.sess.span_err(sp, "unnecessary `priv` qualifier"); tcx.sess.span_err(sp, "unnecessary `priv` qualifier");
if note.len() > 0 { if note.len() > 0 {
tcx.sess.span_note(sp, note); tcx.sess.span_note(sp, note);
} }
} }
}; };
let check_struct = |def: &@ast::struct_def| { let check_struct = |def: &@ast::StructDef| {
for f in def.fields.iter() { for f in def.fields.iter() {
match f.node.kind { match f.node.kind {
ast::named_field(_, ast::public) => { ast::NamedField(_, ast::Public) => {
tcx.sess.span_err(f.span, "unnecessary `pub` \ tcx.sess.span_err(f.span, "unnecessary `pub` \
visibility"); visibility");
} }
ast::named_field(_, ast::private) => { ast::NamedField(_, ast::Private) => {
// Fields should really be private by default... // Fields should really be private by default...
} }
ast::named_field(..) | ast::unnamed_field => {} ast::NamedField(..) | ast::UnnamedField => {}
} }
} }
}; };
match item.node { match item.node {
// implementations of traits don't need visibility qualifiers because // implementations of traits don't need visibility qualifiers because
// that's controlled by having the trait in scope. // that's controlled by having the trait in scope.
ast::item_impl(_, Some(..), _, ref methods) => { ast::ItemImpl(_, Some(..), _, ref methods) => {
check_inherited(item.span, item.vis, check_inherited(item.span, item.vis,
"visibility qualifiers have no effect on trait \ "visibility qualifiers have no effect on trait \
impls"); impls");
@ -891,7 +890,7 @@ impl SanePrivacyVisitor {
} }
} }
ast::item_impl(_, _, _, ref methods) => { ast::ItemImpl(_, _, _, ref methods) => {
check_inherited(item.span, item.vis, check_inherited(item.span, item.vis,
"place qualifiers on individual methods instead"); "place qualifiers on individual methods instead");
for i in methods.iter() { for i in methods.iter() {
@ -899,7 +898,7 @@ impl SanePrivacyVisitor {
default"); default");
} }
} }
ast::item_foreign_mod(ref fm) => { ast::ItemForeignMod(ref fm) => {
check_inherited(item.span, item.vis, check_inherited(item.span, item.vis,
"place qualifiers on individual functions \ "place qualifiers on individual functions \
instead"); instead");
@ -909,48 +908,48 @@ impl SanePrivacyVisitor {
} }
} }
ast::item_enum(ref def, _) => { ast::ItemEnum(ref def, _) => {
for v in def.variants.iter() { for v in def.variants.iter() {
match v.node.vis { match v.node.vis {
ast::public => { ast::Public => {
if item.vis == ast::public { if item.vis == ast::Public {
tcx.sess.span_err(v.span, "unnecessary `pub` \ tcx.sess.span_err(v.span, "unnecessary `pub` \
visibility"); visibility");
} }
} }
ast::private => { ast::Private => {
if item.vis != ast::public { if item.vis != ast::Public {
tcx.sess.span_err(v.span, "unnecessary `priv` \ tcx.sess.span_err(v.span, "unnecessary `priv` \
visibility"); visibility");
} }
} }
ast::inherited => {} ast::Inherited => {}
} }
match v.node.kind { match v.node.kind {
ast::struct_variant_kind(ref s) => check_struct(s), ast::StructVariantKind(ref s) => check_struct(s),
ast::tuple_variant_kind(..) => {} ast::TupleVariantKind(..) => {}
} }
} }
} }
ast::item_struct(ref def, _) => check_struct(def), ast::ItemStruct(ref def, _) => check_struct(def),
ast::item_trait(_, _, ref methods) => { ast::ItemTrait(_, _, ref methods) => {
for m in methods.iter() { for m in methods.iter() {
match *m { match *m {
ast::provided(ref m) => { ast::Provided(ref m) => {
check_inherited(m.span, m.vis, check_inherited(m.span, m.vis,
"unnecessary visibility"); "unnecessary visibility");
} }
ast::required(..) => {} ast::Required(..) => {}
} }
} }
} }
ast::item_static(..) | ast::ItemStatic(..) |
ast::item_fn(..) | ast::item_mod(..) | ast::item_ty(..) | ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) |
ast::item_mac(..) => { ast::ItemMac(..) => {
check_not_priv(item.span, item.vis, "items are private by \ check_not_priv(item.span, item.vis, "items are private by \
default"); default");
} }
@ -959,58 +958,58 @@ impl SanePrivacyVisitor {
/// When inside of something like a function or a method, visibility has no /// When inside of something like a function or a method, visibility has no
/// control over anything so this forbids any mention of any visibility /// control over anything so this forbids any mention of any visibility
fn check_all_inherited(&self, item: &ast::item) { fn check_all_inherited(&self, item: &ast::Item) {
let tcx = self.tcx; let tcx = self.tcx;
let check_inherited = |sp: Span, vis: ast::visibility| { let check_inherited = |sp: Span, vis: ast::Visibility| {
if vis != ast::inherited { if vis != ast::Inherited {
tcx.sess.span_err(sp, "visibility has no effect inside functions"); tcx.sess.span_err(sp, "visibility has no effect inside functions");
} }
}; };
let check_struct = |def: &@ast::struct_def| { let check_struct = |def: &@ast::StructDef| {
for f in def.fields.iter() { for f in def.fields.iter() {
match f.node.kind { match f.node.kind {
ast::named_field(_, p) => check_inherited(f.span, p), ast::NamedField(_, p) => check_inherited(f.span, p),
ast::unnamed_field => {} ast::UnnamedField => {}
} }
} }
}; };
check_inherited(item.span, item.vis); check_inherited(item.span, item.vis);
match item.node { match item.node {
ast::item_impl(_, _, _, ref methods) => { ast::ItemImpl(_, _, _, ref methods) => {
for m in methods.iter() { for m in methods.iter() {
check_inherited(m.span, m.vis); check_inherited(m.span, m.vis);
} }
} }
ast::item_foreign_mod(ref fm) => { ast::ItemForeignMod(ref fm) => {
for i in fm.items.iter() { for i in fm.items.iter() {
check_inherited(i.span, i.vis); check_inherited(i.span, i.vis);
} }
} }
ast::item_enum(ref def, _) => { ast::ItemEnum(ref def, _) => {
for v in def.variants.iter() { for v in def.variants.iter() {
check_inherited(v.span, v.node.vis); check_inherited(v.span, v.node.vis);
match v.node.kind { match v.node.kind {
ast::struct_variant_kind(ref s) => check_struct(s), ast::StructVariantKind(ref s) => check_struct(s),
ast::tuple_variant_kind(..) => {} ast::TupleVariantKind(..) => {}
} }
} }
} }
ast::item_struct(ref def, _) => check_struct(def), ast::ItemStruct(ref def, _) => check_struct(def),
ast::item_trait(_, _, ref methods) => { ast::ItemTrait(_, _, ref methods) => {
for m in methods.iter() { for m in methods.iter() {
match *m { match *m {
ast::required(..) => {} ast::Required(..) => {}
ast::provided(ref m) => check_inherited(m.span, m.vis), ast::Provided(ref m) => check_inherited(m.span, m.vis),
} }
} }
} }
ast::item_static(..) | ast::ItemStatic(..) |
ast::item_fn(..) | ast::item_mod(..) | ast::item_ty(..) | ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) |
ast::item_mac(..) => {} ast::ItemMac(..) => {}
} }
} }
} }

View file

@ -44,21 +44,21 @@ fn generics_require_inlining(generics: &ast::Generics) -> bool {
// Returns true if the given item must be inlined because it may be // Returns true if the given item must be inlined because it may be
// monomorphized or it was marked with `#[inline]`. This will only return // monomorphized or it was marked with `#[inline]`. This will only return
// true for functions. // true for functions.
fn item_might_be_inlined(item: &ast::item) -> bool { fn item_might_be_inlined(item: &ast::Item) -> bool {
if attributes_specify_inlining(item.attrs) { if attributes_specify_inlining(item.attrs) {
return true return true
} }
match item.node { match item.node {
ast::item_impl(ref generics, _, _, _) | ast::ItemImpl(ref generics, _, _, _) |
ast::item_fn(_, _, _, ref generics, _) => { ast::ItemFn(_, _, _, ref generics, _) => {
generics_require_inlining(generics) generics_require_inlining(generics)
} }
_ => false, _ => false,
} }
} }
fn method_might_be_inlined(tcx: ty::ctxt, method: &ast::method, fn method_might_be_inlined(tcx: ty::ctxt, method: &ast::Method,
impl_src: ast::DefId) -> bool { impl_src: ast::DefId) -> bool {
if attributes_specify_inlining(method.attrs) || if attributes_specify_inlining(method.attrs) ||
generics_require_inlining(&method.generics) { generics_require_inlining(&method.generics) {
@ -68,7 +68,7 @@ fn method_might_be_inlined(tcx: ty::ctxt, method: &ast::method,
{ {
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&impl_src.node) { match items.get().find(&impl_src.node) {
Some(&ast_map::node_item(item, _)) => { Some(&ast_map::NodeItem(item, _)) => {
item_might_be_inlined(item) item_might_be_inlined(item)
} }
Some(..) | None => { Some(..) | None => {
@ -187,7 +187,7 @@ impl Visitor<()> for MarkSymbolVisitor {
visit::walk_expr(self, expr, ()) visit::walk_expr(self, expr, ())
} }
fn visit_item(&mut self, _item: &ast::item, _: ()) { fn visit_item(&mut self, _item: &ast::Item, _: ()) {
// Do not recurse into items. These items will be added to the worklist // Do not recurse into items. These items will be added to the worklist
// and recursed into manually if necessary. // and recursed into manually if necessary.
} }
@ -215,19 +215,19 @@ impl ReachableContext {
let node_id = def_id.node; let node_id = def_id.node;
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&node_id) { match items.get().find(&node_id) {
Some(&ast_map::node_item(item, _)) => { Some(&ast_map::NodeItem(item, _)) => {
match item.node { match item.node {
ast::item_fn(..) => item_might_be_inlined(item), ast::ItemFn(..) => item_might_be_inlined(item),
_ => false, _ => false,
} }
} }
Some(&ast_map::node_trait_method(trait_method, _, _)) => { Some(&ast_map::NodeTraitMethod(trait_method, _, _)) => {
match *trait_method { match *trait_method {
ast::required(_) => false, ast::Required(_) => false,
ast::provided(_) => true, ast::Provided(_) => true,
} }
} }
Some(&ast_map::node_method(method, impl_did, _)) => { Some(&ast_map::NodeMethod(method, impl_did, _)) => {
if generics_require_inlining(&method.generics) || if generics_require_inlining(&method.generics) ||
attributes_specify_inlining(method.attrs) { attributes_specify_inlining(method.attrs) {
true true
@ -236,9 +236,9 @@ impl ReachableContext {
// impl require inlining, this method does too. // impl require inlining, this method does too.
assert!(impl_did.crate == ast::LOCAL_CRATE); assert!(impl_did.crate == ast::LOCAL_CRATE);
match items.get().find(&impl_did.node) { match items.get().find(&impl_did.node) {
Some(&ast_map::node_item(item, _)) => { Some(&ast_map::NodeItem(item, _)) => {
match item.node { match item.node {
ast::item_impl(ref generics, _, _, _) => { ast::ItemImpl(ref generics, _, _, _) => {
generics_require_inlining(generics) generics_require_inlining(generics)
} }
_ => false _ => false
@ -308,7 +308,7 @@ impl ReachableContext {
} }
} }
fn propagate_node(&self, node: &ast_map::ast_node, fn propagate_node(&self, node: &ast_map::Node,
search_item: ast::NodeId, search_item: ast::NodeId,
visitor: &mut MarkSymbolVisitor) { visitor: &mut MarkSymbolVisitor) {
if !self.tcx.sess.building_library.get() { if !self.tcx.sess.building_library.get() {
@ -318,9 +318,9 @@ impl ReachableContext {
// but all other rust-only interfaces can be private (they will not // but all other rust-only interfaces can be private (they will not
// participate in linkage after this product is produced) // participate in linkage after this product is produced)
match *node { match *node {
ast_map::node_item(item, _) => { ast_map::NodeItem(item, _) => {
match item.node { match item.node {
ast::item_fn(_, ast::extern_fn, _, _, _) => { ast::ItemFn(_, ast::ExternFn, _, _, _) => {
let mut reachable_symbols = let mut reachable_symbols =
self.reachable_symbols.borrow_mut(); self.reachable_symbols.borrow_mut();
reachable_symbols.get().insert(search_item); reachable_symbols.get().insert(search_item);
@ -340,9 +340,9 @@ impl ReachableContext {
} }
match *node { match *node {
ast_map::node_item(item, _) => { ast_map::NodeItem(item, _) => {
match item.node { match item.node {
ast::item_fn(_, _, _, _, search_block) => { ast::ItemFn(_, _, _, _, search_block) => {
if item_might_be_inlined(item) { if item_might_be_inlined(item) {
visit::walk_block(visitor, search_block, ()) visit::walk_block(visitor, search_block, ())
} }
@ -350,7 +350,7 @@ impl ReachableContext {
// Statics with insignificant addresses are not reachable // Statics with insignificant addresses are not reachable
// because they're inlined specially into all other crates. // because they're inlined specially into all other crates.
ast::item_static(..) => { ast::ItemStatic(..) => {
if attr::contains_name(item.attrs, if attr::contains_name(item.attrs,
"address_insignificant") { "address_insignificant") {
let mut reachable_symbols = let mut reachable_symbols =
@ -362,10 +362,10 @@ impl ReachableContext {
// These are normal, nothing reachable about these // These are normal, nothing reachable about these
// inherently and their children are already in the // inherently and their children are already in the
// worklist, as determined by the privacy pass // worklist, as determined by the privacy pass
ast::item_ty(..) | ast::ItemTy(..) |
ast::item_mod(..) | ast::item_foreign_mod(..) | ast::ItemMod(..) | ast::ItemForeignMod(..) |
ast::item_impl(..) | ast::item_trait(..) | ast::ItemImpl(..) | ast::ItemTrait(..) |
ast::item_struct(..) | ast::item_enum(..) => {} ast::ItemStruct(..) | ast::ItemEnum(..) => {}
_ => { _ => {
self.tcx.sess.span_bug(item.span, self.tcx.sess.span_bug(item.span,
@ -374,25 +374,25 @@ impl ReachableContext {
} }
} }
} }
ast_map::node_trait_method(trait_method, _, _) => { ast_map::NodeTraitMethod(trait_method, _, _) => {
match *trait_method { match *trait_method {
ast::required(..) => { ast::Required(..) => {
// Keep going, nothing to get exported // Keep going, nothing to get exported
} }
ast::provided(ref method) => { ast::Provided(ref method) => {
visit::walk_block(visitor, method.body, ()) visit::walk_block(visitor, method.body, ())
} }
} }
} }
ast_map::node_method(method, did, _) => { ast_map::NodeMethod(method, did, _) => {
if method_might_be_inlined(self.tcx, method, did) { if method_might_be_inlined(self.tcx, method, did) {
visit::walk_block(visitor, method.body, ()) visit::walk_block(visitor, method.body, ())
} }
} }
// Nothing to recurse on for these // Nothing to recurse on for these
ast_map::node_foreign_item(..) | ast_map::NodeForeignItem(..) |
ast_map::node_variant(..) | ast_map::NodeVariant(..) |
ast_map::node_struct_ctor(..) => {} ast_map::NodeStructCtor(..) => {}
_ => { _ => {
let ident_interner = token::get_ident_interner(); let ident_interner = token::get_ident_interner();
let desc = ast_map::node_id_to_str(self.tcx.items, let desc = ast_map::node_id_to_str(self.tcx.items,

View file

@ -29,8 +29,8 @@ use std::cell::RefCell;
use std::hashmap::{HashMap, HashSet}; use std::hashmap::{HashMap, HashSet};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::{ast, visit}; use syntax::{ast, visit};
use syntax::visit::{Visitor,fn_kind}; use syntax::visit::{Visitor, FnKind};
use syntax::ast::{Block,item,fn_decl,NodeId,Arm,Pat,Stmt,Expr,Local}; use syntax::ast::{Block, Item, FnDecl, NodeId, Arm, Pat, Stmt, Expr, Local};
/** /**
The region maps encode information about region relationships. The region maps encode information about region relationships.
@ -425,7 +425,7 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor,
} }
fn resolve_item(visitor: &mut RegionResolutionVisitor, fn resolve_item(visitor: &mut RegionResolutionVisitor,
item: &ast::item, item: &ast::Item,
cx: Context) { cx: Context) {
// Items create a new outer block scope as far as we're concerned. // Items create a new outer block scope as far as we're concerned.
let new_cx = Context {var_parent: None, parent: None, ..cx}; let new_cx = Context {var_parent: None, parent: None, ..cx};
@ -433,8 +433,8 @@ fn resolve_item(visitor: &mut RegionResolutionVisitor,
} }
fn resolve_fn(visitor: &mut RegionResolutionVisitor, fn resolve_fn(visitor: &mut RegionResolutionVisitor,
fk: &visit::fn_kind, fk: &FnKind,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
sp: Span, sp: Span,
id: ast::NodeId, id: ast::NodeId,
@ -453,7 +453,7 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
var_parent: Some(body.id), var_parent: Some(body.id),
..cx}; ..cx};
match *fk { match *fk {
visit::fk_method(_, _, method) => { visit::FkMethod(_, _, method) => {
visitor.region_maps.record_parent(method.self_id, body.id); visitor.region_maps.record_parent(method.self_id, body.id);
} }
_ => {} _ => {}
@ -463,13 +463,10 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
// The body of the fn itself is either a root scope (top-level fn) // The body of the fn itself is either a root scope (top-level fn)
// or it continues with the inherited scope (closures). // or it continues with the inherited scope (closures).
let body_cx = match *fk { let body_cx = match *fk {
visit::fk_item_fn(..) | visit::FkItemFn(..) | visit::FkMethod(..) => {
visit::fk_method(..) => {
Context {parent: None, var_parent: None, ..cx} Context {parent: None, var_parent: None, ..cx}
} }
visit::fk_fn_block(..) => { visit::FkFnBlock(..) => cx
cx
}
}; };
visitor.visit_block(body, body_cx); visitor.visit_block(body, body_cx);
} }
@ -480,11 +477,11 @@ impl Visitor<Context> for RegionResolutionVisitor {
resolve_block(self, b, cx); resolve_block(self, b, cx);
} }
fn visit_item(&mut self, i: &item, cx: Context) { fn visit_item(&mut self, i: &Item, cx: Context) {
resolve_item(self, i, cx); resolve_item(self, i, cx);
} }
fn visit_fn(&mut self, fk: &fn_kind, fd: &fn_decl, fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl,
b: &Block, s: Span, n: NodeId, cx: Context) { b: &Block, s: Span, n: NodeId, cx: Context) {
resolve_fn(self, fk, fd, b, s, n, cx); resolve_fn(self, fk, fd, b, s, n, cx);
} }

View file

@ -21,7 +21,7 @@ use syntax::ast;
use syntax::ast_util::{def_id_of_def, local_def, mtwt_resolve}; use syntax::ast_util::{def_id_of_def, local_def, mtwt_resolve};
use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method}; use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method};
use syntax::parse::token; use syntax::parse::token;
use syntax::parse::token::{ident_interner, interner_get}; use syntax::parse::token::{IdentInterner, interner_get};
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
use syntax::print::pprust::path_to_str; use syntax::print::pprust::path_to_str;
use syntax::codemap::{Span, DUMMY_SP, Pos}; use syntax::codemap::{Span, DUMMY_SP, Pos};
@ -133,11 +133,11 @@ enum NameDefinition {
enum SelfBinding { enum SelfBinding {
NoSelfBinding, NoSelfBinding,
HasSelfBinding(NodeId, explicit_self) HasSelfBinding(NodeId, ExplicitSelf)
} }
impl Visitor<()> for Resolver { impl Visitor<()> for Resolver {
fn visit_item(&mut self, item: &item, _: ()) { fn visit_item(&mut self, item: &Item, _: ()) {
self.resolve_item(item); self.resolve_item(item);
} }
fn visit_arm(&mut self, arm: &Arm, _: ()) { fn visit_arm(&mut self, arm: &Arm, _: ()) {
@ -735,13 +735,11 @@ fn NameBindings() -> NameBindings {
/// Interns the names of the primitive types. /// Interns the names of the primitive types.
struct PrimitiveTypeTable { struct PrimitiveTypeTable {
primitive_types: HashMap<Name,prim_ty>, primitive_types: HashMap<Name, PrimTy>,
} }
impl PrimitiveTypeTable { impl PrimitiveTypeTable {
fn intern(&mut self, fn intern(&mut self, string: &str, primitive_type: PrimTy) {
string: &str,
primitive_type: prim_ty) {
self.primitive_types.insert(token::intern(string), primitive_type); self.primitive_types.insert(token::intern(string), primitive_type);
} }
} }
@ -751,21 +749,21 @@ fn PrimitiveTypeTable() -> PrimitiveTypeTable {
primitive_types: HashMap::new() primitive_types: HashMap::new()
}; };
table.intern("bool", ty_bool); table.intern("bool", TyBool);
table.intern("char", ty_char); table.intern("char", TyChar);
table.intern("f32", ty_float(ty_f32)); table.intern("f32", TyFloat(TyF32));
table.intern("f64", ty_float(ty_f64)); table.intern("f64", TyFloat(TyF64));
table.intern("int", ty_int(ty_i)); table.intern("int", TyInt(TyI));
table.intern("i8", ty_int(ty_i8)); table.intern("i8", TyInt(TyI8));
table.intern("i16", ty_int(ty_i16)); table.intern("i16", TyInt(TyI16));
table.intern("i32", ty_int(ty_i32)); table.intern("i32", TyInt(TyI32));
table.intern("i64", ty_int(ty_i64)); table.intern("i64", TyInt(TyI64));
table.intern("str", ty_str); table.intern("str", TyStr);
table.intern("uint", ty_uint(ty_u)); table.intern("uint", TyUint(TyU));
table.intern("u8", ty_uint(ty_u8)); table.intern("u8", TyUint(TyU8));
table.intern("u16", ty_uint(ty_u16)); table.intern("u16", TyUint(TyU16));
table.intern("u32", ty_uint(ty_u32)); table.intern("u32", TyUint(TyU32));
table.intern("u64", ty_uint(ty_u64)); table.intern("u64", TyUint(TyU64));
return table; return table;
} }
@ -841,7 +839,7 @@ struct Resolver {
session: @Session, session: @Session,
lang_items: LanguageItems, lang_items: LanguageItems,
intr: @ident_interner, intr: @IdentInterner,
graph_root: @NameBindings, graph_root: @NameBindings,
@ -898,12 +896,12 @@ struct BuildReducedGraphVisitor<'a> {
impl<'a> Visitor<ReducedGraphParent> for BuildReducedGraphVisitor<'a> { impl<'a> Visitor<ReducedGraphParent> for BuildReducedGraphVisitor<'a> {
fn visit_item(&mut self, item: &item, context: ReducedGraphParent) { fn visit_item(&mut self, item: &Item, context: ReducedGraphParent) {
let p = self.resolver.build_reduced_graph_for_item(item, context); let p = self.resolver.build_reduced_graph_for_item(item, context);
visit::walk_item(self, item, p); visit::walk_item(self, item, p);
} }
fn visit_foreign_item(&mut self, foreign_item: &foreign_item, fn visit_foreign_item(&mut self, foreign_item: &ForeignItem,
context: ReducedGraphParent) { context: ReducedGraphParent) {
self.resolver.build_reduced_graph_for_foreign_item(foreign_item, self.resolver.build_reduced_graph_for_foreign_item(foreign_item,
context, context,
@ -913,7 +911,7 @@ impl<'a> Visitor<ReducedGraphParent> for BuildReducedGraphVisitor<'a> {
}) })
} }
fn visit_view_item(&mut self, view_item: &view_item, context: ReducedGraphParent) { fn visit_view_item(&mut self, view_item: &ViewItem, context: ReducedGraphParent) {
self.resolver.build_reduced_graph_for_view_item(view_item, context); self.resolver.build_reduced_graph_for_view_item(view_item, context);
} }
@ -927,7 +925,7 @@ impl<'a> Visitor<ReducedGraphParent> for BuildReducedGraphVisitor<'a> {
struct UnusedImportCheckVisitor<'a> { resolver: &'a Resolver } struct UnusedImportCheckVisitor<'a> { resolver: &'a Resolver }
impl<'a> Visitor<()> for UnusedImportCheckVisitor<'a> { impl<'a> Visitor<()> for UnusedImportCheckVisitor<'a> {
fn visit_view_item(&mut self, vi: &view_item, _: ()) { fn visit_view_item(&mut self, vi: &ViewItem, _: ()) {
self.resolver.check_for_item_unused_imports(vi); self.resolver.check_for_item_unused_imports(vi);
visit::walk_view_item(self, vi, ()); visit::walk_view_item(self, vi, ());
} }
@ -1141,16 +1139,16 @@ impl Resolver {
/// Constructs the reduced graph for one item. /// Constructs the reduced graph for one item.
fn build_reduced_graph_for_item(&mut self, fn build_reduced_graph_for_item(&mut self,
item: &item, item: &Item,
parent: ReducedGraphParent) parent: ReducedGraphParent)
-> ReducedGraphParent -> ReducedGraphParent
{ {
let ident = item.ident; let ident = item.ident;
let sp = item.span; let sp = item.span;
let is_public = item.vis == ast::public; let is_public = item.vis == ast::Public;
match item.node { match item.node {
item_mod(..) => { ItemMod(..) => {
let (name_bindings, new_parent) = let (name_bindings, new_parent) =
self.add_child(ident, parent, ForbidDuplicateModules, sp); self.add_child(ident, parent, ForbidDuplicateModules, sp);
@ -1160,16 +1158,16 @@ impl Resolver {
Some(def_id), Some(def_id),
NormalModuleKind, NormalModuleKind,
false, false,
item.vis == ast::public, item.vis == ast::Public,
sp); sp);
ModuleReducedGraphParent(name_bindings.get_module()) ModuleReducedGraphParent(name_bindings.get_module())
} }
item_foreign_mod(..) => parent, ItemForeignMod(..) => parent,
// These items live in the value namespace. // These items live in the value namespace.
item_static(_, m, _) => { ItemStatic(_, m, _) => {
let (name_bindings, _) = let (name_bindings, _) =
self.add_child(ident, parent, ForbidDuplicateValues, sp); self.add_child(ident, parent, ForbidDuplicateValues, sp);
let mutbl = m == ast::MutMutable; let mutbl = m == ast::MutMutable;
@ -1178,7 +1176,7 @@ impl Resolver {
(DefStatic(local_def(item.id), mutbl), sp, is_public); (DefStatic(local_def(item.id), mutbl), sp, is_public);
parent parent
} }
item_fn(_, purity, _, _, _) => { ItemFn(_, purity, _, _, _) => {
let (name_bindings, new_parent) = let (name_bindings, new_parent) =
self.add_child(ident, parent, ForbidDuplicateValues, sp); self.add_child(ident, parent, ForbidDuplicateValues, sp);
@ -1188,7 +1186,7 @@ impl Resolver {
} }
// These items live in the type namespace. // These items live in the type namespace.
item_ty(..) => { ItemTy(..) => {
let (name_bindings, _) = let (name_bindings, _) =
self.add_child(ident, parent, ForbidDuplicateTypes, sp); self.add_child(ident, parent, ForbidDuplicateTypes, sp);
@ -1197,7 +1195,7 @@ impl Resolver {
parent parent
} }
item_enum(ref enum_definition, _) => { ItemEnum(ref enum_definition, _) => {
let (name_bindings, new_parent) = let (name_bindings, new_parent) =
self.add_child(ident, parent, ForbidDuplicateTypes, sp); self.add_child(ident, parent, ForbidDuplicateTypes, sp);
@ -1215,7 +1213,7 @@ impl Resolver {
} }
// These items live in both the type and value namespaces. // These items live in both the type and value namespaces.
item_struct(struct_def, _) => { ItemStruct(struct_def, _) => {
// Adding to both Type and Value namespaces or just Type? // Adding to both Type and Value namespaces or just Type?
let (forbid, ctor_id) = match struct_def.ctor_id { let (forbid, ctor_id) = match struct_def.ctor_id {
Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)), Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
@ -1241,7 +1239,7 @@ impl Resolver {
new_parent new_parent
} }
item_impl(_, None, ty, ref methods) => { ItemImpl(_, None, ty, ref methods) => {
// If this implements an anonymous trait, then add all the // If this implements an anonymous trait, then add all the
// methods within to a new module, if the type was defined // methods within to a new module, if the type was defined
// within this module. // within this module.
@ -1252,7 +1250,7 @@ impl Resolver {
// Create the module and add all methods. // Create the module and add all methods.
match ty.node { match ty.node {
ty_path(ref path, _, _) if path.segments.len() == 1 => { TyPath(ref path, _, _) if path.segments.len() == 1 => {
let name = path_to_ident(path); let name = path_to_ident(path);
let existing_parent_opt = { let existing_parent_opt = {
@ -1305,7 +1303,7 @@ impl Resolver {
ForbidDuplicateValues, ForbidDuplicateValues,
method.span); method.span);
let def = match method.explicit_self.node { let def = match method.explicit_self.node {
sty_static => { SelfStatic => {
// Static methods become // Static methods become
// `def_static_method`s. // `def_static_method`s.
DefStaticMethod(local_def(method.id), DefStaticMethod(local_def(method.id),
@ -1320,7 +1318,7 @@ impl Resolver {
} }
}; };
let is_public = method.vis == ast::public; let is_public = method.vis == ast::Public;
method_name_bindings.define_value(def, method_name_bindings.define_value(def,
method.span, method.span,
is_public); is_public);
@ -1332,9 +1330,9 @@ impl Resolver {
parent parent
} }
item_impl(_, Some(_), _, _) => parent, ItemImpl(_, Some(_), _, _) => parent,
item_trait(_, _, ref methods) => { ItemTrait(_, _, ref methods) => {
let (name_bindings, new_parent) = let (name_bindings, new_parent) =
self.add_child(ident, parent, ForbidDuplicateTypes, sp); self.add_child(ident, parent, ForbidDuplicateTypes, sp);
@ -1344,7 +1342,7 @@ impl Resolver {
Some(local_def(item.id)), Some(local_def(item.id)),
TraitModuleKind, TraitModuleKind,
false, false,
item.vis == ast::public, item.vis == ast::Public,
sp); sp);
let module_parent = ModuleReducedGraphParent(name_bindings. let module_parent = ModuleReducedGraphParent(name_bindings.
get_module()); get_module());
@ -1358,7 +1356,7 @@ impl Resolver {
// Add it as a name in the trait module. // Add it as a name in the trait module.
let def = match ty_m.explicit_self.node { let def = match ty_m.explicit_self.node {
sty_static => { SelfStatic => {
// Static methods become `def_static_method`s. // Static methods become `def_static_method`s.
DefStaticMethod(local_def(ty_m.id), DefStaticMethod(local_def(ty_m.id),
FromTrait(local_def(item.id)), FromTrait(local_def(item.id)),
@ -1380,7 +1378,7 @@ impl Resolver {
// Add it to the trait info if not static. // Add it to the trait info if not static.
match ty_m.explicit_self.node { match ty_m.explicit_self.node {
sty_static => {} SelfStatic => {}
_ => { _ => {
method_names.insert(ident.name, ()); method_names.insert(ident.name, ());
} }
@ -1403,7 +1401,7 @@ impl Resolver {
new_parent new_parent
} }
item_mac(..) => { ItemMac(..) => {
fail!("item macros unimplemented") fail!("item macros unimplemented")
} }
} }
@ -1412,7 +1410,7 @@ impl Resolver {
// Constructs the reduced graph for one variant. Variants exist in the // Constructs the reduced graph for one variant. Variants exist in the
// type and/or value namespaces. // type and/or value namespaces.
fn build_reduced_graph_for_variant(&mut self, fn build_reduced_graph_for_variant(&mut self,
variant: &variant, variant: &Variant,
item_id: DefId, item_id: DefId,
parent: ReducedGraphParent, parent: ReducedGraphParent,
parent_public: bool) { parent_public: bool) {
@ -1420,17 +1418,17 @@ impl Resolver {
// XXX: this is unfortunate to have to do this privacy calculation // XXX: this is unfortunate to have to do this privacy calculation
// here. This should be living in middle::privacy, but it's // here. This should be living in middle::privacy, but it's
// necessary to keep around in some form becaues of glob imports... // necessary to keep around in some form becaues of glob imports...
let is_public = parent_public && variant.node.vis != ast::private; let is_public = parent_public && variant.node.vis != ast::Private;
match variant.node.kind { match variant.node.kind {
tuple_variant_kind(_) => { TupleVariantKind(_) => {
let (child, _) = self.add_child(ident, parent, ForbidDuplicateValues, let (child, _) = self.add_child(ident, parent, ForbidDuplicateValues,
variant.span); variant.span);
child.define_value(DefVariant(item_id, child.define_value(DefVariant(item_id,
local_def(variant.node.id), false), local_def(variant.node.id), false),
variant.span, is_public); variant.span, is_public);
} }
struct_variant_kind(_) => { StructVariantKind(_) => {
let (child, _) = self.add_child(ident, parent, ForbidDuplicateTypesAndValues, let (child, _) = self.add_child(ident, parent, ForbidDuplicateTypesAndValues,
variant.span); variant.span);
child.define_type(DefVariant(item_id, child.define_type(DefVariant(item_id,
@ -1443,11 +1441,10 @@ impl Resolver {
/// Constructs the reduced graph for one 'view item'. View items consist /// Constructs the reduced graph for one 'view item'. View items consist
/// of imports and use directives. /// of imports and use directives.
fn build_reduced_graph_for_view_item(&mut self, fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
view_item: &view_item, parent: ReducedGraphParent) {
parent: ReducedGraphParent) {
match view_item.node { match view_item.node {
view_item_use(ref view_paths) => { ViewItemUse(ref view_paths) => {
for view_path in view_paths.iter() { for view_path in view_paths.iter() {
// Extract and intern the module part of the path. For // Extract and intern the module part of the path. For
// globs and lists, the path is found directly in the AST; // globs and lists, the path is found directly in the AST;
@ -1455,7 +1452,7 @@ impl Resolver {
let mut module_path = ~[]; let mut module_path = ~[];
match view_path.node { match view_path.node {
view_path_simple(_, ref full_path, _) => { ViewPathSimple(_, ref full_path, _) => {
let path_len = full_path.segments.len(); let path_len = full_path.segments.len();
assert!(path_len != 0); assert!(path_len != 0);
@ -1468,8 +1465,8 @@ impl Resolver {
} }
} }
view_path_glob(ref module_ident_path, _) | ViewPathGlob(ref module_ident_path, _) |
view_path_list(ref module_ident_path, _, _) => { ViewPathList(ref module_ident_path, _, _) => {
for segment in module_ident_path.segments.iter() { for segment in module_ident_path.segments.iter() {
module_path.push(segment.identifier) module_path.push(segment.identifier)
} }
@ -1478,9 +1475,9 @@ impl Resolver {
// Build up the import directives. // Build up the import directives.
let module_ = self.get_module_from_parent(parent); let module_ = self.get_module_from_parent(parent);
let is_public = view_item.vis == ast::public; let is_public = view_item.vis == ast::Public;
match view_path.node { match view_path.node {
view_path_simple(binding, ref full_path, id) => { ViewPathSimple(binding, ref full_path, id) => {
let source_ident = let source_ident =
full_path.segments.last().identifier; full_path.segments.last().identifier;
let subclass = @SingleImport(binding, let subclass = @SingleImport(binding,
@ -1492,7 +1489,7 @@ impl Resolver {
id, id,
is_public); is_public);
} }
view_path_list(_, ref source_idents, _) => { ViewPathList(_, ref source_idents, _) => {
for source_ident in source_idents.iter() { for source_ident in source_idents.iter() {
let name = source_ident.node.name; let name = source_ident.node.name;
let subclass = @SingleImport(name, name); let subclass = @SingleImport(name, name);
@ -1505,7 +1502,7 @@ impl Resolver {
is_public); is_public);
} }
} }
view_path_glob(_, id) => { ViewPathGlob(_, id) => {
self.build_import_directive(module_, self.build_import_directive(module_,
module_path, module_path,
@GlobImport, @GlobImport,
@ -1517,7 +1514,7 @@ impl Resolver {
} }
} }
view_item_extern_mod(name, _, node_id) => { ViewItemExternMod(name, _, node_id) => {
// n.b. we don't need to look at the path option here, because cstore already did // n.b. we don't need to look at the path option here, because cstore already did
match self.session.cstore.find_extern_mod_stmt_cnum(node_id) { match self.session.cstore.find_extern_mod_stmt_cnum(node_id) {
Some(crate_id) => { Some(crate_id) => {
@ -1550,19 +1547,19 @@ impl Resolver {
/// Constructs the reduced graph for one foreign item. /// Constructs the reduced graph for one foreign item.
fn build_reduced_graph_for_foreign_item(&mut self, fn build_reduced_graph_for_foreign_item(&mut self,
foreign_item: &foreign_item, foreign_item: &ForeignItem,
parent: ReducedGraphParent, parent: ReducedGraphParent,
f: |&mut Resolver, f: |&mut Resolver,
ReducedGraphParent|) { ReducedGraphParent|) {
let name = foreign_item.ident; let name = foreign_item.ident;
let is_public = foreign_item.vis == ast::public; let is_public = foreign_item.vis == ast::Public;
let (name_bindings, new_parent) = let (name_bindings, new_parent) =
self.add_child(name, parent, ForbidDuplicateValues, self.add_child(name, parent, ForbidDuplicateValues,
foreign_item.span); foreign_item.span);
match foreign_item.node { match foreign_item.node {
foreign_item_fn(_, ref generics) => { ForeignItemFn(_, ref generics) => {
let def = DefFn(local_def(foreign_item.id), unsafe_fn); let def = DefFn(local_def(foreign_item.id), UnsafeFn);
name_bindings.define_value(def, foreign_item.span, is_public); name_bindings.define_value(def, foreign_item.span, is_public);
self.with_type_parameter_rib( self.with_type_parameter_rib(
@ -1572,7 +1569,7 @@ impl Resolver {
NormalRibKind), NormalRibKind),
|this| f(this, new_parent)); |this| f(this, new_parent));
} }
foreign_item_static(_, m) => { ForeignItemStatic(_, m) => {
let def = DefStatic(local_def(foreign_item.id), m); let def = DefStatic(local_def(foreign_item.id), m);
name_bindings.define_value(def, foreign_item.span, is_public); name_bindings.define_value(def, foreign_item.span, is_public);
@ -1613,7 +1610,7 @@ impl Resolver {
fn handle_external_def(&mut self, fn handle_external_def(&mut self,
def: Def, def: Def,
vis: visibility, vis: Visibility,
child_name_bindings: @NameBindings, child_name_bindings: @NameBindings,
final_ident: &str, final_ident: &str,
ident: Ident, ident: Ident,
@ -1621,7 +1618,7 @@ impl Resolver {
debug!("(building reduced graph for \ debug!("(building reduced graph for \
external crate) building external def, priv {:?}", external crate) building external def, priv {:?}",
vis); vis);
let is_public = vis == ast::public; let is_public = vis == ast::Public;
let is_exported = is_public && match new_parent { let is_exported = is_public && match new_parent {
ModuleReducedGraphParent(module) => { ModuleReducedGraphParent(module) => {
match module.def_id.get() { match module.def_id.get() {
@ -1669,7 +1666,7 @@ impl Resolver {
// We assume the parent is visible, or else we wouldn't have seen // We assume the parent is visible, or else we wouldn't have seen
// it. Also variants are public-by-default if the parent was also // it. Also variants are public-by-default if the parent was also
// public. // public.
let is_public = vis != ast::private; let is_public = vis != ast::Private;
if is_struct { if is_struct {
child_name_bindings.define_type(def, DUMMY_SP, is_public); child_name_bindings.define_type(def, DUMMY_SP, is_public);
self.structs.insert(variant_id); self.structs.insert(variant_id);
@ -1703,7 +1700,7 @@ impl Resolver {
self.session.str_of(method_name)); self.session.str_of(method_name));
// Add it to the trait info if not static. // Add it to the trait info if not static.
if explicit_self != sty_static { if explicit_self != SelfStatic {
interned_method_names.insert(method_name.name); interned_method_names.insert(method_name.name);
} }
if is_exported { if is_exported {
@ -1767,7 +1764,7 @@ impl Resolver {
root: @Module, root: @Module,
def_like: DefLike, def_like: DefLike,
ident: Ident, ident: Ident,
visibility: visibility) { visibility: Visibility) {
match def_like { match def_like {
DlDef(def) => { DlDef(def) => {
// Add the new child item, if necessary. // Add the new child item, if necessary.
@ -1881,7 +1878,7 @@ impl Resolver {
method_name_bindings.define_value( method_name_bindings.define_value(
def, DUMMY_SP, def, DUMMY_SP,
visibility == ast::public); visibility == ast::Public);
} }
} }
@ -3633,7 +3630,7 @@ impl Resolver {
visit::walk_crate(self, crate, ()); visit::walk_crate(self, crate, ());
} }
fn resolve_item(&mut self, item: &item) { fn resolve_item(&mut self, item: &Item) {
debug!("(resolving item) resolving {}", debug!("(resolving item) resolving {}",
self.session.str_of(item.ident)); self.session.str_of(item.ident));
@ -3641,7 +3638,7 @@ impl Resolver {
// enum item: resolve all the variants' discrs, // enum item: resolve all the variants' discrs,
// then resolve the ty params // then resolve the ty params
item_enum(ref enum_def, ref generics) => { ItemEnum(ref enum_def, ref generics) => {
for variant in (*enum_def).variants.iter() { for variant in (*enum_def).variants.iter() {
for dis_expr in variant.node.disr_expr.iter() { for dis_expr in variant.node.disr_expr.iter() {
// resolve the discriminator expr // resolve the discriminator expr
@ -3664,7 +3661,7 @@ impl Resolver {
}); });
} }
item_ty(_, ref generics) => { ItemTy(_, ref generics) => {
self.with_type_parameter_rib(HasTypeParameters(generics, self.with_type_parameter_rib(HasTypeParameters(generics,
item.id, item.id,
0, 0,
@ -3674,7 +3671,7 @@ impl Resolver {
}); });
} }
item_impl(ref generics, ItemImpl(ref generics,
ref implemented_traits, ref implemented_traits,
self_type, self_type,
ref methods) => { ref methods) => {
@ -3685,7 +3682,7 @@ impl Resolver {
*methods); *methods);
} }
item_trait(ref generics, ref traits, ref methods) => { ItemTrait(ref generics, ref traits, ref methods) => {
// Create a new rib for the self type. // Create a new rib for the self type.
let self_type_rib = @Rib::new(NormalRibKind); let self_type_rib = @Rib::new(NormalRibKind);
{ {
@ -3719,7 +3716,7 @@ impl Resolver {
// FIXME #4951: Do we need a node ID here? // FIXME #4951: Do we need a node ID here?
match *method { match *method {
required(ref ty_m) => { ast::Required(ref ty_m) => {
this.with_type_parameter_rib this.with_type_parameter_rib
(HasTypeParameters(&ty_m.generics, (HasTypeParameters(&ty_m.generics,
item.id, item.id,
@ -3739,7 +3736,7 @@ impl Resolver {
this.resolve_type(ty_m.decl.output); this.resolve_type(ty_m.decl.output);
}); });
} }
provided(m) => { ast::Provided(m) => {
this.resolve_method(MethodRibKind(item.id, this.resolve_method(MethodRibKind(item.id,
Provided(m.id)), Provided(m.id)),
m, m,
@ -3753,24 +3750,24 @@ impl Resolver {
type_ribs.get().pop(); type_ribs.get().pop();
} }
item_struct(ref struct_def, ref generics) => { ItemStruct(ref struct_def, ref generics) => {
self.resolve_struct(item.id, self.resolve_struct(item.id,
generics, generics,
struct_def.fields); struct_def.fields);
} }
item_mod(ref module_) => { ItemMod(ref module_) => {
self.with_scope(Some(item.ident), |this| { self.with_scope(Some(item.ident), |this| {
this.resolve_module(module_, item.span, item.ident, this.resolve_module(module_, item.span, item.ident,
item.id); item.id);
}); });
} }
item_foreign_mod(ref foreign_module) => { ItemForeignMod(ref foreign_module) => {
self.with_scope(Some(item.ident), |this| { self.with_scope(Some(item.ident), |this| {
for foreign_item in foreign_module.items.iter() { for foreign_item in foreign_module.items.iter() {
match foreign_item.node { match foreign_item.node {
foreign_item_fn(_, ref generics) => { ForeignItemFn(_, ref generics) => {
this.with_type_parameter_rib( this.with_type_parameter_rib(
HasTypeParameters( HasTypeParameters(
generics, foreign_item.id, 0, generics, foreign_item.id, 0,
@ -3779,7 +3776,7 @@ impl Resolver {
*foreign_item, *foreign_item,
())); ()));
} }
foreign_item_static(..) => { ForeignItemStatic(..) => {
visit::walk_foreign_item(this, visit::walk_foreign_item(this,
*foreign_item, *foreign_item,
()); ());
@ -3789,7 +3786,7 @@ impl Resolver {
}); });
} }
item_fn(fn_decl, _, _, ref generics, block) => { ItemFn(fn_decl, _, _, ref generics, block) => {
self.resolve_function(OpaqueFunctionRibKind, self.resolve_function(OpaqueFunctionRibKind,
Some(fn_decl), Some(fn_decl),
HasTypeParameters HasTypeParameters
@ -3801,15 +3798,15 @@ impl Resolver {
NoSelfBinding); NoSelfBinding);
} }
item_static(..) => { ItemStatic(..) => {
self.with_constant_rib(|this| { self.with_constant_rib(|this| {
visit::walk_item(this, item, ()); visit::walk_item(this, item, ());
}); });
} }
item_mac(..) => { ItemMac(..) => {
fail!("item macros unimplemented") fail!("item macros unimplemented")
} }
} }
} }
@ -3895,7 +3892,7 @@ impl Resolver {
fn resolve_function(&mut self, fn resolve_function(&mut self,
rib_kind: RibKind, rib_kind: RibKind,
optional_declaration: Option<P<fn_decl>>, optional_declaration: Option<P<FnDecl>>,
type_parameters: TypeParameters, type_parameters: TypeParameters,
block: P<Block>, block: P<Block>,
self_binding: SelfBinding) { self_binding: SelfBinding) {
@ -3932,7 +3929,7 @@ impl Resolver {
} }
HasSelfBinding(self_node_id, explicit_self) => { HasSelfBinding(self_node_id, explicit_self) => {
let mutable = match explicit_self.node { let mutable = match explicit_self.node {
sty_uniq(m) | sty_value(m) if m == MutMutable => true, SelfUniq(m) | SelfValue(m) if m == MutMutable => true,
_ => false _ => false
}; };
let def_like = DlDef(DefSelf(self_node_id, mutable)); let def_like = DlDef(DefSelf(self_node_id, mutable));
@ -3996,7 +3993,7 @@ impl Resolver {
fn resolve_trait_reference(&mut self, fn resolve_trait_reference(&mut self,
id: NodeId, id: NodeId,
trait_reference: &trait_ref, trait_reference: &TraitRef,
reference_type: TraitReferenceType) { reference_type: TraitReferenceType) {
match self.resolve_path(id, &trait_reference.path, TypeNS, true) { match self.resolve_path(id, &trait_reference.path, TypeNS, true) {
None => { None => {
@ -4020,11 +4017,11 @@ impl Resolver {
fn resolve_struct(&mut self, fn resolve_struct(&mut self,
id: NodeId, id: NodeId,
generics: &Generics, generics: &Generics,
fields: &[struct_field]) { fields: &[StructField]) {
let mut ident_map: HashMap<ast::Ident, &struct_field> = HashMap::new(); let mut ident_map: HashMap<ast::Ident, &StructField> = HashMap::new();
for field in fields.iter() { for field in fields.iter() {
match field.node.kind { match field.node.kind {
named_field(ident, _) => { NamedField(ident, _) => {
match ident_map.find(&ident) { match ident_map.find(&ident) {
Some(&prev_field) => { Some(&prev_field) => {
let ident_str = self.session.str_of(ident); let ident_str = self.session.str_of(ident);
@ -4062,7 +4059,7 @@ impl Resolver {
// to be NormalRibKind? // to be NormalRibKind?
fn resolve_method(&mut self, fn resolve_method(&mut self,
rib_kind: RibKind, rib_kind: RibKind,
method: @method, method: @Method,
outer_type_parameter_count: uint) { outer_type_parameter_count: uint) {
let method_generics = &method.generics; let method_generics = &method.generics;
let type_parameters = let type_parameters =
@ -4072,8 +4069,8 @@ impl Resolver {
rib_kind); rib_kind);
// we only have self ty if it is a non static method // we only have self ty if it is a non static method
let self_binding = match method.explicit_self.node { let self_binding = match method.explicit_self.node {
sty_static => { NoSelfBinding } SelfStatic => NoSelfBinding,
_ => { HasSelfBinding(method.self_id, method.explicit_self) } _ => HasSelfBinding(method.self_id, method.explicit_self)
}; };
self.resolve_function(rib_kind, self.resolve_function(rib_kind,
@ -4086,9 +4083,9 @@ impl Resolver {
fn resolve_implementation(&mut self, fn resolve_implementation(&mut self,
id: NodeId, id: NodeId,
generics: &Generics, generics: &Generics,
opt_trait_reference: &Option<trait_ref>, opt_trait_reference: &Option<TraitRef>,
self_type: &Ty, self_type: &Ty,
methods: &[@method]) { methods: &[@Method]) {
// If applicable, create a rib for the type parameters. // If applicable, create a rib for the type parameters.
let outer_type_parameter_count = generics.ty_params.len(); let outer_type_parameter_count = generics.ty_params.len();
self.with_type_parameter_rib(HasTypeParameters(generics, self.with_type_parameter_rib(HasTypeParameters(generics,
@ -4160,14 +4157,11 @@ impl Resolver {
}); });
} }
fn resolve_module(&mut self, fn resolve_module(&mut self, module: &Mod, _span: Span,
module_: &_mod, _name: Ident, id: NodeId) {
_span: Span,
_name: Ident,
id: NodeId) {
// Write the implementations in scope into the module metadata. // Write the implementations in scope into the module metadata.
debug!("(resolving module) resolving module ID {}", id); debug!("(resolving module) resolving module ID {}", id);
visit::walk_mod(self, module_, ()); visit::walk_mod(self, module, ());
} }
fn resolve_local(&mut self, local: &Local) { fn resolve_local(&mut self, local: &Local) {
@ -4305,7 +4299,7 @@ impl Resolver {
// Like path expressions, the interpretation of path types depends // Like path expressions, the interpretation of path types depends
// on whether the path has multiple elements in it or not. // on whether the path has multiple elements in it or not.
ty_path(ref path, ref bounds, path_id) => { TyPath(ref path, ref bounds, path_id) => {
// This is a path in the type namespace. Walk through scopes // This is a path in the type namespace. Walk through scopes
// scopes looking for it. // scopes looking for it.
let mut result_def = None; let mut result_def = None;
@ -4387,7 +4381,7 @@ impl Resolver {
}); });
} }
ty_closure(c) => { TyClosure(c) => {
c.bounds.as_ref().map(|bounds| { c.bounds.as_ref().map(|bounds| {
for bound in bounds.iter() { for bound in bounds.iter() {
self.resolve_type_parameter_bound(ty.id, bound); self.resolve_type_parameter_bound(ty.id, bound);
@ -5548,20 +5542,20 @@ impl Resolver {
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, crate, ());
} }
fn check_for_item_unused_imports(&self, vi: &view_item) { fn check_for_item_unused_imports(&self, vi: &ViewItem) {
// Ignore is_public import statements because there's no way to be sure // Ignore is_public import statements because there's no way to be sure
// whether they're used or not. Also ignore imports with a dummy span // whether they're used or not. Also ignore imports with a dummy span
// because this means that they were generated in some fashion by the // because this means that they were generated in some fashion by the
// compiler and we don't need to consider them. // compiler and we don't need to consider them.
if vi.vis == public { return } if vi.vis == Public { return }
if vi.span == DUMMY_SP { return } if vi.span == DUMMY_SP { return }
match vi.node { match vi.node {
view_item_extern_mod(..) => {} // ignore ViewItemExternMod(..) => {} // ignore
view_item_use(ref path) => { ViewItemUse(ref path) => {
for p in path.iter() { for p in path.iter() {
match p.node { match p.node {
view_path_simple(_, _, id) | view_path_glob(_, id) => { ViewPathSimple(_, _, id) | ViewPathGlob(_, id) => {
if !self.used_imports.contains(&id) { if !self.used_imports.contains(&id) {
self.session.add_lint(unused_imports, self.session.add_lint(unused_imports,
id, p.span, id, p.span,
@ -5569,7 +5563,7 @@ impl Resolver {
} }
} }
view_path_list(_, ref list, _) => { ViewPathList(_, ref list, _) => {
for i in list.iter() { for i in list.iter() {
if !self.used_imports.contains(&i.node.id) { if !self.used_imports.contains(&i.node.id) {
self.session.add_lint(unused_imports, self.session.add_lint(unused_imports,

View file

@ -57,21 +57,21 @@ pub fn crate(sess: session::Session, crate: &ast::Crate)
impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext { impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
fn visit_item(&mut self, fn visit_item(&mut self,
item: &ast::item, item: &ast::Item,
_: &'a ScopeChain<'a>) { _: &'a ScopeChain<'a>) {
let scope = match item.node { let scope = match item.node {
ast::item_fn(..) | // fn lifetimes get added in visit_fn below ast::ItemFn(..) | // fn lifetimes get added in visit_fn below
ast::item_mod(..) | ast::ItemMod(..) |
ast::item_mac(..) | ast::ItemMac(..) |
ast::item_foreign_mod(..) | ast::ItemForeignMod(..) |
ast::item_static(..) => { ast::ItemStatic(..) => {
RootScope RootScope
} }
ast::item_ty(_, ref generics) | ast::ItemTy(_, ref generics) |
ast::item_enum(_, ref generics) | ast::ItemEnum(_, ref generics) |
ast::item_struct(_, ref generics) | ast::ItemStruct(_, ref generics) |
ast::item_impl(ref generics, _, _, _) | ast::ItemImpl(ref generics, _, _, _) |
ast::item_trait(ref generics, _, _) => { ast::ItemTrait(ref generics, _, _) => {
self.check_lifetime_names(&generics.lifetimes); self.check_lifetime_names(&generics.lifetimes);
ItemScope(&generics.lifetimes) ItemScope(&generics.lifetimes)
} }
@ -81,34 +81,29 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
debug!("exiting scope {:?}", scope); debug!("exiting scope {:?}", scope);
} }
fn visit_fn(&mut self, fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
fk: &visit::fn_kind, b: &ast::Block, s: Span, n: ast::NodeId,
fd: &ast::fn_decl,
b: &ast::Block,
s: Span,
n: ast::NodeId,
scope: &'a ScopeChain<'a>) { scope: &'a ScopeChain<'a>) {
match *fk { match *fk {
visit::fk_item_fn(_, generics, _, _) | visit::FkItemFn(_, generics, _, _) |
visit::fk_method(_, generics, _) => { visit::FkMethod(_, generics, _) => {
let scope1 = FnScope(n, &generics.lifetimes, scope); let scope1 = FnScope(n, &generics.lifetimes, scope);
self.check_lifetime_names(&generics.lifetimes); self.check_lifetime_names(&generics.lifetimes);
debug!("pushing fn scope id={} due to item/method", n); debug!("pushing fn scope id={} due to item/method", n);
visit::walk_fn(self, fk, fd, b, s, n, &scope1); visit::walk_fn(self, fk, fd, b, s, n, &scope1);
debug!("popping fn scope id={} due to item/method", n); debug!("popping fn scope id={} due to item/method", n);
} }
visit::fk_fn_block(..) => { visit::FkFnBlock(..) => {
visit::walk_fn(self, fk, fd, b, s, n, scope); visit::walk_fn(self, fk, fd, b, s, n, scope);
} }
} }
} }
fn visit_ty(&mut self, fn visit_ty(&mut self, ty: &ast::Ty,
ty: &ast::Ty,
scope: &'a ScopeChain<'a>) { scope: &'a ScopeChain<'a>) {
match ty.node { match ty.node {
ast::ty_closure(@ast::TyClosure { lifetimes: ref lifetimes, .. }) | ast::TyClosure(@ast::ClosureTy { lifetimes: ref lifetimes, .. }) |
ast::ty_bare_fn(@ast::TyBareFn { lifetimes: ref lifetimes, .. }) => { ast::TyBareFn(@ast::BareFnTy { lifetimes: ref lifetimes, .. }) => {
let scope1 = FnScope(ty.id, lifetimes, scope); let scope1 = FnScope(ty.id, lifetimes, scope);
self.check_lifetime_names(lifetimes); self.check_lifetime_names(lifetimes);
debug!("pushing fn scope id={} due to type", ty.id); debug!("pushing fn scope id={} due to type", ty.id);

View file

@ -303,11 +303,11 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
debug!("range_to_inttype: {:?} {:?}", hint, bounds); debug!("range_to_inttype: {:?} {:?}", hint, bounds);
// Lists of sizes to try. u64 is always allowed as a fallback. // Lists of sizes to try. u64 is always allowed as a fallback.
static choose_shortest: &'static[IntType] = &[ static choose_shortest: &'static[IntType] = &[
attr::UnsignedInt(ast::ty_u8), attr::SignedInt(ast::ty_i8), attr::UnsignedInt(ast::TyU8), attr::SignedInt(ast::TyI8),
attr::UnsignedInt(ast::ty_u16), attr::SignedInt(ast::ty_i16), attr::UnsignedInt(ast::TyU16), attr::SignedInt(ast::TyI16),
attr::UnsignedInt(ast::ty_u32), attr::SignedInt(ast::ty_i32)]; attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)];
static at_least_32: &'static[IntType] = &[ static at_least_32: &'static[IntType] = &[
attr::UnsignedInt(ast::ty_u32), attr::SignedInt(ast::ty_i32)]; attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)];
let attempts; let attempts;
match hint { match hint {
@ -336,7 +336,7 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
return ity; return ity;
} }
} }
return attr::UnsignedInt(ast::ty_u64); return attr::UnsignedInt(ast::TyU64);
} }
pub fn ll_inttype(cx: &CrateContext, ity: IntType) -> Type { pub fn ll_inttype(cx: &CrateContext, ity: IntType) -> Type {

View file

@ -27,7 +27,7 @@ use middle::trans::type_::Type;
use syntax::ast; use syntax::ast;
// Take an inline assembly expression and splat it out via LLVM // Take an inline assembly expression and splat it out via LLVM
pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::inline_asm) pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm)
-> &'a Block<'a> { -> &'a Block<'a> {
let mut bcx = bcx; let mut bcx = bcx;
let mut constraints = ~[]; let mut constraints = ~[];
@ -98,8 +98,8 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::inline_asm)
}; };
let dialect = match ia.dialect { let dialect = match ia.dialect {
ast::asm_att => lib::llvm::AD_ATT, ast::AsmAtt => lib::llvm::AD_ATT,
ast::asm_intel => lib::llvm::AD_Intel ast::AsmIntel => lib::llvm::AD_Intel
}; };
let r = ia.asm.with_c_str(|a| { let r = ia.asm.with_c_str(|a| {

View file

@ -77,7 +77,7 @@ use std::libc::c_uint;
use std::vec; use std::vec;
use std::local_data; use std::local_data;
use syntax::ast::Name; use syntax::ast::Name;
use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name}; use syntax::ast_map::{PathName, PathPrettyName, path_elem_to_str};
use syntax::ast_util::{local_def, is_local}; use syntax::ast_util::{local_def, is_local};
use syntax::attr; use syntax::attr;
use syntax::codemap::Span; use syntax::codemap::Span;
@ -1745,7 +1745,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
// Be warned! You must call `init_function` before doing anything with the // Be warned! You must call `init_function` before doing anything with the
// returned function context. // returned function context.
pub fn new_fn_ctxt_w_id(ccx: @CrateContext, pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
path: path, path: ast_map::Path,
llfndecl: ValueRef, llfndecl: ValueRef,
id: ast::NodeId, id: ast::NodeId,
output_type: ty::t, output_type: ty::t,
@ -1841,7 +1841,7 @@ pub fn init_function<'a>(
} }
pub fn new_fn_ctxt(ccx: @CrateContext, pub fn new_fn_ctxt(ccx: @CrateContext,
path: path, path: ast_map::Path,
llfndecl: ValueRef, llfndecl: ValueRef,
output_type: ty::t, output_type: ty::t,
sp: Option<Span>) sp: Option<Span>)
@ -1867,7 +1867,7 @@ pub fn new_fn_ctxt(ccx: @CrateContext,
// field of the fn_ctxt with // field of the fn_ctxt with
pub fn create_llargs_for_fn_args(cx: &FunctionContext, pub fn create_llargs_for_fn_args(cx: &FunctionContext,
self_arg: self_arg, self_arg: self_arg,
args: &[ast::arg]) args: &[ast::Arg])
-> ~[ValueRef] { -> ~[ValueRef] {
let _icx = push_ctxt("create_llargs_for_fn_args"); let _icx = push_ctxt("create_llargs_for_fn_args");
@ -1892,7 +1892,7 @@ pub fn create_llargs_for_fn_args(cx: &FunctionContext,
pub fn copy_args_to_allocas<'a>( pub fn copy_args_to_allocas<'a>(
fcx: &FunctionContext<'a>, fcx: &FunctionContext<'a>,
bcx: &'a Block<'a>, bcx: &'a Block<'a>,
args: &[ast::arg], args: &[ast::Arg],
raw_llargs: &[ValueRef], raw_llargs: &[ValueRef],
arg_tys: &[ty::t]) arg_tys: &[ty::t])
-> &'a Block<'a> { -> &'a Block<'a> {
@ -2007,8 +2007,8 @@ pub enum self_arg { impl_self(ty::t, ty::SelfMode), no_self, }
// If the function closes over its environment a closure will be // If the function closes over its environment a closure will be
// returned. // returned.
pub fn trans_closure(ccx: @CrateContext, pub fn trans_closure(ccx: @CrateContext,
path: path, path: ast_map::Path,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
llfndecl: ValueRef, llfndecl: ValueRef,
self_arg: self_arg, self_arg: self_arg,
@ -2085,8 +2085,8 @@ pub fn trans_closure(ccx: @CrateContext,
// trans_fn: creates an LLVM function corresponding to a source language // trans_fn: creates an LLVM function corresponding to a source language
// function. // function.
pub fn trans_fn(ccx: @CrateContext, pub fn trans_fn(ccx: @CrateContext,
path: path, path: ast_map::Path,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
llfndecl: ValueRef, llfndecl: ValueRef,
self_arg: self_arg, self_arg: self_arg,
@ -2115,7 +2115,7 @@ pub fn trans_fn(ccx: @CrateContext,
} }
fn insert_synthetic_type_entries(bcx: &Block, fn insert_synthetic_type_entries(bcx: &Block,
fn_args: &[ast::arg], fn_args: &[ast::Arg],
arg_tys: &[ty::t]) { arg_tys: &[ty::t]) {
/*! /*!
* For tuple-like structs and enum-variants, we generate * For tuple-like structs and enum-variants, we generate
@ -2144,8 +2144,8 @@ fn insert_synthetic_type_entries(bcx: &Block,
pub fn trans_enum_variant(ccx: @CrateContext, pub fn trans_enum_variant(ccx: @CrateContext,
_enum_id: ast::NodeId, _enum_id: ast::NodeId,
variant: &ast::variant, variant: &ast::Variant,
args: &[ast::variant_arg], args: &[ast::VariantArg],
disr: ty::Disr, disr: ty::Disr,
param_substs: Option<@param_substs>, param_substs: Option<@param_substs>,
llfndecl: ValueRef) { llfndecl: ValueRef) {
@ -2161,7 +2161,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
} }
pub fn trans_tuple_struct(ccx: @CrateContext, pub fn trans_tuple_struct(ccx: @CrateContext,
fields: &[ast::struct_field], fields: &[ast::StructField],
ctor_id: ast::NodeId, ctor_id: ast::NodeId,
param_substs: Option<@param_substs>, param_substs: Option<@param_substs>,
llfndecl: ValueRef) { llfndecl: ValueRef) {
@ -2181,12 +2181,12 @@ trait IdAndTy {
fn ty(&self) -> ast::P<ast::Ty>; fn ty(&self) -> ast::P<ast::Ty>;
} }
impl IdAndTy for ast::variant_arg { impl IdAndTy for ast::VariantArg {
fn id(&self) -> ast::NodeId { self.id } fn id(&self) -> ast::NodeId { self.id }
fn ty(&self) -> ast::P<ast::Ty> { self.ty } fn ty(&self) -> ast::P<ast::Ty> { self.ty }
} }
impl IdAndTy for ast::struct_field { impl IdAndTy for ast::StructField {
fn id(&self) -> ast::NodeId { self.node.id } fn id(&self) -> ast::NodeId { self.node.id }
fn ty(&self) -> ast::P<ast::Ty> { self.node.ty } fn ty(&self) -> ast::P<ast::Ty> { self.node.ty }
} }
@ -2201,7 +2201,7 @@ pub fn trans_enum_variant_or_tuple_like_struct<A:IdAndTy>(
{ {
// Translate variant arguments to function arguments. // Translate variant arguments to function arguments.
let fn_args = args.map(|varg| { let fn_args = args.map(|varg| {
ast::arg { ast::Arg {
ty: varg.ty(), ty: varg.ty(),
pat: ast_util::ident_to_pat( pat: ast_util::ident_to_pat(
ccx.tcx.sess.next_node_id(), ccx.tcx.sess.next_node_id(),
@ -2272,7 +2272,7 @@ pub fn trans_enum_variant_or_tuple_like_struct<A:IdAndTy>(
finish_fn(&fcx, bcx); finish_fn(&fcx, bcx);
} }
pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def, pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::EnumDef,
id: ast::NodeId, vi: @~[@ty::VariantInfo], id: ast::NodeId, vi: @~[@ty::VariantInfo],
i: &mut uint) { i: &mut uint) {
for &variant in enum_definition.variants.iter() { for &variant in enum_definition.variants.iter() {
@ -2280,15 +2280,15 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def,
*i += 1; *i += 1;
match variant.node.kind { match variant.node.kind {
ast::tuple_variant_kind(ref args) if args.len() > 0 => { ast::TupleVariantKind(ref args) if args.len() > 0 => {
let llfn = get_item_val(ccx, variant.node.id); let llfn = get_item_val(ccx, variant.node.id);
trans_enum_variant(ccx, id, variant, *args, trans_enum_variant(ccx, id, variant, *args,
disr_val, None, llfn); disr_val, None, llfn);
} }
ast::tuple_variant_kind(_) => { ast::TupleVariantKind(_) => {
// Nothing to do. // Nothing to do.
} }
ast::struct_variant_kind(struct_def) => { ast::StructVariantKind(struct_def) => {
trans_struct_def(ccx, struct_def); trans_struct_def(ccx, struct_def);
} }
} }
@ -2300,29 +2300,28 @@ pub struct TransItemVisitor {
} }
impl Visitor<()> for TransItemVisitor { impl Visitor<()> for TransItemVisitor {
fn visit_item(&mut self, i: &ast::item, _:()) { fn visit_item(&mut self, i: &ast::Item, _:()) {
trans_item(self.ccx, i); trans_item(self.ccx, i);
} }
} }
pub fn trans_item(ccx: @CrateContext, item: &ast::item) { pub fn trans_item(ccx: @CrateContext, item: &ast::Item) {
let _icx = push_ctxt("trans_item"); let _icx = push_ctxt("trans_item");
let path = { let path = {
let items = ccx.tcx.items.borrow(); let items = ccx.tcx.items.borrow();
match items.get().get_copy(&item.id) { match items.get().get_copy(&item.id) {
ast_map::node_item(_, p) => p, ast_map::NodeItem(_, p) => p,
// tjc: ? // tjc: ?
_ => fail!("trans_item"), _ => fail!("trans_item"),
} }
}; };
match item.node { match item.node {
ast::item_fn(decl, purity, _abis, ref generics, body) => { ast::ItemFn(decl, purity, _abis, ref generics, body) => {
if purity == ast::extern_fn { if purity == ast::ExternFn {
let llfndecl = get_item_val(ccx, item.id); let llfndecl = get_item_val(ccx, item.id);
foreign::trans_rust_fn_with_foreign_abi( foreign::trans_rust_fn_with_foreign_abi(
ccx, ccx,
&vec::append((*path).clone(), &vec::append_one((*path).clone(), PathName(item.ident)),
[path_name(item.ident)]),
decl, decl,
body, body,
item.attrs, item.attrs,
@ -2331,7 +2330,7 @@ pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
} else if !generics.is_type_parameterized() { } else if !generics.is_type_parameterized() {
let llfndecl = get_item_val(ccx, item.id); let llfndecl = get_item_val(ccx, item.id);
trans_fn(ccx, trans_fn(ccx,
vec::append((*path).clone(), [path_name(item.ident)]), vec::append_one((*path).clone(), PathName(item.ident)),
decl, decl,
body, body,
llfndecl, llfndecl,
@ -2346,7 +2345,7 @@ pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
v.visit_block(body, ()); v.visit_block(body, ());
} }
} }
ast::item_impl(ref generics, _, _, ref ms) => { ast::ItemImpl(ref generics, _, _, ref ms) => {
meth::trans_impl(ccx, meth::trans_impl(ccx,
(*path).clone(), (*path).clone(),
item.ident, item.ident,
@ -2354,17 +2353,17 @@ pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
generics, generics,
item.id); item.id);
} }
ast::item_mod(ref m) => { ast::ItemMod(ref m) => {
trans_mod(ccx, m); trans_mod(ccx, m);
} }
ast::item_enum(ref enum_definition, ref generics) => { ast::ItemEnum(ref enum_definition, ref generics) => {
if !generics.is_type_parameterized() { if !generics.is_type_parameterized() {
let vi = ty::enum_variants(ccx.tcx, local_def(item.id)); let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
let mut i = 0; let mut i = 0;
trans_enum_def(ccx, enum_definition, item.id, vi, &mut i); trans_enum_def(ccx, enum_definition, item.id, vi, &mut i);
} }
} }
ast::item_static(_, m, expr) => { ast::ItemStatic(_, m, expr) => {
consts::trans_const(ccx, m, item.id); consts::trans_const(ccx, m, item.id);
// Do static_assert checking. It can't really be done much earlier // Do static_assert checking. It can't really be done much earlier
// because we need to get the value of the bool out of LLVM // because we need to get the value of the bool out of LLVM
@ -2384,15 +2383,15 @@ pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
} }
} }
}, },
ast::item_foreign_mod(ref foreign_mod) => { ast::ItemForeignMod(ref foreign_mod) => {
foreign::trans_foreign_mod(ccx, foreign_mod); foreign::trans_foreign_mod(ccx, foreign_mod);
} }
ast::item_struct(struct_def, ref generics) => { ast::ItemStruct(struct_def, ref generics) => {
if !generics.is_type_parameterized() { if !generics.is_type_parameterized() {
trans_struct_def(ccx, struct_def); trans_struct_def(ccx, struct_def);
} }
} }
ast::item_trait(..) => { ast::ItemTrait(..) => {
// Inside of this trait definition, we won't be actually translating any // Inside of this trait definition, we won't be actually translating any
// functions, but the trait still needs to be walked. Otherwise default // functions, but the trait still needs to be walked. Otherwise default
// methods with items will not get translated and will cause ICE's when // methods with items will not get translated and will cause ICE's when
@ -2404,7 +2403,7 @@ pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
} }
} }
pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def) { pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::StructDef) {
// If this is a tuple-like struct, translate the constructor. // If this is a tuple-like struct, translate the constructor.
match struct_def.ctor_id { match struct_def.ctor_id {
// We only need to translate a constructor if there are fields; // We only need to translate a constructor if there are fields;
@ -2423,7 +2422,7 @@ pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def) {
// separate modules in the compiled program. That's because modules exist // separate modules in the compiled program. That's because modules exist
// only as a convenience for humans working with the code, to organize names // only as a convenience for humans working with the code, to organize names
// and control visibility. // and control visibility.
pub fn trans_mod(ccx: @CrateContext, m: &ast::_mod) { pub fn trans_mod(ccx: @CrateContext, m: &ast::Mod) {
let _icx = push_ctxt("trans_mod"); let _icx = push_ctxt("trans_mod");
for item in m.items.iter() { for item in m.items.iter() {
trans_item(ccx, *item); trans_item(ccx, *item);
@ -2580,18 +2579,19 @@ pub fn fill_fn_pair(bcx: &Block,
Store(bcx, llenvblobptr, env_cell); Store(bcx, llenvblobptr, env_cell);
} }
pub fn item_path(ccx: &CrateContext, id: &ast::NodeId) -> path { pub fn item_path(ccx: &CrateContext, id: &ast::NodeId) -> ast_map::Path {
ty::item_path(ccx.tcx, ast_util::local_def(*id)) ty::item_path(ccx.tcx, ast_util::local_def(*id))
} }
fn exported_name(ccx: &CrateContext, path: path, ty: ty::t, attrs: &[ast::Attribute]) -> ~str { fn exported_name(ccx: &CrateContext, path: ast_map::Path,
ty: ty::t, attrs: &[ast::Attribute]) -> ~str {
match attr::first_attr_value_str_by_name(attrs, "export_name") { match attr::first_attr_value_str_by_name(attrs, "export_name") {
// Use provided name // Use provided name
Some(name) => name.to_owned(), Some(name) => name.to_owned(),
// Don't mangle // Don't mangle
_ if attr::contains_name(attrs, "no_mangle") _ if attr::contains_name(attrs, "no_mangle")
=> path_elt_to_str(*path.last(), token::get_ident_interner()), => path_elem_to_str(*path.last(), token::get_ident_interner()),
// Usual name mangling // Usual name mangling
_ => mangle_exported_name(ccx, path, ty) _ => mangle_exported_name(ccx, path, ty)
@ -2615,15 +2615,15 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
items.get().get_copy(&id) items.get().get_copy(&id)
}; };
let val = match item { let val = match item {
ast_map::node_item(i, pth) => { ast_map::NodeItem(i, pth) => {
let elt = path_pretty_name(i.ident, id as u64); let elt = PathPrettyName(i.ident, id as u64);
let my_path = vec::append_one((*pth).clone(), elt); let my_path = vec::append_one((*pth).clone(), elt);
let ty = ty::node_id_to_type(ccx.tcx, i.id); let ty = ty::node_id_to_type(ccx.tcx, i.id);
let sym = exported_name(ccx, my_path, ty, i.attrs); let sym = exported_name(ccx, my_path, ty, i.attrs);
let v = match i.node { let v = match i.node {
ast::item_static(_, _, expr) => { ast::ItemStatic(_, _, expr) => {
// If this static came from an external crate, then // If this static came from an external crate, then
// we need to get the symbol from csearch instead of // we need to get the symbol from csearch instead of
// using the current crate's name/version // using the current crate's name/version
@ -2720,8 +2720,8 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
} }
} }
ast::item_fn(_, purity, _, _, _) => { ast::ItemFn(_, purity, _, _, _) => {
let llfn = if purity != ast::extern_fn { let llfn = if purity != ast::ExternFn {
register_fn(ccx, i.span, sym, i.id, ty) register_fn(ccx, i.span, sym, i.id, ty)
} else { } else {
foreign::register_rust_fn_with_foreign_abi(ccx, foreign::register_rust_fn_with_foreign_abi(ccx,
@ -2748,33 +2748,33 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
v v
} }
ast_map::node_trait_method(trait_method, _, pth) => { ast_map::NodeTraitMethod(trait_method, _, pth) => {
debug!("get_item_val(): processing a node_trait_method"); debug!("get_item_val(): processing a NodeTraitMethod");
match *trait_method { match *trait_method {
ast::required(_) => { ast::Required(_) => {
ccx.sess.bug("unexpected variant: required trait method in \ ccx.sess.bug("unexpected variant: required trait method in \
get_item_val()"); get_item_val()");
} }
ast::provided(m) => { ast::Provided(m) => {
register_method(ccx, id, pth, m) register_method(ccx, id, pth, m)
} }
} }
} }
ast_map::node_method(m, _, pth) => { ast_map::NodeMethod(m, _, pth) => {
register_method(ccx, id, pth, m) register_method(ccx, id, pth, m)
} }
ast_map::node_foreign_item(ni, abis, _, pth) => { ast_map::NodeForeignItem(ni, abis, _, pth) => {
let ty = ty::node_id_to_type(ccx.tcx, ni.id); let ty = ty::node_id_to_type(ccx.tcx, ni.id);
foreign = true; foreign = true;
match ni.node { match ni.node {
ast::foreign_item_fn(..) => { ast::ForeignItemFn(..) => {
let path = vec::append((*pth).clone(), [path_name(ni.ident)]); let path = vec::append_one((*pth).clone(), PathName(ni.ident));
foreign::register_foreign_item_fn(ccx, abis, &path, ni) foreign::register_foreign_item_fn(ccx, abis, &path, ni)
} }
ast::foreign_item_static(..) => { ast::ForeignItemStatic(..) => {
// Treat the crate map static specially in order to // Treat the crate map static specially in order to
// a weak-linkage-like functionality where it's // a weak-linkage-like functionality where it's
// dynamically resolved at runtime. If we're // dynamically resolved at runtime. If we're
@ -2813,25 +2813,25 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
} }
} }
ast_map::node_variant(ref v, enm, pth) => { ast_map::NodeVariant(ref v, enm, pth) => {
let llfn; let llfn;
match v.node.kind { match v.node.kind {
ast::tuple_variant_kind(ref args) => { ast::TupleVariantKind(ref args) => {
assert!(args.len() != 0u); assert!(args.len() != 0u);
let pth = vec::append((*pth).clone(), let pth = vec::append((*pth).clone(),
[path_name(enm.ident), [PathName(enm.ident),
path_name((*v).node.name)]); PathName((*v).node.name)]);
let ty = ty::node_id_to_type(ccx.tcx, id); let ty = ty::node_id_to_type(ccx.tcx, id);
let sym = exported_name(ccx, pth, ty, enm.attrs); let sym = exported_name(ccx, pth, ty, enm.attrs);
llfn = match enm.node { llfn = match enm.node {
ast::item_enum(_, _) => { ast::ItemEnum(_, _) => {
register_fn(ccx, (*v).span, sym, id, ty) register_fn(ccx, (*v).span, sym, id, ty)
} }
_ => fail!("node_variant, shouldn't happen") _ => fail!("NodeVariant, shouldn't happen")
}; };
} }
ast::struct_variant_kind(_) => { ast::StructVariantKind(_) => {
fail!("struct variant kind unexpected in get_item_val") fail!("struct variant kind unexpected in get_item_val")
} }
} }
@ -2839,7 +2839,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
llfn llfn
} }
ast_map::node_struct_ctor(struct_def, struct_item, struct_path) => { ast_map::NodeStructCtor(struct_def, struct_item, struct_path) => {
// Only register the constructor if this is a tuple-like struct. // Only register the constructor if this is a tuple-like struct.
match struct_def.ctor_id { match struct_def.ctor_id {
None => { None => {
@ -2883,12 +2883,12 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
pub fn register_method(ccx: @CrateContext, pub fn register_method(ccx: @CrateContext,
id: ast::NodeId, id: ast::NodeId,
path: @ast_map::path, path: @ast_map::Path,
m: @ast::method) -> ValueRef { m: @ast::Method) -> ValueRef {
let mty = ty::node_id_to_type(ccx.tcx, id); let mty = ty::node_id_to_type(ccx.tcx, id);
let mut path = (*path).clone(); let mut path = (*path).clone();
path.push(path_pretty_name(m.ident, token::gensym("meth") as u64)); path.push(PathPrettyName(m.ident, token::gensym("meth") as u64));
let sym = exported_name(ccx, path, mty, m.attrs); let sym = exported_name(ccx, path, mty, m.attrs);
@ -3138,7 +3138,7 @@ pub fn create_module_map(ccx: &CrateContext) -> (ValueRef, uint) {
pub fn symname(sess: session::Session, name: &str, pub fn symname(sess: session::Session, name: &str,
hash: &str, vers: &str) -> ~str { hash: &str, vers: &str) -> ~str {
let elt = path_name(sess.ident_of(name)); let elt = PathName(sess.ident_of(name));
link::exported_name(sess, ~[elt], hash, vers) link::exported_name(sess, ~[elt], hash, vers)
} }

View file

@ -370,7 +370,7 @@ pub fn trans_fn_ref_with_vtables(
|| format!("local item should be in ast map")); || format!("local item should be in ast map"));
match *map_node { match *map_node {
ast_map::node_foreign_item(_, abis, _, _) => { ast_map::NodeForeignItem(_, abis, _, _) => {
must_monomorphise = abis.is_intrinsic() must_monomorphise = abis.is_intrinsic()
} }
_ => { _ => {

View file

@ -26,7 +26,7 @@ use util::ppaux::ty_to_str;
use std::vec; use std::vec;
use syntax::ast; use syntax::ast;
use syntax::ast_map::path_name; use syntax::ast_map::PathName;
use syntax::ast_util; use syntax::ast_util;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
@ -358,7 +358,7 @@ pub fn load_environment(fcx: &FunctionContext,
pub fn trans_expr_fn<'a>( pub fn trans_expr_fn<'a>(
bcx: &'a Block<'a>, bcx: &'a Block<'a>,
sigil: ast::Sigil, sigil: ast::Sigil,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
outer_id: ast::NodeId, outer_id: ast::NodeId,
user_id: ast::NodeId, user_id: ast::NodeId,
@ -400,7 +400,7 @@ pub fn trans_expr_fn<'a>(
}; };
let sub_path = vec::append_one(bcx.fcx.path.clone(), let sub_path = vec::append_one(bcx.fcx.path.clone(),
path_name(special_idents::anon)); PathName(special_idents::anon));
// XXX: Bad copy. // XXX: Bad copy.
let s = mangle_internal_name_by_path_and_seq(ccx, let s = mangle_internal_name_by_path_and_seq(ccx,
sub_path.clone(), sub_path.clone(),

View file

@ -39,7 +39,7 @@ use std::hashmap::HashMap;
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char}; use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
use std::vec; use std::vec;
use syntax::ast::{Name, Ident}; use syntax::ast::{Name, Ident};
use syntax::ast_map::{path, path_elt, path_pretty_name}; use syntax::ast_map::{Path, PathElem, PathPrettyName};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::parse::token; use syntax::parse::token;
use syntax::{ast, ast_map}; use syntax::{ast, ast_map};
@ -79,10 +79,10 @@ pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
} }
} }
pub fn gensym_name(name: &str) -> (Ident, path_elt) { pub fn gensym_name(name: &str) -> (Ident, PathElem) {
let name = token::gensym(name); let name = token::gensym(name);
let ident = Ident::new(name); let ident = Ident::new(name);
(ident, path_pretty_name(ident, name as u64)) (ident, PathPrettyName(ident, name as u64))
} }
pub struct tydesc_info { pub struct tydesc_info {
@ -257,7 +257,7 @@ pub struct FunctionContext<'a> {
// The source span and nesting context where this function comes from, for // The source span and nesting context where this function comes from, for
// error reporting and symbol generation. // error reporting and symbol generation.
span: Option<Span>, span: Option<Span>,
path: path, path: Path,
// The arena that blocks are allocated from. // The arena that blocks are allocated from.
block_arena: TypedArena<Block<'a>>, block_arena: TypedArena<Block<'a>>,
@ -1078,13 +1078,13 @@ pub fn align_to(cx: &Block, off: ValueRef, align: ValueRef) -> ValueRef {
return build::And(cx, bumped, build::Not(cx, mask)); return build::And(cx, bumped, build::Not(cx, mask));
} }
pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str { pub fn path_str(sess: session::Session, p: &[PathElem]) -> ~str {
let mut r = ~""; let mut r = ~"";
let mut first = true; let mut first = true;
for e in p.iter() { for e in p.iter() {
match *e { match *e {
ast_map::path_name(s) | ast_map::path_mod(s) | ast_map::PathName(s) | ast_map::PathMod(s) |
ast_map::path_pretty_name(s, _) => { ast_map::PathPrettyName(s, _) => {
if first { if first {
first = false first = false
} else { } else {

View file

@ -35,44 +35,44 @@ use std::libc::c_uint;
use std::vec; use std::vec;
use syntax::{ast, ast_util, ast_map}; use syntax::{ast, ast_util, ast_map};
pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::lit) pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
-> ValueRef { -> ValueRef {
let _icx = push_ctxt("trans_lit"); let _icx = push_ctxt("trans_lit");
match lit.node { match lit.node {
ast::lit_char(i) => C_integral(Type::char(), i as u64, false), ast::LitChar(i) => C_integral(Type::char(), i as u64, false),
ast::lit_int(i, t) => C_integral(Type::int_from_ty(cx, t), i as u64, true), ast::LitInt(i, t) => C_integral(Type::int_from_ty(cx, t), i as u64, true),
ast::lit_uint(u, t) => C_integral(Type::uint_from_ty(cx, t), u, false), ast::LitUint(u, t) => C_integral(Type::uint_from_ty(cx, t), u, false),
ast::lit_int_unsuffixed(i) => { ast::LitIntUnsuffixed(i) => {
let lit_int_ty = ty::node_id_to_type(cx.tcx, e.id); let lit_int_ty = ty::node_id_to_type(cx.tcx, e.id);
match ty::get(lit_int_ty).sty { match ty::get(lit_int_ty).sty {
ty::ty_int(t) => { ty::ty_int(t) => {
C_integral(Type::int_from_ty(cx, t), i as u64, true) C_integral(Type::int_from_ty(cx, t), i as u64, true)
} }
ty::ty_uint(t) => { ty::ty_uint(t) => {
C_integral(Type::uint_from_ty(cx, t), i as u64, false) C_integral(Type::uint_from_ty(cx, t), i as u64, false)
} }
_ => cx.sess.span_bug(lit.span, _ => cx.sess.span_bug(lit.span,
format!("integer literal has type {} (expected int or uint)", format!("integer literal has type {} (expected int or uint)",
ty_to_str(cx.tcx, lit_int_ty))) ty_to_str(cx.tcx, lit_int_ty)))
}
} }
} ast::LitFloat(fs, t) => C_floating(fs, Type::float_from_ty(t)),
ast::lit_float(fs, t) => C_floating(fs, Type::float_from_ty(t)), ast::LitFloatUnsuffixed(fs) => {
ast::lit_float_unsuffixed(fs) => { let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id);
let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id); match ty::get(lit_float_ty).sty {
match ty::get(lit_float_ty).sty { ty::ty_float(t) => {
ty::ty_float(t) => { C_floating(fs, Type::float_from_ty(t))
C_floating(fs, Type::float_from_ty(t)) }
} _ => {
_ => { cx.sess.span_bug(lit.span,
cx.sess.span_bug(lit.span, "floating point literal doesn't have the right type");
"floating point literal doesn't have the right type"); }
} }
} }
} ast::LitBool(b) => C_bool(b),
ast::lit_bool(b) => C_bool(b), ast::LitNil => C_nil(),
ast::lit_nil => C_nil(), ast::LitStr(s, _) => C_estr_slice(cx, s),
ast::lit_str(s, _) => C_estr_slice(cx, s), ast::LitBinary(data) => C_binary_slice(cx, data),
ast::lit_binary(data) => C_binary_slice(cx, data),
} }
} }
@ -172,8 +172,8 @@ pub fn get_const_val(cx: @CrateContext,
}; };
match opt_item { match opt_item {
ast_map::node_item(@ast::item { ast_map::NodeItem(@ast::Item {
node: ast::item_static(_, ast::MutImmutable, _), .. node: ast::ItemStatic(_, ast::MutImmutable, _), ..
}, _) => { }, _) => {
trans_const(cx, ast::MutImmutable, def_id.node); trans_const(cx, ast::MutImmutable, def_id.node);
} }
@ -551,8 +551,8 @@ fn const_expr_unadjusted(cx: @CrateContext,
match sub.node { match sub.node {
ast::ExprLit(ref lit) => { ast::ExprLit(ref lit) => {
match lit.node { match lit.node {
ast::lit_str(..) => { const_expr(cx, sub) } ast::LitStr(..) => { const_expr(cx, sub) }
_ => { cx.sess.span_bug(e.span, "bad const-slice lit") } _ => { cx.sess.span_bug(e.span, "bad const-slice lit") }
} }
} }
ast::ExprVec(ref es, ast::MutImmutable) => { ast::ExprVec(ref es, ast::MutImmutable) => {

View file

@ -62,7 +62,7 @@ pub struct CrateContext {
// came from) // came from)
external_srcs: RefCell<HashMap<ast::NodeId, ast::DefId>>, external_srcs: RefCell<HashMap<ast::NodeId, ast::DefId>>,
// A set of static items which cannot be inlined into other crates. This // A set of static items which cannot be inlined into other crates. This
// will pevent in ii_item() structures from being encoded into the metadata // will pevent in IIItem() structures from being encoded into the metadata
// that is generated // that is generated
non_inlineable_statics: RefCell<HashSet<ast::NodeId>>, non_inlineable_statics: RefCell<HashSet<ast::NodeId>>,
// Cache instances of monomorphized functions // Cache instances of monomorphized functions

View file

@ -330,8 +330,8 @@ pub fn create_captured_var_metadata(bcx: &Block,
None => { None => {
cx.sess.span_bug(span, "debuginfo::create_captured_var_metadata() - NodeId not found"); cx.sess.span_bug(span, "debuginfo::create_captured_var_metadata() - NodeId not found");
} }
Some(ast_map::node_local(ident, _)) => ident, Some(ast_map::NodeLocal(ident, _)) => ident,
Some(ast_map::node_arg(@ast::Pat { node: ast::PatIdent(_, ref path, _), .. })) => { Some(ast_map::NodeArg(@ast::Pat { node: ast::PatIdent(_, ref path, _), .. })) => {
ast_util::path_to_ident(path) ast_util::path_to_ident(path)
} }
_ => { _ => {
@ -429,12 +429,12 @@ pub fn create_self_argument_metadata(bcx: &Block,
items.get().get_copy(&bcx.fcx.id) items.get().get_copy(&bcx.fcx.id)
}; };
let span = match fnitem { let span = match fnitem {
ast_map::node_method(@ast::method { explicit_self: explicit_self, .. }, _, _) => { ast_map::NodeMethod(@ast::Method { explicit_self: explicit_self, .. }, _, _) => {
explicit_self.span explicit_self.span
} }
ast_map::node_trait_method( ast_map::NodeTraitMethod(
@ast::provided( @ast::Provided(
@ast::method { @ast::Method {
explicit_self: explicit_self, explicit_self: explicit_self,
.. ..
}), }),
@ -494,7 +494,7 @@ pub fn create_self_argument_metadata(bcx: &Block,
/// Creates debug information for the given function argument. /// Creates debug information for the given function argument.
/// ///
/// Adds the created metadata nodes directly to the crate's IR. /// Adds the created metadata nodes directly to the crate's IR.
pub fn create_argument_metadata(bcx: &Block, arg: &ast::arg) { pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) {
if fn_should_be_ignored(bcx.fcx) { if fn_should_be_ignored(bcx.fcx) {
return; return;
} }
@ -618,9 +618,9 @@ pub fn create_function_debug_context(cx: &CrateContext,
items.get().get_copy(&fn_ast_id) items.get().get_copy(&fn_ast_id)
}; };
let (ident, fn_decl, generics, top_level_block, span, has_path) = match fnitem { let (ident, fn_decl, generics, top_level_block, span, has_path) = match fnitem {
ast_map::node_item(ref item, _) => { ast_map::NodeItem(ref item, _) => {
match item.node { match item.node {
ast::item_fn(fn_decl, _, _, ref generics, top_level_block) => { ast::ItemFn(fn_decl, _, _, ref generics, top_level_block) => {
(item.ident, fn_decl, generics, top_level_block, item.span, true) (item.ident, fn_decl, generics, top_level_block, item.span, true)
} }
_ => { _ => {
@ -629,8 +629,8 @@ pub fn create_function_debug_context(cx: &CrateContext,
} }
} }
} }
ast_map::node_method( ast_map::NodeMethod(
@ast::method { @ast::Method {
decl: fn_decl, decl: fn_decl,
ident: ident, ident: ident,
generics: ref generics, generics: ref generics,
@ -642,7 +642,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
_) => { _) => {
(ident, fn_decl, generics, top_level_block, span, true) (ident, fn_decl, generics, top_level_block, span, true)
} }
ast_map::node_expr(ref expr) => { ast_map::NodeExpr(ref expr) => {
match expr.node { match expr.node {
ast::ExprFnBlock(fn_decl, top_level_block) | ast::ExprFnBlock(fn_decl, top_level_block) |
ast::ExprProc(fn_decl, top_level_block) => { ast::ExprProc(fn_decl, top_level_block) => {
@ -661,9 +661,9 @@ pub fn create_function_debug_context(cx: &CrateContext,
"create_function_debug_context: expected an expr_fn_block here") "create_function_debug_context: expected an expr_fn_block here")
} }
} }
ast_map::node_trait_method( ast_map::NodeTraitMethod(
@ast::provided( @ast::Provided(
@ast::method { @ast::Method {
decl: fn_decl, decl: fn_decl,
ident: ident, ident: ident,
generics: ref generics, generics: ref generics,
@ -675,11 +675,8 @@ pub fn create_function_debug_context(cx: &CrateContext,
_) => { _) => {
(ident, fn_decl, generics, top_level_block, span, true) (ident, fn_decl, generics, top_level_block, span, true)
} }
ast_map::node_foreign_item(@ast::foreign_item { .. }, _, _, _) | ast_map::NodeForeignItem(..) | ast_map::NodeVariant(..)
ast_map::node_variant(..) | | ast_map::NodeStructCtor(..) => { return FunctionWithoutDebugInfo; }
ast_map::node_struct_ctor(..) => {
return FunctionWithoutDebugInfo;
}
_ => cx.sess.bug(format!("create_function_debug_context: \ _ => cx.sess.bug(format!("create_function_debug_context: \
unexpected sort of node: {:?}", fnitem)) unexpected sort of node: {:?}", fnitem))
}; };
@ -705,7 +702,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
file_metadata, file_metadata,
&mut function_name); &mut function_name);
// There is no ast_map::path for ast::ExprFnBlock-type functions. For now, just don't put them // There is no ast_map::Path for ast::ExprFnBlock-type functions. For now, just don't put them
// into a namespace. In the future this could be improved somehow (storing a path in the // into a namespace. In the future this could be improved somehow (storing a path in the
// ast_map, or construct a path using the enclosing function). // ast_map, or construct a path using the enclosing function).
let (linkage_name, containing_scope) = if has_path { let (linkage_name, containing_scope) = if has_path {
@ -779,7 +776,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
fn get_function_signature(cx: &CrateContext, fn get_function_signature(cx: &CrateContext,
fn_ast_id: ast::NodeId, fn_ast_id: ast::NodeId,
fn_decl: &ast::fn_decl, fn_decl: &ast::FnDecl,
param_substs: Option<@param_substs>, param_substs: Option<@param_substs>,
error_span: Span) -> DIArray { error_span: Span) -> DIArray {
if !cx.sess.opts.extra_debuginfo { if !cx.sess.opts.extra_debuginfo {
@ -790,7 +787,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
// Return type -- llvm::DIBuilder wants this at index 0 // Return type -- llvm::DIBuilder wants this at index 0
match fn_decl.output.node { match fn_decl.output.node {
ast::ty_nil => { ast::TyNil => {
signature.push(ptr::null()); signature.push(ptr::null());
} }
_ => { _ => {
@ -1118,22 +1115,22 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType {
ty::ty_bool => (~"bool", DW_ATE_boolean), ty::ty_bool => (~"bool", DW_ATE_boolean),
ty::ty_char => (~"char", DW_ATE_unsigned_char), ty::ty_char => (~"char", DW_ATE_unsigned_char),
ty::ty_int(int_ty) => match int_ty { ty::ty_int(int_ty) => match int_ty {
ast::ty_i => (~"int", DW_ATE_signed), ast::TyI => (~"int", DW_ATE_signed),
ast::ty_i8 => (~"i8", DW_ATE_signed), ast::TyI8 => (~"i8", DW_ATE_signed),
ast::ty_i16 => (~"i16", DW_ATE_signed), ast::TyI16 => (~"i16", DW_ATE_signed),
ast::ty_i32 => (~"i32", DW_ATE_signed), ast::TyI32 => (~"i32", DW_ATE_signed),
ast::ty_i64 => (~"i64", DW_ATE_signed) ast::TyI64 => (~"i64", DW_ATE_signed)
}, },
ty::ty_uint(uint_ty) => match uint_ty { ty::ty_uint(uint_ty) => match uint_ty {
ast::ty_u => (~"uint", DW_ATE_unsigned), ast::TyU => (~"uint", DW_ATE_unsigned),
ast::ty_u8 => (~"u8", DW_ATE_unsigned), ast::TyU8 => (~"u8", DW_ATE_unsigned),
ast::ty_u16 => (~"u16", DW_ATE_unsigned), ast::TyU16 => (~"u16", DW_ATE_unsigned),
ast::ty_u32 => (~"u32", DW_ATE_unsigned), ast::TyU32 => (~"u32", DW_ATE_unsigned),
ast::ty_u64 => (~"u64", DW_ATE_unsigned) ast::TyU64 => (~"u64", DW_ATE_unsigned)
}, },
ty::ty_float(float_ty) => match float_ty { ty::ty_float(float_ty) => match float_ty {
ast::ty_f32 => (~"f32", DW_ATE_float), ast::TyF32 => (~"f32", DW_ATE_float),
ast::ty_f64 => (~"f64", DW_ATE_float) ast::TyF64 => (~"f64", DW_ATE_float)
}, },
_ => cx.sess.bug("debuginfo::basic_type_metadata - t is invalid type") _ => cx.sess.bug("debuginfo::basic_type_metadata - t is invalid type")
}; };
@ -1422,7 +1419,7 @@ fn describe_enum_variant(cx: &CrateContext,
{ {
let items = cx.tcx.items.borrow(); let items = cx.tcx.items.borrow();
match items.get().find(&variant_info.id.node) { match items.get().find(&variant_info.id.node) {
Some(&ast_map::node_variant(ref variant, _, _)) => variant.span, Some(&ast_map::NodeVariant(ref variant, _, _)) => variant.span,
ref node => { ref node => {
cx.sess.span_warn(span, cx.sess.span_warn(span,
format!("debuginfo::enum_metadata()::\ format!("debuginfo::enum_metadata()::\
@ -2311,7 +2308,7 @@ fn get_namespace_and_span_for_item(cx: &CrateContext,
{ {
let items = cx.tcx.items.borrow(); let items = cx.tcx.items.borrow();
let definition_span = match items.get().find(&def_id.node) { let definition_span = match items.get().find(&def_id.node) {
Some(&ast_map::node_item(@ast::item { span, .. }, _)) => span, Some(&ast_map::NodeItem(@ast::Item { span, .. }, _)) => span,
ref node => { ref node => {
cx.sess.span_warn(warning_span, cx.sess.span_warn(warning_span,
format!("debuginfo::\ format!("debuginfo::\
@ -2704,7 +2701,7 @@ fn populate_scope_map(cx: &CrateContext,
scope_stack, scope_stack,
scope_map, scope_map,
|cx, scope_stack, scope_map| { |cx, scope_stack, scope_map| {
for &ast::arg { pat: pattern, .. } in decl.inputs.iter() { for &ast::Arg { pat: pattern, .. } in decl.inputs.iter() {
walk_pattern(cx, pattern, scope_stack, scope_map); walk_pattern(cx, pattern, scope_stack, scope_map);
} }
@ -2783,9 +2780,9 @@ fn populate_scope_map(cx: &CrateContext,
} }
} }
ast::ExprInlineAsm(ast::inline_asm { inputs: ref inputs, ast::ExprInlineAsm(ast::InlineAsm { inputs: ref inputs,
outputs: ref outputs, outputs: ref outputs,
.. }) => { .. }) => {
// inputs, outputs: ~[(@str, @expr)] // inputs, outputs: ~[(@str, @expr)]
for &(_, @ref exp) in inputs.iter() { for &(_, @ref exp) in inputs.iter() {
walk_expr(cx, exp, scope_stack, scope_map); walk_expr(cx, exp, scope_stack, scope_map);
@ -2852,7 +2849,7 @@ fn namespace_for_item(cx: &CrateContext,
if def_id.crate == ast::LOCAL_CRATE { if def_id.crate == ast::LOCAL_CRATE {
// prepend crate name if not already present // prepend crate name if not already present
let crate_namespace_ident = token::str_to_ident(cx.link_meta.crateid.name); let crate_namespace_ident = token::str_to_ident(cx.link_meta.crateid.name);
item_path.insert(0, ast_map::path_mod(crate_namespace_ident)); item_path.insert(0, ast_map::PathMod(crate_namespace_ident));
} }
item_path item_path

View file

@ -152,7 +152,7 @@ use std::hashmap::HashMap;
use std::vec; use std::vec;
use syntax::print::pprust::{expr_to_str}; use syntax::print::pprust::{expr_to_str};
use syntax::ast; use syntax::ast;
use syntax::ast_map::path_mod; use syntax::ast_map::PathMod;
use syntax::codemap; use syntax::codemap;
// Destinations // Destinations
@ -748,7 +748,7 @@ fn trans_rvalue_dps_unadjusted<'a>(
args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect(); args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect();
return trans_adt(bcx, repr, 0, numbered_fields, None, dest); return trans_adt(bcx, repr, 0, numbered_fields, None, dest);
} }
ast::ExprLit(@codemap::Spanned {node: ast::lit_str(s, _), ..}) => { ast::ExprLit(@codemap::Spanned {node: ast::LitStr(s, _), ..}) => {
return tvec::trans_lit_str(bcx, expr, s, dest); return tvec::trans_lit_str(bcx, expr, s, dest);
} }
ast::ExprVstore(contents, ast::ExprVstoreSlice) | ast::ExprVstore(contents, ast::ExprVstoreSlice) |
@ -1392,7 +1392,7 @@ fn trans_adt<'a>(
fn trans_immediate_lit<'a>( fn trans_immediate_lit<'a>(
bcx: &'a Block<'a>, bcx: &'a Block<'a>,
expr: &ast::Expr, expr: &ast::Expr,
lit: ast::lit) lit: ast::Lit)
-> DatumBlock<'a> { -> DatumBlock<'a> {
// must not be a string constant, that is a RvalueDpsExpr // must not be a string constant, that is a RvalueDpsExpr
let _icx = push_ctxt("trans_immediate_lit"); let _icx = push_ctxt("trans_immediate_lit");
@ -1916,10 +1916,10 @@ pub fn trans_log_level<'a>(bcx: &'a Block<'a>) -> DatumBlock<'a> {
None => ccx.link_meta.crateid.name.to_managed(), None => ccx.link_meta.crateid.name.to_managed(),
}; };
}; };
let mut modpath = ~[path_mod(ccx.sess.ident_of(srccrate))]; let mut modpath = ~[PathMod(ccx.sess.ident_of(srccrate))];
for e in bcx.fcx.path.iter() { for e in bcx.fcx.path.iter() {
match *e { match *e {
path_mod(_) => { modpath.push(*e) } PathMod(_) => { modpath.push(*e) }
_ => {} _ => {}
} }
} }

View file

@ -107,8 +107,8 @@ pub fn llvm_calling_convention(ccx: &CrateContext,
pub fn register_foreign_item_fn(ccx: @CrateContext, pub fn register_foreign_item_fn(ccx: @CrateContext,
abis: AbiSet, abis: AbiSet,
path: &ast_map::path, path: &ast_map::Path,
foreign_item: @ast::foreign_item) -> ValueRef { foreign_item: @ast::ForeignItem) -> ValueRef {
/*! /*!
* Registers a foreign function found in a library. * Registers a foreign function found in a library.
* Just adds a LLVM global. * Just adds a LLVM global.
@ -352,15 +352,15 @@ pub fn trans_native_call<'a>(
} }
pub fn trans_foreign_mod(ccx: @CrateContext, pub fn trans_foreign_mod(ccx: @CrateContext,
foreign_mod: &ast::foreign_mod) { foreign_mod: &ast::ForeignMod) {
let _icx = push_ctxt("foreign::trans_foreign_mod"); let _icx = push_ctxt("foreign::trans_foreign_mod");
for &foreign_item in foreign_mod.items.iter() { for &foreign_item in foreign_mod.items.iter() {
match foreign_item.node { match foreign_item.node {
ast::foreign_item_fn(..) => { ast::ForeignItemFn(..) => {
let items = ccx.tcx.items.borrow(); let items = ccx.tcx.items.borrow();
let (abis, mut path) = let (abis, mut path) =
match items.get().get_copy(&foreign_item.id) { match items.get().get_copy(&foreign_item.id) {
ast_map::node_foreign_item(_, abis, _, path) => { ast_map::NodeForeignItem(_, abis, _, path) => {
(abis, (*path).clone()) (abis, (*path).clone())
} }
_ => { _ => {
@ -369,7 +369,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
} }
}; };
if !(abis.is_rust() || abis.is_intrinsic()) { if !(abis.is_rust() || abis.is_intrinsic()) {
path.push(ast_map::path_name(foreign_item.ident)); path.push(ast_map::PathName(foreign_item.ident));
register_foreign_item_fn(ccx, abis, &path, foreign_item); register_foreign_item_fn(ccx, abis, &path, foreign_item);
} }
} }
@ -437,8 +437,8 @@ pub fn register_rust_fn_with_foreign_abi(ccx: @CrateContext,
} }
pub fn trans_rust_fn_with_foreign_abi(ccx: @CrateContext, pub fn trans_rust_fn_with_foreign_abi(ccx: @CrateContext,
path: &ast_map::path, path: &ast_map::Path,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
attrs: &[ast::Attribute], attrs: &[ast::Attribute],
llwrapfn: ValueRef, llwrapfn: ValueRef,
@ -455,8 +455,8 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @CrateContext,
} }
fn build_rust_fn(ccx: @CrateContext, fn build_rust_fn(ccx: @CrateContext,
path: &ast_map::path, path: &ast_map::Path,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
attrs: &[ast::Attribute], attrs: &[ast::Attribute],
id: ast::NodeId) id: ast::NodeId)
@ -465,7 +465,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @CrateContext,
let tcx = ccx.tcx; let tcx = ccx.tcx;
let t = ty::node_id_to_type(tcx, id); let t = ty::node_id_to_type(tcx, id);
let ps = link::mangle_internal_name_by_path( let ps = link::mangle_internal_name_by_path(
ccx, vec::append_one((*path).clone(), ast_map::path_name( ccx, vec::append_one((*path).clone(), ast_map::PathName(
special_idents::clownshoe_abi special_idents::clownshoe_abi
))); )));
@ -748,7 +748,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @CrateContext,
// This code is kind of a confused mess and needs to be reworked given // This code is kind of a confused mess and needs to be reworked given
// the massive simplifications that have occurred. // the massive simplifications that have occurred.
pub fn link_name(ccx: &CrateContext, i: @ast::foreign_item) -> @str { pub fn link_name(ccx: &CrateContext, i: @ast::ForeignItem) -> @str {
match attr::first_attr_value_str_by_name(i.attrs, "link_name") { match attr::first_attr_value_str_by_name(i.attrs, "link_name") {
None => ccx.sess.str_of(i.ident), None => ccx.sess.str_of(i.ident),
Some(ln) => ln, Some(ln) => ln,

View file

@ -19,7 +19,7 @@ use util::ppaux::ty_to_str;
use std::vec; use std::vec;
use syntax::ast; use syntax::ast;
use syntax::ast_map::path_name; use syntax::ast_map::PathName;
use syntax::ast_util::local_def; use syntax::ast_util::local_def;
use syntax::attr; use syntax::attr;
@ -56,7 +56,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
external.get().insert(fn_id, None); external.get().insert(fn_id, None);
fn_id fn_id
} }
csearch::found(ast::ii_item(item)) => { csearch::found(ast::IIItem(item)) => {
{ {
let mut external = ccx.external.borrow_mut(); let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut(); let mut external_srcs = ccx.external_srcs.borrow_mut();
@ -76,7 +76,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
// however, so we use the available_externally linkage which llvm // however, so we use the available_externally linkage which llvm
// provides // provides
match item.node { match item.node {
ast::item_static(..) => { ast::ItemStatic(..) => {
let g = get_item_val(ccx, item.id); let g = get_item_val(ccx, item.id);
// see the comment in get_item_val() as to why this check is // see the comment in get_item_val() as to why this check is
// performed here. // performed here.
@ -90,7 +90,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
local_def(item.id) local_def(item.id)
} }
csearch::found(ast::ii_foreign(item)) => { csearch::found(ast::IIForeign(item)) => {
{ {
let mut external = ccx.external.borrow_mut(); let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut(); let mut external_srcs = ccx.external_srcs.borrow_mut();
@ -99,7 +99,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
} }
local_def(item.id) local_def(item.id)
} }
csearch::found_parent(parent_id, ast::ii_item(item)) => { csearch::found_parent(parent_id, ast::IIItem(item)) => {
{ {
let mut external = ccx.external.borrow_mut(); let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut(); let mut external_srcs = ccx.external_srcs.borrow_mut();
@ -109,7 +109,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
let mut my_id = 0; let mut my_id = 0;
match item.node { match item.node {
ast::item_enum(_, _) => { ast::ItemEnum(_, _) => {
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id)); let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
let vs_there = ty::enum_variants(ccx.tcx, parent_id); let vs_there = ty::enum_variants(ccx.tcx, parent_id);
for (here, there) in vs_here.iter().zip(vs_there.iter()) { for (here, there) in vs_here.iter().zip(vs_there.iter()) {
@ -118,7 +118,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
external.get().insert(there.id, Some(here.id.node)); external.get().insert(there.id, Some(here.id.node));
} }
} }
ast::item_struct(ref struct_def, _) => { ast::ItemStruct(ref struct_def, _) => {
match struct_def.ctor_id { match struct_def.ctor_id {
None => {} None => {}
Some(ctor_id) => { Some(ctor_id) => {
@ -138,7 +138,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
ccx.sess.bug("maybe_get_item_ast returned a found_parent \ ccx.sess.bug("maybe_get_item_ast returned a found_parent \
with a non-item parent"); with a non-item parent");
} }
csearch::found(ast::ii_method(impl_did, is_provided, mth)) => { csearch::found(ast::IIMethod(impl_did, is_provided, mth)) => {
{ {
let mut external = ccx.external.borrow_mut(); let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut(); let mut external_srcs = ccx.external_srcs.borrow_mut();
@ -159,18 +159,17 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
if num_type_params == 0 { if num_type_params == 0 {
let llfn = get_item_val(ccx, mth.id); let llfn = get_item_val(ccx, mth.id);
let path = vec::append( let path = vec::append_one(
ty::item_path(ccx.tcx, impl_did), ty::item_path(ccx.tcx, impl_did), PathName(mth.ident));
[path_name(mth.ident)]);
let self_kind = match mth.explicit_self.node { let self_kind = match mth.explicit_self.node {
ast::sty_static => no_self, ast::SelfStatic => no_self,
_ => { _ => {
let self_ty = ty::node_id_to_type(ccx.tcx, let self_ty = ty::node_id_to_type(ccx.tcx,
mth.self_id); mth.self_id);
debug!("calling inline trans_fn with self_ty {}", debug!("calling inline trans_fn with self_ty {}",
ty_to_str(ccx.tcx, self_ty)); ty_to_str(ccx.tcx, self_ty));
match mth.explicit_self.node { match mth.explicit_self.node {
ast::sty_value(_) => impl_self(self_ty, ty::ByRef), ast::SelfValue(_) => impl_self(self_ty, ty::ByRef),
_ => impl_self(self_ty, ty::ByCopy), _ => impl_self(self_ty, ty::ByCopy),
} }
} }

View file

@ -31,8 +31,8 @@ use middle::trans::type_::Type;
pub fn trans_intrinsic(ccx: @CrateContext, pub fn trans_intrinsic(ccx: @CrateContext,
decl: ValueRef, decl: ValueRef,
item: &ast::foreign_item, item: &ast::ForeignItem,
path: ast_map::path, path: ast_map::Path,
substs: @param_substs, substs: @param_substs,
_attributes: &[ast::Attribute], _attributes: &[ast::Attribute],
ref_id: Option<ast::NodeId>) { ref_id: Option<ast::NodeId>) {
@ -348,7 +348,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let sp = { let sp = {
let items = ccx.tcx.items.borrow(); let items = ccx.tcx.items.borrow();
match items.get().get_copy(&ref_id.unwrap()) { match items.get().get_copy(&ref_id.unwrap()) {
ast_map::node_expr(e) => e.span, ast_map::NodeExpr(e) => e.span,
_ => fail!("transmute has non-expr arg"), _ => fail!("transmute has non-expr arg"),
} }
}; };

View file

@ -34,11 +34,9 @@ use middle::trans::type_::Type;
use std::c_str::ToCStr; use std::c_str::ToCStr;
use std::vec; use std::vec;
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name}; use syntax::ast_map::{Path, PathMod, PathName, PathPrettyName};
use syntax::ast_util;
use syntax::{ast, ast_map};
use syntax::parse::token; use syntax::parse::token;
use syntax::visit; use syntax::{ast, ast_map, ast_util, visit};
/** /**
The main "translation" pass for methods. Generates code The main "translation" pass for methods. Generates code
@ -47,9 +45,9 @@ be generated once they are invoked with specific type parameters,
see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`. see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`.
*/ */
pub fn trans_impl(ccx: @CrateContext, pub fn trans_impl(ccx: @CrateContext,
path: path, path: Path,
name: ast::Ident, name: ast::Ident,
methods: &[@ast::method], methods: &[@ast::Method],
generics: &ast::Generics, generics: &ast::Generics,
id: ast::NodeId) { id: ast::NodeId) {
let _icx = push_ctxt("impl::trans_impl"); let _icx = push_ctxt("impl::trans_impl");
@ -67,12 +65,12 @@ pub fn trans_impl(ccx: @CrateContext,
} }
return; return;
} }
let sub_path = vec::append_one(path, path_name(name)); let sub_path = vec::append_one(path, PathName(name));
for method in methods.iter() { for method in methods.iter() {
if method.generics.ty_params.len() == 0u { if method.generics.ty_params.len() == 0u {
let llfn = get_item_val(ccx, method.id); let llfn = get_item_val(ccx, method.id);
let path = vec::append_one(sub_path.clone(), let path = vec::append_one(sub_path.clone(),
path_name(method.ident)); PathName(method.ident));
trans_method(ccx, trans_method(ccx,
path, path,
@ -98,13 +96,13 @@ pub fn trans_impl(ccx: @CrateContext,
/// ///
/// XXX(pcwalton) Can we take `path` by reference? /// XXX(pcwalton) Can we take `path` by reference?
pub fn trans_method(ccx: @CrateContext, pub fn trans_method(ccx: @CrateContext,
path: path, path: Path,
method: &ast::method, method: &ast::Method,
param_substs: Option<@param_substs>, param_substs: Option<@param_substs>,
llfn: ValueRef) { llfn: ValueRef) {
// figure out how self is being passed // figure out how self is being passed
let self_arg = match method.explicit_self.node { let self_arg = match method.explicit_self.node {
ast::sty_static => { ast::SelfStatic => {
no_self no_self
} }
_ => { _ => {
@ -120,7 +118,7 @@ pub fn trans_method(ccx: @CrateContext,
debug!("calling trans_fn with self_ty {}", debug!("calling trans_fn with self_ty {}",
self_ty.repr(ccx.tcx)); self_ty.repr(ccx.tcx));
match method.explicit_self.node { match method.explicit_self.node {
ast::sty_value(_) => impl_self(self_ty, ty::ByRef), ast::SelfValue(_) => impl_self(self_ty, ty::ByRef),
_ => impl_self(self_ty, ty::ByCopy), _ => impl_self(self_ty, ty::ByCopy),
} }
} }
@ -252,7 +250,7 @@ pub fn trans_static_method_callee(bcx: &Block,
{ {
let items = bcx.tcx().items.borrow(); let items = bcx.tcx().items.borrow();
match items.get().get_copy(&method_id.node) { match items.get().get_copy(&method_id.node) {
ast_map::node_trait_method(trait_method, _, _) => { ast_map::NodeTraitMethod(trait_method, _, _) => {
ast_util::trait_method_to_ty_method(trait_method).ident ast_util::trait_method_to_ty_method(trait_method).ident
} }
_ => fail!("callee is not a trait method") _ => fail!("callee is not a trait method")
@ -261,8 +259,8 @@ pub fn trans_static_method_callee(bcx: &Block,
} else { } else {
let path = csearch::get_item_path(bcx.tcx(), method_id); let path = csearch::get_item_path(bcx.tcx(), method_id);
match path[path.len()-1] { match path[path.len()-1] {
path_pretty_name(s, _) | path_name(s) => { s } PathPrettyName(s, _) | PathName(s) => { s }
path_mod(_) => { fail!("path doesn't have a name?") } PathMod(_) => { fail!("path doesn't have a name?") }
} }
}; };
debug!("trans_static_method_callee: method_id={:?}, callee_id={:?}, \ debug!("trans_static_method_callee: method_id={:?}, callee_id={:?}, \

View file

@ -107,44 +107,44 @@ pub fn monomorphic_fn(ccx: @CrateContext,
// Get the path so that we can create a symbol // Get the path so that we can create a symbol
let (pt, name, span) = match map_node { let (pt, name, span) = match map_node {
ast_map::node_item(i, pt) => (pt, i.ident, i.span), ast_map::NodeItem(i, pt) => (pt, i.ident, i.span),
ast_map::node_variant(ref v, enm, pt) => (pt, (*v).node.name, enm.span), ast_map::NodeVariant(ref v, enm, pt) => (pt, (*v).node.name, enm.span),
ast_map::node_method(m, _, pt) => (pt, m.ident, m.span), ast_map::NodeMethod(m, _, pt) => (pt, m.ident, m.span),
ast_map::node_foreign_item(i, abis, _, pt) if abis.is_intrinsic() ast_map::NodeForeignItem(i, abis, _, pt) if abis.is_intrinsic()
=> (pt, i.ident, i.span), => (pt, i.ident, i.span),
ast_map::node_foreign_item(..) => { ast_map::NodeForeignItem(..) => {
// Foreign externs don't have to be monomorphized. // Foreign externs don't have to be monomorphized.
return (get_item_val(ccx, fn_id.node), true); return (get_item_val(ccx, fn_id.node), true);
} }
ast_map::node_trait_method(@ast::provided(m), _, pt) => { ast_map::NodeTraitMethod(@ast::Provided(m), _, pt) => {
// If this is a static provided method, indicate that // If this is a static provided method, indicate that
// and stash the number of params on the method. // and stash the number of params on the method.
if m.explicit_self.node == ast::sty_static { if m.explicit_self.node == ast::SelfStatic {
is_static_provided = Some(m.generics.ty_params.len()); is_static_provided = Some(m.generics.ty_params.len());
} }
(pt, m.ident, m.span) (pt, m.ident, m.span)
} }
ast_map::node_trait_method(@ast::required(_), _, _) => { ast_map::NodeTraitMethod(@ast::Required(_), _, _) => {
ccx.tcx.sess.bug("Can't monomorphize a required trait method") ccx.tcx.sess.bug("Can't monomorphize a required trait method")
} }
ast_map::node_expr(..) => { ast_map::NodeExpr(..) => {
ccx.tcx.sess.bug("Can't monomorphize an expr") ccx.tcx.sess.bug("Can't monomorphize an expr")
} }
ast_map::node_stmt(..) => { ast_map::NodeStmt(..) => {
ccx.tcx.sess.bug("Can't monomorphize a stmt") ccx.tcx.sess.bug("Can't monomorphize a stmt")
} }
ast_map::node_arg(..) => ccx.tcx.sess.bug("Can't monomorphize an arg"), ast_map::NodeArg(..) => ccx.tcx.sess.bug("Can't monomorphize an arg"),
ast_map::node_block(..) => { ast_map::NodeBlock(..) => {
ccx.tcx.sess.bug("Can't monomorphize a block") ccx.tcx.sess.bug("Can't monomorphize a block")
} }
ast_map::node_local(..) => { ast_map::NodeLocal(..) => {
ccx.tcx.sess.bug("Can't monomorphize a local") ccx.tcx.sess.bug("Can't monomorphize a local")
} }
ast_map::node_callee_scope(..) => { ast_map::NodeCalleeScope(..) => {
ccx.tcx.sess.bug("Can't monomorphize a callee-scope") ccx.tcx.sess.bug("Can't monomorphize a callee-scope")
} }
ast_map::node_struct_ctor(_, i, pt) => (pt, i.ident, i.span) ast_map::NodeStructCtor(_, i, pt) => (pt, i.ident, i.span)
}; };
debug!("monomorphic_fn about to subst into {}", llitem_ty.repr(ccx.tcx)); debug!("monomorphic_fn about to subst into {}", llitem_ty.repr(ccx.tcx));
@ -219,8 +219,8 @@ pub fn monomorphic_fn(ccx: @CrateContext,
}; };
let lldecl = match map_node { let lldecl = match map_node {
ast_map::node_item(i@@ast::item { ast_map::NodeItem(i@@ast::Item {
node: ast::item_fn(decl, _, _, _, body), node: ast::ItemFn(decl, _, _, _, body),
.. ..
}, _) => { }, _) => {
let d = mk_lldecl(); let d = mk_lldecl();
@ -236,22 +236,22 @@ pub fn monomorphic_fn(ccx: @CrateContext,
[]); []);
d d
} }
ast_map::node_item(..) => { ast_map::NodeItem(..) => {
ccx.tcx.sess.bug("Can't monomorphize this kind of item") ccx.tcx.sess.bug("Can't monomorphize this kind of item")
} }
ast_map::node_foreign_item(i, _, _, _) => { ast_map::NodeForeignItem(i, _, _, _) => {
let d = mk_lldecl(); let d = mk_lldecl();
intrinsic::trans_intrinsic(ccx, d, i, pt, psubsts, i.attrs, intrinsic::trans_intrinsic(ccx, d, i, pt, psubsts, i.attrs,
ref_id); ref_id);
d d
} }
ast_map::node_variant(v, enum_item, _) => { ast_map::NodeVariant(v, enum_item, _) => {
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id)); let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
let this_tv = *tvs.iter().find(|tv| { tv.id.node == fn_id.node}).unwrap(); let this_tv = *tvs.iter().find(|tv| { tv.id.node == fn_id.node}).unwrap();
let d = mk_lldecl(); let d = mk_lldecl();
set_inline_hint(d); set_inline_hint(d);
match v.node.kind { match v.node.kind {
ast::tuple_variant_kind(ref args) => { ast::TupleVariantKind(ref args) => {
trans_enum_variant(ccx, trans_enum_variant(ccx,
enum_item.id, enum_item.id,
v, v,
@ -260,25 +260,25 @@ pub fn monomorphic_fn(ccx: @CrateContext,
Some(psubsts), Some(psubsts),
d); d);
} }
ast::struct_variant_kind(_) => ast::StructVariantKind(_) =>
ccx.tcx.sess.bug("can't monomorphize struct variants"), ccx.tcx.sess.bug("can't monomorphize struct variants"),
} }
d d
} }
ast_map::node_method(mth, _, _) => { ast_map::NodeMethod(mth, _, _) => {
// XXX: What should the self type be here? // XXX: What should the self type be here?
let d = mk_lldecl(); let d = mk_lldecl();
set_llvm_fn_attrs(mth.attrs, d); set_llvm_fn_attrs(mth.attrs, d);
meth::trans_method(ccx, pt, mth, Some(psubsts), d); meth::trans_method(ccx, pt, mth, Some(psubsts), d);
d d
} }
ast_map::node_trait_method(@ast::provided(mth), _, pt) => { ast_map::NodeTraitMethod(@ast::Provided(mth), _, pt) => {
let d = mk_lldecl(); let d = mk_lldecl();
set_llvm_fn_attrs(mth.attrs, d); set_llvm_fn_attrs(mth.attrs, d);
meth::trans_method(ccx, (*pt).clone(), mth, Some(psubsts), d); meth::trans_method(ccx, (*pt).clone(), mth, Some(psubsts), d);
d d
} }
ast_map::node_struct_ctor(struct_def, _, _) => { ast_map::NodeStructCtor(struct_def, _, _) => {
let d = mk_lldecl(); let d = mk_lldecl();
set_inline_hint(d); set_inline_hint(d);
base::trans_tuple_struct(ccx, base::trans_tuple_struct(ccx,
@ -291,13 +291,13 @@ pub fn monomorphic_fn(ccx: @CrateContext,
} }
// Ugh -- but this ensures any new variants won't be forgotten // Ugh -- but this ensures any new variants won't be forgotten
ast_map::node_expr(..) | ast_map::NodeExpr(..) |
ast_map::node_stmt(..) | ast_map::NodeStmt(..) |
ast_map::node_trait_method(..) | ast_map::NodeTraitMethod(..) |
ast_map::node_arg(..) | ast_map::NodeArg(..) |
ast_map::node_block(..) | ast_map::NodeBlock(..) |
ast_map::node_callee_scope(..) | ast_map::NodeCalleeScope(..) |
ast_map::node_local(..) => { ast_map::NodeLocal(..) => {
ccx.tcx.sess.bug(format!("Can't monomorphize a {:?}", map_node)) ccx.tcx.sess.bug(format!("Can't monomorphize a {:?}", map_node))
} }
}; };

View file

@ -29,7 +29,7 @@ use std::option::{Some,None};
use std::vec; use std::vec;
use syntax::ast::DefId; use syntax::ast::DefId;
use syntax::ast; use syntax::ast;
use syntax::ast_map::path_name; use syntax::ast_map::PathName;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
use middle::trans::type_::Type; use middle::trans::type_::Type;
@ -158,18 +158,18 @@ impl<'a> Reflector<'a> {
ty::ty_nil => self.leaf("nil"), ty::ty_nil => self.leaf("nil"),
ty::ty_bool => self.leaf("bool"), ty::ty_bool => self.leaf("bool"),
ty::ty_char => self.leaf("char"), ty::ty_char => self.leaf("char"),
ty::ty_int(ast::ty_i) => self.leaf("int"), ty::ty_int(ast::TyI) => self.leaf("int"),
ty::ty_int(ast::ty_i8) => self.leaf("i8"), ty::ty_int(ast::TyI8) => self.leaf("i8"),
ty::ty_int(ast::ty_i16) => self.leaf("i16"), ty::ty_int(ast::TyI16) => self.leaf("i16"),
ty::ty_int(ast::ty_i32) => self.leaf("i32"), ty::ty_int(ast::TyI32) => self.leaf("i32"),
ty::ty_int(ast::ty_i64) => self.leaf("i64"), ty::ty_int(ast::TyI64) => self.leaf("i64"),
ty::ty_uint(ast::ty_u) => self.leaf("uint"), ty::ty_uint(ast::TyU) => self.leaf("uint"),
ty::ty_uint(ast::ty_u8) => self.leaf("u8"), ty::ty_uint(ast::TyU8) => self.leaf("u8"),
ty::ty_uint(ast::ty_u16) => self.leaf("u16"), ty::ty_uint(ast::TyU16) => self.leaf("u16"),
ty::ty_uint(ast::ty_u32) => self.leaf("u32"), ty::ty_uint(ast::TyU32) => self.leaf("u32"),
ty::ty_uint(ast::ty_u64) => self.leaf("u64"), ty::ty_uint(ast::TyU64) => self.leaf("u64"),
ty::ty_float(ast::ty_f32) => self.leaf("f32"), ty::ty_float(ast::TyF32) => self.leaf("f32"),
ty::ty_float(ast::ty_f64) => self.leaf("f64"), ty::ty_float(ast::TyF64) => self.leaf("f64"),
ty::ty_unboxed_vec(ref mt) => { ty::ty_unboxed_vec(ref mt) => {
let values = self.c_mt(mt); let values = self.c_mt(mt);
@ -290,7 +290,7 @@ impl<'a> Reflector<'a> {
mutbl: ast::MutImmutable }); mutbl: ast::MutImmutable });
let make_get_disr = || { let make_get_disr = || {
let sub_path = bcx.fcx.path + &[path_name(special_idents::anon)]; let sub_path = bcx.fcx.path + &[PathName(special_idents::anon)];
let sym = mangle_internal_name_by_path_and_seq(ccx, let sym = mangle_internal_name_by_path_and_seq(ccx,
sub_path, sub_path,
"get_disr"); "get_disr");
@ -416,10 +416,10 @@ pub fn ast_sigil_constant(sigil: ast::Sigil) -> uint {
} }
} }
pub fn ast_purity_constant(purity: ast::purity) -> uint { pub fn ast_purity_constant(purity: ast::Purity) -> uint {
match purity { match purity {
ast::unsafe_fn => 1u, ast::UnsafeFn => 1u,
ast::impure_fn => 2u, ast::ImpureFn => 2u,
ast::extern_fn => 3u ast::ExternFn => 3u
} }
} }

View file

@ -225,7 +225,7 @@ pub fn trans_slice_vstore<'a>(
// Handle the &"..." case: // Handle the &"..." case:
match content_expr.node { match content_expr.node {
ast::ExprLit(@codemap::Spanned {node: ast::lit_str(s, _), span: _}) => { ast::ExprLit(@codemap::Spanned {node: ast::LitStr(s, _), span: _}) => {
return trans_lit_str(bcx, content_expr, s, dest); return trans_lit_str(bcx, content_expr, s, dest);
} }
_ => {} _ => {}
@ -320,7 +320,7 @@ pub fn trans_uniq_or_managed_vstore<'a>(
heap_exchange => { heap_exchange => {
match content_expr.node { match content_expr.node {
ast::ExprLit(@codemap::Spanned { ast::ExprLit(@codemap::Spanned {
node: ast::lit_str(s, _), span node: ast::LitStr(s, _), span
}) => { }) => {
let llptrval = C_cstr(bcx.ccx(), s); let llptrval = C_cstr(bcx.ccx(), s);
let llptrval = PointerCast(bcx, llptrval, Type::i8p()); let llptrval = PointerCast(bcx, llptrval, Type::i8p());
@ -382,7 +382,7 @@ pub fn write_content<'a>(
let _indenter = indenter(); let _indenter = indenter();
match content_expr.node { match content_expr.node {
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(s, _), .. }) => { ast::ExprLit(@codemap::Spanned { node: ast::LitStr(s, _), .. }) => {
match dest { match dest {
Ignore => { Ignore => {
return bcx; return bcx;
@ -479,7 +479,7 @@ pub fn elements_required(bcx: &Block, content_expr: &ast::Expr) -> uint {
//! Figure out the number of elements we need to store this content //! Figure out the number of elements we need to store this content
match content_expr.node { match content_expr.node {
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(s, _), .. }) => { ast::ExprLit(@codemap::Spanned { node: ast::LitStr(s, _), .. }) => {
s.len() s.len()
}, },
ast::ExprVec(ref es, _) => es.len(), ast::ExprVec(ref es, _) => es.len(),

View file

@ -117,30 +117,30 @@ impl Type {
Type::f64() Type::f64()
} }
pub fn int_from_ty(ctx: &CrateContext, t: ast::int_ty) -> Type { pub fn int_from_ty(ctx: &CrateContext, t: ast::IntTy) -> Type {
match t { match t {
ast::ty_i => ctx.int_type, ast::TyI => ctx.int_type,
ast::ty_i8 => Type::i8(), ast::TyI8 => Type::i8(),
ast::ty_i16 => Type::i16(), ast::TyI16 => Type::i16(),
ast::ty_i32 => Type::i32(), ast::TyI32 => Type::i32(),
ast::ty_i64 => Type::i64() ast::TyI64 => Type::i64()
} }
} }
pub fn uint_from_ty(ctx: &CrateContext, t: ast::uint_ty) -> Type { pub fn uint_from_ty(ctx: &CrateContext, t: ast::UintTy) -> Type {
match t { match t {
ast::ty_u => ctx.int_type, ast::TyU => ctx.int_type,
ast::ty_u8 => Type::i8(), ast::TyU8 => Type::i8(),
ast::ty_u16 => Type::i16(), ast::TyU16 => Type::i16(),
ast::ty_u32 => Type::i32(), ast::TyU32 => Type::i32(),
ast::ty_u64 => Type::i64() ast::TyU64 => Type::i64()
} }
} }
pub fn float_from_ty(t: ast::float_ty) -> Type { pub fn float_from_ty(t: ast::FloatTy) -> Type {
match t { match t {
ast::ty_f32 => Type::f32(), ast::TyF32 => Type::f32(),
ast::ty_f64 => Type::f64() ast::TyF64 => Type::f64()
} }
} }

View file

@ -267,7 +267,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
ty::ty_evec(ref mt, ty::vstore_slice(_)) => { ty::ty_evec(ref mt, ty::vstore_slice(_)) => {
let p_ty = type_of(cx, mt.ty).ptr_to(); let p_ty = type_of(cx, mt.ty).ptr_to();
let u_ty = Type::uint_from_ty(cx, ast::ty_u); let u_ty = Type::uint_from_ty(cx, ast::TyU);
Type::struct_([p_ty, u_ty], false) Type::struct_([p_ty, u_ty], false)
} }

View file

@ -76,8 +76,8 @@ pub struct Method {
generics: ty::Generics, generics: ty::Generics,
transformed_self_ty: Option<ty::t>, transformed_self_ty: Option<ty::t>,
fty: BareFnTy, fty: BareFnTy,
explicit_self: ast::explicit_self_, explicit_self: ast::ExplicitSelf_,
vis: ast::visibility, vis: ast::Visibility,
def_id: ast::DefId, def_id: ast::DefId,
container: MethodContainer, container: MethodContainer,
@ -90,14 +90,14 @@ impl Method {
generics: ty::Generics, generics: ty::Generics,
transformed_self_ty: Option<ty::t>, transformed_self_ty: Option<ty::t>,
fty: BareFnTy, fty: BareFnTy,
explicit_self: ast::explicit_self_, explicit_self: ast::ExplicitSelf_,
vis: ast::visibility, vis: ast::Visibility,
def_id: ast::DefId, def_id: ast::DefId,
container: MethodContainer, container: MethodContainer,
provided_source: Option<ast::DefId>) provided_source: Option<ast::DefId>)
-> Method { -> Method {
// Check the invariants. // Check the invariants.
if explicit_self == ast::sty_static { if explicit_self == ast::SelfStatic {
assert!(transformed_self_ty.is_none()); assert!(transformed_self_ty.is_none());
} else { } else {
assert!(transformed_self_ty.is_some()); assert!(transformed_self_ty.is_some());
@ -162,7 +162,7 @@ pub enum SelfMode {
pub struct field_ty { pub struct field_ty {
name: Name, name: Name,
id: DefId, id: DefId,
vis: ast::visibility, vis: ast::Visibility,
} }
// Contains information needed to resolve types and (in the future) look up // Contains information needed to resolve types and (in the future) look up
@ -305,7 +305,7 @@ struct ctxt_ {
/// Despite its name, `items` does not only map NodeId to an item but /// Despite its name, `items` does not only map NodeId to an item but
/// also to expr/stmt/local/arg/etc /// also to expr/stmt/local/arg/etc
items: ast_map::map, items: ast_map::Map,
intrinsic_defs: RefCell<HashMap<ast::DefId, t>>, intrinsic_defs: RefCell<HashMap<ast::DefId, t>>,
freevars: RefCell<freevars::freevar_map>, freevars: RefCell<freevars::freevar_map>,
tcache: type_cache, tcache: type_cache,
@ -435,14 +435,14 @@ pub fn type_id(t: t) -> uint { get(t).id }
#[deriving(Clone, Eq, IterBytes)] #[deriving(Clone, Eq, IterBytes)]
pub struct BareFnTy { pub struct BareFnTy {
purity: ast::purity, purity: ast::Purity,
abis: AbiSet, abis: AbiSet,
sig: FnSig sig: FnSig
} }
#[deriving(Clone, Eq, IterBytes)] #[deriving(Clone, Eq, IterBytes)]
pub struct ClosureTy { pub struct ClosureTy {
purity: ast::purity, purity: ast::Purity,
sigil: ast::Sigil, sigil: ast::Sigil,
onceness: ast::Onceness, onceness: ast::Onceness,
region: Region, region: Region,
@ -596,18 +596,18 @@ mod primitives {
def_prim_ty!(TY_NIL, super::ty_nil, 0) def_prim_ty!(TY_NIL, super::ty_nil, 0)
def_prim_ty!(TY_BOOL, super::ty_bool, 1) def_prim_ty!(TY_BOOL, super::ty_bool, 1)
def_prim_ty!(TY_CHAR, super::ty_char, 2) def_prim_ty!(TY_CHAR, super::ty_char, 2)
def_prim_ty!(TY_INT, super::ty_int(ast::ty_i), 3) def_prim_ty!(TY_INT, super::ty_int(ast::TyI), 3)
def_prim_ty!(TY_I8, super::ty_int(ast::ty_i8), 4) def_prim_ty!(TY_I8, super::ty_int(ast::TyI8), 4)
def_prim_ty!(TY_I16, super::ty_int(ast::ty_i16), 5) def_prim_ty!(TY_I16, super::ty_int(ast::TyI16), 5)
def_prim_ty!(TY_I32, super::ty_int(ast::ty_i32), 6) def_prim_ty!(TY_I32, super::ty_int(ast::TyI32), 6)
def_prim_ty!(TY_I64, super::ty_int(ast::ty_i64), 7) def_prim_ty!(TY_I64, super::ty_int(ast::TyI64), 7)
def_prim_ty!(TY_UINT, super::ty_uint(ast::ty_u), 8) def_prim_ty!(TY_UINT, super::ty_uint(ast::TyU), 8)
def_prim_ty!(TY_U8, super::ty_uint(ast::ty_u8), 9) def_prim_ty!(TY_U8, super::ty_uint(ast::TyU8), 9)
def_prim_ty!(TY_U16, super::ty_uint(ast::ty_u16), 10) def_prim_ty!(TY_U16, super::ty_uint(ast::TyU16), 10)
def_prim_ty!(TY_U32, super::ty_uint(ast::ty_u32), 11) def_prim_ty!(TY_U32, super::ty_uint(ast::TyU32), 11)
def_prim_ty!(TY_U64, super::ty_uint(ast::ty_u64), 12) def_prim_ty!(TY_U64, super::ty_uint(ast::TyU64), 12)
def_prim_ty!(TY_F32, super::ty_float(ast::ty_f32), 14) def_prim_ty!(TY_F32, super::ty_float(ast::TyF32), 14)
def_prim_ty!(TY_F64, super::ty_float(ast::ty_f64), 15) def_prim_ty!(TY_F64, super::ty_float(ast::TyF64), 15)
pub static TY_BOT: t_box_ = t_box_ { pub static TY_BOT: t_box_ = t_box_ {
sty: super::ty_bot, sty: super::ty_bot,
@ -632,9 +632,9 @@ pub enum sty {
ty_bot, ty_bot,
ty_bool, ty_bool,
ty_char, ty_char,
ty_int(ast::int_ty), ty_int(ast::IntTy),
ty_uint(ast::uint_ty), ty_uint(ast::UintTy),
ty_float(ast::float_ty), ty_float(ast::FloatTy),
ty_estr(vstore), ty_estr(vstore),
ty_enum(DefId, substs), ty_enum(DefId, substs),
ty_box(t), ty_box(t),
@ -672,8 +672,8 @@ pub struct TraitRef {
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]
pub enum IntVarValue { pub enum IntVarValue {
IntType(ast::int_ty), IntType(ast::IntTy),
UintType(ast::uint_ty), UintType(ast::UintTy),
} }
#[deriving(Clone, ToStr)] #[deriving(Clone, ToStr)]
@ -694,7 +694,7 @@ pub struct expected_found<T> {
#[deriving(Clone, ToStr)] #[deriving(Clone, ToStr)]
pub enum type_err { pub enum type_err {
terr_mismatch, terr_mismatch,
terr_purity_mismatch(expected_found<purity>), terr_purity_mismatch(expected_found<Purity>),
terr_onceness_mismatch(expected_found<Onceness>), terr_onceness_mismatch(expected_found<Onceness>),
terr_abi_mismatch(expected_found<AbiSet>), terr_abi_mismatch(expected_found<AbiSet>),
terr_mutability, terr_mutability,
@ -720,7 +720,7 @@ pub enum type_err {
terr_sorts(expected_found<t>), terr_sorts(expected_found<t>),
terr_integer_as_char, terr_integer_as_char,
terr_int_mismatch(expected_found<IntVarValue>), terr_int_mismatch(expected_found<IntVarValue>),
terr_float_mismatch(expected_found<ast::float_ty>), terr_float_mismatch(expected_found<ast::FloatTy>),
terr_traits(expected_found<ast::DefId>), terr_traits(expected_found<ast::DefId>),
terr_builtin_bounds(expected_found<BuiltinBounds>), terr_builtin_bounds(expected_found<BuiltinBounds>),
terr_variadic_mismatch(expected_found<bool>) terr_variadic_mismatch(expected_found<bool>)
@ -964,7 +964,7 @@ pub type node_type_table = RefCell<HashMap<uint,t>>;
pub fn mk_ctxt(s: session::Session, pub fn mk_ctxt(s: session::Session,
dm: resolve::DefMap, dm: resolve::DefMap,
named_region_map: @RefCell<resolve_lifetime::NamedRegionMap>, named_region_map: @RefCell<resolve_lifetime::NamedRegionMap>,
amap: ast_map::map, amap: ast_map::Map,
freevars: freevars::freevar_map, freevars: freevars::freevar_map,
region_maps: middle::region::RegionMaps, region_maps: middle::region::RegionMaps,
lang_items: middle::lang_items::LanguageItems) lang_items: middle::lang_items::LanguageItems)
@ -1204,30 +1204,30 @@ pub fn mk_u32() -> t { mk_prim_t(&primitives::TY_U32) }
#[inline] #[inline]
pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) } pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) }
pub fn mk_mach_int(tm: ast::int_ty) -> t { pub fn mk_mach_int(tm: ast::IntTy) -> t {
match tm { match tm {
ast::ty_i => mk_int(), ast::TyI => mk_int(),
ast::ty_i8 => mk_i8(), ast::TyI8 => mk_i8(),
ast::ty_i16 => mk_i16(), ast::TyI16 => mk_i16(),
ast::ty_i32 => mk_i32(), ast::TyI32 => mk_i32(),
ast::ty_i64 => mk_i64(), ast::TyI64 => mk_i64(),
} }
} }
pub fn mk_mach_uint(tm: ast::uint_ty) -> t { pub fn mk_mach_uint(tm: ast::UintTy) -> t {
match tm { match tm {
ast::ty_u => mk_uint(), ast::TyU => mk_uint(),
ast::ty_u8 => mk_u8(), ast::TyU8 => mk_u8(),
ast::ty_u16 => mk_u16(), ast::TyU16 => mk_u16(),
ast::ty_u32 => mk_u32(), ast::TyU32 => mk_u32(),
ast::ty_u64 => mk_u64(), ast::TyU64 => mk_u64(),
} }
} }
pub fn mk_mach_float(tm: ast::float_ty) -> t { pub fn mk_mach_float(tm: ast::FloatTy) -> t {
match tm { match tm {
ast::ty_f32 => mk_f32(), ast::TyF32 => mk_f32(),
ast::ty_f64 => mk_f64(), ast::TyF64 => mk_f64(),
} }
} }
@ -1306,7 +1306,7 @@ pub fn mk_ctor_fn(cx: ctxt,
let input_args = input_tys.map(|t| *t); let input_args = input_tys.map(|t| *t);
mk_bare_fn(cx, mk_bare_fn(cx,
BareFnTy { BareFnTy {
purity: ast::impure_fn, purity: ast::ImpureFn,
abis: AbiSet::Rust(), abis: AbiSet::Rust(),
sig: FnSig { sig: FnSig {
binder_id: binder_id, binder_id: binder_id,
@ -1550,7 +1550,7 @@ pub fn type_is_str(ty: t) -> bool {
pub fn sequence_element_type(cx: ctxt, ty: t) -> t { pub fn sequence_element_type(cx: ctxt, ty: t) -> t {
match get(ty).sty { match get(ty).sty {
ty_estr(_) => return mk_mach_uint(ast::ty_u8), ty_estr(_) => return mk_mach_uint(ast::TyU8),
ty_evec(mt, _) | ty_unboxed_vec(mt) => return mt.ty, ty_evec(mt, _) | ty_unboxed_vec(mt) => return mt.ty,
_ => cx.sess.bug("sequence_element_type called on non-sequence value"), _ => cx.sess.bug("sequence_element_type called on non-sequence value"),
} }
@ -2497,7 +2497,7 @@ pub fn type_is_signed(ty: t) -> bool {
pub fn type_is_machine(ty: t) -> bool { pub fn type_is_machine(ty: t) -> bool {
match get(ty).sty { match get(ty).sty {
ty_int(ast::ty_i) | ty_uint(ast::ty_u) => false, ty_int(ast::TyI) | ty_uint(ast::TyU) => false,
ty_int(..) | ty_uint(..) | ty_float(..) => true, ty_int(..) | ty_uint(..) | ty_float(..) => true,
_ => false _ => false
} }
@ -2735,7 +2735,7 @@ pub fn ty_closure_sigil(fty: t) -> Sigil {
} }
} }
pub fn ty_fn_purity(fty: t) -> ast::purity { pub fn ty_fn_purity(fty: t) -> ast::Purity {
match get(fty).sty { match get(fty).sty {
ty_bare_fn(ref f) => f.purity, ty_bare_fn(ref f) => f.purity,
ty_closure(ref f) => f.purity, ty_closure(ref f) => f.purity,
@ -3184,7 +3184,7 @@ pub fn expr_kind(tcx: ctxt,
ast::ExprDoBody(..) | ast::ExprDoBody(..) |
ast::ExprBlock(..) | ast::ExprBlock(..) |
ast::ExprRepeat(..) | ast::ExprRepeat(..) |
ast::ExprLit(@codemap::Spanned {node: lit_str(..), ..}) | ast::ExprLit(@codemap::Spanned {node: LitStr(..), ..}) |
ast::ExprVstore(_, ast::ExprVstoreSlice) | ast::ExprVstore(_, ast::ExprVstoreSlice) |
ast::ExprVstore(_, ast::ExprVstoreMutSlice) | ast::ExprVstore(_, ast::ExprVstoreMutSlice) |
ast::ExprVec(..) => { ast::ExprVec(..) => {
@ -3232,7 +3232,7 @@ pub fn expr_kind(tcx: ctxt,
ast::ExprForLoop(..) => fail!("non-desugared expr_for_loop"), ast::ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
ast::ExprLogLevel | ast::ExprLogLevel |
ast::ExprLit(_) | // Note: lit_str is carved out above ast::ExprLit(_) | // Note: LitStr is carved out above
ast::ExprUnary(..) | ast::ExprUnary(..) |
ast::ExprAddrOf(..) | ast::ExprAddrOf(..) |
ast::ExprBinary(..) | ast::ExprBinary(..) |
@ -3551,8 +3551,8 @@ pub fn provided_trait_methods(cx: ctxt, id: ast::DefId) -> ~[@Method] {
{ {
let items = cx.items.borrow(); let items = cx.items.borrow();
match items.get().find(&id.node) { match items.get().find(&id.node) {
Some(&ast_map::node_item(@ast::item { Some(&ast_map::NodeItem(@ast::Item {
node: item_trait(_, _, ref ms), node: ItemTrait(_, _, ref ms),
.. ..
}, _)) => }, _)) =>
match ast_util::split_trait_methods(*ms) { match ast_util::split_trait_methods(*ms) {
@ -3673,8 +3673,8 @@ pub fn impl_trait_ref(cx: ctxt, id: ast::DefId) -> Option<@TraitRef> {
{ {
let items = cx.items.borrow(); let items = cx.items.borrow();
match items.get().find(&id.node) { match items.get().find(&id.node) {
Some(&ast_map::node_item(@ast::item { Some(&ast_map::NodeItem(@ast::Item {
node: ast::item_impl(_, ref opt_trait, _, _), node: ast::ItemImpl(_, ref opt_trait, _, _),
..}, ..},
_)) => { _)) => {
match opt_trait { match opt_trait {
@ -3694,7 +3694,7 @@ pub fn impl_trait_ref(cx: ctxt, id: ast::DefId) -> Option<@TraitRef> {
return ret; return ret;
} }
pub fn trait_ref_to_def_id(tcx: ctxt, tr: &ast::trait_ref) -> ast::DefId { pub fn trait_ref_to_def_id(tcx: ctxt, tr: &ast::TraitRef) -> ast::DefId {
let def_map = tcx.def_map.borrow(); let def_map = tcx.def_map.borrow();
let def = def_map.get() let def = def_map.get()
.find(&tr.ref_id) .find(&tr.ref_id)
@ -3732,7 +3732,7 @@ pub struct VariantInfo {
name: ast::Ident, name: ast::Ident,
id: ast::DefId, id: ast::DefId,
disr_val: Disr, disr_val: Disr,
vis: visibility vis: Visibility
} }
impl VariantInfo { impl VariantInfo {
@ -3741,12 +3741,12 @@ impl VariantInfo {
/// ///
/// Does not do any caching of the value in the type context. /// Does not do any caching of the value in the type context.
pub fn from_ast_variant(cx: ctxt, pub fn from_ast_variant(cx: ctxt,
ast_variant: &ast::variant, ast_variant: &ast::Variant,
discriminant: Disr) -> VariantInfo { discriminant: Disr) -> VariantInfo {
let ctor_ty = node_id_to_type(cx, ast_variant.node.id); let ctor_ty = node_id_to_type(cx, ast_variant.node.id);
match ast_variant.node.kind { match ast_variant.node.kind {
ast::tuple_variant_kind(ref args) => { ast::TupleVariantKind(ref args) => {
let arg_tys = if args.len() > 0 { ty_fn_args(ctor_ty).map(|a| *a) } else { ~[] }; let arg_tys = if args.len() > 0 { ty_fn_args(ctor_ty).map(|a| *a) } else { ~[] };
return VariantInfo { return VariantInfo {
@ -3759,17 +3759,17 @@ impl VariantInfo {
vis: ast_variant.node.vis vis: ast_variant.node.vis
}; };
}, },
ast::struct_variant_kind(ref struct_def) => { ast::StructVariantKind(ref struct_def) => {
let fields: &[struct_field] = struct_def.fields; let fields: &[StructField] = struct_def.fields;
assert!(fields.len() > 0); assert!(fields.len() > 0);
let arg_tys = ty_fn_args(ctor_ty).map(|a| *a); let arg_tys = ty_fn_args(ctor_ty).map(|a| *a);
let arg_names = fields.map(|field| { let arg_names = fields.map(|field| {
match field.node.kind { match field.node.kind {
named_field(ident, _) => ident, NamedField(ident, _) => ident,
unnamed_field => cx.sess.bug( UnnamedField => cx.sess.bug(
"enum_variants: all fields in struct must have a name") "enum_variants: all fields in struct must have a name")
} }
}); });
@ -3853,7 +3853,7 @@ pub fn has_dtor(cx: ctxt, struct_id: DefId) -> bool {
ty_dtor(cx, struct_id).is_present() ty_dtor(cx, struct_id).is_present()
} }
pub fn item_path(cx: ctxt, id: ast::DefId) -> ast_map::path { pub fn item_path(cx: ctxt, id: ast::DefId) -> ast_map::Path {
if id.crate != ast::LOCAL_CRATE { if id.crate != ast::LOCAL_CRATE {
return csearch::get_item_path(cx, id) return csearch::get_item_path(cx, id)
} }
@ -3865,45 +3865,43 @@ pub fn item_path(cx: ctxt, id: ast::DefId) -> ast_map::path {
// match *node { // match *node {
let items = cx.items.borrow(); let items = cx.items.borrow();
match *items.get().get(&id.node) { match *items.get().get(&id.node) {
ast_map::node_item(item, path) => { ast_map::NodeItem(item, path) => {
let item_elt = match item.node { let item_elt = match item.node {
item_mod(_) | item_foreign_mod(_) => { ItemMod(_) | ItemForeignMod(_) => {
ast_map::path_mod(item.ident) ast_map::PathMod(item.ident)
} }
_ => { _ => ast_map::PathName(item.ident)
ast_map::path_name(item.ident) };
} vec::append_one((*path).clone(), item_elt)
}; }
vec::append_one((*path).clone(), item_elt)
}
ast_map::node_foreign_item(nitem, _, _, path) => { ast_map::NodeForeignItem(nitem, _, _, path) => {
vec::append_one((*path).clone(), vec::append_one((*path).clone(),
ast_map::path_name(nitem.ident)) ast_map::PathName(nitem.ident))
} }
ast_map::node_method(method, _, path) => { ast_map::NodeMethod(method, _, path) => {
vec::append_one((*path).clone(), vec::append_one((*path).clone(),
ast_map::path_name(method.ident)) ast_map::PathName(method.ident))
} }
ast_map::node_trait_method(trait_method, _, path) => { ast_map::NodeTraitMethod(trait_method, _, path) => {
let method = ast_util::trait_method_to_ty_method(&*trait_method); let method = ast_util::trait_method_to_ty_method(&*trait_method);
vec::append_one((*path).clone(), vec::append_one((*path).clone(),
ast_map::path_name(method.ident)) ast_map::PathName(method.ident))
} }
ast_map::node_variant(ref variant, _, path) => { ast_map::NodeVariant(ref variant, _, path) => {
vec::append_one(path.init().to_owned(), vec::append_one(path.init().to_owned(),
ast_map::path_name((*variant).node.name)) ast_map::PathName((*variant).node.name))
} }
ast_map::node_struct_ctor(_, item, path) => { ast_map::NodeStructCtor(_, item, path) => {
vec::append_one((*path).clone(), ast_map::path_name(item.ident)) vec::append_one((*path).clone(), ast_map::PathName(item.ident))
} }
ref node => { ref node => {
cx.sess.bug(format!("cannot find item_path for node {:?}", node)); cx.sess.bug(format!("cannot find item_path for node {:?}", node));
} }
} }
} }
@ -3938,8 +3936,8 @@ pub fn enum_variants(cx: ctxt, id: ast::DefId) -> @~[@VariantInfo] {
{ {
let items = cx.items.borrow(); let items = cx.items.borrow();
match items.get().get_copy(&id.node) { match items.get().get_copy(&id.node) {
ast_map::node_item(@ast::item { ast_map::NodeItem(@ast::Item {
node: ast::item_enum(ref enum_definition, _), node: ast::ItemEnum(ref enum_definition, _),
.. ..
}, _) => { }, _) => {
let mut last_discriminant: Option<Disr> = None; let mut last_discriminant: Option<Disr> = None;
@ -4045,7 +4043,7 @@ pub fn each_attr(tcx: ctxt, did: DefId, f: |@MetaItem| -> bool) -> bool {
{ {
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&did.node) { match items.get().find(&did.node) {
Some(&ast_map::node_item(@ast::item { Some(&ast_map::NodeItem(@ast::Item {
attrs: ref attrs, attrs: ref attrs,
.. ..
}, _)) => }, _)) =>
@ -4131,17 +4129,17 @@ pub fn lookup_struct_fields(cx: ctxt, did: ast::DefId) -> ~[field_ty] {
{ {
let items = cx.items.borrow(); let items = cx.items.borrow();
match items.get().find(&did.node) { match items.get().find(&did.node) {
Some(&ast_map::node_item(i,_)) => { Some(&ast_map::NodeItem(i,_)) => {
match i.node { match i.node {
ast::item_struct(struct_def, _) => { ast::ItemStruct(struct_def, _) => {
struct_field_tys(struct_def.fields) struct_field_tys(struct_def.fields)
} }
_ => cx.sess.bug("struct ID bound to non-struct") _ => cx.sess.bug("struct ID bound to non-struct")
} }
} }
Some(&ast_map::node_variant(ref variant, _, _)) => { Some(&ast_map::NodeVariant(ref variant, _, _)) => {
match (*variant).node.kind { match (*variant).node.kind {
ast::struct_variant_kind(struct_def) => { ast::StructVariantKind(struct_def) => {
struct_field_tys(struct_def.fields) struct_field_tys(struct_def.fields)
} }
_ => { _ => {
@ -4175,22 +4173,22 @@ pub fn lookup_struct_field(cx: ctxt,
} }
} }
fn struct_field_tys(fields: &[struct_field]) -> ~[field_ty] { fn struct_field_tys(fields: &[StructField]) -> ~[field_ty] {
fields.map(|field| { fields.map(|field| {
match field.node.kind { match field.node.kind {
named_field(ident, visibility) => { NamedField(ident, visibility) => {
field_ty { field_ty {
name: ident.name, name: ident.name,
id: ast_util::local_def(field.node.id), id: ast_util::local_def(field.node.id),
vis: visibility, vis: visibility,
} }
} }
unnamed_field => { UnnamedField => {
field_ty { field_ty {
name: name:
syntax::parse::token::special_idents::unnamed_field.name, syntax::parse::token::special_idents::unnamed_field.name,
id: ast_util::local_def(field.node.id), id: ast_util::local_def(field.node.id),
vis: ast::public, vis: ast::Public,
} }
} }
} }
@ -4417,15 +4415,15 @@ pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::Expr) ->
} }
// Determine what purity to check a nested function under // Determine what purity to check a nested function under
pub fn determine_inherited_purity(parent: (ast::purity, ast::NodeId), pub fn determine_inherited_purity(parent: (ast::Purity, ast::NodeId),
child: (ast::purity, ast::NodeId), child: (ast::Purity, ast::NodeId),
child_sigil: ast::Sigil) child_sigil: ast::Sigil)
-> (ast::purity, ast::NodeId) { -> (ast::Purity, ast::NodeId) {
// If the closure is a stack closure and hasn't had some non-standard // If the closure is a stack closure and hasn't had some non-standard
// purity inferred for it, then check it under its parent's purity. // purity inferred for it, then check it under its parent's purity.
// Otherwise, use its own // Otherwise, use its own
match child_sigil { match child_sigil {
ast::BorrowedSigil if child.first() == ast::impure_fn => parent, ast::BorrowedSigil if child.first() == ast::ImpureFn => parent,
_ => child _ => child
} }
} }
@ -4674,9 +4672,9 @@ pub fn trait_id_of_impl(tcx: ctxt,
None => return None None => return None
}; };
match node { match node {
&ast_map::node_item(item, _) => { &ast_map::NodeItem(item, _) => {
match item.node { match item.node {
ast::item_impl(_, Some(ref trait_ref), _, _) => { ast::ItemImpl(_, Some(ref trait_ref), _, _) => {
Some(node_id_to_trait_ref(tcx, trait_ref.ref_id).def_id) Some(node_id_to_trait_ref(tcx, trait_ref.ref_id).def_id)
} }
_ => None _ => None

View file

@ -288,7 +288,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
} }
fn ast_mt_to_mt<AC:AstConv, RS:RegionScope>( fn ast_mt_to_mt<AC:AstConv, RS:RegionScope>(
this: &AC, rscope: &RS, mt: &ast::mt) -> ty::mt { this: &AC, rscope: &RS, mt: &ast::MutTy) -> ty::mt {
ty::mt {ty: ast_ty_to_ty(this, rscope, mt.ty), mutbl: mt.mutbl} ty::mt {ty: ast_ty_to_ty(this, rscope, mt.ty), mutbl: mt.mutbl}
} }
@ -300,7 +300,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
RS:RegionScope>( RS:RegionScope>(
this: &AC, this: &AC,
rscope: &RS, rscope: &RS,
a_seq_ty: &ast::mt, a_seq_ty: &ast::MutTy,
vst: ty::vstore, vst: ty::vstore,
constr: |ty::mt| -> ty::t) constr: |ty::mt| -> ty::t)
-> ty::t { -> ty::t {
@ -308,7 +308,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
debug!("mk_pointer(vst={:?})", vst); debug!("mk_pointer(vst={:?})", vst);
match a_seq_ty.ty.node { match a_seq_ty.ty.node {
ast::ty_vec(ty) => { ast::TyVec(ty) => {
let mut mt = ast_ty_to_mt(this, rscope, ty); let mut mt = ast_ty_to_mt(this, rscope, ty);
if a_seq_ty.mutbl == ast::MutMutable { if a_seq_ty.mutbl == ast::MutMutable {
mt = ty::mt { ty: mt.ty, mutbl: a_seq_ty.mutbl }; mt = ty::mt { ty: mt.ty, mutbl: a_seq_ty.mutbl };
@ -316,13 +316,13 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
debug!("&[]: vst={:?}", vst); debug!("&[]: vst={:?}", vst);
return ty::mk_evec(tcx, mt, vst); return ty::mk_evec(tcx, mt, vst);
} }
ast::ty_path(ref path, ref bounds, id) => { ast::TyPath(ref path, ref bounds, id) => {
// Note that the "bounds must be empty if path is not a trait" // Note that the "bounds must be empty if path is not a trait"
// restriction is enforced in the below case for ty_path, which // restriction is enforced in the below case for ty_path, which
// will run after this as long as the path isn't a trait. // will run after this as long as the path isn't a trait.
let def_map = tcx.def_map.borrow(); let def_map = tcx.def_map.borrow();
match def_map.get().find(&id) { match def_map.get().find(&id) {
Some(&ast::DefPrimTy(ast::ty_str)) if a_seq_ty.mutbl == ast::MutImmutable => { Some(&ast::DefPrimTy(ast::TyStr)) if a_seq_ty.mutbl == ast::MutImmutable => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS); check_path_args(tcx, path, NO_TPS | NO_REGIONS);
return ty::mk_estr(tcx, vst); return ty::mk_estr(tcx, vst);
} }
@ -400,44 +400,44 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
let typ = match ast_ty.node { let typ = match ast_ty.node {
ast::ty_nil => ty::mk_nil(), ast::TyNil => ty::mk_nil(),
ast::ty_bot => ty::mk_bot(), ast::TyBot => ty::mk_bot(),
ast::ty_box(ty) => { ast::TyBox(ty) => {
let mt = ast::mt { ty: ty, mutbl: ast::MutImmutable }; let mt = ast::MutTy { ty: ty, mutbl: ast::MutImmutable };
mk_pointer(this, rscope, &mt, ty::vstore_box, mk_pointer(this, rscope, &mt, ty::vstore_box,
|tmt| ty::mk_box(tcx, tmt.ty)) |tmt| ty::mk_box(tcx, tmt.ty))
} }
ast::ty_uniq(ty) => { ast::TyUniq(ty) => {
let mt = ast::mt { ty: ty, mutbl: ast::MutImmutable }; let mt = ast::MutTy { ty: ty, mutbl: ast::MutImmutable };
mk_pointer(this, rscope, &mt, ty::vstore_uniq, mk_pointer(this, rscope, &mt, ty::vstore_uniq,
|tmt| ty::mk_uniq(tcx, tmt)) |tmt| ty::mk_uniq(tcx, tmt))
} }
ast::ty_vec(ty) => { ast::TyVec(ty) => {
tcx.sess.span_err(ast_ty.span, "bare `[]` is not a type"); tcx.sess.span_err(ast_ty.span, "bare `[]` is not a type");
// return /something/ so they can at least get more errors // return /something/ so they can at least get more errors
ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty), ty::vstore_uniq) ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty), ty::vstore_uniq)
} }
ast::ty_ptr(ref mt) => { ast::TyPtr(ref mt) => {
ty::mk_ptr(tcx, ast_mt_to_mt(this, rscope, mt)) ty::mk_ptr(tcx, ast_mt_to_mt(this, rscope, mt))
} }
ast::ty_rptr(ref region, ref mt) => { ast::TyRptr(ref region, ref mt) => {
let r = opt_ast_region_to_region(this, rscope, ast_ty.span, region); let r = opt_ast_region_to_region(this, rscope, ast_ty.span, region);
debug!("ty_rptr r={}", r.repr(this.tcx())); debug!("ty_rptr r={}", r.repr(this.tcx()));
mk_pointer(this, rscope, mt, ty::vstore_slice(r), mk_pointer(this, rscope, mt, ty::vstore_slice(r),
|tmt| ty::mk_rptr(tcx, r, tmt)) |tmt| ty::mk_rptr(tcx, r, tmt))
} }
ast::ty_tup(ref fields) => { ast::TyTup(ref fields) => {
let flds = fields.map(|&t| ast_ty_to_ty(this, rscope, t)); let flds = fields.map(|&t| ast_ty_to_ty(this, rscope, t));
ty::mk_tup(tcx, flds) ty::mk_tup(tcx, flds)
} }
ast::ty_bare_fn(ref bf) => { ast::TyBareFn(ref bf) => {
if bf.decl.variadic && !bf.abis.is_c() { if bf.decl.variadic && !bf.abis.is_c() {
tcx.sess.span_err(ast_ty.span, "variadic function must have C calling convention"); tcx.sess.span_err(ast_ty.span, "variadic function must have C calling convention");
} }
ty::mk_bare_fn(tcx, ty_of_bare_fn(this, ast_ty.id, bf.purity, ty::mk_bare_fn(tcx, ty_of_bare_fn(this, ast_ty.id, bf.purity,
bf.abis, bf.decl)) bf.abis, bf.decl))
} }
ast::ty_closure(ref f) => { ast::TyClosure(ref f) => {
if f.sigil == ast::ManagedSigil { if f.sigil == ast::ManagedSigil {
tcx.sess.span_err(ast_ty.span, tcx.sess.span_err(ast_ty.span,
"managed closures are not supported"); "managed closures are not supported");
@ -463,7 +463,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
ast_ty.span); ast_ty.span);
ty::mk_closure(tcx, fn_decl) ty::mk_closure(tcx, fn_decl)
} }
ast::ty_path(ref path, ref bounds, id) => { ast::TyPath(ref path, ref bounds, id) => {
let def_map = tcx.def_map.borrow(); let def_map = tcx.def_map.borrow();
let a_def = match def_map.get().find(&id) { let a_def = match def_map.get().find(&id) {
None => tcx.sess.span_fatal( None => tcx.sess.span_fatal(
@ -495,27 +495,27 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
} }
ast::DefPrimTy(nty) => { ast::DefPrimTy(nty) => {
match nty { match nty {
ast::ty_bool => { ast::TyBool => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS); check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_bool() ty::mk_bool()
} }
ast::ty_char => { ast::TyChar => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS); check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_char() ty::mk_char()
} }
ast::ty_int(it) => { ast::TyInt(it) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS); check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_mach_int(it) ty::mk_mach_int(it)
} }
ast::ty_uint(uit) => { ast::TyUint(uit) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS); check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_mach_uint(uit) ty::mk_mach_uint(uit)
} }
ast::ty_float(ft) => { ast::TyFloat(ft) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS); check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_mach_float(ft) ty::mk_mach_float(ft)
} }
ast::ty_str => { ast::TyStr => {
tcx.sess.span_err(ast_ty.span, tcx.sess.span_err(ast_ty.span,
"bare `str` is not a type"); "bare `str` is not a type");
// return /something/ so they can at least get more errors // return /something/ so they can at least get more errors
@ -547,7 +547,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
} }
} }
} }
ast::ty_fixed_length_vec(ty, e) => { ast::TyFixedLengthVec(ty, e) => {
match const_eval::eval_const_expr_partial(&tcx, e) { match const_eval::eval_const_expr_partial(&tcx, e) {
Ok(ref r) => { Ok(ref r) => {
match *r { match *r {
@ -570,10 +570,10 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
} }
} }
} }
ast::ty_typeof(_e) => { ast::TyTypeof(_e) => {
tcx.sess.span_bug(ast_ty.span, "typeof is reserved but unimplemented"); tcx.sess.span_bug(ast_ty.span, "typeof is reserved but unimplemented");
} }
ast::ty_infer => { ast::TyInfer => {
// ty_infer should only appear as the type of arguments or return // ty_infer should only appear as the type of arguments or return
// values in a fn_expr, or as the type of local variables. Both of // values in a fn_expr, or as the type of local variables. Both of
// these cases are handled specially and should not descend into this // these cases are handled specially and should not descend into this
@ -593,28 +593,28 @@ pub fn ty_of_arg<AC:AstConv,
RS:RegionScope>( RS:RegionScope>(
this: &AC, this: &AC,
rscope: &RS, rscope: &RS,
a: &ast::arg, a: &ast::Arg,
expected_ty: Option<ty::t>) expected_ty: Option<ty::t>)
-> ty::t { -> ty::t {
match a.ty.node { match a.ty.node {
ast::ty_infer if expected_ty.is_some() => expected_ty.unwrap(), ast::TyInfer if expected_ty.is_some() => expected_ty.unwrap(),
ast::ty_infer => this.ty_infer(a.ty.span), ast::TyInfer => this.ty_infer(a.ty.span),
_ => ast_ty_to_ty(this, rscope, a.ty), _ => ast_ty_to_ty(this, rscope, a.ty),
} }
} }
struct SelfInfo { struct SelfInfo {
untransformed_self_ty: ty::t, untransformed_self_ty: ty::t,
explicit_self: ast::explicit_self explicit_self: ast::ExplicitSelf
} }
pub fn ty_of_method<AC:AstConv>( pub fn ty_of_method<AC:AstConv>(
this: &AC, this: &AC,
id: ast::NodeId, id: ast::NodeId,
purity: ast::purity, purity: ast::Purity,
untransformed_self_ty: ty::t, untransformed_self_ty: ty::t,
explicit_self: ast::explicit_self, explicit_self: ast::ExplicitSelf,
decl: &ast::fn_decl) -> (Option<ty::t>, ty::BareFnTy) decl: &ast::FnDecl) -> (Option<ty::t>, ty::BareFnTy)
{ {
let self_info = SelfInfo { let self_info = SelfInfo {
untransformed_self_ty: untransformed_self_ty, untransformed_self_ty: untransformed_self_ty,
@ -628,9 +628,9 @@ pub fn ty_of_method<AC:AstConv>(
pub fn ty_of_bare_fn<AC:AstConv>( pub fn ty_of_bare_fn<AC:AstConv>(
this: &AC, this: &AC,
id: ast::NodeId, id: ast::NodeId,
purity: ast::purity, purity: ast::Purity,
abi: AbiSet, abi: AbiSet,
decl: &ast::fn_decl) -> ty::BareFnTy decl: &ast::FnDecl) -> ty::BareFnTy
{ {
let (_, b) = ty_of_method_or_bare_fn(this, id, purity, let (_, b) = ty_of_method_or_bare_fn(this, id, purity,
abi, None, decl); abi, None, decl);
@ -640,10 +640,10 @@ pub fn ty_of_bare_fn<AC:AstConv>(
fn ty_of_method_or_bare_fn<AC:AstConv>( fn ty_of_method_or_bare_fn<AC:AstConv>(
this: &AC, this: &AC,
id: ast::NodeId, id: ast::NodeId,
purity: ast::purity, purity: ast::Purity,
abi: AbiSet, abi: AbiSet,
opt_self_info: Option<&SelfInfo>, opt_self_info: Option<&SelfInfo>,
decl: &ast::fn_decl) -> (Option<Option<ty::t>>, ty::BareFnTy) decl: &ast::FnDecl) -> (Option<Option<ty::t>>, ty::BareFnTy)
{ {
debug!("ty_of_method_or_bare_fn"); debug!("ty_of_method_or_bare_fn");
@ -658,7 +658,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv>(
let input_tys = decl.inputs.map(|a| ty_of_arg(this, &rb, a, None)); let input_tys = decl.inputs.map(|a| ty_of_arg(this, &rb, a, None));
let output_ty = match decl.output.node { let output_ty = match decl.output.node {
ast::ty_infer => this.ty_infer(decl.output.span), ast::TyInfer => this.ty_infer(decl.output.span),
_ => ast_ty_to_ty(this, &rb, decl.output) _ => ast_ty_to_ty(this, &rb, decl.output)
}; };
@ -678,11 +678,11 @@ fn ty_of_method_or_bare_fn<AC:AstConv>(
self_info: &SelfInfo) -> Option<ty::t> self_info: &SelfInfo) -> Option<ty::t>
{ {
match self_info.explicit_self.node { match self_info.explicit_self.node {
ast::sty_static => None, ast::SelfStatic => None,
ast::sty_value(_) => { ast::SelfValue(_) => {
Some(self_info.untransformed_self_ty) Some(self_info.untransformed_self_ty)
} }
ast::sty_region(ref lifetime, mutability) => { ast::SelfRegion(ref lifetime, mutability) => {
let region = let region =
opt_ast_region_to_region(this, rscope, opt_ast_region_to_region(this, rscope,
self_info.explicit_self.span, self_info.explicit_self.span,
@ -691,10 +691,10 @@ fn ty_of_method_or_bare_fn<AC:AstConv>(
ty::mt {ty: self_info.untransformed_self_ty, ty::mt {ty: self_info.untransformed_self_ty,
mutbl: mutability})) mutbl: mutability}))
} }
ast::sty_box(_) => { ast::SelfBox(_) => {
Some(ty::mk_box(this.tcx(), self_info.untransformed_self_ty)) Some(ty::mk_box(this.tcx(), self_info.untransformed_self_ty))
} }
ast::sty_uniq(_) => { ast::SelfUniq(_) => {
Some(ty::mk_uniq(this.tcx(), Some(ty::mk_uniq(this.tcx(),
ty::mt {ty: self_info.untransformed_self_ty, ty::mt {ty: self_info.untransformed_self_ty,
mutbl: ast::MutImmutable})) mutbl: ast::MutImmutable}))
@ -708,11 +708,11 @@ pub fn ty_of_closure<AC:AstConv,RS:RegionScope>(
rscope: &RS, rscope: &RS,
id: ast::NodeId, id: ast::NodeId,
sigil: ast::Sigil, sigil: ast::Sigil,
purity: ast::purity, purity: ast::Purity,
onceness: ast::Onceness, onceness: ast::Onceness,
bounds: ty::BuiltinBounds, bounds: ty::BuiltinBounds,
opt_lifetime: &Option<ast::Lifetime>, opt_lifetime: &Option<ast::Lifetime>,
decl: &ast::fn_decl, decl: &ast::FnDecl,
expected_sig: Option<ty::FnSig>, expected_sig: Option<ty::FnSig>,
span: Span) span: Span)
-> ty::ClosureTy -> ty::ClosureTy
@ -755,8 +755,8 @@ pub fn ty_of_closure<AC:AstConv,RS:RegionScope>(
let expected_ret_ty = expected_sig.map(|e| e.output); let expected_ret_ty = expected_sig.map(|e| e.output);
let output_ty = match decl.output.node { let output_ty = match decl.output.node {
ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.unwrap(), ast::TyInfer if expected_ret_ty.is_some() => expected_ret_ty.unwrap(),
ast::ty_infer => this.ty_infer(decl.output.span), ast::TyInfer => this.ty_infer(decl.output.span),
_ => ast_ty_to_ty(this, &rb, decl.output) _ => ast_ty_to_ty(this, &rb, decl.output)
}; };

View file

@ -100,8 +100,8 @@ use std::cell::RefCell;
use std::hashmap::HashSet; use std::hashmap::HashSet;
use std::result; use std::result;
use std::vec; use std::vec;
use syntax::ast::{DefId, sty_value, sty_region, sty_box}; use syntax::ast::{DefId, SelfValue, SelfRegion, SelfBox};
use syntax::ast::{sty_uniq, sty_static, NodeId}; use syntax::ast::{SelfUniq, SelfStatic, NodeId};
use syntax::ast::{MutMutable, MutImmutable}; use syntax::ast::{MutMutable, MutImmutable};
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
@ -505,7 +505,7 @@ impl<'a> LookupContext<'a> {
let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id); let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id);
match trait_methods.iter().position(|m| { match trait_methods.iter().position(|m| {
m.explicit_self != ast::sty_static && m.explicit_self != ast::SelfStatic &&
m.ident.name == self.m_name }) m.ident.name == self.m_name })
{ {
Some(pos) => { Some(pos) => {
@ -944,7 +944,7 @@ impl<'a> LookupContext<'a> {
self.enforce_drop_trait_limitations(candidate); self.enforce_drop_trait_limitations(candidate);
// static methods should never have gotten this far: // static methods should never have gotten this far:
assert!(candidate.method_ty.explicit_self != sty_static); assert!(candidate.method_ty.explicit_self != SelfStatic);
let transformed_self_ty = match candidate.origin { let transformed_self_ty = match candidate.origin {
method_object(..) => { method_object(..) => {
@ -1078,27 +1078,27 @@ impl<'a> LookupContext<'a> {
self_ty: None, self_ty: None,
tps: rcvr_substs.tps.clone()}; tps: rcvr_substs.tps.clone()};
match method_ty.explicit_self { match method_ty.explicit_self {
ast::sty_static => { ast::SelfStatic => {
self.bug(~"static method for object type receiver"); self.bug(~"static method for object type receiver");
} }
ast::sty_value(_) => { ast::SelfValue(_) => {
ty::mk_err() // error reported in `enforce_object_limitations()` ty::mk_err() // error reported in `enforce_object_limitations()`
} }
ast::sty_region(..) | ast::sty_box(..) | ast::sty_uniq(..) => { ast::SelfRegion(..) | ast::SelfBox(..) | ast::SelfUniq(..) => {
let transformed_self_ty = let transformed_self_ty =
method_ty.transformed_self_ty.clone().unwrap(); method_ty.transformed_self_ty.clone().unwrap();
match ty::get(transformed_self_ty).sty { match ty::get(transformed_self_ty).sty {
ty::ty_rptr(r, mt) => { // must be sty_region ty::ty_rptr(r, mt) => { // must be SelfRegion
ty::mk_trait(self.tcx(), trait_def_id, ty::mk_trait(self.tcx(), trait_def_id,
substs, RegionTraitStore(r), mt.mutbl, substs, RegionTraitStore(r), mt.mutbl,
ty::EmptyBuiltinBounds()) ty::EmptyBuiltinBounds())
} }
ty::ty_box(_) => { // must be sty_box ty::ty_box(_) => { // must be SelfBox
ty::mk_trait(self.tcx(), trait_def_id, ty::mk_trait(self.tcx(), trait_def_id,
substs, BoxTraitStore, ast::MutImmutable, substs, BoxTraitStore, ast::MutImmutable,
ty::EmptyBuiltinBounds()) ty::EmptyBuiltinBounds())
} }
ty::ty_uniq(mt) => { // must be sty_uniq ty::ty_uniq(mt) => { // must be SelfUniq
ty::mk_trait(self.tcx(), trait_def_id, ty::mk_trait(self.tcx(), trait_def_id,
substs, UniqTraitStore, mt.mutbl, substs, UniqTraitStore, mt.mutbl,
ty::EmptyBuiltinBounds()) ty::EmptyBuiltinBounds())
@ -1133,21 +1133,21 @@ impl<'a> LookupContext<'a> {
} }
match candidate.method_ty.explicit_self { match candidate.method_ty.explicit_self {
ast::sty_static => { // reason (a) above ast::SelfStatic => { // reason (a) above
self.tcx().sess.span_err( self.tcx().sess.span_err(
self.expr.span, self.expr.span,
"cannot call a method without a receiver \ "cannot call a method without a receiver \
through an object"); through an object");
} }
ast::sty_value(_) => { // reason (a) above ast::SelfValue(_) => { // reason (a) above
self.tcx().sess.span_err( self.tcx().sess.span_err(
self.expr.span, self.expr.span,
"cannot call a method with a by-value receiver \ "cannot call a method with a by-value receiver \
through an object"); through an object");
} }
ast::sty_region(..) | ast::sty_box(..) | ast::sty_uniq(..) => {} ast::SelfRegion(..) | ast::SelfBox(..) | ast::SelfUniq(..) => {}
} }
if ty::type_has_self(method_fty) { // reason (a) above if ty::type_has_self(method_fty) { // reason (a) above
@ -1196,16 +1196,16 @@ impl<'a> LookupContext<'a> {
self.ty_to_str(rcvr_ty), self.cand_to_str(candidate)); self.ty_to_str(rcvr_ty), self.cand_to_str(candidate));
return match candidate.method_ty.explicit_self { return match candidate.method_ty.explicit_self {
sty_static => { SelfStatic => {
debug!("(is relevant?) explicit self is static"); debug!("(is relevant?) explicit self is static");
false false
} }
sty_value(_) => { SelfValue(_) => {
rcvr_matches_ty(self.fcx, rcvr_ty, candidate) rcvr_matches_ty(self.fcx, rcvr_ty, candidate)
} }
sty_region(_, m) => { SelfRegion(_, m) => {
debug!("(is relevant?) explicit self is a region"); debug!("(is relevant?) explicit self is a region");
match ty::get(rcvr_ty).sty { match ty::get(rcvr_ty).sty {
ty::ty_rptr(_, mt) => { ty::ty_rptr(_, mt) => {
@ -1222,7 +1222,7 @@ impl<'a> LookupContext<'a> {
} }
} }
sty_box(m) => { SelfBox(m) => {
debug!("(is relevant?) explicit self is a box"); debug!("(is relevant?) explicit self is a box");
match ty::get(rcvr_ty).sty { match ty::get(rcvr_ty).sty {
ty::ty_box(typ) => { ty::ty_box(typ) => {
@ -1238,7 +1238,7 @@ impl<'a> LookupContext<'a> {
} }
} }
sty_uniq(_) => { SelfUniq(_) => {
debug!("(is relevant?) explicit self is a unique pointer"); debug!("(is relevant?) explicit self is a unique pointer");
match ty::get(rcvr_ty).sty { match ty::get(rcvr_ty).sty {
ty::ty_uniq(mt) => { ty::ty_uniq(mt) => {
@ -1312,10 +1312,9 @@ impl<'a> LookupContext<'a> {
{ {
let items = self.tcx().items.borrow(); let items = self.tcx().items.borrow();
match items.get().find(&did.node) { match items.get().find(&did.node) {
Some(&ast_map::node_method(m, _, _)) Some(&ast_map::NodeMethod(m, _, _))
| Some(&ast_map::node_trait_method(@ast::provided(m), | Some(&ast_map::NodeTraitMethod(@ast::Provided(m),
_, _, _)) => {
_)) => {
m.span m.span
} }
_ => fail!("report_static_candidate: bad item {:?}", did) _ => fail!("report_static_candidate: bad item {:?}", did)
@ -1376,9 +1375,9 @@ impl<'a> LookupContext<'a> {
} }
} }
pub fn get_mode_from_explicit_self(explicit_self: ast::explicit_self_) -> SelfMode { pub fn get_mode_from_explicit_self(explicit_self: ast::ExplicitSelf_) -> SelfMode {
match explicit_self { match explicit_self {
sty_value(_) => ty::ByRef, SelfValue(_) => ty::ByRef,
_ => ty::ByCopy, _ => ty::ByCopy,
} }
} }

View file

@ -116,7 +116,7 @@ use std::result;
use std::util::replace; use std::util::replace;
use std::vec; use std::vec;
use syntax::abi::AbiSet; use syntax::abi::AbiSet;
use syntax::ast::{provided, required}; use syntax::ast::{Provided, Required};
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_util::local_def; use syntax::ast_util::local_def;
@ -181,12 +181,12 @@ pub enum FnKind {
#[deriving(Clone)] #[deriving(Clone)]
pub struct PurityState { pub struct PurityState {
def: ast::NodeId, def: ast::NodeId,
purity: ast::purity, purity: ast::Purity,
priv from_fn: bool priv from_fn: bool
} }
impl PurityState { impl PurityState {
pub fn function(purity: ast::purity, def: ast::NodeId) -> PurityState { pub fn function(purity: ast::Purity, def: ast::NodeId) -> PurityState {
PurityState { def: def, purity: purity, from_fn: true } PurityState { def: def, purity: purity, from_fn: true }
} }
@ -196,11 +196,11 @@ impl PurityState {
// unsafe we shouldn't attribute the unsafe'ness to the block. This // unsafe we shouldn't attribute the unsafe'ness to the block. This
// way the block can be warned about instead of ignoring this // way the block can be warned about instead of ignoring this
// extraneous block (functions are never warned about). // extraneous block (functions are never warned about).
ast::unsafe_fn if self.from_fn => *self, ast::UnsafeFn if self.from_fn => *self,
purity => { purity => {
let (purity, def) = match blk.rules { let (purity, def) = match blk.rules {
ast::UnsafeBlock(..) => (ast::unsafe_fn, blk.id), ast::UnsafeBlock(..) => (ast::UnsafeFn, blk.id),
ast::DefaultBlock => (purity, self.def), ast::DefaultBlock => (purity, self.def),
}; };
PurityState{ def: def, PurityState{ def: def,
@ -284,7 +284,7 @@ pub fn blank_fn_ctxt(ccx: @CrateCtxt,
@FnCtxt { @FnCtxt {
err_count_on_creation: ccx.tcx.sess.err_count(), err_count_on_creation: ccx.tcx.sess.err_count(),
ret_ty: rty, ret_ty: rty,
ps: RefCell::new(PurityState::function(ast::impure_fn, 0)), ps: RefCell::new(PurityState::function(ast::ImpureFn, 0)),
region_lb: Cell::new(region_bnd), region_lb: Cell::new(region_bnd),
fn_kind: Vanilla, fn_kind: Vanilla,
inh: @Inherited::new(ccx.tcx, param_env), inh: @Inherited::new(ccx.tcx, param_env),
@ -305,7 +305,7 @@ impl ExprTyProvider for FnCtxt {
struct CheckItemTypesVisitor { ccx: @CrateCtxt } struct CheckItemTypesVisitor { ccx: @CrateCtxt }
impl Visitor<()> for CheckItemTypesVisitor { impl Visitor<()> for CheckItemTypesVisitor {
fn visit_item(&mut self, i: &ast::item, _: ()) { fn visit_item(&mut self, i: &ast::Item, _: ()) {
check_item(self.ccx, i); check_item(self.ccx, i);
visit::walk_item(self, i, ()); visit::walk_item(self, i, ());
} }
@ -317,7 +317,7 @@ pub fn check_item_types(ccx: @CrateCtxt, crate: &ast::Crate) {
} }
pub fn check_bare_fn(ccx: @CrateCtxt, pub fn check_bare_fn(ccx: @CrateCtxt,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
id: ast::NodeId, id: ast::NodeId,
self_info: Option<SelfInfo>, self_info: Option<SelfInfo>,
@ -367,7 +367,7 @@ impl Visitor<()> for GatherLocalsVisitor {
// Add explicitly-declared locals. // Add explicitly-declared locals.
fn visit_local(&mut self, local: &ast::Local, _: ()) { fn visit_local(&mut self, local: &ast::Local, _: ()) {
let o_ty = match local.ty.node { let o_ty = match local.ty.node {
ast::ty_infer => None, ast::TyInfer => None,
_ => Some(self.fcx.to_ty(local.ty)) _ => Some(self.fcx.to_ty(local.ty))
}; };
self.assign(local.id, o_ty); self.assign(local.id, o_ty);
@ -409,17 +409,17 @@ impl Visitor<()> for GatherLocalsVisitor {
} }
// Don't descend into fns and items // Don't descend into fns and items
fn visit_fn(&mut self, _: &visit::fn_kind, _: &ast::fn_decl, fn visit_fn(&mut self, _: &visit::FnKind, _: &ast::FnDecl,
_: &ast::Block, _: Span, _: ast::NodeId, _: ()) { } _: &ast::Block, _: Span, _: ast::NodeId, _: ()) { }
fn visit_item(&mut self, _: &ast::item, _: ()) { } fn visit_item(&mut self, _: &ast::Item, _: ()) { }
} }
pub fn check_fn(ccx: @CrateCtxt, pub fn check_fn(ccx: @CrateCtxt,
opt_self_info: Option<SelfInfo>, opt_self_info: Option<SelfInfo>,
purity: ast::purity, purity: ast::Purity,
fn_sig: &ty::FnSig, fn_sig: &ty::FnSig,
decl: &ast::fn_decl, decl: &ast::FnDecl,
id: ast::NodeId, id: ast::NodeId,
body: &ast::Block, body: &ast::Block,
fn_kind: FnKind, fn_kind: FnKind,
@ -506,7 +506,7 @@ pub fn check_fn(ccx: @CrateCtxt,
return fcx; return fcx;
fn gather_locals(fcx: @FnCtxt, fn gather_locals(fcx: @FnCtxt,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: &ast::Block, body: &ast::Block,
arg_tys: &[ty::t], arg_tys: &[ty::t],
opt_self_info: Option<SelfInfo>) { opt_self_info: Option<SelfInfo>) {
@ -576,21 +576,21 @@ pub fn check_struct(ccx: @CrateCtxt, id: ast::NodeId, span: Span) {
} }
} }
pub fn check_item(ccx: @CrateCtxt, it: &ast::item) { pub fn check_item(ccx: @CrateCtxt, it: &ast::Item) {
debug!("check_item(it.id={}, it.ident={})", debug!("check_item(it.id={}, it.ident={})",
it.id, it.id,
ty::item_path_str(ccx.tcx, local_def(it.id))); ty::item_path_str(ccx.tcx, local_def(it.id)));
let _indenter = indenter(); let _indenter = indenter();
match it.node { match it.node {
ast::item_static(_, _, e) => check_const(ccx, it.span, e, it.id), ast::ItemStatic(_, _, e) => check_const(ccx, it.span, e, it.id),
ast::item_enum(ref enum_definition, _) => { ast::ItemEnum(ref enum_definition, _) => {
check_enum_variants(ccx, check_enum_variants(ccx,
it.span, it.span,
enum_definition.variants, enum_definition.variants,
it.id); it.id);
} }
ast::item_fn(decl, _, _, _, body) => { ast::ItemFn(decl, _, _, _, body) => {
let fn_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id)); let fn_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
// FIXME(#5121) -- won't work for lifetimes that appear in type bounds // FIXME(#5121) -- won't work for lifetimes that appear in type bounds
@ -604,8 +604,8 @@ pub fn check_item(ccx: @CrateCtxt, it: &ast::item) {
check_bare_fn(ccx, decl, body, it.id, None, fn_tpt.ty, param_env); check_bare_fn(ccx, decl, body, it.id, None, fn_tpt.ty, param_env);
} }
ast::item_impl(_, ref opt_trait_ref, _, ref ms) => { ast::ItemImpl(_, ref opt_trait_ref, _, ref ms) => {
debug!("item_impl {} with id {}", ccx.tcx.sess.str_of(it.ident), it.id); debug!("ItemImpl {} with id {}", ccx.tcx.sess.str_of(it.ident), it.id);
let impl_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id)); let impl_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
for m in ms.iter() { for m in ms.iter() {
@ -629,29 +629,29 @@ pub fn check_item(ccx: @CrateCtxt, it: &ast::item) {
} }
} }
ast::item_trait(_, _, ref trait_methods) => { ast::ItemTrait(_, _, ref trait_methods) => {
let trait_def = ty::lookup_trait_def(ccx.tcx, local_def(it.id)); let trait_def = ty::lookup_trait_def(ccx.tcx, local_def(it.id));
for trait_method in (*trait_methods).iter() { for trait_method in (*trait_methods).iter() {
match *trait_method { match *trait_method {
required(..) => { Required(..) => {
// Nothing to do, since required methods don't have // Nothing to do, since required methods don't have
// bodies to check. // bodies to check.
} }
provided(m) => { Provided(m) => {
check_method_body(ccx, &trait_def.generics, check_method_body(ccx, &trait_def.generics,
Some(trait_def.trait_ref), m); Some(trait_def.trait_ref), m);
} }
} }
} }
} }
ast::item_struct(..) => { ast::ItemStruct(..) => {
check_struct(ccx, it.id, it.span); check_struct(ccx, it.id, it.span);
} }
ast::item_ty(ref t, ref generics) => { ast::ItemTy(ref t, ref generics) => {
let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id); let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id);
check_bounds_are_used(ccx, t.span, &generics.ty_params, tpt_ty); check_bounds_are_used(ccx, t.span, &generics.ty_params, tpt_ty);
} }
ast::item_foreign_mod(ref m) => { ast::ItemForeignMod(ref m) => {
if m.abis.is_intrinsic() { if m.abis.is_intrinsic() {
for item in m.items.iter() { for item in m.items.iter() {
check_intrinsic_type(ccx, *item); check_intrinsic_type(ccx, *item);
@ -664,7 +664,7 @@ pub fn check_item(ccx: @CrateCtxt, it: &ast::item) {
} }
match item.node { match item.node {
ast::foreign_item_fn(ref fn_decl, _) => { ast::ForeignItemFn(ref fn_decl, _) => {
if fn_decl.variadic && !m.abis.is_c() { if fn_decl.variadic && !m.abis.is_c() {
ccx.tcx.sess.span_err( ccx.tcx.sess.span_err(
item.span, "variadic function must have C calling convention"); item.span, "variadic function must have C calling convention");
@ -682,7 +682,7 @@ pub fn check_item(ccx: @CrateCtxt, it: &ast::item) {
fn check_method_body(ccx: @CrateCtxt, fn check_method_body(ccx: @CrateCtxt,
item_generics: &ty::Generics, item_generics: &ty::Generics,
self_bound: Option<@ty::TraitRef>, self_bound: Option<@ty::TraitRef>,
method: &ast::method) { method: &ast::Method) {
/*! /*!
* Type checks a method body. * Type checks a method body.
* *
@ -734,9 +734,9 @@ fn check_method_body(ccx: @CrateCtxt,
fn check_impl_methods_against_trait(ccx: @CrateCtxt, fn check_impl_methods_against_trait(ccx: @CrateCtxt,
impl_span: Span, impl_span: Span,
impl_generics: &ty::Generics, impl_generics: &ty::Generics,
ast_trait_ref: &ast::trait_ref, ast_trait_ref: &ast::TraitRef,
impl_trait_ref: &ty::TraitRef, impl_trait_ref: &ty::TraitRef,
impl_methods: &[@ast::method]) { impl_methods: &[@ast::Method]) {
// Locate trait methods // Locate trait methods
let tcx = ccx.tcx; let tcx = ccx.tcx;
let trait_methods = ty::trait_methods(tcx, impl_trait_ref.def_id); let trait_methods = ty::trait_methods(tcx, impl_trait_ref.def_id);
@ -831,8 +831,8 @@ pub fn compare_impl_method(tcx: ty::ctxt,
// inscrutable, particularly for cases where one method has no // inscrutable, particularly for cases where one method has no
// self. // self.
match (&trait_m.explicit_self, &impl_m.explicit_self) { match (&trait_m.explicit_self, &impl_m.explicit_self) {
(&ast::sty_static, &ast::sty_static) => {} (&ast::SelfStatic, &ast::SelfStatic) => {}
(&ast::sty_static, _) => { (&ast::SelfStatic, _) => {
tcx.sess.span_err( tcx.sess.span_err(
impl_m_span, impl_m_span,
format!("method `{}` has a `{}` declaration in the impl, \ format!("method `{}` has a `{}` declaration in the impl, \
@ -842,7 +842,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
tcx.sess.intr()))); tcx.sess.intr())));
return; return;
} }
(_, &ast::sty_static) => { (_, &ast::SelfStatic) => {
tcx.sess.span_err( tcx.sess.span_err(
impl_m_span, impl_m_span,
format!("method `{}` has a `{}` declaration in the trait, \ format!("method `{}` has a `{}` declaration in the trait, \
@ -1378,31 +1378,31 @@ pub fn do_autoderef(fcx: @FnCtxt, sp: Span, t: ty::t) -> (ty::t, uint) {
} }
// AST fragment checking // AST fragment checking
pub fn check_lit(fcx: @FnCtxt, lit: &ast::lit) -> ty::t { pub fn check_lit(fcx: @FnCtxt, lit: &ast::Lit) -> ty::t {
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
match lit.node { match lit.node {
ast::lit_str(..) => ty::mk_estr(tcx, ty::vstore_slice(ty::ReStatic)), ast::LitStr(..) => ty::mk_estr(tcx, ty::vstore_slice(ty::ReStatic)),
ast::lit_binary(..) => { ast::LitBinary(..) => {
ty::mk_evec(tcx, ty::mt{ ty: ty::mk_u8(), mutbl: ast::MutImmutable }, ty::mk_evec(tcx, ty::mt{ ty: ty::mk_u8(), mutbl: ast::MutImmutable },
ty::vstore_slice(ty::ReStatic)) ty::vstore_slice(ty::ReStatic))
} }
ast::lit_char(_) => ty::mk_char(), ast::LitChar(_) => ty::mk_char(),
ast::lit_int(_, t) => ty::mk_mach_int(t), ast::LitInt(_, t) => ty::mk_mach_int(t),
ast::lit_uint(_, t) => ty::mk_mach_uint(t), ast::LitUint(_, t) => ty::mk_mach_uint(t),
ast::lit_int_unsuffixed(_) => { ast::LitIntUnsuffixed(_) => {
// An unsuffixed integer literal could have any integral type, // An unsuffixed integer literal could have any integral type,
// so we create an integral type variable for it. // so we create an integral type variable for it.
ty::mk_int_var(tcx, fcx.infcx().next_int_var_id()) ty::mk_int_var(tcx, fcx.infcx().next_int_var_id())
} }
ast::lit_float(_, t) => ty::mk_mach_float(t), ast::LitFloat(_, t) => ty::mk_mach_float(t),
ast::lit_float_unsuffixed(_) => { ast::LitFloatUnsuffixed(_) => {
// An unsuffixed floating point literal could have any floating point // An unsuffixed floating point literal could have any floating point
// type, so we create a floating point type variable for it. // type, so we create a floating point type variable for it.
ty::mk_float_var(tcx, fcx.infcx().next_float_var_id()) ty::mk_float_var(tcx, fcx.infcx().next_float_var_id())
} }
ast::lit_nil => ty::mk_nil(), ast::LitNil => ty::mk_nil(),
ast::lit_bool(_) => ty::mk_bool() ast::LitBool(_) => ty::mk_bool()
} }
} }
@ -1815,17 +1815,17 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
// in C but we just error out instead and require explicit casts. // in C but we just error out instead and require explicit casts.
let arg_ty = structurally_resolved_type(fcx, arg.span, fcx.expr_ty(*arg)); let arg_ty = structurally_resolved_type(fcx, arg.span, fcx.expr_ty(*arg));
match ty::get(arg_ty).sty { match ty::get(arg_ty).sty {
ty::ty_float(ast::ty_f32) => { ty::ty_float(ast::TyF32) => {
fcx.type_error_message(arg.span, fcx.type_error_message(arg.span,
|t| format!("can't pass an {} to variadic function, \ |t| format!("can't pass an {} to variadic function, \
cast to c_double", t), arg_ty, None); cast to c_double", t), arg_ty, None);
} }
ty::ty_int(ast::ty_i8) | ty::ty_int(ast::ty_i16) | ty::ty_bool => { ty::ty_int(ast::TyI8) | ty::ty_int(ast::TyI16) | ty::ty_bool => {
fcx.type_error_message(arg.span, fcx.type_error_message(arg.span,
|t| format!("can't pass {} to variadic function, cast to c_int", |t| format!("can't pass {} to variadic function, cast to c_int",
t), arg_ty, None); t), arg_ty, None);
} }
ty::ty_uint(ast::ty_u8) | ty::ty_uint(ast::ty_u16) => { ty::ty_uint(ast::TyU8) | ty::ty_uint(ast::TyU16) => {
fcx.type_error_message(arg.span, fcx.type_error_message(arg.span,
|t| format!("can't pass {} to variadic function, cast to c_uint", |t| format!("can't pass {} to variadic function, cast to c_uint",
t), arg_ty, None); t), arg_ty, None);
@ -2250,7 +2250,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
fn check_expr_fn(fcx: @FnCtxt, fn check_expr_fn(fcx: @FnCtxt,
expr: &ast::Expr, expr: &ast::Expr,
ast_sigil_opt: Option<ast::Sigil>, ast_sigil_opt: Option<ast::Sigil>,
decl: &ast::fn_decl, decl: &ast::FnDecl,
body: ast::P<ast::Block>, body: ast::P<ast::Block>,
fn_kind: FnKind, fn_kind: FnKind,
expected: Option<ty::t>) { expected: Option<ty::t>) {
@ -2295,7 +2295,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
} }
_ => () _ => ()
} }
(None, ast::impure_fn, sigil, (None, ast::ImpureFn, sigil,
onceness, bounds) onceness, bounds)
} }
} }
@ -2304,7 +2304,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
// If the proto is specified, use that, otherwise select a // If the proto is specified, use that, otherwise select a
// proto based on inference. // proto based on inference.
let (sigil, purity) = match ast_sigil_opt { let (sigil, purity) = match ast_sigil_opt {
Some(p) => (p, ast::impure_fn), Some(p) => (p, ast::ImpureFn),
None => (expected_sigil, expected_purity) None => (expected_sigil, expected_purity)
}; };
@ -2622,7 +2622,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
match expr.node { match expr.node {
ast::ExprVstore(ev, vst) => { ast::ExprVstore(ev, vst) => {
let typ = match ev.node { let typ = match ev.node {
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(..), .. }) => { ast::ExprLit(@codemap::Spanned { node: ast::LitStr(..), .. }) => {
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst); let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
ty::mk_estr(tcx, tt) ty::mk_estr(tcx, tt)
} }
@ -3081,7 +3081,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
if type_is_c_like_enum(fcx, expr.span, t_e) && t_1_is_trivial { if type_is_c_like_enum(fcx, expr.span, t_e) && t_1_is_trivial {
// casts from C-like enums are allowed // casts from C-like enums are allowed
} else if t_1_is_char { } else if t_1_is_char {
if ty::get(te).sty != ty::ty_uint(ast::ty_u8) { if ty::get(te).sty != ty::ty_uint(ast::TyU8) {
fcx.type_error_message(expr.span, |actual| { fcx.type_error_message(expr.span, |actual| {
format!("only `u8` can be cast as `char`, not `{}`", actual) format!("only `u8` can be cast as `char`, not `{}`", actual)
}, t_e, None); }, t_e, None);
@ -3541,28 +3541,28 @@ pub fn check_simd(tcx: ty::ctxt, sp: Span, id: ast::NodeId) {
pub fn check_enum_variants(ccx: @CrateCtxt, pub fn check_enum_variants(ccx: @CrateCtxt,
sp: Span, sp: Span,
vs: &[ast::P<ast::variant>], vs: &[ast::P<ast::Variant>],
id: ast::NodeId) { id: ast::NodeId) {
fn disr_in_range(ccx: @CrateCtxt, fn disr_in_range(ccx: @CrateCtxt,
ty: attr::IntType, ty: attr::IntType,
disr: ty::Disr) -> bool { disr: ty::Disr) -> bool {
fn uint_in_range(ccx: @CrateCtxt, ty: ast::uint_ty, disr: ty::Disr) -> bool { fn uint_in_range(ccx: @CrateCtxt, ty: ast::UintTy, disr: ty::Disr) -> bool {
match ty { match ty {
ast::ty_u8 => disr as u8 as Disr == disr, ast::TyU8 => disr as u8 as Disr == disr,
ast::ty_u16 => disr as u16 as Disr == disr, ast::TyU16 => disr as u16 as Disr == disr,
ast::ty_u32 => disr as u32 as Disr == disr, ast::TyU32 => disr as u32 as Disr == disr,
ast::ty_u64 => disr as u64 as Disr == disr, ast::TyU64 => disr as u64 as Disr == disr,
ast::ty_u => uint_in_range(ccx, ccx.tcx.sess.targ_cfg.uint_type, disr) ast::TyU => uint_in_range(ccx, ccx.tcx.sess.targ_cfg.uint_type, disr)
} }
} }
fn int_in_range(ccx: @CrateCtxt, ty: ast::int_ty, disr: ty::Disr) -> bool { fn int_in_range(ccx: @CrateCtxt, ty: ast::IntTy, disr: ty::Disr) -> bool {
match ty { match ty {
ast::ty_i8 => disr as i8 as Disr == disr, ast::TyI8 => disr as i8 as Disr == disr,
ast::ty_i16 => disr as i16 as Disr == disr, ast::TyI16 => disr as i16 as Disr == disr,
ast::ty_i32 => disr as i32 as Disr == disr, ast::TyI32 => disr as i32 as Disr == disr,
ast::ty_i64 => disr as i64 as Disr == disr, ast::TyI64 => disr as i64 as Disr == disr,
ast::ty_i => int_in_range(ccx, ccx.tcx.sess.targ_cfg.int_type, disr) ast::TyI => int_in_range(ccx, ccx.tcx.sess.targ_cfg.int_type, disr)
} }
} }
match ty { match ty {
@ -3572,7 +3572,7 @@ pub fn check_enum_variants(ccx: @CrateCtxt,
} }
fn do_check(ccx: @CrateCtxt, fn do_check(ccx: @CrateCtxt,
vs: &[ast::P<ast::variant>], vs: &[ast::P<ast::Variant>],
id: ast::NodeId, id: ast::NodeId,
hint: attr::ReprAttr) hint: attr::ReprAttr)
-> ~[@ty::VariantInfo] { -> ~[@ty::VariantInfo] {
@ -3975,7 +3975,7 @@ pub fn check_bounds_are_used(ccx: @CrateCtxt,
} }
} }
pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::foreign_item) { pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) {
fn param(ccx: @CrateCtxt, n: uint) -> ty::t { fn param(ccx: @CrateCtxt, n: uint) -> ty::t {
ty::mk_param(ccx.tcx, n, local_def(0)) ty::mk_param(ccx.tcx, n, local_def(0))
} }
@ -4277,7 +4277,7 @@ pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::foreign_item) {
} }
}; };
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy { let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
purity: ast::unsafe_fn, purity: ast::UnsafeFn,
abis: AbiSet::Intrinsic(), abis: AbiSet::Intrinsic(),
sig: FnSig {binder_id: it.id, sig: FnSig {binder_id: it.id,
inputs: inputs, inputs: inputs,

View file

@ -175,7 +175,7 @@ impl Visitor<()> for Rcx {
// hierarchy, and in particular the relationships between free // hierarchy, and in particular the relationships between free
// regions, until regionck, as described in #3238. // regions, until regionck, as described in #3238.
fn visit_item(&mut self, i: &ast::item, _: ()) { visit_item(self, i); } fn visit_item(&mut self, i: &ast::Item, _: ()) { visit_item(self, i); }
fn visit_expr(&mut self, ex: &ast::Expr, _: ()) { visit_expr(self, ex); } fn visit_expr(&mut self, ex: &ast::Expr, _: ()) { visit_expr(self, ex); }
@ -188,7 +188,7 @@ impl Visitor<()> for Rcx {
fn visit_block(&mut self, b: &ast::Block, _: ()) { visit_block(self, b); } fn visit_block(&mut self, b: &ast::Block, _: ()) { visit_block(self, b); }
} }
fn visit_item(_rcx: &mut Rcx, _item: &ast::item) { fn visit_item(_rcx: &mut Rcx, _item: &ast::Item) {
// Ignore items // Ignore items
} }

View file

@ -552,7 +552,7 @@ pub fn location_info_for_expr(expr: &ast::Expr) -> LocationInfo {
id: expr.id id: expr.id
} }
} }
pub fn location_info_for_item(item: &ast::item) -> LocationInfo { pub fn location_info_for_item(item: &ast::Item) -> LocationInfo {
LocationInfo { LocationInfo {
span: item.span, span: item.span,
id: item.id id: item.id
@ -760,7 +760,7 @@ fn resolve_expr(fcx: @FnCtxt, ex: &ast::Expr) {
} }
pub fn resolve_impl(ccx: @CrateCtxt, pub fn resolve_impl(ccx: @CrateCtxt,
impl_item: &ast::item, impl_item: &ast::Item,
impl_generics: &ty::Generics, impl_generics: &ty::Generics,
impl_trait_ref: &ty::TraitRef) { impl_trait_ref: &ty::TraitRef) {
let param_env = ty::construct_parameter_environment( let param_env = ty::construct_parameter_environment(
@ -819,7 +819,7 @@ impl visit::Visitor<()> for @FnCtxt {
fn visit_expr(&mut self, ex: &ast::Expr, _: ()) { fn visit_expr(&mut self, ex: &ast::Expr, _: ()) {
resolve_expr(*self, ex); resolve_expr(*self, ex);
} }
fn visit_item(&mut self, _: &ast::item, _: ()) { fn visit_item(&mut self, _: &ast::Item, _: ()) {
// no-op // no-op
} }
} }

View file

@ -343,12 +343,12 @@ fn visit_local(l: &ast::Local, wbcx: &mut WbCtxt) {
} }
visit::walk_local(wbcx, l, ()); visit::walk_local(wbcx, l, ());
} }
fn visit_item(_item: &ast::item, _wbcx: &mut WbCtxt) { fn visit_item(_item: &ast::Item, _wbcx: &mut WbCtxt) {
// Ignore items // Ignore items
} }
impl Visitor<()> for WbCtxt { impl Visitor<()> for WbCtxt {
fn visit_item(&mut self, i: &ast::item, _: ()) { visit_item(i, self); } fn visit_item(&mut self, i: &ast::Item, _: ()) { visit_item(i, self); }
fn visit_stmt(&mut self, s: &ast::Stmt, _: ()) { visit_stmt(s, self); } fn visit_stmt(&mut self, s: &ast::Stmt, _: ()) { visit_stmt(s, self); }
fn visit_expr(&mut self, ex:&ast::Expr, _: ()) { visit_expr(ex, self); } fn visit_expr(&mut self, ex:&ast::Expr, _: ()) { visit_expr(ex, self); }
fn visit_block(&mut self, b: &ast::Block, _: ()) { visit_block(b, self); } fn visit_block(&mut self, b: &ast::Block, _: ()) { visit_block(b, self); }
@ -366,7 +366,7 @@ pub fn resolve_type_vars_in_expr(fcx: @FnCtxt, e: &ast::Expr) -> bool {
} }
pub fn resolve_type_vars_in_fn(fcx: @FnCtxt, pub fn resolve_type_vars_in_fn(fcx: @FnCtxt,
decl: &ast::fn_decl, decl: &ast::FnDecl,
blk: &ast::Block, blk: &ast::Block,
self_info: Option<SelfInfo>) -> bool { self_info: Option<SelfInfo>) -> bool {
let mut wbcx = WbCtxt { fcx: fcx, success: true }; let mut wbcx = WbCtxt { fcx: fcx, success: true };

View file

@ -36,10 +36,10 @@ use middle::typeck::infer::{new_infer_ctxt, resolve_ivar, resolve_type};
use middle::typeck::infer; use middle::typeck::infer;
use util::ppaux::Repr; use util::ppaux::Repr;
use syntax::ast::{Crate, DefId, DefStruct, DefTy}; use syntax::ast::{Crate, DefId, DefStruct, DefTy};
use syntax::ast::{item, item_enum, item_impl, item_mod, item_struct}; use syntax::ast::{Item, ItemEnum, ItemImpl, ItemMod, ItemStruct};
use syntax::ast::{LOCAL_CRATE, trait_ref, ty_path}; use syntax::ast::{LOCAL_CRATE, TraitRef, TyPath};
use syntax::ast; use syntax::ast;
use syntax::ast_map::node_item; use syntax::ast_map::NodeItem;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_util::{def_id_of_def, local_def}; use syntax::ast_util::{def_id_of_def, local_def};
use syntax::codemap::Span; use syntax::codemap::Span;
@ -159,13 +159,13 @@ pub struct CoherenceChecker {
struct CoherenceCheckVisitor { cc: CoherenceChecker } struct CoherenceCheckVisitor { cc: CoherenceChecker }
impl visit::Visitor<()> for CoherenceCheckVisitor { impl visit::Visitor<()> for CoherenceCheckVisitor {
fn visit_item(&mut self, item: &item, _: ()) { fn visit_item(&mut self, item: &Item, _: ()) {
// debug!("(checking coherence) item '{}'", // debug!("(checking coherence) item '{}'",
// self.cc.crate_context.tcx.sess.str_of(item.ident)); // self.cc.crate_context.tcx.sess.str_of(item.ident));
match item.node { match item.node {
item_impl(_, ref opt_trait, _, _) => { ItemImpl(_, ref opt_trait, _, _) => {
match opt_trait.clone() { match opt_trait.clone() {
Some(opt_trait) => { Some(opt_trait) => {
self.cc.check_implementation(item, [opt_trait]); self.cc.check_implementation(item, [opt_trait]);
@ -185,14 +185,14 @@ impl visit::Visitor<()> for CoherenceCheckVisitor {
struct PrivilegedScopeVisitor { cc: CoherenceChecker } struct PrivilegedScopeVisitor { cc: CoherenceChecker }
impl visit::Visitor<()> for PrivilegedScopeVisitor { impl visit::Visitor<()> for PrivilegedScopeVisitor {
fn visit_item(&mut self, item: &item, _: ()) { fn visit_item(&mut self, item: &Item, _: ()) {
match item.node { match item.node {
item_mod(ref module_) => { ItemMod(ref module_) => {
// Then visit the module items. // Then visit the module items.
visit::walk_mod(self, module_, ()); visit::walk_mod(self, module_, ());
} }
item_impl(_, None, ast_ty, _) => { ItemImpl(_, None, ast_ty, _) => {
if !self.cc.ast_type_is_defined_in_local_crate(ast_ty) { if !self.cc.ast_type_is_defined_in_local_crate(ast_ty) {
// This is an error. // This is an error.
let session = self.cc.crate_context.tcx.sess; let session = self.cc.crate_context.tcx.sess;
@ -202,7 +202,7 @@ impl visit::Visitor<()> for PrivilegedScopeVisitor {
a trait or new type instead"); a trait or new type instead");
} }
} }
item_impl(_, Some(ref trait_ref), _, _) => { ItemImpl(_, Some(ref trait_ref), _, _) => {
// `for_ty` is `Type` in `impl Trait for Type` // `for_ty` is `Type` in `impl Trait for Type`
let for_ty = let for_ty =
ty::node_id_to_type(self.cc.crate_context.tcx, ty::node_id_to_type(self.cc.crate_context.tcx,
@ -259,8 +259,8 @@ impl CoherenceChecker {
} }
pub fn check_implementation(&self, pub fn check_implementation(&self,
item: &item, item: &Item,
associated_traits: &[trait_ref]) { associated_traits: &[TraitRef]) {
let tcx = self.crate_context.tcx; let tcx = self.crate_context.tcx;
let self_type = ty::lookup_item_type(tcx, local_def(item.id)); let self_type = ty::lookup_item_type(tcx, local_def(item.id));
@ -546,7 +546,7 @@ impl CoherenceChecker {
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, crate, ());
} }
pub fn trait_ref_to_trait_def_id(&self, trait_ref: &trait_ref) -> DefId { pub fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId {
let def_map = self.crate_context.tcx.def_map; let def_map = self.crate_context.tcx.def_map;
let def_map = def_map.borrow(); let def_map = def_map.borrow();
let trait_def = def_map.get().get_copy(&trait_ref.ref_id); let trait_def = def_map.get().get_copy(&trait_ref.ref_id);
@ -560,7 +560,7 @@ impl CoherenceChecker {
pub fn ast_type_is_defined_in_local_crate(&self, original_type: &ast::Ty) pub fn ast_type_is_defined_in_local_crate(&self, original_type: &ast::Ty)
-> bool { -> bool {
match original_type.node { match original_type.node {
ty_path(_, _, path_id) => { TyPath(_, _, path_id) => {
let def_map = self.crate_context.tcx.def_map.borrow(); let def_map = self.crate_context.tcx.def_map.borrow();
match def_map.get().get_copy(&path_id) { match def_map.get().get_copy(&path_id) {
DefTy(def_id) | DefStruct(def_id) => { DefTy(def_id) | DefStruct(def_id) => {
@ -577,9 +577,9 @@ impl CoherenceChecker {
original_type.span, original_type.span,
"resolve didn't resolve this type?!"); "resolve didn't resolve this type?!");
} }
Some(&node_item(item, _)) => { Some(&NodeItem(item, _)) => {
match item.node { match item.node {
item_struct(..) | item_enum(..) => true, ItemStruct(..) | ItemEnum(..) => true,
_ => false, _ => false,
} }
} }
@ -594,10 +594,10 @@ impl CoherenceChecker {
} }
// Converts an implementation in the AST to an Impl structure. // Converts an implementation in the AST to an Impl structure.
pub fn create_impl_from_item(&self, item: &item) -> @Impl { pub fn create_impl_from_item(&self, item: &Item) -> @Impl {
let tcx = self.crate_context.tcx; let tcx = self.crate_context.tcx;
match item.node { match item.node {
item_impl(_, ref trait_refs, _, ref ast_methods) => { ItemImpl(_, ref trait_refs, _, ref ast_methods) => {
let mut methods = ~[]; let mut methods = ~[];
for ast_method in ast_methods.iter() { for ast_method in ast_methods.iter() {
methods.push(ty::method(tcx, local_def(ast_method.id))); methods.push(ty::method(tcx, local_def(ast_method.id)));
@ -630,7 +630,7 @@ impl CoherenceChecker {
assert_eq!(implementation.did.crate, LOCAL_CRATE); assert_eq!(implementation.did.crate, LOCAL_CRATE);
let items = self.crate_context.tcx.items.borrow(); let items = self.crate_context.tcx.items.borrow();
match items.get().find(&implementation.did.node) { match items.get().find(&implementation.did.node) {
Some(&node_item(item, _)) => { Some(&NodeItem(item, _)) => {
return item.span; return item.span;
} }
_ => { _ => {
@ -736,7 +736,7 @@ impl CoherenceChecker {
{ {
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&impl_info.did.node) { match items.get().find(&impl_info.did.node) {
Some(&ast_map::node_item(@ref item, _)) => { Some(&ast_map::NodeItem(@ref item, _)) => {
tcx.sess.span_err((*item).span, tcx.sess.span_err((*item).span,
"the Drop trait may \ "the Drop trait may \
only be implemented \ only be implemented \

View file

@ -62,11 +62,11 @@ struct CollectItemTypesVisitor {
} }
impl visit::Visitor<()> for CollectItemTypesVisitor { impl visit::Visitor<()> for CollectItemTypesVisitor {
fn visit_item(&mut self, i: &ast::item, _: ()) { fn visit_item(&mut self, i: &ast::Item, _: ()) {
convert(self.ccx, i); convert(self.ccx, i);
visit::walk_item(self, i, ()); visit::walk_item(self, i, ());
} }
fn visit_foreign_item(&mut self, i: &ast::foreign_item, _: ()) { fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
convert_foreign(self.ccx, i); convert_foreign(self.ccx, i);
visit::walk_foreign_item(self, i, ()); visit::walk_foreign_item(self, i, ());
} }
@ -112,8 +112,8 @@ impl AstConv for CrateCtxt {
let items = self.tcx.items.borrow(); let items = self.tcx.items.borrow();
match items.get().find(&id.node) { match items.get().find(&id.node) {
Some(&ast_map::node_item(item, _)) => ty_of_item(self, item), Some(&ast_map::NodeItem(item, _)) => ty_of_item(self, item),
Some(&ast_map::node_foreign_item(foreign_item, abis, _, _)) => { Some(&ast_map::NodeForeignItem(foreign_item, abis, _, _)) => {
ty_of_foreign_item(self, foreign_item, abis) ty_of_foreign_item(self, foreign_item, abis)
} }
ref x => { ref x => {
@ -135,7 +135,7 @@ impl AstConv for CrateCtxt {
pub fn get_enum_variant_types(ccx: &CrateCtxt, pub fn get_enum_variant_types(ccx: &CrateCtxt,
enum_ty: ty::t, enum_ty: ty::t,
variants: &[ast::P<ast::variant>], variants: &[ast::P<ast::Variant>],
generics: &ast::Generics) { generics: &ast::Generics) {
let tcx = ccx.tcx; let tcx = ccx.tcx;
@ -145,17 +145,17 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
// constructors get turned into functions. // constructors get turned into functions.
let scope = variant.node.id; let scope = variant.node.id;
let result_ty = match variant.node.kind { let result_ty = match variant.node.kind {
ast::tuple_variant_kind(ref args) if args.len() > 0 => { ast::TupleVariantKind(ref args) if args.len() > 0 => {
let rs = ExplicitRscope; let rs = ExplicitRscope;
let input_tys = args.map(|va| ccx.to_ty(&rs, va.ty)); let input_tys = args.map(|va| ccx.to_ty(&rs, va.ty));
ty::mk_ctor_fn(tcx, scope, input_tys, enum_ty) ty::mk_ctor_fn(tcx, scope, input_tys, enum_ty)
} }
ast::tuple_variant_kind(_) => { ast::TupleVariantKind(_) => {
enum_ty enum_ty
} }
ast::struct_variant_kind(struct_def) => { ast::StructVariantKind(struct_def) => {
let tpt = ty_param_bounds_and_ty { let tpt = ty_param_bounds_and_ty {
generics: ty_generics(ccx, generics, 0), generics: ty_generics(ccx, generics, 0),
ty: enum_ty ty: enum_ty
@ -189,8 +189,8 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
let tcx = ccx.tcx; let tcx = ccx.tcx;
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().get_copy(&trait_id) { match items.get().get_copy(&trait_id) {
ast_map::node_item(@ast::item { ast_map::NodeItem(@ast::Item {
node: ast::item_trait(ref generics, _, ref ms), node: ast::ItemTrait(ref generics, _, ref ms),
.. ..
}, _) => { }, _) => {
let trait_ty_generics = let trait_ty_generics =
@ -200,14 +200,14 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
// store it into the `tcx.methods` table: // store it into the `tcx.methods` table:
for m in ms.iter() { for m in ms.iter() {
let ty_method = @match m { let ty_method = @match m {
&ast::required(ref m) => { &ast::Required(ref m) => {
ty_method_of_trait_method( ty_method_of_trait_method(
ccx, trait_id, &trait_ty_generics, ccx, trait_id, &trait_ty_generics,
&m.id, &m.ident, &m.explicit_self, &m.id, &m.ident, &m.explicit_self,
&m.generics, &m.purity, m.decl) &m.generics, &m.purity, m.decl)
} }
&ast::provided(ref m) => { &ast::Provided(ref m) => {
ty_method_of_trait_method( ty_method_of_trait_method(
ccx, trait_id, &trait_ty_generics, ccx, trait_id, &trait_ty_generics,
&m.id, &m.ident, &m.explicit_self, &m.id, &m.ident, &m.explicit_self,
@ -215,7 +215,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
} }
}; };
if ty_method.explicit_self == ast::sty_static { if ty_method.explicit_self == ast::SelfStatic {
make_static_method_ty(ccx, trait_id, ty_method, make_static_method_ty(ccx, trait_id, ty_method,
&trait_ty_generics); &trait_ty_generics);
} }
@ -227,8 +227,8 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
// Add an entry mapping // Add an entry mapping
let method_def_ids = @ms.map(|m| { let method_def_ids = @ms.map(|m| {
match m { match m {
&ast::required(ref ty_method) => local_def(ty_method.id), &ast::Required(ref ty_method) => local_def(ty_method.id),
&ast::provided(ref method) => local_def(method.id) &ast::Provided(ref method) => local_def(method.id)
} }
}); });
@ -372,10 +372,10 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
trait_generics: &ty::Generics, trait_generics: &ty::Generics,
m_id: &ast::NodeId, m_id: &ast::NodeId,
m_ident: &ast::Ident, m_ident: &ast::Ident,
m_explicit_self: &ast::explicit_self, m_explicit_self: &ast::ExplicitSelf,
m_generics: &ast::Generics, m_generics: &ast::Generics,
m_purity: &ast::purity, m_purity: &ast::Purity,
m_decl: &ast::fn_decl) -> ty::Method m_decl: &ast::FnDecl) -> ty::Method
{ {
let trait_self_ty = ty::mk_self(this.tcx, local_def(trait_id)); let trait_self_ty = ty::mk_self(this.tcx, local_def(trait_id));
let (transformed_self_ty, fty) = let (transformed_self_ty, fty) =
@ -390,7 +390,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
fty, fty,
m_explicit_self.node, m_explicit_self.node,
// assume public, because this is only invoked on trait methods // assume public, because this is only invoked on trait methods
ast::public, ast::Public,
local_def(*m_id), local_def(*m_id),
TraitContainer(local_def(trait_id)), TraitContainer(local_def(trait_id)),
None None
@ -401,7 +401,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
pub fn ensure_supertraits(ccx: &CrateCtxt, pub fn ensure_supertraits(ccx: &CrateCtxt,
id: ast::NodeId, id: ast::NodeId,
sp: codemap::Span, sp: codemap::Span,
ast_trait_refs: &[ast::trait_ref]) ast_trait_refs: &[ast::TraitRef])
-> ty::BuiltinBounds -> ty::BuiltinBounds
{ {
let tcx = ccx.tcx; let tcx = ccx.tcx;
@ -443,7 +443,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
pub fn convert_field(ccx: &CrateCtxt, pub fn convert_field(ccx: &CrateCtxt,
struct_generics: &ty::Generics, struct_generics: &ty::Generics,
v: &ast::struct_field) { v: &ast::StructField) {
let tt = ccx.to_ty(&ExplicitRscope, v.node.ty); let tt = ccx.to_ty(&ExplicitRscope, v.node.ty);
write_ty_to_tcx(ccx.tcx, v.node.id, tt); write_ty_to_tcx(ccx.tcx, v.node.id, tt);
/* add the field to the tcache */ /* add the field to the tcache */
@ -457,11 +457,11 @@ pub fn convert_field(ccx: &CrateCtxt,
fn convert_methods(ccx: &CrateCtxt, fn convert_methods(ccx: &CrateCtxt,
container: MethodContainer, container: MethodContainer,
ms: &[@ast::method], ms: &[@ast::Method],
untransformed_rcvr_ty: ty::t, untransformed_rcvr_ty: ty::t,
rcvr_ty_generics: &ty::Generics, rcvr_ty_generics: &ty::Generics,
rcvr_ast_generics: &ast::Generics, rcvr_ast_generics: &ast::Generics,
rcvr_visibility: ast::visibility) rcvr_visibility: ast::Visibility)
{ {
let tcx = ccx.tcx; let tcx = ccx.tcx;
for m in ms.iter() { for m in ms.iter() {
@ -505,10 +505,10 @@ fn convert_methods(ccx: &CrateCtxt,
fn ty_of_method(ccx: &CrateCtxt, fn ty_of_method(ccx: &CrateCtxt,
container: MethodContainer, container: MethodContainer,
m: &ast::method, m: &ast::Method,
untransformed_rcvr_ty: ty::t, untransformed_rcvr_ty: ty::t,
rcvr_generics: &ast::Generics, rcvr_generics: &ast::Generics,
rcvr_visibility: ast::visibility) -> ty::Method rcvr_visibility: ast::Visibility) -> ty::Method
{ {
let (transformed_self_ty, fty) = let (transformed_self_ty, fty) =
astconv::ty_of_method(ccx, m.id, m.purity, astconv::ty_of_method(ccx, m.id, m.purity,
@ -551,13 +551,13 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
} }
} }
pub fn convert(ccx: &CrateCtxt, it: &ast::item) { pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
let tcx = ccx.tcx; let tcx = ccx.tcx;
debug!("convert: item {} with id {}", tcx.sess.str_of(it.ident), it.id); debug!("convert: item {} with id {}", tcx.sess.str_of(it.ident), it.id);
match it.node { match it.node {
// These don't define types. // These don't define types.
ast::item_foreign_mod(_) | ast::item_mod(_) => {} ast::ItemForeignMod(_) | ast::ItemMod(_) => {}
ast::item_enum(ref enum_definition, ref generics) => { ast::ItemEnum(ref enum_definition, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "enumeration"); ensure_no_ty_param_bounds(ccx, it.span, generics, "enumeration");
let tpt = ty_of_item(ccx, it); let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty); write_ty_to_tcx(tcx, it.id, tpt.ty);
@ -566,7 +566,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
enum_definition.variants, enum_definition.variants,
generics); generics);
} }
ast::item_impl(ref generics, ref opt_trait_ref, selfty, ref ms) => { ast::ItemImpl(ref generics, ref opt_trait_ref, selfty, ref ms) => {
let i_ty_generics = ty_generics(ccx, generics, 0); let i_ty_generics = ty_generics(ccx, generics, 0);
let selfty = ccx.to_ty(&ExplicitRscope, selfty); let selfty = ccx.to_ty(&ExplicitRscope, selfty);
write_ty_to_tcx(tcx, it.id, selfty); write_ty_to_tcx(tcx, it.id, selfty);
@ -585,7 +585,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
// from the trait, not the impl. Forcing the visibility to be public // from the trait, not the impl. Forcing the visibility to be public
// makes things sorta work. // makes things sorta work.
let parent_visibility = if opt_trait_ref.is_some() { let parent_visibility = if opt_trait_ref.is_some() {
ast::public ast::Public
} else { } else {
it.vis it.vis
}; };
@ -609,7 +609,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
} }
} }
} }
ast::item_trait(ref generics, _, ref trait_methods) => { ast::ItemTrait(ref generics, _, ref trait_methods) => {
let trait_def = trait_def_of_item(ccx, it); let trait_def = trait_def_of_item(ccx, it);
// Run convert_methods on the provided methods. // Run convert_methods on the provided methods.
@ -629,7 +629,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
// static trait methods. This is somewhat unfortunate. // static trait methods. This is somewhat unfortunate.
ensure_trait_methods(ccx, it.id); ensure_trait_methods(ccx, it.id);
} }
ast::item_struct(struct_def, ref generics) => { ast::ItemStruct(struct_def, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "structure"); ensure_no_ty_param_bounds(ccx, it.span, generics, "structure");
// Write the class type // Write the class type
@ -643,7 +643,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
convert_struct(ccx, struct_def, tpt, it.id); convert_struct(ccx, struct_def, tpt, it.id);
} }
ast::item_ty(_, ref generics) => { ast::ItemTy(_, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "type"); ensure_no_ty_param_bounds(ccx, it.span, generics, "type");
let tpt = ty_of_item(ccx, it); let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty); write_ty_to_tcx(tcx, it.id, tpt.ty);
@ -659,7 +659,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
} }
pub fn convert_struct(ccx: &CrateCtxt, pub fn convert_struct(ccx: &CrateCtxt,
struct_def: &ast::struct_def, struct_def: &ast::StructDef,
tpt: ty::ty_param_bounds_and_ty, tpt: ty::ty_param_bounds_and_ty,
id: ast::NodeId) { id: ast::NodeId) {
let tcx = ccx.tcx; let tcx = ccx.tcx;
@ -684,7 +684,7 @@ pub fn convert_struct(ccx: &CrateCtxt,
let mut tcache = tcx.tcache.borrow_mut(); let mut tcache = tcx.tcache.borrow_mut();
tcache.get().insert(local_def(ctor_id), tpt); tcache.get().insert(local_def(ctor_id), tpt);
} }
} else if struct_def.fields[0].node.kind == ast::unnamed_field { } else if struct_def.fields[0].node.kind == ast::UnnamedField {
// Tuple-like. // Tuple-like.
let inputs = { let inputs = {
let tcache = tcx.tcache.borrow(); let tcache = tcx.tcache.borrow();
@ -707,7 +707,7 @@ pub fn convert_struct(ccx: &CrateCtxt,
} }
} }
pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::foreign_item) { pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::ForeignItem) {
// As above, this call populates the type table with the converted // As above, this call populates the type table with the converted
// type of the foreign item. We simply write it into the node type // type of the foreign item. We simply write it into the node type
// table. // table.
@ -718,7 +718,7 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::foreign_item) {
// convenient way to extract the ABI. - ndm // convenient way to extract the ABI. - ndm
let items = ccx.tcx.items.borrow(); let items = ccx.tcx.items.borrow();
let abis = match items.get().find(&i.id) { let abis = match items.get().find(&i.id) {
Some(&ast_map::node_foreign_item(_, abis, _, _)) => abis, Some(&ast_map::NodeForeignItem(_, abis, _, _)) => abis,
ref x => { ref x => {
ccx.tcx.sess.bug(format!("unexpected sort of item \ ccx.tcx.sess.bug(format!("unexpected sort of item \
in get_item_ty(): {:?}", (*x))); in get_item_ty(): {:?}", (*x)));
@ -733,7 +733,7 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::foreign_item) {
} }
pub fn instantiate_trait_ref(ccx: &CrateCtxt, pub fn instantiate_trait_ref(ccx: &CrateCtxt,
ast_trait_ref: &ast::trait_ref, ast_trait_ref: &ast::TraitRef,
self_ty: ty::t) -> @ty::TraitRef self_ty: ty::t) -> @ty::TraitRef
{ {
/*! /*!
@ -772,13 +772,13 @@ fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> @ty::TraitDef {
let items = ccx.tcx.items.borrow(); let items = ccx.tcx.items.borrow();
match items.get().get(&trait_id.node) { match items.get().get(&trait_id.node) {
&ast_map::node_item(item, _) => trait_def_of_item(ccx, item), &ast_map::NodeItem(item, _) => trait_def_of_item(ccx, item),
_ => ccx.tcx.sess.bug(format!("get_trait_def({}): not an item", _ => ccx.tcx.sess.bug(format!("get_trait_def({}): not an item",
trait_id.node)) trait_id.node))
} }
} }
pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::item) -> @ty::TraitDef { pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> @ty::TraitDef {
let def_id = local_def(it.id); let def_id = local_def(it.id);
let tcx = ccx.tcx; let tcx = ccx.tcx;
{ {
@ -790,7 +790,7 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::item) -> @ty::TraitDef {
} }
match it.node { match it.node {
ast::item_trait(ref generics, ref supertraits, _) => { ast::ItemTrait(ref generics, ref supertraits, _) => {
let self_ty = ty::mk_self(tcx, def_id); let self_ty = ty::mk_self(tcx, def_id);
let ty_generics = ty_generics(ccx, generics, 0); let ty_generics = ty_generics(ccx, generics, 0);
let substs = mk_item_substs(ccx, &ty_generics, Some(self_ty)); let substs = mk_item_substs(ccx, &ty_generics, Some(self_ty));
@ -812,7 +812,7 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::item) -> @ty::TraitDef {
} }
} }
pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item) pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
-> ty::ty_param_bounds_and_ty { -> ty::ty_param_bounds_and_ty {
let def_id = local_def(it.id); let def_id = local_def(it.id);
let tcx = ccx.tcx; let tcx = ccx.tcx;
@ -824,7 +824,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
} }
} }
match it.node { match it.node {
ast::item_static(t, _, _) => { ast::ItemStatic(t, _, _) => {
let typ = ccx.to_ty(&ExplicitRscope, t); let typ = ccx.to_ty(&ExplicitRscope, t);
let tpt = no_params(typ); let tpt = no_params(typ);
@ -832,7 +832,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
tcache.get().insert(local_def(it.id), tpt); tcache.get().insert(local_def(it.id), tpt);
return tpt; return tpt;
} }
ast::item_fn(decl, purity, abi, ref generics, _) => { ast::ItemFn(decl, purity, abi, ref generics, _) => {
let ty_generics = ty_generics(ccx, generics, 0); let ty_generics = ty_generics(ccx, generics, 0);
let tofd = astconv::ty_of_bare_fn(ccx, let tofd = astconv::ty_of_bare_fn(ccx,
it.id, it.id,
@ -855,7 +855,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
tcache.get().insert(local_def(it.id), tpt); tcache.get().insert(local_def(it.id), tpt);
return tpt; return tpt;
} }
ast::item_ty(t, ref generics) => { ast::ItemTy(t, ref generics) => {
{ {
let mut tcache = tcx.tcache.borrow_mut(); let mut tcache = tcx.tcache.borrow_mut();
match tcache.get().find(&local_def(it.id)) { match tcache.get().find(&local_def(it.id)) {
@ -876,7 +876,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
tcache.get().insert(local_def(it.id), tpt); tcache.get().insert(local_def(it.id), tpt);
return tpt; return tpt;
} }
ast::item_enum(_, ref generics) => { ast::ItemEnum(_, ref generics) => {
// Create a new generic polytype. // Create a new generic polytype.
let ty_generics = ty_generics(ccx, generics, 0); let ty_generics = ty_generics(ccx, generics, 0);
let substs = mk_item_substs(ccx, &ty_generics, None); let substs = mk_item_substs(ccx, &ty_generics, None);
@ -890,12 +890,12 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
tcache.get().insert(local_def(it.id), tpt); tcache.get().insert(local_def(it.id), tpt);
return tpt; return tpt;
} }
ast::item_trait(..) => { ast::ItemTrait(..) => {
tcx.sess.span_bug( tcx.sess.span_bug(
it.span, it.span,
format!("Invoked ty_of_item on trait")); format!("Invoked ty_of_item on trait"));
} }
ast::item_struct(_, ref generics) => { ast::ItemStruct(_, ref generics) => {
let ty_generics = ty_generics(ccx, generics, 0); let ty_generics = ty_generics(ccx, generics, 0);
let substs = mk_item_substs(ccx, &ty_generics, None); let substs = mk_item_substs(ccx, &ty_generics, None);
let t = ty::mk_struct(tcx, local_def(it.id), substs); let t = ty::mk_struct(tcx, local_def(it.id), substs);
@ -908,25 +908,25 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
tcache.get().insert(local_def(it.id), tpt); tcache.get().insert(local_def(it.id), tpt);
return tpt; return tpt;
} }
ast::item_impl(..) | ast::item_mod(_) | ast::ItemImpl(..) | ast::ItemMod(_) |
ast::item_foreign_mod(_) => fail!(), ast::ItemForeignMod(_) => fail!(),
ast::item_mac(..) => fail!("item macros unimplemented") ast::ItemMac(..) => fail!("item macros unimplemented")
} }
} }
pub fn ty_of_foreign_item(ccx: &CrateCtxt, pub fn ty_of_foreign_item(ccx: &CrateCtxt,
it: &ast::foreign_item, it: &ast::ForeignItem,
abis: AbiSet) -> ty::ty_param_bounds_and_ty abis: AbiSet) -> ty::ty_param_bounds_and_ty
{ {
match it.node { match it.node {
ast::foreign_item_fn(fn_decl, ref generics) => { ast::ForeignItemFn(fn_decl, ref generics) => {
ty_of_foreign_fn_decl(ccx, ty_of_foreign_fn_decl(ccx,
fn_decl, fn_decl,
local_def(it.id), local_def(it.id),
generics, generics,
abis) abis)
} }
ast::foreign_item_static(t, _) => { ast::ForeignItemStatic(t, _) => {
ty::ty_param_bounds_and_ty { ty::ty_param_bounds_and_ty {
generics: ty::Generics { generics: ty::Generics {
type_param_defs: @~[], type_param_defs: @~[],
@ -1016,7 +1016,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
} }
pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt, pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
decl: &ast::fn_decl, decl: &ast::FnDecl,
def_id: ast::DefId, def_id: ast::DefId,
ast_generics: &ast::Generics, ast_generics: &ast::Generics,
abis: AbiSet) abis: AbiSet)
@ -1030,7 +1030,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
ccx.tcx, ccx.tcx,
ty::BareFnTy { ty::BareFnTy {
abis: abis, abis: abis,
purity: ast::unsafe_fn, purity: ast::UnsafeFn,
sig: ty::FnSig {binder_id: def_id.node, sig: ty::FnSig {binder_id: def_id.node,
inputs: input_tys, inputs: input_tys,
output: output_ty, output: output_ty,

View file

@ -63,7 +63,7 @@ use util::common::indent;
use util::ppaux::Repr; use util::ppaux::Repr;
use std::result; use std::result;
use syntax::ast::{Onceness, purity}; use syntax::ast::{Onceness, Purity};
use syntax::ast; use syntax::ast;
use syntax::opt_vec; use syntax::opt_vec;
use syntax::abi::AbiSet; use syntax::abi::AbiSet;
@ -245,7 +245,7 @@ pub trait Combine {
} }
} }
fn purities(&self, a: purity, b: purity) -> cres<purity>; fn purities(&self, a: Purity, b: Purity) -> cres<Purity>;
fn abis(&self, a: AbiSet, b: AbiSet) -> cres<AbiSet> { fn abis(&self, a: AbiSet, b: AbiSet) -> cres<AbiSet> {
if a == b { if a == b {
@ -591,7 +591,7 @@ pub fn super_tys<C:Combine>(this: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
this: &C, this: &C,
vid_is_expected: bool, vid_is_expected: bool,
vid: ty::FloatVid, vid: ty::FloatVid,
val: ast::float_ty) -> cres<ty::t> val: ast::FloatTy) -> cres<ty::t>
{ {
if_ok!(this.infcx().simple_var_t(vid_is_expected, vid, val)); if_ok!(this.infcx().simple_var_t(vid_is_expected, vid, val));
Ok(ty::mk_mach_float(val)) Ok(ty::mk_mach_float(val))

View file

@ -21,9 +21,9 @@ use middle::typeck::infer::to_str::InferStr;
use middle::typeck::infer::{cres, InferCtxt}; use middle::typeck::infer::{cres, InferCtxt};
use middle::typeck::infer::{TypeTrace, Subtype}; use middle::typeck::infer::{TypeTrace, Subtype};
use middle::typeck::infer::fold_regions_in_sig; use middle::typeck::infer::fold_regions_in_sig;
use syntax::ast::{Many, Once, extern_fn, impure_fn, MutImmutable, MutMutable}; use syntax::ast::{Many, Once, MutImmutable, MutMutable};
use syntax::ast::{unsafe_fn, NodeId}; use syntax::ast::{ExternFn, ImpureFn, UnsafeFn, NodeId};
use syntax::ast::{Onceness, purity}; use syntax::ast::{Onceness, Purity};
use std::hashmap::HashMap; use std::hashmap::HashMap;
use util::common::{indenter}; use util::common::{indenter};
use util::ppaux::mt_to_str; use util::ppaux::mt_to_str;
@ -81,11 +81,11 @@ impl Combine for Glb {
Lub(*self.get_ref()).tys(a, b) Lub(*self.get_ref()).tys(a, b)
} }
fn purities(&self, a: purity, b: purity) -> cres<purity> { fn purities(&self, a: Purity, b: Purity) -> cres<Purity> {
match (a, b) { match (a, b) {
(extern_fn, _) | (_, extern_fn) => Ok(extern_fn), (ExternFn, _) | (_, ExternFn) => Ok(ExternFn),
(impure_fn, _) | (_, impure_fn) => Ok(impure_fn), (ImpureFn, _) | (_, ImpureFn) => Ok(ImpureFn),
(unsafe_fn, unsafe_fn) => Ok(unsafe_fn) (UnsafeFn, UnsafeFn) => Ok(UnsafeFn)
} }
} }

View file

@ -22,9 +22,9 @@ use middle::typeck::infer::{cres, InferCtxt};
use middle::typeck::infer::fold_regions_in_sig; use middle::typeck::infer::fold_regions_in_sig;
use middle::typeck::infer::{TypeTrace, Subtype}; use middle::typeck::infer::{TypeTrace, Subtype};
use std::hashmap::HashMap; use std::hashmap::HashMap;
use syntax::ast::{Many, Once, extern_fn, impure_fn, NodeId}; use syntax::ast::{Many, Once, NodeId};
use syntax::ast::{unsafe_fn}; use syntax::ast::{ExternFn, ImpureFn, UnsafeFn};
use syntax::ast::{Onceness, purity}; use syntax::ast::{Onceness, Purity};
use util::ppaux::mt_to_str; use util::ppaux::mt_to_str;
pub struct Lub(CombineFields); // least-upper-bound: common supertype pub struct Lub(CombineFields); // least-upper-bound: common supertype
@ -79,11 +79,11 @@ impl Combine for Lub {
Glb(*self.get_ref()).tys(a, b) Glb(*self.get_ref()).tys(a, b)
} }
fn purities(&self, a: purity, b: purity) -> cres<purity> { fn purities(&self, a: Purity, b: Purity) -> cres<Purity> {
match (a, b) { match (a, b) {
(unsafe_fn, _) | (_, unsafe_fn) => Ok(unsafe_fn), (UnsafeFn, _) | (_, UnsafeFn) => Ok(UnsafeFn),
(impure_fn, _) | (_, impure_fn) => Ok(impure_fn), (ImpureFn, _) | (_, ImpureFn) => Ok(ImpureFn),
(extern_fn, extern_fn) => Ok(extern_fn), (ExternFn, ExternFn) => Ok(ExternFn),
} }
} }

View file

@ -89,7 +89,7 @@ pub struct InferCtxt {
// Map from floating variable to the kind of float it represents // Map from floating variable to the kind of float it represents
float_var_bindings: RefCell<ValsAndBindings<ty::FloatVid, float_var_bindings: RefCell<ValsAndBindings<ty::FloatVid,
Option<ast::float_ty>>>, Option<ast::FloatTy>>>,
float_var_counter: Cell<uint>, float_var_counter: Cell<uint>,
// For region variables. // For region variables.

View file

@ -260,8 +260,7 @@ impl ResolveState {
if self.should(force_ivar) { if self.should(force_ivar) {
// As a last resort, default to int. // As a last resort, default to int.
let ty = ty::mk_int(); let ty = ty::mk_int();
self.infcx.set(vid, self.infcx.set(vid, Root(Some(IntType(ast::TyI)), node.rank));
Root(Some(IntType(ast::ty_i)), node.rank));
ty ty
} else { } else {
ty::mk_int_var(self.infcx.tcx, vid) ty::mk_int_var(self.infcx.tcx, vid)
@ -282,7 +281,7 @@ impl ResolveState {
if self.should(force_fvar) { if self.should(force_fvar) {
// As a last resort, default to f64. // As a last resort, default to f64.
let ty = ty::mk_f64(); let ty = ty::mk_f64();
self.infcx.set(vid, Root(Some(ast::ty_f64), node.rank)); self.infcx.set(vid, Root(Some(ast::TyF64), node.rank));
ty ty
} else { } else {
ty::mk_float_var(self.infcx.tcx, vid) ty::mk_float_var(self.infcx.tcx, vid)

View file

@ -25,7 +25,7 @@ use middle::typeck::infer::{TypeTrace, Subtype};
use util::common::{indenter}; use util::common::{indenter};
use util::ppaux::bound_region_to_str; use util::ppaux::bound_region_to_str;
use syntax::ast::{Onceness, purity}; use syntax::ast::{Onceness, Purity};
pub struct Sub(CombineFields); // "subtype", "subregion" etc pub struct Sub(CombineFields); // "subtype", "subregion" etc
@ -87,7 +87,7 @@ impl Combine for Sub {
} }
} }
fn purities(&self, a: purity, b: purity) -> cres<purity> { fn purities(&self, a: Purity, b: Purity) -> cres<Purity> {
self.lub().purities(a, b).compare(b, || { self.lub().purities(a, b).compare(b, || {
ty::terr_purity_mismatch(expected_found(self, a, b)) ty::terr_purity_mismatch(expected_found(self, a, b))
}) })

View file

@ -105,7 +105,7 @@ impl Env {
}; };
fn search_mod(self: &Env, fn search_mod(self: &Env,
m: &ast::_mod, m: &ast::Mod,
idx: uint, idx: uint,
names: &[~str]) -> Option<ast::node_id> { names: &[~str]) -> Option<ast::node_id> {
assert!(idx < names.len()); assert!(idx < names.len());
@ -118,7 +118,7 @@ impl Env {
} }
fn search(self: &Env, fn search(self: &Env,
it: @ast::item, it: @ast::Item,
idx: uint, idx: uint,
names: &[~str]) -> Option<ast::node_id> { names: &[~str]) -> Option<ast::node_id> {
if idx == names.len() { if idx == names.len() {
@ -126,18 +126,18 @@ impl Env {
} }
return match it.node { return match it.node {
ast::item_const(..) | ast::item_fn(..) | ast::ItemConst(..) | ast::ItemFn(..) |
ast::item_foreign_mod(..) | ast::item_ty(..) => { ast::ItemForeignMod(..) | ast::ItemTy(..) => {
None None
} }
ast::item_enum(..) | ast::item_struct(..) | ast::ItemEnum(..) | ast::ItemStruct(..) |
ast::item_trait(..) | ast::item_impl(..) | ast::ItemTrait(..) | ast::ItemImpl(..) |
ast::item_mac(..) => { ast::ItemMac(..) => {
None None
} }
ast::item_mod(ref m) => { ast::ItemMod(ref m) => {
search_mod(self, m, idx, names) search_mod(self, m, idx, names)
} }
}; };
@ -185,7 +185,7 @@ impl Env {
let inputs = input_tys.map(|t| {mode: ast::expl(ast::by_copy), let inputs = input_tys.map(|t| {mode: ast::expl(ast::by_copy),
ty: *t}); ty: *t});
ty::mk_fn(self.tcx, FnTyBase { ty::mk_fn(self.tcx, FnTyBase {
meta: FnMeta {purity: ast::impure_fn, meta: FnMeta {purity: ast::ImpureFn,
proto: ast::ProtoBare, proto: ast::ProtoBare,
onceness: ast::Many, onceness: ast::Many,
region: ty::ReStatic, region: ty::ReStatic,

View file

@ -82,7 +82,7 @@ impl InferStr for IntVarValue {
} }
} }
impl InferStr for ast::float_ty { impl InferStr for ast::FloatTy {
fn inf_str(&self, _cx: &InferCtxt) -> ~str { fn inf_str(&self, _cx: &InferCtxt) -> ~str {
self.to_str() self.to_str()
} }

View file

@ -296,16 +296,15 @@ impl SimplyUnifiable for IntVarValue {
} }
} }
impl UnifyVid<Option<ast::float_ty>> for ty::FloatVid { impl UnifyVid<Option<ast::FloatTy>> for ty::FloatVid {
fn appropriate_vals_and_bindings<'v>(infcx: &'v InferCtxt) fn appropriate_vals_and_bindings<'v>(infcx: &'v InferCtxt)
-> &'v RefCell<ValsAndBindings<ty::FloatVid, -> &'v RefCell<ValsAndBindings<ty::FloatVid, Option<ast::FloatTy>>> {
Option<ast::float_ty>>> {
return &infcx.float_var_bindings; return &infcx.float_var_bindings;
} }
} }
impl SimplyUnifiable for ast::float_ty { impl SimplyUnifiable for ast::FloatTy {
fn to_type_err(err: expected_found<ast::float_ty>) -> ty::type_err { fn to_type_err(err: expected_found<ast::FloatTy>) -> ty::type_err {
return ty::terr_float_mismatch(err); return ty::terr_float_mismatch(err);
} }
} }

View file

@ -152,7 +152,7 @@ pub struct method_map_entry {
self_mode: ty::SelfMode, self_mode: ty::SelfMode,
// the type of explicit self on the method // the type of explicit self on the method
explicit_self: ast::explicit_self_, explicit_self: ast::ExplicitSelf_,
// method details being invoked // method details being invoked
origin: method_origin, origin: method_origin,
@ -352,9 +352,9 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
ty::ty_bare_fn(..) => { ty::ty_bare_fn(..) => {
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&main_id) { match items.get().find(&main_id) {
Some(&ast_map::node_item(it,_)) => { Some(&ast_map::NodeItem(it,_)) => {
match it.node { match it.node {
ast::item_fn(_, _, _, ref ps, _) ast::ItemFn(_, _, _, ref ps, _)
if ps.is_parameterized() => { if ps.is_parameterized() => {
tcx.sess.span_err( tcx.sess.span_err(
main_span, main_span,
@ -367,7 +367,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
_ => () _ => ()
} }
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy { let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
purity: ast::impure_fn, purity: ast::ImpureFn,
abis: abi::AbiSet::Rust(), abis: abi::AbiSet::Rust(),
sig: ty::FnSig { sig: ty::FnSig {
binder_id: main_id, binder_id: main_id,
@ -398,9 +398,9 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
ty::ty_bare_fn(_) => { ty::ty_bare_fn(_) => {
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&start_id) { match items.get().find(&start_id) {
Some(&ast_map::node_item(it,_)) => { Some(&ast_map::NodeItem(it,_)) => {
match it.node { match it.node {
ast::item_fn(_,_,_,ref ps,_) ast::ItemFn(_,_,_,ref ps,_)
if ps.is_parameterized() => { if ps.is_parameterized() => {
tcx.sess.span_err( tcx.sess.span_err(
start_span, start_span,
@ -414,7 +414,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
} }
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy { let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
purity: ast::impure_fn, purity: ast::ImpureFn,
abis: abi::AbiSet::Rust(), abis: abi::AbiSet::Rust(),
sig: ty::FnSig { sig: ty::FnSig {
binder_id: start_id, binder_id: start_id,

View file

@ -328,7 +328,7 @@ impl<'a> TermsContext<'a> {
} }
impl<'a> Visitor<()> for TermsContext<'a> { impl<'a> Visitor<()> for TermsContext<'a> {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
debug!("add_inferreds for item {}", item.repr(self.tcx)); debug!("add_inferreds for item {}", item.repr(self.tcx));
let inferreds_on_entry = self.num_inferred(); let inferreds_on_entry = self.num_inferred();
@ -337,16 +337,16 @@ impl<'a> Visitor<()> for TermsContext<'a> {
// tcx, we rely on the fact that all inferreds for a particular // tcx, we rely on the fact that all inferreds for a particular
// item are assigned continuous indices. // item are assigned continuous indices.
match item.node { match item.node {
ast::item_trait(..) => { ast::ItemTrait(..) => {
self.add_inferred(item.id, SelfParam, 0, item.id); self.add_inferred(item.id, SelfParam, 0, item.id);
} }
_ => { } _ => { }
} }
match item.node { match item.node {
ast::item_enum(_, ref generics) | ast::ItemEnum(_, ref generics) |
ast::item_struct(_, ref generics) | ast::ItemStruct(_, ref generics) |
ast::item_trait(ref generics, _, _) => { ast::ItemTrait(ref generics, _, _) => {
for (i, p) in generics.lifetimes.iter().enumerate() { for (i, p) in generics.lifetimes.iter().enumerate() {
self.add_inferred(item.id, RegionParam, i, p.id); self.add_inferred(item.id, RegionParam, i, p.id);
} }
@ -374,13 +374,13 @@ impl<'a> Visitor<()> for TermsContext<'a> {
visit::walk_item(self, item, ()); visit::walk_item(self, item, ());
} }
ast::item_impl(..) | ast::ItemImpl(..) |
ast::item_static(..) | ast::ItemStatic(..) |
ast::item_fn(..) | ast::ItemFn(..) |
ast::item_mod(..) | ast::ItemMod(..) |
ast::item_foreign_mod(..) | ast::ItemForeignMod(..) |
ast::item_ty(..) | ast::ItemTy(..) |
ast::item_mac(..) => { ast::ItemMac(..) => {
visit::walk_item(self, item, ()); visit::walk_item(self, item, ());
} }
} }
@ -433,12 +433,12 @@ fn add_constraints_from_crate<'a>(terms_cx: TermsContext<'a>,
} }
impl<'a> Visitor<()> for ConstraintContext<'a> { impl<'a> Visitor<()> for ConstraintContext<'a> {
fn visit_item(&mut self, item: &ast::item, _: ()) { fn visit_item(&mut self, item: &ast::Item, _: ()) {
let did = ast_util::local_def(item.id); let did = ast_util::local_def(item.id);
let tcx = self.terms_cx.tcx; let tcx = self.terms_cx.tcx;
match item.node { match item.node {
ast::item_enum(ref enum_definition, _) => { ast::ItemEnum(ref enum_definition, _) => {
// Hack: If we directly call `ty::enum_variants`, it // Hack: If we directly call `ty::enum_variants`, it
// annoyingly takes it upon itself to run off and // annoyingly takes it upon itself to run off and
// evaluate the discriminants eagerly (*grumpy* that's // evaluate the discriminants eagerly (*grumpy* that's
@ -460,7 +460,7 @@ impl<'a> Visitor<()> for ConstraintContext<'a> {
} }
} }
ast::item_struct(..) => { ast::ItemStruct(..) => {
let struct_fields = ty::lookup_struct_fields(tcx, did); let struct_fields = ty::lookup_struct_fields(tcx, did);
for field_info in struct_fields.iter() { for field_info in struct_fields.iter() {
assert_eq!(field_info.id.crate, ast::LOCAL_CRATE); assert_eq!(field_info.id.crate, ast::LOCAL_CRATE);
@ -469,7 +469,7 @@ impl<'a> Visitor<()> for ConstraintContext<'a> {
} }
} }
ast::item_trait(..) => { ast::ItemTrait(..) => {
let methods = ty::trait_methods(tcx, did); let methods = ty::trait_methods(tcx, did);
for method in methods.iter() { for method in methods.iter() {
match method.transformed_self_ty { match method.transformed_self_ty {
@ -493,13 +493,13 @@ impl<'a> Visitor<()> for ConstraintContext<'a> {
} }
} }
ast::item_static(..) | ast::ItemStatic(..) |
ast::item_fn(..) | ast::ItemFn(..) |
ast::item_mod(..) | ast::ItemMod(..) |
ast::item_foreign_mod(..) | ast::ItemForeignMod(..) |
ast::item_ty(..) | ast::ItemTy(..) |
ast::item_impl(..) | ast::ItemImpl(..) |
ast::item_mac(..) => { ast::ItemMac(..) => {
visit::walk_item(self, item, ()); visit::walk_item(self, item, ());
} }
} }

View file

@ -74,13 +74,13 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
ReScope(node_id) => { ReScope(node_id) => {
let items = cx.items.borrow(); let items = cx.items.borrow();
match items.get().find(&node_id) { match items.get().find(&node_id) {
Some(&ast_map::node_block(ref blk)) => { Some(&ast_map::NodeBlock(ref blk)) => {
explain_span(cx, "block", blk.span) explain_span(cx, "block", blk.span)
} }
Some(&ast_map::node_callee_scope(expr)) => { Some(&ast_map::NodeCalleeScope(expr)) => {
explain_span(cx, "callee", expr.span) explain_span(cx, "callee", expr.span)
} }
Some(&ast_map::node_expr(expr)) => { Some(&ast_map::NodeExpr(expr)) => {
match expr.node { match expr.node {
ast::ExprCall(..) => explain_span(cx, "call", expr.span), ast::ExprCall(..) => explain_span(cx, "call", expr.span),
ast::ExprMethodCall(..) => { ast::ExprMethodCall(..) => {
@ -90,11 +90,11 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
_ => explain_span(cx, "expression", expr.span) _ => explain_span(cx, "expression", expr.span)
} }
} }
Some(&ast_map::node_stmt(stmt)) => { Some(&ast_map::NodeStmt(stmt)) => {
explain_span(cx, "statement", stmt.span) explain_span(cx, "statement", stmt.span)
} }
Some(&ast_map::node_item(it, _)) if (match it.node { Some(&ast_map::NodeItem(it, _)) if (match it.node {
ast::item_fn(..) => true, _ => false}) => { ast::ItemFn(..) => true, _ => false}) => {
explain_span(cx, "function body", it.span) explain_span(cx, "function body", it.span)
} }
Some(_) | None => { Some(_) | None => {
@ -116,12 +116,12 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
let items = cx.items.borrow(); let items = cx.items.borrow();
match items.get().find(&fr.scope_id) { match items.get().find(&fr.scope_id) {
Some(&ast_map::node_block(ref blk)) => { Some(&ast_map::NodeBlock(ref blk)) => {
let (msg, opt_span) = explain_span(cx, "block", blk.span); let (msg, opt_span) = explain_span(cx, "block", blk.span);
(format!("{} {}", prefix, msg), opt_span) (format!("{} {}", prefix, msg), opt_span)
} }
Some(&ast_map::node_item(it, _)) if match it.node { Some(&ast_map::NodeItem(it, _)) if match it.node {
ast::item_impl(..) => true, _ => false} => { ast::ItemImpl(..) => true, _ => false} => {
let (msg, opt_span) = explain_span(cx, "impl", it.span); let (msg, opt_span) = explain_span(cx, "impl", it.span);
(format!("{} {}", prefix, msg), opt_span) (format!("{} {}", prefix, msg), opt_span)
} }
@ -176,11 +176,11 @@ pub fn bound_region_to_str(cx: ctxt,
pub fn ReScope_id_to_str(cx: ctxt, node_id: ast::NodeId) -> ~str { pub fn ReScope_id_to_str(cx: ctxt, node_id: ast::NodeId) -> ~str {
let items = cx.items.borrow(); let items = cx.items.borrow();
match items.get().find(&node_id) { match items.get().find(&node_id) {
Some(&ast_map::node_block(ref blk)) => { Some(&ast_map::NodeBlock(ref blk)) => {
format!("<block at {}>", format!("<block at {}>",
cx.sess.codemap.span_to_str(blk.span)) cx.sess.codemap.span_to_str(blk.span))
} }
Some(&ast_map::node_expr(expr)) => { Some(&ast_map::NodeExpr(expr)) => {
match expr.node { match expr.node {
ast::ExprCall(..) => { ast::ExprCall(..) => {
format!("<call at {}>", format!("<call at {}>",
@ -314,7 +314,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_to_str(cx, input) ty_to_str(cx, input)
} }
fn bare_fn_to_str(cx: ctxt, fn bare_fn_to_str(cx: ctxt,
purity: ast::purity, purity: ast::Purity,
abis: AbiSet, abis: AbiSet,
ident: Option<ast::Ident>, ident: Option<ast::Ident>,
sig: &ty::FnSig) sig: &ty::FnSig)
@ -326,7 +326,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
}; };
match purity { match purity {
ast::impure_fn => {} ast::ImpureFn => {}
_ => { _ => {
s.push_str(purity.to_str()); s.push_str(purity.to_str());
s.push_char(' '); s.push_char(' ');
@ -368,7 +368,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
} }
match cty.purity { match cty.purity {
ast::impure_fn => {} ast::ImpureFn => {}
_ => { _ => {
s.push_str(cty.purity.to_str()); s.push_str(cty.purity.to_str());
s.push_char(' '); s.push_char(' ');
@ -449,9 +449,9 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_bot => ~"!", ty_bot => ~"!",
ty_bool => ~"bool", ty_bool => ~"bool",
ty_char => ~"char", ty_char => ~"char",
ty_int(ast::ty_i) => ~"int", ty_int(ast::TyI) => ~"int",
ty_int(t) => ast_util::int_ty_to_str(t), ty_int(t) => ast_util::int_ty_to_str(t),
ty_uint(ast::ty_u) => ~"uint", ty_uint(ast::TyU) => ~"uint",
ty_uint(t) => ast_util::uint_ty_to_str(t), ty_uint(t) => ast_util::uint_ty_to_str(t),
ty_float(t) => ast_util::float_ty_to_str(t), ty_float(t) => ast_util::float_ty_to_str(t),
ty_box(typ) => ~"@" + ty_to_str(cx, typ), ty_box(typ) => ~"@" + ty_to_str(cx, typ),
@ -665,7 +665,7 @@ impl Repr for ast::Expr {
} }
} }
impl Repr for ast::item { impl Repr for ast::Item {
fn repr(&self, tcx: ctxt) -> ~str { fn repr(&self, tcx: ctxt) -> ~str {
format!("item({})", format!("item({})",
ast_map::node_id_to_str(tcx.items, ast_map::node_id_to_str(tcx.items,
@ -746,12 +746,12 @@ impl Repr for ast::DefId {
{ {
let items = tcx.items.borrow(); let items = tcx.items.borrow();
match items.get().find(&self.node) { match items.get().find(&self.node) {
Some(&ast_map::node_item(..)) | Some(&ast_map::NodeItem(..)) |
Some(&ast_map::node_foreign_item(..)) | Some(&ast_map::NodeForeignItem(..)) |
Some(&ast_map::node_method(..)) | Some(&ast_map::NodeMethod(..)) |
Some(&ast_map::node_trait_method(..)) | Some(&ast_map::NodeTraitMethod(..)) |
Some(&ast_map::node_variant(..)) | Some(&ast_map::NodeVariant(..)) |
Some(&ast_map::node_struct_ctor(..)) => { Some(&ast_map::NodeStructCtor(..)) => {
return format!("{:?}:{}", return format!("{:?}:{}",
*self, *self,
ty::item_path_str(tcx, *self)); ty::item_path_str(tcx, *self));
@ -815,13 +815,13 @@ impl Repr for ast::Ident {
} }
} }
impl Repr for ast::explicit_self_ { impl Repr for ast::ExplicitSelf_ {
fn repr(&self, _tcx: ctxt) -> ~str { fn repr(&self, _tcx: ctxt) -> ~str {
format!("{:?}", *self) format!("{:?}", *self)
} }
} }
impl Repr for ast::visibility { impl Repr for ast::Visibility {
fn repr(&self, _tcx: ctxt) -> ~str { fn repr(&self, _tcx: ctxt) -> ~str {
format!("{:?}", *self) format!("{:?}", *self)
} }
@ -911,12 +911,12 @@ impl Repr for ty::vstore {
} }
} }
impl Repr for ast_map::path_elt { impl Repr for ast_map::PathElem {
fn repr(&self, tcx: ctxt) -> ~str { fn repr(&self, tcx: ctxt) -> ~str {
match *self { match *self {
ast_map::path_mod(id) => id.repr(tcx), ast_map::PathMod(id) => id.repr(tcx),
ast_map::path_name(id) => id.repr(tcx), ast_map::PathName(id) => id.repr(tcx),
ast_map::path_pretty_name(id, _) => id.repr(tcx), ast_map::PathPrettyName(id, _) => id.repr(tcx),
} }
} }
} }

View file

@ -324,11 +324,11 @@ impl Clean<Generics> for ast::Generics {
pub struct Method { pub struct Method {
generics: Generics, generics: Generics,
self_: SelfTy, self_: SelfTy,
purity: ast::purity, purity: ast::Purity,
decl: FnDecl, decl: FnDecl,
} }
impl Clean<Item> for ast::method { impl Clean<Item> for ast::Method {
fn clean(&self) -> Item { fn clean(&self) -> Item {
Item { Item {
name: Some(self.ident.clean()), name: Some(self.ident.clean()),
@ -348,7 +348,7 @@ impl Clean<Item> for ast::method {
#[deriving(Clone, Encodable, Decodable)] #[deriving(Clone, Encodable, Decodable)]
pub struct TyMethod { pub struct TyMethod {
purity: ast::purity, purity: ast::Purity,
decl: FnDecl, decl: FnDecl,
generics: Generics, generics: Generics,
self_: SelfTy, self_: SelfTy,
@ -381,14 +381,14 @@ pub enum SelfTy {
SelfOwned, SelfOwned,
} }
impl Clean<SelfTy> for ast::explicit_self { impl Clean<SelfTy> for ast::ExplicitSelf {
fn clean(&self) -> SelfTy { fn clean(&self) -> SelfTy {
match self.node { match self.node {
ast::sty_static => SelfStatic, ast::SelfStatic => SelfStatic,
ast::sty_value(_) => SelfValue, ast::SelfValue(_) => SelfValue,
ast::sty_uniq(_) => SelfOwned, ast::SelfUniq(_) => SelfOwned,
ast::sty_region(lt, mt) => SelfBorrowed(lt.clean(), mt.clean()), ast::SelfRegion(lt, mt) => SelfBorrowed(lt.clean(), mt.clean()),
ast::sty_box(mt) => SelfManaged(mt.clean()), ast::SelfBox(mt) => SelfManaged(mt.clean()),
} }
} }
} }
@ -397,7 +397,7 @@ impl Clean<SelfTy> for ast::explicit_self {
pub struct Function { pub struct Function {
decl: FnDecl, decl: FnDecl,
generics: Generics, generics: Generics,
purity: ast::purity, purity: ast::Purity,
} }
impl Clean<Item> for doctree::Function { impl Clean<Item> for doctree::Function {
@ -424,11 +424,11 @@ pub struct ClosureDecl {
lifetimes: ~[Lifetime], lifetimes: ~[Lifetime],
decl: FnDecl, decl: FnDecl,
onceness: ast::Onceness, onceness: ast::Onceness,
purity: ast::purity, purity: ast::Purity,
bounds: ~[TyParamBound] bounds: ~[TyParamBound]
} }
impl Clean<ClosureDecl> for ast::TyClosure { impl Clean<ClosureDecl> for ast::ClosureTy {
fn clean(&self) -> ClosureDecl { fn clean(&self) -> ClosureDecl {
ClosureDecl { ClosureDecl {
sigil: self.sigil, sigil: self.sigil,
@ -453,7 +453,7 @@ pub struct FnDecl {
attrs: ~[Attribute] attrs: ~[Attribute]
} }
impl Clean<FnDecl> for ast::fn_decl { impl Clean<FnDecl> for ast::FnDecl {
fn clean(&self) -> FnDecl { fn clean(&self) -> FnDecl {
FnDecl { FnDecl {
inputs: self.inputs.iter().map(|x| x.clean()).collect(), inputs: self.inputs.iter().map(|x| x.clean()).collect(),
@ -471,7 +471,7 @@ pub struct Argument {
id: ast::NodeId id: ast::NodeId
} }
impl Clean<Argument> for ast::arg { impl Clean<Argument> for ast::Arg {
fn clean(&self) -> Argument { fn clean(&self) -> Argument {
Argument { Argument {
name: name_from_pat(self.pat), name: name_from_pat(self.pat),
@ -487,11 +487,11 @@ pub enum RetStyle {
Return Return
} }
impl Clean<RetStyle> for ast::ret_style { impl Clean<RetStyle> for ast::RetStyle {
fn clean(&self) -> RetStyle { fn clean(&self) -> RetStyle {
match *self { match *self {
ast::return_val => Return, ast::Return => Return,
ast::noreturn => NoReturn ast::NoReturn => NoReturn
} }
} }
} }
@ -520,7 +520,7 @@ impl Clean<Item> for doctree::Trait {
} }
} }
impl Clean<Type> for ast::trait_ref { impl Clean<Type> for ast::TraitRef {
fn clean(&self) -> Type { fn clean(&self) -> Type {
resolve_type(self.path.clean(), None, self.ref_id) resolve_type(self.path.clean(), None, self.ref_id)
} }
@ -553,11 +553,11 @@ impl TraitMethod {
} }
} }
impl Clean<TraitMethod> for ast::trait_method { impl Clean<TraitMethod> for ast::TraitMethod {
fn clean(&self) -> TraitMethod { fn clean(&self) -> TraitMethod {
match self { match self {
&ast::required(ref t) => Required(t.clean()), &ast::Required(ref t) => Required(t.clean()),
&ast::provided(ref t) => Provided(t.clean()), &ast::Provided(ref t) => Provided(t.clean()),
} }
} }
} }
@ -567,7 +567,7 @@ impl Clean<TraitMethod> for ast::trait_method {
/// it does not preserve mutability or boxes. /// it does not preserve mutability or boxes.
#[deriving(Clone, Encodable, Decodable)] #[deriving(Clone, Encodable, Decodable)]
pub enum Type { pub enum Type {
/// structs/enums/traits (anything that'd be an ast::ty_path) /// structs/enums/traits (anything that'd be an ast::TyPath)
ResolvedPath { ResolvedPath {
path: Path, path: Path,
typarams: Option<~[TyParamBound]>, typarams: Option<~[TyParamBound]>,
@ -589,7 +589,7 @@ pub enum Type {
/// For references to self /// For references to self
Self(ast::NodeId), Self(ast::NodeId),
/// Primitives are just the fixed-size numeric types (plus int/uint/float), and char. /// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
Primitive(ast::prim_ty), Primitive(ast::PrimTy),
Closure(~ClosureDecl), Closure(~ClosureDecl),
/// extern "ABI" fn /// extern "ABI" fn
BareFunction(~BareFunctionDecl), BareFunction(~BareFunctionDecl),
@ -650,10 +650,10 @@ pub struct StructField {
type_: Type, type_: Type,
} }
impl Clean<Item> for ast::struct_field { impl Clean<Item> for ast::StructField {
fn clean(&self) -> Item { fn clean(&self) -> Item {
let (name, vis) = match self.node.kind { let (name, vis) = match self.node.kind {
ast::named_field(id, vis) => (Some(id), Some(vis)), ast::NamedField(id, vis) => (Some(id), Some(vis)),
_ => (None, None) _ => (None, None)
}; };
Item { Item {
@ -669,9 +669,9 @@ impl Clean<Item> for ast::struct_field {
} }
} }
pub type Visibility = ast::visibility; pub type Visibility = ast::Visibility;
impl Clean<Option<Visibility>> for ast::visibility { impl Clean<Option<Visibility>> for ast::Visibility {
fn clean(&self) -> Option<Visibility> { fn clean(&self) -> Option<Visibility> {
Some(*self) Some(*self)
} }
@ -713,7 +713,7 @@ pub struct VariantStruct {
fields_stripped: bool, fields_stripped: bool,
} }
impl Clean<VariantStruct> for syntax::ast::struct_def { impl Clean<VariantStruct> for syntax::ast::StructDef {
fn clean(&self) -> VariantStruct { fn clean(&self) -> VariantStruct {
VariantStruct { VariantStruct {
struct_type: doctree::struct_type_from_def(self), struct_type: doctree::struct_type_from_def(self),
@ -774,17 +774,17 @@ pub enum VariantKind {
StructVariant(VariantStruct), StructVariant(VariantStruct),
} }
impl Clean<VariantKind> for ast::variant_kind { impl Clean<VariantKind> for ast::VariantKind {
fn clean(&self) -> VariantKind { fn clean(&self) -> VariantKind {
match self { match self {
&ast::tuple_variant_kind(ref args) => { &ast::TupleVariantKind(ref args) => {
if args.len() == 0 { if args.len() == 0 {
CLikeVariant CLikeVariant
} else { } else {
TupleVariant(args.iter().map(|x| x.ty.clean()).collect()) TupleVariant(args.iter().map(|x| x.ty.clean()).collect())
} }
}, },
&ast::struct_variant_kind(ref sd) => StructVariant(sd.clean()), &ast::StructVariantKind(ref sd) => StructVariant(sd.clean()),
} }
} }
} }
@ -892,13 +892,13 @@ impl Clean<Item> for doctree::Typedef {
#[deriving(Clone, Encodable, Decodable)] #[deriving(Clone, Encodable, Decodable)]
pub struct BareFunctionDecl { pub struct BareFunctionDecl {
purity: ast::purity, purity: ast::Purity,
generics: Generics, generics: Generics,
decl: FnDecl, decl: FnDecl,
abi: ~str abi: ~str
} }
impl Clean<BareFunctionDecl> for ast::TyBareFn { impl Clean<BareFunctionDecl> for ast::BareFnTy {
fn clean(&self) -> BareFunctionDecl { fn clean(&self) -> BareFunctionDecl {
BareFunctionDecl { BareFunctionDecl {
purity: self.purity, purity: self.purity,
@ -986,7 +986,7 @@ pub struct ViewItem {
inner: ViewItemInner inner: ViewItemInner
} }
impl Clean<Item> for ast::view_item { impl Clean<Item> for ast::ViewItem {
fn clean(&self) -> Item { fn clean(&self) -> Item {
Item { Item {
name: None, name: None,
@ -1007,12 +1007,12 @@ pub enum ViewItemInner {
Import(~[ViewPath]) Import(~[ViewPath])
} }
impl Clean<ViewItemInner> for ast::view_item_ { impl Clean<ViewItemInner> for ast::ViewItem_ {
fn clean(&self) -> ViewItemInner { fn clean(&self) -> ViewItemInner {
match self { match self {
&ast::view_item_extern_mod(ref i, ref p, ref id) => &ast::ViewItemExternMod(ref i, ref p, ref id) =>
ExternMod(i.clean(), p.map(|(ref x, _)| x.to_owned()), *id), ExternMod(i.clean(), p.map(|(ref x, _)| x.to_owned()), *id),
&ast::view_item_use(ref vp) => Import(vp.clean()) &ast::ViewItemUse(ref vp) => Import(vp.clean())
} }
} }
} }
@ -1033,14 +1033,14 @@ pub struct ImportSource {
did: Option<ast::DefId>, did: Option<ast::DefId>,
} }
impl Clean<ViewPath> for ast::view_path { impl Clean<ViewPath> for ast::ViewPath {
fn clean(&self) -> ViewPath { fn clean(&self) -> ViewPath {
match self.node { match self.node {
ast::view_path_simple(ref i, ref p, id) => ast::ViewPathSimple(ref i, ref p, id) =>
SimpleImport(i.clean(), resolve_use_source(p.clean(), id)), SimpleImport(i.clean(), resolve_use_source(p.clean(), id)),
ast::view_path_glob(ref p, id) => ast::ViewPathGlob(ref p, id) =>
GlobImport(resolve_use_source(p.clean(), id)), GlobImport(resolve_use_source(p.clean(), id)),
ast::view_path_list(ref p, ref pl, id) => ast::ViewPathList(ref p, ref pl, id) =>
ImportList(resolve_use_source(p.clean(), id), pl.clean()), ImportList(resolve_use_source(p.clean(), id), pl.clean()),
} }
} }
@ -1052,7 +1052,7 @@ pub struct ViewListIdent {
source: Option<ast::DefId>, source: Option<ast::DefId>,
} }
impl Clean<ViewListIdent> for ast::path_list_ident { impl Clean<ViewListIdent> for ast::PathListIdent {
fn clean(&self) -> ViewListIdent { fn clean(&self) -> ViewListIdent {
ViewListIdent { ViewListIdent {
name: self.node.name.clean(), name: self.node.name.clean(),
@ -1061,23 +1061,23 @@ impl Clean<ViewListIdent> for ast::path_list_ident {
} }
} }
impl Clean<~[Item]> for ast::foreign_mod { impl Clean<~[Item]> for ast::ForeignMod {
fn clean(&self) -> ~[Item] { fn clean(&self) -> ~[Item] {
self.items.clean() self.items.clean()
} }
} }
impl Clean<Item> for ast::foreign_item { impl Clean<Item> for ast::ForeignItem {
fn clean(&self) -> Item { fn clean(&self) -> Item {
let inner = match self.node { let inner = match self.node {
ast::foreign_item_fn(ref decl, ref generics) => { ast::ForeignItemFn(ref decl, ref generics) => {
ForeignFunctionItem(Function { ForeignFunctionItem(Function {
decl: decl.clean(), decl: decl.clean(),
generics: generics.clean(), generics: generics.clean(),
purity: ast::extern_fn, purity: ast::ExternFn,
}) })
} }
ast::foreign_item_static(ref ty, mutbl) => { ast::ForeignItemStatic(ref ty, mutbl) => {
ForeignStaticItem(Static { ForeignStaticItem(Static {
type_: ty.clean(), type_: ty.clean(),
mutability: if mutbl {Mutable} else {Immutable}, mutability: if mutbl {Mutable} else {Immutable},
@ -1115,18 +1115,18 @@ impl ToSource for syntax::codemap::Span {
} }
} }
fn lit_to_str(lit: &ast::lit) -> ~str { fn lit_to_str(lit: &ast::Lit) -> ~str {
match lit.node { match lit.node {
ast::lit_str(st, _) => st.to_owned(), ast::LitStr(st, _) => st.to_owned(),
ast::lit_binary(data) => format!("{:?}", data.as_slice()), ast::LitBinary(data) => format!("{:?}", data.as_slice()),
ast::lit_char(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'", ast::LitChar(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'",
ast::lit_int(i, _t) => i.to_str(), ast::LitInt(i, _t) => i.to_str(),
ast::lit_uint(u, _t) => u.to_str(), ast::LitUint(u, _t) => u.to_str(),
ast::lit_int_unsuffixed(i) => i.to_str(), ast::LitIntUnsuffixed(i) => i.to_str(),
ast::lit_float(f, _t) => f.to_str(), ast::LitFloat(f, _t) => f.to_str(),
ast::lit_float_unsuffixed(f) => f.to_str(), ast::LitFloatUnsuffixed(f) => f.to_str(),
ast::lit_bool(b) => b.to_str(), ast::LitBool(b) => b.to_str(),
ast::lit_nil => ~"", ast::LitNil => ~"",
} }
} }
@ -1186,8 +1186,8 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
(i, TypeTrait) (i, TypeTrait)
}, },
ast::DefPrimTy(p) => match p { ast::DefPrimTy(p) => match p {
ast::ty_str => return String, ast::TyStr => return String,
ast::ty_bool => return Bool, ast::TyBool => return Bool,
_ => return Primitive(p) _ => return Primitive(p)
}, },
ast::DefTyParam(i, _) => return Generic(i.node), ast::DefTyParam(i, _) => return Generic(i.node),

View file

@ -28,10 +28,10 @@ pub struct Module {
typedefs: ~[Typedef], typedefs: ~[Typedef],
statics: ~[Static], statics: ~[Static],
traits: ~[Trait], traits: ~[Trait],
vis: ast::visibility, vis: ast::Visibility,
impls: ~[Impl], impls: ~[Impl],
foreigns: ~[ast::foreign_mod], foreigns: ~[ast::ForeignMod],
view_items: ~[ast::view_item], view_items: ~[ast::ViewItem],
} }
impl Module { impl Module {
@ -70,22 +70,22 @@ pub enum StructType {
pub enum TypeBound { pub enum TypeBound {
RegionBound, RegionBound,
TraitBound(ast::trait_ref) TraitBound(ast::TraitRef)
} }
pub struct Struct { pub struct Struct {
vis: ast::visibility, vis: ast::Visibility,
id: NodeId, id: NodeId,
struct_type: StructType, struct_type: StructType,
name: Ident, name: Ident,
generics: ast::Generics, generics: ast::Generics,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
fields: ~[ast::struct_field], fields: ~[ast::StructField],
where: Span, where: Span,
} }
pub struct Enum { pub struct Enum {
vis: ast::visibility, vis: ast::Visibility,
variants: ~[Variant], variants: ~[Variant],
generics: ast::Generics, generics: ast::Generics,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
@ -97,19 +97,19 @@ pub struct Enum {
pub struct Variant { pub struct Variant {
name: Ident, name: Ident,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
kind: ast::variant_kind, kind: ast::VariantKind,
id: ast::NodeId, id: ast::NodeId,
vis: ast::visibility, vis: ast::Visibility,
where: Span, where: Span,
} }
pub struct Function { pub struct Function {
decl: ast::fn_decl, decl: ast::FnDecl,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
id: NodeId, id: NodeId,
name: Ident, name: Ident,
vis: ast::visibility, vis: ast::Visibility,
purity: ast::purity, purity: ast::Purity,
where: Span, where: Span,
generics: ast::Generics, generics: ast::Generics,
} }
@ -121,7 +121,7 @@ pub struct Typedef {
id: ast::NodeId, id: ast::NodeId,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
where: Span, where: Span,
vis: ast::visibility, vis: ast::Visibility,
} }
pub struct Static { pub struct Static {
@ -130,34 +130,34 @@ pub struct Static {
expr: @ast::Expr, expr: @ast::Expr,
name: Ident, name: Ident,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
vis: ast::visibility, vis: ast::Visibility,
id: ast::NodeId, id: ast::NodeId,
where: Span, where: Span,
} }
pub struct Trait { pub struct Trait {
name: Ident, name: Ident,
methods: ~[ast::trait_method], //should be TraitMethod methods: ~[ast::TraitMethod], //should be TraitMethod
generics: ast::Generics, generics: ast::Generics,
parents: ~[ast::trait_ref], parents: ~[ast::TraitRef],
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
id: ast::NodeId, id: ast::NodeId,
where: Span, where: Span,
vis: ast::visibility, vis: ast::Visibility,
} }
pub struct Impl { pub struct Impl {
generics: ast::Generics, generics: ast::Generics,
trait_: Option<ast::trait_ref>, trait_: Option<ast::TraitRef>,
for_: ast::P<ast::Ty>, for_: ast::P<ast::Ty>,
methods: ~[@ast::method], methods: ~[@ast::Method],
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
where: Span, where: Span,
vis: ast::visibility, vis: ast::Visibility,
id: ast::NodeId, id: ast::NodeId,
} }
pub fn struct_type_from_def(sd: &ast::struct_def) -> StructType { pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
if sd.ctor_id.is_some() { if sd.ctor_id.is_some() {
// We are in a tuple-struct // We are in a tuple-struct
match sd.fields.len() { match sd.fields.len() {

View file

@ -28,21 +28,21 @@ use html::render::{cache_key, current_location_key};
/// Helper to render an optional visibility with a space after it (if the /// Helper to render an optional visibility with a space after it (if the
/// visibility is preset) /// visibility is preset)
pub struct VisSpace(Option<ast::visibility>); pub struct VisSpace(Option<ast::Visibility>);
/// Similarly to VisSpace, this structure is used to render a purity with a /// Similarly to VisSpace, this structure is used to render a purity with a
/// space after it. /// space after it.
pub struct PuritySpace(ast::purity); pub struct PuritySpace(ast::Purity);
/// Wrapper struct for properly emitting a method declaration. /// Wrapper struct for properly emitting a method declaration.
pub struct Method<'a>(&'a clean::SelfTy, &'a clean::FnDecl); pub struct Method<'a>(&'a clean::SelfTy, &'a clean::FnDecl);
impl VisSpace { impl VisSpace {
pub fn get(&self) -> Option<ast::visibility> { pub fn get(&self) -> Option<ast::Visibility> {
let VisSpace(v) = *self; v let VisSpace(v) = *self; v
} }
} }
impl PuritySpace { impl PuritySpace {
pub fn get(&self) -> ast::purity { pub fn get(&self) -> ast::Purity {
let PuritySpace(v) = *self; v let PuritySpace(v) = *self; v
} }
} }
@ -290,21 +290,21 @@ impl fmt::Default for clean::Type {
clean::Self(..) => f.buf.write("Self".as_bytes()), clean::Self(..) => f.buf.write("Self".as_bytes()),
clean::Primitive(prim) => { clean::Primitive(prim) => {
let s = match prim { let s = match prim {
ast::ty_int(ast::ty_i) => "int", ast::TyInt(ast::TyI) => "int",
ast::ty_int(ast::ty_i8) => "i8", ast::TyInt(ast::TyI8) => "i8",
ast::ty_int(ast::ty_i16) => "i16", ast::TyInt(ast::TyI16) => "i16",
ast::ty_int(ast::ty_i32) => "i32", ast::TyInt(ast::TyI32) => "i32",
ast::ty_int(ast::ty_i64) => "i64", ast::TyInt(ast::TyI64) => "i64",
ast::ty_uint(ast::ty_u) => "uint", ast::TyUint(ast::TyU) => "uint",
ast::ty_uint(ast::ty_u8) => "u8", ast::TyUint(ast::TyU8) => "u8",
ast::ty_uint(ast::ty_u16) => "u16", ast::TyUint(ast::TyU16) => "u16",
ast::ty_uint(ast::ty_u32) => "u32", ast::TyUint(ast::TyU32) => "u32",
ast::ty_uint(ast::ty_u64) => "u64", ast::TyUint(ast::TyU64) => "u64",
ast::ty_float(ast::ty_f32) => "f32", ast::TyFloat(ast::TyF32) => "f32",
ast::ty_float(ast::ty_f64) => "f64", ast::TyFloat(ast::TyF64) => "f64",
ast::ty_str => "str", ast::TyStr => "str",
ast::ty_bool => "bool", ast::TyBool => "bool",
ast::ty_char => "char", ast::TyChar => "char",
}; };
f.buf.write(s.as_bytes()); f.buf.write(s.as_bytes());
} }
@ -437,9 +437,9 @@ impl<'a> fmt::Default for Method<'a> {
impl fmt::Default for VisSpace { impl fmt::Default for VisSpace {
fn fmt(v: &VisSpace, f: &mut fmt::Formatter) { fn fmt(v: &VisSpace, f: &mut fmt::Formatter) {
match v.get() { match v.get() {
Some(ast::public) => { write!(f.buf, "pub "); } Some(ast::Public) => { write!(f.buf, "pub "); }
Some(ast::private) => { write!(f.buf, "priv "); } Some(ast::Private) => { write!(f.buf, "priv "); }
Some(ast::inherited) | None => {} Some(ast::Inherited) | None => {}
} }
} }
} }
@ -447,9 +447,9 @@ impl fmt::Default for VisSpace {
impl fmt::Default for PuritySpace { impl fmt::Default for PuritySpace {
fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) { fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) {
match p.get() { match p.get() {
ast::unsafe_fn => write!(f.buf, "unsafe "), ast::UnsafeFn => write!(f.buf, "unsafe "),
ast::extern_fn => write!(f.buf, "extern "), ast::ExternFn => write!(f.buf, "extern "),
ast::impure_fn => {} ast::ImpureFn => {}
} }
} }
} }

View file

@ -1149,7 +1149,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item, t: &clean::Trait) {
} }
fn render_method(w: &mut Writer, meth: &clean::Item, withlink: bool) { fn render_method(w: &mut Writer, meth: &clean::Item, withlink: bool) {
fn fun(w: &mut Writer, it: &clean::Item, purity: ast::purity, fn fun(w: &mut Writer, it: &clean::Item, purity: ast::Purity,
g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl, g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl,
withlink: bool) { withlink: bool) {
write!(w, "{}fn {withlink, select, write!(w, "{}fn {withlink, select,
@ -1158,7 +1158,7 @@ fn render_method(w: &mut Writer, meth: &clean::Item, withlink: bool) {
other{<span class='fnname'>{name}</span>} other{<span class='fnname'>{name}</span>}
}{generics}{decl}", }{generics}{decl}",
match purity { match purity {
ast::unsafe_fn => "unsafe ", ast::UnsafeFn => "unsafe ",
_ => "", _ => "",
}, },
ty = shortty(it), ty = shortty(it),

View file

@ -96,13 +96,13 @@ impl<'a> fold::DocFolder for Stripper<'a> {
} }
clean::ViewItemItem(..) => { clean::ViewItemItem(..) => {
if i.visibility != Some(ast::public) { if i.visibility != Some(ast::Public) {
return None return None
} }
} }
clean::StructFieldItem(..) => { clean::StructFieldItem(..) => {
if i.visibility == Some(ast::private) { if i.visibility == Some(ast::Private) {
return None; return None;
} }
} }

View file

@ -42,13 +42,12 @@ impl<'a> RustdocVisitor<'a> {
self.attrs = crate.attrs.clone(); self.attrs = crate.attrs.clone();
self.module = self.visit_mod_contents(crate.span, crate.attrs.clone(), self.module = self.visit_mod_contents(crate.span, crate.attrs.clone(),
ast::public, ast::CRATE_NODE_ID, ast::Public, ast::CRATE_NODE_ID,
&crate.module, None); &crate.module, None);
} }
pub fn visit_struct_def(&mut self, item: &ast::item, sd: @ast::struct_def, pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef,
generics: &ast::Generics) -> Struct {
generics: &ast::Generics) -> Struct {
debug!("Visiting struct"); debug!("Visiting struct");
let struct_type = struct_type_from_def(sd); let struct_type = struct_type_from_def(sd);
Struct { Struct {
@ -63,8 +62,8 @@ impl<'a> RustdocVisitor<'a> {
} }
} }
pub fn visit_enum_def(&mut self, it: &ast::item, def: &ast::enum_def, pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef,
params: &ast::Generics) -> Enum { params: &ast::Generics) -> Enum {
debug!("Visiting enum"); debug!("Visiting enum");
let mut vars: ~[Variant] = ~[]; let mut vars: ~[Variant] = ~[];
for x in def.variants.iter() { for x in def.variants.iter() {
@ -88,8 +87,8 @@ impl<'a> RustdocVisitor<'a> {
} }
} }
pub fn visit_fn(&mut self, item: &ast::item, fd: &ast::fn_decl, pub fn visit_fn(&mut self, item: &ast::Item, fd: &ast::FnDecl,
purity: &ast::purity, _abi: &AbiSet, purity: &ast::Purity, _abi: &AbiSet,
gen: &ast::Generics) -> Function { gen: &ast::Generics) -> Function {
debug!("Visiting fn"); debug!("Visiting fn");
Function { Function {
@ -105,8 +104,8 @@ impl<'a> RustdocVisitor<'a> {
} }
pub fn visit_mod_contents(&mut self, span: Span, attrs: ~[ast::Attribute], pub fn visit_mod_contents(&mut self, span: Span, attrs: ~[ast::Attribute],
vis: ast::visibility, id: ast::NodeId, vis: ast::Visibility, id: ast::NodeId,
m: &ast::_mod, m: &ast::Mod,
name: Option<ast::Ident>) -> Module { name: Option<ast::Ident>) -> Module {
let mut om = Module::new(name); let mut om = Module::new(name);
for item in m.view_items.iter() { for item in m.view_items.iter() {
@ -194,10 +193,10 @@ impl<'a> RustdocVisitor<'a> {
*items.get().get(&def.node) *items.get().get(&def.node)
}; };
match item { match item {
ast_map::node_item(it, _) => { ast_map::NodeItem(it, _) => {
if glob { if glob {
match it.node { match it.node {
ast::item_mod(ref m) => { ast::ItemMod(ref m) => {
for vi in m.view_items.iter() { for vi in m.view_items.iter() {
self.visit_view_item(vi, om); self.visit_view_item(vi, om);
} }
@ -216,21 +215,21 @@ impl<'a> RustdocVisitor<'a> {
} }
} }
pub fn visit_item(&mut self, item: &ast::item, om: &mut Module) { pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
debug!("Visiting item {:?}", item); debug!("Visiting item {:?}", item);
match item.node { match item.node {
ast::item_mod(ref m) => { ast::ItemMod(ref m) => {
om.mods.push(self.visit_mod_contents(item.span, item.attrs.clone(), om.mods.push(self.visit_mod_contents(item.span, item.attrs.clone(),
item.vis, item.id, m, item.vis, item.id, m,
Some(item.ident))); Some(item.ident)));
}, },
ast::item_enum(ref ed, ref gen) => ast::ItemEnum(ref ed, ref gen) =>
om.enums.push(self.visit_enum_def(item, ed, gen)), om.enums.push(self.visit_enum_def(item, ed, gen)),
ast::item_struct(sd, ref gen) => ast::ItemStruct(sd, ref gen) =>
om.structs.push(self.visit_struct_def(item, sd, gen)), om.structs.push(self.visit_struct_def(item, sd, gen)),
ast::item_fn(fd, ref pur, ref abi, ref gen, _) => ast::ItemFn(fd, ref pur, ref abi, ref gen, _) =>
om.fns.push(self.visit_fn(item, fd, pur, abi, gen)), om.fns.push(self.visit_fn(item, fd, pur, abi, gen)),
ast::item_ty(ty, ref gen) => { ast::ItemTy(ty, ref gen) => {
let t = Typedef { let t = Typedef {
ty: ty, ty: ty,
gen: gen.clone(), gen: gen.clone(),
@ -242,7 +241,7 @@ impl<'a> RustdocVisitor<'a> {
}; };
om.typedefs.push(t); om.typedefs.push(t);
}, },
ast::item_static(ty, ref mut_, ref exp) => { ast::ItemStatic(ty, ref mut_, ref exp) => {
let s = Static { let s = Static {
type_: ty, type_: ty,
mutability: mut_.clone(), mutability: mut_.clone(),
@ -255,7 +254,7 @@ impl<'a> RustdocVisitor<'a> {
}; };
om.statics.push(s); om.statics.push(s);
}, },
ast::item_trait(ref gen, ref tr, ref met) => { ast::ItemTrait(ref gen, ref tr, ref met) => {
let t = Trait { let t = Trait {
name: item.ident, name: item.ident,
methods: met.clone(), methods: met.clone(),
@ -268,7 +267,7 @@ impl<'a> RustdocVisitor<'a> {
}; };
om.traits.push(t); om.traits.push(t);
}, },
ast::item_impl(ref gen, ref tr, ty, ref meths) => { ast::ItemImpl(ref gen, ref tr, ty, ref meths) => {
let i = Impl { let i = Impl {
generics: gen.clone(), generics: gen.clone(),
trait_: tr.clone(), trait_: tr.clone(),
@ -281,7 +280,7 @@ impl<'a> RustdocVisitor<'a> {
}; };
om.impls.push(i); om.impls.push(i);
}, },
ast::item_foreign_mod(ref fm) => { ast::ItemForeignMod(ref fm) => {
om.foreigns.push(fm.clone()); om.foreigns.push(fm.clone());
} }
_ => (), _ => (),

View file

@ -23,7 +23,7 @@ use syntax::codemap::{DUMMY_SP, Spanned};
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
use syntax::{ast, attr, codemap, diagnostic, fold, visit}; use syntax::{ast, attr, codemap, diagnostic, fold, visit};
use syntax::attr::AttrMetaMethods; use syntax::attr::AttrMetaMethods;
use syntax::fold::ast_fold; use syntax::fold::Folder;
use syntax::visit::Visitor; use syntax::visit::Visitor;
use syntax::util::small_vector::SmallVector; use syntax::util::small_vector::SmallVector;
use rustc::back::link::output_type_exe; use rustc::back::link::output_type_exe;
@ -70,9 +70,9 @@ struct ReadyCtx {
fns: ~[ListenerFn] fns: ~[ListenerFn]
} }
fn fold_mod(m: &ast::_mod, fold: &mut CrateSetup) -> ast::_mod { fn fold_mod(m: &ast::Mod, fold: &mut CrateSetup) -> ast::Mod {
fn strip_main(item: @ast::item) -> @ast::item { fn strip_main(item: @ast::Item) -> @ast::Item {
@ast::item { @ast::Item {
attrs: item.attrs.iter().filter_map(|attr| { attrs: item.attrs.iter().filter_map(|attr| {
if "main" != attr.name() { if "main" != attr.name() {
Some(*attr) Some(*attr)
@ -84,14 +84,14 @@ fn fold_mod(m: &ast::_mod, fold: &mut CrateSetup) -> ast::_mod {
} }
} }
fold::noop_fold_mod(&ast::_mod { fold::noop_fold_mod(&ast::Mod {
items: m.items.map(|item| strip_main(*item)), items: m.items.map(|item| strip_main(*item)),
.. (*m).clone() .. (*m).clone()
}, fold) }, fold)
} }
fn fold_item(item: @ast::item, fold: &mut CrateSetup) fn fold_item(item: @ast::Item, fold: &mut CrateSetup)
-> SmallVector<@ast::item> { -> SmallVector<@ast::Item> {
fold.ctx.path.push(item.ident); fold.ctx.path.push(item.ident);
let mut cmds = ~[]; let mut cmds = ~[];
@ -133,11 +133,11 @@ struct CrateSetup<'a> {
ctx: &'a mut ReadyCtx, ctx: &'a mut ReadyCtx,
} }
impl<'a> fold::ast_fold for CrateSetup<'a> { impl<'a> fold::Folder for CrateSetup<'a> {
fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> { fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> {
fold_item(item, self) fold_item(item, self)
} }
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod { fn fold_mod(&mut self, module: &ast::Mod) -> ast::Mod {
fold_mod(module, self) fold_mod(module, self)
} }
} }
@ -350,7 +350,7 @@ pub fn compile_crate_from_input(input: &Path,
// Returns None if one of the flags that suppresses compilation output was // Returns None if one of the flags that suppresses compilation output was
// given // given
crate: ast::Crate, crate: ast::Crate,
ast_map: syntax::ast_map::map, ast_map: syntax::ast_map::Map,
what: OutputType) -> Option<Path> { what: OutputType) -> Option<Path> {
debug!("Calling build_output_filenames with {}, building library? {:?}", debug!("Calling build_output_filenames with {}, building library? {:?}",
out_dir.display(), sess.building_library); out_dir.display(), sess.building_library);
@ -447,12 +447,12 @@ struct ViewItemVisitor<'a> {
} }
impl<'a> Visitor<()> for ViewItemVisitor<'a> { impl<'a> Visitor<()> for ViewItemVisitor<'a> {
fn visit_view_item(&mut self, vi: &ast::view_item, env: ()) { fn visit_view_item(&mut self, vi: &ast::ViewItem, env: ()) {
use conditions::nonexistent_package::cond; use conditions::nonexistent_package::cond;
match vi.node { match vi.node {
// ignore metadata, I guess // ignore metadata, I guess
ast::view_item_extern_mod(lib_ident, path_opt, _) => { ast::ViewItemExternMod(lib_ident, path_opt, _) => {
let lib_name = match path_opt { let lib_name = match path_opt {
Some((p, _)) => p, Some((p, _)) => p,
None => self.sess.str_of(lib_ident) None => self.sess.str_of(lib_ident)
@ -619,9 +619,9 @@ pub fn find_and_install_dependencies(context: &BuildContext,
visit::walk_crate(&mut visitor, c, ()) visit::walk_crate(&mut visitor, c, ())
} }
pub fn mk_string_lit(s: @str) -> ast::lit { pub fn mk_string_lit(s: @str) -> ast::Lit {
Spanned { Spanned {
node: ast::lit_str(s, ast::CookedStr), node: ast::LitStr(s, ast::CookedStr),
span: DUMMY_SP span: DUMMY_SP
} }
} }

View file

@ -32,6 +32,7 @@ pub enum Abi {
RustIntrinsic, RustIntrinsic,
} }
#[allow(non_camel_case_types)]
#[deriving(Eq)] #[deriving(Eq)]
pub enum Architecture { pub enum Architecture {
// NB. You cannot change the ordering of these // NB. You cannot change the ordering of these

View file

@ -197,7 +197,7 @@ pub static DUMMY_NODE_ID: NodeId = -1;
// detects Copy, Send, Send, and Freeze. // detects Copy, Send, Send, and Freeze.
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum TyParamBound { pub enum TyParamBound {
TraitTyParamBound(trait_ref), TraitTyParamBound(TraitRef),
RegionTyParamBound RegionTyParamBound
} }
@ -234,8 +234,8 @@ pub enum MethodProvenance {
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum Def { pub enum Def {
DefFn(DefId, purity), DefFn(DefId, Purity),
DefStaticMethod(/* method */ DefId, MethodProvenance, purity), DefStaticMethod(/* method */ DefId, MethodProvenance, Purity),
DefSelf(NodeId, bool /* is_mutbl */), DefSelf(NodeId, bool /* is_mutbl */),
DefSelfTy(/* trait id */ NodeId), DefSelfTy(/* trait id */ NodeId),
DefMod(DefId), DefMod(DefId),
@ -246,7 +246,7 @@ pub enum Def {
DefVariant(DefId /* enum */, DefId /* variant */, bool /* is_structure */), DefVariant(DefId /* enum */, DefId /* variant */, bool /* is_structure */),
DefTy(DefId), DefTy(DefId),
DefTrait(DefId), DefTrait(DefId),
DefPrimTy(prim_ty), DefPrimTy(PrimTy),
DefTyParam(DefId, uint), DefTyParam(DefId, uint),
DefBinding(NodeId, BindingMode), DefBinding(NodeId, BindingMode),
DefUse(DefId), DefUse(DefId),
@ -256,13 +256,13 @@ pub enum Def {
NodeId), // id for the block/body of the closure expr NodeId), // id for the block/body of the closure expr
/// Note that if it's a tuple struct's definition, the node id of the DefId /// Note that if it's a tuple struct's definition, the node id of the DefId
/// may either refer to the item definition's id or the struct_def.ctor_id. /// may either refer to the item definition's id or the StructDef.ctor_id.
/// ///
/// The cases that I have encountered so far are (this is not exhaustive): /// The cases that I have encountered so far are (this is not exhaustive):
/// - If it's a ty_path referring to some tuple struct, then DefMap maps /// - If it's a ty_path referring to some tuple struct, then DefMap maps
/// it to a def whose id is the item definition's id. /// it to a def whose id is the item definition's id.
/// - If it's an ExprPath referring to some tuple struct, then DefMap maps /// - If it's an ExprPath referring to some tuple struct, then DefMap maps
/// it to a def whose id is the struct_def.ctor_id. /// it to a def whose id is the StructDef.ctor_id.
DefStruct(DefId), DefStruct(DefId),
DefTyParamBinder(NodeId), /* struct, impl or trait with ty params */ DefTyParamBinder(NodeId), /* struct, impl or trait with ty params */
DefRegion(NodeId), DefRegion(NodeId),
@ -284,7 +284,7 @@ pub type CrateConfig = ~[@MetaItem];
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct Crate { pub struct Crate {
module: _mod, module: Mod,
attrs: ~[Attribute], attrs: ~[Attribute],
config: CrateConfig, config: CrateConfig,
span: Span, span: Span,
@ -296,7 +296,7 @@ pub type MetaItem = Spanned<MetaItem_>;
pub enum MetaItem_ { pub enum MetaItem_ {
MetaWord(@str), MetaWord(@str),
MetaList(@str, ~[@MetaItem]), MetaList(@str, ~[@MetaItem]),
MetaNameValue(@str, lit), MetaNameValue(@str, Lit),
} }
// can't be derived because the MetaList requires an unordered comparison // can't be derived because the MetaList requires an unordered comparison
@ -326,7 +326,7 @@ impl Eq for MetaItem_ {
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub struct Block { pub struct Block {
view_items: ~[view_item], view_items: ~[ViewItem],
stmts: ~[@Stmt], stmts: ~[@Stmt],
expr: Option<@Expr>, expr: Option<@Expr>,
id: NodeId, id: NodeId,
@ -464,7 +464,7 @@ pub enum Stmt_ {
StmtSemi(@Expr, NodeId), StmtSemi(@Expr, NodeId),
// bool: is there a trailing sem-colon? // bool: is there a trailing sem-colon?
StmtMac(mac, bool), StmtMac(Mac, bool),
} }
// FIXME (pending discussion of #1697, #2178...): local should really be // FIXME (pending discussion of #1697, #2178...): local should really be
@ -486,7 +486,7 @@ pub enum Decl_ {
// a local (let) binding: // a local (let) binding:
DeclLocal(@Local), DeclLocal(@Local),
// an item binding: // an item binding:
DeclItem(@item), DeclItem(@Item),
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
@ -553,7 +553,7 @@ pub enum Expr_ {
ExprTup(~[@Expr]), ExprTup(~[@Expr]),
ExprBinary(NodeId, BinOp, @Expr, @Expr), ExprBinary(NodeId, BinOp, @Expr, @Expr),
ExprUnary(NodeId, UnOp, @Expr), ExprUnary(NodeId, UnOp, @Expr),
ExprLit(@lit), ExprLit(@Lit),
ExprCast(@Expr, P<Ty>), ExprCast(@Expr, P<Ty>),
ExprIf(@Expr, P<Block>, Option<@Expr>), ExprIf(@Expr, P<Block>, Option<@Expr>),
ExprWhile(@Expr, P<Block>), ExprWhile(@Expr, P<Block>),
@ -563,8 +563,8 @@ pub enum Expr_ {
// FIXME #6993: change to Option<Name> // FIXME #6993: change to Option<Name>
ExprLoop(P<Block>, Option<Ident>), ExprLoop(P<Block>, Option<Ident>),
ExprMatch(@Expr, ~[Arm]), ExprMatch(@Expr, ~[Arm]),
ExprFnBlock(P<fn_decl>, P<Block>), ExprFnBlock(P<FnDecl>, P<Block>),
ExprProc(P<fn_decl>, P<Block>), ExprProc(P<FnDecl>, P<Block>),
ExprDoBody(@Expr), ExprDoBody(@Expr),
ExprBlock(P<Block>), ExprBlock(P<Block>),
@ -588,9 +588,9 @@ pub enum Expr_ {
/// Gets the log level for the enclosing module /// Gets the log level for the enclosing module
ExprLogLevel, ExprLogLevel,
ExprInlineAsm(inline_asm), ExprInlineAsm(InlineAsm),
ExprMac(mac), ExprMac(Mac),
// A struct literal expression. // A struct literal expression.
ExprStruct(Path, ~[Field], Option<@Expr> /* base */), ExprStruct(Path, ~[Field], Option<@Expr> /* base */),
@ -610,31 +610,38 @@ pub enum Expr_ {
// If the syntax extension is an MBE macro, it will attempt to match its // If the syntax extension is an MBE macro, it will attempt to match its
// LHS "matchers" against the provided token tree, and if it finds a // LHS "matchers" against the provided token tree, and if it finds a
// match, will transcribe the RHS token tree, splicing in any captured // match, will transcribe the RHS token tree, splicing in any captured
// macro_parser::matched_nonterminals into the tt_nonterminals it finds. // macro_parser::matched_nonterminals into the TTNonterminals it finds.
// //
// The RHS of an MBE macro is the only place a tt_nonterminal or tt_seq // The RHS of an MBE macro is the only place a TTNonterminal or TTSeq
// makes any real sense. You could write them elsewhere but nothing // makes any real sense. You could write them elsewhere but nothing
// else knows what to do with them, so you'll probably get a syntax // else knows what to do with them, so you'll probably get a syntax
// error. // error.
// //
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
#[doc="For macro invocations; parsing is delegated to the macro"] #[doc="For macro invocations; parsing is delegated to the macro"]
pub enum token_tree { pub enum TokenTree {
// a single token // a single token
tt_tok(Span, ::parse::token::Token), TTTok(Span, ::parse::token::Token),
// a delimited sequence (the delimiters appear as the first // a delimited sequence (the delimiters appear as the first
// and last elements of the vector) // and last elements of the vector)
tt_delim(@~[token_tree]), TTDelim(@~[TokenTree]),
// These only make sense for right-hand-sides of MBE macros: // These only make sense for right-hand-sides of MBE macros:
// a kleene-style repetition sequence with a span, a tt_forest, // a kleene-style repetition sequence with a span, a TTForest,
// an optional separator, and a boolean where true indicates // an optional separator, and a boolean where true indicates
// zero or more (..), and false indicates one or more (+). // zero or more (..), and false indicates one or more (+).
tt_seq(Span, @~[token_tree], Option<::parse::token::Token>, bool), TTSeq(Span, @~[TokenTree], Option<::parse::token::Token>, bool),
// a syntactic variable that will be filled in by macro expansion. // a syntactic variable that will be filled in by macro expansion.
tt_nonterminal(Span, Ident) TTNonterminal(Span, Ident)
}
// NOTE remove after next snapshot
// Required for ext::quote macros.
#[cfg(stage0)]
pub fn tt_tok(span: Span, tok: ::parse::token::Token) -> TokenTree {
TTTok(span, tok)
} }
// //
@ -646,15 +653,15 @@ pub enum token_tree {
// token-trees, and are thus primarily used by the macro-defining extension // token-trees, and are thus primarily used by the macro-defining extension
// itself. // itself.
// //
// match_tok // MatchTok
// --------- // --------
// //
// A matcher that matches a single token, denoted by the token itself. So // A matcher that matches a single token, denoted by the token itself. So
// long as there's no $ involved. // long as there's no $ involved.
// //
// //
// match_seq // MatchSeq
// --------- // --------
// //
// A matcher that matches a sequence of sub-matchers, denoted various // A matcher that matches a sequence of sub-matchers, denoted various
// possible ways: // possible ways:
@ -665,7 +672,7 @@ pub enum token_tree {
// $(A B C);* zero or more semi-separated 'A B C' seqs // $(A B C);* zero or more semi-separated 'A B C' seqs
// //
// //
// match_nonterminal // MatchNonterminal
// ----------------- // -----------------
// //
// A matcher that matches one of a few interesting named rust // A matcher that matches one of a few interesting named rust
@ -682,35 +689,35 @@ pub enum token_tree {
// //
// As a final, horrifying aside, note that macro-by-example's input is // As a final, horrifying aside, note that macro-by-example's input is
// also matched by one of these matchers. Holy self-referential! It is matched // also matched by one of these matchers. Holy self-referential! It is matched
// by an match_seq, specifically this one: // by an MatchSeq, specifically this one:
// //
// $( $lhs:matchers => $rhs:tt );+ // $( $lhs:matchers => $rhs:tt );+
// //
// If you understand that, you have closed to loop and understand the whole // If you understand that, you have closed to loop and understand the whole
// macro system. Congratulations. // macro system. Congratulations.
// //
pub type matcher = Spanned<matcher_>; pub type Matcher = Spanned<Matcher_>;
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum matcher_ { pub enum Matcher_ {
// match one token // match one token
match_tok(::parse::token::Token), MatchTok(::parse::token::Token),
// match repetitions of a sequence: body, separator, zero ok?, // match repetitions of a sequence: body, separator, zero ok?,
// lo, hi position-in-match-array used: // lo, hi position-in-match-array used:
match_seq(~[matcher], Option<::parse::token::Token>, bool, uint, uint), MatchSeq(~[Matcher], Option<::parse::token::Token>, bool, uint, uint),
// parse a Rust NT: name to bind, name of NT, position in match array: // parse a Rust NT: name to bind, name of NT, position in match array:
match_nonterminal(Ident, Ident, uint) MatchNonterminal(Ident, Ident, uint)
} }
pub type mac = Spanned<mac_>; pub type Mac = Spanned<Mac_>;
// represents a macro invocation. The Path indicates which macro // represents a macro invocation. The Path indicates which macro
// is being invoked, and the vector of token-trees contains the source // is being invoked, and the vector of token-trees contains the source
// of the macro invocation. // of the macro invocation.
// There's only one flavor, now, so this could presumably be simplified. // There's only one flavor, now, so this could presumably be simplified.
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum mac_ { pub enum Mac_ {
mac_invoc_tt(Path,~[token_tree],SyntaxContext), // new macro-invocation MacInvocTT(Path, ~[TokenTree], SyntaxContext), // new macro-invocation
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
@ -719,26 +726,26 @@ pub enum StrStyle {
RawStr(uint) RawStr(uint)
} }
pub type lit = Spanned<lit_>; pub type Lit = Spanned<Lit_>;
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum lit_ { pub enum Lit_ {
lit_str(@str, StrStyle), LitStr(@str, StrStyle),
lit_binary(@[u8]), LitBinary(@[u8]),
lit_char(u32), LitChar(u32),
lit_int(i64, int_ty), LitInt(i64, IntTy),
lit_uint(u64, uint_ty), LitUint(u64, UintTy),
lit_int_unsuffixed(i64), LitIntUnsuffixed(i64),
lit_float(@str, float_ty), LitFloat(@str, FloatTy),
lit_float_unsuffixed(@str), LitFloatUnsuffixed(@str),
lit_nil, LitNil,
lit_bool(bool), LitBool(bool),
} }
// NB: If you change this, you'll probably want to change the corresponding // NB: If you change this, you'll probably want to change the corresponding
// type structure in middle/ty.rs as well. // type structure in middle/ty.rs as well.
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct mt { pub struct MutTy {
ty: P<Ty>, ty: P<Ty>,
mutbl: Mutability, mutbl: Mutability,
} }
@ -746,7 +753,7 @@ pub struct mt {
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct TypeField { pub struct TypeField {
ident: Ident, ident: Ident,
mt: mt, mt: MutTy,
span: Span, span: Span,
} }
@ -754,10 +761,10 @@ pub struct TypeField {
pub struct TypeMethod { pub struct TypeMethod {
ident: Ident, ident: Ident,
attrs: ~[Attribute], attrs: ~[Attribute],
purity: purity, purity: Purity,
decl: P<fn_decl>, decl: P<FnDecl>,
generics: Generics, generics: Generics,
explicit_self: explicit_self, explicit_self: ExplicitSelf,
id: NodeId, id: NodeId,
span: Span, span: Span,
} }
@ -766,48 +773,48 @@ pub struct TypeMethod {
// implementation, just a signature) or provided (meaning it has a default // implementation, just a signature) or provided (meaning it has a default
// implementation). // implementation).
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum trait_method { pub enum TraitMethod {
required(TypeMethod), Required(TypeMethod),
provided(@method), Provided(@Method),
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum int_ty { pub enum IntTy {
ty_i, TyI,
ty_i8, TyI8,
ty_i16, TyI16,
ty_i32, TyI32,
ty_i64, TyI64,
} }
impl ToStr for int_ty { impl ToStr for IntTy {
fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
::ast_util::int_ty_to_str(*self) ::ast_util::int_ty_to_str(*self)
} }
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum uint_ty { pub enum UintTy {
ty_u, TyU,
ty_u8, TyU8,
ty_u16, TyU16,
ty_u32, TyU32,
ty_u64, TyU64,
} }
impl ToStr for uint_ty { impl ToStr for UintTy {
fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
::ast_util::uint_ty_to_str(*self) ::ast_util::uint_ty_to_str(*self)
} }
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum float_ty { pub enum FloatTy {
ty_f32, TyF32,
ty_f64, TyF64,
} }
impl ToStr for float_ty { impl ToStr for FloatTy {
fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
::ast_util::float_ty_to_str(*self) ::ast_util::float_ty_to_str(*self)
} }
@ -817,19 +824,19 @@ impl ToStr for float_ty {
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct Ty { pub struct Ty {
id: NodeId, id: NodeId,
node: ty_, node: Ty_,
span: Span, span: Span,
} }
// Not represented directly in the AST, referred to by name through a ty_path. // Not represented directly in the AST, referred to by name through a ty_path.
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum prim_ty { pub enum PrimTy {
ty_int(int_ty), TyInt(IntTy),
ty_uint(uint_ty), TyUint(UintTy),
ty_float(float_ty), TyFloat(FloatTy),
ty_str, TyStr,
ty_bool, TyBool,
ty_char TyChar
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
@ -848,13 +855,13 @@ impl ToStr for Onceness {
} }
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct TyClosure { pub struct ClosureTy {
sigil: Sigil, sigil: Sigil,
region: Option<Lifetime>, region: Option<Lifetime>,
lifetimes: OptVec<Lifetime>, lifetimes: OptVec<Lifetime>,
purity: purity, purity: Purity,
onceness: Onceness, onceness: Onceness,
decl: P<fn_decl>, decl: P<FnDecl>,
// Optional optvec distinguishes between "fn()" and "fn:()" so we can // Optional optvec distinguishes between "fn()" and "fn:()" so we can
// implement issue #7264. None means "fn()", which means infer a default // implement issue #7264. None means "fn()", which means infer a default
// bound based on pointer sigil during typeck. Some(Empty) means "fn:()", // bound based on pointer sigil during typeck. Some(Empty) means "fn:()",
@ -863,42 +870,42 @@ pub struct TyClosure {
} }
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct TyBareFn { pub struct BareFnTy {
purity: purity, purity: Purity,
abis: AbiSet, abis: AbiSet,
lifetimes: OptVec<Lifetime>, lifetimes: OptVec<Lifetime>,
decl: P<fn_decl> decl: P<FnDecl>
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum ty_ { pub enum Ty_ {
ty_nil, TyNil,
ty_bot, /* bottom type */ TyBot, /* bottom type */
ty_box(P<Ty>), TyBox(P<Ty>),
ty_uniq(P<Ty>), TyUniq(P<Ty>),
ty_vec(P<Ty>), TyVec(P<Ty>),
ty_fixed_length_vec(P<Ty>, @Expr), TyFixedLengthVec(P<Ty>, @Expr),
ty_ptr(mt), TyPtr(MutTy),
ty_rptr(Option<Lifetime>, mt), TyRptr(Option<Lifetime>, MutTy),
ty_closure(@TyClosure), TyClosure(@ClosureTy),
ty_bare_fn(@TyBareFn), TyBareFn(@BareFnTy),
ty_tup(~[P<Ty>]), TyTup(~[P<Ty>]),
ty_path(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above TyPath(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above
ty_typeof(@Expr), TyTypeof(@Expr),
// ty_infer means the type should be inferred instead of it having been // ty_infer means the type should be inferred instead of it having been
// specified. This should only appear at the "top level" of a type and not // specified. This should only appear at the "top level" of a type and not
// nested in one. // nested in one.
ty_infer, TyInfer,
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum asm_dialect { pub enum AsmDialect {
asm_att, AsmAtt,
asm_intel AsmIntel
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct inline_asm { pub struct InlineAsm {
asm: @str, asm: @str,
asm_str_style: StrStyle, asm_str_style: StrStyle,
clobbers: @str, clobbers: @str,
@ -906,159 +913,159 @@ pub struct inline_asm {
outputs: ~[(@str, @Expr)], outputs: ~[(@str, @Expr)],
volatile: bool, volatile: bool,
alignstack: bool, alignstack: bool,
dialect: asm_dialect dialect: AsmDialect
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct arg { pub struct Arg {
ty: P<Ty>, ty: P<Ty>,
pat: @Pat, pat: @Pat,
id: NodeId, id: NodeId,
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct fn_decl { pub struct FnDecl {
inputs: ~[arg], inputs: ~[Arg],
output: P<Ty>, output: P<Ty>,
cf: ret_style, cf: RetStyle,
variadic: bool variadic: bool
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum purity { pub enum Purity {
unsafe_fn, // declared with "unsafe fn" UnsafeFn, // declared with "unsafe fn"
impure_fn, // declared with "fn" ImpureFn, // declared with "fn"
extern_fn, // declared with "extern fn" ExternFn, // declared with "extern fn"
} }
impl ToStr for purity { impl ToStr for Purity {
fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
match *self { match *self {
impure_fn => ~"impure", ImpureFn => ~"impure",
unsafe_fn => ~"unsafe", UnsafeFn => ~"unsafe",
extern_fn => ~"extern" ExternFn => ~"extern"
} }
} }
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum ret_style { pub enum RetStyle {
noreturn, // functions with return type _|_ that always NoReturn, // functions with return type _|_ that always
// raise an error or exit (i.e. never return to the caller) // raise an error or exit (i.e. never return to the caller)
return_val, // everything else Return, // everything else
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum explicit_self_ { pub enum ExplicitSelf_ {
sty_static, // no self SelfStatic, // no self
sty_value(Mutability), // `self` SelfValue(Mutability), // `self`
sty_region(Option<Lifetime>, Mutability), // `&'lt self` SelfRegion(Option<Lifetime>, Mutability), // `&'lt self`
sty_box(Mutability), // `@self` SelfBox(Mutability), // `@self`
sty_uniq(Mutability) // `~self` SelfUniq(Mutability) // `~self`
} }
pub type explicit_self = Spanned<explicit_self_>; pub type ExplicitSelf = Spanned<ExplicitSelf_>;
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct method { pub struct Method {
ident: Ident, ident: Ident,
attrs: ~[Attribute], attrs: ~[Attribute],
generics: Generics, generics: Generics,
explicit_self: explicit_self, explicit_self: ExplicitSelf,
purity: purity, purity: Purity,
decl: P<fn_decl>, decl: P<FnDecl>,
body: P<Block>, body: P<Block>,
id: NodeId, id: NodeId,
span: Span, span: Span,
self_id: NodeId, self_id: NodeId,
vis: visibility, vis: Visibility,
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct _mod { pub struct Mod {
view_items: ~[view_item], view_items: ~[ViewItem],
items: ~[@item], items: ~[@Item],
} }
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub struct foreign_mod { pub struct ForeignMod {
abis: AbiSet, abis: AbiSet,
view_items: ~[view_item], view_items: ~[ViewItem],
items: ~[@foreign_item], items: ~[@ForeignItem],
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct variant_arg { pub struct VariantArg {
ty: P<Ty>, ty: P<Ty>,
id: NodeId, id: NodeId,
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum variant_kind { pub enum VariantKind {
tuple_variant_kind(~[variant_arg]), TupleVariantKind(~[VariantArg]),
struct_variant_kind(@struct_def), StructVariantKind(@StructDef),
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct enum_def { pub struct EnumDef {
variants: ~[P<variant>], variants: ~[P<Variant>],
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct variant_ { pub struct Variant_ {
name: Ident, name: Ident,
attrs: ~[Attribute], attrs: ~[Attribute],
kind: variant_kind, kind: VariantKind,
id: NodeId, id: NodeId,
disr_expr: Option<@Expr>, disr_expr: Option<@Expr>,
vis: visibility, vis: Visibility,
} }
pub type variant = Spanned<variant_>; pub type Variant = Spanned<Variant_>;
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct path_list_ident_ { pub struct PathListIdent_ {
name: Ident, name: Ident,
id: NodeId, id: NodeId,
} }
pub type path_list_ident = Spanned<path_list_ident_>; pub type PathListIdent = Spanned<PathListIdent_>;
pub type view_path = Spanned<view_path_>; pub type ViewPath = Spanned<ViewPath_>;
#[deriving(Eq, Encodable, Decodable, IterBytes)] #[deriving(Eq, Encodable, Decodable, IterBytes)]
pub enum view_path_ { pub enum ViewPath_ {
// quux = foo::bar::baz // quux = foo::bar::baz
// //
// or just // or just
// //
// foo::bar::baz (with 'baz =' implicitly on the left) // foo::bar::baz (with 'baz =' implicitly on the left)
view_path_simple(Ident, Path, NodeId), ViewPathSimple(Ident, Path, NodeId),
// foo::bar::* // foo::bar::*
view_path_glob(Path, NodeId), ViewPathGlob(Path, NodeId),
// foo::bar::{a,b,c} // foo::bar::{a,b,c}
view_path_list(Path, ~[path_list_ident], NodeId) ViewPathList(Path, ~[PathListIdent], NodeId)
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct view_item { pub struct ViewItem {
node: view_item_, node: ViewItem_,
attrs: ~[Attribute], attrs: ~[Attribute],
vis: visibility, vis: Visibility,
span: Span, span: Span,
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum view_item_ { pub enum ViewItem_ {
// ident: name used to refer to this crate in the code // ident: name used to refer to this crate in the code
// optional @str: if present, this is a location (containing // optional @str: if present, this is a location (containing
// arbitrary characters) from which to fetch the crate sources // arbitrary characters) from which to fetch the crate sources
// For example, extern mod whatever = "github.com/mozilla/rust" // For example, extern mod whatever = "github.com/mozilla/rust"
view_item_extern_mod(Ident, Option<(@str, StrStyle)>, NodeId), ViewItemExternMod(Ident, Option<(@str, StrStyle)>, NodeId),
view_item_use(~[@view_path]), ViewItemUse(~[@ViewPath]),
} }
// Meta-data associated with an item // Meta-data associated with an item
@ -1082,53 +1089,53 @@ pub struct Attribute_ {
} }
/* /*
trait_refs appear in impls. TraitRef's appear in impls.
resolve maps each trait_ref's ref_id to its defining trait; that's all resolve maps each TraitRef's ref_id to its defining trait; that's all
that the ref_id is for. The impl_id maps to the "self type" of this impl. that the ref_id is for. The impl_id maps to the "self type" of this impl.
If this impl is an item_impl, the impl_id is redundant (it could be the If this impl is an ItemImpl, the impl_id is redundant (it could be the
same as the impl's node id). same as the impl's node id).
*/ */
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub struct trait_ref { pub struct TraitRef {
path: Path, path: Path,
ref_id: NodeId, ref_id: NodeId,
} }
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub enum visibility { pub enum Visibility {
public, Public,
private, Private,
inherited, Inherited,
} }
impl visibility { impl Visibility {
pub fn inherit_from(&self, parent_visibility: visibility) -> visibility { pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
match self { match self {
&inherited => parent_visibility, &Inherited => parent_visibility,
&public | &private => *self &Public | &Private => *self
} }
} }
} }
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub struct struct_field_ { pub struct StructField_ {
kind: struct_field_kind, kind: StructFieldKind,
id: NodeId, id: NodeId,
ty: P<Ty>, ty: P<Ty>,
attrs: ~[Attribute], attrs: ~[Attribute],
} }
pub type struct_field = Spanned<struct_field_>; pub type StructField = Spanned<StructField_>;
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub enum struct_field_kind { pub enum StructFieldKind {
named_field(Ident, visibility), NamedField(Ident, Visibility),
unnamed_field // element of a tuple-like struct UnnamedField // element of a tuple-like struct
} }
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct struct_def { pub struct StructDef {
fields: ~[struct_field], /* fields, not including ctor */ fields: ~[StructField], /* fields, not including ctor */
/* ID of the constructor. This is only used for tuple- or enum-like /* ID of the constructor. This is only used for tuple- or enum-like
* structs. */ * structs. */
ctor_id: Option<NodeId> ctor_id: Option<NodeId>
@ -1139,57 +1146,57 @@ pub struct struct_def {
we just use dummy names for anon items. we just use dummy names for anon items.
*/ */
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct item { pub struct Item {
ident: Ident, ident: Ident,
attrs: ~[Attribute], attrs: ~[Attribute],
id: NodeId, id: NodeId,
node: item_, node: Item_,
vis: visibility, vis: Visibility,
span: Span, span: Span,
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum item_ { pub enum Item_ {
item_static(P<Ty>, Mutability, @Expr), ItemStatic(P<Ty>, Mutability, @Expr),
item_fn(P<fn_decl>, purity, AbiSet, Generics, P<Block>), ItemFn(P<FnDecl>, Purity, AbiSet, Generics, P<Block>),
item_mod(_mod), ItemMod(Mod),
item_foreign_mod(foreign_mod), ItemForeignMod(ForeignMod),
item_ty(P<Ty>, Generics), ItemTy(P<Ty>, Generics),
item_enum(enum_def, Generics), ItemEnum(EnumDef, Generics),
item_struct(@struct_def, Generics), ItemStruct(@StructDef, Generics),
item_trait(Generics, ~[trait_ref], ~[trait_method]), ItemTrait(Generics, ~[TraitRef], ~[TraitMethod]),
item_impl(Generics, ItemImpl(Generics,
Option<trait_ref>, // (optional) trait this impl implements Option<TraitRef>, // (optional) trait this impl implements
P<Ty>, // self P<Ty>, // self
~[@method]), ~[@Method]),
// a macro invocation (which includes macro definition) // a macro invocation (which includes macro definition)
item_mac(mac), ItemMac(Mac),
} }
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct foreign_item { pub struct ForeignItem {
ident: Ident, ident: Ident,
attrs: ~[Attribute], attrs: ~[Attribute],
node: foreign_item_, node: ForeignItem_,
id: NodeId, id: NodeId,
span: Span, span: Span,
vis: visibility, vis: Visibility,
} }
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub enum foreign_item_ { pub enum ForeignItem_ {
foreign_item_fn(P<fn_decl>, Generics), ForeignItemFn(P<FnDecl>, Generics),
foreign_item_static(P<Ty>, /* is_mutbl */ bool), ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
} }
// The data we save and restore about an inlined item or method. This is not // The data we save and restore about an inlined item or method. This is not
// part of the AST that we parse from a file, but it becomes part of the tree // part of the AST that we parse from a file, but it becomes part of the tree
// that we trans. // that we trans.
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub enum inlined_item { pub enum InlinedItem {
ii_item(@item), IIItem(@Item),
ii_method(DefId /* impl id */, bool /* is provided */, @method), IIMethod(DefId /* impl id */, bool /* is provided */, @Method),
ii_foreign(@foreign_item), IIForeign(@ForeignItem),
} }
#[cfg(test)] #[cfg(test)]
@ -1200,7 +1207,7 @@ mod test {
// Assert that the AST remains Freeze (#10693). // Assert that the AST remains Freeze (#10693).
#[test] fn ast_is_freeze() { #[test] fn ast_is_freeze() {
is_freeze::<item>(); is_freeze::<Item>();
} }
} }
@ -1292,7 +1299,7 @@ mod test {
let e : crate = let e : crate =
spanned{ spanned{
node: crate_{ node: crate_{
module: _mod {view_items: ~[], items: ~[]}, module: Mod {view_items: ~[], items: ~[]},
attrs: ~[], attrs: ~[],
config: ~[] config: ~[]
}, },

View file

@ -14,10 +14,9 @@ use ast;
use ast_util; use ast_util;
use codemap::Span; use codemap::Span;
use diagnostic::SpanHandler; use diagnostic::SpanHandler;
use fold::ast_fold; use fold::Folder;
use fold; use fold;
use parse::token::get_ident_interner; use parse::token::{get_ident_interner, IdentInterner};
use parse::token::ident_interner;
use parse::token::special_idents; use parse::token::special_idents;
use print::pprust; use print::pprust;
use util::small_vector::SmallVector; use util::small_vector::SmallVector;
@ -26,34 +25,34 @@ use std::cell::RefCell;
use std::hashmap::HashMap; use std::hashmap::HashMap;
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]
pub enum path_elt { pub enum PathElem {
path_mod(Ident), PathMod(Ident),
path_name(Ident), PathName(Ident),
// A pretty name can come from an `impl` block. We attempt to select a // A pretty name can come from an `impl` block. We attempt to select a
// reasonable name for debuggers to see, but to guarantee uniqueness with // reasonable name for debuggers to see, but to guarantee uniqueness with
// other paths the hash should also be taken into account during symbol // other paths the hash should also be taken into account during symbol
// generation. // generation.
path_pretty_name(Ident, u64), PathPrettyName(Ident, u64),
} }
impl path_elt { impl PathElem {
pub fn ident(&self) -> Ident { pub fn ident(&self) -> Ident {
match *self { match *self {
path_mod(ident) | PathMod(ident) |
path_name(ident) | PathName(ident) |
path_pretty_name(ident, _) => ident PathPrettyName(ident, _) => ident
} }
} }
} }
pub type path = ~[path_elt]; pub type Path = ~[PathElem];
pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner) pub fn path_to_str_with_sep(p: &[PathElem], sep: &str, itr: @IdentInterner)
-> ~str { -> ~str {
let strs = p.map(|e| { let strs = p.map(|e| {
match *e { match *e {
path_mod(s) | path_name(s) | path_pretty_name(s, _) => { PathMod(s) | PathName(s) | PathPrettyName(s, _) => {
itr.get(s.name) itr.get(s.name)
} }
} }
@ -61,7 +60,7 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner)
strs.connect(sep) strs.connect(sep)
} }
pub fn path_ident_to_str(p: &path, i: Ident, itr: @ident_interner) -> ~str { pub fn path_ident_to_str(p: &Path, i: Ident, itr: @IdentInterner) -> ~str {
if p.is_empty() { if p.is_empty() {
itr.get(i.name).to_owned() itr.get(i.name).to_owned()
} else { } else {
@ -69,13 +68,13 @@ pub fn path_ident_to_str(p: &path, i: Ident, itr: @ident_interner) -> ~str {
} }
} }
pub fn path_to_str(p: &[path_elt], itr: @ident_interner) -> ~str { pub fn path_to_str(p: &[PathElem], itr: @IdentInterner) -> ~str {
path_to_str_with_sep(p, "::", itr) path_to_str_with_sep(p, "::", itr)
} }
pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str { pub fn path_elem_to_str(pe: PathElem, itr: @IdentInterner) -> ~str {
match pe { match pe {
path_mod(s) | path_name(s) | path_pretty_name(s, _) => { PathMod(s) | PathName(s) | PathPrettyName(s, _) => {
itr.get(s.name).to_owned() itr.get(s.name).to_owned()
} }
} }
@ -90,26 +89,26 @@ pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str {
// relic of $ being one of the very few valid symbol names on // relic of $ being one of the very few valid symbol names on
// unix. These kinds of details shouldn't be exposed way up here // unix. These kinds of details shouldn't be exposed way up here
// in the ast. // in the ast.
fn pretty_ty(ty: &Ty, itr: @ident_interner, out: &mut ~str) { fn pretty_ty(ty: &Ty, itr: @IdentInterner, out: &mut ~str) {
let (prefix, subty) = match ty.node { let (prefix, subty) = match ty.node {
ty_uniq(ty) => ("$UP$", &*ty), TyUniq(ty) => ("$UP$", &*ty),
ty_box(ty) => ("$SP$", &*ty), TyBox(ty) => ("$SP$", &*ty),
ty_ptr(mt { ty, mutbl }) => (if mutbl == MutMutable {"$RPmut$"} else {"$RP$"}, TyPtr(MutTy { ty, mutbl }) => (if mutbl == MutMutable {"$RPmut$"} else {"$RP$"},
&*ty), &*ty),
ty_rptr(_, mt { ty, mutbl }) => (if mutbl == MutMutable {"$BPmut$"} else {"$BP$"}, TyRptr(_, MutTy { ty, mutbl }) => (if mutbl == MutMutable {"$BPmut$"} else {"$BP$"},
&*ty), &*ty),
ty_vec(ty) => ("$VEC$", &*ty), TyVec(ty) => ("$VEC$", &*ty),
ty_fixed_length_vec(ty, _) => ("$FIXEDVEC$", &*ty), TyFixedLengthVec(ty, _) => ("$FIXEDVEC$", &*ty),
// these can't be represented as <prefix><contained ty>, so // these can't be represented as <prefix><contained ty>, so
// need custom handling. // need custom handling.
ty_nil => { out.push_str("$NIL$"); return } TyNil => { out.push_str("$NIL$"); return }
ty_path(ref path, _, _) => { TyPath(ref path, _, _) => {
out.push_str(itr.get(path.segments.last().identifier.name)); out.push_str(itr.get(path.segments.last().identifier.name));
return return
} }
ty_tup(ref tys) => { TyTup(ref tys) => {
out.push_str(format!("$TUP_{}$", tys.len())); out.push_str(format!("$TUP_{}$", tys.len()));
for subty in tys.iter() { for subty in tys.iter() {
pretty_ty(*subty, itr, out); pretty_ty(*subty, itr, out);
@ -119,11 +118,11 @@ fn pretty_ty(ty: &Ty, itr: @ident_interner, out: &mut ~str) {
} }
// meh, better than nothing. // meh, better than nothing.
ty_bot => { out.push_str("$BOT$"); return } TyBot => { out.push_str("$BOT$"); return }
ty_closure(..) => { out.push_str("$CLOSURE$"); return } TyClosure(..) => { out.push_str("$CLOSURE$"); return }
ty_bare_fn(..) => { out.push_str("$FN$"); return } TyBareFn(..) => { out.push_str("$FN$"); return }
ty_typeof(..) => { out.push_str("$TYPEOF$"); return } TyTypeof(..) => { out.push_str("$TYPEOF$"); return }
ty_infer(..) => { out.push_str("$INFER$"); return } TyInfer(..) => { out.push_str("$INFER$"); return }
}; };
@ -131,7 +130,7 @@ fn pretty_ty(ty: &Ty, itr: @ident_interner, out: &mut ~str) {
pretty_ty(subty, itr, out); pretty_ty(subty, itr, out);
} }
pub fn impl_pretty_name(trait_ref: &Option<trait_ref>, ty: &Ty) -> path_elt { pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> PathElem {
let itr = get_ident_interner(); let itr = get_ident_interner();
let hash = (trait_ref, ty).hash(); let hash = (trait_ref, ty).hash();
@ -145,56 +144,56 @@ pub fn impl_pretty_name(trait_ref: &Option<trait_ref>, ty: &Ty) -> path_elt {
}; };
pretty_ty(ty, itr, &mut pretty); pretty_ty(ty, itr, &mut pretty);
path_pretty_name(Ident::new(itr.gensym(pretty)), hash) PathPrettyName(Ident::new(itr.gensym(pretty)), hash)
} }
#[deriving(Clone)] #[deriving(Clone)]
pub enum ast_node { pub enum Node {
node_item(@item, @path), NodeItem(@Item, @Path),
node_foreign_item(@foreign_item, AbiSet, visibility, @path), NodeForeignItem(@ForeignItem, AbiSet, Visibility, @Path),
node_trait_method(@trait_method, DefId /* trait did */, NodeTraitMethod(@TraitMethod, DefId /* trait did */,
@path /* path to the trait */), @Path /* path to the trait */),
node_method(@method, DefId /* impl did */, @path /* path to the impl */), NodeMethod(@Method, DefId /* impl did */, @Path /* path to the impl */),
/// node_variant represents a variant of an enum, e.g., for /// NodeVariant represents a variant of an enum, e.g., for
/// `enum A { B, C, D }`, there would be a node_item for `A`, and a /// `enum A { B, C, D }`, there would be a NodeItem for `A`, and a
/// node_variant item for each of `B`, `C`, and `D`. /// NodeVariant item for each of `B`, `C`, and `D`.
node_variant(P<variant>, @item, @path), NodeVariant(P<Variant>, @Item, @Path),
node_expr(@Expr), NodeExpr(@Expr),
node_stmt(@Stmt), NodeStmt(@Stmt),
node_arg(@Pat), NodeArg(@Pat),
// HACK(eddyb) should always be a pattern, but `self` is not, and thus it // HACK(eddyb) should always be a pattern, but `self` is not, and thus it
// is identified only by an ident and no span is available. In all other // is identified only by an ident and no span is available. In all other
// cases, node_span will return the proper span (required by borrowck). // cases, node_span will return the proper span (required by borrowck).
node_local(Ident, Option<@Pat>), NodeLocal(Ident, Option<@Pat>),
node_block(P<Block>), NodeBlock(P<Block>),
/// node_struct_ctor represents a tuple struct. /// NodeStructCtor represents a tuple struct.
node_struct_ctor(@struct_def, @item, @path), NodeStructCtor(@StructDef, @Item, @Path),
node_callee_scope(@Expr) NodeCalleeScope(@Expr)
} }
impl ast_node { impl Node {
pub fn with_attrs<T>(&self, f: |Option<&[Attribute]>| -> T) -> T { pub fn with_attrs<T>(&self, f: |Option<&[Attribute]>| -> T) -> T {
let attrs = match *self { let attrs = match *self {
node_item(i, _) => Some(i.attrs.as_slice()), NodeItem(i, _) => Some(i.attrs.as_slice()),
node_foreign_item(fi, _, _, _) => Some(fi.attrs.as_slice()), NodeForeignItem(fi, _, _, _) => Some(fi.attrs.as_slice()),
node_trait_method(tm, _, _) => match *tm { NodeTraitMethod(tm, _, _) => match *tm {
required(ref type_m) => Some(type_m.attrs.as_slice()), Required(ref type_m) => Some(type_m.attrs.as_slice()),
provided(m) => Some(m.attrs.as_slice()) Provided(m) => Some(m.attrs.as_slice())
}, },
node_method(m, _, _) => Some(m.attrs.as_slice()), NodeMethod(m, _, _) => Some(m.attrs.as_slice()),
node_variant(ref v, _, _) => Some(v.node.attrs.as_slice()), NodeVariant(ref v, _, _) => Some(v.node.attrs.as_slice()),
// unit/tuple structs take the attributes straight from // unit/tuple structs take the attributes straight from
// the struct definition. // the struct definition.
node_struct_ctor(_, strct, _) => Some(strct.attrs.as_slice()), NodeStructCtor(_, strct, _) => Some(strct.attrs.as_slice()),
_ => None _ => None
}; };
f(attrs) f(attrs)
} }
} }
pub type map = @RefCell<HashMap<NodeId, ast_node>>; pub type Map = @RefCell<HashMap<NodeId, Node>>;
pub trait FoldOps { pub trait FoldOps {
fn new_id(&self, id: ast::NodeId) -> ast::NodeId { fn new_id(&self, id: ast::NodeId) -> ast::NodeId {
@ -206,24 +205,24 @@ pub trait FoldOps {
} }
pub struct Ctx<F> { pub struct Ctx<F> {
map: map, map: Map,
path: path, path: Path,
diag: @SpanHandler, diag: @SpanHandler,
fold_ops: F fold_ops: F
} }
impl<F> Ctx<F> { impl<F> Ctx<F> {
fn insert(&self, id: ast::NodeId, node: ast_node) { fn insert(&self, id: ast::NodeId, node: Node) {
let mut map = self.map.borrow_mut(); let mut map = self.map.borrow_mut();
map.get().insert(id, node); map.get().insert(id, node);
} }
fn map_self(&self, m: @method) { fn map_self(&self, m: @Method) {
self.insert(m.self_id, node_local(special_idents::self_, None)); self.insert(m.self_id, NodeLocal(special_idents::self_, None));
} }
} }
impl<F: FoldOps> ast_fold for Ctx<F> { impl<F: FoldOps> Folder for Ctx<F> {
fn new_id(&mut self, id: ast::NodeId) -> ast::NodeId { fn new_id(&mut self, id: ast::NodeId) -> ast::NodeId {
self.fold_ops.new_id(id) self.fold_ops.new_id(id)
} }
@ -232,69 +231,65 @@ impl<F: FoldOps> ast_fold for Ctx<F> {
self.fold_ops.new_span(span) self.fold_ops.new_span(span)
} }
fn fold_item(&mut self, i: @item) -> SmallVector<@item> { fn fold_item(&mut self, i: @Item) -> SmallVector<@Item> {
// clone is FIXME #2543 // clone is FIXME #2543
let item_path = @self.path.clone(); let item_path = @self.path.clone();
self.path.push(match i.node { self.path.push(match i.node {
item_impl(_, ref maybe_trait, ty, _) => { ItemImpl(_, ref maybe_trait, ty, _) => {
// Right now the ident on impls is __extensions__ which isn't // Right now the ident on impls is __extensions__ which isn't
// very pretty when debugging, so attempt to select a better // very pretty when debugging, so attempt to select a better
// name to use. // name to use.
impl_pretty_name(maybe_trait, ty) impl_pretty_name(maybe_trait, ty)
} }
item_mod(_) | item_foreign_mod(_) => path_mod(i.ident), ItemMod(_) | ItemForeignMod(_) => PathMod(i.ident),
_ => path_name(i.ident) _ => PathName(i.ident)
}); });
let i = fold::noop_fold_item(i, self).expect_one("expected one item"); let i = fold::noop_fold_item(i, self).expect_one("expected one item");
self.insert(i.id, node_item(i, item_path)); self.insert(i.id, NodeItem(i, item_path));
match i.node { match i.node {
item_impl(_, _, _, ref ms) => { ItemImpl(_, _, _, ref ms) => {
// clone is FIXME #2543 // clone is FIXME #2543
let p = @self.path.clone(); let p = @self.path.clone();
let impl_did = ast_util::local_def(i.id); let impl_did = ast_util::local_def(i.id);
for &m in ms.iter() { for &m in ms.iter() {
self.insert(m.id, node_method(m, impl_did, p)); self.insert(m.id, NodeMethod(m, impl_did, p));
self.map_self(m); self.map_self(m);
} }
} }
item_enum(ref enum_definition, _) => { ItemEnum(ref enum_definition, _) => {
// clone is FIXME #2543 // clone is FIXME #2543
let p = @self.path.clone(); let p = @self.path.clone();
for &v in enum_definition.variants.iter() { for &v in enum_definition.variants.iter() {
self.insert(v.node.id, node_variant(v, i, p)); self.insert(v.node.id, NodeVariant(v, i, p));
} }
} }
item_foreign_mod(ref nm) => { ItemForeignMod(ref nm) => {
for nitem in nm.items.iter() { for nitem in nm.items.iter() {
// Compute the visibility for this native item. // Compute the visibility for this native item.
let visibility = match nitem.vis { let visibility = nitem.vis.inherit_from(i.vis);
public => public,
private => private,
inherited => i.vis
};
self.insert(nitem.id, self.insert(nitem.id,
// Anonymous extern mods go in the parent scope. // Anonymous extern mods go in the parent scope.
node_foreign_item(*nitem, nm.abis, visibility, item_path)); NodeForeignItem(*nitem, nm.abis, visibility, item_path));
} }
} }
item_struct(struct_def, _) => { ItemStruct(struct_def, _) => {
// If this is a tuple-like struct, register the constructor. // If this is a tuple-like struct, register the constructor.
match struct_def.ctor_id { match struct_def.ctor_id {
None => {} None => {}
Some(ctor_id) => { Some(ctor_id) => {
// clone is FIXME #2543 // clone is FIXME #2543
let p = @self.path.clone(); let p = @self.path.clone();
self.insert(ctor_id, node_struct_ctor(struct_def, i, p)); self.insert(ctor_id, NodeStructCtor(struct_def, i, p));
} }
} }
} }
item_trait(_, ref traits, ref methods) => { ItemTrait(_, ref traits, ref methods) => {
for t in traits.iter() { for t in traits.iter() {
self.insert(t.ref_id, node_item(i, item_path)); self.insert(t.ref_id, NodeItem(i, item_path));
} }
// clone is FIXME #2543 // clone is FIXME #2543
@ -302,11 +297,11 @@ impl<F: FoldOps> ast_fold for Ctx<F> {
for tm in methods.iter() { for tm in methods.iter() {
let d_id = ast_util::local_def(i.id); let d_id = ast_util::local_def(i.id);
match *tm { match *tm {
required(ref m) => { Required(ref m) => {
self.insert(m.id, node_trait_method(@(*tm).clone(), d_id, p)); self.insert(m.id, NodeTraitMethod(@(*tm).clone(), d_id, p));
} }
provided(m) => { Provided(m) => {
self.insert(m.id, node_trait_method(@provided(m), d_id, p)); self.insert(m.id, NodeTraitMethod(@Provided(m), d_id, p));
self.map_self(m); self.map_self(m);
} }
} }
@ -325,7 +320,7 @@ impl<F: FoldOps> ast_fold for Ctx<F> {
match pat.node { match pat.node {
PatIdent(_, ref path, _) => { PatIdent(_, ref path, _) => {
// Note: this is at least *potentially* a pattern... // Note: this is at least *potentially* a pattern...
self.insert(pat.id, node_local(ast_util::path_to_ident(path), Some(pat))); self.insert(pat.id, NodeLocal(ast_util::path_to_ident(path), Some(pat)));
} }
_ => {} _ => {}
} }
@ -336,13 +331,13 @@ impl<F: FoldOps> ast_fold for Ctx<F> {
fn fold_expr(&mut self, expr: @Expr) -> @Expr { fn fold_expr(&mut self, expr: @Expr) -> @Expr {
let expr = fold::noop_fold_expr(expr, self); let expr = fold::noop_fold_expr(expr, self);
self.insert(expr.id, node_expr(expr)); self.insert(expr.id, NodeExpr(expr));
// Expressions which are or might be calls: // Expressions which are or might be calls:
{ {
let r = expr.get_callee_id(); let r = expr.get_callee_id();
for callee_id in r.iter() { for callee_id in r.iter() {
self.insert(*callee_id, node_callee_scope(expr)); self.insert(*callee_id, NodeCalleeScope(expr));
} }
} }
@ -351,34 +346,34 @@ impl<F: FoldOps> ast_fold for Ctx<F> {
fn fold_stmt(&mut self, stmt: &Stmt) -> SmallVector<@Stmt> { fn fold_stmt(&mut self, stmt: &Stmt) -> SmallVector<@Stmt> {
let stmt = fold::noop_fold_stmt(stmt, self).expect_one("expected one statement"); let stmt = fold::noop_fold_stmt(stmt, self).expect_one("expected one statement");
self.insert(ast_util::stmt_id(stmt), node_stmt(stmt)); self.insert(ast_util::stmt_id(stmt), NodeStmt(stmt));
SmallVector::one(stmt) SmallVector::one(stmt)
} }
fn fold_method(&mut self, m: @method) -> @method { fn fold_method(&mut self, m: @Method) -> @Method {
self.path.push(path_name(m.ident)); self.path.push(PathName(m.ident));
let m = fold::noop_fold_method(m, self); let m = fold::noop_fold_method(m, self);
self.path.pop(); self.path.pop();
m m
} }
fn fold_fn_decl(&mut self, decl: &fn_decl) -> P<fn_decl> { fn fold_fn_decl(&mut self, decl: &FnDecl) -> P<FnDecl> {
let decl = fold::noop_fold_fn_decl(decl, self); let decl = fold::noop_fold_fn_decl(decl, self);
for a in decl.inputs.iter() { for a in decl.inputs.iter() {
self.insert(a.id, node_arg(a.pat)); self.insert(a.id, NodeArg(a.pat));
} }
decl decl
} }
fn fold_block(&mut self, block: P<Block>) -> P<Block> { fn fold_block(&mut self, block: P<Block>) -> P<Block> {
let block = fold::noop_fold_block(block, self); let block = fold::noop_fold_block(block, self);
self.insert(block.id, node_block(block)); self.insert(block.id, NodeBlock(block));
block block
} }
} }
pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate, pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate,
fold_ops: F) -> (Crate, map) { fold_ops: F) -> (Crate, Map) {
let mut cx = Ctx { let mut cx = Ctx {
map: @RefCell::new(HashMap::new()), map: @RefCell::new(HashMap::new()),
path: ~[], path: ~[],
@ -392,11 +387,11 @@ pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate,
// crate. The `path` should be the path to the item but should not include // crate. The `path` should be the path to the item but should not include
// the item itself. // the item itself.
pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler, pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler,
map: map, map: Map,
path: path, path: Path,
fold_ops: F, fold_ops: F,
fold_ii: |&mut Ctx<F>| -> inlined_item) fold_ii: |&mut Ctx<F>| -> InlinedItem)
-> inlined_item { -> InlinedItem {
// I believe it is ok for the local IDs of inlined items from other crates // I believe it is ok for the local IDs of inlined items from other crates
// to overlap with the local ids from this crate, so just generate the ids // to overlap with the local ids from this crate, so just generate the ids
// starting from 0. // starting from 0.
@ -413,18 +408,18 @@ pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler,
// don't decode and instantiate the impl, but just the method, we have to // don't decode and instantiate the impl, but just the method, we have to
// add it to the table now. Likewise with foreign items. // add it to the table now. Likewise with foreign items.
match ii { match ii {
ii_item(..) => {} // fallthrough IIItem(..) => {} // fallthrough
ii_foreign(i) => { IIForeign(i) => {
cx.insert(i.id, node_foreign_item(i, cx.insert(i.id, NodeForeignItem(i,
AbiSet::Intrinsic(), AbiSet::Intrinsic(),
i.vis, // Wrong but OK i.vis, // Wrong but OK
@path)); @path));
} }
ii_method(impl_did, is_provided, m) => { IIMethod(impl_did, is_provided, m) => {
let entry = if is_provided { let entry = if is_provided {
node_trait_method(@provided(m), impl_did, @path) NodeTraitMethod(@Provided(m), impl_did, @path)
} else { } else {
node_method(m, impl_did, @path) NodeMethod(m, impl_did, @path)
}; };
cx.insert(m.id, entry); cx.insert(m.id, entry);
cx.map_self(m); cx.map_self(m);
@ -434,100 +429,98 @@ pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler,
ii ii
} }
pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str { pub fn node_id_to_str(map: Map, id: NodeId, itr: @IdentInterner) -> ~str {
let map = map.borrow(); let map = map.borrow();
match map.get().find(&id) { match map.get().find(&id) {
None => { None => {
format!("unknown node (id={})", id) format!("unknown node (id={})", id)
} }
Some(&node_item(item, path)) => { Some(&NodeItem(item, path)) => {
let path_str = path_ident_to_str(path, item.ident, itr); let path_str = path_ident_to_str(path, item.ident, itr);
let item_str = match item.node { let item_str = match item.node {
item_static(..) => ~"static", ItemStatic(..) => ~"static",
item_fn(..) => ~"fn", ItemFn(..) => ~"fn",
item_mod(..) => ~"mod", ItemMod(..) => ~"mod",
item_foreign_mod(..) => ~"foreign mod", ItemForeignMod(..) => ~"foreign mod",
item_ty(..) => ~"ty", ItemTy(..) => ~"ty",
item_enum(..) => ~"enum", ItemEnum(..) => ~"enum",
item_struct(..) => ~"struct", ItemStruct(..) => ~"struct",
item_trait(..) => ~"trait", ItemTrait(..) => ~"trait",
item_impl(..) => ~"impl", ItemImpl(..) => ~"impl",
item_mac(..) => ~"macro" ItemMac(..) => ~"macro"
}; };
format!("{} {} (id={})", item_str, path_str, id) format!("{} {} (id={})", item_str, path_str, id)
} }
Some(&node_foreign_item(item, abi, _, path)) => { Some(&NodeForeignItem(item, abi, _, path)) => {
format!("foreign item {} with abi {:?} (id={})", format!("foreign item {} with abi {:?} (id={})",
path_ident_to_str(path, item.ident, itr), abi, id) path_ident_to_str(path, item.ident, itr), abi, id)
} }
Some(&node_method(m, _, path)) => { Some(&NodeMethod(m, _, path)) => {
format!("method {} in {} (id={})", format!("method {} in {} (id={})",
itr.get(m.ident.name), path_to_str(*path, itr), id) itr.get(m.ident.name), path_to_str(*path, itr), id)
} }
Some(&node_trait_method(ref tm, _, path)) => { Some(&NodeTraitMethod(ref tm, _, path)) => {
let m = ast_util::trait_method_to_ty_method(&**tm); let m = ast_util::trait_method_to_ty_method(&**tm);
format!("method {} in {} (id={})", format!("method {} in {} (id={})",
itr.get(m.ident.name), path_to_str(*path, itr), id) itr.get(m.ident.name), path_to_str(*path, itr), id)
} }
Some(&node_variant(ref variant, _, path)) => { Some(&NodeVariant(ref variant, _, path)) => {
format!("variant {} in {} (id={})", format!("variant {} in {} (id={})",
itr.get(variant.node.name.name), path_to_str(*path, itr), id) itr.get(variant.node.name.name), path_to_str(*path, itr), id)
} }
Some(&node_expr(expr)) => { Some(&NodeExpr(expr)) => {
format!("expr {} (id={})", pprust::expr_to_str(expr, itr), id) format!("expr {} (id={})", pprust::expr_to_str(expr, itr), id)
} }
Some(&node_callee_scope(expr)) => { Some(&NodeCalleeScope(expr)) => {
format!("callee_scope {} (id={})", pprust::expr_to_str(expr, itr), id) format!("callee_scope {} (id={})", pprust::expr_to_str(expr, itr), id)
} }
Some(&node_stmt(stmt)) => { Some(&NodeStmt(stmt)) => {
format!("stmt {} (id={})", format!("stmt {} (id={})",
pprust::stmt_to_str(stmt, itr), id) pprust::stmt_to_str(stmt, itr), id)
} }
Some(&node_arg(pat)) => { Some(&NodeArg(pat)) => {
format!("arg {} (id={})", pprust::pat_to_str(pat, itr), id) format!("arg {} (id={})", pprust::pat_to_str(pat, itr), id)
} }
Some(&node_local(ident, _)) => { Some(&NodeLocal(ident, _)) => {
format!("local (id={}, name={})", id, itr.get(ident.name)) format!("local (id={}, name={})", id, itr.get(ident.name))
} }
Some(&node_block(block)) => { Some(&NodeBlock(block)) => {
format!("block {} (id={})", pprust::block_to_str(block, itr), id) format!("block {} (id={})", pprust::block_to_str(block, itr), id)
} }
Some(&node_struct_ctor(_, _, path)) => { Some(&NodeStructCtor(_, _, path)) => {
format!("struct_ctor {} (id={})", path_to_str(*path, itr), id) format!("struct_ctor {} (id={})", path_to_str(*path, itr), id)
} }
} }
} }
pub fn node_item_query<Result>(items: map, id: NodeId, query: |@item| -> Result, error_msg: ~str) pub fn node_item_query<Result>(items: Map, id: NodeId, query: |@Item| -> Result, error_msg: ~str)
-> Result { -> Result {
let items = items.borrow(); let items = items.borrow();
match items.get().find(&id) { match items.get().find(&id) {
Some(&node_item(it, _)) => query(it), Some(&NodeItem(it, _)) => query(it),
_ => fail!("{}", error_msg) _ => fail!("{}", error_msg)
} }
} }
pub fn node_span(items: map, pub fn node_span(items: Map, id: ast::NodeId) -> Span {
id: ast::NodeId)
-> Span {
let items = items.borrow(); let items = items.borrow();
match items.get().find(&id) { match items.get().find(&id) {
Some(&node_item(item, _)) => item.span, Some(&NodeItem(item, _)) => item.span,
Some(&node_foreign_item(foreign_item, _, _, _)) => foreign_item.span, Some(&NodeForeignItem(foreign_item, _, _, _)) => foreign_item.span,
Some(&node_trait_method(@required(ref type_method), _, _)) => type_method.span, Some(&NodeTraitMethod(@Required(ref type_method), _, _)) => type_method.span,
Some(&node_trait_method(@provided(ref method), _, _)) => method.span, Some(&NodeTraitMethod(@Provided(ref method), _, _)) => method.span,
Some(&node_method(method, _, _)) => method.span, Some(&NodeMethod(method, _, _)) => method.span,
Some(&node_variant(variant, _, _)) => variant.span, Some(&NodeVariant(variant, _, _)) => variant.span,
Some(&node_expr(expr)) => expr.span, Some(&NodeExpr(expr)) => expr.span,
Some(&node_stmt(stmt)) => stmt.span, Some(&NodeStmt(stmt)) => stmt.span,
Some(&node_arg(pat)) => pat.span, Some(&NodeArg(pat)) => pat.span,
Some(&node_local(_, pat)) => match pat { Some(&NodeLocal(_, pat)) => match pat {
Some(pat) => pat.span, Some(pat) => pat.span,
None => fail!("node_span: cannot get span from node_local (likely `self`)") None => fail!("node_span: cannot get span from NodeLocal (likely `self`)")
}, },
Some(&node_block(block)) => block.span, Some(&NodeBlock(block)) => block.span,
Some(&node_struct_ctor(_, item, _)) => item.span, Some(&NodeStructCtor(_, item, _)) => item.span,
Some(&node_callee_scope(expr)) => expr.span, Some(&NodeCalleeScope(expr)) => expr.span,
None => fail!("node_span: could not find id {}", id), None => fail!("node_span: could not find id {}", id),
} }
} }

View file

@ -151,46 +151,46 @@ pub fn is_path(e: @Expr) -> bool {
return match e.node { ExprPath(_) => true, _ => false }; return match e.node { ExprPath(_) => true, _ => false };
} }
pub fn int_ty_to_str(t: int_ty) -> ~str { pub fn int_ty_to_str(t: IntTy) -> ~str {
match t { match t {
ty_i => ~"", TyI => ~"",
ty_i8 => ~"i8", TyI8 => ~"i8",
ty_i16 => ~"i16", TyI16 => ~"i16",
ty_i32 => ~"i32", TyI32 => ~"i32",
ty_i64 => ~"i64" TyI64 => ~"i64"
} }
} }
pub fn int_ty_max(t: int_ty) -> u64 { pub fn int_ty_max(t: IntTy) -> u64 {
match t { match t {
ty_i8 => 0x80u64, TyI8 => 0x80u64,
ty_i16 => 0x8000u64, TyI16 => 0x8000u64,
ty_i | ty_i32 => 0x80000000u64, // actually ni about ty_i TyI | TyI32 => 0x80000000u64, // actually ni about TyI
ty_i64 => 0x8000000000000000u64 TyI64 => 0x8000000000000000u64
} }
} }
pub fn uint_ty_to_str(t: uint_ty) -> ~str { pub fn uint_ty_to_str(t: UintTy) -> ~str {
match t { match t {
ty_u => ~"u", TyU => ~"u",
ty_u8 => ~"u8", TyU8 => ~"u8",
ty_u16 => ~"u16", TyU16 => ~"u16",
ty_u32 => ~"u32", TyU32 => ~"u32",
ty_u64 => ~"u64" TyU64 => ~"u64"
} }
} }
pub fn uint_ty_max(t: uint_ty) -> u64 { pub fn uint_ty_max(t: UintTy) -> u64 {
match t { match t {
ty_u8 => 0xffu64, TyU8 => 0xffu64,
ty_u16 => 0xffffu64, TyU16 => 0xffffu64,
ty_u | ty_u32 => 0xffffffffu64, // actually ni about ty_u TyU | TyU32 => 0xffffffffu64, // actually ni about TyU
ty_u64 => 0xffffffffffffffffu64 TyU64 => 0xffffffffffffffffu64
} }
} }
pub fn float_ty_to_str(t: float_ty) -> ~str { pub fn float_ty_to_str(t: FloatTy) -> ~str {
match t { ty_f32 => ~"f32", ty_f64 => ~"f64" } match t { TyF32 => ~"f32", TyF64 => ~"f64" }
} }
pub fn is_call_expr(e: @Expr) -> bool { pub fn is_call_expr(e: @Expr) -> bool {
@ -243,21 +243,21 @@ pub fn unguarded_pat(a: &Arm) -> Option<~[@Pat]> {
} }
} }
pub fn public_methods(ms: ~[@method]) -> ~[@method] { pub fn public_methods(ms: ~[@Method]) -> ~[@Method] {
ms.move_iter().filter(|m| { ms.move_iter().filter(|m| {
match m.vis { match m.vis {
public => true, Public => true,
_ => false _ => false
} }
}).collect() }).collect()
} }
// extract a TypeMethod from a trait_method. if the trait_method is // extract a TypeMethod from a TraitMethod. if the TraitMethod is
// a default, pull out the useful fields to make a TypeMethod // a default, pull out the useful fields to make a TypeMethod
pub fn trait_method_to_ty_method(method: &trait_method) -> TypeMethod { pub fn trait_method_to_ty_method(method: &TraitMethod) -> TypeMethod {
match *method { match *method {
required(ref m) => (*m).clone(), Required(ref m) => (*m).clone(),
provided(ref m) => { Provided(ref m) => {
TypeMethod { TypeMethod {
ident: m.ident, ident: m.ident,
attrs: m.attrs.clone(), attrs: m.attrs.clone(),
@ -272,23 +272,23 @@ pub fn trait_method_to_ty_method(method: &trait_method) -> TypeMethod {
} }
} }
pub fn split_trait_methods(trait_methods: &[trait_method]) pub fn split_trait_methods(trait_methods: &[TraitMethod])
-> (~[TypeMethod], ~[@method]) { -> (~[TypeMethod], ~[@Method]) {
let mut reqd = ~[]; let mut reqd = ~[];
let mut provd = ~[]; let mut provd = ~[];
for trt_method in trait_methods.iter() { for trt_method in trait_methods.iter() {
match *trt_method { match *trt_method {
required(ref tm) => reqd.push((*tm).clone()), Required(ref tm) => reqd.push((*tm).clone()),
provided(m) => provd.push(m) Provided(m) => provd.push(m)
} }
}; };
(reqd, provd) (reqd, provd)
} }
pub fn struct_field_visibility(field: ast::struct_field) -> visibility { pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
match field.node.kind { match field.node.kind {
ast::named_field(_, visibility) => visibility, ast::NamedField(_, visibility) => visibility,
ast::unnamed_field => ast::public ast::UnnamedField => ast::Public
} }
} }
@ -332,14 +332,14 @@ pub fn empty_generics() -> Generics {
// Enumerating the IDs which appear in an AST // Enumerating the IDs which appear in an AST
#[deriving(Encodable, Decodable)] #[deriving(Encodable, Decodable)]
pub struct id_range { pub struct IdRange {
min: NodeId, min: NodeId,
max: NodeId, max: NodeId,
} }
impl id_range { impl IdRange {
pub fn max() -> id_range { pub fn max() -> IdRange {
id_range { IdRange {
min: u32::max_value, min: u32::max_value,
max: u32::min_value, max: u32::min_value,
} }
@ -378,7 +378,7 @@ impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> {
impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
fn visit_mod(&mut self, fn visit_mod(&mut self,
module: &_mod, module: &Mod,
_: Span, _: Span,
node_id: NodeId, node_id: NodeId,
env: ()) { env: ()) {
@ -386,19 +386,19 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
visit::walk_mod(self, module, env) visit::walk_mod(self, module, env)
} }
fn visit_view_item(&mut self, view_item: &view_item, env: ()) { fn visit_view_item(&mut self, view_item: &ViewItem, env: ()) {
match view_item.node { match view_item.node {
view_item_extern_mod(_, _, node_id) => { ViewItemExternMod(_, _, node_id) => {
self.operation.visit_id(node_id) self.operation.visit_id(node_id)
} }
view_item_use(ref view_paths) => { ViewItemUse(ref view_paths) => {
for view_path in view_paths.iter() { for view_path in view_paths.iter() {
match view_path.node { match view_path.node {
view_path_simple(_, _, node_id) | ViewPathSimple(_, _, node_id) |
view_path_glob(_, node_id) => { ViewPathGlob(_, node_id) => {
self.operation.visit_id(node_id) self.operation.visit_id(node_id)
} }
view_path_list(_, ref paths, node_id) => { ViewPathList(_, ref paths, node_id) => {
self.operation.visit_id(node_id); self.operation.visit_id(node_id);
for path in paths.iter() { for path in paths.iter() {
self.operation.visit_id(path.node.id) self.operation.visit_id(path.node.id)
@ -411,12 +411,12 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
visit::walk_view_item(self, view_item, env) visit::walk_view_item(self, view_item, env)
} }
fn visit_foreign_item(&mut self, foreign_item: &foreign_item, env: ()) { fn visit_foreign_item(&mut self, foreign_item: &ForeignItem, env: ()) {
self.operation.visit_id(foreign_item.id); self.operation.visit_id(foreign_item.id);
visit::walk_foreign_item(self, foreign_item, env) visit::walk_foreign_item(self, foreign_item, env)
} }
fn visit_item(&mut self, item: &item, env: ()) { fn visit_item(&mut self, item: &Item, env: ()) {
if !self.pass_through_items { if !self.pass_through_items {
if self.visited_outermost { if self.visited_outermost {
return return
@ -427,7 +427,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
self.operation.visit_id(item.id); self.operation.visit_id(item.id);
match item.node { match item.node {
item_enum(ref enum_definition, _) => { ItemEnum(ref enum_definition, _) => {
for variant in enum_definition.variants.iter() { for variant in enum_definition.variants.iter() {
self.operation.visit_id(variant.node.id) self.operation.visit_id(variant.node.id)
} }
@ -475,7 +475,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
fn visit_ty(&mut self, typ: &Ty, env: ()) { fn visit_ty(&mut self, typ: &Ty, env: ()) {
self.operation.visit_id(typ.id); self.operation.visit_id(typ.id);
match typ.node { match typ.node {
ty_path(_, _, id) => self.operation.visit_id(id), TyPath(_, _, id) => self.operation.visit_id(id),
_ => {} _ => {}
} }
visit::walk_ty(self, typ, env) visit::walk_ty(self, typ, env)
@ -487,16 +487,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
} }
fn visit_fn(&mut self, fn visit_fn(&mut self,
function_kind: &visit::fn_kind, function_kind: &visit::FnKind,
function_declaration: &fn_decl, function_declaration: &FnDecl,
block: &Block, block: &Block,
span: Span, span: Span,
node_id: NodeId, node_id: NodeId,
env: ()) { env: ()) {
if !self.pass_through_items { if !self.pass_through_items {
match *function_kind { match *function_kind {
visit::fk_method(..) if self.visited_outermost => return, visit::FkMethod(..) if self.visited_outermost => return,
visit::fk_method(..) => self.visited_outermost = true, visit::FkMethod(..) => self.visited_outermost = true,
_ => {} _ => {}
} }
} }
@ -504,14 +504,14 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
self.operation.visit_id(node_id); self.operation.visit_id(node_id);
match *function_kind { match *function_kind {
visit::fk_item_fn(_, generics, _, _) => { visit::FkItemFn(_, generics, _, _) => {
self.visit_generics_helper(generics) self.visit_generics_helper(generics)
} }
visit::fk_method(_, generics, method) => { visit::FkMethod(_, generics, method) => {
self.operation.visit_id(method.self_id); self.operation.visit_id(method.self_id);
self.visit_generics_helper(generics) self.visit_generics_helper(generics)
} }
visit::fk_fn_block => {} visit::FkFnBlock => {}
} }
for argument in function_declaration.inputs.iter() { for argument in function_declaration.inputs.iter() {
@ -528,19 +528,19 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
if !self.pass_through_items { if !self.pass_through_items {
match *function_kind { match *function_kind {
visit::fk_method(..) => self.visited_outermost = false, visit::FkMethod(..) => self.visited_outermost = false,
_ => {} _ => {}
} }
} }
} }
fn visit_struct_field(&mut self, struct_field: &struct_field, env: ()) { fn visit_struct_field(&mut self, struct_field: &StructField, env: ()) {
self.operation.visit_id(struct_field.node.id); self.operation.visit_id(struct_field.node.id);
visit::walk_struct_field(self, struct_field, env) visit::walk_struct_field(self, struct_field, env)
} }
fn visit_struct_def(&mut self, fn visit_struct_def(&mut self,
struct_def: &struct_def, struct_def: &StructDef,
ident: ast::Ident, ident: ast::Ident,
generics: &ast::Generics, generics: &ast::Generics,
id: NodeId, id: NodeId,
@ -550,16 +550,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
visit::walk_struct_def(self, struct_def, ident, generics, id, ()); visit::walk_struct_def(self, struct_def, ident, generics, id, ());
} }
fn visit_trait_method(&mut self, tm: &ast::trait_method, _: ()) { fn visit_trait_method(&mut self, tm: &ast::TraitMethod, _: ()) {
match *tm { match *tm {
ast::required(ref m) => self.operation.visit_id(m.id), ast::Required(ref m) => self.operation.visit_id(m.id),
ast::provided(ref m) => self.operation.visit_id(m.id), ast::Provided(ref m) => self.operation.visit_id(m.id),
} }
visit::walk_trait_method(self, tm, ()); visit::walk_trait_method(self, tm, ());
} }
} }
pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &inlined_item, pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem,
operation: &O) { operation: &O) {
let mut id_visitor = IdVisitor { let mut id_visitor = IdVisitor {
operation: operation, operation: operation,
@ -568,14 +568,14 @@ pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &inlined_item,
}; };
match *item { match *item {
ii_item(i) => id_visitor.visit_item(i, ()), IIItem(i) => id_visitor.visit_item(i, ()),
ii_foreign(i) => id_visitor.visit_foreign_item(i, ()), IIForeign(i) => id_visitor.visit_foreign_item(i, ()),
ii_method(_, _, m) => visit::walk_method_helper(&mut id_visitor, m, ()), IIMethod(_, _, m) => visit::walk_method_helper(&mut id_visitor, m, ()),
} }
} }
struct IdRangeComputingVisitor { struct IdRangeComputingVisitor {
result: Cell<id_range>, result: Cell<IdRange>,
} }
impl IdVisitingOperation for IdRangeComputingVisitor { impl IdVisitingOperation for IdRangeComputingVisitor {
@ -586,18 +586,18 @@ impl IdVisitingOperation for IdRangeComputingVisitor {
} }
} }
pub fn compute_id_range_for_inlined_item(item: &inlined_item) -> id_range { pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange {
let visitor = IdRangeComputingVisitor { let visitor = IdRangeComputingVisitor {
result: Cell::new(id_range::max()) result: Cell::new(IdRange::max())
}; };
visit_ids_for_inlined_item(item, &visitor); visit_ids_for_inlined_item(item, &visitor);
visitor.result.get() visitor.result.get()
} }
pub fn is_item_impl(item: @ast::item) -> bool { pub fn is_item_impl(item: @ast::Item) -> bool {
match item.node { match item.node {
item_impl(..) => true, ItemImpl(..) => true,
_ => false _ => false
} }
} }
@ -630,21 +630,21 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
} }
pub trait EachViewItem { pub trait EachViewItem {
fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool; fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool;
} }
struct EachViewItemData<'a> { struct EachViewItemData<'a> {
callback: 'a |&ast::view_item| -> bool, callback: 'a |&ast::ViewItem| -> bool,
} }
impl<'a> Visitor<()> for EachViewItemData<'a> { impl<'a> Visitor<()> for EachViewItemData<'a> {
fn visit_view_item(&mut self, view_item: &ast::view_item, _: ()) { fn visit_view_item(&mut self, view_item: &ast::ViewItem, _: ()) {
let _ = (self.callback)(view_item); let _ = (self.callback)(view_item);
} }
} }
impl EachViewItem for ast::Crate { impl EachViewItem for ast::Crate {
fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool { fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool {
let mut visit = EachViewItemData { let mut visit = EachViewItemData {
callback: f, callback: f,
}; };
@ -653,17 +653,16 @@ impl EachViewItem for ast::Crate {
} }
} }
pub fn view_path_id(p: &view_path) -> NodeId { pub fn view_path_id(p: &ViewPath) -> NodeId {
match p.node { match p.node {
view_path_simple(_, _, id) | ViewPathSimple(_, _, id) | ViewPathGlob(_, id)
view_path_glob(_, id) | | ViewPathList(_, _, id) => id
view_path_list(_, _, id) => id
} }
} }
/// Returns true if the given struct def is tuple-like; i.e. that its fields /// Returns true if the given struct def is tuple-like; i.e. that its fields
/// are unnamed. /// are unnamed.
pub fn struct_def_is_tuple_like(struct_def: &ast::struct_def) -> bool { pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool {
struct_def.ctor_id.is_some() struct_def.ctor_id.is_some()
} }

View file

@ -66,7 +66,7 @@ impl AttrMetaMethods for MetaItem {
match self.node { match self.node {
MetaNameValue(_, ref v) => { MetaNameValue(_, ref v) => {
match v.node { match v.node {
ast::lit_str(s, _) => Some(s), ast::LitStr(s, _) => Some(s),
_ => None, _ => None,
} }
}, },
@ -126,11 +126,11 @@ impl AttributeMethods for Attribute {
/* Constructors */ /* Constructors */
pub fn mk_name_value_item_str(name: @str, value: @str) -> @MetaItem { pub fn mk_name_value_item_str(name: @str, value: @str) -> @MetaItem {
let value_lit = dummy_spanned(ast::lit_str(value, ast::CookedStr)); let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr));
mk_name_value_item(name, value_lit) mk_name_value_item(name, value_lit)
} }
pub fn mk_name_value_item(name: @str, value: ast::lit) -> @MetaItem { pub fn mk_name_value_item(name: @str, value: ast::Lit) -> @MetaItem {
@dummy_spanned(MetaNameValue(name, value)) @dummy_spanned(MetaNameValue(name, value))
} }
@ -152,7 +152,7 @@ pub fn mk_attr(item: @MetaItem) -> Attribute {
pub fn mk_sugared_doc_attr(text: @str, lo: BytePos, hi: BytePos) -> Attribute { pub fn mk_sugared_doc_attr(text: @str, lo: BytePos, hi: BytePos) -> Attribute {
let style = doc_comment_style(text); let style = doc_comment_style(text);
let lit = spanned(lo, hi, ast::lit_str(text, ast::CookedStr)); let lit = spanned(lo, hi, ast::LitStr(text, ast::CookedStr));
let attr = Attribute_ { let attr = Attribute_ {
style: style, style: style,
value: @spanned(lo, hi, MetaNameValue(@"doc", lit)), value: @spanned(lo, hi, MetaNameValue(@"doc", lit)),
@ -423,16 +423,16 @@ pub fn find_repr_attr(diagnostic: @SpanHandler, attr: @ast::MetaItem, acc: ReprA
fn int_type_of_word(s: &str) -> Option<IntType> { fn int_type_of_word(s: &str) -> Option<IntType> {
match s { match s {
"i8" => Some(SignedInt(ast::ty_i8)), "i8" => Some(SignedInt(ast::TyI8)),
"u8" => Some(UnsignedInt(ast::ty_u8)), "u8" => Some(UnsignedInt(ast::TyU8)),
"i16" => Some(SignedInt(ast::ty_i16)), "i16" => Some(SignedInt(ast::TyI16)),
"u16" => Some(UnsignedInt(ast::ty_u16)), "u16" => Some(UnsignedInt(ast::TyU16)),
"i32" => Some(SignedInt(ast::ty_i32)), "i32" => Some(SignedInt(ast::TyI32)),
"u32" => Some(UnsignedInt(ast::ty_u32)), "u32" => Some(UnsignedInt(ast::TyU32)),
"i64" => Some(SignedInt(ast::ty_i64)), "i64" => Some(SignedInt(ast::TyI64)),
"u64" => Some(UnsignedInt(ast::ty_u64)), "u64" => Some(UnsignedInt(ast::TyU64)),
"int" => Some(SignedInt(ast::ty_i)), "int" => Some(SignedInt(ast::TyI)),
"uint" => Some(UnsignedInt(ast::ty_u)), "uint" => Some(UnsignedInt(ast::TyU)),
_ => None _ => None
} }
} }
@ -456,8 +456,8 @@ impl ReprAttr {
#[deriving(Eq)] #[deriving(Eq)]
pub enum IntType { pub enum IntType {
SignedInt(ast::int_ty), SignedInt(ast::IntTy),
UnsignedInt(ast::uint_ty) UnsignedInt(ast::UintTy)
} }
impl IntType { impl IntType {
@ -470,10 +470,10 @@ impl IntType {
} }
fn is_ffi_safe(self) -> bool { fn is_ffi_safe(self) -> bool {
match self { match self {
SignedInt(ast::ty_i8) | UnsignedInt(ast::ty_u8) | SignedInt(ast::TyI8) | UnsignedInt(ast::TyU8) |
SignedInt(ast::ty_i16) | UnsignedInt(ast::ty_u16) | SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) |
SignedInt(ast::ty_i32) | UnsignedInt(ast::ty_u32) | SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) |
SignedInt(ast::ty_i64) | UnsignedInt(ast::ty_u64) => true, SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true,
_ => false _ => false
} }
} }

View file

@ -24,7 +24,7 @@ pub trait Emitter {
fn emit(&self, fn emit(&self,
cmsp: Option<(&codemap::CodeMap, Span)>, cmsp: Option<(&codemap::CodeMap, Span)>,
msg: &str, msg: &str,
lvl: level); lvl: Level);
} }
// a span-handler is like a handler but also // a span-handler is like a handler but also
@ -37,18 +37,18 @@ pub struct SpanHandler {
impl SpanHandler { impl SpanHandler {
pub fn span_fatal(@self, sp: Span, msg: &str) -> ! { pub fn span_fatal(@self, sp: Span, msg: &str) -> ! {
self.handler.emit(Some((&*self.cm, sp)), msg, fatal); self.handler.emit(Some((&*self.cm, sp)), msg, Fatal);
fail!(); fail!();
} }
pub fn span_err(@self, sp: Span, msg: &str) { pub fn span_err(@self, sp: Span, msg: &str) {
self.handler.emit(Some((&*self.cm, sp)), msg, error); self.handler.emit(Some((&*self.cm, sp)), msg, Error);
self.handler.bump_err_count(); self.handler.bump_err_count();
} }
pub fn span_warn(@self, sp: Span, msg: &str) { pub fn span_warn(@self, sp: Span, msg: &str) {
self.handler.emit(Some((&*self.cm, sp)), msg, warning); self.handler.emit(Some((&*self.cm, sp)), msg, Warning);
} }
pub fn span_note(@self, sp: Span, msg: &str) { pub fn span_note(@self, sp: Span, msg: &str) {
self.handler.emit(Some((&*self.cm, sp)), msg, note); self.handler.emit(Some((&*self.cm, sp)), msg, Note);
} }
pub fn span_bug(@self, sp: Span, msg: &str) -> ! { pub fn span_bug(@self, sp: Span, msg: &str) -> ! {
self.span_fatal(sp, ice_msg(msg)); self.span_fatal(sp, ice_msg(msg));
@ -71,11 +71,11 @@ pub struct Handler {
impl Handler { impl Handler {
pub fn fatal(@self, msg: &str) -> ! { pub fn fatal(@self, msg: &str) -> ! {
self.emit.emit(None, msg, fatal); self.emit.emit(None, msg, Fatal);
fail!(); fail!();
} }
pub fn err(@self, msg: &str) { pub fn err(@self, msg: &str) {
self.emit.emit(None, msg, error); self.emit.emit(None, msg, Error);
self.bump_err_count(); self.bump_err_count();
} }
pub fn bump_err_count(@self) { pub fn bump_err_count(@self) {
@ -100,10 +100,10 @@ impl Handler {
self.fatal(s); self.fatal(s);
} }
pub fn warn(@self, msg: &str) { pub fn warn(@self, msg: &str) {
self.emit.emit(None, msg, warning); self.emit.emit(None, msg, Warning);
} }
pub fn note(@self, msg: &str) { pub fn note(@self, msg: &str) {
self.emit.emit(None, msg, note); self.emit.emit(None, msg, Note);
} }
pub fn bug(@self, msg: &str) -> ! { pub fn bug(@self, msg: &str) -> ! {
self.fatal(ice_msg(msg)); self.fatal(ice_msg(msg));
@ -114,7 +114,7 @@ impl Handler {
pub fn emit(@self, pub fn emit(@self,
cmsp: Option<(&codemap::CodeMap, Span)>, cmsp: Option<(&codemap::CodeMap, Span)>,
msg: &str, msg: &str,
lvl: level) { lvl: Level) {
self.emit.emit(cmsp, msg, lvl); self.emit.emit(cmsp, msg, lvl);
} }
} }
@ -145,28 +145,30 @@ pub fn mk_handler(emitter: Option<@Emitter>) -> @Handler {
} }
#[deriving(Eq)] #[deriving(Eq)]
pub enum level { pub enum Level {
fatal, Fatal,
error, Error,
warning, Warning,
note, Note,
} }
fn diagnosticstr(lvl: level) -> ~str { impl ToStr for Level {
match lvl { fn to_str(&self) -> ~str {
fatal => ~"error", match *self {
error => ~"error", Fatal | Error => ~"error",
warning => ~"warning", Warning => ~"warning",
note => ~"note" Note => ~"note"
}
} }
} }
fn diagnosticcolor(lvl: level) -> term::color::Color { impl Level {
match lvl { fn color(self) -> term::color::Color {
fatal => term::color::BRIGHT_RED, match self {
error => term::color::BRIGHT_RED, Fatal | Error => term::color::BRIGHT_RED,
warning => term::color::BRIGHT_YELLOW, Warning => term::color::BRIGHT_YELLOW,
note => term::color::BRIGHT_GREEN Note => term::color::BRIGHT_GREEN
}
} }
} }
@ -212,15 +214,15 @@ fn print_maybe_styled(msg: &str, color: term::attr::Attr) {
} }
} }
fn print_diagnostic(topic: &str, lvl: level, msg: &str) { fn print_diagnostic(topic: &str, lvl: Level, msg: &str) {
let mut stderr = io::stderr(); let mut stderr = io::stderr();
if !topic.is_empty() { if !topic.is_empty() {
write!(&mut stderr as &mut io::Writer, "{} ", topic); write!(&mut stderr as &mut io::Writer, "{} ", topic);
} }
print_maybe_styled(format!("{}: ", diagnosticstr(lvl)), print_maybe_styled(format!("{}: ", lvl.to_str()),
term::attr::ForegroundColor(diagnosticcolor(lvl))); term::attr::ForegroundColor(lvl.color()));
print_maybe_styled(format!("{}\n", msg), term::attr::Bold); print_maybe_styled(format!("{}\n", msg), term::attr::Bold);
} }
@ -230,7 +232,7 @@ impl Emitter for DefaultEmitter {
fn emit(&self, fn emit(&self,
cmsp: Option<(&codemap::CodeMap, Span)>, cmsp: Option<(&codemap::CodeMap, Span)>,
msg: &str, msg: &str,
lvl: level) { lvl: Level) {
match cmsp { match cmsp {
Some((cm, sp)) => { Some((cm, sp)) => {
let sp = cm.adjust_span(sp); let sp = cm.adjust_span(sp);
@ -247,7 +249,7 @@ impl Emitter for DefaultEmitter {
fn highlight_lines(cm: &codemap::CodeMap, fn highlight_lines(cm: &codemap::CodeMap,
sp: Span, sp: Span,
lvl: level, lvl: Level,
lines: &codemap::FileLines) { lines: &codemap::FileLines) {
let fm = lines.file; let fm = lines.file;
let mut err = io::stderr(); let mut err = io::stderr();
@ -308,7 +310,7 @@ fn highlight_lines(cm: &codemap::CodeMap,
let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u; let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u;
num_squigglies.times(|| s.push_char('~')); num_squigglies.times(|| s.push_char('~'));
} }
print_maybe_styled(s + "\n", term::attr::ForegroundColor(diagnosticcolor(lvl))); print_maybe_styled(s + "\n", term::attr::ForegroundColor(lvl.color()));
} }
} }
@ -319,10 +321,10 @@ fn print_macro_backtrace(cm: &codemap::CodeMap, sp: Span) {
codemap::MacroAttribute => ("#[", "]"), codemap::MacroAttribute => ("#[", "]"),
codemap::MacroBang => ("", "!") codemap::MacroBang => ("", "!")
}; };
print_diagnostic(ss, note, print_diagnostic(ss, Note,
format!("in expansion of {}{}{}", pre, ei.callee.name, post)); format!("in expansion of {}{}{}", pre, ei.callee.name, post));
let ss = cm.span_to_str(ei.call_site); let ss = cm.span_to_str(ei.call_site);
print_diagnostic(ss, note, "expansion site"); print_diagnostic(ss, Note, "expansion site");
print_macro_backtrace(cm, ei.call_site); print_macro_backtrace(cm, ei.call_site);
} }
} }

View file

@ -37,7 +37,7 @@ fn next_state(s: State) -> Option<State> {
} }
} }
pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult { -> base::MacResult {
let mut p = parse::new_parser_from_tts(cx.parse_sess(), let mut p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(), cx.cfg(),
@ -50,7 +50,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
let mut cons = ~""; let mut cons = ~"";
let mut volatile = false; let mut volatile = false;
let mut alignstack = false; let mut alignstack = false;
let mut dialect = ast::asm_att; let mut dialect = ast::AsmAtt;
let mut state = Asm; let mut state = Asm;
@ -139,7 +139,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
} else if "alignstack" == option { } else if "alignstack" == option {
alignstack = true; alignstack = true;
} else if "intel" == option { } else if "intel" == option {
dialect = ast::asm_intel; dialect = ast::AsmIntel;
} }
if p.token == token::COMMA { if p.token == token::COMMA {
@ -187,7 +187,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
MRExpr(@ast::Expr { MRExpr(@ast::Expr {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ExprInlineAsm(ast::inline_asm { node: ast::ExprInlineAsm(ast::InlineAsm {
asm: asm, asm: asm,
asm_str_style: asm_str_style.unwrap(), asm_str_style: asm_str_style.unwrap(),
clobbers: cons.to_managed(), clobbers: cons.to_managed(),

View file

@ -25,9 +25,9 @@ use std::hashmap::HashMap;
// //
// MacResult, NormalTT, IdentTT // MacResult, NormalTT, IdentTT
// //
// also note that ast::mac used to have a bunch of extraneous cases and // also note that ast::Mac used to have a bunch of extraneous cases and
// is now probably a redundant AST node, can be merged with // is now probably a redundant AST node, can be merged with
// ast::mac_invoc_tt. // ast::MacInvocTT.
pub struct MacroDef { pub struct MacroDef {
name: @str, name: @str,
@ -35,7 +35,7 @@ pub struct MacroDef {
} }
pub type ItemDecorator = pub type ItemDecorator =
fn(&ExtCtxt, Span, @ast::MetaItem, ~[@ast::item]) -> ~[@ast::item]; fn(&ExtCtxt, Span, @ast::MetaItem, ~[@ast::Item]) -> ~[@ast::Item];
pub struct SyntaxExpanderTT { pub struct SyntaxExpanderTT {
expander: SyntaxExpanderTTExpander, expander: SyntaxExpanderTTExpander,
@ -46,13 +46,13 @@ pub trait SyntaxExpanderTTTrait {
fn expand(&self, fn expand(&self,
ecx: &mut ExtCtxt, ecx: &mut ExtCtxt,
span: Span, span: Span,
token_tree: &[ast::token_tree], token_tree: &[ast::TokenTree],
context: ast::SyntaxContext) context: ast::SyntaxContext)
-> MacResult; -> MacResult;
} }
pub type SyntaxExpanderTTFunNoCtxt = pub type SyntaxExpanderTTFunNoCtxt =
fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::token_tree]) fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::TokenTree])
-> MacResult; -> MacResult;
enum SyntaxExpanderTTExpander { enum SyntaxExpanderTTExpander {
@ -63,7 +63,7 @@ impl SyntaxExpanderTTTrait for SyntaxExpanderTT {
fn expand(&self, fn expand(&self,
ecx: &mut ExtCtxt, ecx: &mut ExtCtxt,
span: Span, span: Span,
token_tree: &[ast::token_tree], token_tree: &[ast::TokenTree],
_: ast::SyntaxContext) _: ast::SyntaxContext)
-> MacResult { -> MacResult {
match self.expander { match self.expander {
@ -89,7 +89,7 @@ pub trait SyntaxExpanderTTItemTrait {
cx: &mut ExtCtxt, cx: &mut ExtCtxt,
sp: Span, sp: Span,
ident: ast::Ident, ident: ast::Ident,
token_tree: ~[ast::token_tree], token_tree: ~[ast::TokenTree],
context: ast::SyntaxContext) context: ast::SyntaxContext)
-> MacResult; -> MacResult;
} }
@ -99,7 +99,7 @@ impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem {
cx: &mut ExtCtxt, cx: &mut ExtCtxt,
sp: Span, sp: Span,
ident: ast::Ident, ident: ast::Ident,
token_tree: ~[ast::token_tree], token_tree: ~[ast::TokenTree],
context: ast::SyntaxContext) context: ast::SyntaxContext)
-> MacResult { -> MacResult {
match self.expander { match self.expander {
@ -114,21 +114,21 @@ impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem {
} }
pub type SyntaxExpanderTTItemFun = pub type SyntaxExpanderTTItemFun =
fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree], ast::SyntaxContext) fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::TokenTree], ast::SyntaxContext)
-> MacResult; -> MacResult;
pub type SyntaxExpanderTTItemFunNoCtxt = pub type SyntaxExpanderTTItemFunNoCtxt =
fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree]) -> MacResult; fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::TokenTree]) -> MacResult;
pub trait AnyMacro { pub trait AnyMacro {
fn make_expr(&self) -> @ast::Expr; fn make_expr(&self) -> @ast::Expr;
fn make_items(&self) -> SmallVector<@ast::item>; fn make_items(&self) -> SmallVector<@ast::Item>;
fn make_stmt(&self) -> @ast::Stmt; fn make_stmt(&self) -> @ast::Stmt;
} }
pub enum MacResult { pub enum MacResult {
MRExpr(@ast::Expr), MRExpr(@ast::Expr),
MRItem(@ast::item), MRItem(@ast::Item),
MRAny(@AnyMacro), MRAny(@AnyMacro),
MRDef(MacroDef), MRDef(MacroDef),
} }
@ -393,15 +393,15 @@ impl ExtCtxt {
pub fn expr_to_str(cx: &ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast::StrStyle) { pub fn expr_to_str(cx: &ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast::StrStyle) {
match expr.node { match expr.node {
ast::ExprLit(l) => match l.node { ast::ExprLit(l) => match l.node {
ast::lit_str(s, style) => (s, style), ast::LitStr(s, style) => (s, style),
_ => cx.span_fatal(l.span, err_msg) _ => cx.span_fatal(l.span, err_msg)
}, },
_ => cx.span_fatal(expr.span, err_msg) _ => cx.span_fatal(expr.span, err_msg)
} }
} }
pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree], pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree],
name: &str) { name: &str) {
if tts.len() != 0 { if tts.len() != 0 {
cx.span_fatal(sp, format!("{} takes no arguments", name)); cx.span_fatal(sp, format!("{} takes no arguments", name));
@ -410,7 +410,7 @@ pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree],
pub fn get_single_str_from_tts(cx: &ExtCtxt, pub fn get_single_str_from_tts(cx: &ExtCtxt,
sp: Span, sp: Span,
tts: &[ast::token_tree], tts: &[ast::TokenTree],
name: &str) name: &str)
-> @str { -> @str {
if tts.len() != 1 { if tts.len() != 1 {
@ -418,15 +418,15 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt,
} }
match tts[0] { match tts[0] {
ast::tt_tok(_, token::LIT_STR(ident)) ast::TTTok(_, token::LIT_STR(ident))
| ast::tt_tok(_, token::LIT_STR_RAW(ident, _)) => cx.str_of(ident), | ast::TTTok(_, token::LIT_STR_RAW(ident, _)) => cx.str_of(ident),
_ => cx.span_fatal(sp, format!("{} requires a string.", name)), _ => cx.span_fatal(sp, format!("{} requires a string.", name)),
} }
} }
pub fn get_exprs_from_tts(cx: &ExtCtxt, pub fn get_exprs_from_tts(cx: &ExtCtxt,
sp: Span, sp: Span,
tts: &[ast::token_tree]) -> ~[@ast::Expr] { tts: &[ast::TokenTree]) -> ~[@ast::Expr] {
let mut p = parse::new_parser_from_tts(cx.parse_sess(), let mut p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(), cx.cfg(),
tts.to_owned()); tts.to_owned());

View file

@ -15,7 +15,7 @@ use ast_util;
use codemap::{Span, respan, DUMMY_SP}; use codemap::{Span, respan, DUMMY_SP};
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::quote::rt::*; use ext::quote::rt::*;
use fold::ast_fold; use fold::Folder;
use opt_vec; use opt_vec;
use opt_vec::OptVec; use opt_vec::OptVec;
@ -43,9 +43,9 @@ pub trait AstBuilder {
-> ast::Path; -> ast::Path;
// types // types
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::mt; fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;
fn ty(&self, span: Span, ty: ast::ty_) -> P<ast::Ty>; fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>;
fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> P<ast::Ty>; fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> P<ast::Ty>;
fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
@ -67,7 +67,7 @@ pub trait AstBuilder {
fn typaram(&self, id: ast::Ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam; fn typaram(&self, id: ast::Ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam;
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef;
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound; fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime; fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime;
@ -86,7 +86,7 @@ pub trait AstBuilder {
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block>; fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block>;
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block>; fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block>;
fn block_all(&self, span: Span, fn block_all(&self, span: Span,
view_items: ~[ast::view_item], view_items: ~[ast::ViewItem],
stmts: ~[@ast::Stmt], stmts: ~[@ast::Stmt],
expr: Option<@ast::Expr>) -> P<ast::Block>; expr: Option<@ast::Expr>) -> P<ast::Block>;
@ -119,7 +119,7 @@ pub trait AstBuilder {
fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr; fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr;
fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: ~[ast::Field]) -> @ast::Expr; fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: ~[ast::Field]) -> @ast::Expr;
fn expr_lit(&self, sp: Span, lit: ast::lit_) -> @ast::Expr; fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> @ast::Expr;
fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr; fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr;
fn expr_int(&self, sp: Span, i: int) -> @ast::Expr; fn expr_int(&self, sp: Span, i: int) -> @ast::Expr;
@ -160,7 +160,7 @@ pub trait AstBuilder {
cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr; cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr;
fn lambda_fn_decl(&self, span: Span, fn lambda_fn_decl(&self, span: Span,
fn_decl: P<ast::fn_decl>, blk: P<ast::Block>) -> @ast::Expr; fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> @ast::Expr;
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr; fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr;
fn lambda0(&self, span: Span, blk: P<ast::Block>) -> @ast::Expr; fn lambda0(&self, span: Span, blk: P<ast::Block>) -> @ast::Expr;
@ -176,64 +176,64 @@ pub trait AstBuilder {
// items // items
fn item(&self, span: Span, fn item(&self, span: Span,
name: Ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item; name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item;
fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::arg; fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::Arg;
// XXX unused self // XXX unused self
fn fn_decl(&self, inputs: ~[ast::arg], output: P<ast::Ty>) -> P<ast::fn_decl>; fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl>;
fn item_fn_poly(&self, fn item_fn_poly(&self,
span: Span, span: Span,
name: Ident, name: Ident,
inputs: ~[ast::arg], inputs: ~[ast::Arg],
output: P<ast::Ty>, output: P<ast::Ty>,
generics: Generics, generics: Generics,
body: P<ast::Block>) -> @ast::item; body: P<ast::Block>) -> @ast::Item;
fn item_fn(&self, fn item_fn(&self,
span: Span, span: Span,
name: Ident, name: Ident,
inputs: ~[ast::arg], inputs: ~[ast::Arg],
output: P<ast::Ty>, output: P<ast::Ty>,
body: P<ast::Block>) -> @ast::item; body: P<ast::Block>) -> @ast::Item;
fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::variant; fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::Variant;
fn item_enum_poly(&self, fn item_enum_poly(&self,
span: Span, span: Span,
name: Ident, name: Ident,
enum_definition: ast::enum_def, enum_definition: ast::EnumDef,
generics: Generics) -> @ast::item; generics: Generics) -> @ast::Item;
fn item_enum(&self, span: Span, name: Ident, enum_def: ast::enum_def) -> @ast::item; fn item_enum(&self, span: Span, name: Ident, enum_def: ast::EnumDef) -> @ast::Item;
fn item_struct_poly(&self, fn item_struct_poly(&self,
span: Span, span: Span,
name: Ident, name: Ident,
struct_def: ast::struct_def, struct_def: ast::StructDef,
generics: Generics) -> @ast::item; generics: Generics) -> @ast::Item;
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::struct_def) -> @ast::item; fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> @ast::Item;
fn item_mod(&self, span: Span, fn item_mod(&self, span: Span,
name: Ident, attrs: ~[ast::Attribute], name: Ident, attrs: ~[ast::Attribute],
vi: ~[ast::view_item], items: ~[@ast::item]) -> @ast::item; vi: ~[ast::ViewItem], items: ~[@ast::Item]) -> @ast::Item;
fn item_ty_poly(&self, fn item_ty_poly(&self,
span: Span, span: Span,
name: Ident, name: Ident,
ty: P<ast::Ty>, ty: P<ast::Ty>,
generics: Generics) -> @ast::item; generics: Generics) -> @ast::Item;
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::item; fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item;
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute; fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute;
fn meta_word(&self, sp: Span, w: @str) -> @ast::MetaItem; fn meta_word(&self, sp: Span, w: @str) -> @ast::MetaItem;
fn meta_list(&self, sp: Span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem; fn meta_list(&self, sp: Span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem;
fn meta_name_value(&self, sp: Span, name: @str, value: ast::lit_) -> @ast::MetaItem; fn meta_name_value(&self, sp: Span, name: @str, value: ast::Lit_) -> @ast::MetaItem;
fn view_use(&self, sp: Span, fn view_use(&self, sp: Span,
vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item; vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem;
fn view_use_list(&self, sp: Span, vis: ast::visibility, fn view_use_list(&self, sp: Span, vis: ast::Visibility,
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item; path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem;
fn view_use_glob(&self, sp: Span, fn view_use_glob(&self, sp: Span,
vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item; vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem;
} }
impl AstBuilder for ExtCtxt { impl AstBuilder for ExtCtxt {
@ -274,14 +274,14 @@ impl AstBuilder for ExtCtxt {
} }
} }
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::mt { fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
ast::mt { ast::MutTy {
ty: ty, ty: ty,
mutbl: mutbl mutbl: mutbl
} }
} }
fn ty(&self, span: Span, ty: ast::ty_) -> P<ast::Ty> { fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty> {
P(ast::Ty { P(ast::Ty {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: span, span: span,
@ -292,7 +292,7 @@ impl AstBuilder for ExtCtxt {
fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>) fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>)
-> P<ast::Ty> { -> P<ast::Ty> {
self.ty(path.span, self.ty(path.span,
ast::ty_path(path, bounds, ast::DUMMY_NODE_ID)) ast::TyPath(path, bounds, ast::DUMMY_NODE_ID))
} }
// Might need to take bounds as an argument in the future, if you ever want // Might need to take bounds as an argument in the future, if you ever want
@ -309,15 +309,15 @@ impl AstBuilder for ExtCtxt {
mutbl: ast::Mutability) mutbl: ast::Mutability)
-> P<ast::Ty> { -> P<ast::Ty> {
self.ty(span, self.ty(span,
ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl))) ast::TyRptr(lifetime, self.ty_mt(ty, mutbl)))
} }
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> { fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
self.ty(span, ast::ty_uniq(ty)) self.ty(span, ast::TyUniq(ty))
} }
fn ty_box(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> { fn ty_box(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
self.ty(span, ast::ty_box(ty)) self.ty(span, ast::TyBox(ty))
} }
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> { fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
@ -336,19 +336,19 @@ impl AstBuilder for ExtCtxt {
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField { fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField {
ast::TypeField { ast::TypeField {
ident: name, ident: name,
mt: ast::mt { ty: ty, mutbl: ast::MutImmutable }, mt: ast::MutTy { ty: ty, mutbl: ast::MutImmutable },
span: span, span: span,
} }
} }
fn ty_infer(&self, span: Span) -> P<ast::Ty> { fn ty_infer(&self, span: Span) -> P<ast::Ty> {
self.ty(span, ast::ty_infer) self.ty(span, ast::TyInfer)
} }
fn ty_nil(&self) -> P<ast::Ty> { fn ty_nil(&self) -> P<ast::Ty> {
P(ast::Ty { P(ast::Ty {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ty_nil, node: ast::TyNil,
span: DUMMY_SP, span: DUMMY_SP,
}) })
} }
@ -381,8 +381,8 @@ impl AstBuilder for ExtCtxt {
} }
} }
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref { fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
ast::trait_ref { ast::TraitRef {
path: path, path: path,
ref_id: ast::DUMMY_NODE_ID ref_id: ast::DUMMY_NODE_ID
} }
@ -449,7 +449,7 @@ impl AstBuilder for ExtCtxt {
} }
fn block_all(&self, fn block_all(&self,
span: Span, span: Span,
view_items: ~[ast::view_item], view_items: ~[ast::ViewItem],
stmts: ~[@ast::Stmt], stmts: ~[@ast::Stmt],
expr: Option<@ast::Expr>) -> P<ast::Block> { expr: Option<@ast::Expr>) -> P<ast::Block> {
P(ast::Block { P(ast::Block {
@ -541,20 +541,20 @@ impl AstBuilder for ExtCtxt {
self.expr_struct(span, self.path_ident(span, id), fields) self.expr_struct(span, self.path_ident(span, id), fields)
} }
fn expr_lit(&self, sp: Span, lit: ast::lit_) -> @ast::Expr { fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> @ast::Expr {
self.expr(sp, ast::ExprLit(@respan(sp, lit))) self.expr(sp, ast::ExprLit(@respan(sp, lit)))
} }
fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr { fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr {
self.expr_lit(span, ast::lit_uint(i as u64, ast::ty_u)) self.expr_lit(span, ast::LitUint(i as u64, ast::TyU))
} }
fn expr_int(&self, sp: Span, i: int) -> @ast::Expr { fn expr_int(&self, sp: Span, i: int) -> @ast::Expr {
self.expr_lit(sp, ast::lit_int(i as i64, ast::ty_i)) self.expr_lit(sp, ast::LitInt(i as i64, ast::TyI))
} }
fn expr_u8(&self, sp: Span, u: u8) -> @ast::Expr { fn expr_u8(&self, sp: Span, u: u8) -> @ast::Expr {
self.expr_lit(sp, ast::lit_uint(u as u64, ast::ty_u8)) self.expr_lit(sp, ast::LitUint(u as u64, ast::TyU8))
} }
fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr { fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr {
self.expr_lit(sp, ast::lit_bool(value)) self.expr_lit(sp, ast::LitBool(value))
} }
fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr { fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr {
@ -570,7 +570,7 @@ impl AstBuilder for ExtCtxt {
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreSlice) self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreSlice)
} }
fn expr_str(&self, sp: Span, s: @str) -> @ast::Expr { fn expr_str(&self, sp: Span, s: @str) -> @ast::Expr {
self.expr_lit(sp, ast::lit_str(s, ast::CookedStr)) self.expr_lit(sp, ast::LitStr(s, ast::CookedStr))
} }
fn expr_str_uniq(&self, sp: Span, s: @str) -> @ast::Expr { fn expr_str_uniq(&self, sp: Span, s: @str) -> @ast::Expr {
self.expr_vstore(sp, self.expr_str(sp, s), ast::ExprVstoreUniq) self.expr_vstore(sp, self.expr_str(sp, s), ast::ExprVstoreUniq)
@ -675,7 +675,7 @@ impl AstBuilder for ExtCtxt {
} }
fn lambda_fn_decl(&self, span: Span, fn lambda_fn_decl(&self, span: Span,
fn_decl: P<ast::fn_decl>, blk: P<ast::Block>) -> @ast::Expr { fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> @ast::Expr {
self.expr(span, ast::ExprFnBlock(fn_decl, blk)) self.expr(span, ast::ExprFnBlock(fn_decl, blk))
} }
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr { fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr {
@ -715,9 +715,9 @@ impl AstBuilder for ExtCtxt {
self.lambda1(span, self.block(span, stmts, None), ident) self.lambda1(span, self.block(span, stmts, None), ident)
} }
fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::arg { fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg {
let arg_pat = self.pat_ident(span, ident); let arg_pat = self.pat_ident(span, ident);
ast::arg { ast::Arg {
ty: ty, ty: ty,
pat: arg_pat, pat: arg_pat,
id: ast::DUMMY_NODE_ID id: ast::DUMMY_NODE_ID
@ -725,51 +725,51 @@ impl AstBuilder for ExtCtxt {
} }
// XXX unused self // XXX unused self
fn fn_decl(&self, inputs: ~[ast::arg], output: P<ast::Ty>) -> P<ast::fn_decl> { fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl> {
P(ast::fn_decl { P(ast::FnDecl {
inputs: inputs, inputs: inputs,
output: output, output: output,
cf: ast::return_val, cf: ast::Return,
variadic: false variadic: false
}) })
} }
fn item(&self, span: Span, fn item(&self, span: Span,
name: Ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item { name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item {
// XXX: Would be nice if our generated code didn't violate // XXX: Would be nice if our generated code didn't violate
// Rust coding conventions // Rust coding conventions
@ast::item { ident: name, @ast::Item { ident: name,
attrs: attrs, attrs: attrs,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: node, node: node,
vis: ast::inherited, vis: ast::Inherited,
span: span } span: span }
} }
fn item_fn_poly(&self, fn item_fn_poly(&self,
span: Span, span: Span,
name: Ident, name: Ident,
inputs: ~[ast::arg], inputs: ~[ast::Arg],
output: P<ast::Ty>, output: P<ast::Ty>,
generics: Generics, generics: Generics,
body: P<ast::Block>) -> @ast::item { body: P<ast::Block>) -> @ast::Item {
self.item(span, self.item(span,
name, name,
~[], ~[],
ast::item_fn(self.fn_decl(inputs, output), ast::ItemFn(self.fn_decl(inputs, output),
ast::impure_fn, ast::ImpureFn,
AbiSet::Rust(), AbiSet::Rust(),
generics, generics,
body)) body))
} }
fn item_fn(&self, fn item_fn(&self,
span: Span, span: Span,
name: Ident, name: Ident,
inputs: ~[ast::arg], inputs: ~[ast::Arg],
output: P<ast::Ty>, output: P<ast::Ty>,
body: P<ast::Block> body: P<ast::Block>
) -> @ast::item { ) -> @ast::Item {
self.item_fn_poly( self.item_fn_poly(
span, span,
name, name,
@ -779,40 +779,36 @@ impl AstBuilder for ExtCtxt {
body) body)
} }
fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::variant { fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::Variant {
let args = tys.move_iter().map(|ty| { let args = tys.move_iter().map(|ty| {
ast::variant_arg { ty: ty, id: ast::DUMMY_NODE_ID } ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID }
}).collect(); }).collect();
respan(span, respan(span,
ast::variant_ { ast::Variant_ {
name: name, name: name,
attrs: ~[], attrs: ~[],
kind: ast::tuple_variant_kind(args), kind: ast::TupleVariantKind(args),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
disr_expr: None, disr_expr: None,
vis: ast::public vis: ast::Public
}) })
} }
fn item_enum_poly(&self, span: Span, name: Ident, fn item_enum_poly(&self, span: Span, name: Ident,
enum_definition: ast::enum_def, enum_definition: ast::EnumDef,
generics: Generics) -> @ast::item { generics: Generics) -> @ast::Item {
self.item(span, name, ~[], ast::item_enum(enum_definition, generics)) self.item(span, name, ~[], ast::ItemEnum(enum_definition, generics))
} }
fn item_enum(&self, span: Span, name: Ident, fn item_enum(&self, span: Span, name: Ident,
enum_definition: ast::enum_def) -> @ast::item { enum_definition: ast::EnumDef) -> @ast::Item {
self.item_enum_poly(span, name, enum_definition, self.item_enum_poly(span, name, enum_definition,
ast_util::empty_generics()) ast_util::empty_generics())
} }
fn item_struct( fn item_struct(&self, span: Span, name: Ident,
&self, struct_def: ast::StructDef) -> @ast::Item {
span: Span,
name: Ident,
struct_def: ast::struct_def
) -> @ast::item {
self.item_struct_poly( self.item_struct_poly(
span, span,
name, name,
@ -821,25 +817,20 @@ impl AstBuilder for ExtCtxt {
) )
} }
fn item_struct_poly( fn item_struct_poly(&self, span: Span, name: Ident,
&self, struct_def: ast::StructDef, generics: Generics) -> @ast::Item {
span: Span, self.item(span, name, ~[], ast::ItemStruct(@struct_def, generics))
name: Ident,
struct_def: ast::struct_def,
generics: Generics
) -> @ast::item {
self.item(span, name, ~[], ast::item_struct(@struct_def, generics))
} }
fn item_mod(&self, span: Span, name: Ident, fn item_mod(&self, span: Span, name: Ident,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
vi: ~[ast::view_item], vi: ~[ast::ViewItem],
items: ~[@ast::item]) -> @ast::item { items: ~[@ast::Item]) -> @ast::Item {
self.item( self.item(
span, span,
name, name,
attrs, attrs,
ast::item_mod(ast::_mod { ast::ItemMod(ast::Mod {
view_items: vi, view_items: vi,
items: items, items: items,
}) })
@ -847,11 +838,11 @@ impl AstBuilder for ExtCtxt {
} }
fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>, fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
generics: Generics) -> @ast::item { generics: Generics) -> @ast::Item {
self.item(span, name, ~[], ast::item_ty(ty, generics)) self.item(span, name, ~[], ast::ItemTy(ty, generics))
} }
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::item { fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item {
self.item_ty_poly(span, name, ty, ast_util::empty_generics()) self.item_ty_poly(span, name, ty, ast_util::empty_generics())
} }
@ -869,38 +860,38 @@ impl AstBuilder for ExtCtxt {
fn meta_list(&self, sp: Span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem { fn meta_list(&self, sp: Span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem {
@respan(sp, ast::MetaList(name, mis)) @respan(sp, ast::MetaList(name, mis))
} }
fn meta_name_value(&self, sp: Span, name: @str, value: ast::lit_) -> @ast::MetaItem { fn meta_name_value(&self, sp: Span, name: @str, value: ast::Lit_) -> @ast::MetaItem {
@respan(sp, ast::MetaNameValue(name, respan(sp, value))) @respan(sp, ast::MetaNameValue(name, respan(sp, value)))
} }
fn view_use(&self, sp: Span, fn view_use(&self, sp: Span,
vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item { vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem {
ast::view_item { ast::ViewItem {
node: ast::view_item_use(vp), node: ast::ViewItemUse(vp),
attrs: ~[], attrs: ~[],
vis: vis, vis: vis,
span: sp span: sp
} }
} }
fn view_use_list(&self, sp: Span, vis: ast::visibility, fn view_use_list(&self, sp: Span, vis: ast::Visibility,
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item { path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem {
let imports = imports.map(|id| { let imports = imports.map(|id| {
respan(sp, ast::path_list_ident_ { name: *id, id: ast::DUMMY_NODE_ID }) respan(sp, ast::PathListIdent_ { name: *id, id: ast::DUMMY_NODE_ID })
}); });
self.view_use(sp, vis, self.view_use(sp, vis,
~[@respan(sp, ~[@respan(sp,
ast::view_path_list(self.path(sp, path), ast::ViewPathList(self.path(sp, path),
imports, imports,
ast::DUMMY_NODE_ID))]) ast::DUMMY_NODE_ID))])
} }
fn view_use_glob(&self, sp: Span, fn view_use_glob(&self, sp: Span,
vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item { vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem {
self.view_use(sp, vis, self.view_use(sp, vis,
~[@respan(sp, ~[@respan(sp,
ast::view_path_glob(self.path(sp, path), ast::DUMMY_NODE_ID))]) ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID))])
} }
} }
@ -908,7 +899,7 @@ struct Duplicator<'a> {
cx: &'a ExtCtxt, cx: &'a ExtCtxt,
} }
impl<'a> ast_fold for Duplicator<'a> { impl<'a> Folder for Duplicator<'a> {
fn new_id(&mut self, _: NodeId) -> NodeId { fn new_id(&mut self, _: NodeId) -> NodeId {
ast::DUMMY_NODE_ID ast::DUMMY_NODE_ID
} }

View file

@ -18,7 +18,7 @@ use ext::build::AstBuilder;
use std::char; use std::char;
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult {
// Gather all argument expressions // Gather all argument expressions
let exprs = get_exprs_from_tts(cx, sp, tts); let exprs = get_exprs_from_tts(cx, sp, tts);
let mut bytes = ~[]; let mut bytes = ~[];
@ -28,14 +28,14 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) ->
// expression is a literal // expression is a literal
ast::ExprLit(lit) => match lit.node { ast::ExprLit(lit) => match lit.node {
// string literal, push each byte to vector expression // string literal, push each byte to vector expression
ast::lit_str(s, _) => { ast::LitStr(s, _) => {
for byte in s.bytes() { for byte in s.bytes() {
bytes.push(cx.expr_u8(expr.span, byte)); bytes.push(cx.expr_u8(expr.span, byte));
} }
} }
// u8 literal, push to vector expression // u8 literal, push to vector expression
ast::lit_uint(v, ast::ty_u8) => { ast::LitUint(v, ast::TyU8) => {
if v > 0xFF { if v > 0xFF {
cx.span_err(expr.span, "Too large u8 literal in bytes!") cx.span_err(expr.span, "Too large u8 literal in bytes!")
} else { } else {
@ -44,7 +44,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) ->
} }
// integer literal, push to vector expression // integer literal, push to vector expression
ast::lit_int_unsuffixed(v) => { ast::LitIntUnsuffixed(v) => {
if v > 0xFF { if v > 0xFF {
cx.span_err(expr.span, "Too large integer literal in bytes!") cx.span_err(expr.span, "Too large integer literal in bytes!")
} else if v < 0 { } else if v < 0 {
@ -55,7 +55,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) ->
} }
// char literal, push to vector expression // char literal, push to vector expression
ast::lit_char(v) => { ast::LitChar(v) => {
if char::from_u32(v).unwrap().is_ascii() { if char::from_u32(v).unwrap().is_ascii() {
bytes.push(cx.expr_u8(expr.span, v as u8)); bytes.push(cx.expr_u8(expr.span, v as u8));
} else { } else {

View file

@ -23,9 +23,9 @@ use attr;
use attr::*; use attr::*;
use parse; use parse;
use parse::token; use parse::token;
use parse::attr::parser_attr; use parse::attr::ParserAttr;
pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult {
let mut p = parse::new_parser_from_tts(cx.parse_sess(), let mut p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(), cx.cfg(),
tts.to_owned()); tts.to_owned());

Some files were not shown because too many files have changed in this diff Show more