Convert most codemap types from records to structs
This commit is contained in:
parent
f05e2da709
commit
4c68084963
9 changed files with 52 additions and 34 deletions
|
|
@ -15,7 +15,7 @@ pure fn dummy_spanned<T>(+t: T) -> spanned<T> {
|
|||
|
||||
/* assuming that we're not in macro expansion */
|
||||
pure fn mk_sp(lo: uint, hi: uint) -> span {
|
||||
{lo: lo, hi: hi, expn_info: None}
|
||||
span {lo: lo, hi: hi, expn_info: None}
|
||||
}
|
||||
|
||||
// make this a const, once the compiler supports it
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use std::serialization::{Serializable,
|
|||
|
||||
export filename;
|
||||
export filemap;
|
||||
export filemap_;
|
||||
export span;
|
||||
export file_substr;
|
||||
export fss_none;
|
||||
|
|
@ -34,7 +35,9 @@ export new_codemap;
|
|||
|
||||
type filename = ~str;
|
||||
|
||||
type file_pos = {ch: uint, byte: uint};
|
||||
struct file_pos {
|
||||
ch: uint, byte: uint
|
||||
}
|
||||
|
||||
impl file_pos : cmp::Eq {
|
||||
pure fn eq(other: &file_pos) -> bool {
|
||||
|
|
@ -55,23 +58,34 @@ enum file_substr {
|
|||
fss_external({filename: ~str, line: uint, col: uint})
|
||||
}
|
||||
|
||||
type filemap =
|
||||
@{name: filename, substr: file_substr, src: @~str,
|
||||
start_pos: file_pos, mut lines: ~[file_pos]};
|
||||
struct filemap_ {
|
||||
name: filename, substr: file_substr, src: @~str,
|
||||
start_pos: file_pos, mut lines: ~[file_pos]
|
||||
}
|
||||
|
||||
type CodeMap = @{files: DVec<filemap>};
|
||||
type filemap = @filemap_;
|
||||
|
||||
type loc = {file: filemap, line: uint, col: uint};
|
||||
struct CodeMap_ {
|
||||
files: DVec<filemap>
|
||||
}
|
||||
|
||||
fn new_codemap() -> CodeMap { @{files: DVec()} }
|
||||
type CodeMap = @CodeMap_;
|
||||
|
||||
struct loc {
|
||||
file: filemap, line: uint, col: uint
|
||||
}
|
||||
|
||||
fn new_codemap() -> CodeMap { @CodeMap_ {files: DVec()} }
|
||||
|
||||
fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
|
||||
src: @~str,
|
||||
start_pos_ch: uint, start_pos_byte: uint)
|
||||
-> filemap {
|
||||
return @{name: filename, substr: substr, src: src,
|
||||
start_pos: {ch: start_pos_ch, byte: start_pos_byte},
|
||||
mut lines: ~[{ch: start_pos_ch, byte: start_pos_byte}]};
|
||||
return @filemap_ {
|
||||
name: filename, substr: substr, src: src,
|
||||
start_pos: file_pos {ch: start_pos_ch, byte: start_pos_byte},
|
||||
mut lines: ~[file_pos {ch: start_pos_ch, byte: start_pos_byte}]
|
||||
};
|
||||
}
|
||||
|
||||
fn new_filemap(+filename: filename, src: @~str,
|
||||
|
|
@ -88,7 +102,7 @@ fn mk_substr_filename(cm: CodeMap, sp: span) -> ~str
|
|||
}
|
||||
|
||||
fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
|
||||
file.lines.push({ch: chpos, byte: byte_pos + file.start_pos.byte});
|
||||
file.lines.push(file_pos {ch: chpos, byte: byte_pos + file.start_pos.byte});
|
||||
}
|
||||
|
||||
type lookup_fn = pure fn(file_pos) -> uint;
|
||||
|
|
@ -118,7 +132,7 @@ fn lookup_line(map: CodeMap, pos: uint, lookup: lookup_fn)
|
|||
|
||||
fn lookup_pos(map: CodeMap, pos: uint, lookup: lookup_fn) -> loc {
|
||||
let {fm: f, line: a} = lookup_line(map, pos, lookup);
|
||||
return {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
|
||||
return loc {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
|
||||
}
|
||||
|
||||
fn lookup_char_pos(map: CodeMap, pos: uint) -> loc {
|
||||
|
|
@ -160,9 +174,9 @@ fn adjust_span(map: CodeMap, sp: span) -> span {
|
|||
match (line.fm.substr) {
|
||||
fss_none => sp,
|
||||
fss_internal(s) => {
|
||||
adjust_span(map, {lo: s.lo + (sp.lo - line.fm.start_pos.ch),
|
||||
hi: s.lo + (sp.hi - line.fm.start_pos.ch),
|
||||
expn_info: sp.expn_info})}
|
||||
adjust_span(map, span {lo: s.lo + (sp.lo - line.fm.start_pos.ch),
|
||||
hi: s.lo + (sp.hi - line.fm.start_pos.ch),
|
||||
expn_info: sp.expn_info})}
|
||||
fss_external(_) => sp
|
||||
}
|
||||
}
|
||||
|
|
@ -173,7 +187,7 @@ enum expn_info_ {
|
|||
}
|
||||
type expn_info = Option<@expn_info_>;
|
||||
|
||||
type span = {lo: uint, hi: uint, expn_info: expn_info};
|
||||
struct span {lo: uint, hi: uint, expn_info: expn_info}
|
||||
|
||||
impl span : cmp::Eq {
|
||||
pure fn eq(other: &span) -> bool {
|
||||
|
|
@ -207,7 +221,10 @@ fn span_to_str(sp: span, cm: CodeMap) -> ~str {
|
|||
lo.line, lo.col, hi.line, hi.col)
|
||||
}
|
||||
|
||||
type file_lines = {file: filemap, lines: ~[uint]};
|
||||
struct file_lines {
|
||||
file: filemap,
|
||||
lines: ~[uint]
|
||||
}
|
||||
|
||||
fn span_to_filename(sp: span, cm: codemap::CodeMap) -> filename {
|
||||
let lo = lookup_char_pos(cm, sp.lo);
|
||||
|
|
@ -221,7 +238,7 @@ fn span_to_lines(sp: span, cm: codemap::CodeMap) -> @file_lines {
|
|||
for uint::range(lo.line - 1u, hi.line as uint) |i| {
|
||||
lines.push(i);
|
||||
};
|
||||
return @{file: lo.file, lines: lines};
|
||||
return @file_lines {file: lo.file, lines: lines};
|
||||
}
|
||||
|
||||
fn get_line(fm: filemap, line: int) -> ~str unsafe {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use std::map::HashMap;
|
|||
use parse::parser;
|
||||
use diagnostic::span_handler;
|
||||
use codemap::{CodeMap, span, expn_info, expanded_from};
|
||||
use ast_util::dummy_sp;
|
||||
|
||||
// obsolete old-style #macro code:
|
||||
//
|
||||
|
|
@ -169,15 +170,15 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
|
|||
expanded_from({call_site: cs, callie: callie}) => {
|
||||
self.backtrace =
|
||||
Some(@expanded_from({
|
||||
call_site: {lo: cs.lo, hi: cs.hi,
|
||||
expn_info: self.backtrace},
|
||||
call_site: span {lo: cs.lo, hi: cs.hi,
|
||||
expn_info: self.backtrace},
|
||||
callie: callie}));
|
||||
}
|
||||
}
|
||||
}
|
||||
fn bt_pop() {
|
||||
match self.backtrace {
|
||||
Some(@expanded_from({call_site: {expn_info: prev, _}, _})) => {
|
||||
Some(@expanded_from({call_site: span {expn_info: prev, _}, _})) => {
|
||||
self.backtrace = prev
|
||||
}
|
||||
_ => 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])
|
|||
|
||||
// these spans won't matter, anyways
|
||||
fn ms(m: matcher_) -> matcher {
|
||||
{node: m, span: {lo: 0u, hi: 0u, expn_info: None}}
|
||||
{node: m, span: dummy_sp()}
|
||||
}
|
||||
let arg_nm = cx.parse_sess().interner.gensym(@~"arg");
|
||||
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
|
|||
|
||||
fn new_span(cx: ext_ctxt, sp: span) -> span {
|
||||
/* this discards information in the case of macro-defining macros */
|
||||
return {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
|
||||
return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
|
||||
}
|
||||
|
||||
// FIXME (#2247): this is a terrible kludge to inject some macros into
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ fn path(ids: ~[ident], span: span) -> @ast::path {
|
|||
}
|
||||
|
||||
fn empty_span() -> span {
|
||||
{lo: 0, hi: 0, expn_info: None}
|
||||
span {lo: 0, hi: 0, expn_info: None}
|
||||
}
|
||||
|
||||
trait append_types {
|
||||
|
|
@ -95,7 +95,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
}
|
||||
|
||||
fn empty_span() -> span {
|
||||
{lo: 0, hi: 0, expn_info: self.backtrace()}
|
||||
span {lo: 0, hi: 0, expn_info: self.backtrace()}
|
||||
}
|
||||
|
||||
fn block_expr(b: ast::blk) -> @ast::expr {
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
|
|||
fn new_id(_old: node_id, cx: ext_ctxt) -> node_id { return cx.next_id(); }
|
||||
fn new_span(cx: ext_ctxt, sp: span) -> span {
|
||||
/* this discards information in the case of macro-defining macros */
|
||||
return {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
|
||||
return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
|
||||
}
|
||||
let afp = default_ast_fold();
|
||||
let f_pre =
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use base::*;
|
||||
use codemap::span;
|
||||
use codemap::{span, loc, filemap_};
|
||||
use print::pprust;
|
||||
use build::{mk_base_vec_e,mk_uint,mk_u8,mk_uniq_str};
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file");
|
||||
let { file: @{ name: filename, _ }, _ } =
|
||||
let loc { file: @filemap_ { name: filename, _ }, _ } =
|
||||
codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
return mk_uniq_str(cx, sp, filename);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,13 @@ use macro_parser::{parse, parse_or_else, success, failure, named_match,
|
|||
matched_seq, matched_nonterminal, error};
|
||||
use std::map::HashMap;
|
||||
use parse::token::special_idents;
|
||||
use ast_util::dummy_sp;
|
||||
|
||||
fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
arg: ~[ast::token_tree]) -> base::mac_result {
|
||||
// these spans won't matter, anyways
|
||||
fn ms(m: matcher_) -> matcher {
|
||||
{node: m, span: {lo: 0u, hi: 0u, expn_info: None}}
|
||||
{node: m, span: dummy_sp()}
|
||||
}
|
||||
|
||||
let lhs_nm = cx.parse_sess().interner.gensym(@~"lhs");
|
||||
|
|
@ -65,7 +66,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
|||
}
|
||||
|
||||
// Which arm's failure should we report? (the one furthest along)
|
||||
let mut best_fail_spot = {lo: 0u, hi: 0u, expn_info: None};
|
||||
let mut best_fail_spot = dummy_sp();
|
||||
let mut best_fail_msg = ~"internal error: ran no matchers";
|
||||
|
||||
let s_d = cx.parse_sess().span_diagnostic;
|
||||
|
|
|
|||
|
|
@ -3415,9 +3415,8 @@ impl Parser {
|
|||
|p| p.parse_token_tree());
|
||||
let m = ast::mac_invoc_tt(pth, tts);
|
||||
let m: ast::mac = {node: m,
|
||||
span: {lo: self.span.lo,
|
||||
hi: self.span.hi,
|
||||
expn_info: None}};
|
||||
span: mk_sp(self.span.lo,
|
||||
self.span.hi)};
|
||||
let item_ = item_mac(m);
|
||||
return iovi_item(self.mk_item(lo, self.last_span.hi, id, item_,
|
||||
visibility, attrs));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue