Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make codemap byte-oriented, simpler #3992

Merged
merged 28 commits into from
Nov 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4c68084
Convert most codemap types from records to structs
brson Nov 12, 2012
5f881b4
Remove filemap box typedef from codemap
brson Nov 13, 2012
1f33031
Move filemap ctors to static methods
brson Nov 13, 2012
9fc75e8
Move codemap doc comments to the proper place
brson Nov 13, 2012
385a466
Reformatting in codemap
brson Nov 13, 2012
5b248a6
Remove CodeMap box typedef from codemap
brson Nov 13, 2012
18a825b
Reorder codemap decls
brson Nov 13, 2012
d115944
Remove expn_info box typedef from codemap
brson Nov 13, 2012
15a5d2c
Convert codemap from legacy_exports
brson Nov 13, 2012
2ec09c4
Objectify the codemap
brson Nov 13, 2012
b22f941
Make it clearer which codemap functions use chars vs. bytes
brson Nov 13, 2012
38b9740
Remove unused get_snippet function from codemap
brson Nov 13, 2012
9ecf863
Camel case all the codemap types except span
brson Nov 13, 2012
f67bfe9
Add types for character position and byte position in the codemap
brson Nov 13, 2012
8069d2f
Track character and byte positions together in the parser
brson Nov 15, 2012
3a9ccd5
Factor out some position management code in the lexer
brson Nov 15, 2012
b1dff40
Create CodeMap.add_filemap
brson Nov 15, 2012
4a0f4f5
Refactor the lexer to use FilePos types
brson Nov 15, 2012
bcccf33
Add some comments to codemap and lexer
brson Nov 15, 2012
d5e35e3
Convert CodeMap and FileMap to use &self instead of @self
brson Nov 15, 2012
8cba337
Remove CodeMap.lookup_byte_pos
brson Nov 16, 2012
81d2015
Change spans to use byte offsets instead of char offsets
brson Nov 16, 2012
2374154
Stop storing char positions in CodeMap
brson Nov 16, 2012
4a5b28f
Stop tracking CodeMap offsets in the parse session. Big simplification
brson Nov 16, 2012
1ac28c3
Remove unused types from codemap
brson Nov 16, 2012
2af0885
Remove incorrect comment from codemap
brson Nov 16, 2012
7c72fd8
Add some docs to codemap
brson Nov 16, 2012
e621e68
Remove unused MultiByteChar.sum field from codemap
brson Nov 16, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libfuzzer/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn as_str(f: fn@(+x: io::Writer)) -> ~str {
io::with_str_writer(f)
}

