]> git.lizzy.rs Git - rust.git/commitdiff
Merge remote-tracking branch 'brson/codemap'
authorBrian Anderson <banderson@mozilla.com>
Sat, 17 Nov 2012 02:54:48 +0000 (18:54 -0800)
committerBrian Anderson <banderson@mozilla.com>
Sun, 18 Nov 2012 02:38:39 +0000 (18:38 -0800)
Conflicts:
src/libsyntax/ext/source_util.rs

13 files changed:
1  2 
src/librustc/driver/driver.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/liveness.rs
src/librustc/middle/trans/base.rs
src/librustc/rustc.rs
src/libsyntax/ast.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/quote.rs
src/libsyntax/ext/source_util.rs
src/libsyntax/parse/lexer.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/libsyntax/syntax.rc

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index db77166bfe316405f0b1d07efca7dea9c7a1789b,0000000000000000000000000000000000000000..3cca48c7508911d5443807d75dc22a86237e8178
mode 100644,000000..100644
--- /dev/null
@@@ -1,388 -1,0 +1,399 @@@
- use codemap::span;
 +use mod ast;
 +use mod parse::token;
 +
-         Some(@codemap::expanded_from(cr)) => {
++use codemap::{span, BytePos};
 +use ext::base::ext_ctxt;
 +use token::*;
 +
 +/**
 +*
 +* Quasiquoting works via token trees.
 +*
 +* This is registered as a expression syntax extension called quote! that lifts
 +* its argument token-tree to an AST representing the construction of the same
 +* token tree, with ast::tt_nonterminal nodes interpreted as antiquotes
 +* (splices).
 +*
 +*/
 +
 +pub mod rt {
 +    pub use ast::*;
 +    pub use parse::token::*;
 +    pub use parse::new_parser_from_tt;
++    pub use codemap::BytePos;
++    pub use codemap::span;
 +}
 +
 +pub fn expand_quote_tokens(cx: ext_ctxt,
 +                           sp: span,
 +                           tts: ~[ast::token_tree]) -> base::mac_result {
 +    base::mr_expr(expand_tt(cx, sp, tts))
 +}
 +
 +pub fn expand_quote_expr(cx: ext_ctxt,
 +                         sp: span,
 +                         tts: ~[ast::token_tree]) -> base::mac_result {
 +    base::mr_expr(expand_parse_call(cx, sp, ~"parse_expr", ~[], tts))
 +}
 +
 +pub fn expand_quote_item(cx: ext_ctxt,
 +                         sp: span,
 +                         tts: ~[ast::token_tree]) -> base::mac_result {
 +    let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]);
 +    base::mr_expr(expand_parse_call(cx, sp, ~"parse_item",
 +                                    ~[e_attrs], tts))
 +}
 +
 +pub fn expand_quote_pat(cx: ext_ctxt,
 +                        sp: span,
 +                        tts: ~[ast::token_tree]) -> base::mac_result {
 +    let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true));
 +    base::mr_expr(expand_parse_call(cx, sp, ~"parse_pat",
 +                                    ~[e_refutable], tts))
 +}
 +
 +pub fn expand_quote_type(cx: ext_ctxt,
 +                         sp: span,
 +                         tts: ~[ast::token_tree]) -> base::mac_result {
 +    let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false));
 +    base::mr_expr(expand_parse_call(cx, sp, ~"parse_type",
 +                                    ~[e_param_colons], tts))
 +}
 +
 +pub fn expand_quote_stmt(cx: ext_ctxt,
 +                         sp: span,
 +                         tts: ~[ast::token_tree]) -> base::mac_result {
 +    let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]);
 +    base::mr_expr(expand_parse_call(cx, sp, ~"parse_stmt",
 +                                    ~[e_attrs], tts))
 +}
 +
 +fn ids_ext(cx: ext_ctxt, strs: ~[~str]) -> ~[ast::ident] {
 +    strs.map(|str| cx.parse_sess().interner.intern(@*str))
 +}
 +
 +fn id_ext(cx: ext_ctxt, str: ~str) -> ast::ident {
 +    cx.parse_sess().interner.intern(@str)
 +}
 +
 +fn mk_option_span(cx: ext_ctxt,
 +                  qsp: span,
 +                  sp: Option<span>) -> @ast::expr {
 +    match sp {
 +        None => build::mk_path(cx, qsp, ids_ext(cx, ~[~"None"])),
 +        Some(sp) => {
 +            build::mk_call(cx, qsp,
 +                           ids_ext(cx, ~[~"Some"]),
 +                           ~[build::mk_managed(cx, qsp,
 +                                               mk_span(cx, qsp, sp))])
 +        }
 +    }
 +}
 +
 +fn mk_span(cx: ext_ctxt, qsp: span, sp: span) -> @ast::expr {
 +
 +    let e_expn_info = match sp.expn_info {
 +        None => build::mk_path(cx, qsp, ids_ext(cx, ~[~"None"])),
-     build::mk_rec_e(cx, qsp,
++        Some(@codemap::ExpandedFrom(cr)) => {
 +            let e_callee =
 +                build::mk_rec_e(
 +                    cx, qsp,
 +                    ~[{ident: id_ext(cx, ~"name"),
 +                       ex: build::mk_uniq_str(cx, qsp,
 +                                              cr.callie.name)},
 +                      {ident: id_ext(cx, ~"span"),
 +                       ex: mk_option_span(cx, qsp, cr.callie.span)}]);
 +
 +            let e_expn_info_ =
 +                build::mk_call(
 +                    cx, qsp,
 +                    ids_ext(cx, ~[~"expanded_from"]),
 +                    ~[build::mk_rec_e(
 +                        cx, qsp,
 +                        ~[{ident: id_ext(cx, ~"call_site"),
 +                           ex: mk_span(cx, qsp, cr.call_site)},
 +                          {ident: id_ext(cx, ~"callie"),
 +                           ex: e_callee}])]);
 +
 +            build::mk_call(cx, qsp,
 +                           ids_ext(cx, ~[~"Some"]),
 +                           ~[build::mk_managed(cx, qsp, e_expn_info_)])
 +        }
 +    };
 +
-                        ex: build::mk_uint(cx, qsp, sp.lo) },
++    let span_path = ids_ext(
++        cx, ~[~"syntax", ~"ext", ~"quote", ~"rt", ~"span"]);
++
++    build::mk_struct_e(cx, qsp,
++                       span_path,
 +                    ~[{ident: id_ext(cx, ~"lo"),
-                        ex: build::mk_uint(cx, qsp, sp.hi) },
++                       ex: mk_bytepos(cx, qsp, sp.lo) },
 +
 +                      {ident: id_ext(cx, ~"hi"),
++                       ex: mk_bytepos(cx, qsp, sp.hi) },
 +
 +                      {ident: id_ext(cx, ~"expn_info"),
 +                       ex: e_expn_info}])
 +}
 +
 +// Lift an ident to the expr that evaluates to that ident.
 +//
 +// NB: this identifies the interner used when re-parsing the token tree
 +// with the interner used during initial parse. This is _wrong_ and we
 +// should be emitting a &str here and the token type should be ok with
 +// &static/str or &session/str. Longer-term issue.
 +fn mk_ident(cx: ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr {
 +    build::mk_struct_e(cx, sp,
 +                       ids_ext(cx, ~[~"ident"]),
 +                       ~[{ident: id_ext(cx, ~"repr"),
 +                          ex: build::mk_uint(cx, sp, ident.repr) }])
 +}
 +
++fn mk_bytepos(cx: ext_ctxt, sp: span, bpos: BytePos) -> @ast::expr {
++    let path = ids_ext(cx, ~[~"syntax", ~"ext", ~"quote", ~"rt", ~"BytePos"]);
++    let arg = build::mk_uint(cx, sp, bpos.to_uint());
++    build::mk_call(cx, sp, path, ~[arg])
++}
 +
 +fn mk_binop(cx: ext_ctxt, sp: span, bop: token::binop) -> @ast::expr {
 +    let name = match bop {
 +        PLUS => "PLUS",
 +        MINUS => "MINUS",
 +        STAR => "STAR",
 +        SLASH => "SLASH",
 +        PERCENT => "PERCENT",
 +        CARET => "CARET",
 +        AND => "AND",
 +        OR => "OR",
 +        SHL => "SHL",
 +        SHR => "SHR"
 +    };
 +    build::mk_path(cx, sp,
 +                   ids_ext(cx, ~[name.to_owned()]))
 +}
 +
 +fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr {
 +
 +    match tok {
 +        BINOP(binop) => {
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"BINOP"]),
 +                                  ~[mk_binop(cx, sp, binop)]);
 +        }
 +        BINOPEQ(binop) => {
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"BINOPEQ"]),
 +                                  ~[mk_binop(cx, sp, binop)]);
 +        }
 +
 +        LIT_INT(i, ity) => {
 +            let s_ity = match ity {
 +                ast::ty_i => ~"ty_i",
 +                ast::ty_char => ~"ty_char",
 +                ast::ty_i8 => ~"ty_i8",
 +                ast::ty_i16 => ~"ty_i16",
 +                ast::ty_i32 => ~"ty_i32",
 +                ast::ty_i64 => ~"ty_i64"
 +            };
 +            let e_ity =
 +                build::mk_path(cx, sp,
 +                               ids_ext(cx, ~[s_ity]));
 +
 +            let e_i64 = build::mk_lit(cx, sp, ast::lit_int(i, ast::ty_i64));
 +
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"LIT_INT"]),
 +                                  ~[e_i64, e_ity]);
 +        }
 +
 +        LIT_UINT(u, uty) => {
 +            let s_uty = match uty {
 +                ast::ty_u => ~"ty_u",
 +                ast::ty_u8 => ~"ty_u8",
 +                ast::ty_u16 => ~"ty_u16",
 +                ast::ty_u32 => ~"ty_u32",
 +                ast::ty_u64 => ~"ty_u64"
 +            };
 +            let e_uty =
 +                build::mk_path(cx, sp,
 +                               ids_ext(cx, ~[s_uty]));
 +
 +            let e_u64 = build::mk_lit(cx, sp, ast::lit_uint(u, ast::ty_u64));
 +
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"LIT_UINT"]),
 +                                  ~[e_u64, e_uty]);
 +        }
 +
 +        LIT_INT_UNSUFFIXED(i) => {
 +            let e_i64 = build::mk_lit(cx, sp,
 +                                      ast::lit_int(i, ast::ty_i64));
 +
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"LIT_INT_UNSUFFIXED"]),
 +                                  ~[e_i64]);
 +        }
 +
 +        LIT_FLOAT(fident, fty) => {
 +            let s_fty = match fty {
 +                ast::ty_f => ~"ty_f",
 +                ast::ty_f32 => ~"ty_f32",
 +                ast::ty_f64 => ~"ty_f64"
 +            };
 +            let e_fty =
 +                build::mk_path(cx, sp,
 +                               ids_ext(cx, ~[s_fty]));
 +
 +            let e_fident = mk_ident(cx, sp, fident);
 +
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"LIT_FLOAT"]),
 +                                  ~[e_fident, e_fty]);
 +        }
 +
 +        LIT_STR(ident) => {
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"LIT_STR"]),
 +                                  ~[mk_ident(cx, sp, ident)]);
 +        }
 +
 +        IDENT(ident, b) => {
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"IDENT"]),
 +                                  ~[mk_ident(cx, sp, ident),
 +                                    build::mk_lit(cx, sp, ast::lit_bool(b))]);
 +        }
 +
 +        DOC_COMMENT(ident) => {
 +            return build::mk_call(cx, sp,
 +                                  ids_ext(cx, ~[~"DOC_COMMENT"]),
 +                                  ~[mk_ident(cx, sp, ident)]);
 +        }
 +
 +        INTERPOLATED(_) => fail ~"quote! with interpolated token",
 +
 +        _ => ()
 +    }
 +
 +    let name = match tok {
 +        EQ => "EQ",
 +        LT => "LT",
 +        LE => "LE",
 +        EQEQ => "EQEQ",
 +        NE => "NE",
 +        GE => "GE",
 +        GT => "GT",
 +        ANDAND => "ANDAND",
 +        OROR => "OROR",
 +        NOT => "NOT",
 +        TILDE => "TILDE",
 +        AT => "AT",
 +        DOT => "DOT",
 +        DOTDOT => "DOTDOT",
 +        ELLIPSIS => "ELLIPSIS",
 +        COMMA => "COMMA",
 +        SEMI => "SEMI",
 +        COLON => "COLON",
 +        MOD_SEP => "MOD_SEP",
 +        RARROW => "RARROW",
 +        LARROW => "LARROW",
 +        DARROW => "DARROW",
 +        FAT_ARROW => "FAT_ARROW",
 +        LPAREN => "LPAREN",
 +        RPAREN => "RPAREN",
 +        LBRACKET => "LBRACKET",
 +        RBRACKET => "RBRACKET",
 +        LBRACE => "LBRACE",
 +        RBRACE => "RBRACE",
 +        POUND => "POUND",
 +        DOLLAR => "DOLLAR",
 +        UNDERSCORE => "UNDERSCORE",
 +        EOF => "EOF",
 +        _ => fail
 +    };
 +    build::mk_path(cx, sp,
 +                   ids_ext(cx, ~[name.to_owned()]))
 +}
 +
 +
 +fn mk_tt(cx: ext_ctxt, sp: span, tt: &ast::token_tree) -> @ast::expr {
 +    match *tt {
 +        ast::tt_tok(sp, tok) =>
 +        build::mk_call(cx, sp,
 +                       ids_ext(cx, ~[~"tt_tok"]),
 +                       ~[mk_span(cx, sp, sp),
 +                         mk_token(cx, sp, tok)]),
 +
 +        ast::tt_delim(tts) => {
 +            let e_tts = tts.map(|tt| mk_tt(cx, sp, tt));
 +            build::mk_call(cx, sp,
 +                           ids_ext(cx, ~[~"tt_delim"]),
 +                           ~[build::mk_uniq_vec_e(cx, sp, e_tts)])
 +        }
 +
 +        ast::tt_seq(*) => fail ~"tt_seq in quote!",
 +
 +        ast::tt_nonterminal(sp, ident) =>
 +        build::mk_copy(cx, sp, build::mk_path(cx, sp, ~[ident]))
 +    }
 +}
 +
 +
 +fn expand_tt(cx: ext_ctxt,
 +             sp: span,
 +             tts: ~[ast::token_tree]) -> @ast::expr {
 +    // NB: It appears that the main parser loses its mind if we consider
 +    // $foo as a tt_nonterminal during the main parse, so we have to re-parse
 +    // under quote_depth > 0. This is silly and should go away; the _guess_ is
 +    // it has to do with transition away from supporting old-style macros, so
 +    // try removing it when enough of them are gone.
 +    let p = parse::new_parser_from_tt(cx.parse_sess(), cx.cfg(), tts);
 +    p.quote_depth += 1u;
 +    let tq = dvec::DVec();
 +    while p.token != token::EOF {
 +        tq.push(p.parse_token_tree());
 +    }
 +    let tts = tq.get();
 +
 +    // We want to emit a block expression that does a sequence of 'use's to
 +    // import the runtime module, followed by a tt expression.
 +    let uses = ~[ build::mk_glob_use(cx, sp, ids_ext(cx, ~[~"syntax",
 +                                                           ~"ext",
 +                                                           ~"quote",
 +                                                           ~"rt"])) ];
 +    build::mk_block(cx, sp, uses, ~[],
 +                    Some(mk_tt(cx, sp, &ast::tt_delim(tts))))
 +}
 +
 +fn expand_parse_call(cx: ext_ctxt,
 +                     sp: span,
 +                     parse_method: ~str,
 +                     arg_exprs: ~[@ast::expr],
 +                     tts: ~[ast::token_tree]) -> @ast::expr {
 +    let tt_expr = expand_tt(cx, sp, tts);
 +
 +    let cfg_call = || build::mk_call_(
 +        cx, sp, build::mk_access(cx, sp, ids_ext(cx, ~[~"ext_cx"]),
 +                                 id_ext(cx, ~"cfg")), ~[]);
 +
 +    let parse_sess_call = || build::mk_call_(
 +        cx, sp, build::mk_access(cx, sp, ids_ext(cx, ~[~"ext_cx"]),
 +                                 id_ext(cx, ~"parse_sess")), ~[]);
 +
 +    let new_parser_call =
 +        build::mk_call(cx, sp,
 +                       ids_ext(cx, ~[~"syntax",
 +                                     ~"ext",
 +                                     ~"quote",
 +                                     ~"rt",
 +                                     ~"new_parser_from_tt"]),
 +                       ~[parse_sess_call(),
 +                         cfg_call(),
 +                         build::mk_uniq_vec_e(cx, sp, ~[tt_expr])]);
 +
 +    build::mk_call_(cx, sp,
 +                    build::mk_access_(cx, sp, new_parser_call,
 +                                      id_ext(cx, parse_method)),
 +                    arg_exprs)
 +}
 +
