From 8e9eba8013490e7b6ba059397bbe73b7128c04b3 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 17 May 2013 18:41:14 +1000 Subject: [PATCH 1/6] syntax/ext: remove the ~str dependence of the deriving code. --- src/libsyntax/ext/deriving/clone.rs | 8 +-- src/libsyntax/ext/deriving/cmp/eq.rs | 8 +-- src/libsyntax/ext/deriving/cmp/ord.rs | 14 ++-- src/libsyntax/ext/deriving/cmp/totaleq.rs | 6 +- src/libsyntax/ext/deriving/cmp/totalord.rs | 6 +- src/libsyntax/ext/deriving/generic.rs | 16 ++--- src/libsyntax/ext/deriving/iter_bytes.rs | 10 +-- src/libsyntax/ext/deriving/rand.rs | 10 +-- src/libsyntax/ext/deriving/to_str.rs | 6 +- src/libsyntax/ext/deriving/ty.rs | 76 +++++++++++----------- 10 files changed, 81 insertions(+), 79 deletions(-) diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index aceb60ebbd7d6..1759cde0fc975 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -21,12 +21,12 @@ pub fn expand_deriving_clone(cx: @ext_ctxt, in_items: ~[@item]) -> ~[@item] { let trait_def = TraitDef { - path: Path::new(~[~"core", ~"clone", ~"Clone"]), + path: Path::new(~["core", "clone", "Clone"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ MethodDef { - name: ~"clone", + name: "clone", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[], @@ -48,12 +48,12 @@ pub fn expand_deriving_deep_clone(cx: @ext_ctxt, in_items: ~[@item]) -> ~[@item] { let trait_def = TraitDef { - path: Path::new(~[~"core", ~"clone", ~"DeepClone"]), + path: Path::new(~["core", "clone", "DeepClone"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ MethodDef { - name: ~"deep_clone", + name: "deep_clone", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[], diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 3d93f844ea3bb..e6fcfdf556354 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -36,7 +36,7 @@ pub fn expand_deriving_eq(cx: @ext_ctxt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], - ret_ty: Literal(Path::new(~[~"bool"])), + ret_ty: Literal(Path::new(~["bool"])), const_nonmatching: true, combine_substructure: $f }, @@ -44,12 +44,12 @@ pub fn expand_deriving_eq(cx: @ext_ctxt, ); let trait_def = TraitDef { - path: Path::new(~[~"core", ~"cmp", ~"Eq"]), + path: Path::new(~["core", "cmp", "Eq"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ - md!(~"eq", cs_eq), - md!(~"ne", cs_ne) + md!("eq", cs_eq), + md!("ne", cs_ne) ] }; diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 5445aef4491be..5aae8454c09b4 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -26,7 +26,7 @@ pub fn expand_deriving_ord(cx: @ext_ctxt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], - ret_ty: Literal(Path::new(~[~"bool"])), + ret_ty: Literal(Path::new(~["bool"])), const_nonmatching: false, combine_substructure: |cx, span, substr| cs_ord($less, $equal, cx, span, substr) @@ -37,15 +37,15 @@ pub fn expand_deriving_ord(cx: @ext_ctxt, let trait_def = TraitDef { - path: Path::new(~[~"core", ~"cmp", ~"Ord"]), + path: Path::new(~["core", "cmp", "Ord"]), // XXX: Ord doesn't imply Eq yet - additional_bounds: ~[Literal(Path::new(~[~"core", ~"cmp", ~"Eq"]))], + additional_bounds: ~[Literal(Path::new(~["core", "cmp", "Eq"]))], generics: LifetimeBounds::empty(), methods: ~[ - md!(~"lt", true, false), - md!(~"le", true, true), - md!(~"gt", false, false), - md!(~"ge", false, true) + md!("lt", true, false), + md!("le", true, true), + md!("gt", false, false), + md!("ge", false, true) ] }; diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 4541569b829ac..9ab44f506bade 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -26,16 +26,16 @@ pub fn expand_deriving_totaleq(cx: @ext_ctxt, } let trait_def = TraitDef { - path: Path::new(~[~"core", ~"cmp", ~"TotalEq"]), + path: Path::new(~["core", "cmp", "TotalEq"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ MethodDef { - name: ~"equals", + name: "equals", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], - ret_ty: Literal(Path::new(~[~"bool"])), + ret_ty: Literal(Path::new(~["bool"])), const_nonmatching: true, combine_substructure: cs_equals } diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 8f156e6a9e315..1b6ea16b86e2d 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -20,16 +20,16 @@ pub fn expand_deriving_totalord(cx: @ext_ctxt, mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { let trait_def = TraitDef { - path: Path::new(~[~"core", ~"cmp", ~"TotalOrd"]), + path: Path::new(~["core", "cmp", "TotalOrd"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ MethodDef { - name: ~"cmp", + name: "cmp", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], - ret_ty: Literal(Path::new(~[~"core", ~"cmp", ~"Ordering"])), + ret_ty: Literal(Path::new(~["core", "cmp", "Ordering"])), const_nonmatching: false, combine_substructure: cs_cmp } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 2fc9dadfe2c1b..ae9c4c1fefb44 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -195,13 +195,13 @@ pub fn expand_deriving_generic(cx: @ext_ctxt, pub struct TraitDef<'self> { /// Path of the trait, including any type parameters - path: Path, + path: Path<'self>, /// Additional bounds required of any type parameters of the type, /// other than the current trait - additional_bounds: ~[Ty], + additional_bounds: ~[Ty<'self>], /// Any extra lifetimes and/or bounds, e.g. `D: std::serialize::Decoder` - generics: LifetimeBounds, + generics: LifetimeBounds<'self>, methods: ~[MethodDef<'self>] } @@ -209,20 +209,20 @@ pub struct TraitDef<'self> { pub struct MethodDef<'self> { /// name of the method - name: ~str, + name: &'self str, /// List of generics, e.g. `R: core::rand::Rng` - generics: LifetimeBounds, + generics: LifetimeBounds<'self>, /// Whether there is a self argument (outer Option) i.e. whether /// this is a static function, and whether it is a pointer (inner /// Option) - explicit_self: Option>, + explicit_self: Option>>, /// Arguments other than the self argument - args: ~[Ty], + args: ~[Ty<'self>], /// Return type - ret_ty: Ty, + ret_ty: Ty<'self>, /// if the value of the nonmatching enums is independent of the /// actual enum variants, i.e. can use _ => .. match. diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 1c9ec6ece2e1d..9b8f127d42a0b 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -19,19 +19,19 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt, mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { let trait_def = TraitDef { - path: Path::new(~[~"core", ~"to_bytes", ~"IterBytes"]), + path: Path::new(~["core", "to_bytes", "IterBytes"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ MethodDef { - name: ~"iter_bytes", + name: "iter_bytes", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[ - Literal(Path::new(~[~"bool"])), - Literal(Path::new(~[~"core", ~"to_bytes", ~"Cb"])) + Literal(Path::new(~["bool"])), + Literal(Path::new(~["core", "to_bytes", "Cb"])) ], - ret_ty: Literal(Path::new(~[~"bool"])), + ret_ty: Literal(Path::new(~["bool"])), const_nonmatching: false, combine_substructure: iter_bytes_substructure } diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 2d91fcd346ae5..2fb47c1e53ec2 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -21,20 +21,20 @@ pub fn expand_deriving_rand(cx: @ext_ctxt, in_items: ~[@item]) -> ~[@item] { let trait_def = TraitDef { - path: Path::new(~[~"core", ~"rand", ~"Rand"]), + path: Path::new(~["core", "rand", "Rand"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ MethodDef { - name: ~"rand", + name: "rand", generics: LifetimeBounds { lifetimes: ~[], - bounds: ~[(~"R", - ~[ Path::new(~[~"core", ~"rand", ~"Rng"]) ])] + bounds: ~[("R", + ~[ Path::new(~["core", "rand", "Rng"]) ])] }, explicit_self: None, args: ~[ - Ptr(~Literal(Path::new_local(~"R")), + Ptr(~Literal(Path::new_local("R")), Borrowed(None, ast::m_mutbl)) ], ret_ty: Self, diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index f155cb3790faa..0c12a1948cd4c 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -20,16 +20,16 @@ pub fn expand_deriving_to_str(cx: @ext_ctxt, in_items: ~[@item]) -> ~[@item] { let trait_def = TraitDef { - path: Path::new(~[~"core", ~"to_str", ~"ToStr"]), + path: Path::new(~["core", "to_str", "ToStr"]), additional_bounds: ~[], generics: LifetimeBounds::empty(), methods: ~[ MethodDef { - name: ~"to_str", + name: "to_str", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[], - ret_ty: Ptr(~Literal(Path::new_local(~"str")), Owned), + ret_ty: Ptr(~Literal(Path::new_local("str")), Owned), const_nonmatching: false, combine_substructure: to_str_substructure } diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 5fc3aeb789c10..bbc6b6634e383 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -21,31 +21,30 @@ use codemap::{span,respan}; use opt_vec; /// The types of pointers -#[deriving(Eq)] -pub enum PtrTy { +pub enum PtrTy<'self> { Owned, // ~ Managed(ast::mutability), // @[mut] - Borrowed(Option<~str>, ast::mutability), // &['lifetime] [mut] + Borrowed(Option<&'self str>, ast::mutability), // &['lifetime] [mut] } /// A path, e.g. `::core::option::Option::` (global). Has support /// for type parameters and a lifetime. -#[deriving(Eq)] -pub struct Path { - path: ~[~str], - lifetime: Option<~str>, - params: ~[~Ty], +pub struct Path<'self> { + path: ~[&'self str], + lifetime: Option<&'self str>, + params: ~[~Ty<'self>], global: bool } -pub impl Path { - fn new(path: ~[~str]) -> Path { +pub impl<'self> Path<'self> { + fn new<'r>(path: ~[&'r str]) -> Path<'r> { Path::new_(path, None, ~[], true) } - fn new_local(path: ~str) -> Path { + fn new_local<'r>(path: &'r str) -> Path<'r> { Path::new_(~[ path ], None, ~[], false) } - fn new_(path: ~[~str], lifetime: Option<~str>, params: ~[~Ty], global: bool) -> Path { + fn new_<'r>(path: ~[&'r str], lifetime: Option<&'r str>, params: ~[~Ty<'r>], global: bool) + -> Path<'r> { Path { path: path, lifetime: lifetime, @@ -56,9 +55,9 @@ pub impl Path { fn to_ty(&self, cx: @ext_ctxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Ty { - build::mk_ty_path_path(cx, span, - self.to_path(cx, span, - self_ty, self_generics)) + build::mk_ty_path_path(cx, span, + self.to_path(cx, span, + self_ty, self_generics)) } fn to_path(&self, cx: @ext_ctxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Path { @@ -75,45 +74,44 @@ pub impl Path { } /// A type. Supports pointers (except for *), Self, and literals -#[deriving(Eq)] -pub enum Ty { +pub enum Ty<'self> { Self, // &/~/@ Ty - Ptr(~Ty, PtrTy), + Ptr(~Ty<'self>, PtrTy<'self>), // mod::mod::Type<[lifetime], [Params...]>, including a plain type // parameter, and things like `int` - Literal(Path), + Literal(Path<'self>), // includes nil - Tuple(~[Ty]) + Tuple(~[Ty<'self>]) } -pub fn borrowed_ptrty() -> PtrTy { +pub fn borrowed_ptrty<'r>() -> PtrTy<'r> { Borrowed(None, ast::m_imm) } -pub fn borrowed(ty: ~Ty) -> Ty { +pub fn borrowed<'r>(ty: ~Ty<'r>) -> Ty<'r> { Ptr(ty, borrowed_ptrty()) } -pub fn borrowed_explicit_self() -> Option> { +pub fn borrowed_explicit_self<'r>() -> Option>> { Some(Some(borrowed_ptrty())) } -pub fn borrowed_self() -> Ty { +pub fn borrowed_self<'r>() -> Ty<'r> { borrowed(~Self) } -pub fn nil_ty() -> Ty { +pub fn nil_ty() -> Ty<'static> { Tuple(~[]) } -fn mk_lifetime(cx: @ext_ctxt, span: span, lt: &Option<~str>) -> Option<@ast::Lifetime> { +fn mk_lifetime(cx: @ext_ctxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> { match *lt { Some(ref s) => Some(@build::mk_lifetime(cx, span, cx.ident_of(*s))), None => None } } -pub impl Ty { +pub impl<'self> Ty<'self> { fn to_ty(&self, cx: @ext_ctxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Ty { match *self { @@ -174,7 +172,7 @@ pub impl Ty { } -fn mk_ty_param(cx: @ext_ctxt, span: span, name: ~str, bounds: ~[Path], +fn mk_ty_param(cx: @ext_ctxt, span: span, name: &str, bounds: &[Path], self_ident: ident, self_generics: &Generics) -> ast::TyParam { let bounds = opt_vec::from( do bounds.map |b| { @@ -192,24 +190,28 @@ fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Gene } /// Lifetimes and bounds on type parameters -pub struct LifetimeBounds { - lifetimes: ~[~str], - bounds: ~[(~str, ~[Path])] +pub struct LifetimeBounds<'self> { + lifetimes: ~[&'self str], + bounds: ~[(&'self str, ~[Path<'self>])] } -pub impl LifetimeBounds { - fn empty() -> LifetimeBounds { +pub impl<'self> LifetimeBounds<'self> { + fn empty() -> LifetimeBounds<'static> { LifetimeBounds { lifetimes: ~[], bounds: ~[] } } fn to_generics(&self, cx: @ext_ctxt, span: span, self_ty: ident, self_generics: &Generics) -> Generics { - let lifetimes = do self.lifetimes.map |<| { - build::mk_lifetime(cx, span, cx.ident_of(lt)) + let lifetimes = do self.lifetimes.map |lt| { + build::mk_lifetime(cx, span, cx.ident_of(*lt)) }; - let ty_params = do self.bounds.map |&(name, bounds)| { - mk_ty_param(cx, span, name, bounds, self_ty, self_generics) + let ty_params = do self.bounds.map |t| { + match t { + &(ref name, ref bounds) => { + mk_ty_param(cx, span, *name, *bounds, self_ty, self_generics) + } + } }; mk_generics(lifetimes, ty_params) } From eea265ea165cb0e6fa989a3712efd701456b265d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 17 May 2013 20:10:26 +1000 Subject: [PATCH 2/6] syntax/ext: Remove the trait-object indirection of the ext_ctxt object. --- src/libsyntax/ext/base.rs | 188 +++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 106 deletions(-) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 2a7f8c8865b81..b387694c6c191 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -202,131 +202,107 @@ pub fn syntax_expander_table() -> SyntaxEnv { // One of these is made during expansion and incrementally updated as we go; // when a macro expansion occurs, the resulting nodes have the backtrace() // -> expn_info of their expansion context stored into their span. -pub trait ext_ctxt { - fn codemap(&self) -> @CodeMap; - fn parse_sess(&self) -> @mut parse::ParseSess; - fn cfg(&self) -> ast::crate_cfg; - fn call_site(&self) -> span; - fn print_backtrace(&self); - fn backtrace(&self) -> Option<@ExpnInfo>; - fn mod_push(&self, mod_name: ast::ident); - fn mod_pop(&self); - fn mod_path(&self) -> ~[ast::ident]; - fn bt_push(&self, ei: codemap::ExpnInfo); - fn bt_pop(&self); - fn span_fatal(&self, sp: span, msg: &str) -> !; - fn span_err(&self, sp: span, msg: &str); - fn span_warn(&self, sp: span, msg: &str); - fn span_unimpl(&self, sp: span, msg: &str) -> !; - fn span_bug(&self, sp: span, msg: &str) -> !; - fn bug(&self, msg: &str) -> !; - fn next_id(&self) -> ast::node_id; - fn trace_macros(&self) -> bool; - fn set_trace_macros(&self, x: bool); - /* for unhygienic identifier transformation */ - fn str_of(&self, id: ast::ident) -> ~str; - fn ident_of(&self, st: &str) -> ast::ident; +pub struct ext_ctxt { + parse_sess: @mut parse::ParseSess, + cfg: ast::crate_cfg, + backtrace: @mut Option<@ExpnInfo>, + + // These two @mut's should really not be here, + // but the self types for CtxtRepr are all wrong + // and there are bugs in the code for object + // types that make this hard to get right at the + // moment. - nmatsakis + mod_path: @mut ~[ast::ident], + trace_mac: @mut bool } -pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) - -> @ext_ctxt { - struct CtxtRepr { - parse_sess: @mut parse::ParseSess, - cfg: ast::crate_cfg, - backtrace: @mut Option<@ExpnInfo>, - - // These two @mut's should really not be here, - // but the self types for CtxtRepr are all wrong - // and there are bugs in the code for object - // types that make this hard to get right at the - // moment. - nmatsakis - mod_path: @mut ~[ast::ident], - trace_mac: @mut bool - } - impl ext_ctxt for CtxtRepr { - fn codemap(&self) -> @CodeMap { self.parse_sess.cm } - fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } - fn cfg(&self) -> ast::crate_cfg { copy self.cfg } - fn call_site(&self) -> span { - match *self.backtrace { - Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, - None => self.bug("missing top span") - } +pub impl ext_ctxt { + fn codemap(&self) -> @CodeMap { self.parse_sess.cm } + fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } + fn cfg(&self) -> ast::crate_cfg { copy self.cfg } + fn call_site(&self) -> span { + match *self.backtrace { + Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, + None => self.bug("missing top span") } - fn print_backtrace(&self) { } - fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace } - fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); } - fn mod_pop(&self) { self.mod_path.pop(); } - fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path } - fn bt_push(&self, ei: codemap::ExpnInfo) { - match ei { - ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { + } + fn print_backtrace(&self) { } + fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace } + fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); } + fn mod_pop(&self) { self.mod_path.pop(); } + fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path } + fn bt_push(&self, ei: codemap::ExpnInfo) { + match ei { + ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { *self.backtrace = Some(@ExpandedFrom(CallInfo { call_site: span {lo: cs.lo, hi: cs.hi, expn_info: *self.backtrace}, callee: copy *callee})); - } } } - fn bt_pop(&self) { - match *self.backtrace { - Some(@ExpandedFrom(CallInfo { - call_site: span {expn_info: prev, _}, _ - })) => { + } + fn bt_pop(&self) { + match *self.backtrace { + Some(@ExpandedFrom( + CallInfo { + call_site: span {expn_info: prev, _}, _ + })) => { *self.backtrace = prev - } - _ => self.bug("tried to pop without a push") } - } - fn span_fatal(&self, sp: span, msg: &str) -> ! { - self.print_backtrace(); - self.parse_sess.span_diagnostic.span_fatal(sp, msg); - } - fn span_err(&self, sp: span, msg: &str) { - self.print_backtrace(); - self.parse_sess.span_diagnostic.span_err(sp, msg); - } - fn span_warn(&self, sp: span, msg: &str) { - self.print_backtrace(); - self.parse_sess.span_diagnostic.span_warn(sp, msg); - } - fn span_unimpl(&self, sp: span, msg: &str) -> ! { - self.print_backtrace(); - self.parse_sess.span_diagnostic.span_unimpl(sp, msg); - } - fn span_bug(&self, sp: span, msg: &str) -> ! { - self.print_backtrace(); - self.parse_sess.span_diagnostic.span_bug(sp, msg); - } - fn bug(&self, msg: &str) -> ! { - self.print_backtrace(); - self.parse_sess.span_diagnostic.handler().bug(msg); - } - fn next_id(&self) -> ast::node_id { - return parse::next_node_id(self.parse_sess); - } - fn trace_macros(&self) -> bool { - *self.trace_mac - } - fn set_trace_macros(&self, x: bool) { - *self.trace_mac = x - } - fn str_of(&self, id: ast::ident) -> ~str { - copy *self.parse_sess.interner.get(id) - } - fn ident_of(&self, st: &str) -> ast::ident { - self.parse_sess.interner.intern(st) + _ => self.bug("tried to pop without a push") } } - let imp: @CtxtRepr = @CtxtRepr { + fn span_fatal(&self, sp: span, msg: &str) -> ! { + self.print_backtrace(); + self.parse_sess.span_diagnostic.span_fatal(sp, msg); + } + fn span_err(&self, sp: span, msg: &str) { + self.print_backtrace(); + self.parse_sess.span_diagnostic.span_err(sp, msg); + } + fn span_warn(&self, sp: span, msg: &str) { + self.print_backtrace(); + self.parse_sess.span_diagnostic.span_warn(sp, msg); + } + fn span_unimpl(&self, sp: span, msg: &str) -> ! { + self.print_backtrace(); + self.parse_sess.span_diagnostic.span_unimpl(sp, msg); + } + fn span_bug(&self, sp: span, msg: &str) -> ! { + self.print_backtrace(); + self.parse_sess.span_diagnostic.span_bug(sp, msg); + } + fn bug(&self, msg: &str) -> ! { + self.print_backtrace(); + self.parse_sess.span_diagnostic.handler().bug(msg); + } + fn next_id(&self) -> ast::node_id { + parse::next_node_id(self.parse_sess) + } + fn trace_macros(&self) -> bool { + *self.trace_mac + } + fn set_trace_macros(&self, x: bool) { + *self.trace_mac = x + } + fn str_of(&self, id: ast::ident) -> ~str { + copy *self.parse_sess.interner.get(id) + } + fn ident_of(&self, st: &str) -> ast::ident { + self.parse_sess.interner.intern(st) + } +} + +pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) + -> @ext_ctxt { + @ext_ctxt { parse_sess: parse_sess, cfg: cfg, backtrace: @mut None, mod_path: @mut ~[], trace_mac: @mut false - }; - ((imp) as @ext_ctxt) + } } pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { From 4045da9f4f7290b02bee52caa42504e4ce5406f7 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 17 May 2013 21:27:17 +1000 Subject: [PATCH 3/6] syntax/ext: modernise ext_ctxt to be CamelCase and use new. --- src/librustc/front/test.rs | 6 +- src/librustpkg/util.rs | 6 +- src/libsyntax/ext/asm.rs | 2 +- src/libsyntax/ext/auto_encode.rs | 4 +- src/libsyntax/ext/base.rs | 41 +++--- src/libsyntax/ext/build.rs | 140 ++++++++++----------- src/libsyntax/ext/bytes.rs | 2 +- src/libsyntax/ext/concat_idents.rs | 2 +- src/libsyntax/ext/deriving/clone.rs | 8 +- src/libsyntax/ext/deriving/cmp/eq.rs | 8 +- src/libsyntax/ext/deriving/cmp/ord.rs | 6 +- src/libsyntax/ext/deriving/cmp/totaleq.rs | 6 +- src/libsyntax/ext/deriving/cmp/totalord.rs | 8 +- src/libsyntax/ext/deriving/decodable.rs | 26 ++-- src/libsyntax/ext/deriving/encodable.rs | 18 +-- src/libsyntax/ext/deriving/generic.rs | 52 ++++---- src/libsyntax/ext/deriving/iter_bytes.rs | 6 +- src/libsyntax/ext/deriving/mod.rs | 26 ++-- src/libsyntax/ext/deriving/rand.rs | 8 +- src/libsyntax/ext/deriving/to_str.rs | 6 +- src/libsyntax/ext/deriving/ty.rs | 18 +-- src/libsyntax/ext/env.rs | 2 +- src/libsyntax/ext/expand.rs | 16 +-- src/libsyntax/ext/fmt.rs | 24 ++-- src/libsyntax/ext/log_syntax.rs | 2 +- src/libsyntax/ext/pipes/ast_builder.rs | 4 +- src/libsyntax/ext/pipes/check.rs | 4 +- src/libsyntax/ext/pipes/liveness.rs | 4 +- src/libsyntax/ext/pipes/mod.rs | 4 +- src/libsyntax/ext/pipes/pipec.rs | 42 +++---- src/libsyntax/ext/pipes/proto.rs | 4 +- src/libsyntax/ext/quote.rs | 124 +++++++++--------- src/libsyntax/ext/source_util.rs | 18 +-- src/libsyntax/ext/trace_macros.rs | 4 +- src/libsyntax/ext/tt/macro_rules.rs | 8 +- src/test/run-pass-fulldeps/quote-tokens.rs | 4 +- 36 files changed, 331 insertions(+), 332 deletions(-) diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index eb199f6e10834..a0ff8cb5e4d24 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -17,7 +17,7 @@ use syntax::ast_util::*; use syntax::attr; use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan}; use syntax::codemap; -use syntax::ext::base::{mk_ctxt, ext_ctxt}; +use syntax::ext::base::ExtCtxt; use syntax::fold; use syntax::print::pprust; use syntax::{ast, ast_util}; @@ -36,7 +36,7 @@ struct TestCtxt { sess: session::Session, crate: @ast::crate, path: ~[ast::ident], - ext_cx: @ext_ctxt, + ext_cx: @ExtCtxt, testfns: ~[Test] } @@ -64,7 +64,7 @@ fn generate_test_harness(sess: session::Session, let cx: @mut TestCtxt = @mut TestCtxt { sess: sess, crate: crate, - ext_cx: mk_ctxt(sess.parse_sess, copy sess.opts.cfg), + ext_cx: ExtCtxt::new(sess.parse_sess, copy sess.opts.cfg), path: ~[], testfns: ~[] }; diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 0ae9539fecec3..f18396f95be42 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -19,7 +19,7 @@ use std::semver; use std::term; use syntax::ast_util::*; use syntax::codemap::{dummy_sp, spanned, dummy_spanned}; -use syntax::ext::base::{mk_ctxt, ext_ctxt}; +use syntax::ext::base::ExtCtxt; use syntax::{ast, attr, codemap, diagnostic, fold}; use syntax::ast::{meta_name_value, meta_list}; use syntax::attr::{mk_attr}; @@ -178,7 +178,7 @@ struct ListenerFn { struct ReadyCtx { sess: session::Session, crate: @ast::crate, - ext_cx: @ext_ctxt, + ext_cx: @ExtCtxt, path: ~[ast::ident], fns: ~[ListenerFn] } @@ -247,7 +247,7 @@ pub fn ready_crate(sess: session::Session, let ctx = @mut ReadyCtx { sess: sess, crate: crate, - ext_cx: mk_ctxt(sess.parse_sess, copy sess.opts.cfg), + ext_cx: ExtCtxt::new(sess.parse_sess, copy sess.opts.cfg), path: ~[], fns: ~[] }; diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 97c5797cf57d2..162eced11242b 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -37,7 +37,7 @@ fn next_state(s: State) -> Option { } } -pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 6bb3ac5eba4cd..64d2644b38310 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -15,7 +15,7 @@ use codemap::span; use ext::base::*; pub fn expand_auto_encode( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, _mitem: @ast::meta_item, in_items: ~[@ast::item] @@ -25,7 +25,7 @@ pub fn expand_auto_encode( } pub fn expand_auto_decode( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, _mitem: @ast::meta_item, in_items: ~[@ast::item] diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index b387694c6c191..9b71fb9647ce1 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -33,7 +33,7 @@ pub struct MacroDef { ext: SyntaxExtension } -pub type ItemDecorator = @fn(@ext_ctxt, +pub type ItemDecorator = @fn(@ExtCtxt, span, @ast::meta_item, ~[@ast::item]) @@ -44,7 +44,7 @@ pub struct SyntaxExpanderTT { span: Option } -pub type SyntaxExpanderTTFun = @fn(@ext_ctxt, +pub type SyntaxExpanderTTFun = @fn(@ExtCtxt, span, &[ast::token_tree]) -> MacResult; @@ -54,7 +54,7 @@ pub struct SyntaxExpanderTTItem { span: Option } -pub type SyntaxExpanderTTItemFun = @fn(@ext_ctxt, +pub type SyntaxExpanderTTItemFun = @fn(@ExtCtxt, span, ast::ident, ~[ast::token_tree]) @@ -202,7 +202,7 @@ pub fn syntax_expander_table() -> SyntaxEnv { // One of these is made during expansion and incrementally updated as we go; // when a macro expansion occurs, the resulting nodes have the backtrace() // -> expn_info of their expansion context stored into their span. -pub struct ext_ctxt { +pub struct ExtCtxt { parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg, backtrace: @mut Option<@ExpnInfo>, @@ -216,7 +216,17 @@ pub struct ext_ctxt { trace_mac: @mut bool } -pub impl ext_ctxt { +pub impl ExtCtxt { + fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) -> @ExtCtxt { + @ExtCtxt { + parse_sess: parse_sess, + cfg: cfg, + backtrace: @mut None, + mod_path: @mut ~[], + trace_mac: @mut false + } + } + fn codemap(&self) -> @CodeMap { self.parse_sess.cm } fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } fn cfg(&self) -> ast::crate_cfg { copy self.cfg } @@ -294,18 +304,7 @@ pub impl ext_ctxt { } } -pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) - -> @ext_ctxt { - @ext_ctxt { - parse_sess: parse_sess, - cfg: cfg, - backtrace: @mut None, - mod_path: @mut ~[], - trace_mac: @mut false - } -} - -pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { +pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::expr, err_msg: ~str) -> ~str { match expr.node { ast::expr_lit(l) => match l.node { ast::lit_str(s) => copy *s, @@ -315,7 +314,7 @@ pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { } } -pub fn expr_to_ident(cx: @ext_ctxt, +pub fn expr_to_ident(cx: @ExtCtxt, expr: @ast::expr, err_msg: &str) -> ast::ident { match expr.node { @@ -329,14 +328,14 @@ pub fn expr_to_ident(cx: @ext_ctxt, } } -pub fn check_zero_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree], +pub fn check_zero_tts(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree], name: &str) { if tts.len() != 0 { cx.span_fatal(sp, fmt!("%s takes no arguments", name)); } } -pub fn get_single_str_from_tts(cx: @ext_ctxt, +pub fn get_single_str_from_tts(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree], name: &str) -> ~str { @@ -351,7 +350,7 @@ pub fn get_single_str_from_tts(cx: @ext_ctxt, } } -pub fn get_exprs_from_tts(cx: @ext_ctxt, tts: &[ast::token_tree]) +pub fn get_exprs_from_tts(cx: @ExtCtxt, tts: &[ast::token_tree]) -> ~[@ast::expr] { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 624e0495e5950..e28c04d198af3 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -12,7 +12,7 @@ use ast; use codemap; use codemap::span; use fold; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use opt_vec::OptVec; @@ -22,7 +22,7 @@ pub struct Field { ex: @ast::expr } -pub fn mk_expr(cx: @ext_ctxt, +pub fn mk_expr(cx: @ExtCtxt, sp: codemap::span, expr: ast::expr_) -> @ast::expr { @@ -34,32 +34,32 @@ pub fn mk_expr(cx: @ext_ctxt, } } -pub fn mk_lit(cx: @ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { +pub fn mk_lit(cx: @ExtCtxt, sp: span, lit: ast::lit_) -> @ast::expr { let sp_lit = @codemap::spanned { node: lit, span: sp }; mk_expr(cx, sp, ast::expr_lit(sp_lit)) } -pub fn mk_int(cx: @ext_ctxt, sp: span, i: int) -> @ast::expr { +pub fn mk_int(cx: @ExtCtxt, sp: span, i: int) -> @ast::expr { let lit = ast::lit_int(i as i64, ast::ty_i); return mk_lit(cx, sp, lit); } -pub fn mk_uint(cx: @ext_ctxt, sp: span, u: uint) -> @ast::expr { +pub fn mk_uint(cx: @ExtCtxt, sp: span, u: uint) -> @ast::expr { let lit = ast::lit_uint(u as u64, ast::ty_u); return mk_lit(cx, sp, lit); } -pub fn mk_u8(cx: @ext_ctxt, sp: span, u: u8) -> @ast::expr { +pub fn mk_u8(cx: @ExtCtxt, sp: span, u: u8) -> @ast::expr { let lit = ast::lit_uint(u as u64, ast::ty_u8); return mk_lit(cx, sp, lit); } -pub fn mk_binary(cx: @ext_ctxt, sp: span, op: ast::binop, +pub fn mk_binary(cx: @ExtCtxt, sp: span, op: ast::binop, lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { cx.next_id(); // see ast_util::op_expr_callee_id mk_expr(cx, sp, ast::expr_binary(op, lhs, rhs)) } -pub fn mk_deref(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_deref(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { mk_unary(cx, sp, ast::deref, e) } -pub fn mk_unary(cx: @ext_ctxt, sp: span, op: ast::unop, e: @ast::expr) +pub fn mk_unary(cx: @ExtCtxt, sp: span, op: ast::unop, e: @ast::expr) -> @ast::expr { cx.next_id(); // see ast_util::op_expr_callee_id mk_expr(cx, sp, ast::expr_unary(op, e)) @@ -91,78 +91,78 @@ pub fn mk_raw_path_global_(sp: span, rp: rp, types: types } } -pub fn mk_path_raw(cx: @ext_ctxt, sp: span, path: @ast::Path)-> @ast::expr { +pub fn mk_path_raw(cx: @ExtCtxt, sp: span, path: @ast::Path)-> @ast::expr { mk_expr(cx, sp, ast::expr_path(path)) } -pub fn mk_path(cx: @ext_ctxt, sp: span, idents: ~[ast::ident]) +pub fn mk_path(cx: @ExtCtxt, sp: span, idents: ~[ast::ident]) -> @ast::expr { mk_path_raw(cx, sp, mk_raw_path(sp, idents)) } -pub fn mk_path_global(cx: @ext_ctxt, sp: span, idents: ~[ast::ident]) +pub fn mk_path_global(cx: @ExtCtxt, sp: span, idents: ~[ast::ident]) -> @ast::expr { mk_path_raw(cx, sp, mk_raw_path_global(sp, idents)) } -pub fn mk_access_(cx: @ext_ctxt, sp: span, p: @ast::expr, m: ast::ident) +pub fn mk_access_(cx: @ExtCtxt, sp: span, p: @ast::expr, m: ast::ident) -> @ast::expr { mk_expr(cx, sp, ast::expr_field(p, m, ~[])) } -pub fn mk_access(cx: @ext_ctxt, sp: span, p: ~[ast::ident], m: ast::ident) +pub fn mk_access(cx: @ExtCtxt, sp: span, p: ~[ast::ident], m: ast::ident) -> @ast::expr { let pathexpr = mk_path(cx, sp, p); return mk_access_(cx, sp, pathexpr, m); } -pub fn mk_addr_of(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_addr_of(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { return mk_expr(cx, sp, ast::expr_addr_of(ast::m_imm, e)); } -pub fn mk_mut_addr_of(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_mut_addr_of(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { return mk_expr(cx, sp, ast::expr_addr_of(ast::m_mutbl, e)); } -pub fn mk_method_call(cx: @ext_ctxt, +pub fn mk_method_call(cx: @ExtCtxt, sp: span, rcvr_expr: @ast::expr, method_ident: ast::ident, args: ~[@ast::expr]) -> @ast::expr { mk_expr(cx, sp, ast::expr_method_call(rcvr_expr, method_ident, ~[], args, ast::NoSugar)) } -pub fn mk_call_(cx: @ext_ctxt, sp: span, fn_expr: @ast::expr, +pub fn mk_call_(cx: @ExtCtxt, sp: span, fn_expr: @ast::expr, args: ~[@ast::expr]) -> @ast::expr { mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar)) } -pub fn mk_call(cx: @ext_ctxt, sp: span, fn_path: ~[ast::ident], +pub fn mk_call(cx: @ExtCtxt, sp: span, fn_path: ~[ast::ident], args: ~[@ast::expr]) -> @ast::expr { let pathexpr = mk_path(cx, sp, fn_path); return mk_call_(cx, sp, pathexpr, args); } -pub fn mk_call_global(cx: @ext_ctxt, sp: span, fn_path: ~[ast::ident], +pub fn mk_call_global(cx: @ExtCtxt, sp: span, fn_path: ~[ast::ident], args: ~[@ast::expr]) -> @ast::expr { let pathexpr = mk_path_global(cx, sp, fn_path); return mk_call_(cx, sp, pathexpr, args); } // e = expr, t = type -pub fn mk_base_vec_e(cx: @ext_ctxt, sp: span, exprs: ~[@ast::expr]) +pub fn mk_base_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { let vecexpr = ast::expr_vec(exprs, ast::m_imm); mk_expr(cx, sp, vecexpr) } -pub fn mk_vstore_e(cx: @ext_ctxt, sp: span, expr: @ast::expr, +pub fn mk_vstore_e(cx: @ExtCtxt, sp: span, expr: @ast::expr, vst: ast::expr_vstore) -> @ast::expr { mk_expr(cx, sp, ast::expr_vstore(expr, vst)) } -pub fn mk_uniq_vec_e(cx: @ext_ctxt, sp: span, exprs: ~[@ast::expr]) +pub fn mk_uniq_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_uniq) } -pub fn mk_slice_vec_e(cx: @ext_ctxt, sp: span, exprs: ~[@ast::expr]) +pub fn mk_slice_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_slice) } -pub fn mk_base_str(cx: @ext_ctxt, sp: span, s: ~str) -> @ast::expr { +pub fn mk_base_str(cx: @ExtCtxt, sp: span, s: ~str) -> @ast::expr { let lit = ast::lit_str(@s); return mk_lit(cx, sp, lit); } -pub fn mk_uniq_str(cx: @ext_ctxt, sp: span, s: ~str) -> @ast::expr { +pub fn mk_uniq_str(cx: @ExtCtxt, 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: &Field) -> ast::field { @@ -174,7 +174,7 @@ pub fn mk_field(sp: span, f: &Field) -> ast::field { pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] { fields.map(|f| mk_field(sp, f)) } -pub fn mk_struct_e(cx: @ext_ctxt, +pub fn mk_struct_e(cx: @ExtCtxt, sp: span, ctor_path: ~[ast::ident], fields: ~[Field]) @@ -184,7 +184,7 @@ pub fn mk_struct_e(cx: @ext_ctxt, mk_fields(sp, fields), option::None::<@ast::expr>)) } -pub fn mk_global_struct_e(cx: @ext_ctxt, +pub fn mk_global_struct_e(cx: @ExtCtxt, sp: span, ctor_path: ~[ast::ident], fields: ~[Field]) @@ -194,7 +194,7 @@ pub fn mk_global_struct_e(cx: @ext_ctxt, mk_fields(sp, fields), option::None::<@ast::expr>)) } -pub fn mk_glob_use(cx: @ext_ctxt, +pub fn mk_glob_use(cx: @ExtCtxt, sp: span, vis: ast::visibility, path: ~[ast::ident]) -> @ast::view_item { @@ -207,7 +207,7 @@ pub fn mk_glob_use(cx: @ext_ctxt, vis: vis, span: sp } } -pub fn mk_local(cx: @ext_ctxt, sp: span, mutbl: bool, +pub fn mk_local(cx: @ExtCtxt, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt { let pat = @ast::pat { @@ -232,7 +232,7 @@ pub fn mk_local(cx: @ext_ctxt, sp: span, mutbl: bool, let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp}; @codemap::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } } -pub fn mk_block(cx: @ext_ctxt, span: span, +pub fn mk_block(cx: @ExtCtxt, span: span, view_items: ~[@ast::view_item], stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> @ast::expr { @@ -248,7 +248,7 @@ pub fn mk_block(cx: @ext_ctxt, span: span, }; mk_expr(cx, span, ast::expr_block(blk)) } -pub fn mk_block_(cx: @ext_ctxt, +pub fn mk_block_(cx: @ExtCtxt, span: span, stmts: ~[@ast::stmt]) -> ast::blk { @@ -263,7 +263,7 @@ pub fn mk_block_(cx: @ext_ctxt, span: span, } } -pub fn mk_simple_block(cx: @ext_ctxt, +pub fn mk_simple_block(cx: @ExtCtxt, span: span, expr: @ast::expr) -> ast::blk { @@ -278,14 +278,14 @@ pub fn mk_simple_block(cx: @ext_ctxt, span: span, } } -pub fn mk_lambda_(cx: @ext_ctxt, +pub fn mk_lambda_(cx: @ExtCtxt, span: span, fn_decl: ast::fn_decl, blk: ast::blk) -> @ast::expr { mk_expr(cx, span, ast::expr_fn_block(fn_decl, blk)) } -pub fn mk_lambda(cx: @ext_ctxt, +pub fn mk_lambda(cx: @ExtCtxt, span: span, fn_decl: ast::fn_decl, expr: @ast::expr) @@ -293,7 +293,7 @@ pub fn mk_lambda(cx: @ext_ctxt, let blk = mk_simple_block(cx, span, expr); mk_lambda_(cx, span, fn_decl, blk) } -pub fn mk_lambda_stmts(cx: @ext_ctxt, +pub fn mk_lambda_stmts(cx: @ExtCtxt, span: span, fn_decl: ast::fn_decl, stmts: ~[@ast::stmt]) @@ -301,37 +301,37 @@ pub fn mk_lambda_stmts(cx: @ext_ctxt, let blk = mk_block(cx, span, ~[], stmts, None); mk_lambda(cx, span, fn_decl, blk) } -pub fn mk_lambda_no_args(cx: @ext_ctxt, +pub fn mk_lambda_no_args(cx: @ExtCtxt, span: span, expr: @ast::expr) -> @ast::expr { let fn_decl = mk_fn_decl(~[], mk_ty_infer(cx, span)); mk_lambda(cx, span, fn_decl, expr) } -pub fn mk_copy(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_copy(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { mk_expr(cx, sp, ast::expr_copy(e)) } -pub fn mk_managed(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_managed(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e)) } -pub fn mk_pat(cx: @ext_ctxt, span: span, pat: ast::pat_) -> @ast::pat { +pub fn mk_pat(cx: @ExtCtxt, span: span, pat: ast::pat_) -> @ast::pat { @ast::pat { id: cx.next_id(), node: pat, span: span } } -pub fn mk_pat_wild(cx: @ext_ctxt, span: span) -> @ast::pat { +pub fn mk_pat_wild(cx: @ExtCtxt, span: span) -> @ast::pat { mk_pat(cx, span, ast::pat_wild) } -pub fn mk_pat_lit(cx: @ext_ctxt, +pub fn mk_pat_lit(cx: @ExtCtxt, span: span, expr: @ast::expr) -> @ast::pat { mk_pat(cx, span, ast::pat_lit(expr)) } -pub fn mk_pat_ident(cx: @ext_ctxt, +pub fn mk_pat_ident(cx: @ExtCtxt, span: span, ident: ast::ident) -> @ast::pat { mk_pat_ident_with_binding_mode(cx, span, ident, ast::bind_by_copy) } -pub fn mk_pat_ident_with_binding_mode(cx: @ext_ctxt, +pub fn mk_pat_ident_with_binding_mode(cx: @ExtCtxt, span: span, ident: ast::ident, bm: ast::binding_mode) -> @ast::pat { @@ -339,7 +339,7 @@ pub fn mk_pat_ident_with_binding_mode(cx: @ext_ctxt, let pat = ast::pat_ident(bm, path, None); mk_pat(cx, span, pat) } -pub fn mk_pat_enum(cx: @ext_ctxt, +pub fn mk_pat_enum(cx: @ExtCtxt, span: span, path: @ast::Path, subpats: ~[@ast::pat]) @@ -347,7 +347,7 @@ pub fn mk_pat_enum(cx: @ext_ctxt, let pat = ast::pat_enum(path, Some(subpats)); mk_pat(cx, span, pat) } -pub fn mk_pat_struct(cx: @ext_ctxt, +pub fn mk_pat_struct(cx: @ExtCtxt, span: span, path: @ast::Path, field_pats: ~[ast::field_pat]) @@ -355,13 +355,13 @@ pub fn mk_pat_struct(cx: @ext_ctxt, let pat = ast::pat_struct(path, field_pats, false); mk_pat(cx, span, pat) } -pub fn mk_bool(cx: @ext_ctxt, span: span, value: bool) -> @ast::expr { +pub fn mk_bool(cx: @ExtCtxt, span: span, value: bool) -> @ast::expr { let lit_expr = ast::expr_lit(@codemap::spanned { node: ast::lit_bool(value), span: span }); build::mk_expr(cx, span, lit_expr) } -pub fn mk_stmt(cx: @ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt { +pub fn mk_stmt(cx: @ExtCtxt, span: span, expr: @ast::expr) -> @ast::stmt { let stmt_ = ast::stmt_semi(expr, cx.next_id()); @codemap::spanned { node: stmt_, span: span } } @@ -373,7 +373,7 @@ pub fn mk_ty_mt(ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt { } } -pub fn mk_ty(cx: @ext_ctxt, +pub fn mk_ty(cx: @ExtCtxt, span: span, ty: ast::ty_) -> @ast::Ty { @ast::Ty { @@ -383,7 +383,7 @@ pub fn mk_ty(cx: @ext_ctxt, } } -pub fn mk_ty_path(cx: @ext_ctxt, +pub fn mk_ty_path(cx: @ExtCtxt, span: span, idents: ~[ ast::ident ]) -> @ast::Ty { @@ -391,7 +391,7 @@ pub fn mk_ty_path(cx: @ext_ctxt, mk_ty_path_path(cx, span, ty) } -pub fn mk_ty_path_global(cx: @ext_ctxt, +pub fn mk_ty_path_global(cx: @ExtCtxt, span: span, idents: ~[ ast::ident ]) -> @ast::Ty { @@ -399,7 +399,7 @@ pub fn mk_ty_path_global(cx: @ext_ctxt, mk_ty_path_path(cx, span, ty) } -pub fn mk_ty_path_path(cx: @ext_ctxt, +pub fn mk_ty_path_path(cx: @ExtCtxt, span: span, path: @ast::Path) -> @ast::Ty { @@ -407,7 +407,7 @@ pub fn mk_ty_path_path(cx: @ext_ctxt, mk_ty(cx, span, ty) } -pub fn mk_ty_rptr(cx: @ext_ctxt, +pub fn mk_ty_rptr(cx: @ExtCtxt, span: span, ty: @ast::Ty, lifetime: Option<@ast::Lifetime>, @@ -416,39 +416,39 @@ pub fn mk_ty_rptr(cx: @ext_ctxt, mk_ty(cx, span, ast::ty_rptr(lifetime, mk_ty_mt(ty, mutbl))) } -pub fn mk_ty_uniq(cx: @ext_ctxt, span: span, ty: @ast::Ty) -> @ast::Ty { +pub fn mk_ty_uniq(cx: @ExtCtxt, span: span, ty: @ast::Ty) -> @ast::Ty { mk_ty(cx, span, ast::ty_uniq(mk_ty_mt(ty, ast::m_imm))) } -pub fn mk_ty_box(cx: @ext_ctxt, span: span, +pub fn mk_ty_box(cx: @ExtCtxt, span: span, ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty { mk_ty(cx, span, ast::ty_box(mk_ty_mt(ty, mutbl))) } -pub fn mk_ty_infer(cx: @ext_ctxt, span: span) -> @ast::Ty { +pub fn mk_ty_infer(cx: @ExtCtxt, span: span) -> @ast::Ty { mk_ty(cx, span, ast::ty_infer) } -pub fn mk_trait_ref_global(cx: @ext_ctxt, +pub fn mk_trait_ref_global(cx: @ExtCtxt, span: span, idents: ~[ ast::ident ]) -> @ast::trait_ref { mk_trait_ref_(cx, build::mk_raw_path_global(span, idents)) } -pub fn mk_trait_ref_(cx: @ext_ctxt, path: @ast::Path) -> @ast::trait_ref { +pub fn mk_trait_ref_(cx: @ExtCtxt, path: @ast::Path) -> @ast::trait_ref { @ast::trait_ref { path: path, ref_id: cx.next_id() } } -pub fn mk_simple_ty_path(cx: @ext_ctxt, +pub fn mk_simple_ty_path(cx: @ExtCtxt, span: span, ident: ast::ident) -> @ast::Ty { mk_ty_path(cx, span, ~[ ident ]) } -pub fn mk_arg(cx: @ext_ctxt, +pub fn mk_arg(cx: @ExtCtxt, span: span, ident: ast::ident, ty: @ast::Ty) @@ -464,29 +464,29 @@ pub fn mk_arg(cx: @ext_ctxt, pub fn mk_fn_decl(inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val } } -pub fn mk_trait_ty_param_bound_global(cx: @ext_ctxt, +pub fn mk_trait_ty_param_bound_global(cx: @ExtCtxt, span: span, idents: ~[ast::ident]) -> ast::TyParamBound { ast::TraitTyParamBound(mk_trait_ref_global(cx, span, idents)) } -pub fn mk_trait_ty_param_bound_(cx: @ext_ctxt, +pub fn mk_trait_ty_param_bound_(cx: @ExtCtxt, path: @ast::Path) -> ast::TyParamBound { ast::TraitTyParamBound(mk_trait_ref_(cx, path)) } -pub fn mk_ty_param(cx: @ext_ctxt, +pub fn mk_ty_param(cx: @ExtCtxt, ident: ast::ident, bounds: @OptVec) -> ast::TyParam { ast::TyParam { ident: ident, id: cx.next_id(), bounds: bounds } } -pub fn mk_lifetime(cx: @ext_ctxt, +pub fn mk_lifetime(cx: @ExtCtxt, span: span, ident: ast::ident) -> ast::Lifetime { ast::Lifetime { id: cx.next_id(), span: span, ident: ident } } -pub fn mk_arm(cx: @ext_ctxt, +pub fn mk_arm(cx: @ExtCtxt, span: span, pats: ~[@ast::pat], expr: @ast::expr) @@ -497,7 +497,7 @@ pub fn mk_arm(cx: @ext_ctxt, body: mk_simple_block(cx, span, expr) } } -pub fn mk_unreachable(cx: @ext_ctxt, span: span) -> @ast::expr { +pub fn mk_unreachable(cx: @ExtCtxt, span: span) -> @ast::expr { let loc = cx.codemap().lookup_char_pos(span.lo); mk_call_global( cx, @@ -515,11 +515,11 @@ pub fn mk_unreachable(cx: @ext_ctxt, span: span) -> @ast::expr { ] ) } -pub fn mk_unreachable_arm(cx: @ext_ctxt, span: span) -> ast::arm { +pub fn mk_unreachable_arm(cx: @ExtCtxt, span: span) -> ast::arm { mk_arm(cx, span, ~[mk_pat_wild(cx, span)], mk_unreachable(cx, span)) } -pub fn make_self(cx: @ext_ctxt, span: span) -> @ast::expr { +pub fn make_self(cx: @ExtCtxt, span: span) -> @ast::expr { build::mk_expr(cx, span, ast::expr_self) } @@ -529,7 +529,7 @@ pub fn make_self(cx: @ext_ctxt, span: span) -> @ast::expr { // These functions just duplicate AST nodes. // -pub fn duplicate_expr(cx: @ext_ctxt, expr: @ast::expr) -> @ast::expr { +pub fn duplicate_expr(cx: @ExtCtxt, expr: @ast::expr) -> @ast::expr { let folder = fold::default_ast_fold(); let folder = @fold::AstFoldFns { new_id: |_| cx.next_id(), @@ -599,7 +599,7 @@ trait ExtCtxtMethods { -> @ast::expr; } -impl ExtCtxtMethods for @ext_ctxt { +impl ExtCtxtMethods for @ExtCtxt { fn bind_path( &self, _span: span, diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index 7c2f27ada3bce..da13c9bfa28e1 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -16,7 +16,7 @@ use ext::base::*; use ext::base; use ext::build::{mk_u8, mk_slice_vec_e}; -pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { +pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { // Gather all argument expressions let exprs = get_exprs_from_tts(cx, tts); let mut bytes = ~[]; diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index da32cc1162513..e6600e198fa6d 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -14,7 +14,7 @@ use ext::base::*; use ext::base; use parse::token; -pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let mut res_str = ~""; for tts.eachi |i, e| { diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 1759cde0fc975..c08b478e8ed6f 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -10,12 +10,12 @@ use ast::{meta_item, item, expr}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; -pub fn expand_deriving_clone(cx: @ext_ctxt, +pub fn expand_deriving_clone(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) @@ -42,7 +42,7 @@ pub fn expand_deriving_clone(cx: @ext_ctxt, &trait_def) } -pub fn expand_deriving_deep_clone(cx: @ext_ctxt, +pub fn expand_deriving_deep_clone(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) @@ -73,7 +73,7 @@ pub fn expand_deriving_deep_clone(cx: @ext_ctxt, fn cs_clone( name: &str, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { let clone_ident = substr.method_ident; let ctor_ident; diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index e6fcfdf556354..197366b09ae3c 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -10,21 +10,21 @@ use ast::{meta_item, item, expr}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; -pub fn expand_deriving_eq(cx: @ext_ctxt, +pub fn expand_deriving_eq(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different - fn cs_eq(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr { + fn cs_eq(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cs_and(|cx, span, _, _| build::mk_bool(cx, span, false), cx, span, substr) } - fn cs_ne(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr { + fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cs_or(|cx, span, _, _| build::mk_bool(cx, span, true), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 5aae8454c09b4..29fc2c7271c0b 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -11,11 +11,11 @@ use ast::{meta_item, item, expr_if, expr}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; -pub fn expand_deriving_ord(cx: @ext_ctxt, +pub fn expand_deriving_ord(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { @@ -55,7 +55,7 @@ pub fn expand_deriving_ord(cx: @ext_ctxt, /// `less`: is this `lt` or `le`? `equal`: is this `le` or `ge`? fn cs_ord(less: bool, equal: bool, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { let binop = if less { cx.ident_of("lt") diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 9ab44f506bade..0ab99430d1078 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -11,16 +11,16 @@ use ast::{meta_item, item, expr}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; -pub fn expand_deriving_totaleq(cx: @ext_ctxt, +pub fn expand_deriving_totaleq(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { - fn cs_equals(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr { + fn cs_equals(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cs_and(|cx, span, _, _| build::mk_bool(cx, span, false), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 1b6ea16b86e2d..2b4d8a28fbd93 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -10,12 +10,12 @@ use ast::{meta_item, item, expr}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; use core::cmp::{Ordering, Equal, Less, Greater}; -pub fn expand_deriving_totalord(cx: @ext_ctxt, +pub fn expand_deriving_totalord(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { @@ -41,7 +41,7 @@ pub fn expand_deriving_totalord(cx: @ext_ctxt, } -pub fn ordering_const(cx: @ext_ctxt, span: span, cnst: Ordering) -> @expr { +pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr { let cnst = match cnst { Less => "Less", Equal => "Equal", @@ -53,7 +53,7 @@ pub fn ordering_const(cx: @ext_ctxt, span: span, cnst: Ordering) -> @expr { cx.ident_of(cnst)]) } -pub fn cs_cmp(cx: @ext_ctxt, span: span, +pub fn cs_cmp(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cs_same_method_fold( diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index fe20511204632..24f9b6acf8534 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -15,7 +15,7 @@ encodable.rs for more. use ast; use ast::*; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::*; use codemap::{span, spanned}; @@ -23,7 +23,7 @@ use ast_util; use opt_vec; pub fn expand_deriving_decodable( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, _mitem: @meta_item, in_items: ~[@item] @@ -38,7 +38,7 @@ pub fn expand_deriving_decodable( } fn create_derived_decodable_impl( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, type_ident: ident, generics: &Generics, @@ -91,7 +91,7 @@ fn create_derived_decodable_impl( // Creates a method from the given set of statements conforming to the // signature of the `decodable` method. fn create_decode_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, type_ident: ast::ident, generics: &Generics, @@ -142,7 +142,7 @@ fn create_decode_method( } fn call_substructure_decode_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span ) -> @ast::expr { // Call the substructure method. @@ -166,7 +166,7 @@ fn call_substructure_decode_method( } fn expand_deriving_decodable_struct_def( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -192,7 +192,7 @@ fn expand_deriving_decodable_struct_def( } fn expand_deriving_decodable_enum_def( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, enum_definition: &enum_def, type_ident: ident, @@ -218,7 +218,7 @@ fn expand_deriving_decodable_enum_def( } fn create_read_struct_field( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, idx: uint, ident: ident @@ -251,7 +251,7 @@ fn create_read_struct_field( } fn create_read_struct_arg( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, idx: uint, ident: ident @@ -274,7 +274,7 @@ fn create_read_struct_arg( } fn expand_deriving_decodable_struct_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -334,7 +334,7 @@ fn expand_deriving_decodable_struct_method( } fn create_read_variant_arg( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, idx: uint, variant: &ast::variant @@ -392,7 +392,7 @@ fn create_read_variant_arg( } fn create_read_enum_variant( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, enum_definition: &enum_def ) -> @expr { @@ -459,7 +459,7 @@ fn create_read_enum_variant( } fn expand_deriving_decodable_enum_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, enum_definition: &enum_def, type_ident: ast::ident, diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index b1df8405d7627..128bbf39b16c6 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -78,7 +78,7 @@ would yield functions like: use ast; use ast::*; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::*; use codemap::{span, spanned}; @@ -86,7 +86,7 @@ use ast_util; use opt_vec; pub fn expand_deriving_encodable( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, _mitem: @meta_item, in_items: ~[@item] @@ -101,7 +101,7 @@ pub fn expand_deriving_encodable( } fn create_derived_encodable_impl( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, type_ident: ident, generics: &Generics, @@ -154,7 +154,7 @@ fn create_derived_encodable_impl( // Creates a method from the given set of statements conforming to the // signature of the `encodable` method. fn create_encode_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, statements: ~[@stmt] ) -> @method { @@ -197,7 +197,7 @@ fn create_encode_method( } fn call_substructure_encode_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, self_field: @expr ) -> @ast::expr { @@ -217,7 +217,7 @@ fn call_substructure_encode_method( } fn expand_deriving_encodable_struct_def( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -242,7 +242,7 @@ fn expand_deriving_encodable_struct_def( } fn expand_deriving_encodable_enum_def( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, enum_definition: &enum_def, type_ident: ident, @@ -267,7 +267,7 @@ fn expand_deriving_encodable_enum_def( } fn expand_deriving_encodable_struct_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, type_ident: ident, struct_def: &struct_def @@ -361,7 +361,7 @@ fn expand_deriving_encodable_struct_method( } fn expand_deriving_encodable_enum_method( - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, type_ident: ast::ident, enum_definition: &enum_def diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index ae9c4c1fefb44..0bb97ec31224c 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -165,7 +165,7 @@ StaticEnum(, ~[(, Left(1)), use ast; use ast::{enum_def, expr, ident, Generics, struct_def}; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::*; use codemap::{span,respan}; @@ -174,7 +174,7 @@ use opt_vec; pub use self::ty::*; mod ty; -pub fn expand_deriving_generic(cx: @ext_ctxt, +pub fn expand_deriving_generic(cx: @ExtCtxt, span: span, _mitem: @ast::meta_item, in_items: ~[@ast::item], @@ -281,7 +281,7 @@ Combine the values of all the fields together. The last argument is all the fields of all the structures, see above for details. */ pub type CombineSubstructureFunc<'self> = - &'self fn(@ext_ctxt, span, &Substructure) -> @expr; + &'self fn(@ExtCtxt, span, &Substructure) -> @expr; /** Deal with non-matching enum variants, the arguments are a list @@ -289,14 +289,14 @@ representing each variant: (variant index, ast::variant instance, [variant fields]), and a list of the nonself args of the type */ pub type EnumNonMatchFunc<'self> = - &'self fn(@ext_ctxt, span, + &'self fn(@ExtCtxt, span, &[(uint, ast::variant, ~[(Option, @expr)])], &[@expr]) -> @expr; impl<'self> TraitDef<'self> { - fn create_derived_impl(&self, cx: @ext_ctxt, span: span, + fn create_derived_impl(&self, cx: @ExtCtxt, span: span, type_ident: ident, generics: &Generics, methods: ~[@ast::method]) -> @ast::item { let trait_path = self.path.to_path(cx, span, type_ident, generics); @@ -315,7 +315,7 @@ impl<'self> TraitDef<'self> { additional_bounds) } - fn expand_struct_def(&self, cx: @ext_ctxt, + fn expand_struct_def(&self, cx: @ExtCtxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -347,7 +347,7 @@ impl<'self> TraitDef<'self> { } fn expand_enum_def(&self, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, enum_def: &enum_def, type_ident: ident, generics: &Generics) -> @ast::item { @@ -380,7 +380,7 @@ impl<'self> TraitDef<'self> { impl<'self> MethodDef<'self> { fn call_substructure_method(&self, - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, type_ident: ident, self_args: &[@expr], @@ -398,7 +398,7 @@ impl<'self> MethodDef<'self> { &substructure) } - fn get_ret_ty(&self, cx: @ext_ctxt, span: span, + fn get_ret_ty(&self, cx: @ExtCtxt, span: span, generics: &Generics, type_ident: ident) -> @ast::Ty { self.ret_ty.to_ty(cx, span, type_ident, generics) } @@ -407,7 +407,7 @@ impl<'self> MethodDef<'self> { self.explicit_self.is_none() } - fn split_self_nonself_args(&self, cx: @ext_ctxt, span: span, + fn split_self_nonself_args(&self, cx: @ExtCtxt, span: span, type_ident: ident, generics: &Generics) -> (ast::explicit_self, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) { @@ -451,7 +451,7 @@ impl<'self> MethodDef<'self> { (ast_explicit_self, self_args, nonself_args, arg_tys) } - fn create_method(&self, cx: @ext_ctxt, span: span, + fn create_method(&self, cx: @ExtCtxt, span: span, type_ident: ident, generics: &Generics, explicit_self: ast::explicit_self, @@ -509,7 +509,7 @@ impl<'self> MethodDef<'self> { ~~~ */ fn expand_struct_method_body(&self, - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -567,7 +567,7 @@ impl<'self> MethodDef<'self> { } fn expand_static_struct_method_body(&self, - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -609,7 +609,7 @@ impl<'self> MethodDef<'self> { ~~~ */ fn expand_enum_method_body(&self, - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, enum_def: &enum_def, type_ident: ident, @@ -645,7 +645,7 @@ impl<'self> MethodDef<'self> { the first call). */ fn build_enum_match(&self, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, enum_def: &enum_def, type_ident: ident, self_args: &[@expr], @@ -786,7 +786,7 @@ impl<'self> MethodDef<'self> { } fn expand_static_enum_method_body(&self, - cx: @ext_ctxt, + cx: @ExtCtxt, span: span, enum_def: &enum_def, type_ident: ident, @@ -810,7 +810,7 @@ impl<'self> MethodDef<'self> { } } -fn summarise_struct(cx: @ext_ctxt, span: span, +fn summarise_struct(cx: @ExtCtxt, span: span, struct_def: &struct_def) -> Either { let mut named_idents = ~[]; let mut unnamed_count = 0; @@ -840,12 +840,12 @@ Fold the fields. `use_foldl` controls whether this is done left-to-right (`true`) or right-to-left (`false`). */ pub fn cs_fold(use_foldl: bool, - f: &fn(@ext_ctxt, span, + f: &fn(@ExtCtxt, span, old: @expr, self_f: @expr, other_fs: &[@expr]) -> @expr, base: @expr, enum_nonmatch_f: EnumNonMatchFunc, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { @@ -879,9 +879,9 @@ f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1), ~~~ */ #[inline(always)] -pub fn cs_same_method(f: &fn(@ext_ctxt, span, ~[@expr]) -> @expr, +pub fn cs_same_method(f: &fn(@ExtCtxt, span, ~[@expr]) -> @expr, enum_nonmatch_f: EnumNonMatchFunc, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { @@ -911,10 +911,10 @@ fields. `use_foldl` controls whether this is done left-to-right */ #[inline(always)] pub fn cs_same_method_fold(use_foldl: bool, - f: &fn(@ext_ctxt, span, @expr, @expr) -> @expr, + f: &fn(@ExtCtxt, span, @expr, @expr) -> @expr, base: @expr, enum_nonmatch_f: EnumNonMatchFunc, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { cs_same_method( |cx, span, vals| { @@ -940,7 +940,7 @@ on all the fields. #[inline(always)] pub fn cs_binop(binop: ast::binop, base: @expr, enum_nonmatch_f: EnumNonMatchFunc, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { cs_same_method_fold( true, // foldl is good enough @@ -958,7 +958,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr, /// cs_binop with binop == or #[inline(always)] pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { cs_binop(ast::or, build::mk_bool(cx, span, false), enum_nonmatch_f, @@ -967,7 +967,7 @@ pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, /// cs_binop with binop == and #[inline(always)] pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc, - cx: @ext_ctxt, span: span, + cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { cs_binop(ast::and, build::mk_bool(cx, span, true), enum_nonmatch_f, diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 9b8f127d42a0b..c655eef34d1eb 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -10,11 +10,11 @@ use ast::{meta_item, item, expr, and}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; -pub fn expand_deriving_iter_bytes(cx: @ext_ctxt, +pub fn expand_deriving_iter_bytes(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { @@ -41,7 +41,7 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt, expand_deriving_generic(cx, span, mitem, in_items, &trait_def) } -fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr { +fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { let lsb0_f = match substr.nonself_args { [l, f] => ~[l, f], _ => cx.span_bug(span, "Incorrect number of arguments in `deriving(IterBytes)`") diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 6f4429af12d75..4a6c78038389e 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -20,7 +20,7 @@ library. use ast; use ast::{Ty, enum_def, expr, ident, item, Generics, meta_item, struct_def}; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use codemap::{span, respan}; use parse::token::special_idents::clownshoes_extensions; @@ -45,20 +45,20 @@ pub mod totalord; pub mod generic; -pub type ExpandDerivingStructDefFn<'self> = &'self fn(@ext_ctxt, +pub type ExpandDerivingStructDefFn<'self> = &'self fn(@ExtCtxt, span, x: &struct_def, ident, y: &Generics) -> @item; -pub type ExpandDerivingEnumDefFn<'self> = &'self fn(@ext_ctxt, +pub type ExpandDerivingEnumDefFn<'self> = &'self fn(@ExtCtxt, span, x: &enum_def, ident, y: &Generics) -> @item; -pub fn expand_meta_deriving(cx: @ext_ctxt, +pub fn expand_meta_deriving(cx: @ExtCtxt, _span: span, mitem: @meta_item, in_items: ~[@item]) @@ -113,7 +113,7 @@ pub fn expand_meta_deriving(cx: @ext_ctxt, } } -pub fn expand_deriving(cx: @ext_ctxt, +pub fn expand_deriving(cx: @ExtCtxt, span: span, in_items: ~[@item], expand_deriving_struct_def: ExpandDerivingStructDefFn, @@ -143,7 +143,7 @@ pub fn expand_deriving(cx: @ext_ctxt, result } -fn create_impl_item(cx: @ext_ctxt, span: span, item: ast::item_) -> @item { +fn create_impl_item(cx: @ExtCtxt, span: span, item: ast::item_) -> @item { let doc_attr = respan(span, ast::lit_str(@~"Automatically derived.")); let doc_attr = respan(span, ast::meta_name_value(@~"doc", doc_attr)); @@ -164,7 +164,7 @@ fn create_impl_item(cx: @ext_ctxt, span: span, item: ast::item_) -> @item { } } -pub fn create_self_type_with_params(cx: @ext_ctxt, +pub fn create_self_type_with_params(cx: @ExtCtxt, span: span, type_ident: ident, generics: &Generics) @@ -193,7 +193,7 @@ pub fn create_self_type_with_params(cx: @ext_ctxt, build::mk_ty_path_path(cx, span, self_type) } -pub fn create_derived_impl(cx: @ext_ctxt, +pub fn create_derived_impl(cx: @ExtCtxt, span: span, type_ident: ident, generics: &Generics, @@ -249,7 +249,7 @@ pub fn create_derived_impl(cx: @ext_ctxt, return create_impl_item(cx, span, impl_item); } -pub fn create_subpatterns(cx: @ext_ctxt, +pub fn create_subpatterns(cx: @ExtCtxt, span: span, field_paths: ~[@ast::Path], mutbl: ast::mutability) @@ -265,7 +265,7 @@ enum StructType { Unknown, Record, Tuple } -pub fn create_struct_pattern(cx: @ext_ctxt, +pub fn create_struct_pattern(cx: @ExtCtxt, span: span, struct_ident: ident, struct_def: &struct_def, @@ -326,7 +326,7 @@ pub fn create_struct_pattern(cx: @ext_ctxt, (pattern, ident_expr) } -pub fn create_enum_variant_pattern(cx: @ext_ctxt, +pub fn create_enum_variant_pattern(cx: @ExtCtxt, span: span, variant: &ast::variant, prefix: &str, @@ -366,14 +366,14 @@ pub fn create_enum_variant_pattern(cx: @ext_ctxt, } } -pub fn variant_arg_count(_cx: @ext_ctxt, _span: span, variant: &ast::variant) -> uint { +pub fn variant_arg_count(_cx: @ExtCtxt, _span: span, variant: &ast::variant) -> uint { match variant.node.kind { ast::tuple_variant_kind(ref args) => args.len(), ast::struct_variant_kind(ref struct_def) => struct_def.fields.len(), } } -pub fn expand_enum_or_struct_match(cx: @ext_ctxt, +pub fn expand_enum_or_struct_match(cx: @ExtCtxt, span: span, arms: ~[ ast::arm ]) -> @expr { diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 2fb47c1e53ec2..64cf7e93b92e8 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -11,11 +11,11 @@ use ast; use ast::{meta_item, item, expr, ident}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; -pub fn expand_deriving_rand(cx: @ext_ctxt, +pub fn expand_deriving_rand(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) @@ -47,7 +47,7 @@ pub fn expand_deriving_rand(cx: @ext_ctxt, expand_deriving_generic(cx, span, mitem, in_items, &trait_def) } -fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr { +fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { let rng = match substr.nonself_args { [rng] => ~[ rng ], _ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`") @@ -113,7 +113,7 @@ fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr _ => cx.bug("Non-static method in `deriving(Rand)`") }; - fn rand_thing(cx: @ext_ctxt, span: span, + fn rand_thing(cx: @ExtCtxt, span: span, ctor_ident: ident, summary: &Either, rand_call: &fn() -> @expr) -> @expr { diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 0c12a1948cd4c..19fd601186b1e 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -10,11 +10,11 @@ use ast::{meta_item, item, expr}; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use ext::deriving::generic::*; -pub fn expand_deriving_to_str(cx: @ext_ctxt, +pub fn expand_deriving_to_str(cx: @ExtCtxt, span: span, mitem: @meta_item, in_items: ~[@item]) @@ -39,7 +39,7 @@ pub fn expand_deriving_to_str(cx: @ext_ctxt, expand_deriving_generic(cx, span, mitem, in_items, &trait_def) } -fn to_str_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr { +fn to_str_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { match substr.self_args { [self_obj] => { let self_addr = build::mk_addr_of(cx, span, self_obj); diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index bbc6b6634e383..154e7647bb560 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -15,7 +15,7 @@ explicit `Self` type to use when specifying impls to be derived. use ast; use ast::{expr,Generics,ident}; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::build; use codemap::{span,respan}; use opt_vec; @@ -53,13 +53,13 @@ pub impl<'self> Path<'self> { } } - fn to_ty(&self, cx: @ext_ctxt, span: span, + fn to_ty(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Ty { build::mk_ty_path_path(cx, span, self.to_path(cx, span, self_ty, self_generics)) } - fn to_path(&self, cx: @ext_ctxt, span: span, + fn to_path(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Path { let idents = self.path.map(|s| cx.ident_of(*s) ); let lt = mk_lifetime(cx, span, &self.lifetime); @@ -104,7 +104,7 @@ pub fn nil_ty() -> Ty<'static> { Tuple(~[]) } -fn mk_lifetime(cx: @ext_ctxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> { +fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> { match *lt { Some(ref s) => Some(@build::mk_lifetime(cx, span, cx.ident_of(*s))), None => None @@ -112,7 +112,7 @@ fn mk_lifetime(cx: @ext_ctxt, span: span, lt: &Option<&str>) -> Option<@ast::Lif } pub impl<'self> Ty<'self> { - fn to_ty(&self, cx: @ext_ctxt, span: span, + fn to_ty(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Ty { match *self { Ptr(ref ty, ref ptr) => { @@ -146,7 +146,7 @@ pub impl<'self> Ty<'self> { } } - fn to_path(&self, cx: @ext_ctxt, span: span, + fn to_path(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Path { match *self { Self => { @@ -172,7 +172,7 @@ pub impl<'self> Ty<'self> { } -fn mk_ty_param(cx: @ext_ctxt, span: span, name: &str, bounds: &[Path], +fn mk_ty_param(cx: @ExtCtxt, span: span, name: &str, bounds: &[Path], self_ident: ident, self_generics: &Generics) -> ast::TyParam { let bounds = opt_vec::from( do bounds.map |b| { @@ -201,7 +201,7 @@ pub impl<'self> LifetimeBounds<'self> { lifetimes: ~[], bounds: ~[] } } - fn to_generics(&self, cx: @ext_ctxt, span: span, + fn to_generics(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> Generics { let lifetimes = do self.lifetimes.map |lt| { build::mk_lifetime(cx, span, cx.ident_of(*lt)) @@ -218,7 +218,7 @@ pub impl<'self> LifetimeBounds<'self> { } -pub fn get_explicit_self(cx: @ext_ctxt, span: span, self_ptr: &Option) +pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) -> (@expr, ast::explicit_self) { let self_path = build::make_self(cx, span); match *self_ptr { diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 4be75d9ee5b57..3d74595e645ae 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -20,7 +20,7 @@ use ext::base::*; use ext::base; use ext::build::mk_base_str; -pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let var = get_single_str_from_tts(cx, sp, tts, "env!"); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ff0cf6f28ad8f..b993162cfa3dd 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -23,7 +23,7 @@ use parse; use parse::{parse_item_from_source_str}; pub fn expand_expr(extsbox: @mut SyntaxEnv, - cx: @ext_ctxt, + cx: @ExtCtxt, e: &expr_, s: span, fld: @ast_fold, @@ -109,7 +109,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, // NB: there is some redundancy between this and expand_item, below, and // they might benefit from some amount of semantic and language-UI merger. pub fn expand_mod_items(extsbox: @mut SyntaxEnv, - cx: @ext_ctxt, + cx: @ExtCtxt, module_: &ast::_mod, fld: @ast_fold, orig: @fn(&ast::_mod, @ast_fold) -> ast::_mod) @@ -161,7 +161,7 @@ macro_rules! with_exts_frame ( // When we enter a module, record it, for the sake of `module!` pub fn expand_item(extsbox: @mut SyntaxEnv, - cx: @ext_ctxt, + cx: @ExtCtxt, it: @ast::item, fld: @ast_fold, orig: @fn(@ast::item, @ast_fold) -> Option<@ast::item>) @@ -227,7 +227,7 @@ macro_rules! without_macro_scoping( // Support for item-position macro invocations, exactly the same // logic as for expression-position macro invocations. pub fn expand_item_mac(extsbox: @mut SyntaxEnv, - cx: @ext_ctxt, it: @ast::item, + cx: @ExtCtxt, it: @ast::item, fld: @ast_fold) -> Option<@ast::item> { let (pth, tts) = match it.node { @@ -294,7 +294,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, // expand a stmt pub fn expand_stmt(extsbox: @mut SyntaxEnv, - cx: @ext_ctxt, + cx: @ExtCtxt, s: &stmt_, sp: span, fld: @ast_fold, @@ -360,7 +360,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, pub fn expand_block(extsbox: @mut SyntaxEnv, - cx: @ext_ctxt, + cx: @ExtCtxt, blk: &blk_, sp: span, fld: @ast_fold, @@ -381,7 +381,7 @@ pub fn expand_block(extsbox: @mut SyntaxEnv, } } -pub fn new_span(cx: @ext_ctxt, sp: span) -> span { +pub fn new_span(cx: @ExtCtxt, sp: span) -> span { /* this discards information in the case of macro-defining macros */ return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()}; } @@ -590,7 +590,7 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, // every method/element of AstFoldFns in fold.rs. let extsbox = @mut syntax_expander_table(); let afp = default_ast_fold(); - let cx: @ext_ctxt = mk_ctxt(parse_sess, copy cfg); + let cx = ExtCtxt::new(parse_sess, copy cfg); let f_pre = @AstFoldFns { fold_expr: |expr,span,recur| expand_expr(extsbox, cx, expr, span, recur, afp.fold_expr), diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 24046faa6849d..ca281a22e3922 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -23,7 +23,7 @@ use ext::build::*; use core::unstable::extfmt::ct::*; -pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let args = get_exprs_from_tts(cx, tts); if args.len() == 0 { @@ -34,7 +34,7 @@ pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) ~"first argument to fmt! must be a string literal."); let fmtspan = args[0].span; debug!("Format string: %s", fmt); - fn parse_fmt_err_(cx: @ext_ctxt, sp: span, msg: &str) -> ! { + fn parse_fmt_err_(cx: @ExtCtxt, sp: span, msg: &str) -> ! { cx.span_fatal(sp, msg); } let parse_fmt_err: @fn(&str) -> ! = |s| parse_fmt_err_(cx, fmtspan, s); @@ -46,23 +46,23 @@ pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) // probably be factored out in common with other code that builds // expressions. Also: Cleanup the naming of these functions. // Note: Moved many of the common ones to build.rs --kevina -fn pieces_to_expr(cx: @ext_ctxt, sp: span, +fn pieces_to_expr(cx: @ExtCtxt, sp: span, pieces: ~[Piece], args: ~[@ast::expr]) -> @ast::expr { - fn make_path_vec(cx: @ext_ctxt, ident: &str) -> ~[ast::ident] { + fn make_path_vec(cx: @ExtCtxt, ident: &str) -> ~[ast::ident] { let intr = cx.parse_sess().interner; return ~[intr.intern("unstable"), intr.intern("extfmt"), intr.intern("rt"), intr.intern(ident)]; } - fn make_rt_path_expr(cx: @ext_ctxt, sp: span, nm: &str) -> @ast::expr { + fn make_rt_path_expr(cx: @ExtCtxt, sp: span, nm: &str) -> @ast::expr { let path = make_path_vec(cx, nm); return mk_path_global(cx, sp, path); } // Produces an AST expression that represents a RT::conv record, // which tells the RT::conv* functions how to perform the conversion - fn make_rt_conv_expr(cx: @ext_ctxt, sp: span, cnv: &Conv) -> @ast::expr { - fn make_flags(cx: @ext_ctxt, sp: span, flags: &[Flag]) -> @ast::expr { + fn make_rt_conv_expr(cx: @ExtCtxt, sp: span, cnv: &Conv) -> @ast::expr { + fn make_flags(cx: @ExtCtxt, sp: span, flags: &[Flag]) -> @ast::expr { let mut tmp_expr = make_rt_path_expr(cx, sp, "flag_none"); for flags.each |f| { let fstr = match *f { @@ -77,7 +77,7 @@ fn pieces_to_expr(cx: @ext_ctxt, sp: span, } return tmp_expr; } - fn make_count(cx: @ext_ctxt, sp: span, cnt: Count) -> @ast::expr { + fn make_count(cx: @ExtCtxt, sp: span, cnt: Count) -> @ast::expr { match cnt { CountImplied => { return make_rt_path_expr(cx, sp, "CountImplied"); @@ -91,7 +91,7 @@ fn pieces_to_expr(cx: @ext_ctxt, sp: span, _ => cx.span_unimpl(sp, "unimplemented fmt! conversion") } } - fn make_ty(cx: @ext_ctxt, sp: span, t: Ty) -> @ast::expr { + fn make_ty(cx: @ExtCtxt, sp: span, t: Ty) -> @ast::expr { let rt_type = match t { TyHex(c) => match c { CaseUpper => "TyHexUpper", @@ -103,7 +103,7 @@ fn pieces_to_expr(cx: @ext_ctxt, sp: span, }; return make_rt_path_expr(cx, sp, rt_type); } - fn make_conv_struct(cx: @ext_ctxt, sp: span, flags_expr: @ast::expr, + fn make_conv_struct(cx: @ExtCtxt, sp: span, flags_expr: @ast::expr, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { let intr = cx.parse_sess().interner; @@ -134,7 +134,7 @@ fn pieces_to_expr(cx: @ext_ctxt, sp: span, make_conv_struct(cx, sp, rt_conv_flags, rt_conv_width, rt_conv_precision, rt_conv_ty) } - fn make_conv_call(cx: @ext_ctxt, sp: span, conv_type: &str, cnv: &Conv, + fn make_conv_call(cx: @ExtCtxt, sp: span, conv_type: &str, cnv: &Conv, arg: @ast::expr, buf: @ast::expr) -> @ast::expr { let fname = ~"conv_" + conv_type; let path = make_path_vec(cx, fname); @@ -143,7 +143,7 @@ fn pieces_to_expr(cx: @ext_ctxt, sp: span, return mk_call_global(cx, arg.span, path, args); } - fn make_new_conv(cx: @ext_ctxt, sp: span, cnv: &Conv, + fn make_new_conv(cx: @ExtCtxt, sp: span, cnv: &Conv, arg: @ast::expr, buf: @ast::expr) -> @ast::expr { fn is_signed_type(cnv: &Conv) -> bool { match cnv.ty { diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 76d9a9420ce50..a3f6fb8e97d21 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -14,7 +14,7 @@ use ext::base::*; use ext::base; use print; -pub fn expand_syntax_ext(cx: @ext_ctxt, +pub fn expand_syntax_ext(cx: @ExtCtxt, sp: codemap::span, tt: &[ast::token_tree]) -> base::MacResult { diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index a514828725866..1f38b14efbecf 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -19,7 +19,7 @@ use ast; use ast_util; use codemap::{span, respan, dummy_sp, spanned}; use codemap; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::quote::rt::*; use opt_vec; use opt_vec::OptVec; @@ -135,7 +135,7 @@ pub trait ext_ctxt_ast_builder { fn strip_bounds(&self, bounds: &Generics) -> Generics; } -impl ext_ctxt_ast_builder for @ext_ctxt { +impl ext_ctxt_ast_builder for @ExtCtxt { fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { self.ty_path_ast_builder(path_global(~[ self.ident_of("core"), diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index 38e43d1ade562..c0b7f5bbb8426 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -31,11 +31,11 @@ that. use ast; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::pipes::proto::{state, protocol, next_state}; use ext::pipes::proto; -impl proto::visitor<(), (), ()> for @ext_ctxt { +impl proto::visitor<(), (), ()> for @ExtCtxt { fn visit_proto(&self, _proto: protocol, _states: &[()]) { } fn visit_state(&self, state: state, _m: &[()]) { diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs index 104e5f94d1770..8d45e47d54ef7 100644 --- a/src/libsyntax/ext/pipes/liveness.rs +++ b/src/libsyntax/ext/pipes/liveness.rs @@ -37,12 +37,12 @@ updating the states using rule (2) until there are no changes. */ -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::pipes::proto::{protocol_}; use std::bitv::Bitv; -pub fn analyze(proto: @mut protocol_, _cx: @ext_ctxt) { +pub fn analyze(proto: @mut protocol_, _cx: @ExtCtxt) { debug!("initializing colive analysis"); let num_states = proto.num_states(); let mut colive = do (copy proto.states).map_to_vec |state| { diff --git a/src/libsyntax/ext/pipes/mod.rs b/src/libsyntax/ext/pipes/mod.rs index 642f22e973680..46de21d1c0b2e 100644 --- a/src/libsyntax/ext/pipes/mod.rs +++ b/src/libsyntax/ext/pipes/mod.rs @@ -46,7 +46,7 @@ FIXME (#3072) - This is still incomplete. use ast; use codemap::span; use ext::base; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::pipes::parse_proto::proto_parser; use ext::pipes::pipec::gen_init; use ext::pipes::proto::visit; @@ -63,7 +63,7 @@ pub mod check; pub mod liveness; -pub fn expand_proto(cx: @ext_ctxt, _sp: span, id: ast::ident, +pub fn expand_proto(cx: @ExtCtxt, _sp: span, id: ast::ident, tt: ~[ast::token_tree]) -> base::MacResult { let sess = cx.parse_sess(); let cfg = cx.cfg(); diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 8a9c714e7e939..83b3572c85f36 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -12,7 +12,7 @@ use ast; use codemap::{dummy_sp, spanned}; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path}; use ext::pipes::ast_builder::{path_global}; use ext::pipes::proto::*; @@ -21,27 +21,27 @@ use opt_vec; use opt_vec::OptVec; pub trait gen_send { - fn gen_send(&mut self, cx: @ext_ctxt, try: bool) -> @ast::item; - fn to_ty(&mut self, cx: @ext_ctxt) -> @ast::Ty; + fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item; + fn to_ty(&mut self, cx: @ExtCtxt) -> @ast::Ty; } pub trait to_type_decls { - fn to_type_decls(&self, cx: @ext_ctxt) -> ~[@ast::item]; - fn to_endpoint_decls(&self, cx: @ext_ctxt, + fn to_type_decls(&self, cx: @ExtCtxt) -> ~[@ast::item]; + fn to_endpoint_decls(&self, cx: @ExtCtxt, dir: direction) -> ~[@ast::item]; } pub trait gen_init { - fn gen_init(&self, cx: @ext_ctxt) -> @ast::item; - fn compile(&self, cx: @ext_ctxt) -> @ast::item; - fn buffer_ty_path(&self, cx: @ext_ctxt) -> @ast::Ty; - fn gen_buffer_type(&self, cx: @ext_ctxt) -> @ast::item; - fn gen_buffer_init(&self, ext_cx: @ext_ctxt) -> @ast::expr; - fn gen_init_bounded(&self, ext_cx: @ext_ctxt) -> @ast::expr; + fn gen_init(&self, cx: @ExtCtxt) -> @ast::item; + fn compile(&self, cx: @ExtCtxt) -> @ast::item; + fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty; + fn gen_buffer_type(&self, cx: @ExtCtxt) -> @ast::item; + fn gen_buffer_init(&self, ext_cx: @ExtCtxt) -> @ast::expr; + fn gen_init_bounded(&self, ext_cx: @ExtCtxt) -> @ast::expr; } impl gen_send for message { - fn gen_send(&mut self, cx: @ext_ctxt, try: bool) -> @ast::item { + fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item { debug!("pipec: gen_send"); let name = self.name(); @@ -184,14 +184,14 @@ impl gen_send for message { } } - fn to_ty(&mut self, cx: @ext_ctxt) -> @ast::Ty { + fn to_ty(&mut self, cx: @ExtCtxt) -> @ast::Ty { cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span()) .add_tys(cx.ty_vars_global(&self.get_generics().ty_params))) } } impl to_type_decls for state { - fn to_type_decls(&self, cx: @ext_ctxt) -> ~[@ast::item] { + fn to_type_decls(&self, cx: @ExtCtxt) -> ~[@ast::item] { debug!("pipec: to_type_decls"); // This compiles into two different type declarations. Say the // state is called ping. This will generate both `ping` and @@ -240,7 +240,7 @@ impl to_type_decls for state { ] } - fn to_endpoint_decls(&self, cx: @ext_ctxt, + fn to_endpoint_decls(&self, cx: @ExtCtxt, dir: direction) -> ~[@ast::item] { debug!("pipec: to_endpoint_decls"); let dir = match dir { @@ -302,7 +302,7 @@ impl to_type_decls for state { } impl gen_init for protocol { - fn gen_init(&self, cx: @ext_ctxt) -> @ast::item { + fn gen_init(&self, cx: @ExtCtxt) -> @ast::item { let ext_cx = cx; debug!("gen_init"); @@ -340,7 +340,7 @@ impl gen_init for protocol { body.to_source(cx))) } - fn gen_buffer_init(&self, ext_cx: @ext_ctxt) -> @ast::expr { + fn gen_buffer_init(&self, ext_cx: @ExtCtxt) -> @ast::expr { ext_cx.struct_expr(path(~[ext_cx.ident_of("__Buffer")], dummy_sp()), self.states.map_to_vec(|s| { @@ -352,7 +352,7 @@ impl gen_init for protocol { })) } - fn gen_init_bounded(&self, ext_cx: @ext_ctxt) -> @ast::expr { + fn gen_init_bounded(&self, ext_cx: @ExtCtxt) -> @ast::expr { debug!("gen_init_bounded"); let buffer_fields = self.gen_buffer_init(ext_cx); let buffer = quote_expr!(~::core::pipes::Buffer { @@ -378,7 +378,7 @@ impl gen_init for protocol { }) } - fn buffer_ty_path(&self, cx: @ext_ctxt) -> @ast::Ty { + fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty { let mut params: OptVec = opt_vec::Empty; for (copy self.states).each |s| { for s.generics.ty_params.each |tp| { @@ -395,7 +395,7 @@ impl gen_init for protocol { .add_tys(cx.ty_vars_global(¶ms))) } - fn gen_buffer_type(&self, cx: @ext_ctxt) -> @ast::item { + fn gen_buffer_type(&self, cx: @ExtCtxt) -> @ast::item { let ext_cx = cx; let mut params: OptVec = opt_vec::Empty; let fields = do (copy self.states).map_to_vec |s| { @@ -436,7 +436,7 @@ impl gen_init for protocol { cx.strip_bounds(&generics)) } - fn compile(&self, cx: @ext_ctxt) -> @ast::item { + fn compile(&self, cx: @ExtCtxt) -> @ast::item { let mut items = ~[self.gen_init(cx)]; let mut client_states = ~[]; let mut server_states = ~[]; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 7bf58bc6f324c..12a0a0a24d616 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -10,7 +10,7 @@ use ast; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path}; #[deriving(Eq)] @@ -92,7 +92,7 @@ pub impl state_ { } /// Returns the type that is used for the messages. - fn to_ty(&self, cx: @ext_ctxt) -> @ast::Ty { + fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty { cx.ty_path_ast_builder (path(~[cx.ident_of(self.name)],self.span).add_tys( cx.ty_vars(&self.generics.ty_params))) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 2134c2ba19bff..2ccceeec294fc 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -10,7 +10,7 @@ use ast; use codemap::{BytePos, Pos, span}; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::base; use ext::build; use parse::token::*; @@ -30,7 +30,7 @@ use parse; pub mod rt { use ast; - use ext::base::ext_ctxt; + use ext::base::ExtCtxt; use parse; use print::pprust; @@ -44,11 +44,11 @@ pub mod rt { use print::pprust::{item_to_str, ty_to_str}; pub trait ToTokens { - pub fn to_tokens(&self, _cx: @ext_ctxt) -> ~[token_tree]; + pub fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree]; } impl ToTokens for ~[token_tree] { - pub fn to_tokens(&self, _cx: @ext_ctxt) -> ~[token_tree] { + pub fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree] { copy *self } } @@ -57,10 +57,10 @@ pub mod rt { trait ToSource : ToTokens { // Takes a thing and generates a string containing rust code for it. - pub fn to_source(cx: @ext_ctxt) -> ~str; + pub fn to_source(cx: @ExtCtxt) -> ~str; // If you can make source, you can definitely make tokens. - pub fn to_tokens(cx: @ext_ctxt) -> ~[token_tree] { + pub fn to_tokens(cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } @@ -69,80 +69,80 @@ pub mod rt { pub trait ToSource { // Takes a thing and generates a string containing rust code for it. - pub fn to_source(&self, cx: @ext_ctxt) -> ~str; + pub fn to_source(&self, cx: @ExtCtxt) -> ~str; } impl ToSource for ast::ident { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { copy *cx.parse_sess().interner.get(*self) } } impl ToSource for @ast::item { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { item_to_str(*self, cx.parse_sess().interner) } } impl<'self> ToSource for &'self [@ast::item] { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { str::connect(self.map(|i| i.to_source(cx)), "\n\n") } } impl ToSource for @ast::Ty { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { ty_to_str(*self, cx.parse_sess().interner) } } impl<'self> ToSource for &'self [@ast::Ty] { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { str::connect(self.map(|i| i.to_source(cx)), ", ") } } impl ToSource for Generics { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { pprust::generics_to_str(self, cx.parse_sess().interner) } } impl ToSource for @ast::expr { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { pprust::expr_to_str(*self, cx.parse_sess().interner) } } impl ToSource for ast::blk { - fn to_source(&self, cx: @ext_ctxt) -> ~str { + fn to_source(&self, cx: @ExtCtxt) -> ~str { pprust::block_to_str(self, cx.parse_sess().interner) } } impl<'self> ToSource for &'self str { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_str(@str::to_owned(*self))); pprust::lit_to_str(@lit) } } impl ToSource for int { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i)); pprust::lit_to_str(@lit) } } impl ToSource for i8 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i8)); pprust::lit_to_str(@lit) } } impl ToSource for i16 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i16)); pprust::lit_to_str(@lit) } @@ -150,49 +150,49 @@ pub mod rt { impl ToSource for i32 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i32)); pprust::lit_to_str(@lit) } } impl ToSource for i64 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i64)); pprust::lit_to_str(@lit) } } impl ToSource for uint { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u)); pprust::lit_to_str(@lit) } } impl ToSource for u8 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u8)); pprust::lit_to_str(@lit) } } impl ToSource for u16 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u16)); pprust::lit_to_str(@lit) } } impl ToSource for u32 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u32)); pprust::lit_to_str(@lit) } } impl ToSource for u64 { - fn to_source(&self, _cx: @ext_ctxt) -> ~str { + fn to_source(&self, _cx: @ExtCtxt) -> ~str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u64)); pprust::lit_to_str(@lit) } @@ -201,115 +201,115 @@ pub mod rt { // Alas ... we write these out instead. All redundant. impl ToTokens for ast::ident { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::item { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl<'self> ToTokens for &'self [@ast::item] { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::Ty { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl<'self> ToTokens for &'self [@ast::Ty] { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for Generics { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::expr { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for ast::blk { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl<'self> ToTokens for &'self str { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for int { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for i8 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for i16 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for i32 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for i64 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for uint { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for u8 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for u16 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for u32 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for u64 { - fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } @@ -321,7 +321,7 @@ pub mod rt { fn parse_tts(&self, s: ~str) -> ~[ast::token_tree]; } - impl ExtParseUtils for @ext_ctxt { + impl ExtParseUtils for ExtCtxt { fn parse_item(&self, s: ~str) -> @ast::item { let res = parse::parse_item_from_source_str( @@ -367,19 +367,19 @@ pub mod rt { } -pub fn expand_quote_tokens(cx: @ext_ctxt, +pub fn expand_quote_tokens(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::MRExpr(expand_tts(cx, sp, tts)) } -pub fn expand_quote_expr(cx: @ext_ctxt, +pub fn expand_quote_expr(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::MRExpr(expand_parse_call(cx, sp, "parse_expr", ~[], tts)) } -pub fn expand_quote_item(cx: @ext_ctxt, +pub fn expand_quote_item(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); @@ -387,7 +387,7 @@ pub fn expand_quote_item(cx: @ext_ctxt, ~[e_attrs], tts)) } -pub fn expand_quote_pat(cx: @ext_ctxt, +pub fn expand_quote_pat(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true)); @@ -395,7 +395,7 @@ pub fn expand_quote_pat(cx: @ext_ctxt, ~[e_refutable], tts)) } -pub fn expand_quote_ty(cx: @ext_ctxt, +pub fn expand_quote_ty(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false)); @@ -403,7 +403,7 @@ pub fn expand_quote_ty(cx: @ext_ctxt, ~[e_param_colons], tts)) } -pub fn expand_quote_stmt(cx: @ext_ctxt, +pub fn expand_quote_stmt(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); @@ -411,16 +411,16 @@ pub fn expand_quote_stmt(cx: @ext_ctxt, ~[e_attrs], tts)) } -fn ids_ext(cx: @ext_ctxt, strs: ~[~str]) -> ~[ast::ident] { +fn ids_ext(cx: @ExtCtxt, strs: ~[~str]) -> ~[ast::ident] { strs.map(|str| cx.parse_sess().interner.intern(*str)) } -fn id_ext(cx: @ext_ctxt, str: &str) -> ast::ident { +fn id_ext(cx: @ExtCtxt, str: &str) -> ast::ident { cx.parse_sess().interner.intern(str) } // Lift an ident to the expr that evaluates to that ident. -fn mk_ident(cx: @ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr { +fn mk_ident(cx: @ExtCtxt, sp: span, ident: ast::ident) -> @ast::expr { let e_str = build::mk_base_str(cx, sp, cx.str_of(ident)); build::mk_method_call(cx, sp, build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), @@ -428,13 +428,13 @@ fn mk_ident(cx: @ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr { ~[e_str]) } -fn mk_bytepos(cx: @ext_ctxt, sp: span, bpos: BytePos) -> @ast::expr { +fn mk_bytepos(cx: @ExtCtxt, sp: span, bpos: BytePos) -> @ast::expr { let path = ids_ext(cx, ~[~"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 { +fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { let name = match bop { PLUS => "PLUS", MINUS => "MINUS", @@ -451,7 +451,7 @@ fn mk_binop(cx: @ext_ctxt, sp: span, bop: token::binop) -> @ast::expr { ids_ext(cx, ~[name.to_owned()])) } -fn mk_token(cx: @ext_ctxt, sp: span, tok: &token::Token) -> @ast::expr { +fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { match *tok { BINOP(binop) => { @@ -600,7 +600,7 @@ fn mk_token(cx: @ext_ctxt, sp: span, tok: &token::Token) -> @ast::expr { } -fn mk_tt(cx: @ext_ctxt, sp: span, tt: &ast::token_tree) +fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree) -> ~[@ast::stmt] { match *tt { @@ -646,7 +646,7 @@ fn mk_tt(cx: @ext_ctxt, sp: span, tt: &ast::token_tree) } } -fn mk_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +fn mk_tts(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> ~[@ast::stmt] { let mut ss = ~[]; for tts.each |tt| { @@ -655,7 +655,7 @@ fn mk_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) ss } -fn expand_tts(cx: @ext_ctxt, +fn expand_tts(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> @ast::expr { @@ -729,7 +729,7 @@ fn expand_tts(cx: @ext_ctxt, ids_ext(cx, ~[~"tt"])))) } -fn expand_parse_call(cx: @ext_ctxt, +fn expand_parse_call(cx: @ExtCtxt, sp: span, parse_method: &str, arg_exprs: ~[@ast::expr], diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index c0d9b3f06af56..d78c06bec0774 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -23,7 +23,7 @@ use print::pprust; // a given file into the current one. /* line!(): expands to the current line number */ -pub fn expand_line(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_line(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "line!"); @@ -34,7 +34,7 @@ pub fn expand_line(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) } /* col!(): expands to the current column number */ -pub fn expand_col(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_col(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "col!"); @@ -46,7 +46,7 @@ pub fn expand_col(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) /* file!(): expands to the current filename */ /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ -pub fn expand_file(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "file!"); @@ -56,13 +56,13 @@ pub fn expand_file(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) base::MRExpr(mk_base_str(cx, topmost.call_site, filename)) } -pub fn expand_stringify(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_stringify(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, cx.parse_sess().interner); base::MRExpr(mk_base_str(cx, sp, s)) } -pub fn expand_mod(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_mod(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); base::MRExpr(mk_base_str(cx, sp, @@ -73,7 +73,7 @@ pub fn expand_mod(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) // include! : parse the given file as an expr // This is generally a bad idea because it's going to behave // unhygienically. -pub fn expand_include(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_include(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include!"); let p = parse::new_sub_parser_from_file( @@ -83,7 +83,7 @@ pub fn expand_include(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) } // include_str! : read the given file, insert it as a literal string expr -pub fn expand_include_str(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_include_str(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file))); @@ -97,7 +97,7 @@ pub fn expand_include_str(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) base::MRExpr(mk_base_str(cx, sp, result::unwrap(res))) } -pub fn expand_include_bin(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { @@ -141,7 +141,7 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { // resolve a file-system path to an absolute file-system path (if it // isn't already) -fn res_rel_file(cx: @ext_ctxt, sp: codemap::span, arg: &Path) -> Path { +fn res_rel_file(cx: @ExtCtxt, sp: codemap::span, arg: &Path) -> Path { // NB: relative paths are resolved relative to the compilation unit if !arg.is_absolute { let cu = Path(cx.codemap().span_to_filename(sp)); diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index 0ecb3b2a3f47f..25607a8bfa76f 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -10,12 +10,12 @@ use ast; use codemap::span; -use ext::base::ext_ctxt; +use ext::base::ExtCtxt; use ext::base; use parse::lexer::{new_tt_reader, reader}; use parse::parser::Parser; -pub fn expand_trace_macros(cx: @ext_ctxt, +pub fn expand_trace_macros(cx: @ExtCtxt, sp: span, tt: &[ast::token_tree]) -> base::MacResult { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index d34eca342e93e..3814243efc4c6 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -13,7 +13,7 @@ use ast::{ident, matcher_, matcher, match_tok, match_nonterminal, match_seq}; use ast::{tt_delim}; use ast; use codemap::{span, spanned, dummy_sp}; -use ext::base::{ext_ctxt, MacResult, MRAny, MRDef, MacroDef, NormalTT}; +use ext::base::{ExtCtxt, MacResult, MRAny, MRDef, MacroDef, NormalTT}; use ext::base; use ext::tt::macro_parser::{error}; use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal}; @@ -26,7 +26,7 @@ use print; use core::io; -pub fn add_new_extension(cx: @ext_ctxt, +pub fn add_new_extension(cx: @ExtCtxt, sp: span, name: ident, arg: ~[ast::token_tree]) @@ -73,7 +73,7 @@ pub fn add_new_extension(cx: @ext_ctxt, }; // Given `lhses` and `rhses`, this is the new macro we create - fn generic_extension(cx: @ext_ctxt, sp: span, name: ident, + fn generic_extension(cx: @ExtCtxt, sp: span, name: ident, arg: &[ast::token_tree], lhses: &[@named_match], rhses: &[@named_match]) -> MacResult { @@ -145,7 +145,7 @@ pub fn add_new_extension(cx: @ext_ctxt, cx.span_fatal(best_fail_spot, best_fail_msg); } - let exp: @fn(@ext_ctxt, span, &[ast::token_tree]) -> MacResult = + let exp: @fn(@ExtCtxt, span, &[ast::token_tree]) -> MacResult = |cx, sp, arg| generic_extension(cx, sp, name, arg, *lhses, *rhses); return MRDef(MacroDef{ diff --git a/src/test/run-pass-fulldeps/quote-tokens.rs b/src/test/run-pass-fulldeps/quote-tokens.rs index 3ec54955229d3..0cd416afc8316 100644 --- a/src/test/run-pass-fulldeps/quote-tokens.rs +++ b/src/test/run-pass-fulldeps/quote-tokens.rs @@ -12,9 +12,9 @@ extern mod syntax; -use syntax::ext::base::ext_ctxt; +use syntax::ext::base::ExtCtxt; -fn syntax_extension(ext_cx: @ext_ctxt) { +fn syntax_extension(ext_cx: @ExtCtxt) { let e_toks : ~[syntax::ast::token_tree] = quote_tokens!(1 + 2); let p_toks : ~[syntax::ast::token_tree] = quote_tokens!((x, 1 .. 4, *)); From 8c15a0ec4cf023a08078d74ed615ecef0cc10a66 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 17 May 2013 23:51:25 +1000 Subject: [PATCH 4/6] syntax/ext: collect the ast building traits into a single trait. --- src/libsyntax/ext/build.rs | 488 ++++++++++++++++++++----- src/libsyntax/ext/pipes/ast_builder.rs | 382 +------------------ src/libsyntax/ext/pipes/pipec.rs | 38 +- src/libsyntax/ext/pipes/proto.rs | 5 +- 4 files changed, 420 insertions(+), 493 deletions(-) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index e28c04d198af3..a2d88c1f23a88 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -8,13 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use abi::AbiSet; +use ast::ident; use ast; +use ast_util; use codemap; -use codemap::span; +use codemap::{span, respan, dummy_sp, spanned}; use fold; use ext::base::ExtCtxt; -use ext::build; - +use ext::quote::rt::*; +use opt_vec; use opt_vec::OptVec; pub struct Field { @@ -547,14 +550,8 @@ mod syntax { pub use parse; } -trait ExtCtxtMethods { - fn bind_path(&self, - span: span, - ident: ast::ident, - path: @ast::Path, - bounds: @OptVec) - -> ast::TyParam; - fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; +pub trait AstBuilder { + // paths fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; fn path_tps(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) @@ -564,16 +561,35 @@ trait ExtCtxtMethods { strs: ~[ast::ident], tps: ~[@ast::Ty]) -> @ast::Path; - fn ty_path(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) - -> @ast::Ty; - fn binder_pat(&self, span: span, nm: ast::ident) -> @ast::pat; - fn stmt(&self, expr: @ast::expr) -> @ast::stmt; + + // types + fn ty_path(&self, @ast::Path) -> @ast::Ty; + + fn ty_param(&self, id: ast::ident, bounds: @OptVec) + -> ast::TyParam; + fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty]; + fn ty_vars_global(&self, ty_params: &OptVec) -> ~[@ast::Ty]; + fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field; + fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty; + fn ty_infer(&self) -> @ast::Ty; + fn ty_nil_ast_builder(&self) -> @ast::Ty; + fn strip_bounds(&self, bounds: &Generics) -> Generics; + + + // statements + fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt; + fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt; + + // literals fn lit_str(&self, span: span, s: @~str) -> @ast::expr; fn lit_uint(&self, span: span, i: uint) -> @ast::expr; - fn lambda0(&self, blk: ast::blk) -> @ast::expr; - fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr; - fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk; - fn expr_blk(&self, expr: @ast::expr) -> ast::blk; + + // blocks + fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::blk; + fn blk_expr(&self, expr: @ast::expr) -> ast::blk; + + // expressions + fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; fn expr_path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; fn expr_var(&self, span: span, var: &str) -> @ast::expr; @@ -588,6 +604,13 @@ trait ExtCtxtMethods { ident: ast::ident, args: ~[@ast::expr]) -> @ast::expr; + fn expr_blk(&self, b: ast::blk) -> @ast::expr; + fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field; + fn expr_struct(&self, + path: @ast::Path, + fields: ~[ast::field]) -> @ast::expr; + fn lambda0(&self, blk: ast::blk) -> @ast::expr; + fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr; fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr; fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) -> @ast::expr; @@ -597,37 +620,64 @@ trait ExtCtxtMethods { stmts: ~[@ast::stmt], ident: ast::ident) -> @ast::expr; -} -impl ExtCtxtMethods for @ExtCtxt { - fn bind_path( - &self, - _span: span, - ident: ast::ident, - path: @ast::Path, - bounds: @OptVec - ) -> ast::TyParam { - let bound = ast::TraitTyParamBound(@ast::trait_ref { - ref_id: self.next_id(), - path: path - }); + // items + fn item(&self, name: ident, span: span, node: ast::item_) -> @ast::item; - ast::TyParam { - ident: ident, - id: self.next_id(), - bounds: @bounds.prepend(bound) - } - } + fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg; + fn fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; - fn expr(&self, span: span, node: ast::expr_) -> @ast::expr { - @ast::expr { - id: self.next_id(), - callee_id: self.next_id(), - node: node, - span: span, - } - } + fn item_fn_poly(&self, + ame: ident, + inputs: ~[ast::arg], + output: @ast::Ty, + generics: Generics, + body: ast::blk) -> @ast::item; + fn item_fn(&self, + name: ident, + inputs: ~[ast::arg], + output: @ast::Ty, + body: ast::blk) -> @ast::item; + + fn variant(&self, + name: ident, + span: span, + tys: ~[@ast::Ty]) -> ast::variant; + fn item_enum_poly(&self, + name: ident, + span: span, + enum_definition: ast::enum_def, + generics: Generics) -> @ast::item; + fn item_enum(&self, + name: ident, + span: span, + enum_definition: ast::enum_def) -> @ast::item; + + fn item_struct_poly(&self, + name: ident, + span: span, + struct_def: ast::struct_def, + generics: Generics) -> @ast::item; + fn item_struct(&self, + name: ident, + span: span, + struct_def: ast::struct_def) -> @ast::item; + + fn item_mod(&self, + name: ident, + span: span, + items: ~[@ast::item]) -> @ast::item; + + fn item_ty_poly(&self, + name: ident, + span: span, + ty: @ast::Ty, + generics: Generics) -> @ast::item; + fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item; + +} +impl AstBuilder for @ExtCtxt { fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path { @ast::Path { span: span, @@ -678,37 +728,89 @@ impl ExtCtxtMethods for @ExtCtxt { } } - fn ty_path( - &self, - span: span, - strs: ~[ast::ident], - tps: ~[@ast::Ty] - ) -> @ast::Ty { + fn ty_path(&self, path: @ast::Path) -> @ast::Ty { + build::mk_ty(*self, path.span, + ast::ty_path(path, self.next_id())) + } + + fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { + self.ty_path( + self.path_tps_global(dummy_sp(), + ~[ + self.ident_of("core"), + self.ident_of("option"), + self.ident_of("Option") + ], + ~[ ty ])) + } + + fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field { + spanned { + node: ast::ty_field_ { + ident: name, + mt: ast::mt { ty: ty, mutbl: ast::m_imm }, + }, + span: dummy_sp(), + } + } + + fn ty_infer(&self) -> @ast::Ty { @ast::Ty { id: self.next_id(), - node: ast::ty_path( - self.path_tps(span, strs, tps), - self.next_id()), - span: span, + node: ast::ty_infer, + span: dummy_sp(), } } - fn binder_pat(&self, span: span, nm: ast::ident) -> @ast::pat { - @ast::pat { + fn ty_param(&self, id: ast::ident, bounds: @OptVec) + -> ast::TyParam + { + ast::TyParam { ident: id, id: self.next_id(), bounds: bounds } + } + + fn ty_nil_ast_builder(&self) -> @ast::Ty { + @ast::Ty { id: self.next_id(), - node: ast::pat_ident( - ast::bind_by_ref(ast::m_imm), - self.path(span, ~[nm]), - None), - span: span, + node: ast::ty_nil, + span: dummy_sp(), + } + } + + fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty] { + opt_vec::take_vec( + ty_params.map(|p| self.ty_path( + mk_raw_path(dummy_sp(), ~[p.ident])))) + } + + fn ty_vars_global(&self, + ty_params: &OptVec) -> ~[@ast::Ty] { + opt_vec::take_vec( + ty_params.map(|p| self.ty_path( + mk_raw_path(dummy_sp(), ~[p.ident])))) + } + + fn strip_bounds(&self, generics: &Generics) -> Generics { + let no_bounds = @opt_vec::Empty; + let new_params = do generics.ty_params.map |ty_param| { + ast::TyParam { bounds: no_bounds, ..copy *ty_param } + }; + Generics { + ty_params: new_params, + .. copy *generics } } - fn stmt(&self, expr: @ast::expr) -> @ast::stmt { + + fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt { @codemap::spanned { node: ast::stmt_semi(expr, self.next_id()), span: expr.span } } + fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt { + let ext_cx = *self; + quote_stmt!( let $ident = $e; ) + } + fn lit_str(&self, span: span, s: @~str) -> @ast::expr { self.expr( span, @@ -729,24 +831,12 @@ impl ExtCtxtMethods for @ExtCtxt { span: span})) } - fn lambda0(&self, blk: ast::blk) -> @ast::expr { - let ext_cx = *self; - let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk)); - quote_expr!( || $blk_e ) - } - - fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr { - let ext_cx = *self; - let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk)); - quote_expr!( |$ident| $blk_e ) - } - - fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk { + fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::blk { codemap::spanned { node: ast::blk_ { view_items: ~[], stmts: stmts, - expr: None, + expr: expr, id: self.next_id(), rules: ast::default_blk, }, @@ -754,16 +844,16 @@ impl ExtCtxtMethods for @ExtCtxt { } } - fn expr_blk(&self, expr: @ast::expr) -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: ~[], - expr: Some(expr), - id: self.next_id(), - rules: ast::default_blk, - }, - span: expr.span, + fn blk_expr(&self, expr: @ast::expr) -> ast::blk { + self.blk(expr.span, ~[], Some(expr)) + } + + fn expr(&self, span: span, node: ast::expr_) -> @ast::expr { + @ast::expr { + id: self.next_id(), + callee_id: self.next_id(), + node: node, + span: span, } } @@ -815,18 +905,49 @@ impl ExtCtxtMethods for @ExtCtxt { self.expr(span, ast::expr_method_call(expr, ident, ~[], args, ast::NoSugar)) } + fn expr_blk(&self, b: ast::blk) -> @ast::expr { + self.expr(dummy_sp(), ast::expr_block(b)) + } + fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field { + spanned { + node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e }, + span: dummy_sp(), + } + } + fn expr_struct(&self, path: @ast::Path, + fields: ~[ast::field]) -> @ast::expr { + @ast::expr { + id: self.next_id(), + callee_id: self.next_id(), + node: ast::expr_struct(path, fields, None), + span: dummy_sp() + } + } + + + fn lambda0(&self, blk: ast::blk) -> @ast::expr { + let ext_cx = *self; + let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk)); + quote_expr!( || $blk_e ) + } + + fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr { + let ext_cx = *self; + let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk)); + quote_expr!( |$ident| $blk_e ) + } fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr { - self.lambda0(self.expr_blk(expr)) + self.lambda0(self.blk_expr(expr)) } fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) -> @ast::expr { - self.lambda1(self.expr_blk(expr), ident) + self.lambda1(self.blk_expr(expr), ident) } fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr { - self.lambda0(self.blk(span, stmts)) + self.lambda0(self.blk(span, stmts, None)) } fn lambda_stmts_1(&self, @@ -834,6 +955,189 @@ impl ExtCtxtMethods for @ExtCtxt { stmts: ~[@ast::stmt], ident: ast::ident) -> @ast::expr { - self.lambda1(self.blk(span, stmts), ident) + self.lambda1(self.blk(span, stmts, None), ident) + } + + + fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg { + ast::arg { + is_mutbl: false, + ty: ty, + pat: @ast::pat { + id: self.next_id(), + node: ast::pat_ident( + ast::bind_by_copy, + ast_util::ident_to_path(dummy_sp(), name), + None), + span: dummy_sp(), + }, + id: self.next_id(), + } } + + fn fn_decl(&self, inputs: ~[ast::arg], + output: @ast::Ty) -> ast::fn_decl { + ast::fn_decl { + inputs: inputs, + output: output, + cf: ast::return_val, + } + } + + fn item(&self, name: ident, span: span, + node: ast::item_) -> @ast::item { + + // XXX: Would be nice if our generated code didn't violate + // Rust coding conventions + let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ { + style: ast::attr_outer, + value: @respan(dummy_sp(), + ast::meta_list(@~"allow", ~[ + @respan(dummy_sp(), + ast::meta_word( + @~"non_camel_case_types")) + ])), + is_sugared_doc: false + }); + + @ast::item { ident: name, + attrs: ~[non_camel_case_attribute], + id: self.next_id(), + node: node, + vis: ast::public, + span: span } + } + + fn item_fn_poly(&self, name: ident, + inputs: ~[ast::arg], + output: @ast::Ty, + generics: Generics, + body: ast::blk) -> @ast::item { + self.item(name, + dummy_sp(), + ast::item_fn(self.fn_decl(inputs, output), + ast::impure_fn, + AbiSet::Rust(), + generics, + body)) + } + + fn item_fn(&self, + name: ident, + inputs: ~[ast::arg], + output: @ast::Ty, + body: ast::blk + ) -> @ast::item { + self.item_fn_poly( + name, + inputs, + output, + ast_util::empty_generics(), + body + ) + } + + fn variant(&self, name: ident, span: span, + tys: ~[@ast::Ty]) -> ast::variant { + let args = do tys.map |ty| { + ast::variant_arg { ty: *ty, id: self.next_id() } + }; + + spanned { + node: ast::variant_ { + name: name, + attrs: ~[], + kind: ast::tuple_variant_kind(args), + id: self.next_id(), + disr_expr: None, + vis: ast::public + }, + span: span, + } + } + + fn item_enum_poly(&self, name: ident, span: span, + enum_definition: ast::enum_def, + generics: Generics) -> @ast::item { + self.item(name, span, ast::item_enum(enum_definition, generics)) + } + + fn item_enum(&self, name: ident, span: span, + enum_definition: ast::enum_def) -> @ast::item { + self.item_enum_poly(name, span, enum_definition, + ast_util::empty_generics()) + } + + fn item_struct( + &self, name: ident, + span: span, + struct_def: ast::struct_def + ) -> @ast::item { + self.item_struct_poly( + name, + span, + struct_def, + ast_util::empty_generics() + ) + } + + fn item_struct_poly( + &self, + name: ident, + span: span, + struct_def: ast::struct_def, + generics: Generics + ) -> @ast::item { + self.item(name, span, ast::item_struct(@struct_def, generics)) + } + + fn item_mod(&self, name: ident, span: span, + items: ~[@ast::item]) -> @ast::item { + + // XXX: Total hack: import `core::kinds::Owned` to work around a + // parser bug whereby `fn f` doesn't parse. + let vi = ast::view_item_use(~[ + @codemap::spanned { + node: ast::view_path_simple( + self.ident_of("Owned"), + mk_raw_path( + codemap::dummy_sp(), + ~[ + self.ident_of("core"), + self.ident_of("kinds"), + self.ident_of("Owned") + ] + ), + self.next_id() + ), + span: codemap::dummy_sp() + } + ]); + let vi = @ast::view_item { + node: vi, + attrs: ~[], + vis: ast::private, + span: codemap::dummy_sp() + }; + + self.item( + name, + span, + ast::item_mod(ast::_mod { + view_items: ~[vi], + items: items, + }) + ) + } + + fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty, + generics: Generics) -> @ast::item { + self.item(name, span, ast::item_ty(ty, generics)) + } + + fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item { + self.item_ty_poly(name, span, ty, ast_util::empty_generics()) + } + + } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 1f38b14efbecf..44f47c0d588a4 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -13,16 +13,10 @@ // To start with, it will be use dummy spans, but it might someday do // something smarter. -use abi::AbiSet; use ast::ident; use ast; -use ast_util; -use codemap::{span, respan, dummy_sp, spanned}; -use codemap; -use ext::base::ExtCtxt; +use codemap::span; use ext::quote::rt::*; -use opt_vec; -use opt_vec::OptVec; // Transitional reexports so qquote can find the paths it is looking for mod syntax { @@ -66,377 +60,3 @@ impl append_types for @ast::Path { } } } - -pub trait ext_ctxt_ast_builder { - fn ty_param(&self, id: ast::ident, bounds: @OptVec) - -> ast::TyParam; - fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg; - fn expr_block(&self, e: @ast::expr) -> ast::blk; - fn fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; - fn item(&self, name: ident, span: span, node: ast::item_) -> @ast::item; - fn item_fn_poly(&self, - ame: ident, - inputs: ~[ast::arg], - output: @ast::Ty, - generics: Generics, - body: ast::blk) -> @ast::item; - fn item_fn(&self, - name: ident, - inputs: ~[ast::arg], - output: @ast::Ty, - body: ast::blk) -> @ast::item; - fn item_enum_poly(&self, - name: ident, - span: span, - enum_definition: ast::enum_def, - generics: Generics) -> @ast::item; - fn item_enum(&self, - name: ident, - span: span, - enum_definition: ast::enum_def) -> @ast::item; - fn item_struct_poly(&self, - name: ident, - span: span, - struct_def: ast::struct_def, - generics: Generics) -> @ast::item; - fn item_struct(&self, - name: ident, - span: span, - struct_def: ast::struct_def) -> @ast::item; - fn struct_expr(&self, - path: @ast::Path, - fields: ~[ast::field]) -> @ast::expr; - fn variant(&self, - name: ident, - span: span, - tys: ~[@ast::Ty]) -> ast::variant; - fn item_mod(&self, - name: ident, - span: span, - items: ~[@ast::item]) -> @ast::item; - fn ty_path_ast_builder(&self, path: @ast::Path) -> @ast::Ty; - fn item_ty_poly(&self, - name: ident, - span: span, - ty: @ast::Ty, - generics: Generics) -> @ast::item; - fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item; - fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty]; - fn ty_vars_global(&self, ty_params: &OptVec) -> ~[@ast::Ty]; - fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field; - fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field; - fn block(&self, stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk; - fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt; - fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt; - fn block_expr(&self, b: ast::blk) -> @ast::expr; - fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty; - fn ty_infer(&self) -> @ast::Ty; - fn ty_nil_ast_builder(&self) -> @ast::Ty; - fn strip_bounds(&self, bounds: &Generics) -> Generics; -} - -impl ext_ctxt_ast_builder for @ExtCtxt { - fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { - self.ty_path_ast_builder(path_global(~[ - self.ident_of("core"), - self.ident_of("option"), - self.ident_of("Option") - ], dummy_sp()).add_ty(ty)) - } - - fn block_expr(&self, b: ast::blk) -> @ast::expr { - @expr { - id: self.next_id(), - callee_id: self.next_id(), - node: ast::expr_block(b), - span: dummy_sp(), - } - } - - fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt { - @spanned { node: ast::stmt_expr(e, self.next_id()), - span: dummy_sp()} - } - - fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt { - let ext_cx = *self; - quote_stmt!( let $ident = $e; ) - } - - fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field { - spanned { - node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e }, - span: dummy_sp(), - } - } - - fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field { - spanned { - node: ast::ty_field_ { - ident: name, - mt: ast::mt { ty: ty, mutbl: ast::m_imm }, - }, - span: dummy_sp(), - } - } - - fn ty_infer(&self) -> @ast::Ty { - @ast::Ty { - id: self.next_id(), - node: ast::ty_infer, - span: dummy_sp(), - } - } - - fn ty_param(&self, id: ast::ident, bounds: @OptVec) - -> ast::TyParam - { - ast::TyParam { ident: id, id: self.next_id(), bounds: bounds } - } - - fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg { - ast::arg { - is_mutbl: false, - ty: ty, - pat: @ast::pat { - id: self.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - ast_util::ident_to_path(dummy_sp(), name), - None), - span: dummy_sp(), - }, - id: self.next_id(), - } - } - - fn block(&self, stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk { - let blk = ast::blk_ { - view_items: ~[], - stmts: stmts, - expr: Some(e), - id: self.next_id(), - rules: ast::default_blk, - }; - - spanned { node: blk, span: dummy_sp() } - } - - fn expr_block(&self, e: @ast::expr) -> ast::blk { - self.block(~[], e) - } - - fn fn_decl(&self, inputs: ~[ast::arg], - output: @ast::Ty) -> ast::fn_decl { - ast::fn_decl { - inputs: inputs, - output: output, - cf: ast::return_val, - } - } - - fn item(&self, name: ident, span: span, - node: ast::item_) -> @ast::item { - - // XXX: Would be nice if our generated code didn't violate - // Rust coding conventions - let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ { - style: ast::attr_outer, - value: @respan(dummy_sp(), - ast::meta_list(@~"allow", ~[ - @respan(dummy_sp(), - ast::meta_word( - @~"non_camel_case_types")) - ])), - is_sugared_doc: false - }); - - @ast::item { ident: name, - attrs: ~[non_camel_case_attribute], - id: self.next_id(), - node: node, - vis: ast::public, - span: span } - } - - fn item_fn_poly(&self, name: ident, - inputs: ~[ast::arg], - output: @ast::Ty, - generics: Generics, - body: ast::blk) -> @ast::item { - self.item(name, - dummy_sp(), - ast::item_fn(self.fn_decl(inputs, output), - ast::impure_fn, - AbiSet::Rust(), - generics, - body)) - } - - fn item_fn(&self, - name: ident, - inputs: ~[ast::arg], - output: @ast::Ty, - body: ast::blk - ) -> @ast::item { - self.item_fn_poly( - name, - inputs, - output, - ast_util::empty_generics(), - body - ) - } - - fn item_enum_poly(&self, name: ident, span: span, - enum_definition: ast::enum_def, - generics: Generics) -> @ast::item { - self.item(name, span, ast::item_enum(enum_definition, generics)) - } - - fn item_enum(&self, name: ident, span: span, - enum_definition: ast::enum_def) -> @ast::item { - self.item_enum_poly(name, span, enum_definition, - ast_util::empty_generics()) - } - - fn item_struct( - &self, name: ident, - span: span, - struct_def: ast::struct_def - ) -> @ast::item { - self.item_struct_poly( - name, - span, - struct_def, - ast_util::empty_generics() - ) - } - - fn item_struct_poly( - &self, - name: ident, - span: span, - struct_def: ast::struct_def, - generics: Generics - ) -> @ast::item { - self.item(name, span, ast::item_struct(@struct_def, generics)) - } - - fn struct_expr(&self, path: @ast::Path, - fields: ~[ast::field]) -> @ast::expr { - @ast::expr { - id: self.next_id(), - callee_id: self.next_id(), - node: ast::expr_struct(path, fields, None), - span: dummy_sp() - } - } - - fn variant(&self, name: ident, span: span, - tys: ~[@ast::Ty]) -> ast::variant { - let args = do tys.map |ty| { - ast::variant_arg { ty: *ty, id: self.next_id() } - }; - - spanned { - node: ast::variant_ { - name: name, - attrs: ~[], - kind: ast::tuple_variant_kind(args), - id: self.next_id(), - disr_expr: None, - vis: ast::public - }, - span: span, - } - } - - fn item_mod(&self, name: ident, span: span, - items: ~[@ast::item]) -> @ast::item { - - // XXX: Total hack: import `core::kinds::Owned` to work around a - // parser bug whereby `fn f` doesn't parse. - let vi = ast::view_item_use(~[ - @codemap::spanned { - node: ast::view_path_simple( - self.ident_of("Owned"), - path( - ~[ - self.ident_of("core"), - self.ident_of("kinds"), - self.ident_of("Owned") - ], - codemap::dummy_sp() - ), - self.next_id() - ), - span: codemap::dummy_sp() - } - ]); - let vi = @ast::view_item { - node: vi, - attrs: ~[], - vis: ast::private, - span: codemap::dummy_sp() - }; - - self.item( - name, - span, - ast::item_mod(ast::_mod { - view_items: ~[vi], - items: items, - }) - ) - } - - fn ty_path_ast_builder(&self, path: @ast::Path) -> @ast::Ty { - @ast::Ty { - id: self.next_id(), - node: ast::ty_path(path, self.next_id()), - span: path.span, - } - } - - fn ty_nil_ast_builder(&self) -> @ast::Ty { - @ast::Ty { - id: self.next_id(), - node: ast::ty_nil, - span: dummy_sp(), - } - } - - fn strip_bounds(&self, generics: &Generics) -> Generics { - let no_bounds = @opt_vec::Empty; - let new_params = do generics.ty_params.map |ty_param| { - ast::TyParam { bounds: no_bounds, ..copy *ty_param } - }; - Generics { - ty_params: new_params, - .. copy *generics - } - } - - fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty, - generics: Generics) -> @ast::item { - self.item(name, span, ast::item_ty(ty, generics)) - } - - fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item { - self.item_ty_poly(name, span, ty, ast_util::empty_generics()) - } - - fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty] { - opt_vec::take_vec( - ty_params.map(|p| self.ty_path_ast_builder( - path(~[p.ident], dummy_sp())))) - } - - fn ty_vars_global(&self, - ty_params: &OptVec) -> ~[@ast::Ty] { - opt_vec::take_vec( - ty_params.map(|p| self.ty_path_ast_builder( - path(~[p.ident], dummy_sp())))) - } -} diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 83b3572c85f36..4362699378344 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -13,7 +13,8 @@ use ast; use codemap::{dummy_sp, spanned}; use ext::base::ExtCtxt; -use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path}; +use ext::build::AstBuilder; +use ext::pipes::ast_builder::{append_types, path}; use ext::pipes::ast_builder::{path_global}; use ext::pipes::proto::*; use ext::quote::rt::*; @@ -54,7 +55,7 @@ impl gen_send for message { let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str())); let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(*n, *t)); - let pipe_ty = cx.ty_path_ast_builder( + let pipe_ty = cx.ty_path( path(~[this.data_name()], span) .add_tys(cx.ty_vars_global(&this.generics.ty_params))); let args_ast = vec::append( @@ -111,7 +112,7 @@ impl gen_send for message { let body = cx.parse_expr(body); - let mut rty = cx.ty_path_ast_builder(path(~[next.data_name()], + let mut rty = cx.ty_path(path(~[next.data_name()], span) .add_tys(copy next_state.tys)); if try { @@ -124,7 +125,7 @@ impl gen_send for message { args_ast, rty, self.get_generics(), - cx.expr_block(body)) + cx.blk_expr(body)) } message(ref _id, span, ref tys, this, None) => { @@ -137,7 +138,7 @@ impl gen_send for message { let args_ast = vec::append( ~[cx.arg(cx.ident_of("pipe"), - cx.ty_path_ast_builder( + cx.ty_path( path(~[this.data_name()], span) .add_tys(cx.ty_vars_global( &this.generics.ty_params))))], @@ -179,13 +180,13 @@ impl gen_send for message { cx.ty_nil_ast_builder() }, self.get_generics(), - cx.expr_block(body)) + cx.blk_expr(body)) } } } fn to_ty(&mut self, cx: @ExtCtxt) -> @ast::Ty { - cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span()) + cx.ty_path(path(~[cx.ident_of(self.name())], self.span()) .add_tys(cx.ty_vars_global(&self.get_generics().ty_params))) } } @@ -217,7 +218,7 @@ impl to_type_decls for state { }; vec::append_one(tys, - cx.ty_path_ast_builder( + cx.ty_path( path(~[cx.ident_of(dir), cx.ident_of(next_name)], span) .add_tys(copy next_state.tys))) @@ -264,12 +265,12 @@ impl to_type_decls for state { cx.item_ty_poly( self.data_name(), self.span, - cx.ty_path_ast_builder( + cx.ty_path( path_global(~[cx.ident_of("core"), cx.ident_of("pipes"), cx.ident_of(dir.to_str() + "Packet")], dummy_sp()) - .add_ty(cx.ty_path_ast_builder( + .add_ty(cx.ty_path( path(~[cx.ident_of("super"), self.data_name()], dummy_sp()) @@ -282,13 +283,13 @@ impl to_type_decls for state { cx.item_ty_poly( self.data_name(), self.span, - cx.ty_path_ast_builder( + cx.ty_path( path_global(~[cx.ident_of("core"), cx.ident_of("pipes"), cx.ident_of(dir.to_str() + "PacketBuffered")], dummy_sp()) - .add_tys(~[cx.ty_path_ast_builder( + .add_tys(~[cx.ty_path( path(~[cx.ident_of("super"), self.data_name()], dummy_sp()) @@ -341,7 +342,7 @@ impl gen_init for protocol { } fn gen_buffer_init(&self, ext_cx: @ExtCtxt) -> @ast::expr { - ext_cx.struct_expr(path(~[ext_cx.ident_of("__Buffer")], + ext_cx.expr_struct(path(~[ext_cx.ident_of("__Buffer")], dummy_sp()), self.states.map_to_vec(|s| { let fty = s.to_ty(ext_cx); @@ -360,15 +361,16 @@ impl gen_init for protocol { data: $buffer_fields, }); - let entangle_body = ext_cx.block_expr( - ext_cx.block( + let entangle_body = ext_cx.expr_blk( + ext_cx.blk( + dummy_sp(), self.states.map_to_vec( |s| ext_cx.parse_stmt( fmt!("data.%s.set_buffer(buffer)", s.name))), - ext_cx.parse_expr(fmt!( + Some(ext_cx.parse_expr(fmt!( "::core::ptr::to_mut_unsafe_ptr(&mut (data.%s))", - self.states[0].name)))); + self.states[0].name))))); quote_expr!({ let buffer = $buffer; @@ -389,7 +391,7 @@ impl gen_init for protocol { } } - cx.ty_path_ast_builder(path(~[cx.ident_of("super"), + cx.ty_path(path(~[cx.ident_of("super"), cx.ident_of("__Buffer")], copy self.span) .add_tys(cx.ty_vars_global(¶ms))) diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 12a0a0a24d616..4471c5bb9b855 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -11,7 +11,8 @@ use ast; use codemap::span; use ext::base::ExtCtxt; -use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path}; +use ext::build::AstBuilder; +use ext::pipes::ast_builder::{append_types, path}; #[deriving(Eq)] pub enum direction { send, recv } @@ -93,7 +94,7 @@ pub impl state_ { /// Returns the type that is used for the messages. fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty { - cx.ty_path_ast_builder + cx.ty_path (path(~[cx.ident_of(self.name)],self.span).add_tys( cx.ty_vars(&self.generics.ty_params))) } From 6e5051553050974eb9362e1465cc2d40e2c9a610 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 18 May 2013 00:19:28 +1000 Subject: [PATCH 5/6] syntax/ext: migrate build.rs functions to AstBuilder methods. --- src/libsyntax/ext/build.rs | 1330 ++++++++++++-------- src/libsyntax/ext/bytes.rs | 12 +- src/libsyntax/ext/deriving/clone.rs | 9 +- src/libsyntax/ext/deriving/cmp/eq.rs | 6 +- src/libsyntax/ext/deriving/cmp/ord.rs | 24 +- src/libsyntax/ext/deriving/cmp/totaleq.rs | 4 +- src/libsyntax/ext/deriving/cmp/totalord.rs | 6 +- src/libsyntax/ext/deriving/decodable.rs | 168 ++- src/libsyntax/ext/deriving/encodable.rs | 131 +- src/libsyntax/ext/deriving/generic.rs | 34 +- src/libsyntax/ext/deriving/iter_bytes.rs | 8 +- src/libsyntax/ext/deriving/mod.rs | 52 +- src/libsyntax/ext/deriving/rand.rs | 40 +- src/libsyntax/ext/deriving/to_str.rs | 6 +- src/libsyntax/ext/deriving/ty.rs | 36 +- src/libsyntax/ext/env.rs | 6 +- src/libsyntax/ext/fmt.rs | 41 +- src/libsyntax/ext/quote.rs | 120 +- src/libsyntax/ext/source_util.rs | 18 +- 19 files changed, 1126 insertions(+), 925 deletions(-) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a2d88c1f23a88..eb48ed583750d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -25,525 +25,6 @@ pub struct Field { ex: @ast::expr } -pub fn mk_expr(cx: @ExtCtxt, - sp: codemap::span, - expr: ast::expr_) - -> @ast::expr { - @ast::expr { - id: cx.next_id(), - callee_id: cx.next_id(), - node: expr, - span: sp, - } -} - -pub fn mk_lit(cx: @ExtCtxt, sp: span, lit: ast::lit_) -> @ast::expr { - let sp_lit = @codemap::spanned { node: lit, span: sp }; - mk_expr(cx, sp, ast::expr_lit(sp_lit)) -} -pub fn mk_int(cx: @ExtCtxt, sp: span, i: int) -> @ast::expr { - let lit = ast::lit_int(i as i64, ast::ty_i); - return mk_lit(cx, sp, lit); -} -pub fn mk_uint(cx: @ExtCtxt, sp: span, u: uint) -> @ast::expr { - let lit = ast::lit_uint(u as u64, ast::ty_u); - return mk_lit(cx, sp, lit); -} -pub fn mk_u8(cx: @ExtCtxt, sp: span, u: u8) -> @ast::expr { - let lit = ast::lit_uint(u as u64, ast::ty_u8); - return mk_lit(cx, sp, lit); -} -pub fn mk_binary(cx: @ExtCtxt, sp: span, op: ast::binop, - lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { - cx.next_id(); // see ast_util::op_expr_callee_id - mk_expr(cx, sp, ast::expr_binary(op, lhs, rhs)) -} - -pub fn mk_deref(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - mk_unary(cx, sp, ast::deref, e) -} -pub fn mk_unary(cx: @ExtCtxt, sp: span, op: ast::unop, e: @ast::expr) - -> @ast::expr { - cx.next_id(); // see ast_util::op_expr_callee_id - mk_expr(cx, sp, ast::expr_unary(op, e)) -} -pub fn mk_raw_path(sp: span, idents: ~[ast::ident]) -> @ast::Path { - mk_raw_path_(sp, idents, None, ~[]) -} -pub fn mk_raw_path_(sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) - -> @ast::Path { - @ast::Path { span: sp, - global: false, - idents: idents, - rp: rp, - types: types } -} -pub fn mk_raw_path_global(sp: span, idents: ~[ast::ident]) -> @ast::Path { - mk_raw_path_global_(sp, idents, None, ~[]) -} -pub fn mk_raw_path_global_(sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) -> @ast::Path { - @ast::Path { span: sp, - global: true, - idents: idents, - rp: rp, - types: types } -} -pub fn mk_path_raw(cx: @ExtCtxt, sp: span, path: @ast::Path)-> @ast::expr { - mk_expr(cx, sp, ast::expr_path(path)) -} -pub fn mk_path(cx: @ExtCtxt, sp: span, idents: ~[ast::ident]) - -> @ast::expr { - mk_path_raw(cx, sp, mk_raw_path(sp, idents)) -} -pub fn mk_path_global(cx: @ExtCtxt, sp: span, idents: ~[ast::ident]) - -> @ast::expr { - mk_path_raw(cx, sp, mk_raw_path_global(sp, idents)) -} -pub fn mk_access_(cx: @ExtCtxt, sp: span, p: @ast::expr, m: ast::ident) - -> @ast::expr { - mk_expr(cx, sp, ast::expr_field(p, m, ~[])) -} -pub fn mk_access(cx: @ExtCtxt, sp: span, p: ~[ast::ident], m: ast::ident) - -> @ast::expr { - let pathexpr = mk_path(cx, sp, p); - return mk_access_(cx, sp, pathexpr, m); -} -pub fn mk_addr_of(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - return mk_expr(cx, sp, ast::expr_addr_of(ast::m_imm, e)); -} -pub fn mk_mut_addr_of(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - return mk_expr(cx, sp, ast::expr_addr_of(ast::m_mutbl, e)); -} -pub fn mk_method_call(cx: @ExtCtxt, - sp: span, - rcvr_expr: @ast::expr, - method_ident: ast::ident, - args: ~[@ast::expr]) -> @ast::expr { - mk_expr(cx, sp, ast::expr_method_call(rcvr_expr, method_ident, ~[], args, ast::NoSugar)) -} -pub fn mk_call_(cx: @ExtCtxt, sp: span, fn_expr: @ast::expr, - args: ~[@ast::expr]) -> @ast::expr { - mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar)) -} -pub fn mk_call(cx: @ExtCtxt, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { - let pathexpr = mk_path(cx, sp, fn_path); - return mk_call_(cx, sp, pathexpr, args); -} -pub fn mk_call_global(cx: @ExtCtxt, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { - let pathexpr = mk_path_global(cx, sp, fn_path); - return mk_call_(cx, sp, pathexpr, args); -} -// e = expr, t = type -pub fn mk_base_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - let vecexpr = ast::expr_vec(exprs, ast::m_imm); - mk_expr(cx, sp, vecexpr) -} -pub fn mk_vstore_e(cx: @ExtCtxt, sp: span, expr: @ast::expr, - vst: ast::expr_vstore) -> - @ast::expr { - mk_expr(cx, sp, ast::expr_vstore(expr, vst)) -} -pub fn mk_uniq_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_uniq) -} -pub fn mk_slice_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), - ast::expr_vstore_slice) -} -pub fn mk_base_str(cx: @ExtCtxt, sp: span, s: ~str) -> @ast::expr { - let lit = ast::lit_str(@s); - return mk_lit(cx, sp, lit); -} -pub fn mk_uniq_str(cx: @ExtCtxt, 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: &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: ~[Field]) -> ~[ast::field] { - fields.map(|f| mk_field(sp, f)) -} -pub fn mk_struct_e(cx: @ExtCtxt, - 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: @ExtCtxt, - sp: span, - ctor_path: ~[ast::ident], - 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: @ExtCtxt, - sp: span, - vis: ast::visibility, - 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, - }; - @ast::view_item { node: ast::view_item_use(~[glob]), - attrs: ~[], - vis: vis, - span: sp } -} -pub fn mk_local(cx: @ExtCtxt, sp: span, mutbl: bool, - ident: ast::ident, ex: @ast::expr) -> @ast::stmt { - - let pat = @ast::pat { - id: cx.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - mk_raw_path(sp, ~[ident]), - None), - span: sp, - }; - let ty = @ast::Ty { id: cx.next_id(), node: ast::ty_infer, span: sp }; - let local = @codemap::spanned { - node: ast::local_ { - is_mutbl: mutbl, - ty: ty, - pat: pat, - init: Some(ex), - id: cx.next_id(), - }, - span: sp, - }; - let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp}; - @codemap::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } -} -pub fn mk_block(cx: @ExtCtxt, span: span, - view_items: ~[@ast::view_item], - stmts: ~[@ast::stmt], - expr: Option<@ast::expr>) -> @ast::expr { - let blk = codemap::spanned { - node: ast::blk_ { - view_items: view_items, - stmts: stmts, - expr: expr, - id: cx.next_id(), - rules: ast::default_blk, - }, - span: span, - }; - mk_expr(cx, span, ast::expr_block(blk)) -} -pub fn mk_block_(cx: @ExtCtxt, - span: span, - stmts: ~[@ast::stmt]) - -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: stmts, - expr: None, - id: cx.next_id(), - rules: ast::default_blk, - }, - span: span, - } -} -pub fn mk_simple_block(cx: @ExtCtxt, - span: span, - expr: @ast::expr) - -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: ~[], - expr: Some(expr), - id: cx.next_id(), - rules: ast::default_blk, - }, - span: span, - } -} -pub fn mk_lambda_(cx: @ExtCtxt, - span: span, - fn_decl: ast::fn_decl, - blk: ast::blk) - -> @ast::expr { - mk_expr(cx, span, ast::expr_fn_block(fn_decl, blk)) -} -pub fn mk_lambda(cx: @ExtCtxt, - span: span, - fn_decl: ast::fn_decl, - expr: @ast::expr) - -> @ast::expr { - let blk = mk_simple_block(cx, span, expr); - mk_lambda_(cx, span, fn_decl, blk) -} -pub fn mk_lambda_stmts(cx: @ExtCtxt, - span: span, - fn_decl: ast::fn_decl, - stmts: ~[@ast::stmt]) - -> @ast::expr { - let blk = mk_block(cx, span, ~[], stmts, None); - mk_lambda(cx, span, fn_decl, blk) -} -pub fn mk_lambda_no_args(cx: @ExtCtxt, - span: span, - expr: @ast::expr) - -> @ast::expr { - let fn_decl = mk_fn_decl(~[], mk_ty_infer(cx, span)); - mk_lambda(cx, span, fn_decl, expr) -} -pub fn mk_copy(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - mk_expr(cx, sp, ast::expr_copy(e)) -} -pub fn mk_managed(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e)) -} -pub fn mk_pat(cx: @ExtCtxt, span: span, pat: ast::pat_) -> @ast::pat { - @ast::pat { id: cx.next_id(), node: pat, span: span } -} -pub fn mk_pat_wild(cx: @ExtCtxt, span: span) -> @ast::pat { - mk_pat(cx, span, ast::pat_wild) -} -pub fn mk_pat_lit(cx: @ExtCtxt, - span: span, - expr: @ast::expr) -> @ast::pat { - mk_pat(cx, span, ast::pat_lit(expr)) -} -pub fn mk_pat_ident(cx: @ExtCtxt, - span: span, - ident: ast::ident) -> @ast::pat { - mk_pat_ident_with_binding_mode(cx, span, ident, ast::bind_by_copy) -} - -pub fn mk_pat_ident_with_binding_mode(cx: @ExtCtxt, - span: span, - ident: ast::ident, - bm: ast::binding_mode) -> @ast::pat { - let path = mk_raw_path(span, ~[ ident ]); - let pat = ast::pat_ident(bm, path, None); - mk_pat(cx, span, pat) -} -pub fn mk_pat_enum(cx: @ExtCtxt, - span: span, - path: @ast::Path, - subpats: ~[@ast::pat]) - -> @ast::pat { - let pat = ast::pat_enum(path, Some(subpats)); - mk_pat(cx, span, pat) -} -pub fn mk_pat_struct(cx: @ExtCtxt, - span: span, - path: @ast::Path, - field_pats: ~[ast::field_pat]) - -> @ast::pat { - let pat = ast::pat_struct(path, field_pats, false); - mk_pat(cx, span, pat) -} -pub fn mk_bool(cx: @ExtCtxt, span: span, value: bool) -> @ast::expr { - let lit_expr = ast::expr_lit(@codemap::spanned { - node: ast::lit_bool(value), - span: span }); - build::mk_expr(cx, span, lit_expr) -} -pub fn mk_stmt(cx: @ExtCtxt, span: span, expr: @ast::expr) -> @ast::stmt { - let stmt_ = ast::stmt_semi(expr, cx.next_id()); - @codemap::spanned { node: stmt_, span: span } -} - -pub fn mk_ty_mt(ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt { - ast::mt { - ty: ty, - mutbl: mutbl - } -} - -pub fn mk_ty(cx: @ExtCtxt, - span: span, - ty: ast::ty_) -> @ast::Ty { - @ast::Ty { - id: cx.next_id(), - span: span, - node: ty - } -} - -pub fn mk_ty_path(cx: @ExtCtxt, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty { - let ty = build::mk_raw_path(span, idents); - mk_ty_path_path(cx, span, ty) -} - -pub fn mk_ty_path_global(cx: @ExtCtxt, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty { - let ty = build::mk_raw_path_global(span, idents); - mk_ty_path_path(cx, span, ty) -} - -pub fn mk_ty_path_path(cx: @ExtCtxt, - span: span, - path: @ast::Path) - -> @ast::Ty { - let ty = ast::ty_path(path, cx.next_id()); - mk_ty(cx, span, ty) -} - -pub fn mk_ty_rptr(cx: @ExtCtxt, - span: span, - ty: @ast::Ty, - lifetime: Option<@ast::Lifetime>, - mutbl: ast::mutability) - -> @ast::Ty { - mk_ty(cx, span, - ast::ty_rptr(lifetime, mk_ty_mt(ty, mutbl))) -} -pub fn mk_ty_uniq(cx: @ExtCtxt, span: span, ty: @ast::Ty) -> @ast::Ty { - mk_ty(cx, span, ast::ty_uniq(mk_ty_mt(ty, ast::m_imm))) -} -pub fn mk_ty_box(cx: @ExtCtxt, span: span, - ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty { - mk_ty(cx, span, ast::ty_box(mk_ty_mt(ty, mutbl))) -} - - - -pub fn mk_ty_infer(cx: @ExtCtxt, span: span) -> @ast::Ty { - mk_ty(cx, span, ast::ty_infer) -} -pub fn mk_trait_ref_global(cx: @ExtCtxt, - span: span, - idents: ~[ ast::ident ]) - -> @ast::trait_ref -{ - mk_trait_ref_(cx, build::mk_raw_path_global(span, idents)) -} -pub fn mk_trait_ref_(cx: @ExtCtxt, path: @ast::Path) -> @ast::trait_ref { - @ast::trait_ref { - path: path, - ref_id: cx.next_id() - } -} -pub fn mk_simple_ty_path(cx: @ExtCtxt, - span: span, - ident: ast::ident) - -> @ast::Ty { - mk_ty_path(cx, span, ~[ ident ]) -} -pub fn mk_arg(cx: @ExtCtxt, - span: span, - ident: ast::ident, - ty: @ast::Ty) - -> ast::arg { - let arg_pat = mk_pat_ident(cx, span, ident); - ast::arg { - is_mutbl: false, - ty: ty, - pat: arg_pat, - id: cx.next_id() - } -} -pub fn mk_fn_decl(inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { - ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val } -} -pub fn mk_trait_ty_param_bound_global(cx: @ExtCtxt, - span: span, - idents: ~[ast::ident]) - -> ast::TyParamBound { - ast::TraitTyParamBound(mk_trait_ref_global(cx, span, idents)) -} -pub fn mk_trait_ty_param_bound_(cx: @ExtCtxt, - path: @ast::Path) -> ast::TyParamBound { - ast::TraitTyParamBound(mk_trait_ref_(cx, path)) -} -pub fn mk_ty_param(cx: @ExtCtxt, - ident: ast::ident, - bounds: @OptVec) - -> ast::TyParam { - ast::TyParam { ident: ident, id: cx.next_id(), bounds: bounds } -} -pub fn mk_lifetime(cx: @ExtCtxt, - span: span, - ident: ast::ident) - -> ast::Lifetime { - ast::Lifetime { id: cx.next_id(), span: span, ident: ident } -} -pub fn mk_arm(cx: @ExtCtxt, - span: span, - pats: ~[@ast::pat], - expr: @ast::expr) - -> ast::arm { - ast::arm { - pats: pats, - guard: None, - body: mk_simple_block(cx, span, expr) - } -} -pub fn mk_unreachable(cx: @ExtCtxt, span: span) -> @ast::expr { - let loc = cx.codemap().lookup_char_pos(span.lo); - mk_call_global( - cx, - span, - ~[ - cx.ident_of("core"), - cx.ident_of("sys"), - cx.ident_of("FailWithCause"), - cx.ident_of("fail_with"), - ], - ~[ - mk_base_str(cx, span, ~"internal error: entered unreachable code"), - mk_base_str(cx, span, copy loc.file.name), - mk_uint(cx, span, loc.line), - ] - ) -} -pub fn mk_unreachable_arm(cx: @ExtCtxt, span: span) -> ast::arm { - mk_arm(cx, span, ~[mk_pat_wild(cx, span)], mk_unreachable(cx, span)) -} - -pub fn make_self(cx: @ExtCtxt, span: span) -> @ast::expr { - build::mk_expr(cx, span, ast::expr_self) -} - -// -// Duplication functions -// -// These functions just duplicate AST nodes. -// - -pub fn duplicate_expr(cx: @ExtCtxt, expr: @ast::expr) -> @ast::expr { - let folder = fold::default_ast_fold(); - let folder = @fold::AstFoldFns { - new_id: |_| cx.next_id(), - ..*folder - }; - let folder = fold::make_fold(folder); - folder.fold_expr(expr) -} - - - // Transitional reexports so qquote can find the paths it is looking for mod syntax { pub use ext; @@ -555,12 +36,12 @@ pub trait AstBuilder { fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; fn path_tps(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) - -> @ast::Path; + -> @ast::Path; fn path_tps_global(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) - -> @ast::Path; + -> @ast::Path; // types fn ty_path(&self, @ast::Path) -> @ast::Ty; @@ -595,15 +76,15 @@ pub trait AstBuilder { fn expr_var(&self, span: span, var: &str) -> @ast::expr; fn expr_self(&self, span: span) -> @ast::expr; fn expr_field(&self, span: span, expr: @ast::expr, ident: ast::ident) - -> @ast::expr; + -> @ast::expr; fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) - -> @ast::expr; + -> @ast::expr; fn expr_method_call(&self, span: span, expr: @ast::expr, ident: ast::ident, args: ~[@ast::expr]) - -> @ast::expr; + -> @ast::expr; fn expr_blk(&self, b: ast::blk) -> @ast::expr; fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field; fn expr_struct(&self, @@ -613,13 +94,13 @@ pub trait AstBuilder { fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr; fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr; fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) - -> @ast::expr; + -> @ast::expr; fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr; fn lambda_stmts_1(&self, span: span, stmts: ~[@ast::stmt], ident: ast::ident) - -> @ast::expr; + -> @ast::expr; // items fn item(&self, name: ident, span: span, node: ast::item_) -> @ast::item; @@ -675,6 +156,226 @@ pub trait AstBuilder { generics: Generics) -> @ast::item; fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item; + + + + fn mk_expr(&self, + sp: codemap::span, + expr: ast::expr_) + -> @ast::expr; + + fn mk_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr; + fn mk_int(&self, sp: span, i: int) -> @ast::expr; + fn mk_uint(&self, sp: span, u: uint) -> @ast::expr; + fn mk_u8(&self, sp: span, u: u8) -> @ast::expr; + fn mk_binary(&self, sp: span, op: ast::binop, + lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr; + + fn mk_deref(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_unary(&self, sp: span, op: ast::unop, e: @ast::expr) + -> @ast::expr; + // XXX: unused self + fn mk_raw_path(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path; + // XXX: unused self + fn mk_raw_path_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) + -> @ast::Path; + // XXX: unused self + fn mk_raw_path_global(&self, sp: span,idents: ~[ast::ident]) -> @ast::Path; + // XXX: unused self + fn mk_raw_path_global_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) -> @ast::Path; + fn mk_path_raw(&self, sp: span, path: @ast::Path)-> @ast::expr; + fn mk_path(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr; + fn mk_path_global(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr; + fn mk_access_(&self, sp: span, p: @ast::expr, m: ast::ident) + -> @ast::expr; + fn mk_access(&self, sp: span, p: ~[ast::ident], m: ast::ident) + -> @ast::expr; + fn mk_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_method_call(&self, + sp: span, + rcvr_expr: @ast::expr, + method_ident: ast::ident, + args: ~[@ast::expr]) -> @ast::expr; + fn mk_call_(&self, sp: span, fn_expr: @ast::expr, + args: ~[@ast::expr]) -> @ast::expr; + fn mk_call(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr; + fn mk_call_global(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr; + // e = expr, t = type + fn mk_base_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr; + fn mk_vstore_e(&self, sp: span, expr: @ast::expr, + vst: ast::expr_vstore) -> + @ast::expr; + fn mk_uniq_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr; + fn mk_slice_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr; + fn mk_base_str(&self, sp: span, s: ~str) -> @ast::expr; + fn mk_uniq_str(&self, sp: span, s: ~str) -> @ast::expr; + // XXX: unused self + fn mk_field(&self, sp: span, f: &Field) -> ast::field; + // XXX: unused self + fn mk_fields(&self, sp: span, fields: ~[Field]) -> ~[ast::field]; + fn mk_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr; + fn mk_global_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr; + fn mk_glob_use(&self, + sp: span, + vis: ast::visibility, + path: ~[ast::ident]) -> @ast::view_item; + fn mk_local(&self, sp: span, mutbl: bool, + ident: ast::ident, ex: @ast::expr) -> @ast::stmt; + fn mk_block(&self, span: span, + view_items: ~[@ast::view_item], + stmts: ~[@ast::stmt], + expr: Option<@ast::expr>) -> @ast::expr; + fn mk_block_(&self, + span: span, + stmts: ~[@ast::stmt]) + -> ast::blk; + fn mk_simple_block(&self, + span: span, + expr: @ast::expr) + -> ast::blk; + fn mk_lambda_(&self, + span: span, + fn_decl: ast::fn_decl, + blk: ast::blk) + -> @ast::expr; + fn mk_lambda(&self, + span: span, + fn_decl: ast::fn_decl, + expr: @ast::expr) + -> @ast::expr; + fn mk_lambda_stmts(&self, + span: span, + fn_decl: ast::fn_decl, + stmts: ~[@ast::stmt]) + -> @ast::expr ; + fn mk_lambda_no_args(&self, + span: span, + expr: @ast::expr) + -> @ast::expr; + fn mk_copy(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_managed(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_pat(&self, span: span, pat: ast::pat_) -> @ast::pat; + fn mk_pat_wild(&self, span: span) -> @ast::pat; + fn mk_pat_lit(&self, + span: span, + expr: @ast::expr) -> @ast::pat; + fn mk_pat_ident(&self, + span: span, + ident: ast::ident) -> @ast::pat; + + fn mk_pat_ident_with_binding_mode(&self, + span: span, + ident: ast::ident, + bm: ast::binding_mode) -> @ast::pat; + fn mk_pat_enum(&self, + span: span, + path: @ast::Path, + subpats: ~[@ast::pat]) + -> @ast::pat; + fn mk_pat_struct(&self, + span: span, + path: @ast::Path, + field_pats: ~[ast::field_pat]) + -> @ast::pat; + fn mk_bool(&self, span: span, value: bool) -> @ast::expr; + fn mk_stmt(&self, span: span, expr: @ast::expr) -> @ast::stmt; + + // XXX: unused self + fn mk_ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt; + + fn mk_ty(&self, + span: span, + ty: ast::ty_) -> @ast::Ty; + + fn mk_ty_path(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty; + + fn mk_ty_path_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty; + + fn mk_ty_path_path(&self, + span: span, + path: @ast::Path) + -> @ast::Ty; + + fn mk_ty_rptr(&self, + span: span, + ty: @ast::Ty, + lifetime: Option<@ast::Lifetime>, + mutbl: ast::mutability) + -> @ast::Ty; + fn mk_ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty; + fn mk_ty_box(&self, span: span, + ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty; + + + + fn mk_ty_infer(&self, span: span) -> @ast::Ty; + fn mk_trait_ref_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::trait_ref; + fn mk_trait_ref_(&self, path: @ast::Path) -> @ast::trait_ref; + fn mk_simple_ty_path(&self, + span: span, + ident: ast::ident) + -> @ast::Ty; + fn mk_arg(&self, + span: span, + ident: ast::ident, + ty: @ast::Ty) + -> ast::arg; + // XXX unused self + fn mk_fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; + fn mk_trait_ty_param_bound_global(&self, + span: span, + idents: ~[ast::ident]) + -> ast::TyParamBound; + fn mk_trait_ty_param_bound_(&self, + path: @ast::Path) -> ast::TyParamBound; + fn mk_ty_param(&self, + ident: ast::ident, + bounds: @OptVec) + -> ast::TyParam; + fn mk_lifetime(&self, + span: span, + ident: ast::ident) + -> ast::Lifetime; + fn mk_arm(&self, + span: span, + pats: ~[@ast::pat], + expr: @ast::expr) + -> ast::arm; + fn mk_unreachable(&self, span: span) -> @ast::expr; + fn mk_unreachable_arm(&self, span: span) -> ast::arm; + + fn make_self(&self, span: span) -> @ast::expr; } impl AstBuilder for @ExtCtxt { @@ -729,8 +430,8 @@ impl AstBuilder for @ExtCtxt { } fn ty_path(&self, path: @ast::Path) -> @ast::Ty { - build::mk_ty(*self, path.span, - ast::ty_path(path, self.next_id())) + self.mk_ty(path.span, + ast::ty_path(path, self.next_id())) } fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { @@ -779,14 +480,14 @@ impl AstBuilder for @ExtCtxt { fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty] { opt_vec::take_vec( ty_params.map(|p| self.ty_path( - mk_raw_path(dummy_sp(), ~[p.ident])))) + self.mk_raw_path(dummy_sp(), ~[p.ident])))) } fn ty_vars_global(&self, ty_params: &OptVec) -> ~[@ast::Ty] { opt_vec::take_vec( ty_params.map(|p| self.ty_path( - mk_raw_path(dummy_sp(), ~[p.ident])))) + self.mk_raw_path(dummy_sp(), ~[p.ident])))) } fn strip_bounds(&self, generics: &Generics) -> Generics { @@ -803,7 +504,7 @@ impl AstBuilder for @ExtCtxt { fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt { @codemap::spanned { node: ast::stmt_semi(expr, self.next_id()), - span: expr.span } + span: expr.span } } fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt { @@ -819,7 +520,7 @@ impl AstBuilder for @ExtCtxt { span, ast::expr_lit( @codemap::spanned { node: ast::lit_str(s), - span: span})), + span: span})), ast::expr_vstore_uniq)) } @@ -828,7 +529,7 @@ impl AstBuilder for @ExtCtxt { span, ast::expr_lit( @codemap::spanned { node: ast::lit_uint(i as u64, ast::ty_u), - span: span})) + span: span})) } fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::blk { @@ -942,7 +643,7 @@ impl AstBuilder for @ExtCtxt { } fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) - -> @ast::expr { + -> @ast::expr { self.lambda1(self.blk_expr(expr), ident) } @@ -954,7 +655,7 @@ impl AstBuilder for @ExtCtxt { span: span, stmts: ~[@ast::stmt], ident: ast::ident) - -> @ast::expr { + -> @ast::expr { self.lambda1(self.blk(span, stmts, None), ident) } @@ -992,20 +693,20 @@ impl AstBuilder for @ExtCtxt { let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ { style: ast::attr_outer, value: @respan(dummy_sp(), - ast::meta_list(@~"allow", ~[ - @respan(dummy_sp(), - ast::meta_word( - @~"non_camel_case_types")) - ])), + ast::meta_list(@~"allow", ~[ + @respan(dummy_sp(), + ast::meta_word( + @~"non_camel_case_types")) + ])), is_sugared_doc: false }); @ast::item { ident: name, - attrs: ~[non_camel_case_attribute], - id: self.next_id(), - node: node, - vis: ast::public, - span: span } + attrs: ~[non_camel_case_attribute], + id: self.next_id(), + node: node, + vis: ast::public, + span: span } } fn item_fn_poly(&self, name: ident, @@ -1027,7 +728,7 @@ impl AstBuilder for @ExtCtxt { inputs: ~[ast::arg], output: @ast::Ty, body: ast::blk - ) -> @ast::item { + ) -> @ast::item { self.item_fn_poly( name, inputs, @@ -1100,7 +801,7 @@ impl AstBuilder for @ExtCtxt { @codemap::spanned { node: ast::view_path_simple( self.ident_of("Owned"), - mk_raw_path( + self.mk_raw_path( codemap::dummy_sp(), ~[ self.ident_of("core"), @@ -1140,4 +841,539 @@ impl AstBuilder for @ExtCtxt { } + + + + + + fn mk_expr(&self, + sp: codemap::span, + expr: ast::expr_) + -> @ast::expr { + @ast::expr { + id: self.next_id(), + callee_id: self.next_id(), + node: expr, + span: sp, + } + } + + fn mk_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr { + let sp_lit = @codemap::spanned { node: lit, span: sp }; + self.mk_expr( sp, ast::expr_lit(sp_lit)) + } + fn mk_int(&self, sp: span, i: int) -> @ast::expr { + let lit = ast::lit_int(i as i64, ast::ty_i); + return self.mk_lit( sp, lit); + } + fn mk_uint(&self, sp: span, u: uint) -> @ast::expr { + let lit = ast::lit_uint(u as u64, ast::ty_u); + return self.mk_lit( sp, lit); + } + fn mk_u8(&self, sp: span, u: u8) -> @ast::expr { + let lit = ast::lit_uint(u as u64, ast::ty_u8); + return self.mk_lit( sp, lit); + } + fn mk_binary(&self, sp: span, op: ast::binop, + lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { + self.next_id(); // see ast_util::op_expr_callee_id + self.mk_expr( sp, ast::expr_binary(op, lhs, rhs)) + } + + fn mk_deref(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.mk_unary( sp, ast::deref, e) + } + fn mk_unary(&self, sp: span, op: ast::unop, e: @ast::expr) + -> @ast::expr { + self.next_id(); // see ast_util::op_expr_callee_id + self.mk_expr( sp, ast::expr_unary(op, e)) + } + // XXX: unused self + fn mk_raw_path(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path { + self.mk_raw_path_(sp, idents, None, ~[]) + } + // XXX: unused self + fn mk_raw_path_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) + -> @ast::Path { + @ast::Path { span: sp, + global: false, + idents: idents, + rp: rp, + types: types } + } + // XXX: unused self + fn mk_raw_path_global(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path { + self.mk_raw_path_global_(sp, idents, None, ~[]) + } + // XXX: unused self + fn mk_raw_path_global_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) -> @ast::Path { + @ast::Path { span: sp, + global: true, + idents: idents, + rp: rp, + types: types } + } + fn mk_path_raw(&self, sp: span, path: @ast::Path)-> @ast::expr { + self.mk_expr( sp, ast::expr_path(path)) + } + fn mk_path(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr { + self.mk_path_raw( sp, self.mk_raw_path(sp, idents)) + } + fn mk_path_global(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr { + self.mk_path_raw( sp, self.mk_raw_path_global(sp, idents)) + } + fn mk_access_(&self, sp: span, p: @ast::expr, m: ast::ident) + -> @ast::expr { + self.mk_expr( sp, ast::expr_field(p, m, ~[])) + } + fn mk_access(&self, sp: span, p: ~[ast::ident], m: ast::ident) + -> @ast::expr { + let pathexpr = self.mk_path( sp, p); + return self.mk_access_( sp, pathexpr, m); + } + fn mk_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { + return self.mk_expr( sp, ast::expr_addr_of(ast::m_imm, e)); + } + fn mk_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { + return self.mk_expr( sp, ast::expr_addr_of(ast::m_mutbl, e)); + } + fn mk_method_call(&self, + sp: span, + rcvr_expr: @ast::expr, + method_ident: ast::ident, + args: ~[@ast::expr]) -> @ast::expr { + self.mk_expr( sp, ast::expr_method_call(rcvr_expr, method_ident, ~[], args, ast::NoSugar)) + } + fn mk_call_(&self, sp: span, fn_expr: @ast::expr, + args: ~[@ast::expr]) -> @ast::expr { + self.mk_expr( sp, ast::expr_call(fn_expr, args, ast::NoSugar)) + } + fn mk_call(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr { + let pathexpr = self.mk_path( sp, fn_path); + return self.mk_call_( sp, pathexpr, args); + } + fn mk_call_global(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr { + let pathexpr = self.mk_path_global( sp, fn_path); + return self.mk_call_( sp, pathexpr, args); + } + // e = expr, t = type + fn mk_base_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr { + let vecexpr = ast::expr_vec(exprs, ast::m_imm); + self.mk_expr( sp, vecexpr) + } + fn mk_vstore_e(&self, sp: span, expr: @ast::expr, + vst: ast::expr_vstore) -> + @ast::expr { + self.mk_expr( sp, ast::expr_vstore(expr, vst)) + } + fn mk_uniq_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr { + self.mk_vstore_e( sp, self.mk_base_vec_e( sp, exprs), ast::expr_vstore_uniq) + } + fn mk_slice_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr { + self.mk_vstore_e( sp, self.mk_base_vec_e( sp, exprs), + ast::expr_vstore_slice) + } + fn mk_base_str(&self, sp: span, s: ~str) -> @ast::expr { + let lit = ast::lit_str(@s); + return self.mk_lit( sp, lit); + } + fn mk_uniq_str(&self, sp: span, s: ~str) -> @ast::expr { + self.mk_vstore_e( sp, self.mk_base_str( sp, s), ast::expr_vstore_uniq) + } + // XXX: unused self + fn mk_field(&self, sp: span, f: &Field) -> ast::field { + codemap::spanned { + node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex }, + span: sp, + } + } + // XXX: unused self + fn mk_fields(&self, sp: span, fields: ~[Field]) -> ~[ast::field] { + fields.map(|f| self.mk_field(sp, f)) + } + fn mk_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr { + self.mk_expr( sp, + ast::expr_struct(self.mk_raw_path(sp, ctor_path), + self.mk_fields(sp, fields), + option::None::<@ast::expr>)) + } + fn mk_global_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr { + self.mk_expr( sp, + ast::expr_struct(self.mk_raw_path_global(sp, ctor_path), + self.mk_fields(sp, fields), + option::None::<@ast::expr>)) + } + fn mk_glob_use(&self, + sp: span, + vis: ast::visibility, + path: ~[ast::ident]) -> @ast::view_item { + let glob = @codemap::spanned { + node: ast::view_path_glob(self.mk_raw_path(sp, path), self.next_id()), + span: sp, + }; + @ast::view_item { node: ast::view_item_use(~[glob]), + attrs: ~[], + vis: vis, + span: sp } + } + fn mk_local(&self, sp: span, mutbl: bool, + ident: ast::ident, ex: @ast::expr) -> @ast::stmt { + + let pat = @ast::pat { + id: self.next_id(), + node: ast::pat_ident( + ast::bind_by_copy, + self.mk_raw_path(sp, ~[ident]), + None), + span: sp, + }; + let ty = @ast::Ty { id: self.next_id(), node: ast::ty_infer, span: sp }; + let local = @codemap::spanned { + node: ast::local_ { + is_mutbl: mutbl, + ty: ty, + pat: pat, + init: Some(ex), + id: self.next_id(), + }, + span: sp, + }; + let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp}; + @codemap::spanned { node: ast::stmt_decl(@decl, self.next_id()), span: sp } + } + fn mk_block(&self, span: span, + view_items: ~[@ast::view_item], + stmts: ~[@ast::stmt], + expr: Option<@ast::expr>) -> @ast::expr { + let blk = codemap::spanned { + node: ast::blk_ { + view_items: view_items, + stmts: stmts, + expr: expr, + id: self.next_id(), + rules: ast::default_blk, + }, + span: span, + }; + self.mk_expr( span, ast::expr_block(blk)) + } + fn mk_block_(&self, + span: span, + stmts: ~[@ast::stmt]) + -> ast::blk { + codemap::spanned { + node: ast::blk_ { + view_items: ~[], + stmts: stmts, + expr: None, + id: self.next_id(), + rules: ast::default_blk, + }, + span: span, + } + } + fn mk_simple_block(&self, + span: span, + expr: @ast::expr) + -> ast::blk { + codemap::spanned { + node: ast::blk_ { + view_items: ~[], + stmts: ~[], + expr: Some(expr), + id: self.next_id(), + rules: ast::default_blk, + }, + span: span, + } + } + fn mk_lambda_(&self, + span: span, + fn_decl: ast::fn_decl, + blk: ast::blk) + -> @ast::expr { + self.mk_expr( span, ast::expr_fn_block(fn_decl, blk)) + } + fn mk_lambda(&self, + span: span, + fn_decl: ast::fn_decl, + expr: @ast::expr) + -> @ast::expr { + let blk = self.mk_simple_block( span, expr); + self.mk_lambda_( span, fn_decl, blk) + } + fn mk_lambda_stmts(&self, + span: span, + fn_decl: ast::fn_decl, + stmts: ~[@ast::stmt]) + -> @ast::expr { + let blk = self.mk_block( span, ~[], stmts, None); + self.mk_lambda( span, fn_decl, blk) + } + fn mk_lambda_no_args(&self, + span: span, + expr: @ast::expr) + -> @ast::expr { + let fn_decl = self.mk_fn_decl(~[], self.mk_ty_infer( span)); + self.mk_lambda( span, fn_decl, expr) + } + fn mk_copy(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.mk_expr( sp, ast::expr_copy(e)) + } + fn mk_managed(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.mk_expr( sp, ast::expr_unary(ast::box(ast::m_imm), e)) + } + fn mk_pat(&self, span: span, pat: ast::pat_) -> @ast::pat { + @ast::pat { id: self.next_id(), node: pat, span: span } + } + fn mk_pat_wild(&self, span: span) -> @ast::pat { + self.mk_pat( span, ast::pat_wild) + } + fn mk_pat_lit(&self, + span: span, + expr: @ast::expr) -> @ast::pat { + self.mk_pat( span, ast::pat_lit(expr)) + } + fn mk_pat_ident(&self, + span: span, + ident: ast::ident) -> @ast::pat { + self.mk_pat_ident_with_binding_mode( span, ident, ast::bind_by_copy) + } + + fn mk_pat_ident_with_binding_mode(&self, + span: span, + ident: ast::ident, + bm: ast::binding_mode) -> @ast::pat { + let path = self.mk_raw_path(span, ~[ ident ]); + let pat = ast::pat_ident(bm, path, None); + self.mk_pat( span, pat) + } + fn mk_pat_enum(&self, + span: span, + path: @ast::Path, + subpats: ~[@ast::pat]) + -> @ast::pat { + let pat = ast::pat_enum(path, Some(subpats)); + self.mk_pat( span, pat) + } + fn mk_pat_struct(&self, + span: span, + path: @ast::Path, + field_pats: ~[ast::field_pat]) + -> @ast::pat { + let pat = ast::pat_struct(path, field_pats, false); + self.mk_pat( span, pat) + } + fn mk_bool(&self, span: span, value: bool) -> @ast::expr { + let lit_expr = ast::expr_lit(@codemap::spanned { + node: ast::lit_bool(value), + span: span }); + self.mk_expr( span, lit_expr) + } + fn mk_stmt(&self, span: span, expr: @ast::expr) -> @ast::stmt { + let stmt_ = ast::stmt_semi(expr, self.next_id()); + @codemap::spanned { node: stmt_, span: span } + } + + // XXX: unused self + fn mk_ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt { + ast::mt { + ty: ty, + mutbl: mutbl + } + } + + fn mk_ty(&self, + span: span, + ty: ast::ty_) -> @ast::Ty { + @ast::Ty { + id: self.next_id(), + span: span, + node: ty + } + } + + fn mk_ty_path(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty { + let ty = self.mk_raw_path(span, idents); + self.mk_ty_path_path( span, ty) + } + + fn mk_ty_path_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty { + let ty = self.mk_raw_path_global(span, idents); + self.mk_ty_path_path( span, ty) + } + + fn mk_ty_path_path(&self, + span: span, + path: @ast::Path) + -> @ast::Ty { + let ty = ast::ty_path(path, self.next_id()); + self.mk_ty( span, ty) + } + + fn mk_ty_rptr(&self, + span: span, + ty: @ast::Ty, + lifetime: Option<@ast::Lifetime>, + mutbl: ast::mutability) + -> @ast::Ty { + self.mk_ty( span, + ast::ty_rptr(lifetime, self.mk_ty_mt(ty, mutbl))) + } + fn mk_ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty { + self.mk_ty( span, ast::ty_uniq(self.mk_ty_mt(ty, ast::m_imm))) + } + fn mk_ty_box(&self, span: span, + ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty { + self.mk_ty( span, ast::ty_box(self.mk_ty_mt(ty, mutbl))) + } + + + + fn mk_ty_infer(&self, span: span) -> @ast::Ty { + self.mk_ty( span, ast::ty_infer) + } + fn mk_trait_ref_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::trait_ref + { + self.mk_trait_ref_( self.mk_raw_path_global(span, idents)) + } + fn mk_trait_ref_(&self, path: @ast::Path) -> @ast::trait_ref { + @ast::trait_ref { + path: path, + ref_id: self.next_id() + } + } + fn mk_simple_ty_path(&self, + span: span, + ident: ast::ident) + -> @ast::Ty { + self.mk_ty_path( span, ~[ ident ]) + } + fn mk_arg(&self, + span: span, + ident: ast::ident, + ty: @ast::Ty) + -> ast::arg { + let arg_pat = self.mk_pat_ident( span, ident); + ast::arg { + is_mutbl: false, + ty: ty, + pat: arg_pat, + id: self.next_id() + } + } + // XXX unused self + fn mk_fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { + ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val } + } + fn mk_trait_ty_param_bound_global(&self, + span: span, + idents: ~[ast::ident]) + -> ast::TyParamBound { + ast::TraitTyParamBound(self.mk_trait_ref_global( span, idents)) + } + fn mk_trait_ty_param_bound_(&self, + path: @ast::Path) -> ast::TyParamBound { + ast::TraitTyParamBound(self.mk_trait_ref_( path)) + } + fn mk_ty_param(&self, + ident: ast::ident, + bounds: @OptVec) + -> ast::TyParam { + ast::TyParam { ident: ident, id: self.next_id(), bounds: bounds } + } + fn mk_lifetime(&self, + span: span, + ident: ast::ident) + -> ast::Lifetime { + ast::Lifetime { id: self.next_id(), span: span, ident: ident } + } + fn mk_arm(&self, + span: span, + pats: ~[@ast::pat], + expr: @ast::expr) + -> ast::arm { + ast::arm { + pats: pats, + guard: None, + body: self.mk_simple_block( span, expr) + } + } + fn mk_unreachable(&self, span: span) -> @ast::expr { + let loc = self.codemap().lookup_char_pos(span.lo); + self.mk_call_global( + span, + ~[ + self.ident_of("core"), + self.ident_of("sys"), + self.ident_of("FailWithCause"), + self.ident_of("fail_with"), + ], + ~[ + self.mk_base_str( span, ~"internal error: entered unreachable code"), + self.mk_base_str( span, copy loc.file.name), + self.mk_uint( span, loc.line), + ] + ) + } + fn mk_unreachable_arm(&self, span: span) -> ast::arm { + self.mk_arm( span, ~[self.mk_pat_wild( span)], self.mk_unreachable( span)) + } + + fn make_self(&self, span: span) -> @ast::expr { + self.mk_expr( span, ast::expr_self) + } +} + + +pub trait Duplicate { + // + // Duplication functions + // + // These functions just duplicate AST nodes. + // + + fn duplicate(&self, cx: @ExtCtxt) -> Self; +} + +impl Duplicate for @ast::expr { + fn duplicate(&self, cx: @ExtCtxt) -> @ast::expr { + let folder = fold::default_ast_fold(); + let folder = @fold::AstFoldFns { + new_id: |_| cx.next_id(), + ..*folder + }; + let folder = fold::make_fold(folder); + folder.fold_expr(*self) + } } diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index da13c9bfa28e1..cdc6e267cccba 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -14,7 +14,7 @@ use ast; use codemap::span; use ext::base::*; use ext::base; -use ext::build::{mk_u8, mk_slice_vec_e}; +use ext::build::AstBuilder; pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { // Gather all argument expressions @@ -28,7 +28,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas // string literal, push each byte to vector expression ast::lit_str(s) => { for s.each |byte| { - bytes.push(mk_u8(cx, sp, byte)); + bytes.push(cx.mk_u8(sp, byte)); } } @@ -37,7 +37,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas if v > 0xFF { cx.span_err(sp, "Too large u8 literal in bytes!") } else { - bytes.push(mk_u8(cx, sp, v as u8)); + bytes.push(cx.mk_u8(sp, v as u8)); } } @@ -48,14 +48,14 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas } else if v < 0 { cx.span_err(sp, "Negative integer literal in bytes!") } else { - bytes.push(mk_u8(cx, sp, v as u8)); + bytes.push(cx.mk_u8(sp, v as u8)); } } // char literal, push to vector expression ast::lit_int(v, ast::ty_char) => { if (v as char).is_ascii() { - bytes.push(mk_u8(cx, sp, v as u8)); + bytes.push(cx.mk_u8(sp, v as u8)); } else { cx.span_err(sp, "Non-ascii char literal in bytes!") } @@ -68,6 +68,6 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas } } - let e = mk_slice_vec_e(cx, sp, bytes); + let e = cx.mk_slice_vec_e(sp, bytes); MRExpr(e) } diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index c08b478e8ed6f..07aead9588ac1 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -12,6 +12,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; @@ -79,7 +80,7 @@ fn cs_clone( let ctor_ident; let all_fields; let subcall = |field| - build::mk_method_call(cx, span, field, clone_ident, ~[]); + cx.mk_method_call(span, field, clone_ident, ~[]); match *substr.fields { Struct(ref af) => { @@ -102,7 +103,7 @@ fn cs_clone( [(None, _, _), .. _] => { // enum-like let subcalls = all_fields.map(|&(_, self_f, _)| subcall(self_f)); - build::mk_call(cx, span, ctor_ident, subcalls) + cx.mk_call(span, ctor_ident, subcalls) }, _ => { // struct-like @@ -118,9 +119,9 @@ fn cs_clone( if fields.is_empty() { // no fields, so construct like `None` - build::mk_path(cx, span, ctor_ident) + cx.mk_path(span, ctor_ident) } else { - build::mk_struct_e(cx, span, + cx.mk_struct_e(span, ctor_ident, fields) } diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 197366b09ae3c..1af6640448977 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_eq(cx: @ExtCtxt, @@ -21,11 +21,11 @@ pub fn expand_deriving_eq(cx: @ExtCtxt, // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different fn cs_eq(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_and(|cx, span, _, _| build::mk_bool(cx, span, false), + cs_and(|cx, span, _, _| cx.mk_bool(span, false), cx, span, substr) } fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_or(|cx, span, _, _| build::mk_bool(cx, span, true), + cs_or(|cx, span, _, _| cx.mk_bool(span, true), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 29fc2c7271c0b..41b5bf63aca34 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -12,7 +12,7 @@ use ast::{meta_item, item, expr_if, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_ord(cx: @ExtCtxt, @@ -62,10 +62,10 @@ fn cs_ord(less: bool, equal: bool, } else { cx.ident_of("gt") }; - let false_blk_expr = build::mk_block(cx, span, + let false_blk_expr = cx.mk_block(span, ~[], ~[], - Some(build::mk_bool(cx, span, false))); - let base = build::mk_bool(cx, span, equal); + Some(cx.mk_bool(span, false))); + let base = cx.mk_bool(span, equal); cs_fold( false, // need foldr, @@ -98,19 +98,19 @@ fn cs_ord(less: bool, equal: bool, cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`"); } - let cmp = build::mk_method_call(cx, span, + let cmp = cx.mk_method_call(span, self_f, cx.ident_of("eq"), other_fs.to_owned()); - let subexpr = build::mk_simple_block(cx, span, subexpr); + let subexpr = cx.mk_simple_block(span, subexpr); let elseif = expr_if(cmp, subexpr, Some(false_blk_expr)); - let elseif = build::mk_expr(cx, span, elseif); + let elseif = cx.mk_expr(span, elseif); - let cmp = build::mk_method_call(cx, span, + let cmp = cx.mk_method_call(span, self_f, binop, other_fs.to_owned()); - let true_blk = build::mk_simple_block(cx, span, - build::mk_bool(cx, span, true)); + let true_blk = cx.mk_simple_block(span, + cx.mk_bool(span, true)); let if_ = expr_if(cmp, true_blk, Some(elseif)); - build::mk_expr(cx, span, if_) + cx.mk_expr(span, if_) }, base, |cx, span, args, _| { @@ -119,7 +119,7 @@ fn cs_ord(less: bool, equal: bool, match args { [(self_var, _, _), (other_var, _, _)] => - build::mk_bool(cx, span, + cx.mk_bool(span, if less { self_var < other_var } else { diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 0ab99430d1078..48393efce6487 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -12,7 +12,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_totaleq(cx: @ExtCtxt, @@ -21,7 +21,7 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt, in_items: ~[@item]) -> ~[@item] { fn cs_equals(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_and(|cx, span, _, _| build::mk_bool(cx, span, false), + cs_and(|cx, span, _, _| cx.mk_bool(span, false), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 2b4d8a28fbd93..3404a21edd0de 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; use core::cmp::{Ordering, Equal, Less, Greater}; @@ -47,7 +47,7 @@ pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr { Equal => "Equal", Greater => "Greater" }; - build::mk_path_global(cx, span, + cx.mk_path_global(span, ~[cx.ident_of("core"), cx.ident_of("cmp"), cx.ident_of(cnst)]) @@ -60,7 +60,7 @@ pub fn cs_cmp(cx: @ExtCtxt, span: span, // foldr (possibly) nests the matches in lexical_ordering better false, |cx, span, old, new| { - build::mk_call_global(cx, span, + cx.mk_call_global(span, ~[cx.ident_of("core"), cx.ident_of("cmp"), cx.ident_of("lexical_ordering")], diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 24f9b6acf8534..781ac9814ec9b 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -16,7 +16,8 @@ encodable.rs for more. use ast; use ast::*; use ext::base::ExtCtxt; -use ext::build; +use ext::build::Field; +use ext::build::AstBuilder; use ext::deriving::*; use codemap::{span, spanned}; use ast_util; @@ -44,12 +45,10 @@ fn create_derived_decodable_impl( generics: &Generics, method: @method ) -> @item { - let decoder_ty_param = build::mk_ty_param( - cx, + let decoder_ty_param = cx.mk_ty_param( cx.ident_of("__D"), @opt_vec::with( - build::mk_trait_ty_param_bound_global( - cx, + cx.mk_trait_ty_param_bound_global( span, ~[ cx.ident_of("std"), @@ -64,7 +63,7 @@ fn create_derived_decodable_impl( let generic_ty_params = opt_vec::with(decoder_ty_param); let methods = [method]; - let trait_path = build::mk_raw_path_global_( + let trait_path = cx.mk_raw_path_global_( span, ~[ cx.ident_of("std"), @@ -73,7 +72,7 @@ fn create_derived_decodable_impl( ], None, ~[ - build::mk_simple_ty_path(cx, span, cx.ident_of("__D")) + cx.mk_simple_ty_path(span, cx.ident_of("__D")) ] ); create_derived_impl( @@ -98,15 +97,14 @@ fn create_decode_method( expr: @ast::expr ) -> @method { // Create the `e` parameter. - let d_arg_type = build::mk_ty_rptr( - cx, + let d_arg_type = cx.mk_ty_rptr( span, - build::mk_simple_ty_path(cx, span, cx.ident_of("__D")), + cx.mk_simple_ty_path(span, cx.ident_of("__D")), None, ast::m_mutbl ); let d_ident = cx.ident_of("__d"); - let d_arg = build::mk_arg(cx, span, d_ident, d_arg_type); + let d_arg = cx.mk_arg(span, d_ident, d_arg_type); // Create the type of the return value. let output_type = create_self_type_with_params( @@ -118,10 +116,10 @@ fn create_decode_method( // Create the function declaration. let inputs = ~[d_arg]; - let fn_decl = build::mk_fn_decl(inputs, output_type); + let fn_decl = cx.mk_fn_decl(inputs, output_type); // Create the body block. - let body_block = build::mk_simple_block(cx, span, expr); + let body_block = cx.mk_simple_block(span, expr); // Create the method. let explicit_self = spanned { node: sty_static, span: span }; @@ -146,11 +144,9 @@ fn call_substructure_decode_method( span: span ) -> @ast::expr { // Call the substructure method. - build::mk_call_( - cx, + cx.mk_call_( span, - build::mk_path_global( - cx, + cx.mk_path_global( span, ~[ cx.ident_of("std"), @@ -160,7 +156,7 @@ fn call_substructure_decode_method( ] ), ~[ - build::mk_path(cx, span, ~[cx.ident_of("__d")]) + cx.mk_path(span, ~[cx.ident_of("__d")]) ] ) } @@ -222,32 +218,31 @@ fn create_read_struct_field( span: span, idx: uint, ident: ident -) -> build::Field { +) -> Field { // Call the substructure method. let decode_expr = call_substructure_decode_method(cx, span); - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_struct_field"), ~[ - build::mk_base_str(cx, span, cx.str_of(ident)), - build::mk_uint(cx, span, idx), - build::mk_lambda(cx, + cx.mk_base_str(span, cx.str_of(ident)), + cx.mk_uint(span, idx), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], - build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[d_arg], + cx.mk_ty_infer(span)), decode_expr), ] ); - build::Field { ident: ident, ex: call_expr } + Field { ident: ident, ex: call_expr } } fn create_read_struct_arg( @@ -255,22 +250,21 @@ fn create_read_struct_arg( span: span, idx: uint, ident: ident -) -> build::Field { +) -> Field { // Call the substructure method. let decode_expr = call_substructure_decode_method(cx, span); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_struct_arg"), ~[ - build::mk_uint(cx, span, idx), - build::mk_lambda_no_args(cx, span, decode_expr), + cx.mk_uint(span, idx), + cx.mk_lambda_no_args(span, decode_expr), ] ); - build::Field { ident: ident, ex: call_expr } + Field { ident: ident, ex: call_expr } } fn expand_deriving_decodable_struct_method( @@ -298,29 +292,25 @@ fn expand_deriving_decodable_struct_method( i += 1; } - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let read_struct_expr = build::mk_method_call( - cx, + let read_struct_expr = cx.mk_method_call( span, - build::mk_path( - cx, + cx.mk_path( span, ~[cx.ident_of("__d")] ), cx.ident_of("read_struct"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), - build::mk_uint(cx, span, fields.len()), - build::mk_lambda( - cx, + cx.mk_base_str(span, cx.str_of(type_ident)), + cx.mk_uint(span, fields.len()), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], build::mk_ty_infer(cx, span)), - build::mk_struct_e( - cx, + cx.mk_fn_decl(~[d_arg], cx.mk_ty_infer(span)), + cx.mk_struct_e( span, ~[type_ident], fields @@ -340,14 +330,14 @@ fn create_read_variant_arg( variant: &ast::variant ) -> ast::arm { // Create the matching pattern. - let pat = build::mk_pat_lit(cx, span, build::mk_uint(cx, span, idx)); + let pat = cx.mk_pat_lit(span, cx.mk_uint(span, idx)); // Feed each argument in this variant to the decode function // as well. let variant_arg_len = variant_arg_count(cx, span, variant); let expr = if variant_arg_len == 0 { - build::mk_path(cx, span, ~[variant.node.name]) + cx.mk_path(span, ~[variant.node.name]) } else { // Feed the discriminant to the decode function. let mut args = ~[]; @@ -356,22 +346,21 @@ fn create_read_variant_arg( // Call the substructure method. let expr = call_substructure_decode_method(cx, span); - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); - let t_infer = build::mk_ty_infer(cx, span); + cx.mk_ty_infer(span)); + let t_infer = cx.mk_ty_infer(span); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_enum_variant_arg"), ~[ - build::mk_uint(cx, span, j), - build::mk_lambda(cx, + cx.mk_uint(span, j), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], t_infer), + cx.mk_fn_decl(~[d_arg], t_infer), expr), ] ); @@ -379,8 +368,7 @@ fn create_read_variant_arg( args.push(call_expr); } - build::mk_call( - cx, + cx.mk_call( span, ~[variant.node.name], args @@ -388,7 +376,7 @@ fn create_read_variant_arg( }; // Create the arm. - build::mk_arm(cx, span, ~[pat], expr) + cx.mk_arm(span, ~[pat], expr) } fn create_read_enum_variant( @@ -397,12 +385,10 @@ fn create_read_enum_variant( enum_definition: &enum_def ) -> @expr { // Create a vector that contains all the variant names. - let expr_arm_names = build::mk_base_vec_e( - cx, + let expr_arm_names = cx.mk_base_vec_e( span, do enum_definition.variants.map |variant| { - build::mk_base_str( - cx, + cx.mk_base_str( span, cx.str_of(variant.node.name) ) @@ -415,41 +401,36 @@ fn create_read_enum_variant( }; // Add the impossible case arm. - arms.push(build::mk_unreachable_arm(cx, span)); + arms.push(cx.mk_unreachable_arm(span)); // Create the read_enum_variant expression. - build::mk_method_call( - cx, + cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_enum_variant"), ~[ expr_arm_names, - build::mk_lambda( - cx, + cx.mk_lambda( span, - build::mk_fn_decl( + cx.mk_fn_decl( ~[ - build::mk_arg( - cx, + cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span) + cx.mk_ty_infer(span) ), - build::mk_arg( - cx, + cx.mk_arg( span, cx.ident_of("__i"), - build::mk_ty_infer(cx, span) + cx.mk_ty_infer(span) ) ], - build::mk_ty_infer(cx, span) + cx.mk_ty_infer(span) ), - build::mk_expr( - cx, + cx.mk_expr( span, ast::expr_match( - build::mk_path(cx, span, ~[cx.ident_of("__i")]), + cx.mk_path(span, ~[cx.ident_of("__i")]), arms ) ) @@ -471,23 +452,22 @@ fn expand_deriving_decodable_enum_method( enum_definition ); - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); // Create the read_enum expression - let read_enum_expr = build::mk_method_call( - cx, + let read_enum_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_enum"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), - build::mk_lambda(cx, + cx.mk_base_str(span, cx.str_of(type_ident)), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], - build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[d_arg], + cx.mk_ty_infer(span)), read_enum_variant_expr), ] ); diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 128bbf39b16c6..eda1909aed4cb 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -79,7 +79,7 @@ would yield functions like: use ast; use ast::*; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::*; use codemap::{span, spanned}; use ast_util; @@ -107,12 +107,10 @@ fn create_derived_encodable_impl( generics: &Generics, method: @method ) -> @item { - let encoder_ty_param = build::mk_ty_param( - cx, + let encoder_ty_param = cx.mk_ty_param( cx.ident_of("__E"), @opt_vec::with( - build::mk_trait_ty_param_bound_global( - cx, + cx.mk_trait_ty_param_bound_global( span, ~[ cx.ident_of("std"), @@ -127,7 +125,7 @@ fn create_derived_encodable_impl( let generic_ty_params = opt_vec::with(encoder_ty_param); let methods = [method]; - let trait_path = build::mk_raw_path_global_( + let trait_path = cx.mk_raw_path_global_( span, ~[ cx.ident_of("std"), @@ -136,7 +134,7 @@ fn create_derived_encodable_impl( ], None, ~[ - build::mk_simple_ty_path(cx, span, cx.ident_of("__E")) + cx.mk_simple_ty_path(span, cx.ident_of("__E")) ] ); create_derived_impl( @@ -159,24 +157,23 @@ fn create_encode_method( statements: ~[@stmt] ) -> @method { // Create the `e` parameter. - let e_arg_type = build::mk_ty_rptr( - cx, + let e_arg_type = cx.mk_ty_rptr( span, - build::mk_simple_ty_path(cx, span, cx.ident_of("__E")), + cx.mk_simple_ty_path(span, cx.ident_of("__E")), None, ast::m_mutbl ); - let e_arg = build::mk_arg(cx, span, cx.ident_of("__e"), e_arg_type); + let e_arg = cx.mk_arg(span, cx.ident_of("__e"), e_arg_type); // Create the type of the return value. let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span }; // Create the function declaration. let inputs = ~[e_arg]; - let fn_decl = build::mk_fn_decl(inputs, output_type); + let fn_decl = cx.mk_fn_decl(inputs, output_type); // Create the body block. - let body_block = build::mk_block_(cx, span, statements); + let body_block = cx.mk_block_(span, statements); // Create the method. let explicit_self = spanned { node: sty_region(None, m_imm), span: span }; @@ -203,12 +200,11 @@ fn call_substructure_encode_method( ) -> @ast::expr { // Gather up the parameters we want to chain along. let e_ident = cx.ident_of("__e"); - let e_expr = build::mk_path(cx, span, ~[e_ident]); + let e_expr = cx.mk_path(span, ~[e_ident]); // Call the substructure method. let encode_ident = cx.ident_of("encode"); - build::mk_method_call( - cx, + cx.mk_method_call( span, self_field, encode_ident, @@ -279,9 +275,9 @@ fn expand_deriving_encodable_struct_method( match struct_field.node.kind { named_field(ident, _) => { // Create the accessor for this field. - let self_field = build::mk_access_(cx, + let self_field = cx.mk_access_( span, - build::make_self(cx, span), + cx.make_self(span), ident); // Call the substructure method. @@ -292,31 +288,29 @@ fn expand_deriving_encodable_struct_method( ); let e_ident = cx.ident_of("__e"); - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, e_ident, - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let blk_expr = build::mk_lambda( - cx, + let blk_expr = cx.mk_lambda( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), encode_expr ); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_struct_field"), ~[ - build::mk_base_str(cx, span, cx.str_of(ident)), - build::mk_uint(cx, span, idx), + cx.mk_base_str(span, cx.str_of(ident)), + cx.mk_uint(span, idx), blk_expr ] ); - statements.push(build::mk_stmt(cx, span, call_expr)); + statements.push(cx.mk_stmt(span, call_expr)); } unnamed_field => { cx.span_unimpl( @@ -328,33 +322,30 @@ fn expand_deriving_encodable_struct_method( idx += 1; } - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, cx.ident_of("__e"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let emit_struct_stmt = build::mk_method_call( - cx, + let emit_struct_stmt = cx.mk_method_call( span, - build::mk_path( - cx, + cx.mk_path( span, ~[cx.ident_of("__e")] ), cx.ident_of("emit_struct"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), - build::mk_uint(cx, span, statements.len()), - build::mk_lambda_stmts( - cx, + cx.mk_base_str(span, cx.str_of(type_ident)), + cx.mk_uint(span, statements.len()), + cx.mk_lambda_stmts( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), statements ), ] ); - let statements = ~[build::mk_stmt(cx, span, emit_struct_stmt)]; + let statements = ~[cx.mk_stmt(span, emit_struct_stmt)]; // Create the method itself. return create_encode_method(cx, span, statements); @@ -382,56 +373,52 @@ fn expand_deriving_encodable_enum_method( let expr = call_substructure_encode_method(cx, span, field); let e_ident = cx.ident_of("__e"); - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, e_ident, - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let blk_expr = build::mk_lambda( - cx, + let blk_expr = cx.mk_lambda( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), expr ); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_enum_variant_arg"), ~[ - build::mk_uint(cx, span, j), + cx.mk_uint(span, j), blk_expr, ] ); - stmts.push(build::mk_stmt(cx, span, call_expr)); + stmts.push(cx.mk_stmt(span, call_expr)); } // Create the pattern body. - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, cx.ident_of("__e"), - build::mk_ty_infer(cx, span)); - let call_expr = build::mk_method_call( - cx, + cx.mk_ty_infer(span)); + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_enum_variant"), ~[ - build::mk_base_str(cx, span, cx.str_of(variant.node.name)), - build::mk_uint(cx, span, i), - build::mk_uint(cx, span, variant_arg_len), - build::mk_lambda_stmts( - cx, + cx.mk_base_str(span, cx.str_of(variant.node.name)), + cx.mk_uint(span, i), + cx.mk_uint(span, variant_arg_len), + cx.mk_lambda_stmts( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), stmts ) ] ); - let match_body_block = build::mk_simple_block(cx, span, call_expr); + let match_body_block = cx.mk_simple_block(span, call_expr); // Create the arm. ast::arm { @@ -442,31 +429,29 @@ fn expand_deriving_encodable_enum_method( }; let e_ident = cx.ident_of("__e"); - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, e_ident, - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); // Create the method body. - let lambda_expr = build::mk_lambda( - cx, + let lambda_expr = cx.mk_lambda( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), expand_enum_or_struct_match(cx, span, arms) ); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_enum"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), + cx.mk_base_str(span, cx.str_of(type_ident)), lambda_expr, ] ); - let stmt = build::mk_stmt(cx, span, call_expr); + let stmt = cx.mk_stmt(span, call_expr); // Create the method. create_encode_method(cx, span, ~[stmt]) diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 0bb97ec31224c..4859fec2e4452 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -166,7 +166,7 @@ use ast; use ast::{enum_def, expr, ident, Generics, struct_def}; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::*; use codemap::{span,respan}; use opt_vec; @@ -431,7 +431,7 @@ impl<'self> MethodDef<'self> { let ident = cx.ident_of(fmt!("__arg_%u", i)); arg_tys.push((ident, ast_ty)); - let arg_expr = build::mk_path(cx, span, ~[ident]); + let arg_expr = cx.mk_path(span, ~[ident]); match *ty { // for static methods, just treat any Self @@ -440,7 +440,7 @@ impl<'self> MethodDef<'self> { self_args.push(arg_expr); } Ptr(~Self, _) if nonstatic => { - self_args.push(build::mk_deref(cx, span, arg_expr)) + self_args.push(cx.mk_deref(span, arg_expr)) } _ => { nonself_args.push(arg_expr); @@ -461,14 +461,14 @@ impl<'self> MethodDef<'self> { let fn_generics = self.generics.to_generics(cx, span, type_ident, generics); let args = do arg_types.map |&(id, ty)| { - build::mk_arg(cx, span, id, ty) + cx.mk_arg(span, id, ty) }; let ret_type = self.get_ret_ty(cx, span, generics, type_ident); let method_ident = cx.ident_of(self.name); - let fn_decl = build::mk_fn_decl(args, ret_type); - let body_block = build::mk_simple_block(cx, span, body); + let fn_decl = cx.mk_fn_decl(args, ret_type); + let body_block = cx.mk_simple_block(span, body); // Create the method. @@ -558,10 +558,10 @@ impl<'self> MethodDef<'self> { let match_arm = ast::arm { pats: ~[ pat ], guard: None, - body: build::mk_simple_block(cx, span, body) + body: cx.mk_simple_block(span, body) }; - body = build::mk_expr(cx, span, ast::expr_match(arg_expr, ~[match_arm])) + body = cx.mk_expr(span, ast::expr_match(arg_expr, ~[match_arm])) } body } @@ -738,15 +738,15 @@ impl<'self> MethodDef<'self> { matches_so_far, match_count + 1); matches_so_far.pop(); - arms.push(build::mk_arm(cx, span, ~[ pattern ], arm_expr)); + arms.push(cx.mk_arm(span, ~[ pattern ], arm_expr)); if enum_def.variants.len() > 1 { let e = &EnumNonMatching(&[]); let wild_expr = self.call_substructure_method(cx, span, type_ident, self_args, nonself_args, e); - let wild_arm = build::mk_arm(cx, span, - ~[ build::mk_pat_wild(cx, span) ], + let wild_arm = cx.mk_arm(span, + ~[ cx.mk_pat_wild(span) ], wild_expr); arms.push(wild_arm); } @@ -774,13 +774,13 @@ impl<'self> MethodDef<'self> { match_count + 1); matches_so_far.pop(); - let arm = build::mk_arm(cx, span, ~[ pattern ], arm_expr); + let arm = cx.mk_arm(span, ~[ pattern ], arm_expr); arms.push(arm); } } // match foo { arm, arm, arm, ... } - build::mk_expr(cx, span, + cx.mk_expr(span, ast::expr_match(self_args[match_count], arms)) } } @@ -887,7 +887,7 @@ pub fn cs_same_method(f: &fn(@ExtCtxt, span, ~[@expr]) -> @expr, EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { // call self_n.method(other_1_n, other_2_n, ...) let called = do all_fields.map |&(_, self_field, other_fields)| { - build::mk_method_call(cx, span, + cx.mk_method_call(span, self_field, substructure.method_ident, other_fields) @@ -945,7 +945,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr, cs_same_method_fold( true, // foldl is good enough |cx, span, old, new| { - build::mk_binary(cx, span, + cx.mk_binary(span, binop, old, new) @@ -960,7 +960,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr, pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { - cs_binop(ast::or, build::mk_bool(cx, span, false), + cs_binop(ast::or, cx.mk_bool(span, false), enum_nonmatch_f, cx, span, substructure) } @@ -969,7 +969,7 @@ pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc, cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { - cs_binop(ast::and, build::mk_bool(cx, span, true), + cs_binop(ast::and, cx.mk_bool(span, true), enum_nonmatch_f, cx, span, substructure) } diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index c655eef34d1eb..cc89bae37b76f 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr, and}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_iter_bytes(cx: @ExtCtxt, @@ -48,7 +48,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ }; let iter_bytes_ident = substr.method_ident; let call_iterbytes = |thing_expr| { - build::mk_method_call(cx, span, + cx.mk_method_call(span, thing_expr, iter_bytes_ident, copy lsb0_f) }; @@ -63,7 +63,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ // iteration function. let discriminant = match variant.node.disr_expr { Some(copy d)=> d, - None => build::mk_uint(cx, span, index) + None => cx.mk_uint(span, index) }; exprs.push(call_iterbytes(discriminant)); @@ -82,6 +82,6 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ } do vec::foldl(exprs[0], exprs.slice(1, exprs.len())) |prev, me| { - build::mk_binary(cx, span, and, prev, *me) + cx.mk_binary(span, and, prev, *me) } } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 4a6c78038389e..a7f70236251ba 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -21,7 +21,7 @@ library. use ast; use ast::{Ty, enum_def, expr, ident, item, Generics, meta_item, struct_def}; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use codemap::{span, respan}; use parse::token::special_idents::clownshoes_extensions; use opt_vec; @@ -172,7 +172,7 @@ pub fn create_self_type_with_params(cx: @ExtCtxt, // Create the type parameters on the `self` path. let mut self_ty_params = ~[]; for generics.ty_params.each |ty_param| { - let self_ty_param = build::mk_simple_ty_path(cx, + let self_ty_param = cx.mk_simple_ty_path( span, ty_param.ident); self_ty_params.push(self_ty_param); @@ -186,11 +186,11 @@ pub fn create_self_type_with_params(cx: @ExtCtxt, // Create the type of `self`. - let self_type = build::mk_raw_path_(span, - ~[ type_ident ], + let self_type = cx.mk_raw_path_(span, + ~[ type_ident ], lifetime, self_ty_params); - build::mk_ty_path_path(cx, span, self_type) + cx.mk_ty_path_path(span, self_type) } pub fn create_derived_impl(cx: @ExtCtxt, @@ -222,18 +222,18 @@ pub fn create_derived_impl(cx: @ExtCtxt, for generics.ty_params.each |ty_param| { // extra restrictions on the generics parameters to the type being derived upon let mut bounds = do bounds_paths.map |&bound_path| { - build::mk_trait_ty_param_bound_(cx, bound_path) + cx.mk_trait_ty_param_bound_(bound_path) }; let this_trait_bound = - build::mk_trait_ty_param_bound_(cx, trait_path); + cx.mk_trait_ty_param_bound_(trait_path); bounds.push(this_trait_bound); - impl_generics.ty_params.push(build::mk_ty_param(cx, ty_param.ident, @bounds)); + impl_generics.ty_params.push(cx.mk_ty_param(ty_param.ident, @bounds)); } // Create the reference to the trait. - let trait_ref = build::mk_trait_ref_(cx, trait_path); + let trait_ref = cx.mk_trait_ref_(trait_path); // Create the type of `self`. let self_type = create_self_type_with_params(cx, @@ -255,7 +255,7 @@ pub fn create_subpatterns(cx: @ExtCtxt, mutbl: ast::mutability) -> ~[@ast::pat] { do field_paths.map |&path| { - build::mk_pat(cx, span, + cx.mk_pat(span, ast::pat_ident(ast::bind_by_ref(mutbl), path, None)) } } @@ -274,12 +274,12 @@ pub fn create_struct_pattern(cx: @ExtCtxt, -> (@ast::pat, ~[(Option, @expr)]) { if struct_def.fields.is_empty() { return ( - build::mk_pat_ident_with_binding_mode( - cx, span, struct_ident, ast::bind_infer), + cx.mk_pat_ident_with_binding_mode( + span, struct_ident, ast::bind_infer), ~[]); } - let matching_path = build::mk_raw_path(span, ~[ struct_ident ]); + let matching_path = cx.mk_raw_path(span, ~[ struct_ident ]); let mut paths = ~[], ident_expr = ~[]; @@ -301,10 +301,10 @@ pub fn create_struct_pattern(cx: @ExtCtxt, cx.span_bug(span, "A struct with named and unnamed fields in `deriving`"); } }; - let path = build::mk_raw_path(span, + let path = cx.mk_raw_path(span, ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]); paths.push(path); - ident_expr.push((opt_id, build::mk_path_raw(cx, span, path))); + ident_expr.push((opt_id, cx.mk_path_raw(span, path))); } let subpats = create_subpatterns(cx, span, paths, mutbl); @@ -318,9 +318,9 @@ pub fn create_struct_pattern(cx: @ExtCtxt, push(ast::field_pat { ident: id.get(), pat: pat }) } }; - build::mk_pat_struct(cx, span, matching_path, field_pats) + cx.mk_pat_struct(span, matching_path, field_pats) } else { - build::mk_pat_enum(cx, span, matching_path, subpats) + cx.mk_pat_enum(span, matching_path, subpats) }; (pattern, ident_expr) @@ -337,24 +337,24 @@ pub fn create_enum_variant_pattern(cx: @ExtCtxt, match variant.node.kind { ast::tuple_variant_kind(ref variant_args) => { if variant_args.is_empty() { - return (build::mk_pat_ident_with_binding_mode( - cx, span, variant_ident, ast::bind_infer), ~[]); + return (cx.mk_pat_ident_with_binding_mode( + span, variant_ident, ast::bind_infer), ~[]); } - let matching_path = build::mk_raw_path(span, ~[ variant_ident ]); + let matching_path = cx.mk_raw_path(span, ~[ variant_ident ]); let mut paths = ~[], ident_expr = ~[]; for uint::range(0, variant_args.len()) |i| { - let path = build::mk_raw_path(span, + let path = cx.mk_raw_path(span, ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]); paths.push(path); - ident_expr.push((None, build::mk_path_raw(cx, span, path))); + ident_expr.push((None, cx.mk_path_raw(span, path))); } let subpats = create_subpatterns(cx, span, paths, mutbl); - (build::mk_pat_enum(cx, span, matching_path, subpats), + (cx.mk_pat_enum(span, matching_path, subpats), ident_expr) } ast::struct_variant_kind(struct_def) => { @@ -377,8 +377,8 @@ pub fn expand_enum_or_struct_match(cx: @ExtCtxt, span: span, arms: ~[ ast::arm ]) -> @expr { - let self_expr = build::make_self(cx, span); - let self_expr = build::mk_unary(cx, span, ast::deref, self_expr); + let self_expr = cx.make_self(span); + let self_expr = cx.mk_unary(span, ast::deref, self_expr); let self_match_expr = ast::expr_match(self_expr, arms); - build::mk_expr(cx, span, self_match_expr) + cx.mk_expr(span, self_match_expr) } diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 64cf7e93b92e8..b8e9de22fb0ef 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -12,7 +12,7 @@ use ast; use ast::{meta_item, item, expr, ident}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::{AstBuilder, Duplicate, Field}; use ext::deriving::generic::*; pub fn expand_deriving_rand(cx: @ExtCtxt, @@ -59,10 +59,10 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cx.ident_of("rand") ]; let rand_call = || { - build::mk_call_global(cx, + cx.mk_call_global( span, copy rand_ident, - ~[ build::duplicate_expr(cx, rng[0]) ]) + ~[ rng[0].duplicate(cx) ]) }; return match *substr.fields { @@ -74,30 +74,30 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cx.span_fatal(span, "`Rand` cannot be derived for enums with no variants"); } - let variant_count = build::mk_uint(cx, span, variants.len()); + let variant_count = cx.mk_uint(span, variants.len()); // need to specify the uint-ness of the random number - let u32_ty = build::mk_ty_path(cx, span, ~[cx.ident_of("uint")]); - let r_ty = build::mk_ty_path(cx, span, ~[cx.ident_of("R")]); - let rand_name = build::mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); - let rand_name = build::mk_path_raw(cx, span, rand_name); + let u32_ty = cx.mk_ty_path(span, ~[cx.ident_of("uint")]); + let r_ty = cx.mk_ty_path(span, ~[cx.ident_of("R")]); + let rand_name = cx.mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); + let rand_name = cx.mk_path_raw(span, rand_name); - let rv_call = build::mk_call_(cx, + let rv_call = cx.mk_call_( span, rand_name, - ~[ build::duplicate_expr(cx, rng[0]) ]); + ~[ rng[0].duplicate(cx) ]); // rand() % variants.len() - let rand_variant = build::mk_binary(cx, span, ast::rem, + let rand_variant = cx.mk_binary(span, ast::rem, rv_call, variant_count); let mut arms = do variants.mapi |i, id_sum| { - let i_expr = build::mk_uint(cx, span, i); - let pat = build::mk_pat_lit(cx, span, i_expr); + let i_expr = cx.mk_uint(span, i); + let pat = cx.mk_pat_lit(span, i_expr); match *id_sum { (ident, ref summary) => { - build::mk_arm(cx, span, + cx.mk_arm(span, ~[ pat ], rand_thing(cx, span, ident, summary, rand_call)) } @@ -105,9 +105,9 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { }; // _ => {} at the end. Should never occur - arms.push(build::mk_unreachable_arm(cx, span)); + arms.push(cx.mk_unreachable_arm(span)); - build::mk_expr(cx, span, + cx.mk_expr(span, ast::expr_match(rand_variant, arms)) } _ => cx.bug("Non-static method in `deriving(Rand)`") @@ -121,20 +121,20 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { match *summary { Left(copy count) => { if count == 0 { - build::mk_path(cx, span, ctor_ident) + cx.mk_path(span, ctor_ident) } else { let exprs = vec::from_fn(count, |_| rand_call()); - build::mk_call(cx, span, ctor_ident, exprs) + cx.mk_call(span, ctor_ident, exprs) } } Right(ref fields) => { let rand_fields = do fields.map |ident| { - build::Field { + Field { ident: *ident, ex: rand_call() } }; - build::mk_struct_e(cx, span, ctor_ident, rand_fields) + cx.mk_struct_e(span, ctor_ident, rand_fields) } } } diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 19fd601186b1e..9198c67177e53 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_to_str(cx: @ExtCtxt, @@ -42,8 +42,8 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt, fn to_str_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { match substr.self_args { [self_obj] => { - let self_addr = build::mk_addr_of(cx, span, self_obj); - build::mk_call_global(cx, span, + let self_addr = cx.mk_addr_of(span, self_obj); + cx.mk_call_global(span, ~[cx.ident_of("core"), cx.ident_of("sys"), cx.ident_of("log_str")], diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 154e7647bb560..a9d13bfe79c48 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -16,7 +16,7 @@ explicit `Self` type to use when specifying impls to be derived. use ast; use ast::{expr,Generics,ident}; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use codemap::{span,respan}; use opt_vec; @@ -55,7 +55,7 @@ pub impl<'self> Path<'self> { fn to_ty(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Ty { - build::mk_ty_path_path(cx, span, + cx.mk_ty_path_path(span, self.to_path(cx, span, self_ty, self_generics)) } @@ -66,9 +66,9 @@ pub impl<'self> Path<'self> { let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics)); if self.global { - build::mk_raw_path_global_(span, idents, lt, tys) + cx.mk_raw_path_global_(span, idents, lt, tys) } else { - build::mk_raw_path_(span, idents, lt, tys) + cx.mk_raw_path_(span, idents, lt, tys) } } } @@ -106,7 +106,7 @@ pub fn nil_ty() -> Ty<'static> { fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> { match *lt { - Some(ref s) => Some(@build::mk_lifetime(cx, span, cx.ident_of(*s))), + Some(ref s) => Some(@cx.mk_lifetime(span, cx.ident_of(*s))), None => None } } @@ -119,20 +119,20 @@ pub impl<'self> Ty<'self> { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); match *ptr { Owned => { - build::mk_ty_uniq(cx, span, raw_ty) + cx.mk_ty_uniq(span, raw_ty) } Managed(mutbl) => { - build::mk_ty_box(cx, span, raw_ty, mutbl) + cx.mk_ty_box(span, raw_ty, mutbl) } Borrowed(ref lt, mutbl) => { let lt = mk_lifetime(cx, span, lt); - build::mk_ty_rptr(cx, span, raw_ty, lt, mutbl) + cx.mk_ty_rptr(span, raw_ty, lt, mutbl) } } } Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) } Self => { - build::mk_ty_path_path(cx, span, self.to_path(cx, span, self_ty, self_generics)) + cx.mk_ty_path_path(span, self.to_path(cx, span, self_ty, self_generics)) } Tuple(ref fields) => { let ty = if fields.is_empty() { @@ -141,7 +141,7 @@ pub impl<'self> Ty<'self> { ast::ty_tup(fields.map(|f| f.to_ty(cx, span, self_ty, self_generics))) }; - build::mk_ty(cx, span, ty) + cx.mk_ty(span, ty) } } } @@ -151,7 +151,7 @@ pub impl<'self> Ty<'self> { match *self { Self => { let self_params = do self_generics.ty_params.map |ty_param| { - build::mk_ty_path(cx, span, ~[ ty_param.ident ]) + cx.mk_ty_path(span, ~[ ty_param.ident ]) }; let lifetime = if self_generics.lifetimes.is_empty() { None @@ -159,7 +159,7 @@ pub impl<'self> Ty<'self> { Some(@*self_generics.lifetimes.get(0)) }; - build::mk_raw_path_(span, ~[self_ty], lifetime, + cx.mk_raw_path_(span, ~[self_ty], lifetime, opt_vec::take_vec(self_params)) } Literal(ref p) => { @@ -177,9 +177,9 @@ fn mk_ty_param(cx: @ExtCtxt, span: span, name: &str, bounds: &[Path], let bounds = opt_vec::from( do bounds.map |b| { let path = b.to_path(cx, span, self_ident, self_generics); - build::mk_trait_ty_param_bound_(cx, path) + cx.mk_trait_ty_param_bound_(path) }); - build::mk_ty_param(cx, cx.ident_of(name), @bounds) + cx.mk_ty_param(cx.ident_of(name), @bounds) } fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Generics { @@ -204,7 +204,7 @@ pub impl<'self> LifetimeBounds<'self> { fn to_generics(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> Generics { let lifetimes = do self.lifetimes.map |lt| { - build::mk_lifetime(cx, span, cx.ident_of(*lt)) + cx.mk_lifetime(span, cx.ident_of(*lt)) }; let ty_params = do self.bounds.map |t| { match t { @@ -220,7 +220,7 @@ pub impl<'self> LifetimeBounds<'self> { pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) -> (@expr, ast::explicit_self) { - let self_path = build::make_self(cx, span); + let self_path = cx.make_self(span); match *self_ptr { None => { (self_path, respan(span, ast::sty_value)) @@ -232,12 +232,12 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) Owned => ast::sty_uniq(ast::m_imm), Managed(mutbl) => ast::sty_box(mutbl), Borrowed(ref lt, mutbl) => { - let lt = lt.map(|s| @build::mk_lifetime(cx, span, + let lt = lt.map(|s| @cx.mk_lifetime(span, cx.ident_of(*s))); ast::sty_region(lt, mutbl) } }); - let self_expr = build::mk_deref(cx, span, self_path); + let self_expr = cx.mk_deref(span, self_path); (self_expr, self_ty) } } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 3d74595e645ae..fb7367b47bafc 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -18,7 +18,7 @@ use ast; use codemap::span; use ext::base::*; use ext::base; -use ext::build::mk_base_str; +use ext::build::AstBuilder; pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { @@ -29,8 +29,8 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) // Option rather than just an maybe-empty string. let e = match os::getenv(var) { - None => mk_base_str(cx, sp, ~""), - Some(ref s) => mk_base_str(cx, sp, copy *s) + None => cx.mk_base_str(sp, ~""), + Some(ref s) => cx.mk_base_str(sp, copy *s) }; MRExpr(e) } diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index ca281a22e3922..1e4ff03b610c8 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -19,7 +19,7 @@ use codemap::span; use ext::base::*; use ext::base; use ext::build; -use ext::build::*; +use ext::build::AstBuilder; use core::unstable::extfmt::ct::*; @@ -56,7 +56,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, } fn make_rt_path_expr(cx: @ExtCtxt, sp: span, nm: &str) -> @ast::expr { let path = make_path_vec(cx, nm); - return mk_path_global(cx, sp, path); + cx.mk_path_global(sp, path) } // Produces an AST expression that represents a RT::conv record, // which tells the RT::conv* functions how to perform the conversion @@ -72,7 +72,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, FlagSignAlways => "flag_sign_always", FlagAlternate => "flag_alternate" }; - tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr, + tmp_expr = cx.mk_binary(sp, ast::bitor, tmp_expr, make_rt_path_expr(cx, sp, fstr)); } return tmp_expr; @@ -83,10 +83,10 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, return make_rt_path_expr(cx, sp, "CountImplied"); } CountIs(c) => { - let count_lit = mk_uint(cx, sp, c as uint); + let count_lit = cx.mk_uint(sp, c as uint); let count_is_path = make_path_vec(cx, "CountIs"); let count_is_args = ~[count_lit]; - return mk_call_global(cx, sp, count_is_path, count_is_args); + return cx.mk_call_global(sp, count_is_path, count_is_args); } _ => cx.span_unimpl(sp, "unimplemented fmt! conversion") } @@ -107,8 +107,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { let intr = cx.parse_sess().interner; - mk_global_struct_e( - cx, + cx.mk_global_struct_e( sp, make_path_vec(cx, "Conv"), ~[ @@ -140,7 +139,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, let path = make_path_vec(cx, fname); let cnv_expr = make_rt_conv_expr(cx, sp, cnv); let args = ~[cnv_expr, arg, buf]; - return mk_call_global(cx, arg.span, path, args); + cx.mk_call_global(arg.span, path, args) } fn make_new_conv(cx: @ExtCtxt, sp: span, cnv: &Conv, @@ -198,10 +197,10 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, TyChar => ("char", arg), TyBits | TyOctal | TyHex(_) | TyInt(Unsigned) => ("uint", arg), TyFloat => ("float", arg), - TyPoly => ("poly", mk_addr_of(cx, sp, arg)) + TyPoly => ("poly", cx.mk_addr_of(sp, arg)) }; return make_conv_call(cx, arg.span, name, cnv, actual_arg, - mk_mut_addr_of(cx, arg.span, buf)); + cx.mk_mut_addr_of(arg.span, buf)); } fn log_conv(c: &Conv) { debug!("Building conversion:"); @@ -259,7 +258,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, /* 'ident' is the local buffer building up the result of fmt! */ let ident = cx.parse_sess().interner.intern("__fmtbuf"); - let buf = || mk_path(cx, fmt_sp, ~[ident]); + let buf = || cx.mk_path(fmt_sp, ~[ident]); let str_ident = cx.parse_sess().interner.intern("str"); let push_ident = cx.parse_sess().interner.intern("push_str"); let mut stms = ~[]; @@ -276,14 +275,14 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, buffer with it directly. If it's actually the only piece, then there's no need for it to be mutable */ if i == 0 { - stms.push(mk_local(cx, fmt_sp, npieces > 1, ident, mk_uniq_str(cx, fmt_sp, s))); + stms.push(cx.mk_local(fmt_sp, npieces > 1, ident, cx.mk_uniq_str(fmt_sp, s))); } else { - let args = ~[mk_mut_addr_of(cx, fmt_sp, buf()), mk_base_str(cx, fmt_sp, s)]; - let call = mk_call_global(cx, + let args = ~[cx.mk_mut_addr_of(fmt_sp, buf()), cx.mk_base_str(fmt_sp, s)]; + let call = cx.mk_call_global( fmt_sp, ~[str_ident, push_ident], args); - stms.push(mk_stmt(cx, fmt_sp, call)); + stms.push(cx.mk_stmt(fmt_sp, call)); } } @@ -300,12 +299,12 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, /* If the first portion is a conversion, then the local buffer must be initialized as an empty string */ if i == 0 { - stms.push(mk_local(cx, fmt_sp, true, ident, - mk_uniq_str(cx, fmt_sp, ~""))); + stms.push(cx.mk_local(fmt_sp, true, ident, + cx.mk_uniq_str(fmt_sp, ~""))); } - stms.push(mk_stmt(cx, fmt_sp, - make_new_conv(cx, fmt_sp, conv, - args[n], buf()))); + stms.push(cx.mk_stmt(fmt_sp, + make_new_conv(cx, fmt_sp, conv, + args[n], buf()))); } } } @@ -317,5 +316,5 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, nargs, expected_nargs)); } - return mk_block(cx, fmt_sp, ~[], stms, Some(buf())); + cx.mk_block(fmt_sp, ~[], stms, Some(buf())) } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 2ccceeec294fc..5ab28b50e841c 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -12,7 +12,7 @@ use ast; use codemap::{BytePos, Pos, span}; use ext::base::ExtCtxt; use ext::base; -use ext::build; +use ext::build::AstBuilder; use parse::token::*; use parse::token; use parse; @@ -382,7 +382,7 @@ pub fn expand_quote_expr(cx: @ExtCtxt, pub fn expand_quote_item(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); + let e_attrs = cx.mk_uniq_vec_e(sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, "parse_item", ~[e_attrs], tts)) } @@ -390,7 +390,7 @@ pub fn expand_quote_item(cx: @ExtCtxt, pub fn expand_quote_pat(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true)); + let e_refutable = cx.mk_lit(sp, ast::lit_bool(true)); base::MRExpr(expand_parse_call(cx, sp, "parse_pat", ~[e_refutable], tts)) } @@ -398,7 +398,7 @@ pub fn expand_quote_pat(cx: @ExtCtxt, pub fn expand_quote_ty(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false)); + let e_param_colons = cx.mk_lit(sp, ast::lit_bool(false)); base::MRExpr(expand_parse_call(cx, sp, "parse_ty", ~[e_param_colons], tts)) } @@ -406,7 +406,7 @@ pub fn expand_quote_ty(cx: @ExtCtxt, pub fn expand_quote_stmt(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); + let e_attrs = cx.mk_uniq_vec_e(sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, "parse_stmt", ~[e_attrs], tts)) } @@ -421,17 +421,17 @@ fn id_ext(cx: @ExtCtxt, str: &str) -> ast::ident { // Lift an ident to the expr that evaluates to that ident. fn mk_ident(cx: @ExtCtxt, sp: span, ident: ast::ident) -> @ast::expr { - let e_str = build::mk_base_str(cx, sp, cx.str_of(ident)); - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), - id_ext(cx, "ident_of"), - ~[e_str]) + let e_str = cx.mk_base_str(sp, cx.str_of(ident)); + cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), + id_ext(cx, "ident_of"), + ~[e_str]) } fn mk_bytepos(cx: @ExtCtxt, sp: span, bpos: BytePos) -> @ast::expr { let path = ids_ext(cx, ~[~"BytePos"]); - let arg = build::mk_uint(cx, sp, bpos.to_uint()); - build::mk_call(cx, sp, path, ~[arg]) + let arg = cx.mk_uint(sp, bpos.to_uint()); + cx.mk_call(sp, path, ~[arg]) } fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { @@ -447,7 +447,7 @@ fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { SHL => "SHL", SHR => "SHR" }; - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[name.to_owned()])) } @@ -455,12 +455,12 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { match *tok { BINOP(binop) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"BINOP"]), ~[mk_binop(cx, sp, binop)]); } BINOPEQ(binop) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"BINOPEQ"]), ~[mk_binop(cx, sp, binop)]); } @@ -475,12 +475,12 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_i64 => ~"ty_i64" }; let e_ity = - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[s_ity])); - let e_i64 = build::mk_lit(cx, sp, ast::lit_int(i, ast::ty_i64)); + let e_i64 = cx.mk_lit(sp, ast::lit_int(i, ast::ty_i64)); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_INT"]), ~[e_i64, e_ity]); } @@ -494,21 +494,21 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_u64 => ~"ty_u64" }; let e_uty = - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[s_uty])); - let e_u64 = build::mk_lit(cx, sp, ast::lit_uint(u, ast::ty_u64)); + let e_u64 = cx.mk_lit(sp, ast::lit_uint(u, ast::ty_u64)); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_UINT"]), ~[e_u64, e_uty]); } LIT_INT_UNSUFFIXED(i) => { - let e_i64 = build::mk_lit(cx, sp, + let e_i64 = cx.mk_lit(sp, ast::lit_int(i, ast::ty_i64)); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_INT_UNSUFFIXED"]), ~[e_i64]); } @@ -520,37 +520,37 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_f64 => ~"ty_f64" }; let e_fty = - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[s_fty])); let e_fident = mk_ident(cx, sp, fident); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_FLOAT"]), ~[e_fident, e_fty]); } LIT_STR(ident) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_STR"]), ~[mk_ident(cx, sp, ident)]); } IDENT(ident, b) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"IDENT"]), ~[mk_ident(cx, sp, ident), - build::mk_lit(cx, sp, ast::lit_bool(b))]); + cx.mk_lit(sp, ast::lit_bool(b))]); } LIFETIME(ident) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIFETIME"]), ~[mk_ident(cx, sp, ident)]); } DOC_COMMENT(ident) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"DOC_COMMENT"]), ~[mk_ident(cx, sp, ident)]); } @@ -595,7 +595,7 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { EOF => "EOF", _ => fail!() }; - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[name.to_owned()])) } @@ -606,18 +606,18 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree) match *tt { ast::tt_tok(sp, ref tok) => { - let e_sp = build::mk_path(cx, sp, + let e_sp = cx.mk_path(sp, ids_ext(cx, ~[~"sp"])); let e_tok = - build::mk_call(cx, sp, + cx.mk_call(sp, ids_ext(cx, ~[~"tt_tok"]), ~[e_sp, mk_token(cx, sp, tok)]); let e_push = - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"tt"])), + cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"tt"])), id_ext(cx, "push"), ~[e_tok]); - ~[build::mk_stmt(cx, sp, e_push)] + ~[cx.mk_stmt(sp, e_push)] } @@ -629,19 +629,19 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree) // tt.push_all_move($ident.to_tokens(ext_cx)) let e_to_toks = - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ~[ident]), + cx.mk_method_call(sp, + cx.mk_path(sp, ~[ident]), id_ext(cx, "to_tokens"), - ~[build::mk_path(cx, sp, + ~[cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"]))]); let e_push = - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"tt"])), + cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"tt"])), id_ext(cx, "push_all_move"), ~[e_to_toks]); - ~[build::mk_stmt(cx, sp, e_push)] + ~[cx.mk_stmt(sp, e_push)] } } } @@ -677,11 +677,11 @@ fn expand_tts(cx: @ExtCtxt, // We want to emit a block expression that does a sequence of 'use's to // import the runtime module, followed by a tt-building expression. - let uses = ~[ build::mk_glob_use(cx, sp, ast::public, - ids_ext(cx, ~[~"syntax", - ~"ext", - ~"quote", - ~"rt"])) ]; + let uses = ~[ cx.mk_glob_use(sp, ast::public, + ids_ext(cx, ~[~"syntax", + ~"ext", + ~"quote", + ~"rt"])) ]; // We also bind a single value, sp, to ext_cx.call_site() // @@ -709,23 +709,23 @@ fn expand_tts(cx: @ExtCtxt, // of quotes, for example) but at this point it seems not likely to be // worth the hassle. - let e_sp = build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), + let e_sp = cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), id_ext(cx, "call_site"), ~[]); - let stmt_let_sp = build::mk_local(cx, sp, false, + let stmt_let_sp = cx.mk_local(sp, false, id_ext(cx, "sp"), e_sp); - let stmt_let_tt = build::mk_local(cx, sp, true, + let stmt_let_tt = cx.mk_local(sp, true, id_ext(cx, "tt"), - build::mk_uniq_vec_e(cx, sp, ~[])); + cx.mk_uniq_vec_e(sp, ~[])); - build::mk_block(cx, sp, uses, + cx.mk_block(sp, uses, ~[stmt_let_sp, stmt_let_tt] + mk_tts(cx, sp, tts), - Some(build::mk_path(cx, sp, + Some(cx.mk_path(sp, ids_ext(cx, ~[~"tt"])))) } @@ -736,16 +736,16 @@ fn expand_parse_call(cx: @ExtCtxt, tts: &[ast::token_tree]) -> @ast::expr { let tts_expr = expand_tts(cx, sp, tts); - let cfg_call = || build::mk_method_call( - cx, sp, build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), + let cfg_call = || cx.mk_method_call( + sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), id_ext(cx, "cfg"), ~[]); - let parse_sess_call = || build::mk_method_call( - cx, sp, build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), + let parse_sess_call = || cx.mk_method_call( + sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), id_ext(cx, "parse_sess"), ~[]); let new_parser_call = - build::mk_call_global(cx, sp, + cx.mk_call_global(sp, ids_ext(cx, ~[~"syntax", ~"ext", ~"quote", @@ -755,7 +755,7 @@ fn expand_parse_call(cx: @ExtCtxt, cfg_call(), tts_expr]); - build::mk_method_call(cx, sp, + cx.mk_method_call(sp, new_parser_call, id_ext(cx, parse_method), arg_exprs) diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index d78c06bec0774..40dc44ca99326 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -14,7 +14,7 @@ use codemap::{FileMap, Loc, Pos, ExpandedFrom, span}; use codemap::{CallInfo, NameAndSpan}; use ext::base::*; use ext::base; -use ext::build::{mk_base_vec_e, mk_uint, mk_u8, mk_base_str}; +use ext::build::AstBuilder; use parse; use print::pprust; @@ -30,7 +30,7 @@ pub fn expand_line(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(mk_uint(cx, topmost.call_site, loc.line)) + base::MRExpr(cx.mk_uint(topmost.call_site, loc.line)) } /* col!(): expands to the current column number */ @@ -40,7 +40,7 @@ pub fn expand_col(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(mk_uint(cx, topmost.call_site, loc.col.to_uint())) + base::MRExpr(cx.mk_uint(topmost.call_site, loc.col.to_uint())) } /* file!(): expands to the current filename */ @@ -53,19 +53,19 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let Loc { file: @FileMap { name: filename, _ }, _ } = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(mk_base_str(cx, topmost.call_site, filename)) + base::MRExpr(cx.mk_base_str(topmost.call_site, filename)) } pub fn expand_stringify(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, cx.parse_sess().interner); - base::MRExpr(mk_base_str(cx, sp, s)) + base::MRExpr(cx.mk_base_str(sp, s)) } pub fn expand_mod(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); - base::MRExpr(mk_base_str(cx, sp, + base::MRExpr(cx.mk_base_str(sp, str::connect(cx.mod_path().map( |x| cx.str_of(*x)), "::"))) } @@ -94,7 +94,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) } } - base::MRExpr(mk_base_str(cx, sp, result::unwrap(res))) + base::MRExpr(cx.mk_base_str(sp, result::unwrap(res))) } pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) @@ -103,9 +103,9 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { result::Ok(src) => { let u8_exprs = vec::map(src, |char| { - mk_u8(cx, sp, *char) + cx.mk_u8(sp, *char) }); - base::MRExpr(mk_base_vec_e(cx, sp, u8_exprs)) + base::MRExpr(cx.mk_base_vec_e(sp, u8_exprs)) } result::Err(ref e) => { cx.parse_sess().span_diagnostic.handler().fatal((*e)) From a59bec43e34715880f471db7d7c9d57939649d92 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 19 May 2013 15:53:42 +1000 Subject: [PATCH 6/6] syntax/ext: convert all AstBuilder methods to a uniform syntax. --- src/libsyntax/ext/build.rs | 1562 +++++++------------- src/libsyntax/ext/bytes.rs | 10 +- src/libsyntax/ext/deriving/clone.rs | 17 +- src/libsyntax/ext/deriving/cmp/eq.rs | 4 +- src/libsyntax/ext/deriving/cmp/ord.rs | 29 +- src/libsyntax/ext/deriving/cmp/totaleq.rs | 2 +- src/libsyntax/ext/deriving/cmp/totalord.rs | 19 +- src/libsyntax/ext/deriving/decodable.rs | 204 +-- src/libsyntax/ext/deriving/encodable.rs | 165 +-- src/libsyntax/ext/deriving/generic.rs | 52 +- src/libsyntax/ext/deriving/iter_bytes.rs | 6 +- src/libsyntax/ext/deriving/mod.rs | 102 +- src/libsyntax/ext/deriving/rand.rs | 55 +- src/libsyntax/ext/deriving/to_str.rs | 12 +- src/libsyntax/ext/deriving/ty.rs | 43 +- src/libsyntax/ext/env.rs | 4 +- src/libsyntax/ext/fmt.rs | 64 +- src/libsyntax/ext/pipes/ast_builder.rs | 2 +- src/libsyntax/ext/pipes/pipec.rs | 90 +- src/libsyntax/ext/quote.rs | 226 ++- src/libsyntax/ext/source_util.rs | 16 +- 21 files changed, 998 insertions(+), 1686 deletions(-) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index eb48ed583750d..01a504101b914 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -12,8 +12,7 @@ use abi::AbiSet; use ast::ident; use ast; use ast_util; -use codemap; -use codemap::{span, respan, dummy_sp, spanned}; +use codemap::{span, respan, dummy_sp}; use fold; use ext::base::ExtCtxt; use ext::quote::rt::*; @@ -34,442 +33,291 @@ mod syntax { pub trait AstBuilder { // paths fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path_ident(&self, span: span, id: ast::ident) -> @ast::Path; fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; - fn path_tps(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) - -> @ast::Path; - fn path_tps_global(&self, - span: span, - strs: ~[ast::ident], - tps: ~[@ast::Ty]) + fn path_all(&self, sp: span, + global: bool, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) -> @ast::Path; // types + fn ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt; + + fn ty(&self, span: span, ty: ast::ty_) -> @ast::Ty; fn ty_path(&self, @ast::Path) -> @ast::Ty; + fn ty_ident(&self, span: span, idents: ast::ident) -> @ast::Ty; + + fn ty_rptr(&self, span: span, + ty: @ast::Ty, + lifetime: Option<@ast::Lifetime>, + mutbl: ast::mutability) + -> @ast::Ty; + fn ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty; + fn ty_box(&self, span: span, ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty; + + fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty; + fn ty_infer(&self, sp: span) -> @ast::Ty; + fn ty_nil(&self) -> @ast::Ty; - fn ty_param(&self, id: ast::ident, bounds: @OptVec) - -> ast::TyParam; fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty]; fn ty_vars_global(&self, ty_params: &OptVec) -> ~[@ast::Ty]; - fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field; - fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty; - fn ty_infer(&self) -> @ast::Ty; - fn ty_nil_ast_builder(&self) -> @ast::Ty; + fn ty_field_imm(&self, span: span, name: ident, ty: @ast::Ty) -> ast::ty_field; fn strip_bounds(&self, bounds: &Generics) -> Generics; + fn typaram(&self, id: ast::ident, bounds: @OptVec) -> ast::TyParam; + + fn trait_ref(&self, path: @ast::Path) -> @ast::trait_ref; + fn typarambound(&self, path: @ast::Path) -> ast::TyParamBound; + fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime; // statements fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt; - fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt; - - // literals - fn lit_str(&self, span: span, s: @~str) -> @ast::expr; - fn lit_uint(&self, span: span, i: uint) -> @ast::expr; + fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt; // blocks fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::blk; fn blk_expr(&self, expr: @ast::expr) -> ast::blk; + fn blk_all(&self, span: span, + view_items: ~[@ast::view_item], + stmts: ~[@ast::stmt], + expr: Option<@ast::expr>) -> ast::blk; // expressions fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; - fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; - fn expr_path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; - fn expr_var(&self, span: span, var: &str) -> @ast::expr; + fn expr_path(&self, path: @ast::Path) -> @ast::expr; + fn expr_ident(&self, span: span, id: ast::ident) -> @ast::expr; + fn expr_self(&self, span: span) -> @ast::expr; - fn expr_field(&self, span: span, expr: @ast::expr, ident: ast::ident) - -> @ast::expr; - fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) - -> @ast::expr; - fn expr_method_call(&self, - span: span, - expr: @ast::expr, - ident: ast::ident, - args: ~[@ast::expr]) - -> @ast::expr; + fn expr_binary(&self, sp: span, op: ast::binop, + lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr; + fn expr_deref(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn expr_unary(&self, sp: span, op: ast::unop, e: @ast::expr) -> @ast::expr; + + fn expr_copy(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn expr_managed(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn expr_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn expr_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn expr_field_access(&self, span: span, expr: @ast::expr, ident: ast::ident) -> @ast::expr; + fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) -> @ast::expr; + fn expr_call_ident(&self, span: span, id: ast::ident, args: ~[@ast::expr]) -> @ast::expr; + fn expr_call_global(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr; + fn expr_method_call(&self, span: span, + expr: @ast::expr, ident: ast::ident, + args: ~[@ast::expr]) -> @ast::expr; fn expr_blk(&self, b: ast::blk) -> @ast::expr; - fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field; - fn expr_struct(&self, - path: @ast::Path, - fields: ~[ast::field]) -> @ast::expr; - fn lambda0(&self, blk: ast::blk) -> @ast::expr; - fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr; - fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr; - fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) - -> @ast::expr; + + fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field; + fn expr_struct(&self, span: span, path: @ast::Path, fields: ~[ast::field]) -> @ast::expr; + fn expr_struct_ident(&self, span: span, id: ast::ident, fields: ~[ast::field]) -> @ast::expr; + + fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr; + + fn expr_uint(&self, span: span, i: uint) -> @ast::expr; + fn expr_int(&self, sp: span, i: int) -> @ast::expr; + fn expr_u8(&self, sp: span, u: u8) -> @ast::expr; + fn expr_bool(&self, sp: span, value: bool) -> @ast::expr; + + fn expr_vstore(&self, sp: span, expr: @ast::expr, vst: ast::expr_vstore) -> @ast::expr; + fn expr_vec(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr; + fn expr_vec_uniq(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr; + fn expr_vec_slice(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr; + fn expr_str(&self, sp: span, s: ~str) -> @ast::expr; + fn expr_str_uniq(&self, sp: span, s: ~str) -> @ast::expr; + + fn expr_unreachable(&self, span: span) -> @ast::expr; + + fn pat(&self, span: span, pat: ast::pat_) -> @ast::pat; + fn pat_wild(&self, span: span) -> @ast::pat; + fn pat_lit(&self, span: span, expr: @ast::expr) -> @ast::pat; + fn pat_ident(&self, span: span, ident: ast::ident) -> @ast::pat; + + fn pat_ident_binding_mode(&self, + span: span, + ident: ast::ident, + bm: ast::binding_mode) -> @ast::pat; + fn pat_enum(&self, span: span, path: @ast::Path, subpats: ~[@ast::pat]) -> @ast::pat; + fn pat_struct(&self, span: span, + path: @ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat; + + fn arm(&self, span: span, pats: ~[@ast::pat], expr: @ast::expr) -> ast::arm; + fn arm_unreachable(&self, span: span) -> ast::arm; + + fn expr_match(&self, span: span, arg: @ast::expr, arms: ~[ast::arm]) -> @ast::expr; + fn expr_if(&self, span: span, + cond: @ast::expr, then: @ast::expr, els: Option<@ast::expr>) -> @ast::expr; + + fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::blk) -> @ast::expr; + + fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::blk) -> @ast::expr; + fn lambda0(&self, span: span, blk: ast::blk) -> @ast::expr; + fn lambda1(&self, span: span, blk: ast::blk, ident: ast::ident) -> @ast::expr; + + fn lambda_expr(&self, span: span, ids: ~[ast::ident], blk: @ast::expr) -> @ast::expr; + fn lambda_expr_0(&self, span: span, expr: @ast::expr) -> @ast::expr; + fn lambda_expr_1(&self, span: span, expr: @ast::expr, ident: ast::ident) -> @ast::expr; + + fn lambda_stmts(&self, span: span, ids: ~[ast::ident], blk: ~[@ast::stmt]) -> @ast::expr; fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr; - fn lambda_stmts_1(&self, - span: span, - stmts: ~[@ast::stmt], - ident: ast::ident) - -> @ast::expr; + fn lambda_stmts_1(&self, span: span, stmts: ~[@ast::stmt], ident: ast::ident) -> @ast::expr; // items - fn item(&self, name: ident, span: span, node: ast::item_) -> @ast::item; + fn item(&self, span: span, + name: ident, attrs: ~[ast::attribute], node: ast::item_) -> @ast::item; - fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg; + fn arg(&self, span: span, name: ident, ty: @ast::Ty) -> ast::arg; + // XXX unused self fn fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; fn item_fn_poly(&self, - ame: ident, + span: span, + name: ident, inputs: ~[ast::arg], output: @ast::Ty, generics: Generics, body: ast::blk) -> @ast::item; fn item_fn(&self, + span: span, name: ident, inputs: ~[ast::arg], output: @ast::Ty, body: ast::blk) -> @ast::item; - fn variant(&self, - name: ident, - span: span, - tys: ~[@ast::Ty]) -> ast::variant; + fn variant(&self, span: span, name: ident, tys: ~[@ast::Ty]) -> ast::variant; fn item_enum_poly(&self, - name: ident, span: span, + name: ident, enum_definition: ast::enum_def, generics: Generics) -> @ast::item; - fn item_enum(&self, - name: ident, - span: span, - enum_definition: ast::enum_def) -> @ast::item; + fn item_enum(&self, span: span, name: ident, enum_def: ast::enum_def) -> @ast::item; fn item_struct_poly(&self, - name: ident, span: span, + name: ident, struct_def: ast::struct_def, generics: Generics) -> @ast::item; - fn item_struct(&self, - name: ident, - span: span, - struct_def: ast::struct_def) -> @ast::item; + fn item_struct(&self, span: span, name: ident, struct_def: ast::struct_def) -> @ast::item; - fn item_mod(&self, - name: ident, - span: span, - items: ~[@ast::item]) -> @ast::item; + fn item_mod(&self, span: span, + name: ident, attrs: ~[ast::attribute], + vi: ~[@ast::view_item], items: ~[@ast::item]) -> @ast::item; fn item_ty_poly(&self, - name: ident, span: span, + name: ident, ty: @ast::Ty, generics: Generics) -> @ast::item; - fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item; - - - - - fn mk_expr(&self, - sp: codemap::span, - expr: ast::expr_) - -> @ast::expr; - - fn mk_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr; - fn mk_int(&self, sp: span, i: int) -> @ast::expr; - fn mk_uint(&self, sp: span, u: uint) -> @ast::expr; - fn mk_u8(&self, sp: span, u: u8) -> @ast::expr; - fn mk_binary(&self, sp: span, op: ast::binop, - lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr; - - fn mk_deref(&self, sp: span, e: @ast::expr) -> @ast::expr; - fn mk_unary(&self, sp: span, op: ast::unop, e: @ast::expr) - -> @ast::expr; - // XXX: unused self - fn mk_raw_path(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path; - // XXX: unused self - fn mk_raw_path_(&self, sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) - -> @ast::Path; - // XXX: unused self - fn mk_raw_path_global(&self, sp: span,idents: ~[ast::ident]) -> @ast::Path; - // XXX: unused self - fn mk_raw_path_global_(&self, sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) -> @ast::Path; - fn mk_path_raw(&self, sp: span, path: @ast::Path)-> @ast::expr; - fn mk_path(&self, sp: span, idents: ~[ast::ident]) - -> @ast::expr; - fn mk_path_global(&self, sp: span, idents: ~[ast::ident]) - -> @ast::expr; - fn mk_access_(&self, sp: span, p: @ast::expr, m: ast::ident) - -> @ast::expr; - fn mk_access(&self, sp: span, p: ~[ast::ident], m: ast::ident) - -> @ast::expr; - fn mk_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; - fn mk_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; - fn mk_method_call(&self, - sp: span, - rcvr_expr: @ast::expr, - method_ident: ast::ident, - args: ~[@ast::expr]) -> @ast::expr; - fn mk_call_(&self, sp: span, fn_expr: @ast::expr, - args: ~[@ast::expr]) -> @ast::expr; - fn mk_call(&self, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr; - fn mk_call_global(&self, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr; - // e = expr, t = type - fn mk_base_vec_e(&self, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr; - fn mk_vstore_e(&self, sp: span, expr: @ast::expr, - vst: ast::expr_vstore) -> - @ast::expr; - fn mk_uniq_vec_e(&self, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr; - fn mk_slice_vec_e(&self, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr; - fn mk_base_str(&self, sp: span, s: ~str) -> @ast::expr; - fn mk_uniq_str(&self, sp: span, s: ~str) -> @ast::expr; - // XXX: unused self - fn mk_field(&self, sp: span, f: &Field) -> ast::field; - // XXX: unused self - fn mk_fields(&self, sp: span, fields: ~[Field]) -> ~[ast::field]; - fn mk_struct_e(&self, - sp: span, - ctor_path: ~[ast::ident], - fields: ~[Field]) - -> @ast::expr; - fn mk_global_struct_e(&self, - sp: span, - ctor_path: ~[ast::ident], - fields: ~[Field]) - -> @ast::expr; - fn mk_glob_use(&self, - sp: span, - vis: ast::visibility, - path: ~[ast::ident]) -> @ast::view_item; - fn mk_local(&self, sp: span, mutbl: bool, - ident: ast::ident, ex: @ast::expr) -> @ast::stmt; - fn mk_block(&self, span: span, - view_items: ~[@ast::view_item], - stmts: ~[@ast::stmt], - expr: Option<@ast::expr>) -> @ast::expr; - fn mk_block_(&self, - span: span, - stmts: ~[@ast::stmt]) - -> ast::blk; - fn mk_simple_block(&self, - span: span, - expr: @ast::expr) - -> ast::blk; - fn mk_lambda_(&self, - span: span, - fn_decl: ast::fn_decl, - blk: ast::blk) - -> @ast::expr; - fn mk_lambda(&self, - span: span, - fn_decl: ast::fn_decl, - expr: @ast::expr) - -> @ast::expr; - fn mk_lambda_stmts(&self, - span: span, - fn_decl: ast::fn_decl, - stmts: ~[@ast::stmt]) - -> @ast::expr ; - fn mk_lambda_no_args(&self, - span: span, - expr: @ast::expr) - -> @ast::expr; - fn mk_copy(&self, sp: span, e: @ast::expr) -> @ast::expr; - fn mk_managed(&self, sp: span, e: @ast::expr) -> @ast::expr; - fn mk_pat(&self, span: span, pat: ast::pat_) -> @ast::pat; - fn mk_pat_wild(&self, span: span) -> @ast::pat; - fn mk_pat_lit(&self, - span: span, - expr: @ast::expr) -> @ast::pat; - fn mk_pat_ident(&self, - span: span, - ident: ast::ident) -> @ast::pat; - - fn mk_pat_ident_with_binding_mode(&self, - span: span, - ident: ast::ident, - bm: ast::binding_mode) -> @ast::pat; - fn mk_pat_enum(&self, - span: span, - path: @ast::Path, - subpats: ~[@ast::pat]) - -> @ast::pat; - fn mk_pat_struct(&self, - span: span, - path: @ast::Path, - field_pats: ~[ast::field_pat]) - -> @ast::pat; - fn mk_bool(&self, span: span, value: bool) -> @ast::expr; - fn mk_stmt(&self, span: span, expr: @ast::expr) -> @ast::stmt; - - // XXX: unused self - fn mk_ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt; - - fn mk_ty(&self, - span: span, - ty: ast::ty_) -> @ast::Ty; - - fn mk_ty_path(&self, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty; - - fn mk_ty_path_global(&self, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty; - - fn mk_ty_path_path(&self, - span: span, - path: @ast::Path) - -> @ast::Ty; + fn item_ty(&self, span: span, name: ident, ty: @ast::Ty) -> @ast::item; - fn mk_ty_rptr(&self, - span: span, - ty: @ast::Ty, - lifetime: Option<@ast::Lifetime>, - mutbl: ast::mutability) - -> @ast::Ty; - fn mk_ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty; - fn mk_ty_box(&self, span: span, - ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty; + fn attribute(&self, sp: span, mi: @ast::meta_item) -> ast::attribute; + fn meta_word(&self, sp: span, w: ~str) -> @ast::meta_item; + fn meta_list(&self, sp: span, name: ~str, mis: ~[@ast::meta_item]) -> @ast::meta_item; + fn meta_name_value(&self, sp: span, name: ~str, value: ast::lit_) -> @ast::meta_item; - - fn mk_ty_infer(&self, span: span) -> @ast::Ty; - fn mk_trait_ref_global(&self, - span: span, - idents: ~[ ast::ident ]) - -> @ast::trait_ref; - fn mk_trait_ref_(&self, path: @ast::Path) -> @ast::trait_ref; - fn mk_simple_ty_path(&self, - span: span, - ident: ast::ident) - -> @ast::Ty; - fn mk_arg(&self, - span: span, - ident: ast::ident, - ty: @ast::Ty) - -> ast::arg; - // XXX unused self - fn mk_fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; - fn mk_trait_ty_param_bound_global(&self, - span: span, - idents: ~[ast::ident]) - -> ast::TyParamBound; - fn mk_trait_ty_param_bound_(&self, - path: @ast::Path) -> ast::TyParamBound; - fn mk_ty_param(&self, - ident: ast::ident, - bounds: @OptVec) - -> ast::TyParam; - fn mk_lifetime(&self, - span: span, - ident: ast::ident) - -> ast::Lifetime; - fn mk_arm(&self, - span: span, - pats: ~[@ast::pat], - expr: @ast::expr) - -> ast::arm; - fn mk_unreachable(&self, span: span) -> @ast::expr; - fn mk_unreachable_arm(&self, span: span) -> ast::arm; - - fn make_self(&self, span: span) -> @ast::expr; + fn view_use(&self, sp: span, + vis: ast::visibility, vp: ~[@ast::view_path]) -> @ast::view_item; + fn view_use_list(&self, sp: span, vis: ast::visibility, + path: ~[ast::ident], imports: &[ast::ident]) -> @ast::view_item; + fn view_use_glob(&self, sp: span, + vis: ast::visibility, path: ~[ast::ident]) -> @ast::view_item; } impl AstBuilder for @ExtCtxt { fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path { - @ast::Path { - span: span, - global: false, - idents: strs, - rp: None, - types: ~[] - } + self.path_all(span, false, strs, None, ~[]) + } + fn path_ident(&self, span: span, id: ast::ident) -> @ast::Path { + self.path(span, ~[id]) } - fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path { + self.path_all(span, true, strs, None, ~[]) + } + fn path_all(&self, sp: span, + global: bool, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) + -> @ast::Path { @ast::Path { - span: span, - global: true, - idents: strs, - rp: None, - types: ~[] + span: sp, + global: global, + idents: idents, + rp: rp, + types: types } } - fn path_tps( - &self, - span: span, - strs: ~[ast::ident], - tps: ~[@ast::Ty] - ) -> @ast::Path { - @ast::Path { - span: span, - global: false, - idents: strs, - rp: None, - types: tps + fn ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt { + ast::mt { + ty: ty, + mutbl: mutbl } } - fn path_tps_global( - &self, - span: span, - strs: ~[ast::ident], - tps: ~[@ast::Ty] - ) -> @ast::Path { - @ast::Path { + fn ty(&self, span: span, ty: ast::ty_) -> @ast::Ty { + @ast::Ty { + id: self.next_id(), span: span, - global: true, - idents: strs, - rp: None, - types: tps + node: ty } } fn ty_path(&self, path: @ast::Path) -> @ast::Ty { - self.mk_ty(path.span, - ast::ty_path(path, self.next_id())) + self.ty(path.span, + ast::ty_path(path, self.next_id())) + } + + fn ty_ident(&self, span: span, ident: ast::ident) + -> @ast::Ty { + self.ty_path(self.path_ident(span, ident)) + } + + fn ty_rptr(&self, + span: span, + ty: @ast::Ty, + lifetime: Option<@ast::Lifetime>, + mutbl: ast::mutability) + -> @ast::Ty { + self.ty(span, + ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl))) + } + fn ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty { + self.ty(span, ast::ty_uniq(self.ty_mt(ty, ast::m_imm))) + } + fn ty_box(&self, span: span, + ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty { + self.ty(span, ast::ty_box(self.ty_mt(ty, mutbl))) } fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { self.ty_path( - self.path_tps_global(dummy_sp(), - ~[ - self.ident_of("core"), - self.ident_of("option"), - self.ident_of("Option") - ], - ~[ ty ])) - } - - fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field { - spanned { - node: ast::ty_field_ { - ident: name, - mt: ast::mt { ty: ty, mutbl: ast::m_imm }, - }, - span: dummy_sp(), - } + self.path_all(dummy_sp(), + true, + ~[ + self.ident_of("core"), + self.ident_of("option"), + self.ident_of("Option") + ], + None, + ~[ ty ])) } - fn ty_infer(&self) -> @ast::Ty { - @ast::Ty { - id: self.next_id(), - node: ast::ty_infer, - span: dummy_sp(), - } + fn ty_field_imm(&self, span: span, name: ident, ty: @ast::Ty) -> ast::ty_field { + respan(span, + ast::ty_field_ { + ident: name, + mt: ast::mt { ty: ty, mutbl: ast::m_imm }, + }) } - fn ty_param(&self, id: ast::ident, bounds: @OptVec) - -> ast::TyParam - { - ast::TyParam { ident: id, id: self.next_id(), bounds: bounds } + fn ty_infer(&self, span: span) -> @ast::Ty { + self.ty(span, ast::ty_infer) } - fn ty_nil_ast_builder(&self) -> @ast::Ty { + fn ty_nil(&self) -> @ast::Ty { @ast::Ty { id: self.next_id(), node: ast::ty_nil, @@ -477,17 +325,22 @@ impl AstBuilder for @ExtCtxt { } } + fn typaram(&self, id: ast::ident, bounds: @OptVec) -> ast::TyParam { + ast::TyParam { ident: id, id: self.next_id(), bounds: bounds } + } + + // these are strange, and probably shouldn't be used outside of + // pipes. Specifically, the global version possible generates + // incorrect code. fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty] { opt_vec::take_vec( - ty_params.map(|p| self.ty_path( - self.mk_raw_path(dummy_sp(), ~[p.ident])))) + ty_params.map(|p| self.ty_ident(dummy_sp(), p.ident))) } - fn ty_vars_global(&self, - ty_params: &OptVec) -> ~[@ast::Ty] { + fn ty_vars_global(&self, ty_params: &OptVec) -> ~[@ast::Ty] { opt_vec::take_vec( ty_params.map(|p| self.ty_path( - self.mk_raw_path(dummy_sp(), ~[p.ident])))) + self.path_global(dummy_sp(), ~[p.ident])))) } fn strip_bounds(&self, generics: &Generics) -> Generics { @@ -501,52 +354,59 @@ impl AstBuilder for @ExtCtxt { } } + fn trait_ref(&self, path: @ast::Path) -> @ast::trait_ref { + @ast::trait_ref { + path: path, + ref_id: self.next_id() + } + } - fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt { - @codemap::spanned { node: ast::stmt_semi(expr, self.next_id()), - span: expr.span } + fn typarambound(&self, path: @ast::Path) -> ast::TyParamBound { + ast::TraitTyParamBound(self.trait_ref(path)) } - fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt { - let ext_cx = *self; - quote_stmt!( let $ident = $e; ) + fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime { + ast::Lifetime { id: self.next_id(), span: span, ident: ident } } - fn lit_str(&self, span: span, s: @~str) -> @ast::expr { - self.expr( - span, - ast::expr_vstore( - self.expr( - span, - ast::expr_lit( - @codemap::spanned { node: ast::lit_str(s), - span: span})), - ast::expr_vstore_uniq)) + fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt { + @respan(expr.span, ast::stmt_semi(expr, self.next_id())) } - fn lit_uint(&self, span: span, i: uint) -> @ast::expr { - self.expr( - span, - ast::expr_lit( - @codemap::spanned { node: ast::lit_uint(i as u64, ast::ty_u), - span: span})) + fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt { + let pat = self.pat_ident(sp, ident); + let local = @respan(sp, + ast::local_ { + is_mutbl: mutbl, + ty: self.ty_infer(sp), + pat: pat, + init: Some(ex), + id: self.next_id(), + }); + let decl = respan(sp, ast::decl_local(~[local])); + @respan(sp, ast::stmt_decl(@decl, self.next_id())) } fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: stmts, - expr: expr, - id: self.next_id(), - rules: ast::default_blk, - }, - span: span, - } + self.blk_all(span, ~[], stmts, expr) } fn blk_expr(&self, expr: @ast::expr) -> ast::blk { - self.blk(expr.span, ~[], Some(expr)) + self.blk_all(expr.span, ~[], ~[], Some(expr)) + } + fn blk_all(&self, + span: span, + view_items: ~[@ast::view_item], + stmts: ~[@ast::stmt], + expr: Option<@ast::expr>) -> ast::blk { + respan(span, + ast::blk_ { + view_items: view_items, + stmts: stmts, + expr: expr, + id: self.next_id(), + rules: ast::default_blk, + }) } fn expr(&self, span: span, node: ast::expr_) -> @ast::expr { @@ -558,126 +418,243 @@ impl AstBuilder for @ExtCtxt { } } - fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr { - self.expr(span, ast::expr_path(self.path(span, strs))) + fn expr_path(&self, path: @ast::Path) -> @ast::expr { + self.expr(path.span, ast::expr_path(path)) } - fn expr_path_global( - &self, - span: span, - strs: ~[ast::ident] - ) -> @ast::expr { - self.expr(span, ast::expr_path(self.path_global(span, strs))) + fn expr_ident(&self, span: span, id: ast::ident) -> @ast::expr { + self.expr_path(self.path_ident(span, id)) + } + fn expr_self(&self, span: span) -> @ast::expr { + self.expr(span, ast::expr_self) } - fn expr_var(&self, span: span, var: &str) -> @ast::expr { - self.expr_path(span, ~[self.ident_of(var)]) + fn expr_binary(&self, sp: span, op: ast::binop, + lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { + self.next_id(); // see ast_util::op_expr_callee_id + self.expr(sp, ast::expr_binary(op, lhs, rhs)) } - fn expr_self(&self, span: span) -> @ast::expr { - self.expr(span, ast::expr_self) + fn expr_deref(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.expr_unary(sp, ast::deref, e) + } + fn expr_unary(&self, sp: span, op: ast::unop, e: @ast::expr) + -> @ast::expr { + self.next_id(); // see ast_util::op_expr_callee_id + self.expr(sp, ast::expr_unary(op, e)) } - fn expr_field( - &self, - span: span, - expr: @ast::expr, - ident: ast::ident - ) -> @ast::expr { - self.expr(span, ast::expr_field(expr, ident, ~[])) + fn expr_copy(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.expr(sp, ast::expr_copy(e)) + } + fn expr_managed(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.expr_unary(sp, ast::box(ast::m_imm), e) } - fn expr_call( - &self, - span: span, - expr: @ast::expr, - args: ~[@ast::expr] - ) -> @ast::expr { - self.expr(span, ast::expr_call(expr, args, ast::NoSugar)) + fn expr_field_access(&self, sp: span, expr: @ast::expr, ident: ast::ident) -> @ast::expr { + self.expr(sp, ast::expr_field(expr, ident, ~[])) + } + fn expr_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.expr(sp, ast::expr_addr_of(ast::m_imm, e)) + } + fn expr_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.expr(sp, ast::expr_addr_of(ast::m_mutbl, e)) } - fn expr_method_call( - &self, - span: span, - expr: @ast::expr, - ident: ast::ident, - args: ~[@ast::expr] - ) -> @ast::expr { + fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) -> @ast::expr { + self.expr(span, ast::expr_call(expr, args, ast::NoSugar)) + } + fn expr_call_ident(&self, span: span, id: ast::ident, args: ~[@ast::expr]) -> @ast::expr { + self.expr(span, + ast::expr_call(self.expr_ident(span, id), args, ast::NoSugar)) + } + fn expr_call_global(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr { + let pathexpr = self.expr_path(self.path_global(sp, fn_path)); + self.expr_call(sp, pathexpr, args) + } + fn expr_method_call(&self, span: span, + expr: @ast::expr, + ident: ast::ident, + args: ~[@ast::expr]) -> @ast::expr { self.expr(span, ast::expr_method_call(expr, ident, ~[], args, ast::NoSugar)) } fn expr_blk(&self, b: ast::blk) -> @ast::expr { - self.expr(dummy_sp(), ast::expr_block(b)) + self.expr(b.span, ast::expr_block(b)) } - fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field { - spanned { - node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e }, - span: dummy_sp(), - } + fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field { + respan(span, ast::field_ { mutbl: ast::m_imm, ident: name, expr: e }) } - fn expr_struct(&self, path: @ast::Path, - fields: ~[ast::field]) -> @ast::expr { - @ast::expr { - id: self.next_id(), - callee_id: self.next_id(), - node: ast::expr_struct(path, fields, None), - span: dummy_sp() + fn expr_struct(&self, span: span, path: @ast::Path, fields: ~[ast::field]) -> @ast::expr { + self.expr(span, ast::expr_struct(path, fields, None)) + } + fn expr_struct_ident(&self, span: span, + id: ast::ident, fields: ~[ast::field]) -> @ast::expr { + self.expr_struct(span, self.path_ident(span, id), fields) + } + + fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr { + self.expr(sp, ast::expr_lit(@respan(sp, lit))) + } + fn expr_uint(&self, span: span, i: uint) -> @ast::expr { + self.expr_lit(span, ast::lit_uint(i as u64, ast::ty_u)) + } + fn expr_int(&self, sp: span, i: int) -> @ast::expr { + self.expr_lit(sp, ast::lit_int(i as i64, ast::ty_i)) + } + fn expr_u8(&self, sp: span, u: u8) -> @ast::expr { + self.expr_lit(sp, ast::lit_uint(u as u64, ast::ty_u8)) + } + fn expr_bool(&self, sp: span, value: bool) -> @ast::expr { + self.expr_lit(sp, ast::lit_bool(value)) + } + + fn expr_vstore(&self, sp: span, expr: @ast::expr, vst: ast::expr_vstore) -> @ast::expr { + self.expr(sp, ast::expr_vstore(expr, vst)) + } + fn expr_vec(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { + self.expr(sp, ast::expr_vec(exprs, ast::m_imm)) + } + fn expr_vec_uniq(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { + self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::expr_vstore_uniq) + } + fn expr_vec_slice(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { + self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::expr_vstore_slice) + } + fn expr_str(&self, sp: span, s: ~str) -> @ast::expr { + self.expr_lit(sp, ast::lit_str(@s)) + } + fn expr_str_uniq(&self, sp: span, s: ~str) -> @ast::expr { + self.expr_vstore(sp, self.expr_str(sp, s), ast::expr_vstore_uniq) + } + + + fn expr_unreachable(&self, span: span) -> @ast::expr { + let loc = self.codemap().lookup_char_pos(span.lo); + self.expr_call_global( + span, + ~[ + self.ident_of("core"), + self.ident_of("sys"), + self.ident_of("FailWithCause"), + self.ident_of("fail_with"), + ], + ~[ + self.expr_str(span, ~"internal error: entered unreachable code"), + self.expr_str(span, copy loc.file.name), + self.expr_uint(span, loc.line), + ]) + } + + + fn pat(&self, span: span, pat: ast::pat_) -> @ast::pat { + @ast::pat { id: self.next_id(), node: pat, span: span } + } + fn pat_wild(&self, span: span) -> @ast::pat { + self.pat(span, ast::pat_wild) + } + fn pat_lit(&self, span: span, expr: @ast::expr) -> @ast::pat { + self.pat(span, ast::pat_lit(expr)) + } + fn pat_ident(&self, span: span, ident: ast::ident) -> @ast::pat { + self.pat_ident_binding_mode(span, ident, ast::bind_by_copy) + } + + fn pat_ident_binding_mode(&self, + span: span, + ident: ast::ident, + bm: ast::binding_mode) -> @ast::pat { + let path = self.path_ident(span, ident); + let pat = ast::pat_ident(bm, path, None); + self.pat(span, pat) + } + fn pat_enum(&self, span: span, path: @ast::Path, subpats: ~[@ast::pat]) -> @ast::pat { + let pat = ast::pat_enum(path, Some(subpats)); + self.pat(span, pat) + } + fn pat_struct(&self, span: span, + path: @ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat { + let pat = ast::pat_struct(path, field_pats, false); + self.pat(span, pat) + } + + fn arm(&self, _span: span, pats: ~[@ast::pat], expr: @ast::expr) -> ast::arm { + ast::arm { + pats: pats, + guard: None, + body: self.blk_expr(expr) } } + fn arm_unreachable(&self, span: span) -> ast::arm { + self.arm(span, ~[self.pat_wild(span)], self.expr_unreachable(span)) + } + + fn expr_match(&self, span: span, arg: @ast::expr, arms: ~[ast::arm]) -> @expr { + self.expr(span, ast::expr_match(arg, arms)) + } - fn lambda0(&self, blk: ast::blk) -> @ast::expr { + fn expr_if(&self, span: span, + cond: @ast::expr, then: @ast::expr, els: Option<@ast::expr>) -> @ast::expr { + let els = els.map(|x| self.expr_blk(self.blk_expr(*x))); + self.expr(span, ast::expr_if(cond, self.blk_expr(then), els)) + } + + fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::blk) -> @ast::expr { + self.expr(span, ast::expr_fn_block(fn_decl, blk)) + } + fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::blk) -> @ast::expr { + let fn_decl = self.fn_decl( + ids.map(|id| self.arg(span, *id, self.ty_infer(span))), + self.ty_infer(span)); + + self.expr(span, ast::expr_fn_block(fn_decl, blk)) + } + fn lambda0(&self, _span: span, blk: ast::blk) -> @ast::expr { let ext_cx = *self; let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk)); - quote_expr!( || $blk_e ) + quote_expr!(|| $blk_e ) } - fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr { + fn lambda1(&self, _span: span, blk: ast::blk, ident: ast::ident) -> @ast::expr { let ext_cx = *self; let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk)); - quote_expr!( |$ident| $blk_e ) + quote_expr!(|$ident| $blk_e ) } - fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr { - self.lambda0(self.blk_expr(expr)) + fn lambda_expr(&self, span: span, ids: ~[ast::ident], expr: @ast::expr) -> @ast::expr { + self.lambda(span, ids, self.blk_expr(expr)) } - - fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) - -> @ast::expr { - self.lambda1(self.blk_expr(expr), ident) + fn lambda_expr_0(&self, span: span, expr: @ast::expr) -> @ast::expr { + self.lambda0(span, self.blk_expr(expr)) + } + fn lambda_expr_1(&self, span: span, expr: @ast::expr, ident: ast::ident) -> @ast::expr { + self.lambda1(span, self.blk_expr(expr), ident) } + fn lambda_stmts(&self, span: span, ids: ~[ast::ident], stmts: ~[@ast::stmt]) -> @ast::expr { + self.lambda(span, ids, self.blk(span, stmts, None)) + } fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr { - self.lambda0(self.blk(span, stmts, None)) + self.lambda0(span, self.blk(span, stmts, None)) } - - fn lambda_stmts_1(&self, - span: span, - stmts: ~[@ast::stmt], - ident: ast::ident) - -> @ast::expr { - self.lambda1(self.blk(span, stmts, None), ident) + fn lambda_stmts_1(&self, span: span, stmts: ~[@ast::stmt], ident: ast::ident) -> @ast::expr { + self.lambda1(span, self.blk(span, stmts, None), ident) } - - fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg { + fn arg(&self, span: span, ident: ast::ident, ty: @ast::Ty) -> ast::arg { + let arg_pat = self.pat_ident(span, ident); ast::arg { is_mutbl: false, ty: ty, - pat: @ast::pat { - id: self.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - ast_util::ident_to_path(dummy_sp(), name), - None), - span: dummy_sp(), - }, - id: self.next_id(), + pat: arg_pat, + id: self.next_id() } } - fn fn_decl(&self, inputs: ~[ast::arg], - output: @ast::Ty) -> ast::fn_decl { + // XXX unused self + fn fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { ast::fn_decl { inputs: inputs, output: output, @@ -685,37 +662,28 @@ impl AstBuilder for @ExtCtxt { } } - fn item(&self, name: ident, span: span, - node: ast::item_) -> @ast::item { - + fn item(&self, span: span, + name: ident, attrs: ~[ast::attribute], node: ast::item_) -> @ast::item { // XXX: Would be nice if our generated code didn't violate // Rust coding conventions - let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ { - style: ast::attr_outer, - value: @respan(dummy_sp(), - ast::meta_list(@~"allow", ~[ - @respan(dummy_sp(), - ast::meta_word( - @~"non_camel_case_types")) - ])), - is_sugared_doc: false - }); - @ast::item { ident: name, - attrs: ~[non_camel_case_attribute], + attrs: attrs, id: self.next_id(), node: node, vis: ast::public, span: span } } - fn item_fn_poly(&self, name: ident, + fn item_fn_poly(&self, + span: span, + name: ident, inputs: ~[ast::arg], output: @ast::Ty, generics: Generics, body: ast::blk) -> @ast::item { - self.item(name, - dummy_sp(), + self.item(span, + name, + ~[], ast::item_fn(self.fn_decl(inputs, output), ast::impure_fn, AbiSet::Rust(), @@ -724,59 +692,58 @@ impl AstBuilder for @ExtCtxt { } fn item_fn(&self, + span: span, name: ident, inputs: ~[ast::arg], output: @ast::Ty, body: ast::blk ) -> @ast::item { self.item_fn_poly( + span, name, inputs, output, ast_util::empty_generics(), - body - ) + body) } - fn variant(&self, name: ident, span: span, - tys: ~[@ast::Ty]) -> ast::variant { + fn variant(&self, span: span, name: ident, tys: ~[@ast::Ty]) -> ast::variant { let args = do tys.map |ty| { ast::variant_arg { ty: *ty, id: self.next_id() } }; - spanned { - node: ast::variant_ { - name: name, - attrs: ~[], - kind: ast::tuple_variant_kind(args), - id: self.next_id(), - disr_expr: None, - vis: ast::public - }, - span: span, - } + respan(span, + ast::variant_ { + name: name, + attrs: ~[], + kind: ast::tuple_variant_kind(args), + id: self.next_id(), + disr_expr: None, + vis: ast::public + }) } - fn item_enum_poly(&self, name: ident, span: span, + fn item_enum_poly(&self, span: span, name: ident, enum_definition: ast::enum_def, generics: Generics) -> @ast::item { - self.item(name, span, ast::item_enum(enum_definition, generics)) + self.item(span, name, ~[], ast::item_enum(enum_definition, generics)) } - fn item_enum(&self, name: ident, span: span, + fn item_enum(&self, span: span, name: ident, enum_definition: ast::enum_def) -> @ast::item { - self.item_enum_poly(name, span, enum_definition, + self.item_enum_poly(span, name, enum_definition, ast_util::empty_generics()) } fn item_struct( - &self, name: ident, + &self, span: span, + name: ident, struct_def: ast::struct_def ) -> @ast::item { self.item_struct_poly( - name, span, + name, struct_def, ast_util::empty_generics() ) @@ -784,574 +751,85 @@ impl AstBuilder for @ExtCtxt { fn item_struct_poly( &self, - name: ident, span: span, + name: ident, struct_def: ast::struct_def, generics: Generics ) -> @ast::item { - self.item(name, span, ast::item_struct(@struct_def, generics)) + self.item(span, name, ~[], ast::item_struct(@struct_def, generics)) } - fn item_mod(&self, name: ident, span: span, + fn item_mod(&self, span: span, name: ident, + attrs: ~[ast::attribute], + vi: ~[@ast::view_item], items: ~[@ast::item]) -> @ast::item { - - // XXX: Total hack: import `core::kinds::Owned` to work around a - // parser bug whereby `fn f` doesn't parse. - let vi = ast::view_item_use(~[ - @codemap::spanned { - node: ast::view_path_simple( - self.ident_of("Owned"), - self.mk_raw_path( - codemap::dummy_sp(), - ~[ - self.ident_of("core"), - self.ident_of("kinds"), - self.ident_of("Owned") - ] - ), - self.next_id() - ), - span: codemap::dummy_sp() - } - ]); - let vi = @ast::view_item { - node: vi, - attrs: ~[], - vis: ast::private, - span: codemap::dummy_sp() - }; - self.item( - name, span, + name, + attrs, ast::item_mod(ast::_mod { - view_items: ~[vi], + view_items: vi, items: items, }) ) } - fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty, + fn item_ty_poly(&self, span: span, name: ident, ty: @ast::Ty, generics: Generics) -> @ast::item { - self.item(name, span, ast::item_ty(ty, generics)) + self.item(span, name, ~[], ast::item_ty(ty, generics)) } - fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item { - self.item_ty_poly(name, span, ty, ast_util::empty_generics()) + fn item_ty(&self, span: span, name: ident, ty: @ast::Ty) -> @ast::item { + self.item_ty_poly(span, name, ty, ast_util::empty_generics()) } - - - - - - - fn mk_expr(&self, - sp: codemap::span, - expr: ast::expr_) - -> @ast::expr { - @ast::expr { - id: self.next_id(), - callee_id: self.next_id(), - node: expr, - span: sp, - } + fn attribute(&self, sp: span, mi: @ast::meta_item) -> ast::attribute { + respan(sp, + ast::attribute_ { + style: ast::attr_outer, + value: mi, + is_sugared_doc: false + }) } - fn mk_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr { - let sp_lit = @codemap::spanned { node: lit, span: sp }; - self.mk_expr( sp, ast::expr_lit(sp_lit)) + fn meta_word(&self, sp: span, w: ~str) -> @ast::meta_item { + @respan(sp, ast::meta_word(@w)) } - fn mk_int(&self, sp: span, i: int) -> @ast::expr { - let lit = ast::lit_int(i as i64, ast::ty_i); - return self.mk_lit( sp, lit); + fn meta_list(&self, sp: span, name: ~str, mis: ~[@ast::meta_item]) -> @ast::meta_item { + @respan(sp, ast::meta_list(@name, mis)) } - fn mk_uint(&self, sp: span, u: uint) -> @ast::expr { - let lit = ast::lit_uint(u as u64, ast::ty_u); - return self.mk_lit( sp, lit); - } - fn mk_u8(&self, sp: span, u: u8) -> @ast::expr { - let lit = ast::lit_uint(u as u64, ast::ty_u8); - return self.mk_lit( sp, lit); - } - fn mk_binary(&self, sp: span, op: ast::binop, - lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { - self.next_id(); // see ast_util::op_expr_callee_id - self.mk_expr( sp, ast::expr_binary(op, lhs, rhs)) + fn meta_name_value(&self, sp: span, name: ~str, value: ast::lit_) -> @ast::meta_item { + @respan(sp, ast::meta_name_value(@name, respan(sp, value))) } - fn mk_deref(&self, sp: span, e: @ast::expr) -> @ast::expr { - self.mk_unary( sp, ast::deref, e) - } - fn mk_unary(&self, sp: span, op: ast::unop, e: @ast::expr) - -> @ast::expr { - self.next_id(); // see ast_util::op_expr_callee_id - self.mk_expr( sp, ast::expr_unary(op, e)) - } - // XXX: unused self - fn mk_raw_path(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path { - self.mk_raw_path_(sp, idents, None, ~[]) - } - // XXX: unused self - fn mk_raw_path_(&self, sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) - -> @ast::Path { - @ast::Path { span: sp, - global: false, - idents: idents, - rp: rp, - types: types } - } - // XXX: unused self - fn mk_raw_path_global(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path { - self.mk_raw_path_global_(sp, idents, None, ~[]) - } - // XXX: unused self - fn mk_raw_path_global_(&self, sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) -> @ast::Path { - @ast::Path { span: sp, - global: true, - idents: idents, - rp: rp, - types: types } - } - fn mk_path_raw(&self, sp: span, path: @ast::Path)-> @ast::expr { - self.mk_expr( sp, ast::expr_path(path)) - } - fn mk_path(&self, sp: span, idents: ~[ast::ident]) - -> @ast::expr { - self.mk_path_raw( sp, self.mk_raw_path(sp, idents)) - } - fn mk_path_global(&self, sp: span, idents: ~[ast::ident]) - -> @ast::expr { - self.mk_path_raw( sp, self.mk_raw_path_global(sp, idents)) - } - fn mk_access_(&self, sp: span, p: @ast::expr, m: ast::ident) - -> @ast::expr { - self.mk_expr( sp, ast::expr_field(p, m, ~[])) - } - fn mk_access(&self, sp: span, p: ~[ast::ident], m: ast::ident) - -> @ast::expr { - let pathexpr = self.mk_path( sp, p); - return self.mk_access_( sp, pathexpr, m); - } - fn mk_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { - return self.mk_expr( sp, ast::expr_addr_of(ast::m_imm, e)); - } - fn mk_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { - return self.mk_expr( sp, ast::expr_addr_of(ast::m_mutbl, e)); - } - fn mk_method_call(&self, - sp: span, - rcvr_expr: @ast::expr, - method_ident: ast::ident, - args: ~[@ast::expr]) -> @ast::expr { - self.mk_expr( sp, ast::expr_method_call(rcvr_expr, method_ident, ~[], args, ast::NoSugar)) - } - fn mk_call_(&self, sp: span, fn_expr: @ast::expr, - args: ~[@ast::expr]) -> @ast::expr { - self.mk_expr( sp, ast::expr_call(fn_expr, args, ast::NoSugar)) - } - fn mk_call(&self, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { - let pathexpr = self.mk_path( sp, fn_path); - return self.mk_call_( sp, pathexpr, args); - } - fn mk_call_global(&self, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { - let pathexpr = self.mk_path_global( sp, fn_path); - return self.mk_call_( sp, pathexpr, args); - } - // e = expr, t = type - fn mk_base_vec_e(&self, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - let vecexpr = ast::expr_vec(exprs, ast::m_imm); - self.mk_expr( sp, vecexpr) - } - fn mk_vstore_e(&self, sp: span, expr: @ast::expr, - vst: ast::expr_vstore) -> - @ast::expr { - self.mk_expr( sp, ast::expr_vstore(expr, vst)) - } - fn mk_uniq_vec_e(&self, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - self.mk_vstore_e( sp, self.mk_base_vec_e( sp, exprs), ast::expr_vstore_uniq) - } - fn mk_slice_vec_e(&self, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - self.mk_vstore_e( sp, self.mk_base_vec_e( sp, exprs), - ast::expr_vstore_slice) - } - fn mk_base_str(&self, sp: span, s: ~str) -> @ast::expr { - let lit = ast::lit_str(@s); - return self.mk_lit( sp, lit); - } - fn mk_uniq_str(&self, sp: span, s: ~str) -> @ast::expr { - self.mk_vstore_e( sp, self.mk_base_str( sp, s), ast::expr_vstore_uniq) - } - // XXX: unused self - fn mk_field(&self, sp: span, f: &Field) -> ast::field { - codemap::spanned { - node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex }, - span: sp, + fn view_use(&self, sp: span, + vis: ast::visibility, vp: ~[@ast::view_path]) -> @ast::view_item { + @ast::view_item { + node: ast::view_item_use(vp), + attrs: ~[], + vis: vis, + span: sp } } - // XXX: unused self - fn mk_fields(&self, sp: span, fields: ~[Field]) -> ~[ast::field] { - fields.map(|f| self.mk_field(sp, f)) - } - fn mk_struct_e(&self, - sp: span, - ctor_path: ~[ast::ident], - fields: ~[Field]) - -> @ast::expr { - self.mk_expr( sp, - ast::expr_struct(self.mk_raw_path(sp, ctor_path), - self.mk_fields(sp, fields), - option::None::<@ast::expr>)) - } - fn mk_global_struct_e(&self, - sp: span, - ctor_path: ~[ast::ident], - fields: ~[Field]) - -> @ast::expr { - self.mk_expr( sp, - ast::expr_struct(self.mk_raw_path_global(sp, ctor_path), - self.mk_fields(sp, fields), - option::None::<@ast::expr>)) - } - fn mk_glob_use(&self, - sp: span, - vis: ast::visibility, - path: ~[ast::ident]) -> @ast::view_item { - let glob = @codemap::spanned { - node: ast::view_path_glob(self.mk_raw_path(sp, path), self.next_id()), - span: sp, - }; - @ast::view_item { node: ast::view_item_use(~[glob]), - attrs: ~[], - vis: vis, - span: sp } - } - fn mk_local(&self, sp: span, mutbl: bool, - ident: ast::ident, ex: @ast::expr) -> @ast::stmt { - let pat = @ast::pat { - id: self.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - self.mk_raw_path(sp, ~[ident]), - None), - span: sp, - }; - let ty = @ast::Ty { id: self.next_id(), node: ast::ty_infer, span: sp }; - let local = @codemap::spanned { - node: ast::local_ { - is_mutbl: mutbl, - ty: ty, - pat: pat, - init: Some(ex), - id: self.next_id(), - }, - span: sp, + fn view_use_list(&self, sp: span, vis: ast::visibility, + path: ~[ast::ident], imports: &[ast::ident]) -> @ast::view_item { + let imports = do imports.map |id| { + respan(sp, ast::path_list_ident_ { name: *id, id: self.next_id() }) }; - let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp}; - @codemap::spanned { node: ast::stmt_decl(@decl, self.next_id()), span: sp } - } - fn mk_block(&self, span: span, - view_items: ~[@ast::view_item], - stmts: ~[@ast::stmt], - expr: Option<@ast::expr>) -> @ast::expr { - let blk = codemap::spanned { - node: ast::blk_ { - view_items: view_items, - stmts: stmts, - expr: expr, - id: self.next_id(), - rules: ast::default_blk, - }, - span: span, - }; - self.mk_expr( span, ast::expr_block(blk)) - } - fn mk_block_(&self, - span: span, - stmts: ~[@ast::stmt]) - -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: stmts, - expr: None, - id: self.next_id(), - rules: ast::default_blk, - }, - span: span, - } - } - fn mk_simple_block(&self, - span: span, - expr: @ast::expr) - -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: ~[], - expr: Some(expr), - id: self.next_id(), - rules: ast::default_blk, - }, - span: span, - } - } - fn mk_lambda_(&self, - span: span, - fn_decl: ast::fn_decl, - blk: ast::blk) - -> @ast::expr { - self.mk_expr( span, ast::expr_fn_block(fn_decl, blk)) - } - fn mk_lambda(&self, - span: span, - fn_decl: ast::fn_decl, - expr: @ast::expr) - -> @ast::expr { - let blk = self.mk_simple_block( span, expr); - self.mk_lambda_( span, fn_decl, blk) - } - fn mk_lambda_stmts(&self, - span: span, - fn_decl: ast::fn_decl, - stmts: ~[@ast::stmt]) - -> @ast::expr { - let blk = self.mk_block( span, ~[], stmts, None); - self.mk_lambda( span, fn_decl, blk) - } - fn mk_lambda_no_args(&self, - span: span, - expr: @ast::expr) - -> @ast::expr { - let fn_decl = self.mk_fn_decl(~[], self.mk_ty_infer( span)); - self.mk_lambda( span, fn_decl, expr) - } - fn mk_copy(&self, sp: span, e: @ast::expr) -> @ast::expr { - self.mk_expr( sp, ast::expr_copy(e)) - } - fn mk_managed(&self, sp: span, e: @ast::expr) -> @ast::expr { - self.mk_expr( sp, ast::expr_unary(ast::box(ast::m_imm), e)) - } - fn mk_pat(&self, span: span, pat: ast::pat_) -> @ast::pat { - @ast::pat { id: self.next_id(), node: pat, span: span } - } - fn mk_pat_wild(&self, span: span) -> @ast::pat { - self.mk_pat( span, ast::pat_wild) - } - fn mk_pat_lit(&self, - span: span, - expr: @ast::expr) -> @ast::pat { - self.mk_pat( span, ast::pat_lit(expr)) - } - fn mk_pat_ident(&self, - span: span, - ident: ast::ident) -> @ast::pat { - self.mk_pat_ident_with_binding_mode( span, ident, ast::bind_by_copy) - } - - fn mk_pat_ident_with_binding_mode(&self, - span: span, - ident: ast::ident, - bm: ast::binding_mode) -> @ast::pat { - let path = self.mk_raw_path(span, ~[ ident ]); - let pat = ast::pat_ident(bm, path, None); - self.mk_pat( span, pat) - } - fn mk_pat_enum(&self, - span: span, - path: @ast::Path, - subpats: ~[@ast::pat]) - -> @ast::pat { - let pat = ast::pat_enum(path, Some(subpats)); - self.mk_pat( span, pat) - } - fn mk_pat_struct(&self, - span: span, - path: @ast::Path, - field_pats: ~[ast::field_pat]) - -> @ast::pat { - let pat = ast::pat_struct(path, field_pats, false); - self.mk_pat( span, pat) - } - fn mk_bool(&self, span: span, value: bool) -> @ast::expr { - let lit_expr = ast::expr_lit(@codemap::spanned { - node: ast::lit_bool(value), - span: span }); - self.mk_expr( span, lit_expr) - } - fn mk_stmt(&self, span: span, expr: @ast::expr) -> @ast::stmt { - let stmt_ = ast::stmt_semi(expr, self.next_id()); - @codemap::spanned { node: stmt_, span: span } - } - - // XXX: unused self - fn mk_ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt { - ast::mt { - ty: ty, - mutbl: mutbl - } - } - - fn mk_ty(&self, - span: span, - ty: ast::ty_) -> @ast::Ty { - @ast::Ty { - id: self.next_id(), - span: span, - node: ty - } - } - - fn mk_ty_path(&self, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty { - let ty = self.mk_raw_path(span, idents); - self.mk_ty_path_path( span, ty) - } - fn mk_ty_path_global(&self, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty { - let ty = self.mk_raw_path_global(span, idents); - self.mk_ty_path_path( span, ty) - } - - fn mk_ty_path_path(&self, - span: span, - path: @ast::Path) - -> @ast::Ty { - let ty = ast::ty_path(path, self.next_id()); - self.mk_ty( span, ty) - } - - fn mk_ty_rptr(&self, - span: span, - ty: @ast::Ty, - lifetime: Option<@ast::Lifetime>, - mutbl: ast::mutability) - -> @ast::Ty { - self.mk_ty( span, - ast::ty_rptr(lifetime, self.mk_ty_mt(ty, mutbl))) - } - fn mk_ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty { - self.mk_ty( span, ast::ty_uniq(self.mk_ty_mt(ty, ast::m_imm))) - } - fn mk_ty_box(&self, span: span, - ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty { - self.mk_ty( span, ast::ty_box(self.mk_ty_mt(ty, mutbl))) - } - - - - fn mk_ty_infer(&self, span: span) -> @ast::Ty { - self.mk_ty( span, ast::ty_infer) - } - fn mk_trait_ref_global(&self, - span: span, - idents: ~[ ast::ident ]) - -> @ast::trait_ref - { - self.mk_trait_ref_( self.mk_raw_path_global(span, idents)) - } - fn mk_trait_ref_(&self, path: @ast::Path) -> @ast::trait_ref { - @ast::trait_ref { - path: path, - ref_id: self.next_id() - } - } - fn mk_simple_ty_path(&self, - span: span, - ident: ast::ident) - -> @ast::Ty { - self.mk_ty_path( span, ~[ ident ]) - } - fn mk_arg(&self, - span: span, - ident: ast::ident, - ty: @ast::Ty) - -> ast::arg { - let arg_pat = self.mk_pat_ident( span, ident); - ast::arg { - is_mutbl: false, - ty: ty, - pat: arg_pat, - id: self.next_id() - } - } - // XXX unused self - fn mk_fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { - ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val } - } - fn mk_trait_ty_param_bound_global(&self, - span: span, - idents: ~[ast::ident]) - -> ast::TyParamBound { - ast::TraitTyParamBound(self.mk_trait_ref_global( span, idents)) - } - fn mk_trait_ty_param_bound_(&self, - path: @ast::Path) -> ast::TyParamBound { - ast::TraitTyParamBound(self.mk_trait_ref_( path)) - } - fn mk_ty_param(&self, - ident: ast::ident, - bounds: @OptVec) - -> ast::TyParam { - ast::TyParam { ident: ident, id: self.next_id(), bounds: bounds } - } - fn mk_lifetime(&self, - span: span, - ident: ast::ident) - -> ast::Lifetime { - ast::Lifetime { id: self.next_id(), span: span, ident: ident } - } - fn mk_arm(&self, - span: span, - pats: ~[@ast::pat], - expr: @ast::expr) - -> ast::arm { - ast::arm { - pats: pats, - guard: None, - body: self.mk_simple_block( span, expr) - } - } - fn mk_unreachable(&self, span: span) -> @ast::expr { - let loc = self.codemap().lookup_char_pos(span.lo); - self.mk_call_global( - span, - ~[ - self.ident_of("core"), - self.ident_of("sys"), - self.ident_of("FailWithCause"), - self.ident_of("fail_with"), - ], - ~[ - self.mk_base_str( span, ~"internal error: entered unreachable code"), - self.mk_base_str( span, copy loc.file.name), - self.mk_uint( span, loc.line), - ] - ) - } - fn mk_unreachable_arm(&self, span: span) -> ast::arm { - self.mk_arm( span, ~[self.mk_pat_wild( span)], self.mk_unreachable( span)) + self.view_use(sp, vis, + ~[@respan(sp, + ast::view_path_list(self.path(sp, path), + imports, + self.next_id()))]) } - fn make_self(&self, span: span) -> @ast::expr { - self.mk_expr( span, ast::expr_self) + fn view_use_glob(&self, sp: span, + vis: ast::visibility, path: ~[ast::ident]) -> @ast::view_item { + self.view_use(sp, vis, + ~[@respan(sp, + ast::view_path_glob(self.path(sp, path), self.next_id()))]) } } diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index cdc6e267cccba..a046395b6f5c8 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -28,7 +28,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas // string literal, push each byte to vector expression ast::lit_str(s) => { for s.each |byte| { - bytes.push(cx.mk_u8(sp, byte)); + bytes.push(cx.expr_u8(sp, byte)); } } @@ -37,7 +37,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas if v > 0xFF { cx.span_err(sp, "Too large u8 literal in bytes!") } else { - bytes.push(cx.mk_u8(sp, v as u8)); + bytes.push(cx.expr_u8(sp, v as u8)); } } @@ -48,14 +48,14 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas } else if v < 0 { cx.span_err(sp, "Negative integer literal in bytes!") } else { - bytes.push(cx.mk_u8(sp, v as u8)); + bytes.push(cx.expr_u8(sp, v as u8)); } } // char literal, push to vector expression ast::lit_int(v, ast::ty_char) => { if (v as char).is_ascii() { - bytes.push(cx.mk_u8(sp, v as u8)); + bytes.push(cx.expr_u8(sp, v as u8)); } else { cx.span_err(sp, "Non-ascii char literal in bytes!") } @@ -68,6 +68,6 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas } } - let e = cx.mk_slice_vec_e(sp, bytes); + let e = cx.expr_vec_slice(sp, bytes); MRExpr(e) } diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 07aead9588ac1..007826a84165d 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -11,7 +11,6 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; use ext::build::AstBuilder; use ext::deriving::generic::*; @@ -80,15 +79,15 @@ fn cs_clone( let ctor_ident; let all_fields; let subcall = |field| - cx.mk_method_call(span, field, clone_ident, ~[]); + cx.expr_method_call(span, field, clone_ident, ~[]); match *substr.fields { Struct(ref af) => { - ctor_ident = ~[ substr.type_ident ]; + ctor_ident = substr.type_ident; all_fields = af; } EnumMatching(_, variant, ref af) => { - ctor_ident = ~[ variant.node.name ]; + ctor_ident = variant.node.name; all_fields = af; }, EnumNonMatching(*) => cx.span_bug(span, @@ -103,7 +102,7 @@ fn cs_clone( [(None, _, _), .. _] => { // enum-like let subcalls = all_fields.map(|&(_, self_f, _)| subcall(self_f)); - cx.mk_call(span, ctor_ident, subcalls) + cx.expr_call_ident(span, ctor_ident, subcalls) }, _ => { // struct-like @@ -114,16 +113,14 @@ fn cs_clone( fmt!("unnamed field in normal struct in `deriving(%s)`", name)) }; - build::Field { ident: ident, ex: subcall(self_f) } + cx.field_imm(span, ident, subcall(self_f)) }; if fields.is_empty() { // no fields, so construct like `None` - cx.mk_path(span, ctor_ident) + cx.expr_ident(span, ctor_ident) } else { - cx.mk_struct_e(span, - ctor_ident, - fields) + cx.expr_struct_ident(span, ctor_ident, fields) } } } diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 1af6640448977..11c0a597cebab 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -21,11 +21,11 @@ pub fn expand_deriving_eq(cx: @ExtCtxt, // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different fn cs_eq(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_and(|cx, span, _, _| cx.mk_bool(span, false), + cs_and(|cx, span, _, _| cx.expr_bool(span, false), cx, span, substr) } fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_or(|cx, span, _, _| cx.mk_bool(span, true), + cs_or(|cx, span, _, _| cx.expr_bool(span, true), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 41b5bf63aca34..9438e1b0f858d 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -9,7 +9,7 @@ // except according to those terms. -use ast::{meta_item, item, expr_if, expr}; +use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -62,10 +62,7 @@ fn cs_ord(less: bool, equal: bool, } else { cx.ident_of("gt") }; - let false_blk_expr = cx.mk_block(span, - ~[], ~[], - Some(cx.mk_bool(span, false))); - let base = cx.mk_bool(span, equal); + let base = cx.expr_bool(span, equal); cs_fold( false, // need foldr, @@ -98,19 +95,15 @@ fn cs_ord(less: bool, equal: bool, cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`"); } - let cmp = cx.mk_method_call(span, - self_f, cx.ident_of("eq"), other_fs.to_owned()); - let subexpr = cx.mk_simple_block(span, subexpr); - let elseif = expr_if(cmp, subexpr, Some(false_blk_expr)); - let elseif = cx.mk_expr(span, elseif); + let cmp = cx.expr_method_call(span, + self_f, cx.ident_of("eq"), other_fs.to_owned()); + let elseif = cx.expr_if(span, cmp, + subexpr, Some(cx.expr_bool(span, false))); - let cmp = cx.mk_method_call(span, - self_f, binop, other_fs.to_owned()); - let true_blk = cx.mk_simple_block(span, - cx.mk_bool(span, true)); - let if_ = expr_if(cmp, true_blk, Some(elseif)); - - cx.mk_expr(span, if_) + let cmp = cx.expr_method_call(span, + self_f, binop, other_fs.to_owned()); + cx.expr_if(span, cmp, + cx.expr_bool(span, true), Some(elseif)) }, base, |cx, span, args, _| { @@ -119,7 +112,7 @@ fn cs_ord(less: bool, equal: bool, match args { [(self_var, _, _), (other_var, _, _)] => - cx.mk_bool(span, + cx.expr_bool(span, if less { self_var < other_var } else { diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 48393efce6487..f1e952eb5f63c 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -21,7 +21,7 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt, in_items: ~[@item]) -> ~[@item] { fn cs_equals(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_and(|cx, span, _, _| cx.mk_bool(span, false), + cs_and(|cx, span, _, _| cx.expr_bool(span, false), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 3404a21edd0de..e26f4a34304cb 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -47,10 +47,11 @@ pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr { Equal => "Equal", Greater => "Greater" }; - cx.mk_path_global(span, - ~[cx.ident_of("core"), - cx.ident_of("cmp"), - cx.ident_of(cnst)]) + cx.expr_path( + cx.path_global(span, + ~[cx.ident_of("core"), + cx.ident_of("cmp"), + cx.ident_of(cnst)])) } pub fn cs_cmp(cx: @ExtCtxt, span: span, @@ -60,11 +61,11 @@ pub fn cs_cmp(cx: @ExtCtxt, span: span, // foldr (possibly) nests the matches in lexical_ordering better false, |cx, span, old, new| { - cx.mk_call_global(span, - ~[cx.ident_of("core"), - cx.ident_of("cmp"), - cx.ident_of("lexical_ordering")], - ~[old, new]) + cx.expr_call_global(span, + ~[cx.ident_of("core"), + cx.ident_of("cmp"), + cx.ident_of("lexical_ordering")], + ~[old, new]) }, ordering_const(cx, span, Equal), |cx, span, list, _| { diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 781ac9814ec9b..a8c84e8e361e5 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -16,7 +16,6 @@ encodable.rs for more. use ast; use ast::*; use ext::base::ExtCtxt; -use ext::build::Field; use ext::build::AstBuilder; use ext::deriving::*; use codemap::{span, spanned}; @@ -45,26 +44,25 @@ fn create_derived_decodable_impl( generics: &Generics, method: @method ) -> @item { - let decoder_ty_param = cx.mk_ty_param( + let decoder_ty_param = cx.typaram( cx.ident_of("__D"), @opt_vec::with( - cx.mk_trait_ty_param_bound_global( - span, - ~[ - cx.ident_of("std"), - cx.ident_of("serialize"), - cx.ident_of("Decoder"), - ] - ) - ) - ); + cx.typarambound( + cx.path_global( + span, + ~[ + cx.ident_of("std"), + cx.ident_of("serialize"), + cx.ident_of("Decoder"), + ])))); // All the type parameters need to bound to the trait. let generic_ty_params = opt_vec::with(decoder_ty_param); let methods = [method]; - let trait_path = cx.mk_raw_path_global_( + let trait_path = cx.path_all( span, + true, ~[ cx.ident_of("std"), cx.ident_of("serialize"), @@ -72,7 +70,7 @@ fn create_derived_decodable_impl( ], None, ~[ - cx.mk_simple_ty_path(span, cx.ident_of("__D")) + cx.ty_ident(span, cx.ident_of("__D")) ] ); create_derived_impl( @@ -97,14 +95,14 @@ fn create_decode_method( expr: @ast::expr ) -> @method { // Create the `e` parameter. - let d_arg_type = cx.mk_ty_rptr( + let d_arg_type = cx.ty_rptr( span, - cx.mk_simple_ty_path(span, cx.ident_of("__D")), + cx.ty_ident(span, cx.ident_of("__D")), None, ast::m_mutbl ); let d_ident = cx.ident_of("__d"); - let d_arg = cx.mk_arg(span, d_ident, d_arg_type); + let d_arg = cx.arg(span, d_ident, d_arg_type); // Create the type of the return value. let output_type = create_self_type_with_params( @@ -116,10 +114,10 @@ fn create_decode_method( // Create the function declaration. let inputs = ~[d_arg]; - let fn_decl = cx.mk_fn_decl(inputs, output_type); + let fn_decl = cx.fn_decl(inputs, output_type); // Create the body block. - let body_block = cx.mk_simple_block(span, expr); + let body_block = cx.blk_expr(expr); // Create the method. let explicit_self = spanned { node: sty_static, span: span }; @@ -144,19 +142,21 @@ fn call_substructure_decode_method( span: span ) -> @ast::expr { // Call the substructure method. - cx.mk_call_( + cx.expr_call( span, - cx.mk_path_global( - span, - ~[ - cx.ident_of("std"), - cx.ident_of("serialize"), - cx.ident_of("Decodable"), - cx.ident_of("decode"), - ] + cx.expr_path( + cx.path_global( + span, + ~[ + cx.ident_of("std"), + cx.ident_of("serialize"), + cx.ident_of("Decodable"), + cx.ident_of("decode"), + ] + ) ), ~[ - cx.mk_path(span, ~[cx.ident_of("__d")]) + cx.expr_ident(span, cx.ident_of("__d")) ] ) } @@ -218,31 +218,24 @@ fn create_read_struct_field( span: span, idx: uint, ident: ident -) -> Field { +) -> ast::field { // Call the substructure method. let decode_expr = call_substructure_decode_method(cx, span); - let d_arg = cx.mk_arg( - span, - cx.ident_of("__d"), - cx.mk_ty_infer(span)); + let d_id = cx.ident_of("__d"); - let call_expr = cx.mk_method_call( + let call_expr = cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__d")]), + cx.expr_ident(span, d_id), cx.ident_of("read_struct_field"), ~[ - cx.mk_base_str(span, cx.str_of(ident)), - cx.mk_uint(span, idx), - cx.mk_lambda( - span, - cx.mk_fn_decl(~[d_arg], - cx.mk_ty_infer(span)), - decode_expr), + cx.expr_str(span, cx.str_of(ident)), + cx.expr_uint(span, idx), + cx.lambda_expr_1(span, decode_expr, d_id) ] ); - Field { ident: ident, ex: call_expr } + cx.field_imm(span, ident, call_expr) } fn create_read_struct_arg( @@ -250,21 +243,21 @@ fn create_read_struct_arg( span: span, idx: uint, ident: ident -) -> Field { +) -> ast::field { // Call the substructure method. let decode_expr = call_substructure_decode_method(cx, span); - let call_expr = cx.mk_method_call( + let call_expr = cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__d")]), + cx.expr_ident(span, cx.ident_of("__d")), cx.ident_of("read_struct_arg"), ~[ - cx.mk_uint(span, idx), - cx.mk_lambda_no_args(span, decode_expr), + cx.expr_uint(span, idx), + cx.lambda_expr_0(span, decode_expr), ] ); - Field { ident: ident, ex: call_expr } + cx.field_imm(span, ident, call_expr) } fn expand_deriving_decodable_struct_method( @@ -292,30 +285,19 @@ fn expand_deriving_decodable_struct_method( i += 1; } - let d_arg = cx.mk_arg( - span, - cx.ident_of("__d"), - cx.mk_ty_infer(span)); + let d_id = cx.ident_of("__d"); - let read_struct_expr = cx.mk_method_call( + let read_struct_expr = cx.expr_method_call( span, - cx.mk_path( - span, - ~[cx.ident_of("__d")] - ), + cx.expr_ident(span, d_id), cx.ident_of("read_struct"), ~[ - cx.mk_base_str(span, cx.str_of(type_ident)), - cx.mk_uint(span, fields.len()), - cx.mk_lambda( + cx.expr_str(span, cx.str_of(type_ident)), + cx.expr_uint(span, fields.len()), + cx.lambda_expr_1( span, - cx.mk_fn_decl(~[d_arg], cx.mk_ty_infer(span)), - cx.mk_struct_e( - span, - ~[type_ident], - fields - ) - ), + cx.expr_struct_ident(span, type_ident, fields), + d_id) ] ); @@ -330,14 +312,14 @@ fn create_read_variant_arg( variant: &ast::variant ) -> ast::arm { // Create the matching pattern. - let pat = cx.mk_pat_lit(span, cx.mk_uint(span, idx)); + let pat = cx.pat_lit(span, cx.expr_uint(span, idx)); // Feed each argument in this variant to the decode function // as well. let variant_arg_len = variant_arg_count(cx, span, variant); let expr = if variant_arg_len == 0 { - cx.mk_path(span, ~[variant.node.name]) + cx.expr_ident(span, variant.node.name) } else { // Feed the discriminant to the decode function. let mut args = ~[]; @@ -346,37 +328,26 @@ fn create_read_variant_arg( // Call the substructure method. let expr = call_substructure_decode_method(cx, span); - let d_arg = cx.mk_arg( - span, - cx.ident_of("__d"), - cx.mk_ty_infer(span)); - let t_infer = cx.mk_ty_infer(span); + let d_id = cx.ident_of("__d"); - let call_expr = cx.mk_method_call( + let call_expr = cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__d")]), + cx.expr_ident(span, d_id), cx.ident_of("read_enum_variant_arg"), ~[ - cx.mk_uint(span, j), - cx.mk_lambda( - span, - cx.mk_fn_decl(~[d_arg], t_infer), - expr), + cx.expr_uint(span, j), + cx.lambda_expr_1(span, expr, d_id), ] ); args.push(call_expr); } - cx.mk_call( - span, - ~[variant.node.name], - args - ) + cx.expr_call_ident(span, variant.node.name, args) }; // Create the arm. - cx.mk_arm(span, ~[pat], expr) + cx.arm(span, ~[pat], expr) } fn create_read_enum_variant( @@ -385,10 +356,10 @@ fn create_read_enum_variant( enum_definition: &enum_def ) -> @expr { // Create a vector that contains all the variant names. - let expr_arm_names = cx.mk_base_vec_e( + let expr_arm_names = cx.expr_vec( span, do enum_definition.variants.map |variant| { - cx.mk_base_str( + cx.expr_str( span, cx.str_of(variant.node.name) ) @@ -401,40 +372,18 @@ fn create_read_enum_variant( }; // Add the impossible case arm. - arms.push(cx.mk_unreachable_arm(span)); + arms.push(cx.arm_unreachable(span)); // Create the read_enum_variant expression. - cx.mk_method_call( + cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__d")]), + cx.expr_ident(span, cx.ident_of("__d")), cx.ident_of("read_enum_variant"), ~[ expr_arm_names, - cx.mk_lambda( - span, - cx.mk_fn_decl( - ~[ - cx.mk_arg( - span, - cx.ident_of("__d"), - cx.mk_ty_infer(span) - ), - cx.mk_arg( - span, - cx.ident_of("__i"), - cx.mk_ty_infer(span) - ) - ], - cx.mk_ty_infer(span) - ), - cx.mk_expr( - span, - ast::expr_match( - cx.mk_path(span, ~[cx.ident_of("__i")]), - arms - ) - ) - ) + cx.lambda_expr(span, + ~[cx.ident_of("__d"), cx.ident_of("__i")], + cx.expr_match(span, cx.expr_ident(span, cx.ident_of("__i")), arms)) ] ) } @@ -452,23 +401,16 @@ fn expand_deriving_decodable_enum_method( enum_definition ); - let d_arg = cx.mk_arg( - span, - cx.ident_of("__d"), - cx.mk_ty_infer(span)); + let d_id = cx.ident_of("__d"); // Create the read_enum expression - let read_enum_expr = cx.mk_method_call( + let read_enum_expr = cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__d")]), + cx.expr_ident(span, d_id), cx.ident_of("read_enum"), ~[ - cx.mk_base_str(span, cx.str_of(type_ident)), - cx.mk_lambda( - span, - cx.mk_fn_decl(~[d_arg], - cx.mk_ty_infer(span)), - read_enum_variant_expr), + cx.expr_str(span, cx.str_of(type_ident)), + cx.lambda_expr_1(span, read_enum_variant_expr, d_id) ] ); diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index eda1909aed4cb..72a1745f902be 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -107,26 +107,25 @@ fn create_derived_encodable_impl( generics: &Generics, method: @method ) -> @item { - let encoder_ty_param = cx.mk_ty_param( + let encoder_ty_param = cx.typaram( cx.ident_of("__E"), @opt_vec::with( - cx.mk_trait_ty_param_bound_global( - span, - ~[ - cx.ident_of("std"), - cx.ident_of("serialize"), - cx.ident_of("Encoder"), - ] - ) - ) - ); + cx.typarambound( + cx.path_global( + span, + ~[ + cx.ident_of("std"), + cx.ident_of("serialize"), + cx.ident_of("Encoder"), + ])))); // All the type parameters need to bound to the trait. let generic_ty_params = opt_vec::with(encoder_ty_param); let methods = [method]; - let trait_path = cx.mk_raw_path_global_( + let trait_path = cx.path_all( span, + true, ~[ cx.ident_of("std"), cx.ident_of("serialize"), @@ -134,7 +133,7 @@ fn create_derived_encodable_impl( ], None, ~[ - cx.mk_simple_ty_path(span, cx.ident_of("__E")) + cx.ty_ident(span, cx.ident_of("__E")) ] ); create_derived_impl( @@ -157,23 +156,23 @@ fn create_encode_method( statements: ~[@stmt] ) -> @method { // Create the `e` parameter. - let e_arg_type = cx.mk_ty_rptr( + let e_arg_type = cx.ty_rptr( span, - cx.mk_simple_ty_path(span, cx.ident_of("__E")), + cx.ty_ident(span, cx.ident_of("__E")), None, ast::m_mutbl ); - let e_arg = cx.mk_arg(span, cx.ident_of("__e"), e_arg_type); + let e_arg = cx.arg(span, cx.ident_of("__e"), e_arg_type); // Create the type of the return value. - let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span }; + let output_type = cx.ty_nil(); // Create the function declaration. let inputs = ~[e_arg]; - let fn_decl = cx.mk_fn_decl(inputs, output_type); + let fn_decl = cx.fn_decl(inputs, output_type); // Create the body block. - let body_block = cx.mk_block_(span, statements); + let body_block = cx.blk(span, statements, None); // Create the method. let explicit_self = spanned { node: sty_region(None, m_imm), span: span }; @@ -200,11 +199,11 @@ fn call_substructure_encode_method( ) -> @ast::expr { // Gather up the parameters we want to chain along. let e_ident = cx.ident_of("__e"); - let e_expr = cx.mk_path(span, ~[e_ident]); + let e_expr = cx.expr_ident(span, e_ident); // Call the substructure method. let encode_ident = cx.ident_of("encode"); - cx.mk_method_call( + cx.expr_method_call( span, self_field, encode_ident, @@ -275,10 +274,9 @@ fn expand_deriving_encodable_struct_method( match struct_field.node.kind { named_field(ident, _) => { // Create the accessor for this field. - let self_field = cx.mk_access_( - span, - cx.make_self(span), - ident); + let self_field = cx.expr_field_access(span, + cx.expr_self(span), + ident); // Call the substructure method. let encode_expr = call_substructure_encode_method( @@ -288,29 +286,19 @@ fn expand_deriving_encodable_struct_method( ); let e_ident = cx.ident_of("__e"); - let e_arg = cx.mk_arg( - span, - e_ident, - cx.mk_ty_infer(span)); - let blk_expr = cx.mk_lambda( + let call_expr = cx.expr_method_call( span, - cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), - encode_expr - ); - - let call_expr = cx.mk_method_call( - span, - cx.mk_path(span, ~[cx.ident_of("__e")]), + cx.expr_ident(span, e_ident), cx.ident_of("emit_struct_field"), ~[ - cx.mk_base_str(span, cx.str_of(ident)), - cx.mk_uint(span, idx), - blk_expr + cx.expr_str(span, cx.str_of(ident)), + cx.expr_uint(span, idx), + cx.lambda_expr_1(span, encode_expr, e_ident) ] ); - statements.push(cx.mk_stmt(span, call_expr)); + statements.push(cx.stmt_expr(call_expr)); } unnamed_field => { cx.span_unimpl( @@ -322,30 +310,19 @@ fn expand_deriving_encodable_struct_method( idx += 1; } - let e_arg = cx.mk_arg( - span, - cx.ident_of("__e"), - cx.mk_ty_infer(span)); - - let emit_struct_stmt = cx.mk_method_call( + let e_id = cx.ident_of("__e"); + let emit_struct_stmt = cx.expr_method_call( span, - cx.mk_path( - span, - ~[cx.ident_of("__e")] - ), + cx.expr_ident(span, e_id), cx.ident_of("emit_struct"), ~[ - cx.mk_base_str(span, cx.str_of(type_ident)), - cx.mk_uint(span, statements.len()), - cx.mk_lambda_stmts( - span, - cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), - statements - ), + cx.expr_str(span, cx.str_of(type_ident)), + cx.expr_uint(span, statements.len()), + cx.lambda_stmts_1(span, statements, e_id), ] ); - let statements = ~[cx.mk_stmt(span, emit_struct_stmt)]; + let statements = ~[cx.stmt_expr(emit_struct_stmt)]; // Create the method itself. return create_encode_method(cx, span, statements); @@ -373,85 +350,59 @@ fn expand_deriving_encodable_enum_method( let expr = call_substructure_encode_method(cx, span, field); let e_ident = cx.ident_of("__e"); - let e_arg = cx.mk_arg( - span, - e_ident, - cx.mk_ty_infer(span)); - - let blk_expr = cx.mk_lambda( - span, - cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), - expr - ); - - let call_expr = cx.mk_method_call( + let call_expr = cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__e")]), + cx.expr_ident(span, e_ident), cx.ident_of("emit_enum_variant_arg"), ~[ - cx.mk_uint(span, j), - blk_expr, + cx.expr_uint(span, j), + cx.lambda_expr_1(span, expr, e_ident), ] ); - stmts.push(cx.mk_stmt(span, call_expr)); + stmts.push(cx.stmt_expr(call_expr)); } // Create the pattern body. - let e_arg = cx.mk_arg( - span, - cx.ident_of("__e"), - cx.mk_ty_infer(span)); - let call_expr = cx.mk_method_call( + let e_id = cx.ident_of("__e"); + + let call_expr = cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__e")]), + cx.expr_ident(span, e_id), cx.ident_of("emit_enum_variant"), ~[ - cx.mk_base_str(span, cx.str_of(variant.node.name)), - cx.mk_uint(span, i), - cx.mk_uint(span, variant_arg_len), - cx.mk_lambda_stmts( - span, - cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), - stmts - ) + cx.expr_str(span, cx.str_of(variant.node.name)), + cx.expr_uint(span, i), + cx.expr_uint(span, variant_arg_len), + cx.lambda_stmts_1(span, stmts, e_id) ] ); - let match_body_block = cx.mk_simple_block(span, call_expr); + //let match_body_block = cx.blk_expr(call_expr); // Create the arm. - ast::arm { - pats: ~[pat], - guard: None, - body: match_body_block, - } + cx.arm(span, ~[pat], call_expr) //match_body_block) }; let e_ident = cx.ident_of("__e"); - let e_arg = cx.mk_arg( - span, - e_ident, - cx.mk_ty_infer(span)); // Create the method body. - let lambda_expr = cx.mk_lambda( + let lambda_expr = cx.lambda_expr_1( span, - cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), - expand_enum_or_struct_match(cx, span, arms) - ); + expand_enum_or_struct_match(cx, span, arms), + e_ident); - let call_expr = cx.mk_method_call( + let call_expr = cx.expr_method_call( span, - cx.mk_path(span, ~[cx.ident_of("__e")]), + cx.expr_ident(span, e_ident), cx.ident_of("emit_enum"), ~[ - cx.mk_base_str(span, cx.str_of(type_ident)), + cx.expr_str(span, cx.str_of(type_ident)), lambda_expr, ] ); - let stmt = cx.mk_stmt(span, call_expr); + let stmt = cx.stmt_expr(call_expr); // Create the method. create_encode_method(cx, span, ~[stmt]) diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 4859fec2e4452..b61c78721fee9 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -431,7 +431,7 @@ impl<'self> MethodDef<'self> { let ident = cx.ident_of(fmt!("__arg_%u", i)); arg_tys.push((ident, ast_ty)); - let arg_expr = cx.mk_path(span, ~[ident]); + let arg_expr = cx.expr_ident(span, ident); match *ty { // for static methods, just treat any Self @@ -440,7 +440,7 @@ impl<'self> MethodDef<'self> { self_args.push(arg_expr); } Ptr(~Self, _) if nonstatic => { - self_args.push(cx.mk_deref(span, arg_expr)) + self_args.push(cx.expr_deref(span, arg_expr)) } _ => { nonself_args.push(arg_expr); @@ -461,14 +461,14 @@ impl<'self> MethodDef<'self> { let fn_generics = self.generics.to_generics(cx, span, type_ident, generics); let args = do arg_types.map |&(id, ty)| { - cx.mk_arg(span, id, ty) + cx.arg(span, id, ty) }; let ret_type = self.get_ret_ty(cx, span, generics, type_ident); let method_ident = cx.ident_of(self.name); - let fn_decl = cx.mk_fn_decl(args, ret_type); - let body_block = cx.mk_simple_block(span, body); + let fn_decl = cx.fn_decl(args, ret_type); + let body_block = cx.blk_expr(body); // Create the method. @@ -555,13 +555,8 @@ impl<'self> MethodDef<'self> { // structs. This is actually right-to-left, but it shoudn't // matter. for vec::each2(self_args, patterns) |&arg_expr, &pat| { - let match_arm = ast::arm { - pats: ~[ pat ], - guard: None, - body: cx.mk_simple_block(span, body) - }; - - body = cx.mk_expr(span, ast::expr_match(arg_expr, ~[match_arm])) + body = cx.expr_match(span, arg_expr, + ~[ cx.arm(span, ~[pat], body) ]) } body } @@ -690,7 +685,7 @@ impl<'self> MethodDef<'self> { } let field_tuples = do vec::map_zip(*self_vec, - enum_matching_fields) |&(id, self_f), &other| { + enum_matching_fields) |&(id, self_f), &other| { (id, self_f, other) }; substructure = EnumMatching(variant_index, variant, field_tuples); @@ -738,16 +733,16 @@ impl<'self> MethodDef<'self> { matches_so_far, match_count + 1); matches_so_far.pop(); - arms.push(cx.mk_arm(span, ~[ pattern ], arm_expr)); + arms.push(cx.arm(span, ~[ pattern ], arm_expr)); if enum_def.variants.len() > 1 { let e = &EnumNonMatching(&[]); let wild_expr = self.call_substructure_method(cx, span, type_ident, self_args, nonself_args, e); - let wild_arm = cx.mk_arm(span, - ~[ cx.mk_pat_wild(span) ], - wild_expr); + let wild_arm = cx.arm(span, + ~[ cx.pat_wild(span) ], + wild_expr); arms.push(wild_arm); } } else { @@ -774,14 +769,13 @@ impl<'self> MethodDef<'self> { match_count + 1); matches_so_far.pop(); - let arm = cx.mk_arm(span, ~[ pattern ], arm_expr); + let arm = cx.arm(span, ~[ pattern ], arm_expr); arms.push(arm); } } // match foo { arm, arm, arm, ... } - cx.mk_expr(span, - ast::expr_match(self_args[match_count], arms)) + cx.expr_match(span, self_args[match_count], arms) } } @@ -887,10 +881,10 @@ pub fn cs_same_method(f: &fn(@ExtCtxt, span, ~[@expr]) -> @expr, EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { // call self_n.method(other_1_n, other_2_n, ...) let called = do all_fields.map |&(_, self_field, other_fields)| { - cx.mk_method_call(span, - self_field, - substructure.method_ident, - other_fields) + cx.expr_method_call(span, + self_field, + substructure.method_ident, + other_fields) }; f(cx, span, called) @@ -945,9 +939,9 @@ pub fn cs_binop(binop: ast::binop, base: @expr, cs_same_method_fold( true, // foldl is good enough |cx, span, old, new| { - cx.mk_binary(span, - binop, - old, new) + cx.expr_binary(span, + binop, + old, new) }, base, @@ -960,7 +954,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr, pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { - cs_binop(ast::or, cx.mk_bool(span, false), + cs_binop(ast::or, cx.expr_bool(span, false), enum_nonmatch_f, cx, span, substructure) } @@ -969,7 +963,7 @@ pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc, cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { - cs_binop(ast::and, cx.mk_bool(span, true), + cs_binop(ast::and, cx.expr_bool(span, true), enum_nonmatch_f, cx, span, substructure) } diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index cc89bae37b76f..ae321c3e40956 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -48,7 +48,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ }; let iter_bytes_ident = substr.method_ident; let call_iterbytes = |thing_expr| { - cx.mk_method_call(span, + cx.expr_method_call(span, thing_expr, iter_bytes_ident, copy lsb0_f) }; @@ -63,7 +63,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ // iteration function. let discriminant = match variant.node.disr_expr { Some(copy d)=> d, - None => cx.mk_uint(span, index) + None => cx.expr_uint(span, index) }; exprs.push(call_iterbytes(discriminant)); @@ -82,6 +82,6 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ } do vec::foldl(exprs[0], exprs.slice(1, exprs.len())) |prev, me| { - cx.mk_binary(span, and, prev, *me) + cx.expr_binary(span, and, prev, *me) } } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index a7f70236251ba..7da66f88ca908 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -22,7 +22,7 @@ use ast; use ast::{Ty, enum_def, expr, ident, item, Generics, meta_item, struct_def}; use ext::base::ExtCtxt; use ext::build::AstBuilder; -use codemap::{span, respan}; +use codemap::span; use parse::token::special_idents::clownshoes_extensions; use opt_vec; @@ -143,38 +143,15 @@ pub fn expand_deriving(cx: @ExtCtxt, result } -fn create_impl_item(cx: @ExtCtxt, span: span, item: ast::item_) -> @item { - let doc_attr = respan(span, - ast::lit_str(@~"Automatically derived.")); - let doc_attr = respan(span, ast::meta_name_value(@~"doc", doc_attr)); - let doc_attr = ast::attribute_ { - style: ast::attr_outer, - value: @doc_attr, - is_sugared_doc: false - }; - let doc_attr = respan(span, doc_attr); - - @ast::item { - ident: clownshoes_extensions, - attrs: ~[doc_attr], - id: cx.next_id(), - node: item, - vis: ast::public, - span: span, - } -} - pub fn create_self_type_with_params(cx: @ExtCtxt, - span: span, - type_ident: ident, - generics: &Generics) - -> @Ty { + span: span, + type_ident: ident, + generics: &Generics) + -> @Ty { // Create the type parameters on the `self` path. let mut self_ty_params = ~[]; for generics.ty_params.each |ty_param| { - let self_ty_param = cx.mk_simple_ty_path( - span, - ty_param.ident); + let self_ty_param = cx.ty_ident(span, ty_param.ident); self_ty_params.push(self_ty_param); } @@ -186,11 +163,7 @@ pub fn create_self_type_with_params(cx: @ExtCtxt, // Create the type of `self`. - let self_type = cx.mk_raw_path_(span, - ~[ type_ident ], - lifetime, - self_ty_params); - cx.mk_ty_path_path(span, self_type) + cx.ty_path(cx.path_all(span, false, ~[ type_ident ], lifetime, self_ty_params)) } pub fn create_derived_impl(cx: @ExtCtxt, @@ -222,18 +195,17 @@ pub fn create_derived_impl(cx: @ExtCtxt, for generics.ty_params.each |ty_param| { // extra restrictions on the generics parameters to the type being derived upon let mut bounds = do bounds_paths.map |&bound_path| { - cx.mk_trait_ty_param_bound_(bound_path) + cx.typarambound(bound_path) }; - let this_trait_bound = - cx.mk_trait_ty_param_bound_(trait_path); + let this_trait_bound = cx.typarambound(trait_path); bounds.push(this_trait_bound); - impl_generics.ty_params.push(cx.mk_ty_param(ty_param.ident, @bounds)); + impl_generics.ty_params.push(cx.typaram(ty_param.ident, @bounds)); } // Create the reference to the trait. - let trait_ref = cx.mk_trait_ref_(trait_path); + let trait_ref = cx.trait_ref(trait_path); // Create the type of `self`. let self_type = create_self_type_with_params(cx, @@ -241,12 +213,18 @@ pub fn create_derived_impl(cx: @ExtCtxt, type_ident, generics); - // Create the impl item. - let impl_item = ast::item_impl(impl_generics, - Some(trait_ref), - self_type, - methods.map(|x| *x)); - return create_impl_item(cx, span, impl_item); + let doc_attr = cx.attribute( + span, + cx.meta_name_value(span, + ~"doc", ast::lit_str(@~"Automatically derived."))); + cx.item( + span, + clownshoes_extensions, + ~[doc_attr], + ast::item_impl(impl_generics, + Some(trait_ref), + self_type, + methods.map(|x| *x))) } pub fn create_subpatterns(cx: @ExtCtxt, @@ -255,7 +233,7 @@ pub fn create_subpatterns(cx: @ExtCtxt, mutbl: ast::mutability) -> ~[@ast::pat] { do field_paths.map |&path| { - cx.mk_pat(span, + cx.pat(span, ast::pat_ident(ast::bind_by_ref(mutbl), path, None)) } } @@ -274,12 +252,12 @@ pub fn create_struct_pattern(cx: @ExtCtxt, -> (@ast::pat, ~[(Option, @expr)]) { if struct_def.fields.is_empty() { return ( - cx.mk_pat_ident_with_binding_mode( + cx.pat_ident_binding_mode( span, struct_ident, ast::bind_infer), ~[]); } - let matching_path = cx.mk_raw_path(span, ~[ struct_ident ]); + let matching_path = cx.path(span, ~[ struct_ident ]); let mut paths = ~[], ident_expr = ~[]; @@ -301,10 +279,10 @@ pub fn create_struct_pattern(cx: @ExtCtxt, cx.span_bug(span, "A struct with named and unnamed fields in `deriving`"); } }; - let path = cx.mk_raw_path(span, - ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]); + let path = cx.path_ident(span, + cx.ident_of(fmt!("%s_%u", prefix, i))); paths.push(path); - ident_expr.push((opt_id, cx.mk_path_raw(span, path))); + ident_expr.push((opt_id, cx.expr_path(path))); } let subpats = create_subpatterns(cx, span, paths, mutbl); @@ -318,9 +296,9 @@ pub fn create_struct_pattern(cx: @ExtCtxt, push(ast::field_pat { ident: id.get(), pat: pat }) } }; - cx.mk_pat_struct(span, matching_path, field_pats) + cx.pat_struct(span, matching_path, field_pats) } else { - cx.mk_pat_enum(span, matching_path, subpats) + cx.pat_enum(span, matching_path, subpats) }; (pattern, ident_expr) @@ -337,24 +315,24 @@ pub fn create_enum_variant_pattern(cx: @ExtCtxt, match variant.node.kind { ast::tuple_variant_kind(ref variant_args) => { if variant_args.is_empty() { - return (cx.mk_pat_ident_with_binding_mode( + return (cx.pat_ident_binding_mode( span, variant_ident, ast::bind_infer), ~[]); } - let matching_path = cx.mk_raw_path(span, ~[ variant_ident ]); + let matching_path = cx.path_ident(span, variant_ident); let mut paths = ~[], ident_expr = ~[]; for uint::range(0, variant_args.len()) |i| { - let path = cx.mk_raw_path(span, - ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]); + let path = cx.path_ident(span, + cx.ident_of(fmt!("%s_%u", prefix, i))); paths.push(path); - ident_expr.push((None, cx.mk_path_raw(span, path))); + ident_expr.push((None, cx.expr_path(path))); } let subpats = create_subpatterns(cx, span, paths, mutbl); - (cx.mk_pat_enum(span, matching_path, subpats), + (cx.pat_enum(span, matching_path, subpats), ident_expr) } ast::struct_variant_kind(struct_def) => { @@ -377,8 +355,6 @@ pub fn expand_enum_or_struct_match(cx: @ExtCtxt, span: span, arms: ~[ ast::arm ]) -> @expr { - let self_expr = cx.make_self(span); - let self_expr = cx.mk_unary(span, ast::deref, self_expr); - let self_match_expr = ast::expr_match(self_expr, arms); - cx.mk_expr(span, self_match_expr) + let self_expr = cx.expr_deref(span, cx.expr_self(span)); + cx.expr_match(span, self_expr, arms) } diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index b8e9de22fb0ef..16f754727b078 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -12,7 +12,7 @@ use ast; use ast::{meta_item, item, expr, ident}; use codemap::span; use ext::base::ExtCtxt; -use ext::build::{AstBuilder, Duplicate, Field}; +use ext::build::{AstBuilder, Duplicate}; use ext::deriving::generic::*; pub fn expand_deriving_rand(cx: @ExtCtxt, @@ -59,10 +59,9 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cx.ident_of("rand") ]; let rand_call = || { - cx.mk_call_global( - span, - copy rand_ident, - ~[ rng[0].duplicate(cx) ]) + cx.expr_call_global(span, + copy rand_ident, + ~[ rng[0].duplicate(cx) ]) }; return match *substr.fields { @@ -74,41 +73,39 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cx.span_fatal(span, "`Rand` cannot be derived for enums with no variants"); } - let variant_count = cx.mk_uint(span, variants.len()); + let variant_count = cx.expr_uint(span, variants.len()); // need to specify the uint-ness of the random number - let u32_ty = cx.mk_ty_path(span, ~[cx.ident_of("uint")]); - let r_ty = cx.mk_ty_path(span, ~[cx.ident_of("R")]); - let rand_name = cx.mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); - let rand_name = cx.mk_path_raw(span, rand_name); + let u32_ty = cx.ty_ident(span, cx.ident_of("uint")); + let r_ty = cx.ty_ident(span, cx.ident_of("R")); + let rand_name = cx.path_all(span, false, copy rand_ident, None, ~[ u32_ty, r_ty ]); + let rand_name = cx.expr_path(rand_name); - let rv_call = cx.mk_call_( - span, - rand_name, - ~[ rng[0].duplicate(cx) ]); + let rv_call = cx.expr_call(span, + rand_name, + ~[ rng[0].duplicate(cx) ]); // rand() % variants.len() - let rand_variant = cx.mk_binary(span, ast::rem, + let rand_variant = cx.expr_binary(span, ast::rem, rv_call, variant_count); let mut arms = do variants.mapi |i, id_sum| { - let i_expr = cx.mk_uint(span, i); - let pat = cx.mk_pat_lit(span, i_expr); + let i_expr = cx.expr_uint(span, i); + let pat = cx.pat_lit(span, i_expr); match *id_sum { (ident, ref summary) => { - cx.mk_arm(span, - ~[ pat ], - rand_thing(cx, span, ident, summary, rand_call)) + cx.arm(span, + ~[ pat ], + rand_thing(cx, span, ident, summary, rand_call)) } } }; // _ => {} at the end. Should never occur - arms.push(cx.mk_unreachable_arm(span)); + arms.push(cx.arm_unreachable(span)); - cx.mk_expr(span, - ast::expr_match(rand_variant, arms)) + cx.expr_match(span, rand_variant, arms) } _ => cx.bug("Non-static method in `deriving(Rand)`") }; @@ -117,24 +114,20 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { ctor_ident: ident, summary: &Either, rand_call: &fn() -> @expr) -> @expr { - let ctor_ident = ~[ ctor_ident ]; match *summary { Left(copy count) => { if count == 0 { - cx.mk_path(span, ctor_ident) + cx.expr_ident(span, ctor_ident) } else { let exprs = vec::from_fn(count, |_| rand_call()); - cx.mk_call(span, ctor_ident, exprs) + cx.expr_call_ident(span, ctor_ident, exprs) } } Right(ref fields) => { let rand_fields = do fields.map |ident| { - Field { - ident: *ident, - ex: rand_call() - } + cx.field_imm(span, *ident, rand_call()) }; - cx.mk_struct_e(span, ctor_ident, rand_fields) + cx.expr_struct_ident(span, ctor_ident, rand_fields) } } } diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 9198c67177e53..89b469575e54b 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -42,12 +42,12 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt, fn to_str_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { match substr.self_args { [self_obj] => { - let self_addr = cx.mk_addr_of(span, self_obj); - cx.mk_call_global(span, - ~[cx.ident_of("core"), - cx.ident_of("sys"), - cx.ident_of("log_str")], - ~[self_addr]) + let self_addr = cx.expr_addr_of(span, self_obj); + cx.expr_call_global(span, + ~[cx.ident_of("core"), + cx.ident_of("sys"), + cx.ident_of("log_str")], + ~[self_addr]) } _ => cx.span_bug(span, "Invalid number of arguments in `deriving(ToStr)`") } diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index a9d13bfe79c48..99bc2d87b3095 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -55,9 +55,8 @@ pub impl<'self> Path<'self> { fn to_ty(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Ty { - cx.mk_ty_path_path(span, - self.to_path(cx, span, - self_ty, self_generics)) + cx.ty_path(self.to_path(cx, span, + self_ty, self_generics)) } fn to_path(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Path { @@ -65,11 +64,7 @@ pub impl<'self> Path<'self> { let lt = mk_lifetime(cx, span, &self.lifetime); let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics)); - if self.global { - cx.mk_raw_path_global_(span, idents, lt, tys) - } else { - cx.mk_raw_path_(span, idents, lt, tys) - } + cx.path_all(span, self.global, idents, lt, tys) } } @@ -106,7 +101,7 @@ pub fn nil_ty() -> Ty<'static> { fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> { match *lt { - Some(ref s) => Some(@cx.mk_lifetime(span, cx.ident_of(*s))), + Some(ref s) => Some(@cx.lifetime(span, cx.ident_of(*s))), None => None } } @@ -119,20 +114,20 @@ pub impl<'self> Ty<'self> { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); match *ptr { Owned => { - cx.mk_ty_uniq(span, raw_ty) + cx.ty_uniq(span, raw_ty) } Managed(mutbl) => { - cx.mk_ty_box(span, raw_ty, mutbl) + cx.ty_box(span, raw_ty, mutbl) } Borrowed(ref lt, mutbl) => { let lt = mk_lifetime(cx, span, lt); - cx.mk_ty_rptr(span, raw_ty, lt, mutbl) + cx.ty_rptr(span, raw_ty, lt, mutbl) } } } Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) } Self => { - cx.mk_ty_path_path(span, self.to_path(cx, span, self_ty, self_generics)) + cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) } Tuple(ref fields) => { let ty = if fields.is_empty() { @@ -141,7 +136,7 @@ pub impl<'self> Ty<'self> { ast::ty_tup(fields.map(|f| f.to_ty(cx, span, self_ty, self_generics))) }; - cx.mk_ty(span, ty) + cx.ty(span, ty) } } } @@ -151,7 +146,7 @@ pub impl<'self> Ty<'self> { match *self { Self => { let self_params = do self_generics.ty_params.map |ty_param| { - cx.mk_ty_path(span, ~[ ty_param.ident ]) + cx.ty_ident(span, ty_param.ident) }; let lifetime = if self_generics.lifetimes.is_empty() { None @@ -159,8 +154,8 @@ pub impl<'self> Ty<'self> { Some(@*self_generics.lifetimes.get(0)) }; - cx.mk_raw_path_(span, ~[self_ty], lifetime, - opt_vec::take_vec(self_params)) + cx.path_all(span, false, ~[self_ty], lifetime, + opt_vec::take_vec(self_params)) } Literal(ref p) => { p.to_path(cx, span, self_ty, self_generics) @@ -177,9 +172,9 @@ fn mk_ty_param(cx: @ExtCtxt, span: span, name: &str, bounds: &[Path], let bounds = opt_vec::from( do bounds.map |b| { let path = b.to_path(cx, span, self_ident, self_generics); - cx.mk_trait_ty_param_bound_(path) + cx.typarambound(path) }); - cx.mk_ty_param(cx.ident_of(name), @bounds) + cx.typaram(cx.ident_of(name), @bounds) } fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Generics { @@ -204,7 +199,7 @@ pub impl<'self> LifetimeBounds<'self> { fn to_generics(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> Generics { let lifetimes = do self.lifetimes.map |lt| { - cx.mk_lifetime(span, cx.ident_of(*lt)) + cx.lifetime(span, cx.ident_of(*lt)) }; let ty_params = do self.bounds.map |t| { match t { @@ -220,7 +215,7 @@ pub impl<'self> LifetimeBounds<'self> { pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) -> (@expr, ast::explicit_self) { - let self_path = cx.make_self(span); + let self_path = cx.expr_self(span); match *self_ptr { None => { (self_path, respan(span, ast::sty_value)) @@ -232,12 +227,12 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) Owned => ast::sty_uniq(ast::m_imm), Managed(mutbl) => ast::sty_box(mutbl), Borrowed(ref lt, mutbl) => { - let lt = lt.map(|s| @cx.mk_lifetime(span, - cx.ident_of(*s))); + let lt = lt.map(|s| @cx.lifetime(span, + cx.ident_of(*s))); ast::sty_region(lt, mutbl) } }); - let self_expr = cx.mk_deref(span, self_path); + let self_expr = cx.expr_deref(span, self_path); (self_expr, self_ty) } } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index fb7367b47bafc..32fbc9139998e 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -29,8 +29,8 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) // Option rather than just an maybe-empty string. let e = match os::getenv(var) { - None => cx.mk_base_str(sp, ~""), - Some(ref s) => cx.mk_base_str(sp, copy *s) + None => cx.expr_str(sp, ~""), + Some(ref s) => cx.expr_str(sp, copy *s) }; MRExpr(e) } diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 1e4ff03b610c8..55d3d4ee8349d 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -18,7 +18,6 @@ use ast; use codemap::span; use ext::base::*; use ext::base; -use ext::build; use ext::build::AstBuilder; use core::unstable::extfmt::ct::*; @@ -56,7 +55,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, } fn make_rt_path_expr(cx: @ExtCtxt, sp: span, nm: &str) -> @ast::expr { let path = make_path_vec(cx, nm); - cx.mk_path_global(sp, path) + cx.expr_path(cx.path_global(sp, path)) } // Produces an AST expression that represents a RT::conv record, // which tells the RT::conv* functions how to perform the conversion @@ -72,8 +71,8 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, FlagSignAlways => "flag_sign_always", FlagAlternate => "flag_alternate" }; - tmp_expr = cx.mk_binary(sp, ast::bitor, tmp_expr, - make_rt_path_expr(cx, sp, fstr)); + tmp_expr = cx.expr_binary(sp, ast::bitor, tmp_expr, + make_rt_path_expr(cx, sp, fstr)); } return tmp_expr; } @@ -83,10 +82,10 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, return make_rt_path_expr(cx, sp, "CountImplied"); } CountIs(c) => { - let count_lit = cx.mk_uint(sp, c as uint); + let count_lit = cx.expr_uint(sp, c as uint); let count_is_path = make_path_vec(cx, "CountIs"); let count_is_args = ~[count_lit]; - return cx.mk_call_global(sp, count_is_path, count_is_args); + return cx.expr_call_global(sp, count_is_path, count_is_args); } _ => cx.span_unimpl(sp, "unimplemented fmt! conversion") } @@ -107,22 +106,14 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { let intr = cx.parse_sess().interner; - cx.mk_global_struct_e( + cx.expr_struct( sp, - make_path_vec(cx, "Conv"), + cx.path_global(sp, make_path_vec(cx, "Conv")), ~[ - 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 - }, + cx.field_imm(sp, intr.intern("flags"), flags_expr), + cx.field_imm(sp, intr.intern("width"), width_expr), + cx.field_imm(sp, intr.intern("precision"), precision_expr), + cx.field_imm(sp, intr.intern("ty"), ty_expr) ] ) } @@ -139,7 +130,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, let path = make_path_vec(cx, fname); let cnv_expr = make_rt_conv_expr(cx, sp, cnv); let args = ~[cnv_expr, arg, buf]; - cx.mk_call_global(arg.span, path, args) + cx.expr_call_global(arg.span, path, args) } fn make_new_conv(cx: @ExtCtxt, sp: span, cnv: &Conv, @@ -197,10 +188,10 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, TyChar => ("char", arg), TyBits | TyOctal | TyHex(_) | TyInt(Unsigned) => ("uint", arg), TyFloat => ("float", arg), - TyPoly => ("poly", cx.mk_addr_of(sp, arg)) + TyPoly => ("poly", cx.expr_addr_of(sp, arg)) }; return make_conv_call(cx, arg.span, name, cnv, actual_arg, - cx.mk_mut_addr_of(arg.span, buf)); + cx.expr_mut_addr_of(arg.span, buf)); } fn log_conv(c: &Conv) { debug!("Building conversion:"); @@ -258,7 +249,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, /* 'ident' is the local buffer building up the result of fmt! */ let ident = cx.parse_sess().interner.intern("__fmtbuf"); - let buf = || cx.mk_path(fmt_sp, ~[ident]); + let buf = || cx.expr_ident(fmt_sp, ident); let str_ident = cx.parse_sess().interner.intern("str"); let push_ident = cx.parse_sess().interner.intern("push_str"); let mut stms = ~[]; @@ -275,14 +266,14 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, buffer with it directly. If it's actually the only piece, then there's no need for it to be mutable */ if i == 0 { - stms.push(cx.mk_local(fmt_sp, npieces > 1, ident, cx.mk_uniq_str(fmt_sp, s))); + stms.push(cx.stmt_let(fmt_sp, npieces > 1, + ident, cx.expr_str_uniq(fmt_sp, s))); } else { - let args = ~[cx.mk_mut_addr_of(fmt_sp, buf()), cx.mk_base_str(fmt_sp, s)]; - let call = cx.mk_call_global( - fmt_sp, - ~[str_ident, push_ident], - args); - stms.push(cx.mk_stmt(fmt_sp, call)); + let args = ~[cx.expr_mut_addr_of(fmt_sp, buf()), cx.expr_str(fmt_sp, s)]; + let call = cx.expr_call_global(fmt_sp, + ~[str_ident, push_ident], + args); + stms.push(cx.stmt_expr(call)); } } @@ -299,12 +290,11 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, /* If the first portion is a conversion, then the local buffer must be initialized as an empty string */ if i == 0 { - stms.push(cx.mk_local(fmt_sp, true, ident, - cx.mk_uniq_str(fmt_sp, ~""))); + stms.push(cx.stmt_let(fmt_sp, true, ident, + cx.expr_str_uniq(fmt_sp, ~""))); } - stms.push(cx.mk_stmt(fmt_sp, - make_new_conv(cx, fmt_sp, conv, - args[n], buf()))); + stms.push(cx.stmt_expr(make_new_conv(cx, fmt_sp, conv, + args[n], buf()))); } } } @@ -316,5 +306,5 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, nargs, expected_nargs)); } - cx.mk_block(fmt_sp, ~[], stms, Some(buf())) + cx.expr_blk(cx.blk(fmt_sp, stms, Some(buf()))) } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 44f47c0d588a4..1f2e3f06a7310 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -16,7 +16,7 @@ use ast::ident; use ast; use codemap::span; -use ext::quote::rt::*; +// use ext::quote::rt::*; // Transitional reexports so qquote can find the paths it is looking for mod syntax { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 4362699378344..0482dffe6d44c 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -53,14 +53,13 @@ impl gen_send for message { assert!(next_state.tys.len() == next.generics.ty_params.len()); let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str())); - let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(*n, *t)); + let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(span, *n, *t)); let pipe_ty = cx.ty_path( path(~[this.data_name()], span) - .add_tys(cx.ty_vars_global(&this.generics.ty_params))); + .add_tys(cx.ty_vars(&this.generics.ty_params))); let args_ast = vec::append( - ~[cx.arg(cx.ident_of("pipe"), - pipe_ty)], + ~[cx.arg(span, cx.ident_of("pipe"), pipe_ty)], args_ast); let mut body = ~"{\n"; @@ -113,15 +112,16 @@ impl gen_send for message { let body = cx.parse_expr(body); let mut rty = cx.ty_path(path(~[next.data_name()], - span) - .add_tys(copy next_state.tys)); + span) + .add_tys(copy next_state.tys)); if try { rty = cx.ty_option(rty); } let name = cx.ident_of(if try { ~"try_" + name } else { name } ); - cx.item_fn_poly(name, + cx.item_fn_poly(dummy_sp(), + name, args_ast, rty, self.get_generics(), @@ -133,14 +133,15 @@ impl gen_send for message { let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str())); let args_ast = do vec::map_zip(arg_names, *tys) |n, t| { - cx.arg(cx.ident_of(*n), *t) + cx.arg(span, cx.ident_of(*n), *t) }; let args_ast = vec::append( - ~[cx.arg(cx.ident_of("pipe"), + ~[cx.arg(span, + cx.ident_of("pipe"), cx.ty_path( path(~[this.data_name()], span) - .add_tys(cx.ty_vars_global( + .add_tys(cx.ty_vars( &this.generics.ty_params))))], args_ast); @@ -172,12 +173,13 @@ impl gen_send for message { let name = if try { ~"try_" + name } else { name }; - cx.item_fn_poly(cx.ident_of(name), + cx.item_fn_poly(dummy_sp(), + cx.ident_of(name), args_ast, if try { - cx.ty_option(cx.ty_nil_ast_builder()) + cx.ty_option(cx.ty_nil()) } else { - cx.ty_nil_ast_builder() + cx.ty_nil() }, self.get_generics(), cx.blk_expr(body)) @@ -187,7 +189,7 @@ impl gen_send for message { fn to_ty(&mut self, cx: @ExtCtxt) -> @ast::Ty { cx.ty_path(path(~[cx.ident_of(self.name())], self.span()) - .add_tys(cx.ty_vars_global(&self.get_generics().ty_params))) + .add_tys(cx.ty_vars(&self.get_generics().ty_params))) } } @@ -226,15 +228,15 @@ impl to_type_decls for state { None => tys }; - let v = cx.variant(cx.ident_of(name), span, tys); + let v = cx.variant(span, cx.ident_of(name), tys); items_msg.push(v); } ~[ cx.item_enum_poly( - name, self.span, + name, ast::enum_def { variants: items_msg }, cx.strip_bounds(&self.generics) ) @@ -263,8 +265,8 @@ impl to_type_decls for state { if !self.proto.is_bounded() { items.push( cx.item_ty_poly( - self.data_name(), self.span, + self.data_name(), cx.ty_path( path_global(~[cx.ident_of("core"), cx.ident_of("pipes"), @@ -274,15 +276,15 @@ impl to_type_decls for state { path(~[cx.ident_of("super"), self.data_name()], dummy_sp()) - .add_tys(cx.ty_vars_global( + .add_tys(cx.ty_vars( &self.generics.ty_params))))), cx.strip_bounds(&self.generics))); } else { items.push( cx.item_ty_poly( - self.data_name(), self.span, + self.data_name(), cx.ty_path( path_global(~[cx.ident_of("core"), cx.ident_of("pipes"), @@ -342,15 +344,18 @@ impl gen_init for protocol { } fn gen_buffer_init(&self, ext_cx: @ExtCtxt) -> @ast::expr { - ext_cx.expr_struct(path(~[ext_cx.ident_of("__Buffer")], - dummy_sp()), - self.states.map_to_vec(|s| { - let fty = s.to_ty(ext_cx); - ext_cx.field_imm(ext_cx.ident_of(s.name), - quote_expr!( - ::core::pipes::mk_packet::<$fty>() - )) - })) + ext_cx.expr_struct( + dummy_sp(), + path(~[ext_cx.ident_of("__Buffer")], + dummy_sp()), + self.states.map_to_vec(|s| { + let fty = s.to_ty(ext_cx); + ext_cx.field_imm(dummy_sp(), + ext_cx.ident_of(s.name), + quote_expr!( + ::core::pipes::mk_packet::<$fty>() + )) + })) } fn gen_init_bounded(&self, ext_cx: @ExtCtxt) -> @ast::expr { @@ -392,9 +397,9 @@ impl gen_init for protocol { } cx.ty_path(path(~[cx.ident_of("super"), - cx.ident_of("__Buffer")], - copy self.span) - .add_tys(cx.ty_vars_global(¶ms))) + cx.ident_of("__Buffer")], + copy self.span) + .add_tys(cx.ty_vars_global(¶ms))) } fn gen_buffer_type(&self, cx: @ExtCtxt) -> @ast::item { @@ -429,8 +434,8 @@ impl gen_init for protocol { }; cx.item_struct_poly( - cx.ident_of("__Buffer"), dummy_sp(), + cx.ident_of("__Buffer"), ast::struct_def { fields: fields, ctor_id: None @@ -454,13 +459,24 @@ impl gen_init for protocol { items.push(self.gen_buffer_type(cx)) } - items.push(cx.item_mod(cx.ident_of("client"), - copy self.span, + items.push(cx.item_mod(copy self.span, + cx.ident_of("client"), + ~[], ~[], client_states)); - items.push(cx.item_mod(cx.ident_of("server"), - copy self.span, + items.push(cx.item_mod(copy self.span, + cx.ident_of("server"), + ~[], ~[], server_states)); - cx.item_mod(cx.ident_of(copy self.name), copy self.span, items) + // XXX: Would be nice if our generated code didn't violate + // Rust coding conventions + let allows = cx.attribute( + copy self.span, + cx.meta_list(copy self.span, + ~"allow", + ~[cx.meta_word(copy self.span, ~"non_camel_case_types"), + cx.meta_word(copy self.span, ~"unused_mut")])); + cx.item_mod(copy self.span, cx.ident_of(copy self.name), + ~[allows], ~[], items) } } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 5ab28b50e841c..1c57d500c221a 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -382,7 +382,7 @@ pub fn expand_quote_expr(cx: @ExtCtxt, pub fn expand_quote_item(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_attrs = cx.mk_uniq_vec_e(sp, ~[]); + let e_attrs = cx.expr_vec_uniq(sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, "parse_item", ~[e_attrs], tts)) } @@ -390,7 +390,7 @@ pub fn expand_quote_item(cx: @ExtCtxt, pub fn expand_quote_pat(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_refutable = cx.mk_lit(sp, ast::lit_bool(true)); + let e_refutable = cx.expr_lit(sp, ast::lit_bool(true)); base::MRExpr(expand_parse_call(cx, sp, "parse_pat", ~[e_refutable], tts)) } @@ -398,7 +398,7 @@ pub fn expand_quote_pat(cx: @ExtCtxt, pub fn expand_quote_ty(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_param_colons = cx.mk_lit(sp, ast::lit_bool(false)); + let e_param_colons = cx.expr_lit(sp, ast::lit_bool(false)); base::MRExpr(expand_parse_call(cx, sp, "parse_ty", ~[e_param_colons], tts)) } @@ -406,7 +406,7 @@ pub fn expand_quote_ty(cx: @ExtCtxt, pub fn expand_quote_stmt(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_attrs = cx.mk_uniq_vec_e(sp, ~[]); + let e_attrs = cx.expr_vec_uniq(sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, "parse_stmt", ~[e_attrs], tts)) } @@ -421,17 +421,17 @@ fn id_ext(cx: @ExtCtxt, str: &str) -> ast::ident { // Lift an ident to the expr that evaluates to that ident. fn mk_ident(cx: @ExtCtxt, sp: span, ident: ast::ident) -> @ast::expr { - let e_str = cx.mk_base_str(sp, cx.str_of(ident)); - cx.mk_method_call(sp, - cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), - id_ext(cx, "ident_of"), - ~[e_str]) + let e_str = cx.expr_str(sp, cx.str_of(ident)); + cx.expr_method_call(sp, + cx.expr_ident(sp, id_ext(cx, "ext_cx")), + id_ext(cx, "ident_of"), + ~[e_str]) } fn mk_bytepos(cx: @ExtCtxt, sp: span, bpos: BytePos) -> @ast::expr { - let path = ids_ext(cx, ~[~"BytePos"]); - let arg = cx.mk_uint(sp, bpos.to_uint()); - cx.mk_call(sp, path, ~[arg]) + let path = id_ext(cx, "BytePos"); + let arg = cx.expr_uint(sp, bpos.to_uint()); + cx.expr_call_ident(sp, path, ~[arg]) } fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { @@ -447,22 +447,21 @@ fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { SHL => "SHL", SHR => "SHR" }; - cx.mk_path(sp, - ids_ext(cx, ~[name.to_owned()])) + cx.expr_ident(sp, id_ext(cx, name)) } fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { match *tok { BINOP(binop) => { - return cx.mk_call(sp, - ids_ext(cx, ~[~"BINOP"]), - ~[mk_binop(cx, sp, binop)]); + return cx.expr_call_ident(sp, + id_ext(cx, "BINOP"), + ~[mk_binop(cx, sp, binop)]); } BINOPEQ(binop) => { - return cx.mk_call(sp, - ids_ext(cx, ~[~"BINOPEQ"]), - ~[mk_binop(cx, sp, binop)]); + return cx.expr_call_ident(sp, + id_ext(cx, "BINOPEQ"), + ~[mk_binop(cx, sp, binop)]); } LIT_INT(i, ity) => { @@ -474,15 +473,13 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_i32 => ~"ty_i32", ast::ty_i64 => ~"ty_i64" }; - let e_ity = - cx.mk_path(sp, - ids_ext(cx, ~[s_ity])); + let e_ity = cx.expr_ident(sp, id_ext(cx, s_ity)); - let e_i64 = cx.mk_lit(sp, ast::lit_int(i, ast::ty_i64)); + let e_i64 = cx.expr_lit(sp, ast::lit_int(i, ast::ty_i64)); - return cx.mk_call(sp, - ids_ext(cx, ~[~"LIT_INT"]), - ~[e_i64, e_ity]); + return cx.expr_call_ident(sp, + id_ext(cx, "LIT_INT"), + ~[e_i64, e_ity]); } LIT_UINT(u, uty) => { @@ -493,24 +490,21 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_u32 => ~"ty_u32", ast::ty_u64 => ~"ty_u64" }; - let e_uty = - cx.mk_path(sp, - ids_ext(cx, ~[s_uty])); + let e_uty = cx.expr_ident(sp, id_ext(cx, s_uty)); - let e_u64 = cx.mk_lit(sp, ast::lit_uint(u, ast::ty_u64)); + let e_u64 = cx.expr_lit(sp, ast::lit_uint(u, ast::ty_u64)); - return cx.mk_call(sp, - ids_ext(cx, ~[~"LIT_UINT"]), - ~[e_u64, e_uty]); + return cx.expr_call_ident(sp, + id_ext(cx, "LIT_UINT"), + ~[e_u64, e_uty]); } LIT_INT_UNSUFFIXED(i) => { - let e_i64 = cx.mk_lit(sp, - ast::lit_int(i, ast::ty_i64)); + let e_i64 = cx.expr_lit(sp, ast::lit_int(i, ast::ty_i64)); - return cx.mk_call(sp, - ids_ext(cx, ~[~"LIT_INT_UNSUFFIXED"]), - ~[e_i64]); + return cx.expr_call_ident(sp, + id_ext(cx, "LIT_INT_UNSUFFIXED"), + ~[e_i64]); } LIT_FLOAT(fident, fty) => { @@ -519,40 +513,38 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_f32 => ~"ty_f32", ast::ty_f64 => ~"ty_f64" }; - let e_fty = - cx.mk_path(sp, - ids_ext(cx, ~[s_fty])); + let e_fty = cx.expr_ident(sp, id_ext(cx, s_fty)); let e_fident = mk_ident(cx, sp, fident); - return cx.mk_call(sp, - ids_ext(cx, ~[~"LIT_FLOAT"]), - ~[e_fident, e_fty]); + return cx.expr_call_ident(sp, + id_ext(cx, "LIT_FLOAT"), + ~[e_fident, e_fty]); } LIT_STR(ident) => { - return cx.mk_call(sp, - ids_ext(cx, ~[~"LIT_STR"]), - ~[mk_ident(cx, sp, ident)]); + return cx.expr_call_ident(sp, + id_ext(cx, "LIT_STR"), + ~[mk_ident(cx, sp, ident)]); } IDENT(ident, b) => { - return cx.mk_call(sp, - ids_ext(cx, ~[~"IDENT"]), - ~[mk_ident(cx, sp, ident), - cx.mk_lit(sp, ast::lit_bool(b))]); + return cx.expr_call_ident(sp, + id_ext(cx, "IDENT"), + ~[mk_ident(cx, sp, ident), + cx.expr_bool(sp, b)]); } LIFETIME(ident) => { - return cx.mk_call(sp, - ids_ext(cx, ~[~"LIFETIME"]), - ~[mk_ident(cx, sp, ident)]); + return cx.expr_call_ident(sp, + id_ext(cx, "LIFETIME"), + ~[mk_ident(cx, sp, ident)]); } DOC_COMMENT(ident) => { - return cx.mk_call(sp, - ids_ext(cx, ~[~"DOC_COMMENT"]), - ~[mk_ident(cx, sp, ident)]); + return cx.expr_call_ident(sp, + id_ext(cx, "DOC_COMMENT"), + ~[mk_ident(cx, sp, ident)]); } INTERPOLATED(_) => fail!("quote! with interpolated token"), @@ -595,8 +587,7 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { EOF => "EOF", _ => fail!() }; - cx.mk_path(sp, - ids_ext(cx, ~[name.to_owned()])) + cx.expr_ident(sp, id_ext(cx, name)) } @@ -606,19 +597,16 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree) match *tt { ast::tt_tok(sp, ref tok) => { - let e_sp = cx.mk_path(sp, - ids_ext(cx, ~[~"sp"])); - let e_tok = - cx.mk_call(sp, - ids_ext(cx, ~[~"tt_tok"]), - ~[e_sp, mk_token(cx, sp, tok)]); + let e_sp = cx.expr_ident(sp, id_ext(cx, "sp")); + let e_tok = cx.expr_call_ident(sp, + id_ext(cx, "tt_tok"), + ~[e_sp, mk_token(cx, sp, tok)]); let e_push = - cx.mk_method_call(sp, - cx.mk_path(sp, ids_ext(cx, ~[~"tt"])), - id_ext(cx, "push"), - ~[e_tok]); - ~[cx.mk_stmt(sp, e_push)] - + cx.expr_method_call(sp, + cx.expr_ident(sp, id_ext(cx, "tt")), + id_ext(cx, "push"), + ~[e_tok]); + ~[cx.stmt_expr(e_push)] } ast::tt_delim(ref tts) => mk_tts(cx, sp, *tts), @@ -629,19 +617,18 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree) // tt.push_all_move($ident.to_tokens(ext_cx)) let e_to_toks = - cx.mk_method_call(sp, - cx.mk_path(sp, ~[ident]), - id_ext(cx, "to_tokens"), - ~[cx.mk_path(sp, - ids_ext(cx, ~[~"ext_cx"]))]); + cx.expr_method_call(sp, + cx.expr_ident(sp, ident), + id_ext(cx, "to_tokens"), + ~[cx.expr_ident(sp, id_ext(cx, "ext_cx"))]); let e_push = - cx.mk_method_call(sp, - cx.mk_path(sp, ids_ext(cx, ~[~"tt"])), - id_ext(cx, "push_all_move"), - ~[e_to_toks]); + cx.expr_method_call(sp, + cx.expr_ident(sp, id_ext(cx, "tt")), + id_ext(cx, "push_all_move"), + ~[e_to_toks]); - ~[cx.mk_stmt(sp, e_push)] + ~[cx.stmt_expr(e_push)] } } } @@ -677,11 +664,11 @@ fn expand_tts(cx: @ExtCtxt, // We want to emit a block expression that does a sequence of 'use's to // import the runtime module, followed by a tt-building expression. - let uses = ~[ cx.mk_glob_use(sp, ast::public, - ids_ext(cx, ~[~"syntax", - ~"ext", - ~"quote", - ~"rt"])) ]; + let uses = ~[ cx.view_use_glob(sp, ast::public, + ids_ext(cx, ~[~"syntax", + ~"ext", + ~"quote", + ~"rt"])) ]; // We also bind a single value, sp, to ext_cx.call_site() // @@ -709,24 +696,24 @@ fn expand_tts(cx: @ExtCtxt, // of quotes, for example) but at this point it seems not likely to be // worth the hassle. - let e_sp = cx.mk_method_call(sp, - cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), - id_ext(cx, "call_site"), - ~[]); + let e_sp = cx.expr_method_call(sp, + cx.expr_ident(sp, id_ext(cx, "ext_cx")), + id_ext(cx, "call_site"), + ~[]); - let stmt_let_sp = cx.mk_local(sp, false, - id_ext(cx, "sp"), - e_sp); + let stmt_let_sp = cx.stmt_let(sp, false, + id_ext(cx, "sp"), + e_sp); - let stmt_let_tt = cx.mk_local(sp, true, - id_ext(cx, "tt"), - cx.mk_uniq_vec_e(sp, ~[])); + let stmt_let_tt = cx.stmt_let(sp, true, + id_ext(cx, "tt"), + cx.expr_vec_uniq(sp, ~[])); - cx.mk_block(sp, uses, - ~[stmt_let_sp, - stmt_let_tt] + mk_tts(cx, sp, tts), - Some(cx.mk_path(sp, - ids_ext(cx, ~[~"tt"])))) + cx.expr_blk( + cx.blk_all(sp, uses, + ~[stmt_let_sp, + stmt_let_tt] + mk_tts(cx, sp, tts), + Some(cx.expr_ident(sp, id_ext(cx, "tt"))))) } fn expand_parse_call(cx: @ExtCtxt, @@ -736,27 +723,26 @@ fn expand_parse_call(cx: @ExtCtxt, tts: &[ast::token_tree]) -> @ast::expr { let tts_expr = expand_tts(cx, sp, tts); - let cfg_call = || cx.mk_method_call( - sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), + let cfg_call = || cx.expr_method_call( + sp, cx.expr_ident(sp, id_ext(cx, "ext_cx")), id_ext(cx, "cfg"), ~[]); - let parse_sess_call = || cx.mk_method_call( - sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), + let parse_sess_call = || cx.expr_method_call( + sp, cx.expr_ident(sp, id_ext(cx, "ext_cx")), id_ext(cx, "parse_sess"), ~[]); let new_parser_call = - cx.mk_call_global(sp, - ids_ext(cx, ~[~"syntax", - ~"ext", - ~"quote", - ~"rt", - ~"new_parser_from_tts"]), - ~[parse_sess_call(), - cfg_call(), - tts_expr]); - - cx.mk_method_call(sp, - new_parser_call, - id_ext(cx, parse_method), - arg_exprs) + cx.expr_call_global(sp, + ids_ext(cx, ~[~"syntax", + ~"ext", + ~"quote", + ~"rt", + ~"new_parser_from_tts"]), + ~[parse_sess_call(), + cfg_call(), + tts_expr]); + + cx.expr_method_call(sp, new_parser_call, + id_ext(cx, parse_method), + arg_exprs) } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 40dc44ca99326..30e6b7cfc65c9 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -30,7 +30,7 @@ pub fn expand_line(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(cx.mk_uint(topmost.call_site, loc.line)) + base::MRExpr(cx.expr_uint(topmost.call_site, loc.line)) } /* col!(): expands to the current column number */ @@ -40,7 +40,7 @@ pub fn expand_col(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(cx.mk_uint(topmost.call_site, loc.col.to_uint())) + base::MRExpr(cx.expr_uint(topmost.call_site, loc.col.to_uint())) } /* file!(): expands to the current filename */ @@ -53,19 +53,19 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let Loc { file: @FileMap { name: filename, _ }, _ } = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(cx.mk_base_str(topmost.call_site, filename)) + base::MRExpr(cx.expr_str(topmost.call_site, filename)) } pub fn expand_stringify(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, cx.parse_sess().interner); - base::MRExpr(cx.mk_base_str(sp, s)) + base::MRExpr(cx.expr_str(sp, s)) } pub fn expand_mod(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); - base::MRExpr(cx.mk_base_str(sp, + base::MRExpr(cx.expr_str(sp, str::connect(cx.mod_path().map( |x| cx.str_of(*x)), "::"))) } @@ -94,7 +94,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) } } - base::MRExpr(cx.mk_base_str(sp, result::unwrap(res))) + base::MRExpr(cx.expr_str(sp, result::unwrap(res))) } pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) @@ -103,9 +103,9 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { result::Ok(src) => { let u8_exprs = vec::map(src, |char| { - cx.mk_u8(sp, *char) + cx.expr_u8(sp, *char) }); - base::MRExpr(cx.mk_base_vec_e(sp, u8_exprs)) + base::MRExpr(cx.expr_vec(sp, u8_exprs)) } result::Err(ref e) => { cx.parse_sess().span_diagnostic.handler().fatal((*e))