diff options
| author | John Clements <clements@racket-lang.org> | 2013-04-23 10:57:41 -0700 |
|---|---|---|
| committer | John Clements <clements@racket-lang.org> | 2013-04-28 09:49:20 -0700 |
| commit | c73a9c9cd08991b8766b6badabcb08f5c6b48799 (patch) | |
| tree | ef8d0e45759b9b72b1b263a209da79268a5047db /src/libsyntax/parse/token.rs | |
| parent | a2493ad04811c1133127be8740bf30c2d24504ab (diff) | |
| download | rust-c73a9c9cd08991b8766b6badabcb08f5c6b48799.tar.gz rust-c73a9c9cd08991b8766b6badabcb08f5c6b48799.zip | |
refactoring mod.rs
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 106 |
1 files changed, 57 insertions, 49 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 413f1688df1..2f8acbcece7 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -390,60 +390,68 @@ pub impl ident_interner { } } +// return a fresh interner, preloaded with special identifiers. +// EFFECT: stores this interner in TLS +pub fn mk_fresh_ident_interner() -> @ident_interner { + // the indices here must correspond to the numbers in + // special_idents. + let init_vec = ~[ + @~"_", // 0 + @~"anon", // 1 + @~"drop", // 2 + @~"", // 3 + @~"unary", // 4 + @~"!", // 5 + @~"[]", // 6 + @~"unary-", // 7 + @~"__extensions__", // 8 + @~"self", // 9 + @~"item", // 10 + @~"block", // 11 + @~"stmt", // 12 + @~"pat", // 13 + @~"expr", // 14 + @~"ty", // 15 + @~"ident", // 16 + @~"path", // 17 + @~"tt", // 18 + @~"matchers", // 19 + @~"str", // 20 + @~"TyVisitor", // 21 + @~"arg", // 22 + @~"descrim", // 23 + @~"__rust_abi", // 24 + @~"__rust_stack_shim", // 25 + @~"TyDesc", // 26 + @~"dtor", // 27 + @~"main", // 28 + @~"<opaque>", // 29 + @~"blk", // 30 + @~"static", // 31 + @~"intrinsic", // 32 + @~"__foreign_mod__", // 33 + @~"__field__", // 34 + @~"C", // 35 + @~"Self", // 36 + ]; + + let rv = @ident_interner { + interner: interner::Interner::prefill(init_vec) + }; + unsafe { + task::local_data::local_data_set(interner_key!(), @rv); + } + rv +} + +// if an interner exists in TLS, return it. Otherwise, prepare a +// fresh one. pub fn mk_ident_interner() -> @ident_interner { unsafe { match task::local_data::local_data_get(interner_key!()) { Some(interner) => *interner, None => { - // the indices here must correspond to the numbers in - // special_idents. - let init_vec = ~[ - @~"_", // 0 - @~"anon", // 1 - @~"drop", // 2 - @~"", // 3 - @~"unary", // 4 - @~"!", // 5 - @~"[]", // 6 - @~"unary-", // 7 - @~"__extensions__", // 8 - @~"self", // 9 - @~"item", // 10 - @~"block", // 11 - @~"stmt", // 12 - @~"pat", // 13 - @~"expr", // 14 - @~"ty", // 15 - @~"ident", // 16 - @~"path", // 17 - @~"tt", // 18 - @~"matchers", // 19 - @~"str", // 20 - @~"TyVisitor", // 21 - @~"arg", // 22 - @~"descrim", // 23 - @~"__rust_abi", // 24 - @~"__rust_stack_shim", // 25 - @~"TyDesc", // 26 - @~"dtor", // 27 - @~"main", // 28 - @~"<opaque>", // 29 - @~"blk", // 30 - @~"static", // 31 - @~"intrinsic", // 32 - @~"__foreign_mod__", // 33 - @~"__field__", // 34 - @~"C", // 35 - @~"Self", // 36 - ]; - - let rv = @ident_interner { - interner: interner::Interner::prefill(init_vec) - }; - - task::local_data::local_data_set(interner_key!(), @rv); - - rv + mk_fresh_ident_interner() } } } |
