Merge pull request #4720 from jbclements/syntactic-cleanup

Syntactic cleanup
This commit is contained in:
Brian Anderson 2013-02-01 11:18:21 -08:00
commit a05bbb2013
57 changed files with 471 additions and 308 deletions

View File

@ -851,6 +851,9 @@ mod quux {
In this example, the module `quux` re-exports all of the public names defined in `foo`. In this example, the module `quux` re-exports all of the public names defined in `foo`.
Also note that the paths contained in `use` items are relative to the crate root; so, in the previous
example, the use refers to `quux::foo::*`, and not simply to `foo::*`.
### Functions ### Functions
A _function item_ defines a sequence of [statements](#statements) and an optional final [expression](#expressions), along with a name and a set of parameters. A _function item_ defines a sequence of [statements](#statements) and an optional final [expression](#expressions), along with a name and a set of parameters.

View File

@ -286,7 +286,7 @@ pub fn load_link(mis: ~[@ast::meta_item]) -> (Option<~str>,
let mut uuid = None; let mut uuid = None;
for mis.each |a| { for mis.each |a| {
match a.node { match a.node {
ast::meta_name_value(v, ast::spanned { node: ast::lit_str(s), ast::meta_name_value(v, codemap::spanned { node: ast::lit_str(s),
_ }) => { _ }) => {
match v { match v {
~"name" => name = Some(*s), ~"name" => name = Some(*s),
@ -314,7 +314,7 @@ pub fn load_crate(filename: &Path) -> Option<Crate> {
for c.node.attrs.each |a| { for c.node.attrs.each |a| {
match a.node.value.node { match a.node.value.node {
ast::meta_name_value(v, ast::spanned { node: ast::lit_str(_), ast::meta_name_value(v, codemap::spanned { node: ast::lit_str(_),
_ }) => { _ }) => {
match v { match v {
~"desc" => desc = Some(v), ~"desc" => desc = Some(v),

View File

@ -74,12 +74,12 @@ pub fn common_exprs() -> ~[ast::expr] {
id: 0, id: 0,
callee_id: -1, callee_id: -1,
node: e, node: e,
span: ast_util::dummy_sp(), span: codemap::dummy_sp(),
} }
} }
fn dsl(l: ast::lit_) -> ast::lit { fn dsl(l: ast::lit_) -> ast::lit {
ast::spanned { node: l, span: ast_util::dummy_sp() } codemap::spanned { node: l, span: codemap::dummy_sp() }
} }
~[dse(ast::expr_break(option::None)), ~[dse(ast::expr_break(option::None)),

View File

@ -344,14 +344,15 @@ pub mod test {
use syntax::ast; use syntax::ast;
use syntax::ast_util; use syntax::ast_util;
use syntax::codemap;
pub fn make_crate_type_attr(+t: ~str) -> ast::attribute { pub fn make_crate_type_attr(+t: ~str) -> ast::attribute {
ast_util::respan(ast_util::dummy_sp(), ast::attribute_ { codemap::respan(codemap::dummy_sp(), ast::attribute_ {
style: ast::attr_outer, style: ast::attr_outer,
value: ast_util::respan(ast_util::dummy_sp(), value: codemap::respan(codemap::dummy_sp(),
ast::meta_name_value( ast::meta_name_value(
~"crate_type", ~"crate_type",
ast_util::respan(ast_util::dummy_sp(), codemap::respan(codemap::dummy_sp(),
ast::lit_str(@t)))), ast::lit_str(@t)))),
is_sugared_doc: false is_sugared_doc: false
}) })
@ -361,7 +362,7 @@ pub mod test {
let mut attrs = ~[]; let mut attrs = ~[];
if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; } if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; }
if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; } if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; }
@ast_util::respan(ast_util::dummy_sp(), ast::crate_ { @codemap::respan(codemap::dummy_sp(), ast::crate_ {
module: ast::_mod { view_items: ~[], items: ~[] }, module: ast::_mod { view_items: ~[], items: ~[] },
attrs: attrs, attrs: attrs,
config: ~[] config: ~[]

View File

@ -17,6 +17,7 @@ use syntax::ast;
use syntax::ast_util::*; use syntax::ast_util::*;
use syntax::attr; use syntax::attr;
use syntax::codemap; use syntax::codemap;
use syntax::codemap::dummy_sp;
use syntax::fold; use syntax::fold;
const CORE_VERSION: &static/str = "0.6"; const CORE_VERSION: &static/str = "0.6";
@ -36,8 +37,8 @@ fn use_core(crate: @ast::crate) -> bool {
fn inject_libcore_ref(sess: Session, fn inject_libcore_ref(sess: Session,
crate: @ast::crate) -> @ast::crate { crate: @ast::crate) -> @ast::crate {
fn spanned<T: Copy>(x: T) -> ast::spanned<T> { fn spanned<T: Copy>(x: T) -> codemap::spanned<T> {
ast::spanned { node: x, span: dummy_sp() } codemap::spanned { node: x, span: dummy_sp() }
} }
let precursor = @fold::AstFoldFns { let precursor = @fold::AstFoldFns {

View File

@ -13,6 +13,7 @@ use core::prelude::*;
use driver::session::Session; use driver::session::Session;
use syntax::parse; use syntax::parse;
use syntax::ast; use syntax::ast;
use syntax::codemap::spanned;
use core::vec; use core::vec;
@ -34,7 +35,7 @@ pub fn inject_intrinsic(sess: Session, crate: @ast::crate) -> @ast::crate {
let items = vec::append(~[item], crate.node.module.items); let items = vec::append(~[item], crate.node.module.items);
@ast::spanned { @spanned {
node: ast::crate_ { node: ast::crate_ {
module: ast::_mod { module: ast::_mod {
items: items, items: items,

View File

@ -21,7 +21,8 @@ use core::option;
use core::vec; use core::vec;
use syntax::ast_util::*; use syntax::ast_util::*;
use syntax::attr; use syntax::attr;
use syntax::codemap::span; use syntax::codemap::{dummy_sp, span};
use syntax::codemap;
use syntax::fold; use syntax::fold;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::{ast, ast_util}; use syntax::{ast, ast_util};
@ -237,8 +238,8 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
return @item; return @item;
} }
fn nospan<T: Copy>(t: T) -> ast::spanned<T> { fn nospan<T: Copy>(t: T) -> codemap::spanned<T> {
ast::spanned { node: t, span: dummy_sp() } codemap::spanned { node: t, span: dummy_sp() }
} }
fn path_node(+ids: ~[ast::ident]) -> @ast::path { fn path_node(+ids: ~[ast::ident]) -> @ast::path {
@ -535,7 +536,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
let body_: ast::blk_ = let body_: ast::blk_ =
default_block(~[], option::Some(test_main_call_expr), default_block(~[], option::Some(test_main_call_expr),
cx.sess.next_node_id()); cx.sess.next_node_id());
let body = ast::spanned { node: body_, span: dummy_sp() }; let body = codemap::spanned { node: body_, span: dummy_sp() };
let item_ = ast::item_fn(decl, ast::impure_fn, ~[], body); let item_ = ast::item_fn(decl, ast::impure_fn, ~[], body);
let item = ast::item { let item = ast::item {

View File

@ -24,7 +24,7 @@ use core::either;
use core::option; use core::option;
use core::vec; use core::vec;
use syntax::attr; use syntax::attr;
use syntax::codemap::span; use syntax::codemap::{span, dummy_sp};
use syntax::diagnostic::span_handler; use syntax::diagnostic::span_handler;
use syntax::parse::token::ident_interner; use syntax::parse::token::ident_interner;
use syntax::print::pprust; use syntax::print::pprust;
@ -294,7 +294,7 @@ fn resolve_crate_deps(e: env, cdata: @~[u8]) -> cstore::cnum_map {
// This is a new one so we've got to load it // This is a new one so we've got to load it
// FIXME (#2404): Need better error reporting than just a bogus // FIXME (#2404): Need better error reporting than just a bogus
// span. // span.
let fake_span = ast_util::dummy_sp(); let fake_span = dummy_sp();
let local_cnum = resolve_crate(e, cname, cmetas, let local_cnum = resolve_crate(e, cname, cmetas,
/*bad*/copy dep.hash, fake_span); /*bad*/copy dep.hash, fake_span);
cnum_map.insert(extrn_cnum, local_cnum); cnum_map.insert(extrn_cnum, local_cnum);

View File

@ -26,7 +26,7 @@ use std::ebml;
use std::map::HashMap; use std::map::HashMap;
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_util::dummy_sp; use syntax::codemap::dummy_sp;
use syntax::ast_util; use syntax::ast_util;
use syntax::diagnostic::expect; use syntax::diagnostic::expect;
use syntax::diagnostic::span_handler; use syntax::diagnostic::span_handler;

View File

@ -45,6 +45,7 @@ use syntax::diagnostic::span_handler;
use syntax::parse::token::ident_interner; use syntax::parse::token::ident_interner;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::{ast, ast_util}; use syntax::{ast, ast_util};
use syntax::codemap;
// A function that takes a def_id relative to the crate being searched and // A function that takes a def_id relative to the crate being searched and
// returns a def_id relative to the compilation environment, i.e. if we hit a // returns a def_id relative to the compilation environment, i.e. if we hit a
@ -981,13 +982,13 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
assert (vec::len(meta_items) == 1u); assert (vec::len(meta_items) == 1u);
let meta_item = meta_items[0]; let meta_item = meta_items[0];
attrs.push( attrs.push(
ast::spanned { codemap::spanned {
node: ast::attribute_ { node: ast::attribute_ {
style: ast::attr_outer, style: ast::attr_outer,
value: /*bad*/copy *meta_item, value: /*bad*/copy *meta_item,
is_sugared_doc: false, is_sugared_doc: false,
}, },
span: ast_util::dummy_sp() span: codemap::dummy_sp()
}); });
}; };
} }

View File

@ -26,8 +26,7 @@ use core::uint;
use core::vec; use core::vec;
use syntax::ast; use syntax::ast;
use syntax::ast::*; use syntax::ast::*;
use syntax::ast_util; use syntax::codemap::{respan, dummy_sp};
use syntax::ast_util::respan;
use std::map::HashMap; use std::map::HashMap;
// Compact string representation for ty::t values. API ty_str & // Compact string representation for ty::t values. API ty_str &
@ -114,7 +113,7 @@ fn parse_path(st: @pstate) -> @ast::path {
':' => { next(st); next(st); } ':' => { next(st); next(st); }
c => { c => {
if c == '(' { if c == '(' {
return @ast::path { span: ast_util::dummy_sp(), return @ast::path { span: dummy_sp(),
global: false, global: false,
idents: idents, idents: idents,
rp: None, rp: None,

View File

@ -220,7 +220,7 @@ impl extended_decode_ctxt {
ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) } ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) }
} }
fn tr_span(_span: span) -> span { fn tr_span(_span: span) -> span {
ast_util::dummy_sp() // FIXME (#1972): handle span properly codemap::dummy_sp() // FIXME (#1972): handle span properly
} }
} }
@ -300,9 +300,9 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
let stmts_sans_items = do blk.stmts.filtered |stmt| { let stmts_sans_items = do blk.stmts.filtered |stmt| {
match stmt.node { match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@ast::spanned { node: ast::decl_local(_), ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
span: _}, _) => true, span: _}, _) => true,
ast::stmt_decl(@ast::spanned { node: ast::decl_item(_), ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_),
span: _}, _) => false, span: _}, _) => false,
ast::stmt_mac(*) => die!(~"unexpanded macro in astencode") ast::stmt_mac(*) => die!(~"unexpanded macro in astencode")
} }
@ -336,7 +336,7 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => { ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
let dtor_body = fld.fold_block((*dtor).node.body); let dtor_body = fld.fold_block((*dtor).node.body);
ast::ii_dtor( ast::ii_dtor(
ast::spanned { codemap::spanned {
node: ast::struct_dtor_ { body: dtor_body, node: ast::struct_dtor_ { body: dtor_body,
.. /*bad*/copy (*dtor).node }, .. /*bad*/copy (*dtor).node },
.. (/*bad*/copy *dtor) }, .. (/*bad*/copy *dtor) },
@ -377,7 +377,7 @@ fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
let new_parent = xcx.tr_def_id(parent_id); let new_parent = xcx.tr_def_id(parent_id);
let new_self = fld.new_id((*dtor).node.self_id); let new_self = fld.new_id((*dtor).node.self_id);
ast::ii_dtor( ast::ii_dtor(
ast::spanned { codemap::spanned {
node: ast::struct_dtor_ { id: dtor_id, node: ast::struct_dtor_ { id: dtor_id,
attrs: dtor_attrs, attrs: dtor_attrs,
self_id: new_self, self_id: new_self,

View File

@ -20,6 +20,7 @@ use core::dvec::DVec;
use core::option; use core::option;
use std::map::HashMap; use std::map::HashMap;
use syntax::ast::*; use syntax::ast::*;
use syntax::codemap;
use syntax::{visit, ast_util, ast_map}; use syntax::{visit, ast_util, ast_map};
pub fn check_crate(sess: Session, pub fn check_crate(sess: Session,
@ -64,7 +65,10 @@ pub fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
fn is_str(e: @expr) -> bool { fn is_str(e: @expr) -> bool {
match e.node { match e.node {
expr_vstore( expr_vstore(
@expr { node: expr_lit(@spanned { node: lit_str(_), _}), _ }, @expr { node: expr_lit(@codemap::spanned {
node: lit_str(_),
_}),
_ },
expr_vstore_uniq expr_vstore_uniq
) => true, ) => true,
_ => false _ => false
@ -96,7 +100,7 @@ pub fn check_expr(sess: Session,
~"disallowed operator in constant expression"); ~"disallowed operator in constant expression");
return; return;
} }
expr_lit(@spanned {node: lit_str(_), _}) => { } expr_lit(@codemap::spanned {node: lit_str(_), _}) => { }
expr_binary(_, _, _) | expr_unary(_, _) => { expr_binary(_, _, _) | expr_unary(_, _) => {
if method_map.contains_key(e.id) { if method_map.contains_key(e.id) {
sess.span_err(e.span, ~"user-defined operators are not \ sess.span_err(e.span, ~"user-defined operators are not \
@ -183,7 +187,7 @@ pub fn check_expr(sess: Session,
} }
} }
match e.node { match e.node {
expr_lit(@spanned {node: lit_int(v, t), _}) => { expr_lit(@codemap::spanned {node: lit_int(v, t), _}) => {
if t != ty_char { if t != ty_char {
if (v as u64) > ast_util::int_ty_max( if (v as u64) > ast_util::int_ty_max(
if t == ty_i { sess.targ_cfg.int_type } else { t }) { if t == ty_i { sess.targ_cfg.int_type } else { t }) {
@ -191,7 +195,7 @@ pub fn check_expr(sess: Session,
} }
} }
} }
expr_lit(@spanned {node: lit_uint(v, t), _}) => { expr_lit(@codemap::spanned {node: lit_uint(v, t), _}) => {
if v > ast_util::uint_ty_max( if v > ast_util::uint_ty_max(
if t == ty_u { sess.targ_cfg.uint_type } else { t }) { if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
sess.span_err(e.span, ~"literal out of range for its type"); sess.span_err(e.span, ~"literal out of range for its type");

View File

@ -26,9 +26,8 @@ use core::vec;
use std::map::HashMap; use std::map::HashMap;
use std::sort; use std::sort;
use syntax::ast::*; use syntax::ast::*;
use syntax::ast_util::{variant_def_ids, dummy_sp, unguarded_pat, walk_pat}; use syntax::ast_util::{variant_def_ids, unguarded_pat, walk_pat};
use syntax::ast_util; use syntax::codemap::{span, dummy_sp, spanned};
use syntax::codemap::span;
use syntax::print::pprust::pat_to_str; use syntax::print::pprust::pat_to_str;
use syntax::visit; use syntax::visit;
@ -464,7 +463,7 @@ pub fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
} }
pub fn wild() -> @pat { pub fn wild() -> @pat {
@pat {id: 0, node: pat_wild, span: ast_util::dummy_sp()} @pat {id: 0, node: pat_wild, span: dummy_sp()}
} }
pub fn specialize(cx: @MatchCheckCtxt, pub fn specialize(cx: @MatchCheckCtxt,

View File

@ -26,7 +26,7 @@ use core::str;
use core::vec; use core::vec;
use std::map::HashMap; use std::map::HashMap;
use syntax::ast::*; use syntax::ast::*;
use syntax::codemap::span; use syntax::codemap::{span, spanned};
use syntax::print::pprust::expr_to_str; use syntax::print::pprust::expr_to_str;
use syntax::{visit, ast_util}; use syntax::{visit, ast_util};

View File

@ -39,6 +39,7 @@ use std::oldsmallintmap;
use syntax::ast_util::{path_to_ident}; use syntax::ast_util::{path_to_ident};
use syntax::attr; use syntax::attr;
use syntax::codemap::span; use syntax::codemap::span;
use syntax::codemap;
use syntax::print::pprust::{expr_to_str, mode_to_str, pat_to_str}; use syntax::print::pprust::{expr_to_str, mode_to_str, pat_to_str};
use syntax::{ast, ast_util, visit}; use syntax::{ast, ast_util, visit};
@ -453,7 +454,7 @@ fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
match e.node { match e.node {
ast::expr_while(cond, _) => { ast::expr_while(cond, _) => {
match cond.node { match cond.node {
ast::expr_lit(@ast::spanned { ast::expr_lit(@codemap::spanned {
node: ast::lit_bool(true), _}) => node: ast::lit_bool(true), _}) =>
{ {
cx.sess.span_lint( cx.sess.span_lint(

View File

@ -14,11 +14,10 @@ use middle::resolve;
use middle::ty; use middle::ty;
use syntax::ast::*; use syntax::ast::*;
use syntax::ast_util; use syntax::ast_util::{path_to_ident, walk_pat};
use syntax::ast_util::{path_to_ident, respan, walk_pat};
use syntax::fold; use syntax::fold;
use syntax::fold::*; use syntax::fold::*;
use syntax::codemap::span; use syntax::codemap::{span, respan};
use std::map::HashMap; use std::map::HashMap;
pub type PatIdMap = HashMap<ident, node_id>; pub type PatIdMap = HashMap<ident, node_id>;

View File

@ -58,7 +58,7 @@ use syntax::ast::{variant, view_item, view_item_import};
use syntax::ast::{view_item_use, view_path_glob, view_path_list}; use syntax::ast::{view_item_use, view_path_glob, view_path_list};
use syntax::ast::{view_path_simple, visibility, anonymous, named, not}; use syntax::ast::{view_path_simple, visibility, anonymous, named, not};
use syntax::ast::{unsafe_fn}; use syntax::ast::{unsafe_fn};
use syntax::ast_util::{def_id_of_def, dummy_sp, local_def}; use syntax::ast_util::{def_id_of_def, local_def};
use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method}; use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method};
use syntax::ast_util::{Privacy, Public, Private}; use syntax::ast_util::{Privacy, Public, Private};
use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy}; use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy};
@ -66,7 +66,7 @@ use syntax::attr::{attr_metas, contains_name, attrs_contains_name};
use syntax::parse::token::ident_interner; use syntax::parse::token::ident_interner;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
use syntax::print::pprust::{pat_to_str, path_to_str}; use syntax::print::pprust::{pat_to_str, path_to_str};
use syntax::codemap::span; use syntax::codemap::{span, dummy_sp};
use syntax::visit::{default_visitor, fk_method, mk_vt, Visitor, visit_block}; use syntax::visit::{default_visitor, fk_method, mk_vt, Visitor, visit_block};
use syntax::visit::{visit_crate, visit_expr, visit_expr_opt, visit_fn}; use syntax::visit::{visit_crate, visit_expr, visit_expr_opt, visit_fn};
use syntax::visit::{visit_foreign_item, visit_item, visit_method_helper}; use syntax::visit::{visit_foreign_item, visit_item, visit_method_helper};

View File

@ -1850,7 +1850,7 @@ pub fn trans_enum_variant(ccx: @crate_ctxt,
ty: varg.ty, ty: varg.ty,
pat: ast_util::ident_to_pat( pat: ast_util::ident_to_pat(
ccx.tcx.sess.next_node_id(), ccx.tcx.sess.next_node_id(),
ast_util::dummy_sp(), codemap::dummy_sp(),
special_idents::arg), special_idents::arg),
id: varg.id, id: varg.id,
} }
@ -1913,7 +1913,7 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt,
is_mutbl: false, is_mutbl: false,
ty: field.node.ty, ty: field.node.ty,
pat: ast_util::ident_to_pat(ccx.tcx.sess.next_node_id(), pat: ast_util::ident_to_pat(ccx.tcx.sess.next_node_id(),
ast_util::dummy_sp(), codemap::dummy_sp(),
special_idents::arg), special_idents::arg),
id: field.node.id id: field.node.id
} }
@ -2044,7 +2044,7 @@ pub fn trans_item(ccx: @crate_ctxt, item: ast::item) {
} else { } else {
for vec::each((*body).node.stmts) |stmt| { for vec::each((*body).node.stmts) |stmt| {
match stmt.node { match stmt.node {
ast::stmt_decl(@ast::spanned { node: ast::decl_item(i), ast::stmt_decl(@codemap::spanned { node: ast::decl_item(i),
_ }, _) => { _ }, _) => {
trans_item(ccx, *i); trans_item(ccx, *i);
} }

View File

@ -142,7 +142,7 @@ use util::ppaux::ty_to_str;
use syntax::print::pprust::{expr_to_str}; use syntax::print::pprust::{expr_to_str};
use syntax::ast; use syntax::ast;
use syntax::ast::spanned; use syntax::codemap::spanned;
// Destinations // Destinations
@ -552,7 +552,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
ast::expr_tup(ref args) => { ast::expr_tup(ref args) => {
return trans_tup(bcx, *args, dest); return trans_tup(bcx, *args, dest);
} }
ast::expr_lit(@ast::spanned {node: ast::lit_str(s), _}) => { ast::expr_lit(@codemap::spanned {node: ast::lit_str(s), _}) => {
return tvec::trans_lit_str(bcx, expr, s, dest); return tvec::trans_lit_str(bcx, expr, s, dest);
} }
ast::expr_vstore(contents, ast::expr_vstore_slice) | ast::expr_vstore(contents, ast::expr_vstore_slice) |

View File

@ -223,7 +223,7 @@ fn traverse_inline_body(cx: ctx, body: blk) {
fn traverse_all_resources_and_impls(cx: ctx, crate_mod: _mod) { fn traverse_all_resources_and_impls(cx: ctx, crate_mod: _mod) {
visit::visit_mod( visit::visit_mod(
crate_mod, ast_util::dummy_sp(), 0, cx, crate_mod, codemap::dummy_sp(), 0, cx,
visit::mk_vt(@visit::Visitor { visit::mk_vt(@visit::Visitor {
visit_expr: |_e, _cx, _v| { }, visit_expr: |_e, _cx, _v| { },
visit_item: |i, cx, v| { visit_item: |i, cx, v| {

View File

@ -28,7 +28,7 @@ use core::option::is_some;
use core::vec; use core::vec;
use std::map::HashMap; use std::map::HashMap;
use syntax::ast; use syntax::ast;
use syntax::ast_util::dummy_sp; use syntax::codemap::dummy_sp;
use syntax::codemap::span; use syntax::codemap::span;
use syntax::util::interner; use syntax::util::interner;

View File

@ -201,7 +201,7 @@ pub fn trans_slice_vstore(bcx: block,
// Handle the &"..." case: // Handle the &"..." case:
match content_expr.node { match content_expr.node {
ast::expr_lit(@ast::spanned {node: ast::lit_str(s), span: _}) => { ast::expr_lit(@codemap::spanned {node: ast::lit_str(s), span: _}) => {
return trans_lit_str(bcx, content_expr, s, dest); return trans_lit_str(bcx, content_expr, s, dest);
} }
_ => {} _ => {}
@ -296,7 +296,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block,
match heap { match heap {
heap_exchange => { heap_exchange => {
match content_expr.node { match content_expr.node {
ast::expr_lit(@ast::spanned { ast::expr_lit(@codemap::spanned {
node: ast::lit_str(s), _ node: ast::lit_str(s), _
}) => { }) => {
let llptrval = C_cstr(bcx.ccx(), copy *s); let llptrval = C_cstr(bcx.ccx(), copy *s);
@ -354,7 +354,7 @@ pub fn write_content(bcx: block,
let _indenter = indenter(); let _indenter = indenter();
match /*bad*/copy content_expr.node { match /*bad*/copy content_expr.node {
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => { ast::expr_lit(@codemap::spanned { node: ast::lit_str(s), _ }) => {
match dest { match dest {
Ignore => { Ignore => {
return bcx; return bcx;
@ -461,7 +461,7 @@ pub fn elements_required(bcx: block, content_expr: @ast::expr) -> uint {
//! Figure out the number of elements we need to store this content //! Figure out the number of elements we need to store this content
match /*bad*/copy content_expr.node { match /*bad*/copy content_expr.node {
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => { ast::expr_lit(@codemap::spanned { node: ast::lit_str(s), _ }) => {
s.len() + 1 s.len() + 1
}, },
ast::expr_vec(es, _) => es.len(), ast::expr_vec(es, _) => es.len(),

View File

@ -47,6 +47,7 @@ use syntax::ast::*;
use syntax::ast_util::{is_local, local_def}; use syntax::ast_util::{is_local, local_def};
use syntax::ast_util; use syntax::ast_util;
use syntax::codemap::span; use syntax::codemap::span;
use syntax::codemap;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::{ast, ast_map}; use syntax::{ast, ast_map};
use syntax; use syntax;
@ -3166,7 +3167,7 @@ pub fn expr_kind(tcx: ctxt,
ast::expr_block(*) | ast::expr_block(*) |
ast::expr_copy(*) | ast::expr_copy(*) |
ast::expr_repeat(*) | ast::expr_repeat(*) |
ast::expr_lit(@ast::spanned {node: lit_str(_), _}) | ast::expr_lit(@codemap::spanned {node: lit_str(_), _}) |
ast::expr_vstore(_, ast::expr_vstore_slice) | ast::expr_vstore(_, ast::expr_vstore_slice) |
ast::expr_vstore(_, ast::expr_vstore_mut_slice) | ast::expr_vstore(_, ast::expr_vstore_mut_slice) |
ast::expr_vstore(_, ast::expr_vstore_fixed(_)) | ast::expr_vstore(_, ast::expr_vstore_fixed(_)) |

View File

@ -108,7 +108,7 @@ use syntax::ast::{m_const, m_mutbl, m_imm};
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_map::node_id_to_str; use syntax::ast_map::node_id_to_str;
use syntax::ast_util::dummy_sp; use syntax::codemap::dummy_sp;
use syntax::codemap::span; use syntax::codemap::span;
pub fn lookup( pub fn lookup(

View File

@ -117,13 +117,13 @@ use core::vec;
use std::list::Nil; use std::list::Nil;
use std::map::HashMap; use std::map::HashMap;
use std::map; use std::map;
use syntax::ast::{provided, required, spanned, ty_i}; use syntax::ast::{provided, required, ty_i};
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_util::{Private, Public, is_local, local_def, respan}; use syntax::ast_util::{Private, Public, is_local, local_def};
use syntax::ast_util::{visibility_to_privacy}; use syntax::ast_util::{visibility_to_privacy};
use syntax::ast_util; use syntax::ast_util;
use syntax::codemap::span; use syntax::codemap::{span, spanned, respan};
use syntax::codemap; use syntax::codemap;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
use syntax::print::pprust; use syntax::print::pprust;
@ -528,7 +528,7 @@ pub fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
def_id: local_def(id), def_id: local_def(id),
explicit_self: explicit_self:
spanned { node: ast::sty_by_ref, spanned { node: ast::sty_by_ref,
span: ast_util::dummy_sp() } }; span: codemap::dummy_sp() } };
// typecheck the dtor // typecheck the dtor
let dtor_dec = ast_util::dtor_dec(); let dtor_dec = ast_util::dtor_dec();
check_bare_fn(ccx, &dtor_dec, check_bare_fn(ccx, &dtor_dec,
@ -1919,7 +1919,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt,
match /*bad*/copy expr.node { match /*bad*/copy expr.node {
ast::expr_vstore(ev, vst) => { ast::expr_vstore(ev, vst) => {
let typ = match /*bad*/copy ev.node { let typ = match /*bad*/copy ev.node {
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => { ast::expr_lit(@codemap::spanned { node: ast::lit_str(s), _ }) => {
let tt = ast_expr_vstore_to_vstore(fcx, ev, str::len(*s), vst); let tt = ast_expr_vstore_to_vstore(fcx, ev, str::len(*s), vst);
ty::mk_estr(tcx, tt) ty::mk_estr(tcx, tt)
} }
@ -2608,7 +2608,7 @@ pub fn check_block_with_expected(fcx0: @fn_ctxt,
for blk.node.stmts.each |s| { for blk.node.stmts.each |s| {
if bot && !warned && if bot && !warned &&
match s.node { match s.node {
ast::stmt_decl(@ast::spanned { node: ast::decl_local(_), ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
_}, _) | _}, _) |
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) => { ast::stmt_expr(_, _) | ast::stmt_semi(_, _) => {
true true

View File

@ -22,6 +22,7 @@ use util::ppaux;
use std::list::Cons; use std::list::Cons;
use syntax::ast; use syntax::ast;
use syntax::codemap;
use syntax::print::pprust::{expr_to_str}; use syntax::print::pprust::{expr_to_str};
// Helper functions related to manipulating region types. // Helper functions related to manipulating region types.
@ -57,7 +58,7 @@ pub fn replace_bound_regions_in_fn_sig(
let mut all_tys = ty::tys_in_fn_sig(fn_sig); let mut all_tys = ty::tys_in_fn_sig(fn_sig);
match self_info { match self_info {
Some({explicit_self: ast::spanned { node: ast::sty_region(m), Some({explicit_self: codemap::spanned { node: ast::sty_region(m),
_}, _}) => { _}, _}) => {
let region = ty::re_bound(ty::br_self); let region = ty::re_bound(ty::br_self);
let ty = ty::mk_rptr(tcx, region, let ty = ty::mk_rptr(tcx, region,

View File

@ -46,9 +46,9 @@ use syntax::ast::{trait_ref};
use syntax::ast; use syntax::ast;
use syntax::ast_map::node_item; use syntax::ast_map::node_item;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_util::{def_id_of_def, dummy_sp, local_def}; use syntax::ast_util::{def_id_of_def, local_def};
use syntax::attr; use syntax::attr;
use syntax::codemap::span; use syntax::codemap::{span, dummy_sp};
use syntax::parse; use syntax::parse;
use syntax::visit::{default_simple_visitor, default_visitor}; use syntax::visit::{default_simple_visitor, default_visitor};
use syntax::visit::{mk_simple_visitor, mk_vt, visit_crate, visit_item}; use syntax::visit::{mk_simple_visitor, mk_vt, visit_crate, visit_item};

View File

@ -286,7 +286,8 @@ use syntax::ast::{ret_style, purity};
use syntax::ast::{m_const, m_imm, m_mutbl}; use syntax::ast::{m_const, m_imm, m_mutbl};
use syntax::ast::{unsafe_fn, impure_fn, pure_fn, extern_fn}; use syntax::ast::{unsafe_fn, impure_fn, pure_fn, extern_fn};
use syntax::ast; use syntax::ast;
use syntax::ast_util::dummy_sp; use syntax::codemap::dummy_sp;
use syntax::codemap;
use syntax::ast_util; use syntax::ast_util;
use syntax::codemap::span; use syntax::codemap::span;
@ -389,7 +390,7 @@ pub fn can_mk_subty(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
debug!("can_mk_subty(%s <: %s)", a.inf_str(cx), b.inf_str(cx)); debug!("can_mk_subty(%s <: %s)", a.inf_str(cx), b.inf_str(cx));
do indent { do indent {
do cx.probe { do cx.probe {
cx.sub(true, ast_util::dummy_sp()).tys(a, b) cx.sub(true, codemap::dummy_sp()).tys(a, b)
} }
}.to_ures() }.to_ures()
} }
@ -429,7 +430,7 @@ pub fn can_mk_coercety(cx: @InferCtxt, a: ty::t, b: ty::t) -> ures {
debug!("can_mk_coercety(%s -> %s)", a.inf_str(cx), b.inf_str(cx)); debug!("can_mk_coercety(%s -> %s)", a.inf_str(cx), b.inf_str(cx));
do indent { do indent {
do cx.probe { do cx.probe {
let span = ast_util::dummy_sp(); let span = codemap::dummy_sp();
Coerce(cx.combine_fields(true, span)).tys(a, b) Coerce(cx.combine_fields(true, span)).tys(a, b)
} }
}.to_ures() }.to_ures()

View File

@ -31,7 +31,7 @@ use std::getopts::{opt_present};
use std::getopts; use std::getopts;
use std::getopts; use std::getopts;
use std::map::HashMap; use std::map::HashMap;
use syntax::ast_util::dummy_sp; use syntax::codemap::dummy_sp;
use syntax::parse::parse_crate_from_source_str; use syntax::parse::parse_crate_from_source_str;
use syntax::{ast, attr, parse}; use syntax::{ast, attr, parse};

View File

@ -70,10 +70,10 @@ use std::list;
use std::map::HashMap; use std::map::HashMap;
use std::map; use std::map;
use std::oldsmallintmap; use std::oldsmallintmap;
use syntax::ast::{provided, required, spanned}; use syntax::ast::{provided, required};
use syntax::ast_map::node_id_to_str; use syntax::ast_map::node_id_to_str;
use syntax::ast_util::{local_def, respan, split_trait_methods}; use syntax::ast_util::{local_def, split_trait_methods};
use syntax::codemap::span; use syntax::codemap::{span, spanned, respan};
use syntax::print::pprust::*; use syntax::print::pprust::*;
use syntax::visit; use syntax::visit;
use syntax::{ast, ast_util, ast_map}; use syntax::{ast, ast_util, ast_map};

View File

@ -10,7 +10,7 @@
// The Rust abstract syntax tree. // The Rust abstract syntax tree.
use codemap::{span, FileName}; use codemap::{span, FileName, spanned};
use core::cast; use core::cast;
use core::cmp; use core::cmp;
@ -21,10 +21,6 @@ use core::to_bytes;
use core::to_str::ToStr; use core::to_str::ToStr;
use std::serialize::{Encodable, Decodable, Encoder, Decoder}; use std::serialize::{Encodable, Decodable, Encoder, Decoder};
#[auto_encode]
#[auto_decode]
pub struct spanned<T> { node: T, span: span }
/* can't import macros yet, so this is copied from token.rs. See its comment /* can't import macros yet, so this is copied from token.rs. See its comment
* there. */ * there. */
macro_rules! interner_key ( macro_rules! interner_key (

View File

@ -13,7 +13,7 @@ use core::prelude::*;
use ast::*; use ast::*;
use ast; use ast;
use ast_util; use ast_util;
use codemap::{span, BytePos}; use codemap::{span, BytePos, dummy_sp};
use parse::token; use parse::token;
use visit; use visit;
@ -24,28 +24,6 @@ use core::str;
use core::to_bytes; use core::to_bytes;
use core::vec; use core::vec;
pub pure fn spanned<T>(+lo: BytePos, +hi: BytePos, +t: T) -> spanned<T> {
respan(mk_sp(lo, hi), move t)
}
pub pure fn respan<T>(sp: span, +t: T) -> spanned<T> {
spanned {node: t, span: sp}
}
pub pure fn dummy_spanned<T>(+t: T) -> spanned<T> {
respan(dummy_sp(), move t)
}
/* assuming that we're not in macro expansion */
pub 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
pub pure fn dummy_sp() -> span { return mk_sp(BytePos(0), BytePos(0)); }
pub pure fn path_name_i(idents: &[ident], intr: @token::ident_interner) pub pure fn path_name_i(idents: &[ident], intr: @token::ident_interner)
-> ~str { -> ~str {
// FIXME: Bad copies (#2543 -- same for everything else that says "bad") // FIXME: Bad copies (#2543 -- same for everything else that says "bad")

View File

@ -13,7 +13,7 @@
use core::prelude::*; use core::prelude::*;
use ast; use ast;
use ast_util::{spanned, dummy_spanned}; use codemap::{spanned, dummy_spanned};
use attr; use attr;
use codemap::BytePos; use codemap::BytePos;
use diagnostic::span_handler; use diagnostic::span_handler;

View File

@ -23,8 +23,6 @@ source code snippets, etc.
use core::prelude::*; use core::prelude::*;
use ast_util;
use core::cmp; use core::cmp;
use core::dvec::DVec; use core::dvec::DVec;
use core::str; use core::str;
@ -130,6 +128,10 @@ pub struct span {
expn_info: Option<@ExpnInfo> expn_info: Option<@ExpnInfo>
} }
#[auto_encode]
#[auto_decode]
pub struct spanned<T> { node: T, span: span }
pub impl span : cmp::Eq { pub impl span : cmp::Eq {
pure fn eq(&self, other: &span) -> bool { pure fn eq(&self, other: &span) -> bool {
return (*self).lo == (*other).lo && (*self).hi == (*other).hi; return (*self).lo == (*other).lo && (*self).hi == (*other).hi;
@ -144,10 +146,32 @@ pub impl<S: Encoder> span: Encodable<S> {
pub impl<D: Decoder> span: Decodable<D> { pub impl<D: Decoder> span: Decodable<D> {
static fn decode(_d: &D) -> span { static fn decode(_d: &D) -> span {
ast_util::dummy_sp() dummy_sp()
} }
} }
pub pure fn spanned<T>(+lo: BytePos, +hi: BytePos, +t: T) -> spanned<T> {
respan(mk_sp(lo, hi), move t)
}
pub pure fn respan<T>(sp: span, +t: T) -> spanned<T> {
spanned {node: t, span: sp}
}
pub pure fn dummy_spanned<T>(+t: T) -> spanned<T> {
respan(dummy_sp(), move t)
}
/* assuming that we're not in macro expansion */
pub 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
pub pure fn dummy_sp() -> span { return mk_sp(BytePos(0), BytePos(0)); }
/// A source code location used for error reporting /// A source code location used for error reporting
pub struct Loc { pub struct Loc {
/// Information about the original source /// Information about the original source
@ -158,6 +182,20 @@ pub struct Loc {
col: CharPos col: CharPos
} }
/// A source code location used as the result of lookup_char_pos_adj
// Actually, *none* of the clients use the filename *or* file field;
// perhaps they should just be removed.
pub struct LocWithOpt {
filename: ~str,
line: uint,
col: CharPos,
file: Option<@FileMap>,
}
// used to be structural records. Better names, anyone?
pub struct FileMapAndLine {fm: @FileMap, line: uint}
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
/// Extra information for tracking macro expansion of spans /// Extra information for tracking macro expansion of spans
pub enum ExpnInfo { pub enum ExpnInfo {
ExpandedFrom({call_site: span, ExpandedFrom({call_site: span,
@ -204,10 +242,19 @@ pub struct FileMap {
} }
pub impl FileMap { pub impl FileMap {
// EFFECT: register a start-of-line offset in the
// table of line-beginnings.
// UNCHECKED INVARIANT: these offsets must be added in the right
// order and must be in the right places; there is shared knowledge
// about what ends a line between this file and parse.rs
fn next_line(&self, +pos: BytePos) { fn next_line(&self, +pos: BytePos) {
// the new charpos must be > the last one (or it's the first one).
assert ((self.lines.len() == 0)
|| (self.lines[self.lines.len() - 1] < pos));
self.lines.push(pos); self.lines.push(pos);
} }
// get a line from the list of pre-computed line-beginnings
pub fn get_line(&self, line: int) -> ~str { pub fn get_line(&self, line: int) -> ~str {
unsafe { unsafe {
let begin: BytePos = self.lines[line] - self.start_pos; let begin: BytePos = self.lines[line] - self.start_pos;
@ -279,27 +326,25 @@ pub impl CodeMap {
return self.lookup_pos(pos); return self.lookup_pos(pos);
} }
pub fn lookup_char_pos_adj(&self, +pos: BytePos) pub fn lookup_char_pos_adj(&self, +pos: BytePos) -> LocWithOpt
-> {filename: ~str, line: uint, col: CharPos, file: Option<@FileMap>}
{ {
let loc = self.lookup_char_pos(pos); let loc = self.lookup_char_pos(pos);
match (loc.file.substr) { match (loc.file.substr) {
FssNone => { FssNone =>
{filename: /* FIXME (#2543) */ copy loc.file.name, LocWithOpt {
line: loc.line, filename: /* FIXME (#2543) */ copy loc.file.name,
col: loc.col, line: loc.line,
file: Some(loc.file)} col: loc.col,
} file: Some(loc.file)},
FssInternal(sp) => { FssInternal(sp) =>
self.lookup_char_pos_adj( self.lookup_char_pos_adj(
sp.lo + (pos - loc.file.start_pos)) sp.lo + (pos - loc.file.start_pos)),
} FssExternal(ref eloc) =>
FssExternal(ref eloc) => { LocWithOpt {
{filename: /* FIXME (#2543) */ copy (*eloc).filename, filename: /* FIXME (#2543) */ copy (*eloc).filename,
line: (*eloc).line + loc.line - 1u, line: (*eloc).line + loc.line - 1u,
col: if loc.line == 1 {eloc.col + loc.col} else {loc.col}, col: if loc.line == 1 {eloc.col + loc.col} else {loc.col},
file: None} file: None}
}
} }
} }
@ -319,7 +364,7 @@ pub impl CodeMap {
} }
pub fn span_to_str(&self, sp: span) -> ~str { pub fn span_to_str(&self, sp: span) -> ~str {
if self.files.len() == 0 && sp == ast_util::dummy_sp() { if self.files.len() == 0 && sp == dummy_sp() {
return ~"no-location"; return ~"no-location";
} }
@ -383,8 +428,7 @@ priv impl CodeMap {
return a; return a;
} }
fn lookup_line(&self, +pos: BytePos) fn lookup_line(&self, pos: BytePos) -> FileMapAndLine
-> {fm: @FileMap, line: uint}
{ {
let idx = self.lookup_filemap_idx(pos); let idx = self.lookup_filemap_idx(pos);
let f = self.files[idx]; let f = self.files[idx];
@ -394,11 +438,11 @@ priv impl CodeMap {
let m = (a + b) / 2u; let m = (a + b) / 2u;
if f.lines[m] > pos { b = m; } else { a = m; } if f.lines[m] > pos { b = m; } else { a = m; }
} }
return {fm: f, line: a}; return FileMapAndLine {fm: f, line: a};
} }
fn lookup_pos(&self, +pos: BytePos) -> Loc { fn lookup_pos(&self, +pos: BytePos) -> Loc {
let {fm: f, line: a} = self.lookup_line(pos); let FileMapAndLine {fm: f, line: a} = self.lookup_line(pos);
let line = a + 1u; // Line numbers start at 1 let line = a + 1u; // Line numbers start at 1
let chpos = self.bytepos_to_local_charpos(pos); let chpos = self.bytepos_to_local_charpos(pos);
let linebpos = f.lines[a]; let linebpos = f.lines[a];
@ -424,11 +468,11 @@ priv impl CodeMap {
} }
fn lookup_byte_offset(&self, +bpos: BytePos) fn lookup_byte_offset(&self, +bpos: BytePos)
-> {fm: @FileMap, pos: BytePos} { -> FileMapAndBytePos {
let idx = self.lookup_filemap_idx(bpos); let idx = self.lookup_filemap_idx(bpos);
let fm = self.files[idx]; let fm = self.files[idx];
let offset = bpos - fm.start_pos; let offset = bpos - fm.start_pos;
return {fm: fm, pos: offset}; return FileMapAndBytePos {fm: fm, pos: offset};
} }
// Converts an absolute BytePos to a CharPos relative to the file it is // Converts an absolute BytePos to a CharPos relative to the file it is
@ -458,6 +502,36 @@ priv impl CodeMap {
} }
} }
#[cfg(test)]
mod test {
use super::*;
use util::testing::check_equal;
#[test]
fn t1 () {
let cm = CodeMap::new();
let fm = cm.new_filemap(~"blork.rs",@~"first line.\nsecond line");
fm.next_line(BytePos(0));
check_equal(&fm.get_line(0),&~"first line.");
// TESTING BROKEN BEHAVIOR:
fm.next_line(BytePos(10));
check_equal(&fm.get_line(1),&~".");
}
#[test]
#[should_fail]
fn t2 () {
let cm = CodeMap::new();
let fm = cm.new_filemap(~"blork.rs",@~"first line.\nsecond line");
// TESTING *REALLY* BROKEN BEHAVIOR:
fm.next_line(BytePos(0));
fm.next_line(BytePos(10));
fm.next_line(BytePos(2));
}
}
// //
// Local Variables: // Local Variables:
// mode: rust // mode: rust

View File

@ -311,7 +311,7 @@ priv impl ext_ctxt {
} }
fn stmt(expr: @ast::expr) -> @ast::stmt { fn stmt(expr: @ast::expr) -> @ast::stmt {
@ast::spanned { node: ast::stmt_semi(expr, self.next_id()), @codemap::spanned { node: ast::stmt_semi(expr, self.next_id()),
span: expr.span } span: expr.span }
} }
@ -322,7 +322,7 @@ priv impl ext_ctxt {
self.expr( self.expr(
span, span,
ast::expr_lit( ast::expr_lit(
@ast::spanned { node: ast::lit_str(s), @codemap::spanned { node: ast::lit_str(s),
span: span})), span: span})),
ast::expr_vstore_uniq)) ast::expr_vstore_uniq))
} }
@ -331,7 +331,7 @@ priv impl ext_ctxt {
self.expr( self.expr(
span, span,
ast::expr_lit( ast::expr_lit(
@ast::spanned { node: ast::lit_uint(i as u64, ast::ty_u), @codemap::spanned { node: ast::lit_uint(i as u64, ast::ty_u),
span: span})) span: span}))
} }
@ -342,7 +342,7 @@ priv impl ext_ctxt {
} }
fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk { fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {
ast::spanned { codemap::spanned {
node: ast::blk_ { node: ast::blk_ {
view_items: ~[], view_items: ~[],
stmts: stmts, stmts: stmts,
@ -355,7 +355,7 @@ priv impl ext_ctxt {
} }
fn expr_blk(expr: @ast::expr) -> ast::blk { fn expr_blk(expr: @ast::expr) -> ast::blk {
ast::spanned { codemap::spanned {
node: ast::blk_ { node: ast::blk_ {
view_items: ~[], view_items: ~[],
stmts: ~[], stmts: ~[],
@ -593,7 +593,7 @@ fn mk_ser_method(
ident: cx.ident_of(~"encode"), ident: cx.ident_of(~"encode"),
attrs: ~[], attrs: ~[],
tps: ~[], tps: ~[],
self_ty: ast::spanned { node: ast::sty_region(ast::m_imm), self_ty: codemap::spanned { node: ast::sty_region(ast::m_imm),
span: span }, span: span },
purity: ast::impure_fn, purity: ast::impure_fn,
decl: ser_decl, decl: ser_decl,
@ -651,7 +651,7 @@ fn mk_deser_method(
ident: cx.ident_of(~"decode"), ident: cx.ident_of(~"decode"),
attrs: ~[], attrs: ~[],
tps: ~[], tps: ~[],
self_ty: ast::spanned { node: ast::sty_static, span: span }, self_ty: codemap::spanned { node: ast::sty_static, span: span },
purity: ast::impure_fn, purity: ast::impure_fn,
decl: deser_decl, decl: deser_decl,
body: deser_body, body: deser_body,
@ -762,7 +762,7 @@ fn mk_struct_deser_impl(
] ]
); );
ast::spanned { codemap::spanned {
node: ast::field_ { node: ast::field_ {
mutbl: field.mutbl, mutbl: field.mutbl,
ident: field.ident, ident: field.ident,

View File

@ -11,9 +11,8 @@
use core::prelude::*; use core::prelude::*;
use ast; use ast;
use ast_util::dummy_sp;
use codemap; use codemap;
use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom}; use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom, dummy_sp};
use diagnostic::span_handler; use diagnostic::span_handler;
use ext; use ext;
use parse; use parse;

View File

@ -32,7 +32,7 @@ pub fn mk_expr(cx: ext_ctxt,
} }
pub fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { pub fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
let sp_lit = @ast::spanned { node: lit, span: sp }; let sp_lit = @codemap::spanned { node: lit, span: sp };
mk_expr(cx, sp, ast::expr_lit(sp_lit)) mk_expr(cx, sp, ast::expr_lit(sp_lit))
} }
pub fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr { pub fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
@ -149,7 +149,7 @@ pub fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
} }
pub fn mk_field(sp: span, f: &{ident: ast::ident, ex: @ast::expr}) pub fn mk_field(sp: span, f: &{ident: ast::ident, ex: @ast::expr})
-> ast::field { -> ast::field {
ast::spanned { codemap::spanned {
node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex }, node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex },
span: sp, span: sp,
} }
@ -188,7 +188,7 @@ pub fn mk_global_struct_e(cx: ext_ctxt,
pub fn mk_glob_use(cx: ext_ctxt, pub fn mk_glob_use(cx: ext_ctxt,
sp: span, sp: span,
path: ~[ast::ident]) -> @ast::view_item { path: ~[ast::ident]) -> @ast::view_item {
let glob = @ast::spanned { let glob = @codemap::spanned {
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()), node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
span: sp, span: sp,
}; };
@ -209,7 +209,7 @@ pub fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
span: sp, span: sp,
}; };
let ty = @ast::Ty { id: cx.next_id(), node: ast::ty_infer, span: sp }; let ty = @ast::Ty { id: cx.next_id(), node: ast::ty_infer, span: sp };
let local = @ast::spanned { let local = @codemap::spanned {
node: ast::local_ { node: ast::local_ {
is_mutbl: mutbl, is_mutbl: mutbl,
ty: ty, ty: ty,
@ -219,14 +219,14 @@ pub fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
}, },
span: sp, span: sp,
}; };
let decl = ast::spanned {node: ast::decl_local(~[local]), span: sp}; let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp};
@ast::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } @codemap::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp }
} }
pub fn mk_block(cx: ext_ctxt, span: span, pub fn mk_block(cx: ext_ctxt, span: span,
view_items: ~[@ast::view_item], view_items: ~[@ast::view_item],
stmts: ~[@ast::stmt], stmts: ~[@ast::stmt],
expr: Option<@ast::expr>) -> @ast::expr { expr: Option<@ast::expr>) -> @ast::expr {
let blk = ast::spanned { let blk = codemap::spanned {
node: ast::blk_ { node: ast::blk_ {
view_items: view_items, view_items: view_items,
stmts: stmts, stmts: stmts,
@ -242,7 +242,7 @@ pub fn mk_block_(cx: ext_ctxt,
span: span, span: span,
+stmts: ~[@ast::stmt]) +stmts: ~[@ast::stmt])
-> ast::blk { -> ast::blk {
ast::spanned { codemap::spanned {
node: ast::blk_ { node: ast::blk_ {
view_items: ~[], view_items: ~[],
stmts: stmts, stmts: stmts,
@ -257,7 +257,7 @@ pub fn mk_simple_block(cx: ext_ctxt,
span: span, span: span,
expr: @ast::expr) expr: @ast::expr)
-> ast::blk { -> ast::blk {
ast::spanned { codemap::spanned {
node: ast::blk_ { node: ast::blk_ {
view_items: ~[], view_items: ~[],
stmts: ~[], stmts: ~[],
@ -307,13 +307,14 @@ pub fn mk_pat_struct(cx: ext_ctxt,
mk_pat(cx, span, move pat) mk_pat(cx, span, move pat)
} }
pub fn mk_bool(cx: ext_ctxt, span: span, value: bool) -> @ast::expr { pub fn mk_bool(cx: ext_ctxt, span: span, value: bool) -> @ast::expr {
let lit_expr = ast::expr_lit(@ast::spanned { node: ast::lit_bool(value), let lit_expr = ast::expr_lit(@codemap::spanned {
span: span }); node: ast::lit_bool(value),
span: span });
build::mk_expr(cx, span, move lit_expr) build::mk_expr(cx, span, move lit_expr)
} }
pub fn mk_stmt(cx: ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt { pub fn mk_stmt(cx: ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt {
let stmt_ = ast::stmt_semi(expr, cx.next_id()); let stmt_ = ast::stmt_semi(expr, cx.next_id());
@ast::spanned { node: move stmt_, span: span } @codemap::spanned { node: move stmt_, span: span }
} }
pub fn mk_ty_path(cx: ext_ctxt, pub fn mk_ty_path(cx: ext_ctxt,
span: span, span: span,

View File

@ -18,12 +18,12 @@ use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, item, item_}; use ast::{enum_variant_kind, expr, expr_match, ident, item, item_};
use ast::{item_enum, item_impl, item_struct, m_imm, meta_item, method}; use ast::{item_enum, item_impl, item_struct, m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn}; use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
use ast::{re_anon, spanned, stmt, struct_def, struct_variant_kind}; use ast::{re_anon, stmt, struct_def, struct_variant_kind};
use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, ty_param}; use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, ty_param};
use ast::{ty_param_bound, ty_path, ty_rptr, unnamed_field, variant}; use ast::{ty_param_bound, ty_path, ty_rptr, unnamed_field, variant};
use ext::base::ext_ctxt; use ext::base::ext_ctxt;
use ext::build; use ext::build;
use codemap::span; use codemap::{span, spanned};
use parse::token::special_idents::clownshoes_extensions; use parse::token::special_idents::clownshoes_extensions;
use core::dvec; use core::dvec;

View File

@ -154,7 +154,7 @@ pub fn expand_item_mac(exts: HashMap<~str, SyntaxExtension>,
fld: ast_fold) -> Option<@ast::item> { fld: ast_fold) -> Option<@ast::item> {
let (pth, tts) = match it.node { let (pth, tts) = match it.node {
item_mac(ast::spanned { node: mac_invoc_tt(pth, ref tts), _}) => { item_mac(codemap::spanned { node: mac_invoc_tt(pth, ref tts), _}) => {
(pth, (*tts)) (pth, (*tts))
} }
_ => cx.span_bug(it.span, ~"invalid item macro invocation") _ => cx.span_bug(it.span, ~"invalid item macro invocation")
@ -234,7 +234,7 @@ pub fn expand_stmt(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
{call_site: sp, callie: {name: *extname, span: exp_sp}})); {call_site: sp, callie: {name: *extname, span: exp_sp}}));
let expanded = match exp(cx, mac.span, tts) { let expanded = match exp(cx, mac.span, tts) {
MRExpr(e) => MRExpr(e) =>
@ast::spanned { node: stmt_expr(e, cx.next_id()), @codemap::spanned { node: stmt_expr(e, cx.next_id()),
span: e.span}, span: e.span},
MRAny(_,_,stmt_mkr) => stmt_mkr(), MRAny(_,_,stmt_mkr) => stmt_mkr(),
_ => cx.span_fatal( _ => cx.span_fatal(

View File

@ -17,10 +17,11 @@ use core::prelude::*;
use ast::{ident, node_id}; use ast::{ident, node_id};
use ast; use ast;
use ast_util::{ident_to_path, respan, dummy_sp}; use ast_util::{ident_to_path};
use ast_util; use ast_util;
use attr; use attr;
use codemap::span; use codemap::{span, respan, dummy_sp};
use codemap;
use ext::base::{ext_ctxt, mk_ctxt}; use ext::base::{ext_ctxt, mk_ctxt};
use ext::quote::rt::*; use ext::quote::rt::*;
@ -310,7 +311,7 @@ pub impl ext_ctxt: ext_ctxt_ast_builder {
// XXX: Total hack: import `core::kinds::Owned` to work around a // XXX: Total hack: import `core::kinds::Owned` to work around a
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse. // parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
let vi = ast::view_item_import(~[ let vi = ast::view_item_import(~[
@ast::spanned { @codemap::spanned {
node: ast::view_path_simple( node: ast::view_path_simple(
self.ident_of(~"Owned"), self.ident_of(~"Owned"),
path( path(
@ -319,19 +320,19 @@ pub impl ext_ctxt: ext_ctxt_ast_builder {
self.ident_of(~"kinds"), self.ident_of(~"kinds"),
self.ident_of(~"Owned") self.ident_of(~"Owned")
], ],
ast_util::dummy_sp() codemap::dummy_sp()
), ),
ast::type_value_ns, ast::type_value_ns,
self.next_id() self.next_id()
), ),
span: ast_util::dummy_sp() span: codemap::dummy_sp()
} }
]); ]);
let vi = @ast::view_item { let vi = @ast::view_item {
node: vi, node: vi,
attrs: ~[], attrs: ~[],
vis: ast::private, vis: ast::private,
span: ast_util::dummy_sp() span: codemap::dummy_sp()
}; };
self.item( self.item(

View File

@ -11,7 +11,7 @@
// A protocol compiler for Rust. // A protocol compiler for Rust.
use ast::ident; use ast::ident;
use ast_util::dummy_sp; use codemap::dummy_sp;
use ext::base::ext_ctxt; use ext::base::ext_ctxt;
use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path}; use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path};
use ext::pipes::ast_builder::{path_global}; use ext::pipes::ast_builder::{path_global};

View File

@ -10,8 +10,7 @@
// Earley-like parser for macros. // Earley-like parser for macros.
use ast::{matcher, match_tok, match_seq, match_nonterminal, ident}; use ast::{matcher, match_tok, match_seq, match_nonterminal, ident};
use ast_util::mk_sp; use codemap::{BytePos, mk_sp};
use codemap::BytePos;
use codemap; use codemap;
use parse::common::*; //resolve bug? use parse::common::*; //resolve bug?
use parse::lexer::*; //resolve bug? use parse::lexer::*; //resolve bug?
@ -189,13 +188,13 @@ pub fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match])
fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match], fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match],
ret_val: HashMap<ident, @named_match>) { ret_val: HashMap<ident, @named_match>) {
match m { match m {
ast::spanned {node: match_tok(_), _} => (), codemap::spanned {node: match_tok(_), _} => (),
ast::spanned {node: match_seq(ref more_ms, _, _, _, _), _} => { codemap::spanned {node: match_seq(ref more_ms, _, _, _, _), _} => {
for (*more_ms).each() |next_m| { for (*more_ms).each() |next_m| {
n_rec(p_s, *next_m, res, ret_val) n_rec(p_s, *next_m, res, ret_val)
}; };
} }
ast::spanned { codemap::spanned {
node: match_nonterminal(bind_name, _, idx), span: sp node: match_nonterminal(bind_name, _, idx), span: sp
} => { } => {
if ret_val.contains_key(bind_name) { if ret_val.contains_key(bind_name) {
@ -239,7 +238,7 @@ pub fn parse(sess: parse_sess,
let mut next_eis = ~[]; // or proceed normally let mut next_eis = ~[]; // or proceed normally
let mut eof_eis = ~[]; let mut eof_eis = ~[];
let {tok: tok, sp: sp} = rdr.peek(); let TokenAndSpan {tok: tok, sp: sp} = rdr.peek();
/* we append new items to this while we go */ /* we append new items to this while we go */
while cur_eis.len() > 0u { /* for each Earley Item */ while cur_eis.len() > 0u { /* for each Earley Item */

View File

@ -13,8 +13,7 @@ use core::prelude::*;
use ast::{ident, matcher_, matcher, match_tok, match_nonterminal, match_seq}; use ast::{ident, matcher_, matcher, match_tok, match_nonterminal, match_seq};
use ast::{tt_delim}; use ast::{tt_delim};
use ast; use ast;
use ast_util::dummy_sp; use codemap::{span, spanned, dummy_sp};
use codemap::span;
use ext::base::{ext_ctxt, MacResult, MRAny, MRDef, MacroDef, NormalTT}; use ext::base::{ext_ctxt, MacResult, MRAny, MRDef, MacroDef, NormalTT};
use ext::base; use ext::base;
use ext::tt::macro_parser::{error}; use ext::tt::macro_parser::{error};
@ -33,7 +32,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
arg: ~[ast::token_tree]) -> base::MacResult { arg: ~[ast::token_tree]) -> base::MacResult {
// these spans won't matter, anyways // these spans won't matter, anyways
fn ms(m: matcher_) -> matcher { fn ms(m: matcher_) -> matcher {
ast::spanned { node: m, span: dummy_sp() } spanned { node: m, span: dummy_sp() }
} }
let lhs_nm = cx.parse_sess().interner.gensym(@~"lhs"); let lhs_nm = cx.parse_sess().interner.gensym(@~"lhs");

View File

@ -13,10 +13,11 @@ use core::prelude::*;
use ast; use ast;
use ast::{token_tree, tt_delim, tt_tok, tt_seq, tt_nonterminal,ident}; use ast::{token_tree, tt_delim, tt_tok, tt_seq, tt_nonterminal,ident};
use ast_util; use ast_util;
use codemap::span; use codemap::{span, dummy_sp};
use diagnostic::span_handler; use diagnostic::span_handler;
use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal}; use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal};
use parse::token::{EOF, INTERPOLATED, IDENT, Token, nt_ident, ident_interner}; use parse::token::{EOF, INTERPOLATED, IDENT, Token, nt_ident, ident_interner};
use parse::lexer::TokenAndSpan;
use core::option; use core::option;
use core::vec; use core::vec;
@ -69,7 +70,7 @@ pub fn new_tt_reader(sp_diag: span_handler, itr: @ident_interner,
mut repeat_len: ~[], mut repeat_len: ~[],
/* dummy values, never read: */ /* dummy values, never read: */
mut cur_tok: EOF, mut cur_tok: EOF,
mut cur_span: ast_util::dummy_sp() mut cur_span: dummy_sp()
}; };
tt_next_token(r); /* get cur_tok and cur_span set up */ tt_next_token(r); /* get cur_tok and cur_span set up */
return r; return r;
@ -149,8 +150,8 @@ fn lockstep_iter_size(t: token_tree, r: tt_reader) -> lis {
} }
pub fn tt_next_token(&&r: tt_reader) -> {tok: Token, sp: span} { pub fn tt_next_token(&&r: tt_reader) -> TokenAndSpan {
let ret_val = { tok: r.cur_tok, sp: r.cur_span }; let ret_val = TokenAndSpan { tok: r.cur_tok, sp: r.cur_span };
while r.cur.idx >= r.cur.readme.len() { while r.cur.idx >= r.cur.readme.len() {
/* done with this set; pop or repeat? */ /* done with this set; pop or repeat? */
if ! r.cur.dotdotdoted if ! r.cur.dotdotdoted

View File

@ -11,7 +11,7 @@
use core::prelude::*; use core::prelude::*;
use ast; use ast;
use ast_util::spanned; use codemap::spanned;
use codemap::BytePos; use codemap::BytePos;
use parse::common::*; //resolve bug? use parse::common::*; //resolve bug?
use parse::token; use parse::token;

View File

@ -13,6 +13,7 @@
*/ */
use ast; use ast;
use codemap;
use ast_util::operator_prec; use ast_util::operator_prec;
pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
@ -31,7 +32,8 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
pub fn expr_is_simple_block(e: @ast::expr) -> bool { pub fn expr_is_simple_block(e: @ast::expr) -> bool {
match e.node { match e.node {
ast::expr_block( ast::expr_block(
ast::spanned { node: ast::blk_ { rules: ast::default_blk, _ }, _ } codemap::spanned {
node: ast::blk_ { rules: ast::default_blk, _ }, _ }
) => true, ) => true,
_ => false _ => false
} }

View File

@ -14,7 +14,7 @@ use ast;
use codemap::{BytePos, CharPos, CodeMap, FileMap, Pos}; use codemap::{BytePos, CharPos, CodeMap, FileMap, Pos};
use diagnostic; use diagnostic;
use parse::lexer::{is_whitespace, get_str_from, reader}; use parse::lexer::{is_whitespace, get_str_from, reader};
use parse::lexer::{string_reader, bump, is_eof, nextch}; use parse::lexer::{string_reader, bump, is_eof, nextch, TokenAndSpan};
use parse::lexer; use parse::lexer;
use parse::token; use parse::token;
use parse; use parse;
@ -334,7 +334,7 @@ pub fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
let bstart = rdr.pos; let bstart = rdr.pos;
rdr.next_token(); rdr.next_token();
//discard, and look ahead; we're working with internal state //discard, and look ahead; we're working with internal state
let {tok: tok, sp: sp} = rdr.peek(); let TokenAndSpan {tok: tok, sp: sp} = rdr.peek();
if token::is_lit(tok) { if token::is_lit(tok) {
let s = get_str_from(rdr, bstart); let s = get_str_from(rdr, bstart);
literals.push({lit: s, pos: sp.lo}); literals.push({lit: s, pos: sp.lo});

View File

@ -11,8 +11,7 @@
use core::prelude::*; use core::prelude::*;
use ast; use ast;
use ast_util::spanned; use codemap::{BytePos, spanned};
use codemap::BytePos;
use parse::lexer::reader; use parse::lexer::reader;
use parse::parser::Parser; use parse::parser::Parser;
use parse::token; use parse::token;
@ -190,7 +189,9 @@ pub impl Parser {
if self.token == token::GT { if self.token == token::GT {
self.bump(); self.bump();
} else if self.token == token::BINOP(token::SHR) { } else if self.token == token::BINOP(token::SHR) {
self.swap(token::GT, self.span.lo + BytePos(1u), self.span.hi); self.replace_token(token::GT,
self.span.lo + BytePos(1u),
self.span.hi);
} else { } else {
let mut s: ~str = ~"expected `"; let mut s: ~str = ~"expected `";
s += token_to_str(self.reader, token::GT); s += token_to_str(self.reader, token::GT);
@ -229,7 +230,7 @@ pub impl Parser {
} }
fn parse_seq_lt_gt<T: Copy>(sep: Option<token::Token>, fn parse_seq_lt_gt<T: Copy>(sep: Option<token::Token>,
f: fn(Parser) -> T) -> ast::spanned<~[T]> { f: fn(Parser) -> T) -> spanned<~[T]> {
let lo = self.span.lo; let lo = self.span.lo;
self.expect(token::LT); self.expect(token::LT);
let result = self.parse_seq_to_before_gt::<T>(sep, f); let result = self.parse_seq_to_before_gt::<T>(sep, f);
@ -277,7 +278,7 @@ pub impl Parser {
// NB: Do not use this function unless you actually plan to place the // NB: Do not use this function unless you actually plan to place the
// spanned list in the AST. // spanned list in the AST.
fn parse_seq<T: Copy>(bra: token::Token, ket: token::Token, sep: seq_sep, fn parse_seq<T: Copy>(bra: token::Token, ket: token::Token, sep: seq_sep,
f: fn(Parser) -> T) -> ast::spanned<~[T]> { f: fn(Parser) -> T) -> spanned<~[T]> {
let lo = self.span.lo; let lo = self.span.lo;
self.expect(bra); self.expect(bra);
let result = self.parse_seq_to_before_end::<T>(ket, sep, f); let result = self.parse_seq_to_before_end::<T>(ket, sep, f);

View File

@ -10,8 +10,7 @@
use parser::Parser; use parser::Parser;
use attr::parser_attr; use attr::parser_attr;
use ast_util::mk_sp; use codemap::{span, mk_sp};
use codemap::span;
type ctx = type ctx =
@{sess: parse::parse_sess, @{sess: parse::parse_sess,
@ -75,7 +74,7 @@ fn parse_companion_mod(cx: ctx, prefix: &Path, suffix: &Option<Path>)
// XXX: Using a dummy span, but this code will go away soon // XXX: Using a dummy span, but this code will go away soon
let p0 = new_sub_parser_from_file(cx.sess, cx.cfg, let p0 = new_sub_parser_from_file(cx.sess, cx.cfg,
modpath, modpath,
ast_util::dummy_sp()); codemap::dummy_sp());
let inner_attrs = p0.parse_inner_attrs_and_next(); let inner_attrs = p0.parse_inner_attrs_and_next();
let m0 = p0.parse_mod_items(token::EOF, inner_attrs.next); let m0 = p0.parse_mod_items(token::EOF, inner_attrs.next);
return (m0.view_items, m0.items, inner_attrs.inner); return (m0.view_items, m0.items, inner_attrs.inner);

View File

@ -30,14 +30,17 @@ use std;
pub trait reader { pub trait reader {
fn is_eof() -> bool; fn is_eof() -> bool;
fn next_token() -> {tok: token::Token, sp: span}; fn next_token() -> TokenAndSpan;
fn fatal(~str) -> !; fn fatal(~str) -> !;
fn span_diag() -> span_handler; fn span_diag() -> span_handler;
pure fn interner() -> @token::ident_interner; pure fn interner() -> @token::ident_interner;
fn peek() -> {tok: token::Token, sp: span}; fn peek() -> TokenAndSpan;
fn dup() -> reader; fn dup() -> reader;
} }
#[deriving_eq]
pub struct TokenAndSpan {tok: token::Token, sp: span}
pub type string_reader = @{ pub type string_reader = @{
span_diagnostic: span_handler, span_diagnostic: span_handler,
src: @~str, src: @~str,
@ -79,11 +82,14 @@ pub fn new_low_level_string_reader(span_diagnostic: span_handler,
filemap: filemap, interner: itr, filemap: filemap, interner: itr,
/* dummy values; not read */ /* dummy values; not read */
mut peek_tok: token::EOF, mut peek_tok: token::EOF,
mut peek_span: ast_util::dummy_sp()}; mut peek_span: codemap::dummy_sp()};
bump(r); bump(r);
return r; return r;
} }
// duplicating the string reader is probably a bad idea, in
// that using them will cause interleaved pushes of line
// offsets to the underlying filemap...
fn dup_string_reader(&&r: string_reader) -> string_reader { fn dup_string_reader(&&r: string_reader) -> string_reader {
@{span_diagnostic: r.span_diagnostic, src: r.src, @{span_diagnostic: r.span_diagnostic, src: r.src,
mut pos: r.pos, mut pos: r.pos,
@ -95,8 +101,9 @@ fn dup_string_reader(&&r: string_reader) -> string_reader {
impl string_reader: reader { impl string_reader: reader {
fn is_eof() -> bool { is_eof(self) } fn is_eof() -> bool { is_eof(self) }
fn next_token() -> {tok: token::Token, sp: span} { // return the next token. EFFECT: advances the string_reader.
let ret_val = {tok: self.peek_tok, sp: self.peek_span}; fn next_token() -> TokenAndSpan {
let ret_val = TokenAndSpan {tok: self.peek_tok, sp: self.peek_span};
string_advance_token(self); string_advance_token(self);
return ret_val; return ret_val;
} }
@ -105,15 +112,15 @@ impl string_reader: reader {
} }
fn span_diag() -> span_handler { self.span_diagnostic } fn span_diag() -> span_handler { self.span_diagnostic }
pure fn interner() -> @token::ident_interner { self.interner } pure fn interner() -> @token::ident_interner { self.interner }
fn peek() -> {tok: token::Token, sp: span} { fn peek() -> TokenAndSpan {
{tok: self.peek_tok, sp: self.peek_span} TokenAndSpan {tok: self.peek_tok, sp: self.peek_span}
} }
fn dup() -> reader { dup_string_reader(self) as reader } fn dup() -> reader { dup_string_reader(self) as reader }
} }
pub impl tt_reader: reader { pub impl tt_reader: reader {
fn is_eof() -> bool { self.cur_tok == token::EOF } fn is_eof() -> bool { self.cur_tok == token::EOF }
fn next_token() -> {tok: token::Token, sp: span} { fn next_token() -> TokenAndSpan {
/* weird resolve bug: if the following `if`, or any of its /* weird resolve bug: if the following `if`, or any of its
statements are removed, we get resolution errors */ statements are removed, we get resolution errors */
if false { if false {
@ -127,27 +134,29 @@ pub impl tt_reader: reader {
} }
fn span_diag() -> span_handler { self.sp_diag } fn span_diag() -> span_handler { self.sp_diag }
pure fn interner() -> @token::ident_interner { self.interner } pure fn interner() -> @token::ident_interner { self.interner }
fn peek() -> {tok: token::Token, sp: span} { fn peek() -> TokenAndSpan {
{ tok: self.cur_tok, sp: self.cur_span } TokenAndSpan { tok: self.cur_tok, sp: self.cur_span }
} }
fn dup() -> reader { dup_tt_reader(self) as reader } fn dup() -> reader { dup_tt_reader(self) as reader }
} }
// EFFECT: advance peek_tok and peek_span to refer to the next token.
fn string_advance_token(&&r: string_reader) { fn string_advance_token(&&r: string_reader) {
for consume_whitespace_and_comments(r).each |comment| { match (consume_whitespace_and_comments(r)) {
r.peek_tok = comment.tok; Some(comment) => {
r.peek_span = comment.sp; r.peek_tok = comment.tok;
return; r.peek_span = comment.sp;
},
None => {
if is_eof(r) {
r.peek_tok = token::EOF;
} else {
let start_bytepos = r.last_pos;
r.peek_tok = next_token_inner(r);
r.peek_span = codemap::mk_sp(start_bytepos, r.last_pos);
};
}
} }
if is_eof(r) {
r.peek_tok = token::EOF;
} else {
let start_bytepos = r.last_pos;
r.peek_tok = next_token_inner(r);
r.peek_span = ast_util::mk_sp(start_bytepos, r.last_pos);
};
} }
fn byte_offset(rdr: string_reader) -> BytePos { fn byte_offset(rdr: string_reader) -> BytePos {
@ -163,6 +172,8 @@ pub fn get_str_from(rdr: string_reader, start: BytePos) -> ~str {
} }
} }
// EFFECT: advance the StringReader by one character. If a newline is
// discovered, add it to the FileMap's list of line start offsets.
pub fn bump(rdr: string_reader) { pub fn bump(rdr: string_reader) {
rdr.last_pos = rdr.pos; rdr.last_pos = rdr.pos;
let current_byte_offset = byte_offset(rdr).to_uint();; let current_byte_offset = byte_offset(rdr).to_uint();;
@ -233,16 +244,19 @@ fn is_hex_digit(c: char) -> bool {
fn is_bin_digit(c: char) -> bool { return c == '0' || c == '1'; } fn is_bin_digit(c: char) -> bool { return c == '0' || c == '1'; }
// might return a sugared-doc-attr // EFFECT: eats whitespace and comments.
// returns a Some(sugared-doc-attr) if one exists, None otherwise.
fn consume_whitespace_and_comments(rdr: string_reader) fn consume_whitespace_and_comments(rdr: string_reader)
-> Option<{tok: token::Token, sp: span}> { -> Option<TokenAndSpan> {
while is_whitespace(rdr.curr) { bump(rdr); } while is_whitespace(rdr.curr) { bump(rdr); }
return consume_any_line_comment(rdr); return consume_any_line_comment(rdr);
} }
// might return a sugared-doc-attr // PRECONDITION: rdr.curr is not whitespace
// EFFECT: eats any kind of comment.
// returns a Some(sugared-doc-attr) if one exists, None otherwise
fn consume_any_line_comment(rdr: string_reader) fn consume_any_line_comment(rdr: string_reader)
-> Option<{tok: token::Token, sp: span}> { -> Option<TokenAndSpan> {
if rdr.curr == '/' { if rdr.curr == '/' {
match nextch(rdr) { match nextch(rdr) {
'/' => { '/' => {
@ -256,9 +270,9 @@ fn consume_any_line_comment(rdr: string_reader)
str::push_char(&mut acc, rdr.curr); str::push_char(&mut acc, rdr.curr);
bump(rdr); bump(rdr);
} }
return Some({ return Some(TokenAndSpan{
tok: token::DOC_COMMENT(rdr.interner.intern(@acc)), tok: token::DOC_COMMENT(rdr.interner.intern(@acc)),
sp: ast_util::mk_sp(start_bpos, rdr.pos) sp: codemap::mk_sp(start_bpos, rdr.pos)
}); });
} else { } else {
while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); } while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); }
@ -285,7 +299,7 @@ fn consume_any_line_comment(rdr: string_reader)
// might return a sugared-doc-attr // might return a sugared-doc-attr
fn consume_block_comment(rdr: string_reader) fn consume_block_comment(rdr: string_reader)
-> Option<{tok: token::Token, sp: span}> { -> Option<TokenAndSpan> {
// block comments starting with "/**" or "/*!" are doc-comments // block comments starting with "/**" or "/*!" are doc-comments
if rdr.curr == '*' || rdr.curr == '!' { if rdr.curr == '*' || rdr.curr == '!' {
@ -301,9 +315,9 @@ fn consume_block_comment(rdr: string_reader)
acc += ~"*/"; acc += ~"*/";
bump(rdr); bump(rdr);
bump(rdr); bump(rdr);
return Some({ return Some(TokenAndSpan{
tok: token::DOC_COMMENT(rdr.interner.intern(@acc)), tok: token::DOC_COMMENT(rdr.interner.intern(@acc)),
sp: ast_util::mk_sp(start_bpos, rdr.pos) sp: codemap::mk_sp(start_bpos, rdr.pos)
}); });
} }
} else { } else {
@ -702,6 +716,41 @@ fn consume_whitespace(rdr: string_reader) {
while is_whitespace(rdr.curr) && !is_eof(rdr) { bump(rdr); } while is_whitespace(rdr.curr) && !is_eof(rdr) { bump(rdr); }
} }
#[cfg(test)]
pub mod test {
use super::*;
use util::interner;
use diagnostic;
use util::testing::{check_equal, check_equal_ptr};
#[test] fn t1 () {
let teststr =
@~"/* my source file */
fn main() { io::println(~\"zebra\"); }\n";
let cm = CodeMap::new();
let fm = cm.new_filemap(~"zebra.rs",teststr);
let ident_interner = token::mk_ident_interner(); // interner::mk();
let id = ident_interner.intern(@~"fn");
let span_handler =
diagnostic::mk_span_handler(diagnostic::mk_handler(None),@cm);
let string_reader = new_string_reader(span_handler,fm,ident_interner);
let tok1 = string_reader.next_token();
let tok2 = TokenAndSpan{
tok:token::IDENT(id, false),
sp:span {lo:BytePos(21),hi:BytePos(23),expn_info: None}};
check_equal (tok1,tok2);
// the 'main' id is already read:
check_equal (string_reader.last_pos,BytePos(28));
// read another token:
let tok3 = string_reader.next_token();
let tok4 = TokenAndSpan{
tok:token::IDENT(ident_interner.intern (@~"main"), false),
sp:span {lo:BytePos(24),hi:BytePos(28),expn_info: None}};
check_equal (tok3,tok4);
// the lparen is already read:
check_equal (string_reader.last_pos,BytePos(29))
}
}
// //
// Local Variables: // Local Variables:

View File

@ -10,6 +10,7 @@
//! The main parser interface //! The main parser interface
use ast::node_id; use ast::node_id;
use ast; use ast;
use codemap::{span, CodeMap, FileMap, CharPos, BytePos}; use codemap::{span, CodeMap, FileMap, CharPos, BytePos};
@ -33,6 +34,7 @@ pub mod token;
pub mod comments; pub mod comments;
pub mod attr; pub mod attr;
/// Common routines shared by parser mods /// Common routines shared by parser mods
pub mod common; pub mod common;
@ -215,3 +217,4 @@ pub fn new_parser_from_tts(sess: parse_sess, cfg: ast::crate_cfg,
None, tts); None, tts);
return Parser(sess, cfg, trdr as reader) return Parser(sess, cfg, trdr as reader)
} }

View File

@ -21,8 +21,7 @@ use core::prelude::*;
use ast::{expr, expr_lit, lit_nil}; use ast::{expr, expr_lit, lit_nil};
use ast; use ast;
use ast_util::{respan}; use codemap::{span, respan};
use codemap::span;
use parse::parser::Parser; use parse::parser::Parser;
use parse::token::Token; use parse::token::Token;
use parse::token; use parse::token;

View File

@ -55,15 +55,16 @@ use ast::{view_path, view_path_glob, view_path_list, view_path_simple};
use ast::{visibility, vstore, vstore_box, vstore_fixed, vstore_slice}; use ast::{visibility, vstore, vstore_box, vstore_fixed, vstore_slice};
use ast::{vstore_uniq}; use ast::{vstore_uniq};
use ast; use ast;
use ast_util::{spanned, respan, mk_sp, ident_to_path, operator_prec}; use ast_util::{ident_to_path, operator_prec};
use ast_util; use ast_util;
use classify; use classify;
use codemap::{span,FssNone, BytePos}; use codemap::{span,FssNone, BytePos, spanned, respan, mk_sp};
use codemap; use codemap;
use parse::attr::parser_attr; use parse::attr::parser_attr;
use parse::common::{seq_sep_none, token_to_str}; use parse::common::{seq_sep_none, token_to_str};
use parse::common::{seq_sep_trailing_disallowed, seq_sep_trailing_allowed}; use parse::common::{seq_sep_trailing_disallowed, seq_sep_trailing_allowed};
use parse::lexer::reader; use parse::lexer::reader;
use parse::lexer::TokenAndSpan;
use parse::obsolete::{ObsoleteClassTraits, ObsoleteModeInFnType}; use parse::obsolete::{ObsoleteClassTraits, ObsoleteModeInFnType};
use parse::obsolete::{ObsoleteLet, ObsoleteFieldTerminator}; use parse::obsolete::{ObsoleteLet, ObsoleteFieldTerminator};
use parse::obsolete::{ObsoleteMoveInit, ObsoleteBinaryMove}; use parse::obsolete::{ObsoleteMoveInit, ObsoleteBinaryMove};
@ -193,7 +194,7 @@ pub fn Parser(sess: parse_sess,
token: tok0.tok, token: tok0.tok,
span: span0, span: span0,
last_span: span0, last_span: span0,
buffer: [mut {tok: tok0.tok, sp: span0}, ..4], buffer: [mut TokenAndSpan {tok: tok0.tok, sp: span0}, ..4],
buffer_start: 0, buffer_start: 0,
buffer_end: 0, buffer_end: 0,
tokens_consumed: 0u, tokens_consumed: 0u,
@ -213,7 +214,7 @@ pub struct Parser {
mut token: token::Token, mut token: token::Token,
mut span: span, mut span: span,
mut last_span: span, mut last_span: span,
mut buffer: [mut {tok: token::Token, sp: span} * 4], mut buffer: [mut TokenAndSpan * 4],
mut buffer_start: int, mut buffer_start: int,
mut buffer_end: int, mut buffer_end: int,
mut tokens_consumed: uint, mut tokens_consumed: uint,
@ -234,6 +235,7 @@ pub struct Parser {
} }
pub impl Parser { pub impl Parser {
// advance the parser by one token
fn bump() { fn bump() {
self.last_span = self.span; self.last_span = self.span;
let next = if self.buffer_start == self.buffer_end { let next = if self.buffer_start == self.buffer_end {
@ -247,7 +249,8 @@ pub impl Parser {
self.span = next.sp; self.span = next.sp;
self.tokens_consumed += 1u; self.tokens_consumed += 1u;
} }
fn swap(next: token::Token, +lo: BytePos, +hi: BytePos) { // EFFECT: replace the current token and span with the given one
fn replace_token(next: token::Token, +lo: BytePos, +hi: BytePos) {
self.token = next; self.token = next;
self.span = mk_sp(lo, hi); self.span = mk_sp(lo, hi);
} }
@ -800,7 +803,7 @@ pub impl Parser {
self.bump(); self.bump();
self.lit_from_token(tok) self.lit_from_token(tok)
}; };
ast::spanned { node: lit, span: mk_sp(lo, self.last_span.hi) } codemap::spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }
} }
fn parse_path_without_tps() -> @path { fn parse_path_without_tps() -> @path {
@ -875,7 +878,7 @@ pub impl Parser {
self.parse_seq_lt_gt(Some(token::COMMA), self.parse_seq_lt_gt(Some(token::COMMA),
|p| p.parse_ty(false)) |p| p.parse_ty(false))
} else { } else {
ast::spanned {node: ~[], span: path.span} codemap::spanned {node: ~[], span: path.span}
} }
}; };
@ -917,14 +920,14 @@ pub impl Parser {
@expr { @expr {
id: self.get_id(), id: self.get_id(),
callee_id: self.get_id(), callee_id: self.get_id(),
node: expr_mac(ast::spanned {node: m, span: mk_sp(lo, hi)}), node: expr_mac(codemap::spanned {node: m, span: mk_sp(lo, hi)}),
span: mk_sp(lo, hi), span: mk_sp(lo, hi),
} }
} }
fn mk_lit_u32(i: u32) -> @expr { fn mk_lit_u32(i: u32) -> @expr {
let span = self.span; let span = self.span;
let lv_lit = @ast::spanned { node: lit_uint(i as u64, ty_u32), let lv_lit = @codemap::spanned { node: lit_uint(i as u64, ty_u32),
span: span }; span: span };
@expr { @expr {
@ -1404,7 +1407,7 @@ pub impl Parser {
hi = e.span.hi; hi = e.span.hi;
// HACK: turn &[...] into a &-evec // HACK: turn &[...] into a &-evec
ex = match e.node { ex = match e.node {
expr_vec(*) | expr_lit(@ast::spanned { expr_vec(*) | expr_lit(@codemap::spanned {
node: lit_str(_), span: _ node: lit_str(_), span: _
}) })
if m == m_imm => { if m == m_imm => {
@ -1429,7 +1432,7 @@ pub impl Parser {
expr_vec(*) if m == m_mutbl => expr_vec(*) if m == m_mutbl =>
expr_vstore(e, expr_vstore_mut_box), expr_vstore(e, expr_vstore_mut_box),
expr_vec(*) if m == m_imm => expr_vstore(e, expr_vstore_box), expr_vec(*) if m == m_imm => expr_vstore(e, expr_vstore_box),
expr_lit(@ast::spanned { expr_lit(@codemap::spanned {
node: lit_str(_), span: _}) if m == m_imm => node: lit_str(_), span: _}) if m == m_imm =>
expr_vstore(e, expr_vstore_box), expr_vstore(e, expr_vstore_box),
_ => expr_unary(box(m), e) _ => expr_unary(box(m), e)
@ -1442,7 +1445,7 @@ pub impl Parser {
hi = e.span.hi; hi = e.span.hi;
// HACK: turn ~[...] into a ~-evec // HACK: turn ~[...] into a ~-evec
ex = match e.node { ex = match e.node {
expr_vec(*) | expr_lit(@ast::spanned { expr_vec(*) | expr_lit(@codemap::spanned {
node: lit_str(_), span: _}) node: lit_str(_), span: _})
if m == m_imm => expr_vstore(e, expr_vstore_uniq), if m == m_imm => expr_vstore(e, expr_vstore_uniq),
_ => expr_unary(uniq(m), e) _ => expr_unary(uniq(m), e)
@ -1453,11 +1456,12 @@ pub impl Parser {
return self.mk_expr(lo, hi, ex); return self.mk_expr(lo, hi, ex);
} }
// parse an expression of binops
fn parse_binops() -> @expr { fn parse_binops() -> @expr {
return self.parse_more_binops(self.parse_prefix_expr(), 0); self.parse_more_binops(self.parse_prefix_expr(), 0)
} }
// parse an expression of binops of at least min_prec precedence
fn parse_more_binops(lhs: @expr, min_prec: uint) -> fn parse_more_binops(lhs: @expr, min_prec: uint) ->
@expr { @expr {
if self.expr_is_complete(lhs) { return lhs; } if self.expr_is_complete(lhs) { return lhs; }
@ -1465,65 +1469,73 @@ pub impl Parser {
if peeked == token::BINOP(token::OR) && if peeked == token::BINOP(token::OR) &&
(self.restriction == RESTRICT_NO_BAR_OP || (self.restriction == RESTRICT_NO_BAR_OP ||
self.restriction == RESTRICT_NO_BAR_OR_DOUBLEBAR_OP) { self.restriction == RESTRICT_NO_BAR_OR_DOUBLEBAR_OP) {
return lhs; lhs
} } else if peeked == token::OROR &&
if peeked == token::OROR &&
self.restriction == RESTRICT_NO_BAR_OR_DOUBLEBAR_OP { self.restriction == RESTRICT_NO_BAR_OR_DOUBLEBAR_OP {
return lhs; lhs
} } else {
let cur_opt = token_to_binop(peeked); let cur_opt = token_to_binop(peeked);
match cur_opt { match cur_opt {
Some(cur_op) => { Some(cur_op) => {
let cur_prec = operator_prec(cur_op); let cur_prec = operator_prec(cur_op);
if cur_prec > min_prec { if cur_prec > min_prec {
self.bump(); self.bump();
let expr = self.parse_prefix_expr(); let expr = self.parse_prefix_expr();
let rhs = self.parse_more_binops(expr, cur_prec); let rhs = self.parse_more_binops(expr, cur_prec);
self.get_id(); // see ast_util::op_expr_callee_id self.get_id(); // see ast_util::op_expr_callee_id
let bin = self.mk_expr(lhs.span.lo, rhs.span.hi, let bin = self.mk_expr(lhs.span.lo, rhs.span.hi,
expr_binary(cur_op, lhs, rhs)); expr_binary(cur_op, lhs, rhs));
return self.parse_more_binops(bin, min_prec); self.parse_more_binops(bin, min_prec)
} else {
lhs
}
}
None => {
if as_prec > min_prec && self.eat_keyword(~"as") {
let rhs = self.parse_ty(true);
let _as = self.mk_expr(lhs.span.lo,
rhs.span.hi,
expr_cast(lhs, rhs));
self.parse_more_binops(_as, min_prec)
} else {
lhs
}
}
} }
}
_ => ()
} }
if as_prec > min_prec && self.eat_keyword(~"as") {
let rhs = self.parse_ty(true);
let _as =
self.mk_expr(lhs.span.lo, rhs.span.hi, expr_cast(lhs, rhs));
return self.parse_more_binops(_as, min_prec);
}
return lhs;
} }
// parse an assignment expression....
// actually, this seems to be the main entry point for
// parsing an arbitrary expression.
fn parse_assign_expr() -> @expr { fn parse_assign_expr() -> @expr {
let lo = self.span.lo; let lo = self.span.lo;
let lhs = self.parse_binops(); let lhs = self.parse_binops();
match copy self.token { match copy self.token {
token::EQ => { token::EQ => {
self.bump(); self.bump();
let rhs = self.parse_expr(); let rhs = self.parse_expr();
return self.mk_expr(lo, rhs.span.hi, expr_assign(lhs, rhs)); self.mk_expr(lo, rhs.span.hi, expr_assign(lhs, rhs))
} }
token::BINOPEQ(op) => { token::BINOPEQ(op) => {
self.bump(); self.bump();
let rhs = self.parse_expr(); let rhs = self.parse_expr();
let mut aop; let mut aop;
match op { match op {
token::PLUS => aop = add, token::PLUS => aop = add,
token::MINUS => aop = subtract, token::MINUS => aop = subtract,
token::STAR => aop = mul, token::STAR => aop = mul,
token::SLASH => aop = div, token::SLASH => aop = div,
token::PERCENT => aop = rem, token::PERCENT => aop = rem,
token::CARET => aop = bitxor, token::CARET => aop = bitxor,
token::AND => aop = bitand, token::AND => aop = bitand,
token::OR => aop = bitor, token::OR => aop = bitor,
token::SHL => aop = shl, token::SHL => aop = shl,
token::SHR => aop = shr token::SHR => aop = shr
} }
self.get_id(); // see ast_util::op_expr_callee_id self.get_id(); // see ast_util::op_expr_callee_id
return self.mk_expr(lo, rhs.span.hi, self.mk_expr(lo, rhs.span.hi,
expr_assign_op(aop, lhs, rhs)); expr_assign_op(aop, lhs, rhs))
} }
token::LARROW => { token::LARROW => {
self.obsolete(copy self.span, ObsoleteBinaryMove); self.obsolete(copy self.span, ObsoleteBinaryMove);
@ -1531,17 +1543,18 @@ pub impl Parser {
self.bump(); // <- self.bump(); // <-
self.bump(); // rhs self.bump(); // rhs
self.bump(); // ; self.bump(); // ;
return self.mk_expr(lo, self.span.hi, self.mk_expr(lo, self.span.hi,
expr_break(None)); expr_break(None))
} }
token::DARROW => { token::DARROW => {
self.bump(); self.bump();
let rhs = self.parse_expr(); let rhs = self.parse_expr();
return self.mk_expr(lo, rhs.span.hi, expr_swap(lhs, rhs)); self.mk_expr(lo, rhs.span.hi, expr_swap(lhs, rhs))
}
_ => {
lhs
} }
_ => {/* fall through */ }
} }
return lhs;
} }
fn parse_if_expr() -> @expr { fn parse_if_expr() -> @expr {
@ -1556,7 +1569,7 @@ pub impl Parser {
hi = elexpr.span.hi; hi = elexpr.span.hi;
} }
let q = {cond: cond, then: thn, els: els, lo: lo, hi: hi}; let q = {cond: cond, then: thn, els: els, lo: lo, hi: hi};
return self.mk_expr(q.lo, q.hi, expr_if(q.cond, q.then, q.els)); self.mk_expr(q.lo, q.hi, expr_if(q.cond, q.then, q.els))
} }
fn parse_fn_expr(proto: Proto) -> @expr { fn parse_fn_expr(proto: Proto) -> @expr {
@ -1567,8 +1580,9 @@ pub impl Parser {
let decl = self.parse_fn_decl(|p| p.parse_arg_or_capture_item()); let decl = self.parse_fn_decl(|p| p.parse_arg_or_capture_item());
let body = self.parse_block(); let body = self.parse_block();
return self.mk_expr(lo, body.span.hi,
expr_fn(proto, decl, body, @())); self.mk_expr(lo, body.span.hi,
expr_fn(proto, decl, body, @()))
} }
// `|args| { ... }` like in `do` expressions // `|args| { ... }` like in `do` expressions
@ -1794,7 +1808,7 @@ pub impl Parser {
self.eat(token::COMMA); self.eat(token::COMMA);
} }
let blk = ast::spanned { let blk = codemap::spanned {
node: ast::blk_ { node: ast::blk_ {
view_items: ~[], view_items: ~[],
stmts: ~[], stmts: ~[],
@ -1812,10 +1826,12 @@ pub impl Parser {
return self.mk_expr(lo, hi, expr_match(discriminant, arms)); return self.mk_expr(lo, hi, expr_match(discriminant, arms));
} }
// parse an expression
fn parse_expr() -> @expr { fn parse_expr() -> @expr {
return self.parse_expr_res(UNRESTRICTED); return self.parse_expr_res(UNRESTRICTED);
} }
// parse an expression, subject to the given restriction
fn parse_expr_res(r: restriction) -> @expr { fn parse_expr_res(r: restriction) -> @expr {
let old = self.restriction; let old = self.restriction;
self.restriction = r; self.restriction = r;
@ -1943,7 +1959,9 @@ pub impl Parser {
// HACK: parse @"..." as a literal of a vstore @str // HACK: parse @"..." as a literal of a vstore @str
pat = match sub.node { pat = match sub.node {
pat_lit(e@@expr { pat_lit(e@@expr {
node: expr_lit(@ast::spanned {node: lit_str(_), span: _}), _ node: expr_lit(@codemap::spanned {
node: lit_str(_),
span: _}), _
}) => { }) => {
let vst = @expr { let vst = @expr {
id: self.get_id(), id: self.get_id(),
@ -1963,7 +1981,9 @@ pub impl Parser {
// HACK: parse ~"..." as a literal of a vstore ~str // HACK: parse ~"..." as a literal of a vstore ~str
pat = match sub.node { pat = match sub.node {
pat_lit(e@@expr { pat_lit(e@@expr {
node: expr_lit(@ast::spanned {node: lit_str(_), span: _}), _ node: expr_lit(@codemap::spanned {
node: lit_str(_),
span: _}), _
}) => { }) => {
let vst = @expr { let vst = @expr {
id: self.get_id(), id: self.get_id(),
@ -1985,7 +2005,7 @@ pub impl Parser {
// HACK: parse &"..." as a literal of a borrowed str // HACK: parse &"..." as a literal of a borrowed str
pat = match sub.node { pat = match sub.node {
pat_lit(e@@expr { pat_lit(e@@expr {
node: expr_lit(@ast::spanned { node: expr_lit(@codemap::spanned {
node: lit_str(_), span: _}), _ node: lit_str(_), span: _}), _
}) => { }) => {
let vst = @expr { let vst = @expr {
@ -2011,7 +2031,9 @@ pub impl Parser {
if self.token == token::RPAREN { if self.token == token::RPAREN {
hi = self.span.hi; hi = self.span.hi;
self.bump(); self.bump();
let lit = @ast::spanned {node: lit_nil, span: mk_sp(lo, hi)}; let lit = @codemap::spanned {
node: lit_nil,
span: mk_sp(lo, hi)};
let expr = self.mk_expr(lo, hi, expr_lit(lit)); let expr = self.mk_expr(lo, hi, expr_lit(lit));
pat = pat_lit(expr); pat = pat_lit(expr);
} else { } else {
@ -2381,7 +2403,7 @@ pub impl Parser {
match self.token { match self.token {
token::SEMI => { token::SEMI => {
self.bump(); self.bump();
stmts.push(@ast::spanned { stmts.push(@codemap::spanned {
node: stmt_semi(e, stmt_id), node: stmt_semi(e, stmt_id),
.. *stmt}); .. *stmt});
} }
@ -2406,7 +2428,7 @@ pub impl Parser {
match self.token { match self.token {
token::SEMI => { token::SEMI => {
self.bump(); self.bump();
stmts.push(@ast::spanned { stmts.push(@codemap::spanned {
node: stmt_mac((*m), true), node: stmt_mac((*m), true),
.. *stmt}); .. *stmt});
} }
@ -2940,7 +2962,7 @@ pub impl Parser {
let actual_dtor = do the_dtor.map |dtor| { let actual_dtor = do the_dtor.map |dtor| {
let (d_body, d_attrs, d_s) = *dtor; let (d_body, d_attrs, d_s) = *dtor;
ast::spanned { node: ast::struct_dtor_ { id: self.get_id(), codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(),
attrs: d_attrs, attrs: d_attrs,
self_id: self.get_id(), self_id: self.get_id(),
body: d_body}, body: d_body},
@ -3445,7 +3467,7 @@ pub impl Parser {
self.bump(); self.bump();
let mut actual_dtor = do the_dtor.map |dtor| { let mut actual_dtor = do the_dtor.map |dtor| {
let (d_body, d_attrs, d_s) = *dtor; let (d_body, d_attrs, d_s) = *dtor;
ast::spanned { node: ast::struct_dtor_ { id: self.get_id(), codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(),
attrs: d_attrs, attrs: d_attrs,
self_id: self.get_id(), self_id: self.get_id(),
body: d_body }, body: d_body },
@ -3737,7 +3759,7 @@ pub impl Parser {
_ => self.fatal(~"expected open delimiter") _ => self.fatal(~"expected open delimiter")
}; };
let m = ast::mac_invoc_tt(pth, tts); let m = ast::mac_invoc_tt(pth, tts);
let m: ast::mac = ast::spanned { node: m, let m: ast::mac = codemap::spanned { node: m,
span: mk_sp(self.span.lo, span: mk_sp(self.span.lo,
self.span.hi) }; self.span.hi) };
let item_ = item_mac(m); let item_ = item_mac(m);

View File

@ -575,7 +575,7 @@ pub fn print_item(s: ps, &&item: @ast::item) {
} }
bclose(s, item.span); bclose(s, item.span);
} }
ast::item_mac(ast::spanned { node: ast::mac_invoc_tt(pth, ref tts), ast::item_mac(codemap::spanned { node: ast::mac_invoc_tt(pth, ref tts),
_}) => { _}) => {
print_visibility(s, item.vis); print_visibility(s, item.vis);
print_path(s, pth, false); print_path(s, pth, false);
@ -2241,6 +2241,7 @@ pub mod test {
use parse; use parse;
use super::*; use super::*;
//use util; //use util;
use util::testing::check_equal;
fn string_check<T : Eq> (given : &T, expected: &T) { fn string_check<T : Eq> (given : &T, expected: &T) {
if !(given == expected) { if !(given == expected) {
@ -2257,11 +2258,11 @@ pub mod test {
inputs: ~[], inputs: ~[],
output: @ast::Ty {id: 0, output: @ast::Ty {id: 0,
node: ast::ty_nil, node: ast::ty_nil,
span: ast_util::dummy_sp()}, span: codemap::dummy_sp()},
cf: ast::return_val cf: ast::return_val
}; };
assert fun_to_str(decl, abba_ident, ~[],mock_interner) check_equal (&fun_to_str(decl, abba_ident, ~[],mock_interner),
== ~"fn abba()"; &~"fn abba()");
} }
#[test] #[test]
@ -2269,7 +2270,7 @@ pub mod test {
let mock_interner = parse::token::mk_fake_ident_interner(); let mock_interner = parse::token::mk_fake_ident_interner();
let ident = mock_interner.intern(@~"principal_skinner"); let ident = mock_interner.intern(@~"principal_skinner");
let var = ast_util::respan(ast_util::dummy_sp(), ast::variant_ { let var = codemap::respan(codemap::dummy_sp(), ast::variant_ {
name: ident, name: ident,
attrs: ~[], attrs: ~[],
// making this up as I go.... ? // making this up as I go.... ?
@ -2280,7 +2281,7 @@ pub mod test {
}); });
let varstr = variant_to_str(var,mock_interner); let varstr = variant_to_str(var,mock_interner);
string_check(&varstr,&~"pub principal_skinner"); check_equal(&varstr,&~"pub principal_skinner");
} }
} }

View File

@ -46,10 +46,11 @@ pub mod ast_map;
pub mod visit; pub mod visit;
pub mod fold; pub mod fold;
pub mod util { pub mod util {
#[path = "interner.rs"]
pub mod interner; pub mod interner;
pub mod testing;
} }
#[path = "parse/mod.rs"] #[path = "parse/mod.rs"]
pub mod parse; pub mod parse;
@ -86,3 +87,4 @@ pub mod ext {
pub mod trace_macros; pub mod trace_macros;
} }

View File

@ -0,0 +1,24 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// support for test cases.
use core::cmp;
pub pure fn check_equal_ptr<T : cmp::Eq> (given : &T, expected: &T) {
if !((given == expected) && (expected == given )) {
fail (fmt!("given %?, expected %?",given,expected));
}
}
pub pure fn check_equal<T : cmp::Eq> (given : T, expected: T) {
if !((given == expected) && (expected == given )) {
fail (fmt!("given %?, expected %?",given,expected));
}
}