Accept prefix notation for writing the types of str/~ and friends.
This commit is contained in:
@@ -291,14 +291,14 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
|
||||
sha: sha1) -> link_meta {
|
||||
|
||||
type provided_metas =
|
||||
{name: option<@str>,
|
||||
vers: option<@str>,
|
||||
{name: option<@str/~>,
|
||||
vers: option<@str/~>,
|
||||
cmh_items: ~[@ast::meta_item]};
|
||||
|
||||
fn provided_link_metas(sess: session, c: ast::crate) ->
|
||||
provided_metas {
|
||||
let mut name: option<@str> = none;
|
||||
let mut vers: option<@str> = none;
|
||||
let mut name: option<@str/~> = none;
|
||||
let mut vers: option<@str/~> = none;
|
||||
let mut cmh_items: ~[@ast::meta_item] = ~[];
|
||||
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
|
||||
attr::require_unique_names(sess.diagnostic(), linkage_metas);
|
||||
@@ -321,7 +321,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
|
||||
// This calculates CMH as defined above
|
||||
fn crate_meta_extras_hash(sha: sha1, _crate: ast::crate,
|
||||
metas: provided_metas,
|
||||
dep_hashes: ~[@str]) -> str {
|
||||
dep_hashes: ~[@str/~]) -> str {
|
||||
fn len_and_str(s: str) -> str {
|
||||
ret #fmt["%u_%s", str::len(s), s];
|
||||
}
|
||||
@@ -362,7 +362,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
|
||||
}
|
||||
|
||||
fn crate_meta_name(sess: session, _crate: ast::crate,
|
||||
output: str, metas: provided_metas) -> @str {
|
||||
output: str, metas: provided_metas) -> @str/~ {
|
||||
ret alt metas.name {
|
||||
some(v) { v }
|
||||
none {
|
||||
@@ -384,7 +384,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
|
||||
}
|
||||
|
||||
fn crate_meta_vers(sess: session, _crate: ast::crate,
|
||||
metas: provided_metas) -> @str {
|
||||
metas: provided_metas) -> @str/~ {
|
||||
ret alt metas.vers {
|
||||
some(v) { v }
|
||||
none {
|
||||
@@ -490,7 +490,7 @@ fn mangle(ss: path) -> str {
|
||||
n
|
||||
}
|
||||
|
||||
fn exported_name(path: path, hash: @str, vers: @str) -> str {
|
||||
fn exported_name(path: path, hash: @str/~, vers: @str/~) -> str {
|
||||
ret mangle(
|
||||
vec::append_one(vec::append_one(path, path_name(hash)),
|
||||
path_name(vers)));
|
||||
@@ -502,7 +502,7 @@ fn mangle_exported_name(ccx: @crate_ctxt, path: path, t: ty::t) -> str {
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_type_only(ccx: @crate_ctxt,
|
||||
t: ty::t, name: @str) ->
|
||||
t: ty::t, name: @str/~) ->
|
||||
str {
|
||||
let s = @util::ppaux::ty_to_short_str(ccx.tcx, t);
|
||||
let hash = get_symbol_hash(ccx, t);
|
||||
@@ -510,7 +510,7 @@ fn mangle_internal_name_by_type_only(ccx: @crate_ctxt,
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_path_and_seq(ccx: @crate_ctxt, path: path,
|
||||
flav: @str) -> str {
|
||||
flav: @str/~) -> str {
|
||||
ret mangle(vec::append_one(path, path_name(@ccx.names(*flav))));
|
||||
}
|
||||
|
||||
@@ -518,7 +518,7 @@ fn mangle_internal_name_by_path(_ccx: @crate_ctxt, path: path) -> str {
|
||||
ret mangle(path);
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: @str) -> str {
|
||||
fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: @str/~) -> str {
|
||||
ret ccx.names(*flav);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,5 +133,5 @@ fn hash_path(&&s: str) -> uint {
|
||||
ret h;
|
||||
}
|
||||
|
||||
type link_meta = {name: @str, vers: @str, extras_hash: str};
|
||||
type link_meta = {name: @str/~, vers: @str/~, extras_hash: str};
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ fn read_crates(diag: span_handler, crate: ast::crate,
|
||||
type cache_entry = {
|
||||
cnum: int,
|
||||
span: span,
|
||||
hash: @str,
|
||||
hash: @str/~,
|
||||
metas: @~[@ast::meta_item]
|
||||
};
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ type cnum_map = map::hashmap<ast::crate_num, ast::crate_num>;
|
||||
// Multiple items may have the same def_id in crate metadata. They may be
|
||||
// renamed imports or reexports. This map keeps the "real" module path
|
||||
// and def_id.
|
||||
type mod_path_map = map::hashmap<ast::def_id, @str>;
|
||||
type mod_path_map = map::hashmap<ast::def_id, @str/~>;
|
||||
|
||||
type crate_metadata = @{name: str,
|
||||
data: @~[u8],
|
||||
@@ -83,12 +83,12 @@ fn get_crate_data(cstore: cstore, cnum: ast::crate_num) -> crate_metadata {
|
||||
ret p(cstore).metas.get(cnum);
|
||||
}
|
||||
|
||||
fn get_crate_hash(cstore: cstore, cnum: ast::crate_num) -> @str {
|
||||
fn get_crate_hash(cstore: cstore, cnum: ast::crate_num) -> @str/~ {
|
||||
let cdata = get_crate_data(cstore, cnum);
|
||||
ret decoder::get_crate_hash(cdata.data);
|
||||
}
|
||||
|
||||
fn get_crate_vers(cstore: cstore, cnum: ast::crate_num) -> @str {
|
||||
fn get_crate_vers(cstore: cstore, cnum: ast::crate_num) -> @str/~ {
|
||||
let cdata = get_crate_data(cstore, cnum);
|
||||
ret decoder::get_crate_vers(cdata.data);
|
||||
}
|
||||
@@ -153,8 +153,8 @@ fn find_use_stmt_cnum(cstore: cstore,
|
||||
|
||||
// returns hashes of crates directly used by this crate. Hashes are
|
||||
// sorted by crate name.
|
||||
fn get_dep_hashes(cstore: cstore) -> ~[@str] {
|
||||
type crate_hash = {name: @str, hash: @str};
|
||||
fn get_dep_hashes(cstore: cstore) -> ~[@str/~] {
|
||||
type crate_hash = {name: @str/~, hash: @str/~};
|
||||
let mut result = ~[];
|
||||
|
||||
for p(cstore).use_crate_map.each_value |cnum| {
|
||||
@@ -171,7 +171,7 @@ fn get_dep_hashes(cstore: cstore) -> ~[@str] {
|
||||
for sorted.each |x| {
|
||||
#debug(" hash[%s]: %s", *x.name, *x.hash);
|
||||
}
|
||||
fn mapper(ch: crate_hash) -> @str { ret ch.hash; }
|
||||
fn mapper(ch: crate_hash) -> @str/~ { ret ch.hash; }
|
||||
ret vec::map(sorted, mapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -775,7 +775,7 @@ fn list_meta_items(meta_items: ebml::doc, out: io::writer) {
|
||||
}
|
||||
}
|
||||
|
||||
fn list_crate_attributes(md: ebml::doc, hash: @str, out: io::writer) {
|
||||
fn list_crate_attributes(md: ebml::doc, hash: @str/~, out: io::writer) {
|
||||
out.write_str(#fmt("=Crate Attributes (%s)=\n", *hash));
|
||||
|
||||
for get_attributes(md).each |attr| {
|
||||
@@ -790,7 +790,7 @@ fn get_crate_attributes(data: @~[u8]) -> ~[ast::attribute] {
|
||||
}
|
||||
|
||||
type crate_dep = {cnum: ast::crate_num, name: ast::ident,
|
||||
vers: @str, hash: @str};
|
||||
vers: @str/~, hash: @str/~};
|
||||
|
||||
fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
|
||||
let mut deps: ~[crate_dep] = ~[];
|
||||
@@ -821,13 +821,13 @@ fn list_crate_deps(data: @~[u8], out: io::writer) {
|
||||
out.write_str("\n");
|
||||
}
|
||||
|
||||
fn get_crate_hash(data: @~[u8]) -> @str {
|
||||
fn get_crate_hash(data: @~[u8]) -> @str/~ {
|
||||
let cratedoc = ebml::doc(data);
|
||||
let hashdoc = ebml::get_doc(cratedoc, tag_crate_hash);
|
||||
ret @str::from_bytes(ebml::doc_data(hashdoc));
|
||||
}
|
||||
|
||||
fn get_crate_vers(data: @~[u8]) -> @str {
|
||||
fn get_crate_vers(data: @~[u8]) -> @str/~ {
|
||||
let attrs = decoder::get_crate_attributes(data);
|
||||
ret alt attr::last_meta_item_value_str_by_name(
|
||||
attr::find_linkage_metas(attrs), "vers") {
|
||||
|
||||
@@ -116,7 +116,7 @@ fn find_library_crate_aux(cx: ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
fn crate_name_from_metas(metas: ~[@ast::meta_item]) -> @str {
|
||||
fn crate_name_from_metas(metas: ~[@ast::meta_item]) -> @str/~ {
|
||||
let name_items = attr::find_meta_items_by_name(metas, "name");
|
||||
alt vec::last_opt(name_items) {
|
||||
some(i) {
|
||||
|
||||
@@ -29,7 +29,7 @@ type ctxt = {
|
||||
// Compact string representation for ty.t values. API ty_str & parse_from_str.
|
||||
// Extra parameters are for converting to/from def_ids in the string rep.
|
||||
// Whatever format you choose should not contain pipe characters.
|
||||
type ty_abbrev = {pos: uint, len: uint, s: @str};
|
||||
type ty_abbrev = {pos: uint, len: uint, s: @str/~};
|
||||
|
||||
enum abbrev_ctxt { ac_no_abbrevs, ac_use_abbrevs(hashmap<ty::t, ty_abbrev>), }
|
||||
|
||||
|
||||
@@ -462,7 +462,10 @@ fn check_item_old_vecs(cx: ty::ctxt, it: @ast::item) {
|
||||
old_strs, t.id, it.id,
|
||||
t.span, "deprecated str type");
|
||||
}
|
||||
ast::ty_vstore(inner, _) {
|
||||
ast::ty_vstore(inner, _) |
|
||||
ast::ty_box({ty: inner, _}) |
|
||||
ast::ty_uniq({ty: inner, _}) |
|
||||
ast::ty_rptr(_, {ty: inner, _}) {
|
||||
uses_vstore.insert(inner.id, true);
|
||||
}
|
||||
_ { }
|
||||
|
||||
@@ -202,18 +202,18 @@ fn Atom(n: uint) -> Atom {
|
||||
}
|
||||
|
||||
class AtomTable {
|
||||
let atoms: hashmap<@str,Atom>;
|
||||
let strings: dvec<@str>;
|
||||
let atoms: hashmap<@str/~,Atom>;
|
||||
let strings: dvec<@str/~>;
|
||||
let mut atom_count: uint;
|
||||
|
||||
new() {
|
||||
self.atoms = hashmap::<@str,Atom>(|x| str::hash(*x),
|
||||
self.atoms = hashmap::<@str/~,Atom>(|x| str::hash(*x),
|
||||
|x, y| str::eq(*x, *y));
|
||||
self.strings = dvec();
|
||||
self.atom_count = 0u;
|
||||
}
|
||||
|
||||
fn intern(string: @str) -> Atom {
|
||||
fn intern(string: @str/~) -> Atom {
|
||||
alt self.atoms.find(string) {
|
||||
none { /* fall through */ }
|
||||
some(atom) { ret atom; }
|
||||
@@ -227,11 +227,11 @@ class AtomTable {
|
||||
ret atom;
|
||||
}
|
||||
|
||||
fn atom_to_str(atom: Atom) -> @str {
|
||||
fn atom_to_str(atom: Atom) -> @str/~ {
|
||||
ret self.strings.get_elt(atom);
|
||||
}
|
||||
|
||||
fn atoms_to_strs(atoms: ~[Atom], f: fn(@str) -> bool) {
|
||||
fn atoms_to_strs(atoms: ~[Atom], f: fn(@str/~) -> bool) {
|
||||
for atoms.each |atom| {
|
||||
if !f(self.atom_to_str(atom)) {
|
||||
ret;
|
||||
@@ -239,7 +239,7 @@ class AtomTable {
|
||||
}
|
||||
}
|
||||
|
||||
fn atoms_to_str(atoms: ~[Atom]) -> @str {
|
||||
fn atoms_to_str(atoms: ~[Atom]) -> @str/~ {
|
||||
// XXX: str::connect should do this.
|
||||
let mut result = "";
|
||||
let mut first = true;
|
||||
@@ -577,7 +577,8 @@ class PrimitiveTypeTable {
|
||||
self.intern(atom_table, @"u64", ty_uint(ty_u64));
|
||||
}
|
||||
|
||||
fn intern(atom_table: @AtomTable, string: @str, primitive_type: prim_ty) {
|
||||
fn intern(atom_table: @AtomTable, string: @str/~,
|
||||
primitive_type: prim_ty) {
|
||||
let atom = (*atom_table).intern(string);
|
||||
self.primitive_types.insert(atom, primitive_type);
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t)
|
||||
}
|
||||
}
|
||||
|
||||
fn trans_estr(bcx: block, s: @str, vstore: ast::vstore,
|
||||
fn trans_estr(bcx: block, s: @str/~, vstore: ast::vstore,
|
||||
dest: dest) -> block {
|
||||
let _icx = bcx.insn_ctxt("tvec::trans_estr");
|
||||
let ccx = bcx.ccx();
|
||||
|
||||
@@ -253,7 +253,7 @@ type ctxt =
|
||||
freevars: freevars::freevar_map,
|
||||
tcache: type_cache,
|
||||
rcache: creader_cache,
|
||||
short_names_cache: hashmap<t, @str>,
|
||||
short_names_cache: hashmap<t, @str/~>,
|
||||
needs_drop_cache: hashmap<t, bool>,
|
||||
needs_unwind_cleanup_cache: hashmap<t, bool>,
|
||||
kind_cache: hashmap<t, kind>,
|
||||
|
||||
@@ -160,12 +160,17 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy>(
|
||||
ret {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl};
|
||||
}
|
||||
|
||||
fn mk_vstore<AC: ast_conv, RS: region_scope copy>(
|
||||
self: AC, rscope: RS, a_seq_ty: @ast::ty, vst: ty::vstore) -> ty::t {
|
||||
// Handle @, ~, and & being able to mean estrs and evecs.
|
||||
// If a_seq_ty is a str or a vec, make it an estr/evec
|
||||
fn mk_maybe_vstore<AC: ast_conv, RS: region_scope copy>(
|
||||
self: AC, rscope: RS, a_seq_ty: ast::mt, vst: ty::vstore,
|
||||
constr: fn(ty::mt) -> ty::t) -> ty::t {
|
||||
|
||||
let tcx = self.tcx();
|
||||
|
||||
alt a_seq_ty.node {
|
||||
alt a_seq_ty.ty.node {
|
||||
// to convert to an e{vec,str}, there can't be a mutability argument
|
||||
_ if a_seq_ty.mutbl != ast::m_imm {}
|
||||
ast::ty_vec(mt) {
|
||||
ret ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, mt), vst);
|
||||
}
|
||||
@@ -181,13 +186,8 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy>(
|
||||
_ {}
|
||||
}
|
||||
|
||||
// Get the type, just for the error message
|
||||
let seq_ty = ast_ty_to_ty(self, rscope, a_seq_ty);
|
||||
tcx.sess.span_err(
|
||||
a_seq_ty.span,
|
||||
#fmt["bound not allowed on a %s",
|
||||
ty::ty_sort_str(tcx, seq_ty)]);
|
||||
ret seq_ty;
|
||||
let seq_ty = ast_mt_to_mt(self, rscope, a_seq_ty);
|
||||
ret constr(seq_ty);
|
||||
}
|
||||
|
||||
fn check_path_args(tcx: ty::ctxt,
|
||||
@@ -227,10 +227,12 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy>(
|
||||
ast::ty_nil { ty::mk_nil(tcx) }
|
||||
ast::ty_bot { ty::mk_bot(tcx) }
|
||||
ast::ty_box(mt) {
|
||||
ty::mk_box(tcx, ast_mt_to_mt(self, rscope, mt))
|
||||
mk_maybe_vstore(self, rscope, mt, ty::vstore_box,
|
||||
|tmt| ty::mk_box(tcx, tmt))
|
||||
}
|
||||
ast::ty_uniq(mt) {
|
||||
ty::mk_uniq(tcx, ast_mt_to_mt(self, rscope, mt))
|
||||
mk_maybe_vstore(self, rscope, mt, ty::vstore_uniq,
|
||||
|tmt| ty::mk_uniq(tcx, tmt))
|
||||
}
|
||||
ast::ty_vec(mt) {
|
||||
ty::mk_vec(tcx, ast_mt_to_mt(self, rscope, mt))
|
||||
@@ -240,8 +242,9 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy>(
|
||||
}
|
||||
ast::ty_rptr(region, mt) {
|
||||
let r = ast_region_to_region(self, rscope, ast_ty.span, region);
|
||||
let mt = ast_mt_to_mt(self, in_anon_rscope(rscope, r), mt);
|
||||
ty::mk_rptr(tcx, r, mt)
|
||||
mk_maybe_vstore(self, in_anon_rscope(rscope, r), mt,
|
||||
ty::vstore_slice(r),
|
||||
|tmt| ty::mk_rptr(tcx, r, tmt))
|
||||
}
|
||||
ast::ty_tup(fields) {
|
||||
let flds = vec::map(fields, |t| ast_ty_to_ty(self, rscope, t));
|
||||
@@ -318,24 +321,64 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy>(
|
||||
}
|
||||
}
|
||||
}
|
||||
// This is awful and repetitive but will go away
|
||||
ast::ty_vstore(a_t, ast::vstore_slice(a_r)) {
|
||||
let r = ast_region_to_region(self, rscope, ast_ty.span, a_r);
|
||||
mk_vstore(self, in_anon_rscope(rscope, r), a_t, ty::vstore_slice(r))
|
||||
mk_maybe_vstore(self, in_anon_rscope(rscope, r),
|
||||
{ty: a_t, mutbl: ast::m_imm},
|
||||
ty::vstore_slice(r),
|
||||
|ty| {
|
||||
tcx.sess.span_err(
|
||||
a_t.span,
|
||||
#fmt["bound not allowed on a %s",
|
||||
ty::ty_sort_str(tcx, ty.ty)]);
|
||||
ty.ty
|
||||
})
|
||||
|
||||
}
|
||||
ast::ty_vstore(a_t, ast::vstore_uniq) {
|
||||
mk_vstore(self, rscope, a_t, ty::vstore_uniq)
|
||||
mk_maybe_vstore(self, rscope, {ty: a_t, mutbl: ast::m_imm},
|
||||
ty::vstore_uniq,
|
||||
|ty| {
|
||||
tcx.sess.span_err(
|
||||
a_t.span,
|
||||
#fmt["bound not allowed on a %s",
|
||||
ty::ty_sort_str(tcx, ty.ty)]);
|
||||
ty.ty
|
||||
})
|
||||
}
|
||||
ast::ty_vstore(a_t, ast::vstore_box) {
|
||||
mk_vstore(self, rscope, a_t, ty::vstore_box)
|
||||
mk_maybe_vstore(self, rscope, {ty: a_t, mutbl: ast::m_imm},
|
||||
ty::vstore_box,
|
||||
|ty| {
|
||||
tcx.sess.span_err(
|
||||
a_t.span,
|
||||
#fmt["bound not allowed on a %s",
|
||||
ty::ty_sort_str(tcx, ty.ty)]);
|
||||
ty.ty
|
||||
})
|
||||
}
|
||||
ast::ty_vstore(a_t, ast::vstore_fixed(some(u))) {
|
||||
mk_vstore(self, rscope, a_t, ty::vstore_fixed(u))
|
||||
mk_maybe_vstore(self, rscope, {ty: a_t, mutbl: ast::m_imm},
|
||||
ty::vstore_fixed(u),
|
||||
|ty| {
|
||||
tcx.sess.span_err(
|
||||
a_t.span,
|
||||
#fmt["bound not allowed on a %s",
|
||||
ty::ty_sort_str(tcx, ty.ty)]);
|
||||
ty.ty
|
||||
})
|
||||
}
|
||||
ast::ty_vstore(_, ast::vstore_fixed(none)) {
|
||||
tcx.sess.span_bug(
|
||||
ast_ty.span,
|
||||
"implied fixed length for bound");
|
||||
}
|
||||
/*
|
||||
ast::ty_vstore(_, _) {
|
||||
tcx.sess.span_bug(ast_ty.span, "some BS");
|
||||
}
|
||||
*/
|
||||
ast::ty_constr(t, cs) {
|
||||
let mut out_cs = ~[];
|
||||
for cs.each |constr| {
|
||||
|
||||
Reference in New Issue
Block a user