Simple merge
Simple merge
index 49c3d38ce554be7428e37204a639fa19f39d8bfd,74d06789ad8995c34a3be35789b620791aa8badb..2f96f6ba0a098f05585f6dfc06797f5bc634d0c3
@@@ -3414,20 -3410,13 +3414,19 @@@ impl Parser 
              let pth = self.parse_path_without_tps();
              self.expect(token::NOT);
              let id = self.parse_ident();
 -            let tts = self.parse_unspanned_seq(
 -                token::LPAREN, token::RPAREN, seq_sep_none(),
 -                |p| p.parse_token_tree());
 +            let tts = match self.token {
 +              token::LPAREN | token::LBRACE => {
 +                let ket = token::flip_delimiter(copy self.token);
 +                self.parse_unspanned_seq(copy self.token, ket,
 +                                         seq_sep_none(),
 +                                         |p| p.parse_token_tree())
 +              }
 +              _ => self.fatal(~"expected open delimiter")
 +            };
              let m = ast::mac_invoc_tt(pth, tts);
              let m: ast::mac = {node: m,
-                                span: {lo: self.span.lo,
-                                       hi: self.span.hi,
-                                       expn_info: None}};
+                                span: mk_sp(self.span.lo,
+                                            self.span.hi)};
              let item_ = item_mac(m);
              return iovi_item(self.mk_item(lo, self.last_span.hi, id, item_,
                                            visibility, attrs));
Simple merge
Simple merge