Skip to content

Commit ce750a7

Browse files
committed
Box AST idents
1 parent bdd2000 commit ce750a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+629
-603
lines changed

src/cargo/cargo.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ fn load_link(mis: [@ast::meta_item]) -> (option<str>,
224224
for mis.each {|a|
225225
alt a.node {
226226
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
227-
alt v {
228-
"name" { name = some(s); }
229-
"vers" { vers = some(s); }
230-
"uuid" { uuid = some(s); }
227+
alt *v {
228+
"name" { name = some(*s); }
229+
"vers" { vers = some(*s); }
230+
"uuid" { uuid = some(*s); }
231231
_ { }
232232
}
233233
}
@@ -259,15 +259,15 @@ fn load_crate(filename: str) -> option<crate> {
259259
for c.node.attrs.each {|a|
260260
alt a.node.value.node {
261261
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
262-
alt v {
263-
"desc" { desc = some(v); }
264-
"sigs" { sigs = some(v); }
265-
"crate_type" { crate_type = some(v); }
262+
alt *v {
263+
"desc" { desc = some(*v); }
264+
"sigs" { sigs = some(*v); }
265+
"crate_type" { crate_type = some(*v); }
266266
_ { }
267267
}
268268
}
269269
ast::meta_list(v, mis) {
270-
if v == "link" {
270+
if *v == "link" {
271271
let (n, v, u) = load_link(mis);
272272
name = n;
273273
vers = v;
@@ -290,7 +290,7 @@ fn load_crate(filename: str) -> option<crate> {
290290
ast::view_item_use(ident, metas, id) {
291291
let name_items = attr::find_meta_items_by_name(metas, "name");
292292
let m = if name_items.is_empty() {
293-
metas + [attr::mk_name_value_item_str("name", ident)]
293+
metas + [attr::mk_name_value_item_str(@"name", *ident)]
294294
} else {
295295
metas
296296
};
@@ -303,9 +303,9 @@ fn load_crate(filename: str) -> option<crate> {
303303
some(value) {
304304
let name = attr::get_meta_item_name(item);
305305

306-
alt name {
307-
"vers" { attr_vers = value; }
308-
"from" { attr_from = value; }
306+
alt *name {
307+
"vers" { attr_vers = *value; }
308+
"from" { attr_from = *value; }
309309
_ {}
310310
}
311311
}
@@ -317,11 +317,11 @@ fn load_crate(filename: str) -> option<crate> {
317317
attr_from
318318
} else {
319319
if !str::is_empty(attr_vers) {
320-
attr_name + "@" + attr_vers
321-
} else { attr_name }
320+
*attr_name + "@" + attr_vers
321+
} else { *attr_name }
322322
};
323323

324-
alt attr_name {
324+
alt *attr_name {
325325
"std" | "core" { }
326326
_ { e.deps += [query]; }
327327
}

src/fuzzer/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn common_exprs() -> [ast::expr] {
4545
dse(ast::expr_cont),
4646
dse(ast::expr_fail(option::none)),
4747
dse(ast::expr_fail(option::some(
48-
@dse(ast::expr_lit(@dsl(ast::lit_str("boo"))))))),
48+
@dse(ast::expr_lit(@dsl(ast::lit_str(@"boo"))))))),
4949
dse(ast::expr_ret(option::none)),
5050
dse(ast::expr_lit(@dsl(ast::lit_nil))),
5151
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),

src/libstd/map.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import chained::hashmap;
44
export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
5+
export box_str_hash;
56
export bytes_hash, int_hash, uint_hash, set_add;
67
export hash_from_vec, hash_from_strs, hash_from_bytes;
78
export hash_from_ints, hash_from_uints;
@@ -292,6 +293,11 @@ fn str_hash<V: copy>() -> hashmap<str, V> {
292293
ret hashmap(str::hash, str::eq);
293294
}
294295

296+
#[doc = "Construct a hashmap for boxed string keys"]
297+
fn box_str_hash<V: copy>() -> hashmap<@str, V> {
298+
ret hashmap({|x: @str|str::hash(*x)}, {|x,y|str::eq(*x,*y)});
299+
}
300+
295301
#[doc = "Construct a hashmap for byte string keys"]
296302
fn bytes_hash<V: copy>() -> hashmap<[u8], V> {
297303
ret hashmap(vec::u8::hash, vec::u8::eq);

src/libsyntax/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn deserialize_span<D>(_d: D) -> span {
3030
type spanned<T> = {node: T, span: span};
3131

3232
#[auto_serialize]
33-
type ident = str;
33+
type ident = @str;
3434

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

400400
#[auto_serialize]
401401
enum lit_ {
402-
lit_str(str),
402+
lit_str(@str),
403403
lit_int(i64, int_ty),
404404
lit_uint(u64, uint_ty),
405405
lit_int_unsuffixed(i64, int_ty),
406-
lit_float(str, float_ty),
406+
lit_float(@str, float_ty),
407407
lit_nil,
408408
lit_bool(bool),
409409
}

src/libsyntax/ast_map.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ import ast_util::path_to_ident;
66
import ast_util::inlined_item_methods;
77
import diagnostic::span_handler;
88

9-
enum path_elt { path_mod(str), path_name(str) }
9+
enum path_elt { path_mod(ident), path_name(ident) }
1010
type path = [path_elt];
1111

1212
fn path_to_str_with_sep(p: path, sep: str) -> str {
1313
let strs = vec::map(p) {|e|
1414
alt e {
15-
path_mod(s) { /* FIXME: bad */ copy s }
16-
path_name(s) { /* FIXME: bad */ copy s }
15+
path_mod(s) { /* FIXME: bad */ copy *s }
16+
path_name(s) { /* FIXME: bad */ copy *s }
1717
}
1818
};
1919
str::connect(strs, sep)
2020
}
2121

2222
fn path_ident_to_str(p: path, i: ident) -> str {
2323
if vec::is_empty(p) {
24-
/* FIXME: bad */ copy i
24+
/* FIXME: bad */ copy *i
2525
} else {
26-
#fmt["%s::%s", path_to_str(p), i]
26+
#fmt["%s::%s", path_to_str(p), *i]
2727
}
2828
}
2929

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

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

@@ -192,7 +192,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
192192
item_impl(_, _, _, _, ms) {
193193
let impl_did = ast_util::local_def(i.id);
194194
for ms.each {|m|
195-
map_method(impl_did, extend(cx, /* FIXME: bad */ copy i.ident), m,
195+
map_method(impl_did, extend(cx, i.ident), m,
196196
cx);
197197
}
198198
}
@@ -208,7 +208,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
208208
for vs.each {|v|
209209
cx.map.insert(v.node.id, node_variant(
210210
/* FIXME: bad */ copy v, i,
211-
extend(cx, /* FIXME: bad */ copy i.ident)));
211+
extend(cx, i.ident)));
212212
}
213213
}
214214
item_native_mod(nm) {
@@ -229,17 +229,17 @@ fn map_item(i: @item, cx: ctx, v: vt) {
229229
vec::iter(ifces) {|p| cx.map.insert(p.id,
230230
node_item(i, item_path)); };
231231
let d_id = ast_util::local_def(i.id);
232-
let p = extend(cx, /* FIXME: bad */ copy i.ident);
232+
let p = extend(cx, i.ident);
233233
// only need to handle methods
234234
vec::iter(ms) {|m| map_method(d_id, p, m, cx); }
235235
}
236236
_ { }
237237
}
238238
alt i.node {
239239
item_mod(_) | item_native_mod(_) {
240-
cx.path += [path_mod(/* FIXME: bad */ copy i.ident)];
240+
cx.path += [path_mod(i.ident)];
241241
}
242-
_ { cx.path += [path_name(/* FIXME: bad */ copy i.ident)]; }
242+
_ { cx.path += [path_name(i.ident)]; }
243243
}
244244
visit::visit_item(i, cx, v);
245245
vec::pop(cx.path);
@@ -281,11 +281,11 @@ fn node_id_to_str(map: map, id: node_id) -> str {
281281
}
282282
some(node_method(m, impl_did, path)) {
283283
#fmt["method %s in %s (id=%?)",
284-
m.ident, path_to_str(*path), id]
284+
*m.ident, path_to_str(*path), id]
285285
}
286286
some(node_variant(variant, def_id, path)) {
287287
#fmt["variant %s in %s (id=%?)",
288-
variant.node.name, path_to_str(*path), id]
288+
*variant.node.name, path_to_str(*path), id]
289289
}
290290
some(node_expr(expr)) {
291291
#fmt["expr %s (id=%?)",

src/libsyntax/ast_util.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ pure fn dummy_sp() -> span { ret mk_sp(0u, 0u); }
2323

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

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

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

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

src/libsyntax/attr.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export require_unique_names;
4747
/* Constructors */
4848

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

@@ -100,12 +100,12 @@ fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
100100
Gets the string value if the meta_item is a meta_name_value variant
101101
containing a string, otherwise none
102102
"]
103-
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<str> {
103+
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@str> {
104104
alt meta.node {
105105
ast::meta_name_value(_, v) {
106106
alt v.node {
107107
ast::lit_str(s) {
108-
option::some(/* FIXME bad */ copy s)
108+
option::some(s)
109109
}
110110
_ {
111111
option::none
@@ -130,11 +130,11 @@ a tuple containing the name and string value, otherwise `none`
130130
"]
131131
fn get_name_value_str_pair(
132132
item: @ast::meta_item
133-
) -> option<(str, str)> {
133+
) -> option<(ast::ident, @str)> {
134134
alt attr::get_meta_item_value_str(item) {
135135
some(value) {
136136
let name = attr::get_meta_item_name(item);
137-
some((name, /* FIXME bad */ copy value))
137+
some((name, value))
138138
}
139139
none { none }
140140
}
@@ -146,11 +146,11 @@ fn get_name_value_str_pair(
146146
#[doc = "
147147
Search a list of attributes and return only those with a specific name
148148
"]
149-
fn find_attrs_by_name(attrs: [ast::attribute], +name: ast::ident) ->
149+
fn find_attrs_by_name(attrs: [ast::attribute], +name: str) ->
150150
[ast::attribute] {
151151
let filter = (
152152
fn@(a: ast::attribute) -> option<ast::attribute> {
153-
if get_attr_name(a) == name {
153+
if *get_attr_name(a) == name {
154154
option::some(a)
155155
} else { option::none }
156156
}
@@ -161,10 +161,10 @@ fn find_attrs_by_name(attrs: [ast::attribute], +name: ast::ident) ->
161161
#[doc = "
162162
Searcha list of meta items and return only those with a specific name
163163
"]
164-
fn find_meta_items_by_name(metas: [@ast::meta_item], +name: ast::ident) ->
164+
fn find_meta_items_by_name(metas: [@ast::meta_item], +name: str) ->
165165
[@ast::meta_item] {
166166
let filter = fn@(&&m: @ast::meta_item) -> option<@ast::meta_item> {
167-
if get_meta_item_name(m) == name {
167+
if *get_meta_item_name(m) == name {
168168
option::some(m)
169169
} else { option::none }
170170
};
@@ -209,17 +209,17 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
209209
}
210210
}
211211

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

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

221-
fn first_attr_value_str_by_name(attrs: [ast::attribute], +name: ast::ident)
222-
-> option<str> {
221+
fn first_attr_value_str_by_name(attrs: [ast::attribute], +name: str)
222+
-> option<@str> {
223223
let mattrs = find_attrs_by_name(attrs, name);
224224
if vec::len(mattrs) > 0u {
225225
ret get_meta_item_value_str(attr_meta(mattrs[0]));
@@ -238,11 +238,11 @@ fn last_meta_item_by_name(
238238
fn last_meta_item_value_str_by_name(
239239
items: [@ast::meta_item],
240240
+name: str
241-
) -> option<str> {
241+
) -> option<@str> {
242242
alt last_meta_item_by_name(items, name) {
243243
some(item) {
244244
alt attr::get_meta_item_value_str(item) {
245-
some(value) { some(/* FIXME bad */ copy value) }
245+
some(value) { some(value) }
246246
none { none }
247247
}
248248
}
@@ -285,7 +285,7 @@ fn sort_meta_items(+items: [@ast::meta_item]) -> [@ast::meta_item] {
285285
ret vec::from_mut(v);
286286
}
287287

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

291291
ret vec::filter_map(items, {
@@ -326,17 +326,17 @@ fn native_abi(attrs: [ast::attribute]) -> either<str, ast::native_abi> {
326326
option::none {
327327
either::right(ast::native_abi_cdecl)
328328
}
329-
option::some("rust-intrinsic") {
329+
option::some(@"rust-intrinsic") {
330330
either::right(ast::native_abi_rust_intrinsic)
331331
}
332-
option::some("cdecl") {
332+
option::some(@"cdecl") {
333333
either::right(ast::native_abi_cdecl)
334334
}
335-
option::some("stdcall") {
335+
option::some(@"stdcall") {
336336
either::right(ast::native_abi_stdcall)
337337
}
338338
option::some(t) {
339-
either::left("unsupported abi: " + t)
339+
either::left("unsupported abi: " + *t)
340340
}
341341
};
342342
}
@@ -352,8 +352,8 @@ fn find_inline_attr(attrs: [ast::attribute]) -> inline_attr {
352352
// TODO---validate the usage of #[inline] and #[inline(always)]
353353
vec::foldl(ia_none, attrs) {|ia,attr|
354354
alt attr.node.value.node {
355-
ast::meta_word("inline") { ia_hint }
356-
ast::meta_list("inline", items) {
355+
ast::meta_word(@"inline") { ia_hint }
356+
ast::meta_list(@"inline", items) {
357357
if !vec::is_empty(find_meta_items_by_name(items, "always")) {
358358
ia_always
359359
} else {
@@ -373,11 +373,11 @@ fn require_unique_names(diagnostic: span_handler,
373373
let name = get_meta_item_name(meta);
374374

375375
// FIXME: How do I silence the warnings? --pcw
376-
if map.contains_key(name) {
376+
if map.contains_key(*name) {
377377
diagnostic.span_fatal(meta.span,
378-
#fmt["duplicate meta item `%s`", name]);
378+
#fmt["duplicate meta item `%s`", *name]);
379379
}
380-
map.insert(name, ());
380+
map.insert(*name, ());
381381
}
382382
}
383383

0 commit comments

Comments
 (0)