Skip to content

Commit 4c68084

Browse files
committed
Convert most codemap types from records to structs
1 parent f05e2da commit 4c68084

File tree

9 files changed

+52
-34
lines changed

9 files changed

+52
-34
lines changed

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pure fn dummy_spanned<T>(+t: T) -> spanned<T> {
1515

1616
/* assuming that we're not in macro expansion */
1717
pure fn mk_sp(lo: uint, hi: uint) -> span {
18-
{lo: lo, hi: hi, expn_info: None}
18+
span {lo: lo, hi: hi, expn_info: None}
1919
}
2020

2121
// make this a const, once the compiler supports it

src/libsyntax/codemap.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::serialization::{Serializable,
66

77
export filename;
88
export filemap;
9+
export filemap_;
910
export span;
1011
export file_substr;
1112
export fss_none;
@@ -34,7 +35,9 @@ export new_codemap;
3435

3536
type filename = ~str;
3637

37-
type file_pos = {ch: uint, byte: uint};
38+
struct file_pos {
39+
ch: uint, byte: uint
40+
}
3841

3942
impl file_pos : cmp::Eq {
4043
pure fn eq(other: &file_pos) -> bool {
@@ -55,23 +58,34 @@ enum file_substr {
5558
fss_external({filename: ~str, line: uint, col: uint})
5659
}
5760

58-
type filemap =
59-
@{name: filename, substr: file_substr, src: @~str,
60-
start_pos: file_pos, mut lines: ~[file_pos]};
61+
struct filemap_ {
62+
name: filename, substr: file_substr, src: @~str,
63+
start_pos: file_pos, mut lines: ~[file_pos]
64+
}
65+
66+
type filemap = @filemap_;
67+
68+
struct CodeMap_ {
69+
files: DVec<filemap>
70+
}
6171

62-
type CodeMap = @{files: DVec<filemap>};
72+
type CodeMap = @CodeMap_;
6373

64-
type loc = {file: filemap, line: uint, col: uint};
74+
struct loc {
75+
file: filemap, line: uint, col: uint
76+
}
6577

66-
fn new_codemap() -> CodeMap { @{files: DVec()} }
78+
fn new_codemap() -> CodeMap { @CodeMap_ {files: DVec()} }
6779

6880
fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
6981
src: @~str,
7082
start_pos_ch: uint, start_pos_byte: uint)
7183
-> filemap {
72-
return @{name: filename, substr: substr, src: src,
73-
start_pos: {ch: start_pos_ch, byte: start_pos_byte},
74-
mut lines: ~[{ch: start_pos_ch, byte: start_pos_byte}]};
84+
return @filemap_ {
85+
name: filename, substr: substr, src: src,
86+
start_pos: file_pos {ch: start_pos_ch, byte: start_pos_byte},
87+
mut lines: ~[file_pos {ch: start_pos_ch, byte: start_pos_byte}]
88+
};
7589
}
7690

7791
fn new_filemap(+filename: filename, src: @~str,
@@ -88,7 +102,7 @@ fn mk_substr_filename(cm: CodeMap, sp: span) -> ~str
88102
}
89103

90104
fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
91-
file.lines.push({ch: chpos, byte: byte_pos + file.start_pos.byte});
105+
file.lines.push(file_pos {ch: chpos, byte: byte_pos + file.start_pos.byte});
92106
}
93107

94108
type lookup_fn = pure fn(file_pos) -> uint;
@@ -118,7 +132,7 @@ fn lookup_line(map: CodeMap, pos: uint, lookup: lookup_fn)
118132

119133
fn lookup_pos(map: CodeMap, pos: uint, lookup: lookup_fn) -> loc {
120134
let {fm: f, line: a} = lookup_line(map, pos, lookup);
121-
return {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
135+
return loc {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
122136
}
123137

124138
fn lookup_char_pos(map: CodeMap, pos: uint) -> loc {
@@ -160,9 +174,9 @@ fn adjust_span(map: CodeMap, sp: span) -> span {
160174
match (line.fm.substr) {
161175
fss_none => sp,
162176
fss_internal(s) => {
163-
adjust_span(map, {lo: s.lo + (sp.lo - line.fm.start_pos.ch),
164-
hi: s.lo + (sp.hi - line.fm.start_pos.ch),
165-
expn_info: sp.expn_info})}
177+
adjust_span(map, span {lo: s.lo + (sp.lo - line.fm.start_pos.ch),
178+
hi: s.lo + (sp.hi - line.fm.start_pos.ch),
179+
expn_info: sp.expn_info})}
166180
fss_external(_) => sp
167181
}
168182
}
@@ -173,7 +187,7 @@ enum expn_info_ {
173187
}
174188
type expn_info = Option<@expn_info_>;
175189

176-
type span = {lo: uint, hi: uint, expn_info: expn_info};
190+
struct span {lo: uint, hi: uint, expn_info: expn_info}
177191

178192
impl span : cmp::Eq {
179193
pure fn eq(other: &span) -> bool {
@@ -207,7 +221,10 @@ fn span_to_str(sp: span, cm: CodeMap) -> ~str {
207221
lo.line, lo.col, hi.line, hi.col)
208222
}
209223

210-
type file_lines = {file: filemap, lines: ~[uint]};
224+
struct file_lines {
225+
file: filemap,
226+
lines: ~[uint]
227+
}
211228

212229
fn span_to_filename(sp: span, cm: codemap::CodeMap) -> filename {
213230
let lo = lookup_char_pos(cm, sp.lo);
@@ -221,7 +238,7 @@ fn span_to_lines(sp: span, cm: codemap::CodeMap) -> @file_lines {
221238
for uint::range(lo.line - 1u, hi.line as uint) |i| {
222239
lines.push(i);
223240
};
224-
return @{file: lo.file, lines: lines};
241+
return @file_lines {file: lo.file, lines: lines};
225242
}
226243

227244
fn get_line(fm: filemap, line: int) -> ~str unsafe {

src/libsyntax/ext/base.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::map::HashMap;
22
use parse::parser;
33
use diagnostic::span_handler;
44
use codemap::{CodeMap, span, expn_info, expanded_from};
5+
use ast_util::dummy_sp;
56

67
// obsolete old-style #macro code:
78
//
@@ -169,15 +170,15 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
169170
expanded_from({call_site: cs, callie: callie}) => {
170171
self.backtrace =
171172
Some(@expanded_from({
172-
call_site: {lo: cs.lo, hi: cs.hi,
173-
expn_info: self.backtrace},
173+
call_site: span {lo: cs.lo, hi: cs.hi,
174+
expn_info: self.backtrace},
174175
callie: callie}));
175176
}
176177
}
177178
}
178179
fn bt_pop() {
179180
match self.backtrace {
180-
Some(@expanded_from({call_site: {expn_info: prev, _}, _})) => {
181+
Some(@expanded_from({call_site: span {expn_info: prev, _}, _})) => {
181182
self.backtrace = prev
182183
}
183184
_ => self.bug(~"tried to pop without a push")
@@ -311,7 +312,7 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree])
311312

312313
// these spans won't matter, anyways
313314
fn ms(m: matcher_) -> matcher {
314-
{node: m, span: {lo: 0u, hi: 0u, expn_info: None}}
315+
{node: m, span: dummy_sp()}
315316
}
316317
let arg_nm = cx.parse_sess().interner.gensym(@~"arg");
317318

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
232232

233233
fn new_span(cx: ext_ctxt, sp: span) -> span {
234234
/* this discards information in the case of macro-defining macros */
235-
return {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
235+
return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
236236
}
237237

238238
// FIXME (#2247): this is a terrible kludge to inject some macros into

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn path(ids: ~[ident], span: span) -> @ast::path {
2424
}
2525

2626
fn empty_span() -> span {
27-
{lo: 0, hi: 0, expn_info: None}
27+
span {lo: 0, hi: 0, expn_info: None}
2828
}
2929

3030
trait append_types {
@@ -95,7 +95,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
9595
}
9696

9797
fn empty_span() -> span {
98-
{lo: 0, hi: 0, expn_info: self.backtrace()}
98+
span {lo: 0, hi: 0, expn_info: self.backtrace()}
9999
}
100100

101101
fn block_expr(b: ast::blk) -> @ast::expr {

src/libsyntax/ext/simplext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
177177
fn new_id(_old: node_id, cx: ext_ctxt) -> node_id { return cx.next_id(); }
178178
fn new_span(cx: ext_ctxt, sp: span) -> span {
179179
/* this discards information in the case of macro-defining macros */
180-
return {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
180+
return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
181181
}
182182
let afp = default_ast_fold();
183183
let f_pre =

src/libsyntax/ext/source_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use base::*;
2-
use codemap::span;
2+
use codemap::{span, loc, filemap_};
33
use print::pprust;
44
use build::{mk_base_vec_e,mk_uint,mk_u8,mk_uniq_str};
55

@@ -34,7 +34,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
3434
fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
3535
_body: ast::mac_body) -> @ast::expr {
3636
get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file");
37-
let { file: @{ name: filename, _ }, _ } =
37+
let loc { file: @filemap_ { name: filename, _ }, _ } =
3838
codemap::lookup_char_pos(cx.codemap(), sp.lo);
3939
return mk_uniq_str(cx, sp, filename);
4040
}

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ use macro_parser::{parse, parse_or_else, success, failure, named_match,
99
matched_seq, matched_nonterminal, error};
1010
use std::map::HashMap;
1111
use parse::token::special_idents;
12+
use ast_util::dummy_sp;
1213

1314
fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
1415
arg: ~[ast::token_tree]) -> base::mac_result {
1516
// these spans won't matter, anyways
1617
fn ms(m: matcher_) -> matcher {
17-
{node: m, span: {lo: 0u, hi: 0u, expn_info: None}}
18+
{node: m, span: dummy_sp()}
1819
}
1920

2021
let lhs_nm = cx.parse_sess().interner.gensym(@~"lhs");
@@ -65,7 +66,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
6566
}
6667

6768
// Which arm's failure should we report? (the one furthest along)
68-
let mut best_fail_spot = {lo: 0u, hi: 0u, expn_info: None};
69+
let mut best_fail_spot = dummy_sp();
6970
let mut best_fail_msg = ~"internal error: ran no matchers";
7071

7172
let s_d = cx.parse_sess().span_diagnostic;

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,9 +3415,8 @@ impl Parser {
34153415
|p| p.parse_token_tree());
34163416
let m = ast::mac_invoc_tt(pth, tts);
34173417
let m: ast::mac = {node: m,
3418-
span: {lo: self.span.lo,
3419-
hi: self.span.hi,
3420-
expn_info: None}};
3418+
span: mk_sp(self.span.lo,
3419+
self.span.hi)};
34213420
let item_ = item_mac(m);
34223421
return iovi_item(self.mk_item(lo, self.last_span.hi, id, item_,
34233422
visibility, attrs));

0 commit comments

Comments
 (0)