about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-11-12 19:32:48 -0800
committerBrian Anderson <banderson@mozilla.com>2012-11-14 15:18:29 -0800
commitf67bfe97389a256fc95216c29a2b8a066ee16a2c (patch)
treea638c4c480ceb60138a39a05c5b04967ac814eb6 /src/libsyntax/ext
parent9ecf86343a136c71cbb2bb8da9bfd1734fec37f4 (diff)
downloadrust-f67bfe97389a256fc95216c29a2b8a066ee16a2c.tar.gz
rust-f67bfe97389a256fc95216c29a2b8a066ee16a2c.zip
Add types for character position and byte position in the codemap
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/base.rs4
-rw-r--r--src/libsyntax/ext/pipes/ast_builder.rs55
-rw-r--r--src/libsyntax/ext/pipes/check.rs1
-rw-r--r--src/libsyntax/ext/pipes/liveness.rs2
-rw-r--r--src/libsyntax/ext/pipes/pipec.rs13
-rw-r--r--src/libsyntax/ext/qquote.rs18
-rw-r--r--src/libsyntax/ext/source_util.rs2
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs5
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs2
9 files changed, 48 insertions, 54 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index ad33e99ff04..66ef3bec2a7 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -178,7 +178,9 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
         }
         fn bt_pop() {
             match self.backtrace {
-              Some(@ExpandedFrom({call_site: span {expn_info: prev, _}, _})) => {
+              Some(@ExpandedFrom({
+                  call_site: span {expn_info: prev, _}, _
+              })) => {
                 self.backtrace = prev
               }
               _ => self.bug(~"tried to pop without a push")
diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs
index 3d63b0ddb77..652ad5533c4 100644
--- a/src/libsyntax/ext/pipes/ast_builder.rs
+++ b/src/libsyntax/ext/pipes/ast_builder.rs
@@ -4,7 +4,7 @@
 // something smarter.
 
 use ast::{ident, node_id};
-use ast_util::{ident_to_path, respan};
+use ast_util::{ident_to_path, respan, dummy_sp};
 use codemap::span;
 use ext::base::mk_ctxt;
 
@@ -23,10 +23,6 @@ fn path(ids: ~[ident], span: span) -> @ast::path {
       types: ~[]}
 }
 
-fn empty_span() -> span {
-    span {lo: 0, hi: 0, expn_info: None}
-}
-
 trait append_types {
     fn add_ty(ty: @ast::Ty) -> @ast::path;
     fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path;
@@ -83,26 +79,21 @@ trait ext_ctxt_ast_builder {
     fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
     fn stmt_expr(e: @ast::expr) -> @ast::stmt;
     fn block_expr(b: ast::blk) -> @ast::expr;
-    fn empty_span() -> span;
     fn ty_option(ty: @ast::Ty) -> @ast::Ty;
 }
 
 impl ext_ctxt: ext_ctxt_ast_builder {
     fn ty_option(ty: @ast::Ty) -> @ast::Ty {
         self.ty_path_ast_builder(path(~[self.ident_of(~"Option")],
-                                      self.empty_span())
+                                      dummy_sp())
                                  .add_ty(ty))
     }
 
-    fn empty_span() -> span {
-        span {lo: 0, hi: 0, expn_info: self.backtrace()}
-    }
-
     fn block_expr(b: ast::blk) -> @ast::expr {
         @{id: self.next_id(),
           callee_id: self.next_id(),
           node: ast::expr_block(b),
-          span: self.empty_span()}
+          span: dummy_sp()}
     }
 
     fn move_expr(e: @ast::expr) -> @ast::expr {
@@ -114,7 +105,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
 
     fn stmt_expr(e: @ast::expr) -> @ast::stmt {
         @{node: ast::stmt_expr(e, self.next_id()),
-          span: self.empty_span()}
+          span: dummy_sp()}
     }
 
     fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt {
@@ -130,43 +121,43 @@ impl ext_ctxt: ext_ctxt_ast_builder {
                      pat: @{id: self.next_id(),
                             node: ast::pat_ident(ast::bind_by_implicit_ref,
                                                  path(~[ident],
-                                                      self.empty_span()),
+                                                      dummy_sp()),
                                                  None),
-                            span: self.empty_span()},
+                            span: dummy_sp()},
                      init: Some(self.move_expr(e)),
                      id: self.next_id()},
-              span: self.empty_span()}]),
-                               span: self.empty_span()}, self.next_id()),
-         span: self.empty_span()}
+              span: dummy_sp()}]),
+                               span: dummy_sp()}, self.next_id()),
+         span: dummy_sp()}
     }
 
     fn field_imm(name: ident, e: @ast::expr) -> ast::field {
         {node: {mutbl: ast::m_imm, ident: name, expr: e},
-         span: self.empty_span()}
+         span: dummy_sp()}
     }
 
     fn rec(+fields: ~[ast::field]) -> @ast::expr {
         @{id: self.next_id(),
           callee_id: self.next_id(),
           node: ast::expr_rec(fields, None),
-          span: self.empty_span()}
+          span: dummy_sp()}
     }
 
     fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
         {node: {ident: name, mt: { ty: ty, mutbl: ast::m_imm } },
-          span: self.empty_span()}
+          span: dummy_sp()}
     }
 
     fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
         @{id: self.next_id(),
           node: ast::ty_rec(fields),
-          span: self.empty_span()}
+          span: dummy_sp()}
     }
 
     fn ty_infer() -> @ast::Ty {
         @{id: self.next_id(),
           node: ast::ty_infer,
-          span: self.empty_span()}
+          span: dummy_sp()}
     }
 
     fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
