diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2011-07-06 19:00:00 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2011-07-07 12:53:17 -0700 |
| commit | 0e2fff53375eba748b6d6727f69a2560f96bc8ec (patch) | |
| tree | 0c7e27b7d5cf9fe41a1fc00cdbcbf87baf71368f /src/comp/syntax/ext | |
| parent | bbcbaa6601a56c543f9200ce3bc047c366eff3ed (diff) | |
| download | rust-0e2fff53375eba748b6d6727f69a2560f96bc8ec.tar.gz rust-0e2fff53375eba748b6d6727f69a2560f96bc8ec.zip | |
rustc: Change lots of AST nodes to use interior vectors
Diffstat (limited to 'src/comp/syntax/ext')
| -rw-r--r-- | src/comp/syntax/ext/base.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ext/env.rs | 5 | ||||
| -rw-r--r-- | src/comp/syntax/ext/fmt.rs | 29 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 21 |
4 files changed, 31 insertions, 28 deletions
diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index 766dd9f3f28..7b0accb573b 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -8,8 +8,8 @@ import std::map::new_str_hash; import codemap; type syntax_expander = - fn(&ext_ctxt, span, &vec[@ast::expr], option::t[str]) -> @ast::expr; -type macro_definer = fn(&ext_ctxt, span, &vec[@ast::expr], + fn(&ext_ctxt, span, &(@ast::expr)[], option::t[str]) -> @ast::expr; +type macro_definer = fn(&ext_ctxt, span, &(@ast::expr)[], option::t[str]) -> tup(str, syntax_extension); tag syntax_extension { diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 7b12c045898..fad55953519 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -5,6 +5,7 @@ * should all get sucked into either the compiler syntax extension plugin * interface. */ +import std::ivec; import std::str; import std::vec; import std::option; @@ -12,9 +13,9 @@ import std::generic_os; import base::*; export expand_syntax_ext; -fn expand_syntax_ext(&ext_ctxt cx, codemap::span sp, &vec[@ast::expr] args, +fn expand_syntax_ext(&ext_ctxt cx, codemap::span sp, &(@ast::expr)[] args, option::t[str] body) -> @ast::expr { - if (vec::len[@ast::expr](args) != 1u) { + if (ivec::len[@ast::expr](args) != 1u) { cx.span_fatal(sp, "malformed #env call"); } // FIXME: if this was more thorough it would manufacture an diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index c7e2787d502..0f3b38a808b 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -5,6 +5,7 @@ * should all get sucked into either the standard library extfmt module or the * compiler syntax extension plugin interface. */ +import std::ivec; import std::str; import std::vec; import std::option; @@ -15,9 +16,9 @@ import base::*; import codemap::span; export expand_syntax_ext; -fn expand_syntax_ext(&ext_ctxt cx, span sp, &vec[@ast::expr] args, +fn expand_syntax_ext(&ext_ctxt cx, span sp, &(@ast::expr)[] args, option::t[str] body) -> @ast::expr { - if (vec::len[@ast::expr](args) == 0u) { + if (ivec::len[@ast::expr](args) == 0u) { cx.span_fatal(sp, "#fmt requires a format string"); } auto fmt = expr_to_str(cx, args.(0), "first argument to #fmt must be a " @@ -37,7 +38,7 @@ fn expand_syntax_ext(&ext_ctxt cx, span sp, &vec[@ast::expr] args, // be factored out in common with other code that builds expressions. // FIXME: Cleanup the naming of these functions fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces, - vec[@ast::expr] args) -> @ast::expr { + &(@ast::expr)[] args) -> @ast::expr { fn make_new_lit(&ext_ctxt cx, span sp, ast::lit_ lit) -> @ast::expr { auto sp_lit = @rec(node=lit, span=sp); @@ -67,26 +68,26 @@ fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces, auto pathexpr = ast::expr_path(sp_path); ret @rec(id=cx.next_id(), node=pathexpr, span=sp); } - fn make_vec_expr(&ext_ctxt cx, span sp, vec[@ast::expr] exprs) -> + fn make_vec_expr(&ext_ctxt cx, span sp, &(@ast::expr)[] exprs) -> @ast::expr { auto vecexpr = ast::expr_vec(exprs, ast::imm, ast::sk_rc); ret @rec(id=cx.next_id(), node=vecexpr, span=sp); } fn make_call(&ext_ctxt cx, span sp, &ast::ident[] fn_path, - vec[@ast::expr] args) -> @ast::expr { + &(@ast::expr)[] args) -> @ast::expr { auto pathexpr = make_path_expr(cx, sp, fn_path); auto callexpr = ast::expr_call(pathexpr, args); ret @rec(id=cx.next_id(), node=callexpr, span=sp); } fn make_rec_expr(&ext_ctxt cx, span sp, vec[tup(ast::ident, @ast::expr)] fields) -> @ast::expr { - let vec[ast::field] astfields = []; + let ast::field[] astfields = ~[]; for (tup(ast::ident, @ast::expr) field in fields) { auto ident = field._0; auto val = field._1; auto astfield = rec(node=rec(mut=ast::imm, ident=ident, expr=val), span=sp); - astfields += [astfield]; + astfields += ~[astfield]; } auto recexpr = ast::expr_rec(astfields, option::none[@ast::expr]); ret @rec(id=cx.next_id(), node=recexpr, span=sp); @@ -109,7 +110,7 @@ fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces, @ast::expr { fn make_flags(&ext_ctxt cx, span sp, vec[flag] flags) -> @ast::expr { - let vec[@ast::expr] flagexprs = []; + let (@ast::expr)[] flagexprs = ~[]; for (flag f in flags) { auto fstr; alt (f) { @@ -121,14 +122,14 @@ fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces, case (flag_sign_always) { fstr = "flag_sign_always"; } case (flag_alternate) { fstr = "flag_alternate"; } } - flagexprs += [make_rt_path_expr(cx, sp, fstr)]; + flagexprs += ~[make_rt_path_expr(cx, sp, fstr)]; } // FIXME: 0-length vectors can't have their type inferred // through the rec that these flags are a member of, so // this is a hack placeholder flag - if (vec::len[@ast::expr](flagexprs) == 0u) { - flagexprs += [make_rt_path_expr(cx, sp, "flag_none")]; + if (ivec::len[@ast::expr](flagexprs) == 0u) { + flagexprs += ~[make_rt_path_expr(cx, sp, "flag_none")]; } ret make_vec_expr(cx, sp, flagexprs); } @@ -141,7 +142,7 @@ fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces, case (count_is(?c)) { auto count_lit = make_new_int(cx, sp, c); auto count_is_path = make_path_vec("count_is"); - auto count_is_args = [count_lit]; + auto count_is_args = ~[count_lit]; ret make_call(cx, sp, count_is_path, count_is_args); } case (_) { @@ -185,7 +186,7 @@ fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces, auto fname = "conv_" + conv_type; auto path = make_path_vec(fname); auto cnv_expr = make_rt_conv_expr(cx, sp, cnv); - auto args = [cnv_expr, arg]; + auto args = ~[cnv_expr, arg]; ret make_call(cx, arg.span, path, args); } fn make_new_conv(&ext_ctxt cx, span sp, conv cnv, @ast::expr arg) @@ -328,7 +329,7 @@ fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces, auto fmt_sp = args.(0).span; auto n = 0u; auto tmp_expr = make_new_str(cx, sp, ""); - auto nargs = vec::len[@ast::expr](args); + auto nargs = ivec::len[@ast::expr](args); for (piece pc in pieces) { alt (pc) { case (piece_string(?s)) { diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 53b37da6c27..46b1fd636ce 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -34,7 +34,7 @@ fn position[T](&T x, &vec[T] v) -> option::t[uint] { } // substitute, in a position that's required to be an ident -fn subst_ident(&ext_ctxt cx, &vec[@ast::expr] args, +fn subst_ident(&ext_ctxt cx, &(@ast::expr)[] args, @vec[ident] param_names, &ident i, ast_fold fld) -> ident { alt (position(i, *param_names)) { case (some[uint](?idx)) { @@ -48,7 +48,7 @@ fn subst_ident(&ext_ctxt cx, &vec[@ast::expr] args, } } -fn subst_path(&ext_ctxt cx, &vec[@ast::expr] args, +fn subst_path(&ext_ctxt cx, &(@ast::expr)[] args, @vec[ident] param_names, &path_ p, ast_fold fld) -> path_ { // Don't substitute into qualified names. if (ivec::len(p.types) > 0u || ivec::len(p.idents) != 1u) { ret p; } @@ -70,7 +70,7 @@ fn subst_path(&ext_ctxt cx, &vec[@ast::expr] args, } -fn subst_expr(&ext_ctxt cx, &vec[@ast::expr] args, @vec[ident] param_names, +fn subst_expr(&ext_ctxt cx, &(@ast::expr)[] args, @vec[ident] param_names, &ast::expr_ e, ast_fold fld, fn(&ast::expr_, ast_fold) -> ast::expr_ orig) -> ast::expr_ { ret alt(e) { @@ -90,20 +90,21 @@ fn subst_expr(&ext_ctxt cx, &vec[@ast::expr] args, @vec[ident] param_names, } -fn add_new_extension(&ext_ctxt cx, span sp, &vec[@ast::expr] args, +fn add_new_extension(&ext_ctxt cx, span sp, &(@ast::expr)[] args, option::t[str] body) -> tup(str, syntax_extension) { - if (len(args) < 2u) { + if (ivec::len(args) < 2u) { cx.span_fatal(sp, "malformed extension description"); } - fn generic_extension(&ext_ctxt cx, span sp, &vec[@ast::expr] args, + fn generic_extension(&ext_ctxt cx, span sp, &(@ast::expr)[] args, option::t[str] body, @vec[ident] param_names, @ast::expr dest_form) -> @ast::expr { - if (len(args) != len(*param_names)) { + if (ivec::len(args) != len(*param_names)) { cx.span_fatal(sp, #fmt("extension expects %u arguments, got %u", - len(*param_names), len(args))); + len(*param_names), ivec::len(args))); } + // FIXME: This binds to alias arguments. auto afp = default_ast_fold(); auto f_pre = rec(fold_ident = bind subst_ident(cx, args, param_names, _, _), @@ -120,7 +121,7 @@ fn add_new_extension(&ext_ctxt cx, span sp, &vec[@ast::expr] args, let vec[ident] param_names = vec::empty[ident](); let uint idx = 1u; - while(1u+idx < len(args)) { + while(1u+idx < ivec::len(args)) { param_names += [expr_to_ident(cx, args.(idx), "this parameter name must be an identifier.")]; @@ -129,7 +130,7 @@ fn add_new_extension(&ext_ctxt cx, span sp, &vec[@ast::expr] args, ret tup(expr_to_str(cx, args.(0), "first arg must be a literal string."), normal(bind generic_extension(_,_,_,_,@param_names, - args.(len(args)-1u)))); + args.(ivec::len(args)-1u)))); } |