fn check_variants_of_ast(crate: ast::crate, codemap: codemap::CodeMap,
fn check_variants_of_ast(crate: ast::crate, codemap: @codemap::CodeMap,
filename: &Path, cx: context) {
let stolen = steal(crate, cx.mode);
let extra_exprs = vec::filter(common_exprs(),
Expand All @@ -239,7 +239,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::CodeMap,

fn check_variants_T<T: Copy>(
crate: ast::crate,
codemap: codemap::CodeMap,
codemap: @codemap::CodeMap,
filename: &Path,
thing_label: ~str,
things: ~[T],
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: input,
ppm_expanded | ppm_normal => pprust::no_ann()
};
let is_expanded = upto != cu_parse;
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
let src = sess.codemap.get_filemap(source_name(input)).src;
do io::with_str_reader(*src) |rdr| {
pprust::print_crate(sess.codemap, sess.parse_sess.interner,
sess.span_diagnostic, crate,
Expand Down Expand Up @@ -574,7 +574,7 @@ fn build_session_options(binary: ~str,

fn build_session(sopts: @session::options,
demitter: diagnostic::emitter) -> Session {
let codemap = codemap::new_codemap();
let codemap = @codemap::CodeMap::new();
let diagnostic_handler =
diagnostic::mk_handler(Some(demitter));
let span_diagnostic_handler =
Expand All @@ -583,7 +583,7 @@ fn build_session(sopts: @session::options,
}

fn build_session_(sopts: @session::options,
cm: codemap::CodeMap,
cm: @codemap::CodeMap,
demitter: diagnostic::emitter,
span_diagnostic_handler: diagnostic::span_handler)
-> Session {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type Session_ = {targ_cfg: @config,
opts: @options,
cstore: metadata::cstore::CStore,
parse_sess: parse_sess,
codemap: codemap::CodeMap,
codemap: @codemap::CodeMap,
// For a library crate, this is always none
mut main_fn: Option<(node_id, codemap::span)>,
span_diagnostic: diagnostic::span_handler,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index);

debug!("encoding info for item at %s",
syntax::codemap::span_to_str(item.span, ecx.tcx.sess.codemap));
ecx.tcx.sess.codemap.span_to_str(item.span));

match item.node {
item_const(_, _) => {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ use std::map::HashMap;
use syntax::{visit, ast_util};
use syntax::print::pprust::{expr_to_str, block_to_str};
use visit::vt;
use syntax::codemap::{span, span_to_str};
use syntax::codemap::span;
use syntax::ast::*;
use io::WriterUtil;
use capture::{cap_move, cap_drop, cap_copy, cap_ref};
Expand Down Expand Up @@ -170,9 +170,9 @@ impl LiveNodeKind : cmp::Eq {
fn live_node_kind_to_str(lnk: LiveNodeKind, cx: ty::ctxt) -> ~str {
let cm = cx.sess.codemap;
match lnk {
FreeVarNode(s) => fmt!("Free var node [%s]", span_to_str(s, cm)),
ExprNode(s) => fmt!("Expr node [%s]", span_to_str(s, cm)),
VarDefNode(s) => fmt!("Var def node [%s]", span_to_str(s, cm)),
FreeVarNode(s) => fmt!("Free var node [%s]", cm.span_to_str(s)),
ExprNode(s) => fmt!("Expr node [%s]", cm.span_to_str(s)),
VarDefNode(s) => fmt!("Var def node [%s]", cm.span_to_str(s)),
ExitNode => ~"Exit node"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ fn trans_trace(bcx: block, sp_opt: Option<span>, trace_str: ~str) {
let {V_filename, V_line} = match sp_opt {
Some(sp) => {
let sess = bcx.sess();
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
{V_filename: C_cstr(bcx.ccx(), loc.file.name),
V_line: loc.line as int}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ fn _UndefReturn(cx: block, Fn: ValueRef) -> ValueRef {
fn add_span_comment(bcx: block, sp: span, text: ~str) {
let ccx = bcx.ccx();
if !ccx.sess.no_asm_comments() {
let s = text + ~" (" + codemap::span_to_str(sp, ccx.sess.codemap)
let s = text + ~" (" + ccx.sess.codemap.span_to_str(sp)
+ ~")";
log(debug, s);
add_comment(bcx, s);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fn trans_fail_value(bcx: block, sp_opt: Option<span>, V_fail_str: ValueRef)
let {V_filename, V_line} = match sp_opt {
Some(sp) => {
let sess = bcx.sess();
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
{V_filename: C_cstr(bcx.ccx(), loc.file.name),
V_line: loc.line as int}
}
Expand All @@ -361,7 +361,7 @@ fn trans_fail_bounds_check(bcx: block, sp: span,
let _icx = bcx.insn_ctxt("trans_fail_bounds_check");
let ccx = bcx.ccx();

let loc = codemap::lookup_char_pos(bcx.sess().parse_sess.cm, sp.lo);
let loc = bcx.sess().parse_sess.cm.lookup_char_pos(sp.lo);
let line = C_int(ccx, loc.line as int);
let filename_cstr = C_cstr(bcx.ccx(), loc.file.name);
let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
Expand Down
35 changes: 16 additions & 19 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use trans::build::B;
use middle::ty;
use syntax::{ast, codemap, ast_util, ast_map};
use syntax::parse::token::ident_interner;
use codemap::span;
use codemap::{span, CharPos};
use ast::Ty;
use pat_util::*;
use util::ppaux::ty_to_str;
Expand Down Expand Up @@ -112,7 +112,7 @@ type compile_unit_md = {name: ~str};
type subprogram_md = {id: ast::node_id};
type local_var_md = {id: ast::node_id};
type tydesc_md = {hash: uint};
type block_md = {start: codemap::loc, end: codemap::loc};
type block_md = {start: codemap::Loc, end: codemap::Loc};
type argument_md = {id: ast::node_id};
type retval_md = {id: ast::node_id};

Expand Down Expand Up @@ -229,8 +229,8 @@ fn create_file(cx: @crate_ctxt, full_path: ~str) -> @metadata<file_md> {
return mdval;
}

fn line_from_span(cm: codemap::CodeMap, sp: span) -> uint {
codemap::lookup_char_pos(cm, sp.lo).line
fn line_from_span(cm: @codemap::CodeMap, sp: span) -> uint {
cm.lookup_char_pos(sp.lo).line
}

fn create_block(cx: block) -> @metadata<block_md> {
Expand All @@ -244,9 +244,9 @@ fn create_block(cx: block) -> @metadata<block_md> {
}
let sp = cx.node_info.get().span;

let start = codemap::lookup_char_pos(cx.sess().codemap, sp.lo);
let start = cx.sess().codemap.lookup_char_pos(sp.lo);
let fname = start.file.name;
let end = codemap::lookup_char_pos(cx.sess().codemap, sp.hi);
let end = cx.sess().codemap.lookup_char_pos(sp.hi);
let tg = LexicalBlockTag;
/*alt cached_metadata::<@metadata<block_md>>(
cache, tg,
Expand All @@ -266,8 +266,8 @@ fn create_block(cx: block) -> @metadata<block_md> {
};
let lldata = ~[lltag(tg),
parent,
lli32(start.line as int),
lli32(start.col as int),
lli32(start.line.to_int()),
lli32(start.col.to_int()),
file_node.node,
lli32(unique_id)
];
Expand Down Expand Up @@ -597,7 +597,7 @@ fn create_ty(_cx: @crate_ctxt, _t: ty::t, _ty: @ast::Ty)
}

fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> ~str {
codemap::lookup_char_pos(cx.sess.codemap, sp.lo).file.name
cx.sess.codemap.lookup_char_pos(sp.lo).file.name
}

fn create_var(type_tag: int, context: ValueRef, name: ~str, file: ValueRef,
Expand Down Expand Up @@ -629,8 +629,7 @@ fn create_local_var(bcx: block, local: @ast::local)
// FIXME this should be handled (#2533)
_ => fail ~"no single variable name for local"
};
let loc = codemap::lookup_char_pos(cx.sess.codemap,
local.span.lo);
let loc = cx.sess.codemap.lookup_char_pos(local.span.lo);
let ty = node_id_type(bcx, local.node.id);
let tymd = create_ty(cx, ty, local.node.ty);
let filemd = create_file(cx, loc.file.name);
Expand Down Expand Up @@ -674,8 +673,7 @@ fn create_arg(bcx: block, arg: ast::arg, sp: span)
option::None => ()
}

let loc = codemap::lookup_char_pos(cx.sess.codemap,
sp.lo);
let loc = cx.sess.codemap.lookup_char_pos(sp.lo);
let ty = node_id_type(bcx, arg.id);
let tymd = create_ty(cx, ty, arg.ty);
let filemd = create_file(cx, loc.file.name);
Expand Down Expand Up @@ -714,9 +712,9 @@ fn update_source_pos(cx: block, s: span) {
}
let cm = cx.sess().codemap;
let blockmd = create_block(cx);
let loc = codemap::lookup_char_pos(cm, s.lo);
let scopedata = ~[lli32(loc.line as int),
lli32(loc.col as int),
let loc = cm.lookup_char_pos(s.lo);
let scopedata = ~[lli32(loc.line.to_int()),
lli32(loc.col.to_int()),
blockmd.node,
llnull()];
let dbgscope = llmdnode(scopedata);
Expand All @@ -731,7 +729,7 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> {
log(debug, fcx.id);

let sp = fcx.span.get();
log(debug, codemap::span_to_str(sp, cx.sess.codemap));
log(debug, cx.sess.codemap.span_to_str(sp));

let (ident, ret_ty, id) = match cx.tcx.items.get(fcx.id) {
ast_map::node_item(item, _) => {
Expand Down Expand Up @@ -773,8 +771,7 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> {
option::None => ()
}

let loc = codemap::lookup_char_pos(cx.sess.codemap,
sp.lo);
let loc = cx.sess.codemap.lookup_char_pos(sp.lo);
let file_node = create_file(cx, loc.file.name).node;
let ty_node = if cx.sess.opts.extra_debuginfo {
match ret_ty.node {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/infer/region_inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ impl RegionVarBindings {
self.undo_log.push(AddVar(vid));
}
debug!("created new region variable %? with span %?",
vid, codemap::span_to_str(span, self.tcx.sess.codemap));
vid, self.tcx.sess.codemap.span_to_str(span));
return vid;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn monitor(+f: fn~(diagnostic::emitter)) {

// The 'diagnostics emitter'. Every error, warning, etc. should
// go through this function.
let demitter = fn@(cmsp: Option<(codemap::CodeMap, codemap::span)>,
let demitter = fn@(cmsp: Option<(@codemap::CodeMap, codemap::span)>,
msg: &str, lvl: diagnostic::level) {
if lvl == diagnostic::fatal {
comm::send(ch, fatal);
Expand Down
15 changes: 8 additions & 7 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ fn explain_region_and_span(cx: ctxt, region: ty::Region)
fn explain_span(cx: ctxt, heading: ~str, span: span)
-> (~str, Option<span>)
{
let lo = codemap::lookup_char_pos_adj(cx.sess.codemap, span.lo);
(fmt!("the %s at %u:%u", heading, lo.line, lo.col), Some(span))
let lo = cx.sess.codemap.lookup_char_pos_adj(span.lo);
(fmt!("the %s at %u:%u", heading,
lo.line, lo.col.to_uint()), Some(span))
}
}

Expand All @@ -131,29 +132,29 @@ fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
match cx.items.find(node_id) {
Some(ast_map::node_block(blk)) => {
fmt!("<block at %s>",
codemap::span_to_str(blk.span, cx.sess.codemap))
cx.sess.codemap.span_to_str(blk.span))
}
Some(ast_map::node_expr(expr)) => {
match expr.node {
ast::expr_call(*) => {
fmt!("<call at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap))
cx.sess.codemap.span_to_str(expr.span))
}
ast::expr_match(*) => {
fmt!("<alt at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap))
cx.sess.codemap.span_to_str(expr.span))
}
ast::expr_assign_op(*) |
ast::expr_field(*) |
ast::expr_unary(*) |
ast::expr_binary(*) |
ast::expr_index(*) => {
fmt!("<method at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap))
cx.sess.codemap.span_to_str(expr.span))
}
_ => {
fmt!("<expression at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap))
cx.sess.codemap.span_to_str(expr.span))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/astsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn build_ctxt(sess: Session,

fn build_session() -> Session {
let sopts: @options = basic_options();
let codemap = codemap::new_codemap();
let codemap = @codemap::CodeMap::new();
let error_handlers = build_error_handlers(codemap);
let {emitter, span_handler} = error_handlers;

Expand All @@ -137,7 +137,7 @@ type ErrorHandlers = {
// Build a custom error handler that will allow us to ignore non-fatal
// errors
fn build_error_handlers(
codemap: codemap::CodeMap
codemap: @codemap::CodeMap
) -> ErrorHandlers {

type DiagnosticHandler = {
Expand All @@ -156,13 +156,13 @@ fn build_error_handlers(
fn note(msg: &str) { self.inner.note(msg) }
fn bug(msg: &str) -> ! { self.inner.bug(msg) }
fn unimpl(msg: &str) -> ! { self.inner.unimpl(msg) }
fn emit(cmsp: Option<(codemap::CodeMap, codemap::span)>,
fn emit(cmsp: Option<(@codemap::CodeMap, codemap::span)>,
msg: &str, lvl: diagnostic::level) {
self.inner.emit(cmsp, msg, lvl)
}
}

let emitter = fn@(cmsp: Option<(codemap::CodeMap, codemap::span)>,
let emitter = fn@(cmsp: Option<(@codemap::CodeMap, codemap::span)>,
msg: &str, lvl: diagnostic::level) {
diagnostic::emit(cmsp, msg, lvl);
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/attr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod test {

let parse_sess = syntax::parse::new_parse_sess(None);
let parser = parse::new_parser_from_source_str(
parse_sess, ~[], ~"-", codemap::fss_none, @source);
parse_sess, ~[], ~"-", codemap::FssNone, @source);

parser.parse_outer_attributes()
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::serialization::{Serializable,
Deserializable,
Serializer,
Deserializer};
use codemap::{span, filename};
use codemap::{span, FileName};
use parse::token;

#[auto_serialize]
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use codemap::span;
use codemap::{span, BytePos};
use ast::*;

pure fn spanned<T>(lo: uint, hi: uint, +t: T) -> spanned<T> {
pure fn spanned<T>(+lo: BytePos, +hi: BytePos, +t: T) -> spanned<T> {
respan(mk_sp(lo, hi), move t)
}

Expand All @@ -14,12 +14,12 @@ 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}
pure fn mk_sp(+lo: BytePos, +hi: BytePos) -> span {
span {lo: lo, hi: hi, expn_info: None}
}

// make this a const, once the compiler supports it
pure fn dummy_sp() -> span { return mk_sp(0u, 0u); }
pure fn dummy_sp() -> span { return mk_sp(BytePos(0), BytePos(0)); }



Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use either::Either;
use diagnostic::span_handler;
use ast_util::{spanned, dummy_spanned};
use parse::comments::{doc_comment_style, strip_doc_comment_decoration};
use codemap::BytePos;

// Constructors
export mk_name_value_item_str;
Expand Down Expand Up @@ -74,7 +75,8 @@ fn mk_attr(item: @ast::meta_item) -> ast::attribute {
is_sugared_doc: false});
}

fn mk_sugared_doc_attr(text: ~str, lo: uint, hi: uint) -> ast::attribute {
fn mk_sugared_doc_attr(text: ~str,
+lo: BytePos, +hi: BytePos) -> ast::attribute {
let lit = spanned(lo, hi, ast::lit_str(@text));
let attr = {
style: doc_comment_style(text),
Expand Down
Loading