Skip to content

Commit 152cbaa

Browse files
committed
Move functions from syntax::ast to syntax::ast_util
This leaves syntax::ast just defining the AST, which strikes me as somewhat nicer
1 parent a3affaa commit 152cbaa

33 files changed

+358
-314
lines changed

src/comp/front/attr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import std::str;
55
import std::map;
66
import std::option;
77
import syntax::ast;
8+
import syntax::ast_util;
89
import util::common;
910
import driver::session;
1011

@@ -189,7 +190,7 @@ fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) {
189190
}
190191

191192
fn span<T>(item: &T) -> ast::spanned<T> {
192-
ret {node: item, span: ast::mk_sp(0u, 0u)};
193+
ret {node: item, span: ast_util::dummy_sp()};
193194
}
194195

195196
fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item {

src/comp/front/test.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import std::option;
44
import std::vec;
55
import syntax::ast;
6+
import syntax::ast_util;
7+
import syntax::ast_util::dummy_sp;
68
import syntax::fold;
79
import syntax::print::pprust;
810
import front::attr;
@@ -88,7 +90,7 @@ fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) ->
8890
@ast::item {
8991

9092
cx.path += [i.ident];
91-
log #fmt["current path: %s", ast::path_name_i(cx.path)];
93+
log #fmt["current path: %s", ast_util::path_name_i(cx.path)];
9294

9395
if is_test_fn(i) {
9496
log "this is a test function";
@@ -161,15 +163,15 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item {
161163
attrs: [],
162164
id: cx.next_node_id(),
163165
node: item_,
164-
span: ast::dummy_sp()};
166+
span: dummy_sp()};
165167

166168
log #fmt["Synthetic test module:\n%s\n", pprust::item_to_str(@item)];
167169

168170
ret @item;
169171
}
170172

171173
fn nospan<T>(t: &T) -> ast::spanned<T> {
172-
ret {node: t, span: ast::dummy_sp()};
174+
ret {node: t, span: dummy_sp()};
173175
}
174176

175177
fn mk_tests(cx: &test_ctxt) -> @ast::item {
@@ -199,7 +201,7 @@ fn mk_tests(cx: &test_ctxt) -> @ast::item {
199201
attrs: [],
200202
id: cx.next_node_id(),
201203
node: item_,
202-
span: ast::dummy_sp()};
204+
span: dummy_sp()};
203205
ret @item;
204206
}
205207

@@ -237,20 +239,20 @@ fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr {
237239

238240
ret @{id: cx.next_node_id(),
239241
node: ast::expr_vec(descs, ast::imm),
240-
span: ast::dummy_sp()};
242+
span: dummy_sp()};
241243
}
242244

243245
fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
244246
let path = test.path;
245247

246-
log #fmt["encoding %s", ast::path_name_i(path)];
248+
log #fmt["encoding %s", ast_util::path_name_i(path)];
247249

248250
let name_lit: ast::lit =
249-
nospan(ast::lit_str(ast::path_name_i(path), ast::sk_rc));
251+
nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_rc));
250252
let name_expr: ast::expr =
251253
{id: cx.next_node_id(),
252254
node: ast::expr_lit(@name_lit),
253-
span: ast::dummy_sp()};
255+
span: dummy_sp()};
254256

255257
let name_field: ast::field =
256258
nospan({mut: ast::imm, ident: "name", expr: @name_expr});
@@ -260,7 +262,7 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
260262
let fn_expr: ast::expr =
261263
{id: cx.next_node_id(),
262264
node: ast::expr_path(fn_path),
263-
span: ast::dummy_sp()};
265+
span: dummy_sp()};
264266

265267
let fn_field: ast::field =
266268
nospan({mut: ast::imm, ident: "fn", expr: @fn_expr});
@@ -270,15 +272,15 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
270272
let ignore_expr: ast::expr =
271273
{id: cx.next_node_id(),
272274
node: ast::expr_lit(@ignore_lit),
273-
span: ast::dummy_sp()};
275+
span: dummy_sp()};
274276

275277
let ignore_field: ast::field =
276278
nospan({mut: ast::imm, ident: "ignore", expr: @ignore_expr});
277279

