diff options
| author | Paul Stansifer <paul.stansifer@gmail.com> | 2012-08-02 15:34:13 -0700 |
|---|---|---|
| committer | Paul Stansifer <paul.stansifer@gmail.com> | 2012-08-22 14:59:24 -0700 |
| commit | 7317bf8792ebb3f27768109b7d574ee0806cc5e5 (patch) | |
| tree | c18d1d03ccee13544d7eaa57234f2a39bf24b5a4 /src | |
| parent | 9a7890d73af5ebe4bf862fa727427e290da1391b (diff) | |
| download | rust-7317bf8792ebb3f27768109b7d574ee0806cc5e5.tar.gz rust-7317bf8792ebb3f27768109b7d574ee0806cc5e5.zip | |
pre-intern some fixed names so they can be used as constants
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/util/interner.rs | 9 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a1309e3ecef..10fac8d0e23 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -279,9 +279,18 @@ pure fn is_bar(t: token) -> bool { type ident_interner = util::interner::interner<@~str>; +mod special_idents { + const underscore : uint = 0u; + const anon : uint = 1u; + const destr : uint = 2u; // 'drop', but that's reserved +} + fn mk_ident_interner() -> ident_interner { - let rv = @interner::mk::<@~str>(|x| str::hash(*x), - |x,y| str::eq(*x, *y)); + /* the indices here must correspond to the numbers in special_idents */ + let init_vec = ~[@~"_", @~"anon", @~"drop"]; + + let rv = @interner::mk_prefill::<@~str>(|x| str::hash(*x), + |x,y| str::eq(*x, *y), init_vec); rv } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 9b7398d16c7..19b27be83e2 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -18,6 +18,15 @@ fn mk<T: const copy>(+hasher: hashfn<T>, +eqer: eqfn<T>) -> interner<T> { return hi as interner::<T>; } +fn mk_prefill<T: const copy>(hasher: hashfn<T>, eqer: eqfn<T>, + init: ~[T]) -> interner<T> { + + let rv = mk(hasher, eqer); + for init.each() |v| { rv.intern(v); } + return rv; +} + + /* when traits can extend traits, we should extend index<uint,T> to get [] */ trait interner<T: const copy> { fn intern(T) -> uint; |