@@ -181,9 +172,9 @@ impl ext_ctxt: ext_ctxt_ast_builder {
          pat: @{id: self.next_id(),
                 node: ast::pat_ident(
                     ast::bind_by_value,
-                    ast_util::ident_to_path(self.empty_span(), name),
+                    ast_util::ident_to_path(dummy_sp(), name),
                     None),
-                span: self.empty_span()},
+                span: dummy_sp()},
          id: self.next_id()}
     }
 
@@ -195,7 +186,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
                    rules: ast::default_blk};
 
         {node: blk,
-         span: self.empty_span()}
+         span: dummy_sp()}
     }
 
     fn expr_block(e: @ast::expr) -> ast::blk {
@@ -215,11 +206,11 @@ impl ext_ctxt: ext_ctxt_ast_builder {
 
         // XXX: Would be nice if our generated code didn't violate
         // Rust coding conventions
-        let non_camel_case_attribute = respan(self.empty_span(), {
+        let non_camel_case_attribute = respan(dummy_sp(), {
             style: ast::attr_outer,
-            value: respan(self.empty_span(),
+            value: respan(dummy_sp(),
                           ast::meta_list(~"allow", ~[
-                              @respan(self.empty_span(),
+                              @respan(dummy_sp(),
                                       ast::meta_word(~"non_camel_case_types"))
                           ])),
             is_sugared_doc: false
@@ -239,7 +230,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
                     +ty_params: ~[ast::ty_param],
                     +body: ast::blk) -> @ast::item {
         self.item(name,
-                  self.empty_span(),
+                  dummy_sp(),
                   ast::item_fn(self.fn_decl(inputs, output),
                                ast::impure_fn,
                                ty_params,
@@ -298,7 +289,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
     fn ty_nil_ast_builder() -> @ast::Ty {
         @{id: self.next_id(),
           node: ast::ty_nil,
-          span: self.empty_span()}
+          span: dummy_sp()}
     }
 
     fn item_ty_poly(name: ident,
@@ -314,6 +305,6 @@ impl ext_ctxt: ext_ctxt_ast_builder {
 
     fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
         ty_params.map(|p| self.ty_path_ast_builder(
-            path(~[p.ident], self.empty_span())))
+            path(~[p.ident], dummy_sp())))
     }
 }
diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs
index fcc0c84a4ff..a90b679f697 100644
--- a/src/libsyntax/ext/pipes/check.rs
+++ b/src/libsyntax/ext/pipes/check.rs
@@ -22,7 +22,6 @@ that.
 use ext::base::ext_ctxt;
 
 use proto::{state, protocol, next_state};
-use ast_builder::empty_span;
 
 impl ext_ctxt: proto::visitor<(), (), ()>  {
     fn visit_proto(_proto: protocol,
diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs
index a9bfd87ab0e..e86b3f0ea59 100644
--- a/src/libsyntax/ext/pipes/liveness.rs
+++ b/src/libsyntax/ext/pipes/liveness.rs
@@ -29,8 +29,6 @@ updating the states using rule (2) until there are no changes.
 
 use std::bitv::{Bitv};
 
-use ast_builder::empty_span;
-
 fn analyze(proto: protocol, _cx: ext_ctxt) {
     debug!("initializing colive analysis");
     let num_states = proto.num_states();
diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs
index 7e1cbe9ad0d..d03a0fde66c 100644
--- a/src/libsyntax/ext/pipes/pipec.rs
+++ b/src/libsyntax/ext/pipes/pipec.rs
@@ -5,6 +5,7 @@ use to_str::ToStr;
 use dvec::DVec;
 
 use ast::ident;
+use ast_util::dummy_sp;
 use util::interner;
 use print::pprust;
 use pprust::{item_to_str, ty_to_str};
@@ -12,7 +13,7 @@ use ext::base::{mk_ctxt, ext_ctxt};
 use parse::*;
 use proto::*;
 
-use ast_builder::{append_types, path, empty_span};
+use ast_builder::{append_types, path};
 
 // Transitional reexports so qquote can find the paths it is looking for
 mod syntax {
@@ -256,11 +257,11 @@ impl state: to_type_decls {
                     cx.ty_path_ast_builder(
                         path(~[cx.ident_of(~"pipes"),
                                cx.ident_of(dir.to_str() + ~"Packet")],
-                             empty_span())
+                             dummy_sp())
                         .add_ty(cx.ty_path_ast_builder(
                             path(~[cx.ident_of(self.proto.name),
                                    self.data_name()],
-                                 empty_span())
+                                 dummy_sp())
                             .add_tys(cx.ty_vars(self.ty_params))))),
                     self.ty_params));
         }
@@ -273,11 +274,11 @@ impl state: to_type_decls {
                         path(~[cx.ident_of(~"pipes"),
                                cx.ident_of(dir.to_str()
                                            + ~"PacketBuffered")],
-                             empty_span())
+                             dummy_sp())
                         .add_tys(~[cx.ty_path_ast_builder(
                             path(~[cx.ident_of(self.proto.name),
                                    self.data_name()],
-                                 empty_span())
+                                 dummy_sp())
                             .add_tys(cx.ty_vars(self.ty_params))),
                                    self.proto.buffer_ty_path(cx)])),
                     self.ty_params));
@@ -394,7 +395,7 @@ impl protocol: gen_init {
 
         cx.item_ty_poly(
             cx.ident_of(~"__Buffer"),
-            cx.empty_span(),
+            dummy_sp(),
             cx.ty_rec(fields),
             params)
     }
diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs
index 1d17b09329c..50d1e0033e2 100644
--- a/src/libsyntax/ext/qquote.rs
+++ b/src/libsyntax/ext/qquote.rs
@@ -4,6 +4,7 @@ use parse::parser;
 use parse::parser::{Parser, parse_from_source_str};
 use dvec::DVec;
 use parse::token::ident_interner;
+use codemap::CharPos;
 
 use fold::*;
 use visit::*;
@@ -15,13 +16,13 @@ use io::*;
 use codemap::span;
 
 struct gather_item {
-    lo: uint,
-    hi: uint,
+    lo: CharPos,
+    hi: CharPos,
     e: @ast::expr,
     constr: ~str
 }
 
-type aq_ctxt = @{lo: uint, gather: DVec<gather_item>};
+type aq_ctxt = @{lo: CharPos, gather: DVec<gather_item>};
 enum fragment {
     from_expr(@ast::expr),
     from_ty(@ast::Ty)
@@ -114,7 +115,7 @@ impl @ast::pat: qq_helper {
     fn get_fold_fn() -> ~str {~"fold_pat"}
 }
 
-fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
+fn gather_anti_quotes<N: qq_helper>(lo: CharPos, node: N) -> aq_ctxt
 {
     let v = @{visit_expr: |node, &&cx, v| visit_aq(node, ~"from_expr", cx, v),
               visit_ty: |node, &&cx, v| visit_aq(node, ~"from_ty", cx, v),
@@ -226,7 +227,8 @@ fn finish<T: qq_helper>
     let mut str2 = ~"";
     enum state {active, skip(uint), blank};
     let mut state = active;
-    let mut i = 0u, j = 0u;
+    let mut i = CharPos(0u);
+    let mut j = 0u;
     let g_len = cx.gather.len();
     for str::chars_each(*str) |ch| {
         if (j < g_len && i == cx.gather[j].lo) {
@@ -242,7 +244,7 @@ fn finish<T: qq_helper>
           blank if is_space(ch) => str::push_char(&mut str2, ch),
           blank => str::push_char(&mut str2, ' ')
         }
-        i += 1u;
+        i += CharPos(1u);
         if (j < g_len && i == cx.gather[j].hi) {
             assert ch == ')';
             state = active;
@@ -270,7 +272,7 @@ fn finish<T: qq_helper>
                                  ~"qquote", ~"mk_file_substr"]),
                                 ~[mk_uniq_str(cx,sp, loc.file.name),
                                  mk_uint(cx,sp, loc.line),
-                                 mk_uint(cx,sp, loc.col)]),
+                                 mk_uint(cx,sp, loc.col.to_uint())]),
                         mk_unary(cx,sp, ast::box(ast::m_imm),
                                  mk_uniq_str(cx,sp, str2)),
                         cfg_call(),
@@ -346,7 +348,7 @@ fn replace_ty(repls: ~[fragment],
 
 fn mk_file_substr(fname: ~str, line: uint, col: uint) ->
     codemap::FileSubstr {
-    codemap::FssExternal({filename: fname, line: line, col: col})
+    codemap::FssExternal({filename: fname, line: line, col: CharPos(col)})
 }
 
 // Local Variables:
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs
index 3e4f24dff02..3fed340904a 100644
--- a/src/libsyntax/ext/source_util.rs
+++ b/src/libsyntax/ext/source_util.rs
@@ -25,7 +25,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
               _body: ast::mac_body) -> @ast::expr {
     get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"col");
     let loc = cx.codemap().lookup_char_pos(sp.lo);
-    return mk_uint(cx, sp, loc.col);
+    return mk_uint(cx, sp, loc.col.to_uint());
 }
 
 /* file!(): expands to the current filename */
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index 76814a688f5..2f371e1f8c5 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -11,6 +11,7 @@ use dvec::DVec;
 use ast::{matcher, match_tok, match_seq, match_nonterminal, ident};
 use ast_util::mk_sp;
 use std::map::HashMap;
+use codemap::CharPos;
 
 /* This is an Earley-like parser, without support for in-grammar nonterminals,
 only by calling out to the main rust parser for named nonterminals (which it
@@ -102,7 +103,7 @@ type matcher_pos = ~{
     mut up: matcher_pos_up, // mutable for swapping only
     matches: ~[DVec<@named_match>],
     match_lo: uint, match_hi: uint,
-    sp_lo: uint,
+    sp_lo: CharPos,
 };
 
 fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
@@ -122,7 +123,7 @@ fn count_names(ms: &[matcher]) -> uint {
 }
 
 #[allow(non_implicitly_copyable_typarams)]
-fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: uint)
+fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: CharPos)
     -> matcher_pos {
     let mut match_idx_hi = 0u;
     for ms.each() |elt| {
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index 238f9db6ac5..78f0e4fc8f8 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -53,7 +53,7 @@ fn new_tt_reader(sp_diag: span_handler, itr: @ident_interner,
               mut repeat_len: ~[],
               /* dummy values, never read: */
               mut cur_tok: EOF,
-              mut cur_span: ast_util::mk_sp(0u,0u)
+              mut cur_span: ast_util::dummy_sp()
              };
     tt_next_token(r); /* get cur_tok and cur_span set up */
     return r;