278280
let desc_rec_: ast::expr_ =
279281
ast::expr_rec([name_field, fn_field, ignore_field], option::none);
280282
let desc_rec: ast::expr =
281-
{id: cx.next_node_id(), node: desc_rec_, span: ast::dummy_sp()};
283+
{id: cx.next_node_id(), node: desc_rec_, span: dummy_sp()};
282284
ret @desc_rec;
283285
}
284286

@@ -307,7 +309,7 @@ fn mk_main(cx: &test_ctxt) -> @ast::item {
307309
{stmts: [],
308310
expr: option::some(test_main_call_expr),
309311
id: cx.next_node_id()};
310-
let body = {node: body_, span: ast::dummy_sp()};
312+
let body = {node: body_, span: dummy_sp()};
311313

312314
let fn_ = {decl: decl, proto: proto, body: body};
313315

@@ -317,7 +319,7 @@ fn mk_main(cx: &test_ctxt) -> @ast::item {
317319
attrs: [],
318320
id: cx.next_node_id(),
319321
node: item_,
320-
span: ast::dummy_sp()};
322+
span: dummy_sp()};
321323
ret @item;
322324
}
323325

@@ -330,7 +332,7 @@ fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr {
330332
let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
331333

332334
let args_path_expr: ast::expr =
333-
{id: cx.next_node_id(), node: args_path_expr_, span: ast::dummy_sp()};
335+
{id: cx.next_node_id(), node: args_path_expr_, span: dummy_sp()};
334336

335337
// Call __test::test to generate the vector of test_descs
336338
let test_path: ast::path =
@@ -339,12 +341,12 @@ fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr {
339341
let test_path_expr_: ast::expr_ = ast::expr_path(test_path);
340342

341343
let test_path_expr: ast::expr =
342-
{id: cx.next_node_id(), node: test_path_expr_, span: ast::dummy_sp()};
344+
{id: cx.next_node_id(), node: test_path_expr_, span: dummy_sp()};
343345

344346
let test_call_expr_: ast::expr_ = ast::expr_call(@test_path_expr, []);
345347

346348
let test_call_expr: ast::expr =
347-
{id: cx.next_node_id(), node: test_call_expr_, span: ast::dummy_sp()};
349+
{id: cx.next_node_id(), node: test_call_expr_, span: dummy_sp()};
348350

349351
// Call std::test::test_main
350352
let test_main_path: ast::path =
@@ -357,7 +359,7 @@ fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr {
357359
let test_main_path_expr: ast::expr =
358360
{id: cx.next_node_id(),
359361
node: test_main_path_expr_,
360-
span: ast::dummy_sp()};
362+
span: dummy_sp()};
361363

362364
let test_main_call_expr_: ast::expr_ =
363365
ast::expr_call(@test_main_path_expr,
@@ -366,7 +368,7 @@ fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr {
366368
let test_main_call_expr: ast::expr =
367369
{id: cx.next_node_id(),
368370
node: test_main_call_expr_,
369-
span: ast::dummy_sp()};
371+
span: dummy_sp()};
370372

371373
ret @test_main_call_expr;
372374
}

src/comp/metadata/creader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import driver::session;
44
import syntax::ast;
5+
import syntax::ast_util;
56
import lib::llvm::False;
67
import lib::llvm::llvm;
78
import lib::llvm::mk_object_file;
@@ -262,7 +263,7 @@ fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map {
262263
log "need to load it";
263264
// This is a new one so we've got to load it
264265
// FIXME: Need better error reporting than just a bogus span
265-
let fake_span = ast::dummy_sp();
266+
let fake_span = ast_util::dummy_sp();
266267
let local_cnum = resolve_crate(e, cname, [], fake_span);
267268
cnum_map.insert(extrn_cnum, local_cnum);
268269
}

src/comp/metadata/decoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import std::str;
77
import std::io;
88
import std::map::hashmap;
99
import syntax::ast;
10+
import syntax::ast_util;
1011
import front::attr;
1112
import middle::ty;
1213
import common::*;
@@ -335,7 +336,7 @@ fn get_attributes(md: &ebml::doc) -> [ast::attribute] {
335336
let meta_item = meta_items[0];
336337
attrs +=
337338
[{node: {style: ast::attr_outer, value: *meta_item},
338-
span: ast::dummy_sp()}];
339+
span: ast_util::dummy_sp()}];
339340
}
340341
}
341342
option::none. { }

