# impl Shape for int { }
# let mycircle = 0;
-let myshape: Shape = @mycircle as @Shape;
+let myshape: @Shape = @mycircle as @Shape;
~~~~
The resulting value is a managed box containing the value that was cast,
use libc;
use libc::{c_void, size_t, c_int};
use ptr;
+use rand::RngUtil;
use vec;
#[cfg(test)] use rand;
use hash::Hash;
use iter;
use option::{None, Option, Some};
+ use rand::RngUtil;
use rand;
use uint;
use vec;
pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
- -> Result<Writer, ~str> {
-
+ -> Result<@Writer, ~str> {
#[cfg(windows)]
fn wb() -> c_int {
(O_WRONLY | libc::consts::os::extra::O_BINARY) as c_int
}
#[allow(non_implicitly_copyable_typarams)]
-pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<Writer, ~str> {
+pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> {
mk_file_writer(path, flags).chain(|w| result::Ok(w))
}
// FIXME: fileflags // #2004
-pub fn buffered_file_writer(path: &Path) -> Result<Writer, ~str> {
+pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
unsafe {
let f = do os::as_c_charp(path.to_str()) |pathbuf| {
do os::as_c_charp("w") |modebuf| {
libc::fopen(pathbuf, modebuf)
}
};
- return if f as uint == 0u { result::Err(~"error opening "
- + path.to_str()) }
- else { result::Ok(FILE_writer(f, true)) }
+ return if f as uint == 0u {
+ result::Err(~"error opening " + path.to_str())
+ } else {
+ result::Ok(FILE_writer(f, true))
+ }
}
}
BytesWriter { bytes: ~[], mut pos: 0u }
}
-pub pure fn with_bytes_writer(f: &fn(Writer)) -> ~[u8] {
+pub pure fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
let wr = @BytesWriter();
- f(wr as Writer);
+ f(wr as @Writer);
let @BytesWriter{bytes, _} = wr;
return bytes;
}
-pub pure fn with_str_writer(f: &fn(Writer)) -> ~str {
+pub pure fn with_str_writer(f: &fn(@Writer)) -> ~str {
let mut v = with_bytes_writer(f);
// FIXME (#3758): This should not be needed.
pub trait FSyncable { fn fsync(&self, l: Level) -> int; }
// Call o.fsync after executing blk
- pub fn obj_sync(o: FSyncable, opt_level: Option<Level>,
- blk: &fn(v: Res<FSyncable>)) {
+ pub fn obj_sync(o: @FSyncable, opt_level: Option<Level>,
+ blk: &fn(v: Res<@FSyncable>)) {
blk(Res(Arg {
val: o, opt_level: opt_level,
fsync_fn: |o, l| o.fsync(l)
~"A hoopy frood who really knows where his towel is.";
debug!(copy frood);
{
- let out: io::Writer =
+ let out: @io::Writer =
result::get(
&io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
out.write_str(frood);
}
- let inp: io::Reader = result::get(&io::file_reader(tmpfile));
+ let inp: @io::Reader = result::get(&io::file_reader(tmpfile));
let frood2: ~str = inp.read_c_str();
debug!(copy frood2);
fail_unless!(frood == frood2);
use os::{remove_file, setenv};
use os;
use path::Path;
+ use rand::RngUtil;
use rand;
use run;
use str;
}
fn make_rand_name() -> ~str {
- let rng: rand::Rng = rand::Rng();
+ let rng: @rand::Rng = rand::Rng();
let n = ~"TEST" + rng.gen_str(10u);
fail_unless!(getenv(n).is_none());
n
/// A type that can be randomly generated using an RNG
pub trait Rand {
- static fn rand(rng: rand::Rng) -> Self;
+ static fn rand(rng: @rand::Rng) -> Self;
}
impl Rand for int {
- static fn rand(rng: rand::Rng) -> int {
+ static fn rand(rng: @rand::Rng) -> int {
rng.gen_int()
}
}
impl Rand for i8 {
- static fn rand(rng: rand::Rng) -> i8 {
+ static fn rand(rng: @rand::Rng) -> i8 {
rng.gen_i8()
}
}
impl Rand for i16 {
- static fn rand(rng: rand::Rng) -> i16 {
+ static fn rand(rng: @rand::Rng) -> i16 {
rng.gen_i16()
}
}
impl Rand for i32 {
- static fn rand(rng: rand::Rng) -> i32 {
+ static fn rand(rng: @rand::Rng) -> i32 {
rng.gen_i32()
}
}
impl Rand for i64 {
- static fn rand(rng: rand::Rng) -> i64 {
+ static fn rand(rng: @rand::Rng) -> i64 {
rng.gen_i64()
}
}
impl Rand for u8 {
- static fn rand(rng: rand::Rng) -> u8 {
+ static fn rand(rng: @rand::Rng) -> u8 {
rng.gen_u8()
}
}
impl Rand for u16 {
- static fn rand(rng: rand::Rng) -> u16 {
+ static fn rand(rng: @rand::Rng) -> u16 {
rng.gen_u16()
}
}
impl Rand for u32 {
- static fn rand(rng: rand::Rng) -> u32 {
+ static fn rand(rng: @rand::Rng) -> u32 {
rng.gen_u32()
}
}
impl Rand for u64 {
- static fn rand(rng: rand::Rng) -> u64 {
+ static fn rand(rng: @rand::Rng) -> u64 {
rng.gen_u64()
}
}
impl Rand for float {
- static fn rand(rng: rand::Rng) -> float {
+ static fn rand(rng: @rand::Rng) -> float {
rng.gen_float()
}
}
impl Rand for f32 {
- static fn rand(rng: rand::Rng) -> f32 {
+ static fn rand(rng: @rand::Rng) -> f32 {
rng.gen_f32()
}
}
impl Rand for f64 {
- static fn rand(rng: rand::Rng) -> f64 {
+ static fn rand(rng: @rand::Rng) -> f64 {
rng.gen_f64()
}
}
impl Rand for char {
- static fn rand(rng: rand::Rng) -> char {
+ static fn rand(rng: @rand::Rng) -> char {
rng.gen_char()
}
}
impl Rand for bool {
- static fn rand(rng: rand::Rng) -> bool {
+ static fn rand(rng: @rand::Rng) -> bool {
rng.gen_bool()
}
}
impl<T:Rand> Rand for Option<T> {
- static fn rand(rng: rand::Rng) -> Option<T> {
- if rng.gen_bool() { Some(Rand::rand(rng)) }
- else { None }
+ static fn rand(rng: @rand::Rng) -> Option<T> {
+ if rng.gen_bool() {
+ Some(Rand::rand(rng))
+ } else {
+ None
+ }
}
}
item: T,
}
+pub trait RngUtil {
+ fn gen<T:Rand>(&self) -> T;
+ /// Return a random int
+ fn gen_int(&self) -> int;
+ fn gen_int_range(&self, start: int, end: int) -> int;
+ /// Return a random i8
+ fn gen_i8(&self) -> i8;
+ /// Return a random i16
+ fn gen_i16(&self) -> i16;
+ /// Return a random i32
+ fn gen_i32(&self) -> i32;
+ /// Return a random i64
+ fn gen_i64(&self) -> i64;
+ /// Return a random uint
+ fn gen_uint(&self) -> uint;
+ /**
+ * Return a uint randomly chosen from the range [start, end),
+ * failing if start >= end
+ */
+ fn gen_uint_range(&self, start: uint, end: uint) -> uint;
+ /// Return a random u8
+ fn gen_u8(&self) -> u8;
+ /// Return a random u16
+ fn gen_u16(&self) -> u16;
+ /// Return a random u32
+ fn gen_u32(&self) -> u32;
+ /// Return a random u64
+ fn gen_u64(&self) -> u64;
+ /// Return a random float in the interval [0,1]
+ fn gen_float(&self) -> float;
+ /// Return a random f32 in the interval [0,1]
+ fn gen_f32(&self) -> f32;
+ /// Return a random f64 in the interval [0,1]
+ fn gen_f64(&self) -> f64;
+ /// Return a random char
+ fn gen_char(&self) -> char;
+ /**
+ * Return a char randomly chosen from chars, failing if chars is empty
+ */
+ fn gen_char_from(&self, chars: &str) -> char;
+ /// Return a random bool
+ fn gen_bool(&self) -> bool;
+ /// Return a bool with a 1 in n chance of true
+ fn gen_weighted_bool(&self, n: uint) -> bool;
+ /**
+ * Return a random string of the specified length composed of A-Z,a-z,0-9
+ */
+ fn gen_str(&self, len: uint) -> ~str;
+ /// Return a random byte string of the specified length
+ fn gen_bytes(&self, len: uint) -> ~[u8];
+ /// Choose an item randomly, failing if values is empty
+ fn choose<T:Copy>(&self, values: &[T]) -> T;
+ /// Choose Some(item) randomly, returning None if values is empty
+ fn choose_option<T:Copy>(&self, values: &[T]) -> Option<T>;
+ /**
+ * Choose an item respecting the relative weights, failing if the sum of
+ * the weights is 0
+ */
+ fn choose_weighted<T:Copy>(&self, v : &[Weighted<T>]) -> T;
+ /**
+ * Choose Some(item) respecting the relative weights, returning none if
+ * the sum of the weights is 0
+ */
+ fn choose_weighted_option<T:Copy>(&self, v: &[Weighted<T>]) -> Option<T>;
+ /**
+ * Return a vec containing copies of the items, in order, where
+ * the weight of the item determines how many copies there are
+ */
+ fn weighted_vec<T:Copy>(&self, v: &[Weighted<T>]) -> ~[T];
+ /// Shuffle a vec
+ fn shuffle<T:Copy>(&self, values: &[T]) -> ~[T];
+ /// Shuffle a mutable vec in place
+ fn shuffle_mut<T>(&self, values: &mut [T]);
+}
+
/// Extension methods for random number generators
-pub impl Rng {
+impl RngUtil for @Rng {
/// Return a random value for a Rand type
fn gen<T:Rand>(&self) -> T {
Rand::rand(*self)
}
/// Create a random number generator with a system specified seed
-pub fn Rng() -> Rng {
+pub fn Rng() -> @Rng {
seeded_rng(seed())
}
}
}
-pub pure fn xorshift() -> Rng {
+pub pure fn xorshift() -> @Rng {
// constants taken from http://en.wikipedia.org/wiki/Xorshift
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
}
* seeded by the system. Intended to be used in method chaining style, ie
* task_rng().gen_int().
*/
-pub fn task_rng() -> Rng {
+pub fn task_rng() -> @Rng {
let r : Option<@RandRes>;
unsafe {
r = task::local_data::local_data_get(tls_rng_state);
fn write_escaped_char(&self, ch: char);
}
-impl EscapedCharWriter for Writer {
+impl EscapedCharWriter for @Writer {
fn write_escaped_char(&self, ch: char) {
match ch {
'\t' => self.write_str("\\t"),
fn get_id(&mut self) -> pid_t;
/// Returns an io::writer that can be used to write to stdin
- fn input(&mut self) -> io::Writer;
+ fn input(&mut self) -> @io::Writer;
/// Returns an io::reader that can be used to read from stdout
- fn output(&mut self) -> io::Reader;
+ fn output(&mut self) -> @io::Reader;
/// Returns an io::reader that can be used to read from stderr
- fn err(&mut self) -> io::Reader;
+ fn err(&mut self) -> @io::Reader;
/// Closes the handle to the child processes standard input
fn close_input(&mut self);
*
* A class with a <program> field
*/
-pub fn start_program(prog: &str, args: &[~str]) -> Program {
+pub fn start_program(prog: &str, args: &[~str]) -> @Program {
let pipe_input = os::pipe();
let pipe_output = os::pipe();
let pipe_err = os::pipe();
impl Program for ProgRes {
fn get_id(&mut self) -> pid_t { return self.r.pid; }
- fn input(&mut self) -> io::Writer {
+ fn input(&mut self) -> @io::Writer {
io::fd_writer(self.r.in_fd, false)
}
- fn output(&mut self) -> io::Reader {
+ fn output(&mut self) -> @io::Reader {
io::FILE_reader(self.r.out_file, false)
}
- fn err(&mut self) -> io::Reader {
+ fn err(&mut self) -> @io::Reader {
io::FILE_reader(self.r.err_file, false)
}
fn close_input(&mut self) { close_repr_input(&mut self.r); }
pub trait LocalData { }
impl<T:Durable> LocalData for @T { }
-impl Eq for LocalData {
+impl Eq for @LocalData {
pure fn eq(&self, other: &@LocalData) -> bool {
unsafe {
let ptr_a: (uint, uint) = cast::reinterpret_cast(&(*self));
// If TLS is used heavily in future, this could be made more efficient with a
// proper map.
-type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
+type TaskLocalElement = (*libc::c_void, *libc::c_void, @LocalData);
// Has to be a pointer at outermost layer; the foreign call returns void *.
type TaskLocalMap = @mut ~[Option<TaskLocalElement>];
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use sys;
use cast;
+use libc::{c_void, size_t};
+use rand::RngUtil;
+use rand;
+use sys;
use task;
use vec;
-use rand;
-use libc::{c_void, size_t};
#[cfg(test)] use uint;
newexpr: ast::expr, tm: test_mode) ->
ast::crate {
let j: @mut uint = @mut 0u;
- fn fold_expr_rep(j_: @mut uint, i_: uint, newexpr_: ast::expr_,
- original: &ast::expr_, fld: fold::ast_fold,
- tm_: test_mode) ->
- ast::expr_ {
+ fn fold_expr_rep(j_: @mut uint,
+ i_: uint,
+ newexpr_: ast::expr_,
+ original: &ast::expr_,
+ fld: @fold::ast_fold,
+ tm_: test_mode)
+ -> ast::expr_ {
*j_ += 1u;
if i_ + 1u == *j_ && safe_to_replace_expr(original, tm_) {
newexpr_
pub fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::Ty,
tm: test_mode) -> ast::crate {
let j: @mut uint = @mut 0u;
- fn fold_ty_rep(j_: @mut uint, i_: uint, newty_: ast::ty_,
- original: &ast::ty_, fld: fold::ast_fold,
- tm_: test_mode) ->
- ast::ty_ {
+ fn fold_ty_rep(j_: @mut uint,
+ i_: uint,
+ newty_: ast::ty_,
+ original: &ast::ty_,
+ fld: @fold::ast_fold,
+ tm_: test_mode)
+ -> ast::ty_ {
*j_ += 1u;
if i_ + 1u == *j_ && safe_to_replace_ty(original, tm_) {
newty_
while i < n { it(i); i += 1u; }
}
-pub fn as_str(f: @fn(+x: io::Writer)) -> ~str {
+pub fn as_str(f: @fn(+x: @io::Writer)) -> ~str {
io::with_str_writer(f)
}
diagnostic::mk_span_handler(handler, codemap),
crate2,
fname,
- rdr, a,
+ rdr,
+ a,
pprust::no_ann(),
false))
};
pub fn build_session_(sopts: @session::options,
cm: @codemap::CodeMap,
demitter: diagnostic::Emitter,
- span_diagnostic_handler: diagnostic::span_handler)
+ span_diagnostic_handler: @diagnostic::span_handler)
-> Session {
let target_cfg = build_target_config(sopts, demitter);
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler,
fail!();
}
-pub fn list_metadata(sess: Session, path: &Path, out: io::Writer) {
+pub fn list_metadata(sess: Session, path: &Path, out: @io::Writer) {
metadata::loader::list_file_metadata(
sess.parse_sess.interner,
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out);
codemap: @codemap::CodeMap,
// For a library crate, this is always none
main_fn: @mut Option<(node_id, codemap::span)>,
- span_diagnostic: diagnostic::span_handler,
- filesearch: filesearch::FileSearch,
+ span_diagnostic: @diagnostic::span_handler,
+ filesearch: @filesearch::FileSearch,
building_library: @mut bool,
working_dir: Path,
lint_settings: lint::LintSettings
fn next_node_id(&self) -> ast::node_id {
return syntax::parse::next_node_id(self.parse_sess);
}
- fn diagnostic(&self) -> diagnostic::span_handler {
+ fn diagnostic(&self) -> @diagnostic::span_handler {
self.span_diagnostic
}
fn debugging_opt(&self, opt: uint) -> bool {
}
}
-fn fold_mod(cx: @Context, m: &ast::_mod, fld: fold::ast_fold) -> ast::_mod {
+fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
let filtered_items =
m.items.filter_mapped(|a| filter_item(cx, *a));
let filtered_view_items =
fn fold_foreign_mod(
cx: @Context,
nm: &ast::foreign_mod,
- fld: fold::ast_fold
+ fld: @fold::ast_fold
) -> ast::foreign_mod {
let filtered_items =
nm.items.filter_mapped(|a| filter_foreign_item(cx, *a));
}
fn fold_item_underscore(cx: @Context, item: &ast::item_,
- fld: fold::ast_fold) -> ast::item_ {
+ fld: @fold::ast_fold) -> ast::item_ {
let item = match *item {
ast::item_impl(ref a, b, c, ref methods) => {
let methods = methods.filtered(|m| method_in_cfg(cx, *m) );
fn fold_block(
cx: @Context,
b: &ast::blk_,
- fld: fold::ast_fold
+ fld: @fold::ast_fold
) -> ast::blk_ {
let filtered_stmts =
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
#[abi = "rust-intrinsic"]
pub extern {
pub fn get_tydesc<T>() -> *();
- pub fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor);
+ pub fn visit_tydesc(++td: *TyDesc, &&tv: @TyVisitor);
}
}
}
sess: session::Session,
crate: @ast::crate,
path: ~[ast::ident],
- ext_cx: ext_ctxt,
+ ext_cx: @ext_ctxt,
testfns: ~[Test]
}
fn fold_mod(cx: @mut TestCtxt,
m: &ast::_mod,
- fld: fold::ast_fold)
+ fld: @fold::ast_fold)
-> ast::_mod {
// Remove any #[main] from the AST so it doesn't clash with
// the one we're going to add. Only if compiling an executable.
fn fold_crate(cx: @mut TestCtxt,
c: &ast::crate_,
- fld: fold::ast_fold)
+ fld: @fold::ast_fold)
-> ast::crate_ {
let folded = fold::noop_fold_crate(c, fld);
}
-fn fold_item(cx: @mut TestCtxt, &&i: @ast::item, fld: fold::ast_fold)
+fn fold_item(cx: @mut TestCtxt, &&i: @ast::item, fld: @fold::ast_fold)
-> Option<@ast::item> {
cx.path.push(i.ident);
debug!("current path: %s",
// Traverses an AST, reading all the information about use'd crates and extern
// libraries necessary for later resolving, typechecking, linking, etc.
-pub fn read_crates(diag: span_handler,
+pub fn read_crates(diag: @span_handler,
crate: ast::crate,
cstore: @mut cstore::CStore,
- filesearch: FileSearch,
+ filesearch: @FileSearch,
os: loader::os,
statik: bool,
intr: @ident_interner) {
}
fn warn_if_multiple_versions(e: @mut Env,
- diag: span_handler,
+ diag: @span_handler,
crate_cache: @mut ~[cache_entry]) {
use core::either::*;
}
struct Env {
- diag: span_handler,
- filesearch: FileSearch,
+ diag: @span_handler,
+ filesearch: @FileSearch,
cstore: @mut cstore::CStore,
os: loader::os,
statik: bool,
}
fn list_meta_items(intr: @ident_interner,
- meta_items: ebml::Doc, out: io::Writer) {
+ meta_items: ebml::Doc,
+ out: @io::Writer) {
for get_meta_items(meta_items).each |mi| {
out.write_str(fmt!("%s\n", pprust::meta_item_to_str(*mi, intr)));
}
}
fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str,
- out: io::Writer) {
+ out: @io::Writer) {
out.write_str(fmt!("=Crate Attributes (%s)=\n", hash));
for get_attributes(md).each |attr| {
return deps;
}
-fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: io::Writer) {
+fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: @io::Writer) {
out.write_str(~"=External Dependencies=\n");
for get_crate_deps(intr, data).each |dep| {
}
pub fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8],
- out: io::Writer) {
+ out: @io::Writer) {
let hash = get_crate_hash(bytes);
let md = reader::Doc(bytes);
list_crate_attributes(intr, md, *hash, out);
ii: ast::inlined_item);
pub struct EncodeParams {
- diag: span_handler,
+ diag: @span_handler,
tcx: ty::ctxt,
reachable: HashMap<ast::node_id, ()>,
reexports2: middle::resolve::ExportMap2,
}
pub struct EncodeContext {
- diag: span_handler,
+ diag: @span_handler,
tcx: ty::ctxt,
stats: @mut Stats,
reachable: HashMap<ast::node_id, ()>,
}
fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
- write_fn: &fn(io::Writer, T)) {
+ write_fn: &fn(@io::Writer, T)) {
let writer = ebml_w.writer;
ebml_w.start_tag(tag_index);
let mut bucket_locs: ~[uint] = ~[];
ebml_w.end_tag();
}
-fn write_str(writer: io::Writer, &&s: ~str) { writer.write_str(s); }
+fn write_str(writer: @io::Writer, &&s: ~str) { writer.write_str(s); }
-fn write_int(writer: io::Writer, &&n: int) {
+fn write_int(writer: @io::Writer, &&n: int) {
fail_unless!(n < 0x7fff_ffff);
writer.write_be_u32(n as u32);
}
type_abbrevs: ty::new_ty_hash()
};
- let ebml_w = writer::Encoder(wr as io::Writer);
+ let ebml_w = writer::Encoder(wr as @io::Writer);
encode_hash(ebml_w, ecx.link_meta.extras_hash);
pub fn mk_filesearch(maybe_sysroot: Option<Path>,
target_triple: &str,
- +addl_lib_search_paths: ~[Path]) -> FileSearch {
+ +addl_lib_search_paths: ~[Path])
+ -> @FileSearch {
struct FileSearchImpl {
sysroot: Path,
addl_lib_search_paths: ~[Path],
} as @FileSearch
}
-pub fn search<T:Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> {
+pub fn search<T:Copy>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
let mut rslt = None;
for filesearch.lib_search_paths().each |lib_search_path| {
debug!("searching %s", lib_search_path.to_str());
}
pub struct Context {
- diag: span_handler,
- filesearch: FileSearch,
+ diag: @span_handler,
+ filesearch: @FileSearch,
span: span,
ident: ast::ident,
metas: ~[@ast::meta_item],
fn find_library_crate_aux(
cx: Context,
(prefix, suffix): (~str, ~str),
- filesearch: filesearch::FileSearch
+ filesearch: @filesearch::FileSearch
) -> Option<(~str, @~[u8])> {
let crate_name = crate_name_from_metas(cx.metas);
let prefix: ~str = prefix + *crate_name + ~"-";
}
}
-pub fn note_linkage_attrs(intr: @ident_interner, diag: span_handler,
+pub fn note_linkage_attrs(intr: @ident_interner,
+ diag: @span_handler,
attrs: ~[ast::attribute]) {
for attr::find_linkage_metas(attrs).each |mi| {
diag.handler().note(fmt!("meta: %s",
// A diagnostic function for dumping crate metadata to an output stream
pub fn list_file_metadata(intr: @ident_interner,
- os: os, path: &Path, out: io::Writer) {
+ os: os,
+ path: &Path,
+ out: @io::Writer) {
match get_metadata_section(os, path) {
option::Some(bytes) => decoder::list_crate_metadata(intr, bytes, out),
option::None => {
use middle::ty::Vid;
pub struct ctxt {
- diag: span_handler,
+ diag: @span_handler,
// Def -> str Callback:
ds: @fn(def_id) -> ~str,
// The type context.
}
}
-pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) {
+pub fn enc_ty(w: @io::Writer, cx: @ctxt, t: ty::t) {
match cx.abbrevs {
ac_no_abbrevs => {
let result_str = match cx.tcx.short_names_cache.find(&t) {
}
}
}
-fn enc_mt(w: io::Writer, cx: @ctxt, mt: ty::mt) {
+fn enc_mt(w: @io::Writer, cx: @ctxt, mt: ty::mt) {
match mt.mutbl {
m_imm => (),
m_mutbl => w.write_char('m'),
enc_ty(w, cx, mt.ty);
}
-fn enc_opt<T>(w: io::Writer, t: Option<T>, enc_f: &fn(T)) {
+fn enc_opt<T>(w: @io::Writer, t: Option<T>, enc_f: &fn(T)) {
match &t {
&None => w.write_char('n'),
&Some(ref v) => {
}
}
-fn enc_substs(w: io::Writer, cx: @ctxt, substs: ty::substs) {
+fn enc_substs(w: @io::Writer, cx: @ctxt, substs: ty::substs) {
do enc_opt(w, substs.self_r) |r| { enc_region(w, cx, r) }
do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) }
w.write_char('[');
w.write_char(']');
}
-fn enc_region(w: io::Writer, cx: @ctxt, r: ty::Region) {
+fn enc_region(w: @io::Writer, cx: @ctxt, r: ty::Region) {
match r {
ty::re_bound(br) => {
w.write_char('b');
}
}
-fn enc_bound_region(w: io::Writer, cx: @ctxt, br: ty::bound_region) {
+fn enc_bound_region(w: @io::Writer, cx: @ctxt, br: ty::bound_region) {
match br {
ty::br_self => w.write_char('s'),
ty::br_anon(idx) => {
}
}
-pub fn enc_vstore(w: io::Writer, cx: @ctxt, v: ty::vstore) {
+pub fn enc_vstore(w: @io::Writer, cx: @ctxt, v: ty::vstore) {
w.write_char('/');
match v {
ty::vstore_fixed(u) => {
}
}
-pub fn enc_trait_store(w: io::Writer, cx: @ctxt, s: ty::TraitStore) {
+pub fn enc_trait_store(w: @io::Writer, cx: @ctxt, s: ty::TraitStore) {
match s {
ty::UniqTraitStore => w.write_char('~'),
ty::BoxTraitStore => w.write_char('@'),
}
}
-fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
+fn enc_sty(w: @io::Writer, cx: @ctxt, +st: ty::sty) {
match st {
ty::ty_nil => w.write_char('n'),
ty::ty_bot => w.write_char('z'),
}
}
-fn enc_sigil(w: io::Writer, sigil: Sigil) {
+fn enc_sigil(w: @io::Writer, sigil: Sigil) {
match sigil {
ManagedSigil => w.write_str("@"),
OwnedSigil => w.write_str("~"),
}
}
-pub fn enc_arg(w: io::Writer, cx: @ctxt, arg: ty::arg) {
+pub fn enc_arg(w: @io::Writer, cx: @ctxt, arg: ty::arg) {
enc_mode(w, cx, arg.mode);
enc_ty(w, cx, arg.ty);
}
-pub fn enc_mode(w: io::Writer, cx: @ctxt, m: mode) {
+pub fn enc_mode(w: @io::Writer, cx: @ctxt, m: mode) {
match ty::resolved_mode(cx.tcx, m) {
by_copy => w.write_char('+'),
by_ref => w.write_char('='),
}
}
-fn enc_purity(w: io::Writer, p: purity) {
+fn enc_purity(w: @io::Writer, p: purity) {
match p {
pure_fn => w.write_char('p'),
impure_fn => w.write_char('i'),
}
}
-fn enc_abi(w: io::Writer, a: Abi) {
+fn enc_abi(w: @io::Writer, a: Abi) {
match a {
RustAbi => w.write_char('r'),
}
}
-fn enc_onceness(w: io::Writer, o: Onceness) {
+fn enc_onceness(w: @io::Writer, o: Onceness) {
match o {
Once => w.write_char('o'),
Many => w.write_char('m')
}
}
-fn enc_bare_fn_ty(w: io::Writer, cx: @ctxt, ft: &ty::BareFnTy) {
+fn enc_bare_fn_ty(w: @io::Writer, cx: @ctxt, ft: &ty::BareFnTy) {
enc_purity(w, ft.purity);
enc_abi(w, ft.abi);
enc_fn_sig(w, cx, &ft.sig);
}
-fn enc_closure_ty(w: io::Writer, cx: @ctxt, ft: &ty::ClosureTy) {
+fn enc_closure_ty(w: @io::Writer, cx: @ctxt, ft: &ty::ClosureTy) {
enc_sigil(w, ft.sigil);
enc_purity(w, ft.purity);
enc_onceness(w, ft.onceness);
enc_fn_sig(w, cx, &ft.sig);
}
-fn enc_fn_sig(w: io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
+fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
w.write_char('[');
for fsig.inputs.each |arg| {
enc_arg(w, cx, *arg);
enc_ty(w, cx, fsig.output);
}
-pub fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {
+pub fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {
for vec::each(*bs) |bound| {
match *bound {
ty::bound_owned => w.write_char('S'),
// nested items, as otherwise it would get confused when translating
// inlined items.
fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
- fn drop_nested_items(blk: &ast::blk_, fld: fold::ast_fold) -> ast::blk_ {
+ fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ {
let stmts_sans_items = do blk.stmts.filtered |stmt| {
match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
}
}
- fn write_vars(&self, wr: io::Writer,
+ fn write_vars(&self,
+ wr: @io::Writer,
ln: LiveNode,
test: &fn(uint) -> LiveNode) {
let node_base_idx = self.idx(ln, Variable(0));
}
}
-pub fn x86_64_abi_info() -> ABIInfo {
+pub fn x86_64_abi_info() -> @ABIInfo {
return @X86_64_ABIInfo as @ABIInfo;
}
pub fn T_opaque_trait(cx: @CrateContext, store: ty::TraitStore) -> TypeRef {
match store {
- ty::BoxTraitStore | ty::BareTraitStore => {
+ ty::BoxTraitStore => {
T_struct(~[T_ptr(cx.tydesc_type), T_opaque_box_ptr(cx)])
}
ty::UniqTraitStore => {
ty::RegionTraitStore(_) => {
T_struct(~[T_ptr(cx.tydesc_type), T_ptr(T_i8())])
}
+ ty::BareTraitStore => {
+ cx.sess.bug(~"can't make T_opaque_trait with bare trait store")
+ }
}
}
use syntax::{attr, ast_map};
use syntax::parse::token::special_idents;
-fn abi_info(arch: session::arch) -> cabi::ABIInfo {
+fn abi_info(arch: session::arch) -> @cabi::ABIInfo {
return match arch {
arch_x86_64 => x86_64_abi_info(),
arch_arm => cabi_arm::abi_info(),
pub type ctxt = @ctxt_;
struct ctxt_ {
- diag: syntax::diagnostic::span_handler,
+ diag: @syntax::diagnostic::span_handler,
interner: HashMap<intern_key, t_box>,
next_id: @mut uint,
vecs_implicitly_copyable: bool,
fn storeify(cx: ctxt, ty: t, store: TraitStore) -> t {
match ty::get(ty).sty {
ty::ty_trait(did, ref substs, trait_store) => {
- if store == trait_store ||
- (store == BareTraitStore &&
- trait_store == BoxTraitStore) ||
- (store == BoxTraitStore &&
- trait_store == BareTraitStore) {
+ if store == trait_store {
ty
} else {
mk_trait(cx, did, (/*bad*/copy *substs), store)
// Handle @, ~, and & being able to mean estrs and evecs.
// If a_seq_ty is a str or a vec, make it an estr/evec.
- // Also handle function sigils and first-class trait types.
+ // Also handle first-class trait types.
fn mk_pointer<AC:AstConv,RS:region_scope + Copy + Durable>(
self: &AC,
rscope: &RS,
fail_unless!(ccx.tcx.intrinsic_defs.contains_key(&ty_visitor_name));
let (_, tydesc_ty) = tcx.intrinsic_defs.get(&tydesc_name);
let (_, visitor_trait) = tcx.intrinsic_defs.get(&ty_visitor_name);
+
+ let visitor_trait = match ty::get(visitor_trait).sty {
+ ty::ty_trait(trait_def_id, ref trait_substs, _) => {
+ ty::mk_trait(tcx,
+ trait_def_id,
+ copy *trait_substs,
+ ty::BoxTraitStore)
+ }
+ _ => {
+ tcx.sess.span_bug(it.span, ~"TyVisitor wasn't a trait?!")
+ }
+ };
+
let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {ty: tydesc_ty,
mutbl: ast::m_imm});
(0u, ~[arg(ast::by_copy, td_ptr),
vcx.infcx.ty_to_str(ity));
match ty::get(ity).sty {
- ty::ty_trait(idid, _, _) => {
+ ty::ty_trait(idid, ref isubsts, _) => {
if trait_id == idid {
debug!("(checking vtable) @0 \
relating ty to trait \
ty with did %?",
idid);
+
+ // Convert `ity` so that it has the right vstore.
+ let ity = ty::mk_trait(vcx.tcx(),
+ idid,
+ copy *isubsts,
+ trait_store);
+
relate_trait_tys(vcx, location_info,
trait_ty, ity);
let vtable = vtable_param(n, n_bound);
match (&ty::get(ty).sty, store) {
(&ty::ty_box(mt), ty::BoxTraitStore) |
// XXX: Bare trait store is deprecated.
- (&ty::ty_box(mt), ty::BareTraitStore) |
(&ty::ty_uniq(mt), ty::UniqTraitStore) |
(&ty::ty_rptr(_, mt), ty::RegionTraitStore(*)) => {
let location_info =
}
}
- // XXX: Remove bare below.
- (_, ty::BoxTraitStore) | (_, ty::BareTraitStore) => {
+ (_, ty::BareTraitStore) => {
+ fcx.ccx.tcx.sess.span_err(
+ ex.span,
+ ~"a sigil (`@`, `~`, or `&`) must be specified \
+ when casting to a trait");
+ }
+
+ (_, ty::BoxTraitStore) => {
fcx.ccx.tcx.sess.span_err(
ex.span,
fmt!("can only cast an @-pointer \
}
}
- // XXX: This should go away soon.
- (ty::BareTraitStore, ty::BoxTraitStore) |
- (ty::BoxTraitStore, ty::BareTraitStore) => {
- Ok(ty::BoxTraitStore)
- }
-
_ if a == b => {
Ok(a)
}
pub fn in_binding_rscope<RS:region_scope + Copy + Durable>(self: &RS)
-> binding_rscope {
- let base = @(copy *self) as @region_scope;
+ let base = @copy *self;
+ let base = base as @region_scope;
binding_rscope { base: base, anon_bindings: @mut 0 }
}
impl region_scope for binding_rscope {
/// A utility function that hands off a pretty printer to a callback.
fn with_pp(intr: @token::ident_interner,
- cb: &fn(@pprust::ps, io::Writer)) -> ~str {
+ cb: &fn(@pprust::ps, @io::Writer)) -> ~str {
do io::with_str_writer |writer| {
let pp = pprust::rust_printer(writer, intr);
}
/// Run a command, e.g. :clear, :exit, etc.
-fn run_cmd(repl: &mut Repl, _in: io::Reader, _out: io::Writer,
+fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
cmd: ~str, args: ~[~str]) -> CmdAction {
let mut action = action_none;
match cmd {
/// Executes a line of input, which may either be rust code or a
/// :command. Returns a new Repl if it has changed.
-fn run_line(repl: &mut Repl, in: io::Reader, out: io::Writer, line: ~str)
+fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str)
-> Option<Repl> {
if line.starts_with(~":") {
let full = line.substr(1, line.len() - 1);
struct ReadyCtx {
sess: session::Session,
crate: @ast::crate,
- ext_cx: ext_ctxt,
+ ext_cx: @ext_ctxt,
path: ~[ast::ident],
fns: ~[ListenerFn]
}
-fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod,
- fold: fold::ast_fold) -> ast::_mod {
+fn fold_mod(_ctx: @mut ReadyCtx,
+ m: &ast::_mod,
+ fold: @fold::ast_fold) -> ast::_mod {
fn strip_main(item: @ast::item) -> @ast::item {
@ast::item {
attrs: do item.attrs.filtered |attr| {
}, fold)
}
-fn fold_item(ctx: @mut ReadyCtx, item: @ast::item,
- fold: fold::ast_fold) -> Option<@ast::item> {
-
+fn fold_item(ctx: @mut ReadyCtx,
+ item: @ast::item,
+ fold: @fold::ast_fold) -> Option<@ast::item> {
ctx.path.push(item.ident);
let attrs = attr::find_attrs_by_name(item.attrs, ~"pkg_do");
fail_unless!(a.capacity() == uint::bits);
}
- fn rng() -> rand::Rng {
+ fn rng() -> @rand::Rng {
let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
rand::seeded_rng(seed)
}
// ebml writing
pub struct Encoder {
- writer: io::Writer,
+ writer: @io::Writer,
priv mut size_positions: ~[uint],
}
- fn write_sized_vuint(w: io::Writer, n: uint, size: uint) {
+ fn write_sized_vuint(w: @io::Writer, n: uint, size: uint) {
match size {
1u => w.write(&[0x80u8 | (n as u8)]),
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
};
}
- fn write_vuint(w: io::Writer, n: uint) {
+ fn write_vuint(w: @io::Writer, n: uint) {
if n < 0x7f_u { write_sized_vuint(w, n, 1u); return; }
if n < 0x4000_u { write_sized_vuint(w, n, 2u); return; }
if n < 0x200000_u { write_sized_vuint(w, n, 3u); return; }
fail!(fmt!("vint to write too big: %?", n));
}
- pub fn Encoder(w: io::Writer) -> Encoder {
+ pub fn Encoder(w: @io::Writer) -> Encoder {
let size_positions: ~[uint] = ~[];
Encoder { writer: w, mut size_positions: size_positions }
}
}
pub trait FromReader {
- static fn from_reader(r: Reader) -> Self;
+ static fn from_reader(r: @Reader) -> Self;
}
pub trait FromWriter {
- static fn from_writer(w: Writer) -> Self;
+ static fn from_writer(w: @Writer) -> Self;
}
impl FromReader for json::Decoder/&self {
- static fn from_reader(r: Reader) -> json::Decoder/&self {
+ static fn from_reader(r: @Reader) -> json::Decoder/&self {
match json::from_reader(r) {
Ok(json) => {
json::Decoder(json)
}
impl FromWriter for json::Encoder {
- static fn from_writer(w: Writer) -> json::Encoder {
+ static fn from_writer(w: @Writer) -> json::Encoder {
json::Encoder(w)
}
}
impl FromReader for ebml::reader::Decoder {
- static fn from_reader(r: Reader) -> ebml::reader::Decoder {
+ static fn from_reader(r: @Reader) -> ebml::reader::Decoder {
let buf = @r.read_whole_stream();
let doc = ebml::reader::Doc(buf);
ebml::reader::Decoder(doc)
}
impl FromWriter for ebml::writer::Encoder {
- static fn from_writer(w: Writer) -> ebml::writer::Encoder {
+ static fn from_writer(w: @Writer) -> ebml::writer::Encoder {
ebml::writer::Encoder(w)
}
}
}
pub struct Encoder {
- priv wr: io::Writer,
+ priv wr: @io::Writer,
}
-pub fn Encoder(wr: io::Writer) -> Encoder {
+pub fn Encoder(wr: @io::Writer) -> Encoder {
Encoder { wr: wr }
}
}
pub struct PrettyEncoder {
- priv wr: io::Writer,
+ priv wr: @io::Writer,
priv mut indent: uint,
}
-pub fn PrettyEncoder(wr: io::Writer) -> PrettyEncoder {
+pub fn PrettyEncoder(wr: @io::Writer) -> PrettyEncoder {
PrettyEncoder { wr: wr, indent: 0 }
}
}
/// Encodes a json value into a io::writer
-pub fn to_writer(wr: io::Writer, json: &Json) {
+pub fn to_writer(wr: @io::Writer, json: &Json) {
json.encode(&Encoder(wr))
}
}
/// Encodes a json value into a io::writer
-pub fn to_pretty_writer(wr: io::Writer, json: &Json) {
+pub fn to_pretty_writer(wr: @io::Writer, json: &Json) {
json.encode(&PrettyEncoder(wr))
}
}
pub struct Parser {
- priv rdr: io::Reader,
+ priv rdr: @io::Reader,
priv mut ch: char,
priv mut line: uint,
priv mut col: uint,
}
/// Decode a json value from an io::reader
-pub fn Parser(rdr: io::Reader) -> Parser {
+pub fn Parser(rdr: @io::Reader) -> Parser {
Parser {
rdr: rdr,
ch: rdr.read_char(),
}
}
-/// Decodes a json value from an io::reader
-pub fn from_reader(rdr: io::Reader) -> Result<Json, Error> {
+/// Decodes a json value from an @io::Reader
+pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> {
Parser(rdr).parse()
}
let sock_buf = @socket_buf(result::unwrap(conn_result));
buf_write(sock_buf, expected_req);
- let buf_reader = sock_buf as Reader;
+ let buf_reader = sock_buf as @Reader;
let actual_response = str::from_bytes(buf_reader.read_whole_stream());
debug!("Actual response: %s", actual_response);
fail_unless!(expected_resp == actual_response);
}
pub impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> T<K, V> {
- fn to_writer(&self, wr: io::Writer) {
+ fn to_writer(&self, wr: @io::Writer) {
if self.count == 0u {
wr.write_str(~"{}");
return;
use core::io;
pub struct Serializer {
- wr: io::Writer,
+ wr: @io::Writer,
}
-pub fn Serializer(wr: io::Writer) -> Serializer {
+pub fn Serializer(wr: @io::Writer) -> Serializer {
Serializer { wr: wr }
}
bad_parse: () -> ();
}
-fn take_nonempty_prefix(rdr: io::Reader,
+fn take_nonempty_prefix(rdr: @io::Reader,
ch: char,
pred: &fn(char) -> bool) -> (~str, char) {
let mut buf = ~"";
(buf, ch)
}
-fn take_num(rdr: io::Reader, ch: char) -> (uint, char) {
+fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
let (s, ch) = take_nonempty_prefix(rdr, ch, char::is_digit);
match uint::from_str(s) {
None => { bad_parse::cond.raise(()); (0, ch) },
}
}
-fn take_ident(rdr: io::Reader, ch: char) -> (Identifier, char) {
+fn take_ident(rdr: @io::Reader, ch: char) -> (Identifier, char) {
let (s,ch) = take_nonempty_prefix(rdr, ch, char::is_alphanumeric);
if s.all(char::is_digit) {
match uint::from_str(s) {
}
}
-fn parse_reader(rdr: io::Reader) -> Version {
-
+fn parse_reader(rdr: @io::Reader) -> Version {
let (major, ch) = take_num(rdr, rdr.read_char());
expect(ch, '.');
let (minor, ch) = take_num(rdr, rdr.read_char());
use sort::tim_sort;
+ use core::rand::RngUtil;
use core::rand;
use core::vec;
use sort::*;
+ use core::rand::RngUtil;
use core::rand;
use core::task;
use core::uint;
use core::os;
use core::prelude::*;
+use core::rand::RngUtil;
use core::rand;
pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
pub const color_bright_cyan: u8 = 14u8;
pub const color_bright_white: u8 = 15u8;
-pub fn esc(writer: io::Writer) { writer.write(~[0x1bu8, '[' as u8]); }
+pub fn esc(writer: @io::Writer) { writer.write(~[0x1bu8, '[' as u8]); }
/// Reset the foreground and background colors to default
-pub fn reset(writer: io::Writer) {
+pub fn reset(writer: @io::Writer) {
esc(writer);
writer.write(~['0' as u8, 'm' as u8]);
}
};
}
-pub fn set_color(writer: io::Writer, first_char: u8, color: u8) {
+pub fn set_color(writer: @io::Writer, first_char: u8, color: u8) {
fail_unless!((color < 16u8));
esc(writer);
let mut color = color;
}
/// Set the foreground color
-pub fn fg(writer: io::Writer, color: u8) {
+pub fn fg(writer: @io::Writer, color: u8) {
return set_color(writer, '3' as u8, color);
}
/// Set the background color
-pub fn bg(writer: io::Writer, color: u8) {
+pub fn bg(writer: @io::Writer, color: u8) {
return set_color(writer, '4' as u8, color);
}
pub enum TestResult { TrOk, TrFailed, TrIgnored, TrBench(BenchSamples) }
struct ConsoleTestState {
- out: io::Writer,
- log_out: Option<io::Writer>,
+ out: @io::Writer,
+ log_out: Option<@io::Writer>,
use_color: bool,
mut total: uint,
mut passed: uint,
}
}
- fn write_log(out: io::Writer, result: TestResult, test: &TestDesc) {
+ fn write_log(out: @io::Writer, result: TestResult, test: &TestDesc) {
out.write_line(fmt!("%s %s",
match result {
TrOk => ~"ok",
}, test.name.to_str()));
}
- fn write_ok(out: io::Writer, use_color: bool) {
+ fn write_ok(out: @io::Writer, use_color: bool) {
write_pretty(out, ~"ok", term::color_green, use_color);
}
- fn write_failed(out: io::Writer, use_color: bool) {
+ fn write_failed(out: @io::Writer, use_color: bool) {
write_pretty(out, ~"FAILED", term::color_red, use_color);
}
- fn write_ignored(out: io::Writer, use_color: bool) {
+ fn write_ignored(out: @io::Writer, use_color: bool) {
write_pretty(out, ~"ignored", term::color_yellow, use_color);
}
- fn write_bench(out: io::Writer, use_color: bool) {
+ fn write_bench(out: @io::Writer, use_color: bool) {
write_pretty(out, ~"bench", term::color_cyan, use_color);
}
- fn write_pretty(out: io::Writer, word: &str, color: u8, use_color: bool) {
+ fn write_pretty(out: @io::Writer,
+ word: &str,
+ color: u8,
+ use_color: bool) {
if use_color && term::color_supported() {
term::fg(out, color);
}
use stats::Stats;
use core::num;
+ use core::rand::RngUtil;
use core::rand;
use core::u64;
use core::vec;
let mut prev_madp = 0.0;
loop {
-
let n_samples = rng.gen_uint_range(50, 60);
let n_iter = rng.gen_uint_range(magnitude,
magnitude * 2);
use uv;
use core::iter;
+ use core::rand::RngUtil;
use core::rand;
use core::task;
use core::pipes::{stream, SharedChan};
mod test_treemap {
use core::prelude::*;
use super::*;
+ use core::rand::RngUtil;
use core::rand;
#[test]
map: @map,
path: path,
local_id: uint,
- diag: span_handler,
+ diag: @span_handler,
}
pub type vt = visit::vt<@mut Ctx>;
});
}
-pub fn map_crate(diag: span_handler, c: crate) -> map {
+pub fn map_crate(diag: @span_handler, c: crate) -> map {
let cx = @mut Ctx {
map: @std::oldmap::HashMap(),
path: ~[],
// Used for items loaded from external crate that are being inlined into this
// crate. The `path` should be the path to the item but should not include
// the item itself.
-pub fn map_decoded_item(diag: span_handler,
+pub fn map_decoded_item(diag: @span_handler,
map: map,
+path: path,
ii: inlined_item) {
}
-pub fn require_unique_names(diagnostic: span_handler,
+pub fn require_unique_names(diagnostic: @span_handler,
metas: &[@ast::meta_item]) {
let mut set = LinearSet::new();
for metas.each |meta| {
fn span_note(@mut self, sp: span, msg: &str);
fn span_bug(@mut self, sp: span, msg: &str) -> !;
fn span_unimpl(@mut self, sp: span, msg: &str) -> !;
- fn handler(@mut self) -> handler;
+ fn handler(@mut self) -> @handler;
}
struct HandlerT {
}
struct CodemapT {
- handler: handler,
+ handler: @handler,
cm: @codemap::CodeMap,
}
fn span_unimpl(@mut self, sp: span, msg: &str) -> ! {
self.span_bug(sp, ~"unimplemented " + msg);
}
- fn handler(@mut self) -> handler {
+ fn handler(@mut self) -> @handler {
self.handler
}
}
fmt!("internal compiler error: %s", msg)
}
-pub fn mk_span_handler(handler: handler, cm: @codemap::CodeMap)
- -> span_handler {
+pub fn mk_span_handler(handler: @handler, cm: @codemap::CodeMap)
+ -> @span_handler {
@mut CodemapT { handler: handler, cm: cm } as @span_handler
}
}
}
-pub fn expect<T:Copy>(diag: span_handler,
+pub fn expect<T:Copy>(diag: @span_handler,
opt: Option<T>,
msg: &fn() -> ~str) -> T {
match opt {
}
}
-pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
- -> base::MacResult {
-
- let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(),
+pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
+ -> base::MacResult {
+ let p = parse::new_parser_from_tts(cx.parse_sess(),
+ cx.cfg(),
vec::from_slice(tts));
let mut asm = ~"";
}
pub fn expand_auto_encode(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
_mitem: @ast::meta_item,
in_items: ~[@ast::item]
}
pub fn expand_auto_decode(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
_mitem: @ast::meta_item,
in_items: ~[@ast::item]
}
}
-priv impl ext_ctxt {
+priv impl @ext_ctxt {
fn bind_path(
&self,
span: span,
}
fn mk_impl(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ident: ast::ident,
ty_param: ast::TyParam,
}
fn mk_ser_impl(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ident: ast::ident,
generics: &ast::Generics,
}
fn mk_deser_impl(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ident: ast::ident,
generics: &ast::Generics,
}
fn mk_ser_method(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
+ser_body: ast::blk
) -> @ast::method {
}
fn mk_deser_method(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ty: @ast::Ty,
+deser_body: ast::blk
}
fn mk_struct_ser_impl(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ident: ast::ident,
fields: &[@ast::struct_field],
}
fn mk_struct_deser_impl(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ident: ast::ident,
fields: ~[@ast::struct_field],
}
fn mk_enum_ser_impl(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ident: ast::ident,
+enum_def: ast::enum_def,
}
fn mk_enum_deser_impl(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
ident: ast::ident,
+enum_def: ast::enum_def,
}
fn ser_variant(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
v_name: ast::ident,
v_idx: uint,
}
fn mk_enum_ser_body(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
name: ast::ident,
+variants: ~[ast::variant]
}
fn mk_enum_deser_variant_nary(
- cx: ext_ctxt,
+ cx: @ext_ctxt,
span: span,
name: ast::ident,
args: ~[ast::variant_arg]
}
fn mk_enum_deser_body(
- ext_cx: ext_ctxt,
+ ext_cx: @ext_ctxt,
span: span,
name: ast::ident,
variants: ~[ast::variant]
ext: SyntaxExtension
}
-pub type ItemDecorator = @fn(ext_ctxt,
+pub type ItemDecorator = @fn(@ext_ctxt,
span,
@ast::meta_item,
~[@ast::item])
span: Option<span>
}
-pub type SyntaxExpanderTTFun = @fn(ext_ctxt,
+pub type SyntaxExpanderTTFun = @fn(@ext_ctxt,
span,
&[ast::token_tree])
-> MacResult;
span: Option<span>
}
-pub type SyntaxExpanderTTItemFun = @fn(ext_ctxt,
+pub type SyntaxExpanderTTItemFun = @fn(@ext_ctxt,
span,
ast::ident,
~[ast::token_tree])
fn ident_of(@mut self, st: ~str) -> ast::ident;
}
-pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
- +cfg: ast::crate_cfg) -> ext_ctxt {
+pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, +cfg: ast::crate_cfg)
+ -> @ext_ctxt {
struct CtxtRepr {
parse_sess: @mut parse::ParseSess,
cfg: ast::crate_cfg,
((imp) as @ext_ctxt)
}
-pub fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str {
+pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str {
match expr.node {
ast::expr_lit(l) => match l.node {
ast::lit_str(s) => copy *s,
}
}
-pub fn expr_to_ident(cx: ext_ctxt,
+pub fn expr_to_ident(cx: @ext_ctxt,
expr: @ast::expr,
err_msg: ~str) -> ast::ident {
match expr.node {
}
}
-pub fn check_zero_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree],
+pub fn check_zero_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree],
name: &str) {
if tts.len() != 0 {
cx.span_fatal(sp, fmt!("%s takes no arguments", name));
}
}
-pub fn get_single_str_from_tts(cx: ext_ctxt,
+pub fn get_single_str_from_tts(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree],
name: &str) -> ~str {
}
}
-pub fn get_exprs_from_tts(cx: ext_ctxt, tts: &[ast::token_tree])
+pub fn get_exprs_from_tts(cx: @ext_ctxt, tts: &[ast::token_tree])
-> ~[@ast::expr] {
let p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
ex: @ast::expr
}
-pub fn mk_expr(cx: ext_ctxt,
+pub fn mk_expr(cx: @ext_ctxt,
sp: codemap::span,
+expr: ast::expr_)
-> @ast::expr {
}
}
-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 = @codemap::spanned { node: lit, span: sp };
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 {
let lit = ast::lit_int(i as i64, ast::ty_i);
return mk_lit(cx, sp, lit);
}
-pub fn mk_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
+pub fn mk_uint(cx: @ext_ctxt, sp: span, u: uint) -> @ast::expr {
let lit = ast::lit_uint(u as u64, ast::ty_u);
return mk_lit(cx, sp, lit);
}
-pub fn mk_u8(cx: ext_ctxt, sp: span, u: u8) -> @ast::expr {
+pub fn mk_u8(cx: @ext_ctxt, sp: span, u: u8) -> @ast::expr {
let lit = ast::lit_uint(u as u64, ast::ty_u8);
return mk_lit(cx, sp, lit);
}
-pub fn mk_binary(cx: ext_ctxt, sp: span, op: ast::binop,
+pub fn mk_binary(cx: @ext_ctxt, sp: span, op: ast::binop,
lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr {
cx.next_id(); // see ast_util::op_expr_callee_id
mk_expr(cx, sp, ast::expr_binary(op, lhs, rhs))
}
-pub fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
+pub fn mk_unary(cx: @ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
-> @ast::expr {
cx.next_id(); // see ast_util::op_expr_callee_id
mk_expr(cx, sp, ast::expr_unary(op, e))
rp: None,
types: ~[] }
}
-pub fn mk_path(cx: ext_ctxt, sp: span, +idents: ~[ast::ident]) -> @ast::expr {
+pub fn mk_path(cx: @ext_ctxt, sp: span, +idents: ~[ast::ident])
+ -> @ast::expr {
mk_expr(cx, sp, ast::expr_path(mk_raw_path(sp, idents)))
}
-pub fn mk_path_global(cx: ext_ctxt, sp: span, +idents: ~[ast::ident])
+pub fn mk_path_global(cx: @ext_ctxt, sp: span, +idents: ~[ast::ident])
-> @ast::expr {
mk_expr(cx, sp, ast::expr_path(mk_raw_path_global(sp, idents)))
}
-pub fn mk_access_(cx: ext_ctxt, sp: span, p: @ast::expr, m: ast::ident)
+pub fn mk_access_(cx: @ext_ctxt, sp: span, p: @ast::expr, m: ast::ident)
-> @ast::expr {
mk_expr(cx, sp, ast::expr_field(p, m, ~[]))
}
-pub fn mk_access(cx: ext_ctxt, sp: span, +p: ~[ast::ident], m: ast::ident)
+pub fn mk_access(cx: @ext_ctxt, sp: span, +p: ~[ast::ident], m: ast::ident)
-> @ast::expr {
let pathexpr = mk_path(cx, sp, p);
return mk_access_(cx, sp, pathexpr, m);
}
-pub fn mk_addr_of(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
+pub fn mk_addr_of(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
return mk_expr(cx, sp, ast::expr_addr_of(ast::m_imm, e));
}
-pub fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr,
+pub fn mk_call_(cx: @ext_ctxt, sp: span, fn_expr: @ast::expr,
+args: ~[@ast::expr]) -> @ast::expr {
mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar))
}
-pub fn mk_call(cx: ext_ctxt, sp: span, +fn_path: ~[ast::ident],
+pub fn mk_call(cx: @ext_ctxt, sp: span, +fn_path: ~[ast::ident],
+args: ~[@ast::expr]) -> @ast::expr {
let pathexpr = mk_path(cx, sp, fn_path);
return mk_call_(cx, sp, pathexpr, args);
}
-pub fn mk_call_global(cx: ext_ctxt, sp: span, +fn_path: ~[ast::ident],
+pub fn mk_call_global(cx: @ext_ctxt, sp: span, +fn_path: ~[ast::ident],
+args: ~[@ast::expr]) -> @ast::expr {
let pathexpr = mk_path_global(cx, sp, fn_path);
return mk_call_(cx, sp, pathexpr, args);
}
// e = expr, t = type
-pub fn mk_base_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr])
+pub fn mk_base_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr])
-> @ast::expr {
let vecexpr = ast::expr_vec(exprs, ast::m_imm);
mk_expr(cx, sp, vecexpr)
}
-pub fn mk_vstore_e(cx: ext_ctxt, sp: span, expr: @ast::expr,
+pub fn mk_vstore_e(cx: @ext_ctxt, sp: span, expr: @ast::expr,
vst: ast::expr_vstore) ->
@ast::expr {
mk_expr(cx, sp, ast::expr_vstore(expr, vst))
}
-pub fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr])
+pub fn mk_uniq_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr])
-> @ast::expr {
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_uniq)
}
-pub fn mk_slice_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr])
+pub fn mk_slice_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr])
-> @ast::expr {
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs),
ast::expr_vstore_slice)
}
-pub fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr])
+pub fn mk_fixed_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr])
-> @ast::expr {
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs),
ast::expr_vstore_fixed(None))
}
-pub fn mk_base_str(cx: ext_ctxt, sp: span, +s: ~str) -> @ast::expr {
+pub fn mk_base_str(cx: @ext_ctxt, sp: span, +s: ~str) -> @ast::expr {
let lit = ast::lit_str(@s);
return mk_lit(cx, sp, lit);
}
-pub fn mk_uniq_str(cx: ext_ctxt, sp: span, +s: ~str) -> @ast::expr {
+pub fn mk_uniq_str(cx: @ext_ctxt, sp: span, +s: ~str) -> @ast::expr {
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::expr_vstore_uniq)
}
pub fn mk_field(sp: span, f: &Field) -> ast::field {
pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] {
fields.map(|f| mk_field(sp, f))
}
-pub fn mk_struct_e(cx: ext_ctxt,
+pub fn mk_struct_e(cx: @ext_ctxt,
sp: span,
+ctor_path: ~[ast::ident],
+fields: ~[Field])
mk_fields(sp, fields),
option::None::<@ast::expr>))
}
-pub fn mk_global_struct_e(cx: ext_ctxt,
+pub fn mk_global_struct_e(cx: @ext_ctxt,
sp: span,
+ctor_path: ~[ast::ident],
+fields: ~[Field])
mk_fields(sp, fields),
option::None::<@ast::expr>))
}
-pub fn mk_glob_use(cx: ext_ctxt,
+pub fn mk_glob_use(cx: @ext_ctxt,
sp: span,
+path: ~[ast::ident]) -> @ast::view_item {
let glob = @codemap::spanned {
vis: ast::private,
span: sp }
}
-pub fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
+pub fn mk_local(cx: @ext_ctxt, sp: span, mutbl: bool,
ident: ast::ident, ex: @ast::expr) -> @ast::stmt {
let pat = @ast::pat {
let decl = codemap::spanned {node: ast::decl_local(~[local]), 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],
+stmts: ~[@ast::stmt],
expr: Option<@ast::expr>) -> @ast::expr {
};
mk_expr(cx, span, ast::expr_block(blk))
}
-pub fn mk_block_(cx: ext_ctxt,
+pub fn mk_block_(cx: @ext_ctxt,
span: span,
+stmts: ~[@ast::stmt])
-> ast::blk {
span: span,
}
}
-pub fn mk_simple_block(cx: ext_ctxt,
+pub fn mk_simple_block(cx: @ext_ctxt,
span: span,
expr: @ast::expr)
-> ast::blk {
span: span,
}
}
-pub fn mk_copy(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
+pub fn mk_copy(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
mk_expr(cx, sp, ast::expr_copy(e))
}
-pub fn mk_managed(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
+pub fn mk_managed(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e))
}
-pub fn mk_pat(cx: ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat {
+pub fn mk_pat(cx: @ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat {
@ast::pat { id: cx.next_id(), node: pat, span: span }
}
-pub fn mk_pat_ident(cx: ext_ctxt,
+pub fn mk_pat_ident(cx: @ext_ctxt,
span: span,
ident: ast::ident) -> @ast::pat {
mk_pat_ident_with_binding_mode(cx, span, ident, ast::bind_by_copy)
}
-pub fn mk_pat_ident_with_binding_mode(cx: ext_ctxt,
+pub fn mk_pat_ident_with_binding_mode(cx: @ext_ctxt,
span: span,
ident: ast::ident,
bm: ast::binding_mode) -> @ast::pat {
let pat = ast::pat_ident(bm, path, None);
mk_pat(cx, span, pat)
}
-pub fn mk_pat_enum(cx: ext_ctxt,
+pub fn mk_pat_enum(cx: @ext_ctxt,
span: span,
path: @ast::path,
+subpats: ~[@ast::pat])
let pat = ast::pat_enum(path, Some(subpats));
mk_pat(cx, span, pat)
}
-pub fn mk_pat_struct(cx: ext_ctxt,
+pub fn mk_pat_struct(cx: @ext_ctxt,
span: span,
path: @ast::path,
+field_pats: ~[ast::field_pat])
let pat = ast::pat_struct(path, field_pats, false);
mk_pat(cx, span, 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(@codemap::spanned {
node: ast::lit_bool(value),
span: span });
build::mk_expr(cx, span, 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());
@codemap::spanned { node: stmt_, span: span }
}
-pub fn mk_ty_path(cx: ext_ctxt,
+pub fn mk_ty_path(cx: @ext_ctxt,
span: span,
+idents: ~[ ast::ident ])
-> @ast::Ty {
let ty = @ast::Ty { id: cx.next_id(), node: ty, span: span };
ty
}
-pub fn mk_ty_path_global(cx: ext_ctxt,
+pub fn mk_ty_path_global(cx: @ext_ctxt,
span: span,
+idents: ~[ ast::ident ])
-> @ast::Ty {
let ty = @ast::Ty { id: cx.next_id(), node: ty, span: span };
ty
}
-pub fn mk_simple_ty_path(cx: ext_ctxt,
+pub fn mk_simple_ty_path(cx: @ext_ctxt,
span: span,
ident: ast::ident)
-> @ast::Ty {
mk_ty_path(cx, span, ~[ ident ])
}
-pub fn mk_arg(cx: ext_ctxt,
+pub fn mk_arg(cx: @ext_ctxt,
span: span,
ident: ast::ident,
ty: @ast::Ty)
pub fn mk_fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl {
ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val }
}
-pub fn mk_ty_param(cx: ext_ctxt,
+pub fn mk_ty_param(cx: @ext_ctxt,
ident: ast::ident,
bounds: @OptVec<ast::TyParamBound>)
-> ast::TyParam {
ast::TyParam { ident: ident, id: cx.next_id(), bounds: bounds }
}
-pub fn mk_lifetime(cx: ext_ctxt,
+pub fn mk_lifetime(cx: @ext_ctxt,
span: span,
ident: ast::ident) -> ast::Lifetime
{
use ext::base;
use parse::token;
-pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let mut res_str = ~"";
for tts.eachi |i, e| {
}
}
-type ExpandDerivingStructDefFn = &self/fn(ext_ctxt,
+type ExpandDerivingStructDefFn = &self/fn(@ext_ctxt,
span,
x: &struct_def,
ident,
y: &Generics) -> @item;
-type ExpandDerivingEnumDefFn = &self/fn(ext_ctxt,
+type ExpandDerivingEnumDefFn = &self/fn(@ext_ctxt,
span,
x: &enum_def,
ident,
y: &Generics) -> @item;
-pub fn expand_meta_deriving(cx: ext_ctxt,
+pub fn expand_meta_deriving(cx: @ext_ctxt,
_span: span,
mitem: @meta_item,
in_items: ~[@item])
}
}
-pub fn expand_deriving_eq(cx: ext_ctxt,
+pub fn expand_deriving_eq(cx: @ext_ctxt,
span: span,
_mitem: @meta_item,
in_items: ~[@item])
expand_deriving_eq_enum_def)
}
-pub fn expand_deriving_iter_bytes(cx: ext_ctxt,
+pub fn expand_deriving_iter_bytes(cx: @ext_ctxt,
span: span,
_mitem: @meta_item,
in_items: ~[@item])
expand_deriving_iter_bytes_enum_def)
}
-pub fn expand_deriving_clone(cx: ext_ctxt,
+pub fn expand_deriving_clone(cx: @ext_ctxt,
span: span,
_: @meta_item,
in_items: ~[@item])
expand_deriving_clone_enum_def)
}
-fn expand_deriving(cx: ext_ctxt,
+fn expand_deriving(cx: @ext_ctxt,
span: span,
in_items: ~[@item],
expand_deriving_struct_def: ExpandDerivingStructDefFn,
result
}
-fn create_impl_item(cx: ext_ctxt, span: span, +item: item_) -> @item {
+fn create_impl_item(cx: @ext_ctxt, span: span, +item: item_) -> @item {
@ast::item {
ident: clownshoes_extensions,
attrs: ~[],
/// Creates a method from the given expression, the signature of which
/// conforms to the `eq` or `ne` method.
-fn create_eq_method(cx: ext_ctxt,
+fn create_eq_method(cx: @ext_ctxt,
span: span,
method_ident: ident,
type_ident: ident,
}
}
-fn create_self_type_with_params(cx: ext_ctxt,
+fn create_self_type_with_params(cx: @ext_ctxt,
span: span,
type_ident: ident,
generics: &Generics)
@ast::Ty { id: cx.next_id(), node: self_type, span: span }
}
-fn create_derived_impl(cx: ext_ctxt,
+fn create_derived_impl(cx: @ext_ctxt,
span: span,
type_ident: ident,
generics: &Generics,
return create_impl_item(cx, span, impl_item);
}
-fn create_derived_eq_impl(cx: ext_ctxt,
+fn create_derived_eq_impl(cx: @ext_ctxt,
span: span,
type_ident: ident,
generics: &Generics,
create_derived_impl(cx, span, type_ident, generics, methods, trait_path)
}
-fn create_derived_iter_bytes_impl(cx: ext_ctxt,
+fn create_derived_iter_bytes_impl(cx: @ext_ctxt,
span: span,
type_ident: ident,
generics: &Generics,
create_derived_impl(cx, span, type_ident, generics, methods, trait_path)
}
-fn create_derived_clone_impl(cx: ext_ctxt,
+fn create_derived_clone_impl(cx: @ext_ctxt,
span: span,
type_ident: ident,
generics: &Generics,
// Creates a method from the given set of statements conforming to the
// signature of the `iter_bytes` method.
-fn create_iter_bytes_method(cx: ext_ctxt,
+fn create_iter_bytes_method(cx: @ext_ctxt,
span: span,
+statements: ~[@stmt])
-> @method {
// Creates a method from the given expression conforming to the signature of
// the `clone` method.
-fn create_clone_method(cx: ext_ctxt,
+fn create_clone_method(cx: @ext_ctxt,
span: span,
+type_ident: ast::ident,
generics: &Generics,
}
}
-fn create_subpatterns(cx: ext_ctxt,
+fn create_subpatterns(cx: @ext_ctxt,
span: span,
prefix: ~str,
n: uint)
})
}
-fn create_enum_variant_pattern(cx: ext_ctxt,
+fn create_enum_variant_pattern(cx: @ext_ctxt,
span: span,
variant: &variant,
prefix: ~str)
}
}
-fn call_substructure_eq_method(cx: ext_ctxt,
+fn call_substructure_eq_method(cx: @ext_ctxt,
span: span,
self_field: @expr,
other_field_ref: @expr,
};
}
-fn finish_eq_chain_expr(cx: ext_ctxt,
+fn finish_eq_chain_expr(cx: @ext_ctxt,
span: span,
chain_expr: Option<@expr>,
junction: Junction)
}
}
-fn call_substructure_iter_bytes_method(cx: ext_ctxt,
+fn call_substructure_iter_bytes_method(cx: @ext_ctxt,
span: span,
self_field: @expr)
-> @stmt {
build::mk_stmt(cx, span, self_call)
}
-fn call_substructure_clone_method(cx: ext_ctxt,
+fn call_substructure_clone_method(cx: @ext_ctxt,
span: span,
self_field: @expr)
-> @expr {
build::mk_call_(cx, span, self_method, ~[])
}
-fn variant_arg_count(cx: ext_ctxt, span: span, variant: &variant) -> uint {
+fn variant_arg_count(cx: @ext_ctxt, span: span, variant: &variant) -> uint {
match variant.node.kind {
tuple_variant_kind(ref args) => args.len(),
struct_variant_kind(ref struct_def) => struct_def.fields.len(),
}
}
-fn expand_deriving_eq_struct_def(cx: ext_ctxt,
+fn expand_deriving_eq_struct_def(cx: @ext_ctxt,
span: span,
struct_def: &struct_def,
type_ident: ident,
ne_method);
}
-fn expand_deriving_eq_enum_def(cx: ext_ctxt,
+fn expand_deriving_eq_enum_def(cx: @ext_ctxt,
span: span,
enum_definition: &enum_def,
type_ident: ident,
ne_method);
}
-fn expand_deriving_iter_bytes_struct_def(cx: ext_ctxt,
+fn expand_deriving_iter_bytes_struct_def(cx: @ext_ctxt,
span: span,
struct_def: &struct_def,
type_ident: ident,
method);
}
-fn expand_deriving_iter_bytes_enum_def(cx: ext_ctxt,
+fn expand_deriving_iter_bytes_enum_def(cx: @ext_ctxt,
span: span,
enum_definition: &enum_def,
type_ident: ident,
method);
}
-fn expand_deriving_clone_struct_def(cx: ext_ctxt,
+fn expand_deriving_clone_struct_def(cx: @ext_ctxt,
span: span,
struct_def: &struct_def,
type_ident: ident,
create_derived_clone_impl(cx, span, type_ident, generics, method)
}
-fn expand_deriving_clone_enum_def(cx: ext_ctxt,
+fn expand_deriving_clone_enum_def(cx: @ext_ctxt,
span: span,
enum_definition: &enum_def,
type_ident: ident,
create_derived_clone_impl(cx, span, type_ident, generics, method)
}
-fn expand_deriving_eq_struct_method(cx: ext_ctxt,
+fn expand_deriving_eq_struct_method(cx: @ext_ctxt,
span: span,
struct_def: &struct_def,
method_ident: ident,
body);
}
-fn expand_deriving_iter_bytes_struct_method(cx: ext_ctxt,
+fn expand_deriving_iter_bytes_struct_method(cx: @ext_ctxt,
span: span,
struct_def: &struct_def)
-> @method {
return create_iter_bytes_method(cx, span, statements);
}
-fn expand_deriving_clone_struct_method(cx: ext_ctxt,
+fn expand_deriving_clone_struct_method(cx: @ext_ctxt,
span: span,
struct_def: &struct_def,
type_ident: ident,
create_clone_method(cx, span, type_ident, generics, struct_literal)
}
-fn expand_deriving_clone_tuple_struct_method(cx: ext_ctxt,
+fn expand_deriving_clone_tuple_struct_method(cx: @ext_ctxt,
span: span,
struct_def: &struct_def,
type_ident: ident,
create_clone_method(cx, span, type_ident, generics, self_match_expr)
}
-fn expand_deriving_eq_enum_method(cx: ext_ctxt,
+fn expand_deriving_eq_enum_method(cx: @ext_ctxt,
span: span,
enum_definition: &enum_def,
method_ident: ident,
self_match_expr);
}
-fn expand_deriving_eq_struct_tuple_method(cx: ext_ctxt,
+fn expand_deriving_eq_struct_tuple_method(cx: @ext_ctxt,
span: span,
struct_def: &struct_def,
method_ident: ident,
type_ident, generics, self_match_expr)
}
-fn expand_enum_or_struct_match(cx: ext_ctxt,
+fn expand_enum_or_struct_match(cx: @ext_ctxt,
span: span,
arms: ~[ ast::arm ])
-> @expr {
build::mk_expr(cx, span, self_match_expr)
}
-fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt,
+fn expand_deriving_iter_bytes_enum_method(cx: @ext_ctxt,
span: span,
enum_definition: &enum_def)
-> @method {
create_iter_bytes_method(cx, span, ~[ self_match_stmt ])
}
-fn expand_deriving_clone_enum_method(cx: ext_ctxt,
+fn expand_deriving_clone_enum_method(cx: @ext_ctxt,
span: span,
enum_definition: &enum_def,
type_ident: ident,
use ext::base;
use ext::build::mk_uniq_str;
-pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let var = get_single_str_from_tts(cx, sp, tts, "env!");
use core::vec;
pub fn expand_expr(extsbox: @mut SyntaxEnv,
- cx: ext_ctxt,
+ cx: @ext_ctxt,
e: &expr_,
s: span,
- fld: ast_fold,
- orig: @fn(&expr_, span, ast_fold) -> (expr_, span))
+ fld: @ast_fold,
+ orig: @fn(&expr_, span, @ast_fold) -> (expr_, span))
-> (expr_, span) {
match *e {
// expr_mac should really be expr_ext or something; it's the
// NB: there is some redundancy between this and expand_item, below, and
// they might benefit from some amount of semantic and language-UI merger.
pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
- cx: ext_ctxt,
+ cx: @ext_ctxt,
module_: &ast::_mod,
- fld: ast_fold,
- orig: @fn(&ast::_mod, ast_fold) -> ast::_mod)
+ fld: @ast_fold,
+ orig: @fn(&ast::_mod, @ast_fold) -> ast::_mod)
-> ast::_mod {
// Fold the contents first:
let module_ = orig(module_, fld);
// When we enter a module, record it, for the sake of `module!`
pub fn expand_item(extsbox: @mut SyntaxEnv,
- cx: ext_ctxt,
+ cx: @ext_ctxt,
it: @ast::item,
- fld: ast_fold,
- orig: @fn(@ast::item, ast_fold) -> Option<@ast::item>)
+ fld: @ast_fold,
+ orig: @fn(@ast::item, @ast_fold) -> Option<@ast::item>)
-> Option<@ast::item> {
// need to do expansion first... it might turn out to be a module.
let maybe_it = match it.node {
// Support for item-position macro invocations, exactly the same
// logic as for expression-position macro invocations.
pub fn expand_item_mac(+extsbox: @mut SyntaxEnv,
- cx: ext_ctxt, &&it: @ast::item,
- fld: ast_fold) -> Option<@ast::item> {
-
+ cx: @ext_ctxt, &&it: @ast::item,
+ fld: @ast_fold)
+ -> Option<@ast::item> {
let (pth, tts) = match it.node {
item_mac(codemap::spanned { node: mac_invoc_tt(pth, ref tts), _}) => {
(pth, copy *tts)
// expand a stmt
pub fn expand_stmt(extsbox: @mut SyntaxEnv,
- cx: ext_ctxt,
+ cx: @ext_ctxt,
s: &stmt_,
sp: span,
- fld: ast_fold,
- orig: @fn(&stmt_, span, ast_fold) -> (stmt_, span))
+ fld: @ast_fold,
+ orig: @fn(&stmt_, span, @ast_fold) -> (stmt_, span))
-> (stmt_, span) {
let (mac, pth, tts, semi) = match *s {
stmt_mac(ref mac, semi) => {
pub fn expand_block(extsbox: @mut SyntaxEnv,
- cx: ext_ctxt,
+ cx: @ext_ctxt,
blk: &blk_,
sp: span,
- fld: ast_fold,
- orig: @fn(&blk_, span, ast_fold) -> (blk_, span))
+ fld: @ast_fold,
+ orig: @fn(&blk_, span, @ast_fold) -> (blk_, span))
-> (blk_, span) {
match (*extsbox).find(&@~" block") {
// no scope limit on macros in this block, no need
}
}
-pub fn new_span(cx: ext_ctxt, sp: span) -> span {
+pub fn new_span(cx: @ext_ctxt, sp: span) -> span {
/* this discards information in the case of macro-defining macros */
return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
}
// every method/element of AstFoldFns in fold.rs.
let extsbox = @mut syntax_expander_table();
let afp = default_ast_fold();
- let cx: ext_ctxt = mk_ctxt(parse_sess, copy cfg);
+ let cx: @ext_ctxt = mk_ctxt(parse_sess, copy cfg);
let f_pre = @AstFoldFns {
fold_expr: |expr,span,recur|
expand_expr(extsbox, cx, expr, span, recur, afp.fold_expr),
use core::unstable::extfmt::ct::*;
-pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let args = get_exprs_from_tts(cx, tts);
if args.len() == 0 {
~"first argument to fmt! must be a string literal.");
let fmtspan = args[0].span;
debug!("Format string: %s", fmt);
- fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: &str) -> ! {
+ fn parse_fmt_err_(cx: @ext_ctxt, sp: span, msg: &str) -> ! {
cx.span_fatal(sp, msg);
}
let parse_fmt_err: @fn(&str) -> ! = |s| parse_fmt_err_(cx, fmtspan, s);
// probably be factored out in common with other code that builds
// expressions. Also: Cleanup the naming of these functions.
// Note: Moved many of the common ones to build.rs --kevina
-fn pieces_to_expr(cx: ext_ctxt, sp: span,
+fn pieces_to_expr(cx: @ext_ctxt, sp: span,
pieces: ~[Piece], args: ~[@ast::expr])
-> @ast::expr {
- fn make_path_vec(cx: ext_ctxt, ident: @~str) -> ~[ast::ident] {
+ fn make_path_vec(cx: @ext_ctxt, ident: @~str) -> ~[ast::ident] {
let intr = cx.parse_sess().interner;
return ~[intr.intern(@~"unstable"), intr.intern(@~"extfmt"),
intr.intern(@~"rt"), intr.intern(ident)];
}
- fn make_rt_path_expr(cx: ext_ctxt, sp: span, nm: @~str) -> @ast::expr {
+ fn make_rt_path_expr(cx: @ext_ctxt, sp: span, nm: @~str) -> @ast::expr {
let path = make_path_vec(cx, nm);
return mk_path_global(cx, sp, path);
}
// Produces an AST expression that represents a RT::conv record,
// which tells the RT::conv* functions how to perform the conversion
- fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: Conv) -> @ast::expr {
- fn make_flags(cx: ext_ctxt, sp: span, flags: ~[Flag]) -> @ast::expr {
+ fn make_rt_conv_expr(cx: @ext_ctxt, sp: span, cnv: Conv) -> @ast::expr {
+ fn make_flags(cx: @ext_ctxt, sp: span, flags: ~[Flag]) -> @ast::expr {
let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none");
for flags.each |f| {
let fstr = match *f {
}
return tmp_expr;
}
- fn make_count(cx: ext_ctxt, sp: span, cnt: Count) -> @ast::expr {
+ fn make_count(cx: @ext_ctxt, sp: span, cnt: Count) -> @ast::expr {
match cnt {
CountImplied => {
return make_rt_path_expr(cx, sp, @~"CountImplied");
_ => cx.span_unimpl(sp, ~"unimplemented fmt! conversion")
}
}
- fn make_ty(cx: ext_ctxt, sp: span, t: Ty) -> @ast::expr {
+ fn make_ty(cx: @ext_ctxt, sp: span, t: Ty) -> @ast::expr {
let mut rt_type;
match t {
TyHex(c) => match c {
}
return make_rt_path_expr(cx, sp, @rt_type);
}
- fn make_conv_struct(cx: ext_ctxt, sp: span, flags_expr: @ast::expr,
+ fn make_conv_struct(cx: @ext_ctxt, sp: span, flags_expr: @ast::expr,
width_expr: @ast::expr, precision_expr: @ast::expr,
ty_expr: @ast::expr) -> @ast::expr {
let intr = cx.parse_sess().interner;
make_conv_struct(cx, sp, rt_conv_flags, rt_conv_width,
rt_conv_precision, rt_conv_ty)
}
- fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: ~str, cnv: Conv,
+ fn make_conv_call(cx: @ext_ctxt, sp: span, conv_type: ~str, cnv: Conv,
arg: @ast::expr) -> @ast::expr {
let fname = ~"conv_" + conv_type;
let path = make_path_vec(cx, @fname);
return mk_call_global(cx, arg.span, path, args);
}
- fn make_new_conv(cx: ext_ctxt, sp: span, cnv: Conv, arg: @ast::expr) ->
+ fn make_new_conv(cx: @ext_ctxt, sp: span, cnv: Conv, arg: @ast::expr) ->
@ast::expr {
// FIXME: Move validation code into core::extfmt (Issue #2249)
use ext::base;
use print;
-pub fn expand_syntax_ext(cx: ext_ctxt,
+pub fn expand_syntax_ext(cx: @ext_ctxt,
sp: codemap::span,
tt: &[ast::token_tree])
-> base::MacResult {
fn strip_bounds(&self, bounds: &Generics) -> Generics;
}
-impl ext_ctxt_ast_builder for ext_ctxt {
+impl ext_ctxt_ast_builder for @ext_ctxt {
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty {
self.ty_path_ast_builder(path_global(~[
self.ident_of(~"core"),
use ext::pipes::proto::{state, protocol, next_state};
use ext::pipes::proto;
-impl proto::visitor<(), (), ()> for ext_ctxt {
- fn visit_proto(&self, _proto: protocol,
- _states: &[()]) { }
+impl proto::visitor<(), (), ()> for @ext_ctxt {
+ fn visit_proto(&self, _proto: protocol, _states: &[()]) { }
fn visit_state(&self, state: state, _m: &[()]) {
if state.messages.len() == 0 {
use core::str;
use std::bitv::Bitv;
-pub fn analyze(proto: protocol, _cx: ext_ctxt) {
+pub fn analyze(proto: protocol, _cx: @ext_ctxt) {
debug!("initializing colive analysis");
let num_states = proto.num_states();
let mut colive = do (copy proto.states).map_to_vec |state| {
pub mod liveness;
-pub fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
+pub fn expand_proto(cx: @ext_ctxt, _sp: span, id: ast::ident,
tt: ~[ast::token_tree]) -> base::MacResult {
let sess = cx.parse_sess();
let cfg = cx.cfg();
let tt_rdr = new_tt_reader(copy cx.parse_sess().span_diagnostic,
- cx.parse_sess().interner, None, copy tt);
- let rdr = tt_rdr as reader;
+ cx.parse_sess().interner,
+ None,
+ copy tt);
+ let rdr = tt_rdr as @reader;
let rust_parser = Parser(sess, cfg, rdr.dup());
let mut proto = rust_parser.parse_proto(cx.str_of(id));
use core::vec;
pub trait gen_send {
- fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item;
- fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty;
+ fn gen_send(&mut self, cx: @ext_ctxt, try: bool) -> @ast::item;
+ fn to_ty(&mut self, cx: @ext_ctxt) -> @ast::Ty;
}
pub trait to_type_decls {
- fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item];
- fn to_endpoint_decls(&self, cx: ext_ctxt,
+ fn to_type_decls(&self, cx: @ext_ctxt) -> ~[@ast::item];
+ fn to_endpoint_decls(&self, cx: @ext_ctxt,
dir: direction) -> ~[@ast::item];
}
pub trait gen_init {
- fn gen_init(&self, cx: ext_ctxt) -> @ast::item;
- fn compile(&self, cx: ext_ctxt) -> @ast::item;
- fn buffer_ty_path(&self, cx: ext_ctxt) -> @ast::Ty;
- fn gen_buffer_type(&self, cx: ext_ctxt) -> @ast::item;
- fn gen_buffer_init(&self, ext_cx: ext_ctxt) -> @ast::expr;
- fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr;
+ fn gen_init(&self, cx: @ext_ctxt) -> @ast::item;
+ fn compile(&self, cx: @ext_ctxt) -> @ast::item;
+ fn buffer_ty_path(&self, cx: @ext_ctxt) -> @ast::Ty;
+ fn gen_buffer_type(&self, cx: @ext_ctxt) -> @ast::item;
+ fn gen_buffer_init(&self, ext_cx: @ext_ctxt) -> @ast::expr;
+ fn gen_init_bounded(&self, ext_cx: @ext_ctxt) -> @ast::expr;
}
impl gen_send for message {
- fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item {
+ fn gen_send(&mut self, cx: @ext_ctxt, try: bool) -> @ast::item {
debug!("pipec: gen_send");
let name = self.name();
}
}
- fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty {
+ fn to_ty(&mut self, cx: @ext_ctxt) -> @ast::Ty {
cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span())
.add_tys(cx.ty_vars_global(&self.get_generics().ty_params)))
}
}
impl to_type_decls for state {
- fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item] {
+ fn to_type_decls(&self, cx: @ext_ctxt) -> ~[@ast::item] {
debug!("pipec: to_type_decls");
// This compiles into two different type declarations. Say the
// state is called ping. This will generate both `ping` and
]
}
- fn to_endpoint_decls(&self, cx: ext_ctxt,
+ fn to_endpoint_decls(&self, cx: @ext_ctxt,
dir: direction) -> ~[@ast::item] {
debug!("pipec: to_endpoint_decls");
let dir = match dir {
}
impl gen_init for protocol {
- fn gen_init(&self, cx: ext_ctxt) -> @ast::item {
+ fn gen_init(&self, cx: @ext_ctxt) -> @ast::item {
let ext_cx = cx;
debug!("gen_init");
body.to_source(cx)))
}
- fn gen_buffer_init(&self, ext_cx: ext_ctxt) -> @ast::expr {
+ fn gen_buffer_init(&self, ext_cx: @ext_ctxt) -> @ast::expr {
ext_cx.struct_expr(path(~[ext_cx.ident_of(~"__Buffer")],
dummy_sp()),
self.states.map_to_vec(|s| {
}))
}
- fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr {
+ fn gen_init_bounded(&self, ext_cx: @ext_ctxt) -> @ast::expr {
debug!("gen_init_bounded");
let buffer_fields = self.gen_buffer_init(ext_cx);
let buffer = quote_expr!(~::core::pipes::Buffer {
})
}
- fn buffer_ty_path(&self, cx: ext_ctxt) -> @ast::Ty {
+ fn buffer_ty_path(&self, cx: @ext_ctxt) -> @ast::Ty {
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
for (copy self.states).each |s| {
for s.generics.ty_params.each |tp| {
.add_tys(cx.ty_vars_global(¶ms)))
}
- fn gen_buffer_type(&self, cx: ext_ctxt) -> @ast::item {
+ fn gen_buffer_type(&self, cx: @ext_ctxt) -> @ast::item {
let ext_cx = cx;
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
let fields = do (copy self.states).map_to_vec |s| {
cx.strip_bounds(&generics))
}
- fn compile(&self, cx: ext_ctxt) -> @ast::item {
+ fn compile(&self, cx: @ext_ctxt) -> @ast::item {
let mut items = ~[self.gen_init(cx)];
let mut client_states = ~[];
let mut server_states = ~[];
}
/// Returns the type that is used for the messages.
- fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty {
+ fn to_ty(&self, cx: @ext_ctxt) -> @ast::Ty {
cx.ty_path_ast_builder
(path(~[cx.ident_of(self.name)],self.span).add_tys(
cx.ty_vars(&self.generics.ty_params)))
use print::pprust::{item_to_str, ty_to_str};
pub trait ToTokens {
- pub fn to_tokens(&self, _cx: ext_ctxt) -> ~[token_tree];
+ pub fn to_tokens(&self, _cx: @ext_ctxt) -> ~[token_tree];
}
impl ToTokens for ~[token_tree] {
- pub fn to_tokens(&self, _cx: ext_ctxt) -> ~[token_tree] {
+ pub fn to_tokens(&self, _cx: @ext_ctxt) -> ~[token_tree] {
copy *self
}
}
trait ToSource : ToTokens {
// Takes a thing and generates a string containing rust code for it.
- pub fn to_source(cx: ext_ctxt) -> ~str;
+ pub fn to_source(cx: @ext_ctxt) -> ~str;
// If you can make source, you can definitely make tokens.
- pub fn to_tokens(cx: ext_ctxt) -> ~[token_tree] {
+ pub fn to_tokens(cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
pub trait ToSource {
// Takes a thing and generates a string containing rust code for it.
- pub fn to_source(&self, cx: ext_ctxt) -> ~str;
+ pub fn to_source(&self, cx: @ext_ctxt) -> ~str;
}
impl ToSource for ast::ident {
- fn to_source(&self, cx: ext_ctxt) -> ~str {
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
copy *cx.parse_sess().interner.get(*self)
}
}
impl ToSource for @ast::item {
- fn to_source(&self, cx: ext_ctxt) -> ~str {
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
item_to_str(*self, cx.parse_sess().interner)
}
}
impl ToSource for ~[@ast::item] {
- fn to_source(&self, cx: ext_ctxt) -> ~str {
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
str::connect(self.map(|i| i.to_source(cx)), ~"\n\n")
}
}
impl ToSource for @ast::Ty {
- fn to_source(&self, cx: ext_ctxt) -> ~str {
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
ty_to_str(*self, cx.parse_sess().interner)
}
}
impl ToSource for ~[@ast::Ty] {
- fn to_source(&self, cx: ext_ctxt) -> ~str {
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
str::connect(self.map(|i| i.to_source(cx)), ~", ")
}
}
impl ToSource for Generics {
- fn to_source(&self, cx: ext_ctxt) -> ~str {
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
pprust::generics_to_str(self, cx.parse_sess().interner)
}
}
impl ToSource for @ast::expr {
- fn to_source(&self, cx: ext_ctxt) -> ~str {
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
pprust::expr_to_str(*self, cx.parse_sess().interner)
}
}
// Alas ... we write these out instead. All redundant.
impl ToTokens for ast::ident {
- fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
impl ToTokens for @ast::item {
- fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
impl ToTokens for ~[@ast::item] {
- fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
impl ToTokens for @ast::Ty {
- fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
impl ToTokens for ~[@ast::Ty] {
- fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
impl ToTokens for Generics {
- fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
impl ToTokens for @ast::expr {
- fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
cx.parse_tts(self.to_source(cx))
}
}
fn parse_tts(&self, s: ~str) -> ~[ast::token_tree];
}
- impl ExtParseUtils for ext_ctxt {
+ impl ExtParseUtils for @ext_ctxt {
fn parse_item(&self, s: ~str) -> @ast::item {
let res = parse::parse_item_from_source_str(
}
-pub fn expand_quote_tokens(cx: ext_ctxt,
+pub fn expand_quote_tokens(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree]) -> base::MacResult {
base::MRExpr(expand_tts(cx, sp, tts))
}
-pub fn expand_quote_expr(cx: ext_ctxt,
+pub fn expand_quote_expr(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree]) -> base::MacResult {
base::MRExpr(expand_parse_call(cx, sp, ~"parse_expr", ~[], tts))
}
-pub fn expand_quote_item(cx: ext_ctxt,
+pub fn expand_quote_item(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]);
~[e_attrs], tts))
}
-pub fn expand_quote_pat(cx: ext_ctxt,
+pub fn expand_quote_pat(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true));
~[e_refutable], tts))
}
-pub fn expand_quote_ty(cx: ext_ctxt,
+pub fn expand_quote_ty(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false));
~[e_param_colons], tts))
}
-pub fn expand_quote_stmt(cx: ext_ctxt,
+pub fn expand_quote_stmt(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]);
~[e_attrs], tts))
}
-fn ids_ext(cx: ext_ctxt, strs: ~[~str]) -> ~[ast::ident] {
+fn ids_ext(cx: @ext_ctxt, strs: ~[~str]) -> ~[ast::ident] {
strs.map(|str| cx.parse_sess().interner.intern(@copy *str))
}
-fn id_ext(cx: ext_ctxt, +str: ~str) -> ast::ident {
+fn id_ext(cx: @ext_ctxt, +str: ~str) -> ast::ident {
cx.parse_sess().interner.intern(@str)
}
// Lift an ident to the expr that evaluates to that ident.
-fn mk_ident(cx: ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr {
+fn mk_ident(cx: @ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr {
let e_meth = build::mk_access(cx, sp,
ids_ext(cx, ~[~"ext_cx"]),
id_ext(cx, ~"ident_of"));
build::mk_call_(cx, sp, e_meth, ~[e_str])
}
-fn mk_bytepos(cx: ext_ctxt, sp: span, bpos: BytePos) -> @ast::expr {
+fn mk_bytepos(cx: @ext_ctxt, sp: span, bpos: BytePos) -> @ast::expr {
let path = ids_ext(cx, ~[~"BytePos"]);
let arg = build::mk_uint(cx, sp, bpos.to_uint());
build::mk_call(cx, sp, path, ~[arg])
}
-fn mk_binop(cx: ext_ctxt, sp: span, bop: token::binop) -> @ast::expr {
+fn mk_binop(cx: @ext_ctxt, sp: span, bop: token::binop) -> @ast::expr {
let name = match bop {
PLUS => "PLUS",
MINUS => "MINUS",
ids_ext(cx, ~[name.to_owned()]))
}
-fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr {
+fn mk_token(cx: @ext_ctxt, sp: span, tok: token::Token) -> @ast::expr {
match tok {
BINOP(binop) => {
}
-fn mk_tt(cx: ext_ctxt, sp: span, tt: &ast::token_tree)
+fn mk_tt(cx: @ext_ctxt, sp: span, tt: &ast::token_tree)
-> ~[@ast::stmt] {
match *tt {
}
}
-fn mk_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+fn mk_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> ~[@ast::stmt] {
let mut ss = ~[];
for tts.each |tt| {
ss
}
-fn expand_tts(cx: ext_ctxt,
+fn expand_tts(cx: @ext_ctxt,
sp: span,
tts: &[ast::token_tree]) -> @ast::expr {
ids_ext(cx, ~[~"tt"]))))
}
-fn expand_parse_call(cx: ext_ctxt,
+fn expand_parse_call(cx: @ext_ctxt,
sp: span,
+parse_method: ~str,
+arg_exprs: ~[@ast::expr],
// a given file into the current one.
/* line!(): expands to the current line number */
-pub fn expand_line(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_line(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "line!");
}
/* col!(): expands to the current column number */
-pub fn expand_col(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_col(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "col!");
/* file!(): expands to the current filename */
/* The filemap (`loc.file`) contains a bunch more information we could spit
* out if we wanted. */
-pub fn expand_file(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_file(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "file!");
base::MRExpr(mk_base_str(cx, topmost.call_site, filename))
}
-pub fn expand_stringify(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_stringify(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let s = pprust::tts_to_str(tts, cx.parse_sess().interner);
base::MRExpr(mk_base_str(cx, sp, s))
}
-pub fn expand_mod(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_mod(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "module_path!");
base::MRExpr(mk_base_str(cx, sp,
// include! : parse the given file as an expr
// This is generally a bad idea because it's going to behave
// unhygienically.
-pub fn expand_include(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_include(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let file = get_single_str_from_tts(cx, sp, tts, "include!");
let p = parse::new_sub_parser_from_file(
}
// include_str! : read the given file, insert it as a literal string expr
-pub fn expand_include_str(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_include_str(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file)));
base::MRExpr(mk_base_str(cx, sp, result::unwrap(res)))
}
-pub fn expand_include_bin(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
+pub fn expand_include_bin(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) {
// resolve a file-system path to an absolute file-system path (if it
// isn't already)
-fn res_rel_file(cx: ext_ctxt, sp: codemap::span, arg: &Path) -> Path {
+fn res_rel_file(cx: @ext_ctxt, sp: codemap::span, arg: &Path) -> Path {
// NB: relative paths are resolved relative to the compilation unit
if !arg.is_absolute {
let cu = Path(cx.codemap().span_to_filename(sp));
use parse::lexer::{new_tt_reader, reader};
use parse::parser::Parser;
-pub fn expand_trace_macros(cx: ext_ctxt, sp: span,
- tt: &[ast::token_tree]) -> base::MacResult {
+pub fn expand_trace_macros(cx: @ext_ctxt,
+ sp: span,
+ tt: &[ast::token_tree])
+ -> base::MacResult {
let sess = cx.parse_sess();
let cfg = cx.cfg();
let tt_rdr = new_tt_reader(
None,
vec::from_slice(tt)
);
- let rdr = tt_rdr as reader;
+ let rdr = tt_rdr as @reader;
let rust_parser = Parser(
sess,
copy cfg,
pub fn parse_or_else(
sess: @mut ParseSess,
+cfg: ast::crate_cfg,
- rdr: reader,
+ rdr: @reader,
ms: ~[matcher]
) -> HashMap<ident, @named_match> {
match parse(sess, cfg, rdr, ms) {
pub fn parse(
sess: @mut ParseSess,
cfg: ast::crate_cfg,
- rdr: reader,
+ rdr: @reader,
ms: ~[matcher]
) -> parse_result {
let mut cur_eis = ~[];
use core::io;
-pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
- arg: ~[ast::token_tree]) -> base::MacResult {
+pub fn add_new_extension(cx: @ext_ctxt,
+ sp: span,
+ name: ident,
+ arg: ~[ast::token_tree])
+ -> base::MacResult {
// these spans won't matter, anyways
fn ms(m: matcher_) -> matcher {
spanned { node: copy m, span: dummy_sp() }
// Parse the macro_rules! invocation (`none` is for no interpolations):
let arg_reader = new_tt_reader(copy cx.parse_sess().span_diagnostic,
cx.parse_sess().interner, None, copy arg);
- let argument_map = parse_or_else(cx.parse_sess(), cx.cfg(),
- arg_reader as reader, argument_gram);
+ let argument_map = parse_or_else(cx.parse_sess(),
+ cx.cfg(),
+ arg_reader as @reader,
+ argument_gram);
// Extract the arguments:
let lhses = match argument_map.get(&lhs_nm) {
};
// Given `lhses` and `rhses`, this is the new macro we create
- fn generic_extension(cx: ext_ctxt, sp: span, name: ident,
+ fn generic_extension(cx: @ext_ctxt, sp: span, name: ident,
arg: &[ast::token_tree],
lhses: ~[@named_match], rhses: ~[@named_match])
-> MacResult {
itr,
None,
vec::from_slice(arg)
- ) as reader;
+ ) as @reader;
match parse(cx.parse_sess(), cx.cfg(), arg_rdr, (*mtcs)) {
success(named_matches) => {
let rhs = match rhses[i] {
// rhs has holes ( `$id` and `$(...)` that need filled)
let trncbr = new_tt_reader(s_d, itr, Some(named_matches),
rhs);
- let p = @Parser(cx.parse_sess(), cx.cfg(),
- trncbr as reader);
+ let p = @Parser(cx.parse_sess(),
+ cx.cfg(),
+ trncbr as @reader);
// Let the context choose how to interpret the result.
// Weird, but useful for X-macros.
cx.span_fatal(best_fail_spot, best_fail_msg);
}
- let exp: @fn(ext_ctxt, span, &[ast::token_tree]) -> MacResult =
+ let exp: @fn(@ext_ctxt, span, &[ast::token_tree]) -> MacResult =
|cx, sp, arg| generic_extension(cx, sp, name, arg, lhses, rhses);
return MRDef(MacroDef{
}
pub struct TtReader {
- sp_diag: span_handler,
+ sp_diag: @span_handler,
interner: @ident_interner,
// the unzipped tree:
cur: @mut TtFrame,
/** This can do Macro-By-Example transcription. On the other hand, if
* `src` contains no `tt_seq`s and `tt_nonterminal`s, `interp` can (and
* should) be none. */
-pub fn new_tt_reader(sp_diag: span_handler,
+pub fn new_tt_reader(sp_diag: @span_handler,
itr: @ident_interner,
interp: Option<std::oldmap::HashMap<ident,@named_match>>,
+src: ~[ast::token_tree])
pub struct AstFoldFns {
//unlike the others, item_ is non-trivial
- fold_crate: @fn(&crate_, span, ast_fold) -> (crate_, span),
- fold_view_item: @fn(view_item_, ast_fold) -> view_item_,
- fold_foreign_item: @fn(@foreign_item, ast_fold) -> @foreign_item,
- fold_item: @fn(@item, ast_fold) -> Option<@item>,
- fold_struct_field: @fn(@struct_field, ast_fold) -> @struct_field,
- fold_item_underscore: @fn(&item_, ast_fold) -> item_,
- fold_method: @fn(@method, ast_fold) -> @method,
- fold_block: @fn(&blk_, span, ast_fold) -> (blk_, span),
- fold_stmt: @fn(&stmt_, span, ast_fold) -> (stmt_, span),
- fold_arm: @fn(&arm, ast_fold) -> arm,
- fold_pat: @fn(&pat_, span, ast_fold) -> (pat_, span),
- fold_decl: @fn(&decl_, span, ast_fold) -> (decl_, span),
- fold_expr: @fn(&expr_, span, ast_fold) -> (expr_, span),
- fold_ty: @fn(&ty_, span, ast_fold) -> (ty_, span),
- fold_mod: @fn(&_mod, ast_fold) -> _mod,
- fold_foreign_mod: @fn(&foreign_mod, ast_fold) -> foreign_mod,
- fold_variant: @fn(&variant_, span, ast_fold) -> (variant_, span),
- fold_ident: @fn(ident, ast_fold) -> ident,
- fold_path: @fn(@path, ast_fold) -> path,
- fold_local: @fn(&local_, span, ast_fold) -> (local_, span),
+ fold_crate: @fn(&crate_, span, @ast_fold) -> (crate_, span),
+ fold_view_item: @fn(view_item_, @ast_fold) -> view_item_,
+ fold_foreign_item: @fn(@foreign_item, @ast_fold) -> @foreign_item,
+ fold_item: @fn(@item, @ast_fold) -> Option<@item>,
+ fold_struct_field: @fn(@struct_field, @ast_fold) -> @struct_field,
+ fold_item_underscore: @fn(&item_, @ast_fold) -> item_,
+ fold_method: @fn(@method, @ast_fold) -> @method,
+ fold_block: @fn(&blk_, span, @ast_fold) -> (blk_, span),
+ fold_stmt: @fn(&stmt_, span, @ast_fold) -> (stmt_, span),
+ fold_arm: @fn(&arm, @ast_fold) -> arm,
+ fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span),
+ fold_decl: @fn(&decl_, span, @ast_fold) -> (decl_, span),
+ fold_expr: @fn(&expr_, span, @ast_fold) -> (expr_, span),
+ fold_ty: @fn(&ty_, span, @ast_fold) -> (ty_, span),
+ fold_mod: @fn(&_mod, @ast_fold) -> _mod,
+ fold_foreign_mod: @fn(&foreign_mod, @ast_fold) -> foreign_mod,
+ fold_variant: @fn(&variant_, span, @ast_fold) -> (variant_, span),
+ fold_ident: @fn(ident, @ast_fold) -> ident,
+ fold_path: @fn(@path, @ast_fold) -> path,
+ fold_local: @fn(&local_, span, @ast_fold) -> (local_, span),
map_exprs: @fn(@fn(@expr) -> @expr, &[@expr]) -> ~[@expr],
new_id: @fn(node_id) -> node_id,
new_span: @fn(span) -> span
}
}
-pub fn wrap<T>(f: @fn(&T, ast_fold) -> T)
- -> @fn(&T, span, ast_fold) -> (T, span) {
+pub fn wrap<T>(f: @fn(&T, @ast_fold) -> T)
+ -> @fn(&T, span, @ast_fold) -> (T, span) {
let result: @fn(&T, span, @ast_fold) -> (T, span) = |x, s, fld| {
(f(x, fld), s)
};
}
}
-pub impl ast_fold {
+pub impl @ast_fold {
fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute] {
attrs.map(|x| fold_attribute_(*x, *self))
}
}
-pub fn make_fold(afp: ast_fold_fns) -> ast_fold {
+pub fn make_fold(afp: ast_fold_fns) -> @ast_fold {
afp as @ast_fold
}
while level > 0 {
debug!("=== block comment level %d", level);
if is_eof(rdr) {
- (rdr as reader).fatal(~"unterminated block comment");
+ (rdr as @reader).fatal(~"unterminated block comment");
}
if rdr.curr == '\n' {
trim_whitespace_prefix_and_push_line(&mut lines, curr_line,
pos: BytePos
}
-pub fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
+pub fn gather_comments_and_literals(span_diagnostic:
+ @diagnostic::span_handler,
+path: ~str,
- srdr: io::Reader) -> (~[cmnt], ~[lit]) {
+ srdr: @io::Reader)
+ -> (~[cmnt], ~[lit]) {
let src = @str::from_bytes(srdr.read_whole_stream());
let itr = parse::token::mk_fake_ident_interner();
let cm = CodeMap::new();
}
}
-pub fn token_to_str(reader: reader, token: &token::Token) -> ~str {
+pub fn token_to_str(reader: @reader, token: &token::Token) -> ~str {
token::to_str(reader.interner(), token)
}
fn is_eof(@mut self) -> bool;
fn next_token(@mut self) -> TokenAndSpan;
fn fatal(@mut self, ~str) -> !;
- fn span_diag(@mut self) -> span_handler;
+ fn span_diag(@mut self) -> @span_handler;
pure fn interner(@mut self) -> @token::ident_interner;
fn peek(@mut self) -> TokenAndSpan;
- fn dup(@mut self) -> reader;
+ fn dup(@mut self) -> @reader;
}
#[deriving_eq]
pub struct TokenAndSpan {tok: token::Token, sp: span}
pub struct StringReader {
- span_diagnostic: span_handler,
+ span_diagnostic: @span_handler,
src: @~str,
// The absolute offset within the codemap of the next character to read
pos: BytePos,
peek_span: span
}
-pub fn new_string_reader(span_diagnostic: span_handler,
+pub fn new_string_reader(span_diagnostic: @span_handler,
filemap: @codemap::FileMap,
itr: @token::ident_interner)
-> @mut StringReader {
}
/* For comments.rs, which hackily pokes into 'pos' and 'curr' */
-pub fn new_low_level_string_reader(span_diagnostic: span_handler,
+pub fn new_low_level_string_reader(span_diagnostic: @span_handler,
filemap: @codemap::FileMap,
itr: @token::ident_interner)
-> @mut StringReader {
fn fatal(@mut self, m: ~str) -> ! {
self.span_diagnostic.span_fatal(copy self.peek_span, m)
}
- fn span_diag(@mut self) -> span_handler { self.span_diagnostic }
+ fn span_diag(@mut self) -> @span_handler { self.span_diagnostic }
pure fn interner(@mut self) -> @token::ident_interner { self.interner }
fn peek(@mut self) -> TokenAndSpan {
TokenAndSpan {
sp: copy self.peek_span,
}
}
- fn dup(@mut self) -> reader { dup_string_reader(self) as reader }
+ fn dup(@mut self) -> @reader { dup_string_reader(self) as @reader }
}
impl reader for TtReader {
fn fatal(@mut self, m: ~str) -> ! {
self.sp_diag.span_fatal(copy self.cur_span, m);
}
- fn span_diag(@mut self) -> span_handler { self.sp_diag }
+ fn span_diag(@mut self) -> @span_handler { self.sp_diag }
pure fn interner(@mut self) -> @token::ident_interner { self.interner }
fn peek(@mut self) -> TokenAndSpan {
TokenAndSpan {
sp: copy self.cur_span,
}
}
- fn dup(@mut self) -> reader { dup_tt_reader(self) as reader }
+ fn dup(@mut self) -> @reader { dup_tt_reader(self) as @reader }
}
// EFFECT: advance peek_tok and peek_span to refer to the next token.
pub struct ParseSess {
cm: @codemap::CodeMap,
next_id: node_id,
- span_diagnostic: span_handler,
+ span_diagnostic: @span_handler,
interner: @ident_interner,
}
}
}
-pub fn new_parse_sess_special_handler(sh: span_handler, cm: @codemap::CodeMap)
- -> @mut ParseSess {
+pub fn new_parse_sess_special_handler(sh: @span_handler,
+ cm: @codemap::CodeMap)
+ -> @mut ParseSess {
@mut ParseSess {
cm: cm,
next_id: 1,
return rv;
}
-pub fn new_parser_from_source_str(
- sess: @mut ParseSess,
- +cfg: ast::crate_cfg,
- +name: ~str,
- +ss: codemap::FileSubstr,
- source: @~str
-) -> Parser {
+pub fn new_parser_from_source_str(sess: @mut ParseSess,
+ +cfg: ast::crate_cfg,
+ +name: ~str,
+ +ss: codemap::FileSubstr,
+ source: @~str)
+ -> Parser {
let filemap = sess.cm.new_filemap_w_substr(name, ss, source);
let srdr = lexer::new_string_reader(
copy sess.span_diagnostic,
filemap,
sess.interner
);
- Parser(sess, cfg, srdr as reader)
+ Parser(sess, cfg, srdr as @reader)
}
/// Read the entire source file, return a parser
match io::read_whole_file_str(path) {
Ok(src) => {
let filemap = sess.cm.new_filemap(path.to_str(), @src);
- let srdr = lexer::new_string_reader(
- copy sess.span_diagnostic,
- filemap,
- sess.interner
- );
- Ok(Parser(sess, cfg, srdr as reader))
+ let srdr = lexer::new_string_reader(copy sess.span_diagnostic,
+ filemap,
+ sess.interner);
+ Ok(Parser(sess, cfg, srdr as @reader))
}
Err(e) => Err(e)
None,
tts
);
- Parser(sess, cfg, trdr as reader)
+ Parser(sess, cfg, trdr as @reader)
}
// abort if necessary
pub fn Parser(sess: @mut ParseSess,
+cfg: ast::crate_cfg,
- +rdr: reader) -> Parser {
-
+ +rdr: @reader)
+ -> Parser {
let tok0 = copy rdr.next_token();
let interner = rdr.interner();
tokens_consumed: @mut uint,
restriction: @mut restriction,
quote_depth: @mut uint, // not (yet) related to the quasiquoter
- reader: reader,
+ reader: @reader,
interner: @token::ident_interner,
keywords: HashMap<~str, ()>,
strict_keywords: HashMap<~str, ()>,
pp::end(s.s);
}
-pub fn rust_printer(writer: io::Writer, intr: @ident_interner) -> @ps {
+pub fn rust_printer(writer: @io::Writer, intr: @ident_interner) -> @ps {
return @ps {
s: pp::mk_printer(writer, default_columns),
cm: None::<@CodeMap>,
// Requires you to pass an input filename and reader so that
// it can scan the input text for comments and literals to
// copy forward.
-pub fn print_crate(cm: @CodeMap, intr: @ident_interner,
- span_diagnostic: diagnostic::span_handler,
- crate: @ast::crate, filename: ~str, in: io::Reader,
- out: io::Writer, ann: pp_ann, is_expanded: bool) {
+pub fn print_crate(cm: @CodeMap,
+ intr: @ident_interner,
+ span_diagnostic: @diagnostic::span_handler,
+ crate: @ast::crate,
+ filename: ~str,
+ in: @io::Reader,
+ out: @io::Writer,
+ ann: pp_ann,
+ is_expanded: bool) {
let (cmnts, lits) = comments::gather_comments_and_literals(
span_diagnostic,
copy filename,
pub trait i<T> { }
-pub fn f<T>() -> i<T> {
+pub fn f<T>() -> @i<T> {
impl<T> i<T> for () { }
@() as @i<T>
}
fn main() {
- let nyan : noisy = @cat(0, 2, ~"nyan") as @noisy;
+ let nyan : @noisy = @cat(0, 2, ~"nyan") as @noisy;
nyan.eat(); //~ ERROR type `@noisy` does not implement any method in scope named `eat`
}
fn get() -> A { *self }
}
-fn repeater<A:Copy>(v: @A) -> repeat<A> {
+fn repeater<A:Copy>(v: @A) -> @repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type
- @v as repeat::<A> // No
+ @v as @repeat::<A> // No
}
fn main() {
// Error results because the type of is inferred to be
- // repeat<&blk/int> where blk is the lifetime of the block below.
+ // @repeat<&blk/int> where blk is the lifetime of the block below.
let y = { //~ ERROR reference is not valid
let x: &blk/int = &3;
// the fn body itself.
let v = &3;
struct F<T> { f: T }
- let x = @F {f:t} as foo;
+ let x = @F {f:t} as @foo;
fail_unless!(x.foo(v) == 3);
}
-fn to_foo_2<T:Copy>(t: T) -> foo {
+fn to_foo_2<T:Copy>(t: T) -> @foo {
// Not OK---T may contain borrowed ptrs and it is going to escape
// as part of the returned foo value
struct F<T> { f: T }
- @F {f:t} as foo //~ ERROR value may contain borrowed pointers; use `&static` bound
+ @F {f:t} as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound
}
-fn to_foo_3<T:Copy + &static>(t: T) -> foo {
+fn to_foo_3<T:Copy + &static>(t: T) -> @foo {
// OK---T may escape as part of the returned foo value, but it is
// owned and hence does not contain borrowed ptrs
struct F<T> { f: T }
- @F {f:t} as foo
+ @F {f:t} as @foo
}
fn main() {
trait foo { fn foo(); }
-fn to_foo<T:Copy + foo>(t: T) -> foo {
+fn to_foo<T:Copy + foo>(t: T) -> @foo {
@t as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound
}
-fn to_foo2<T:Copy + foo + &static>(t: T) -> foo {
+fn to_foo2<T:Copy + foo + &static>(t: T) -> @foo {
@t as @foo
}
fn main() {
let x: @Map<~str, ~str> = @LinearMap::new::<~str, ~str>() as
- Map::<~str, ~str>;
+ @Map::<~str, ~str>;
let y: @Map<uint, ~str> = @x;
//~^ ERROR mismatched types: expected `@core::container::Map<uint,~str>`
}
return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
}
-fn a_fn2(e: a_trait<'a>) -> a_trait<'b> {
+fn a_fn2(e: @a_trait<'a>) -> @a_trait<'b> {
return e; //~ ERROR mismatched types: expected `@a_trait/&b` but found `@a_trait/&a`
}
}
struct with_foo<'self> {
- f: foo<'self>
+ f: @foo<'self>
}
trait set_foo_foo {
}
-fn get_v(gc: get_ctxt) -> uint {
+fn get_v(gc: @get_ctxt) -> uint {
gc.get_ctxt().v
}
fn main() {
let ctxt = ctxt { v: 22u };
let hc = has_ctxt { c: &ctxt };
- fail_unless!(get_v(@hc as get_ctxt) == 22u);
+ fail_unless!(get_v(@hc as @get_ctxt) == 22u);
}
fn get_ctxt() -> &self/ctxt { self.c }
}
-fn make_gc() -> get_ctxt {
+fn make_gc() -> @get_ctxt {
let ctxt = ctxt { v: 22u };
let hc = has_ctxt { c: &ctxt }; //~ ERROR illegal borrow
- return @hc as get_ctxt;
+ return @hc as @get_ctxt;
}
fn main() {
fn get_ctxt() -> &self/uint;
}
-fn make_gc1(gc: get_ctxt/&a) -> get_ctxt/&b {
+fn make_gc1(gc: @get_ctxt/&a) -> @get_ctxt/&b {
return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b` but found `@get_ctxt/&a`
}
fn get_ctxt() -> &self/uint { self.r }
}
-fn make_gc2(foo: Foo/&a) -> get_ctxt/&b {
- return @foo as get_ctxt; //~ ERROR cannot infer an appropriate lifetime
+fn make_gc2(foo: Foo/&a) -> @get_ctxt/&b {
+ return @foo as @get_ctxt; //~ ERROR cannot infer an appropriate lifetime
}
fn main() {
fn set(t: T) { self.f = t; }
}
-fn set_box_trait<T>(b: box_trait<@const T>, v: @const T) {
+fn set_box_trait<T>(b: @box_trait<@const T>, v: @const T) {
b.set(v);
}
fn main() {
let b = box_impl::<@int>(box::<@int> {f: @3});
- set_box_trait(@b as box_trait::<@int>, @mut 5);
+ set_box_trait(@b as @box_trait::<@int>, @mut 5);
//~^ ERROR values differ in mutability
set_box_impl(b, @mut 5);
//~^ ERROR values differ in mutability
fn main() {
10i.dup::<int>(); //~ ERROR does not take type parameters
10i.blah::<int, int>(); //~ ERROR incorrect number of type parameters
- (@10 as bar).dup(); //~ ERROR contains a self-type
+ (@10 as @bar).dup(); //~ ERROR contains a self-type
}
fn call_it<B:TraitB>(b: B) -> int {
let y = 4u;
- b.gimme_an_a(y) //~ ERROR failed to find an implementation of trait @TraitA
+ b.gimme_an_a(y) //~ ERROR failed to find an implementation of trait TraitA
}
fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait clam<A:Copy> {
+trait c lam<A:Copy> {
fn chowder(y: A);
}
struct foo<A> {
}
}
-fn f<A:Copy>(x: clam<A>, a: A) {
+fn f<A:Copy>(x: @clam<A>, a: A) {
x.chowder(a);
}
pub fn main() {
let c = foo(42);
- let d: clam<int> = @c as clam::<int>;
+ let d: @clam<int> = @c as @clam::<int>;
f(d, c.x);
}
trait hax { }
impl<A> hax for A { }
-fn perform_hax<T:&static>(x: @T) -> hax {
+fn perform_hax<T:&static>(x: @T) -> @hax {
@x as @hax
}
// let y = @({a: 4i});
// let z = @({a: 4i} as it);
// let z = @({a: true} as it);
- let z = @(@true as it);
+ let z = @(@true as @it);
// x.f();
// y.f();
// (*z).f();
fn get() -> A { *self }
}
-fn repeater<A:Copy>(v: @A) -> repeat<A> {
+fn repeater<A:Copy>(v: @A) -> @repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type
- @v as repeat::<A> // No
+ @v as @repeat::<A> // No
}
pub fn main() {
}
}
-impl Serializer for io::Writer {
+impl Serializer for @io::Writer {
}
pub fn main() {
}
}
-fn get_v(gc: get_ctxt) -> uint {
+fn get_v(gc: @get_ctxt) -> uint {
gc.get_ctxt().v
}