rustc: Fix cross-crate max/min-class-style constructors

This commit is contained in:
Patrick Walton 2012-07-26 15:29:33 -07:00
parent 5cf99c585a
commit afd9a75c9e
12 changed files with 40 additions and 22 deletions

View File

@ -87,7 +87,7 @@ enum def {
def_upvar(node_id /* local id of closed over var */,
@def /* closed over def */,
node_id /* expr node that creates the closure */),
def_class(def_id),
def_class(def_id, bool /* has constructor */),
def_region(node_id)
}

View File

@ -53,7 +53,7 @@ pure fn def_id_of_def(d: def) -> def_id {
def_fn(id, _) | def_mod(id) |
def_foreign_mod(id) | def_const(id) |
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
def_use(id) | def_class(id) { id }
def_use(id) | def_class(id, _) { id }
def_arg(id, _) | def_local(id, _) | def_self(id) |
def_upvar(id, _, _) | def_binding(id) | def_region(id) {
local_def(id)

View File

@ -283,7 +283,8 @@ fn item_to_def_like(item: ebml::doc, did: ast::def_id, cnum: ast::crate_num)
let fam_ch = item_family(item);
alt fam_ch {
'c' { dl_def(ast::def_const(did)) }
'C' { dl_def(ast::def_class(did)) }
'C' { dl_def(ast::def_class(did, true)) }
'S' { dl_def(ast::def_class(did, false)) }
'u' { dl_def(ast::def_fn(did, ast::unsafe_fn)) }
'f' { dl_def(ast::def_fn(did, ast::impure_fn)) }
'p' { dl_def(ast::def_fn(did, ast::pure_fn)) }
@ -707,7 +708,7 @@ fn family_has_type_params(fam_ch: char) -> bool {
alt check fam_ch {
'c' | 'T' | 'm' | 'n' | 'g' | 'h' | 'j' { false }
'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' | 'C'
| 'a'
| 'a' | 'S'
{ true }
}
}
@ -751,6 +752,7 @@ fn item_family_to_str(fam: char) -> ~str {
'i' { ret ~"impl"; }
'I' { ret ~"trait"; }
'C' { ret ~"class"; }
'S' { ret ~"struct"; }
'g' { ret ~"public field"; }
'j' { ret ~"private field"; }
}

View File

@ -663,7 +663,16 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
/* Now, make an item for the class itself */
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_family(ebml_w, 'C');
alt ctor {
none {
encode_family(ebml_w, 'S');
}
some(_) {
encode_family(ebml_w, 'C');
}
}
encode_type_param_bounds(ebml_w, ecx, tps);
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_name(ebml_w, item.ident);

View File

@ -369,8 +369,8 @@ impl of tr for ast::def {
ast::def_upvar(nid1, def, nid2) {
ast::def_upvar(xcx.tr_id(nid1), @(*def).tr(xcx), xcx.tr_id(nid2))
}
ast::def_class(did) {
ast::def_class(did.tr(xcx))
ast::def_class(did, has_constructor) {
ast::def_class(did.tr(xcx), has_constructor)
}
ast::def_region(nid) { ast::def_region(xcx.tr_id(nid)) }
}

View File

@ -196,7 +196,7 @@ impl public_methods for borrowck_ctxt {
ast::def_foreign_mod(_) | ast::def_const(_) |
ast::def_use(_) | ast::def_variant(_, _) |
ast::def_ty(_) | ast::def_prim_ty(_) |
ast::def_ty_param(_, _) | ast::def_class(_) |
ast::def_ty_param(_, _) | ast::def_class(_, _) |
ast::def_region(_) {
@{id:id, span:span,
cat:cat_special(sk_static_item), lp:none,

View File

@ -467,7 +467,7 @@ fn determine_rp_in_ty(ty: @ast::ty,
alt ty.node {
ast::ty_path(_, id) {
alt cx.def_map.get(id) {
ast::def_ty(did) | ast::def_class(did) {
ast::def_ty(did) | ast::def_class(did, _) {
if did.crate == ast::local_crate {
cx.add_dep(did.node, cx.item_id);
} else {

View File

@ -41,7 +41,7 @@ import syntax::visit::{visit_mod, visit_ty, vt};
import box::ptr_eq;
import dvec::{dvec, extensions};
import option::get;
import option::{get, is_some};
import str::{connect, split_str};
import vec::pop;
@ -604,7 +604,7 @@ class Resolver {
let unused_import_lint_level: level;
let trait_info: hashmap<def_id,@hashmap<Atom,()>>;
let structs: hashmap<def_id,()>;
let structs: hashmap<def_id,bool>;
// The number of imports that are currently unresolved.
let mut unresolved_imports: uint;
@ -926,7 +926,8 @@ class Resolver {
(*name_bindings).define_impl(impl_info);
// Record the def ID of this struct.
self.structs.insert(local_def(item.id), ());
self.structs.insert(local_def(item.id),
is_some(optional_ctor));
visit_item(item, new_parent, visitor);
}
@ -1378,12 +1379,16 @@ class Resolver {
(*child_name_bindings).define_type(def);
}
def_class(def_id) {
def_class(def_id, has_constructor) {
#debug("(building reduced graph for external \
crate) building value and type %s",
final_ident);
(*child_name_bindings).define_value(def);
crate) building type %s (value? %d)",
final_ident,
if has_constructor { 1 } else { 0 });
(*child_name_bindings).define_type(def);
if has_constructor {
(*child_name_bindings).define_value(def);
}
}
def_self(*) | def_arg(*) | def_local(*) |
def_prim_ty(*) | def_ty_param(*) | def_binding(*) |
@ -4201,7 +4206,9 @@ class Resolver {
some(definition @ def_ty(class_id))
if self.structs.contains_key(class_id) {
self.record_def(expr.id, def_class(class_id));
let has_constructor = self.structs.get(class_id);
let class_def = def_class(class_id, has_constructor);
self.record_def(expr.id, class_def);
}
_ {
self.session.span_err(path.span,

View File

@ -2587,7 +2587,7 @@ fn type_err_to_str(cx: ctxt, err: type_err) -> ~str {
fn def_has_ty_params(def: ast::def) -> bool {
alt def {
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_)
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_, _)
{ true }
_ { false }
}

View File

@ -270,7 +270,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>(
path_to_str(path))); }
some(d) { d }};
alt a_def {
ast::def_ty(did) | ast::def_class(did) {
ast::def_ty(did) | ast::def_class(did, _) {
ast_path_to_ty(self, rscope, did, path, id).ty
}
ast::def_prim_ty(nty) {

View File

@ -1649,7 +1649,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
// Resolve the path.
let class_id;
alt tcx.def_map.find(id) {
some(ast::def_class(type_def_id)) => {
some(ast::def_class(type_def_id, _)) => {
class_id = type_def_id;
}
_ => {
@ -2160,7 +2160,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
}
ast::def_fn(id, _) | ast::def_const(id) |
ast::def_variant(_, id) | ast::def_class(id) {
ast::def_variant(_, id) | ast::def_class(id, _) {
ret ty::lookup_item_type(fcx.ccx.tcx, id);
}
ast::def_binding(nid) {

View File

@ -200,7 +200,7 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
ast::def_foreign_mod(_) | ast::def_const(_) |
ast::def_use(_) | ast::def_variant(_, _) |
ast::def_ty(_) | ast::def_prim_ty(_) |
ast::def_ty_param(_, _) | ast::def_class(_) |
ast::def_ty_param(_, _) | ast::def_class(_, _) |
ast::def_region(_) {
ty::re_static
}