src/comp/metadata/encoder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import std::option::none;
1010
import std::ebml;
1111
import std::map;
1212
import syntax::ast::*;
13+
import syntax::ast_util;
14+
import syntax::ast_util::local_def;
1315
import common::*;
1416
import middle::trans_common::crate_ctxt;
1517
import middle::ty;
@@ -71,7 +73,7 @@ fn encode_native_module_item_paths(ebml_w: &ebml::writer, nmod: &native_mod,
7173
fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod,
7274
path: &[str], index: &mutable [entry<str>]) {
7375
for it: @item in module.items {
74-
if !is_exported(it.ident, module) { cont; }
76+
if !ast_util::is_exported(it.ident, module) { cont; }
7577
alt it.node {
7678
item_const(_, _) {
7779
add_to_index(ebml_w, path, index, it.ident);

src/comp/metadata/tydecode.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import std::option::none;
88
import std::option::some;
99
import syntax::ast;
1010
import syntax::ast::*;
11-
import ast::respan;
11+
import syntax::ast_util;
12+
import syntax::ast_util::respan;
1213
import middle::ty;
1314

1415
export parse_def_id;
@@ -106,7 +107,7 @@ fn parse_path(st: @pstate, sd: str_def) -> ast::path {
106107
':' { next(st); next(st); }
107108
c {
108109
if c == '(' {
109-
ret respan(ast::dummy_sp(),
110+
ret respan(ast_util::dummy_sp(),
110111
{global: false, idents: idents, types: []});
111112
} else { idents += [parse_ident_(st, sd, is_last)]; }
112113
}
@@ -152,7 +153,7 @@ fn parse_ty_constr_arg(st: @pstate, sd: str_def) ->
152153

153154
fn parse_constr<@T>(st: @pstate, sd: str_def, pser: arg_parser<T>) ->
154155
@ty::constr_general<T> {
155-
let sp = ast::dummy_sp(); // FIXME: use a real span
156+
let sp = ast_util::dummy_sp(); // FIXME: use a real span
156157
let args: [@sp_constr_arg<T>] = [];
157158
let pth: path = parse_path(st, sd);
158159
let ignore: char = next(st) as char;

src/comp/middle/alias.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import syntax::ast;
3+
import syntax::ast_util;
34
import ast::ident;
45
import ast::fn_ident;
56
import ast::node_id;
@@ -195,7 +196,7 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) ->
195196
if arg_t.mode == ty::mo_alias(true) {
196197
alt path_def(cx, arg) {
197198
some(def) {
198-
let dnum = ast::def_id_of_def(def).node;
199+
let dnum = ast_util::def_id_of_def(def).node;
199200
if def_is_local(def, true) {
200201
if is_immutable_alias(cx, sc, dnum) {
201202
cx.tcx.sess.span_err(
@@ -302,7 +303,7 @@ fn check_tail_call(cx: &ctx, call: &@ast::expr) {
302303
alt args[i].node {
303304
ast::expr_path(_) {
304305
let def = cx.tcx.def_map.get(args[i].id);
305-
let dnum = ast::def_id_of_def(def).node;
306+
let dnum = ast_util::def_id_of_def(def).node;
306307
alt cx.local_map.find(dnum) {
307308
some(arg(ast::alias(mut))) {
308309
if mut_a && !mut {
@@ -352,7 +353,7 @@ fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope,
352353
}
353354

354355
fn arm_defnums(arm: &ast::arm) -> [node_id] {
355-
ret ast::pat_binding_ids(arm.pats[0]);
356+
ret ast_util::pat_binding_ids(arm.pats[0]);
356357
}
357358

358359
fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
@@ -361,7 +362,7 @@ fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
361362
alt call.node {
362363
ast::expr_call(f, args) {
363364
let data = check_call(cx, f, args, sc);
364-
let bindings = ast::pat_binding_ids(local.node.pat);
365+
let bindings = ast_util::pat_binding_ids(local.node.pat);
365366
let new_sc =
366367
@{root_vars: data.root_vars,
367368
block_defnum: bindings[vec::len(bindings) - 1u],
@@ -393,7 +394,7 @@ fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
393394
util::ppaux::ty_to_str(cx.tcx, seq_t));
394395
}
395396
}
396-
let bindings = ast::pat_binding_ids(local.node.pat);
397+
let bindings = ast_util::pat_binding_ids(local.node.pat);
397398
let new_sc =
398399
@{root_vars: root_def,
399400
block_defnum: bindings[vec::len(bindings) - 1u],
@@ -408,7 +409,7 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
408409
assign: bool, sc: &scope) {
409410
let def = cx.tcx.def_map.get(id);
410411
if !def_is_local(def, true) { ret; }
411-
let my_defnum = ast::def_id_of_def(def).node;
412+
let my_defnum = ast_util::def_id_of_def(def).node;
412413
let var_t = ty::expr_ty(cx.tcx, ex);
413414
for r: restrict in *sc {
414415

@@ -429,7 +430,7 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
429430
fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt<scope>) {
430431
alt dest.node {
431432
ast::expr_path(p) {
432-
let dnum = ast::def_id_of_def(cx.tcx.def_map.get(dest.id)).node;
433+
let dnum = ast_util::def_id_of_def(cx.tcx.def_map.get(dest.id)).node;
433434
cx.mut_map.insert(dnum, ());
434435
if is_immutable_alias(*cx, sc, dnum) {
435436
cx.tcx.sess.span_err(dest.span, "assigning to immutable alias");
@@ -515,15 +516,17 @@ fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) {
515516
let msg =
516517
alt prob {
517518
overwritten(sp, wpt) {
518-
{span: sp, msg: "overwriting " + ast::path_name(wpt)}
519+
{span: sp, msg: "overwriting " + ast_util::path_name(wpt)}
519520
}
520521
val_taken(sp, vpt) {
521-
{span: sp, msg: "taking the value of " + ast::path_name(vpt)}
522+
{span: sp,
523+
msg: "taking the value of " + ast_util::path_name(vpt)}
522524
}
523525
};
524526
cx.tcx.sess.span_err(msg.span,
525527
msg.msg + " will invalidate alias " +
526-
ast::path_name(p) + ", which is still used");
528+
ast_util::path_name(p) +
529+
", which is still used");
527530
}
528531
}
529532

@@ -660,7 +663,7 @@ fn path_def(cx: &ctx, ex: &@ast::expr) -> option::t<ast::def> {
660663
fn path_def_id(cx: &ctx, ex: &@ast::expr) -> option::t<ast::def_id> {
661664
alt ex.node {
662665
ast::expr_path(_) {
663-
ret some(ast::def_id_of_def(cx.tcx.def_map.get(ex.id)));
666+
ret some(ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id)));
664667
}
665668
_ { ret none; }
666669
}

src/comp/middle/ast_map.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ fn node_span(node: &ast_node) -> codemap::span {
125125

126126
#[cfg(test)]
127127
mod test {
128+
import syntax::ast_util;
129+
128130
#[test]
129131
fn test_node_span_item() {
130-
let expected: codemap::span = mk_sp(20u, 30u);
132+
let expected: codemap::span = ast_util::mk_sp(20u, 30u);
131133
let node =
132134
node_item(@{ident: "test",
133135
attrs: [],
@@ -139,7 +141,7 @@ mod test {
139141

140142
#[test]
141143
fn test_node_span_obj_ctor() {
142-
let expected: codemap::span = mk_sp(20u, 30u);
144+
let expected: codemap::span = ast_util::mk_sp(20u, 30u);
143145
let node =
144146
node_obj_ctor(@{ident: "test",
145147
attrs: [],
@@ -151,7 +153,7 @@ mod test {
151153

152154
#[test]
153155
fn test_node_span_native_item() {
154-
let expected: codemap::span = mk_sp(20u, 30u);
156+
let expected: codemap::span = ast_util::mk_sp(20u, 30u);
155157
let node =
156158
node_native_item(@{ident: "test",
157159
attrs: [],
@@ -163,7 +165,7 @@ mod test {
163165

164166
#[test]
165167
fn test_node_span_expr() {
166-
let expected: codemap::span = mk_sp(20u, 30u);
168+
let expected: codemap::span = ast_util::mk_sp(20u, 30u);
167169
let node = node_expr(@{id: 0, node: expr_break, span: expected});
168170
assert (node_span(node) == expected);
169171
}

0 commit comments

Comments
 (0)