Skip to content

Commit

Permalink
auto merge of #5071 : luqmana/rust/derec, r=pcwalton
Browse files Browse the repository at this point in the history
Rid libsyntax of records and get rid of the last piece in `librustc/front/test.rs`.
  • Loading branch information
bors committed Feb 21, 2013
2 parents c0218fb + b02f5c2 commit 4a5e8c5
Show file tree
Hide file tree
Showing 25 changed files with 330 additions and 241 deletions.
4 changes: 2 additions & 2 deletions src/libfuzzer/fuzzer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub fn parse_and_print(code: @~str) -> ~str {
sess.cm,
// Assuming there are no token_trees
syntax::parse::token::mk_fake_ident_interner(),
sess.span_diagnostic,
copy sess.span_diagnostic,
crate,
filename.to_str(),
rdr, a,
Expand Down Expand Up @@ -622,7 +622,7 @@ pub fn check_variants(files: &[Path], cx: Context) {
sess.cm,
// Assuming no token_trees
syntax::parse::token::mk_fake_ident_interner(),
sess.span_diagnostic,
copy sess.span_diagnostic,
crate,
file_str,
rdr, a,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use syntax::ast::node_id;
use syntax::ast::{int_ty, uint_ty, float_ty};
use syntax::codemap::span;
use syntax::diagnostic;
use syntax::parse::parse_sess;
use syntax::parse::ParseSess;
use syntax::{ast, codemap};
use syntax;

Expand Down Expand Up @@ -151,7 +151,7 @@ pub struct Session_ {
targ_cfg: @config,
opts: @options,
cstore: @mut metadata::cstore::CStore,
parse_sess: parse_sess,
parse_sess: @mut ParseSess,
codemap: @codemap::CodeMap,
// For a library crate, this is always none
main_fn: @mut Option<(node_id, codemap::span)>,
Expand Down
18 changes: 8 additions & 10 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

// Code that generates a test runner to run all the tests in a crate

// XXX - Need to finish off libsyntax first
#[legacy_records];
#[allow(structural_records)];

use core::prelude::*;

use driver::session;
Expand All @@ -25,7 +21,7 @@ use core::option;
use core::vec;
use syntax::ast_util::*;
use syntax::attr;
use syntax::codemap::{dummy_sp, span, ExpandedFrom};
use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan};
use syntax::codemap;
use syntax::fold;
use syntax::print::pprust;
Expand Down Expand Up @@ -81,11 +77,13 @@ fn generate_test_harness(sess: session::Session,
testfns: ~[]
};

cx.ext_cx.bt_push(ExpandedFrom({
call_site: dummy_sp(),
callie: {
name: ~"test",
span: None}}));
cx.ext_cx.bt_push(ExpandedFrom(CallInfo {
call_site: dummy_sp(),
callee: NameAndSpan {
name: ~"test",
span: None
}
}));

let precursor = @fold::AstFoldFns {
fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,18 +1193,18 @@ fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
#[cfg(test)]
trait fake_ext_ctxt {
fn cfg() -> ast::crate_cfg;
fn parse_sess() -> parse::parse_sess;
fn parse_sess() -> @mut parse::ParseSess;
fn call_site() -> span;
fn ident_of(+st: ~str) -> ast::ident;
}

#[cfg(test)]
type fake_session = parse::parse_sess;
type fake_session = @mut parse::ParseSess;

#[cfg(test)]
impl fake_ext_ctxt for fake_session {
fn cfg() -> ast::crate_cfg { ~[] }
fn parse_sess() -> parse::parse_sess { self }
fn parse_sess() -> @mut parse::ParseSess { self }
fn call_site() -> span {
codemap::span {
lo: codemap::BytePos(0),
Expand Down
9 changes: 7 additions & 2 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,16 @@ pub struct LocWithOpt {
// used to be structural records. Better names, anyone?
pub struct FileMapAndLine {fm: @FileMap, line: uint}
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
pub struct NameAndSpan {name: ~str, span: Option<span>}

pub struct CallInfo {
call_site: span,
callee: NameAndSpan
}

/// Extra information for tracking macro expansion of spans
pub enum ExpnInfo {
ExpandedFrom({call_site: span,
callie: {name: ~str, span: Option<span>}})
ExpandedFrom(CallInfo)
}

pub type FileName = ~str;
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ fn highlight_lines(cm: @codemap::CodeMap,

fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) {
do option::iter(&sp.expn_info) |ei| {
let ss = option::map_default(&ei.callie.span, @~"",
let ss = option::map_default(&ei.callee.span, @~"",
|span| @cm.span_to_str(*span));
print_diagnostic(*ss, note,
fmt!("in expansion of %s!", ei.callie.name));
fmt!("in expansion of %s!", ei.callee.name));
let ss = cm.span_to_str(ei.call_site);
print_diagnostic(ss, note, ~"expansion site");
print_macro_backtrace(cm, ei.call_site);
Expand Down
19 changes: 10 additions & 9 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use core::prelude::*;
use ast;
use codemap;
use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom, dummy_sp};
use codemap::{CallInfo, NameAndSpan};
use diagnostic::span_handler;
use ext;
use parse;
Expand Down Expand Up @@ -166,7 +167,7 @@ pub fn syntax_expander_table() -> SyntaxExtensions {
// -> expn_info of their expansion context stored into their span.
pub trait ext_ctxt {
fn codemap(@mut self) -> @CodeMap;
fn parse_sess(@mut self) -> parse::parse_sess;
fn parse_sess(@mut self) -> @mut parse::ParseSess;
fn cfg(@mut self) -> ast::crate_cfg;
fn call_site(@mut self) -> span;
fn print_backtrace(@mut self);
Expand All @@ -190,22 +191,22 @@ pub trait ext_ctxt {
fn ident_of(@mut self, st: ~str) -> ast::ident;
}

pub fn mk_ctxt(parse_sess: parse::parse_sess,
pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
cfg: ast::crate_cfg) -> ext_ctxt {
struct CtxtRepr {
parse_sess: parse::parse_sess,
parse_sess: @mut parse::ParseSess,
cfg: ast::crate_cfg,
backtrace: Option<@ExpnInfo>,
mod_path: ~[ast::ident],
trace_mac: bool
}
impl ext_ctxt for CtxtRepr {
fn codemap(@mut self) -> @CodeMap { self.parse_sess.cm }
fn parse_sess(@mut self) -> parse::parse_sess { self.parse_sess }
fn parse_sess(@mut self) -> @mut parse::ParseSess { self.parse_sess }
fn cfg(@mut self) -> ast::crate_cfg { self.cfg }
fn call_site(@mut self) -> span {
match self.backtrace {
Some(@ExpandedFrom({call_site: cs, _})) => cs,
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
None => self.bug(~"missing top span")
}
}
Expand All @@ -216,18 +217,18 @@ pub fn mk_ctxt(parse_sess: parse::parse_sess,
fn mod_path(@mut self) -> ~[ast::ident] { return self.mod_path; }
fn bt_push(@mut self, ei: codemap::ExpnInfo) {
match ei {
ExpandedFrom({call_site: cs, callie: ref callie}) => {
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
self.backtrace =
Some(@ExpandedFrom({
Some(@ExpandedFrom(CallInfo {
call_site: span {lo: cs.lo, hi: cs.hi,
expn_info: self.backtrace},
callie: (*callie)}));
callee: (*callee)}));
}
}
}
fn bt_pop(@mut self) {
match self.backtrace {
Some(@ExpandedFrom({
Some(@ExpandedFrom(CallInfo {
call_site: span {expn_info: prev, _}, _
})) => {
self.backtrace = prev
Expand Down
33 changes: 14 additions & 19 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use ext::build;
use core::dvec;
use core::option;

pub struct Field {
ident: ast::ident,
ex: @ast::expr
}

pub fn mk_expr(cx: ext_ctxt,
sp: codemap::span,
expr: ast::expr_)
Expand Down Expand Up @@ -147,47 +152,37 @@ pub fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
pub fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::expr_vstore_uniq)
}
pub fn mk_field(sp: span, f: &{ident: ast::ident, ex: @ast::expr})
-> ast::field {
pub fn mk_field(sp: span, f: &Field) -> ast::field {
codemap::spanned {
node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex },
span: sp,
}
}
pub fn mk_fields(sp: span, fields: ~[{ident: ast::ident, ex: @ast::expr}])
-> ~[ast::field] {
pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] {
fields.map(|f| mk_field(sp, f))
}
pub fn mk_rec_e(cx: ext_ctxt,
sp: span,
fields: ~[{ident: ast::ident, ex: @ast::expr}])
-> @ast::expr {
pub fn mk_rec_e(cx: ext_ctxt, sp: span, fields: ~[Field]) -> @ast::expr {
mk_expr(cx, sp, ast::expr_rec(mk_fields(sp, fields),
option::None::<@ast::expr>))
}
pub fn mk_struct_e(cx: ext_ctxt,
sp: span,
ctor_path: ~[ast::ident],
fields: ~[{ident: ast::ident, ex: @ast::expr}])
-> @ast::expr {
pub fn mk_struct_e(cx: ext_ctxt, sp: span, ctor_path: ~[ast::ident],
fields: ~[Field]) -> @ast::expr {
mk_expr(cx, sp,
ast::expr_struct(mk_raw_path(sp, ctor_path),
mk_fields(sp, fields),
option::None::<@ast::expr>))
}
pub fn mk_global_struct_e(cx: ext_ctxt,
sp: span,
pub fn mk_global_struct_e(cx: ext_ctxt, sp: span,
ctor_path: ~[ast::ident],
fields: ~[{ident: ast::ident, ex: @ast::expr}])
fields: ~[Field])
-> @ast::expr {
mk_expr(cx, sp,
ast::expr_struct(mk_raw_path_global(sp, ctor_path),
mk_fields(sp, fields),
option::None::<@ast::expr>))
}
pub fn mk_glob_use(cx: ext_ctxt,
sp: span,
path: ~[ast::ident]) -> @ast::view_item {
pub fn mk_glob_use(cx: ext_ctxt, sp: span, path: ~[ast::ident])
-> @ast::view_item {
let glob = @codemap::spanned {
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
span: sp,
Expand Down
48 changes: 33 additions & 15 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ast::{crate, expr_, expr_mac, mac_invoc_tt};
use ast::{tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
use ast;
use attr;
use codemap::{span, ExpandedFrom};
use codemap::{span, CallInfo, ExpandedFrom, NameAndSpan};
use ext::base::*;
use fold::*;
use parse::{parser, parse_expr_from_source_str, new_parser_from_tts};
Expand Down Expand Up @@ -48,8 +48,12 @@ pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt,
}
Some(NormalTT(SyntaxExpanderTT{expander: exp,
span: exp_sp})) => {
cx.bt_push(ExpandedFrom({call_site: s,
callie: {name: *extname, span: exp_sp}}));
cx.bt_push(ExpandedFrom(CallInfo{
call_site: s,
callee: NameAndSpan {
name: *extname, span: exp_sp
}
}));

let expanded = match exp(cx, (*mac).span, (*tts)) {
MRExpr(e) => e,
Expand Down Expand Up @@ -105,9 +109,13 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt,
match exts.find(&mname) {
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
Some(ItemDecorator(dec_fn)) => {
cx.bt_push(ExpandedFrom({call_site: attr.span,
callie: {name: /*bad*/ copy *mname,
span: None}}));
cx.bt_push(ExpandedFrom(CallInfo {
call_site: attr.span,
callee: NameAndSpan {
name: /*bad*/ copy *mname,
span: None
}
}));
let r = dec_fn(cx, attr.span, attr.node.value, items);
cx.bt_pop();
r
Expand Down Expand Up @@ -170,9 +178,13 @@ pub fn expand_item_mac(exts: SyntaxExtensions,
given '%s'", *extname,
*cx.parse_sess().interner.get(it.ident)));
}
cx.bt_push(ExpandedFrom({call_site: it.span,
callie: {name: *extname,
span: (*expand).span}}));
cx.bt_push(ExpandedFrom(CallInfo {
call_site: it.span,
callee: NameAndSpan {
name: *extname,
span: (*expand).span
}
}));
((*expand).expander)(cx, it.span, tts)
}
Some(ItemTT(ref expand)) => {
Expand All @@ -181,9 +193,13 @@ pub fn expand_item_mac(exts: SyntaxExtensions,
fmt!("macro %s! expects an ident argument",
*extname));
}
cx.bt_push(ExpandedFrom({call_site: it.span,
callie: {name: *extname,
span: (*expand).span}}));
cx.bt_push(ExpandedFrom(CallInfo {
call_site: it.span,
callee: NameAndSpan {
name: *extname,
span: (*expand).span
}
}));
((*expand).expander)(cx, it.span, it.ident, tts)
}
_ => cx.span_fatal(
Expand Down Expand Up @@ -228,8 +244,10 @@ pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt,

Some(NormalTT(
SyntaxExpanderTT{expander: exp, span: exp_sp})) => {
cx.bt_push(ExpandedFrom(
{call_site: sp, callie: {name: *extname, span: exp_sp}}));
cx.bt_push(ExpandedFrom(CallInfo {
call_site: sp,
callee: NameAndSpan { name: *extname, span: exp_sp }
}));
let expanded = match exp(cx, mac.span, tts) {
MRExpr(e) =>
@codemap::spanned { node: stmt_expr(e, cx.next_id()),
Expand Down Expand Up @@ -321,7 +339,7 @@ pub fn core_macros() -> ~str {
}";
}

pub fn expand_crate(parse_sess: parse::parse_sess,
pub fn expand_crate(parse_sess: @mut parse::ParseSess,
cfg: ast::crate_cfg, c: @crate) -> @crate {
let exts = syntax_expander_table();
let afp = default_ast_fold();
Expand Down
16 changes: 12 additions & 4 deletions src/libsyntax/ext/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,18 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
sp,
make_path_vec(cx, @~"Conv"),
~[
{ident: intr.intern(@~"flags"), ex: flags_expr},
{ident: intr.intern(@~"width"), ex: width_expr},
{ident: intr.intern(@~"precision"), ex: precision_expr},
{ident: intr.intern(@~"ty"), ex: ty_expr},
build::Field {
ident: intr.intern(@~"flags"), ex: flags_expr
},
build::Field {
ident: intr.intern(@~"width"), ex: width_expr
},
build::Field {
ident: intr.intern(@~"precision"), ex: precision_expr
},
build::Field {
ident: intr.intern(@~"ty"), ex: ty_expr
},
]
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/pipes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
tt: ~[ast::token_tree]) -> base::MacResult {
let sess = cx.parse_sess();
let cfg = cx.cfg();
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
let tt_rdr = new_tt_reader(copy cx.parse_sess().span_diagnostic,
cx.parse_sess().interner, None, tt);
let rdr = tt_rdr as reader;
let rust_parser = Parser(sess, cfg, rdr.dup());
Expand Down
Loading

0 comments on commit 4a5e8c5

Please sign in to comment.