diff options
| author | Brian Anderson <[email protected]> | 2011-02-27 15:29:31 -0500 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-03-02 10:28:14 -0800 |
| commit | 5e06ec977f4446a7b19a09dd3a3781bcf26f8442 (patch) | |
| tree | 7aa9620fa069db8f7a40d60841c15b6ae3e66d06 | |
| parent | Parse parameter types for fmt extension (diff) | |
| download | rust-5e06ec977f4446a7b19a09dd3a3781bcf26f8442.tar.xz rust-5e06ec977f4446a7b19a09dd3a3781bcf26f8442.zip | |
Rewrite expand_syntax_ext to avoid a mysterious memory leak
| -rw-r--r-- | src/comp/front/parser.rs | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index e5f68033..7a7a863c 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -656,10 +656,8 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr { some(token.COMMA), pf, p); hi = es.span; - ex = ast.expr_ext(pth, es.node, none[@ast.expr], - none[@ast.expr], ast.ann_none); - // FIXME: Here is probably not the right place for this - ex = expand_syntax_ext(p, @spanned(lo, hi, ex)).node; + ex = expand_syntax_ext(p, es.span, pth, es.node, + none[@ast.expr]); } case (token.FAIL) { @@ -748,24 +746,23 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr { * rust crates. At the moment we have neither. */ -impure fn expand_syntax_ext(parser p, @ast.expr ext) -> @ast.expr { - check (ast.is_ext_expr(ext)); - alt (ext.node) { - case (ast.expr_ext(?path, ?args, ?body, _, ?ann)) { - check (_vec.len[ast.ident](path.node.idents) > 0u); - auto extname = path.node.idents.(0); - if (_str.eq(extname, "fmt")) { - auto expanded = extfmt.expand_syntax_ext(args, body); - auto newexpr = ast.expr_ext(path, args, body, - some[@ast.expr](expanded), ann); - - ret @spanned(ext.span, ext.span, newexpr); - } else { - p.err("unknown syntax extension"); - } - } +impure fn expand_syntax_ext(parser p, ast.span sp, + &ast.path path, vec[@ast.expr] args, + option.t[@ast.expr] body) -> ast.expr_ { + + check (_vec.len[ast.ident](path.node.idents) > 0u); + auto extname = path.node.idents.(0); + if (_str.eq(extname, "fmt")) { + auto expanded = extfmt.expand_syntax_ext(args, body); + auto newexpr = ast.expr_ext(path, args, body, + some[@ast.expr](expanded), + ast.ann_none); + + ret newexpr; + } else { + p.err("unknown syntax extension"); + fail; } - fail; } impure fn extend_expr_by_ident(parser p, span lo, span hi, |