diff options
| author | bors <bors@rust-lang.org> | 2013-08-28 15:30:38 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-28 15:30:38 -0700 |
| commit | 7971c46c44420f2b72086ff0b8726b1ada308bcc (patch) | |
| tree | 720fbb0d73a24b8c94e171db78ac4a316ad86cb5 /src/libsyntax | |
| parent | da96b3ec6a88a3f88627a001fb3be7620621a3d2 (diff) | |
| parent | 02f93ca32481d3b1a6a307d28223ca061348eb0c (diff) | |
| download | rust-7971c46c44420f2b72086ff0b8726b1ada308bcc.tar.gz rust-7971c46c44420f2b72086ff0b8726b1ada308bcc.zip | |
auto merge of #8718 : bblum/rust/typeof, r=pcwalton
r? anybody
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/oldvisit.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 3 |
7 files changed, 39 insertions, 3 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 44015a8b443..aec279e9c53 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -791,6 +791,7 @@ pub enum ty_ { ty_tup(~[Ty]), ty_path(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above ty_mac(mac), + ty_typeof(@expr), // ty_infer means the type should be inferred instead of it having been // specified. This should only appear at the "top level" of a type and not // nested in one. diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 458737e2fbf..6e3cd8e7159 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -697,6 +697,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ { fld.fold_expr(e) ) } + ty_typeof(e) => ty_typeof(fld.fold_expr(e)), ty_mac(ref mac) => ty_mac(fold_mac(mac)) } } diff --git a/src/libsyntax/oldvisit.rs b/src/libsyntax/oldvisit.rs index 56576ee3599..e1dcdb9222c 100644 --- a/src/libsyntax/oldvisit.rs +++ b/src/libsyntax/oldvisit.rs @@ -279,6 +279,9 @@ pub fn visit_ty<E:Clone>(t: &Ty, (e, v): (E, vt<E>)) { (v.visit_ty)(mt.ty, (e.clone(), v)); (v.visit_expr)(ex, (e.clone(), v)); }, + ty_typeof(ex) => { + (v.visit_expr)(ex, (e.clone(), v)); + } ty_nil | ty_bot | ty_mac(_) | ty_infer => () } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8ca858b7935..ea7a7540e36 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -51,7 +51,7 @@ use ast::{struct_variant_kind, subtract}; use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value}; use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok}; use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box}; -use ast::{TypeField, ty_fixed_length_vec, ty_closure, ty_bare_fn}; +use ast::{TypeField, ty_fixed_length_vec, ty_closure, ty_bare_fn, ty_typeof}; use ast::{ty_infer, TypeMethod}; use ast::{ty_nil, TyParam, TyParamBound, ty_path, ty_ptr, ty_rptr}; use ast::{ty_tup, ty_u32, ty_uniq, ty_vec, uniq}; @@ -1136,6 +1136,13 @@ impl Parser { let result = self.parse_ty_closure(ast::BorrowedSigil, None); self.obsolete(*self.last_span, ObsoleteBareFnType); result + } else if self.eat_keyword(keywords::Typeof) { + // TYPEOF + // In order to not be ambiguous, the type must be surrounded by parens. + self.expect(&token::LPAREN); + let e = self.parse_expr(); + self.expect(&token::RPAREN); + ty_typeof(e) } else if *self.token == token::MOD_SEP || is_ident_or_path(self.token) { // NAMED TYPE @@ -3610,6 +3617,19 @@ impl Parser { self.bump(); sty_value } + token::BINOP(token::STAR) => { + // Possibly "*self" or "*mut self" -- not supported. Try to avoid + // emitting cryptic "unexpected token" errors. + self.bump(); + if self.token_is_mutability(self.token) { + self.bump(); + } + if self.is_self_ident() { + self.span_err(*self.span, "cannot pass self by unsafe pointer"); + self.bump(); + } + sty_value + } _ => { sty_static } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 0d7def84003..8128a4e905c 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -478,6 +478,7 @@ fn mk_fresh_ident_interner() -> @ident_interner { "be", // 64 "pure", // 65 "yield", // 66 + "typeof", // 67 ]; @ident_interner { @@ -595,6 +596,7 @@ pub mod keywords { True, Trait, Type, + Typeof, Unsafe, Use, While, @@ -639,6 +641,7 @@ pub mod keywords { True => ident { name: 57, ctxt: 0 }, Trait => ident { name: 58, ctxt: 0 }, Type => ident { name: 59, ctxt: 0 }, + Typeof => ident { name: 67, ctxt: 0 }, Unsafe => ident { name: 60, ctxt: 0 }, Use => ident { name: 61, ctxt: 0 }, While => ident { name: 62, ctxt: 0 }, @@ -660,7 +663,7 @@ pub fn is_keyword(kw: keywords::Keyword, tok: &Token) -> bool { pub fn is_any_keyword(tok: &Token) -> bool { match *tok { token::IDENT(sid, false) => match sid.name { - 8 | 27 | 32 .. 66 => true, + 8 | 27 | 32 .. 67 => true, _ => false, }, _ => false @@ -680,7 +683,7 @@ pub fn is_strict_keyword(tok: &Token) -> bool { pub fn is_reserved_keyword(tok: &Token) -> bool { match *tok { token::IDENT(sid, false) => match sid.name { - 64 .. 66 => true, + 64 .. 67 => true, _ => false, }, _ => false, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d449ba4eb5f..9c31d982590 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -435,6 +435,11 @@ pub fn print_type(s: @ps, ty: &ast::Ty) { print_expr(s, v); word(s.s, "]"); } + ast::ty_typeof(e) => { + word(s.s, "typeof("); + print_expr(s, e); + word(s.s, ")"); + } ast::ty_mac(_) => { fail!("print_type doesn't know how to print a ty_mac"); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index e5b7823ae44..79304aebea2 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -314,6 +314,9 @@ pub fn walk_ty<E:Clone, V:Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) { visitor.visit_ty(mutable_type.ty, env.clone()); visitor.visit_expr(expression, env) } + ty_typeof(expression) => { + visitor.visit_expr(expression, env) + } ty_nil | ty_bot | ty_mac(_) | ty_infer => () } } |
