diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2012-10-07 14:56:18 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2012-10-07 14:56:18 -0700 |
| commit | d301dd3686ddd04845c1e9f5b9254aa3498a8a7b (patch) | |
| tree | cd486ef0e451fe8ce7c98a6a212f3237e4f390b9 /src/libsyntax | |
| parent | e1c517ca4815273285ac5699a88ccf0bcdb6103e (diff) | |
| download | rust-d301dd3686ddd04845c1e9f5b9254aa3498a8a7b.tar.gz rust-d301dd3686ddd04845c1e9f5b9254aa3498a8a7b.zip | |
remove the old auto_serialize syntax extension
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/auto_serialize.rs | 109 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_serialize2.rs | 80 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 64 | ||||
| -rw-r--r-- | src/libsyntax/syntax.rc | 1 |
4 files changed, 146 insertions, 108 deletions
diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 64915c60742..63a6551bf88 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -122,34 +122,7 @@ fn expand(cx: ext_ctxt, } } -trait ext_ctxt_helpers { - fn helper_path(base_path: @ast::path, helper_name: ~str) -> @ast::path; - fn path(span: span, strs: ~[ast::ident]) -> @ast::path; - fn path_tps(span: span, strs: ~[ast::ident], - tps: ~[@ast::ty]) -> @ast::path; - fn ty_path(span: span, strs: ~[ast::ident], tps: ~[@ast::ty]) -> @ast::ty; - fn ty_fn(span: span, - -input_tys: ~[@ast::ty], - -output: @ast::ty) -> @ast::ty; - fn ty_nil(span: span) -> @ast::ty; - fn expr(span: span, node: ast::expr_) -> @ast::expr; - fn var_ref(span: span, name: ast::ident) -> @ast::expr; - fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk; - fn expr_blk(expr: @ast::expr) -> ast::blk; - fn binder_pat(span: span, nm: ast::ident) -> @ast::pat; - fn stmt(expr: @ast::expr) -> @ast::stmt; - fn alt_stmt(arms: ~[ast::arm], span: span, -v: @ast::expr) -> @ast::stmt; - fn lit_str(span: span, s: @~str) -> @ast::expr; - fn lit_uint(span: span, i: uint) -> @ast::expr; - fn lambda(blk: ast::blk) -> @ast::expr; - fn clone_folder() -> fold::ast_fold; - fn clone(v: @ast::expr) -> @ast::expr; - fn clone_ty(v: @ast::ty) -> @ast::ty; - fn clone_ty_param(v: ast::ty_param) -> ast::ty_param; - fn at(span: span, expr: @ast::expr) -> @ast::expr; -} - -impl ext_ctxt: ext_ctxt_helpers { +priv impl ext_ctxt { fn helper_path(base_path: @ast::path, helper_name: ~str) -> @ast::path { let head = vec::init(base_path.idents); @@ -162,22 +135,6 @@ impl ext_ctxt: ext_ctxt_helpers { tail)))])) } - fn path(span: span, strs: ~[ast::ident]) -> @ast::path { - @{span: span, global: false, idents: strs, rp: None, types: ~[]} - } - - fn path_tps(span: span, strs: ~[ast::ident], - tps: ~[@ast::ty]) -> @ast::path { - @{span: span, global: false, idents: strs, rp: None, types: tps} - } - - fn ty_path(span: span, strs: ~[ast::ident], - tps: ~[@ast::ty]) -> @ast::ty { - @{id: self.next_id(), - node: ast::ty_path(self.path_tps(span, strs, tps), self.next_id()), - span: span} - } - fn ty_fn(span: span, -input_tys: ~[@ast::ty], -output: @ast::ty) -> @ast::ty { @@ -202,48 +159,10 @@ impl ext_ctxt: ext_ctxt_helpers { @{id: self.next_id(), node: ast::ty_nil, span: span} } - fn expr(span: span, node: ast::expr_) -> @ast::expr { - @{id: self.next_id(), callee_id: self.next_id(), - node: node, span: span} - } - fn var_ref(span: span, name: ast::ident) -> @ast::expr { self.expr(span, ast::expr_path(self.path(span, ~[name]))) } - fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk { - {node: {view_items: ~[], - stmts: stmts, - expr: None, - id: self.next_id(), - rules: ast::default_blk}, - span: span} - } - - fn expr_blk(expr: @ast::expr) -> ast::blk { - {node: {view_items: ~[], - stmts: ~[], - expr: Some(expr), - id: self.next_id(), - rules: ast::default_blk}, - span: expr.span} - } - - fn binder_pat(span: span, nm: ast::ident) -> @ast::pat { - let path = @{span: span, global: false, idents: ~[nm], - rp: None, types: ~[]}; - @{id: self.next_id(), - node: ast::pat_ident(ast::bind_by_implicit_ref, - path, - None), - span: span} - } - - fn stmt(expr: @ast::expr) -> @ast::stmt { - @{node: ast::stmt_semi(expr, self.next_id()), - span: expr.span} - } - fn alt_stmt(arms: ~[ast::arm], span: span, -v: @ast::expr) -> @ast::stmt { self.stmt( @@ -252,32 +171,6 @@ impl ext_ctxt: ext_ctxt_helpers { ast::expr_match(v, arms))) } - fn lit_str(span: span, s: @~str) -> @ast::expr { - self.expr( - span, - ast::expr_vstore( - self.expr( - span, - ast::expr_lit( - @{node: ast::lit_str(s), - span: span})), - ast::expr_vstore_uniq)) - } - - fn lit_uint(span: span, i: uint) -> @ast::expr { - self.expr( - span, - ast::expr_lit( - @{node: ast::lit_uint(i as u64, ast::ty_u), - span: span})) - } - - fn lambda(blk: ast::blk) -> @ast::expr { - let ext_cx = self; - let blk_e = self.expr(blk.span, ast::expr_block(blk)); - #ast{ || $(blk_e) } - } - fn clone_folder() -> fold::ast_fold { fold::make_fold(@{ new_id: |_id| self.next_id(), diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index 99f837a4c84..ba48b0d3f5f 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -215,6 +215,86 @@ fn expand_auto_deserialize( } priv impl ext_ctxt { + fn expr(span: span, node: ast::expr_) -> @ast::expr { + @{id: self.next_id(), callee_id: self.next_id(), + node: node, span: span} + } + + fn path(span: span, strs: ~[ast::ident]) -> @ast::path { + @{span: span, global: false, idents: strs, rp: None, types: ~[]} + } + + fn path_tps(span: span, strs: ~[ast::ident], + tps: ~[@ast::ty]) -> @ast::path { + @{span: span, global: false, idents: strs, rp: None, types: tps} + } + + fn ty_path(span: span, strs: ~[ast::ident], + tps: ~[@ast::ty]) -> @ast::ty { + @{id: self.next_id(), + node: ast::ty_path(self.path_tps(span, strs, tps), self.next_id()), + span: span} + } + + fn binder_pat(span: span, nm: ast::ident) -> @ast::pat { + let path = @{span: span, global: false, idents: ~[nm], + rp: None, types: ~[]}; + @{id: self.next_id(), + node: ast::pat_ident(ast::bind_by_implicit_ref, + path, + None), + span: span} + } + + fn stmt(expr: @ast::expr) -> @ast::stmt { + @{node: ast::stmt_semi(expr, self.next_id()), + span: expr.span} + } + + fn lit_str(span: span, s: @~str) -> @ast::expr { + self.expr( + span, + ast::expr_vstore( + self.expr( + span, + ast::expr_lit( + @{node: ast::lit_str(s), + span: span})), + ast::expr_vstore_uniq)) + } + + fn lit_uint(span: span, i: uint) -> @ast::expr { + self.expr( + span, + ast::expr_lit( + @{node: ast::lit_uint(i as u64, ast::ty_u), + span: span})) + } + + fn lambda(blk: ast::blk) -> @ast::expr { + let ext_cx = self; + let blk_e = self.expr(blk.span, ast::expr_block(blk)); + #ast{ || $(blk_e) } + } + + fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk { + {node: {view_items: ~[], + stmts: stmts, + expr: None, + id: self.next_id(), + rules: ast::default_blk}, + span: span} + } + + fn expr_blk(expr: @ast::expr) -> ast::blk { + {node: {view_items: ~[], + stmts: ~[], + expr: Some(expr), + id: self.next_id(), + rules: ast::default_blk}, + span: expr.span} + } + fn expr_path(span: span, strs: ~[ast::ident]) -> @ast::expr { self.expr(span, ast::expr_path(self.path(span, strs))) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 53880baea9b..794c5233e21 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -64,6 +64,7 @@ enum syntax_extension { // A temporary hard-coded map of methods for expanding syntax extension // AST nodes into full ASTs +#[cfg(stage0)] fn syntax_expander_table() -> HashMap<~str, syntax_extension> { fn builtin(f: syntax_expander_) -> syntax_extension {normal({expander: f, span: None})} @@ -122,6 +123,69 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> { return syntax_expanders; } +#[cfg(stage1)] +#[cfg(stage2)] +fn syntax_expander_table() -> HashMap<~str, syntax_extension> { + fn builtin(f: syntax_expander_) -> syntax_extension + {normal({expander: f, span: None})} + fn builtin_expr_tt(f: syntax_expander_tt_) -> syntax_extension { + expr_tt({expander: f, span: None}) + } + fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension { + item_tt({expander: f, span: None}) + } + let syntax_expanders = HashMap(); + syntax_expanders.insert(~"macro", + macro_defining(ext::simplext::add_new_extension)); + syntax_expanders.insert(~"macro_rules", + builtin_item_tt( + ext::tt::macro_rules::add_new_extension)); + syntax_expanders.insert(~"fmt", builtin(ext::fmt::expand_syntax_ext)); + syntax_expanders.insert( + ~"auto_serialize", + item_decorator(ext::auto_serialize2::expand_auto_serialize)); + syntax_expanders.insert( + ~"auto_deserialize", + item_decorator(ext::auto_serialize2::expand_auto_deserialize)); + syntax_expanders.insert( + ~"auto_serialize2", + item_decorator(ext::auto_serialize2::expand_auto_serialize)); + syntax_expanders.insert( + ~"auto_deserialize2", + item_decorator(ext::auto_serialize2::expand_auto_deserialize)); + syntax_expanders.insert(~"env", builtin(ext::env::expand_syntax_ext)); + syntax_expanders.insert(~"concat_idents", + builtin(ext::concat_idents::expand_syntax_ext)); + syntax_expanders.insert(~"ident_to_str", + builtin(ext::ident_to_str::expand_syntax_ext)); + syntax_expanders.insert(~"log_syntax", + builtin_expr_tt( + ext::log_syntax::expand_syntax_ext)); + syntax_expanders.insert(~"ast", + builtin(ext::qquote::expand_ast)); + syntax_expanders.insert(~"line", + builtin(ext::source_util::expand_line)); + syntax_expanders.insert(~"col", + builtin(ext::source_util::expand_col)); + syntax_expanders.insert(~"file", + builtin(ext::source_util::expand_file)); + syntax_expanders.insert(~"stringify", + builtin(ext::source_util::expand_stringify)); + syntax_expanders.insert(~"include", + builtin(ext::source_util::expand_include)); + syntax_expanders.insert(~"include_str", + builtin(ext::source_util::expand_include_str)); + syntax_expanders.insert(~"include_bin", + builtin(ext::source_util::expand_include_bin)); + syntax_expanders.insert(~"module_path", + builtin(ext::source_util::expand_mod)); + syntax_expanders.insert(~"proto", + builtin_item_tt(ext::pipes::expand_proto)); + syntax_expanders.insert( + ~"trace_macros", + builtin_expr_tt(ext::trace_macros::expand_trace_macros)); + return syntax_expanders; +} // One of these is made during expansion and incrementally updated as we go; // when a macro expansion occurs, the resulting nodes have the backtrace() diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 38abf5f445c..4a6bac9cd64 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -128,6 +128,7 @@ mod ext { mod ident_to_str; #[legacy_exports] mod log_syntax; + #[cfg(stage0)] #[legacy_exports] mod auto_serialize; #[legacy_exports] |
