diff options
| author | Corey Richardson <corey@octayn.net> | 2014-07-06 01:17:59 -0700 |
|---|---|---|
| committer | Corey Richardson <corey@octayn.net> | 2014-07-09 00:49:54 -0700 |
| commit | 092c5078be5b9abfc4e1a80e3ef9d015d321479c (patch) | |
| tree | 46b19fe160154e14c412e928e676daa809407913 /src/libsyntax/ast.rs | |
| parent | f512779554a436d11dd9ffde4c198da6241dfd58 (diff) | |
| download | rust-092c5078be5b9abfc4e1a80e3ef9d015d321479c.tar.gz rust-092c5078be5b9abfc4e1a80e3ef9d015d321479c.zip | |
ast: make Name its own type
Diffstat (limited to 'src/libsyntax/ast.rs')
| -rw-r--r-- | src/libsyntax/ast.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2a49d0e0f5b..ebfc45d22ce 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -52,10 +52,7 @@ impl Ident { pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}} pub fn as_str<'a>(&'a self) -> &'a str { - unsafe { - // FIXME #12938: can't use copy_lifetime since &str isn't a &T - ::std::mem::transmute(token::get_ident(*self).get()) - } + self.name.as_str() } } @@ -109,7 +106,26 @@ pub static ILLEGAL_CTXT : SyntaxContext = 1; /// A name is a part of an identifier, representing a string or gensym. It's /// the result of interning. -pub type Name = u32; +#[deriving(Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone, Show)] +pub struct Name(pub u32); + +impl Name { + pub fn as_str<'a>(&'a self) -> &'a str { + unsafe { + // FIXME #12938: can't use copy_lifetime since &str isn't a &T + ::std::mem::transmute(token::get_name(*self).get()) + } + } + + pub fn uint(&self) -> uint { + let Name(nm) = *self; + nm as uint + } + + pub fn ident(&self) -> Ident { + Ident { name: *self, ctxt: 0 } + } +} /// A mark represents a unique id associated with a macro expansion pub type Mrk = u32; |
