Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box AST idents #2583

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ fn load_link(mis: [@ast::meta_item]) -> (option<str>,
for mis.each {|a|
alt a.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
alt v {
"name" { name = some(s); }
"vers" { vers = some(s); }
"uuid" { uuid = some(s); }
alt *v {
"name" { name = some(*s); }
"vers" { vers = some(*s); }
"uuid" { uuid = some(*s); }
_ { }
}
}
Expand Down Expand Up @@ -259,15 +259,15 @@ fn load_crate(filename: str) -> option<crate> {
for c.node.attrs.each {|a|
alt a.node.value.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
alt v {
"desc" { desc = some(v); }
"sigs" { sigs = some(v); }
"crate_type" { crate_type = some(v); }
alt *v {
"desc" { desc = some(*v); }
"sigs" { sigs = some(*v); }
"crate_type" { crate_type = some(*v); }
_ { }
}
}
ast::meta_list(v, mis) {
if v == "link" {
if *v == "link" {
let (n, v, u) = load_link(mis);
name = n;
vers = v;
Expand All @@ -290,7 +290,7 @@ fn load_crate(filename: str) -> option<crate> {
ast::view_item_use(ident, metas, id) {
let name_items = attr::find_meta_items_by_name(metas, "name");
let m = if name_items.is_empty() {
metas + [attr::mk_name_value_item_str("name", ident)]
metas + [attr::mk_name_value_item_str(@"name", *ident)]
} else {
metas
};
Expand All @@ -303,9 +303,9 @@ fn load_crate(filename: str) -> option<crate> {
some(value) {
let name = attr::get_meta_item_name(item);

alt name {
"vers" { attr_vers = value; }
"from" { attr_from = value; }
alt *name {
"vers" { attr_vers = *value; }
"from" { attr_from = *value; }
_ {}
}
}
Expand All @@ -317,11 +317,11 @@ fn load_crate(filename: str) -> option<crate> {
attr_from
} else {
if !str::is_empty(attr_vers) {
attr_name + "@" + attr_vers
} else { attr_name }
*attr_name + "@" + attr_vers
} else { *attr_name }
};

alt attr_name {
alt *attr_name {
"std" | "core" { }
_ { e.deps += [query]; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzer/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn common_exprs() -> [ast::expr] {
dse(ast::expr_cont),
dse(ast::expr_fail(option::none)),
dse(ast::expr_fail(option::some(
@dse(ast::expr_lit(@dsl(ast::lit_str("boo"))))))),
@dse(ast::expr_lit(@dsl(ast::lit_str(@"boo"))))))),
dse(ast::expr_ret(option::none)),
dse(ast::expr_lit(@dsl(ast::lit_nil))),
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),
Expand Down
6 changes: 6 additions & 0 deletions src/libstd/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import chained::hashmap;
export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
export box_str_hash;
export bytes_hash, int_hash, uint_hash, set_add;
export hash_from_vec, hash_from_strs, hash_from_bytes;
export hash_from_ints, hash_from_uints;
Expand Down Expand Up @@ -292,6 +293,11 @@ fn str_hash<V: copy>() -> hashmap<str, V> {
ret hashmap(str::hash, str::eq);
}

#[doc = "Construct a hashmap for boxed string keys"]
fn box_str_hash<V: copy>() -> hashmap<@str, V> {
ret hashmap({|x: @str|str::hash(*x)}, {|x,y|str::eq(*x,*y)});
}

#[doc = "Construct a hashmap for byte string keys"]
fn bytes_hash<V: copy>() -> hashmap<[u8], V> {
ret hashmap(vec::u8::hash, vec::u8::eq);
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn deserialize_span<D>(_d: D) -> span {
type spanned<T> = {node: T, span: span};

#[auto_serialize]
type ident = str;
type ident = @str;

// Functions may or may not have names.
#[auto_serialize]
Expand Down Expand Up @@ -399,11 +399,11 @@ type lit = spanned<lit_>;

#[auto_serialize]
enum lit_ {
lit_str(str),
lit_str(@str),
lit_int(i64, int_ty),
lit_uint(u64, uint_ty),
lit_int_unsuffixed(i64, int_ty),
lit_float(str, float_ty),
lit_float(@str, float_ty),
lit_nil,
lit_bool(bool),
}
Expand Down
26 changes: 13 additions & 13 deletions src/libsyntax/ast_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import ast_util::path_to_ident;
import ast_util::inlined_item_methods;
import diagnostic::span_handler;

enum path_elt { path_mod(str), path_name(str) }
enum path_elt { path_mod(ident), path_name(ident) }
type path = [path_elt];

fn path_to_str_with_sep(p: path, sep: str) -> str {
let strs = vec::map(p) {|e|
alt e {
path_mod(s) { /* FIXME: bad */ copy s }
path_name(s) { /* FIXME: bad */ copy s }
path_mod(s) { /* FIXME: bad */ copy *s }
path_name(s) { /* FIXME: bad */ copy *s }
}
};
str::connect(strs, sep)
}

fn path_ident_to_str(p: path, i: ident) -> str {
if vec::is_empty(p) {
/* FIXME: bad */ copy i
/* FIXME: bad */ copy *i
} else {
#fmt["%s::%s", path_to_str(p), i]
#fmt["%s::%s", path_to_str(p), *i]
}
}

Expand Down Expand Up @@ -59,7 +59,7 @@ type ctx = {map: map, mut path: path,
mut local_id: uint, diag: span_handler};
type vt = visit::vt<ctx>;

fn extend(cx: ctx, +elt: str) -> @path {
fn extend(cx: ctx, +elt: ident) -> @path {
@(cx.path + [path_name(elt)])
}

Expand Down Expand Up @@ -192,7 +192,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
item_impl(_, _, _, _, ms) {
let impl_did = ast_util::local_def(i.id);
for ms.each {|m|
map_method(impl_did, extend(cx, /* FIXME: bad */ copy i.ident), m,
map_method(impl_did, extend(cx, i.ident), m,
cx);
}
}
Expand All @@ -208,7 +208,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
for vs.each {|v|
cx.map.insert(v.node.id, node_variant(
/* FIXME: bad */ copy v, i,
extend(cx, /* FIXME: bad */ copy i.ident)));
extend(cx, i.ident)));
}
}
item_native_mod(nm) {
Expand All @@ -229,17 +229,17 @@ fn map_item(i: @item, cx: ctx, v: vt) {
vec::iter(ifces) {|p| cx.map.insert(p.id,
node_item(i, item_path)); };
let d_id = ast_util::local_def(i.id);
let p = extend(cx, /* FIXME: bad */ copy i.ident);
let p = extend(cx, i.ident);
// only need to handle methods
vec::iter(ms) {|m| map_method(d_id, p, m, cx); }
}
_ { }
}
alt i.node {
item_mod(_) | item_native_mod(_) {
cx.path += [path_mod(/* FIXME: bad */ copy i.ident)];
cx.path += [path_mod(i.ident)];
}
_ { cx.path += [path_name(/* FIXME: bad */ copy i.ident)]; }
_ { cx.path += [path_name(i.ident)]; }
}
visit::visit_item(i, cx, v);
vec::pop(cx.path);
Expand Down Expand Up @@ -281,11 +281,11 @@ fn node_id_to_str(map: map, id: node_id) -> str {
}
some(node_method(m, impl_did, path)) {
#fmt["method %s in %s (id=%?)",
m.ident, path_to_str(*path), id]
*m.ident, path_to_str(*path), id]
}
some(node_variant(variant, def_id, path)) {
#fmt["variant %s in %s (id=%?)",
variant.node.name, path_to_str(*path), id]
*variant.node.name, path_to_str(*path), id]
}
some(node_expr(expr)) {
#fmt["expr %s (id=%?)",
Expand Down
7 changes: 5 additions & 2 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pure fn dummy_sp() -> span { ret mk_sp(0u, 0u); }

pure fn path_name(p: @path) -> str { path_name_i(p.idents) }

pure fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") }
pure fn path_name_i(idents: [ident]) -> str {
// FIXME: Bad copies
str::connect(idents.map({|i|*i}), "::")
}

pure fn path_to_ident(p: @path) -> ident { vec::last(p.idents) }

Expand Down Expand Up @@ -380,7 +383,7 @@ fn dtor_dec() -> fn_decl {
let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()};
// dtor has one argument, of type ()
{inputs: [{mode: ast::expl(ast::by_ref),
ty: nil_t, ident: "_", id: 0}],
ty: nil_t, ident: @"_", id: 0}],
output: nil_t, purity: impure_fn, cf: return_val, constraints: []}
}

Expand Down
50 changes: 25 additions & 25 deletions src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export require_unique_names;
/* Constructors */

fn mk_name_value_item_str(+name: ast::ident, +value: str) -> @ast::meta_item {
let value_lit = dummy_spanned(ast::lit_str(value));
let value_lit = dummy_spanned(ast::lit_str(@value));
ret mk_name_value_item(name, value_lit);
}

Expand Down Expand Up @@ -100,12 +100,12 @@ fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
Gets the string value if the meta_item is a meta_name_value variant
containing a string, otherwise none
"]
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<str> {
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@str> {
alt meta.node {
ast::meta_name_value(_, v) {
alt v.node {
ast::lit_str(s) {
option::some(/* FIXME bad */ copy s)
option::some(s)
}
_ {
option::none
Expand All @@ -130,11 +130,11 @@ a tuple containing the name and string value, otherwise `none`
"]
fn get_name_value_str_pair(
item: @ast::meta_item
) -> option<(str, str)> {
) -> option<(ast::ident, @str)> {
alt attr::get_meta_item_value_str(item) {
some(value) {
let name = attr::get_meta_item_name(item);
some((name, /* FIXME bad */ copy value))
some((name, value))
}
none { none }
}
Expand All @@ -146,11 +146,11 @@ fn get_name_value_str_pair(
#[doc = "
Search a list of attributes and return only those with a specific name
"]
fn find_attrs_by_name(attrs: [ast::attribute], +name: ast::ident) ->
fn find_attrs_by_name(attrs: [ast::attribute], +name: str) ->
[ast::attribute] {
let filter = (
fn@(a: ast::attribute) -> option<ast::attribute> {
if get_attr_name(a) == name {
if *get_attr_name(a) == name {
option::some(a)
} else { option::none }
}
Expand All @@ -161,10 +161,10 @@ fn find_attrs_by_name(attrs: [ast::attribute], +name: ast::ident) ->
#[doc = "
Searcha list of meta items and return only those with a specific name
"]
fn find_meta_items_by_name(metas: [@ast::meta_item], +name: ast::ident) ->
fn find_meta_items_by_name(metas: [@ast::meta_item], +name: str) ->
[@ast::meta_item] {
let filter = fn@(&&m: @ast::meta_item) -> option<@ast::meta_item> {
if get_meta_item_name(m) == name {
if *get_meta_item_name(m) == name {
option::some(m)
} else { option::none }
};
Expand Down Expand Up @@ -209,17 +209,17 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
}
}

fn contains_name(metas: [@ast::meta_item], +name: ast::ident) -> bool {
fn contains_name(metas: [@ast::meta_item], +name: str) -> bool {
let matches = find_meta_items_by_name(metas, name);
ret vec::len(matches) > 0u;
}

fn attrs_contains_name(attrs: [ast::attribute], +name: ast::ident) -> bool {
fn attrs_contains_name(attrs: [ast::attribute], +name: str) -> bool {
vec::is_not_empty(find_attrs_by_name(attrs, name))
}

fn first_attr_value_str_by_name(attrs: [ast::attribute], +name: ast::ident)
-> option<str> {
fn first_attr_value_str_by_name(attrs: [ast::attribute], +name: str)
-> option<@str> {
let mattrs = find_attrs_by_name(attrs, name);
if vec::len(mattrs) > 0u {
ret get_meta_item_value_str(attr_meta(mattrs[0]));
Expand All @@ -238,11 +238,11 @@ fn last_meta_item_by_name(
fn last_meta_item_value_str_by_name(
items: [@ast::meta_item],
+name: str
) -> option<str> {
) -> option<@str> {
alt last_meta_item_by_name(items, name) {
some(item) {
alt attr::get_meta_item_value_str(item) {
some(value) { some(/* FIXME bad */ copy value) }
some(value) { some(value) }
none { none }
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ fn sort_meta_items(+items: [@ast::meta_item]) -> [@ast::meta_item] {
ret vec::from_mut(v);
}

fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) ->
fn remove_meta_items_by_name(items: [@ast::meta_item], name: ast::ident) ->
[@ast::meta_item] {

ret vec::filter_map(items, {
Expand Down Expand Up @@ -326,17 +326,17 @@ fn native_abi(attrs: [ast::attribute]) -> either<str, ast::native_abi> {
option::none {
either::right(ast::native_abi_cdecl)
}
option::some("rust-intrinsic") {
option::some(@"rust-intrinsic") {
either::right(ast::native_abi_rust_intrinsic)
}
option::some("cdecl") {
option::some(@"cdecl") {
either::right(ast::native_abi_cdecl)
}
option::some("stdcall") {
option::some(@"stdcall") {
either::right(ast::native_abi_stdcall)
}
option::some(t) {
either::left("unsupported abi: " + t)
either::left("unsupported abi: " + *t)
}
};
}
Expand All @@ -352,8 +352,8 @@ fn find_inline_attr(attrs: [ast::attribute]) -> inline_attr {
// TODO---validate the usage of #[inline] and #[inline(always)]
vec::foldl(ia_none, attrs) {|ia,attr|
alt attr.node.value.node {
ast::meta_word("inline") { ia_hint }
ast::meta_list("inline", items) {
ast::meta_word(@"inline") { ia_hint }
ast::meta_list(@"inline", items) {
if !vec::is_empty(find_meta_items_by_name(items, "always")) {
ia_always
} else {
Expand All @@ -373,11 +373,11 @@ fn require_unique_names(diagnostic: span_handler,
let name = get_meta_item_name(meta);

// FIXME: How do I silence the warnings? --pcw
if map.contains_key(name) {
if map.contains_key(*name) {
diagnostic.span_fatal(meta.span,
#fmt["duplicate meta item `%s`", name]);
#fmt["duplicate meta item `%s`", *name]);
}
map.insert(name, ());
map.insert(*name, ());
}
}

Expand Down
Loading