librustc: De-export rustc. rs=deexporting
This commit is contained in:
parent
cc9999c609
commit
ae50912875
21 changed files with 415 additions and 528 deletions
|
@ -50,12 +50,8 @@ use syntax::visit;
|
|||
use syntax;
|
||||
use writer = std::ebml::writer;
|
||||
|
||||
export maps;
|
||||
export encode_inlined_item;
|
||||
export decode_inlined_item;
|
||||
|
||||
// Auxiliary maps of things to be encoded
|
||||
type maps = {
|
||||
pub type maps = {
|
||||
mutbl_map: middle::borrowck::mutbl_map,
|
||||
root_map: middle::borrowck::root_map,
|
||||
last_use_map: middle::liveness::last_use_map,
|
||||
|
@ -91,11 +87,11 @@ trait tr_intern {
|
|||
// ______________________________________________________________________
|
||||
// Top-level methods.
|
||||
|
||||
fn encode_inlined_item(ecx: @e::encode_ctxt,
|
||||
ebml_w: writer::Encoder,
|
||||
path: &[ast_map::path_elt],
|
||||
ii: ast::inlined_item,
|
||||
maps: maps) {
|
||||
pub fn encode_inlined_item(ecx: @e::encode_ctxt,
|
||||
ebml_w: writer::Encoder,
|
||||
path: &[ast_map::path_elt],
|
||||
ii: ast::inlined_item,
|
||||
maps: maps) {
|
||||
debug!("> Encoding inlined item: %s::%s (%u)",
|
||||
ast_map::path_to_str(path, ecx.tcx.sess.parse_sess.interner),
|
||||
ecx.tcx.sess.str_of(ii.ident()),
|
||||
|
@ -114,11 +110,12 @@ fn encode_inlined_item(ecx: @e::encode_ctxt,
|
|||
ebml_w.writer.tell());
|
||||
}
|
||||
|
||||
fn decode_inlined_item(cdata: cstore::crate_metadata,
|
||||
tcx: ty::ctxt,
|
||||
maps: maps,
|
||||
+path: ast_map::path,
|
||||
par_doc: ebml::Doc) -> Option<ast::inlined_item> {
|
||||
pub fn decode_inlined_item(cdata: cstore::crate_metadata,
|
||||
tcx: ty::ctxt,
|
||||
maps: maps,
|
||||
+path: ast_map::path,
|
||||
par_doc: ebml::Doc)
|
||||
-> Option<ast::inlined_item> {
|
||||
let dcx = @{cdata: cdata, tcx: tcx, maps: maps};
|
||||
match par_doc.opt_child(c::tag_ast) {
|
||||
None => None,
|
||||
|
|
|
@ -20,37 +20,27 @@ use std::map;
|
|||
use syntax::codemap::span;
|
||||
use syntax::{ast, ast_util};
|
||||
|
||||
export capture_mode;
|
||||
export capture_var;
|
||||
export capture_map;
|
||||
export check_capture_clause;
|
||||
export compute_capture_vars;
|
||||
export cap_copy;
|
||||
export cap_move;
|
||||
export cap_drop;
|
||||
export cap_ref;
|
||||
|
||||
enum capture_mode {
|
||||
pub enum capture_mode {
|
||||
cap_copy, // Copy the value into the closure.
|
||||
cap_move, // Move the value into the closure.
|
||||
cap_drop, // Drop value after creating closure.
|
||||
cap_ref, // Reference directly from parent stack frame (block fn).
|
||||
}
|
||||
|
||||
type capture_var = {
|
||||
pub type capture_var = {
|
||||
def: ast::def, // Variable being accessed free
|
||||
span: span, // Location of access or cap item
|
||||
cap_item: Option<ast::capture_item>, // Capture item, if any
|
||||
mode: capture_mode // How variable is being accessed
|
||||
};
|
||||
|
||||
type capture_map = map::HashMap<ast::def_id, capture_var>;
|
||||
pub type capture_map = map::HashMap<ast::def_id, capture_var>;
|
||||
|
||||
// checks the capture clause for a fn_expr() and issues warnings or
|
||||
// errors for any irregularities which we identify.
|
||||
fn check_capture_clause(tcx: ty::ctxt,
|
||||
fn_expr_id: ast::node_id,
|
||||
cap_clause: ast::capture_clause) {
|
||||
pub fn check_capture_clause(tcx: ty::ctxt,
|
||||
fn_expr_id: ast::node_id,
|
||||
cap_clause: ast::capture_clause) {
|
||||
let freevars = freevars::get_freevars(tcx, fn_expr_id);
|
||||
let seen_defs = map::HashMap();
|
||||
|
||||
|
@ -73,10 +63,11 @@ fn check_capture_clause(tcx: ty::ctxt,
|
|||
}
|
||||
}
|
||||
|
||||
fn compute_capture_vars(tcx: ty::ctxt,
|
||||
fn_expr_id: ast::node_id,
|
||||
fn_proto: ast::Proto,
|
||||
cap_clause: ast::capture_clause) -> ~[capture_var] {
|
||||
pub fn compute_capture_vars(tcx: ty::ctxt,
|
||||
fn_expr_id: ast::node_id,
|
||||
fn_proto: ast::Proto,
|
||||
cap_clause: ast::capture_clause)
|
||||
-> ~[capture_var] {
|
||||
let freevars = freevars::get_freevars(tcx, fn_expr_id);
|
||||
let cap_map = map::HashMap();
|
||||
|
||||
|
|
|
@ -22,9 +22,12 @@ use std::map::HashMap;
|
|||
use syntax::ast::*;
|
||||
use syntax::{visit, ast_util, ast_map};
|
||||
|
||||
fn check_crate(sess: Session, crate: @crate, ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
method_map: typeck::method_map, tcx: ty::ctxt) {
|
||||
pub fn check_crate(sess: Session,
|
||||
crate: @crate,
|
||||
ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
method_map: typeck::method_map,
|
||||
tcx: ty::ctxt) {
|
||||
visit::visit_crate(*crate, false, visit::mk_vt(@visit::Visitor {
|
||||
visit_item: |a,b,c| check_item(sess, ast_map, def_map, a, b, c),
|
||||
visit_pat: check_pat,
|
||||
|
@ -35,9 +38,12 @@ fn check_crate(sess: Session, crate: @crate, ast_map: ast_map::map,
|
|||
sess.abort_if_errors();
|
||||
}
|
||||
|
||||
fn check_item(sess: Session, ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
it: @item, &&_is_const: bool, v: visit::vt<bool>) {
|
||||
pub fn check_item(sess: Session,
|
||||
ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
it: @item,
|
||||
&&_is_const: bool,
|
||||
v: visit::vt<bool>) {
|
||||
match it.node {
|
||||
item_const(_, ex) => {
|
||||
(v.visit_expr)(ex, true, v);
|
||||
|
@ -54,7 +60,7 @@ fn check_item(sess: Session, ast_map: ast_map::map,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
|
||||
pub fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
|
||||
fn is_str(e: @expr) -> bool {
|
||||
match e.node {
|
||||
expr_vstore(
|
||||
|
@ -75,9 +81,13 @@ fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr(sess: Session, def_map: resolve::DefMap,
|
||||
method_map: typeck::method_map, tcx: ty::ctxt,
|
||||
e: @expr, &&is_const: bool, v: visit::vt<bool>) {
|
||||
pub fn check_expr(sess: Session,
|
||||
def_map: resolve::DefMap,
|
||||
method_map: typeck::method_map,
|
||||
tcx: ty::ctxt,
|
||||
e: @expr,
|
||||
&&is_const: bool,
|
||||
v: visit::vt<bool>) {
|
||||
if is_const {
|
||||
match e.node {
|
||||
expr_unary(box(_), _) | expr_unary(uniq(_), _) |
|
||||
|
@ -194,9 +204,10 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
|
|||
|
||||
// Make sure a const item doesn't recursively refer to itself
|
||||
// FIXME: Should use the dependency graph when it's available (#1356)
|
||||
fn check_item_recursion(sess: Session, ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap, it: @item) {
|
||||
|
||||
pub fn check_item_recursion(sess: Session,
|
||||
ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
it: @item) {
|
||||
type env = {
|
||||
root_it: @item,
|
||||
sess: Session,
|
||||
|
|
|
@ -14,9 +14,9 @@ use middle::ty;
|
|||
use syntax::ast::*;
|
||||
use syntax::visit;
|
||||
|
||||
type ctx = {in_loop: bool, can_ret: bool};
|
||||
pub type ctx = {in_loop: bool, can_ret: bool};
|
||||
|
||||
fn check_crate(tcx: ty::ctxt, crate: @crate) {
|
||||
pub fn check_crate(tcx: ty::ctxt, crate: @crate) {
|
||||
visit::visit_crate(*crate,
|
||||
{in_loop: false, can_ret: true},
|
||||
visit::mk_vt(@visit::Visitor {
|
||||
|
|
|
@ -31,12 +31,12 @@ use syntax::codemap::span;
|
|||
use syntax::print::pprust::pat_to_str;
|
||||
use syntax::visit;
|
||||
|
||||
struct MatchCheckCtxt {
|
||||
pub struct MatchCheckCtxt {
|
||||
tcx: ty::ctxt,
|
||||
method_map: method_map,
|
||||
}
|
||||
|
||||
fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
|
||||
pub fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
|
||||
let cx = @MatchCheckCtxt { tcx: tcx, method_map: method_map };
|
||||
visit::visit_crate(*crate, (), visit::mk_vt(@visit::Visitor {
|
||||
visit_expr: |a,b,c| check_expr(cx, a, b, c),
|
||||
|
@ -48,7 +48,7 @@ fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
|
|||
tcx.sess.abort_if_errors();
|
||||
}
|
||||
|
||||
fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
|
||||
pub fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
|
||||
if !ty::expr_is_lval(cx.tcx, cx.method_map, expr) {
|
||||
return false;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
|
||||
pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
|
||||
visit::visit_expr(ex, s, v);
|
||||
match ex.node {
|
||||
expr_match(scrut, ref arms) => {
|
||||
|
@ -108,7 +108,7 @@ fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
|
|||
}
|
||||
|
||||
// Check for unreachable patterns
|
||||
fn check_arms(cx: @MatchCheckCtxt, arms: ~[arm]) {
|
||||
pub fn check_arms(cx: @MatchCheckCtxt, arms: ~[arm]) {
|
||||
let mut seen = ~[];
|
||||
for arms.each |arm| {
|
||||
for arm.pats.each |pat| {
|
||||
|
@ -124,14 +124,14 @@ fn check_arms(cx: @MatchCheckCtxt, arms: ~[arm]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn raw_pat(p: @pat) -> @pat {
|
||||
pub fn raw_pat(p: @pat) -> @pat {
|
||||
match p.node {
|
||||
pat_ident(_, _, Some(s)) => { raw_pat(s) }
|
||||
_ => { p }
|
||||
}
|
||||
}
|
||||
|
||||
fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
||||
pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
||||
assert(!pats.is_empty());
|
||||
let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) {
|
||||
not_useful => return, // This is good, wildcard pattern isn't reachable
|
||||
|
@ -171,11 +171,12 @@ fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
|||
cx.tcx.sess.span_err(sp, msg);
|
||||
}
|
||||
|
||||
type matrix = ~[~[@pat]];
|
||||
pub type matrix = ~[~[@pat]];
|
||||
|
||||
enum useful { useful(ty::t, ctor), useful_, not_useful }
|
||||
pub enum useful { useful(ty::t, ctor), useful_, not_useful }
|
||||
|
||||
enum ctor {
|
||||
#[deriving_eq]
|
||||
pub enum ctor {
|
||||
single,
|
||||
variant(def_id),
|
||||
val(const_val),
|
||||
|
@ -183,27 +184,6 @@ enum ctor {
|
|||
vec(uint)
|
||||
}
|
||||
|
||||
impl ctor : cmp::Eq {
|
||||
pure fn eq(&self, other: &ctor) -> bool {
|
||||
match ((*self), (*other)) {
|
||||
(single, single) => true,
|
||||
(variant(did_self), variant(did_other)) => did_self == did_other,
|
||||
(val(ref cv_self), val(ref cv_other)) =>
|
||||
(*cv_self) == (*cv_other),
|
||||
(range(ref cv0_self, ref cv1_self),
|
||||
range(ref cv0_other, ref cv1_other)) => {
|
||||
(*cv0_self) == (*cv0_other) && (*cv1_self) == (*cv1_other)
|
||||
}
|
||||
(vec(n_self), vec(n_other)) => n_self == n_other,
|
||||
(single, _) | (variant(_), _) | (val(_), _) |
|
||||
(range(*), _) | (vec(*), _) => {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
pure fn ne(&self, other: &ctor) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
// Algorithm from http://moscova.inria.fr/~maranget/papers/warn/index.html
|
||||
//
|
||||
// Whether a vector `v` of patterns is 'useful' in relation to a set of such
|
||||
|
@ -217,7 +197,7 @@ impl ctor : cmp::Eq {
|
|||
|
||||
// Note: is_useful doesn't work on empty types, as the paper notes.
|
||||
// So it assumes that v is non-empty.
|
||||
fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
|
||||
pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
|
||||
if m.len() == 0u { return useful_; }
|
||||
if m[0].len() == 0u { return not_useful; }
|
||||
let real_pat = match vec::find(m, |r| r[0].id != 0) {
|
||||
|
@ -290,8 +270,13 @@ fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_useful_specialized(cx: @MatchCheckCtxt, m: matrix, +v: ~[@pat],
|
||||
+ctor: ctor, arity: uint, lty: ty::t) -> useful {
|
||||
pub fn is_useful_specialized(cx: @MatchCheckCtxt,
|
||||
m: matrix,
|
||||
+v: ~[@pat],
|
||||
+ctor: ctor,
|
||||
arity: uint,
|
||||
lty: ty::t)
|
||||
-> useful {
|
||||
let ms = vec::filter_map(m, |r| specialize(cx, copy *r,
|
||||
ctor, arity, lty));
|
||||
let could_be_useful = is_useful(
|
||||
|
@ -302,7 +287,7 @@ fn is_useful_specialized(cx: @MatchCheckCtxt, m: matrix, +v: ~[@pat],
|
|||
}
|
||||
}
|
||||
|
||||
fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
|
||||
pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
|
||||
let pat = raw_pat(p);
|
||||
match /*bad*/copy pat.node {
|
||||
pat_wild => { None }
|
||||
|
@ -339,7 +324,7 @@ fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
|
||||
pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
|
||||
let pat = raw_pat(p);
|
||||
match pat.node {
|
||||
pat_wild => { true }
|
||||
|
@ -353,10 +338,10 @@ fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn missing_ctor(cx: @MatchCheckCtxt,
|
||||
m: matrix,
|
||||
left_ty: ty::t)
|
||||
-> Option<ctor> {
|
||||
pub fn missing_ctor(cx: @MatchCheckCtxt,
|
||||
m: matrix,
|
||||
left_ty: ty::t)
|
||||
-> Option<ctor> {
|
||||
match ty::get(left_ty).sty {
|
||||
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_rptr(*) | ty::ty_tup(_) |
|
||||
ty::ty_rec(_) | ty::ty_struct(*) => {
|
||||
|
@ -453,7 +438,7 @@ fn missing_ctor(cx: @MatchCheckCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
|
||||
pub fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
|
||||
match /*bad*/copy ty::get(ty).sty {
|
||||
ty::ty_tup(fs) => fs.len(),
|
||||
ty::ty_rec(fs) => fs.len(),
|
||||
|
@ -477,12 +462,16 @@ fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
|
|||
}
|
||||
}
|
||||
|
||||
fn wild() -> @pat {
|
||||
pub fn wild() -> @pat {
|
||||
@pat {id: 0, node: pat_wild, span: ast_util::dummy_sp()}
|
||||
}
|
||||
|
||||
fn specialize(cx: @MatchCheckCtxt, +r: ~[@pat], ctor_id: ctor, arity: uint,
|
||||
left_ty: ty::t) -> Option<~[@pat]> {
|
||||
pub fn specialize(cx: @MatchCheckCtxt,
|
||||
+r: ~[@pat],
|
||||
ctor_id: ctor,
|
||||
arity: uint,
|
||||
left_ty: ty::t)
|
||||
-> Option<~[@pat]> {
|
||||
// Sad, but I can't get rid of this easily
|
||||
let mut r0 = copy *raw_pat(r[0]);
|
||||
match r0 {
|
||||
|
@ -648,12 +637,15 @@ fn specialize(cx: @MatchCheckCtxt, +r: ~[@pat], ctor_id: ctor, arity: uint,
|
|||
}
|
||||
}
|
||||
|
||||
fn default(cx: @MatchCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> {
|
||||
pub fn default(cx: @MatchCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> {
|
||||
if is_wild(cx, r[0]) { Some(vec::tail(r)) }
|
||||
else { None }
|
||||
}
|
||||
|
||||
fn check_local(cx: @MatchCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
|
||||
pub fn check_local(cx: @MatchCheckCtxt,
|
||||
loc: @local,
|
||||
&&s: (),
|
||||
v: visit::vt<()>) {
|
||||
visit::visit_local(loc, s, v);
|
||||
if is_refutable(cx, loc.node.pat) {
|
||||
cx.tcx.sess.span_err(loc.node.pat.span,
|
||||
|
@ -668,14 +660,14 @@ fn check_local(cx: @MatchCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
|
|||
check_legality_of_move_bindings(cx, is_lvalue, false, [ loc.node.pat ]);
|
||||
}
|
||||
|
||||
fn check_fn(cx: @MatchCheckCtxt,
|
||||
kind: visit::fn_kind,
|
||||
decl: fn_decl,
|
||||
body: blk,
|
||||
sp: span,
|
||||
id: node_id,
|
||||
&&s: (),
|
||||
v: visit::vt<()>) {
|
||||
pub fn check_fn(cx: @MatchCheckCtxt,
|
||||
kind: visit::fn_kind,
|
||||
decl: fn_decl,
|
||||
body: blk,
|
||||
sp: span,
|
||||
id: node_id,
|
||||
&&s: (),
|
||||
v: visit::vt<()>) {
|
||||
visit::visit_fn(kind, decl, body, sp, id, s, v);
|
||||
for decl.inputs.each |input| {
|
||||
if is_refutable(cx, input.pat) {
|
||||
|
@ -685,7 +677,7 @@ fn check_fn(cx: @MatchCheckCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
|
||||
pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
|
||||
match cx.tcx.def_map.find(pat.id) {
|
||||
Some(def_variant(enum_id, _)) => {
|
||||
if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u {
|
||||
|
@ -726,10 +718,10 @@ fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
|
|||
|
||||
// Legality of move bindings checking
|
||||
|
||||
fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
|
||||
is_lvalue: bool,
|
||||
has_guard: bool,
|
||||
pats: &[@pat]) {
|
||||
pub fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
|
||||
is_lvalue: bool,
|
||||
has_guard: bool,
|
||||
pats: &[@pat]) {
|
||||
let tcx = cx.tcx;
|
||||
let def_map = tcx.def_map;
|
||||
let mut by_ref_span = None;
|
||||
|
|
|
@ -53,13 +53,13 @@ use syntax::ast::*;
|
|||
// - Non-constants: everything else.
|
||||
//
|
||||
|
||||
enum constness {
|
||||
pub enum constness {
|
||||
integral_const,
|
||||
general_const,
|
||||
non_const
|
||||
}
|
||||
|
||||
fn join(a: constness, b: constness) -> constness {
|
||||
pub fn join(a: constness, b: constness) -> constness {
|
||||
match (a, b) {
|
||||
(integral_const, integral_const) => integral_const,
|
||||
(integral_const, general_const)
|
||||
|
@ -69,13 +69,14 @@ fn join(a: constness, b: constness) -> constness {
|
|||
}
|
||||
}
|
||||
|
||||
fn join_all(cs: &[constness]) -> constness {
|
||||
pub fn join_all(cs: &[constness]) -> constness {
|
||||
vec::foldl(integral_const, cs, |a, b| join(a, *b))
|
||||
}
|
||||
|
||||
fn classify(e: @expr,
|
||||
def_map: resolve::DefMap,
|
||||
tcx: ty::ctxt) -> constness {
|
||||
pub fn classify(e: @expr,
|
||||
def_map: resolve::DefMap,
|
||||
tcx: ty::ctxt)
|
||||
-> constness {
|
||||
let did = ast_util::local_def(e.id);
|
||||
match tcx.ccache.find(did) {
|
||||
Some(x) => x,
|
||||
|
@ -168,14 +169,16 @@ fn classify(e: @expr,
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> {
|
||||
pub fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> {
|
||||
match tcx.def_map.find(e.id) {
|
||||
Some(ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::def_id) -> Option<@expr> {
|
||||
pub fn lookup_const_by_id(tcx: ty::ctxt,
|
||||
def_id: ast::def_id)
|
||||
-> Option<@expr> {
|
||||
if ast_util::is_local(def_id) {
|
||||
match tcx.items.find(def_id.node) {
|
||||
None => None,
|
||||
|
@ -190,7 +193,7 @@ fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::def_id) -> Option<@expr> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_constness(tcx: ty::ctxt, e: @expr) -> constness {
|
||||
pub fn lookup_constness(tcx: ty::ctxt, e: @expr) -> constness {
|
||||
match lookup_const(tcx, e) {
|
||||
Some(rhs) => {
|
||||
let ty = ty::expr_ty(tcx, rhs);
|
||||
|
@ -204,9 +207,9 @@ fn lookup_constness(tcx: ty::ctxt, e: @expr) -> constness {
|
|||
}
|
||||
}
|
||||
|
||||
fn process_crate(crate: @ast::crate,
|
||||
def_map: resolve::DefMap,
|
||||
tcx: ty::ctxt) {
|
||||
pub fn process_crate(crate: @ast::crate,
|
||||
def_map: resolve::DefMap,
|
||||
tcx: ty::ctxt) {
|
||||
let v = visit::mk_simple_visitor(@visit::SimpleVisitor {
|
||||
visit_expr_post: |e| { classify(e, def_map, tcx); },
|
||||
.. *visit::default_simple_visitor()
|
||||
|
@ -218,7 +221,8 @@ fn process_crate(crate: @ast::crate,
|
|||
|
||||
// FIXME (#33): this doesn't handle big integer/float literals correctly
|
||||
// (nor does the rest of our literal handling).
|
||||
enum const_val {
|
||||
#[deriving_eq]
|
||||
pub enum const_val {
|
||||
const_float(f64),
|
||||
const_int(i64),
|
||||
const_uint(u64),
|
||||
|
@ -226,30 +230,15 @@ enum const_val {
|
|||
const_bool(bool)
|
||||
}
|
||||
|
||||
impl const_val : cmp::Eq {
|
||||
pure fn eq(&self, other: &const_val) -> bool {
|
||||
match ((*self), (*other)) {
|
||||
(const_float(a), const_float(b)) => a == b,
|
||||
(const_int(a), const_int(b)) => a == b,
|
||||
(const_uint(a), const_uint(b)) => a == b,
|
||||
(const_str(ref a), const_str(ref b)) => (*a) == (*b),
|
||||
(const_bool(a), const_bool(b)) => a == b,
|
||||
(const_float(_), _) | (const_int(_), _) | (const_uint(_), _) |
|
||||
(const_str(_), _) | (const_bool(_), _) => false
|
||||
}
|
||||
}
|
||||
pure fn ne(&self, other: &const_val) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
fn eval_const_expr(tcx: middle::ty::ctxt, e: @expr) -> const_val {
|
||||
pub fn eval_const_expr(tcx: middle::ty::ctxt, e: @expr) -> const_val {
|
||||
match eval_const_expr_partial(tcx, e) {
|
||||
Ok(ref r) => (/*bad*/copy *r),
|
||||
Err(ref s) => fail (/*bad*/copy *s)
|
||||
}
|
||||
}
|
||||
|
||||
fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
|
||||
-> Result<const_val, ~str> {
|
||||
pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
|
||||
-> Result<const_val, ~str> {
|
||||
use middle::ty;
|
||||
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
|
||||
match e.node {
|
||||
|
@ -409,7 +398,7 @@ fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
|
|||
}
|
||||
}
|
||||
|
||||
fn lit_to_const(lit: @lit) -> const_val {
|
||||
pub fn lit_to_const(lit: @lit) -> const_val {
|
||||
match lit.node {
|
||||
lit_str(s) => const_str(/*bad*/copy *s),
|
||||
lit_int(n, _) => const_int(n),
|
||||
|
@ -423,7 +412,7 @@ fn lit_to_const(lit: @lit) -> const_val {
|
|||
}
|
||||
}
|
||||
|
||||
fn compare_const_vals(a: const_val, b: const_val) -> int {
|
||||
pub fn compare_const_vals(a: const_val, b: const_val) -> int {
|
||||
match (a, b) {
|
||||
(const_int(a), const_int(b)) => {
|
||||
if a == b {
|
||||
|
@ -474,15 +463,15 @@ fn compare_const_vals(a: const_val, b: const_val) -> int {
|
|||
}
|
||||
}
|
||||
|
||||
fn compare_lit_exprs(tcx: middle::ty::ctxt, a: @expr, b: @expr) -> int {
|
||||
pub fn compare_lit_exprs(tcx: middle::ty::ctxt, a: @expr, b: @expr) -> int {
|
||||
compare_const_vals(eval_const_expr(tcx, a), eval_const_expr(tcx, b))
|
||||
}
|
||||
|
||||
fn lit_expr_eq(tcx: middle::ty::ctxt, a: @expr, b: @expr) -> bool {
|
||||
pub fn lit_expr_eq(tcx: middle::ty::ctxt, a: @expr, b: @expr) -> bool {
|
||||
compare_lit_exprs(tcx, a, b) == 0
|
||||
}
|
||||
|
||||
fn lit_eq(a: @lit, b: @lit) -> bool {
|
||||
pub fn lit_eq(a: @lit, b: @lit) -> bool {
|
||||
compare_const_vals(lit_to_const(a), lit_to_const(b)) == 0
|
||||
}
|
||||
|
||||
|
|
|
@ -23,23 +23,16 @@ use syntax::codemap::span;
|
|||
use syntax::print::pprust::path_to_str;
|
||||
use syntax::{ast, ast_util, visit};
|
||||
|
||||
export annotate_freevars;
|
||||
export freevar_map;
|
||||
export freevar_info;
|
||||
export freevar_entry;
|
||||
export get_freevars;
|
||||
export has_freevars;
|
||||
|
||||
// A vector of defs representing the free variables referred to in a function.
|
||||
// (The def_upvar will already have been stripped).
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
struct freevar_entry {
|
||||
pub struct freevar_entry {
|
||||
def: ast::def, //< The variable being accessed free.
|
||||
span: span //< First span where it is accessed (there can be multiple)
|
||||
}
|
||||
type freevar_info = @~[@freevar_entry];
|
||||
type freevar_map = HashMap<ast::node_id, freevar_info>;
|
||||
pub type freevar_info = @~[@freevar_entry];
|
||||
pub type freevar_map = HashMap<ast::node_id, freevar_info>;
|
||||
|
||||
// Searches through part of the AST for all references to locals or
|
||||
// upvars in this frame and returns the list of definition IDs thus found.
|
||||
|
@ -105,7 +98,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk)
|
|||
// efficient as it fully recomputes the free variables at every
|
||||
// node of interest rather than building up the free variables in
|
||||
// one pass. This could be improved upon if it turns out to matter.
|
||||
fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) ->
|
||||
pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) ->
|
||||
freevar_map {
|
||||
let freevars = HashMap();
|
||||
|
||||
|
@ -124,13 +117,13 @@ fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) ->
|
|||
return freevars;
|
||||
}
|
||||
|
||||
fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info {
|
||||
pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info {
|
||||
match tcx.freevars.find(fid) {
|
||||
None => fail ~"get_freevars: " + int::str(fid) + ~" has no freevars",
|
||||
Some(d) => return d
|
||||
}
|
||||
}
|
||||
fn has_freevars(tcx: ty::ctxt, fid: ast::node_id) -> bool {
|
||||
pub fn has_freevars(tcx: ty::ctxt, fid: ast::node_id) -> bool {
|
||||
return vec::len(*get_freevars(tcx, fid)) != 0u;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,9 +60,9 @@ use syntax::{visit, ast_util};
|
|||
// primitives in the stdlib are explicitly annotated to only take sendable
|
||||
// types.
|
||||
|
||||
const try_adding: &str = "Try adding a move";
|
||||
pub const try_adding: &str = "Try adding a move";
|
||||
|
||||
fn kind_to_str(k: Kind) -> ~str {
|
||||
pub fn kind_to_str(k: Kind) -> ~str {
|
||||
let mut kinds = ~[];
|
||||
|
||||
if ty::kind_lteq(kind_const(), k) {
|
||||
|
@ -82,17 +82,19 @@ fn kind_to_str(k: Kind) -> ~str {
|
|||
str::connect(kinds, ~" ")
|
||||
}
|
||||
|
||||
type rval_map = HashMap<node_id, ()>;
|
||||
pub type rval_map = HashMap<node_id, ()>;
|
||||
|
||||
type ctx = {tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
last_use_map: liveness::last_use_map,
|
||||
current_item: node_id};
|
||||
pub type ctx = {
|
||||
tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
last_use_map: liveness::last_use_map,
|
||||
current_item: node_id
|
||||
};
|
||||
|
||||
fn check_crate(tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
last_use_map: liveness::last_use_map,
|
||||
crate: @crate) {
|
||||
pub fn check_crate(tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
last_use_map: liveness::last_use_map,
|
||||
crate: @crate) {
|
||||
let ctx = {tcx: tcx,
|
||||
method_map: method_map,
|
||||
last_use_map: last_use_map,
|
||||
|
@ -116,13 +118,17 @@ fn check_crate(tcx: ty::ctxt,
|
|||
// bool flag is only used for checking closures,
|
||||
// where it refers to whether a var is 'move' in the
|
||||
// capture clause
|
||||
type check_fn = fn@(ctx, node_id, Option<@freevar_entry>,
|
||||
bool, ty::t, sp: span);
|
||||
pub type check_fn = fn@(ctx,
|
||||
node_id,
|
||||
Option<@freevar_entry>,
|
||||
bool,
|
||||
ty::t,
|
||||
sp: span);
|
||||
|
||||
// Yields the appropriate function to check the kind of closed over
|
||||
// variables. `id` is the node_id for some expression that creates the
|
||||
// closure.
|
||||
fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
|
||||
pub fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
|
||||
fn check_for_uniq(cx: ctx, id: node_id, fv: Option<@freevar_entry>,
|
||||
is_move: bool, var_t: ty::t, sp: span) {
|
||||
// all captured data must be sendable, regardless of whether it is
|
||||
|
@ -191,9 +197,8 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
|
|||
|
||||
// Check that the free variables used in a shared/sendable closure conform
|
||||
// to the copy/move kind bounds. Then recursively check the function body.
|
||||
fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
|
||||
fn_id: node_id, cx: ctx, v: visit::vt<ctx>) {
|
||||
|
||||
pub fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
|
||||
fn_id: node_id, cx: ctx, v: visit::vt<ctx>) {
|
||||
// Find the check function that enforces the appropriate bounds for this
|
||||
// kind of function:
|
||||
do with_appropriate_checker(cx, fn_id) |chk| {
|
||||
|
@ -237,7 +242,7 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
|
|||
visit::visit_fn(fk, decl, body, sp, fn_id, cx, v);
|
||||
}
|
||||
|
||||
fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
|
||||
pub fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
|
||||
match b.node.expr {
|
||||
Some(ex) => maybe_copy(cx, ex,
|
||||
Some(("Tail expressions in blocks must be copyable",
|
||||
|
@ -247,7 +252,7 @@ fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
|
|||
visit::visit_block(b, cx, v);
|
||||
}
|
||||
|
||||
fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) {
|
||||
pub fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) {
|
||||
for vec::each(a.pats) |p| {
|
||||
do pat_util::pat_bindings(cx.tcx.def_map, *p) |mode, id, span, _pth| {
|
||||
if mode == bind_by_value {
|
||||
|
@ -260,7 +265,7 @@ fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) {
|
|||
visit::visit_arm(a, cx, v);
|
||||
}
|
||||
|
||||
fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
pub fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));
|
||||
let id_to_use = match e.node {
|
||||
expr_index(*)|expr_assign_op(*)|
|
||||
|
@ -407,7 +412,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
|||
visit::visit_expr(e, cx, v);
|
||||
}
|
||||
|
||||
fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
|
||||
pub fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
|
||||
match stmt.node {
|
||||
stmt_decl(@spanned {node: decl_local(ref locals), _}, _) => {
|
||||
for locals.each |local| {
|
||||
|
@ -424,7 +429,7 @@ fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
|
|||
visit::visit_stmt(stmt, cx, v);
|
||||
}
|
||||
|
||||
fn check_ty(aty: @Ty, cx: ctx, v: visit::vt<ctx>) {
|
||||
pub fn check_ty(aty: @Ty, cx: ctx, v: visit::vt<ctx>) {
|
||||
match aty.node {
|
||||
ty_path(_, id) => {
|
||||
do option::iter(&cx.tcx.node_type_substs.find(id)) |ts| {
|
||||
|
@ -440,8 +445,8 @@ fn check_ty(aty: @Ty, cx: ctx, v: visit::vt<ctx>) {
|
|||
visit::visit_ty(aty, cx, v);
|
||||
}
|
||||
|
||||
fn check_bounds(cx: ctx, id: node_id, sp: span,
|
||||
ty: ty::t, bounds: ty::param_bounds) {
|
||||
pub fn check_bounds(cx: ctx, id: node_id, sp: span,
|
||||
ty: ty::t, bounds: ty::param_bounds) {
|
||||
let kind = ty::type_kind(cx.tcx, ty);
|
||||
let p_kind = ty::param_bounds_to_kind(bounds);
|
||||
if !ty::kind_lteq(p_kind, kind) {
|
||||
|
@ -466,11 +471,11 @@ fn check_bounds(cx: ctx, id: node_id, sp: span,
|
|||
}
|
||||
}
|
||||
|
||||
fn maybe_copy(cx: ctx, ex: @expr, why: Option<(&str,&str)>) {
|
||||
pub fn maybe_copy(cx: ctx, ex: @expr, why: Option<(&str,&str)>) {
|
||||
check_copy_ex(cx, ex, true, why);
|
||||
}
|
||||
|
||||
fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
|
||||
pub fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
|
||||
match ex.node {
|
||||
expr_path(_) => {
|
||||
match cx.tcx.def_map.get(ex.id) {
|
||||
|
@ -484,8 +489,8 @@ fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_copy_ex(cx: ctx, ex: @expr, implicit_copy: bool,
|
||||
why: Option<(&str,&str)>) {
|
||||
pub fn check_copy_ex(cx: ctx, ex: @expr, implicit_copy: bool,
|
||||
why: Option<(&str,&str)>) {
|
||||
if ty::expr_is_lval(cx.tcx, cx.method_map, ex) &&
|
||||
|
||||
// a reference to a constant like `none`... no need to warn
|
||||
|
@ -515,7 +520,7 @@ fn check_copy_ex(cx: ctx, ex: @expr, implicit_copy: bool,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_imm_free_var(cx: ctx, def: def, sp: span) {
|
||||
pub fn check_imm_free_var(cx: ctx, def: def, sp: span) {
|
||||
let msg = ~"mutable variables cannot be implicitly captured; \
|
||||
use a capture clause";
|
||||
match def {
|
||||
|
@ -537,8 +542,8 @@ fn check_imm_free_var(cx: ctx, def: def, sp: span) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_copy(cx: ctx, id: node_id, ty: ty::t, sp: span,
|
||||
implicit_copy: bool, why: Option<(&str,&str)>) {
|
||||
pub fn check_copy(cx: ctx, id: node_id, ty: ty::t, sp: span,
|
||||
implicit_copy: bool, why: Option<(&str,&str)>) {
|
||||
let k = ty::type_kind(cx.tcx, ty);
|
||||
if !ty::kind_can_be_copied(k) {
|
||||
cx.tcx.sess.span_err(sp, ~"copying a noncopyable value");
|
||||
|
@ -556,7 +561,7 @@ fn check_copy(cx: ctx, id: node_id, ty: ty::t, sp: span,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_send(cx: ctx, ty: ty::t, sp: span) -> bool {
|
||||
pub fn check_send(cx: ctx, ty: ty::t, sp: span) -> bool {
|
||||
if !ty::kind_can_be_sent(ty::type_kind(cx.tcx, ty)) {
|
||||
cx.tcx.sess.span_err(sp, ~"not a sendable value");
|
||||
false
|
||||
|
@ -566,7 +571,7 @@ fn check_send(cx: ctx, ty: ty::t, sp: span) -> bool {
|
|||
}
|
||||
|
||||
// note: also used from middle::typeck::regionck!
|
||||
fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
|
||||
pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
|
||||
if !ty::kind_is_durable(ty::type_kind(tcx, ty)) {
|
||||
match ty::get(ty).sty {
|
||||
ty::ty_param(*) => {
|
||||
|
@ -607,7 +612,7 @@ fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
|
|||
///
|
||||
/// (3) The type parameter is owned (and therefore does not contain
|
||||
/// borrowed ptrs).
|
||||
fn check_cast_for_escaping_regions(
|
||||
pub fn check_cast_for_escaping_regions(
|
||||
cx: ctx,
|
||||
source: @expr,
|
||||
target: @expr) {
|
||||
|
@ -652,7 +657,7 @@ fn check_cast_for_escaping_regions(
|
|||
}
|
||||
|
||||
/// Ensures that values placed into a ~Trait are copyable and sendable.
|
||||
fn check_kind_bounds_of_cast(cx: ctx, source: @expr, target: @expr) {
|
||||
pub fn check_kind_bounds_of_cast(cx: ctx, source: @expr, target: @expr) {
|
||||
let target_ty = ty::expr_ty(cx.tcx, target);
|
||||
match ty::get(target_ty).sty {
|
||||
ty::ty_trait(_, _, ty::vstore_uniq) => {
|
||||
|
|
|
@ -77,11 +77,11 @@ pub enum LangItem {
|
|||
StrDupUniqFnLangItem, // 33
|
||||
}
|
||||
|
||||
struct LanguageItems {
|
||||
pub struct LanguageItems {
|
||||
items: [ Option<def_id> * 34 ]
|
||||
}
|
||||
|
||||
impl LanguageItems {
|
||||
pub impl LanguageItems {
|
||||
static pub fn new() -> LanguageItems {
|
||||
LanguageItems {
|
||||
items: [ None, ..34 ]
|
||||
|
@ -410,7 +410,9 @@ impl LanguageItemCollector {
|
|||
}
|
||||
}
|
||||
|
||||
fn collect_language_items(crate: @crate, session: Session) -> LanguageItems {
|
||||
pub fn collect_language_items(crate: @crate,
|
||||
session: Session)
|
||||
-> LanguageItems {
|
||||
let mut items = LanguageItems::new();
|
||||
let collector = LanguageItemCollector(crate, session, &mut items);
|
||||
collector.collect();
|
||||
|
|
|
@ -42,15 +42,6 @@ use syntax::codemap::span;
|
|||
use syntax::print::pprust::{expr_to_str, mode_to_str, pat_to_str};
|
||||
use syntax::{ast, ast_util, visit};
|
||||
|
||||
export lint, ctypes, unused_imports, while_true, path_statement, old_vecs;
|
||||
export unrecognized_lint, non_implicitly_copyable_typarams;
|
||||
export vecs_implicitly_copyable, implicit_copies, legacy_modes;
|
||||
export level, allow, warn, deny, forbid;
|
||||
export lint_dict, get_lint_dict, level_to_str;
|
||||
export get_lint_level, get_lint_settings_level;
|
||||
export check_crate, build_settings_crate, mk_lint_settings;
|
||||
export lint_settings;
|
||||
|
||||
/**
|
||||
* A 'lint' check is a kind of miscellaneous constraint that a user _might_
|
||||
* want to enforce, but might reasonably want to permit as well, on a
|
||||
|
@ -72,7 +63,8 @@ export lint_settings;
|
|||
* process.
|
||||
*/
|
||||
|
||||
enum lint {
|
||||
#[deriving_eq]
|
||||
pub enum lint {
|
||||
ctypes,
|
||||
unused_imports,
|
||||
while_true,
|
||||
|
@ -100,14 +92,7 @@ enum lint {
|
|||
// dead_assignment
|
||||
}
|
||||
|
||||
impl lint : cmp::Eq {
|
||||
pure fn eq(&self, other: &lint) -> bool {
|
||||
((*self) as uint) == ((*other) as uint)
|
||||
}
|
||||
pure fn ne(&self, other: &lint) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
fn level_to_str(lv: level) -> &static/str {
|
||||
pub fn level_to_str(lv: level) -> &static/str {
|
||||
match lv {
|
||||
allow => "allow",
|
||||
warn => "warn",
|
||||
|
@ -116,7 +101,7 @@ fn level_to_str(lv: level) -> &static/str {
|
|||
}
|
||||
}
|
||||
|
||||
enum level {
|
||||
pub enum level {
|
||||
allow, warn, deny, forbid
|
||||
}
|
||||
|
||||
|
@ -131,13 +116,13 @@ type lint_spec = @{lint: lint,
|
|||
desc: &static/str,
|
||||
default: level};
|
||||
|
||||
type lint_dict = HashMap<~str,lint_spec>;
|
||||
pub type lint_dict = HashMap<~str,lint_spec>;
|
||||
|
||||
/*
|
||||
Pass names should not contain a '-', as the compiler normalizes
|
||||
'-' to '_' in command-line flags
|
||||
*/
|
||||
fn get_lint_dict() -> lint_dict {
|
||||
pub fn get_lint_dict() -> lint_dict {
|
||||
let v = ~[
|
||||
(~"ctypes",
|
||||
@{lint: ctypes,
|
||||
|
@ -257,27 +242,28 @@ type lint_mode_map = HashMap<ast::node_id, lint_modes>;
|
|||
// settings_map maps node ids of items with non-default lint settings
|
||||
// to their settings; default_settings contains the settings for everything
|
||||
// not in the map.
|
||||
type lint_settings = {
|
||||
pub type lint_settings = {
|
||||
default_settings: lint_modes,
|
||||
settings_map: lint_mode_map
|
||||
};
|
||||
|
||||
fn mk_lint_settings() -> lint_settings {
|
||||
pub fn mk_lint_settings() -> lint_settings {
|
||||
{default_settings: smallintmap::mk(),
|
||||
settings_map: HashMap()}
|
||||
}
|
||||
|
||||
fn get_lint_level(modes: lint_modes, lint: lint) -> level {
|
||||
pub fn get_lint_level(modes: lint_modes, lint: lint) -> level {
|
||||
match modes.find(lint as uint) {
|
||||
Some(c) => c,
|
||||
None => allow
|
||||
}
|
||||
}
|
||||
|
||||
fn get_lint_settings_level(settings: lint_settings,
|
||||
lint_mode: lint,
|
||||
_expr_id: ast::node_id,
|
||||
item_id: ast::node_id) -> level {
|
||||
pub fn get_lint_settings_level(settings: lint_settings,
|
||||
lint_mode: lint,
|
||||
_expr_id: ast::node_id,
|
||||
item_id: ast::node_id)
|
||||
-> level {
|
||||
match settings.settings_map.find(item_id) {
|
||||
Some(modes) => get_lint_level(modes, lint_mode),
|
||||
None => get_lint_level(settings.default_settings, lint_mode)
|
||||
|
@ -405,8 +391,7 @@ fn build_settings_item(i: @ast::item, &&cx: ctxt, v: visit::vt<ctxt>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn build_settings_crate(sess: session::Session, crate: @ast::crate) {
|
||||
|
||||
pub fn build_settings_crate(sess: session::Session, crate: @ast::crate) {
|
||||
let cx = ctxt_({dict: get_lint_dict(),
|
||||
curr: smallintmap::mk(),
|
||||
is_default: true,
|
||||
|
@ -999,8 +984,7 @@ fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
|
||||
|
||||
pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
|
||||
let v = visit::mk_simple_visitor(@visit::SimpleVisitor {
|
||||
visit_item: |it|
|
||||
check_item(it, tcx),
|
||||
|
|
|
@ -129,9 +129,6 @@ use syntax::visit::{fk_anon, fk_dtor, fk_fn_block, fk_item_fn, fk_method};
|
|||
use syntax::visit::{vt};
|
||||
use syntax::{visit, ast_util};
|
||||
|
||||
export check_crate;
|
||||
export last_use_map;
|
||||
|
||||
// Maps from an expr id to a list of variable ids for which this expr
|
||||
// is the last use. Typically, the expr is a path and the node id is
|
||||
// the local/argument/etc that the path refers to. However, it also
|
||||
|
@ -140,7 +137,7 @@ export last_use_map;
|
|||
//
|
||||
// Very subtle (#2633): borrowck will remove entries from this table
|
||||
// if it detects an outstanding loan (that is, the addr is taken).
|
||||
type last_use_map = HashMap<node_id, @DVec<node_id>>;
|
||||
pub type last_use_map = HashMap<node_id, @DVec<node_id>>;
|
||||
|
||||
enum Variable = uint;
|
||||
enum LiveNode = uint;
|
||||
|
@ -204,9 +201,9 @@ fn live_node_kind_to_str(lnk: LiveNodeKind, cx: ty::ctxt) -> ~str {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_crate(tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
crate: @crate) -> last_use_map {
|
||||
pub fn check_crate(tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
crate: @crate) -> last_use_map {
|
||||
let visitor = visit::mk_vt(@visit::Visitor {
|
||||
visit_fn: visit_fn,
|
||||
visit_local: visit_local,
|
||||
|
|
|
@ -63,7 +63,7 @@ use syntax::codemap::span;
|
|||
use syntax::print::pprust;
|
||||
|
||||
#[deriving_eq]
|
||||
enum categorization {
|
||||
pub enum categorization {
|
||||
cat_rvalue, // result of eval'ing some misc expr
|
||||
cat_special(special_kind), //
|
||||
cat_local(ast::node_id), // local variable
|
||||
|
@ -101,7 +101,7 @@ pub enum comp_kind {
|
|||
|
||||
// different kinds of expressions we might evaluate
|
||||
#[deriving_eq]
|
||||
enum special_kind {
|
||||
pub enum special_kind {
|
||||
sk_method,
|
||||
sk_static_item,
|
||||
sk_implicit_self, // old by-reference `self`
|
||||
|
@ -114,7 +114,7 @@ enum special_kind {
|
|||
//
|
||||
// note: cmt stands for "categorized mutable type".
|
||||
#[deriving_eq]
|
||||
struct cmt_ {
|
||||
pub struct cmt_ {
|
||||
id: ast::node_id, // id of expr/pat producing this value
|
||||
span: span, // span of same expr/pat
|
||||
cat: categorization, // categorization of expr
|
||||
|
@ -123,7 +123,7 @@ struct cmt_ {
|
|||
ty: ty::t // type of the expr
|
||||
}
|
||||
|
||||
type cmt = @cmt_;
|
||||
pub type cmt = @cmt_;
|
||||
|
||||
// a loan path is like a category, but it exists only when the data is
|
||||
// interior to the stack frame. loan paths are used as the key to a
|
||||
|
@ -139,12 +139,12 @@ pub enum loan_path {
|
|||
|
||||
// We pun on *T to mean both actual deref of a ptr as well
|
||||
// as accessing of components:
|
||||
enum deref_kind {deref_ptr(ptr_kind), deref_comp(comp_kind)}
|
||||
pub enum deref_kind {deref_ptr(ptr_kind), deref_comp(comp_kind)}
|
||||
|
||||
// Categorizes a derefable type. Note that we include vectors and strings as
|
||||
// derefable (we model an index as the combination of a deref and then a
|
||||
// pointer adjustment).
|
||||
fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
|
||||
pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
|
||||
match ty::get(t).sty {
|
||||
ty::ty_uniq(*) |
|
||||
ty::ty_evec(_, ty::vstore_uniq) |
|
||||
|
@ -206,7 +206,7 @@ fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
|
|||
}
|
||||
}
|
||||
|
||||
fn deref_kind(tcx: ty::ctxt, t: ty::t) -> deref_kind {
|
||||
pub fn deref_kind(tcx: ty::ctxt, t: ty::t) -> deref_kind {
|
||||
match opt_deref_kind(t) {
|
||||
Some(k) => k,
|
||||
None => {
|
||||
|
@ -217,29 +217,27 @@ fn deref_kind(tcx: ty::ctxt, t: ty::t) -> deref_kind {
|
|||
}
|
||||
}
|
||||
|
||||
fn cat_expr(
|
||||
tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
expr: @ast::expr) -> cmt {
|
||||
|
||||
pub fn cat_expr(tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
expr: @ast::expr)
|
||||
-> cmt {
|
||||
let mcx = &mem_categorization_ctxt {
|
||||
tcx: tcx, method_map: method_map
|
||||
};
|
||||
return mcx.cat_expr(expr);
|
||||
}
|
||||
|
||||
fn cat_expr_unadjusted(
|
||||
tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
expr: @ast::expr) -> cmt {
|
||||
|
||||
pub fn cat_expr_unadjusted(tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
expr: @ast::expr)
|
||||
-> cmt {
|
||||
let mcx = &mem_categorization_ctxt {
|
||||
tcx: tcx, method_map: method_map
|
||||
};
|
||||
return mcx.cat_expr_unadjusted(expr);
|
||||
}
|
||||
|
||||
fn cat_expr_autoderefd(
|
||||
pub fn cat_expr_autoderefd(
|
||||
tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
expr: @ast::expr,
|
||||
|
@ -251,7 +249,7 @@ fn cat_expr_autoderefd(
|
|||
return mcx.cat_expr_autoderefd(expr, adj);
|
||||
}
|
||||
|
||||
fn cat_def(
|
||||
pub fn cat_def(
|
||||
tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
expr_id: ast::node_id,
|
||||
|
@ -265,7 +263,7 @@ fn cat_def(
|
|||
return mcx.cat_def(expr_id, expr_span, expr_ty, def);
|
||||
}
|
||||
|
||||
fn cat_variant<N: ast_node>(
|
||||
pub fn cat_variant<N: ast_node>(
|
||||
tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
arg: N,
|
||||
|
@ -278,37 +276,37 @@ fn cat_variant<N: ast_node>(
|
|||
return mcx.cat_variant(arg, enum_did, cmt);
|
||||
}
|
||||
|
||||
trait ast_node {
|
||||
pub trait ast_node {
|
||||
fn id() -> ast::node_id;
|
||||
fn span() -> span;
|
||||
}
|
||||
|
||||
impl @ast::expr: ast_node {
|
||||
pub impl @ast::expr: ast_node {
|
||||
fn id() -> ast::node_id { self.id }
|
||||
fn span() -> span { self.span }
|
||||
}
|
||||
|
||||
impl @ast::pat: ast_node {
|
||||
pub impl @ast::pat: ast_node {
|
||||
fn id() -> ast::node_id { self.id }
|
||||
fn span() -> span { self.span }
|
||||
}
|
||||
|
||||
trait get_type_for_node {
|
||||
pub trait get_type_for_node {
|
||||
fn ty<N: ast_node>(node: N) -> ty::t;
|
||||
}
|
||||
|
||||
impl ty::ctxt: get_type_for_node {
|
||||
pub impl ty::ctxt: get_type_for_node {
|
||||
fn ty<N: ast_node>(node: N) -> ty::t {
|
||||
ty::node_id_to_type(self, node.id())
|
||||
}
|
||||
}
|
||||
|
||||
struct mem_categorization_ctxt {
|
||||
pub struct mem_categorization_ctxt {
|
||||
tcx: ty::ctxt,
|
||||
method_map: typeck::method_map,
|
||||
}
|
||||
|
||||
impl &mem_categorization_ctxt {
|
||||
pub impl &mem_categorization_ctxt {
|
||||
fn cat_expr(expr: @ast::expr) -> cmt {
|
||||
match self.tcx.adjustments.find(expr.id) {
|
||||
None => {
|
||||
|
@ -1043,10 +1041,11 @@ impl &mem_categorization_ctxt {
|
|||
/// The node_id here is the node of the expression that references the field.
|
||||
/// This function looks it up in the def map in case the type happens to be
|
||||
/// an enum to determine which variant is in use.
|
||||
fn field_mutbl(tcx: ty::ctxt,
|
||||
base_ty: ty::t,
|
||||
f_name: ast::ident,
|
||||
node_id: ast::node_id) -> Option<ast::mutability> {
|
||||
pub fn field_mutbl(tcx: ty::ctxt,
|
||||
base_ty: ty::t,
|
||||
f_name: ast::ident,
|
||||
node_id: ast::node_id)
|
||||
-> Option<ast::mutability> {
|
||||
// Need to refactor so that records/class fields can be treated uniformly.
|
||||
match /*bad*/copy ty::get(base_ty).sty {
|
||||
ty::ty_rec(fields) => {
|
||||
|
@ -1089,7 +1088,7 @@ fn field_mutbl(tcx: ty::ctxt,
|
|||
return None;
|
||||
}
|
||||
|
||||
impl categorization {
|
||||
pub impl categorization {
|
||||
fn derefs_through_mutable_box(&const self) -> bool {
|
||||
match *self {
|
||||
cat_deref(_, _, gc_ptr(ast::m_mutbl)) => {
|
||||
|
|
|
@ -22,16 +22,11 @@ use syntax::fold::*;
|
|||
use syntax::codemap::span;
|
||||
use std::map::HashMap;
|
||||
|
||||
export pat_binding_ids, pat_bindings, pat_id_map, PatIdMap;
|
||||
export pat_is_variant_or_struct, pat_is_binding, pat_is_binding_or_wild;
|
||||
export pat_is_const;
|
||||
export arms_have_by_move_bindings;
|
||||
|
||||
type PatIdMap = HashMap<ident, node_id>;
|
||||
pub type PatIdMap = HashMap<ident, node_id>;
|
||||
|
||||
// This is used because same-named variables in alternative patterns need to
|
||||
// use the node_id of their namesake in the first pattern.
|
||||
fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap {
|
||||
pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap {
|
||||
let map = HashMap();
|
||||
do pat_bindings(dm, pat) |_bm, p_id, _s, n| {
|
||||
map.insert(path_to_ident(n), p_id);
|
||||
|
@ -39,7 +34,7 @@ fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap {
|
|||
return map;
|
||||
}
|
||||
|
||||
fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool {
|
||||
pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool {
|
||||
match pat.node {
|
||||
pat_enum(_, _) | pat_ident(_, _, None) | pat_struct(*) => {
|
||||
match dm.find(pat.id) {
|
||||
|
@ -51,7 +46,7 @@ fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool {
|
||||
pub fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool {
|
||||
match pat.node {
|
||||
pat_ident(_, _, None) => {
|
||||
match dm.find(pat.id) {
|
||||
|
@ -63,7 +58,7 @@ fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn pat_is_binding(dm: resolve::DefMap, pat: @pat) -> bool {
|
||||
pub fn pat_is_binding(dm: resolve::DefMap, pat: @pat) -> bool {
|
||||
match pat.node {
|
||||
pat_ident(*) => {
|
||||
!pat_is_variant_or_struct(dm, pat) &&
|
||||
|
@ -73,7 +68,7 @@ fn pat_is_binding(dm: resolve::DefMap, pat: @pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @pat) -> bool {
|
||||
pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @pat) -> bool {
|
||||
match pat.node {
|
||||
pat_ident(*) => pat_is_binding(dm, pat),
|
||||
pat_wild => true,
|
||||
|
@ -81,7 +76,7 @@ fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn pat_bindings(dm: resolve::DefMap, pat: @pat,
|
||||
pub fn pat_bindings(dm: resolve::DefMap, pat: @pat,
|
||||
it: fn(binding_mode, node_id, span, @path)) {
|
||||
do walk_pat(pat) |p| {
|
||||
match p.node {
|
||||
|
@ -93,13 +88,13 @@ fn pat_bindings(dm: resolve::DefMap, pat: @pat,
|
|||
}
|
||||
}
|
||||
|
||||
fn pat_binding_ids(dm: resolve::DefMap, pat: @pat) -> ~[node_id] {
|
||||
pub fn pat_binding_ids(dm: resolve::DefMap, pat: @pat) -> ~[node_id] {
|
||||
let mut found = ~[];
|
||||
pat_bindings(dm, pat, |_bm, b_id, _sp, _pt| found.push(b_id) );
|
||||
return found;
|
||||
}
|
||||
|
||||
fn arms_have_by_move_bindings(tcx: ty::ctxt, +arms: &[arm]) -> bool {
|
||||
pub fn arms_have_by_move_bindings(tcx: ty::ctxt, +arms: &[arm]) -> bool {
|
||||
for arms.each |arm| {
|
||||
for arm.pats.each |pat| {
|
||||
let mut found = false;
|
||||
|
|
|
@ -34,7 +34,9 @@ use syntax::ast_util::{visibility_to_privacy};
|
|||
use syntax::codemap::span;
|
||||
use syntax::visit;
|
||||
|
||||
fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
pub fn check_crate(tcx: ty::ctxt,
|
||||
method_map: &method_map,
|
||||
crate: @ast::crate) {
|
||||
let privileged_items = @DVec();
|
||||
let legacy_exports = has_legacy_export_attr(crate.node.attrs);
|
||||
|
||||
|
|
|
@ -38,12 +38,14 @@ use syntax::codemap::span;
|
|||
use syntax::print::pprust;
|
||||
use syntax::{ast, visit};
|
||||
|
||||
type parent = Option<ast::node_id>;
|
||||
pub type parent = Option<ast::node_id>;
|
||||
|
||||
/* Records the parameter ID of a region name. */
|
||||
type binding = {node_id: ast::node_id,
|
||||
name: ~str,
|
||||
br: ty::bound_region};
|
||||
pub type binding = {
|
||||
node_id: ast::node_id,
|
||||
name: ~str,
|
||||
br: ty::bound_region
|
||||
};
|
||||
|
||||
/**
|
||||
Encodes the bounding lifetime for a given AST node:
|
||||
|
@ -55,9 +57,9 @@ Encodes the bounding lifetime for a given AST node:
|
|||
- Variables and bindings are mapped to the block in which they are declared.
|
||||
|
||||
*/
|
||||
type region_map = HashMap<ast::node_id, ast::node_id>;
|
||||
pub type region_map = HashMap<ast::node_id, ast::node_id>;
|
||||
|
||||
struct ctxt {
|
||||
pub struct ctxt {
|
||||
sess: Session,
|
||||
def_map: resolve::DefMap,
|
||||
|
||||
|
@ -109,8 +111,8 @@ struct ctxt {
|
|||
|
||||
/// Returns true if `subscope` is equal to or is lexically nested inside
|
||||
/// `superscope` and false otherwise.
|
||||
fn scope_contains(region_map: region_map, superscope: ast::node_id,
|
||||
subscope: ast::node_id) -> bool {
|
||||
pub fn scope_contains(region_map: region_map, superscope: ast::node_id,
|
||||
subscope: ast::node_id) -> bool {
|
||||
let mut subscope = subscope;
|
||||
while superscope != subscope {
|
||||
match region_map.find(subscope) {
|
||||
|
@ -124,9 +126,9 @@ fn scope_contains(region_map: region_map, superscope: ast::node_id,
|
|||
/// Determines whether one region is a subregion of another. This is
|
||||
/// intended to run *after inference* and sadly the logic is somewhat
|
||||
/// duplicated with the code in infer.rs.
|
||||
fn is_subregion_of(region_map: region_map,
|
||||
sub_region: ty::Region,
|
||||
super_region: ty::Region) -> bool {
|
||||
pub fn is_subregion_of(region_map: region_map,
|
||||
sub_region: ty::Region,
|
||||
super_region: ty::Region) -> bool {
|
||||
sub_region == super_region ||
|
||||
match (sub_region, super_region) {
|
||||
(_, ty::re_static) => {
|
||||
|
@ -147,8 +149,10 @@ fn is_subregion_of(region_map: region_map,
|
|||
/// Finds the nearest common ancestor (if any) of two scopes. That
|
||||
/// is, finds the smallest scope which is greater than or equal to
|
||||
/// both `scope_a` and `scope_b`.
|
||||
fn nearest_common_ancestor(region_map: region_map, scope_a: ast::node_id,
|
||||
scope_b: ast::node_id) -> Option<ast::node_id> {
|
||||
pub fn nearest_common_ancestor(region_map: region_map,
|
||||
scope_a: ast::node_id,
|
||||
scope_b: ast::node_id)
|
||||
-> Option<ast::node_id> {
|
||||
|
||||
fn ancestors_of(region_map: region_map, scope: ast::node_id)
|
||||
-> ~[ast::node_id] {
|
||||
|
@ -198,7 +202,7 @@ fn nearest_common_ancestor(region_map: region_map, scope_a: ast::node_id,
|
|||
}
|
||||
|
||||
/// Extracts that current parent from cx, failing if there is none.
|
||||
fn parent_id(cx: ctxt, span: span) -> ast::node_id {
|
||||
pub fn parent_id(cx: ctxt, span: span) -> ast::node_id {
|
||||
match cx.parent {
|
||||
None => {
|
||||
cx.sess.span_bug(span, ~"crate should not be parent here");
|
||||
|
@ -210,14 +214,14 @@ fn parent_id(cx: ctxt, span: span) -> ast::node_id {
|
|||
}
|
||||
|
||||
/// Records the current parent (if any) as the parent of `child_id`.
|
||||
fn record_parent(cx: ctxt, child_id: ast::node_id) {
|
||||
pub fn record_parent(cx: ctxt, child_id: ast::node_id) {
|
||||
for cx.parent.each |parent_id| {
|
||||
debug!("parent of node %d is node %d", child_id, *parent_id);
|
||||
cx.region_map.insert(child_id, *parent_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
pub fn resolve_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
// Record the parent of this block.
|
||||
record_parent(cx, blk.node.id);
|
||||
|
||||
|
@ -226,11 +230,11 @@ fn resolve_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) {
|
|||
visit::visit_block(blk, new_cx, visitor);
|
||||
}
|
||||
|
||||
fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
pub fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
visit::visit_arm(arm, cx, visitor);
|
||||
}
|
||||
|
||||
fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
pub fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
match pat.node {
|
||||
ast::pat_ident(*) => {
|
||||
let defn_opt = cx.def_map.find(pat.id);
|
||||
|
@ -250,7 +254,7 @@ fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
|
|||
visit::visit_pat(pat, cx, visitor);
|
||||
}
|
||||
|
||||
fn resolve_stmt(stmt: @ast::stmt, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
pub fn resolve_stmt(stmt: @ast::stmt, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
match stmt.node {
|
||||
ast::stmt_decl(*) => {
|
||||
visit::visit_stmt(stmt, cx, visitor);
|
||||
|
@ -267,7 +271,7 @@ fn resolve_stmt(stmt: @ast::stmt, cx: ctxt, visitor: visit::vt<ctxt>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
pub fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
record_parent(cx, expr.id);
|
||||
|
||||
let mut new_cx = cx;
|
||||
|
@ -308,21 +312,26 @@ fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
|
|||
visit::visit_expr(expr, new_cx, visitor);
|
||||
}
|
||||
|
||||
fn resolve_local(local: @ast::local, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
pub fn resolve_local(local: @ast::local,
|
||||
cx: ctxt,
|
||||
visitor: visit::vt<ctxt>) {
|
||||
record_parent(cx, local.node.id);
|
||||
visit::visit_local(local, cx, visitor);
|
||||
}
|
||||
|
||||
fn resolve_item(item: @ast::item, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
pub fn resolve_item(item: @ast::item, cx: ctxt, visitor: visit::vt<ctxt>) {
|
||||
// Items create a new outer block scope as far as we're concerned.
|
||||
let new_cx: ctxt = ctxt {parent: None,.. cx};
|
||||
visit::visit_item(item, new_cx, visitor);
|
||||
}
|
||||
|
||||
fn resolve_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
|
||||
sp: span, id: ast::node_id, cx: ctxt,
|
||||
visitor: visit::vt<ctxt>) {
|
||||
|
||||
pub fn resolve_fn(fk: visit::fn_kind,
|
||||
decl: ast::fn_decl,
|
||||
body: ast::blk,
|
||||
sp: span,
|
||||
id: ast::node_id,
|
||||
cx: ctxt,
|
||||
visitor: visit::vt<ctxt>) {
|
||||
let fn_cx = match fk {
|
||||
visit::fk_item_fn(*) | visit::fk_method(*) |
|
||||
visit::fk_dtor(*) => {
|
||||
|
@ -355,8 +364,10 @@ fn resolve_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
|
|||
visit::visit_fn(fk, decl, body, sp, id, fn_cx, visitor);
|
||||
}
|
||||
|
||||
fn resolve_crate(sess: Session, def_map: resolve::DefMap,
|
||||
crate: @ast::crate) -> region_map {
|
||||
pub fn resolve_crate(sess: Session,
|
||||
def_map: resolve::DefMap,
|
||||
crate: @ast::crate)
|
||||
-> region_map {
|
||||
let cx: ctxt = ctxt {sess: sess,
|
||||
def_map: def_map,
|
||||
region_map: HashMap(),
|
||||
|
@ -396,17 +407,17 @@ fn resolve_crate(sess: Session, def_map: resolve::DefMap,
|
|||
// a worklist. We can then process the worklist, propagating indirect
|
||||
// dependencies until a fixed point is reached.
|
||||
|
||||
type region_paramd_items = HashMap<ast::node_id, region_variance>;
|
||||
pub type region_paramd_items = HashMap<ast::node_id, region_variance>;
|
||||
|
||||
#[deriving_eq]
|
||||
struct region_dep {
|
||||
pub struct region_dep {
|
||||
ambient_variance: region_variance,
|
||||
id: ast::node_id
|
||||
}
|
||||
|
||||
type dep_map = HashMap<ast::node_id, @DVec<region_dep>>;
|
||||
pub type dep_map = HashMap<ast::node_id, @DVec<region_dep>>;
|
||||
|
||||
type determine_rp_ctxt_ = {
|
||||
pub type determine_rp_ctxt_ = {
|
||||
sess: Session,
|
||||
ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
|
@ -426,12 +437,13 @@ type determine_rp_ctxt_ = {
|
|||
mut ambient_variance: region_variance,
|
||||
};
|
||||
|
||||
enum determine_rp_ctxt {
|
||||
pub enum determine_rp_ctxt {
|
||||
determine_rp_ctxt_(@determine_rp_ctxt_)
|
||||
}
|
||||
|
||||
fn join_variance(++variance1: region_variance,
|
||||
++variance2: region_variance) -> region_variance{
|
||||
pub fn join_variance(++variance1: region_variance,
|
||||
++variance2: region_variance)
|
||||
-> region_variance {
|
||||
match (variance1, variance2) {
|
||||
(rv_invariant, _) => {rv_invariant}
|
||||
(_, rv_invariant) => {rv_invariant}
|
||||
|
@ -450,8 +462,9 @@ fn join_variance(++variance1: region_variance,
|
|||
/// appears in a co-variant position. This implies that this
|
||||
/// occurrence of `r` is contra-variant with respect to the current
|
||||
/// item, and hence the function returns `rv_contravariant`.
|
||||
fn add_variance(+ambient_variance: region_variance,
|
||||
+variance: region_variance) -> region_variance {
|
||||
pub fn add_variance(+ambient_variance: region_variance,
|
||||
+variance: region_variance)
|
||||
-> region_variance {
|
||||
match (ambient_variance, variance) {
|
||||
(rv_invariant, _) => rv_invariant,
|
||||
(_, rv_invariant) => rv_invariant,
|
||||
|
@ -461,7 +474,7 @@ fn add_variance(+ambient_variance: region_variance,
|
|||
}
|
||||
}
|
||||
|
||||
impl determine_rp_ctxt {
|
||||
pub impl determine_rp_ctxt {
|
||||
fn add_variance(variance: region_variance) -> region_variance {
|
||||
add_variance(self.ambient_variance, variance)
|
||||
}
|
||||
|
@ -594,21 +607,21 @@ impl determine_rp_ctxt {
|
|||
}
|
||||
}
|
||||
|
||||
fn determine_rp_in_item(item: @ast::item,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
pub fn determine_rp_in_item(item: @ast::item,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
do cx.with(item.id, true) {
|
||||
visit::visit_item(item, cx, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_rp_in_fn(fk: visit::fn_kind,
|
||||
decl: ast::fn_decl,
|
||||
body: ast::blk,
|
||||
_sp: span,
|
||||
_id: ast::node_id,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
pub fn determine_rp_in_fn(fk: visit::fn_kind,
|
||||
decl: ast::fn_decl,
|
||||
body: ast::blk,
|
||||
_sp: span,
|
||||
_id: ast::node_id,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
do cx.with(cx.item_id, false) {
|
||||
do cx.with_ambient_variance(rv_contravariant) {
|
||||
for decl.inputs.each |a| {
|
||||
|
@ -621,18 +634,17 @@ fn determine_rp_in_fn(fk: visit::fn_kind,
|
|||
}
|
||||
}
|
||||
|
||||
fn determine_rp_in_ty_method(ty_m: ast::ty_method,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
pub fn determine_rp_in_ty_method(ty_m: ast::ty_method,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
do cx.with(cx.item_id, false) {
|
||||
visit::visit_ty_method(ty_m, cx, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_rp_in_ty(ty: @ast::Ty,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
|
||||
pub fn determine_rp_in_ty(ty: @ast::Ty,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
// we are only interested in types that will require an item to
|
||||
// be region-parameterized. if cx.item_id is zero, then this type
|
||||
// is not a member of a type defn nor is it a constitutent of an
|
||||
|
@ -762,9 +774,9 @@ fn determine_rp_in_ty(ty: @ast::Ty,
|
|||
}
|
||||
}
|
||||
|
||||
fn determine_rp_in_struct_field(cm: @ast::struct_field,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
pub fn determine_rp_in_struct_field(cm: @ast::struct_field,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
match cm.node.kind {
|
||||
ast::named_field(_, ast::struct_mutable, _) => {
|
||||
do cx.with_ambient_variance(rv_invariant) {
|
||||
|
@ -778,10 +790,11 @@ fn determine_rp_in_struct_field(cm: @ast::struct_field,
|
|||
}
|
||||
}
|
||||
|
||||
fn determine_rp_in_crate(sess: Session,
|
||||
ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
crate: @ast::crate) -> region_paramd_items {
|
||||
pub fn determine_rp_in_crate(sess: Session,
|
||||
ast_map: ast_map::map,
|
||||
def_map: resolve::DefMap,
|
||||
crate: @ast::crate)
|
||||
-> region_paramd_items {
|
||||
let cx = determine_rp_ctxt_(@{sess: sess,
|
||||
ast_map: ast_map,
|
||||
def_map: def_map,
|
||||
|
@ -842,3 +855,4 @@ fn determine_rp_in_crate(sess: Session,
|
|||
// return final set
|
||||
return cx.region_paramd_items;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,79 +83,51 @@ use std::map::HashMap;
|
|||
use str_eq = str::eq;
|
||||
|
||||
// Definition mapping
|
||||
type DefMap = HashMap<node_id,def>;
|
||||
pub type DefMap = HashMap<node_id,def>;
|
||||
|
||||
struct binding_info {
|
||||
pub struct binding_info {
|
||||
span: span,
|
||||
binding_mode: binding_mode,
|
||||
}
|
||||
|
||||
// Map from the name in a pattern to its binding mode.
|
||||
type BindingMap = HashMap<ident,binding_info>;
|
||||
pub type BindingMap = HashMap<ident,binding_info>;
|
||||
|
||||
// Implementation resolution
|
||||
//
|
||||
// XXX: This kind of duplicates information kept in ty::method. Maybe it
|
||||
// should go away.
|
||||
|
||||
type MethodInfo = {
|
||||
pub type MethodInfo = {
|
||||
did: def_id,
|
||||
n_tps: uint,
|
||||
ident: ident,
|
||||
self_type: self_ty_
|
||||
};
|
||||
|
||||
type Impl = { did: def_id, ident: ident, methods: ~[@MethodInfo] };
|
||||
pub type Impl = { did: def_id, ident: ident, methods: ~[@MethodInfo] };
|
||||
|
||||
// Trait method resolution
|
||||
type TraitMap = @HashMap<node_id,@DVec<def_id>>;
|
||||
pub type TraitMap = @HashMap<node_id,@DVec<def_id>>;
|
||||
|
||||
// This is the replacement export map. It maps a module to all of the exports
|
||||
// within.
|
||||
type ExportMap2 = HashMap<node_id, ~[Export2]>;
|
||||
pub type ExportMap2 = HashMap<node_id, ~[Export2]>;
|
||||
|
||||
struct Export2 {
|
||||
pub struct Export2 {
|
||||
name: ~str, // The name of the target.
|
||||
def_id: def_id, // The definition of the target.
|
||||
reexport: bool, // Whether this is a reexport.
|
||||
}
|
||||
|
||||
enum PatternBindingMode {
|
||||
#[deriving_eq]
|
||||
pub enum PatternBindingMode {
|
||||
RefutableMode,
|
||||
LocalIrrefutableMode,
|
||||
ArgumentIrrefutableMode(mode)
|
||||
}
|
||||
|
||||
impl PatternBindingMode : cmp::Eq {
|
||||
pure fn eq(&self, other: &PatternBindingMode) -> bool {
|
||||
match (*self) {
|
||||
RefutableMode => {
|
||||
match *other {
|
||||
RefutableMode => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
LocalIrrefutableMode => {
|
||||
match *other {
|
||||
LocalIrrefutableMode => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
ArgumentIrrefutableMode(mode_a) => {
|
||||
match *other {
|
||||
ArgumentIrrefutableMode(mode_b) => mode_a == mode_b,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pure fn ne(&self, other: &PatternBindingMode) -> bool {
|
||||
!(*self).eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum Namespace {
|
||||
pub enum Namespace {
|
||||
TypeNS,
|
||||
ValueNS
|
||||
}
|
||||
|
@ -163,7 +135,7 @@ enum Namespace {
|
|||
/// A NamespaceResult represents the result of resolving an import in
|
||||
/// a particular namespace. The result is either definitely-resolved,
|
||||
/// definitely- unresolved, or unknown.
|
||||
enum NamespaceResult {
|
||||
pub enum NamespaceResult {
|
||||
/// Means that resolve hasn't gathered enough information yet to determine
|
||||
/// whether the name is bound in this namespace. (That is, it hasn't
|
||||
/// resolved all `use` directives yet.)
|
||||
|
@ -176,7 +148,7 @@ enum NamespaceResult {
|
|||
BoundResult(@Module, @NameBindings)
|
||||
}
|
||||
|
||||
impl NamespaceResult {
|
||||
pub impl NamespaceResult {
|
||||
pure fn is_unknown() -> bool {
|
||||
match self {
|
||||
UnknownResult => true,
|
||||
|
@ -185,69 +157,55 @@ impl NamespaceResult {
|
|||
}
|
||||
}
|
||||
|
||||
enum NameDefinition {
|
||||
pub enum NameDefinition {
|
||||
NoNameDefinition, //< The name was unbound.
|
||||
ChildNameDefinition(def), //< The name identifies an immediate child.
|
||||
ImportNameDefinition(def) //< The name identifies an import.
|
||||
|
||||
}
|
||||
|
||||
enum Mutability {
|
||||
#[deriving_eq]
|
||||
pub enum Mutability {
|
||||
Mutable,
|
||||
Immutable
|
||||
}
|
||||
|
||||
impl Mutability : cmp::Eq {
|
||||
pure fn eq(&self, other: &Mutability) -> bool {
|
||||
((*self) as uint) == ((*other) as uint)
|
||||
}
|
||||
pure fn ne(&self, other: &Mutability) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
enum SelfBinding {
|
||||
pub enum SelfBinding {
|
||||
NoSelfBinding,
|
||||
HasSelfBinding(node_id, bool /* is implicit */)
|
||||
}
|
||||
|
||||
enum CaptureClause {
|
||||
pub enum CaptureClause {
|
||||
NoCaptureClause,
|
||||
HasCaptureClause(capture_clause)
|
||||
}
|
||||
|
||||
type ResolveVisitor = vt<()>;
|
||||
pub type ResolveVisitor = vt<()>;
|
||||
|
||||
enum ImportDirectiveNS {
|
||||
#[deriving_eq]
|
||||
pub enum ImportDirectiveNS {
|
||||
TypeNSOnly,
|
||||
AnyNS
|
||||
}
|
||||
|
||||
impl ImportDirectiveNS : cmp::Eq {
|
||||
pure fn eq(&self, other: &ImportDirectiveNS) -> bool {
|
||||
((*self) as uint) == ((*other) as uint)
|
||||
}
|
||||
pure fn ne(&self, other: &ImportDirectiveNS) -> bool {
|
||||
!(*self).eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains data for specific types of import directives.
|
||||
enum ImportDirectiveSubclass {
|
||||
pub enum ImportDirectiveSubclass {
|
||||
SingleImport(ident /* target */, ident /* source */, ImportDirectiveNS),
|
||||
GlobImport
|
||||
}
|
||||
|
||||
/// The context that we thread through while building the reduced graph.
|
||||
enum ReducedGraphParent {
|
||||
pub enum ReducedGraphParent {
|
||||
ModuleReducedGraphParent(@Module)
|
||||
}
|
||||
|
||||
enum ResolveResult<T> {
|
||||
pub enum ResolveResult<T> {
|
||||
Failed, // Failed to resolve the name.
|
||||
Indeterminate, // Couldn't determine due to unresolved globs.
|
||||
Success(T) // Successfully resolved the import.
|
||||
}
|
||||
|
||||
impl<T> ResolveResult<T> {
|
||||
pub impl<T> ResolveResult<T> {
|
||||
fn failed() -> bool {
|
||||
match self { Failed => true, _ => false }
|
||||
}
|
||||
|
@ -256,7 +214,7 @@ impl<T> ResolveResult<T> {
|
|||
}
|
||||
}
|
||||
|
||||
enum TypeParameters/& {
|
||||
pub enum TypeParameters/& {
|
||||
NoTypeParameters, //< No type parameters.
|
||||
HasTypeParameters(&~[ty_param], //< Type parameters.
|
||||
node_id, //< ID of the enclosing item
|
||||
|
@ -282,7 +240,7 @@ enum TypeParameters/& {
|
|||
// The rib kind controls the translation of argument or local definitions
|
||||
// (`def_arg` or `def_local`) to upvars (`def_upvar`).
|
||||
|
||||
enum RibKind {
|
||||
pub enum RibKind {
|
||||
// No translation needs to be applied.
|
||||
NormalRibKind,
|
||||
|
||||
|
@ -305,7 +263,7 @@ enum RibKind {
|
|||
}
|
||||
|
||||
// Methods can be required or provided. Required methods only occur in traits.
|
||||
enum MethodSort {
|
||||
pub enum MethodSort {
|
||||
Required,
|
||||
Provided(node_id)
|
||||
}
|
||||
|
@ -317,48 +275,34 @@ enum MethodSort {
|
|||
// XXX: The X-ray flag is kind of questionable in the first place. It might
|
||||
// be better to introduce an expr_xray_path instead.
|
||||
|
||||
enum XrayFlag {
|
||||
#[deriving_eq]
|
||||
pub enum XrayFlag {
|
||||
NoXray, //< Private items cannot be accessed.
|
||||
Xray //< Private items can be accessed.
|
||||
}
|
||||
|
||||
enum UseLexicalScopeFlag {
|
||||
pub enum UseLexicalScopeFlag {
|
||||
DontUseLexicalScope,
|
||||
UseLexicalScope
|
||||
}
|
||||
|
||||
enum SearchThroughModulesFlag {
|
||||
pub enum SearchThroughModulesFlag {
|
||||
DontSearchThroughModules,
|
||||
SearchThroughModules
|
||||
}
|
||||
|
||||
enum ModulePrefixResult {
|
||||
pub enum ModulePrefixResult {
|
||||
NoPrefixFound,
|
||||
PrefixFound(@Module, uint)
|
||||
}
|
||||
|
||||
impl XrayFlag : cmp::Eq {
|
||||
pure fn eq(&self, other: &XrayFlag) -> bool {
|
||||
((*self) as uint) == ((*other) as uint)
|
||||
}
|
||||
pure fn ne(&self, other: &XrayFlag) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
enum AllowCapturingSelfFlag {
|
||||
#[deriving_eq]
|
||||
pub enum AllowCapturingSelfFlag {
|
||||
AllowCapturingSelf, //< The "self" definition can be captured.
|
||||
DontAllowCapturingSelf, //< The "self" definition cannot be captured.
|
||||
}
|
||||
|
||||
impl AllowCapturingSelfFlag : cmp::Eq {
|
||||
pure fn eq(&self, other: &AllowCapturingSelfFlag) -> bool {
|
||||
((*self) as uint) == ((*other) as uint)
|
||||
}
|
||||
pure fn ne(&self, other: &AllowCapturingSelfFlag) -> bool {
|
||||
!(*self).eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
enum BareIdentifierPatternResolution {
|
||||
pub enum BareIdentifierPatternResolution {
|
||||
FoundStructOrEnumVariant(def),
|
||||
FoundConst(def),
|
||||
BareIdentifierPatternUnresolved
|
||||
|
@ -366,7 +310,8 @@ enum BareIdentifierPatternResolution {
|
|||
|
||||
// Specifies how duplicates should be handled when adding a child item if
|
||||
// another item exists with the same name in some namespace.
|
||||
enum DuplicateCheckingMode {
|
||||
#[deriving_eq]
|
||||
pub enum DuplicateCheckingMode {
|
||||
ForbidDuplicateModules,
|
||||
ForbidDuplicateTypes,
|
||||
ForbidDuplicateValues,
|
||||
|
@ -374,19 +319,10 @@ enum DuplicateCheckingMode {
|
|||
OverwriteDuplicates
|
||||
}
|
||||
|
||||
impl DuplicateCheckingMode : cmp::Eq {
|
||||
pure fn eq(&self, other: &DuplicateCheckingMode) -> bool {
|
||||
((*self) as uint) == (*other as uint)
|
||||
}
|
||||
pure fn ne(&self, other: &DuplicateCheckingMode) -> bool {
|
||||
!(*self).eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the namespace associated with the given duplicate checking mode,
|
||||
// or fails for OverwriteDuplicates. This is used for error messages.
|
||||
fn namespace_for_duplicate_checking_mode(mode: DuplicateCheckingMode) ->
|
||||
Namespace {
|
||||
pub fn namespace_for_duplicate_checking_mode(mode: DuplicateCheckingMode)
|
||||
-> Namespace {
|
||||
match mode {
|
||||
ForbidDuplicateModules | ForbidDuplicateTypes |
|
||||
ForbidDuplicateTypesAndValues => TypeNS,
|
||||
|
@ -396,12 +332,12 @@ fn namespace_for_duplicate_checking_mode(mode: DuplicateCheckingMode) ->
|
|||
}
|
||||
|
||||
/// One local scope.
|
||||
struct Rib {
|
||||
pub struct Rib {
|
||||
bindings: HashMap<ident,def_like>,
|
||||
kind: RibKind,
|
||||
}
|
||||
|
||||
fn Rib(kind: RibKind) -> Rib {
|
||||
pub fn Rib(kind: RibKind) -> Rib {
|
||||
Rib {
|
||||
bindings: HashMap(),
|
||||
kind: kind
|
||||
|
@ -410,17 +346,18 @@ fn Rib(kind: RibKind) -> Rib {
|
|||
|
||||
|
||||
/// One import directive.
|
||||
struct ImportDirective {
|
||||
pub struct ImportDirective {
|
||||
privacy: Privacy,
|
||||
module_path: @DVec<ident>,
|
||||
subclass: @ImportDirectiveSubclass,
|
||||
span: span,
|
||||
}
|
||||
|
||||
fn ImportDirective(privacy: Privacy,
|
||||
module_path: @DVec<ident>,
|
||||
subclass: @ImportDirectiveSubclass,
|
||||
span: span) -> ImportDirective {
|
||||
pub fn ImportDirective(privacy: Privacy,
|
||||
module_path: @DVec<ident>,
|
||||
subclass: @ImportDirectiveSubclass,
|
||||
span: span)
|
||||
-> ImportDirective {
|
||||
ImportDirective {
|
||||
privacy: privacy,
|
||||
module_path: module_path,
|
||||
|
@ -430,12 +367,12 @@ fn ImportDirective(privacy: Privacy,
|
|||
}
|
||||
|
||||
/// The item that an import resolves to.
|
||||
struct Target {
|
||||
pub struct Target {
|
||||
target_module: @Module,
|
||||
bindings: @NameBindings,
|
||||
}
|
||||
|
||||
fn Target(target_module: @Module, bindings: @NameBindings) -> Target {
|
||||
pub fn Target(target_module: @Module, bindings: @NameBindings) -> Target {
|
||||
Target {
|
||||
target_module: target_module,
|
||||
bindings: bindings
|
||||
|
@ -443,7 +380,7 @@ fn Target(target_module: @Module, bindings: @NameBindings) -> Target {
|
|||
}
|
||||
|
||||
/// An ImportResolution represents a particular `use` directive.
|
||||
struct ImportResolution {
|
||||
pub struct ImportResolution {
|
||||
/// The privacy of this `use` directive (whether it's `use` or
|
||||
/// `pub use`.
|
||||
privacy: Privacy,
|
||||
|
@ -463,7 +400,7 @@ struct ImportResolution {
|
|||
mut used: bool,
|
||||
}
|
||||
|
||||
fn ImportResolution(privacy: Privacy, span: span) -> ImportResolution {
|
||||
pub fn ImportResolution(privacy: Privacy, span: span) -> ImportResolution {
|
||||
ImportResolution {
|
||||
privacy: privacy,
|
||||
span: span,
|
||||
|
@ -474,7 +411,7 @@ fn ImportResolution(privacy: Privacy, span: span) -> ImportResolution {
|
|||
}
|
||||
}
|
||||
|
||||
impl ImportResolution {
|
||||
pub impl ImportResolution {
|
||||
fn target_for_namespace(namespace: Namespace) -> Option<Target> {
|
||||
match namespace {
|
||||
TypeNS => return copy self.type_target,
|
||||
|
@ -484,14 +421,14 @@ impl ImportResolution {
|
|||
}
|
||||
|
||||
/// The link from a module up to its nearest parent node.
|
||||
enum ParentLink {
|
||||
pub enum ParentLink {
|
||||
NoParentLink,
|
||||
ModuleParentLink(@Module, ident),
|
||||
BlockParentLink(@Module, node_id)
|
||||
}
|
||||
|
||||
/// The type of module this is.
|
||||
enum ModuleKind {
|
||||
pub enum ModuleKind {
|
||||
NormalModuleKind,
|
||||
ExternModuleKind,
|
||||
TraitModuleKind,
|
||||
|
@ -499,7 +436,7 @@ enum ModuleKind {
|
|||
}
|
||||
|
||||
/// One node in the tree of modules.
|
||||
struct Module {
|
||||
pub struct Module {
|
||||
parent_link: ParentLink,
|
||||
mut def_id: Option<def_id>,
|
||||
kind: ModuleKind,
|
||||
|
@ -549,10 +486,11 @@ struct Module {
|
|||
mut resolved_import_count: uint,
|
||||
}
|
||||
|
||||
fn Module(parent_link: ParentLink,
|
||||
def_id: Option<def_id>,
|
||||
kind: ModuleKind,
|
||||
legacy_exports: bool) -> Module {
|
||||
pub fn Module(parent_link: ParentLink,
|
||||
def_id: Option<def_id>,
|
||||
kind: ModuleKind,
|
||||
legacy_exports: bool)
|
||||
-> Module {
|
||||
Module {
|
||||
parent_link: parent_link,
|
||||
def_id: def_id,
|
||||
|
@ -568,13 +506,13 @@ fn Module(parent_link: ParentLink,
|
|||
}
|
||||
}
|
||||
|
||||
impl Module {
|
||||
pub impl Module {
|
||||
fn all_imports_resolved() -> bool {
|
||||
return self.imports.len() == self.resolved_import_count;
|
||||
}
|
||||
}
|
||||
|
||||
fn unused_import_lint_level(session: Session) -> level {
|
||||
pub fn unused_import_lint_level(session: Session) -> level {
|
||||
for session.opts.lint_opts.each |lint_option_pair| {
|
||||
let (lint_type, lint_level) = *lint_option_pair;
|
||||
if lint_type == unused_imports {
|
||||
|
@ -585,21 +523,21 @@ fn unused_import_lint_level(session: Session) -> level {
|
|||
}
|
||||
|
||||
// Records a possibly-private type definition.
|
||||
struct TypeNsDef {
|
||||
pub struct TypeNsDef {
|
||||
mut privacy: Privacy,
|
||||
mut module_def: Option<@Module>,
|
||||
mut type_def: Option<def>
|
||||
}
|
||||
|
||||
// Records a possibly-private value definition.
|
||||
struct ValueNsDef {
|
||||
pub struct ValueNsDef {
|
||||
privacy: Privacy,
|
||||
def: def,
|
||||
}
|
||||
|
||||
// Records the definitions (at most one for each namespace) that a name is
|
||||
// bound to.
|
||||
struct NameBindings {
|
||||
pub struct NameBindings {
|
||||
mut type_def: Option<TypeNsDef>, //< Meaning in type namespace.
|
||||
mut value_def: Option<ValueNsDef>, //< Meaning in value namespace.
|
||||
|
||||
|
@ -609,8 +547,7 @@ struct NameBindings {
|
|||
mut value_span: Option<span>,
|
||||
}
|
||||
|
||||
impl NameBindings {
|
||||
|
||||
pub impl NameBindings {
|
||||
/// Creates a new module in this set of name bindings.
|
||||
fn define_module(privacy: Privacy,
|
||||
parent_link: ParentLink,
|
||||
|
@ -758,7 +695,7 @@ impl NameBindings {
|
|||
}
|
||||
}
|
||||
|
||||
fn NameBindings() -> NameBindings {
|
||||
pub fn NameBindings() -> NameBindings {
|
||||
NameBindings {
|
||||
type_def: None,
|
||||
value_def: None,
|
||||
|
@ -767,13 +704,12 @@ fn NameBindings() -> NameBindings {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Interns the names of the primitive types.
|
||||
struct PrimitiveTypeTable {
|
||||
pub struct PrimitiveTypeTable {
|
||||
primitive_types: HashMap<ident,prim_ty>,
|
||||
}
|
||||
|
||||
impl PrimitiveTypeTable {
|
||||
pub impl PrimitiveTypeTable {
|
||||
fn intern(intr: @ident_interner, string: @~str,
|
||||
primitive_type: prim_ty) {
|
||||
let ident = intr.intern(string);
|
||||
|
@ -781,7 +717,7 @@ impl PrimitiveTypeTable {
|
|||
}
|
||||
}
|
||||
|
||||
fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
|
||||
pub fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
|
||||
let table = PrimitiveTypeTable {
|
||||
primitive_types: HashMap()
|
||||
};
|
||||
|
@ -807,15 +743,17 @@ fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
|
|||
}
|
||||
|
||||
|
||||
fn namespace_to_str(ns: Namespace) -> ~str {
|
||||
pub fn namespace_to_str(ns: Namespace) -> ~str {
|
||||
match ns {
|
||||
TypeNS => ~"type",
|
||||
ValueNS => ~"value",
|
||||
}
|
||||
}
|
||||
|
||||
fn Resolver(session: Session, lang_items: LanguageItems,
|
||||
crate: @crate) -> Resolver {
|
||||
pub fn Resolver(session: Session,
|
||||
lang_items: LanguageItems,
|
||||
crate: @crate)
|
||||
-> Resolver {
|
||||
let graph_root = @NameBindings();
|
||||
|
||||
(*graph_root).define_module(Public,
|
||||
|
@ -874,7 +812,7 @@ fn Resolver(session: Session, lang_items: LanguageItems,
|
|||
}
|
||||
|
||||
/// The main resolver class.
|
||||
struct Resolver {
|
||||
pub struct Resolver {
|
||||
session: Session,
|
||||
lang_items: LanguageItems,
|
||||
crate: @crate,
|
||||
|
@ -932,8 +870,7 @@ struct Resolver {
|
|||
trait_map: TraitMap,
|
||||
}
|
||||
|
||||
impl Resolver {
|
||||
|
||||
pub impl Resolver {
|
||||
/// The main name resolution procedure.
|
||||
fn resolve(@self, this: @Resolver) {
|
||||
self.build_reduced_graph(this);
|
||||
|
@ -5576,11 +5513,14 @@ impl Resolver {
|
|||
}
|
||||
|
||||
/// Entry point to crate resolution.
|
||||
fn resolve_crate(session: Session, lang_items: LanguageItems, crate: @crate)
|
||||
-> { def_map: DefMap,
|
||||
exp_map2: ExportMap2,
|
||||
trait_map: TraitMap } {
|
||||
|
||||
pub fn resolve_crate(session: Session,
|
||||
lang_items: LanguageItems,
|
||||
crate: @crate)
|
||||
-> {
|
||||
def_map: DefMap,
|
||||
exp_map2: ExportMap2,
|
||||
trait_map: TraitMap
|
||||
} {
|
||||
let resolver = @Resolver(session, lang_items, crate);
|
||||
resolver.resolve(resolver);
|
||||
return {
|
||||
|
|
|
@ -171,14 +171,16 @@ fn md_from_metadata<T>(val: debug_metadata) -> T {
|
|||
}
|
||||
}
|
||||
|
||||
fn cached_metadata<T: Copy>(cache: metadata_cache, mdtag: int,
|
||||
eq: fn(md: T) -> bool) -> Option<T> {
|
||||
fn cached_metadata<T: Copy>(cache: metadata_cache,
|
||||
mdtag: int,
|
||||
eq_fn: fn(md: T) -> bool)
|
||||
-> Option<T> {
|
||||
unsafe {
|
||||
if cache.contains_key(mdtag) {
|
||||
let items = cache.get(mdtag);
|
||||
for items.each |item| {
|
||||
let md: T = md_from_metadata::<T>(*item);
|
||||
if eq(md) {
|
||||
if eq_fn(md) {
|
||||
return option::Some(md);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1272,12 +1272,12 @@ fn trans_unary_datum(bcx: block,
|
|||
contents_ty: ty::t,
|
||||
heap: heap) -> DatumBlock {
|
||||
let _icx = bcx.insn_ctxt("trans_boxed_expr");
|
||||
let {bcx, box, body} =
|
||||
let {bcx, box: bx, body} =
|
||||
base::malloc_general(bcx, contents_ty, heap);
|
||||
add_clean_free(bcx, box, heap);
|
||||
add_clean_free(bcx, bx, heap);
|
||||
let bcx = trans_into(bcx, contents, SaveIn(body));
|
||||
revoke_clean(bcx, box);
|
||||
return immediate_rvalue_bcx(bcx, box, box_ty);
|
||||
revoke_clean(bcx, bx);
|
||||
return immediate_rvalue_bcx(bcx, bx, box_ty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,11 +81,11 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
|
|||
let vecbodyty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
|
||||
let vecsize = Add(bcx, alloc, llsize_of(ccx, ccx.opaque_vec_type));
|
||||
|
||||
let {bcx, box, body} =
|
||||
let {bcx, box: bx, body} =
|
||||
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
|
||||
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
|
||||
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
|
||||
return rslt(bcx, box);
|
||||
return rslt(bcx, bx);
|
||||
}
|
||||
pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
|
||||
fill: ValueRef, alloc: ValueRef) -> Result {
|
||||
|
@ -243,7 +243,7 @@ pub fn trans_slice_vstore(bcx: block,
|
|||
|
||||
pub fn trans_lit_str(bcx: block,
|
||||
lit_expr: @ast::expr,
|
||||
lit_str: @~str,
|
||||
str_lit: @~str,
|
||||
dest: Dest)
|
||||
-> block {
|
||||
//!
|
||||
|
@ -261,9 +261,9 @@ pub fn trans_lit_str(bcx: block,
|
|||
Ignore => bcx,
|
||||
SaveIn(lldest) => {
|
||||
unsafe {
|
||||
let bytes = lit_str.len() + 1; // count null-terminator too
|
||||
let bytes = str_lit.len() + 1; // count null-terminator too
|
||||
let llbytes = C_uint(bcx.ccx(), bytes);
|
||||
let llcstr = C_cstr(bcx.ccx(), /*bad*/copy *lit_str);
|
||||
let llcstr = C_cstr(bcx.ccx(), /*bad*/copy *str_lit);
|
||||
let llcstr = llvm::LLVMConstPointerCast(llcstr,
|
||||
T_ptr(T_i8()));
|
||||
Store(bcx,
|
||||
|
|
|
@ -20,16 +20,6 @@ use util::ppaux;
|
|||
use std::map::HashMap;
|
||||
use syntax::ast;
|
||||
|
||||
export type_of;
|
||||
export type_of_dtor;
|
||||
export type_of_explicit_arg;
|
||||
export type_of_explicit_args;
|
||||
export type_of_fn_from_ty;
|
||||
export type_of_fn;
|
||||
export type_of_glue_fn;
|
||||
export type_of_non_gc_box;
|
||||
export type_of_rooted;
|
||||
|
||||
pub fn type_of_explicit_arg(ccx: @crate_ctxt, arg: ty::arg) -> TypeRef {
|
||||
let llty = type_of(ccx, arg.ty);
|
||||
match ty::resolved_mode(ccx.tcx, arg.mode) {
|
||||
|
|
|
@ -78,41 +78,25 @@ pub mod middle {
|
|||
pub mod machine;
|
||||
}
|
||||
pub mod ty;
|
||||
#[legacy_exports]
|
||||
pub mod resolve;
|
||||
#[path = "typeck/mod.rs"]
|
||||
pub mod typeck;
|
||||
#[legacy_exports]
|
||||
pub mod check_loop;
|
||||
#[legacy_exports]
|
||||
pub mod check_match;
|
||||
#[legacy_exports]
|
||||
pub mod check_const;
|
||||
#[legacy_exports]
|
||||
pub mod lint;
|
||||
#[path = "borrowck/mod.rs"]
|
||||
pub mod borrowck;
|
||||
#[legacy_exports]
|
||||
pub mod mem_categorization;
|
||||
#[legacy_exports]
|
||||
pub mod liveness;
|
||||
#[legacy_exports]
|
||||
pub mod kind;
|
||||
#[legacy_exports]
|
||||
pub mod freevars;
|
||||
#[legacy_exports]
|
||||
pub mod capture;
|
||||
#[legacy_exports]
|
||||
pub mod pat_util;
|
||||
#[legacy_exports]
|
||||
pub mod region;
|
||||
#[legacy_exports]
|
||||
pub mod const_eval;
|
||||
#[legacy_exports]
|
||||
pub mod astencode;
|
||||
#[legacy_exports]
|
||||
pub mod lang_items;
|
||||
#[legacy_exports]
|
||||
pub mod privacy;
|
||||
pub mod mode;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue